5

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 :

  • Will using buffer geometry speed up my CSG, but that said is there any library to perform CSG operations on THREE.BufferGeometry instances?

  • Is there a way I can speed up the process by using any other methods ?

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.

2 Answers 2

5
+50

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.