Karana.KUtils.vizutils#
Classes and functions associated with visualizing forces.
Classes#
This class is a helper to visualize the force on a Node. |
|
This class is a helper to visualize forces generated by contact. |
|
This class is a helper to visualize forces generated by contact. |
|
A protocol for classes representing a spring model between a pair of nodes. |
Functions#
|
Compute a sphere-swept convex hull. |
|
Create a ScenePartSpec for a convex hull over a body's nodes. |
Package Contents#
- class Karana.KUtils.vizutils.NodeForceVisualizer(name: str, scene: Karana.Scene.ProxyScene, force_scale: float | collections.abc.Callable = 0.01, radius: float = 0.01, color: Karana.Scene.Color = Color.WHITE, auto_update: bool = True)[source]#
This class is a helper to visualize the force on a Node.
The force is visualized as an arrow emanating from the point where the force is applied. The arrow’s length scales based on the magnitude of the force.
Unless constructed with auto_update=True, the update method must be called periodically to update the arrow.
- setNode(node: Karana.Dynamics.Node | None, update: bool = True)[source]#
Set the external force node to visualize.
- Parameters:
node (Node | None) – The node to visualize the force of, or None to disable
update (bool) – If True, immediately update the force visualization
- class Karana.KUtils.vizutils.LastContactVisualizer(name: str, contact: Karana.Collision.ContactForceBase, scene: Karana.Scene.ProxyScene, *, colors: tuple[Karana.Scene.Color, Karana.Scene.Color] = (Color.YELLOW, Color.BLUE), force_scale: float | collections.abc.Callable = 0.01, radius: float = 0.01, auto_update: bool = True)[source]#
This class is a helper to visualize forces generated by contact.
The force is visualized as a pair of arrows emanating from the point where the force is applied. The arrow’s length scales based on the magnitude of the force.
Unless constructed with auto_update=True, the update method must be called periodically to update the arrows.
- class Karana.KUtils.vizutils.SpringForceVisualizer(name: str, mdl: SpringModelProtocol, scene: Karana.Scene.ProxyScene, *, colors: tuple[Karana.Scene.Color, Karana.Scene.Color] = (Color.YELLOW, Color.BLUE), force_scale: float | collections.abc.Callable = 0.01, radius: float = 0.01, auto_update: bool = True)[source]#
This class is a helper to visualize forces generated by contact.
The force is visualized as a pair of arrows emanating from the point where the force is applied. The arrow’s length scales based on the magnitude of the force.
Unless constructed with auto_update=True, the update method must be called periodically to update the arrows.
- class Karana.KUtils.vizutils.SpringModelProtocol[source]#
Bases:
ProtocolA protocol for classes representing a spring model between a pair of nodes.
- sourceNode() Karana.Dynamics.Node[source]#
Return the starting node of the spring.
- targetNode() Karana.Dynamics.Node[source]#
Return the ending node of the spring.
- Karana.KUtils.vizutils.computeSphereSweptHull(positions, *, sphere_radius: float = 0.03, points_per_sphere: int = 20)[source]#
Compute a sphere-swept convex hull.
- Parameters:
positions – An Nx3 array of vertex positions to form a hull over.
sphere_radius (float) – Radius of the sphere to sweep over the hull. Defaults to 0.03.
points_per_sphere (int) – Number of points on the sphere surface approximation. Defaults to 20.
- Returns:
A StaticMeshGeometry for the sphere-swept convex hull
- Return type:
- Karana.KUtils.vizutils.createBodyHullPartSpec(body: Karana.Dynamics.PhysicalBody, *, sphere_radius: float = 0.03, points_per_sphere: int = 20, material: Karana.Scene.PhysicalMaterial | Karana.Scene.PhongMaterial | None = None) Karana.Scene.ScenePartSpec[source]#
Create a ScenePartSpec for a convex hull over a body’s nodes.
The resulting ScenePartSpec should be added to the body by calling PhysicalBody.addScenePartSpec.
- Parameters:
body (PhysicalBody) – The body of interest
sphere_radius (float) – Radius of the sphere swept through the hull. Defaults to 0.03.
points_per_sphere (int) – Number of points on the sphere surface approximation. Defaults to 20.
material (PhysicalMaterial | PhongMaterial | None) – Material to apply. If None, uses a default material.
- Returns:
A ScenePartSpec for the hull
- Return type: