Skip to content
Permalink
Browse files

feat(inspectorCanvas): fix:restore arcball camera controller->angle b…

…efore update snapshot
  • Loading branch information...
yyc-git committed May 29, 2019
1 parent 7912f99 commit 62c8c40fffde9ee6aaead1aa27a9d31383630df9
Showing with 395 additions and 117 deletions.
  1. +1 −1 ...ble_component/asset/composable_component/header/eventHandler/AssetHeaderRemoveNodeEventHandler.re
  2. +2 −1 ...roject/composable_component/asset/composable_component/header/utils/AssetHeaderRemoveNodeUtils.re
  3. +3 −2 ...oject/composable_component/asset/composable_component/header/utils/ExtractAndRelateAssetsUtils.re
  4. +15 −18 ...omposable_component/assetTree_Inspector/atom_component/material_Inspector/ui/MaterialInspector.re
  5. +18 −21 ...nspector/composable_component/assetTree_Inspector/atom_component/wdb_inspector/ui/WDBInspector.re
  6. +2 −5 ...sable_component/assetTree_Inspector/atom_component/wdb_inspector/utils/WDBInspectorEngineUtils.re
  7. +0 −45 ...ble_component/inspector/composable_component/assetTree_Inspector/utils/AssetTreeInspectorUtils.re
  8. +85 −0 ...osable_component/inspector/composable_component/assetTree_Inspector/utils/InspectorCanvasUtils.re
  9. +1 −1 src/core/composable_component/mainEditor/ui/MainEditor.re
  10. +2 −5 src/core/utils/inspectorEngine/DefaultSceneInspectorEngineUtils.re
  11. +6 −4 src/service/stateTuple/logic/asset/WDBAssetLogicService.re
  12. +36 −3 test/integration/asset/composable_component/header/mainEditorAssetHeaderLoadWDB_test.re
  13. +75 −1 ...t/assetTree_inspector/atom_component/material_inspector/materialInspector_inspectorCanvas_test.re
  14. +89 −6 ...e_component/assetTree_inspector/atom_component/wdb_inspector/wdbInspector_inspectorCanvas_test.re
  15. +60 −4 test/integration/inspector/composable_component/assetTree_inspector/tool/InspectorCanvasTool.re
@@ -68,7 +68,7 @@ module CustomEventHandler = {
);

(editorState, inspectorEngineState)
|> AssetTreeInspectorUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> InspectorCanvasUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> StateInspectorEngineService.setState
|> ignore;

