simvx.core.mesh_builder

Procedural geometry construction tool.

MeshBuilder provides a vertex-by-vertex mesh building API: set the attributes that apply, add a vertex, and commit a Mesh at the end. ImmediateGeometry3D rebuilds its mesh every frame from a user callback, suitable for debug visualisations, trails, and dynamic geometry. Primitive shapes come from the Mesh classmethods (Mesh.box(), Mesh.plane(), Mesh.sphere() and the rest).

Usage::

from simvx.core import MeshBuilder, PrimitiveType

st = MeshBuilder()
st.begin(PrimitiveType.TRIANGLES)
st.set_normal((0, 1, 0))
st.set_uv((0, 0))
st.add_vertex((0, 0, 0))
st.set_uv((1, 0))
st.add_vertex((1, 0, 0))
st.set_uv((0.5, 1))
st.add_vertex((0.5, 1, 0))
mesh = st.commit()

Module Contents

Classes

PrimitiveType

Primitive topology for MeshBuilder.

MeshBuilder

Vertex-by-vertex mesh construction tool.

ImmediateGeometry3D

A 3D node whose mesh is rebuilt every frame via a callback.

Data

API

simvx.core.mesh_builder.log

‘getLogger(…)’

simvx.core.mesh_builder.__all__

[‘MeshBuilder’, ‘PrimitiveType’, ‘ImmediateGeometry3D’]

class simvx.core.mesh_builder.PrimitiveType[source]

Bases: enum.IntEnum

Primitive topology for MeshBuilder.

Initialization

Initialize self. See help(type(self)) for accurate signature.

TRIANGLES

0

LINES

1

POINTS

2

TRIANGLE_STRIP

3

__abs__()
__add__()
__and__()
__bool__()
__ceil__()
__delattr__()
__dir__()
__divmod__()
__eq__()
__float__()
__floor__()
__floordiv__()
__format__()
__ge__()
__getattribute__()
__getnewargs__()
__getstate__()
__gt__()
__hash__()
__index__()
__int__()
__invert__()
__le__()
__lshift__()
__lt__()
__mod__()
__mul__()
__ne__()
__neg__()
__new__()
__or__()
__pos__()
__pow__()
__radd__()
__rand__()
__rdivmod__()
__reduce__()
__reduce_ex__()
__repr__()
__rfloordiv__()
__rlshift__()
__rmod__()
__rmul__()
__ror__()
__round__()
__rpow__()
__rrshift__()
__rshift__()
__rsub__()
__rtruediv__()
__rxor__()
__setattr__()
__sizeof__()
__str__()
__sub__()
__subclasshook__()
__truediv__()
__trunc__()
__xor__()
as_integer_ratio()
bit_count()
bit_length()
conjugate()
class denominator
class imag
is_integer()
class numerator
class real
to_bytes()
__deepcopy__(memo)
__copy__()
name()
value()
class simvx.core.mesh_builder.MeshBuilder[source]

Vertex-by-vertex mesh construction tool.

Accumulates vertex attributes then emits a Mesh on commit(). Set per-vertex attributes (normal, uv, colour) before calling add_vertex() – the current values are latched when the vertex is added.

Initialization

__slots__

