1.對(duì)象合并

    使用THREE.Group對(duì)象作為組合對(duì)象,調(diào)用它的add函數(shù)附加其他幾何體。如下面的代碼,創(chuàng)建了兩個(gè)幾何體sphere、cube,然后調(diào)用group的add函數(shù),把兩個(gè)幾何體組合在一起。代碼中的redraw函數(shù)在最后調(diào)用了position.BoundingBox()函數(shù),用來(lái)定位組合體對(duì)象的位置。在positionBoundingBox函數(shù)中調(diào)用了setFromeObject并且返回了一個(gè)THREE.Box3對(duì)象。這里先不介紹這個(gè)對(duì)象,直接看后面的代碼,通過(guò)box.max和box.min的兩個(gè)位置對(duì)象,計(jì)算出了BoxGeometry的width、height、depth。最后也通過(guò)這兩個(gè)位置對(duì)象計(jì)算出bboxMesh的position值。

seo優(yōu)化培訓(xùn),網(wǎng)絡(luò)推廣培訓(xùn),網(wǎng)絡(luò)營(yíng)銷培訓(xùn),SEM培訓(xùn),網(wǎng)絡(luò)優(yōu)化,在線營(yíng)銷培訓(xùn)

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

網(wǎng)友評(píng)論