@asyra/preset 0.5.7 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +128 -0
- package/README.md +11 -7
- package/dist/agent-activity.d.ts +61 -0
- package/dist/agent-activity.d.ts.map +1 -0
- package/dist/agent-activity.js +224 -0
- package/dist/agent-activity.js.map +1 -0
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +2 -2
- package/dist/catalog.js.map +1 -1
- package/dist/cleanup-reporter.d.ts.map +1 -1
- package/dist/cleanup-reporter.js.map +1 -1
- package/dist/components/fills.d.ts +3 -1
- package/dist/components/fills.d.ts.map +1 -1
- package/dist/components/fills.js +74 -0
- package/dist/components/fills.js.map +1 -1
- package/dist/components/frame.d.ts +2 -2
- package/dist/components/frame.d.ts.map +1 -1
- package/dist/components/frame.js +1 -0
- package/dist/components/frame.js.map +1 -1
- package/dist/components/group.d.ts +9 -21
- package/dist/components/group.d.ts.map +1 -1
- package/dist/components/group.js +188 -84
- package/dist/components/group.js.map +1 -1
- package/dist/components/oval.d.ts +2 -2
- package/dist/components/oval.d.ts.map +1 -1
- package/dist/components/oval.js +3 -1
- package/dist/components/oval.js.map +1 -1
- package/dist/components/rectangle.d.ts +2 -2
- package/dist/components/rectangle.d.ts.map +1 -1
- package/dist/components/rectangle.js +3 -1
- package/dist/components/rectangle.js.map +1 -1
- package/dist/components/shape-hit-area.d.ts.map +1 -1
- package/dist/components/shape-hit-area.js.map +1 -1
- package/dist/components/text.d.ts +9 -0
- package/dist/components/text.d.ts.map +1 -0
- package/dist/components/text.js +61 -0
- package/dist/components/text.js.map +1 -0
- package/dist/components/vector-compound-fill.d.ts +8 -0
- package/dist/components/vector-compound-fill.d.ts.map +1 -0
- package/dist/components/vector-compound-fill.js +149 -0
- package/dist/components/vector-compound-fill.js.map +1 -0
- package/dist/components/vector.d.ts.map +1 -1
- package/dist/components/vector.js +85 -565
- package/dist/components/vector.js.map +1 -1
- package/dist/composition/error.d.ts.map +1 -1
- package/dist/composition/error.js.map +1 -1
- package/dist/composition/profile-provider.d.ts +2 -1
- package/dist/composition/profile-provider.d.ts.map +1 -1
- package/dist/composition/profile-provider.js +8 -2
- package/dist/composition/profile-provider.js.map +1 -1
- package/dist/composition/resolve.d.ts +2 -0
- package/dist/composition/resolve.d.ts.map +1 -1
- package/dist/composition/resolve.js +30 -6
- package/dist/composition/resolve.js.map +1 -1
- package/dist/defaults/install.d.ts.map +1 -1
- package/dist/defaults/install.js +2 -1
- package/dist/defaults/install.js.map +1 -1
- package/dist/defaults/installation.d.ts.map +1 -1
- package/dist/defaults/installation.js +2 -0
- package/dist/defaults/installation.js.map +1 -1
- package/dist/defaults/modules/selection.d.ts.map +1 -1
- package/dist/defaults/modules/selection.js.map +1 -1
- package/dist/defaults/modules/vector-editing.d.ts.map +1 -1
- package/dist/defaults/modules/vector-editing.js.map +1 -1
- package/dist/defaults/owned-state.d.ts.map +1 -1
- package/dist/defaults/owned-state.js.map +1 -1
- package/dist/defaults/private-manager.d.ts.map +1 -1
- package/dist/defaults/private-manager.js +2 -1
- package/dist/defaults/private-manager.js.map +1 -1
- package/dist/events/preset-event-names.d.ts +2 -0
- package/dist/events/preset-event-names.d.ts.map +1 -1
- package/dist/events/register-events.d.ts.map +1 -1
- package/dist/events/register-events.js +4 -2
- package/dist/events/register-events.js.map +1 -1
- package/dist/group-bounds.d.ts +36 -0
- package/dist/group-bounds.d.ts.map +1 -0
- package/dist/group-bounds.js +141 -0
- package/dist/group-bounds.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/preset.d.ts.map +1 -1
- package/dist/preset.js +22 -4
- package/dist/preset.js.map +1 -1
- package/dist/props/components/anchor-points-component.d.ts.map +1 -1
- package/dist/props/components/anchor-points-component.js.map +1 -1
- package/dist/props/components/children-map-property-component.d.ts.map +1 -1
- package/dist/props/components/children-map-property-component.js.map +1 -1
- package/dist/props/components/fills-component.d.ts.map +1 -1
- package/dist/props/components/fills-component.js +3 -2
- package/dist/props/components/fills-component.js.map +1 -1
- package/dist/props/components/position-component.js +1 -1
- package/dist/props/components/position-component.js.map +1 -1
- package/dist/props/components/strokes-component.d.ts.map +1 -1
- package/dist/props/components/strokes-component.js +4 -3
- package/dist/props/components/strokes-component.js.map +1 -1
- package/dist/props/components/text-component.d.ts +67 -0
- package/dist/props/components/text-component.d.ts.map +1 -0
- package/dist/props/components/text-component.js +128 -0
- package/dist/props/components/text-component.js.map +1 -0
- package/dist/props/components/vector-networks-component.d.ts.map +1 -1
- package/dist/props/components/vector-networks-component.js.map +1 -1
- package/dist/props/components/vector-points-component.d.ts.map +1 -1
- package/dist/props/components/vector-points-component.js.map +1 -1
- package/dist/props/components/vector-segments-component.d.ts.map +1 -1
- package/dist/props/components/vector-segments-component.js.map +1 -1
- package/dist/props/register-property-schemas.d.ts.map +1 -1
- package/dist/props/register-property-schemas.js +6 -0
- package/dist/props/register-property-schemas.js.map +1 -1
- package/dist/render-layers/selection-overlay-render-layer.d.ts.map +1 -1
- package/dist/render-layers/selection-overlay-render-layer.js +7 -2
- package/dist/render-layers/selection-overlay-render-layer.js.map +1 -1
- package/dist/render-layers/vector-path-editing-render-layer.d.ts.map +1 -1
- package/dist/render-layers/vector-path-editing-render-layer.js.map +1 -1
- package/dist/selection/ids.d.ts.map +1 -1
- package/dist/selection/ids.js.map +1 -1
- package/dist/selection/register-default-selections.d.ts.map +1 -1
- package/dist/selection/register-default-selections.js +4 -2
- package/dist/selection/register-default-selections.js.map +1 -1
- package/dist/spatial/assets/binary.d.ts +22 -0
- package/dist/spatial/assets/binary.d.ts.map +1 -0
- package/dist/spatial/assets/binary.js +132 -0
- package/dist/spatial/assets/binary.js.map +1 -0
- package/dist/spatial/assets/decode.d.ts +23 -0
- package/dist/spatial/assets/decode.d.ts.map +1 -0
- package/dist/spatial/assets/decode.js +102 -0
- package/dist/spatial/assets/decode.js.map +1 -0
- package/dist/spatial/assets/preview-worker.d.ts +13 -0
- package/dist/spatial/assets/preview-worker.d.ts.map +1 -0
- package/dist/spatial/assets/preview-worker.js +188 -0
- package/dist/spatial/assets/preview-worker.js.map +1 -0
- package/dist/spatial/assets/scene.d.ts +13 -0
- package/dist/spatial/assets/scene.d.ts.map +1 -0
- package/dist/spatial/assets/scene.js +99 -0
- package/dist/spatial/assets/scene.js.map +1 -0
- package/dist/spatial/assets/schema.d.ts +22 -0
- package/dist/spatial/assets/schema.d.ts.map +1 -0
- package/dist/spatial/assets/schema.js +93 -0
- package/dist/spatial/assets/schema.js.map +1 -0
- package/dist/spatial/bounds.d.ts +15 -0
- package/dist/spatial/bounds.d.ts.map +1 -0
- package/dist/spatial/bounds.js +94 -0
- package/dist/spatial/bounds.js.map +1 -0
- package/dist/spatial/camera-controls.d.ts +53 -0
- package/dist/spatial/camera-controls.d.ts.map +1 -0
- package/dist/spatial/camera-controls.js +208 -0
- package/dist/spatial/camera-controls.js.map +1 -0
- package/dist/spatial/components.d.ts +20 -0
- package/dist/spatial/components.d.ts.map +1 -0
- package/dist/spatial/components.js +83 -0
- package/dist/spatial/components.js.map +1 -0
- package/dist/spatial/editing.d.ts +51 -0
- package/dist/spatial/editing.d.ts.map +1 -0
- package/dist/spatial/editing.js +152 -0
- package/dist/spatial/editing.js.map +1 -0
- package/dist/spatial/emissive-bloom.d.ts +22 -0
- package/dist/spatial/emissive-bloom.d.ts.map +1 -0
- package/dist/spatial/emissive-bloom.js +197 -0
- package/dist/spatial/emissive-bloom.js.map +1 -0
- package/dist/spatial/graphics.d.ts +9 -0
- package/dist/spatial/graphics.d.ts.map +1 -0
- package/dist/spatial/graphics.js +119 -0
- package/dist/spatial/graphics.js.map +1 -0
- package/dist/spatial/lazy-engine.d.ts +6 -0
- package/dist/spatial/lazy-engine.d.ts.map +1 -0
- package/dist/spatial/lazy-engine.js +92 -0
- package/dist/spatial/lazy-engine.js.map +1 -0
- package/dist/spatial/lighting.d.ts +28 -0
- package/dist/spatial/lighting.d.ts.map +1 -0
- package/dist/spatial/lighting.js +103 -0
- package/dist/spatial/lighting.js.map +1 -0
- package/dist/spatial/opaque-frame.d.ts +11 -0
- package/dist/spatial/opaque-frame.d.ts.map +1 -0
- package/dist/spatial/opaque-frame.js +131 -0
- package/dist/spatial/opaque-frame.js.map +1 -0
- package/dist/spatial/pose.d.ts +22 -0
- package/dist/spatial/pose.d.ts.map +1 -0
- package/dist/spatial/pose.js +83 -0
- package/dist/spatial/pose.js.map +1 -0
- package/dist/spatial/presentation.d.ts +16 -0
- package/dist/spatial/presentation.d.ts.map +1 -0
- package/dist/spatial/presentation.js +66 -0
- package/dist/spatial/presentation.js.map +1 -0
- package/dist/spatial/reflection-environment.d.ts +13 -0
- package/dist/spatial/reflection-environment.d.ts.map +1 -0
- package/dist/spatial/reflection-environment.js +63 -0
- package/dist/spatial/reflection-environment.js.map +1 -0
- package/dist/spatial/registration.d.ts +6 -0
- package/dist/spatial/registration.d.ts.map +1 -0
- package/dist/spatial/registration.js +82 -0
- package/dist/spatial/registration.js.map +1 -0
- package/dist/spatial/shadow-frame.d.ts +13 -0
- package/dist/spatial/shadow-frame.d.ts.map +1 -0
- package/dist/spatial/shadow-frame.js +60 -0
- package/dist/spatial/shadow-frame.js.map +1 -0
- package/dist/spatial/spatial-contract.d.ts +10 -0
- package/dist/spatial/spatial-contract.d.ts.map +1 -0
- package/dist/spatial/spatial-contract.js +414 -0
- package/dist/spatial/spatial-contract.js.map +1 -0
- package/dist/spatial/spatial-layer.d.ts +47 -0
- package/dist/spatial/spatial-layer.d.ts.map +1 -0
- package/dist/spatial/spatial-layer.js +224 -0
- package/dist/spatial/spatial-layer.js.map +1 -0
- package/dist/spatial/surface-contract.d.ts +4 -0
- package/dist/spatial/surface-contract.d.ts.map +1 -0
- package/dist/spatial/surface-contract.js +40 -0
- package/dist/spatial/surface-contract.js.map +1 -0
- package/dist/spatial/surface-textures.d.ts +8 -0
- package/dist/spatial/surface-textures.d.ts.map +1 -0
- package/dist/spatial/surface-textures.js +46 -0
- package/dist/spatial/surface-textures.js.map +1 -0
- package/dist/spatial/three-engine.d.ts +91 -0
- package/dist/spatial/three-engine.d.ts.map +1 -0
- package/dist/spatial/three-engine.js +1127 -0
- package/dist/spatial/three-engine.js.map +1 -0
- package/dist/spatial/transmission-capture.d.ts +13 -0
- package/dist/spatial/transmission-capture.d.ts.map +1 -0
- package/dist/spatial/transmission-capture.js +215 -0
- package/dist/spatial/transmission-capture.js.map +1 -0
- package/dist/spatial-assets.d.ts +4 -0
- package/dist/spatial-assets.d.ts.map +1 -0
- package/dist/spatial-assets.js +4 -0
- package/dist/spatial-assets.js.map +1 -0
- package/dist/spatial-contract.d.ts +3 -0
- package/dist/spatial-contract.d.ts.map +1 -0
- package/dist/spatial-contract.js +3 -0
- package/dist/spatial-contract.js.map +1 -0
- package/dist/spatial-engine.d.ts +5 -0
- package/dist/spatial-engine.d.ts.map +1 -0
- package/dist/spatial-engine.js +5 -0
- package/dist/spatial-engine.js.map +1 -0
- package/dist/spatial.d.ts +9 -0
- package/dist/spatial.d.ts.map +1 -0
- package/dist/spatial.js +9 -0
- package/dist/spatial.js.map +1 -0
- package/dist/subscriptions/data-channel.d.ts.map +1 -1
- package/dist/subscriptions/data-channel.js +372 -124
- package/dist/subscriptions/data-channel.js.map +1 -1
- package/dist/subscriptions/render-system.d.ts.map +1 -1
- package/dist/subscriptions/render-system.js +4 -2
- package/dist/subscriptions/render-system.js.map +1 -1
- package/dist/subscriptions/shared-channels.d.ts.map +1 -1
- package/dist/subscriptions/shared-channels.js +4 -2
- package/dist/subscriptions/shared-channels.js.map +1 -1
- package/dist/subscriptions/vector-selection.d.ts +4 -0
- package/dist/subscriptions/vector-selection.d.ts.map +1 -0
- package/dist/subscriptions/vector-selection.js +175 -0
- package/dist/subscriptions/vector-selection.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/register-properties.d.ts.map +1 -1
- package/dist/ui/register-properties.js +3 -2
- package/dist/ui/register-properties.js.map +1 -1
- package/dist/vector/synthetic-handle.d.ts.map +1 -1
- package/dist/vector/synthetic-handle.js.map +1 -1
- package/package.json +44 -12
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Color, LinearSRGBColorSpace, Matrix4, Quaternion, Vector3 } from 'three';
|
|
2
|
+
import { GLB_LIMITS, integer, list, record, tuple } from './schema.js';
|
|
3
|
+
export function nodeTransform(node) {
|
|
4
|
+
const matrix = new Matrix4();
|
|
5
|
+
if (node.matrix !== undefined) {
|
|
6
|
+
if (node.translation !== undefined ||
|
|
7
|
+
node.rotation !== undefined ||
|
|
8
|
+
node.scale !== undefined) {
|
|
9
|
+
throw new Error('Node cannot combine matrix and TRS');
|
|
10
|
+
}
|
|
11
|
+
const m = tuple(node.matrix, 16, 'node matrix');
|
|
12
|
+
if (m[3] !== 0 || m[7] !== 0 || m[11] !== 0 || m[15] !== 1) {
|
|
13
|
+
throw new Error('Unsupported projective node matrix');
|
|
14
|
+
}
|
|
15
|
+
const columns = [
|
|
16
|
+
new Vector3(...m.slice(0, 3)),
|
|
17
|
+
new Vector3(...m.slice(4, 7)),
|
|
18
|
+
new Vector3(...m.slice(8, 11))
|
|
19
|
+
];
|
|
20
|
+
if (columns.some((column) => column.length() < 1e-9)) {
|
|
21
|
+
throw new Error('Singular node transform');
|
|
22
|
+
}
|
|
23
|
+
const unit = columns.map((column) => column.clone().normalize());
|
|
24
|
+
if (Math.abs(unit[0].dot(unit[1])) > 1e-8 ||
|
|
25
|
+
Math.abs(unit[0].dot(unit[2])) > 1e-8 ||
|
|
26
|
+
Math.abs(unit[1].dot(unit[2])) > 1e-8) {
|
|
27
|
+
throw new Error('Unsupported sheared node matrix');
|
|
28
|
+
}
|
|
29
|
+
matrix.fromArray(m);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const t = tuple(node.translation ?? [0, 0, 0], 3, 'node translation'), r = tuple(node.rotation ?? [0, 0, 0, 1], 4, 'node rotation'), s = tuple(node.scale ?? [1, 1, 1], 3, 'node scale');
|
|
33
|
+
if (s.some((value) => value <= 0) ||
|
|
34
|
+
Math.abs(Math.hypot(...r) - 1) > 1e-8) {
|
|
35
|
+
throw new Error('Invalid node scale or rotation');
|
|
36
|
+
}
|
|
37
|
+
matrix.compose(new Vector3(...t), new Quaternion(...r).normalize(), new Vector3(...s));
|
|
38
|
+
}
|
|
39
|
+
if (!Number.isFinite(matrix.determinant()) || matrix.determinant() <= 0) {
|
|
40
|
+
throw new Error('Negative or singular node transform');
|
|
41
|
+
}
|
|
42
|
+
return matrix;
|
|
43
|
+
}
|
|
44
|
+
export function sceneNodes(json) {
|
|
45
|
+
const nodes = list(json.nodes, 'nodes', GLB_LIMITS.nodes, 1), scene = record(list(json.scenes, 'scenes', 1, 1)[0], 'scene');
|
|
46
|
+
if (json.scene !== undefined && json.scene !== 0) {
|
|
47
|
+
throw new Error('Only one explicit scene is supported');
|
|
48
|
+
}
|
|
49
|
+
const roots = list(scene.nodes, 'scene roots', GLB_LIMITS.nodes, 1);
|
|
50
|
+
const visited = new Set(), result = [];
|
|
51
|
+
const visit = (input, parent) => {
|
|
52
|
+
const index = integer(input, 'node index', nodes.length - 1);
|
|
53
|
+
if (visited.has(index)) {
|
|
54
|
+
throw new Error('Node cycle or multiple parents');
|
|
55
|
+
}
|
|
56
|
+
visited.add(index);
|
|
57
|
+
const node = record(nodes[index], 'node'), matrix = parent.clone().multiply(nodeTransform(node));
|
|
58
|
+
result.push({ node, matrix, index });
|
|
59
|
+
for (const child of list(node.children ?? [], 'node children', GLB_LIMITS.nodes)) {
|
|
60
|
+
visit(child, matrix);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
roots.forEach((root) => visit(root, new Matrix4()));
|
|
64
|
+
if (visited.size !== nodes.length) {
|
|
65
|
+
throw new Error('Unused nodes are outside the restricted scene profile');
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
export function appearance(value) {
|
|
70
|
+
const material = record(value ?? {}, 'material'), pbr = record(material.pbrMetallicRoughness ?? {}, 'PBR material');
|
|
71
|
+
const factor = tuple(pbr.baseColorFactor ?? [1, 1, 1, 1], 4, 'base color');
|
|
72
|
+
if (factor.some((v) => v < 0 || v > 1)) {
|
|
73
|
+
throw new Error('Invalid base color');
|
|
74
|
+
}
|
|
75
|
+
for (const key of ['metallicFactor', 'roughnessFactor']) {
|
|
76
|
+
if (pbr[key] !== undefined &&
|
|
77
|
+
(typeof pbr[key] !== 'number' ||
|
|
78
|
+
!Number.isFinite(pbr[key]) ||
|
|
79
|
+
pbr[key] < 0 ||
|
|
80
|
+
pbr[key] > 1)) {
|
|
81
|
+
throw new Error('Invalid PBR scalar');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (material.emissiveFactor !== undefined &&
|
|
85
|
+
tuple(material.emissiveFactor, 3, 'emissive factor').some((v) => v !== 0)) {
|
|
86
|
+
throw new Error('Unsupported emissive material');
|
|
87
|
+
}
|
|
88
|
+
if (material.alphaMode !== undefined &&
|
|
89
|
+
!['OPAQUE', 'BLEND'].includes(String(material.alphaMode))) {
|
|
90
|
+
throw new Error('Unsupported alpha mode');
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
color: new Color()
|
|
94
|
+
.setRGB(factor[0], factor[1], factor[2], LinearSRGBColorSpace)
|
|
95
|
+
.getHex(),
|
|
96
|
+
opacity: material.alphaMode === 'BLEND' ? factor[3] : 1
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=scene.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scene.js","sourceRoot":"","sources":["../../../src/spatial/assets/scene.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,oBAAoB,EACpB,OAAO,EACP,UAAU,EACV,OAAO,EACR,MAAM,OAAO,CAAA;AACd,OAAO,EACL,UAAU,EAC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AM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,oBAAoB,CAAC;aAC7D,MAAM,EAAE;QACX,OAAO,EAAE,QAAQ,CAAC,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACxD,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const GLB_LIMITS: Readonly<{
|
|
2
|
+
bytes: number;
|
|
3
|
+
deadlineMs: 5000;
|
|
4
|
+
jsonBytes: number;
|
|
5
|
+
nodes: 128;
|
|
6
|
+
meshes: 64;
|
|
7
|
+
primitives: 256;
|
|
8
|
+
vertices: 200000;
|
|
9
|
+
indices: 600000;
|
|
10
|
+
coordinate: 1000;
|
|
11
|
+
jsonDepth: 24;
|
|
12
|
+
jsonValues: 50000;
|
|
13
|
+
}>;
|
|
14
|
+
export type JsonRecord = Record<string, unknown>;
|
|
15
|
+
export declare function record(value: unknown, label: string): JsonRecord;
|
|
16
|
+
export declare function list(value: unknown, label: string, max: number, min?: number): unknown[];
|
|
17
|
+
export declare function integer(value: unknown, label: string, max: number, min?: number): number;
|
|
18
|
+
export declare function tuple(value: unknown, length: number, label: string): number[];
|
|
19
|
+
export declare function name(value: unknown, fallback: string): string;
|
|
20
|
+
/** Reject active/unsupported features anywhere, including otherwise unused metadata. */
|
|
21
|
+
export declare function inspectJson(input: unknown): void;
|
|
22
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/spatial/assets/schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;;;;;;;;;EAYrB,CAAA;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEhD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAMhE;AAED,wBAAgB,IAAI,CAClB,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,GAAG,SAAI,GACN,OAAO,EAAE,CAMX;AAED,wBAAgB,OAAO,CACrB,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,GAAG,SAAI,GACN,MAAM,CAWR;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAQ7E;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAU7D;AAuBD,wFAAwF;AACxF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAyBhD"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export const GLB_LIMITS = Object.freeze({
|
|
2
|
+
bytes: 16 * 1024 * 1024,
|
|
3
|
+
deadlineMs: 5000,
|
|
4
|
+
jsonBytes: 2 * 1024 * 1024,
|
|
5
|
+
nodes: 128,
|
|
6
|
+
meshes: 64,
|
|
7
|
+
primitives: 256,
|
|
8
|
+
vertices: 200000,
|
|
9
|
+
indices: 600000,
|
|
10
|
+
coordinate: 1000,
|
|
11
|
+
jsonDepth: 24,
|
|
12
|
+
jsonValues: 50000
|
|
13
|
+
});
|
|
14
|
+
export function record(value, label) {
|
|
15
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
16
|
+
throw new Error(`Invalid ${label}`);
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
export function list(value, label, max, min = 0) {
|
|
21
|
+
if (!Array.isArray(value) || value.length < min || value.length > max) {
|
|
22
|
+
throw new Error(`Invalid or over-budget ${label}`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
export function integer(value, label, max, min = 0) {
|
|
27
|
+
if (typeof value !== 'number' ||
|
|
28
|
+
!Number.isSafeInteger(value) ||
|
|
29
|
+
value < min ||
|
|
30
|
+
value > max) {
|
|
31
|
+
throw new Error(`Invalid ${label}`);
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
export function tuple(value, length, label) {
|
|
36
|
+
const values = list(value, label, length, length);
|
|
37
|
+
if (!values.every((v) => typeof v === 'number' && Number.isFinite(v))) {
|
|
38
|
+
throw new Error(`Nonfinite ${label}`);
|
|
39
|
+
}
|
|
40
|
+
return values;
|
|
41
|
+
}
|
|
42
|
+
export function name(value, fallback) {
|
|
43
|
+
if (value === undefined) {
|
|
44
|
+
return fallback;
|
|
45
|
+
}
|
|
46
|
+
if (typeof value !== 'string' || value.length > 200) {
|
|
47
|
+
throw new Error('Invalid asset name');
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
const forbidden = new Set([
|
|
52
|
+
'uri',
|
|
53
|
+
'extensions',
|
|
54
|
+
'extensionsUsed',
|
|
55
|
+
'extensionsRequired',
|
|
56
|
+
'images',
|
|
57
|
+
'textures',
|
|
58
|
+
'samplers',
|
|
59
|
+
'animations',
|
|
60
|
+
'skins',
|
|
61
|
+
'skin',
|
|
62
|
+
'weights',
|
|
63
|
+
'targets',
|
|
64
|
+
'sparse',
|
|
65
|
+
'cameras',
|
|
66
|
+
'camera',
|
|
67
|
+
'__proto__',
|
|
68
|
+
'prototype',
|
|
69
|
+
'constructor'
|
|
70
|
+
]);
|
|
71
|
+
/** Reject active/unsupported features anywhere, including otherwise unused metadata. */
|
|
72
|
+
export function inspectJson(input) {
|
|
73
|
+
const pending = [{ value: input, depth: 0 }];
|
|
74
|
+
let count = 0;
|
|
75
|
+
while (pending.length) {
|
|
76
|
+
const item = pending.pop();
|
|
77
|
+
if (!item) {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
if (++count > GLB_LIMITS.jsonValues || item.depth > GLB_LIMITS.jsonDepth) {
|
|
81
|
+
throw new Error('GLB JSON resource limit exceeded');
|
|
82
|
+
}
|
|
83
|
+
if (item.value && typeof item.value === 'object') {
|
|
84
|
+
for (const [key, value] of Object.entries(item.value)) {
|
|
85
|
+
if (forbidden.has(key) || key.endsWith('Texture')) {
|
|
86
|
+
throw new Error(`Unsupported GLB feature: ${key}`);
|
|
87
|
+
}
|
|
88
|
+
pending.push({ value, depth: item.depth + 1 });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/spatial/assets/schema.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;IACtC,KAAK,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;IACvB,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI;IAC1B,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,EAAE;IACV,UAAU,EAAE,GAAG;IACf,QAAQ,EAAE,MAAM;IAChB,OAAO,EAAE,MAAM;IACf,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,EAAE;IACb,UAAU,EAAE,KAAK;CAClB,CAAC,CAAA;AAIF,MAAM,UAAU,MAAM,CAAC,KAAc,EAAE,KAAa;IAClD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,WAAW,KAAK,EAAE,CAAC,CAAA;IACrC,CAAC;IAED,OAAO,KAAmB,CAAA;AAC5B,CAAC;AAED,MAAM,UAAU,IAAI,CACl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4BAA4B,GAAG,EAAE,CAAC,CAAA;gBACpD,CAAC;gBAED,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAA;YAChD,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SpatialVector } from '@asyra/render-engine';
|
|
2
|
+
import type { SpatialMesh } from './spatial-layer.js';
|
|
3
|
+
export interface SpatialBounds {
|
|
4
|
+
readonly min: SpatialVector;
|
|
5
|
+
readonly max: SpatialVector;
|
|
6
|
+
}
|
|
7
|
+
/** Lifetime-owned local extrema. World poses are recomputed on every query. */
|
|
8
|
+
export declare class SpatialBoundsOwner {
|
|
9
|
+
private local;
|
|
10
|
+
private disposed;
|
|
11
|
+
measure(values: readonly SpatialMesh[]): SpatialBounds | null;
|
|
12
|
+
dispose(): void;
|
|
13
|
+
private localBounds;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=bounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bounds.d.ts","sourceRoot":"","sources":["../../src/spatial/bounds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,aAAa,EAEd,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAA;IAC3B,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAA;CAC5B;AAQD,+EAA+E;AAC/E,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAA6C;IAE1D,OAAO,CAAC,QAAQ,CAAQ;IAExB,OAAO,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,aAAa,GAAG,IAAI;IAkF7D,OAAO,IAAI,IAAI;IAKf,OAAO,CAAC,WAAW;CAyCpB"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { readSpatialDescriptor } from './spatial-contract.js';
|
|
2
|
+
const freeze = (min, max) => Object.freeze({
|
|
3
|
+
min: Object.freeze(min),
|
|
4
|
+
max: Object.freeze(max)
|
|
5
|
+
});
|
|
6
|
+
/** Lifetime-owned local extrema. World poses are recomputed on every query. */
|
|
7
|
+
export class SpatialBoundsOwner {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.local = new WeakMap();
|
|
10
|
+
this.disposed = false;
|
|
11
|
+
}
|
|
12
|
+
measure(values) {
|
|
13
|
+
if (this.disposed) {
|
|
14
|
+
throw new Error('Spatial bounds owner is disposed');
|
|
15
|
+
}
|
|
16
|
+
const descriptors = values.map((value) => {
|
|
17
|
+
const admitted = readSpatialDescriptor(value);
|
|
18
|
+
if (admitted.kind !== 'mesh') {
|
|
19
|
+
throw new Error('Expected a spatial mesh');
|
|
20
|
+
}
|
|
21
|
+
return admitted;
|
|
22
|
+
});
|
|
23
|
+
if (!descriptors.length) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const min = [Infinity, Infinity, Infinity], max = [-Infinity, -Infinity, -Infinity];
|
|
27
|
+
for (const descriptor of descriptors) {
|
|
28
|
+
const bounds = this.localBounds(descriptor.shape);
|
|
29
|
+
const transform = (point, position, rotation, scale = [1, 1, 1]) => {
|
|
30
|
+
const [x, y, z] = point.map((n, i) => n * scale[i]), [qx, qy, qz, qw] = rotation;
|
|
31
|
+
const tx = 2 * (qy * z - qz * y), ty = 2 * (qz * x - qx * z), tz = 2 * (qx * y - qy * x);
|
|
32
|
+
return [
|
|
33
|
+
x + qw * tx + qy * tz - qz * ty + position[0],
|
|
34
|
+
y + qw * ty + qz * tx - qx * tz + position[1],
|
|
35
|
+
z + qw * tz + qx * ty - qy * tx + position[2]
|
|
36
|
+
];
|
|
37
|
+
};
|
|
38
|
+
for (const instance of descriptor.instances ?? [null]) {
|
|
39
|
+
for (const x of [bounds.min[0], bounds.max[0]]) {
|
|
40
|
+
for (const y of [bounds.min[1], bounds.max[1]]) {
|
|
41
|
+
for (const z of [bounds.min[2], bounds.max[2]]) {
|
|
42
|
+
let point = [x, y, z];
|
|
43
|
+
if (instance) {
|
|
44
|
+
point = transform(point, instance.position, instance.rotation, instance.scale);
|
|
45
|
+
}
|
|
46
|
+
point = transform(point, descriptor.position, descriptor.rotation, descriptor.scale);
|
|
47
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
48
|
+
min[axis] = Math.min(min[axis], point[axis]);
|
|
49
|
+
max[axis] = Math.max(max[axis], point[axis]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!min.every(Number.isFinite) || !max.every(Number.isFinite)) {
|
|
57
|
+
throw new Error('Nonfinite spatial bounds');
|
|
58
|
+
}
|
|
59
|
+
return freeze(min, max);
|
|
60
|
+
}
|
|
61
|
+
dispose() {
|
|
62
|
+
this.disposed = true;
|
|
63
|
+
this.local = new WeakMap();
|
|
64
|
+
}
|
|
65
|
+
localBounds(shape) {
|
|
66
|
+
const existing = this.local.get(shape);
|
|
67
|
+
if (existing) {
|
|
68
|
+
return existing;
|
|
69
|
+
}
|
|
70
|
+
let result;
|
|
71
|
+
if (shape.kind === 'triangles') {
|
|
72
|
+
const min = [Infinity, Infinity, Infinity], max = [-Infinity, -Infinity, -Infinity];
|
|
73
|
+
for (let i = 0; i < shape.positions.length; i++) {
|
|
74
|
+
const axis = i % 3;
|
|
75
|
+
min[axis] = Math.min(min[axis], shape.positions[i]);
|
|
76
|
+
max[axis] = Math.max(max[axis], shape.positions[i]);
|
|
77
|
+
}
|
|
78
|
+
result = freeze(min, max);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const half = shape.kind === 'box'
|
|
82
|
+
? shape.size.map((n) => n / 2)
|
|
83
|
+
: [
|
|
84
|
+
shape.radius,
|
|
85
|
+
shape.radius + (shape.kind === 'capsule' ? shape.length / 2 : 0),
|
|
86
|
+
shape.radius
|
|
87
|
+
];
|
|
88
|
+
result = freeze(half.map((n) => -n), half);
|
|
89
|
+
}
|
|
90
|
+
this.local.set(shape, result);
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=bounds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bounds.js","sourceRoot":"","sources":["../../src/spatial/bounds.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAQ7D,MAAM,MAAM,GAAG,CAAC,GAAa,EAAE,GAAa,EAAiB,EAAE,CAC7D,MAAM,CAAC,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAA6B;IACnD,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAA6B;CACpD,CAAC,CAAA;AAEJ,+EAA+E;AAC/E,MAAM,OAAO,kBAAkB;IAA/B;QACU,UAAK,GAAG,IAAI,OAAO,EAA+B,CAAA;QAElD,aAAQ,GAAG,KAAK,CAAA;IAkI1B,CAAC;IAhIC,OAAO,CAAC,MAA8B;QACpC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;QACrD,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACvC,MAAM,QAAQ,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAA;YAE7C,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;YAC5C,CAAC;YAED,OAAO,QAAQ,CAAA;QACjB,CAAC,CAAC,CAAA;QAEF,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YACxB,OA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AC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;gBACnD,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;YACrD,CAAC;YAED,MAAM,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAC3B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,GACR,KAAK,CAAC,IAAI,KAAK,KAAK;gBAClB,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;gBAC9B,CAAC,CAAC;oBACE,KAAK,CAAC,MAAM;oBACZ,KAAK,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBAChE,KAAK,CAAC,MAAM;iBACb,CAAA;YAEP,MAAM,GAAG,MAAM,CACb,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EACnB,IAAI,CACL,CAAA;QACH,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QAE7B,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { SpatialVector } from '@asyra/render-engine';
|
|
2
|
+
import type { SpatialCamera } from './spatial-layer.js';
|
|
3
|
+
import type { SpatialBounds } from './bounds.js';
|
|
4
|
+
type Vector = SpatialVector;
|
|
5
|
+
/** Uses the same admission owner as spatial submission. */
|
|
6
|
+
export declare function readSpatialCamera(value: unknown): SpatialCamera;
|
|
7
|
+
export declare function spatialCameraDistance(camera: SpatialCamera): number;
|
|
8
|
+
export declare function moveSpatialCamera(camera: SpatialCamera, right: number, up: number, forward: number): SpatialCamera;
|
|
9
|
+
export declare function panSpatialCamera(camera: SpatialCamera, dx: number, dy: number, height: number, reference: {
|
|
10
|
+
distance: number;
|
|
11
|
+
fov: number;
|
|
12
|
+
}): SpatialCamera;
|
|
13
|
+
export declare function dollySpatialCamera(camera: SpatialCamera, distance: number): SpatialCamera;
|
|
14
|
+
export interface SpatialPolarLimits {
|
|
15
|
+
minPolar: number;
|
|
16
|
+
maxPolar: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const orbitSpatialCamera: (camera: SpatialCamera, yaw: number, polar: number, limits: SpatialPolarLimits) => {
|
|
19
|
+
kind: "camera";
|
|
20
|
+
position: SpatialVector;
|
|
21
|
+
target: SpatialVector;
|
|
22
|
+
fov: number;
|
|
23
|
+
near: number;
|
|
24
|
+
far: number;
|
|
25
|
+
};
|
|
26
|
+
export declare const lookSpatialCamera: (camera: SpatialCamera, yaw: number, polar: number, limits: SpatialPolarLimits) => {
|
|
27
|
+
kind: "camera";
|
|
28
|
+
position: SpatialVector;
|
|
29
|
+
target: SpatialVector;
|
|
30
|
+
fov: number;
|
|
31
|
+
near: number;
|
|
32
|
+
far: number;
|
|
33
|
+
};
|
|
34
|
+
export declare function zoomSpatialCamera(camera: SpatialCamera, magnification: number, maxFov: number): SpatialCamera;
|
|
35
|
+
export declare function projectSpatialCamera(camera: SpatialCamera, aspect: number, policy: {
|
|
36
|
+
projection: 'perspective';
|
|
37
|
+
minimumAspect: number;
|
|
38
|
+
maxFov: number;
|
|
39
|
+
}): SpatialCamera;
|
|
40
|
+
export declare function fitSpatialCameraBounds(camera: SpatialCamera, bounds: SpatialBounds | null, width: number, height: number, options: {
|
|
41
|
+
padding: number;
|
|
42
|
+
verticalFov: number;
|
|
43
|
+
}): SpatialCamera;
|
|
44
|
+
/** Frame an App-selected point set using its enclosing view-space prism. */
|
|
45
|
+
export declare function frameSpatialCameraPoints(camera: SpatialCamera, points: Iterable<Vector>, width: number, height: number, options: {
|
|
46
|
+
padding: number;
|
|
47
|
+
minDistance: number;
|
|
48
|
+
nearFraction: number;
|
|
49
|
+
minimumFarPadding: number;
|
|
50
|
+
farPaddingRatio: number;
|
|
51
|
+
}): SpatialCamera;
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=camera-controls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera-controls.d.ts","sourceRoot":"","sources":["../../src/spatial/camera-controls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,KAAK,MAAM,GAAG,aAAa,CAAA;AA0B3B,2DAA2D;AAC3D,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAQ/D;AAUD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAInE;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,GACd,aAAa,CAcf;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,SAAS,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC3C,aAAa,CAgBf;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,MAAM,GACf,aAAa,CAaf;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;CACjB;AA2CD,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,aAAa,EACrB,KAAK,MAAM,EACX,OAAO,MAAM,EACb,QAAQ,kBAAkB;;;;;;;CACiB,CAAA;AAE7C,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,aAAa,EACrB,KAAK,MAAM,EACX,OAAO,MAAM,EACb,QAAQ,kBAAkB;;;;;;;CACkB,CAAA;AAE9C,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,GACb,aAAa,CAef;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE;IAAE,UAAU,EAAE,aAAa,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC3E,aAAa,CAef;AASD,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,aAAa,GAAG,IAAI,EAC5B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAChD,aAAa,CAyDf;AAED,4EAA4E;AAC5E,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EACxB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IACP,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,iBAAiB,EAAE,MAAM,CAAA;IACzB,eAAe,EAAE,MAAM,CAAA;CACxB,GACA,aAAa,CAuEf"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { readSpatialDescriptor } from './spatial-contract.js';
|
|
2
|
+
const finite = (...values) => {
|
|
3
|
+
if (!values.every(Number.isFinite)) {
|
|
4
|
+
throw new Error('Invalid camera control input');
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
const tuple = (values) => [values[0], values[1], values[2]];
|
|
8
|
+
const add = (a, b) => tuple(a.map((n, i) => n + b[i]));
|
|
9
|
+
const sub = (a, b) => tuple(a.map((n, i) => n - b[i]));
|
|
10
|
+
const scale = (a, n) => tuple(a.map((v) => v * n));
|
|
11
|
+
const dot = (a, b) => a.reduce((n, v, i) => n + v * b[i], 0);
|
|
12
|
+
const cross = (a, b) => [
|
|
13
|
+
a[1] * b[2] - a[2] * b[1],
|
|
14
|
+
a[2] * b[0] - a[0] * b[2],
|
|
15
|
+
a[0] * b[1] - a[1] * b[0]
|
|
16
|
+
];
|
|
17
|
+
const normalize = (v) => scale(v, 1 / Math.hypot(...v));
|
|
18
|
+
/** Uses the same admission owner as spatial submission. */
|
|
19
|
+
export function readSpatialCamera(value) {
|
|
20
|
+
const camera = readSpatialDescriptor(value);
|
|
21
|
+
if (camera.kind !== 'camera') {
|
|
22
|
+
throw new Error('Expected perspective camera');
|
|
23
|
+
}
|
|
24
|
+
return camera;
|
|
25
|
+
}
|
|
26
|
+
function basis(camera) {
|
|
27
|
+
camera = readSpatialCamera(camera);
|
|
28
|
+
const back = normalize(sub(camera.position, camera.target));
|
|
29
|
+
const right = normalize(cross([0, 1, 0], back));
|
|
30
|
+
return { back, right, up: cross(back, right) };
|
|
31
|
+
}
|
|
32
|
+
export function spatialCameraDistance(camera) {
|
|
33
|
+
camera = readSpatialCamera(camera);
|
|
34
|
+
return Math.hypot(...sub(camera.position, camera.target));
|
|
35
|
+
}
|
|
36
|
+
export function moveSpatialCamera(camera, right, up, forward) {
|
|
37
|
+
camera = readSpatialCamera(camera);
|
|
38
|
+
finite(right, up, forward);
|
|
39
|
+
const b = basis(camera);
|
|
40
|
+
const offset = add(add(scale(b.right, right), scale(b.up, up)), scale(b.back, -forward));
|
|
41
|
+
return readSpatialCamera({
|
|
42
|
+
...camera,
|
|
43
|
+
position: add(camera.position, offset),
|
|
44
|
+
target: add(camera.target, offset)
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function panSpatialCamera(camera, dx, dy, height, reference) {
|
|
48
|
+
finite(dx, dy, height, reference.distance, reference.fov);
|
|
49
|
+
if (height <= 0 ||
|
|
50
|
+
reference.distance <= 0 ||
|
|
51
|
+
reference.fov <= 0 ||
|
|
52
|
+
reference.fov >= 180) {
|
|
53
|
+
throw new Error('Invalid camera pan');
|
|
54
|
+
}
|
|
55
|
+
const units = (2 * reference.distance * Math.tan((reference.fov * Math.PI) / 360)) /
|
|
56
|
+
height;
|
|
57
|
+
return moveSpatialCamera(camera, -dx * units, dy * units, 0);
|
|
58
|
+
}
|
|
59
|
+
export function dollySpatialCamera(camera, distance) {
|
|
60
|
+
camera = readSpatialCamera(camera);
|
|
61
|
+
finite(distance);
|
|
62
|
+
const b = basis(camera);
|
|
63
|
+
if (distance <= 0) {
|
|
64
|
+
throw new Error('Invalid camera distance');
|
|
65
|
+
}
|
|
66
|
+
return readSpatialCamera({
|
|
67
|
+
...camera,
|
|
68
|
+
position: add(camera.target, scale(b.back, distance))
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function rotate(camera, yaw, polar, limits, orbit) {
|
|
72
|
+
camera = readSpatialCamera(camera);
|
|
73
|
+
finite(yaw, polar, limits.minPolar, limits.maxPolar);
|
|
74
|
+
if (limits.minPolar <= 0 ||
|
|
75
|
+
limits.maxPolar >= Math.PI ||
|
|
76
|
+
limits.minPolar > limits.maxPolar) {
|
|
77
|
+
throw new Error('Invalid polar limits');
|
|
78
|
+
}
|
|
79
|
+
const offset = orbit
|
|
80
|
+
? sub(camera.position, camera.target)
|
|
81
|
+
: sub(camera.target, camera.position);
|
|
82
|
+
const radius = Math.hypot(...offset);
|
|
83
|
+
const theta = Math.atan2(offset[0], offset[2]) + yaw;
|
|
84
|
+
const phi = Math.max(limits.minPolar, Math.min(limits.maxPolar, Math.acos(Math.max(-1, Math.min(1, offset[1] / radius))) + polar));
|
|
85
|
+
const result = add(orbit ? camera.target : camera.position, [
|
|
86
|
+
radius * Math.sin(phi) * Math.sin(theta),
|
|
87
|
+
radius * Math.cos(phi),
|
|
88
|
+
radius * Math.sin(phi) * Math.cos(theta)
|
|
89
|
+
]);
|
|
90
|
+
return readSpatialCamera({
|
|
91
|
+
...camera,
|
|
92
|
+
...(orbit ? { position: result } : { target: result })
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export const orbitSpatialCamera = (camera, yaw, polar, limits) => rotate(camera, yaw, polar, limits, true);
|
|
96
|
+
export const lookSpatialCamera = (camera, yaw, polar, limits) => rotate(camera, yaw, polar, limits, false);
|
|
97
|
+
export function zoomSpatialCamera(camera, magnification, maxFov) {
|
|
98
|
+
camera = readSpatialCamera(camera);
|
|
99
|
+
finite(magnification, maxFov);
|
|
100
|
+
if (magnification <= 0 || maxFov <= 0 || maxFov >= 180) {
|
|
101
|
+
throw new Error('Invalid camera zoom');
|
|
102
|
+
}
|
|
103
|
+
return readSpatialCamera({
|
|
104
|
+
...camera,
|
|
105
|
+
fov: Math.min(maxFov, (360 / Math.PI) *
|
|
106
|
+
Math.atan(Math.tan((camera.fov * Math.PI) / 360) / magnification))
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
export function projectSpatialCamera(camera, aspect, policy) {
|
|
110
|
+
if (policy.projection !== 'perspective') {
|
|
111
|
+
throw new Error('Unsupported world camera projection');
|
|
112
|
+
}
|
|
113
|
+
finite(aspect, policy.minimumAspect);
|
|
114
|
+
if (aspect <= 0 || policy.minimumAspect <= 0) {
|
|
115
|
+
throw new Error('Invalid viewport aspect');
|
|
116
|
+
}
|
|
117
|
+
return zoomSpatialCamera(camera, 1 / Math.max(1, policy.minimumAspect / aspect), policy.maxFov);
|
|
118
|
+
}
|
|
119
|
+
function viewport(width, height, padding) {
|
|
120
|
+
finite(width, height, padding);
|
|
121
|
+
if (padding < 0 || width <= 2 * padding || height <= 2 * padding) {
|
|
122
|
+
throw new Error('Viewport too small for fit padding');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export function fitSpatialCameraBounds(camera, bounds, width, height, options) {
|
|
126
|
+
const original = camera;
|
|
127
|
+
camera = readSpatialCamera(camera);
|
|
128
|
+
const b = basis(camera);
|
|
129
|
+
viewport(width, height, options.padding);
|
|
130
|
+
finite(options.verticalFov);
|
|
131
|
+
if (options.verticalFov <= 0 || options.verticalFov >= 180) {
|
|
132
|
+
throw new Error('Invalid fit FOV');
|
|
133
|
+
}
|
|
134
|
+
if (!bounds) {
|
|
135
|
+
return original;
|
|
136
|
+
}
|
|
137
|
+
finite(...bounds.min, ...bounds.max);
|
|
138
|
+
if (bounds.min.some((n, i) => n > bounds.max[i])) {
|
|
139
|
+
throw new Error('Invalid bounds');
|
|
140
|
+
}
|
|
141
|
+
const target = tuple(bounds.min.map((n, i) => (n + bounds.max[i]) / 2));
|
|
142
|
+
const vertical = Math.tan((options.verticalFov * Math.PI) / 360), horizontal = (vertical * width) / height;
|
|
143
|
+
let distance = 0;
|
|
144
|
+
for (const x of [bounds.min[0], bounds.max[0]]) {
|
|
145
|
+
for (const y of [bounds.min[1], bounds.max[1]]) {
|
|
146
|
+
for (const z of [bounds.min[2], bounds.max[2]]) {
|
|
147
|
+
const p = sub([x, y, z], target), depth = dot(b.back, p);
|
|
148
|
+
distance = Math.max(distance, depth +
|
|
149
|
+
Math.abs(dot(b.right, p)) /
|
|
150
|
+
(horizontal * (1 - (2 * options.padding) / width)), depth +
|
|
151
|
+
Math.abs(dot(b.up, p)) /
|
|
152
|
+
(vertical * (1 - (2 * options.padding) / height)), depth + camera.near);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
distance += 1e-6;
|
|
157
|
+
return readSpatialCamera({
|
|
158
|
+
...camera,
|
|
159
|
+
target,
|
|
160
|
+
position: add(target, scale(b.back, distance)),
|
|
161
|
+
far: Math.max(camera.far, distance + Math.hypot(...sub(bounds.max, bounds.min)))
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/** Frame an App-selected point set using its enclosing view-space prism. */
|
|
165
|
+
export function frameSpatialCameraPoints(camera, points, width, height, options) {
|
|
166
|
+
const original = camera;
|
|
167
|
+
camera = readSpatialCamera(camera);
|
|
168
|
+
const b = basis(camera);
|
|
169
|
+
viewport(width, height, options.padding);
|
|
170
|
+
finite(options.minDistance, options.nearFraction, options.minimumFarPadding, options.farPaddingRatio);
|
|
171
|
+
if (options.minDistance <= 0 ||
|
|
172
|
+
options.nearFraction <= 0 ||
|
|
173
|
+
options.nearFraction >= 1 ||
|
|
174
|
+
options.minimumFarPadding < 0 ||
|
|
175
|
+
options.farPaddingRatio < 0) {
|
|
176
|
+
throw new Error('Invalid framing limits');
|
|
177
|
+
}
|
|
178
|
+
const min = [Infinity, Infinity, Infinity], max = [-Infinity, -Infinity, -Infinity];
|
|
179
|
+
let count = 0;
|
|
180
|
+
for (const point of points) {
|
|
181
|
+
finite(...point);
|
|
182
|
+
const p = [dot(point, b.right), dot(point, b.up), dot(point, b.back)];
|
|
183
|
+
for (let i = 0; i < 3; i++) {
|
|
184
|
+
min[i] = Math.min(min[i], p[i]);
|
|
185
|
+
max[i] = Math.max(max[i], p[i]);
|
|
186
|
+
}
|
|
187
|
+
count++;
|
|
188
|
+
}
|
|
189
|
+
if (!count) {
|
|
190
|
+
return original;
|
|
191
|
+
}
|
|
192
|
+
const middle = tuple(min.map((n, i) => n + (max[i] - n) / 2)), half = tuple(min.map((n, i) => (max[i] - n) / 2));
|
|
193
|
+
const target = add(add(scale(b.right, middle[0]), scale(b.up, middle[1])), scale(b.back, middle[2]));
|
|
194
|
+
const tan = Math.tan((camera.fov * Math.PI) / 360);
|
|
195
|
+
const distance = half[2] +
|
|
196
|
+
Math.max(options.minDistance, half[0] /
|
|
197
|
+
(((tan * width) / height) * (1 - (2 * options.padding) / width)), half[1] / (tan * (1 - (2 * options.padding) / height)));
|
|
198
|
+
return readSpatialCamera({
|
|
199
|
+
...camera,
|
|
200
|
+
target,
|
|
201
|
+
position: add(target, scale(b.back, distance)),
|
|
202
|
+
near: Math.min(camera.near, (distance - half[2]) * options.nearFraction),
|
|
203
|
+
far: Math.max(camera.far, distance +
|
|
204
|
+
half[2] +
|
|
205
|
+
Math.max(options.minimumFarPadding, distance * options.farPaddingRatio))
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=camera-controls.js.map
|