Problem
A page cannot ask the engine "which objects lie inside this rectangle on screen". The example select-with-a-box (#327, site/examples/select-with-a-box.html) answers it by hand: it projects each piece's world box, takes the screen rectangle round the eight corners and compares rectangles. That is picking redone in the page, it over-selects (a box's projected rectangle is larger than the object), and every page that wants a marquee (the scene editor of #366, an RTS-style unit selection, a measuring tool) would copy it.
The click picking of #368 (world.raycast, camera.rayThrough, raycast(roots, ray)) answers one point; this issue adds the area.
Required Work
world.selectInRect(rect, options?) (name free, beside world.raycast): the objects inside a screen rectangle, as the same Object3D the page added, the same identity raycast returns.
- A sub-frustum, not projected boxes: the rectangle cut out of the camera frustum (
Frustum, Plane in packages/sdk-core/src/world/math/volumes.ts), tested against each object's world bounds, then refined on the triangles for page-built meshes so an object whose box meets the rectangle but whose surface does not is not caught.
- Two modes:
intersect (touches the rectangle) and contain (wholly inside); roots to limit the search to a subtree; helper marks skipped as raycast skips them.
- One scene walk shared with
raycast: same traversal, same visibility and helper rules, no second copy (check:duplicates, check:helpers).
- Loaded models answered as
raycast answers them (on their box, their triangles live on the GPU), declared in the doc.
- Named failure (
EngineError) where the view has no size, as RAYCAST_NO_VIEW.
docs/SDK.md and the API reference beside the raycast section.
Pages that move onto it
Out of scope
Lasso (free-form) selection, visibility-buffer area picking (pickPixel of #263), transforming several objects at once.
Proof
Tests: intersect vs contain, an object whose box meets the rectangle but whose triangles do not (not caught), nested transforms, roots, helpers skipped, degenerate rectangle. One short browser proof on the example: the same drag selects the same pieces before/after, minus the over-selected ones, capture in the PR.
Links
Built on #368 (raycast, #366/#367). Example from #327. Part of #327 (documentation and portal).
Problem
A page cannot ask the engine "which objects lie inside this rectangle on screen". The example
select-with-a-box(#327,site/examples/select-with-a-box.html) answers it by hand: it projects each piece's world box, takes the screen rectangle round the eight corners and compares rectangles. That is picking redone in the page, it over-selects (a box's projected rectangle is larger than the object), and every page that wants a marquee (the scene editor of #366, an RTS-style unit selection, a measuring tool) would copy it.The click picking of #368 (
world.raycast,camera.rayThrough,raycast(roots, ray)) answers one point; this issue adds the area.Required Work
world.selectInRect(rect, options?)(name free, besideworld.raycast): the objects inside a screen rectangle, as the sameObject3Dthe page added, the same identityraycastreturns.Frustum,Planeinpackages/sdk-core/src/world/math/volumes.ts), tested against each object's world bounds, then refined on the triangles for page-built meshes so an object whose box meets the rectangle but whose surface does not is not caught.intersect(touches the rectangle) andcontain(wholly inside);rootsto limit the search to a subtree;helpermarks skipped asraycastskips them.raycast: same traversal, same visibility and helper rules, no second copy (check:duplicates,check:helpers).raycastanswers them (on their box, their triangles live on the GPU), declared in the doc.EngineError) where the view has no size, asRAYCAST_NO_VIEW.docs/SDK.mdand the API reference beside the raycast section.Pages that move onto it
site/examples/select-with-a-box.html: its hand projection (screenBounds,meets) replaced by the engine call; the page keeps only the marquee drawing and the highlight.Out of scope
Lasso (free-form) selection, visibility-buffer area picking (
pickPixelof #263), transforming several objects at once.Proof
Tests: intersect vs contain, an object whose box meets the rectangle but whose triangles do not (not caught), nested transforms,
roots, helpers skipped, degenerate rectangle. One short browser proof on the example: the same drag selects the same pieces before/after, minus the over-selected ones, capture in the PR.Links
Built on #368 (raycast, #366/#367). Example from #327. Part of #327 (documentation and portal).