Skip to content
Permalink
Browse files

feat(inspectorCanvas): fix MaterialInspector->update snapshot bug

description
1.add material;
2.select m1;
3.load wdb;

m1->snapshot is updated to empty!!!

reason
when load wdb, trigger MaterialInspector->willUnmount->update snapshot. but at this time, the container is empty(has generate wdb related snapshots and clear container before).

solution
MaterialInspector->willUnmount add judge:
only if material sphere is in container(add in didMount), update snapshot.
  • Loading branch information...
yyc-git committed May 29, 2019
1 parent 688a223 commit b6d3a647581d65835f1213f96405295595a37067
@@ -27,7 +27,7 @@ let _createAllMaterialSnapshot =
engineState,
(editorState, inspectorEngineState),
) => {
let (editorState, inspectorEngineState) =
let (editorState, (inspectorEngineState, _)) =
(editorState, inspectorEngineState)
|> InspectorCanvasUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> MaterialInspectorEngineUtils.createMaterialSphereIntoInspectorCanvas(
@@ -655,7 +655,7 @@ module AssetTree = {
~engineState,
);

let (editorState, inspectorEngineState) =
let (editorState, (inspectorEngineState, _)) =
(editorState, inspectorEngineState)
|> InspectorCanvasUtils.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory
|> MaterialInspectorEngineUtils.createMaterialSphereIntoInspectorCanvas(
@@ -11,7 +11,7 @@ module Method = {

Console.tryCatch(
() => {
let (editorState, inspectorEngineState) =
let (editorState, (inspectorEngineState, sphere)) =
MaterialInspectorEngineUtils.createMaterialSphereIntoInspectorCanvas(
type_,
materialComponent,
@@ -20,30 +20,40 @@ module Method = {
StateInspectorEngineService.unsafeGetState(),
);

editorState |> StateEditorService.setState |> ignore;
editorState
|> MaterialSphereInspectorCanvasEditorService.setMaterialSphereGameObjectInInspectorCanvas(
sphere,
)
|> StateEditorService.setState
|> ignore;
inspectorEngineState |> StateLogicService.refreshInspectorEngineState;
},
e => Console.throwFatal(e) |> ignore,
);
};

let _doesUpdateSnapshot =
(currentNodeId, (editorState, inspectorEngineState)) =>
OperateTreeAssetEditorService.isNodeExistById(currentNodeId, editorState)
&& MaterialSphereInspectorCanvasEditorService.isExistInContainer(
editorState,
inspectorEngineState,
);

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

InspectorCanvasUtils.hideInspectorCanvas();

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

OperateTreeAssetEditorService.isNodeExistById(currentNodeId)
|> StateLogicService.getEditorState ?
_doesUpdateSnapshot(
currentNodeId,
(
StateEditorService.getState(),
StateInspectorEngineService.unsafeGetState(),
),
) ?
InspectorCanvasUtils.updateSnapshot(
currentNodeId,
(
@@ -52,6 +62,17 @@ module Method = {
),
) :
();

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

MaterialSphereInspectorCanvasEditorService.removeMaterialSphereGameObjectInInspectorCanvas
|> StateLogicService.getAndSetEditorState;
};
};

@@ -6,9 +6,12 @@ let _createSphereWithClonedMaterial =
inspectorEngineState
|> PrimitiveEngineService.createSphere(material, addMaterialFunc);

inspectorEngineState
|> GameObjectEngineService.initGameObject(sphere)
|> HierarchyGameObjectEngineService.addChild(containerGameObject, sphere);
(
inspectorEngineState
|> GameObjectEngineService.initGameObject(sphere)
|> HierarchyGameObjectEngineService.addChild(containerGameObject, sphere),
sphere,
);
};

let _createBasicMaterialSphereIntoInspectorCanvas =
@@ -3,5 +3,9 @@ type clonedBasicSourceTextureInInspectorEngineState = Wonderjs.BasicSourceTextur
type inspectorCanvasRecord = {
containerGameObject: option(int),
basicSourceTextureCacheMap:
WonderCommonlib.ImmutableSparseMapService.t(clonedBasicSourceTextureInInspectorEngineState),
WonderCommonlib.ImmutableSparseMapService.t(
clonedBasicSourceTextureInInspectorEngineState,
),
materialSphereGameObjectInInspectorCanvas:
option(Wonderjs.GameObjectPrimitiveType.gameObject),
};
@@ -5,6 +5,7 @@ let create = () => {
containerGameObject: None,
basicSourceTextureCacheMap:
WonderCommonlib.ImmutableSparseMapService.createEmpty(),
materialSphereGameObjectInInspectorCanvas: None,
},
imgCanvasRecord: {
imgContext: None,
@@ -0,0 +1,36 @@
open EditorType;

let getMaterialSphereGameObjectInInspectorCanvas = editorState =>
editorState.inspectorCanvasRecord.materialSphereGameObjectInInspectorCanvas;

let setMaterialSphereGameObjectInInspectorCanvas =
(materialSphereGameObjectInInspectorCanvas, editorState) => {
...editorState,
inspectorCanvasRecord: {
...editorState.inspectorCanvasRecord,
materialSphereGameObjectInInspectorCanvas:
Some(materialSphereGameObjectInInspectorCanvas),
},
};

let removeMaterialSphereGameObjectInInspectorCanvas = editorState => {
...editorState,
inspectorCanvasRecord: {
...editorState.inspectorCanvasRecord,
materialSphereGameObjectInInspectorCanvas: None,
},
};

let isExistInContainer = (editorState, inspectorEngineState) =>
switch (getMaterialSphereGameObjectInInspectorCanvas(editorState)) {
| None => false
| Some(materialSphereGameObjectInInspectorCanvas) =>
HierarchyGameObjectEngineService.findGameObjectByUid(
materialSphereGameObjectInInspectorCanvas,
ContainerGameObjectInspectorCanvasEditorService.unsafeGetContainerGameObject(
editorState,
),
inspectorEngineState,
)
|> Js.Option.isSome
};
@@ -113,3 +113,8 @@ let getChildren = (gameObject, engineState) =>

let hasChildren = (gameObject, engineState) =>
getChildren(gameObject, engineState) |> Js.Array.length > 0;

let findGameObjectByUid = (uid, parentGameObject, engineState) =>
engineState
|> getAllGameObjects(parentGameObject)
|> Js.Array.find(gameObject => gameObject === uid);
@@ -32,7 +32,7 @@ let _ =
(),
);

let (editorState, inspectorEngineState) =
let (editorState, (inspectorEngineState, _)) =
inspectorEngineState
|> MaterialInspectorEngineUtils.createMaterialSphereIntoInspectorCanvas(
MaterialDataAssetType.BasicMaterial,
@@ -12,7 +12,7 @@ let prepareMaterialSphere = inspectorEngineState => {
let (addedMaterialNodeId, newMaterialComponent) =
MaterialInspectorCanvasTool.createNewMaterial();

let (editorState, inspectorEngineState) =
let (editorState, (inspectorEngineState, _)) =
inspectorEngineState
|> MaterialInspectorEngineUtils.createMaterialSphereIntoInspectorCanvas(
MaterialDataAssetType.LightMaterial,
@@ -369,11 +369,6 @@ let _ =
"if material is removed, not create material sphere's snapshot", () => {
NoWorkerJobTool.initStateWithDisposeJob(~sandbox, ());
MainEditorSceneTool.prepareScene(sandbox);
let _ =
InspectorCanvasTool.prepareInspectorAndImgCanvasAndReturnAllData(
~sandbox,
(),
);
let (addedMaterialNodeId, materialComponent) =
MaterialInspectorCanvasTool.createNewMaterial();

@@ -383,13 +378,22 @@ let _ =
);
_willUnmount(addedMaterialNodeId);

let editorState = StateEditorService.getState();
let imgContext =
editorState |> ImgContextImgCanvasEditorService.unsafeGetImgContext;
CanvasType.convertContextToJsObj(imgContext)##clearRect
|> expect
|> not_
|> toCalled;
InspectorCanvasTool.Material.judgeNotCreateMaterialSphere();
});
test(
"if material sphere not in container, not create material sphere's snapshot",
() => {
let (addedMaterialNodeId, materialComponent) =
MaterialInspectorCanvasTool.createNewMaterial();

MaterialInspectorTool.didMount(
MaterialDataAssetType.LightMaterial,
materialComponent,
);
InspectorCanvasTool.disposeContainerGameObjectAllChildrenAndReallocateCPUMemory();
_willUnmount(addedMaterialNodeId);

InspectorCanvasTool.Material.judgeNotCreateMaterialSphere();
});

describe("else, create material sphere's snapshot", () => {
@@ -14,8 +14,6 @@ let changeMaterialType =
(sourceMaterialType, targetMaterialType),
);

let createMaterialSphereInToInspectorCanvas = MaterialInspectorEngineUtils.createMaterialSphereIntoInspectorCanvas;

let didMount = MaterialInspector.Method.didMount;

let willUnmount = MaterialInspector.Method.willUnmount;
@@ -90,6 +90,31 @@ let prepareInspectorEngineState = sandbox => {
|> StateLogicService.getAndSetInspectorEngineState;
};

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

module Material = {
let judgeNotCreateMaterialSphere = () => {
open Wonder_jest;
open Expect;
open Sinon;

let editorState = StateEditorService.getState();
let imgContext =
editorState |> ImgContextImgCanvasEditorService.unsafeGetImgContext;
CanvasType.convertContextToJsObj(imgContext)##clearRect
|> expect
|> not_
|> toCalled;
};
};

module ArcballCameraController = {
let unsafeGetArcballCameraControllerComponent = inspectorEngineState =>
GameObjectComponentEngineService.unsafeGetArcballCameraControllerComponent(

0 comments on commit b6d3a64

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