* fix(nodes,viewer): window preset live wall preview + shaped-cutout move tracking MoveWindowTool marked the moving window `isTransient` unconditionally, but WindowSystem only rebuilds the host wall's cutout for non-transient windows — so a window *preset* (isNew) showed no live hole on the wall and couldn't be placed consecutively without leaving/re-entering. Guard the transient mark on `!isNew`, matching MoveDoorTool. Separately, shaped openings (arch / rounded / `opening`) rebuild their cutout brush from `node.position`, which a same-wall move doesn't write (it mutates the mesh directly and publishes to `useLiveTransforms`). The wall-system's `getEffectiveNode` only merges `useLiveNodeOverrides` (resize arrows), so shaped cutouts lagged the move while rectangular ones (rebuilt from the live mesh matrixWorld) tracked. Fold `useLiveTransforms` into door/window children before collecting cutouts so shaped holes follow the live move too. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(editor,viewer,nodes): smooth item placement on shelves Three issues made hosting an item on a shelf janky (item-on-item was already smooth because plain items have no `def.geometry` to rebuild): - Jitter: the draft mesh intercepted the cursor ray, so the shelf-row hit was re-derived from the moving item each frame. Disable raycasting on the draft during placement (incl. async GLB children, reconciled per frame) so the ray passes through to the surface beneath — mirrors MoveRegistryNodeTool. - Reparent/vanish at the edges: `onShelfLeave` flipped state to floor without reparenting the draft off the shelf, so the floor strategy's level-local position rendered compounded with the shelf transform. The grid handler now owns the shelf→floor transition. - In/out oscillation: reparenting the draft onto the shelf dirtied the shelf, and GeometrySystem disposed+rebuilt its boards, making r3f fire a spurious shelf:leave→enter that thrashed placement between the row and the floor. Add an opt-in `def.geometryKey` so GeometrySystem skips the rebuild when geometry inputs are unchanged (shelf boards don't depend on hosted children). Keep the item sticky by testing the cursor ray against the shelf's bounding box: a ray that slips through a gap and lands on the floor behind the shelf still counts as "on the shelf"; only a ray that misses the shelf detaches to the floor. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * feat(editor-app): add Shelf to the standalone editor Build tab The shelf kind is fully wired (def.tool, presentation icon, StructureTool id) but was absent from the standalone editor's Build palette. Add it between Column and Spawn Point. Community has its own build-tab and is left untouched. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * chore(mcp): biome-format coordinate-conventions-demo.json The committed example violated Biome formatting (expanded polygon arrays), which broke the `mcp-ci` Biome check on main (#356) and every branch since. Format it so CI is green. Pure formatting — no content change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
163 lines
5.5 KiB
TypeScript
163 lines
5.5 KiB
TypeScript
'use client'
|
|
|
|
import { MaterialPaintPanel, useEditor } from '@pascal-app/editor'
|
|
import Image from 'next/image'
|
|
import { useCallback, useEffect, useRef } from 'react'
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipProvider,
|
|
TooltipTrigger,
|
|
} from '@/components/toolbar-tooltip'
|
|
import { cn } from '@/lib/utils'
|
|
|
|
/**
|
|
* Raw structure-tool kinds the Build tab can activate. These map 1:1 to the
|
|
* editor's `StructureTool` ids.
|
|
*/
|
|
type BuildToolKind =
|
|
| 'wall'
|
|
| 'fence'
|
|
| 'slab'
|
|
| 'ceiling'
|
|
| 'roof'
|
|
| 'stair'
|
|
| 'elevator'
|
|
| 'door'
|
|
| 'window'
|
|
| 'column'
|
|
| 'shelf'
|
|
| 'spawn'
|
|
|
|
type BuildType = {
|
|
/** Selection id — equals `kind` for tool types, `'painting'` for paint mode. */
|
|
id: string
|
|
label: string
|
|
iconSrc: string
|
|
/** Present for structure-tool types (absent for the paint mode). */
|
|
kind?: BuildToolKind
|
|
/** Non-placement special mode. */
|
|
mode?: 'material-paint'
|
|
}
|
|
|
|
// Same icons + ordering as the community Build sidebar, minus presets.
|
|
const BUILD_TYPES: BuildType[] = [
|
|
{ id: 'wall', label: 'Wall', iconSrc: '/icons/wall.png', kind: 'wall' },
|
|
{ id: 'fence', label: 'Fence', iconSrc: '/icons/fence.png', kind: 'fence' },
|
|
{ id: 'slab', label: 'Slab', iconSrc: '/icons/floor.png', kind: 'slab' },
|
|
{ id: 'ceiling', label: 'Ceiling', iconSrc: '/icons/ceiling.png', kind: 'ceiling' },
|
|
{ id: 'roof', label: 'Roof', iconSrc: '/icons/roof.png', kind: 'roof' },
|
|
{ id: 'stair', label: 'Stairs', iconSrc: '/icons/stairs.png', kind: 'stair' },
|
|
{ id: 'elevator', label: 'Elevator', iconSrc: '/icons/elevator.png', kind: 'elevator' },
|
|
{ id: 'door', label: 'Door', iconSrc: '/icons/door.png', kind: 'door' },
|
|
{ id: 'window', label: 'Window', iconSrc: '/icons/window.png', kind: 'window' },
|
|
{ id: 'column', label: 'Column', iconSrc: '/icons/column.png', kind: 'column' },
|
|
{ id: 'shelf', label: 'Shelf', iconSrc: '/icons/shelf.png', kind: 'shelf' },
|
|
{ id: 'spawn', label: 'Spawn Point', iconSrc: '/icons/site.png', kind: 'spawn' },
|
|
{ id: 'painting', label: 'Painting', iconSrc: '/icons/paint.png', mode: 'material-paint' },
|
|
]
|
|
|
|
/**
|
|
* Activate a raw structure draw/cursor tool. Mirrors the editor's own
|
|
* structure-tool activation (`setPhase`/`setStructureLayer`/`setMode`/`setTool`).
|
|
*/
|
|
function activateBuildTool(kind: BuildToolKind): void {
|
|
const ed = useEditor.getState()
|
|
ed.setPhase('structure')
|
|
ed.setStructureLayer('elements')
|
|
ed.setCatalogCategory(null)
|
|
ed.setToolDefaults(kind, null)
|
|
ed.setMode('build')
|
|
ed.setTool(kind)
|
|
}
|
|
|
|
/** Enter material-paint mode — the Build tab's "Painting" category. */
|
|
function activatePaintMode(): void {
|
|
const ed = useEditor.getState()
|
|
ed.setPhase('structure')
|
|
ed.setStructureLayer('elements')
|
|
ed.setMode('material-paint')
|
|
}
|
|
|
|
/**
|
|
* Build tab for the open-source standalone editor — a preset-less replica of
|
|
* the community Build sidebar. Clicking a type activates its raw tool, drawn
|
|
* with the kind's own `def.defaults()`. The "Painting" type swaps in the
|
|
* material-paint panel.
|
|
*/
|
|
export function BuildTab() {
|
|
const activeTool = useEditor((s) => s.tool)
|
|
const mode = useEditor((s) => s.mode)
|
|
|
|
const isTypeActive = (type: BuildType) =>
|
|
type.mode === 'material-paint'
|
|
? mode === 'material-paint'
|
|
: mode === 'build' && activeTool === type.kind
|
|
|
|
const handleTypeClick = useCallback((type: BuildType) => {
|
|
if (type.mode === 'material-paint') {
|
|
activatePaintMode()
|
|
} else if (type.kind) {
|
|
activateBuildTool(type.kind)
|
|
}
|
|
}, [])
|
|
|
|
// On open, land on the first build tool — parity with the community Build
|
|
// sidebar, so switching to Build immediately arms a usable tool.
|
|
const didInitRef = useRef(false)
|
|
useEffect(() => {
|
|
if (didInitRef.current) return
|
|
didInitRef.current = true
|
|
const firstType = BUILD_TYPES.find((t) => t.kind)
|
|
if (firstType) handleTypeClick(firstType)
|
|
}, [handleTypeClick])
|
|
|
|
return (
|
|
<div className="flex h-full flex-col gap-3 p-3">
|
|
<TooltipProvider delayDuration={0} disableHoverableContent>
|
|
<div
|
|
className="grid gap-1.5"
|
|
style={{ gridTemplateColumns: 'repeat(auto-fill, minmax(56px, 1fr))' }}
|
|
>
|
|
{BUILD_TYPES.map((type) => {
|
|
const active = isTypeActive(type)
|
|
return (
|
|
<Tooltip key={type.id}>
|
|
<TooltipTrigger asChild>
|
|
<button
|
|
className={cn(
|
|
'group relative flex aspect-square items-center justify-center rounded-xl p-1 transition-all duration-200',
|
|
active
|
|
? 'bg-primary/10 ring-1 ring-primary/50'
|
|
: 'bg-muted/40 opacity-70 grayscale hover:bg-muted hover:opacity-100 hover:grayscale-0',
|
|
)}
|
|
onClick={() => handleTypeClick(type)}
|
|
type="button"
|
|
>
|
|
<Image
|
|
alt={type.label}
|
|
className="size-full object-contain transition-transform duration-200 group-hover:scale-110"
|
|
height={48}
|
|
src={type.iconSrc}
|
|
width={48}
|
|
/>
|
|
</button>
|
|
</TooltipTrigger>
|
|
<TooltipContent className="pointer-events-none" side="top">
|
|
{type.label}
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
)
|
|
})}
|
|
</div>
|
|
</TooltipProvider>
|
|
|
|
{mode === 'material-paint' ? (
|
|
<div className="min-h-0 flex-1 overflow-y-auto">
|
|
<MaterialPaintPanel />
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
)
|
|
}
|