melonjs 19.6.0 → 19.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/README.md +17 -14
- package/build/application/application.d.ts +34 -2
- package/build/application/application.d.ts.map +1 -1
- package/build/application/settings.d.ts +37 -1
- package/build/application/settings.d.ts.map +1 -1
- package/build/camera/camera2d.d.ts +59 -7
- package/build/camera/camera2d.d.ts.map +1 -1
- package/build/camera/camera3d.d.ts +335 -0
- package/build/camera/camera3d.d.ts.map +1 -0
- package/build/camera/frustum.d.ts +162 -0
- package/build/camera/frustum.d.ts.map +1 -0
- package/build/const.d.ts +30 -3
- package/build/const.d.ts.map +1 -1
- package/build/geometries/sphere.d.ts +105 -0
- package/build/geometries/sphere.d.ts.map +1 -0
- package/build/index.d.ts +6 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +27497 -24696
- package/build/index.js.map +4 -4
- package/build/input/keyboard.d.ts.map +1 -1
- package/build/input/pointerevent.d.ts.map +1 -1
- package/build/lang/deprecated.d.ts +18 -0
- package/build/lang/deprecated.d.ts.map +1 -1
- package/build/level/tiled/TMXLayer.d.ts.map +1 -1
- package/build/loader/loadingscreen.d.ts +8 -0
- package/build/loader/loadingscreen.d.ts.map +1 -1
- package/build/loader/parsers/mtl.d.ts.map +1 -1
- package/build/loader/parsers/obj.d.ts.map +1 -1
- package/build/math/color.d.ts +43 -5
- package/build/math/color.d.ts.map +1 -1
- package/build/math/math.d.ts +44 -0
- package/build/math/math.d.ts.map +1 -1
- package/build/math/matrix3d.d.ts +1 -1
- package/build/math/observableVector2d.d.ts +14 -2
- package/build/math/observableVector2d.d.ts.map +1 -1
- package/build/math/observableVector3d.d.ts +14 -2
- package/build/math/observableVector3d.d.ts.map +1 -1
- package/build/math/vector2d.d.ts +16 -2
- package/build/math/vector2d.d.ts.map +1 -1
- package/build/math/vector3d.d.ts +16 -2
- package/build/math/vector3d.d.ts.map +1 -1
- package/build/particles/emitter.d.ts.map +1 -1
- package/build/physics/adapter.d.ts +77 -0
- package/build/physics/adapter.d.ts.map +1 -1
- package/build/physics/broadphase/aabb3d.d.ts +115 -0
- package/build/physics/broadphase/aabb3d.d.ts.map +1 -0
- package/build/physics/broadphase/broadphase.d.ts +74 -0
- package/build/physics/broadphase/broadphase.d.ts.map +1 -0
- package/build/physics/broadphase/factory.d.ts +30 -0
- package/build/physics/broadphase/factory.d.ts.map +1 -0
- package/build/physics/broadphase/octree.d.ts +325 -0
- package/build/physics/broadphase/octree.d.ts.map +1 -0
- package/build/physics/broadphase/quadtree.d.ts +184 -0
- package/build/physics/broadphase/quadtree.d.ts.map +1 -0
- package/build/physics/builtin/body.d.ts +7 -3
- package/build/physics/builtin/body.d.ts.map +1 -1
- package/build/physics/builtin/builtin-adapter.d.ts +6 -1
- package/build/physics/builtin/builtin-adapter.d.ts.map +1 -1
- package/build/physics/builtin/raycast.d.ts.map +1 -1
- package/build/physics/world.d.ts +15 -4
- package/build/physics/world.d.ts.map +1 -1
- package/build/renderable/container.d.ts +51 -5
- package/build/renderable/container.d.ts.map +1 -1
- package/build/renderable/mesh.d.ts +85 -10
- package/build/renderable/mesh.d.ts.map +1 -1
- package/build/renderable/renderable.d.ts +9 -4
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/ui/uitextbutton.d.ts +2 -1
- package/build/renderable/ui/uitextbutton.d.ts.map +1 -1
- package/build/state/stage.d.ts +8 -0
- package/build/state/stage.d.ts.map +1 -1
- package/build/state/state.d.ts.map +1 -1
- package/build/system/device.d.ts +196 -310
- package/build/system/device.d.ts.map +1 -1
- package/build/system/event.d.ts +49 -0
- package/build/system/event.d.ts.map +1 -1
- package/build/system/fullscreen.d.ts +16 -0
- package/build/system/fullscreen.d.ts.map +1 -0
- package/build/system/platform.d.ts +32 -4
- package/build/system/platform.d.ts.map +1 -1
- package/build/system/timer.d.ts.map +1 -1
- package/build/utils/function.d.ts +7 -1
- package/build/utils/function.d.ts.map +1 -1
- package/build/utils/types.d.ts +5 -0
- package/build/utils/types.d.ts.map +1 -1
- package/build/video/buffer/vertex.d.ts +19 -4
- package/build/video/buffer/vertex.d.ts.map +1 -1
- package/build/video/canvas/canvas_renderer.d.ts +4 -4
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
- package/build/video/canvas_factory.d.ts +25 -0
- package/build/video/canvas_factory.d.ts.map +1 -0
- package/build/video/renderer.d.ts +89 -15
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/renderstate.d.ts +12 -0
- package/build/video/renderstate.d.ts.map +1 -1
- package/build/video/rendertarget/rendertarget.d.ts +3 -1
- package/build/video/rendertarget/rendertarget.d.ts.map +1 -1
- package/build/video/texture/cache.d.ts +5 -0
- package/build/video/texture/cache.d.ts.map +1 -1
- package/build/video/texture/resource.d.ts +22 -14
- package/build/video/texture/resource.d.ts.map +1 -1
- package/build/video/video.d.ts +3 -1
- package/build/video/video.d.ts.map +1 -1
- package/build/video/webgl/batchers/batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/lit_quad_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/material_batcher.d.ts +9 -0
- package/build/video/webgl/batchers/material_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/mesh_batcher.d.ts +45 -1
- package/build/video/webgl/batchers/mesh_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/primitive_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/quad_batcher.d.ts +2 -2
- package/build/video/webgl/batchers/quad_batcher.d.ts.map +1 -1
- package/build/video/webgl/renderers/tmxlayer/orthogonal.d.ts.map +1 -1
- package/build/video/webgl/webgl_renderer.d.ts +2 -2
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/package.json +4 -3
- package/build/physics/builtin/quadtree.d.ts +0 -112
- package/build/physics/builtin/quadtree.d.ts.map +0 -1
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import type { ObservableVector3d } from "../math/observableVector3d.ts";
|
|
2
|
+
import { Vector3d } from "../math/vector3d.ts";
|
|
3
|
+
import type Container from "./../renderable/container.js";
|
|
4
|
+
import type Renderable from "./../renderable/renderable.js";
|
|
5
|
+
import type Renderer from "./../video/renderer.js";
|
|
6
|
+
import Camera2d from "./camera2d.ts";
|
|
7
|
+
import Frustum, { type FrustumOptions } from "./frustum.ts";
|
|
8
|
+
/**
|
|
9
|
+
* A perspective camera that extends {@link Camera2d} with a view
|
|
10
|
+
* {@link Frustum} (fov / aspect / near / far) and orientation
|
|
11
|
+
* (pitch / yaw / roll). Slots into `Stage.cameras` as a drop-in
|
|
12
|
+
* replacement for `Camera2d` — inherits the post-effect FBO bracket,
|
|
13
|
+
* color-matrix, fade / shake / follow plumbing, and screen viewport.
|
|
14
|
+
*
|
|
15
|
+
* **WebGL required.** Camera3d's perspective projection, depth-buffer
|
|
16
|
+
* painter sort and mesh draw path all live in the WebGL renderer; the
|
|
17
|
+
* Canvas backend has none of these and would render a stuck blank scene.
|
|
18
|
+
* Construct the Application with `renderer: video.WEBGL` to get a hard
|
|
19
|
+
* throw at construction time if WebGL is unavailable. Pairing
|
|
20
|
+
* `cameraClass: Camera3d` with `video.AUTO` will emit a `console.warn`
|
|
21
|
+
* at construction (and silently misrender) when AUTO falls back to
|
|
22
|
+
* Canvas — see {@link ApplicationSettings.renderer} for the contract.
|
|
23
|
+
*
|
|
24
|
+
* Conventions:
|
|
25
|
+
* - **Y-down + +Z forward.** Sprite at higher `pos.y` appears lower
|
|
26
|
+
* on screen (same as Camera2d). Sprite at higher `pos.z` is
|
|
27
|
+
* farther from the camera and renders smaller. Matches melonJS's
|
|
28
|
+
* 2D conventions so existing Camera2d code translates directly.
|
|
29
|
+
* - **Rotations are extrinsic XYZ.** `pitch` (X axis, look up/down),
|
|
30
|
+
* `yaw` (Y axis, look left/right), `roll` (Z axis, screen-plane
|
|
31
|
+
* bank — also exposed as `Camera2d.rotation` via Renderable
|
|
32
|
+
* inheritance for backward compatibility).
|
|
33
|
+
* - **Follow offset (PR B scope).** When a target is set,
|
|
34
|
+
* `followOffset` is applied in **world space**:
|
|
35
|
+
* `camera.pos = target.pos + followOffset`. Target-rotation-aware
|
|
36
|
+
* follow (Cinemachine / Unreal spring-arm style, where the offset
|
|
37
|
+
* rotates with the target's orientation) is deferred until a
|
|
38
|
+
* showcase needs it (e.g. AfterBurner's banking jet).
|
|
39
|
+
*
|
|
40
|
+
* Known limitations (PR B scope):
|
|
41
|
+
* - `Light2d` is 2D-only — visible artifacts under perspective.
|
|
42
|
+
* Avoid combining with Camera3d for now.
|
|
43
|
+
* - `localToWorld` / `worldToLocal` overrides fall back to the
|
|
44
|
+
* ortho-equivalent 2D projection at z=0. Full 3D unproject for
|
|
45
|
+
* arbitrary depth is future work.
|
|
46
|
+
* @category Camera
|
|
47
|
+
* @example
|
|
48
|
+
* // opt in app-wide:
|
|
49
|
+
* const app = new Application(1024, 768, {
|
|
50
|
+
* parent: "screen",
|
|
51
|
+
* cameraClass: Camera3d,
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // or per-stage with custom fov:
|
|
55
|
+
* class GameStage extends Stage {
|
|
56
|
+
* constructor() {
|
|
57
|
+
* super({
|
|
58
|
+
* cameras: [new Camera3d(0, 0, 1024, 768, { fov: Math.PI / 3 })],
|
|
59
|
+
* });
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
*/
|
|
63
|
+
export default class Camera3d extends Camera2d {
|
|
64
|
+
/**
|
|
65
|
+
* Override `Camera2d.defaultSortOn` to declare `"depth"` as this
|
|
66
|
+
* camera's preferred sort mode. `Application` / `Stage` apply this
|
|
67
|
+
* to `world.sortOn` at bootstrap, so games opting into Camera3d via
|
|
68
|
+
* `cameraClass: Camera3d` get camera-distance painter's sort for
|
|
69
|
+
* free — the only correct sort for alpha-blended sprites under
|
|
70
|
+
* perspective.
|
|
71
|
+
*/
|
|
72
|
+
static defaultSortOn: "x" | "y" | "z" | "depth";
|
|
73
|
+
/**
|
|
74
|
+
* the view frustum (perspective parameters + projection matrix).
|
|
75
|
+
* Mutating `frustum.fov` / `aspect` / `near` / `far` directly
|
|
76
|
+
* requires calling `frustum.update()` to rebuild the matrix;
|
|
77
|
+
* the proxy setters on this camera (`camera.fov = ...`) handle
|
|
78
|
+
* that automatically.
|
|
79
|
+
*/
|
|
80
|
+
frustum: Frustum;
|
|
81
|
+
/**
|
|
82
|
+
* X-axis rotation in radians (look up/down). Positive values
|
|
83
|
+
* pitch the camera up.
|
|
84
|
+
* @default 0
|
|
85
|
+
*/
|
|
86
|
+
pitch: number;
|
|
87
|
+
/**
|
|
88
|
+
* Y-axis rotation in radians (look left/right). Positive values
|
|
89
|
+
* yaw the camera to the right.
|
|
90
|
+
* @default 0
|
|
91
|
+
*/
|
|
92
|
+
yaw: number;
|
|
93
|
+
/**
|
|
94
|
+
* World-space offset from the followed target. When `target` is
|
|
95
|
+
* set via {@link Camera2d#follow}, the camera position resolves to
|
|
96
|
+
* `target.pos + followOffset`. Common usage: `(0, -2, -8)` for a
|
|
97
|
+
* behind-and-above third-person view.
|
|
98
|
+
*
|
|
99
|
+
* Treated as world-space in this release — target-rotation-aware
|
|
100
|
+
* follow (where the offset rotates with the target's orientation,
|
|
101
|
+
* Cinemachine / Unreal spring-arm style) is deferred until a
|
|
102
|
+
* showcase needs it (e.g. AfterBurner's banking jet).
|
|
103
|
+
* @default (0, 0, 0)
|
|
104
|
+
*/
|
|
105
|
+
followOffset: Vector3d;
|
|
106
|
+
/**
|
|
107
|
+
* Reserved for future follow-look-ahead support — currently unused
|
|
108
|
+
* by `updateTarget`. The intent is: when wired in, the camera will
|
|
109
|
+
* look at `target.pos + lookAhead` instead of `target.pos`, so a
|
|
110
|
+
* follow-cam stays slightly ahead of its target (e.g. for a
|
|
111
|
+
* cinematic forward-looking shot in AfterBurner). Field is exposed
|
|
112
|
+
* now so user code can set it without waiting for the wiring.
|
|
113
|
+
* @default (0, 0, 1)
|
|
114
|
+
*/
|
|
115
|
+
lookAhead: Vector3d;
|
|
116
|
+
/**
|
|
117
|
+
* @param minX - start x offset
|
|
118
|
+
* @param minY - start y offset
|
|
119
|
+
* @param maxX - end x offset
|
|
120
|
+
* @param maxY - end y offset
|
|
121
|
+
* @param [opts] - perspective parameters (see {@link FrustumOptions})
|
|
122
|
+
*/
|
|
123
|
+
constructor(minX: number, minY: number, maxX: number, maxY: number, opts?: FrustumOptions);
|
|
124
|
+
/**
|
|
125
|
+
* vertical field of view in radians. Setting this rebuilds the
|
|
126
|
+
* projection matrix. Proxies to `frustum.fov`.
|
|
127
|
+
*/
|
|
128
|
+
get fov(): number;
|
|
129
|
+
set fov(value: number);
|
|
130
|
+
/**
|
|
131
|
+
* aspect ratio (width / height). Auto-updated on `resize()`.
|
|
132
|
+
* Setting manually overrides the auto-derived value until the
|
|
133
|
+
* next resize. Proxies to `frustum.aspect`.
|
|
134
|
+
*/
|
|
135
|
+
get aspect(): number;
|
|
136
|
+
set aspect(value: number);
|
|
137
|
+
/**
|
|
138
|
+
* Update the perspective near/far clip distances and rebuild the
|
|
139
|
+
* projection matrix in one shot. Anything closer than `near` or
|
|
140
|
+
* farther than `far` is clipped by the GPU; projection math also
|
|
141
|
+
* degrades sharply just before `far`, so size the far plane to the
|
|
142
|
+
* deepest object in your scene with a little headroom. Defaults are
|
|
143
|
+
* `near = 0.1`, `far = 1000` — typical AfterBurner-class scenes
|
|
144
|
+
* with enemies spawning at z = 3000+ need to push `far` out.
|
|
145
|
+
*
|
|
146
|
+
* **This is the supported way to change near/far at runtime.** The
|
|
147
|
+
* inherited `Camera2d.near` / `.far` are plain instance fields —
|
|
148
|
+
* direct assignment (`camera.near = 5`) updates the cached value
|
|
149
|
+
* but leaves the projection matrix stale until the next
|
|
150
|
+
* `resize()`. TypeScript's property-vs-accessor rule prevents
|
|
151
|
+
* shadowing the inherited fields with accessor pairs, so the
|
|
152
|
+
* convenience method is the public contract instead.
|
|
153
|
+
* @param near - near clip distance
|
|
154
|
+
* @param far - far clip distance
|
|
155
|
+
* @returns this camera (chainable)
|
|
156
|
+
*/
|
|
157
|
+
setClipPlanes(near: number, far: number): this;
|
|
158
|
+
/**
|
|
159
|
+
* Rebuild the projection matrix from the frustum. Called by the
|
|
160
|
+
* base `Camera2d` constructor and by `resize()`. Camera3d's
|
|
161
|
+
* version replaces the ortho matrix with the frustum's perspective.
|
|
162
|
+
* @ignore
|
|
163
|
+
*/
|
|
164
|
+
_updateProjectionMatrix(): void;
|
|
165
|
+
/**
|
|
166
|
+
* Override Camera2d's non-default projection setup so that a Camera3d
|
|
167
|
+
* used in split-screen / picture-in-picture still renders the world
|
|
168
|
+
* with perspective instead of falling back to a 2D ortho. The
|
|
169
|
+
* camera's perspective `projectionMatrix` is mirrored into
|
|
170
|
+
* `worldProjection`; the surrounding `clipRect` set by the base
|
|
171
|
+
* `draw()` handles confining the draw region to the camera's
|
|
172
|
+
* sub-screen rect, and the frustum's `aspect` is already in sync
|
|
173
|
+
* with the camera's width/height. `screenProjection` is left alone
|
|
174
|
+
* because it was already set up correctly in
|
|
175
|
+
* {@link Camera3d#_updateProjectionMatrix}.
|
|
176
|
+
* @ignore
|
|
177
|
+
*/
|
|
178
|
+
_setupNonDefaultProjection(renderer: Renderer): void;
|
|
179
|
+
/**
|
|
180
|
+
* Resize the camera viewport and recompute aspect ratio.
|
|
181
|
+
* @param w - new width
|
|
182
|
+
* @param h - new height
|
|
183
|
+
* @returns this camera
|
|
184
|
+
*/
|
|
185
|
+
resize(w: number, h: number): this;
|
|
186
|
+
/**
|
|
187
|
+
* Apply the camera's full 3D view transform to the world container.
|
|
188
|
+
* Order: rotate first (pitch, yaw), then translate by `-camera.pos`.
|
|
189
|
+
* Post-multiplication semantics give us
|
|
190
|
+
* `currentTransform = R⁻¹ ∘ T(-pos)` — applied to a world point,
|
|
191
|
+
* this subtracts the camera position then rotates by the camera's
|
|
192
|
+
* inverse orientation, which is the standard view transform.
|
|
193
|
+
* @ignore
|
|
194
|
+
*/
|
|
195
|
+
_applyContainerViewTransform(container: Container, translateX: number, translateY: number): void;
|
|
196
|
+
/**
|
|
197
|
+
* Revert {@link Camera3d#_applyContainerViewTransform} in reverse
|
|
198
|
+
* order to restore the container's `currentTransform` to its
|
|
199
|
+
* pre-camera state.
|
|
200
|
+
* @ignore
|
|
201
|
+
*/
|
|
202
|
+
_revertContainerViewTransform(container: Container, translateX: number, translateY: number): void;
|
|
203
|
+
/**
|
|
204
|
+
* Point the camera at a world-space target by deriving pitch and
|
|
205
|
+
* yaw from the direction (target − camera.pos). Roll is unaffected.
|
|
206
|
+
*
|
|
207
|
+
* Three call shapes:
|
|
208
|
+
* - `lookAt(x, y, z)` — raw world coordinates
|
|
209
|
+
* - `lookAt(vector3d)` — a 3D point
|
|
210
|
+
* - `lookAt(renderable)` — uses `renderable.pos` (matches the
|
|
211
|
+
* `Renderable.lookAt(target)` signature so Camera3d is a structural
|
|
212
|
+
* drop-in replacement for Camera2d / Renderable in user code).
|
|
213
|
+
*
|
|
214
|
+
* Last-write-wins with manual `pitch` / `yaw` assignment: if you
|
|
215
|
+
* call `lookAt(...)` then set `camera.pitch = 0.1` directly, the
|
|
216
|
+
* next frame renders with the manual pitch.
|
|
217
|
+
* @param xOrTarget - target world x, or a target with `pos` / `x`,`y`,`z`
|
|
218
|
+
* @param y - target world y (only when first arg is a number)
|
|
219
|
+
* @param z - target world z (only when first arg is a number)
|
|
220
|
+
* @returns this camera
|
|
221
|
+
*/
|
|
222
|
+
lookAt(xOrTarget: number | {
|
|
223
|
+
x: number;
|
|
224
|
+
y: number;
|
|
225
|
+
z?: number;
|
|
226
|
+
pos?: ObservableVector3d;
|
|
227
|
+
}, y?: number, z?: number): this;
|
|
228
|
+
/**
|
|
229
|
+
* Convenience overload of `lookAt` accepting a {@link Vector3d}.
|
|
230
|
+
* @param target - world-space point to look at
|
|
231
|
+
* @returns this camera
|
|
232
|
+
*/
|
|
233
|
+
setLookAt(target: Vector3d): this;
|
|
234
|
+
/**
|
|
235
|
+
* Set the target-local follow offset. Called once when configuring
|
|
236
|
+
* a follow-cam (e.g. behind-and-above third person:
|
|
237
|
+
* `setFollowOffset(0, -2, -8)`).
|
|
238
|
+
* @param x - target-local x offset
|
|
239
|
+
* @param y - target-local y offset
|
|
240
|
+
* @param z - target-local z offset
|
|
241
|
+
* @returns this camera
|
|
242
|
+
*/
|
|
243
|
+
setFollowOffset(x: number, y: number, z: number): this;
|
|
244
|
+
/**
|
|
245
|
+
* Override Camera2d's 2D follow logic to additionally resolve
|
|
246
|
+
* `followOffset` against the target's z. When `target` is set, the
|
|
247
|
+
* camera's world position becomes `target.pos + followOffset`.
|
|
248
|
+
*
|
|
249
|
+
* **Semantic change vs Camera2d.follow:** this override **does not
|
|
250
|
+
* honor `follow_axis`, `deadzone`, or `smoothFollow` / `damping`**.
|
|
251
|
+
* Camera3d tracks its target exactly each frame because the typical
|
|
252
|
+
* 3D use case (behind-the-plane follow-cam, third-person orbit) wants
|
|
253
|
+
* 1:1 tracking with no scroll-deadzone. If you need damped or
|
|
254
|
+
* axis-constrained follow under perspective, set `target = null` and
|
|
255
|
+
* lerp `camera.pos` toward the target manually in your `update()`.
|
|
256
|
+
*
|
|
257
|
+
* **PR B scope:** `followOffset` is treated as **world-space**.
|
|
258
|
+
* Target-rotation-aware follow (where the offset rotates with the
|
|
259
|
+
* target's orientation, Cinemachine / Unreal-style) lands when a
|
|
260
|
+
* showcase (AfterBurner's banking jet) demands it.
|
|
261
|
+
* @param dt - delta time in milliseconds (ignored — no damping)
|
|
262
|
+
* @ignore
|
|
263
|
+
*/
|
|
264
|
+
updateTarget(dt?: number): void;
|
|
265
|
+
/**
|
|
266
|
+
* Visibility check used by `Container.update` (in turn driving
|
|
267
|
+
* `Container.draw`) to skip rendering off-screen children.
|
|
268
|
+
*
|
|
269
|
+
* Camera2d's implementation tests a 2D bounds-rectangle overlap
|
|
270
|
+
* against `this.worldView` — that test is invalid under perspective:
|
|
271
|
+
* the visible region is a frustum that widens with distance and
|
|
272
|
+
* rotates with the camera's pitch / yaw, not a fixed axis-aligned
|
|
273
|
+
* rect at the camera's x / y. Camera3d substitutes plane-based
|
|
274
|
+
* frustum culling — each non-floating renderable's bounding sphere
|
|
275
|
+
* is tested against the six frustum planes that were extracted in
|
|
276
|
+
* the most recent `update()` call. Floating elements (HUD / UI)
|
|
277
|
+
* still use Camera2d's 2D rect test because their bounds are
|
|
278
|
+
* screen-space and the perspective transform doesn't apply to them.
|
|
279
|
+
* @param obj - the renderable to test
|
|
280
|
+
* @param [floating] - test against screen coordinates instead of frustum
|
|
281
|
+
* @returns true if the renderable's bounds overlap the frustum
|
|
282
|
+
*/
|
|
283
|
+
isVisible(obj: Renderable, floating?: boolean): boolean;
|
|
284
|
+
/**
|
|
285
|
+
* Bulk frustum cull via the world's {@link Octree}. Returns every
|
|
286
|
+
* renderable whose octant the current frustum overlaps —
|
|
287
|
+
* conservative (some renderables may still narrow-cull out
|
|
288
|
+
* via {@link Camera3d#isVisible}'s per-sphere test) but
|
|
289
|
+
* O(visible + walk) instead of O(scene).
|
|
290
|
+
*
|
|
291
|
+
* Only applicable under `cameraClass: Camera3d` (or any setup
|
|
292
|
+
* where `world.sortOn === "depth"` and the broadphase is an
|
|
293
|
+
* Octree). Returns an empty array under a 2D broadphase — call
|
|
294
|
+
* sites can guard on the array length or branch on
|
|
295
|
+
* `world.sortOn`.
|
|
296
|
+
*
|
|
297
|
+
* For a 1000-renderable scene with ~50 visible, expect a 5-20×
|
|
298
|
+
* speedup over walking every renderable and per-item
|
|
299
|
+
* {@link Camera3d#isVisible}.
|
|
300
|
+
* @param world - the world to cull (its broadphase must be an Octree); typed structurally to sidestep the Camera3d → World import cycle
|
|
301
|
+
* @param world.broadphase - the world's spatial broadphase
|
|
302
|
+
* @param world.sortOn - guard: returns empty unless this equals `"depth"`
|
|
303
|
+
* @param [out] - caller-supplied result array (re-entrancy-safe)
|
|
304
|
+
* @returns visible-renderable candidates
|
|
305
|
+
* @example
|
|
306
|
+
* const visible = camera.queryVisible(app.world);
|
|
307
|
+
* for (const r of visible) {
|
|
308
|
+
* // narrow-phase per-renderable visibility (sphere / OBB) if needed
|
|
309
|
+
* if (camera.isVisible(r)) r.draw(renderer);
|
|
310
|
+
* }
|
|
311
|
+
*/
|
|
312
|
+
queryVisible(world: {
|
|
313
|
+
broadphase: unknown;
|
|
314
|
+
sortOn: string;
|
|
315
|
+
}, out?: Renderable[]): Renderable[];
|
|
316
|
+
/**
|
|
317
|
+
* Per-frame update — extends Camera2d's behavior (target follow,
|
|
318
|
+
* camera effects) with rebuilding the frustum's six bounding
|
|
319
|
+
* planes so {@link Camera3d#isVisible} returns accurate results
|
|
320
|
+
* for the current camera state.
|
|
321
|
+
* @param dt - delta time in milliseconds
|
|
322
|
+
* @returns true if the camera's state changed
|
|
323
|
+
* @ignore
|
|
324
|
+
*/
|
|
325
|
+
update(dt?: number): boolean;
|
|
326
|
+
/**
|
|
327
|
+
* Recompute the frustum's six bounding planes from the current
|
|
328
|
+
* `projectionMatrix × viewMatrix` (the world → clip matrix).
|
|
329
|
+
* Called from {@link Camera3d#update} each frame; `isVisible`
|
|
330
|
+
* then tests against the cached planes.
|
|
331
|
+
* @ignore
|
|
332
|
+
*/
|
|
333
|
+
_rebuildFrustumPlanes(): void;
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=camera3d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera3d.d.ts","sourceRoot":"","sources":["../../src/camera/camera3d.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,KAAK,SAAS,MAAM,8BAA8B,CAAC;AAC1D,OAAO,KAAK,UAAU,MAAM,+BAA+B,CAAC;AAC5D,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,OAAO,EAAE,EAAE,KAAK,cAAc,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* A plane in 3D space, expressed as `Ax + By + Cz + D = 0`.
|
|
4
|
+
* `normal` is `(A, B, C)`; `constant` is `D`. Used by {@link Frustum}
|
|
5
|
+
* to represent the six bounding planes for culling.
|
|
6
|
+
* @category Camera
|
|
7
|
+
*/
|
|
8
|
+
export interface Plane {
|
|
9
|
+
/** plane normal (A, B, C in the plane equation) — not necessarily unit-length */
|
|
10
|
+
nx: number;
|
|
11
|
+
ny: number;
|
|
12
|
+
nz: number;
|
|
13
|
+
/** plane constant (D in the plane equation) */
|
|
14
|
+
d: number;
|
|
15
|
+
}
|
|
16
|
+
export interface FrustumOptions {
|
|
17
|
+
/** vertical field of view in radians (default: π / 3 = 60°) */
|
|
18
|
+
fov?: number;
|
|
19
|
+
/** aspect ratio (width / height) — default 1.0 (square) */
|
|
20
|
+
aspect?: number;
|
|
21
|
+
/** distance to the near clipping plane (default 0.1) */
|
|
22
|
+
near?: number;
|
|
23
|
+
/** distance to the far clipping plane (default 1000) */
|
|
24
|
+
far?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A view frustum — the truncated pyramid that defines a perspective
|
|
28
|
+
* camera's visible volume. Holds the four projection parameters
|
|
29
|
+
* (`fov`, `aspect`, `near`, `far`) and the matching projection matrix.
|
|
30
|
+
*
|
|
31
|
+
* Used by {@link Camera3d} as its source of truth for perspective
|
|
32
|
+
* projection. The matrix follows melonJS conventions: Y-down (sprite
|
|
33
|
+
* at higher `y` appears lower on screen, matching Camera2d) and +Z
|
|
34
|
+
* forward (sprite at higher `pos.z` is farther from the camera and
|
|
35
|
+
* renders smaller). This differs from the OpenGL default of Y-up and
|
|
36
|
+
* -Z forward, but matches the rest of the engine and lets Camera2d
|
|
37
|
+
* code translate directly to Camera3d.
|
|
38
|
+
*
|
|
39
|
+
* Plane-based frustum culling is available via {@link Frustum#planes}
|
|
40
|
+
* (rebuilt by {@link Frustum#setFromViewProjection} per frame) plus
|
|
41
|
+
* {@link Frustum#containsPoint} / {@link Frustum#intersectsSphere} for
|
|
42
|
+
* culling tests. `Camera3d.update` calls `setFromViewProjection` once
|
|
43
|
+
* per frame so its `isVisible(obj)` queries against current planes —
|
|
44
|
+
* no per-frame setup needed from user code.
|
|
45
|
+
* @category Camera
|
|
46
|
+
* @example
|
|
47
|
+
* const frustum = new Frustum({ fov: Math.PI / 3, aspect: 16 / 9 });
|
|
48
|
+
* frustum.near = 0.5;
|
|
49
|
+
* frustum.update();
|
|
50
|
+
* renderer.setProjection(frustum.projectionMatrix);
|
|
51
|
+
*/
|
|
52
|
+
export default class Frustum {
|
|
53
|
+
/**
|
|
54
|
+
* vertical field of view in radians.
|
|
55
|
+
* Mutating this field requires calling {@link Frustum#update} to
|
|
56
|
+
* rebuild the projection matrix — or use {@link Frustum#set} to
|
|
57
|
+
* change multiple parameters and update in one call.
|
|
58
|
+
*/
|
|
59
|
+
fov: number;
|
|
60
|
+
/**
|
|
61
|
+
* aspect ratio (width / height). Camera3d sets this automatically
|
|
62
|
+
* from its viewport on resize.
|
|
63
|
+
*/
|
|
64
|
+
aspect: number;
|
|
65
|
+
/**
|
|
66
|
+
* distance to the near clipping plane (positive — measured along
|
|
67
|
+
* +Z, the camera's forward direction).
|
|
68
|
+
*/
|
|
69
|
+
near: number;
|
|
70
|
+
/**
|
|
71
|
+
* distance to the far clipping plane.
|
|
72
|
+
*/
|
|
73
|
+
far: number;
|
|
74
|
+
/**
|
|
75
|
+
* the perspective projection matrix derived from `fov`, `aspect`,
|
|
76
|
+
* `near` and `far`. Rebuilt by {@link Frustum#update}.
|
|
77
|
+
*/
|
|
78
|
+
projectionMatrix: Matrix3d;
|
|
79
|
+
/**
|
|
80
|
+
* The six bounding planes of this frustum in world space, in order:
|
|
81
|
+
* left, right, bottom, top, near, far. Each plane is oriented so
|
|
82
|
+
* its `(nx, ny, nz)` normal points **inward** — a point with
|
|
83
|
+
* positive signed distance to a plane is on the visible side.
|
|
84
|
+
*
|
|
85
|
+
* Populated by {@link Frustum#setFromViewProjection}. Callers that
|
|
86
|
+
* use {@link Frustum#intersectsSphere} or {@link Frustum#containsPoint}
|
|
87
|
+
* must first call `setFromViewProjection` each frame the camera
|
|
88
|
+
* moves; otherwise the planes describe a stale frustum.
|
|
89
|
+
*/
|
|
90
|
+
planes: Plane[];
|
|
91
|
+
/**
|
|
92
|
+
* @param [opts] - initial parameters; any omitted field uses the
|
|
93
|
+
* class default
|
|
94
|
+
*/
|
|
95
|
+
constructor(opts?: FrustumOptions);
|
|
96
|
+
/**
|
|
97
|
+
* Atomically set all four parameters and rebuild the projection
|
|
98
|
+
* matrix in one call.
|
|
99
|
+
* @param fov - vertical field of view in radians
|
|
100
|
+
* @param aspect - aspect ratio (width / height)
|
|
101
|
+
* @param near - distance to the near clipping plane
|
|
102
|
+
* @param far - distance to the far clipping plane
|
|
103
|
+
* @returns this Frustum for chaining
|
|
104
|
+
*/
|
|
105
|
+
set(fov: number, aspect: number, near: number, far: number): this;
|
|
106
|
+
/**
|
|
107
|
+
* Rebuild {@link Frustum#projectionMatrix} from the current
|
|
108
|
+
* parameter values. Call this after mutating any of `fov`,
|
|
109
|
+
* `aspect`, `near`, `far` individually.
|
|
110
|
+
*
|
|
111
|
+
* The matrix is the standard OpenGL perspective post-multiplied by
|
|
112
|
+
* `scale(1, -1, -1)` so that:
|
|
113
|
+
* - Y-down matches melonJS screen + Camera2d conventions
|
|
114
|
+
* - +Z is forward (positive `pos.z` = farther from camera)
|
|
115
|
+
*/
|
|
116
|
+
update(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Rebuild the six bounding {@link Frustum#planes} from the world →
|
|
119
|
+
* clip matrix. Standard Gribb–Hartmann extraction: each plane is
|
|
120
|
+
* one of the six combinations of the matrix's row 3 (the "w" row)
|
|
121
|
+
* ± rows 0, 1, 2.
|
|
122
|
+
*
|
|
123
|
+
* Call this once per frame after the camera has moved (typically
|
|
124
|
+
* from `Camera3d.update`); the planes are then valid in world
|
|
125
|
+
* space for that frame and can be tested against world-space
|
|
126
|
+
* bounds via {@link Frustum#intersectsSphere} /
|
|
127
|
+
* {@link Frustum#containsPoint}.
|
|
128
|
+
*
|
|
129
|
+
* **Pass `projectionMatrix × viewMatrix`** — column-major /
|
|
130
|
+
* gl-matrix convention: a world-space point becomes a clip-space
|
|
131
|
+
* point via `clip = projection × view × world`, so the combined
|
|
132
|
+
* matrix is `projection × view`. The parameter name says
|
|
133
|
+
* `viewProjection` for that reason — it's the matrix uploaded to
|
|
134
|
+
* `uProjectionMatrix` in the vertex shader (after Camera3d bakes
|
|
135
|
+
* the per-frame world translate into the view via
|
|
136
|
+
* `container.translate`).
|
|
137
|
+
* @param viewProjection - the `projectionMatrix × viewMatrix` matrix
|
|
138
|
+
*/
|
|
139
|
+
setFromViewProjection(viewProjection: Matrix3d): void;
|
|
140
|
+
/**
|
|
141
|
+
* Test whether a world-space sphere overlaps this frustum.
|
|
142
|
+
* Conservative — a sphere that touches even one plane's positive
|
|
143
|
+
* side is reported visible. Always run {@link Frustum#setFromViewProjection}
|
|
144
|
+
* first so the planes describe the current camera view.
|
|
145
|
+
* @param x - sphere center x in world coords
|
|
146
|
+
* @param y - sphere center y in world coords
|
|
147
|
+
* @param z - sphere center z in world coords
|
|
148
|
+
* @param radius - sphere radius in world units
|
|
149
|
+
* @returns true if the sphere is at least partially inside the frustum
|
|
150
|
+
*/
|
|
151
|
+
intersectsSphere(x: number, y: number, z: number, radius: number): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Test whether a world-space point is inside this frustum.
|
|
154
|
+
* Always run {@link Frustum#setFromViewProjection} first.
|
|
155
|
+
* @param x - world x
|
|
156
|
+
* @param y - world y
|
|
157
|
+
* @param z - world z
|
|
158
|
+
* @returns true if the point is inside (on the positive side of every plane)
|
|
159
|
+
*/
|
|
160
|
+
containsPoint(x: number, y: number, z: number): boolean;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=frustum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frustum.d.ts","source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gB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAc1E;;;;;;;OAOG;IACH,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;CASvD"}
|
package/build/const.d.ts
CHANGED
|
@@ -1,13 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Select the HTML5 Canvas renderer. Lower performance and no shader /
|
|
3
|
+
* mesh / Camera3d support, but supported on every browser including
|
|
4
|
+
* environments where WebGL is unavailable (some embedded webviews,
|
|
5
|
+
* stripped-down kiosk browsers, GPU blocklisted by driver policy).
|
|
6
|
+
*
|
|
7
|
+
* Use when the example / game uses only 2D sprites + primitives and you
|
|
8
|
+
* want the broadest possible reach. Anything depending on `ShaderEffect`,
|
|
9
|
+
* `Mesh`, `Camera3d`, GPU TMX tile rendering or `Light2d` will silently
|
|
10
|
+
* not work — those subsystems are WebGL-only.
|
|
3
11
|
*/
|
|
4
12
|
export declare const CANVAS = 0;
|
|
5
13
|
/**
|
|
6
|
-
*
|
|
14
|
+
* Require the WebGL renderer. **Throws at `new Application(...)` time
|
|
15
|
+
* if WebGL is unavailable** (driver-blocklisted GPU, software fallback
|
|
16
|
+
* failing the `failIfMajorPerformanceCaveat` check, no `WebGLRenderingContext`
|
|
17
|
+
* in the environment, etc.) — does NOT silently fall back to Canvas.
|
|
18
|
+
*
|
|
19
|
+
* Use this when your scene needs WebGL (Camera3d, Mesh, ShaderEffect,
|
|
20
|
+
* Light2d, GPU tilemap) and you'd rather fail fast with a clear error
|
|
21
|
+
* than have the engine render a stuck blank canvas.
|
|
22
|
+
*
|
|
23
|
+
* If Canvas fallback is acceptable when WebGL isn't there, use
|
|
24
|
+
* {@link AUTO} instead.
|
|
7
25
|
*/
|
|
8
26
|
export declare const WEBGL = 1;
|
|
9
27
|
/**
|
|
10
|
-
*
|
|
28
|
+
* Auto-select the renderer: prefer WebGL when available, silently fall
|
|
29
|
+
* back to Canvas otherwise. Application construction always succeeds.
|
|
30
|
+
*
|
|
31
|
+
* Use this when your scene works under both renderers (2D sprites,
|
|
32
|
+
* primitives, basic tile maps) and you want the engine to pick the
|
|
33
|
+
* best available backend. Note: subsystems that require WebGL
|
|
34
|
+
* (Camera3d, Mesh, ShaderEffect, Light2d, GPU tilemap) will silently
|
|
35
|
+
* stop working under the Canvas fallback path — if your scene depends
|
|
36
|
+
* on any of those, use {@link WEBGL} so the failure surfaces at
|
|
37
|
+
* construction time instead of as a black canvas at runtime.
|
|
11
38
|
*/
|
|
12
39
|
export declare const AUTO = 2;
|
|
13
40
|
export type RendererType = typeof CANVAS | typeof WEBGL | typeof AUTO;
|
package/build/const.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,MAAM,IAAI,CAAC;AAExB;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,KAAK,IAAI,CAAC;AAEvB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,IAAI,IAAI,CAAC;AAEtB,MAAM,MAAM,YAAY,GAAG,OAAO,MAAM,GAAG,OAAO,KAAK,GAAG,OAAO,IAAI,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Vector3d } from "../math/vector3d.ts";
|
|
2
|
+
import { AABB3d } from "../physics/broadphase/aabb3d.ts";
|
|
3
|
+
/**
|
|
4
|
+
* A 3D sphere — `{ centre, radius }`. Sibling of {@link Ellipse} in
|
|
5
|
+
* the geometry surface; used by {@link Octree} / `adapter.querySphere`
|
|
6
|
+
* as the canonical 3D region-query shape, and by user code for any
|
|
7
|
+
* sphere-vs-sphere / sphere-vs-AABB collision check under
|
|
8
|
+
* {@link Camera3d}.
|
|
9
|
+
*
|
|
10
|
+
* Not currently part of the {@link BodyShape} union — `Body` is 2D-
|
|
11
|
+
* only in melonJS today; Sphere is a math/geometry primitive that
|
|
12
|
+
* would slot in once a 3D physics adapter ships.
|
|
13
|
+
* @category Geometry
|
|
14
|
+
* @example
|
|
15
|
+
* import { Sphere } from "melonjs";
|
|
16
|
+
*
|
|
17
|
+
* const a = new Sphere(0, 0, 0, 10);
|
|
18
|
+
* const b = new Sphere(15, 0, 0, 10);
|
|
19
|
+
* a.overlaps(b); // true — surfaces touch at x = 5
|
|
20
|
+
*/
|
|
21
|
+
export declare class Sphere {
|
|
22
|
+
/** Centre coordinates of the sphere (Y-down, +Z forward — Camera3d convention). */
|
|
23
|
+
pos: Vector3d;
|
|
24
|
+
/** Sphere radius. Negative values are treated like their absolute value in {@link Sphere.overlaps} / {@link Sphere.contains}. */
|
|
25
|
+
radius: number;
|
|
26
|
+
/**
|
|
27
|
+
* Cached AABB for this sphere. Allocated lazily on the first
|
|
28
|
+
* {@link Sphere.getBounds} call so a sphere used only for inline
|
|
29
|
+
* `overlaps` checks doesn't pay for the AABB.
|
|
30
|
+
* @ignore
|
|
31
|
+
*/
|
|
32
|
+
_bounds?: AABB3d;
|
|
33
|
+
/**
|
|
34
|
+
* @param x - centre x
|
|
35
|
+
* @param y - centre y
|
|
36
|
+
* @param z - centre z
|
|
37
|
+
* @param radius - sphere radius
|
|
38
|
+
*/
|
|
39
|
+
constructor(x: number, y: number, z: number, radius: number);
|
|
40
|
+
/**
|
|
41
|
+
* Re-position and resize the sphere in one shot. Mirrors
|
|
42
|
+
* {@link Ellipse.setShape}.
|
|
43
|
+
* @param x - centre x
|
|
44
|
+
* @param y - centre y
|
|
45
|
+
* @param z - centre z
|
|
46
|
+
* @param radius - sphere radius
|
|
47
|
+
* @returns this sphere for chaining
|
|
48
|
+
*/
|
|
49
|
+
setShape(x: number, y: number, z: number, radius: number): this;
|
|
50
|
+
/**
|
|
51
|
+
* Test whether a point lies inside the sphere (boundary inclusive).
|
|
52
|
+
* Squared-distance test — no `sqrt` on the hot path. Matches the
|
|
53
|
+
* boundary convention of {@link AABB3d.contains}.
|
|
54
|
+
* @param x - point x
|
|
55
|
+
* @param y - point y
|
|
56
|
+
* @param z - point z
|
|
57
|
+
*/
|
|
58
|
+
contains(x: number, y: number, z: number): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Vector form of {@link Sphere.contains}.
|
|
61
|
+
* @param v - point
|
|
62
|
+
*/
|
|
63
|
+
contains(v: Vector3d): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Test whether this sphere overlaps another. Boundary inclusive
|
|
66
|
+
* (touching surfaces count as overlap), matching
|
|
67
|
+
* {@link AABB3d.overlaps}.
|
|
68
|
+
* @param other - the other sphere
|
|
69
|
+
*/
|
|
70
|
+
overlaps(other: Sphere): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Test whether this sphere overlaps an axis-aligned box. Delegates
|
|
73
|
+
* to {@link AABB3d.overlapsSphere} so the two shapes agree on
|
|
74
|
+
* boundary semantics.
|
|
75
|
+
* @param aabb - the box
|
|
76
|
+
*/
|
|
77
|
+
overlapsAABB(aabb: AABB3d): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Smallest {@link AABB3d} containing this sphere. Cached — repeat
|
|
80
|
+
* calls without a `setShape` between return the same instance and
|
|
81
|
+
* the same values.
|
|
82
|
+
*/
|
|
83
|
+
getBounds(): AABB3d;
|
|
84
|
+
/** @ignore */
|
|
85
|
+
_updateBounds(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Reset the sphere to a zero-radius point at the origin.
|
|
88
|
+
*/
|
|
89
|
+
clear(): this;
|
|
90
|
+
/**
|
|
91
|
+
* Deep copy of this sphere. The clone shares NOTHING with the
|
|
92
|
+
* original — independent `pos` Vector3d, independent AABB cache.
|
|
93
|
+
* Pulls from {@link spherePool} so back-to-back clones are
|
|
94
|
+
* allocation-free.
|
|
95
|
+
*/
|
|
96
|
+
clone(): Sphere;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A pool of {@link Sphere} instances. Mirrors {@link ellipsePool} —
|
|
100
|
+
* `spherePool.get(x, y, z, r)` recycles an existing instance via
|
|
101
|
+
* `setShape` before allocating a new one; release via the
|
|
102
|
+
* matching `.release()` (the `createPool` contract).
|
|
103
|
+
*/
|
|
104
|
+
export declare const spherePool: import("../system/pool.ts").Pool<Sphere, [x: number, y: number, z: number, radius: number]>;
|
|
105
|
+
//# sourceMappingURL=sphere.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sphere.d.ts","sourceRoot":"","sources":["../../src/geometries/sphere.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAGzD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,MAAM;IAClB,mFAAmF;IACnF,GAAG,EAAE,QAAQ,CAAC;IAEd,iIAAiI;IACjI,MAAM,EAAE,MAAM,CAAC;IAEf;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;gBACS,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK3D;;;;;;;;OAQG;IACH,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAUxD;;;;;;;OAOG;IACH,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;IAClD;;;OAGG;IACH,QAAQ,CAAC,CAAC,EAAE,QAAQ,GAAG,OAAO;IAsB9B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAahC;;;;;OAKG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAInC;;;;OAIG;IACH,SAAS,IAAI,MAAM;IAQnB,cAAc;IACd,aAAa;IAYb;;OAEG;IACH,KAAK;IASL;;;;;OAKG;IACH,KAAK;CAGL;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,6FAWrB,CAAC"}
|