redhotmagma-visualization 1.28.5 → 1.29.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.
- package/AlignTargetProvider.js +129 -0
- package/CommonUtils/Deferred.js +135 -0
- package/CommonUtils/Observable.js +126 -0
- package/CommonUtils/PropertyObserver.js +61 -0
- package/CommonUtils/SyncCurrentFunction.js +59 -0
- package/CommonUtils/SyncObservableEvent.js +19 -0
- package/CommonUtils/pointerEvent.js +415 -0
- package/Constants.js +23 -0
- package/DevApp.js +1049 -0
- package/ExposedModules.js +26 -0
- package/FallbackVisualization.js +26 -0
- package/PrintingEffects/ColorEmbossingEffect.js +58 -0
- package/PrintingEffects/DomingEffect.js +150 -0
- package/PrintingEffects/EmbossingEffect.js +65 -0
- package/PrintingEffects/EmbroideryEffect.js +541 -0
- package/PrintingEffects/EngravingEffect.js +65 -0
- package/PrintingEffects/PrintingEffects.js +117 -0
- package/PrintingEffects/PrintingEffectsUtils.js +53 -0
- package/PrintingEffects/resources/embroidery_multiply.jpg +0 -0
- package/PrintingEffects/resources/embroidery_screen.jpg +0 -0
- package/README.md +11 -4
- package/React/ReactBase.js +111 -0
- package/Three/Controls/OrbitControls.js +745 -0
- package/Three/Exporters/glTFExporter.js +48 -0
- package/Three/Loaders/ColladaLoader.js +2916 -0
- package/Three/Loaders/MTLLoader.js +449 -0
- package/Three/Loaders/OBJLoader.js +548 -0
- package/Three/Three2D.js +1790 -0
- package/Three/Three2DLayers.js +504 -0
- package/Three/Three3D.js +1412 -0
- package/Three/Three3DScene.js +1432 -0
- package/Three/ThreeBase.js +724 -0
- package/Utils/DesignArea/getDesignAreaCanvasSize.js +32 -0
- package/Utils/TextureBuilder/createTextureBuilder.js +334 -0
- package/Utils/TextureBuilder/textureBuilderFunctions.js +87 -0
- package/Utils/alignToElement.js +58 -0
- package/Utils/createAlphaMapFromAlphaChannel.js +50 -0
- package/Utils/createCache.js +46 -0
- package/Utils/createCanvas.js +29 -0
- package/Utils/createImageRepository.js +124 -0
- package/Utils/disposeMaterial.js +41 -0
- package/Utils/getImageSize.js +15 -0
- package/Utils/imagePreloader.js +76 -0
- package/Utils/initTextureCanvas.js +49 -0
- package/Utils/isMobileDevice.js +19 -0
- package/Utils/optimizeTextureImage.js +73 -0
- package/Utils/rememberCameraViewOffset.js +21 -0
- package/Utils/removeObject.js +22 -0
- package/Utils/restrictCameraMovement.js +45 -0
- package/Utils/setOrthographicCameraSize.js +16 -0
- package/Utils/updateFitSizeToElement.js +39 -0
- package/VisualizationContainer.js +279 -0
- package/VisualizationInterface.js +298 -0
- package/VisualizationProvider.js +38 -0
- package/__mocks__/exportedSample.svg +45 -0
- package/index.js +16 -0
- package/package.json +10 -70
- package/scripts/cpPublic.js +9 -12
- package/scripts/cpPublicLocal.js +30 -0
- package/src/CommonUtils/Observable.js +1 -0
- package/src/CommonUtils/pointerEvent.js +2 -1
- package/src/DevApp.js +2 -1
- package/src/FallbackVisualization.js +1 -5
- package/src/PrintingEffects/DomingEffect.js +1 -0
- package/src/PrintingEffects/EmbroideryEffect.js +3 -2
- package/src/React/ReactBase.js +1 -1
- package/src/Three/Controls/OrbitControls.js +2 -0
- package/src/Three/Loaders/ColladaLoader.js +111 -294
- package/src/Three/Loaders/MTLLoader.js +2 -0
- package/src/Three/Loaders/OBJLoader.js +2 -0
- package/src/Three/Three2D.js +18 -11
- package/src/Three/Three3D.js +9 -1
- package/src/Three/ThreeBase.js +14 -2
- package/src/Utils/DesignArea/getDesignAreaCanvasSize.js +1 -0
- package/src/Utils/TextureBuilder/createTextureBuilder.js +2 -0
- package/src/Utils/imagePreloader.js +1 -0
- package/src/Utils/initTextureCanvas.js +3 -0
- package/src/Utils/isMobileDevice.js +2 -0
- package/src/Utils/optimizeTextureImage.js +1 -0
- package/src/VisualizationContainer.js +3 -1
- package/src/VisualizationInterface.js +10 -1
- package/visualizationAdapterCreator.js +76 -0
- package/babel.config.js +0 -41
- package/scripts/cpPath.js +0 -151
- package/scripts/moveLibToPackageRoot.js +0 -44
- package/scripts/utils/fileSystem.js +0 -69
- package/scripts/utils/process.js +0 -19
- package/tsconfig.json +0 -22
|
@@ -0,0 +1,724 @@
|
|
|
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 _this2$_intersectionR;
|
|
231
|
+
|
|
232
|
+
var raycaster = new _three.Raycaster();
|
|
233
|
+
|
|
234
|
+
var _this2$renderer$domEl = _this2.renderer.domElement.getBoundingClientRect(),
|
|
235
|
+
elementWidth = _this2$renderer$domEl.width,
|
|
236
|
+
elementHeight = _this2$renderer$domEl.height,
|
|
237
|
+
offsetX = _this2$renderer$domEl.left,
|
|
238
|
+
offsetY = _this2$renderer$domEl.top;
|
|
239
|
+
|
|
240
|
+
var point = (0, _pointerEvent.getPointFromPointerEvent)(pointerEvent);
|
|
241
|
+
var mouse = new _three.Vector2((point.x - offsetX) / elementWidth * 2 - 1, -((point.y - offsetY) / elementHeight) * 2 + 1);
|
|
242
|
+
raycaster.setFromCamera(mouse, _this2.camera);
|
|
243
|
+
var intersects = raycaster.intersectObjects(((_this2$_intersectionR = _this2._intersectionRoot) === null || _this2$_intersectionR === void 0 ? void 0 : _this2$_intersectionR.children) || _this2.scene.children, true);
|
|
244
|
+
|
|
245
|
+
if (intersects.length > 0) {
|
|
246
|
+
var intersect = intersects[0]; // closest object
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
target: intersect,
|
|
250
|
+
getTextureHit: function getTextureHit() {
|
|
251
|
+
var material = intersect.object.material;
|
|
252
|
+
|
|
253
|
+
if (material && _this2._customizableMaterialKeys.indexOf(material.name) !== -1) {
|
|
254
|
+
// note: the texture Y is flipped by default in the webgl context
|
|
255
|
+
// see (https://github.com/mrdoob/three.js/issues/5644)
|
|
256
|
+
// so if it's flipped we need to flip it back to get the image coordinates
|
|
257
|
+
var texture = material.map;
|
|
258
|
+
var flipY = texture.flipY;
|
|
259
|
+
var _texture$image = texture.image,
|
|
260
|
+
width = _texture$image.width,
|
|
261
|
+
height = _texture$image.height;
|
|
262
|
+
var x = Math.round(intersect.uv.x * width);
|
|
263
|
+
var y = Math.round((flipY ? 1 - intersect.uv.y : intersect.uv.y) * height);
|
|
264
|
+
return _this2.textureHitFormatter(intersect, {
|
|
265
|
+
width: width,
|
|
266
|
+
height: height,
|
|
267
|
+
x: x,
|
|
268
|
+
y: y
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return null;
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
return _this2;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
_createClass(ThreeBase, [{
|
|
282
|
+
key: "init",
|
|
283
|
+
value:
|
|
284
|
+
/**
|
|
285
|
+
* Initializes the 3D renderer, camera and scene
|
|
286
|
+
* @param {HTMLElement} [container=<div>]
|
|
287
|
+
* @param {boolean} useDefaultSetup
|
|
288
|
+
*/
|
|
289
|
+
function init() {
|
|
290
|
+
var container = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.createElement("div");
|
|
291
|
+
var useDefaultSetup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
292
|
+
this._isInitialized = true;
|
|
293
|
+
var scene = this.createScene();
|
|
294
|
+
this.scene = scene;
|
|
295
|
+
this.camera = this.createCamera();
|
|
296
|
+
scene.add(this.camera);
|
|
297
|
+
this.renderer = this.createRenderer();
|
|
298
|
+
this.addToContainer(container);
|
|
299
|
+
this.setupContextLostHandling();
|
|
300
|
+
|
|
301
|
+
if (useDefaultSetup) {
|
|
302
|
+
this.setupDefaultLightning();
|
|
303
|
+
this.setupDefaultControls();
|
|
304
|
+
this.setupDefaultHitTest();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
this.observable.dispatch(_Constants.EventTypes.Initialized);
|
|
308
|
+
}
|
|
309
|
+
}, {
|
|
310
|
+
key: "createScene",
|
|
311
|
+
value: function createScene() {
|
|
312
|
+
return new _three.Scene();
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Create and return a customized three.js renderer object
|
|
316
|
+
* @return {WebGLRenderer}
|
|
317
|
+
*/
|
|
318
|
+
|
|
319
|
+
}, {
|
|
320
|
+
key: "createRenderer",
|
|
321
|
+
value: function createRenderer() {}
|
|
322
|
+
/**
|
|
323
|
+
* Create and return a customized three.js camera object
|
|
324
|
+
* @return {Camera}
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
}, {
|
|
328
|
+
key: "createCamera",
|
|
329
|
+
value: function createCamera() {}
|
|
330
|
+
/**
|
|
331
|
+
* Updates the camera size (different setup for different camera types)
|
|
332
|
+
* @param {number} width
|
|
333
|
+
* @param {number} height
|
|
334
|
+
*/
|
|
335
|
+
// eslint-disable-next-line no-unused-vars
|
|
336
|
+
|
|
337
|
+
}, {
|
|
338
|
+
key: "updateCamera",
|
|
339
|
+
value: function updateCamera(width, height) {}
|
|
340
|
+
}, {
|
|
341
|
+
key: "addToContainer",
|
|
342
|
+
value: function addToContainer(container) {
|
|
343
|
+
this._container = container;
|
|
344
|
+
container.appendChild(this.renderer.domElement);
|
|
345
|
+
var size = container.getBoundingClientRect();
|
|
346
|
+
this.setSize(size, false);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Creates the paths for loading a model (object + material)
|
|
350
|
+
* @returns {{objPath: string, mtlPath: string}}
|
|
351
|
+
*/
|
|
352
|
+
|
|
353
|
+
}, {
|
|
354
|
+
key: "getModelPaths",
|
|
355
|
+
value: function getModelPaths() {
|
|
356
|
+
var _basePath = this._basePath,
|
|
357
|
+
_itemPath = this._itemPath,
|
|
358
|
+
_materialVariantPath = this._materialVariantPath;
|
|
359
|
+
var objPath = _itemPath ? [_basePath, _itemPath].join("/") : "";
|
|
360
|
+
var mtlPath = _materialVariantPath ? [objPath, "materials", _materialVariantPath].join("/") : "";
|
|
361
|
+
return {
|
|
362
|
+
objPath: objPath,
|
|
363
|
+
mtlPath: mtlPath
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Sets the canvas size
|
|
368
|
+
* @param {number} width
|
|
369
|
+
* @param {number} height
|
|
370
|
+
* @param {boolean} rerender
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
}, {
|
|
374
|
+
key: "setSize",
|
|
375
|
+
value: function setSize(_ref2) {
|
|
376
|
+
var width = _ref2.width,
|
|
377
|
+
height = _ref2.height;
|
|
378
|
+
var rerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
379
|
+
this.renderer.setSize(width, height);
|
|
380
|
+
this.updateCamera(width, height); // if not animating render should be called directly
|
|
381
|
+
|
|
382
|
+
if (rerender && !this.isAnimating()) {
|
|
383
|
+
this.render();
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Creates a simple cube for testing the scene setup
|
|
388
|
+
* @returns {Mesh}
|
|
389
|
+
*/
|
|
390
|
+
|
|
391
|
+
}, {
|
|
392
|
+
key: "createSampleCube",
|
|
393
|
+
value: function createSampleCube() {
|
|
394
|
+
var geometry = new _three.BoxGeometry(1, 1, 1);
|
|
395
|
+
var material = new _three.MeshBasicMaterial({
|
|
396
|
+
color: 0x00ff00
|
|
397
|
+
});
|
|
398
|
+
var cube = new _three.Mesh(geometry, material);
|
|
399
|
+
return cube;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Implement this function to add default lights to the scene
|
|
403
|
+
*/
|
|
404
|
+
|
|
405
|
+
}, {
|
|
406
|
+
key: "setupDefaultLightning",
|
|
407
|
+
value: function setupDefaultLightning() {}
|
|
408
|
+
/**
|
|
409
|
+
* @param {HTMLElement} targetElement
|
|
410
|
+
* @param {{}} options Custom options for the controls (see the OrbitControls.js file for details)
|
|
411
|
+
*/
|
|
412
|
+
// eslint-disable-next-line no-unused-vars
|
|
413
|
+
|
|
414
|
+
}, {
|
|
415
|
+
key: "setupDefaultControls",
|
|
416
|
+
value: function setupDefaultControls(targetElement) {
|
|
417
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
418
|
+
}
|
|
419
|
+
}, {
|
|
420
|
+
key: "addAxesHelper",
|
|
421
|
+
value: function addAxesHelper() {
|
|
422
|
+
var axesHelper = new _three.AxesHelper(50);
|
|
423
|
+
this.scene.add(axesHelper);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Enable or disable the controls
|
|
427
|
+
* @param {boolean} [enabled=true]
|
|
428
|
+
*/
|
|
429
|
+
|
|
430
|
+
}, {
|
|
431
|
+
key: "setControlsEnabled",
|
|
432
|
+
value: function setControlsEnabled() {
|
|
433
|
+
var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
434
|
+
|
|
435
|
+
if (!this.controls) {
|
|
436
|
+
throw new Error("The controls should be available for the setControlsEnabled call!");
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
this.controls.enabled = enabled;
|
|
440
|
+
} // eslint-disable-next-line no-unused-vars
|
|
441
|
+
|
|
442
|
+
}, {
|
|
443
|
+
key: "updateMaterial",
|
|
444
|
+
value: function updateMaterial() {
|
|
445
|
+
var targetObject = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.scene;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Getter function for the customizable materials
|
|
449
|
+
* @returns {Array}
|
|
450
|
+
*/
|
|
451
|
+
|
|
452
|
+
}, {
|
|
453
|
+
key: "getCustomizableMaterials",
|
|
454
|
+
value: function getCustomizableMaterials() {
|
|
455
|
+
return this._customizableMaterials;
|
|
456
|
+
}
|
|
457
|
+
}, {
|
|
458
|
+
key: "isCustomizableMaterialAvailable",
|
|
459
|
+
value: function isCustomizableMaterialAvailable() {
|
|
460
|
+
return this._customizableMaterials.length > 0;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Returns the material for the given name, or false if not found.
|
|
464
|
+
* @param {string} name
|
|
465
|
+
* @returns {boolean|Material}
|
|
466
|
+
*/
|
|
467
|
+
|
|
468
|
+
}, {
|
|
469
|
+
key: "findMaterialByName",
|
|
470
|
+
value: function findMaterialByName(name) {
|
|
471
|
+
var _iterator = _createForOfIteratorHelper(this._customizableMaterials),
|
|
472
|
+
_step;
|
|
473
|
+
|
|
474
|
+
try {
|
|
475
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
476
|
+
var mat = _step.value;
|
|
477
|
+
|
|
478
|
+
if (mat.name === name) {
|
|
479
|
+
return mat;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
} catch (err) {
|
|
483
|
+
_iterator.e(err);
|
|
484
|
+
} finally {
|
|
485
|
+
_iterator.f();
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Calls the given drawing function for custom drawing implementations
|
|
492
|
+
* It provides the drawing context and the original texture image to the callback function.
|
|
493
|
+
* It also invalidates the texture to make it update in the next render.
|
|
494
|
+
* Calls the render function if it's not animating continuously.
|
|
495
|
+
* @param {function(ctx: CanvasRenderingContext2D, image: HTMLImageElement)} drawingFn
|
|
496
|
+
* @param {boolean} updateAlpha
|
|
497
|
+
* @param {boolean} clearTexture
|
|
498
|
+
* @param {string|undefined} materialName If not provided it uses the first customizable material
|
|
499
|
+
*/
|
|
500
|
+
|
|
501
|
+
}, {
|
|
502
|
+
key: "getDrawingContext",
|
|
503
|
+
value: function getDrawingContext(drawingFn) {
|
|
504
|
+
var updateAlpha = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
505
|
+
var clearTexture = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
506
|
+
var materialName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Starts the continuous animation in the animation frame
|
|
510
|
+
* It also updates the related tween group.
|
|
511
|
+
* @param {number} time The timestamp value from the requestAnimationFrame callback (DOMHighResTimeStamp)
|
|
512
|
+
*/
|
|
513
|
+
|
|
514
|
+
}, {
|
|
515
|
+
key: "render",
|
|
516
|
+
value: function render() {
|
|
517
|
+
this.renderer && this.renderer.render(this.scene, this.camera);
|
|
518
|
+
}
|
|
519
|
+
}, {
|
|
520
|
+
key: "isAnimating",
|
|
521
|
+
value: function isAnimating() {
|
|
522
|
+
return this._isAnimating;
|
|
523
|
+
}
|
|
524
|
+
}, {
|
|
525
|
+
key: "cleanUpCameraAnimations",
|
|
526
|
+
value: function cleanUpCameraAnimations() {
|
|
527
|
+
this.stopAnimation("camera");
|
|
528
|
+
this.cameraTweenGroup.getAll().forEach(function (t) {
|
|
529
|
+
return t.stop();
|
|
530
|
+
});
|
|
531
|
+
this.cameraTweenGroup.removeAll();
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Ads a click event listener to the targetElement
|
|
535
|
+
* The hit test will be performed only if the controls are enabled.
|
|
536
|
+
* On success it dispatches the EventTypes.Intersection event with the intersection data.
|
|
537
|
+
* @see getIntersection
|
|
538
|
+
* @see Observable
|
|
539
|
+
* @see createPointerHitListener
|
|
540
|
+
* @param targetElement
|
|
541
|
+
*/
|
|
542
|
+
|
|
543
|
+
}, {
|
|
544
|
+
key: "setupDefaultHitTest",
|
|
545
|
+
value: function setupDefaultHitTest(targetElement) {
|
|
546
|
+
var _this3 = this;
|
|
547
|
+
|
|
548
|
+
var element = targetElement || this.renderer.domElement;
|
|
549
|
+
(0, _pointerEvent.createPointerHitListener)(element, function (evt) {
|
|
550
|
+
if (!_this3._hitTestEnabled) {
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if (!_this3.controls || _this3.controls.enabled || _this3._cameraMovementLocked) {
|
|
555
|
+
var is = _this3.getIntersection(evt);
|
|
556
|
+
|
|
557
|
+
_this3.observable.dispatch(is ? _Constants.EventTypes.Intersection : _Constants.EventTypes.ClickAway, is);
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Checks if the pointer intersects with the model
|
|
563
|
+
* @param {MouseEvent|TouchEvent} pointerEvent
|
|
564
|
+
* @returns {{target: { distance, point, face, faceIndex, object }, getTextureHit: (function())}|null}
|
|
565
|
+
*/
|
|
566
|
+
|
|
567
|
+
}, {
|
|
568
|
+
key: "textureHitFormatter",
|
|
569
|
+
value: function textureHitFormatter(intersect, position) {
|
|
570
|
+
return position;
|
|
571
|
+
}
|
|
572
|
+
}, {
|
|
573
|
+
key: "setupContextLostHandling",
|
|
574
|
+
value: function setupContextLostHandling() {
|
|
575
|
+
var _this = this;
|
|
576
|
+
|
|
577
|
+
this.renderer.getContext().canvas.addEventListener("webglcontextlost", function (event) {
|
|
578
|
+
event.preventDefault();
|
|
579
|
+
window.cancelAnimationFrame(_this._animationFrame); // eslint-disable-next-line no-console
|
|
580
|
+
|
|
581
|
+
console.warn("WEBGL CONTEXT LOST");
|
|
582
|
+
}, false);
|
|
583
|
+
this.renderer.getContext().canvas.addEventListener("webglcontextrestored", function () {
|
|
584
|
+
// if it was animating before start it again
|
|
585
|
+
if (_this._animationFrame) {
|
|
586
|
+
_this.animate();
|
|
587
|
+
} // eslint-disable-next-line no-console
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
console.warn("WEGL CONTEXT RESTORED");
|
|
591
|
+
}, false);
|
|
592
|
+
}
|
|
593
|
+
}, {
|
|
594
|
+
key: "toggleCameraLock",
|
|
595
|
+
value: function toggleCameraLock(locked) {
|
|
596
|
+
this._cameraMovementLocked = locked;
|
|
597
|
+
|
|
598
|
+
if (this.controls) {
|
|
599
|
+
this.controls.enabled = !locked;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}, {
|
|
603
|
+
key: "toggleHitTest",
|
|
604
|
+
value: function toggleHitTest(enabled) {
|
|
605
|
+
this._hitTestEnabled = enabled;
|
|
606
|
+
}
|
|
607
|
+
}, {
|
|
608
|
+
key: "clearScene",
|
|
609
|
+
value: function clearScene() {
|
|
610
|
+
// remove all Group objects
|
|
611
|
+
this.scene.children.filter(function (obj) {
|
|
612
|
+
return obj.type === "Group";
|
|
613
|
+
}).forEach(_removeObject.removeObject); // clear customizable materials and camera views
|
|
614
|
+
|
|
615
|
+
this._customizableMaterials = [];
|
|
616
|
+
this.cameraViews = {};
|
|
617
|
+
}
|
|
618
|
+
}, {
|
|
619
|
+
key: "dispose",
|
|
620
|
+
value: function dispose() {
|
|
621
|
+
this.stopAnimation();
|
|
622
|
+
this.cleanUpCameraAnimations();
|
|
623
|
+
this.observable.dispose();
|
|
624
|
+
|
|
625
|
+
if (this._container && this.renderer) {
|
|
626
|
+
this._container.removeChild(this.renderer.domElement);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
if (this.scene) {
|
|
630
|
+
this.scene.traverse(function (obj) {
|
|
631
|
+
if (obj.geometry) {
|
|
632
|
+
obj.geometry.dispose();
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
if (obj.material) {
|
|
636
|
+
(0, _disposeMaterial.disposeMaterial)(obj.material);
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
this.scene = null;
|
|
642
|
+
|
|
643
|
+
if (this.renderer) {
|
|
644
|
+
this.renderer.dispose();
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
this.renderer = null;
|
|
648
|
+
this.camera = null;
|
|
649
|
+
this.cameraViews = null;
|
|
650
|
+
this.controls = null;
|
|
651
|
+
this._customizableMaterials = [];
|
|
652
|
+
this._isInitialized = false; // eslint-disable-next-line no-console
|
|
653
|
+
|
|
654
|
+
console.info("Three instance has been successfully disposed.");
|
|
655
|
+
}
|
|
656
|
+
}, {
|
|
657
|
+
key: "abortScreenshotting",
|
|
658
|
+
value: function abortScreenshotting() {
|
|
659
|
+
this._screenshottingInProgress && Object.defineProperty(this, "_abortScreenshotting", {
|
|
660
|
+
configurable: true,
|
|
661
|
+
get: function get() {
|
|
662
|
+
delete this._abortScreenshotting;
|
|
663
|
+
return true;
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
}, {
|
|
668
|
+
key: "createTempOverlay",
|
|
669
|
+
value: function () {
|
|
670
|
+
var _createTempOverlay = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
671
|
+
var canvas, _createWorkingCanvas, _createWorkingCanvas2, tmpCanvas, scale, container;
|
|
672
|
+
|
|
673
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
674
|
+
while (1) {
|
|
675
|
+
switch (_context2.prev = _context2.next) {
|
|
676
|
+
case 0:
|
|
677
|
+
canvas = this.renderer.domElement;
|
|
678
|
+
this.render();
|
|
679
|
+
_createWorkingCanvas = (0, _createCanvas.createWorkingCanvas)(canvas, true), _createWorkingCanvas2 = _slicedToArray(_createWorkingCanvas, 1), tmpCanvas = _createWorkingCanvas2[0];
|
|
680
|
+
scale = 1 / this.renderer.getPixelRatio();
|
|
681
|
+
container = this._container;
|
|
682
|
+
Object.assign(tmpCanvas.style, {
|
|
683
|
+
position: "absolute",
|
|
684
|
+
top: "50%",
|
|
685
|
+
left: "50%",
|
|
686
|
+
transform: "translate(-50%, -50%) scale(".concat(scale, ", ").concat(scale, ")"),
|
|
687
|
+
opacity: 0
|
|
688
|
+
});
|
|
689
|
+
container.insertBefore(tmpCanvas, canvas);
|
|
690
|
+
_context2.next = 9;
|
|
691
|
+
return new Promise(function (resolve) {
|
|
692
|
+
window.requestAnimationFrame(function () {
|
|
693
|
+
tmpCanvas.style.opacity = 1;
|
|
694
|
+
canvas.style.visibility = "hidden";
|
|
695
|
+
resolve();
|
|
696
|
+
});
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
case 9:
|
|
700
|
+
return _context2.abrupt("return", function () {
|
|
701
|
+
canvas.style.visibility = "visible";
|
|
702
|
+
container.removeChild(tmpCanvas);
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
case 10:
|
|
706
|
+
case "end":
|
|
707
|
+
return _context2.stop();
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}, _callee2, this);
|
|
711
|
+
}));
|
|
712
|
+
|
|
713
|
+
function createTempOverlay() {
|
|
714
|
+
return _createTempOverlay.apply(this, arguments);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
return createTempOverlay;
|
|
718
|
+
}()
|
|
719
|
+
}]);
|
|
720
|
+
|
|
721
|
+
return ThreeBase;
|
|
722
|
+
}(_VisualizationInterface.VisualizationInterface);
|
|
723
|
+
|
|
724
|
+
exports.ThreeBase = ThreeBase;
|