three.js - mesh group example? (THREE.Object3D() advanced)

ぃ、小莉子 提交于 2019-11-30 10:46:20

The dragging will be a bit more tricky because you need to work out where would the x/y positions of the mouse on the screen (screen space) will be in the 3D world, then you will need to cast a ray and check if it intersects the object you want to drag. I presume this will be a different question.

Setting object hierarchy is fairly simple. As you hinted, you will use a THREE.Object3D instance to nest objects into using it's add() method. The idea is that you will use a Mesh for objects that have geometry, and Object3D instances, where you simply need to nest elements. I suggest starting with the canvas_geometry_hierarchy sample.

The interesting bits are:

group = new THREE.Object3D();//create an empty container
group.add( mesh );//add a mesh with geometry to it
scene.add( group );//when done, add the group to the scene

another way, because a mesh can be a parent too

meshParent.add(meshChild1);
meshParent.add(meshChild2);
scene.add(meshParent);

or

mesh1.add(mesh2);
mesh3.add(mesh1);
scene.add(mesh3);

mesh3 manipulates all meshes, mesh1 manipulates itself and mesh2, mesh2 manipulates itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!