我正在尝试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, camera
let cube
function 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>
慕虎7371278
相关分类