2013-07-11 44 views
0

所以基本上,我使用Three.js在javascript中創建了一個機器人對象,並傳遞了我正在使用的three.js場景變量對象來繪製機器人部件,出於某種原因,但場景對象不會傳遞到函數中(它不會繪製) - 我是否缺少有關JavaScript函數的內容?將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"); 
    } 
} 

回答

0

也許這更象是你想要的結果:

Robot.prototype.draw = function() { 
    for (x in this.parts){ 
    this.sc.add(this.parts[x]); // < - spot the difference :) 
    alert("hit"); 
    } 
} 
+0

那好吧...所以我認爲,X代表的實際對象,如它在普通Java的是不是這樣的? – Skorpius