gi3d

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: BSD-3-Clause Imports: 29 Imported by: 11

README

Gi3D

gi3d is the package for the 3D scenegraph in GoGi.

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 Lines (rendered as thin boxes 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).

See EVE (emergent Virtual Engine) for a physics engine built on top of gi3d.

Scenegraph Structure

  • Scene is the root node of the 3D scenegraph.

    • Camera is a field on the Scene that has all the current camera settings. By default the camera does a naturalistic Perspective projection, but you can enable Orthographic by ticking the Ortho button -- you will generally need to reduce the Far plane value to be able to see anything -- the Ortho projection shows you the entire scene within those two planes, and it scales accordingly to be able to fit everything.

    • Lights contain the lighting parameters for the scene -- if you don't have any lights, everything will be dark!

      • Ambient lights contribute generic lighting to every surface uniformly -- usually have this at a low level to represent scattered light that has bounced around everywhere.
      • Dir ectional lights represent a distant light-source like the sun, with effectively parallel rays -- the position of the light determines its direction by pointing back from there to the origin -- think of it as the location of the sun. Only the normal direction value is used so the magnitude of the values doesn't matter.
      • Point lights have a specific position and radiate light uniformly in all directions from that point, with both a linear and quadratic decay term.
      • Spot lights are the most sophisticated lights, with both a position and direction, and an angular cutoff so light only spreads out in a cone, with appropriate decay factors.
    • Meshes are the library of Mesh shapes that can be used in the scene. These provide the triangle-based surfaces used to define shapes. The shape.go code provides the basic geometric primitives such as Box, Sphere, Cylinder, etc, and you can load mesh shapes from standard .obj files as exported by almost all 3D rendering programs. You can also write code to generate your own custom / dynamic shapes, as we do with the NetView in the emergent neural network simulation system.

    • Textures are the library of Texture files that define more complex colored surfaces for objects. These can be loaded from standard image files.

    • Solids are the Children of the Scene, and actually determine the content of the 3D scene. Each Solid has a Mesh field with the name of the mesh that defines its shape, and a Mat field that determines its material properties (Color, Texture, etc). In addition, each Solid has its own Pose field that determines its position, scale and orientation within the scene. Because each Solid is a ki.Ki tree node, it can contain other scene elements as its Children -- they will inherit the Pose settings of the parent (and so-on up the tree -- all poses are cumulative) but not automatically any material settings. You can call CopyMatToChildren if you want to apply the current materials to the children nodes. And use Style parameters to set these according to node name or Class name.

    • Groups can be used to apply Pose settings to a set of Children that are all grouped together (e.g., a multi-part complex object can be moved together etc by putting a set of Solids into a Group)

Events, Selection, Manipulation

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.

Embedded 2D Viewport

A full 2D GUI can be embedded within a 3D scene using the Embed2D Node type, which renders a Viewport2D onto a Texture projected onto a Plane. It captures events within its own bounding box, and translates them into coordinates for the 2D embedded gui. This allows full 2D interactive control within whatever perspective is presentin the 3D scene. However, things like cursors and popups render in the flat 2D screen and are only approximately located.

In addition to interactive guis, the embedded 2D node can be used for rendering full SVG graphics to a texture.

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

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

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 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.

View Source
var Embed2DProps = ki.Props{
	"EnumType:Flag": gi.KiT_NodeFlags,
}
View Source
var EmbedViewportProps = ki.Props{
	"EnumType:Flag":    gi.KiT_VpFlags,
	"color":            &gi.Prefs.Colors.Font,
	"background-color": &gi.Prefs.Colors.Background,
}
View Source
var GroupProps = ki.Props{
	"EnumType:Flag": gi.KiT_NodeFlags,
}
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_Capsule = kit.Types.AddType(&Capsule{}, nil)
View Source
var KiT_Cylinder = kit.Types.AddType(&Cylinder{}, nil)
View Source
var KiT_DirLight = kit.Types.AddType(&DirLight{}, nil)
View Source
var KiT_Embed2D = kit.Types.AddType(&Embed2D{}, Embed2DProps)
View Source
var KiT_EmbedViewport = kit.Types.AddType(&EmbedViewport{}, EmbedViewportProps)
View Source
var KiT_GenMesh = kit.Types.AddType(&GenMesh{}, nil)
View Source
var KiT_Group = kit.Types.AddType(&Group{}, GroupProps)
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_Lines = kit.Types.AddType(&Lines{}, nil)
View Source
var KiT_ManipPt = kit.Types.AddType(&ManipPt{}, ManipPtProps)
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_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_SceneFlags = kit.Enums.AddEnumExt(gi.KiT_NodeFlags, SceneFlagsN, kit.BitFlag, nil)
View Source
var KiT_SceneView = kit.Types.AddType(&SceneView{}, nil)
View Source
var KiT_SelModes = kit.Enums.AddEnum(SelModesN, kit.NotBitFlag, nil)
View Source
var KiT_Solid = kit.Types.AddType(&Solid{}, SolidProps)
View Source
var KiT_Sphere = kit.Types.AddType(&Sphere{}, nil)
View Source
var KiT_SpotLight = kit.Types.AddType(&SpotLight{}, nil)
View Source
var KiT_Text2D = kit.Types.AddType(&Text2D{}, Text2DProps)
View Source
var KiT_TextureBase = kit.Types.AddType(&TextureBase{}, nil)
View Source
var KiT_TextureFile = kit.Types.AddType(&TextureFile{}, nil)
View Source
var KiT_Torus = kit.Types.AddType(&Torus{}, nil)
View Source
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

