gi3d

package
v0.9.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2019 License: BSD-3-Clause Imports: 21 Imported by: 12

Documentation

Overview

Package gi3d provides a 3D scenegraph for the GoGi GUI framework.

The scenegraph is rooted at a gi3d.Scene node which is like gi.Viewport2D where the scene is rendered, similar to the svg.SVG node for SVG drawings.

Children of the Scene are either Group or Object -- Group applies a transform (position size, rotation etc) to everything under it, while Object has its own transform and a Material and Mesh which define the color / texture and shape of the object.

Solid shapes that are have uniform Material color properties on all surfaces can be a single Object, but if you need e.g., different textures for each side of a box then that must be represented as a Group of Objects using Plane Mesh's, each of which can then bind to a different Texture via their Material settings.

All Meshes are indexed triangles, and there are standard shapes such as Box, Sphere, Cylinder, Capsule, and Line (rendered as a thin Box with end points specified). Objects have computed bounding boxes and can be selected etc.

The Scene maintains a map of uniquely-named Mesh elements, and Objects refer to those by name. The same goes for Textures. This allows for efficient re-use of meshes and textures across multiple objects. The object basically instantiates a unique combination of these properties, and has a unique location / orientation in the scene.

The Scene also holds the Camera and Lights for rendering, and is fully in charge of the rendering process by iterating over the scene elements and culling out-of-view elements, ordering opaque then transparent elements, etc.

There are standard Render types that manage the relevant GPU programs / Pipelines to do the actual rendering, depending on Material and Mesh properties (e.g., uniform vs per-vertex color vs. texture).

Index

Constants

This section is empty.

Variables

View Source
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

View Source
var KiT_AmbientLight = kit.Types.AddType(&AmbientLight{}, nil)
View Source
var KiT_Box = kit.Types.AddType(&Box{}, nil)
View Source
var KiT_Camera = kit.Types.AddType(&Camera{}, CameraProps)
View Source
var KiT_DirLight = kit.Types.AddType(&DirLight{}, nil)
View Source
var KiT_Group = kit.Types.AddType(&Group{}, nil)
View Source
var KiT_LightBase = kit.Types.AddType(&LightBase{}, nil)
View Source
var KiT_LightColors = kit.Enums.AddEnum(LightColorsN, kit.NotBitFlag, nil)
View Source
var KiT_MeshBase = kit.Types.AddType(&MeshBase{}, nil)
View Source
var KiT_MeshValueView = kit.Types.AddType(&MeshValueView{}, nil)
View Source
var KiT_Node3DBase = kit.Types.AddType(&Node3DBase{}, Node3DBaseProps)
View Source
var KiT_NodeFlags = kit.Enums.AddEnumExt(gi.KiT_NodeFlags, NodeFlagsN, kit.BitFlag, nil)
View Source
var KiT_Object = kit.Types.AddType(&Object{}, nil)
View Source
var KiT_Plane = kit.Types.AddType(&Plane{}, nil)
View Source
var KiT_PointLight = kit.Types.AddType(&PointLight{}, nil)
View Source
var KiT_Pose = kit.Types.AddType(&Pose{}, PoseProps)
View Source
var KiT_Scene = kit.Types.AddType(&Scene{}, SceneProps)
View Source
var KiT_SceneView = kit.Types.AddType(&SceneView{}, nil)
View Source
var KiT_SpotLight = kit.Types.AddType(&SpotLight{}, nil)
View Source
var KiT_Text2D = kit.Types.AddType(&Text2D{}, nil)
View Source
var KiT_TextureBase = kit.Types.AddType(&TextureBase{}, nil)
View Source
var KiT_TextureFile = kit.Types.AddType(&TextureFile{}, nil)
View Source
var LightColorMap = map[LightColors]gi.Color{
	DirectSun:    {255, 255, 255, 255},
	CarbonArc:    {255, 250, 244, 255},
	Halogen:      {255, 241, 224, 255},
	Tungsten100W: {255, 214, 170, 255},
	Tungsten40W:  {255, 197, 143, 255},
	Candle:       {255, 147, 41, 255},
	Overcast:     {201, 226, 255, 255},
	FluorWarm:    {255, 244, 229, 255},
	FluorStd:     {244, 255, 250, 255},
	FluorCool:    {212, 235, 255, 255},
	FluorFull:    {255, 244, 242, 255},
	FluorGrow:    {255, 239, 247, 255},
	MercuryVapor: {216, 247, 255, 255},
	SodiumVapor:  {255, 209, 178, 255},
	MetalHalide:  {242, 252, 255, 255},
}

LightColorMap provides a map of named light colors

View Source
var Node3DBaseProps = ki.Props{
	"base-type":     true,
	"EnumType:Flag": KiT_NodeFlags,
}
View Source
var PoseProps = ki.Props{
	"ToolBar": ki.PropSlice{
		{"SetEulerRotation", ki.Props{
			"desc": "Set the local rotation (relative to parent) using Euler angles, in degrees.",
			"icon": "rotate-3d",
			"Args": ki.PropSlice{
				{"Pitch", ki.Props{
					"desc": "rotation up / down along the X axis (in the Y-Z plane), e.g., the altitude (climbing, descending) for motion along the Z depth axis",
				}},
				{"Yaw", ki.Props{
					"desc": "rotation along the Y axis (in the horizontal X-Z plane), e.g., the bearing or direction for motion along the Z depth axis",
				}},
				{"Roll", ki.Props{
					"desc": "rotation along the Z axis (in the X-Y plane), e.g., the bank angle for motion along the Z depth axis",
				}},
			},
		}},
		{"SetAxisRotation", ki.Props{
			"desc": "Set the local rotation (relative to parent) using Axis about which to rotate, and the angle.",
			"icon": "rotate-3d",
			"Args": ki.PropSlice{
				{"X", ki.BlankProp{}},
				{"Y", ki.BlankProp{}},
				{"Z", ki.BlankProp{}},
				{"Angle", ki.BlankProp{}},
			},
		}},
		{"RotateEuler", ki.Props{
			"desc": "rotate (relative to current rotation) using Euler angles, in degrees.",
			"icon": "rotate-3d",
			"Args": ki.PropSlice{
				{"Pitch", ki.Props{
					"desc": "rotation up / down along the X axis (in the Y-Z plane), e.g., the altitude (climbing, descending) for motion along the Z depth axis",
				}},
				{"Yaw", ki.Props{
					"desc": "rotation along the Y axis (in the horizontal X-Z plane), e.g., the bearing or direction for motion along the Z depth axis",
				}},
				{"Roll", ki.Props{
					"desc": "rotation along the Z axis (in the X-Y plane), e.g., the bank angle for motion along the Z depth axis",
				}},
			},
		}},
		{"RotateOnAxis", ki.Props{
			"desc": "Rotate (relative to current rotation) using Axis about which to rotate, and the angle.",
			"icon": "rotate-3d",
			"Args": ki.PropSlice{
				{"X", ki.BlankProp{}},
				{"Y", ki.BlankProp{}},
				{"Z", ki.BlankProp{}},
				{"Angle", ki.BlankProp{}},
			},
		}},
		{"LookAt", ki.Props{
			"icon": "rotate-3d",
			"Args": ki.PropSlice{
				{"Target", ki.BlankProp{}},
				{"UpDir", ki.BlankProp{}},
			},
		}},
		{"EulerRotation", ki.Props{
			"desc":        "The local rotation (relative to parent) in Euler angles in degrees (X = Pitch, Y = Yaw, Z = Roll)",
			"icon":        "rotate-3d",
			"show-return": "true",
		}},
		{"sep-rot", ki.BlankProp{}},
		{"MoveOnAxis", ki.Props{
			"desc": "Move given distance on given X,Y,Z axis relative to current rotation orientation.",
			"icon": "pan",
			"Args": ki.PropSlice{
				{"X", ki.BlankProp{}},
				{"Y", ki.BlankProp{}},
				{"Z", ki.BlankProp{}},
				{"Dist", ki.BlankProp{}},
			},
		}},
		{"MoveOnAxisAbs", ki.Props{
			"desc": "Move given distance on given X,Y,Z axis in absolute coords, not relative to current rotation orientation.",
			"icon": "pan",
			"Args": ki.PropSlice{
				{"X", ki.BlankProp{}},
				{"Y", ki.BlankProp{}},
				{"Z", ki.BlankProp{}},
				{"Dist", ki.BlankProp{}},
			},
		}},
	},
}

PoseProps define the ToolBar and MenuBar for StructView

View Source
var RenderPhong = `` /* 3756-byte string literal not displayed */
View Source
var RenderUniCamera = `
layout (std140) uniform Camera
{
    mat4 MVMatrix;
    mat4 MVPMatrix;
    mat3 NormMatrix;
};
`
View Source
var RenderUniLights = `` /* 924-byte string literal not displayed */
View Source
var SceneProps = ki.Props{
	"EnumType:Flag": gi.KiT_NodeFlags,
	"ToolBar": ki.PropSlice{
		{"UpdateSig", ki.Props{
			"label": "Update",
			"icon":  "update",
		}},
	},
}

SceneProps define the ToolBar and MenuBar for StructView

View Source
var Update3DTrace = false

Set Update3DTrace to true to get a trace of 3D updating

Functions

func ColorToVec3f

func ColorToVec3f(clr gi.Color) mat32.Vec3

ColorToVec3f converts given gi.Color to mat32.Vec3 float32's

func ColorToVec4f

func ColorToVec4f(clr gi.Color) mat32.Vec4

ColorToVec4f converts given gi.Color to mat32.Vec4 float32's

func KiToNode3D

func KiToNode3D(k ki.Ki) (Node3D, *Node3DBase)

KiToNode3D converts Ki to a Node3D interface and a Node3DBase obj -- nil if not.

Types

type AmbientLight

type AmbientLight struct {
	LightBase
}

AmbientLight provides diffuse uniform lighting -- typically only one of these

func AddNewAmbientLight

func AddNewAmbientLight(sc *Scene, name string, lumens float32, color LightColors) *AmbientLight

AddNewAmbientLight adds Ambient to given scene, with given name, standard color, and lumens (0-1 normalized)

type BBox

type BBox struct {
	BBox    mat32.Box3   `desc:"bounding box in local coords"`
	BSphere mat32.Sphere `desc:"bounding sphere in local coords"`
	Area    float32      `desc:"area"`
	Volume  float32      `desc:"volume"`
}

BBox contains bounding box and other gross object properties

func (*BBox) SetBounds

func (bb *BBox) SetBounds(min, max mat32.Vec3)

SetBounds sets BBox from min, max and updates other factors based on that

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)

func AddNewBox

func AddNewBox(sc *Scene, name string, width, height, depth float32) *Box

AddNewBox adds Box mesh to given scene, with given name and size

func (*Box) Make

func (bx *Box) Make(sc *Scene)

type Camera

type Camera struct {
	Pose          Pose       `` /* 126-byte string literal not displayed */
	Target        mat32.Vec3 `` /* 165-byte string literal not displayed */
	UpDir         mat32.Vec3 `desc:"up direction for camera -- which way is up -- defaults to positive Y axis, and is reset by call to LookAt method"`
	Ortho         bool       `` /* 206-byte string literal not displayed */
	FOV           float32    `desc:"field of view in degrees "`
	Aspect        float32    `desc:"aspect ratio (width/height)"`
	Near          float32    `desc:"near plane z coordinate"`
	Far           float32    `desc:"far plane z coordinate"`
	ViewMatrix    mat32.Mat4 `view:"-" desc:"view matrix (inverse of the Pose.Matrix)"`
	PrjnMatrix    mat32.Mat4 `view:"-" desc:"projection matrix, defining the camera perspective / ortho transform"`
	InvPrjnMatrix mat32.Mat4 `view:"-" desc:"inverse of the projection matrix"`
}

Camera defines the properties of the camera

func (*Camera) DefaultPose

func (cm *Camera) DefaultPose()

DefaultPose resets the camera pose to default location and orientation, looking at the origin from 0,0,10, with up Y axis

func (*Camera) Defaults

func (cm *Camera) Defaults()

func (*Camera) GenGoSet added in v0.9.9

func (cm *Camera) GenGoSet(path string) string

GenGoSet returns code to set values in object at given path (var.member etc)

func (*Camera) LookAt

func (cm *Camera) LookAt(target, upDir mat32.Vec3)

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

func (cm *Camera) Orbit(delX, delY float32)

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

func (cm *Camera) Pan(delX, delY float32)

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) PanAxis

func (cm *Camera) PanAxis(delX, delY float32)

PanAxis moves the camera and target along world X,Y axes

func (*Camera) PanTarget

func (cm *Camera) PanTarget(delX, delY, delZ float32)

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) Zoom

func (cm *Camera) Zoom(zoomPct float32)

Zoom moves along axis given pct closer or further from the target it always moves the target back also if it distance is < 1

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

func (*DirLight) ViewDir

func (dl *DirLight) ViewDir(viewMat *mat32.Mat4) mat32.Vec3

ViewDir gets the direction normal vector, pre-computing the view transform

type Group

type Group struct {
	Node3DBase
}

Group collects individual elements in a scene but does not have a Mesh or Material of its own. It does have a transform that applies to all nodes under it.

func AddNewGroup

func AddNewGroup(sc *Scene, parent ki.Ki, name string) *Group

AddNewGroup adds a new group of given name to given parent

func (*Group) Defaults

func (gp *Group) Defaults()

func (*Group) RenderClass

func (gp *Group) RenderClass() RenderClasses

func (*Group) UpdateMeshBBox added in v0.9.9

func (gp *Group) UpdateMeshBBox()

UpdateMeshBBox updates the Mesh-based BBox info for all nodes. groups aggregate over elements

type Light

type Light interface {
	// Name returns name of the light -- lights are accessed by name
	Name() string

	// Color returns color of light
	Color() gi.Color

	// Lumens returns brightness of light
	Lumens() float32
}

Light represents a light that illuminates a scene these are stored on the overall scene object and not within the graph

type LightBase

type LightBase struct {
	Nm    string   `desc:"name of light -- lights accessed by name so it matters"`
	On    bool     `desc:"whether light is on or off"`
	Lumns float32  `` /* 186-byte string literal not displayed */
	Clr   gi.Color `desc:"color of light a full intensity"`
}

LightBase provides the base implementation for Light interface

func (*LightBase) Color

func (lb *LightBase) Color() gi.Color

func (*LightBase) Lumens

func (lb *LightBase) Lumens() float32

func (*LightBase) Name

func (lb *LightBase) Name() string

Name returns name of the light -- lights are accessed by name

type LightColors

type LightColors int

LightColors are standard light colors for different light sources

const (
	DirectSun LightColors = iota
	CarbonArc
	Halogen
	Tungsten100W
	Tungsten40W
	Candle
	Overcast
	FluorWarm
	FluorStd
	FluorCool
	FluorFull
	FluorGrow
	MercuryVapor
	SodiumVapor
	MetalHalide
	LightColorsN
)

func (*LightColors) FromString

func (i *LightColors) FromString(s string) error

func (LightColors) String

func (i LightColors) String() string

type Material

type Material struct {
	Color     gi.Color `` /* 200-byte string literal not displayed */
	Emissive  gi.Color `desc:"color that surface emits independent of any lighting -- i.e., glow -- can be used for marking lights with an object"`
	Specular  gi.Color `desc:"shiny reflective color of surface -- set to white for shiny objects and to Color for non-shiny objects"`
	Shiny     float32  `` /* 338-byte string literal not displayed */
	Bright    float32  `` /* 183-byte string literal not displayed */
	Texture   TexName  `desc:"texture to provide color for the surface"`
	Tiling    Tiling   `view:"inline" viewif:"Texture!=''" desc:"texture tiling parameters -- repeat and offset"`
	CullBack  bool     `desc:"cull the back-facing surfaces"`
	CullFront bool     `desc:"cull the front-facing surfaces"`
	TexPtr    Texture  `view:"-" desc:"pointer to texture"`
}

Material describes the material properties of a surface (colors, shininess, texture) i.e., phong lighting parameters. Main color is used for both ambient and diffuse color, and alpha component is used for opacity. The Emissive color is only for glowing objects. The Specular color is always white (multiplied by light color). Textures are stored on the Scene and accessed by name

func (*Material) Defaults

func (mt *Material) Defaults()

Defaults sets default surface parameters

func (*Material) IsTransparent

func (mt *Material) IsTransparent() bool

IsTransparent returns true if texture says it is, or if color has alpha < 255

func (*Material) NoTexture

func (mt *Material) NoTexture()

NoTexture resets any texture setting that might have been set

func (*Material) SetTexture

func (mt *Material) SetTexture(sc *Scene, tex Texture)

SetTexture sets material to use given texture

func (*Material) SetTextureName

func (mt *Material) SetTextureName(sc *Scene, texName string) error

SetTextureName sets material to use given texture name (textures are accessed by name on Scene). If name is empty, then texture is reset

func (*Material) Validate

func (mt *Material) Validate(sc *Scene) error

Validate does overall material validation, including checking that material texture is valid if set

type Mesh

type Mesh interface {
	// Name returns name of the mesh
	Name() string

	// AsMeshBase returns the MeshBase for this Mesh
	AsMeshBase() *MeshBase

	// Reset resets all of the vector and index data for this mesh (to start fresh)
	Reset()

	// Make makes the shape mesh (defined for specific shape types)
	// This does not call any other gpu setup functions and should
	// be runnable outside of gpu context and on any thread -- just
	// sets the various Vtx etc Arrays, and doesn't touch the gpu Buffer
	Make(sc *Scene)

	// Update updates any dynamically changing meshes (can be optimized to only update
	// relevant vertex data instead of the indexes, norms, and texture coords)
	// Unlike Make, this is only called with context active on main thread
	// and is responsible for calling any relevant Set*Data and Transfer method(s) to update the GPU.
	Update(sc *Scene)

	// ComputeNorms automatically computes the normals from existing vertex data
	ComputeNorms()

	// Alloc allocates given number of vertex and index values, optionally including colors
	// More efficient if number of such is known in advance
	Alloc(vtxs, idxs int, color bool)

	// AddPlane adds everything to render a plane with the given parameters.
	// waxis, haxis = width, height axis, wdir, hdir are the directions for width and height dimensions.
	// wsegs, hsegs = number of segments to create in each dimension -- more finely subdividing a plane
	// allows for higher-quality lighting and texture rendering (minimum of 1 will be enforced).
	// offset is the distance to place the plane along the orthogonal axis.
	// if clr is non-Nil then it will be added
	AddPlane(waxis, haxis mat32.Dims, wdir, hdir int, width, height, woff, hoff, zoff float32, wsegs, hsegs int, clr gi.Color)

	// SetPlane sets plane vertex data (optionally norm, texUV, color, and indexes) at given starting
	// *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), and starting Idx index.
	// If doing a dynamic updating, compute the starting index using PlaneSize (and typically don't update Idx).
	// waxis, haxis = width, height axis, wdir, hdir are the directions for width and height dimensions.
	// wsegs, hsegs = number of segments to create in each dimension -- more finely subdividing a plane
	// allows for higher-quality lighting and texture rendering (minimum of 1 will be enforced).
	// offset is the distance to place the plane along the orthogonal axis.
	// if clr is non-Nil then it will be added
	SetPlane(stVtxIdx, stIdxIdx int, setNorm, setTex, setIdx bool, waxis, haxis mat32.Dims, wdir, hdir int, width, height, woff, hoff, zoff float32, wsegs, hsegs int, clr gi.Color)

	// PlaneSize returns the size of a single plane's worth of vertex and index data
	// with given number of segments.
	// Note: In *vertex* units, not float units (i.e., x3 to get actual float offset in Vtx array).
	// Use for computing the starting indexes in SetPlaneVtx.
	// vtxSize = (wsegs + 1) * (hsegs + 1)
	// idxSize = wsegs * hsegs * 6
	PlaneSize(wsegs, hsegs int) (vtxSize, idxSize int)

	// Validate checks if all the vertex data is valid
	// any errors are logged
	Validate() error

	// HasColor returns true if this mesh has vertex-specific colors available
	HasColor() bool

	// IsTransparent returns true if this mesh has vertex-specific colors available
	// and at least some are transparent.
	IsTransparent() bool

	// MakeVectors compiles the existing mesh data into the Vectors for GPU rendering
	// Must be called with relevant context active.
	MakeVectors(sc *Scene) error

	// Activate activates the mesh Vectors on the GPU
	// Must be called with relevant context active
	// returns false if there is no mesh defined
	Activate(sc *Scene) bool

	// Activate deletes the mesh Vectors on the GPU
	// Must be called with relevant context active, on main thread
	Delete(sc *Scene)

	// TransferAll transfer all buffer data to GPU (vectors and indexes)
	// Activate must have just been called
	TransferAll()

	// TransferVectors transfer vectors buffer data to GPU (if vector data has changed)
	// Activate must have just been called
	TransferVectors()

	// TransferIndexes transfer vectors buffer data to GPU (if index data has changed)
	// Activate must have just been called
	TransferIndexes()

	// Render3D calls gpu.TrianglesIndexed to render the mesh.
	// Must be called in context on main thread -- does activate, then draw triangles indexed
	Render3D(sc *Scene)

	// SetVtxData sets the (updated) Vtx data into the overall vector that
	// will be transfered using the next TransferVectors call.
	// It is essential that the length has not changed -- if length is changing
	// then you must update everything and call MakeVectors.
	// Use this for dynamically updating vertex data.
	// has no constraints on where called.
	SetVtxData(sc *Scene)

	// SetNormData sets the (updated) Norm data into the overall vector that
	// will be transfered using the next TransferVectors call.
	// It is essential that the length has not changed -- if length is changing
	// then you must update everything and call MakeVectors.
	// Use this for dynamically updating vertex data.
	// has no constraints on where called.
	SetNormData(sc *Scene)

	// SetColorData sets the (updated) Color data into the overall vector that
	// will be transfered using the next TransferVectors call.
	// It is essential that the length has not changed -- if length is changing
	// then you must update everything and call MakeVectors.
	// Use this for dynamically updating color data (only use if vertex color in use!)
	// has no constraints on where called.
	SetColorData(sc *Scene)
}

Mesh holds the mesh-based shape used for rendering an object. Only indexed triangle meshes are supported. All Mesh's must define Vtx, Norm, Tex (stored interleaved), and Idx components. Per-vertex Color is optional, and is appended to the vertex buffer non-interleaved if present.

type MeshBase

type MeshBase struct {
	Nm      string         `desc:"name of mesh -- meshes are linked to objects by name so this matters"`
	Dynamic bool           `desc:"if true, this mesh changes frequently -- otherwise considered to be static"`
	Trans   bool           `desc:"set to true if color has transparency -- not worth checking manually"`
	Vtx     mat32.ArrayF32 `desc:"verticies for triangle shapes that make up the mesh -- all mesh structures must use indexed triangle meshes"`
	Norm    mat32.ArrayF32 `desc:"computed normals for each vertex"`
	Tex     mat32.ArrayF32 `desc:"texture U,V coordinates for mapping textures onto vertexes"`
	Idx     mat32.ArrayU32 `desc:"indexes that sequentially in groups of 3 define the actual triangle faces"`
	Color   mat32.ArrayF32 `` /* 190-byte string literal not displayed */
	BBox    BBox           `desc:"computed bounding-box and other gross object properties"`
	Buff    gpu.BufferMgr  `view:"-" desc:"buffer holding computed verticies, normals, indices, etc for rendering"`
}

MeshBase provides the core implementation of Mesh interface

func (*MeshBase) Activate

func (ms *MeshBase) Activate(sc *Scene) bool

Activate activates the mesh Vectors on the GPU Must be called with relevant context active on main thread

func (*MeshBase) AddPlane

func (ms *MeshBase) AddPlane(waxis, haxis mat32.Dims, wdir, hdir int, width, height, woff, hoff, zoff float32, wsegs, hsegs int, clr gi.Color)

AddPlane adds everything to render a plane with the given parameters (convenience wrapper around SetPlane method). waxis, haxis = width, height axis, wdir, hdir are the directions for width and height dimensions. wsegs, hsegs = number of segments to create in each dimension -- more finely subdividing a plane allows for higher-quality lighting and texture rendering (minimum of 1 will be enforced). offset is the distance to place the plane along the orthogonal axis.

func (*MeshBase) Alloc

func (ms *MeshBase) Alloc(vtxs, idxs int, color bool)

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

func (ms *MeshBase) AsMeshBase() *MeshBase

AsMeshBase returns the MeshBase for this Mesh

func (*MeshBase) ComputeNorms

func (ms *MeshBase) ComputeNorms()

func (*MeshBase) Delete

func (ms *MeshBase) Delete(sc *Scene)

Delete deletes the mesh Vectors on the GPU Must be called with relevant context active on main thread

func (*MeshBase) HasColor

func (ms *MeshBase) HasColor() bool

func (*MeshBase) IsTransparent

func (ms *MeshBase) IsTransparent() bool

func (*MeshBase) MakeVectors

func (ms *MeshBase) MakeVectors(sc *Scene) error

MakeVectors compiles the existing mesh data into the Vectors for GPU rendering Must be called with relevant context active on main thread

func (*MeshBase) Name

func (ms *MeshBase) Name() string

func (*MeshBase) PlaneSize

func (ms *MeshBase) PlaneSize(wsegs, hsegs int) (vtxSize, idxSize int)

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

func (ms *MeshBase) Render3D(sc *Scene)

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

func (ms *MeshBase) SetColorData(sc *Scene)

SetColorData sets the (updated) Color data into the overall vector that will be transfered using the next TransferVectors call. It is essential that the length has not changed -- if length is changing then you must update everything and call MakeVectors. Use this for dynamically updating color data (only use if vertex color in use!) has no constraints on where called.

func (*MeshBase) SetNormData

func (ms *MeshBase) SetNormData(sc *Scene)

SetNormData sets the (updated) Norm data into the overall vector that will be transfered using the next TransferVectors call. It is essential that the length has not changed -- if length is changing then you must update everything and call MakeVectors. Use this for dynamically updating vertex data. has no constraints on where called.

func (*MeshBase) SetPlane

func (ms *MeshBase) SetPlane(stVtxIdx, stIdxIdx int, setNorm, setTex, setIdx bool, waxis, haxis mat32.Dims, wdir, hdir int, width, height, woff, hoff, zoff float32, wsegs, hsegs int, clr gi.Color)

SetPlane sets plane vertex data (optionally norm, texUV, color, and indexes) at given starting *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), and starting Idx index. If doing a dynamic updating, compute the starting index using PlaneSize (and typically don't update Idx). waxis, haxis = width, height axis, wdir, hdir are the directions for width and height dimensions. wsegs, hsegs = number of segments to create in each dimension -- more finely subdividing a plane allows for higher-quality lighting and texture rendering (minimum of 1 will be enforced). offset is the distance to place the plane along the orthogonal axis. if clr is non-Nil then it will be added

func (*MeshBase) SetVtxData

func (ms *MeshBase) SetVtxData(sc *Scene)

SetVtxData sets the (updated) Vtx data into the overall vector that will be transfered using the next TransferVectors call. It is essential that the length has not changed -- if length is changing then you must update everything and call MakeVectors. Use this for dynamically updating vertex data. has no constraints on where called.

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

func (*MeshBase) Update

func (ms *MeshBase) Update(sc *Scene)

func (*MeshBase) Validate

func (ms *MeshBase) Validate() error

Validate checks if all the vertex data is valid any errors are logged

type MeshName

type MeshName string

MeshName is a mesh name -- provides an automatic gui chooser for meshes Used on Object to link to meshes by name.

func (MeshName) ValueView

func (mn MeshName) ValueView() giv.ValueView

ValueView registers MeshValueView as the viewer of MeshName

type MeshValueView

type MeshValueView struct {
	giv.ValueViewBase
}

MeshValueView presents an action for displaying a MeshName and selecting meshes from a ChooserDialog

func (*MeshValueView) Activate

func (vv *MeshValueView) Activate(vp *gi.Viewport2D, dlgRecv ki.Ki, dlgFunc ki.RecvFunc)

func (*MeshValueView) ConfigWidget

func (vv *MeshValueView) ConfigWidget(widg gi.Node2D)

func (*MeshValueView) HasAction

func (vv *MeshValueView) HasAction() bool

func (*MeshValueView) UpdateWidget

func (vv *MeshValueView) UpdateWidget()

func (*MeshValueView) WidgetType

func (vv *MeshValueView) WidgetType() reflect.Type

type Node3D

type Node3D interface {
	gi.Node

	// IsObject returns true if this is an Object node (else a Group)
	IsObject() bool

	// AsNode3D returns a generic Node3DBase for our node -- gives generic
	// access to all the base-level data structures without requiring
	// interface methods.
	AsNode3D() *Node3DBase

	// AsObject returns a node as Object (nil if not)
	AsObject() *Object

	// Validate checks that scene element is valid
	Validate(sc *Scene) error

	// UpdateWorldMatrix updates this node's local and world matrix based on parent's world matrix
	// This sets the WorldMatrixUpdated flag but does not check that flag -- calling
	// routine can optionally do so.
	UpdateWorldMatrix(parWorld *mat32.Mat4)

	// UpdateMVPMatrix updates this node's MVP matrix based on given view and prjn matrix from camera
	// Called during rendering.
	UpdateMVPMatrix(viewMat, prjnMat *mat32.Mat4)

	// UpdateMeshBBox updates the Mesh-based BBox info for all nodes.
	// groups aggregate over elements.  called from FuncDownMeLast traversal
	UpdateMeshBBox()

	// UpdateBBox2D updates this node's 2D bounding-box information based on scene
	// size and other scene bbox info from scene
	UpdateBBox2D(size mat32.Vec2, sc *Scene)

	// RayPick converts a given 2D point in scene image coordinates
	// into a ray from the camera position pointing through line of sight of camera
	// into *local* coordinates of the object.
	// This can be used to find point of intersection in local coordinates relative
	// to a given plane of interest, for example (see Ray methods for intersections)
	RayPick(pos image.Point, sc *Scene) mat32.Ray

	// WorldMatrix returns the world matrix for this node
	WorldMatrix() *mat32.Mat4

	// IsVisible provides the definitive answer as to whether a given node
	// is currently visible.  It is only entirely valid after a render pass
	// for widgets in a visible window, but it checks the window and viewport
	// for their visibility status as well, which is available always.
	// Non-visible nodes are automatically not rendered and not connected to
	// window events.  The Invisible flag is one key element of the IsVisible
	// calculus -- it is set by e.g., TabView for invisible tabs, and is also
	// set if a widget is entirely out of render range.  But again, use
	// IsVisible as the main end-user method.
	// For robustness, it recursively calls the parent -- this is typically
	// a short path -- propagating the Invisible flag properly can be
	// very challenging without mistakenly overwriting invisibility at various
	// levels.
	IsVisible() bool

	// IsTransparent returns true if object has transparent color
	IsTransparent() bool

	// Init3D does 3D intialization
	Init3D(sc *Scene)

	// RenderClass returns the class of rendering for this object
	// used for organizing the ordering of rendering
	RenderClass() RenderClasses

	// Render3D is called by Scene Render3D on main thread,
	// everything ready to go..
	Render3D(sc *Scene, rc RenderClasses, rnd Render)

	// ConnectEvents3D: setup connections to window events -- called in
	// Render3D if in bounds.  It can be useful to create modular methods for
	// different event types that can then be mix-and-matched in any more
	// specialized types.
	ConnectEvents3D(sc *Scene)
}

Node3D is the common interface for all gi3d scenegraph nodes

type Node3DBase

type Node3DBase struct {
	gi.NodeBase
	Pose      Pose       `desc:"complete specification of position and orientation"`
	MeshBBox  BBox       `desc:"mesh-based local bounding box (aggregated for groups)"`
	WorldBBox BBox       `desc:"world coordinates bounding box"`
	NDCBBox   mat32.Box3 `desc:"normalized display coordinates bounding box"`
}

Node3DBase is the basic 3D scenegraph node, which has the full transform information relative to parent, and computed bounding boxes, etc. There are only two different kinds of Nodes: Group and Object

func KiToNode3DBase

func KiToNode3DBase(k ki.Ki) *Node3DBase

KiToNode3DBase converts Ki to a *Node3DBase -- use when known to be at least of this type, not-nil, etc

func (*Node3DBase) AsNode3D

func (nb *Node3DBase) AsNode3D() *Node3DBase

AsNode3D returns a generic Node3DBase for our node -- gives generic access to all the base-level data structures without requiring interface methods.

func (*Node3DBase) AsObject

func (nb *Node3DBase) AsObject() *Object

func (*Node3DBase) ConnectEvent added in v0.9.9

func (nb *Node3DBase) ConnectEvent(win *gi.Window, et oswin.EventType, pri gi.EventPris, fun ki.RecvFunc)

ConnectEvent connects this node to receive a given type of GUI event signal from the parent window -- typically connect only visible nodes, and disconnect when not visible

func (*Node3DBase) ConnectEvents3D added in v0.9.9

func (nb *Node3DBase) ConnectEvents3D(sc *Scene)

func (*Node3DBase) DisconnectAllEvents added in v0.9.9

func (nb *Node3DBase) DisconnectAllEvents(win *gi.Window, pri gi.EventPris)

DisconnectAllEvents disconnects node from all window events -- typically disconnect when not visible -- pri is priority -- pass AllPris for all priorities. This goes down the entire tree from this node on down, as typically everything under will not get an explicit disconnect call because no further updating will happen

func (*Node3DBase) DisconnectEvent added in v0.9.9

func (nb *Node3DBase) DisconnectEvent(win *gi.Window, et oswin.EventType, pri gi.EventPris)

DisconnectEvent disconnects this receiver from receiving given event type -- pri is priority -- pass AllPris for all priorities -- see also DisconnectAllEvents

func (*Node3DBase) Init3D

func (nb *Node3DBase) Init3D(sc *Scene)

func (*Node3DBase) IsObject

func (nb *Node3DBase) IsObject() bool

func (*Node3DBase) IsTransparent

func (nb *Node3DBase) IsTransparent() bool

func (*Node3DBase) IsVisible

func (nb *Node3DBase) IsVisible() bool

func (*Node3DBase) RayPick added in v0.9.9

func (nb *Node3DBase) RayPick(pos image.Point, sc *Scene) mat32.Ray

RayPick converts a given 2D point in scene image coordinates into a ray from the camera position pointing through line of sight of camera into *local* coordinates of the object. This can be used to find point of intersection in local coordinates relative to a given plane of interest, for example (see Ray methods for intersections). To convert mouse window-relative coords into scene-relative coords subtract the sc.ObjBBox.Min which includes any scrolling effects

func (*Node3DBase) Render3D

func (nb *Node3DBase) Render3D(sc *Scene, rc RenderClasses, rnd Render)

func (*Node3DBase) TrackCamera

func (nb *Node3DBase) TrackCamera(sc *Scene)

TrackCamera moves this node to pose of camera

func (*Node3DBase) TrackLight

func (nb *Node3DBase) TrackLight(sc *Scene, lightName string) error

TrackLight moves node to position of light of given name. For SpotLight, copies entire Pose. Does not work for Ambient light which has no position information.

func (*Node3DBase) UpdateBBox2D added in v0.9.9

func (nb *Node3DBase) UpdateBBox2D(size mat32.Vec2, sc *Scene)

UpdateBBox2D updates this node's 2D bounding-box information based on scene size and min offset position.

func (*Node3DBase) UpdateMVPMatrix

func (nb *Node3DBase) UpdateMVPMatrix(viewMat, prjnMat *mat32.Mat4)

UpdateMVPMatrix updates this node's MVP matrix based on given view, prjn matricies from camera. Called during rendering.

func (*Node3DBase) UpdateWorldMatrix

func (nb *Node3DBase) UpdateWorldMatrix(parWorld *mat32.Mat4)

UpdateWorldMatrix updates this node's world matrix based on parent's world matrix. If a nil matrix is passed, then the previously-set parent world matrix is used. This sets the WorldMatrixUpdated flag but does not check that flag -- calling routine can optionally do so.

func (*Node3DBase) Validate

func (nb *Node3DBase) Validate(sc *Scene) error

func (*Node3DBase) WorldMatrix

func (nb *Node3DBase) WorldMatrix() *mat32.Mat4

WorldMatrix returns the world matrix for this node

func (*Node3DBase) WorldMatrixUpdated

func (nb *Node3DBase) WorldMatrixUpdated() bool

type NodeFlags added in v0.9.9

type NodeFlags int

NodeFlags extend gi.NodeFlags to hold 3D node state

const (
	// WorldMatrixUpdated means that the Pose.WorldMatrix has been updated
	WorldMatrixUpdated NodeFlags = NodeFlags(gi.NodeFlagsN) + iota

	// VectorsUpdated means that the rendering vectors information is updated
	VectorsUpdated

	NodeFlagsN
)

func StringToNodeFlags added in v0.9.9

func StringToNodeFlags(s string) (NodeFlags, error)

func (NodeFlags) String added in v0.9.9

func (i NodeFlags) String() string

type Object

type Object struct {
	Node3DBase
	Mesh    MeshName `desc:"name of the mesh shape information used for rendering this object -- all meshes are collected on the Scene"`
	Mat     Material `desc:"material properties of the surface (color, shininess, texture, etc)"`
	MeshPtr Mesh     `view:"-" desc:"cached pointer to mesh"`
}

Object represents an individual 3D object or object element. It has its own unique spatial transforms and material properties, and points to a mesh structure.

func AddNewObject

func AddNewObject(sc *Scene, parent ki.Ki, name string, meshName string) *Object

AddNewObject adds a new object of given name and mesh to given parent

func (*Object) AsObject

func (obj *Object) AsObject() *Object

func (*Object) Defaults

func (obj *Object) Defaults()

Defaults sets default initial settings for object params -- important to call this before setting specific values, as the initial zero values for some parameters are degenerate

func (*Object) Init3D

func (obj *Object) Init3D(sc *Scene)

func (*Object) IsObject

func (obj *Object) IsObject() bool

func (*Object) IsTransparent

func (obj *Object) IsTransparent() bool

func (*Object) IsVisible

func (obj *Object) IsVisible() bool

func (*Object) Render3D

func (obj *Object) Render3D(sc *Scene, rc RenderClasses, rnd Render)

Render3D activates this object for rendering ()

func (*Object) RenderClass

func (obj *Object) RenderClass() RenderClasses

RenderClass returns the class of rendering for this object used for organizing the ordering of rendering

func (*Object) SetMesh

func (obj *Object) SetMesh(sc *Scene, ms Mesh)

SetMesh sets mesh

func (*Object) SetMeshName

func (obj *Object) SetMeshName(sc *Scene, meshName string) error

SetMeshName sets mesh to given mesh name.

func (*Object) UpdateMeshBBox added in v0.9.9

func (obj *Object) UpdateMeshBBox()

UpdateMeshBBox updates the Mesh-based BBox info for all nodes. groups aggregate over elements

func (*Object) Validate

func (obj *Object) Validate(sc *Scene) error

Validate checks that object has valid mesh and texture settings, etc

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

func AddNewPlane(sc *Scene, name string, width, height float32) *Plane

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.

func (*Plane) Make

func (pl *Plane) Make(sc *Scene)

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.

func (*PointLight) ViewPos

func (pl *PointLight) ViewPos(viewMat *mat32.Mat4) mat32.Vec3

ViewPos gets the position vector, pre-computing the view transform

type Pose

type Pose struct {
	Pos         mat32.Vec3 `desc:"position of center of object"`
	Scale       mat32.Vec3 `desc:"scale (relative to parent)"`
	Quat        mat32.Quat `desc:"Node rotation specified as a Quat (relative to parent)"`
	Matrix      mat32.Mat4 `view:"-" desc:"Local matrix. Contains all position/rotation/scale information (relative to parent)"`
	ParMatrix   mat32.Mat4 `view:"-" desc:"Parent's world matrix -- we cache this so that we can independently update our own matrix"`
	WorldMatrix mat32.Mat4 `` /* 143-byte string literal not displayed */
	MVMatrix    mat32.Mat4 `view:"-" desc:"model * view matrix -- tranforms into camera-centered coords"`
	MVPMatrix   mat32.Mat4 `view:"-" desc:"model * view * projection matrix -- full final render matrix"`
	NormMatrix  mat32.Mat3 `view:"-" desc:"normal matrix based on MVMatrix"`
}

Pose contains the full specification of a given object's position and orientation

func (*Pose) CopyFrom

func (ps *Pose) CopyFrom(op *Pose)

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

func (ps *Pose) EulerRotation() mat32.Vec3

EulerRotation returns the current rotation in Euler angles (degrees).

func (*Pose) EulerRotationRad

func (ps *Pose) EulerRotationRad() mat32.Vec3

EulerRotationRad returns the current rotation in Euler angles (radians).

func (*Pose) GenGoSet added in v0.9.9

func (ps *Pose) GenGoSet(path string) string

GenGoSet returns code to set values in object at given path (var.member etc)

func (*Pose) LookAt

func (ps *Pose) LookAt(target, upDir mat32.Vec3)

LookAt points the object at given target location using given up direction.

func (*Pose) MoveOnAxis

func (ps *Pose) MoveOnAxis(x, y, z, dist float32)

MoveOnAxis moves (translates) the specified distance on the specified local axis, relative to the current rotation orientation.

func (*Pose) MoveOnAxisAbs

func (ps *Pose) MoveOnAxisAbs(x, y, z, dist float32)

MoveOnAxisAbs moves (translates) the specified distance on the specified local axis, in absolute X,Y,Z coordinates.

func (*Pose) RotateEuler

func (ps *Pose) RotateEuler(x, y, z float32)

RotateEuler rotates by given Euler angles (in degrees) relative to existing rotation.

func (*Pose) RotateEulerRad

func (ps *Pose) RotateEulerRad(x, y, z, angle float32)

RotateEulerRad rotates by given Euler angles (in radians) relative to existing rotation.

func (*Pose) RotateOnAxis

func (ps *Pose) RotateOnAxis(x, y, z, angle float32)

RotateOnAxis rotates around the specified local axis the specified angle in degrees.

func (*Pose) RotateOnAxisRad

func (ps *Pose) RotateOnAxisRad(x, y, z, angle float32)

RotateOnAxisRad rotates around the specified local axis the specified angle in radians.

func (*Pose) SetAxisRotation

func (ps *Pose) SetAxisRotation(x, y, z, angle float32)

SetAxisRotation sets rotation from local axis and angle in degrees.

func (*Pose) SetAxisRotationRad

func (ps *Pose) SetAxisRotationRad(x, y, z, angle float32)

SetAxisRotationRad sets rotation from local axis and angle in radians.

func (*Pose) SetEulerRotation

func (ps *Pose) SetEulerRotation(x, y, z float32)

SetEulerRotation sets the rotation in Euler angles (degrees).

func (*Pose) SetEulerRotationRad

func (ps *Pose) SetEulerRotationRad(x, y, z float32)

SetEulerRotationRad sets the rotation in Euler angles (radians).

func (*Pose) SetMatrix

func (ps *Pose) SetMatrix(m *mat32.Mat4)

SetMatrix sets the local transformation matrix and updates Pos, Scale, Quat.

func (*Pose) UpdateMVPMatrix

func (ps *Pose) UpdateMVPMatrix(viewMat, prjnMat *mat32.Mat4)

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

func (ps *Pose) UpdateWorldMatrix(parWorld *mat32.Mat4)

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

func (ps *Pose) WorldEulerRotation() mat32.Vec3

WorldEulerRotation returns the current world rotation in Euler angles.

func (*Pose) WorldPos

func (ps *Pose) WorldPos() mat32.Vec3

WorldPos returns the current world position.

func (*Pose) WorldQuat

func (ps *Pose) WorldQuat() mat32.Quat

WorldQuat returns the current world quaternion.

func (*Pose) WorldScale

func (ps *Pose) WorldScale() mat32.Vec3

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

type RenderBase struct {
	Nm   string
	Pipe gpu.Pipeline
}

Base render type

func (*RenderBase) Activate

func (rb *RenderBase) Activate(rn *Renderers)

func (*RenderBase) Compile

func (rb *RenderBase) Compile(rn *Renderers) error

func (*RenderBase) Delete

func (rb *RenderBase) Delete(rn *Renderers)

func (*RenderBase) Name

func (rb *RenderBase) Name() string

func (*RenderBase) Pipeline

func (rb *RenderBase) Pipeline() gpu.Pipeline

func (*RenderBase) VtxFragProg

func (rb *RenderBase) VtxFragProg() gpu.Program

type RenderClasses

type RenderClasses int32

RenderClasses define the different classes of rendering

const (
	RClassNone RenderClasses = iota
	RClassOpaqueUniform
	RClassOpaqueVertex
	RClassOpaqueTexture
	RClassTransUniform
	RClassTransVertex
	RClassTransTexture
	RenderClassesN
)

type RenderInputs

type RenderInputs int32

RenderInputs define the locations of the Vectors inputs to the rendering programs All Vectors must use these locations so that Mesh data does not depend on which program is being used to render it.

const (
	InVtxPos RenderInputs = iota
	InVtxNorm
	InVtxTex
	InVtxColor
	RenderInputsN
)

type RenderTexture

type RenderTexture struct {
	RenderBase
}

RenderTexture renders a texture material.

func (*RenderTexture) Init

func (rb *RenderTexture) Init(rn *Renderers) error

func (*RenderTexture) SetMat

func (rb *RenderTexture) SetMat(mat *Material, sc *Scene) error

type RenderUniformColor

type RenderUniformColor struct {
	RenderBase
}

RenderUniformColor renders a material with one color for entire object. This uses the standard Phong color model, with color computed in the fragment shader (more accurate, more expensive).

func (*RenderUniformColor) Init

func (rb *RenderUniformColor) Init(rn *Renderers) error

func (*RenderUniformColor) SetMat

func (rb *RenderUniformColor) SetMat(mat *Material, sc *Scene) 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

func (*RenderVertexColor) SetMat

func (rb *RenderVertexColor) SetMat(mat *Material, sc *Scene) 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

func (rn *Renderers) AddNewRender(rb Render, errs *[]error)

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

func (rn *Renderers) Init(sc *Scene) (bool, error)

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 (rn *Renderers) InitRenders() error

func (*Renderers) InitUnis

func (rn *Renderers) InitUnis() error

func (*Renderers) InitVectors

func (rn *Renderers) InitVectors()

func (*Renderers) SetLights

func (rn *Renderers) SetLights(sc *Scene)

SetLights sets the lights and recompiles the programs accordingly Must be called with proper context activated

func (*Renderers) SetLightsUnis

func (rn *Renderers) SetLightsUnis(sc *Scene)

SetLightsUnis sets the lights and recompiles the programs accordingly Must be called with proper context activated, on main thread

func (*Renderers) SetMatrix

func (rn *Renderers) SetMatrix(pose *Pose)

SetMatrix sets the view etc matrix uniforms Must be called with appropriate context (window) activated and already on main.

type Scene

type Scene struct {
	gi.WidgetBase
	Geom          gi.Geom2DInt       `desc:"Viewport-level viewbox within any parent Viewport2D"`
	Camera        Camera             `desc:"camera determines view onto scene"`
	BgColor       gi.Color           `desc:"background color"`
	Lights        map[string]Light   `desc:"all lights used in the scene"`
	Meshes        map[string]Mesh    `desc:"all meshes used in the scene"`
	Textures      map[string]Texture `desc:"all textures used in the scene"`
	NoNav         bool               `desc:"don't activate the standard navigation keyboard and mouse event processing to move around the camera in the scene"`
	SavedCams     map[string]Camera  `desc:"saved cameras -- can Save and Set these to view the scene from different angles"`
	Win           *gi.Window         `copy:"-" json:"-" xml:"-" desc:"our parent window that we render into"`
	Renders       Renderers          `view:"-" desc:"rendering programs"`
	Frame         gpu.Framebuffer    `view:"-" desc:"direct render target for scene"`
	Tex           gpu.Texture2D      `view:"-" desc:"the texture that the framebuffer returns, which should be rendered into the window"`
	SetDragCursor bool               `view:"-" desc:"has dragging cursor been set yet?"`
}

Scene is the overall scenegraph containing nodes as children. It renders to its own Framebuffer, the Texture of which is then drawn directly onto the window WinTex using the DirectWinUpload protocol.

There is default navigation event processing (disabled by setting NoNav) where mouse drag events Orbit the camera (Shift = Pan, Alt = PanTarget) and arrow keys do Orbit, Pan, PanTarget with same key modifiers. Spacebar restores original "default" camera, and numbers save (1st time) or restore (subsequently) camera views (Control = always save)

A Group at the top-level named "TrackCamera" will automatically track the camera (i.e., its Pose is copied) -- Objects in that group can set their relative Pos etc to display relative to the camera, to achieve "first person" effects.

func AddNewScene

func AddNewScene(parent ki.Ki, name string) *Scene

AddNewScene adds a new scene to given parent node, with given name.

func (*Scene) ActivateFrame

func (sc *Scene) ActivateFrame() bool

ActivateFrame creates (if necc) and activates framebuffer for GPU rendering context returns false if not possible

func (*Scene) ActivateOffFrame added in v0.9.9

func (sc *Scene) ActivateOffFrame(frame *gpu.Framebuffer, name string, size image.Point, msamp int) bool

ActivateOffFrame creates (if necc) and activates given offscreen framebuffer for GPU rendering context, of given size, and multisampling number (4 = default for good antialiasing, 0 if not hardware accelerated). returns false if not possible

func (*Scene) ActivateWin

func (sc *Scene) ActivateWin() bool

ActivateWin activates the window context for GPU rendering context (on the main thread -- all GPU rendering actions must be performed on main thread) returns false if not possible (i.e., Win nil, not visible)

func (*Scene) AddLight

func (sc *Scene) AddLight(lt Light)

AddLight adds given light to lights see AddNewX for convenience methods to add specific lights

func (*Scene) AddMesh

func (sc *Scene) AddMesh(ms Mesh)

AddMesh adds given mesh to mesh collection see AddNewX for convenience methods to add specific shapes

func (*Scene) AddTexture

func (sc *Scene) AddTexture(tx Texture)

AddTexture adds given texture to texture collection see AddNewTextureFile to add a texture that loads from file

func (*Scene) BBox2D

func (sc *Scene) BBox2D() image.Rectangle

func (*Scene) ChildrenBBox2D

func (sc *Scene) ChildrenBBox2D() image.Rectangle

func (*Scene) ComputeBBox2D

func (sc *Scene) ComputeBBox2D(parBBox image.Rectangle, delta image.Point)

func (*Scene) Defaults

func (sc *Scene) Defaults()

Defaults sets default scene params (camera, bg = white)

func (*Scene) DeleteResources

func (sc *Scene) DeleteResources()

DeleteResources deletes all GPU resources -- sets context and runs on main this is called during Disconnect and before the window is closed

func (*Scene) DeleteUnusedMeshes

func (sc *Scene) DeleteUnusedMeshes()

DeleteUnusedMeshes deletes all unused meshes

func (*Scene) DirectWinUpload

func (sc *Scene) DirectWinUpload() bool

func (*Scene) Disconnect

func (sc *Scene) Disconnect()

func (*Scene) Init2D

func (sc *Scene) Init2D()

func (*Scene) Init3D

func (sc *Scene) Init3D()

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

func (sc *Scene) InitMeshesInCtxt() bool

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

func (sc *Scene) InitTextures() bool

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

func (sc *Scene) InitTexturesInCtxt() bool

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 (sc *Scene) IsDirectWinUpload() bool

func (*Scene) IsVisible

func (sc *Scene) IsVisible() bool

func (*Scene) Layout2D

func (sc *Scene) Layout2D(parBBox image.Rectangle, iter int) bool

func (*Scene) MeshByName added in v0.9.9

func (sc *Scene) MeshByName(nm string) Mesh

MeshByName looks for mesh by name -- returns nil if not found

func (*Scene) MeshByNameTry added in v0.9.9

func (sc *Scene) MeshByNameTry(nm string) (Mesh, error)

MeshByNameTry looks for mesh by name -- returns error if not found

func (*Scene) MeshList

func (sc *Scene) MeshList() []string

MeshList returns a list of available meshes (e.g., for chooser)

func (*Scene) Move2D

func (sc *Scene) Move2D(delta image.Point, parBBox image.Rectangle)

func (*Scene) NavEvents

func (sc *Scene) NavEvents()

NavEvents handles standard viewer navigation events

func (*Scene) NavKeyEvents

func (sc *Scene) NavKeyEvents(kt *key.ChordEvent)

NavKeyEvents handles standard viewer keyboard navigation events

func (*Scene) ObjsIntersectingPoint added in v0.9.9

func (sc *Scene) ObjsIntersectingPoint(pos image.Point) []Node3D

ObjsIntersectingPoint finds all the objects that contain given 2D window coordinate

func (*Scene) PopBounds

func (sc *Scene) PopBounds()

func (*Scene) PushBounds

func (sc *Scene) PushBounds() bool

we use our own render for these -- Viewport member is our parent!

func (*Scene) Render

func (sc *Scene) Render() bool

Render renders the scene to the Frame framebuffer

func (*Scene) Render2D

func (sc *Scene) Render2D()

func (*Scene) Render3D

func (sc *Scene) Render3D()

Render3D renders the scene to the framebuffer all scene-level resources must be initialized and activated at this point

func (*Scene) RenderOffFrame added in v0.9.9

func (sc *Scene) RenderOffFrame() bool

RenderOffFrame renders the scene to currently-activated offscreen framebuffer must call ActivateOffFrame first and call Frame.Rendered() after!

func (*Scene) Resize

func (sc *Scene) Resize(nwsz image.Point)

func (*Scene) SaveCamera

func (sc *Scene) SaveCamera(name string)

SaveCamera saves the current camera with given name -- can be restored later with SetCamera. "default" is a special name that is automatically saved on first render, and restored with the spacebar under default NavEvents. Numbered cameras 0-9 also saved / restored with corresponding keys.

func (*Scene) SetCamera

func (sc *Scene) SetCamera(name string) error

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) Size2D

func (sc *Scene) Size2D(iter int)

func (*Scene) Style2D

func (sc *Scene) Style2D()

func (*Scene) Text2DPlaneMesh

func (sc *Scene) Text2DPlaneMesh() Mesh

Text2DPlaneMesh returns the special Text2DPLane mesh (creating it if it does not yet exist). This is a 1x1 plane with a normal pointing in positive Z direction used for all Text2D rendering

func (*Scene) TextureList

func (sc *Scene) TextureList() []string

TextureList returns a list of available textures (e.g., for chooser)

func (*Scene) TrackCamera

func (sc *Scene) TrackCamera() bool

TrackCamera -- a Group at the top-level named "TrackCamera" will automatically track the camera (i.e., its Pose is copied). Objects in that group can set their relative Pos etc to display relative to the camera, to achieve "first person" effects.

func (*Scene) UpdateMVPMatrix added in v0.9.9

func (sc *Scene) UpdateMVPMatrix()

UpdateMVPMatrix updates the Model-View-Projection matrix for all scene elements and BBox2D

func (*Scene) UpdateMeshBBox added in v0.9.9

func (sc *Scene) UpdateMeshBBox()

UpdateMeshBBox updates the Mesh-based BBox info for all nodes. groups aggregate over elements

func (*Scene) UpdateMeshes

