mqo

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Save added in v0.3.1

func Save(doc *Document, path string) error

func SaveMQOZ added in v0.3.1

func SaveMQOZ(doc *Document, path string) error

func UpdateBoneRef

func UpdateBoneRef(bones []*BoneOld)

func WriteMQX

func WriteMQX(mqo *Document, w io.Writer, mqoName string) error

Types

type Bone

type Bone struct {
	ID       int          `xml:"id,attr"`
	Name     string       `xml:"name,attr"`
	Group    int          `xml:"group,attr,omitempty"`
	Parent   int          `xml:"parent,attr,omitempty"`
	Pos      Vector3Attr  `xml:"pos,attr,omitempty"`
	Movable  int          `xml:"movable,attr,omitempty"`
	Hide     int          `xml:"hide,attr,omitempty"`
	Dummy    int          `xml:"dummy,attr,omitempty"`
	Color    string       `xml:"color,attr,omitempty"`
	UpVector *Vector3Attr `xml:"upVector,attr,omitempty"`
	Rotate   *Vector3Attr `xml:"rotate,attr,omitempty"`

	IK *BoneIK `xml:"IK,omitempty"`

	Weights []*BoneWeight2 `xml:"W"`

	// internal use
	RotationOffset Vector3 `xml:"-"`
	// contains filtered or unexported fields
}

func (*Bone) SetVertexWeight

func (b *Bone) SetVertexWeight(objectID, vertID int, weight float32) *VertexWeight

type BoneIK

type BoneIK struct {
	ChainCount int `xml:"chain,attr"`

	// MMD
	Name    string `xml:"name,attr"`
	TipName string `xml:"tipName,attr"`
}

type BoneObj

type BoneObj struct {
	ID int `xml:"id,attr"`
}

type BoneOld

type BoneOld struct {
	ID      int    `xml:"id,attr"`
	Name    string `xml:"name,attr"`
	Group   int    `xml:"group,attr"`
	IsDummy int    `xml:"isDummy,attr"`

	RtX float32 `xml:"rtX,attr"`
	RtY float32 `xml:"rtY,attr"`
	RtZ float32 `xml:"rtZ,attr"`
	TpX float32 `xml:"tpX,attr"`
	TpY float32 `xml:"tpY,attr"`
	TpZ float32 `xml:"tpZ,attr"`

	MvX float32 `xml:"mvX,attr"`
	MvY float32 `xml:"mvY,attr"`
	MvZ float32 `xml:"mvZ,attr"`

	RotB float32 `xml:"rotB,attr"`
	RotH float32 `xml:"rotH,attr"`
	RotP float32 `xml:"rotP,attr"`

	Sc float32 `xml:"sc,attr"`

	MaxAngB float32 `xml:"maxAngB,attr"`
	MaxAngH float32 `xml:"maxAngH,attr"`
	MaxAngP float32 `xml:"maxAngP,attr"`

	MinAngB float32 `xml:"minAngB,attr"`
	MinAngH float32 `xml:"minAngH,attr"`
	MinAngP float32 `xml:"minAngP,attr"`

	Parent   BoneRef    `xml:"P"`
	Children []*BoneRef `xml:"C"`

	Weights []*BoneWeight `xml:"W"`
}

type BonePlugin

type BonePlugin struct {
	XMLName xml.Name `xml:"Plugin.56A31D20.71F282AB"`

	Name     string `xml:"name,attr"`
	BoneSet  BoneSet
	BoneSet2 BoneSet2
	PoseSet  PoseSet `xml:"Poses"`
	Obj      []BoneObj
}

func GetBonePlugin

func GetBonePlugin(mqo *Document) *BonePlugin

func (*BonePlugin) AddBone

func (p *BonePlugin) AddBone(b *Bone)

func (*BonePlugin) ApplyTransform added in v0.3.3

func (p *BonePlugin) ApplyTransform(transform *Matrix4)

func (*BonePlugin) Bones

func (p *BonePlugin) Bones() []*Bone

func (*BonePlugin) PostDeserialize

func (p *BonePlugin) PostDeserialize(mqo *Document)

