scw

package
v0.0.0-...-dda0d94 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidSCWMagic expected magic is to be SC3D (first 4 bytes of the File)
	ErrInvalidSCWMagic = errors.New("invalid scw file magic")
)

Functions

func EncodeSc3dProperty

func EncodeSc3dProperty(prop Sc3dProperty, writer *Writer)

Types

type Camera3D

type Camera3D struct {
	Name        string
	Yfov, Xfov  float32 // not sure...
	AspectRatio float32
	ZNear, ZFar float32
}

func (*Camera3D) Decode

func (c *Camera3D) Decode(reader *Reader) (err error)

func (*Camera3D) Encode

func (c *Camera3D) Encode(writer *Writer)

func (*Camera3D) Tag

func (c *Camera3D) Tag() string

type File

type File struct {
	Header
	Materials  []*Material
	Geometries []*Geometry
	Scene
	Cameras      []*Camera3D
	MinorVersion int // used for versions under 2
	// contains filtered or unexported fields
}

func New

func New(data []byte) *File

func (*File) Encode

func (f *File) Encode() []byte

func (*File) Load

func (f *File) Load() (err error)

Load loads a File, for now support of scw version 2 is under development

in the future support for version 1 is planned.

func (*File) LoadJSON

func (f *File) LoadJSON() (err error)

type Geometry

type Geometry struct {
	SCWFile *File `json:"-"`
	Name    string
	Group   string
	// this was used in older versions of scw format
	IgnoredMatrix Matrix4x4
	Vertices      []SourceArray
	HasBindMatrix bool
	BindMatrix    Matrix4x4
	Skins         struct {
		Joints              []string
		InverseBindMatrices []Matrix4x4
	}
	SkinWeights []Weight
	Materials   []IndexArray
}

func (*Geometry) Decode

func (g *Geometry) Decode(reader *Reader) (err error)

func (*Geometry) Encode

func (g *Geometry) Encode(writer *Writer)

func (*Geometry) Tag

func (g *Geometry) Tag() string
type Header struct {
	Version       uint16
	FrameRate     uint16
	FirstFrame    uint16
	LastFrame     uint16
	MaterialsFile string
	Unknown       int
}

func (*Header) Decode

func (h *Header) Decode(reader *Reader) (err error)

func (*Header) Encode

func (h *Header) Encode(writer *Writer)

func (*Header) Tag

func (h *Header) Tag() string

type IndexArray

type IndexArray struct {
	Name            string
	IndexBufferSize byte
	IndexBuffer     []uint32
	TrianglesCount  uint32
	InputsCount     byte
}

func (*IndexArray) Decode

func (i *IndexArray) Decode(reader *Reader) (err error)

func (*IndexArray) Encode

func (i *IndexArray) Encode(writer *Writer)

type InstanceMaterial

type InstanceMaterial struct {
	Name, Target string
}

func (*InstanceMaterial) Decode

func (i *InstanceMaterial) Decode(reader *Reader) (err error)

func (*InstanceMaterial) Encode

func (i *InstanceMaterial) Encode(writer *Writer)

type KeyFrame

type KeyFrame struct {
	ID                 uint16
	Rotation           Quaternion
	Translation, Scale Vector3
}

func (*KeyFrame) Decode

func (f *KeyFrame) Decode(reader *Reader, u8 uint8, v58 uint16, Frames []KeyFrame) (err error)

func (*KeyFrame) Encode

func (f *KeyFrame) Encode(writer *Writer, u8 uint8, v58 uint16, Frames []KeyFrame)

type Material

type Material struct {
	SCWFile    *File `json:"-"`
	Name       string
	ShaderFile string
	BlendMode  byte
	Variables  struct {
		Ambient                                    Variable
		Diffuse                                    Variable
		Specular                                   Variable
		StencilTex2D                               string
		NormalTex2D                                string
		Colorize                                   Variable
		Emission                                   Variable
		OpacityTex2D                               string
		Opacity, Unk                               float32
		LightmapTex2D, LightmapSpecularTex2D, Unk2 string
	}
	ShaderConfig       uint32
	StencilScaleOffset [4]float32
}

func (*Material) Decode

func (m *Material) Decode(reader *Reader) (err error)

func (*Material) Encode

func (m *Material) Encode(writer *Writer)

func (*Material) Tag

func (m *Material) Tag() string

type Matrix4x4

type Matrix4x4 [4][4]float32

func (*Matrix4x4) Decode

func (m *Matrix4x4) Decode(reader *Reader) (err error)

func (*Matrix4x4) Encode

func (m *Matrix4x4) Encode(writer *Writer)

func (*Matrix4x4) Transpose

func (m *Matrix4x4) Transpose()

type Node

type Node struct {
	SCWFile          *File `json:"-"`
	Name, ParentName string
	Instances        []NodeInstance
	Frames           []KeyFrame
	FramesFlags      byte
}

