Documentation
¶
Overview ¶
Package scene3d supplies an opt-in 3D viewport for Golet native UI. The initial renderer is a pure-Go software rasterizer, not a native GPU engine. It supports indexed meshes, six-plane clipping, depth testing, opaque flat materials and directional lighting. No frontend is required.
Index ¶
Constants ¶
const MaxPixels = 4 * 1024 * 1024
MaxPixels bounds color/depth buffer allocation (32 MiB combined). A viewport can render at lower resolution than its display rectangle.
Variables ¶
This section is empty.
Functions ¶
func View ¶
func View(c *ui.Context, o ViewOptions) ui.Element
View creates a normal UI element containing a 3D image. It participates in layout, clipping, overlays and input with Forma in the same native window. Call only while building a ui.View, and mutate scenes on that UI thread. The renderer is CPU-based; the resulting image uses Golet's usual compositor.
Types ¶
type Camera ¶
Camera is a perspective camera. FOVY is vertical radians; Near must be positive and Far greater than Near. Defaults are explicit via DefaultCamera.
func DefaultCamera ¶
func DefaultCamera() Camera
type DirectionalLight ¶
DirectionalLight.Direction points FROM the surface TOWARD the light. Intensity is nonnegative. Lighting is flat Lambert plus Scene.Ambient.
type Mat4 ¶
type Mat4 [16]float32
Mat4 is a column-major matrix acting on column vectors. Use Identity for objects without a transform; Instance's zero matrix also means identity.
func Translation ¶
type Material ¶
Material is opaque flat shading. Alpha must be 255; blending is not yet supported. Unlit bypasses lighting; DoubleSided disables back-face culling.
type Mesh ¶
type Mesh struct {
// contains filtered or unexported fields
}
Mesh owns immutable geometry, shared by any number of instances. NewMesh copies its input. CCW triangles face outwards.
func LoadOBJ ¶
LoadOBJ loads triangulated Wavefront OBJ positions and faces. Positive and relative negative indices and v/vt/vn syntax are accepted. UVs, normals and materials are not imported: the initial renderer uses flat solid materials. Polygons must be triangulated by the exporter. No external files are opened.
func NewMesh ¶
NewMesh validates and copies indexed triangles. Degenerate triangles are legal and skipped during rendering. Vertices must be finite.
func (*Mesh) TriangleCount ¶
func (*Mesh) VertexCount ¶
type OBJLimits ¶
OBJLimits bounds untrusted input. Zero fields select defaults: 16 MiB, 250,000 vertices and 500,000 triangles. Lines are limited to 64 KiB.
type OrbitControls ¶
type OrbitControls struct {
// RotationSpeed is radians per DIP, default .006.
RotationSpeed float32
// ZoomSpeed is the exponential wheel factor per DIP, default .002.
ZoomSpeed float32
// Distance bounds default to max(.25, Near*2) and Far*.9 respectively.
MinDistance, MaxDistance float32
// contains filtered or unexported fields
}
OrbitControls provides event-driven, Y-up camera navigation. Keep one per viewport on its UI thread. Left drag orbits, Shift+left or middle drag pans, wheel and touchpad pinch dolly. It never schedules animation or allocates resources. Camera.Target is the orbit pivot and moves together with panning.
func (*OrbitControls) Cancel ¶
func (o *OrbitControls) Cancel()
Cancel releases drag state when removing a viewport or resetting its camera. Golet also delivers pointer-up when a captured window loses focus.
func (*OrbitControls) Handle ¶
func (o *OrbitControls) Handle(camera *Camera, ev ui.InputEvent, viewportHeight float32) bool
Handle consumes navigation events and updates camera. viewportHeight is the displayed height in DIPs, used to make panning independent of render scale. Forward events from ViewOptions.OnInput; Golet captures accepted drags and delivers moves/releases outside the viewport. Other inputs return false.
func (*OrbitControls) Rotate ¶
func (o *OrbitControls) Rotate(camera *Camera, yaw, pitch float32) bool
Rotate changes yaw and pitch in radians while retaining target and distance. Pitch stops just short of the poles, preventing camera flips. Returns false for an invalid camera or non-finite deltas. Navigation assumes world Y is up.
type Renderer ¶
Renderer allows alternative CPU/image-producing renderers without changing scene ownership or the viewport. Direct GPU texture sharing is not yet part of this interface and requires a future compositor integration.
type Request ¶
Request describes one immutable frame. Scene and its slices must not change until Render returns. Width and Height are render pixels, not window DIPs.
type Scene ¶
type Scene struct {
Instances []Instance
Lights []DirectionalLight
Ambient float32
Background color.RGBA
}
Scene is a caller-owned snapshot. Do not mutate while rendering. The caller controls animation, simulation and scheduling; there is no background loop.
type Software ¶
type Software struct{}
Software is a stateless, flat-shaded reference renderer. Different targets may be rendered concurrently. It uses no worker pool or global resources.
type Stats ¶
type Stats struct {
Instances, CulledInstances, Triangles, RasterizedTriangles, ShadedPixels int
BufferBytes int
}
Stats counts actual work; it does not measure GPU time or promise FPS.
type Target ¶
Target holds reusable CPU buffers. Use one per viewport/rendering goroutine. Image is borrowed until the next Render; copy it to retain a frame.
func (*Target) BufferBytes ¶
BufferBytes reports retained color, depth and transformed-vertex capacity, excluding immutable meshes, Go headers and the UI compositor's GPU texture.
type Vec3 ¶
type Vec3 struct{ X, Y, Z float32 }
Vec3 is a point or direction in a right-handed world; Y points up.
type ViewOptions ¶
type ViewOptions struct {
Scene *Scene
Camera Camera
Revision uint64
// Scale is render pixels per DIP (default 1, maximum 2). MaxDimension
// caps either side (default 1024, maximum 2048), preserving aspect ratio.
Scale float32
MaxDimension int
// NewRenderer is called once per mounted view. nil uses Software.
NewRenderer func() Renderer
OnInput func(ui.InputEvent) bool
// Animate updates scene transforms before each visible frame. nil leaves
// the viewport event-driven. Reduced-motion preferences suppress it.
// It runs on the UI thread; use the supplied clock, not wall-clock timers.
Animate func(time.Time)
// OnFrame runs after a render attempt on the UI thread. It must not
// reenter rendering. Errors are explicit; failed frames are not displayed.
// After an error, change Revision or another frame input to retry.
OnFrame func(Stats, error)
}
ViewOptions control rendering and integration with Forma or other native UI. Revision must change when Scene or mesh instance/material/light data changes. Camera and resolution changes are detected automatically. No timer is started. Use a stable UI Key when showing/reordering several viewports.