redhotmagma-visualization 1.28.3 → 1.29.1

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 (88) hide show
  1. package/AlignTargetProvider.js +129 -0
  2. package/CommonUtils/Deferred.js +135 -0
  3. package/CommonUtils/Observable.js +126 -0
  4. package/CommonUtils/PropertyObserver.js +61 -0
  5. package/CommonUtils/SyncCurrentFunction.js +59 -0
  6. package/CommonUtils/SyncObservableEvent.js +19 -0
  7. package/CommonUtils/pointerEvent.js +415 -0
  8. package/Constants.js +23 -0
  9. package/DevApp.js +1049 -0
  10. package/ExposedModules.js +26 -0
  11. package/FallbackVisualization.js +26 -0
  12. package/PrintingEffects/ColorEmbossingEffect.js +58 -0
  13. package/PrintingEffects/DomingEffect.js +150 -0
  14. package/PrintingEffects/EmbossingEffect.js +65 -0
  15. package/PrintingEffects/EmbroideryEffect.js +541 -0
  16. package/PrintingEffects/EngravingEffect.js +65 -0
  17. package/PrintingEffects/PrintingEffects.js +117 -0
  18. package/PrintingEffects/PrintingEffectsUtils.js +53 -0
  19. package/PrintingEffects/resources/embroidery_multiply.jpg +0 -0
  20. package/PrintingEffects/resources/embroidery_screen.jpg +0 -0
  21. package/README.md +11 -4
  22. package/React/ReactBase.js +111 -0
  23. package/Three/Controls/OrbitControls.js +745 -0
  24. package/Three/Exporters/glTFExporter.js +48 -0
  25. package/Three/Loaders/ColladaLoader.js +2916 -0
  26. package/Three/Loaders/MTLLoader.js +449 -0
  27. package/Three/Loaders/OBJLoader.js +548 -0
  28. package/Three/Three2D.js +1790 -0
  29. package/Three/Three2DLayers.js +504 -0
  30. package/Three/Three3D.js +1412 -0
  31. package/Three/Three3DScene.js +1432 -0
  32. package/Three/ThreeBase.js +724 -0
  33. package/Utils/DesignArea/getDesignAreaCanvasSize.js +32 -0
  34. package/Utils/TextureBuilder/createTextureBuilder.js +334 -0
  35. package/Utils/TextureBuilder/textureBuilderFunctions.js +87 -0
  36. package/Utils/alignToElement.js +58 -0
  37. package/Utils/createAlphaMapFromAlphaChannel.js +50 -0
  38. package/Utils/createCache.js +46 -0
  39. package/Utils/createCanvas.js +29 -0
  40. package/Utils/createImageRepository.js +124 -0
  41. package/Utils/disposeMaterial.js +41 -0
  42. package/Utils/getImageSize.js +15 -0
  43. package/Utils/imagePreloader.js +76 -0
  44. package/Utils/initTextureCanvas.js +49 -0
  45. package/Utils/isMobileDevice.js +19 -0
  46. package/Utils/optimizeTextureImage.js +73 -0
  47. package/Utils/rememberCameraViewOffset.js +21 -0
  48. package/Utils/removeObject.js +22 -0
  49. package/Utils/restrictCameraMovement.js +45 -0
  50. package/Utils/setOrthographicCameraSize.js +16 -0
  51. package/Utils/updateFitSizeToElement.js +39 -0
  52. package/VisualizationContainer.js +279 -0
  53. package/VisualizationInterface.js +298 -0
  54. package/VisualizationProvider.js +38 -0
  55. package/__mocks__/exportedSample.svg +45 -0
  56. package/index.js +16 -0
  57. package/package.json +10 -70
  58. package/scripts/cpPublic.js +9 -12
  59. package/scripts/cpPublicLocal.js +30 -0
  60. package/src/CommonUtils/Observable.js +1 -0
  61. package/src/CommonUtils/pointerEvent.js +2 -1
  62. package/src/DevApp.js +2 -1
  63. package/src/FallbackVisualization.js +1 -5
  64. package/src/PrintingEffects/DomingEffect.js +1 -0
  65. package/src/PrintingEffects/EmbroideryEffect.js +3 -2
  66. package/src/React/ReactBase.js +1 -1
  67. package/src/Three/Controls/OrbitControls.js +2 -0
  68. package/src/Three/Loaders/ColladaLoader.js +111 -294
  69. package/src/Three/Loaders/MTLLoader.js +2 -0
  70. package/src/Three/Loaders/OBJLoader.js +2 -0
  71. package/src/Three/Three2D.js +18 -11
  72. package/src/Three/Three3D.js +9 -1
  73. package/src/Three/ThreeBase.js +14 -2
  74. package/src/Utils/DesignArea/getDesignAreaCanvasSize.js +1 -0
  75. package/src/Utils/TextureBuilder/createTextureBuilder.js +2 -0
  76. package/src/Utils/imagePreloader.js +1 -0
  77. package/src/Utils/initTextureCanvas.js +3 -0
  78. package/src/Utils/isMobileDevice.js +2 -0
  79. package/src/Utils/optimizeTextureImage.js +1 -0
  80. package/src/VisualizationContainer.js +3 -1
  81. package/src/VisualizationInterface.js +10 -1
  82. package/visualizationAdapterCreator.js +76 -0
  83. package/babel.config.js +0 -41
  84. package/scripts/cpPath.js +0 -151
  85. package/scripts/moveLibToPackageRoot.js +0 -44
  86. package/scripts/utils/fileSystem.js +0 -69
  87. package/scripts/utils/process.js +0 -19
  88. package/tsconfig.json +0 -22
