#Dynamic animations

29 messages · Page 1 of 1 (latest)

south pulsar
#

I need to make dynamic animations in my project, animations that are not in the scene when exported from model load.

#

this is the structure of the external animation that I want to insert in the scene. (I removed the tracks for the print)

#

and I got these errors

blissful lava
#

it shouldn't matter where the animations come from but that code executes in the render function and that's not good. animation is a side effect. the view the mixer wants to animate doesn't exist at that point. it needs to run inside useeffect

#

btw, useAnimation already creates clips for you, no need to do that yourself

south pulsar
#

however using useAnimation I only get static animations, if I want to add more animations to the same model I would have to do a new upload, it is not desired to use another .glb for another pack of new animations

blissful lava
#

ah ok, still, executing this in the function body isn't possible, needs to be in a useEffect

south pulsar
#

I did something like this

blissful lava
#

and works?

south pulsar
#

i got theses errors

#

it's like not finding the model to make the animation

#

I found this difference in "_localRoot" using the actions of the animations imported from the model and the action imported externally

blissful lava
#

yes, animations are super specific, the tree has to exist exactly the same with all the groups and names present

#

how do you render the model?

#

can you show me a snap of that?

south pulsar
#

I used the useGLTF hook
const { nodes, materials, scene, animations } = useGLTF(pathLisa)

blissful lava
#

i think that's the problem, "scene" is empty

#

in threejs an object can only ever be added to a parent once. if you do this

parent1.add(foo)
parent2.add(foo)

foo will be child of parent2

#

you need to give it a reference to the actual scene:

const ref = useRef()

<Controller scene={ref}

...
useEffect(() => {
scene.current

#

and make sure the ref points to the first object, not the outer group, group name=scene should be the one

#

if this is too hard to figure out you can put it online as a codesandbox. i've never used foreign animation on a foreign scene before but i imagine it will work if it targets the correct scene

south pulsar
# south pulsar

I changed "lisaRef" to "lisaRef.current" on line 58 and it didn't give an error, but the animation still didn't happen

south pulsar
#

should the uuid be the same in _localRoot?

south pulsar
#

this worked

#

finally

#

after 3 months