Skip to content
Permalink
Browse files

feat(asset): convert,assemble,generate add "gameObject->isActive, scr…

…ipt->isActive, meshRenderer->isRender"
  • Loading branch information...
yyc-git committed Apr 13, 2019
1 parent d772512 commit 83603b8a8622a3c40f1f9683c1c785bb5b86e5f1
Showing with 797 additions and 147 deletions.
  1. +1 −0 src/asset/assemble/BatchOperateStreamSystem.re
  2. +36 −15 src/asset/assemble/BatchOperateSystem.re
  3. +1 −0 src/asset/assemble/BatchOperateWholeSystem.re
  4. +10 −0 src/asset/assemble/utils/AssembleIsActiveUtils.re
  5. +1 −0 src/asset/converter/ConvertDefaultMaterialSystem.re
  6. +10 −1 src/asset/converter/ConvertGLTFJsonToRecordSystem.re
  7. +19 −1 src/asset/converter/ConvertGameObjectsSystem.re
  8. +6 −2 src/asset/converter/ConvertMeshRenderersSystem.re
  9. +2 −1 src/asset/data/CommonAssetType.re
  10. +5 −1 src/asset/data/GLTFType.re
  11. +6 −1 src/asset/data/GenerateSceneGraphType.re
  12. +5 −1 src/asset/data/WDType.re
  13. +5 −0 src/asset/generate/BuildMeshRendererDataSystem.re
  14. +2 −0 src/asset/generate/BuildScriptDataSystem.re
  15. +14 −3 src/asset/generate/EncodeGLBJsonSystem.re
  16. +7 −4 src/asset/generate/node/AddNodeDataSystem.re
  17. +6 −1 src/asset/generate/node/GetNodeDataSystem.re
  18. +32 −38 src/service/state/main/meshRenderer/AddMeshRendererMainService.re
  19. +84 −0 test/integration/no_worker/asset/assemble/assembleWDBFromGLB_test.re
  20. +214 −33 test/integration/no_worker/asset/convert/convertGLBToWDB_test.re
  21. +39 −2 test/integration/no_worker/asset/generate/generateSceneGraphByGLB_test.re
  22. +159 −4 test/integration/no_worker/asset/generate/generateSceneGraphByGameObject_test.re
  23. +37 −32 test/integration/no_worker/asset/tool/AssembleWDBSystemTool.re
  24. +51 −4 test/integration/no_worker/asset/tool/ConvertGLBTool.re
  25. +45 −3 test/unit/ecs/component/meshRenderer/MeshRenderer_test.re
@@ -65,6 +65,7 @@ let batchOperate =
(gameObjects, basicSourceTextures),
(geometrys, geometryArr),
)
|> BatchOperateSystem.batchSetIsActive(gameObjectArr, gameObjects)
|> BatchOperateSystem.batchSetIsRoot(gameObjectArr, gameObjects);

