redhotmagma-visualization 1.44.9 → 1.45.0

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 (37) hide show
  1. package/Constants.js +1 -0
  2. package/DevApp.js +14 -0
  3. package/Three/Three2D.js +25 -4
  4. package/Three/Three3D.js +121 -83
  5. package/Three/Three3DScene.js +132 -58
  6. package/Utils/createBakedShadow.js +1 -2
  7. package/Utils/initTextureCanvas.js +3 -1
  8. package/Utils/optimizeTextureImage.js +1 -1
  9. package/Utils/rememberCameraViewOffset.js +12 -7
  10. package/Utils/restrictCameraMovement.js +2 -2
  11. package/package.json +3 -3
  12. package/public/libs/draco/README.md +2 -2
  13. package/public/libs/draco/draco_decoder.js +17 -35
  14. package/public/libs/draco/draco_decoder.wasm +0 -0
  15. package/public/libs/draco/draco_wasm_wrapper.js +117 -104
  16. package/public/libs/draco/gltf/draco_decoder.js +16 -31
  17. package/public/libs/draco/gltf/draco_decoder.wasm +0 -0
  18. package/public/libs/draco/gltf/draco_wasm_wrapper.js +116 -104
  19. package/src/Constants.js +1 -0
  20. package/src/DevApp.js +12 -0
  21. package/src/Three/Three2D.js +4 -3
  22. package/src/Three/Three3D.js +15 -8
  23. package/src/Three/Three3DScene.js +85 -29
  24. package/src/Three/__tests__/Three3D.test.js +0 -33
  25. package/src/Utils/createBakedShadow.js +2 -4
  26. package/src/Utils/initTextureCanvas.js +2 -1
  27. package/src/Utils/optimizeTextureImage.js +1 -1
  28. package/src/Utils/rememberCameraViewOffset.js +5 -3
  29. package/src/Utils/restrictCameraMovement.js +1 -1
  30. package/Three/Controls/OrbitControls.js +0 -724
  31. package/Three/Loaders/ColladaLoader.js +0 -2568
  32. package/Three/Loaders/MTLLoader.js +0 -418
  33. package/Three/Loaders/OBJLoader.js +0 -516
  34. package/src/Three/Controls/OrbitControls.js +0 -934
  35. package/src/Three/Loaders/ColladaLoader.js +0 -3245
  36. package/src/Three/Loaders/MTLLoader.js +0 -512
  37. package/src/Three/Loaders/OBJLoader.js +0 -640
