Currently, I am attempting to create a cross section of a heart model that I have imported using the STLLoader function in three.js. To achieve this, I am experimenting with the ThreeCSG wrapper for the csg.js library, similar to the approach outlined in this helpful Stack Overflow post.
Below is the snippet of code where I perform 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 and then proceed to attempt mesh subtraction within the loader's callback function. However, I encounter an error message on line 34 of the ThreeCSG wrapper file:
ThreeCSG.js:34 Uncaught TypeError: Cannot read property 'length' of undefined
This error has led me to ponder whether the issue lies in my usage of ThreeCSG, if the subtraction should be performed elsewhere in the code, or perhaps STL models are not supported.
In light of this dilemma, I find myself at an impasse and seek guidance from individuals well-versed in the intricacies of working with three.js.