let (
@@ -416,15 +416,19 @@ let batchSetMeshRendererData = ({meshRenderers}, meshRendererArr, state) =>
meshRendererData |> OptionService.isJsonSerializedValueNone ?
state :
{
let {drawMode} =
let {drawMode, isRender} =
meshRendererData |> OptionService.unsafeGetJsonSerializedValue;
let meshRenderer = meshRendererArr[index];

OperateMeshRendererMainService.setDrawMode(
meshRenderer,
drawMode |> DrawModeType.drawModeToUint8,
state,
);
state
|> OperateMeshRendererMainService.setDrawMode(
meshRenderer,
drawMode |> DrawModeType.drawModeToUint8,
)
|> OperateMeshRendererMainService.setIsRender(
meshRenderer,
isRender,
);
},
state,
);
@@ -460,10 +464,15 @@ let batchSetLightMaterialData = ({lightMaterials}, lightMaterialArr, state) =>
let batchSetScriptData = ({scripts}, scriptArr, state) =>
scripts
|> WonderCommonlib.ArrayService.reduceOneParami(
(. state, {eventFunctionDataMap, attributeMap}: script, index) => {
(.
state,
{isActive, eventFunctionDataMap, attributeMap}: script,
index,
) => {
let script = scriptArr[index];

state
|> IsActiveScriptMainService.setIsActive(script, isActive)
|> OperateScriptDataMainService.addEventFunctionDataMap(
script,
ConvertScriptDataUtils.convertEventFunctionDataMapJsonToRecord(
@@ -533,6 +542,26 @@ let batchSetNames =
|> _batchSetTextureName(basicSourceTextureArr, basicSourceTextures)
|> _batchSetGeometryName(geometrys, geometryArr);

let batchSetIsActive = (gameObjectArr, gameObjects: WDType.gameObjects, state) =>
gameObjectArr
|> WonderCommonlib.ArrayService.reduceOneParami(
(. state, gameObject, index) =>
AssembleIsActiveUtils.doesGameObjectHasIsActiveData(
index,
gameObjects,
) ?
SetIsActiveGameObjectMainService.setIsActive(
gameObject,
AssembleIsActiveUtils.unsafeGetGameObjectIsActiveData(
index,
gameObjects,
),
state,
) :
state,
state,
);

let batchSetIsRoot = (gameObjectArr, gameObjects: WDType.gameObjects, state) =>
gameObjectArr
|> WonderCommonlib.ArrayService.reduceOneParami(
@@ -547,13 +576,5 @@ let batchSetIsRoot = (gameObjectArr, gameObjects: WDType.gameObjects, state) =>
state,
) :
state,
/* switch (
gameObjects.isRoots
|> WonderCommonlib.MutableSparseMapService.get(index)
) {
| Some(isRoot) =>
IsRootGameObjectMainService.setIsRoot(. gameObject, isRoot, state)
| None => state
}, */
state,
);
@@ -265,6 +265,7 @@ let batchOperate =
(gameObjects, basicSourceTextures),
(geometrys, geometryArr),
)
|> BatchOperateSystem.batchSetIsActive(gameObjectArr, gameObjects)
|> BatchOperateSystem.batchSetIsRoot(gameObjectArr, gameObjects);

let (
@@ -0,0 +1,10 @@
let doesGameObjectHasIsActiveData =
(gameObjectIndex, gameObjects: WDType.gameObjects) =>
gameObjects.isActives
|> WonderCommonlib.MutableSparseMapService.get(gameObjectIndex)
|> Js.Option.isSome;

let unsafeGetGameObjectIsActiveData =
(gameObjectIndex, gameObjects: WDType.gameObjects) =>
gameObjects.isActives
|> WonderCommonlib.MutableSparseMapService.unsafeGet(gameObjectIndex);
@@ -68,6 +68,7 @@ let _setDefaultMaterial =
lightMaterial: Some(defaultMaterialIndex),
cameraController: None,
script: None,
isActive: None,
isRoot: None,
})
| Some(extras) =>
@@ -265,7 +265,10 @@ let _convertExtras = json =>
"meshRenderers",
array(json =>
(
{drawMode: json |> field("drawMode", int)}: meshRenderer
{
drawMode: json |> field("drawMode", int),
isRender: json |> field("isRender", bool),
}: meshRenderer
)
),
),
@@ -296,6 +299,7 @@ let _convertExtras = json =>
(
/* WonderLog.Log.print(json) |> ignore; */
{
isActive: json |> field("isActive", bool),
eventFunctionDataMap:
_getScriptMap("eventFunctionDataMap", json),
/* json
@@ -568,6 +572,11 @@ let _convertNodes = json =>
script:
json
|> optimizedOptional(optimizedField("script", int)),
isActive:
json
|> optimizedOptional(
optimizedField("isActive", bool),
),
isRoot:
json
|> optimizedOptional(optimizedField("isRoot", bool)),
@@ -22,6 +22,23 @@ let _getNames = ({nodes, meshes}: GLTFType.gltf) =>
[||],
);

let _getIsActives = ({nodes, meshes}: GLTFType.gltf) =>
nodes
|> WonderCommonlib.ArrayService.reduceOneParami(
(. isActiveMap, {extras}: GLTFType.node, index) =>
switch (extras) {
| None => isActiveMap
| Some(({isActive}: GLTFType.nodeExtras)) =>
switch (isActive) {
| None => isActiveMap
| Some(isActive) =>
isActiveMap
|> WonderCommonlib.MutableSparseMapService.set(index, isActive)
}
},
WonderCommonlib.MutableSparseMapService.createEmpty(),
);

let _getIsRoots = ({nodes, meshes}: GLTFType.gltf) =>
nodes
|> WonderCommonlib.ArrayService.reduceOneParami(
@@ -39,8 +56,9 @@ let _getIsRoots = ({nodes, meshes}: GLTFType.gltf) =>
WonderCommonlib.MutableSparseMapService.createEmpty(),
);

let convert = (({nodes}: GLTFType.gltf) as gltf) : WDType.gameObjects => {
let convert = (({nodes}: GLTFType.gltf) as gltf): WDType.gameObjects => {
count: ConvertCommon.getCount(nodes),
names: _getNames(gltf),
isActives: _getIsActives(gltf),
isRoots: _getIsRoots(gltf),
};
@@ -23,6 +23,7 @@ let _convertByMesh = (meshes, geometryGameObjectIndices, geometryIndices) =>
| Some(6) => DrawModeType.Triangle_fan
| None => DrawModeType.Triangles
},
isRender: true,
}: WDType.meshRenderer,
) :
None;
@@ -43,11 +44,14 @@ let convertToMeshRenderers =
| Some(meshRenderers) when Js.Array.length(meshRenderers) > 0 =>
meshRenderers
|> WonderCommonlib.ArrayService.reduceOneParami(
(. arr, {drawMode}: GLTFType.meshRenderer, index) =>
(. arr, {drawMode, isRender}: GLTFType.meshRenderer, index) =>
arr
|> ArrayService.push(
Some(
{drawMode: drawMode |> DrawModeType.uint8ToDrawMode}: WDType.meshRenderer,
{
drawMode: drawMode |> DrawModeType.uint8ToDrawMode,
isRender,
}: WDType.meshRenderer,
),
),
[||],
@@ -1,4 +1,5 @@
type script = {
isActive: bool,
eventFunctionDataMap: Js.Dict.t(string),
attributeMap: Js.Dict.t(string),
};
};
@@ -195,6 +195,7 @@ type nodeExtras = {
cameraController: option(cameraControllerIndex),
script: option(scriptIndex),
isRoot: option(bool),
isActive: option(bool),
};

type nodeKHRLightsExtension = {light: int};
@@ -249,7 +250,10 @@ type khrLightsExtension = {lights: array(light)};

type extensions = {khr_lights: option(khrLightsExtension)};

type meshRenderer = {drawMode: Js.Typed_array.Uint8Array.elt};
type meshRenderer = {
drawMode: Js.Typed_array.Uint8Array.elt,
isRender: bool,
};

type basicCameraView = {isActive: bool};

@@ -5,6 +5,7 @@ type nodeExtras = {
lightMaterial: option(int),
cameraController: option(int),
script: option(int),
isActive: option(bool),
isRoot: option(bool),
};

@@ -75,7 +76,10 @@ type imageData = {
byteOffset: int,
};

type meshRendererData = {drawMode: Js.Typed_array.Uint8Array.elt};
type meshRendererData = {
drawMode: Js.Typed_array.Uint8Array.elt,
isRender: bool,
};

type basicMaterialData = {
colorFactor: option(array(float)),
@@ -115,6 +119,7 @@ type lightData = {
};

type scriptData = {
isActive: bool,
eventFunctionDataMapStr: string,
attributeMapStr: string,
};
@@ -41,6 +41,7 @@ type gameObjects = {
count: int,
names: array(string),
isRoots: WonderCommonlib.MutableSparseMapService.t(bool),
isActives: WonderCommonlib.MutableSparseMapService.t(bool),
};

type transform = {
@@ -49,7 +50,10 @@ type transform = {
scale: option((float, float, float)),
};

type meshRenderer = {drawMode: DrawModeType.drawMode};
type meshRenderer = {
drawMode: DrawModeType.drawMode,
isRender: bool,
};

type geometry = {
name: string,
@@ -22,6 +22,11 @@ let build = (meshRendererDataMap, state) => {
meshRenderer,
state,
),
isRender:
OperateMeshRendererMainService.getIsRender(
meshRenderer,
state,
),
}: GenerateSceneGraphType.meshRendererData,
),
[||],
@@ -17,6 +17,8 @@ let build = (scriptDataMap, {scriptRecord} as state) => {
scriptDataArr
|> ArrayService.push(
{
isActive:
IsActiveScriptMainService.unsafeGetIsActive(script, state),
eventFunctionDataMapStr:
ConvertScriptDataUtils.unsafeGetEventFunctionDataMapStr(
script,
@@ -91,6 +91,7 @@ let _encodeNodeExtras = (extras, list) =>
lightMaterial,
cameraController,
script,
isActive,
isRoot,
}: nodeExtras
),
@@ -107,6 +108,12 @@ let _encodeNodeExtras = (extras, list) =>
let extraList =
_encodeNodeMaterial(basicMaterial, lightMaterial, extraList);

let extraList =
switch (isActive) {
| None => extraList
| Some(isActive) => [("isActive", isActive |> bool), ...extraList]
};

let extraList =
switch (isRoot) {
| None => extraList
@@ -214,8 +221,9 @@ let _encodeMeshRendererExtra = (meshRendererDataArr, extraList) =>
(
"meshRenderers",
meshRendererDataArr
|> Js.Array.map((({drawMode}: meshRendererData) as data) =>
[("drawMode", drawMode |> int)] |> object_
|> Js.Array.map((({isRender, drawMode}: meshRendererData) as data) =>
[("isRender", isRender |> bool), ("drawMode", drawMode |> int)]
|> object_
)
|> jsonArray,
),
@@ -312,9 +320,12 @@ let _encodeScriptExtra = (scriptDataArr, extraList) =>
scriptDataArr
|> Js.Array.map(
(
({eventFunctionDataMapStr, attributeMapStr}: scriptData) as data,
(
{isActive, eventFunctionDataMapStr, attributeMapStr}: scriptData
) as data,
) =>
[
("isActive", isActive |> bool),
(
"eventFunctionDataMap",
eventFunctionDataMapStr |> Js.Json.parseExn,

0 comments on commit 83603b8

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