vmodel

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VFUV      = VertexFlags(1)
	VFNormal  = VertexFlags(2)
	VFTangent = VertexFlags(4)
	VFWeights = VertexFlags(16)
)
View Source
const (
	Color               = Property(0x01000000)
	CAlbedo             = Color + 1
	CEmissive           = Color + 2
	CSpecular           = Color + 3
	Texture             = Property(0x02000000)
	TxAlbedo            = Texture + 1
	TxEmissive          = Texture + 2
	TxSpecular          = Texture + 3
	TxBump              = Texture + 4
	TxMetallicRoughness = Texture + 5
	Factor              = Property(0x03000000)
	FSpeculaPower       = Factor + 1
	FMetalness          = Factor + 2
	FRoughness          = Factor + 3
	// For decals to specify if normal difference from surface to decal will attenuate decal effect.
	// 0 - No attanuation, 1 - Full attenuation (factor = dot(normal, decalNormal))
	FNormalAttenuation = Factor + 4
	// Max level of alpha to discard pixel.
	FAlphaCutoff = Factor + 5
	Special      = Property(0xFF000000)
	SMaxIndex    = Special + 1
	PropertyKind = Property(0xFF000000)
)
View Source
const (
	MESHKindNormal  = MeshKind(0)
	MESHKindSkinned = MeshKind(1)
	MESHMax         = 2
)
View Source
const (
	TTranslation = ChannelTarget(1)
	TScale       = ChannelTarget(2)
	TRotation    = ChannelTarget(3)
)

Variables

This section is empty.

Functions

func AddInput

func AddInput(ctx vk.APIContext, gr *vk.GraphicsPipeline, kind MeshKind)

func DescribeWhiteImage

func DescribeWhiteImage(ctx vk.APIContext) (desc vk.ImageDescription)

func GetDefaultSampler

func GetDefaultSampler(ctx vk.APIContext, dev *vk.Device) *vk.Sampler

Types

type AABB

type AABB struct {
	Min mgl32.Vec3
	Max mgl32.Vec3
}

func (*AABB) Add

func (aabb *AABB) Add(first bool, vertex mgl32.Vec3)

func (AABB) Center

func (aabb AABB) Center() mgl32.Vec3

func (AABB) Len

func (aabb AABB) Len() float32

func (*AABB) Translate

func (aabb *AABB) Translate(tr mgl32.Mat4) AABB

type Animation

type Animation struct {
	Name     string
	Channels []Channel
}

type BoundShader added in v0.20.1

type BoundShader interface {
	Shader
	SetModel(model *Model)
}

type Channel

type Channel struct {
	Joint  int
	Input  []float32
	Output []float32
	Target ChannelTarget
}

type ChannelTarget

type ChannelTarget uint32

type Compute

type Compute struct {
	// contains filtered or unexported fields
}

func NewCompute

func NewCompute(ctx vk.APIContext, dev *vk.Device) *Compute

func (*Compute) Dispose

func (cp *Compute) Dispose()

func (*Compute) MipImage

func (cp *Compute) MipImage(img *vk.Image, layer uint32, mipTo uint32)

type Copier

type Copier struct {
	// contains filtered or unexported fields
}

func NewCopier

func NewCopier(ctx vk.APIContext, dev *vk.Device) *Copier

func (*Copier) CopyFromImage

func (c *Copier) CopyFromImage(src *vk.Image, imRange vk.ImageRange, kind string, finalLayout vk.ImageLayout) (content []byte)

func (*Copier) CopyToBuffer

func (c *Copier) CopyToBuffer(dst *vk.Buffer, content []byte)

func (*Copier) CopyToImage

func (c *Copier) CopyToImage(dst *vk.Image, kind string, content []byte, imRange vk.ImageRange, finalLayout vk.ImageLayout)

func (*Copier) CopyWhiteImage

func (c *Copier) CopyWhiteImage(dst *vk.Image)

func (*Copier) Dispose

func (c *Copier) Dispose()

func (*Copier) SetLayout

func (c *Copier) SetLayout(dst *vk.Image, imRange vk.ImageRange, finalLayout vk.ImageLayout)

