simvx.core.mesh_instance_2d¶
MeshInstance2D — custom 2D mesh rendering node.
Renders arbitrary 2D geometry defined by vertices, indices, UVs, and per-vertex colours. Useful for deformable shapes, terrain slices, soft-body visuals, and any geometry that doesn’t fit a simple sprite or polygon.
Module Contents¶
Classes¶
Immutable-ish 2D mesh data: vertices, triangle indices, UVs, and per-vertex colours. |
|
Renders a custom 2D mesh defined by a :class: |
Data¶
API¶
- simvx.core.mesh_instance_2d.__all__¶
[‘Mesh2D’, ‘MeshInstance2D’]
- class simvx.core.mesh_instance_2d.Mesh2D[source]¶
Immutable-ish 2D mesh data: vertices, triangle indices, UVs, and per-vertex colours.
Vertices and UVs are stored as
(N, 2)float32 arrays. Colours are(N, 4)float32 RGBA. Indices are a flatuint32array where every three consecutive values form one triangle.Factory class-methods create common primitives with correct winding and UVs.
- vertices: numpy.ndarray¶
‘field(…)’
- indices: numpy.ndarray¶
‘field(…)’
- uvs: numpy.ndarray¶
‘field(…)’
- colours: numpy.ndarray¶
‘field(…)’
- property vertex_count: int¶
- property triangle_count: int¶
- property is_empty: bool¶
- get_aabb() tuple[simvx.core.math.types.Vec2, simvx.core.math.types.Vec2][source]¶
Axis-aligned bounding box as
(min_corner, max_corner).
- classmethod from_polygon(points: list | numpy.ndarray) simvx.core.mesh_instance_2d.Mesh2D[source]¶
Fan-triangulate a convex polygon.
Points should be in order (CW or CCW). UVs are derived from the bounding box. All vertices share white colour.
- classmethod from_rect(width: float, height: float, centered: bool = True) simvx.core.mesh_instance_2d.Mesh2D[source]¶
Axis-aligned rectangle as two triangles.
When centered the origin is at the rectangle centre; otherwise it is at the top-left corner.
- classmethod from_circle(radius: float, segments: int = 32) simvx.core.mesh_instance_2d.Mesh2D[source]¶
Regular polygon approximating a circle centred at the origin.
- classmethod from_grid(width: float, height: float, cols: int, rows: int, centered: bool = True) simvx.core.mesh_instance_2d.Mesh2D[source]¶
Subdivided rectangle useful for terrain slices or deformation grids.
Creates a cols x rows quad grid (
(cols+1)*(rows+1)vertices).
- class simvx.core.mesh_instance_2d.MeshInstance2D(mesh: simvx.core.mesh_instance_2d.Mesh2D | None = None, texture: Any = None, modulate: tuple = (1.0, 1.0, 1.0, 1.0), position=None, rotation: float = 0.0, scale=None, **kwargs)[source]¶
Bases:
simvx.core.nodes_2d.node2d.Node2DRenders a custom 2D mesh defined by a :class:
Mesh2D.The mesh vertices are in local space and transformed by the node’s position, rotation, and scale before drawing. An optional texture and modulate colour tint the output.
Example::
mesh = Mesh2D.from_rect(64, 64) node = MeshInstance2D(mesh=mesh, modulate=(1, 0, 0, 1)) root.add_child(node)
Initialization
- texture¶
‘Property(…)’
- modulate¶
‘Property(…)’
- property mesh: simvx.core.mesh_instance_2d.Mesh2D | None¶
- classmethod from_dict(data: dict) simvx.core.mesh_instance_2d.MeshInstance2D[source]¶
Deserialise from a dictionary.
- z_index¶
‘Property(…)’
- z_as_relative¶
‘Property(…)’
- render_layer¶
‘Property(…)’
- set_render_layer(index: int, enabled: bool = True) None¶
- is_on_render_layer(index: int) bool¶
- property absolute_z_index: int¶
- property position: simvx.core.math.types.Vec2¶
- property rotation: float¶
- property rotation_degrees: float¶
- property scale: simvx.core.math.types.Vec2¶
- property world_position: simvx.core.math.types.Vec2¶
- property world_rotation: float¶
- property world_scale: simvx.core.math.types.Vec2¶
- property forward: simvx.core.math.types.Vec2¶
- property right: simvx.core.math.types.Vec2¶
- translate(offset: tuple[float, float] | numpy.ndarray)¶
- rotate(radians: float)¶
- rotate_deg(degrees: float)¶
- look_at(target: tuple[float, float] | numpy.ndarray)¶
- transform_points(points: list[simvx.core.math.types.Vec2]) list[simvx.core.math.types.Vec2]¶
- draw_polygon(renderer, points: list[simvx.core.math.types.Vec2], closed=True, colour=None)¶
- wrap_screen(margin: float = 20)¶
- strict_errors: ClassVar[bool]¶
True
- script_error_raised¶
‘Signal(…)’
- classmethod __init_subclass__(**kwargs)¶
- property name: str¶
- property process_mode: simvx.core.descriptors.ProcessMode¶
- reset_error() None¶
- add_child(node: simvx.core.node.Node) simvx.core.node.Node¶
- remove_child(node: simvx.core.node.Node)¶
- reparent(new_parent: simvx.core.node.Node)¶
- get_node(path: str) simvx.core.node.Node¶
- find_child(name: str, recursive: bool = False) simvx.core.node.Node | None¶
- find(node_type: type, recursive: bool = True) simvx.core.node.Node | None¶
- property path: str¶
- add_to_group(group: str)¶
- remove_from_group(group: str)¶
- is_in_group(group: str) bool¶
- ready() None¶
- enter_tree() None¶
- exit_tree() None¶
- process(dt: float) None¶
- physics_process(dt: float) None¶
- input_event(event: simvx.core.events.InputEvent) None¶
- input(event: simvx.core.events.TreeInputEvent) None¶
- unhandled_input(event: simvx.core.events.TreeInputEvent) None¶
- start_coroutine(gen: simvx.core.descriptors.Coroutine) simvx.core.descriptors.CoroutineHandle¶
- stop_coroutine(gen_or_handle)¶
- clear_children()¶
- destroy()¶
- property app¶
- property tree: simvx.core.scene_tree.SceneTree¶
- get_tree() simvx.core.scene_tree.SceneTree¶
- __getitem__(key: str)¶
- classmethod get_properties() dict[str, simvx.core.descriptors.Property]¶
- __repr__()¶