Documentation
¶
Overview ¶
Package draw provides a Go API for creating and managing 3D visualizations with Viam's motion tools. It supports various geometric primitives (arrows, lines, points, NURBS curves), 3D models, and frame systems, with flexible color management and scene configuration options. All shapes can be serialized to Protobuf for rendering.
Index ¶
- Variables
- func DrawFrameSystemGeometries(frameSystem *referenceframe.FrameSystem, ...) (*drawv1.Transforms, error)
- func DrawGeometries(geometriesInFrame *referenceframe.GeometriesInFrame, colors []Color) (*drawv1.Transforms, error)
- func DrawGeometry(id string, geometry spatialmath.Geometry, pose spatialmath.Pose, parent string, ...) (*commonv1.Transform, error)
- func MetadataToStruct(metadata Metadata) (*structpb.Struct, error)
- func NewTransform(id string, name string, parent string, pose spatialmath.Pose, ...) (*commonv1.Transform, error)
- func WithAnimated(animated bool) sceneCameraOption
- func WithArrows(arrows Arrows) drawShapeOption
- func WithColorPalette(palette []Color, numPoses int) drawArrowsOption
- func WithColors[T ConfigurableColors](colors []Color) func(T)
- func WithGrid(grid bool) sceneMetadataOption
- func WithGridCellSize(gridCellSize float32) sceneMetadataOption
- func WithGridFadeDistance(gridFadeDistance float32) sceneMetadataOption
- func WithGridSectionSize(gridSectionSize float32) sceneMetadataOption
- func WithHSV(h, s, v float32) colorOption
- func WithLine(line Line) drawShapeOption
- func WithLineColors(lineColor Color, pointColor *Color) drawLineOption
- func WithLineWidth(width float32) drawLineOption
- func WithMetadataColors(colors ...Color) drawMetadataOption
- func WithModel(model Model) drawShapeOption
- func WithModelAnimationName(animationName string) drawModelOption
- func WithModelAssetSizeBytes(sizeBytes uint64) drawModelAssetOption
- func WithModelAssets(assets ...*ModelAsset) drawModelOption
- func WithModelScale(scale r3.Vector) drawModelOption
- func WithName(name string) colorOption
- func WithNurbs(nurbs Nurbs) drawShapeOption
- func WithNurbsColors(defaultColor Color, perPointColors ...Color) drawNurbsOption
- func WithNurbsDegree(degree int32) drawNurbsOption
- func WithNurbsWeights(weights []float64) drawNurbsOption
- func WithOrthographicCamera(orthographicCamera *drawv1.OrthographicCamera) sceneCameraOption
- func WithPerArrowColors(colors ...Color) drawArrowsOption
- func WithPerPointColors(colors ...Color) drawPointsOption
- func WithPerspectiveCamera(perspectiveCamera *drawv1.PerspectiveCamera) sceneCameraOption
- func WithPointSize(size float32) drawLineOption
- func WithPoints(points Points) drawShapeOption
- func WithPointsSize(size float32) drawPointsOption
- func WithRGB(r, g, b uint8) colorOption
- func WithRGBA(rgba color.RGBA) colorOption
- func WithRenderArmModels(renderArmModels drawv1.RenderArmModels) sceneMetadataOption
- func WithRenderShapes(renderShapes []drawv1.RenderShapes) sceneMetadataOption
- func WithSceneCamera(sceneCamera SceneCamera) sceneMetadataOption
- func WithSceneLinePointSize(linePointSize float32) sceneMetadataOption
- func WithSceneLineWidth(lineWidth float32) sceneMetadataOption
- func WithScenePointColor(pointColor Color) sceneMetadataOption
- func WithScenePointSize(pointSize float32) sceneMetadataOption
- func WithSingleArrowColor(color Color) drawArrowsOption
- func WithSinglePointColor(color Color) drawPointsOption
- type Arrows
- type BufferPackedEntry
- type BufferPacker
- type Color
- type ColorChooser
- type ConfigurableColors
- type DrawColorsConfig
- type Drawable
- type Drawing
- type Line
- type Metadata
- type Model
- type ModelAsset
- type Nurbs
- type Points
- type SceneCamera
- type SceneMetadata
- type Shape
- type Snapshot
- func (snapshot *Snapshot) DrawArrows(name string, parent string, pose spatialmath.Pose, poses []spatialmath.Pose, ...) error
- func (snapshot *Snapshot) DrawFrame(id string, name string, parent string, pose spatialmath.Pose, ...) error
- func (snapshot *Snapshot) DrawFrameSystemGeometries(frameSystem *referenceframe.FrameSystem, ...) error
- func (snapshot *Snapshot) DrawGeometry(geometry spatialmath.Geometry, pose spatialmath.Pose, parent string, ...) error
- func (snapshot *Snapshot) DrawLine(name string, parent string, pose spatialmath.Pose, points []r3.Vector, ...) error
- func (snapshot *Snapshot) DrawModel(name string, parent string, pose spatialmath.Pose, options ...drawModelOption) error
- func (snapshot *Snapshot) DrawPoints(name string, parent string, pose spatialmath.Pose, positions []r3.Vector, ...) error
- func (snapshot *Snapshot) Drawings() []*Drawing
- func (snapshot *Snapshot) MarshalBinary() ([]byte, error)
- func (snapshot *Snapshot) MarshalBinaryGzip() ([]byte, error)
- func (snapshot *Snapshot) MarshalJSON() ([]byte, error)
- func (snapshot *Snapshot) SceneMetadata() SceneMetadata
- func (snapshot *Snapshot) ToProto() *drawv1.Snapshot
- func (snapshot *Snapshot) Transforms() []*commonv1.Transform
- func (snapshot *Snapshot) UUID() []byte
- func (snapshot *Snapshot) Validate() error
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultArrowColor is the default color for arrows (green). DefaultArrowColor = NewColor(WithName("green")) // DefaultLineColor is the default color for lines (blue). DefaultLineColor = NewColor(WithName("blue")) // DefaultLinePointColor is the default color for points at line vertices (dark blue). DefaultLinePointColor = NewColor(WithName("darkblue")) // DefaultPointColor is the default color for point clouds (gray). DefaultPointColor = NewColor(WithName("gray")) )
Default colors for various drawing primitives, as specified in drawing.proto.
var ( // DefaultModelScale is the default model scale (1.0, 1.0, 1.0 - no scaling). DefaultModelScale = r3.Vector{X: 1.0, Y: 1.0, Z: 1.0} // DefaultModelAnimationName is the default animation name (empty string means no animation). DefaultModelAnimationName = "" )
var ( // DefaultNurbsDegree is the default polynomial degree for NURBS curves (cubic). DefaultNurbsDegree int32 = 3 // DefaultNurbsWeight is the default weight value for NURBS control points. DefaultNurbsWeight = 1.0 // DefaultNurbsColor is the default color for NURBS curves (cyan). DefaultNurbsColor = NewColor(WithName("cyan")) )
var ( // DefaultSceneCamera is the default camera configuration with a perspective view from position // [3000, 3000, 3000]mm looking at the origin. Provides an isometric-style view of the scene. DefaultSceneCamera = SceneCamera{ Position: r3.Vector{X: 3000, Y: 3000, Z: 3000}, LookAt: r3.Vector{X: 0, Y: 0, Z: 0}, Animated: false, PerspectiveCamera: &drawv1.PerspectiveCamera{}, } // DefaultGridEnabled specifies whether the grid is visible by default. DefaultGridEnabled = true // DefaultGridCellSize is the default grid cell size in millimeters (500mm = 0.5m). DefaultGridCellSize float32 = 500.0 // DefaultGridSectionSize is the default grid section size in millimeters (10000mm = 10m). DefaultGridSectionSize float32 = 10000.0 // DefaultGridFadeDistance is the default distance at which the grid fades out (25000mm = 25m). DefaultGridFadeDistance float32 = 25000.0 )
var DefaultAlpha = uint8(255)
DefaultAlpha is the default alpha value (fully opaque).
var ( // DefaultLineWidth is the default line width in millimeters. DefaultLineWidth float32 = 5.0 )
var ( // DefaultPointSize is the default point size in millimeters. DefaultPointSize float32 = 10.0 )
Functions ¶
func DrawFrameSystemGeometries ¶
func DrawFrameSystemGeometries( frameSystem *referenceframe.FrameSystem, inputs referenceframe.FrameSystemInputs, colors map[string]Color, ) (*drawv1.Transforms, error)
DrawFrameSystemGeometries renders all geometries in a frame system to the world frame. The colors map allows you to specify colors for specific frames by name; frames without specified colors inherit their parent's color or default to magenta. Returns the rendered transforms or an error if the frame system cannot be converted.
func DrawGeometries ¶
func DrawGeometries(geometriesInFrame *referenceframe.GeometriesInFrame, colors []Color) (*drawv1.Transforms, error)
DrawGeometries creates transforms for rendering multiple geometries, each with its own color. Returns an error if the number of colors doesn't match the number of geometries.
func DrawGeometry ¶
func DrawGeometry( id string, geometry spatialmath.Geometry, pose spatialmath.Pose, parent string, color Color, ) (*commonv1.Transform, error)
DrawGeometry creates a transform for rendering a single geometry with the specified id, pose, parent reference frame, and color. Returns an error if the metadata cannot be converted to a struct.
func MetadataToStruct ¶
MetadataToStruct converts drawing Metadata to a Protocol Buffer structpb.Struct suitable for embedding in transforms. Colors are base64-encoded for efficient transmission. Returns an error if the metadata cannot be converted.
func NewTransform ¶
func NewTransform( id string, name string, parent string, pose spatialmath.Pose, geometry spatialmath.Geometry, metadata *structpb.Struct, ) (*commonv1.Transform, error)
NewTransform creates a Protocol Buffer Transform message representing an object in 3D space. The id can be empty (auto-generated UUID) or a valid UUID string. The geometry and metadata parameters are optional (can be nil). Returns an error if the id is not a valid UUID.
func WithAnimated ¶
func WithAnimated(animated bool) sceneCameraOption
WithAnimated creates a camera option that enables or disables camera rotation animation.
func WithArrows ¶
func WithArrows(arrows Arrows) drawShapeOption
WithArrows creates a shape option that configures the shape as an Arrows geometry.
func WithColorPalette ¶ added in v1.3.3
func WithColors ¶
func WithColors[T ConfigurableColors](colors []Color) func(T)
WithColors creates a configuration option that sets colors for any type implementing ConfigurableColors.
func WithGrid ¶
func WithGrid(grid bool) sceneMetadataOption
WithGrid creates a metadata option that enables or disables the grid display.
func WithGridCellSize ¶
func WithGridCellSize(gridCellSize float32) sceneMetadataOption
WithGridCellSize creates a metadata option that sets the grid cell size in millimeters.
func WithGridFadeDistance ¶
func WithGridFadeDistance(gridFadeDistance float32) sceneMetadataOption
WithGridFadeDistance creates a metadata option that sets the distance at which the grid fades out in millimeters. Helps improve visibility at different scales.
func WithGridSectionSize ¶
func WithGridSectionSize(gridSectionSize float32) sceneMetadataOption
WithGridSectionSize creates a metadata option that sets the grid section size in millimeters. Sections are typically rendered with thicker or differently colored lines.
func WithHSV ¶
func WithHSV(h, s, v float32) colorOption
WithHSV creates a color option that sets the color from HSV values with full opacity (alpha=255). All parameters (h, s, v) should be in the range 0.0-1.0, where h is hue, s is saturation, and v is value/brightness.
func WithLine ¶
func WithLine(line Line) drawShapeOption
WithLine creates a shape option that configures the shape as a Line geometry.
func WithLineColors ¶
WithLineColors creates a line option that sets colors for the line segments and vertex points. If pointColor is nil, the line color is used for both.
func WithLineWidth ¶
func WithLineWidth(width float32) drawLineOption
WithLineWidth creates a line option that sets the line segment width in millimeters.
func WithMetadataColors ¶
func WithMetadataColors(colors ...Color) drawMetadataOption
WithMetadataColors creates a metadata option that sets the color list for the metadata.
func WithModel ¶
func WithModel(model Model) drawShapeOption
WithModel creates a shape option that configures the shape as a 3D Model geometry.
func WithModelAnimationName ¶
func WithModelAnimationName(animationName string) drawModelOption
WithModelAnimationName creates a model option that specifies which animation to play.
func WithModelAssetSizeBytes ¶
func WithModelAssetSizeBytes(sizeBytes uint64) drawModelAssetOption
WithModelAssetSizeBytes creates a model asset option that sets the file size in bytes.
func WithModelAssets ¶
func WithModelAssets(assets ...*ModelAsset) drawModelOption
WithModelAssets creates a model option that adds one or more assets to the model.
func WithModelScale ¶
WithModelScale creates a model option that sets the scaling factors for each axis.
func WithName ¶
func WithName(name string) colorOption
WithName creates a color option that sets the color using a standard web color name (e.g., "red", "blue", "magenta"). See https://www.w3.org/TR/SVG11/types.html#ColorKeywords for the complete list of supported color names.
func WithNurbs ¶
func WithNurbs(nurbs Nurbs) drawShapeOption
WithNurbs creates a shape option that configures the shape as a NURBS curve geometry.
func WithNurbsColors ¶
WithNurbsColors creates a NURBS option that sets the color for the curve. If only defaultColor is provided, it applies to the entire curve. Note: Per-point colors are not currently supported in rendering.
func WithNurbsDegree ¶
func WithNurbsDegree(degree int32) drawNurbsOption
WithNurbsDegree creates a NURBS option that sets the polynomial degree of the curve. Higher degrees create smoother curves but require more control points.
func WithNurbsWeights ¶
func WithNurbsWeights(weights []float64) drawNurbsOption
WithNurbsWeights creates a NURBS option that sets the weight for each control point. Weights control the influence of each point on the curve (higher weights pull the curve closer).
func WithOrthographicCamera ¶
func WithOrthographicCamera(orthographicCamera *drawv1.OrthographicCamera) sceneCameraOption
WithOrthographicCamera creates a camera option that configures orthographic projection.
func WithPerArrowColors ¶
func WithPerArrowColors(colors ...Color) drawArrowsOption
WithPerArrowColors sets the color for each arrow.
func WithPerPointColors ¶
func WithPerPointColors(colors ...Color) drawPointsOption
WithPerPointColors creates a points option that sets the colors for each point.
func WithPerspectiveCamera ¶
func WithPerspectiveCamera(perspectiveCamera *drawv1.PerspectiveCamera) sceneCameraOption
WithPerspectiveCamera creates a camera option that configures perspective projection.
func WithPointSize ¶
func WithPointSize(size float32) drawLineOption
WithPointSize creates a line option that sets the size of vertex points in millimeters.
func WithPoints ¶
func WithPoints(points Points) drawShapeOption
WithPoints creates a shape option that configures the shape as a Points geometry.
func WithPointsSize ¶
func WithPointsSize(size float32) drawPointsOption
WithPointsSize creates a points option that sets the size of each point in millimeters.
func WithRGB ¶
func WithRGB(r, g, b uint8) colorOption
WithRGB creates a color option that sets RGB values with full opacity (alpha=255).
func WithRGBA ¶
WithRGBA creates a color option that sets RGBA values from a standard library color.RGBA struct.
func WithRenderArmModels ¶
func WithRenderArmModels(renderArmModels drawv1.RenderArmModels) sceneMetadataOption
WithRenderArmModels creates a metadata option that controls how robot arm models are rendered. Options include showing models, colliders, or both.
func WithRenderShapes ¶
func WithRenderShapes(renderShapes []drawv1.RenderShapes) sceneMetadataOption
WithRenderShapes creates a metadata option that specifies which shape types to render. By default, all shape types (arrows, points, lines, models) are rendered.
func WithSceneCamera ¶
func WithSceneCamera(sceneCamera SceneCamera) sceneMetadataOption
WithSceneCamera creates a metadata option that sets the scene camera configuration.
func WithSceneLinePointSize ¶
func WithSceneLinePointSize(linePointSize float32) sceneMetadataOption
WithSceneLinePointSize creates a metadata option that sets the default size in millimeters for vertex points on lines (can be overridden per-object).
func WithSceneLineWidth ¶
func WithSceneLineWidth(lineWidth float32) sceneMetadataOption
WithSceneLineWidth creates a metadata option that sets the default line width in millimeters for all lines in the scene (can be overridden per-object).
func WithScenePointColor ¶
func WithScenePointColor(pointColor Color) sceneMetadataOption
WithScenePointColor creates a metadata option that sets the default point color for all points in the scene (can be overridden per-object).
func WithScenePointSize ¶
func WithScenePointSize(pointSize float32) sceneMetadataOption
WithScenePointSize creates a metadata option that sets the default point size in millimeters for all points in the scene (can be overridden per-object).
func WithSingleArrowColor ¶
func WithSingleArrowColor(color Color) drawArrowsOption
WithSingleArrowColor sets the color for all arrows.
func WithSinglePointColor ¶
func WithSinglePointColor(color Color) drawPointsOption
WithSinglePointColor creates a points option that sets the color for all points.
Types ¶
type Arrows ¶
type Arrows struct {
// Poses defines the position and orientation of each arrow to render.
Poses []spatialmath.Pose
// Colors specifies the color for each arrow. Can be a single color (applied to all arrows)
// or one color per pose.
Colors []Color
}
Arrows represents a set of directional arrows positioned at specific poses in 3D space. Each arrow visualizes orientation and position, useful for showing coordinate frames or directions.
func NewArrows ¶
func NewArrows(poses []spatialmath.Pose, options ...drawArrowsOption) (*Arrows, error)
NewArrows creates a new Arrows object from the given poses and optional configuration. Returns an error if the number of colors doesn't match the requirements (must be 1 or equal to number of poses).
type BufferPackedEntry ¶
type BufferPacker ¶
type BufferPacker[T BufferPackedEntry] struct { // contains filtered or unexported fields }
BufferPacker provides efficient direct buffer writing for numeric data. The type parameter T must be either float32 or uint8.
func NewBufferPacker ¶
func NewBufferPacker[T BufferPackedEntry](elementCount, fieldsPerElement int) *BufferPacker[T]
NewBufferPacker creates a new buffer packer with pre-allocated capacity for elementCount items, each with fieldsPerElement fields.
func (*BufferPacker[T]) Read ¶
func (packer *BufferPacker[T]) Read() []byte
Read returns the packed buffer as little-endian bytes. For uint8 buffers, returns the buffer directly. For float32 buffers, converts each value to its little-endian byte representation.
func (*BufferPacker[T]) Write ¶
func (packer *BufferPacker[T]) Write(values ...T)
Write appends values directly to the buffer at the current offset and advances the offset.
type Color ¶
type Color struct {
// R is the red channel value (0-255).
R uint8 `json:"r"`
// G is the green channel value (0-255).
G uint8 `json:"g"`
// B is the blue channel value (0-255).
B uint8 `json:"b"`
// A is the alpha (transparency) channel value (0-255, where 0 is fully transparent and 255 is fully opaque).
A uint8 `json:"a"`
}
Color represents an RGBA color with 8-bit channels (0-255 range).
func NewColor ¶
func NewColor(options ...colorOption) Color
NewColor creates a new Color with the given options. If no options are provided, returns black with full opacity (0, 0, 0, 255).
func (Color) SetAlpha ¶
SetAlpha returns a new Color with the specified alpha value, preserving the RGB values.
func (Color) SetRGB ¶
SetRGB returns a new Color with the specified RGB values, preserving the original alpha value.
type ColorChooser ¶
type ColorChooser struct {
// contains filtered or unexported fields
}
ColorChooser cycles through a list of colors, useful for automatically assigning different colors to multiple objects. Each call to Next() returns the next color in sequence, wrapping around to the start.
func NewDefaultColorChooser ¶
func NewDefaultColorChooser() ColorChooser
NewDefaultColorChooser creates a ColorChooser populated with all standard web color names.
func (ColorChooser) Next ¶
func (chooser ColorChooser) Next() Color
Next returns the next color in the sequence, cycling back to the first color after reaching the end.
type ConfigurableColors ¶
type ConfigurableColors interface {
// SetColors replaces the current colors with the provided list.
SetColors([]Color)
}
ConfigurableColors is an interface for types that can have their colors configured.
type DrawColorsConfig ¶
type DrawColorsConfig struct {
// contains filtered or unexported fields
}
DrawColorsConfig stores color configuration for drawable objects.
func NewDrawColorsConfig ¶
func NewDrawColorsConfig(colors ...Color) DrawColorsConfig
NewDrawColorsConfig creates a new color configuration with the given colors.
func (*DrawColorsConfig) SetColors ¶
func (config *DrawColorsConfig) SetColors(colors []Color)
SetColors replaces the current colors with the provided list.
type Drawable ¶
type Drawable interface {
// Draw creates a Drawing of this object with the given name, parent reference frame, and pose.
Draw(name string, parent string, pose spatialmath.Pose) *Drawing
}
Drawable is an interface for types that can create a Drawing representation of themselves.
type Drawing ¶
type Drawing struct {
Name string
Parent string
Pose spatialmath.Pose
Shape Shape
Metadata Metadata
}
Drawing represents a complete drawable object in 3D space, consisting of a Shape positioned at a Pose within a reference frame (Parent), along with associated Metadata like colors.
func NewDrawing ¶
func NewDrawing( name string, parent string, pose spatialmath.Pose, shape Shape, metadata Metadata, ) *Drawing
NewDrawing creates a new Drawing with the specified name, parent reference frame, pose, shape, and metadata.
type Line ¶
type Line struct {
// Positions defines the vertices of the line in sequence.
Positions []r3.Vector
// LineWidth specifies the thickness of the line segments in millimeters (default: 5mm).
LineWidth float32
// PointSize specifies the size of points rendered at each vertex in millimeters (default: 10mm).
PointSize float32
// LineColor is the color used for rendering the line segments (default: blue).
LineColor Color
// PointColor is the color used for rendering the vertex points (default: dark blue).
PointColor Color
}
Line represents a polyline (connected line segments) in 3D space, with optional visible points at each vertex. Useful for drawing paths, trajectories, or connected geometric shapes.
func NewLine ¶
NewLine creates a new Line from the given vertex positions and optional configuration. Returns an error if there are fewer than 2 positions or if the point size is non-positive.
type Metadata ¶
type Metadata struct {
Colors []Color
}
Metadata stores additional rendering information for a Drawing, such as colors for the shape's components.
func NewMetadata ¶
func NewMetadata(options ...drawMetadataOption) Metadata
NewMetadata creates a new Metadata with the given options. If no options are provided, returns empty metadata.
type Model ¶
type Model struct {
// Assets contains the model files and associated resources (textures, etc.).
Assets []*ModelAsset
// Scale specifies the scaling factors for each axis (default: [1.0, 1.0, 1.0]).
Scale r3.Vector
// AnimationName specifies which animation to play (empty string means no animation).
AnimationName string
}
Model represents a 3D model in various formats (GLB, GLTF, PLY, PCD, etc.). Models can have multiple assets (textures, meshes) and support animations and scaling.
func NewModel ¶
NewModel creates a new Model with the given options. Returns an error if no assets are provided or if the scale values are non-positive.
type ModelAsset ¶
ModelAsset represents a 3D model asset that can be loaded from either a URL or binary data. Common formats include GLB, GLTF, PLY, and PCD files.
func NewBinaryModelAsset ¶
func NewBinaryModelAsset(mimeType string, binaryContent []byte, options ...drawModelAssetOption) (*ModelAsset, error)
NewBinaryModelAsset creates a ModelAsset from binary data (e.g., an embedded file or loaded file). Common MIME types include "model/gltf-binary" for GLB files. Returns an error if the binary content is empty.
func NewURLModelAsset ¶
func NewURLModelAsset(mimeType string, url string, options ...drawModelAssetOption) (*ModelAsset, error)
NewURLModelAsset creates a ModelAsset that references a 3D model from a URL. Common MIME types include "model/gltf-binary" for GLB files. Returns an error if the URL is empty.
type Nurbs ¶
type Nurbs struct {
// ControlPoints defines the poses that influence the curve's shape.
ControlPoints []spatialmath.Pose
// Knots is the knot vector that determines parameter values along the curve.
// Length must equal len(ControlPoints) + Degree + 1.
Knots []float64
// Degree specifies the polynomial degree of the curve (default: 3 for cubic).
Degree int32
// Weights controls the influence of each control point on the curve.
// Defaults to 1.0 for each control point (uniform weighting).
Weights []float64
// Color specifies the rendering color for the curve.
Color Color
}
Nurbs represents a Non-Uniform Rational B-Spline (NURBS) curve in 3D space. NURBS curves are defined by control points, weights, a knot vector, and a polynomial degree. They are commonly used to represent smooth, curved paths and surfaces.
func NewNurbs ¶
func NewNurbs(controlPoints []spatialmath.Pose, knots []float64, options ...drawNurbsOption) (*Nurbs, error)
NewNurbs creates a new NURBS curve with the given control points, knot vector, and options. Returns an error if control points or knots are empty, if the degree is non-positive, if the weights don't match the number of control points, or if the knot vector length is incorrect (must be len(controlPoints) + degree + 1).
type Points ¶
type Points struct {
// Positions defines the location of each point.
Positions []r3.Vector
// PointSize specifies the size of each point in millimeters (default: 10mm).
PointSize float32
// Colors specifies the color for each point. Can be a single color (applied to all points)
// or one color per point.
Colors []Color
}
Points represents a point cloud or set of discrete points in 3D space. Useful for visualizing sensor data, waypoints, or sparse 3D data.
func NewPoints ¶
NewPoints creates a new Points object from the given positions and optional configuration. Returns an error if positions are empty, if the point size is non-positive, or if the number of colors doesn't match requirements (must be 1 or equal to number of positions).
type SceneCamera ¶
type SceneCamera struct {
// Position is the camera location in millimeters (world coordinates).
Position r3.Vector
// LookAt is the point the camera is aimed at in millimeters (world coordinates).
LookAt r3.Vector
// Animated enables camera rotation animation when true.
Animated bool
// PerspectiveCamera configures perspective projection (objects appear smaller with distance).
PerspectiveCamera *drawv1.PerspectiveCamera
// OrthographicCamera configures orthographic projection (parallel projection, no perspective).
OrthographicCamera *drawv1.OrthographicCamera
}
SceneCamera configures the viewpoint for rendering a 3D scene. Supports both perspective and orthographic projection modes. Exactly one of PerspectiveCamera or OrthographicCamera must be set.
func NewSceneCamera ¶
func NewSceneCamera(position r3.Vector, lookAt r3.Vector, options ...sceneCameraOption) SceneCamera
NewSceneCamera creates a new camera configuration with the specified position and look-at point (both in millimeters). By default, creates a perspective camera.
func (*SceneCamera) ToProto ¶
func (camera *SceneCamera) ToProto() *drawv1.SceneCamera
ToProto converts the SceneCamera to its Protocol Buffer representation for serialization.
type SceneMetadata ¶
type SceneMetadata struct {
SceneCamera SceneCamera
Grid bool
GridCellSize float32
GridSectionSize float32
GridFadeDistance float32
PointSize float32
PointColor Color
LineWidth float32
LinePointSize float32
RenderArmModels drawv1.RenderArmModels
RenderShapes []drawv1.RenderShapes
}
SceneMetadata contains global configuration for rendering a 3D scene, including camera settings, grid display options, default rendering styles, and visibility flags for different shape types.
func NewSceneMetadata ¶
func NewSceneMetadata(options ...sceneMetadataOption) SceneMetadata
NewSceneMetadata creates a new scene metadata configuration with sensible defaults (grid enabled, perspective camera, etc.) that can be customized with options.
func (*SceneMetadata) ToProto ¶
func (metadata *SceneMetadata) ToProto() *drawv1.SceneMetadata
ToProto converts the SceneMetadata to its Protocol Buffer representation for serialization.
func (*SceneMetadata) Validate ¶
func (metadata *SceneMetadata) Validate() error
Validate checks that all scene metadata values are valid. Returns an error if any values are out of acceptable ranges (e.g., negative sizes) or invalid enum values.
type Shape ¶
type Shape struct {
Center spatialmath.Pose
Label string
Arrows *Arrows
Line *Line
Points *Points
Model *Model
Nurbs *Nurbs
// contains filtered or unexported fields
}
Shape represents a drawable geometric shape or object in 3D space. A Shape contains exactly one geometry type (Arrows, Line, Points, Model, or Nurbs), positioned at Center with a Label.
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot represents a snapshot of a world state
func NewSnapshot ¶
func NewSnapshot(sceneOptions ...sceneMetadataOption) *Snapshot
NewSnapshot creates a new snapshot with a unique UUID
func (*Snapshot) DrawArrows ¶
func (snapshot *Snapshot) DrawArrows( name string, parent string, pose spatialmath.Pose, poses []spatialmath.Pose, options ...drawArrowsOption, ) error
DrawArrows draws arrows to the snapshot
- name is the name of the arrows
- parent is the parent of the arrows
- pose is the pose of the arrows
- poses are the poses of the arrows
- options are the options for the arrows
- Returns an error if the arrows cannot be drawn
func (*Snapshot) DrawFrame ¶
func (snapshot *Snapshot) DrawFrame( id string, name string, parent string, pose spatialmath.Pose, geometry spatialmath.Geometry, metadata *structpb.Struct, ) error
DrawFrame draws a frame transform to the snapshot
- id is the ID of the frame
- name is the name of the frame
- parent is the parent of the frame
- pose is the pose of the frame
- geometry is the geometry of the frame
- metadata is visualizer metadata for the frame
- Returns an error if the frame transform cannot be drawn
func (*Snapshot) DrawFrameSystemGeometries ¶
func (snapshot *Snapshot) DrawFrameSystemGeometries( frameSystem *referenceframe.FrameSystem, inputs referenceframe.FrameSystemInputs, colors map[string]Color, ) error
DrawFrameSystemGeometries draws the geometries of a frame system in the world frame to the snapshot
- frameSystem is the frame system to draw
- inputs are the inputs to the frame system
- colors are the colors to use for the frame system geometries, mapped by frame name
- Returns an error if the frame system geometries cannot be drawn
func (*Snapshot) DrawGeometry ¶
func (snapshot *Snapshot) DrawGeometry( geometry spatialmath.Geometry, pose spatialmath.Pose, parent string, color Color, ) error
DrawGeometry draws a geometry to the snapshot
- geometry is the geometry to draw
- pose is the pose of the geometry
- parent is the parent of the geometry
- color is the color of the geometry
- Returns an error if the geometry cannot be drawn
func (*Snapshot) DrawLine ¶
func (snapshot *Snapshot) DrawLine( name string, parent string, pose spatialmath.Pose, points []r3.Vector, options ...drawLineOption, ) error
DrawLine draws a line to the snapshot
- name is the name of the line
- parent is the parent of the line
- pose is the pose of the line
- points are the points of the line
- options are the options for the line
- Returns an error if the line cannot be drawn
func (*Snapshot) DrawModel ¶
func (snapshot *Snapshot) DrawModel( name string, parent string, pose spatialmath.Pose, options ...drawModelOption, ) error
DrawModelFromURL draws a model from a URL to the snapshot
- name is the name of the model
- parent is the parent of the model
- pose is the pose of the model
- options are the options for the model
- Returns an error if the model cannot be drawn
func (*Snapshot) DrawPoints ¶
func (snapshot *Snapshot) DrawPoints( name string, parent string, pose spatialmath.Pose, positions []r3.Vector, options ...drawPointsOption, ) error
DrawPoints draws a set of points to the snapshot
- name is the name of the points
- parent is the parent of the points
- pose is the pose of the points
- positions are the positions of the points
- options are the options for the points
- Returns an error if the points cannot be drawn
func (*Snapshot) MarshalBinary ¶
MarshalBinary marshals a snapshot to binary protobuf format
func (*Snapshot) MarshalBinaryGzip ¶
MarshalBinaryGzip marshals a snapshot to gzip-compressed binary protobuf format
func (*Snapshot) MarshalJSON ¶
MarshalJSON marshals a snapshot to JSON
func (*Snapshot) SceneMetadata ¶
func (snapshot *Snapshot) SceneMetadata() SceneMetadata
SceneMetadata returns the scene metadata of the snapshot
func (*Snapshot) Transforms ¶
Transforms returns the transforms of the snapshot