1.对象合并
使用THREE.Group对象作为组合对象,调用它的add函数附加其他几何体。如下面的代码,创建了两个几何体sphere、cube,然后调用group的add函数,把两个几何体组合在一起。代码中的redraw函数在最后调用了position.BoundingBox()函数,用来定位组合体对象的位置。在positionBoundingBox函数中调用了setFromeObject并且返回了一个THREE.Box3对象。这里先不介绍这个对象,直接看后面的代码,通过box.max和box.min的两个位置对象,计算出了BoxGeometry的width、height、depth。最后也通过这两个位置对象计算出bboxMesh的position值。
this.redraw = function () {
scene.remove(group);
sphere = createMesh(new THREE.SphereGeometry(5, 10, 10));
cube = createMesh(new THREE.CubeGeometry(6, 6, 6));
sphere.position.set(controls.spherePosX, controls.spherePosY, controls.spherePosZ);
cube.position.set(controls.cubePosX, controls.cubePosY, controls.cubePosZ);
group = new THREE.Group();
group.add(sphere);
group.add(cube);
scene.add(group);
controls.positionBoundingBox();  


