Class Drawing3d
MonoBehaviour that accumulates 3D geometry (lines, shapes, point clouds, mesh instances, labels) into a single mesh and renders it each frame.
Inherited Members
Namespace: Unity.SimulationPro.Foundation.Visualizations
Assembly: Unity.SimulationPro.Foundation.Visualizations.dll
Syntax
public class Drawing3d : MonoBehaviour
Methods
AddPointCloud(int, Material)
Retrieves an existing dormant PointCloudDrawing or creates a new one, setting its initial capacity and material.
Declaration
public PointCloudDrawing AddPointCloud(int numPoints = 0, Material material = null)
Parameters
| Type | Name | Description |
|---|---|---|
| int | numPoints | Optional initial point capacity hint for pre-allocating buffers. |
| Material | material | Optional material override. Uses the manager's default point-cloud material when |
Returns
| Type | Description |
|---|---|
| PointCloudDrawing | A PointCloudDrawing ready to receive points. |
Clear()
Removes all geometry, labels, mesh instances, and point clouds from this drawing, returning supplemental objects to the dormant pool.
Declaration
public void Clear()
ClearDuration()
Cancels the auto-destroy timer, allowing the drawing to persist indefinitely.
Declaration
public void ClearDuration()
Create(float, Material)
Creates a new Drawing3d via Drawing3dManager.
Declaration
public static Drawing3d Create(float duration = -1, Material material = null)
Parameters
| Type | Name | Description |
|---|---|---|
| float | duration | Optional lifetime in seconds. Negative values mean the drawing persists indefinitely. |
| Material | material | Optional material override. Uses the manager's default vertex-color material when |
Returns
| Type | Description |
|---|---|
| Drawing3d | The new Drawing3d instance. |
Destroy()
Destroys the underlying GameObject, removing this drawing from the scene.
Declaration
public void Destroy()
DestroyAfterDelay(float)
Coroutine that waits for duration seconds and then calls Destroy().
Declaration
public IEnumerator DestroyAfterDelay(float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| float | duration | Delay in seconds before destruction. |
Returns
| Type | Description |
|---|---|
| IEnumerator | An enumerator for use with |
DrawArrow(Vector3, Vector3, Color32, float, float, float)
Draws a line from from to to with a cone arrowhead at the tip.
Declaration
public void DrawArrow(Vector3 from, Vector3 to, Color32 color, float thickness = 0.1, float arrowheadScale = 3, float arrowheadGradient = 0.5)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | from | The arrow tail position. |
| Vector3 | to | The arrow tip position. |
| Color32 | color | The arrow color. |
| float | thickness | The shaft thickness in world units. |
| float | arrowheadScale | Multiplier applied to the shaft thickness to compute the arrowhead radius. |
| float | arrowheadGradient | Ratio of arrowhead radius to length, controlling how pointy the cone is. |
DrawCircle(Vector3, Vector3, Color32, float, int)
Draws a double-sided filled circle (disc) with the given normal direction.
Declaration
public void DrawCircle(Vector3 center, Vector3 normal, Color32 color, float radius, int numRingVertices = 8)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | center | The disc center in world space. |
| Vector3 | normal | The surface normal direction. |
| Color32 | color | The fill color. |
| float | radius | The disc radius in world units. |
| int | numRingVertices | The number of vertices in the circumference ring. |
DrawCircleOneSided(Vector3, Vector3, Color32, float, int)
Draws a single-sided filled circle (disc) visible only from the side the normal faces.
Declaration
public void DrawCircleOneSided(Vector3 center, Vector3 normal, Color32 color, float radius, int numRingVertices = 8)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | center | The disc center in world space. |
| Vector3 | normal | The surface normal direction. |
| Color32 | color | The fill color. |
| float | radius | The disc radius in world units. |
| int | numRingVertices | The number of vertices in the circumference ring. |
DrawCone(Vector3, Vector3, Color32, float, int)
Draws a cone with a filled base disc and an apex at tipPosition.
Declaration
public void DrawCone(Vector3 basePosition, Vector3 tipPosition, Color32 color, float radius, int numRingVertices = 8)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | basePosition | The center of the base circle in world space. |
| Vector3 | tipPosition | The apex position in world space. |
| Color32 | color | The color (the base is rendered at half-brightness). |
| float | radius | The base circle radius in world units. |
| int | numRingVertices | The number of vertices in the base ring. |
DrawCuboid(Vector3, Vector3, Color32)
Draws an axis-aligned cuboid centered at center with the given half-extents.
Declaration
public void DrawCuboid(Vector3 center, Vector3 halfSize, Color32 color)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | center | The center position in world space. |
| Vector3 | halfSize | Half the width, height, and depth in world units. |
| Color32 | color | The fill color. |
DrawCuboid(Vector3, Vector3, Quaternion, Color32)
Draws a rotated cuboid centered at center with the given half-extents and orientation.
Declaration
public void DrawCuboid(Vector3 center, Vector3 halfSize, Quaternion rotation, Color32 color)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | center | The center position in world space. |
| Vector3 | halfSize | Half the width, height, and depth in local space. |
| Quaternion | rotation | The orientation of the cuboid. |
| Color32 | color | The fill color. |
DrawCylinder(Vector3, Vector3, Color32, float, int)
Draws a cylinder with capped ends between two endpoint positions with a uniform color.
Declaration
public void DrawCylinder(Vector3 bottom, Vector3 top, Color32 color, float radius, int numRingVertices = 8)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | bottom | The bottom center in world space. |
| Vector3 | top | The top center in world space. |
| Color32 | color | The fill color. |
| float | radius | The cylinder radius in world units. |
| int | numRingVertices | The number of vertices in each cap ring. |
DrawCylinder(Vector3, Vector3, Color32, Color32, float, int)
Draws a cylinder with capped ends between two endpoint positions with separate colors for each end.
Declaration
public void DrawCylinder(Vector3 bottom, Vector3 top, Color32 bottomColor, Color32 topColor, float radius, int numRingVertices = 8)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | bottom | The bottom center in world space. |
| Vector3 | top | The top center in world space. |
| Color32 | bottomColor | The color of the bottom cap and adjacent wall vertices. |
| Color32 | topColor | The color of the top cap and adjacent wall vertices. |
| float | radius | The cylinder radius in world units. |
| int | numRingVertices | The number of vertices in each cap ring. |
DrawLabel(string, Vector3, Color, float)
Adds a text label that is rendered in screen space at the 3D world position each frame.
Declaration
public void DrawLabel(string text, Vector3 position, Color color, float worldSpacing = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The label text. |
| Vector3 | position | The world-space anchor position. |
| Color | color | The text color. |
| float | worldSpacing | Optional horizontal offset in world units applied along the camera's right axis, useful for nudging labels away from geometry. |
DrawLine(Vector3, Vector3, Color32, float)
Draws a solid rectangular-cross-section line from from to to with a uniform color.
Declaration
public void DrawLine(Vector3 from, Vector3 to, Color32 color, float thickness = 0.1)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | from | The start point in world space. |
| Vector3 | to | The end point in world space. |
| Color32 | color | The line color. |
| float | thickness | The line thickness in world units. |
DrawLine(Vector3, Vector3, Color32, Color32, float)
Draws a solid rectangular-cross-section line from from to to with a per-endpoint color gradient.
Declaration
public void DrawLine(Vector3 from, Vector3 to, Color32 fromColor, Color32 toColor, float thickness = 0.1)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | from | The start point in world space. |
| Vector3 | to | The end point in world space. |
| Color32 | fromColor | The color at the start endpoint. |
| Color32 | toColor | The color at the end endpoint. |
| float | thickness | The line thickness in world units. |
DrawLineStrip(Vector3[], Color32, float)
Draws a connected strip of line segments through all points in stripPoints with a uniform color.
Declaration
public void DrawLineStrip(Vector3[] stripPoints, Color32 color, float thickness)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3[] | stripPoints | The sequence of points. |
| Color32 | color | The line color. |
| float | thickness | The line thickness in world units. |
DrawLineStrip(Vector3[], Color32[], float)
Draws a connected strip of line segments through all points in stripPoints with per-point colors.
Declaration
public void DrawLineStrip(Vector3[] stripPoints, Color32[] stripColors, float thickness)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3[] | stripPoints | The sequence of points. |
| Color32[] | stripColors | Colors corresponding to each point. |
| float | thickness | The line thickness in world units. |
DrawLines(Vector3[], Color32, float)
Draws multiple disconnected line segments from consecutive pairs in pointPairs with a uniform color.
Declaration
public void DrawLines(Vector3[] pointPairs, Color32 color, float thickness)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3[] | pointPairs | An array where each consecutive pair of elements defines one line segment. |
| Color32 | color | The line color. |
| float | thickness | The line thickness in world units. |
DrawLines(Vector3[], Color32[], float)
Draws multiple disconnected line segments from consecutive pairs in pointPairs, using per-endpoint colors.
Declaration
public void DrawLines(Vector3[] pointPairs, Color32[] colorPairs, float thickness)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3[] | pointPairs | An array where each consecutive pair of elements defines one line segment. |
| Color32[] | colorPairs | Colors corresponding to each point in |
| float | thickness | The line thickness in world units. |
DrawMesh(Mesh, Transform, Color32)
Draws a mesh instance using the position, rotation, and scale from transform, tinted with color.
Declaration
public void DrawMesh(Mesh source, Transform transform, Color32 color)
Parameters
| Type | Name | Description |
|---|---|---|
| Mesh | source | The source mesh to render. |
| Transform | transform | The transform providing position, rotation, and scale. |
| Color32 | color | The tint color applied to the mesh. |
DrawMesh(Mesh, Vector3, Quaternion, Vector3, Color32)
Draws a mesh instance at the given position, rotation, and scale, tinted with color. Uses an alpha-blended material when the color is semi-transparent.
Declaration
public void DrawMesh(Mesh source, Vector3 position, Quaternion rotation, Vector3 scale, Color32 color)
Parameters
| Type | Name | Description |
|---|---|---|
| Mesh | source | The source mesh to render. |
| Vector3 | position | The world-space position. |
| Quaternion | rotation | The world-space rotation. |
| Vector3 | scale | The local scale. |
| Color32 | color | The tint color. |
DrawMesh(Mesh, Vector3, Quaternion, Vector3, Material)
Draws a mesh instance at the given position, rotation, and scale using an explicit material. Returns the supplemental GameObject created for the mesh.
Declaration
public GameObject DrawMesh(Mesh source, Vector3 position, Quaternion rotation, Vector3 scale, Material material)
Parameters
| Type | Name | Description |
|---|---|---|
| Mesh | source | The source mesh to render. |
| Vector3 | position | The world-space position. |
| Quaternion | rotation | The world-space rotation. |
| Vector3 | scale | The local scale. |
| Material | material | The material to use. |
Returns
| Type | Description |
|---|---|
| GameObject | The GameObject hosting the mesh instance. |
DrawParallelepiped(Vector3, Vector3, Vector3, Vector3, Color32)
Draws a parallelepiped (generalized box) defined by a center and three edge vectors.
Declaration
public void DrawParallelepiped(Vector3 center, Vector3 x, Vector3 y, Vector3 z, Color32 color)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | center | The center position in world space. |
| Vector3 | x | Half-extent along the first edge direction. |
| Vector3 | y | Half-extent along the second edge direction. |
| Vector3 | z | Half-extent along the third edge direction. |
| Color32 | color | The fill color. |
DrawPath(IEnumerable<Vector3>, Color32, float)
Draws a continuous tube-like path through all points in path with mitered corners.
Declaration
public void DrawPath(IEnumerable<Vector3> path, Color32 color, float thickness = 0.1)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<Vector3> | path | The sequence of points defining the path. |
| Color32 | color | The path color. |
| float | thickness | The path thickness in world units. |
DrawPoint(Vector3, string, Color32, float)
Draws a point as a small octahedron centered at point with a 3D text label.
Declaration
public void DrawPoint(Vector3 point, string label, Color32 color, float radius = 0.1)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | point | The world-space position. |
| string | label | The text to display near the point. |
| Color32 | color | The point and label color. |
| float | radius | The radius of the octahedron in world units. |
DrawPoint(Vector3, Color32, float)
Draws a point as a small octahedron centered at point.
Declaration
public void DrawPoint(Vector3 point, Color32 color, float radius = 0.1)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | point | The world-space position. |
| Color32 | color | The point color. |
| float | radius | The radius of the octahedron in world units. |
DrawQuad(Vector3, Vector3, Vector3, Vector3, Color32, bool)
Draws a flat quadrilateral defined by four vertices.
Declaration
public void DrawQuad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Color32 color, bool doubleSided = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | a | First vertex. |
| Vector3 | b | Second vertex. |
| Vector3 | c | Third vertex. |
| Vector3 | d | Fourth vertex. |
| Color32 | color | The fill color. |
| bool | doubleSided | If |
DrawSphere(Vector3, Color32, float, int)
Draws a uniform sphere at center.
Declaration
public void DrawSphere(Vector3 center, Color32 color, float radius, int numDivisions = 16)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | center | The sphere center in world space. |
| Color32 | color | The sphere color. |
| float | radius | The sphere radius in world units. |
| int | numDivisions | The number of longitude divisions used to triangulate the sphere. |
DrawSpheroid(Vector3, Vector3, Quaternion, Color32, int)
Draws an ellipsoid (spheroid) at center with independent per-axis radii and an optional rotation.
Declaration
public void DrawSpheroid(Vector3 center, Vector3 radii, Quaternion rotation, Color32 color, int numDivisions = 16)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | center | The center in world space. |
| Vector3 | radii | The half-extents along each local axis. |
| Quaternion | rotation | The orientation of the ellipsoid. |
| Color32 | color | The fill color. |
| int | numDivisions | The number of longitude divisions used to triangulate the ellipsoid. |
DrawTriangle(Vector3, Vector3, Vector3, Color32)
Draws a single triangle with a uniform color.
Declaration
public void DrawTriangle(Vector3 a, Vector3 b, Vector3 c, Color32 color)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | a | First vertex. |
| Vector3 | b | Second vertex. |
| Vector3 | c | Third vertex. |
| Color32 | color | The fill color. |
DrawTriangle(Vector3, Vector3, Vector3, Color32, Color32, Color32)
Draws a single triangle with per-vertex colors.
Declaration
public void DrawTriangle(Vector3 a, Vector3 b, Vector3 c, Color32 colorA, Color32 colorB, Color32 colorC)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | a | First vertex. |
| Vector3 | b | Second vertex. |
| Vector3 | c | Third vertex. |
| Color32 | colorA | Color at the first vertex. |
| Color32 | colorB | Color at the second vertex. |
| Color32 | colorC | Color at the third vertex. |
DrawTriangleFan(Color32, Vector3, Vector3, params Vector3[])
Draws a triangle fan: a series of triangles sharing a common center vertex.
Declaration
public void DrawTriangleFan(Color32 color, Vector3 center, Vector3 first, params Vector3[] fanPoints)
Parameters
| Type | Name | Description |
|---|---|---|
| Color32 | color | The fill color for all triangles. |
| Vector3 | center | The shared center vertex. |
| Vector3 | first | The first outer vertex. |
| Vector3[] | fanPoints | Additional outer vertices, each forming a new triangle with the center and the preceding vertex. |
DrawTriangleStrip(Color32, Vector3, Vector3, params Vector3[])
Draws a triangle strip: a sequence of triangles where each new point forms a triangle with the two preceding points.
Declaration
public void DrawTriangleStrip(Color32 color, Vector3 first, Vector3 second, params Vector3[] otherPoints)
Parameters
| Type | Name | Description |
|---|---|---|
| Color32 | color | The fill color for all triangles. |
| Vector3 | first | The first vertex. |
| Vector3 | second | The second vertex. |
| Vector3[] | otherPoints | Subsequent vertices; each creates a new triangle. |
Init(Drawing3dManager, Material, float)
Initializes the drawing's mesh and renderer components. Called by CreateDrawing(float, Material).
Declaration
public void Init(Drawing3dManager parent, Material material, float duration = -1)
Parameters
| Type | Name | Description |
|---|---|---|
| Drawing3dManager | parent | The manager that owns this drawing. |
| Material | material | The rendering material to use. |
| float | duration | Optional lifetime in seconds. |
Refresh()
Uploads the accumulated vertex, color, and triangle data to the underlying mesh. Called automatically by Drawing3dManager each LateUpdate for dirty drawings.
Declaration
public void Refresh()
SetDuration(float)
Starts or restarts the auto-destroy timer so this drawing is destroyed after duration seconds.
Declaration
public void SetDuration(float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| float | duration | Lifetime in seconds. |
SetParent(Transform)
Parents this drawing's transform to parent and resets its local position and rotation to identity.
Declaration
public void SetParent(Transform parent)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | parent | The new parent transform. |
SetPosition(Vector3)
Sets the world-space position of this drawing's transform.
Declaration
public void SetPosition(Vector3 worldPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | worldPosition | The new world position. |
SetRotation(Quaternion)
Sets the world-space rotation of this drawing's transform.
Declaration
public void SetRotation(Quaternion worldRotation)
Parameters
| Type | Name | Description |
|---|---|---|
| Quaternion | worldRotation | The new world rotation. |