Browse Source

[WIP] Trade: Implement support for Weights & JointIndices in MeshData.

Signed-off-by: Squareys <squareys@googlemail.com>
pull/444/head
Squareys 6 years ago
parent
commit
17931de06e
  1. 12
      src/Magnum/Trade/MeshData.cpp
  2. 75
      src/Magnum/Trade/MeshData.h

12
src/Magnum/Trade/MeshData.cpp

@ -777,6 +777,18 @@ Containers::Array<UnsignedInt> MeshData::objectIdsAsArray(const UnsignedInt id)
return out;
}
Containers::Array<Vector4> MeshData::weightsAsArray(const UnsignedInt id) const {
Containers::Array<Vector4> out{_vertexCount};
weightsInto(out, id);
return out;
}
Containers::Array<Vector4us> MeshData::jointIndicesAsArray(const UnsignedInt id) const {
Containers::Array<Vector4us> out{_vertexCount};
jointIndicesInto(out, id);
return out;
}
Containers::Array<char> MeshData::releaseIndexData() {
_indexCount = 0;
Containers::Array<char> out = std::move(_indexData);

75
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<UnsignedInt> 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<Vector4> 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<Vector4> 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<Vector4us> 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<Vector4us> destination, UnsignedInt id = 0) const;
/**
* @brief Release index data storage
*

Loading…
Cancel
Save