three自定义动画

 

three自定义动画

var clock = new THREE.Clock()

/* 模型从一个位置移动到另一个位置的动画 mesh:为控制的mesh或者object3d name:为mesh或object3d的名字 initX,initY,initZ:为mesh或object3d初始化的x,y,z; x, y, z:为mesh或object3d移动后的位置的x,y,z; */ modelAnimation(mesh, name, initX, initY, initZ, x, y, z,) { var times = [0, 20]; var values = [ initX, initY, initZ, x, y, z]; var posTrack = new THREE.KeyframeTrack(name, times, values); var clip = new THREE.AnimationClip("default", 2, [posTrack]); this.mixer = new THREE.AnimationMixer(mesh); var AnimationAction = this.mixer.clipAction(clip); AnimationAction.timeScale = 5; AnimationAction.loop = THREE.LoopOnce; AnimationAction.clampWhenFinished=true; AnimationAction.time = 0; clip.duration = 1; AnimationAction.play(); }

function render(){
  renderer.render(scene, camera);
  requestAnimationFrame(render);
  let time = clock.getDelta();
  if (mixer) {
    mixer.update(time);
  }
}

  

有疑问请加 qq 群讨论:854184700

 

posted @ 2022-05-14 17:45  web与webGL  阅读(192)  评论(0)    收藏  举报