forked from DevilboxGames/ReincarnationTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCRLights.ms
More file actions
403 lines (352 loc) · 9.51 KB
/
Copy pathCRLights.ms
File metadata and controls
403 lines (352 loc) · 9.51 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
CRLightAttribute = attributes CRLightCustomAttribute attribID:#(0x5c212ae7, 0x57b99048) version:1
(
parameters crlightparams rollout:CRLightRollout
(
UsePool type:#boolean default:false ui:chk_UsePool
IsASunLight type:#boolean default: false ui:chk_IsASun
ShadowSplitCount type:#integer default: 1 ui:spn_ShadowSplitCount
ShadowSplitDistribution type:#float default:0.5 ui:spn_ShadowSplitDistribution
ShadowDistanceMin type:#float default:0.5 ui:spn_ShadowDistanceMin
ShadowDistanceMax type:#float default:2000 ui:spn_ShadowDistanceMax
ShadowCoverageX type:#float default:1 ui:spn_ShadowCoverageX
ShadowCoverageY type:#float default:1 ui:spn_ShadowCoverageY
UseEdgeColour type:#boolean default:false ui:chk_UseEdgeColour
EdgeColour type:#color default:(color 0 0 0 255) ui:colpck_EdgeColour
)
rollout CRLightRollout "CR Light Properties"
(
checkbox chk_UsePool "Use Pool"
checkbox chk_IsASun "Is A Sun (possibly?)"
group "Shadows"
(
spinner spn_ShadowSplitCount "Split Count" type:#integer range:[0,4,1]
spinner spn_ShadowSplitDistribution "Split Distribution" type:#float range:[0,1,0.5]
spinner spn_ShadowDistanceMin "Min Distance" type:#float range:[0,4000,0.1]
spinner spn_ShadowDistanceMax "Max Distance" type:#float range:[0,4000,2000]
spinner spn_ShadowCoverageX "Coverage X" type:#float range:[0,100,1]
spinner spn_ShadowCoverageY "Coverage Y" type:#float range:[0,100,1]
)
group "Edge Colour"
(
checkbox chk_UseEdgeColour "Use Edge Colour"
colorpicker colpck_EdgeColour "Colour" alpha:true title:"Light Edge Colour"
)
)
)
fn IsCRLight obj =
(
(custAttributes.get obj CRLightAttribute) != undefined
)
fn AddAttributesToLight obj =
(
if (IsCRLight obj) == false then custattributes.add obj CRLightAttribute
)
struct CRLight
(
Name,
FolderName,
LightType, -- 0 = Point, 1 = Directional, 2 = Spot
ColourR,
ColourG,
ColourB,
Intensity,
Range,
Inner,
Outer,
NearClip,
Flags,
ShadowResX,
ShadowResY,
ShadowCoverageX,
ShadowCoverageY,
ShadowBias,
ShadowIntensity,
SplitCount,
SplitDistribution,
ShadowDistanceMin,
ShadowDistanceMax,
UseEdgeColour,
EdgeColourR,
EdgeColourG,
EdgeColourB,
EdgeColourA,
GoboScaleX,
GoboScaleY,
GoboOffsetX,
GoboOffsetY,
GoboTexture,
FlagCastShadow,
FlagUsesGobo,
FlagUnknown8,
FlagUsePool,
fn SplitFlags =
(
FlagCastShadow = CheckBitIsSet Flags 0
FlagUsesGobo = CheckBitIsSet Flags 2
FlagUnknown8 = CheckBitIsSet Flags 3
FlagUsePool = CheckBitIsSet Flags 8
),
fn SetFlags =
(
Flags = 0
if FlagCastShadow then Flags = Flags + 0x1
if FlagUsesGobo then Flags = Flags + 0x4
if FlagUnknown8 then Flags = Flags + 0x8
if FlagUsePool then Flags = Flags + 0x100
),
fn LoadLight fileName =
(
f = fopen fileName "r"
result = false
FolderName = getFilenamePath filename
Name = getFilenameFile filename
header = readlong f
if header != 3 then
(
fclose f
format "% isn't a valid LIGHT file!\n" fileName
)
else
(
LightType = readlong f #unsigned
ColourR = readfloat f
ColourG = readfloat f
ColourB = readfloat f
Intensity = readfloat f
Range = readfloat f
Inner = readfloat f
Outer = readfloat f
NearClip = readfloat f
Flags = readlong f #unsigned
ShadowResX = readlong f
ShadowResY = readlong f
ShadowCoverageX = readfloat f
ShadowCoverageY = readfloat f
ShadowBias = readfloat f
ShadowIntensity = readfloat f
SplitCount = readlong f #unsigned
SplitDistribution = readfloat f
ShadowDistanceMin = readfloat f
ShadowDistanceMax = readfloat f
UseEdgeColour = readlong f #unsigned
EdgeColourR = readbyte f
EdgeColourG = readbyte f
EdgeColourB = readbyte f
EdgeColourA = readbyte f
GoboScaleX = readfloat f
GoboScaleY = readfloat f
GoboOffsetX = readfloat f
GoboOffsetY = readfloat f
--nameLength = readlong f #unsigned
GoboTexture = readpaddedstring f
fclose f
SplitFlags()
result = true
)
result
),
fn SaveLight fileName =
(
f = fopen filename "w"
SetFlags()
writelong f 3
writelong f LightType
writefloat f ColourR
writefloat f ColourG
writefloat f ColourB
writefloat f Intensity
writefloat f Range
writefloat f Inner
writefloat f Outer
writefloat f NearClip
writelong f Flags
writelong f ShadowResX
writelong f ShadowResY
writefloat f ShadowCoverageX
writefloat f ShadowCoverageY
writefloat f ShadowBias
writefloat f ShadowIntensity
writelong f SplitCount
writefloat f SplitDistribution
writefloat f ShadowDistanceMin
writefloat f ShadowDistanceMax
writelong f UseEdgeColour
writebyte f EdgeColourR
writebyte f EdgeColourG
writebyte f EdgeColourB
writebyte f EdgeColourA
writefloat f GoboScaleX
writefloat f GoboScaleY
writefloat f GoboOffsetX
writefloat f GoboOffsetY
--writelong f GoboTexture.count
witepaddedstring f GoboTexture
fclose f
),
fn SetToLight obj =
(
if (IsCRLight obj) == false
then AddAttributesToLight obj
if LightType == 0 then
obj.type = #omni
else if LightType == 1 then
obj.type = #freeDirect
else if LightType == 2 then
obj.type = #freeSpot
obj.rgb = color (ColourR * 255) (ColourG * 255) (ColourB * 255) 255
obj.multiplier = Intensity
obj.useNearAtten = true
obj.showNearAtten = true
obj.nearAttenStart = NearClip
obj.nearAttenEnd = NearClip
obj.useFarAtten = true
obj.showFarAtten = true
obj.farAttenStart = Range
obj.farAttenEnd = Range
if obj.type== #freespot then
(
obj.hotspot = Inner
obj.falloff = Outer
)
if FlagCastShadow then
(
obj.castShadows = true
obj.shadowGenerator = shadowMap()
if ShadowResX > ShadowResY then
obj.shadowGenerator.mapsize = ShadowResX
else
obj.shadowGenerator.mapsize = ShadowResY
obj.shadowGenerator.mapbias = ShadowBias
obj.shadowmultiplier = ShadowIntensity
obj.CRLightCustomAttribute.ShadowSplitCount = SplitCount
obj.CRLightCustomAttribute.ShadowSplitDistribution = SplitDistribution
obj.CRLightCustomAttribute.ShadowDistanceMin = ShadowDistanceMin
obj.CRLightCustomAttribute.ShadowDistanceMax = ShadowDistanceMin
obj.CRLightCustomAttribute.ShadowCoverageX = ShadowCoverageX
obj.CRLightCustomAttribute.ShadowCoverageY = ShadowCoverageY
)
else
(
obj.castShadows = false
)
obj.CRLightCustomAttribute.UseEdgeColour = UseEdgeColour == 1
obj.CRLightCustomAttribute.EdgeColour = color EdgeColourR EdgeColourG EdgeColourB EdgeColourA
if FlagUsesGobo then
(
obj.projector = true
obj.projectormap = LoadCRTexture FolderName GoboTexture
format "%\n" obj.projectormap
obj.projectormap.coords.U_Tiling = GoboScaleX
obj.projectormap.coords.V_Tiling = GoboScaleY
obj.projectormap.coords.U_Offset = GoboOffsetX
obj.projectormap.coords.V_Offset = GoboOffsetY
)
else
(
obj.projector = false
)
obj.CRLightCustomAttribute.UsePool = FlagUsePool
obj.CRLightCustomAttribute.IsASunLight = FlagUnknown8
),
fn SetFromLight obj =
(
if obj.type == #freeDirect then
LightType = 1
else if obj.type == #freeSpot then
LightType = 2
else
LightType = 0
ColourR = obj.rgb.r / 255
ColourG = obj.rgb.g / 255
ColourB = obj.rgb.b / 255
Intensity = obj.multiplier
NearClip = obj.nearAttenEnd
Range = obj.farAttenEnd
if LightType == 0 then
(
Inner = 22.5
Outer = 45
)
else
(
Inner = obj.hotspot
Outer = obj.falloff
)
if obj.castShadows then
(
FlagCastShadow = true
ShadowResX = obj.shadowGenerator.mapsize
ShadowResY = obj.shadowGenerator.mapsize
ShadowBias = obj.shadowGenerator.mapbias
ShadowIntensity = obj.shadowMultiplier
SplitCount = obj.CRLightCustomAttribute.ShadowSplitCount
SplitDistribution = obj.CRLightCustomAttribute.ShadowSplitDistribution
ShadowDistanceMin = obj.CRLightCustomAttribute.ShadowDistanceMin
ShadowDistanceMax = obj.CRLightCustomAttribute.ShadowDistanceMax
ShadowCoverageX = obj.CRLightCustomAttribute.ShadowCoverageX
ShadowCoverageY = obj.CRLightCustomAttribute.ShadowCoverageY
)
else
(
FlagCastShadow = false
ShadowResX = 0
ShadowResY = 0
ShadowBias = 0
ShadowIntensity = 1
ShadowCoverageX = 1
ShadowCoverageY = 1
SplitCount = 0
SplitDistribution = 0
ShadowDistanceMin = 0
ShadowDistanceMax = 0
)
if obj.CRLightCustomAttribute.UseEdgeColour then
(
UseEdgeColour = 1
EdgeColourR = obj.CRLightCustomAttribute.EdgeColour.r
EdgeColourG = obj.CRLightCustomAttribute.EdgeColour.g
EdgeColourB = obj.CRLightCustomAttribute.EdgeColour.b
EdgeColourA = obj.CRLightCustomAttribute.EdgeColour.a
)
else
(
UseEdgeColour = 0
EdgeColourR = 0
EdgeColourG = 0
EdgeColourB = 0
EdgeColourA = 255
)
if obj.projector then
(
FlagUsesGobo = true
GoboTexture = getFilenameFile obj.projectormap.filename
GoboScaleX = obj.projectormap.coords.U_Tiling
GoboScaleY = obj.projectormap.coords.V_Tiling
GoboOffsetX = obj.projectormap.coords.U_Offset
GoboOffsetV = obj.projectormap.coords.V_Offset
if GoboScaleX == undefined then GoboScaleX = 1
if GoboScaleY == undefined then GoboScaleY = 1
if GoboOffsetX == undefined then GoboOffsetX =0
if GoboOffsetY == undefined then GoboOffsetY = 0
)
else
(
FlagUsesGobo = false
GoboTexture = ""
GoboScaleX = 1
GoboScaleY = 1
GoboOffsetX = 0
GoboOffsetY = 0
)
FlagUsePool = obj.CRLightCustomAttribute.UsePool
FlagUnknown8 = obj.CRLightCustomAttribute.IsASunLight
)
)
fn ConverToCRLightButton_Pressed sender arg =
(
for obj in selection do
(
if classof obj == freeSpot or classof obj == omnilight or classof obj == Directionallight then
AddAttributesToLight obj
)
)