-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scene-view): "transform gizmo": add "switch world coordinate sys…
…tem" ui
- Loading branch information
Showing
8 changed files
with
226 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...onent/controller/atom_component/transformGizmo/ui/TransformGizmoCoordinateSystemSwitch.re
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
open TransformGizmoCoordinateSystemSwitchType; | ||
|
||
type state = {selectedCoordinateSystem: coordinateSystem}; | ||
|
||
type action = | ||
| Change(coordinateSystem, onChangeFunc); | ||
|
||
module Method = { | ||
let getText = (coordinateSystem: coordinateSystem) => | ||
switch (coordinateSystem) { | ||
| World => "World" | ||
| Local => "Local" | ||
}; | ||
|
||
let _getReverse = (coordinateSystem: coordinateSystem) : coordinateSystem => | ||
switch (coordinateSystem) { | ||
| World => Local | ||
| Local => World | ||
}; | ||
|
||
let change = ((state, send), onChangeFunc) => | ||
send( | ||
Change(state.selectedCoordinateSystem |> _getReverse, onChangeFunc), | ||
); | ||
}; | ||
|
||
let component = ReasonReact.reducerComponent("TransformGizmoSwitch"); | ||
|
||
let reducer = (action, state) => | ||
switch (action) { | ||
| Change(coordinateSystem, onChangeFunc) => | ||
ReasonReactUtils.updateWithSideEffects( | ||
{...state, selectedCoordinateSystem: coordinateSystem}, _state => | ||
onChangeFunc(coordinateSystem) | ||
) | ||
}; | ||
|
||
let render = | ||
(onChangeFunc, ({state, send}: ReasonReact.self('a, 'b, 'c)) as self) => | ||
<article | ||
key="TransformGizmoCoordinateSystemSwitch" | ||
className="transform-gizmo-coordinate-system-switch"> | ||
<button onClick=(_e => Method.change((state, send), onChangeFunc))> | ||
(DomHelper.textEl(Method.getText(state.selectedCoordinateSystem))) | ||
</button> | ||
</article>; | ||
|
||
let make = (~defaultCoordinateSystem, ~onChange, _children) => { | ||
...component, | ||
initialState: () => {selectedCoordinateSystem: defaultCoordinateSystem}, | ||
reducer, | ||
render: self => render(onChange, self), | ||
}; |
10 changes: 10 additions & 0 deletions
10
...t/controller/atom_component/transformGizmo/ui/TransformGizmoCoordinateSystemSwitchType.re
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
type coordinateSystem = SceneViewType.coordinateSystem; | ||
|
||
type onChangeFunc = coordinateSystem => unit; | ||
|
||
type item = { | ||
coordinateSystem, | ||
onChangeFunc, | ||
}; | ||
|
||
/* type data = array(item); */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...core/utils/engine/job/init/initTransformGizmosJob/CoordinateSystemTransformGizmosUtils.re
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
let rotateWholeGizmoToCurrentSceneTreeNode = | ||
( | ||
currentSceneTreeNode, | ||
wholeGizmo, | ||
coordinateSystem: SceneViewType.coordinateSystem, | ||
engineState, | ||
) => { | ||
let wholeGizmoTransform = | ||
GameObjectComponentEngineService.unsafeGetTransformComponent( | ||
wholeGizmo, | ||
engineState, | ||
); | ||
|
||
switch (coordinateSystem) { | ||
| Local => | ||
let currentSceneTreeNodeTransform = | ||
GameObjectComponentEngineService.unsafeGetTransformComponent( | ||
currentSceneTreeNode, | ||
engineState, | ||
); | ||
|
||
engineState | ||
|> TransformEngineService.setEulerAngles( | ||
wholeGizmoTransform, | ||
TransformEngineService.getEulerAngles( | ||
currentSceneTreeNodeTransform, | ||
engineState, | ||
), | ||
); | ||
| World => | ||
engineState | ||
|> TransformEngineService.setEulerAngles( | ||
wholeGizmoTransform, | ||
(0., 0., 0.), | ||
) | ||
}; | ||
}; | ||
|
||
let rotateWholeTransformGizmoToCurrentSceneTreeNode = | ||
(editorState, engineState) => { | ||
let currentSceneTreeNode = | ||
SceneTreeEditorService.unsafeGetCurrentSceneTreeNode(editorState); | ||
|
||
let coordinateSystem = | ||
CoordinateSystemTransformGizmoSceneViewEditorService.getCoordinateSystem( | ||
editorState, | ||
); | ||
|
||
engineState | ||
|> rotateWholeGizmoToCurrentSceneTreeNode( | ||
currentSceneTreeNode, | ||
OperateTranslationGizmoSceneViewEditorService.unsafeGetTranslationWholeGizmo( | ||
editorState, | ||
), | ||
coordinateSystem, | ||
) | ||
|> rotateWholeGizmoToCurrentSceneTreeNode( | ||
currentSceneTreeNode, | ||
OperateRotationGizmoSceneViewEditorService.unsafeGetRotationWholeGizmo( | ||
editorState, | ||
), | ||
coordinateSystem, | ||
); | ||
}; |
Oops, something went wrong.