View Source
var ManipPtProps = ki.Props{
	"EnumType:Flag": gi.KiT_NodeFlags,
}
View Source
var Node3DBaseProps = ki.Props{
	"base-type":     true,
	"EnumType:Flag": KiT_NodeFlags,
}
View Source
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

View Source
var RenderPhong = `` /* 3765-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": KiT_SceneFlags,
	"ToolBar": ki.PropSlice{
		{"Update", ki.Props{
			"icon": "update",
		}},
	},
}

SceneProps define the ToolBar and MenuBar for StructView

View Source
var SolidProps = ki.Props{
	"EnumType:Flag": gi.KiT_NodeFlags,
}
View Source
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

View Source
var Text2DProps = ki.Props{
	"EnumType:Flag": gi.KiT_NodeFlags,
}
View Source
var Update3DTrace = false

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

Functions

func AddNewLineBoxMeshes added in v0.9.11

func AddNewLineBoxMeshes(sc *Scene, meshNm string, bbox mat32.Box3, width float32)

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

func ColorToVec3f(clr gist.Color) mat32.Vec3

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

func ColorToVec4f

func ColorToVec4f(clr gist.Color) mat32.Vec4

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

func InitMesh added in v0.9.11

func InitMesh(ms Mesh, sc *Scene)

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 MiterPts added in v0.9.11

func MiterPts(ax, ay, bx, by, cx, cy, w2 float32) mat32.Vec2

func SetLineStartEnd added in v1.0.0

func SetLineStartEnd(ln *Solid, st, ed mat32.Vec3)

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

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

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

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)

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 */
	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) 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 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) ViewMainAxis added in v0.9.11

func (cm *Camera) ViewMainAxis() (dim mat32.Dims, sign float32)

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

func (cm *Camera) ViewVector() mat32.Vec3

ViewVector is the vector between the camera position and target

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

func AddNewCapsule(sc *Scene, name string, height, radius float32, segs, heightSegs int) *Capsule

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.

func (*Capsule) Make added in v0.9.11

func (cp *Capsule) Make(sc *Scene)

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

func UnitConeMesh(sc *Scene, segs int) *Cylinder

UnitConeMesh returns the unit-sized cone mesh, of name ConeMeshName-segs

func (*Cylinder) Make added in v0.9.11

func (cy *Cylinder) Make(sc *Scene)

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

func DecodeFile(fname string) (Decoder, error)

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

func (*DirLight) ViewDir

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

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

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 (em *Embed2D) ConnectEvents3D(sc *Scene)

func (*Embed2D) Defaults added in v0.9.11

func (em *Embed2D) Defaults(sc *Scene)

func (*Embed2D) Disconnect added in v0.9.11

func (em *Embed2D) Disconnect()

func (*Embed2D) Init3D added in v0.9.11

func (em *Embed2D) Init3D(sc *Scene)

func (*Embed2D) Project2D added in v0.9.11

func (em *Embed2D) Project2D(sc *Scene, pt image.Point) (image.Point, bool)

func (*Embed2D) RenderClass added in v0.9.11

func (em *Embed2D) RenderClass() RenderClasses

func (*Embed2D) Resize added in v0.9.11

func (em *Embed2D) Resize(width, height int)

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

func (em *Embed2D) ResizeToFit() error

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 (em *Embed2D) UpdateBBox2D(size mat32.Vec2, sc *Scene)

func (*Embed2D) UpdateWorldMatrix added in v0.9.11

