Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepass to de-duplicate object names at JSX generation time #231

Open
donmccurdy opened this issue Nov 16, 2023 · 2 comments
Open

Prepass to de-duplicate object names at JSX generation time #231

donmccurdy opened this issue Nov 16, 2023 · 2 comments

Comments

@donmccurdy
Copy link
Member

Currently gltfjsx relies on matching the exact implementation of GLTFLoader's createUniqueName ...

https://github.com/pmndrs/gltfjsx/blob/8bf87e1913b941ae16a1c57817d08e865f8568f6/src/bin/GLTFLoader.js#L1911C1-L1924

... to ensure that names in JSX match names GLTFLoader will output, given the same file. However, it's difficult for three.js to guarantee indefinitely that the same .glb file will always result in the same names in future releases. When the file contains duplicate names, GLTFLoader must assign suffixes like _1 or _2, and refactoring or performance changes in GLTFLoader could change the order in which suffixes are assigned.

I'd like to add a step to gltfjsx, pre-processing the input to ensure unique names, so that GLTFLoader's createUniqueName will have nothing to de-duplicate at runtime. That would be an additional step in src/utils/transform.js. Are others OK with this change?

Related:

@donmccurdy
Copy link
Member Author

donmccurdy commented Nov 16, 2023

Picking up from pmndrs/react-three-fiber#2498, another issue to consider is that three.js must clone materials when they're reused by incompatible meshes. Presence of vertex colors and vertex tangents would be one example of this. The same prepass could do this change as well, outputting a GLB with N copies of a reused material, each having a unique name.

@donmccurdy donmccurdy changed the title De-duplicate object names at JSX generation time Prepass to de-duplicate object names at JSX generation time Nov 16, 2023
@CodyJasonBennett
Copy link
Member

I don't see a better alternative than mutating the GLB. I'd have to concur with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants