Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to clone models in program #1363

Closed
fuzihaofzh opened this issue Feb 20, 2012 · 3 comments
Closed

How to clone models in program #1363

fuzihaofzh opened this issue Feb 20, 2012 · 3 comments
Labels

Comments

@fuzihaofzh
Copy link

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;
}
@mrdoob
Copy link
Owner

mrdoob commented Feb 20, 2012

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

@mrdoob mrdoob closed this as completed Feb 21, 2012
@zhhuan
Copy link

zhhuan commented Jan 23, 2018

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

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 23, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants