forked from DevilboxGames/ReincarnationTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCRHelpsFunctions.ms
More file actions
1156 lines (1017 loc) · 27.5 KB
/
Copy pathCRHelpsFunctions.ms
File metadata and controls
1156 lines (1017 loc) · 27.5 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
fn KeepMaxAlive =
(
if (MaxVersion())[1] >= 9000 do (dotnetClass "Application").doEvents()
)
fn InvLerp a b v = (
va = v - a
ba = b - a
t = va / ba
t
)
fn AddCustomModifier obj modifierName custattrib allowMultiple:false = (
accessoryModifier = obj.modifiers[modifierName]
if accessoryModifier == undefined or allowMultiple then (
max modify mode
accessoryModifier = emptyModifier()
accessoryModifier.name = modifierName
addModifier obj accessoryModifier
custattributes.add accessoryModifier custattrib baseObject:false
)
accessoryModifier
)
fn Lerp a b t = (
it = 1.0 - t
v = it * a + b * t
v
)
fn RenameDuplicateParts = (
for obj in objects do (
duplicateNames = 1
for obj2 in objects do (
if obj2.name == obj.name and obj2 != obj then (
duplicateNames = duplicateNames + 1
obj2.name = obj2.name + "_" + (duplicateNames as string)
format "duplicate name of % found: %. renaming to %_%\n" obj.name obj2.name obj2.name duplicateNames
)
)
if duplicateNames > 1 then (
obj.name = obj.name + "_1"
)
)
)
fn getFilesRecursive root pattern =
(
dir_array = GetDirectories (root+"/*")
for d in dir_array do
join dir_array (GetDirectories (d+"/*"))
my_files = #()
for f in dir_array do
join my_files (getFiles (f + pattern))
my_files
)
fn GetFolderName filepath = (
pathParts = filterstring (getFilenamePath filepath) "\\/"
pathParts[pathParts.count]
)
fn DisableProcessWindowsGhosting =
(
if classof (dotnet.GetType "DisableWindowsGhosting")!=dotNetObject do
(
local source = StringStream ("
using System.Runtime.InteropServices;
public class DisableWindowsGhosting
{
[DllImport(\"user32.dll\")]
public static extern bool DisableProcessWindowsGhosting();
}")
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.GenerateInMemory = on
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source as String)
flush source
close source
if (compilerResults.Errors.Count > 0 ) then
(
local errs = stringstream ""
for i = 0 to (compilerResults.Errors.Count-1) do
(
local err = compilerResults.Errors.Item[i]
format "Error:% Line:% Column:% %\n" err.ErrorNumber err.Line err.Column err.ErrorText to:errs
)
format "%\n" errs
undefined
)
else
(
compilerResults.CompiledAssembly.CreateInstance "DisableWindowsGhosting"
)
)
)
fn buildcarmaindicesarray m = (
indices = #()
verts=#()
t_verts=#()
vertstrings=#()
model = snapshotasmesh m
mfaces = getNumFaces model
tvcount = getnumtverts model
if tvcount != 0 then
(
for i=1 to mfaces do (--build verts list
faceverts = getFace model i
faceuvs = gettvface model i
newface = [1,1,1]
for j=1 to 3 do (
vert = getvert model faceverts[j]
uv = gettvert model faceuvs[j]
index = faceverts[j]
vertstring = (#(vert,uv) as string)
vertcheck = finditem vertstrings vertstring
if vertcheck == 0 then (
append verts vert
append t_verts uv
append indices index
append vertstrings vertstring
)
)
)
)
return indices
)
fn StopNullNodesRendering = (
for obj in objects where (classof obj.baseObject) != CarmaHelper_WheelPlaceholder and (classof obj.baseObject) != CarmaHelper_AccessoryPlaceholder and (IsObjectANullCNT obj or (classof obj.baseObject) == CarmaHelper_JointHelper) do (
obj.castShadows=false
obj.primaryVisibility=false
)
)
fn ReplaceWheelsWithTempMeshes = (
)
fn ScatterObjectsOnMesh target objects count countIsPerArea:false = (
)
fn computeConvexHull theNode maxVerts:64 pushAmt:0.0 cleanup:true = (
with redraw off (
/*local rb = MassFX_RBody()
select theNode
local cmdMode = getCommandPanelTaskMode() -- store previous mode
setCommandPanelTaskMode #modify
addModifier theNode rb
rb.meshVerticesLimit = maxVerts
rb.meshType = 4 -- 3 = capsule, 4 = convex
rb.meshInflation = pushAmt
rb.RBMeshRegenerate 1
hull = rb.RBMeshConvertToCustomMesh 1
if isValidNode hull then (
hull.name += "_Hull"
-- RBMeshCustomNodeExtract
)
if cleanup then (
deleteModifier theNode 1
setCommandPanelTaskMode cmdMode -- restore previous mode
)*/
hull = Editable_Mesh name:(theNode.name + "_hull")
hull.mesh = nvpx.CreateBoundingConvex theNode maxVerts pushAmt
hull.pivot = hull.center
hull.pos = theNode.center
hull.pivot = [0,0,0]
)
hull
)
fn SearchUniqueVerts pos vert = (
if pos < vert.pos then -1
else if pos > vert.pos then 1
0
)
fn StringIsInt str =
(
(str as integer) as string == str
)
fn StringIsFloat str =
(
rx = dotnetobject "System.Text.RegularExpressions.Regex" "^[-]?[0-9]+\.[0-9]+$"
rx.isMatch str
)
fn StringIsPoint3 str =
(
rx = dotnetobject "System.Text.RegularExpressions.Regex" "^[-]?[0-9]+\.[0-9]+[\s]*,[\s]*[-]?[0-9]+\.[0-9]+[\s]*,[\s]*[-]?[0-9]+\.[0-9]+$"
rx.isMatch str
)
fn StringAsPoint3 str =
(
rx = dotnetobject "System.Text.RegularExpressions.Regex" "^([-]?[0-9]+\.[0-9]+)[\s]*,[\s]*([-]?[0-9]+\.[0-9]+)[\s]*,[\s]*([-]?[0-9]+\.[0-9]+)$"
matches = rx.Match str
[matches.Groups.Item[1].Value as float, matches.Groups.Item[2].Value as float, matches.Groups.Item[3].Value as float]
)
fn StringAsPoint2 str =
(
rx = dotnetobject "System.Text.RegularExpressions.Regex" "^([-]?[0-9]+\.[0-9]+)[\s]*,[\s]*([-]?[0-9]+\.[0-9]+)"
matches = rx.Match str
[matches.Groups.Item[1].Value as float, matches.Groups.Item[2].Value as float]
)
fn GetBonesFromSkin skinMod =
(
boneArray = for o in objects where (refs.dependencylooptest skinMod o) collect o
for i=1 to boneArray.count do
(
if boneArray[i].parent != undefined and (finditem boneArray boneArray[i].parent) == 0 then append boneArray boneArray[i].parent
)
boneArray
)
fn GetRootBoneFromSkin skinMod =
(
boneArray = for o in objects where (refs.dependencylooptest skinMod o) collect o
rootbone = undefined
for i=1 to boneArray.count do
(
if boneArray[i].parent == undefined then rootbone = boneArray[i]
)
--return boneArray
rootbone
)
fn showProps obj doClearListener:false=
(
if doClearListener then clearListener()
format "Properties:\n"
showProperties obj
format "\nMethods:\n"
showMethods obj
format "\nEvents:\n"
showEvents obj
)
fn FindObjectByPosition pos notTheseObjs:#() onlyPointHelpers:false =
(
foundobjs = #()
for obj in objects where ((distance pos obj.position) == 0 and (finditem notTheseObjs obj)==0) do
(
if onlyPointHelpers == false or (classof obj) == pointhelper then append foundobjs obj
)
-- format "Ive FoundObjs: %\n" foundobjs
foundobj = undefined
if foundobjs.count > 0 then foundobj = foundobjs[1]
foundobj
)
fn quatdot q1 q2 =
(
q1.w*q2.w + q1.x* q2.x + q1.y*q2.y + q1.z*q2.z
)
fn ConvertFromCRSpace pos noflip:false=
(
if noflip then
[pos.x,pos.z,pos.y]
else
[-pos.x,-pos.z,pos.y]
)
fn ConvertToCRSpace pos noflip:false =
(
if noflip then
[pos.x,pos.z,pos.y]
else
[-pos.x,pos.z,-pos.y]
)
fn ConvertQuatFromCRSpace q =
(
(quat q.y -q.x q.w q.z)
)
fn ConvertQuatToCRSpace q =
(
(quat -q.y q.x q.w q.z)
)
fn ConvertQuatFromCRSpace2 q =
(
(quat -q.x q.z -q.y q.w)
)
fn ConvertQuatToCRSpace2 q =
(
(quat -q.x -q.z q.y q.w)
)
fn GetAllChildren obj &arr:#() =
(
for c in obj.children do
(
append arr c
GetAllChildren c arr:arr
)
arr
)
fn GetDescendantByName obj nodeName =
(
foundobj = undefined
if tolower(nodeName) == tolower(obj.name) then foundobj = obj
else
(
allchildren = GetAllChildren obj arr:#()
for c in allchildren do
(
if tolower(nodeName) == tolower(c.name) then foundobj = c
)
)
foundobj
)
fn getNodeByName2 nodeName =
(
foundobj = undefined
for obj in objects do
(
if (stricmp obj.name nodeName) == 0 then
(
--format "Found %\n" obj.name
foundobj = obj
)
)
--format "Didn't find object named %\n" nodeName
foundobj
)
fn getBoneByName nodeName =
(
foundobj = undefined
for obj in objects do
(
if (stricmp obj.name nodeName) == 0 and (classof obj)== BoneGeometry then
(
--format "Found %\n" obj.name
foundobj = obj
)
)
--format "Didn't find object named %\n" nodeName
foundobj
)
fn DecodeLOLFile filename =
(
decodedLOL = undefined
if ((dotnetclass "System.IO.File").exists filename) then
(
LOLDecoder = dotnetclass "LOLDecoder.LOLDecoderLib"
decodedLOL = LOLDecoder.DecodeLOLFile filename
)
decodedLOL
)
fn ReloadButton_Pressed sender arg =
(
if carma_reincarnation_dockfloater.dialogbar then cui.UnRegisterDialogBar carma_reincarnation_dockfloater
destroydialog carma_reincarnation_dockfloater
filein "ReincarnationTools.ms"
)
fn Close_Pressed sender arg =
(
if carma_reincarnation_dockfloater.dialogbar then cui.UnRegisterDialogBar carma_reincarnation_dockfloater
destroydialog carma_reincarnation_dockfloater
)
struct BatchRouteTopType (Name, SubTypes, Values)
struct BatchRouteSubType (Name, Values)
fn BatchLevelRoutesButton_Pressed sender arg =
(
global CarmaSettings
levelsPath = CarmaSettings.DataCorePath+"/Content/Levels/"
levelsList= getDirectories(levelsPath+"*")
AILinkTypes = #()
AINodeTypes = #()
TopSectionTypes = #()
for i=1 to levelsList.count do
(
if ((dotnetclass "System.IO.File").exists (levelsList[i]+"routes.txt")) then
(
splitDir = filterstring levelsList[i] "\/"
levelName = splitDir[splitDir.count]
routesText = openfile (levelsList[i]+"routes.txt") mode:"r"
lineNum=0
activeType=undefined
activeSubType = undefined
while not (eof routesText) do
(
lineNum += 1
curline = trimLeft (trimRight (readline routesText))
if curline[1] == "[" then
(
foundType = false
for topType in TopSectionTypes where (toupper topType.Name) == (toupper curLine) do
(
activeType = topType
foundType = true
)
if not foundType then
(
activeType = BatchRouteTopType Name:curLine SubTypes:#() Values:#()
append TopSectionTypes activeType
activeSubType = undefined
)
)
else if curline[1] == "<" then
(
foundType = false
for subType in activeType.SubTypes where (toupper subType.Name) == (toupper curLine) do
(
foundType = true
activeSubType = subType
)
if not foundType then
(
activeSubType = BatchRouteSubType Name:curLine Values:#()
append activeType.SubTypes activeSubType
)
)
else if activeSubType == undefined and activeType != undefined then
(
if StringIsInt curLine then appendIfUnique activeType.Values "INTEGER"
else if StringIsFloat curLine then appendIfUnique activeType.Values "FLOAT"
else if StringIsPoint3 curLine then appendIfUnique activeType.Values "POINT3"
else appendIfUnique activeType.Values curLine
)
else if activeSubType != undefined then
(
if StringIsInt curLine then appendIfUnique activeSubType.Values "INTEGER"
else if StringIsFloat curLine then appendIfUnique activeSubType.Values "FLOAT"
else if StringIsPoint3 curLine then appendIfUnique activeSubType.Values "POINT3"
else appendIfUnique activeSubType.Values curLine
)
)
)
)
for topType in TopSectionTypes do
(
format "%\n" topType.Name
if topType.SubTypes.count > 0 do format "Potential Sub Types:\n"
for subType in topType.SubTypes do
(
format "\t%\n" subType.Name
if subType.Values.count > 0 do format "\tPotential Values:\n"
for val in subType.Values do
(
format "\t\t%\n" val
)
)
if topType.Values.count > 0 do format "Potential Values:\n"
for val in topType.Values do
(
format "\t%\n" val
)
)
)
fn BatchCarSetupLOLsButton_Pressed sender arg =
(
global CarmaSettings
vehiclesPath = CarmaSettings.DataCorePath+"/Content/Vehicles/"
vehiclesList = getDirectories(vehiclesPath+"*")
funcTypes = #()
funcArgs = #()
funcArgCars = #()
for i=1 to vehiclesList.count do
(
if (dotnetclass "System.IO.File").exists (vehiclesList[i]+"setup.lol") then
(
splitDir = filterstring vehiclesList[i] "\/"
carName = splitDir[splitDir.count]
lolscript = StringStream (DecodeLOLFile (vehiclesList[i]+"setup.lol"))
lineNum = 0
while (eof lolscript) == false do
(
lineNum += 1
curline = trimLeft (trimRight (readline lolscript))
splitLine = filterstring curline "()"
--format "%\n" splitline
--format "Line %: % \n" lineNum curline
if curline=="" or splitLine[1] == undefined or splitLine[2] == undefined then continue
funcPos = finditem funcTypes (trimLeft (trimRight splitLine[1]))
if funcPos == 0 then
(
append funcTypes (trimLeft (trimRight splitLine[1]))
append funcArgs #(splitline[2])
append funcArgCars #(carName)
)
else
(
argPos = findItem funcArgs[funcPos] (trimLeft (trimRight splitline[2]))
if argPos == 0 then
(
append funcArgs[funcPos] (trimLeft (trimRight splitline[2]))
append funcArgCars[funcPos] carName
)
else
(
funcArgCars[funcPos][argPos] = funcArgCars[funcPos][argPos] + ", " + carName
)
)
)
)
)
outputtext = ""
attribText = "CarSetupLOLAttrib = attributes CarSetuLOLAttrib_Def attribID:"+(genclassid() as string)+" version:1\n(\n"
attribText += "\tparameters"
for i=1 to funcTypes.count do
(
if funcTypes[i] == undefined then continue
outputtext = outputtext+ "\nFunc #"+(i as string)+": "+funcTypes[i]+"\n"
for j=1 to 1 do -- funcArgs[i].count do
(
outputtext = outputtext + "\t Args for car(s): "+funcArgCars[i][j]+"\n\t\t"+funcArgs[i][j]+"\n"
)
)
attribText = ")\n"
format "\n\n\n%" outputtext
)
fn BatchCarStructureParseCData cdata carName &funcTypes &funcArgs &funcArgCars =
(
lineNum = 0
lolscript = StringStream cdata
while (eof lolscript) == false do
(
lineNum += 1
curline = trimLeft (trimRight (readline lolscript))
splitLine = filterstring curline "()"
--format "%\n" splitline
--format "Line %: % \n" lineNum curline
if curline=="" or (curLine[1] == "-" and curLine[2]=="-") or splitLine[1] == undefined or splitLine[2] == undefined then continue
funcPos = finditem funcTypes (trimLeft (trimRight splitLine[1]))
if funcPos == 0 then
(
append funcTypes (trimLeft (trimRight splitLine[1]))
append funcArgs #(splitline[2])
append funcArgCars #(carName)
)
else
(
argPos = findItem funcArgs[funcPos] (trimLeft (trimRight splitline[2]))
if argPos == 0 then
(
append funcArgs[funcPos] (trimLeft (trimRight splitline[2]))
append funcArgCars[funcPos] carName
)
else
(
funcArgCars[funcPos][argPos] = funcArgCars[funcPos][argPos] + ", " + carName
)
)
)
)
fn BatchCarStructuresGetCData xmlnode =
(
foundobj = ""
for i=1 to xmlnode.childnodes.count do
(
child = xmlnode.childnodes.item ( i-1)
if child.nodetype == child.nodetype.cdata then
(
foundobj = child.value
i = xmlnode.childnodes.count + 1
)
--format "childnod type: %\nchildnode data:%\n\n" child.nodetype child.value
)
foundobj
)
fn BatchCarStructuresParseNodes xmlnode carName &partTypes &partArgs &partArgCars &weldTypes &weldArgs &weldArgCars &jointTypes &jointArgs &jointArgCars =
(
CData = BatchCarStructuresGetCData xmlnode
if CData != "" then
(
if xmlnode.name == "PART" or xmlnode.name == "ROOT" then
(
BatchCarStructureParseCData CData carName &partTypes &partArgs &partArgCars
)
else if xmlnode.name == "WELD" then
(
BatchCarStructureParseCData CData carName &weldTypes &weldArgs &weldArgCars
)
else if xmlnode.name == "JOINT" then
(
BatchCarStructureParseCData CData carName &jointTypes &jointArgs &jointArgCars
)
)
for i=1 to xmlnode.childnodes.count do
(
child = xmlnode.childnodes.item ( i-1)
if child.nodetype == child.nodetype.cdata then
(
)
else
(
BatchCarStructuresParseNodes child carName &partTypes &partArgs &partArgCars &weldTypes &weldArgs &weldArgCars &jointTypes &jointArgs &jointArgCars
)
)
)
fn BatchCarStructuresButton_Pressed sender arg =
(
global CarmaSettings
vehiclesPath = CarmaSettings.DataCorePath+"/Content/Vehicles/"
vehiclesList = getDirectories(vehiclesPath+"*")
charTypes = #()
charArgs = #()
charArgCars = #()
partTypes = #()
partArgs = #()
partArgCars = #()
weldTypes = #()
weldArgs = #()
weldArgCars = #()
jointTypes = #()
jointArgs = #()
jointArgCars = #()
for i=1 to vehiclesList.count do
(
if (dotnetclass "System.IO.File").exists (vehiclesList[i]+"structure.xml") then
(
splitDir = filterstring vehiclesList[i] "\/"
carName = splitDir[splitDir.count]
structureFileName = vehiclesList[i]+"structure.xml"
dotnet.loadAssembly "system.xml"
xmlDoc=dotNetObject "system.xml.xmlDocument"
xmlDoc.load (structureFileName)
characteristicsBlock = (xmlDoc.GetElementsByTagName "CHARACTERISTICS").item 0
charCData = BatchCarStructuresGetCData characteristicsBlock
BatchCarStructureParseCData charCData carName &charTypes &charArgs &charArgCars
xmlRootNode = (xmlDoc.GetElementsByTagName "ROOT").item 0
BatchCarStructuresParseNodes xmlRootNode carName &partTypes &partArgs &partArgCars &weldTypes &weldArgs &weldArgCars &jointTypes &jointArgs &jointArgCars
)
)
outputtext = ""
attribText = "CarSetupLOLAttrib = attributes CarSetuLOLAttrib_Def attribID:"+(genclassid() as string)+" version:1\n(\n"
attribText += "\tparameters"
outputtext = outputtext + "Vehicle Characteristics:\n"
for i=1 to charTypes.count do
(
if charTypes[i] == undefined then continue
outputtext = outputtext+ "\nFunc #"+(i as string)+": "+charTypes[i]+"\t\t"+charArgs[i][1]+"\t\t"
for j=1 to charArgCars[i].count do
(
outputtext = outputtext + charArgCars[i][j]+","
)
)
outputtext = outputtext + "\n\nVehicle PART:\n"
for i=1 to partTypes.count do
(
if partTypes[i] == undefined then continue
outputtext = outputtext+ "\nFunc #"+(i as string)+": "+partTypes[i]+"\t\t"+partArgs[i][1]+"\t\t"
for j=1 to partArgCars[i].count do
(
outputtext = outputtext + partArgCars[i][j]+","
)
)
outputtext = outputtext + "\n\nVehicle WELD:\n"
for i=1 to weldTypes.count do
(
if weldTypes[i] == undefined then continue
outputtext = outputtext+ "\nFunc #"+(i as string)+": "+weldTypes[i]+"\t\t"+weldArgs[i][1]+"\t\t"
for j=1 to weldArgCars[i].count do
(
outputtext = outputtext + weldArgCars[i][j]+","
)
)
outputtext = outputtext + "n\nVehicle JOINT:\n"
for i=1 to jointTypes.count do
(
if jointTypes[i] == undefined then continue
outputtext = outputtext+ "\nFunc #"+(i as string)+": "+jointTypes[i]+"\t\t"+jointArgs[i][1]+"\t\t"
for j=1 to jointArgCars[i].count do
(
outputtext = outputtext + jointArgCars[i][j]+","
)
)
attribText = ")\n"
format "\n\n\n%" outputtext
)
/********************************************
*** ATTRIBUTE HELPERS
********************************************/
/********************************************
*** IMPORT EXPORT HELPERS
********************************************/
fn ReadQuotedString f = (
skipToString f "\""
local str = readDelimitedString f "\""
while str[str.count] == "\\" do (
str = str + "\"" + readDelimitedString f "\""
)
str
)
fn ReadNonBlankLine f = (
if not eof f then (
curline = trimRight (trimLeft (readline f))
while (curline == undefined or curline == "") and not eof f do
curline = trimRight (trimLeft (readline f))
)
curline
)
fn writestring2 f string =
(
writestring f string
fseek f -1 #seek_cur
)
fn ReadString2 f fixedLen =
(
local str = ""
for i = 1 to fixedLen do
(
str0 = ReadByte f #unsigned
if str0!=0xFD AND str0!=0xFC do str+= bit.intAsChar str0
)
str
)
fn witepaddedstring f str =
(
str_length = str.count
str_div4 = str_length / 4
str_plus1 = 0
if (mod str_length 4) > 0 do
(
str_plus1=1
)
str_added = str_div4 + str_plus1
str_padding = (str_added * 4) - str_length + 4
writelong f str_length #unsigned
writestring2 f str
for i = 1 to str_padding do
(
writebyte f 0
)
)
fn readpaddedstring f version61OrLess:false=
(
str_length = readlong f #unsigned
str_div4 = str_length / 4
str_plus1 = 0
if (mod str_length 4) > 0 do
(
str_plus1=1
)
str_added = str_div4 + str_plus1
extraPadding = 4
if version61OrLess do extraPadding=0
str_padding = (str_added * 4) - str_length + extraPadding
newString = readstring2 f str_length
for i = 1 to str_padding do
(
readbyte f
)
newString
)
fn CheckBitIsSet flags bitNum =
(
result = false
if bitNum==0 then
(
if (bit.and flags 1)==1 then result = true
)
else if (bit.and flags (bit.shift 1 bitNum))==(bit.shift 1 bitNum) then result = true
result
)
fn printFlagBits flags numBits fieldName =
(
format "% has value of % - " fieldName flags
for i = (numBits-1) to 0 by -1 do
(
if (CheckBitIsSet flags i) then format "%" 1
else format "%" 0
)
format "\n"
)
fn PrintArrayInFull arrayToPrint arrayName ignoreUndefined:false =
(
txt = "\n"+arrayName+" size: "+(arrayToPrint.count as string)+" \n contents:\n"
for i=1 to arrayToPrint.count do
(
if ignoreUndefined == false or arrayToPrint[i] != undefined do
(
txt += (i as string)+": "+(arrayToPrint[i] as string)+"\n"
)
)
format "%\n-------------\n" txt
)
fn PrintArrayInFull2 arrayToPrint arrayName ignoreUndefined:false =
(
format "\n\n% size: % \n" arrayName arrayToPrint.count
format "% contents:\n" arrayName
for i=1 to arrayToPrint.count do
(
if ignoreUndefined == false or arrayToPrint[i] != undefined do
(
format "%: %\n" i arrayToPrint[i]
)
)
format "\n-------------\n"
)
fn calcMeshBoundingBox verts =
(
local vmin = undefined
local vmax = undefined
for vert in verts do
(
if vmin == undefined then vmin = [vert.x, vert.y, vert.z]
else
(
if vmin.x > vert.x do vmin.x = vert.x
if vmin.y > vert.y do vmin.y = vert.y
if vmin.z > vert.z do vmin.z= vert.z
)
if vmax == undefined then vmax = [vert.x, vert.y, vert.z]
else
(
if vmax.x < vert.x do vmax.x = vert.x
if vmax.y < vert.y do vmax.y = vert.y
if vmax.z < vert.z do vmax.z= vert.z
)
)
vhalfDist = (length (vmax - vmin)) / 2
vcenter = vmin + ((vmax - vmin) / 2)
(mbbox vmin: vmin vmax: vmax center: vcenter halfdist: vhalfDist)
)
fn bboxHasVert bboxVerts vert =
(
result = false
for i=1 to bboxVerts.count do
(
if bboxVerts[i].x == vert.x and bboxVerts[i].y == vert.y and bboxVerts[i].z == vert.z do
(
result = true
i = bboxVerts.count + 1
)
)
result
)
fn PrintMeshScript msh =
(
m = snapshotasmesh msh
numVerts = getNumVerts m
numFaces = getNumFaces m
format "m = mesh vertices:#("
for i=1 to numVerts do
(
vert = getVert m i
spacer=""
if i > 1 do spacer=","
format "%[%, %, %]" spacer vert.x vert.y vert.z
)
format ") faces:#("
for i=1 to numFaces do
(
face = getFace m i
spacer=""
if i > 1 do spacer=","
format "%[%, %, %]" spacer face.x face.y face.z
)
format ")\n"
for i=1 to numFaces do
(
smoothingGroup = getFaceSmoothGroup m i
matID = getfacematid m i
format "setFaceSmoothGroup m % %\n" i smoothingGroup
format "setFaceMatID m % %\n" i matID
)
)
fn SplitVertexNormals =
(
oldTransform = selection[1].transform
selection[1].transform = matrix3 1
m = snapshotasmesh selection[1]
newVertsList = #()
faceNewVertInds = #()
vertNormals = #()
faceIndicesForNormals =#()
for i=1 to (getNumFaces m) do
(
verts = getFace m i
rNorms = meshop.getFaceRNormals m i
if(vertNormals[verts.x] == undefined) do
(
vertNormals[verts.x] = #()
faceIndicesForNormals[verts.x] = #()
)
if(vertNormals[verts.y] == undefined) do
(
vertNormals[verts.y] = #()
faceIndicesForNormals[verts.y] = #()
)
if(vertNormals[verts.z] == undefined) do
(
vertNormals[verts.z] = #()
faceIndicesForNormals[verts.z] = #()
)
if (finditem vertNormals[verts.x] rNorms[1])==0 then
(
append vertNormals[verts.x] rNorms[1]
faceIndicesForNormals[verts.x][vertNormals[verts.x].count] = #(i)
)
else
(
append faceIndicesForNormals[verts.x][(finditem vertNormals[verts.x] rNorms[1])] i
)
if (finditem vertNormals[verts.y] rNorms[2])==0 then
(
append vertNormals[verts.y] rNorms[2]
faceIndicesForNormals[verts.y][vertNormals[verts.y].count] = #(i)
)
else