-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
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
glTF models cannot be copied or cloned #8869
Comments
Yes that sounds like something useful... when you say it "works in a slightly unexpected manner" what would you expect? How would you refactor the data structures? Happy to take a look though I'm not sure when I can get to it. |
In other words, 'slightly unexpected manner' = the object3d hierarchy loaded from a glTF depends on external components (assets and animations) in a manner which makes it not comply with the .clone() and .copy() semantics. I would have expected that copy&clone on the root object3d loaded from a glTF would have given me an object that renders correctly :) To refactor this, either the shader/animation(s) would need to be contained within the loaded hierarchy OR if it is more desirable that they are owned by an external container (glTFShaders/glTFAnimator), the direction of referencing would need to be reversed: instead of the shader/animation pointing to a mesh, the mesh would have a reference to the shader/animation. The latter approach might not work for animations - all copies would share the same animation pace & timing, which might need further refactoring. |
so. How to clone a gltf model now ??? |
Partial update on this: As of r83, THREE.GLTFLoader uses the core threejs animation classes. Because I don't know where things are at for shaders, however. |
Is the gltfloader could clone now ? |
@easyfrog There are situations in which cloning a GLTF model will still fail. Specifically, custom GLSL shaders. If you run into further cases, please do file an issue. |
The original loader for glTF 1.0 has been replaced with the loader for glTF2.0. There are fewer edge cases for cloning, but still a few (specifically skinned animation). Closing this issue: the glTF2-specific issues are tracked by #11573. |
Description of the problem
The current glTF loader works in a slightly unexpected manner: shaders and animations point to a specific instance of a loaded glTF hierarchy, so .clone() or .copy() operations on that hierarchy will drop the links, resulting in the copy not rendering nor animating.
I am intending to patch this in vizor.io initially by providing a deepCopyglTF() function which also goes off and clones the animations and shaders and rebinds them to the new copy.
However as a long-term-solution for three.js it would be preferable to be able to copy and clone these things via the standard three.js way - i.e. calling .copy() or .clone(). This would require the glTF loader to be refactored so that the loaded mesh hierarchy is entirely self contained with no extra external resources pointing to it (this would also remove the need to update glTFAnimator and glTFShaders explicitly). I'm unlikely to get to that anytime soon but would be interested in hearing if anyone else has given thought to this or is working on a similar issue?
ping @tparisi
The text was updated successfully, but these errors were encountered: