Replace per-tool rule trees (.cursor/rules, .claude/rules, .codex/rules) with a single wiki/architecture/ source — 11 pages + README — readable as plain markdown by any agent. Canonical skills live in .agents/skills/; .claude/skills, .cursor/skills, .codex/skills are directory symlinks. AGENTS.md is the entrypoint (rewritten as a lean overview, no per-tool path lists). CLAUDE.md, GEMINI.md, and .github/copilot-instructions.md all point to it. Add open-pr skill (uses .github/pull_request_template.md as the source of truth for the PR body) and remove the dangling .claude/CLAUDE.md relative symlink. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3.2 KiB
Spatial Queries
Placement validation for tools — canPlaceOnFloor, canPlaceOnWall, canPlaceOnCeiling.
Applies to: apps/editor/components/tools/**.
useSpatialQuery() validates whether an item can be placed at a given position without overlapping existing items. Every placement tool must call it before committing a node to the scene.
Source: packages/core/src/hooks/spatial-grid/use-spatial-query.ts
Hook
const { canPlaceOnFloor, canPlaceOnWall, canPlaceOnCeiling } = useSpatialQuery()
All three methods return { valid: boolean; conflictIds: string[] }.
canPlaceOnWall additionally returns adjustedY: number (snapped height).
canPlaceOnFloor
canPlaceOnFloor(
levelId: string,
position: [number, number, number],
dimensions: [number, number, number], // scaled width/height/depth
rotation: [number, number, number],
ignoreIds?: string[], // pass [draftItem.id] to exclude self
): { valid: boolean; conflictIds: string[] }
Usage in a tool:
const pos: [number, number, number] = [x, 0, z]
const { valid } = canPlaceOnFloor(levelId, pos, getScaledDimensions(item), item.rotation, [item.id])
if (valid) createNode(item, levelId)
canPlaceOnWall
canPlaceOnWall(
levelId: string,
wallId: string,
localX: number, // distance along wall from start
localY: number, // height from floor
dimensions: [number, number, number],
attachType: 'wall' | 'wall-side', // 'wall' needs clearance both sides; 'wall-side' only one
side?: 'front' | 'back',
ignoreIds?: string[],
): { valid: boolean; conflictIds: string[]; adjustedY: number }
adjustedY contains the snapped Y so items sit flush on the slab — always use it instead of the raw localY:
const { valid, adjustedY } = canPlaceOnWall(levelId, wallId, x, y, dims, 'wall', undefined, [item.id])
if (valid) updateNode(item.id, { wallT: x, wallY: adjustedY })
canPlaceOnCeiling
canPlaceOnCeiling(
ceilingId: string,
position: [number, number, number],
dimensions: [number, number, number],
rotation: [number, number, number],
ignoreIds?: string[],
): { valid: boolean; conflictIds: string[] }
Slab Elevation
When items rest on a slab (not flat ground), use these to get the correct Y:
import { spatialGridManager } from '@pascal-app/core'
// Y at a single point
const y = spatialGridManager.getSlabElevationAt(levelId, x, z)
// Y considering the item's full footprint (highest slab point under item)
const y = spatialGridManager.getSlabElevationForItem(levelId, position, dimensions, rotation)
Rules
- Always pass
[item.id]inignoreIdswhen validating a draft item that already exists in the scene — otherwise it collides with itself. - Use
adjustedYfromcanPlaceOnWall— don't use the raw cursor Y for wall-mounted items. - Use
getScaledDimensions(item)(packages/core/src/schema/nodes/item.ts) to account for item scale, not the rawasset.dimensions. - Validate on every pointer move for live feedback (highlight ghost red/green). Only
createNode/updateNodeon pointer up or click.
See apps/editor/components/tools/item/use-placement-coordinator.tsx for a full implementation.