three.js 利用鼠標移動攝像機

導入控制器

import { TrackballControls } from 'three/addons/controls/TrackballControls.js';

代碼

document.body.appendChild(renderer.domElement); function renderScene() {
  trackballControls.update(clock.getDelta());
  cube.rotation.x += controls.rotationSpeed;
  cube.rotation.y += controls.rotationSpeed;
  cube.rotation.z += controls.rotationSpeed;

  requestAnimationFrame(renderScene);
  stats.update();
  renderer.render(scene, camera);
}
renderScene();


//由於它需要響應文檔對象模型(DOM)元素的事件,它的初始化代碼必須出現在 appendChild 函數調用之後。
var trackballControls = new TrackballControls(camera, renderer.domElement);
var clock = new THREE.Clock(); //創建THREE.Clock對象,用於計算上次調用經過的時間



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章