@shapediver/viewer.rendering-engine.light-engine 3.3.4 → 3.3.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapediver/viewer.rendering-engine.light-engine",
3
- "version": "3.3.4",
3
+ "version": "3.3.6",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "Michael Oppitz <michael@shapediver.com>",
@@ -10,11 +10,10 @@
10
10
  "test": "__tests__"
11
11
  },
12
12
  "files": [
13
- "dist",
14
- "src",
15
13
  "package.json",
14
+ "dist/",
16
15
  "README.md",
17
- "tsconfig.json"
16
+ "LICENSE"
18
17
  ],
19
18
  "publishConfig": {
20
19
  "access": "public"
@@ -39,12 +38,12 @@
39
38
  "testEnvironment": "node"
40
39
  },
41
40
  "dependencies": {
42
- "@shapediver/viewer.rendering-engine.rendering-engine": "3.3.4",
41
+ "@shapediver/viewer.rendering-engine.rendering-engine": "3.3.6",
43
42
  "@shapediver/viewer.settings": "1.0.2",
44
- "@shapediver/viewer.shared.node-tree": "3.3.4",
45
- "@shapediver/viewer.shared.services": "3.3.4",
46
- "@shapediver/viewer.shared.types": "3.3.4",
43
+ "@shapediver/viewer.shared.node-tree": "3.3.6",
44
+ "@shapediver/viewer.shared.services": "3.3.6",
45
+ "@shapediver/viewer.shared.types": "3.3.6",
47
46
  "gl-matrix": "3.3.0"
48
47
  },
49
- "gitHead": "8193da527b4e3fc4d90181018bd60d6ac70be3e8"
48
+ "gitHead": "13aea937b128a001e6e93be300674c4a04624c29"
50
49
  }