@@ -29,7 +29,7 @@ let _createAllMaterialSnapshot =
) => {
let (editorState, inspectorEngineState) =
(editorState, inspectorEngineState)
|> AssetTreeInspectorUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> InspectorCanvasUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> MaterialInspectorEngineUtils.createMaterialSphereIntoInspectorCanvas(
MaterialDataAssetType.LightMaterial,
material,
@@ -39,6 +39,7 @@ let _createAllMaterialSnapshot =

let inspectorEngineState =
inspectorEngineState
|> InspectorCanvasUtils.restoreArcballCameraControllerAngle
|> StateLogicService.renderInspectorEngineStateAndReturnState;

let editorState =
@@ -657,7 +657,7 @@ module AssetTree = {

let (editorState, inspectorEngineState) =
(editorState, inspectorEngineState)
|> AssetTreeInspectorUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> InspectorCanvasUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> MaterialInspectorEngineUtils.createMaterialSphereIntoInspectorCanvas(
MaterialDataAssetType.LightMaterial,
material,
@@ -667,6 +667,7 @@ module AssetTree = {

let inspectorEngineState =
inspectorEngineState
|> InspectorCanvasUtils.restoreArcballCameraControllerAngle
|> StateLogicService.renderInspectorEngineStateAndReturnState;

let editorState =
@@ -711,7 +712,7 @@ module AssetTree = {
);

(editorState, inspectorEngineState)
|> AssetTreeInspectorUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> InspectorCanvasUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> StateInspectorEngineService.setState;

(editorState, engineState);
@@ -7,7 +7,7 @@ module Method = {
let changeMaterialType = InspectorChangeMaterialTypeEventHandler.MakeEventHandler.pushUndoStackWithNoCopyEngineState;

let didMount = (type_, materialComponent) => {
AssetTreeInspectorUtils.showInspectorCanvas();
InspectorCanvasUtils.showInspectorCanvas();

Console.tryCatch(
() => {
@@ -27,34 +27,31 @@ module Method = {
);
};

let _updateSnapshot = (currentNodeId, dispatchFunc) => {
StateEditorService.getState()
|> ImgCanvasUtils.clipTargetCanvasSnapshotAndSetToImageDataMapByMaterialNodeId(
DomHelper.getElementById("inspector-canvas"),
DomHelper.getElementById("img-canvas"),
currentNodeId,
)
|> StateEditorService.setState
|> ignore;

dispatchFunc(AppStore.UpdateAction(Update([|UpdateStore.Project|])))
|> ignore;
};

let willUnmount = (currentNodeId, dispatchFunc) => {
AssetTreeInspectorUtils.hideInspectorCanvas();
InspectorCanvasUtils.restoreArcballCameraControllerAngle
|> StateLogicService.getInspectorEngineStateToGetData
|> StateLogicService.refreshInspectorEngineState;

InspectorCanvasUtils.hideInspectorCanvas();

(
StateEditorService.getState(),
StateInspectorEngineService.unsafeGetState(),
)
|> AssetTreeInspectorUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> InspectorCanvasUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> StateInspectorEngineService.setState
|> ignore;

OperateTreeAssetEditorService.isNodeExistById(currentNodeId)
|> StateLogicService.getEditorState ?
_updateSnapshot(currentNodeId, dispatchFunc) : ();
InspectorCanvasUtils.updateSnapshot(
currentNodeId,
(
ImgCanvasUtils.clipTargetCanvasSnapshotAndSetToImageDataMapByMaterialNodeId,
dispatchFunc,
),
) :
();
};
};

@@ -1,24 +1,10 @@
module Method = {
let _updateSnapshot = (currentNodeId, dispatchFunc) => {
StateEditorService.getState()
|> ImgCanvasUtils.clipTargetCanvasSnapshotAndSetToImageDataMapByWDBNodeId(
DomHelper.getElementById("inspector-canvas"),
DomHelper.getElementById("img-canvas"),
currentNodeId,
)
|> StateEditorService.setState
|> ignore;

dispatchFunc(AppStore.UpdateAction(Update([|UpdateStore.Project|])))
|> ignore;
};

let didMount = (currentNodeId, wdbGameObject, dispatchFunc) => {
AssetTreeInspectorUtils.showInspectorCanvas();
InspectorCanvasUtils.showInspectorCanvas();

Console.tryCatch(
() => {
let (editorState, inspectorEngineState) =
let (newWDBGameObject, editorState, inspectorEngineState) =
StateInspectorEngineService.unsafeGetState()
|> WDBInspectorEngineUtils.createWDBIntoInspectorCanvas(
wdbGameObject,
@@ -28,23 +14,34 @@ module Method = {

editorState |> StateEditorService.setState |> ignore;

inspectorEngineState |> StateLogicService.refreshInspectorEngineState;
inspectorEngineState
|> WDBInspectorEngineUtils.setCameraFocusWDBGameObject(
newWDBGameObject,
)
|> InspectorCanvasUtils.restoreArcballCameraControllerAngle
|> StateLogicService.refreshInspectorEngineState;

_updateSnapshot(currentNodeId, dispatchFunc);
InspectorCanvasUtils.updateSnapshot(
currentNodeId,
(
ImgCanvasUtils.clipTargetCanvasSnapshotAndSetToImageDataMapByWDBNodeId,
dispatchFunc,
),
);
},
e => Console.throwFatal(e) |> ignore,
);
};

let willUnmount = () => {
AssetTreeInspectorUtils.hideInspectorCanvas();
InspectorCanvasUtils.hideInspectorCanvas();

(
StateEditorService.getState(),
StateInspectorEngineService.unsafeGetState(),
)
|> AssetTreeInspectorUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> AssetTreeInspectorUtils.setCameraDefaultDistance
|> InspectorCanvasUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> InspectorCanvasUtils.setCameraDefaultDistance
|> StateInspectorEngineService.setState
|> ignore;
};
@@ -42,7 +42,7 @@ let rec _iterateCreateNewWDBGameObject =
(newGameObject, editorState, inspectorEngineState);
};

let _setCameraFocusWDBGameObject = (newWDBGameObject, inspectorEngineState) => {
let setCameraFocusWDBGameObject = (newWDBGameObject, inspectorEngineState) => {
let camera =
GameObjectInspectorEngineService.unsafeGetCamera(inspectorEngineState);

@@ -70,8 +70,5 @@ let createWDBIntoInspectorCanvas =
newWDBGameObject,
);

(
editorState,
inspectorEngineState |> _setCameraFocusWDBGameObject(newWDBGameObject),
);
(newWDBGameObject, editorState, inspectorEngineState);
};

This file was deleted.

@@ -0,0 +1,85 @@
let getCameraDefaultDistance = () => 1.1;

let showInspectorCanvas = () =>
DomHelper.setDomDisplay(
DomHelper.getElementById("inspectorCanvasParent"),
true,
);

let hideInspectorCanvas = () =>
DomHelper.setDomDisplay(
DomHelper.getElementById("inspectorCanvasParent"),
false,
);

let _reallocateCPUMemory =
(inspectorEngineState: Wonderjs.StateDataMainType.state) =>
inspectorEngineState
|> ReallocateCPUMemoryJobEngineService.reallocateGameObjectByDisposeCount
|> ReallocateCPUMemoryJobEngineService.reallocateGeometry(0.5);

let disposeContainerGameObjectAllChildrenAndReallocateCPUMemory =
((editorState, inspectorEngineState: Wonderjs.StateDataMainType.state)) =>
(editorState, inspectorEngineState)
|> InspectorEngineGameObjectLogicService.disposeInspectorEngineContainerGameObjectAllChildren
|> JobEngineService.execDisposeJob
|> _reallocateCPUMemory;

let setCameraDefaultDistance = inspectorEngineState => {
let cameraArcballControllerComponent =
GameObjectComponentEngineService.unsafeGetArcballCameraControllerComponent(
GameObjectInspectorEngineService.unsafeGetCamera(inspectorEngineState),
inspectorEngineState,
);

inspectorEngineState
|> ArcballCameraEngineService.setArcballCameraControllerTarget(
cameraArcballControllerComponent,
(0., 0., 0.),
)
|> ArcballCameraEngineService.setArcballCameraControllerDistance(
getCameraDefaultDistance(),
cameraArcballControllerComponent,
);
};

let initArcballCameraControllerAngle =
(arcballCameraController, inspectorEngineState) =>
inspectorEngineState
|> ArcballCameraEngineService.setArcballCameraControllerTheta(
arcballCameraController,
1.5,
)
|> ArcballCameraEngineService.setArcballCameraControllerPhi(
arcballCameraController,
Js.Math._PI /. 2.,
);

let restoreArcballCameraControllerAngle = inspectorEngineState => {
let cameraArcballControllerComponent =
GameObjectComponentEngineService.unsafeGetArcballCameraControllerComponent(
GameObjectInspectorEngineService.unsafeGetCamera(inspectorEngineState),
inspectorEngineState,
);

inspectorEngineState
|> initArcballCameraControllerAngle(cameraArcballControllerComponent);
};

let updateSnapshot =
(
currentNodeId,
(clipTargetCanvasSnapshotAndSetToImageDataMapFunc, dispatchFunc),
) => {
StateEditorService.getState()
|> clipTargetCanvasSnapshotAndSetToImageDataMapFunc(
DomHelper.getElementById("inspector-canvas"),
DomHelper.getElementById("img-canvas"),
currentNodeId,
)
|> StateEditorService.setState
|> ignore;

dispatchFunc(AppStore.UpdateAction(Update([|UpdateStore.Project|])))
|> ignore;
};
@@ -32,7 +32,7 @@ module Method = {
ResizeUtils.resizeMainCanvasScreen();
ResizeUtils.resizeInspectorCanvasScreen();

AssetTreeInspectorUtils.hideInspectorCanvas();
InspectorCanvasUtils.hideInspectorCanvas();
},
);

@@ -1,7 +1,5 @@
let getAmbientLightArr = () => [|0.2, 0.2, 0.2|];

let getCameraDefaultDistance = () => 1.1;

let _initCameraAddToSceneGameObject = (camera, inspectorEngineState) => {
let (inspectorEngineState, arcballCameraController) =
ArcballCameraEngineService.create(inspectorEngineState);
@@ -15,7 +13,7 @@ let _initCameraAddToSceneGameObject = (camera, inspectorEngineState) => {
),
) */
|> ArcballCameraEngineService.setArcballCameraControllerDistance(
getCameraDefaultDistance(),
InspectorCanvasUtils.getCameraDefaultDistance(),
arcballCameraController,
)
|> ArcballCameraEngineService.setArcballCameraControllerWheelSpeed(
@@ -30,9 +28,8 @@ let _initCameraAddToSceneGameObject = (camera, inspectorEngineState) => {
arcballCameraController,
1.,
)
|> ArcballCameraEngineService.setArcballCameraControllerTheta(
|> InspectorCanvasUtils.initArcballCameraControllerAngle(
arcballCameraController,
1.5,
)
|> ArcballCameraControllerLogicService.bindArcballCameraControllerEventForInspector(
arcballCameraController,
@@ -54,9 +54,9 @@ let createWDBNodeUseImageDataMapSnapshot =

let createWDBNodeUseCreatedSnapshot =
((wdbNodeId, name, gameObject, parentFolderNode), editorState) => {
let (editorState, inspectorEngineState) =
let (newWDBGameObject, editorState, inspectorEngineState) =
(editorState, StateInspectorEngineService.unsafeGetState())
|> AssetTreeInspectorUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> InspectorCanvasUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> WDBInspectorEngineUtils.createWDBIntoInspectorCanvas(
gameObject,
editorState,
@@ -65,6 +65,8 @@ let createWDBNodeUseCreatedSnapshot =

let inspectorEngineState =
inspectorEngineState
|> WDBInspectorEngineUtils.setCameraFocusWDBGameObject(newWDBGameObject)
|> InspectorCanvasUtils.restoreArcballCameraControllerAngle
|> StateLogicService.renderInspectorEngineStateAndReturnState;

let editorState =
@@ -75,8 +77,8 @@ let createWDBNodeUseCreatedSnapshot =
);

(editorState, inspectorEngineState)
|> AssetTreeInspectorUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> AssetTreeInspectorUtils.setCameraDefaultDistance
|> InspectorCanvasUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> InspectorCanvasUtils.setCameraDefaultDistance
|> StateInspectorEngineService.setState;

editorState;

0 comments on commit 62c8c40

Please sign in to comment.
You can’t perform that action at this time.