redhotmagma-visualization 1.28.0-beta.2 → 1.28.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 (96) hide show
  1. package/README.md +4 -11
  2. package/babel.config.js +41 -0
  3. package/package.json +72 -6
  4. package/public/libs/draco/README.md +32 -0
  5. package/public/libs/draco/draco_decoder.js +52 -0
  6. package/public/libs/draco/draco_decoder.wasm +0 -0
  7. package/public/libs/draco/draco_encoder.js +33 -0
  8. package/public/libs/draco/draco_wasm_wrapper.js +104 -0
  9. package/public/libs/draco/gltf/draco_decoder.js +48 -0
  10. package/public/libs/draco/gltf/draco_decoder.wasm +0 -0
  11. package/public/libs/draco/gltf/draco_encoder.js +33 -0
  12. package/public/libs/draco/gltf/draco_wasm_wrapper.js +104 -0
  13. package/scripts/cpPath.js +151 -0
  14. package/scripts/cpPublic.js +39 -0
  15. package/scripts/moveLibToPackageRoot.js +44 -0
  16. package/scripts/utils/fileSystem.js +69 -0
  17. package/scripts/utils/process.js +19 -0
  18. package/src/CommonUtils/Observable.js +0 -1
  19. package/src/CommonUtils/pointerEvent.js +1 -2
  20. package/src/DevApp.js +1 -2
  21. package/src/FallbackVisualization.js +5 -1
  22. package/src/PrintingEffects/DomingEffect.js +0 -1
  23. package/src/PrintingEffects/EmbroideryEffect.js +2 -3
  24. package/src/React/ReactBase.js +1 -1
  25. package/src/Three/Controls/OrbitControls.js +0 -2
  26. package/src/Three/Loaders/ColladaLoader.js +294 -111
  27. package/src/Three/Loaders/MTLLoader.js +0 -2
  28. package/src/Three/Loaders/OBJLoader.js +0 -2
  29. package/src/Three/Three2D.js +6 -7
  30. package/src/Three/Three3D.js +1 -9
  31. package/src/Three/ThreeBase.js +1 -10
  32. package/src/Utils/DesignArea/getDesignAreaCanvasSize.js +0 -1
  33. package/src/Utils/TextureBuilder/createTextureBuilder.js +0 -2
  34. package/src/Utils/imagePreloader.js +0 -1
  35. package/src/Utils/initTextureCanvas.js +0 -3
  36. package/src/Utils/isMobileDevice.js +0 -2
  37. package/src/Utils/optimizeTextureImage.js +0 -1
  38. package/src/VisualizationContainer.js +1 -3
  39. package/src/VisualizationInterface.js +1 -10
  40. package/tsconfig.json +22 -0
  41. package/AlignTargetProvider.js +0 -129
  42. package/CommonUtils/Deferred.js +0 -135
  43. package/CommonUtils/Observable.js +0 -126
  44. package/CommonUtils/PropertyObserver.js +0 -61
  45. package/CommonUtils/SyncCurrentFunction.js +0 -59
  46. package/CommonUtils/SyncObservableEvent.js +0 -19
  47. package/CommonUtils/pointerEvent.js +0 -415
  48. package/Constants.js +0 -23
  49. package/DevApp.js +0 -1049
  50. package/ExposedModules.js +0 -26
  51. package/FallbackVisualization.js +0 -26
  52. package/PrintingEffects/ColorEmbossingEffect.js +0 -58
  53. package/PrintingEffects/DomingEffect.js +0 -150
  54. package/PrintingEffects/EmbossingEffect.js +0 -65
  55. package/PrintingEffects/EmbroideryEffect.js +0 -541
  56. package/PrintingEffects/EngravingEffect.js +0 -65
  57. package/PrintingEffects/PrintingEffects.js +0 -117
  58. package/PrintingEffects/PrintingEffectsUtils.js +0 -53
  59. package/PrintingEffects/resources/embroidery_multiply.jpg +0 -0
  60. package/PrintingEffects/resources/embroidery_screen.jpg +0 -0
  61. package/React/ReactBase.js +0 -111
  62. package/Three/Controls/OrbitControls.js +0 -745
  63. package/Three/Exporters/glTFExporter.js +0 -48
  64. package/Three/Loaders/ColladaLoader.js +0 -2916
  65. package/Three/Loaders/MTLLoader.js +0 -449
  66. package/Three/Loaders/OBJLoader.js +0 -548
  67. package/Three/Three2D.js +0 -1778
  68. package/Three/Three2DLayers.js +0 -504
  69. package/Three/Three3D.js +0 -1412
  70. package/Three/Three3DScene.js +0 -1432
  71. package/Three/ThreeBase.js +0 -722
  72. package/Utils/DesignArea/getDesignAreaCanvasSize.js +0 -32
  73. package/Utils/TextureBuilder/createTextureBuilder.js +0 -334
  74. package/Utils/TextureBuilder/textureBuilderFunctions.js +0 -87
  75. package/Utils/alignToElement.js +0 -58
  76. package/Utils/createAlphaMapFromAlphaChannel.js +0 -50
  77. package/Utils/createCache.js +0 -46
  78. package/Utils/createCanvas.js +0 -29
  79. package/Utils/createImageRepository.js +0 -124
  80. package/Utils/disposeMaterial.js +0 -41
  81. package/Utils/getImageSize.js +0 -15
  82. package/Utils/imagePreloader.js +0 -76
  83. package/Utils/initTextureCanvas.js +0 -49
  84. package/Utils/isMobileDevice.js +0 -19
  85. package/Utils/optimizeTextureImage.js +0 -73
  86. package/Utils/rememberCameraViewOffset.js +0 -21
  87. package/Utils/removeObject.js +0 -22
  88. package/Utils/restrictCameraMovement.js +0 -45
  89. package/Utils/setOrthographicCameraSize.js +0 -16
  90. package/Utils/updateFitSizeToElement.js +0 -39
  91. package/VisualizationContainer.js +0 -279
  92. package/VisualizationInterface.js +0 -293
  93. package/VisualizationProvider.js +0 -38
  94. package/__mocks__/exportedSample.svg +0 -45
  95. package/index.js +0 -16
  96. package/visualizationAdapterCreator.js +0 -76
