我正在尝试OrbitControls在 THREE.js 中使用。如果我let cameraControl = new OrbitControls(camera)从下面删除该行,将不会出现错误。但是现在,我有“Uncaught TypeError: Cannot read property 'addEventListener' of undefined”我尝试更改OrbitControls(camera)为THREE.OrbitControls(camera),然后出现“Uncaught TypeError: THREE.OrbitControls is not a constructor”。我尝试OrbitControls.js使用<script src=...></script>outside导入"module",而不是import {OrbitControls} from ...;,但它不起作用,我也尝试移动let cameraControl = new OrbitControls(camera)到其他行,但也不起作用。任何想法如何解决?<body><script type="module">import * as THREE from 'https://threejsfundamentals.org/threejs/resources/threejs/r115/build/three.module.js';import {OrbitControls} from 'https://threejsfundamentals.org/threejs/resources/threejs/r115/examples/jsm/controls/OrbitControls.js';let scene, renderer, cameralet cubefunction init() { scene = new THREE.Scene() renderer = new THREE.WebGLRenderer() renderer.setSize(window.innerWidth, window.innerHeight) document.body.appendChild(renderer.domElement) camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 100) let cameraControl = new OrbitControls(camera) camera.position.set(10, 10, 10) camera.lookAt(scene.position) // cube cube = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1)) scene.add(cube)}function render() { requestAnimationFrame(render) renderer.render(scene, camera)}init()render()</script></body>
1 回答
慕虎7371278
TA贡献1802条经验 获得超4个赞
让 cameraControl = new OrbitControls(camera)
始终像这样创建控件:
let cameraControl = new OrbitControls(camera, renderer.domElement);
第二个参数现在是强制性的。
添加回答
举报
0/150
提交
取消