From 2498e6c31310ded91dea13b2e5dbf152c2ada888 Mon Sep 17 00:00:00 2001 From: Sage_of_Mirrors Date: Wed, 10 Jan 2018 17:40:19 -0600 Subject: [PATCH] Skinned meshes that are exported to DAE replace the initial skinless 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. --- SuperBMD/source/BMD/MAT3.cs | 7 ++++++- SuperBMD/source/Model.cs | 33 ++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/SuperBMD/source/BMD/MAT3.cs b/SuperBMD/source/BMD/MAT3.cs index c5b58db..f84095a 100644 --- a/SuperBMD/source/BMD/MAT3.cs +++ b/SuperBMD/source/BMD/MAT3.cs @@ -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; diff --git a/SuperBMD/source/Model.cs b/SuperBMD/source/Model.cs index a1b0d64..e5ba270 100644 --- a/SuperBMD/source/Model.cs +++ b/SuperBMD/source/Model.cs @@ -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 @@ -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(); } @@ -214,22 +214,27 @@ public void ExportAssImp(string fileName, string modelType, ExportSettings setti { foreach (Mesh mesh in outScene.Meshes) { - test.WriteLine($""); - - test.WriteLine($""); - test.WriteLine("#skeleton_root"); - test.WriteLine(""); - - test.WriteLine(""); + test.WriteLine($" "); + + test.WriteLine($" "); + test.WriteLine(" #skeleton_root"); + test.WriteLine(" "); + test.WriteLine(" "); + test.WriteLine($" "); + test.WriteLine(" "); + test.WriteLine(" "); + test.WriteLine(" "); + + test.WriteLine(" "); test.Flush(); } test.WriteLine(line); test.Flush(); } - else if (line.Contains("", "\n"); + string matLine = line.Replace("", ""); test.WriteLine(matLine); test.Flush(); } @@ -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)