@@ -1,1432 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Three3DScene = void 0;
7
-
8
- var _three = require("three");
9
-
10
- var _Three3D2 = require("./Three3D");
11
-
12
- var _isMobileDevice = require("../Utils/isMobileDevice");
13
-
14
- var _GLTFLoader = require("three/examples/jsm/loaders/GLTFLoader");
15
-
16
- var _DRACOLoader = require("three/examples/jsm/loaders/DRACOLoader");
17
-
18
- var _get = _interopRequireDefault(require("lodash/get"));
19
-
20
- var _size = _interopRequireDefault(require("lodash/size"));
21
-
22
- var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
23
-
24
- var _glTFExporter = require("./Exporters/glTFExporter");
25
-
26
- var _findIndex = _interopRequireDefault(require("lodash/findIndex"));
27
-
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
29
-
30
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
31
-
32
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
33
-
34
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
35
-
36
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
37
-
38
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
39
-
40
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
41
-
42
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
43
-
44
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
45
-
46
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
47
-
48
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
49
-
50
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
51
-
52
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
53
-
54
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
55
-
56
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
57
-
58
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
59
-
60
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
61
-
62
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
63
-
64
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
65
-
66
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
67
-
68
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
69
-
70
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
71
-
72
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
73
-
74
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
75
-
76
- var UNSET = Symbol("unset");
77
- var allowedObjectProps = ["position", "rotation", "scale"];
78
-
79
- function getSrc(item) {
80
- return item && (item.model || item.src);
81
- }
82
-
83
- function getPatch(oldObj, newObj) {
84
- var patch = {};
85
- newObj && Object.keys(newObj).forEach(function (prop) {
86
- if ((0, _isPlainObject["default"])(newObj[prop])) {
87
- var objPatch = getPatch(oldObj && oldObj[prop], newObj[prop]);
88
-
89
- if (Object.keys(objPatch).length) {
90
- patch[prop] = objPatch;
91
- }
92
- } else {
93
- patch[prop] = newObj[prop];
94
- }
95
- });
96
- oldObj && Object.keys(oldObj).forEach(function (prop) {
97
- if (!newObj.hasOwnProperty(prop)) {
98
- if ((0, _isPlainObject["default"])(_typeof(newObj[prop]))) {
99
- var objPatch = getPatch(oldObj[prop], newObj[prop]);
100
-
101
- if (Object.keys(objPatch).length) {
102
- patch[prop] = objPatch;
103
- }
104
- } else {
105
- patch[prop] = UNSET;
106
- }
107
- }
108
- });
109
- return patch;
110
- }
111
-
112
- function disposeNonUsedObjects(root, disposeTarget) {
113
- var disposableObjects = [];
114
- disposeTarget.traverse(function (_ref) {
115
- var geometry = _ref.geometry,
116
- material = _ref.material;
117
- geometry && disposableObjects.push(geometry);
118
- material && disposableObjects.push(material);
119
- material && disposableObjects.push.apply(disposableObjects, _toConsumableArray(Object.values(material).filter(function (value) {
120
- return value && value.isTexture;
121
- })));
122
- });
123
- var referencedObjects = [];
124
- root.traverse(function (_ref2) {
125
- var geometry = _ref2.geometry,
126
- material = _ref2.material;
127
- geometry && referencedObjects.push(geometry);
128
- material && referencedObjects.push(material);
129
- material && referencedObjects.push.apply(referencedObjects, _toConsumableArray(Object.values(material).filter(function (value) {
130
- return value && value.isTexture;
131
- })));
132
- });
133
-
134
- for (var _i = 0, _disposableObjects = disposableObjects; _i < _disposableObjects.length; _i++) {
135
- var object = _disposableObjects[_i];
136
-
137
- if (referencedObjects.indexOf(object) === -1) {
138
- object.dispose();
139
- }
140
- }
141
- }
142
-
143
- function getMaterials(tree) {
144
- var materials = {};
145
- tree.traverse(function (_ref3) {
146
- var material = _ref3.material;
147
-
148
- if (material) {
149
- materials[material.name] = material;
150
- }
151
- });
152
- return materials;
153
- }
154
-
155
- function getAllMaterials(tree) {
156
- var materials = [];
157
- tree.traverse(function (_ref4) {
158
- var material = _ref4.material;
159
-
160
- if (material && materials.indexOf(material) === -1) {
161
- materials.push(material);
162
- }
163
- });
164
- return materials;
165
- }
166
-
167
- function findImageBySrc(tree, src) {
168
- var result = null;
169
- tree.traverse(function (_ref5) {
170
- var material = _ref5.material;
171
-
172
- if (!result && material) {
173
- for (var _i2 = 0, _Object$values = Object.values(material); _i2 < _Object$values.length; _i2++) {
174
- var value = _Object$values[_i2];
175
-
176
- if (value && value.isTexture && value.image && value.image.src === src) {
177
- result = value.image;
178
- }
179
- }
180
- }
181
- });
182
- return result;
183
- }
184
-
185
- function setLightShadow(light) {
186
- var d = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
187
-
188
- // directional light has orthographic camera (due to the parallel ray direction)
189
- if (light.isDirectionalLight) {
190
- light.castShadow = true;
191
- light.shadow.mapSize.width = 1024;
192
- light.shadow.mapSize.height = 1024;
193
- light.shadow.camera.top = d;
194
- light.shadow.camera.bottom = -d;
195
- light.shadow.camera.left = -d;
196
- light.shadow.camera.right = d;
197
- light.shadow.camera.near = 0.0001;
198
- light.shadow.camera.far = 10000;
199
- light.shadow.camera.updateProjectionMatrix();
200
- }
201
- }
202
-
203
- function createIndexCounter() {
204
- var counters = {};
205
-
206
- var add = function add(index) {
207
- if (undefined === counters[index]) {
208
- counters[index] = 0;
209
- } else {
210
- counters[index]++;
211
- }
212
-
213
- return counters[index];
214
- };
215
-
216
- var reset = function reset() {
217
- counters = {};
218
- };
219
-
220
- return {
221
- add: add,
222
- reset: reset
223
- };
224
- }
225
-
226
- function diffResourceLists(oldList, newList) {
227
- var toBeRemoved = [];
228
- var toBeAdded = [];
229
- var toBeUpdated = [];
230
- var toBeApplied = [];
231
- var indexCounter = createIndexCounter();
232
-
233
- var _iterator = _createForOfIteratorHelper(oldList),
234
- _step;
235
-
236
- try {
237
- var _loop = function _loop() {
238
- var item = _step.value;
239
- var src = getSrc(item);
240
-
241
- if (!src) {
242
- return "continue";
243
- }
244
-
245
- var index = indexCounter.add(src);
246
- var newItem = newList.filter(function (newItem) {
247
- return getSrc(newItem) === src;
248
- })[index];
249
-
250
- if (!newItem) {
251
- toBeRemoved.push(_objectSpread(_objectSpread({}, item), {}, {
252
- index: index
253
- }));
254
- } else {
255
- var patch = getPatch(item, newItem);
256
-
257
- if (Object.keys(patch).length) {
258
- toBeUpdated.push(_objectSpread(_objectSpread({}, patch), {}, {
259
- model: src,
260
- index: index
261
- }));
262
- }
263
- }
264
- };
265
-
266
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
267
- var _ret = _loop();
268
-
269
- if (_ret === "continue") continue;
270
- }
271
- } catch (err) {
272
- _iterator.e(err);
273
- } finally {
274
- _iterator.f();
275
- }
276
-
277
- indexCounter.reset();
278
-
279
- var _iterator2 = _createForOfIteratorHelper(newList),
280
- _step2;
281
-
282
- try {
283
- var _loop2 = function _loop2() {
284
- var item = _step2.value;
285
- var src = getSrc(item);
286
-
287
- if (!src) {
288
- item.params && toBeApplied.push(item);
289
- return "continue";
290
- }
291
-
292
- var index = indexCounter.add(src);
293
-
294
- if (!oldList.filter(function (oldItem) {
295
- return getSrc(oldItem) === src;
296
- })[index]) {
297
- toBeAdded.push(_objectSpread(_objectSpread({}, item), {}, {
298
- index: index
299
- }));
300
- }
301
- };
302
-
303
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
304
- var _ret2 = _loop2();
305
-
306
- if (_ret2 === "continue") continue;
307
- }
308
- } catch (err) {
309
- _iterator2.e(err);
310
- } finally {
311
- _iterator2.f();
312
- }
313
-
314
- return {
315
- toBeRemoved: toBeRemoved,
316
- toBeAdded: toBeAdded,
317
- toBeUpdated: toBeUpdated,
318
- toBeApplied: toBeApplied
319
- };
320
- }
321
-
322
- function findObjectWith(root, testFn) {
323
- var result = null;
324
- root.traverse(function (object) {
325
- if (!result && testFn(object)) {
326
- result = object;
327
- }
328
- });
329
- return result;
330
- }
331
-
332
- function findAllObjectsWith(root, testFn) {
333
- var result = [];
334
- root.traverse(function (object) {
335
- return testFn(object) && result.push(object);
336
- });
337
- return result;
338
- }
339
-
340
- function mapObjectValues(object, valueMap) {
341
- return Object.keys(object).reduce(function (res, key) {
342
- return _objectSpread(_objectSpread({}, res), {}, _defineProperty({}, key, valueMap && valueMap[object[key]] || object[key]));
343
- }, {});
344
- }
345
-
346
- function setCameraAspectFromRendererSize(camera, renderer) {
347
- var _renderer$domElement = renderer.domElement,
348
- width = _renderer$domElement.width,
349
- height = _renderer$domElement.height;
350
- camera.aspect = width / height;
351
- camera.updateProjectionMatrix();
352
- }
353
-
354
- var Three3DScene = /*#__PURE__*/function (_Three3D) {
355
- _inherits(Three3DScene, _Three3D);
356
-
357
- var _super = _createSuper(Three3DScene);
358
-
359
- function Three3DScene() {
360
- var _this;
361
-
362
- var cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
363
-
364
- _classCallCheck(this, Three3DScene);
365
-
366
- _this = _super.call(this, cfg);
367
-
368
- _defineProperty(_assertThisInitialized(_this), "DefaultCustomizableMaterialKey", "CustomizableMaterial");
369
-
370
- _defineProperty(_assertThisInitialized(_this), "clock", new _three.Clock());
371
-
372
- _defineProperty(_assertThisInitialized(_this), "animations", []);
373
-
374
- _defineProperty(_assertThisInitialized(_this), "currentResourceList", []);
375
-
376
- _defineProperty(_assertThisInitialized(_this), "sceneContainer", function () {
377
- var g = new _three.Group();
378
- g.name = "sceneContainer";
379
- return g;
380
- }());
381
-
382
- _defineProperty(_assertThisInitialized(_this), "mixer", new _three.AnimationMixer(_this.sceneContainer));
383
-
384
- _defineProperty(_assertThisInitialized(_this), "defaultCamera", null);
385
-
386
- _defineProperty(_assertThisInitialized(_this), "dirLightPosition", new _three.Vector3(1, 1, 1).normalize());
387
-
388
- _defineProperty(_assertThisInitialized(_this), "cameraPosition", new _three.Vector3(0, 1, 2).normalize());
389
-
390
- _defineProperty(_assertThisInitialized(_this), "animate", function () {
391
- var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
392
-
393
- if (!_this._isAnimating) {
394
- window.cancelAnimationFrame(_this._animationFrame);
395
- _this._animationFrame = null;
396
- return;
397
- }
398
-
399
- _this._animationFrame = window.requestAnimationFrame(_this.animate);
400
-
401
- if (time) {
402
- var delta = _this.clock.getDelta();
403
-
404
- _this.mixer.update(delta);
405
-
406
- _this.cameraTweenGroup.update(time);
407
-
408
- if (_this.controls) {
409
- _this.controls.update();
410
- }
411
-
412
- _this.render();
413
- }
414
- });
415
-
416
- _defineProperty(_assertThisInitialized(_this), "helpers", {
417
- addDirectionalLightHelper: function addDirectionalLightHelper() {
418
- var _assertThisInitialize = _assertThisInitialized(_this),
419
- dirLight = _assertThisInitialize.dirLight;
420
-
421
- var cameraHelper = new _three.CameraHelper(dirLight.shadow.camera);
422
-
423
- _this.scene.add(cameraHelper);
424
- },
425
- addSceneSphereHelper: function addSceneSphereHelper() {
426
- var box = _this.getSceneContainerBox();
427
-
428
- var sphere = new _three.Sphere();
429
- box.getBoundingSphere(sphere);
430
- var sphereMesh = new _three.Mesh(new _three.SphereGeometry(sphere.radius, 32, 32), new _three.MeshBasicMaterial({
431
- color: 0x66ff66,
432
- wireframe: true
433
- }));
434
- sphereMesh.position.copy(sphere.center);
435
-
436
- _this.scene.add(sphereMesh);
437
- }
438
- });
439
-
440
- cfg.modelBasePath ? _this._modelBasePath = cfg.modelBasePath : _this._modelBasePath = "";
441
- return _this;
442
- }
443
-
444
- _createClass(Three3DScene, [{
445
- key: "createLoadingManager",
446
- value: function createLoadingManager() {
447
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
448
- var _options$basePath = options.basePath,
449
- basePath = _options$basePath === void 0 ? "" : _options$basePath,
450
- _options$resourcePath = options.resourcePath,
451
- resourcePath = _options$resourcePath === void 0 ? "/" : _options$resourcePath;
452
- var _this$_loadingManager = this._loadingManager,
453
- onLoad = _this$_loadingManager.onLoad,
454
- onProgress = _this$_loadingManager.onProgress,
455
- onError = _this$_loadingManager.onError;
456
- var loadingManager = new _three.LoadingManager(onLoad, onProgress, onError);
457
- loadingManager.setURLModifier(function (url) {
458
- if (/^(data|blob):/.test(url)) {
459
- return url;
460
- }
461
-
462
- var fixedBasePath = basePath.replace(/\/$/, "");
463
- return url.indexOf("/") === 0 ? "".concat(fixedBasePath).concat(url) : "".concat(fixedBasePath).concat(resourcePath).concat(url.replace("./", ""));
464
- });
465
- return loadingManager;
466
- }
467
- }, {
468
- key: "createLoader",
469
- value: function createLoader() {
470
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
471
- var loadingManager = this.createLoadingManager(options);
472
- var dracoLoader = new _DRACOLoader.DRACOLoader();
473
- dracoLoader.setDecoderPath("libs/draco/gltf/");
474
- var loader = new _GLTFLoader.GLTFLoader(loadingManager);
475
- loader.setDRACOLoader(dracoLoader);
476
- return loader;
477
- }
478
- }, {
479
- key: "createImageLoader",
480
- value: function createImageLoader() {
481
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
482
- var loadingManager = this.createLoadingManager(options);
483
- var imageLoader = new _three.ImageLoader(loadingManager);
484
- return imageLoader;
485
- }
486
- }, {
487
- key: "createRenderer",
488
- value: function createRenderer() {
489
- var renderer = new _three.WebGLRenderer({
490
- alpha: true,
491
- antialias: true
492
- });
493
- renderer.outputEncoding = _three.sRGBEncoding;
494
- renderer.shadowMap.enabled = true;
495
- renderer.shadowMap.type = _three.PCFSoftShadowMap;
496
- var realWidth = window.innerWidth * window.devicePixelRatio;
497
-
498
- if ((0, _isMobileDevice.isMobileDevice)() && realWidth >= 1024) {
499
- renderer.setPixelRatio(1);
500
- } else {
501
- renderer.setPixelRatio(window.devicePixelRatio);
502
- }
503
-
504
- return renderer;
505
- }
506
- }, {
507
- key: "createCamera",
508
- value: function createCamera() {
509
- var camera = new _three.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.01);
510
- camera.position.copy(this.cameraPosition).multiplyScalar(1000);
511
- return camera;
512
- }
513
- }, {
514
- key: "setupDefaultLightning",
515
- value: function setupDefaultLightning() {}
516
- }, {
517
- key: "loadModel",
518
- value: function loadModel() {}
519
- }, {
520
- key: "createScene",
521
- value: function createScene() {
522
- var scene = new _three.Scene();
523
- scene.add(this.createHemiLight());
524
- scene.add(this.createGround());
525
- scene.add(this.createDirLight());
526
- scene.add(this.sceneContainer);
527
- return scene;
528
- }
529
- }, {
530
- key: "createGround",
531
- value: function createGround() {
532
- var mesh = new _three.Mesh(new _three.PlaneBufferGeometry(1, 1), new _three.MeshPhongMaterial({
533
- color: 0xffffff
534
- }));
535
- mesh.name = "ground";
536
- mesh.rotation.x = -Math.PI / 2;
537
- mesh.receiveShadow = true;
538
- this.ground = mesh;
539
- return mesh;
540
- }
541
- }, {
542
- key: "createHemiLight",
543
- value: function createHemiLight() {
544
- var hemiLight = new _three.HemisphereLight(0xffffff, 0x666666, 0.7);
545
- hemiLight.name = "hemiLight";
546
- hemiLight.position.set(0, 100, 0);
547
- this.hemiLight = hemiLight;
548
- return hemiLight;
549
- }
550
- }, {
551
- key: "createDirLight",
552
- value: function createDirLight() {
553
- var dirLight = new _three.DirectionalLight(0xffffff, 1);
554
- dirLight.name = "dirLight";
555
- dirLight.position.set(1, 1, 1).normalize();
556
- setLightShadow(dirLight);
557
- this.dirLight = dirLight;
558
- return dirLight;
559
- }
560
- }, {
561
- key: "addLightsIfNeeded",
562
- value: function addLightsIfNeeded(scene) {
563
- var sceneHasLight = scene.getObjectByProperty("isLight", true);
564
-
565
- if (!sceneHasLight && !this.dirLight) {
566
- this.scene.add(this.createDirLight());
567
- } else if (sceneHasLight) {
568
- // remove if the scene shipped its own light
569
- this.scene.remove(this.dirLight);
570
- delete this.dirLight;
571
- }
572
- }
573
- }, {
574
- key: "fixImportedScene",
575
- value: function fixImportedScene(scene) {
576
- var _this2 = this;
577
-
578
- scene.traverse(function (object) {
579
- if (object.isMesh) {
580
- object.castShadow = true;
581
- }
582
-
583
- if (object.isLight && object.target) {
584
- object.target = _this2.ground;
585
- setLightShadow(object);
586
- }
587
- });
588
- }
589
- }, {
590
- key: "applyCustomizations",
591
- value: function () {
592
- var _applyCustomizations = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(model, item, imageLoader) {
593
- var _this3 = this;
594
-
595
- var options,
596
- _options$saveAndResto,
597
- saveAndRestore,
598
- params,
599
- material,
600
- _params,
601
- _args3 = arguments;
602
-
603
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
604
- while (1) {
605
- switch (_context3.prev = _context3.next) {
606
- case 0:
607
- options = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : {};
608
- _options$saveAndResto = options.saveAndRestore, saveAndRestore = _options$saveAndResto === void 0 ? true : _options$saveAndResto;
609
- params = item.params;
610
-
611
- if (params) {
612
- Object.keys(params).forEach(function (p) {
613
- // skip not allowed props
614
- if (allowedObjectProps.indexOf(p) === -1) {
615
- return;
616
- } // restore original value first
617
-
618
-
619
- if (params[p] === UNSET) {
620
- if (model.originalValues && model.originalValues[p]) {
621
- model[p].copy(model.originalValues[p]);
622
- }
623
-
624
- return;
625
- } // store original value for later restoration
626
-
627
-
628
- if (!model.originalValues) {
629
- model.originalValues = {};
630
- }
631
-
632
- if (!model.originalValues[p]) {
633
- model.originalValues[p] = model[p] ? model[p].clone() : model[p];
634
- } // apply the param values
635
-
636
-
637
- switch (p) {
638
- case "scale":
639
- {
640
- var _params$p = params[p],
641
- _params$p$x = _params$p.x,
642
- x = _params$p$x === void 0 ? 1 : _params$p$x,
643
- _params$p$y = _params$p.y,
644
- y = _params$p$y === void 0 ? 1 : _params$p$y,
645
- _params$p$z = _params$p.z,
646
- z = _params$p$z === void 0 ? 1 : _params$p$z;
647
- model[p].set(x, y, z);
648
- break;
649
- }
650
-
651
- case "rotation":
652
- case "position":
653
- {
654
- var _params$p2 = params[p],
655
- _params$p2$x = _params$p2.x,
656
- _x4 = _params$p2$x === void 0 ? 0 : _params$p2$x,
657
- _params$p2$y = _params$p2.y,
658
- _y = _params$p2$y === void 0 ? 0 : _params$p2$y,
659
- _params$p2$z = _params$p2.z,
660
- _z = _params$p2$z === void 0 ? 0 : _params$p2$z;
661
-
662
- model[p].set(_x4, _y, _z);
663
- break;
664
- }
665
- }
666
- });
667
- } // store & restore original material and textures before applying new param values
668
-
669
-
670
- saveAndRestore && Object.values(getMaterials(model)).map(function (mat) {
671
- if (!mat.original) {
672
- mat.original = mat.clone();
673
- Object.values(mat).filter(function (value) {
674
- return value && value.isTexture;
675
- }).forEach(function (texture) {
676
- if (!texture.original) {
677
- texture.original = texture.clone();
678
- }
679
- });
680
- } else {
681
- mat.copy(mat.original);
682
- Object.keys(mat).forEach(function (key) {
683
- var value = mat[key];
684
-
685
- if (value && value.original) {
686
- value.copy(value.original);
687
- }
688
- });
689
- mat.needsUpdate = true;
690
- }
691
- }); // set new material params if provided
692
- // the material object should be located under item.params.material
693
- // item.material is only for backward compatibility
694
-
695
- material = params && params.material || item.material;
696
-
697
- if (!material) {
698
- _context3.next = 12;
699
- break;
700
- }
701
-
702
- _params = material.params;
703
- _context3.t0 = _params;
704
-
705
- if (!_context3.t0) {
706
- _context3.next = 12;
707
- break;
708
- }
709
-
710
- _context3.next = 12;
711
- return Promise.all(getAllMaterials(model).map( /*#__PURE__*/function () {
712
- var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(material) {
713
- var materialName, materialNames;
714
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
715
- while (1) {
716
- switch (_context2.prev = _context2.next) {
717
- case 0:
718
- materialName = _params.materialName, materialNames = _params.materialNames; // check materialNames list if provided
719
-
720
- if (!(materialNames instanceof Array && materialNames.indexOf(material.name) === -1)) {
721
- _context2.next = 3;
722
- break;
723
- }
724
-
725
- return _context2.abrupt("return");
726
-
727
- case 3:
728
- if (!(materialName && material.name !== materialName)) {
729
- _context2.next = 5;
730
- break;
731
- }
732
-
733
- return _context2.abrupt("return");
734
-
735
- case 5:
736
- _context2.next = 7;
737
- return Promise.all(Object.keys(_params).map( /*#__PURE__*/function () {
738
- var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(p) {
739
- var texture, value;
740
- return regeneratorRuntime.wrap(function _callee$(_context) {
741
- while (1) {
742
- switch (_context.prev = _context.next) {
743
- case 0:
744
- if (!(_params[p] === UNSET)) {
745
- _context.next = 2;
746
- break;
747
- }
748
-
749
- return _context.abrupt("return");
750
-
751
- case 2:
752
- _context.t0 = p;
753
- _context.next = _context.t0 === "alphaMap" ? 5 : _context.t0 === "aoMap" ? 5 : _context.t0 === "emissiveMap" ? 5 : _context.t0 === "lightMap" ? 5 : _context.t0 === "map" ? 5 : _context.t0 === "metalnessMap" ? 5 : _context.t0 === "normalMap" ? 5 : _context.t0 === "roughnessMap" ? 5 : _context.t0 === "aoMapIntensity" ? 15 : _context.t0 === "emissiveIntensity" ? 15 : _context.t0 === "envMapIntensity" ? 15 : _context.t0 === "lightMapIntensity" ? 15 : _context.t0 === "metalness" ? 15 : _context.t0 === "opacity" ? 15 : _context.t0 === "refractionRatio" ? 15 : _context.t0 === "roughness" ? 15 : _context.t0 === "color" ? 18 : _context.t0 === "emissive" ? 18 : 20;
754
- break;
755
-
756
- case 5:
757
- texture = material[p] || material.map && material.map.clone() || new _three.Texture();
758
- _context.t1 = findImageBySrc(_this3.sceneContainer, "".concat(_this3._modelBasePath).concat(_params[p]));
759
-
760
- if (_context.t1) {
761
- _context.next = 11;
762
- break;
763
- }
764
-
765
- _context.next = 10;
766
- return new Promise(function (resolve, reject) {
767
- return imageLoader.load(_params[p], resolve, undefined, reject);
768
- });
769
-
770
- case 10:
771
- _context.t1 = _context.sent;
772
-
773
- case 11:
774
- texture.image = _context.t1;
775
- texture.needsUpdate = true;
776
- material[p] = texture;
777
- return _context.abrupt("break", 20);
778
-
779
- case 15:
780
- value = parseFloat(_params[p]);
781
-
782
- if (!isNaN(value)) {
783
- material[p] = value;
784
- }
785
-
786
- return _context.abrupt("break", 20);
787
-
788
- case 18:
789
- material[p] = new _three.Color(_params[p]);
790
- return _context.abrupt("break", 20);
791
-
792
- case 20:
793
- case "end":
794
- return _context.stop();
795
- }
796
- }
797
- }, _callee);
798
- }));
799
-
800
- return function (_x6) {
801
- return _ref7.apply(this, arguments);
802
- };
803
- }()));
804
-
805
- case 7:
806
- material.transparent = !!material.alphaMap;
807
- material.needsUpdate = true;
808
-
809
- case 9:
810
- case "end":
811
- return _context2.stop();
812
- }
813
- }
814
- }, _callee2);
815
- }));
816
-
817
- return function (_x5) {
818
- return _ref6.apply(this, arguments);
819
- };
820
- }()));
821
-
822
- case 12:
823
- case "end":
824
- return _context3.stop();
825
- }
826
- }
827
- }, _callee3);
828
- }));
829
-
830
- function applyCustomizations(_x, _x2, _x3) {
831
- return _applyCustomizations.apply(this, arguments);
832
- }
833
-
834
- return applyCustomizations;
835
- }()
836
- }, {
837
- key: "loadSceneContainer",
838
- value: function loadSceneContainer(item) {
839
- var _this4 = this;
840
-
841
- var path;
842
-
843
- var itemType = _typeof(item);
844
-
845
- if ("string" === itemType) {
846
- path = item;
847
- } else if ("object" === itemType) {
848
- path = getSrc(item);
849
- }
850
-
851
- var _this$parseModelPath = this.parseModelPath(path),
852
- resourcePath = _this$parseModelPath.resourcePath,
853
- modelFileName = _this$parseModelPath.modelFileName;
854
-
855
- var loaderOptions = {
856
- basePath: this._modelBasePath,
857
- resourcePath: resourcePath
858
- };
859
- var modelLoader = this.createLoader(loaderOptions);
860
- var imageLoader = this.createImageLoader(loaderOptions);
861
- return new Promise(function (resolve, reject) {
862
- modelLoader.load(modelFileName, /*#__PURE__*/function () {
863
- var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(gltf) {
864
- var model;
865
- return regeneratorRuntime.wrap(function _callee4$(_context4) {
866
- while (1) {
867
- switch (_context4.prev = _context4.next) {
868
- case 0:
869
- model = gltf.scene;
870
- model.userData.path = path;
871
-
872
- if (undefined !== item.index) {
873
- model.userData.index = item.index;
874
- }
875
-
876
- _this4.fixImportedScene(model);
877
-
878
- if (!("object" === itemType)) {
879
- _context4.next = 7;
880
- break;
881
- }
882
-
883
- _context4.next = 7;
884
- return _this4.applyCustomizations(model, item, imageLoader);
885
-
886
- case 7:
887
- resolve(gltf);
888
-
889
- case 8:
890
- case "end":
891
- return _context4.stop();
892
- }
893
- }
894
- }, _callee4);
895
- }));
896
-
897
- return function (_x7) {
898
- return _ref8.apply(this, arguments);
899
- };
900
- }(), undefined, reject);
901
- });
902
- }
903
- }, {
904
- key: "findCustomizableMaterials",
905
- value: function findCustomizableMaterials(materialsObj) {
906
- var _iterator3 = _createForOfIteratorHelper(this._customizableMaterialKeys),
907
- _step3;
908
-
909
- try {
910
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
911
- var key = _step3.value;
912
- var mat = materialsObj[key];
913
-
914
- if (mat) {
915
- this.prepareCustomCanvasForMaterial(mat);
916
- var index = (0, _findIndex["default"])(this._customizableMaterials, {
917
- name: key
918
- });
919
-
920
- if (index === -1) {
921
- this._customizableMaterials.push(mat);
922
- } else if (this._customizableMaterials[index] !== mat) {
923
- this._customizableMaterials[index] = mat;
924
- }
925
- }
926
- }
927
- } catch (err) {
928
- _iterator3.e(err);
929
- } finally {
930
- _iterator3.f();
931
- }
932
- }
933
- }, {
934
- key: "initCustomizableMaterialsIfNeeded",
935
- value: function () {
936
- var _initCustomizableMaterialsIfNeeded = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
937
- var materials;
938
- return regeneratorRuntime.wrap(function _callee5$(_context5) {
939
- while (1) {
940
- switch (_context5.prev = _context5.next) {
941
- case 0:
942
- // reset customizable materials to always find the right one in the loaded scene
943
- this._customizableMaterialKeys.length = 0;
944
- this._customizableMaterials.length = 0;
945
- materials = getMaterials(this.sceneContainer);
946
-
947
- if ((0, _size["default"])(materials)) {
948
- this.guessCustomizableMaterialNameIfNotSet(materials);
949
- this.findCustomizableMaterials(materials);
950
- }
951
-
952
- _context5.next = 6;
953
- return this.dispatchMaterialUpdateEvent();
954
-
955
- case 6:
956
- case "end":
957
- return _context5.stop();
958
- }
959
- }
960
- }, _callee5, this);
961
- }));
962
-
963
- function initCustomizableMaterialsIfNeeded() {
964
- return _initCustomizableMaterialsIfNeeded.apply(this, arguments);
965
- }
966
-
967
- return initCustomizableMaterialsIfNeeded;
968
- }()
969
- }, {
970
- key: "parseModelPath",
971
- value: function parseModelPath(path) {
972
- var matches = path.match(/([^/].+\/)([^/]+)/);
973
-
974
- if (!matches.length) {
975
- throw new Error("Model path cannot be parsed: " + path);
976
- }
977
-
978
- var resourcePath = "/" + matches[1];
979
- var modelFileName = matches[2];
980
- return {
981
- resourcePath: resourcePath,
982
- modelFileName: modelFileName
983
- };
984
- }
985
- }, {
986
- key: "loadScene",
987
- value: function () {
988
- var _loadScene = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(resourceList) {
989
- var _this5 = this;
990
-
991
- var sceneContainer, _diffResourceLists, toBeRemoved, toBeAdded, toBeUpdated, toBeApplied, shouldResetScene, toBeDisposed, triggerLoadEvent, sceneParts, imageLoader, mixer, animations;
992
-
993
- return regeneratorRuntime.wrap(function _callee6$(_context6) {
994
- while (1) {
995
- switch (_context6.prev = _context6.next) {
996
- case 0:
997
- sceneContainer = this.sceneContainer;
998
- this.stopAnimation();
999
- _diffResourceLists = diffResourceLists(this.currentResourceList || [], resourceList || []), toBeRemoved = _diffResourceLists.toBeRemoved, toBeAdded = _diffResourceLists.toBeAdded, toBeUpdated = _diffResourceLists.toBeUpdated, toBeApplied = _diffResourceLists.toBeApplied;
1000
- shouldResetScene = toBeRemoved.length === this.currentResourceList.length;
1001
- shouldResetScene && this.resetScene();
1002
- this.currentResourceList = resourceList;
1003
- toBeDisposed = [];
1004
- toBeRemoved.forEach(function (item) {
1005
- var itemSrc = getSrc(item);
1006
- var object = findObjectWith(sceneContainer, function (_ref9) {
1007
- var userData = _ref9.userData;
1008
- return userData.path === itemSrc && userData.index === item.index;
1009
- });
1010
-
1011
- if (object) {
1012
- object.parent.remove(object);
1013
- toBeDisposed.push(object);
1014
- }
1015
- });
1016
- toBeDisposed.forEach(function (object) {
1017
- return disposeNonUsedObjects(sceneContainer, object);
1018
- });
1019
- triggerLoadEvent = !!(toBeAdded.length || toBeUpdated.length || toBeApplied.length);
1020
- triggerLoadEvent && this.onLoadStart();
1021
- _context6.next = 13;
1022
- return Promise.all(toBeAdded.map(function (item) {
1023
- return _this5.loadSceneContainer(item);
1024
- }));
1025
-
1026
- case 13:
1027
- sceneParts = _context6.sent;
1028
- sceneParts.forEach(function (_ref10) {
1029
- var scene = _ref10.scene,
1030
- animations = _ref10.animations;
1031
- sceneContainer.add(scene); // collect animations
1032
-
1033
- if (animations.length) {
1034
- var _this5$animations;
1035
-
1036
- (_this5$animations = _this5.animations).push.apply(_this5$animations, _toConsumableArray(animations.filter(function (_ref11) {
1037
- var name = _ref11.name;
1038
- return !_this5.animations.find(function (_ref12) {
1039
- var existingName = _ref12.name;
1040
- return name !== existingName;
1041
- });
1042
- })));
1043
- }
1044
- });
1045
- sceneContainer.updateWorldMatrix(true, true);
1046
- _context6.next = 18;
1047
- return Promise.all(toBeUpdated.map(function (item) {
1048
- var itemSrc = getSrc(item);
1049
- var object = findObjectWith(sceneContainer, function (_ref13) {
1050
- var userData = _ref13.userData;
1051
- return userData.path === itemSrc && userData.index === item.index;
1052
- });
1053
- var path = getSrc(item);
1054
-
1055
- var _this5$parseModelPath = _this5.parseModelPath(path),
1056
- resourcePath = _this5$parseModelPath.resourcePath;
1057
-
1058
- var loaderOptions = {
1059
- basePath: _this5._modelBasePath,
1060
- resourcePath: resourcePath
1061
- };
1062
-
1063
- var imageLoader = _this5.createImageLoader(loaderOptions);
1064
-
1065
- return object && _this5.applyCustomizations(object, item, imageLoader);
1066
- }));
1067
-
1068
- case 18:
1069
- // apply global or targeted param values
1070
- imageLoader = this.createImageLoader({
1071
- basePath: this._modelBasePath
1072
- });
1073
- _context6.next = 21;
1074
- return Promise.all(toBeApplied.map(function (_ref14) {
1075
- var optionParams = _ref14.params,
1076
- files = _ref14.files;
1077
- // find model based on objectName
1078
- var objectName = optionParams.objectName,
1079
- _optionParams$materia = optionParams.material,
1080
- material = _optionParams$materia === void 0 ? {} : _optionParams$materia;
1081
- var objects = objectName ? findAllObjectsWith(sceneContainer, function (_ref15) {
1082
- var name = _ref15.name;
1083
- return name === objectName;
1084
- }) : sceneContainer.children;
1085
- var params = material.params;
1086
- var item = {
1087
- params: _objectSpread(_objectSpread({}, optionParams), {}, {
1088
- material: _objectSpread(_objectSpread({}, material), {}, {
1089
- params: params && mapObjectValues(params, files)
1090
- })
1091
- })
1092
- };
1093
- return Promise.all(objects.map(function (object) {
1094
- return _this5.applyCustomizations(object, item, imageLoader, {
1095
- saveAndRestore: false
1096
- });
1097
- }));
1098
- }));
1099
-
1100
- case 21:
1101
- _context6.next = 23;
1102
- return this.initCustomizableMaterialsIfNeeded();
1103
-
1104
- case 23:
1105
- this.addLightsIfNeeded(sceneContainer);
1106
- this.fitSceneToCamera();
1107
- this.initCameraViews(this.getCameras(sceneContainer));
1108
- triggerLoadEvent && this.onLoadFinished(); // start first animation
1109
-
1110
- if (this.animations.length) {
1111
- mixer = this.mixer, animations = this.animations;
1112
- mixer.stopAllAction();
1113
- mixer.uncacheRoot(mixer.getRoot());
1114
- mixer.clipAction(animations[0]).play();
1115
- this.startAnimation("builtin");
1116
- }
1117
-
1118
- if (!this.isAnimating()) {
1119
- this.render();
1120
- }
1121
-
1122
- case 29:
1123
- case "end":
1124
- return _context6.stop();
1125
- }
1126
- }
1127
- }, _callee6, this);
1128
- }));
1129
-
1130
- function loadScene(_x8) {
1131
- return _loadScene.apply(this, arguments);
1132
- }
1133
-
1134
- return loadScene;
1135
- }()
1136
- }, {
1137
- key: "getCameras",
1138
- value: function getCameras() {
1139
- var tree = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.sceneContainer;
1140
- var cameras = [];
1141
- tree.traverse(function (object) {
1142
- if (object.isCamera) {
1143
- cameras.push(object);
1144
- }
1145
- });
1146
- return cameras;
1147
- }
1148
- }, {
1149
- key: "initCameraViews",
1150
- value: function initCameraViews(cameras) {
1151
- var box = this.getSceneContainerBox();
1152
- var center = new _three.Vector3();
1153
- box.getCenter(center);
1154
- this.cameraViews["default"] = null;
1155
- this.cameraViews = cameras.reduce(function (views, camera) {
1156
- var position = new _three.Vector3();
1157
- camera.getWorldPosition(position);
1158
- var distance = position.distanceTo(center);
1159
- var dir = new _three.Vector3();
1160
- camera.getWorldDirection(dir);
1161
- var lookat = dir.multiplyScalar(distance).add(position);
1162
- var rotation = new _three.Quaternion();
1163
- camera.getWorldQuaternion(rotation);
1164
-
1165
- var orientation = _three.Object3D.DefaultUp.clone().applyQuaternion(rotation);
1166
-
1167
- return _objectSpread(_objectSpread({}, views), {}, _defineProperty({}, camera.name.toLowerCase(), {
1168
- position: position,
1169
- lookat: lookat,
1170
- orientation: orientation
1171
- }));
1172
- }, {});
1173
-
1174
- if (!this.cameraViews["default"]) {
1175
- this.cameraViews["default"] = {
1176
- position: this.cameraPosition.clone().multiplyScalar(this.controls.maxDistance * 0.75),
1177
- lookat: center.clone(),
1178
- orientation: new _three.Vector3(0, 1, 0)
1179
- };
1180
- }
1181
- }
1182
- }, {
1183
- key: "resetScene",
1184
- value: function resetScene() {
1185
- this.mixer.stopAllAction().uncacheRoot(this.mixer.getRoot());
1186
- this.sceneContainer.scale.set(1, 1, 1);
1187
- this.defaultCamera = null;
1188
- this.animations.length = 0;
1189
- this._customizableMaterialKeys.length = 0;
1190
- this._customizableMaterials.length = 0;
1191
- }
1192
- }, {
1193
- key: "getSceneContainerBox",
1194
- value: function getSceneContainerBox() {
1195
- var box = new _three.Box3();
1196
- this.sceneContainer.traverse(function (object) {
1197
- if (object.isMesh) {
1198
- box.expandByObject(object);
1199
- }
1200
- });
1201
- return box;
1202
- }
1203
- }, {
1204
- key: "fitSceneToCamera",
1205
- value: function fitSceneToCamera() {
1206
- var controls = this.controls,
1207
- camera = this.camera,
1208
- ground = this.ground,
1209
- dirLight = this.dirLight,
1210
- hemiLight = this.hemiLight;
1211
- var box = this.getSceneContainerBox();
1212
- var fitOffset = 1.2;
1213
- var sphere = new _three.Sphere();
1214
- box.getBoundingSphere(sphere);
1215
-
1216
- if (sphere.radius < 0.001) {
1217
- return;
1218
- }
1219
-
1220
- var minDistance = sphere.radius;
1221
- var fitDistance = sphere.radius / Math.atan(Math.PI * camera.fov / 360);
1222
- var distance = fitOffset * fitDistance;
1223
- var maxDistance = Math.max(minDistance * 5, distance * 1.5); // update scene objects
1224
-
1225
- if (ground) {
1226
- ground.position.y = box.min.y;
1227
- ground.position.x = sphere.center.x;
1228
- ground.position.z = sphere.center.z;
1229
- ground.scale.set(1, 1, 1).multiplyScalar(maxDistance * 2);
1230
- }
1231
-
1232
- if (dirLight) {
1233
- dirLight.position.copy(this.dirLightPosition).multiplyScalar(maxDistance).add(sphere.center);
1234
- this.scene.add(dirLight.target);
1235
- dirLight.target.position.copy(sphere.center);
1236
- setLightShadow(dirLight, minDistance);
1237
- }
1238
-
1239
- if (hemiLight) {
1240
- hemiLight.position.y = maxDistance;
1241
- } // update controls
1242
-
1243
-
1244
- if (minDistance === controls.minDistance) {
1245
- return;
1246
- }
1247
-
1248
- controls.minDistance = minDistance;
1249
- controls.maxDistance = maxDistance;
1250
- camera.near = minDistance * 0.01;
1251
- camera.far = maxDistance * 100;
1252
- camera.position.copy(camera.position.normalize().multiplyScalar(maxDistance * 0.75));
1253
- camera.updateProjectionMatrix();
1254
- controls.target = sphere.center;
1255
- controls.update();
1256
- }
1257
- }, {
1258
- key: "setActiveAnimation",
1259
- value: function setActiveAnimation(animationName) {
1260
- var animation = this.animations.find(function (_ref16) {
1261
- var name = _ref16.name;
1262
- return name === animationName;
1263
- });
1264
-
1265
- if (animation) {
1266
- this.mixer.stopAllAction().clipAction(animation).play();
1267
- }
1268
- }
1269
- }, {
1270
- key: "getAnimations",
1271
- value: function getAnimations() {
1272
- return this.animations;
1273
- }
1274
- }, {
1275
- key: "setActiveCamera",
1276
- value: function setActiveCamera(cameraName) {
1277
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1278
- var _options$updateContro = options.updateControls,
1279
- updateControls = _options$updateContro === void 0 ? false : _options$updateContro,
1280
- _options$setAsDefault = options.setAsDefault,
1281
- setAsDefault = _options$setAsDefault === void 0 ? false : _options$setAsDefault,
1282
- _options$rerender = options.rerender,
1283
- rerender = _options$rerender === void 0 ? true : _options$rerender;
1284
- var originalCamera = !cameraName || cameraName === "default" ? this.defaultCamera : this.scene.getObjectByName(cameraName);
1285
-
1286
- if (originalCamera) {
1287
- var view = this.camera.view;
1288
- var camera = originalCamera.clone();
1289
- camera.view = view;
1290
- setCameraAspectFromRendererSize(camera, this.renderer);
1291
- this.camera = camera;
1292
- camera.updateProjectionMatrix();
1293
-
1294
- if (updateControls && this.controls) {
1295
- this.controls.object = camera;
1296
- }
1297
-
1298
- if (setAsDefault) {
1299
- this.defaultCamera = originalCamera;
1300
- }
1301
-
1302
- if (rerender) {
1303
- this.render();
1304
- }
1305
- }
1306
- }
1307
- }, {
1308
- key: "update",
1309
- value: function () {
1310
- var _update = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(configuration) {
1311
- var sceneData;
1312
- return regeneratorRuntime.wrap(function _callee7$(_context7) {
1313
- while (1) {
1314
- switch (_context7.prev = _context7.next) {
1315
- case 0:
1316
- this._configuration = configuration;
1317
- sceneData = (0, _get["default"])(configuration, "visualizationData.sceneData", false) || (0, _get["default"])(configuration, "visualizationData.designViews[0].models.".concat(this._materialVariantPath), false);
1318
- _context7.t0 = sceneData;
1319
-
1320
- if (!_context7.t0) {
1321
- _context7.next = 6;
1322
- break;
1323
- }
1324
-
1325
- _context7.next = 6;
1326
- return this.loadScene(sceneData);
1327
-
1328
- case 6:
1329
- case "end":
1330
- return _context7.stop();
1331
- }
1332
- }
1333
- }, _callee7, this);
1334
- }));
1335
-
1336
- function update(_x9) {
1337
- return _update.apply(this, arguments);
1338
- }
1339
-
1340
- return update;
1341
- }()
1342
- }, {
1343
- key: "updateMaterial",
1344
- value: function () {
1345
- var _updateMaterial = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
1346
- var sceneData;
1347
- return regeneratorRuntime.wrap(function _callee8$(_context8) {
1348
- while (1) {
1349
- switch (_context8.prev = _context8.next) {
1350
- case 0:
1351
- sceneData = (0, _get["default"])(this._designAreaList, "[0].designView.models.".concat(this._materialVariantPath)) || (0, _get["default"])(this._configuration, "visualizationData.designViews[0].models.".concat(this._materialVariantPath)) || false;
1352
- _context8.t0 = sceneData;
1353
-
1354
- if (!_context8.t0) {
1355
- _context8.next = 5;
1356
- break;
1357
- }
1358
-
1359
- _context8.next = 5;
1360
- return this.loadScene(sceneData);
1361
-
1362
- case 5:
1363
- case "end":
1364
- return _context8.stop();
1365
- }
1366
- }
1367
- }, _callee8, this);
1368
- }));
1369
-
1370
- function updateMaterial() {
1371
- return _updateMaterial.apply(this, arguments);
1372
- }
1373
-
1374
- return updateMaterial;
1375
- }()
1376
- }, {
1377
- key: "updateDesignAreaList",
1378
- value: function () {
1379
- var _updateDesignAreaList = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9(designAreaList) {
1380
- var sceneData;
1381
- return regeneratorRuntime.wrap(function _callee9$(_context9) {
1382
- while (1) {
1383
- switch (_context9.prev = _context9.next) {
1384
- case 0:
1385
- this._designAreaList = designAreaList;
1386
- sceneData = (0, _get["default"])(designAreaList, "[0].designView.models.".concat(this._materialVariantPath));
1387
- _context9.t0 = sceneData;
1388
-
1389
- if (!_context9.t0) {
1390
- _context9.next = 6;
1391
- break;
1392
- }
1393
-
1394
- _context9.next = 6;
1395
- return this.loadScene(sceneData);
1396
-
1397
- case 6:
1398
- case "end":
1399
- return _context9.stop();
1400
- }
1401
- }
1402
- }, _callee9, this);
1403
- }));
1404
-
1405
- function updateDesignAreaList(_x10) {
1406
- return _updateDesignAreaList.apply(this, arguments);
1407
- }
1408
-
1409
- return updateDesignAreaList;
1410
- }()
1411
- }, {
1412
- key: "exportGLTF",
1413
- value: function exportGLTF() {
1414
- (0, _glTFExporter.exportGLTF)(this.sceneContainer);
1415
- }
1416
- }, {
1417
- key: "setupScreenshots",
1418
- value: function setupScreenshots() {
1419
- var _this6 = this;
1420
-
1421
- var groundVisibility = this.ground.visible;
1422
- this.ground.visible = false;
1423
- return function () {
1424
- _this6.ground.visible = groundVisibility;
1425
- };
1426
- }
1427
- }]);
1428
-
1429
- return Three3DScene;
1430
- }(_Three3D2.Three3D);
1431
-
1432
- exports.Three3DScene = Three3DScene;