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
package/Three/Three3D.js DELETED
@@ -1,1412 +0,0 @@
1
- "use strict";
2
-
3
- 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); }
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.Three3D = exports.DEFAULT_TEXTURE_SIZE = exports.MIN_DISTANCE_MULTIPLIER = exports.MAX_DISTANCE_MULTIPLIER = void 0;
9
-
10
- var _three = require("three");
11
-
12
- var _tween = _interopRequireDefault(require("@tweenjs/tween.js"));
13
-
14
- var _first = _interopRequireDefault(require("lodash/first"));
15
-
16
- var _findIndex = _interopRequireDefault(require("lodash/findIndex"));
17
-
18
- var _get2 = _interopRequireDefault(require("lodash/get"));
19
-
20
- var _ThreeBase2 = require("./ThreeBase");
21
-
22
- var _MTLLoader = _interopRequireDefault(require("./Loaders/MTLLoader"));
23
-
24
- var _OBJLoader = _interopRequireDefault(require("./Loaders/OBJLoader"));
25
-
26
- var _ColladaLoader = _interopRequireDefault(require("./Loaders/ColladaLoader"));
27
-
28
- var _initTextureCanvas = require("../Utils/initTextureCanvas");
29
-
30
- var _createCanvas = require("../Utils/createCanvas");
31
-
32
- var _createAlphaMapFromAlphaChannel = require("../Utils/createAlphaMapFromAlphaChannel");
33
-
34
- var _Deferred = require("../CommonUtils/Deferred");
35
-
36
- var _Constants = require("../Constants");
37
-
38
- var _disposeMaterial = require("../Utils/disposeMaterial");
39
-
40
- var _rememberCameraViewOffset = require("../Utils/rememberCameraViewOffset");
41
-
42
- var _restrictCameraMovement = require("../Utils/restrictCameraMovement");
43
-
44
- var _isMobileDevice = require("../Utils/isMobileDevice");
45
-
46
- var _OrbitControls = _interopRequireDefault(require("./Controls/OrbitControls"));
47
-
48
- var _pointerEvent = require("../CommonUtils/pointerEvent");
49
-
50
- var _createTextureBuilder = require("../Utils/TextureBuilder/createTextureBuilder");
51
-
52
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
53
-
54
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
55
-
56
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
57
-
58
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
59
-
60
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
61
-
62
- 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(_e2) { throw _e2; }, 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(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
63
-
64
- 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); }
65
-
66
- 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; }
67
-
68
- 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); } }
69
-
70
- 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); }); }; }
71
-
72
- 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; }
73
-
74
- 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; }
75
-
76
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
77
-
78
- 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); } }
79
-
80
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
81
-
82
- function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
83
-
84
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
85
-
86
- 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); }
87
-
88
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
89
-
90
- 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); }; }
91
-
92
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
93
-
94
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
95
-
96
- 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; } }
97
-
98
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
99
-
100
- 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; }
101
-
102
- var MAX_DISTANCE_MULTIPLIER = 1.1;
103
- exports.MAX_DISTANCE_MULTIPLIER = MAX_DISTANCE_MULTIPLIER;
104
- var MIN_DISTANCE_MULTIPLIER = 0.1;
105
- exports.MIN_DISTANCE_MULTIPLIER = MIN_DISTANCE_MULTIPLIER;
106
- var DEFAULT_TEXTURE_SIZE = 2048;
107
- exports.DEFAULT_TEXTURE_SIZE = DEFAULT_TEXTURE_SIZE;
108
-
109
- var Three3D = /*#__PURE__*/function (_ThreeBase) {
110
- _inherits(Three3D, _ThreeBase);
111
-
112
- var _super = _createSuper(Three3D);
113
-
114
- function Three3D() {
115
- var _this;
116
-
117
- _classCallCheck(this, Three3D);
118
-
119
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
120
- args[_key] = arguments[_key];
121
- }
122
-
123
- _this = _super.call.apply(_super, [this].concat(args));
124
-
125
- _defineProperty(_assertThisInitialized(_this), "DefaultCustomizableMaterialKey", "main_material");
126
-
127
- _defineProperty(_assertThisInitialized(_this), "loadMaterial", function () {
128
- var _src;
129
-
130
- var promise;
131
- /**
132
- * Loads the material from the given path
133
- * @param {string} src
134
- * @returns {Promise.<*>}
135
- */
136
-
137
- return function (src) {
138
- if (_src === src) {
139
- // eslint-disable-next-line no-console
140
- console.log("Material is already loaded: " + src);
141
- return promise;
142
- }
143
-
144
- _src = src; // eslint-disable-next-line no-console
145
-
146
- console.log("Loading material: " + src);
147
- promise = new Promise(function (resolve, reject) {
148
- var _this$getPathAndFileN = _this.getPathAndFileName(src),
149
- path = _this$getPathAndFileN.path,
150
- fileName = _this$getPathAndFileN.fileName;
151
-
152
- new _MTLLoader["default"](_this._loadingManager).setPath(path).load(fileName, function (materialCreator) {
153
- var textureLoadingManager = new _three.LoadingManager(function () {
154
- // eslint-disable-next-line no-console
155
- console.log("All textures have been lodaed.");
156
- resolve(materialCreator);
157
- }, undefined, _this.onLoadError);
158
- textureLoadingManager.setURLModifier(function (url) {
159
- if ((0, _isMobileDevice.isMobileDevice)()) {
160
- return url.replace(/(https?:\/\/(.+?)\/)/, "$1media/") + "?mobile=1";
161
- }
162
-
163
- return url;
164
- });
165
- materialCreator.setManager(textureLoadingManager);
166
- materialCreator.preload();
167
- var isTexture = Object.values(materialCreator.materials).reduce(function (isTexture, material) {
168
- return Object.values(material).reduce(function (isTexture, propValue) {
169
- return propValue instanceof _three.Texture || isTexture;
170
- }, false) || isTexture;
171
- }, false);
172
-
173
- if (!isTexture) {
174
- // eslint-disable-next-line no-console
175
- console.log("Materials do not contain any texture.");
176
- resolve(materialCreator);
177
- }
178
- }, undefined, reject);
179
- });
180
- return promise;
181
- };
182
- }());
183
-
184
- return _this;
185
- }
186
-
187
- _createClass(Three3D, [{
188
- key: "createRenderer",
189
- value: function createRenderer() {
190
- var renderer = new _three.WebGLRenderer({
191
- alpha: true,
192
- antialias: true,
193
- gammaInput: true,
194
- gammaOutput: true
195
- });
196
- var realWidth = window.innerWidth * window.devicePixelRatio;
197
-
198
- if ((0, _isMobileDevice.isMobileDevice)() && realWidth >= 1024) {
199
- renderer.setPixelRatio(1);
200
- } else {
201
- renderer.setPixelRatio(window.devicePixelRatio);
202
- }
203
-
204
- return renderer;
205
- }
206
- }, {
207
- key: "createCamera",
208
- value: function createCamera() {
209
- var camera = new _three.PerspectiveCamera(55, 1, 1, 2000);
210
- camera.position.z = 50;
211
- return camera;
212
- }
213
- }, {
214
- key: "updateCamera",
215
- value: function updateCamera(width, height) {
216
- this.camera.aspect = width / height;
217
- this.camera.updateProjectionMatrix();
218
- }
219
- }, {
220
- key: "setupDefaultLightning",
221
- value: function setupDefaultLightning() {
222
- var ambientLight = new _three.AmbientLight(0xcccccc, 0.4);
223
- this.scene.add(ambientLight);
224
- var pointLight = new _three.PointLight(0xffffff, 0.8);
225
- this.camera.add(pointLight);
226
- }
227
- /**
228
- * @param {HTMLElement} targetElement
229
- * @param {{}} options Custom options for the controls (see the OrbitControls.js file for details)
230
- */
231
-
232
- }, {
233
- key: "setupDefaultControls",
234
- value: function setupDefaultControls(targetElement) {
235
- var _this2 = this;
236
-
237
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
238
- var element = targetElement || this.renderer.domElement;
239
- this._cleanUpZoomHandler = (0, _pointerEvent.createZoomHandler)(element, function (evt, data) {
240
- _this2.observable.dispatch(_Constants.EventTypes.Zoomed, _objectSpread({
241
- originalEvent: evt
242
- }, data), true);
243
- }); // register OrbitControls as the default camera movement handler
244
-
245
- var controls = new _OrbitControls["default"](this.camera, element);
246
- controls.addEventListener("change", function () {
247
- if (!_this2._isAnimating) {
248
- window.cancelAnimationFrame(_this2._renderFrame);
249
- _this2._renderFrame = window.requestAnimationFrame(_this2.render.bind(_this2));
250
- }
251
- });
252
- controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
253
-
254
- controls.enableKeys = false;
255
- controls.screenSpacePanning = false;
256
- controls.dampingFactor = 1;
257
- controls.minDistance = 0.2;
258
- controls.maxDistance = 10;
259
- controls.maxPolarAngle = Math.PI;
260
- Object.assign(controls, options);
261
- this.controls = controls;
262
- }
263
- /**
264
- * Loads the model from the pre-configured paths
265
- * Note: this function should be refactored when we have more objects/materials and not only one
266
- * @param {boolean} loadCameraViews Load the camera views for the model
267
- * @param {boolean} rerender
268
- */
269
-
270
- }, {
271
- key: "loadModel",
272
- value: function () {
273
- var _loadModel = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
274
- var loadCameraViews,
275
- rerender,
276
- _this$getModelPaths,
277
- objPath,
278
- promises,
279
- result,
280
- _args = arguments;
281
-
282
- return regeneratorRuntime.wrap(function _callee$(_context) {
283
- while (1) {
284
- switch (_context.prev = _context.next) {
285
- case 0:
286
- loadCameraViews = _args.length > 0 && _args[0] !== undefined ? _args[0] : true;
287
- rerender = _args.length > 1 && _args[1] !== undefined ? _args[1] : true;
288
- _this$getModelPaths = this.getModelPaths(), objPath = _this$getModelPaths.objPath;
289
-
290
- if (!objPath) {
291
- _context.next = 14;
292
- break;
293
- }
294
-
295
- promises = [this.loadObject("".concat(objPath, "/model.obj"))];
296
-
297
- if (loadCameraViews) {
298
- promises.push(this.loadCameraViewsAdvanced("".concat(objPath, "/cameraviews.dae")));
299
- }
300
-
301
- this.onLoadStart();
302
- _context.next = 9;
303
- return Promise.all(promises);
304
-
305
- case 9:
306
- result = _context.sent;
307
- this.onLoadFinished();
308
- this.observable.dispatch(_Constants.EventTypes.ModelLoaded);
309
-
310
- if (rerender) {
311
- this.render();
312
- }
313
-
314
- return _context.abrupt("return", result);
315
-
316
- case 14:
317
- return _context.abrupt("return", Promise.reject("Cannot load model, the item path is not defined!"));
318
-
319
- case 15:
320
- case "end":
321
- return _context.stop();
322
- }
323
- }
324
- }, _callee, this);
325
- }));
326
-
327
- function loadModel() {
328
- return _loadModel.apply(this, arguments);
329
- }
330
-
331
- return loadModel;
332
- }()
333
- /**
334
- * Load the camera views (positions and lookAt points) from an obj file
335
- * For the currently processed view params see the jumpToView method.
336
- * The value of the param (Vector3) is calculated by taking the geometric center point of the object's
337
- * bounding sphere.
338
- * It resolves with an object that contains all the collected data in the following format:
339
- * {
340
- * <name>: {
341
- * <param>: Vector3
342
- * },
343
- * ... and so on
344
- * }
345
- * @see jumpToView
346
- * @param {string} src The url of the obj file that contains the positions.
347
- * @param {boolean} [setDefault=true] Jump to the default view immediately after the views are processed.
348
- * @returns {Promise.<{}>}
349
- */
350
-
351
- }, {
352
- key: "loadCameraViews",
353
- value: function () {
354
- var _loadCameraViews = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(src) {
355
- var setDefault,
356
- group,
357
- children,
358
- views,
359
- _iterator,
360
- _step,
361
- obj,
362
- matches,
363
- viewName,
364
- viewParam,
365
- pos,
366
- _args2 = arguments;
367
-
368
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
369
- while (1) {
370
- switch (_context2.prev = _context2.next) {
371
- case 0:
372
- setDefault = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : true;
373
- _context2.next = 3;
374
- return this.loadObject(src, false);
375
-
376
- case 3:
377
- group = _context2.sent;
378
- children = group.children;
379
-
380
- if (!(children && children.length > 0)) {
381
- _context2.next = 37;
382
- break;
383
- }
384
-
385
- views = {};
386
- _iterator = _createForOfIteratorHelper(children);
387
- _context2.prev = 8;
388
-
389
- _iterator.s();
390
-
391
- case 10:
392
- if ((_step = _iterator.n()).done) {
393
- _context2.next = 25;
394
- break;
395
- }
396
-
397
- obj = _step.value;
398
-
399
- if (obj instanceof _three.Mesh) {
400
- _context2.next = 14;
401
- break;
402
- }
403
-
404
- return _context2.abrupt("continue", 23);
405
-
406
- case 14:
407
- matches = ("" + obj.name).toLowerCase().match(/(.+)_(position|lookat)$/);
408
-
409
- if (matches) {
410
- _context2.next = 18;
411
- break;
412
- }
413
-
414
- // eslint-disable-next-line no-console
415
- console.warn("Camera view object skipped: ".concat(obj.name));
416
- return _context2.abrupt("continue", 23);
417
-
418
- case 18:
419
- viewName = matches[1];
420
- viewParam = matches[2];
421
- obj.geometry.computeBoundingSphere();
422
- pos = obj.geometry.boundingSphere.center.clone();
423
- views[viewName] = _objectSpread(_objectSpread({}, views[viewName]), {}, _defineProperty({}, viewParam, pos));
424
-
425
- case 23:
426
- _context2.next = 10;
427
- break;
428
-
429
- case 25:
430
- _context2.next = 30;
431
- break;
432
-
433
- case 27:
434
- _context2.prev = 27;
435
- _context2.t0 = _context2["catch"](8);
436
-
437
- _iterator.e(_context2.t0);
438
-
439
- case 30:
440
- _context2.prev = 30;
441
-
442
- _iterator.f();
443
-
444
- return _context2.finish(30);
445
-
446
- case 33:
447
- this.cameraViews = views;
448
-
449
- if (setDefault) {
450
- this.jumpToView("default", false);
451
- }
452
-
453
- this.setControlsDistanceMinMax();
454
- return _context2.abrupt("return", views);
455
-
456
- case 37:
457
- case "end":
458
- return _context2.stop();
459
- }
460
- }
461
- }, _callee2, this, [[8, 27, 30, 33]]);
462
- }));
463
-
464
- function loadCameraViews(_x) {
465
- return _loadCameraViews.apply(this, arguments);
466
- }
467
-
468
- return loadCameraViews;
469
- }()
470
- /**
471
- * Loads the camera views (positions, rotations and lookAt points) from a Collada file (.dae)
472
- * The main difference to loadCameraViews is that it reads the camera rotation and adds it to the params.
473
- * @param {string} src The url of the obj file that contains the positions.
474
- * @param {boolean} [setDefault=true] Jump to the default view immediately after the views are processed.
475
- * @returns {Promise.<{}>}
476
- */
477
-
478
- }, {
479
- key: "loadCameraViewsAdvanced",
480
- value: function () {
481
- var _loadCameraViewsAdvanced = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(src) {
482
- var setDefault,
483
- loader,
484
- _this$getPathAndFileN2,
485
- path,
486
- fileName,
487
- _yield$Promise,
488
- scene,
489
- views,
490
- _args4 = arguments;
491
-
492
- return regeneratorRuntime.wrap(function _callee4$(_context4) {
493
- while (1) {
494
- switch (_context4.prev = _context4.next) {
495
- case 0:
496
- setDefault = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : true;
497
- loader = new _ColladaLoader["default"](this._loadingManager);
498
- _this$getPathAndFileN2 = this.getPathAndFileName(src), path = _this$getPathAndFileN2.path, fileName = _this$getPathAndFileN2.fileName;
499
- _context4.next = 5;
500
- return new Promise(function (resolve, reject) {
501
- loader.setPath(path).load(fileName, /*#__PURE__*/function () {
502
- var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(object) {
503
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
504
- while (1) {
505
- switch (_context3.prev = _context3.next) {
506
- case 0:
507
- resolve(object);
508
-
509
- case 1:
510
- case "end":
511
- return _context3.stop();
512
- }
513
- }
514
- }, _callee3);
515
- }));
516
-
517
- return function (_x3) {
518
- return _ref.apply(this, arguments);
519
- };
520
- }(), _ThreeBase2.onProgress, reject);
521
- });
522
-
523
- case 5:
524
- _yield$Promise = _context4.sent;
525
- scene = _yield$Promise.scene;
526
- views = {};
527
- scene.traverse(function (obj) {
528
- var matches = ("" + obj.name).toLowerCase().match(/(.+)_(position|lookat)$/);
529
-
530
- if (matches) {
531
- var viewName = matches[1];
532
- var viewParam = matches[2];
533
-
534
- var params = _objectSpread(_objectSpread({}, views[viewName]), {}, _defineProperty({}, viewParam, obj.position.clone())); // if it's the position, create a custom up vector from its rotation
535
-
536
-
537
- if (viewParam === "position") {
538
- params.orientation = _three.Object3D.DefaultUp.clone().applyEuler(obj.rotation);
539
- }
540
-
541
- views[viewName] = params;
542
- }
543
- });
544
- this.cameraViews = views;
545
-
546
- if (setDefault) {
547
- this.jumpToView("default", false);
548
- }
549
-
550
- this.setControlsDistanceMinMax();
551
- return _context4.abrupt("return", views);
552
-
553
- case 13:
554
- case "end":
555
- return _context4.stop();
556
- }
557
- }
558
- }, _callee4, this);
559
- }));
560
-
561
- function loadCameraViewsAdvanced(_x2) {
562
- return _loadCameraViewsAdvanced.apply(this, arguments);
563
- }
564
-
565
- return loadCameraViewsAdvanced;
566
- }()
567
- }, {
568
- key: "loadObject",
569
- value:
570
- /**
571
- * Loads the object from the given path.
572
- * It adds the object to the scene immediately (by default).
573
- * @param {string} src
574
- * @param {boolean} addToScene
575
- * @returns {Promise<Group>}
576
- */
577
- function loadObject(src) {
578
- var _this3 = this;
579
-
580
- var addToScene = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
581
- var objLoader = new _OBJLoader["default"](this._loadingManager);
582
-
583
- var _this$getPathAndFileN3 = this.getPathAndFileName(src),
584
- path = _this$getPathAndFileN3.path,
585
- fileName = _this$getPathAndFileN3.fileName;
586
-
587
- return new Promise(function (resolve, reject) {
588
- objLoader.setPath(path).load(fileName, /*#__PURE__*/function () {
589
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(object) {
590
- return regeneratorRuntime.wrap(function _callee5$(_context5) {
591
- while (1) {
592
- switch (_context5.prev = _context5.next) {
593
- case 0:
594
- _context5.next = 2;
595
- return _this3.updateMaterial(object);
596
-
597
- case 2:
598
- if (addToScene) {
599
- _this3.scene.add(object);
600
- }
601
-
602
- resolve(object);
603
-
604
- case 4:
605
- case "end":
606
- return _context5.stop();
607
- }
608
- }
609
- }, _callee5);
610
- }));
611
-
612
- return function (_x4) {
613
- return _ref2.apply(this, arguments);
614
- };
615
- }(), _ThreeBase2.onProgress, reject);
616
- });
617
- }
618
- }, {
619
- key: "dispatchMaterialUpdateEvent",
620
- value: function () {
621
- var _dispatchMaterialUpdateEvent = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
622
- var options,
623
- _options$screenshot,
624
- screenshot,
625
- eventParams,
626
- _args6 = arguments;
627
-
628
- return regeneratorRuntime.wrap(function _callee6$(_context6) {
629
- while (1) {
630
- switch (_context6.prev = _context6.next) {
631
- case 0:
632
- options = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {};
633
- _options$screenshot = options.screenshot, screenshot = _options$screenshot === void 0 ? false : _options$screenshot;
634
- eventParams = {
635
- variant: this._materialVariantPath,
636
- screenshot: screenshot
637
- }; // the redrawing of the areas can be synced if the event handler returns a Promise
638
-
639
- _context6.next = 5;
640
- return this.observable.dispatch(_Constants.EventTypes.MaterialUpdated, eventParams);
641
-
642
- case 5:
643
- case "end":
644
- return _context6.stop();
645
- }
646
- }
647
- }, _callee6, this);
648
- }));
649
-
650
- function dispatchMaterialUpdateEvent() {
651
- return _dispatchMaterialUpdateEvent.apply(this, arguments);
652
- }
653
-
654
- return dispatchMaterialUpdateEvent;
655
- }()
656
- }, {
657
- key: "updateMaterial",
658
- value: function () {
659
- var _updateMaterial = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
660
- var targetObject,
661
- options,
662
- _this$getModelPaths2,
663
- mtlPath,
664
- materialCreator,
665
- _args7 = arguments;
666
-
667
- return regeneratorRuntime.wrap(function _callee7$(_context7) {
668
- while (1) {
669
- switch (_context7.prev = _context7.next) {
670
- case 0:
671
- targetObject = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : this.scene;
672
- options = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : {};
673
- // eslint-disable-next-line no-console
674
- console.log("Updating materials...");
675
- _this$getModelPaths2 = this.getModelPaths(), mtlPath = _this$getModelPaths2.mtlPath;
676
-
677
- if (mtlPath) {
678
- _context7.next = 7;
679
- break;
680
- }
681
-
682
- // eslint-disable-next-line no-console
683
- console.log("Missing material path!");
684
- return _context7.abrupt("return");
685
-
686
- case 7:
687
- _context7.next = 9;
688
- return this.loadMaterial("".concat(mtlPath, "/materials.mtl"));
689
-
690
- case 9:
691
- materialCreator = _context7.sent;
692
- this.guessCustomizableMaterialNameIfNotSet(materialCreator.materials);
693
- this.findCustomizableMaterials(materialCreator.materials);
694
- this.applyMaterials(materialCreator.materials, targetObject);
695
- _context7.next = 15;
696
- return this.dispatchMaterialUpdateEvent(options);
697
-
698
- case 15:
699
- return _context7.abrupt("return", materialCreator);
700
-
701
- case 16:
702
- case "end":
703
- return _context7.stop();
704
- }
705
- }
706
- }, _callee7, this);
707
- }));
708
-
709
- function updateMaterial() {
710
- return _updateMaterial.apply(this, arguments);
711
- }
712
-
713
- return updateMaterial;
714
- }()
715
- /**
716
- * Sets a single customizable material name that can be used for drawing on the texture
717
- * @param matName
718
- */
719
-
720
- }, {
721
- key: "setCustomizableMaterialName",
722
- value: function setCustomizableMaterialName(matName) {
723
- this._customizableMaterialKeys = [matName];
724
- }
725
- }, {
726
- key: "guessCustomizableMaterialNameIfNotSet",
727
- value: function guessCustomizableMaterialNameIfNotSet(materials) {
728
- if (this._customizableMaterialKeys.length === 0) {
729
- var materialName = this.DefaultCustomizableMaterialKey; // if there is no default material, pick the first from the list (fallback)
730
-
731
- if (!materials[materialName]) {
732
- var firstMaterialName = Object.keys(materials).find(function (matName) {
733
- var material = materials[matName];
734
-
735
- if (material.map && material.map.image) {
736
- return true;
737
- }
738
- });
739
-
740
- if (firstMaterialName) {
741
- materialName = firstMaterialName;
742
- }
743
- }
744
-
745
- this.setCustomizableMaterialName(materialName);
746
- }
747
- }
748
- /**
749
- * Find the objects using the given materials and update them
750
- * @param materials
751
- * @param targetObject
752
- */
753
-
754
- }, {
755
- key: "applyMaterials",
756
- value: function applyMaterials(materials, targetObject) {
757
- targetObject && targetObject.traverse && targetObject.traverse(function (object) {
758
- if (object.material && object.material.name) {
759
- var requiredMaterial = materials[object.material.name];
760
-
761
- if (requiredMaterial && object.material !== requiredMaterial) {
762
- (0, _disposeMaterial.disposeMaterial)(object.material);
763
- object.material = requiredMaterial;
764
- }
765
- }
766
- });
767
- }
768
- /**
769
- * Finds the marked customizable materials and prepares a canvas for drawing on the texture
770
- * @param {*} materialsObj
771
- */
772
-
773
- }, {
774
- key: "findCustomizableMaterials",
775
- value: function findCustomizableMaterials(materialsObj) {
776
- // eslint-disable-next-line no-console
777
- console.log("Looking for customizable materials...");
778
-
779
- var _iterator2 = _createForOfIteratorHelper(this._customizableMaterialKeys),
780
- _step2;
781
-
782
- try {
783
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
784
- var key = _step2.value;
785
- var mat = materialsObj[key];
786
-
787
- if (mat) {
788
- this.prepareCustomCanvasForMaterial(mat);
789
- var index = (0, _findIndex["default"])(this._customizableMaterials, {
790
- name: key
791
- });
792
-
793
- if (index === -1) {
794
- this._customizableMaterials.push(mat);
795
- } else if (this._customizableMaterials[index] !== mat) {
796
- (0, _disposeMaterial.disposeMaterial)(this._customizableMaterials[index]);
797
- this._customizableMaterials[index] = mat;
798
- }
799
- }
800
- }
801
- } catch (err) {
802
- _iterator2.e(err);
803
- } finally {
804
- _iterator2.f();
805
- }
806
- }
807
- /**
808
- * Creates the canvas for the material texture and draws the original image on it
809
- * @param {Material} material
810
- */
811
-
812
- }, {
813
- key: "prepareCustomCanvasForMaterial",
814
- value: function prepareCustomCanvasForMaterial(material) {
815
- if (material && material.map && material.map.image) {
816
- // init canvas for diffuse map
817
- (0, _initTextureCanvas.initTextureCanvas)(material.map);
818
- material.map.anisotropy = this.renderer.capabilities.getMaxAnisotropy(); // init canvas for alpha map
819
-
820
- if (material.alphaMap) {
821
- (0, _initTextureCanvas.initTextureCanvas)(material.alphaMap);
822
- }
823
- } else {
824
- throw new Error("Cannot prepare canvas for material: ".concat(material.name));
825
- }
826
- }
827
- }, {
828
- key: "getCanvasContextForTexture",
829
- value: function getCanvasContextForTexture(texture) {
830
- var originalImage = texture.originalImage,
831
- canvas = texture.image;
832
-
833
- if (texture.originalImage && canvas instanceof HTMLCanvasElement) {
834
- var ctx = canvas.getContext("2d");
835
- return {
836
- ctx: ctx,
837
- originalImage: originalImage,
838
- canvas: canvas,
839
- texture: texture
840
- };
841
- }
842
-
843
- throw new Error("Cannot get drawing context for canvas. Is it prepared already?");
844
- }
845
- /**
846
- * Moves the camera to the given position and target (look at point)
847
- * @param {Vector3|undefined} position The new position
848
- * @param {Vector3|undefined} orientation The new orientation of the camera (up vector)
849
- * @param {Vector3|undefined} target The new look at point
850
- * @param {{[position]: number, [target]: number, [orientation]: number}} duration The animation duration in ms
851
- * @requires TWEEN
852
- */
853
-
854
- }, {
855
- key: "moveCamera",
856
- value: function moveCamera(position, orientation, target) {
857
- var _this4 = this;
858
-
859
- var duration = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
860
- this.cleanUpCameraAnimations();
861
- var animationDef = new _Deferred.DeferredGroup();
862
-
863
- if (position) {
864
- // use spherical coordinates to keep the distance from the object
865
- var sp0 = new _three.Spherical();
866
- sp0.setFromVector3(this.camera.position);
867
- var sp1 = new _three.Spherical();
868
- sp1.setFromVector3(position); // always take the shorter way around the target
869
-
870
- if (Math.abs(sp1.theta - sp0.theta) > Math.PI) {
871
- sp1.theta += (sp1.theta > 0 ? -1 : 1) * Math.PI * 2;
872
- }
873
-
874
- new _tween["default"].Tween(sp0, this.cameraTweenGroup).to(sp1, duration.position || 1000).easing(_tween["default"].Easing.Quadratic.Out).onUpdate(function () {
875
- _this4.camera.position.setFromSpherical(sp0);
876
- }).onComplete(animationDef.createResolver()).start();
877
- }
878
-
879
- if (orientation) {
880
- new _tween["default"].Tween(this.camera.up, this.cameraTweenGroup).to(orientation, duration.orientation || 700).easing(_tween["default"].Easing.Quadratic.Out).onComplete(animationDef.createResolver()).start();
881
- }
882
-
883
- if (this.controls && target) {
884
- new _tween["default"].Tween(this.controls.target, this.cameraTweenGroup).to(target, duration.target || 500).easing(_tween["default"].Easing.Quadratic.Out).onComplete(animationDef.createResolver()).start();
885
- }
886
-
887
- animationDef.then(function () {
888
- return _this4.stopAnimation("camera");
889
- });
890
- this.startAnimation("camera");
891
- }
892
- /**
893
- * Jump to the selected view
894
- * Note: the available views are loaded from an additional obj file
895
- * @see loadCameraViews
896
- * @see moveCamera
897
- * @see setCameraPosition
898
- * @param {string} viewName The name of the view object in this.cameraViews
899
- * @param {boolean} [animate=true] Use animation or set it directly
900
- * @param {{[position]: number, [target]: number}} duration The animation duration in ms
901
- */
902
-
903
- }, {
904
- key: "jumpToView",
905
- value: function jumpToView(viewName) {
906
- var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
907
- var duration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
908
- var viewNameSafe = ("" + viewName).toLowerCase();
909
- var view = this.cameraViews[viewNameSafe];
910
-
911
- if (!view) {
912
- // eslint-disable-next-line no-console
913
- console.error("Camera view does not exist: ".concat(viewNameSafe));
914
- return;
915
- }
916
-
917
- var _this$cameraViews$def = _objectSpread(_objectSpread({}, this.cameraViews["default"]), view),
918
- position = _this$cameraViews$def.position,
919
- orientation = _this$cameraViews$def.orientation,
920
- target = _this$cameraViews$def.lookat;
921
-
922
- if (animate) {
923
- this.moveCamera(position, orientation, target, duration);
924
- } else {
925
- this.setCameraPosition(position, orientation, target);
926
- }
927
- }
928
- /**
929
- * Sets the camera position and renders the scene if it's not animating
930
- * @param {{x: number|undefined, y: number|undefined, z: number|undefined}} position
931
- * @param {{x: number|undefined, y: number|undefined, z: number|undefined}} oritentation
932
- * @param {{x: number|undefined, y: number|undefined, z: number|undefined}} target
933
- */
934
-
935
- }, {
936
- key: "setCameraPosition",
937
- value: function setCameraPosition() {
938
- var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
939
- y: 30
940
- };
941
- var oritentation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
942
- var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
943
- y: 10
944
- };
945
-
946
- if (!this.camera) {
947
- throw new Error("The camera must be available for the setCameraPosition call!");
948
- }
949
-
950
- Object.assign(this.camera.position, position);
951
- Object.assign(this.camera.up, oritentation);
952
-
953
- if (this.controls && this.controls.target) {
954
- Object.assign(this.controls.target, target);
955
-
956
- if (!this.isAnimating()) {
957
- this.controls.update();
958
- }
959
- }
960
- }
961
- }, {
962
- key: "setupScreenshots",
963
- value: function setupScreenshots() {
964
- // do initial steps before actually starting to create screenshots
965
- // it has to return a "restore" function
966
- return function () {};
967
- }
968
- }, {
969
- key: "getScreenshots",
970
- value: function () {
971
- var _getScreenshots = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9(callback, _ref3) {
972
- var _this5 = this;
973
-
974
- var viewList, variantList, size, removeTempOverlay, restoreCameraViewOffset, origVariantPath, origPosition, origOrientation, origTarget, origSize, origPixelRatio, restoreOriginalValues, restoreScreenshotSetup, width, height, screenshots, views, viewKeyList, _iterator3, _step3, variant, data, _iterator4, _step4, viewKey, view, _this$cameraViews$def2, position, orientation, target;
975
-
976
- return regeneratorRuntime.wrap(function _callee9$(_context9) {
977
- while (1) {
978
- switch (_context9.prev = _context9.next) {
979
- case 0:
980
- viewList = _ref3.viewList, variantList = _ref3.variantList, size = _ref3.size;
981
-
982
- if (this.renderer) {
983
- _context9.next = 3;
984
- break;
985
- }
986
-
987
- return _context9.abrupt("return", callback({}));
988
-
989
- case 3:
990
- this._screenshottingInProgress = true;
991
- this.endAnimation();
992
- _context9.next = 7;
993
- return this.animationRunning();
994
-
995
- case 7:
996
- _context9.next = 9;
997
- return this.createTempOverlay();
998
-
999
- case 9:
1000
- removeTempOverlay = _context9.sent;
1001
- restoreCameraViewOffset = (0, _rememberCameraViewOffset.rememberCameraViewOffset)(this.camera); // store original state values
1002
-
1003
- origVariantPath = this._materialVariantPath;
1004
- origPosition = this.camera.position.clone();
1005
- origOrientation = this.camera.up.clone();
1006
- origTarget = this.controls ? this.controls.target.clone() : false;
1007
- origSize = new _three.Vector2();
1008
- this.renderer.getSize(origSize);
1009
- origPixelRatio = this.renderer.getPixelRatio();
1010
-
1011
- restoreOriginalValues = /*#__PURE__*/function () {
1012
- var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
1013
- return regeneratorRuntime.wrap(function _callee8$(_context8) {
1014
- while (1) {
1015
- switch (_context8.prev = _context8.next) {
1016
- case 0:
1017
- _this5._screenshottingInProgress = false;
1018
-
1019
- _this5.renderer.setSize(origSize.width, origSize.height);
1020
-
1021
- _this5.renderer.setPixelRatio(origPixelRatio);
1022
-
1023
- _this5.updateCamera(origSize.width, origSize.height);
1024
-
1025
- _this5.setCameraPosition(origPosition, origOrientation, origTarget);
1026
-
1027
- restoreCameraViewOffset();
1028
- _this5._materialVariantPath = origVariantPath;
1029
- _context8.next = 9;
1030
- return _this5.updateMaterial();
1031
-
1032
- case 9:
1033
- _this5.render();
1034
-
1035
- removeTempOverlay();
1036
-
1037
- case 11:
1038
- case "end":
1039
- return _context8.stop();
1040
- }
1041
- }
1042
- }, _callee8);
1043
- }));
1044
-
1045
- return function restoreOriginalValues() {
1046
- return _ref4.apply(this, arguments);
1047
- };
1048
- }();
1049
-
1050
- _context9.next = 21;
1051
- return this.setupScreenshots();
1052
-
1053
- case 21:
1054
- restoreScreenshotSetup = _context9.sent;
1055
- // get the size from the size param, or use default values
1056
- width = (0, _get2["default"])(size, "width", 1024);
1057
- height = (0, _get2["default"])(size, "height", 768);
1058
- screenshots = {};
1059
- views = this.cameraViews; // if the viewList option is provided, use it as keys instead of the list of all views
1060
-
1061
- viewKeyList = viewList instanceof Array && viewList.length > 0 ? viewList : Object.keys(views);
1062
- _iterator3 = _createForOfIteratorHelper(variantList);
1063
- _context9.prev = 28;
1064
-
1065
- _iterator3.s();
1066
-
1067
- case 30:
1068
- if ((_step3 = _iterator3.n()).done) {
1069
- _context9.next = 77;
1070
- break;
1071
- }
1072
-
1073
- variant = _step3.value;
1074
-
1075
- if (!this._abortScreenshotting) {
1076
- _context9.next = 36;
1077
- break;
1078
- }
1079
-
1080
- _context9.next = 35;
1081
- return restoreOriginalValues();
1082
-
1083
- case 35:
1084
- return _context9.abrupt("return", _context9.sent);
1085
-
1086
- case 36:
1087
- data = {};
1088
- this.setMaterialVariantPath(variant);
1089
- _context9.prev = 38;
1090
- _context9.next = 41;
1091
- return this.updateMaterial(this.scene, {
1092
- screenshot: true
1093
- });
1094
-
1095
- case 41:
1096
- _context9.next = 46;
1097
- break;
1098
-
1099
- case 43:
1100
- _context9.prev = 43;
1101
- _context9.t0 = _context9["catch"](38);
1102
- return _context9.abrupt("continue", 75);
1103
-
1104
- case 46:
1105
- _iterator4 = _createForOfIteratorHelper(viewKeyList);
1106
- _context9.prev = 47;
1107
-
1108
- _iterator4.s();
1109
-
1110
- case 49:
1111
- if ((_step4 = _iterator4.n()).done) {
1112
- _context9.next = 66;
1113
- break;
1114
- }
1115
-
1116
- viewKey = _step4.value;
1117
-
1118
- if (!this._abortScreenshotting) {
1119
- _context9.next = 55;
1120
- break;
1121
- }
1122
-
1123
- _context9.next = 54;
1124
- return restoreOriginalValues();
1125
-
1126
- case 54:
1127
- return _context9.abrupt("return", _context9.sent);
1128
-
1129
- case 55:
1130
- view = views[viewKey];
1131
- _this$cameraViews$def2 = _objectSpread(_objectSpread({}, this.cameraViews["default"]), view), position = _this$cameraViews$def2.position, orientation = _this$cameraViews$def2.orientation, target = _this$cameraViews$def2.lookat; // set the camera to the screenshot size
1132
-
1133
- this.renderer.setPixelRatio(1);
1134
- this.renderer.setSize(width, height);
1135
- this.updateCamera(width, height);
1136
- this.camera.clearViewOffset();
1137
- this.setCameraPosition(position, orientation, target);
1138
- this.render();
1139
- data[viewKey] = this.renderer.domElement.toDataURL("image/png");
1140
-
1141
- case 64:
1142
- _context9.next = 49;
1143
- break;
1144
-
1145
- case 66:
1146
- _context9.next = 71;
1147
- break;
1148
-
1149
- case 68:
1150
- _context9.prev = 68;
1151
- _context9.t1 = _context9["catch"](47);
1152
-
1153
- _iterator4.e(_context9.t1);
1154
-
1155
- case 71:
1156
- _context9.prev = 71;
1157
-
1158
- _iterator4.f();
1159
-
1160
- return _context9.finish(71);
1161
-
1162
- case 74:
1163
- screenshots[variant] = data;
1164
-
1165
- case 75:
1166
- _context9.next = 30;
1167
- break;
1168
-
1169
- case 77:
1170
- _context9.next = 82;
1171
- break;
1172
-
1173
- case 79:
1174
- _context9.prev = 79;
1175
- _context9.t2 = _context9["catch"](28);
1176
-
1177
- _iterator3.e(_context9.t2);
1178
-
1179
- case 82:
1180
- _context9.prev = 82;
1181
-
1182
- _iterator3.f();
1183
-
1184
- return _context9.finish(82);
1185
-
1186
- case 85:
1187
- _context9.next = 87;
1188
- return restoreScreenshotSetup();
1189
-
1190
- case 87:
1191
- _context9.next = 89;
1192
- return restoreOriginalValues();
1193
-
1194
- case 89:
1195
- callback(screenshots);
1196
-
1197
- case 90:
1198
- case "end":
1199
- return _context9.stop();
1200
- }
1201
- }
1202
- }, _callee9, this, [[28, 79, 82, 85], [38, 43], [47, 68, 71, 74]]);
1203
- }));
1204
-
1205
- function getScreenshots(_x5, _x6) {
1206
- return _getScreenshots.apply(this, arguments);
1207
- }
1208
-
1209
- return getScreenshots;
1210
- }()
1211
- }, {
1212
- key: "calculateTextureScaling",
1213
- value: function calculateTextureScaling(textureImage) {
1214
- return textureImage.width / DEFAULT_TEXTURE_SIZE;
1215
- }
1216
- }, {
1217
- key: "textureHitFormatter",
1218
- value: function textureHitFormatter(intersect, position) {
1219
- var x = position.x,
1220
- y = position.y,
1221
- width = position.width,
1222
- height = position.height;
1223
- return {
1224
- width: DEFAULT_TEXTURE_SIZE,
1225
- height: DEFAULT_TEXTURE_SIZE,
1226
- x: x / width * DEFAULT_TEXTURE_SIZE,
1227
- y: y / height * DEFAULT_TEXTURE_SIZE
1228
- };
1229
- }
1230
- /**
1231
- * Calls the given drawing function for custom drawing implementations
1232
- * It provides the drawing context and the original texture image to the callback function.
1233
- * It also invalidates the texture to make it update in the next render.
1234
- * Calls the render function if it's not animating continuously.
1235
- * @param {function} drawingFn
1236
- * @param {boolean} updateAlpha
1237
- * @param {boolean} clearTexture
1238
- * @param {string|undefined} materialName If not provided it uses the first customizable material
1239
- */
1240
-
1241
- }, {
1242
- key: "getDrawingContext",
1243
- value: function () {
1244
- var _getDrawingContext = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10(drawingFn) {
1245
- var updateAlpha,
1246
- clearTexture,
1247
- materialName,
1248
- material,
1249
- _this$getCanvasContex,
1250
- ctx,
1251
- canvas,
1252
- originalImage,
1253
- texture,
1254
- scaling,
1255
- getTextureBuilder,
1256
- _createWorkingCanvas,
1257
- _createWorkingCanvas2,
1258
- tmpCanvas,
1259
- tmpCtx,
1260
- _args10 = arguments;
1261
-
1262
- return regeneratorRuntime.wrap(function _callee10$(_context10) {
1263
- while (1) {
1264
- switch (_context10.prev = _context10.next) {
1265
- case 0:
1266
- updateAlpha = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : false;
1267
- clearTexture = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : false;
1268
- materialName = _args10.length > 3 && _args10[3] !== undefined ? _args10[3] : undefined;
1269
- material = materialName ? this.findMaterialByName(materialName) : (0, _first["default"])(this._customizableMaterials);
1270
-
1271
- if (!(!material || !material.map || !material.map.image)) {
1272
- _context10.next = 6;
1273
- break;
1274
- }
1275
-
1276
- throw new Error("Cannot get drawing context for material: ".concat(materialName, "! Is it prepared already?"));
1277
-
1278
- case 6:
1279
- _this$getCanvasContex = this.getCanvasContextForTexture(material.map), ctx = _this$getCanvasContex.ctx, canvas = _this$getCanvasContex.canvas, originalImage = _this$getCanvasContex.originalImage, texture = _this$getCanvasContex.texture;
1280
- scaling = this.calculateTextureScaling(canvas);
1281
- getTextureBuilder = (0, _createTextureBuilder.createTextureBuilder)(originalImage, {
1282
- scaling: scaling
1283
- });
1284
-
1285
- if (clearTexture) {
1286
- // draw the texture image on the drawing canvas to clear the previous state
1287
- ctx.drawImage(originalImage, 0, 0);
1288
- }
1289
-
1290
- if (!(updateAlpha && material.alphaMap)) {
1291
- _context10.next = 18;
1292
- break;
1293
- }
1294
-
1295
- // create a temporary canvas
1296
- _createWorkingCanvas = (0, _createCanvas.createWorkingCanvas)(canvas), _createWorkingCanvas2 = _slicedToArray(_createWorkingCanvas, 2), tmpCanvas = _createWorkingCanvas2[0], tmpCtx = _createWorkingCanvas2[1]; // do the drawing on a temporary canvas first, so we can get the alpha values
1297
-
1298
- _context10.next = 14;
1299
- return drawingFn(tmpCtx, getTextureBuilder);
1300
-
1301
- case 14:
1302
- // copy the temp canvas on the diffuse map
1303
- ctx.drawImage(tmpCanvas, 0, 0);
1304
- this.updateAlphaMap(material.alphaMap, tmpCanvas);
1305
- _context10.next = 20;
1306
- break;
1307
-
1308
- case 18:
1309
- _context10.next = 20;
1310
- return drawingFn(ctx, getTextureBuilder);
1311
-
1312
- case 20:
1313
- texture.needsUpdate = true;
1314
-
1315
- if (!this.isAnimating()) {
1316
- this.render();
1317
- }
1318
-
1319
- case 22:
1320
- case "end":
1321
- return _context10.stop();
1322
- }
1323
- }
1324
- }, _callee10, this);
1325
- }));
1326
-
1327
- function getDrawingContext(_x7) {
1328
- return _getDrawingContext.apply(this, arguments);
1329
- }
1330
-
1331
- return getDrawingContext;
1332
- }()
1333
- }, {
1334
- key: "updateAlphaMap",
1335
- value: function updateAlphaMap(texture, srcCanvas) {
1336
- var _this$getCanvasContex2 = this.getCanvasContextForTexture(texture),
1337
- ctx = _this$getCanvasContex2.ctx,
1338
- canvas = _this$getCanvasContex2.canvas,
1339
- originalImage = _this$getCanvasContex2.originalImage;
1340
-
1341
- ctx.drawImage(originalImage, 0, 0); // draw the original alpha image on the canvas
1342
-
1343
- (0, _createAlphaMapFromAlphaChannel.createAlphaMapFromAlphaChannel)(srcCanvas, canvas);
1344
- texture.needsUpdate = true;
1345
- }
1346
- }, {
1347
- key: "lockHorizontalRotation",
1348
- value: function lockHorizontalRotation(fixedAngle) {
1349
- if (!this.controls) {
1350
- throw new Error("The controls should be available for the lockHorizontalRotation call!");
1351
- }
1352
-
1353
- this.controls.minAzimuthAngle = fixedAngle;
1354
- this.controls.maxAzimuthAngle = fixedAngle;
1355
- }
1356
- }, {
1357
- key: "lockVerticalRotation",
1358
- value: function lockVerticalRotation(fixedAngle) {
1359
- if (!this.controls) {
1360
- throw new Error("The controls should be available for the lockVerticalRotation call!");
1361
- }
1362
-
1363
- this.controls.minPolarAngle = fixedAngle;
1364
- this.controls.maxPolarAngle = fixedAngle;
1365
- }
1366
- }, {
1367
- key: "setControlsDistanceMinMax",
1368
- value: function setControlsDistanceMinMax() {
1369
- var _this$cameraViews$def3 = this.cameraViews["default"],
1370
- position = _this$cameraViews$def3.position,
1371
- lookat = _this$cameraViews$def3.lookat;
1372
- var d = position.distanceTo(lookat);
1373
- this.controls.maxDistance = d * MAX_DISTANCE_MULTIPLIER;
1374
- this.controls.minDistance = d * MIN_DISTANCE_MULTIPLIER;
1375
- this.controls.update();
1376
- }
1377
- }, {
1378
- key: "restrictUserMovement",
1379
- value: function restrictUserMovement() {
1380
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1381
-
1382
- var _angleRad$options = _objectSpread({
1383
- angleRad: Math.PI * 0.1
1384
- }, options),
1385
- angleRad = _angleRad$options.angleRad;
1386
-
1387
- this._releaseUserMovementRestriction = (0, _restrictCameraMovement.restrictOrbitControls)(this.controls).byAngle(angleRad);
1388
- }
1389
- }, {
1390
- key: "freeUserMovement",
1391
- value: function freeUserMovement() {
1392
- if (this._releaseUserMovementRestriction) {
1393
- this._releaseUserMovementRestriction();
1394
-
1395
- delete this._releaseUserMovementRestriction;
1396
- }
1397
- }
1398
- }, {
1399
- key: "dispose",
1400
- value: function dispose() {
1401
- if (this._cleanUpZoomHandler) {
1402
- this._cleanUpZoomHandler();
1403
- }
1404
-
1405
- _get(_getPrototypeOf(Three3D.prototype), "dispose", this).call(this);
1406
- }
1407
- }]);
1408
-
1409
- return Three3D;
1410
- }(_ThreeBase2.ThreeBase);
1411
-
1412
- exports.Three3D = Three3D;