fix furnish node
This commit is contained in:
@@ -19,7 +19,7 @@ export interface DraftNodeHandle {
|
||||
/** Whether the current draft was adopted (move mode) vs created (create mode) */
|
||||
readonly isAdopted: boolean
|
||||
/** Create a new draft item at the given position. Returns the created node or null. */
|
||||
create: (gridPosition: Vector3, asset: Asset) => ItemNode | null
|
||||
create: (gridPosition: Vector3, asset: Asset, rotation?: [number, number, number]) => ItemNode | null
|
||||
/** Take ownership of an existing scene node as the draft (for move mode). */
|
||||
adopt: (node: ItemNode) => void
|
||||
/** Commit the current draft. Create mode: delete+recreate. Move mode: update in place. */
|
||||
@@ -41,12 +41,13 @@ export function useDraftNode(): DraftNodeHandle {
|
||||
const adoptedRef = useRef(false)
|
||||
const originalStateRef = useRef<OriginalState | null>(null)
|
||||
|
||||
const create = useCallback((gridPosition: Vector3, asset: Asset): ItemNode | null => {
|
||||
const create = useCallback((gridPosition: Vector3, asset: Asset, rotation?: [number, number, number]): ItemNode | null => {
|
||||
const currentLevelId = useViewer.getState().selection.levelId
|
||||
if (!currentLevelId) return null
|
||||
|
||||
const node = ItemNode.parse({
|
||||
position: [gridPosition.x, gridPosition.y, gridPosition.z],
|
||||
rotation: rotation ?? [0, 0, 0],
|
||||
name: asset.name,
|
||||
asset,
|
||||
metadata: { isTransient: true },
|
||||
|
||||
@@ -93,7 +93,7 @@ export function usePlacementCoordinator(config: PlacementCoordinatorConfig): Rea
|
||||
cursorRef.current.position.set(...result.cursorPosition)
|
||||
cursorRef.current.rotation.y = result.cursorRotationY
|
||||
|
||||
draftNode.create(gridPosition.current, asset)
|
||||
draftNode.create(gridPosition.current, asset, [0, result.cursorRotationY, 0])
|
||||
|
||||
const draft = draftNode.current
|
||||
if (draft) {
|
||||
@@ -146,9 +146,12 @@ export function usePlacementCoordinator(config: PlacementCoordinatorConfig): Rea
|
||||
const result = floorStrategy.click(getContext(), event, validators)
|
||||
if (!result) return
|
||||
|
||||
// Preserve cursor rotation for the next draft
|
||||
const currentRotation: [number, number, number] = [0, cursorRef.current.rotation.y, 0]
|
||||
|
||||
draftNode.commit(result.nodeUpdate)
|
||||
if (config.onCommitted()) {
|
||||
draftNode.create(gridPosition.current, asset)
|
||||
draftNode.create(gridPosition.current, asset, currentRotation)
|
||||
revalidate()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user