2

我必须多次加载相同的 collada 对象。这是代码

var ai = [];

function setupAI() {
    var c = getMapSector(cam.position);

    var loader = new THREE.ColladaLoader();
    loader.options.convertUpAxis = true;
    loader.load('models/monster.DAE',function colladaReady( collada ){
    var op = collada.scene;
    skin = collada.skins [ 0 ];


    for (var i = 0; i < NUMAI; i++) {


         var o = THREE.SceneUtils.cloneObject(op);

        o.scale.x = o.scale.y = o.scale.z = 0.006;
                o.updateMatrix();

    do {
        var x = getRandBetween(0, mapW-1);
        var z = getRandBetween(0, mapH-1);
    } while (map[x][z] > 0 || (x == c.x && z == c.z));
    x = Math.floor(x - mapW/2) * UNITSIZE;
    z = Math.floor(z - mapW/2) * UNITSIZE;
    o.position.set(x, UNITSIZE * 0.15, z);
    o.health = 100;
    //o.path = getAIpath(o);
    o.pathPos = 1;
    o.lastRandomX = Math.random();
    o.lastRandomZ = Math.random();
    o.lastShot = Date.now(); // Higher-fidelity timers aren't a big deal here.
    ai.push(o);
    scene.add(o);
}
    });


}

但这在这一行中给出了错误

var o = THREE.SceneUtils.cloneObject(op);

但是如果我将加载程序放在循环中,它会变得很重并且不会加载到浏览器中。

4

0 回答 0