Function 将three.js对象传入javascript

Function 将three.js对象传入javascript,function,object,parameters,three.js,Function,Object,Parameters,Three.js,因此,基本上,我正在使用Three.js在javascript中创建一个robot对象,并传入Three.js场景变量对象,我正在使用该对象通过数组绘制机器人部件-尽管出于某种原因,场景对象不会传递到函数中(它不会绘制)-我是否缺少javascript函数的某些内容 function Robot(sc){ this.sc=sc; var robtexture = new THREE.MeshLambertMaterial({ map: THREE.ImageUt

因此,基本上,我正在使用Three.js在javascript中创建一个robot对象,并传入Three.js场景变量对象,我正在使用该对象通过数组绘制机器人部件-尽管出于某种原因,场景对象不会传递到函数中(它不会绘制)-我是否缺少javascript函数的某些内容

function Robot(sc){
    this.sc=sc;

    var robtexture = new THREE.MeshLambertMaterial({
        map: THREE.ImageUtils.loadTexture('tex/dmetal.png')
    });

    this.parts = [];

    var current;

    //make body

    current=new THREE.Mesh(new THREE.CubeGeometry(10,15,10), robtexture);

    this.parts.push(current);

    alert("hit");

    //make legs
}

Robot.prototype.draw = function() {
    for (x in this.parts){
        this.sc.add(x);
        alert("hit");
    }
}

也许这更符合您的预期:

Robot.prototype.draw = function() {
  for (x in this.parts){
    this.sc.add(this.parts[x]); // < - spot the difference :)
    alert("hit");
  }
}
Robot.prototype.draw=函数(){
对于(本部分中的x){
this.sc.add(this.parts[x]);//<-找出差异:)
警惕(“击中”);
}
}

Oh ok ok…所以我认为x代表了实际的对象,就像它在普通Java中所做的那样-不是这样吗?