Volume.h#

Contains an implementation of Volume generation.

Includes#

  • PVRAssets/model/Mesh.h

Included By#

Namespaces#

Classes#

Source Code#

#pragma once

#include "PVRAssets/model/Mesh.h"

namespace pvr {

class Volume
{
public:
    struct VolumeEdge
    {
        uint32_t vertexIndices[2];
        uint32_t visibilityFlags;
    };

    struct VolumeTriangle
    {
        uint32_t vertexIndices[3];
        uint32_t edgeIndices[3];
        glm::vec3 normal;
        int32_t winding;
    };

    struct VolumeMesh
    {
        glm::vec3* vertices;
        VolumeEdge* edges;
        VolumeTriangle* triangles;
        glm::vec3 minimum;
        glm::vec3 maximum;
        uint32_t numVertices;
        uint32_t numEdges;
        uint32_t numTriangles;

        uint8_t* vertexData;

        bool needs32BitIndices;

        VolumeMesh() : vertices(nullptr), edges(nullptr), triangles(nullptr), numVertices(0), numEdges(0), numTriangles(0), vertexData(nullptr), needs32BitIndices(false) {}
    };

    virtual ~Volume();

    bool init(const assets::Mesh& mesh);

    bool init(const uint8_t* const data, uint32_t numVertices, uint32_t verticesStride, DataType vertexType, const uint8_t* const faceData, uint32_t numFaces, IndexType indexType);

    uint32_t getVertexDataSize();

    uint32_t getVertexDataStride();

    uint32_t getVertexDataPositionOffset();

    uint32_t getVertexDataExtrudeOffset();

    uint8_t* getVertexData();

    uint32_t getIndexDataSize();

    uint32_t getIndexDataStride();

    uint32_t getTriangleCount();

    VolumeTriangle getTriangleData(uint32_t triangleIndex);

    void getVerticesForTriangle(const VolumeTriangle& triangle, glm::vec3& vertex0, glm::vec3& vertex1, glm::vec3& vertex2);

    bool isVolumeClosed();

protected:
    uint32_t findOrCreateVertex(const glm::vec3& vertex, bool& existed);

    uint32_t findOrCreateEdge(const glm::vec3& v0, const glm::vec3& v1, bool& existed);

    void findOrCreateTriangle(const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2);

    VolumeMesh _volumeMesh;

    bool _isClosed;
};
} // namespace pvr