@combeenation/3d-viewer 12.4.1 → 13.0.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/dist/lib-cjs/buildinfo.json +1 -1
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/dist/lib-cjs/index.d.ts +63 -63
- package/dist/lib-cjs/index.js +81 -114
- package/dist/lib-cjs/index.js.map +1 -1
- package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.d.ts +10 -0
- package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.js +124 -0
- package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.js.map +1 -0
- package/dist/lib-cjs/internal/cloningHelper.d.ts +19 -0
- package/dist/lib-cjs/internal/cloningHelper.js +165 -0
- package/dist/lib-cjs/internal/cloningHelper.js.map +1 -0
- package/dist/lib-cjs/internal/deviceHelper.d.ts +9 -0
- package/dist/lib-cjs/{api/util → internal}/deviceHelper.js +6 -10
- package/dist/lib-cjs/internal/deviceHelper.js.map +1 -0
- package/dist/lib-cjs/internal/geometryHelper.d.ts +21 -0
- package/dist/lib-cjs/{api/util → internal}/geometryHelper.js +57 -24
- package/dist/lib-cjs/internal/geometryHelper.js.map +1 -0
- package/dist/lib-cjs/internal/metadataHelper.d.ts +26 -0
- package/dist/lib-cjs/internal/metadataHelper.js +51 -0
- package/dist/lib-cjs/internal/metadataHelper.js.map +1 -0
- package/dist/lib-cjs/internal/paintableHelper.d.ts +40 -0
- package/dist/lib-cjs/internal/paintableHelper.js +287 -0
- package/dist/lib-cjs/internal/paintableHelper.js.map +1 -0
- package/dist/lib-cjs/internal/tagsHelper.d.ts +12 -0
- package/dist/lib-cjs/internal/tagsHelper.js +38 -0
- package/dist/lib-cjs/internal/tagsHelper.js.map +1 -0
- package/dist/lib-cjs/manager/cameraManager.d.ts +51 -0
- package/dist/lib-cjs/manager/cameraManager.js +154 -0
- package/dist/lib-cjs/manager/cameraManager.js.map +1 -0
- package/dist/lib-cjs/manager/debugManager.d.ts +60 -0
- package/dist/lib-cjs/manager/debugManager.js +218 -0
- package/dist/lib-cjs/manager/debugManager.js.map +1 -0
- package/dist/lib-cjs/manager/eventManager.d.ts +52 -0
- package/dist/lib-cjs/manager/eventManager.js +72 -0
- package/dist/lib-cjs/manager/eventManager.js.map +1 -0
- package/dist/lib-cjs/{api/manager → manager}/gltfExportManager.d.ts +29 -34
- package/dist/lib-cjs/{api/manager → manager}/gltfExportManager.js +99 -120
- package/dist/lib-cjs/manager/gltfExportManager.js.map +1 -0
- package/dist/lib-cjs/manager/materialManager.d.ts +35 -0
- package/dist/lib-cjs/manager/materialManager.js +126 -0
- package/dist/lib-cjs/manager/materialManager.js.map +1 -0
- package/dist/lib-cjs/manager/modelManager.d.ts +145 -0
- package/dist/lib-cjs/manager/modelManager.js +381 -0
- package/dist/lib-cjs/manager/modelManager.js.map +1 -0
- package/dist/lib-cjs/manager/parameterManager.d.ts +210 -0
- package/dist/lib-cjs/manager/parameterManager.js +515 -0
- package/dist/lib-cjs/manager/parameterManager.js.map +1 -0
- package/dist/lib-cjs/manager/sceneManager.d.ts +45 -0
- package/dist/lib-cjs/manager/sceneManager.js +65 -0
- package/dist/lib-cjs/manager/sceneManager.js.map +1 -0
- package/dist/lib-cjs/manager/screenshotManager.d.ts +36 -0
- package/dist/lib-cjs/manager/screenshotManager.js +40 -0
- package/dist/lib-cjs/manager/screenshotManager.js.map +1 -0
- package/dist/lib-cjs/manager/textureManager.d.ts +12 -0
- package/dist/lib-cjs/manager/textureManager.js +44 -0
- package/dist/lib-cjs/manager/textureManager.js.map +1 -0
- package/dist/lib-cjs/viewer.d.ts +117 -0
- package/dist/lib-cjs/viewer.js +222 -0
- package/dist/lib-cjs/viewer.js.map +1 -0
- package/dist/lib-cjs/{api/classes/viewerError.d.ts → viewerError.d.ts} +6 -1
- package/dist/lib-cjs/{api/classes/viewerError.js → viewerError.js} +6 -1
- package/dist/lib-cjs/viewerError.js.map +1 -0
- package/package.json +10 -11
- package/src/dev.ts +14 -37
- package/src/{types.d.ts → globalTypes.d.ts} +8 -18
- package/src/index.ts +79 -113
- package/src/internal/cbnCustomBabylonLoaderPlugin.ts +149 -0
- package/src/internal/cloningHelper.ts +225 -0
- package/src/internal/deviceHelper.ts +25 -0
- package/src/{api/util → internal}/geometryHelper.ts +63 -24
- package/src/internal/metadataHelper.ts +63 -0
- package/src/internal/paintableHelper.ts +310 -0
- package/src/internal/tagsHelper.ts +41 -0
- package/src/manager/cameraManager.ts +236 -0
- package/src/manager/debugManager.ts +245 -0
- package/src/manager/eventManager.ts +72 -0
- package/src/{api/manager → manager}/gltfExportManager.ts +132 -125
- package/src/manager/materialManager.ts +135 -0
- package/src/manager/modelManager.ts +456 -0
- package/src/manager/parameterManager.ts +652 -0
- package/src/manager/sceneManager.ts +101 -0
- package/src/manager/screenshotManager.ts +59 -0
- package/src/manager/textureManager.ts +32 -0
- package/src/viewer.ts +296 -0
- package/src/{api/classes/viewerError.ts → viewerError.ts} +6 -1
- package/dist/lib-cjs/api/classes/animationInterface.d.ts +0 -8
- package/dist/lib-cjs/api/classes/animationInterface.js +0 -3
- package/dist/lib-cjs/api/classes/animationInterface.js.map +0 -1
- package/dist/lib-cjs/api/classes/dottedPath.d.ts +0 -79
- package/dist/lib-cjs/api/classes/dottedPath.js +0 -167
- package/dist/lib-cjs/api/classes/dottedPath.js.map +0 -1
- package/dist/lib-cjs/api/classes/element.d.ts +0 -153
- package/dist/lib-cjs/api/classes/element.js +0 -703
- package/dist/lib-cjs/api/classes/element.js.map +0 -1
- package/dist/lib-cjs/api/classes/event.d.ts +0 -401
- package/dist/lib-cjs/api/classes/event.js +0 -425
- package/dist/lib-cjs/api/classes/event.js.map +0 -1
- package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +0 -26
- package/dist/lib-cjs/api/classes/eventBroadcaster.js +0 -50
- package/dist/lib-cjs/api/classes/eventBroadcaster.js.map +0 -1
- package/dist/lib-cjs/api/classes/fuzzyMap.d.ts +0 -7
- package/dist/lib-cjs/api/classes/fuzzyMap.js +0 -22
- package/dist/lib-cjs/api/classes/fuzzyMap.js.map +0 -1
- package/dist/lib-cjs/api/classes/parameter.d.ts +0 -410
- package/dist/lib-cjs/api/classes/parameter.js +0 -643
- package/dist/lib-cjs/api/classes/parameter.js.map +0 -1
- package/dist/lib-cjs/api/classes/parameterObservable.d.ts +0 -36
- package/dist/lib-cjs/api/classes/parameterObservable.js +0 -73
- package/dist/lib-cjs/api/classes/parameterObservable.js.map +0 -1
- package/dist/lib-cjs/api/classes/parameterizable.d.ts +0 -15
- package/dist/lib-cjs/api/classes/parameterizable.js +0 -103
- package/dist/lib-cjs/api/classes/parameterizable.js.map +0 -1
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +0 -45
- package/dist/lib-cjs/api/classes/placementAnimation.js +0 -177
- package/dist/lib-cjs/api/classes/placementAnimation.js.map +0 -1
- package/dist/lib-cjs/api/classes/variant.d.ts +0 -261
- package/dist/lib-cjs/api/classes/variant.js +0 -873
- package/dist/lib-cjs/api/classes/variant.js.map +0 -1
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +0 -53
- package/dist/lib-cjs/api/classes/variantInstance.js +0 -126
- package/dist/lib-cjs/api/classes/variantInstance.js.map +0 -1
- package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +0 -17
- package/dist/lib-cjs/api/classes/variantParameterizable.js +0 -87
- package/dist/lib-cjs/api/classes/variantParameterizable.js.map +0 -1
- package/dist/lib-cjs/api/classes/viewer.d.ts +0 -215
- package/dist/lib-cjs/api/classes/viewer.js +0 -709
- package/dist/lib-cjs/api/classes/viewer.js.map +0 -1
- package/dist/lib-cjs/api/classes/viewerError.js.map +0 -1
- package/dist/lib-cjs/api/classes/viewerLight.d.ts +0 -66
- package/dist/lib-cjs/api/classes/viewerLight.js +0 -345
- package/dist/lib-cjs/api/classes/viewerLight.js.map +0 -1
- package/dist/lib-cjs/api/internal/lensRendering.d.ts +0 -8
- package/dist/lib-cjs/api/internal/lensRendering.js +0 -12
- package/dist/lib-cjs/api/internal/lensRendering.js.map +0 -1
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +0 -13
- package/dist/lib-cjs/api/internal/sceneSetup.js +0 -228
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +0 -1
- package/dist/lib-cjs/api/manager/animationManager.d.ts +0 -30
- package/dist/lib-cjs/api/manager/animationManager.js +0 -127
- package/dist/lib-cjs/api/manager/animationManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/sceneManager.d.ts +0 -33
- package/dist/lib-cjs/api/manager/sceneManager.js +0 -129
- package/dist/lib-cjs/api/manager/sceneManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/tagManager.d.ts +0 -118
- package/dist/lib-cjs/api/manager/tagManager.js +0 -531
- package/dist/lib-cjs/api/manager/tagManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +0 -22
- package/dist/lib-cjs/api/manager/textureLoadManager.js +0 -108
- package/dist/lib-cjs/api/manager/textureLoadManager.js.map +0 -1
- package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +0 -106
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +0 -291
- package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +0 -1
- package/dist/lib-cjs/api/store/specStorage.d.ts +0 -32
- package/dist/lib-cjs/api/store/specStorage.js +0 -66
- package/dist/lib-cjs/api/store/specStorage.js.map +0 -1
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +0 -238
- package/dist/lib-cjs/api/util/babylonHelper.js +0 -826
- package/dist/lib-cjs/api/util/babylonHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/debugHelper.d.ts +0 -9
- package/dist/lib-cjs/api/util/debugHelper.js +0 -94
- package/dist/lib-cjs/api/util/debugHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/deviceHelper.d.ts +0 -9
- package/dist/lib-cjs/api/util/deviceHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/geometryHelper.d.ts +0 -17
- package/dist/lib-cjs/api/util/geometryHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +0 -490
- package/dist/lib-cjs/api/util/globalTypes.js +0 -2
- package/dist/lib-cjs/api/util/globalTypes.js.map +0 -1
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +0 -58
- package/dist/lib-cjs/api/util/resourceHelper.js +0 -215
- package/dist/lib-cjs/api/util/resourceHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +0 -58
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js +0 -229
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/stringHelper.d.ts +0 -13
- package/dist/lib-cjs/api/util/stringHelper.js +0 -33
- package/dist/lib-cjs/api/util/stringHelper.js.map +0 -1
- package/dist/lib-cjs/api/util/structureHelper.d.ts +0 -9
- package/dist/lib-cjs/api/util/structureHelper.js +0 -58
- package/dist/lib-cjs/api/util/structureHelper.js.map +0 -1
- package/src/api/classes/animationInterface.ts +0 -10
- package/src/api/classes/dottedPath.ts +0 -181
- package/src/api/classes/element.ts +0 -766
- package/src/api/classes/event.ts +0 -457
- package/src/api/classes/eventBroadcaster.ts +0 -52
- package/src/api/classes/fuzzyMap.ts +0 -21
- package/src/api/classes/parameter.ts +0 -686
- package/src/api/classes/parameterObservable.ts +0 -73
- package/src/api/classes/parameterizable.ts +0 -87
- package/src/api/classes/placementAnimation.ts +0 -162
- package/src/api/classes/variant.ts +0 -965
- package/src/api/classes/variantInstance.ts +0 -123
- package/src/api/classes/variantParameterizable.ts +0 -83
- package/src/api/classes/viewer.ts +0 -751
- package/src/api/classes/viewerLight.ts +0 -335
- package/src/api/internal/debugViewer.ts +0 -90
- package/src/api/internal/lensRendering.ts +0 -9
- package/src/api/internal/sceneSetup.ts +0 -208
- package/src/api/manager/animationManager.ts +0 -143
- package/src/api/manager/sceneManager.ts +0 -134
- package/src/api/manager/tagManager.ts +0 -572
- package/src/api/manager/textureLoadManager.ts +0 -107
- package/src/api/manager/variantInstanceManager.ts +0 -306
- package/src/api/store/specStorage.ts +0 -68
- package/src/api/util/babylonHelper.ts +0 -915
- package/src/api/util/debugHelper.ts +0 -121
- package/src/api/util/deviceHelper.ts +0 -31
- package/src/api/util/globalTypes.ts +0 -566
- package/src/api/util/resourceHelper.ts +0 -201
- package/src/api/util/sceneLoaderHelper.ts +0 -247
- package/src/api/util/stringHelper.ts +0 -30
- package/src/api/util/structureHelper.ts +0 -62
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.parsePaintable = exports.paintableParameterObserver = void 0;
|
|
27
|
+
const index_1 = require("../index");
|
|
28
|
+
const is_svg_1 = __importDefault(require("is-svg"));
|
|
29
|
+
const lodash_es_1 = require("lodash-es");
|
|
30
|
+
/**
|
|
31
|
+
* Observer implementation for "paintable" parameter.
|
|
32
|
+
* Basically creates a dynamic texture from the source image and assigns it as albedo (or diffuse) texture.
|
|
33
|
+
*/
|
|
34
|
+
function paintableParameterObserver(newValue, materials, scene) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const paintable = parsePaintable(newValue);
|
|
37
|
+
// check if value is svg or image source, do the conversion accordingly
|
|
38
|
+
const srcIsSvg = (0, is_svg_1.default)(paintable.src);
|
|
39
|
+
if (!srcIsSvg && paintable.src.includes('<svg') && paintable.src.includes('</svg>')) {
|
|
40
|
+
// seems like the user tried to use a SVG string, as <svg> tags are used
|
|
41
|
+
// inform the user that this is not a valid SVG string
|
|
42
|
+
throw new index_1.ViewerError({
|
|
43
|
+
id: index_1.ViewerErrorIds.InvalidParameterValue,
|
|
44
|
+
message: `Invalid value for parameter "paintable" given:\nsource string is no valid SVG string\nGiven value: ${paintable.src}`,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
let imageSource;
|
|
48
|
+
try {
|
|
49
|
+
imageSource = srcIsSvg ? yield _createImageFromSvg(paintable.src) : yield _createImageFromImgSrc(paintable.src);
|
|
50
|
+
}
|
|
51
|
+
catch (_a) {
|
|
52
|
+
// SVG might be invalid, even if it passes `isSvg` check
|
|
53
|
+
// in this case the image can't be created and will throw an error, which should be handled by the viewer and
|
|
54
|
+
// Combeenation viewer control
|
|
55
|
+
throw new index_1.ViewerError({
|
|
56
|
+
id: index_1.ViewerErrorIds.InvalidParameterValue,
|
|
57
|
+
message: `Invalid value for parameter "paintable" given:\nimage can't be created from source string\nGiven value: ${paintable.src}`,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// apply image source on desired material(s)
|
|
61
|
+
for (const material of materials) {
|
|
62
|
+
_drawPaintableOnMaterial(material, imageSource, scene, paintable.options);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.paintableParameterObserver = paintableParameterObserver;
|
|
67
|
+
/**
|
|
68
|
+
* Parser for paintable value.
|
|
69
|
+
* ATM this is only used internally, but it could theoretically be used to create ones own paintable implementation.
|
|
70
|
+
*
|
|
71
|
+
* @param value The value to parse. Examples:
|
|
72
|
+
* ```ts
|
|
73
|
+
* // Default definition as JSON object:
|
|
74
|
+
* '{ "src": "https://path.to/image.jpg", "uScale": 0.5 }'
|
|
75
|
+
*
|
|
76
|
+
* // Short hand definition, only contains source string:
|
|
77
|
+
* 'https://path.to/image.jpg'
|
|
78
|
+
*
|
|
79
|
+
* // Full content, paintable texture is flipped in both directions
|
|
80
|
+
* '{ "src": "https://path.to/image.jpg", "uScale": -1, "vScale": -1, "uOffset": 0, "vOffset": 0 }'
|
|
81
|
+
*
|
|
82
|
+
* // SVG content can be used directly:
|
|
83
|
+
* '<svg>...</svg>'
|
|
84
|
+
*
|
|
85
|
+
* // SVG in src property works as well:
|
|
86
|
+
* '{ "src": "<svg>...</svg>", "uScale": 0.5 }'
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
function parsePaintable(value) {
|
|
90
|
+
if (!(0, lodash_es_1.isString)(value)) {
|
|
91
|
+
throw new index_1.ViewerError({
|
|
92
|
+
id: index_1.ViewerErrorIds.InvalidParameterValue,
|
|
93
|
+
message: `Unable to parse paintable value: not a string\nGiven value: ${value}`,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const paintableValue = { src: '' };
|
|
97
|
+
let valObj = null;
|
|
98
|
+
try {
|
|
99
|
+
valObj = JSON.parse(value);
|
|
100
|
+
}
|
|
101
|
+
catch (_a) {
|
|
102
|
+
// use string directly
|
|
103
|
+
paintableValue.src = value;
|
|
104
|
+
if (value.startsWith('{')) {
|
|
105
|
+
// seems like the user tried to use a JSON string, as the input starts with {
|
|
106
|
+
throw new index_1.ViewerError({
|
|
107
|
+
id: index_1.ViewerErrorIds.InvalidParameterValue,
|
|
108
|
+
message: `Unable to parse paintable value: not a valid JSON string\nGiven value: ${value}`,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (valObj) {
|
|
113
|
+
// input string is JSON, src attribute is required
|
|
114
|
+
if (!valObj.src) {
|
|
115
|
+
throw new index_1.ViewerError({
|
|
116
|
+
id: index_1.ViewerErrorIds.InvalidParameterValue,
|
|
117
|
+
message: `Unable to parse paintable value: property "src" is missing\nGiven value: ${value}`,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (!(0, lodash_es_1.isString)(valObj.src)) {
|
|
121
|
+
throw new index_1.ViewerError({
|
|
122
|
+
id: index_1.ViewerErrorIds.InvalidParameterValue,
|
|
123
|
+
message: `Unable to parse paintable value: property "src" is not a string\nGiven value: ${value}`,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
// split src and options
|
|
127
|
+
const { src } = valObj, options = __rest(valObj, ["src"]);
|
|
128
|
+
paintableValue.src = src;
|
|
129
|
+
// only forward valid paintable options
|
|
130
|
+
const validOptionKeys = ['uScale', 'vScale', 'uOffset', 'vOffset'];
|
|
131
|
+
const { validOptions, invalidKeys } = Object.entries(options).reduce((accRes, [curKey, curValue]) => {
|
|
132
|
+
const isValidKey = validOptionKeys.includes(curKey);
|
|
133
|
+
if (isValidKey) {
|
|
134
|
+
accRes.validOptions[curKey] = curValue;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
accRes.invalidKeys.push(curKey);
|
|
138
|
+
}
|
|
139
|
+
return accRes;
|
|
140
|
+
}, { validOptions: {}, invalidKeys: [] });
|
|
141
|
+
if (invalidKeys.length) {
|
|
142
|
+
console.warn('Invalid paintable options provided: ' + invalidKeys.toString());
|
|
143
|
+
}
|
|
144
|
+
paintableValue.options = validOptions;
|
|
145
|
+
}
|
|
146
|
+
return paintableValue;
|
|
147
|
+
}
|
|
148
|
+
exports.parsePaintable = parsePaintable;
|
|
149
|
+
function _drawPaintableOnMaterial(material, imageSource, scene, options) {
|
|
150
|
+
var _a, _b, _c, _d;
|
|
151
|
+
// always take width and height from image source, scaling is done with uvScale properties
|
|
152
|
+
const widthAndHeight = {
|
|
153
|
+
width: imageSource.width,
|
|
154
|
+
height: imageSource.height,
|
|
155
|
+
};
|
|
156
|
+
const texture = new index_1.DynamicTexture(`${material.id}.paintable_texture`, widthAndHeight, scene);
|
|
157
|
+
// draw image on texture
|
|
158
|
+
const ctx = texture.getContext();
|
|
159
|
+
ctx.drawImage(imageSource, 0, 0);
|
|
160
|
+
texture.update();
|
|
161
|
+
// apply settings from paintable options to tweak position and scaling of image on the texture
|
|
162
|
+
texture.uScale = (_a = options === null || options === void 0 ? void 0 : options.uScale) !== null && _a !== void 0 ? _a : texture.uScale;
|
|
163
|
+
texture.vScale = (_b = options === null || options === void 0 ? void 0 : options.vScale) !== null && _b !== void 0 ? _b : texture.vScale;
|
|
164
|
+
texture.uOffset = (_c = options === null || options === void 0 ? void 0 : options.uOffset) !== null && _c !== void 0 ? _c : texture.uOffset;
|
|
165
|
+
texture.vOffset = (_d = options === null || options === void 0 ? void 0 : options.vOffset) !== null && _d !== void 0 ? _d : texture.vOffset;
|
|
166
|
+
// wrap mode is preferred, as it will always show the texture, no matter which position offset is currently chosen
|
|
167
|
+
// clamp mode requires more knowledge (and patience) when adjusting the uv scale and offset values
|
|
168
|
+
texture.wrapU = index_1.Texture.WRAP_ADDRESSMODE;
|
|
169
|
+
texture.wrapV = index_1.Texture.WRAP_ADDRESSMODE;
|
|
170
|
+
// apply the paintable texture on the dedicated material type
|
|
171
|
+
const materialCls = material.getClassName();
|
|
172
|
+
switch (materialCls) {
|
|
173
|
+
case 'PBRMaterial':
|
|
174
|
+
material.albedoTexture = texture;
|
|
175
|
+
break;
|
|
176
|
+
case 'StandardMaterial':
|
|
177
|
+
material.diffuseTexture = texture;
|
|
178
|
+
break;
|
|
179
|
+
default:
|
|
180
|
+
throw new Error(`Setting paintable texture for material of instance "${materialCls}" not implemented (yet)`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Creates a HTML image element based on a SVG string, whereas all the embedded assets in the SVG (eg: fonts, images)
|
|
185
|
+
* are already loaded and exchanged by their base64 representation.\
|
|
186
|
+
* There the output image can exist as "standalone" image and may be used for example as a paintable.
|
|
187
|
+
*
|
|
188
|
+
* !!CAUTION!!: The used functions within this code section are very well evaluated since most alternatives
|
|
189
|
+
* somehow don't work in Safari, as mentioned in the following BJS forum entries:
|
|
190
|
+
* - https://forum.babylonjs.com/t/drawing-svg-content-text-into-dynamictexture-doesnt-work-in-safari-v15/25048
|
|
191
|
+
* - https://forum.babylonjs.com/t/texture-createfrombase64string-doesnt-seem-to-work-for-ios-devices-initially/25502
|
|
192
|
+
*/
|
|
193
|
+
function _createImageFromSvg(svgSrc) {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
// replace assets with their base64 versions in svg source code
|
|
196
|
+
const svgWithAssetsEmbedded = yield _embedAssets(svgSrc);
|
|
197
|
+
// create data string which can be used as an image source
|
|
198
|
+
const svgEncoded = 'data:image/svg+xml,' + encodeURIComponent(svgWithAssetsEmbedded);
|
|
199
|
+
return _createImageFromImgSrc(svgEncoded);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Creates an HTML image element from a dedicated image source.\
|
|
204
|
+
* Also waits until the image has loaded.
|
|
205
|
+
*
|
|
206
|
+
* !!CAUTION!!: The `setTimeout` after loading is finished is required due to a Safari bug:
|
|
207
|
+
* - https://bugs.webkit.org/show_bug.cgi?id=39059
|
|
208
|
+
* - https://bugs.webkit.org/show_bug.cgi?id=219770
|
|
209
|
+
*
|
|
210
|
+
* It's not 100% ensured that the timeout solves the issue in every case, but there is no other way unfortunately.\
|
|
211
|
+
* => Keep an eye on it in future projects
|
|
212
|
+
*
|
|
213
|
+
* @param imgSrc Theoretically every source is valid which is also supported by
|
|
214
|
+
* [HTMLImageElement.src](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/src).\
|
|
215
|
+
* Known exceptions are SVGs with embedded assets that are provided as object URL. See comments in
|
|
216
|
+
* {@link createImageFromSvg} for further details.
|
|
217
|
+
*/
|
|
218
|
+
function _createImageFromImgSrc(imgSrc) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
const img = new Image();
|
|
221
|
+
yield new Promise((resolve, reject) => {
|
|
222
|
+
img.onload = () => {
|
|
223
|
+
setTimeout(resolve, 0);
|
|
224
|
+
};
|
|
225
|
+
img.onerror = () => {
|
|
226
|
+
reject();
|
|
227
|
+
};
|
|
228
|
+
img.crossOrigin = 'anonymous';
|
|
229
|
+
img.src = imgSrc;
|
|
230
|
+
});
|
|
231
|
+
return img;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Replaces all supported image & font URLs in the given SVG with their base64 representation.
|
|
236
|
+
*/
|
|
237
|
+
function _embedAssets(svgSrc) {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
const _imageExtensions = ['png', 'gif', 'jpg', 'jpeg', 'svg', 'bmp'];
|
|
240
|
+
const _fontExtensions = ['woff2', 'woff', 'ttf', 'otf'];
|
|
241
|
+
const _assetExtensions = [..._imageExtensions, ..._fontExtensions];
|
|
242
|
+
// Regex copied from https://stackoverflow.com/a/8943487/1273551, not "stress tested"...
|
|
243
|
+
const urlRegex = /(\bhttps?:\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gi;
|
|
244
|
+
const allUrls = svgSrc.match(urlRegex);
|
|
245
|
+
const assetUrls = allUrls.filter(url => {
|
|
246
|
+
const indexParam = url.indexOf('?');
|
|
247
|
+
// remove url parameter to recognize extension
|
|
248
|
+
if (indexParam > -1) {
|
|
249
|
+
url = url.substring(0, indexParam);
|
|
250
|
+
}
|
|
251
|
+
return _assetExtensions.some(extension => url.toLowerCase().endsWith(`.${extension}`));
|
|
252
|
+
});
|
|
253
|
+
const assetBase64Fetcher = assetUrls.map(_fetchBase64AssetUrl);
|
|
254
|
+
const assetFetcherResults = yield Promise.all(assetBase64Fetcher);
|
|
255
|
+
return assetFetcherResults.reduce((svgSrc, x) => svgSrc.replace(x.url, x.base64), svgSrc);
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Fetch asset (image or font) and convert it to base64 string representation.
|
|
260
|
+
*/
|
|
261
|
+
function _fetchBase64AssetUrl(assetUrl) {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
// TODO WTT: Cache known base64 representation and only fetch/convert when not already known.
|
|
264
|
+
// Usually the fetch shouldn't hit the network but the browser cache since the SVG was already drawn..
|
|
265
|
+
const resp = yield fetch(assetUrl);
|
|
266
|
+
const blob = yield resp.blob();
|
|
267
|
+
return new Promise((resolve, reject) => {
|
|
268
|
+
const reader = new FileReader();
|
|
269
|
+
reader.onloadend = (event) => {
|
|
270
|
+
const target = event.target;
|
|
271
|
+
if (!target) {
|
|
272
|
+
return reject(`Asset with URL "${assetUrl}" could not be loaded.`);
|
|
273
|
+
}
|
|
274
|
+
const result = target.result;
|
|
275
|
+
if (!result) {
|
|
276
|
+
return reject(`Asset with URL "${assetUrl}" returned an empty result.`);
|
|
277
|
+
}
|
|
278
|
+
resolve({
|
|
279
|
+
url: assetUrl,
|
|
280
|
+
base64: result.toString(),
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
reader.readAsDataURL(blob);
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=paintableHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paintableHelper.js","sourceRoot":"","sources":["../../../src/internal/paintableHelper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAUkB;AAClB,oDAA2B;AAC3B,yCAAqC;AAcrC;;;GAGG;AACH,SAAsB,0BAA0B,CAC9C,QAAwB,EACxB,SAAqB,EACrB,KAAY;;QAEZ,MAAM,SAAS,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;QAE3C,uEAAuE;QACvE,MAAM,QAAQ,GAAG,IAAA,gBAAK,EAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACtC,IAAI,CAAC,QAAQ,IAAI,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;YACnF,wEAAwE;YACxE,sDAAsD;YACtD,MAAM,IAAI,mBAAW,CAAC;gBACpB,EAAE,EAAE,sBAAc,CAAC,qBAAqB;gBACxC,OAAO,EAAE,sGAAsG,SAAS,CAAC,GAAG,EAAE;aAC/H,CAAC,CAAC;SACJ;QAED,IAAI,WAA8B,CAAC;QACnC,IAAI;YACF,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAM,mBAAmB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,sBAAsB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;SACjH;QAAC,WAAM;YACN,wDAAwD;YACxD,6GAA6G;YAC7G,8BAA8B;YAC9B,MAAM,IAAI,mBAAW,CAAC;gBACpB,EAAE,EAAE,sBAAc,CAAC,qBAAqB;gBACxC,OAAO,EAAE,2GAA2G,SAAS,CAAC,GAAG,EAAE;aACpI,CAAC,CAAC;SACJ;QAED,4CAA4C;QAC5C,K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;oBACX,OAAO,MAAM,CAAC,mBAAmB,QAAQ,wBAAwB,CAAC,CAAC;iBACpE;gBACD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;gBAC7B,IAAI,CAAC,MAAM,EAAE;oBACX,OAAO,MAAM,CAAC,mBAAmB,QAAQ,6BAA6B,CAAC,CAAC;iBACzE;gBACD,OAAO,CAAC;oBACN,GAAG,EAAE,QAAQ;oBACb,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAY;iBACpC,CAAC,CAAC;YACL,CAAC,CAAC;YACF,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Material, Node } from '../index';
|
|
2
|
+
/**
|
|
3
|
+
* This is a wrapper around Babylon.js Tags API, as the API is really clunky to use
|
|
4
|
+
*/
|
|
5
|
+
declare type TagTarget = Node | Material;
|
|
6
|
+
export declare function hasTag(object: TagTarget, tag: string): boolean;
|
|
7
|
+
export declare function getTags(object: TagTarget): string[];
|
|
8
|
+
export declare function setTags(object: TagTarget, tags: string[]): void;
|
|
9
|
+
export declare function deleteAllTags(object: TagTarget): void;
|
|
10
|
+
export declare function setTagsAsString(object: TagTarget, tagsString: string): void;
|
|
11
|
+
export declare function cloneTags(sourceObject: TagTarget, destinationObject: TagTarget): void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cloneTags = exports.setTagsAsString = exports.deleteAllTags = exports.setTags = exports.getTags = exports.hasTag = void 0;
|
|
4
|
+
const tags_1 = require("@babylonjs/core/Misc/tags");
|
|
5
|
+
function hasTag(object, tag) {
|
|
6
|
+
return tags_1.Tags.MatchesQuery(object, tag);
|
|
7
|
+
}
|
|
8
|
+
exports.hasTag = hasTag;
|
|
9
|
+
function getTags(object) {
|
|
10
|
+
var _a;
|
|
11
|
+
const tagsObject = (_a = tags_1.Tags.GetTags(object, false)) !== null && _a !== void 0 ? _a : {};
|
|
12
|
+
const tags = Object.keys(tagsObject);
|
|
13
|
+
return tags;
|
|
14
|
+
}
|
|
15
|
+
exports.getTags = getTags;
|
|
16
|
+
function setTags(object, tags) {
|
|
17
|
+
const tagsString = tags.join(' ');
|
|
18
|
+
tags_1.Tags.AddTagsTo(object, tagsString);
|
|
19
|
+
}
|
|
20
|
+
exports.setTags = setTags;
|
|
21
|
+
function deleteAllTags(object) {
|
|
22
|
+
const curTags = tags_1.Tags.GetTags(object);
|
|
23
|
+
if (curTags) {
|
|
24
|
+
tags_1.Tags.RemoveTagsFrom(object, curTags);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.deleteAllTags = deleteAllTags;
|
|
28
|
+
function setTagsAsString(object, tagsString) {
|
|
29
|
+
tags_1.Tags.AddTagsTo(object, tagsString);
|
|
30
|
+
}
|
|
31
|
+
exports.setTagsAsString = setTagsAsString;
|
|
32
|
+
function cloneTags(sourceObject, destinationObject) {
|
|
33
|
+
if (tags_1.Tags.HasTags(sourceObject)) {
|
|
34
|
+
tags_1.Tags.AddTagsTo(destinationObject, tags_1.Tags.GetTags(sourceObject, true));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.cloneTags = cloneTags;
|
|
38
|
+
//# sourceMappingURL=tagsHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tagsHelper.js","sourceRoot":"","sources":["../../../src/internal/tagsHelper.ts"],"names":[],"mappings":";;;AACA,oDAAiD;AAQjD,SAAgB,MAAM,CAAC,MAAiB,EAAE,GAAW;IACnD,OAAO,WAAI,CAAC,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACxC,CAAC;AAFD,wBAEC;AAED,SAAgB,OAAO,CAAC,MAAiB;;IACvC,MAAM,UAAU,GAAG,MAAA,WAAI,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,mCAAI,EAAE,CAAC;IACrD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAErC,OAAO,IAAI,CAAC;AACd,CAAC;AALD,0BAKC;AAED,SAAgB,OAAO,CAAC,MAAiB,EAAE,IAAc;IACvD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,WAAI,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AACrC,CAAC;AAHD,0BAGC;AAED,SAAgB,aAAa,CAAC,MAAiB;IAC7C,MAAM,OAAO,GAAG,WAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,OAAO,EAAE;QACX,WAAI,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACtC;AACH,CAAC;AALD,sCAKC;AAED,SAAgB,eAAe,CAAC,MAAiB,EAAE,UAAkB;IACnE,WAAI,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AACrC,CAAC;AAFD,0CAEC;AAED,SAAgB,SAAS,CAAC,YAAuB,EAAE,iBAA4B;IAC7E,IAAI,WAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QAC9B,WAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,WAAI,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;KACrE;AACH,CAAC;AAJD,8BAIC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AnimationGroup, ArcRotateCamera, ExcludedGeometryList, Vector3, Viewer } from '../index';
|
|
2
|
+
export declare type CameraPosition = {
|
|
3
|
+
alpha: number;
|
|
4
|
+
beta: number;
|
|
5
|
+
radius: number;
|
|
6
|
+
target: Vector3;
|
|
7
|
+
};
|
|
8
|
+
export declare type AutofocusSettings = {
|
|
9
|
+
/** Can be used to customize the margins shown around the 3d model. Defaults to 1. */
|
|
10
|
+
radiusFactor?: number;
|
|
11
|
+
adjustWheelPrecision?: boolean;
|
|
12
|
+
adjustPanningSensibility?: boolean;
|
|
13
|
+
adjustPinchPrecision?: boolean;
|
|
14
|
+
/** Desired horizontal camera angle, this won't be overwritten by the autofocus function */
|
|
15
|
+
alpha?: number;
|
|
16
|
+
/** Desired vertical camera angle, this won't be overwritten by the autofocus function */
|
|
17
|
+
beta?: number;
|
|
18
|
+
/** Optional list of geometry to be excluded from consideration */
|
|
19
|
+
exclude?: ExcludedGeometryList;
|
|
20
|
+
durationMs?: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Manager for camera related tasks
|
|
24
|
+
*/
|
|
25
|
+
export declare class CameraManager {
|
|
26
|
+
protected viewer: Viewer;
|
|
27
|
+
static readonly CAMERA_ANIMATION_NAME = "__cameraAnimation__";
|
|
28
|
+
/** @internal */
|
|
29
|
+
static readonly DEFAULT_CAMERA_POSITION: CameraPosition;
|
|
30
|
+
protected static readonly _AUTOFOCUS_CONSTANTS: {
|
|
31
|
+
minZ: number;
|
|
32
|
+
wheelPrecision: number;
|
|
33
|
+
panningSensibility: number;
|
|
34
|
+
pinchPrecision: number;
|
|
35
|
+
};
|
|
36
|
+
protected static readonly _DEFAULT_AUTOFOCUS_RADIUS_FACTOR = 1;
|
|
37
|
+
protected static readonly _DEFAULT_CAM_SPEED_MS = 250;
|
|
38
|
+
/** @internal */
|
|
39
|
+
constructor(viewer: Viewer);
|
|
40
|
+
/**
|
|
41
|
+
* Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
|
|
42
|
+
*/
|
|
43
|
+
autofocusActiveCamera(settings?: AutofocusSettings): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Moves the active camera smoothly to certain position
|
|
46
|
+
*
|
|
47
|
+
* @param durationMs defaults to 250ms if unset, use 0 for instant movement
|
|
48
|
+
*/
|
|
49
|
+
moveActiveCameraTo(position: CameraPosition, durationMs?: number): Promise<void>;
|
|
50
|
+
protected static _addCameraAnimationToGroup(targetProperty: string, from: number | Vector3, to: number | Vector3, framesPerSec: number, dataType: number, animationGroup: AnimationGroup, activeCamera: ArcRotateCamera): void;
|
|
51
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CameraManager = void 0;
|
|
13
|
+
const index_1 = require("../index");
|
|
14
|
+
/**
|
|
15
|
+
* Manager for camera related tasks
|
|
16
|
+
*/
|
|
17
|
+
class CameraManager {
|
|
18
|
+
/** @internal */
|
|
19
|
+
constructor(viewer) {
|
|
20
|
+
this.viewer = viewer;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
|
|
24
|
+
*/
|
|
25
|
+
autofocusActiveCamera(settings) {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const activeCamera = this.viewer.scene.activeCamera;
|
|
29
|
+
if (!(activeCamera instanceof index_1.ArcRotateCamera)) {
|
|
30
|
+
throw new Error(`Camera type "${activeCamera === null || activeCamera === void 0 ? void 0 : activeCamera.getClassName()}" is not implemented for "autofocusActiveCamera".`);
|
|
31
|
+
}
|
|
32
|
+
// get bounding box of all visible meshes, this is the base for the autofocus algorithm
|
|
33
|
+
const boundingInfo = this.viewer.calculateBoundingInfo(settings === null || settings === void 0 ? void 0 : settings.exclude);
|
|
34
|
+
// optionally show bounding sphere for debugging purpose
|
|
35
|
+
this.viewer.eventManager.fireEvent(index_1.ViewerEvent.AutofocusStart, boundingInfo.boundingSphere);
|
|
36
|
+
const radius = boundingInfo.boundingSphere.radius;
|
|
37
|
+
const center = boundingInfo.boundingSphere.center;
|
|
38
|
+
// set lower radius limit on edge of bounding sphere to make sure that we can't dive into the meshes
|
|
39
|
+
activeCamera.lowerRadiusLimit = radius;
|
|
40
|
+
// additional settings
|
|
41
|
+
// constants for division are taken directly from Babylon.js repository
|
|
42
|
+
activeCamera.minZ = Math.min(radius / CameraManager._AUTOFOCUS_CONSTANTS.minZ, 1);
|
|
43
|
+
if ((settings === null || settings === void 0 ? void 0 : settings.adjustWheelPrecision) !== false) {
|
|
44
|
+
activeCamera.wheelPrecision = CameraManager._AUTOFOCUS_CONSTANTS.wheelPrecision / radius;
|
|
45
|
+
}
|
|
46
|
+
if ((settings === null || settings === void 0 ? void 0 : settings.adjustPanningSensibility) !== false) {
|
|
47
|
+
activeCamera.panningSensibility = CameraManager._AUTOFOCUS_CONSTANTS.panningSensibility / radius;
|
|
48
|
+
}
|
|
49
|
+
if ((settings === null || settings === void 0 ? void 0 : settings.adjustPinchPrecision) !== false) {
|
|
50
|
+
activeCamera.pinchPrecision = CameraManager._AUTOFOCUS_CONSTANTS.pinchPrecision / radius;
|
|
51
|
+
}
|
|
52
|
+
const radiusFactor = (_a = settings === null || settings === void 0 ? void 0 : settings.radiusFactor) !== null && _a !== void 0 ? _a : CameraManager._DEFAULT_AUTOFOCUS_RADIUS_FACTOR;
|
|
53
|
+
const alpha = (_b = settings === null || settings === void 0 ? void 0 : settings.alpha) !== null && _b !== void 0 ? _b : CameraManager.DEFAULT_CAMERA_POSITION.alpha;
|
|
54
|
+
const beta = (_c = settings === null || settings === void 0 ? void 0 : settings.beta) !== null && _c !== void 0 ? _c : CameraManager.DEFAULT_CAMERA_POSITION.beta;
|
|
55
|
+
// calculation is taken from Babylon.js repository, which on their side took it from this SO post:
|
|
56
|
+
// http://stackoverflow.com/questions/2866350/move-camera-to-fit-3d-scene
|
|
57
|
+
// there's a good sketch which explains the calculation quite a bit
|
|
58
|
+
const aspectRatio = this.viewer.engine.getAspectRatio(activeCamera);
|
|
59
|
+
const frustumSlopeY = Math.tan(activeCamera.fov / 2);
|
|
60
|
+
const frustumSlopeX = frustumSlopeY * aspectRatio;
|
|
61
|
+
const distanceForHorizontalFrustum = radius * Math.sqrt(1 + 1 / (frustumSlopeX * frustumSlopeX));
|
|
62
|
+
const distanceForVerticalFrustum = radius * Math.sqrt(1 + 1 / (frustumSlopeY * frustumSlopeY));
|
|
63
|
+
const distance = Math.max(distanceForHorizontalFrustum, distanceForVerticalFrustum);
|
|
64
|
+
const newCameraPosition = {
|
|
65
|
+
alpha: alpha,
|
|
66
|
+
beta: beta,
|
|
67
|
+
radius: distance * radiusFactor,
|
|
68
|
+
target: center,
|
|
69
|
+
};
|
|
70
|
+
yield this.moveActiveCameraTo(newCameraPosition, settings === null || settings === void 0 ? void 0 : settings.durationMs);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Moves the active camera smoothly to certain position
|
|
75
|
+
*
|
|
76
|
+
* @param durationMs defaults to 250ms if unset, use 0 for instant movement
|
|
77
|
+
*/
|
|
78
|
+
moveActiveCameraTo(position, durationMs = CameraManager._DEFAULT_CAM_SPEED_MS) {
|
|
79
|
+
var _a, _b, _c, _d;
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const activeCamera = this.viewer.scene.activeCamera;
|
|
82
|
+
if (!(activeCamera instanceof index_1.ArcRotateCamera)) {
|
|
83
|
+
throw new Error(`Camera type "${activeCamera === null || activeCamera === void 0 ? void 0 : activeCamera.getClassName()}" is not implemented yet for "moveActiveCameraTo".`);
|
|
84
|
+
}
|
|
85
|
+
if (durationMs === 0) {
|
|
86
|
+
// instant movement without animation
|
|
87
|
+
activeCamera.alpha = (_a = position.alpha) !== null && _a !== void 0 ? _a : activeCamera.alpha;
|
|
88
|
+
activeCamera.beta = (_b = position.beta) !== null && _b !== void 0 ? _b : activeCamera.beta;
|
|
89
|
+
activeCamera.radius = (_c = position.radius) !== null && _c !== void 0 ? _c : activeCamera.radius;
|
|
90
|
+
activeCamera.target = (_d = position.target) !== null && _d !== void 0 ? _d : activeCamera.target;
|
|
91
|
+
}
|
|
92
|
+
const framesPerSec = 100;
|
|
93
|
+
const animationGroup = new index_1.AnimationGroup(CameraManager.CAMERA_ANIMATION_NAME, this.viewer.scene);
|
|
94
|
+
if (position.alpha !== undefined) {
|
|
95
|
+
// transform the target's alpha value into the same turn as the current camera position to avoid movements
|
|
96
|
+
// > 360 degrees
|
|
97
|
+
const alphaGap = activeCamera.alpha - position.alpha;
|
|
98
|
+
const cntTurns = Math.round(alphaGap / (2 * Math.PI));
|
|
99
|
+
const targetAlpha = position.alpha + 2 * Math.PI * cntTurns;
|
|
100
|
+
CameraManager._addCameraAnimationToGroup('alpha', activeCamera.alpha, targetAlpha, framesPerSec, index_1.Animation.ANIMATIONTYPE_FLOAT, animationGroup, activeCamera);
|
|
101
|
+
}
|
|
102
|
+
if (position.beta !== undefined) {
|
|
103
|
+
CameraManager._addCameraAnimationToGroup('beta', activeCamera.beta, position.beta, framesPerSec, index_1.Animation.ANIMATIONTYPE_FLOAT, animationGroup, activeCamera);
|
|
104
|
+
}
|
|
105
|
+
if (position.radius !== undefined) {
|
|
106
|
+
CameraManager._addCameraAnimationToGroup('radius', activeCamera.radius, position.radius, framesPerSec, index_1.Animation.ANIMATIONTYPE_FLOAT, animationGroup, activeCamera);
|
|
107
|
+
}
|
|
108
|
+
if (position.target !== undefined) {
|
|
109
|
+
CameraManager._addCameraAnimationToGroup('target', activeCamera.target, position.target, framesPerSec, index_1.Animation.ANIMATIONTYPE_VECTOR3, animationGroup, activeCamera);
|
|
110
|
+
}
|
|
111
|
+
// animation is created for 1 second (100 frames), adjust speed ratio according to desired movement time
|
|
112
|
+
const speedRatio = 1000 / durationMs;
|
|
113
|
+
return new Promise(resolve => {
|
|
114
|
+
animationGroup.onAnimationGroupEndObservable.addOnce(() => {
|
|
115
|
+
animationGroup.dispose();
|
|
116
|
+
resolve();
|
|
117
|
+
});
|
|
118
|
+
animationGroup.start(false, speedRatio, 0, 100);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
static _addCameraAnimationToGroup(targetProperty, from, to, framesPerSec, dataType, animationGroup, activeCamera) {
|
|
123
|
+
const alphaAnimation = new index_1.Animation(targetProperty, targetProperty, framesPerSec, dataType, index_1.Animation.ANIMATIONLOOPMODE_CONSTANT);
|
|
124
|
+
alphaAnimation.setKeys([
|
|
125
|
+
{
|
|
126
|
+
frame: 0,
|
|
127
|
+
value: from,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
frame: 100,
|
|
131
|
+
value: to,
|
|
132
|
+
},
|
|
133
|
+
]);
|
|
134
|
+
animationGroup.addTargetedAnimation(alphaAnimation, activeCamera);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.CameraManager = CameraManager;
|
|
138
|
+
CameraManager.CAMERA_ANIMATION_NAME = '__cameraAnimation__';
|
|
139
|
+
/** @internal */
|
|
140
|
+
CameraManager.DEFAULT_CAMERA_POSITION = {
|
|
141
|
+
alpha: (45 * Math.PI) / 180,
|
|
142
|
+
beta: (75 * Math.PI) / 180,
|
|
143
|
+
radius: 1,
|
|
144
|
+
target: new index_1.Vector3(0, 0, 0),
|
|
145
|
+
};
|
|
146
|
+
CameraManager._AUTOFOCUS_CONSTANTS = {
|
|
147
|
+
minZ: 100,
|
|
148
|
+
wheelPrecision: 100,
|
|
149
|
+
panningSensibility: 2500,
|
|
150
|
+
pinchPrecision: 200,
|
|
151
|
+
};
|
|
152
|
+
CameraManager._DEFAULT_AUTOFOCUS_RADIUS_FACTOR = 1;
|
|
153
|
+
CameraManager._DEFAULT_CAM_SPEED_MS = 250;
|
|
154
|
+
//# sourceMappingURL=cameraManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cameraManager.js","sourceRoot":"","sources":["../../../src/manager/cameraManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAQkB;AAwBlB;;GAEG;AACH,MAAa,aAAa;IAqBxB,gBAAgB;IAChB,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C;;OAEG;IACU,qBAAqB,CAAC,QAA4B;;;YAC7D,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC;YAEpD,IAAI,CAAC,CAAC,YAAY,YAAY,uBAAe,CAAC,EAAE;gBAC9C,MAAM,IAAI,KAAK,CAAC,gBAAgB,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,YAAY,EAAE,mDAAmD,CAAC,CAAC;aAClH;YAED,uFAAuF;YACvF,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,CAAC,CAAC;YAC1E,wDAAwD;YACxD,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,mBAAW,CAAC,cAAc,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC;YAE5F,MAAM,MAAM,GAAG,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC;YAClD,MAAM,MAAM,GAAG,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC;YAElD,oGAAoG;YACpG,YAAY,CAAC,gBAAgB,GAAG,MAAM,CAAC;YAEvC,sBAAsB;YACtB,uEAAuE;YACvE,YAAY,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,aAAa,CAAC,oBAAoB,CA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,CAAC,EAAE,CAAC,GAAG,GAAG;IAC1B,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,IAAI,eAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;CAC7B,CAAC;AAEwB,kCAAoB,GAAG;IAC/C,IAAI,EAAE,GAAG;IACT,cAAc,EAAE,GAAG;IACnB,kBAAkB,EAAE,IAAI;IACxB,cAAc,EAAE,GAAG;CACpB,CAAC;AAEwB,8CAAgC,GAAG,CAAC,CAAC;AACrC,mCAAqB,GAAG,GAAG,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { AxesViewer, BoundingSphere, Color3, IInspectorOptions, Scene, TransformNode, Vector3, Viewer } from '../index';
|
|
2
|
+
declare type DebugAxisKeys = 'X' | 'Y' | 'Z';
|
|
3
|
+
declare type DebugAxisConfig = {
|
|
4
|
+
color: Color3;
|
|
5
|
+
position: Vector3;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Manager for debugging functionalities
|
|
9
|
+
*/
|
|
10
|
+
export declare class DebugManager {
|
|
11
|
+
protected viewer: Viewer;
|
|
12
|
+
protected static _DEBUG_AXIS_MAP: Record<DebugAxisKeys, DebugAxisConfig>;
|
|
13
|
+
protected static _WORLD_COORD_ROOT_KEY: string;
|
|
14
|
+
protected static _BOUNDING_SPHERE_KEY: string;
|
|
15
|
+
protected _axesViewer: AxesViewer | null;
|
|
16
|
+
protected _showBoundingSphereForAutofocus: boolean;
|
|
17
|
+
/** @internal */
|
|
18
|
+
constructor(viewer: Viewer);
|
|
19
|
+
/**
|
|
20
|
+
* Assign callback for drawing bounding sphere on autofocusing
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
registerAutofocusStartListener(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Enables the Babylon.js [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
|
|
26
|
+
* Due to the additional size of the inspector, this function is only available in "development" builds!
|
|
27
|
+
*
|
|
28
|
+
* @returns Signalizes if inspector could be loaded
|
|
29
|
+
*/
|
|
30
|
+
showInspector(options?: IInspectorOptions): Promise<boolean>;
|
|
31
|
+
hideInspector(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Show world coordinate system with given dimension.\
|
|
34
|
+
* This is especially usefull when working on project with tricky positioning. (e.g. clones)
|
|
35
|
+
*/
|
|
36
|
+
showWorldCoordinates(dimension: number): void;
|
|
37
|
+
hideWorldCoordinates(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Draws a wireframe bounding sphere on the next call of {@link CameraManager.autofocusActiveCamera}.\
|
|
40
|
+
* This is usefull for checking which parts of the scene get centered.
|
|
41
|
+
*/
|
|
42
|
+
showBoundingSphereForAutofocus(): void;
|
|
43
|
+
hideBoundingSphereForAutofocus(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Adjust and enhance coordinate axes to fulfill our needs.
|
|
46
|
+
* - moves nodes into common root
|
|
47
|
+
* - adds text node
|
|
48
|
+
*/
|
|
49
|
+
protected static _prepareWorldCoordinateAxis(text: 'X' | 'Y' | 'Z', axis: TransformNode, root: TransformNode, dimension: number, utilityLayerScene: Scene): void;
|
|
50
|
+
/**
|
|
51
|
+
* Calculate factor for creating world coordinate axes with exactly one unit in length
|
|
52
|
+
*/
|
|
53
|
+
protected static _getWorldCoordinatesAxesUnifyFactor(): number;
|
|
54
|
+
/**
|
|
55
|
+
* Visualize bounding sphere which is used to zoom in via `autofocusActiveCamera` function
|
|
56
|
+
*/
|
|
57
|
+
protected _drawBoundingSphereForAutofocus(boundingSphere: BoundingSphere): void;
|
|
58
|
+
protected _removeBoundingSphereForAutofocus(): void;
|
|
59
|
+
}
|
|
60
|
+
export {};
|