Passing a prop to GLTFJSX generated model file gives an error #1711
-
The problem I am dealing with is because I have a glb model with a few animations. I currently only wanted to test playing each of them using a separate button to choose between each animation. I used the GLTFJSX file generator to convert the model into a js file and have another file with a simple canvas setup. The file with the canvas. import React, { useState } from 'react';
import { Canvas } from "@react-three/fiber";
import Boat from "./Boat.js";
export default function BoatAnim() {
const [anim, setAnim] = useState("Fly");
return (
<>
<div style={{ position: 'absolute', zIndex: '3' }}>
<button onClick={() => setAnim("Fly")}>Fly</button>
<button onClick={() => setAnim("Float")}>Float</button>
</div>
<Canvas camera={{ position: [0, 2.5, 20] }}>
<color attach="background" args={"lightblue"} />
<directionalLight color={"orange"} intensity={0.5} />
<ambientLight color={"yellow"} intensity={0.2} />
<Boat animation={anim} />
</Canvas>
</>
);
} The model file. import React, { useRef, useEffect } from 'react';
import { useGLTF, useAnimations } from '@react-three/drei';
import { LoopOnce } from 'three';
export default function Model({ animation, ...props }) {
const group = useRef()
const { nodes, materials, animations } = useGLTF('/boat.glb')
const { actions } = useAnimations(animations, group)
useEffect(() => {
console.log("Props", props);
console.log("Animation", animation);
actions.Fly.play();
actions.Fly.setLoop(LoopOnce);
actions.Fly.clampWhenFinished = true;
});
return (
<group ref={group} {...props} dispose={null}>
<mesh name="Boat" geometry={nodes.Boat.geometry} material={materials._15211_Wakeboard_v1default} scale={0.05} />
</group>
)
}
useGLTF.preload('/boat.glb') As you can see I have a state set-up that is being assigned by the click of a button, and is being passed into the model. Currently I'm not even really doing anything with it, just console logging it to check that I get the correct input, which I do. However, whenever the state is passed, I get an
So my questions are: How can I resolve this issue? Perhaps I should be passing the animation I want to be played a different way? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
This is related to #1569.
|
Beta Was this translation helpful? Give feedback.
This is related to #1569.
args
must be an array of arguments, so you'd declare a Color with<color attach="background" args={["lightblue"]} />
: