check wall + clean attach/detach
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user