(‘_primitive’, ‘_positions’, ‘_normals’, ‘_uvs’, ‘_colours’, ‘_indices’, ‘_cur_normal’, ‘_cur_uv’, ‘…

begin(primitive: simvx.core.mesh_builder.PrimitiveType = PrimitiveType.TRIANGLES) → None[source]

Start a new surface. Clears any previously accumulated data.

set_normal(normal: collections.abc.Sequence[float] | simvx.core.math.types.Vec3) → None[source]

Set the normal for subsequent vertices.

set_uv(uv: collections.abc.Sequence[float] | simvx.core.math.types.Vec2) → None[source]

Set the UV coordinate for subsequent vertices.

set_colour(colour: collections.abc.Sequence[float]) → None[source]

Set the vertex colour (RGBA) for subsequent vertices.

add_vertex(position: collections.abc.Sequence[float] | simvx.core.math.types.Vec3) → None[source]

Add a vertex with the currently set attributes.

add_index(index: int) → None[source]

Add an index referencing a previously added vertex.

add_triangle_fan(vertices: collections.abc.Sequence[collections.abc.Sequence[float]], uvs: collections.abc.Sequence[collections.abc.Sequence[float]] | None = None, normals: collections.abc.Sequence[collections.abc.Sequence[float]] | None = None) → None[source]

Add a triangle fan as indexed triangles.

The first vertex is the hub; triangles are formed with consecutive pairs of the remaining vertices.

generate_normals() → None[source]

Auto-compute smooth normals from triangle geometry.

Only works when primitive type is TRIANGLES. Uses the index list if present, otherwise assumes every three consecutive vertices form a triangle.

generate_tangents() → None[source]

Auto-compute tangents using Lengyel’s method (MikkTSpace-lite).

Stores tangent data on the resulting mesh as a tangents attribute (Nx4 float32 array with w = handedness). This is a best-effort implementation suitable for normal mapping.

commit() → simvx.core.graphics.mesh.Mesh[source]

Build and return a Mesh from the accumulated vertex data.

clear() → None[source]

Reset the tool for reuse (same as constructing a new instance).

property vertex_count: int[source]

Number of vertices accumulated so far.

property index_count: int[source]

Number of indices accumulated so far.

class simvx.core.mesh_builder.ImmediateGeometry3D(**kwargs)[source]

Bases: simvx.core.nodes_3d.node3d.Node3D

A 3D node whose mesh is rebuilt every frame via a callback.

Override _draw_geometry or connect to the draw signal to provide geometry each frame. The node creates a fresh MeshBuilder, passes it to your callback, and commits the result as the renderable mesh.

Usage::

class MyTrail(ImmediateGeometry3D):
    def _draw_geometry(self, st: MeshBuilder) -> None:
        st.begin(PrimitiveType.TRIANGLES)
        # ... add vertices ...

Or with signals::

def draw_fn(st: MeshBuilder) -> None:
    st.begin(PrimitiveType.TRIANGLES)
    # ...

ig = ImmediateGeometry3D()
ig.draw.connect(draw_fn)

Initialization

on_update(dt: float) → None[source]
position

‘_SpatialVecProperty(…)’

rotation

‘Property(…)’

scale

‘_SpatialVecProperty(…)’

render_layer

‘Property(…)’

property rotation_degrees: simvx.core.math.types.Vec3
property world_position: simvx.core.math.types.Vec3
property world_rotation: simvx.core.math.types.Quat
property world_scale: simvx.core.math.types.Vec3
property forward: simvx.core.math.types.Vec3
property right: simvx.core.math.types.Vec3
property up: simvx.core.math.types.Vec3
translate(offset: tuple[float, float, float] | numpy.ndarray)
translate_global(offset: tuple[float, float, float] | numpy.ndarray)
rotate(axis: tuple[float, float, float] | numpy.ndarray, angle: float)
rotate_x(angle: float)
rotate_y(angle: float)
rotate_z(angle: float)
look_at(target: tuple[float, float, float] | numpy.ndarray, up=None)
face_along(forward: tuple[float, float, float] | numpy.ndarray, up: tuple[float, float, float] | numpy.ndarray | None = None) → None
set_render_layer(index: int, enabled: bool = True) → None
is_on_render_layer(index: int) → bool
wrap_bounds(bounds: tuple[float, float, float] | numpy.ndarray, margin: float = 1.0)
strict_errors: ClassVar[bool]

True

dev_checks: ClassVar[bool]

None

dev_warnings: ClassVar[bool]

None

freeze_check_interval: ClassVar[float]

1.0

dynamic: bool

False

visible

‘Property(…)’

update_mode

‘Property(…)’

focus_mode

‘Property(…)’

drag_threshold

‘Property(…)’

focus_entered

‘Signal(…)’

focus_exited

‘Signal(…)’

__properties__: ClassVar[dict[str, simvx.core.descriptors.Property]]

None

classmethod __init_subclass__(**kwargs)
property name: str
property visible_in_tree: bool
property input_player: simvx.core.input.players.InputPlayer
property input_context: simvx.core.input.contexts.InputContext | None
reset_error() → None
add_child(node: simvx.core.node.T) → simvx.core.node.T
remove_child(node: simvx.core.node.Node) → None
reparent(new_parent: simvx.core.node.Node)
node_at(path, default=_NO_DEFAULT)
find(target, *, direct: bool = False)
find_all(target, *, direct: bool = False)
expect(target, *, direct: bool = False)
ancestor(target)
walk(*, include_self: bool = True) → collections.abc.Iterator[simvx.core.node.Node]
property path: str
property is_scene_root: bool
add_to_group(group: str)
remove_from_group(group: str)
is_in_group(group: str) → bool
on_ready() → None
on_enter_tree() → None
on_exit_tree() → None
on_fixed_update(dt: float) → None
on_draw(canvas) → None
on_draw_3d(gizmos) → None
on_picked(event: simvx.core.input.events.PickEvent) → bool | None
on_gui_input(event: simvx.core.input.events.GuiInputEvent) → bool | None
start_coroutine(gen: simvx.core.descriptors.Coroutine) → simvx.core.descriptors.CoroutineHandle
stop_coroutine(gen_or_handle)
property focused: bool
property focus_rect: tuple[float, float, float, float] | None
drag_threshold_for(pointer_type: simvx.core.input.enums.PointerType | str) → float
grab_focus() → None
release_focus() → None
capture_pointer(pointer_id: int | None = None) → None
release_pointer(pointer_id: int | None = None) → None
queue_redraw() → None
property render_dirty: bool
clear_children()
destroy()
property destroying: bool
property destroyed: bool
call_deferred(method: collections.abc.Callable[..., Any], *args: Any) → None
property app
property tree: simvx.core.scene_tree.SceneTree
property viewport_size: simvx.core.math.types.Vec2
property viewport_insets: tuple[float, float, float, float]
property physics
property physics_2d
__getitem__(key: str)
classmethod get_properties() → dict[str, simvx.core.descriptors.Property]
__repr__()