func (*BonePlugin) PreSerialize

func (p *BonePlugin) PreSerialize(mqo *Document)

func (*BonePlugin) SetBones

func (p *BonePlugin) SetBones(bones []*Bone)

type BonePose

type BonePose struct {
	// oneof
	ID   int    `xml:"id,attr"`
	Name string `xml:"name,attr"`

	// Translation
	MvX float32 `xml:"mvX,attr"`
	MvY float32 `xml:"mvY,attr"`
	MvZ float32 `xml:"mvZ,attr"`

	// Rotation
	RotB float32 `xml:"rotB,attr"`
	RotH float32 `xml:"rotH,attr"`
	RotP float32 `xml:"rotP,attr"`

	// Scale
	ScB float32 `xml:"scB,attr"`
	ScH float32 `xml:"scH,attr"`
	ScP float32 `xml:"scP,attr"`
}

type BoneRef

type BoneRef struct {
	ID int `xml:"id,attr"`
}

type BoneSet

type BoneSet struct {
	Bone []*BoneOld
}

type BoneSet2

type BoneSet2 struct {
	Limit int     `xml:"limit,attr"`
	Bones []*Bone `xml:"Bone"`
}

type BoneWeight

type BoneWeight struct {
	ObjectID int     `xml:"oi,attr"`
	VertexID int     `xml:"vi,attr"`
	Weight   float32 `xml:"w,attr"`
}

type BoneWeight2

type BoneWeight2 struct {
	ObjectID int             `xml:"obj,attr"`
	Vertexes []*VertexWeight `xml:"V"`
}

type Document added in v0.2.1

type Document struct {
	Scene     *Scene
	Materials []*Material
	Objects   []*Object

	Plugins []Plugin
}

func Load added in v0.3.1

func Load(path string) (*Document, error)

func LoadMQOZ added in v0.3.1

func LoadMQOZ(path string) (*Document, error)

func NewDocument

func NewDocument() *Document

func (*Document) ApplyTransform added in v0.3.3

func (doc *Document) ApplyTransform(transform *Matrix4)

Transform all objects and plugins

func (*Document) BoneAdjustX added in v0.2.2

func (doc *Document) BoneAdjustX(baseBone *Bone)

for T-Pose adjustment TODO: more generic function.

func (*Document) BoneTransform added in v0.2.3

func (doc *Document) BoneTransform(baseBone *Bone, transform func(v *Vector3), boneFn func(b *Bone))

func (*Document) FixNames added in v0.3.2

func (doc *Document) FixNames()

func (*Document) FixObjectID added in v0.2.1

func (doc *Document) FixObjectID()

func (*Document) GetObjectByID added in v0.2.2

func (doc *Document) GetObjectByID(id int) *Object

func (*Document) GetPlugins added in v0.2.1

func (doc *Document) GetPlugins() []Plugin

func (*Document) GetWorldTransforms added in v0.3.5

func (doc *Document) GetWorldTransforms() map[*Object]*Matrix4

type Face

type Face struct {
	UID      int
	Verts    []int
	Material int
	UVs      []Vector2
	Normals  []*Vector3
}

func (*Face) Flip added in v0.3.1

func (f *Face) Flip()

type MQXDoc

type MQXDoc struct {
	XMLName    xml.Name `xml:"MetasequoiaDocument"`
	IncludedBy string

	Plugins []Plugin
}

func ReadMQX

func ReadMQX(r io.Reader) (*MQXDoc, error)

type Material

type Material struct {
	Name  string
	UID   int
	Color Vector4

	Diffuse  float32
	Ambient  float32
	Emission float32
	Specular float32
	Power    float32

	Texture      string
	BumpTexture  string
	AlphaTexture string

	EmissionColor *Vector3

	DoubleSided bool

	Shader int
	Ex2    *MaterialEx2
}

func (*Material) GetShaderName added in v0.3.0

func (m *Material) GetShaderName() string

type MaterialEx2

type MaterialEx2 struct {
	ShaderType          string
	ShaderName          string
	ShaderParams        map[string]interface{}
	ShaderMappingParams map[string]map[string]interface{}
}

