TriangleMesh

Qualified name: algan.mobs.three\_d\_models.mesh.TriangleMesh

class TriangleMesh(vertices, faces, normals=None, uvs=None, texture=None, vertex_colors=None, material_texture_map=None, material_texture_flags=0, normal_texture_map=None, ignore_normals=False, recompute_normals=False, **kwargs)[source]

Bases: Mob

An arbitrary indexed triangle mesh with optional per-corner normals, UVs and a texture map.

Parameters:
  • vertices (torch.Tensor[V, 3]) – Vertex positions.

  • faces (torch.Tensor[F, 3]) – Triangle vertex indices into vertices.

  • normals (torch.Tensor[V, 3], optional) – Per-vertex normals (in the mesh’s local frame). When omitted, flat per-face normals are computed from the geometry each frame (so they stay correct under rotation and deformation).

  • uvs (torch.Tensor[V, 2], optional) – Per-vertex texture coordinates. Required to show texture / material_texture_map / normal_texture_map.

  • texture (torch.Tensor, optional) – Either a [W, H, 5] texture map already in engine layout (as built by image_to_texture_map()) or a raw image [H, W, C] which is converted automatically. Provides the surface albedo; replaces the per-vertex color where present.

  • vertex_colors (torch.Tensor[V, 5], optional) – Per-vertex colors (RGB + glow + opacity). Ignored when a texture is given. Falls back to a single color otherwise.

  • material_texture_map – Optional per-texel material-property / tangent-space normal maps, forwarded to the ray tracer exactly as for Surface.

  • material_texture_flags – Optional per-texel material-property / tangent-space normal maps, forwarded to the ray tracer exactly as for Surface.

  • normal_texture_map – Optional per-texel material-property / tangent-space normal maps, forwarded to the ray tracer exactly as for Surface.

  • ignore_normals (bool) – If True the mesh carries zero normals (no lighting interaction).

  • *args – Passed to Mob.

  • **kwargs – Passed to Mob.

Methods

get_default_color

Get the color this Mob uses when none was given.

get_render_primitives

triangle_shell_ids

Per-triangle connected-component id, or None for a single shell.

Attributes

animation_manager

This mob's scene-owned animation manager.

basis

The Mob's orientation and scale, as a flattened 3x3 matrix of shape (*, 9).

casts_shadows

Whether this Mob's geometry blocks light on its way from a light source to another surface -- whether it casts a shadow.

children

The Mobs attached below this one, in attachment order.

closed_shell

Whether this Mob's triangles form a CLOSED shell -- every camera ray that enters the geometry crosses a second time on its way out.

draws_descendants

Whether get_render_primitives returns geometry belonging to this Mob's DESCENDANTS as well as its own.

forward

Get the direction the Mob is facing.

lifespan

This mob's [spawn, despawn) interval on its Scene timeline (a Lifespan).

location

The Mob's position in world space, shape (*, 3).

normalized_basis

The Mob's orientation with scale divided out, shape (*, 9).

parents

The Mobs this one is attached to, in attachment order.

receives_shadows

Whether this Mob's surfaces are darkened by shadows cast onto them.

right

Get the Mob's own rightward direction.

scale_coefficient

The Mob's scale along its own right, up and forward axes, shape (*, 3).

two_sided

Whether this Mob's geometry should be lit from whichever side the ray arrives on.

up

Get the Mob's own upward direction.

x

The Mob's x coordinate in world units, shape (*, 1).

xy

The Mob's x and y coordinates in world units, shape (*, 2).

y

The Mob's y coordinate in world units, shape (*, 1).

z

The Mob's z coordinate in world units, shape (*, 1).

get_default_color()[source]

Get the color this Mob uses when none was given.

Override in a subclass to give a shape its own default; the built-in shapes do exactly that.

Returns:

BLACK for the base class.

Return type:

Color

triangle_shell_ids()[source]

Per-triangle connected-component id, or None for a single shell.

An imported file’s mesh routinely holds several disconnected parts, and treating them as one surface lets the analytic-AA run rule sum coverage across parts that merely overlap on screen. corner_index already carries the topology the loader read (it is kept for smooth normals), so the components are a graph walk over shared EDGES – not shared vertices, which would fuse two cones meeting at a single apex.

Computed once and cached: the result depends only on construction-time topology, never on the animated positions.