@solidrt/2d 0.0.67 → 0.0.68

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/src/views.ts CHANGED
@@ -25,6 +25,7 @@ import { spriteDispatch } from "./dispatch.ts"
25
25
  import type { PointerFeed } from "@solidrt/core"
26
26
  import type { LayerPointerListener, Sprite, LayerHandlers } from "./layer.ts"
27
27
  import { checkOversample, thrashSentinel } from "./oversample.ts"
28
+ import { atlasBindings } from "./shaders.ts"
28
29
 
29
30
  export type ViewOptions = {
30
31
  /** View pixels: the viewport its camera maps the world onto. */
@@ -52,9 +53,9 @@ export type ViewHandle = {
52
53
  /** Element handlers wiring the view's pointer events (sprites, groups
53
54
  * and the root listeners); see handlersFor. */
54
55
  handlers: LayerHandlers
55
- /** View pixels, as created or last set by setSize. */
56
- readonly width: number
57
- readonly height: number
56
+ /** View pixels, as created or last set by setSize (a fresh object per
57
+ * call) - @solidrt/3d's view.size(), what a camera control reads. */
58
+ size(): { width: number; height: number }
58
59
  setSize(width: number, height: number): void
59
60
  /**
60
61
  * Listen at the root of the event walk. Every down, move, up, wheel and
@@ -89,6 +90,10 @@ export type ViewHandle = {
89
90
  /** View pixels -> world (layer) pixels, the inverse: what pointer
90
91
  * dispatch applies to every event. */
91
92
  unproject(x: number, y: number): [number, number]
93
+ /** The layer's pick through this view: the view pixel unprojected, the
94
+ * sprites' screen-size floors measured at this camera's zoom - what
95
+ * the pointer walk hits. */
96
+ pick(x: number, y: number): Sprite[]
92
97
  /**
93
98
  * handlers for a leaf whose LAYOUT size differs from the view size
94
99
  * (events scale by view/layout; a leaf laid out AT view size just uses
@@ -100,13 +105,15 @@ export type ViewHandle = {
100
105
  }
101
106
 
102
107
  // What a layer hands its views: the pipeline and quad every entry draws
103
- // with, the atlas, the key order one entry declares, and live reads of
108
+ // with, the atlases, the key order one entry declares, and live reads of
104
109
  // the state the layer fans out.
105
110
  export type ViewDeps = {
106
111
  label: string
107
112
  pipeline: RenderPipelineId
108
113
  quad: BufferId
109
- atlas: TextureId
114
+ /** The layer's atlas textures in sampler order (the pipeline was
115
+ * compiled for exactly this many). */
116
+ atlases: readonly TextureId[]
110
117
  /** The layer's current instance buffers, in the pipeline's layout order
111
118
  * after the quad (the pose and style pair on the node layer, the one
112
119
  * record buffer on records). */
@@ -114,7 +121,8 @@ export type ViewDeps = {
114
121
  /** The instance count as last published. */
115
122
  count: () => number
116
123
  tint: () => [number, number, number, number]
117
- pick: (x: number, y: number) => Sprite[]
124
+ /** The layer's pick, `zoom` the camera zoom its floors are measured at. */
125
+ pick: (x: number, y: number, zoom: number) => Sprite[]
118
126
  /** The layer's key order (`orderBy`), declared by ONE live entry. */
119
127
  order?: InstanceOrder
120
128
  }
@@ -173,7 +181,7 @@ export function createViews(deps: ViewDeps): Views {
173
181
  width * oversample,
174
182
  height * oversample,
175
183
  { uViewport: [width, height], ...cameraParams(cam), uTint: deps.tint() },
176
- { textures: { uAtlas: deps.atlas }, clearColor: opts.clearColor ?? [0, 0, 0, 0], label, autoFree: false },
184
+ { textures: atlasBindings(deps.atlases), clearColor: opts.clearColor ?? [0, 0, 0, 0], label, autoFree: false },
177
185
  )
178
186
  let order = ordered === null ? deps.order : undefined
179
187
  let entry = entryFor(texture, order)
@@ -200,12 +208,7 @@ export function createViews(deps: ViewDeps): Views {
200
208
  let view: ViewHandle = {
201
209
  texture,
202
210
  handlers: undefined as unknown as LayerHandlers,
203
- get width() {
204
- return width
205
- },
206
- get height() {
207
- return height
208
- },
211
+ size: () => ({ width, height }),
209
212
  setSize(w, h) {
210
213
  if (disposed || (w === width && h === height)) return
211
214
  checkOversample("setSize", oversample, w, h)
@@ -245,6 +248,10 @@ export function createViews(deps: ViewDeps): Views {
245
248
  unproject(x, y) {
246
249
  return unprojectCamera(cam, x, y)
247
250
  },
251
+ pick(x, y) {
252
+ let [wx, wy] = unprojectCamera(cam, x, y)
253
+ return deps.pick(wx, wy, cam.zoom)
254
+ },
248
255
  handlersFor(layout) {
249
256
  return dispatch(layout)
250
257
  },