func (sc *Scene) UpdateMeshes()

UpdateMeshes calls Update on all meshes This version us to be used by external users -- sets context and runs on main

func (*Scene) UpdateMeshesInCtxt

func (sc *Scene) UpdateMeshesInCtxt() bool

UpdateMeshesInCtxt calls Update on all the meshes in context on main thread Update is responsible for doing any transfers

func (*Scene) UpdateWorldMatrix

func (sc *Scene) UpdateWorldMatrix()

UpdateWorldMatrix updates the world matrix for all scene elements called during Init3D and rendering

func (*Scene) Validate

func (sc *Scene) Validate() error

Validate traverses the scene and validates all the elements -- errors are logged and a non-nil return indicates that at least one error was found.

type SceneView added in v0.9.9

type SceneView struct {
	gi.Layout
}

SceneView provides a toolbar controller for a gi3d.Scene

func AddNewSceneView added in v0.9.9

func AddNewSceneView(parent ki.Ki, name string) *SceneView

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

func (sv *SceneView) IsConfiged() bool

IsConfiged returns true if widget is fully configured

func (*SceneView) Scene added in v0.9.9

func (sv *SceneView) Scene() *Scene

func (*SceneView) Toolbar added in v0.9.9

func (sv *SceneView) Toolbar() *gi.ToolBar

func (*SceneView) ToolbarConfig added in v0.9.9

