Three.js: Collada Exporter doesn't handle InstancedMeshes

Created on 7 Feb 2020  路  8Comments  路  Source: mrdoob/three.js

When using InstancedMesh for repeating objects and then exporting it through ColladaExporter, only the base mesh appears in exported model, no instances.

Enhancement Examples

Most helpful comment

once you put it in collada exporter, all the other exporters are going to want it. so yes, +1 for utility

All 8 comments

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:

  • Group

    • Mesh

    • Mesh

    • ...

... 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 Meshes 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seep picture seep  路  3Comments

ghost picture ghost  路  3Comments

yqrashawn picture yqrashawn  路  3Comments

makc picture makc  路  3Comments

boyravikumar picture boyravikumar  路  3Comments