@combeenation/3d-viewer 20.0.0-alpha2 → 20.0.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib-cjs/buildinfo.json +1 -1
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/dist/lib-cjs/manager/camera-manager.d.ts +10 -0
- package/dist/lib-cjs/manager/camera-manager.js +40 -20
- package/dist/lib-cjs/manager/camera-manager.js.map +1 -1
- package/dist/lib-cjs/manager/scene-manager.d.ts +10 -1
- package/dist/lib-cjs/manager/scene-manager.js +4 -3
- package/dist/lib-cjs/manager/scene-manager.js.map +1 -1
- package/dist/lib-cjs/utils/viewer-utils.d.ts +40 -1
- package/dist/lib-cjs/utils/viewer-utils.js +48 -0
- package/dist/lib-cjs/utils/viewer-utils.js.map +1 -1
- package/package.json +1 -1
- package/src/manager/camera-manager.ts +63 -20
- package/src/manager/scene-manager.ts +15 -3
- package/src/utils/viewer-utils.ts +84 -0
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
Mesh,
|
|
5
5
|
MorphTarget,
|
|
6
6
|
MorphTargetManager,
|
|
7
|
+
Node,
|
|
8
|
+
Tags,
|
|
7
9
|
TransformNode,
|
|
8
10
|
Vector3,
|
|
9
11
|
VertexBuffer,
|
|
@@ -13,6 +15,7 @@ import {
|
|
|
13
15
|
export type BakeGeometrySettings = {
|
|
14
16
|
keepTransformation?: boolean;
|
|
15
17
|
};
|
|
18
|
+
|
|
16
19
|
export type CreateTransformNodeSettings = {
|
|
17
20
|
parentNode?: TransformNode;
|
|
18
21
|
position?: Vector3;
|
|
@@ -20,6 +23,34 @@ export type CreateTransformNodeSettings = {
|
|
|
20
23
|
scaling?: Vector3;
|
|
21
24
|
};
|
|
22
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Expected metadata structure for find node functions {@link ViewerUtils.findChildNodes} and
|
|
28
|
+
* {@link ViewerUtils.findParentNode}
|
|
29
|
+
*/
|
|
30
|
+
export type MetadataObject = Record<string, unknown>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Contains all constructor that derive from `Node`, e.g. `TransformNode`, `Mesh`
|
|
34
|
+
*/
|
|
35
|
+
export type DerivedNodeType<T extends Node> = new (...args: any[]) => T;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Criteria object for find node functions {@link ViewerUtils.findChildNodes} and {@link ViewerUtils.findParentNode}.\
|
|
39
|
+
* If property is omitted, the dedicated filter passes.
|
|
40
|
+
*
|
|
41
|
+
* @param nodeName has to match exactly
|
|
42
|
+
* @param tagName uses algorithm of `Tags.MatchesQuery`, in most cases this is just an exact string match check
|
|
43
|
+
* @param metadataObject has to be an object, filter passes if all property values of the given input object match the
|
|
44
|
+
* checked node
|
|
45
|
+
* @param type nodes type has to match (e.g. Mesh)
|
|
46
|
+
*/
|
|
47
|
+
export type FindNodeCriteria<T extends Node> = {
|
|
48
|
+
nodeName?: string;
|
|
49
|
+
tagName?: string;
|
|
50
|
+
metadataObject?: MetadataObject;
|
|
51
|
+
type?: DerivedNodeType<T>;
|
|
52
|
+
};
|
|
53
|
+
|
|
23
54
|
export class ViewerUtils {
|
|
24
55
|
/** @internal */
|
|
25
56
|
public constructor(protected viewer: Viewer) {}
|
|
@@ -99,6 +130,41 @@ export class ViewerUtils {
|
|
|
99
130
|
return node;
|
|
100
131
|
}
|
|
101
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Finds all child nodes (TransformNodes, Meshes, but also Lights, Cameras, etc...) that match a given criteria.
|
|
135
|
+
*
|
|
136
|
+
* @param node If left empty, all nodes of the scene are considered
|
|
137
|
+
* @param criteria If left empty, all child nodes are returned
|
|
138
|
+
*/
|
|
139
|
+
public findChildNodes<T extends Node>(node?: Node, criteria?: FindNodeCriteria<T>): T[] {
|
|
140
|
+
const allNodes = node ? node.getChildren(undefined, false) : [...this.viewer.scene.getNodes()];
|
|
141
|
+
|
|
142
|
+
if (!criteria) return allNodes as T[];
|
|
143
|
+
|
|
144
|
+
const foundNodes = allNodes.filter(node => this._matchesFindNodeCriteria(node, criteria));
|
|
145
|
+
return foundNodes as T[];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Finds nearest node that matches a given criteria.\
|
|
150
|
+
* Returns `undefined` if no node could be found.
|
|
151
|
+
*/
|
|
152
|
+
public findParentNode<T extends Node>(node: Node, criteria?: FindNodeCriteria<T>): T | undefined {
|
|
153
|
+
const parent = node.parent;
|
|
154
|
+
if (!parent) {
|
|
155
|
+
return undefined;
|
|
156
|
+
} else if (!criteria) {
|
|
157
|
+
return parent as T;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const matchesCriteria = this._matchesFindNodeCriteria(parent, criteria);
|
|
161
|
+
if (matchesCriteria) {
|
|
162
|
+
return parent as T;
|
|
163
|
+
} else {
|
|
164
|
+
return this.findParentNode(parent, criteria);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
102
168
|
/**
|
|
103
169
|
* @param kind morph targets can affect various vertices kinds, whereas "position" is the most common one
|
|
104
170
|
* still other kinds (like normals or tangents) can be affected as well and can be provided on this input
|
|
@@ -146,4 +212,22 @@ export class ViewerUtils {
|
|
|
146
212
|
|
|
147
213
|
return null;
|
|
148
214
|
}
|
|
215
|
+
|
|
216
|
+
protected _matchesFindNodeCriteria<T extends Node>(node: Node, criteria?: FindNodeCriteria<T>): boolean {
|
|
217
|
+
if (!criteria) return true;
|
|
218
|
+
|
|
219
|
+
const { nodeName, tagName, metadataObject, type } = criteria;
|
|
220
|
+
const nodeNameFits = !nodeName || node.name === nodeName;
|
|
221
|
+
const tagNameFits = !tagName || Tags.MatchesQuery(node, tagName);
|
|
222
|
+
const metadataFits = !metadataObject || this._matchesMetadata(node.metadata, metadataObject);
|
|
223
|
+
const typeFits = !type || node instanceof type;
|
|
224
|
+
|
|
225
|
+
return nodeNameFits && tagNameFits && metadataFits && typeFits;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
protected _matchesMetadata(metadata: unknown, filter: MetadataObject): boolean {
|
|
229
|
+
if (!metadata || typeof metadata !== 'object') return false;
|
|
230
|
+
|
|
231
|
+
return Object.entries(filter).every(([key, value]) => (metadata as MetadataObject)[key] === value);
|
|
232
|
+
}
|
|
149
233
|
}
|