@ac-kit/graphics-view 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/CHANGELOG.md +80 -0
- package/LICENSE +28 -0
- package/README.md +206 -2
- package/dist/camera/camera3.d.ts +17 -0
- package/dist/camera/camera3.d.ts.map +1 -0
- package/dist/camera/camera3.js +2 -0
- package/dist/camera/camera3.js.map +1 -0
- package/dist/camera/look-around-camera.d.ts +110 -0
- package/dist/camera/look-around-camera.d.ts.map +1 -0
- package/dist/camera/look-around-camera.js +220 -0
- package/dist/camera/look-around-camera.js.map +1 -0
- package/dist/camera/orbit-camera.d.ts +102 -0
- package/dist/camera/orbit-camera.d.ts.map +1 -0
- package/dist/camera/orbit-camera.js +252 -0
- package/dist/camera/orbit-camera.js.map +1 -0
- package/dist/dom/_inertia-input.d.ts +35 -0
- package/dist/dom/_inertia-input.d.ts.map +1 -0
- package/dist/dom/_inertia-input.js +121 -0
- package/dist/dom/_inertia-input.js.map +1 -0
- package/dist/dom/bind-look-around-input.d.ts +54 -0
- package/dist/dom/bind-look-around-input.d.ts.map +1 -0
- package/dist/dom/bind-look-around-input.js +111 -0
- package/dist/dom/bind-look-around-input.js.map +1 -0
- package/dist/dom/bind-orbit-input.d.ts +47 -0
- package/dist/dom/bind-orbit-input.d.ts.map +1 -0
- package/dist/dom/bind-orbit-input.js +118 -0
- package/dist/dom/bind-orbit-input.js.map +1 -0
- package/dist/dom/bind-view2-input.d.ts +60 -0
- package/dist/dom/bind-view2-input.d.ts.map +1 -0
- package/dist/dom/bind-view2-input.js +164 -0
- package/dist/dom/bind-view2-input.js.map +1 -0
- package/dist/dom/index.d.ts +4 -0
- package/dist/dom/index.d.ts.map +1 -0
- package/dist/dom/index.js +4 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/view2/interpolate-view2-frame.d.ts +13 -0
- package/dist/view2/interpolate-view2-frame.d.ts.map +1 -0
- package/dist/view2/interpolate-view2-frame.js +30 -0
- package/dist/view2/interpolate-view2-frame.js.map +1 -0
- package/dist/view2/view2.d.ts +195 -0
- package/dist/view2/view2.d.ts.map +1 -0
- package/dist/view2/view2.js +445 -0
- package/dist/view2/view2.js.map +1 -0
- package/dist/view3/_projection.d.ts +20 -0
- package/dist/view3/_projection.d.ts.map +1 -0
- package/dist/view3/_projection.js +43 -0
- package/dist/view3/_projection.js.map +1 -0
- package/dist/view3/choose-depth-range.d.ts +25 -0
- package/dist/view3/choose-depth-range.d.ts.map +1 -0
- package/dist/view3/choose-depth-range.js +22 -0
- package/dist/view3/choose-depth-range.js.map +1 -0
- package/dist/view3/view3.d.ts +145 -0
- package/dist/view3/view3.d.ts.map +1 -0
- package/dist/view3/view3.js +306 -0
- package/dist/view3/view3.js.map +1 -0
- package/package.json +76 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @ac-kit/graphics-view
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 34e8cfa: First release. Pan, zoom about a point, turn and fit a 2D view, keep it within bounds and scale
|
|
8
|
+
limits, and convert between screen and world coordinates, for Canvas 2D, SVG or
|
|
9
|
+
GPU drawing; `interpolateView2Frame` animates between two frames. Orbit a 3D
|
|
10
|
+
camera around a target or look around from a fixed eye, both with exact view
|
|
11
|
+
matrices at the poles, see it through a perspective or orthographic lens, and
|
|
12
|
+
convert world points to the screen and screen points to picking rays and
|
|
13
|
+
planes, with the frustum, the world size of a pixel, the zero-to-one,
|
|
14
|
+
negative-one-to-one and reversed depth ranges, an infinite far plane and
|
|
15
|
+
`chooseDepthRange`.
|
|
16
|
+
|
|
17
|
+
`@ac-kit/graphics-view/dom` binds a view or a camera to an element's input, on
|
|
18
|
+
`@ac-kit/ui-gesture/dom`: `bindView2Input` (drag pans; wheel, trackpad pinch,
|
|
19
|
+
pinch and double tap zoom about the pointer; arrows pan in the map convention;
|
|
20
|
+
`+` and `-` zoom; optional twist, per-axis pan and zoom, and a panning wheel),
|
|
21
|
+
`bindOrbitInput` (left drag and one touch pan, the right button rotates, two
|
|
22
|
+
touches dolly and rotate, wheel and trackpad pinch dolly, arrows pan or rotate
|
|
23
|
+
with Shift, `+` and `-` dolly; the lens may change between events, and an
|
|
24
|
+
orthographic lens pans at its own scale) and `bindLookAroundInput` (drag turns
|
|
25
|
+
the view by the angle under the pointer, pinch, wheel and `+`/`-` zoom the
|
|
26
|
+
field of view, arrows turn). The `View2` and look-around bindings can continue a
|
|
27
|
+
released drag by exponential decay on animation frames, never under
|
|
28
|
+
`prefers-reduced-motion: reduce`, which they follow while bound. Each binding
|
|
29
|
+
reports hover and taps for picking, supports cooperative gestures for a view
|
|
30
|
+
inside a scrolling page, leaves to the page any wheel or key it does not act on
|
|
31
|
+
(an arrow along an axis that does not pan, a wheel during an orbit press),
|
|
32
|
+
returns a `Disposable`, and stops at an
|
|
33
|
+
`AbortSignal`.
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [34e8cfa]
|
|
38
|
+
- Updated dependencies [34e8cfa]
|
|
39
|
+
- Updated dependencies [34e8cfa]
|
|
40
|
+
- Updated dependencies [34e8cfa]
|
|
41
|
+
- Updated dependencies [34e8cfa]
|
|
42
|
+
- Updated dependencies [34e8cfa]
|
|
43
|
+
- Updated dependencies [34e8cfa]
|
|
44
|
+
- Updated dependencies [34e8cfa]
|
|
45
|
+
- Updated dependencies [34e8cfa]
|
|
46
|
+
- Updated dependencies [34e8cfa]
|
|
47
|
+
- Updated dependencies [34e8cfa]
|
|
48
|
+
- Updated dependencies [34e8cfa]
|
|
49
|
+
- Updated dependencies [34e8cfa]
|
|
50
|
+
- Updated dependencies [34e8cfa]
|
|
51
|
+
- Updated dependencies [34e8cfa]
|
|
52
|
+
- Updated dependencies [34e8cfa]
|
|
53
|
+
- Updated dependencies [34e8cfa]
|
|
54
|
+
- Updated dependencies [34e8cfa]
|
|
55
|
+
- Updated dependencies [34e8cfa]
|
|
56
|
+
- Updated dependencies [34e8cfa]
|
|
57
|
+
- Updated dependencies [34e8cfa]
|
|
58
|
+
- Updated dependencies [34e8cfa]
|
|
59
|
+
- Updated dependencies [34e8cfa]
|
|
60
|
+
- Updated dependencies [34e8cfa]
|
|
61
|
+
- Updated dependencies [34e8cfa]
|
|
62
|
+
- Updated dependencies [34e8cfa]
|
|
63
|
+
- Updated dependencies [34e8cfa]
|
|
64
|
+
- Updated dependencies [34e8cfa]
|
|
65
|
+
- Updated dependencies [34e8cfa]
|
|
66
|
+
- Updated dependencies [34e8cfa]
|
|
67
|
+
- Updated dependencies [34e8cfa]
|
|
68
|
+
- Updated dependencies [34e8cfa]
|
|
69
|
+
- Updated dependencies [34e8cfa]
|
|
70
|
+
- Updated dependencies [34e8cfa]
|
|
71
|
+
- Updated dependencies [34e8cfa]
|
|
72
|
+
- Updated dependencies [34e8cfa]
|
|
73
|
+
- Updated dependencies [34e8cfa]
|
|
74
|
+
- Updated dependencies [34e8cfa]
|
|
75
|
+
- @ac-kit/browser@0.3.0
|
|
76
|
+
- @ac-kit/core@0.12.0
|
|
77
|
+
- @ac-kit/math-scalar@0.3.0
|
|
78
|
+
- @ac-kit/math-linear@0.3.0
|
|
79
|
+
- @ac-kit/math-geometry@0.3.0
|
|
80
|
+
- @ac-kit/ui-gesture@0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Anthony Champagne and contributors
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,207 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ac-kit/graphics-view
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
2D views and 3D cameras with screen ↔ world conversions and picking rays, for
|
|
4
|
+
Canvas 2D, SVG or GPU drawing. The root is pure; the pointer, wheel and
|
|
5
|
+
keyboard bindings live in `@ac-kit/graphics-view/dom`.
|
|
6
|
+
|
|
7
|
+
The root is pure: it reads no browser global and knows no GPU type, so it runs
|
|
8
|
+
under Node. Screen coordinates are CSS pixels of the element the view is shown
|
|
9
|
+
in, origin top-left, y down. Math values follow the `@ac-kit/math-linear`
|
|
10
|
+
standard: the output comes first, nothing allocates after construction, and
|
|
11
|
+
builders and setters called once per event throw `RangeError` where a query
|
|
12
|
+
never does. Every class has a `version` that increases on each change, so a
|
|
13
|
+
renderer compares one number to know whether to redraw. A package that needs
|
|
14
|
+
only the arithmetic uses `@ac-kit/math-linear` and `@ac-kit/math-geometry`
|
|
15
|
+
directly.
|
|
16
|
+
|
|
17
|
+
## `View2`: pan, zoom and turn a 2D view
|
|
18
|
+
|
|
19
|
+
A view says which world area a viewport shows. Pans, zooms and turns come in
|
|
20
|
+
screen pixels, as gestures produce them, and are clamped by the scale limits
|
|
21
|
+
and the bounds after each call; a call whose result would not be finite
|
|
22
|
+
changes nothing.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { box2Create, box2FromXywh } from "@ac-kit/math-geometry";
|
|
26
|
+
import { affine2Create, vec2Create, vec2Of } from "@ac-kit/math-linear";
|
|
27
|
+
import { View2 } from "@ac-kit/graphics-view";
|
|
28
|
+
|
|
29
|
+
const view = new View2({ yAxis: "up", width: 800, height: 600 });
|
|
30
|
+
view.fit(box2FromXywh(box2Create(), 0, 0, 100, 50), { padding: 24 });
|
|
31
|
+
view.zoomAbout(2, 400, 300); // the world point under (400, 300) stays there
|
|
32
|
+
|
|
33
|
+
// Canvas 2D: context.setTransform(...view.getWorldToScreen(affine2Create(), devicePixelRatio))
|
|
34
|
+
// SVG: transform="matrix(a b c d e f)" with the same six numbers
|
|
35
|
+
const screen = view.worldToScreen(vec2Create(), vec2Of(10, 10));
|
|
36
|
+
const world = view.screenToWorld(vec2Create(), screen);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`getWorldToClip` and `getViewProjection` give the matrix for a GPU pass that
|
|
40
|
+
covers the viewport. `interpolateView2Frame` animates between two
|
|
41
|
+
`getFrame()` values: the centre linearly, the scale geometrically, the
|
|
42
|
+
rotation along the shorter arc, both ends exact.
|
|
43
|
+
|
|
44
|
+
## `OrbitCamera` and `LookAroundCamera`: 3D cameras
|
|
45
|
+
|
|
46
|
+
`OrbitCamera` orbits a target by azimuth and inclination about the up axis
|
|
47
|
+
(`"y"` by default, `"z"` for charts and geography), dollies within a distance
|
|
48
|
+
range and pans the target, kept inside an optional sphere. The inclination
|
|
49
|
+
never reaches a pole (its bounds lie within (0, π)) and the camera's up never
|
|
50
|
+
flips. Frames outside the bounds are clamped, never refused.
|
|
51
|
+
|
|
52
|
+
`LookAroundCamera` looks around from a fixed eye with a yaw and a pitch and no
|
|
53
|
+
roll; zoom changes the field of view. `projectionScale` takes the radius
|
|
54
|
+
function of the projection you draw with (`Math.tan` for a perspective view),
|
|
55
|
+
and `getProjectionRotation` gives the rotation an azimuthal sky chart projects
|
|
56
|
+
with.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { OrbitCamera, LookAroundCamera } from "@ac-kit/graphics-view";
|
|
60
|
+
import { mat4x4Create, vec3Of } from "@ac-kit/math-linear";
|
|
61
|
+
|
|
62
|
+
const orbit = new OrbitCamera({
|
|
63
|
+
target: vec3Of(0, 0, 0),
|
|
64
|
+
eye: vec3Of(0, 5, 10),
|
|
65
|
+
distance: [1, 50],
|
|
66
|
+
inclination: [0.1, Math.PI / 2],
|
|
67
|
+
});
|
|
68
|
+
orbit.rotate(0.1, -0.05);
|
|
69
|
+
orbit.dolly(0.9);
|
|
70
|
+
const view = orbit.getView(mat4x4Create()); // right-handed, looking down −Z
|
|
71
|
+
|
|
72
|
+
const sky = new LookAroundCamera({ yaw: Math.PI / 2, pitch: 0.2 });
|
|
73
|
+
sky.zoom(1.5);
|
|
74
|
+
const pixelsPerUnit = sky.projectionScale(Math.tan, 600);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## `/dom`: pointer, wheel and keyboard input
|
|
78
|
+
|
|
79
|
+
`bindView2Input`, `bindOrbitInput` and `bindLookAroundInput` map the gestures of
|
|
80
|
+
`@ac-kit/ui-gesture/dom` onto a view or a camera. Each takes the element, the
|
|
81
|
+
view or camera, and options with an `onChange` that is called once per input
|
|
82
|
+
event that changed it (ask the renderer for a frame there). Each returns a
|
|
83
|
+
`Disposable`, and also stops at `signal`. Bind one binding per element: claims
|
|
84
|
+
do not arbitrate the wheel, so two bindings on one element would both zoom. Style
|
|
85
|
+
the element `touch-action: none` and make it focusable (`tabindex="0"`): a press
|
|
86
|
+
focuses it, so its keys work next. Taps and hover are passed through (`onTap`,
|
|
87
|
+
`onHover`, `onHoverEnd`) for picking. A wheel step or key the binding does not
|
|
88
|
+
act on is left to the page, neither cancelled nor stopped: an arrow along an
|
|
89
|
+
axis `panAxes` leaves out, a zoom key with `zoomAxes: "none"`, and, for the
|
|
90
|
+
orbit, a wheel during a press.
|
|
91
|
+
|
|
92
|
+
`cooperative: true` leaves an unmodified wheel and a one-finger touch to the
|
|
93
|
+
page, for a view inside a scrolling page. The page must then keep its own
|
|
94
|
+
gestures: style that element `touch-action: pan-x pan-y pinch-zoom` instead of
|
|
95
|
+
`none`, or a finger that starts on it can never scroll the page.
|
|
96
|
+
|
|
97
|
+
```css
|
|
98
|
+
.view {
|
|
99
|
+
touch-action: none; /* the view owns every gesture */
|
|
100
|
+
}
|
|
101
|
+
.view.cooperative {
|
|
102
|
+
touch-action: pan-x pan-y pinch-zoom; /* with `cooperative: true` */
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import { FrameScheduler } from "@ac-kit/browser";
|
|
108
|
+
import { OrbitCamera, View2 } from "@ac-kit/graphics-view";
|
|
109
|
+
import {
|
|
110
|
+
bindOrbitInput,
|
|
111
|
+
bindView2Input,
|
|
112
|
+
} from "@ac-kit/graphics-view/dom";
|
|
113
|
+
import { vec3Of } from "@ac-kit/math-linear";
|
|
114
|
+
|
|
115
|
+
const controller = new AbortController();
|
|
116
|
+
const { signal } = controller;
|
|
117
|
+
// Two canvases, each focusable (tabindex="0") and class "view".
|
|
118
|
+
const canvas = document.querySelector("#map")!;
|
|
119
|
+
const orbitCanvas = document.querySelector("#scene")!;
|
|
120
|
+
const scheduler = new FrameScheduler(window, () => draw(), { signal });
|
|
121
|
+
|
|
122
|
+
// 2D: drag pans, the wheel, a pinch and a double tap zoom about the pointer,
|
|
123
|
+
// arrows pan (ArrowRight reveals what lies to the right), + and - zoom about
|
|
124
|
+
// the centre. `rotate` lets two fingers turn the view.
|
|
125
|
+
const view = new View2({ width: 800, height: 600, rotatable: true });
|
|
126
|
+
bindView2Input(canvas, view, {
|
|
127
|
+
onChange: () => scheduler.invalidate(),
|
|
128
|
+
rotate: true,
|
|
129
|
+
inertia: true,
|
|
130
|
+
signal,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// 3D: left drag and one touch pan, the right button rotates, two touches
|
|
134
|
+
// pinch to dolly and move together to rotate, the wheel and a trackpad pinch
|
|
135
|
+
// dolly, arrows pan (rotate with Shift), + and - dolly.
|
|
136
|
+
const camera = new OrbitCamera({
|
|
137
|
+
target: vec3Of(0, 0, 0),
|
|
138
|
+
eye: vec3Of(0, 5, 10),
|
|
139
|
+
distance: [1, 50],
|
|
140
|
+
inclination: [0.1, Math.PI / 2],
|
|
141
|
+
});
|
|
142
|
+
bindOrbitInput(orbitCanvas, camera, {
|
|
143
|
+
lens: { kind: "perspective", fovY: Math.PI / 3, near: 0.1, far: 100 },
|
|
144
|
+
onChange: () => scheduler.invalidate(),
|
|
145
|
+
signal,
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`bindLookAroundInput(element, lookAroundCamera, options)` turns a
|
|
150
|
+
`LookAroundCamera` the same way: a drag turns the view by the angle under the
|
|
151
|
+
pointer (give `radius` the projection's radius function, `Math.tan` by
|
|
152
|
+
default), a pinch, the wheel and `+`/`-` zoom the field of view, arrows turn.
|
|
153
|
+
|
|
154
|
+
- `View2` options: `zoomAxes` and `panAxes` (`"xy"`, `"x"`, `"y"`, `"none"`:
|
|
155
|
+
a time axis zoomed alone), `wheel: "pan"` for an unmodified wheel that pans,
|
|
156
|
+
`keyPanPixels`, `keyZoomFactor`, `doubleTapZoomFactor` (1 turns the double
|
|
157
|
+
tap off) and `accept` (where a press may start, such as a chart's plot area).
|
|
158
|
+
- `inertia` (`View2` and look-around) continues a released one-finger drag by
|
|
159
|
+
exponential decay on animation frames (`frames` defaults to the element's
|
|
160
|
+
window), and ends at the next press, wheel, key or tap, or at `signal`. It
|
|
161
|
+
never runs while `(prefers-reduced-motion: reduce)` matches, which is
|
|
162
|
+
followed while the binding lives.
|
|
163
|
+
- Orbit options: `lens` (a lens, or a function read at every event, so a zoom
|
|
164
|
+
by field of view is followed; an orthographic lens pans at its own scale),
|
|
165
|
+
`rotationPerHeight`, `keyPanPixels`, `keyRotationRadians`, `keyDollyFactor`
|
|
166
|
+
and `wheelZoomPixels`.
|
|
167
|
+
- Zoom and rotate buttons (WCAG 2.5.1, 2.5.7): the bindings add no controls;
|
|
168
|
+
put buttons beside the view that call `view.zoomAbout(2, width / 2,
|
|
169
|
+
height / 2)`, `view.zoomAbout(0.5, …)`, `view.fit(…)` and, for a rotatable
|
|
170
|
+
view, `view.rotateAbout(…)`.
|
|
171
|
+
- An invalid step or factor throws a `RangeError` at bind time; so does a lens
|
|
172
|
+
the camera refuses.
|
|
173
|
+
|
|
174
|
+
## `View3`: a camera seen through a lens
|
|
175
|
+
|
|
176
|
+
`View3` puts a camera behind a perspective or orthographic lens on a
|
|
177
|
+
viewport, and gives the matrices a renderer needs and the conversions between
|
|
178
|
+
world points, screen points and picking rays. Matrices are cached and
|
|
179
|
+
recomputed when the camera, the lens, the depth range or the viewport changes.
|
|
180
|
+
`chooseDepthRange` picks reversed depth (`"one-to-zero"`) only where it gains
|
|
181
|
+
precision: a `depth32float` attachment and native zero-to-one clip depth. The
|
|
182
|
+
far plane may be `Infinity`.
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
import { chooseDepthRange, OrbitCamera, View3 } from "@ac-kit/graphics-view";
|
|
186
|
+
import { ray3Create } from "@ac-kit/math-geometry";
|
|
187
|
+
import { vec3Create, vec3Of } from "@ac-kit/math-linear";
|
|
188
|
+
|
|
189
|
+
const camera = new OrbitCamera({
|
|
190
|
+
target: vec3Of(0, 0, 0),
|
|
191
|
+
eye: vec3Of(0, 5, 10),
|
|
192
|
+
distance: [1, 50],
|
|
193
|
+
inclination: [0.1, Math.PI / 2],
|
|
194
|
+
});
|
|
195
|
+
const view = new View3({
|
|
196
|
+
camera,
|
|
197
|
+
lens: { kind: "perspective", fovY: Math.PI / 3, near: 0.1, far: Infinity },
|
|
198
|
+
depthRange: chooseDepthRange({ nativeZeroToOne: true, floatDepth: true }),
|
|
199
|
+
width: 800,
|
|
200
|
+
height: 600,
|
|
201
|
+
});
|
|
202
|
+
const ray = view.screenToRay(ray3Create(), 400, 300); // the picking ray through the centre
|
|
203
|
+
const pixel = view.worldToScreen(vec3Create(), vec3Of(0, 0, 0)); // [x px, y px, depth]
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
See the [generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/graphics-view/)
|
|
207
|
+
for the full reference.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Mat4x4, Vec3 } from "@ac-kit/math-linear";
|
|
2
|
+
/** Which world axis is up. */
|
|
3
|
+
export type CameraUp = "y" | "z";
|
|
4
|
+
/** What a `View3` needs from a camera. */
|
|
5
|
+
export interface Camera3 {
|
|
6
|
+
/** Increases on each change of the camera. */
|
|
7
|
+
readonly version: number;
|
|
8
|
+
/**
|
|
9
|
+
* A camera that owns its field of view (look-around zoom); `undefined`
|
|
10
|
+
* otherwise.
|
|
11
|
+
*/
|
|
12
|
+
readonly fovY: number | undefined;
|
|
13
|
+
/** World → camera: right-handed, looking down −Z. */
|
|
14
|
+
getView(out: Mat4x4): Mat4x4;
|
|
15
|
+
getEye(out: Vec3): Vec3;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=camera3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera3.d.ts","sourceRoot":"","sources":["../../src/camera/camera3.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAExD,8BAA8B;AAC9B,MAAM,MAAM,QAAQ,GAAG,GAAG,GAAG,GAAG,CAAC;AAEjC,0CAA0C;AAC1C,MAAM,WAAW,OAAO;IACvB,8CAA8C;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,qDAAqD;IACrD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,MAAM,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera3.js","sourceRoot":"","sources":["../../src/camera/camera3.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type Callable } from "@ac-kit/core";
|
|
2
|
+
import { type Mat3x3, type Mat4x4, type ReadonlyVec3, type Vec3 } from "@ac-kit/math-linear";
|
|
3
|
+
import type { Camera3, CameraUp } from "./camera3.js";
|
|
4
|
+
export type LookAroundCameraOptions = {
|
|
5
|
+
/** Default the origin. */
|
|
6
|
+
readonly eye?: ReadonlyVec3;
|
|
7
|
+
/**
|
|
8
|
+
* `"z"` (default): east-north-up, yaw clockwise from north (+Y) toward east
|
|
9
|
+
* (+X), as math-geometry's `HorizontalCoords` azimuth; `"y"`: yaw from −Z
|
|
10
|
+
* toward +X.
|
|
11
|
+
*/
|
|
12
|
+
readonly up?: CameraUp;
|
|
13
|
+
readonly yaw?: number;
|
|
14
|
+
/** Elevation above the horizontal plane, radians. */
|
|
15
|
+
readonly pitch?: number;
|
|
16
|
+
/** Default [−π/2, π/2]. */
|
|
17
|
+
readonly pitchLimits?: readonly [min: number, max: number];
|
|
18
|
+
/** Vertical field of view, radians. Default π/3. */
|
|
19
|
+
readonly fovY?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Default [π/180, 2π/3]; `projectionScale` refuses a field beyond a
|
|
22
|
+
* projection's domain.
|
|
23
|
+
*/
|
|
24
|
+
readonly fovLimits?: readonly [min: number, max: number];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Looking around from a fixed eye: a sky dome, a first-person view, an
|
|
28
|
+
* azimuthal sky chart. Yaw and pitch, no roll; zoom changes the field of view.
|
|
29
|
+
* The axes are built from the angles, so straight up and straight down are
|
|
30
|
+
* exact (the yaw still turns the view there) and the camera's up never flips.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const camera = new LookAroundCamera({ yaw: Math.PI / 2, pitch: 0.2 });
|
|
34
|
+
* camera.rotate(0.01, 0);
|
|
35
|
+
* camera.zoom(1.5);
|
|
36
|
+
* const view = camera.getView(mat4x4Create());
|
|
37
|
+
*/
|
|
38
|
+
export declare class LookAroundCamera implements Camera3 {
|
|
39
|
+
private readonly up_;
|
|
40
|
+
private readonly eye_;
|
|
41
|
+
private readonly minPitch_;
|
|
42
|
+
private readonly maxPitch_;
|
|
43
|
+
private readonly minFov_;
|
|
44
|
+
private readonly maxFov_;
|
|
45
|
+
private yaw_;
|
|
46
|
+
private pitch_;
|
|
47
|
+
private fovY_;
|
|
48
|
+
private version_;
|
|
49
|
+
/**
|
|
50
|
+
* @throws {RangeError} For limits out of order or out of range (pitch within
|
|
51
|
+
* [−π/2, π/2], field of view within (0, π)), or a non-finite eye, yaw,
|
|
52
|
+
* pitch or field of view.
|
|
53
|
+
*/
|
|
54
|
+
constructor(options?: LookAroundCameraOptions);
|
|
55
|
+
/** Increases on each change of the orientation or the field of view. */
|
|
56
|
+
get version(): number;
|
|
57
|
+
get fovY(): number;
|
|
58
|
+
/** Radians in [0, 2π). */
|
|
59
|
+
get yaw(): number;
|
|
60
|
+
get pitch(): number;
|
|
61
|
+
getEye(out: Vec3): Vec3;
|
|
62
|
+
/** World → camera: right-handed, looking down −Z, the up axis up. */
|
|
63
|
+
getView(out: Mat4x4): Mat4x4;
|
|
64
|
+
/** Unit view direction. */
|
|
65
|
+
getDirection(out: Vec3): Vec3;
|
|
66
|
+
/**
|
|
67
|
+
* Adds radians; the yaw is wrapped to [0, 2π) and the pitch clamped.
|
|
68
|
+
*
|
|
69
|
+
* @throws {RangeError} For non-finite input.
|
|
70
|
+
*/
|
|
71
|
+
rotate(yaw: number, pitch: number): void;
|
|
72
|
+
/** @throws {RangeError} For a non-finite yaw or pitch. */
|
|
73
|
+
setOrientation(yaw: number, pitch: number): void;
|
|
74
|
+
/**
|
|
75
|
+
* Turns toward `direction` (need not be unit, at any magnitude).
|
|
76
|
+
*
|
|
77
|
+
* @throws {RangeError} For a zero or non-finite direction.
|
|
78
|
+
*/
|
|
79
|
+
lookToward(direction: ReadonlyVec3): void;
|
|
80
|
+
/**
|
|
81
|
+
* Divides the field of view by `factor` (> 1 zooms in), clamped.
|
|
82
|
+
*
|
|
83
|
+
* @throws {RangeError} Unless positive and finite.
|
|
84
|
+
*/
|
|
85
|
+
zoom(factor: number): void;
|
|
86
|
+
/**
|
|
87
|
+
* The rotation `math-map-projection`'s azimuthal kernels take: the view
|
|
88
|
+
* direction to +X, the camera's left to +Y and up to +Z. A sky seen from
|
|
89
|
+
* inside is then mirrored in x on screen (`DrawSphereProjection.mirror`).
|
|
90
|
+
*/
|
|
91
|
+
getProjectionRotation(out: Mat3x3): Mat3x3;
|
|
92
|
+
/**
|
|
93
|
+
* Screen pixels per projection-plane unit so that the field of view spans
|
|
94
|
+
* `viewportHeight` through a projection whose plane distance from the centre
|
|
95
|
+
* at angular distance `angle` is `radius(angle)` — one of
|
|
96
|
+
* math-map-projection's `…Radius` functions (`stereographicRadius`), or
|
|
97
|
+
* `Math.tan` for a perspective (gnomonic) view: `(viewportHeight / 2) /
|
|
98
|
+
* radius(fovY / 2)`. Taking the function, not a projection name, keeps this
|
|
99
|
+
* package free of math-map-projection. O(1).
|
|
100
|
+
*
|
|
101
|
+
* @throws {RangeError} When `viewportHeight` is not positive and finite, or
|
|
102
|
+
* `radius(fovY / 2)` is not finite and positive (half the field at or
|
|
103
|
+
* beyond the projection's domain).
|
|
104
|
+
*/
|
|
105
|
+
projectionScale(radius: Callable<[angle: number], number>, viewportHeight: number): number;
|
|
106
|
+
/** Writes the forward, right, up and back axes in the world frame. */
|
|
107
|
+
private axes_;
|
|
108
|
+
private commit_;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=look-around-camera.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"look-around-camera.d.ts","sourceRoot":"","sources":["../../src/camera/look-around-camera.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,QAAQ,EAIb,MAAM,cAAc,CAAC;AAOtB,OAAO,EACN,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,IAAI,EAQT,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEtD,MAAM,MAAM,uBAAuB,GAAG;IACrC,0BAA0B;IAC1B,QAAQ,CAAC,GAAG,CAAC,EAAE,YAAY,CAAC;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,2BAA2B;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC3D,oDAAoD;IACpD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;CACzD,CAAC;AAgCF;;;;;;;;;;;GAWG;AACH,qBAAa,gBAAiB,YAAW,OAAO;IAC/C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAW;IAC/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAsB;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,QAAQ,CAAK;IAErB;;;;OAIG;IACH,YAAY,OAAO,GAAE,uBAA4B,EA2ChD;IAED,wEAAwE;IACxE,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,0BAA0B;IAC1B,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,MAAM,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAEtB;IAED,qEAAqE;IACrE,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG3B;IAED,2BAA2B;IAC3B,YAAY,CAAC,GAAG,EAAE,IAAI,GAAG,IAAI,CAG5B;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAQvC;IAED,0DAA0D;IAC1D,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAQ/C;IAED;;;;OAIG;IACH,UAAU,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI,CAyBxC;IAED;;;;OAIG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAOzB;IAED;;;;OAIG;IACH,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAezC;IAED;;;;;;;;;;;;OAYG;IACH,eAAe,CACd,MAAM,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EACzC,cAAc,EAAE,MAAM,GACpB,MAAM,CAaR;IAED,sEAAsE;IACtE,OAAO,CAAC,KAAK;IAeb,OAAO,CAAC,OAAO;CAQf"}
|