func (*MaterialEx2) FloatParam added in v0.2.1

func (m *MaterialEx2) FloatParam(name string) float64

func (*MaterialEx2) IntParam added in v0.2.1

func (m *MaterialEx2) IntParam(name string) int

func (*MaterialEx2) StringParam added in v0.2.1

func (m *MaterialEx2) StringParam(name string) string

type Matrix4 added in v0.3.3

type Matrix4 = geom.Matrix4

type MorphPlugin

type MorphPlugin struct {
	XMLName xml.Name `xml:"Plugin.56A31D20.C452C6DB"`

	Name     string `xml:"name,attr"`
	MorphSet MorphSet
}

func GetMorphPlugin

func GetMorphPlugin(mqo *Document) *MorphPlugin

func (*MorphPlugin) Morphs added in v0.2.0

func (p *MorphPlugin) Morphs() []*MorphTargetList

func (*MorphPlugin) PostDeserialize

func (p *MorphPlugin) PostDeserialize(mqo *Document)

func (*MorphPlugin) PreSerialize

func (p *MorphPlugin) PreSerialize(mqo *Document)

type MorphSet

type MorphSet struct {
	Targets []*MorphTargetList `xml:"TargetList"`
}

type MorphTarget

type MorphTarget struct {
	Name  string `xml:"name,attr"`
	Param int    `xml:"param,attr"`
}

type MorphTargetList

type MorphTargetList struct {
	Base   string `xml:"base,attr"`
	Target []*MorphTarget
}

type Object

type Object struct {
	UID          int
	Name         string
	Vertexes     []*Vector3
	Faces        []*Face
	Visible      bool
	Locked       bool
	Depth        int
	Folding      bool
	Shading      int
	Facet        float32
	Patch        int
	PatchSegment int
	Mirror       int
	MirrorDis    float32

	Scale       *Vector3
	Rotation    *Vector3 // TODO: EulerAngles
	Translation *Vector3

	Color *Vector3

	VertexByUID map[int]int

	// Internal use
	SharedGeometryHint *SharedGeometryHint
}

func NewObject

func NewObject(name string) *Object

func (*Object) ApplyTransform added in v0.3.3

func (o *Object) ApplyTransform(transform *Matrix4)

Transform object

func (*Object) Clone

func (o *Object) Clone() *Object

func (*Object) FixhNormals added in v0.3.2

func (obj *Object) FixhNormals()

func (*Object) GetLocalTransform added in v0.3.5

func (o *Object) GetLocalTransform() *geom.Matrix4

func (*Object) GetRotation added in v0.3.5

func (o *Object) GetRotation() *geom.Quaternion

func (*Object) GetSmoothNormals added in v0.2.3

func (obj *Object) GetSmoothNormals() []Vector3

func (*Object) GetVertexIndexByID added in v0.2.1

func (o *Object) GetVertexIndexByID(uid int) int

func (*Object) SetLocalTransform added in v0.3.5

func (o *Object) SetLocalTransform(mat *geom.Matrix4)

func (*Object) SetRotation added in v0.3.5

func (o *Object) SetRotation(r *geom.Quaternion)

func (*Object) Triangulate added in v0.3.2

func (o *Object) Triangulate()

type Parser

type Parser struct {
	Open func(name string) (io.ReadCloser, error)
	// contains filtered or unexported fields
}

Parser for mqo file.

func NewParser

func NewParser(r io.Reader, path string) *Parser

NewParser returns new parser.

func (*Parser) Parse

func (p *Parser) Parse() (*Document, error)

type PhysicsBody added in v0.3.5

type PhysicsBody struct {
	Shapes []*PhysicsShape `xml:"Shapes>Shape"`

	Mass           float32 `xml:"mass,attr"`
	Kinematic      bool    `xml:"kinematic,attr,omitempty"`
	CollisionGroup int
	CollisionMask  int

	// TODO: PhysicsMaterial
	Restitution    float32
	Friction       float32
	LinearDamping  float32
	AngularDamping float32

	// optional
	Name         string `xml:"name,attr,omitempty"`
	TargetBoneID int    `xml:"targetBone,attr,omitempty"`
	TargetObjID  int    `xml:"targetObj,attr,omitempty"`
}

