Skip to content

Commit

Permalink
fix(asset): fix "remove material asset":1.remove instead of dispose m…
Browse files Browse the repository at this point in the history
…aterial->maps; 2.if material has no gameObjects, dispose material;

update wonder.js version
  • Loading branch information
yyc-git committed May 27, 2019
1 parent 51a9e19 commit d81994f
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 201 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"wonder-commonlib": "^0.2.32",
"wonder-hotkey": "^0.0.1",
"wonder-log": "^0.2.11",
"wonder.js": "1.1.0-alpha.9"
"wonder.js": "1.1.0-alpha.10"
},
"resolutions": {
"wonder-log": "^0.2.11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let replaceMaterialByMaterialType =
};

let engineState =
InspectorRenderGroupUtils.Dispose.replaceGameObjectsMaterialsOfTheMaterial(
InspectorRenderGroupUtils.Dispose.disposeMaterialOrReplaceGameObjectsMaterialsOfTheMaterial(
(
(sourceMaterial, targetMaterial),
(sourceMaterialType, targetMaterialType),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,30 +109,30 @@ module Remove = {
};

/* let replaceMaterialByMaterialType =
(gameObject, sourceMateralType, targetMaterialType, engineState) => {
let (sourceRenderGroup, removeSourceMaterialFunc) =
_getOperateSourceRenderGroupData(
sourceMateralType,
gameObject,
engineState,
);
(gameObject, sourceMateralType, targetMaterialType, engineState) => {
let (sourceRenderGroup, removeSourceMaterialFunc) =
_getOperateSourceRenderGroupData(
sourceMateralType,
gameObject,
engineState,
);
let (engineState, targetRenderGroup, addTargetMaterialFunc) =
_getOperateTargetRenderGroupData(
sourceRenderGroup.meshRenderer,
targetMaterialType,
engineState,
);
let (engineState, targetRenderGroup, addTargetMaterialFunc) =
_getOperateTargetRenderGroupData(
sourceRenderGroup.meshRenderer,
targetMaterialType,
engineState,
);
engineState
|> RenderGroupEngineService.replaceMaterial(
(sourceRenderGroup, targetRenderGroup),
gameObject,
(removeSourceMaterialFunc, addTargetMaterialFunc),
);
engineState
|> RenderGroupEngineService.replaceMaterial(
(sourceRenderGroup, targetRenderGroup),
gameObject,
(removeSourceMaterialFunc, addTargetMaterialFunc),
);
engineState;
}; */
engineState;
}; */

let replaceMaterialByMaterialData =
(
Expand Down Expand Up @@ -177,6 +177,12 @@ module Remove = {
};

module Dispose = {
let _getDisposeMaterialFunc = materialType =>
switch (materialType) {
| BasicMaterial => BasicMaterialEngineService.disposeBasicMaterial
| LightMaterial => LightMaterialEngineService.disposeLightMaterialRemoveTexture
};

let _getOperateSourceRenderGroupData =
(meshRenderer, material, materialType, engineState) =>
switch (materialType) {
Expand All @@ -186,7 +192,7 @@ module Dispose = {
)
| LightMaterial => (
RenderGroupEngineService.buildRenderGroup(meshRenderer, material),
GameObjectComponentEngineService.disposeLightMaterialComponent,
GameObjectComponentEngineService.disposeLightMaterialComponentRemoveTexture,
)
};

Expand Down Expand Up @@ -244,7 +250,7 @@ module Dispose = {
);
};

let replaceGameObjectsMaterialsOfTheMaterial =
let disposeMaterialOrReplaceGameObjectsMaterialsOfTheMaterial =
(
(
(sourceMaterial, targetMaterial),
Expand All @@ -259,10 +265,14 @@ module Dispose = {
engineState,
)
) {
| None => engineState
| None =>
let disposeMaterialFunc = _getDisposeMaterialFunc(sourceMaterialType);

disposeMaterialFunc(sourceMaterial, engineState);
| Some(gameObjects) =>
let engineState =
gameObjects
|> WonderLog.Log.print
|> WonderCommonlib.ArrayService.reduceOneParam(
(. engineState, gameObject) =>
replaceMaterial(
Expand Down
90 changes: 0 additions & 90 deletions src/service/state/editor/asset/RemoveNodeAssetEditorService.re

This file was deleted.

5 changes: 4 additions & 1 deletion src/service/state/engine/BasicMaterialEngineService.re
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ let reInitBasicMaterialsAndClearShaderCache = (materials, engineState) =>

let getAllBasicMaterials = BasicMaterialAPI.getAllBasicMaterials;

let batchDisposeBasicMaterial = BasicMaterialAPI.batchDisposeBasicMaterial;
let batchDisposeBasicMaterial = BasicMaterialAPI.batchDisposeBasicMaterial;

let disposeBasicMaterial = (material, state) =>
batchDisposeBasicMaterial([|material|], state);
8 changes: 8 additions & 0 deletions src/service/state/engine/LightMaterialEngineService.re
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ let getAllLightMaterials = LightMaterialAPI.getAllLightMaterials;

let batchDisposeLightMaterial = LightMaterialAPI.batchDisposeLightMaterial;

let batchDisposeLightMaterialRemoveTexture = LightMaterialAPI.batchDisposeLightMaterialRemoveTexture;

let disposeLightMaterial = (material, state) =>
batchDisposeLightMaterial([|material|], state);

let disposeLightMaterialRemoveTexture = (material, state) =>
batchDisposeLightMaterialRemoveTexture([|material|], state);

let createLightMaterialAndSetName = (materialName, engineState) => {
let (engineState, material) = engineState |> create;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ let addLightMaterialComponent = GameObjectAPI.addGameObjectLightMaterialComponen

let disposeLightMaterialComponent = GameObjectAPI.disposeGameObjectLightMaterialComponent;

let disposeLightMaterialComponentRemoveTexture = GameObjectAPI.disposeGameObjectLightMaterialComponentRemoveTexture;

let removeLightMaterialComponent = GameObjectAPI.removeGameObjectLightMaterialComponent;

/* basic material */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ let _disposeMaterialNodeEngineData =
editorState,
);

InspectorRenderGroupUtils.Dispose.replaceGameObjectsMaterialsOfTheMaterial(

WonderLog.Log.print(( "_disposeMaterialNodeEngineData", materialComponent)) |> ignore;

InspectorRenderGroupUtils.Dispose.disposeMaterialOrReplaceGameObjectsMaterialsOfTheMaterial(
((materialComponent, defaultMaterial), (type_, defaultMaterialType)),
engineState,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MainEditorAssetHeader->remove material
select material;
click remove-button;
should remove it from assetTreeRoot 1`] = `
<article
className="wonder-asset-assetChildren"
/>
`;

exports[`MainEditorAssetHeader->remove material else, replace material's gameObjects' material to default material
add material m1;
select sceneTree->gameObject g1;
g1 change material to m1;
Expand Down Expand Up @@ -213,7 +222,7 @@ exports[`MainEditorAssetHeader->remove material
</article>
`;

exports[`MainEditorAssetHeader->remove material
exports[`MainEditorAssetHeader->remove material else, replace material's gameObjects' material to default material
add material m1;
select sceneTree->gameObject g1;
g1 change material to m1;
Expand Down Expand Up @@ -425,12 +434,3 @@ exports[`MainEditorAssetHeader->remove material
</div>
</article>
`;

exports[`MainEditorAssetHeader->remove material
select material;
click remove-button;
should remove it from assetTreeRoot 1`] = `
<article
className="wonder-asset-assetChildren"
/>
`;
Loading

0 comments on commit d81994f

Please sign in to comment.