From a9df3bbdfef41c1a96a989289c655fc6c58477d2 Mon Sep 17 00:00:00 2001 From: yyc <395976266@qq.com> Date: Tue, 10 Nov 2020 14:13:45 +0800 Subject: [PATCH] feat(architecture): ISceneGraphRepoDp->geometryRepo add isFlipTexCoordY fix UpdatePathTracingCPJobEntity->_createVertexBufferData related logic; --- .../scene/GeometryApService.re | 4 ++++ .../interface/engine/ISceneGraphRepoDp.re | 1 + .../BuildAccerlerationContainerDoService.re | 2 +- .../geometry/OperateGeometryDoService.re | 6 +++++ .../api/domain/GeometryRunAPI.re | 4 ++++ .../update/UpdatePathTracingCPJobEntity.re | 11 +++++---- .../api/dependency/SceneGraphRepoDpCPAPI.re | 2 ++ .../dependency/vo/SceneGraphRepoDpCPType.re | 1 + .../tool/SceneGraphRepoDependencyTool.re | 3 +++ .../updatePathTracingCPJob_test.re | 6 ++--- test/run/tool/GeometryCPTool.re | 24 +++++++++++++++---- 11 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/construct/application_layer/scene/GeometryApService.re b/src/construct/application_layer/scene/GeometryApService.re index 775677208..99e84a725 100755 --- a/src/construct/application_layer/scene/GeometryApService.re +++ b/src/construct/application_layer/scene/GeometryApService.re @@ -18,6 +18,10 @@ let getIndices = geometry => { IndicesGeometryDoService.getIndices(geometry); }; +let isFlipTexCoordY = geometry => { + OperateGeometryDoService.isFlipTexCoordY(geometry); +}; + let isSame = (geometry1, geometry2) => { OperateGeometryDoService.isSame(geometry1, geometry2); }; diff --git a/src/construct/domain_layer/dependency/interface/engine/ISceneGraphRepoDp.re b/src/construct/domain_layer/dependency/interface/engine/ISceneGraphRepoDp.re index ad770c2b6..4b456963a 100755 --- a/src/construct/domain_layer/dependency/interface/engine/ISceneGraphRepoDp.re +++ b/src/construct/domain_layer/dependency/interface/engine/ISceneGraphRepoDp.re @@ -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, }; diff --git a/src/construct/domain_layer/domain/ray_tracing/service/BuildAccerlerationContainerDoService.re b/src/construct/domain_layer/domain/ray_tracing/service/BuildAccerlerationContainerDoService.re index 8468ff196..743fa2fdb 100755 --- a/src/construct/domain_layer/domain/ray_tracing/service/BuildAccerlerationContainerDoService.re +++ b/src/construct/domain_layer/domain/ray_tracing/service/BuildAccerlerationContainerDoService.re @@ -146,7 +146,7 @@ let _createInstances = geometryContainerMap => { ->RotationVO.value, OperateTransformDoService.getScale(transform) ->ScaleVO.value, - ))-> Log.printForDebug, + )), ~instanceOffset=_convertHitGroupIndexToInstanceOffset(0), ~geometryContainer, (), diff --git a/src/construct/domain_layer/domain/scene/scene_graph/service/geometry/OperateGeometryDoService.re b/src/construct/domain_layer/domain/scene/scene_graph/service/geometry/OperateGeometryDoService.re index 2d81d5a19..796e8df2e 100644 --- a/src/construct/domain_layer/domain/scene/scene_graph/service/geometry/OperateGeometryDoService.re +++ b/src/construct/domain_layer/domain/scene/scene_graph/service/geometry/OperateGeometryDoService.re @@ -1,3 +1,9 @@ +let isFlipTexCoordY = geometry => { + DpContainer.unsafeGetGeometryRepoDp().isFlipTexCoordY( + geometry->GeometryEntity.value, + ); +}; + let isSame = (geometry1, geometry2) => { DpContainer.unsafeGetGeometryRepoDp().isSame( geometry1->GeometryEntity.value, diff --git a/src/construct/external_layer/api/domain/GeometryRunAPI.re b/src/construct/external_layer/api/domain/GeometryRunAPI.re index 71375417c..08e873a63 100755 --- a/src/construct/external_layer/api/domain/GeometryRunAPI.re +++ b/src/construct/external_layer/api/domain/GeometryRunAPI.re @@ -18,6 +18,10 @@ let getIndices = geometry => { GeometryApService.getIndices(geometry); }; +let isFlipTexCoordY = geometry => { + GeometryApService.isFlipTexCoordY(geometry); +}; + let isSame = (geometry1, geometry2) => { GeometryApService.isSame(geometry1, geometry2); }; diff --git a/src/run/domain_layer/domain/pipeline/pipeline/entity/jobs/update/UpdatePathTracingCPJobEntity.re b/src/run/domain_layer/domain/pipeline/pipeline/entity/jobs/update/UpdatePathTracingCPJobEntity.re index dee6d6d5f..de14951f6 100755 --- a/src/run/domain_layer/domain/pipeline/pipeline/entity/jobs/update/UpdatePathTracingCPJobEntity.re +++ b/src/run/domain_layer/domain/pipeline/pipeline/entity/jobs/update/UpdatePathTracingCPJobEntity.re @@ -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) { @@ -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; diff --git a/src/run/external_layer/api/dependency/SceneGraphRepoDpCPAPI.re b/src/run/external_layer/api/dependency/SceneGraphRepoDpCPAPI.re index aa9a38dd8..9c44e8946 100755 --- a/src/run/external_layer/api/dependency/SceneGraphRepoDpCPAPI.re +++ b/src/run/external_layer/api/dependency/SceneGraphRepoDpCPAPI.re @@ -47,6 +47,7 @@ let set = getTexCoords, getTangents, getIndices, + isFlipTexCoordY, isSame: isSameGeometry, getId: getGeometryId, }: SceneGraphRepoDpCPType.geometryRepo = geometryRepo; @@ -146,6 +147,7 @@ let set = getIndices: geometry => { getIndices(geometry)->OptionSt.fromNullable; }, + isFlipTexCoordY, }, }: ISceneGraphRepoDp.sceneGraphRepo, ); diff --git a/src/run/external_layer/api/dependency/vo/SceneGraphRepoDpCPType.re b/src/run/external_layer/api/dependency/vo/SceneGraphRepoDpCPType.re index afd2ce612..dd6965c2f 100644 --- a/src/run/external_layer/api/dependency/vo/SceneGraphRepoDpCPType.re +++ b/src/run/external_layer/api/dependency/vo/SceneGraphRepoDpCPType.re @@ -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, }; diff --git a/test/construct/tool/SceneGraphRepoDependencyTool.re b/test/construct/tool/SceneGraphRepoDependencyTool.re index 405f6fa73..98689812c 100755 --- a/test/construct/tool/SceneGraphRepoDependencyTool.re +++ b/test/construct/tool/SceneGraphRepoDependencyTool.re @@ -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 => { @@ -189,6 +191,7 @@ let buildGeometryRepo = getTexCoords, getTangents, getIndices, + isFlipTexCoordY, }; let build = diff --git a/test/run/integration/updatePathTracingCPJob_test.re b/test/run/integration/updatePathTracingCPJob_test.re index 9105051dd..ee5adde3f 100755 --- a/test/run/integration/updatePathTracingCPJob_test.re +++ b/test/run/integration/updatePathTracingCPJob_test.re @@ -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 = @@ -1073,7 +1073,7 @@ let _ = 11., 0., 0.5, - 1., + 0., 0., 0., 1., @@ -1089,7 +1089,7 @@ let _ = 3., 0., 0.10000000149011612, - 0., + 1., 0., 0., 2., diff --git a/test/run/tool/GeometryCPTool.re b/test/run/tool/GeometryCPTool.re index f98ff474c..e6ef1c06f 100644 --- a/test/run/tool/GeometryCPTool.re +++ b/test/run/tool/GeometryCPTool.re @@ -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), @@ -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) {