func (sv *SceneView) ToolbarConfig()

type SpotLight

type SpotLight struct {
	LightBase
	Pose        Pose    // position and orientation
	AngDecay    float32 `desc:"Angular decay factor -- defaults to 15"`
	CutoffAngle float32 `max:"90" min:"1" desc:"Cut off angle (in degrees) -- defaults to 45 -- max of 90"`
	LinDecay    float32 `desc:"Distance linear decay factor -- defaults to 1"`
	QuadDecay   float32 `desc:"Distance quadratic decay factor -- defaults to 1"`
}

Spotlight is a light with a position and direction and associated decay factors and angles. which divide the light intensity as a function of linear and quadratic distance. The quadratic factor dominates at longer distances.

func AddNewSpotLight

func AddNewSpotLight(sc *Scene, name string, lumens float32, color LightColors) *SpotLight

AddNewSpotLight adds spot light to given scene, with given name, standard color, and lumens (0-1 normalized) By default it is located at 0,5,5 (up and between default camera and origin) and pointing at the origin. Use the Pose LookAt function to point it at other locations. In its unrotated state, it points down the -Z axis (i.e., into the scene using default view parameters)

func (*SpotLight) LookAt

func (sl *SpotLight) LookAt(target, upDir mat32.Vec3)

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)

func (*SpotLight) ViewDir

func (sl *SpotLight) ViewDir(viewMat *mat32.Mat4) mat32.Vec3

ViewDir gets the direction normal vector, pre-computing the view transform

func (*SpotLight) ViewPos

func (sl *SpotLight) ViewPos(viewMat *mat32.Mat4) mat32.Vec3

ViewPos gets the position of the light, pre-computing the view transform

type TexName

type TexName string

TexName provides a GUI interface for choosing textures

type Text2D

type Text2D struct {
	Object
	Text        string         `desc:"the text string to display"`
	Sty         gi.Style       `json:"-" xml:"-" desc:"styling settings for the text"`
	TxtPos      gi.Vec2D       `xml:"-" json:"-" desc:"position offset of start of text rendering relative to upper-left corner"`
	TxtRender   gi.TextRender  `view:"-" xml:"-" json:"-" desc:"render data for text label"`
	TxtTex      *TextureBase   `` /* 136-byte string literal not displayed */
	RenderState gi.RenderState `copy:"-" json:"-" xml:"-" view:"-" desc:"render state for rendering text"`
}

Text2D presents 2D rendered text on a vertically-oriented plane, using a texture. Call SetText() which calls RenderText to update fortext changes (re-renders texture). The native scale is such that a unit height value is the height of the default font set by the font-size property, and the X axis is scaled proportionally based on the rendered text size to maintain the aspect ratio. Further scaling can be applied on top of that by setting the Pose.Scale values as usual. Standard styling properties can be set on the node to set font size, family, and text alignment relative to the Pose.Pos position (e.g., Left, Top puts the upper-left corner of text at Pos). Note that higher quality is achieved by using a larger font size (36 default). The margin property creates blank margin of the background color around the text (2 px default) and the background-color defaults to transparent but can be set to any color.

func AddNewText2D

func AddNewText2D(sc *Scene, parent ki.Ki, name string, text string) *Text2D

AddNewText2D adds a new object of given name and text string to given parent

func (*Text2D) Defaults

func (txt *Text2D) Defaults(sc *Scene)

func (*Text2D) Disconnect

func (txt *Text2D) Disconnect()

func (*Text2D) Init3D

func (txt *Text2D) Init3D(sc *Scene)

func (*Text2D) IsTransparent

func (txt *Text2D) IsTransparent() bool

func (*Text2D) RenderClass

func (txt *Text2D) RenderClass() RenderClasses

func (*Text2D) RenderText

func (txt *Text2D) RenderText(sc *Scene)

func (*Text2D) SetText

func (txt *Text2D) SetText(sc *Scene, str string)

SetText sets the text and renders it to the texture image

func (*Text2D) StyleText

func (txt *Text2D) StyleText(sc *Scene)

StyleText does basic 2D styling

func (*Text2D) TextSize

func (txt *Text2D) TextSize() (mat32.Vec2, bool)

TextSize returns the size of the text plane, applying all *local* scaling factors if nothing rendered yet, returns false

func (*Text2D) UpdateWorldMatrix

func (txt *Text2D) UpdateWorldMatrix(parWorld *mat32.Mat4)

func (*Text2D) Validate

func (txt *Text2D) Validate(sc *Scene) error

Validate checks that object has valid mesh and texture settings, etc

type Texture

type Texture interface {
	// Name returns name of the texture
	Name() string

	// Init initializes the texture and uploads it to the GPU, so it is ready to use
	// Must be called in context on main thread
	Init(sc *Scene) error

	// Activate activates this texture on the GPU, at given texture number.
	// in preparation for rendering
	// Must be called in context on main thread
	Activate(sc *Scene, texNo int)

	// Delete deletes the texture GPU resources -- must be called in context on main thread
	Delete(sc *Scene)

	// BotZero returns true if this texture has the Y=0 pixels at the bottom
	// of the image.  Otherwise, Y=0 is at the top, which is the default
	// for most images loaded from files.
	BotZero() bool

	// SetBotZero sets whether this texture has the Y=0 pixels at the bottom
	// of the image.  Otherwise, Y=0 is at the top, which is the default
	// for most images loaded from files.
	SetBotZero(botzero bool)

	// IsTransparent returns true if there is any transparency present in the texture
	// This is not auto-detected but rather must be set manually.
	// It affects the rendering order -- transparent items are rendered last.
	IsTransparent() bool

	// SetTransparent sets the transparency flag for this texture.
	SetTransparent(trans bool)
}

type TextureBase

type TextureBase struct {
	Nm    string        `desc:"name of the texture -- textures are connected to material / objects by name"`
	Bot0  bool          `` /* 146-byte string literal not displayed */
	Trans bool          `desc:"set to true if texture has transparency"`
	Tex   gpu.Texture2D `view:"-" desc:"gpu texture object"`
}

TextureBase is the base texture implementation

func (*TextureBase) Activate

func (tx *TextureBase) Activate(sc *Scene, texNo int)

Activate activates this texture on the GPU, in preparation for rendering Must be called in context on main thread

func (*TextureBase) BotZero

func (tx *TextureBase) BotZero() bool

func (*TextureBase) Delete

func (tx *TextureBase) Delete(sc *Scene)

Delete deletes the texture GPU resources -- must be called in context on main thread

func (*TextureBase) Init

func (tx *TextureBase) Init(sc *Scene) error

Init initializes the texture and activates it -- for base case it must be set externally prior to this call. Must be called in context on main thread

func (*TextureBase) IsTransparent

func (tx *TextureBase) IsTransparent() bool

func (*TextureBase) Name

func (tx *TextureBase) Name() string

func (*TextureBase) NewTex

func (tx *TextureBase) NewTex() gpu.Texture2D

makes a new gpu.Texture2D if Tex field is nil, and returns it in any case

func (*TextureBase) SetBotZero

func (tx *TextureBase) SetBotZero(botzero bool)

func (*TextureBase) SetTransparent

func (tx *TextureBase) SetTransparent(trans bool)

type TextureFile

type TextureFile struct {
	TextureBase
	File gi.FileName `desc:"filename for the texture"`
}

TextureFile is a texture loaded from a file

func AddNewTextureFile

func AddNewTextureFile(sc *Scene, name string, filename string) *TextureFile

AddNewTextureFile adds a new texture from file of given name and filename

func (*TextureFile) Activate

func (tx *TextureFile) Activate(sc *Scene, texNo int)

Activate activates this texture on the GPU, in preparation for rendering Must be called in context on main thread

func (*TextureFile) Init

func (tx *TextureFile) Init(sc *Scene) error

Init initializes the texture, opens the file, and uploads it to the GPU Must be called in context on main thread

type TextureGi2D

type TextureGi2D struct {
	TextureBase
	Viewport *gi.Viewport2D
}

TextureGi2D is a dynamic texture material driven by a gi.Viewport2D viewport anything rendered to the viewport will be projected onto the surface of any object using this texture.

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

func (*Tiling) Defaults

func (tl *Tiling) Defaults()

Defaults sets default tiling params if not yet initialized

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL