有没有办法在THREE.JS中裁剪模型?
例如我有这个模型:
知道我想把他从腰带上扯下来,就像这样:
有办法吗?
也许创建一个立方体并将其定位以覆盖腿部,然后以某种方式移除模型中与立方体相交的所有部分......
感谢。
[更新]
我想我找到了一个适合我的解决方案,
我想改进它并替换PointInsideBBOX以检查顶点或面是否碰撞或在第二个网格内部,任何想法?
这个解决方案对我来说更好,因为所有纹理和骨骼动画都很完美。
mesh.material.materials.push( new THREE.MeshBasicMaterial({visible: false}));
var matIndex = mesh.material.materials.length - 1;
function PointInsideBBOX(point,box) {
if (
point.x>=box.x1 && point.x<=box.x2 &&
point.y>=box.y1 && point.y<=box.y2 &&
point.z>=box.z1 && point.z<=box.z2
) return true;
return false;
}
var box = {
x1: -0.25 , y1: -0.5 , z1: -0.25 ,
x2: 0.25 , y2: 0.5 , z2: 0.25 ,
};
for(var i=0; i<mesh.geometry.faces.length; i++) {
var face = mesh.geometry.faces[i];
if ( !PointInsideBBOX(mesh.geometry.vertices[face.a],box) ||
!PointInsideBBOX(mesh.geometry.vertices[face.b],box) ||
!PointInsideBBOX(mesh.geometry.vertices[face.c],box)
) continue;
face.materialIndex = matIndex;
}
mesh.geometry.elementsNeedUpdate = true;
&#13;
答案 0 :(得分:2)
您可以尝试使用此项目https://github.com/chandlerprall/ThreeCSG
var cube_geometry = new THREE.CubeGeometry(10,10,10);
var cube_mesh = new THREE.Mesh(cube_geometry);
cube_mesh.position.x = x;
cube_mesh.position.y = 0; //y;
cube_mesh.position.z = z;
var CutBSP = new ThreeBSP(cube_mesh);
var ModelBSP = new ThreeBSP(mesh); //<---- your THREE Mesh
var EditiedBSP = ModelBSP.subtract(CutBSP);
var result = EditiedBSP.toMesh(new THREE.MeshLambertMaterial({shading: THREE.SmoothShading}));
result.geometry.computeVertexNormals();
mesh.geometry = result.geometry; //<---- your NEW Geometry