Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Create snapshot upon releasing transform gizmo #9126

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const ScenePreviewCameraNodeEditor: EditorComponentType = (props) => {
transform.rotation.copy(rotation)
computeTransformMatrix(props.entity)

EditorControlFunctions.commitTransformSave(props.entity)
EditorControlFunctions.commitTransformSave([props.entity])
}

const updateScenePreview = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const TransformPropertyGroup: EditorComponentType = (props) => {
const useGlobalTransformComponent = useHookstate(false)

const onRelease = () => {
EditorControlFunctions.commitTransformSave(props.entity)
EditorControlFunctions.commitTransformSave([props.entity])
}

const onChangeDynamicLoad = (value) => {
Expand Down
16 changes: 9 additions & 7 deletions packages/editor/src/functions/EditorControlFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,14 +777,16 @@ const addToSelection = (nodes: EntityOrObjectUUID[]) => {
// dispatchAction(EditorHistoryAction.createSnapshot(newSnapshot))
}

const commitTransformSave = (entity: Entity) => {
const commitTransformSave = (nodes: EntityOrObjectUUID[]) => {
const newSnapshot = EditorHistoryState.cloneCurrentSnapshot()
LocalTransformComponent.stateMap[entity]!.set(LocalTransformComponent.valueMap[entity])

const entityData = newSnapshot.data.scene.entities[getComponent(entity, UUIDComponent)]
const component = entityData.components.find((c) => c.name === LocalTransformComponent.jsonID)!
component.props = serializeComponent(entity, LocalTransformComponent)

for (let i = 0; i < nodes.length; i++) {
const entity = nodes[i]
if (typeof entity === 'string') continue
LocalTransformComponent.stateMap[entity]!.set(LocalTransformComponent.valueMap[entity])
const entityData = newSnapshot.data.scene.entities[getComponent(entity, UUIDComponent)]
const component = entityData.components.find((c) => c.name === LocalTransformComponent.jsonID)!
component.props = serializeComponent(entity, LocalTransformComponent)
}
dispatchAction(EditorHistoryAction.createSnapshot(newSnapshot))
}

Expand Down
5 changes: 4 additions & 1 deletion packages/editor/src/systems/EditorControlSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,13 @@ const execute = () => {
EditorControlFunctions.replaceSelection([])
}
}

gizmoObj.deselectAxis()
dragging = false
}

// commit transform changes upon releasing the gizmo
const nodes = getEntityNodeArrayFromEntities(getState(SelectionState).selectedEntities)
EditorControlFunctions.commitTransformSave(nodes)
}

if (editorHelperState.isFlyModeEnabled) return
Expand Down
Loading