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

default generated tsx code problems #273

Open
patacoding opened this issue Aug 13, 2024 · 1 comment
Open

default generated tsx code problems #273

patacoding opened this issue Aug 13, 2024 · 1 comment

Comments

@patacoding
Copy link

const group = React.useRef<THREE.Group>()
const { scene, animations } = useGLTF('/autonomous_robot_sweeper-transformed.glb')
const clone = React.useMemo(() => SkeletonUtils.clone(scene), [scene])
const { nodes, materials } = useGraph(clone) as GLTFResult

// actions is empty
const { actions } = useAnimations(animations, group)

// this way get correct result
const actions = useAnimations(animations, group)

maybe useAnimations version problem? tested with "@react-three/drei": "^9.106.0",

@patacoding patacoding changed the title default generated tsx code error for get actions default generated tsx code problems Aug 14, 2024
@patacoding
Copy link
Author

patacoding commented Aug 14, 2024

I need reuse loaded gltf model and play animations of each of them at same time, default generated detail jsx component will cause warning like THREE.PropertyBinding: No target node found for track: somebone.position and stop animation

use following code solve my problems

const group = useRef<THREE.Group>(null)

const { scene, animations } = useGLTF('url')

const clone = useMemo(() => SkeletonUtils.clone(scene), [scene])

const { nodes, materials } = useGraph(clone) as GLTFResult

const mixer = new THREE.AnimationMixer(clone)

const actions = useAnimations(animations, group)

// console.log('actions:', actions)

const playClipName = 'Track'

for (let index = 0; index < actions.clips.length; index++) {
const clipName = actions.clips[index].name
const clip = actions.clips[index]
if (clipName === playClipName) {
mixer.clipAction(clip).play()
}
}

useFrame((_state, delta) => {
mixer.update(delta)
})

return (

<primitive scale={1} position={[2, 0, 0]} object={clone} />

)

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

1 participant