-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path3dsMax AMF2.ms
1578 lines (1329 loc) · 47.3 KB
/
3dsMax AMF2.ms
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
/******************************************************************************
AMF Importer By Gravemind2401
-------------------------------------------------------------------------------
A new format built by Gravemind2401 to cater for many, many more options
when importing as well as up to 85%+ smaller filesize and better shader support
******************************************************************************/
header = 0
version = 0.0
mName = ""
inFile = ""
loaded = false
nodeInfo = #()
regionInfo = #()
shaderInfo = #()
shaderTypes = #()
boneList = #()
meshList = #()
treeNodes = #()
usedShaders = #()
mGroupInfo = #()
fn readHeader = (
header = readLong inFile
version = readFloat inFile
mName = readString inFile
)
fn readNodes = (
nodeInfo = #()
nCount = readLong inFile
nAddress = readLong inFile
fPos = ftell inFile
if nCount > 0 do (
fseek inFile nAddress #seek_set
for n = 1 to nCount do (
nName = readString inFile
parentIndex = readShort inFile
childIndex = readShort inFile
siblingIndex = readShort inFile
pos = [readFloat inFile, readFloat inFile, readFloat inFile]
rot = quat (readFloat inFile) (readFloat inFile) (readFloat inFile) (readFloat inFile)
--in case max decides to order by name
pre = ""
if n < 100 do ( pre += "0" )
if n < 010 do ( pre += "0" )
nName = (pre + (n as string) + nName)
append nodeInfo #(nName, parentIndex, childIndex, siblingIndex, pos, rot)
)
)
fseek inFile fPos #seek_set
)
fn readMarkers = (
mGroupInfo = #()
mgCount = readLong inFile
mgAddress = readLong inFile
fPos = ftell inFile
if mgCount > 0 do (
fseek inFile mgAddress #seek_set
for mg = 1 to mgCount do (
markers = #()
mgName = "#" + readString inFile
mCount = readLong inFile
mAddress = readLong inFile
cPos = ftell inFile
if mCount > 0 do (
fseek inFile mAddress #seek_set
for m = 1 to mCount do (
rIndex = readByte inFile
pIndex = readByte inFile
nIndex = readShort inFile
pos = [readFloat inFile, readFloat inFile, readFloat inFile]
rot = quat (readFloat inFile) (readFloat inFile) (readFloat inFile) (readFloat inFile)
append markers #(rIndex, pIndex, nIndex, pos, rot)
)
)
append mGroupInfo #(mgName, markers)
fseek inFile cPos #seek_set
)
)
fseek inFile fPos #seek_set
)
fn getVMatrix xbounds ybounds zbounds = (
dMat = matrix3 [1.0 / 65535.0, 0, 0] [0, 1.0 / 65535.0, 0] [0, 0, 1.0 / 65535.0] [0, 0, 0]
bMat = matrix3 [xbounds.y - xbounds.x, 0, 0] [0, ybounds.y - ybounds.x, 0] [0, 0, zbounds.y - zbounds.x] [xbounds.x, ybounds.x, zbounds.x]
--return (dMat * bMat)
return dMat
)
fn getTMatrix ubounds vbounds = (
dMat = matrix3 [1.0 / 32767.0, 0, 0] [0, 1.0 / 32767.0, 0] [0, 0, 1.0 / 32767.0] [0, 0, 0]
bMat = matrix3 [ubounds.y - ubounds.x, 0, 0] [0, vbounds.y - vbounds.x, 0] [0, 0, 0] [ubounds.x, vbounds.x, 0]
--return (dMat * bMat)
return matrix3 1
)
fn readVertices vFormat cFormat vCount = (
verts = #()
vmat = matrix3 1
tmat = matrix3 1
if vCount > 0 do (
if cFormat > 0 then (
xbounds = [readFloat inFile, readFloat inFile]
ybounds = [readFloat inFile, readFloat inFile]
zbounds = [readFloat inFile, readFloat inFile]
ubounds = [readFloat inFile, readFloat inFile]
vbounds = [readFloat inFile, readFloat inFile]
vmat = getVMatrix xbounds ybounds zbounds
tmat = getTMatrix ubounds vbounds
)
for v = 1 to vCount do (
if cFormat == 1 then (
pos = [readShort inFile, readShort inFile, readShort inFile]
norm = [0,0,0]
readLong inFile
tex = [readShort inFile, readShort inFile, 0.0] * tmat
)
else (
pos = [readFloat inFile, readFloat inFile, readFloat inFile]
norm = [readFloat inFile, readFloat inFile, readFloat inFile]
tex = [readFloat inFile, readFloat inFile, 0.0]
)
indices = #()
weights = #()
if vFormat == 1 do (
iCount = 1
i1 = (readByte inFile #unsigned) + 1
i2 = (readByte inFile #unsigned) + 1
if(i2 != 256) do (
iCount += 1
i3 = (readByte inFile #unsigned) + 1
if(i3 != 256) do (
iCount += 1
i4 = (readByte inFile #unsigned) + 1
if(i4 != 256) do (
iCount += 1
)
)
)
w1 = readFloat inFile
indices = #(i1)
weights = #(w1)
if(iCount > 1) do (
w2 = readFloat inFile
indices = #(i1, i2)
weights = #(w1, w2)
)
if(iCount > 2) do (
w3 = readFloat inFile
indices = #(i1, i2, i3)
weights = #(w1, w2, w3)
)
if(iCount > 3) do (
w4 = readFloat inFile
indices = #(i1, i2, i3, i4)
weights = #(w1, w2, w3, w4)
)
)
if vFormat == 2 do (
i1 = (readByte inFile #unsigned) + 1
indices = #(i1)
weights = #(1.0)
i2 = (readByte inFile #unsigned) + 1
if(i2 != 256) do (
indices = #(i1, i2)
weights = #(1.0, 1.0)
i3 = (readByte inFile #unsigned) + 1
if(i3 != 256) do (
indices = #(i1, i2, i3)
weights = #(1.0, 1.0, 1.0)
i4 = (readByte inFile #unsigned) + 1
if(i4 != 256) do (
indices = #(i1, i2, i3, i4)
weights = #(1.0, 1.0, 1.0, 1.0)
)
)
)
)
append verts #(pos, norm, tex, indices, weights)
)
)
return #(verts, vmat)
)
fn copyVertices vFrom cFormat = (
verts = #()
vmat = matrix3 1
tmat = matrix3 1
if vFrom.count > 0 do (
if cFormat > 0 then (
xbounds = [readFloat inFile, readFloat inFile]
ybounds = [readFloat inFile, readFloat inFile]
zbounds = [readFloat inFile, readFloat inFile]
ubounds = [readFloat inFile, readFloat inFile]
vbounds = [readFloat inFile, readFloat inFile]
vmat = getVMatrix xbounds ybounds zbounds
tmat = getTMatrix ubounds vbounds
)
)
return #(vFrom, vmat)
)
fn readFaces vLen fCount = (
faces = #()
if fCount > 0 do (
for f = 1 to fCount do (
if vLen > 65535 then (
append faces [readLong inFile + 1, readLong inFile + 1, readLong inFile + 1]
)
else (
append faces [readShort inFile #unsigned + 1, readShort inFile #unsigned + 1, readShort inFile #unsigned + 1]
)
)
)
return faces
)
fn readMeshes sCount = (
meshes = #()
if sCount > 0 do (
for s = 1 to sCount do (
shIndx = readShort inFile + 1
fStart = readLong inFile + 1
fCount = readLong inFile
append meshes #(shIndx, fStart, fCount)
)
)
return meshes
)
fn readRegions = (
regionInfo = #()
rCount = readLong inFile
rAddress = readLong inFile
fPos = ftell inFile
if rCount > 0 do (
fseek inFile rAddress #seek_set
for r = 1 to rCount do (
perms = #()
rName = readString inFile
pCount = readLong inFile
pAddress = readLong inFile
pPos = ftell inFile
if pCount > 0 do (
fseek inFile pAddress #seek_set
for p = 1 to pCount do (
pName = readString inFile
vTemp = readByte inFile
nIndex = readByte inFile #unsigned
vCount = readLong inFile
vAddress = readLong inFile
fCount = readLong inFile
fAddress = readLong inFile
sCount = readLong inFile
sAddress = readLong inFile
vFormat = bit.and vTemp 15
cFormat = bit.shift (bit.and vTemp 240) -4
trnsfm = matrix3 1
if version >= 0.1 do (
mult = readFloat inFile
if not bit.isNAN mult do (
row1 = [readFloat inFile, readFloat inFile, readFloat inFile]
row2 = [readFloat inFile, readFloat inFile, readFloat inFile]
row3 = [readFloat inFile, readFloat inFile, readFloat inFile]
row4 = [readFloat inFile, readFloat inFile, readFloat inFile]
trnsfm = matrix3 row1 row2 row3 row4
)
)
xPos = ftell inFile
vDone = false
fDone = false
verts = #()
faces = #()
--save memory, use same vertices as before if possible
for permX in perms do (
if permX[7] == vAddress and not vDone do (
verts = copyVertices permX[4] cFormat
vDone = true
)
if permX[8] == fAddress and not fDone do (
faces = permX[5]
fDone = true
)
if vDone and fDone do ( exit )
)
if not vDone do (
fseek inFile vAddress #seek_set
verts = readVertices vFormat cFormat vCount
)
if not fDone do (
fseek inFile fAddress #seek_set
faces = readFaces vCount fCount
)
fseek inFile sAddress #seek_set
meshes = readMeshes sCount
print ("verts: " + (verts[2] as string))
print ("trnsfm: " + (trnsfm as string))
append perms #(pName, vFormat, nIndex, verts[1], faces, meshes, vAddress, fAddress, mult, (verts[2] * trnsfm))
fseek inFile xPos #seek_set
)
)
append regionInfo #(rName, perms)
fseek inFile pPos #seek_set
)
)
fseek inFile fPos #seek_set
)
fn readShaders = (
shaderInfo = #()
shaderTypes = #()
sCount = readLong inFile
sAddress = readLong inFile
fPos = ftell inFile
if sCount > 0 do (
fseek inFile sAddress #seek_set
for s = 1 to sCount do (
sName = readString inFile
sType = 0
--* denotes a terrain blend shader
if sName[1] == "*" do (
sType = 1
sName = (substring sName 2 (sName.count - 1))
)
append shaderTypes sType
if sType == 0 then (
paths = #()
uvTiles = #()
tints = #()
for i = 1 to 8 do (
append paths (readString inFile)
if paths[i] != "null" then (
append uvTiles [readFloat inFile, readFloat inFile]
)
else (
append uvTiles [0.0, 0.0]
)
)
if version >= 1.1 then (
for i = 1 to 4 do (
append tints [readByte inFile #unsigned, readByte inFile #unsigned, readByte inFile #unsigned, readByte inFile #unsigned]
)
)
else (
for i = 1 to 4 do (
append tints [0, 0, 0, 0]
)
)
isTrans = (readByte inFile == 1)
ccOnly = (readByte inFile == 1)
append shaderInfo #(sName, paths, uvTiles, isTrans, ccOnly, tints)
)
else (
baseMaps = #()
bumpMaps = #()
detMaps = #()
baseTiles = #()
bumpTiles = #()
detTiles = #()
blendPath = readString inFile
if blendPath != "null" then (
blendTile = [readFloat inFile, readFloat inFile]
)
else (
blendTile = [0, 0]
)
baseCount = readByte inFile
bumpCount = readByte inFile
detCount = readByte inFile
for i = 1 to baseCount do (
append baseMaps (readString inFile)
append baseTiles [readFloat inFile, readFloat inFile]
)
for i = 1 to bumpCount do (
append bumpMaps (readString inFile)
append bumpTiles [readFloat inFile, readFloat inFile]
)
for i = 1 to detCount do (
append detMaps (readString inFile)
append detTiles [readFloat inFile, readFloat inFile]
)
append shaderInfo #(sName, blendPath, blendTile, baseMaps, baseTiles, bumpMaps, bumpTiles, detMaps, detTiles)
)
)
)
fseek inFile fPos #seek_set
)
fn loadRegions tv = (
treeNodes = #()
for reg in regionInfo do (
pNode = tv.Nodes.add reg[1]
pNode.checked = true
subNodes = #()
for perm in reg[2] do (
cNode = pNode.Nodes.add perm[1]
cNode.checked = true
append subNodes cNode
)
append treeNodes #(pNode, subNodes)
)
)
fn createBones nodeRadius boneEnable = (
boneList = #()
for b = 1 to nodeInfo.count do (
-- nodeInfo #(nName, parentIndex, childIndex, siblingIndex, pos, rot)
iNode = nodeInfo[b]
myBone = BoneSys.createBone iNode[5] [iNode[5].x + nodeRadius, iNode[5].y, iNode[5].z] [0,0,1]
myBone.name = iNode[1]
myBone.width = nodeRadius
myBone.height = nodeRadius
if iNode[3] == -1 then ( myBone.taper = 50 )
else ( myBone.taper = 70 )
mybone.setBoneEnable false 0
append boneList myBone
if iNode[2] != -1 do (
myBone.parent = boneList[iNode[2] + 1]
)
in coordsys parent myBone.rotation = iNode[6]
in coordsys parent myBone.pos = iNode[5]
)
for b = 1 to boneList.count do (
-- nodeInfo #(nName, parentIndex, childIndex, siblingIndex, pos, rot)
myBone = boneList[b]
nName = myBone.name as string
if myBone.children.count > 0 then (
for c = 1 to myBone.children.count do (
dist = distance myBone myBone.children[c]
if dist > myBone.length do ( myBone.length = dist )
)
)
else (
myBone.length = nodeRadius
)
-- if (findString nName "pelvis" != undefined) or (findString nName "spine" != undefined) then (
-- myBone.height *= 0.5
-- myBone.taper = -180
-- if myBone.children.count > 0 do ( myBone.length = distance myBone myBone.children[1] )
-- )
--
-- if (findString nName "l_thumb" != undefined) or (findString nName "r_thumb" != undefined) or
-- (findString nName "l_index" != undefined) or (findString nName "r_index" != undefined) or
-- (findString nName "l_middle" != undefined) or (findString nName "r_middle" != undefined) or
-- (findString nName "l_ring" != undefined) or (findString nName "r_ring" != undefined) or
-- (findString nName "l_pinky" != undefined) or (findString nName "r_pinky" != undefined) then (
-- myBone.height *= 0.2
-- myBone.width *= 0.2
--
-- if(myBone.children.count == 0) do ( myBone.length *= 0.3 )
-- )
--
-- if (findString nName "l_upperarm" != undefined) or (findString nName "r_upperarm" != undefined) or
-- (findString nName "l_thigh" != undefined) or (findString nName "r_thigh" != undefined) or
-- (findString nName "l_clav" != undefined) or (findString nName "r_clav" != undefined) then (
-- myBone.height *= 1.3
-- myBone.width *= 1.3
-- )
--
-- if (findString nName "l_forearm" != undefined) or (findString nName "r_forearm" != undefined) or
-- (findString nName "l_calf" != undefined) or (findString nName "r_calf" != undefined) then (
-- myBone.height *= 1.15
-- myBone.width *= 1.15
-- )
--
-- if (findString nName "l_hand" != undefined) or (findString nName "r_hand" != undefined) then (
-- myBone.height *= 0.2
-- myBone.length *= 0.75
-- myBone.taper = -75
-- )
--
-- if (findString nName "l_foot" != undefined) or (findString nName "r_foot" != undefined) then (
-- myBone.length *= 0.65
-- )
--
-- if (findString nName "l_cheek" != undefined) or (findString nName "r_cheek" != undefined) or
-- (findString nName "l_brow" != undefined) or (findString nName "r_brow" != undefined) or
-- (findString nName "l_lip" != undefined) or (findString nName "r_lip" != undefined) or
-- (findString nName "l_nose" != undefined) or (findString nName "r_nose" != undefined) or
-- (findString nName "l_hair" != undefined) or (findString nName "r_hair" != undefined) or
-- (findString nName "c_lip" != undefined) or (findString nName "c_hair" != undefined) or
-- (findString nName "l_mouth" != undefined) or (findString nName "r_mouth" != undefined) or
-- (findString nName "eye_left" != undefined) or (findString nName "eye_right" != undefined) or
-- (findString nName "l_eye" != undefined) or (findString nName "r_eye" != undefined) or
-- (findString nName "jaw" != undefined) or (findString nName "f_nose" != undefined) or
-- (findString nName "f_lip" != undefined) or (findString nName "f_thoat" != undefined) then (
-- myBone.height *= 0.2
-- myBone.width *= 0.2
-- myBone.length = nodeRadius * 0.2
-- )
--
-- if (findString nName "helper" != undefined) or (findString nName "fixup" != undefined) or
-- (findString nName "jiggle" != undefined) or (findString nName "pedestal" != undefined) or
-- (findString nName "twist" != undefined) or (findString nName "twist" != undefined) then (
-- myBone.height = nodeRadius
-- myBone.width = nodeRadius
-- myBone.length = nodeRadius
-- myBone.taper = 50
-- )
if boneEnable do (
myBone.setBoneEnable true 0
)
)
completeRedraw()
)
fn createMarkers markRadius = (
for mg = 1 to mGroupInfo.count do(
mGroup = mGroupInfo[mg][2]
for m = 1 to mGroup.count do(
marker = sphere radius:markRadius
marker.name = mGroupInfo[mg][1]
if mGroup[m][3] != -1 do (
marker.parent = boneList[mGroup[m][3] + 1]
)
in coordsys parent marker.rotation = mGroup[m][5]
in coordsys parent marker.pos = mGroup[m][4]
)
)
completeRedraw()
)
fn createMeshes mrge norm weight uv unwrap tv = (
meshList = #()
usedShaders = #()
meshDic = #()
for r = 1 to treeNodes.count do (
rNode = treeNodes[r]
if(rNode[1].checked != true) do ( continue )
rInfo = regionInfo[r]
rName = rInfo[1]
rPerms = rInfo[2]
for p = 1 to rNode[2].count do (
pNode = rNode[2][p]
if(pNode.checked != true) do ( continue )
pInfo = rPerms[p]
pName = pInfo[1]
vFormat = pInfo[2]
nIndex = pInfo[3]
-- perms #(pName, vFormat, nIndex, verts, faces, meshes, vAddress, fAddress, trnsfm)
-- meshes #(shIndx, fStart, fCount)
-- verts #(pos, norm, tex, indices, weights)
for s = 1 to pInfo[6].count do (
if s > 1 and mrge do ( continue )
sInfo = pInfo[6][s]
found = false
if version >= 0.1 do (
if not bit.isNAN pInfo[9] do (
for pair in meshDic do ( --check for an existing copy of an instance, and use that as a base
if pair[1] == pInfo[7] do (
maxOps.cloneNodes pair[2] cloneType:#instance newNodes:&newMesh
if mrge then (
newMesh.name = rName + ":" + pName
)
else (
newMesh.name = rName + ":" + pName + ":" + (s as string)
)
mult = pInfo[9]
newMesh.transform = (matrix3 [mult,0,0] [0,mult,0] [0,0,mult] [0,0,0])
newMesh.transform *= pInfo[10]
newMesh.transform *= (matrix3 [100,0,0] [0,100,0] [0,0,100] [0,0,0])
append meshList newMesh
found = true
)
)
)
)
if found do continue
vertList = #()
normList = #()
uvList = #()
faceList = #()
matList = #()
weightList = #()
indexList = #()
--fill faces first so we have the range of vert indices to use
if mrge then (
for sub in pInfo[6] do (
for f = 1 to sub[3] do ( append matList sub[1] )
appendIfUnique usedShaders sub[1]
)
faceList = pInfo[5]
)
else (
for i = 0 to (sInfo[3] - 1) do (
append matList sInfo[1]
append faceList pInfo[5][sInfo[2] + i]
)
appendIfUnique usedShaders sInfo[1]
)
if mrge then (
for v in pInfo[4] do (
append vertList v[1]
append normList v[2]
append uvList v[3]
if nIndex == 255 then (
append indexList v[4]
append weightList v[5]
)
else (
append indexList #(nIndex + 1)
append weightList #(1)
)
)
)
else ( --fill the vertList only with verts in the range of the face indices, and shift the indices to start at 1
vMin = pInfo[4].count
vMax = 1
for i = 1 to faceList.count do (
if faceList[i].x < vMin do ( vMin = faceList[i].x )
if faceList[i].y < vMin do ( vMin = faceList[i].y )
if faceList[i].z < vMin do ( vMin = faceList[i].z )
if faceList[i].x > vMax do ( vMax = faceList[i].x )
if faceList[i].y > vMax do ( vMax = faceList[i].y )
if faceList[i].z > vMax do ( vMax = faceList[i].z )
)
for i = vMin to vMax do (
append vertList pInfo[4][i][1]
append normList pInfo[4][i][2]
append uvList pInfo[4][i][3]
if nIndex == 255 then (
append indexList pInfo[4][i][4]
append weightList pInfo[4][i][5]
)
else (
append indexList #(nIndex + 1)
append weightList #(1)
)
)
for i = 1 to faceList.count do (
faceList[i] -= (vMin - 1)
)
)
if uv then (
newMesh = mesh vertices:vertList tVerts:uvList faces:faceList materialIDs:matList
buildTVFaces newMesh
for i = 1 to newMesh.numfaces do (
setTVFace newMesh i (getFace newMesh i)
)
)
else (
newMesh = mesh vertices:vertList faces:faceList
)
if mrge then (
newMesh.name = rName + ":" + pName
)
else (
newMesh.name = rName + ":" + pName + ":" + (s as string)
)
newMesh.Faces[rName] = newMesh.Faces --face group for CE region exports
if norm do (
max modify mode
normMod = Edit_Normals ()
select newMesh
addModifier newMesh normMod
normMod.selectBy = 1
normMod.SelLevel = #Vertex
normMod.Unify selection:#{1..normMod.GetNumNormals()}
normMod.MakeExplicit selection:#{1..normMod.GetNumNormals()}
for i = 1 to newMesh.numverts do (
sel = #{i}
norms = #{}
normMod.ConvertVertexSelection &sel &norms
for j in norms do (
normMod.SetNormal j normList[i]
)
)
--dont want annoying modifier with lines everywhere
collapseStack newMesh
)
if version >= 0.1 do (
if not bit.isNAN pInfo[9] do (
mult = pInfo[9]
newMesh.transform = (matrix3 [mult,0,0] [0,mult,0] [0,0,mult] [0,0,0])
newMesh.transform *= pInfo[10]
newMesh.transform *= (matrix3 [100,0,0] [0,100,0] [0,0,100] [0,0,0])
)
)
if unwrap do (
uvMod = Unwrap_UVW ()
addModifier newMesh uvMod
)
if (vFormat > 0 or nIndex != 255) and weight do
(
max modify mode
theSkin = Skin()
select newMesh
addModifier newMesh theSkin
for b in boneList do (
skinOps.addbone theSkin b 0
)
redrawViews()
for v = 1 to vertList.count do (
skinOps.ReplaceVertexWeights theSkin v indexList[v] weightList[v]
)
if vFormat == 2 or nIndex != 255 do ( theSkin.rigid_vertices = true )
)
append meshList newMesh
append meshDic #(pInfo[7], newMesh)
)
)
)
completeRedraw()
)
rollout shaderRollout "AMF Shaders" width:392 height:416
(
GroupBox grp_bitmaps "Bitmaps" pos:[8,8] width:376 height:64
label lbl_bitmaps "Bitmaps Folder:" pos:[16,32] width:104 height:16
edittext edt_bitmaps "" pos:[16,48] width:288 height:16
button btn_browse "Browse" pos:[312,48] width:64 height:16
GroupBox grp_cc "CC Options" pos:[8,80] width:120 height:120 enabled:false
checkbox chk_cc "Use CC Maps" pos:[16,102] width:104 height:16 enabled:false checked:true
checkbox chk_ccGlobal "Global Colours" pos:[16,120] width:104 height:16 enabled:false checked:true
label lbl_prim "Primary:" pos:[16,138] width:64 height:16 enabled:false
label lbl_sec "Secondary:" pos:[16,156] width:64 height:16 enabled:false
label lbl_tert "Tertiary:" pos:[16,174] width:64 height:16 enabled:false
colorPicker cp_prim "" pos:[96,139] width:25 height:18 enabled:false color:(color 255 255 255)
colorPicker cp_sec "" pos:[96,157] width:25 height:18 enabled:false color:(color 255 255 255)
colorPicker cp_tert "" pos:[96,175] width:25 height:18 enabled:false color:(color 0 0 255)
GroupBox grp_bump "Bump Options" pos:[136,80] width:120 height:120 enabled:false
checkbox chk_bump "Use Bump Maps" pos:[144,102] width:104 height:16 enabled:false checked:true
label lbl_bumpAmount "Amount:" pos:[144,120] width:56 height:16 enabled:false
label lbl_bumpMult "Multiplier:" pos:[144,138] width:56 height:16 enabled:false
spinner spn_bump1 "" pos:[208,120] width:40 height:16 enabled:false range:[0,100,100] type:#integer
spinner spn_bump2 "" pos:[208,138] width:40 height:16 enabled:false range:[0,10,1.0]
GroupBox grp_spec "Specular Options" pos:[264,80] width:120 height:120
checkbox chk_spec "Use Specular" pos:[272,102] width:104 height:16 enabled:false checked:true
checkbox chk_diffspec "Use Diffuse Spec" pos:[272,120] width:104 height:16 checked:true
label lbl_specAmount "Amount:" pos:[272,138] width:56 height:16
spinner spn_spec "" pos:[336,138] width:40 height:16 range:[0,100,50] type:#integer
checkbox chk_specTint "Specular Tint" pos:[272,156] width:104 height:16 enabled:false checked:true
label lbl_specTintAmt "Amount:" pos:[272,174] width:56 height:16 enabled:false
spinner spn_specTint "" pos:[336,174] width:40 height:16 enabled:false range:[0,100,50] type:#integer
GroupBox grp_detail "Detail Options" pos:[136,208] width:120 height:120 enabled:false
checkbox chk_detail "Use Diff Detail" pos:[144,230] width:104 height:16 enabled:false checked:true
label lbl_dOpacity "Opacity:" pos:[144,248] width:56 height:16 enabled:false
spinner spn_dOpacity "" pos:[208,248] width:40 height:16 enabled:false range:[0,100,100] type:#integer
checkbox chk_dBump "Use Bump Detail" pos:[144,266] width:104 height:16 enabled:false checked:true
label lbl_dBumpMult "Multiplier:" pos:[144,284] width:56 height:16 enabled:false
spinner spn_dBump "" pos:[208,284] width:40 height:16 enabled:false range:[0,20,5]
GroupBox grp_illum "Illum Options" pos:[8,208] width:120 height:120 enabled:false
checkbox chk_illum "Use Illum Maps" pos:[16,230] width:104 height:16 enabled:false checked:true
label lbl_illumAmount "Amount:" pos:[16,248] width:56 height:16 enabled:false
spinner spn_illum "" pos:[80,248] width:40 height:16 enabled:false range:[0,100,100] type:#integer
checkbox chk_illumTint "Illumination Tint" pos:[16,266] width:104 height:16 enabled:false checked:true
label lbl_illumTintAmt "Amount:" pos:[16,284] width:56 height:16 enabled:false
spinner spn_illumTint "" pos:[80,284] width:40 height:16 enabled:false range:[0,100,100] type:#integer
GroupBox grp_other "Other Options" pos:[264,208] width:120 height:120
label lbl_fExt "Extension:" pos:[272,230] width:56 height:16
edittext edt_fExt "" pos:[333,230] width:43 height:16
label lbl_matID "Material ID:" pos:[272,248] width:56 height:16
spinner spn_matID "" pos:[336,248] width:40 height:16 range:[1,30,1] type:#integer
checkbox chk_sel "Selective Import" pos:[272,266] width:104 height:16 checked:true
checkbox chk_opac "Use Opacity Maps" pos:[272,284] width:104 height:16 enabled:false checked:true
label lbl_albAmount "Alb Tint:" pos:[272,302] width:56 height:16 enabled:false
spinner spn_albAmount "" pos:[336,302] width:40 height:16 enabled:false range:[0,100,100] type:#integer
GroupBox grp_apply "Apply Shaders" pos:[8,336] width:376 height:72
button btn_apply "Apply" pos:[80,360] width:104 height:32
button btn_cancel "Close" pos:[208,360] width:104 height:32
on shaderRollout open do (
edt_fExt.text = ".tif"
-- [0] shaderInfo #(sName, paths, uvTiles, isTrans, ccOnly, tints)
-- [1] shaderInfo #(sName, blendPath, blendTile, baseMaps, baseTiles, bumpMaps, bumpTiles, detMaps, detTiles)
for i = 1 to shaderInfo.count do (
sh = shaderInfo[i]
if shaderTypes[i] == 1 do ( --terrain blend
if sh[6].count > 0 do ( --bumps
grp_bump.enabled = chk_bump.enabled = true
lbl_bumpAmount.enabled = lbl_bumpMult.enabled = true
spn_bump1.enabled = spn_bump2.enabled = true
)
if sh[8].count > 0 do ( --details
grp_detail.enabled = chk_detail.enabled = true
lbl_dOpacity.enabled = spn_dOpacity.enabled = true
)
continue
)
if sh[2][1] != "null" do ( --diffuse
)
if sh[2][2] != "null" do ( --diffuse detail
grp_detail.enabled = chk_detail.enabled = true
lbl_dOpacity.enabled = spn_dOpacity.enabled = true
)
if sh[2][3] != "null" do ( --colour change
grp_cc.enabled = true
chk_cc.enabled = chk_ccGlobal.enabled = true
lbl_prim.enabled = lbl_sec.enabled = lbl_tert.enabled = true
cp_prim.enabled = cp_sec.enabled = cp_tert.enabled = true
)
if sh[2][4] != "null" do ( --bump
grp_bump.enabled = chk_bump.enabled = true
lbl_bumpAmount.enabled = lbl_bumpMult.enabled = true
spn_bump1.enabled = spn_bump2.enabled = true
)
if sh[2][5] != "null" and sh[2][4] != "null" do ( --bump detail
grp_detail.enabled = chk_dBump.enabled = true
lbl_dBumpMult.enabled = spn_dBump.enabled = true
)
if sh[2][6] != "null" do ( --self illumination
grp_illum.enabled = chk_illum.enabled = true
lbl_illumAmount.enabled = spn_illum.enabled = true
if sh[6][2][4] != 0 do ( --illum tint
chk_illumTint.enabled = lbl_illumTintAmt.enabled = spn_illumTint.enabled = true
)
)
if sh[2][7] != "null" do ( --specular
chk_spec.enabled = true
)
if sh[2][8] != "null" do ( --unused
)
if sh[4] do ( --opacity flag
chk_opac.enabled = true
)
if sh[6][1][4] != 0 do ( --albedo tint
lbl_albAmount.enabled = spn_albAmount.enabled = true
)
--illum above
if sh[6][3][4] != 0 do ( --spec tint
chk_specTint.enabled = lbl_specTintAmt.enabled = spn_specTint.enabled = true
)
if sh[6][4][4] != 0 do ( --unused
)
)
)
on btn_browse pressed do (
bPath = getSavePath caption:"Select your root data folder"
if bPath != undefined do ( edt_bitmaps.text = bPath )
)
on chk_illumTint changed val do (
lbl_illumTintAmt.enabled = spn_illumTint.enabled = val
)
on chk_specTint changed val do (
lbl_specTintAmt.enabled = spn_specTint.enabled = val
)
on chk_cc changed val do (
chk_ccGlobal.enabled = val
lbl_prim.enabled = lbl_sec.enabled = lbl_tert.enabled = val
cp_prim.enabled = cp_sec.enabled = cp_tert.enabled = val
)
on chk_bump changed val do (
lbl_bumpAmount.enabled = lbl_bumpMult.enabled = val
spn_bump1.enabled = spn_bump2.enabled = val
if val then (
chk_dBump.enabled = val
lbl_dBumpMult.enabled = spn_dBump.enabled =chk_dBump.checked
)
else (
chk_dBump.enabled = lbl_dBumpMult.enabled = spn_dBump.enabled = val
)
)
on chk_spec changed val do (
if chk_diffspec.checked != true do (
lbl_specAmount.enabled = spn_spec.enabled = val
)
)
on chk_diffspec changed val do (
if chk_spec.checked != true or chk_spec.enabled != true do (
lbl_specAmount.enabled = spn_spec.enabled = val
)
)
on chk_detail changed val do (
lbl_dOpacity.enabled = spn_dOpacity.enabled = val
)
on chk_dBump changed val do (
lbl_dBumpMult.enabled = spn_dBump.enabled = val
)
on chk_illum changed val do (
lbl_illumAmount.enabled = spn_illum.enabled = val
if val then (