simvx.core.graphics.mesh

Geometry data with procedural primitives.

High-level: Mesh.cube(), Mesh.sphere(), Mesh.cone() Low-level: Mesh(positions, indices, normals, texcoords) + interleaved_bytes()

Module Contents

Classes

Mesh

Vertex data with optional GPU buffers. Pure data until renderer uploads.

Data

API

simvx.core.graphics.mesh.log

‘getLogger(…)’

simvx.core.graphics.mesh.MeshSource

None

class simvx.core.graphics.mesh.Mesh(positions, indices=None, normals=None, texcoords=None, topology='triangles')[source]

Vertex data with optional GPU buffers. Pure data until renderer uploads.

Create via class methods: Mesh.cube(), Mesh.sphere(), Mesh.cone(), Mesh.cylinder() Or from raw data: Mesh(positions, indices, normals, texcoords) Or load from a Wavefront OBJ: Mesh.from_obj(“model.obj”) Mesh.from_obj(Resource(“game.assets”, “ship.obj”))

The optional :attr:factory_spec records the call that produced a mesh ({"name": "cube", "kwargs": {"size": 1.0}} or {"name": "obj", "source": <spec>}) so scene serialisation can round-trip the mesh by replaying the factory.

Initialization

property vertex_count: int[source]
property index_count: int[source]
property stride: int[source]

Bytes per interleaved vertex.

property has_normals: bool[source]
property has_texcoords: bool[source]
interleaved_bytes() bytes[source]

Pack vertex data interleaved (pos[,normal][,uv]) for GPU upload.

index_bytes() bytes[source]
bounding_box() tuple[numpy.ndarray, numpy.ndarray][source]

Returns (min_corner, max_corner) as vec3 arrays.

bounding_radius() float[source]

Radius of bounding sphere centered at origin.

generate_normals() simvx.core.graphics.mesh.Mesh[source]

Compute smooth vertex normals from face geometry. Returns self.

classmethod cube(size: float = 1.0) simvx.core.graphics.mesh.Mesh[source]

Axis-aligned cube centered at origin. 24 vertices, 36 indices.

classmethod sphere(radius: float = 1.0, rings: int = 16, segments: int = 16) simvx.core.graphics.mesh.Mesh[source]

UV sphere.

classmethod cone(radius: float = 0.5, height: float = 1.0, segments: int = 16) simvx.core.graphics.mesh.Mesh[source]

Cone pointing up +Y, base centered at origin.

classmethod cylinder(radius: float = 0.5, height: float = 1.0, segments: int = 16) simvx.core.graphics.mesh.Mesh[source]

Cylinder along +Y axis, centered at origin.

classmethod load(source: simvx.core.graphics.mesh.MeshSource) simvx.core.graphics.mesh.Mesh[source]

Load a mesh from any supported source.

Currently delegates to :meth:from_obj (only Wavefront OBJ is supported). The check is by file extension on the resolved path.

classmethod from_obj(source: simvx.core.graphics.mesh.MeshSource) simvx.core.graphics.mesh.Mesh[source]

Load from Wavefront OBJ. Handles v/vt/vn/f directives.

Accepts str / os.PathLike (filesystem path),

Class:

~simvx.core.Resource (package handle), or

Class:

importlib.resources.abc.Traversable (raw importlib.resources result).