type DrawContext

type DrawContext struct {
	Frame Frame
	Pass  vk.RenderPass
	List  *vk.DrawList
}

func (*DrawContext) Draw

func (dc *DrawContext) Draw(pl vk.Pipeline, from uint32, count uint32) *vk.DrawItem

func (*DrawContext) DrawIndexed

func (dc *DrawContext) DrawIndexed(pl vk.Pipeline, from uint32, count uint32) *vk.DrawItem

type Frame added in v0.20.1

type Frame interface {
	// Retrieve renderer associated to this frame
	GetRenderer() Renderer

	// Retrieve render cache assosiate to this render instance
	GetCache() *vk.RenderCache
}

type ImageBuilder

type ImageBuilder struct {
	Kind    string
	Content []byte
	Usage   vk.ImageUsageFlags
	Desc    vk.ImageDescription
	// contains filtered or unexported fields
}

type ImageIndex

type ImageIndex int

type Joint

type Joint struct {
	Translate     mgl32.Vec3
	Scale         mgl32.Vec3
	Rotate        mgl32.Quat
	InverseMatrix mgl32.Mat4
	Root          bool
	Children      []int
	Name          string
}

type Material

type Material struct {
	Props  MaterialProperties
	Shader Shader
	Name   string
}

type MaterialIndex

type MaterialIndex int

type MaterialInfo added in v0.20.1

type MaterialInfo struct {
	Props MaterialProperties
	Name  string
	Decal bool
	// contains filtered or unexported fields
}

type MaterialProperties

type MaterialProperties map[Property]interface{}

func NewMaterialProperties

func NewMaterialProperties() MaterialProperties

func (MaterialProperties) GetColor

func (mp MaterialProperties) GetColor(prop Property, defaultValue mgl32.Vec4) mgl32.Vec4

func (MaterialProperties) GetFactor

func (mp MaterialProperties) GetFactor(prop Property, defaultValue float32) float32

func (MaterialProperties) GetImage

func (mp MaterialProperties) GetImage(prop Property) ImageIndex

func (MaterialProperties) SetColor

func (mp MaterialProperties) SetColor(prop Property, val mgl32.Vec4) MaterialProperties

func (MaterialProperties) SetFactor

func (mp MaterialProperties) SetFactor(prop Property, val float32) MaterialProperties

func (MaterialProperties) SetImage

type Mesh

type Mesh struct {
	Kind  MeshKind
	AABB  AABB
	Model *Model
	From  uint32
	Count uint32
}

type MeshBuilder

type MeshBuilder struct {
	Vextexies []*VertexBuilder
	Incides   []uint32
	// contains filtered or unexported fields
}

MeshBuilder is used to construct one mesh. Mesh is then added to model builder

func (*MeshBuilder) AddCube

func (mb *MeshBuilder) AddCube(tr mgl32.Mat4)

AddCube will create simple unit cube (1x1x1) transformed with given transformation This method is used to make simple test models.

func (*MeshBuilder) AddIcosahedron

func (mb *MeshBuilder) AddIcosahedron(tr mgl32.Mat4)

AddIcosahedron adds simple unit icosahedron to mesh

func (*MeshBuilder) AddIndex

func (mb *MeshBuilder) AddIndex(points ...uint32) (index int)

Add indexes to vertexes. Mesh can be used without index information, in witch case each set of three vertexes will make one triagle. VGE don't support any other modes to combine vertexes. Use indexes if you wan't to reuse same vertex multiple times

func (*MeshBuilder) AddPlane

func (mb *MeshBuilder) AddPlane(tr mgl32.Mat4)

AddPlane adds one unit plane to to mesh

func (*MeshBuilder) AddVertex

func (mb *MeshBuilder) AddVertex(position mgl32.Vec3) *VertexBuilder

Add new vertex to mesh. You must provide at least position of mesh

func (*MeshBuilder) GetPositions

func (mb *MeshBuilder) GetPositions() (positions []float32)

GetPosition retrieves all mesh positions as float32 array

type MeshIndex

type MeshIndex int

type MeshKind

type MeshKind int

type Model

