bg2e-js 2.0.0 → 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 (132) 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.js +0 -32
  5. package/app/Canvas.js +0 -98
  6. package/app/EventBase.js +0 -8
  7. package/app/KeyboardEvent.js +0 -51
  8. package/app/MainLoop.js +0 -251
  9. package/app/MouseEvent.js +0 -77
  10. package/app/TouchEvent.js +0 -15
  11. package/base/Color.js +0 -131
  12. package/base/Environment.js +0 -78
  13. package/base/Light.js +0 -176
  14. package/base/Material.js +0 -619
  15. package/base/PolyList.js +0 -336
  16. package/base/Texture.js +0 -545
  17. package/db/Bg2LoaderPlugin.js +0 -113
  18. package/db/DBPluginApi.js +0 -40
  19. package/db/Loader.js +0 -91
  20. package/db/LoaderPlugin.js +0 -26
  21. package/db/MtlParser.js +0 -7
  22. package/db/ObjLoaderPlugin.js +0 -51
  23. package/db/ObjParser.js +0 -233
  24. package/db/ObjWriterPlugin.js +0 -18
  25. package/db/VitscnjLoaderPlugin.js +0 -87
  26. package/db/Writer.js +0 -49
  27. package/db/WriterPlugin.js +0 -20
  28. package/debug/DebugRenderer.js +0 -138
  29. package/debug/WebGLTextureViewer.js +0 -67
  30. package/manipulation/SelectionBuffer.js +0 -65
  31. package/manipulation/SelectionHighlight.js +0 -69
  32. package/manipulation/SelectionIdAssignVisitor.js +0 -86
  33. package/manipulation/SelectionManager.js +0 -134
  34. package/manipulation/SelectionMode.js +0 -6
  35. package/math/Mat3.js +0 -248
  36. package/math/Mat4.js +0 -694
  37. package/math/MatrixStrategy.js +0 -23
  38. package/math/Quat.js +0 -60
  39. package/math/Vec.js +0 -728
  40. package/math/constants.js +0 -44
  41. package/math/functions.js +0 -104
  42. package/math/index.js +0 -74
  43. package/phsics/joint.js +0 -124
  44. package/primitives/arrow.js +0 -58
  45. package/primitives/cone.js +0 -137
  46. package/primitives/cube.js +0 -59
  47. package/primitives/cylinder.js +0 -215
  48. package/primitives/index.js +0 -13
  49. package/primitives/plane.js +0 -31
  50. package/primitives/sphere.js +0 -808
  51. package/render/BRDFIntegrationMap.js +0 -4
  52. package/render/Environment.js +0 -105
  53. package/render/EnvironmentRenderer.js +0 -12
  54. package/render/FrameBuffer.js +0 -26
  55. package/render/MaterialRenderer.js +0 -28
  56. package/render/Pipeline.js +0 -83
  57. package/render/PolyListRenderer.js +0 -42
  58. package/render/RenderBuffer.js +0 -189
  59. package/render/RenderQueue.js +0 -162
  60. package/render/RenderState.js +0 -82
  61. package/render/Renderer.js +0 -202
  62. package/render/SceneAppController.js +0 -208
  63. package/render/SceneRenderer.js +0 -310
  64. package/render/Shader.js +0 -21
  65. package/render/ShadowRenderer.js +0 -159
  66. package/render/SkyCube.js +0 -77
  67. package/render/SkySphere.js +0 -94
  68. package/render/TextureMergerRenderer.js +0 -58
  69. package/render/TextureRenderer.js +0 -29
  70. package/render/webgl/FrameBuffer.js +0 -9
  71. package/render/webgl/MaterialRenderer.js +0 -99
  72. package/render/webgl/Pipeline.js +0 -82
  73. package/render/webgl/PolyListRenderer.js +0 -224
  74. package/render/webgl/RenderBuffer.js +0 -244
  75. package/render/webgl/Renderer.js +0 -239
  76. package/render/webgl/SceneRenderer.js +0 -43
  77. package/render/webgl/ShaderProgram.js +0 -348
  78. package/render/webgl/ShadowRenderer.js +0 -6
  79. package/render/webgl/SkyCube.js +0 -15
  80. package/render/webgl/SkySphere.js +0 -14
  81. package/render/webgl/State.js +0 -149
  82. package/render/webgl/TextureRenderer.js +0 -167
  83. package/render/webgl/VertexBuffer.js +0 -128
  84. package/scene/Camera.js +0 -378
  85. package/scene/Chain.js +0 -43
  86. package/scene/ChainJoint.js +0 -55
  87. package/scene/Component.js +0 -146
  88. package/scene/ComponentMap.js +0 -99
  89. package/scene/Drawable.js +0 -130
  90. package/scene/EnvironmentComponent.js +0 -123
  91. package/scene/FindNodeVisitor.js +0 -55
  92. package/scene/LightComponent.js +0 -146
  93. package/scene/MatrixState.js +0 -39
  94. package/scene/Node.js +0 -300
  95. package/scene/NodeVisitor.js +0 -12
  96. package/scene/OrbitCameraController.js +0 -407
  97. package/scene/SmoothOrbitCameraController.js +0 -92
  98. package/scene/Transform.js +0 -74
  99. package/scene/index.js +0 -24
  100. package/shaders/BasicDiffuseColorShader.js +0 -91
  101. package/shaders/BasicPBRLightShader.js +0 -238
  102. package/shaders/DebugRenderShader.js +0 -79
  103. package/shaders/DepthRenderShader.js +0 -69
  104. package/shaders/IrradianceMapCubeShader.js +0 -99
  105. package/shaders/PBRLightIBLShader.js +0 -380
  106. package/shaders/PickSelectionShader.js +0 -75
  107. package/shaders/PresentDebugFramebufferShader.js +0 -90
  108. package/shaders/PresentTextureShader.js +0 -73
  109. package/shaders/SelectionHighlightShader.js +0 -98
  110. package/shaders/ShaderFunction.js +0 -72
  111. package/shaders/SkyCubeShader.js +0 -78
  112. package/shaders/SkySphereShader.js +0 -77
  113. package/shaders/SpecularMapCubeShader.js +0 -145
  114. package/shaders/TextureMergerShader.js +0 -127
  115. package/shaders/webgl_shader_lib.js +0 -187
  116. package/tools/BinaryResourceProvider.js +0 -15
  117. package/tools/ImageResourceProvider.js +0 -65
  118. package/tools/MaterialModifier.js +0 -228
  119. package/tools/Resource.js +0 -177
  120. package/tools/ResourceProvider.js +0 -56
  121. package/tools/TextResourceProvider.js +0 -24
  122. package/tools/TextureCache.js +0 -44
  123. package/tools/TextureResourceDatabase.js +0 -87
  124. package/tools/UserAgent.js +0 -294
  125. package/tools/VideoResourceProvider.js +0 -51
  126. package/tools/WriteStrategy.js +0 -22
  127. package/tools/base64.js +0 -15
  128. package/tools/crypto.js +0 -15
  129. package/tools/endiantess.js +0 -15
  130. package/tools/image.js +0 -15
  131. package/tools/index.js +0 -33
  132. package/tools/processType.js +0 -56