package/DevApp.js ADDED
@@ -0,0 +1,1049 @@
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["default"] = void 0;
9
+
10
+ var _root = require("react-hot-loader/root");
11
+
12
+ var _react = _interopRequireWildcard(require("react"));
13
+
14
+ var _VisualizationProvider = require("./VisualizationProvider");
15
+
16
+ var _VisualizationContainer = _interopRequireDefault(require("./VisualizationContainer"));
17
+
18
+ var _visualizationAdapterCreator = require("./visualizationAdapterCreator");
19
+
20
+ var _designAreaList2D = _interopRequireDefault(require("./__mocks__/designAreaList2D"));
21
+
22
+ var _designAreaList2DVariant = _interopRequireDefault(require("./__mocks__/designAreaList2DVariant"));
23
+
24
+ var _designAreaList3DVariant = _interopRequireDefault(require("./__mocks__/designAreaList3DVariant"));
25
+
26
+ var _exportedSampleSvg = require("./__mocks__/exportedSampleSvg");
27
+
28
+ var _AlignTargetProvider = require("./AlignTargetProvider");
29
+
30
+ var _Constants = require("./Constants");
31
+
32
+ var _three = require("three");
33
+
34
+ var _makeStyles = _interopRequireDefault(require("@material-ui/core/styles/makeStyles"));
35
+
36
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
37
+
38
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
39
+
40
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
41
+
42
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
43
+
44
+ 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."); }
45
+
46
+ 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; }
47
+
48
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
49
+
50
+ 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; } } }; }
51
+
52
+ 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); }
53
+
54
+ 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; }
55
+
56
+ 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); } }
57
+
58
+ 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); }); }; }
59
+
60
+ 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; }
61
+
62
+ 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; }
63
+
64
+ 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; }
65
+
66
+ var adapterConfig = (0, _visualizationAdapterCreator.createAdapterConfig)({
67
+ host: "/"
68
+ }, {
69
+ "2dVariant": {
70
+ modelBasePath: "/models/2dVariant"
71
+ }
72
+ });
73
+ var textureBuilderConfig = {
74
+ highlight: {
75
+ borderColor: "red",
76
+ lineWidth: 2
77
+ }
78
+ };
79
+ var effectOptions = {
80
+ engraving: {
81
+ fillColor: "rgba(250,250,200,0.7)"
82
+ }
83
+ };
84
+ var modelData = {
85
+ "3dScene": {
86
+ Customized: {
87
+ designAreaList: [],
88
+ configuration: {
89
+ visualizationData: {
90
+ sceneData: [{
91
+ src: "models/3d/Sofa/base.gltf",
92
+ material: {
93
+ params: {
94
+ color: "#202020"
95
+ }
96
+ }
97
+ }, {
98
+ src: "models/3d/Sofa/side.gltf",
99
+ material: {
100
+ params: {
101
+ map: "textures/red.jpg"
102
+ }
103
+ }
104
+ }, {
105
+ src: "models/3d/Sofa/sitting_pads.gltf",
106
+ material: {
107
+ params: {
108
+ map: "textures/rhm.jpg"
109
+ }
110
+ }
111
+ }, {
112
+ src: "models/3d/Sofa/back_pads.gltf",
113
+ material: {
114
+ params: {
115
+ map: "textures/yellow.jpg"
116
+ }
117
+ }
118
+ }, {
119
+ src: "models/3d/Sofa/cylinders.gltf",
120
+ material: {
121
+ params: {
122
+ map: "textures/green.jpg"
123
+ }
124
+ }
125
+ }, {
126
+ src: "models/3d/Sofa/pillows.gltf",
127
+ material: {
128
+ params: {
129
+ map: "textures/blue.jpg"
130
+ }
131
+ }
132
+ }]
133
+ }
134
+ }
135
+ },
136
+ Designed: {
137
+ designAreaList: [{
138
+ identifier: "top",
139
+ baseShape: {
140
+ type: "Plane"
141
+ },
142
+ position: {
143
+ width: 580,
144
+ height: 290,
145
+ x: 1010,
146
+ y: 1500,
147
+ angle: -Math.PI / 2
148
+ },
149
+ height: 300,
150
+ width: 600,
151
+ designView: {
152
+ identifier: "top_view"
153
+ }
154
+ }],
155
+ configuration: {
156
+ visualizationData: {
157
+ sceneData: [{
158
+ src: "models/3d/GroundVehicle/SceneBase.gltf"
159
+ }, {
160
+ src: "models/3d/GroundVehicle/Body.gltf"
161
+ }, {
162
+ src: "models/3d/GroundVehicle/WheelsFront.gltf",
163
+ material: {
164
+ params: {
165
+ map: "FunnyWheel.jpg"
166
+ }
167
+ }
168
+ }, {
169
+ src: "models/3d/GroundVehicle/WheelsMid.gltf",
170
+ material: {
171
+ params: {
172
+ map: "FunnyWheel.jpg",
173
+ color: "#FF00FF"
174
+ }
175
+ }
176
+ }, {
177
+ src: "models/3d/GroundVehicle/WheelsRear.gltf",
178
+ material: {
179
+ params: {
180
+ map: "FunnyWheel.jpg",
181
+ color: "#00FF00"
182
+ }
183
+ }
184
+ }]
185
+ }
186
+ }
187
+ },
188
+ CreatorDesigner: {
189
+ designAreaList: [{
190
+ identifier: "top",
191
+ baseShape: {
192
+ type: "Plane"
193
+ },
194
+ position: {
195
+ width: 800,
196
+ height: 400,
197
+ x: 410,
198
+ y: 1500,
199
+ angle: -Math.PI / 2
200
+ },
201
+ height: 400,
202
+ width: 800,
203
+ designView: {
204
+ identifier: "top_view"
205
+ }
206
+ }],
207
+ configuration: {
208
+ visualizationData: {
209
+ sceneData: [{
210
+ src: "models/3d/Pouf/camera2.gltf"
211
+ }, {
212
+ src: "models/3d/Pouf/top.gltf",
213
+ material: {
214
+ params: {
215
+ color: "#BBBBBB",
216
+ metalness: 0.6,
217
+ roughness: 0.8
218
+ }
219
+ }
220
+ }, {
221
+ src: "models/3d/Pouf/bottom.gltf",
222
+ material: {
223
+ params: {
224
+ color: "#202020",
225
+ metalness: 0.6,
226
+ roughness: 0.8
227
+ }
228
+ }
229
+ }]
230
+ }
231
+ }
232
+ },
233
+ Animated: {
234
+ designAreaList: [],
235
+ configuration: {
236
+ visualizationData: {
237
+ sceneData: [{
238
+ src: "models/3d/Soldier.glb"
239
+ }]
240
+ }
241
+ }
242
+ },
243
+ Large: {
244
+ designAreaList: [],
245
+ configuration: {
246
+ visualizationData: {
247
+ sceneData: [{
248
+ src: "models/3d/LittlestTokyo.glb"
249
+ }]
250
+ }
251
+ }
252
+ },
253
+ FlexibleOptionsLocalParams: {
254
+ designAreaList: [],
255
+ configuration: {
256
+ visualizationData: {
257
+ sceneData: [{
258
+ src: "models/3d/GroundVehicle/SceneBase.gltf"
259
+ }, {
260
+ src: "models/3d/GroundVehicle/WheelsFront.gltf",
261
+ params: {
262
+ material: {
263
+ params: {
264
+ map: "FunnyWheel.jpg"
265
+ }
266
+ }
267
+ }
268
+ }, {
269
+ src: "models/3d/GroundVehicle/WheelsFront.gltf",
270
+ params: {
271
+ material: {
272
+ params: {
273
+ map: "FunnyWheel.jpg",
274
+ color: "#FF00FF"
275
+ }
276
+ },
277
+ position: {
278
+ z: -3
279
+ }
280
+ }
281
+ }, {
282
+ src: "models/3d/GroundVehicle/WheelsFront.gltf",
283
+ params: {
284
+ material: {
285
+ params: {
286
+ map: "FunnyWheel.jpg",
287
+ color: "#00FF00"
288
+ }
289
+ },
290
+ position: {
291
+ z: 3
292
+ }
293
+ }
294
+ }]
295
+ }
296
+ }
297
+ },
298
+ FlexibleOptionsGlobalParams: {
299
+ designAreaList: [],
300
+ configuration: {
301
+ visualizationData: {
302
+ sceneData: [{
303
+ src: "models/3d/GroundVehicle/SceneBase.gltf"
304
+ }, {
305
+ src: "models/3d/GroundVehicle/Body.gltf"
306
+ }, {
307
+ model: "models/3d/GroundVehicle/WheelsFront.gltf",
308
+ params: {
309
+ position: {
310
+ z: 0
311
+ }
312
+ }
313
+ }, {
314
+ model: "models/3d/GroundVehicle/WheelsFront.gltf",
315
+ params: {
316
+ position: {
317
+ z: -3.75
318
+ }
319
+ }
320
+ }, {
321
+ model: "models/3d/GroundVehicle/WheelsFront.gltf",
322
+ params: {
323
+ position: {
324
+ z: -5.05
325
+ }
326
+ }
327
+ }, {
328
+ params: {
329
+ objectName: "Wheels",
330
+ material: {
331
+ params: {
332
+ map: "FunnyWheel.jpg",
333
+ color: "#FF00FF"
334
+ }
335
+ }
336
+ },
337
+ files: {
338
+ "FunnyWheel.jpg": "models/3d/GroundVehicle/FunnyWheel.jpg"
339
+ }
340
+ }, {
341
+ params: {
342
+ objectName: "GroundVehicleMesh_0",
343
+ material: {
344
+ params: {
345
+ color: "#00FFFF"
346
+ }
347
+ }
348
+ }
349
+ }, {
350
+ params: {
351
+ material: {
352
+ params: {
353
+ materialName: "CustomizableMaterial",
354
+ color: "#FFFF00"
355
+ }
356
+ }
357
+ }
358
+ }]
359
+ }
360
+ }
361
+ }
362
+ }
363
+ };
364
+
365
+ var getDemoData = function getDemoData(mode, model) {
366
+ var demoData = {
367
+ "2dVariant": {
368
+ itemPath: "softshell",
369
+ materialPath: "softshell_red_s",
370
+ view: _designAreaList2DVariant["default"][0].designView,
371
+ designAreaList: _designAreaList2DVariant["default"]
372
+ },
373
+ "2dLayer": {
374
+ designAreaList: _designAreaList2D["default"],
375
+ configuration: {
376
+ visualizationData: {
377
+ viewImages: {
378
+ front_view: ["models/2d/front_view/softshell_avocado.png", "models/2d/front_view/hood_anthracite.png", "models/2d/front_view/zipper_avocado.png", "models/2d/front_view/applications_green.png"],
379
+ rear_view: ["models/2d/rear_view/softshell_avocado.png", "models/2d/rear_view/hood_anthracite.png", "models/2d/rear_view/applications_green.png"]
380
+ }
381
+ }
382
+ },
383
+ view: _designAreaList2D["default"][0].designView
384
+ },
385
+ "3dScene": _objectSpread({}, modelData["3dScene"][model]),
386
+ "3dVariant": {
387
+ materialPath: "base",
388
+ view: "default",
389
+ designAreaList: _designAreaList3DVariant["default"]
390
+ }
391
+ };
392
+ return demoData[mode];
393
+ };
394
+
395
+ var loadDemoModel = /*#__PURE__*/function () {
396
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(visualization, mode, model) {
397
+ var _getDemoData, configuration, view, designAreaList, itemPath, materialPath;
398
+
399
+ return regeneratorRuntime.wrap(function _callee$(_context) {
400
+ while (1) {
401
+ switch (_context.prev = _context.next) {
402
+ case 0:
403
+ _getDemoData = getDemoData(mode, model), configuration = _getDemoData.configuration, view = _getDemoData.view, designAreaList = _getDemoData.designAreaList, itemPath = _getDemoData.itemPath, materialPath = _getDemoData.materialPath;
404
+ _context.t0 = visualization.update && configuration;
405
+
406
+ if (!_context.t0) {
407
+ _context.next = 5;
408
+ break;
409
+ }
410
+
411
+ _context.next = 5;
412
+ return visualization.update(configuration);
413
+
414
+ case 5:
415
+ _context.t1 = itemPath;
416
+
417
+ if (!_context.t1) {
418
+ _context.next = 9;
419
+ break;
420
+ }
421
+
422
+ _context.next = 9;
423
+ return visualization.updateItemPath(itemPath);
424
+
425
+ case 9:
426
+ _context.t2 = materialPath;
427
+
428
+ if (!_context.t2) {
429
+ _context.next = 13;
430
+ break;
431
+ }
432
+
433
+ _context.next = 13;
434
+ return visualization.updateMaterialVariantPath(materialPath);
435
+
436
+ case 13:
437
+ _context.t3 = designAreaList;
438
+
439
+ if (!_context.t3) {
440
+ _context.next = 17;
441
+ break;
442
+ }
443
+
444
+ _context.next = 17;
445
+ return visualization.updateDesignAreaList(designAreaList);
446
+
447
+ case 17:
448
+ _context.t4 = view;
449
+
450
+ if (!_context.t4) {
451
+ _context.next = 26;
452
+ break;
453
+ }
454
+
455
+ if (!visualization.setView) {
456
+ _context.next = 24;
457
+ break;
458
+ }
459
+
460
+ _context.next = 22;
461
+ return visualization.setView(view);
462
+
463
+ case 22:
464
+ _context.next = 26;
465
+ break;
466
+
467
+ case 24:
468
+ _context.next = 26;
469
+ return visualization.jumpToView(view);
470
+
471
+ case 26:
472
+ case "end":
473
+ return _context.stop();
474
+ }
475
+ }
476
+ }, _callee);
477
+ }));
478
+
479
+ return function loadDemoModel(_x, _x2, _x3) {
480
+ return _ref.apply(this, arguments);
481
+ };
482
+ }();
483
+
484
+ function strokeStar(ctx, x, y, r, n, inset) {
485
+ ctx.save();
486
+ ctx.beginPath();
487
+ ctx.translate(x, y);
488
+ ctx.moveTo(0, 0 - r);
489
+
490
+ for (var i = 0; i < n; i++) {
491
+ ctx.rotate(Math.PI / n);
492
+ ctx.lineTo(0, 0 - r * inset);
493
+ ctx.rotate(Math.PI / n);
494
+ ctx.lineTo(0, 0 - r);
495
+ }
496
+
497
+ ctx.closePath();
498
+ ctx.fill();
499
+ ctx.restore();
500
+ }
501
+
502
+ function drawImage(ctx, scaling, effect) {
503
+ ctx.save();
504
+ ctx.scale(scaling, scaling);
505
+ ctx.fillStyle = effect === "color_embossing" ? "white" : "black";
506
+ ctx.font = "70px Arial";
507
+ ctx.fillText("Hello World", 20, 80);
508
+ strokeStar(ctx, 100, 20, 5, 5, 2);
509
+ ctx.restore();
510
+ }
511
+
512
+ var drawToTexture = function drawToTexture(effect, designAreaList) {
513
+ return /*#__PURE__*/function () {
514
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(textureCtx, getTextureBuilder) {
515
+ var designAreas,
516
+ _getTextureBuilder,
517
+ drawCanvasToArea,
518
+ highlightDesignAreas,
519
+ drawOn,
520
+ _iterator,
521
+ _step,
522
+ _loop,
523
+ _args3 = arguments;
524
+
525
+ return regeneratorRuntime.wrap(function _callee2$(_context3) {
526
+ while (1) {
527
+ switch (_context3.prev = _context3.next) {
528
+ case 0:
529
+ designAreas = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : designAreaList;
530
+ _getTextureBuilder = getTextureBuilder(textureBuilderConfig), drawCanvasToArea = _getTextureBuilder.drawCanvasToArea, highlightDesignAreas = _getTextureBuilder.highlightDesignAreas, drawOn = _getTextureBuilder.drawOn;
531
+ highlightDesignAreas(designAreas);
532
+ _iterator = _createForOfIteratorHelper(designAreas);
533
+ _context3.prev = 4;
534
+ _loop = /*#__PURE__*/regeneratorRuntime.mark(function _loop() {
535
+ var designArea;
536
+ return regeneratorRuntime.wrap(function _loop$(_context2) {
537
+ while (1) {
538
+ switch (_context2.prev = _context2.next) {
539
+ case 0:
540
+ designArea = _step.value;
541
+ _context2.next = 3;
542
+ return drawCanvasToArea({
543
+ drawToContext: function drawToContext(ctx, x, y, width) {
544
+ drawImage(ctx, width / designArea.position.width, effect);
545
+ },
546
+ designArea: designArea,
547
+ effect: effect,
548
+ effectOptions: effectOptions[effect],
549
+ getSvg: _exportedSampleSvg.getExportedSampleSvg
550
+ });
551
+
552
+ case 3:
553
+ case "end":
554
+ return _context2.stop();
555
+ }
556
+ }
557
+ }, _loop);
558
+ });
559
+
560
+ _iterator.s();
561
+
562
+ case 7:
563
+ if ((_step = _iterator.n()).done) {
564
+ _context3.next = 11;
565
+ break;
566
+ }
567
+
568
+ return _context3.delegateYield(_loop(), "t0", 9);
569
+
570
+ case 9:
571
+ _context3.next = 7;
572
+ break;
573
+
574
+ case 11:
575
+ _context3.next = 16;
576
+ break;
577
+
578
+ case 13:
579
+ _context3.prev = 13;
580
+ _context3.t1 = _context3["catch"](4);
581
+
582
+ _iterator.e(_context3.t1);
583
+
584
+ case 16:
585
+ _context3.prev = 16;
586
+
587
+ _iterator.f();
588
+
589
+ return _context3.finish(16);
590
+
591
+ case 19:
592
+ drawOn(textureCtx);
593
+
594
+ case 20:
595
+ case "end":
596
+ return _context3.stop();
597
+ }
598
+ }
599
+ }, _callee2, null, [[4, 13, 16, 19]]);
600
+ }));
601
+
602
+ return function (_x4, _x5) {
603
+ return _ref2.apply(this, arguments);
604
+ };
605
+ }();
606
+ };
607
+
608
+ var addTexture = function addTexture(visualization, mode, model, effect) {
609
+ visualization.getDrawingContext(drawToTexture(effect, getDemoData(mode, model).designAreaList), true
610
+ /* update alpha */
611
+ , true
612
+ /* clean up texture before drawing */
613
+ );
614
+ };
615
+
616
+ var expose = function expose(name, value) {
617
+ return window[name] = value;
618
+ };
619
+
620
+ var AlignTestComponent = (0, _AlignTargetProvider.withAlignTarget)(function (props) {
621
+ var ref = /*#__PURE__*/_react["default"].createRef();
622
+
623
+ (0, _react.useEffect)(function () {
624
+ props.alignTarget.add(ref.current);
625
+ return function () {
626
+ return props.alignTarget.remove(ref.current);
627
+ };
628
+ }, []);
629
+ return /*#__PURE__*/_react["default"].createElement("div", {
630
+ ref: ref,
631
+ style: {
632
+ position: "fixed",
633
+ top: "50%",
634
+ left: "40%",
635
+ transform: "translate(-50%,-50%)",
636
+ width: 300,
637
+ height: 150,
638
+ background: "yellow",
639
+ zIndex: 999,
640
+ opacity: 0.5,
641
+ padding: 50,
642
+ boxSizing: "border-box",
643
+ textAlign: "center"
644
+ }
645
+ }, typeof props.children === "function" ? props.children({
646
+ elementRef: ref
647
+ }) : props.children);
648
+ });
649
+
650
+ var MovementRestrictButton = function MovementRestrictButton(_ref3) {
651
+ var visualization = _ref3.visualization;
652
+
653
+ var _useState = (0, _react.useState)(false),
654
+ _useState2 = _slicedToArray(_useState, 2),
655
+ isMovementRestricted = _useState2[0],
656
+ restrictMovement = _useState2[1];
657
+
658
+ return /*#__PURE__*/_react["default"].createElement("div", {
659
+ className: "feature"
660
+ }, /*#__PURE__*/_react["default"].createElement("button", {
661
+ onClick: function onClick() {
662
+ if (isMovementRestricted) {
663
+ visualization.freeUserMovement();
664
+ restrictMovement(false);
665
+ } else {
666
+ visualization.restrictUserMovement();
667
+ restrictMovement(true);
668
+ }
669
+ }
670
+ }, isMovementRestricted ? "Release movement restriction" : "Restrict movement"));
671
+ };
672
+
673
+ var ViewSwitchOptions = function ViewSwitchOptions(_ref4) {
674
+ var visualization = _ref4.visualization,
675
+ mode = _ref4.mode;
676
+
677
+ var _useState3 = (0, _react.useState)(getDemoData(mode).view),
678
+ _useState4 = _slicedToArray(_useState3, 2),
679
+ designView = _useState4[0],
680
+ setDesignView = _useState4[1];
681
+
682
+ var _useState5 = (0, _react.useState)(""),
683
+ _useState6 = _slicedToArray(_useState5, 2),
684
+ designArea = _useState6[0],
685
+ setDesignArea = _useState6[1];
686
+
687
+ (0, _react.useEffect)(function () {
688
+ visualization.setView && visualization.setView(designView);
689
+ setDesignArea("");
690
+ }, [designView]);
691
+ (0, _react.useEffect)(function () {
692
+ designArea && visualization.jumpToArea(designArea);
693
+ }, [designArea]);
694
+ var designAreaList = getDemoData(mode).designAreaList;
695
+ return /*#__PURE__*/_react["default"].createElement("div", {
696
+ className: "feature"
697
+ }, /*#__PURE__*/_react["default"].createElement("div", {
698
+ className: "feature"
699
+ }, /*#__PURE__*/_react["default"].createElement("label", null, "Switch design views:"), designAreaList.map(function (_ref5) {
700
+ var designView = _ref5.designView;
701
+ return /*#__PURE__*/_react["default"].createElement("button", {
702
+ key: designView.identifier,
703
+ value: designView.identifier,
704
+ onClick: function onClick() {
705
+ return setDesignView(designView);
706
+ }
707
+ }, designView.identifier);
708
+ })), /*#__PURE__*/_react["default"].createElement("div", {
709
+ className: "feature"
710
+ }, /*#__PURE__*/_react["default"].createElement("label", null, "Switch design areas:"), designAreaList.filter(function (_ref6) {
711
+ var identifier = _ref6.designView.identifier;
712
+ return identifier === designView.identifier;
713
+ }).map(function (_ref7) {
714
+ var identifier = _ref7.identifier;
715
+ return /*#__PURE__*/_react["default"].createElement("button", {
716
+ key: identifier,
717
+ value: identifier,
718
+ onClick: function onClick(_ref8) {
719
+ var value = _ref8.target.value;
720
+ return setDesignArea(value);
721
+ }
722
+ }, identifier);
723
+ })));
724
+ };
725
+
726
+ var CameraViews = function CameraViews(_ref9) {
727
+ var visualization = _ref9.visualization,
728
+ cameras = _ref9.cameras;
729
+ (0, _react.useEffect)(function () {
730
+ visualization && visualization.jumpToView && visualization.jumpToView("default");
731
+ }, [cameras]);
732
+ if (!visualization || !cameras || !cameras.length) return null;
733
+ return /*#__PURE__*/_react["default"].createElement("div", {
734
+ className: "feature"
735
+ }, /*#__PURE__*/_react["default"].createElement("select", {
736
+ onChange: function onChange(_ref10) {
737
+ var value = _ref10.target.value;
738
+ return visualization.jumpToView(value);
739
+ }
740
+ }, /*#__PURE__*/_react["default"].createElement("option", null, "Select view"), cameras.map(function (name) {
741
+ return /*#__PURE__*/_react["default"].createElement("option", {
742
+ key: name,
743
+ value: name
744
+ }, name);
745
+ })));
746
+ };
747
+
748
+ var Animations = function Animations(_ref11) {
749
+ var visualization = _ref11.visualization,
750
+ animations = _ref11.animations;
751
+ if (!visualization || !animations || !animations.length) return null;
752
+ return /*#__PURE__*/_react["default"].createElement("div", {
753
+ className: "feature"
754
+ }, /*#__PURE__*/_react["default"].createElement("select", {
755
+ onChange: function onChange(_ref12) {
756
+ var value = _ref12.target.value;
757
+ return visualization.setActiveAnimation(value);
758
+ }
759
+ }, /*#__PURE__*/_react["default"].createElement("option", null, "Select animation"), animations.map(function (name) {
760
+ return /*#__PURE__*/_react["default"].createElement("option", {
761
+ key: name,
762
+ value: name
763
+ }, name);
764
+ })));
765
+ };
766
+
767
+ var ColorVariants = function ColorVariants(_ref13) {
768
+ var visualization = _ref13.visualization,
769
+ variants = _ref13.variants;
770
+ if (!visualization) return null;
771
+ return /*#__PURE__*/_react["default"].createElement("div", {
772
+ className: "feature"
773
+ }, /*#__PURE__*/_react["default"].createElement("select", {
774
+ onChange: function onChange(_ref14) {
775
+ var value = _ref14.target.value;
776
+ return visualization.updateMaterialVariantPath(value);
777
+ }
778
+ }, /*#__PURE__*/_react["default"].createElement("option", null, "Select variant"), variants.map(function (name) {
779
+ return /*#__PURE__*/_react["default"].createElement("option", {
780
+ key: name,
781
+ value: name
782
+ }, name);
783
+ })));
784
+ };
785
+
786
+ var FeatureAvailability = function FeatureAvailability(_ref15) {
787
+ var availableFor = _ref15.availableFor,
788
+ mode = _ref15.mode,
789
+ children = _ref15.children;
790
+
791
+ if (-1 !== availableFor.indexOf(mode)) {
792
+ return children;
793
+ }
794
+
795
+ return null;
796
+ };
797
+
798
+ var useStyles = (0, _makeStyles["default"])({
799
+ container: {
800
+ position: "absolute",
801
+ top: 0,
802
+ right: 0,
803
+ zIndex: 999,
804
+ padding: 8,
805
+ background: "rgba(255,255,255,0.5)",
806
+ fontFamily: "system-ui",
807
+ width: 500,
808
+ "& button, & select, & [type='checkbox']": {
809
+ fontFamily: "system-ui",
810
+ border: "1px solid",
811
+ borderColor: "rgb(106,101,80)",
812
+ background: "rgb(200,190,151)",
813
+ borderRadius: 3,
814
+ marginRight: 8,
815
+ fontSize: "1em"
816
+ },
817
+ "& label": {
818
+ marginRight: 8
819
+ },
820
+ "& .feature": {
821
+ marginTop: 8
822
+ }
823
+ },
824
+ features: {
825
+ fontWeight: "bold",
826
+ fontStyle: "italic"
827
+ }
828
+ });
829
+
830
+ var App = function App() {
831
+ var _useState7 = (0, _react.useState)("3dScene"),
832
+ _useState8 = _slicedToArray(_useState7, 2),
833
+ mode = _useState8[0],
834
+ setMode = _useState8[1];
835
+
836
+ var _useState9 = (0, _react.useState)(""),
837
+ _useState10 = _slicedToArray(_useState9, 2),
838
+ model = _useState10[0],
839
+ setModel = _useState10[1];
840
+
841
+ var _useState11 = (0, _react.useState)(),
842
+ _useState12 = _slicedToArray(_useState11, 2),
843
+ visualization = _useState12[0],
844
+ setVisualization = _useState12[1];
845
+
846
+ var _useState13 = (0, _react.useState)(false),
847
+ _useState14 = _slicedToArray(_useState13, 2),
848
+ showAlignTestComponent = _useState14[0],
849
+ setShowAlignTestComponent = _useState14[1];
850
+
851
+ var _useState15 = (0, _react.useState)(""),
852
+ _useState16 = _slicedToArray(_useState15, 2),
853
+ effect = _useState16[0],
854
+ setEffect = _useState16[1];
855
+
856
+ var _useState17 = (0, _react.useState)({}),
857
+ _useState18 = _slicedToArray(_useState17, 2),
858
+ features = _useState18[0],
859
+ setFeatures = _useState18[1];
860
+
861
+ (0, _react.useEffect)(function () {
862
+ visualization && visualization.dispose();
863
+ var mappedMode = {
864
+ "3dVariant": "3dScene" // the variant mode is deprecated, the demo is made with the 3dScene
865
+
866
+ }[mode] || mode;
867
+
868
+ var _visualization = (0, _visualizationAdapterCreator.createVisualizationAdapter)(adapterConfig, mappedMode);
869
+
870
+ setVisualization(_visualization);
871
+ setEffect("");
872
+ setModel("");
873
+ }, [mode]);
874
+ (0, _react.useEffect)(function () {
875
+ var drawFn = function drawFn() {
876
+ visualization.getDrawingContext(drawToTexture("print", getDemoData(mode, model).designAreaList), true
877
+ /* update alpha */
878
+ , true
879
+ /* clean up texture before drawing */
880
+ );
881
+ };
882
+
883
+ visualization && visualization.observable.on(_Constants.EventTypes.MaterialUpdated, drawFn);
884
+ return function () {
885
+ visualization && visualization.observable.off(_Constants.EventTypes.MaterialUpdated, drawFn);
886
+ };
887
+ }, [visualization, mode, model]); // highlight intersected (clicked) object
888
+
889
+ (0, _react.useEffect)(function () {
890
+ if (visualization) {
891
+ var restoreColor;
892
+ var to;
893
+ visualization.observable.on(_Constants.EventTypes.Intersection, function (v) {
894
+ // eslint-disable-next-line no-console
895
+ console.log("Intersection", v);
896
+ var mat = v.data.target.object.material;
897
+ window.clearTimeout(to);
898
+ restoreColor && restoreColor();
899
+ var col = mat.color;
900
+ mat.color = new _three.Color(1, 0.5, 0.5);
901
+ mat.updateNeeded = true;
902
+ visualization.render();
903
+
904
+ restoreColor = function restoreColor() {
905
+ mat.color = col;
906
+ mat.updateNeeded = true;
907
+ visualization.render();
908
+ };
909
+
910
+ to = window.setTimeout(restoreColor, 500);
911
+ });
912
+ }
913
+ }, [visualization]);
914
+ expose("visualization", visualization);
915
+ var classes = useStyles();
916
+ var modelList = modelData[mode] && Object.keys(modelData[mode]);
917
+ var designAreaList = getDemoData(mode, model).designAreaList;
918
+ return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
919
+ className: classes.container
920
+ }, /*#__PURE__*/_react["default"].createElement("select", {
921
+ onChange: function onChange(_ref16) {
922
+ var value = _ref16.target.value;
923
+ return setMode(value);
924
+ }
925
+ }, /*#__PURE__*/_react["default"].createElement("option", {
926
+ value: "3dScene"
927
+ }, "3D scene"), /*#__PURE__*/_react["default"].createElement("option", {
928
+ value: "3dVariant"
929
+ }, "3D variant"), /*#__PURE__*/_react["default"].createElement("option", {
930
+ value: "2dLayer"
931
+ }, "2D layer"), /*#__PURE__*/_react["default"].createElement("option", {
932
+ value: "2dVariant"
933
+ }, "2D variant")), modelList && /*#__PURE__*/_react["default"].createElement("select", {
934
+ value: model,
935
+ onChange: function onChange(_ref17) {
936
+ var value = _ref17.target.value;
937
+ return setModel(value);
938
+ }
939
+ }, /*#__PURE__*/_react["default"].createElement("option", null, "Select model"), modelList.map(function (model) {
940
+ return /*#__PURE__*/_react["default"].createElement("option", {
941
+ value: model,
942
+ key: model
943
+ }, model);
944
+ })), (!modelList || model) && /*#__PURE__*/_react["default"].createElement("button", {
945
+ onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
946
+ var foundFeatures;
947
+ return regeneratorRuntime.wrap(function _callee3$(_context4) {
948
+ while (1) {
949
+ switch (_context4.prev = _context4.next) {
950
+ case 0:
951
+ _context4.next = 2;
952
+ return loadDemoModel(visualization, mode, model);
953
+
954
+ case 2:
955
+ foundFeatures = {};
956
+
957
+ if (visualization.getCameras) {
958
+ foundFeatures.cameras = visualization.getCameras().map(function (_ref19) {
959
+ var name = _ref19.name;
960
+ return name;
961
+ });
962
+ }
963
+
964
+ if (visualization.getAnimations) {
965
+ foundFeatures.animations = visualization.getAnimations().map(function (_ref20) {
966
+ var name = _ref20.name;
967
+ return name;
968
+ });
969
+ }
970
+
971
+ setFeatures(foundFeatures);
972
+
973
+ case 6:
974
+ case "end":
975
+ return _context4.stop();
976
+ }
977
+ }
978
+ }, _callee3);
979
+ }))
980
+ }, "Load demo model"), /*#__PURE__*/_react["default"].createElement("div", {
981
+ className: "feature"
982
+ }, /*#__PURE__*/_react["default"].createElement("label", null, "Use custom align target"), /*#__PURE__*/_react["default"].createElement("input", {
983
+ type: "checkbox",
984
+ onClick: function onClick(_ref21) {
985
+ var checked = _ref21.target.checked;
986
+ return setShowAlignTestComponent(checked);
987
+ }
988
+ })), designAreaList && designAreaList.length > 0 && /*#__PURE__*/_react["default"].createElement("div", {
989
+ className: "feature"
990
+ }, /*#__PURE__*/_react["default"].createElement("label", null, "Texture content effect:"), /*#__PURE__*/_react["default"].createElement("select", {
991
+ value: effect,
992
+ onChange: function onChange(_ref22) {
993
+ var value = _ref22.target.value;
994
+ setEffect(value);
995
+ addTexture(visualization, mode, model, value);
996
+ }
997
+ }, /*#__PURE__*/_react["default"].createElement("option", null, "No effect"), /*#__PURE__*/_react["default"].createElement("option", {
998
+ value: "embossing"
999
+ }, "embossing"), /*#__PURE__*/_react["default"].createElement("option", {
1000
+ value: "engraving"
1001
+ }, "engraving"), /*#__PURE__*/_react["default"].createElement("option", {
1002
+ value: "doming"
1003
+ }, "doming"), /*#__PURE__*/_react["default"].createElement("option", {
1004
+ value: "embroidery"
1005
+ }, "embroidery"), /*#__PURE__*/_react["default"].createElement("option", {
1006
+ value: "color_embossing"
1007
+ }, "color embossing"))), /*#__PURE__*/_react["default"].createElement("div", {
1008
+ className: "feature"
1009
+ }, /*#__PURE__*/_react["default"].createElement("label", {
1010
+ className: classes.features
1011
+ }, "Features:"), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(FeatureAvailability, {
1012
+ availableFor: ["3dScene", "3dVariant"],
1013
+ mode: mode
1014
+ }, /*#__PURE__*/_react["default"].createElement(MovementRestrictButton, {
1015
+ visualization: visualization
1016
+ })), /*#__PURE__*/_react["default"].createElement(FeatureAvailability, {
1017
+ availableFor: ["3dScene", "3dVariant"],
1018
+ mode: mode
1019
+ }, /*#__PURE__*/_react["default"].createElement(CameraViews, {
1020
+ visualization: visualization,
1021
+ cameras: features.cameras
1022
+ })), /*#__PURE__*/_react["default"].createElement(FeatureAvailability, {
1023
+ availableFor: ["3dScene", "3dVariant"],
1024
+ mode: mode
1025
+ }, /*#__PURE__*/_react["default"].createElement(Animations, {
1026
+ visualization: visualization,
1027
+ animations: features.animations
1028
+ })), /*#__PURE__*/_react["default"].createElement(FeatureAvailability, {
1029
+ availableFor: ["2dLayer", "2dVariant"],
1030
+ mode: mode
1031
+ }, /*#__PURE__*/_react["default"].createElement(ViewSwitchOptions, {
1032
+ visualization: visualization,
1033
+ mode: mode
1034
+ })), /*#__PURE__*/_react["default"].createElement(FeatureAvailability, {
1035
+ availableFor: ["3dVariant"],
1036
+ mode: mode
1037
+ }, /*#__PURE__*/_react["default"].createElement(ColorVariants, {
1038
+ visualization: visualization,
1039
+ variants: ["base", "red", "green", "metallic", "glass"]
1040
+ }))))), /*#__PURE__*/_react["default"].createElement(_VisualizationProvider.VisualizationProvider, {
1041
+ visualization: visualization
1042
+ }, /*#__PURE__*/_react["default"].createElement(_AlignTargetProvider.AlignTargetProvider, null, showAlignTestComponent && /*#__PURE__*/_react["default"].createElement(AlignTestComponent, null, "The camera offset should be aligned to this component."), /*#__PURE__*/_react["default"].createElement(_VisualizationContainer["default"], {
1043
+ autoDispose: true
1044
+ }))));
1045
+ };
1046
+
1047
+ var _default = (0, _root.hot)(App);
1048
+
1049
+ exports["default"] = _default;