asset

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 20 Imported by: 4

Documentation

Index

Constants

View Source
const (
	UnspecifiedOffset        = int32(-1)
	UnspecifiedMaterialIndex = int32(-1)
	UnspecifiedArmatureIndex = int32(-1)
)
View Source
const UnspecifiedIndex = int32(-1)
View Source
const UnspecifiedNodeIndex = int32(-1)

Variables

View Source
var ErrNotFound = fmt.Errorf("not found")

ErrNotFound indicates that the specified content is not available.

Functions

This section is empty.

Types

type Animation added in v0.9.0

type Animation struct {
	Name      string
	StartTime float64
	EndTime   float64
	Bindings  []AnimationBinding
}

type AnimationBinding added in v0.9.0

type AnimationBinding struct {
	NodeIndex            int32
	NodeName             string // alternative in case of isolated animation
	TranslationKeyframes []TranslationKeyframe
	RotationKeyframes    []RotationKeyframe
	ScaleKeyframes       []ScaleKeyframe
}

type Armature added in v0.9.0

type Armature struct {
	Joints []Joint
}

type Binary added in v0.8.0

type Binary struct {
	Data []byte
}

Binary represents a blob of bytes

func (*Binary) DecodeFrom added in v0.8.0

func (b *Binary) DecodeFrom(in io.Reader) error

func (*Binary) EncodeTo added in v0.8.0

func (b *Binary) EncodeTo(out io.Writer) error

type BodyDefinition added in v0.8.0

type BodyDefinition struct {
	Name                   string
	Mass                   float64
	MomentOfInertia        dprec.Mat3
	RestitutionCoefficient float64
	DragFactor             float64
	AngularDragFactor      float64
	CollisionBoxes         []CollisionBox
	CollisionSpheres       []CollisionSphere
	CollisionMeshes        []CollisionMesh
}

type BodyInstance added in v0.8.0

type BodyInstance struct {
	Name      string
	NodeIndex int32
	BodyIndex int32
}

type CollisionBox added in v0.8.0

type CollisionBox struct {
	Translation dprec.Vec3
	Rotation    dprec.Quat
	Width       float64
	Height      float64
	Lenght      float64
}

type CollisionMesh added in v0.8.0

type CollisionMesh struct {
	Translation dprec.Vec3
	Rotation    dprec.Quat
	Triangles   []CollisionTriangle
}

type CollisionSphere added in v0.8.0

type CollisionSphere struct {
	Translation dprec.Vec3
	Radius      float64
}

type CollisionTriangle added in v0.8.0

type CollisionTriangle struct {
	A dprec.Vec3
	B dprec.Vec3
	C dprec.Vec3
}

type CubeTexture

type CubeTexture struct {
	Dimension  uint16
	Filtering  FilterMode
	Format     TexelFormat
	Flags      TextureFlag
	FrontSide  CubeTextureSide
	BackSide   CubeTextureSide
	LeftSide   CubeTextureSide
	RightSide  CubeTextureSide
	TopSide    CubeTextureSide
	BottomSide CubeTextureSide
}

func (*CubeTexture) DecodeFrom

func (t *CubeTexture) DecodeFrom(in io.Reader) error

func (*CubeTexture) EncodeTo

func (t *CubeTexture) EncodeTo(out io.Writer) error

type CubeTextureSide

type CubeTextureSide struct {
	Data []byte
}

type Decodable

type Decodable interface {
	DecodeFrom(in io.Reader) error
}

Decodable represents an asset that can be deserialized.

type Encodable

type Encodable interface {
	EncodeTo(out io.Writer) error
}

Encodable represents an asset that can be serialized.

type FilterMode

type FilterMode uint8
const (
	FilterModeNearest FilterMode = iota
	FilterModeLinear
	FilterModeAnisotropic
)

type IndexLayout added in v0.8.0

type IndexLayout uint8
const (
	IndexLayoutUint16 IndexLayout = iota
	IndexLayoutUint32
)

type Joint added in v0.9.0

type Joint struct {
	NodeIndex         int32
	InverseBindMatrix sprec.Mat4
}

type LightInstance added in v0.10.0

type LightInstance struct {
	Name               string
	NodeIndex          int32
	Type               LightType
	EmitRange          float64
	EmitOuterConeAngle dprec.Angle
	EmitInnerConeAngle dprec.Angle
	EmitColor          dprec.Vec3
}

type LightType added in v0.10.0

type LightType uint8
const (
	LightTypePoint LightType = 1 + iota
	LightTypeSpot
	LightTypeDirectional
)

type Material added in v0.8.0

type Material struct {
	Name            string
	Type            MaterialType
	BackfaceCulling bool
	AlphaTesting    bool
	AlphaThreshold  float32
	Blending        bool
	ScalarMask      uint32
	Scalars         [16]float32
	Textures        [16]TextureRef
}

type MaterialType added in v0.8.0

type MaterialType uint8
const (
	MaterialTypePBR MaterialType = iota
	MaterialTypeAlbedo
)

type MeshDefinition added in v0.8.0

