Y YASPS
Docs menu
Getting started Scene Mesh Primitive Primitive union Connectivity Attribute Minimizer Solver Differentiator Matrix Jacobian Hessian Gradient Examples Dropping in a container Cubify Inverse simulation

API reference · 02

Mesh

A mesh groups primitives and mesh-level attributes inside a scene.

A mesh object is often created under the scene using scene.addMesh. We normally never construct a mesh explicitly from the constructor.

world = scene("world")
model = world.addMesh("model")

addPrimitive

addPrimitive(name, numInstances, isDynamic=False)

Create, register, and return a primitive. The primitive is also available on the mesh by name.

Parameter Type Default Description
name str required Nonempty primitive identifier. Must be a valid, unique Python identifier within the mesh.
numInstances int required Initial number of primitive instances.
isDynamic bool False Allow the instance count to change with updateNumInstances.

Example

vertices = model.addPrimitive("vertices", numInstances=positions.shape[0])
contacts = model.addPrimitive("contacts", numInstances=0, isDynamic=True)

assert model.vertices is vertices

Returns: primitive.

Raises: ValueError when the name already exists or is not valid.

addPrimitiveUnion

addPrimitiveUnion(name, primitives)

Create a named primitive union from existing primitives or primitive unions. The result is also available on the mesh by name.

Parameter Type Description
name str Nonempty primitive union identifier. Must be valid and unique within the mesh.
primitives list of primitive or primitiveUnion Primitives and primitive unions to combine, in concatenation order.

Example

vertices = model.addPrimitiveUnion("vertices", [fixed_vertices, moving_vertices])

assert model.vertices is vertices

Returns: primitive union.

Raises: ValueError when the name already exists or is not valid. The primitive union validates that every member belongs to the same mesh.

addAttribute

addAttribute(name, computed_attribute=None, rows=1, cols=1)

Create a mesh-level data attribute, or bind a name to an unnamed computed attribute.

Parameter Type Default Description
name str required Name stored in the mesh attribute dictionary.
computed_attribute attribute or None None Unnamed symbolic expression to bind. When supplied, rows and cols are ignored.
rows int 1 Per-instance row count for a new data attribute.
cols int 1 Per-instance column count for a new data attribute.

Example

offset = model.addAttribute("offset", rows=3, cols=1)
offset_squared = model.addAttribute("offset_squared", computed_attribute=offset * offset)

Returns: attribute.

Raises: ValueError for a duplicate name or when computed_attribute already has a name.

addConstant

addConstant(name, rows=1, cols=1)

Create a constant attribute on the mesh. Its value can be updated, but YASPS treats it as constant during differentiation and excludes it from minimization targets.

Parameter Type Default Description
name str required Name stored in the mesh attribute dictionary.
rows int 1 Per-instance row count.
cols int 1 Per-instance column count.

Example

mu = model.addConstant("mu")
translation = model.addConstant("translation", rows=3, cols=1)

Returns: attribute.

Raises: ValueError for a duplicate name.

__getitem__

mesh[key]

Retrieve one named mesh-level attribute, or pack several named attributes into one row expression.

Key Result
str The named attribute.

Example``

mu = model["mu"]

Raises: KeyError when an attribute is missing or the key is neither a string nor tuple.

Properties

Property Type Description
name str Mesh identifier supplied to scene.addMesh.
scene scene Scene that owns this mesh.
mesh mesh This mesh itself.
type str Always "mesh".
primitives dict[str, primitive or primitiveUnion] Named primitives and primitive unions owned by the mesh.
attributes dict[str, attribute] Named mesh-level attributes and constants.
numInstances int Always 1. Any attribute created at mesh scope has one instance.
numPrimitives int Number of primitives and primitive unions in primitives.
fullName str Scene-qualified mesh identifier.