Skip to content

Commit

Permalink
Model Exporter speed enhanced (now it's faster)
Browse files Browse the repository at this point in the history
  • Loading branch information
BuilderDemo7 committed Dec 11, 2023
1 parent c8e42fb commit 5af08a0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
39 changes: 23 additions & 16 deletions WADExplorer/Extras/DDIDFF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,24 +511,30 @@ public static TriangleIndex GetWhatTriangleUsesVertex(int vert, List<TriangleInd
public string AsOBJ(string mtlFileName=null)
{
string obj = "# Automatically generated by WADExplorer\n";
string vertices = "";
string vcolors = "";
string texcoords = "";
string faces = "";
//string vertices = "";
StringWriter vertTW = new StringWriter();
StringWriter vcolorsTW = new StringWriter();
//string vcolors = "";
StringWriter texcoordsTW = new StringWriter();
//string texcoords = "";
StringWriter facesTW = new StringWriter();
//string faces = "";
if (mtlFileName!=null)
obj += $"mtllib {mtlFileName}\n";

vertices += $"\n# Vertices ({Vertices.Count})\n";
vertTW.Write($"\n# Vertices ({Vertices.Count})\n");
foreach(Vertex vert in Vertices)
{
vertices += $"v {vert.Position.X:F8} {vert.Position.Y:F8} {vert.Position.Z:F8}\n".Replace(",",".");
string v = vert.Position.Format("v {0:F8} {1:F8} {2:F8}\n").Replace(",", ".");
/*vertices +=*/ // too slow!
vertTW.Write(v.ToLower().Contains("nan") ? "v 0.0 0.0 0.0\n" : v);
}
vcolors += $"\n# Vertex Colors ({VerticesColors.Count})\n# *May not be imported but informed in the file\n";
vcolorsTW.Write( $"\n# Vertex Colors ({VerticesColors.Count})\n# *May not be imported but informed in the file\n" );
foreach (VertexColor vcol in VerticesColors)
{
vcolors += $"vc {vcol.R} {vcol.G} {vcol.B} {vcol.A}\n";
vcolorsTW.Write( $"vc {vcol.R} {vcol.G} {vcol.B} {vcol.A}\n" );
}
texcoords += $"\n# Texture Coordinates ({TextureCoordinates.Count})\n";
texcoordsTW.Write($"\n# Texture Coordinates ({TextureCoordinates.Count})\n");
int texcoordandvertid = 0;
int tex_matId = -1;
foreach (TexCoords texcoord in TextureCoordinates)
Expand Down Expand Up @@ -558,11 +564,12 @@ public string AsOBJ(string mtlFileName=null)
y = 1 - y;
}

texcoords += $"vt {x:F8} {y:F8}\n".Replace(",", ".");
string vt = $"vt {x:F8} {y:F8}\n".Replace(",", ".");
texcoordsTW.Write( vt.ToLower().Contains("nan") ? "vt 0.0 0.0\n" : vt );
texcoordandvertid++;
}
faces += $"\n# There is {Materials.Data.MaterialsCount} materials from the source DDI RenderWare DFF stream";
faces += $"\n# Triangle indices ({TriangleIndices.Count})\n";
facesTW.Write( $"\n# There is {Materials.Data.MaterialsCount} materials from the source DDI RenderWare DFF stream" );
facesTW.Write( $"\n# Triangle indices ({TriangleIndices.Count})\n" );
#region Old_Code
/*
int matId = -1;
Expand All @@ -580,7 +587,7 @@ public string AsOBJ(string mtlFileName=null)
{
for (int matId = 0; matId < Materials.Materials.Count; matId++)
{
faces += $"usemtl Mat_{matId}\n";
facesTW.Write($"usemtl Mat_{matId}\n");

foreach (TriangleIndex tidx in TriangleIndices)
{
Expand All @@ -595,7 +602,7 @@ public string AsOBJ(string mtlFileName=null)
int vert1 = triangle.Vert1 + 1;
int vert2 = triangle.Vert2 + 1;
int vert3 = triangle.Vert3 + 1;
faces += $"f {vert1}/{vert1} {vert2}/{vert2} {vert3}/{vert3}\n";
facesTW.Write($"f {vert1}/{vert1} {vert2}/{vert2} {vert3}/{vert3}\n");
}
}
}
Expand All @@ -607,11 +614,11 @@ public string AsOBJ(string mtlFileName=null)
int vert1 = tidx.Vert1 + 1;
int vert2 = tidx.Vert2 + 1;
int vert3 = tidx.Vert3 + 1;
faces += $"f {vert1}/{vert1} {vert2}/{vert2} {vert3}/{vert3}\n";
facesTW.Write($"f {vert1}/{vert1} {vert2}/{vert2} {vert3}/{vert3}\n");
}
}

return obj+vertices+ vcolors + texcoords+faces;
return obj + vertTW.ToString() + vcolorsTW.ToString() + texcoordsTW.ToString() + facesTW.ToString();
}

public string AsOBJMTL()
Expand Down
10 changes: 10 additions & 0 deletions WADExplorer/Extras/DFFCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public Vector3(Stream stream)
Load(stream);
}

public string Format(string format)
{
return String.Format(format,_x,_y,_z);
}

public byte[] GetBytes()
{
byte[] bytes = new byte[12];
Expand Down Expand Up @@ -126,6 +131,11 @@ public Vector2(Stream stream)
Load(stream);
}

public string Format(string format)
{
return String.Format(format, _x, _y);
}

public byte[] GetBytes()
{
byte[] bytes = new byte[8];
Expand Down
4 changes: 2 additions & 2 deletions WADExplorer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// É possível especificar todos os valores ou usar como padrão os Números de Build e da Revisão
// utilizando o "*" como mostrado abaixo:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.3")]
[assembly: AssemblyFileVersion("1.0.3")]
[assembly: AssemblyVersion("1.0.3.5")]
[assembly: AssemblyFileVersion("1.0.3.5")]
4 changes: 2 additions & 2 deletions WADExplorer/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ private void convertdffToobjToolStripMenuItem_Click(object sender, EventArgs e)

f.Close();
fmtl.Close();
MessageBox.Show("Successfully exported as WaveFront OBJ!");
MessageBox.Show("Successfully exported as WaveFront OBJ!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
Expand Down Expand Up @@ -1046,7 +1046,7 @@ private void converobjTodffToolStripMenuItem_Click(object sender, EventArgs e)
FileStream f = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.Write);
f.Write(buffer, 0, buffer.Length);
f.Close();
MessageBox.Show("Successfully exported as DDI RenderWare Dive File Format!");
MessageBox.Show("Successfully exported as DDI RenderWare Dive File Format!","Success",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
Expand Down

0 comments on commit 5af08a0

Please sign in to comment.