forked from DevilboxGames/ReincarnationTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC1Mobile_MaterialTools.ms
More file actions
174 lines (153 loc) · 4.58 KB
/
Copy pathC1Mobile_MaterialTools.ms
File metadata and controls
174 lines (153 loc) · 4.58 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
function SMEGetSelMats = (
viewNode = sme.GetView (sme.activeView)
smeSelMats = #()
for n = 1 to trackViewNodes[#sme][(sme.activeView)].numSubs do (
m = trackViewNodes[#sme][(sme.activeView)][n].reference
b = viewNode.GetNodeByRef m
if b.selected do append smeSelMats m
)
return smeSelMats
)
fn ApplyMatCA obj = (
if(classof obj.material) == multimaterial then (
)
)
fn DeleteMatCAOnSelectedMat = (
mats =SMEGetSelMats()
for mat in mats do (
if mat_ca != undefined then custattributes.delete mat mat_ca
custattributes.delete mat mtlmat_ca
)
)
fn MatIsMTL Mat = (
(isProperty mat "mat_flags") and (isProperty mat "mat_ambient") == false
)
fn MatIsC1MAT Mat = (
(isProperty mat "mat_ambient")
)
fn AddMTLtoMat mat = (
if (MatIsMTL mat) == false then (
if MatIsC1MAT mat then (
custattributes.delete mat mat_ca
)
custattributes.add mat mtlmat_ca
for i = mat.mtlmat_data.layer_name.count to 1 by -1 do (
deleteItem mat.mtlmat_data.layer_name i
deleteItem mat.mtlmat_data.layer_blend_mode i
deleteItem mat.mtlmat_data.layer_alpha_opacity i
deleteItem mat.mtlmat_data.layer_specialfx i
deleteItem mat.mtlmat_data.layer_flipbook_fps i
deleteItem mat.mtlmat_data.layer_scrollspeed_u i
deleteItem mat.mtlmat_data.layer_scrollspeed_v i
deleteItem mat.mtlmat_data.layer_mappingmode_u i
deleteItem mat.mtlmat_data.layer_mappingmode_v i
deleteItem mat.mtlmat_data.layer_uv_slot i
deleteItem mat.mtlmat_data.layer_numframes_u i
deleteItem mat.mtlmat_data.layer_numframes_v i
deleteItem mat.mtlmat_data.layer_layerflags i
)
mtl = MTLFile()
if mat != undefined and mat.diffuseMap != undefined and (classof mat.diffuseMap) == bitmaptexture then
(
bitmapFileName = mat.diffuseMap.filename
mtl.Layers[1].mapname = getFilenameFile bitmapFileName
)
mtl.AmbientRed = mat.diffuse.r / 255
mtl.AmbientGreen = mat.diffuse.g / 255
mtl.AmbientRed = mat.diffuse.b / 255
mtl.EmissiveRed = mat.ambient.r / 255
mtl.EmissiveGreen = mat.ambient.g / 255
mtl.EmissiveRed = mat.ambient.b / 255
mtl.SpecularRed = mat.Specular.r / 255
mtl.SpecularGreen = mat.Specular.g / 255
mtl.SpecularRed = mat.Specular.b / 255
mtl.SpecularPower = mat.SpecularLevel / 255
mtl.ApplyToMaterial mat
)
)
fn AddMatCAToSelectedMat deleteCA:false = (
if(deleteCA) then (
DeleteMatCAOnSelectedMat()
)
mats =SMEGetSelMats()
for mat in mats do (
AddMTLtoMat mat
)
)
fn LoadAndApplyMTL mtl_file = (
mat = (SMEGetSelMats())[1]
mtl = MTLFile()
mtl.Load mtl_file
mtl.ApplyToMaterial mat
)
fn GetAndSaveMTL mtl_file mat = (
mat = mat
mtl = MTLFile()
mtl.GetFromMaterial mat
mtl.Save mtl_file
)
fn GetAndSaveyMTL mtl_file = (
GetAndSaveMTL mtl_file (SMEGetSelMats())[1]
)
fn TestMTLShit = (
LoadAndApplyMTL "E:\Backups\CarmAndroid\WADs\Data_Android\DATA\CONTENT\TRACKS\LEVELS\CITY_A\0ROAD.MTL"
)
fn ApplyMTLToAllMatsInScene OnlyWithDiffuse:false OnlyProperlyNamed:false = (
numMats = 0
format "Addimg CA to % mats \n" sceneMaterials.count
for mat in sceneMaterials do (
if classof mat == multimaterial then (
for submat in mat.materiallist do (
if submat != undefined then (
if (OnlyWithDiffuse == false or submat.diffusemap != undefined) and (OnlyProperlyNamed == false or (matchPattern submat.name pattern:"material*#*") == false) then (
numMats = numMats + 1
AddMTLtoMat submat
)
if (mod numMats 20 )== 0 then (
format "Done % mats\n" numMats
if (MaxVersion())[1] >= 9000 do (dotnetClass "Application").doEvents()
)
)
)
)
else if classof mat == Standardmaterial then (
if (OnlyWithDiffuse == false or mat.diffusemap != undefined) and (OnlyWithProperName == false or (matchPattern mat.name pattern:"material*#*") == false) then (
numMats = numMats + 1
AddMTLtoMat mat
)
)
if (mod numMats 20 )== 0 then (
format "Done % mats\n" numMats
if (MaxVersion())[1] >= 9000 do (dotnetClass "Application").doEvents()
)
)
Format "Added MTL attribute to % mats \n" nummats
)
fn RemoveTrisWithDummyMaterials obj = (
matids = #()
if ClassOf obj.mat == multimaterial then (
for i = 1 to obj.mat.materiallist.count do (
if (custAttributes.get obj.mat.materiallist[i] mat_ca) == undefined then
(
append matids i
)
)
)
else (
if (custAttributes.get obj.material mtlmat_ca) == undefined then
(
append matids 1
)
)
format "found % mats to remove: %\n" matids.count matids
if matids.count > 0 then (
numfaces = getNumFaces obj
for i = numfaces to 1 by -1 do (
matid = getFaceMatID obj i
if (finditem matids matid) != 0 then (
deleteface obj i
)
)
)
update obj
)