ofbx

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: MIT Imports: 16 Imported by: 1

README

ofbx

ofbx is a library for parsing FBX files. FBX files contain geometry, animation, texture and material information for 3D models.

This is a Go port of github.com/nem0/OpenFBX.

ofbx is currently at version 0.1 and has limited functionality. The internal API will change drastically as we refactor away from patterns used in nem0/OpenFBX, and this will likely involve significant changes to the external API as well.

Documentation

Index

Constants

View Source
const (
	BoneTranslate = "Lcl Translation"
	BoneRotate    = "Lcl Rotation"
	BoneScale     = "Lcl Scaling"
)
View Source
const MaxUvs = 4

MaxUvs is the highest number of UVs allowed

Variables

View Source
var (
	UpAxis                  = UpVectorX
	UpAxisSign              = 1
	FrontAxis               = FrontVectorParityOdd
	FrontAxisSign           = 1
	CoordAxis               = CoordSystemRight
	CoordAxisSign           = 1
	OriginalUpAxis          int
	OriginalUpAxisSign              = 1
	UnitScaleFactor         float32 = 1
	OriginalUnitScaleFactor float32 = 1
	TimeSpanStart           uint64
	TimeSpanStop            uint64
	TimeMode                        = FrameRateDefault
	CustomFrameRate         float32 = -1.0
)

Default Settings

Functions

func GetFramerateFromTimeMode

func GetFramerateFromTimeMode(f FrameRate, custom float32) float32

GetFramerateFromTimeMode gets time from a given framerate TODO: Confirm these

func Vec2FromString

func Vec2FromString(str, end string, val *floatgeom.Point2) string

Vec2FromString gets a vec from string //Todo: Convert from using pointer math...

func Vec3FromString

func Vec3FromString(str, end string, val *floatgeom.Point3) string

Vec3FromString gets a vec from string

func Vec4FromString

func Vec4FromString(str, end string, val *floatgeom.Point4) string

Vec4FromString gets a vec from string

Types

type AnimationCurve

type AnimationCurve struct {
	Object
	Times        []time.Duration
	Values       []float32
	AttrFlags    []int64
	AttrData     []float32
	AttrRefCount []int64
}

AnimationCurve are a mapping of key frame times to a set of data. Basic need is to have Times mapping with Values while disregarding AttributeFlags and Data

func NewAnimationCurve

func NewAnimationCurve(scene *Scene, element *Element) *AnimationCurve

NewAnimationCurve creates a new stub AnimationCurve

func (*AnimationCurve) String

func (ac *AnimationCurve) String() string

String pretty prints out the AnimationCurve

func (*AnimationCurve) Type

func (ac *AnimationCurve) Type() Type

Type returns the type ANIMATION_CURVE

type AnimationCurveNode

type AnimationCurveNode struct {
	Object
	Curves       [3]Curve
	Bone         Obj
	BoneLinkProp string
	// contains filtered or unexported fields
}

AnimationCurveNode is a mapping of Curve to a property

func NewAnimationCurveNode

func NewAnimationCurveNode(s *Scene, e *Element) *AnimationCurveNode

NewAnimationCurveNode creates a new AnimationCurveNode with just the base object

func (*AnimationCurveNode) String

func (acn *AnimationCurveNode) String() string

String pretty formats the AnimationCurveNode

func (*AnimationCurveNode) Type

func (acn *AnimationCurveNode) Type() Type

Type returns ANIMATION_CURVE_NODE

type AnimationLayer

type AnimationLayer struct {
	Object
	CurveNodes []*AnimationCurveNode
}

AnimationLayer is a collection of AnimationCurveNodes along with possibily some properties

func NewAnimationLayer

func NewAnimationLayer(scene *Scene, element *Element) *AnimationLayer

NewAnimationLayer creates a new AnimationLayer with no curvenodes

func (*AnimationLayer) String

func (as *AnimationLayer) String() string

String pretty formats the AnimationLayers Curve Nodes

func (*AnimationLayer) Type

func (as *AnimationLayer) Type() Type

