-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic model parsing functionality
- Loading branch information
Showing
9 changed files
with
215 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace G2DataGUI.Common.Data.Models; | ||
|
||
public class Model | ||
{ | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using G2DataGUI.Common.Data.Common; | ||
|
||
namespace G2DataGUI.Common.Data.Models; | ||
|
||
public class Models : BaseContainer | ||
{ | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using G2DataGUI.IO.Streams; | ||
|
||
namespace G2DataGUI.Common.Data.Models; | ||
|
||
public class NJCM | ||
{ | ||
public uint ByteLength { get; private set; } | ||
public NJSBone BaseBone { get; private set; } = null; | ||
|
||
/// <summary> | ||
/// Represents the ASCII string "NJCM" | ||
/// </summary> | ||
public static byte[] Identifier => new byte[] { 0x4E, 0x4A, 0x43, 0x4D }; | ||
|
||
/// <summary> | ||
/// Offsets do not account for Identifier or ByteLength | ||
/// </summary> | ||
public static long DataOffset => 0x08; | ||
|
||
public static NJCM ReadNJCM(Stream reader, long instanceOffset) | ||
{ | ||
var identifier = reader.ReadRawByteArray((uint)Identifier.Length); | ||
if (!Identifier.SequenceEqual(identifier)) | ||
{ | ||
return null; | ||
} | ||
|
||
NJCM njcm = new() | ||
{ | ||
ByteLength = reader.ReadRawUInt(), | ||
BaseBone = NJSBone.ReadNJSObject(reader, instanceOffset + DataOffset), | ||
}; | ||
|
||
return njcm; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.IO; | ||
using G2DataGUI.Common.Data.Common; | ||
using G2DataGUI.IO.Streams; | ||
|
||
namespace G2DataGUI.Common.Data.Models; | ||
|
||
public class NJSBone | ||
{ | ||
public uint Flags { get; set; } | ||
public NJSMesh Model { 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 static NJSBone ReadNJSObject(Stream reader, long instanceOffset) | ||
{ | ||
NJSBone obj = new() | ||
{ | ||
Flags = reader.ReadRawUInt(), | ||
}; | ||
|
||
var modelOffset = reader.ReadRawUInt(); | ||
if (modelOffset > 0) | ||
{ | ||
long position = reader.Position; | ||
reader.Seek(instanceOffset + modelOffset, SeekOrigin.Begin); | ||
obj.Model = NJSMesh.ReadNJSModel(reader, instanceOffset); | ||
reader.Seek(position, SeekOrigin.Begin); | ||
} | ||
|
||
obj.Position = Vector3.ReadVector3(reader); | ||
obj.Angle = Vector3.ReadVector3(reader); | ||
obj.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); | ||
reader.Seek(position, SeekOrigin.Begin); | ||
} | ||
|
||
var siblingOffset = reader.ReadRawUInt(); | ||
if (siblingOffset > 0) | ||
{ | ||
long position = reader.Position; | ||
reader.Seek(instanceOffset + siblingOffset, SeekOrigin.Begin); | ||
obj.Sibling = ReadNJSObject(reader, instanceOffset); | ||
reader.Seek(position, SeekOrigin.Begin); | ||
} | ||
|
||
return obj; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.IO; | ||
using G2DataGUI.Common.Data.Common; | ||
using G2DataGUI.IO.Streams; | ||
|
||
namespace G2DataGUI.Common.Data.Models; | ||
|
||
public class NJSMesh | ||
{ | ||
public NJSVertexList VertexList { get; set; } = null; | ||
// indices | ||
public Vector3 Center { get; set; } | ||
public float Radius { get; set; } | ||
|
||
public static NJSMesh ReadNJSModel(Stream reader, long instanceOffset) | ||
{ | ||
NJSMesh model = new(); | ||
|
||
var vertexOffset = reader.ReadRawUInt(); | ||
if (vertexOffset > 0) | ||
{ | ||
var position = reader.Position; | ||
reader.Seek(instanceOffset + vertexOffset, SeekOrigin.Begin); | ||
model.VertexList = NJSVertexList.ReadNJSVertexList(reader); | ||
reader.Seek(position, SeekOrigin.Begin); | ||
} | ||
|
||
model.Center = Vector3.ReadVector3(reader); | ||
model.Radius = reader.ReadRawFloat(); | ||
|
||
return model; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using G2DataGUI.Common.Data.Common; | ||
using G2DataGUI.IO.Streams; | ||
|
||
namespace G2DataGUI.Common.Data.Models; | ||
|
||
public class NJSVertexList | ||
{ | ||
/// <summary> | ||
/// Always 0x2900? | ||
/// </summary> | ||
public short Format { get; set; } | ||
|
||
/// <summary> | ||
/// No idea | ||
/// </summary> | ||
public short Unknown1 { get; set; } | ||
|
||
/// <summary> | ||
/// Always 0x0000? | ||
/// </summary> | ||
public short Flags { get; set; } | ||
|
||
/// <summary> | ||
/// Number of Vertices | ||
/// </summary> | ||
public short Count { get; set; } | ||
|
||
/// <summary> | ||
/// Should end with a 0xFF000000? | ||
/// </summary> | ||
public List<Vector3> VertexList { get; set; } = new List<Vector3>(); | ||
|
||
public static NJSVertexList ReadNJSVertexList(Stream reader) | ||
{ | ||
NJSVertexList list = new() | ||
{ | ||
Format = reader.ReadRawShort(), | ||
Unknown1 = reader.ReadRawShort(), | ||
Flags = reader.ReadRawShort(), | ||
Count = reader.ReadRawShort(), | ||
}; | ||
|
||
for (int index = 0; index < list.Count; index++) | ||
{ | ||
list.VertexList.Add(Vector3.ReadVector3(reader)); | ||
} | ||
|
||
return list; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace G2DataGUI.Common.Data.Models; | ||
|
||
public class NJTL | ||
{ | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace G2DataGUI.Common.Data.Models; | ||
internal class NMDM | ||
{ | ||
} |