damitj07
damitj07

Reputation: 2899

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.

Upvotes: 5

Views: 1289

Answers (2)

jgphilpott
jgphilpott

Reputation: 649

For CSG performance improvements I highly recommend taking a look at this OctreeCSG repo! It uses a newer method known as Octree-Embedded BSPs for a nearly 1000X performance increase (details here)!

I don't think whether you're using standard Geometry or BufferGeometry will make a big difference (if any). The main performance catalyst is the underlying CSG algorithm.

Upvotes: 0

Davide Necchi
Davide Necchi

Reputation: 796

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

Upvotes: 5

Related Questions