type MeshDefinition struct {
	Name                 string
	VertexLayout         VertexLayout
	VertexData           []byte
	IndexLayout          IndexLayout
	IndexData            []byte
	Fragments            []MeshFragment
	BoundingSphereRadius float64
}

type MeshFragment added in v0.8.0

type MeshFragment struct {
	Topology      MeshTopology
	IndexOffset   uint32
	IndexCount    uint32
	MaterialIndex int32
}

type MeshInstance added in v0.8.0

type MeshInstance struct {
	Name            string
	NodeIndex       int32
	ArmatureIndex   int32
	DefinitionIndex int32
}

type MeshTopology added in v0.8.0

type MeshTopology uint8
const (
	MeshTopologyPoints MeshTopology = iota
	MeshTopologyLineStrip
	MeshTopologyLineLoop
	MeshTopologyLines
	MeshTopologyTriangleStrip
	MeshTopologyTriangleFan
	MeshTopologyTriangles
)

type Model added in v0.8.0

type Model struct {
	Nodes           []Node
	Animations      []Animation
	Armatures       []Armature
	Textures        []TwoDTexture
	Materials       []Material
	MeshDefinitions []MeshDefinition
	MeshInstances   []MeshInstance
	BodyDefinitions []BodyDefinition
	BodyInstances   []BodyInstance
	LightInstances  []LightInstance
}

func (*Model) DecodeFrom added in v0.8.0

func (m *Model) DecodeFrom(in io.Reader) error

func (*Model) EncodeTo added in v0.8.0

func (m *Model) EncodeTo(out io.Writer) error

type ModelInstance added in v0.9.0

type ModelInstance struct {
	ModelIndex  int32
	ModelID     string
	Name        string
	Translation dprec.Vec3
	Rotation    dprec.Quat
	Scale       dprec.Vec3
}

type Node added in v0.8.0

type Node struct {
	Name        string
	ParentIndex int32
	Translation dprec.Vec3
	Rotation    dprec.Quat
	Scale       dprec.Vec3
}

type PBRMaterialView added in v0.9.0

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

func NewPBRMaterialView added in v0.9.0

func NewPBRMaterialView(delegate *Material) *PBRMaterialView

func (*PBRMaterialView) BaseColor added in v0.9.0

func (v *PBRMaterialView) BaseColor() sprec.Vec4

func (*PBRMaterialView) BaseColorTexture added in v0.9.0

func (v *PBRMaterialView) BaseColorTexture() TextureRef

func (*PBRMaterialView) Metallic added in v0.9.0

func (v *PBRMaterialView) Metallic() float32

func (*PBRMaterialView) MetallicRoughnessTexture added in v0.9.0

func (v *PBRMaterialView) MetallicRoughnessTexture() TextureRef

func (*PBRMaterialView) NormalScale added in v0.9.0

func (v *PBRMaterialView) NormalScale() float32

func (*PBRMaterialView) NormalTexture added in v0.9.0

func (v *PBRMaterialView) NormalTexture() TextureRef

func (*PBRMaterialView) Roughness added in v0.9.0

func (v *PBRMaterialView) Roughness() float32

func (*PBRMaterialView) SetBaseColor added in v0.9.0

func (v *PBRMaterialView) SetBaseColor(color sprec.Vec4)

func (*PBRMaterialView) SetBaseColorTexture added in v0.9.0

func (v *PBRMaterialView) SetBaseColorTexture(texture TextureRef)

func (*PBRMaterialView) SetMetallic added in v0.9.0

func (v *PBRMaterialView) SetMetallic(metallic float32)

func (*PBRMaterialView) SetMetallicRoughnessTexture added in v0.9.0

func (v *PBRMaterialView) SetMetallicRoughnessTexture(texture TextureRef)

func (*PBRMaterialView) SetNormalScale added in v0.9.0

func (v *PBRMaterialView) SetNormalScale(scale float32)

func (*PBRMaterialView) SetNormalTexture added in v0.9.0

func (v *PBRMaterialView) SetNormalTexture(texture TextureRef)

func (*PBRMaterialView) SetRoughness added in v0.9.0

func (v *PBRMaterialView) SetRoughness(roughness float32)

type Registry

type Registry interface {
	Resources() []Resource
	ResourceByID(id string) Resource
	ResourceByName(name string) Resource
	ResourcesByName(name string) []Resource
	CreateResource(kind, name string) Resource
	// CreateIDResource is deprecated and available only due to the old
	// pack mechanism.
	CreateIDResource(id, kind, name string) Resource
	Save() error
}

Registry represents a managment interface for assets.

func NewDirRegistry

func NewDirRegistry(dir string) (Registry, error)

NewDirRegistry creates a Registry implementation that stores content on the filesystem. The provided dir parameter needs to point to the project root. A special assets directory will be created inside if one is not available already.

func NewWebRegistry

func NewWebRegistry(assetsURL string) (Registry, error)

NewWebRegistry creates a Registry implementation that reads content from the web. The provided assetsURL parameter needs to point to the web location of the assets.

This registry does not support write or delete operations.

