2017-05-12 73 views
0

我正在製作一個3d json模型的副本,我已經動畫了,如果我在場景中只有1個模型,它就可以工作。Threejs克隆網格動畫

但是,當我試圖做一些副本,它出現以下錯誤:

遺漏的類型錯誤:無法讀取的未定義的屬性「0」。

下面的函數是在錯誤的引用到:

for(i =0; i < enemics_generats; i++){ 

    var enemic = dolent.clone(true); //Clone from original model 
    enemic.name = i.toString(); 
    if (i > 5){//set 5 visible, the rest invisble 
     enemic.visible = false; 
    } 
    else{ 
     enemic.visible = true; 
    } 

    enemic.box = new THREE.Box3().setFromObject(enemic);//Box collider 
    enemic.box_helper = new THREE.BoxHelper(enemic); //Box to be displayed on the scene 

    //ERROR IS ON THIS 2 FOLLOWING LANES 

    enemic.mixer = new THREE.AnimationMixer(enemic); 
    enemic.mixer.clipAction(enemic.animations[ 0 ]).play(); //HERE IS WHERE THE ERROR APPEARS 

    enemics.push(enemic);//Add to the array 

    scene.add(enemic);//Add to scene 
    scene.add(enemic.box_helper); 
} 

感謝您的時間。

+0

如果你的動畫特性或功能的定義。 –

+0

JSON加載器從文件讀取動畫,並將它們存儲在動畫屬性中。 –

+0

所以,「dolent」(它是原始的加載模型)在裏面有動畫。 –

回答

0

Object3D.clone不會複製你的動畫數組。它只會複製與THREE.js對象相關的屬性。您將需要在您的克隆對象中手動複製(或引用)您的動畫數組。

var obj1 = new THREE.Object3D(); 
 
obj1.someProperty = "test"; 
 
var obj2 = obj1.clone(); 
 
console.log(obj2.someProperty); // undefined
<script src="https://threejs.org/build/three.js"></script>

+0

很高興知道,我會參考原創動畫。 謝謝 –