Skip to content

Commit

Permalink
Add prelim eqg mds, mod, ter support
Browse files Browse the repository at this point in the history
  • Loading branch information
xackery committed Sep 4, 2024
1 parent 5f55d5b commit 4ec7635
Show file tree
Hide file tree
Showing 28 changed files with 1,347 additions and 252 deletions.
12 changes: 3 additions & 9 deletions quail/dir_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@ func (q *Quail) DirRead(path string) error {

baseName := filepath.Base(path)
baseName = strings.TrimSuffix(baseName, ".quail")
q.Wld = &wce.Wce{
FileName: baseName + ".wld",
}
q.Wld = wce.New(baseName + ".wld")
err = q.Wld.ReadAscii(path + "/_root.wce")
if err != nil {
return err
}

fi, err = os.Stat(path + "/_objects/_root.wce")
if err == nil && !fi.IsDir() {
q.WldObject = &wce.Wce{
FileName: baseName + "objects.wld",
}
q.WldObject = wce.New(baseName + "objects.wld")
err = q.WldObject.ReadAscii(path + "/_objects/_root.wce")
if err != nil {
return err
Expand All @@ -51,9 +47,7 @@ func (q *Quail) DirRead(path string) error {

fi, err = os.Stat(path + "/_lights/_root.wce")
if err == nil && !fi.IsDir() {
q.WldLights = &wce.Wce{
FileName: baseName + "lights.wld",
}
q.WldLights = wce.New(baseName + "lights.wld")
err = q.WldLights.ReadAscii(path + "/_lights/_root.wce")
if err != nil {
return err
Expand Down
6 changes: 2 additions & 4 deletions quail/pfs_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ func (q *Quail) PfsRead(path string) error {
return fmt.Errorf("wld read: %w", err)
}

q.Wld = &wce.Wce{
FileName: filepath.Base(path) + ".wld",
}
q.Wld = wce.New(filepath.Base(path))

err = q.Wld.ReadRaw(rawWld)
err = q.Wld.ReadWldRaw(rawWld)
if err != nil {
return fmt.Errorf("wld read: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions quail/pfs_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (e *Quail) S3DExport(fileVersion uint32, pfsVersion int, path string) error
if e.Wld != nil {
buf := &bytes.Buffer{}

err := e.Wld.WriteRaw(buf)
err := e.Wld.WriteWldRaw(buf)
if err != nil {
return fmt.Errorf("write wld: %w", err)
}
Expand All @@ -191,7 +191,7 @@ func (e *Quail) S3DExport(fileVersion uint32, pfsVersion int, path string) error
if e.WldObject != nil {
buf := &bytes.Buffer{}

err := e.WldObject.WriteRaw(buf)
err := e.WldObject.WriteWldRaw(buf)
if err != nil {
return fmt.Errorf("write wld: %w", err)
}
Expand All @@ -206,7 +206,7 @@ func (e *Quail) S3DExport(fileVersion uint32, pfsVersion int, path string) error
if e.WldLights != nil {
buf := &bytes.Buffer{}

err := e.WldLights.WriteRaw(buf)
err := e.WldLights.WriteWldRaw(buf)
if err != nil {
return fmt.Errorf("write wld: %w", err)
}
Expand Down
48 changes: 24 additions & 24 deletions quail/raw_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ func (q *Quail) modConvertMesh(in *raw.Mod) (*common.Model, error) {
for _, triangle := range in.Triangles {
model.Triangles = append(model.Triangles, common.Triangle{
Index: common.UIndex3{
X: uint32(triangle.Index.X),
Y: uint32(triangle.Index.Y),
Z: uint32(triangle.Index.Z),
X: uint32(triangle.Index[0]),
Y: uint32(triangle.Index[1]),
Z: uint32(triangle.Index[2]),
},
MaterialName: triangle.MaterialName,
Flag: uint32(triangle.Flag),
Expand All @@ -163,19 +163,19 @@ func (q *Quail) modConvertMesh(in *raw.Mod) (*common.Model, error) {
for _, vertex := range in.Vertices {
model.Vertices = append(model.Vertices, common.Vertex{
Position: common.Vector3{
X: vertex.Position.X,
Y: vertex.Position.Y,
Z: vertex.Position.Z,
X: vertex.Position[0],
Y: vertex.Position[1],
Z: vertex.Position[2],
},
Uv: common.Vector2{
X: vertex.Uv.X,
Y: vertex.Uv.Y,
X: vertex.Uv[0],
Y: vertex.Uv[1],
},
Tint: common.RGBA{
R: vertex.Tint.R,
G: vertex.Tint.G,
B: vertex.Tint.B,
A: vertex.Tint.A,
R: vertex.Tint[0],
G: vertex.Tint[1],
B: vertex.Tint[2],
A: vertex.Tint[3],
},
})
}
Expand Down Expand Up @@ -206,9 +206,9 @@ func (q *Quail) mdsConvertMesh(in *raw.Mds) (*common.Model, error) {
for _, triangle := range in.Triangles {
model.Triangles = append(model.Triangles, common.Triangle{
Index: common.UIndex3{
X: uint32(triangle.Index.X),
Y: uint32(triangle.Index.Y),
Z: uint32(triangle.Index.Z),
X: uint32(triangle.Index[0]),
Y: uint32(triangle.Index[1]),
Z: uint32(triangle.Index[2]),
},
MaterialName: triangle.MaterialName,
Flag: uint32(triangle.Flag),
Expand All @@ -217,19 +217,19 @@ func (q *Quail) mdsConvertMesh(in *raw.Mds) (*common.Model, error) {
for _, vertex := range in.Vertices {
model.Vertices = append(model.Vertices, common.Vertex{
Position: common.Vector3{
X: vertex.Position.X,
Y: vertex.Position.Y,
Z: vertex.Position.Z,
X: vertex.Position[0],
Y: vertex.Position[1],
Z: vertex.Position[2],
},
Uv: common.Vector2{
X: vertex.Uv.X,
Y: vertex.Uv.Y,
X: vertex.Uv[0],
Y: vertex.Uv[1],
},
Tint: common.RGBA{
R: vertex.Tint.R,
G: vertex.Tint.G,
B: vertex.Tint.B,
A: vertex.Tint.A,
R: vertex.Tint[0],
G: vertex.Tint[1],
B: vertex.Tint[2],
A: vertex.Tint[3],
},
})
}
Expand Down
6 changes: 2 additions & 4 deletions quail/raw_read_wld.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import (

func (q *Quail) wldRead(srcWld *raw.Wld, filename string) error {

wld := &wce.Wce{
FileName: filename,
}
err := wld.ReadRaw(srcWld)
wld := wce.New(filename)
err := wld.ReadWldRaw(srcWld)
if err != nil {
return fmt.Errorf("read wld: %w", err)
}
Expand Down
55 changes: 27 additions & 28 deletions raw/mds_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/xackery/encdec"
"github.com/xackery/quail/helper"
"github.com/xackery/quail/model"
)

type Mds struct {
Expand Down Expand Up @@ -114,16 +113,16 @@ func (mds *Mds) Read(r io.ReadSeeker) error {
bone.Next = dec.Int32()
bone.ChildrenCount = dec.Uint32()
bone.ChildIndex = dec.Int32()
bone.Pivot.X = dec.Float32()
bone.Pivot.Y = dec.Float32()
bone.Pivot.Z = dec.Float32()
bone.Rotation.X = dec.Float32()
bone.Rotation.Y = dec.Float32()
bone.Rotation.Z = dec.Float32()
bone.Rotation.W = dec.Float32()
bone.Scale.X = dec.Float32()
bone.Scale.Y = dec.Float32()
bone.Scale.Z = dec.Float32()
bone.Pivot[0] = dec.Float32()
bone.Pivot[1] = dec.Float32()
bone.Pivot[2] = dec.Float32()
bone.Rotation[0] = dec.Float32()
bone.Rotation[1] = dec.Float32()
bone.Rotation[2] = dec.Float32()
bone.Rotation[3] = dec.Float32()
bone.Scale[0] = dec.Float32()
bone.Scale[1] = dec.Float32()
bone.Scale[2] = dec.Float32()
mds.Bones = append(mds.Bones, bone)
}

Expand All @@ -137,35 +136,35 @@ func (mds *Mds) Read(r io.ReadSeeker) error {

for i := 0; i < int(verticesCount); i++ {
v := &Vertex{}
v.Position.X = dec.Float32()
v.Position.Y = dec.Float32()
v.Position.Z = dec.Float32()
v.Normal.X = dec.Float32()
v.Normal.Y = dec.Float32()
v.Normal.Z = dec.Float32()
v.Position[0] = dec.Float32()
v.Position[1] = dec.Float32()
v.Position[2] = dec.Float32()
v.Normal[0] = dec.Float32()
v.Normal[1] = dec.Float32()
v.Normal[2] = dec.Float32()
if mds.Version <= 2 {
v.Tint = model.RGBA{R: 128, G: 128, B: 128, A: 255}
v.Tint = [4]uint8{128, 128, 128, 255}
} else {
v.Tint = model.RGBA{R: dec.Uint8(), G: dec.Uint8(), B: dec.Uint8(), A: dec.Uint8()}
v.Tint = [4]uint8{dec.Uint8(), dec.Uint8(), dec.Uint8(), dec.Uint8()}
}
v.Uv.X = dec.Float32()
v.Uv.Y = dec.Float32()
v.Uv[0] = dec.Float32()
v.Uv[1] = dec.Float32()
if mds.Version <= 2 {
v.Uv2.X = 0
v.Uv2.Y = 0
v.Uv2[0] = 0
v.Uv2[1] = 0
} else {
v.Uv2.X = dec.Float32()
v.Uv2.Y = dec.Float32()
v.Uv2[0] = dec.Float32()
v.Uv2[1] = dec.Float32()
}

mds.Vertices = append(mds.Vertices, v)
}

for i := 0; i < int(triangleCount); i++ {
t := Triangle{}
t.Index.X = dec.Uint32()
t.Index.Y = dec.Uint32()
t.Index.Z = dec.Uint32()
t.Index[0] = dec.Uint32()
t.Index[1] = dec.Uint32()
t.Index[2] = dec.Uint32()

materialID := dec.Int32()

Expand Down
2 changes: 2 additions & 0 deletions raw/mds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func TestMdsRead(t *testing.T) {
//{eqg: "aam.eqg", file: "aam.mds"}, // PASS
// .mds|1|ae3.mds|ae3.eqg
//{eqg: "ae3.eqg", file: "ae3.mds"}, // PASS
//{eqg: "djf.eqg", file: "djf.mds"}, // PASS
{eqg: "mrd.eqg", file: "mrd.mds"}, // PASS
// .mds|1|bcn.mds|harbingers.eqg
//{eqg: "harbingers.eqg", file: "bcn.mds"}, // PASS
// .mds|1|stnd_gnome_wave.mds|it12095.eqg
Expand Down
52 changes: 26 additions & 26 deletions raw/mds_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ func (mds *Mds) Write(w io.Writer) error {
enc.Int32(bone.Next)
enc.Uint32(bone.ChildrenCount)
enc.Int32(bone.ChildIndex)
enc.Float32(bone.Pivot.X)
enc.Float32(bone.Pivot.Y)
enc.Float32(bone.Pivot.Z)
enc.Float32(bone.Rotation.X)
enc.Float32(bone.Rotation.Y)
enc.Float32(bone.Rotation.Z)
enc.Float32(bone.Scale.X)
enc.Float32(bone.Scale.Y)
enc.Float32(bone.Scale.Z)
enc.Float32(bone.Pivot[0])
enc.Float32(bone.Pivot[1])
enc.Float32(bone.Pivot[2])
enc.Float32(bone.Rotation[0])
enc.Float32(bone.Rotation[1])
enc.Float32(bone.Rotation[2])
enc.Float32(bone.Scale[0])
enc.Float32(bone.Scale[1])
enc.Float32(bone.Scale[2])
enc.Float32(bone.Scale2)
}

Expand All @@ -90,30 +90,30 @@ func (mds *Mds) Write(w io.Writer) error {
enc.Uint32(uint32(len(mds.BoneAssignments)))

for _, vert := range mds.Vertices {
enc.Float32(vert.Position.X)
enc.Float32(vert.Position.Y)
enc.Float32(vert.Position.Z)
enc.Float32(vert.Normal.X)
enc.Float32(vert.Normal.Y)
enc.Float32(vert.Normal.Z)
enc.Float32(vert.Position[0])
enc.Float32(vert.Position[1])
enc.Float32(vert.Position[2])
enc.Float32(vert.Normal[0])
enc.Float32(vert.Normal[1])
enc.Float32(vert.Normal[2])
if mds.Version > 2 {
enc.Uint8(vert.Tint.R)
enc.Uint8(vert.Tint.G)
enc.Uint8(vert.Tint.B)
enc.Uint8(vert.Tint.A)
enc.Uint8(vert.Tint[0])
enc.Uint8(vert.Tint[1])
enc.Uint8(vert.Tint[2])
enc.Uint8(vert.Tint[3])
}
enc.Float32(vert.Uv.X)
enc.Float32(vert.Uv.Y)
enc.Float32(vert.Uv[0])
enc.Float32(vert.Uv[1])
if mds.Version > 2 {
enc.Float32(vert.Uv2.X)
enc.Float32(vert.Uv2.Y)
enc.Float32(vert.Uv2[0])
enc.Float32(vert.Uv2[1])
}
}

for _, tri := range mds.Triangles {
enc.Uint32(tri.Index.X)
enc.Uint32(tri.Index.Y)
enc.Uint32(tri.Index.Z)
enc.Uint32(tri.Index[0])
enc.Uint32(tri.Index[1])
enc.Uint32(tri.Index[2])
matID := int32(0)
for _, mat := range mds.Materials {
if mat.Name == tri.MaterialName {
Expand Down
Loading

0 comments on commit 4ec7635

Please sign in to comment.