Skip to content

Commit eef6de2

Browse files
committed
feat(asset): add "assemble wdd" draft
1 parent 9b52ea1 commit eef6de2

File tree

13 files changed

+870
-95
lines changed

13 files changed

+870
-95
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let addChildrenToParent = (parent, children) =>
2+
children
3+
->ListSt.traverseResultM(child => {
4+
HierachyTransformDoService.setParent(parent, child)
5+
})
6+
->ListSt.ignoreTraverseResultValue;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
open WDDType;
2+
3+
let assembleWDBData = wdd => {
4+
BatchCreateDoService.batchCreate(wdd)
5+
->Result.bind(BatchOperateDoService.batchOperate(wdd))
6+
->Result.bind(BuildRootGameObjectDoService.build(wdd));
7+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
open WDDType;
2+
3+
let _batchAddComponents = (addComponentFunc, gameObjects, components) => {
4+
ListSt.zipBy(gameObjects, components, (gameObject, component) => {
5+
addComponentFunc(gameObject, component)
6+
})
7+
->ListSt.sequenceResultM;
8+
};
9+
10+
let batchAddComponents =
11+
(
12+
wdd,
13+
(
14+
transformGameObjects,
15+
gameObjectTransforms,
16+
geometryGameObjects,
17+
gameObjectGeometries,
18+
basicCameraViewGameObjects,
19+
gameObjectBasicCameraViews,
20+
perspectiveCameraProjectionGameObjects,
21+
gameObjectPerspectiveCameraProjection,
22+
bsdfMaterialGameObjects,
23+
gameObjectBSDFMaterials,
24+
directionLightGameObjects,
25+
gameObjectDirectionLights,
26+
),
27+
) => {
28+
ListResult.mergeResults([
29+
_batchAddComponents(
30+
AddComponentGameObjectDoService.addTransform,
31+
transformGameObjects,
32+
gameObjectTransforms,
33+
),
34+
_batchAddComponents(
35+
AddComponentGameObjectDoService.addGeometry,
36+
geometryGameObjects,
37+
gameObjectGeometries,
38+
),
39+
_batchAddComponents(
40+
AddComponentGameObjectDoService.addBasicCameraView,
41+
basicCameraViewGameObjects,
42+
gameObjectBasicCameraViews,
43+
),
44+
_batchAddComponents(
45+
AddComponentGameObjectDoService.addPerspectiveCameraProjection,
46+
perspectiveCameraProjectionGameObjects,
47+
gameObjectPerspectiveCameraProjection,
48+
),
49+
_batchAddComponents(
50+
AddComponentGameObjectDoService.addBSDFMaterial,
51+
bsdfMaterialGameObjects,
52+
gameObjectBSDFMaterials,
53+
),
54+
_batchAddComponents(
55+
AddComponentGameObjectDoService.addDirectionLight,
56+
directionLightGameObjects,
57+
gameObjectDirectionLights,
58+
),
59+
]);
60+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
open WDDType;
2+
3+
let _batchCreateEntitiesWithResult = (createFunc, count) =>
4+
ListSt.range(0, count - 1)
5+
->ListSt.traverseReduceResultM(
6+
(list, _) => {
7+
createFunc()->Result.mapSuccess(entity => [entity, ...list])
8+
},
9+
[],
10+
)
11+
->Result.mapSuccess(ListSt.reverse);
12+
13+
let _batchCreateEntitiesWithoutResult = (createFunc, count) =>
14+
ListSt.range(0, count - 1)
15+
->ListSt.reduce([], (list, _) => {[createFunc(), ...list]})
16+
->ListSt.reverse;
17+
18+
let _batchCreateGameObject = ({gameObjects}) =>
19+
_batchCreateEntitiesWithResult(
20+
CreateGameObjectDoService.create,
21+
gameObjects.count,
22+
);
23+
24+
let _batchCreateTransform = ({transforms}) =>
25+
_batchCreateEntitiesWithResult(
26+
CreateTransformDoService.create,
27+
transforms->ListSt.length,
28+
);
29+
30+
let _batchCreateGeometry = ({geometries}) =>
31+
_batchCreateEntitiesWithResult(
32+
CreateGeometryDoService.create,
33+
geometries->ListSt.length,
34+
);
35+
36+
let _batchCreateBSDFMaterial = ({bsdfMaterials}) =>
37+
_batchCreateEntitiesWithResult(
38+
CreateBSDFMaterialDoService.create,
39+
bsdfMaterials->ListSt.length,
40+
);
41+
42+
let _batchCreateDirectionLight = ({directionLights}) =>
43+
_batchCreateEntitiesWithResult(
44+
CreateDirectionLightDoService.create,
45+
directionLights->ListSt.length,
46+
);
47+
48+
let _batchCreateBasicCameraView = ({basicCameraViews}) =>
49+
_batchCreateEntitiesWithoutResult(
50+
CreateBasicCameraViewDoService.create,
51+
basicCameraViews->ListSt.length,
52+
);
53+
54+
let _batchCreatePerspectiveCameraProjection =
55+
({perspectiveCameraProjections}) =>
56+
_batchCreateEntitiesWithoutResult(
57+
CreatePerspectiveCameraProjectionDoService.create,
58+
perspectiveCameraProjections->ListSt.length,
59+
);
60+
61+
let batchCreate = wdd => {
62+
Tuple5.collectResult(
63+
_batchCreateGameObject(wdd),
64+
_batchCreateTransform(wdd),
65+
_batchCreateGeometry(wdd),
66+
_batchCreateBSDFMaterial(wdd),
67+
_batchCreateDirectionLight(wdd),
68+
)
69+
->Result.mapSuccess(
70+
(gameObjects, transforms, geometries, bsdfMaterials, directionLights) => {
71+
(
72+
gameObjects,
73+
(
74+
transforms,
75+
geometries,
76+
bsdfMaterials,
77+
directionLights,
78+
_batchCreateBasicCameraView(wdd),
79+
_batchCreatePerspectiveCameraProjection(wdd),
80+
),
81+
)
82+
});
83+
};

0 commit comments

Comments
 (0)