ke.physics¶
Low-level PhysX world, rigid body, articulation, and visual sync APIs.
API overview¶
PhysX world configuration including timestep, up axis, and reporting. |
|
PhysX simulation world. |
|
Python batch interface over individual D6 handles, with batched CUDA readback. |
|
PhysX articulation construction settings. |
|
PhysX articulation wrapper. |
|
Sync PhysX articulation state into scene/render visuals. |
|
Configuration for explicit GPU physics state synchronization. |
|
Explicit GPU physics synchronization wrapper. |
Wrapper and lifetime policy¶
The Python low-level physics API is exposed through thin wrapper classes around native pybind11 objects. The wrapper classes remain importable for stable IDE completion and API documentation even when KangEngine is built without PhysX; constructing or using a PhysX-backed object in such a build raises a runtime error.
Use the .native property only when deliberately dropping to native parity.
Helper code that accepts either wrapper or native objects should normalize with
unwrap_native(obj).
Contact queries and GPU state views expose backend-owned state. Treat
PhysicsWorld.get_contacts(), PhysicsWorld.get_contact_forces(...), and
PhysicsGpuSystem.views() conservatively: later simulation, synchronization,
refresh, or clear operations may update or invalidate the underlying storage.
Copy returned array-like data explicitly when a stable snapshot is required.
Return and error contracts¶
API |
Contract |
|---|---|
|
Borrowed device storage owned by the GPU system. Fetch and apply methods update it; releasing or invalidating the system invalidates the view. |
|
Current-query data only. Copy values that must remain stable across later simulation or clear operations. |
Resource and actor wrappers |
Native handles tied to their owning world. Using them after world release
raises |
Invalid indices and names generally raise KeyError or IndexError;
invalid shapes and configuration values raise ValueError; unavailable
PhysX/CUDA features and invalid lifecycle state raise RuntimeError.
- class kangengine.physics.PhysicsConfig[native]¶
PhysX world configuration including timestep, up axis, and reporting.
- __init__(
- *,
- dt: float = 1.0 / 60.0,
- solver_type: int = 1,
- static_friction: float = 1.0,
- dynamic_friction: float = 1.0,
- restitution: float = 0.0,
- enable_gpu: bool = False,
- gpu_dynamics: PhysicsGpuDynamicsConfig = PhysicsGpuDynamicsConfig(),
- enable_contact_reports: bool = True,
- enable_body_accelerations: bool = False,
- cpu_dispatcher_threads: int = 4,
- bounce_threshold_velocity: float = 2.0,
- friction_offset_threshold: float = 0.03999999910593033,
- friction_correlation_distance: float = 0.02500000037252903,
- enable_stabilization: bool = False,
- friction_combine_mode: kangengine.physics.MaterialCombineMode = <MaterialCombineMode.MIN: 1>,
- restitution_combine_mode: kangengine.physics.MaterialCombineMode = <MaterialCombineMode.AVERAGE: 0>,
Create physics configuration from keyword arguments.
- property bounce_threshold_velocity¶
Relative speed below which contacts do not bounce.
- property cpu_dispatcher_threads¶
Worker threads used by the PhysX CPU dispatcher.
- property dt¶
Simulation timestep in seconds.
- property dynamic_friction¶
Default material dynamic friction.
- property enable_body_accelerations¶
Enable PhysX rigid-body acceleration state.
- property enable_contact_reports¶
Enable contact collection during simulation.
- property enable_gpu¶
Enable PhysX GPU features when available.
- property enable_stabilization¶
Enable the PhysX scene stabilization pass.
- property friction_combine_mode¶
- property friction_correlation_distance¶
Distance used to correlate friction patches.
- property friction_offset_threshold¶
Contact separation threshold for friction anchors.
- property gpu_dynamics¶
GPU dynamics memory capacities used at scene creation.
- property restitution¶
Default material restitution.
- property restitution_combine_mode¶
- property solver_type¶
0 for PGS, 1 for TGS.
- Type:
Solver type
- property static_friction¶
Default material static friction.
- static y_up() PhysicsConfig¶
Create configuration for a Y-up world.
- static z_up() PhysicsConfig¶
Create configuration for a Z-up world.
- class kangengine.physics.PhysicsGpuDynamicsConfig[native]¶
PhysX GPU dynamics buffer capacities used during scene creation.
- __init__(
- *,
- temp_buffer_capacity: int = 67108864,
- max_rigid_contact_count: int = 4194304,
- max_rigid_patch_count: int = 524288,
- heap_capacity: int = 268435456,
- found_lost_pairs_capacity: int = 4194304,
- found_lost_aggregate_pairs_capacity: int = 33554432,
- total_aggregate_pairs_capacity: int = 2097152,
- collision_stack_size: int = 268435456,
- max_num_partitions: int = 8,
Create GPU dynamics capacities from keyword arguments.
- property collision_stack_size¶
GPU collision stack size in bytes.
- property found_lost_aggregate_pairs_capacity¶
Capacity for found and lost aggregate pairs.
- property found_lost_pairs_capacity¶
Capacity for found and lost rigid pairs.
- property heap_capacity¶
GPU dynamics heap capacity in bytes.
- property max_num_partitions¶
Maximum GPU dynamics partition count.
- property max_rigid_contact_count¶
Maximum rigid contact count.
- property max_rigid_patch_count¶
Maximum rigid contact patch count.
- property temp_buffer_capacity¶
Temporary GPU buffer capacity in bytes.
- property total_aggregate_pairs_capacity¶
Capacity for all aggregate pairs.
- class kangengine.physics.PhysicsMaterialDesc[native]¶
PhysX material factors used by collision shapes.
- as_tuple() tuple[float, float, float]¶
Return (static_friction, dynamic_friction, restitution).
- property dynamic_friction¶
PhysX dynamic friction coefficient.
- property friction_combine_mode¶
- property restitution¶
PhysX restitution coefficient.
- property restitution_combine_mode¶
- property static_friction¶
PhysX static friction coefficient.
- class kangengine.physics.CollisionMaterialOverride[native]¶
Collision material override matched by body/geom name or index. Later overrides win.
- static all_geoms(
- material: object,
Override every collision geom in the built actor/articulation.
- property body_index¶
Matched body index, or -1 for name/all matching.
- property body_name¶
Matched body name, or empty for all bodies.
- static for_body(
- body_name: str,
- material: object,
Override every collision geom on a named body.
- static for_geom(
- body_name: str,
- geom_name: str,
- material: object,
Override one named collision geom on a named body.
- static for_indices(
- body_index: int,
- geom_index: int,
- material: object,
Override by imported body index and collision geom index.
- property geom_index¶
Matched geom index inside the body, or -1.
- property geom_name¶
Matched geom name, or empty for all geoms.
- property material¶
Override material.
- class kangengine.physics.ContactPoint[native]¶
Contact point reported by the PhysX world.
- property impulse¶
Contact impulse.
- property normal¶
World-space contact normal.
- property position¶
World-space contact position.
- property separation¶
Contact separation distance.
- class kangengine.physics.RigidDynamic[native]¶
PhysX dynamic rigid body owned by a PhysicsWorld.
- add_force(force: Any) None¶
Overloaded function.
add_force(self: kangengine.RigidDynamic, force: npt.ArrayLike | torch.Tensor) -> None
Apply a world-space force from a numpy array.
add_force(self: kangengine.RigidDynamic, force: collections.abc.Sequence[float]) -> None
Apply a world-space force.
- add_force_at_position(force: Any, position: Any) None¶
Overloaded function.
add_force_at_position(self: kangengine.RigidDynamic, force: npt.ArrayLike | torch.Tensor, position: npt.ArrayLike | torch.Tensor) -> None
Apply a world-space force at a world-space position.
add_force_at_position(self: kangengine.RigidDynamic, force: collections.abc.Sequence[float], position: collections.abc.Sequence[float]) -> None
Apply a world-space force at a world-space position.
- get_collision_materials() list[PhysicsMaterialDesc]¶
Return independent material descriptions in collision shape order.
- get_convex_collision_meshes() list[Any]¶
Return render meshes reconstructed from cooked convex shapes.
- get_inverse_mass() float¶
Return inverse rigid body mass.
- get_local_com_pose() NDArray[np.float32]¶
Return actor-local [position xyz, rotation xyzw].
- get_local_com_position() Any¶
Return the center-of-mass position in the actor frame.
- get_local_com_quat_xyzw() Any¶
Return the center-of-mass frame rotation as an XYZW quaternion.
- get_mass() float¶
Return rigid body mass.
- get_mass_space_inertia() Any¶
Return the diagonal inertia tensor in the center-of-mass frame.
- get_mass_space_inverse_inertia() Any¶
Return inverse diagonal inertia in the center-of-mass frame.
- get_root_angular_velocity() Any¶
Return root angular velocity.
- get_root_linear_velocity() Any¶
Return root linear velocity.
- get_root_position() Any¶
Return root position as [x, y, z].
- get_root_quat_xyzw() Any¶
Return root rotation as XYZW quaternion.
- is_sleeping() bool¶
Return whether this rigid body is sleeping.
- num_shapes() int¶
Return the number of collision shapes attached to this body.
- release() None¶
Release the underlying PhysX actor.
- set_kinematic(enabled: bool = True) None¶
Enable or disable kinematic rigid-body behavior.
- set_local_com_pose(pose: ArrayLike) None¶
Set actor-local [position xyz, rotation xyzw]; preserve actor pose.
- set_mass(mass: float) None¶
Set mass in kg without changing inertia or waking the actor.
- set_mass_space_inertia(inertia: ArrayLike) None¶
Set principal inertia in kg*m^2 in the COM frame.
- set_root_state(
- pos: Any,
- quat_xyzw: Any,
- linear_velocity: Any = ...,
- angular_velocity: Any = ...,
Overloaded function.
set_root_state(self: kangengine.RigidDynamic, pos: npt.ArrayLike | torch.Tensor, quat_xyzw: npt.ArrayLike | torch.Tensor, linear_velocity: npt.ArrayLike | torch.Tensor, angular_velocity: npt.ArrayLike | torch.Tensor) -> None
Reset root pose and dynamic velocities; kinematics use pose only.
set_root_state(self: kangengine.RigidDynamic, pos: collections.abc.Sequence[float], quat_xyzw: collections.abc.Sequence[float], linear_velocity: collections.abc.Sequence[float] = [0.0, 0.0, 0.0], angular_velocity: collections.abc.Sequence[float] = [0.0, 0.0, 0.0]) -> None
Reset root pose and dynamic velocities; kinematics use pose only.
- set_root_velocity(
- linear_velocity: ArrayLike,
- angular_velocity: ArrayLike,
- kangengine.physics.unwrap_native(obj: Any) Any[python]¶
Return
obj._nativewhenobjis a KangEngine Python wrapper.- Return type:
Any
- kangengine.physics.mjcf_friction_to_physx(
- friction: collections.abc.Sequence[float],
Map MJCF geom friction values to KangEngine’s PhysX material descriptor.
- class kangengine.physics.PhysicsWorld(config: PhysicsConfig | None = None)[python]¶
Bases:
_NativeWrapperPhysX simulation world.
The class is always importable. Constructing it requires a KangEngine build with PhysX bindings. The wrapper owns a native
_ke.physics.PhysicsWorldand forwards calls directly.- add_default_ground() None¶
- Return type:
None
- add_heightfield(
- heights: Any,
- rows: int,
- cols: int,
- horizontal_scale: float = 1.0,
- up_axis: Any = None,
- center: bool = True,
- register_as_ground: bool = True,
- material: PhysicsMaterialDesc | None = None,
- Return type:
bool
- add_heightmap_collision(
- path: str,
- up_axis: Any = None,
- horizontal_scale: float = 1.0,
- height_scale: float = 64.0,
- height_offset: float = -16.0,
- sample_stride: int = 1,
- center: bool = True,
- register_as_ground: bool = True,
- material: PhysicsMaterialDesc | None = None,
- Return type:
bool
- add_static_box(
- half_extents: Sequence[float],
- pos: Sequence[float],
- quat_xyzw: Sequence[float] = (0.0, 0.0, 0.0, 1.0),
- register_as_ground: bool = True,
- Return type:
RigidStatic
- add_triangle_mesh(
- mesh,
- *,
- position=(0.0, 0.0, 0.0),
- quat_xyzw=(0.0, 0.0, 0.0, 1.0),
- material=None,
- gpu_compatible=True,
- contact_offset=0.02,
- rest_offset=0.0,
- register_as_ground=True,
- num_prims_per_leaf=4,
- weld_tolerance=0.0,
Cook/cache an immutable source mesh and create an exclusive static shape.
- Return type:
RigidStatic
- clear_contacts() None¶
- Return type:
None
- clear_ground_actors() None¶
- Return type:
None
- create_d6_joint(
- body0: JointBody | RigidDynamic | RigidStatic | None,
- body1: JointBody | RigidDynamic | RigidStatic | None,
- *,
- config: D6JointConfig | None = None,
Connect rigid bodies/link handles; None denotes the world.
Frames are local xyz/xyzw poses (world poses for None endpoints). Call only between completed physics steps.
- Return type:
- create_dynamic_box(
- half_extents: Sequence[float],
- pos: Sequence[float],
- quat_xyzw: Sequence[float] = (0.0, 0.0, 0.0, 1.0),
- density: float = 1.0,
- Return type:
- create_dynamic_convex_compound(
- parts: Sequence[ConvexMeshPart],
- pos: Any,
- quat_xyzw: Any = (0.0, 0.0, 0.0, 1.0),
- density: float = 1.0,
- cooking: ConvexCookingOptions | None = None,
- material: PhysicsMaterialDesc | None = None,
- collision_group: int = 0,
- contact_offset: float = 0.02,
- rest_offset: float = 0.0,
Cook convex parts as shapes on one dynamic rigid body.
- Return type:
- create_dynamic_rigid(
- data: Any,
- pos: Any,
- quat_xyzw: Any = (0.0, 0.0, 0.0, 1.0),
- density: float = 1.0,
- collision_group: int = 0,
- contact_offset: float = 0.02,
- rest_offset: float = 0.0,
- material_overrides: Sequence[CollisionMaterialOverride] = (),
- kinematic: bool = False,
Create a rigid body; triangle collision meshes require kinematic mode.
- Return type:
- create_dynamic_sphere(
- radius: float,
- pos: Sequence[float],
- quat_xyzw: Sequence[float] = (0.0, 0.0, 0.0, 1.0),
- density: float = 1.0,
- Return type:
- create_static_convex_compound(
- parts: Sequence[ConvexMeshPart],
- pos: Any = (0.0, 0.0, 0.0),
- quat_xyzw: Any = (0.0, 0.0, 0.0, 1.0),
- cooking: ConvexCookingOptions | None = None,
- material: PhysicsMaterialDesc | None = None,
- collision_group: int = 0,
- contact_offset: float = 0.02,
- rest_offset: float = 0.0,
- register_as_ground: bool = False,
Cook convex parts as shapes on one static rigid body.
- Return type:
Any
- get_collision_geometry(
- articulation: Articulation,
- *,
- environment: Sequence[RigidStatic] = (),
- include_mesh_data: bool = False,
Copy actual collider metadata, with optional unscaled cooked mesh data.
- Return type:
dict[str,Any]
- get_contact_forces(
- articulation: Articulation | Articulation,
- ground_only: bool = False,
Return contact-force data for an articulation.
The concrete return type is backend-dependent. Treat array-like results as borrowed or refreshable data unless you explicitly copy them; later simulation steps or synchronization calls may update the underlying storage.
- Return type:
Any
- get_contacts(
- rigid: RigidDynamic | None = None,
Return last-step snapshots; select rigid to orient impulses onto it.
Positions are world-space meters; impulses are N*s. Sleeping pairs may report no contacts. Divide impulse by simulation dt for force in N.
- Return type:
Sequence[ContactPoint]
- get_ground_contact_forces(
- articulation: Articulation | Articulation,
- Return type:
Any
- get_rigid_contact_force(
- rigid: RigidDynamic,
- ground_only: bool = False,
- Return type:
Any
- get_rigid_ground_contact_force(
- rigid: RigidDynamic,
- Return type:
Any
- get_simulation_statistics() dict[str, int]¶
Return contact counts and SDK-supported GPU memory demand statistics.
- Return type:
dict[str,int]
- get_static_collision_geometry() list[dict]¶
Copy static simulation geometry with xyz/xyzw poses and snapshot-local indices.
- Return type:
list[dict]
- joint_body(body: RigidDynamic | RigidStatic) JointBody¶
Get a checked endpoint for a rigid body in this world.
- Return type:
- num_body_actors() int¶
- Return type:
int
- num_cached_materials() int¶
- Return type:
int
- num_contacts() int¶
- Return type:
int
- num_ground_actors() int¶
- Return type:
int
- query_collisions(
- articulation: Articulation,
- link_poses: ArrayLike | Tensor,
- *,
- environment: Sequence[RigidStatic] = (),
- self_collision: bool = True,
- exclude_adjacent: bool = True,
- body_pairs: Sequence[Sequence[int]] | None = None,
- excluded_body_pairs: Sequence[Sequence[int]] = (),
- excluded_environment_pairs: Sequence[Sequence[int]] = (),
Query single/batched world xyz/xyzw link poses without stepping or mutation.
- Return type:
list[dict[str,Any]]
- remove_static_actor(actor: RigidStatic) None¶
Remove a static actor and its ground registration; invalidates actor.
- Return type:
None
- set_dt(dt: float) None¶
- Return type:
None
- set_rigid_collision_material(
- rigid: RigidDynamic | RigidStatic,
- material: PhysicsMaterialDesc,
- Return type:
int
- set_rigid_collision_material_overrides(
- rigid: RigidDynamic | RigidStatic,
- data: Any,
- material_overrides: Sequence[CollisionMaterialOverride],
- Return type:
int
- step() None¶
Advance simulation by one configured timestep.
- Return type:
None
- class kangengine.physics.D6Axis[native]¶
Members:
X
Y
Z
TWIST
SWING1
SWING2
- SWING1 = <D6Axis.SWING1: 4>¶
- SWING2 = <D6Axis.SWING2: 5>¶
- TWIST = <D6Axis.TWIST: 3>¶
- X = <D6Axis.X: 0>¶
- Y = <D6Axis.Y: 1>¶
- Z = <D6Axis.Z: 2>¶
- D6Axis.name -> str
- property value¶
- class kangengine.physics.D6Motion[native]¶
Members:
LOCKED
LIMITED
FREE
- FREE = <D6Motion.FREE: 2>¶
- LIMITED = <D6Motion.LIMITED: 1>¶
- LOCKED = <D6Motion.LOCKED: 0>¶
- D6Motion.name -> str
- property value¶
- class kangengine.physics.D6DriveAxis[native]¶
Members:
X
Y
Z
TWIST
SWING
SLERP
- SLERP = <D6DriveAxis.SLERP: 5>¶
- SWING = <D6DriveAxis.SWING: 4>¶
- TWIST = <D6DriveAxis.TWIST: 3>¶
- X = <D6DriveAxis.X: 0>¶
- Y = <D6DriveAxis.Y: 1>¶
- Z = <D6DriveAxis.Z: 2>¶
- D6DriveAxis.name -> str
- property value¶
- class kangengine.physics.D6DriveConfig[native]¶
- __init__(
- *,
- stiffness: float = 0.0,
- damping: float = 0.0,
- force_limit: float = 3.4028234663852886e+38,
- acceleration: bool = False,
- property acceleration¶
- property damping¶
- property force_limit¶
- property stiffness¶
- class kangengine.physics.D6JointConfig[native]¶
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: kangengine.physics.D6JointConfig) -> None
__init__(self: kangengine.physics.D6JointConfig, config: kangengine.physics.D6JointConfig) -> None
- property break_force¶
- property break_torque¶
- property drive_angular_velocity¶
- property drive_linear_velocity¶
- property drive_target¶
- property drives¶
- property enabled¶
- property frame0¶
- property frame1¶
- property linear_limits¶
- property locked_axes¶
- property motions¶
- property swing_limits¶
- property twist_limits¶
- validate() None¶
Validate all settings without changing a joint.
- class kangengine.physics.D6Joint[native]¶
- property broken¶
- property config¶
Return an independent configuration snapshot.
- property enabled¶
- property frame0¶
- property frame1¶
- get_wrench() list[float]¶
Read [Fx,Fy,Fz,Tx,Ty,Tz] on endpoint 1 in world axes, torque about frame1. Call after a completed step. Disabled/broken joints return zero. Direct GPU reads synchronize. TGS torque reporting has backend limitations; see D6_JOINTS.md.
- release() None¶
- set_break_force(force: float, torque: float) None¶
- set_drive(axis: D6DriveAxis, config: D6DriveConfig) None¶
- set_drive_target(pose: Sequence[float]) None¶
- set_drive_velocity(linear: Sequence[float], angular: Sequence[float]) None¶
- set_enabled(enabled: bool) None¶
- set_frame0(frame0: Sequence[float]) None¶
- set_frame1(frame1: Sequence[float]) None¶
- set_frames(frame0: Sequence[float], frame1: Sequence[float]) None¶
- set_swing_limit(y_angle: float, z_angle: float) None¶
- set_twist_limit(lower: float, upper: float) None¶
- property valid¶
- class kangengine.physics.D6Batch(joints: Sequence[D6Joint]) None[python]¶
Python batch interface over individual D6 handles, with batched CUDA readback.
Removing an endpoint invalidates only the joints connected to it. The caller owns environment/limb-to-index mapping and simulation timing.
- property broken¶
- classmethod create(
- world: PhysicsWorld | NativePhysicsWorld,
- bodies0: Sequence[JointBody | RigidDynamic | RigidStatic | None],
- bodies1: Sequence[JointBody | RigidDynamic | RigidStatic | None],
- *,
- frames0: ArrayLike | Tensor,
- frames1: ArrayLike | Tensor,
- config: D6JointConfig | None = None,
Connect paired body/link handles; None denotes the fixed world.
Frames are [N,7] xyz/xyzw poses in each endpoint’s local coordinates (world coordinates for None). Explicit frames override config frames. Raw rigid bodies are also accepted and converted to endpoint handles. Torch frames are detached and converted to CPU float32, including CUDA inputs, then converted to Python lists once per frame batch. This device transfer synchronizes before the CPU PhysX calls.
- Return type:
- classmethod create_world_frames(
- world: PhysicsWorld | NativePhysicsWorld,
- articulations: Sequence[Articulation],
- frame_names: Sequence[str],
- *,
- world_frames: ArrayLike | Tensor,
- config: D6JointConfig | None = None,
Attach named model frames to world poses using their physical owners.
Example: attach a robot’s named frame at a world-space xyz/xyzw pose:
joints = D6Batch.create_world_frames( physics_world, [robot], ["attachment_frame"], world_frames=[[0, 0, 0, 0, 0, 0, 1]], )
Resolves the owning body and local frame offset automatically.
- Return type:
- classmethod create_world_links(
- world: PhysicsWorld | NativePhysicsWorld,
- articulations: Sequence[Articulation],
- link_indices: Sequence[int],
- *,
- world_frames: ArrayLike | Tensor,
- link_frames: ArrayLike | Tensor,
- config: D6JointConfig | None = None,
Connect each link to the fixed world.
world_frames: world-space attachment poses; link_frames: link-local poses. Both use [x, y, z, qx, qy, qz, qw]. CPU/CUDA tensors are accepted; CUDA frames are copied to CPU before setting PhysX constraints.
- Return type:
- property enabled¶
- fetch_wrenches(
- *,
- gpu_system: PhysicsGpuSystem | NativePhysicsGpuSystem | None = None,
Refresh a reusable Torch CUDA [N,6] tensor without host force copies.
Pass an initialized PhysicsGpuSystem on the first call. Later calls reuse that system and the output tensor. Operations run on the current Torch stream. Use the same stream for consumers, or synchronize them before overwriting this shared tensor in another stream.
- Return type:
None
- get_wrenches(indices: Sequence[int] | None = None) NDArray[np.float32]¶
Return host float32 [N,6] wrenches; Direct GPU reads synchronize per joint.
- Return type:
GenericAlias[float32]
- release() None¶
- Return type:
None
- set_break_force(indices: Sequence[int], force: float, torque: float) None¶
- Return type:
None
- set_drive(
- indices: Sequence[int],
- axis: D6DriveAxis,
- config: D6DriveConfig,
- Return type:
None
- set_drive_targets(indices: Sequence[int], poses: ArrayLike | Tensor) None¶
- Return type:
None
- set_drive_velocity(
- indices: Sequence[int],
- linear: Sequence[float],
- angular: Sequence[float],
- Return type:
None
- set_enabled(indices: Sequence[int], enabled: bool) None¶
- Return type:
None
- set_frames0(indices: Sequence[int], frames: ArrayLike | Tensor) None¶
Update endpoint 0 poses; Torch inputs are detached/copied to CPU.
- Return type:
None
- set_frames1(indices: Sequence[int], frames: ArrayLike | Tensor) None¶
Update endpoint 1 poses; Torch inputs are detached/copied to CPU.
- Return type:
None
- set_linear_limit(
- indices: Sequence[int],
- axis: D6Axis,
- lower: float,
- upper: float,
- Return type:
None
- set_link_frames(indices: Sequence[int], frames: ArrayLike | Tensor) None¶
Link-local frame1 updates for batches created with create_world_links.
- Return type:
None
- set_swing_limit(indices: Sequence[int], y_angle: float, z_angle: float) None¶
- Return type:
None
- set_twist_limit(indices: Sequence[int], lower: float, upper: float) None¶
- Return type:
None
- set_world_frames(indices: Sequence[int], frames: ArrayLike | Tensor) None¶
World-space frame0 updates for batches created with create_world_links.
- Return type:
None
- property size¶
- property wrenches¶
Torch CUDA [N,6] from the last fetch; clone() to preserve a snapshot.
- class kangengine.physics.ArticulationConfig[native]¶
PhysX articulation construction settings.
- __init__(
- *,
- fix_base: bool = True,
- disable_self_collision: bool = True,
- use_aggregate: bool = False,
- solver_position_iteration_count: int = 16,
- solver_velocity_iteration_count: int = 1,
- collision_group: int = 0,
- root_linear_damping: float = 0.0,
- root_angular_damping: float = 0.05000000074505806,
- link_linear_damping: float = 0.0,
- link_angular_damping: float = 0.05000000074505806,
- max_angular_velocity: float = 100.0,
- max_depenetration_velocity: float = 1.0000000331813535e+32,
- sleep_threshold: float = 0.004999999888241291,
- stabilization_threshold: float = 0.0005000000237487257,
- enable_gyroscopic_forces: bool = False,
- contact_offset: float = 0.019999999552965164,
- rest_offset: float = 0.0,
- material_overrides: collections.abc.Sequence[CollisionMaterialOverride] = [],
- enable_ccd: bool = False,
Create articulation configuration from keyword arguments.
- add_material_override(
- self: ArticulationConfig,
- override: CollisionMaterialOverride,
Append a build-time collision material override. Later overrides win.
- clear_material_overrides(
- self: ArticulationConfig,
Remove all collision material overrides.
- property collision_group¶
Collision group bit used for created actors.
- property contact_offset¶
PhysX contact offset.
- property disable_self_collision¶
Disable self collision between articulation links.
- property enable_ccd¶
Enable continuous collision detection.
- property enable_gyroscopic_forces¶
Enable gyroscopic forces on articulation links.
- property fix_base¶
Whether the root body is fixed.
- static fixed_base() ArticulationConfig¶
Create configuration for a fixed-base articulation.
- static free_base() ArticulationConfig¶
Create configuration for a free-base articulation.
- property link_angular_damping¶
Angular damping for child links.
- property link_linear_damping¶
Linear damping for child links.
- property material_overrides¶
Build-time collision material overrides.
- property max_angular_velocity¶
Maximum angular velocity for links.
- property max_depenetration_velocity¶
Maximum depenetration velocity for links.
- property rest_offset¶
PhysX rest offset.
- property root_angular_damping¶
Angular damping for the root link.
- property root_linear_damping¶
Linear damping for the root link.
- property sleep_threshold¶
Articulation sleep threshold.
- property solver_iterations¶
Compatibility alias for solver_position_iteration_count.
- property solver_position_iteration_count¶
Position solver iteration count.
- property solver_velocity_iteration_count¶
Velocity solver iteration count.
- property stabilization_threshold¶
Articulation stabilization threshold.
- property use_aggregate¶
Group articulation links into one PhysX broadphase aggregate.
- class kangengine.physics.Articulation(native_articulation: Any | None = None)[python]¶
Bases:
_NativeWrapperPhysX articulation wrapper.
- static build(
- physics: PhysicsWorld | PhysicsWorld,
- data: Any,
- config: ArticulationConfig | None = None,
- Return type:
- static build_from_template(
- physics,
- template,
- *,
- config=None,
- Return type:
- get_collision_materials() list[list[PhysicsMaterialDesc]]¶
Return copies of the collision materials, indexed by link then shape.
- Return type:
list[list[PhysicsMaterialDesc]]
- get_link_local_com_poses() NDArray[np.float32]¶
Link-local
[position xyz, rotation xyzw], shape(B, 7).- Return type:
GenericAlias[float32]
- get_link_mass_space_inertias() NDArray[np.float32]¶
Principal inertia in each COM frame, shape
(B, 3), kg*m².- Return type:
GenericAlias[float32]
- get_link_masses() NDArray[np.float32]¶
Masses in logical link order, shape
(B,), kg.- Return type:
GenericAlias[float32]
- get_link_shape_counts() list[int]¶
- Return type:
list[int]
- num_dofs() int¶
- Return type:
int
- num_links() int¶
- Return type:
int
- release() None¶
- Return type:
None
- set_collision_material(
- physics: PhysicsWorld | PhysicsWorld,
- material: PhysicsMaterialDesc,
- Return type:
int
- set_collision_material_overrides(
- physics: PhysicsWorld | PhysicsWorld,
- material_overrides: Sequence[CollisionMaterialOverride],
- Return type:
int
- set_link_local_com_poses(
- link_indices: Sequence[int],
- poses,
- Return type:
None
- set_link_mass_space_inertias(
- link_indices: Sequence[int],
- inertias,
- Return type:
None
- set_link_masses(
- link_indices: Sequence[int],
- masses,
Set selected masses in kg; inertia remains unchanged.
- Return type:
None
- set_root_velocity(linear_velocity, angular_velocity) None¶
Set world linear (m/s) and angular (rad/s) velocities, each shape (3,).
- Return type:
None
- class kangengine.physics.PhysicsBridge None[python]¶
Bases:
_NativeWrapperSync PhysX articulation state into scene/render visuals.
- add(
- artic: Articulation | Articulation,
- skel_bridge: Any,
- Return type:
None
- add_collision_visuals(
- artic: Articulation | Articulation,
- scene: Any,
- path: str = '/collision',
- visible_by_default: bool = False,
- set_collision_visible(visible: bool) None¶
- Return type:
None
- sync() None¶
- Return type:
None
- class kangengine.physics.GpuPhysicsConfig[native]¶
Configuration for explicit GPU physics state synchronization.
- __init__(
- *,
- cuda_device_id: int = 0,
- max_contact_pairs: int = 65536,
- max_contact_points: int = 262144,
Create GPU synchronization configuration from keyword arguments.
- property cuda_device_id¶
CUDA device ordinal used by GPU physics.
- property max_contact_pairs¶
Maximum mirrored contact pair count.
- property max_contact_points¶
Maximum mirrored contact point count.
- class kangengine.physics.PhysicsGpuStateViews[native]¶
Backend-owned GPU state and command-buffer views. State buffers are refreshed by the corresponding fetch methods; command buffers are submitted by apply methods. The views become invalid when their PhysicsGpuSystem is released.
- property articulation_centroidal_bias_forces¶
- property articulation_centroidal_momentum_matrices¶
- property articulation_com_root¶
- property articulation_com_world¶
- property articulation_coriolis_forces¶
- property articulation_dense_jacobians¶
- property articulation_gravity_forces¶
- property articulation_joint_accelerations¶
Articulation joint-acceleration state.
- property articulation_joint_forces¶
Articulation joint-force state.
- property articulation_joint_positions¶
Articulation joint-position state.
- property articulation_joint_velocities¶
Articulation joint-velocity state.
- property articulation_link_accelerations¶
- property articulation_link_data¶
position xyz (m), quaternion xyzw, linear velocity xyz (m/s), angular velocity xyz (rad/s). Pose and velocity have separate fetch methods; padded links are not state.
- Type:
World state [A,max_links,13]
- property articulation_link_forces¶
- property articulation_link_incoming_joint_forces¶
Incoming joint-force state for articulation links.
- property articulation_link_torques¶
- property articulation_mass_matrices¶
- property articulation_target_joint_positions¶
Joint-position target command buffer.
- property articulation_target_joint_velocities¶
Joint-velocity target command buffer.
- property contact_pair_body_refs¶
Body references for packed contact pairs.
- property contact_pair_count¶
Number of valid packed contact pairs.
- property contact_pair_headers¶
Headers describing packed contact-pair ranges.
- property contact_pairs¶
Packed contact-pair state buffer.
- property contact_point_count¶
Number of valid packed contact points.
- property contact_point_pair_indices¶
Contact-pair index for each packed contact point.
- property contact_points¶
Packed contact-point state buffer.
- property rigid_accelerations¶
Rigid COM linear/angular acceleration state.
- property rigid_data¶
position xyz (m), quaternion xyzw, linear velocity xyz (m/s), angular velocity xyz (rad/s). Refreshed by fetch_rigid_data().
- Type:
World state [R,13]
- property rigid_force¶
Rigid force command buffer submitted by apply_rigid_force().
- property rigid_torque¶
Rigid torque command buffer submitted by apply_rigid_torque().
- class kangengine.physics.PhysicsGpuSystem(
- world: PhysicsWorld | PhysicsWorld,
- config: GpuPhysicsConfig | None = None,
Bases:
_NativeWrapperExplicit GPU physics synchronization wrapper.
- articulation_row(
- articulation: Articulation | Articulation,
- Return type:
int
- fetch_d6_wrenches(
- joints: Sequence[D6Joint],
- output: GpuArrayView,
Write joint wrenches into caller-owned CUDA float32 [N,6] storage.
The output view supplies the CUDA stream and must remain valid until that stream completes. D6Batch.fetch_wrenches manages Torch storage.
- Return type:
None
- rigid_row(rigid: RigidDynamic) int¶
- Return type:
int
- views() PhysicsGpuStateViews¶
Return borrowed GPU state views owned by this PhysicsGpuSystem.
The returned object may reference buffers managed by the native GPU physics system. Keep this PhysicsGpuSystem alive while using the views, and do not assume values remain unchanged after later simulation, synchronization, or refresh operations.
- Return type:
- kangengine.physics.aggregate_contact_sensors_cuda(...)[native]¶
Aggregates contact sensor outputs on the GPU. Available only in CUDA-enabled builds.
Collision visual notes¶
PhysicsBridge.add_collision_visuals(...) creates optional SceneGraph debug
prims for articulation collision shapes. These prims mirror the existing PhysX
collision descriptors and carry scene-side CollisionShapeComponent metadata;
they do not create additional simulation shapes.
MJCF primitive collision geoms are imported directly. Collidable MJCF mesh geoms are not cooked yet; bodies with unsupported collidable mesh geoms may receive KangEngine fallback boxes. Visual-only mesh geoms remain render-only.