Why isn't a hole created in the mesh?

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:

  1. I’m working on converting a Mesh3D object to a Babylon.js mesh, including holes in the mesh.
  2. 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.
  1. 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.
  2. 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

  1. 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
);

  1. In both approaches (PolygonMeshBuilder and ExtrudePolygon), 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.
  1. 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

  1. Why does the hole data in _holes not result in a visible hole in the rendered mesh?
  2. Is there an issue with how the depth or normals are being handled?
  3. Are there any additional steps needed to correctly process holes using PolygonMeshBuilder or ExtrudePolygon?

Additional Context

  • Data verification:
    • The com_isClockwise function confirms that the holes are counter-clockwise.
    • Logs show correct data being passed to both PolygonMeshBuilder and ExtrudePolygon.
  • Material:
    • Backface culling is disabled (backFaceCulling = false), so both sides are rendered.
    • Normals are recalculated using forceSharedVertices() and createNormals(true).

Attached Images

  1. Base Mesh (First Image)
  2. Defined Hole Region (Second Image)
  3. Tilted View (Third Image)
  4. Top-down View (Fourth Image)

Any insights or suggestions would be greatly appreciated. Thank you in advance! :blush:




Can you make a simple repro of the problem in the Playground, so that we can help you more easily? Thanks in advance!

3 Likes