Type returns the type of Animation_layer

type AnimationStack

type AnimationStack struct {
	Object
	Layers []*AnimationLayer
}

An AnimationStack is collection of 1 to n AnimationLayers along with possibily some properties

func NewAnimationStack

func NewAnimationStack(scene *Scene, element *Element) *AnimationStack

NewAnimationStack creates a new empty stack

func (*AnimationStack) String

func (as *AnimationStack) String() string

String returns a pretty print version of AnimationStack

func (*AnimationStack) Type

func (as *AnimationStack) Type() Type

Type returns the Animation_stack type

type Cluster

type Cluster struct {
	Object

	Link          Obj
	Skin          *Skin
	Indices       []int
	Weights       []float64
	Transform     Matrix
	TransformLink Matrix
}

Cluster is an entity which acts on a subset of a geometry's control points For each control point that the cluster acts on, the intensity of the cluster's action is modulated by a weight. The link mode (ELinkMode) specifies how the weights are taken into account.

func NewCluster

func NewCluster(scene *Scene, element *Element) *Cluster

NewCluster creates a new empty Cluster object

func (*Cluster) String

func (c *Cluster) String() string

String pretty formats the Cluster for printing

func (*Cluster) Type

func (c *Cluster) Type() Type

Type returns CLUSTER

type Color

type Color struct {
	R, G, B float32
}

Color is a set of floats RGB

func (*Color) String

func (c *Color) String() string

type Connection

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

Connection is a connection from an Object to either another Object or a Property

func (*Connection) String

func (c *Connection) String() string

type ConnectionType

type ConnectionType int

ConnectionType dictates what the Object is connecting to

const (
	// ObjectConn is a connection to another Object
	ObjectConn ConnectionType = iota
	// PropConn is a connection to a proprety
	PropConn ConnectionType = iota
)

Connection Types

func (ConnectionType) String

func (ct ConnectionType) String() string

type CoordSystem

type CoordSystem int

CoordSystem specifies the third vector of the system.

const (
	CoordSystemRight CoordSystem = iota
	CoordSystemLeft  CoordSystem = iota
)

CoordSystem options

type CountReader

type CountReader struct {
	io.Reader
	ReadSoFar int
}

CountReader an io reader that knows how many bytes it has currently read

func NewCountReader

func NewCountReader(r io.Reader) *CountReader

NewCountReader creates a new wrapper around an io.Reader with a count of 0

func (*CountReader) Read

func (c *CountReader) Read(p []byte) (n int, err error)

Read reads in some number of bytes and returns the result from the underlying io.Reader

type Cursor

type Cursor struct {
	*bufio.Reader
	// contains filtered or unexported fields
}

Cursor is a rapper for a reader

func (*Cursor) ReadSoFar

func (c *Cursor) ReadSoFar() int

ReadSoFar returns how much of the data has been read

type Curve

type Curve struct {
	Curve *AnimationCurve
	// contains filtered or unexported fields
}

Curve is a connection Linkage for an AnimationCurve

func (*Curve) String

func (c *Curve) String() string

String pretty formats the Curve

type CurveMode

type CurveMode int

CurveMode details how the values in the CurveNode should be interperted and used (translation,rotation,scale)

const (
	// TRANSLATION is a CurveMode where the curve applies a Translation
	TRANSLATION CurveMode = iota
	// ROTATION is a CurveMode where the curve applies a rotation
	ROTATION CurveMode = iota
	// SCALE is a CurveMode where the curve applies a scaling effect
	SCALE CurveMode = iota
)

type DataView

type DataView struct {
	bytes.Reader
}

DataView leftover concept that knows how to present different type sof data

func BufferDataView

func BufferDataView(buff *bytes.Buffer) *DataView

BufferDataView creates a DataView from the delivered buffer

func NewDataView

func NewDataView(s string) *DataView

NewDataView creates a new Dataview and the underlying bytes reader on the given string

func (*DataView) String

func (dv *DataView) String() string

type Element

type Element struct {
	ID         *DataView
	Children   []*Element
	Properties []*Property
}

