-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
260 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,77 @@ | ||
package rawfrag | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/xackery/quail/model" | ||
"github.com/xackery/encdec" | ||
) | ||
|
||
// WldFragDmTrackDef2 is DmTrackDef2 in libeq, Mesh Animated Vertices in openzone, DMTRACKDEF in wld, MeshAnimatedVertices in lantern | ||
type WldFragDmTrackDef2 struct { | ||
NameRef int32 `yaml:"name_ref"` | ||
Flags uint32 `yaml:"flags"` | ||
VertexCount uint16 `yaml:"vertex_count"` | ||
FrameCount uint16 `yaml:"frame_count"` | ||
Param1 uint16 `yaml:"param_1"` // usually contains 100 | ||
Param2 uint16 `yaml:"param_2"` // usually contains 0 | ||
Scale uint16 `yaml:"scale"` | ||
Frames []WldFragMeshAnimatedBone `yaml:"frames"` | ||
Size6 uint32 `yaml:"size_6"` | ||
} | ||
|
||
type WldFragMeshAnimatedBone struct { | ||
Position model.Vector3 `yaml:"position"` | ||
NameRef int32 | ||
Flags uint32 | ||
Param1 uint16 | ||
Param2 uint16 | ||
Scale uint16 | ||
Frames [][][3]int16 | ||
Size6 uint16 | ||
} | ||
|
||
func (e *WldFragDmTrackDef2) FragCode() int { | ||
return FragCodeDmTrackDef2 | ||
} | ||
|
||
func (e *WldFragDmTrackDef2) Write(w io.Writer, isNewWorld bool) error { | ||
enc := encdec.NewEncoder(w, binary.LittleEndian) | ||
enc.Int32(e.NameRef) | ||
enc.Uint32(e.Flags) | ||
if len(e.Frames) < 1 { | ||
return fmt.Errorf("no frames found") | ||
} | ||
enc.Uint16(uint16(len(e.Frames[0]))) | ||
enc.Uint16(uint16(len(e.Frames))) | ||
enc.Uint16(e.Param1) | ||
enc.Uint16(e.Param2) | ||
enc.Uint16(e.Scale) | ||
for _, frame := range e.Frames { | ||
for _, vert := range frame { | ||
enc.Int16(vert[0]) | ||
enc.Int16(vert[1]) | ||
enc.Int16(vert[2]) | ||
} | ||
} | ||
enc.Uint16(e.Size6) | ||
err := enc.Error() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (e *WldFragDmTrackDef2) Read(r io.ReadSeeker, isNewWorld bool) error { | ||
dec := encdec.NewDecoder(r, binary.LittleEndian) | ||
e.NameRef = dec.Int32() | ||
e.Flags = dec.Uint32() | ||
vertexCount := dec.Uint16() | ||
frameCount := dec.Uint16() | ||
e.Param1 = dec.Uint16() | ||
e.Param2 = dec.Uint16() | ||
e.Scale = dec.Uint16() | ||
e.Frames = make([][][3]int16, frameCount) | ||
for i := range e.Frames { | ||
e.Frames[i] = make([][3]int16, vertexCount) | ||
for j := range e.Frames[i] { | ||
e.Frames[i][j][0] = dec.Int16() | ||
e.Frames[i][j][1] = dec.Int16() | ||
e.Frames[i][j][2] = dec.Int16() | ||
} | ||
} | ||
e.Size6 = dec.Uint16() | ||
err := dec.Error() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.