110 lines
4.0 KiB
C++
110 lines
4.0 KiB
C++
#pragma once
|
|
|
|
#include <XCEngine/Core/Asset/IResource.h>
|
|
#include <XCEngine/Core/Containers/Array.h>
|
|
#include <XCEngine/Core/Math/Bounds.h>
|
|
#include <XCEngine/Core/Math/Vector2.h>
|
|
#include <XCEngine/Core/Math/Vector3.h>
|
|
#include <XCEngine/Core/Types.h>
|
|
|
|
namespace XCEngine {
|
|
namespace Resources {
|
|
|
|
class Material;
|
|
class Texture;
|
|
|
|
enum class VertexAttribute : Core::uint32 {
|
|
Position = 1 << 0, Normal = 1 << 1, Tangent = 1 << 2,
|
|
Color = 1 << 3, UV0 = 1 << 4, UV1 = 1 << 5,
|
|
UV2 = 1 << 6, UV3 = 1 << 7, BoneWeights = 1 << 8, BoneIndices = 1 << 9,
|
|
Bitangent = 1 << 10
|
|
};
|
|
|
|
inline VertexAttribute operator|(VertexAttribute a, VertexAttribute b) {
|
|
return static_cast<VertexAttribute>(static_cast<Core::uint32>(a) | static_cast<Core::uint32>(b));
|
|
}
|
|
|
|
inline VertexAttribute operator&(VertexAttribute a, VertexAttribute b) {
|
|
return static_cast<VertexAttribute>(static_cast<Core::uint32>(a) & static_cast<Core::uint32>(b));
|
|
}
|
|
|
|
inline bool HasVertexAttribute(VertexAttribute attributes, VertexAttribute flag) {
|
|
return (static_cast<Core::uint32>(attributes) & static_cast<Core::uint32>(flag)) != 0;
|
|
}
|
|
|
|
struct StaticMeshVertex {
|
|
Math::Vector3 position = Math::Vector3::Zero();
|
|
Math::Vector3 normal = Math::Vector3::Zero();
|
|
Math::Vector3 tangent = Math::Vector3::Zero();
|
|
Math::Vector3 bitangent = Math::Vector3::Zero();
|
|
Math::Vector2 uv0 = Math::Vector2::Zero();
|
|
};
|
|
|
|
struct MeshSection {
|
|
Core::uint32 baseVertex;
|
|
Core::uint32 vertexCount;
|
|
Core::uint32 startIndex;
|
|
Core::uint32 indexCount;
|
|
Core::uint32 materialID;
|
|
Math::Bounds bounds;
|
|
};
|
|
|
|
class Mesh : public IResource {
|
|
public:
|
|
Mesh();
|
|
virtual ~Mesh() override;
|
|
|
|
ResourceType GetType() const override { return ResourceType::Mesh; }
|
|
const Containers::String& GetName() const override { return m_name; }
|
|
const Containers::String& GetPath() const override { return m_path; }
|
|
ResourceGUID GetGUID() const override { return m_guid; }
|
|
bool IsValid() const override { return m_isValid; }
|
|
size_t GetMemorySize() const override { return m_memorySize; }
|
|
void Release() override;
|
|
|
|
void SetVertexData(const void* data, size_t size, Core::uint32 vertexCount,
|
|
Core::uint32 vertexStride, VertexAttribute attributes);
|
|
const void* GetVertexData() const { return m_vertexData.Data(); }
|
|
size_t GetVertexDataSize() const { return m_vertexData.Size(); }
|
|
Core::uint32 GetVertexCount() const { return m_vertexCount; }
|
|
Core::uint32 GetVertexStride() const { return m_vertexStride; }
|
|
VertexAttribute GetVertexAttributes() const { return m_attributes; }
|
|
|
|
void SetIndexData(const void* data, size_t size, Core::uint32 indexCount, bool use32Bit);
|
|
const void* GetIndexData() const { return m_indexData.Data(); }
|
|
size_t GetIndexDataSize() const { return m_indexData.Size(); }
|
|
Core::uint32 GetIndexCount() const { return m_indexCount; }
|
|
bool IsUse32BitIndex() const { return m_use32BitIndex; }
|
|
|
|
void SetBounds(const Math::Bounds& bounds) { m_bounds = bounds; }
|
|
const Math::Bounds& GetBounds() const { return m_bounds; }
|
|
|
|
void AddSection(const MeshSection& section);
|
|
void AddMaterial(Material* material);
|
|
void AddTexture(Texture* texture);
|
|
const Containers::Array<MeshSection>& GetSections() const { return m_sections; }
|
|
const Containers::Array<Material*>& GetMaterials() const { return m_materials; }
|
|
const Containers::Array<Texture*>& GetTextures() const { return m_textures; }
|
|
Material* GetMaterial(Core::uint32 index) const;
|
|
|
|
private:
|
|
void UpdateMemorySize();
|
|
|
|
Core::uint32 m_vertexCount = 0;
|
|
Core::uint32 m_vertexStride = 0;
|
|
VertexAttribute m_attributes = VertexAttribute::Position;
|
|
|
|
Core::uint32 m_indexCount = 0;
|
|
bool m_use32BitIndex = false;
|
|
|
|
Containers::Array<Core::uint8> m_vertexData;
|
|
Containers::Array<Core::uint8> m_indexData;
|
|
Containers::Array<MeshSection> m_sections;
|
|
Containers::Array<Material*> m_materials;
|
|
Containers::Array<Texture*> m_textures;
|
|
Math::Bounds m_bounds;
|
|
};
|
|
|
|
} // namespace Resources
|
|
} // namespace XCEngine
|