我尝试导入我的3d模型,但它并没有在黑屏上加载,我得到了一个错误,说"未捕获的类型错误:无法读取未定义的属性(读取"itemStart"(。我在下面有我的代码,如果你需要更多详细信息,请告诉我。
// Scene
const scene = new THREE.Scene();
scene.background = new THREE.Color("grey");
// Base camera
const camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight,)
camera.position.set(0,100,800);
// full screen webgl renderer
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth,window.innerHeight);
document.body.appendChild(renderer.domElement);
// make sure project is responsive based on window resizing
window.addEventListener('resize', () =>{
renderer.setSize(window.innerWidth,window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
})
// add a light
const light = new THREE.AmbientLight(0x555500,4)
scene.add(light);
// load object
const loader = new THREE.GLTFLoader();
loader.load('do-yatte/yatte4.gltf', function (gltf) {
scene.add(gltf.scene);
})
const render = function() {
requestAnimationFrame(render)
renderer.render(scene, camera);
}
render();
更改此项:
const loader = new THREE.GLTFLoader();
对此:
const loader = new GLTFLoader();
不需要THREE名称空间。