@shapediver/viewer.rendering-engine.intersection-restriction-engine 3.16.7 → 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.
Files changed (95) hide show
  1. package/dist/api/implementation/AbstractRestrictionApi.d.ts +12 -12
  2. package/dist/api/implementation/AbstractRestrictionApi.js +46 -46
  3. package/dist/api/implementation/AbstractRestrictionApi.js.map +1 -1
  4. package/dist/api/implementation/AbstractSnapRestrictionApi.d.ts +12 -12
  5. package/dist/api/implementation/AbstractSnapRestrictionApi.js +46 -46
  6. package/dist/api/implementation/AbstractSnapRestrictionApi.js.map +1 -1
  7. package/dist/api/implementation/camera_plane/CameraPlaneRestrictionApi.d.ts +6 -6
  8. package/dist/api/implementation/camera_plane/CameraPlaneRestrictionApi.js +23 -23
  9. package/dist/api/implementation/camera_plane/CameraPlaneRestrictionApi.js.map +1 -1
  10. package/dist/api/implementation/geometry/GeometryRestrictionApi.d.ts +14 -14
  11. package/dist/api/implementation/geometry/GeometryRestrictionApi.js +53 -53
  12. package/dist/api/implementation/geometry/GeometryRestrictionApi.js.map +1 -1
  13. package/dist/api/implementation/line/LineRestrictionApi.d.ts +10 -10
  14. package/dist/api/implementation/line/LineRestrictionApi.js +39 -39
  15. package/dist/api/implementation/line/LineRestrictionApi.js.map +1 -1
  16. package/dist/api/implementation/plane/PlaneRestrictionApi.d.ts +19 -19
  17. package/dist/api/implementation/plane/PlaneRestrictionApi.js +66 -66
  18. package/dist/api/implementation/plane/PlaneRestrictionApi.js.map +1 -1
  19. package/dist/api/implementation/plane/snap/AngularRestrictionApi.d.ts +9 -9
  20. package/dist/api/implementation/plane/snap/AngularRestrictionApi.js +39 -39
  21. package/dist/api/implementation/plane/snap/AngularRestrictionApi.js.map +1 -1
  22. package/dist/api/implementation/plane/snap/AxisRestrictionApi.d.ts +6 -6
  23. package/dist/api/implementation/plane/snap/AxisRestrictionApi.js +23 -23
  24. package/dist/api/implementation/plane/snap/AxisRestrictionApi.js.map +1 -1
  25. package/dist/api/implementation/plane/snap/GridRestrictionApi.d.ts +9 -9
  26. package/dist/api/implementation/plane/snap/GridRestrictionApi.js +39 -39
  27. package/dist/api/implementation/plane/snap/GridRestrictionApi.js.map +1 -1
  28. package/dist/api/implementation/point/PointRestrictionApi.d.ts +9 -9
  29. package/dist/api/implementation/point/PointRestrictionApi.js +36 -36
  30. package/dist/api/implementation/point/PointRestrictionApi.js.map +1 -1
  31. package/dist/api/interfaces/IRestrictionApi.d.ts +10 -10
  32. package/dist/api/interfaces/IRestrictionApi.js +2 -2
  33. package/dist/api/interfaces/ISnapRestrictionApi.d.ts +12 -12
  34. package/dist/api/interfaces/ISnapRestrictionApi.js +2 -2
  35. package/dist/implementation/EventManager.d.ts +25 -25
  36. package/dist/implementation/EventManager.d.ts.map +1 -1
  37. package/dist/implementation/EventManager.js +62 -62
  38. package/dist/implementation/EventManager.js.map +1 -1
  39. package/dist/implementation/GeometryMathManager.d.ts +87 -87
  40. package/dist/implementation/GeometryMathManager.js +260 -260
  41. package/dist/implementation/GeometryMathManager.js.map +1 -1
  42. package/dist/implementation/RestrictionManager.d.ts +28 -28
  43. package/dist/implementation/RestrictionManager.js +323 -323
  44. package/dist/implementation/RestrictionManager.js.map +1 -1
  45. package/dist/implementation/restrictions/AbstractRestriction.d.ts +42 -42
  46. package/dist/implementation/restrictions/AbstractRestriction.js +164 -154
  47. package/dist/implementation/restrictions/AbstractRestriction.js.map +1 -1
  48. package/dist/implementation/restrictions/AbstractSnapRestriction.d.ts +35 -35
  49. package/dist/implementation/restrictions/AbstractSnapRestriction.js +150 -140
  50. package/dist/implementation/restrictions/AbstractSnapRestriction.js.map +1 -1
  51. package/dist/implementation/restrictions/RestrictionsHelper.d.ts +10 -10
  52. package/dist/implementation/restrictions/RestrictionsHelper.d.ts.map +1 -1
  53. package/dist/implementation/restrictions/RestrictionsHelper.js +50 -50
  54. package/dist/implementation/restrictions/RestrictionsHelper.js.map +1 -1
  55. package/dist/implementation/restrictions/camera_plane/CameraPlaneRestriction.d.ts +17 -17
  56. package/dist/implementation/restrictions/camera_plane/CameraPlaneRestriction.js +62 -62
  57. package/dist/implementation/restrictions/camera_plane/CameraPlaneRestriction.js.map +1 -1
  58. package/dist/implementation/restrictions/geometry/GeometryRestriction.d.ts +92 -92
  59. package/dist/implementation/restrictions/geometry/GeometryRestriction.js +410 -400
  60. package/dist/implementation/restrictions/geometry/GeometryRestriction.js.map +1 -1
  61. package/dist/implementation/restrictions/line/LineRestriction.d.ts +58 -58
  62. package/dist/implementation/restrictions/line/LineRestriction.js +291 -281
  63. package/dist/implementation/restrictions/line/LineRestriction.js.map +1 -1
  64. package/dist/implementation/restrictions/plane/PlaneRestriction.d.ts +65 -65
  65. package/dist/implementation/restrictions/plane/PlaneRestriction.js +306 -306
  66. package/dist/implementation/restrictions/plane/PlaneRestriction.js.map +1 -1
  67. package/dist/implementation/restrictions/plane/snap/AngularRestriction.d.ts +39 -39
  68. package/dist/implementation/restrictions/plane/snap/AngularRestriction.d.ts.map +1 -1
  69. package/dist/implementation/restrictions/plane/snap/AngularRestriction.js +346 -346
  70. package/dist/implementation/restrictions/plane/snap/AngularRestriction.js.map +1 -1
  71. package/dist/implementation/restrictions/plane/snap/AxisRestriction.d.ts +27 -27
  72. package/dist/implementation/restrictions/plane/snap/AxisRestriction.d.ts.map +1 -1
  73. package/dist/implementation/restrictions/plane/snap/AxisRestriction.js +239 -229
  74. package/dist/implementation/restrictions/plane/snap/AxisRestriction.js.map +1 -1
  75. package/dist/implementation/restrictions/plane/snap/GridRestriction.d.ts +39 -39
  76. package/dist/implementation/restrictions/plane/snap/GridRestriction.d.ts.map +1 -1
  77. package/dist/implementation/restrictions/plane/snap/GridRestriction.js +318 -308
  78. package/dist/implementation/restrictions/plane/snap/GridRestriction.js.map +1 -1
  79. package/dist/implementation/restrictions/point/PointRestriction.d.ts +45 -45
  80. package/dist/implementation/restrictions/point/PointRestriction.js +166 -156
  81. package/dist/implementation/restrictions/point/PointRestriction.js.map +1 -1
  82. package/dist/index.d.ts +29 -29
  83. package/dist/index.js +37 -37
  84. package/dist/interfaces/IDragAnchor.d.ts +8 -8
  85. package/dist/interfaces/IDragAnchor.js +2 -2
  86. package/dist/interfaces/IRestriction.d.ts +117 -117
  87. package/dist/interfaces/IRestriction.d.ts.map +1 -1
  88. package/dist/interfaces/IRestriction.js +23 -23
  89. package/dist/interfaces/IRestriction.js.map +1 -1
  90. package/dist/interfaces/IRestrictionManager.d.ts +13 -13
  91. package/dist/interfaces/IRestrictionManager.js +2 -2
  92. package/dist/interfaces/ISnapRestriction.d.ts +81 -81
  93. package/dist/interfaces/ISnapRestriction.d.ts.map +1 -1
  94. package/dist/interfaces/ISnapRestriction.js +3 -3
  95. package/package.json +10 -10
@@ -1,401 +1,411 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
26
- if (kind === "m") throw new TypeError("Private method is not writable");
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
28
- 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");
29
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
30
- };
31
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
32
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
33
- 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");
34
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
35
- };
36
- var _GeometryRestriction_eventEngine, _GeometryRestriction_rayCasterParams, _GeometryRestriction_raycaster, _GeometryRestriction_viewport, _GeometryRestriction_geometryMathManager, _GeometryRestriction_lineIntersectionPercentage, _GeometryRestriction_nodes, _GeometryRestriction_pointIntersectionPercentage, _GeometryRestriction_radius, _GeometryRestriction_sceneBoundingSphereRadius, _GeometryRestriction_settings, _GeometryRestriction_snapRestrictions, _GeometryRestriction_snapToEdges, _GeometryRestriction_snapToEdgesRadius, _GeometryRestriction_snapToFaces, _GeometryRestriction_snapToVertices, _GeometryRestriction_snapToVerticesRadius, _GeometryRestriction_visualizationObject, _GeometryRestriction_wireframe, _GeometryRestriction_wireframeColor, _GeometryRestriction_wireframeDepthTest, _GeometryRestriction_wireframePointSize;
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.GeometryRestriction = void 0;
39
- const viewer_1 = require("@shapediver/viewer");
40
- const viewer_shared_math_1 = require("@shapediver/viewer.shared.math");
41
- const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
42
- const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
43
- const gl_matrix_1 = require("gl-matrix");
44
- const THREE = __importStar(require("three"));
45
- const AbstractRestriction_1 = require("../AbstractRestriction");
46
- let pointTexture = viewer_1.MaterialEngine.instance
47
- .loadMap("https://viewer.shapediver.com/v3/graphics/point_soft.png")
48
- .then((mapData) => {
49
- pointTexture = new THREE.Texture(mapData.image);
50
- pointTexture.needsUpdate = true;
51
- return pointTexture;
52
- });
53
- // #endregion Type aliases (1)
54
- // #region Classes (1)
55
- class GeometryRestriction extends AbstractRestriction_1.AbstractRestriction {
56
- // #endregion Properties (17)
57
- // #region Constructors (1)
58
- constructor(viewport, geometryMathManager, parentNode, id, settings, properties) {
59
- var _a, _b, _c, _d, _e, _f, _g, _h;
60
- super(viewport, parentNode, id, properties);
61
- // #region Properties (17)
62
- _GeometryRestriction_eventEngine.set(this, viewer_shared_services_1.EventEngine.instance);
63
- _GeometryRestriction_rayCasterParams.set(this, {
64
- Line: { threshold: 1 },
65
- Line2: { threshold: 1 },
66
- Points: { threshold: 1 },
67
- Mesh: {},
68
- LOD: {},
69
- Sprite: {},
70
- });
71
- _GeometryRestriction_raycaster.set(this, new THREE.Raycaster());
72
- _GeometryRestriction_viewport.set(this, void 0);
73
- _GeometryRestriction_geometryMathManager.set(this, void 0);
74
- _GeometryRestriction_lineIntersectionPercentage.set(this, 0.025);
75
- _GeometryRestriction_nodes.set(this, []);
76
- _GeometryRestriction_pointIntersectionPercentage.set(this, 0.025);
77
- _GeometryRestriction_radius.set(this, void 0);
78
- _GeometryRestriction_sceneBoundingSphereRadius.set(this, 0);
79
- _GeometryRestriction_settings.set(this, void 0);
80
- _GeometryRestriction_snapRestrictions.set(this, {});
81
- _GeometryRestriction_snapToEdges.set(this, true);
82
- _GeometryRestriction_snapToEdgesRadius.set(this, void 0);
83
- _GeometryRestriction_snapToFaces.set(this, true);
84
- _GeometryRestriction_snapToVertices.set(this, true);
85
- _GeometryRestriction_snapToVerticesRadius.set(this, void 0);
86
- _GeometryRestriction_visualizationObject.set(this, new THREE.Object3D());
87
- _GeometryRestriction_wireframe.set(this, void 0);
88
- _GeometryRestriction_wireframeColor.set(this, void 0);
89
- _GeometryRestriction_wireframeDepthTest.set(this, void 0);
90
- _GeometryRestriction_wireframePointSize.set(this, void 0);
91
- __classPrivateFieldSet(this, _GeometryRestriction_viewport, viewport, "f");
92
- __classPrivateFieldSet(this, _GeometryRestriction_settings, settings, "f");
93
- __classPrivateFieldSet(this, _GeometryRestriction_geometryMathManager, geometryMathManager, "f");
94
- __classPrivateFieldSet(this, _GeometryRestriction_wireframe, (_b = (_a = properties.wireframe) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _GeometryRestriction_settings, "f").wireframe) !== null && _b !== void 0 ? _b : true, "f");
95
- __classPrivateFieldSet(this, _GeometryRestriction_wireframeColor, (_d = (_c = properties.wireframeColor) !== null && _c !== void 0 ? _c : __classPrivateFieldGet(this, _GeometryRestriction_settings, "f").wireframeColor) !== null && _d !== void 0 ? _d : __classPrivateFieldGet(this, _GeometryRestriction_settings, "f").points.color_1, "f");
96
- __classPrivateFieldSet(this, _GeometryRestriction_wireframePointSize, properties.wireframePointSize
97
- ? properties.wireframePointSize * __classPrivateFieldGet(this, _GeometryRestriction_viewport, "f").pointSize
98
- : 10 * __classPrivateFieldGet(this, _GeometryRestriction_viewport, "f").pointSize, "f");
99
- __classPrivateFieldSet(this, _GeometryRestriction_wireframeDepthTest, (_e = properties.wireframeDepthTest) !== null && _e !== void 0 ? _e : true, "f");
100
- __classPrivateFieldSet(this, _GeometryRestriction_snapToVertices, (_f = properties.snapToVertices) !== null && _f !== void 0 ? _f : true, "f");
101
- __classPrivateFieldSet(this, _GeometryRestriction_snapToEdges, (_g = properties.snapToEdges) !== null && _g !== void 0 ? _g : true, "f");
102
- __classPrivateFieldSet(this, _GeometryRestriction_snapToFaces, (_h = properties.snapToFaces) !== null && _h !== void 0 ? _h : true, "f");
103
- __classPrivateFieldSet(this, _GeometryRestriction_snapToVerticesRadius, properties.snapToVerticesRadius, "f");
104
- __classPrivateFieldSet(this, _GeometryRestriction_snapToEdgesRadius, properties.snapToEdgesRadius, "f");
105
- __classPrivateFieldSet(this, _GeometryRestriction_radius, properties.radius, "f");
106
- __classPrivateFieldSet(this, _GeometryRestriction_sceneBoundingSphereRadius, viewer_1.sceneTree.root.boundingBox.boundingSphere.radius, "f");
107
- this.updateIntersectionThresholds();
108
- __classPrivateFieldGet(this, _GeometryRestriction_eventEngine, "f").addListener(viewer_shared_services_1.EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, (e) => {
109
- const event = e;
110
- if (event.viewportId === __classPrivateFieldGet(this, _GeometryRestriction_viewport, "f").id) {
111
- const boundingBox = new viewer_shared_math_1.Box(event.boundingBox.min, event.boundingBox.max);
112
- __classPrivateFieldSet(this, _GeometryRestriction_sceneBoundingSphereRadius, boundingBox.boundingSphere.radius, "f");
113
- this.updateIntersectionThresholds();
114
- }
115
- });
116
- this.updateNodes(properties.nodes);
117
- }
118
- // #endregion Constructors (1)
119
- // #region Public Getters And Setters (8)
120
- get nodes() {
121
- return __classPrivateFieldGet(this, _GeometryRestriction_nodes, "f");
122
- }
123
- get snapRestrictions() {
124
- return __classPrivateFieldGet(this, _GeometryRestriction_snapRestrictions, "f");
125
- }
126
- get snapToEdges() {
127
- return __classPrivateFieldGet(this, _GeometryRestriction_snapToEdges, "f");
128
- }
129
- set snapToEdges(value) {
130
- __classPrivateFieldSet(this, _GeometryRestriction_snapToEdges, value, "f");
131
- }
132
- get snapToFaces() {
133
- return __classPrivateFieldGet(this, _GeometryRestriction_snapToFaces, "f");
134
- }
135
- set snapToFaces(value) {
136
- __classPrivateFieldSet(this, _GeometryRestriction_snapToFaces, value, "f");
137
- }
138
- get snapToVertices() {
139
- return __classPrivateFieldGet(this, _GeometryRestriction_snapToVertices, "f");
140
- }
141
- set snapToVertices(value) {
142
- __classPrivateFieldSet(this, _GeometryRestriction_snapToVertices, value, "f");
143
- }
144
- // #endregion Public Getters And Setters (8)
145
- // #region Public Methods (3)
146
- rayTrace(ray, metaData) {
147
- var _a, _b, _c, _d, _e, _f;
148
- if (this.enabled === false)
149
- return;
150
- if (__classPrivateFieldGet(this, _GeometryRestriction_snapToVertices, "f") === false &&
151
- __classPrivateFieldGet(this, _GeometryRestriction_snapToEdges, "f") === false &&
152
- __classPrivateFieldGet(this, _GeometryRestriction_snapToFaces, "f") === false)
153
- return;
154
- // assign raycaster parameters
155
- __classPrivateFieldGet(this, _GeometryRestriction_raycaster, "f").params = __classPrivateFieldGet(this, _GeometryRestriction_rayCasterParams, "f");
156
- __classPrivateFieldGet(this, _GeometryRestriction_raycaster, "f").ray.direction.set(ray.direction[0], ray.direction[1], ray.direction[2]);
157
- __classPrivateFieldGet(this, _GeometryRestriction_raycaster, "f").ray.origin.set(ray.origin[0], ray.origin[1], ray.origin[2]);
158
- // intersect all nodes
159
- let intersections = [];
160
- __classPrivateFieldGet(this, _GeometryRestriction_nodes, "f").forEach((node) => {
161
- const threeJsObject = node.convertedObject[__classPrivateFieldGet(this, _GeometryRestriction_viewport, "f").id];
162
- if (threeJsObject) {
163
- const currentIntersections = __classPrivateFieldGet(this, _GeometryRestriction_raycaster, "f").intersectObject(threeJsObject);
164
- intersections = intersections.concat(currentIntersections);
165
- }
166
- });
167
- // sort
168
- intersections.sort((a, b) => a.distance - b.distance);
169
- // return first intersection
170
- if (intersections.length > 0) {
171
- const object = intersections[0].object;
172
- let geometryRestrictionIntersectionData;
173
- // search the three.js object hierarchy for the converted object
174
- let tempObject = object;
175
- while (tempObject.parent) {
176
- const intersectedNode = __classPrivateFieldGet(this, _GeometryRestriction_nodes, "f").find((node) => node.id === tempObject.SDid &&
177
- node.version === tempObject.SDversion);
178
- if (intersectedNode) {
179
- // from this node, we can get the geometry data
180
- intersectedNode.traverseData((d) => {
181
- if (d instanceof viewer_shared_node_tree_1.GeometryData &&
182
- d.id === object.parent.SDid &&
183
- d.version === object.parent.SDversion) {
184
- geometryRestrictionIntersectionData = {
185
- node: intersectedNode,
186
- geometryData: d,
187
- };
188
- }
189
- });
190
- break;
191
- }
192
- tempObject = tempObject.parent;
193
- }
194
- const geometry = object.geometry;
195
- const positionAttribute = geometry.getAttribute("position");
196
- if (object instanceof THREE.Points &&
197
- intersections[0].index !== undefined) {
198
- if (!__classPrivateFieldGet(this, _GeometryRestriction_snapToVertices, "f"))
199
- return;
200
- const vertex = new THREE.Vector3();
201
- vertex.fromBufferAttribute(positionAttribute, intersections[0].index);
202
- object.localToWorld(vertex);
203
- return this.constructRestrictionResult(gl_matrix_1.vec3.fromValues(vertex.x, vertex.y, vertex.z), intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
204
- }
205
- const intersectionPoint = intersections[0].point;
206
- const intersectionPointVec3 = gl_matrix_1.vec3.fromValues(intersectionPoint.x, intersectionPoint.y, intersectionPoint.z);
207
- if (!intersections[0].face)
208
- return this.constructRestrictionResult(intersectionPointVec3, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
209
- if (__classPrivateFieldGet(this, _GeometryRestriction_snapToVertices, "f") === true || __classPrivateFieldGet(this, _GeometryRestriction_snapToEdges, "f") === true) {
210
- const vertexA = new THREE.Vector3();
211
- vertexA.fromBufferAttribute(positionAttribute, intersections[0].face.a);
212
- object.localToWorld(vertexA);
213
- const vertexAVec3 = gl_matrix_1.vec3.fromValues(vertexA.x, vertexA.y, vertexA.z);
214
- const vertexB = new THREE.Vector3();
215
- vertexB.fromBufferAttribute(positionAttribute, intersections[0].face.b);
216
- object.localToWorld(vertexB);
217
- const vertexBVec3 = gl_matrix_1.vec3.fromValues(vertexB.x, vertexB.y, vertexB.z);
218
- const vertexC = new THREE.Vector3();
219
- vertexC.fromBufferAttribute(positionAttribute, intersections[0].face.c);
220
- object.localToWorld(vertexC);
221
- const vertexCVec3 = gl_matrix_1.vec3.fromValues(vertexC.x, vertexC.y, vertexC.z);
222
- if (__classPrivateFieldGet(this, _GeometryRestriction_snapToVertices, "f") === true) {
223
- const distanceA = this.checkDistance(intersectionPointVec3, vertexAVec3, (_a = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _GeometryRestriction_snapToVerticesRadius, "f"));
224
- const distanceB = this.checkDistance(intersectionPointVec3, vertexBVec3, (_b = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _b !== void 0 ? _b : __classPrivateFieldGet(this, _GeometryRestriction_snapToVerticesRadius, "f"));
225
- const distanceC = this.checkDistance(intersectionPointVec3, vertexCVec3, (_c = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _c !== void 0 ? _c : __classPrivateFieldGet(this, _GeometryRestriction_snapToVerticesRadius, "f"));
226
- // part 1 - check if the intersection point is close to a vertex
227
- if (distanceA.check &&
228
- distanceA.distanceSquared < distanceB.distanceSquared &&
229
- distanceA.distanceSquared < distanceC.distanceSquared) {
230
- return this.constructRestrictionResult(vertexAVec3, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
231
- }
232
- else if (distanceB.check &&
233
- distanceB.distanceSquared < distanceA.distanceSquared &&
234
- distanceB.distanceSquared < distanceC.distanceSquared) {
235
- return this.constructRestrictionResult(vertexBVec3, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
236
- }
237
- else if (distanceC.check &&
238
- distanceC.distanceSquared < distanceA.distanceSquared &&
239
- distanceC.distanceSquared < distanceB.distanceSquared) {
240
- return this.constructRestrictionResult(vertexCVec3, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
241
- }
242
- }
243
- if (__classPrivateFieldGet(this, _GeometryRestriction_snapToEdges, "f") === true) {
244
- // part 2 - check if the intersection point is close to an edge
245
- // create the closest points on the edges
246
- const closestPointOnEdgeAB = __classPrivateFieldGet(this, _GeometryRestriction_geometryMathManager, "f").closestPointOnLine(vertexAVec3, vertexBVec3, intersectionPointVec3);
247
- const closestPointOnEdgeBC = __classPrivateFieldGet(this, _GeometryRestriction_geometryMathManager, "f").closestPointOnLine(vertexBVec3, vertexCVec3, intersectionPointVec3);
248
- const closestPointOnEdgeCA = __classPrivateFieldGet(this, _GeometryRestriction_geometryMathManager, "f").closestPointOnLine(vertexCVec3, vertexAVec3, intersectionPointVec3);
249
- // create the distances
250
- const distanceAB = this.checkDistance(intersectionPointVec3, closestPointOnEdgeAB, (_d = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _d !== void 0 ? _d : __classPrivateFieldGet(this, _GeometryRestriction_snapToEdgesRadius, "f"));
251
- const distanceBC = this.checkDistance(intersectionPointVec3, closestPointOnEdgeBC, (_e = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _e !== void 0 ? _e : __classPrivateFieldGet(this, _GeometryRestriction_snapToEdgesRadius, "f"));
252
- const distanceCA = this.checkDistance(intersectionPointVec3, closestPointOnEdgeCA, (_f = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _f !== void 0 ? _f : __classPrivateFieldGet(this, _GeometryRestriction_snapToEdgesRadius, "f"));
253
- // check if the intersection point is close to an edge
254
- if (distanceAB.check &&
255
- distanceAB.distanceSquared <
256
- distanceBC.distanceSquared &&
257
- distanceAB.distanceSquared < distanceCA.distanceSquared) {
258
- return this.constructRestrictionResult(closestPointOnEdgeAB, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
259
- }
260
- else if (distanceBC.check &&
261
- distanceBC.distanceSquared <
262
- distanceAB.distanceSquared &&
263
- distanceBC.distanceSquared < distanceCA.distanceSquared) {
264
- return this.constructRestrictionResult(closestPointOnEdgeBC, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
265
- }
266
- else if (distanceCA.check &&
267
- distanceCA.distanceSquared <
268
- distanceAB.distanceSquared &&
269
- distanceCA.distanceSquared < distanceBC.distanceSquared) {
270
- return this.constructRestrictionResult(closestPointOnEdgeCA, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
271
- }
272
- }
273
- }
274
- if (__classPrivateFieldGet(this, _GeometryRestriction_snapToFaces, "f") === true) {
275
- // part 3 - face intersection
276
- return this.constructRestrictionResult(gl_matrix_1.vec3.fromValues(intersectionPoint.x, intersectionPoint.y, intersectionPoint.z), intersections[0].distance, undefined, geometryRestrictionIntersectionData);
277
- }
278
- }
279
- return;
280
- }
281
- updateNodes(nodes) {
282
- __classPrivateFieldSet(this, _GeometryRestriction_nodes, nodes, "f");
283
- if (__classPrivateFieldGet(this, _GeometryRestriction_wireframe, "f")) {
284
- __classPrivateFieldGet(this, _GeometryRestriction_visualizationObject, "f").traverse((object) => {
285
- if (object instanceof THREE.LineSegments) {
286
- object.geometry.dispose();
287
- object.material.dispose();
288
- }
289
- });
290
- this._object3D.remove(__classPrivateFieldGet(this, _GeometryRestriction_visualizationObject, "f"));
291
- __classPrivateFieldSet(this, _GeometryRestriction_visualizationObject, new THREE.Object3D(), "f");
292
- __classPrivateFieldGet(this, _GeometryRestriction_nodes, "f").forEach((node) => {
293
- const threeJsObject = node.convertedObject[__classPrivateFieldGet(this, _GeometryRestriction_viewport, "f").id];
294
- if (threeJsObject) {
295
- let parent = threeJsObject.parent;
296
- while (parent) {
297
- parent.updateMatrixWorld(true);
298
- parent = parent.parent;
299
- }
300
- threeJsObject.updateMatrixWorld(true);
301
- threeJsObject.traverse((object) => {
302
- if (object instanceof THREE.Mesh) {
303
- const wireframe = new THREE.WireframeGeometry(object.geometry);
304
- const line = new THREE.LineSegments(wireframe, new THREE.LineBasicMaterial({
305
- color: new THREE.Color(__classPrivateFieldGet(this, _GeometryRestriction_wireframeColor, "f")),
306
- depthTest: __classPrivateFieldGet(this, _GeometryRestriction_wireframeDepthTest, "f"),
307
- depthWrite: !__classPrivateFieldGet(this, _GeometryRestriction_wireframeDepthTest, "f"),
308
- }));
309
- line.matrix.copy(object.matrixWorld);
310
- line.renderOrder = 100;
311
- line.matrixAutoUpdate = false;
312
- __classPrivateFieldGet(this, _GeometryRestriction_visualizationObject, "f").add(line);
313
- }
314
- else if (object instanceof THREE.Line) {
315
- const line = new THREE.Line(object.geometry, new THREE.LineBasicMaterial({
316
- color: new THREE.Color(__classPrivateFieldGet(this, _GeometryRestriction_wireframeColor, "f")),
317
- depthTest: __classPrivateFieldGet(this, _GeometryRestriction_wireframeDepthTest, "f"),
318
- depthWrite: !__classPrivateFieldGet(this, _GeometryRestriction_wireframeDepthTest, "f"),
319
- }));
320
- line.matrix.copy(object.matrixWorld);
321
- line.renderOrder = 100;
322
- line.matrixAutoUpdate = false;
323
- __classPrivateFieldGet(this, _GeometryRestriction_visualizationObject, "f").add(line);
324
- }
325
- else if (object instanceof THREE.Points) {
326
- const height = __classPrivateFieldGet(this, _GeometryRestriction_viewport, "f").canvas.height;
327
- const pointSize = __classPrivateFieldGet(this, _GeometryRestriction_wireframePointSize, "f") * (height / 1080);
328
- const points = new THREE.Points(object.geometry, new THREE.PointsMaterial(Object.assign({ color: new THREE.Color(__classPrivateFieldGet(this, _GeometryRestriction_wireframeColor, "f")), size: pointSize, sizeAttenuation: false, depthTest: __classPrivateFieldGet(this, _GeometryRestriction_wireframeDepthTest, "f"), depthWrite: !__classPrivateFieldGet(this, _GeometryRestriction_wireframeDepthTest, "f"), transparent: true }, (pointTexture instanceof THREE.Texture
329
- ? { map: pointTexture }
330
- : {}))));
331
- points.matrix.copy(object.matrixWorld);
332
- points.renderOrder = 100;
333
- points.matrixAutoUpdate = false;
334
- __classPrivateFieldGet(this, _GeometryRestriction_visualizationObject, "f").add(points);
335
- }
336
- });
337
- }
338
- });
339
- this._object3D.add(__classPrivateFieldGet(this, _GeometryRestriction_visualizationObject, "f"));
340
- }
341
- }
342
- // #endregion Public Methods (3)
343
- // #region Protected Methods (1)
344
- visibilityChanged() { }
345
- // #endregion Protected Methods (1)
346
- // #region Private Methods (1)
347
- updateIntersectionThresholds() {
348
- var _a, _b, _c;
349
- __classPrivateFieldGet(this, _GeometryRestriction_rayCasterParams, "f").Points.threshold =
350
- (_a = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _GeometryRestriction_sceneBoundingSphereRadius, "f") * __classPrivateFieldGet(this, _GeometryRestriction_pointIntersectionPercentage, "f");
351
- __classPrivateFieldGet(this, _GeometryRestriction_rayCasterParams, "f").Line.threshold =
352
- (_b = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _b !== void 0 ? _b : __classPrivateFieldGet(this, _GeometryRestriction_sceneBoundingSphereRadius, "f") * __classPrivateFieldGet(this, _GeometryRestriction_lineIntersectionPercentage, "f");
353
- __classPrivateFieldGet(this, _GeometryRestriction_rayCasterParams, "f").Line2.threshold =
354
- (_c = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _c !== void 0 ? _c : __classPrivateFieldGet(this, _GeometryRestriction_sceneBoundingSphereRadius, "f") * __classPrivateFieldGet(this, _GeometryRestriction_lineIntersectionPercentage, "f");
355
- }
356
- constructRestrictionResult(targetPoint, distanceOriginToClosestIntersectionPoint, closestPointOnRay, geometryRestrictionIntersectionData) {
357
- const closestPointOnRayVec3 = closestPointOnRay
358
- ? gl_matrix_1.vec3.fromValues(closestPointOnRay.x, closestPointOnRay.y, closestPointOnRay.z)
359
- : targetPoint;
360
- return {
361
- closestIntersectionPoint: closestPointOnRay
362
- ? gl_matrix_1.vec3.fromValues(closestPointOnRay.x, closestPointOnRay.y, closestPointOnRay.z)
363
- : targetPoint,
364
- distanceOriginToClosestIntersectionPointSquared: distanceOriginToClosestIntersectionPoint *
365
- distanceOriginToClosestIntersectionPoint,
366
- targetPoint,
367
- distanceClosestPointToTargetPointSquared: closestPointOnRayVec3 !== targetPoint
368
- ? gl_matrix_1.vec3.sqrDist(closestPointOnRayVec3, targetPoint)
369
- : 0,
370
- restriction: this,
371
- restrictionIntersectionData: geometryRestrictionIntersectionData,
372
- };
373
- }
374
- /**
375
- * We check the distance between two points.
376
- * If a radius is given, we check if the distance is smaller than the radius.
377
- * If no radius is given, we move to the screen space distance check.
378
- *
379
- * @param point1
380
- * @param point2
381
- * @param radius
382
- * @returns
383
- */
384
- checkDistance(point1, point2, radius) {
385
- if (radius !== undefined) {
386
- const distance = gl_matrix_1.vec3.sqrDist(point1, point2);
387
- return {
388
- distanceSquared: distance * distance,
389
- check: distance < radius,
390
- };
391
- }
392
- else {
393
- return __classPrivateFieldGet(this, _GeometryRestriction_geometryMathManager, "f").screenSpaceDistanceCheck(point1, point2, __classPrivateFieldGet(this, _GeometryRestriction_settings, "f").points.size_0 *
394
- __classPrivateFieldGet(this, _GeometryRestriction_settings, "f").distanceMultiplicationFactor);
395
- }
396
- }
397
- }
398
- exports.GeometryRestriction = GeometryRestriction;
399
- _GeometryRestriction_eventEngine = new WeakMap(), _GeometryRestriction_rayCasterParams = new WeakMap(), _GeometryRestriction_raycaster = new WeakMap(), _GeometryRestriction_viewport = new WeakMap(), _GeometryRestriction_geometryMathManager = new WeakMap(), _GeometryRestriction_lineIntersectionPercentage = new WeakMap(), _GeometryRestriction_nodes = new WeakMap(), _GeometryRestriction_pointIntersectionPercentage = new WeakMap(), _GeometryRestriction_radius = new WeakMap(), _GeometryRestriction_sceneBoundingSphereRadius = new WeakMap(), _GeometryRestriction_settings = new WeakMap(), _GeometryRestriction_snapRestrictions = new WeakMap(), _GeometryRestriction_snapToEdges = new WeakMap(), _GeometryRestriction_snapToEdgesRadius = new WeakMap(), _GeometryRestriction_snapToFaces = new WeakMap(), _GeometryRestriction_snapToVertices = new WeakMap(), _GeometryRestriction_snapToVerticesRadius = new WeakMap(), _GeometryRestriction_visualizationObject = new WeakMap(), _GeometryRestriction_wireframe = new WeakMap(), _GeometryRestriction_wireframeColor = new WeakMap(), _GeometryRestriction_wireframeDepthTest = new WeakMap(), _GeometryRestriction_wireframePointSize = new WeakMap();
400
- // #endregion Classes (1)
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
36
+ if (kind === "m") throw new TypeError("Private method is not writable");
37
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
38
+ 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");
39
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
40
+ };
41
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
42
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
43
+ 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");
44
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
45
+ };
46
+ var _GeometryRestriction_eventEngine, _GeometryRestriction_rayCasterParams, _GeometryRestriction_raycaster, _GeometryRestriction_viewport, _GeometryRestriction_geometryMathManager, _GeometryRestriction_lineIntersectionPercentage, _GeometryRestriction_nodes, _GeometryRestriction_pointIntersectionPercentage, _GeometryRestriction_radius, _GeometryRestriction_sceneBoundingSphereRadius, _GeometryRestriction_settings, _GeometryRestriction_snapRestrictions, _GeometryRestriction_snapToEdges, _GeometryRestriction_snapToEdgesRadius, _GeometryRestriction_snapToFaces, _GeometryRestriction_snapToVertices, _GeometryRestriction_snapToVerticesRadius, _GeometryRestriction_visualizationObject, _GeometryRestriction_wireframe, _GeometryRestriction_wireframeColor, _GeometryRestriction_wireframeDepthTest, _GeometryRestriction_wireframePointSize;
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.GeometryRestriction = void 0;
49
+ const viewer_1 = require("@shapediver/viewer");
50
+ const viewer_shared_math_1 = require("@shapediver/viewer.shared.math");
51
+ const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
52
+ const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
53
+ const gl_matrix_1 = require("gl-matrix");
54
+ const THREE = __importStar(require("three"));
55
+ const AbstractRestriction_1 = require("../AbstractRestriction");
56
+ let pointTexture = viewer_1.MaterialEngine.instance
57
+ .loadMap("https://viewer.shapediver.com/v3/graphics/point_soft.png")
58
+ .then((mapData) => {
59
+ pointTexture = new THREE.Texture(mapData.image);
60
+ pointTexture.needsUpdate = true;
61
+ return pointTexture;
62
+ });
63
+ // #endregion Type aliases (1)
64
+ // #region Classes (1)
65
+ class GeometryRestriction extends AbstractRestriction_1.AbstractRestriction {
66
+ // #endregion Properties (17)
67
+ // #region Constructors (1)
68
+ constructor(viewport, geometryMathManager, parentNode, id, settings, properties) {
69
+ var _a, _b, _c, _d, _e, _f, _g, _h;
70
+ super(viewport, parentNode, id, properties);
71
+ // #region Properties (17)
72
+ _GeometryRestriction_eventEngine.set(this, viewer_shared_services_1.EventEngine.instance);
73
+ _GeometryRestriction_rayCasterParams.set(this, {
74
+ Line: { threshold: 1 },
75
+ Line2: { threshold: 1 },
76
+ Points: { threshold: 1 },
77
+ Mesh: {},
78
+ LOD: {},
79
+ Sprite: {},
80
+ });
81
+ _GeometryRestriction_raycaster.set(this, new THREE.Raycaster());
82
+ _GeometryRestriction_viewport.set(this, void 0);
83
+ _GeometryRestriction_geometryMathManager.set(this, void 0);
84
+ _GeometryRestriction_lineIntersectionPercentage.set(this, 0.025);
85
+ _GeometryRestriction_nodes.set(this, []);
86
+ _GeometryRestriction_pointIntersectionPercentage.set(this, 0.025);
87
+ _GeometryRestriction_radius.set(this, void 0);
88
+ _GeometryRestriction_sceneBoundingSphereRadius.set(this, 0);
89
+ _GeometryRestriction_settings.set(this, void 0);
90
+ _GeometryRestriction_snapRestrictions.set(this, {});
91
+ _GeometryRestriction_snapToEdges.set(this, true);
92
+ _GeometryRestriction_snapToEdgesRadius.set(this, void 0);
93
+ _GeometryRestriction_snapToFaces.set(this, true);
94
+ _GeometryRestriction_snapToVertices.set(this, true);
95
+ _GeometryRestriction_snapToVerticesRadius.set(this, void 0);
96
+ _GeometryRestriction_visualizationObject.set(this, new THREE.Object3D());
97
+ _GeometryRestriction_wireframe.set(this, void 0);
98
+ _GeometryRestriction_wireframeColor.set(this, void 0);
99
+ _GeometryRestriction_wireframeDepthTest.set(this, void 0);
100
+ _GeometryRestriction_wireframePointSize.set(this, void 0);
101
+ __classPrivateFieldSet(this, _GeometryRestriction_viewport, viewport, "f");
102
+ __classPrivateFieldSet(this, _GeometryRestriction_settings, settings, "f");
103
+ __classPrivateFieldSet(this, _GeometryRestriction_geometryMathManager, geometryMathManager, "f");
104
+ __classPrivateFieldSet(this, _GeometryRestriction_wireframe, (_b = (_a = properties.wireframe) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _GeometryRestriction_settings, "f").wireframe) !== null && _b !== void 0 ? _b : true, "f");
105
+ __classPrivateFieldSet(this, _GeometryRestriction_wireframeColor, (_d = (_c = properties.wireframeColor) !== null && _c !== void 0 ? _c : __classPrivateFieldGet(this, _GeometryRestriction_settings, "f").wireframeColor) !== null && _d !== void 0 ? _d : __classPrivateFieldGet(this, _GeometryRestriction_settings, "f").points.color_1, "f");
106
+ __classPrivateFieldSet(this, _GeometryRestriction_wireframePointSize, properties.wireframePointSize
107
+ ? properties.wireframePointSize * __classPrivateFieldGet(this, _GeometryRestriction_viewport, "f").pointSize
108
+ : 10 * __classPrivateFieldGet(this, _GeometryRestriction_viewport, "f").pointSize, "f");
109
+ __classPrivateFieldSet(this, _GeometryRestriction_wireframeDepthTest, (_e = properties.wireframeDepthTest) !== null && _e !== void 0 ? _e : true, "f");
110
+ __classPrivateFieldSet(this, _GeometryRestriction_snapToVertices, (_f = properties.snapToVertices) !== null && _f !== void 0 ? _f : true, "f");
111
+ __classPrivateFieldSet(this, _GeometryRestriction_snapToEdges, (_g = properties.snapToEdges) !== null && _g !== void 0 ? _g : true, "f");
112
+ __classPrivateFieldSet(this, _GeometryRestriction_snapToFaces, (_h = properties.snapToFaces) !== null && _h !== void 0 ? _h : true, "f");
113
+ __classPrivateFieldSet(this, _GeometryRestriction_snapToVerticesRadius, properties.snapToVerticesRadius, "f");
114
+ __classPrivateFieldSet(this, _GeometryRestriction_snapToEdgesRadius, properties.snapToEdgesRadius, "f");
115
+ __classPrivateFieldSet(this, _GeometryRestriction_radius, properties.radius, "f");
116
+ __classPrivateFieldSet(this, _GeometryRestriction_sceneBoundingSphereRadius, viewer_1.sceneTree.root.boundingBox.boundingSphere.radius, "f");
117
+ this.updateIntersectionThresholds();
118
+ __classPrivateFieldGet(this, _GeometryRestriction_eventEngine, "f").addListener(viewer_shared_services_1.EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, (e) => {
119
+ const event = e;
120
+ if (event.viewportId === __classPrivateFieldGet(this, _GeometryRestriction_viewport, "f").id) {
121
+ const boundingBox = new viewer_shared_math_1.Box(event.boundingBox.min, event.boundingBox.max);
122
+ __classPrivateFieldSet(this, _GeometryRestriction_sceneBoundingSphereRadius, boundingBox.boundingSphere.radius, "f");
123
+ this.updateIntersectionThresholds();
124
+ }
125
+ });
126
+ this.updateNodes(properties.nodes);
127
+ }
128
+ // #endregion Constructors (1)
129
+ // #region Public Getters And Setters (8)
130
+ get nodes() {
131
+ return __classPrivateFieldGet(this, _GeometryRestriction_nodes, "f");
132
+ }
133
+ get snapRestrictions() {
134
+ return __classPrivateFieldGet(this, _GeometryRestriction_snapRestrictions, "f");
135
+ }
136
+ get snapToEdges() {
137
+ return __classPrivateFieldGet(this, _GeometryRestriction_snapToEdges, "f");
138
+ }
139
+ set snapToEdges(value) {
140
+ __classPrivateFieldSet(this, _GeometryRestriction_snapToEdges, value, "f");
141
+ }
142
+ get snapToFaces() {
143
+ return __classPrivateFieldGet(this, _GeometryRestriction_snapToFaces, "f");
144
+ }
145
+ set snapToFaces(value) {
146
+ __classPrivateFieldSet(this, _GeometryRestriction_snapToFaces, value, "f");
147
+ }
148
+ get snapToVertices() {
149
+ return __classPrivateFieldGet(this, _GeometryRestriction_snapToVertices, "f");
150
+ }
151
+ set snapToVertices(value) {
152
+ __classPrivateFieldSet(this, _GeometryRestriction_snapToVertices, value, "f");
153
+ }
154
+ // #endregion Public Getters And Setters (8)
155
+ // #region Public Methods (3)
156
+ rayTrace(ray, metaData) {
157
+ var _a, _b, _c, _d, _e, _f;
158
+ if (this.enabled === false)
159
+ return;
160
+ if (__classPrivateFieldGet(this, _GeometryRestriction_snapToVertices, "f") === false &&
161
+ __classPrivateFieldGet(this, _GeometryRestriction_snapToEdges, "f") === false &&
162
+ __classPrivateFieldGet(this, _GeometryRestriction_snapToFaces, "f") === false)
163
+ return;
164
+ // assign raycaster parameters
165
+ __classPrivateFieldGet(this, _GeometryRestriction_raycaster, "f").params = __classPrivateFieldGet(this, _GeometryRestriction_rayCasterParams, "f");
166
+ __classPrivateFieldGet(this, _GeometryRestriction_raycaster, "f").ray.direction.set(ray.direction[0], ray.direction[1], ray.direction[2]);
167
+ __classPrivateFieldGet(this, _GeometryRestriction_raycaster, "f").ray.origin.set(ray.origin[0], ray.origin[1], ray.origin[2]);
168
+ // intersect all nodes
169
+ let intersections = [];
170
+ __classPrivateFieldGet(this, _GeometryRestriction_nodes, "f").forEach((node) => {
171
+ const threeJsObject = node.convertedObject[__classPrivateFieldGet(this, _GeometryRestriction_viewport, "f").id];
172
+ if (threeJsObject) {
173
+ const currentIntersections = __classPrivateFieldGet(this, _GeometryRestriction_raycaster, "f").intersectObject(threeJsObject);
174
+ intersections = intersections.concat(currentIntersections);
175
+ }
176
+ });
177
+ // sort
178
+ intersections.sort((a, b) => a.distance - b.distance);
179
+ // return first intersection
180
+ if (intersections.length > 0) {
181
+ const object = intersections[0].object;
182
+ let geometryRestrictionIntersectionData;
183
+ // search the three.js object hierarchy for the converted object
184
+ let tempObject = object;
185
+ while (tempObject.parent) {
186
+ const intersectedNode = __classPrivateFieldGet(this, _GeometryRestriction_nodes, "f").find((node) => node.id === tempObject.SDid &&
187
+ node.version === tempObject.SDversion);
188
+ if (intersectedNode) {
189
+ // from this node, we can get the geometry data
190
+ intersectedNode.traverseData((d) => {
191
+ if (d instanceof viewer_shared_node_tree_1.GeometryData &&
192
+ d.id === object.parent.SDid &&
193
+ d.version === object.parent.SDversion) {
194
+ geometryRestrictionIntersectionData = {
195
+ node: intersectedNode,
196
+ geometryData: d,
197
+ };
198
+ }
199
+ });
200
+ break;
201
+ }
202
+ tempObject = tempObject.parent;
203
+ }
204
+ const geometry = object.geometry;
205
+ const positionAttribute = geometry.getAttribute("position");
206
+ if (object instanceof THREE.Points &&
207
+ intersections[0].index !== undefined) {
208
+ if (!__classPrivateFieldGet(this, _GeometryRestriction_snapToVertices, "f"))
209
+ return;
210
+ const vertex = new THREE.Vector3();
211
+ vertex.fromBufferAttribute(positionAttribute, intersections[0].index);
212
+ object.localToWorld(vertex);
213
+ return this.constructRestrictionResult(gl_matrix_1.vec3.fromValues(vertex.x, vertex.y, vertex.z), intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
214
+ }
215
+ const intersectionPoint = intersections[0].point;
216
+ const intersectionPointVec3 = gl_matrix_1.vec3.fromValues(intersectionPoint.x, intersectionPoint.y, intersectionPoint.z);
217
+ if (!intersections[0].face)
218
+ return this.constructRestrictionResult(intersectionPointVec3, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
219
+ if (__classPrivateFieldGet(this, _GeometryRestriction_snapToVertices, "f") === true || __classPrivateFieldGet(this, _GeometryRestriction_snapToEdges, "f") === true) {
220
+ const vertexA = new THREE.Vector3();
221
+ vertexA.fromBufferAttribute(positionAttribute, intersections[0].face.a);
222
+ object.localToWorld(vertexA);
223
+ const vertexAVec3 = gl_matrix_1.vec3.fromValues(vertexA.x, vertexA.y, vertexA.z);
224
+ const vertexB = new THREE.Vector3();
225
+ vertexB.fromBufferAttribute(positionAttribute, intersections[0].face.b);
226
+ object.localToWorld(vertexB);
227
+ const vertexBVec3 = gl_matrix_1.vec3.fromValues(vertexB.x, vertexB.y, vertexB.z);
228
+ const vertexC = new THREE.Vector3();
229
+ vertexC.fromBufferAttribute(positionAttribute, intersections[0].face.c);
230
+ object.localToWorld(vertexC);
231
+ const vertexCVec3 = gl_matrix_1.vec3.fromValues(vertexC.x, vertexC.y, vertexC.z);
232
+ if (__classPrivateFieldGet(this, _GeometryRestriction_snapToVertices, "f") === true) {
233
+ const distanceA = this.checkDistance(intersectionPointVec3, vertexAVec3, (_a = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _GeometryRestriction_snapToVerticesRadius, "f"));
234
+ const distanceB = this.checkDistance(intersectionPointVec3, vertexBVec3, (_b = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _b !== void 0 ? _b : __classPrivateFieldGet(this, _GeometryRestriction_snapToVerticesRadius, "f"));
235
+ const distanceC = this.checkDistance(intersectionPointVec3, vertexCVec3, (_c = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _c !== void 0 ? _c : __classPrivateFieldGet(this, _GeometryRestriction_snapToVerticesRadius, "f"));
236
+ // part 1 - check if the intersection point is close to a vertex
237
+ if (distanceA.check &&
238
+ distanceA.distanceSquared < distanceB.distanceSquared &&
239
+ distanceA.distanceSquared < distanceC.distanceSquared) {
240
+ return this.constructRestrictionResult(vertexAVec3, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
241
+ }
242
+ else if (distanceB.check &&
243
+ distanceB.distanceSquared < distanceA.distanceSquared &&
244
+ distanceB.distanceSquared < distanceC.distanceSquared) {
245
+ return this.constructRestrictionResult(vertexBVec3, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
246
+ }
247
+ else if (distanceC.check &&
248
+ distanceC.distanceSquared < distanceA.distanceSquared &&
249
+ distanceC.distanceSquared < distanceB.distanceSquared) {
250
+ return this.constructRestrictionResult(vertexCVec3, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
251
+ }
252
+ }
253
+ if (__classPrivateFieldGet(this, _GeometryRestriction_snapToEdges, "f") === true) {
254
+ // part 2 - check if the intersection point is close to an edge
255
+ // create the closest points on the edges
256
+ const closestPointOnEdgeAB = __classPrivateFieldGet(this, _GeometryRestriction_geometryMathManager, "f").closestPointOnLine(vertexAVec3, vertexBVec3, intersectionPointVec3);
257
+ const closestPointOnEdgeBC = __classPrivateFieldGet(this, _GeometryRestriction_geometryMathManager, "f").closestPointOnLine(vertexBVec3, vertexCVec3, intersectionPointVec3);
258
+ const closestPointOnEdgeCA = __classPrivateFieldGet(this, _GeometryRestriction_geometryMathManager, "f").closestPointOnLine(vertexCVec3, vertexAVec3, intersectionPointVec3);
259
+ // create the distances
260
+ const distanceAB = this.checkDistance(intersectionPointVec3, closestPointOnEdgeAB, (_d = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _d !== void 0 ? _d : __classPrivateFieldGet(this, _GeometryRestriction_snapToEdgesRadius, "f"));
261
+ const distanceBC = this.checkDistance(intersectionPointVec3, closestPointOnEdgeBC, (_e = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _e !== void 0 ? _e : __classPrivateFieldGet(this, _GeometryRestriction_snapToEdgesRadius, "f"));
262
+ const distanceCA = this.checkDistance(intersectionPointVec3, closestPointOnEdgeCA, (_f = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _f !== void 0 ? _f : __classPrivateFieldGet(this, _GeometryRestriction_snapToEdgesRadius, "f"));
263
+ // check if the intersection point is close to an edge
264
+ if (distanceAB.check &&
265
+ distanceAB.distanceSquared <
266
+ distanceBC.distanceSquared &&
267
+ distanceAB.distanceSquared < distanceCA.distanceSquared) {
268
+ return this.constructRestrictionResult(closestPointOnEdgeAB, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
269
+ }
270
+ else if (distanceBC.check &&
271
+ distanceBC.distanceSquared <
272
+ distanceAB.distanceSquared &&
273
+ distanceBC.distanceSquared < distanceCA.distanceSquared) {
274
+ return this.constructRestrictionResult(closestPointOnEdgeBC, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
275
+ }
276
+ else if (distanceCA.check &&
277
+ distanceCA.distanceSquared <
278
+ distanceAB.distanceSquared &&
279
+ distanceCA.distanceSquared < distanceBC.distanceSquared) {
280
+ return this.constructRestrictionResult(closestPointOnEdgeCA, intersections[0].distance, intersections[0].pointOnLine, geometryRestrictionIntersectionData);
281
+ }
282
+ }
283
+ }
284
+ if (__classPrivateFieldGet(this, _GeometryRestriction_snapToFaces, "f") === true) {
285
+ // part 3 - face intersection
286
+ return this.constructRestrictionResult(gl_matrix_1.vec3.fromValues(intersectionPoint.x, intersectionPoint.y, intersectionPoint.z), intersections[0].distance, undefined, geometryRestrictionIntersectionData);
287
+ }
288
+ }
289
+ return;
290
+ }
291
+ updateNodes(nodes) {
292
+ __classPrivateFieldSet(this, _GeometryRestriction_nodes, nodes, "f");
293
+ if (__classPrivateFieldGet(this, _GeometryRestriction_wireframe, "f")) {
294
+ __classPrivateFieldGet(this, _GeometryRestriction_visualizationObject, "f").traverse((object) => {
295
+ if (object instanceof THREE.LineSegments) {
296
+ object.geometry.dispose();
297
+ object.material.dispose();
298
+ }
299
+ });
300
+ this._object3D.remove(__classPrivateFieldGet(this, _GeometryRestriction_visualizationObject, "f"));
301
+ __classPrivateFieldSet(this, _GeometryRestriction_visualizationObject, new THREE.Object3D(), "f");
302
+ __classPrivateFieldGet(this, _GeometryRestriction_nodes, "f").forEach((node) => {
303
+ const threeJsObject = node.convertedObject[__classPrivateFieldGet(this, _GeometryRestriction_viewport, "f").id];
304
+ if (threeJsObject) {
305
+ let parent = threeJsObject.parent;
306
+ while (parent) {
307
+ parent.updateMatrixWorld(true);
308
+ parent = parent.parent;
309
+ }
310
+ threeJsObject.updateMatrixWorld(true);
311
+ threeJsObject.traverse((object) => {
312
+ if (object instanceof THREE.Mesh) {
313
+ const wireframe = new THREE.WireframeGeometry(object.geometry);
314
+ const line = new THREE.LineSegments(wireframe, new THREE.LineBasicMaterial({
315
+ color: new THREE.Color(__classPrivateFieldGet(this, _GeometryRestriction_wireframeColor, "f")),
316
+ depthTest: __classPrivateFieldGet(this, _GeometryRestriction_wireframeDepthTest, "f"),
317
+ depthWrite: !__classPrivateFieldGet(this, _GeometryRestriction_wireframeDepthTest, "f"),
318
+ }));
319
+ line.matrix.copy(object.matrixWorld);
320
+ line.renderOrder = 100;
321
+ line.matrixAutoUpdate = false;
322
+ __classPrivateFieldGet(this, _GeometryRestriction_visualizationObject, "f").add(line);
323
+ }
324
+ else if (object instanceof THREE.Line) {
325
+ const line = new THREE.Line(object.geometry, new THREE.LineBasicMaterial({
326
+ color: new THREE.Color(__classPrivateFieldGet(this, _GeometryRestriction_wireframeColor, "f")),
327
+ depthTest: __classPrivateFieldGet(this, _GeometryRestriction_wireframeDepthTest, "f"),
328
+ depthWrite: !__classPrivateFieldGet(this, _GeometryRestriction_wireframeDepthTest, "f"),
329
+ }));
330
+ line.matrix.copy(object.matrixWorld);
331
+ line.renderOrder = 100;
332
+ line.matrixAutoUpdate = false;
333
+ __classPrivateFieldGet(this, _GeometryRestriction_visualizationObject, "f").add(line);
334
+ }
335
+ else if (object instanceof THREE.Points) {
336
+ const height = __classPrivateFieldGet(this, _GeometryRestriction_viewport, "f").canvas.height;
337
+ const pointSize = __classPrivateFieldGet(this, _GeometryRestriction_wireframePointSize, "f") * (height / 1080);
338
+ const points = new THREE.Points(object.geometry, new THREE.PointsMaterial(Object.assign({ color: new THREE.Color(__classPrivateFieldGet(this, _GeometryRestriction_wireframeColor, "f")), size: pointSize, sizeAttenuation: false, depthTest: __classPrivateFieldGet(this, _GeometryRestriction_wireframeDepthTest, "f"), depthWrite: !__classPrivateFieldGet(this, _GeometryRestriction_wireframeDepthTest, "f"), transparent: true }, (pointTexture instanceof THREE.Texture
339
+ ? { map: pointTexture }
340
+ : {}))));
341
+ points.matrix.copy(object.matrixWorld);
342
+ points.renderOrder = 100;
343
+ points.matrixAutoUpdate = false;
344
+ __classPrivateFieldGet(this, _GeometryRestriction_visualizationObject, "f").add(points);
345
+ }
346
+ });
347
+ }
348
+ });
349
+ this._object3D.add(__classPrivateFieldGet(this, _GeometryRestriction_visualizationObject, "f"));
350
+ }
351
+ }
352
+ // #endregion Public Methods (3)
353
+ // #region Protected Methods (1)
354
+ visibilityChanged() { }
355
+ // #endregion Protected Methods (1)
356
+ // #region Private Methods (1)
357
+ updateIntersectionThresholds() {
358
+ var _a, _b, _c;
359
+ __classPrivateFieldGet(this, _GeometryRestriction_rayCasterParams, "f").Points.threshold =
360
+ (_a = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _GeometryRestriction_sceneBoundingSphereRadius, "f") * __classPrivateFieldGet(this, _GeometryRestriction_pointIntersectionPercentage, "f");
361
+ __classPrivateFieldGet(this, _GeometryRestriction_rayCasterParams, "f").Line.threshold =
362
+ (_b = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _b !== void 0 ? _b : __classPrivateFieldGet(this, _GeometryRestriction_sceneBoundingSphereRadius, "f") * __classPrivateFieldGet(this, _GeometryRestriction_lineIntersectionPercentage, "f");
363
+ __classPrivateFieldGet(this, _GeometryRestriction_rayCasterParams, "f").Line2.threshold =
364
+ (_c = __classPrivateFieldGet(this, _GeometryRestriction_radius, "f")) !== null && _c !== void 0 ? _c : __classPrivateFieldGet(this, _GeometryRestriction_sceneBoundingSphereRadius, "f") * __classPrivateFieldGet(this, _GeometryRestriction_lineIntersectionPercentage, "f");
365
+ }
366
+ constructRestrictionResult(targetPoint, distanceOriginToClosestIntersectionPoint, closestPointOnRay, geometryRestrictionIntersectionData) {
367
+ const closestPointOnRayVec3 = closestPointOnRay
368
+ ? gl_matrix_1.vec3.fromValues(closestPointOnRay.x, closestPointOnRay.y, closestPointOnRay.z)
369
+ : targetPoint;
370
+ return {
371
+ closestIntersectionPoint: closestPointOnRay
372
+ ? gl_matrix_1.vec3.fromValues(closestPointOnRay.x, closestPointOnRay.y, closestPointOnRay.z)
373
+ : targetPoint,
374
+ distanceOriginToClosestIntersectionPointSquared: distanceOriginToClosestIntersectionPoint *
375
+ distanceOriginToClosestIntersectionPoint,
376
+ targetPoint,
377
+ distanceClosestPointToTargetPointSquared: closestPointOnRayVec3 !== targetPoint
378
+ ? gl_matrix_1.vec3.sqrDist(closestPointOnRayVec3, targetPoint)
379
+ : 0,
380
+ restriction: this,
381
+ restrictionIntersectionData: geometryRestrictionIntersectionData,
382
+ };
383
+ }
384
+ /**
385
+ * We check the distance between two points.
386
+ * If a radius is given, we check if the distance is smaller than the radius.
387
+ * If no radius is given, we move to the screen space distance check.
388
+ *
389
+ * @param point1
390
+ * @param point2
391
+ * @param radius
392
+ * @returns
393
+ */
394
+ checkDistance(point1, point2, radius) {
395
+ if (radius !== undefined) {
396
+ const distance = gl_matrix_1.vec3.sqrDist(point1, point2);
397
+ return {
398
+ distanceSquared: distance * distance,
399
+ check: distance < radius,
400
+ };
401
+ }
402
+ else {
403
+ return __classPrivateFieldGet(this, _GeometryRestriction_geometryMathManager, "f").screenSpaceDistanceCheck(point1, point2, __classPrivateFieldGet(this, _GeometryRestriction_settings, "f").points.size_0 *
404
+ __classPrivateFieldGet(this, _GeometryRestriction_settings, "f").distanceMultiplicationFactor);
405
+ }
406
+ }
407
+ }
408
+ exports.GeometryRestriction = GeometryRestriction;
409
+ _GeometryRestriction_eventEngine = new WeakMap(), _GeometryRestriction_rayCasterParams = new WeakMap(), _GeometryRestriction_raycaster = new WeakMap(), _GeometryRestriction_viewport = new WeakMap(), _GeometryRestriction_geometryMathManager = new WeakMap(), _GeometryRestriction_lineIntersectionPercentage = new WeakMap(), _GeometryRestriction_nodes = new WeakMap(), _GeometryRestriction_pointIntersectionPercentage = new WeakMap(), _GeometryRestriction_radius = new WeakMap(), _GeometryRestriction_sceneBoundingSphereRadius = new WeakMap(), _GeometryRestriction_settings = new WeakMap(), _GeometryRestriction_snapRestrictions = new WeakMap(), _GeometryRestriction_snapToEdges = new WeakMap(), _GeometryRestriction_snapToEdgesRadius = new WeakMap(), _GeometryRestriction_snapToFaces = new WeakMap(), _GeometryRestriction_snapToVertices = new WeakMap(), _GeometryRestriction_snapToVerticesRadius = new WeakMap(), _GeometryRestriction_visualizationObject = new WeakMap(), _GeometryRestriction_wireframe = new WeakMap(), _GeometryRestriction_wireframeColor = new WeakMap(), _GeometryRestriction_wireframeDepthTest = new WeakMap(), _GeometryRestriction_wireframePointSize = new WeakMap();
410
+ // #endregion Classes (1)
401
411
  //# sourceMappingURL=GeometryRestriction.js.map