From: seungho Date: Tue, 12 Jul 2022 05:27:03 +0000 (+0900) Subject: Compute min/max value if min/max is not defined. X-Git-Tag: dali_2.1.32~9^2~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=a656457377ae913f2a81b33a506ef905cdf01ff8 Compute min/max value if min/max is not defined. Change-Id: I84f8b912e00aed48f5c45c7a64a2e3e3e00dd371 Signed-off-by: seungho --- diff --git a/automated-tests/resources/beer.bin b/automated-tests/resources/beer.bin new file mode 100644 index 0000000..08571fd Binary files /dev/null and b/automated-tests/resources/beer.bin differ diff --git a/automated-tests/resources/beer_modelViewTest.dli b/automated-tests/resources/beer_modelViewTest.dli new file mode 100644 index 0000000..20be585 --- /dev/null +++ b/automated-tests/resources/beer_modelViewTest.dli @@ -0,0 +1,181 @@ +{ + "asset": { "version": "1.0" }, + "scene": 0, + "scenes": [ { "nodes": [ 0 ] } ], + "nodes": [ + { + "name": "Scene", + "matrix": [ 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1 ], + "children": [ 1, 2 ] + }, + { + "name": "Cube", + "matrix": [ 2.5, 0, 0, 0, 0, 2.5, 0, 0, 0, 0, 2.5, 0, 0, 0, 0, 1 ], + "model": { + "mesh": 0, + "material": 0, + "shader": 0 + } + }, + { + "name": "bottle", + "matrix": [ 0.125, 0, 0, 0, 0, -0, 0.125, 0, 0, -0.125, -0, 0, -0, 0, -1.5, 1 ], + "children": [ 3, 4, 5, 6 ] + }, + { + "name": "bottle-cap", + "model": { + "mesh": 3, + "material": 2, + "shader": 1 + } + }, + { + "name": "bottle-alpha-front", + "model": { + "mesh": 1, + "material": 1, + "shader": 2 + } + }, + { + "name": "bottle-alpha-back", + "model": { + "mesh": 1, + "material": 1, + "shader": 3 + } + }, + { + "name": "bottle-label", + "model": { + "mesh": 2, + "material": 0, + "shader": 4 + } + } + ], + "meshes": [ + { + "uri": "cube.bin", + "attributes": 31, + "primitive": "TRIANGLES", + "indices": { "byteOffset": 0, "byteLength": 72 }, + "positions": { "byteOffset": 72, "byteLength": 288 }, + "normals": { "byteOffset": 360, "byteLength": 288 }, + "textures": { "byteOffset": 648, "byteLength": 192 }, + "tangents": { "byteOffset": 840, "byteLength": 288 } + }, + { + "uri": "beer.bin", + "attributes": 31, + "primitive": "TRIANGLES", + "indices": { "byteOffset": 0, "byteLength": 19920 }, + "positions": { "byteOffset": 19920, "byteLength": 54792 }, + "normals": { "byteOffset": 74712, "byteLength": 54792 }, + "textures": { "byteOffset": 129504, "byteLength": 36528 }, + "tangents": { "byteOffset": 166032, "byteLength": 54792 } + }, + { + "uri": "beer.bin", + "attributes": 31, + "primitive": "TRIANGLES", + "indices": { "byteOffset": 220824, "byteLength": 13200 }, + "positions": { "byteOffset": 234024, "byteLength": 14628 }, + "normals": { "byteOffset": 248652, "byteLength": 14628 }, + "textures": { "byteOffset": 263280, "byteLength": 9752 }, + "tangents": { "byteOffset": 273032, "byteLength": 14628 } + }, + { + "uri": "beer.bin", + "attributes": 31, + "primitive": "TRIANGLES", + "indices": { "byteOffset": 287660, "byteLength": 31440 }, + "positions": { "byteOffset": 319100, "byteLength": 121032 }, + "normals": { "byteOffset": 440132, "byteLength": 121032 }, + "textures": { "byteOffset": 561164, "byteLength": 80688 }, + "tangents": { "byteOffset": 641852, "byteLength": 121032 } + } + ], + "skeletons": [ + ], + "cameras": [ + { + "fov": 60, + "near": 0.1, + "far": 100, + "matrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 3.5, 1 ] + } + ], + "lights": [ + ], + "materials": [ + { + "color": [ 1.0, 0.95, 0.5 ], + "metallic": 0.25, + "roughness": 1.0, + "environment": 1 + }, + { + "color": [ 0.1, 0.4, 0.0, 0.6 ], + "metallic": 0.4, + "roughness": 0.0, + "environment": 1 + }, + { + "color": [ 0.5, 0.5, 0.5 ], + "metallic": 1.0, + "roughness": 0.0, + "environment": 1 + } + ], + "environment": [ + { + }, + { + "cubeSpecular": "Studio/Radiance.ktx", + "cubeDiffuse": "Studio/Irradiance.ktx", + "iblIntensity": 0.75 + } + ], + "shaders": [ + { + "vertex": "dli_pbr.vsh", + "fragment": "dli_pbr.fsh", + "rendererState": "DEPTH_TEST|CULL_FRONT", + "uCubeMatrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ], + "uMaxLOD": 6 + }, + { + "vertex": "dli_pbr.vsh", + "fragment": "dli_pbr.fsh", + "rendererState": "DEPTH_TEST|DEPTH_WRITE", + "uCubeMatrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ], + "uMaxLOD": 6 + }, + { + "vertex": "dli_pbr.vsh", + "fragment": "dli_pbr.fsh", + "defines": [ "THREE_TEX" ], + "rendererState": "ALPHA_BLEND|DEPTH_TEST|CULL_FRONT", + "uCubeMatrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ], + "uMaxLOD": 6 + }, + { + "vertex": "dli_pbr.vsh", + "fragment": "dli_pbr.fsh", + "defines": [ "THREE_TEX" ], + "rendererState": "ALPHA_BLEND|DEPTH_TEST|CULL_BACK", + "uCubeMatrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ], + "uMaxLOD": 6 + }, + { + "vertex": "dli_pbr.vsh", + "fragment": "dli_pbr.fsh", + "defines": [ "FLIP_V" ], + "rendererState": "DEPTH_TEST|DEPTH_WRITE|CULL_BACK", + "uCubeMatrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ], + "uMaxLOD": 6 + } + ] +} diff --git a/automated-tests/resources/cube.bin b/automated-tests/resources/cube.bin new file mode 100644 index 0000000..f5bd426 Binary files /dev/null and b/automated-tests/resources/cube.bin differ diff --git a/automated-tests/src/dali-scene-loader/utc-Dali-ModelView.cpp b/automated-tests/src/dali-scene-loader/utc-Dali-ModelView.cpp index edc6bc2..4c374a4 100644 --- a/automated-tests/src/dali-scene-loader/utc-Dali-ModelView.cpp +++ b/automated-tests/src/dali-scene-loader/utc-Dali-ModelView.cpp @@ -46,6 +46,7 @@ const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCub const char* TEST_GLTF_TRIANGLE_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedTriangle.gltf"; const char* TEST_GLTF_ANIMATION_TEST_FILE_NAME = TEST_RESOURCE_DIR "/animationTest.gltf"; const char* TEST_DLI_FILE_NAME = TEST_RESOURCE_DIR "/arc.dli"; +const char* TEST_DLI_BEER_FILE_NAME = TEST_RESOURCE_DIR "/beer_modelViewTest.dli"; /** * For the diffuse and specular cube map texture. * These textures are based off version of Wave engine sample @@ -437,6 +438,35 @@ int UtcDaliModelViewFitSize02(void) { ToolkitTestApplication application; + Scene3D::ModelView view = Scene3D::ModelView::New(TEST_DLI_BEER_FILE_NAME); + view.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50)); + + application.GetScene().Add(view); + + application.SendNotification(); + application.Render(); + + Actor rootActor = view.GetModelRoot(); + Vector3 rootSize = rootActor.GetProperty(Dali::Actor::Property::SIZE); + DALI_TEST_EQUALS(Vector3(5, 5, 5), rootSize, TEST_LOCATION); + + Vector3 rootScale = rootActor.GetProperty(Dali::Actor::Property::SCALE); + DALI_TEST_EQUALS(Vector3(1, 1, 1), rootScale, TEST_LOCATION); + + view.FitSize(true); + rootSize = rootActor.GetProperty(Dali::Actor::Property::SIZE); + DALI_TEST_EQUALS(Vector3(5, 5, 5), rootSize, TEST_LOCATION); + + rootScale = rootActor.GetProperty(Dali::Actor::Property::SCALE); + DALI_TEST_EQUALS(Vector3(10, 10, 10), rootScale, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliModelViewFitSize03(void) +{ + ToolkitTestApplication application; + Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME); view.SetProperty(Dali::Actor::Property::SIZE, Vector2(0, 0)); diff --git a/dali-scene-loader/public-api/mesh-definition.cpp b/dali-scene-loader/public-api/mesh-definition.cpp index 373b445..75b19a7 100644 --- a/dali-scene-loader/public-api/mesh-definition.cpp +++ b/dali-scene-loader/public-api/mesh-definition.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -454,6 +454,21 @@ MeshDefinition::Accessor::Accessor(const MeshDefinition::Blob& blob, { } +void MeshDefinition::Blob::ComputeMinMax(std::vector& min, std::vector& max, uint32_t numComponents, uint32_t count, const float* values) +{ + min.assign(numComponents, MAXFLOAT); + max.assign(numComponents, -MAXFLOAT); + for(uint32_t i = 0; i < count; ++i) + { + for(uint32_t j = 0; j < numComponents; ++j) + { + min[j] = std::min(min[j], *values); + max[j] = std::max(max[j], *values); + values++; + } + } +} + void MeshDefinition::Blob::ApplyMinMax(const std::vector& min, const std::vector& max, uint32_t count, float* values) { DALI_ASSERT_DEBUG(max.size() == min.size() || max.size() * min.size() == 0); @@ -504,6 +519,11 @@ uint32_t MeshDefinition::Blob::GetBufferSize() const return IsConsecutive() ? mLength : (mLength * mElementSizeHint / mStride); } +void MeshDefinition::Blob::ComputeMinMax(uint32_t numComponents, uint32_t count, float* values) +{ + ComputeMinMax(mMin, mMax, numComponents, count, values); +} + void MeshDefinition::Blob::ApplyMinMax(uint32_t count, float* values) const { ApplyMinMax(mMin, mMax, count, values); @@ -545,7 +565,7 @@ void MeshDefinition::RequestTangents() } MeshDefinition::RawData -MeshDefinition::LoadRaw(const std::string& modelsPath) const +MeshDefinition::LoadRaw(const std::string& modelsPath) { RawData raw; if(IsQuad()) @@ -613,7 +633,14 @@ MeshDefinition::LoadRaw(const std::string& modelsPath) const } uint32_t numVector3 = bufferSize / sizeof(Vector3); - mPositions.mBlob.ApplyMinMax(numVector3, reinterpret_cast(buffer.data())); + if(mPositions.mBlob.mMin.size() != 3u || mPositions.mBlob.mMax.size() != 3u) + { + mPositions.mBlob.ComputeMinMax(3u, numVector3, reinterpret_cast(buffer.data())); + } + else + { + mPositions.mBlob.ApplyMinMax(numVector3, reinterpret_cast(buffer.data())); + } if(HasBlendShapes()) { diff --git a/dali-scene-loader/public-api/mesh-definition.h b/dali-scene-loader/public-api/mesh-definition.h index 2fe4394..b4b2c7d 100644 --- a/dali-scene-loader/public-api/mesh-definition.h +++ b/dali-scene-loader/public-api/mesh-definition.h @@ -1,7 +1,7 @@ #ifndef DALI_SCENE_LOADER_MESH_DEFINITION_H #define DALI_SCENE_LOADER_MESH_DEFINITION_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,6 +78,8 @@ struct DALI_SCENE_LOADER_API MeshDefinition std::vector mMin; std::vector mMax; + static void ComputeMinMax(std::vector& min, std::vector& max, uint32_t numComponents, uint32_t count, const float* values); + static void ApplyMinMax(const std::vector& min, const std::vector& max, uint32_t count, float* values); Blob() = default; @@ -107,7 +109,20 @@ struct DALI_SCENE_LOADER_API MeshDefinition } /** - * @brief Applies the min / max values, if they're defined. + * @brief Computes the min / max of the input value data. + * The min and max are stored in mMin and mMax. + * + * @param[in] numComponents number of components of data type. e.g., 3 for Vector3. + * @param[in] count The number of data. + * @param[in] values Data for the mesh. + */ + void ComputeMinMax(uint32_t numComponents, uint32_t count, float* values); + + /** + * @brief Applies the min / max values, if they're defined in the model + * + * @param[in] count The number of data. + * @param[in] values Data for the mesh that min / max values will be applied. */ void ApplyMinMax(uint32_t count, float* values) const; }; @@ -224,7 +239,7 @@ struct DALI_SCENE_LOADER_API MeshDefinition * attribute buffers, as well as blend shape data. This is then returned. * @note This can be done on any thread. */ - RawData LoadRaw(const std::string& modelsPath) const; + RawData LoadRaw(const std::string& modelsPath); /** * @brief Creates a MeshGeometry based firstly on the value of the uri member: