How to clone an object3d in Three.js?

2019-01-18 23:37发布

I want to clone a model loaded with loader, I found this issue on github,but the solution doesn't work. It seems there has been an structural change in Object3D.

How can I clone an Object3D in current stable version of Three.js?

2条回答
smile是对你的礼貌
2楼-- · 2019-01-18 23:38

Actually mrdoob's answer is your answer...

The loader output a geometry you use to create a mesh. You need to create a new mesh with the loader-created mesh's geometry and material.

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

You want to clone a Mesh and not an Object3D because the output of the loader is a Mesh.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-18 23:54

In this new version of three.js you have a method clone.

For example, I use a queen from chess and I had to duplicate multiple times:

// queen is a mesh
var newQueen = queen.clone();

// make sure to re position to be able to see the new queen!
newQueen.position.set(100,100,100); // or any other coordinates

It will work with any mesh.

I used three.js r61.

查看更多
登录 后发表回答