UnityGLTF icon indicating copy to clipboard operation
UnityGLTF copied to clipboard

Import Animation .glb files to existing GLTF model?

Open marcspraragen opened this issue 6 years ago • 9 comments

I'm wondering if there is support and/or sample scenes for importing separate animation .glb files at runtime and applying them to an existing GLTF model component in the scene? Thanks!

marcspraragen avatar Jun 13 '19 16:06 marcspraragen

hey, lol. saw you over at the TriLib forums. Guessing you gave up on it? :) Have you been able to get this GLTF loader working on android by any chance? Im having zero luck.

anupamdas2012 avatar Jun 14 '19 22:06 anupamdas2012

Hey, there doesn't seem to be a sample to work from but I'm still experimenting. :)

marcspraragen avatar Jun 17 '19 16:06 marcspraragen

Hi @marcspraragen,

This isn't something that is built in, but I think you should be able to accomplish it with UnityGLTF. If you load scene in a glb which contains a mesh that has an animation attached to it, then it will load as a Unity animation. Then should be able to copy that animation onto another mesh.

AdamMitchell-ms avatar Jun 17 '19 20:06 AdamMitchell-ms

Thanks Adam! The other possibility I was looking for applying an animation was merging a model .gltf with a model-less animation .gltf at runtime. Does (or could, with some tweaking) RootMergeComponent script cover this case?

marcspraragen avatar Jun 18 '19 12:06 marcspraragen

This is not possible right now. Side note, are these valid gltfs?
Looking at the spec, animation channel targets must specify a node. And I think that node needs to be in the same gltf to be valid. https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#channel https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#animations

That aside, if you wanted to accomplish this, then you'd need to:

  • Make GLTFSceneImporter.ConstructClip public or expose a public function that calls it.
  • Come up with some way to retarget the animation's referenced nodes to the nodes from another file.
    • See the call to GetNode() inside ConstructClip(). Maybe have ConstructClip take in a function to get a node given a node id. By default it will call GetNode() as it does now.

If you do the work to enable something like this, please send a pull request to get it into master branch so others can benefit from it.

AdamMitchell-ms avatar Jun 24 '19 22:06 AdamMitchell-ms

Thanks for your reply! I will definitely share any successful updates.

marcspraragen avatar Jun 26 '19 12:06 marcspraragen

Any updates on this capability? We have worked around it by leaving all animations in one file per the spec

marcspraragen avatar Jan 15 '20 16:01 marcspraragen

Oh finally, someone has tried on what I am stuck for a week now. So the case is the same as me. I want to apply an animation from one GLTF file to another. I don't want to bloat my main mesh while loading the main scene.

Any update on this issue? @marcspraragen
Screenshot of my files below (will give a better perspective) issue

I can do this same in the Sandbox provided by BabylonJS, if they can do it I am sure there would be something that I have missed.

Link - https://drive.google.com/file/d/1VV9CeVitHk31aZ71ejI9-FZdRwDgGDu1/view?usp=sharing

nipundavid avatar Jun 03 '20 09:06 nipundavid

We tried quite a bit to transplant / construct animated clips between imported scenes and their nodes, but it ended up being unreliable. Also, it's hard to test because even though UnityGLTF is open source, GLTF spec is too much of a black box (I'm guessing that factor has stumped many other efforts here).

marcspraragen avatar Jul 22 '20 21:07 marcspraragen