picogl.renderer.meshdata
Provides functionality for managing OpenGL mesh data, including vertices, normals, texture coordinates, colors, and indices. This class offers a set of utilities to handle OpenGL-related state objects and simplify rendering workflows.
Classes
Representation of mesh data for OpenGL rendering. |
Module Contents
- class picogl.renderer.meshdata.MeshData(vertices: numpy.ndarray = None, normals: numpy.ndarray = None, texcoords: numpy.ndarray = None, colors: numpy.ndarray = None, indices: numpy.ndarray = None)[source]
Representation of mesh data for OpenGL rendering.
This class encapsulates mesh data and provides utilities for setting up and managing vertex attributes such as positions, normals, texture coordinates, colors, and indices. It enables interoperability with OpenGL through context management and binding/unbinding functions. Additionally, the class includes methods for raw data conversion and generation of default attributes.
- as_canonical_names()[source]
Converts the mesh data into a dictionary with canonical attribute names.
- draw()[source]
Draws the mesh with optional OpenGL parameters for color, line width, drawing mode, fill mode, and alpha transparency.
- classmethod _to_float32_flat(arr, name: str, required: bool = False) numpy.ndarray[source]
- classmethod _to_float32_flat_or_none(arr, name: str) numpy.ndarray[source]
- classmethod _to_int32_flat(arr, name: str, required: bool = False) numpy.ndarray[source]
- classmethod _default_colors_for_vertices(vertex_count: int) numpy.ndarray[source]
- classmethod _default_normals_for_vertices(vertex_count: int) numpy.ndarray[source]
- classmethod from_raw(vertices: numpy.ndarray | list[float], normals: numpy.ndarray | list[float] | None = None, uvs: numpy.ndarray | list[float] | None = None, colors: numpy.ndarray | list[float] | None = None, indices: numpy.ndarray | list[float] | None = None, color_per_vertex: numpy.ndarray | list[float] | None = None)[source]
Build a MeshData from raw/python inputs.
- Parameters:
vertices – np.ndarray required, list/array of x,y,z triplets
normals – np.ndarray optional, list/array of x,y,z triplets
uvs – np.ndarray optional, list/array of u,v pairs
indices – np.ndarray optional int indices
colors – np.ndarray optional per-vertex colors (flat float32 array)
color_per_vertex – np.ndarray if provided and colors is None, generate per-vertex colors
- draw(color: tuple = None, line_width: float = 1.0, mode: int = GL.GL_TRIANGLES, fill: bool = False, alpha: float = 1.0)[source]
Draw the mesh with optional color override and transparency.
- Parameters:
color – Optional color override. If None and vertex colors exist, uses vertex colors.
line_width – Line width for wireframe mode
mode – OpenGL drawing mode
fill – Whether to fill or use wireframe
alpha – Transparency value from 0.0 (opaque) to 1.0 (fully transparent)