transient nodes
This commit is contained in:
@@ -17,8 +17,8 @@ import { AppSidebar } from '../ui/sidebar/app-sidebar'
|
||||
import { CustomCameraControls } from './custom-camera-controls'
|
||||
import { SelectionManager } from './selection-manager'
|
||||
|
||||
initSpatialGridSync()
|
||||
useScene.getState().loadScene()
|
||||
initSpatialGridSync()
|
||||
|
||||
export default function Editor() {
|
||||
useKeyboard()
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
emitter,
|
||||
type GridEvent,
|
||||
ItemNode,
|
||||
isObject,
|
||||
sceneRegistry,
|
||||
useScene,
|
||||
useSpatialQuery,
|
||||
@@ -29,6 +30,12 @@ function snapToGrid(position: number, dimension: number): number {
|
||||
return Math.round((position - offset) * 2) / 2 + offset
|
||||
}
|
||||
|
||||
const stripTransient = (meta: any) => {
|
||||
if (!isObject(meta)) return meta
|
||||
const { isTransient, ...rest } = meta as Record<string, any>
|
||||
return rest
|
||||
}
|
||||
|
||||
export const ItemTool: React.FC = () => {
|
||||
const cursorRef = useRef<Mesh>(null!)
|
||||
const draftItem = useRef<ItemNode | null>(null)
|
||||
@@ -90,6 +97,9 @@ export const ItemTool: React.FC = () => {
|
||||
position: [gridPosition.current.x, gridPosition.current.y, gridPosition.current.z],
|
||||
name: selectedItem.name,
|
||||
asset: selectedItem,
|
||||
metadata: {
|
||||
isTransient: true,
|
||||
},
|
||||
})
|
||||
useScene.getState().createNode(draftItem.current, currentLevelId)
|
||||
checkCanPlace()
|
||||
@@ -124,8 +134,10 @@ export const ItemTool: React.FC = () => {
|
||||
if (!currentLevelId || !draftItem.current || !checkCanPlace()) return
|
||||
|
||||
useScene.temporal.getState().resume()
|
||||
|
||||
useScene.getState().updateNode(draftItem.current.id, {
|
||||
position: [gridPosition.current.x, 0, gridPosition.current.z],
|
||||
metadata: stripTransient(draftItem.current.metadata),
|
||||
})
|
||||
draftItem.current = null
|
||||
|
||||
@@ -187,6 +199,7 @@ export const ItemTool: React.FC = () => {
|
||||
useScene.getState().updateNode(draftItem.current.id, {
|
||||
position: [gridPosition.current.x, gridPosition.current.y, gridPosition.current.z],
|
||||
parentId: event.node.id,
|
||||
metadata: stripTransient(draftItem.current.metadata),
|
||||
})
|
||||
useScene.getState().dirtyNodes.add(event.node.id)
|
||||
draftItem.current = null
|
||||
|
||||
Reference in New Issue
Block a user