@combeenation/3d-viewer 18.4.0 → 18.5.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/manager/dimension-line-manager.d.ts +2 -16
- package/dist/lib-cjs/manager/dimension-line-manager.js +4 -6
- package/dist/lib-cjs/manager/dimension-line-manager.js.map +1 -1
- package/dist/lib-cjs/manager/html-anchor-manager.d.ts +51 -10
- package/dist/lib-cjs/manager/html-anchor-manager.js +22 -11
- package/dist/lib-cjs/manager/html-anchor-manager.js.map +1 -1
- package/package.json +1 -1
- package/src/manager/dimension-line-manager.ts +7 -23
- package/src/manager/html-anchor-manager.ts +75 -21
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Color3, LinesMesh, TransformNode, Vector3, Viewer } from '../index';
|
|
1
|
+
import { Color3, HtmlAnchorOptions, LinesMesh, TransformNode, Vector3, Viewer } from '../index';
|
|
2
2
|
/**
|
|
3
3
|
* Options for dimension line creation
|
|
4
4
|
*/
|
|
5
|
-
export declare type DimensionLineOptions = {
|
|
5
|
+
export declare type DimensionLineOptions = Pick<HtmlAnchorOptions, 'occlusion' | 'scaling'> & {
|
|
6
6
|
/**
|
|
7
7
|
* Default: `Color3.Black()`
|
|
8
8
|
*/
|
|
@@ -25,20 +25,6 @@ export declare type DimensionLineOptions = {
|
|
|
25
25
|
* Default: no parent node set
|
|
26
26
|
*/
|
|
27
27
|
parentNode?: TransformNode;
|
|
28
|
-
/**
|
|
29
|
-
* `true`: html elements can be occluded by other meshes
|
|
30
|
-
* `false`: html elements will always be shown in front of the scene
|
|
31
|
-
*
|
|
32
|
-
* Default: `false`
|
|
33
|
-
*/
|
|
34
|
-
hideIfOccluded: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* `true`: html element size is relative to camera distance, just like a "normal" 3d object
|
|
37
|
-
* `false`: html element size remains constant
|
|
38
|
-
*
|
|
39
|
-
* Default: `false`
|
|
40
|
-
*/
|
|
41
|
-
scaleWithCameraDistance: boolean;
|
|
42
28
|
/**
|
|
43
29
|
* Optional callback for label text creation.\
|
|
44
30
|
* Provides calculated length from `startPoint` and `endPoint` as parameter in meters.
|
|
@@ -13,8 +13,6 @@ class DimensionLineManager {
|
|
|
13
13
|
this._defaultLineOptions = {
|
|
14
14
|
lineColor: index_1.Color3.Black(),
|
|
15
15
|
closingLineHeight: 0.05,
|
|
16
|
-
hideIfOccluded: false,
|
|
17
|
-
scaleWithCameraDistance: false,
|
|
18
16
|
labelTextCb: (lengthM) => {
|
|
19
17
|
const lengthRounded = Math.round(lengthM * 1000 * 100) / 100;
|
|
20
18
|
return `${lengthRounded} mm`;
|
|
@@ -50,7 +48,7 @@ class DimensionLineManager {
|
|
|
50
48
|
}
|
|
51
49
|
const resDefaultOptions = Object.assign({}, this._defaultLineOptions);
|
|
52
50
|
(0, lodash_es_1.merge)(resDefaultOptions, options);
|
|
53
|
-
const { lineColor, closingLineHeight, closingLineDirection: closingLineDirectionIn, parentNode,
|
|
51
|
+
const { lineColor, closingLineHeight, closingLineDirection: closingLineDirectionIn, parentNode, occlusion, scaling, labelTextCb, labelCssClass, } = resDefaultOptions;
|
|
54
52
|
let closingLineDirection = closingLineDirectionIn;
|
|
55
53
|
if (!closingLineDirection) {
|
|
56
54
|
// evaluate closing line direction if not given
|
|
@@ -71,7 +69,7 @@ class DimensionLineManager {
|
|
|
71
69
|
linesMesh.position = lineCenter;
|
|
72
70
|
linesMesh.color = lineColor;
|
|
73
71
|
// rendering group id 1 reserved for html anchor meshes, which are required for occlusion checking
|
|
74
|
-
linesMesh.renderingGroupId = hideIfOccluded ? 0 : 2;
|
|
72
|
+
linesMesh.renderingGroupId = (occlusion === null || occlusion === void 0 ? void 0 : occlusion.hideIfOccluded) ? 0 : 2;
|
|
75
73
|
// tag can be used to exclude dimension lines from autofocus or gltf export
|
|
76
74
|
index_1.Tags.AddTagsTo(linesMesh, DimensionLineManager.DIMENSION_LINE_KEY);
|
|
77
75
|
if (parentNode) {
|
|
@@ -102,8 +100,8 @@ class DimensionLineManager {
|
|
|
102
100
|
this.viewer.htmlAnchorManager.addHtmlAnchor(name, span, index_1.Vector3.Zero(), {
|
|
103
101
|
parentNode: linesMesh,
|
|
104
102
|
group: DimensionLineManager.DIMENSION_LINE_KEY,
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
occlusion,
|
|
104
|
+
scaling,
|
|
107
105
|
});
|
|
108
106
|
this._dimensionLineObjs[name] = { linesMesh, htmlLabelName };
|
|
109
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dimension-line-manager.js","sourceRoot":"","sources":["../../../src/manager/dimension-line-manager.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"dimension-line-manager.js","sourceRoot":"","sources":["../../../src/manager/dimension-line-manager.ts"],"names":[],"mappings":";;;AAAA,oCAAmH;AACnH,yCAAkC;AA0ClC;;GAEG;AACH,MAAa,oBAAoB;IA+B/B,gBAAgB;IAChB,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QA7BjC,wBAAmB,GAAyB;YACpD,SAAS,EAAE,cAAM,CAAC,KAAK,EAAE;YACzB,iBAAiB,EAAE,IAAI;YACvB,WAAW,EAAE,CAAC,OAAO,EAAU,EAAE;gBAC/B,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;gBAC7D,OAAO,GAAG,aAAa,KAAK,CAAC;YAC/B,CAAC;YACD,aAAa,EAAE,EAAE;SAClB,CAAC;QAEF,uEAAuE;QACvE,sDAAsD;QAC5C,uBAAkB,GAKxB,EAAE,CAAC;IAYuC,CAAC;IAV/C;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAAC,IAAmB;QACnD,OAAO,YAAI,CAAC,YAAY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E;YACtE,UAAU,EAAE,SAAS;YACrB,KAAK,EAAE,oBAAoB,CAAC,kBAAkB;YAC9C,SAAS;YACT,OAAO;SACR,CAAC,CAAC;QAEH,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;IAC/D,CAAC;IAED;;OAEG;IACI,mBAAmB,CAAC,IAAY;QACrC,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,aAAa,EAAE;YAClB,OAAO,CAAC,IAAI,CAAC,mBAAmB,IAAI,kBAAkB,CAAC,CAAC;YACxD,OAAO;SACR;QAED,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACrD,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAE7C,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACI,uBAAuB;QAC5B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YACzD,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC;;AA3JH,oDA4JC;AA3JwB,uCAAkB,GAAG,UAAU,CAAC"}
|
|
@@ -1,4 +1,51 @@
|
|
|
1
1
|
import { AbstractMesh, ArcRotateCamera, Camera, NodeDescription, ScreenshotSize, StandardMaterial, TransformNode, Vector3, Viewer } from '..';
|
|
2
|
+
export declare type HtmlAnchorOcclusionOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* `true`: html elements can be occluded by other meshes
|
|
5
|
+
* `false`: html elements will always be shown in front of the scene
|
|
6
|
+
*
|
|
7
|
+
* Default: `false`
|
|
8
|
+
*/
|
|
9
|
+
hideIfOccluded: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Size of dummy mesh for occlusion check
|
|
12
|
+
* Smaller values result in a more precise occlusion check around the center of the anchor.
|
|
13
|
+
* Too small values can lead to flickering of the html element.
|
|
14
|
+
*
|
|
15
|
+
* Default: 0.01
|
|
16
|
+
*/
|
|
17
|
+
anchorMeshSize?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare type HtmlAnchorScalingOptions = {
|
|
20
|
+
/**
|
|
21
|
+
* `true`: html element size is relative to camera distance, just like a "normal" 3d object
|
|
22
|
+
* `false`: html element size remains constant and `referenceScale`, `minScale` and `maxScale` will have no effect
|
|
23
|
+
*
|
|
24
|
+
* Default: `false`
|
|
25
|
+
*/
|
|
26
|
+
scaleWithCameraDistance: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Basis factor for converting camera distance in Babylon.js units to pixels.
|
|
29
|
+
* Find a suitable value for your project by trial and error, whereas larger values will make the html anchor elements
|
|
30
|
+
* larger as well.
|
|
31
|
+
*
|
|
32
|
+
* Default: 1
|
|
33
|
+
*/
|
|
34
|
+
referenceScale?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Can be used to limit the calculated scale value so that a html anchor element is still readable/clickable if the
|
|
37
|
+
* camera is far zoomed out.
|
|
38
|
+
*
|
|
39
|
+
* Default: undefined (no limit)
|
|
40
|
+
*/
|
|
41
|
+
minScale?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Max limit cap when zooming the camera in to avoid html anchor elements getting too large.
|
|
44
|
+
*
|
|
45
|
+
* Default: undefined (no limit)
|
|
46
|
+
*/
|
|
47
|
+
maxScale?: number;
|
|
48
|
+
};
|
|
2
49
|
export declare type HtmlAnchorOptions = {
|
|
3
50
|
/**
|
|
4
51
|
* Associated anchor mesh will be created underneath this parent node.\
|
|
@@ -10,19 +57,13 @@ export declare type HtmlAnchorOptions = {
|
|
|
10
57
|
*/
|
|
11
58
|
group?: string;
|
|
12
59
|
/**
|
|
13
|
-
*
|
|
14
|
-
* `false`: html elements will always be shown in front of the scene
|
|
15
|
-
*
|
|
16
|
-
* Default: `false`
|
|
60
|
+
* Occlusion options, see {@link HtmlAnchorOcclusionOptions}
|
|
17
61
|
*/
|
|
18
|
-
|
|
62
|
+
occlusion?: HtmlAnchorOcclusionOptions;
|
|
19
63
|
/**
|
|
20
|
-
*
|
|
21
|
-
* `false`: html element size remains constant
|
|
22
|
-
*
|
|
23
|
-
* Default: `false`
|
|
64
|
+
* Scaling options, see {@link HtmlAnchorScalingOptions}
|
|
24
65
|
*/
|
|
25
|
-
|
|
66
|
+
scaling?: HtmlAnchorScalingOptions;
|
|
26
67
|
/**
|
|
27
68
|
* Activates/deactivates `pointer-events` CSS class of anchor element.\
|
|
28
69
|
* Set this to `true` if the html element should be interactive (e.g. button)
|
|
@@ -61,6 +61,7 @@ class HtmlAnchorManager {
|
|
|
61
61
|
* mesh within the scene.
|
|
62
62
|
*/
|
|
63
63
|
addHtmlAnchor(name, htmlElement, position, options) {
|
|
64
|
+
var _a;
|
|
64
65
|
if (!this.viewer.canvas) {
|
|
65
66
|
return;
|
|
66
67
|
}
|
|
@@ -68,7 +69,7 @@ class HtmlAnchorManager {
|
|
|
68
69
|
console.warn(`Html anchor "${name}" already exists`);
|
|
69
70
|
return;
|
|
70
71
|
}
|
|
71
|
-
const { parentNode, enablePointerEvents } = options !== null && options !== void 0 ? options : {};
|
|
72
|
+
const { parentNode, occlusion, enablePointerEvents } = options !== null && options !== void 0 ? options : {};
|
|
72
73
|
// create a parent for the input html element, which will receive the updated style and transform data
|
|
73
74
|
// in this way the original input element remains untouched
|
|
74
75
|
const parentHtmlElement = document.createElement('div');
|
|
@@ -85,7 +86,9 @@ class HtmlAnchorManager {
|
|
|
85
86
|
this.viewer.canvas.insertAdjacentElement('afterend', parentHtmlElement);
|
|
86
87
|
// NOTE: creates a sphere with fixed size, which could be problematic in scene with "strange" dimensions
|
|
87
88
|
// add a property for the sphere size if required
|
|
88
|
-
const anchorMesh = __1.MeshBuilder.CreateSphere(`${HtmlAnchorManager._HTML_ANCHOR_KEY}_${name}`, {
|
|
89
|
+
const anchorMesh = __1.MeshBuilder.CreateSphere(`${HtmlAnchorManager._HTML_ANCHOR_KEY}_${name}`, {
|
|
90
|
+
diameter: (_a = occlusion === null || occlusion === void 0 ? void 0 : occlusion.anchorMeshSize) !== null && _a !== void 0 ? _a : 0.01,
|
|
91
|
+
});
|
|
89
92
|
anchorMesh.position = position;
|
|
90
93
|
anchorMesh.parent = parentNode !== null && parentNode !== void 0 ? parentNode : null;
|
|
91
94
|
// anchor mesh will be invisible, we only need it for positioning and occlusion check
|
|
@@ -194,26 +197,34 @@ class HtmlAnchorManager {
|
|
|
194
197
|
return anchorKeys;
|
|
195
198
|
}
|
|
196
199
|
_updateHtmlAnchor(parentHtmlElement, anchorMesh, camera, width, height, baseScale, useRayHitTestForOcclusionCheck, options, excludeNodes) {
|
|
197
|
-
const {
|
|
200
|
+
const { occlusion, scaling } = options !== null && options !== void 0 ? options : {};
|
|
201
|
+
const { hideIfOccluded } = occlusion !== null && occlusion !== void 0 ? occlusion : {};
|
|
202
|
+
const { scaleWithCameraDistance, referenceScale, minScale, maxScale } = scaling !== null && scaling !== void 0 ? scaling : {};
|
|
198
203
|
const viewMatrix = camera.getViewMatrix();
|
|
199
204
|
const projectionMatrix = camera.getProjectionMatrix();
|
|
200
205
|
const transformMatrix = viewMatrix.multiply(projectionMatrix);
|
|
201
206
|
// convert into 2d space
|
|
202
207
|
const vertexScreenCoords = __1.Vector3.Project(__1.Vector3.Zero(), anchorMesh.getWorldMatrix(), transformMatrix, new __1.Viewport(0, 0, width, height));
|
|
208
|
+
const meshWorldPos = anchorMesh.getAbsolutePosition();
|
|
209
|
+
// calculate camera world position manually, as there is no help function like for meshes
|
|
210
|
+
const camWorldMatrix = camera.computeWorldMatrix();
|
|
211
|
+
const camWorldPos = camWorldMatrix.getTranslation();
|
|
212
|
+
const distance = __1.Vector3.Distance(meshWorldPos, camWorldPos);
|
|
213
|
+
const camYWindow = distance * Math.tan(camera.fov / 2);
|
|
203
214
|
// base scale is used if width and height don't equal the viewer canvas, which is the case for screenshots
|
|
204
215
|
let scale = baseScale;
|
|
205
216
|
if (scaleWithCameraDistance) {
|
|
206
|
-
const meshWorldPos = anchorMesh.getAbsolutePosition();
|
|
207
|
-
// calculate camera world position manually, as there is no help function like for meshes
|
|
208
|
-
const camWorldMatrix = camera.computeWorldMatrix();
|
|
209
|
-
const camWorldPos = camWorldMatrix.getTranslation();
|
|
210
|
-
const distance = __1.Vector3.Distance(meshWorldPos, camWorldPos);
|
|
211
|
-
const frustumSlopeY = Math.tan(camera.fov / 2);
|
|
212
217
|
// if the distance from camera to mesh gets larger, the html elements scaling will be decreased
|
|
213
218
|
// we also consider the cameras FOV, so scale 1 means, that the resulting vertical frustum of the camera
|
|
214
219
|
// distance equals 1
|
|
215
|
-
|
|
216
|
-
|
|
220
|
+
scale *= (referenceScale !== null && referenceScale !== void 0 ? referenceScale : 1) / camYWindow;
|
|
221
|
+
// apply scale caps
|
|
222
|
+
if (minScale !== undefined) {
|
|
223
|
+
scale = Math.max(scale, minScale);
|
|
224
|
+
}
|
|
225
|
+
if (maxScale !== undefined) {
|
|
226
|
+
scale = Math.min(scale, maxScale);
|
|
227
|
+
}
|
|
217
228
|
}
|
|
218
229
|
const elementXOffset = (parentHtmlElement.offsetWidth * scale) / 2;
|
|
219
230
|
const elementYOffset = (parentHtmlElement.offsetHeight * scale) / 2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-anchor-manager.js","sourceRoot":"","sources":["../../../src/manager/html-anchor-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0BAcY;AACZ,iEAAiG;AACjG,yDAAiE;AACjE,8DAAsC;
|
|
1
|
+
{"version":3,"file":"html-anchor-manager.js","sourceRoot":"","sources":["../../../src/manager/html-anchor-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0BAcY;AACZ,iEAAiG;AACjG,yDAAiE;AACjE,8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Q,CAAC,CAAC;gBAC1D,MAAM,GAAG,GAAG,IAAI,OAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;gBACnD,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CACvC,GAAG,EACH,IAAI,CAAC,EAAE,CAAC,CAAC,IAAA,oCAAsB,EAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,EACxF,KAAK,CACN,CAAC;gBACF,UAAU,GAAG,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,MAAK,UAAU,CAAC;aAC7C;iBAAM;gBACL,uCAAuC;gBACvC,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC;aACpC;SACF;QAED,iBAAiB,CAAC,KAAK,CAAC,OAAO,GAAG,YAAY,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAC5E,CAAC;IAES,8BAA8B;QACtC,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC5B,OAAO,IAAI,CAAC,mBAAmB,CAAC;SACjC;QAED,IAAI,CAAC,mBAAmB,GAAG,IAAI,oBAAgB,CAAC,gBAAgB,CAAC,CAAC;QAClE,IAAI,CAAC,mBAAmB,CAAC,KAAK,GAAG,CAAC,CAAC;QACnC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;;AAxUH,8CAyUC;AAxU2B,kCAAgB,GAAG,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Color3, LinesMesh, MeshBuilder, Tags, TransformNode, Vector3, Viewer } from '../index';
|
|
1
|
+
import { Color3, HtmlAnchorOptions, LinesMesh, MeshBuilder, Tags, TransformNode, Vector3, Viewer } from '../index';
|
|
2
2
|
import { merge } from 'lodash-es';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Options for dimension line creation
|
|
6
6
|
*/
|
|
7
|
-
export type DimensionLineOptions = {
|
|
7
|
+
export type DimensionLineOptions = Pick<HtmlAnchorOptions, 'occlusion' | 'scaling'> & {
|
|
8
8
|
/**
|
|
9
9
|
* Default: `Color3.Black()`
|
|
10
10
|
*/
|
|
@@ -27,20 +27,6 @@ export type DimensionLineOptions = {
|
|
|
27
27
|
* Default: no parent node set
|
|
28
28
|
*/
|
|
29
29
|
parentNode?: TransformNode;
|
|
30
|
-
/**
|
|
31
|
-
* `true`: html elements can be occluded by other meshes
|
|
32
|
-
* `false`: html elements will always be shown in front of the scene
|
|
33
|
-
*
|
|
34
|
-
* Default: `false`
|
|
35
|
-
*/
|
|
36
|
-
hideIfOccluded: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* `true`: html element size is relative to camera distance, just like a "normal" 3d object
|
|
39
|
-
* `false`: html element size remains constant
|
|
40
|
-
*
|
|
41
|
-
* Default: `false`
|
|
42
|
-
*/
|
|
43
|
-
scaleWithCameraDistance: boolean;
|
|
44
30
|
/**
|
|
45
31
|
* Optional callback for label text creation.\
|
|
46
32
|
* Provides calculated length from `startPoint` and `endPoint` as parameter in meters.
|
|
@@ -64,8 +50,6 @@ export class DimensionLineManager {
|
|
|
64
50
|
protected _defaultLineOptions: DimensionLineOptions = {
|
|
65
51
|
lineColor: Color3.Black(),
|
|
66
52
|
closingLineHeight: 0.05,
|
|
67
|
-
hideIfOccluded: false,
|
|
68
|
-
scaleWithCameraDistance: false,
|
|
69
53
|
labelTextCb: (lengthM): string => {
|
|
70
54
|
const lengthRounded = Math.round(lengthM * 1000 * 100) / 100;
|
|
71
55
|
return `${lengthRounded} mm`;
|
|
@@ -123,8 +107,8 @@ export class DimensionLineManager {
|
|
|
123
107
|
closingLineHeight,
|
|
124
108
|
closingLineDirection: closingLineDirectionIn,
|
|
125
109
|
parentNode,
|
|
126
|
-
|
|
127
|
-
|
|
110
|
+
occlusion,
|
|
111
|
+
scaling,
|
|
128
112
|
labelTextCb,
|
|
129
113
|
labelCssClass,
|
|
130
114
|
} = resDefaultOptions;
|
|
@@ -151,7 +135,7 @@ export class DimensionLineManager {
|
|
|
151
135
|
linesMesh.position = lineCenter;
|
|
152
136
|
linesMesh.color = lineColor;
|
|
153
137
|
// rendering group id 1 reserved for html anchor meshes, which are required for occlusion checking
|
|
154
|
-
linesMesh.renderingGroupId = hideIfOccluded ? 0 : 2;
|
|
138
|
+
linesMesh.renderingGroupId = occlusion?.hideIfOccluded ? 0 : 2;
|
|
155
139
|
// tag can be used to exclude dimension lines from autofocus or gltf export
|
|
156
140
|
Tags.AddTagsTo(linesMesh, DimensionLineManager.DIMENSION_LINE_KEY);
|
|
157
141
|
if (parentNode) {
|
|
@@ -185,8 +169,8 @@ export class DimensionLineManager {
|
|
|
185
169
|
this.viewer.htmlAnchorManager.addHtmlAnchor(name, span, Vector3.Zero(), {
|
|
186
170
|
parentNode: linesMesh,
|
|
187
171
|
group: DimensionLineManager.DIMENSION_LINE_KEY,
|
|
188
|
-
|
|
189
|
-
|
|
172
|
+
occlusion,
|
|
173
|
+
scaling,
|
|
190
174
|
});
|
|
191
175
|
|
|
192
176
|
this._dimensionLineObjs[name] = { linesMesh, htmlLabelName };
|
|
@@ -17,6 +17,55 @@ import { getInternalMetadataValue, setInternalMetadataValue } from '../internal/
|
|
|
17
17
|
import { nodeMatchesAnyCriteria } from '../internal/node-helper';
|
|
18
18
|
import html2canvas from 'html2canvas';
|
|
19
19
|
|
|
20
|
+
export type HtmlAnchorOcclusionOptions = {
|
|
21
|
+
/**
|
|
22
|
+
* `true`: html elements can be occluded by other meshes
|
|
23
|
+
* `false`: html elements will always be shown in front of the scene
|
|
24
|
+
*
|
|
25
|
+
* Default: `false`
|
|
26
|
+
*/
|
|
27
|
+
hideIfOccluded: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Size of dummy mesh for occlusion check
|
|
30
|
+
* Smaller values result in a more precise occlusion check around the center of the anchor.
|
|
31
|
+
* Too small values can lead to flickering of the html element.
|
|
32
|
+
*
|
|
33
|
+
* Default: 0.01
|
|
34
|
+
*/
|
|
35
|
+
anchorMeshSize?: number;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type HtmlAnchorScalingOptions = {
|
|
39
|
+
/**
|
|
40
|
+
* `true`: html element size is relative to camera distance, just like a "normal" 3d object
|
|
41
|
+
* `false`: html element size remains constant and `referenceScale`, `minScale` and `maxScale` will have no effect
|
|
42
|
+
*
|
|
43
|
+
* Default: `false`
|
|
44
|
+
*/
|
|
45
|
+
scaleWithCameraDistance: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Basis factor for converting camera distance in Babylon.js units to pixels.
|
|
48
|
+
* Find a suitable value for your project by trial and error, whereas larger values will make the html anchor elements
|
|
49
|
+
* larger as well.
|
|
50
|
+
*
|
|
51
|
+
* Default: 1
|
|
52
|
+
*/
|
|
53
|
+
referenceScale?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Can be used to limit the calculated scale value so that a html anchor element is still readable/clickable if the
|
|
56
|
+
* camera is far zoomed out.
|
|
57
|
+
*
|
|
58
|
+
* Default: undefined (no limit)
|
|
59
|
+
*/
|
|
60
|
+
minScale?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Max limit cap when zooming the camera in to avoid html anchor elements getting too large.
|
|
63
|
+
*
|
|
64
|
+
* Default: undefined (no limit)
|
|
65
|
+
*/
|
|
66
|
+
maxScale?: number;
|
|
67
|
+
};
|
|
68
|
+
|
|
20
69
|
export type HtmlAnchorOptions = {
|
|
21
70
|
/**
|
|
22
71
|
* Associated anchor mesh will be created underneath this parent node.\
|
|
@@ -28,19 +77,13 @@ export type HtmlAnchorOptions = {
|
|
|
28
77
|
*/
|
|
29
78
|
group?: string;
|
|
30
79
|
/**
|
|
31
|
-
*
|
|
32
|
-
* `false`: html elements will always be shown in front of the scene
|
|
33
|
-
*
|
|
34
|
-
* Default: `false`
|
|
80
|
+
* Occlusion options, see {@link HtmlAnchorOcclusionOptions}
|
|
35
81
|
*/
|
|
36
|
-
|
|
82
|
+
occlusion?: HtmlAnchorOcclusionOptions;
|
|
37
83
|
/**
|
|
38
|
-
*
|
|
39
|
-
* `false`: html element size remains constant
|
|
40
|
-
*
|
|
41
|
-
* Default: `false`
|
|
84
|
+
* Scaling options, see {@link HtmlAnchorScalingOptions}
|
|
42
85
|
*/
|
|
43
|
-
|
|
86
|
+
scaling?: HtmlAnchorScalingOptions;
|
|
44
87
|
/**
|
|
45
88
|
* Activates/deactivates `pointer-events` CSS class of anchor element.\
|
|
46
89
|
* Set this to `true` if the html element should be interactive (e.g. button)
|
|
@@ -123,7 +166,7 @@ export class HtmlAnchorManager {
|
|
|
123
166
|
return;
|
|
124
167
|
}
|
|
125
168
|
|
|
126
|
-
const { parentNode, enablePointerEvents } = options ?? {};
|
|
169
|
+
const { parentNode, occlusion, enablePointerEvents } = options ?? {};
|
|
127
170
|
|
|
128
171
|
// create a parent for the input html element, which will receive the updated style and transform data
|
|
129
172
|
// in this way the original input element remains untouched
|
|
@@ -142,7 +185,9 @@ export class HtmlAnchorManager {
|
|
|
142
185
|
|
|
143
186
|
// NOTE: creates a sphere with fixed size, which could be problematic in scene with "strange" dimensions
|
|
144
187
|
// add a property for the sphere size if required
|
|
145
|
-
const anchorMesh = MeshBuilder.CreateSphere(`${HtmlAnchorManager._HTML_ANCHOR_KEY}_${name}`, {
|
|
188
|
+
const anchorMesh = MeshBuilder.CreateSphere(`${HtmlAnchorManager._HTML_ANCHOR_KEY}_${name}`, {
|
|
189
|
+
diameter: occlusion?.anchorMeshSize ?? 0.01,
|
|
190
|
+
});
|
|
146
191
|
anchorMesh.position = position;
|
|
147
192
|
anchorMesh.parent = parentNode ?? null;
|
|
148
193
|
// anchor mesh will be invisible, we only need it for positioning and occlusion check
|
|
@@ -297,7 +342,9 @@ export class HtmlAnchorManager {
|
|
|
297
342
|
options?: HtmlAnchorOptions,
|
|
298
343
|
excludeNodes?: NodeDescription[]
|
|
299
344
|
): void {
|
|
300
|
-
const {
|
|
345
|
+
const { occlusion, scaling } = options ?? {};
|
|
346
|
+
const { hideIfOccluded } = occlusion ?? {};
|
|
347
|
+
const { scaleWithCameraDistance, referenceScale, minScale, maxScale } = scaling ?? {};
|
|
301
348
|
|
|
302
349
|
const viewMatrix = camera.getViewMatrix();
|
|
303
350
|
const projectionMatrix = camera.getProjectionMatrix();
|
|
@@ -311,20 +358,27 @@ export class HtmlAnchorManager {
|
|
|
311
358
|
new Viewport(0, 0, width, height)
|
|
312
359
|
);
|
|
313
360
|
|
|
361
|
+
const meshWorldPos = anchorMesh.getAbsolutePosition();
|
|
362
|
+
// calculate camera world position manually, as there is no help function like for meshes
|
|
363
|
+
const camWorldMatrix = camera.computeWorldMatrix();
|
|
364
|
+
const camWorldPos = camWorldMatrix.getTranslation();
|
|
365
|
+
const distance = Vector3.Distance(meshWorldPos, camWorldPos);
|
|
366
|
+
const camYWindow = distance * Math.tan(camera.fov / 2);
|
|
367
|
+
|
|
314
368
|
// base scale is used if width and height don't equal the viewer canvas, which is the case for screenshots
|
|
315
369
|
let scale = baseScale;
|
|
316
370
|
if (scaleWithCameraDistance) {
|
|
317
|
-
const meshWorldPos = anchorMesh.getAbsolutePosition();
|
|
318
|
-
// calculate camera world position manually, as there is no help function like for meshes
|
|
319
|
-
const camWorldMatrix = camera.computeWorldMatrix();
|
|
320
|
-
const camWorldPos = camWorldMatrix.getTranslation();
|
|
321
|
-
const distance = Vector3.Distance(meshWorldPos, camWorldPos);
|
|
322
|
-
const frustumSlopeY = Math.tan(camera.fov / 2);
|
|
323
371
|
// if the distance from camera to mesh gets larger, the html elements scaling will be decreased
|
|
324
372
|
// we also consider the cameras FOV, so scale 1 means, that the resulting vertical frustum of the camera
|
|
325
373
|
// distance equals 1
|
|
326
|
-
|
|
327
|
-
|
|
374
|
+
scale *= (referenceScale ?? 1) / camYWindow;
|
|
375
|
+
// apply scale caps
|
|
376
|
+
if (minScale !== undefined) {
|
|
377
|
+
scale = Math.max(scale, minScale);
|
|
378
|
+
}
|
|
379
|
+
if (maxScale !== undefined) {
|
|
380
|
+
scale = Math.min(scale, maxScale);
|
|
381
|
+
}
|
|
328
382
|
}
|
|
329
383
|
|
|
330
384
|
const elementXOffset = (parentHtmlElement.offsetWidth * scale) / 2;
|