fixing system orders for ensuring level calculation comes last

This commit is contained in:
wass08
2026-02-23 09:08:15 +09:00
parent 4555325389
commit 3894d7c8bf
5 changed files with 13 additions and 11 deletions
@@ -51,7 +51,7 @@ export const ItemSystem = () => {
}
clearDirty(id as AnyNodeId)
})
}, 2)
})
return null
@@ -29,7 +29,7 @@ export const SlabSystem = () => {
}
// If mesh not found, keep it dirty for next frame
})
})
}, 1)
return null
}
@@ -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<string, Set<string>>()
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
@@ -50,7 +50,7 @@ export const WindowSystem = () => {
useScene.getState().dirtyNodes.add((node as WindowNode).parentId as AnyNodeId)
}
})
})
}, 3)
return null
}
@@ -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
}