Element stores a set of properties and a set of children

func (*Element) String

func (e *Element) String() string

type FrameRate

type FrameRate int

FrameRate enumerates standard rates of how many frames should be advanced per second

const (
	FrameRateDefault       FrameRate = iota
	FrameRate120           FrameRate = iota
	FrameRate100           FrameRate = iota
	FrameRate60            FrameRate = iota
	FrameRate50            FrameRate = iota
	FrameRate48            FrameRate = iota
	FrameRate30            FrameRate = iota
	FrameRate30Drop        FrameRate = iota
	FrameRateNTSCDropFrame FrameRate = iota
	FrameRateNTSCFullFrame FrameRate = iota
	FrameRatePAL           FrameRate = iota
	FrameRateCinema        FrameRate = iota
	FrameRate1000          FrameRate = iota
	FrameRateCinemaND      FrameRate = iota
	FrameRateCustom        FrameRate = iota
)

FrameRate values

type FrontVector

type FrontVector int

FrontVector is a vector with origin at the screen pointing toward the camera.

const (
	FrontVectorParityEven FrontVector = 1
	FrontVectorParityOdd  FrontVector = 2
)

FrontVector Parity Options

type Geometry

type Geometry struct {
	Object
	Skin *Skin

	Vertices, Normals, Tangents []floatgeom.Point3

	UVs       [MaxUvs][]floatgeom.Point2
	Colors    []floatgeom.Point4
	Materials []int

	Faces [][]int
	// contains filtered or unexported fields
}

Geometry is the base geometric shape objec that is implemented in forms such as meshes that dictate control point deformations

func NewGeometry

func NewGeometry(scene *Scene, element *Element) *Geometry

NewGeometry makes a stub Geometry

func (*Geometry) GetOldVerts added in v1.0.1

func (g *Geometry) GetOldVerts() []int

func (*Geometry) String

func (g *Geometry) String() string

func (*Geometry) Type

func (g *Geometry) Type() Type

Type returns GEOMETRY

type Header struct {
	Reserved [2]uint8
	Version  uint32
}

Header is a magic set of ints

func (Header) String

func (h Header) String() string

type Material

type Material struct {
	Object
	EmissiveColor     Color
	EmissiveFactor    float64
	AmbientColor      Color
	DiffuseColor      Color
	DiffuseFactor     float64
	TransparentColor  Color
	SpecularColor     Color
	SpecularFactor    float64
	Shininess         float64
	ShininessExponent float64
	ReflectionColor   Color
	ReflectionFactor  float64
	Textures          [TextureCOUNT]*Texture
}

Material stores texture pointers and how to apply them

func NewMaterial

func NewMaterial(scene *Scene, element *Element) *Material

NewMaterial makes a stub Material

func (*Material) String

func (m *Material) String() string

func (*Material) Type

func (m *Material) Type() Type

Type returns MATERIAl

type Matrix

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

Matrix is a 16 sized slice that we operate on as if it was actually a matrix

func GetGlobalMatrix added in v1.0.1

func GetGlobalMatrix(o Obj) Matrix

func (Matrix) Mul

func (m1 Matrix) Mul(m2 Matrix) Matrix

Mul multiplies the values of two matricies together and returns the output

func (*Matrix) ToArray added in v1.0.1

func (mat *Matrix) ToArray() [16]float64

type Mesh

type Mesh struct {
	Object
	Geometry  *Geometry
	Materials []*Material
}

Mesh is a geometry made of polygon https://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_class_fbx_mesh_html

func NewMesh

func NewMesh(scene *Scene, element *Element) *Mesh

NewMesh cretes a new stub Object

func (*Mesh) Animations

func (m *Mesh) Animations() []*AnimationStack

Animations returns the Animation Stacks connected to this mesh

func (*Mesh) GetGeometricMatrix added in v1.0.1

func (m *Mesh) GetGeometricMatrix() Matrix

func (*Mesh) String

func (m *Mesh) String() string

func (*Mesh) Type

func (m *Mesh) Type() Type

Type returns MESH

type NeedsPostProcessing

