bg2e-js 2.0.1 → 2.0.2

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.
Files changed (135) hide show
  1. package/dist/bg2e-js.js +11001 -0
  2. package/dist/bg2e-js.js.map +1 -0
  3. package/package.json +17 -6
  4. package/app/AppController.d.ts +0 -37
  5. package/app/AppController.js +0 -32
  6. package/app/Canvas.d.ts +0 -42
  7. package/app/Canvas.js +0 -98
  8. package/app/EventBase.js +0 -8
  9. package/app/KeyboardEvent.js +0 -51
  10. package/app/MainLoop.d.ts +0 -245
  11. package/app/MainLoop.js +0 -251
  12. package/app/MouseEvent.js +0 -77
  13. package/app/TouchEvent.js +0 -15
  14. package/base/Color.js +0 -131
  15. package/base/Environment.js +0 -78
  16. package/base/Light.js +0 -176
  17. package/base/Material.js +0 -619
  18. package/base/PolyList.js +0 -336
  19. package/base/Texture.js +0 -545
  20. package/db/Bg2LoaderPlugin.js +0 -113
  21. package/db/DBPluginApi.js +0 -40
  22. package/db/Loader.js +0 -91
  23. package/db/LoaderPlugin.js +0 -26
  24. package/db/MtlParser.js +0 -7
  25. package/db/ObjLoaderPlugin.js +0 -51
  26. package/db/ObjParser.js +0 -233
  27. package/db/ObjWriterPlugin.js +0 -18
  28. package/db/VitscnjLoaderPlugin.js +0 -87
  29. package/db/Writer.js +0 -49
  30. package/db/WriterPlugin.js +0 -20
  31. package/debug/DebugRenderer.js +0 -138
  32. package/debug/WebGLTextureViewer.js +0 -67
  33. package/manipulation/SelectionBuffer.js +0 -65
  34. package/manipulation/SelectionHighlight.js +0 -69
  35. package/manipulation/SelectionIdAssignVisitor.js +0 -86
  36. package/manipulation/SelectionManager.js +0 -134
  37. package/manipulation/SelectionMode.js +0 -6
  38. package/math/Mat3.js +0 -248
  39. package/math/Mat4.js +0 -694
  40. package/math/MatrixStrategy.js +0 -23
  41. package/math/Quat.js +0 -60
  42. package/math/Vec.js +0 -728
  43. package/math/constants.js +0 -44
  44. package/math/functions.js +0 -104
  45. package/math/index.js +0 -74
  46. package/phsics/joint.js +0 -124
  47. package/primitives/arrow.js +0 -58
  48. package/primitives/cone.js +0 -137
  49. package/primitives/cube.js +0 -59
  50. package/primitives/cylinder.js +0 -215
  51. package/primitives/index.js +0 -13
  52. package/primitives/plane.js +0 -31
  53. package/primitives/sphere.js +0 -808
  54. package/render/BRDFIntegrationMap.js +0 -4
  55. package/render/Environment.js +0 -105
  56. package/render/EnvironmentRenderer.js +0 -12
  57. package/render/FrameBuffer.js +0 -26
  58. package/render/MaterialRenderer.js +0 -28
  59. package/render/Pipeline.js +0 -83
  60. package/render/PolyListRenderer.js +0 -42
  61. package/render/RenderBuffer.js +0 -189
  62. package/render/RenderQueue.js +0 -162
  63. package/render/RenderState.js +0 -82
  64. package/render/Renderer.js +0 -202
  65. package/render/SceneAppController.js +0 -208
  66. package/render/SceneRenderer.js +0 -310
  67. package/render/Shader.js +0 -21
  68. package/render/ShadowRenderer.js +0 -159
  69. package/render/SkyCube.js +0 -77
  70. package/render/SkySphere.js +0 -94
  71. package/render/TextureMergerRenderer.js +0 -58
  72. package/render/TextureRenderer.js +0 -29
  73. package/render/webgl/FrameBuffer.js +0 -9
  74. package/render/webgl/MaterialRenderer.js +0 -99
  75. package/render/webgl/Pipeline.js +0 -82
  76. package/render/webgl/PolyListRenderer.js +0 -224
  77. package/render/webgl/RenderBuffer.js +0 -244
  78. package/render/webgl/Renderer.js +0 -239
  79. package/render/webgl/SceneRenderer.js +0 -43
  80. package/render/webgl/ShaderProgram.js +0 -350
  81. package/render/webgl/ShadowRenderer.js +0 -6
  82. package/render/webgl/SkyCube.js +0 -15
  83. package/render/webgl/SkySphere.js +0 -14
  84. package/render/webgl/State.js +0 -149
  85. package/render/webgl/TextureRenderer.js +0 -167
  86. package/render/webgl/VertexBuffer.js +0 -128
  87. package/scene/Camera.js +0 -378
  88. package/scene/Chain.js +0 -43
  89. package/scene/ChainJoint.js +0 -55
  90. package/scene/Component.js +0 -146
  91. package/scene/ComponentMap.js +0 -99
  92. package/scene/Drawable.js +0 -130
  93. package/scene/EnvironmentComponent.js +0 -123
  94. package/scene/FindNodeVisitor.js +0 -55
  95. package/scene/LightComponent.js +0 -146
  96. package/scene/MatrixState.js +0 -39
  97. package/scene/Node.js +0 -300
  98. package/scene/NodeVisitor.js +0 -12
  99. package/scene/OrbitCameraController.js +0 -407
  100. package/scene/SmoothOrbitCameraController.js +0 -92
  101. package/scene/Transform.js +0 -74
  102. package/scene/index.js +0 -24
  103. package/shaders/BasicDiffuseColorShader.js +0 -91
  104. package/shaders/BasicPBRLightShader.js +0 -238
  105. package/shaders/DebugRenderShader.js +0 -79
  106. package/shaders/DepthRenderShader.js +0 -69
  107. package/shaders/IrradianceMapCubeShader.js +0 -99
  108. package/shaders/PBRLightIBLShader.js +0 -380
  109. package/shaders/PickSelectionShader.js +0 -75
  110. package/shaders/PresentDebugFramebufferShader.js +0 -90
  111. package/shaders/PresentTextureShader.js +0 -73
  112. package/shaders/SelectionHighlightShader.js +0 -98
  113. package/shaders/ShaderFunction.js +0 -72
  114. package/shaders/SkyCubeShader.js +0 -78
  115. package/shaders/SkySphereShader.js +0 -77
  116. package/shaders/SpecularMapCubeShader.js +0 -145
  117. package/shaders/TextureMergerShader.js +0 -127
  118. package/shaders/webgl_shader_lib.js +0 -187
  119. package/tools/BinaryResourceProvider.js +0 -15
  120. package/tools/ImageResourceProvider.js +0 -65
  121. package/tools/MaterialModifier.js +0 -228
  122. package/tools/Resource.js +0 -177
  123. package/tools/ResourceProvider.js +0 -56
  124. package/tools/TextResourceProvider.js +0 -24
  125. package/tools/TextureCache.js +0 -44
  126. package/tools/TextureResourceDatabase.js +0 -87
  127. package/tools/UserAgent.js +0 -294
  128. package/tools/VideoResourceProvider.js +0 -51
  129. package/tools/WriteStrategy.js +0 -22
  130. package/tools/base64.js +0 -15
  131. package/tools/crypto.js +0 -15
  132. package/tools/endiantess.js +0 -15
  133. package/tools/image.js +0 -15
  134. package/tools/index.js +0 -33
  135. package/tools/processType.js +0 -56
