I’m a beginner for three.js , my question is gltf model animation is working on https://gltf-viewer.donmccurdy.com/ , but not working on my code
this is model copter.glb (143.6 KB)
`
threejs - copter<style>
body {
margin: 0;
overflow: hidden;
}
</style>
<canvas id="myCanvas"></canvas>
<script src="three.js"></script>
<script src="GLTFLoader.js"></script>
<script src="AnimationMixer.js"></script>
<script>
var renderer,
scene,
camera,
model,
animations,
myCanvas = document.getElementById('myCanvas');
//RENDERER
renderer = new THREE.WebGLRenderer({
canvas: myCanvas,
antialias: true
});
renderer.setClearColor(0x000000);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
//CAMERA
camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 0.1, 1000);
//SCENE
scene = new THREE.Scene();
//LIGHTS
var light = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(light);
var light2 = new THREE.PointLight(0xffffff, 0.5);
scene.add(light2);
var loader = new THREE.GLTFLoader();
loader.load('copter.glb', handle_load);
var mesh;
function handle_load(gltf) {
console.log(gltf);
mesh = gltf.scene;
// console.log(mesh.children[0]);
// mesh.children[0].material = new THREE.MeshLambertMaterial();
scene.add(mesh);
mesh.position.z = -10;
var model = gltf.scene;
var animations = gltf.animations;
scene.add(model);
//
mixer = new THREE.AnimationMixer(model);
var action = mixer.clipAction(animations[0]); // access first animation clip
action.play();
}
//RENDER LOOP
render();
var delta = 0;
var prevTime = Date.now();
function render() {
delta += 0.1;
if (mesh) {
// mesh.rotation.y += 0.01;
//animation mesh
// mesh.morphTargetInfluences[ 0 ] = Math.sin(delta) * 20.0;
}
renderer.render(scene, camera);
requestAnimationFrame(render);
}
</script>
`
plz help
``