Javascript 无法设置属性';y';未定义的

Javascript 无法设置属性';y';未定义的,javascript,three.js,Javascript,Three.js,我目前正在尝试使用three.js加载和显示一个.stl文件,代码如下: var stlLoader = new THREE.STLLoader(); stlLoader.load('assets/Cap.stl', function (object){ object.position.y = - 100; scene.add(object); console.log("Object inserted."); fitCameraToObject(camer

我目前正在尝试使用three.js加载和显示一个.stl文件,代码如下:

var stlLoader = new THREE.STLLoader();
stlLoader.load('assets/Cap.stl', function (object){
    object.position.y = - 100;  
    scene.add(object);
    console.log("Object inserted.");  
    fitCameraToObject(camera,object,2,controls);
    controls.update();
    animate();
},
function ( xhr ) {
    console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
function (err) 
{
    console.error(err);
} 
);
(第142-158行)

但我在加载页面时在控制台中收到此错误:

webGLLoader.js:156 TypeError: Cannot set property 'y' of undefined
    at webGLLoader.js:144
    at Object.onLoad (STLLoader.js:80)
    at XMLHttpRequest.<anonymous> (three.js:35998)
(anonymous) @ webGLLoader.js:156
(anonymous) @ STLLoader.js:86
(anonymous) @ three.js:35998
load (async)
load @ three.js:35976
load @ STLLoader.js:76
(anonymous) @ webGLLoader.js:143
webGLLoader.js:156类型错误:无法设置未定义的属性“y”
在webGLLoader.js:144
在Object.onLoad(STLLoader.js:80)
在XMLHttpRequest。(three.js:35998)
(匿名)@webGLLoader.js:156
(匿名)@STLLoader.js:86
(匿名)@three.js:35998
加载(异步)
加载@three.js:35976
load@STLLoader.js:76
(匿名)@webGLLoader.js:143

我不确定为什么会发生这种情况,因为在使用其他加载程序时,我能够以相同的方式设置对象的位置。

STL文件仅包含几何图形<代码>STLLoader返回一个对象。
BufferGeometry
对象没有
position
属性,但您可以使用它创建
网格
,该属性确实存在

//three.js r113
让loader=new THREE.STLLoader();
loader.load(“./file.stl”,函数(geo){
设mesh=new THREE.mesh(geo,new THREE.MeshBasicMaterial({color:“red”}));
网格位置y=-100;
场景。添加(网格);
});
添加console.log(object.position);在第3行之前,查看它是否未定义。