fixing system orders for ensuring level calculation comes last
This commit is contained in:
@@ -51,7 +51,7 @@ export const ItemSystem = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clearDirty(id as AnyNodeId)
|
clearDirty(id as AnyNodeId)
|
||||||
})
|
}, 2)
|
||||||
})
|
})
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export const SlabSystem = () => {
|
|||||||
}
|
}
|
||||||
// If mesh not found, keep it dirty for next frame
|
// If mesh not found, keep it dirty for next frame
|
||||||
})
|
})
|
||||||
})
|
}, 1)
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useFrame } from '@react-three/fiber'
|
import { useFrame } from '@react-three/fiber'
|
||||||
import * as THREE from 'three'
|
import * as THREE from 'three'
|
||||||
import { computeBoundsTree } from 'three-mesh-bvh'
|
|
||||||
import { Brush, Evaluator, SUBTRACTION } from 'three-bvh-csg'
|
import { Brush, Evaluator, SUBTRACTION } from 'three-bvh-csg'
|
||||||
|
import { computeBoundsTree } from 'three-mesh-bvh'
|
||||||
import { sceneRegistry } from '../../hooks/scene-registry/scene-registry'
|
import { sceneRegistry } from '../../hooks/scene-registry/scene-registry'
|
||||||
import { spatialGridManager } from '../../hooks/spatial-grid/spatial-grid-manager'
|
import { spatialGridManager } from '../../hooks/spatial-grid/spatial-grid-manager'
|
||||||
import { resolveLevelId } from '../../hooks/spatial-grid/spatial-grid-sync'
|
import { resolveLevelId } from '../../hooks/spatial-grid/spatial-grid-sync'
|
||||||
@@ -22,7 +22,7 @@ const csgEvaluator = new Evaluator()
|
|||||||
// WALL SYSTEM
|
// WALL SYSTEM
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
let useFrameNb = 0;
|
let useFrameNb = 0
|
||||||
export const WallSystem = () => {
|
export const WallSystem = () => {
|
||||||
const dirtyNodes = useScene((state) => state.dirtyNodes)
|
const dirtyNodes = useScene((state) => state.dirtyNodes)
|
||||||
const clearDirty = useScene((state) => state.clearDirty)
|
const clearDirty = useScene((state) => state.clearDirty)
|
||||||
@@ -35,7 +35,7 @@ export const WallSystem = () => {
|
|||||||
// Collect dirty walls and their levels
|
// Collect dirty walls and their levels
|
||||||
const dirtyWallsByLevel = new Map<string, Set<string>>()
|
const dirtyWallsByLevel = new Map<string, Set<string>>()
|
||||||
|
|
||||||
useFrameNb += 1;
|
useFrameNb += 1
|
||||||
dirtyNodes.forEach((id) => {
|
dirtyNodes.forEach((id) => {
|
||||||
const node = nodes[id]
|
const node = nodes[id]
|
||||||
if (!node || node.type !== 'wall') return
|
if (!node || node.type !== 'wall') return
|
||||||
@@ -75,7 +75,7 @@ export const WallSystem = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}, 4)
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,6 @@ function updateWallGeometry(wallId: string, miterData: WallMiterData) {
|
|||||||
const node = nodes[wallId as WallNode['id']]
|
const node = nodes[wallId as WallNode['id']]
|
||||||
if (!node || node.type !== 'wall') return
|
if (!node || node.type !== 'wall') return
|
||||||
|
|
||||||
|
|
||||||
const mesh = sceneRegistry.nodes.get(wallId) as THREE.Mesh
|
const mesh = sceneRegistry.nodes.get(wallId) as THREE.Mesh
|
||||||
if (!mesh) return
|
if (!mesh) return
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export const WindowSystem = () => {
|
|||||||
useScene.getState().dirtyNodes.add((node as WindowNode).parentId as AnyNodeId)
|
useScene.getState().dirtyNodes.add((node as WindowNode).parentId as AnyNodeId)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
}, 3)
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ function getLevelHeight(
|
|||||||
} else if (child.type === 'wall') {
|
} else if (child.type === 'wall') {
|
||||||
// Wall mesh is pushed up to slabElevation by WallSystem.
|
// Wall mesh is pushed up to slabElevation by WallSystem.
|
||||||
// mesh.position.y + wall.height gives the actual top Y in level-local space.
|
// 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)
|
const top = meshY + ((child as WallNode).height ?? DEFAULT_LEVEL_HEIGHT)
|
||||||
if (top > maxTop) maxTop = top
|
if (top > maxTop) maxTop = top
|
||||||
}
|
}
|
||||||
@@ -78,11 +81,11 @@ export const LevelSystem = () => {
|
|||||||
const explodedExtra = levelMode === 'exploded' ? index * EXPLODED_GAP : 0
|
const explodedExtra = levelMode === 'exploded' ? index * EXPLODED_GAP : 0
|
||||||
const targetY = baseY + explodedExtra
|
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
|
obj.visible = levelMode !== 'solo' || level?.id === selectedLevel || !selectedLevel
|
||||||
|
|
||||||
cumulativeY += getLevelHeight(levelId, nodes)
|
cumulativeY += getLevelHeight(levelId, nodes)
|
||||||
}
|
}
|
||||||
})
|
}, 5) // Using a lower priority so it runs after transforms from other systems have settled
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user