Three.js: How to clone models in program

Created on 20 Feb 2012  路  3Comments  路  Source: mrdoob/three.js

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;
}
Question

Most helpful comment

Please don't post at threads which are closed for years. Open a new issue instead, provide your dae file and the respective three.js code.

All 3 comments

You should be able to do something like this:

var geometry = collada.scene.children[ 0 ].geometry;
var material = collada.scene.children[ 0 ].material;

for ( var i = 0; i < 10; i ++ ) {
    var mesh = new THREE.Mesh( geometry, material );
    mesh.position.set( i * 100, 0, 0 );
    scene.add( mesh );
}

It didn't work, I meet the same problem.
this is my collada.scene object
image

Please don't post at threads which are closed for years. Open a new issue instead, provide your dae file and the respective three.js code.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

donmccurdy picture donmccurdy  路  3Comments

filharvey picture filharvey  路  3Comments

konijn picture konijn  路  3Comments

ghost picture ghost  路  3Comments

scrubs picture scrubs  路  3Comments