package/base/Material.js DELETED
@@ -1,619 +0,0 @@
1
-
2
- import Vec from '../math/Vec';
3
- import Color from './Color';
4
- import Texture, { TextureDataType, TextureFilter, TextureWrap } from './Texture';
5
- import Canvas from '../app/Canvas';
6
- import TextureCache from '../tools/TextureCache';
7
-
8
-
9
- export const MaterialType = Object.freeze({
10
- PBR: "pbr"
11
- });
12
-
13
- export const MaterialAttributeNames = [
14
- "type",
15
- "class", // Alias of "type"
16
- "diffuse",
17
- "diffuseScale",
18
- "diffuseUV",
19
- "alphaCutoff",
20
- "isTransparent",
21
- "metallic",
22
- "metallicChannel",
23
- "metallicScale",
24
- "metallicUV",
25
- "roughness",
26
- "roughnessChannel",
27
- "roughnessScale",
28
- "roughnessUV",
29
- "fresnel",
30
- "lightEmission",
31
- "lightEmissionChannel",
32
- "lightEmissionScale",
33
- "lightEmissionUV",
34
- "ambientOcclussion",
35
- "ambientOcclussionChannel",
36
- "ambientOcclussionUV",
37
- "normal",
38
- "normalScale",
39
- "normalUV",
40
- "height",
41
- "heightChannel",
42
- "heightScale",
43
- "heightUV",
44
- "heightIntensity",
45
- "castShadows",
46
- "unlit"
47
- ];
48
-
49
- export const ColorTextureAttributes = [
50
- "diffuse",
51
- "normal"
52
- ];
53
-
54
- export const ValueTextureAttributes = [
55
- "metallic",
56
- "roughness",
57
- "lightEmission",
58
- "ambientOcclussion",
59
- "height"
60
- ];
61
-
62
- export const VectorAttribures = [
63
- "diffuseScale",
64
- "metallicScale",
65
- "roughnessScale",
66
- "lightEmissionScale",
67
- "normalScale",
68
- "heightScale"
69
- ];
70
-
71
- export const ColorAttributes = [
72
- "fresnel"
73
- ];
74
-
75
- export const PrimitiveTypeAttributes = [
76
- "type",
77
- "class", // alias off type
78
- "alphaCutoff",
79
- "isTransparent",
80
- "diffuseUV",
81
- "metallicChannel",
82
- "metallicUV",
83
- "roughnessChannel",
84
- "roughnessUV",
85
- "lightEmissionChannel",
86
- "lightEmissionUV",
87
- "ambientOcclussionChannel",
88
- "ambientOcclussionUV",
89
- "normalUV",
90
- "heightChannel",
91
- "heightUV",
92
- "heightIntensity",
93
- "castShadows",
94
- "unlit"
95
- ];
96
-
97
-
98
- export const assertColorTexture = (v, name) => {
99
- if (!v instanceof Color && !v instanceof Texture) {
100
- throw new Error(`Invalid parameter setting '${ name }' material attribute. The required parameter type is Color or Texture`);
101
- }
102
- }
103
-
104
- export const assertColor = (v, name) => {
105
- if (!v instanceof Color) {
106
- throw new Error(`Invalid parameter setting '${ name }' material attribute. The required parameter type is Color`);
107
- }
108
- }
109
-
110
- export const assertScale = (v, name) => {
111
- if (!v instanceof Vec || v.length != 2) {
112
- throw new Error(`Invalid parameter setting '${ name }' material attribute. The required parameter type is Vec with two elements.`);
113
- }
114
- }
115
-
116
- export const assertValueTexture = (v, name) => {
117
- if (!v instanceof Texture && typeof(v) !== "number") {
118
- throw new Error(`Invalid parameter setting '${ name }' material attribute. The required parameter type is Texture or numeric value.`);
119
- }
120
- }
121
-
122
- // Clone the `obj` parameter if it is
123
- // - Vec
124
- // - Color
125
- // - Texture
126
- // Returns the same parameter if not
127
- export const cloneObject = (obj) => {
128
- if (obj instanceof Color) {
129
- return new Color(obj);
130
- }
131
- else if (obj instanceof Vec) {
132
- return new Vec(obj);
133
- }
134
- else if (obj instanceof Texture) {
135
- return obj.clone();
136
- }
137
- else {
138
- return obj;
139
- }
140
- }
141
-
142
- export const serializeColorTexture = (obj) => {
143
- const result = { type: "", data: {} };
144
- if (obj instanceof Color) {
145
- result.type = "Color";
146
- result.data = obj;
147
- }
148
- else if (obj instanceof Texture) {
149
- result.type = "Texture";
150
- obj.serialize(result.data);
151
- }
152
- else {
153
- throw new Error(`Invalid parameter found in material serialization`);
154
- }
155
- return result;
156
- }
157
-
158
-
159
- export const deserializeColorTexture = (obj,relativePath = "", canvas = null) => {
160
- if (obj === null || obj === undefined) {
161
- return null;
162
- }
163
- else if (typeof(obj) === "string") {
164
- // bg2e v1 texture compatibility
165
- const texturePath = relativePath + obj;
166
- const textureCache = TextureCache.Get(canvas);
167
- if (textureCache.findTexture(texturePath)) {
168
- console.debug(`Texture '${ texturePath }' already loaded. Reusing texture.`);
169
- return textureCache.getTexture(texturePath);
170
- }
171
- else {
172
- console.log(`Texture not found in cache. Loading texture '${ texturePath }'`);
173
- const tex = new Texture(canvas);
174
- tex.fileName = relativePath + obj;
175
- tex.dataType = TextureDataType.IMAGE;
176
- tex.minFilter = TextureFilter.LINEAR_MIPMAP_LINEAR;
177
- tex.magFilter = TextureFilter.LINEAR;
178
- tex.wrapModeX = TextureWrap.REPEAT;
179
- tex.wrapModeY = TextureWrap.REPEAT;
180
- textureCache.registerTexture(tex);
181
- return tex;
182
- }
183
- }
184
- else if (Array.isArray(obj) && (obj.length === 3 || obj.length === 4)) {
185
- // bg2e v1 color compatibility
186
- if (obj.length === 3) {
187
- return new Vec(obj[0], obj[1], obj[2], 1);
188
- }
189
- else if (obj.length === 4) {
190
- return new Vec(obj[0], obj[1], obj[2], obj[3]);
191
- }
192
- }
193
- else if (obj.type === "Color") {
194
- return new Color(obj.data);
195
- }
196
- else if (obj.type === "Texture") {
197
- const tex = new Texture(canvas);
198
- tex.deserialize(obj.data);
199
- return tex;
200
- }
201
- else {
202
- reject(new Error(`Invalid parameter found in material deserialization`));
203
- }
204
- }
205
-
206
- export const deserializeVector = (obj) => {
207
- if (!obj) {
208
- return null;
209
- }
210
- else if (obj.length >= 2 && obj.length <= 4) {
211
- return new Vec(obj);
212
- }
213
- else if (obj._v && obj._v.length >= 2 && obj._v.length <= 4) {
214
- return new Vec(obj._v);
215
- }
216
- else {
217
- throw new Error(`Invalid parameter found in material serialization`);
218
- }
219
- }
220
-
221
- export const serializeValueTexture = (obj) => {
222
- const result = { type: "", data: "" };
223
- if (obj instanceof Texture) {
224
- result.type = "Texture";
225
- obj.serialize(result.data);
226
- }
227
- else if (typeof(obj) === "number") {
228
- result.type = "number";
229
- result.data = obj;
230
- }
231
- else {
232
- throw new Error(`Invalid parameter found in material serialization`);
233
- }
234
- return result;
235
- }
236
-
237
- export const deserializeValueTexture = (obj,relativePath, canvas = null) => {
238
- if (obj === null || obj === undefined) {
239
- return null;
240
- }
241
- else if (typeof(obj) === "string") {
242
- const texturePath = relativePath + obj;
243
- const textureCache = TextureCache.Get(canvas);
244
- if (textureCache.findTexture(texturePath)) {
245
- console.debug(`Texture '${ texturePath }' already loaded. Reusing texture.`);
246
- return textureCache.getTexture(texturePath);
247
- }
248
- else {
249
- console.log(`Texture not found in cache. Loading texture '${ texturePath }'`);
250
- const tex = new Texture(canvas);
251
- tex.fileName = relativePath + obj;
252
- tex.dataType = TextureDataType.IMAGE;
253
- tex.wrapModeX = TextureWrap.REPEAT;
254
- tex.wrapModeY = TextureWrap.REPEAT;
255
- tex.minFilter = TextureFilter.LINEAR_MIPMAP_LINEAR;
256
- tex.magFilter = TextureFilter.LINEAR;
257
- textureCache.registerTexture(tex);
258
- return tex;
259
- }
260
- }
261
- else if (typeof(obj) === "number") {
262
- return obj;
263
- }
264
- else if (Array.isArray(obj)) {
265
- // Obsolete option. Return the mean array value
266
- return obj.reduce((a,b) => a + b) / obj.length;
267
- }
268
- else if (obj.type === "Texture") {
269
- const tex = new Texture(canvas);
270
- tex.deserialize(obj.data);
271
- return tex;
272
- }
273
- else if (obj.type === "number") {
274
- return obj.data;
275
- }
276
- else {
277
- throw new Error(`Invalid parameter found in material serialization`)
278
- }
279
- }
280
-
281
- export const serializeAttribute = (att,mat) => {
282
- if (ColorTextureAttributes.indexOf(att) !== -1) {
283
- return serializeColorTexture(mat[att]);
284
- }
285
- else if (ValueTextureAttributes.indexOf(att) !== -1) {
286
- return serializeValueTexture(mat[att]);
287
- }
288
- else if (VectorAttribures.indexOf(att) !== -1 ||
289
- ColorAttributes.indexOf(att) !== -1 ||
290
- PrimitiveTypeAttributes.indexOf(att) !== -1
291
- ) {
292
- return mat[att];
293
- }
294
- else {
295
- throw new Error(`Error in material attribute deserialization: invalid attribute '${ att }'`);
296
- }
297
- }
298
-
299
- export const deserializeAttribute = (att,obj,relativePath,canvas = null) => {
300
- if (ColorTextureAttributes.indexOf(att) !== -1) {
301
- return deserializeColorTexture(obj[att],relativePath,canvas);
302
- }
303
- else if (ValueTextureAttributes.indexOf(att) !== -1) {
304
- return deserializeValueTexture(obj[att],relativePath,canvas);
305
- }
306
- else if (VectorAttribures.indexOf(att) !== -1) {
307
- return deserializeVector(obj[att]);
308
- }
309
- else if (ColorAttributes.indexOf(att) !== -1) {
310
- return new Color(obj[att]);
311
- }
312
- else if (PrimitiveTypeAttributes.indexOf(att) !== -1) {
313
- return obj[att];
314
- }
315
- else {
316
- throw new Error(`Error in material attribute deserialization: invalid attribute '${ att }'`);
317
- }
318
- }
319
-
320
- export default class Material {
321
- static async Deserialize(sceneData,relativePath = "",canvas = null) {
322
- const result = new Material(canvas);
323
- await result.deserialize(sceneData,relativePath,canvas);
324
- return result;
325
- }
326
-
327
- constructor(canvas = null) {
328
- this._canvas = canvas || Canvas.FirstCanvas();
329
- this._type = MaterialType.PBR;
330
- this._renderer = null;
331
-
332
- this._diffuse = Color.White();
333
- this._diffuseScale = new Vec(1, 1);
334
- this._diffuseUV = 0;
335
- this._alphaCutoff = 0.5;
336
- this._isTransparent = false;
337
- this._metallic = 0;
338
- this._metallicChannel = 0;
339
- this._metallicScale = new Vec(1, 1);
340
- this._metallicUV = 0;
341
- this._roughness = 1;
342
- this._roughnessChannel = 0;
343
- this._roughnessScale = new Vec(1, 1);
344
- this._roughnessUV = 0;
345
- this._fresnel = Color.White();
346
- this._lightEmission = 0;
347
- this._lightEmissionChannel = 0;
348
- this._lightEmissionScale = new Vec(1, 1);
349
- this._lightEmissionUV = 0;
350
- this._ambientOcclussion = 1;
351
- this._ambientOcclussionChannel = 0;
352
- this._ambientOcclussionUV = 1;
353
- this._normal = new Color({ r: 0.5, g: 0.5, b: 1 });
354
- this._normalScale = new Vec(1, 1);
355
- this._normalUV = 0;
356
- this._height = 0;
357
- this._heightChannel = 0;
358
- this._heightScale = new Vec(1, 1);
359
- this._heightUV = 0;
360
- this._heightIntensity = 1.0;
361
- this._castShadows = true;
362
- this._unlit = false;
363
-
364
- this._dirty = true;
365
- }
366
-
367
- get canvas() {
368
- return this._canvas;
369
- }
370
-
371
- get renderer() {
372
- return this._renderer;
373
- }
374
-
375
- get dirty() {
376
- return this._dirty;
377
- }
378
-
379
- set dirty(d) {
380
- this._dirty = d;
381
- }
382
-
383
- clone() {
384
- const result = new Material();
385
- result.assign(this);
386
- return result;
387
- }
388
-
389
- assign(other) {
390
- this.type = other._type;
391
- this.diffuse = cloneObject(other._diffuse);
392
- this.diffuseScale = cloneObject(other._diffuseScale);
393
- this.diffuseUV = other._diffuseUV;
394
- this.alphaCutoff = other._alphaCutoff;
395
- this.isTransparent = other._isTransparent;
396
- this.metallic = cloneObject(other._metallic);
397
- this.metallicChannel = other._metallicChannel;
398
- this.metallicScale = cloneObject(other._metallicScale);
399
- this.metallicUV = other._metallicUV;
400
- this.roughness = cloneObject(other._roughness);
401
- this.roughnessChannel = other._roughnessChannel;
402
- this.roughnessScale = cloneObject(other._roughnessScale);
403
- this.roughnessUV = other._roughnessUV;
404
- this.fresnel = cloneObject(other._fresnel);
405
- this.lightEmission = cloneObject(other._lightEmission);
406
- this.lightEmissionChannel = other._lightEmissionChannel;
407
- this.lightEmissionScale = cloneObject(other._lightEmissionScale);
408
- this.lightEmissionUV = other._lightEmissionUV;
409
- this.ambientOcclussion = cloneObject(other._ambientOcclussion);
410
- this.ambientOcclussionChannel = other._ambientOcclussionChannel;
411
- this.ambientOcclussionUV = other._ambientOcclussionUV;
412
- this.normal = cloneObject(other._normal);
413
- this.normalScale = cloneObject(other._normalScale);
414
- this.normalUV = other._normalUV;
415
- this.height = cloneObject(other._height);
416
- this.heightChannel = other._heightChannel;
417
- this.heightScale = cloneObject(other._heightScale);
418
- this.heightUV = other._heightUV;
419
- this.heightIntensity = other._heightIntensity;
420
- this.castShadows = other._castShadows;
421
- this.unlit = other._unlit;
422
- this._dirty = true;
423
- }
424
-
425
- get type() { return this._type; }
426
- set type(v) {
427
- // Compatibility with v1.4
428
- if (v === "PBRMaterial") {
429
- v = "pbr";
430
- }
431
- this._type = v;
432
- this._dirty = true;
433
- }
434
-
435
- // Compatibility with v1.4
436
- set class(v) { this.type = v; this._dirty = true; }
437
- get class() { return this.type; }
438
-
439
-
440
- get diffuse() { return this._diffuse; }
441
- set diffuse(v) {
442
- assertColorTexture(v, "diffuse");
443
- if (this._diffuse instanceof Texture) {
444
- this._diffuse.decReferences();
445
- }
446
- this._diffuse = v;
447
- if (this._diffuse instanceof Texture) {
448
- this._diffuse.incReferences();
449
- }
450
- this._dirty = true;
451
- }
452
-
453
- get diffuseScale() { return this._diffuseScale; }
454
- set diffuseScale(v) { assertScale(v, "diffuseScale"); this._diffuseScale = new Vec(v); this._dirty = true; }
455
- get diffuseUV() { return this._diffuseUV; }
456
- set diffuseUV(v) { this._diffuseUV = v; this._dirty = true; }
457
- get alphaCutoff() { return this._alphaCutoff; }
458
- set alphaCutoff(v) { this._alphaCutoff = v; this._dirty = true; }
459
- get isTransparent() { return this._isTransparent; }
460
- set isTransparent(v) { this._isTransparent = v; this._dirty = true; }
461
-
462
- get metallic() { return this._metallic; }
463
- set metallic(v) {
464
- assertValueTexture(v, "metallic");
465
- if (this._metallic instanceof Texture) {
466
- this._metallic.decReferences();
467
- }
468
- this._metallic = v;
469
- if (this._metallic instanceof Texture) {
470
- this._metallic.incReferences();
471
- }
472
- this._dirty = true;
473
- }
474
-
475
- get metallicChannel() { return this._metallicChannel; }
476
- set metallicChannel(v) { this._metallicChannel = v; this._dirty = true; }
477
- get metallicScale() { return this._metallicScale; }
478
- set metallicScale(v) { assertScale(v, "metallicScale"); this._metallicScale = new Vec(v); this._dirty = true; }
479
- get metallicUV() { return this._metallicUV; }
480
- set metallicUV(v) { this._metallicUV = v; this._dirty = true; }
481
-
482
- get roughness() { return this._roughness; }
483
- set roughness(v) {
484
- assertValueTexture(v, "roughness");
485
- if (this._roughness instanceof Texture) {
486
- this._roughness.decReferences();
487
- }
488
- this._roughness = v;
489
- if (this._roughness instanceof Texture) {
490
- this._roughness.incReferences();
491
- }
492
- this._dirty = true;
493
- }
494
-
495
- get roughnessChannel() { return this._roughnessChannel; }
496
- set roughnessChannel(v) { this._roughnessChannel = v; this._dirty = true; }
497
- get roughnessScale() { return this._roughnessScale; }
498
- set roughnessScale(v) { assertScale(v, "roughnessScale"); this._roughnessScale = new Vec(v); this._dirty = true; }
499
- get roughnessUV() { return this._roughnessUV; }
500
- set roughnessUV(v) { this._roughnessUV = v; this._dirty = true; }
501
- get fresnel() { return this._fresnel; }
502
- set fresnel(v) { assertColor(v, "fresnel"); this._fresnel = v; this._dirty = true; }
503
-
504
- get lightEmission() { return this._lightEmission; }
505
- set lightEmission(v) {
506
- assertValueTexture(v, 'lightEmission');
507
- if (this._lightEmission instanceof Texture) {
508
- this._lightEmission.decReferences();
509
- }
510
- this._lightEmission = v;
511
- if (this._lightEmission instanceof Texture) {
512
- this._lightEmission.incReferences();
513
- }
514
- this._dirty = true;
515
- }
516
-
517
- get lightEmissionChannel() { return this._lightEmissionChannel; }
518
- set lightEmissionChannel(v) { this._lightEmissionChannel = v; this._dirty = true; }
519
- get lightEmissionScale() { return this._lightEmissionScale; }
520
- set lightEmissionScale(v) { assertScale(v, "lightEmissionScale"); this._lightEmissionScale = new Vec(v); this._dirty = true; }
521
- get lightEmissionUV() { return this._lightEmissionUV; }
522
- set lightEmissionUV(v) { this._lightEmissionUV = v; this._dirty = true; }
523
-
524
- get ambientOcclussion() { return this._ambientOcclussion; }
525
- set ambientOcclussion(v) {
526
- assertColorTexture(v, "ambientOcclussion");
527
- if (this._ambientOcclussion instanceof Texture) {
528
- this._ambientOcclussion.decReferences();
529
- }
530
- this._ambientOcclussion = v;
531
- if (this._ambientOcclussion instanceof Texture) {
532
- this._ambientOcclussion.incReferences();
533
- }
534
- this._dirty = true;
535
- }
536
-
537
- get ambientOcclussionChannel() { return this._ambientOcclussionChannel; }
538
- set ambientOcclussionChannel(v) { this._ambientOcclussionChannel = v; this._dirty = true; }
539
- get ambientOcclussionUV() { return this._ambientOcclussionUV; }
540
- set ambientOcclussionUV(v) { this._ambientOcclussionUV = v; this._dirty = true; }
541
-
542
- get normal() { return this._normal; }
543
- set normal(v) {
544
- assertColorTexture(v, "normal");
545
- if (this._normal instanceof Texture) {
546
- this._normal.decReferences();
547
- }
548
- this._normal = v;
549
- if (this._normal instanceof Texture) {
550
- this._normal.incReferences();
551
- }
552
- this._dirty = true;
553
- }
554
-
555
- get normalScale() { return this._normalScale; }
556
- set normalScale(v) { assertScale(v, "normalScale"); this._normalScale = new Vec(v); this._dirty = true; }
557
- get normalUV() { return this._normalUV; }
558
- set normalUV(v) { this._normalUV = v; this._dirty = true; }
559
- get height() { return this._height; }
560
- set height(v) { assertValueTexture(v, "height"); this._height = v; this._dirty = true; }
561
- get heightChannel() { return this._heightChannel; }
562
- set heightChannel(v) { this._heightChannel = v; this._dirty = true; }
563
- get heightScale() { return this._heightScale; }
564
- set heightScale(v) { assertScale(v, "heightScale"); this._heightScale = new Vec(v); this._dirty = true; }
565
- get heightUV() { return this._heightUV; }
566
- set heightUV(v) { this._heightUV = v; this._dirty = true; }
567
- get heightIntensity() { return this._heightIntensity; }
568
- set heightIntensity(v) { this._heightIntensity = v; this._dirty = true; }
569
- get castShadows() { return this._castShadows; }
570
- set castShadows(v) { this._castShadows = v; this._dirty = true; }
571
- get unlit() { return this._unlit; }
572
- set unlit(v) { this._unlit = v; this._dirty = true; }
573
-
574
- async serialize(sceneData) {
575
- MaterialAttributeNames.forEach(att => {
576
- const value = serializeAttribute(att, this);
577
- sceneData[att] = value;
578
- });
579
- }
580
-
581
- async deserialize(sceneData, relativePath) {
582
- const P = [];
583
- for (const i in MaterialAttributeNames) {
584
- const att = MaterialAttributeNames[i];
585
- if (sceneData[att] !== undefined) {
586
- let value = null;
587
- if (att === "type") {
588
- value = deserializeAttribute("class", sceneData, relativePath, this.canvas);
589
- }
590
- else {
591
- value = deserializeAttribute(att, sceneData, relativePath, this.canvas);
592
- if (value instanceof Texture) {
593
- P.push(value.loadImageData());
594
- }
595
- }
596
-
597
- if (value !== null) {
598
- this[att] = value;
599
- }
600
- }
601
- }
602
- return await Promise.all(P);
603
- }
604
-
605
- destroy() {
606
- const decReferences = (attrib) => {
607
- if (this[attrib] instanceof Texture) {
608
- this[attrib].decReferences();
609
- }
610
- }
611
-
612
- ColorTextureAttributes.forEach(decReferences);
613
- ValueTextureAttributes.forEach(decReferences);
614
-
615
- if (this.renderer) {
616
- this.renderer.destroy();
617
- }
618
- }
619
- }