[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / mesh-definition.h
index 7bf1f7c..911359c 100644 (file)
@@ -35,6 +35,7 @@ namespace Dali::Scene3D::Loader
  * @brief Defines a mesh with its attributes, the primitive type to render it as,
  *  and the file to load it from with the offset and length information for the
  *  individual attribute buffers.
+ * @SINCE_2_0.7
  */
 struct DALI_SCENE3D_API MeshDefinition
 {
@@ -45,7 +46,12 @@ struct DALI_SCENE3D_API MeshDefinition
     INVALID = std::numeric_limits<uint32_t>::max()
   };
 
-  enum Flags : uint16_t
+  enum : uint32_t
+  {
+    MAX_NUMBER_OF_JOINT_SETS = 4
+  };
+
+  enum Flags : uint32_t
   {
     FLIP_UVS_VERTICAL = NthBit(0),
     U32_INDICES       = NthBit(1), // default is unsigned short
@@ -54,6 +60,26 @@ struct DALI_SCENE3D_API MeshDefinition
     U8_JOINT_IDS      = NthBit(4),
     U16_WEIGHT        = NthBit(5), // default is floats
     U8_WEIGHT         = NthBit(6),
+    S8_POSITION       = NthBit(7),  // default is floats
+    U8_POSITION       = NthBit(8),  // default is floats
+    S16_POSITION      = NthBit(9),  // default is floats
+    U16_POSITION      = NthBit(10), // default is floats
+    S8_NORMAL         = NthBit(11), // default is floats
+    S16_NORMAL        = NthBit(12), // default is floats
+    S8_TANGENT        = NthBit(13), // default is floats
+    S16_TANGENT       = NthBit(14), // default is floats
+    S8_TEXCOORD       = NthBit(15), // default is floats
+    U8_TEXCOORD       = NthBit(16), // default is floats
+    S16_TEXCOORD      = NthBit(17), // default is floats
+    U16_TEXCOORD      = NthBit(18), // default is floats
+  };
+
+  enum FlagMasks : uint32_t
+  {
+    POSITIONS_MASK = 0x780,
+    NORMALS_MASK   = 0x1800,
+    TANGENTS_MASK  = 0x6000,
+    TEXCOORDS_MASK = 0x78000,
   };
 
   enum Attributes
@@ -70,7 +96,9 @@ struct DALI_SCENE3D_API MeshDefinition
 
   /**
    * @brief Describes raw data in terms of its position and size in a buffer.
-   *  All units in bytes.
+   *
+   * All units in bytes.
+   * @SINCE_2_0.7
    */
   struct Blob
   {
@@ -97,11 +125,13 @@ struct DALI_SCENE3D_API MeshDefinition
 
     /**
      * @brief Calculates the size of a tightly-packed buffer for the elements from the blob.
+     * @SINCE_2_0.7
      */
     uint32_t GetBufferSize() const;
 
     /**
      * @brief Convenience method to tell whether a Blob has meaningful data.
+     * @SINCE_2_0.7
      */
     bool IsDefined() const
     {
@@ -109,8 +139,10 @@ struct DALI_SCENE3D_API MeshDefinition
     }
 
     /**
-     * @brief Convenience method to tell whether the elements stored in the blob follow each
-     *  other tightly. The opposite would be interleaving.
+     * @brief Convenience method to tell whether the elements stored in the blob follow each other tightly.
+     *
+     * The opposite would be interleaving.
+     * @SINCE_2_0.7
      */
     bool IsConsecutive() const
     {
@@ -119,8 +151,9 @@ struct DALI_SCENE3D_API MeshDefinition
 
     /**
      * @brief Computes the min / max of the input value data.
-     * The min and max are stored in mMin and mMax.
      *
+     * The min and max are stored in mMin and mMax.
+     * @SINCE_2_0.7
      * @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.
@@ -130,10 +163,10 @@ struct DALI_SCENE3D_API MeshDefinition
     /**
      * @brief Applies the min / max values, if they're defined in the model
      *
+     * @SINCE_2_0.7
      * @param[in] count The number of data.
      * @param[in] values Data for the mesh that min / max values will be applied.
      * @param[in] sparseIndices Pointer to array of sparse indices (or nullptr if not provided)
-     *
      */
     void ApplyMinMax(uint32_t count, float* values, std::vector<uint32_t>* sparseIndices = nullptr) const;
   };
@@ -142,6 +175,7 @@ struct DALI_SCENE3D_API MeshDefinition
    * @brief A sparse blob describes a change in a reference Blob.
    * @p indices describe what positions of the reference Blob change and
    * @p values describe the new values.
+   * @SINCE_2_0.7
    */
   struct SparseBlob
   {
@@ -166,6 +200,7 @@ struct DALI_SCENE3D_API MeshDefinition
     Blob                        mBlob;
     std::unique_ptr<SparseBlob> mSparse;
     Index                       mBufferIdx = INVALID_INDEX;
+    bool                        mNormalized{false};
 
     Accessor() = default;
 
@@ -177,10 +212,13 @@ struct DALI_SCENE3D_API MeshDefinition
 
     Accessor(const MeshDefinition::Blob&       blob,
              const MeshDefinition::SparseBlob& sparse,
-             Index                             bufferIndex = INVALID_INDEX);
+             Index                             bufferIndex = INVALID_INDEX,
+             bool                              normalized = false);
+
     Accessor(MeshDefinition::Blob&&       blob,
              MeshDefinition::SparseBlob&& sparse,
-             Index                        bufferIndex = INVALID_INDEX);
+             Index                        bufferIndex = INVALID_INDEX,
+             bool                         normalized = false);
 
     bool IsDefined() const
     {
@@ -190,6 +228,7 @@ struct DALI_SCENE3D_API MeshDefinition
 
   /**
    * @brief Stores a blend shape.
+   * @SINCE_2_0.7
    */
   struct BlendShape
   {
@@ -198,6 +237,7 @@ struct DALI_SCENE3D_API MeshDefinition
     Accessor    normals;
     Accessor    tangents;
     float       weight = 0.f;
+    uint32_t    mFlags = 0x0;
   };
 
   struct RawData
@@ -230,21 +270,38 @@ struct DALI_SCENE3D_API MeshDefinition
 
   /**
    * @brief Determines whether the mesh definition is that of a quad.
+   * @SINCE_2_0.7
    */
   bool IsQuad() const;
 
   /**
    * @brief Determines whether the mesh is used for skeletal animation.
+   * @SINCE_2_0.7
    */
   bool IsSkinned() const;
 
   /**
+   * @brief Determines if the mesh has any vertex colors
+   */
+  bool HasVertexColor() const;
+
+  /**
+   * @brief Returns the number of joint sets defined by the mesh
+   *
+   * @SINCE_2_2.52
+   * @note Clamped to 4 to minimise GPU attrs.
+   */
+  uint32_t GetNumberOfJointSets() const;
+
+  /**
    * @brief Whether the mesh has blend shapes.
+   * @SINCE_2_0.7
    */
   bool HasBlendShapes() const;
 
   /**
    * @brief Requests normals to be generated.
+   * @SINCE_2_0.7
    * @note Generation happens in LoadRaw().
    * @note Must have Vector3 positions defined.
    */
@@ -252,14 +309,17 @@ struct DALI_SCENE3D_API MeshDefinition
 
   /**
    * @brief Requests tangents to be generated.
+   * @SINCE_2_0.7
    * @note Generation happens in LoadRaw().
    * @note Must have Vector3 normals defined.
    */
   void RequestTangents();
 
   /**
-   * @brief Loads raw geometry data, which includes index (optional) and
-   *  attribute buffers, as well as blend shape data. This is then returned.
+   * @brief Loads raw geometry data, which includes index (optional) and attribute buffers, as well as blend shape data.
+   *
+   * This is then returned.
+   * @SINCE_2_0.7
    * @note This can be done on any thread.
    */
   RawData LoadRaw(const std::string& modelsPath, BufferDefinition::Vector& buffers);
@@ -270,12 +330,14 @@ struct DALI_SCENE3D_API MeshDefinition
    *  attribute (and index) buffers and blend shape information (if available)
    *  from @a raw.
    *  If mFlipVertical was set, the UVs are flipped in Y, i.e. v = 1.0 - v.
+   * @SINCE_2_0.7
    */
   MeshGeometry Load(RawData&& raw) const;
 
   /**
    * @brief Retrieves what Components information is in this mesh's BlendShape.
    *
+   * @SINCE_2_2.21
    * @param[out] hasPositions True if the BlendShape has position components
    * @param[out] hasNormals True if the BlendShape has normal components
    * @param[out] hasTangents True if the BlendShape has tangent components
@@ -289,12 +351,12 @@ public: // DATA
   std::string              mUri; // When the mesh data is loaded from embedded resources, this URI is used as a data stream.
   Accessor                 mIndices;
   Accessor                 mPositions;
-  Accessor                 mNormals; // data can be generated based on positions
-  Accessor                 mTexCoords;
-  Accessor                 mColors;
+  Accessor                 mNormals;  // data can be generated based on positions
   Accessor                 mTangents; // data can be generated based on normals and texCoords (the latter isn't mandatory; the results will be better if available)
-  Accessor                 mJoints0;
-  Accessor                 mWeights0;
+  std::vector<Accessor>    mTexCoords;
+  std::vector<Accessor>    mColors;
+  std::vector<Accessor>    mJoints;
+  std::vector<Accessor>    mWeights;
   Property::Type           mTangentType{Property::VECTOR3};
 
   Blob                    mBlendShapeHeader;