Hi all,
I’m trying to play an animation I have set up in a GLTF model but still cant get it to work.
Ive been trying for a while and read many forum posts on the best way to approack this. I have decided after reading How to use the animation that comes with the .gltf file that i downloaded in sketchfab - #2 by drcmda that maybe r3f is the way to go to simplify the process.
I have successfully managed to covert the GLTF using the online GLTF/jsx converter and created a r3f project that loads the file but have tried many different variations of the useEffect hook to no effect.
Here is the app.js:
import “./App.css”;
import { Canvas } from “@react-three/fiber”;
import { Environment, OrbitControls } from “@react-three/drei”;
import { Suspense } from “react”;
import Model from “./Model”;
function App() {
return (
);
}
export default App;
and the top few lines of Model.js:
*
Auto-generated by: GitHub - pmndrs/gltfjsx: 🎮 Turns GLTFs into JSX components
*/
import React, { useRef } from “react”;
import { useGLTF, PerspectiveCamera, useAnimations } from “@react-three/drei”;
export default function Model(props) {
const group = useRef();
const { nodes, materials, animations } = useGLTF(“/model.gltf”);
const { actions } = useAnimations(animations, group);
return (
<group ref={group} {…props} dispose={null}>
When I run the code I get the following warning:
Line 11:11: ‘actions’ is assigned a value but never used no-unused-vars
I have tried this line in the Model.js:
useEffect(() => {
actions[‘CameraAction.003’].play(), )
but it keeps throwing up another error message about useEffect needing dependancies. Where does the ‘CameraAction.003’ string come from? Does the GLTF file in the public folder need to be a GLB?
Any help would be much appreciated and if Im better off going back to straight old Three.js please let me know?
Thanks