Three.js 3.js平面几何体夹在墙内

Three.js 3.js平面几何体夹在墙内,three.js,Three.js,我想用Three.js制作一个3D建筑。例如,我用棋盘格纹理制作了6面墙和一个地板。我对wall1和wall4使用了裁剪平面: floor1.material.clippingPlanes = [plane1,plane4]; 我用墙(墙1和墙4)做了飞机(平面1和平面4)。例如,我的wall4 planeGeometry和plane4代码如下: var wallGeometry4=新的三个平面几何图形(40,楼层高度,1,1); var wall4=createMesh(wallGeom

我想用Three.js制作一个3D建筑。例如,我用棋盘格纹理制作了6面墙和一个地板。我对wall1和wall4使用了裁剪平面:

floor1.material.clippingPlanes = [plane1,plane4];

我用墙(墙1和墙4)做了飞机(平面1和平面4)。例如,我的wall4 planeGeometry和plane4代码如下:

var wallGeometry4=新的三个平面几何图形(40,楼层高度,1,1);
var wall4=createMesh(wallGeometry4,“brick_diffuse.jpg”,三个双面,10241024);
单元1.添加(墙4);
位置x=-10;
墙4.位置y=0;
墙4.位置z=-20;
wall4.rotation.y=1.5*Math.PI;
wall4.添加(新的三个EdgeHelper(wall4,0x000000));
var plane4=新的三个平面();
var normal4=新的3.Vector3();
var point4=新的3.Vector3();
normal4.集(0,0,-1).应用四元数(wall4.四元数);
点4.复制(墙4.位置);

平面4.从法线和共面点(法线4,点4)设置实现这一点的一种方法是使用ShapeGeometry

points = [{x:0,y:0},{x:0,y:10},{x:10,y:10},{x:10,y:0},{x:0,y:0}]

function getShapeFromPoints(points){
    const shape = new THREE.Shape();
    shape.moveTo(points[0].x, points[0].y);
    for (let i = 1; i < points.length; i++) {
        shape.lineTo(points[i].x, points[i].y);
    }
    return shape;
}

function createPlaneFromPoints(points) {
    const planeMaterial = getPlaneMaterial();
    const shape = getShapeFromPoints(points);
    const geometry = new THREE.ShapeBufferGeometry(shape);
    geometry.rotateX(degreeToRadians(-90));
    const mesh = new THREE.Mesh(geometry, planeMaterial);
    return mesh;
}
创建墙时,可以将其起点和终点的x和z坐标保存在阵列中,以形成矢量2点的循环。然后,可以使用shapeGeometry从这些点创建新的自定义形状

points = [{x:0,y:0},{x:0,y:10},{x:10,y:10},{x:10,y:0},{x:0,y:0}]

function getShapeFromPoints(points){
    const shape = new THREE.Shape();
    shape.moveTo(points[0].x, points[0].y);
    for (let i = 1; i < points.length; i++) {
        shape.lineTo(points[i].x, points[i].y);
    }
    return shape;
}

function createPlaneFromPoints(points) {
    const planeMaterial = getPlaneMaterial();
    const shape = getShapeFromPoints(points);
    const geometry = new THREE.ShapeBufferGeometry(shape);
    geometry.rotateX(degreeToRadians(-90));
    const mesh = new THREE.Mesh(geometry, planeMaterial);
    return mesh;
}
points=[{x:0,y:0},{x:0,y:10},{x:10,y:10},{x:10,y:0},{x:0,y:0}]
函数getShapeFromPoints(点){
const shape=new THREE.shape();
shape.moveTo(点[0].x,点[0].y);
for(设i=1;i

希望对你有帮助

THREE.Plane()
是一个无限的数学平面。我该怎么办?我怎样才能正确地填充地板?不是吗?作为一个选项:你知道你的墙的尺寸,因此你可以获得角点,然后从它们构建一个形状几何体。另一个选项:使用交叉点剪裁来切出你的角点。另一个选择是,不要使用clippingPlanes,而是在快速
着色器材质中编写自己的剪辑