diff --git a/src/Magnum/Trade/MeshData.cpp b/src/Magnum/Trade/MeshData.cpp index a4a949bc2..658438945 100644 --- a/src/Magnum/Trade/MeshData.cpp +++ b/src/Magnum/Trade/MeshData.cpp @@ -777,6 +777,18 @@ Containers::Array MeshData::objectIdsAsArray(const UnsignedInt id) return out; } +Containers::Array MeshData::weightsAsArray(const UnsignedInt id) const { + Containers::Array out{_vertexCount}; + weightsInto(out, id); + return out; +} + +Containers::Array MeshData::jointIndicesAsArray(const UnsignedInt id) const { + Containers::Array out{_vertexCount}; + jointIndicesInto(out, id); + return out; +} + Containers::Array MeshData::releaseIndexData() { _indexCount = 0; Containers::Array out = std::move(_indexData); diff --git a/src/Magnum/Trade/MeshData.h b/src/Magnum/Trade/MeshData.h index 6e155a216..632133952 100644 --- a/src/Magnum/Trade/MeshData.h +++ b/src/Magnum/Trade/MeshData.h @@ -147,6 +147,24 @@ enum class MeshAttribute: UnsignedShort { */ ObjectId, + /** + * Weights. Type is usually @ref VertexFormat::Vector4, but can be also + * @ref VertexFormat::Vector4h, @ref VertexFormat::Vector4bNormalized or + * @ref VertexFormat::Vector4sNormalized. Corresponds to + * @ref Shaders::Generic::Weights. + * @see @ref MeshData::weightsAsArray() + */ + Weights, + + /** + * JointIndices. Type is usually @ref VertexFormat::Vector4ui, but can be also + * @ref VertexFormat::Vector4i, @ref VertexFormat::Vector4s, @ref VertexFormat::Vector4us, + * @ref VertexFormat::Vector4ub or @ref VertexFormat::Vector4b. Corresponds to + * @ref Shaders::Generic::JointIndices. + * @see @ref MeshData::jointIndicesAsArray() + */ + JointIndices, + /** * This and all higher values are for importer-specific attributes. Can be * of any type. See documentation of a particular importer for details. @@ -613,10 +631,11 @@ the @ref Primitives library. The simplest usage is through the convenience functions @ref positions2DAsArray(), @ref positions3DAsArray(), @ref tangentsAsArray(), @ref bitangentsAsArray(), @ref normalsAsArray(), @ref tangentsAsArray(), @ref textureCoordinates2DAsArray(), -@ref colorsAsArray() and @ref objectIdsAsArray(). Each of these takes an index -(as there can be multiple sets of texture coordinates, for example) and you're -expected to check for attribute presence first with either @ref hasAttribute() -or @ref attributeCount(MeshAttribute) const: +@ref colorsAsArray(), @ref objectIdsAsArray(), @ref weightsAsArray() and +@ref jointIndicesAsArray(). Each of these takes an index (as there can be multiple +sets of texture coordinates, for example) and you're expected to check for +attribute presence first with either @ref hasAttribute() or +@ref attributeCount(MeshAttribute) const: @snippet MagnumTrade.cpp MeshData-usage @@ -1717,6 +1736,54 @@ class MAGNUM_TRADE_EXPORT MeshData { */ void objectIdsInto(Containers::StridedArrayView1D destination, UnsignedInt id = 0) const; + /** + * @brief Weights as 4D float vectors + * + * Convenience alternative to @ref attribute(MeshAttribute, UnsignedInt) const + * with @ref MeshAttribute::Weights as the first argument. Converts + * the weights array from an arbitrary underlying type and returns it + * in a newly-allocated array. Expects that the vertex format is *not* + * implementation-specific, in that case you can only access the + * attribute via the typeless @ref attribute(MeshAttribute, UnsignedInt) const. + * @see @ref weightsInto(), @ref attributeFormat(), + * @ref isVertexFormatImplementationSpecific() + */ + Containers::Array weightsAsArray(UnsignedInt id = 0) const; + + /** + * @brief Weights as 4D float vectors into a pre-allocated view + * + * Like @ref weightsAsArray(), but puts the result into + * @p destination instead of allocating a new array. Expects that + * @p destination is sized to contain exactly all data. + * @see @ref vertexCount() + */ + void weightsInto(Containers::StridedArrayView1D destination, UnsignedInt id = 0) const; + + /** + * @brief Weights as 4D unsigned short vectors + * + * Convenience alternative to @ref attribute(MeshAttribute, UnsignedInt) const + * with @ref MeshAttribute::JointIndices as the first argument. Converts + * the joint indices array from an arbitrary underlying type and returns it + * in a newly-allocated array. Expects that the vertex format is *not* + * implementation-specific, in that case you can only access the + * attribute via the typeless @ref attribute(MeshAttribute, UnsignedInt) const. + * @see @ref jointIndicesInto(), @ref attributeFormat(), + * @ref isVertexFormatImplementationSpecific() + */ + Containers::Array jointIndicesAsArray(UnsignedInt id = 0) const; + + /** + * @brief Weights as 4D unsigned short vectors into a pre-allocated view + * + * Like @ref jointIndicesAsArray(), but puts the result into + * @p destination instead of allocating a new array. Expects that + * @p destination is sized to contain exactly all data. + * @see @ref vertexCount() + */ + void jointIndicesInto(Containers::StridedArrayView1D destination, UnsignedInt id = 0) const; + /** * @brief Release index data storage *