Skip to content

Commit 2498e6c

Browse files
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.
1 parent a5c3ea6 commit 2498e6c

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

SuperBMD/source/BMD/MAT3.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ public MAT3(EndianBinaryReader reader, int offset)
7272
int nextOffset = reader.PeekReadInt32();
7373
int sectionSize = 0;
7474

75-
if (nextOffset == 0)
75+
if (i == Mat3OffsetIndex.NBTScaleData)
76+
{
77+
78+
}
79+
80+
if (nextOffset == 0 && i != Mat3OffsetIndex.NBTScaleData)
7681
{
7782
long saveReaderPos = reader.BaseStream.Position;
7883

SuperBMD/source/Model.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public void ExportAssImp(string fileName, string modelType, ExportSettings setti
173173
}
174174

175175
AssimpContext cont = new AssimpContext();
176-
cont.ExportFile(outScene, fileName, "collada", PostProcessSteps.ValidateDataStructure);
176+
cont.ExportFile(outScene, fileName, "collada", PostProcessSteps.ValidateDataStructure | PostProcessSteps.JoinIdenticalVertices);
177177

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

201201
if (Joints.FlatSkeleton.Exists(x => x.Name == name))
202202
{
203-
string jointLine = line.Replace(">", $" sid=\"{ name }\" type=\"JOINT\">\n");
203+
string jointLine = line.Replace(">", $" sid=\"{ name }\" type=\"JOINT\">");
204204
test.WriteLine(jointLine);
205205
test.Flush();
206206
}
@@ -214,22 +214,27 @@ public void ExportAssImp(string fileName, string modelType, ExportSettings setti
214214
{
215215
foreach (Mesh mesh in outScene.Meshes)
216216
{
217-
test.WriteLine($"<node id=\"{ mesh.Name }\" name=\"{ mesh.Name }\" type=\"NODE\">");
218-
219-
test.WriteLine($"<instance_controller url=\"#{ mesh.Name }-skin\">");
220-
test.WriteLine("<skeleton>#skeleton_root</skeleton>");
221-
test.WriteLine("</instance_controller>");
222-
223-
test.WriteLine("</node>");
217+
test.WriteLine($" <node id=\"{ mesh.Name }\" name=\"{ mesh.Name }\" type=\"NODE\">");
218+
219+
test.WriteLine($" <instance_controller url=\"#{ mesh.Name }-skin\">");
220+
test.WriteLine(" <skeleton>#skeleton_root</skeleton>");
221+
test.WriteLine(" <bind_material>");
222+
test.WriteLine(" <technique_common>");
223+
test.WriteLine($" <instance_material symbol=\"theresonlyone\" target=\"#m{ mesh.MaterialIndex }mat\" />");
224+
test.WriteLine(" </technique_common>");
225+
test.WriteLine(" </bind_material>");
226+
test.WriteLine(" </instance_controller>");
227+
228+
test.WriteLine(" </node>");
224229
test.Flush();
225230
}
226231

227232
test.WriteLine(line);
228233
test.Flush();
229234
}
230-
else if (line.Contains("<matrix") && !line.Contains("//"))
235+
else if (line.Contains("<matrix"))
231236
{
232-
string matLine = line.Replace("<matrix>", "<matrix sid=\"matrix\">\n");
237+
string matLine = line.Replace("<matrix>", "<matrix sid=\"matrix\">");
233238
test.WriteLine(matLine);
234239
test.Flush();
235240
}
@@ -239,6 +244,12 @@ public void ExportAssImp(string fileName, string modelType, ExportSettings setti
239244
test.Flush();
240245
}
241246
}
247+
248+
test.Close();
249+
dae.Close();
250+
251+
File.Copy(fileName + ".dae", fileName, true);
252+
File.Delete(fileName + ".dae");
242253
}
243254

244255
private void AddControllerLibrary(Scene scene, StreamWriter writer)

0 commit comments

Comments
 (0)