bufferGeometry 上的 CSG 操作

CSG operations on bufferGeometry

我目前正在使用 three.js 几何体 class 创建形状,然后对该形状执行多个 CSG 操作。从而不断重绘形状。

这个执行多个 csg 操作的过程很慢,因为我使用光线投射在单击时获取形状并对所选形状和预定义形状(任何形状或几何形状)执行 CSG。

所以我的问题是:

这是我的代码流:

var objects = [];

init();
render();

function init(){
 //scene and camera setup ... etc
   var sphere =  new THREE.SphereGeometry(200, 32, 32);
   objects.push(sphere);
 // raycasting config
 // bind mouse click and move event
 }
  function onMouseDown() {

   var intersects = raycaster.intersectObjects(objects);
   .....
   // get intersected shape ..
   // perfrom csg with predifend shape .
   // Also contains steps to convert 
      geometry to *CSG libaray geometry* 
      and back to Three.js geometry)..
   // replace the shape with existing
   .....
    render();
 }

我在 three.js 个示例中使用 this library for CSG operations and overall flow is similar to this example

我没有用于性能比较的元素,但您可以在 Wilt

的 ThreeCSG ThreeCSG develop 的开发分支中找到一个 buffergeometry 库

它支持 buffergeometry(来自示例):

var nonIndexedBoxMesh = new THREE.Mesh( nonIndexedBufferGeometry, material );
var bsp1 = new ThreeBSP( nonIndexedBoxMesh );
var indexedBoxMesh = new THREE.Mesh( indexedBufferGeometry, material );
var bsp2 = new ThreeBSP( indexedBoxMesh );
var geometry = bsp1.subtract( bsp2 ).toBufferGeometry();
var mesh = new THREE.Mesh( geometry, material );

它适用于 r75