type PhysicsJointConstraint added in v0.3.5

type PhysicsJointConstraint struct {
	Type  string `xml:"type,attr,omitempty"`
	Body1 int    `xml:"body1,attr,omitempty"`
	Body2 int    `xml:"body2,attr,omitempty"`

	Name string `xml:"name,attr,omitempty"` // optional

	// Spring joint
	Position      Vector3XmlAttr
	Rotation      Vector3XmlAttr
	LinerSpring   Vector3XmlAttr
	AngulerSpring Vector3XmlAttr
}

type PhysicsPlugin added in v0.3.5

type PhysicsPlugin struct {
	XMLName xml.Name `xml:"Plugin.7A6E6962.43594850"`
	Name    string   `xml:"name,attr"`

	Bodies      []*PhysicsBody            `xml:"Bodies>Body"`
	Constraints []*PhysicsJointConstraint `xml:"Constraints>Joint"`
}

Fake plugin for keeping physics params

func GetPhysicsPlugin added in v0.3.5

func GetPhysicsPlugin(mqo *Document) *PhysicsPlugin

func (*PhysicsPlugin) ApplyTransform added in v0.3.5

func (p *PhysicsPlugin) ApplyTransform(transform *Matrix4)

func (*PhysicsPlugin) PostDeserialize added in v0.3.5

func (p *PhysicsPlugin) PostDeserialize(mqo *Document)

func (*PhysicsPlugin) PreSerialize added in v0.3.5

func (p *PhysicsPlugin) PreSerialize(mqo *Document)

type PhysicsShape added in v0.3.5

type PhysicsShape struct {
	Type     string `xml:"type,attr"` // BOX | SPHERE | CAPSULE | CYLINDER | MESH
	Size     Vector3XmlAttr
	Position Vector3XmlAttr
	Rotation Vector3XmlAttr
}

type Plugin

type Plugin interface {
	PreSerialize(mqo *Document)
	PostDeserialize(mqo *Document)
}

type PoseSet

type PoseSet struct {
	BonePoses []*BonePose `xml:"Pose"`
}

type Scene

type Scene struct {
	CameraPos    Vector3
	CameraLookAt Vector3
	CameraRot    Vector3
	Zoom2        float32
	FrontClip    float32
	BackClip     float32
	Ortho        bool

	AmbientLight *Vector3
}

type SharedGeometryHint added in v0.3.3

type SharedGeometryHint struct {
	Key       string
	Transform *geom.Matrix4
}

type Vector2

type Vector2 = geom.Vector2

type Vector3

type Vector3 = geom.Vector3

type Vector3Attr added in v0.3.0

type Vector3Attr struct{ Vector3 }

func (*Vector3Attr) MarshalXMLAttr added in v0.3.0

func (v *Vector3Attr) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

func (*Vector3Attr) UnmarshalXMLAttr added in v0.3.0

func (v *Vector3Attr) UnmarshalXMLAttr(attr xml.Attr) error

type Vector3XmlAttr added in v0.3.5

type Vector3XmlAttr struct {
	X geom.Element `xml:"x,attr"`
	Y geom.Element `xml:"y,attr"`
	Z geom.Element `xml:"z,attr"`
}

func (*Vector3XmlAttr) Vec3 added in v0.3.5

func (v *Vector3XmlAttr) Vec3() *Vector3

type Vector4

type Vector4 = geom.Vector4

type VertexWeight

type VertexWeight struct {
	VertexID int     `xml:"v,attr"`
	Weight   float32 `xml:"w,attr"`
}

type Writer added in v0.3.1

type Writer struct {
	Create func(name string) (io.WriteCloser, error)
	// contains filtered or unexported fields
}

func NewWriter added in v0.3.1

func NewWriter(path string) *Writer

func (*Writer) WriteMQO added in v0.3.1

func (writer *Writer) WriteMQO(mqo *Document, ww io.Writer) error

Jump to

Keyboard shortcuts

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