IGLBody

Module: geometry

Represents a geometric body in an OpenGL-based viewer. This class extends IGLGeometry to handle body-level geometry, including faces, edges, and associated data for rendering and picking in a 3D graphics context. It supports loading from JSON data and building indexed meshes for efficient rendering.

__init__

method
__init__(self, geom_id: int, name: str, selectable: bool)
Initializes an IGLBody instance.

Args

Name Type Description
geom_id Unique identifier for the geometry object.
name Human-readable name for the body.
selectable Whether the body can be selected in the viewer.

LoadJson

method
LoadJson(self, b: Dict[str, Any])
Loads body geometry data from a JSON dictionary.

Parses the JSON to set up the body's type, properties, and mesh data.
Supports solid, surface, and line body types, building vertices, triangles,
and edges as needed for OpenGL rendering.

Args

Name Type Description
b Dictionary containing body data from JSON, including BodyID, BodyName, BodyType, Shape, etc.

GetFaceIds

method
GetFaceIds(self)
Retrieves the global face IDs for the body's triangles.

Returns

An array of global face IDs corresponding to each triangle, or None if not set. Shape: (M,) where M is the number of triangles.

build_indexed_mesh

method
build_indexed_mesh(self, shape: Dict[str, Any])
Builds an indexed triangle mesh from shape data.

Processes face data to create a unified vertex list and triangle indices,
along with global face IDs. Computes bounding boxes, centers, and other
face-level data for efficient ray picking and rendering.

Args

Name Type Description
shape Dictionary containing shape data, including "Faces" with nodes, triangles, GID, etc.

Returns

A tuple of (vertices, indices, face_gid): - vertices: Array of unique vertex positions. Shape: (N, 3). - indices: Array of triangle indices into vertices. Shape: (M, 3). - face_gid: Array of global face IDs for each triangle. Shape: (M,).

build_edges

method
build_edges(self, edges: List[Any])
Builds edge geometry from a list of polylines.

Converts a list of edge polylines into a contiguous array of line segments
for OpenGL rendering as lines.

Args

Name Type Description
edges List of polylines, where each polyline is a list of 3D points.

Returns

A contiguous array of edge vertices for line rendering, or None if no valid edges. Shape: (2*K, 3) where K is the number of segments.

build_edges_with_ids

method
build_edges_with_ids(self, edges: List[Any])
Builds edge geometry with associated edge IDs from a list of polylines.

Similar to build_edges, but also assigns a unique ID to each original
polyline for identification purposes.

Args

Name Type Description
edges List of polylines, where each polyline is a list of 3D points.

Returns

A tuple of (vertices, edge_ids): - vertices: Contiguous array of edge vertices, or None. Shape: (2*K, 3). - edge_ids: Array of edge IDs corresponding to vertices, or None. Shape: (2*K,).

GetFaceIdList

method
GetFaceIdList(self)
Retrieves a list of all global face IDs in the body.

Returns

A list of unique global face IDs from FData.