Skip to content

Commit

Permalink
feat(redo-undo): "drag translation gzimo drop" add to undo stack
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed Jan 29, 2019
1 parent b88e485 commit 92660cc
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 125 deletions.
57 changes: 52 additions & 5 deletions src/core/job/init/InitTransformGizmosJob.re
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ let _bindEvent = (editorState, engineState) => {
let editorState = StateEditorService.getState();

let editorState =
SelectTransformGizmoUtils.selectTransformGizmo(
event,
engineState,
IsTransformGizmoRenderSceneViewEditorService.isTranslationWholeGizmoRender(
editorState,
);
) ?
editorState
|> TransformGizmoSceneViewEditorService.setCurrentSceneTreeNodeStartPoint(
InitTransformGizmosUtils.getCurrentSceneTreeNodePosition(
editorState,
engineState,
),
)
|> SelectTransformGizmoUtils.selectTransformGizmo(
event,
engineState,
) :
editorState
|> SelectTransformGizmoSceneViewEditorService.markNotSelectAnyTranslationGizmo;

editorState |> StateEditorService.setState |> ignore;

Expand All @@ -38,7 +49,9 @@ let _bindEvent = (editorState, engineState) => {
~eventName=SceneViewEventEditorService.getPointDragOverEventName(),
~handleFunc=
(. event, engineState) =>
MouseEventService.isLeftMouseButton(event) ?
MouseEventService.isLeftMouseButton(event)
&& SelectTransformGizmoSceneViewEditorService.isSelectAnyTransformGizmo
|> StateLogicService.getEditorState ?
{
let editorState = StateEditorService.getState();

Expand All @@ -62,6 +75,40 @@ let _bindEvent = (editorState, engineState) => {
(),
);

let engineState =
ManageEventEngineService.onCustomGlobalEvent(
~eventName=SceneViewEventEditorService.getPointDragDropEventName(),
~handleFunc=
(. event, engineState) =>
MouseEventService.isLeftMouseButton(event)
&& SelectTransformGizmoSceneViewEditorService.isSelectAnyTransformGizmo
|> StateLogicService.getEditorState ?
{
let editorState = StateEditorService.getState();
let transform =
GameObjectComponentEngineService.unsafeGetTransformComponent(
SceneTreeEditorService.unsafeGetCurrentSceneTreeNode(
editorState,
),
engineState,
);
engineState |> StateEngineService.setState |> ignore;

PositionBlurEventHandler.MakeEventHandler.pushUndoStackWithCopiedEngineState(
(UIStateService.getState(), UIStateService.getDispatch()),
transform,
TransformGizmoSceneViewEditorService.unsafeGetCurrentSceneTreeNodeStartPoint(
editorState,
),
);

(StateEngineService.unsafeGetState(), event);
} :
(engineState, event),
~state=engineState,
(),
);

engineState;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ let setToEditorState =
isTranslationXAxisGizmoSelected: false,
isTranslationYAxisGizmoSelected: false,
isTranslationZAxisGizmoSelected: false,
currentSceneTreeNodeStartPoint: None,
axisGameObjectStartPoint: None,
pickStartPoint: None,
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
let _getCurrentSceneTreeNodePosition = (editorState, engineState) =>
TransformEngineService.getPosition(
GameObjectComponentEngineService.unsafeGetTransformComponent(
SceneTreeEditorService.unsafeGetCurrentSceneTreeNode(editorState),
engineState,
),
engineState,
);

let _findMostOrthogonalPlaneBetweenCurrentSceneTreeNodeAndCameraVecAndPlane =
(
(axis1Vec, plane1: ShapeType.planeShape),
Expand All @@ -19,7 +10,10 @@ let _findMostOrthogonalPlaneBetweenCurrentSceneTreeNodeAndCameraVecAndPlane =
let currentSceneTreeNodeToCameraVec =
Wonderjs.Vector3Service.sub(
Wonderjs.Vector3Type.Float,
_getCurrentSceneTreeNodePosition(editorState, engineState),
InitTransformGizmosUtils.getCurrentSceneTreeNodePosition(
editorState,
engineState,
),
TransformEngineService.getPosition(
GameObjectComponentEngineService.unsafeGetTransformComponent(
cameraGameObject,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let getCurrentSceneTreeNodePosition = (editorState, engineState) =>
TransformEngineService.getPosition(
GameObjectComponentEngineService.unsafeGetTransformComponent(
SceneTreeEditorService.unsafeGetCurrentSceneTreeNode(editorState),
engineState,
),
engineState,
);
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,51 @@ let _selectAxisGizmo =
);
};

let selectTransformGizmo = (event, engineState, editorState) =>
IsTransformGizmoRenderSceneViewEditorService.isTranslationWholeGizmoRender(
editorState,
) ?
{
let cameraGameObject =
SceneViewEditorService.unsafeGetEditCamera(editorState);
let selectTransformGizmo = (event, engineState, editorState) => {
let cameraGameObject =
SceneViewEditorService.unsafeGetEditCamera(editorState);

let ray =
RayUtils.createPerspectiveCameraRayFromEvent(
event,
cameraGameObject,
(editorState, engineState),
);
let ray =
RayUtils.createPerspectiveCameraRayFromEvent(
event,
cameraGameObject,
(editorState, engineState),
);

_isSelectTranslationAxisGizmo(
TransformGizmoSceneViewEditorService.unsafeGetTranslationXAxisGizmo(
editorState,
),
ray,
engineState,
editorState,
) ?
_selectAxisGizmo(
ray,
(
SelectTransformGizmoSceneViewEditorService.onlySelectTranslationXAxisGizmo,
_getMoveStartDataForXAxis,
),
(editorState, engineState),
) :
_isSelectTranslationAxisGizmo(
TransformGizmoSceneViewEditorService.unsafeGetTranslationYAxisGizmo(
editorState,
),
ray,
engineState,
editorState,
) ?
_selectAxisGizmo(
ray,
(
SelectTransformGizmoSceneViewEditorService.onlySelectTranslationYAxisGizmo,
_getMoveStartDataForYAxis,
),
(editorState, engineState),
) :
_isSelectTranslationAxisGizmo(
TransformGizmoSceneViewEditorService.unsafeGetTranslationXAxisGizmo(
TransformGizmoSceneViewEditorService.unsafeGetTranslationZAxisGizmo(
editorState,
),
ray,
Expand All @@ -142,45 +170,11 @@ let selectTransformGizmo = (event, engineState, editorState) =>
_selectAxisGizmo(
ray,
(
SelectTransformGizmoSceneViewEditorService.onlySelectTranslationXAxisGizmo,
_getMoveStartDataForXAxis,
SelectTransformGizmoSceneViewEditorService.onlySelectTranslationZAxisGizmo,
_getMoveStartDataForZAxis,
),
(editorState, engineState),
) :
_isSelectTranslationAxisGizmo(
TransformGizmoSceneViewEditorService.unsafeGetTranslationYAxisGizmo(
editorState,
),
ray,
engineState,
editorState,
) ?
_selectAxisGizmo(
ray,
(
SelectTransformGizmoSceneViewEditorService.onlySelectTranslationYAxisGizmo,
_getMoveStartDataForYAxis,
),
(editorState, engineState),
) :
_isSelectTranslationAxisGizmo(
TransformGizmoSceneViewEditorService.unsafeGetTranslationZAxisGizmo(
editorState,
),
ray,
engineState,
editorState,
) ?
_selectAxisGizmo(
ray,
(
SelectTransformGizmoSceneViewEditorService.onlySelectTranslationZAxisGizmo,
_getMoveStartDataForZAxis,
),
(editorState, engineState),
) :
editorState
|> SelectTransformGizmoSceneViewEditorService.markNotSelectAnyTranslationGizmo;
} :
editorState
|> SelectTransformGizmoSceneViewEditorService.markNotSelectAnyTranslationGizmo;
editorState
|> SelectTransformGizmoSceneViewEditorService.markNotSelectAnyTranslationGizmo;
};
1 change: 1 addition & 0 deletions src/service/record/editor/data/SceneViewType.re
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type transformGizmoData = {
isTranslationXAxisGizmoSelected: bool,
isTranslationYAxisGizmoSelected: bool,
isTranslationZAxisGizmoSelected: bool,
currentSceneTreeNodeStartPoint: option((float, float, float)),
axisGameObjectStartPoint: option((float, float, float)),
pickStartPoint: option((float, float, float)),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,27 @@ let setTranslationZAxisGizmo = (gameObject, editorState) => {
translationZAxisGizmo: gameObject,
}),
},
};

let unsafeGetCurrentSceneTreeNodeStartPoint = editorState =>
RecordTransformGizmoSceneViewEditorService.unsafeGetData(
editorState.sceneViewRecord,
).
currentSceneTreeNodeStartPoint
|> OptionService.unsafeGet;

let setCurrentSceneTreeNodeStartPoint =
(currentSceneTreeNodeStartPoint, editorState) => {
...editorState,
sceneViewRecord: {
...editorState.sceneViewRecord,
transformGizmoData:
Some({
...
RecordTransformGizmoSceneViewEditorService.unsafeGetData(
editorState.sceneViewRecord,
),
currentSceneTreeNodeStartPoint: Some(currentSceneTreeNodeStartPoint),
}),
},
};
Loading

0 comments on commit 92660cc

Please sign in to comment.