Struct Mesh

Synopsis

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

struct Mesh

Description

Mesh description

Mentioned in

Structures

Attribute
Vertex

Methods

get
getNormal
getPosition
getTangent
getTexCrd
getVertex
hasBones

Source

Lines 58-144 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.
    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{};
    }
    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 to DocsForge