donmccurdy/glTF-Transform

Saving information on instancing for subsequent mapping.

K1vs opened this issue · 1 comments

K1vs commented

Is your feature request related to a problem? Please describe.
I have a task to optimize a large scene, it has a lot of meshes which are repeated, and instancing has a very good effect on performance. But when selecting an object, I need to download information about it. I usually do this using his name. But after instancing, this option is no longer available to me. I need some kind of mapping between the original mesh name and the new name and instance number.

Describe the solution you'd like
Option for optimize command "instance-map-file" for generate json file with mapping.
E.g.

{
    [
        {
            "originalMeshName": "XXX",
            "instancedMeshName": "Instance YYY.ZZZ",
        }
    ]
}

Describe alternatives you've considered
If there are alternative ways to achieve this, I'd be glad to know them.

Hi @K1vs!

Currently the instance() function doesn't save the mapping information you describe.

If you are looking for something more custom like the JSON sample you shared, it might be best to copy/paste the contents of instance.ts and modify it to your needs. It's a short, single-file function.

Another possibility would be to extend the function to store an instance attribute like _ID containing the index of the node from which each instance was generated. However, those nodes are removed from the scene graph after generating the instance batch, so you'd need to include logic in your script to preserve whatever data (name, index, extras...) about each node that you need.