type Model struct {
	// contains filtered or unexported fields
}

func (*Model) Bounds

func (m *Model) Bounds(index NodeIndex, transform mgl32.Mat4, includeChild bool) (aabb AABB)

func (*Model) Dispose

func (m *Model) Dispose()

func (*Model) FindMaterial added in v0.20.1

func (m *Model) FindMaterial(name string) MaterialIndex

FindMaterial finds material index for named material. Return is -1 if material was not found

func (*Model) FindNode

func (m *Model) FindNode(nodeName string) NodeIndex

func (*Model) GetImage added in v0.20.1

func (m *Model) GetImage(idx ImageIndex) *vk.Image

func (*Model) GetImageView added in v0.20.1

func (m *Model) GetImageView(idx ImageIndex) (view *vk.ImageView, sampler *vk.Sampler)

func (*Model) GetMaterial

func (m *Model) GetMaterial(idx MaterialIndex) Material

func (*Model) GetMesh

func (m *Model) GetMesh(idx MeshIndex) Mesh

func (*Model) GetNode

func (m *Model) GetNode(idx NodeIndex) Node

func (*Model) GetSkin

func (m *Model) GetSkin(index SkinIndex) *Skin

func (*Model) NodeCount

func (m *Model) NodeCount() int

func (*Model) VertexBuffers

func (m *Model) VertexBuffers(kind MeshKind) []*vk.Buffer

type ModelBuilder

type ModelBuilder struct {
	MipLevels     uint32
	ShaderFactory ShaderFactory

	Materials []MaterialInfo
	Images    []*ImageBuilder
	Meshes    []*MeshBuilder
	Root      *NodeBuilder
	Skins     []Skin
	// contains filtered or unexported fields
}

ModelBuilder allows us to load multiple meshes, materials, images and skins. When we have loaded all nessessary artifacts, model builder can be converted to a model. Model will upload all model information (except Skins) to GPU where Shaders can access them quickly

func (*ModelBuilder) AddDecalMaterial added in v0.20.1

func (mb *ModelBuilder) AddDecalMaterial(name string, props MaterialProperties) MaterialIndex

Add new Decal material to model builders. For Decal material model builder will not create a shader nor allocate any descriptor sets.

func (*ModelBuilder) AddImage

func (mb *ModelBuilder) AddImage(kind string, content []byte, usage vk.ImageUsageFlags) ImageIndex

Attach image to model. This image can be them bound to material using material properties

func (*ModelBuilder) AddMaterial

func (mb *ModelBuilder) AddMaterial(name string, props MaterialProperties) MaterialIndex

Add new material to model builders. Model builders ShaderFactory is finally used to convert material properties to shader. Most of shader also build a descriptor set that links all static assets like color and textures of a material to a single Vulkan descriptor set.

func (*ModelBuilder) AddMesh

func (mb *ModelBuilder) AddMesh(mesh *MeshBuilder) MeshIndex

Add a mesh to model. Actual mesh content is built with MeshBuilder

func (*ModelBuilder) AddNode

func (mb *ModelBuilder) AddNode(name string, parent *NodeBuilder, transform mgl32.Mat4) *NodeBuilder

Add new node to model. If parent node is empty, predefined root node, named _root will be used.

func (*ModelBuilder) AddSkin

func (mb *ModelBuilder) AddSkin(skin Skin) SkinIndex

Add skin to model

func (*ModelBuilder) AddWhite

func (mb *ModelBuilder) AddWhite() ImageIndex

func (*ModelBuilder) FindMaterial added in v0.20.1

func (mb *ModelBuilder) FindMaterial(name string) (index MaterialIndex)

FindMaterial retrieves converted named material. Return is -1, nil if no material was found

func (*ModelBuilder) ToModel

func (mb *ModelBuilder) ToModel(ctx vk.APIContext, dev *vk.Device) *Model

Convert content of model builder to actual model and uploads model content (except skins) to GPU

type Node

type Node struct {
	Name      string
	Children  []NodeIndex
	Model     *Model
	Transform mgl32.Mat4
	Material  MaterialIndex
	Mesh      MeshIndex
	Skin      SkinIndex
	Parent    NodeIndex
}