func (em *Embed2D) UpdateWorldMatrix(parWorld *mat32.Mat4)

func (*Embed2D) UploadViewTex added in v0.9.11

func (em *Embed2D) UploadViewTex(sc *Scene)

UploadViewTex uploads the viewport image to the texture

func (*Embed2D) Validate added in v0.9.11

func (em *Embed2D) Validate(sc *Scene) error

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

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

func (*GenMesh) Make added in v0.9.11

func (ms *GenMesh) Make(sc *Scene)

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

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

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

func (gp *Group) Defaults()

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

func (*LightBase) Color

func (lb *LightBase) Color() gist.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 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

func AddNewLines(sc *Scene, name string, points []mat32.Vec3, width mat32.Vec2, closed bool) *Lines

AddNewLines adds Lines mesh to given scene, with given start, end, and width

func UnitLineMesh added in v0.9.11

func UnitLineMesh(sc *Scene) *Lines

UnitLineMesh returns the unit-sized line mesh, of name LineMeshName

func (*Lines) Make added in v0.9.11

func (ln *Lines) Make(sc *Scene)

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

func (mpt *ManipPt) ConnectEvents3D(sc *Scene)

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

func (mt *Material) Defaults()

Defaults sets default surface parameters

func (*Material) Disconnect added in v1.0.11

func (mt *Material) Disconnect()

Disconnect resets pointers etc

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) SetMatProps added in v0.9.11

func (mt *Material) SetMatProps(par *Material, props ki.Props, vp *gi.Viewport2D)

SetMatProps sets Material values based on ki.Props properties

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) StyleCSS added in v0.9.11

func (mt *Material) StyleCSS(node Node3D, css ki.Props, selector string, vp *gi.Viewport2D)

StyleCSS applies css style properties to given node, parsing out type, .class, and #name selectors, along with optional sub-selector (:hover, :active etc)

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

	// 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

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

func (ms *MeshBase) AddLines(points []mat32.Vec3, width mat32.Vec2, closed bool, offset mat32.Vec3)

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

func (ms *MeshBase) AddQuad(vtxs []mat32.Vec3, texs []mat32.Vec2, clr gist.Color)

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

func (ms *MeshBase) AddTriangle(a, b, c mat32.Vec3, texs []mat32.Vec2, clr gist.Color)

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

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) HasTex added in v0.9.11

func (ms *MeshBase) HasTex() 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 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) SetName added in v0.9.11

func (ms *MeshBase) SetName(nm string)

func (*MeshBase) SetNormData

func (ms *MeshBase) SetNormData(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.

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

func (ms *MeshBase) SetVtxData(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.

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 Solid 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

	// 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

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

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

func StringToNodeFlags(s string) (NodeFlags, error)

func (NodeFlags) String added in v0.9.9

func (i NodeFlags) String() string

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

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 at given path (var.member etc)

func (*Pose) LookAt

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

LookAt points the element 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) MulMatrix added in v0.9.11

func (ps *Pose) MulMatrix(mat *mat32.Mat4)

MulMatrix multiplies current pose Matrix by given Matrix, and re-extracts the Pos, Scale, Quat from resulting matrix.

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

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

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       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"`
	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?"`
	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

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

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) AddFmLibrary added in v0.9.11

func (sc *Scene) AddFmLibrary(nm string, parent ki.Ki) (*Group, error)

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

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. 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

func (sc *Scene) AddMeshUnique(ms Mesh)

AddMeshUniqe adds given mesh to mesh collection, ensuring that it has a unique name if one already exists.

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) AddToLibrary added in v0.9.11

func (sc *Scene) AddToLibrary(gp *Group)

AddToLibrary adds given Group to library, using group's name as unique key in Library map.

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) DeleteMesh added in v0.9.11

func (sc *Scene) DeleteMesh(nm string) error

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

func (sc *Scene) DeleteTexture(nm string) error

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 (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) InitMesh added in v0.9.11

func (sc *Scene) InitMesh(nm string) error

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

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) IsRendering added in v1.2.0

func (sc *Scene) IsRendering() bool

func (*Scene) IsVisible

func (sc *Scene) IsVisible() bool

func (*Scene) Layout2D

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

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

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) NewInLibrary added in v0.9.11

func (sc *Scene) NewInLibrary(nm string) *Group

NewInLibrary makes a new Group in library, using given name as unique key in Library map.

func (*Scene) OpenNewObj added in v0.9.11

func (sc *Scene) OpenNewObj(fname string, parent ki.Ki) (*Group, error)

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

