@weasel-js/kernel3d 1.6.1 → 1.7.1
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/index.d.ts +31 -0
- package/dist/index.js +1512 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ import { SceneNode, Scene, NodeId, AreaSelectDep, InsertExtras, InsertDep, NodeA
|
|
|
9
9
|
* `camera3d` dep of its own rather than reusing the kit's `view`.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
/** An orbit camera. The eye sits `distance` world units from `target` at
|
|
13
|
+
* `yaw`/`pitch`; `fov` is the vertical field of view in radians, and
|
|
14
|
+
* `near`/`far` the clip distances. */
|
|
12
15
|
interface Camera3d {
|
|
13
16
|
target: Vec3;
|
|
14
17
|
/** Radians about +y, measured from +z. */
|
|
@@ -22,11 +25,19 @@ interface Camera3d {
|
|
|
22
25
|
}
|
|
23
26
|
/** Short of vertical: at exactly ±π/2 the eye lands on the up axis and `lookAt` degenerates. */
|
|
24
27
|
declare const MAX_PITCH: number;
|
|
28
|
+
/** A camera with defaults for every field not given: origin target, level at
|
|
29
|
+
* yaw 0, distance 10, fov π/4, near 0.1, far 1000. */
|
|
25
30
|
declare function createCamera(init: Partial<Camera3d>): Camera3d;
|
|
31
|
+
/** The eye's world position. */
|
|
26
32
|
declare function cameraEye(camera: Camera3d): Vec3;
|
|
33
|
+
/** World-to-view matrix, with +y up. */
|
|
27
34
|
declare function cameraView(camera: Camera3d): Mat4;
|
|
35
|
+
/** World-to-clip matrix for a pane of the given width/height `aspect`. */
|
|
28
36
|
declare function cameraViewProjection(camera: Camera3d, aspect: number): Mat4;
|
|
37
|
+
/** The camera turned about its target by the given radians. Pitch is clamped
|
|
38
|
+
* to ±`MAX_PITCH`; yaw is not wrapped. */
|
|
29
39
|
declare function orbitBy(camera: Camera3d, deltaYaw: number, deltaPitch: number): Camera3d;
|
|
40
|
+
/** The camera with its distance multiplied by `factor`, clamped to 0.5..500. */
|
|
30
41
|
declare function dollyBy(camera: Camera3d, factor: number): Camera3d;
|
|
31
42
|
|
|
32
43
|
/**
|
|
@@ -38,6 +49,7 @@ declare function dollyBy(camera: Camera3d, factor: number): Camera3d;
|
|
|
38
49
|
* subclass and no special case.
|
|
39
50
|
*/
|
|
40
51
|
|
|
52
|
+
/** Position, rotation and scale of a 3D node. */
|
|
41
53
|
interface Pose3 {
|
|
42
54
|
position: Vec3;
|
|
43
55
|
rotation: Quat;
|
|
@@ -47,7 +59,10 @@ interface Pose3 {
|
|
|
47
59
|
* its own origin — which is what the kernel assumes nothing about — is
|
|
48
60
|
* `UNIT_CUBE`. */
|
|
49
61
|
declare const UNIT_CUBE: Aabb;
|
|
62
|
+
/** A pose at `position`, unscaled and unrotated unless given. */
|
|
50
63
|
declare function pose3(position: Vec3, scale?: Vec3, rotation?: Quat): Pose3;
|
|
64
|
+
/** The pose as a matrix: scale, then rotation, then translation to
|
|
65
|
+
* `position`. */
|
|
51
66
|
declare function poseMatrix(pose: Pose3): Mat4;
|
|
52
67
|
/**
|
|
53
68
|
* The world box a posed primitive occupies, given the box it occupies in its
|
|
@@ -88,6 +103,8 @@ declare function screenToNdc(point: {
|
|
|
88
103
|
x: number;
|
|
89
104
|
y: number;
|
|
90
105
|
};
|
|
106
|
+
/** Inverse of `screenToNdc`: normalized device coordinates (y up) to a point
|
|
107
|
+
* in `rect`'s space (y down). */
|
|
91
108
|
declare function ndcToScreen(ndc: {
|
|
92
109
|
x: number;
|
|
93
110
|
y: number;
|
|
@@ -133,6 +150,8 @@ declare function projectAabbToScreen(box: Aabb, viewProjection: Mat4, rect: Scre
|
|
|
133
150
|
* guessing. A guess would report a fit the kernel does not have.
|
|
134
151
|
*/
|
|
135
152
|
|
|
153
|
+
/** The camera and the pane it draws into; `width`/`height` are the pane's
|
|
154
|
+
* size in the same units as the pointer points. */
|
|
136
155
|
interface Viewport3d {
|
|
137
156
|
camera: Camera3d;
|
|
138
157
|
width: number;
|
|
@@ -145,9 +164,11 @@ interface Viewport3d {
|
|
|
145
164
|
originX?: number;
|
|
146
165
|
originY?: number;
|
|
147
166
|
}
|
|
167
|
+
/** Read on every dep call, so a dep always sees the current camera and pane. */
|
|
148
168
|
type ViewportSource = () => Viewport3d;
|
|
149
169
|
/** A 3D scene is core's scene with a `Pose3`. Nothing wraps it. */
|
|
150
170
|
type Scene3d<TData, TLayer extends string> = Scene<TData, TLayer, Pose3>;
|
|
171
|
+
/** A node of a `Scene3d`. */
|
|
151
172
|
type Node3d<TData, TLayer extends string> = SceneNode<TData, TLayer, Pose3>;
|
|
152
173
|
/**
|
|
153
174
|
* The world box a node occupies. The kernel cannot answer this, and the reason
|
|
@@ -159,6 +180,8 @@ type Node3d<TData, TLayer extends string> = SceneNode<TData, TLayer, Pose3>;
|
|
|
159
180
|
* Omitted, a node is a unit cube carried by its pose.
|
|
160
181
|
*/
|
|
161
182
|
type NodeBounds<TData, TLayer extends string> = (node: Node3d<TData, TLayer>) => Aabb;
|
|
183
|
+
/** What every 3D dep is built from: the scene, the viewport, and optionally
|
|
184
|
+
* each node's world box. */
|
|
162
185
|
interface World3d<TData, TLayer extends string> {
|
|
163
186
|
scene: Scene3d<TData, TLayer>;
|
|
164
187
|
viewport: ViewportSource;
|
|
@@ -256,8 +279,14 @@ declare function collectOverlayBoxes(handles: Iterable<OngoingHandle>, origin: {
|
|
|
256
279
|
* `viewport.dragPan`, and that wants the 2D `view`.
|
|
257
280
|
*/
|
|
258
281
|
|
|
282
|
+
/** `camera.orbit`: an ongoing drag that turns the `camera3d` dep about its
|
|
283
|
+
* target, relative to the camera as it was when the drag began. */
|
|
259
284
|
declare const orbitAction: Action;
|
|
285
|
+
/** `camera.dolly`: moves the `camera3d` dep toward or away from its target by
|
|
286
|
+
* the wheel's `deltaY`. Bound to the wheel by default, in every tool. */
|
|
260
287
|
declare const dollyAction: Action;
|
|
288
|
+
/** A tool that binds drag to `camera.orbit`. Register `orbitAction` alongside
|
|
289
|
+
* it; the tool only declares the binding. */
|
|
261
290
|
declare function useOrbitTool(): Tool<null>;
|
|
262
291
|
|
|
263
292
|
/**
|
|
@@ -269,6 +298,8 @@ declare function useOrbitTool(): Tool<null>;
|
|
|
269
298
|
* anything core does not already offer.
|
|
270
299
|
*/
|
|
271
300
|
|
|
301
|
+
/** The `camera3d` dep: the orbit camera a 3D host owns, which the camera
|
|
302
|
+
* actions read and replace. */
|
|
272
303
|
interface Camera3dDep {
|
|
273
304
|
get(): Camera3d;
|
|
274
305
|
set(camera: Camera3d): void;
|