type NeedsPostProcessing interface {
	// contains filtered or unexported methods
}

NeedsPostProcessing note objects that require post processing

type Node

type Node struct {
	Object
	// contains filtered or unexported fields
}

Node is a typed object

func NewNode

func NewNode(scene *Scene, element *Element, typ Type) *Node

NewNode creates a new node

func (*Node) String

func (n *Node) String() string

func (*Node) Type

func (n *Node) Type() Type

Type returns a nodes type

type NodeAttribute

type NodeAttribute struct {
	Object
	Attribute *DataView
}

NodeAttribute is an formattable Attribute on a Node

func NewNodeAttribute

func NewNodeAttribute(scene *Scene, element *Element) *NodeAttribute

NewNodeAttribute creates a stube NodeAttribute

func (*NodeAttribute) String

func (na *NodeAttribute) String() string

func (*NodeAttribute) Type

func (na *NodeAttribute) Type() Type

Type returns NODE_ATTRIBUTE

type Obj

type Obj interface {
	ID() uint64
	SetID(uint64)
	Name() string
	Element() *Element
	NodeAttribute() Obj
	SetNodeAttribute(na Obj)
	IsNode() bool
	Scene() *Scene
	Type() Type
	String() string
	// contains filtered or unexported methods
}

Obj interface version of Object

type Object

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

Object is the top level general class in fbx

func NewObject

func NewObject(scene *Scene, e *Element) *Object

NewObject creates a new object

func (*Object) Element

func (o *Object) Element() *Element

Element gets the Element on the Object

func (*Object) ID

func (o *Object) ID() uint64

ID returns the Object's integer id value

func (*Object) IsNode

func (o *Object) IsNode() bool

