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,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getDesignAreaCanvasSize = void 0;
7
-
8
- var _pick = _interopRequireDefault(require("lodash/pick"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
-
12
- var getDesignAreaCanvasSize = function getDesignAreaCanvasSize(designArea) {
13
- var baseShape = designArea.baseShape,
14
- position = designArea.position;
15
- var sourceObject;
16
-
17
- if (baseShape && baseShape.width && baseShape.height) {
18
- sourceObject = baseShape;
19
- } else if (position && position.width && position.height) {
20
- sourceObject = position;
21
- }
22
-
23
- if (!sourceObject) {
24
- // eslint-disable-next-line no-console
25
- console.error("Incomplete design area data, baseShape and position has to be set up correctly.", designArea);
26
- throw new Error("There is no valid source object provided to get the width and height for the canvas!");
27
- }
28
-
29
- return (0, _pick["default"])(sourceObject, ["width", "height"]);
30
- };
31
-
32
- exports.getDesignAreaCanvasSize = getDesignAreaCanvasSize;
@@ -1,334 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "optimizeSizeToTexture", {
7
- enumerable: true,
8
- get: function get() {
9
- return _textureBuilderFunctions.optimizeSizeToTexture;
10
- }
11
- });
12
- exports.clearAreaWithPadding = exports.getPositionWithPadding = exports.highlightArea = exports.getTransformProps = exports.transformCanvas = exports.getDesignAreaSize = exports.createTextureBuilder = void 0;
13
-
14
- var _PrintingEffects = require("../../PrintingEffects/PrintingEffects");
15
-
16
- var _createCanvas = require("../createCanvas");
17
-
18
- var _textureBuilderFunctions = require("./textureBuilderFunctions");
19
-
20
- var _getDesignAreaCanvasSize = require("../DesignArea/getDesignAreaCanvasSize");
21
-
22
- var _excluded = ["scaling"],
23
- _excluded2 = ["x", "y", "width", "height"];
24
-
25
- 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; }
26
-
27
- 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; }
28
-
29
- 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; }
30
-
31
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
32
-
33
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
34
-
35
- 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); } }
36
-
37
- 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); }); }; }
38
-
39
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
40
-
41
- 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."); }
42
-
43
- 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); }
44
-
45
- 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; }
46
-
47
- 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; }
48
-
49
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
50
-
51
- var createTextureBuilder = function createTextureBuilder(textureImage) {
52
- var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
53
-
54
- var _createWorkingCanvas = (0, _createCanvas.createWorkingCanvas)(textureImage),
55
- _createWorkingCanvas2 = _slicedToArray(_createWorkingCanvas, 2),
56
- canvas = _createWorkingCanvas2[0],
57
- ctx = _createWorkingCanvas2[1];
58
-
59
- return function () {
60
- var configObject = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
61
- var _params$scaling = params.scaling,
62
- scaling = _params$scaling === void 0 ? 1 : _params$scaling,
63
- _params$currentZoom = params.currentZoom,
64
- currentZoom = _params$currentZoom === void 0 ? 1 : _params$currentZoom,
65
- _params$useTextureSiz = params.useTextureSize,
66
- useTextureSize = _params$useTextureSiz === void 0 ? false : _params$useTextureSiz; // apply the scaling on the working canvas, so everything will be drawn in the correct size and position
67
-
68
- ctx.scale(scaling, scaling);
69
-
70
- var calculateDesignAreaSize = function calculateDesignAreaSize(designArea) {
71
- return getDesignAreaSize(designArea, useTextureSize && canvas);
72
- };
73
-
74
- var drawCanvasToArea = /*#__PURE__*/function () {
75
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref) {
76
- var drawToContext, designArea, effect, effectOptions, getSvg, baseShape, position, type, _calculateDesignAreaS, width, height, _scaling, effectCanvas;
77
-
78
- return regeneratorRuntime.wrap(function _callee$(_context) {
79
- while (1) {
80
- switch (_context.prev = _context.next) {
81
- case 0:
82
- drawToContext = _ref.drawToContext, designArea = _ref.designArea, effect = _ref.effect, effectOptions = _ref.effectOptions, getSvg = _ref.getSvg;
83
- baseShape = designArea.baseShape, position = designArea.position;
84
-
85
- if (!(!baseShape || !position)) {
86
- _context.next = 5;
87
- break;
88
- }
89
-
90
- // eslint-disable-next-line no-console
91
- console.log("No design area provided.");
92
- return _context.abrupt("return");
93
-
94
- case 5:
95
- type = baseShape.type;
96
- _context.t0 = type;
97
- _context.next = _context.t0 === "Plane" ? 9 : _context.t0 === "Cylinder" ? 9 : 21;
98
- break;
99
-
100
- case 9:
101
- _calculateDesignAreaS = calculateDesignAreaSize(designArea), width = _calculateDesignAreaS.width, height = _calculateDesignAreaS.height, _scaling = _calculateDesignAreaS.scaling;
102
- effectCanvas = new _PrintingEffects.EffectCanvas(width, height);
103
- _context.next = 13;
104
- return drawToContext(effectCanvas.ctx, 0, 0, width, height, {
105
- currentZoom: currentZoom
106
- });
107
-
108
- case 13:
109
- if (!(effect && effect !== "print")) {
110
- _context.next = 16;
111
- break;
112
- }
113
-
114
- _context.next = 16;
115
- return effectCanvas.applyEffect(effect, {
116
- getSvg: getSvg,
117
- effectOptions: effectOptions,
118
- currentZoom: currentZoom
119
- });
120
-
121
- case 16:
122
- ctx.save();
123
- transformCanvas(ctx, getTransformProps(baseShape, position), _scaling);
124
- effectCanvas.drawOn(ctx);
125
- ctx.restore();
126
- return _context.abrupt("break", 23);
127
-
128
- case 21:
129
- // eslint-disable-next-line no-console
130
- console.error("Unknown baseShape type: ".concat(type, ". Texture update will be skipped."));
131
- return _context.abrupt("return");
132
-
133
- case 23:
134
- case "end":
135
- return _context.stop();
136
- }
137
- }
138
- }, _callee);
139
- }));
140
-
141
- return function drawCanvasToArea(_x) {
142
- return _ref2.apply(this, arguments);
143
- };
144
- }();
145
-
146
- var highlightDesignAreas = function highlightDesignAreas(designAreas) {
147
- designAreas.forEach(function (designArea) {
148
- var baseShape = designArea.baseShape,
149
- position = designArea.position;
150
-
151
- if (!baseShape || !position) {
152
- return;
153
- }
154
-
155
- ctx.save();
156
-
157
- var _calculateDesignAreaS2 = calculateDesignAreaSize(designArea),
158
- scaling = _calculateDesignAreaS2.scaling,
159
- size = _objectWithoutProperties(_calculateDesignAreaS2, _excluded);
160
-
161
- transformCanvas(ctx, getTransformProps(baseShape, position), scaling);
162
- var highlight = configObject.highlight;
163
- var _highlight$lineWidth = highlight.lineWidth,
164
- lineWidth = _highlight$lineWidth === void 0 ? 2 : _highlight$lineWidth;
165
- highlightArea(ctx, size, _objectSpread(_objectSpread({}, highlight), {}, {
166
- lineWidth: Math.ceil(lineWidth / currentZoom)
167
- }));
168
- ctx.restore();
169
- });
170
- };
171
-
172
- var drawOn = function drawOn(ctx) {
173
- ctx.drawImage(canvas, 0, 0);
174
- };
175
-
176
- var getTextureImage = function getTextureImage() {
177
- return textureImage;
178
- };
179
-
180
- var getParams = function getParams() {
181
- return params;
182
- };
183
-
184
- return {
185
- drawCanvasToArea: drawCanvasToArea,
186
- highlightDesignAreas: highlightDesignAreas,
187
- drawOn: drawOn,
188
- getTextureImage: getTextureImage,
189
- getParams: getParams,
190
- calculateDesignAreaSize: calculateDesignAreaSize
191
- };
192
- };
193
- };
194
- /**
195
- * Get the design area size
196
- * note: this can be different from the canvas size
197
- * It uses the position first, then the base shape, then 0 as default values
198
- * @param {object} designArea The design area object
199
- * @param {HTMLImageElement|HTMLCanvasElement} [textureElement]
200
- * @returns {{width: number, height: number, scaling: number}}
201
- */
202
-
203
-
204
- exports.createTextureBuilder = createTextureBuilder;
205
-
206
- var getDesignAreaSize = function getDesignAreaSize(designArea, textureElement) {
207
- var _baseShape$position$d = _objectSpread({
208
- baseShape: {},
209
- position: {}
210
- }, designArea),
211
- baseShape = _baseShape$position$d.baseShape,
212
- position = _baseShape$position$d.position;
213
-
214
- var _width$height$baseSha = _objectSpread(_objectSpread({
215
- width: 0,
216
- height: 0
217
- }, baseShape), position),
218
- width = _width$height$baseSha.width,
219
- height = _width$height$baseSha.height;
220
-
221
- var canvasSize = (0, _getDesignAreaCanvasSize.getDesignAreaCanvasSize)(designArea);
222
- var scaling = textureElement ? textureElement.width / canvasSize.width : 1;
223
- return {
224
- width: width * scaling,
225
- height: height * scaling,
226
- scaling: scaling
227
- };
228
- };
229
-
230
- exports.getDesignAreaSize = getDesignAreaSize;
231
-
232
- var transformCanvas = function transformCanvas(ctx) {
233
- var transformProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
234
- var scaling = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
235
- var _transformProps$x = transformProps.x,
236
- x = _transformProps$x === void 0 ? 0 : _transformProps$x,
237
- _transformProps$y = transformProps.y,
238
- y = _transformProps$y === void 0 ? 0 : _transformProps$y,
239
- _transformProps$width = transformProps.width,
240
- width = _transformProps$width === void 0 ? 0 : _transformProps$width,
241
- _transformProps$heigh = transformProps.height,
242
- height = _transformProps$heigh === void 0 ? 0 : _transformProps$heigh,
243
- _transformProps$angle = transformProps.angle,
244
- angle = _transformProps$angle === void 0 ? 0 : _transformProps$angle,
245
- _transformProps$insid = transformProps.inside,
246
- inside = _transformProps$insid === void 0 ? false : _transformProps$insid;
247
-
248
- if (x !== 0 || y !== 0) {
249
- ctx.translate(x * scaling, y * scaling);
250
- }
251
-
252
- if (inside) {
253
- // if the texture is inside, flip it horizontally (it's applied on the back side of the mesh)
254
- ctx.scale(-1, 1);
255
- }
256
-
257
- if (angle !== 0) {
258
- ctx.rotate(angle);
259
- }
260
-
261
- if (width !== 0 || height !== 0) {
262
- ctx.translate(Math.round(-width * scaling / 2), Math.round(-height * scaling / 2));
263
- }
264
- };
265
-
266
- exports.transformCanvas = transformCanvas;
267
-
268
- var getTransformProps = function getTransformProps() {
269
- var baseShape = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
270
- var position = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
271
- var _baseShape$inside = baseShape.inside,
272
- inside = _baseShape$inside === void 0 ? false : _baseShape$inside;
273
- return _objectSpread(_objectSpread({}, position), {}, {
274
- inside: inside
275
- });
276
- };
277
-
278
- exports.getTransformProps = getTransformProps;
279
-
280
- var highlightArea = function highlightArea(ctx, size) {
281
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
282
- var width = size.width,
283
- height = size.height;
284
-
285
- var _borderColor$backgrou = _objectSpread({
286
- borderColor: "rgba(0,0,0,0.9)",
287
- backgroundColor: "transparent",
288
- lineWidth: 2
289
- }, options),
290
- borderColor = _borderColor$backgrou.borderColor,
291
- backgroundColor = _borderColor$backgrou.backgroundColor,
292
- lineWidth = _borderColor$backgrou.lineWidth;
293
-
294
- ctx.fillStyle = backgroundColor;
295
- ctx.fillRect(0, 0, width, height);
296
- ctx.strokeStyle = borderColor;
297
- ctx.lineWidth = lineWidth; // inset stroke instead of centered
298
-
299
- var lineWidthHalf = lineWidth / 2;
300
- ctx.strokeRect(lineWidthHalf, lineWidthHalf, width - lineWidth, height - lineWidth);
301
- };
302
-
303
- exports.highlightArea = highlightArea;
304
-
305
- var getPositionWithPadding = function getPositionWithPadding(_ref3, padding) {
306
- var x = _ref3.x,
307
- y = _ref3.y,
308
- width = _ref3.width,
309
- height = _ref3.height,
310
- otherProps = _objectWithoutProperties(_ref3, _excluded2);
311
-
312
- return _objectSpread(_objectSpread({}, otherProps), {}, {
313
- x: x - padding,
314
- y: y - padding,
315
- width: width + 2 * padding,
316
- height: height + 2 * padding
317
- });
318
- };
319
-
320
- exports.getPositionWithPadding = getPositionWithPadding;
321
-
322
- var clearAreaWithPadding = function clearAreaWithPadding(ctx, originalImage, position) {
323
- var padding = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
324
-
325
- var _getPositionWithPaddi = getPositionWithPadding(position, padding),
326
- x = _getPositionWithPaddi.x,
327
- y = _getPositionWithPaddi.y,
328
- width = _getPositionWithPaddi.width,
329
- height = _getPositionWithPaddi.height;
330
-
331
- ctx.drawImage(originalImage, x, y, width, height, -padding, -padding, width, height);
332
- };
333
-
334
- exports.clearAreaWithPadding = clearAreaWithPadding;
@@ -1,87 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.optimizeSizeToTexture = exports.fitNextPOT = exports.ceilPOT = exports.multiplySize = void 0;
7
-
8
- /**
9
- *
10
- * @param {number} width
11
- * @param {number} height
12
- * @param {number} scalarValue
13
- * @return {{width: number, height: number}}
14
- */
15
- var multiplySize = function multiplySize(_ref, scalarValue) {
16
- var width = _ref.width,
17
- height = _ref.height;
18
- return {
19
- width: width * scalarValue,
20
- height: height * scalarValue
21
- };
22
- };
23
- /**
24
- * Returns the next power of two number
25
- * @param {number} x
26
- * @return {number}
27
- */
28
-
29
-
30
- exports.multiplySize = multiplySize;
31
-
32
- var ceilPOT = function ceilPOT(x) {
33
- return Math.pow(2, Math.ceil(Math.log(x) / Math.log(2)));
34
- };
35
- /**
36
- * Finds the next power of two size
37
- * @param {number} width
38
- * @param {number} height
39
- * @return {{width: number, height: number}}
40
- */
41
-
42
-
43
- exports.ceilPOT = ceilPOT;
44
-
45
- var fitNextPOT = function fitNextPOT(_ref2) {
46
- var width = _ref2.width,
47
- height = _ref2.height;
48
- var ratio = width / height;
49
-
50
- if (ratio > 1) {
51
- width = ceilPOT(width);
52
- height = width / ratio;
53
- } else {
54
- height = ceilPOT(height);
55
- width = height * ratio;
56
- }
57
-
58
- return {
59
- width: width,
60
- height: height
61
- };
62
- };
63
- /**
64
- * Single function that does the texture size optimization in one step
65
- * @param {{width: number, height: number}} size
66
- * @param {number} pixelRatio
67
- * @param {boolean} fitPOT
68
- * @param {number} maxTextureSize
69
- * @return {*}
70
- */
71
-
72
-
73
- exports.fitNextPOT = fitNextPOT;
74
-
75
- var optimizeSizeToTexture = function optimizeSizeToTexture(size) {
76
- var pixelRatio = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
77
- var fitPOT = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
78
- var maxTextureSize = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 2048;
79
-
80
- var _size = multiplySize(size, pixelRatio);
81
-
82
- var potSize = fitPOT ? fitNextPOT(_size) : _size;
83
- var sizeMax = Math.max(potSize.width, potSize.height);
84
- return sizeMax > maxTextureSize ? multiplySize(potSize, maxTextureSize / sizeMax) : potSize;
85
- };
86
-
87
- exports.optimizeSizeToTexture = optimizeSizeToTexture;
@@ -1,58 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.alignToElement = exports.getRectCenter = void 0;
7
-
8
- var getRectCenter = function getRectCenter(_ref) {
9
- var width = _ref.width,
10
- height = _ref.height,
11
- left = _ref.left,
12
- top = _ref.top;
13
- var x = left + width / 2;
14
- var y = top + height / 2;
15
- return {
16
- x: x,
17
- y: y
18
- };
19
- };
20
- /**
21
- * Calculates the view offset to align the camera with the given element
22
- * @param {ThreeBase} visualization
23
- * @param {Element} element
24
- */
25
-
26
-
27
- exports.getRectCenter = getRectCenter;
28
-
29
- var alignToElement = function alignToElement(visualization, element) {
30
- var canvas = visualization.renderer && visualization.renderer.domElement;
31
-
32
- if (visualization && visualization.camera) {
33
- if (!element) {
34
- visualization.camera.clearViewOffset();
35
- return;
36
- } else if (!canvas) {
37
- return;
38
- }
39
-
40
- var containerRect = canvas.getBoundingClientRect();
41
- var width = containerRect.width,
42
- height = containerRect.height;
43
-
44
- var _getRectCenter = getRectCenter(containerRect),
45
- cx = _getRectCenter.x,
46
- cy = _getRectCenter.y;
47
-
48
- var _getRectCenter2 = getRectCenter(element.getBoundingClientRect()),
49
- tx = _getRectCenter2.x,
50
- ty = _getRectCenter2.y;
51
-
52
- var dx = cx - tx;
53
- var dy = cy - ty;
54
- visualization.camera.setViewOffset(width, height, dx, dy, width, height);
55
- }
56
- };
57
-
58
- exports.alignToElement = alignToElement;
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createAlphaMapFromAlphaChannel = void 0;
7
-
8
- var _createCanvas = require("./createCanvas");
9
-
10
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
-
12
- 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."); }
13
-
14
- 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); }
15
-
16
- 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; }
17
-
18
- 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; }
19
-
20
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
21
-
22
- /**
23
- * Algorithm:
24
- * 1. copy the source canvas on a working canvas
25
- * 2. make it's content white keeping the alpha values
26
- * 3. draw it on the target canvas using the higher alpha value
27
- * @param {HTMLCanvasElement} srcCanvas The canvas that has transparency
28
- * @param {HTMLCanvasElement} dstCanvas The target canvas that holds the alpha map
29
- */
30
- var createAlphaMapFromAlphaChannel = function createAlphaMapFromAlphaChannel(srcCanvas, dstCanvas) {
31
- var _createWorkingCanvas = (0, _createCanvas.createWorkingCanvas)(srcCanvas, true),
32
- _createWorkingCanvas2 = _slicedToArray(_createWorkingCanvas, 2),
33
- tmpCanvas = _createWorkingCanvas2[0],
34
- tmpCtx = _createWorkingCanvas2[1]; // draw a white rectangle over the source content using the source-in operation
35
- // to make the source image white keeping the alpha values
36
-
37
-
38
- tmpCtx.globalCompositeOperation = "source-in";
39
- tmpCtx.fillStyle = "white";
40
- tmpCtx.fillRect(0, 0, srcCanvas.width, srcCanvas.height); // copy the content alpha to the target canvas using the lighten operation
41
- // to keep the higher alpha value of the two maps
42
-
43
- var dstCtx = dstCanvas.getContext("2d");
44
- var globalCompositeOperation = dstCtx.globalCompositeOperation;
45
- dstCtx.globalCompositeOperation = "lighten";
46
- dstCtx.drawImage(tmpCanvas, 0, 0);
47
- dstCtx.globalCompositeOperation = globalCompositeOperation;
48
- };
49
-
50
- exports.createAlphaMapFromAlphaChannel = createAlphaMapFromAlphaChannel;
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createCache = createCache;
7
-
8
- function createCache(maxSize) {
9
- var storage = new Map();
10
- var sizeLimit = maxSize - 1;
11
-
12
- function removeLeastRecentlyUsedEntries() {
13
- if (storage.size > sizeLimit) {
14
- var orderedList = Array.from(storage).sort(function (a, b) {
15
- return b[1].time - a[1].time;
16
- });
17
-
18
- for (var i = orderedList.length - 1; i >= sizeLimit; i--) {
19
- storage["delete"](orderedList[i][0]);
20
- }
21
- }
22
- }
23
-
24
- return {
25
- get: function get(key) {
26
- if (storage.has(key)) {
27
- var item = storage.get(key);
28
- item.time = Date.now();
29
- return item.value;
30
- }
31
- },
32
- set: function set(key, value) {
33
- removeLeastRecentlyUsedEntries();
34
- storage.set(key, {
35
- time: Date.now(),
36
- value: value
37
- });
38
- },
39
- clear: function clear() {
40
- storage.clear();
41
- },
42
- "delete": function _delete(key) {
43
- storage["delete"](key);
44
- }
45
- };
46
- }
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createWorkingCanvas = void 0;
7
-
8
- var createWorkingCanvas = function createWorkingCanvas(sourceObject) {
9
- var copy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
10
- var width = sourceObject.width,
11
- height = sourceObject.height;
12
- var canvas = Object.assign(document.createElement("canvas"), {
13
- width: width,
14
- height: height
15
- });
16
- var ctx = canvas.getContext("2d");
17
-
18
- if (!ctx) {
19
- throw new Error("Could not get 2d context for working canvas!");
20
- }
21
-
22
- if (copy) {
23
- ctx.drawImage(sourceObject, 0, 0);
24
- }
25
-
26
- return [canvas, ctx];
27
- };
28
-
29
- exports.createWorkingCanvas = createWorkingCanvas;