BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | List of all members
BrawlLib.Modeling.Collada.Collada Class Reference
Inheritance diagram for BrawlLib.Modeling.Collada.Collada:

Classes

class  ImportOptions
 

Public Types

enum  ImportType
 

Public Member Functions

 Collada ()
 
 Collada (Form owner, string title)
 
void Say (string text)
 
IModel ShowDialog (string filePath, ImportType type)
 
IModel ImportModel (string filePath, ImportType type)
 

Static Public Member Functions

static void Serialize (MDL0Node model, string outFile)
 
static void Serialize (CHR0Node[] animations, float fps, bool bake, string outFile)
 

Public Attributes

string _filePath
 

Static Public Attributes

static string Error
 
static IModel CurrentModel
 
static ImportType ModelType
 
static Matrix TransformMatrix = Matrix.Identity
 
static ImportOptions _importOptions = new ImportOptions()
 

Protected Member Functions

override void OnShown (EventArgs e)
 

Member Enumeration Documentation

◆ ImportType

25 {
26 MDL0 //Wii SDK
27 //BMD, //GameCube SDK
28 //LM, //Luigi's Mansion
29 //FMDL, //Wii U SDK
30 //NP3D, //Namco (Smash 4)
31 }

Constructor & Destructor Documentation

◆ Collada() [1/2]

BrawlLib.Modeling.Collada.Collada.Collada ( )
inline
10 {
11 InitializeComponent();
12 }

◆ Collada() [2/2]

BrawlLib.Modeling.Collada.Collada.Collada ( Form  owner,
string  title 
)
inline
15 : this()
16 {
17 Owner = owner;
18 Text = title;
19 }

Member Function Documentation

◆ ImportModel()

IModel BrawlLib.Modeling.Collada.Collada.ImportModel ( string  filePath,
ImportType  type 
)
inline
34 {
35 IModel model = null;
36 ModelType = type;
37
38 BoneType = ModelType == ImportType.MDL0 ? typeof(MDL0BoneNode) : null;
39
40 //TransformMatrix = Matrix.TransformMatrix(_importOptions._modifyScale, _importOptions._modifyRotation, new Vector3());
41
42 switch (type)
43 {
44 case ImportType.MDL0:
45 MDL0Node m = new MDL0Node
46 {
47 _name = Path.GetFileNameWithoutExtension(filePath),
48 _version = _importOptions._modelVersion.Clamp(8, 11)
49 };
51 {
52 m._originalPath = filePath;
53 }
54
55 m.BeginImport();
56 model = m;
57 break;
58 }
59
60 CurrentModel = model;
61
62 Error = "There was a problem reading the model.";
63 using (DecoderShell shell = DecoderShell.Import(filePath))
64 {
65 try
66 {
67 Error = "There was a problem reading texture entries.";
68
69 //Extract images, removing duplicates
70 foreach (ImageEntry img in shell._images)
71 {
72 string name = !string.IsNullOrEmpty(img._path?.Trim())
73 ? Path.GetFileNameWithoutExtension(img._path.Trim())
74 : img._name ?? img._id;
75
76 switch (type)
77 {
78 case ImportType.MDL0:
79 img._node = ((MDL0Node) model).FindOrCreateTexture(name);
80 break;
81 }
82 }
83
84 Error = "There was a problem creating a default shader.";
85
86 //Create a shader
87 ResourceNode shader = null;
88 switch (type)
89 {
90 case ImportType.MDL0:
91 MDL0Node m = (MDL0Node) model;
92 MDL0ShaderNode shadNode = new MDL0ShaderNode
93 {
94 Ref0 = 0,
95 Ref1 = -1,
96 Ref2 = -1,
97 Ref3 = -1,
98 Ref4 = -1,
99 Ref5 = -1,
100 Ref6 = -1,
101 Ref7 = -1
102 };
103
104 shadNode._parent = m._shadGroup;
105 m._shadList.Add(shadNode);
106
107 switch (_importOptions._mdlType)
108 {
109 case ImportOptions.MDLType.Character:
110 for (int i = 0; i < 3; i++)
111 {
112 switch (i)
113 {
114 case 0:
115 shadNode.AddChild(new MDL0TEVStageNode(0x28F8AF, 0x08F2F0, 0,
116 TevKColorSel.ConstantColor0_RGB, TevKAlphaSel.ConstantColor0_Alpha,
117 TexMapID.TexMap0, TexCoordID.TexCoord0, ColorSelChan.LightChannel0,
118 true));
119 break;
120 case 1:
121 shadNode.AddChild(new MDL0TEVStageNode(0x08FEB0, 0x081FF0, 0,
122 TevKColorSel.ConstantColor1_RGB, TevKAlphaSel.ConstantColor0_Alpha,
123 TexMapID.TexMap7, TexCoordID.TexCoord7, ColorSelChan.LightChannel0,
124 false));
125 break;
126 case 2:
127 shadNode.AddChild(new MDL0TEVStageNode(0x0806EF, 0x081FF0, 0,
128 TevKColorSel.ConstantColor0_RGB, TevKAlphaSel.ConstantColor0_Alpha,
129 TexMapID.TexMap7, TexCoordID.TexCoord7, ColorSelChan.Zero, false));
130 break;
131 }
132 }
133
134 break;
135 case ImportOptions.MDLType.Stage:
136 shadNode.AddChild(new MDL0TEVStageNode(0x28F8AF, 0x08F2F0, 0,
137 TevKColorSel.ConstantColor0_RGB, TevKAlphaSel.ConstantColor0_Alpha,
138 TexMapID.TexMap0, TexCoordID.TexCoord0, ColorSelChan.LightChannel0, true));
139 break;
140 }
141
142 shader = shadNode;
143
144 break;
145 }
146
147 Error = "There was a problem extracting materials.";
148
149 //Extract materials
150 foreach (MaterialEntry mat in shell._materials)
151 {
152 List<int> uwrap = new List<int>();
153 List<int> vwrap = new List<int>();
154 List<int> minfilter = new List<int>();
155 List<int> magfilter = new List<int>();
156 List<ImageEntry> imgEntries = new List<ImageEntry>();
157
158 //Find effect
159 if (mat._effect != null)
160 {
161 foreach (EffectEntry eff in shell._effects)
162 {
163 if (eff._id == mat._effect) //Attach textures and effects to material
164 {
165 if (eff._shader != null)
166 {
167 foreach (LightEffectEntry l in eff._shader._effects)
168 {
169 if (l._type == LightEffectType.diffuse && l._texture != null)
170 {
171 string path = l._texture;
172 foreach (EffectNewParam p in eff._newParams)
173 {
174 if (p._sid == l._texture)
175 {
176 path = p._sampler2D._url?.Trim();
177 if (!string.IsNullOrEmpty(p._sampler2D._source))
178 {
179 foreach (EffectNewParam p2 in eff._newParams)
180 {
181 if (p2._sid == p._sampler2D._source && p2._path != null)
182 {
183 path = p2._path;
184 }
185 }
186 }
187
188 switch (p._sampler2D._wrapS)
189 {
190 case "CLAMP":
191 uwrap.Add(0);
192 break;
193 case "WRAP":
194 uwrap.Add(1);
195 break;
196 case "MIRROR":
197 uwrap.Add(2);
198 break;
199 default:
200 uwrap.Add((int) _importOptions
201 .TextureWrap); // Default to user-defined
202 break;
203 }
204
205 switch (p._sampler2D._wrapT)
206 {
207 case "CLAMP":
208 vwrap.Add(0);
209 break;
210 case "WRAP":
211 vwrap.Add(1);
212 break;
213 case "MIRROR":
214 vwrap.Add(2);
215 break;
216 default:
217 vwrap.Add((int) _importOptions
218 .TextureWrap); // Default to user-defined
219 break;
220 }
221
222 switch (p._sampler2D._minFilter)
223 {
224 case "NEAREST":
225 minfilter.Add(0);
226 break;
227 case "LINEAR":
228 minfilter.Add(1);
229 break;
230 case "NEAREST_MIPMAP_NEAREST":
231 minfilter.Add(2);
232 break;
233 case "LINEAR_MIPMAP_NEAREST":
234 minfilter.Add(3);
235 break;
236 case "NEAREST_MIPMAP_LINEAR":
237 minfilter.Add(4);
238 break;
239 case "LINEAR_MIPMAP_LINEAR":
240 minfilter.Add(5);
241 break;
242 default:
243 minfilter.Add((int) _importOptions
244 .MinFilter); // Default to user-defined
245 break;
246 }
247
248 switch (p._sampler2D._magFilter)
249 {
250 case "NEAREST":
251 magfilter.Add(0);
252 break;
253 case "LINEAR":
254 magfilter.Add(1);
255 break;
256 case "NEAREST_MIPMAP_NEAREST":
257 magfilter.Add(0);
258 //magfilter.Add(2); // Unused. Use Nearest instead.
259 break;
260 case "LINEAR_MIPMAP_NEAREST":
261 magfilter.Add(1);
262 //magfilter.Add(3); // Unused. Use Linear instead.
263 break;
264 case "NEAREST_MIPMAP_LINEAR":
265 magfilter.Add(0);
266 //magfilter.Add(4); // Unused. Use Nearest instead.
267 break;
268 case "LINEAR_MIPMAP_LINEAR":
269 magfilter.Add(1);
270 //magfilter.Add(5); // Unused. Use Linear instead.
271 break;
272 default:
273 magfilter.Add((int) _importOptions
274 .MagFilter); // Default to user-defined
275 break;
276 }
277 }
278 }
279
280 foreach (ImageEntry img in shell._images)
281 {
282 if (img._id == path)
283 {
284 imgEntries.Add(img);
285 break;
286 }
287 }
288 }
289 }
290 }
291 }
292 }
293 }
294
295 switch (type)
296 {
297 case ImportType.MDL0:
298 MDL0MaterialNode matNode = new MDL0MaterialNode();
299
300 MDL0Node m = (MDL0Node) model;
301 matNode._parent = m._matGroup;
302 m._matList.Add(matNode);
303
304 matNode._name = mat._name ?? mat._id;
305 matNode.ShaderNode = shader as MDL0ShaderNode;
306
307 mat._node = matNode;
308 matNode._cull = _importOptions._culling;
309
310 int i = 0;
311 foreach (ImageEntry img in imgEntries)
312 {
314 (mr._texture = img._node as MDL0TextureNode)._references.Add(mr);
315 mr._name = mr._texture.Name;
316 matNode._children.Add(mr);
317 mr._parent = matNode;
318 mr._minFltr = minfilter.Count > i ? minfilter[i] : (int) _importOptions.MinFilter;
319 mr._magFltr = magfilter.Count > i ? magfilter[i] : (int) _importOptions.MagFilter;
320 mr._uWrap = uwrap.Count > i ? uwrap[i] : (int) _importOptions.TextureWrap;
321 mr._vWrap = vwrap.Count > i ? vwrap[i] : (int) _importOptions.TextureWrap;
322 i++;
323 }
324
325 break;
326 }
327 }
328
329 Say("Extracting scenes...");
330
331 List<ObjectInfo> _objects = new List<ObjectInfo>();
332 ResourceNode boneGroup = null;
333 switch (type)
334 {
335 case ImportType.MDL0:
336 boneGroup = ((MDL0Node) model)._boneGroup;
337 break;
338 }
339
340 //Extract bones and objects and create bone tree
341 foreach (SceneEntry scene in shell._scenes)
342 {
343 foreach (NodeEntry node in scene._nodes)
344 {
345 EnumNode(node, boneGroup, scene, model, shell, _objects, TransformMatrix, Matrix.Identity);
346 }
347 }
348
349 //Add root bone if there are no bones
350 if (boneGroup.Children.Count == 0)
351 {
352 switch (type)
353 {
354 case ImportType.MDL0:
355 MDL0BoneNode bone = new MDL0BoneNode
356 {
357 Scale = new Vector3(1)
358 };
359 bone.RecalcBindState(false, false);
360 bone._name = "TopN";
361 TempRootBone = bone;
362 break;
363 }
364 }
365
366 //Create objects
367 foreach (ObjectInfo obj in _objects)
368 {
369 NodeEntry node = obj._node;
370 string w = obj._weighted ? "" : "un";
371 string w2 = obj._weighted ? "\nOne or more vertices may not be weighted correctly." : "";
372 string n = node._name ?? node._id;
373
374 Error = $"There was a problem decoding {w}weighted primitives for the object {n}.{w2}";
375
376 Say($"Decoding {w}weighted primitives for {n}...");
377
378 obj.Initialize(model, shell);
379 }
380
381 //Finish
382 switch (type)
383 {
384 case ImportType.MDL0:
385 MDL0Node mdl0 = (MDL0Node) model;
386 if (TempRootBone != null)
387 {
388 mdl0._boneGroup._children.Add(TempRootBone);
389 TempRootBone._parent = mdl0._boneGroup;
390 }
391
392 FinishMDL0(mdl0);
393 break;
394 }
395 }
396#if !DEBUG
397 catch (Exception x)
398 {
399 MessageBox.Show("Cannot continue importing this model.\n" + Error + "\n\nException:\n" +
400 x);
401 model = null;
402 Close();
403 }
404#endif
405 finally
406 {
407 //Clean up the mess we've made
408 GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
409 }
410 }
411
412 CurrentModel = null;
413 Error = null;
414
415 // Blender Bone Fix
417 {
418 MDL0Node m = (MDL0Node) model;
419 MDL0BoneNode oldTop = m.FindBoneByIndex(0);
420 if (oldTop.HasChildren)
421 {
422 MDL0BoneNode actualTop = (MDL0BoneNode) oldTop.Children[0];
423 // Try to ensure top bone is a mistake bone
424 if (oldTop.Children.Count == 1 && (!oldTop.Name.Equals("TopN") || actualTop.Name.Equals("TopN")))
425 {
426 // Remove the actual top bone
427 m.FindChildrenByName("Bones")[0].AddChild(actualTop);
428 m.FindChildrenByName("Bones")[0].RemoveChild(m.FindChildrenByName("Bones")[0].Children[0]);
430 // Remove reference to the current top bone, as well as any end bones
431 foreach (MDL0ObjectNode obj in m._objList)
432 {
433 if (obj.SingleBind.Equals(oldTop.Name))
434 {
435 obj.SingleBind = actualTop.Name; // Remove unecessary reference to armature bone
436 }
437 else if (obj.SingleBind.EndsWith("_end") && m.FindBone(obj.SingleBind) != null &&
438 m.FindBone(obj.SingleBind).Parent != null &&
439 obj.SingleBind.Equals(m.FindBone(obj.SingleBind).Parent.Name + "_end") &&
440 ensureBoneIsUnused(m.FindBone(obj.SingleBind)))
441 {
442 obj.SingleBind =
444 .Name; // Remove unecessary reference to "end" bones
445 }
446 else
447 {
448 obj.SingleBind = obj.SingleBind; // Ensure bones are still properly linked
449 }
450
451 foreach (DrawCall dc in obj._drawCalls)
452 {
453 if (dc.VisibilityBone.Equals(oldTop.Name))
454 {
455 dc.VisibilityBone = actualTop.Name; // Remove unecessary reference to armature bone
456 }
457 else if (dc.VisibilityBone.EndsWith("_end") && m.FindBone(dc.VisibilityBone) != null &&
458 m.FindBone(dc.VisibilityBone).Parent != null &&
459 dc.VisibilityBone.Equals(m.FindBone(dc.VisibilityBone).Parent.Name + "_end") &&
460 ensureBoneIsUnused(m.FindBone(dc.VisibilityBone)))
461 {
462 dc.VisibilityBone =
464 .Name; // Remove unecessary reference to "end" bones
465 }
466 else
467 {
468 dc.VisibilityBone = dc.VisibilityBone; // Ensure bones are still properly linked
469 }
470 }
471 }
472 }
473 else
474 {
475 // Remove reference to any end bones
476 foreach (MDL0ObjectNode obj in m._objList)
477 {
478 if (obj.SingleBind.EndsWith("_end") && m.FindBone(obj.SingleBind) != null &&
479 m.FindBone(obj.SingleBind).Parent != null &&
480 obj.SingleBind.Equals(m.FindBone(obj.SingleBind).Parent.Name + "_end") &&
481 ensureBoneIsUnused(m.FindBone(obj.SingleBind)))
482 {
483 obj.SingleBind =
485 .Name; // Remove unecessary reference to "end" bones
486 }
487
488 foreach (DrawCall dc in obj._drawCalls)
489 {
490 if (dc.VisibilityBone.EndsWith("_end") && m.FindBone(dc.VisibilityBone) != null &&
491 m.FindBone(dc.VisibilityBone).Parent != null &&
492 dc.VisibilityBone.Equals(m.FindBone(dc.VisibilityBone).Parent.Name + "_end") &&
493 ensureBoneIsUnused(m.FindBone(dc.VisibilityBone)))
494 {
495 dc.VisibilityBone =
497 .Name; // Remove unecessary reference to "end" bones
498 }
499 }
500 }
501 }
502
504 int j = 0;
505 while (b != null)
506 {
507 ++j;
508 if (b != null)
509 {
510 if (b.Name.EndsWith("_end") && ensureBoneIsUnused(b) &&
511 (b.VisibilityDrawCalls == null || b.VisibilityDrawCalls.Length == 0) &&
512 (b.SingleBindObjects == null || b.SingleBindObjects.Length == 0))
513 {
514 b.Parent.RemoveChild(b);
515 }
516 }
517
518 b = m.FindBoneByIndex(j);
519 }
520
522 return m;
523 }
524 }
525
526 return model;
527 }
bool _blenderBoneFix
Definition: ColladaImporter.cs:1217
MatWrapMode TextureWrap
Definition: ColladaImporter.cs:1024
int _modelVersion
Definition: ColladaImporter.cs:1219
MatTextureMinFilter MinFilter
Definition: ColladaImporter.cs:1033
MatTextureMagFilter MagFilter
Definition: ColladaImporter.cs:1042
CullMode _culling
Definition: ColladaImporter.cs:1210
bool _setOrigPath
Definition: ColladaImporter.cs:1216
MDLType _mdlType
Definition: ColladaImporter.cs:1200
static ImportType ModelType
Definition: ColladaImporter.cs:19
static string Error
Definition: ColladaImporter.cs:17
static IModel CurrentModel
Definition: ColladaImporter.cs:18
void Say(string text)
Definition: ColladaImportDialog.cs:30
static ImportOptions _importOptions
Definition: ColladaImporter.cs:949
static Matrix TransformMatrix
Definition: ColladaImporter.cs:22
ImportType
Definition: ColladaImporter.cs:25
Definition: MDL0ObjectNode.cs:2040
string VisibilityBone
Definition: MDL0ObjectNode.cs:2079
Definition: MDL0BoneNode.cs:17
MDL0ObjectNode[] SingleBindObjects
Definition: MDL0BoneNode.cs:170
void RecalcBindState(bool updateMesh, bool moveMeshWithBone, bool updateAssetLists=true)
Definition: MDL0BoneNode.cs:888
Definition: MDL0MaterialNode.cs:22
Definition: MDL0MaterialRefNode.cs:17
Definition: MDL0Node.cs:24
ModelLinker _linker
Definition: MDL0Node.cs:45
List< ResourceNode > _objList
Definition: MDL0Node.cs:306
List< ResourceNode > _matList
Definition: MDL0Node.cs:304
MDL0BoneNode FindBone(string name)
Definition: MDL0Node.cs:752
MDL0GroupNode _matGroup
Definition: MDL0Node.cs:290
MDL0GroupNode _shadGroup
Definition: MDL0Node.cs:291
MDL0GroupNode _boneGroup
Definition: MDL0Node.cs:289
List< ResourceNode > _shadList
Definition: MDL0Node.cs:305
void BeginImport()
Definition: MDL0Node.cs:2599
MDL0BoneNode FindBoneByIndex(int givenIndex)
Definition: MDL0Node.cs:765
Definition: MDL0ObjectNode.cs:21
BindingList< DrawCall > _drawCalls
Definition: MDL0ObjectNode.cs:626
string SingleBind
Definition: MDL0ObjectNode.cs:635
Definition: MDL0ShaderNode.cs:11
override void AddChild(ResourceNode child, bool change)
Definition: MDL0ShaderNode.cs:345
Definition: MDL0TextureNode.cs:17
Definition: ResourceNode.cs:129
virtual bool HasChildren
Definition: ResourceNode.cs:185
ResourceNode[] FindChildrenByName(string name)
Definition: ResourceNode.cs:1558
List< ResourceNode > _children
Definition: ResourceNode.cs:143
ResourceNode Parent
Definition: ResourceNode.cs:245
virtual string Name
Definition: ResourceNode.cs:223
virtual void AddChild(ResourceNode child)
Definition: ResourceNode.cs:757
List< ResourceNode > Children
Definition: ResourceNode.cs:262
virtual void RemoveChild(ResourceNode child)
Definition: ResourceNode.cs:746
void RegenerateBoneCache(bool remake=false)
Definition: ModelLinker.cs:185
string Name
Definition: IBoneNode.cs:11
TexCoordID
Definition: Enum.cs:327
TevKAlphaSel
Definition: Enum.cs:342
ColorSelChan
Definition: Enum.cs:303
TexMapID
Definition: Enum.cs:286
TevKColorSel
Definition: Enum.cs:376
Definition: Matrix.cs:14
static readonly Matrix Identity
Definition: Matrix.cs:15
Definition: Vector3.cs:40

