newton.selection.DeformableCurveView#
- class newton.selection.DeformableCurveView(model, pattern, *, verbose=None)[source]#
Select curves by label and read or update their segment body state.
Experimental
This API may change while deformable selection is developed.
Currently supports rod-backed curves with body and joint ranges. The family describes geometry, not a solver: particle-based curves are not supported yet. Matching surfaces and volumes are excluded from the selection.
After fixed-joint collapse, the view describes the curve’s surviving segment bodies and joints. Curves with no remaining bodies are omitted. Use
collapse_fixed_joints()withjoints_to_keepto preserve the original segment layout.See Deformable Selection for world layout, getter-result lifetime, masked writes, and CUDA graph capture.
- Parameters:
model (Model) – Model containing the finalized deformable objects.
pattern (str | list[str] | re.Pattern[str] | list[int]) – Label glob, list of label globs, compiled regular expression, or unique ascending indices into
curve_label.verbose (bool | None) – If True, log a short selection summary. If None, follow Warp’s logging level.
Methods
__init__(model, pattern, *[, verbose])Return one range of selected deformable-object indices per world.
element_count(kind)Elements of
kindper selected deformable object, orNonewhen counts differ.get_body_transforms(source)Body transforms, shape
(count, body_count).get_body_velocities(source)Body velocities, shape
(count, body_count).ranges(kind)[start, end)element ranges of the selected deformable objects, in selection order.set_body_transforms(target, values, *[, mask])Write body transforms for the masked deformable objects.
set_body_velocities(target, values, *[, mask])Write body velocities for the masked deformable objects.
set_mask_from_indices(mask, ...)Replace a caller-owned mask with the selected deformable objects.
starts(kind)Device-side element-range starts of the selected deformable objects, shape
(count,).Attributes
Bodies per selected deformable object, or
Nonewhen counts differ.Number of selected deformable objects across all worlds.
Selected deformable objects per model world, or None when the counts vary.
Geometric family selected by this view.
Label of each selected deformable object, ordered world by world.
Read-only Python list of model world indices, one per selected deformable object.
Device-side deformable-object boundaries by world.
Read-only device copy of
worlds, shape(count,).- __init__(model, pattern, *, verbose=None)#
- deformable_object_ranges()#
Return one range of selected deformable-object indices per world.
Each
(start, end)pair sliceslabelsor rows of batched state returned by this view. Usedeformable_object_ranges()[world_id]to look up a world. The end is excluded. Empty worlds have equal start and end values. These are selected deformable object indices, not the simulation element indices returned byranges().A global-only selection has one range,
(0, count), and itsworlds_deviceentries are all-1. This single range is not indexed by a model world ID.
- element_count(kind)#
Elements of
kindper selected deformable object, orNonewhen counts differ.Current rods record
body/jointranges, triangle surfaces recordparticle/triangle/edgeranges, and tetrahedral volumes recordparticle/tetrahedronranges. Batched reads and writes require a common count;ranges()remains available when counts differ.particle_countandbody_countare convenience properties for this query on their corresponding state element kinds.- Parameters:
kind (AttributeFrequency | Literal['body', 'joint', 'particle', 'triangle', 'edge', 'tetrahedron']) – Element kind recorded by every selected deformable object: a
AttributeFrequencymember such asPARTICLEor its lowercase name.- Returns:
Common number of elements per selected deformable object, or
None.- Raises:
TypeError – If
kindis not an AttributeFrequency member or a string.ValueError – If the selected deformable objects do not record
kind.
- Return type:
int | None
- get_body_transforms(source)#
Body transforms, shape
(count, body_count).Each transform contains a world-space translation [m] and a unitless quaternion.
- Parameters:
source (Model | State) – Model initial state or simulation state to read.
- Returns:
Body transforms with shape
(count, body_count).- Raises:
ValueError – If body counts differ or the source array’s rank, dtype, device, or length is incompatible with the selection.
- Return type:
wp.array2d[wp.transform]
- get_body_velocities(source)#
Body velocities, shape
(count, body_count).Each value follows
(v_com_world, omega_world): linear velocity [m/s] followed by angular velocity [rad/s].- Parameters:
source (Model | State) – Model initial state or simulation state to read.
- Returns:
Body velocities with shape
(count, body_count).- Raises:
ValueError – If body counts differ or the source array’s rank, dtype, device, or length is incompatible with the selection.
- Return type:
wp.array2d[wp.spatial_vector]
- ranges(kind)#
[start, end)element ranges of the selected deformable objects, in selection order.For consumers that need each deformable object’s raw slice of the flat model arrays, e.g. to hand per-instance offsets to a renderer sync or to custom kernels. See
element_count()for the validkindvalues.Native and USD curves include their construction-time root joints. After fixed-joint collapse, only surviving bodies and joints are exposed. A welded USD graph is one deformable object with the whole graph’s body and joint ranges. Its per-curve import maps are separate and keep empty joint lists. See Rod graphs.
- Parameters:
kind (AttributeFrequency | Literal['body', 'joint', 'particle', 'triangle', 'edge', 'tetrahedron']) – Element kind recorded by every selected deformable object: a
AttributeFrequencymember or its lowercase name.- Returns:
One
[start, end)range per selected deformable object.- Raises:
TypeError – If
kindis not an AttributeFrequency member or a string.ValueError – If the selected deformable objects do not record
kind.
- Return type:
- set_body_transforms(target, values, *, mask=None)#
Write body transforms for the masked deformable objects.
Values stay in view order, including rows that are masked off. Keep values and masks unchanged until backward completes when using a tape. Preallocated device inputs require no temporary arrays during capture.
- Parameters:
target (Model | State) – Model initial state or simulation state to update.
values (Any) – Body transforms with world-space translation [m] and a unitless quaternion, shape
(count, body_count). Must not share storage with the target array; clone live getter results before writing. Host inputs are reshaped with a final axis of length 7. None is invalid.mask (Any) – Boolean array of shape
(count,)on the view’s device, or a host Boolean sequence outside capture. True updates that selected deformable object. None updates the whole selection.
- Raises:
ValueError – If element counts, array shapes/dtypes/devices, mask, target capacity, or non-overlap requirements are not satisfied.
RuntimeError – If host values or a host mask are passed during CUDA capture.
- set_body_velocities(target, values, *, mask=None)#
Write body velocities for the masked deformable objects.
Values stay in view order, including rows that are masked off. Keep values and masks unchanged until backward completes when using a tape. Preallocated device inputs require no temporary arrays during capture.
- Parameters:
target (Model | State) – Model initial state or simulation state to update.
values (Any) – Body velocities in (v_com_world, omega_world) order [m/s, rad/s], shape
(count, body_count). Must not share storage with the target array; clone live getter results before writing. Host inputs are reshaped with a final axis of length 6. None is invalid.mask (Any) – Boolean array of shape
(count,)on the view’s device, or a host Boolean sequence outside capture. True updates that selected deformable object. None updates the whole selection.
- Raises:
ValueError – If element counts, array shapes/dtypes/devices, mask, target capacity, or non-overlap requirements are not satisfied.
RuntimeError – If host values or a host mask are passed during CUDA capture.
- set_mask_from_indices(mask, deformable_object_indices)#
Replace a caller-owned mask with the selected deformable objects.
Indices refer to rows of this view, not model-global IDs. Their order does not reorder values passed to setters. Repeats select an object once. An empty selector clears the mask. Device inputs need no host copy or temporary allocation and can change between CUDA graph replays.
- Parameters:
mask (wp.array[wp.bool]) – Output Boolean array with shape
(count,)on the view’s device. Non-overlapping strided arrays are supported.deformable_object_indices (Any) – Host integer sequence outside capture, or a one-dimensional
int32Warp array on the view’s device. Invalid host indices raise; invalid device indices are ignored, so fixed-capacity device selectors may use-1for unused entries.
- Raises:
TypeError – If the output is not a Warp array or a host index is not an integer. Booleans are not indices.
ValueError – If shapes, dtypes, devices, host bounds, or output strides are invalid. Validation failures leave the output unchanged.
RuntimeError – If host indices are passed during CUDA capture.
- starts(kind)#
Device-side element-range starts of the selected deformable objects, shape
(count,).Together with
element_count()this drives custom kernels over the selection without a host round-trip; the view’s own gather/scatter kernels use the same array. Treat the returned internal array as read-only.- Parameters:
kind (AttributeFrequency | Literal['body', 'joint', 'particle', 'triangle', 'edge', 'tetrahedron']) – Element kind recorded by every selected deformable object: a
AttributeFrequencymember or its lowercase name.- Returns:
Device array containing one start index per selected deformable object.
- Raises:
TypeError – If
kindis not an AttributeFrequency member or a string.ValueError – If the selected deformable objects do not record
kind.
- Return type:
wp.array[wp.int32]
- count#
Number of selected deformable objects across all worlds.
- count_per_world#
Selected deformable objects per model world, or None when the counts vary.
Empty model worlds count as zero, so counts of
[1, 0, 1]giveNone. A global-only selection has one partition and returnscount.
- deformable_object_boundaries: wp.array[wp.int32]#
Device-side deformable-object boundaries by world.
There is one boundary per model world plus a final end boundary. A global-only selection has two boundaries.
World
ispans selected deformable object indices fromdeformable_object_boundaries[i]todeformable_object_boundaries[i + 1], excluding the end. The final entry is the selected deformable object count. Treat this array as read-only. Seedeformable_object_ranges()for the corresponding Python ranges and the global-only case.
- family#
Geometric family selected by this view.
- labels#
Label of each selected deformable object, ordered world by world.
- worlds#
Read-only Python list of model world indices, one per selected deformable object.
worlds_deviceholds the same mapping on the model’s device. Both are created with the view; editing either does not update the other.