IsNode ret[urns whether this is a node

func (*Object) Name

func (o *Object) Name() string

Name gets the Objects Name

func (*Object) NodeAttribute

func (o *Object) NodeAttribute() Obj

NodeAttribute should be deprecated and in favor of exporting the attribute

func (*Object) Scene

func (o *Object) Scene() *Scene

Scene returns the scene used for the object

func (*Object) SetID

func (o *Object) SetID(i uint64)

SetID sets the Objects ID

func (*Object) SetNodeAttribute

func (o *Object) SetNodeAttribute(na Obj)

SetNodeAttribute sets the attribute but should just exported field

func (*Object) String

func (o *Object) String() string

type Property

type Property struct {
	Count int
	Type  PropertyType

	Encoding uint32
	// contains filtered or unexported fields
}

A Property is template class is used to ensure that the data of a FbxObject is strongly typed

func (*Property) String

func (p *Property) String() string

type PropertyType

type PropertyType rune

PropertyType is a mapping of letter to data type

const (
	BOOL        PropertyType = 'C'
	INT16       PropertyType = 'Y'
	LONG        PropertyType = 'L'
	INTEGER     PropertyType = 'I'
	STRING      PropertyType = 'S'
	RAWSTRING   PropertyType = 'R'
	FLOAT       PropertyType = 'F'
	DOUBLE      PropertyType = 'D'
	ArrayDOUBLE PropertyType = 'd'
	ArrayINT    PropertyType = 'i'
	ArrayLONG   PropertyType = 'l'
	ArrayFLOAT  PropertyType = 'f'
	ArrayBOOL   PropertyType = 'b'
	ArrayBYTE   PropertyType = 'c'
)

Property types block

func (PropertyType) IsArray

func (pt PropertyType) IsArray() bool

IsArray checks whether the property is an array

func (PropertyType) Size

func (pt PropertyType) Size() int

Size returns the current property type's size

type Quat

type Quat struct {
	X, Y, Z float64
	// contains filtered or unexported fields
}

Quat probably can bve removed

type RotationOrder

type RotationOrder int

RotationOrder determines the dimension order for rotation

const (
	EulerXYZ   RotationOrder = iota
	EulerXZY   RotationOrder = iota
	EulerYZX   RotationOrder = iota
	EulerYXZ   RotationOrder = iota
	EulerZXY   RotationOrder = iota
	EulerZYX   RotationOrder = iota
	SphericXYZ RotationOrder = iota // Currently unsupported. Treated as EulerXYZ.
)

A block of rotation order sets

type Scene

type Scene struct {
	RootElement *Element
	RootNode    *Node
	FrameRate   float32 // = -1
	Settings
	ObjectMap       map[uint64]Obj
	Meshes          []*Mesh
	AnimationStacks []*AnimationStack
	Connections     []Connection
	TakeInfos       []TakeInfo
}

A Scene is an overarching FBX costruct containing objects and animations

func Load

func Load(r io.Reader) (*Scene, error)

Load tries to load a scene

func (*Scene) Geometries

func (s *Scene) Geometries() []*Geometry

Geometries returns a scene's geometries

func (*Scene) String

func (s *Scene) String() string

type Settings

type Settings struct {
	UpAxis                  UpVector
	UpAxisSign              int
	FrontAxis               FrontVector
	FrontAxisSign           int
	CoordAxis               CoordSystem
	CoordAxisSign           int
	OriginalUpAxis          int
	OriginalUpAxisSign      int
	UnitScaleFactor         float32
	OriginalUnitScaleFactor float32
	TimeSpanStart           uint64
	TimeSpanStop            uint64
	TimeMode                FrameRate
	CustomFrameRate         float32
}

Settings is the overall scene fbx settings

type Skin

type Skin struct {
	Object
	Clusters []*Cluster
}

Skin is a mapping for textures that denotes the control points to act on

func NewSkin

func NewSkin(scene *Scene, element *Element) *Skin

NewSkin creates a new skin

func (*Skin) String

func (s *Skin) String() string

func (*Skin) Type

func (s *Skin) Type() Type

Type returns skin as type

type TakeInfo

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

TakeInfo is a set of data for a time data set

func (*TakeInfo) String

func (t *TakeInfo) String() string

type Texture

type Texture struct {
	Object
	// contains filtered or unexported fields
}

Texture is a texture file on an object

func NewTexture

func NewTexture(scene *Scene, element *Element) *Texture

NewTexture creates a texture

func (*Texture) GetFileName added in v1.0.1

func (t *Texture) GetFileName() string

func (*Texture) GetRelativeFileName added in v1.0.1

func (t *Texture) GetRelativeFileName() *DataView

func (*Texture) String

func (t *Texture) String() string

func (*Texture) Type

func (t *Texture) Type() Type

Type returns Texture

type TextureType

type TextureType int

TextureType determines how a texture be used

const (
	DIFFUSE      TextureType = iota
	NORMAL       TextureType = iota
	TextureCOUNT TextureType = iota
)

Texture type block

type Type

type Type int

Type of the object

const (
	ROOT                 Type = iota
	GEOMETRY             Type = iota
	MATERIAL             Type = iota
	MESH                 Type = iota
	TEXTURE              Type = iota
	LIMB_NODE            Type = iota
	NULL_NODE            Type = iota
	NODE_ATTRIBUTE       Type = iota
	CLUSTER              Type = iota
	SKIN                 Type = iota
	ANIMATION_STACK      Type = iota
	ANIMATION_LAYER      Type = iota
	ANIMATION_CURVE      Type = iota
	ANIMATION_CURVE_NODE Type = iota
	NOTYPE               Type = iota
)

Types of objects

func (Type) String

func (t Type) String() string

type UpVector

type UpVector int

UpVector specifies which canonical axis represents up in the system (typically Y or Z).

const (
	UpVectorX UpVector = 1
	UpVectorY UpVector = 2
	UpVectorZ UpVector = 3
)

UpVector Options

type Vertex

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

Vertex hey wit its a linked list of indices!.....

type VertexDataMapping

type VertexDataMapping int

VertexDataMapping dictates how the vertex is mapped

const (
	ByPolygonVertex VertexDataMapping = iota
	ByPolygon       VertexDataMapping = iota
	ByVertex        VertexDataMapping = iota
)

VertexDataMapping Options

Jump to

Keyboard shortcuts

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