fix default spatial grid
This commit is contained in:
@@ -18,6 +18,7 @@ import { CustomCameraControls } from './custom-camera-controls'
|
|||||||
import { SelectionManager } from './selection-manager'
|
import { SelectionManager } from './selection-manager'
|
||||||
|
|
||||||
useScene.getState().loadScene()
|
useScene.getState().loadScene()
|
||||||
|
console.log('Loaded scene in editor')
|
||||||
initSpatialGridSync()
|
initSpatialGridSync()
|
||||||
|
|
||||||
export default function Editor() {
|
export default function Editor() {
|
||||||
|
|||||||
@@ -26,6 +26,14 @@ export function resolveLevelId(node: AnyNode, nodes: Record<string, AnyNode>): s
|
|||||||
// Call this once at app initialization
|
// Call this once at app initialization
|
||||||
export function initSpatialGridSync() {
|
export function initSpatialGridSync() {
|
||||||
const store = useScene
|
const store = useScene
|
||||||
|
// 1. Initial sync - process all existing nodes
|
||||||
|
const state = store.getState()
|
||||||
|
for (const node of Object.values(state.nodes)) {
|
||||||
|
const levelId = resolveLevelId(node, state.nodes)
|
||||||
|
spatialGridManager.handleNodeCreated(node, levelId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Then subscribe to future changes
|
||||||
|
|
||||||
// Subscribe to all changes
|
// Subscribe to all changes
|
||||||
store.subscribe((state, prevState) => {
|
store.subscribe((state, prevState) => {
|
||||||
|
|||||||
@@ -163,7 +163,8 @@ const useScene = create<SceneState>()(
|
|||||||
zoneIds: state.zoneIds,
|
zoneIds: state.zoneIds,
|
||||||
}),
|
}),
|
||||||
onRehydrateStorage: (state) => {
|
onRehydrateStorage: (state) => {
|
||||||
console.log('hydration starts')
|
|
||||||
|
console.log('hydrating...')
|
||||||
|
|
||||||
// optional
|
// optional
|
||||||
return (state, error) => {
|
return (state, error) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user