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,722 +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.ThreeBase = exports.onProgress = void 0;
9
-
10
- var _three = require("three");
11
-
12
- var _tween = _interopRequireDefault(require("@tweenjs/tween.js"));
13
-
14
- var _pointerEvent = require("../CommonUtils/pointerEvent");
15
-
16
- var _VisualizationInterface = require("../VisualizationInterface");
17
-
18
- var _Constants = require("../Constants");
19
-
20
- var _removeObject = require("../Utils/removeObject");
21
-
22
- var _disposeMaterial = require("../Utils/disposeMaterial");
23
-
24
- var _createCanvas = require("../Utils/createCanvas");
25
-
26
- var _Deferred = _interopRequireDefault(require("../CommonUtils/Deferred"));
27
-
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
29
-
30
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
31
-
32
- 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."); }
33
-
34
- 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; }
35
-
36
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
37
-
38
- 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; } } }; }
39
-
40
- 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); }
41
-
42
- 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; }
43
-
44
- 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); } }
45
-
46
- 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); }); }; }
47
-
48
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
49
-
50
- 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); } }
51
-
52
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
53
-
54
- 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); }
55
-
56
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
57
-
58
- 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); }; }
59
-
60
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
61
-
62
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
63
-
64
- 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; } }
65
-
66
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
67
-
68
- 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; }
69
-
70
- // default progress handler
71
- var onProgress = function onProgress(xhr) {
72
- if (xhr.lengthComputable) {
73
- var percentComplete = xhr.loaded / xhr.total * 100; // eslint-disable-next-line no-console
74
-
75
- console.log(percentComplete.toFixed(2) + "% downloaded");
76
- }
77
- };
78
- /**
79
- * This object is an additional layer between the Three.js library and this app.
80
- * Responsibilities:
81
- * - handles everything we need to load and render the 3D visualization
82
- * - customizes and simplifies the usage of Three.js in this app
83
- * - provides functionality for the common 3D tasks (like drawing on a texture)
84
- */
85
-
86
-
87
- exports.onProgress = onProgress;
88
-
89
- var ThreeBase = /*#__PURE__*/function (_VisualizationInterfa) {
90
- _inherits(ThreeBase, _VisualizationInterfa);
91
-
92
- var _super = _createSuper(ThreeBase);
93
-
94
- function ThreeBase() {
95
- var _this2;
96
-
97
- _classCallCheck(this, ThreeBase);
98
-
99
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
100
- args[_key] = arguments[_key];
101
- }
102
-
103
- _this2 = _super.call.apply(_super, [this].concat(args));
104
-
105
- _defineProperty(_assertThisInitialized(_this2), "_container", null);
106
-
107
- _defineProperty(_assertThisInitialized(_this2), "_customizableMaterialKeys", []);
108
-
109
- _defineProperty(_assertThisInitialized(_this2), "_customizableMaterials", []);
110
-
111
- _defineProperty(_assertThisInitialized(_this2), "_animationFrame", null);
112
-
113
- _defineProperty(_assertThisInitialized(_this2), "_cameraMovementLocked", false);
114
-
115
- _defineProperty(_assertThisInitialized(_this2), "_hitTestEnabled", true);
116
-
117
- _defineProperty(_assertThisInitialized(_this2), "_isAnimating", false);
118
-
119
- _defineProperty(_assertThisInitialized(_this2), "_animationGroups", []);
120
-
121
- _defineProperty(_assertThisInitialized(_this2), "_loadingManager", Object.assign(new _three.LoadingManager(), {
122
- onError: function onError(url) {
123
- return _this2.onLoadError(url);
124
- }
125
- }));
126
-
127
- _defineProperty(_assertThisInitialized(_this2), "camera", null);
128
-
129
- _defineProperty(_assertThisInitialized(_this2), "scene", null);
130
-
131
- _defineProperty(_assertThisInitialized(_this2), "cameraTweenGroup", new _tween["default"].Group());
132
-
133
- _defineProperty(_assertThisInitialized(_this2), "cameraViews", {});
134
-
135
- _defineProperty(_assertThisInitialized(_this2), "animate", function () {
136
- var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
137
-
138
- if (!_this2._isAnimating) {
139
- window.cancelAnimationFrame(_this2._animationFrame);
140
- _this2._animationFrame = null;
141
- return;
142
- }
143
-
144
- _this2._animationFrame = window.requestAnimationFrame(_this2.animate);
145
-
146
- if (time) {
147
- _this2.cameraTweenGroup.update(time);
148
-
149
- if (_this2.controls) {
150
- _this2.controls.update();
151
- }
152
-
153
- _this2.render();
154
- }
155
- });
156
-
157
- _defineProperty(_assertThisInitialized(_this2), "startAnimation", function (name) {
158
- if (_this2._animationGroups.indexOf(name) === -1) {
159
- _this2._animationGroups.push(name);
160
- }
161
-
162
- if (!_this2._isAnimating) {
163
- _this2._animationDeferred = new _Deferred["default"]("animation");
164
- _this2._isAnimating = true;
165
-
166
- _this2.animate();
167
- }
168
- });
169
-
170
- _defineProperty(_assertThisInitialized(_this2), "stopAnimation", function (name) {
171
- var animGroupIdx = _this2._animationGroups.indexOf(name);
172
-
173
- if (!name) {
174
- _this2._animationGroups.length = 0;
175
- } else if (animGroupIdx !== -1) {
176
- _this2._animationGroups.splice(animGroupIdx, 1);
177
- }
178
-
179
- if (_this2._animationGroups.length) {
180
- // there are still running animations in the list
181
- return;
182
- }
183
-
184
- window.cancelAnimationFrame(_this2._animationFrame);
185
- _this2._isAnimating = false;
186
-
187
- if (_this2._animationDeferred) {
188
- _this2._animationDeferred.resolve();
189
-
190
- delete _this2._animationDeferred;
191
- }
192
- });
193
-
194
- _defineProperty(_assertThisInitialized(_this2), "animationRunning", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
195
- return regeneratorRuntime.wrap(function _callee$(_context) {
196
- while (1) {
197
- switch (_context.prev = _context.next) {
198
- case 0:
199
- _context.t0 = _this2._animationDeferred;
200
-
201
- if (!_context.t0) {
202
- _context.next = 5;
203
- break;
204
- }
205
-
206
- _context.next = 4;
207
- return _this2._animationDeferred.promise;
208
-
209
- case 4:
210
- _context.t0 = _context.sent;
211
-
212
- case 5:
213
- return _context.abrupt("return", _context.t0);
214
-
215
- case 6:
216
- case "end":
217
- return _context.stop();
218
- }
219
- }
220
- }, _callee);
221
- })));
222
-
223
- _defineProperty(_assertThisInitialized(_this2), "endAnimation", function () {
224
- return _this2.cameraTweenGroup.getAll().forEach(function (item) {
225
- return item.end();
226
- });
227
- });
228
-
229
- _defineProperty(_assertThisInitialized(_this2), "getIntersection", function (pointerEvent) {
230
- var raycaster = new _three.Raycaster();
231
-
232
- var _this2$renderer$domEl = _this2.renderer.domElement.getBoundingClientRect(),
233
- elementWidth = _this2$renderer$domEl.width,
234
- elementHeight = _this2$renderer$domEl.height,
235
- offsetX = _this2$renderer$domEl.left,
236
- offsetY = _this2$renderer$domEl.top;
237
-
238
- var point = (0, _pointerEvent.getPointFromPointerEvent)(pointerEvent);
239
- var mouse = new _three.Vector2((point.x - offsetX) / elementWidth * 2 - 1, -((point.y - offsetY) / elementHeight) * 2 + 1);
240
- raycaster.setFromCamera(mouse, _this2.camera);
241
- var intersects = raycaster.intersectObjects(_this2.scene.children, true);
242
-
243
- if (intersects.length > 0) {
244
- var intersect = intersects[0]; // closest object
245
-
246
- return {
247
- target: intersect,
248
- getTextureHit: function getTextureHit() {
249
- var material = intersect.object.material;
250
-
251
- if (material && _this2._customizableMaterialKeys.indexOf(material.name) !== -1) {
252
- // note: the texture Y is flipped by default in the webgl context
253
- // see (https://github.com/mrdoob/three.js/issues/5644)
254
- // so if it's flipped we need to flip it back to get the image coordinates
255
- var texture = material.map;
256
- var flipY = texture.flipY;
257
- var _texture$image = texture.image,
258
- width = _texture$image.width,
259
- height = _texture$image.height;
260
- var x = Math.round(intersect.uv.x * width);
261
- var y = Math.round((flipY ? 1 - intersect.uv.y : intersect.uv.y) * height);
262
- return _this2.textureHitFormatter(intersect, {
263
- width: width,
264
- height: height,
265
- x: x,
266
- y: y
267
- });
268
- }
269
- }
270
- };
271
- }
272
-
273
- return null;
274
- });
275
-
276
- return _this2;
277
- }
278
-
279
- _createClass(ThreeBase, [{
280
- key: "init",
281
- value:
282
- /**
283
- * Initializes the 3D renderer, camera and scene
284
- * @param {HTMLElement} [container=<div>]
285
- * @param {boolean} useDefaultSetup
286
- */
287
- function init() {
288
- var container = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.createElement("div");
289
- var useDefaultSetup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
290
- this._isInitialized = true;
291
- var scene = this.createScene();
292
- this.scene = scene;
293
- this.camera = this.createCamera();
294
- scene.add(this.camera);
295
- this.renderer = this.createRenderer();
296
- this.addToContainer(container);
297
- this.setupContextLostHandling();
298
-
299
- if (useDefaultSetup) {
300
- this.setupDefaultLightning();
301
- this.setupDefaultControls();
302
- this.setupDefaultHitTest();
303
- }
304
-
305
- this.observable.dispatch(_Constants.EventTypes.Initialized);
306
- }
307
- }, {
308
- key: "createScene",
309
- value: function createScene() {
310
- return new _three.Scene();
311
- }
312
- /**
313
- * Create and return a customized three.js renderer object
314
- * @return {WebGLRenderer}
315
- */
316
-
317
- }, {
318
- key: "createRenderer",
319
- value: function createRenderer() {}
320
- /**
321
- * Create and return a customized three.js camera object
322
- * @return {Camera}
323
- */
324
-
325
- }, {
326
- key: "createCamera",
327
- value: function createCamera() {}
328
- /**
329
- * Updates the camera size (different setup for different camera types)
330
- * @param {number} width
331
- * @param {number} height
332
- */
333
- // eslint-disable-next-line no-unused-vars
334
-
335
- }, {
336
- key: "updateCamera",
337
- value: function updateCamera(width, height) {}
338
- }, {
339
- key: "addToContainer",
340
- value: function addToContainer(container) {
341
- this._container = container;
342
- container.appendChild(this.renderer.domElement);
343
- var size = container.getBoundingClientRect();
344
- this.setSize(size, false);
345
- }
346
- /**
347
- * Creates the paths for loading a model (object + material)
348
- * @returns {{objPath: string, mtlPath: string}}
349
- */
350
-
351
- }, {
352
- key: "getModelPaths",
353
- value: function getModelPaths() {
354
- var _basePath = this._basePath,
355
- _itemPath = this._itemPath,
356
- _materialVariantPath = this._materialVariantPath;
357
- var objPath = _itemPath ? [_basePath, _itemPath].join("/") : "";
358
- var mtlPath = _materialVariantPath ? [objPath, "materials", _materialVariantPath].join("/") : "";
359
- return {
360
- objPath: objPath,
361
- mtlPath: mtlPath
362
- };
363
- }
364
- /**
365
- * Sets the canvas size
366
- * @param {number} width
367
- * @param {number} height
368
- * @param {boolean} rerender
369
- */
370
-
371
- }, {
372
- key: "setSize",
373
- value: function setSize(_ref2) {
374
- var width = _ref2.width,
375
- height = _ref2.height;
376
- var rerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
377
- this.renderer.setSize(width, height);
378
- this.updateCamera(width, height); // if not animating render should be called directly
379
-
380
- if (rerender && !this.isAnimating()) {
381
- this.render();
382
- }
383
- }
384
- /**
385
- * Creates a simple cube for testing the scene setup
386
- * @returns {Mesh}
387
- */
388
-
389
- }, {
390
- key: "createSampleCube",
391
- value: function createSampleCube() {
392
- var geometry = new _three.BoxGeometry(1, 1, 1);
393
- var material = new _three.MeshBasicMaterial({
394
- color: 0x00ff00
395
- });
396
- var cube = new _three.Mesh(geometry, material);
397
- return cube;
398
- }
399
- /**
400
- * Implement this function to add default lights to the scene
401
- */
402
-
403
- }, {
404
- key: "setupDefaultLightning",
405
- value: function setupDefaultLightning() {}
406
- /**
407
- * @param {HTMLElement} targetElement
408
- * @param {{}} options Custom options for the controls (see the OrbitControls.js file for details)
409
- */
410
- // eslint-disable-next-line no-unused-vars
411
-
412
- }, {
413
- key: "setupDefaultControls",
414
- value: function setupDefaultControls(targetElement) {
415
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
416
- }
417
- }, {
418
- key: "addAxesHelper",
419
- value: function addAxesHelper() {
420
- var axesHelper = new _three.AxesHelper(50);
421
- this.scene.add(axesHelper);
422
- }
423
- /**
424
- * Enable or disable the controls
425
- * @param {boolean} [enabled=true]
426
- */
427
-
428
- }, {
429
- key: "setControlsEnabled",
430
- value: function setControlsEnabled() {
431
- var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
432
-
433
- if (!this.controls) {
434
- throw new Error("The controls should be available for the setControlsEnabled call!");
435
- }
436
-
437
- this.controls.enabled = enabled;
438
- } // eslint-disable-next-line no-unused-vars
439
-
440
- }, {
441
- key: "updateMaterial",
442
- value: function updateMaterial() {
443
- var targetObject = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.scene;
444
- }
445
- /**
446
- * Getter function for the customizable materials
447
- * @returns {Array}
448
- */
449
-
450
- }, {
451
- key: "getCustomizableMaterials",
452
- value: function getCustomizableMaterials() {
453
- return this._customizableMaterials;
454
- }
455
- }, {
456
- key: "isCustomizableMaterialAvailable",
457
- value: function isCustomizableMaterialAvailable() {
458
- return this._customizableMaterials.length > 0;
459
- }
460
- /**
461
- * Returns the material for the given name, or false if not found.
462
- * @param {string} name
463
- * @returns {boolean|Material}
464
- */
465
-
466
- }, {
467
- key: "findMaterialByName",
468
- value: function findMaterialByName(name) {
469
- var _iterator = _createForOfIteratorHelper(this._customizableMaterials),
470
- _step;
471
-
472
- try {
473
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
474
- var mat = _step.value;
475
-
476
- if (mat.name === name) {
477
- return mat;
478
- }
479
- }
480
- } catch (err) {
481
- _iterator.e(err);
482
- } finally {
483
- _iterator.f();
484
- }
485
-
486
- return false;
487
- }
488
- /**
489
- * Calls the given drawing function for custom drawing implementations
490
- * It provides the drawing context and the original texture image to the callback function.
491
- * It also invalidates the texture to make it update in the next render.
492
- * Calls the render function if it's not animating continuously.
493
- * @param {function(ctx: CanvasRenderingContext2D, image: HTMLImageElement)} drawingFn
494
- * @param {boolean} updateAlpha
495
- * @param {boolean} clearTexture
496
- * @param {string|undefined} materialName If not provided it uses the first customizable material
497
- */
498
-
499
- }, {
500
- key: "getDrawingContext",
501
- value: function getDrawingContext(drawingFn) {
502
- var updateAlpha = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
503
- var clearTexture = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
504
- var materialName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
505
- }
506
- /**
507
- * Starts the continuous animation in the animation frame
508
- * It also updates the related tween group.
509
- * @param {number} time The timestamp value from the requestAnimationFrame callback (DOMHighResTimeStamp)
510
- */
511
-
512
- }, {
513
- key: "render",
514
- value: function render() {
515
- this.renderer && this.renderer.render(this.scene, this.camera);
516
- }
517
- }, {
518
- key: "isAnimating",
519
- value: function isAnimating() {
520
- return this._isAnimating;
521
- }
522
- }, {
523
- key: "cleanUpCameraAnimations",
524
- value: function cleanUpCameraAnimations() {
525
- this.stopAnimation("camera");
526
- this.cameraTweenGroup.getAll().forEach(function (t) {
527
- return t.stop();
528
- });
529
- this.cameraTweenGroup.removeAll();
530
- }
531
- /**
532
- * Ads a click event listener to the targetElement
533
- * The hit test will be performed only if the controls are enabled.
534
- * On success it dispatches the EventTypes.Intersection event with the intersection data.
535
- * @see getIntersection
536
- * @see Observable
537
- * @see createPointerHitListener
538
- * @param targetElement
539
- */
540
-
541
- }, {
542
- key: "setupDefaultHitTest",
543
- value: function setupDefaultHitTest(targetElement) {
544
- var _this3 = this;
545
-
546
- var element = targetElement || this.renderer.domElement;
547
- (0, _pointerEvent.createPointerHitListener)(element, function (evt) {
548
- if (!_this3._hitTestEnabled) {
549
- return;
550
- }
551
-
552
- if (!_this3.controls || _this3.controls.enabled || _this3._cameraMovementLocked) {
553
- var is = _this3.getIntersection(evt);
554
-
555
- _this3.observable.dispatch(is ? _Constants.EventTypes.Intersection : _Constants.EventTypes.ClickAway, is);
556
- }
557
- });
558
- }
559
- /**
560
- * Checks if the pointer intersects with the model
561
- * @param {MouseEvent|TouchEvent} pointerEvent
562
- * @returns {{target: { distance, point, face, faceIndex, object }, getTextureHit: (function())}|null}
563
- */
564
-
565
- }, {
566
- key: "textureHitFormatter",
567
- value: function textureHitFormatter(intersect, position) {
568
- return position;
569
- }
570
- }, {
571
- key: "setupContextLostHandling",
572
- value: function setupContextLostHandling() {
573
- var _this = this;
574
-
575
- this.renderer.getContext().canvas.addEventListener("webglcontextlost", function (event) {
576
- event.preventDefault();
577
- window.cancelAnimationFrame(_this._animationFrame); // eslint-disable-next-line no-console
578
-
579
- console.warn("WEBGL CONTEXT LOST");
580
- }, false);
581
- this.renderer.getContext().canvas.addEventListener("webglcontextrestored", function () {
582
- // if it was animating before start it again
583
- if (_this._animationFrame) {
584
- _this.animate();
585
- } // eslint-disable-next-line no-console
586
-
587
-
588
- console.warn("WEGL CONTEXT RESTORED");
589
- }, false);
590
- }
591
- }, {
592
- key: "toggleCameraLock",
593
- value: function toggleCameraLock(locked) {
594
- this._cameraMovementLocked = locked;
595
-
596
- if (this.controls) {
597
- this.controls.enabled = !locked;
598
- }
599
- }
600
- }, {
601
- key: "toggleHitTest",
602
- value: function toggleHitTest(enabled) {
603
- this._hitTestEnabled = enabled;
604
- }
605
- }, {
606
- key: "clearScene",
607
- value: function clearScene() {
608
- // remove all Group objects
609
- this.scene.children.filter(function (obj) {
610
- return obj.type === "Group";
611
- }).forEach(_removeObject.removeObject); // clear customizable materials and camera views
612
-
613
- this._customizableMaterials = [];
614
- this.cameraViews = {};
615
- }
616
- }, {
617
- key: "dispose",
618
- value: function dispose() {
619
- this.stopAnimation();
620
- this.cleanUpCameraAnimations();
621
- this.observable.dispose();
622
-
623
- if (this._container && this.renderer) {
624
- this._container.removeChild(this.renderer.domElement);
625
- }
626
-
627
- if (this.scene) {
628
- this.scene.traverse(function (obj) {
629
- if (obj.geometry) {
630
- obj.geometry.dispose();
631
- }
632
-
633
- if (obj.material) {
634
- (0, _disposeMaterial.disposeMaterial)(obj.material);
635
- }
636
- });
637
- }
638
-
639
- this.scene = null;
640
-
641
- if (this.renderer) {
642
- this.renderer.dispose();
643
- }
644
-
645
- this.renderer = null;
646
- this.camera = null;
647
- this.cameraViews = null;
648
- this.controls = null;
649
- this._customizableMaterials = [];
650
- this._isInitialized = false; // eslint-disable-next-line no-console
651
-
652
- console.info("Three instance has been successfully disposed.");
653
- }
654
- }, {
655
- key: "abortScreenshotting",
656
- value: function abortScreenshotting() {
657
- this._screenshottingInProgress && Object.defineProperty(this, "_abortScreenshotting", {
658
- configurable: true,
659
- get: function get() {
660
- delete this._abortScreenshotting;
661
- return true;
662
- }
663
- });
664
- }
665
- }, {
666
- key: "createTempOverlay",
667
- value: function () {
668
- var _createTempOverlay = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
669
- var canvas, _createWorkingCanvas, _createWorkingCanvas2, tmpCanvas, scale, container;
670
-
671
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
672
- while (1) {
673
- switch (_context2.prev = _context2.next) {
674
- case 0:
675
- canvas = this.renderer.domElement;
676
- this.render();
677
- _createWorkingCanvas = (0, _createCanvas.createWorkingCanvas)(canvas, true), _createWorkingCanvas2 = _slicedToArray(_createWorkingCanvas, 1), tmpCanvas = _createWorkingCanvas2[0];
678
- scale = 1 / this.renderer.getPixelRatio();
679
- container = this._container;
680
- Object.assign(tmpCanvas.style, {
681
- position: "absolute",
682
- top: "50%",
683
- left: "50%",
684
- transform: "translate(-50%, -50%) scale(".concat(scale, ", ").concat(scale, ")"),
685
- opacity: 0
686
- });
687
- container.insertBefore(tmpCanvas, canvas);
688
- _context2.next = 9;
689
- return new Promise(function (resolve) {
690
- window.requestAnimationFrame(function () {
691
- tmpCanvas.style.opacity = 1;
692
- canvas.style.visibility = "hidden";
693
- resolve();
694
- });
695
- });
696
-
697
- case 9:
698
- return _context2.abrupt("return", function () {
699
- canvas.style.visibility = "visible";
700
- container.removeChild(tmpCanvas);
701
- });
702
-
703
- case 10:
704
- case "end":
705
- return _context2.stop();
706
- }
707
- }
708
- }, _callee2, this);
709
- }));
710
-
711
- function createTempOverlay() {
712
- return _createTempOverlay.apply(this, arguments);
713
- }
714
-
715
- return createTempOverlay;
716
- }()
717
- }]);
718
-
719
- return ThreeBase;
720
- }(_VisualizationInterface.VisualizationInterface);
721
-
722
- exports.ThreeBase = ThreeBase;