bg2e-js 2.3.12 → 2.3.13
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/bg2e-js.js +350 -326
- package/dist/bg2e-js.js.map +1 -1
- package/package.json +56 -56
- package/src/app/AppController.ts +39 -39
- package/src/app/Bg2KeyboardEvent.ts +54 -54
- package/src/app/Bg2MouseEvent.ts +82 -82
- package/src/app/Bg2TouchEvent.ts +18 -18
- package/src/app/Canvas.ts +108 -108
- package/src/app/EventBase.ts +10 -10
- package/src/app/MainLoop.ts +273 -273
- package/src/app/index.ts +24 -24
- package/src/base/Color.ts +134 -134
- package/src/base/Environment.ts +183 -183
- package/src/base/Light.ts +192 -192
- package/src/base/Material.ts +620 -620
- package/src/base/PolyList.ts +365 -365
- package/src/base/Texture.ts +620 -620
- package/src/base/index.ts +81 -81
- package/src/db/Bg2LoaderPlugin.ts +143 -143
- package/src/db/DBPluginApi.ts +48 -48
- package/src/db/Loader.ts +116 -116
- package/src/db/LoaderPlugin.ts +34 -34
- package/src/db/MtlParser.ts +7 -7
- package/src/db/ObjLoaderPlugin.ts +54 -54
- package/src/db/ObjParser.ts +252 -252
- package/src/db/ObjWriterPlugin.ts +18 -18
- package/src/db/VitscnjLoaderPlugin.ts +112 -112
- package/src/db/Writer.ts +52 -52
- package/src/db/WriterPlugin.ts +22 -22
- package/src/db/index.ts +44 -44
- package/src/debug/DebugRenderer.ts +173 -173
- package/src/debug/WebGLTextureViewer.ts +75 -75
- package/src/debug/index.ts +6 -6
- package/src/index.html +11 -11
- package/src/index.ts +33 -33
- package/src/manipulation/SelectionBuffer.ts +81 -81
- package/src/manipulation/SelectionHighlight.ts +105 -84
- package/src/manipulation/SelectionIdAssignVisitor.ts +96 -96
- package/src/manipulation/SelectionManager.ts +196 -196
- package/src/manipulation/SelectionMode.ts +6 -6
- package/src/math/Mat3.ts +259 -259
- package/src/math/Mat4.ts +710 -710
- package/src/math/MatrixStrategy.ts +25 -25
- package/src/math/Quat.ts +65 -65
- package/src/math/Vec.ts +753 -753
- package/src/math/constants.ts +46 -46
- package/src/math/functions.ts +103 -103
- package/src/math/index.ts +74 -74
- package/src/phsics/joint.ts +137 -137
- package/src/primitives/arrow.ts +57 -57
- package/src/primitives/cone.ts +138 -138
- package/src/primitives/cube.ts +60 -60
- package/src/primitives/cylinder.ts +216 -216
- package/src/primitives/index.ts +13 -13
- package/src/primitives/plane.ts +31 -31
- package/src/primitives/sphere.ts +809 -809
- package/src/react/useBg2e.ts +69 -69
- package/src/render/BRDFIntegrationMap.ts +4 -4
- package/src/render/Environment.ts +135 -135
- package/src/render/FrameBuffer.ts +35 -35
- package/src/render/MaterialRenderer.ts +34 -34
- package/src/render/Pipeline.ts +108 -108
- package/src/render/PolyListRenderer.ts +47 -47
- package/src/render/RenderBuffer.ts +197 -197
- package/src/render/RenderQueue.ts +198 -198
- package/src/render/RenderState.ts +116 -116
- package/src/render/Renderer.ts +248 -248
- package/src/render/SceneAppController.ts +250 -250
- package/src/render/SceneRenderer.ts +387 -387
- package/src/render/Shader.ts +32 -32
- package/src/render/ShadowRenderer.ts +176 -176
- package/src/render/SkyCube.ts +105 -105
- package/src/render/SkySphere.ts +117 -117
- package/src/render/TextureMergerRenderer.ts +70 -70
- package/src/render/TextureRenderer.ts +34 -34
- package/src/render/index.ts +67 -67
- package/src/render/webgl/FrameBuffer.ts +9 -9
- package/src/render/webgl/MaterialRenderer.ts +112 -112
- package/src/render/webgl/Pipeline.ts +88 -88
- package/src/render/webgl/PolyListRenderer.ts +260 -260
- package/src/render/webgl/RenderBuffer.ts +226 -226
- package/src/render/webgl/Renderer.ts +262 -262
- package/src/render/webgl/SceneRenderer.ts +67 -67
- package/src/render/webgl/ShaderProgram.ts +424 -424
- package/src/render/webgl/ShadowRenderer.ts +6 -6
- package/src/render/webgl/SkyCube.ts +15 -15
- package/src/render/webgl/SkySphere.ts +15 -15
- package/src/render/webgl/State.ts +152 -152
- package/src/render/webgl/TextureRenderer.ts +167 -167
- package/src/render/webgl/VertexBuffer.ts +137 -137
- package/src/render/webgl/index.ts +35 -35
- package/src/scene/Camera.ts +458 -458
- package/src/scene/Chain.ts +44 -44
- package/src/scene/ChainJoint.ts +58 -58
- package/src/scene/Component.ts +177 -177
- package/src/scene/ComponentMap.ts +106 -106
- package/src/scene/Drawable.ts +154 -154
- package/src/scene/EnvironmentComponent.ts +141 -141
- package/src/scene/FindNodeVisitor.ts +59 -59
- package/src/scene/LightComponent.ts +154 -154
- package/src/scene/MatrixState.ts +46 -46
- package/src/scene/Node.ts +328 -328
- package/src/scene/NodeVisitor.ts +15 -15
- package/src/scene/OrbitCameraController.ts +450 -450
- package/src/scene/SmoothOrbitCameraController.ts +99 -99
- package/src/scene/Transform.ts +73 -73
- package/src/scene/index.ts +60 -60
- package/src/shaders/BasicDiffuseColorShader.ts +111 -111
- package/src/shaders/BasicPBRLightShader.ts +276 -276
- package/src/shaders/DebugRenderShader.ts +97 -97
- package/src/shaders/DepthRenderShader.ts +127 -127
- package/src/shaders/IrradianceMapCubeShader.ts +115 -115
- package/src/shaders/PBRLightIBLShader.ts +486 -486
- package/src/shaders/PickSelectionShader.ts +101 -101
- package/src/shaders/PresentDebugFramebufferShader.ts +118 -118
- package/src/shaders/PresentTextureShader.ts +99 -99
- package/src/shaders/SelectionHighlightShader.ts +143 -127
- package/src/shaders/ShaderFunction.ts +318 -318
- package/src/shaders/SkyCubeShader.ts +93 -93
- package/src/shaders/SkySphereShader.ts +102 -102
- package/src/shaders/SpecularMapCubeShader.ts +164 -164
- package/src/shaders/TextureMergerShader.ts +171 -171
- package/src/shaders/index.ts +36 -36
- package/src/shaders/webgl/color_correction.glsl +47 -47
- package/src/shaders/webgl/constants.glsl +6 -6
- package/src/shaders/webgl/index.ts +70 -70
- package/src/shaders/webgl/normal_map.glsl +9 -9
- package/src/shaders/webgl/pbr.glsl +173 -173
- package/src/shaders/webgl/uniforms.glsl +91 -91
- package/src/shaders/webgl_shader_lib.ts +213 -213
- package/src/tools/BinaryResourceProvider.ts +14 -14
- package/src/tools/ImageResourceProvider.ts +66 -66
- package/src/tools/MaterialModifier.ts +446 -446
- package/src/tools/Resource.ts +203 -203
- package/src/tools/ResourceProvider.ts +69 -69
- package/src/tools/TextResourceProvider.ts +24 -24
- package/src/tools/TextureCache.ts +51 -51
- package/src/tools/TextureResourceDatabase.ts +100 -100
- package/src/tools/UserAgent.ts +362 -362
- package/src/tools/VideoResourceProvider.ts +50 -50
- package/src/tools/WriteStrategy.ts +22 -22
- package/src/tools/base64.ts +11 -11
- package/src/tools/crypto.ts +19 -19
- package/src/tools/endiantess.ts +13 -13
- package/src/tools/image.ts +18 -18
- package/src/tools/index.ts +41 -41
- package/src/tools/processType.ts +39 -39
- package/src/vite-env.d.ts +12 -12
package/src/base/Light.ts
CHANGED
|
@@ -1,192 +1,192 @@
|
|
|
1
|
-
|
|
2
|
-
import Vec from '../math/Vec';
|
|
3
|
-
import Mat4 from '../math/Mat4';
|
|
4
|
-
import Color from './Color';
|
|
5
|
-
import Texture from './Texture';
|
|
6
|
-
|
|
7
|
-
export enum LightType {
|
|
8
|
-
DIRECTIONAL = 4,
|
|
9
|
-
SPOT = 1,
|
|
10
|
-
POINT = 5,
|
|
11
|
-
DISABLED = 10
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default class Light {
|
|
15
|
-
_enabled: boolean;
|
|
16
|
-
_type: LightType;
|
|
17
|
-
_direction: Vec;
|
|
18
|
-
_position: Vec;
|
|
19
|
-
_color: Color;
|
|
20
|
-
_intensity: number;
|
|
21
|
-
_spotCutoff: number;
|
|
22
|
-
_spotExponent: number;
|
|
23
|
-
_shadowStrength: number;
|
|
24
|
-
_castShadows: boolean;
|
|
25
|
-
_shadowBias: number;
|
|
26
|
-
_projection: Mat4;
|
|
27
|
-
_depthTexture: Texture | null;
|
|
28
|
-
_viewMatrix?: Mat4;
|
|
29
|
-
|
|
30
|
-
constructor() {
|
|
31
|
-
this._enabled = true;
|
|
32
|
-
|
|
33
|
-
this._type = LightType.DIRECTIONAL;
|
|
34
|
-
|
|
35
|
-
this._direction = new Vec(0,0,-1);
|
|
36
|
-
this._position = new Vec(0,0,0);
|
|
37
|
-
|
|
38
|
-
this._color = new Color({ rgb: 0.9 });
|
|
39
|
-
this._intensity = 20;
|
|
40
|
-
this._spotCutoff = 20;
|
|
41
|
-
this._spotExponent = 30;
|
|
42
|
-
this._shadowStrength = 0.7;
|
|
43
|
-
this._castShadows = true;
|
|
44
|
-
this._shadowBias = 0.00002;
|
|
45
|
-
|
|
46
|
-
this._projection = Mat4.MakeOrtho(-10,10,-10,10,0.1,500.0);
|
|
47
|
-
|
|
48
|
-
// Internal engine use. This attribute will not be serialized
|
|
49
|
-
this._depthTexture = null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
clone() {
|
|
53
|
-
const newLight = new Light();
|
|
54
|
-
newLight.assign(this);
|
|
55
|
-
return newLight;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
assign(other: Light) {
|
|
59
|
-
this.enabled = other.enabled;
|
|
60
|
-
this.type = other.type;
|
|
61
|
-
this.direction.assign(other.direction);
|
|
62
|
-
this.position.assign(other.position);
|
|
63
|
-
this.color.assign(other.color);
|
|
64
|
-
this.spotCutoff = other.spotCutoff;
|
|
65
|
-
this.spotExponent = other.spotExponent;
|
|
66
|
-
this.shadowStrength = other.shadowStrength;
|
|
67
|
-
this.castShadows = other.castShadows;
|
|
68
|
-
this.shadowBias = other.shadowBias;
|
|
69
|
-
this.intensity = other.intensity;
|
|
70
|
-
this.projection.assign(other.projection);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
get enabled() { return this._enabled; }
|
|
74
|
-
set enabled(v: boolean) { this._enabled = v; }
|
|
75
|
-
|
|
76
|
-
get type() { return this._type; }
|
|
77
|
-
set type(t: LightType) { this._type = t; }
|
|
78
|
-
|
|
79
|
-
get direction() { return this._direction; }
|
|
80
|
-
set direction(d: Vec) { this._direction = d; }
|
|
81
|
-
|
|
82
|
-
get position() { return this._position; }
|
|
83
|
-
set position(p: Vec) { this._position = p; }
|
|
84
|
-
|
|
85
|
-
get color() : Color { return this._color; }
|
|
86
|
-
set color(c: Color | number[]) {
|
|
87
|
-
if (c.length === 3) {
|
|
88
|
-
this._color = new Color([c[0], c[1], c[2], 1]);
|
|
89
|
-
}
|
|
90
|
-
else if (c.length === 4) {
|
|
91
|
-
this._color = new Color(c);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
throw new Error(`Invalid light color assignment. Parameter must be a three or four component array.`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
get intensity() { return this._intensity; }
|
|
98
|
-
set intensity(i) { this._intensity = i; }
|
|
99
|
-
|
|
100
|
-
get spotCutoff() { return this._spotCutoff; }
|
|
101
|
-
set spotCutoff(c) { this._spotCutoff = c; }
|
|
102
|
-
get spotExponent() { return this._spotExponent; }
|
|
103
|
-
set spotExponent(e) { this._spotExponent = e; }
|
|
104
|
-
|
|
105
|
-
get shadowStrength() { return this._shadowStrength; }
|
|
106
|
-
set shadowStrength(s) { this._shadowStrength = s; }
|
|
107
|
-
get castShadows() { return this._castShadows; }
|
|
108
|
-
set castShadows(s) { this._castShadows = s; }
|
|
109
|
-
get shadowBias() { return this._shadowBias; }
|
|
110
|
-
set shadowBias(s) { this._shadowBias = s; }
|
|
111
|
-
|
|
112
|
-
get projection() { return this._projection; }
|
|
113
|
-
set projection(p) { this._projection = p; }
|
|
114
|
-
|
|
115
|
-
get depthTexture(): Texture | null {
|
|
116
|
-
return this._depthTexture;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
set depthTexture(t: Texture | null) {
|
|
120
|
-
this._depthTexture = t;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
get viewMatrix() {
|
|
124
|
-
return this._viewMatrix;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
set viewMatrix(m) {
|
|
128
|
-
this._viewMatrix = m;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async deserialize(sceneData: any) {
|
|
132
|
-
switch (sceneData.lightType) {
|
|
133
|
-
case 'kTypeDirectional':
|
|
134
|
-
case LightType.DIRECTIONAL:
|
|
135
|
-
this._type = LightType.DIRECTIONAL;
|
|
136
|
-
// Use the predefined shadow bias for directional lights
|
|
137
|
-
//this._shadowBias = sceneData.shadowBias;
|
|
138
|
-
break;
|
|
139
|
-
case 'kTypeSpot':
|
|
140
|
-
case LightType.SPOT:
|
|
141
|
-
this._type = LightType.SPOT;
|
|
142
|
-
this._shadowBias = sceneData.shadowBias;
|
|
143
|
-
break;
|
|
144
|
-
case 'kTypePoint':
|
|
145
|
-
case LightType.POINT:
|
|
146
|
-
this._type = LightType.POINT;
|
|
147
|
-
break;
|
|
148
|
-
default:
|
|
149
|
-
this._type = LightType.DIRECTIONAL;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const defaultIntensity = () => this._type === LightType.DIRECTIONAL ? 1 : 20;
|
|
153
|
-
|
|
154
|
-
this._position = sceneData.position || new Vec(0,0,0);
|
|
155
|
-
this._direction = sceneData.direction || new Vec(0, 0, -1);
|
|
156
|
-
|
|
157
|
-
if (sceneData.diffuse) {
|
|
158
|
-
this._color = new Color(sceneData.diffuse);
|
|
159
|
-
this._intensity = (sceneData.intensity || 1) * defaultIntensity();
|
|
160
|
-
}
|
|
161
|
-
else if (sceneData.color) {
|
|
162
|
-
this._color = new Color(sceneData.color);
|
|
163
|
-
this._intensity = sceneData.intensity || defaultIntensity();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
this._spotCutoff = sceneData.spotCutoff || 20;
|
|
167
|
-
this._spotExponent = sceneData.spotExponent || 30;
|
|
168
|
-
this._shadowStrength = sceneData.shadowStrength || 1;
|
|
169
|
-
if (sceneData.projection) {
|
|
170
|
-
this._projection = new Mat4(sceneData.projection);
|
|
171
|
-
}
|
|
172
|
-
this._castShadows = sceneData.castShadows !== undefined ? sceneData.castShadows : true;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async serialize(sceneData: any) {
|
|
176
|
-
const lightTypes = [];
|
|
177
|
-
lightTypes[LightType.DIRECTIONAL] = "kTypeDirectional";
|
|
178
|
-
lightTypes[LightType.SPOT] = "kTypeSpot";
|
|
179
|
-
lightTypes[LightType.POINT] = "kTypePoint";
|
|
180
|
-
sceneData.lightType = lightTypes[this._type];
|
|
181
|
-
sceneData.position = this._position;
|
|
182
|
-
sceneData.direction = this._direction;
|
|
183
|
-
sceneData.color = this._color;
|
|
184
|
-
sceneData.intensity = this._intensity;
|
|
185
|
-
sceneData.spotCutoff = this._spotCutoff || 20;
|
|
186
|
-
sceneData.spotExponent = this._spotExponent || 30;
|
|
187
|
-
sceneData.shadowStrength = this._shadowStrength;
|
|
188
|
-
sceneData.projection = this._projection;
|
|
189
|
-
sceneData.castShadows = this._castShadows;
|
|
190
|
-
sceneData.shadowBias = this._shadowBias || 0.0029;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
1
|
+
|
|
2
|
+
import Vec from '../math/Vec';
|
|
3
|
+
import Mat4 from '../math/Mat4';
|
|
4
|
+
import Color from './Color';
|
|
5
|
+
import Texture from './Texture';
|
|
6
|
+
|
|
7
|
+
export enum LightType {
|
|
8
|
+
DIRECTIONAL = 4,
|
|
9
|
+
SPOT = 1,
|
|
10
|
+
POINT = 5,
|
|
11
|
+
DISABLED = 10
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default class Light {
|
|
15
|
+
_enabled: boolean;
|
|
16
|
+
_type: LightType;
|
|
17
|
+
_direction: Vec;
|
|
18
|
+
_position: Vec;
|
|
19
|
+
_color: Color;
|
|
20
|
+
_intensity: number;
|
|
21
|
+
_spotCutoff: number;
|
|
22
|
+
_spotExponent: number;
|
|
23
|
+
_shadowStrength: number;
|
|
24
|
+
_castShadows: boolean;
|
|
25
|
+
_shadowBias: number;
|
|
26
|
+
_projection: Mat4;
|
|
27
|
+
_depthTexture: Texture | null;
|
|
28
|
+
_viewMatrix?: Mat4;
|
|
29
|
+
|
|
30
|
+
constructor() {
|
|
31
|
+
this._enabled = true;
|
|
32
|
+
|
|
33
|
+
this._type = LightType.DIRECTIONAL;
|
|
34
|
+
|
|
35
|
+
this._direction = new Vec(0,0,-1);
|
|
36
|
+
this._position = new Vec(0,0,0);
|
|
37
|
+
|
|
38
|
+
this._color = new Color({ rgb: 0.9 });
|
|
39
|
+
this._intensity = 20;
|
|
40
|
+
this._spotCutoff = 20;
|
|
41
|
+
this._spotExponent = 30;
|
|
42
|
+
this._shadowStrength = 0.7;
|
|
43
|
+
this._castShadows = true;
|
|
44
|
+
this._shadowBias = 0.00002;
|
|
45
|
+
|
|
46
|
+
this._projection = Mat4.MakeOrtho(-10,10,-10,10,0.1,500.0);
|
|
47
|
+
|
|
48
|
+
// Internal engine use. This attribute will not be serialized
|
|
49
|
+
this._depthTexture = null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
clone() {
|
|
53
|
+
const newLight = new Light();
|
|
54
|
+
newLight.assign(this);
|
|
55
|
+
return newLight;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
assign(other: Light) {
|
|
59
|
+
this.enabled = other.enabled;
|
|
60
|
+
this.type = other.type;
|
|
61
|
+
this.direction.assign(other.direction);
|
|
62
|
+
this.position.assign(other.position);
|
|
63
|
+
this.color.assign(other.color);
|
|
64
|
+
this.spotCutoff = other.spotCutoff;
|
|
65
|
+
this.spotExponent = other.spotExponent;
|
|
66
|
+
this.shadowStrength = other.shadowStrength;
|
|
67
|
+
this.castShadows = other.castShadows;
|
|
68
|
+
this.shadowBias = other.shadowBias;
|
|
69
|
+
this.intensity = other.intensity;
|
|
70
|
+
this.projection.assign(other.projection);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get enabled() { return this._enabled; }
|
|
74
|
+
set enabled(v: boolean) { this._enabled = v; }
|
|
75
|
+
|
|
76
|
+
get type() { return this._type; }
|
|
77
|
+
set type(t: LightType) { this._type = t; }
|
|
78
|
+
|
|
79
|
+
get direction() { return this._direction; }
|
|
80
|
+
set direction(d: Vec) { this._direction = d; }
|
|
81
|
+
|
|
82
|
+
get position() { return this._position; }
|
|
83
|
+
set position(p: Vec) { this._position = p; }
|
|
84
|
+
|
|
85
|
+
get color() : Color { return this._color; }
|
|
86
|
+
set color(c: Color | number[]) {
|
|
87
|
+
if (c.length === 3) {
|
|
88
|
+
this._color = new Color([c[0], c[1], c[2], 1]);
|
|
89
|
+
}
|
|
90
|
+
else if (c.length === 4) {
|
|
91
|
+
this._color = new Color(c);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
throw new Error(`Invalid light color assignment. Parameter must be a three or four component array.`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
get intensity() { return this._intensity; }
|
|
98
|
+
set intensity(i) { this._intensity = i; }
|
|
99
|
+
|
|
100
|
+
get spotCutoff() { return this._spotCutoff; }
|
|
101
|
+
set spotCutoff(c) { this._spotCutoff = c; }
|
|
102
|
+
get spotExponent() { return this._spotExponent; }
|
|
103
|
+
set spotExponent(e) { this._spotExponent = e; }
|
|
104
|
+
|
|
105
|
+
get shadowStrength() { return this._shadowStrength; }
|
|
106
|
+
set shadowStrength(s) { this._shadowStrength = s; }
|
|
107
|
+
get castShadows() { return this._castShadows; }
|
|
108
|
+
set castShadows(s) { this._castShadows = s; }
|
|
109
|
+
get shadowBias() { return this._shadowBias; }
|
|
110
|
+
set shadowBias(s) { this._shadowBias = s; }
|
|
111
|
+
|
|
112
|
+
get projection() { return this._projection; }
|
|
113
|
+
set projection(p) { this._projection = p; }
|
|
114
|
+
|
|
115
|
+
get depthTexture(): Texture | null {
|
|
116
|
+
return this._depthTexture;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
set depthTexture(t: Texture | null) {
|
|
120
|
+
this._depthTexture = t;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
get viewMatrix() {
|
|
124
|
+
return this._viewMatrix;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
set viewMatrix(m) {
|
|
128
|
+
this._viewMatrix = m;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async deserialize(sceneData: any) {
|
|
132
|
+
switch (sceneData.lightType) {
|
|
133
|
+
case 'kTypeDirectional':
|
|
134
|
+
case LightType.DIRECTIONAL:
|
|
135
|
+
this._type = LightType.DIRECTIONAL;
|
|
136
|
+
// Use the predefined shadow bias for directional lights
|
|
137
|
+
//this._shadowBias = sceneData.shadowBias;
|
|
138
|
+
break;
|
|
139
|
+
case 'kTypeSpot':
|
|
140
|
+
case LightType.SPOT:
|
|
141
|
+
this._type = LightType.SPOT;
|
|
142
|
+
this._shadowBias = sceneData.shadowBias;
|
|
143
|
+
break;
|
|
144
|
+
case 'kTypePoint':
|
|
145
|
+
case LightType.POINT:
|
|
146
|
+
this._type = LightType.POINT;
|
|
147
|
+
break;
|
|
148
|
+
default:
|
|
149
|
+
this._type = LightType.DIRECTIONAL;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const defaultIntensity = () => this._type === LightType.DIRECTIONAL ? 1 : 20;
|
|
153
|
+
|
|
154
|
+
this._position = sceneData.position || new Vec(0,0,0);
|
|
155
|
+
this._direction = sceneData.direction || new Vec(0, 0, -1);
|
|
156
|
+
|
|
157
|
+
if (sceneData.diffuse) {
|
|
158
|
+
this._color = new Color(sceneData.diffuse);
|
|
159
|
+
this._intensity = (sceneData.intensity || 1) * defaultIntensity();
|
|
160
|
+
}
|
|
161
|
+
else if (sceneData.color) {
|
|
162
|
+
this._color = new Color(sceneData.color);
|
|
163
|
+
this._intensity = sceneData.intensity || defaultIntensity();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
this._spotCutoff = sceneData.spotCutoff || 20;
|
|
167
|
+
this._spotExponent = sceneData.spotExponent || 30;
|
|
168
|
+
this._shadowStrength = sceneData.shadowStrength || 1;
|
|
169
|
+
if (sceneData.projection) {
|
|
170
|
+
this._projection = new Mat4(sceneData.projection);
|
|
171
|
+
}
|
|
172
|
+
this._castShadows = sceneData.castShadows !== undefined ? sceneData.castShadows : true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async serialize(sceneData: any) {
|
|
176
|
+
const lightTypes = [];
|
|
177
|
+
lightTypes[LightType.DIRECTIONAL] = "kTypeDirectional";
|
|
178
|
+
lightTypes[LightType.SPOT] = "kTypeSpot";
|
|
179
|
+
lightTypes[LightType.POINT] = "kTypePoint";
|
|
180
|
+
sceneData.lightType = lightTypes[this._type];
|
|
181
|
+
sceneData.position = this._position;
|
|
182
|
+
sceneData.direction = this._direction;
|
|
183
|
+
sceneData.color = this._color;
|
|
184
|
+
sceneData.intensity = this._intensity;
|
|
185
|
+
sceneData.spotCutoff = this._spotCutoff || 20;
|
|
186
|
+
sceneData.spotExponent = this._spotExponent || 30;
|
|
187
|
+
sceneData.shadowStrength = this._shadowStrength;
|
|
188
|
+
sceneData.projection = this._projection;
|
|
189
|
+
sceneData.castShadows = this._castShadows;
|
|
190
|
+
sceneData.shadowBias = this._shadowBias || 0.0029;
|
|
191
|
+
}
|
|
192
|
+
}
|