◆ OnShown()

override void BrawlLib.Modeling.Collada.Collada.OnShown ( EventArgs  e)
inlineprotected
37 {
38 base.OnShown(e);
39
40 PropertyInfo info = propertyGrid1.GetType().GetProperty("Controls");
41 Control.ControlCollection collection = (Control.ControlCollection) info.GetValue(propertyGrid1, null);
42
43 foreach (object control in collection)
44 {
45 Type type = control.GetType();
46 if ("DocComment" == type.Name)
47 {
48 const BindingFlags Flags = BindingFlags.Instance | BindingFlags.NonPublic;
49 FieldInfo field = type.BaseType.GetField("userSized", Flags);
50 field.SetValue(control, true);
51
52 info = type.GetProperty("Lines");
53 info.SetValue(control, 5, null);
54
55 propertyGrid1.HelpVisible = true;
56 break;
57 }
58 }
59 }

◆ Say()

void BrawlLib.Modeling.Collada.Collada.Say ( string  text)
inline
31 {
32 Status.Text = text;
33 Update();
34 }

◆ Serialize() [1/2]

static void BrawlLib.Modeling.Collada.Collada.Serialize ( CHR0Node[]  animations,
float  fps,
bool  bake,
string  outFile 
)
inlinestatic
1292 {
1293 string[] types = new[] {"scale", "rotate", "translate"};
1294 string[] axes = new[] {"X", "Y", "Z"};
1295 bool first = true;
1296
1297 using (FileStream stream = new FileStream(outFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None,
1298 0x1000, FileOptions.SequentialScan))
1299 {
1300 using (XmlWriter writer = XmlWriter.Create(stream, _writerSettings))
1301 {
1302 writer.Flush();
1303 stream.Position = 0;
1304
1305 writer.WriteStartDocument();
1306 writer.WriteStartElement("COLLADA", "http://www.collada.org/2008/03/COLLADASchema");
1307 writer.WriteAttributeString("version", "1.4.1");
1308
1309 writer.WriteStartElement("asset");
1310 writer.WriteStartElement("contributor");
1311 writer.WriteElementString("authoring_tool", Application.ProductName);
1312 writer.WriteEndElement();
1313 writer.WriteEndElement();
1314
1315 writer.WriteStartElement("library_animations");
1316 {
1317 foreach (CHR0Node animation in animations)
1318 {
1319 string animName = animation.Name;
1320
1321 writer.WriteStartElement("animation");
1322 writer.WriteAttributeString("name", animName);
1323 writer.WriteAttributeString("id", animName);
1324 {
1325 foreach (CHR0EntryNode en in animation.Children)
1326 {
1327 string bone = en.Name;
1328 KeyframeCollection keyframes = en.Keyframes;
1329
1330 for (int index = 0; index < 9; index++)
1331 {
1332 int keyFrameCount = keyframes._keyArrays[index]._keyCount;
1333 KeyframeEntry root = keyframes._keyArrays[index]._keyRoot;
1334
1335 if (keyFrameCount <= 0)
1336 {
1337 continue;
1338 }
1339
1340 string type = types[index / 3];
1341 string axis = axes[index % 3];
1342
1343 string name = $"{bone}_{type}{axis}";
1344
1345 //writer.WriteStartElement("animation");
1346 //writer.WriteAttributeString("id", name);
1347 {
1348 #region Input source
1349
1350 writer.WriteStartElement("source");
1351 writer.WriteAttributeString("id", name + "_input");
1352 {
1353 writer.WriteStartElement("float_array");
1354 writer.WriteAttributeString("id", name + "_inputArr");
1355 writer.WriteAttributeString("count", keyFrameCount.ToString());
1356 {
1357 first = true;
1358 for (KeyframeEntry entry = root._next;
1359 entry != root;
1360 entry = entry._next)
1361 {
1362 if (first)
1363 {
1364 first = false;
1365 }
1366 else
1367 {
1368 writer.WriteString(" ");
1369 }
1370
1371 writer.WriteString(
1372 (entry._index / fps).ToString(CultureInfo
1373 .InvariantCulture
1374 .NumberFormat));
1375 }
1376 }
1377 writer.WriteEndElement(); //float_array
1378
1379 writer.WriteStartElement("technique_common");
1380 {
1381 writer.WriteStartElement("accessor");
1382 writer.WriteAttributeString("source", "#" + name + "_inputArr");
1383 writer.WriteAttributeString("count", keyFrameCount.ToString());
1384 writer.WriteAttributeString("stride", "1");
1385 {
1386 writer.WriteStartElement("param");
1387 writer.WriteAttributeString("name", "TIME");
1388 writer.WriteAttributeString("type", "float");
1389 writer.WriteEndElement(); //param
1390 }
1391 writer.WriteEndElement(); //accessor
1392 }
1393 writer.WriteEndElement(); //technique_common
1394
1395 writer.WriteStartElement("technique");
1396 writer.WriteAttributeString("profile", "MAYA");
1397 {
1398 writer.WriteStartElement("pre_infinity");
1399 writer.WriteString("CONSTANT");
1400 writer.WriteEndElement(); //pre_infinity
1401
1402 writer.WriteStartElement("post_infinity");
1403 writer.WriteString("CONSTANT");
1404 writer.WriteEndElement(); //post_infinity
1405 }
1406 writer.WriteEndElement(); //technique
1407 }
1408 writer.WriteEndElement(); //source
1409
1410 #endregion
1411
1412 #region Output source
1413
1414 writer.WriteStartElement("source");
1415 writer.WriteAttributeString("id", name + "_output");
1416 {
1417 writer.WriteStartElement("float_array");
1418 writer.WriteAttributeString("id", name + "_outputArr");
1419 writer.WriteAttributeString("count", keyFrameCount.ToString());
1420 {
1421 first = true;
1422 for (KeyframeEntry entry = root._next;
1423 entry != root;
1424 entry = entry._next)
1425 {
1426 if (first)
1427 {
1428 first = false;
1429 }
1430 else
1431 {
1432 writer.WriteString(" ");
1433 }
1434
1435 writer.WriteString(
1436 entry._value.ToString(CultureInfo
1437 .InvariantCulture.NumberFormat));
1438 }
1439 }
1440 writer.WriteEndElement(); //float_array
1441
1442 writer.WriteStartElement("technique_common");
1443 {
1444 writer.WriteStartElement("accessor");
1445 writer.WriteAttributeString("source", "#" + name + "_outputArr");
1446 writer.WriteAttributeString("count", keyFrameCount.ToString());
1447 writer.WriteAttributeString("stride", "1");
1448 {
1449 writer.WriteStartElement("param");
1450 writer.WriteAttributeString("name", "TRANSFORM");
1451 writer.WriteAttributeString("type", "float");
1452 writer.WriteEndElement(); //param
1453 }
1454 writer.WriteEndElement(); //accessor
1455 }
1456 writer.WriteEndElement(); //technique_common
1457 }
1458 writer.WriteEndElement(); //source
1459
1460 #endregion
1461
1462 #region In Tangent source
1463
1464 writer.WriteStartElement("source");
1465 writer.WriteAttributeString("id", name + "_inTan");
1466 {
1467 writer.WriteStartElement("float_array");
1468 writer.WriteAttributeString("id", name + "_inTanArr");
1469 writer.WriteAttributeString("count", keyFrameCount.ToString());
1470 {
1471 first = true;
1472 for (KeyframeEntry entry = root._next;
1473 entry != root;
1474 entry = entry._next)
1475 {
1476 if (first)
1477 {
1478 first = false;
1479 }
1480 else
1481 {
1482 writer.WriteString(" ");
1483 }
1484
1485 writer.WriteString(
1486 entry._tangent.ToString(CultureInfo
1487 .InvariantCulture.NumberFormat));
1488 }
1489 }
1490 writer.WriteEndElement(); //float_array
1491
1492 writer.WriteStartElement("technique_common");
1493 {
1494 writer.WriteStartElement("accessor");
1495 writer.WriteAttributeString("source", "#" + name + "_inTanArr");
1496 writer.WriteAttributeString("count", keyFrameCount.ToString());
1497 writer.WriteAttributeString("stride", "1");
1498 {
1499 writer.WriteStartElement("param");
1500 writer.WriteAttributeString("name", "IN_TANGENT");
1501 writer.WriteAttributeString("type", "float");
1502 writer.WriteEndElement(); //param
1503 }
1504 writer.WriteEndElement(); //accessor
1505 }
1506 writer.WriteEndElement(); //technique_common
1507 }
1508 writer.WriteEndElement(); //source
1509
1510 #endregion
1511
1512 #region Out Tangent source
1513
1514 writer.WriteStartElement("source");
1515 writer.WriteAttributeString("id", name + "_outTan");
1516 {
1517 writer.WriteStartElement("float_array");
1518 writer.WriteAttributeString("id", name + "_outTanArr");
1519 writer.WriteAttributeString("count", keyFrameCount.ToString());
1520 {
1521 first = true;
1522 for (KeyframeEntry entry = root._next;
1523 entry != root;
1524 entry = entry._next)
1525 {
1526 if (first)
1527 {
1528 first = false;
1529 }
1530 else
1531 {
1532 writer.WriteString(" ");
1533 }
1534
1535 writer.WriteString(
1536 entry._tangent.ToString(CultureInfo
1537 .InvariantCulture.NumberFormat));
1538 }
1539 }
1540 writer.WriteEndElement(); //float_array
1541
1542 writer.WriteStartElement("technique_common");
1543 {
1544 writer.WriteStartElement("accessor");
1545 writer.WriteAttributeString("source", "#" + name + "_outTanArr");
1546 writer.WriteAttributeString("count", keyFrameCount.ToString());
1547 writer.WriteAttributeString("stride", "1");
1548 {
1549 writer.WriteStartElement("param");
1550 writer.WriteAttributeString("name", "OUT_TANGENT");
1551 writer.WriteAttributeString("type", "float");
1552 writer.WriteEndElement(); //param
1553 }
1554 writer.WriteEndElement(); //accessor
1555 }
1556 writer.WriteEndElement(); //technique_common
1557 }
1558 writer.WriteEndElement(); //source
1559
1560 #endregion
1561
1562 #region Interpolation source
1563
1564 writer.WriteStartElement("source");
1565 writer.WriteAttributeString("id", name + "_interp");
1566 {
1567 writer.WriteStartElement("Name_array");
1568 writer.WriteAttributeString("id", name + "_interpArr");
1569 writer.WriteAttributeString("count", keyFrameCount.ToString());
1570 {
1571 first = true;
1572 for (KeyframeEntry entry = root._next;
1573 entry != root;
1574 entry = entry._next)
1575 {
1576 if (first)
1577 {
1578 first = false;
1579 }
1580 else
1581 {
1582 writer.WriteString(" ");
1583 }
1584
1585 writer.WriteString("HERMITE");
1586 }
1587 }
1588 writer.WriteEndElement(); //Name_array
1589
1590 writer.WriteStartElement("technique_common");
1591 {
1592 writer.WriteStartElement("accessor");
1593 writer.WriteAttributeString("source", "#" + name + "_interpArr");
1594 writer.WriteAttributeString("count", keyFrameCount.ToString());
1595 writer.WriteAttributeString("stride", "1");
1596 {
1597 writer.WriteStartElement("param");
1598 writer.WriteAttributeString("name", "INTERPOLATION");
1599 writer.WriteAttributeString("type", "Name");
1600 writer.WriteEndElement(); //param
1601 }
1602 writer.WriteEndElement(); //accessor
1603 }
1604 writer.WriteEndElement(); //technique_common
1605 }
1606 writer.WriteEndElement(); //source
1607
1608 #endregion
1609
1610 #region Sampler
1611
1612 writer.WriteStartElement("sampler");
1613 writer.WriteAttributeString("id", name + "_sampler");
1614 {
1615 writer.WriteStartElement("input");
1616 writer.WriteAttributeString("semantic", "INPUT");
1617 writer.WriteAttributeString("source", "#" + name + "_input");
1618 writer.WriteEndElement(); //input
1619
1620 writer.WriteStartElement("input");
1621 writer.WriteAttributeString("semantic", "OUTPUT");
1622 writer.WriteAttributeString("source", "#" + name + "_output");
1623 writer.WriteEndElement(); //input
1624
1625 writer.WriteStartElement("input");
1626 writer.WriteAttributeString("semantic", "IN_TANGENT");
1627 writer.WriteAttributeString("source", "#" + name + "_inTan");
1628 writer.WriteEndElement(); //input
1629
1630 writer.WriteStartElement("input");
1631 writer.WriteAttributeString("semantic", "OUT_TANGEN");
1632 writer.WriteAttributeString("source", "#" + name + "_outTan");
1633 writer.WriteEndElement(); //input
1634
1635 writer.WriteStartElement("input");
1636 writer.WriteAttributeString("semantic", "INTERPOLATION");
1637 writer.WriteAttributeString("source", "#" + name + "_interp");
1638 writer.WriteEndElement(); //input
1639 }
1640 writer.WriteEndElement(); //sampler
1641
1642 #endregion
1643
1644 writer.WriteStartElement("channel");
1645 writer.WriteAttributeString("source", "#" + name + "_sampler");
1646 writer.WriteAttributeString("target",
1647 $"{bone}/{type}.{axis}");
1648 writer.WriteEndElement(); //channel
1649 }
1650 //writer.WriteEndElement(); //animation
1651 }
1652 }
1653 }
1654 writer.WriteEndElement(); //animation
1655 }
1656
1657 writer.WriteEndElement(); //library_animations
1658 }
1659 }
1660 }
1661 }
Definition: CHR0Node.cs:909
KeyframeCollection Keyframes
Definition: CHR0Node.cs:923
Definition: CHR0Node.cs:17
Definition: KeyframeCollection.cs:17
KeyframeArray[] _keyArrays
Definition: KeyframeCollection.cs:18
Definition: KeyframeCollection.cs:193
KeyframeEntry _next
Definition: KeyframeCollection.cs:195

