From 3894d7c8bfb7250ceb2aa882a5c0524c24709ccd Mon Sep 17 00:00:00 2001 From: wass08 Date: Mon, 23 Feb 2026 09:08:15 +0900 Subject: [PATCH] fixing system orders for ensuring level calculation comes last --- packages/core/src/systems/item/item-system.tsx | 2 +- packages/core/src/systems/slab/slab-system.tsx | 2 +- packages/core/src/systems/wall/wall-system.tsx | 9 ++++----- packages/core/src/systems/window/window-system.tsx | 2 +- packages/viewer/src/systems/level/level-system.tsx | 9 ++++++--- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/core/src/systems/item/item-system.tsx b/packages/core/src/systems/item/item-system.tsx index 5a70bacc..ef1dd522 100644 --- a/packages/core/src/systems/item/item-system.tsx +++ b/packages/core/src/systems/item/item-system.tsx @@ -51,7 +51,7 @@ export const ItemSystem = () => { } clearDirty(id as AnyNodeId) - }) + }, 2) }) return null diff --git a/packages/core/src/systems/slab/slab-system.tsx b/packages/core/src/systems/slab/slab-system.tsx index 29a2c8b6..29aae139 100644 --- a/packages/core/src/systems/slab/slab-system.tsx +++ b/packages/core/src/systems/slab/slab-system.tsx @@ -29,7 +29,7 @@ export const SlabSystem = () => { } // If mesh not found, keep it dirty for next frame }) - }) + }, 1) return null } diff --git a/packages/core/src/systems/wall/wall-system.tsx b/packages/core/src/systems/wall/wall-system.tsx index 13589518..e741519a 100644 --- a/packages/core/src/systems/wall/wall-system.tsx +++ b/packages/core/src/systems/wall/wall-system.tsx @@ -1,7 +1,7 @@ import { useFrame } from '@react-three/fiber' import * as THREE from 'three' -import { computeBoundsTree } from 'three-mesh-bvh' import { Brush, Evaluator, SUBTRACTION } from 'three-bvh-csg' +import { computeBoundsTree } from 'three-mesh-bvh' import { sceneRegistry } from '../../hooks/scene-registry/scene-registry' import { spatialGridManager } from '../../hooks/spatial-grid/spatial-grid-manager' import { resolveLevelId } from '../../hooks/spatial-grid/spatial-grid-sync' @@ -22,7 +22,7 @@ const csgEvaluator = new Evaluator() // WALL SYSTEM // ============================================================================ -let useFrameNb = 0; +let useFrameNb = 0 export const WallSystem = () => { const dirtyNodes = useScene((state) => state.dirtyNodes) const clearDirty = useScene((state) => state.clearDirty) @@ -35,7 +35,7 @@ export const WallSystem = () => { // Collect dirty walls and their levels const dirtyWallsByLevel = new Map>() - useFrameNb += 1; + useFrameNb += 1 dirtyNodes.forEach((id) => { const node = nodes[id] if (!node || node.type !== 'wall') return @@ -75,7 +75,7 @@ export const WallSystem = () => { } } } - }) + }, 4) return null } @@ -108,7 +108,6 @@ function updateWallGeometry(wallId: string, miterData: WallMiterData) { const node = nodes[wallId as WallNode['id']] if (!node || node.type !== 'wall') return - const mesh = sceneRegistry.nodes.get(wallId) as THREE.Mesh if (!mesh) return diff --git a/packages/core/src/systems/window/window-system.tsx b/packages/core/src/systems/window/window-system.tsx index 57180af5..c533dd2b 100644 --- a/packages/core/src/systems/window/window-system.tsx +++ b/packages/core/src/systems/window/window-system.tsx @@ -50,7 +50,7 @@ export const WindowSystem = () => { useScene.getState().dirtyNodes.add((node as WindowNode).parentId as AnyNodeId) } }) - }) + }, 3) return null } diff --git a/packages/viewer/src/systems/level/level-system.tsx b/packages/viewer/src/systems/level/level-system.tsx index dcc047a8..f6a9bfd3 100644 --- a/packages/viewer/src/systems/level/level-system.tsx +++ b/packages/viewer/src/systems/level/level-system.tsx @@ -33,7 +33,10 @@ function getLevelHeight( } else if (child.type === 'wall') { // Wall mesh is pushed up to slabElevation by WallSystem. // mesh.position.y + wall.height gives the actual top Y in level-local space. - const meshY = sceneRegistry.nodes.get(childId as any)?.position.y ?? 0 + let meshY = sceneRegistry.nodes.get(childId as any)?.position.y ?? 0 + if (meshY < 0) { + meshY = 0 // Guard against invalid negative Y which could cause incorrect height calculation (e.g. from sunken slabs) + } const top = meshY + ((child as WallNode).height ?? DEFAULT_LEVEL_HEIGHT) if (top > maxTop) maxTop = top } @@ -78,11 +81,11 @@ export const LevelSystem = () => { const explodedExtra = levelMode === 'exploded' ? index * EXPLODED_GAP : 0 const targetY = baseY + explodedExtra - obj.position.y = lerp(obj.position.y, targetY, delta * 3) + obj.position.y = lerp(obj.position.y, targetY, delta * 12) // Smoothly animate to new Y position obj.visible = levelMode !== 'solo' || level?.id === selectedLevel || !selectedLevel cumulativeY += getLevelHeight(levelId, nodes) } - }) + }, 5) // Using a lower priority so it runs after transforms from other systems have settled return null }