@aethervtt/shard-controls 0.0.0-stage → 0.1.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/dist/view.js ADDED
@@ -0,0 +1,132 @@
1
+ function createView() {
2
+ return {
3
+ eye: new Float64Array(3),
4
+ right: new Float64Array([1, 0, 0]),
5
+ up: new Float64Array([0, 1, 0]),
6
+ forward: new Float64Array([0, 0, -1]),
7
+ orthographic: false,
8
+ half: 1,
9
+ aspect: 1
10
+ };
11
+ }
12
+ const DEG = Math.PI / 180;
13
+ function orbitDirection(yaw, pitch, out) {
14
+ const y = yaw * DEG;
15
+ const p = pitch * DEG;
16
+ out[0] = Math.sin(y) * Math.cos(p);
17
+ out[1] = Math.sin(p);
18
+ out[2] = Math.cos(y) * Math.cos(p);
19
+ }
20
+ function orbitView(out, target, distance, yaw, pitch, fovY, aspect) {
21
+ const y = yaw * DEG;
22
+ const p = pitch * DEG;
23
+ const cy = Math.cos(y);
24
+ const sy = Math.sin(y);
25
+ const cp = Math.cos(p);
26
+ const sp = Math.sin(p);
27
+ out.eye[0] = target[0] + sy * cp * distance;
28
+ out.eye[1] = target[1] + sp * distance;
29
+ out.eye[2] = target[2] + cy * cp * distance;
30
+ out.forward[0] = -sy * cp;
31
+ out.forward[1] = -sp;
32
+ out.forward[2] = -cy * cp;
33
+ out.right[0] = cy;
34
+ out.right[1] = 0;
35
+ out.right[2] = -sy;
36
+ out.up[0] = -sy * sp;
37
+ out.up[1] = cp;
38
+ out.up[2] = -cy * sp;
39
+ out.orthographic = false;
40
+ out.half = Math.tan(fovY * DEG / 2);
41
+ out.aspect = aspect;
42
+ return out;
43
+ }
44
+ function mapView(out, target, elevation, pitch, orthoHeight, aspect, plane = "xz") {
45
+ orbitView(out, target, elevation, 0, plane === "xy" ? 0 : pitch, 60, aspect);
46
+ out.orthographic = true;
47
+ out.half = orthoHeight / 2;
48
+ return out;
49
+ }
50
+ function poseView(out, position, rotation, orthographic, fovY, orthoHeight, aspect) {
51
+ const x = rotation[0];
52
+ const y = rotation[1];
53
+ const z = rotation[2];
54
+ const w = rotation[3];
55
+ out.eye[0] = position[0];
56
+ out.eye[1] = position[1];
57
+ out.eye[2] = position[2];
58
+ out.right[0] = 1 - 2 * (y * y + z * z);
59
+ out.right[1] = 2 * (x * y + w * z);
60
+ out.right[2] = 2 * (x * z - w * y);
61
+ out.up[0] = 2 * (x * y - w * z);
62
+ out.up[1] = 1 - 2 * (x * x + z * z);
63
+ out.up[2] = 2 * (y * z + w * x);
64
+ out.forward[0] = -2 * (x * z + w * y);
65
+ out.forward[1] = -2 * (y * z - w * x);
66
+ out.forward[2] = -(1 - 2 * (x * x + y * y));
67
+ out.orthographic = orthographic;
68
+ out.half = orthographic ? orthoHeight / 2 : Math.tan(fovY * DEG / 2);
69
+ out.aspect = aspect;
70
+ return out;
71
+ }
72
+ function viewRay(v, x, y, width, height, outOrigin, outDir) {
73
+ const nx = (x / width * 2 - 1) * v.half * v.aspect;
74
+ const ny = (1 - y / height * 2) * v.half;
75
+ if (v.orthographic) {
76
+ for (let i = 0; i < 3; i++) {
77
+ outOrigin[i] = v.eye[i] + v.right[i] * nx + v.up[i] * ny;
78
+ outDir[i] = v.forward[i];
79
+ }
80
+ return;
81
+ }
82
+ const dx = v.forward[0] + v.right[0] * nx + v.up[0] * ny;
83
+ const dy = v.forward[1] + v.right[1] * nx + v.up[1] * ny;
84
+ const dz = v.forward[2] + v.right[2] * nx + v.up[2] * ny;
85
+ const len = Math.sqrt(dx * dx + dy * dy + dz * dz);
86
+ outOrigin[0] = v.eye[0];
87
+ outOrigin[1] = v.eye[1];
88
+ outOrigin[2] = v.eye[2];
89
+ outDir[0] = dx / len;
90
+ outDir[1] = dy / len;
91
+ outDir[2] = dz / len;
92
+ }
93
+ const origin = new Float64Array(3);
94
+ const dir = new Float64Array(3);
95
+ function viewToPlane(v, x, y, width, height, level, out, maxDistance = Number.POSITIVE_INFINITY, axis = 1) {
96
+ viewRay(v, x, y, width, height, origin, dir);
97
+ const d = dir[axis];
98
+ if (Math.abs(d) < 1e-9) return false;
99
+ const t = (level - origin[axis]) / d;
100
+ if (t < 0 || t > maxDistance) return false;
101
+ out[0] = origin[0] + dir[0] * t;
102
+ out[1] = origin[1] + dir[1] * t;
103
+ out[2] = origin[2] + dir[2] * t;
104
+ out[axis] = level;
105
+ return true;
106
+ }
107
+ function viewProject(v, p, width, height, out) {
108
+ const rx = p[0] - v.eye[0];
109
+ const ry = p[1] - v.eye[1];
110
+ const rz = p[2] - v.eye[2];
111
+ const depth = rx * v.forward[0] + ry * v.forward[1] + rz * v.forward[2];
112
+ let sx = rx * v.right[0] + ry * v.right[1] + rz * v.right[2];
113
+ let sy = rx * v.up[0] + ry * v.up[1] + rz * v.up[2];
114
+ if (!v.orthographic) {
115
+ if (depth <= 1e-9) return false;
116
+ sx /= depth;
117
+ sy /= depth;
118
+ }
119
+ out[0] = (sx / (v.half * v.aspect) + 1) * 0.5 * width;
120
+ out[1] = (1 - sy / v.half) * 0.5 * height;
121
+ return true;
122
+ }
123
+ export {
124
+ createView,
125
+ mapView,
126
+ orbitDirection,
127
+ orbitView,
128
+ poseView,
129
+ viewProject,
130
+ viewRay,
131
+ viewToPlane
132
+ };
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@aethervtt/shard-controls",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "LICENSE",
16
+ "README.md"
17
+ ],
18
+ "dependencies": {
19
+ "@aethervtt/shard-core": "0.1.0",
20
+ "@aethervtt/shard-input": "0.1.0",
21
+ "@aethervtt/shard-platform": "0.1.0",
22
+ "@aethervtt/shard-render": "0.1.0",
23
+ "@aethervtt/shard-runtime": "0.1.0",
24
+ "@aethervtt/shard-transform": "0.1.0"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/aethervtt/shard.git",
29
+ "directory": "packages/controls"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public",
33
+ "provenance": true
34
+ },
35
+ "shard": {
36
+ "buildSha": "8e14c9896f82a3554b156f1ffdd68f2cc3e7d78a"
37
+ }
38
+ }