我正在尝试使用three.js的STLLoader函数来加载心脏模型的横截面。我目前正在尝试使用ThreeCSG库的csg.js包装器,与this stack overflow post中的相同。
这是我的csg减法代码
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 );
};
我加载了stl模型,然后在loader的回调函数中,我尝试减去网格。我得到的错误是在ThreeCSG包装文件的第34行,说
ThreeCSG.js:34未捕获的TypeError:无法读取未定义的属性'length'
我猜这是因为(a)我没有使用ThreeCSG,(b)我需要在代码中的其他地方进行减法,或者(c)不支持STL格式模型。
在任何情况下,我都很难过,并且会很感激使用three.js的人的建议。
答案 0 :(得分:0)
看起来很正确。如果STL几何为空或者您忘记初始化xSection,则会发生此错误。