Skip to content
Permalink
Browse files

Added M2 collision model exporting

  • Loading branch information...
dkrutsko committed May 23, 2017
1 parent 0c8b234 commit 8dc08b4968a3bece724455e6b81d9b358cd2721e
Showing with 63 additions and 17 deletions.
  1. +28 −0 OBJExporterUI/Exporters/OBJ/M2Exporter.cs
  2. +20 −8 WoWFormatLib/FileReaders/M2Reader.cs
  3. +15 −9 WoWFormatLib/Structs/M2.Struct.cs
@@ -202,6 +202,34 @@ public static void exportM2(string file, BackgroundWorker exportworker = null, s
}
}

objsw.Close();

exportworker.ReportProgress(90, "Exporting collision..");

if(destinationOverride == null)
{
objsw = new StreamWriter(Path.Combine(outdir, file.Replace(".m2", ".phys.obj")));
}
else {
objsw = new StreamWriter(Path.Combine(outdir, destinationOverride, Path.GetFileName(file.ToLower()).Replace(".m2", ".phys.obj")));
}

objsw.WriteLine("# Written by Marlamin's WoW OBJExporter. Original file: " + file);

for (int i = 0; i < reader.model.boundingvertices.Count(); i++)
{
objsw.WriteLine("v " +
reader.model.boundingvertices[i].vertex.X + " " +
reader.model.boundingvertices[i].vertex.Z + " " +
-reader.model.boundingvertices[i].vertex.Y);
}

for (int i = 0; i < reader.model.boundingtriangles.Count(); i++)
{
var t = reader.model.boundingtriangles[i];
objsw.WriteLine("f " + (t.index_0 + 1) + " " + (t.index_1 + 1) + " " + (t.index_2 + 1));
}

objsw.Close();
// https://en.wikipedia.org/wiki/Wavefront_.obj_file#Basic_materials
// http://wiki.unity3d.com/index.php?title=ExportOBJ
@@ -1,15 +1,15 @@
/*
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
*/
@@ -209,6 +209,7 @@ public void ParseYeOldeM2Struct(Stream m2stream)
model.translookup = readTransLookup(nTransLookup, ofsTranslookup, bin);
model.uvanimlookup = readUVAnimLookup(nUVAnimLookup, ofsUVAnimLookup, bin);
model.boundingtriangles = readBoundingTriangles(nBoundingTriangles, ofsBoundingTriangles, bin);
model.boundingvertices = readBoundingVertices(nBoundingVertices, ofsBoundingVertices, bin);
model.boundingnormals = readBoundingNormals(nBoundingNormals, ofsBoundingNormals, bin);
model.attachments = readAttachments(nAttachments, ofsAttachments, bin);
model.attachlookup = readAttachLookup(nAttachLookup, ofsAttachLookup, bin);
@@ -312,6 +313,17 @@ private BoundingNormal[] readBoundingNormals(uint nBoundingNormals, uint ofsBoun
return boundingNormals;
}

private BoundingVertex[] readBoundingVertices(uint nBoundingVertices, uint ofsBoundingVertices, BinaryReader bin)
{
bin.BaseStream.Position = ofsBoundingVertices;
var boundingVertices = new BoundingVertex[nBoundingVertices];
for (int i = 0; i < nBoundingVertices; i++)
{
boundingVertices[i] = bin.Read<BoundingVertex>();
}
return boundingVertices;
}

private BoundingTriangle[] readBoundingTriangles(uint nBoundingTriangles, uint ofsBoundingTriangles, BinaryReader bin)
{
bin.BaseStream.Position = ofsBoundingTriangles;
@@ -1,15 +1,15 @@
/*
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
*/
@@ -58,6 +58,7 @@ public struct M2Model
public Vector3[] boundingbox;
public float boundingradius;
public BoundingTriangle[] boundingtriangles;
public BoundingVertex[] boundingvertices;
public BoundingNormal[] boundingnormals;
public Attachment[] attachments;
public AttachLookup[] attachlookup;
@@ -99,7 +100,7 @@ public struct AFID
{
public short animID;
public short subAnimID;
public uint fileDataID;
public uint fileDataID;
}

public struct Animation
@@ -194,6 +195,11 @@ public struct BoundingNormal
public Vector3 normal;
}

public struct BoundingVertex
{
public Vector3 vertex;
}

public struct BoundingTriangle
{
public ushort index_0;

0 comments on commit 8dc08b4

Please sign in to comment.
You can’t perform that action at this time.