func (sc *Scene) OpenObj(fname string, gp *Group) error

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

func (sc *Scene) OpenScene(fname string) error

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

func (sc *Scene) OpenToLibrary(fname string, libnm string) (*Group, error)

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

func (sc *Scene) PlaneMesh2D() Mesh

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) 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) ReadObj added in v0.9.11

func (sc *Scene) ReadObj(fname string, rs []io.Reader, gp *Group) error

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

func (sc *Scene) ReadScene(fname string, rs []io.Reader, gp *Group) error

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) 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(offscreen bool)

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) SelectBox added in v0.9.11

func (sc *Scene) SelectBox()

SelectBox draws a selection box around selected node

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) SetManipPt added in v0.9.11

func (sc *Scene) SetManipPt(pt *ManipPt)

SetManipPt sets the CurManipPt

func (*Scene) SetSel added in v0.9.11

func (sc *Scene) SetSel(nd Node3D)

SetSel -- if Selectable is true, then given object is selected if node is nil then selection is reset.

func (*Scene) Size2D

func (sc *Scene) Size2D(iter int)

func (*Scene) SolidsIntersectingPoint added in v0.9.11

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

SolidsIntersectingPoint finds all the solids that contain given 2D window coordinate

func (*Scene) Style2D

func (sc *Scene) Style2D()

func (*Scene) Style3D added in v0.9.11

func (sc *Scene) Style3D()

func (*Scene) TextureByName added in v1.0.11

func (sc *Scene) TextureByName(nm string) Texture

TextureByName looks for texture by name -- returns nil if not found

func (*Scene) TextureByNameTry added in v1.0.11

func (sc *Scene) TextureByNameTry(nm string) (Texture, error)

TextureByNameTry looks for texture by name -- returns error if not found

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

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

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

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

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

func (SelModes) String added in v0.9.11

func (i SelModes) String() string

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

func (*SelParams) Defaults added in v0.9.11

func (sp *SelParams) Defaults()

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

func AddNewSolid(sc *Scene, parent ki.Ki, name string, meshName string) *Solid

AddNewSolid adds a new solid of given name and mesh to given parent

func (*Solid) AsSolid added in v0.9.11

func (sld *Solid) AsSolid() *Solid

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) Init3D added in v0.9.11

func (sld *Solid) Init3D(sc *Scene)

func (*Solid) IsSolid added in v0.9.11

func (sld *Solid) IsSolid() bool

func (*Solid) IsTransparent added in v0.9.11

func (sld *Solid) IsTransparent() bool

func (*Solid) IsVisible added in v0.9.11

func (sld *Solid) IsVisible() bool

func (*Solid) ParentMaterial added in v0.9.11

func (sld *Solid) ParentMaterial() *Material

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) SetMesh added in v0.9.11

func (sld *Solid) SetMesh(sc *Scene, ms Mesh)

SetMesh sets mesh

func (*Solid) SetMeshName added in v0.9.11

func (sld *Solid) SetMeshName(sc *Scene, meshName string) error

SetMeshName sets mesh to given mesh name.

func (*Solid) Style3D added in v0.9.11

func (sld *Solid) Style3D(sc *Scene)

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

func (*Solid) Validate added in v0.9.11

func (sld *Solid) Validate(sc *Scene) error

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

type SolidPoint added in v1.0.0

type SolidPoint struct {
	Solid *Solid
	Point mat32.Vec3
}

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

func AddNewSphere(sc *Scene, name string, radius float32, segs int) *Sphere

AddNewSphere creates a sphere mesh with the specified radius, number of segments (resolution).

func (*Sphere) Make added in v0.9.11

func (sp *Sphere) Make(sc *Scene)

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 {
	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

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

AddNewText2D adds a new text 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 text 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 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

func (*Tiling) Defaults

func (tl *Tiling) Defaults()

Defaults sets default tiling params if not yet initialized

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

func AddNewTorus(sc *Scene, name string, radius, tubeRadius float32, segs int) *Torus

AddNewTorus creates a sphere mesh with the specified outer ring radius, solid tube radius, and number of segments (resolution).

func (*Torus) Make added in v0.9.11

func (sp *Torus) Make(sc *Scene)

Directories

Path Synopsis
io
obj
Package obj is used to parse the Wavefront OBJ file format (*.obj), including associated materials (*.mtl).
Package obj is used to parse the Wavefront OBJ file format (*.obj), including associated materials (*.mtl).

Jump to

Keyboard shortcuts

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