1. 程式人生 > >threejs 第十八用 BSP

threejs 第十八用 BSP

var g = new THREE.BoxGeometry(2, 2, 2);
var m = new THREE.MeshLambertMaterial({ color: 0xff0000 })
        var cube2=new THREE.Mesh(g,m);
var sphereGeometry = new THREE.SphereGeometry(2, 50, 50);
        var sphere =new THREE.Mesh(sphereGeometry,m);

       var bsp1=new ThreeBSP(sphere);
	   var bsp2=new ThreeBSP(cube2);
var meshbsp=(bsp1.union(bsp2)).toMesh(); //intersect  union  subtract
	   meshbsp.geometry.computeFaceNormals();
	   meshbsp.geometry.computeVertexNormals();
 

	   meshbsp.material=m;
	   s.add(meshbsp)

需要標頭檔案ThreeBSP.js

神奇的交 差 並 功能 但是跟merge有點像 好像紋理會受影響 

上面那個程式碼會返回一個球和立方體相交的部分 作為最終繪製的幾何圖形