Skip to content

Commit

Permalink
Skinned meshes that are exported to DAE replace the initial skinless …
Browse files Browse the repository at this point in the history
…mesh that is created by AssImp. Also corrected an error that resulted in skinned exported meshes having no materials, and an error in MAT3 loading that caused an incorrect value to be used for determining the number of NBTScale structs in the material data.
  • Loading branch information
Sage-of-Mirrors committed Jan 10, 2018
1 parent a5c3ea6 commit 2498e6c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
7 changes: 6 additions & 1 deletion SuperBMD/source/BMD/MAT3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ public MAT3(EndianBinaryReader reader, int offset)
int nextOffset = reader.PeekReadInt32();
int sectionSize = 0;

if (nextOffset == 0)
if (i == Mat3OffsetIndex.NBTScaleData)
{

}

if (nextOffset == 0 && i != Mat3OffsetIndex.NBTScaleData)
{
long saveReaderPos = reader.BaseStream.Position;

Expand Down
33 changes: 22 additions & 11 deletions SuperBMD/source/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void ExportAssImp(string fileName, string modelType, ExportSettings setti
}

AssimpContext cont = new AssimpContext();
cont.ExportFile(outScene, fileName, "collada", PostProcessSteps.ValidateDataStructure);
cont.ExportFile(outScene, fileName, "collada", PostProcessSteps.ValidateDataStructure | PostProcessSteps.JoinIdenticalVertices);

if (SkinningEnvelopes.Weights.Count == 0)
return; // There's no skinning information, so we can stop here
Expand All @@ -200,7 +200,7 @@ public void ExportAssImp(string fileName, string modelType, ExportSettings setti

if (Joints.FlatSkeleton.Exists(x => x.Name == name))
{
string jointLine = line.Replace(">", $" sid=\"{ name }\" type=\"JOINT\">\n");
string jointLine = line.Replace(">", $" sid=\"{ name }\" type=\"JOINT\">");
test.WriteLine(jointLine);
test.Flush();
}
Expand All @@ -214,22 +214,27 @@ public void ExportAssImp(string fileName, string modelType, ExportSettings setti
{
foreach (Mesh mesh in outScene.Meshes)
{
test.WriteLine($"<node id=\"{ mesh.Name }\" name=\"{ mesh.Name }\" type=\"NODE\">");

test.WriteLine($"<instance_controller url=\"#{ mesh.Name }-skin\">");
test.WriteLine("<skeleton>#skeleton_root</skeleton>");
test.WriteLine("</instance_controller>");

test.WriteLine("</node>");
test.WriteLine($" <node id=\"{ mesh.Name }\" name=\"{ mesh.Name }\" type=\"NODE\">");

test.WriteLine($" <instance_controller url=\"#{ mesh.Name }-skin\">");
test.WriteLine(" <skeleton>#skeleton_root</skeleton>");
test.WriteLine(" <bind_material>");
test.WriteLine(" <technique_common>");
test.WriteLine($" <instance_material symbol=\"theresonlyone\" target=\"#m{ mesh.MaterialIndex }mat\" />");
test.WriteLine(" </technique_common>");
test.WriteLine(" </bind_material>");
test.WriteLine(" </instance_controller>");

test.WriteLine(" </node>");
test.Flush();
}

test.WriteLine(line);
test.Flush();
}
else if (line.Contains("<matrix") && !line.Contains("//"))
else if (line.Contains("<matrix"))
{
string matLine = line.Replace("<matrix>", "<matrix sid=\"matrix\">\n");
string matLine = line.Replace("<matrix>", "<matrix sid=\"matrix\">");
test.WriteLine(matLine);
test.Flush();
}
Expand All @@ -239,6 +244,12 @@ public void ExportAssImp(string fileName, string modelType, ExportSettings setti
test.Flush();
}
}

test.Close();
dae.Close();

File.Copy(fileName + ".dae", fileName, true);
File.Delete(fileName + ".dae");
}

private void AddControllerLibrary(Scene scene, StreamWriter writer)
Expand Down

0 comments on commit 2498e6c

Please sign in to comment.