load

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2015 License: BSD-2-Clause, Zlib Imports: 15 Imported by: 0

Documentation

Overview

Package load fetches disk based data that will be used for 3D assets. Data is loaded directly from disk for development builds and from a zip file attached to the binary for production builds.

Data that can be loaded from disk is listed in the Loader interface. Data is returned in an intermediate format that is close to how the data was stored on disk. The intermediate format is expected to be be used to populate render or audio based assets:

  Data                      File            Likely Used For
 ------                    ------          ------------------
bitmapped fonts          : txtfile.fnt --> rendered font
colour and surface data  : txtfile.mtl --> rendered model material
vertex data              : txtfile.obj --> rendered model mesh
vertex shader program    : txtfile.vsh -┐
fragment shader program  : txtfile.fsh --> rendered model shader
animated models          : txtfile.iqm --> rendered model animation
images                   : binfile.png --> rendered model texture
audio                    : binfile.wav --> sound played in 3D world

Package load is currently intended for smaller 3D applications where data is loaded directly from files to memory, i.e. no database involved.

Package load is provided as part of the vu (virtual universe) 3D engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChrData

type ChrData struct {
	Char       rune // Character.
	X, Y, W, H int  // Character bit size.
	Xo, Yo, Xa int  // Character offset.
}

ChrData holds UV texture mapping information for one character. It is an intermediate format intended for vu/Model instances.

type FntData

type FntData struct {
	W, H  int       // Width and height
	Chars []ChrData // Character data.
}

FntData holds UV texture mapping information for a font. It is intended for populating rendered models of strings.

type IqAnim

type IqAnim struct {
	Name   string  // Name of the animation
	F0, Fn uint32  // First frame, number of frames.
	Rate   float32 // Frames per second.
}

IqAnim allows a model to have multiple animations. The named animation affects frames from F0 to F0+FN. Expected to be used as part of IqData.

type IqData

type IqData struct {
	Name string // Data name from IQM or IQE file.

	// Mesh and Texture data create the static model.
	V        []float32   // Vertex positions.  Arranged as [][3]float32
	N        []float32   // Vertex normals.    Arranged as [][3]float32
	X        []float32   // Vertex tangents.   Arranged as [][2]float32
	T        []float32   // Vertex tex coords. Arranged as [][2]float32
	F        []uint16    // Triangle Faces.    Arranged as [][3]uint16
	Textures []IqTexture // One or more model textures

	// Optional animation data. Blend indicies indicate which vertex
	// is influenced by which joint, up to 4 joints per vertex. Blend
	// weights gives the amount of influence of a joint on a vertex.
	Anims  []IqAnim  // One or more animations.
	B      []byte    // Vertex blend indicies. Arranged as [][4]byte
	W      []byte    // Vertex blend weights.  Arranged as [][4]byte
	Joints []int32   // Joint parent information for each joint.
	Frames []*lin.M4 // Animation transforms: [NumFrames][NumJoints].
}

IqData is model data from IQM or IQE files. It is intended for populating animated models.

type IqTexture

type IqTexture struct {
	Name   string // Name of the texture resource.
	F0, Fn uint32 // First triangle face index and number of triangle faces.
}

IqTexture allows a model to have multiple textures. The named texture resource affects triangle faces from F0 to F0+FN. Expected to be used as part of IqData.

type Loader

type Loader interface {

	// SetDir overrides the default directory location for the given asset type.
	// All directories are expected to be relative to the application location.
	SetDir(assetType int, dir string) Loader
	Dispose() // Properly terminate asset loading

	// Supported file formats.
	Png(name string) (img image.Image, err error)         // .png
	Mtl(name string) (mtl *MtlData, err error)            // .mtl
	Obj(name string) (obj []*ObjData, err error)          // .obj
	Fnt(name string) (fnt *FntData, err error)            // .fnt
	Vsh(name string) (src []string, err error)            // .vsh
	Fsh(name string) (src []string, err error)            // .fsh
	Wav(name string) (wh *WavHdr, data []byte, err error) // .wav
	Iqm(name string) (iqd *IqData, err error)             // .iqm

	// GetResource allows applications to include and find custom resources.
	GetResource(directory, name string) (file io.ReadCloser, err error)
}

Loader provides methods for loading disk based data assets. Loader methods log development errors for unknown assets or unsupported data types. Loader files will return empty or nil data values when there are errors.

func NewLoader

func NewLoader() Loader

NewLoader provides the default loader implmentation.

type MtlData

type MtlData struct {
	KaR, KaG, KaB float32 // Ambient colour.
	KdR, KdG, KdB float32 // Diffuse colour.
	KsR, KsG, KsB float32 // Specular colour.
	Tr            float32 // Transparency
}

MtlData holds colour and alpha information. It is intended for populating rendered models.

type ObjData

type ObjData struct {
	Name string    // Data name from .obj file.
	V    []float32 // Vertex positions.    Arranged as [][3]float32
	N    []float32 // Vertex normals.      Arranged as [][3]float32
	T    []float32 // Texture coordinates. Arranged as [][2]float32
	F    []uint16  // Triangle faces.      Arranged as [][3]uint16
}

ObjData stores vertex data from .obj files. It is intended for populating rendered models. The V,F buffers are expected to have data. The N,T buffers are optional.

type WavHdr

type WavHdr struct {
	RiffId      [4]byte // "RIFF"
	FileSize    uint32  // Total file size minus 8 bytes.
	WaveId      [4]byte // "WAVE"
	Fmt         [4]byte // "fmt "
	FmtSize     uint32  // Will be 16 for PCM.
	AudioFormat uint16  // Will be 1 for PCM.
	Channels    uint16  // Number of audio channels.
	Frequency   uint32  // 8000, 44100, etc.
	ByteRate    uint32  // SampleRate * NumChannels * BitsPerSample/8.
	BlockAlign  uint16  // NumChannels * BitsPerSample/8.
	SampleBits  uint16  // 8 bits = 8, 16 bits = 16, etc.
	DataId      [4]byte // "data"
	DataSize    uint32  // Size of audio data (total file size minus 44 bytes).
}

WavHdr is used to load a .wav audio file into memory such that it is easily usable by the audio library. The wave PCM soundfile format is:

https://ccrma.stanford.edu/courses/422/projects/WaveFormat/

WavHdr is intended for attaching sounds to 3D locations.

Jump to

Keyboard shortcuts

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