我必须多次加载相同的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);
但是如果我把加载器放在循环中它会变得很重并且不会在浏览器中加载。