check wall + clean attach/detach

This commit is contained in:
wass08
2026-01-19 08:29:43 +09:00
parent a217d0d3a6
commit 69148705c6
3 changed files with 80 additions and 18 deletions
@@ -138,25 +138,36 @@ export class SpatialGridManager {
return grid.canPlace(position, dimensions, rotation, ignoreIds);
}
/**
* Check if an item can be placed on a wall
* @param levelId - the level containing the wall
* @param wallId - the wall to check
* @param localX - X position in wall-local space (distance from wall start)
* @param localY - Y position (height from floor)
* @param dimensions - item dimensions [width, height, depth]
* @param ignoreIds - item IDs to ignore in collision check
*/
canPlaceOnWall(
levelId: string,
wallId: string,
tCenter: number,
itemWidth: number,
yCenter: number,
itemHeight: number,
localX: number,
localY: number,
dimensions: [number, number, number],
ignoreIds?: string[],
) {
const wallLength = this.getWallLength(wallId);
if (wallLength === 0) {
return { valid: false, conflictIds: [] };
}
// Convert local X position to parametric t (0-1)
const tCenter = localX / wallLength;
const [itemWidth, itemHeight] = dimensions;
return this.getWallGrid(levelId).canPlaceOnWall(
wallId,
wallLength,
tCenter,
itemWidth,
yCenter,
localY,
itemHeight,
ignoreIds,
);
@@ -1,9 +1,9 @@
import { useCallback } from "react";
import { spatialGridManager } from "./spatial-grid-manager";
import { LevelNode } from "../../schema";
import { LevelNode, WallNode } from "../../schema";
export function useSpatialQuery() {
const canPlace = useCallback(
const canPlaceOnFloor = useCallback(
(
levelId: LevelNode["id"],
position: [number, number, number],
@@ -22,5 +22,26 @@ export function useSpatialQuery() {
[],
);
return { canPlace };
const canPlaceOnWall = useCallback(
(
levelId: LevelNode["id"],
wallId: WallNode["id"],
localX: number,
localY: number,
dimensions: [number, number, number],
ignoreIds?: string[],
) => {
return spatialGridManager.canPlaceOnWall(
levelId,
wallId,
localX,
localY,
dimensions,
ignoreIds,
);
},
[],
);
return { canPlaceOnFloor, canPlaceOnWall };
}