/// <summary> /// Reads Gfx Vertices /// </summary> public static Vertex[] ReadGfxVertices(ProcessReader reader, long address, int count) { // Preallocate vertex array Vertex[] vertices = new Vertex[count]; // Read buffer var byteBuffer = reader.ReadBytes(address, count * 44); // Loop number of vertices we have for (int i = 0; i < count; i++) { // Read Struct var gfxVertex = ByteUtil.BytesToStruct <GfxVertex>(byteBuffer, i * 44); // Create new SEModel Vertex vertices[i] = new Vertex() { // Set offset Position = new Vector3( gfxVertex.X * 2.54, gfxVertex.Y * 2.54, gfxVertex.Z * 2.54), // Decode and set normal (from DTZxPorter - Wraith, same as XModels) Normal = VertexNormalUnpacking.MethodA(gfxVertex.Normal), // Set UV UV = new Vector2(gfxVertex.U, 1 - gfxVertex.V) }; } // Done return(vertices); }
/// <summary> /// Reads Gfx Vertices /// </summary> public static Vertex[] ReadGfxVertices(ProcessReader reader, long positionsAddress, long uvsAddress, long normalsAddress, int count) { // Preallocate vertex array Vertex[] vertices = new Vertex[count]; // Read buffer var positionsBuffer = reader.ReadBytes(positionsAddress, count * 12); var uvsBuffer = reader.ReadBytes(uvsAddress, count * 8); var normalsBuffer = reader.ReadBytes(normalsAddress, count * 4); // Loop number of vertices we have for (int i = 0; i < count; i++) { // Read Struct var gfxVertexPosition = ByteUtil.BytesToStruct <GfxVertexPosition>(positionsBuffer, i * 12); var gfxVertexUV = ByteUtil.BytesToStruct <GfxVertexUV>(uvsBuffer, i * 8); var gfxVertexNormal = ByteUtil.BytesToStruct <PackedUnitVector>(normalsBuffer, i * 4); // Create new SEModel Vertex vertices[i] = new Vertex() { // Set offset Position = new Vector3( gfxVertexPosition.X * 2.54, gfxVertexPosition.Y * 2.54, gfxVertexPosition.Z * 2.54), // Decode and set normal (from DTZxPorter - Wraith, same as XModels) Normal = VertexNormalUnpacking.MethodB(gfxVertexNormal), // Set UV UV = new Vector2(gfxVertexUV.U, 1 - gfxVertexUV.V) }; } // Done return(vertices); }
/// <summary> /// Unpacks a vertex /// </summary> /// <param name="packedVertex">Vertex to unpack</param> /// <returns></returns> public static Vertex UnpackVertex(GfxVertex packedVertex) { return(new Vertex() { // Set offset Position = new Vector3( packedVertex.X * 2.54, packedVertex.Y * 2.54, packedVertex.Z * 2.54), // Decode and set normal (from DTZxPorter - Wraith, same as XModels) Normal = VertexNormalUnpacking.MethodC(packedVertex.Normal), // Set UV UV = new Vector2(HalfFloats.ToFloat(packedVertex.U), 1 - HalfFloats.ToFloat(packedVertex.V)) }); }