redhotmagma-visualization 1.54.2 → 1.55.0

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.
package/Three/Three2D.js CHANGED
@@ -705,7 +705,7 @@ export var Three2D = /*#__PURE__*/function (_ThreeBase) {
705
705
  value: function getModelPath() {
706
706
  var _this6 = this;
707
707
  if (this._modelPath) {
708
- return [this._modelBasePath, this._modelPath].join("/");
708
+ return this._modelPath.startsWith("http") ? this._modelPath : "".concat(this._modelBasePath, "/").concat(this._modelPath);
709
709
  }
710
710
  var pathChunks = ["_basePath", "_itemPath", "_viewPath", "_materialVariantPath"];
711
711
  var parts = pathChunks.map(function (pathName) {
@@ -198,7 +198,7 @@ export var Three2DLayers = /*#__PURE__*/function (_Three2D) {
198
198
  value: function getModelPath() {
199
199
  var _this3 = this;
200
200
  return this._modelPathList.map(function (path) {
201
- return _this3._modelBasePath + path;
201
+ return path.startsWith("http") ? path : "".concat(_this3._modelBasePath, "/").concat(path.replace(/^\//, ""));
202
202
  });
203
203
  }
204
204
  }, {
@@ -1,3 +1,6 @@
1
+ var _excluded = ["modelFileName"];
2
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
3
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
1
4
  function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
2
5
  function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
3
6
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
@@ -876,12 +879,8 @@ export var Three3DScene = /*#__PURE__*/function (_Three3D) {
876
879
  path = getSrc(item);
877
880
  }
878
881
  var _this$parseModelPath = this.parseModelPath(path),
879
- resourcePath = _this$parseModelPath.resourcePath,
880
- modelFileName = _this$parseModelPath.modelFileName;
881
- var loaderOptions = {
882
- basePath: this._modelBasePath,
883
- resourcePath: resourcePath
884
- };
882
+ modelFileName = _this$parseModelPath.modelFileName,
883
+ loaderOptions = _objectWithoutProperties(_this$parseModelPath, _excluded);
885
884
  var modelLoader = this.createLoader(loaderOptions);
886
885
  var imageLoader = this.createImageLoader(loaderOptions);
887
886
  return new Promise(function (resolve, reject) {
@@ -978,9 +977,11 @@ export var Three3DScene = /*#__PURE__*/function (_Three3D) {
978
977
  if (!matches.length) {
979
978
  throw new Error("Model path cannot be parsed: " + path);
980
979
  }
981
- var resourcePath = "/" + matches[1];
980
+ var resourcePath = matches[1].startsWith("http") ? matches[1] : "/".concat(matches[1]);
982
981
  var modelFileName = matches[2];
982
+ var basePath = resourcePath.startsWith("http") ? "" : this._modelBasePath;
983
983
  return {
984
+ basePath: basePath,
984
985
  resourcePath: resourcePath,
985
986
  modelFileName: modelFileName
986
987
  };
@@ -1118,12 +1119,7 @@ export var Three3DScene = /*#__PURE__*/function (_Three3D) {
1118
1119
  return userData.path === itemSrc && userData.index === item.index;
1119
1120
  });
1120
1121
  var path = getSrc(item);
1121
- var _this8$parseModelPath = _this8.parseModelPath(path),
1122
- resourcePath = _this8$parseModelPath.resourcePath;
1123
- var loaderOptions = {
1124
- basePath: _this8._modelBasePath,
1125
- resourcePath: resourcePath
1126
- };
1122
+ var loaderOptions = _this8.parseModelPath(path);
1127
1123
  var imageLoader = _this8.createImageLoader(loaderOptions);
1128
1124
  return object && _this8.applyCustomizations(object, item, imageLoader);
1129
1125
  }));
@@ -110,26 +110,86 @@ export var createTextureBuilder = function createTextureBuilder(textureImage) {
110
110
  return _ref2.apply(this, arguments);
111
111
  };
112
112
  }();
113
+ var drawCanvasToAreaDirect = /*#__PURE__*/function () {
114
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref3) {
115
+ var drawToContext, designArea, baseShape, position, type, _calculateDesignAreaS2, width, height, _scaling2, _t3, _t4;
116
+ return _regenerator().w(function (_context2) {
117
+ while (1) switch (_context2.p = _context2.n) {
118
+ case 0:
119
+ drawToContext = _ref3.drawToContext, designArea = _ref3.designArea;
120
+ baseShape = designArea.baseShape, position = designArea.position;
121
+ if (!(!baseShape || !position)) {
122
+ _context2.n = 1;
123
+ break;
124
+ }
125
+ // eslint-disable-next-line no-console
126
+ console.log("No design area provided.");
127
+ return _context2.a(2);
128
+ case 1:
129
+ type = baseShape.type;
130
+ _t3 = type;
131
+ _context2.n = _t3 === "Plane" ? 2 : _t3 === "Cylinder" ? 2 : 8;
132
+ break;
133
+ case 2:
134
+ _calculateDesignAreaS2 = calculateDesignAreaSize(designArea), width = _calculateDesignAreaS2.width, height = _calculateDesignAreaS2.height, _scaling2 = _calculateDesignAreaS2.scaling;
135
+ ctx.save();
136
+ transformCanvas(ctx, getTransformProps(baseShape, position), _scaling2);
137
+ _context2.p = 3;
138
+ _context2.n = 4;
139
+ return drawToContext(ctx, 0, 0, width, height, {
140
+ currentZoom: currentZoom
141
+ });
142
+ case 4:
143
+ _context2.n = 6;
144
+ break;
145
+ case 5:
146
+ _context2.p = 5;
147
+ _t4 = _context2.v;
148
+ // eslint-disable-next-line no-console
149
+ console.error("Transfering design to the visualization failed due to the following error.", _t4);
150
+ return _context2.a(2);
151
+ case 6:
152
+ _context2.p = 6;
153
+ ctx.restore();
154
+ return _context2.f(6);
155
+ case 7:
156
+ return _context2.a(3, 9);
157
+ case 8:
158
+ // eslint-disable-next-line no-console
159
+ console.error("Unknown baseShape type: ".concat(type, ". Texture update will be skipped."));
160
+ return _context2.a(2);
161
+ case 9:
162
+ return _context2.a(2);
163
+ }
164
+ }, _callee2, null, [[3, 5, 6, 7]]);
165
+ }));
166
+ return function drawCanvasToAreaDirect(_x2) {
167
+ return _ref4.apply(this, arguments);
168
+ };
169
+ }();
113
170
  var highlightDesignAreas = function highlightDesignAreas(designAreas) {
114
- designAreas.forEach(function (designArea) {
115
- var baseShape = designArea.baseShape,
116
- position = designArea.position;
117
- if (!baseShape || !position) {
118
- return;
119
- }
120
- ctx.save();
121
- var _calculateDesignAreaS2 = calculateDesignAreaSize(designArea),
122
- scaling = _calculateDesignAreaS2.scaling,
123
- size = _objectWithoutProperties(_calculateDesignAreaS2, _excluded);
124
- transformCanvas(ctx, getTransformProps(baseShape, position), scaling);
125
- var highlight = configObject.highlight;
126
- var _highlight$lineWidth = highlight.lineWidth,
127
- lineWidth = _highlight$lineWidth === void 0 ? 2 : _highlight$lineWidth;
128
- highlightArea(ctx, size, _objectSpread(_objectSpread({}, highlight), {}, {
129
- lineWidth: Math.ceil(lineWidth / currentZoom)
130
- }));
131
- ctx.restore();
132
- });
171
+ designAreas.forEach(highlightDesignArea);
172
+ };
173
+ var highlightDesignArea = function highlightDesignArea(designArea) {
174
+ var baseShape = designArea.baseShape,
175
+ position = designArea.position;
176
+ if (!baseShape || !position) {
177
+ return;
178
+ }
179
+ ctx.save();
180
+ var _calculateDesignAreaS3 = calculateDesignAreaSize(designArea),
181
+ scaling = _calculateDesignAreaS3.scaling,
182
+ size = _objectWithoutProperties(_calculateDesignAreaS3, _excluded);
183
+ transformCanvas(ctx, getTransformProps(baseShape, position), scaling);
184
+ var highlight = configObject.highlight,
185
+ _configObject$highlig = configObject.highlightFunction,
186
+ highlightFunction = _configObject$highlig === void 0 ? highlightArea : _configObject$highlig;
187
+ var _highlight$lineWidth = highlight.lineWidth,
188
+ lineWidth = _highlight$lineWidth === void 0 ? 2 : _highlight$lineWidth;
189
+ highlightFunction(ctx, size, _objectSpread(_objectSpread({}, highlight), {}, {
190
+ lineWidth: Math.ceil(lineWidth / currentZoom)
191
+ }));
192
+ ctx.restore();
133
193
  };
134
194
  var drawOn = function drawOn(ctx) {
135
195
  ctx.drawImage(canvas, 0, 0);
@@ -142,6 +202,8 @@ export var createTextureBuilder = function createTextureBuilder(textureImage) {
142
202
  };
143
203
  return {
144
204
  drawCanvasToArea: drawCanvasToArea,
205
+ drawCanvasToAreaDirect: drawCanvasToAreaDirect,
206
+ highlightDesignArea: highlightDesignArea,
145
207
  highlightDesignAreas: highlightDesignAreas,
146
208
  drawOn: drawOn,
147
209
  getTextureImage: getTextureImage,
@@ -238,12 +300,12 @@ export var highlightArea = function highlightArea(ctx, size) {
238
300
  var lineWidthHalf = lineWidth / 2;
239
301
  ctx.strokeRect(lineWidthHalf, lineWidthHalf, width - lineWidth, height - lineWidth);
240
302
  };
241
- export var getPositionWithPadding = function getPositionWithPadding(_ref3, padding) {
242
- var x = _ref3.x,
243
- y = _ref3.y,
244
- width = _ref3.width,
245
- height = _ref3.height,
246
- otherProps = _objectWithoutProperties(_ref3, _excluded2);
303
+ export var getPositionWithPadding = function getPositionWithPadding(_ref5, padding) {
304
+ var x = _ref5.x,
305
+ y = _ref5.y,
306
+ width = _ref5.width,
307
+ height = _ref5.height,
308
+ otherProps = _objectWithoutProperties(_ref5, _excluded2);
247
309
  return _objectSpread(_objectSpread({}, otherProps), {}, {
248
310
  x: x - padding,
249
311
  y: y - padding,
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "redhotmagma-visualization",
3
- "version": "1.54.2",
3
+ "version": "1.55.0",
4
4
  "license": "UNLICENSED",
5
5
  "private": false,
6
6
  "main": "./index.js",
7
7
  "dependencies": {
8
8
  "@babel/polyfill": "^7.12.1",
9
- "@configuratorware/scripts": "1.54.2",
9
+ "@configuratorware/scripts": "1.55.0",
10
10
  "@tweenjs/tween.js": "^17.6.0",
11
11
  "console-polyfill": "^0.3.0",
12
12
  "css-element-queries": "^1.2.3",
@@ -457,7 +457,9 @@ export class Three2D extends ThreeBase {
457
457
 
458
458
  getModelPath() {
459
459
  if (this._modelPath) {
460
- return [this._modelBasePath, this._modelPath].join("/");
460
+ return this._modelPath.startsWith("http")
461
+ ? this._modelPath
462
+ : `${this._modelBasePath}/${this._modelPath}`;
461
463
  }
462
464
 
463
465
  const pathChunks = ["_basePath", "_itemPath", "_viewPath", "_materialVariantPath"];
@@ -97,7 +97,9 @@ export class Three2DLayers extends Three2D {
97
97
  }
98
98
 
99
99
  getModelPath() {
100
- return this._modelPathList.map(path => this._modelBasePath + path);
100
+ return this._modelPathList.map(path =>
101
+ path.startsWith("http") ? path : `${this._modelBasePath}/${path.replace(/^\//, "")}`
102
+ );
101
103
  }
102
104
 
103
105
  getModelPathFromDesignView(designView) {
@@ -729,12 +729,7 @@ export class Three3DScene extends Three3D {
729
729
  } else if ("object" === itemType) {
730
730
  path = getSrc(item);
731
731
  }
732
- const { resourcePath, modelFileName } = this.parseModelPath(path);
733
-
734
- const loaderOptions = {
735
- basePath: this._modelBasePath,
736
- resourcePath,
737
- };
732
+ const { modelFileName, ...loaderOptions } = this.parseModelPath(path);
738
733
 
739
734
  const modelLoader = this.createLoader(loaderOptions);
740
735
  const imageLoader = this.createImageLoader(loaderOptions);
@@ -792,9 +787,11 @@ export class Three3DScene extends Three3D {
792
787
  if (!matches.length) {
793
788
  throw new Error("Model path cannot be parsed: " + path);
794
789
  }
795
- const resourcePath = "/" + matches[1];
790
+ const resourcePath = matches[1].startsWith("http") ? matches[1] : `/${matches[1]}`;
796
791
  const modelFileName = matches[2];
792
+ const basePath = resourcePath.startsWith("http") ? "" : this._modelBasePath;
797
793
  return {
794
+ basePath,
798
795
  resourcePath,
799
796
  modelFileName,
800
797
  };
@@ -914,11 +911,7 @@ export class Three3DScene extends Three3D {
914
911
  );
915
912
 
916
913
  const path = getSrc(item);
917
- const { resourcePath } = this.parseModelPath(path);
918
- const loaderOptions = {
919
- basePath: this._modelBasePath,
920
- resourcePath,
921
- };
914
+ const loaderOptions = this.parseModelPath(path);
922
915
  const imageLoader = this.createImageLoader(loaderOptions);
923
916
 
924
917
  return object && this.applyCustomizations(object, item, imageLoader);
@@ -72,28 +72,69 @@ export const createTextureBuilder = (textureImage, params = {}) => {
72
72
  }
73
73
  };
74
74
 
75
- const highlightDesignAreas = designAreas => {
76
- designAreas.forEach(designArea => {
77
- const { baseShape, position } = designArea;
78
- if (!baseShape || !position) {
75
+ const drawCanvasToAreaDirect = async ({ drawToContext, designArea }) => {
76
+ const { baseShape, position } = designArea;
77
+ if (!baseShape || !position) {
78
+ // eslint-disable-next-line no-console
79
+ console.log("No design area provided.");
80
+ return;
81
+ }
82
+ const { type } = baseShape;
83
+ switch (type) {
84
+ case "Plane":
85
+ case "Cylinder": {
86
+ const { width, height, scaling } = calculateDesignAreaSize(designArea);
87
+ ctx.save();
88
+ transformCanvas(ctx, getTransformProps(baseShape, position), scaling);
89
+ try {
90
+ await drawToContext(ctx, 0, 0, width, height, {
91
+ currentZoom,
92
+ });
93
+ } catch (e) {
94
+ // eslint-disable-next-line no-console
95
+ console.error(
96
+ "Transfering design to the visualization failed due to the following error.",
97
+ e
98
+ );
99
+ return;
100
+ } finally {
101
+ ctx.restore();
102
+ }
103
+
104
+ break;
105
+ }
106
+ default: {
107
+ // eslint-disable-next-line no-console
108
+ console.error(`Unknown baseShape type: ${type}. Texture update will be skipped.`);
79
109
  return;
80
110
  }
81
- ctx.save();
111
+ }
112
+ };
113
+
114
+ const highlightDesignAreas = designAreas => {
115
+ designAreas.forEach(highlightDesignArea);
116
+ };
82
117
 
83
- const { scaling, ...size } = calculateDesignAreaSize(designArea);
118
+ const highlightDesignArea = designArea => {
119
+ const { baseShape, position } = designArea;
120
+ if (!baseShape || !position) {
121
+ return;
122
+ }
123
+ ctx.save();
84
124
 
85
- transformCanvas(ctx, getTransformProps(baseShape, position), scaling);
125
+ const { scaling, ...size } = calculateDesignAreaSize(designArea);
86
126
 
87
- const { highlight } = configObject;
88
- const { lineWidth = 2 } = highlight;
127
+ transformCanvas(ctx, getTransformProps(baseShape, position), scaling);
89
128
 
90
- highlightArea(ctx, size, {
91
- ...highlight,
92
- lineWidth: Math.ceil(lineWidth / currentZoom),
93
- });
129
+ const { highlight, highlightFunction = highlightArea } = configObject;
130
+ const { lineWidth = 2 } = highlight;
94
131
 
95
- ctx.restore();
132
+ highlightFunction(ctx, size, {
133
+ ...highlight,
134
+ lineWidth: Math.ceil(lineWidth / currentZoom),
96
135
  });
136
+
137
+ ctx.restore();
97
138
  };
98
139
 
99
140
  const drawOn = ctx => {
@@ -106,6 +147,8 @@ export const createTextureBuilder = (textureImage, params = {}) => {
106
147
 
107
148
  return {
108
149
  drawCanvasToArea,
150
+ drawCanvasToAreaDirect,
151
+ highlightDesignArea,
109
152
  highlightDesignAreas,
110
153
  drawOn,
111
154
  getTextureImage,