Threejs Cloning网格动画

时间:2017-05-12 02:42:22

标签: javascript animation three.js

我正在复制我已制作动画的3d json模型,如果我在场景中只有一个模型,它就可以工作。

但是当我试图制作一些副本时,会出现以下错误:

未捕获的TypeError:无法读取属性' 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);
}

感谢您的时间。

1 个答案:

答案 0 :(得分: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>

相关问题