X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-scene3d%2Fpublic-api%2Floader%2Fmesh-definition.h;h=911359c4b84894e71f77dbfabd09ebab82478092;hb=HEAD;hp=4e72719ba71b122e7531eed0285e7bcce1127a7d;hpb=026a32be68bfde3ccce97b366b1098df731354e4;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-scene3d/public-api/loader/mesh-definition.h b/dali-scene3d/public-api/loader/mesh-definition.h index 4e72719..911359c 100644 --- a/dali-scene3d/public-api/loader/mesh-definition.h +++ b/dali-scene3d/public-api/loader/mesh-definition.h @@ -17,27 +17,25 @@ * */ -// INTERNAL INCLUDES -#include "dali-scene3d/public-api/api.h" -#include "dali-scene3d/public-api/loader/blend-shape-details.h" -#include "dali-scene3d/public-api/loader/index.h" -#include "dali-scene3d/public-api/loader/mesh-geometry.h" -#include "dali-scene3d/public-api/loader/utils.h" - // EXTERNAL INCLUDES +#include #include -#include "dali/public-api/common/vector-wrapper.h" -namespace Dali -{ -namespace Scene3D -{ -namespace Loader +// INTERNAL INCLUDES +#include +#include +#include +#include +#include +#include + +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 { @@ -48,12 +46,40 @@ struct DALI_SCENE3D_API MeshDefinition INVALID = std::numeric_limits::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 - U16_JOINT_IDS = NthBit(2), // default is floats - U8_JOINT_IDS = NthBit(3), + U8_INDICES = NthBit(2), // default is unsigned short + U16_JOINT_IDS = NthBit(3), // default is floats + 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 { @@ -83,7 +111,7 @@ struct DALI_SCENE3D_API MeshDefinition 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); + static void ApplyMinMax(const std::vector& min, const std::vector& max, uint32_t count, float* values, std::vector* sparseIndices = nullptr); Blob() = default; @@ -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,16 +163,19 @@ 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) const; + void ApplyMinMax(uint32_t count, float* values, std::vector* sparseIndices = nullptr) const; }; /** * @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 { @@ -163,6 +199,8 @@ struct DALI_SCENE3D_API MeshDefinition { Blob mBlob; std::unique_ptr mSparse; + Index mBufferIdx = INVALID_INDEX; + bool mNormalized{false}; Accessor() = default; @@ -173,9 +211,14 @@ struct DALI_SCENE3D_API MeshDefinition Accessor& operator=(Accessor&&) = default; Accessor(const MeshDefinition::Blob& blob, - const MeshDefinition::SparseBlob& sparse); + const MeshDefinition::SparseBlob& sparse, + Index bufferIndex = INVALID_INDEX, + bool normalized = false); + Accessor(MeshDefinition::Blob&& blob, - MeshDefinition::SparseBlob&& sparse); + MeshDefinition::SparseBlob&& sparse, + Index bufferIndex = INVALID_INDEX, + bool normalized = false); bool IsDefined() const { @@ -185,6 +228,7 @@ struct DALI_SCENE3D_API MeshDefinition /** * @brief Stores a blend shape. + * @SINCE_2_0.7 */ struct BlendShape { @@ -193,6 +237,7 @@ struct DALI_SCENE3D_API MeshDefinition Accessor normals; Accessor tangents; float weight = 0.f; + uint32_t mFlags = 0x0; }; struct RawData @@ -225,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. */ @@ -247,17 +309,20 @@ 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); + RawData LoadRaw(const std::string& modelsPath, BufferDefinition::Vector& buffers); /** * @brief Creates a MeshGeometry based firstly on the value of the uri member: @@ -265,33 +330,43 @@ 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 + */ + void RetrieveBlendShapeComponents(bool& hasPositions, bool& hasNormals, bool& hasTangents) const; + public: // DATA std::shared_ptr mRawData; uint32_t mFlags = 0x0; Geometry::Type mPrimitiveType = Geometry::TRIANGLES; - std::string mUri; + 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 mTexCoords; + std::vector mColors; + std::vector mJoints; + std::vector mWeights; Property::Type mTangentType{Property::VECTOR3}; Blob mBlendShapeHeader; std::vector mBlendShapes; BlendShapes::Version mBlendShapeVersion = BlendShapes::Version::INVALID; - Index mSkeletonIdx = INVALID_INDEX; + Index mSkeletonIdx = INVALID_INDEX; + ModelPrimitive mModelPrimitive; }; -} // namespace Loader -} // namespace Scene3D -} // namespace Dali +} // namespace Dali::Scene3D::Loader #endif //DALI_SCENE3D_LOADER_MESH_DEFINITION_H