Hi everyone, I’m having trouble rendering holes in a mesh using both PolygonMeshBuilder
and MeshBuilder.ExtrudePolygon
. Here’s a detailed explanation of my setup and the issue:
- I’m working on converting a Mesh3D object to a Babylon.js mesh, including holes in the mesh.
- The holes and shape are properly defined and logged in the console:
- The shape is a list of
Vector2
points defining the outer boundary. - The holes are lists of
Vector2
points, with each hole being counter-clockwise.
- I use Redux to manage the state of the mesh. When the shape or holes are updated, Redux triggers a re-rendering of the mesh.
- The holes are processed and added using the following logic in
PolygonMeshBuilder
:
const extrudeMesh = new PolygonMeshBuilder(mesh3D.name, c_shape, scene, earcut);
holes.forEach(hole => extrudeMesh.addHole(hole));
const mesh = extrudeMesh.build(false, mesh3D.metadata?.STRV3_THICKNESS); // depth
- I also tried generating the same mesh using
MeshBuilder.ExtrudePolygon
as follows:
const extrudeOptions = {
shape: c_shape.map(v => new Vector3(v.x, 0, v.y)),
holes: holes.map(hole => hole.map(v => new Vector3(v.x, 0, v.y))),
depth: mesh3D.metadata?.STRV3_THICKNESS,
sideOrientation: Mesh.DOUBLESIDE
};
const mesh2 = MeshBuilder.ExtrudePolygon(
mesh3D.name + ‘_test’,
extrudeOptions,
scene,
earcut
);
- In both approaches (
PolygonMeshBuilder
andExtrudePolygon
), the logs indicate that the_holes
property contains the correct data:
- _holes: Data is present and correctly formatted.
- _points: Shape is correct.
- _depth: Correct depth is set.
- However, in the rendered mesh:
- From above: The mesh appears flat, and the holes are not visible.
- From the side: There seems to be a “wall” in the hole regions, suggesting that the hole is being partially processed.
Questions
- Why does the hole data in
_holes
not result in a visible hole in the rendered mesh? - Is there an issue with how the depth or normals are being handled?
- Are there any additional steps needed to correctly process holes using
PolygonMeshBuilder
orExtrudePolygon
?
Additional Context
- Data verification:
- The
com_isClockwise
function confirms that the holes are counter-clockwise. - Logs show correct data being passed to both
PolygonMeshBuilder
andExtrudePolygon
.
- The
- Material:
- Backface culling is disabled (
backFaceCulling = false
), so both sides are rendered. - Normals are recalculated using
forceSharedVertices()
andcreateNormals(true)
.
- Backface culling is disabled (
Attached Images
- Base Mesh (First Image)
- Defined Hole Region (Second Image)
- Tilted View (Third Image)
- Top-down View (Fourth Image)
Any insights or suggestions would be greatly appreciated. Thank you in advance!