@shapediver/viewer.rendering-engine.intersection-restriction-engine 3.16.8 → 3.16.9
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/api/implementation/AbstractRestrictionApi.d.ts +12 -12
- package/dist/api/implementation/AbstractRestrictionApi.js +46 -46
- package/dist/api/implementation/AbstractRestrictionApi.js.map +1 -1
- package/dist/api/implementation/AbstractSnapRestrictionApi.d.ts +12 -12
- package/dist/api/implementation/AbstractSnapRestrictionApi.js +46 -46
- package/dist/api/implementation/AbstractSnapRestrictionApi.js.map +1 -1
- package/dist/api/implementation/camera_plane/CameraPlaneRestrictionApi.d.ts +6 -6
- package/dist/api/implementation/camera_plane/CameraPlaneRestrictionApi.js +23 -23
- package/dist/api/implementation/camera_plane/CameraPlaneRestrictionApi.js.map +1 -1
- package/dist/api/implementation/geometry/GeometryRestrictionApi.d.ts +14 -14
- package/dist/api/implementation/geometry/GeometryRestrictionApi.js +53 -53
- package/dist/api/implementation/geometry/GeometryRestrictionApi.js.map +1 -1
- package/dist/api/implementation/line/LineRestrictionApi.d.ts +10 -10
- package/dist/api/implementation/line/LineRestrictionApi.js +39 -39
- package/dist/api/implementation/line/LineRestrictionApi.js.map +1 -1
- package/dist/api/implementation/plane/PlaneRestrictionApi.d.ts +19 -19
- package/dist/api/implementation/plane/PlaneRestrictionApi.js +66 -66
- package/dist/api/implementation/plane/PlaneRestrictionApi.js.map +1 -1
- package/dist/api/implementation/plane/snap/AngularRestrictionApi.d.ts +9 -9
- package/dist/api/implementation/plane/snap/AngularRestrictionApi.js +39 -39
- package/dist/api/implementation/plane/snap/AngularRestrictionApi.js.map +1 -1
- package/dist/api/implementation/plane/snap/AxisRestrictionApi.d.ts +6 -6
- package/dist/api/implementation/plane/snap/AxisRestrictionApi.js +23 -23
- package/dist/api/implementation/plane/snap/AxisRestrictionApi.js.map +1 -1
- package/dist/api/implementation/plane/snap/GridRestrictionApi.d.ts +9 -9
- package/dist/api/implementation/plane/snap/GridRestrictionApi.js +39 -39
- package/dist/api/implementation/plane/snap/GridRestrictionApi.js.map +1 -1
- package/dist/api/implementation/point/PointRestrictionApi.d.ts +9 -9
- package/dist/api/implementation/point/PointRestrictionApi.js +36 -36
- package/dist/api/implementation/point/PointRestrictionApi.js.map +1 -1
- package/dist/api/interfaces/IRestrictionApi.d.ts +10 -10
- package/dist/api/interfaces/IRestrictionApi.js +2 -2
- package/dist/api/interfaces/ISnapRestrictionApi.d.ts +12 -12
- package/dist/api/interfaces/ISnapRestrictionApi.js +2 -2
- package/dist/implementation/EventManager.d.ts +25 -25
- package/dist/implementation/EventManager.d.ts.map +1 -1
- package/dist/implementation/EventManager.js +62 -62
- package/dist/implementation/EventManager.js.map +1 -1
- package/dist/implementation/GeometryMathManager.d.ts +87 -87
- package/dist/implementation/GeometryMathManager.js +260 -260
- package/dist/implementation/GeometryMathManager.js.map +1 -1
- package/dist/implementation/RestrictionManager.d.ts +28 -28
- package/dist/implementation/RestrictionManager.js +323 -323
- package/dist/implementation/RestrictionManager.js.map +1 -1
- package/dist/implementation/restrictions/AbstractRestriction.d.ts +42 -42
- package/dist/implementation/restrictions/AbstractRestriction.js +164 -154
- package/dist/implementation/restrictions/AbstractRestriction.js.map +1 -1
- package/dist/implementation/restrictions/AbstractSnapRestriction.d.ts +35 -35
- package/dist/implementation/restrictions/AbstractSnapRestriction.js +150 -140
- package/dist/implementation/restrictions/AbstractSnapRestriction.js.map +1 -1
- package/dist/implementation/restrictions/RestrictionsHelper.d.ts +10 -10
- package/dist/implementation/restrictions/RestrictionsHelper.d.ts.map +1 -1
- package/dist/implementation/restrictions/RestrictionsHelper.js +50 -50
- package/dist/implementation/restrictions/RestrictionsHelper.js.map +1 -1
- package/dist/implementation/restrictions/camera_plane/CameraPlaneRestriction.d.ts +17 -17
- package/dist/implementation/restrictions/camera_plane/CameraPlaneRestriction.js +62 -62
- package/dist/implementation/restrictions/camera_plane/CameraPlaneRestriction.js.map +1 -1
- package/dist/implementation/restrictions/geometry/GeometryRestriction.d.ts +92 -92
- package/dist/implementation/restrictions/geometry/GeometryRestriction.js +410 -400
- package/dist/implementation/restrictions/geometry/GeometryRestriction.js.map +1 -1
- package/dist/implementation/restrictions/line/LineRestriction.d.ts +58 -58
- package/dist/implementation/restrictions/line/LineRestriction.js +291 -281
- package/dist/implementation/restrictions/line/LineRestriction.js.map +1 -1
- package/dist/implementation/restrictions/plane/PlaneRestriction.d.ts +65 -65
- package/dist/implementation/restrictions/plane/PlaneRestriction.js +306 -306
- package/dist/implementation/restrictions/plane/PlaneRestriction.js.map +1 -1
- package/dist/implementation/restrictions/plane/snap/AngularRestriction.d.ts +39 -39
- package/dist/implementation/restrictions/plane/snap/AngularRestriction.d.ts.map +1 -1
- package/dist/implementation/restrictions/plane/snap/AngularRestriction.js +346 -346
- package/dist/implementation/restrictions/plane/snap/AngularRestriction.js.map +1 -1
- package/dist/implementation/restrictions/plane/snap/AxisRestriction.d.ts +27 -27
- package/dist/implementation/restrictions/plane/snap/AxisRestriction.d.ts.map +1 -1
- package/dist/implementation/restrictions/plane/snap/AxisRestriction.js +239 -229
- package/dist/implementation/restrictions/plane/snap/AxisRestriction.js.map +1 -1
- package/dist/implementation/restrictions/plane/snap/GridRestriction.d.ts +39 -39
- package/dist/implementation/restrictions/plane/snap/GridRestriction.d.ts.map +1 -1
- package/dist/implementation/restrictions/plane/snap/GridRestriction.js +318 -308
- package/dist/implementation/restrictions/plane/snap/GridRestriction.js.map +1 -1
- package/dist/implementation/restrictions/point/PointRestriction.d.ts +45 -45
- package/dist/implementation/restrictions/point/PointRestriction.js +166 -156
- package/dist/implementation/restrictions/point/PointRestriction.js.map +1 -1
- package/dist/index.d.ts +29 -29
- package/dist/index.js +37 -37
- package/dist/interfaces/IDragAnchor.d.ts +8 -8
- package/dist/interfaces/IDragAnchor.js +2 -2
- package/dist/interfaces/IRestriction.d.ts +117 -117
- package/dist/interfaces/IRestriction.d.ts.map +1 -1
- package/dist/interfaces/IRestriction.js +23 -23
- package/dist/interfaces/IRestriction.js.map +1 -1
- package/dist/interfaces/IRestrictionManager.d.ts +13 -13
- package/dist/interfaces/IRestrictionManager.js +2 -2
- package/dist/interfaces/ISnapRestriction.d.ts +81 -81
- package/dist/interfaces/ISnapRestriction.d.ts.map +1 -1
- package/dist/interfaces/ISnapRestriction.js +3 -3
- package/package.json +10 -10
|
@@ -1,307 +1,307 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _PlaneRestriction_parentNode, _PlaneRestriction_properties, _PlaneRestriction_viewport, _PlaneRestriction_angularRestriction, _PlaneRestriction_axisRestriction, _PlaneRestriction_cameraId, _PlaneRestriction_gridRestriction, _PlaneRestriction_normal, _PlaneRestriction_origin, _PlaneRestriction_plane, _PlaneRestriction_snapRestrictions, _PlaneRestriction_transformationFromXYPlaneMatrix, _PlaneRestriction_transformationToXYPlaneMatrix, _PlaneRestriction_vectorU, _PlaneRestriction_vectorV;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.PlaneRestriction = void 0;
|
|
16
|
-
const viewer_1 = require("@shapediver/viewer");
|
|
17
|
-
const viewer_shared_math_1 = require("@shapediver/viewer.shared.math");
|
|
18
|
-
const gl_matrix_1 = require("gl-matrix");
|
|
19
|
-
const IRestriction_1 = require("../../../interfaces/IRestriction");
|
|
20
|
-
const AbstractRestriction_1 = require("../AbstractRestriction");
|
|
21
|
-
const AngularRestriction_1 = require("./snap/AngularRestriction");
|
|
22
|
-
const AxisRestriction_1 = require("./snap/AxisRestriction");
|
|
23
|
-
const GridRestriction_1 = require("./snap/GridRestriction");
|
|
24
|
-
// #endregion Type aliases (1)
|
|
25
|
-
// #region Classes (1)
|
|
26
|
-
class PlaneRestriction extends AbstractRestriction_1.AbstractRestriction {
|
|
27
|
-
// #endregion Properties (15)
|
|
28
|
-
// #region Constructors (1)
|
|
29
|
-
constructor(viewport, geometryMathManager, parentNode, id, settings, properties) {
|
|
30
|
-
super(viewport, parentNode, id, properties);
|
|
31
|
-
// #region Properties (15)
|
|
32
|
-
_PlaneRestriction_parentNode.set(this, void 0);
|
|
33
|
-
_PlaneRestriction_properties.set(this, void 0);
|
|
34
|
-
_PlaneRestriction_viewport.set(this, void 0);
|
|
35
|
-
_PlaneRestriction_angularRestriction.set(this, void 0);
|
|
36
|
-
_PlaneRestriction_axisRestriction.set(this, void 0);
|
|
37
|
-
_PlaneRestriction_cameraId.set(this, "");
|
|
38
|
-
_PlaneRestriction_gridRestriction.set(this, void 0);
|
|
39
|
-
_PlaneRestriction_normal.set(this, gl_matrix_1.vec3.create());
|
|
40
|
-
_PlaneRestriction_origin.set(this, gl_matrix_1.vec3.create());
|
|
41
|
-
_PlaneRestriction_plane.set(this, new viewer_shared_math_1.Plane());
|
|
42
|
-
_PlaneRestriction_snapRestrictions.set(this, void 0);
|
|
43
|
-
_PlaneRestriction_transformationFromXYPlaneMatrix.set(this, gl_matrix_1.mat4.create());
|
|
44
|
-
_PlaneRestriction_transformationToXYPlaneMatrix.set(this, gl_matrix_1.mat4.create());
|
|
45
|
-
_PlaneRestriction_vectorU.set(this, gl_matrix_1.vec3.create());
|
|
46
|
-
_PlaneRestriction_vectorV.set(this, gl_matrix_1.vec3.create());
|
|
47
|
-
__classPrivateFieldSet(this, _PlaneRestriction_parentNode, parentNode, "f");
|
|
48
|
-
__classPrivateFieldSet(this, _PlaneRestriction_viewport, viewport, "f");
|
|
49
|
-
__classPrivateFieldSet(this, _PlaneRestriction_cameraId, __classPrivateFieldGet(this, _PlaneRestriction_viewport, "f").camera.id, "f");
|
|
50
|
-
__classPrivateFieldSet(this, _PlaneRestriction_properties, properties, "f");
|
|
51
|
-
// Propagate createHelperObjects to sub-restrictions that don't have
|
|
52
|
-
// an explicit override, so that a single flag on the plane restriction
|
|
53
|
-
// suppresses helper objects for all its child snap restrictions.
|
|
54
|
-
const inheritHelperObjects = (sub) => {
|
|
55
|
-
var _a;
|
|
56
|
-
if (properties.createHelperObjects === undefined)
|
|
57
|
-
return sub;
|
|
58
|
-
if (sub === undefined)
|
|
59
|
-
return { createHelperObjects: properties.createHelperObjects };
|
|
60
|
-
return Object.assign(Object.assign({}, sub), { createHelperObjects: (_a = sub.createHelperObjects) !== null && _a !== void 0 ? _a : properties.createHelperObjects });
|
|
61
|
-
};
|
|
62
|
-
__classPrivateFieldSet(this, _PlaneRestriction_gridRestriction, new GridRestriction_1.GridRestriction(viewport, geometryMathManager, parentNode, this, inheritHelperObjects(__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").gridSnapRestriction)), "f");
|
|
63
|
-
__classPrivateFieldSet(this, _PlaneRestriction_angularRestriction, new AngularRestriction_1.AngularRestriction(viewport, geometryMathManager, parentNode, this, settings, inheritHelperObjects(__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").angularSnapRestriction)), "f");
|
|
64
|
-
__classPrivateFieldSet(this, _PlaneRestriction_axisRestriction, new AxisRestriction_1.AxisRestriction(viewport, geometryMathManager, parentNode, this, inheritHelperObjects(__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").axisSnapRestriction)), "f");
|
|
65
|
-
this.updatePlaneDefinition();
|
|
66
|
-
__classPrivateFieldSet(this, _PlaneRestriction_snapRestrictions, {
|
|
67
|
-
grid: __classPrivateFieldGet(this, _PlaneRestriction_gridRestriction, "f"),
|
|
68
|
-
angular: __classPrivateFieldGet(this, _PlaneRestriction_angularRestriction, "f"),
|
|
69
|
-
axis: __classPrivateFieldGet(this, _PlaneRestriction_axisRestriction, "f"),
|
|
70
|
-
}, "f");
|
|
71
|
-
}
|
|
72
|
-
// #endregion Constructors (1)
|
|
73
|
-
// #region Public Getters And Setters (14)
|
|
74
|
-
get angularRestriction() {
|
|
75
|
-
return __classPrivateFieldGet(this, _PlaneRestriction_angularRestriction, "f");
|
|
76
|
-
}
|
|
77
|
-
get axisRestriction() {
|
|
78
|
-
return __classPrivateFieldGet(this, _PlaneRestriction_axisRestriction, "f");
|
|
79
|
-
}
|
|
80
|
-
get gridRestriction() {
|
|
81
|
-
return __classPrivateFieldGet(this, _PlaneRestriction_gridRestriction, "f");
|
|
82
|
-
}
|
|
83
|
-
get normal() {
|
|
84
|
-
return __classPrivateFieldGet(this, _PlaneRestriction_normal, "f");
|
|
85
|
-
}
|
|
86
|
-
get origin() {
|
|
87
|
-
return __classPrivateFieldGet(this, _PlaneRestriction_origin, "f");
|
|
88
|
-
}
|
|
89
|
-
set origin(value) {
|
|
90
|
-
__classPrivateFieldSet(this, _PlaneRestriction_origin, value, "f");
|
|
91
|
-
this.updatePlaneDefinition();
|
|
92
|
-
}
|
|
93
|
-
get snapRestrictions() {
|
|
94
|
-
return __classPrivateFieldGet(this, _PlaneRestriction_snapRestrictions, "f");
|
|
95
|
-
}
|
|
96
|
-
get transformationFromXYPlaneMatrix() {
|
|
97
|
-
return __classPrivateFieldGet(this, _PlaneRestriction_transformationFromXYPlaneMatrix, "f");
|
|
98
|
-
}
|
|
99
|
-
get transformationToXYPlaneMatrix() {
|
|
100
|
-
return __classPrivateFieldGet(this, _PlaneRestriction_transformationToXYPlaneMatrix, "f");
|
|
101
|
-
}
|
|
102
|
-
get vectorU() {
|
|
103
|
-
return __classPrivateFieldGet(this, _PlaneRestriction_vectorU, "f");
|
|
104
|
-
}
|
|
105
|
-
set vectorU(value) {
|
|
106
|
-
__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").vector_u = value;
|
|
107
|
-
this.updatePlaneDefinition();
|
|
108
|
-
}
|
|
109
|
-
get vectorV() {
|
|
110
|
-
return __classPrivateFieldGet(this, _PlaneRestriction_vectorV, "f");
|
|
111
|
-
}
|
|
112
|
-
set vectorV(value) {
|
|
113
|
-
__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").vector_v = value;
|
|
114
|
-
this.updatePlaneDefinition();
|
|
115
|
-
}
|
|
116
|
-
// #endregion Public Getters And Setters (14)
|
|
117
|
-
// #region Public Methods (1)
|
|
118
|
-
rayTrace(ray, metaData) {
|
|
119
|
-
if (this.enabled === false)
|
|
120
|
-
return;
|
|
121
|
-
if ((0, IRestriction_1.isDrawingRestriction)(metaData)) {
|
|
122
|
-
if (__classPrivateFieldGet(this, _PlaneRestriction_cameraId, "f") !== __classPrivateFieldGet(this, _PlaneRestriction_viewport, "f").camera.id)
|
|
123
|
-
this.updatePlaneDefinition();
|
|
124
|
-
let origin = __classPrivateFieldGet(this, _PlaneRestriction_origin, "f");
|
|
125
|
-
if (metaData.startPoint)
|
|
126
|
-
origin = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _PlaneRestriction_origin, "f"), gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _PlaneRestriction_normal, "f"), gl_matrix_1.vec3.dot(gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _PlaneRestriction_origin, "f"), metaData.startPoint), __classPrivateFieldGet(this, _PlaneRestriction_normal, "f"))));
|
|
127
|
-
// find intersection of ray and plane
|
|
128
|
-
const t = (gl_matrix_1.vec3.dot(origin, __classPrivateFieldGet(this, _PlaneRestriction_normal, "f")) -
|
|
129
|
-
gl_matrix_1.vec3.dot(ray.origin, __classPrivateFieldGet(this, _PlaneRestriction_normal, "f"))) /
|
|
130
|
-
gl_matrix_1.vec3.dot(ray.direction, __classPrivateFieldGet(this, _PlaneRestriction_normal, "f"));
|
|
131
|
-
const intersection = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), ray.origin, gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), ray.direction, gl_matrix_1.vec3.fromValues(t, t, t)));
|
|
132
|
-
return this.snap(ray, intersection, t, metaData);
|
|
133
|
-
}
|
|
134
|
-
else if ((0, IRestriction_1.isDraggingRestriction)(metaData)) {
|
|
135
|
-
const distance = __classPrivateFieldGet(this, _PlaneRestriction_plane, "f").intersect(ray.origin, ray.direction);
|
|
136
|
-
if (distance && distance > 0) {
|
|
137
|
-
const intersection = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), ray.direction, gl_matrix_1.vec3.fromValues(distance, distance, distance)), ray.origin);
|
|
138
|
-
return this.snap(ray, intersection, distance, metaData);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
// #endregion Public Methods (1)
|
|
143
|
-
// #region Protected Methods (1)
|
|
144
|
-
visibilityChanged() { }
|
|
145
|
-
// #endregion Protected Methods (1)
|
|
146
|
-
// #region Private Methods (4)
|
|
147
|
-
createDefaultPlane(camera) {
|
|
148
|
-
if (camera.type === viewer_1.CAMERA_TYPE.PERSPECTIVE ||
|
|
149
|
-
(camera.type === viewer_1.CAMERA_TYPE.ORTHOGRAPHIC &&
|
|
150
|
-
camera.direction ===
|
|
151
|
-
viewer_1.ORTHOGRAPHIC_CAMERA_DIRECTION.CUSTOM)) {
|
|
152
|
-
__classPrivateFieldSet(this, _PlaneRestriction_vectorU, gl_matrix_1.vec3.fromValues(1, 0, 0), "f");
|
|
153
|
-
__classPrivateFieldSet(this, _PlaneRestriction_vectorV, gl_matrix_1.vec3.fromValues(0, 1, 0), "f");
|
|
154
|
-
__classPrivateFieldSet(this, _PlaneRestriction_normal, gl_matrix_1.vec3.fromValues(0, 0, 1), "f");
|
|
155
|
-
__classPrivateFieldSet(this, _PlaneRestriction_origin, gl_matrix_1.vec3.fromValues(0, 0, 0), "f");
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
const orthographicCamera = camera;
|
|
159
|
-
const direction = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), orthographicCamera.target, orthographicCamera.position));
|
|
160
|
-
const up = orthographicCamera.direction ===
|
|
161
|
-
viewer_1.ORTHOGRAPHIC_CAMERA_DIRECTION.TOP ||
|
|
162
|
-
orthographicCamera.direction ===
|
|
163
|
-
viewer_1.ORTHOGRAPHIC_CAMERA_DIRECTION.BOTTOM
|
|
164
|
-
? gl_matrix_1.vec3.fromValues(0, 1, 0)
|
|
165
|
-
: gl_matrix_1.vec3.fromValues(0, 0, 1);
|
|
166
|
-
__classPrivateFieldSet(this, _PlaneRestriction_origin, gl_matrix_1.vec3.fromValues(0, 0, 0), "f");
|
|
167
|
-
__classPrivateFieldSet(this, _PlaneRestriction_normal, gl_matrix_1.vec3.negate(gl_matrix_1.vec3.create(), direction), "f");
|
|
168
|
-
__classPrivateFieldSet(this, _PlaneRestriction_vectorU, gl_matrix_1.vec3.clone(up), "f");
|
|
169
|
-
__classPrivateFieldSet(this, _PlaneRestriction_vectorV, gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _PlaneRestriction_normal, "f"), __classPrivateFieldGet(this, _PlaneRestriction_vectorU, "f"))), "f");
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
createTransformationMatrices() {
|
|
173
|
-
// Calculate the transformation matrix for the rotation
|
|
174
|
-
const rotationMatrix = gl_matrix_1.mat4.fromValues(__classPrivateFieldGet(this, _PlaneRestriction_vectorU, "f")[0], __classPrivateFieldGet(this, _PlaneRestriction_vectorV, "f")[0], __classPrivateFieldGet(this, _PlaneRestriction_normal, "f")[0], 0, __classPrivateFieldGet(this, _PlaneRestriction_vectorU, "f")[1], __classPrivateFieldGet(this, _PlaneRestriction_vectorV, "f")[1], __classPrivateFieldGet(this, _PlaneRestriction_normal, "f")[1], 0, __classPrivateFieldGet(this, _PlaneRestriction_vectorU, "f")[2], __classPrivateFieldGet(this, _PlaneRestriction_vectorV, "f")[2], __classPrivateFieldGet(this, _PlaneRestriction_normal, "f")[2], 0, 0, 0, 0, 1);
|
|
175
|
-
let rotationMatrixInverse = gl_matrix_1.mat4.invert(gl_matrix_1.mat4.create(), rotationMatrix);
|
|
176
|
-
if (!rotationMatrixInverse)
|
|
177
|
-
rotationMatrixInverse = gl_matrix_1.mat4.create();
|
|
178
|
-
const pivotMatrix = gl_matrix_1.mat4.fromTranslation(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(__classPrivateFieldGet(this, _PlaneRestriction_origin, "f")[0], __classPrivateFieldGet(this, _PlaneRestriction_origin, "f")[1], __classPrivateFieldGet(this, _PlaneRestriction_origin, "f")[2]));
|
|
179
|
-
const pivotMatrixInverse = gl_matrix_1.mat4.fromTranslation(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(-__classPrivateFieldGet(this, _PlaneRestriction_origin, "f")[0], -__classPrivateFieldGet(this, _PlaneRestriction_origin, "f")[1], -__classPrivateFieldGet(this, _PlaneRestriction_origin, "f")[2]));
|
|
180
|
-
gl_matrix_1.mat4.multiply(__classPrivateFieldGet(this, _PlaneRestriction_transformationToXYPlaneMatrix, "f"), pivotMatrix, rotationMatrix);
|
|
181
|
-
gl_matrix_1.mat4.multiply(__classPrivateFieldGet(this, _PlaneRestriction_transformationToXYPlaneMatrix, "f"), __classPrivateFieldGet(this, _PlaneRestriction_transformationToXYPlaneMatrix, "f"), pivotMatrixInverse);
|
|
182
|
-
gl_matrix_1.mat4.multiply(__classPrivateFieldGet(this, _PlaneRestriction_transformationFromXYPlaneMatrix, "f"), pivotMatrix, rotationMatrixInverse);
|
|
183
|
-
gl_matrix_1.mat4.multiply(__classPrivateFieldGet(this, _PlaneRestriction_transformationFromXYPlaneMatrix, "f"), __classPrivateFieldGet(this, _PlaneRestriction_transformationFromXYPlaneMatrix, "f"), pivotMatrixInverse);
|
|
184
|
-
}
|
|
185
|
-
snap(ray, point, distance, metaData) {
|
|
186
|
-
if (this.enabled === false)
|
|
187
|
-
return;
|
|
188
|
-
if (__classPrivateFieldGet(this, _PlaneRestriction_cameraId, "f") !== __classPrivateFieldGet(this, _PlaneRestriction_viewport, "f").camera.id)
|
|
189
|
-
this.updatePlaneDefinition();
|
|
190
|
-
const sortedSnapRestrictions = Object.values(__classPrivateFieldGet(this, _PlaneRestriction_snapRestrictions, "f")).sort((a, b) => b.priority - a.priority);
|
|
191
|
-
// group snap restrictions by priority
|
|
192
|
-
const groupedSnapRestrictions = {};
|
|
193
|
-
for (const snapRestriction of sortedSnapRestrictions) {
|
|
194
|
-
if (!groupedSnapRestrictions[snapRestriction.priority])
|
|
195
|
-
groupedSnapRestrictions[snapRestriction.priority] = [];
|
|
196
|
-
groupedSnapRestrictions[snapRestriction.priority].push(snapRestriction);
|
|
197
|
-
}
|
|
198
|
-
// call snap method for each group
|
|
199
|
-
for (const snapRestrictions of Object.values(groupedSnapRestrictions)) {
|
|
200
|
-
const results = [];
|
|
201
|
-
for (const snapRestriction of snapRestrictions) {
|
|
202
|
-
results.push(snapRestriction.snap(ray, point, distance, metaData));
|
|
203
|
-
}
|
|
204
|
-
const indexedResults = results.map((value, index) => ({
|
|
205
|
-
index,
|
|
206
|
-
value,
|
|
207
|
-
}));
|
|
208
|
-
// find the result that is closest to the point and set the snap restriction to active
|
|
209
|
-
indexedResults.sort((a, b) => {
|
|
210
|
-
if (!a.value)
|
|
211
|
-
return 1;
|
|
212
|
-
if (!b.value)
|
|
213
|
-
return -1;
|
|
214
|
-
return (gl_matrix_1.vec3.squaredDistance(point, a.value.targetPoint) -
|
|
215
|
-
gl_matrix_1.vec3.squaredDistance(point, b.value.targetPoint));
|
|
216
|
-
});
|
|
217
|
-
for (const snapRestriction of snapRestrictions) {
|
|
218
|
-
snapRestriction.active = false;
|
|
219
|
-
}
|
|
220
|
-
// if a snap restriction returned a result, return it
|
|
221
|
-
if (indexedResults[0].value !== undefined) {
|
|
222
|
-
snapRestrictions[indexedResults[0].index].active = true;
|
|
223
|
-
return indexedResults[0].value;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return {
|
|
227
|
-
closestIntersectionPoint: point,
|
|
228
|
-
distanceOriginToClosestIntersectionPointSquared: gl_matrix_1.vec3.sqrDist(ray.origin, point),
|
|
229
|
-
targetPoint: point,
|
|
230
|
-
distanceClosestPointToTargetPointSquared: 0,
|
|
231
|
-
restriction: this,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
updatePlaneDefinition() {
|
|
235
|
-
const camera = __classPrivateFieldGet(this, _PlaneRestriction_viewport, "f").camera;
|
|
236
|
-
__classPrivateFieldSet(this, _PlaneRestriction_cameraId, camera.id, "f");
|
|
237
|
-
const origin = __classPrivateFieldGet(this, _PlaneRestriction_properties, "f").origin
|
|
238
|
-
? gl_matrix_1.vec3.clone(__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").origin)
|
|
239
|
-
: gl_matrix_1.vec3.fromValues(0, 0, 0);
|
|
240
|
-
const vectorU = __classPrivateFieldGet(this, _PlaneRestriction_properties, "f").vector_u
|
|
241
|
-
? gl_matrix_1.vec3.clone(__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").vector_u)
|
|
242
|
-
: undefined;
|
|
243
|
-
const vectorV = __classPrivateFieldGet(this, _PlaneRestriction_properties, "f").vector_v
|
|
244
|
-
? gl_matrix_1.vec3.clone(__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").vector_v)
|
|
245
|
-
: undefined;
|
|
246
|
-
const planeDefined = origin && vectorU && vectorV;
|
|
247
|
-
let normal = gl_matrix_1.vec3.fromValues(0, 0, 1);
|
|
248
|
-
if (planeDefined) {
|
|
249
|
-
gl_matrix_1.vec3.normalize(vectorU, vectorU);
|
|
250
|
-
gl_matrix_1.vec3.normalize(vectorV, vectorV);
|
|
251
|
-
normal = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), vectorU, vectorV));
|
|
252
|
-
if (gl_matrix_1.vec3.dot(vectorU, vectorV) !== 0)
|
|
253
|
-
gl_matrix_1.vec3.normalize(vectorV, gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), normal, vectorU));
|
|
254
|
-
if (camera.type === viewer_1.CAMERA_TYPE.ORTHOGRAPHIC) {
|
|
255
|
-
const cameraApi = camera;
|
|
256
|
-
const cameraDirectionWS = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), cameraApi.target, cameraApi.position));
|
|
257
|
-
// When this restriction is used inside a drawing tool that
|
|
258
|
-
// transforms rays to the parent node's local space (via
|
|
259
|
-
// DrawingToolsManager.transformRayToLocalSpace), the plane
|
|
260
|
-
// vectors (vectorU, vectorV, normal) are in local space while
|
|
261
|
-
// cameraDirectionWS is still in world space. Converting to
|
|
262
|
-
// local space ensures the edge-on check is performed in the
|
|
263
|
-
// same coordinate frame as the plane normal.
|
|
264
|
-
const invParentMatrix = gl_matrix_1.mat4.invert(gl_matrix_1.mat4.create(), __classPrivateFieldGet(this, _PlaneRestriction_parentNode, "f").worldMatrix);
|
|
265
|
-
const cameraDirection = invParentMatrix
|
|
266
|
-
? gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.fromValues(invParentMatrix[0] * cameraDirectionWS[0] +
|
|
267
|
-
invParentMatrix[4] * cameraDirectionWS[1] +
|
|
268
|
-
invParentMatrix[8] * cameraDirectionWS[2], invParentMatrix[1] * cameraDirectionWS[0] +
|
|
269
|
-
invParentMatrix[5] * cameraDirectionWS[1] +
|
|
270
|
-
invParentMatrix[9] * cameraDirectionWS[2], invParentMatrix[2] * cameraDirectionWS[0] +
|
|
271
|
-
invParentMatrix[6] * cameraDirectionWS[1] +
|
|
272
|
-
invParentMatrix[10] * cameraDirectionWS[2]))
|
|
273
|
-
: cameraDirectionWS;
|
|
274
|
-
// If the (local-space) camera direction is perpendicular to the
|
|
275
|
-
// plane normal the plane is seen edge-on and intersection would
|
|
276
|
-
// be degenerate — fall back to a camera-facing plane instead.
|
|
277
|
-
if (Math.abs(gl_matrix_1.vec3.dot(cameraDirection, normal)) < 0.0001) {
|
|
278
|
-
this.createDefaultPlane(camera);
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
__classPrivateFieldSet(this, _PlaneRestriction_vectorU, vectorU, "f");
|
|
282
|
-
__classPrivateFieldSet(this, _PlaneRestriction_vectorV, vectorV, "f");
|
|
283
|
-
__classPrivateFieldSet(this, _PlaneRestriction_normal, normal, "f");
|
|
284
|
-
__classPrivateFieldSet(this, _PlaneRestriction_origin, origin, "f");
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
__classPrivateFieldSet(this, _PlaneRestriction_vectorU, vectorU, "f");
|
|
289
|
-
__classPrivateFieldSet(this, _PlaneRestriction_vectorV, vectorV, "f");
|
|
290
|
-
__classPrivateFieldSet(this, _PlaneRestriction_normal, normal, "f");
|
|
291
|
-
__classPrivateFieldSet(this, _PlaneRestriction_origin, origin, "f");
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
this.createDefaultPlane(camera);
|
|
296
|
-
}
|
|
297
|
-
__classPrivateFieldSet(this, _PlaneRestriction_plane, new viewer_shared_math_1.Plane().setFromNormalAndCoplanarPoint(__classPrivateFieldGet(this, _PlaneRestriction_normal, "f"), __classPrivateFieldGet(this, _PlaneRestriction_origin, "f")), "f");
|
|
298
|
-
this.createTransformationMatrices();
|
|
299
|
-
__classPrivateFieldGet(this, _PlaneRestriction_gridRestriction, "f").updatePlaneDefinition();
|
|
300
|
-
__classPrivateFieldGet(this, _PlaneRestriction_angularRestriction, "f").updatePlaneDefinition();
|
|
301
|
-
__classPrivateFieldGet(this, _PlaneRestriction_axisRestriction, "f").updatePlaneDefinition();
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
exports.PlaneRestriction = PlaneRestriction;
|
|
305
|
-
_PlaneRestriction_parentNode = new WeakMap(), _PlaneRestriction_properties = new WeakMap(), _PlaneRestriction_viewport = new WeakMap(), _PlaneRestriction_angularRestriction = new WeakMap(), _PlaneRestriction_axisRestriction = new WeakMap(), _PlaneRestriction_cameraId = new WeakMap(), _PlaneRestriction_gridRestriction = new WeakMap(), _PlaneRestriction_normal = new WeakMap(), _PlaneRestriction_origin = new WeakMap(), _PlaneRestriction_plane = new WeakMap(), _PlaneRestriction_snapRestrictions = new WeakMap(), _PlaneRestriction_transformationFromXYPlaneMatrix = new WeakMap(), _PlaneRestriction_transformationToXYPlaneMatrix = new WeakMap(), _PlaneRestriction_vectorU = new WeakMap(), _PlaneRestriction_vectorV = new WeakMap();
|
|
306
|
-
// #endregion Classes (1)
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _PlaneRestriction_parentNode, _PlaneRestriction_properties, _PlaneRestriction_viewport, _PlaneRestriction_angularRestriction, _PlaneRestriction_axisRestriction, _PlaneRestriction_cameraId, _PlaneRestriction_gridRestriction, _PlaneRestriction_normal, _PlaneRestriction_origin, _PlaneRestriction_plane, _PlaneRestriction_snapRestrictions, _PlaneRestriction_transformationFromXYPlaneMatrix, _PlaneRestriction_transformationToXYPlaneMatrix, _PlaneRestriction_vectorU, _PlaneRestriction_vectorV;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PlaneRestriction = void 0;
|
|
16
|
+
const viewer_1 = require("@shapediver/viewer");
|
|
17
|
+
const viewer_shared_math_1 = require("@shapediver/viewer.shared.math");
|
|
18
|
+
const gl_matrix_1 = require("gl-matrix");
|
|
19
|
+
const IRestriction_1 = require("../../../interfaces/IRestriction");
|
|
20
|
+
const AbstractRestriction_1 = require("../AbstractRestriction");
|
|
21
|
+
const AngularRestriction_1 = require("./snap/AngularRestriction");
|
|
22
|
+
const AxisRestriction_1 = require("./snap/AxisRestriction");
|
|
23
|
+
const GridRestriction_1 = require("./snap/GridRestriction");
|
|
24
|
+
// #endregion Type aliases (1)
|
|
25
|
+
// #region Classes (1)
|
|
26
|
+
class PlaneRestriction extends AbstractRestriction_1.AbstractRestriction {
|
|
27
|
+
// #endregion Properties (15)
|
|
28
|
+
// #region Constructors (1)
|
|
29
|
+
constructor(viewport, geometryMathManager, parentNode, id, settings, properties) {
|
|
30
|
+
super(viewport, parentNode, id, properties);
|
|
31
|
+
// #region Properties (15)
|
|
32
|
+
_PlaneRestriction_parentNode.set(this, void 0);
|
|
33
|
+
_PlaneRestriction_properties.set(this, void 0);
|
|
34
|
+
_PlaneRestriction_viewport.set(this, void 0);
|
|
35
|
+
_PlaneRestriction_angularRestriction.set(this, void 0);
|
|
36
|
+
_PlaneRestriction_axisRestriction.set(this, void 0);
|
|
37
|
+
_PlaneRestriction_cameraId.set(this, "");
|
|
38
|
+
_PlaneRestriction_gridRestriction.set(this, void 0);
|
|
39
|
+
_PlaneRestriction_normal.set(this, gl_matrix_1.vec3.create());
|
|
40
|
+
_PlaneRestriction_origin.set(this, gl_matrix_1.vec3.create());
|
|
41
|
+
_PlaneRestriction_plane.set(this, new viewer_shared_math_1.Plane());
|
|
42
|
+
_PlaneRestriction_snapRestrictions.set(this, void 0);
|
|
43
|
+
_PlaneRestriction_transformationFromXYPlaneMatrix.set(this, gl_matrix_1.mat4.create());
|
|
44
|
+
_PlaneRestriction_transformationToXYPlaneMatrix.set(this, gl_matrix_1.mat4.create());
|
|
45
|
+
_PlaneRestriction_vectorU.set(this, gl_matrix_1.vec3.create());
|
|
46
|
+
_PlaneRestriction_vectorV.set(this, gl_matrix_1.vec3.create());
|
|
47
|
+
__classPrivateFieldSet(this, _PlaneRestriction_parentNode, parentNode, "f");
|
|
48
|
+
__classPrivateFieldSet(this, _PlaneRestriction_viewport, viewport, "f");
|
|
49
|
+
__classPrivateFieldSet(this, _PlaneRestriction_cameraId, __classPrivateFieldGet(this, _PlaneRestriction_viewport, "f").camera.id, "f");
|
|
50
|
+
__classPrivateFieldSet(this, _PlaneRestriction_properties, properties, "f");
|
|
51
|
+
// Propagate createHelperObjects to sub-restrictions that don't have
|
|
52
|
+
// an explicit override, so that a single flag on the plane restriction
|
|
53
|
+
// suppresses helper objects for all its child snap restrictions.
|
|
54
|
+
const inheritHelperObjects = (sub) => {
|
|
55
|
+
var _a;
|
|
56
|
+
if (properties.createHelperObjects === undefined)
|
|
57
|
+
return sub;
|
|
58
|
+
if (sub === undefined)
|
|
59
|
+
return { createHelperObjects: properties.createHelperObjects };
|
|
60
|
+
return Object.assign(Object.assign({}, sub), { createHelperObjects: (_a = sub.createHelperObjects) !== null && _a !== void 0 ? _a : properties.createHelperObjects });
|
|
61
|
+
};
|
|
62
|
+
__classPrivateFieldSet(this, _PlaneRestriction_gridRestriction, new GridRestriction_1.GridRestriction(viewport, geometryMathManager, parentNode, this, inheritHelperObjects(__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").gridSnapRestriction)), "f");
|
|
63
|
+
__classPrivateFieldSet(this, _PlaneRestriction_angularRestriction, new AngularRestriction_1.AngularRestriction(viewport, geometryMathManager, parentNode, this, settings, inheritHelperObjects(__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").angularSnapRestriction)), "f");
|
|
64
|
+
__classPrivateFieldSet(this, _PlaneRestriction_axisRestriction, new AxisRestriction_1.AxisRestriction(viewport, geometryMathManager, parentNode, this, inheritHelperObjects(__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").axisSnapRestriction)), "f");
|
|
65
|
+
this.updatePlaneDefinition();
|
|
66
|
+
__classPrivateFieldSet(this, _PlaneRestriction_snapRestrictions, {
|
|
67
|
+
grid: __classPrivateFieldGet(this, _PlaneRestriction_gridRestriction, "f"),
|
|
68
|
+
angular: __classPrivateFieldGet(this, _PlaneRestriction_angularRestriction, "f"),
|
|
69
|
+
axis: __classPrivateFieldGet(this, _PlaneRestriction_axisRestriction, "f"),
|
|
70
|
+
}, "f");
|
|
71
|
+
}
|
|
72
|
+
// #endregion Constructors (1)
|
|
73
|
+
// #region Public Getters And Setters (14)
|
|
74
|
+
get angularRestriction() {
|
|
75
|
+
return __classPrivateFieldGet(this, _PlaneRestriction_angularRestriction, "f");
|
|
76
|
+
}
|
|
77
|
+
get axisRestriction() {
|
|
78
|
+
return __classPrivateFieldGet(this, _PlaneRestriction_axisRestriction, "f");
|
|
79
|
+
}
|
|
80
|
+
get gridRestriction() {
|
|
81
|
+
return __classPrivateFieldGet(this, _PlaneRestriction_gridRestriction, "f");
|
|
82
|
+
}
|
|
83
|
+
get normal() {
|
|
84
|
+
return __classPrivateFieldGet(this, _PlaneRestriction_normal, "f");
|
|
85
|
+
}
|
|
86
|
+
get origin() {
|
|
87
|
+
return __classPrivateFieldGet(this, _PlaneRestriction_origin, "f");
|
|
88
|
+
}
|
|
89
|
+
set origin(value) {
|
|
90
|
+
__classPrivateFieldSet(this, _PlaneRestriction_origin, value, "f");
|
|
91
|
+
this.updatePlaneDefinition();
|
|
92
|
+
}
|
|
93
|
+
get snapRestrictions() {
|
|
94
|
+
return __classPrivateFieldGet(this, _PlaneRestriction_snapRestrictions, "f");
|
|
95
|
+
}
|
|
96
|
+
get transformationFromXYPlaneMatrix() {
|
|
97
|
+
return __classPrivateFieldGet(this, _PlaneRestriction_transformationFromXYPlaneMatrix, "f");
|
|
98
|
+
}
|
|
99
|
+
get transformationToXYPlaneMatrix() {
|
|
100
|
+
return __classPrivateFieldGet(this, _PlaneRestriction_transformationToXYPlaneMatrix, "f");
|
|
101
|
+
}
|
|
102
|
+
get vectorU() {
|
|
103
|
+
return __classPrivateFieldGet(this, _PlaneRestriction_vectorU, "f");
|
|
104
|
+
}
|
|
105
|
+
set vectorU(value) {
|
|
106
|
+
__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").vector_u = value;
|
|
107
|
+
this.updatePlaneDefinition();
|
|
108
|
+
}
|
|
109
|
+
get vectorV() {
|
|
110
|
+
return __classPrivateFieldGet(this, _PlaneRestriction_vectorV, "f");
|
|
111
|
+
}
|
|
112
|
+
set vectorV(value) {
|
|
113
|
+
__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").vector_v = value;
|
|
114
|
+
this.updatePlaneDefinition();
|
|
115
|
+
}
|
|
116
|
+
// #endregion Public Getters And Setters (14)
|
|
117
|
+
// #region Public Methods (1)
|
|
118
|
+
rayTrace(ray, metaData) {
|
|
119
|
+
if (this.enabled === false)
|
|
120
|
+
return;
|
|
121
|
+
if ((0, IRestriction_1.isDrawingRestriction)(metaData)) {
|
|
122
|
+
if (__classPrivateFieldGet(this, _PlaneRestriction_cameraId, "f") !== __classPrivateFieldGet(this, _PlaneRestriction_viewport, "f").camera.id)
|
|
123
|
+
this.updatePlaneDefinition();
|
|
124
|
+
let origin = __classPrivateFieldGet(this, _PlaneRestriction_origin, "f");
|
|
125
|
+
if (metaData.startPoint)
|
|
126
|
+
origin = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _PlaneRestriction_origin, "f"), gl_matrix_1.vec3.scale(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _PlaneRestriction_normal, "f"), gl_matrix_1.vec3.dot(gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _PlaneRestriction_origin, "f"), metaData.startPoint), __classPrivateFieldGet(this, _PlaneRestriction_normal, "f"))));
|
|
127
|
+
// find intersection of ray and plane
|
|
128
|
+
const t = (gl_matrix_1.vec3.dot(origin, __classPrivateFieldGet(this, _PlaneRestriction_normal, "f")) -
|
|
129
|
+
gl_matrix_1.vec3.dot(ray.origin, __classPrivateFieldGet(this, _PlaneRestriction_normal, "f"))) /
|
|
130
|
+
gl_matrix_1.vec3.dot(ray.direction, __classPrivateFieldGet(this, _PlaneRestriction_normal, "f"));
|
|
131
|
+
const intersection = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), ray.origin, gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), ray.direction, gl_matrix_1.vec3.fromValues(t, t, t)));
|
|
132
|
+
return this.snap(ray, intersection, t, metaData);
|
|
133
|
+
}
|
|
134
|
+
else if ((0, IRestriction_1.isDraggingRestriction)(metaData)) {
|
|
135
|
+
const distance = __classPrivateFieldGet(this, _PlaneRestriction_plane, "f").intersect(ray.origin, ray.direction);
|
|
136
|
+
if (distance && distance > 0) {
|
|
137
|
+
const intersection = gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), ray.direction, gl_matrix_1.vec3.fromValues(distance, distance, distance)), ray.origin);
|
|
138
|
+
return this.snap(ray, intersection, distance, metaData);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// #endregion Public Methods (1)
|
|
143
|
+
// #region Protected Methods (1)
|
|
144
|
+
visibilityChanged() { }
|
|
145
|
+
// #endregion Protected Methods (1)
|
|
146
|
+
// #region Private Methods (4)
|
|
147
|
+
createDefaultPlane(camera) {
|
|
148
|
+
if (camera.type === viewer_1.CAMERA_TYPE.PERSPECTIVE ||
|
|
149
|
+
(camera.type === viewer_1.CAMERA_TYPE.ORTHOGRAPHIC &&
|
|
150
|
+
camera.direction ===
|
|
151
|
+
viewer_1.ORTHOGRAPHIC_CAMERA_DIRECTION.CUSTOM)) {
|
|
152
|
+
__classPrivateFieldSet(this, _PlaneRestriction_vectorU, gl_matrix_1.vec3.fromValues(1, 0, 0), "f");
|
|
153
|
+
__classPrivateFieldSet(this, _PlaneRestriction_vectorV, gl_matrix_1.vec3.fromValues(0, 1, 0), "f");
|
|
154
|
+
__classPrivateFieldSet(this, _PlaneRestriction_normal, gl_matrix_1.vec3.fromValues(0, 0, 1), "f");
|
|
155
|
+
__classPrivateFieldSet(this, _PlaneRestriction_origin, gl_matrix_1.vec3.fromValues(0, 0, 0), "f");
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
const orthographicCamera = camera;
|
|
159
|
+
const direction = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), orthographicCamera.target, orthographicCamera.position));
|
|
160
|
+
const up = orthographicCamera.direction ===
|
|
161
|
+
viewer_1.ORTHOGRAPHIC_CAMERA_DIRECTION.TOP ||
|
|
162
|
+
orthographicCamera.direction ===
|
|
163
|
+
viewer_1.ORTHOGRAPHIC_CAMERA_DIRECTION.BOTTOM
|
|
164
|
+
? gl_matrix_1.vec3.fromValues(0, 1, 0)
|
|
165
|
+
: gl_matrix_1.vec3.fromValues(0, 0, 1);
|
|
166
|
+
__classPrivateFieldSet(this, _PlaneRestriction_origin, gl_matrix_1.vec3.fromValues(0, 0, 0), "f");
|
|
167
|
+
__classPrivateFieldSet(this, _PlaneRestriction_normal, gl_matrix_1.vec3.negate(gl_matrix_1.vec3.create(), direction), "f");
|
|
168
|
+
__classPrivateFieldSet(this, _PlaneRestriction_vectorU, gl_matrix_1.vec3.clone(up), "f");
|
|
169
|
+
__classPrivateFieldSet(this, _PlaneRestriction_vectorV, gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), __classPrivateFieldGet(this, _PlaneRestriction_normal, "f"), __classPrivateFieldGet(this, _PlaneRestriction_vectorU, "f"))), "f");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
createTransformationMatrices() {
|
|
173
|
+
// Calculate the transformation matrix for the rotation
|
|
174
|
+
const rotationMatrix = gl_matrix_1.mat4.fromValues(__classPrivateFieldGet(this, _PlaneRestriction_vectorU, "f")[0], __classPrivateFieldGet(this, _PlaneRestriction_vectorV, "f")[0], __classPrivateFieldGet(this, _PlaneRestriction_normal, "f")[0], 0, __classPrivateFieldGet(this, _PlaneRestriction_vectorU, "f")[1], __classPrivateFieldGet(this, _PlaneRestriction_vectorV, "f")[1], __classPrivateFieldGet(this, _PlaneRestriction_normal, "f")[1], 0, __classPrivateFieldGet(this, _PlaneRestriction_vectorU, "f")[2], __classPrivateFieldGet(this, _PlaneRestriction_vectorV, "f")[2], __classPrivateFieldGet(this, _PlaneRestriction_normal, "f")[2], 0, 0, 0, 0, 1);
|
|
175
|
+
let rotationMatrixInverse = gl_matrix_1.mat4.invert(gl_matrix_1.mat4.create(), rotationMatrix);
|
|
176
|
+
if (!rotationMatrixInverse)
|
|
177
|
+
rotationMatrixInverse = gl_matrix_1.mat4.create();
|
|
178
|
+
const pivotMatrix = gl_matrix_1.mat4.fromTranslation(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(__classPrivateFieldGet(this, _PlaneRestriction_origin, "f")[0], __classPrivateFieldGet(this, _PlaneRestriction_origin, "f")[1], __classPrivateFieldGet(this, _PlaneRestriction_origin, "f")[2]));
|
|
179
|
+
const pivotMatrixInverse = gl_matrix_1.mat4.fromTranslation(gl_matrix_1.mat4.create(), gl_matrix_1.vec3.fromValues(-__classPrivateFieldGet(this, _PlaneRestriction_origin, "f")[0], -__classPrivateFieldGet(this, _PlaneRestriction_origin, "f")[1], -__classPrivateFieldGet(this, _PlaneRestriction_origin, "f")[2]));
|
|
180
|
+
gl_matrix_1.mat4.multiply(__classPrivateFieldGet(this, _PlaneRestriction_transformationToXYPlaneMatrix, "f"), pivotMatrix, rotationMatrix);
|
|
181
|
+
gl_matrix_1.mat4.multiply(__classPrivateFieldGet(this, _PlaneRestriction_transformationToXYPlaneMatrix, "f"), __classPrivateFieldGet(this, _PlaneRestriction_transformationToXYPlaneMatrix, "f"), pivotMatrixInverse);
|
|
182
|
+
gl_matrix_1.mat4.multiply(__classPrivateFieldGet(this, _PlaneRestriction_transformationFromXYPlaneMatrix, "f"), pivotMatrix, rotationMatrixInverse);
|
|
183
|
+
gl_matrix_1.mat4.multiply(__classPrivateFieldGet(this, _PlaneRestriction_transformationFromXYPlaneMatrix, "f"), __classPrivateFieldGet(this, _PlaneRestriction_transformationFromXYPlaneMatrix, "f"), pivotMatrixInverse);
|
|
184
|
+
}
|
|
185
|
+
snap(ray, point, distance, metaData) {
|
|
186
|
+
if (this.enabled === false)
|
|
187
|
+
return;
|
|
188
|
+
if (__classPrivateFieldGet(this, _PlaneRestriction_cameraId, "f") !== __classPrivateFieldGet(this, _PlaneRestriction_viewport, "f").camera.id)
|
|
189
|
+
this.updatePlaneDefinition();
|
|
190
|
+
const sortedSnapRestrictions = Object.values(__classPrivateFieldGet(this, _PlaneRestriction_snapRestrictions, "f")).sort((a, b) => b.priority - a.priority);
|
|
191
|
+
// group snap restrictions by priority
|
|
192
|
+
const groupedSnapRestrictions = {};
|
|
193
|
+
for (const snapRestriction of sortedSnapRestrictions) {
|
|
194
|
+
if (!groupedSnapRestrictions[snapRestriction.priority])
|
|
195
|
+
groupedSnapRestrictions[snapRestriction.priority] = [];
|
|
196
|
+
groupedSnapRestrictions[snapRestriction.priority].push(snapRestriction);
|
|
197
|
+
}
|
|
198
|
+
// call snap method for each group
|
|
199
|
+
for (const snapRestrictions of Object.values(groupedSnapRestrictions)) {
|
|
200
|
+
const results = [];
|
|
201
|
+
for (const snapRestriction of snapRestrictions) {
|
|
202
|
+
results.push(snapRestriction.snap(ray, point, distance, metaData));
|
|
203
|
+
}
|
|
204
|
+
const indexedResults = results.map((value, index) => ({
|
|
205
|
+
index,
|
|
206
|
+
value,
|
|
207
|
+
}));
|
|
208
|
+
// find the result that is closest to the point and set the snap restriction to active
|
|
209
|
+
indexedResults.sort((a, b) => {
|
|
210
|
+
if (!a.value)
|
|
211
|
+
return 1;
|
|
212
|
+
if (!b.value)
|
|
213
|
+
return -1;
|
|
214
|
+
return (gl_matrix_1.vec3.squaredDistance(point, a.value.targetPoint) -
|
|
215
|
+
gl_matrix_1.vec3.squaredDistance(point, b.value.targetPoint));
|
|
216
|
+
});
|
|
217
|
+
for (const snapRestriction of snapRestrictions) {
|
|
218
|
+
snapRestriction.active = false;
|
|
219
|
+
}
|
|
220
|
+
// if a snap restriction returned a result, return it
|
|
221
|
+
if (indexedResults[0].value !== undefined) {
|
|
222
|
+
snapRestrictions[indexedResults[0].index].active = true;
|
|
223
|
+
return indexedResults[0].value;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
closestIntersectionPoint: point,
|
|
228
|
+
distanceOriginToClosestIntersectionPointSquared: gl_matrix_1.vec3.sqrDist(ray.origin, point),
|
|
229
|
+
targetPoint: point,
|
|
230
|
+
distanceClosestPointToTargetPointSquared: 0,
|
|
231
|
+
restriction: this,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
updatePlaneDefinition() {
|
|
235
|
+
const camera = __classPrivateFieldGet(this, _PlaneRestriction_viewport, "f").camera;
|
|
236
|
+
__classPrivateFieldSet(this, _PlaneRestriction_cameraId, camera.id, "f");
|
|
237
|
+
const origin = __classPrivateFieldGet(this, _PlaneRestriction_properties, "f").origin
|
|
238
|
+
? gl_matrix_1.vec3.clone(__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").origin)
|
|
239
|
+
: gl_matrix_1.vec3.fromValues(0, 0, 0);
|
|
240
|
+
const vectorU = __classPrivateFieldGet(this, _PlaneRestriction_properties, "f").vector_u
|
|
241
|
+
? gl_matrix_1.vec3.clone(__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").vector_u)
|
|
242
|
+
: undefined;
|
|
243
|
+
const vectorV = __classPrivateFieldGet(this, _PlaneRestriction_properties, "f").vector_v
|
|
244
|
+
? gl_matrix_1.vec3.clone(__classPrivateFieldGet(this, _PlaneRestriction_properties, "f").vector_v)
|
|
245
|
+
: undefined;
|
|
246
|
+
const planeDefined = origin && vectorU && vectorV;
|
|
247
|
+
let normal = gl_matrix_1.vec3.fromValues(0, 0, 1);
|
|
248
|
+
if (planeDefined) {
|
|
249
|
+
gl_matrix_1.vec3.normalize(vectorU, vectorU);
|
|
250
|
+
gl_matrix_1.vec3.normalize(vectorV, vectorV);
|
|
251
|
+
normal = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), vectorU, vectorV));
|
|
252
|
+
if (gl_matrix_1.vec3.dot(vectorU, vectorV) !== 0)
|
|
253
|
+
gl_matrix_1.vec3.normalize(vectorV, gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), normal, vectorU));
|
|
254
|
+
if (camera.type === viewer_1.CAMERA_TYPE.ORTHOGRAPHIC) {
|
|
255
|
+
const cameraApi = camera;
|
|
256
|
+
const cameraDirectionWS = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), cameraApi.target, cameraApi.position));
|
|
257
|
+
// When this restriction is used inside a drawing tool that
|
|
258
|
+
// transforms rays to the parent node's local space (via
|
|
259
|
+
// DrawingToolsManager.transformRayToLocalSpace), the plane
|
|
260
|
+
// vectors (vectorU, vectorV, normal) are in local space while
|
|
261
|
+
// cameraDirectionWS is still in world space. Converting to
|
|
262
|
+
// local space ensures the edge-on check is performed in the
|
|
263
|
+
// same coordinate frame as the plane normal.
|
|
264
|
+
const invParentMatrix = gl_matrix_1.mat4.invert(gl_matrix_1.mat4.create(), __classPrivateFieldGet(this, _PlaneRestriction_parentNode, "f").worldMatrix);
|
|
265
|
+
const cameraDirection = invParentMatrix
|
|
266
|
+
? gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.fromValues(invParentMatrix[0] * cameraDirectionWS[0] +
|
|
267
|
+
invParentMatrix[4] * cameraDirectionWS[1] +
|
|
268
|
+
invParentMatrix[8] * cameraDirectionWS[2], invParentMatrix[1] * cameraDirectionWS[0] +
|
|
269
|
+
invParentMatrix[5] * cameraDirectionWS[1] +
|
|
270
|
+
invParentMatrix[9] * cameraDirectionWS[2], invParentMatrix[2] * cameraDirectionWS[0] +
|
|
271
|
+
invParentMatrix[6] * cameraDirectionWS[1] +
|
|
272
|
+
invParentMatrix[10] * cameraDirectionWS[2]))
|
|
273
|
+
: cameraDirectionWS;
|
|
274
|
+
// If the (local-space) camera direction is perpendicular to the
|
|
275
|
+
// plane normal the plane is seen edge-on and intersection would
|
|
276
|
+
// be degenerate — fall back to a camera-facing plane instead.
|
|
277
|
+
if (Math.abs(gl_matrix_1.vec3.dot(cameraDirection, normal)) < 0.0001) {
|
|
278
|
+
this.createDefaultPlane(camera);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
__classPrivateFieldSet(this, _PlaneRestriction_vectorU, vectorU, "f");
|
|
282
|
+
__classPrivateFieldSet(this, _PlaneRestriction_vectorV, vectorV, "f");
|
|
283
|
+
__classPrivateFieldSet(this, _PlaneRestriction_normal, normal, "f");
|
|
284
|
+
__classPrivateFieldSet(this, _PlaneRestriction_origin, origin, "f");
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
__classPrivateFieldSet(this, _PlaneRestriction_vectorU, vectorU, "f");
|
|
289
|
+
__classPrivateFieldSet(this, _PlaneRestriction_vectorV, vectorV, "f");
|
|
290
|
+
__classPrivateFieldSet(this, _PlaneRestriction_normal, normal, "f");
|
|
291
|
+
__classPrivateFieldSet(this, _PlaneRestriction_origin, origin, "f");
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
this.createDefaultPlane(camera);
|
|
296
|
+
}
|
|
297
|
+
__classPrivateFieldSet(this, _PlaneRestriction_plane, new viewer_shared_math_1.Plane().setFromNormalAndCoplanarPoint(__classPrivateFieldGet(this, _PlaneRestriction_normal, "f"), __classPrivateFieldGet(this, _PlaneRestriction_origin, "f")), "f");
|
|
298
|
+
this.createTransformationMatrices();
|
|
299
|
+
__classPrivateFieldGet(this, _PlaneRestriction_gridRestriction, "f").updatePlaneDefinition();
|
|
300
|
+
__classPrivateFieldGet(this, _PlaneRestriction_angularRestriction, "f").updatePlaneDefinition();
|
|
301
|
+
__classPrivateFieldGet(this, _PlaneRestriction_axisRestriction, "f").updatePlaneDefinition();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
exports.PlaneRestriction = PlaneRestriction;
|
|
305
|
+
_PlaneRestriction_parentNode = new WeakMap(), _PlaneRestriction_properties = new WeakMap(), _PlaneRestriction_viewport = new WeakMap(), _PlaneRestriction_angularRestriction = new WeakMap(), _PlaneRestriction_axisRestriction = new WeakMap(), _PlaneRestriction_cameraId = new WeakMap(), _PlaneRestriction_gridRestriction = new WeakMap(), _PlaneRestriction_normal = new WeakMap(), _PlaneRestriction_origin = new WeakMap(), _PlaneRestriction_plane = new WeakMap(), _PlaneRestriction_snapRestrictions = new WeakMap(), _PlaneRestriction_transformationFromXYPlaneMatrix = new WeakMap(), _PlaneRestriction_transformationToXYPlaneMatrix = new WeakMap(), _PlaneRestriction_vectorU = new WeakMap(), _PlaneRestriction_vectorV = new WeakMap();
|
|
306
|
+
// #endregion Classes (1)
|
|
307
307
|
//# sourceMappingURL=PlaneRestriction.js.map
|