2
votes

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.

1
I have the same error in my script. I suppose here is the unswer to our question stackoverflow.com/questions/20602045/… - user2075609
will probably use obj loader in my situation - user2075609
Since I only needed cross-sections at specific planes, I wrote my own shader program. In the fragment shader, I simply check if the given vertex is beyond the cutting plane and if it is, I discard that vertex. if ( view == 1 && vPosition.z > 0.0 ) discard; - view describes the selected cutting plane. Here is a tutorial on shaders. - Rahat Dhande

1 Answers

0
votes

It looks correct. This error can happen if either the STL geometry is empty or if you forgot to initialize xSection.