◆ Serialize() [2/2]

static void BrawlLib.Modeling.Collada.Collada.Serialize ( MDL0Node  model,
string  outFile 
)
inlinestatic
21 {
22 model.Populate();
23 model.ApplyCHR(null, 0);
24
25 using (FileStream stream = new FileStream(outFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None,
26 0x1000, FileOptions.SequentialScan))
27 {
28 using (XmlWriter writer = XmlWriter.Create(stream, _writerSettings))
29 {
30 writer.Flush();
31 stream.Position = 0;
32
33 writer.WriteStartDocument();
34 writer.WriteStartElement("COLLADA", "http://www.collada.org/2008/03/COLLADASchema");
35 writer.WriteAttributeString("version", "1.5.0");
36
37 writer.WriteStartElement("asset");
38 {
39 writer.WriteStartElement("contributor");
40 writer.WriteElementString("authoring_tool", Application.ProductName);
41 writer.WriteEndElement();
42
43 writer.WriteStartElement("created");
44 writer.WriteString(DateTime.UtcNow.ToString("s", CultureInfo.InvariantCulture) + "Z");
45 writer.WriteEndElement();
46
47 writer.WriteStartElement("modified");
48 writer.WriteString(DateTime.UtcNow.ToString("s", CultureInfo.InvariantCulture) + "Z");
49 writer.WriteEndElement();
50
51 writer.WriteStartElement("unit");
52 writer.WriteAttributeString("meter", "0.01");
53 writer.WriteAttributeString("name", "centimeter");
54 writer.WriteEndElement();
55
56 writer.WriteElementString("up_axis", "Y_UP");
57 }
58 writer.WriteEndElement();
59
60 //Define images
61 WriteImages(model, writer);
62
63 //Define materials
64 WriteMaterials(model, writer);
65
66 //Define effects
67 WriteEffects(model, writer);
68
69 //Define geometry
70 //Create a geometry object for each polygon
71 WriteGeometry(model, writer);
72
73 //Define controllers
74 //Each weighted polygon needs a controller, which assigns weights to each vertex.
75 WriteControllers(model, writer);
76
77 //Define scenes
78 writer.WriteStartElement("library_visual_scenes");
79 {
80 writer.WriteStartElement("visual_scene");
81 {
82 //Attach nodes/bones to scene, starting with TopN
83 //Specify transform for each node
84 //Weighted polygons must use instance_controller
85 //Standard geometry uses instance_geometry
86
87 writer.WriteAttributeString("id", "RootNode");
88 writer.WriteAttributeString("name", "RootNode");
89
90 //Define bones and geometry instances
91 WriteNodes(model, writer);
92 }
93 writer.WriteEndElement();
94 }
95 writer.WriteEndElement();
96
97 writer.WriteStartElement("scene");
98 {
99 writer.WriteStartElement("instance_visual_scene");
100 writer.WriteAttributeString("url", "#RootNode");
101 writer.WriteEndElement(); //instance visual scene
102 }
103 writer.WriteEndElement(); //scene
104 }
105 }
106 }
void ApplyCHR(CHR0Node node, float index)
Definition: MDL0Node.cs:3215
void Populate(int levels=-1)
Definition: ResourceNode.cs:613

