I'm trying to take a cross section of a heart model that I loaded using three.js's STLLoader function. I'm currently trying to use the ThreeCSG wrapper for the csg.js library, same as in this stack overflow post.
Here's my code for the csg subtraction
function modelLoadedCallBack( geometry ) {
material = new THREE.MeshPhongMaterial( { color: model.color } );
mesh = new THREE.Mesh( geometry, material );
mesh.rotation.set( model.rotationX, model.rotationY, model.rotationZ );
mesh.scale.set( model.scale, model.scale, model.scale );
var originalBSP = new ThreeBSP( mesh );
var xSectionBSP = new ThreeBSP( xSection );
var subtractedBSP = originalBSP.subtract( xSectionBSP );
var result = subtractedBSP.toMesh( material );
result.geometry.computeVertexNormals();
scene.add( result );
};
I load the stl model, then in the loader's callback function, I try to subtract the meshes. The error I'm getting is on line 34 of the ThreeCSG wrapper file, saying
ThreeCSG.js:34 Uncaught TypeError: Cannot read property 'length' of undefined
I'm guessing this is because (a) I'm not using ThreeCSG proprerly, (b) I need to do the subtraction somewhere else in the code, or (c) STL format models are not supported.
In any case, I'm completely stumped and would appreciate the advice of someone more experienced in using three.js.