mrdoob/three.js — Issue #1363: How to clone models in program
Author: fllubo
Created: 2012-02-20 14:23:39+00:00
State: open

hello ,I want to load a dae model into my program,for example a teapot and I want to have 10 teapots in the scene I use the clone function as follow,but the object seems to refer to its parent,and then refer to itself so I can't clone it ,how can I have 10 copies of my object?
var dae;
var dae = [];
var loader = new THREE.ColladaLoader();
loader.options.convertUpAxis = true;
loader.load( 'teapot.dae',function colladaReady( collada ) {
dae = collada.scene;
for(var i = 0;i < 10;++i){
daes[i] = clone(dae);
}
});
}
function clone(obj){
if(obj == null || typeof(obj) != 'object')
return obj;
var temp = new Object();//obj.constructor(); // changed
for(var key in obj)
temp[key] = clone(obj[key]);
return temp;
}