Documentation
¶
Overview ¶
Package gi3d provides a 3D scenegraph for the GoGi GUI framework.
The scenegraph is rooted at a gi3d.Scene node which is like gi.Viewport2D where the scene is rendered, similar to the svg.SVG node for SVG drawings.
Children of the Scene are either Group or Object -- Group applies a transform (position size, rotation etc) to everything under it, while Object has its own transform and a Material and Mesh which define the color / texture and shape of the object.
Solid shapes that are have uniform Material color properties on all surfaces can be a single Object, but if you need e.g., different textures for each side of a box then that must be represented as a Group of Objects using Plane Mesh's, each of which can then bind to a different Texture via their Material settings.
All Meshes are indexed triangles, and there are standard shapes such as Box, Sphere, Cylinder, Capsule, and Line (rendered as a thin Box with end points specified). Objects have computed bounding boxes and can be selected etc.
The Scene maintains a map of uniquely-named Mesh elements, and Objects refer to those by name. The same goes for Textures. This allows for efficient re-use of meshes and textures across multiple objects. The object basically instantiates a unique combination of these properties, and has a unique location / orientation in the scene.
The Scene also holds the Camera and Lights for rendering, and is fully in charge of the rendering process by iterating over the scene elements and culling out-of-view elements, ordering opaque then transparent elements, etc.
There are standard Render types that manage the relevant GPU programs / Pipelines to do the actual rendering, depending on Material and Mesh properties (e.g., uniform vs per-vertex color vs. texture).
Index ¶
- Variables
- func ColorToVec3f(clr gi.Color) mat32.Vec3
- func ColorToVec4f(clr gi.Color) mat32.Vec4
- func KiToNode3D(k ki.Ki) (Node3D, *Node3DBase)
- type AmbientLight
- type BBox
- type Box
- type Camera
- func (cm *Camera) DefaultPose()
- func (cm *Camera) Defaults()
- func (cm *Camera) GenGoSet(path string) string
- func (cm *Camera) LookAt(target, upDir mat32.Vec3)
- func (cm *Camera) LookAtOrigin()
- func (cm *Camera) LookAtTarget()
- func (cm *Camera) Orbit(delX, delY float32)
- func (cm *Camera) Pan(delX, delY float32)
- func (cm *Camera) PanAxis(delX, delY float32)
- func (cm *Camera) PanTarget(delX, delY, delZ float32)
- func (cm *Camera) UpdateMatrix()
- func (cm *Camera) Zoom(zoomPct float32)
- type DirLight
- type Group
- type Light
- type LightBase
- type LightColors
- type Material
- type Mesh
- type MeshBase
- func (ms *MeshBase) Activate(sc *Scene) bool
- func (ms *MeshBase) AddPlane(waxis, haxis mat32.Dims, wdir, hdir int, ...)
- func (ms *MeshBase) Alloc(vtxs, idxs int, color bool)
- func (ms *MeshBase) AsMeshBase() *MeshBase
- func (ms *MeshBase) ComputeNorms()
- func (ms *MeshBase) Delete(sc *Scene)
- func (ms *MeshBase) HasColor() bool
- func (ms *MeshBase) IsTransparent() bool
- func (ms *MeshBase) MakeVectors(sc *Scene) error
- func (ms *MeshBase) Name() string
- func (ms *MeshBase) PlaneSize(wsegs, hsegs int) (vtxSize, idxSize int)
- func (ms *MeshBase) Render3D(sc *Scene)
- func (ms *MeshBase) Reset()
- func (ms *MeshBase) SetColorData(sc *Scene)
- func (ms *MeshBase) SetNormData(sc *Scene)
- func (ms *MeshBase) SetPlane(stVtxIdx, stIdxIdx int, setNorm, setTex, setIdx bool, waxis, haxis mat32.Dims, ...)
- func (ms *MeshBase) SetVtxData(sc *Scene)
- func (ms *MeshBase) TransferAll()
- func (ms *MeshBase) TransferIndexes()
- func (ms *MeshBase) TransferVectors()
- func (ms *MeshBase) Update(sc *Scene)
- func (ms *MeshBase) Validate() error
- type MeshName
- type MeshValueView
- type Node3D
- type Node3DBase
- func (nb *Node3DBase) AsNode3D() *Node3DBase
- func (nb *Node3DBase) AsObject() *Object
- func (nb *Node3DBase) ConnectEvent(win *gi.Window, et oswin.EventType, pri gi.EventPris, fun ki.RecvFunc)
- func (nb *Node3DBase) ConnectEvents3D(sc *Scene)
- func (nb *Node3DBase) DisconnectAllEvents(win *gi.Window, pri gi.EventPris)
- func (nb *Node3DBase) DisconnectEvent(win *gi.Window, et oswin.EventType, pri gi.EventPris)
- func (nb *Node3DBase) Init3D(sc *Scene)
- func (nb *Node3DBase) IsObject() bool
- func (nb *Node3DBase) IsTransparent() bool
- func (nb *Node3DBase) IsVisible() bool
- func (nb *Node3DBase) RayPick(pos image.Point, sc *Scene) mat32.Ray
- func (nb *Node3DBase) Render3D(sc *Scene, rc RenderClasses, rnd Render)
- func (nb *Node3DBase) TrackCamera(sc *Scene)
- func (nb *Node3DBase) TrackLight(sc *Scene, lightName string) error
- func (nb *Node3DBase) UpdateBBox2D(size mat32.Vec2, sc *Scene)
- func (nb *Node3DBase) UpdateMVPMatrix(viewMat, prjnMat *mat32.Mat4)
- func (nb *Node3DBase) UpdateWorldMatrix(parWorld *mat32.Mat4)
- func (nb *Node3DBase) Validate(sc *Scene) error
- func (nb *Node3DBase) WorldMatrix() *mat32.Mat4
- func (nb *Node3DBase) WorldMatrixUpdated() bool
- type NodeFlags
- type Object
- func (obj *Object) AsObject() *Object
- func (obj *Object) Defaults()
- func (obj *Object) Init3D(sc *Scene)
- func (obj *Object) IsObject() bool
- func (obj *Object) IsTransparent() bool
- func (obj *Object) IsVisible() bool
- func (obj *Object) Render3D(sc *Scene, rc RenderClasses, rnd Render)
- func (obj *Object) RenderClass() RenderClasses
- func (obj *Object) SetMesh(sc *Scene, ms Mesh)
- func (obj *Object) SetMeshName(sc *Scene, meshName string) error
- func (obj *Object) UpdateMeshBBox()
- func (obj *Object) Validate(sc *Scene) error
- type Plane
- type PointLight
- type Pose
- func (ps *Pose) CopyFrom(op *Pose)
- func (ps *Pose) Defaults()
- func (ps *Pose) EulerRotation() mat32.Vec3
- func (ps *Pose) EulerRotationRad() mat32.Vec3
- func (ps *Pose) GenGoSet(path string) string
- func (ps *Pose) LookAt(target, upDir mat32.Vec3)
- func (ps *Pose) MoveOnAxis(x, y, z, dist float32)
- func (ps *Pose) MoveOnAxisAbs(x, y, z, dist float32)
- func (ps *Pose) RotateEuler(x, y, z float32)
- func (ps *Pose) RotateEulerRad(x, y, z, angle float32)
- func (ps *Pose) RotateOnAxis(x, y, z, angle float32)
- func (ps *Pose) RotateOnAxisRad(x, y, z, angle float32)
- func (ps *Pose) SetAxisRotation(x, y, z, angle float32)
- func (ps *Pose) SetAxisRotationRad(x, y, z, angle float32)
- func (ps *Pose) SetEulerRotation(x, y, z float32)
- func (ps *Pose) SetEulerRotationRad(x, y, z float32)
- func (ps *Pose) SetMatrix(m *mat32.Mat4)
- func (ps *Pose) UpdateMVPMatrix(viewMat, prjnMat *mat32.Mat4)
- func (ps *Pose) UpdateMatrix()
- func (ps *Pose) UpdateWorldMatrix(parWorld *mat32.Mat4)
- func (ps *Pose) WorldEulerRotation() mat32.Vec3
- func (ps *Pose) WorldPos() mat32.Vec3
- func (ps *Pose) WorldQuat() mat32.Quat
- func (ps *Pose) WorldScale() mat32.Vec3
- type Render
- type RenderBase
- type RenderClasses
- type RenderInputs
- type RenderTexture
- type RenderUniformColor
- type RenderVertexColor
- type Renderers
- func (rn *Renderers) AddNewRender(rb Render, errs *[]error)
- func (rn *Renderers) Delete()
- func (rn *Renderers) DrawState()
- func (rn *Renderers) Init(sc *Scene) (bool, error)
- func (rn *Renderers) InitRenders() error
- func (rn *Renderers) InitUnis() error
- func (rn *Renderers) InitVectors()
- func (rn *Renderers) SetLights(sc *Scene)
- func (rn *Renderers) SetLightsUnis(sc *Scene)
- func (rn *Renderers) SetMatrix(pose *Pose)
- type Scene
- func (sc *Scene) ActivateFrame() bool
- func (sc *Scene) ActivateOffFrame(frame *gpu.Framebuffer, name string, size image.Point, msamp int) bool
- func (sc *Scene) ActivateWin() bool
- func (sc *Scene) AddLight(lt Light)
- func (sc *Scene) AddMesh(ms Mesh)
- func (sc *Scene) AddTexture(tx Texture)
- func (sc *Scene) BBox2D() image.Rectangle
- func (sc *Scene) ChildrenBBox2D() image.Rectangle
- func (sc *Scene) ComputeBBox2D(parBBox image.Rectangle, delta image.Point)
- func (sc *Scene) Defaults()
- func (sc *Scene) DeleteResources()
- func (sc *Scene) DeleteUnusedMeshes()
- func (sc *Scene) DirectWinUpload() bool
- func (sc *Scene) Disconnect()
- func (sc *Scene) Init2D()
- func (sc *Scene) Init3D()
- func (sc *Scene) InitMeshes()
- func (sc *Scene) InitMeshesInCtxt() bool
- func (sc *Scene) InitTextures() bool
- func (sc *Scene) InitTexturesInCtxt() bool
- func (sc *Scene) IsDirectWinUpload() bool
- func (sc *Scene) IsVisible() bool
- func (sc *Scene) Layout2D(parBBox image.Rectangle, iter int) bool
- func (sc *Scene) MeshByName(nm string) Mesh
- func (sc *Scene) MeshByNameTry(nm string) (Mesh, error)
- func (sc *Scene) MeshList() []string
- func (sc *Scene) Move2D(delta image.Point, parBBox image.Rectangle)
- func (sc *Scene) NavEvents()
- func (sc *Scene) NavKeyEvents(kt *key.ChordEvent)
- func (sc *Scene) ObjsIntersectingPoint(pos image.Point) []Node3D
- func (sc *Scene) PopBounds()
- func (sc *Scene) PushBounds() bool
- func (sc *Scene) Render() bool
- func (sc *Scene) Render2D()
- func (sc *Scene) Render3D()
- func (sc *Scene) RenderOffFrame() bool
- func (sc *Scene) Resize(nwsz image.Point)
- func (sc *Scene) SaveCamera(name string)
- func (sc *Scene) SetCamera(name string) error
- func (sc *Scene) SetCurWin()
- func (sc *Scene) Size2D(iter int)
- func (sc *Scene) Style2D()
- func (sc *Scene) Text2DPlaneMesh() Mesh
- func (sc *Scene) TextureList() []string
- func (sc *Scene) TrackCamera() bool
- func (sc *Scene) UpdateMVPMatrix()
- func (sc *Scene) UpdateMeshBBox()
- func (sc *Scene) UpdateMeshes()
- func (sc *Scene) UpdateMeshesInCtxt() bool
- func (sc *Scene) UpdateWorldMatrix()
- func (sc *Scene) Validate() error
- type SceneView
- type SpotLight
- type TexName
- type Text2D
- func (txt *Text2D) Defaults(sc *Scene)
- func (txt *Text2D) Disconnect()
- func (txt *Text2D) Init3D(sc *Scene)
- func (txt *Text2D) IsTransparent() bool
- func (txt *Text2D) RenderClass() RenderClasses
- func (txt *Text2D) RenderText(sc *Scene)
- func (txt *Text2D) SetText(sc *Scene, str string)
- func (txt *Text2D) StyleText(sc *Scene)
- func (txt *Text2D) TextSize() (mat32.Vec2, bool)
- func (txt *Text2D) UpdateWorldMatrix(parWorld *mat32.Mat4)
- func (txt *Text2D) Validate(sc *Scene) error
- type Texture
- type TextureBase
- func (tx *TextureBase) Activate(sc *Scene, texNo int)
- func (tx *TextureBase) BotZero() bool
- func (tx *TextureBase) Delete(sc *Scene)
- func (tx *TextureBase) Init(sc *Scene) error
- func (tx *TextureBase) IsTransparent() bool
- func (tx *TextureBase) Name() string
- func (tx *TextureBase) NewTex() gpu.Texture2D
- func (tx *TextureBase) SetBotZero(botzero bool)
- func (tx *TextureBase) SetTransparent(trans bool)
- type TextureFile
- type TextureGi2D
- type Tiling
Constants ¶
This section is empty.
Variables ¶
var CameraProps = ki.Props{ "ToolBar": ki.PropSlice{ {"Defaults", ki.Props{ "label": "Defaults", "icon": "reset", }}, {"LookAt", ki.Props{ "icon": "rotate-3d", "Args": ki.PropSlice{ {"Target", ki.BlankProp{}}, {"UpDir", ki.BlankProp{}}, }, }}, {"Orbit", ki.Props{ "icon": "rotate-3d", "Args": ki.PropSlice{ {"DeltaX", ki.BlankProp{}}, {"DeltaY", ki.BlankProp{}}, }, }}, {"Pan", ki.Props{ "icon": "pan", "Args": ki.PropSlice{ {"DeltaX", ki.BlankProp{}}, {"DeltaY", ki.BlankProp{}}, }, }}, {"PanAxis", ki.Props{ "icon": "pan", "Args": ki.PropSlice{ {"DeltaX", ki.BlankProp{}}, {"DeltaY", ki.BlankProp{}}, }, }}, {"PanTarget", ki.Props{ "icon": "pan", "Args": ki.PropSlice{ {"DeltaX", ki.BlankProp{}}, {"DeltaY", ki.BlankProp{}}, {"DeltaZ", ki.BlankProp{}}, }, }}, {"Zoom", ki.Props{ "icon": "zoom-in", "Args": ki.PropSlice{ {"ZoomPct", ki.BlankProp{}}, }, }}, }, }
CameraProps define the ToolBar and MenuBar for StructView
var KiT_AmbientLight = kit.Types.AddType(&AmbientLight{}, nil)
var KiT_Box = kit.Types.AddType(&Box{}, nil)
var KiT_Camera = kit.Types.AddType(&Camera{}, CameraProps)
var KiT_DirLight = kit.Types.AddType(&DirLight{}, nil)
var KiT_Group = kit.Types.AddType(&Group{}, nil)
var KiT_LightBase = kit.Types.AddType(&LightBase{}, nil)
var KiT_LightColors = kit.Enums.AddEnum(LightColorsN, kit.NotBitFlag, nil)
var KiT_MeshBase = kit.Types.AddType(&MeshBase{}, nil)
var KiT_MeshValueView = kit.Types.AddType(&MeshValueView{}, nil)
var KiT_Node3DBase = kit.Types.AddType(&Node3DBase{}, Node3DBaseProps)
var KiT_NodeFlags = kit.Enums.AddEnumExt(gi.KiT_NodeFlags, NodeFlagsN, kit.BitFlag, nil)
var KiT_Object = kit.Types.AddType(&Object{}, nil)
var KiT_Plane = kit.Types.AddType(&Plane{}, nil)
var KiT_PointLight = kit.Types.AddType(&PointLight{}, nil)
var KiT_Pose = kit.Types.AddType(&Pose{}, PoseProps)
var KiT_Scene = kit.Types.AddType(&Scene{}, SceneProps)
var KiT_SceneView = kit.Types.AddType(&SceneView{}, nil)
var KiT_SpotLight = kit.Types.AddType(&SpotLight{}, nil)
var KiT_Text2D = kit.Types.AddType(&Text2D{}, nil)
var KiT_TextureBase = kit.Types.AddType(&TextureBase{}, nil)
var KiT_TextureFile = kit.Types.AddType(&TextureFile{}, nil)
var LightColorMap = map[LightColors]gi.Color{ DirectSun: {255, 255, 255, 255}, CarbonArc: {255, 250, 244, 255}, Halogen: {255, 241, 224, 255}, Tungsten100W: {255, 214, 170, 255}, Tungsten40W: {255, 197, 143, 255}, Candle: {255, 147, 41, 255}, Overcast: {201, 226, 255, 255}, FluorWarm: {255, 244, 229, 255}, FluorStd: {244, 255, 250, 255}, FluorCool: {212, 235, 255, 255}, FluorFull: {255, 244, 242, 255}, FluorGrow: {255, 239, 247, 255}, MercuryVapor: {216, 247, 255, 255}, SodiumVapor: {255, 209, 178, 255}, MetalHalide: {242, 252, 255, 255}, }
LightColorMap provides a map of named light colors
var Node3DBaseProps = ki.Props{ "base-type": true, "EnumType:Flag": KiT_NodeFlags, }
var PoseProps = ki.Props{ "ToolBar": ki.PropSlice{ {"SetEulerRotation", ki.Props{ "desc": "Set the local rotation (relative to parent) using Euler angles, in degrees.", "icon": "rotate-3d", "Args": ki.PropSlice{ {"Pitch", ki.Props{ "desc": "rotation up / down along the X axis (in the Y-Z plane), e.g., the altitude (climbing, descending) for motion along the Z depth axis", }}, {"Yaw", ki.Props{ "desc": "rotation along the Y axis (in the horizontal X-Z plane), e.g., the bearing or direction for motion along the Z depth axis", }}, {"Roll", ki.Props{ "desc": "rotation along the Z axis (in the X-Y plane), e.g., the bank angle for motion along the Z depth axis", }}, }, }}, {"SetAxisRotation", ki.Props{ "desc": "Set the local rotation (relative to parent) using Axis about which to rotate, and the angle.", "icon": "rotate-3d", "Args": ki.PropSlice{ {"X", ki.BlankProp{}}, {"Y", ki.BlankProp{}}, {"Z", ki.BlankProp{}}, {"Angle", ki.BlankProp{}}, }, }}, {"RotateEuler", ki.Props{ "desc": "rotate (relative to current rotation) using Euler angles, in degrees.", "icon": "rotate-3d", "Args": ki.PropSlice{ {"Pitch", ki.Props{ "desc": "rotation up / down along the X axis (in the Y-Z plane), e.g., the altitude (climbing, descending) for motion along the Z depth axis", }}, {"Yaw", ki.Props{ "desc": "rotation along the Y axis (in the horizontal X-Z plane), e.g., the bearing or direction for motion along the Z depth axis", }}, {"Roll", ki.Props{ "desc": "rotation along the Z axis (in the X-Y plane), e.g., the bank angle for motion along the Z depth axis", }}, }, }}, {"RotateOnAxis", ki.Props{ "desc": "Rotate (relative to current rotation) using Axis about which to rotate, and the angle.", "icon": "rotate-3d", "Args": ki.PropSlice{ {"X", ki.BlankProp{}}, {"Y", ki.BlankProp{}}, {"Z", ki.BlankProp{}}, {"Angle", ki.BlankProp{}}, }, }}, {"LookAt", ki.Props{ "icon": "rotate-3d", "Args": ki.PropSlice{ {"Target", ki.BlankProp{}}, {"UpDir", ki.BlankProp{}}, }, }}, {"EulerRotation", ki.Props{ "desc": "The local rotation (relative to parent) in Euler angles in degrees (X = Pitch, Y = Yaw, Z = Roll)", "icon": "rotate-3d", "show-return": "true", }}, {"sep-rot", ki.BlankProp{}}, {"MoveOnAxis", ki.Props{ "desc": "Move given distance on given X,Y,Z axis relative to current rotation orientation.", "icon": "pan", "Args": ki.PropSlice{ {"X", ki.BlankProp{}}, {"Y", ki.BlankProp{}}, {"Z", ki.BlankProp{}}, {"Dist", ki.BlankProp{}}, }, }}, {"MoveOnAxisAbs", ki.Props{ "desc": "Move given distance on given X,Y,Z axis in absolute coords, not relative to current rotation orientation.", "icon": "pan", "Args": ki.PropSlice{ {"X", ki.BlankProp{}}, {"Y", ki.BlankProp{}}, {"Z", ki.BlankProp{}}, {"Dist", ki.BlankProp{}}, }, }}, }, }
PoseProps define the ToolBar and MenuBar for StructView
var RenderPhong = `` /* 3756-byte string literal not displayed */
var RenderUniCamera = `
layout (std140) uniform Camera
{
mat4 MVMatrix;
mat4 MVPMatrix;
mat3 NormMatrix;
};
`
var RenderUniLights = `` /* 924-byte string literal not displayed */
var SceneProps = ki.Props{ "EnumType:Flag": gi.KiT_NodeFlags, "ToolBar": ki.PropSlice{ {"UpdateSig", ki.Props{ "label": "Update", "icon": "update", }}, }, }
SceneProps define the ToolBar and MenuBar for StructView
var Update3DTrace = false
Set Update3DTrace to true to get a trace of 3D updating
Functions ¶
func ColorToVec3f ¶
ColorToVec3f converts given gi.Color to mat32.Vec3 float32's
func ColorToVec4f ¶
ColorToVec4f converts given gi.Color to mat32.Vec4 float32's
func KiToNode3D ¶
func KiToNode3D(k ki.Ki) (Node3D, *Node3DBase)
KiToNode3D converts Ki to a Node3D interface and a Node3DBase obj -- nil if not.
Types ¶
type AmbientLight ¶
type AmbientLight struct {
LightBase
}
AmbientLight provides diffuse uniform lighting -- typically only one of these
func AddNewAmbientLight ¶
func AddNewAmbientLight(sc *Scene, name string, lumens float32, color LightColors) *AmbientLight
AddNewAmbientLight adds Ambient to given scene, with given name, standard color, and lumens (0-1 normalized)
type BBox ¶
type BBox struct {
BBox mat32.Box3 `desc:"bounding box in local coords"`
BSphere mat32.Sphere `desc:"bounding sphere in local coords"`
Area float32 `desc:"area"`
Volume float32 `desc:"volume"`
}
BBox contains bounding box and other gross object properties
type Box ¶
type Box struct {
MeshBase
Size mat32.Vec3 `desc:"size along each dimension"`
Segs mat32.Vec3i `` /* 137-byte string literal not displayed */
}
Box is a rectangular-shaped solid (cuboid)
type Camera ¶
type Camera struct {
Pose Pose `` /* 126-byte string literal not displayed */
Target mat32.Vec3 `` /* 165-byte string literal not displayed */
UpDir mat32.Vec3 `desc:"up direction for camera -- which way is up -- defaults to positive Y axis, and is reset by call to LookAt method"`
Ortho bool `` /* 206-byte string literal not displayed */
FOV float32 `desc:"field of view in degrees "`
Aspect float32 `desc:"aspect ratio (width/height)"`
Near float32 `desc:"near plane z coordinate"`
Far float32 `desc:"far plane z coordinate"`
ViewMatrix mat32.Mat4 `view:"-" desc:"view matrix (inverse of the Pose.Matrix)"`
PrjnMatrix mat32.Mat4 `view:"-" desc:"projection matrix, defining the camera perspective / ortho transform"`
InvPrjnMatrix mat32.Mat4 `view:"-" desc:"inverse of the projection matrix"`
}
Camera defines the properties of the camera
func (*Camera) DefaultPose ¶
func (cm *Camera) DefaultPose()
DefaultPose resets the camera pose to default location and orientation, looking at the origin from 0,0,10, with up Y axis
func (*Camera) GenGoSet ¶ added in v0.9.9
GenGoSet returns code to set values in object at given path (var.member etc)
func (*Camera) LookAt ¶
LookAt points the camera at given target location, using given up direction, and sets the Target, UpDir fields for future camera movements.
func (*Camera) LookAtOrigin ¶
func (cm *Camera) LookAtOrigin()
LookAtOrigin points the camera at origin with Y axis pointing Up (i.e., standard)
func (*Camera) LookAtTarget ¶
func (cm *Camera) LookAtTarget()
LookAtTarget points the camera at current target using current up direction
func (*Camera) Orbit ¶
Orbit moves the camera along the given 2D axes in degrees (delX = left/right, delY = up/down), relative to current position and orientation, keeping the same distance from the Target, and rotating the camera and the Up direction vector to keep looking at the target.
func (*Camera) Pan ¶
Pan moves the camera along the given 2D axes (left/right, up/down), relative to current position and orientation (i.e., in the plane of the current window view) and it moves the target by the same increment, changing the target position.
func (*Camera) PanTarget ¶
PanTarget moves the target along world X,Y,Z axes and does LookAt at the new target location. It ensures that the target is not identical to the camera position.
func (*Camera) UpdateMatrix ¶
func (cm *Camera) UpdateMatrix()
UpdateMatrix updates the view and prjn matricies
type DirLight ¶
type DirLight struct {
LightBase
Pos mat32.Vec3 `desc:"position of direct light -- assumed to point at the origin so this determines direction"`
}
DirLight is directional light, which is assumed to project light toward the origin based on its position, with no attenuation, like the Sun. For rendering, the position is negated and normalized to get the direction vector (i.e., absolute distance doesn't matter)
func AddNewDirLight ¶
func AddNewDirLight(sc *Scene, name string, lumens float32, color LightColors) *DirLight
AddNewDirLight adds direct light to given scene, with given name, standard color, and lumens (0-1 normalized) By default it is located overhead and toward the default camera (0, 1, 1) -- change Pos otherwise
type Group ¶
type Group struct {
Node3DBase
}
Group collects individual elements in a scene but does not have a Mesh or Material of its own. It does have a transform that applies to all nodes under it.
func AddNewGroup ¶
AddNewGroup adds a new group of given name to given parent
func (*Group) RenderClass ¶
func (gp *Group) RenderClass() RenderClasses
func (*Group) UpdateMeshBBox ¶ added in v0.9.9
func (gp *Group) UpdateMeshBBox()
UpdateMeshBBox updates the Mesh-based BBox info for all nodes. groups aggregate over elements
type Light ¶
type Light interface {
// Name returns name of the light -- lights are accessed by name
Name() string
// Color returns color of light
Color() gi.Color
// Lumens returns brightness of light
Lumens() float32
}
Light represents a light that illuminates a scene these are stored on the overall scene object and not within the graph
type LightBase ¶
type LightBase struct {
Nm string `desc:"name of light -- lights accessed by name so it matters"`
On bool `desc:"whether light is on or off"`
Lumns float32 `` /* 186-byte string literal not displayed */
Clr gi.Color `desc:"color of light a full intensity"`
}
LightBase provides the base implementation for Light interface
type LightColors ¶
type LightColors int
LightColors are standard light colors for different light sources
const ( DirectSun LightColors = iota CarbonArc Halogen Tungsten100W Tungsten40W Candle Overcast FluorWarm FluorStd FluorCool FluorFull FluorGrow MercuryVapor SodiumVapor MetalHalide LightColorsN )
func (*LightColors) FromString ¶
func (i *LightColors) FromString(s string) error
func (LightColors) String ¶
func (i LightColors) String() string
type Material ¶
type Material struct {
Color gi.Color `` /* 200-byte string literal not displayed */
Emissive gi.Color `desc:"color that surface emits independent of any lighting -- i.e., glow -- can be used for marking lights with an object"`
Specular gi.Color `desc:"shiny reflective color of surface -- set to white for shiny objects and to Color for non-shiny objects"`
Shiny float32 `` /* 338-byte string literal not displayed */
Bright float32 `` /* 183-byte string literal not displayed */
Texture TexName `desc:"texture to provide color for the surface"`
Tiling Tiling `view:"inline" viewif:"Texture!=''" desc:"texture tiling parameters -- repeat and offset"`
CullBack bool `desc:"cull the back-facing surfaces"`
CullFront bool `desc:"cull the front-facing surfaces"`
TexPtr Texture `view:"-" desc:"pointer to texture"`
}
Material describes the material properties of a surface (colors, shininess, texture) i.e., phong lighting parameters. Main color is used for both ambient and diffuse color, and alpha component is used for opacity. The Emissive color is only for glowing objects. The Specular color is always white (multiplied by light color). Textures are stored on the Scene and accessed by name
func (*Material) IsTransparent ¶
IsTransparent returns true if texture says it is, or if color has alpha < 255
func (*Material) NoTexture ¶
func (mt *Material) NoTexture()
NoTexture resets any texture setting that might have been set
func (*Material) SetTexture ¶
SetTexture sets material to use given texture
func (*Material) SetTextureName ¶
SetTextureName sets material to use given texture name (textures are accessed by name on Scene). If name is empty, then texture is reset
type Mesh ¶
type Mesh interface {
// Name returns name of the mesh
Name() string
// AsMeshBase returns the MeshBase for this Mesh
AsMeshBase() *MeshBase
// Reset resets all of the vector and index data for this mesh (to start fresh)
Reset()
// Make makes the shape mesh (defined for specific shape types)
// This does not call any other gpu setup functions and should
// be runnable outside of gpu context and on any thread -- just
// sets the various Vtx etc Arrays, and doesn't touch the gpu Buffer
Make(sc *Scene)
// Update updates any dynamically changing meshes (can be optimized to only update
// relevant vertex data instead of the indexes, norms, and texture coords)
// Unlike Make, this is only called with context active on main thread
// and is responsible for calling any relevant Set*Data and Transfer method(s) to update the GPU.
Update(sc *Scene)
// ComputeNorms automatically computes the normals from existing vertex data
ComputeNorms()
// Alloc allocates given number of vertex and index values, optionally including colors
// More efficient if number of such is known in advance
Alloc(vtxs, idxs int, color bool)
// AddPlane adds everything to render a plane with the given parameters.
// waxis, haxis = width, height axis, wdir, hdir are the directions for width and height dimensions.
// wsegs, hsegs = number of segments to create in each dimension -- more finely subdividing a plane
// allows for higher-quality lighting and texture rendering (minimum of 1 will be enforced).
// offset is the distance to place the plane along the orthogonal axis.
// if clr is non-Nil then it will be added
AddPlane(waxis, haxis mat32.Dims, wdir, hdir int, width, height, woff, hoff, zoff float32, wsegs, hsegs int, clr gi.Color)
// SetPlane sets plane vertex data (optionally norm, texUV, color, and indexes) at given starting
// *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), and starting Idx index.
// If doing a dynamic updating, compute the starting index using PlaneSize (and typically don't update Idx).
// waxis, haxis = width, height axis, wdir, hdir are the directions for width and height dimensions.
// wsegs, hsegs = number of segments to create in each dimension -- more finely subdividing a plane
// allows for higher-quality lighting and texture rendering (minimum of 1 will be enforced).
// offset is the distance to place the plane along the orthogonal axis.
// if clr is non-Nil then it will be added
SetPlane(stVtxIdx, stIdxIdx int, setNorm, setTex, setIdx bool, waxis, haxis mat32.Dims, wdir, hdir int, width, height, woff, hoff, zoff float32, wsegs, hsegs int, clr gi.Color)
// PlaneSize returns the size of a single plane's worth of vertex and index data
// with given number of segments.
// Note: In *vertex* units, not float units (i.e., x3 to get actual float offset in Vtx array).
// Use for computing the starting indexes in SetPlaneVtx.
// vtxSize = (wsegs + 1) * (hsegs + 1)
// idxSize = wsegs * hsegs * 6
PlaneSize(wsegs, hsegs int) (vtxSize, idxSize int)
// Validate checks if all the vertex data is valid
// any errors are logged
Validate() error
// HasColor returns true if this mesh has vertex-specific colors available
HasColor() bool
// IsTransparent returns true if this mesh has vertex-specific colors available
// and at least some are transparent.
IsTransparent() bool
// MakeVectors compiles the existing mesh data into the Vectors for GPU rendering
// Must be called with relevant context active.
MakeVectors(sc *Scene) error
// Activate activates the mesh Vectors on the GPU
// Must be called with relevant context active
// returns false if there is no mesh defined
Activate(sc *Scene) bool
// Activate deletes the mesh Vectors on the GPU
// Must be called with relevant context active, on main thread
Delete(sc *Scene)
// TransferAll transfer all buffer data to GPU (vectors and indexes)
// Activate must have just been called
TransferAll()
// TransferVectors transfer vectors buffer data to GPU (if vector data has changed)
// Activate must have just been called
TransferVectors()
// TransferIndexes transfer vectors buffer data to GPU (if index data has changed)
// Activate must have just been called
TransferIndexes()
// Render3D calls gpu.TrianglesIndexed to render the mesh.
// Must be called in context on main thread -- does activate, then draw triangles indexed
Render3D(sc *Scene)
// SetVtxData sets the (updated) Vtx data into the overall vector that
// will be transfered using the next TransferVectors call.
// It is essential that the length has not changed -- if length is changing
// then you must update everything and call MakeVectors.
// Use this for dynamically updating vertex data.
// has no constraints on where called.
SetVtxData(sc *Scene)
// SetNormData sets the (updated) Norm data into the overall vector that
// will be transfered using the next TransferVectors call.
// It is essential that the length has not changed -- if length is changing
// then you must update everything and call MakeVectors.
// Use this for dynamically updating vertex data.
// has no constraints on where called.
SetNormData(sc *Scene)
// SetColorData sets the (updated) Color data into the overall vector that
// will be transfered using the next TransferVectors call.
// It is essential that the length has not changed -- if length is changing
// then you must update everything and call MakeVectors.
// Use this for dynamically updating color data (only use if vertex color in use!)
// has no constraints on where called.
SetColorData(sc *Scene)
}
Mesh holds the mesh-based shape used for rendering an object. Only indexed triangle meshes are supported. All Mesh's must define Vtx, Norm, Tex (stored interleaved), and Idx components. Per-vertex Color is optional, and is appended to the vertex buffer non-interleaved if present.
type MeshBase ¶
type MeshBase struct {
Nm string `desc:"name of mesh -- meshes are linked to objects by name so this matters"`
Dynamic bool `desc:"if true, this mesh changes frequently -- otherwise considered to be static"`
Trans bool `desc:"set to true if color has transparency -- not worth checking manually"`
Vtx mat32.ArrayF32 `desc:"verticies for triangle shapes that make up the mesh -- all mesh structures must use indexed triangle meshes"`
Norm mat32.ArrayF32 `desc:"computed normals for each vertex"`
Tex mat32.ArrayF32 `desc:"texture U,V coordinates for mapping textures onto vertexes"`
Idx mat32.ArrayU32 `desc:"indexes that sequentially in groups of 3 define the actual triangle faces"`
Color mat32.ArrayF32 `` /* 190-byte string literal not displayed */
BBox BBox `desc:"computed bounding-box and other gross object properties"`
Buff gpu.BufferMgr `view:"-" desc:"buffer holding computed verticies, normals, indices, etc for rendering"`
}
MeshBase provides the core implementation of Mesh interface
func (*MeshBase) Activate ¶
Activate activates the mesh Vectors on the GPU Must be called with relevant context active on main thread
func (*MeshBase) AddPlane ¶
func (ms *MeshBase) AddPlane(waxis, haxis mat32.Dims, wdir, hdir int, width, height, woff, hoff, zoff float32, wsegs, hsegs int, clr gi.Color)
AddPlane adds everything to render a plane with the given parameters (convenience wrapper around SetPlane method). waxis, haxis = width, height axis, wdir, hdir are the directions for width and height dimensions. wsegs, hsegs = number of segments to create in each dimension -- more finely subdividing a plane allows for higher-quality lighting and texture rendering (minimum of 1 will be enforced). offset is the distance to place the plane along the orthogonal axis.
func (*MeshBase) Alloc ¶
Alloc allocates given number of vertex and index values, optionally including colors More efficient if number of such is known in advance
func (*MeshBase) AsMeshBase ¶
AsMeshBase returns the MeshBase for this Mesh
func (*MeshBase) ComputeNorms ¶
func (ms *MeshBase) ComputeNorms()
func (*MeshBase) Delete ¶
Delete deletes the mesh Vectors on the GPU Must be called with relevant context active on main thread
func (*MeshBase) IsTransparent ¶
func (*MeshBase) MakeVectors ¶
MakeVectors compiles the existing mesh data into the Vectors for GPU rendering Must be called with relevant context active on main thread
func (*MeshBase) PlaneSize ¶
PlaneSize returns the size of a single plane's worth of vertex and index data with given number of segments. Note: In *vertex* units, not float units (i.e., x3 to get actual float offset in Vtx array). Use for computing the starting indexes in SetPlaneVtx. vtxSize = (wsegs + 1) * (hsegs + 1) idxSize = wsegs * hsegs * 6
func (*MeshBase) Render3D ¶
Render3D calls gpu.TrianglesIndexed to render the mesh Activate must have just been called, assumed to be on main with context
func (*MeshBase) Reset ¶
func (ms *MeshBase) Reset()
Reset resets all of the vector and index data for this mesh (to start fresh)
func (*MeshBase) SetColorData ¶
SetColorData sets the (updated) Color data into the overall vector that will be transfered using the next TransferVectors call. It is essential that the length has not changed -- if length is changing then you must update everything and call MakeVectors. Use this for dynamically updating color data (only use if vertex color in use!) has no constraints on where called.
func (*MeshBase) SetNormData ¶
SetNormData sets the (updated) Norm data into the overall vector that will be transfered using the next TransferVectors call. It is essential that the length has not changed -- if length is changing then you must update everything and call MakeVectors. Use this for dynamically updating vertex data. has no constraints on where called.
func (*MeshBase) SetPlane ¶
func (ms *MeshBase) SetPlane(stVtxIdx, stIdxIdx int, setNorm, setTex, setIdx bool, waxis, haxis mat32.Dims, wdir, hdir int, width, height, woff, hoff, zoff float32, wsegs, hsegs int, clr gi.Color)
SetPlane sets plane vertex data (optionally norm, texUV, color, and indexes) at given starting *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), and starting Idx index. If doing a dynamic updating, compute the starting index using PlaneSize (and typically don't update Idx). waxis, haxis = width, height axis, wdir, hdir are the directions for width and height dimensions. wsegs, hsegs = number of segments to create in each dimension -- more finely subdividing a plane allows for higher-quality lighting and texture rendering (minimum of 1 will be enforced). offset is the distance to place the plane along the orthogonal axis. if clr is non-Nil then it will be added
func (*MeshBase) SetVtxData ¶
SetVtxData sets the (updated) Vtx data into the overall vector that will be transfered using the next TransferVectors call. It is essential that the length has not changed -- if length is changing then you must update everything and call MakeVectors. Use this for dynamically updating vertex data. has no constraints on where called.
func (*MeshBase) TransferAll ¶
func (ms *MeshBase) TransferAll()
TransferAll transfer all buffer data to GPU (vectors and indexes) Activate must have just been called, assumed to be on main with context
func (*MeshBase) TransferIndexes ¶
func (ms *MeshBase) TransferIndexes()
TransferIndexes transfer vectors buffer data to GPU (if index data has changed) Activate must have just been called, assumed to be on main with context
func (*MeshBase) TransferVectors ¶
func (ms *MeshBase) TransferVectors()
TransferVectors transfer vectors buffer data to GPU (if vector data has changed) Activate must have just been called, assumed to be on main with context
type MeshName ¶
type MeshName string
MeshName is a mesh name -- provides an automatic gui chooser for meshes Used on Object to link to meshes by name.
type MeshValueView ¶
type MeshValueView struct {
giv.ValueViewBase
}
MeshValueView presents an action for displaying a MeshName and selecting meshes from a ChooserDialog
func (*MeshValueView) Activate ¶
func (vv *MeshValueView) Activate(vp *gi.Viewport2D, dlgRecv ki.Ki, dlgFunc ki.RecvFunc)
func (*MeshValueView) ConfigWidget ¶
func (vv *MeshValueView) ConfigWidget(widg gi.Node2D)
func (*MeshValueView) HasAction ¶
func (vv *MeshValueView) HasAction() bool
func (*MeshValueView) UpdateWidget ¶
func (vv *MeshValueView) UpdateWidget()
func (*MeshValueView) WidgetType ¶
func (vv *MeshValueView) WidgetType() reflect.Type
type Node3D ¶
type Node3D interface {
gi.Node
// IsObject returns true if this is an Object node (else a Group)
IsObject() bool
// AsNode3D returns a generic Node3DBase for our node -- gives generic
// access to all the base-level data structures without requiring
// interface methods.
AsNode3D() *Node3DBase
// AsObject returns a node as Object (nil if not)
AsObject() *Object
// Validate checks that scene element is valid
Validate(sc *Scene) error
// UpdateWorldMatrix updates this node's local and world matrix based on parent's world matrix
// This sets the WorldMatrixUpdated flag but does not check that flag -- calling
// routine can optionally do so.
UpdateWorldMatrix(parWorld *mat32.Mat4)
// UpdateMVPMatrix updates this node's MVP matrix based on given view and prjn matrix from camera
// Called during rendering.
UpdateMVPMatrix(viewMat, prjnMat *mat32.Mat4)
// UpdateMeshBBox updates the Mesh-based BBox info for all nodes.
// groups aggregate over elements. called from FuncDownMeLast traversal
UpdateMeshBBox()
// UpdateBBox2D updates this node's 2D bounding-box information based on scene
// size and other scene bbox info from scene
UpdateBBox2D(size mat32.Vec2, sc *Scene)
// RayPick converts a given 2D point in scene image coordinates
// into a ray from the camera position pointing through line of sight of camera
// into *local* coordinates of the object.
// This can be used to find point of intersection in local coordinates relative
// to a given plane of interest, for example (see Ray methods for intersections)
RayPick(pos image.Point, sc *Scene) mat32.Ray
// WorldMatrix returns the world matrix for this node
WorldMatrix() *mat32.Mat4
// IsVisible provides the definitive answer as to whether a given node
// is currently visible. It is only entirely valid after a render pass
// for widgets in a visible window, but it checks the window and viewport
// for their visibility status as well, which is available always.
// Non-visible nodes are automatically not rendered and not connected to
// window events. The Invisible flag is one key element of the IsVisible
// calculus -- it is set by e.g., TabView for invisible tabs, and is also
// set if a widget is entirely out of render range. But again, use
// IsVisible as the main end-user method.
// For robustness, it recursively calls the parent -- this is typically
// a short path -- propagating the Invisible flag properly can be
// very challenging without mistakenly overwriting invisibility at various
// levels.
IsVisible() bool
// IsTransparent returns true if object has transparent color
IsTransparent() bool
// Init3D does 3D intialization
Init3D(sc *Scene)
// RenderClass returns the class of rendering for this object
// used for organizing the ordering of rendering
RenderClass() RenderClasses
// Render3D is called by Scene Render3D on main thread,
// everything ready to go..
Render3D(sc *Scene, rc RenderClasses, rnd Render)
// ConnectEvents3D: setup connections to window events -- called in
// Render3D if in bounds. It can be useful to create modular methods for
// different event types that can then be mix-and-matched in any more
// specialized types.
ConnectEvents3D(sc *Scene)
}
Node3D is the common interface for all gi3d scenegraph nodes
type Node3DBase ¶
type Node3DBase struct {
gi.NodeBase
Pose Pose `desc:"complete specification of position and orientation"`
MeshBBox BBox `desc:"mesh-based local bounding box (aggregated for groups)"`
WorldBBox BBox `desc:"world coordinates bounding box"`
NDCBBox mat32.Box3 `desc:"normalized display coordinates bounding box"`
}
Node3DBase is the basic 3D scenegraph node, which has the full transform information relative to parent, and computed bounding boxes, etc. There are only two different kinds of Nodes: Group and Object
func KiToNode3DBase ¶
func KiToNode3DBase(k ki.Ki) *Node3DBase
KiToNode3DBase converts Ki to a *Node3DBase -- use when known to be at least of this type, not-nil, etc
func (*Node3DBase) AsNode3D ¶
func (nb *Node3DBase) AsNode3D() *Node3DBase
AsNode3D returns a generic Node3DBase for our node -- gives generic access to all the base-level data structures without requiring interface methods.
func (*Node3DBase) AsObject ¶
func (nb *Node3DBase) AsObject() *Object
func (*Node3DBase) ConnectEvent ¶ added in v0.9.9
func (nb *Node3DBase) ConnectEvent(win *gi.Window, et oswin.EventType, pri gi.EventPris, fun ki.RecvFunc)
ConnectEvent connects this node to receive a given type of GUI event signal from the parent window -- typically connect only visible nodes, and disconnect when not visible
func (*Node3DBase) ConnectEvents3D ¶ added in v0.9.9
func (nb *Node3DBase) ConnectEvents3D(sc *Scene)
func (*Node3DBase) DisconnectAllEvents ¶ added in v0.9.9
func (nb *Node3DBase) DisconnectAllEvents(win *gi.Window, pri gi.EventPris)
DisconnectAllEvents disconnects node from all window events -- typically disconnect when not visible -- pri is priority -- pass AllPris for all priorities. This goes down the entire tree from this node on down, as typically everything under will not get an explicit disconnect call because no further updating will happen
func (*Node3DBase) DisconnectEvent ¶ added in v0.9.9
DisconnectEvent disconnects this receiver from receiving given event type -- pri is priority -- pass AllPris for all priorities -- see also DisconnectAllEvents
func (*Node3DBase) Init3D ¶
func (nb *Node3DBase) Init3D(sc *Scene)
func (*Node3DBase) IsObject ¶
func (nb *Node3DBase) IsObject() bool
func (*Node3DBase) IsTransparent ¶
func (nb *Node3DBase) IsTransparent() bool
func (*Node3DBase) IsVisible ¶
func (nb *Node3DBase) IsVisible() bool
func (*Node3DBase) RayPick ¶ added in v0.9.9
RayPick converts a given 2D point in scene image coordinates into a ray from the camera position pointing through line of sight of camera into *local* coordinates of the object. This can be used to find point of intersection in local coordinates relative to a given plane of interest, for example (see Ray methods for intersections). To convert mouse window-relative coords into scene-relative coords subtract the sc.ObjBBox.Min which includes any scrolling effects
func (*Node3DBase) Render3D ¶
func (nb *Node3DBase) Render3D(sc *Scene, rc RenderClasses, rnd Render)
func (*Node3DBase) TrackCamera ¶
func (nb *Node3DBase) TrackCamera(sc *Scene)
TrackCamera moves this node to pose of camera
func (*Node3DBase) TrackLight ¶
func (nb *Node3DBase) TrackLight(sc *Scene, lightName string) error
TrackLight moves node to position of light of given name. For SpotLight, copies entire Pose. Does not work for Ambient light which has no position information.
func (*Node3DBase) UpdateBBox2D ¶ added in v0.9.9
func (nb *Node3DBase) UpdateBBox2D(size mat32.Vec2, sc *Scene)
UpdateBBox2D updates this node's 2D bounding-box information based on scene size and min offset position.
func (*Node3DBase) UpdateMVPMatrix ¶
func (nb *Node3DBase) UpdateMVPMatrix(viewMat, prjnMat *mat32.Mat4)
UpdateMVPMatrix updates this node's MVP matrix based on given view, prjn matricies from camera. Called during rendering.
func (*Node3DBase) UpdateWorldMatrix ¶
func (nb *Node3DBase) UpdateWorldMatrix(parWorld *mat32.Mat4)
UpdateWorldMatrix updates this node's world matrix based on parent's world matrix. If a nil matrix is passed, then the previously-set parent world matrix is used. This sets the WorldMatrixUpdated flag but does not check that flag -- calling routine can optionally do so.
func (*Node3DBase) Validate ¶
func (nb *Node3DBase) Validate(sc *Scene) error
func (*Node3DBase) WorldMatrix ¶
func (nb *Node3DBase) WorldMatrix() *mat32.Mat4
WorldMatrix returns the world matrix for this node
func (*Node3DBase) WorldMatrixUpdated ¶
func (nb *Node3DBase) WorldMatrixUpdated() bool
type NodeFlags ¶ added in v0.9.9
type NodeFlags int
NodeFlags extend gi.NodeFlags to hold 3D node state
const ( // WorldMatrixUpdated means that the Pose.WorldMatrix has been updated WorldMatrixUpdated NodeFlags = NodeFlags(gi.NodeFlagsN) + iota // VectorsUpdated means that the rendering vectors information is updated VectorsUpdated NodeFlagsN )
func StringToNodeFlags ¶ added in v0.9.9
type Object ¶
type Object struct {
Node3DBase
Mesh MeshName `desc:"name of the mesh shape information used for rendering this object -- all meshes are collected on the Scene"`
Mat Material `desc:"material properties of the surface (color, shininess, texture, etc)"`
MeshPtr Mesh `view:"-" desc:"cached pointer to mesh"`
}
Object represents an individual 3D object or object element. It has its own unique spatial transforms and material properties, and points to a mesh structure.
func AddNewObject ¶
AddNewObject adds a new object of given name and mesh to given parent
func (*Object) Defaults ¶
func (obj *Object) Defaults()
Defaults sets default initial settings for object params -- important to call this before setting specific values, as the initial zero values for some parameters are degenerate
func (*Object) IsTransparent ¶
func (*Object) Render3D ¶
func (obj *Object) Render3D(sc *Scene, rc RenderClasses, rnd Render)
Render3D activates this object for rendering ()
func (*Object) RenderClass ¶
func (obj *Object) RenderClass() RenderClasses
RenderClass returns the class of rendering for this object used for organizing the ordering of rendering
func (*Object) SetMeshName ¶
SetMeshName sets mesh to given mesh name.
func (*Object) UpdateMeshBBox ¶ added in v0.9.9
func (obj *Object) UpdateMeshBBox()
UpdateMeshBBox updates the Mesh-based BBox info for all nodes. groups aggregate over elements
type Plane ¶
type Plane struct {
MeshBase
NormAxis mat32.Dims `` /* 235-byte string literal not displayed */
NormNeg bool `` /* 135-byte string literal not displayed */
Size mat32.Vec2 `desc:"2D size of plane"`
Segs mat32.Vec2i `` /* 132-byte string literal not displayed */
Offset float32 `desc:"offset from origin along direction of normal to the plane"`
}
Plane is a flat 2D plane, which can be oriented along any axis facing either positive or negative
func AddNewPlane ¶
AddNewPlane adds Plane mesh to given scene, with given name and size, with its normal pointing by default in the positive Y axis (i.e., a "ground" plane). Offset is 0.
type PointLight ¶
type PointLight struct {
LightBase
Pos mat32.Vec3 `desc:"position of light in world coordinates"`
LinDecay float32 `desc:"Distance linear decay factor -- defaults to .1"`
QuadDecay float32 `desc:"Distance quadratic decay factor -- defaults to .01 -- this is "`
}
PointLight is an omnidirectional light with a position and associated decay factors, which divide the light intensity as a function of linear and quadratic distance. The quadratic factor dominates at longer distances.
func AddNewPointLight ¶
func AddNewPointLight(sc *Scene, name string, lumens float32, color LightColors) *PointLight
AddNewPointLight adds point light to given scene, with given name, standard color, and lumens (0-1 normalized) By default it is located at 0,5,5 (up and between default camera and origin) -- set Pos to change.
type Pose ¶
type Pose struct {
Pos mat32.Vec3 `desc:"position of center of object"`
Scale mat32.Vec3 `desc:"scale (relative to parent)"`
Quat mat32.Quat `desc:"Node rotation specified as a Quat (relative to parent)"`
Matrix mat32.Mat4 `view:"-" desc:"Local matrix. Contains all position/rotation/scale information (relative to parent)"`
ParMatrix mat32.Mat4 `view:"-" desc:"Parent's world matrix -- we cache this so that we can independently update our own matrix"`
WorldMatrix mat32.Mat4 `` /* 143-byte string literal not displayed */
MVMatrix mat32.Mat4 `view:"-" desc:"model * view matrix -- tranforms into camera-centered coords"`
MVPMatrix mat32.Mat4 `view:"-" desc:"model * view * projection matrix -- full final render matrix"`
NormMatrix mat32.Mat3 `view:"-" desc:"normal matrix based on MVMatrix"`
}
Pose contains the full specification of a given object's position and orientation
func (*Pose) CopyFrom ¶
CopyFrom copies just the pose information from the other pose, critically not copying the ParMatrix so that is preserved in the receiver.
func (*Pose) Defaults ¶
func (ps *Pose) Defaults()
Defaults sets defaults only if current values are nil
func (*Pose) EulerRotation ¶
EulerRotation returns the current rotation in Euler angles (degrees).
func (*Pose) EulerRotationRad ¶
EulerRotationRad returns the current rotation in Euler angles (radians).
func (*Pose) GenGoSet ¶ added in v0.9.9
GenGoSet returns code to set values in object at given path (var.member etc)
func (*Pose) MoveOnAxis ¶
MoveOnAxis moves (translates) the specified distance on the specified local axis, relative to the current rotation orientation.
func (*Pose) MoveOnAxisAbs ¶
MoveOnAxisAbs moves (translates) the specified distance on the specified local axis, in absolute X,Y,Z coordinates.
func (*Pose) RotateEuler ¶
RotateEuler rotates by given Euler angles (in degrees) relative to existing rotation.
func (*Pose) RotateEulerRad ¶
RotateEulerRad rotates by given Euler angles (in radians) relative to existing rotation.
func (*Pose) RotateOnAxis ¶
RotateOnAxis rotates around the specified local axis the specified angle in degrees.
func (*Pose) RotateOnAxisRad ¶
RotateOnAxisRad rotates around the specified local axis the specified angle in radians.
func (*Pose) SetAxisRotation ¶
SetAxisRotation sets rotation from local axis and angle in degrees.
func (*Pose) SetAxisRotationRad ¶
SetAxisRotationRad sets rotation from local axis and angle in radians.
func (*Pose) SetEulerRotation ¶
SetEulerRotation sets the rotation in Euler angles (degrees).
func (*Pose) SetEulerRotationRad ¶
SetEulerRotationRad sets the rotation in Euler angles (radians).
func (*Pose) SetMatrix ¶
SetMatrix sets the local transformation matrix and updates Pos, Scale, Quat.
func (*Pose) UpdateMVPMatrix ¶
UpdateMVPMatrix updates the model * view, * projection matricies based on camera view, prjn matricies Assumes that WorldMatrix has been updated
func (*Pose) UpdateMatrix ¶
func (ps *Pose) UpdateMatrix()
UpdateMatrix updates the local transform matrix based on its position, quaternion, and scale. Also checks for degenerate nil values
func (*Pose) UpdateWorldMatrix ¶
UpdateWorldMatrix updates the world transform matrix based on Matrix and parent's WorldMatrix. Does NOT call UpdateMatrix so that can include other factors as needed.
func (*Pose) WorldEulerRotation ¶
WorldEulerRotation returns the current world rotation in Euler angles.
func (*Pose) WorldScale ¶
WorldScale returns he current world scale.
type Render ¶
type Render interface {
// Name returns the render name, which is the same as the Go type name
Name() string
// Pipeline returns the gpu.Pipeline for rendering
Pipeline() gpu.Pipeline
// VtxFragProg returns the gpu.Program for Vertex and Fragment shaders
// named "VtxFrag"
VtxFragProg() gpu.Program
// Init initializes the gpu.Pipeline programs and shaders.
Init(rn *Renderers) error
// Compile compiles the gpu.Pipeline programs and shaders.
Compile(rn *Renderers) error
// Activate activates this renderer for rendering
Activate(rn *Renderers)
// Delete deletes this renderer
Delete(rn *Renderers)
}
Render is the interface for a render program, with each managing a GPU Pipeline that implements the shaders to render a given material. Material's use a specific Render to achieve their rendering.
type RenderBase ¶
Base render type
func (*RenderBase) Activate ¶
func (rb *RenderBase) Activate(rn *Renderers)
func (*RenderBase) Compile ¶
func (rb *RenderBase) Compile(rn *Renderers) error
func (*RenderBase) Delete ¶
func (rb *RenderBase) Delete(rn *Renderers)
func (*RenderBase) Name ¶
func (rb *RenderBase) Name() string
func (*RenderBase) Pipeline ¶
func (rb *RenderBase) Pipeline() gpu.Pipeline
func (*RenderBase) VtxFragProg ¶
func (rb *RenderBase) VtxFragProg() gpu.Program
type RenderClasses ¶
type RenderClasses int32
RenderClasses define the different classes of rendering
const ( RClassNone RenderClasses = iota RClassOpaqueUniform RClassOpaqueVertex RClassOpaqueTexture RClassTransUniform RClassTransVertex RClassTransTexture RenderClassesN )
type RenderInputs ¶
type RenderInputs int32
RenderInputs define the locations of the Vectors inputs to the rendering programs All Vectors must use these locations so that Mesh data does not depend on which program is being used to render it.
const ( InVtxPos RenderInputs = iota InVtxNorm InVtxTex InVtxColor RenderInputsN )
type RenderTexture ¶
type RenderTexture struct {
RenderBase
}
RenderTexture renders a texture material.
func (*RenderTexture) Init ¶
func (rb *RenderTexture) Init(rn *Renderers) error
type RenderUniformColor ¶
type RenderUniformColor struct {
RenderBase
}
RenderUniformColor renders a material with one color for entire object. This uses the standard Phong color model, with color computed in the fragment shader (more accurate, more expensive).
func (*RenderUniformColor) Init ¶
func (rb *RenderUniformColor) Init(rn *Renderers) error
type RenderVertexColor ¶
type RenderVertexColor struct {
RenderBase
}
RenderVertexColor renders color parameters per vertex. This uses the standard Phong color model, with color computed in the fragment shader (more accurate, more expensive).
func (*RenderVertexColor) Init ¶
func (rb *RenderVertexColor) Init(rn *Renderers) error
type Renderers ¶
type Renderers struct {
Unis map[string]gpu.Uniforms `desc:"uniforms shared across code"`
Vectors []gpu.Vectors `desc:"input vectors shared across code, indexed by RenderInputs"`
Renders map[string]Render `desc:"collection of Render items"`
NLights int `` /* 133-byte string literal not displayed */
}
Renderers is the container for all GPU rendering Programs Each scene requires its own version of these because the programs need to be recompiled for each specific set of lights.
func (*Renderers) AddNewRender ¶
AddNewRender compiles the given Render and adds any errors to error list and adds it to the global Renders map, by Name()
func (*Renderers) Delete ¶
func (rn *Renderers) Delete()
Delete deletes GPU resources for renderers must be called in context on main
func (*Renderers) DrawState ¶
func (rn *Renderers) DrawState()
DrawState configures the draw state for rendering -- call when first starting rendering
func (*Renderers) Init ¶
Init initializes the Render programs. Must be called with appropriate context (window) activated. Returns true if wasn't already initialized, and error if there is some kind of error during initialization.
func (*Renderers) InitRenders ¶
func (*Renderers) InitVectors ¶
func (rn *Renderers) InitVectors()
func (*Renderers) SetLights ¶
SetLights sets the lights and recompiles the programs accordingly Must be called with proper context activated
func (*Renderers) SetLightsUnis ¶
SetLightsUnis sets the lights and recompiles the programs accordingly Must be called with proper context activated, on main thread
type Scene ¶
type Scene struct {
gi.WidgetBase
Geom gi.Geom2DInt `desc:"Viewport-level viewbox within any parent Viewport2D"`
Camera Camera `desc:"camera determines view onto scene"`
BgColor gi.Color `desc:"background color"`
Lights map[string]Light `desc:"all lights used in the scene"`
Meshes map[string]Mesh `desc:"all meshes used in the scene"`
Textures map[string]Texture `desc:"all textures used in the scene"`
SavedCams map[string]Camera `desc:"saved cameras -- can Save and Set these to view the scene from different angles"`
Win *gi.Window `copy:"-" json:"-" xml:"-" desc:"our parent window that we render into"`
Renders Renderers `view:"-" desc:"rendering programs"`
Frame gpu.Framebuffer `view:"-" desc:"direct render target for scene"`
Tex gpu.Texture2D `view:"-" desc:"the texture that the framebuffer returns, which should be rendered into the window"`
SetDragCursor bool `view:"-" desc:"has dragging cursor been set yet?"`
}
Scene is the overall scenegraph containing nodes as children. It renders to its own Framebuffer, the Texture of which is then drawn directly onto the window WinTex using the DirectWinUpload protocol.
There is default navigation event processing (disabled by setting NoNav) where mouse drag events Orbit the camera (Shift = Pan, Alt = PanTarget) and arrow keys do Orbit, Pan, PanTarget with same key modifiers. Spacebar restores original "default" camera, and numbers save (1st time) or restore (subsequently) camera views (Control = always save)
A Group at the top-level named "TrackCamera" will automatically track the camera (i.e., its Pose is copied) -- Objects in that group can set their relative Pos etc to display relative to the camera, to achieve "first person" effects.
func AddNewScene ¶
AddNewScene adds a new scene to given parent node, with given name.
func (*Scene) ActivateFrame ¶
ActivateFrame creates (if necc) and activates framebuffer for GPU rendering context returns false if not possible
func (*Scene) ActivateOffFrame ¶ added in v0.9.9
func (sc *Scene) ActivateOffFrame(frame *gpu.Framebuffer, name string, size image.Point, msamp int) bool
ActivateOffFrame creates (if necc) and activates given offscreen framebuffer for GPU rendering context, of given size, and multisampling number (4 = default for good antialiasing, 0 if not hardware accelerated). returns false if not possible
func (*Scene) ActivateWin ¶
ActivateWin activates the window context for GPU rendering context (on the main thread -- all GPU rendering actions must be performed on main thread) returns false if not possible (i.e., Win nil, not visible)
func (*Scene) AddLight ¶
AddLight adds given light to lights see AddNewX for convenience methods to add specific lights
func (*Scene) AddMesh ¶
AddMesh adds given mesh to mesh collection see AddNewX for convenience methods to add specific shapes
func (*Scene) AddTexture ¶
AddTexture adds given texture to texture collection see AddNewTextureFile to add a texture that loads from file
func (*Scene) ChildrenBBox2D ¶
func (*Scene) ComputeBBox2D ¶
func (*Scene) Defaults ¶
func (sc *Scene) Defaults()
Defaults sets default scene params (camera, bg = white)
func (*Scene) DeleteResources ¶
func (sc *Scene) DeleteResources()
DeleteResources deletes all GPU resources -- sets context and runs on main this is called during Disconnect and before the window is closed
func (*Scene) DeleteUnusedMeshes ¶
func (sc *Scene) DeleteUnusedMeshes()
DeleteUnusedMeshes deletes all unused meshes
func (*Scene) DirectWinUpload ¶
func (*Scene) Disconnect ¶
func (sc *Scene) Disconnect()
func (*Scene) InitMeshes ¶
func (sc *Scene) InitMeshes()
InitMeshes does a full init and gpu transfer of all the meshes This version us to be used by external users -- sets context and runs on main
func (*Scene) InitMeshesInCtxt ¶
InitMeshesInCtxt does a full init and gpu transfer of all the meshes This version must be called on main thread with context
func (*Scene) InitTextures ¶
InitTextures opens all the textures if not already opened, and establishes the GPU resources for them. This version can be called externally and activates the context and runs on main thread
func (*Scene) InitTexturesInCtxt ¶
InitTexturesInCtxt opens all the textures if not already opened, and establishes the GPU resources for them. Must be called with context on main thread.
func (*Scene) IsDirectWinUpload ¶
func (*Scene) MeshByName ¶ added in v0.9.9
MeshByName looks for mesh by name -- returns nil if not found
func (*Scene) MeshByNameTry ¶ added in v0.9.9
MeshByNameTry looks for mesh by name -- returns error if not found
func (*Scene) NavEvents ¶
func (sc *Scene) NavEvents()
NavEvents handles standard viewer navigation events
func (*Scene) NavKeyEvents ¶
func (sc *Scene) NavKeyEvents(kt *key.ChordEvent)
NavKeyEvents handles standard viewer keyboard navigation events
func (*Scene) ObjsIntersectingPoint ¶ added in v0.9.9
ObjsIntersectingPoint finds all the objects that contain given 2D window coordinate
func (*Scene) PushBounds ¶
we use our own render for these -- Viewport member is our parent!
func (*Scene) Render3D ¶
func (sc *Scene) Render3D()
Render3D renders the scene to the framebuffer all scene-level resources must be initialized and activated at this point
func (*Scene) RenderOffFrame ¶ added in v0.9.9
RenderOffFrame renders the scene to currently-activated offscreen framebuffer must call ActivateOffFrame first and call Frame.Rendered() after!
func (*Scene) SaveCamera ¶
SaveCamera saves the current camera with given name -- can be restored later with SetCamera. "default" is a special name that is automatically saved on first render, and restored with the spacebar under default NavEvents. Numbered cameras 0-9 also saved / restored with corresponding keys.
func (*Scene) SetCamera ¶
SetCamera sets the current camera to that of given name -- error if not found. "default" is a special name that is automatically saved on first render, and restored with the spacebar under default NavEvents. Numbered cameras 0-9 also saved / restored with corresponding keys.
func (*Scene) SetCurWin ¶
func (sc *Scene) SetCurWin()
set our window pointer to point to the current window we are under
func (*Scene) Text2DPlaneMesh ¶
Text2DPlaneMesh returns the special Text2DPLane mesh (creating it if it does not yet exist). This is a 1x1 plane with a normal pointing in positive Z direction used for all Text2D rendering
func (*Scene) TextureList ¶
TextureList returns a list of available textures (e.g., for chooser)
func (*Scene) TrackCamera ¶
TrackCamera -- a Group at the top-level named "TrackCamera" will automatically track the camera (i.e., its Pose is copied). Objects in that group can set their relative Pos etc to display relative to the camera, to achieve "first person" effects.
func (*Scene) UpdateMVPMatrix ¶ added in v0.9.9
func (sc *Scene) UpdateMVPMatrix()
UpdateMVPMatrix updates the Model-View-Projection matrix for all scene elements and BBox2D
func (*Scene) UpdateMeshBBox ¶ added in v0.9.9
func (sc *Scene) UpdateMeshBBox()
UpdateMeshBBox updates the Mesh-based BBox info for all nodes. groups aggregate over elements
func (*Scene) UpdateMeshes ¶
func (sc *Scene) UpdateMeshes()
UpdateMeshes calls Update on all meshes This version us to be used by external users -- sets context and runs on main
func (*Scene) UpdateMeshesInCtxt ¶
UpdateMeshesInCtxt calls Update on all the meshes in context on main thread Update is responsible for doing any transfers
func (*Scene) UpdateWorldMatrix ¶
func (sc *Scene) UpdateWorldMatrix()
UpdateWorldMatrix updates the world matrix for all scene elements called during Init3D and rendering
type SceneView ¶ added in v0.9.9
SceneView provides a toolbar controller for a gi3d.Scene
func AddNewSceneView ¶ added in v0.9.9
AddNewSceneView adds a new SceneView to given parent node, with given name.
func (*SceneView) Config ¶ added in v0.9.9
func (sv *SceneView) Config()
Config configures the overall view widget
func (*SceneView) IsConfiged ¶ added in v0.9.9
IsConfiged returns true if widget is fully configured
func (*SceneView) ToolbarConfig ¶ added in v0.9.9
func (sv *SceneView) ToolbarConfig()
type SpotLight ¶
type SpotLight struct {
LightBase
Pose Pose // position and orientation
AngDecay float32 `desc:"Angular decay factor -- defaults to 15"`
CutoffAngle float32 `max:"90" min:"1" desc:"Cut off angle (in degrees) -- defaults to 45 -- max of 90"`
LinDecay float32 `desc:"Distance linear decay factor -- defaults to 1"`
QuadDecay float32 `desc:"Distance quadratic decay factor -- defaults to 1"`
}
Spotlight is a light with a position and direction and associated decay factors and angles. which divide the light intensity as a function of linear and quadratic distance. The quadratic factor dominates at longer distances.
func AddNewSpotLight ¶
func AddNewSpotLight(sc *Scene, name string, lumens float32, color LightColors) *SpotLight
AddNewSpotLight adds spot light to given scene, with given name, standard color, and lumens (0-1 normalized) By default it is located at 0,5,5 (up and between default camera and origin) and pointing at the origin. Use the Pose LookAt function to point it at other locations. In its unrotated state, it points down the -Z axis (i.e., into the scene using default view parameters)
func (*SpotLight) LookAt ¶
LookAt points the spotlight at given target location, using given up direction.
func (*SpotLight) LookAtOrigin ¶
func (sl *SpotLight) LookAtOrigin()
LookAtOrigin points the spotlight at origin with Y axis pointing Up (i.e., standard)
type Text2D ¶
type Text2D struct {
Object
Text string `desc:"the text string to display"`
Sty gi.Style `json:"-" xml:"-" desc:"styling settings for the text"`
TxtPos gi.Vec2D `xml:"-" json:"-" desc:"position offset of start of text rendering relative to upper-left corner"`
TxtRender gi.TextRender `view:"-" xml:"-" json:"-" desc:"render data for text label"`
TxtTex *TextureBase `` /* 136-byte string literal not displayed */
RenderState gi.RenderState `copy:"-" json:"-" xml:"-" view:"-" desc:"render state for rendering text"`
}
Text2D presents 2D rendered text on a vertically-oriented plane, using a texture. Call SetText() which calls RenderText to update fortext changes (re-renders texture). The native scale is such that a unit height value is the height of the default font set by the font-size property, and the X axis is scaled proportionally based on the rendered text size to maintain the aspect ratio. Further scaling can be applied on top of that by setting the Pose.Scale values as usual. Standard styling properties can be set on the node to set font size, family, and text alignment relative to the Pose.Pos position (e.g., Left, Top puts the upper-left corner of text at Pos). Note that higher quality is achieved by using a larger font size (36 default). The margin property creates blank margin of the background color around the text (2 px default) and the background-color defaults to transparent but can be set to any color.
func AddNewText2D ¶
AddNewText2D adds a new object of given name and text string to given parent
func (*Text2D) Disconnect ¶
func (txt *Text2D) Disconnect()
func (*Text2D) IsTransparent ¶
func (*Text2D) RenderClass ¶
func (txt *Text2D) RenderClass() RenderClasses
func (*Text2D) RenderText ¶
func (*Text2D) TextSize ¶
TextSize returns the size of the text plane, applying all *local* scaling factors if nothing rendered yet, returns false
func (*Text2D) UpdateWorldMatrix ¶
type Texture ¶
type Texture interface {
// Name returns name of the texture
Name() string
// Init initializes the texture and uploads it to the GPU, so it is ready to use
// Must be called in context on main thread
Init(sc *Scene) error
// Activate activates this texture on the GPU, at given texture number.
// in preparation for rendering
// Must be called in context on main thread
Activate(sc *Scene, texNo int)
// Delete deletes the texture GPU resources -- must be called in context on main thread
Delete(sc *Scene)
// BotZero returns true if this texture has the Y=0 pixels at the bottom
// of the image. Otherwise, Y=0 is at the top, which is the default
// for most images loaded from files.
BotZero() bool
// SetBotZero sets whether this texture has the Y=0 pixels at the bottom
// of the image. Otherwise, Y=0 is at the top, which is the default
// for most images loaded from files.
SetBotZero(botzero bool)
// IsTransparent returns true if there is any transparency present in the texture
// This is not auto-detected but rather must be set manually.
// It affects the rendering order -- transparent items are rendered last.
IsTransparent() bool
// SetTransparent sets the transparency flag for this texture.
SetTransparent(trans bool)
}
type TextureBase ¶
type TextureBase struct {
Nm string `desc:"name of the texture -- textures are connected to material / objects by name"`
Bot0 bool `` /* 146-byte string literal not displayed */
Trans bool `desc:"set to true if texture has transparency"`
Tex gpu.Texture2D `view:"-" desc:"gpu texture object"`
}
TextureBase is the base texture implementation
func (*TextureBase) Activate ¶
func (tx *TextureBase) Activate(sc *Scene, texNo int)
Activate activates this texture on the GPU, in preparation for rendering Must be called in context on main thread
func (*TextureBase) BotZero ¶
func (tx *TextureBase) BotZero() bool
func (*TextureBase) Delete ¶
func (tx *TextureBase) Delete(sc *Scene)
Delete deletes the texture GPU resources -- must be called in context on main thread
func (*TextureBase) Init ¶
func (tx *TextureBase) Init(sc *Scene) error
Init initializes the texture and activates it -- for base case it must be set externally prior to this call. Must be called in context on main thread
func (*TextureBase) IsTransparent ¶
func (tx *TextureBase) IsTransparent() bool
func (*TextureBase) Name ¶
func (tx *TextureBase) Name() string
func (*TextureBase) NewTex ¶
func (tx *TextureBase) NewTex() gpu.Texture2D
makes a new gpu.Texture2D if Tex field is nil, and returns it in any case
func (*TextureBase) SetBotZero ¶
func (tx *TextureBase) SetBotZero(botzero bool)
func (*TextureBase) SetTransparent ¶
func (tx *TextureBase) SetTransparent(trans bool)
type TextureFile ¶
type TextureFile struct {
TextureBase
File gi.FileName `desc:"filename for the texture"`
}
TextureFile is a texture loaded from a file
func AddNewTextureFile ¶
func AddNewTextureFile(sc *Scene, name string, filename string) *TextureFile
AddNewTextureFile adds a new texture from file of given name and filename
func (*TextureFile) Activate ¶
func (tx *TextureFile) Activate(sc *Scene, texNo int)
Activate activates this texture on the GPU, in preparation for rendering Must be called in context on main thread
func (*TextureFile) Init ¶
func (tx *TextureFile) Init(sc *Scene) error
Init initializes the texture, opens the file, and uploads it to the GPU Must be called in context on main thread
type TextureGi2D ¶
type TextureGi2D struct {
TextureBase
Viewport *gi.Viewport2D
}
TextureGi2D is a dynamic texture material driven by a gi.Viewport2D viewport anything rendered to the viewport will be projected onto the surface of any object using this texture.