When using InstancedMesh for repeating objects and then exporting it through ColladaExporter, only the base mesh appears in exported model, no instances.
As far as I know, Collada doesn't support instancing:
https://www.khronos.org/files/collada_spec_1_4.pdf
GLTF has a proposal though:
https://github.com/KhronosGroup/glTF/pull/1691
^we could also export InstancedMesh by writing:
... where all the Meshes share the same Geometry. That would avoid duplicating geometry data in a glTF file at least, and I'd guess COLLADA would do the same. But in any format, it's going to import back without the draw call savings.
But in any format, it's going to import back without the draw call savings.
Yes, and that's what makes me wonder if we should support this.
Depending of the use case we could do a utility that converts a InstancedMesh
to multiple Mesh
es and leave it up to the dev to use it on their use case before exporting.
Maybe, if the conversion would be optional, ColladaExporter
should have one option like convertInstancesToMeshes
passed to parse()
instead of having to convert meshes before exporting them?
Depending of the use case we could do a utility that converts a InstancedMesh to multiple Meshes and leave it up to the dev to use it on their use case before exporting.
I vote for this option. How about introducing SceneUtils.createMeshesFromInstancedMesh()
?
First approach:
THREE.SceneUtils = {
createMeshesFromInstancedMesh: function ( instancedMesh ) {
var group = new THREE.Group();
var count = instancedMesh.count;
var geometry = instancedMesh.geometry;
var material = instancedMesh.material;
for ( var i = 0; i < count; i ++ ) {
var mesh = new THREE.Mesh( geometry, material );
instancedMesh.getMatrixAt( i, mesh.matrix );
mesh.matrix.decompose( mesh.position, mesh.quaternion, mesh.scale );
group.add( mesh );
}
group.copy( instancedMesh );
group.updateMatrixWorld(); // ensure correct world matrices of meshes
return group;
},
//
};
once you put it in collada exporter, all the other exporters are going to want it. so yes, +1 for utility
Okay, since the helper is now available I think we can close this issue. If necessary, users can perform the conversion by themselves before exporting.
Most helpful comment
once you put it in collada exporter, all the other exporters are going to want it. so yes, +1 for utility