◆ ShowDialog()

IModel BrawlLib.Modeling.Collada.Collada.ShowDialog ( string  filePath,
ImportType  type 
)
inline
62 {
63 _importOptions = Properties.Settings.Default.ColladaImportOptions;
64 propertyGrid1.SelectedObject = _importOptions;
65
66 if (ShowDialog() == DialogResult.OK)
67 {
68 panel1.Visible = false;
69 Height = 70;
70 UseWaitCursor = true;
71 Text = "Please wait...";
72 Show();
73 Update();
74 IModel model = ImportModel(filePath, type);
75 Properties.Settings.Default.Save();
76 Close();
77 _importOptions = new ImportOptions();
78 return model;
79 }
80
81 _importOptions = new ImportOptions();
82 return null;
83 }
IModel ShowDialog(string filePath, ImportType type)
Definition: ColladaImportDialog.cs:61
IModel ImportModel(string filePath, ImportType type)
Definition: ColladaImporter.cs:33

Member Data Documentation

◆ _filePath

string BrawlLib.Modeling.Collada.Collada._filePath

◆ _importOptions

ImportOptions BrawlLib.Modeling.Collada.Collada._importOptions = new ImportOptions()
static

◆ CurrentModel

IModel BrawlLib.Modeling.Collada.Collada.CurrentModel
static

◆ Error

string BrawlLib.Modeling.Collada.Collada.Error
static

◆ ModelType

ImportType BrawlLib.Modeling.Collada.Collada.ModelType
static

◆ TransformMatrix

Matrix BrawlLib.Modeling.Collada.Collada.TransformMatrix = Matrix.Identity
static

The documentation for this class was generated from the following files: