@shapediver/viewer.rendering-engine.intersection-engine 3.3.3 → 3.3.6
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/package.json +9 -10
- package/src/implementation/IntersectionEngine.ts +0 -170
- package/src/index.ts +0 -14
- package/src/interfaces/IIntersection.ts +0 -14
- package/src/interfaces/IIntersectionEngine.ts +0 -12
- package/src/interfaces/IIntersectionFilter.ts +0 -5
- package/src/interfaces/IRay.ts +0 -6
- package/tsconfig.json +0 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapediver/viewer.rendering-engine.intersection-engine",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Michael Oppitz <michael@shapediver.com>",
|
|
@@ -10,11 +10,10 @@
|
|
|
10
10
|
"test": "__tests__"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
|
-
"dist",
|
|
14
|
-
"src",
|
|
15
13
|
"package.json",
|
|
14
|
+
"dist/",
|
|
16
15
|
"README.md",
|
|
17
|
-
"
|
|
16
|
+
"LICENSE"
|
|
18
17
|
],
|
|
19
18
|
"publishConfig": {
|
|
20
19
|
"access": "public"
|
|
@@ -39,15 +38,15 @@
|
|
|
39
38
|
"testEnvironment": "node"
|
|
40
39
|
},
|
|
41
40
|
"dependencies": {
|
|
42
|
-
"@shapediver/viewer.rendering-engine.rendering-engine": "3.3.
|
|
43
|
-
"@shapediver/viewer.shared.math": "3.3.
|
|
44
|
-
"@shapediver/viewer.shared.node-tree": "3.3.
|
|
45
|
-
"@shapediver/viewer.shared.services": "3.3.
|
|
46
|
-
"@shapediver/viewer.shared.types": "3.3.
|
|
41
|
+
"@shapediver/viewer.rendering-engine.rendering-engine": "3.3.6",
|
|
42
|
+
"@shapediver/viewer.shared.math": "3.3.6",
|
|
43
|
+
"@shapediver/viewer.shared.node-tree": "3.3.6",
|
|
44
|
+
"@shapediver/viewer.shared.services": "3.3.6",
|
|
45
|
+
"@shapediver/viewer.shared.types": "3.3.6",
|
|
47
46
|
"@types/three": "0.162.0",
|
|
48
47
|
"detect-it": "4.0.1",
|
|
49
48
|
"gl-matrix": "3.3.0",
|
|
50
49
|
"three": "0.162.0"
|
|
51
50
|
},
|
|
52
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "13aea937b128a001e6e93be300674c4a04624c29"
|
|
53
52
|
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import { EventEngine, EVENTTYPE } from '@shapediver/viewer.shared.services';
|
|
3
|
-
import { GeometryData } from '@shapediver/viewer.shared.types';
|
|
4
|
-
import { IIntersection } from '../interfaces/IIntersection';
|
|
5
|
-
import { IIntersectionEngine } from '../interfaces/IIntersectionEngine';
|
|
6
|
-
import { IIntersectionFilter } from '../interfaces/IIntersectionFilter';
|
|
7
|
-
import { IRay } from '../interfaces/IRay';
|
|
8
|
-
import { ITree, ITreeNode, Tree } from '@shapediver/viewer.shared.node-tree';
|
|
9
|
-
|
|
10
|
-
export class IntersectionEngine implements IIntersectionEngine {
|
|
11
|
-
// #region Properties (5)
|
|
12
|
-
|
|
13
|
-
private readonly _eventEngine: EventEngine = EventEngine.instance;
|
|
14
|
-
private readonly _raycaster: THREE.Raycaster = new THREE.Raycaster();
|
|
15
|
-
private readonly _tree: ITree = Tree.instance;
|
|
16
|
-
|
|
17
|
-
private static _instance: IntersectionEngine;
|
|
18
|
-
|
|
19
|
-
private _intersectNodes: {
|
|
20
|
-
node: ITreeNode,
|
|
21
|
-
geometryData: { [key: string]: GeometryData },
|
|
22
|
-
visible: boolean,
|
|
23
|
-
excludeViewports: string[],
|
|
24
|
-
restrictViewports: string[],
|
|
25
|
-
}[] = [];
|
|
26
|
-
|
|
27
|
-
// #endregion Properties (5)
|
|
28
|
-
|
|
29
|
-
// #region Constructors (1)
|
|
30
|
-
|
|
31
|
-
private constructor() {
|
|
32
|
-
this.gatherNodes();
|
|
33
|
-
this._eventEngine.addListener(EVENTTYPE.VIEWPORT.VIEWPORT_UPDATED, () => {
|
|
34
|
-
this.gatherNodes();
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// #endregion Constructors (1)
|
|
39
|
-
|
|
40
|
-
// #region Public Static Getters And Setters (1)
|
|
41
|
-
|
|
42
|
-
public static get instance() {
|
|
43
|
-
return this._instance || (this._instance = new this());
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// #endregion Public Static Getters And Setters (1)
|
|
47
|
-
|
|
48
|
-
// #region Public Methods (2)
|
|
49
|
-
|
|
50
|
-
public intersect(
|
|
51
|
-
ray: IRay,
|
|
52
|
-
viewportId: string,
|
|
53
|
-
filterCriteria?: IIntersectionFilter[],
|
|
54
|
-
rayCasterParams?: THREE.RaycasterParameters
|
|
55
|
-
): IIntersection[] {
|
|
56
|
-
let intersections: IIntersection[] = [];
|
|
57
|
-
this._intersectNodes.forEach(i => {
|
|
58
|
-
const currentIntersections = this.intersectNode(ray, i.node, i.geometryData, viewportId, filterCriteria, rayCasterParams);
|
|
59
|
-
if (currentIntersections)
|
|
60
|
-
intersections = intersections.concat(currentIntersections);
|
|
61
|
-
});
|
|
62
|
-
intersections.sort((a, b) => a.distance - b.distance);
|
|
63
|
-
return intersections;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public intersectNode(
|
|
67
|
-
ray: IRay,
|
|
68
|
-
node: ITreeNode,
|
|
69
|
-
geometryData: { [key: string]: GeometryData },
|
|
70
|
-
viewportId: string,
|
|
71
|
-
filterCriteria?: IIntersectionFilter[],
|
|
72
|
-
rayCasterParams?: THREE.RaycasterParameters
|
|
73
|
-
): IIntersection[] | undefined {
|
|
74
|
-
if (node.visible === false) return;
|
|
75
|
-
|
|
76
|
-
if (viewportId !== undefined) {
|
|
77
|
-
if (node.excludeViewports.includes(viewportId)) return;
|
|
78
|
-
if (node.restrictViewports.length > 0 && !node.restrictViewports.includes(viewportId)) return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (filterCriteria) {
|
|
82
|
-
for (let i = 0; i < filterCriteria.length; i++) {
|
|
83
|
-
if (filterCriteria[i](node))
|
|
84
|
-
return this.intersectionTest(ray, node, geometryData, viewportId, rayCasterParams);
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
return this.intersectionTest(ray, node, geometryData, viewportId, rayCasterParams);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// #endregion Public Methods (2)
|
|
92
|
-
|
|
93
|
-
// #region Private Methods (2)
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Gather all nodes that contain geometry data.
|
|
97
|
-
*/
|
|
98
|
-
private gatherNodes() {
|
|
99
|
-
this._intersectNodes = [];
|
|
100
|
-
this._tree.root.traverse(node => {
|
|
101
|
-
if (node.visible === false) return;
|
|
102
|
-
|
|
103
|
-
for (let i = 0; i < node.data.length; i++) {
|
|
104
|
-
if (node.data[i] instanceof GeometryData) {
|
|
105
|
-
const geometryData: GeometryData = node.data[i] as GeometryData;
|
|
106
|
-
let tempNode = node;
|
|
107
|
-
let visible = true, restrictViewports: string[] = [], excludeViewports: string[] = [];
|
|
108
|
-
while (tempNode.parent) {
|
|
109
|
-
visible = tempNode.visible && visible;
|
|
110
|
-
restrictViewports = restrictViewports.concat(tempNode.restrictViewports);
|
|
111
|
-
excludeViewports = excludeViewports.concat(tempNode.excludeViewports);
|
|
112
|
-
tempNode = tempNode.parent;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
this._intersectNodes.push({
|
|
116
|
-
node,
|
|
117
|
-
geometryData: { [`${geometryData.id}_${geometryData.version}`]: geometryData },
|
|
118
|
-
visible,
|
|
119
|
-
restrictViewports: [...new Set(restrictViewports)],
|
|
120
|
-
excludeViewports: [...new Set(excludeViewports)]
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Do the intersection test with the ray and the node.
|
|
129
|
-
*
|
|
130
|
-
* @param ray the ray to test
|
|
131
|
-
* @param node the node to test
|
|
132
|
-
* @param geometryData the geometry data of the node
|
|
133
|
-
* @param viewportId the viewport id
|
|
134
|
-
* @returns
|
|
135
|
-
*/
|
|
136
|
-
private intersectionTest(
|
|
137
|
-
ray: IRay,
|
|
138
|
-
node: ITreeNode,
|
|
139
|
-
geometryData: { [key: string]: GeometryData },
|
|
140
|
-
viewportId: string,
|
|
141
|
-
rayCasterParams?: THREE.RaycasterParameters
|
|
142
|
-
): IIntersection[] | undefined {
|
|
143
|
-
if (rayCasterParams) this._raycaster.params = rayCasterParams;
|
|
144
|
-
|
|
145
|
-
this._raycaster.ray.direction.set(ray.direction[0], ray.direction[1], ray.direction[2]);
|
|
146
|
-
this._raycaster.ray.origin.set(ray.origin[0], ray.origin[1], ray.origin[2]);
|
|
147
|
-
|
|
148
|
-
let intersections: IIntersection[] = [];
|
|
149
|
-
|
|
150
|
-
const threeJsObject = node.convertedObject[viewportId!] as THREE.Object3D;
|
|
151
|
-
if (threeJsObject) {
|
|
152
|
-
const intersectionThree = this._raycaster.intersectObject(threeJsObject);
|
|
153
|
-
const intersection = intersectionThree.map(i => {
|
|
154
|
-
const intersection: IIntersection = {
|
|
155
|
-
distance: i.distance,
|
|
156
|
-
point: [i.point.x, i.point.y, i.point.z],
|
|
157
|
-
node: node,
|
|
158
|
-
geometryData: geometryData[`${(i.object.parent as any).SDid}_${(i.object.parent as any).SDversion}`]
|
|
159
|
-
};
|
|
160
|
-
return intersection;
|
|
161
|
-
});
|
|
162
|
-
intersections = intersections.concat(intersection);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
intersections.sort((a, b) => a.distance - b.distance);
|
|
166
|
-
return intersections;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// #endregion Private Methods (2)
|
|
170
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { IIntersection } from './interfaces/IIntersection';
|
|
2
|
-
import { IIntersectionEngine } from './interfaces/IIntersectionEngine';
|
|
3
|
-
import { IIntersectionFilter } from './interfaces/IIntersectionFilter';
|
|
4
|
-
import { IntersectionEngine } from './implementation/IntersectionEngine';
|
|
5
|
-
import { IRay } from './interfaces/IRay';
|
|
6
|
-
import { RaycasterParameters } from 'three';
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
IRay, IIntersection, IIntersectionFilter, IIntersectionEngine, RaycasterParameters
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
IntersectionEngine
|
|
14
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { vec3 } from "gl-matrix";
|
|
2
|
-
import { ITreeNode } from "@shapediver/viewer.shared.node-tree";
|
|
3
|
-
import { IGeometryData } from "@shapediver/viewer.shared.types";
|
|
4
|
-
|
|
5
|
-
export interface IIntersection {
|
|
6
|
-
/** The distance to the intersection. */
|
|
7
|
-
distance: number,
|
|
8
|
-
/** The point of intersection. */
|
|
9
|
-
point: vec3,
|
|
10
|
-
/** The intersected node. */
|
|
11
|
-
node: ITreeNode
|
|
12
|
-
/** The intersected geometry data */
|
|
13
|
-
geometryData?: IGeometryData
|
|
14
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import { IIntersection } from './IIntersection';
|
|
3
|
-
import { IIntersectionFilter } from './IIntersectionFilter';
|
|
4
|
-
import { IRay } from './IRay';
|
|
5
|
-
|
|
6
|
-
export interface IIntersectionEngine {
|
|
7
|
-
// #region Public Methods (1)
|
|
8
|
-
|
|
9
|
-
intersect(ray: IRay, viewportId: string, filterCriteria?: IIntersectionFilter[], rayCasterParams?: THREE.RaycasterParameters): IIntersection[];
|
|
10
|
-
|
|
11
|
-
// #endregion Public Methods (1)
|
|
12
|
-
}
|
package/src/interfaces/IRay.ts
DELETED
package/tsconfig.json
DELETED