diff --git a/src/G2DataGUI.Common/Data/Common/Vector3.cs b/src/G2DataGUI.Common/Data/Common/Vector3.cs index da7b1f0..9aff692 100644 --- a/src/G2DataGUI.Common/Data/Common/Vector3.cs +++ b/src/G2DataGUI.Common/Data/Common/Vector3.cs @@ -9,6 +9,26 @@ public class Vector3 public float Y { get; set; } public float Z { get; set; } + public static Vector3 operator+(Vector3 left, Vector3 right) + { + return new Vector3 + { + X = left.X + right.X, + Y = left.Y + right.Y, + Z = left.Z + right.Z, + }; + } + + public static Vector3 operator-(Vector3 left, Vector3 right) + { + return new Vector3 + { + X = left.X - right.X, + Y = left.Y - right.Y, + Z = left.Z - right.Z, + }; + } + public static Vector3 ReadVector3(Stream reader) { Vector3 vector3 = new() diff --git a/src/G2DataGUI.Common/Data/Maps/Maps.cs b/src/G2DataGUI.Common/Data/Maps/Maps.cs index 6a6adb3..50b08ee 100644 --- a/src/G2DataGUI.Common/Data/Maps/Maps.cs +++ b/src/G2DataGUI.Common/Data/Maps/Maps.cs @@ -39,7 +39,7 @@ private void ReadMaps() CollectionRefreshed?.Invoke(this, EventArgs.Empty); using var modelFile = File.Open( - "F:\\programming\\languages\\c#\\programs\\G2DataGUI\\build\\Debug\\net7.0\\models\\2a00.chr_model_1.nj", + "F:\\projects\\G2DataGUI\\build\\Debug\\net7.0\\models\\2a00.chr_model_1.nj", FileMode.Open, FileAccess.Read); NJCM model = NJCM.ReadNJCM(modelFile, 0); diff --git a/src/G2DataGUI.Common/Data/Models/NJSBone.cs b/src/G2DataGUI.Common/Data/Models/NJSBone.cs index 86da9a6..245faba 100644 --- a/src/G2DataGUI.Common/Data/Models/NJSBone.cs +++ b/src/G2DataGUI.Common/Data/Models/NJSBone.cs @@ -11,18 +11,21 @@ namespace G2DataGUI.Common.Data.Models; public class NJSBone { public uint Flags { get; set; } - public NJSMesh Model { get; set; } = null; + public NJSBone Parent { get; set; } + public NJSMesh Mesh { get; set; } = null; public Vector3 Position { get; set; } public Vector3 Angle { get; set; } public Vector3 Scale { get; set; } public NJSBone Child { get; set; } = null; public NJSBone Sibling { get; set; } = null; + public Vector3 AbsolutePosition => Parent is not null ? Position + Parent.AbsolutePosition : Position; - public static NJSBone ReadNJSObject(Stream reader, long instanceOffset) + public static NJSBone ReadNJSObject(Stream reader, long instanceOffset, NJSBone parent = null) { - NJSBone obj = new() + NJSBone bone = new() { Flags = reader.ReadRawUInt(), + Parent = parent, }; var modelOffset = reader.ReadRawUInt(); @@ -30,20 +33,20 @@ public static NJSBone ReadNJSObject(Stream reader, long instanceOffset) { long position = reader.Position; reader.Seek(instanceOffset + modelOffset, SeekOrigin.Begin); - obj.Model = NJSMesh.ReadNJSModel(reader, instanceOffset); + bone.Mesh = NJSMesh.ReadNJSModel(reader, instanceOffset, bone); reader.Seek(position, SeekOrigin.Begin); } - obj.Position = Vector3.ReadVector3(reader); - obj.Angle = Vector3.ReadVector3(reader); - obj.Scale = Vector3.ReadVector3(reader); + bone.Position = Vector3.ReadVector3(reader); + bone.Angle = Vector3.ReadVector3(reader); + bone.Scale = Vector3.ReadVector3(reader); var childOffset = reader.ReadRawUInt(); if (childOffset > 0) { long position = reader.Position; reader.Seek(instanceOffset + childOffset, SeekOrigin.Begin); - obj.Child = ReadNJSObject(reader, instanceOffset); + bone.Child = ReadNJSObject(reader, instanceOffset, bone); reader.Seek(position, SeekOrigin.Begin); } @@ -52,10 +55,10 @@ public static NJSBone ReadNJSObject(Stream reader, long instanceOffset) { long position = reader.Position; reader.Seek(instanceOffset + siblingOffset, SeekOrigin.Begin); - obj.Sibling = ReadNJSObject(reader, instanceOffset); + bone.Sibling = ReadNJSObject(reader, instanceOffset, bone); reader.Seek(position, SeekOrigin.Begin); } - return obj; + return bone; } } diff --git a/src/G2DataGUI.Common/Data/Models/NJSMesh.cs b/src/G2DataGUI.Common/Data/Models/NJSMesh.cs index a504d85..715e8b7 100644 --- a/src/G2DataGUI.Common/Data/Models/NJSMesh.cs +++ b/src/G2DataGUI.Common/Data/Models/NJSMesh.cs @@ -10,17 +10,21 @@ public class NJSMesh // indices public Vector3 Center { get; set; } public float Radius { get; set; } + public NJSBone ParentBone { get; set; } - public static NJSMesh ReadNJSModel(Stream reader, long instanceOffset) + public static NJSMesh ReadNJSModel(Stream reader, long instanceOffset, NJSBone parentBone) { - NJSMesh model = new(); + NJSMesh model = new() + { + ParentBone = parentBone, + }; var vertexOffset = reader.ReadRawUInt(); if (vertexOffset > 0) { var position = reader.Position; reader.Seek(instanceOffset + vertexOffset, SeekOrigin.Begin); - model.VertexList = NJSVertexList.ReadNJSVertexList(reader); + model.VertexList = NJSVertexList.ReadNJSVertexList(reader, parentBone); reader.Seek(position, SeekOrigin.Begin); } diff --git a/src/G2DataGUI.Common/Data/Models/NJSVertex.cs b/src/G2DataGUI.Common/Data/Models/NJSVertex.cs new file mode 100644 index 0000000..4749a03 --- /dev/null +++ b/src/G2DataGUI.Common/Data/Models/NJSVertex.cs @@ -0,0 +1,9 @@ +using G2DataGUI.Common.Data.Common; + +namespace G2DataGUI.Common.Data.Models; +public class NJSVertex +{ + public Vector3 Position { get; set; } + public Vector3 AbsolutePosition => Position + ParentBone.AbsolutePosition; + public NJSBone ParentBone { get; set; } +} diff --git a/src/G2DataGUI.Common/Data/Models/NJSVertexList.cs b/src/G2DataGUI.Common/Data/Models/NJSVertexList.cs index b573772..a306be8 100644 --- a/src/G2DataGUI.Common/Data/Models/NJSVertexList.cs +++ b/src/G2DataGUI.Common/Data/Models/NJSVertexList.cs @@ -30,9 +30,9 @@ public class NJSVertexList /// /// Should end with a 0xFF000000? /// - public List VertexList { get; set; } = new List(); + public List VertexList { get; set; } = new List(); - public static NJSVertexList ReadNJSVertexList(Stream reader) + public static NJSVertexList ReadNJSVertexList(Stream reader, NJSBone parentBone) { NJSVertexList list = new() { @@ -44,7 +44,10 @@ public static NJSVertexList ReadNJSVertexList(Stream reader) for (int index = 0; index < list.Count; index++) { - list.VertexList.Add(Vector3.ReadVector3(reader)); + list.VertexList.Add(new NJSVertex{ + Position = Vector3.ReadVector3(reader), + ParentBone = parentBone, + }); } return list;