picogl.renderer.glmesh

A module for GPU-resident indexed and non-indexed geometry.

This module defines the GLMesh class, which represents a 3D mesh stored on the GPU. It provides mechanisms for defining a mesh’s vertices, faces, colors, normals, UVs, and vertex layout, along with functionality for uploading these attributes to GPU buffers and expanding indexed meshes into per-triangle vertex lists if needed.

Classes

GLMesh

GPU-resident geometry: owns VAO/VBO and optional EBO/CBO/NBO buffers.

Functions

expand_triangle_vertices_and_colors(a, b, c, colors, ...) → None

expand_triangle_vertices_and_colors

empty_triangle_vertices(triangle_count[, components]) → numpy.ndarray

empty_triangle_vertices

Module Contents

picogl.renderer.glmesh.expand_triangle_vertices_and_colors(a: int, b: int, c: int, colors: numpy.ndarray, expanded_colors: numpy.ndarray, expanded_vertices: numpy.ndarray, triangle_index: int, vertices: numpy.ndarray) → None[source]

expand_triangle_vertices_and_colors

picogl.renderer.glmesh.empty_triangle_vertices(triangle_count: int, components: int = 3) → numpy.ndarray[source]

empty_triangle_vertices

class picogl.renderer.glmesh.GLMesh(vertices: numpy.ndarray, faces: numpy.ndarray | None = None, colors: numpy.ndarray | None = None, normals: numpy.ndarray | None = None, uvs: numpy.ndarray | None = None, use_indices: bool = True, *, shader_type: Literal[picogl.shaders.type.ShaderType.ISOSURFACE, picogl.shaders.type.ShaderType.RIBBONS, picogl.shaders.type.ShaderType.TEXTURES] = ShaderType.ISOSURFACE, registry_label: str | None = None)[source]

Bases: picogl.gpu.buffers.mesh_owner.MeshDataOwner

GPU-resident geometry: owns VAO/VBO and optional EBO/CBO/NBO buffers. It does not know anything about shaders or matrices.

vao: picogl.backend.modern.core.vertex.array.object.VertexArrayObject | None = None[source]
index_count: int = 0[source]
mesh: picogl.renderer.meshdata.MeshData | None = None[source]
vertices[source]
indices[source]
use_indices[source]
shader_type[source]
_registry_label = None[source]
colors[source]
normals[source]
uvs[source]
_expanded_vertices = None[source]
_expanded_colors = None[source]
_expanded_normals = None[source]
_expanded_uvs = None[source]
_layout_descriptor[source]
_get_buffer_data(vbo_type: picogl.gpu.buffers.vertex.vbo.vbo_class.VBOType) → numpy.ndarray | None[source]

get_buffer_data(vbo_type) -> np.ndarray

_expand_to_non_indexed() → None[source]

Expand the mesh so that every triangle has its own copy of vertices/colors/normals/uvs. This converts indexed data (shared vertices) into a per-triangle vertex list suitable for glDrawArrays. The API remains the same; just keep the EBO empty and set index_count accordingly.

classmethod from_mesh_data(mesh: picogl.renderer.meshdata.MeshData, *, vertex_layout: picogl.shaders.type.ShaderType.ISOSURFACE | picogl.shaders.type.ShaderType.RIBBONS | picogl.shaders.type.ShaderType.TEXTURES = ShaderType.ISOSURFACE, registry_label: str | None = None) → GLMesh[source]

Construct a GLMesh from a MeshData container.

Parameters:
  • mesh (MeshData) – Must have vertices (Nx3). Indices are optional; geometry without indices is rendered directly with glDrawArrays.

  • vertex_layout – surface → attr order pos, color, normal (surface_with_lighting / mesh). ribbon → pos, normal, color (ribbons).

Returns:

Ready-to-upload mesh (GPU buffers are allocated only when upload() is called).

Return type:

GLMesh

_color_attrib_index() → int[source]

Vertex attribute index for the color buffer in this mesh layout.

update_colors(colors: numpy.ndarray)[source]
upload() → None[source]

Allocate & fill GPU buffers.

bind()[source]
unbind()[source]
delete()[source]

Free GPU resources.

__enter__()[source]
__exit__(exc_type, exc, tb)[source]
draw(mode: picogl.backend.gl.enums.GLDrawMode | None = None) → None[source]

Draw via attached MeshData when its CPU arrays are intact.

Callers that copy arrays into this object then drop the MeshData CPU buffers (MeshData.delete) fall back to execute_draw_spec() using the uploaded VAO and index_count. mode overrides the mesh MeshDrawSpec when given (gizmo line draws).