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 Node3D nodes, with Group and Solid as the main subtypes. Node3DBase is the base implementation, which has a Pose for the full matrix transform of relative position, scale, rotation, and bounding boxes at multiple levels.
* Group is a container -- most discrete objects should be organized into a Group, with Groups of Solids underneath. For maximum efficiency it is important to organize large scenegraphs into hierarchical groups by location, so that regions can be pruned for rendering. The Pose on the Group is inherited by everything under it, so things can be transformed at different levels as well.
* Solid has a Material to define the color / texture of the solid, and the name of a Mesh that defines the shape.
Objects that have uniform Material color properties on all surfaces can be a single Solid, but if you need e.g., different textures for each side of a box then that must be represented as a Group of Solids using Plane Mesh's, each of which can then bind to a different Texture via their Material settings.
Node bounding boxes are in both local and World reference frames, and are used for visibility and event selection.
All Meshes are stored directly on the Scene, and must have unique names, as they are referenced from Solids by name. The Mesh contains all the verticies, etc that define a shape, and are the major memory-consuming elements of the scene (along with textures). Thus, the Solid is very lightweight and just points to the Mesh, so Meshes can be reused across multiple Solids for efficiency.
Meshes are only indexed triangles, and there are standard shapes such as Box, Sphere, Cylinder, Capsule, and Line (rendered as a thin Box with end points specified).
Textures are also stored by unique names on the Scene, and the Material can optionally refer to a texture -- likewise allowing efficient re-use across different Solids.
The Scene also contains a Library of uniquely-named "objects" (Groups) which can be loaded from 3D object files, and then added into the scenegraph as needed. Thus, a typical, efficient workflow is to initialize a Library of such objects, and then configure the specific scene from these objects. The library objects are Cloned into the scenegraph -- because the Group and Solid nodes are lightweight, this is all very efficient.
The Scene also holds the Camera and Lights for rendering -- there is no point in putting these out in the scenegraph -- if you want to add a Solid representing one of these elements, you can easily do so.
The Scene 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).
Any change to the Mesh after first initialization (Init3D) must be activated by calling Scene.InitMesh(nm) or Scene.InitMeshes() to redo all. The Update method on the Scene does Init3D and re-renders.
Mouse events are handled by the standard GoGi Window event dispatching methods, based on bounding boxes which are always updated -- this greatly simplifies gui interactions. There is default support for selection and Pose manipulation handling -- see manip.go code and Node3DBase's ConnectEvents3D which responds to mouse clicks.
Index ¶
- Constants
- Variables
- func AddNewLineBoxMeshes(sc *Scene, meshNm string, bbox mat32.Box3, width float32)
- func ColorToVec3f(clr gist.Color) mat32.Vec3
- func ColorToVec4f(clr gist.Color) mat32.Vec4
- func InitMesh(ms Mesh, sc *Scene)
- func KiToNode3D(k ki.Ki) (Node3D, *Node3DBase)
- func MiterPts(ax, ay, bx, by, cx, cy, w2 float32) mat32.Vec2
- func SetLineStartEnd(ln *Solid, st, ed mat32.Vec3)
- 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) ViewMainAxis() (dim mat32.Dims, sign float32)
- func (cm *Camera) ViewVector() mat32.Vec3
- func (cm *Camera) Zoom(zoomPct float32)
- type Capsule
- type Cylinder
- func AddNewCone(sc *Scene, name string, height, radius float32, radialSegs, heightSegs int, ...) *Cylinder
- func AddNewCylinder(sc *Scene, name string, height, radius float32, radialSegs, heightSegs int, ...) *Cylinder
- func AddNewCylinderSector(sc *Scene, name string, height, topRad, botRad float32, ...) *Cylinder
- func UnitConeMesh(sc *Scene, segs int) *Cylinder
- type Decoder
- type DirLight
- type Embed2D
- func (em *Embed2D) ConnectEvents3D(sc *Scene)
- func (em *Embed2D) Defaults(sc *Scene)
- func (em *Embed2D) Disconnect()
- func (em *Embed2D) Init3D(sc *Scene)
- func (em *Embed2D) Project2D(sc *Scene, pt image.Point) (image.Point, bool)
- func (em *Embed2D) RenderClass() RenderClasses
- func (em *Embed2D) Resize(width, height int)
- func (em *Embed2D) ResizeToFit() error
- func (em *Embed2D) SetDPISize()
- func (em *Embed2D) UpdateBBox2D(size mat32.Vec2, sc *Scene)
- func (em *Embed2D) UpdateWorldMatrix(parWorld *mat32.Mat4)
- func (em *Embed2D) UploadViewTex(sc *Scene)
- func (em *Embed2D) Validate(sc *Scene) error
- type EmbedViewport
- func (vp *EmbedViewport) CurPopupIsTooltip() bool
- func (vp *EmbedViewport) DeleteTooltip()
- func (vp *EmbedViewport) EventTopNode() ki.Ki
- func (vp *EmbedViewport) EventTopUpdateEnd(updt bool)
- func (vp *EmbedViewport) EventTopUpdateStart() bool
- func (vp *EmbedViewport) FocusTopNode() ki.Ki
- func (vp *EmbedViewport) IsFocusActive() bool
- func (vp *EmbedViewport) IsInScope(node ki.Ki, popup bool) bool
- func (vp *EmbedViewport) SetFocusActiveState(active bool)
- func (vp *EmbedViewport) VpEventMgr() *gi.EventMgr
- func (vp *EmbedViewport) VpIsVisible() bool
- func (vp *EmbedViewport) VpTop() gi.Viewport
- func (vp *EmbedViewport) VpTopNode() gi.Node
- func (vp *EmbedViewport) VpTopUpdateEnd(updt bool)
- func (vp *EmbedViewport) VpTopUpdateStart() bool
- func (vp *EmbedViewport) VpUploadAll()
- func (vp *EmbedViewport) VpUploadRegion(vpBBox, winBBox image.Rectangle)
- func (vp *EmbedViewport) VpUploadVp()
- type GenMesh
- type Group
- type Light
- type LightBase
- type LightColors
- type Lines
- type ManipPt
- type Material
- func (mt *Material) ApplyCSS(node Node3D, css ki.Props, key, selector string, vp *gi.Viewport2D) bool
- func (mt *Material) Defaults()
- func (mt *Material) Disconnect()
- func (mt *Material) IsTransparent() bool
- func (mt *Material) NoTexture()
- func (mt *Material) SetMatProps(par *Material, props ki.Props, vp *gi.Viewport2D)
- func (mt *Material) SetTexture(sc *Scene, tex Texture)
- func (mt *Material) SetTextureName(sc *Scene, texName string) error
- func (mt *Material) StyleCSS(node Node3D, css ki.Props, selector string, vp *gi.Viewport2D)
- func (mt *Material) Validate(sc *Scene) error
- type Mesh
- type MeshBase
- func (ms *MeshBase) Activate(sc *Scene) bool
- func (ms *MeshBase) AddCylinderSector(height, topRad, botRad float32, radialSegs, heightSegs int, ...)
- func (ms *MeshBase) AddDiskSector(radius float32, segs int, angStart, angLen float32, offset mat32.Vec3)
- func (ms *MeshBase) AddLines(points []mat32.Vec3, width mat32.Vec2, closed bool, offset mat32.Vec3)
- func (ms *MeshBase) AddPlane(waxis, haxis mat32.Dims, wdir, hdir int, ...)
- func (ms *MeshBase) AddQuad(vtxs []mat32.Vec3, texs []mat32.Vec2, clr gist.Color)
- func (ms *MeshBase) AddSphereSector(radius float32, widthSegs, heightSegs int, ...)
- func (ms *MeshBase) AddTorusSector(radius, tubeRadius float32, radialSegs, tubeSegs int, angStart, angLen float32, ...)
- func (ms *MeshBase) AddTriangle(a, b, c mat32.Vec3, texs []mat32.Vec2, clr gist.Color)
- 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) HasTex() 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) SetName(nm string)
- func (ms *MeshBase) SetNormData(sc *Scene)
- func (ms *MeshBase) SetPlane(stVtxIdx, stIdxIdx int, setNorm, setTex, setIdx bool, waxis, haxis mat32.Dims, ...)
- func (ms *MeshBase) SetQuad(stVtxIdx, stIdxIdx int, setIdx bool, vtxs []mat32.Vec3, texs []mat32.Vec2, ...)
- func (ms *MeshBase) SetTriangle(stVtxIdx, stIdxIdx int, setIdx bool, a, b, c mat32.Vec3, texs []mat32.Vec2, ...)
- 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) AsSolid() *Solid
- func (nb *Node3DBase) BaseIface() reflect.Type
- 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) CopyFieldsFrom(frm interface{})
- 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) IsSolid() bool
- func (nb *Node3DBase) IsTransparent() bool
- func (nb *Node3DBase) IsVisible() bool
- func (nb *Node3DBase) NormDCBBox() mat32.Box3
- func (nb *Node3DBase) RayPick(pos image.Point, sc *Scene) mat32.Ray
- func (nb *Node3DBase) Render3D(sc *Scene, rc RenderClasses, rnd Render)
- func (nb *Node3DBase) SetPosePos(pos mat32.Vec3)
- func (nb *Node3DBase) SetPoseQuat(quat mat32.Quat)
- func (nb *Node3DBase) SetPoseScale(scale mat32.Vec3)
- func (nb *Node3DBase) Style3D(sc *Scene)
- 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) UpdateNode3D(sc *Scene)
- 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 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) MulMatrix(mat *mat32.Mat4)
- 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) error
- func (sc *Scene) ActivateWin() bool
- func (sc *Scene) AddFmLibrary(nm string, parent ki.Ki) (*Group, error)
- func (sc *Scene) AddLight(lt Light)
- func (sc *Scene) AddMesh(ms Mesh)
- func (sc *Scene) AddMeshUnique(ms Mesh)
- func (sc *Scene) AddTexture(tx Texture)
- func (sc *Scene) AddToLibrary(gp *Group)
- 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) DeleteMesh(nm string) error
- func (sc *Scene) DeleteMeshes()
- func (sc *Scene) DeleteResources()
- func (sc *Scene) DeleteTexture(nm string) error
- func (sc *Scene) DeleteTextures()
- func (sc *Scene) DeleteUnusedMeshes()
- func (sc *Scene) DirectWinUpload() bool
- func (sc *Scene) Disconnect()
- func (sc *Scene) Init2D()
- func (sc *Scene) Init3D()
- func (sc *Scene) InitMesh(nm string) error
- 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) IsRendering() bool
- func (sc *Scene) IsVisible() bool
- func (sc *Scene) Layout2D(parBBox image.Rectangle, iter int) bool
- func (sc *Scene) ManipBox()
- 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) NewInLibrary(nm string) *Group
- func (sc *Scene) OpenNewObj(fname string, parent ki.Ki) (*Group, error)
- func (sc *Scene) OpenObj(fname string, gp *Group) error
- func (sc *Scene) OpenScene(fname string) error
- func (sc *Scene) OpenToLibrary(fname string, libnm string) (*Group, error)
- func (sc *Scene) PlaneMesh2D() Mesh
- func (sc *Scene) PopBounds()
- func (sc *Scene) PushBounds() bool
- func (sc *Scene) ReadObj(fname string, rs []io.Reader, gp *Group) error
- func (sc *Scene) ReadScene(fname string, rs []io.Reader, gp *Group) error
- func (sc *Scene) Render() bool
- func (sc *Scene) Render2D()
- func (sc *Scene) Render3D(offscreen bool)
- func (sc *Scene) RenderOffFrame() bool
- func (sc *Scene) Resize(nwsz image.Point)
- func (sc *Scene) SaveCamera(name string)
- func (sc *Scene) SelectBox()
- func (sc *Scene) SetCamera(name string) error
- func (sc *Scene) SetCurWin()
- func (sc *Scene) SetManipPt(pt *ManipPt)
- func (sc *Scene) SetSel(nd Node3D)
- func (sc *Scene) Size2D(iter int)
- func (sc *Scene) SolidsIntersectingPoint(pos image.Point) []Node3D
- func (sc *Scene) Style2D()
- func (sc *Scene) Style3D()
- func (sc *Scene) TextureByName(nm string) Texture
- func (sc *Scene) TextureByNameTry(nm string) (Texture, error)
- func (sc *Scene) TextureList() []string
- func (sc *Scene) TrackCamera() bool
- func (sc *Scene) Update()
- func (sc *Scene) UpdateMVPMatrix()
- func (sc *Scene) UpdateMeshBBox()
- func (sc *Scene) UpdateMeshes()
- func (sc *Scene) UpdateMeshesInCtxt() bool
- func (sc *Scene) UpdateNodes3D()
- func (sc *Scene) UpdateWorldMatrix()
- func (sc *Scene) Validate() error
- type SceneFlags
- type SceneView
- type SelModes
- type SelParams
- type Solid
- func (sld *Solid) AsSolid() *Solid
- func (sld *Solid) CopyFieldsFrom(frm interface{})
- func (sld *Solid) Defaults()
- func (sld *Solid) Disconnect()
- func (sld *Solid) Init3D(sc *Scene)
- func (sld *Solid) IsSolid() bool
- func (sld *Solid) IsTransparent() bool
- func (sld *Solid) IsVisible() bool
- func (sld *Solid) ParentMaterial() *Material
- func (sld *Solid) Render3D(sc *Scene, rc RenderClasses, rnd Render)
- func (sld *Solid) RenderClass() RenderClasses
- func (sld *Solid) SetMesh(sc *Scene, ms Mesh)
- func (sld *Solid) SetMeshName(sc *Scene, meshName string) error
- func (sld *Solid) Style3D(sc *Scene)
- func (sld *Solid) UpdateMeshBBox()
- func (sld *Solid) Validate(sc *Scene) error
- type SolidPoint
- type Sphere
- 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
- type Torus
Constants ¶
const ( // FitContent is used as arg for NewEmbed2D to specify that plane should be resized // to fit content. FitContent = true // FixesSize is used as arg for NewEmbed2D to specify that plane should remain a // specified fixed size (using ) FixedSize = false )
const ( // CloseLines is used for the closed arg in AddNewLines: // connect first and last CloseLines = true // OpenLines is used for the closed arg in AddNewLines: // don't connect first and last OpenLines = false )
const ( // StartArrow specifies to add a starting arrow StartArrow = true // NoStartArrow specifies not to add a starting arrow NoStartArrow = false // EndArrow specifies to add a ending arrow EndArrow = true // EndArrow specifies not to add a ending arrow NoEndArrow = false )
const ( // Inactive is used for args indicating if node should be inactive Inactive = true // Active is used for args indicating if node should be inactive or not Active = false )
const ( // TrackCameraName is a reserved top-level Group name -- this group // will have its Pose updated to match that of the camera automatically. TrackCameraName = "TrackCamera" // SelBoxName is the reserved top-level Group name for holding // a bounding box or manipulator for currently selected object. // also used for meshes representing the box. SelBoxName = "__SelectedBox" // ManipBoxName is the reserved top-level name for meshes // representing the manipulation box. ManipBoxName = "__ManipBox" // Plane2DMeshName is the reserved name for the 2D plane mesh // used for Text2D and Embed2D Plane2DMeshName = "__Plane2D" // LineMeshName is the reserved name for a unit-sized Line segment LineMeshName = "__UnitLine" // ConeMeshName is the reserved name for a unit-sized Cone segment. // Has the number of segments appended. ConeMeshName = "__UnitCone" )
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 Decoders = map[string]Decoder{}
Decoders is the master list of decoders, indexed by the primary extension. .obj = Wavefront object file -- only has mesh data, not scene info.
var Embed2DProps = ki.Props{ "EnumType:Flag": gi.KiT_NodeFlags, }
var EmbedViewportProps = ki.Props{ "EnumType:Flag": gi.KiT_VpFlags, "color": &gi.Prefs.Colors.Font, "background-color": &gi.Prefs.Colors.Background, }
var GroupProps = ki.Props{ "EnumType:Flag": gi.KiT_NodeFlags, }
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_Capsule = kit.Types.AddType(&Capsule{}, nil)
var KiT_Cylinder = kit.Types.AddType(&Cylinder{}, nil)
var KiT_DirLight = kit.Types.AddType(&DirLight{}, nil)
var KiT_Embed2D = kit.Types.AddType(&Embed2D{}, Embed2DProps)
var KiT_EmbedViewport = kit.Types.AddType(&EmbedViewport{}, EmbedViewportProps)
var KiT_GenMesh = kit.Types.AddType(&GenMesh{}, nil)
var KiT_Group = kit.Types.AddType(&Group{}, GroupProps)
var KiT_LightBase = kit.Types.AddType(&LightBase{}, nil)
var KiT_LightColors = kit.Enums.AddEnum(LightColorsN, kit.NotBitFlag, nil)
var KiT_Lines = kit.Types.AddType(&Lines{}, nil)
var KiT_ManipPt = kit.Types.AddType(&ManipPt{}, ManipPtProps)
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_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_SceneFlags = kit.Enums.AddEnumExt(gi.KiT_NodeFlags, SceneFlagsN, kit.BitFlag, nil)
var KiT_SceneView = kit.Types.AddType(&SceneView{}, nil)
var KiT_SelModes = kit.Enums.AddEnum(SelModesN, kit.NotBitFlag, nil)
var KiT_Solid = kit.Types.AddType(&Solid{}, SolidProps)
var KiT_Sphere = kit.Types.AddType(&Sphere{}, nil)
var KiT_SpotLight = kit.Types.AddType(&SpotLight{}, nil)
var KiT_Text2D = kit.Types.AddType(&Text2D{}, Text2DProps)
var KiT_TextureBase = kit.Types.AddType(&TextureBase{}, nil)
var KiT_TextureFile = kit.Types.AddType(&TextureFile{}, nil)
var KiT_Torus = kit.Types.AddType(&Torus{}, nil)
var LightColorMap = map[LightColors]gist.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 ManipPtProps = ki.Props{ "EnumType:Flag": gi.KiT_NodeFlags, }
var Node3DBaseProps = ki.Props{ "base-type": true, "EnumType:Flag": KiT_NodeFlags, }
var PoseProps = ki.Props{ "ToolBar": ki.PropSlice{ {"GenGoSet", ki.Props{ "label": "Go Code", "desc": "returns Go Code that sets the current Pose, based on given path to Pose.", "icon": "edit", "show-return": true, "Args": ki.PropSlice{ {"Path", ki.BlankProp{}}, }, }}, {"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 = `` /* 3765-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": KiT_SceneFlags, "ToolBar": ki.PropSlice{ {"Update", ki.Props{ "icon": "update", }}, }, }
SceneProps define the ToolBar and MenuBar for StructView
var SolidProps = ki.Props{ "EnumType:Flag": gi.KiT_NodeFlags, }
var StyleMatFuncs = map[string]gist.StyleFunc{ "color": func(obj interface{}, key string, val interface{}, par interface{}, ctxt gist.Context) { mt := obj.(*Material) if inh, init := gist.StyleInhInit(val, par); inh || init { if inh { mt.Color = par.(*Material).Color } else if init { mt.Color.SetUInt8(128, 128, 128, 255) } return } mt.Color.SetIFace(val, ctxt, key) }, "emissive": func(obj interface{}, key string, val interface{}, par interface{}, ctxt gist.Context) { mt := obj.(*Material) if inh, init := gist.StyleInhInit(val, par); inh || init { if inh { mt.Emissive = par.(*Material).Emissive } else if init { mt.Emissive.SetUInt8(0, 0, 0, 0) } return } mt.Emissive.SetIFace(val, ctxt, key) }, "specular": func(obj interface{}, key string, val interface{}, par interface{}, ctxt gist.Context) { mt := obj.(*Material) if inh, init := gist.StyleInhInit(val, par); inh || init { if inh { mt.Specular = par.(*Material).Specular } else if init { mt.Specular.SetUInt8(255, 255, 255, 255) } return } mt.Specular.SetIFace(val, ctxt, key) }, "shiny": func(obj interface{}, key string, val interface{}, par interface{}, ctxt gist.Context) { mt := obj.(*Material) if inh, init := gist.StyleInhInit(val, par); inh || init { if inh { mt.Shiny = par.(*Material).Shiny } else if init { mt.Shiny = 30 } return } if iv, ok := kit.ToFloat32(val); ok { mt.Shiny = iv } }, "bright": func(obj interface{}, key string, val interface{}, par interface{}, ctxt gist.Context) { mt := obj.(*Material) if inh, init := gist.StyleInhInit(val, par); inh || init { if inh { mt.Bright = par.(*Material).Bright } else if init { mt.Bright = 1 } return } if iv, ok := kit.ToFloat32(val); ok { mt.Bright = iv } }, "texture": func(obj interface{}, key string, val interface{}, par interface{}, ctxt gist.Context) { mt := obj.(*Material) if inh, init := gist.StyleInhInit(val, par); inh || init { if inh { mt.Texture = par.(*Material).Texture } else if init { mt.Texture = "" } return } mt.Texture = TexName(kit.ToString(val)) }, "cull-back": func(obj interface{}, key string, val interface{}, par interface{}, ctxt gist.Context) { mt := obj.(*Material) if inh, init := gist.StyleInhInit(val, par); inh || init { if inh { mt.CullBack = par.(*Material).CullBack } else if init { mt.CullBack = true } return } if bv, ok := kit.ToBool(val); ok { mt.CullBack = bv } }, "cull-front": func(obj interface{}, key string, val interface{}, par interface{}, ctxt gist.Context) { mt := obj.(*Material) if inh, init := gist.StyleInhInit(val, par); inh || init { if inh { mt.CullFront = par.(*Material).CullFront } else if init { mt.CullFront = false } return } if bv, ok := kit.ToBool(val); ok { mt.CullFront = bv } }, }
StyleMatFuncs are functions for styling the Material
var Text2DProps = ki.Props{ "EnumType:Flag": gi.KiT_NodeFlags, }
var Update3DTrace = false
Set Update3DTrace to true to get a trace of 3D updating
Functions ¶
func AddNewLineBoxMeshes ¶ added in v0.9.11
AddNewLineBoxMeshes adds two Meshes defining the edges of a Box. Meshes are named meshNm+"-front" and meshNm+"-side" -- need to be initialized, e.g., using sc.InitMesh()
func ColorToVec3f ¶
ColorToVec3f converts given gist.Color to mat32.Vec3 float32's
func ColorToVec4f ¶
ColorToVec4f converts given gist.Color to mat32.Vec4 float32's
func InitMesh ¶ added in v0.9.11
InitMesh does the full initialization of the mesh: Make, MakeVectors, Activate, TransferAll. Must be called in context on main thread.
func KiToNode3D ¶
func KiToNode3D(k ki.Ki) (Node3D, *Node3DBase)
KiToNode3D converts Ki to a Node3D interface and a Node3DBase obj -- nil if not.
func SetLineStartEnd ¶ added in v1.0.0
SetLineStartEnd sets line Pose such that it starts / ends at given poitns.
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 solid properties
func (*BBox) UpdateFmBBox ¶ added in v0.9.11
func (bb *BBox) UpdateFmBBox()
UpdateFmBBox updates other values from BBox
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 */ CamMu sync.RWMutex `desc:"mutex protecting camera data"` 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"` Frustum *mat32.Frustum `view:"-" desc:"frustum of projection -- viewable space defined by 6 planes of a pyrammidal shape"` }
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 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
func (*Camera) ViewMainAxis ¶ added in v0.9.11
ViewMainAxis returns the dimension along which the view vector is largest along with the sign of that axis (+1 for positive, -1 for negative). this is useful for determining how manipulations should function, for example.
func (*Camera) ViewVector ¶ added in v0.9.11
ViewVector is the vector between the camera position and target
type Capsule ¶ added in v0.9.11
type Capsule struct { MeshBase Height float32 `desc:"height of the cylinder portion"` TopRad float32 `desc:"radius of the top -- set to 0 for a cone"` BotRad float32 `desc:"radius of the bottom"` RadialSegs int `min:"1" desc:"number of radial segments (32 is a reasonable default for full circle)"` HeightSegs int `desc:"number of height segments"` CapSegs int `desc:"number of segments in the hemisphere cap ends (16 is a reasonable default)"` AngStart float32 `min:"0" max:"360" step:"5" desc:"starting angle in degrees, relative to -1,0,0 left side starting point"` AngLen float32 `min:"0" max:"360" step:"5" desc:"total angle to generate in degrees (max 360)"` }
Capsule is a generalized capsule shape: a cylinder with hemisphere end caps. Supports different radii on each end. Height is along the Y axis -- total height is Height + TopRad + BotRad.
func AddNewCapsule ¶ added in v0.9.11
AddNewCapsule creates a generalized capsule mesh (cylinder + hemisphere caps) with the specified height and radius, number of radial, sphere segments, and number of height segments Height is along the Y axis.
type Cylinder ¶ added in v0.9.11
type Cylinder struct { MeshBase Height float32 `desc:"height of the cylinder"` TopRad float32 `desc:"radius of the top -- set to 0 for a cone"` BotRad float32 `desc:"radius of the bottom"` RadialSegs int `min:"1" desc:"number of radial segments (32 is a reasonable default for full circle)"` HeightSegs int `desc:"number of height segments"` Top bool `desc:"render the top disc"` Bottom bool `desc:"render the bottom disc"` AngStart float32 `min:"0" max:"360" step:"5" desc:"starting angle in degrees, relative to -1,0,0 left side starting point"` AngLen float32 `min:"0" max:"360" step:"5" desc:"total angle to generate in degrees (max 360)"` }
Cylinder is a generalized cylinder shape, including a cone or truncated cone by having different size circles at either end. Height is up along the Y axis.
func AddNewCone ¶ added in v0.9.11
func AddNewCone(sc *Scene, name string, height, radius float32, radialSegs, heightSegs int, bottom bool) *Cylinder
AddNewCone creates a cone mesh with the specified base radius, height, number of radial segments, number of height segments, and presence of a bottom cap. Height is along the Y axis.
func AddNewCylinder ¶ added in v0.9.11
func AddNewCylinder(sc *Scene, name string, height, radius float32, radialSegs, heightSegs int, top, bottom bool) *Cylinder
AddNewCylinder creates a cylinder mesh with the specified radius, height, number of radial segments, number of height segments, and presence of a top and/or bottom cap. Height is along the Y axis.
func AddNewCylinderSector ¶ added in v0.9.11
func AddNewCylinderSector(sc *Scene, name string, height, topRad, botRad float32, radialSegs, heightSegs int, angStart, angLen float32, top, bottom bool) *Cylinder
AddNewCylinderSector creates a generalized cylinder (truncated cone) sector mesh with the specified top and bottom radii, height, number of radial segments, number of height segments, sector start angle in degrees, sector size angle in degrees, and presence of a top and/or bottom cap. Height is along the Y axis.
func UnitConeMesh ¶ added in v0.9.11
UnitConeMesh returns the unit-sized cone mesh, of name ConeMeshName-segs
type Decoder ¶ added in v0.9.11
type Decoder interface { // New returns a new instance of the decoder used for a specific decoding New() Decoder // Desc returns the description of this decoder Desc() string // SetFile sets the file name being used for decoding -- needed in case // of loading other files such as textures / materials from the same directory. // Returns a list of files that should be loaded along with the main one, if needed. // For example, .obj decoder adds a corresponding .mtl file. SetFile(fname string) []string // Decode reads the given data and decodes it, returning a new instance // of the Decoder that contains all the decoded info. // Some formats (e.g., Wavefront .obj) have separate .obj and .mtl files // which are passed as two reader args. Decode(rs []io.Reader) error // SetGroup sets the group to contain the decoded objects within the // given scene. SetGroup(sc *Scene, gp *Group) // HasScene returns true if this decoder has full scene information -- // otherwise it only supports objects to be used in SetGroup. HasScene() bool // SetScene sets the scene according to the decoded data. SetScene(sc *Scene) }
Decoder parses 3D object / scene file(s) and imports into a Group or Scene. This interface is implemented by the different format-specific decoders.
func DecodeFile ¶ added in v0.9.11
DecodeFile decodes the given file using a decoder based on the file extension. Returns decoder instance with full decoded state. Supported formats include: .obj = Wavefront OBJ format, including associated materials (.mtl) which
must have same name as .obj, or a default material is used.
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 Embed2D ¶ added in v0.9.11
type Embed2D struct { Solid Viewport *EmbedViewport `desc:"the embedded viewport to display"` Zoom float32 `` /* 144-byte string literal not displayed */ Tex *TextureBase `view:"-" xml:"-" json:"-" desc:"texture object -- this is used directly instead of pointing to the Scene Texture resources"` FitContent bool `` /* 271-byte string literal not displayed */ StdSize image.Point `` /* 163-byte string literal not displayed */ DPISize image.Point `desc:"original size scaled according to logical dpi"` }
Embed2D embeds a 2D Viewport on a vertically-oriented plane, using a texture. The embedded viewport contains its own 2D scenegraph and receives events, with mouse coordinates translated into the 3D plane space. The full range of GoGi 2D elements can be embedded.
func AddNewEmbed2D ¶ added in v0.9.11
func AddNewEmbed2D(sc *Scene, parent ki.Ki, name string, width, height int, fitContent bool) *Embed2D
AddNewEmbed2D adds a new embedded 2D viewport of given name and nominal size according to the standard 96 dpi resolution (i.e., actual size is adjusted relative to that using window's current Logical DPI scaling). If fitContent is true and first and only element in Viewport is a gi.Layout, then it will be resized to fit content size (though no smaller than given size).
func (*Embed2D) ConnectEvents3D ¶ added in v0.9.11
func (*Embed2D) Disconnect ¶ added in v0.9.11
func (em *Embed2D) Disconnect()
func (*Embed2D) RenderClass ¶ added in v0.9.11
func (em *Embed2D) RenderClass() RenderClasses
func (*Embed2D) Resize ¶ added in v0.9.11
Resize resizes viewport and texture to given standardized 96 DPI size, which becomes the specified new size.
func (*Embed2D) ResizeToFit ¶ added in v0.9.11
ResizeToFit resizes viewport and texture to fit the content
func (*Embed2D) SetDPISize ¶ added in v0.9.11
func (em *Embed2D) SetDPISize()
SetDPISize sets the DPI-adjusted size using LogicalDPI from window. Window must be non-nil. Als
func (*Embed2D) UpdateBBox2D ¶ added in v0.9.11
func (*Embed2D) UpdateWorldMatrix ¶ added in v0.9.11
func (*Embed2D) UploadViewTex ¶ added in v0.9.11
UploadViewTex uploads the viewport image to the texture
type EmbedViewport ¶ added in v0.9.11
type EmbedViewport struct { gi.Viewport2D EventMgr gi.EventMgr `json:"-" xml:"-" desc:"event manager that handles dispersing events to nodes"` Scene *Scene `json:"-" xml:"-" desc:"parent scene -- trigger updates"` EmbedPar *Embed2D `json:"-" xml:"-" desc:"parent Embed2D -- render updates"` TopUpdated bool `json:"-" xml:"-" desc:"update flag for top-level updates"` }
EmbedViewport is an embedded viewport with its own event manager to handle events instead of using the Window.
func NewEmbedViewport ¶ added in v0.9.11
func NewEmbedViewport(sc *Scene, em *Embed2D, name string, width, height int) *EmbedViewport
NewEmbedViewport creates a new Pixels Image with the specified width and height, and initializes the renderer etc
func (*EmbedViewport) CurPopupIsTooltip ¶ added in v0.9.11
func (vp *EmbedViewport) CurPopupIsTooltip() bool
func (*EmbedViewport) DeleteTooltip ¶ added in v0.9.11
func (vp *EmbedViewport) DeleteTooltip()
DeleteTooltip deletes any tooltip popup (called when hover ends)
func (*EmbedViewport) EventTopNode ¶ added in v0.9.11
func (vp *EmbedViewport) EventTopNode() ki.Ki
func (*EmbedViewport) EventTopUpdateEnd ¶ added in v0.9.11
func (vp *EmbedViewport) EventTopUpdateEnd(updt bool)
func (*EmbedViewport) EventTopUpdateStart ¶ added in v0.9.11
func (vp *EmbedViewport) EventTopUpdateStart() bool
func (*EmbedViewport) FocusTopNode ¶ added in v0.9.11
func (vp *EmbedViewport) FocusTopNode() ki.Ki
func (*EmbedViewport) IsFocusActive ¶ added in v0.9.11
func (vp *EmbedViewport) IsFocusActive() bool
IsFocusActive returns true if focus is active in this master
func (*EmbedViewport) IsInScope ¶ added in v0.9.11
func (vp *EmbedViewport) IsInScope(node ki.Ki, popup bool) bool
IsInScope returns whether given node is in scope for receiving events
func (*EmbedViewport) SetFocusActiveState ¶ added in v0.9.11
func (vp *EmbedViewport) SetFocusActiveState(active bool)
SetFocusActiveState sets focus active state
func (*EmbedViewport) VpEventMgr ¶ added in v0.9.11
func (vp *EmbedViewport) VpEventMgr() *gi.EventMgr
func (*EmbedViewport) VpIsVisible ¶ added in v0.9.11
func (vp *EmbedViewport) VpIsVisible() bool
func (*EmbedViewport) VpTop ¶ added in v0.9.11
func (vp *EmbedViewport) VpTop() gi.Viewport
func (*EmbedViewport) VpTopNode ¶ added in v0.9.11
func (vp *EmbedViewport) VpTopNode() gi.Node
func (*EmbedViewport) VpTopUpdateEnd ¶ added in v0.9.11
func (vp *EmbedViewport) VpTopUpdateEnd(updt bool)
func (*EmbedViewport) VpTopUpdateStart ¶ added in v0.9.11
func (vp *EmbedViewport) VpTopUpdateStart() bool
func (*EmbedViewport) VpUploadAll ¶ added in v0.9.11
func (vp *EmbedViewport) VpUploadAll()
func (*EmbedViewport) VpUploadRegion ¶ added in v0.9.11
func (vp *EmbedViewport) VpUploadRegion(vpBBox, winBBox image.Rectangle)
VpUploadRegion uploads node region of our viewport image
func (*EmbedViewport) VpUploadVp ¶ added in v0.9.11
func (vp *EmbedViewport) VpUploadVp()
VpUploadVp uploads our viewport image into the parent window -- e.g., called by popups when updating separately
type GenMesh ¶ added in v0.9.11
type GenMesh struct {
MeshBase
}
GenMesh is a generic, arbitrary Mesh
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 AddNewArrow ¶ added in v0.9.11
func AddNewArrow(sc *Scene, parent ki.Ki, name string, st, ed mat32.Vec3, width float32, clr gist.Color, startArrow, endArrow bool, arrowSize, arrowWidth float32, arrowSegs int) *Group
AddNewArrow adds a group with a new line + cone between two specified points, using shared mesh unit line and arrow heads, which are rotated and positioned to go between the designated points. The arrowSize is a multiplier on the width for the radius and length of the arrow head, with width providing an additional multiplicative factor for width to achieve "fat" vs. "thin" arrows. arrowSegs determines how many faces there are on the arrowhead -- 4 = a 4-sided pyramid, etc.
func AddNewGroup ¶
AddNewGroup adds a new group of given name to given parent
func AddNewLineBox ¶ added in v0.9.11
func AddNewLineBox(sc *Scene, parent ki.Ki, meshNm, boxNm string, bbox mat32.Box3, width float32, clr gist.Color, inactive bool) *Group
AddNewLineBox adds a new Group with Solid's and two Meshes defining the edges of a Box. This can be used for drawing a selection box around a Node in the scene, for example. offset is an arbitrary offset (for composing shapes). Meshes are named meshNm+"-front" and meshNm+"-side" -- need to be initialized, e.g., using sc.InitMesh() inactive indicates whether the box and solids should be flagged as inactive (not selectable).
func (*Group) CopyFieldsFrom ¶ added in v0.9.11
func (gp *Group) CopyFieldsFrom(frm interface{})
func (*Group) RaySolidIntersections ¶ added in v1.0.0
func (gp *Group) RaySolidIntersections(ray mat32.Ray) []*SolidPoint
RaySolidIntersections returns a list of solids whose bounding box intersects with the given ray, with the point of intersection. Results are sorted from closest to furthest.
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() gist.Color // Lumens returns brightness of light Lumens() float32 }
Light represents a light that illuminates a scene these are stored on the overall scene 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 gist.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 Lines ¶ added in v0.9.11
type Lines struct { MeshBase Points []mat32.Vec3 `desc:"line points (must be 2 or more)"` Width mat32.Vec2 `desc:"line width, Y = height perpendicular to line direction, and X = depth"` Colors []gist.Color `desc:"optional colors for each point -- actual color interpolates between"` Closed bool `desc:"if true, connect the first and last points to form a closed shape"` }
Lines are lines rendered as long thin boxes defined by points and width parameters. The Mesh must be drawn in the XY plane (i.e., use Z = 0 or a constant unless specifically relevant to have full 3D variation). Rotate the solid to put into other planes.
func AddNewLines ¶ added in v0.9.11
AddNewLines adds Lines mesh to given scene, with given start, end, and width
func UnitLineMesh ¶ added in v0.9.11
UnitLineMesh returns the unit-sized line mesh, of name LineMeshName
type ManipPt ¶ added in v0.9.11
type ManipPt struct {
Solid
}
ManipPt is a manipulation control point
func AddNewManipPt ¶ added in v0.9.11
func AddNewManipPt(sc *Scene, parent ki.Ki, name string, meshName string, clr gist.Color, pos mat32.Vec3) *ManipPt
AddNewManipPt adds a new manipulation point
func (*ManipPt) ConnectEvents3D ¶ added in v0.9.11
Default ManipPt can be selected and manipulated
type Material ¶
type Material struct { Color gist.Color `` /* 226-byte string literal not displayed */ Emissive gist.Color `` /* 154-byte string literal not displayed */ Specular gist.Color `` /* 141-byte string literal not displayed */ Shiny float32 `` /* 364-byte string literal not displayed */ Bright float32 `` /* 211-byte string literal not displayed */ Texture TexName `xml:"texture" desc:"prop: texture = texture to provide color for the surface"` Tiling Tiling `view:"inline" viewif:"Texture!=''" desc:"texture tiling parameters -- repeat and offset"` CullBack bool `xml:"cull-back" desc:"prop: cull-back = cull the back-facing surfaces"` CullFront bool `xml:"cull-front" desc:"prop: cull-front = 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) ApplyCSS ¶ added in v0.9.11
func (mt *Material) ApplyCSS(node Node3D, css ki.Props, key, selector string, vp *gi.Viewport2D) bool
ApplyCSS applies css styles for given node, using key to select sub-props from overall properties list, and optional selector to select a further :name selector within that key
func (*Material) Disconnect ¶ added in v1.0.11
func (mt *Material) Disconnect()
Disconnect resets pointers etc
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) SetMatProps ¶ added in v0.9.11
SetMatProps sets Material values based on ki.Props properties
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 // SetName sets the name of the mesh SetName(nm 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 gist.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 gist.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 // HasTex returns true if this mesh has texture coordinates HasTex() bool // 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 // Delete 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 transferred 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 transferred 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 transferred 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 a Solid. Only indexed triangle meshes are supported. All Mesh's must define Vtx and Norm -- Tex is optional -- all are stored interleaved. The Idx component points into these elements as used in modern indexed VBO rendering. 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 Solids 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 solid properties"` Buff gpu.BufferMgr `view:"-" desc:"buffer holding computed verticies, normals, indices, etc for rendering"` BBoxMu sync.RWMutex `view:"-" copy:"-" json:"-" xml:"-" desc:"mutex on bbox access"` }
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) AddCylinderSector ¶ added in v0.9.11
func (ms *MeshBase) AddCylinderSector(height, topRad, botRad float32, radialSegs, heightSegs int, angStart, angLen float32, top, bottom bool, offset mat32.Vec3)
AddNewCylinderSector creates a generalized cylinder (truncated cone) sector mesh with the specified top and bottom radii, height, number of radial segments, number of height segments, sector start angle in degrees (start = -1,0,0) sector size angle in degrees, and presence of a top and/or bottom cap. Height is along the Y axis. offset is an arbitrary offset (for composing shapes).
func (*MeshBase) AddDiskSector ¶ added in v0.9.11
func (ms *MeshBase) AddDiskSector(radius float32, segs int, angStart, angLen float32, offset mat32.Vec3)
AddDiskSector creates a disk (filled circle) or disk sector mesh with the specified radius, number of radial segments (minimum 3), sector start angle and angle length in degrees. The center of the disk is at the origin, and angle runs counter-clockwise on the XY plane, starting at (x,y,z)=(1,0,0).
func (*MeshBase) AddLines ¶ added in v0.9.11
AddLines adds lines rendered as long thin boxes defined by points and width parameters. The Mesh must be drawn in the XY plane (i.e., use Z = 0 or a constant unless specifically relevant to have full 3D variation). Rotate the solid to put into other planes. offset is an arbitrary offset (for composing shapes).
func (*MeshBase) AddPlane ¶
func (ms *MeshBase) AddPlane(waxis, haxis mat32.Dims, wdir, hdir int, width, height, woff, hoff, zoff float32, wsegs, hsegs int, clr gist.Color)
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
func (*MeshBase) AddQuad ¶ added in v0.9.11
AddQuad adds quad vertex data (optionally texUV, color) to mesh. Must have 4 vtxs, 4 texs if !nil. Norm is auto-computed, and bbox expanded by points.
func (*MeshBase) AddSphereSector ¶ added in v0.9.11
func (ms *MeshBase) AddSphereSector(radius float32, widthSegs, heightSegs int, angStart, angLen, elevStart, elevLen float32, offset mat32.Vec3)
AddSphereSector creates a sphere sector mesh with the specified radius, number of radial segments in each dimension, radial sector start angle and length in degrees (0 - 360), start = -1,0,0, elevation start angle and length in degrees (0 - 180), top = 0, bot = 180, offset is an arbitrary offset (for composing shapes).
func (*MeshBase) AddTorusSector ¶ added in v0.9.11
func (ms *MeshBase) AddTorusSector(radius, tubeRadius float32, radialSegs, tubeSegs int, angStart, angLen float32, offset mat32.Vec3)
NewTorus creates a torus geometry with the specified revolution radius, tube radius, number of radial segments, number of tubular segments, radial sector start angle and length in degrees (0 - 360)
func (*MeshBase) AddTriangle ¶ added in v0.9.11
AddTriangle adds one triangle of vertex data (optionally texUV, color) to mesh. norm is auto-computed, and bounds expanded. Must have 3 texs if not nil.
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 transferred 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 transferred 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 gist.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) SetQuad ¶ added in v0.9.11
func (ms *MeshBase) SetQuad(stVtxIdx, stIdxIdx int, setIdx bool, vtxs []mat32.Vec3, texs []mat32.Vec2, clr gist.Color)
SetQuad sets quad vertex data (optionally 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. Norm is auto-computed, and bbox expanded by points.
func (*MeshBase) SetTriangle ¶ added in v0.9.11
func (ms *MeshBase) SetTriangle(stVtxIdx, stIdxIdx int, setIdx bool, a, b, c mat32.Vec3, texs []mat32.Vec2, clr gist.Color)
SetTriangle sets one triangle of vertex data (optionally 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. Norm is auto-computed, and bounds expanded.
func (*MeshBase) SetVtxData ¶
SetVtxData sets the (updated) Vtx data into the overall vector that will be transferred 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 Solid 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 // IsSolid returns true if this is an Solid node (else a Group) IsSolid() 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 // AsSolid returns a node as Solid (nil if not) AsSolid() *Solid // 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 solid. // 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, under read-lock protection. WorldMatrix() *mat32.Mat4 // NormDCBBox returns the normalized display coordinates bounding box // which is used for clipping. This is read-lock protected. NormDCBBox() mat32.Box3 // 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 solid has transparent color IsTransparent() bool // Init3D does 3D intialization Init3D(sc *Scene) // Style3D does 3D styling using property values on nodes Style3D(sc *Scene) // UpdateNode3D does arbitrary node updating during render process UpdateNode3D(sc *Scene) // RenderClass returns the class of rendering for this solid. // 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) // SetPosePos sets Pose.Pos position to given value, under write lock protection SetPosePos(pos mat32.Vec3) // SetPoseScale sets Pose.Scale scale to given value, under write lock protection SetPoseScale(scale mat32.Vec3) // SetPoseQuat sets Pose.Quat to given value, under write lock protection SetPoseQuat(quat mat32.Quat) }
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"` PoseMu sync.RWMutex `view:"-" copy:"-" json:"-" xml:"-" desc:"mutex on pose access -- needed for parallel updating"` 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, used for frustrum clipping"` }
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 Solid
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) AsSolid ¶ added in v0.9.11
func (nb *Node3DBase) AsSolid() *Solid
func (*Node3DBase) BaseIface ¶ added in v1.2.0
func (nb *Node3DBase) BaseIface() reflect.Type
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)
Default node can be selected / manipulated per the Scene SelMode settings
func (*Node3DBase) CopyFieldsFrom ¶ added in v0.9.11
func (nb *Node3DBase) CopyFieldsFrom(frm interface{})
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) IsSolid ¶ added in v0.9.11
func (nb *Node3DBase) IsSolid() bool
func (*Node3DBase) IsTransparent ¶
func (nb *Node3DBase) IsTransparent() bool
func (*Node3DBase) IsVisible ¶
func (nb *Node3DBase) IsVisible() bool
func (*Node3DBase) NormDCBBox ¶ added in v1.0.5
func (nb *Node3DBase) NormDCBBox() mat32.Box3
NormDCBBox returns the normalized display coordinates bounding box which is used for clipping. This is read-lock protected.
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 solid. 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) SetPosePos ¶ added in v1.0.5
func (nb *Node3DBase) SetPosePos(pos mat32.Vec3)
SetPosePos sets Pose.Pos position to given value, under write lock protection
func (*Node3DBase) SetPoseQuat ¶ added in v1.0.5
func (nb *Node3DBase) SetPoseQuat(quat mat32.Quat)
SetPoseQuat sets Pose.Quat to given value, under write lock protection
func (*Node3DBase) SetPoseScale ¶ added in v1.0.5
func (nb *Node3DBase) SetPoseScale(scale mat32.Vec3)
SetPoseScale sets Pose.Scale scale to given value, under write lock protection
func (*Node3DBase) Style3D ¶ added in v0.9.11
func (nb *Node3DBase) Style3D(sc *Scene)
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) UpdateNode3D ¶ added in v0.9.11
func (nb *Node3DBase) UpdateNode3D(sc *Scene)
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, under read lock protection
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 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 element (relative to parent)"` 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 position and orientation, always relevant to the parent element.
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 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) MulMatrix ¶ added in v0.9.11
MulMatrix multiplies current pose Matrix by given Matrix, and re-extracts the Pos, Scale, Quat from resulting matrix.
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 RClassOpaqueTexture // textures tend to be in background RClassOpaqueUniform RClassOpaqueVertex RClassTransTexture RClassTransUniform RClassTransVertex 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 solid. 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 gist.Color `desc:"background color"` Wireframe bool `desc:"if true, render as wireframe instead of filled"` 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"` Library map[string]*Group `desc:"library of objects that can be 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?"` SelMode SelModes `desc:"how to deal with selection / manipulation events"` CurSel Node3D `copy:"-" json:"-" xml:"-" view:"-" desc:"currently selected node"` CurManipPt *ManipPt `copy:"-" json:"-" xml:"-" view:"-" desc:"currently selected manipulation control point"` SelParams SelParams `view:"inline" desc:"parameters for selection / manipulation box"` }
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) -- Solids 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) error
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).
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) AddFmLibrary ¶ added in v0.9.11
AddFmLibrary adds a Clone of named item in the Library under given parent in the scenegraph. Returns an error if item not found.
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. Any existing mesh of the same name is deleted. see AddNewX for convenience methods to add specific shapes
func (*Scene) AddMeshUnique ¶ added in v0.9.11
AddMeshUniqe adds given mesh to mesh collection, ensuring that it has a unique name if one already exists.
func (*Scene) AddTexture ¶
AddTexture adds given texture to texture collection see AddNewTextureFile to add a texture that loads from file
func (*Scene) AddToLibrary ¶ added in v0.9.11
AddToLibrary adds given Group to library, using group's name as unique key in Library map.
func (*Scene) ChildrenBBox2D ¶
func (*Scene) ComputeBBox2D ¶
func (*Scene) Defaults ¶
func (sc *Scene) Defaults()
Defaults sets default scene params (camera, bg = white)
func (*Scene) DeleteMesh ¶ added in v0.9.11
DeleteMesh removes given mesh -- returns error if mesh not found.
func (*Scene) DeleteMeshes ¶ added in v0.9.11
func (sc *Scene) DeleteMeshes()
DeleteMeshes removes all meshes
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) DeleteTexture ¶ added in v0.9.11
DeleteTexture deletes texture of given name -- returns error if not found
func (*Scene) DeleteTextures ¶ added in v0.9.11
func (sc *Scene) DeleteTextures()
DeleteTextures removes all textures
func (*Scene) DeleteUnusedMeshes ¶
func (sc *Scene) DeleteUnusedMeshes()
DeleteUnusedMeshes deletes all unused meshes
func (*Scene) DirectWinUpload ¶
func (*Scene) Disconnect ¶
func (sc *Scene) Disconnect()
func (*Scene) InitMesh ¶ added in v0.9.11
InitMesh does a full init and gpu transfer of the given mesh name.
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) IsRendering ¶ added in v1.2.0
func (*Scene) ManipBox ¶ added in v0.9.11
func (sc *Scene) ManipBox()
ManipBox draws a manipulation box around selected node
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) NewInLibrary ¶ added in v0.9.11
NewInLibrary makes a new Group in library, using given name as unique key in Library map.
func (*Scene) OpenNewObj ¶ added in v0.9.11
OpenNewObj opens object(s) from given file into a new group under given parent, using a decoder based on the file extension. Supported formats include: .obj = Wavefront OBJ format, including associated materials (.mtl) which
must have same name as .obj, or a default material is used.
func (*Scene) OpenObj ¶ added in v0.9.11
OpenObj opens object(s) from given file into given group in scene, using a decoder based on the file extension. Supported formats include: .obj = Wavefront OBJ format, including associated materials (.mtl) which
must have same name as .obj, or a default material is used.
func (*Scene) OpenScene ¶ added in v0.9.11
OpenScene opens a scene from given file, using a decoder based on the file extension in first file name. Supported formats include: .obj = Wavefront OBJ format, including associated materials (.mtl) which
must have same name as .obj, or a default material is used. Does not support full scene data so only objects are loaded into a new group in scene.
func (*Scene) OpenToLibrary ¶ added in v0.9.11
OpenToLibrary opens object(s) from given file into the scene's Library using a decoder based on the file extension. The library key name must be unique, and is given by libnm -- if empty, then the filename (only) without extension is used. Supported formats include: .obj = Wavefront OBJ format, including associated materials (.mtl) which
must have same name as .obj, or a default material is used.
func (*Scene) PlaneMesh2D ¶ added in v0.9.11
PlaneMesh2D returns the special Plane mesh used for Text2D and Embed2D (creating it if it does not yet exist). This is a 1x1 plane with a normal pointing in +Z direction.
func (*Scene) PushBounds ¶
we use our own render for these -- Viewport member is our parent!
func (*Scene) ReadObj ¶ added in v0.9.11
ReadObj reads object(s) from given reader(s) into given group in scene, using a decoder based on the extension of the given file name -- even though the file name is not directly used to read the file, it is required for naming and decoding selection. This method can be used for loading data embedded in an executable for example. Supported formats include: .obj = Wavefront OBJ format, including associated materials (.mtl) which
is the 2nd reader arg, or a default material is used.
func (*Scene) ReadScene ¶ added in v0.9.11
ReadScene reads scene from given reader(s), using a decoder based on the file name extension -- even though the file name is not directly used to read the file, it is required for naming and decoding selection. This method can be used for loading data embedded in an executable for example. Supported formats include: .obj = Wavefront OBJ format, including associated materials (.mtl) which
must have same name as .obj, or a default material is used. Does not support full scene data so only objects are loaded into a new group in scene.
func (*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) SelectBox ¶ added in v0.9.11
func (sc *Scene) SelectBox()
SelectBox draws a selection box around selected node
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) SetManipPt ¶ added in v0.9.11
SetManipPt sets the CurManipPt
func (*Scene) SetSel ¶ added in v0.9.11
SetSel -- if Selectable is true, then given object is selected if node is nil then selection is reset.
func (*Scene) SolidsIntersectingPoint ¶ added in v0.9.11
SolidsIntersectingPoint finds all the solids that contain given 2D window coordinate
func (*Scene) TextureByName ¶ added in v1.0.11
TextureByName looks for texture by name -- returns nil if not found
func (*Scene) TextureByNameTry ¶ added in v1.0.11
TextureByNameTry looks for texture by name -- returns error if not found
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). Solids in that group can set their relative Pos etc to display relative to the camera, to achieve "first person" effects.
func (*Scene) Update ¶ added in v0.9.11
func (sc *Scene) Update()
Update is a global update of everything: Init3D and re-render
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 (for dynamically updating meshes). This version is 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) UpdateNodes3D ¶ added in v0.9.11
func (sc *Scene) UpdateNodes3D()
func (*Scene) UpdateWorldMatrix ¶
func (sc *Scene) UpdateWorldMatrix()
UpdateWorldMatrix updates the world matrix for all scene elements called during Init3D and rendering
type SceneFlags ¶ added in v1.2.0
type SceneFlags int
SceneFlags extend gi.NodeFlags to hold 3D node state
const ( // Rendering means that the scene is currently rendering Rendering SceneFlags = SceneFlags(gi.NodeFlagsN) + iota SceneFlagsN )
func StringToSceneFlags ¶ added in v1.2.0
func StringToSceneFlags(s string) (SceneFlags, error)
func (SceneFlags) String ¶ added in v1.2.0
func (i SceneFlags) String() string
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 SelModes ¶ added in v0.9.11
type SelModes int
SelModes are selection modes for Scene
const ( // NotSelectable means that selection events are ignored entirely NotSelectable SelModes = iota // Selectable means that nodes can be selected but no visible consequence occurs Selectable // SelectionBox means that a selection bounding box is drawn around selected nodes SelectionBox // Manipulable means that a manipulation box will be created for selected nodes, // which can update the Pose parameters dynamically. Manipulable SelModesN )
func (*SelModes) FromString ¶ added in v0.9.11
type SelParams ¶ added in v0.9.11
type SelParams struct { Color gi.ColorName `desc:"name of color to use for selection box (default yellow)"` Width float32 `desc:"width of the box lines (.01 default)"` Radius float32 `desc:"radius of the manipulation control point spheres"` }
SelParams are parameters for selection / manipulation box
type Solid ¶ added in v0.9.11
type Solid struct { Node3DBase Mesh MeshName `desc:"name of the mesh shape information used for rendering this solid -- all meshes are collected on the Scene"` Mat Material `view:"add-fields" desc:"material properties of the surface (color, shininess, texture, etc)"` MeshPtr Mesh `view:"-" desc:"cached pointer to mesh"` }
Solid represents an individual 3D solid element. It has its own unique spatial transforms and material properties, and points to a mesh structure defining the shape of the solid.
func AddNewLine ¶ added in v0.9.11
func AddNewLine(sc *Scene, parent ki.Ki, name string, st, ed mat32.Vec3, width float32, clr gist.Color) *Solid
AddNewLine adds a new line between two specified points, using a shared mesh unit line, which is rotated and positioned to go between the designated points.
func AddNewSolid ¶ added in v0.9.11
AddNewSolid adds a new solid of given name and mesh to given parent
func (*Solid) CopyFieldsFrom ¶ added in v0.9.11
func (sld *Solid) CopyFieldsFrom(frm interface{})
func (*Solid) Defaults ¶ added in v0.9.11
func (sld *Solid) Defaults()
Defaults sets default initial settings for solid params -- important to call this before setting specific values, as the initial zero values for some parameters are degenerate
func (*Solid) Disconnect ¶ added in v1.0.11
func (sld *Solid) Disconnect()
func (*Solid) IsTransparent ¶ added in v0.9.11
func (*Solid) ParentMaterial ¶ added in v0.9.11
ParentMaterial returns parent's material or nil if not avail
func (*Solid) Render3D ¶ added in v0.9.11
func (sld *Solid) Render3D(sc *Scene, rc RenderClasses, rnd Render)
Render3D activates this solid for rendering
func (*Solid) RenderClass ¶ added in v0.9.11
func (sld *Solid) RenderClass() RenderClasses
RenderClass returns the class of rendering for this solid used for organizing the ordering of rendering
func (*Solid) SetMeshName ¶ added in v0.9.11
SetMeshName sets mesh to given mesh name.
func (*Solid) UpdateMeshBBox ¶ added in v0.9.11
func (sld *Solid) UpdateMeshBBox()
UpdateMeshBBox updates the Mesh-based BBox info for all nodes. groups aggregate over elements
type SolidPoint ¶ added in v1.0.0
SolidPoint contains a Solid and a Point on that solid
type Sphere ¶ added in v0.9.11
type Sphere struct { MeshBase Radius float32 `desc:"radius of the sphere"` WidthSegs int `min:"3" desc:"number of segments around the width of the sphere (32 is reasonable default for full circle)"` HeightSegs int `min:"3" desc:"number of height segments (32 is reasonable default for full height)"` AngStart float32 `min:"0" max:"360" step:"5" desc:"starting radial angle in degrees, relative to -1,0,0 left side starting point"` AngLen float32 `min:"0" max:"360" step:"5" desc:"total radial angle to generate in degrees (max = 360)"` ElevStart float32 `min:"0" max:"180" step:"5" desc:"starting elevation (height) angle in degrees - 0 = top of sphere, and Pi is bottom"` ElevLen float32 `min:"0" max:"180" step:"5" desc:"total angle to generate in degrees (max = 180)"` }
Sphere is a sphere mesh
func AddNewSphere ¶ added in v0.9.11
AddNewSphere creates a sphere mesh with the specified radius, number of segments (resolution).
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 { Solid Text string `desc:"the text string to display"` Sty gist.Style `json:"-" xml:"-" desc:"styling settings for the text"` TxtPos mat32.Vec2 `xml:"-" json:"-" desc:"position offset of start of text rendering relative to upper-left corner"` TxtRender girl.Text `view:"-" xml:"-" json:"-" desc:"render data for text label"` TxtTex *TextureBase `` /* 136-byte string literal not displayed */ RenderState girl.State `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 text 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 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 solid using this texture.
type Tiling ¶
type Tiling struct { Repeat mat32.Vec2 `desc:"how often to repeat the texture in each direction"` Off mat32.Vec2 `desc:"offset for when to start the texure in each direction"` }
Tiling are the texture tiling parameters
type Torus ¶ added in v0.9.11
type Torus struct { MeshBase Radius float32 `desc:"larger radius of the torus ring"` TubeRadius float32 `desc:"radius of the solid tube"` RadialSegs int `min:"1" desc:"number of segments around the radius of the torus (32 is reasonable default for full circle)"` TubeSegs int `min:"1" desc:"number of segments for the tube itself (32 is reasonable default for full height)"` AngStart float32 `min:"0" max:"360" step:"5" desc:"starting radial angle in degrees relative to 1,0,0 starting point"` AngLen float32 `min:"0" max:"360" step:"5" desc:"total radial angle to generate in degrees (max = 360)"` }
Torus is a torus mesh, defined by the radius of the solid tube and the larger radius of the ring.
func AddNewTorus ¶ added in v0.9.11
AddNewTorus creates a sphere mesh with the specified outer ring radius, solid tube radius, and number of segments (resolution).
Source Files ¶
- bbox.go
- camera.go
- cylinder.go
- doc.go
- embed2d.go
- group.go
- io.go
- light.go
- lightcolors_string.go
- lines.go
- manip.go
- material.go
- mesh.go
- node3d.go
- nodeflags_string.go
- pose.go
- render.go
- scene.go
- sceneflags_string.go
- sceneview.go
- selmodes_string.go
- shapes.go
- solid.go
- sphere.go
- style.go
- text2d.go
- texture.go
- torus.go
- valueviews.go