[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / blend-shape-details.h
1 #ifndef DALI_SCENE3D_LOADER_BLEND_SHAPE_DETAILS_H
2 #define DALI_SCENE3D_LOADER_BLEND_SHAPE_DETAILS_H
3 /*
4  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/actors/actor.h>
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/weak-handle.h>
24 #include <dali/public-api/rendering/shader.h>
25 #include <limits> ///< for std::numeric_limits
26 #include <string>
27
28 // INTERNAL INCLUDES
29 #include <dali-scene3d/public-api/api.h>
30
31 namespace Dali::Scene3D::Loader
32 {
33 struct MeshDefinition;
34 struct MeshGeometry;
35
36 struct DALI_SCENE3D_API BlendShapes
37 {
38   using Index                          = uint32_t;
39   static constexpr Index INVALID_INDEX = std::numeric_limits<Index>::max();
40
41   enum class Version
42   {
43     VERSION_1_0,
44     VERSION_2_0,
45     INVALID
46   };
47
48   struct Component
49   {
50     enum
51     {
52       POSITIONS = 0x1,
53       NORMALS   = 0x2,
54       TANGENTS  = 0x4
55     };
56   };
57
58   struct BlendShapeData
59   {
60     std::vector<std::string> names;
61     std::vector<float>       weights;
62     std::vector<float>       unnormalizeFactors;
63     Version                  version{Scene3D::Loader::BlendShapes::Version::INVALID};
64     uint32_t                 bufferOffset{0};
65     int32_t                  components{0x0};
66     Dali::WeakHandle<Actor>  mActor;
67   };
68
69   // shader properties - animatable (uniforms)
70   static const char* NUMBER_OF_BLEND_SHAPES; ///< Integer number of blend shapes loaded.
71   static const char* UNNORMALIZE_FACTOR;     ///< Scalar(s) for position components of blend shapes; Version 1.0: float array (1 per blend shape); Version 2.0: single float.
72   static const char* COMPONENT_SIZE;         ///< Integer offset from one component (positions / normals / tangents) of a blend shape to the next.
73
74   // shader properties - read-only (not available as uniforms)
75   static const char* COMPONENTS; ///< Integer bitmask of the blend shape components that the shader uses; refer to the Components enum.
76
77   // actor property (instance) - animatable (uniforms)
78   static const char* WEIGHTS_UNIFORM; ///< The weight of each blend shape in a float array
79
80   /**
81    * @brief Registers properties based on the mesh definition (and geometry) and identified by the above string constants,
82    *  on the given @a renderer and @a actor.
83    * @SINCE_2_0.7
84    */
85   static void ConfigureProperties(const BlendShapeData& data, Renderer renderer);
86
87   BlendShapes() = delete;
88 };
89
90 } // namespace Dali::Scene3D::Loader
91
92 #endif // DALI_SCENE3D_LOADER_BLEND_SHAPE_DETAILS_H