Skip to content
Permalink
Browse files

feat(asset): wdb add script component data

  • Loading branch information...
yyc-git committed Apr 9, 2019
1 parent 30e0681 commit 5ea3908873c680873dc880484f21087a3ea696f2
Showing with 2,232 additions and 1,285 deletions.
  1. +1 −1 src/api/script/ScriptAPI.re
  2. +12 −12 src/asset/assemble/BatchCreateSystem.re
  3. +9 −0 src/asset/assemble/BatchOperateStreamSystem.re
  4. +33 −0 src/asset/assemble/BatchOperateSystem.re
  5. +9 −0 src/asset/assemble/BatchOperateWholeSystem.re
  6. +7 −7 src/asset/converter/ConvertCamerasSystem.re
  7. +4 −4 src/asset/converter/ConvertDefaultMaterialSystem.re
  8. +4 −1 src/asset/converter/ConvertGLBSystem.re
  9. +32 −1 src/asset/converter/ConvertGLTFJsonToRecordSystem.re
  10. +9 −0 src/asset/converter/ConvertScriptsSystem.re
  11. +28 −0 src/asset/converter/indices/gameObject/ConvertComponentIndexDataSystem.re
  12. +5 −1 src/asset/converter/indices/gameObject/ConvertGameObjectIndexDataSystem.re
  13. +4 −0 src/asset/data/CommonAssetType.re
  14. +20 −6 src/asset/data/GLTFType.re
  15. +12 −4 src/asset/data/GenerateSceneGraphType.re
  16. +4 −0 src/asset/data/WDType.re
  17. +53 −0 src/asset/generate/BuildScriptDataSystem.re
  18. +39 −24 src/asset/generate/EncodeGLBJsonSystem.re
  19. +4 −0 src/asset/generate/GenerateGLBSystem.re
  20. +7 −1 src/asset/generate/node/AddNodeDataSystem.re
  21. +35 −4 src/asset/generate/node/GetNodeComponentDataSystem.re
  22. +40 −53 src/asset/generate/node/GetNodeDataSystem.re
  23. +84 −0 src/asset/utils/ConvertScriptDataUtils.re
  24. +3 −0 src/service/record/main/data/script/ScriptAttributeType.re
  25. +4 −6 src/service/state/main/data/StateDataMainType.re
  26. +3 −1 src/service/state/main/gameObject/BatchAddGameObjectComponentMainService.re
  27. +1 −1 src/service/state/main/script/CloneScriptMainService.re
  28. +1 −1 src/service/state/main/script/CreateScriptMainService.re
  29. +32 −0 src/service/state/main/script/OperateScriptDataMainService.re
  30. +362 −291 test/integration/no_worker/asset/assemble/assembleWDBFromGLB_test.re
  31. +730 −694 test/integration/no_worker/asset/convert/convertGLBToWDB_test.re
  32. +116 −84 test/integration/no_worker/asset/generate/generateSceneGraphByGLB_test.re
  33. +211 −77 test/integration/no_worker/asset/generate/generateSceneGraphByGameObject_test.re
  34. +25 −0 test/integration/no_worker/asset/tool/AssembleWDBSystemTool.re
  35. +164 −0 test/integration/no_worker/asset/tool/AssetScriptTool.re
  36. +47 −3 test/integration/no_worker/asset/tool/ConvertGLBTool.re
  37. +41 −0 test/tool/service/script/ScriptEventFuncTool.re
  38. +37 −8 test/tool/service/script/ScriptTool.re
@@ -1,6 +1,6 @@
open StateDataMainType;

let createScript = state => CreateScriptMainService.create(state);
let createScript = state => CreateScriptMainService.create(. state);

let unsafeGetScriptGameObject = (script, state) =>
GameObjectScriptMainService.unsafeGetGameObject(script, state.scriptRecord);
@@ -92,10 +92,7 @@ let _batchCreateMeshRenderer = ({meshRenderers}, {settingRecord} as state) =>
);

let _batchCreateBasicCameraView =
(
{basicCameraViews, perspectiveCameraProjections},
{basicCameraViewRecord} as state,
) =>
({basicCameraViews}, {basicCameraViewRecord} as state) =>
_batchCreateComponent(
basicCameraViews,
CreateBasicCameraViewMainService.create,
@@ -122,6 +119,9 @@ let _createArcballCameraControllerOneByOne =
state,
);

