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

glTF models cannot be copied or cloned #8869

Closed
kkananen opened this issue May 12, 2016 · 7 comments
Closed

glTF models cannot be copied or cloned #8869

kkananen opened this issue May 12, 2016 · 7 comments

Comments

@kkananen
Copy link

kkananen commented May 12, 2016

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

@tparisi
Copy link
Contributor

tparisi commented May 12, 2016

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.

@kkananen
Copy link
Author

kkananen commented May 12, 2016

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.

@easyfrog
Copy link

so. How to clone a gltf model now ???

@donmccurdy
Copy link
Collaborator

donmccurdy commented Jan 8, 2017

Partial update on this: As of r83, THREE.GLTFLoader uses the core threejs animation classes. Because new THREE.AnimationMixer( root ) is instantiated with a reference to the object, you can create a new mixer for the cloned/copied model without any conflicts.

I don't know where things are at for shaders, however.

@easyfrog
Copy link

easyfrog commented Mar 8, 2017

Is the gltfloader could clone now ?
If don't solve this problem this loader is useless. because is It is very common to clone a model.

@donmccurdy
Copy link
Collaborator

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

@donmccurdy
Copy link
Collaborator

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.

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

4 participants