forked from katzsmile/MakeSKN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
1037 lines (968 loc) · 55.7 KB
/
Copy pathProgram.cs
File metadata and controls
1037 lines (968 loc) · 55.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;
using System.Xml;
enum RenderObjectType
{
Mesh,
CollisionBox
};
enum LevelOfDetail
{
High,
Medium,
Low
};
namespace makeskn
{
class Program
{
static int errors = 0;
static void EmitError(string e)
{
Console.WriteLine("MakeSKN: Error: {0}", e);
++errors;
}
static bool checkLOD(string w3xfile, string fPath, LevelOfDetail LODType)
{
string fPathLowLOD = "";
string LODVersion = "";
switch (LODType)
{
case LevelOfDetail.Medium:
fPathLowLOD = Path.Combine(fPath, "MediumLOD");
LODVersion = "Medium";
break;
case LevelOfDetail.Low:
fPathLowLOD = Path.Combine(fPath, "LowLOD");
LODVersion = "Low";
break;
}
bool IsLowLOD = false;
string fileName = Path.GetFileName(w3xfile);
if (File.Exists(w3xfile))
{
try
{
string Skeleton = "";
string Container = "";
ArrayList SubObjects = new ArrayList();
ArrayList SubObjectTypes = new ArrayList();
ArrayList TexturesList = new ArrayList();
XmlDocument xDoc = new XmlDocument();
xDoc.Load(w3xfile);
string nXML = w3xfile;
XmlNodeList AssetDeclarations = xDoc.GetElementsByTagName("AssetDeclaration");
XmlNodeList W3DContainers = xDoc.GetElementsByTagName("W3DContainer");
XmlNodeList W3DMeshes = xDoc.GetElementsByTagName("W3DMesh");
XmlNodeList W3DCollisionBoxes = xDoc.GetElementsByTagName("W3DCollisionBox");
XmlElement newIncludes = xDoc.CreateElement("Includes", "uri:ea.com:eala:asset");
if (W3DContainers.Count != 0)
{
// Check if LowLOD Container
if (File.Exists(Path.Combine(fPathLowLOD, $"{fileName}")))
{
Console.Write($"\nHas {LODVersion} LOD Container");
return true;
}
foreach (XmlNode AssetDeclaration in AssetDeclarations)
{
foreach (XmlNode W3DContainer in W3DContainers)
{
XmlNamedNodeMap mapAttributes = W3DContainer.Attributes;
foreach (XmlNode xnodAttribute in mapAttributes)
{
if (xnodAttribute.Name == "Hierarchy")
{
xnodAttribute.Value = xnodAttribute.Value.ToUpperInvariant();
Skeleton = xnodAttribute.Value;
}
if (xnodAttribute.Name == "id")
{
Container = xnodAttribute.Value;
}
}
if (!String.IsNullOrEmpty(Skeleton))
{
// If Container ID and Skeleton ID is the same, should be in same file
if (Container.ToLowerInvariant() == Skeleton.ToLowerInvariant())
{
if (File.Exists(Path.Combine(fPathLowLOD, $"{Skeleton}_HRC.w3x")))
{
Console.Write($"\nHas {LODVersion} LOD Skeleton");
// Create LowLOD container in LowLOD folder
File.Copy(Path.Combine(fPath, $"{fileName}"), Path.Combine(fPathLowLOD, $"{fileName}"), true);
return true;
}
}
}
// Search for animation files that have the same ID as the Container
if (File.Exists(Path.Combine(fPath, $"{Container}.w3x")))
{
if (File.Exists(Path.Combine(fPathLowLOD, $"{Container}.w3x")))
{
// Check that it is Animation
string AnimationFile = Path.Combine(fPathLowLOD, $"{Container}.w3x");
XmlTextReader reader = new XmlTextReader(AnimationFile);
// Check that it is an Animation File
if (reader.ReadToFollowing("W3DAnimation"))
{
reader.Close();
Console.Write($"\nHas {LODVersion} LOD Animation");
// Create LowLOD container in LowLOD folder
File.Copy(Path.Combine(fPath, $"{fileName}"), Path.Combine(fPathLowLOD, $"{fileName}"), true);
return true;
}
else
{
reader.Close();
}
}
}
XmlNodeList RenderObjects = xDoc.GetElementsByTagName("RenderObject");
foreach (XmlNode RenderObject in RenderObjects)
{
string strValue = (string)RenderObject.FirstChild.InnerText;
if (RenderObject.FirstChild.Name == "Mesh")
{
SubObjectTypes.Add(RenderObjectType.Mesh);
}
else if (RenderObject.FirstChild.Name == "CollisionBox")
{
SubObjectTypes.Add(RenderObjectType.CollisionBox);
}
SubObjects.Add(strValue);
}
if (SubObjects.Count > 0)
{
for (int i = 0; i < SubObjects.Count; i++)
{
if (File.Exists(Path.Combine(fPathLowLOD, $"{SubObjects[i]}.w3x")))
{
Console.Write($"\nHas {LODVersion} LOD RenderObject");
// Create LowLOD container in LowLOD folder
File.Copy(Path.Combine(fPath, $"{fileName}"), Path.Combine(fPathLowLOD, $"{fileName}"), true);
return true;
}
}
}
}
}
}
}
catch (Exception e)
{
Console.Write("[ERROR]\n");
EmitError("Failed with exception: {0}" + Convert.ToString(e));
}
}
return IsLowLOD;
}
static void buildfile(string w3xfile, string fPath, LevelOfDetail LODType)
{
if (File.Exists(w3xfile))
{
try
{
string Skeleton = "";
string Container = "";
ArrayList SubObjects = new ArrayList();
ArrayList SubObjectTypes = new ArrayList();
ArrayList TexturesList = new ArrayList();
XmlDocument xDoc = new XmlDocument();
xDoc.Load(w3xfile);
string nXML = w3xfile;
XmlNodeList AssetDeclarations = xDoc.GetElementsByTagName("AssetDeclaration");
XmlNodeList W3DContainers = xDoc.GetElementsByTagName("W3DContainer");
XmlNodeList W3DSkeletons = xDoc.GetElementsByTagName("W3DHierarchy");
XmlNodeList W3DAnimations = xDoc.GetElementsByTagName("W3DAnimation");
XmlNodeList W3DMeshes = xDoc.GetElementsByTagName("W3DMesh");
XmlNodeList W3DCollisionBoxes = xDoc.GetElementsByTagName("W3DCollisionBox");
XmlElement newIncludes = xDoc.CreateElement("Includes", "uri:ea.com:eala:asset");
string fPathLowLOD = "";
string LODPostFix = "";
string LODVersion = "";
switch (LODType)
{
case LevelOfDetail.Medium:
fPathLowLOD = Path.Combine(fPath, "MediumLOD");
LODPostFix = "_M";
LODVersion = "Medium";
break;
case LevelOfDetail.Low:
fPathLowLOD = Path.Combine(fPath, "LowLOD");
LODPostFix = "_L";
LODVersion = "Low";
break;
}
bool islowLOD = false;
if (LODType == LevelOfDetail.Medium || LODType == LevelOfDetail.Low)
{
islowLOD = true;
}
if (W3DContainers.Count != 0)
{
foreach (XmlNode AssetDeclaration in AssetDeclarations)
{
foreach (XmlNode W3DContainer in W3DContainers)
{
XmlNamedNodeMap mapAttributes = W3DContainer.Attributes;
foreach (XmlNode xnodAttribute in mapAttributes)
{
if (xnodAttribute.Name == "Hierarchy")
{
xnodAttribute.Value = xnodAttribute.Value.ToUpperInvariant();
Skeleton = xnodAttribute.Value;
}
if (xnodAttribute.Name == "id")
{
Container = xnodAttribute.Value;
}
}
if (islowLOD)
{
Console.Write($"\nProcessing {LODVersion} LOD W3X Container: {Container}");
}
else
{
Console.Write($"\nProcessing W3X Container: {Container}");
}
if (!String.IsNullOrEmpty(Skeleton))
{
// If Container ID and Skeleton ID is the same, should be in same file
if (Container.ToLowerInvariant() == Skeleton.ToLowerInvariant())
{
string SkeletonFile;
bool SkeletonLowLOD;
// Bibber's skeleton extension "_HRC". Not applied to SKL but normally the containers won't match the name in this case
if (File.Exists(Path.Combine(fPathLowLOD, $"{Skeleton}_HRC.w3x")) && islowLOD)
{
SkeletonFile = Path.Combine(fPathLowLOD, $"{Skeleton}_HRC.w3x");
SkeletonLowLOD = true;
}
else
{
SkeletonFile = Path.Combine(fPath, $"{Skeleton}_HRC.w3x");
SkeletonLowLOD = false;
}
XmlTextReader reader = new XmlTextReader(SkeletonFile);
while (reader.Read())
{
reader.ReadToFollowing("W3DHierarchy");
string strInner = reader.ReadOuterXml();
if (strInner.Length != 0)
{
XmlTextReader xmlReader = new XmlTextReader(new StringReader(strInner));
xmlReader.WhitespaceHandling = WhitespaceHandling.None;
XmlNode SkeletonNode = xDoc.ReadNode(xmlReader);
xDoc.DocumentElement.InsertBefore(SkeletonNode, W3DContainer);
xDoc.Save(nXML);
Console.Write($"\n Adding W3X Hierarchy: {Skeleton}");
}
}
// Delete Skeleton File
reader.Close();
if (SkeletonLowLOD || !islowLOD)
{
File.Delete(SkeletonFile);
}
}
// Otherwise reference them to include
else
{
XmlElement Include = xDoc.CreateElement("Include", "uri:ea.com:eala:asset");
Include.SetAttribute("type", "all");
Skeleton = Skeleton.ToLower();
Include.SetAttribute("source", $"ART:{Skeleton}.w3x");
newIncludes.AppendChild(Include);
xDoc.DocumentElement.InsertBefore(newIncludes, W3DContainer);
xDoc.Save(nXML);
}
}
// Search for animation files that have the same ID as the Container
if (File.Exists(Path.Combine(fPath, $"{Container}.w3x")))
{
string AnimationFile;
bool AnimationLowLOD;
if (File.Exists(Path.Combine(fPathLowLOD, $"{Container}.w3x")) && islowLOD)
{
AnimationFile = Path.Combine(fPathLowLOD, $"{Container}.w3x");
AnimationLowLOD = true;
}
else
{
AnimationFile = Path.Combine(fPath, $"{Container}.w3x");
AnimationLowLOD = false;
}
XmlTextReader reader = new XmlTextReader(AnimationFile);
// Check that it is an Animation File
if (reader.ReadToFollowing("W3DAnimation"))
{
reader.Close();
reader = new XmlTextReader(AnimationFile);
while (reader.Read())
{
reader.ReadToFollowing("W3DAnimation");
string strInner = reader.ReadOuterXml();
if (strInner.Length != 0)
{
XmlTextReader xmlReader = new XmlTextReader(new StringReader(strInner));
xmlReader.WhitespaceHandling = WhitespaceHandling.None;
XmlNode AnimationNode = xDoc.ReadNode(xmlReader);
xDoc.DocumentElement.InsertBefore(AnimationNode, W3DContainer);
xDoc.Save(nXML);
}
}
// Delete Animation File
reader.Close();
if (AnimationLowLOD || !islowLOD)
{
File.Delete(AnimationFile);
}
Console.Write($"\n Adding W3X Animation: {Container}");
}
else
{
reader.Close();
}
}
// Unique Case
else if (File.Exists(Path.Combine(fPathLowLOD, $"{Container}.w3x")))
{
string AnimationFile = Path.Combine(fPathLowLOD, $"{Container}.w3x");
XmlTextReader reader = new XmlTextReader(AnimationFile);
// Check that it is an Animation File
if (reader.ReadToFollowing("W3DAnimation"))
{
reader.Close();
reader = new XmlTextReader(AnimationFile);
while (reader.Read())
{
reader.ReadToFollowing("W3DAnimation");
string strInner = reader.ReadOuterXml();
if (strInner.Length != 0)
{
XmlTextReader xmlReader = new XmlTextReader(new StringReader(strInner));
xmlReader.WhitespaceHandling = WhitespaceHandling.None;
XmlNode AnimationNode = xDoc.ReadNode(xmlReader);
xDoc.DocumentElement.InsertBefore(AnimationNode, W3DContainer);
xDoc.Save(nXML);
}
}
// Delete Animation File
reader.Close();
File.Delete(AnimationFile);
Console.Write($"\n Adding W3X Animation: {Container}");
}
else
{
reader.Close();
}
}
XmlNodeList RenderObjects = xDoc.GetElementsByTagName("RenderObject");
foreach (XmlNode RenderObject in RenderObjects)
{
string strValue = (string)RenderObject.FirstChild.InnerText;
if (RenderObject.FirstChild.Name == "Mesh")
{
SubObjectTypes.Add(RenderObjectType.Mesh);
}
else if (RenderObject.FirstChild.Name == "CollisionBox")
{
SubObjectTypes.Add(RenderObjectType.CollisionBox);
}
SubObjects.Add(strValue);
}
if (SubObjects.Count > 0)
{
for (int i = 0; i < SubObjects.Count; i++)
{
string SubObjectFile;
bool RenderLowLOD;
if (File.Exists(Path.Combine(fPathLowLOD, $"{SubObjects[i]}.w3x")) && islowLOD)
{
SubObjectFile = Path.Combine(fPathLowLOD, $"{SubObjects[i]}.w3x");
RenderLowLOD = true;
}
else
{
SubObjectFile = Path.Combine(fPath, $"{SubObjects[i]}.w3x");
RenderLowLOD = false;
}
XmlTextReader reader = new XmlTextReader(SubObjectFile);
while (reader.Read())
{
if ((RenderObjectType)SubObjectTypes[i] == RenderObjectType.Mesh)
{
reader.ReadToFollowing("W3DMesh");
}
else if ((RenderObjectType)SubObjectTypes[i] == RenderObjectType.CollisionBox)
{
reader.ReadToFollowing("W3DCollisionBox");
}
string strInner = reader.ReadOuterXml();
if (strInner.Length != 0)
{
XmlTextReader xmlReader = new XmlTextReader(new StringReader(strInner));
xmlReader.WhitespaceHandling = WhitespaceHandling.None;
XmlNode SubObjectNode = xDoc.ReadNode(xmlReader);
xDoc.DocumentElement.InsertBefore(SubObjectNode, W3DContainer);
xDoc.Save(nXML);
}
}
reader.Close();
if (RenderLowLOD || !islowLOD)
{
File.Delete(SubObjectFile);
}
Console.Write($"\n Adding W3X Render Object: {SubObjects[i]}");
}
}
}
}
XmlNodeList Textures = xDoc.GetElementsByTagName("Texture");
foreach (XmlNode Texture in Textures)
{
string strTexture = (string)Texture.InnerText;
strTexture = strTexture.Trim();
if (!TexturesList.Contains(strTexture))
{
TexturesList.Add(strTexture);
}
}
// Insert Includes if Skeleton is in file
if (Container.ToLowerInvariant() == Skeleton.ToLowerInvariant())
{
foreach (XmlNode W3DHierarchy in W3DSkeletons)
{
xDoc.DocumentElement.InsertBefore(newIncludes, W3DHierarchy);
// Remove redundant namespace
XmlAttributeCollection mapAttributes = W3DHierarchy.Attributes;
mapAttributes.Remove(mapAttributes["xmlns"]);
XmlNodeList FixupMatrices = xDoc.GetElementsByTagName("FixupMatrix");
foreach (XmlNode FixupMatrix in FixupMatrices)
{
XmlAttributeCollection FixupMatrixAttributes = FixupMatrix.Attributes;
FixupMatrixAttributes.Remove(FixupMatrixAttributes["M03"]);
FixupMatrixAttributes.Remove(FixupMatrixAttributes["M13"]);
FixupMatrixAttributes.Remove(FixupMatrixAttributes["M23"]);
FixupMatrixAttributes.Remove(FixupMatrixAttributes["M33"]);
}
XmlNodeList W3DBones = xDoc.GetElementsByTagName("Pivot");
foreach (XmlNode Pivot in W3DBones)
{
XmlAttributeCollection PivotAttributes = Pivot.Attributes;
foreach (XmlNode xnodAttribure in PivotAttributes)
{
if (xnodAttribure.Name == "Name")
{
xnodAttribure.Value = xnodAttribure.Value.ToUpperInvariant();
}
}
}
xDoc.Save(nXML);
}
}
foreach (string strTex in TexturesList)
{
XmlElement Include = xDoc.CreateElement("Include", "uri:ea.com:eala:asset");
Include.SetAttribute("type", "all");
string strTex2 = strTex.ToLower();
Include.SetAttribute("source", $"ART:{strTex2}.xml");
newIncludes.AppendChild(Include);
xDoc.Save(nXML);
}
// Remove Comments
XmlNodeList Comments = xDoc.SelectNodes("//comment()");
foreach (XmlNode Comment in Comments)
{
xDoc.PreserveWhitespace = false;
Comment.ParentNode.RemoveChild(Comment);
xDoc.Save(nXML);
}
// Remove Namespace in each W3D element
foreach (XmlNode W3DAnimation in W3DAnimations)
{
XmlAttributeCollection mapAttributes = W3DAnimation.Attributes;
mapAttributes.Remove(mapAttributes["xmlns"]);
foreach (XmlNode xnodAttribute in mapAttributes)
{
if (xnodAttribute.Name == "Hierarchy")
{
xnodAttribute.Value = xnodAttribute.Value.ToUpperInvariant();
Skeleton = xnodAttribute.Value;
}
}
xDoc.Save(nXML);
}
foreach (XmlNode W3DMesh in W3DMeshes)
{
XmlAttributeCollection mapAttributes = W3DMesh.Attributes;
mapAttributes.Remove(mapAttributes["xmlns"]);
xDoc.Save(nXML);
}
foreach (XmlNode W3DCollisionBox in W3DCollisionBoxes)
{
XmlAttributeCollection mapAttributes = W3DCollisionBox.Attributes;
mapAttributes.Remove(mapAttributes["xmlns"]);
bool JoypadPickingDefault = false;
XmlNamedNodeMap AttributeList = W3DCollisionBox.Attributes;
foreach (XmlNode xnodAttribute in mapAttributes)
{
if (xnodAttribute.Name == "JoypadPickingOnly")
{
if (xnodAttribute.Value == "false")
{
JoypadPickingDefault = true;
}
}
}
if (JoypadPickingDefault)
{
mapAttributes.Remove(mapAttributes["JoypadPickingOnly"]);
}
xDoc.Save(nXML);
}
Console.Write("\n[SUCCESS]\n");
// Set up to sort into sub folders
string SubFolderName = Container.Substring(0, 2);
DirectoryInfo CompiledFolder = new DirectoryInfo(Path.Combine(fPath, "Compiled"));
CompiledFolder.CreateSubdirectory(SubFolderName);
if (islowLOD)
{
if (Path.GetFileNameWithoutExtension(w3xfile).ToLowerInvariant() == Container.ToLowerInvariant())
{
File.Copy(Path.Combine(fPathLowLOD, $"{Container}.w3x"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{Container}{LODPostFix}.w3x"), true);
File.Delete(Path.Combine(fPathLowLOD, $"{Container}.w3x"));
}
else
{
File.Copy(Path.Combine(fPathLowLOD, $"{Container}_CTR.w3x"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{Container}{LODPostFix}.w3x"), true);
File.Delete(Path.Combine(fPathLowLOD, $"{Container}_CTR.w3x"));
}
}
else
{
if (Path.GetFileNameWithoutExtension(w3xfile).ToLowerInvariant() == Container.ToLowerInvariant())
{
File.Copy(Path.Combine(fPath, $"{Container}.w3x"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{Container}.w3x"), true);
File.Delete(Path.Combine(fPath, $"{Container}.w3x"));
}
else
{
File.Copy(Path.Combine(fPath, $"{Container}_CTR.w3x"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{Container}.w3x"), true);
File.Delete(Path.Combine(fPath, $"{Container}_CTR.w3x"));
}
}
}
}
catch (Exception e)
{
Console.Write("\n[ERROR]\n");
EmitError("Failed with exception: {0}" + Convert.ToString(e));
}
}
}
static void movefiles(string w3xfile, string fPath, LevelOfDetail LODType)
{
if (File.Exists(w3xfile))
{
try
{
string Animation = "";
string Skeleton = "";
string Mesh = "";
XmlDocument xDoc = new XmlDocument();
xDoc.Load(w3xfile);
string nXML = w3xfile;
XmlNodeList AssetDeclarations = xDoc.GetElementsByTagName("AssetDeclaration");
XmlNodeList W3DAnimations = xDoc.GetElementsByTagName("W3DAnimation");
XmlNodeList W3DSkeletons = xDoc.GetElementsByTagName("W3DHierarchy");
XmlNodeList W3DMeshes = xDoc.GetElementsByTagName("W3DMesh");
XmlNodeList Includes = xDoc.GetElementsByTagName("Includes");
XmlElement newIncludes = xDoc.CreateElement("Includes", "uri:ea.com:eala:asset");
string fPathLowLOD = "";
string LODPostFix = "";
switch (LODType)
{
case LevelOfDetail.Medium:
fPathLowLOD = Path.Combine(fPath, "MediumLOD");
LODPostFix = "_M";
break;
case LevelOfDetail.Low:
fPathLowLOD = Path.Combine(fPath, "LowLOD");
LODPostFix = "_L";
break;
}
bool islowLOD = false;
if (LODType == LevelOfDetail.Medium || LODType == LevelOfDetail.Low)
{
islowLOD = true;
}
if (W3DAnimations.Count != 0)
{
Console.Write($"\nProcessing W3X Animation: {w3xfile}");
foreach (XmlNode AssetDeclaration in AssetDeclarations)
{
XmlNamedNodeMap DeclarationAttributes = AssetDeclaration.Attributes;
bool FullDeclaration = false;
foreach (XmlNode ADAttributes in DeclarationAttributes)
{
if (ADAttributes.Name == "xmlns:xsi")
{
FullDeclaration = true;
}
}
if (!FullDeclaration)
{
XmlAttribute XSIDeclaration = xDoc.CreateAttribute("xmlns:xsi");
XSIDeclaration.Value = "http://www.w3.org/2001/XMLSchema-instance";
AssetDeclaration.Attributes.Append(XSIDeclaration);
xDoc.Save(nXML);
}
foreach (XmlNode W3DAnimation in W3DAnimations)
{
XmlNamedNodeMap mapAttributes = W3DAnimation.Attributes;
foreach (XmlNode xnodAttribute in mapAttributes)
{
if (xnodAttribute.Name == "id")
{
Animation = xnodAttribute.Value;
}
if (xnodAttribute.Name == "Hierarchy")
{
xnodAttribute.Value = xnodAttribute.Value.ToUpperInvariant();
Skeleton = xnodAttribute.Value;
}
}
if (Includes.Count == 0)
{
XmlElement Include = xDoc.CreateElement("Include", "uri:ea.com:eala:asset");
Include.SetAttribute("type", "all");
Skeleton = Skeleton.ToLower();
Include.SetAttribute("source", $"ART:{Skeleton}.w3x");
newIncludes.AppendChild(Include);
xDoc.DocumentElement.InsertBefore(newIncludes, W3DAnimation);
xDoc.Save(nXML);
}
}
// Remove Comments
XmlNodeList Comments = xDoc.SelectNodes("//comment()");
foreach (XmlNode Comment in Comments)
{
xDoc.PreserveWhitespace = false;
Comment.ParentNode.RemoveChild(Comment);
xDoc.Save(nXML);
}
Console.Write(" [SUCCESS]");
// Copy into compiled folder to avoid second pass
string SubFolderName = Animation.Substring(0, 2);
DirectoryInfo CompiledFolder = new DirectoryInfo(Path.Combine(fPath, "Compiled"));
CompiledFolder.CreateSubdirectory(SubFolderName);
if (islowLOD)
{
File.Copy(Path.Combine(fPathLowLOD, $"{Animation}.w3x"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{Animation}{LODPostFix}.w3x"), true);
File.Delete(Path.Combine(fPathLowLOD, $"{Animation}.w3x"));
}
else
{
File.Copy(Path.Combine(fPath, $"{Animation}.w3x"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{Animation}.w3x"), true);
File.Delete(Path.Combine(fPath, $"{Animation}.w3x"));
}
}
}
if (W3DSkeletons.Count != 0)
{
Console.Write($"\nProcessing W3X Skeleton: {w3xfile}");
foreach (XmlNode AssetDeclaration in AssetDeclarations)
{
foreach (XmlNode W3DHierarchy in W3DSkeletons)
{
XmlNamedNodeMap mapAttributes = W3DHierarchy.Attributes;
foreach (XmlNode xnodAttribute in mapAttributes)
{
if (xnodAttribute.Name == "id")
{
Skeleton = xnodAttribute.Value;
}
}
XmlNodeList FixupMatrices = xDoc.GetElementsByTagName("FixupMatrix");
foreach (XmlNode FixupMatrix in FixupMatrices)
{
XmlAttributeCollection FixupMatrixAttributes = FixupMatrix.Attributes;
FixupMatrixAttributes.Remove(FixupMatrixAttributes["M03"]);
FixupMatrixAttributes.Remove(FixupMatrixAttributes["M13"]);
FixupMatrixAttributes.Remove(FixupMatrixAttributes["M23"]);
FixupMatrixAttributes.Remove(FixupMatrixAttributes["M33"]);
}
XmlNodeList W3DBones = xDoc.GetElementsByTagName("Pivot");
foreach (XmlNode Pivot in W3DBones)
{
XmlAttributeCollection PivotAttributes = Pivot.Attributes;
foreach (XmlNode xnodAttribure in PivotAttributes)
{
if (xnodAttribure.Name == "Name")
{
xnodAttribure.Value = xnodAttribure.Value.ToUpperInvariant();
}
}
}
xDoc.DocumentElement.InsertBefore(newIncludes, W3DHierarchy);
xDoc.Save(nXML);
}
// Remove Comments
XmlNodeList Comments = xDoc.SelectNodes("//comment()");
foreach (XmlNode Comment in Comments)
{
xDoc.PreserveWhitespace = false;
Comment.ParentNode.RemoveChild(Comment);
xDoc.Save(nXML);
}
Console.Write(" [SUCCESS]");
string SubFolderName = Skeleton.Substring(0, 2);
DirectoryInfo CompiledFolder = new DirectoryInfo(Path.Combine(fPath, "Compiled"));
CompiledFolder.CreateSubdirectory(SubFolderName);
if (islowLOD)
{
if (Path.GetFileNameWithoutExtension(w3xfile).ToLowerInvariant() == Skeleton.ToLowerInvariant())
{
File.Copy(Path.Combine(fPathLowLOD, $"{Skeleton}.w3x"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{Skeleton}{LODPostFix}.w3x"), true);
File.Delete(Path.Combine(fPathLowLOD, $"{Skeleton}.w3x"));
}
else
{
File.Copy(Path.Combine(fPathLowLOD, $"{Skeleton}_HRC.w3x"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{Skeleton}{LODPostFix}.w3x"), true);
File.Delete(Path.Combine(fPathLowLOD, $"{Skeleton}_HRC.w3x"));
}
}
else
{
if (Path.GetFileNameWithoutExtension(w3xfile).ToLowerInvariant() == Skeleton.ToLowerInvariant())
{
File.Copy(Path.Combine(fPath, $"{Skeleton}.w3x"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{Skeleton}.w3x"), true);
File.Delete(Path.Combine(fPath, $"{Skeleton}.w3x"));
}
else
{
File.Copy(Path.Combine(fPath, $"{Skeleton}_HRC.w3x"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{Skeleton}.w3x"), true);
File.Delete(Path.Combine(fPath, $"{Skeleton}_HRC.w3x"));
}
}
}
}
if (W3DMeshes.Count != 0)
{
Console.Write($"\nProcessing W3X Mesh: {w3xfile}");
ArrayList TexturesList = new ArrayList();
foreach (XmlNode AssetDeclaration in AssetDeclarations)
{
foreach (XmlNode W3DMesh in W3DMeshes)
{
XmlNamedNodeMap mapAttributes = W3DMesh.Attributes;
foreach (XmlNode xnodAttribute in mapAttributes)
{
if (xnodAttribute.Name == "id")
{
Mesh = xnodAttribute.Value;
}
}
}
// Remove Comments
XmlNodeList Comments = xDoc.SelectNodes("//comment()");
foreach (XmlNode Comment in Comments)
{
xDoc.PreserveWhitespace = false;
Comment.ParentNode.RemoveChild(Comment);
xDoc.Save(nXML);
}
// Include Textures
XmlNodeList Textures = xDoc.GetElementsByTagName("Texture");
foreach (XmlNode Texture in Textures)
{
string strTexture = (string)Texture.InnerText;
strTexture = strTexture.Trim();
if (!TexturesList.Contains(strTexture))
{
TexturesList.Add(strTexture);
}
}
foreach (XmlNode W3DMesh in W3DMeshes)
{
xDoc.DocumentElement.InsertBefore(newIncludes, W3DMesh);
}
foreach (string strTex in TexturesList)
{
XmlElement Include = xDoc.CreateElement("Include", "uri:ea.com:eala:asset");
Include.SetAttribute("type", "all");
string strTex2 = strTex.ToLower();
Include.SetAttribute("source", $"ART:{strTex2}.xml");
newIncludes.AppendChild(Include);
xDoc.Save(nXML);
}
Console.Write(" [SUCCESS]");
string SubFolderName = Mesh.Substring(0, 2);
DirectoryInfo CompiledFolder = new DirectoryInfo(Path.Combine(fPath, "Compiled"));
CompiledFolder.CreateSubdirectory(SubFolderName);
if (islowLOD)
{
File.Copy(Path.Combine(fPathLowLOD, $"{Mesh}.w3x"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{Mesh}{LODPostFix}.w3x"), true);
File.Delete(Path.Combine(fPathLowLOD, $"{Mesh}.w3x"));
}
else
{
File.Copy(Path.Combine(fPath, $"{Mesh}.w3x"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{Mesh}.w3x"), true);
File.Delete(Path.Combine(fPath, $"{Mesh}.w3x"));
}
}
}
}
catch (Exception e)
{
Console.Write(" [ERROR]");
EmitError("Failed with exception: {0}" + Convert.ToString(e));
}
}
}
static void movetexturefiles(string texturefile, string fPath)
{
if (File.Exists(texturefile))
{
try
{
Console.Write($"\nMoving Texture File: {texturefile}");
string texture = Path.GetFileNameWithoutExtension(texturefile);
// Packed and Individual Images are stored in the Image folder instead of SubFolder
if (!texture.StartsWith("Packed") && !texture.StartsWith("Individual"))
{
string SubFolderName = texture.Substring(0, 2);
DirectoryInfo CompiledFolder = new DirectoryInfo(Path.Combine(fPath, "Compiled"));
CompiledFolder.CreateSubdirectory(SubFolderName.ToUpperInvariant());
// Move Texture file
File.Copy(Path.Combine(fPath, $"{texture}.dds"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{texture}.dds"), true);
File.Delete(Path.Combine(fPath, $"{texture}.dds"));
// With Coresponding xml
File.Copy(Path.Combine(fPath, $"{texture}.xml"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}{SubFolderName}{Path.DirectorySeparatorChar}{texture}.xml"), true);
File.Delete(Path.Combine(fPath, $"{texture}.xml"));
}
else
{
DirectoryInfo CompiledFolder = new DirectoryInfo(Path.Combine(fPath, "Compiled"));
CompiledFolder.CreateSubdirectory("Images");
File.Copy(Path.Combine(fPath, $"{texture}.dds"), Path.Combine(fPath, $"Compiled{Path.DirectorySeparatorChar}Images{Path.DirectorySeparatorChar}{texture}.dds"), true);
File.Delete(Path.Combine(fPath, $"{texture}.dds"));
// Packed and Individual Images are included in a single xml file each
File.Delete(Path.Combine(fPath, $"{texture}.xml"));
}
}
catch (Exception e)
{
Console.Write(" [ERROR]\n");
EmitError("Failed with exception: {0}" + Convert.ToString(e));
}
}
}
static void buildskn(string fPath)
{
DirectoryInfo directory = new DirectoryInfo(fPath);
string[] w3xfiles = Directory.GetFiles(fPath, "*.w3x");
foreach (string w3xfile in w3xfiles)
{
// Medium LOD
if (Directory.Exists(Path.Combine(fPath, "MediumLOD")))
{
if (checkLOD(w3xfile, fPath, LevelOfDetail.Medium))
{
string fPathLowLOD = Path.Combine(fPath, "MediumLOD");
string fileName = Path.GetFileName(w3xfile);
buildfile(Path.Combine(fPathLowLOD, $"{fileName}"), fPath, LevelOfDetail.Medium);
}
}
// Low LOD
if (Directory.Exists(Path.Combine(fPath, "LowLOD")))
{
if (checkLOD(w3xfile, fPath, LevelOfDetail.Low))
{
string fPathLowLOD = Path.Combine(fPath, "LowLOD");
string fileName = Path.GetFileName(w3xfile);
buildfile(Path.Combine(fPathLowLOD, $"{fileName}"), fPath, LevelOfDetail.Low);
}
}
// if (!File.Exists(w3xfile))
// {
// Console.Write($"\nMissing {w3xfile}");
// }
buildfile(w3xfile, fPath, LevelOfDetail.High);
}
// Move rest into compiled folder
// Want to remove Bibbers skeleton extensions "HRC"
Console.Write("\nMove Files\n");
foreach (string w3xfile in w3xfiles)
{
movefiles(w3xfile, fPath, LevelOfDetail.High);
}
string[] texturefiles = Directory.GetFiles(fPath, "*.dds");
foreach (string texturefile in texturefiles)
{
movetexturefiles(texturefile, fPath);
}
if (Directory.Exists(Path.Combine(fPath, "MediumLOD")))
{
Console.Write("\nMove Medium LOD Files\n");
string[] w3xfiles_M = Directory.GetFiles(Path.Combine(fPath, "MediumLOD"), "*.w3x");
foreach (string w3xfile in w3xfiles_M)
{
movefiles(w3xfile, fPath, LevelOfDetail.Medium);
}
}
if (Directory.Exists(Path.Combine(fPath, "LowLOD")))
{
Console.Write("\nMove Low LOD Files\n");
string[] w3xfiles_L = Directory.GetFiles(Path.Combine(fPath, "LowLOD"), "*.w3x");
foreach (string w3xfile in w3xfiles_L)
{
movefiles(w3xfile, fPath, LevelOfDetail.Low);
}
}
}
static void Main(string[] args)
{
try
{