2013-09-16 86 views
0

我需要管理對象組的位置作爲一個項目。如何在一個對象中組合兩個立方體?

我:

tankMesh1 = new THREE.Mesh(geometry, material); 
tankMesh2 = new THREE.Mesh(geometry, material); 
scene.add(tankMesh1); 
scene.add(tankMesh2); 

tankMesh2.position = tankMesh2.position + offset * cos (angle) 

我需要:

tankMeshBig = new THREE.Mesh(tankMesh1 , tankMesh2); 

例子:http://jsfiddle.net/ksRyQ/2287/

+0

[three.js - mesh group example? (THREE.Object3D()高級)](http://stackoverflow.com/questions/7985805/three-js-mesh-group-example-three-object3d- advanced) –

+0

請參閱'THREE.GeometryUtils.merge()'in [文檔](http://threejs.org/docs/#Reference/Extras/GeometryUtils)。 – WestLangley

回答

1

您可以使用一個新的THREE.Object3D()

JS:

var group=new THREE.Object3D(); 

tankMesh1 = new THREE.Mesh(geometry, material); 
group.add(tankMesh1); 

geometry = new THREE.CubeGeometry(3, 2, 5); 
tankMesh2 = new THREE.Mesh(geometry, material); 
tankMesh2.position.y = 3; 
group.add(tankMesh2); 

group.rotation.y = 3.141/3; 

scene.add(group); 

http://jsfiddle.net/zYLSC/

+0

如果您打算採用這種方法,那麼在您的小提琴中,您應該翻譯/旋轉組,而不是網格本身。 – WestLangley

+0

好點,我已經更新了答案。 – simonzack

相關問題