Skip to content

Commit

Permalink
feat(architecture): ISceneGraphRepoDp->geometryRepo add isFlipTexCoordY
Browse files Browse the repository at this point in the history
fix UpdatePathTracingCPJobEntity->_createVertexBufferData related logic;
  • Loading branch information
yyc-git committed Nov 10, 2020
1 parent 58a4585 commit a9df3bb
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/construct/application_layer/scene/GeometryApService.re
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ let getIndices = geometry => {
IndicesGeometryDoService.getIndices(geometry);
};

let isFlipTexCoordY = geometry => {
OperateGeometryDoService.isFlipTexCoordY(geometry);
};

let isSame = (geometry1, geometry2) => {
OperateGeometryDoService.isSame(geometry1, geometry2);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type geometryRepo = {
getTexCoords: geometry => option(Js.Typed_array.Float32Array.t),
getTangents: geometry => option(Js.Typed_array.Float32Array.t),
getIndices: geometry => option(Js.Typed_array.Uint32Array.t),
isFlipTexCoordY: geometry => bool,
isSame: (geometry, geometry) => bool,
getId: geometry => int,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ let _createInstances = geometryContainerMap => {
->RotationVO.value,
OperateTransformDoService.getScale(transform)
->ScaleVO.value,
))-> Log.printForDebug,
)),
~instanceOffset=_convertHitGroupIndexToInstanceOffset(0),
~geometryContainer,
(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
let isFlipTexCoordY = geometry => {
DpContainer.unsafeGetGeometryRepoDp().isFlipTexCoordY(
geometry->GeometryEntity.value,
);
};

let isSame = (geometry1, geometry2) => {
DpContainer.unsafeGetGeometryRepoDp().isSame(
geometry1->GeometryEntity.value,
Expand Down
4 changes: 4 additions & 0 deletions src/construct/external_layer/api/domain/GeometryRunAPI.re
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ let getIndices = geometry => {
GeometryApService.getIndices(geometry);
};

let isFlipTexCoordY = geometry => {
GeometryApService.isFlipTexCoordY(geometry);
};

let isSame = (geometry1, geometry2) => {
GeometryApService.isSame(geometry1, geometry2);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ let _createVertexBufferData = allRenderGeometries => {
| Some(texCoords) =>
let length = texCoords->Float32Array.length;

let getTexCoordYFunc =
GeometryRunAPI.isFlipTexCoordY(geometry)
? (i => Float32Array.unsafe_get(texCoords, i^ + 1)->_flipY)
: (i => Float32Array.unsafe_get(texCoords, i^ + 1));

let i = ref(0);
let j = ref(offset);
while (i^ < length) {
Expand All @@ -237,11 +242,7 @@ let _createVertexBufferData = allRenderGeometries => {
j^ + 4,
Float32Array.unsafe_get(texCoords, i^),
);
Float32Array.unsafe_set(
bufferData,
j^ + 5,
Float32Array.unsafe_get(texCoords, i^ + 1)->_flipY,
);
Float32Array.unsafe_set(bufferData, j^ + 5, getTexCoordYFunc(i));

i := i^ + 2;
j := j^ + stride;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let set =
getTexCoords,
getTangents,
getIndices,
isFlipTexCoordY,
isSame: isSameGeometry,
getId: getGeometryId,
}: SceneGraphRepoDpCPType.geometryRepo = geometryRepo;
Expand Down Expand Up @@ -146,6 +147,7 @@ let set =
getIndices: geometry => {
getIndices(geometry)->OptionSt.fromNullable;
},
isFlipTexCoordY,
},
}: ISceneGraphRepoDp.sceneGraphRepo,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type geometryRepo = {
getTexCoords: geometry => Js.Nullable.t(Js.Typed_array.Float32Array.t),
getTangents: geometry => Js.Nullable.t(Js.Typed_array.Float32Array.t),
getIndices: geometry => Js.Nullable.t(Js.Typed_array.Uint32Array.t),
isFlipTexCoordY: geometry => bool,
isSame: (geometry, geometry) => bool,
getId: geometry => int,
};
Expand Down
3 changes: 3 additions & 0 deletions test/construct/tool/SceneGraphRepoDependencyTool.re
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ let buildGeometryRepo =
~getTexCoords=createEmptyStub(refJsObjToSandbox(sandbox^)),
~getTangents=createEmptyStub(refJsObjToSandbox(sandbox^)),
~getIndices=createEmptyStub(refJsObjToSandbox(sandbox^)),
~isFlipTexCoordY=createEmptyStub(refJsObjToSandbox(sandbox^))
->SinonTool.returns(false),
(),
)
: geometryRepo => {
Expand All @@ -189,6 +191,7 @@ let buildGeometryRepo =
getTexCoords,
getTangents,
getIndices,
isFlipTexCoordY,
};

let build =
Expand Down
6 changes: 3 additions & 3 deletions test/run/integration/updatePathTracingCPJob_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ let _ =
)
});
testPromise(
"set each render geometry's vertices, texCoords(should flip vertical), normals, tangents to buffer data and set buffer's data",
"set each render geometry's vertices, texCoords, normals, tangents to buffer data and set buffer's data",
() => {
let _ = _prepare();
let setSubFloat32DataStubData =
Expand Down Expand Up @@ -1073,7 +1073,7 @@ let _ =
11.,
0.,
0.5,
1.,
0.,
0.,
0.,
1.,
Expand All @@ -1089,7 +1089,7 @@ let _ =
3.,
0.,
0.10000000149011612,
0.,
1.,
0.,
0.,
2.,
Expand Down
24 changes: 19 additions & 5 deletions test/run/tool/GeometryCPTool.re
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,17 @@ let buildRepoWithTwoGeometriesAndSetPointData = sandbox => {
3.,
|]);
let tangents1 =
Float32Array.make([|(-0.24470466375350952), (-0.5224775075912476), (-0.8167845010757446), (-0.5092150568962097), (-0.3632996380329132), (-0.7802008390426636),


(-0.4640968143939972), (-0.5406073331832886), (-0.7016821503639221)|]);
Float32Array.make([|
(-0.24470466375350952),
(-0.5224775075912476),
(-0.8167845010757446),
(-0.5092150568962097),
(-0.3632996380329132),
(-0.7802008390426636),
(-0.4640968143939972),
(-0.5406073331832886),
(-0.7016821503639221),
|]);
let tangents2 =
Float32Array.make([|
(-0.46341636776924133),
Expand All @@ -67,7 +74,14 @@ let buildRepoWithTwoGeometriesAndSetPointData = sandbox => {
SceneGraphRepoDependencyTool.buildGeometryRepo(
~sandbox,
~isSame=(geometry1, geometry2) => {geometry1 == geometry2},
~getId=geometry => geometry -> Obj.magic,
~isFlipTexCoordY=
geometry => {
switch (geometry) {
| geometry when geometry == geometry1 => false
| geometry when geometry == geometry2 => true
}
},
~getId=geometry => geometry->Obj.magic,
~getVertices=
geometry =>
switch (geometry) {
Expand Down

0 comments on commit a9df3bb

Please sign in to comment.