我想要使用three.js的STLLoader函數加載一個心臟模型的橫截面。我目前正在嘗試使用ThreeCSG包裝器作爲csg.js庫,與this stack overflow post中的相同。使用three.js STL對象的橫截面
這裏是我的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模型,然後在裝載機的回調函數,我嘗試減去網格。我得到的錯誤是在ThreeCSG包裝文件的第34行,說
ThreeCSG.js:34 Uncaught TypeError: Cannot read property 'length' of undefined
我猜這是因爲(a)我不使用ThreeCSG proprerly,(B)我需要做的減去代碼中的其他位置,或者(c)不支持STL格式模型。
在任何情況下,我完全難住,並會感謝有人使用three.js更有經驗的人的建議。
我在腳本中有同樣的錯誤。我想這裏是對我們的問題unswer https://stackoverflow.com/questions/20602045/csg-operation-with-stlloader/20724436#20724436 – user2075609
可能會使用obj loader在我的情況 – user2075609
由於我只需要橫斷面在我寫了我自己的着色器程序。在片段着色器中,我只是檢查給定的頂點是否超出了切割平面,如果是,則丟棄該頂點。 if(view == 1 && vPosition.z> 0.0)discard; - 視圖描述選定的切割平面。 [Here](http://gamedevelopment.tutsplus.com/tutorials/a-beginners-guide-to-coding-graphics-shaders--cms-23313)是着色器教程。 –