@zephyr3d/scene 0.9.16 → 0.9.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/scene/light.js +156 -154
- package/dist/scene/light.js.map +1 -1
- package/dist/shaders/shadow.js +116 -3
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shadow/pcss.js +2 -1
- package/dist/shadow/pcss.js.map +1 -1
- package/dist/shadow/shadowmapper.js +97 -97
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +20 -0
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/package.json +1 -1
package/dist/scene/light.js
CHANGED
|
@@ -4,9 +4,9 @@ import { BoundingBox } from '../utility/bounding_volume.js';
|
|
|
4
4
|
import { ShadowMapper } from '../shadow/shadowmapper.js';
|
|
5
5
|
import { LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT, LIGHT_TYPE_RECT } from '../values.js';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Base class for any kind of light node
|
|
9
|
-
* @public
|
|
7
|
+
/**
|
|
8
|
+
* Base class for any kind of light node
|
|
9
|
+
* @public
|
|
10
10
|
*/ class BaseLight extends GraphNode {
|
|
11
11
|
/** @internal */ _type;
|
|
12
12
|
/** @internal */ _intensity;
|
|
@@ -14,10 +14,10 @@ import { LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT, LIGHT_TYPE_R
|
|
|
14
14
|
/** @internal */ _directionCutoff;
|
|
15
15
|
/** @internal */ _diffuseIntensity;
|
|
16
16
|
/** @internal */ _extraParams;
|
|
17
|
-
/**
|
|
18
|
-
* Creates a light node
|
|
19
|
-
* @param scene - The scene to which the light node belongs
|
|
20
|
-
* @param type - Type of the light node
|
|
17
|
+
/**
|
|
18
|
+
* Creates a light node
|
|
19
|
+
* @param scene - The scene to which the light node belongs
|
|
20
|
+
* @param type - Type of the light node
|
|
21
21
|
*/ constructor(scene, type){
|
|
22
22
|
super(scene);
|
|
23
23
|
this._intensity = 1;
|
|
@@ -36,66 +36,66 @@ import { LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT, LIGHT_TYPE_R
|
|
|
36
36
|
set intensity(val) {
|
|
37
37
|
this.setIntensity(val);
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Position and range of the light
|
|
41
|
-
*
|
|
42
|
-
* @remarks
|
|
43
|
-
* Gets the position in world space of the light.
|
|
44
|
-
* Light range is encoded into the W component.
|
|
39
|
+
/**
|
|
40
|
+
* Position and range of the light
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* Gets the position in world space of the light.
|
|
44
|
+
* Light range is encoded into the W component.
|
|
45
45
|
*/ get positionAndRange() {
|
|
46
46
|
if (!this._positionRange) {
|
|
47
47
|
this.computeUniforms();
|
|
48
48
|
}
|
|
49
49
|
return this._positionRange;
|
|
50
50
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Direction and cutoff of the light
|
|
53
|
-
*
|
|
54
|
-
* @remarks
|
|
55
|
-
* Gets the direction in world space of the light
|
|
56
|
-
* Light cutoff (for spot light only) is encoded into the W component.
|
|
51
|
+
/**
|
|
52
|
+
* Direction and cutoff of the light
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* Gets the direction in world space of the light
|
|
56
|
+
* Light cutoff (for spot light only) is encoded into the W component.
|
|
57
57
|
*/ get directionAndCutoff() {
|
|
58
58
|
if (!this._directionCutoff) {
|
|
59
59
|
this.computeUniforms();
|
|
60
60
|
}
|
|
61
61
|
return this._directionCutoff;
|
|
62
62
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Color and intensity of the light
|
|
65
|
-
*
|
|
66
|
-
* @remarks
|
|
67
|
-
* Gets the color of the light.
|
|
68
|
-
* Light intensity is encoded into the W component.
|
|
63
|
+
/**
|
|
64
|
+
* Color and intensity of the light
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Gets the color of the light.
|
|
68
|
+
* Light intensity is encoded into the W component.
|
|
69
69
|
*/ get diffuseAndIntensity() {
|
|
70
70
|
if (!this._diffuseIntensity) {
|
|
71
71
|
this.computeUniforms();
|
|
72
72
|
}
|
|
73
73
|
return this._diffuseIntensity;
|
|
74
74
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Extra parameters of the light
|
|
77
|
-
*
|
|
78
|
-
* @remarks
|
|
79
|
-
* Custom data for advanced light types.
|
|
75
|
+
/**
|
|
76
|
+
* Extra parameters of the light
|
|
77
|
+
*
|
|
78
|
+
* @remarks
|
|
79
|
+
* Custom data for advanced light types.
|
|
80
80
|
*/ get extraParams() {
|
|
81
81
|
if (!this._extraParams) {
|
|
82
82
|
this.computeUniforms();
|
|
83
83
|
}
|
|
84
84
|
return this._extraParams;
|
|
85
85
|
}
|
|
86
|
-
/**
|
|
87
|
-
* View matrix of the light
|
|
88
|
-
*
|
|
89
|
-
* @remarks
|
|
90
|
-
* The view matrix of the light is used to transform a point
|
|
91
|
-
* from the world space to the light space.
|
|
86
|
+
/**
|
|
87
|
+
* View matrix of the light
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* The view matrix of the light is used to transform a point
|
|
91
|
+
* from the world space to the light space.
|
|
92
92
|
*/ get viewMatrix() {
|
|
93
93
|
return this.invWorldMatrix;
|
|
94
94
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Sets the intensity of the light
|
|
97
|
-
* @param val - Intensity of the light
|
|
98
|
-
* @returns self
|
|
95
|
+
/**
|
|
96
|
+
* Sets the intensity of the light
|
|
97
|
+
* @param val - Intensity of the light
|
|
98
|
+
* @returns self
|
|
99
99
|
*/ setIntensity(val) {
|
|
100
100
|
if (this._intensity !== val) {
|
|
101
101
|
this._intensity = val;
|
|
@@ -128,26 +128,26 @@ import { LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT, LIGHT_TYPE_R
|
|
|
128
128
|
return false;
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
/*
|
|
132
|
-
export abstract class AmbientLight extends BaseLight {
|
|
133
|
-
constructor(scene: Scene, type: number) {
|
|
134
|
-
super(scene, type);
|
|
135
|
-
}
|
|
136
|
-
isAmbientLight(): this is AmbientLight {
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
*/ /**
|
|
141
|
-
* Base class for any kind of puncual light
|
|
142
|
-
* @public
|
|
131
|
+
/*
|
|
132
|
+
export abstract class AmbientLight extends BaseLight {
|
|
133
|
+
constructor(scene: Scene, type: number) {
|
|
134
|
+
super(scene, type);
|
|
135
|
+
}
|
|
136
|
+
isAmbientLight(): this is AmbientLight {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
*/ /**
|
|
141
|
+
* Base class for any kind of puncual light
|
|
142
|
+
* @public
|
|
143
143
|
*/ class PunctualLight extends BaseLight {
|
|
144
144
|
/** @internal */ _color;
|
|
145
145
|
/** @internal */ _castShadow;
|
|
146
146
|
/** @internal */ _shadowMapper;
|
|
147
|
-
/**
|
|
148
|
-
* Creates an instance of punctual light
|
|
149
|
-
* @param scene - The scene to which the punctual light belongs
|
|
150
|
-
* @param type - The light type
|
|
147
|
+
/**
|
|
148
|
+
* Creates an instance of punctual light
|
|
149
|
+
* @param scene - The scene to which the punctual light belongs
|
|
150
|
+
* @param type - The light type
|
|
151
151
|
*/ constructor(scene, type){
|
|
152
152
|
super(scene, type);
|
|
153
153
|
this.ensurePunctualState();
|
|
@@ -170,10 +170,10 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
170
170
|
set color(color) {
|
|
171
171
|
this.setColor(color);
|
|
172
172
|
}
|
|
173
|
-
/**
|
|
174
|
-
* Sets color of the light
|
|
175
|
-
* @param color - The color to set
|
|
176
|
-
* @returns self
|
|
173
|
+
/**
|
|
174
|
+
* Sets color of the light
|
|
175
|
+
* @param color - The color to set
|
|
176
|
+
* @returns self
|
|
177
177
|
*/ setColor(color) {
|
|
178
178
|
this.ensurePunctualState();
|
|
179
179
|
this._color.set(color);
|
|
@@ -187,10 +187,10 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
187
187
|
set castShadow(b) {
|
|
188
188
|
this.setCastShadow(b);
|
|
189
189
|
}
|
|
190
|
-
/**
|
|
191
|
-
* Sets whether this light casts shadows
|
|
192
|
-
* @param b - true if the light casts shadows
|
|
193
|
-
* @returns self
|
|
190
|
+
/**
|
|
191
|
+
* Sets whether this light casts shadows
|
|
192
|
+
* @param b - true if the light casts shadows
|
|
193
|
+
* @returns self
|
|
194
194
|
*/ setCastShadow(b) {
|
|
195
195
|
this.ensurePunctualState();
|
|
196
196
|
if (this._castShadow !== !!b) {
|
|
@@ -205,9 +205,9 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
205
205
|
this.ensurePunctualState();
|
|
206
206
|
return this._shadowMapper;
|
|
207
207
|
}
|
|
208
|
-
/**
|
|
209
|
-
* {@inheritDoc BaseLight.isPunctualLight}
|
|
210
|
-
* @override
|
|
208
|
+
/**
|
|
209
|
+
* {@inheritDoc BaseLight.isPunctualLight}
|
|
210
|
+
* @override
|
|
211
211
|
*/ isPunctualLight() {
|
|
212
212
|
return true;
|
|
213
213
|
}
|
|
@@ -222,14 +222,14 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
222
222
|
}
|
|
223
223
|
/** @internal */ computeUniforms() {}
|
|
224
224
|
}
|
|
225
|
-
/**
|
|
226
|
-
* Directional light
|
|
227
|
-
* @public
|
|
225
|
+
/**
|
|
226
|
+
* Directional light
|
|
227
|
+
* @public
|
|
228
228
|
*/ class DirectionalLight extends PunctualLight {
|
|
229
229
|
static _currentSunLight = new WeakMap();
|
|
230
|
-
/**
|
|
231
|
-
* Creates an instance of directional light
|
|
232
|
-
* @param scene - The scene to which the light belongs
|
|
230
|
+
/**
|
|
231
|
+
* Creates an instance of directional light
|
|
232
|
+
* @param scene - The scene to which the light belongs
|
|
233
233
|
*/ constructor(scene){
|
|
234
234
|
super(scene, LIGHT_TYPE_DIRECTIONAL);
|
|
235
235
|
this.intensity = 10;
|
|
@@ -251,11 +251,11 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
251
251
|
ref.set(light);
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
|
-
/**
|
|
255
|
-
* true if the light was defined as sun light
|
|
256
|
-
*
|
|
257
|
-
* @remarks
|
|
258
|
-
* Only one directional light will be marked as sun light.
|
|
254
|
+
/**
|
|
255
|
+
* true if the light was defined as sun light
|
|
256
|
+
*
|
|
257
|
+
* @remarks
|
|
258
|
+
* Only one directional light will be marked as sun light.
|
|
259
259
|
**/ get sunLight() {
|
|
260
260
|
return DirectionalLight.getSunLight(this.scene) === this;
|
|
261
261
|
}
|
|
@@ -266,9 +266,9 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
266
266
|
DirectionalLight.setSunLight(this.scene, null);
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
|
-
/**
|
|
270
|
-
* {@inheritDoc BaseLight.isDirectionLight}
|
|
271
|
-
* @override
|
|
269
|
+
/**
|
|
270
|
+
* {@inheritDoc BaseLight.isDirectionLight}
|
|
271
|
+
* @override
|
|
272
272
|
*/ isDirectionLight() {
|
|
273
273
|
return true;
|
|
274
274
|
}
|
|
@@ -284,20 +284,20 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
284
284
|
this._extraParams = new Vector4(0, 0, 0, this.lightType);
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
|
-
/**
|
|
288
|
-
* Point light
|
|
289
|
-
* @public
|
|
287
|
+
/**
|
|
288
|
+
* Point light
|
|
289
|
+
* @public
|
|
290
290
|
*/ class PointLight extends PunctualLight {
|
|
291
291
|
/** @internal */ _range;
|
|
292
292
|
/** @internal */ _diffuseScale;
|
|
293
293
|
/** @internal */ _specularScale;
|
|
294
294
|
/** @internal */ _sourceRadius;
|
|
295
|
-
/**
|
|
296
|
-
* Creates an instance of point light
|
|
297
|
-
* @param scene - The scene to which the light belongs
|
|
295
|
+
/**
|
|
296
|
+
* Creates an instance of point light
|
|
297
|
+
* @param scene - The scene to which the light belongs
|
|
298
298
|
*/ constructor(scene){
|
|
299
299
|
super(scene, LIGHT_TYPE_POINT);
|
|
300
|
-
this._range =
|
|
300
|
+
this._range = 0;
|
|
301
301
|
this._diffuseScale = 1;
|
|
302
302
|
this._specularScale = 1;
|
|
303
303
|
this._sourceRadius = 0;
|
|
@@ -327,10 +327,10 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
327
327
|
set sourceRadius(val) {
|
|
328
328
|
this.setSourceRadius(val);
|
|
329
329
|
}
|
|
330
|
-
/**
|
|
331
|
-
* Sets the range of the light
|
|
332
|
-
* @param val - The value to set
|
|
333
|
-
* @returns self
|
|
330
|
+
/**
|
|
331
|
+
* Sets the range of the light
|
|
332
|
+
* @param val - The value to set
|
|
333
|
+
* @returns self
|
|
334
334
|
*/ setRange(val) {
|
|
335
335
|
val = val < 0 ? 0 : val;
|
|
336
336
|
if (this._range !== val) {
|
|
@@ -340,10 +340,10 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
340
340
|
}
|
|
341
341
|
return this;
|
|
342
342
|
}
|
|
343
|
-
/**
|
|
344
|
-
* Sets the diffuse scale of the light
|
|
345
|
-
* @param val - The value to set
|
|
346
|
-
* @returns self
|
|
343
|
+
/**
|
|
344
|
+
* Sets the diffuse scale of the light
|
|
345
|
+
* @param val - The value to set
|
|
346
|
+
* @returns self
|
|
347
347
|
*/ setDiffuseScale(val) {
|
|
348
348
|
val = val < 0 ? 0 : val;
|
|
349
349
|
if (this._diffuseScale !== val) {
|
|
@@ -352,10 +352,10 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
352
352
|
}
|
|
353
353
|
return this;
|
|
354
354
|
}
|
|
355
|
-
/**
|
|
356
|
-
* Sets the specular scale of the light
|
|
357
|
-
* @param val - The value to set
|
|
358
|
-
* @returns self
|
|
355
|
+
/**
|
|
356
|
+
* Sets the specular scale of the light
|
|
357
|
+
* @param val - The value to set
|
|
358
|
+
* @returns self
|
|
359
359
|
*/ setSpecularScale(val) {
|
|
360
360
|
val = val < 0 ? 0 : val;
|
|
361
361
|
if (this._specularScale !== val) {
|
|
@@ -364,10 +364,10 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
364
364
|
}
|
|
365
365
|
return this;
|
|
366
366
|
}
|
|
367
|
-
/**
|
|
368
|
-
* Sets the source radius of the light
|
|
369
|
-
* @param val - The value to set
|
|
370
|
-
* @returns self
|
|
367
|
+
/**
|
|
368
|
+
* Sets the source radius of the light
|
|
369
|
+
* @param val - The value to set
|
|
370
|
+
* @returns self
|
|
371
371
|
*/ setSourceRadius(val) {
|
|
372
372
|
val = val < 0 ? 0 : val;
|
|
373
373
|
if (this._sourceRadius !== val) {
|
|
@@ -376,40 +376,41 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
376
376
|
}
|
|
377
377
|
return this;
|
|
378
378
|
}
|
|
379
|
-
/**
|
|
380
|
-
* {@inheritDoc BaseLight.isPointLight}
|
|
381
|
-
* @override
|
|
379
|
+
/**
|
|
380
|
+
* {@inheritDoc BaseLight.isPointLight}
|
|
381
|
+
* @override
|
|
382
382
|
*/ isPointLight() {
|
|
383
383
|
return true;
|
|
384
384
|
}
|
|
385
385
|
/** @internal */ computeBoundingVolume() {
|
|
386
|
+
const range = this.positionAndRange.w;
|
|
386
387
|
const bbox = new BoundingBox();
|
|
387
|
-
bbox.minPoint = new Vector3(-
|
|
388
|
-
bbox.maxPoint = new Vector3(
|
|
388
|
+
bbox.minPoint = new Vector3(-range, -range, -range);
|
|
389
|
+
bbox.maxPoint = new Vector3(range, range, range);
|
|
389
390
|
return bbox;
|
|
390
391
|
}
|
|
391
392
|
/** @internal */ computeUniforms() {
|
|
392
393
|
const a = this.worldMatrix.getRow(3);
|
|
393
394
|
const b = this.worldMatrix.getRow(2);
|
|
394
|
-
const range = this.range
|
|
395
|
+
const range = this.range <= 0 ? 32 * Math.sqrt(Math.max(0.0001, this.intensity * Math.max(this._diffuseScale, this._specularScale))) : this.range;
|
|
395
396
|
this._positionRange = new Vector4(a.x, a.y, a.z, range);
|
|
396
397
|
this._directionCutoff = new Vector4(b.x, b.y, b.z, -1);
|
|
397
398
|
this._diffuseIntensity = new Vector4(this.color.x, this.color.y, this.color.z, this.intensity);
|
|
398
399
|
this._extraParams = new Vector4(this._diffuseScale, this._specularScale, this._sourceRadius, this.lightType);
|
|
399
400
|
}
|
|
400
401
|
}
|
|
401
|
-
/**
|
|
402
|
-
* Spot light
|
|
403
|
-
* @public
|
|
402
|
+
/**
|
|
403
|
+
* Spot light
|
|
404
|
+
* @public
|
|
404
405
|
*/ class SpotLight extends PunctualLight {
|
|
405
406
|
/** @internal */ _range;
|
|
406
407
|
/** @internal */ _cutoff;
|
|
407
|
-
/**
|
|
408
|
-
* Creates an instance of spot light
|
|
409
|
-
* @param scene - The scene to which the light belongs
|
|
408
|
+
/**
|
|
409
|
+
* Creates an instance of spot light
|
|
410
|
+
* @param scene - The scene to which the light belongs
|
|
410
411
|
*/ constructor(scene){
|
|
411
412
|
super(scene, LIGHT_TYPE_SPOT);
|
|
412
|
-
this._range =
|
|
413
|
+
this._range = 0;
|
|
413
414
|
this._cutoff = Math.cos(Math.PI / 4);
|
|
414
415
|
this.invalidateBoundingVolume();
|
|
415
416
|
}
|
|
@@ -419,10 +420,10 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
419
420
|
set range(val) {
|
|
420
421
|
this.setRange(val);
|
|
421
422
|
}
|
|
422
|
-
/**
|
|
423
|
-
* Sets the range of the light
|
|
424
|
-
* @param val - The value to set
|
|
425
|
-
* @returns self
|
|
423
|
+
/**
|
|
424
|
+
* Sets the range of the light
|
|
425
|
+
* @param val - The value to set
|
|
426
|
+
* @returns self
|
|
426
427
|
*/ setRange(val) {
|
|
427
428
|
val = val < 0 ? 0 : val;
|
|
428
429
|
if (this._range !== val) {
|
|
@@ -438,10 +439,10 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
438
439
|
set cutoff(val) {
|
|
439
440
|
this.setCutoff(val);
|
|
440
441
|
}
|
|
441
|
-
/**
|
|
442
|
-
* Sets the cutoff of the light
|
|
443
|
-
* @param val - The value to set
|
|
444
|
-
* @returns self
|
|
442
|
+
/**
|
|
443
|
+
* Sets the cutoff of the light
|
|
444
|
+
* @param val - The value to set
|
|
445
|
+
* @returns self
|
|
445
446
|
*/ setCutoff(val) {
|
|
446
447
|
val = val < 0 ? 0 : val;
|
|
447
448
|
if (this._cutoff !== val) {
|
|
@@ -451,40 +452,41 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
451
452
|
}
|
|
452
453
|
return this;
|
|
453
454
|
}
|
|
454
|
-
/**
|
|
455
|
-
* {@inheritDoc BaseLight.isSpotLight}
|
|
456
|
-
* @override
|
|
455
|
+
/**
|
|
456
|
+
* {@inheritDoc BaseLight.isSpotLight}
|
|
457
|
+
* @override
|
|
457
458
|
*/ isSpotLight() {
|
|
458
459
|
return true;
|
|
459
460
|
}
|
|
460
461
|
/** @internal */ computeBoundingVolume() {
|
|
461
462
|
const bbox = new BoundingBox();
|
|
462
463
|
const cosCutoff = Math.cos(this._cutoff);
|
|
463
|
-
const
|
|
464
|
+
const range = this.positionAndRange.w;
|
|
465
|
+
const r = range / cosCutoff * Math.sqrt(1 - cosCutoff * cosCutoff);
|
|
464
466
|
bbox.minPoint = new Vector3(-r, -r, 0);
|
|
465
|
-
bbox.maxPoint = new Vector3(r, r,
|
|
467
|
+
bbox.maxPoint = new Vector3(r, r, range);
|
|
466
468
|
return bbox;
|
|
467
469
|
}
|
|
468
470
|
/** @internal */ computeUniforms() {
|
|
469
471
|
const a = this.worldMatrix.getRow(3);
|
|
470
472
|
const b = this.worldMatrix.getRow(2).scaleBy(-1);
|
|
471
|
-
const range = this.range
|
|
473
|
+
const range = this.range <= 0 ? 32 * Math.sqrt(Math.max(0.0001, this.intensity)) : this.range;
|
|
472
474
|
this._positionRange = new Vector4(a.x, a.y, a.z, range);
|
|
473
475
|
this._directionCutoff = new Vector4(b.x, b.y, b.z, this.cutoff);
|
|
474
476
|
this._diffuseIntensity = new Vector4(this.color.x, this.color.y, this.color.z, this.intensity);
|
|
475
477
|
this._extraParams = new Vector4(0, 0, 0, this.lightType);
|
|
476
478
|
}
|
|
477
479
|
}
|
|
478
|
-
/**
|
|
479
|
-
* Rectangular area light
|
|
480
|
-
* @public
|
|
480
|
+
/**
|
|
481
|
+
* Rectangular area light
|
|
482
|
+
* @public
|
|
481
483
|
*/ class RectLight extends PunctualLight {
|
|
482
484
|
/** @internal */ _range;
|
|
483
485
|
/** @internal */ _width;
|
|
484
486
|
/** @internal */ _height;
|
|
485
|
-
/**
|
|
486
|
-
* Creates an instance of rect light
|
|
487
|
-
* @param scene - The scene to which the light belongs
|
|
487
|
+
/**
|
|
488
|
+
* Creates an instance of rect light
|
|
489
|
+
* @param scene - The scene to which the light belongs
|
|
488
490
|
*/ constructor(scene){
|
|
489
491
|
super(scene, LIGHT_TYPE_RECT);
|
|
490
492
|
this._range = 10;
|
|
@@ -498,10 +500,10 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
498
500
|
set range(val) {
|
|
499
501
|
this.setRange(val);
|
|
500
502
|
}
|
|
501
|
-
/**
|
|
502
|
-
* Sets the range of the light
|
|
503
|
-
* @param val - The value to set
|
|
504
|
-
* @returns self
|
|
503
|
+
/**
|
|
504
|
+
* Sets the range of the light
|
|
505
|
+
* @param val - The value to set
|
|
506
|
+
* @returns self
|
|
505
507
|
*/ setRange(val) {
|
|
506
508
|
val = val < 0 ? 0 : val;
|
|
507
509
|
if (this._range !== val) {
|
|
@@ -517,10 +519,10 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
517
519
|
set width(val) {
|
|
518
520
|
this.setWidth(val);
|
|
519
521
|
}
|
|
520
|
-
/**
|
|
521
|
-
* Sets the width of the light
|
|
522
|
-
* @param val - The value to set
|
|
523
|
-
* @returns self
|
|
522
|
+
/**
|
|
523
|
+
* Sets the width of the light
|
|
524
|
+
* @param val - The value to set
|
|
525
|
+
* @returns self
|
|
524
526
|
*/ setWidth(val) {
|
|
525
527
|
val = val < 0 ? 0 : val;
|
|
526
528
|
if (this._width !== val) {
|
|
@@ -536,10 +538,10 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
536
538
|
set height(val) {
|
|
537
539
|
this.setHeight(val);
|
|
538
540
|
}
|
|
539
|
-
/**
|
|
540
|
-
* Sets the height of the light
|
|
541
|
-
* @param val - The value to set
|
|
542
|
-
* @returns self
|
|
541
|
+
/**
|
|
542
|
+
* Sets the height of the light
|
|
543
|
+
* @param val - The value to set
|
|
544
|
+
* @returns self
|
|
543
545
|
*/ setHeight(val) {
|
|
544
546
|
val = val < 0 ? 0 : val;
|
|
545
547
|
if (this._height !== val) {
|
|
@@ -549,14 +551,14 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
549
551
|
}
|
|
550
552
|
return this;
|
|
551
553
|
}
|
|
552
|
-
/**
|
|
553
|
-
* {@inheritDoc BaseLight.isRectLight}
|
|
554
|
-
* @override
|
|
554
|
+
/**
|
|
555
|
+
* {@inheritDoc BaseLight.isRectLight}
|
|
556
|
+
* @override
|
|
555
557
|
*/ isRectLight() {
|
|
556
558
|
return true;
|
|
557
559
|
}
|
|
558
|
-
/**
|
|
559
|
-
* Rect light supports shadow in current pipeline
|
|
560
|
+
/**
|
|
561
|
+
* Rect light supports shadow in current pipeline
|
|
560
562
|
*/ /** @internal */ computeBoundingVolume() {
|
|
561
563
|
const bbox = new BoundingBox();
|
|
562
564
|
const r = this._range;
|