Karana.KUtils.vizutils#

Classes and functions associated with visualizing forces.

Classes#

NodeForceVisualizer

This class is a helper to visualize the force on a Node.

LastContactVisualizer

This class is a helper to visualize forces generated by contact.

SpringForceVisualizer

This class is a helper to visualize forces generated by contact.

SpringModelProtocol

A protocol for classes representing a spring model between a pair of nodes.

Functions#

computeSphereSweptHull(positions, *[, sphere_radius, ...])

Compute a sphere-swept convex hull.

createBodyHullPartSpec(→ Karana.Scene.ScenePartSpec)

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

update()[source]#

Update the force visualization.

Unless constructed with auto_update=True, this needs to be called whenever the force changes in order to see the effect in the 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.

update(*args)[source]#

Update the force visualization.

This needs to be called whenever to the force changes in order to see the effect in the visualization.

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.

update(*args)[source]#

Update the force visualization.

Unless constructed with auto_update=True, this needs to be called whenever to the force changes in order to see the effect in the visualization.

class Karana.KUtils.vizutils.SpringModelProtocol[source]#

Bases: Protocol

A 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:

StaticMeshGeometry

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:

ScenePartSpec