func (Node) Enum

func (n Node) Enum(world mgl32.Mat4, action func(local mgl32.Mat4, n Node))

type NodeBuilder

type NodeBuilder struct {
	Name     string
	Children []*NodeBuilder
	Location mgl32.Mat4
	Mesh     MeshIndex
	Material MaterialIndex
	Skin     SkinIndex
}

func (*NodeBuilder) AddChild

func (nb *NodeBuilder) AddChild(child ...*NodeBuilder) *NodeBuilder

Add childs adds child nodes to a node

func (*NodeBuilder) ForNodes added in v0.20.1

func (nb *NodeBuilder) ForNodes(action func(n *NodeBuilder, parent *NodeBuilder, index int))

ForNodes recursively enumerates though all nodes child nodes

func (*NodeBuilder) SetMesh

func (nb *NodeBuilder) SetMesh(m MeshIndex, mat MaterialIndex) *NodeBuilder

SetMesh assign a mesh with material to node

func (*NodeBuilder) SetSkinnedMesh

func (nb *NodeBuilder) SetSkinnedMesh(m MeshIndex, mat MaterialIndex, skin SkinIndex) *NodeBuilder

SetMesh assign a mesh with material and skin to node

type NodeIndex

type NodeIndex int

type Property

type Property uint32

type Renderer added in v0.20.1

type Renderer interface {
	// GetPerRenderer allows nodes to store information that is shared between all frames of renderer. Typically each frame has it's own render
	// cache where you can store frame relevant assets. Each image of swapchain will get it's own frame.
	GetPerRenderer(key vk.Key, ctor func(ctx vk.APIContext) interface{}) interface{}
}

type Shader

type Shader interface {
	SetDescriptor(dsMat *vk.DescriptorSet)
	Draw(ctx *DrawContext, mesh Mesh, world mgl32.Mat4, extra ShaderExtra)
	DrawSkinned(ctx *DrawContext, mesh Mesh, world mgl32.Mat4, aniMatrix []mgl32.Mat4, extra ShaderExtra)
}

type ShaderExtra

type ShaderExtra interface {
	Get(key vk.Key) interface{}
}

type ShaderFactory

type ShaderFactory func(ctx vk.APIContext, dev *vk.Device, propSet MaterialProperties) (
	sh Shader, layout *vk.DescriptorLayout, ubf []byte, images []ImageIndex)

type Skin

type Skin struct {
	Joints     []Joint
	Matrix     []mgl32.Mat4
	Animations []Animation
}

type SkinIndex

type SkinIndex int

type VertexBuilder

type VertexBuilder struct {
	Index    uint32
	Position mgl32.Vec3
	Uv       mgl32.Vec2
	Normal   mgl32.Vec3
	Tangent  mgl32.Vec3
	Color    mgl32.Vec4
	Weights  mgl32.Vec4
	// qtangent mgl32.Quat
	Joints [4]uint16
	// contains filtered or unexported fields
}

Vertex builder builds one vertex of a mesh

func (*VertexBuilder) AddColor

func (vb *VertexBuilder) AddColor(color mgl32.Vec4) *VertexBuilder

AddColor adds vertex color. This is not used in current shaders but can be like an extra vec4 value is vertex input

func (*VertexBuilder) AddNormal

func (vb *VertexBuilder) AddNormal(normal mgl32.Vec3) *VertexBuilder

func (*VertexBuilder) AddTangent

func (vb *VertexBuilder) AddTangent(tangent mgl32.Vec3) *VertexBuilder

func (*VertexBuilder) AddUV

func (vb *VertexBuilder) AddUV(uv mgl32.Vec2) *VertexBuilder

func (*VertexBuilder) AddWeights

func (vb *VertexBuilder) AddWeights(weights mgl32.Vec4, joints ...uint16) *VertexBuilder

Add weight and joints to vertex. If you add weights and joints to vertex it will convert whole mesh to a skinned mesh. You must also provide Skin to model nodes that uses skinned mesh. Skinned meshes won't be shown without skin and of cause normal meshes can't handle skins.

type VertexFlags

type VertexFlags int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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