Skip to content

Commit

Permalink
Create snapshot upon releasing transform gizmo (#9126)
Browse files Browse the repository at this point in the history
* explicitly snapshot after mouse button release on translate/rotate/scale gizmos so that snapshot state is accurate

* commitTransformSave is now more consistent with the rest of the EditorControlFunctions and takes an array of nodes rather than one

* touched up comments

---------

Co-authored-by: HexaField <joshfield999@gmail.com>
  • Loading branch information
anselm and HexaField committed Oct 24, 2023
1 parent 545134f commit c638c3f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
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

0 comments on commit c638c3f

Please sign in to comment.