parq_blockmodel.mesh.triangulation.BlockMeshGenerator#

class parq_blockmodel.mesh.triangulation.BlockMeshGenerator(geometry)[source]#

Convert a block model to a triangulated surface mesh.

This class generates vertex and face arrays from a RegularGeometry and optional block attribute data. Supports both rotated and non-rotated geometries, sparse and dense block layouts, and surface-only vs. full interior mesh generation.

Coordinates are always in world space (right-handed), with rotation applied via the RegularGeometry’s axis vectors (axis_u, axis_v, axis_w).

Parameters:

geometry (RegularGeometry) – The block model geometry defining corner, block_size, shape, and axis orientation.

geometry#

The block model geometry.

Type:

RegularGeometry

Notes

All generated triangles use counter-clockwise (CCW) winding order when viewed from the exterior (right-hand rule). This ensures compatibility with standard 3D graphics renderers and PLY/GLB viewers.

__init__(geometry)[source]#

Initialize the mesh generator with a block model geometry.

Parameters:

geometry (RegularGeometry) – The block model geometry. Must have orthonormal axis vectors.

Raises:

ValueError – If the geometry’s axis vectors are not properly oriented.

Methods

__init__(geometry)

Initialize the mesh generator with a block model geometry.

block_corners_local()

Get the 8 corner offsets for a unit cube in local (i, j, k) space.

block_vertices_xyz(i, j, k)

Get the 8 vertices of a block in world coordinates.

cube_faces_ccw()

Get the 6 faces of a cube with CCW winding (right-hand rule).

surface_faces_ccw()

Get only the exterior surface faces of a cube.

triangulate([block_data, surface_only, sparse])

Generate a triangle mesh from block model data.

block_corners_local()[source]#

Get the 8 corner offsets for a unit cube in local (i, j, k) space.

Returns a (8, 3) array where each row is a corner offset: (0,0,0), (1,0,0), (0,1,0), (1,1,0), (0,0,1), (1,0,1), (0,1,1), (1,1,1).

Returns:

Shape (8, 3), corner offsets in local space.

Return type:

np.ndarray

block_vertices_xyz(i, j, k)[source]#

Get the 8 vertices of a block in world coordinates.

Parameters:
  • i (int) – Logical block indices.

  • j (int) – Logical block indices.

  • k (int) – Logical block indices.

Returns:

Shape (8, 3), corner coordinates in world space.

Return type:

np.ndarray

cube_faces_ccw()[source]#

Get the 6 faces of a cube with CCW winding (right-hand rule).

Each face is a pair of triangles sharing an edge. Winding order is such that the outward normal points away from the cube center.

Local vertex numbering:

0: (0,0,0) 1: (1,0,0) 2: (0,1,0) 3: (1,1,0) 4: (0,0,1) 5: (1,0,1) 6: (0,1,1) 7: (1,1,1)

Returns:

Shape (12, 3), 12 triangles (2 per face, 6 faces).

Return type:

np.ndarray

surface_faces_ccw()[source]#

Get only the exterior surface faces of a cube.

For a sparse block model, we typically want only faces on the boundary of the model. This method returns which faces are “exterior” in a dense grid context. When sparse blocks are present, we’ll filter out internal faces via connectivity checks.

Returns the same 12 triangles as cube_faces_ccw(), but this is a placeholder for future boundary detection logic.

Returns:

Shape (12, 3), exterior triangles.

Return type:

np.ndarray

triangulate(block_data=None, surface_only=True, sparse=None)[source]#

Generate a triangle mesh from block model data.

Parameters:
  • block_data (pd.DataFrame, optional) – Block model data with columns like “i”, “j”, “k”, “grade”, “density”, etc. If provided, attributes will be mapped to the mesh. If None, only geometry is returned with no attribute data.

  • sparse (bool, optional) – If True, include only blocks present in block_data. If False or None, generate the full dense mesh. If sparse=True but block_data is None, only non-empty blocks are included.

  • surface_only (bool, default True) – If True, include only exterior surface faces (shared faces with adjacent blocks are removed). If False, include all faces (interior voids remain empty). Only meaningful for sparse models.

Returns:

The generated mesh with vertices, faces, and optional attributes.

Return type:

TriangleMesh

Raises:

ValueError – If block_data is incompatible with the geometry.