@@ -1,512 +0,0 @@
1
- /* eslint-disable */
2
-
3
- // original source: three/examples/js/loaders/MTLLoader
4
-
5
- import * as THREE_imp from "three";
6
-
7
- const THREE = THREE_imp;
8
-
9
- // important: update file from here if needed
10
-
11
- /**
12
- * Loads a Wavefront .mtl file specifying materials
13
- *
14
- * @author angelxuanchang
15
- */
16
-
17
- THREE.MTLLoader = function(manager) {
18
- THREE.Loader.call(this, manager);
19
- };
20
-
21
- THREE.MTLLoader.prototype = {
22
- constructor: THREE.MTLLoader,
23
-
24
- crossOrigin: "anonymous",
25
-
26
- /**
27
- * Loads and parses a MTL asset from a URL.
28
- *
29
- * @param {String} url - URL to the MTL file.
30
- * @param {Function} [onLoad] - Callback invoked with the loaded object.
31
- * @param {Function} [onProgress] - Callback for download progress.
32
- * @param {Function} [onError] - Callback for download errors.
33
- *
34
- * @see setPath setResourcePath
35
- *
36
- * @note In order for relative texture references to resolve correctly
37
- * you must call setResourcePath() explicitly prior to load.
38
- */
39
- load: function(url, onLoad, onProgress, onError) {
40
- var scope = this;
41
-
42
- var path = this.path === undefined ? THREE.LoaderUtils.extractUrlBase(url) : this.path;
43
-
44
- var loader = new THREE.FileLoader(this.manager);
45
- loader.setPath(this.path);
46
- loader.load(
47
- url,
48
- function(text) {
49
- onLoad(scope.parse(text, path));
50
- },
51
- onProgress,
52
- onError
53
- );
54
- },
55
-
56
- /**
57
- * Set base path for resolving references.
58
- * If set this path will be prepended to each loaded and found reference.
59
- *
60
- * @see setResourcePath
61
- * @param {String} path
62
- * @return {THREE.MTLLoader}
63
- *
64
- * @example
65
- * mtlLoader.setPath( 'assets/obj/' );
66
- * mtlLoader.load( 'my.mtl', ... );
67
- */
68
- setPath: function(path) {
69
- this.path = path;
70
- return this;
71
- },
72
-
73
- /**
74
- * Set base path for additional resources like textures.
75
- *
76
- * @see setPath
77
- * @param {String} path
78
- * @return {THREE.MTLLoader}
79
- *
80
- * @example
81
- * mtlLoader.setPath( 'assets/obj/' );
82
- * mtlLoader.setResourcePath( 'assets/textures/' );
83
- * mtlLoader.load( 'my.mtl', ... );
84
- */
85
- setResourcePath: function(path) {
86
- this.resourcePath = path;
87
- return this;
88
- },
89
-
90
- setTexturePath: function(path) {
91
- console.warn("THREE.MTLLoader: .setTexturePath() has been renamed to .setResourcePath().");
92
- return this.setResourcePath(path);
93
- },
94
-
95
- setCrossOrigin: function(value) {
96
- this.crossOrigin = value;
97
- return this;
98
- },
99
-
100
- setMaterialOptions: function(value) {
101
- this.materialOptions = value;
102
- return this;
103
- },
104
-
105
- /**
106
- * Parses a MTL file.
107
- *
108
- * @param {String} text - Content of MTL file
109
- * @return {THREE.MTLLoader.MaterialCreator}
110
- *
111
- * @see setPath setResourcePath
112
- *
113
- * @note In order for relative texture references to resolve correctly
114
- * you must call setResourcePath() explicitly prior to parse.
115
- */
116
- parse: function(text, path) {
117
- var lines = text.split("\n");
118
- var info = {};
119
- var delimiter_pattern = /\s+/;
120
- var materialsInfo = {};
121
-
122
- for (var i = 0; i < lines.length; i++) {
123
- var line = lines[i];
124
- line = line.trim();
125
-
126
- if (line.length === 0 || line.charAt(0) === "#") {
127
- // Blank line or comment ignore
128
- continue;
129
- }
130
-
131
- var pos = line.indexOf(" ");
132
-
133
- var key = pos >= 0 ? line.substring(0, pos) : line;
134
- key = key.toLowerCase();
135
-
136
- var value = pos >= 0 ? line.substring(pos + 1) : "";
137
- value = value.trim();
138
-
139
- if (key === "newmtl") {
140
- // New material
141
-
142
- info = { name: value };
143
- materialsInfo[value] = info;
144
- } else {
145
- if (key === "ka" || key === "kd" || key === "ks" || key === "ke") {
146
- var ss = value.split(delimiter_pattern, 3);
147
- info[key] = [parseFloat(ss[0]), parseFloat(ss[1]), parseFloat(ss[2])];
148
- } else {
149
- info[key] = value;
150
- }
151
- }
152
- }
153
-
154
- var materialCreator = new THREE.MTLLoader.MaterialCreator(
155
- this.resourcePath || path,
156
- this.materialOptions
157
- );
158
- materialCreator.setCrossOrigin(this.crossOrigin);
159
- materialCreator.setManager(this.manager);
160
- materialCreator.setMaterials(materialsInfo);
161
- return materialCreator;
162
- },
163
- };
164
-
165
- /**
166
- * Create a new THREE-MTLLoader.MaterialCreator
167
- * @param baseUrl - Url relative to which textures are loaded
168
- * @param options - Set of options on how to construct the materials
169
- * side: Which side to apply the material
170
- * THREE.FrontSide (default), THREE.BackSide, THREE.DoubleSide
171
- * wrap: What type of wrapping to apply for textures
172
- * THREE.RepeatWrapping (default), THREE.ClampToEdgeWrapping, THREE.MirroredRepeatWrapping
173
- * normalizeRGB: RGBs need to be normalized to 0-1 from 0-255
174
- * Default: false, assumed to be already normalized
175
- * ignoreZeroRGBs: Ignore values of RGBs (Ka,Kd,Ks) that are all 0's
176
- * Default: false
177
- * @constructor
178
- */
179
-
180
- THREE.MTLLoader.MaterialCreator = function(baseUrl, options) {
181
- this.baseUrl = baseUrl || "";
182
- this.options = options;
183
- this.materialsInfo = {};
184
- this.materials = {};
185
- this.materialsArray = [];
186
- this.nameLookup = {};
187
-
188
- this.side = this.options && this.options.side ? this.options.side : THREE.FrontSide;
189
- this.wrap = this.options && this.options.wrap ? this.options.wrap : THREE.RepeatWrapping;
190
- };
191
-
192
- THREE.MTLLoader.MaterialCreator.prototype = {
193
- constructor: THREE.MTLLoader.MaterialCreator,
194
-
195
- crossOrigin: "anonymous",
196
-
197
- setCrossOrigin: function(value) {
198
- this.crossOrigin = value;
199
- return this;
200
- },
201
-
202
- setManager: function(value) {
203
- this.manager = value;
204
- },
205
-
206
- setMaterials: function(materialsInfo) {
207
- this.materialsInfo = this.convert(materialsInfo);
208
- this.materials = {};
209
- this.materialsArray = [];
210
- this.nameLookup = {};
211
- },
212
-
213
- convert: function(materialsInfo) {
214
- if (!this.options) return materialsInfo;
215
-
216
- var converted = {};
217
-
218
- for (var mn in materialsInfo) {
219
- // Convert materials info into normalized form based on options
220
-
221
- var mat = materialsInfo[mn];
222
-
223
- var covmat = {};
224
-
225
- converted[mn] = covmat;
226
-
227
- for (var prop in mat) {
228
- var save = true;
229
- var value = mat[prop];
230
- var lprop = prop.toLowerCase();
231
-
232
- switch (lprop) {
233
- case "kd":
234
- case "ka":
235
- case "ks":
236
- // Diffuse color (color under white light) using RGB values
237
-
238
- if (this.options && this.options.normalizeRGB) {
239
- value = [value[0] / 255, value[1] / 255, value[2] / 255];
240
- }
241
-
242
- if (this.options && this.options.ignoreZeroRGBs) {
243
- if (value[0] === 0 && value[1] === 0 && value[2] === 0) {
244
- // ignore
245
-
246
- save = false;
247
- }
248
- }
249
-
250
- break;
251
-
252
- default:
253
- break;
254
- }
255
-
256
- if (save) {
257
- covmat[lprop] = value;
258
- }
259
- }
260
- }
261
-
262
- return converted;
263
- },
264
-
265
- preload: function() {
266
- for (var mn in this.materialsInfo) {
267
- this.create(mn);
268
- }
269
- },
270
-
271
- getIndex: function(materialName) {
272
- return this.nameLookup[materialName];
273
- },
274
-
275
- getAsArray: function() {
276
- var index = 0;
277
-
278
- for (var mn in this.materialsInfo) {
279
- this.materialsArray[index] = this.create(mn);
280
- this.nameLookup[mn] = index;
281
- index++;
282
- }
283
-
284
- return this.materialsArray;
285
- },
286
-
287
- create: function(materialName) {
288
- if (this.materials[materialName] === undefined) {
289
- this.createMaterial_(materialName);
290
- }
291
-
292
- return this.materials[materialName];
293
- },
294
-
295
- createMaterial_: function(materialName) {
296
- // Create material
297
-
298
- var scope = this;
299
- var mat = this.materialsInfo[materialName];
300
- var params = {
301
- name: materialName,
302
- side: this.side,
303
- };
304
-
305
- function resolveURL(baseUrl, url) {
306
- if (typeof url !== "string" || url === "") return "";
307
-
308
- // Absolute URL
309
- if (/^https?:\/\//i.test(url)) return url;
310
-
311
- return baseUrl + url;
312
- }
313
-
314
- function setMapForType(mapType, value) {
315
- if (params[mapType]) return; // Keep the first encountered texture
316
-
317
- var texParams = scope.getTextureParams(value, params);
318
- var map = scope.loadTexture(resolveURL(scope.baseUrl, texParams.url));
319
-
320
- map.repeat.copy(texParams.scale);
321
- map.offset.copy(texParams.offset);
322
-
323
- map.wrapS = scope.wrap;
324
- map.wrapT = scope.wrap;
325
-
326
- params[mapType] = map;
327
- }
328
-
329
- for (var prop in mat) {
330
- var value = mat[prop];
331
- var n;
332
-
333
- if (value === "") continue;
334
-
335
- switch (prop.toLowerCase()) {
336
- // Ns is material specular exponent
337
-
338
- case "kd":
339
- // Diffuse color (color under white light) using RGB values
340
-
341
- params.color = new THREE.Color().fromArray(value);
342
-
343
- break;
344
-
345
- case "ks":
346
- // Specular color (color when light is reflected from shiny surface) using RGB values
347
- params.specular = new THREE.Color().fromArray(value);
348
-
349
- break;
350
-
351
- case "ke":
352
- // Emissive using RGB values
353
- params.emissive = new THREE.Color().fromArray(value);
354
-
355
- break;
356
-
357
- case "map_kd":
358
- // Diffuse texture map
359
-
360
- setMapForType("map", value);
361
-
362
- break;
363
-
364
- case "map_ks":
365
- // Specular map
366
-
367
- setMapForType("specularMap", value);
368
-
369
- break;
370
-
371
- case "map_ke":
372
- // Emissive map
373
-
374
- setMapForType("emissiveMap", value);
375
-
376
- break;
377
-
378
- case "norm":
379
- setMapForType("normalMap", value);
380
-
381
- break;
382
-
383
- case "map_bump":
384
- case "bump":
385
- // Bump texture map
386
-
387
- setMapForType("bumpMap", value);
388
-
389
- break;
390
-
391
- case "map_d":
392
- // Alpha map
393
-
394
- setMapForType("alphaMap", value);
395
- params.transparent = true;
396
-
397
- break;
398
-
399
- case "map_pm":
400
- // Metalness map
401
-
402
- setMapForType("metalnessMap", value);
403
-
404
- // fine-tune the metalness value if needed
405
- //params.metalness = 0.2;
406
-
407
- break;
408
-
409
- case "map_pr":
410
- // Roughness map
411
-
412
- setMapForType("roughnessMap", value);
413
-
414
- // fine-tune the roughness value if needed
415
- //params.roughness = 0.1;
416
-
417
- break;
418
-
419
- case "ns":
420
- // The specular exponent (defines the focus of the specular highlight)
421
- // A high exponent results in a tight, concentrated highlight. Ns values normally range from 0 to 1000.
422
-
423
- params.shininess = parseFloat(value);
424
-
425
- break;
426
-
427
- case "d":
428
- n = parseFloat(value);
429
-
430
- if (n < 1) {
431
- params.opacity = n;
432
- params.transparent = true;
433
- }
434
-
435
- break;
436
-
437
- case "tr":
438
- n = parseFloat(value);
439
-
440
- if (this.options && this.options.invertTrProperty) n = 1 - n;
441
-
442
- if (n > 0) {
443
- params.opacity = 1 - n;
444
- params.transparent = true;
445
- }
446
-
447
- break;
448
-
449
- default:
450
- break;
451
- }
452
- }
453
-
454
- this.materials[materialName] = new THREE.MeshStandardMaterial(params);
455
- return this.materials[materialName];
456
- },
457
-
458
- getTextureParams: function(value, matParams) {
459
- var texParams = {
460
- scale: new THREE.Vector2(1, 1),
461
- offset: new THREE.Vector2(0, 0),
462
- };
463
-
464
- var items = value.split(/\s+/);
465
- var pos;
466
-
467
- pos = items.indexOf("-bm");
468
-
469
- if (pos >= 0) {
470
- matParams.bumpScale = parseFloat(items[pos + 1]);
471
- items.splice(pos, 2);
472
- }
473
-
474
- pos = items.indexOf("-s");
475
-
476
- if (pos >= 0) {
477
- texParams.scale.set(parseFloat(items[pos + 1]), parseFloat(items[pos + 2]));
478
- items.splice(pos, 4); // we expect 3 parameters here!
479
- }
480
-
481
- pos = items.indexOf("-o");
482
-
483
- if (pos >= 0) {
484
- texParams.offset.set(parseFloat(items[pos + 1]), parseFloat(items[pos + 2]));
485
- items.splice(pos, 4); // we expect 3 parameters here!
486
- }
487
-
488
- texParams.url = items.join(" ").trim();
489
- return texParams;
490
- },
491
-
492
- loadTexture: function(url, mapping, onLoad, onProgress, onError) {
493
- var texture;
494
- var manager = this.manager !== undefined ? this.manager : THREE.DefaultLoadingManager;
495
- var loader = manager.getHandler(url);
496
-
497
- if (loader === null) {
498
- loader = new THREE.TextureLoader(manager);
499
- }
500
-
501
- if (loader.setCrossOrigin) loader.setCrossOrigin(this.crossOrigin);
502
- texture = loader.load(url, onLoad, onProgress, onError);
503
-
504
- if (mapping !== undefined) texture.mapping = mapping;
505
-
506
- return texture;
507
- },
508
- };
509
-
510
- // important: don't forget to export it
511
-
512
- export default THREE.MTLLoader;