Skip to content

Commit

Permalink
feat(asset-bundle): add "checkCircleDependency","removeDupliceData" l…
Browse files Browse the repository at this point in the history
…ogic
  • Loading branch information
yyc-git committed Apr 16, 2019
1 parent 8e5c3c7 commit 259919d
Show file tree
Hide file tree
Showing 23 changed files with 1,560 additions and 307 deletions.
4 changes: 2 additions & 2 deletions src/asset/assemble/AssembleWholeWDBSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ let _buildBufferArray = (buffers: array(int), binBuffer) => {
[|binBuffer|];
};

let _checkWDB = dataView => {
let checkWDB = dataView => {
WonderLog.Contract.requireCheck(
() => {
open WonderLog;
Expand Down Expand Up @@ -189,7 +189,7 @@ let assembleWDBData =

let assemble = (wdb, configTuple, state) => {
let (wdFileContent, streamChunk, binBuffer) =
BufferUtils.decodeWDB(wdb, _checkWDB);
BufferUtils.decodeWDB(wdb, checkWDB);

assembleWDBData(
wdFileContent |> Js.Json.parseExn |> Obj.magic,
Expand Down
107 changes: 107 additions & 0 deletions src/asset/assemble/BatchOperateWholeGeometrySystem.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
open WDType;

open Js.Typed_array;

let _getBufferData =
(
{accessors, bufferViews, buffers},
(accessorIndex, dataViewArr, bytes_per_element),
) => {
WonderLog.Contract.requireCheck(
() =>
WonderLog.(
Contract.(
Operators.(
test(
Log.buildAssertMessage(
~expect={j|not support interleaved buffer data|j},
~actual={j|is interleaved|j},
),
() => {
let accessor = Array.unsafe_get(accessors, accessorIndex);
let {byteStride} =
Array.unsafe_get(bufferViews, accessor.bufferView);

byteStride |> OptionService.isJsonSerializedValueNone ?
assertPass() :
byteStride
|> OptionService.unsafeGetJsonSerializedValue
== BufferUtils.getAccessorTypeSize(accessor.type_)
* bytes_per_element;
},
)
)
)
),
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);

let accessor = Array.unsafe_get(accessors, accessorIndex);
let bufferView = Array.unsafe_get(bufferViews, accessor.bufferView);
let dataView = Array.unsafe_get(dataViewArr, bufferView.buffer);

let offset = accessor.byteOffset + bufferView.byteOffset;

(
dataView |> DataView.buffer,
offset,
BufferUtils.computeTypeArrayLengthByAccessorData(
accessor.count,
accessor.type_,
),
);
};

let _getBufferPointData =
(
(accessorIndex, bytes_per_element, dataViewArr, wd),
fromBufferRangeFunc,
) => {
let (arrayBuffer, offset, length) =
_getBufferData(wd, (accessorIndex, dataViewArr, bytes_per_element));

fromBufferRangeFunc(arrayBuffer, ~offset, ~length);
};

let getBufferAttributeData = (accessorIndex, dataViewArr, wd) =>
_getBufferPointData(
(accessorIndex, Float32Array._BYTES_PER_ELEMENT, dataViewArr, wd),
Float32Array.fromBufferRange,
);

let getAccessorComponentType = ({accessors}, accessorIndex) => {
let accessor = Array.unsafe_get(accessors, accessorIndex);

accessor.componentType;
};

let getBufferIndex16Data = (componentType, accessorIndex, dataViewArr, wd) =>
switch (componentType) {
| UNSIGNED_BYTE =>
Uint16Array.from(
_getBufferPointData(
(accessorIndex, Uint8Array._BYTES_PER_ELEMENT, dataViewArr, wd),
Uint8Array.fromBufferRange,
)
|> Obj.magic,
)
->Some
| UNSIGNED_SHORT =>
_getBufferPointData(
(accessorIndex, Uint16Array._BYTES_PER_ELEMENT, dataViewArr, wd),
Uint16Array.fromBufferRange,
)
->Some
| _ => None
};

let getBufferIndex32Data = (componentType, accessorIndex, dataViewArr, wd) =>
switch (componentType) {
| UNSIGNED_INT =>
_getBufferPointData(
(accessorIndex, Uint32Array._BYTES_PER_ELEMENT, dataViewArr, wd),
Uint32Array.fromBufferRange,
)
->Some
| _ => None
};
129 changes: 19 additions & 110 deletions src/asset/assemble/BatchOperateWholeSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,110 +4,6 @@ open WDType;

open Js.Typed_array;

let _getAccessorComponentType = ({accessors}, accessorIndex) => {
let accessor = Array.unsafe_get(accessors, accessorIndex);

accessor.componentType;
};

let _getBufferData =
(
{accessors, bufferViews, buffers},
(accessorIndex, dataViewArr, bytes_per_element),
) => {
WonderLog.Contract.requireCheck(
() =>
WonderLog.(
Contract.(
Operators.(
test(
Log.buildAssertMessage(
~expect={j|not support interleaved buffer data|j},
~actual={j|is interleaved|j},
),
() => {
let accessor = Array.unsafe_get(accessors, accessorIndex);
let {byteStride} =
Array.unsafe_get(bufferViews, accessor.bufferView);

byteStride |> OptionService.isJsonSerializedValueNone ?
assertPass() :
byteStride
|> OptionService.unsafeGetJsonSerializedValue
== BufferUtils.getAccessorTypeSize(accessor.type_)
* bytes_per_element;
},
)
)
)
),
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);

let accessor = Array.unsafe_get(accessors, accessorIndex);
let bufferView = Array.unsafe_get(bufferViews, accessor.bufferView);
let dataView = Array.unsafe_get(dataViewArr, bufferView.buffer);

let offset = accessor.byteOffset + bufferView.byteOffset;

(
dataView |> DataView.buffer,
offset,
BufferUtils.computeTypeArrayLengthByAccessorData(
accessor.count,
accessor.type_,
),
);
};

let _getBufferPointData =
(
(accessorIndex, bytes_per_element, dataViewArr, wd),
fromBufferRangeFunc,
) => {
let (arrayBuffer, offset, length) =
_getBufferData(wd, (accessorIndex, dataViewArr, bytes_per_element));

fromBufferRangeFunc(arrayBuffer, ~offset, ~length);
};

let _getBufferAttributeData = (accessorIndex, dataViewArr, wd) =>
_getBufferPointData(
(accessorIndex, Float32Array._BYTES_PER_ELEMENT, dataViewArr, wd),
Float32Array.fromBufferRange,
);

let _getBufferIndex16Data = (componentType, accessorIndex, dataViewArr, wd) =>
switch (componentType) {
| UNSIGNED_BYTE =>
Uint16Array.from(
_getBufferPointData(
(accessorIndex, Uint8Array._BYTES_PER_ELEMENT, dataViewArr, wd),
Uint8Array.fromBufferRange,
)
|> Obj.magic,
)
->Some
| UNSIGNED_SHORT =>
_getBufferPointData(
(accessorIndex, Uint16Array._BYTES_PER_ELEMENT, dataViewArr, wd),
Uint16Array.fromBufferRange,
)
->Some
| _ => None
};

let _getBufferIndex32Data = (componentType, accessorIndex, dataViewArr, wd) =>
switch (componentType) {
| UNSIGNED_INT =>
_getBufferPointData(
(accessorIndex, Uint32Array._BYTES_PER_ELEMENT, dataViewArr, wd),
Uint32Array.fromBufferRange,
)
->Some
| _ => None
};

let _batchSetGeometryData =
({geometrys} as wd, geometryArr, bufferArr, state) => {
let dataViewArr =
Expand All @@ -128,15 +24,19 @@ let _batchSetGeometryData =
let state =
VerticesGeometryMainService.setVerticesByTypeArray(
geometry,
_getBufferAttributeData(position, dataViewArr, wd),
BatchOperateWholeGeometrySystem.getBufferAttributeData(
position,
dataViewArr,
wd,
),
state,
);
let state =
normal |> OptionService.isJsonSerializedValueNone ?
state :
NormalsGeometryMainService.setNormalsByTypeArray(
geometry,
_getBufferAttributeData(
BatchOperateWholeGeometrySystem.getBufferAttributeData(
normal |> OptionService.unsafeGetJsonSerializedValue,
dataViewArr,
wd,
Expand All @@ -148,18 +48,27 @@ let _batchSetGeometryData =
state :
TexCoordsGeometryMainService.setTexCoordsByTypeArray(
geometry,
_getBufferAttributeData(
BatchOperateWholeGeometrySystem.getBufferAttributeData(
texCoord |> OptionService.unsafeGetJsonSerializedValue,
dataViewArr,
wd,
),
state,
);

let componentType = _getAccessorComponentType(wd, index);
let componentType =
BatchOperateWholeGeometrySystem.getAccessorComponentType(
wd,
index,
);
let state =
switch (
_getBufferIndex16Data(componentType, index, dataViewArr, wd)
BatchOperateWholeGeometrySystem.getBufferIndex16Data(
componentType,
index,
dataViewArr,
wd,
)
) {
| Some(data) =>
IndicesGeometryMainService.setIndicesByUint16Array(
Expand All @@ -169,7 +78,7 @@ let _batchSetGeometryData =
)
| None =>
switch (
_getBufferIndex32Data(
BatchOperateWholeGeometrySystem.getBufferIndex32Data(
componentType,
index,
dataViewArr,
Expand Down
8 changes: 4 additions & 4 deletions src/asset/generate/BuildGeometryDataSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ open Js.Typed_array;

open GenerateSceneGraphType;

let _getComponentType = pointType =>
let getComponentType = pointType =>
switch (pointType) {
| Vertex
| Normal
Expand All @@ -11,7 +11,7 @@ let _getComponentType = pointType =>
| Index32 => 5125
};

let _getType = pointType =>
let getType = pointType =>
switch (pointType) {
| Vertex
| Normal => "VEC3"
Expand Down Expand Up @@ -46,8 +46,8 @@ let _addBufferViewData =
bufferView: bufferViewDataArr |> Js.Array.length,
/* byteOffset: 0, */
count: pointsCount,
componentType: _getComponentType(pointType),
type_: _getType(pointType),
componentType: getComponentType(pointType),
type_: getType(pointType),
}),
bufferViewDataArr
|> ArrayService.push({
Expand Down
14 changes: 12 additions & 2 deletions src/asset/generate/GenerateCommon.re
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ let checkShouldHasNoSlot = map =>
() =>
map
|> WonderCommonlib.MutableSparseMapService.getValidValues
|> WonderCommonlib.MutableSparseMapService.length == (map |> WonderCommonlib.MutableSparseMapService.length)
|> WonderCommonlib.MutableSparseMapService.length
== (map |> WonderCommonlib.MutableSparseMapService.length)
)
)
)
);
);

let buildBufferViewData = (byteOffset, byteLength) => (
0,
byteOffset,
byteLength,
None,
);

let buildAccessorByteOffset = () => 0;
3 changes: 3 additions & 0 deletions src/asset_bundle/all/data/AllABType.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type abPath = string;

type abDataArr = array((abPath, Js.Typed_array.ArrayBuffer.t));
33 changes: 33 additions & 0 deletions src/asset_bundle/all/data/DependencyDataType.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
open AllABType;

type imageDependencyRelation =
WonderCommonlib.ImmutableHashMapService.t(array(abPath));

type geometryDependencyRelation =
WonderCommonlib.ImmutableHashMapService.t(array(abPath));

/* type dependencyRelation =
WonderCommonlib.ImmutableHashMapService.t(array(abPath)); */

type dependencyRelation = {
imageDependencyRelation,
geometryDependencyRelation
};

/* {
}; */

/* type imageDependencyData = {
};
type geometryDependencyData = {
};
type dependencyData = {
image: imageDependencyData,
geometry: geometryDependencyData
}; */
Loading

0 comments on commit 259919d

Please sign in to comment.