Skip to content

Commit

Permalink
feat(asset-bundle): add "assemble sab" logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed Apr 18, 2019
1 parent a92371d commit 001a1d8
Show file tree
Hide file tree
Showing 19 changed files with 1,242 additions and 440 deletions.
39 changes: 12 additions & 27 deletions src/asset/assemble/AssembleWholeWDBSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ let _getArrayBuffer = (binBuffer, bufferView, bufferViews: array(bufferView)) =>

let _buildImageArray = (isLoadImage, {images, bufferViews}: wd, binBuffer) => {
let blobObjectUrlImageArr = [||];
let imageUint8ArrayDataMap = WonderCommonlib.MutableSparseMapService.createEmpty();
let imageUint8ArrayDataMap =
WonderCommonlib.MutableSparseMapService.createEmpty();

! isLoadImage ?
!isLoadImage ?
resolve((blobObjectUrlImageArr, imageUint8ArrayDataMap)) :
(
images |> OptionService.isJsonSerializedValueNone ?
Expand Down Expand Up @@ -89,28 +90,6 @@ let _buildImageArray = (isLoadImage, {images, bufferViews}: wd, binBuffer) => {
typeArr |> Uint8Array.buffer;
}; */

let _buildBufferArray = (buffers: array(int), binBuffer) => {
WonderLog.Contract.requireCheck(
() => {
open WonderLog;
open Contract;
open Operators;

let bufferLen = buffers |> Js.Array.length;
test(
Log.buildAssertMessage(
~expect={j|has only one buffer|j},
~actual={j|has $bufferLen|j},
),
() =>
bufferLen == 1
);
},
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);

[|binBuffer|];
};

let checkWDB = dataView => {
WonderLog.Contract.requireCheck(
Expand Down Expand Up @@ -160,11 +139,16 @@ let assembleWDBData =
isLoadImage,
),
state,
) =>
) => {
StateDataMainService.setState(StateDataMain.stateData, state) |> ignore;

_buildImageArray(isLoadImage, wd, binBuffer)
|> then_(imageDataTuple => {
let state =
StateDataMainService.unsafeGetState(StateDataMain.stateData);

let hasIMGUIFunc =
! OptionService.isJsonSerializedValueNone(wd.scene.imgui);
!OptionService.isJsonSerializedValueNone(wd.scene.imgui);
let state =
isSetIMGUIFunc && hasIMGUIFunc ?
state |> SetIMGUIFuncSystem.setIMGUIFunc(wd) : state;
Expand All @@ -175,7 +159,7 @@ let assembleWDBData =
|> BatchOperateWholeSystem.batchOperate(
wd,
imageDataTuple,
_buildBufferArray(buffers, binBuffer),
AssembleWholeWDBUtils. buildBufferArray(buffers, binBuffer),
(isBindEvent, isActiveCamera),
);

Expand All @@ -186,6 +170,7 @@ let assembleWDBData =
|> resolve;
})
|> WonderBsMost.Most.fromPromise;
};

let assemble = (wdb, configTuple, state) => {
let (wdFileContent, streamChunk, binBuffer) =
Expand Down
74 changes: 73 additions & 1 deletion src/asset/assemble/BatchOperateWholeGeometrySystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,76 @@ let getBufferIndex32Data = (componentType, accessorIndex, dataViewArr, wd) =>
)
->Some
| _ => None
};
};

let setGeometryData =
(
geometry,
wd,
dataViewArr,
{position, normal, texCoord, index}: WDType.geometry,
state,
) => {
let state =
VerticesGeometryMainService.setVerticesByTypeArray(
geometry,
getBufferAttributeData(position, dataViewArr, wd),
state,
);
let state =
normal |> OptionService.isJsonSerializedValueNone ?
state :
NormalsGeometryMainService.setNormalsByTypeArray(
geometry,
getBufferAttributeData(
normal |> OptionService.unsafeGetJsonSerializedValue,
dataViewArr,
wd,
),
state,
);
let state =
texCoord |> OptionService.isJsonSerializedValueNone ?
state :
TexCoordsGeometryMainService.setTexCoordsByTypeArray(
geometry,
getBufferAttributeData(
texCoord |> OptionService.unsafeGetJsonSerializedValue,
dataViewArr,
wd,
),
state,
);

let componentType = getAccessorComponentType(wd, index);
let state =
switch (getBufferIndex16Data(componentType, index, dataViewArr, wd)) {
| Some(data) =>
IndicesGeometryMainService.setIndicesByUint16Array(
geometry,
data,
state,
)
| None =>
switch (getBufferIndex32Data(componentType, index, dataViewArr, wd)) {
| Some(data) =>
IndicesGeometryMainService.setIndicesByUint32Array(
geometry,
data,
state,
)
| None =>
WonderLog.Log.fatal(
WonderLog.Log.buildFatalMessage(
~title="_batchSetGeometryData",
~description={j|unknown componentType: $componentType|j},
~reason="",
~solution={j||j},
~params={j||j},
),
)
}
};

state;
};
98 changes: 10 additions & 88 deletions src/asset/assemble/BatchOperateWholeSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -16,96 +16,18 @@ let _batchSetGeometryData =
geometryData |> OptionService.isJsonSerializedValueNone ?
state :
{
let {position, normal, texCoord, index}: WDType.geometry =
let ({position, normal, texCoord, index}: WDType.geometry) as geometryData =
geometryData |> OptionService.unsafeGetJsonSerializedValue;

let geometry = Array.unsafe_get(geometryArr, geometryIndex);

let state =
VerticesGeometryMainService.setVerticesByTypeArray(
geometry,
BatchOperateWholeGeometrySystem.getBufferAttributeData(
position,
dataViewArr,
wd,
),
state,
);
let state =
normal |> OptionService.isJsonSerializedValueNone ?
state :
NormalsGeometryMainService.setNormalsByTypeArray(
geometry,
BatchOperateWholeGeometrySystem.getBufferAttributeData(
normal |> OptionService.unsafeGetJsonSerializedValue,
dataViewArr,
wd,
),
state,
);
let state =
texCoord |> OptionService.isJsonSerializedValueNone ?
state :
TexCoordsGeometryMainService.setTexCoordsByTypeArray(
geometry,
BatchOperateWholeGeometrySystem.getBufferAttributeData(
texCoord |> OptionService.unsafeGetJsonSerializedValue,
dataViewArr,
wd,
),
state,
);

let componentType =
BatchOperateWholeGeometrySystem.getAccessorComponentType(
wd,
index,
);
let state =
switch (
BatchOperateWholeGeometrySystem.getBufferIndex16Data(
componentType,
index,
dataViewArr,
wd,
)
) {
| Some(data) =>
IndicesGeometryMainService.setIndicesByUint16Array(
geometry,
data,
state,
)
| None =>
switch (
BatchOperateWholeGeometrySystem.getBufferIndex32Data(
componentType,
index,
dataViewArr,
wd,
)
) {
| Some(data) =>
IndicesGeometryMainService.setIndicesByUint32Array(
geometry,
data,
state,
)
| None =>
WonderLog.Log.fatal(
WonderLog.Log.buildFatalMessage(
~title="_batchSetGeometryData",
~description=
{j|unknown componentType: $componentType|j},
~reason="",
~solution={j||j},
~params={j||j},
),
)
}
};

state;
BatchOperateWholeGeometrySystem.setGeometryData(
geometry,
wd,
dataViewArr,
geometryData,
state,
);
},
state,
);
Expand Down Expand Up @@ -133,7 +55,7 @@ let _getBatchTextureData =
),
);

let _getBatchAllTypeTextureData =
let getBatchAllTypeTextureData =
(lightMaterialArr, basicSourceTextureArr, blobObjectUrlImageArr, wd) =>
_getBatchTextureData(
lightMaterialArr,
Expand Down Expand Up @@ -234,7 +156,7 @@ let batchOperate =
);

let basicSourceTextureData =
_getBatchAllTypeTextureData(
getBatchAllTypeTextureData(
lightMaterialArr,
basicSourceTextureArr,
blobObjectUrlImageArr,
Expand Down
22 changes: 22 additions & 0 deletions src/asset/assemble/utils/AssembleWholeWDBUtils.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let buildBufferArray = (buffers: array(int), binBuffer) => {
WonderLog.Contract.requireCheck(
() => {
open WonderLog;
open Contract;
open Operators;

let bufferLen = buffers |> Js.Array.length;
test(
Log.buildAssertMessage(
~expect={j|has only one buffer|j},
~actual={j|has $bufferLen|j},
),
() =>
bufferLen == 1
);
},
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);

[|binBuffer|];
};
Loading

0 comments on commit 001a1d8

Please sign in to comment.