Struct Mesh

Synopsis

#include <Source/Falcor/Scene/SceneBuilder.h>

struct Mesh

Description

Mesh description. This struct is used by the importers to add new meshes. The description is then processed by the scene builder into an optimized runtime format. The frequency of each vertex attribute is specified individually, but note that an index list is always required.

Mentioned in

Structures

Attribute
Vertex

Methods

get
getAttributeCount
getNormal
getPosition
getTangent
getTexCrd
getVertex
hasBones

Source

Lines 73-181 in Source/Falcor/Scene/SceneBuilder.h.

struct Mesh
{
    enum class AttributeFrequency
    {
        None,
        Constant,       ///< Constant value for mesh. The element count must be 1.
        Uniform,        ///< One value per face. The element count must match `faceCount`.
        Vertex,         ///< One value per vertex. The element count must match `vertexCount`.
        FaceVarying,    ///< One value per vertex per face. The element count must match `indexCount`.
    };
    template<typename T>
    struct Attribute
    {
        const T* pData = nullptr;
        AttributeFrequency frequency = AttributeFrequency::None;
    };
    std::string name;                           ///< The mesh's name.
    uint32_t faceCount = 0;                     ///< The number of primitives the mesh has.
    uint32_t vertexCount = 0;                   ///< The number of vertices the mesh has.
    uint32_t indexCount = 0;                    ///< The number of indices the mesh has.
    const uint32_t* pIndices = nullptr;         ///< Array of indices. The element count must match `indexCount`. This field is required.
    Vao::Topology topology = Vao::Topology::Undefined; ///< The primitive topology of the mesh
    Material::SharedPtr pMaterial;              ///< The mesh's material. Can't be nullptr.
    Attribute<float3> positions;                ///< Array of vertex positions. This field is required.
    Attribute<float3> normals;                  ///< Array of vertex normals. This field is required.
    Attribute<float4> tangents;                 ///< Array of vertex tangents. This field is optional. If set to nullptr, or if BuildFlags::UseOriginalTangentSpace is not set, the tangent space will be generated using MikkTSpace.
    Attribute<float2> texCrds;                  ///< Array of vertex texture coordinates. This field is optional. If set to nullptr, all texCrds will be set to (0,0).
    Attribute<uint4> boneIDs;                   ///< Array of bone IDs. This field is optional. If it's set, that means that the mesh is animated, in which case boneWeights is required.
    Attribute<float4> boneWeights;              ///< Array of bone weights. This field is optional. If it's set, that means that the mesh is animated, in which case boneIDs is required.
    bool isFrontFaceCW = false;                 ///< Indicate whether front-facing side has clockwise winding in object space.
    bool useOriginalTangentSpace = false;       ///< Indicate whether to use the original tangent space that was loaded with the mesh. By default, we will ignore it and use MikkTSpace to generate the tangent space.
    template<typename T>
    T get(const Attribute<T>& attribute, uint32_t face, uint32_t vert) const
    {
        if (attribute.pData)
        {
            switch (attribute.frequency)
            {
            case AttributeFrequency::Constant:
                return attribute.pData[0];
            case AttributeFrequency::Uniform:
                return attribute.pData[face];
            case AttributeFrequency::Vertex:
                return attribute.pData[pIndices[face * 3 + vert]];
            case AttributeFrequency::FaceVarying:
                return attribute.pData[face * 3 + vert];
            default:
                should_not_get_here();
            }
        }
        return T{};
    }
    template<typename T>
    size_t getAttributeCount(const Attribute<T>& attribute)
    {
        switch (attribute.frequency)
        {
        case AttributeFrequency::Constant:
            return 1;
        case AttributeFrequency::Uniform:
            return faceCount;
        case AttributeFrequency::Vertex:
            return vertexCount;
        case AttributeFrequency::FaceVarying:
            return 3 * faceCount;
        default:
            should_not_get_here();
        }
        return 0;
    }
    float3 getPosition(uint32_t face, uint32_t vert) const { return get(positions, face, vert); }
    float3 getNormal(uint32_t face, uint32_t vert) const { return get(normals, face, vert); }
    float4 getTangent(uint32_t face, uint32_t vert) const { return get(tangents, face, vert); }
    float2 getTexCrd(uint32_t face, uint32_t vert) const { return get(texCrds, face, vert); }
    struct Vertex
    {
        float3 position;
        float3 normal;
        float4 tangent;
        float2 texCrd;
        uint4 boneIDs;
        float4 boneWeights;
    };
    Vertex getVertex(uint32_t face, uint32_t vert) const
    {
        Vertex v = {};
        v.position = get(positions, face, vert);
        v.normal = get(normals, face, vert);
        v.tangent = get(tangents, face, vert);
        v.texCrd = get(texCrds, face, vert);
        v.boneIDs = get(boneIDs, face, vert);
        v.boneWeights = get(boneWeights, face, vert);
        return v;
    }
    bool hasBones() const
    {
        return boneWeights.pData || boneIDs.pData;
    }
};





Add Discussion as Guest

Log in