type RegistryLocator added in v0.8.0

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

RegistryLocator is an implementation of ReadLocator that uses a Registry to access resources.

func NewRegistryLocator added in v0.8.0

func NewRegistryLocator(registry Registry) *RegistryLocator

NewRegistryLocator returns a new *FileLocator that is configured to access resources located on the local filesystem.

func (*RegistryLocator) ReadResource added in v0.8.0

func (l *RegistryLocator) ReadResource(path string) (io.ReadCloser, error)

type Resource

type Resource interface {
	ID() string
	Kind() string
	Name() string
	SetName(name string)
	Dependants() []Resource
	Dependencies() []Resource
	AddDependency(resource Resource)
	RemoveDependency(resource Resource)
	ReadPreview() (image.Image, error)
	WritePreview(image.Image) error
	DeletePreview() error
	ReadContent(target Decodable) error
	WriteContent(source Encodable) error
	DeleteContent() error
	Delete()
}

Resource represents the generic aspects of an asset.

type RotationKeyframe added in v0.9.0

type RotationKeyframe struct {
	Timestamp float64
	Rotation  dprec.Quat
}

type ScaleKeyframe added in v0.9.0

type ScaleKeyframe struct {
	Timestamp float64
	Scale     dprec.Vec3
}

type Scene added in v0.8.0

type Scene struct {
	Model
	SkyboxTexture            string
	AmbientReflectionTexture string
	AmbientRefractionTexture string
	ModelDefinitions         []Model
	ModelInstances           []ModelInstance
}

func (*Scene) DecodeFrom added in v0.9.0

func (s *Scene) DecodeFrom(in io.Reader) error

func (*Scene) EncodeTo added in v0.9.0

func (s *Scene) EncodeTo(out io.Writer) error

type TexelFormat

type TexelFormat uint8
const (
	TexelFormatR8 TexelFormat = iota
	TexelFormatR16
	TexelFormatR16F
	TexelFormatR32F
	TexelFormatRG8
	TexelFormatRG16
	TexelFormatRG16F
	TexelFormatRG32F
	TexelFormatRGB8
	TexelFormatRGB16
	TexelFormatRGB16F
	TexelFormatRGB32F
	TexelFormatRGBA8
	TexelFormatRGBA16
	TexelFormatRGBA16F
	TexelFormatRGBA32F
	TexelFormatDepth16F
	TexelFormatDepth32F
)

type TextureFlag added in v0.8.0

type TextureFlag uint8
const (
	TextureFlagMipmapping TextureFlag = 1 << iota
	TextureFlagLinear

	TextureFlagNone TextureFlag = 0
)

func (TextureFlag) Has added in v0.8.0

func (f TextureFlag) Has(flag TextureFlag) bool

type TextureRef added in v0.9.0

type TextureRef struct {
	TextureIndex int32
	TextureID    string
}

func (TextureRef) Valid added in v0.9.0

func (r TextureRef) Valid() bool

type TranslationKeyframe added in v0.9.0

type TranslationKeyframe struct {
	Timestamp   float64
	Translation dprec.Vec3
}

type TwoDTexture

type TwoDTexture struct {
	Width     uint16
	Height    uint16
	Wrapping  WrapMode
	Filtering FilterMode
	Format    TexelFormat
	Flags     TextureFlag
	Data      []byte
}

func (*TwoDTexture) DecodeFrom

func (t *TwoDTexture) DecodeFrom(in io.Reader) error

func (*TwoDTexture) EncodeTo

func (t *TwoDTexture) EncodeTo(out io.Writer) error

type VertexLayout added in v0.8.0

type VertexLayout struct {
	CoordOffset    int32
	CoordStride    int32
	NormalOffset   int32
	NormalStride   int32
	TangentOffset  int32
	TangentStride  int32
	TexCoordOffset int32
	TexCoordStride int32
	ColorOffset    int32
	ColorStride    int32
	WeightsOffset  int32
	WeightsStride  int32
	JointsOffset   int32
	JointsStride   int32
}

VertexLayout describes how vertex data is positioned within the VertexData buffer.

Coords are represented by RGB32F (i.e. three 32-bit float values). Since coords can span a bigger range, 32-bit floats are preferred.

Normals and Tangents are represented by RGB16F (i.e. three 16-bit float values). This should be more than sufficient for normals.

TexCoords are represented by RG16F (i.e. two 16-bit float values). Since texture coordinates are usually close to the zero-one range, 16-bit floats should provide sufficient precision.

Colors are represented by RGBA8UN (i.e. four 8-bit unsigned normalized values). This is sufficient for an sRGB color with alpha.

Weights are represented by RGBA8UN (i.e. four 8-bit unsigned normalized values). This should provide sufficient precision while still being fairly compact.

Joints are represented by RGBA8IU (i.e. four 8-bit integer unsigned values). This means that there can be at most 256 joints in an Armature.

type WrapMode

type WrapMode uint8
const (
	WrapModeRepeat WrapMode = iota
	WrapModeMirroredRepeat
	WrapModeClampToEdge
)

Jump to

Keyboard shortcuts

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