bufferGeometry上的CSG操作

CSG operations on bufferGeometry

本文关键字:操作 CSG 上的 bufferGeometry      更新时间:2023-09-26

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

执行多个csg操作的过程很慢,因为我使用光线投射来获得点击时的形状,并执行选定形状和预定义形状(任何形状或几何体)的csg。

所以我的问题是:

  • 使用缓冲区几何结构会加快我的CSG吗,但也就是说,有任何库可以在THREE.BufferGeometry实例上执行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();
 }

我使用这个库进行CSG操作,总体流程与三个.js示例中的这个示例类似。

我没有性能比较的元素,但你可以在ThreeCSG ThreeCSG的开发分支中找到一个从Wilt 开发的缓冲池库

它支持缓冲测量(来自示例):

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 一起工作