@@ -1,146 +0,0 @@
1
- import Renderer from "../render/Renderer";
2
-
3
- const g_componentClasses = {}
4
-
5
- export const registerComponent = (typeId,componentClass) => {
6
- g_componentClasses[typeId] = componentClass;
7
- }
8
-
9
- export const createComponent = (typeId) => {
10
- const ComponentClass = g_componentClasses[typeId];
11
- if (ComponentClass) {
12
- try {
13
- const compInstance = new ComponentClass();
14
- return compInstance;
15
- }
16
- catch (err) {
17
- if (err.code === -1) {
18
- throw new Error(`Error in component constructor definition. Check the implementation of the '${ typeId }' component constructor. It should call super('typeId') to configure the component type id.`);
19
- }
20
- }
21
- }
22
- else {
23
- console.debug(`Ignoring component with type id='${typeId}'. If this is not expected, check if the component is registered in the component factory.`);
24
- return null;
25
- }
26
- }
27
-
28
- export const deserializeComponent = async (sceneData,loader) => {
29
- const componentInstance = createComponent(sceneData.type);
30
- if (!componentInstance) {
31
- return null;
32
- }
33
-
34
- await componentInstance.deserialize(sceneData,loader);
35
- return componentInstance;
36
- }
37
-
38
- export default class Component {
39
- constructor(typeId) {
40
- this._node = null;
41
- if (!typeId) {
42
- const e = new Error("Invalid typeId specified creating component.");
43
- e.code = -1;
44
- throw e;
45
- }
46
- this._typeId = typeId;
47
- }
48
-
49
- get node() { return this._node; }
50
-
51
- get typeId() { return this._typeId; }
52
-
53
- clone() {
54
- throw new Error("Component.clone() not implemented");
55
- }
56
-
57
- assign(other) {
58
- throw new Error("Component.assign() not implemented");
59
- }
60
-
61
- destroy() {
62
-
63
- }
64
-
65
- addedToNode(node) {
66
-
67
- }
68
-
69
- removedFromNode(node) {
70
-
71
- }
72
-
73
- async deserialize(sceneData,loader) {
74
- }
75
-
76
- async serialize(sceneData,writer) {
77
- sceneData.type = this.typeId;
78
- }
79
-
80
- bindRenderer(renderer) {
81
- if (!renderer instanceof Renderer) {
82
- throw Error("Component.bindRenderer(): invalid renderer. Object is not instance of render.Renderer");
83
- }
84
-
85
- this._renderer = renderer;
86
- }
87
-
88
- async init() {
89
-
90
- }
91
-
92
- get ready() {
93
- return this._renderer !== null;
94
- }
95
-
96
- get renderer() {
97
- return this._renderer;
98
- }
99
-
100
- // Access to brother components
101
- component(identifier) {
102
- return this.node.component(identifier);
103
- }
104
-
105
- get transform() {
106
- return this.component("Transform");
107
- }
108
-
109
- get lightComponent() {
110
- return this.component("Light");
111
- }
112
-
113
- get drawable() {
114
- return this.component("Drawable");
115
- }
116
-
117
- get camera() {
118
- return this.component("Camera");
119
- }
120
-
121
- // Life cycle functions and properties
122
- get requireWillUpdate() { return typeof(this.willUpdate) === "function" }
123
- get requireUpdate() { return typeof(this.update) === "function" }
124
- get requireDraw() { return typeof(this.draw) === "function"; }
125
-
126
- // The following functions can be implemented in component classes to complete the
127
- // life cycle functions
128
- // async init() {}
129
- // willUpdate(delta) {}
130
- // update(delta,modelMatrix) {}
131
- // draw(renderQueue,modelMatrix) {}
132
-
133
- // Event callbacks
134
- keyDown(evt) {}
135
- keyUp(evt) {}
136
- mouseUp(evt) {}
137
- mouseDown(evt) {}
138
- mouseMove(evt) {}
139
- mouseOut(evt) {}
140
- mouseDrag(evt) {}
141
- mouseWheel(evt) {}
142
- touchStart(evt) {}
143
- touchMove(evt) {}
144
- touchEnd(evt) {}
145
- }
146
-
@@ -1,99 +0,0 @@
1
-
2
- import Component from "./Component";
3
-
4
- function syncArray() {
5
- this._array = [];
6
- for (const type in this._obj) {
7
- const c = this._obj[type];
8
- this._array.push(c);
9
- }
10
- }
11
-
12
- export default class ComponentMap {
13
- constructor(node) {
14
- this._node = node;
15
- this._obj = {};
16
- this._array = [];
17
- }
18
-
19
- get array() {
20
- return this._array;
21
- }
22
-
23
- add(comp) {
24
- const typeId = comp.typeId;
25
- const existingComp = this._obj[typeId];
26
- if (existingComp) {
27
- existingComp._node = null;
28
- existingComp.removedFromNode(this._node);
29
- }
30
- this._obj[typeId] = comp;
31
- comp._node = this._node;
32
- comp.addedToNode(this._node);
33
- syncArray.apply(this);
34
- }
35
-
36
- remove(compOrType) {
37
- const typeId = compOrType instanceof Component ? compOrType.typeId : compOrType;
38
- const existingComp = this._obj[typeId];
39
- if (existingComp) {
40
- existingComp._node = null;
41
- existingComp.removedFromNode(this._node);
42
- delete this._obj[typeId];
43
- syncArray.apply(this);
44
- }
45
- }
46
-
47
- empty() {
48
- for (const typeId in this._obj) {
49
- const comp = this._obj[typeId];
50
- comp._node = null;
51
- comp.removedFromNode(this._node);
52
- }
53
- this._obj = {};
54
- this._array = [];
55
- }
56
-
57
- find(typeId) {
58
- return this._obj[typeId];
59
- }
60
-
61
- forEach(cb) {
62
- return this._array.forEach(cb);
63
- }
64
-
65
- every(cb) {
66
- return this._array.every(cb);
67
- }
68
-
69
- some(cb) {
70
- return this._array.some(cb);
71
- }
72
-
73
- map(cb) {
74
- return this._array.map(cb);
75
- }
76
-
77
- filter(cb) {
78
- return this._array.filter(cb);
79
- }
80
-
81
- clone(parentNode) {
82
- const result = new Components(parentNode);
83
- result.assign(this);
84
- return result;
85
- }
86
-
87
- // Note: this function clones the components from 'other'
88
- // instance to this instance.
89
- // This function doesn't modify this._node reference
90
- assign(other) {
91
- this.empty();
92
- for (const typeId in other._obj) {
93
- const comp = other._obj[typeId];
94
- const compClone = comp.clone();
95
- this._obj[typeId] = compClone;
96
- }
97
- syncArray.apply(this);
98
- }
99
- }
package/scene/Drawable.js DELETED
@@ -1,130 +0,0 @@
1
-
2
- import Component from "./Component";
3
- import Mat4 from "../math/Mat4";
4
- import PolyList from "../base/PolyList";
5
- import Material from "../base/Material";
6
- import VitscnjLoaderPlugin, { DrawableFormat } from "../db/VitscnjLoaderPlugin";
7
-
8
- export default class Drawable extends Component {
9
- constructor(name) {
10
- super("Drawable");
11
- this._name = name || "";
12
- this._items = [];
13
- }
14
-
15
- get name() {
16
- return this._name;
17
- }
18
-
19
- set name(n) {
20
- this._name = n;
21
- }
22
-
23
- get valid() {
24
- return this._items.length>0 && this._items.every(item => item.polyList !== null && item.material !== null);
25
- }
26
-
27
- get items() {
28
- return this._items;
29
- }
30
-
31
- clone() {
32
- const result = new Drawable();
33
- result.assign(this);
34
- return result;
35
- }
36
-
37
- assign(other) {
38
- this.destroy();
39
- this._name = other._name;
40
- this._items = [];
41
- other._items.forEach(item => {
42
- const pl = item.polyList.clone();
43
- const mat = item.material.clone();
44
- const trx = new Mat4(item.transform);
45
- this.addPolyList(pl,mat,trx);
46
- });
47
- }
48
-
49
- addPolyList(polyList,material,transform = Mat4.MakeIdentity(),r) {
50
- if (!polyList instanceof PolyList) {
51
- throw new Error("Error adding polyList to drawable object: polyList is not an instance of PolyList");
52
- }
53
- if (!material instanceof Material) {
54
- throw new Error("Error adding polyList to drawable object: material is not an instance of Material");
55
- }
56
- if (!transform instanceof Mat4) {
57
- throw new Error("Error adding polyList to drawable object: transform is not an instance of Mat4");
58
- }
59
- this._items.push({ polyList, material, transform });
60
- }
61
-
62
- removePolyList(plist) {
63
- this._items = this._items.filter(item => item.polyList != plist);
64
- }
65
-
66
- destroy() {
67
-
68
- }
69
-
70
- addedToNode(node) {
71
-
72
- }
73
-
74
- removedFromNode(node) {
75
-
76
- }
77
-
78
- makeSelectable(selectable = true) {
79
- this._items.forEach(({polyList}) => {
80
- polyList.selectable = selectable;
81
- })
82
- }
83
-
84
- async deserialize(sceneData,loader) {
85
- const tryload = async (drawablePath) => {
86
- try {
87
- const result = await loader.loadDrawable(drawablePath);
88
- return result;
89
- }
90
- catch (err) {
91
-
92
- }
93
- }
94
-
95
- const drwFormat = VitscnjLoaderPlugin.PreferredDrawableFormat();
96
- const drw = drwFormat === DrawableFormat.BG2
97
- ? (await tryload(sceneData.name + '.bg2') || await tryload(sceneData.name + '.vwglb'))
98
- : (await tryload(sceneData.name + '.vwglb') || await tryload(sceneData.name + '.bg2'));
99
-
100
- if (!drw) {
101
- throw new Error(`Drawable.deserialize(): could not load drawable with name ${sceneData.name}`);
102
- }
103
- drw.items.forEach(({polyList,material,transform}) => this.addPolyList(polyList,material,transform));
104
- this.name = drw.name;
105
- }
106
-
107
- async serialize(sceneData,writer) {
108
- await super.serialize(sceneData,writer);
109
- throw new Error("Drawable.serialice() not implemented");
110
- }
111
-
112
- bindRenderer(renderer) {
113
- super.bindRenderer(renderer);
114
- this._items.forEach(item => {
115
- item.polyListRenderer = renderer.factory.polyList(item.polyList);
116
- item.materialRenderer = renderer.factory.material(item.material);
117
- });
118
- }
119
-
120
- draw(renderQueue,modelMatrix) {
121
- if (this.ready) {
122
- this._items.forEach(({transform,polyListRenderer,materialRenderer}) => {
123
- renderQueue.addPolyList(
124
- polyListRenderer,
125
- materialRenderer,
126
- Mat4.Mult(transform, modelMatrix));
127
- });
128
- }
129
- }
130
- }
@@ -1,123 +0,0 @@
1
- import { jointUrl } from "../tools/Resource";
2
- import Component from "./Component";
3
-
4
- export default class EnvironmentComponent extends Component {
5
- constructor() {
6
- super("Environment");
7
-
8
- this._equirectangularTexture = "";
9
- this._irradianceIntensity = 1;
10
- this._showSkybox = true;
11
- this._cubemapSize = 512;
12
- this._irradianceMapSize = 32;
13
- this._specularMapSize = 32;
14
- this._specularMapL2Size = 32;
15
-
16
- // Non-serializable attribute
17
- this._environment = null;
18
- }
19
-
20
- set equirectangularTexture(v) {
21
- this._equirectangularTexture = v;
22
- }
23
-
24
- get equirectangularTexture() {
25
- return this._equirectangularTexture;
26
- }
27
-
28
- set irradianceIntensity(v) {
29
- this._irradianceIntensity = v;
30
- }
31
-
32
- get irradianceIntensity() {
33
- return this._irradianceIntensity;
34
- }
35
-
36
- set showSkybox(v) {
37
- this._showSkybox = v;
38
- }
39
-
40
- get showSkybox() {
41
- return this._showSkybox;
42
- }
43
-
44
- set cubemapSize(v) {
45
- this._cubemapSize = v;
46
- }
47
-
48
- get cubemapSize() {
49
- return this._cubemapSize;
50
- }
51
-
52
- set irradianceMapSize(v) {
53
- this._irradianceMapSize = v;
54
- }
55
-
56
- get irradianceMapSize() {
57
- return this._irradianceMapSize;
58
- }
59
-
60
- set specularMapSize(v) {
61
- this._specularMapSize = v;
62
- }
63
-
64
- get specularMapSize() {
65
- return this._specularMapSize;
66
- }
67
-
68
- set specularMapL2Size(v) {
69
- this._specularMapL2Size = v;
70
- }
71
-
72
- get specularMapL2Size() {
73
- return this._specularMapL2Size;
74
- }
75
-
76
- get environment() {
77
- return this._environment;
78
- }
79
-
80
- clone() {
81
- const result = new EnvironmentComponent();
82
- result.assign(this);
83
- return result;
84
- }
85
-
86
- assign(other) {
87
- this.equirectangularTexture = other.equirectangularTexture;
88
- this.irradianceIntensity = other.irradianceIntensity;
89
- this.showSkybox = other.showSkybox;
90
- this.cubemapSize = other.cubemapSize;
91
- this.irradianceMapSize = other.irradianceMapSize;
92
- this.specularMapSize = other.specularMapSize;
93
- this.specularMapL2Size = other.specularMapL2Size;
94
- }
95
-
96
- async deserialize(sceneData,loader) {
97
- super.deserialize(sceneData,loader);
98
- if (loader.currentPath && sceneData.equirectangularTexture) {
99
- this.equirectangularTexture = jointUrl(loader.currentPath,sceneData.equirectangularTexture);
100
- }
101
- this.irradianceIntensity = sceneData.irradianceIntensity || this.irradianceIntensity;
102
- this.showSkybox = sceneData.showSkybox ?? this.showSkybox;
103
- this.cubemapSize = sceneData.cubemapSize || this.cubemapSize;
104
- this.irradianceMapSize = sceneData.irradianceMapSize || this.irradianceMapSize;
105
- this.specularMapSize = sceneData.specularMapSize || this.specularMapSize;
106
- this.specularMapL2Size = sceneData.specularMapL2Size || this.specularMapL2Size;
107
- }
108
-
109
- async serialize(sceneData,writer) {
110
- await super.serialize(sceneData,writer);
111
- throw Error("EnvironmentComponent.serialize(): not implemented");
112
- }
113
-
114
- async init() {
115
- this._environment = this.renderer.factory.environment();
116
- await this._environment.load({
117
- textureUrl: this.equirectangularTexture,
118
- environmentMapSize: [ this.cubemapSize, this.cubemapSize ],
119
- specularMapSize: [ this.specularMapSize, this.specularMapSize ],
120
- irradianceMapSize: [ this.irradianceMapSize, this.irradianceMapSize ]
121
- });
122
- }
123
- }
@@ -1,55 +0,0 @@
1
- import NodeVisitor from "./NodeVisitor";
2
-
3
- export default class FindNodeVisitor extends NodeVisitor {
4
- constructor() {
5
- super();
6
-
7
- this._name;
8
- this._result = [];
9
- this._hasComponents = [];
10
- }
11
-
12
- set name(n) {
13
- this._name = n;
14
- }
15
-
16
- get name() {
17
- return this._name;
18
- }
19
-
20
- get result() {
21
- return this._result;
22
- }
23
-
24
- clear() {
25
- this._result = [];
26
- }
27
-
28
- hasComponents(components) {
29
- if (!Array.isArray(components)) {
30
- components = [components];
31
- }
32
- this._hasComponents = components;
33
- }
34
-
35
- visit(node) {
36
- let add = false;
37
- if (typeof(this._name) === "string") {
38
- add = this._name === node.name;
39
- }
40
- else if (this._name instanceof RegExp) {
41
- add = this._name.test(node.name);
42
- }
43
- else {
44
- add = true;
45
- }
46
-
47
- add = add && (
48
- this._hasComponents.some(compId => node.component(compId)) ||
49
- this._hasComponents.length == 0
50
- );
51
- if (add) {
52
- this._result.push(node);
53
- }
54
- }
55
- }
@@ -1,146 +0,0 @@
1
- import Component from "./Component";
2
- import Light, { LightType } from "../base/Light";
3
- import FindNodeVisitor from "./FindNodeVisitor";
4
-
5
-
6
- export default class LightComponent extends Component {
7
- static GetLights(sceneRoot) {
8
- if (sceneRoot.sceneChanged || !sceneRoot.__lights) {
9
- sceneRoot.__lights = [];
10
- let findLights = new FindNodeVisitor();
11
- findLights.hasComponents(["Light"]);
12
- sceneRoot.accept(findLights);
13
- sceneRoot.__lights = findLights.result.map(n => n.lightComponent);
14
- }
15
- return sceneRoot.__lights;
16
- }
17
-
18
- static GetFirstShadowCastingLight(sceneRoot) {
19
- if (sceneRoot.sceneChanged || !sceneRoot.__mainDirectionalLight) {
20
- sceneRoot.__mainDirectionalLight = LightComponent.GetLights(sceneRoot)
21
- .find(l => l.light.type === LightType.DIRECTIONAL || l.light.type === LightType.SPOT);
22
- }
23
- return sceneRoot.__mainDirectionalLight;
24
- }
25
-
26
- static GetMainDirectionalLight(sceneRoot) {
27
- if (sceneRoot.sceneChanged || !sceneRoot.__mainDirectionalLight) {
28
- sceneRoot.__mainDirectionalLight = LightComponent.GetLights(sceneRoot)
29
- .find(l => l.light.type === LightType.DIRECTIONAL);
30
- }
31
- return sceneRoot.__mainDirectionalLight || LightComponent.GetFirstShadowCastingLight(sceneRoot);
32
- }
33
-
34
- constructor(light = null) {
35
- super("Light");
36
-
37
- this._light = light || new Light();
38
- }
39
-
40
- get light() { return this._light; }
41
- set light(l) { this._light = l; }
42
-
43
- set depthTexture(t) {
44
- this._light.depthTexture = t;
45
- }
46
-
47
- get depthTexture() {
48
- return this._light.depthTexture;
49
- }
50
-
51
- set viewMatrix(vm) {
52
- this._light.viewMatrix = vm;
53
- }
54
-
55
- get viewMatrix() {
56
- return this._light.viewMatrix;
57
- }
58
-
59
- set mvpMatrix(m) {
60
- this._light.mvpMatrix = m;
61
- }
62
-
63
- get mvpMatrix() {
64
- return this._light.mvpMatrix;
65
- }
66
-
67
- clone() {
68
- const result = new Light();
69
- result.assign(this);
70
- return result;
71
- }
72
-
73
- assign(other) {
74
- this._light = other._light.clone();
75
- }
76
-
77
- setProperties({
78
- enabled,
79
- type,
80
- lightType, // alias of type
81
- direction,
82
- position,
83
- color,
84
- spotCutoff,
85
- spotExponent,
86
- shadowStrength,
87
- castShadows,
88
- shadowBias,
89
- intensity,
90
- projection
91
- }) {
92
- if (enabled !== undefined) {
93
- this.light.enabled = enabled;
94
- }
95
- if (type !== undefined) {
96
- this.light.type = type;
97
- }
98
- if (lightType !== undefined) {
99
- this.light.type = lightType;
100
- }
101
- if (direction !== undefined) {
102
- this.light.direction = direction;
103
- }
104
- if (position !== undefined) {
105
- this.light.position = position;
106
- }
107
- if (color !== undefined) {
108
- this.light.color = color;
109
- }
110
- if (spotCutoff !== undefined) {
111
- this.light.spotCutoff = spotCutoff;
112
- }
113
- if (spotExponent !== undefined) {
114
- this.light.spotExponent = spotExponent;
115
- }
116
- if (shadowStrength !== undefined) {
117
- this.light.shadowStrength = shadowStrength;
118
- }
119
- if (castShadows !== undefined) {
120
- this.light.castShadows = castShadows;
121
- }
122
- if (shadowBias !== undefined) {
123
- this.light.shadowBias = shadowBias;
124
- }
125
- if (intensity !== undefined) {
126
- this.light.intensity = intensity;
127
- }
128
- if (projection !== undefined) {
129
- this.light.projection = projection;
130
- }
131
- }
132
-
133
- async deserialize(sceneData,loader) {
134
- await this._light.deserialize(sceneData);
135
- }
136
-
137
- async serialize(sceneData,writer) {
138
- await super.serialize(sceneData,writer);
139
- await this._light.serialize(sceneData);
140
- throw new Error("LightComponent.serialize() not implemented");
141
- }
142
-
143
- draw(renderQueue,modelMatrix) {
144
- renderQueue.addLight(this.light, modelMatrix);
145
- }
146
- }