func (*Node) Decode

func (n *Node) Decode(reader *Reader) (err error)

func (*Node) Encode

func (n *Node) Encode(writer *Writer)

type NodeInstance

type NodeInstance struct {
	Type, Target string
	CameraTarget string
	Materials    []InstanceMaterial
}

func (*NodeInstance) Decode

func (n *NodeInstance) Decode(reader *Reader) (err error)

func (*NodeInstance) Encode

func (n *NodeInstance) Encode(writer *Writer)

type Quaternion

type Quaternion struct {
	Vector3
	W float32
}

Quaternion q= w + xi + yj + zk

w is the scalar component

x, y and z are the vector components

func (*Quaternion) Equals

func (q *Quaternion) Equals(other *Quaternion) bool

type RGBA

type RGBA [4]byte

func (*RGBA) Decode

func (r *RGBA) Decode(reader *Reader) (err error)

func (*RGBA) Encode

func (r *RGBA) Encode(writer *Writer)

type Reader

type Reader struct {
	SkipBytes int
	// contains filtered or unexported fields
}

func NewReader

func NewReader(data []byte) *Reader

func (*Reader) Read

func (r *Reader) Read(n int) ([]byte, error)

func (*Reader) ReadBool

func (r *Reader) ReadBool() (bool, error)

func (*Reader) ReadFloat

func (r *Reader) ReadFloat() (float32, error)

func (*Reader) ReadI16

func (r *Reader) ReadI16() (int16, error)

func (*Reader) ReadU16

func (r *Reader) ReadU16() (uint16, error)

func (*Reader) ReadU32

func (r *Reader) ReadU32() (uint32, error)

func (*Reader) ReadU8

func (r *Reader) ReadU8() (uint8, error)

func (*Reader) ReadUTF

func (r *Reader) ReadUTF() (string, error)

func (*Reader) ReadUTFWithLength

func (r *Reader) ReadUTFWithLength(length uint16) (string, error)

func (*Reader) Seek

func (r *Reader) Seek(n int)

type Sc3dProperty

type Sc3dProperty interface {
	Tag() string
	Encode(writer *Writer)
}

type Scene

type Scene struct {
	Nodes []Node
}

func (*Scene) Encode

func (s *Scene) Encode(writer *Writer)

func (*Scene) Tag

func (s *Scene) Tag() string

type SourceArray

type SourceArray struct {
	Name        string
	Index       byte
	SourceIndex byte      // uh, it is used for TEXTCOORD I think?
	Stride      byte      // stride(Color) / element size
	Scale       float32   // this can always be 0?? (not saying it is)
	Data        []float64 // vertex/coordinate data?
}

func (*SourceArray) Decode

func (s *SourceArray) Decode(reader *Reader) (err error)

func (*SourceArray) Encode

func (s *SourceArray) Encode(writer *Writer)

type Variable

type Variable struct {
	UseText2D bool
	Texture2D string
	Color     RGBA
}

func (*Variable) Decode

func (v *Variable) Decode(reader *Reader) error

func (*Variable) Encode

func (v *Variable) Encode(writer *Writer)

type Vector3

type Vector3 struct {
	X, Y, Z float32
}

func (*Vector3) Equals

func (v *Vector3) Equals(other *Vector3) bool

type Weight

type Weight struct {
	Joints  [4]byte
	Weights [4]uint16
}

func (*Weight) Decode

func (w *Weight) Decode(reader *Reader, scwVersion uint16, scwMinorVersion int) (err error)

func (*Weight) Encode

func (w *Weight) Encode(writer *Writer, scwVersion uint16, scwMinorVersion int)

type Wend

type Wend struct{}

Wend stop tag for scw parser

func (*Wend) Encode

func (w *Wend) Encode(_ *Writer)

func (*Wend) Tag

func (w *Wend) Tag() string

type Writer

type Writer struct {
	bytes.Buffer
}

func NewWriter

func NewWriter() *Writer

func (*Writer) WriteBool

func (w *Writer) WriteBool(value bool)

func (*Writer) WriteBytes

func (w *Writer) WriteBytes(bytes []byte)

func (*Writer) WriteFloat

func (w *Writer) WriteFloat(value float32)

func (*Writer) WriteI16

func (w *Writer) WriteI16(value int16)

func (*Writer) WriteStringChars

func (w *Writer) WriteStringChars(str string)

func (*Writer) WriteStringUTF

func (w *Writer) WriteStringUTF(str string)

func (*Writer) WriteU16

func (w *Writer) WriteU16(value uint16)

func (*Writer) WriteU32

func (w *Writer) WriteU32(value uint32)

func (*Writer) WriteU8

func (w *Writer) WriteU8(b byte)

Jump to

Keyboard shortcuts

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