let _batchCreateScript = ({scripts}, {scriptRecord} as state) =>
_batchCreateComponent(scripts, CreateScriptMainService.create, state);

let _batchCreateBasicMaterial = ({basicMaterials}, {settingRecord} as state) =>
_batchCreateComponent(
basicMaterials,
@@ -136,7 +136,7 @@ let _batchCreateLightMaterial = ({lightMaterials}, {settingRecord} as state) =>
state,
);

let _batchCreateBasicSourceTextureArr =
let _batchCreateBasicSourceTexture =
({basicSourceTextures}, {settingRecord} as state) => {
let basicSourceTextureRecord =
RecordBasicSourceTextureMainService.getRecord(state);
@@ -188,15 +188,15 @@ let _batchCreateLightComponent = (components, createFunc, state) =>
(state, [||]),
);

let _batchCreateDirectionLightArr =
let _batchCreateDirectionLight =
(isRenderLight, {directionLights}, {directionLightRecord} as state) =>
_batchCreateLightComponent(
directionLights,
CreateDirectionLightMainService.create(isRenderLight),
state,
);

let _batchCreatePointLightArr =
let _batchCreatePointLight =
(isRenderLight, {pointLights}, {pointLightRecord} as state) =>
_batchCreateLightComponent(
pointLights,
@@ -217,13 +217,12 @@ let batchCreate = (isRenderLight, wd, state) => {
let (state, basicMaterialArr) = _batchCreateBasicMaterial(wd, state);
let (state, lightMaterialArr) = _batchCreateLightMaterial(wd, state);
let (state, basicSourceTextureArr) =
_batchCreateBasicSourceTextureArr(wd, state);
/* let (state, arrayBufferViewSourceTextureArr) =
_batchCreateArrayBufferViewSourceTextureArr(wd, state); */
_batchCreateBasicSourceTexture(wd, state);
let (state, directionLightArr) =
_batchCreateDirectionLightArr(isRenderLight, wd, state);
_batchCreateDirectionLight(isRenderLight, wd, state);
let (state, pointLightArr) =
_batchCreatePointLightArr(isRenderLight, wd, state);
_batchCreatePointLight(isRenderLight, wd, state);
let (state, scriptArr) = _batchCreateScript(wd, state);

(
state,
@@ -239,6 +238,7 @@ let batchCreate = (isRenderLight, wd, state) => {
lightMaterialArr,
directionLightArr,
pointLightArr,
scriptArr,
),
basicSourceTextureArr,
);
@@ -53,6 +53,7 @@ let batchOperate =
lightMaterialArr,
directionLightArr,
pointLightArr,
scriptArr,
),
basicSourceTextureArr,
),
@@ -90,6 +91,8 @@ let batchOperate =
gameObjectDirectionLights,
pointLightGameObjects,
gameObjectPointLights,
scriptGameObjects,
gameObjectScripts,
),
state,
) =
@@ -106,6 +109,7 @@ let batchOperate =
lightMaterialArr,
directionLightArr,
pointLightArr,
scriptArr,
),
indices,
wd,
@@ -151,6 +155,7 @@ let batchOperate =
|> BatchOperateSystem.batchSetMeshRendererData(wd, meshRendererArr)
|> BatchOperateSystem.batchSetBasicMaterialData(wd, basicMaterialArr)
|> BatchOperateSystem.batchSetLightMaterialData(wd, lightMaterialArr)
|> BatchOperateSystem.batchSetScriptData(wd, scriptArr)
|> BatchOperateLightSystem.batchSetDirectionLightData(
wd,
directionLightArr,
@@ -193,6 +198,10 @@ let batchOperate =
pointLightGameObjects,
gameObjectPointLights,
)
|> BatchAddGameObjectComponentMainService.batchAddScriptComponentForCreate(
scriptGameObjects,
gameObjectScripts,
)
|> BatchSetStreamTextureAllDataSystem.batchSet(basicSourceTextureData),
gameObjectArr,
(geometryArr, geometryGameObjects, gameObjectGeometrys),
@@ -21,6 +21,7 @@ let getBatchComponentGameObjectData =
lightMaterialArr,
directionLightArr,
pointLightArr,
scriptArr,
),
indices,
wd,
@@ -72,6 +73,13 @@ let getBatchComponentGameObjectData =
indices.gameObjectIndices.lightMaterialGameObjectIndexData.componentIndices
|> getBatchArrByIndices(lightMaterialArr);

let scriptGameObjects =
indices.gameObjectIndices.scriptGameObjectIndexData.gameObjectIndices
|> getBatchArrByIndices(gameObjectArr);
let gameObjectScripts =
indices.gameObjectIndices.scriptGameObjectIndexData.componentIndices
|> getBatchArrByIndices(scriptArr);

(
(
parentTransforms,
@@ -114,6 +122,8 @@ let getBatchComponentGameObjectData =
|> getBatchArrByIndices(gameObjectArr),
indices.gameObjectIndices.pointLightGameObjectIndexData.componentIndices
|> getBatchArrByIndices(pointLightArr),
scriptGameObjects,
gameObjectScripts,
),
state,
);
@@ -447,6 +457,29 @@ let batchSetLightMaterialData = ({lightMaterials}, lightMaterialArr, state) =>
state,
);

let batchSetScriptData = ({scripts}, scriptArr, state) =>
scripts
|> WonderCommonlib.ArrayService.reduceOneParami(
(. state, {eventFunctionDataMap, attributeMap}: script, index) => {
let script = scriptArr[index];

state
|> OperateScriptDataMainService.addEventFunctionDataMap(
script,
ConvertScriptDataUtils.convertEventFunctionDataMapJsonToRecord(
eventFunctionDataMap,
),
)
|> OperateScriptDataMainService.addAttributeMap(
script,
ConvertScriptDataUtils.convertAttributeMapJsonToRecord(
attributeMap,
),
);
},
state,
);

let _batchSetGameObjectData = (targets, dataArr, setDataFunc, state) =>
targets
|> WonderCommonlib.ArrayService.reduceOneParami(
@@ -253,6 +253,7 @@ let batchOperate =
lightMaterialArr,
directionLightArr,
pointLightArr,
scriptArr,
),
basicSourceTextureArr,
),
@@ -290,6 +291,8 @@ let batchOperate =
gameObjectDirectionLights,
pointLightGameObjects,
gameObjectPointLights,
scriptGameObjects,
gameObjectScripts,
),
state,
) =
@@ -306,6 +309,7 @@ let batchOperate =
lightMaterialArr,
directionLightArr,
pointLightArr,
scriptArr,
),
indices,
wd,
@@ -359,6 +363,7 @@ let batchOperate =
|> BatchOperateSystem.batchSetMeshRendererData(wd, meshRendererArr)
|> BatchOperateSystem.batchSetBasicMaterialData(wd, basicMaterialArr)
|> BatchOperateSystem.batchSetLightMaterialData(wd, lightMaterialArr)
|> BatchOperateSystem.batchSetScriptData(wd, scriptArr)
|> BatchOperateLightSystem.batchSetDirectionLightData(
wd,
directionLightArr,
@@ -405,6 +410,10 @@ let batchOperate =
pointLightGameObjects,
gameObjectPointLights,
)
|> BatchAddGameObjectComponentMainService.batchAddScriptComponentForCreate(
scriptGameObjects,
gameObjectScripts,
)
|> BatchSetWholeTextureAllDataSystem.batchSet(basicSourceTextureData),
imageUint8ArrayDataMap,
gameObjectArr,
@@ -106,7 +106,8 @@ let getActiveCameraNodeIndex = ({nodes, cameras, extras}: GLTFType.gltf) =>
switch (_getActiveBasicCameraViewIndex(basicCameraViews)) {
| None => None
| Some(basicCameraViewIndex) =>
basicCameraViewIndex |> _getFirstNodeIndexWhichUseBasicCameraView(nodes)
basicCameraViewIndex
|> _getFirstNodeIndexWhichUseBasicCameraView(nodes)
}
| _ => _getFirstNodeIndexWhichUseFirstCamera(nodes)
}
@@ -146,11 +147,10 @@ let convertToArcballCameraControllers = ({extras}: GLTFType.gltf) =>
| Some({arcballCameraControllers}) =>
switch (arcballCameraControllers) {
| None => [||]
| Some(arcballCameraControllers) =>
arcballCameraControllers
|> WonderCommonlib.ArrayService.reduceOneParam(
(. arr, data) => arr |> ArrayService.push(data),
[||],
)
| Some(arcballCameraControllers) => arcballCameraControllers
/* |> WonderCommonlib.ArrayService.reduceOneParam(
(. arr, data) => arr |> ArrayService.push(data),
[||],
) */
}
};
@@ -1,4 +1,4 @@
let _createDefaultMaterial = () : GLTFType.material => {
let _createDefaultMaterial = (): GLTFType.material => {
name: Some("defaultLightMaterial"),
pbrMetallicRoughness:
Some({
@@ -19,7 +19,7 @@ let _addDefaultMaterial = ({materials} as gltf: GLTFType.gltf) => {
| None => (0, Some([|defaultMaterial|]))
| Some(materials) => (
materials |> Js.Array.length,
materials |> ArrayService.push(defaultMaterial) |. Some,
(materials |> ArrayService.push(defaultMaterial))->Some,
)
};

@@ -67,6 +67,7 @@ let _setDefaultMaterial =
basicMaterial: None,
lightMaterial: Some(defaultMaterialIndex),
cameraController: None,
script: None,
isRoot: None,
})
| Some(extras) =>
@@ -84,8 +85,7 @@ let _setDefaultMaterial =
};

let convert =
({materials, nodes, meshes} as gltf: GLTFType.gltf)
: GLTFType.gltf => {
({materials, nodes, meshes} as gltf: GLTFType.gltf): GLTFType.gltf => {
let isNeedAddDefaultMaterial =
nodes
|> WonderCommonlib.ArrayService.reduceOneParam(
@@ -84,6 +84,9 @@ let _buildWDBJsonUint8Array = (gltf: GLTFType.gltf) => {
buffers: ConvertBuffersSystem.convertToBuffers(gltf),
directionLights: directionLightArr,
pointLights: pointLightArr,
scripts:
ConvertScriptsSystem.convertToScripts(gltf)
/* |> WonderLog.Log.printJson, */
}: WDType.wd
)
|> Obj.magic
@@ -227,7 +230,7 @@ let _checkGLB = dataView => {
dataView;
};

let convertGLBData = (gltf, binBuffer) =>
let convertGLBData = (gltf: Js.Json.t, binBuffer) =>
_convertGLBToWDB(ConvertGLTFJsonToRecordSystem.convert(gltf), binBuffer);

let convertGLB = (glb: ArrayBuffer.t) => {
@@ -210,6 +210,11 @@ let _convertExtensions = json =>
),
);

let _getScriptMap = (key, json) => {
let dict: Js.Dict.t(Js.Json.t) = Obj.magic(json: Js.Json.t);
Js.Dict.get(dict, key) |> Obj.magic;
};

let _convertExtras = json =>
json
|> optional(
@@ -282,6 +287,29 @@ let _convertExtras = json =>
),
),
),
scripts:
json
|> optional(
field(
"scripts",
array(json =>
(
/* WonderLog.Log.print(json) |> ignore; */
{
eventFunctionDataMap:
_getScriptMap("eventFunctionDataMap", json),
/* json
|> field("eventFunctionDataMap",dict |> Obj.magic)
|> WonderLog.Log.print */
attributeMap:
/* json |> field("attributeMap", dict |> Obj.magic), */
_getScriptMap("attributeMap", json),
}: script
)
),
),
),
/* |> WonderLog.Log.print */
}
),
);
@@ -537,6 +565,9 @@ let _convertNodes = json =>
|> optimizedOptional(
optimizedField("cameraController", int),
),
script:
json
|> optimizedOptional(optimizedField("script", int)),
isRoot:
json
|> optimizedOptional(optimizedField("isRoot", bool)),
@@ -566,7 +597,7 @@ let _convertNodes = json =>
),
);

let convert = json : GLTFType.gltf => {
let convert = json => {
extensionsUsed: json |> optional(field("extensionsUsed", array(string))),
extensions: _convertExtensions(json),
extras: _convertExtras(json),
@@ -0,0 +1,9 @@
let convertToScripts = ({extras}: GLTFType.gltf) =>
switch (extras) {
| None => [||]
| Some({scripts}) =>
switch (scripts) {
| None => [||]
| Some(scripts) => scripts
}
};

0 comments on commit 5ea3908

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