Skip to content

mesh

FreeBodyEngine.graphics.mesh #

AttributeType #

Bases: Enum

Per-vertex attribute layout a Mesh's attributes dict declares for one channel (e.g. "verticies", "uvs"). Only FLOAT/VEC2/VEC3/VEC4/INT/ IVEC2/IVEC3/IVEC4 are actually handled by the GL33/GL44 backends' upload() (see GLMesh.upload) - MAT3/MAT4/VEC5/VEC6/IVEC5/IVEC6 raise there.

FLOAT = auto() class-attribute instance-attribute #

INT = auto() class-attribute instance-attribute #

IVEC2 = auto() class-attribute instance-attribute #

IVEC3 = auto() class-attribute instance-attribute #

IVEC4 = auto() class-attribute instance-attribute #

IVEC5 = auto() class-attribute instance-attribute #

IVEC6 = auto() class-attribute instance-attribute #

MAT3 = auto() class-attribute instance-attribute #

MAT4 = auto() class-attribute instance-attribute #

VEC2 = auto() class-attribute instance-attribute #

VEC3 = auto() class-attribute instance-attribute #

VEC4 = auto() class-attribute instance-attribute #

VEC5 = auto() class-attribute instance-attribute #

VEC6 = auto() class-attribute instance-attribute #

BufferUsage #

Bases: Enum

GPU buffer update-frequency hint, mapped to GL_STATIC_DRAW/ GL_DYNAMIC_DRAW/GL_STREAM_DRAW by the GL backends. A STATIC mesh additionally refuses set_data() calls - see Mesh.set_data.

DYNAMIC = auto() class-attribute instance-attribute #

STATIC = auto() class-attribute instance-attribute #

STREAM = auto() class-attribute instance-attribute #

IndexType #

Bases: Enum

Index buffer element width - GLMesh selects GL_UNSIGNED_SHORT for UINT16 or GL_UNSIGNED_INT for UINT32 when uploading/drawing indices.

UINT16 = auto() class-attribute instance-attribute #

UINT32 = auto() class-attribute instance-attribute #

Mesh(attributes, indices=None, primitive=PrimitiveType.TRIANGLES, index_type=IndexType.UINT16, usage=BufferUsage.STATIC) #

Backend-agnostic vertex/index geometry: a dict of named per-vertex attributes ({"verticies": (AttributeType.VEC3, array), ...}), optional indices, and drawing/update-frequency hints. Concrete backends (GLMesh etc.) own the actual GPU buffers and implement uploading/drawing/ destroying them.

Stores the mesh's attribute/index data and drawing hints; uploading them to the GPU is left to a concrete subclass's constructor.

attributes = attributes instance-attribute #

index_type = index_type instance-attribute #

indices = indices instance-attribute #

primitive = primitive instance-attribute #

usage = usage instance-attribute #

destroy() #

Releases the mesh's underlying GPU resources.

draw() #

Issues the draw call for this mesh using its currently uploaded GPU buffers.

set_data(attribute_name, data) #

Updates one attribute's data in place - a no-op (with a warning) if this mesh's usage is STATIC, since a static mesh's buffers aren't expected to change after upload.

PrimitiveType #

Bases: Enum

GL primitive topology a Mesh's vertex/index data is drawn as.

TRIANGLES = auto() class-attribute instance-attribute #

TRIANGLE_FAN = auto() class-attribute instance-attribute #

TRIANGLE_STRIP = auto() class-attribute instance-attribute #

create_static_mesh(verticies, uvs, normals, indices, buffer_usage=BufferUsage.STATIC, primitive=PrimitiveType.TRIANGLES) #

Builds a Mesh (via the active renderer's mesh class) from raw vertex/ uv/normal arrays plus indices, always as IndexType.UINT32 regardless of Mesh's own UINT16 default - see the comment on index_type below.

generate_circle(radius=0.5, segments=32) #

Generates a filled circle mesh (a triangle fan around a center vertex), facing +Z.

generate_cube(width=1.0, height=1.0, depth=1.0) #

Generates an axis-aligned box mesh centered at the origin, with unshared per-face vertices so each face gets its own flat UVs/normal.

generate_polygon(local_vertices) #

Generates a filled convex polygon mesh (a triangle fan around the vertices' own centroid), facing +Z - for debug-visualizing a PolygonCollisionShape, whose local_vertices (a list of (x, y)-like pairs) this takes directly.

generate_quad(width=1.0, height=1.0) #

Generates a quad mesh centered at the origin, facing +Z.

generate_sphere(radius=1.0, sectors=36, stacks=18) #

Generates a UV sphere mesh.