this.deepClone = (object) =>{
let target = null;
if(object.type === 'Mesh' || object.type === 'Sprite'){
target = new THREE.Mesh(object.geometry.clone(false), object.material.clone(false) );
}else{
target = object.clone( false );
}
target.name = object.name;
copyProperty(target, object);
if(object.children && object.children.length > 0){
object.children.forEach( child => {
target.add( this.deepClone(child) );
});
}
return target;
}
function copyProperty(target, source){
target.position.x = source.position.x;
target.position.y = source.position.y;
target.position.z = source.position.z;
target.rotation.x = source.rotation.x;
target.rotation.y = source.rotation.y;
target.rotation.z = source.rotation.z;
target.scale.x = source.scale.x;
target.scale.y = source.scale.y;
target.scale.z = source.scale.z;
}