gombz

package module
v0.0.0-...-aee5835 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2016 License: BSD-2-Clause Imports: 6 Imported by: 10

README

GOMBZ

This is a Go library that provides a serializable data structure for 3d models and animations. Basically, it provides a set of data structures that represent 3d models, bones and animations as well as functions to decode and encode them. The serialization process uses BSON notation and then is run through zlib.

Additionally, it provides a compiler to take any file that Assimp supports and turns it into a compressed binary file that can be read by this library.

Requirements

This does require cgo which means that gcc should be in your path when trying to build using this library.

Software requirements:

  • Mathgl - for 3d math
  • BSON - a BSON implementation in Go for binary serialization

The gombz compiler also needs:

  • Assimp version 3.1 - tested with this version
  • Assimp-go - Go wrappers for Assimp

Compiler Installation (gombzc)

The gombz compiler called gombzc can be installed to your $GOPATH/bin folder by using the following command:

go install github.com/tbogdala/gombz/cmd/gombzc

TODO

  • Documentation
  • Better command-line flags to better control ASSIMP
  • Consider supporting more than one mesh
  • Consider including bitangents? Send feedback or create an issue if you feel strongly about this

LICENSE

Gombz is released under the BSD license. See the LICENSE file for more details.

Documentation

Index

Constants

View Source
const (
	// MaxUVChannelCount is the maximum number of UV channels supported.
	MaxUVChannelCount = 8
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Animation

type Animation struct {
	// Name is the name of the animation
	Name string

	// Duration is the length of the animation in ticks
	Duration float32

	// TicksPerSecond is the number of ticks per second for the animation as designed.
	TicksPerSecond float32

	// Transform is the transformation matrix.
	Transform mgl.Mat4

	// Channels is a slice of AnimationChannel objects that deform the bones
	Channels []AnimationChannel
}

Animation represents data required to transform bones in an animation.

type AnimationChannel

type AnimationChannel struct {
	// Name is the name of the animation channel
	Name string

	// BoneId is the corresponding bone.Id value for the channel
	BoneId int32

	// PositionKeys is a slice of vector keys describing bone position at a given time in an animation.
	PositionKeys []AnimationVec3Key

	// ScaleKeys is a slice of vector keys describing bone scale at a given time in an animation.
	ScaleKeys []AnimationVec3Key

	// RotationKeys is a slice of Quat keys describing bone rotation at a given time in an animation.
	RotationKeys []AnimationQuatKey
}

AnimationChannel is an object that contains data required to transform a bone in an animation.

type AnimationQuatKey

type AnimationQuatKey struct {
	// Time specifies the time in the animation for this current Quat value (e.g. rotation).
	Time float32

	// Key is the Quat value (e.g. rotation) at the given time in animation.
	Key mgl.Quat
}

AnimationQuatKey is a animation channel key that contains a quaternion based animation

type AnimationVec3Key

type AnimationVec3Key struct {
	// Time specifies the time in the animation for this current vector value (e.g. position).
	Time float32

	// Key is the vector value (e.g. position) at the given time in animation.
	Key mgl.Vec3
}

AnimationVec3Key is a animation channel key that contains a vector based animation

type Bone

type Bone struct {
	// Name is the name of the bone
	Name string

	// Id is a number assigned to the bone that should be >= 0
	Id int32

	// Parent is the Id of the parent bone in the skeleton. It will be -1 for the root bone.
	Parent int32

	// Offset is the matrix that transforms from mesh space to bone space in bind pose
	Offset mgl.Mat4

	// Transform is the matrix that is the transformation relative to the node's parent.
	Transform mgl.Mat4
}

Bone is a struct that contains transform and skeletal information for skeletal animation.

type Mesh

type Mesh struct {
	// FaceCount is the number of faces in the mesh
	FaceCount uint32

	// BoneCount is the number of bones in the mesh
	BoneCount uint32

	// VertexCount is the number of vertices in the mesh
	VertexCount uint32

	// Vertices is a slice of vertices that are represented with Vec3 float vectors.
	Vertices []mgl.Vec3

	// Normals is a slice of Vec3 floats representing a normal for each vertex.
	Normals []mgl.Vec3

	// Tangents is a slice of Vec3 floats representing a tangent for each vertex.
	Tangents []mgl.Vec3

	// Faces are triplets of unsigned ints that specify the vertices used in a face
	Faces []MeshFace

	// UVChannels is an array (of size MaxUVChannelCount) of slices that are Vec2
	// float arrays representing the UV coordinate for a vertex.
	UVChannels [MaxUVChannelCount][]mgl.Vec2

	// Bones is slice of Bone objects that form the skeleton of the mesh
	Bones []Bone

	// VertexWeightIds is a slice that has a Vec4 for each vertex in Vertices
	// which can contain up to four bone ids that will modify the vertex.
	// Note: stored as a float since that's how it will be passed to shaders
	VertexWeightIds []mgl.Vec4

	// VertexWeights is a slice that has a Vec4 for each vertex in Vertices
	// which can contain up to four bone weights used to determine how much
	// the bone specified by VertexWeightIds affects the vertex position.
	VertexWeights []mgl.Vec4

	// Animations is a slice of Animation objects that represent all animations that
	// can deform the mesh's Bones.
	Animations []Animation
}

Mesh contains the data for a given mesh such as vertices and faces.

func DecodeFile

func DecodeFile(fn string) (outMesh *Mesh, err error)

DecodeFile takes a file path, loads all of the bytes from it and passes it to the DecodeMesh() function to return the Mesh or error on failure.

func DecodeMesh

func DecodeMesh(bs []byte) (outMesh *Mesh, err error)

DecodeMesh takes a byte stream and decompresses it with zlib and then decodes it with bson and returns the result -- or returns a non-nil err on fail.

func (*Mesh) Encode

func (mesh *Mesh) Encode() (out []byte, err error)

Encode takes a given mesh and encodes it to binary with bson and then compresses it with zlib and returns the result -- or returns a non-nil err on fail.

type MeshFace

type MeshFace [3]uint32

MeshFace is an alias for a vector of 3 unsigned ints. Note: currently mathgl doesn't have support for integer vectors

Directories

Path Synopsis
cmd
gombzc
Gombzc is an executable that takes any input file that ASSIMP supports and compiles them into the GOMBZ binary format.
Gombzc is an executable that takes any input file that ASSIMP supports and compiles them into the GOMBZ binary format.

Jump to

Keyboard shortcuts

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