javascriptthree.jsbuffer-geometrythreecsg

CSG operations on bufferGeometry


I am currently using the three.js geometry class for creating a shape and then performing multiple CSG operations on that shape. Thus continuously redrawing the shape.

This process of performing multiple csg operations is slow, as I am using ray-casting to get the shape on click and perform CSG of the selected shape and a pre-defined shape (any shape or geometry).

So my questions are :

This is my code-flow :

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

I am using this library for CSG operations and overall flow is similar to this example in three.js examples.


Solution

  • I don't have element for performance comparison, but you can find a buffergeometry library in develop branch of ThreeCSG ThreeCSG develop from Wilt

    It support buffergeometry (from examples):

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

    It works with r75