@@ -1,106 +0,0 @@
1
- import { AbstractTreeNodeData, ITreeNode } from '@shapediver/viewer.shared.node-tree';
2
- import { Color } from '@shapediver/viewer.shared.types';
3
- import { ILight, LIGHT_TYPE } from '../interface/ILight';
4
- import { UuidGenerator } from '@shapediver/viewer.shared.services';
5
-
6
- export abstract class AbstractLight extends AbstractTreeNodeData implements ILight {
7
- // #region Properties (8)
8
-
9
- readonly #type: LIGHT_TYPE;
10
-
11
- #color: Color;
12
- #intensity: number;
13
- #name?: string;
14
- #order?: number;
15
- #parentNode?: ITreeNode;
16
- #useNodeData: boolean = false;
17
-
18
- protected readonly _uuidGenerator: UuidGenerator = UuidGenerator.instance;
19
-
20
- // #endregion Properties (8)
21
-
22
- // #region Constructors (1)
23
-
24
- constructor(properties: {
25
- color: Color,
26
- intensity: number,
27
- type: LIGHT_TYPE,
28
- name?: string,
29
- order?: number,
30
- id?: string,
31
- version?: string
32
- }) {
33
- super(properties.id, properties.version);
34
- this.#color = properties.color;
35
- this.#intensity = properties.intensity;
36
- this.#type = properties.type;
37
- this.#name = properties.name;
38
- this.#order = properties.order;
39
- }
40
-
41
- // #endregion Constructors (1)
42
-
43
- // #region Public Getters And Setters (13)
44
-
45
- public get color(): Color {
46
- return this.#color;
47
- }
48
-
49
- public set color(value: Color) {
50
- this.#color = value;
51
- this.updateVersion();
52
- if (this.parentNode) this.parentNode.updateVersion();
53
- }
54
-
55
- public get intensity(): number {
56
- return this.#intensity;
57
- }
58
-
59
- public set intensity(value: number) {
60
- this.#intensity = value;
61
- this.updateVersion();
62
- if (this.parentNode) this.parentNode.updateVersion();
63
- }
64
-
65
- public get name(): string | undefined {
66
- return this.#name;
67
- }
68
-
69
- public set name(value: string | undefined) {
70
- this.#name = value;
71
- this.updateVersion();
72
- if (this.parentNode) this.parentNode.updateVersion();
73
- }
74
-
75
- public get order(): number | undefined {
76
- return this.#order;
77
- }
78
-
79
- public set order(value: number | undefined) {
80
- this.#order = value;
81
- this.updateVersion();
82
- if (this.parentNode) this.parentNode.updateVersion();
83
- }
84
-
85
- public get parentNode(): ITreeNode | undefined {
86
- return this.#parentNode;
87
- }
88
-
89
- public set parentNode(value: ITreeNode | undefined) {
90
- this.#parentNode = value;
91
- }
92
-
93
- public get type(): LIGHT_TYPE {
94
- return this.#type;
95
- }
96
-
97
- public get useNodeData(): boolean {
98
- return this.#useNodeData;
99
- }
100
-
101
- public set useNodeData(value: boolean) {
102
- this.#useNodeData = value;
103
- }
104
-
105
- // #endregion Public Getters And Setters (13)
106
- }
@@ -1,328 +0,0 @@
1
- import { AbstractLight } from './AbstractLight';
2
- import { AmbientLight } from './types/AmbientLight';
3
- import {
4
- Converter,
5
- SettingsEngine,
6
- UuidGenerator
7
- } from '@shapediver/viewer.shared.services';
8
- import { DirectionalLight } from './types/DirectionalLight';
9
- import { HemisphereLight } from './types/HemisphereLight';
10
- import {
11
- IAmbientLightProperties,
12
- IDirectionalLightProperties,
13
- IHemisphereLightProperties,
14
- ILightSceneSettings,
15
- IPointLightProperties,
16
- ISpotLightProperties
17
- } from '@shapediver/viewer.settings';
18
- import { LIGHT_TYPE } from '../interface/ILight';
19
- import { ILightEngine } from '../interface/ILightEngine';
20
- import { ILightScene } from '../interface/ILightScene';
21
- import { IRenderingEngine } from '@shapediver/viewer.rendering-engine.rendering-engine';
22
- import {
23
- ITree,
24
- ITreeNode,
25
- Tree,
26
- TreeNode
27
- } from '@shapediver/viewer.shared.node-tree';
28
- import { LightScene } from './LightScene';
29
- import { PointLight } from './types/PointLight';
30
- import { SpotLight } from './types/SpotLight';
31
- import { vec3 } from 'gl-matrix';
32
-
33
- export class LightEngine implements ILightEngine {
34
- // #region Properties (7)
35
-
36
- private readonly _converter: Converter = Converter.instance;
37
- private readonly _lightNode: ITreeNode = new TreeNode('lights');
38
- private readonly _tree: ITree = Tree.instance;
39
- private readonly _uuidGenerator: UuidGenerator = UuidGenerator.instance;
40
-
41
- private _lightScene!: LightScene;
42
- private _lightScenes: { [key: string]: LightScene; } = {};
43
- private _update?: () => void;
44
-
45
- // #endregion Properties (7)
46
-
47
- // #region Constructors (1)
48
-
49
- constructor(private readonly _renderingEngine: IRenderingEngine) {
50
- this._tree.root.addChild(this._lightNode);
51
- this._lightNode.restrictViewports = [this._renderingEngine.id];
52
- }
53
-
54
- // #endregion Constructors (1)
55
-
56
- // #region Public Getters And Setters (4)
57
-
58
- public get lightScene(): LightScene | null {
59
- return this._lightScene;
60
- }
61
-
62
- public get lightScenes(): {
63
- [key: string]: LightScene
64
- } {
65
- return this._lightScenes;
66
- }
67
-
68
- public get update(): (() => void) | undefined {
69
- return this._update;
70
- }
71
-
72
- public set update(value: (() => void) | undefined) {
73
- this._update = value;
74
- }
75
-
76
- // #endregion Public Getters And Setters (4)
77
-
78
- // #region Public Methods (6)
79
-
80
- public applySettings(settingsEngine: SettingsEngine): void {
81
- this._lightScenes = {};
82
-
83
- for (const lightSceneId in settingsEngine.light.lightScenes) {
84
- const lightSceneUUID = this._uuidGenerator.validate(lightSceneId) ? lightSceneId : this._uuidGenerator.create();
85
- const lightSceneName = settingsEngine.light.lightScenes[lightSceneId].name ? settingsEngine.light.lightScenes[lightSceneId].name : lightSceneId;
86
- const ls = new LightScene(this._renderingEngine, { id: lightSceneUUID, name: lightSceneName });
87
- for (const lightId in settingsEngine.light.lightScenes[lightSceneId].lights) {
88
- const lightUUID = this._uuidGenerator.validate(lightId) ? lightId : this._uuidGenerator.create();
89
- const light = settingsEngine.light.lightScenes[lightSceneId].lights[lightId];
90
- let l: AbstractLight;
91
- switch (light.type) {
92
- case LIGHT_TYPE.DIRECTIONAL:
93
- l = new DirectionalLight({
94
- color: this._converter.toHexColor((<IDirectionalLightProperties>light.properties).color),
95
- intensity: (<IDirectionalLightProperties>light.properties).intensity,
96
- direction: this._converter.toVec3((<IDirectionalLightProperties>light.properties).direction),
97
- castShadow: (<IDirectionalLightProperties>light.properties).castShadow,
98
- name: light.name ? light.name : lightId,
99
- order: light.order,
100
- id: lightUUID
101
- });
102
- break;
103
- case LIGHT_TYPE.HEMISPHERE:
104
- l = new HemisphereLight({
105
- color: this._converter.toHexColor((<IHemisphereLightProperties>light.properties).skyColor),
106
- intensity: (<IHemisphereLightProperties>light.properties).intensity,
107
- groundColor: this._converter.toHexColor((<IHemisphereLightProperties>light.properties).groundColor),
108
- name: light.name ? light.name : lightId,
109
- order: light.order,
110
- id: lightUUID
111
- });
112
- break;
113
- case LIGHT_TYPE.POINT:
114
- l = new PointLight({
115
- color: this._converter.toHexColor((<IPointLightProperties>light.properties).color),
116
- intensity: (<IPointLightProperties>light.properties).intensity,
117
- position: this._converter.toVec3((<IPointLightProperties>light.properties).position),
118
- distance: (<IPointLightProperties>light.properties).distance,
119
- decay: (<IPointLightProperties>light.properties).decay,
120
- name: light.name ? light.name : lightId,
121
- order: light.order,
122
- id: lightUUID
123
- });
124
- break;
125
- case LIGHT_TYPE.SPOT:
126
- l = new SpotLight({
127
- color: this._converter.toHexColor((<ISpotLightProperties>light.properties).color),
128
- intensity: (<ISpotLightProperties>light.properties).intensity,
129
- position: this._converter.toVec3((<ISpotLightProperties>light.properties).position),
130
- target: this._converter.toVec3((<ISpotLightProperties>light.properties).target),
131
- distance: (<ISpotLightProperties>light.properties).distance,
132
- decay: (<ISpotLightProperties>light.properties).decay,
133
- angle: (<ISpotLightProperties>light.properties).angle,
134
- penumbra: (<ISpotLightProperties>light.properties).penumbra,
135
- name: light.name ? light.name : lightId,
136
- order: light.order,
137
- id: lightUUID
138
- });
139
- break;
140
- case LIGHT_TYPE.AMBIENT:
141
- default:
142
- l = new AmbientLight({
143
- color: this._converter.toHexColor((<IAmbientLightProperties>light.properties).color),
144
- intensity: (<IAmbientLightProperties>light.properties).intensity,
145
- name: light.name ? light.name : lightId,
146
- order: light.order,
147
- id: lightUUID
148
- });
149
- }
150
- ls.addLight(l);
151
- }
152
- this._lightScenes[ls.id] = ls;
153
- }
154
-
155
- // there is a light scene but no id is saved (old viewer)
156
- if (settingsEngine.light.lightSceneId === undefined && Object.values(settingsEngine.light.lightScenes).length > 0) {
157
- const res = this.assignLightScene(Object.keys(settingsEngine.light.lightScenes)[0]);
158
- if (res === false) {
159
- const ls = <LightScene>this.createLightScene({ name: settingsEngine.light.lightSceneId === 'default' ? 'default' : 'standard' });
160
- ls.addLight(new AmbientLight({ color: '#ffffff', intensity: 0.5, name: 'ambient0' }));
161
- ls.addLight(new DirectionalLight({ color: '#ffffff', intensity: 0.75, direction: vec3.fromValues(.5774, -.5774, .5774), castShadow: true, name: 'directional0' }));
162
- ls.addLight(new DirectionalLight({ color: '#ffffff', intensity: 0.35, direction: vec3.fromValues(.25, -1, 1), castShadow: false, name: 'directional1' }));
163
- this._lightScenes[ls.id] = ls;
164
- }
165
- } // there is no standard light scene in the light scenes, but a light scene name is specified (old viewer)
166
- else if (settingsEngine.light.lightSceneId) {
167
- const res = this.assignLightScene(settingsEngine.light.lightSceneId);
168
- if (res === false) {
169
- const ls = <LightScene>this.createLightScene({ name: settingsEngine.light.lightSceneId === 'default' ? 'default' : 'standard' });
170
- ls.addLight(new AmbientLight({ color: '#ffffff', intensity: 0.5, name: 'ambient0' }));
171
- ls.addLight(new DirectionalLight({ color: '#ffffff', intensity: 0.75, direction: vec3.fromValues(.5774, -.5774, .5774), castShadow: true, name: 'directional0' }));
172
- ls.addLight(new DirectionalLight({ color: '#ffffff', intensity: 0.35, direction: vec3.fromValues(.25, -1, 1), castShadow: false, name: 'directional1' }));
173
- this._lightScenes[ls.id] = ls;
174
- }
175
- }
176
- // this can only be the case if the settings were completely empty, therefore we assign the new light scene
177
- else if (JSON.stringify(settingsEngine.settingsJson) == JSON.stringify({})) {
178
- const ls = <LightScene>this.createLightScene({ name: 'standard', standard: true });
179
- this._lightScenes[ls.id] = ls;
180
- }
181
-
182
- if (this._update) this._update();
183
- }
184
-
185
- public assignLightScene(id: string): boolean {
186
- if (!this._lightScenes[id]) {
187
- for (const lightSceneId in this._lightScenes) {
188
- const lightScene = this._lightScenes[lightSceneId];
189
- const lightSceneName = lightScene.name || lightSceneId;
190
- if (lightSceneName === id) {
191
- const res = this.assignLightScene(lightSceneId);
192
- return res;
193
- }
194
- }
195
- return false;
196
- }
197
- this._lightScene = this._lightScenes[id];
198
- while (this._lightNode.children.length > 0)
199
- this._lightNode.removeChild(this._lightNode.children[0]);
200
- this._lightNode.addChild(this._lightScene!.node);
201
- this._lightNode.updateVersion();
202
-
203
- return true;
204
- }
205
-
206
- public close(): void {
207
- this._tree.root.removeChild(this._lightNode);
208
- }
209
-
210
- public createLightScene(properties: { name?: string, standard?: boolean }): ILightScene {
211
- const lightSceneId = this._uuidGenerator.create();
212
- const lightScene = new LightScene(this._renderingEngine, { id: lightSceneId, name: properties.name });
213
- if (properties.standard === true) {
214
- lightScene.addLight(new DirectionalLight({ color: '#ffffff', intensity: 2.5, direction: vec3.fromValues(.5774, -.5774, .5774), castShadow: true, name: 'directional0' }));
215
- lightScene.addLight(new AmbientLight({ color: '#ffffff', intensity: 0.3, name: 'ambient0' }));
216
- }
217
- this._lightScenes[lightSceneId] = lightScene;
218
- this._lightScene = lightScene;
219
- while (this._lightNode.children.length > 0)
220
- this._lightNode.removeChild(this._lightNode.children[0]);
221
- this._lightNode.addChild(this._lightScene!.node);
222
- this._lightNode.updateVersion();
223
-
224
- if (this._update) this._update();
225
- return lightScene;
226
- }
227
-
228
- public removeLightScene(id: string): boolean {
229
- if (!this._lightScenes[id]) {
230
- for (const lightSceneId in this._lightScenes) {
231
- const lightScene = this._lightScenes[lightSceneId];
232
- const lightSceneName = lightScene.name || lightSceneId;
233
- if (lightSceneName === id) {
234
- const res = this.removeLightScene(lightSceneId);
235
- return res;
236
- }
237
- }
238
- return false;
239
- }
240
-
241
- if (this._lightScene && this._lightScene.id === id) {
242
- (<any>this._lightScene) = undefined;
243
-
244
- while (this._lightNode.children.length > 0)
245
- this._lightNode.removeChild(this._lightNode.children[0]);
246
- this._lightNode.updateVersion();
247
- }
248
- delete this._lightScenes[id];
249
-
250
- if (this._update) this._update();
251
- return true;
252
- }
253
-
254
- public saveSettings(settingsEngine: SettingsEngine) {
255
- settingsEngine.light.lightSceneId = this.lightScene ? this.lightScene.id : undefined;
256
-
257
- const converted: ILightSceneSettings = {};
258
- for (const lightSceneId in this._lightScenes) {
259
- const lightScene = this._lightScenes[lightSceneId];
260
- const lightSceneName = lightScene.name || lightSceneId;
261
- converted[lightSceneId] = {
262
- name: lightSceneName,
263
- lights: {}
264
- };
265
- for (const lightId in lightScene.lights) {
266
- const light = lightScene.lights[lightId];
267
-
268
- let properties;
269
- switch (light.type) {
270
- case LIGHT_TYPE.DIRECTIONAL:
271
- properties = {
272
- color: this._converter.toHexColor(light.color),
273
- intensity: light.intensity,
274
- direction: { x: (<DirectionalLight>light).direction[0], y: (<DirectionalLight>light).direction[1], z: (<DirectionalLight>light).direction[2] },
275
- castShadow: (<DirectionalLight>light).castShadow,
276
- shadowMapResolution: (<DirectionalLight>light).shadowMapResolution,
277
- shadowMapBias: (<DirectionalLight>light).shadowMapBias
278
- };
279
- break;
280
- case LIGHT_TYPE.HEMISPHERE:
281
- properties = {
282
- skyColor: this._converter.toHexColor(light.color),
283
- intensity: light.intensity,
284
- groundColor: this._converter.toHexColor((<HemisphereLight>light).groundColor)
285
- };
286
- break;
287
- case LIGHT_TYPE.POINT:
288
- properties = {
289
- color: this._converter.toHexColor(light.color),
290
- intensity: light.intensity,
291
- position: { x: (<PointLight>light).position[0], y: (<PointLight>light).position[1], z: (<PointLight>light).position[2] },
292
- distance: (<PointLight>light).distance,
293
- decay: (<PointLight>light).decay
294
- };
295
- break;
296
- case LIGHT_TYPE.SPOT:
297
- properties = {
298
- color: this._converter.toHexColor(light.color),
299
- intensity: light.intensity,
300
- position: { x: (<SpotLight>light).position[0], y: (<SpotLight>light).position[1], z: (<SpotLight>light).position[2] },
301
- target: { x: (<SpotLight>light).target[0], y: (<SpotLight>light).target[1], z: (<SpotLight>light).target[2] },
302
- distance: (<SpotLight>light).distance,
303
- decay: (<SpotLight>light).decay,
304
- angle: (<SpotLight>light).angle,
305
- penumbra: (<SpotLight>light).penumbra
306
- };
307
- break;
308
- case LIGHT_TYPE.AMBIENT:
309
- default:
310
- properties = {
311
- color: this._converter.toHexColor(light.color),
312
- intensity: light.intensity
313
- };
314
- }
315
- converted[lightSceneId].lights[lightId] = {
316
- name: light.name,
317
- type: light.type,
318
- properties
319
- };
320
- if (light.order !== undefined)
321
- converted[lightSceneId].lights[lightId].order = light.order;
322
- }
323
- }
324
- settingsEngine.light.lightScenes = converted;
325
- }
326
-
327
- // #endregion Public Methods (6)
328
- }
@@ -1,130 +0,0 @@
1
- import { IRenderingEngine } from '@shapediver/viewer.rendering-engine.rendering-engine';
2
- import { ITreeNode, TreeNode } from '@shapediver/viewer.shared.node-tree'
3
- import { vec3 } from 'gl-matrix';
4
- import { Color } from '@shapediver/viewer.shared.types';
5
-
6
- import { ILight } from '../interface/ILight'
7
- import { ILightScene } from '../interface/ILightScene'
8
- import { AbstractLight } from './AbstractLight'
9
- import { AmbientLight } from './types/AmbientLight';
10
- import { DirectionalLight } from './types/DirectionalLight';
11
- import { HemisphereLight } from './types/HemisphereLight';
12
- import { PointLight } from './types/PointLight';
13
- import { SpotLight } from './types/SpotLight';
14
-
15
- export class LightScene implements ILightScene {
16
- // #region Properties (5)
17
-
18
- private readonly _id: string;
19
- private readonly _lights: { [key: string]: ILight; } = {};
20
- private readonly _node: ITreeNode;
21
-
22
- private _name: string | undefined;
23
- private _update?: () => void;
24
-
25
- // #endregion Properties (5)
26
-
27
- // #region Constructors (1)
28
-
29
- constructor(private readonly _renderingEngine: IRenderingEngine, properties: {id: string, name?: string}) {
30
- this._id = properties.id;
31
- this._name = properties.name;
32
- this._node = new TreeNode(properties.name || properties.id);
33
- }
34
-
35
- // #endregion Constructors (1)
36
-
37
- // #region Public Accessors (5)
38
-
39
- public get id(): string {
40
- return this._id;
41
- }
42
-
43
- public get lights(): { [key: string]: AbstractLight; } {
44
- return <{ [key: string]: AbstractLight; }>this._lights
45
- }
46
-
47
- public get name(): string | undefined {
48
- return this._name;
49
- }
50
-
51
- public set name(value: string | undefined) {
52
- this._name = value;
53
- }
54
-
55
- public get node(): ITreeNode {
56
- return this._node;
57
- }
58
-
59
- public get update(): (() => void) | undefined {
60
- return this._update;
61
- }
62
-
63
- public set update(value: (() => void) | undefined) {
64
- this._update = value;
65
- }
66
-
67
- // #endregion Public Accessors (5)
68
-
69
- // #region Public Methods (8)
70
-
71
- public addAmbientLight(properties: {color?: Color, intensity?: number, name?: string}): AmbientLight {
72
- const light = new AmbientLight(properties);
73
- this.addLight(light);
74
- return light;
75
- }
76
-
77
- public addDirectionalLight(properties: {color?: Color, intensity?: number, direction?: vec3, castShadow?: boolean, shadowMapResolution?: number, shadowMapBias?: number, name?: string}): DirectionalLight {
78
- const light = new DirectionalLight(properties);
79
- this.addLight(light);
80
- return light;
81
- }
82
-
83
- public addHemisphereLight(properties: {color?: Color, intensity?: number, groundColor?: Color, name?: string}): HemisphereLight {
84
- const light = new HemisphereLight(properties);
85
- this.addLight(light);
86
- return light;
87
- }
88
-
89
- public addLight(light: AbstractLight): void {
90
- const node = new TreeNode(light.id);
91
- light.parentNode = node;
92
- node.data.push(light);
93
- this._node.addChild(node)
94
- this._lights[light.id] = light;
95
-
96
- this._node.updateVersion();
97
- if(this._update) this._update();
98
- }
99
-
100
- public addPointLight(properties: {color?: Color, intensity?: number, position?: vec3, distance?: number, decay?: number, name?: string}): PointLight {
101
- const light = new PointLight(properties);
102
- this.addLight(light);
103
- return light;
104
- }
105
-
106
- public addSpotLight(properties: {color?: Color, intensity?: number, position?: vec3, target?: vec3, distance?: number, decay?: number, angle?: number, penumbra?: number, name?: string}): SpotLight {
107
- const light = new SpotLight(properties);
108
- this.addLight(light);
109
- return light;
110
- }
111
-
112
- public removeLight(id: string): boolean {
113
- if (!this._lights[id]) return false;
114
-
115
- for(let i = 0; i < this._node.children.length; i++) {
116
- const node = this._node.children[i];
117
- if(node && node.name === id) {
118
- this._node.removeChild(node);
119
- break;
120
- }
121
- }
122
-
123
- delete this._lights[id];
124
- this._node.updateVersion();
125
- if(this._update) this._update();
126
- return true;
127
- }
128
-
129
- // #endregion Public Methods (8)
130
- }
@@ -1,44 +0,0 @@
1
- import { AbstractLight } from '../AbstractLight';
2
- import { Color } from '@shapediver/viewer.shared.types';
3
- import { IAmbientLight } from '../../interface/types/IAmbientLight';
4
- import { LIGHT_TYPE } from '../../interface/ILight';
5
-
6
- export class AmbientLight extends AbstractLight implements IAmbientLight {
7
- // #region Constructors (1)
8
-
9
- constructor(properties: {
10
- color?: Color,
11
- intensity?: number,
12
- name?: string,
13
- order?: number,
14
- id?: string,
15
- version?: string
16
- }) {
17
- super({
18
- color: properties.color || '#ffffff',
19
- intensity: properties.intensity !== undefined ? properties.intensity : 1,
20
- type: LIGHT_TYPE.AMBIENT,
21
- name: properties.name,
22
- order: properties.order,
23
- id: properties.id,
24
- version: properties.version
25
- });
26
- }
27
-
28
- // #endregion Constructors (1)
29
-
30
- // #region Public Methods (1)
31
-
32
- public clone(): IAmbientLight {
33
- return new AmbientLight({
34
- color: this.color || '#ffffff',
35
- intensity: this.intensity || 0.5,
36
- name: this.name,
37
- order: this.order,
38
- id: this.id,
39
- version: this.version
40
- });
41
- }
42
-
43
- // #endregion Public Methods (1)
44
- }
@@ -1,111 +0,0 @@
1
- import { AbstractLight } from '../AbstractLight';
2
- import { Color } from '@shapediver/viewer.shared.types';
3
- import { IDirectionalLight } from '../../interface/types/IDirectionalLight';
4
- import { LIGHT_TYPE } from '../../interface/ILight';
5
- import { vec3 } from 'gl-matrix';
6
-
7
- export class DirectionalLight extends AbstractLight implements IDirectionalLight {
8
- // #region Properties (4)
9
-
10
- #castShadow: boolean = true;
11
- #direction: vec3 = vec3.fromValues(-1, 0, 1);
12
- #shadowMapBias: number = -0.003;
13
- #shadowMapResolution: number = 1024;
14
-
15
- // #endregion Properties (4)
16
-
17
- // #region Constructors (1)
18
-
19
- constructor(properties: {
20
- color?: Color,
21
- intensity?: number,
22
- direction?: vec3,
23
- castShadow?: boolean,
24
- shadowMapResolution?: number,
25
- shadowMapBias?: number,
26
- name?: string,
27
- order?: number,
28
- id?: string,
29
- version?: string
30
- }) {
31
- super({
32
- color: properties.color || '#ffffff',
33
- intensity: properties.intensity !== undefined ? properties.intensity : 1,
34
- type: LIGHT_TYPE.DIRECTIONAL,
35
- name: properties.name,
36
- order: properties.order,
37
- id: properties.id,
38
- version: properties.version
39
- });
40
-
41
- if (properties.direction) this.#direction = properties.direction;
42
- if (properties.castShadow !== undefined) this.#castShadow = properties.castShadow;
43
- if (properties.shadowMapResolution) this.#shadowMapResolution = properties.shadowMapResolution;
44
- if (properties.shadowMapBias) this.#shadowMapBias = properties.shadowMapBias;
45
- }
46
-
47
- // #endregion Constructors (1)
48
-
49
- // #region Public Getters And Setters (8)
50
-
51
- public get castShadow(): boolean {
52
- return this.#castShadow;
53
- }
54
-
55
- public set castShadow(value: boolean) {
56
- this.#castShadow = value;
57
- this.updateVersion();
58
- if (this.parentNode) this.parentNode.updateVersion();
59
- }
60
-
61
- public get direction(): vec3 {
62
- return this.#direction;
63
- }
64
-
65
- public set direction(value: vec3) {
66
- this.#direction = value;
67
- this.updateVersion();
68
- if (this.parentNode) this.parentNode.updateVersion();
69
- }
70
-
71
- public get shadowMapBias(): number {
72
- return this.#shadowMapBias;
73
- }
74
-
75
- public set shadowMapBias(value: number) {
76
- this.#shadowMapBias = value;
77
- this.updateVersion();
78
- if (this.parentNode) this.parentNode.updateVersion();
79
- }
80
-
81
- public get shadowMapResolution(): number {
82
- return this.#shadowMapResolution;
83
- }
84
-
85
- public set shadowMapResolution(value: number) {
86
- this.#shadowMapResolution = value;
87
- this.updateVersion();
88
- if (this.parentNode) this.parentNode.updateVersion();
89
- }
90
-
91
- // #endregion Public Getters And Setters (8)
92
-
93
- // #region Public Methods (1)
94
-
95
- public clone(): IDirectionalLight {
96
- return new DirectionalLight({
97
- color: this.color,
98
- intensity: this.intensity,
99
- direction: this.direction,
100
- castShadow: this.castShadow,
101
- shadowMapResolution: this.shadowMapResolution,
102
- shadowMapBias: this.shadowMapBias,
103
- name: this.name,
104
- order: this.order,
105
- id: this.id,
106
- version: this.version
107
- });
108
- }
109
-
110
- // #endregion Public Methods (1)
111
- }
@@ -1,68 +0,0 @@
1
- import { AbstractLight } from '../AbstractLight';
2
- import { Color } from '@shapediver/viewer.shared.types';
3
- import { IHemisphereLight } from '../../interface/types/IHemisphereLight';
4
- import { LIGHT_TYPE } from '../../interface/ILight';
5
-
6
- export class HemisphereLight extends AbstractLight implements IHemisphereLight {
7
- // #region Properties (1)
8
-
9
- #groundColor: Color = '#000000';
10
-
11
- // #endregion Properties (1)
12
-
13
- // #region Constructors (1)
14
-
15
- constructor(properties: {
16
- color?: Color,
17
- groundColor?: Color,
18
- intensity?: number,
19
- name?: string,
20
- order?: number,
21
- id?: string,
22
- version?: string
23
- }) {
24
- super({
25
- color: properties.color || '#ffffff',
26
- intensity: properties.intensity !== undefined ? properties.intensity : 1,
27
- type: LIGHT_TYPE.HEMISPHERE,
28
- name: properties.name,
29
- order: properties.order,
30
- id: properties.id,
31
- version: properties.version
32
- });
33
-
34
- if (properties.groundColor) this.#groundColor = properties.groundColor;
35
- }
36
-
37
- // #endregion Constructors (1)
38
-
39
- // #region Public Getters And Setters (2)
40
-
41
- public get groundColor(): Color {
42
- return this.#groundColor;
43
- }
44
-
45
- public set groundColor(value: Color) {
46
- this.#groundColor = value;
47
- this.updateVersion();
48
- if (this.parentNode) this.parentNode.updateVersion();
49
- }
50
-
51
- // #endregion Public Getters And Setters (2)
52
-
53
- // #region Public Methods (1)
54
-
55
- public clone(): IHemisphereLight {
56
- return new HemisphereLight({
57
- color: this.color,
58
- groundColor: this.groundColor,
59
- intensity: this.intensity,
60
- name: this.name,
61
- order: this.order,
62
- id: this.id,
63
- version: this.version
64
- });
65
- }
66
-
67
- // #endregion Public Methods (1)
68
- }
@@ -1,96 +0,0 @@
1
- import { AbstractLight } from '../AbstractLight';
2
- import { Color } from '@shapediver/viewer.shared.types';
3
- import { IPointLight } from '../../interface/types/IPointLight';
4
- import { LIGHT_TYPE } from '../../interface/ILight';
5
- import { vec3 } from 'gl-matrix';
6
-
7
- export class PointLight extends AbstractLight implements IPointLight {
8
- // #region Properties (3)
9
-
10
- #decay: number = 0;
11
- #distance: number = 0;
12
- #position: vec3 = vec3.fromValues(0, 0, 0);
13
-
14
- // #endregion Properties (3)
15
-
16
- // #region Constructors (1)
17
-
18
- constructor(properties: {
19
- color?: Color,
20
- intensity?: number,
21
- position?: vec3,
22
- distance?: number,
23
- decay?: number,
24
- name?: string,
25
- order?: number,
26
- id?: string,
27
- version?: string
28
- }) {
29
- super({
30
- color: properties.color || '#ffffff',
31
- intensity: properties.intensity !== undefined ? properties.intensity : 1,
32
- type: LIGHT_TYPE.POINT,
33
- name: properties.name,
34
- order: properties.order,
35
- id: properties.id,
36
- version: properties.version
37
- });
38
- if (properties.position) this.#position = properties.position;
39
- if (properties.distance) this.#distance = properties.distance;
40
- if (properties.decay) this.#decay = properties.decay;
41
- }
42
-
43
- // #endregion Constructors (1)
44
-
45
- // #region Public Getters And Setters (6)
46
-
47
- public get decay(): number {
48
- return this.#decay;
49
- }
50
-
51
- public set decay(value: number) {
52
- this.#decay = value;
53
- this.updateVersion();
54
- if (this.parentNode) this.parentNode.updateVersion();
55
- }
56
-
57
- public get distance(): number {
58
- return this.#distance;
59
- }
60
-
61
- public set distance(value: number) {
62
- this.#distance = value;
63
- this.updateVersion();
64
- if (this.parentNode) this.parentNode.updateVersion();
65
- }
66
-
67
- public get position(): vec3 {
68
- return this.#position;
69
- }
70
-
71
- public set position(value: vec3) {
72
- this.#position = value;
73
- this.updateVersion();
74
- if (this.parentNode) this.parentNode.updateVersion();
75
- }
76
-
77
- // #endregion Public Getters And Setters (6)
78
-
79
- // #region Public Methods (1)
80
-
81
- public clone(): IPointLight {
82
- return new PointLight({
83
- color: this.color,
84
- position: this.position,
85
- distance: this.distance,
86
- decay: this.decay,
87
- intensity: this.intensity,
88
- name: this.name,
89
- order: this.order,
90
- id: this.id,
91
- version: this.version
92
- });
93
- }
94
-
95
- // #endregion Public Methods (1)
96
- }
@@ -1,138 +0,0 @@
1
- import { AbstractLight } from '../AbstractLight';
2
- import { Color } from '@shapediver/viewer.shared.types';
3
- import { ISpotLight } from '../../interface/types/ISpotLight';
4
- import { LIGHT_TYPE } from '../../interface/ILight';
5
- import { vec3 } from 'gl-matrix';
6
-
7
- export class SpotLight extends AbstractLight implements ISpotLight {
8
- // #region Properties (6)
9
-
10
- #angle: number = Math.PI / 4.0;
11
- #decay: number = 0;
12
- #distance: number = 0;
13
- #penumbra: number = 0.5;
14
- #position: vec3 = vec3.fromValues(-1, 0, 1);
15
- #target: vec3 = vec3.fromValues(0, 0, 0);
16
-
17
- // #endregion Properties (6)
18
-
19
- // #region Constructors (1)
20
-
21
- constructor(properties: {
22
- color?: Color,
23
- intensity?: number,
24
- position?: vec3,
25
- target?: vec3,
26
- distance?: number,
27
- decay?: number,
28
- angle?: number,
29
- penumbra?: number,
30
- name?: string,
31
- order?: number,
32
- id?: string,
33
- version?: string
34
- }) {
35
- super({
36
- color: properties.color || '#ffffff',
37
- intensity: properties.intensity !== undefined ? properties.intensity : 1,
38
- type: LIGHT_TYPE.SPOT,
39
- name: properties.name,
40
- order: properties.order,
41
- id: properties.id,
42
- version: properties.version
43
- });
44
- if (properties.position) this.#position = properties.position;
45
- if (properties.target) this.#target = properties.target;
46
- if (properties.distance) this.#distance = properties.distance;
47
- if (properties.decay) this.#decay = properties.decay;
48
- if (properties.angle) this.#angle = properties.angle;
49
- if (properties.penumbra) this.#penumbra = properties.penumbra;
50
- }
51
-
52
- // #endregion Constructors (1)
53
-
54
- // #region Public Getters And Setters (12)
55
-
56
- public get angle(): number {
57
- return this.#angle;
58
- }
59
-
60
- public set angle(value: number) {
61
- this.#angle = value;
62
- this.updateVersion();
63
- if (this.parentNode) this.parentNode.updateVersion();
64
- }
65
-
66
- public get decay(): number {
67
- return this.#decay;
68
- }
69
-
70
- public set decay(value: number) {
71
- this.#decay = value;
72
- this.updateVersion();
73
- if (this.parentNode) this.parentNode.updateVersion();
74
- }
75
-
76
- public get distance(): number {
77
- return this.#distance;
78
- }
79
-
80
- public set distance(value: number) {
81
- this.#distance = value;
82
- this.updateVersion();
83
- if (this.parentNode) this.parentNode.updateVersion();
84
- }
85
-
86
- public get penumbra(): number {
87
- return this.#penumbra;
88
- }
89
-
90
- public set penumbra(value: number) {
91
- this.#penumbra = value;
92
- this.updateVersion();
93
- if (this.parentNode) this.parentNode.updateVersion();
94
- }
95
-
96
- public get position(): vec3 {
97
- return this.#position;
98
- }
99
-
100
- public set position(value: vec3) {
101
- this.#position = value;
102
- this.updateVersion();
103
- if (this.parentNode) this.parentNode.updateVersion();
104
- }
105
-
106
- public get target(): vec3 {
107
- return this.#target;
108
- }
109
-
110
- public set target(value: vec3) {
111
- this.#target = value;
112
- this.updateVersion();
113
- if (this.parentNode) this.parentNode.updateVersion();
114
- }
115
-
116
- // #endregion Public Getters And Setters (12)
117
-
118
- // #region Public Methods (1)
119
-
120
- public clone(): ISpotLight {
121
- return new SpotLight({
122
- color: this.color,
123
- position: this.position,
124
- target: this.target,
125
- distance: this.distance,
126
- decay: this.decay,
127
- angle: this.angle,
128
- penumbra: this.penumbra,
129
- intensity: this.intensity,
130
- name: this.name,
131
- order: this.order,
132
- id: this.id,
133
- version: this.version
134
- });
135
- }
136
-
137
- // #endregion Public Methods (1)
138
- }
package/src/index.ts DELETED
@@ -1,28 +0,0 @@
1
- import { AbstractLight } from './implementation/AbstractLight'
2
- import { LightEngine } from './implementation/LightEngine'
3
- import { LightScene } from './implementation/LightScene'
4
- import { AmbientLight } from './implementation/types/AmbientLight'
5
- import { DirectionalLight } from './implementation/types/DirectionalLight'
6
- import { HemisphereLight } from './implementation/types/HemisphereLight'
7
- import { PointLight } from './implementation/types/PointLight'
8
- import { SpotLight } from './implementation/types/SpotLight'
9
- import { ILight, LIGHT_TYPE } from './interface/ILight'
10
- import { ILightEngine } from './interface/ILightEngine'
11
- import { ILightScene } from './interface/ILightScene'
12
- import { IAmbientLight } from './interface/types/IAmbientLight'
13
- import { IDirectionalLight } from './interface/types/IDirectionalLight'
14
- import { IHemisphereLight } from './interface/types/IHemisphereLight'
15
- import { IPointLight } from './interface/types/IPointLight'
16
- import { ISpotLight } from './interface/types/ISpotLight'
17
-
18
- export {
19
- ILightEngine, LightEngine, LIGHT_TYPE, ILightScene, LightScene, ILight
20
- }
21
-
22
- export {
23
- IAmbientLight, IDirectionalLight, IHemisphereLight, IPointLight, ISpotLight
24
- }
25
-
26
- export {
27
- AbstractLight, AmbientLight, DirectionalLight, HemisphereLight, PointLight, SpotLight
28
- }
@@ -1,24 +0,0 @@
1
- import { ITreeNodeData } from '@shapediver/viewer.shared.node-tree'
2
- import { Color } from '@shapediver/viewer.shared.types'
3
-
4
- export enum LIGHT_TYPE {
5
- AMBIENT = 'ambient',
6
- DIRECTIONAL = 'directional',
7
- HEMISPHERE = 'hemisphere',
8
- POINT = 'point',
9
- RECTANGLE = 'rectangle',
10
- SPOT = 'spot'
11
- }
12
-
13
- export interface ILight extends ITreeNodeData {
14
- // #region Properties (5)
15
-
16
- id: string;
17
- color: Color,
18
- intensity: number,
19
- name?: string
20
- order?: number
21
- type: LIGHT_TYPE,
22
-
23
- // #endregion Properties (5)
24
- }
@@ -1,17 +0,0 @@
1
- import { ILightScene } from './ILightScene'
2
-
3
- export interface ILightEngine {
4
- // #region Properties (1)
5
-
6
- update?: () => void;
7
-
8
- // #endregion Properties (1)
9
-
10
- // #region Public Methods (3)
11
-
12
- assignLightScene(id: string): boolean;
13
- createLightScene(properties: {name?: string, id?: string, standard?: boolean}): ILightScene;
14
- removeLightScene(id: string): boolean;
15
-
16
- // #endregion Public Methods (3)
17
- }
@@ -1,28 +0,0 @@
1
- import { ITreeNode, TreeNode } from '@shapediver/viewer.shared.node-tree'
2
- import { vec3 } from 'gl-matrix'
3
- import { Color } from '@shapediver/viewer.shared.types'
4
-
5
- import { ILight } from './ILight'
6
-
7
- export interface ILightScene {
8
- // #region Properties (4)
9
-
10
- id: string;
11
- lights: { [key: string]: ILight; };
12
- name?: string
13
- node: ITreeNode;
14
- update?: () => void;
15
-
16
- // #endregion Properties (4)
17
-
18
- // #region Public Methods (6)
19
-
20
- addAmbientLight(properties: {color?: Color, intensity?: number, id?: string, name?: string}): ILight;
21
- addDirectionalLight(properties: {color?: Color, intensity?: number, direction?: vec3, castShadow?: boolean, shadowMapResolution?: number, shadowMapBias?: number, id?: string, name?: string}): ILight;
22
- addHemisphereLight(properties: {color?: Color, intensity?: number, groundColor?: Color, id?: string, name?: string}): ILight;
23
- addPointLight(properties: {color?: Color, intensity?: number, position?: vec3, distance?: number, decay?: number, id?: string, name?: string}): ILight;
24
- addSpotLight(properties: {color?: Color, intensity?: number, position?: vec3, target?: vec3, distance?: number, decay?: number, angle?: number, penumbra?: number, id?: string, name?: string}): ILight;
25
- removeLight(id: string): boolean;
26
-
27
- // #endregion Public Methods (6)
28
- }
@@ -1,5 +0,0 @@
1
- import { ILight } from '../ILight'
2
-
3
- export interface IAmbientLight extends ILight {
4
- clone(): IAmbientLight;
5
- }
@@ -1,12 +0,0 @@
1
- import { vec3 } from 'gl-matrix'
2
-
3
- import { ILight } from '../ILight'
4
-
5
- export interface IDirectionalLight extends ILight {
6
- castShadow: boolean;
7
- direction: vec3;
8
- shadowMapBias: number;
9
- shadowMapResolution: number;
10
-
11
- clone(): IDirectionalLight;
12
- }
@@ -1,9 +0,0 @@
1
- import { Color } from '@shapediver/viewer.shared.types'
2
-
3
- import { ILight } from '../ILight'
4
-
5
- export interface IHemisphereLight extends ILight {
6
- groundColor: Color;
7
-
8
- clone(): IHemisphereLight;
9
- }
@@ -1,11 +0,0 @@
1
- import { vec3 } from 'gl-matrix'
2
-
3
- import { ILight } from '../ILight'
4
-
5
- export interface IPointLight extends ILight {
6
- decay: number;
7
- distance: number;
8
- position: vec3;
9
-
10
- clone(): IPointLight;
11
- }
@@ -1,14 +0,0 @@
1
- import { vec3 } from 'gl-matrix'
2
-
3
- import { ILight } from '../ILight'
4
-
5
- export interface ISpotLight extends ILight {
6
- angle: number;
7
- decay: number;
8
- distance: number;
9
- penumbra: number;
10
- position: vec3;
11
- target: vec3;
12
-
13
- clone(): ISpotLight;
14
- }
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "include": [
4
- "./**/*.ts"
5
- ],
6
- "compilerOptions": {
7
- "rootDir": "src",
8
- "outDir": "dist"
9
- },
10
- "exclude": [
11
- "__tests__",
12
- "node_modules",
13
- "dist",
14
- "dist-dev",
15
- "dist-prod"
16
- ]
17
- }