@solidrt/2d 0.0.55 → 0.0.57
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/AGENTS.md +417 -70
- package/README.md +3 -3
- package/examples/README.md +49 -7
- package/examples/anim.tsx +84 -0
- package/examples/camera-probe.tsx +202 -0
- package/examples/camera.tsx +196 -0
- package/examples/parity.tsx +15 -13
- package/examples/pick.tsx +89 -36
- package/examples/split-screen.tsx +111 -0
- package/examples/springs.tsx +6 -9
- package/examples/sprites.tsx +9 -12
- package/examples/tiles.tsx +42 -18
- package/examples/views.tsx +177 -0
- package/package.json +3 -3
- package/src/animation.ts +178 -0
- package/src/atlas.ts +35 -33
- package/src/camera.ts +111 -0
- package/src/camera2d.ts +713 -0
- package/src/components/auto-oversample.ts +27 -0
- package/src/components/camera2d.tsx +82 -0
- package/src/components/context.ts +48 -0
- package/src/components/group.tsx +68 -0
- package/src/components/index.ts +28 -0
- package/src/components/sprite-layer.tsx +312 -0
- package/src/components/sprite.tsx +72 -0
- package/src/components/tile-layer.tsx +160 -0
- package/src/components/view2d.tsx +151 -0
- package/src/dispatch.ts +231 -0
- package/src/frames.ts +63 -14
- package/src/index.ts +53 -12
- package/src/input.ts +50 -0
- package/src/layer.ts +716 -309
- package/src/oversample-math.ts +73 -0
- package/src/oversample.ts +39 -11
- package/src/records.ts +109 -109
- package/src/shaders.ts +93 -14
- package/src/tiles.ts +256 -48
- package/src/views.ts +294 -0
- package/src/components.tsx +0 -357
package/src/index.ts
CHANGED
|
@@ -1,29 +1,70 @@
|
|
|
1
1
|
// @solidrt/2d - an instanced sprite layer above @solidrt/core/gpu.
|
|
2
|
-
// One atlas, N quads in one draw
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
2
|
+
// One atlas, N quads in one draw per VIEW: a layer holds the sprites and
|
|
3
|
+
// shows only through its views (layer.createView / <View2d>, each a target
|
|
4
|
+
// with a camera of its own - a Unity scene renders only through Cameras,
|
|
5
|
+
// a Godot World2D only through Viewports). The live layer
|
|
6
|
+
// (createSpriteLayer/addSprite) backs every sprite with a SPATIAL ARENA
|
|
7
|
+
// node whose Pose2D record sink writes the pose instance buffer at the
|
|
8
|
+
// core flush, so core producers reach sprites and picking walks the core
|
|
9
|
+
// BVH; style stays a JS-written second instance buffer. The records layer (createRecordLayer)
|
|
7
10
|
// is the raw escape hatch for motion only JS can compute: 13 JS-owned
|
|
8
11
|
// floats per sprite published through the zero-copy write lease. The baked
|
|
9
12
|
// tile layer (createTileLayer/TileLayer) is the static sibling: a tile
|
|
10
13
|
// world rendered once into textures and composited as a few quads,
|
|
11
14
|
// re-baked on change. Two faces throughout: the imperative core (usable
|
|
12
15
|
// without Solid components) and the components (SpriteLayer/Sprite/Group/
|
|
13
|
-
// TileLayer) on top. See AGENTS.md for the model and the traps.
|
|
16
|
+
// View2d/TileLayer) on top. See AGENTS.md for the model and the traps.
|
|
14
17
|
|
|
15
|
-
export { addGroup, addSprite, createSpriteLayer, getSprite, removeGroup, removeSprite, setGroup, setGroupTransition, setSprite, setSpriteParent, setSpriteTransition, POSE_FLOATS, STYLE_FLOATS } from "./layer.ts"
|
|
18
|
+
export { addGroup, addSprite, createSpriteLayer, getSprite, removeGroup, removeSprite, setGroup, setGroupTransition, setSprite, setSpriteParent, setSpriteTransition, worldPosition, POSE_FLOATS, STYLE_FLOATS } from "./layer.ts"
|
|
16
19
|
export { createRecordLayer, FLOATS_PER_SPRITE } from "./records.ts"
|
|
17
|
-
export type { RecordLayer as RecordLayerHandle } from "./records.ts"
|
|
20
|
+
export type { RecordLayer as RecordLayerHandle, RecordLayerOptions } from "./records.ts"
|
|
18
21
|
export { pointInSprite } from "./pick.ts"
|
|
19
|
-
export
|
|
22
|
+
export { projectCamera, unprojectCamera } from "./camera.ts"
|
|
23
|
+
export type { CameraState, CameraUpdate } from "./camera.ts"
|
|
24
|
+
export { createCamera2d } from "./camera2d.ts"
|
|
25
|
+
export type { Camera2d as Camera2dHandle, Camera2dAxes, Camera2dOptions, Camera2dPose, Camera2dTarget, Rect2d } from "./camera2d.ts"
|
|
26
|
+
export { camera2dActions, camera2dBindings } from "./input.ts"
|
|
27
|
+
export type { CameraDevices } from "./input.ts"
|
|
28
|
+
export type {
|
|
29
|
+
AddSpriteOptions,
|
|
30
|
+
Capsule,
|
|
31
|
+
Circle,
|
|
32
|
+
GroupOptions,
|
|
33
|
+
Impact,
|
|
34
|
+
MoveOptions,
|
|
35
|
+
MoveResult,
|
|
36
|
+
Overlap,
|
|
37
|
+
QueryOptions,
|
|
38
|
+
RayHit,
|
|
39
|
+
Rect,
|
|
40
|
+
LayerPointerEvent,
|
|
41
|
+
LayerPointerListener,
|
|
42
|
+
LayerTapEvent,
|
|
43
|
+
LayerWheelEvent,
|
|
44
|
+
Sprite as SpriteHandle,
|
|
45
|
+
SpriteGroup,
|
|
46
|
+
SpriteHandlers,
|
|
47
|
+
SpriteLayer as SpriteLayerHandle,
|
|
48
|
+
SpriteLayerOptions,
|
|
49
|
+
SpriteOptions,
|
|
50
|
+
SpritePointerEvent,
|
|
51
|
+
SpriteTapEvent,
|
|
52
|
+
SpriteWheelEvent,
|
|
53
|
+
TransitionEndEvent,
|
|
54
|
+
Volume,
|
|
55
|
+
} from "./layer.ts"
|
|
56
|
+
export { feedPointer } from "./views.ts"
|
|
57
|
+
export type { ViewHandle, ViewOptions } from "./views.ts"
|
|
20
58
|
export { createTileLayer } from "./tiles.ts"
|
|
21
59
|
export type { TileChunk, TileLayer as TileLayerHandle, TileLayerOptions } from "./tiles.ts"
|
|
22
60
|
|
|
23
61
|
export type { NodeTransition, NodeTransitionSpec } from "flux:spatial"
|
|
24
62
|
export { grid, namedFrames, FULL_FRAME } from "./frames.ts"
|
|
25
|
-
export type { Frame, GridOptions } from "./frames.ts"
|
|
63
|
+
export type { AtlasSize, Frame, GridOptions, NamedFramesOptions } from "./frames.ts"
|
|
64
|
+
export { createAnimation } from "./animation.ts"
|
|
65
|
+
export type { AnimationOptions, SpriteAnimation } from "./animation.ts"
|
|
66
|
+
export { fitOversample } from "./oversample.ts"
|
|
26
67
|
export { createAtlas } from "./atlas.ts"
|
|
27
68
|
export type { Atlas, AtlasOptions } from "./atlas.ts"
|
|
28
|
-
export { Group, Sprite, SpriteLayer, TileLayer, useSpriteLayer } from "./components.
|
|
29
|
-
export type { GroupProps, SpriteLayerProps, SpritePointerProps, SpriteProps, TileCamera, TileLayerProps } from "./components.
|
|
69
|
+
export { Camera2d, Group, Sprite, SpriteLayer, TileLayer, View2d, useSpriteLayer } from "./components/index.ts"
|
|
70
|
+
export type { Camera2dProps, GroupProps, LayerPointerProps, SpriteLayerProps, SpritePointerProps, SpriteProps, TileCamera, TileLayerProps, View2dProps } from "./components/index.ts"
|
package/src/input.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// The standard input wiring for the 2d camera: the action declarations it
|
|
2
|
+
// consumes (its axes, by the shared vocabulary) and a preset that binds
|
|
3
|
+
// the devices an app hands in - plain data the app could write by hand,
|
|
4
|
+
// applied with `input.bind(camera2dBindings({ pointer, gamepad }))` and
|
|
5
|
+
// adjusted afterwards with unbind; nothing binds unless the app says so
|
|
6
|
+
// (ARCHITECTURE.md). `pointer` is the feed of the view showing the layer
|
|
7
|
+
// (`createPointerFeed()`, handed to `<SpriteLayer pointer>` or
|
|
8
|
+
// `<View2d pointer>`, or bridged with feedPointer for an imperative view),
|
|
9
|
+
// `gamepad` a core gamepad device, `keyboard` the core keyboard device.
|
|
10
|
+
//
|
|
11
|
+
// Keys and sticks move the CAMERA where a drag moves the content (the
|
|
12
|
+
// arrow right scrolls the view right, as every map does), so those
|
|
13
|
+
// bindings go through invert() and `pan` keeps its one meaning.
|
|
14
|
+
|
|
15
|
+
import { invert } from "@solidrt/core/input"
|
|
16
|
+
import type { Binding, GamepadDevice, KeyboardDevice, PointerFeed } from "@solidrt/core"
|
|
17
|
+
|
|
18
|
+
export type CameraDevices = {
|
|
19
|
+
pointer?: PointerFeed
|
|
20
|
+
gamepad?: GamepadDevice
|
|
21
|
+
keyboard?: KeyboardDevice
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The 2d camera's actions: `pan`, `zoom`, `roll`. */
|
|
25
|
+
export let camera2dActions = { pan: "vec2", zoom: "axis", roll: "axis" } as const
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The 2d camera's standard bindings: one finger or a mouse drag pans and
|
|
29
|
+
* so do two fingers, a pinch and the wheel zoom about the pointer, a twist
|
|
30
|
+
* rolls; the left stick scrolls, the triggers zoom, the right stick's x
|
|
31
|
+
* rolls; the arrow keys scroll and minus/equals zoom.
|
|
32
|
+
*/
|
|
33
|
+
export function camera2dBindings(devices: CameraDevices): Binding[] {
|
|
34
|
+
let out: Binding[] = []
|
|
35
|
+
let { pointer, gamepad, keyboard } = devices
|
|
36
|
+
if (pointer) {
|
|
37
|
+
out.push(
|
|
38
|
+
{ action: "pan", source: pointer.drag },
|
|
39
|
+
{ action: "pan", source: pointer.pan },
|
|
40
|
+
{ action: "zoom", source: pointer.pinch },
|
|
41
|
+
{ action: "zoom", source: pointer.wheel },
|
|
42
|
+
{ action: "roll", source: pointer.twist },
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
if (gamepad) {
|
|
46
|
+
out.push({ action: "pan", source: invert(gamepad.leftStick) }, { action: "zoom", source: gamepad.triggers }, { action: "roll", source: invert(gamepad.axis("rightX")) })
|
|
47
|
+
}
|
|
48
|
+
if (keyboard) out.push({ action: "pan", source: invert(keyboard.arrows) }, { action: "zoom", source: keyboard.axis("Minus", "Equal") })
|
|
49
|
+
return out
|
|
50
|
+
}
|