| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #pragma once
- #include <anki/resource/Common.h>
- #include <anki/Math.h>
- #include <anki/util/Enum.h>
- namespace anki
- {
- /// @addtogroup resource
- /// @{
- /// Mesh data. This class loads the mesh file and the Mesh class loads it to
- /// the GPU.
- class MeshLoader
- {
- public:
- /// Type of the components.
- enum class ComponentFormat : U32
- {
- NONE,
- R8,
- R8G8,
- R8G8B8,
- R8G8B8A8,
- R16,
- R16G16,
- R16G16B16,
- R16G16B16A16,
- R32,
- R32G32,
- R32G32B32,
- R32G32B32A32,
- R10G10B10A2,
- COUNT
- };
- enum class FormatTransform : U32
- {
- NONE,
- UNORM,
- SNORM,
- UINT,
- SINT,
- FLOAT,
- COUNT
- };
- struct Format
- {
- ComponentFormat m_components = ComponentFormat::NONE;
- FormatTransform m_transform = FormatTransform::NONE;
- };
- enum class Flag : U32
- {
- NONE = 0,
- QUADS = 1 << 0
- };
- ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(Flag, friend);
- struct Header
- {
- Array<U8, 8> m_magic; ///< Magic word.
- U32 m_flags;
- U32 m_flags2;
- Format m_positionsFormat;
- Format m_normalsFormat;
- Format m_tangentsFormat;
- Format m_colorsFormat; ///< Vertex color.
- Format m_uvsFormat;
- Format m_boneWeightsFormat;
- Format m_boneIndicesFormat;
- Format m_indicesFormat; ///< Vertex indices.
- U32 m_totalIndicesCount;
- U32 m_totalVerticesCount;
- /// Number of UV sets. Eg one for normal diffuse and another for
- /// lightmaps.
- U32 m_uvsChannelCount;
- U32 m_subMeshCount;
- U8 m_padding[32];
- };
- static_assert(sizeof(Header) == 128, "Check size of struct");
- class SubMesh
- {
- public:
- U32 m_firstIndex = 0;
- U32 m_indicesCount = 0;
- };
- MeshLoader(ResourceManager* manager)
- : m_manager(manager)
- {
- }
- ~MeshLoader();
- ANKI_USE_RESULT Error load(const ResourceFilename& filename);
- const Header& getHeader() const
- {
- ANKI_ASSERT(isLoaded());
- return m_header;
- }
- const U8* getVertexData() const
- {
- ANKI_ASSERT(isLoaded());
- return &m_verts[0];
- }
- PtrSize getVertexDataSize() const
- {
- ANKI_ASSERT(isLoaded());
- return m_verts.getSizeInBytes();
- }
- PtrSize getVertexSize() const
- {
- ANKI_ASSERT(isLoaded());
- return m_vertSize;
- }
- const U8* getIndexData() const
- {
- ANKI_ASSERT(isLoaded());
- return &m_indices[0];
- }
- PtrSize getIndexDataSize() const
- {
- ANKI_ASSERT(isLoaded());
- return m_indices.getSizeInBytes();
- }
- Bool hasBoneInfo() const
- {
- ANKI_ASSERT(isLoaded());
- return m_header.m_boneWeightsFormat.m_components
- != ComponentFormat::NONE;
- }
- private:
- template<typename T>
- using MDArray = DArray<T>;
- ResourceManager* m_manager;
- Header m_header;
- MDArray<U8> m_verts;
- MDArray<U8> m_indices;
- MDArray<SubMesh> m_subMeshes;
- U8 m_vertSize = 0;
- Bool isLoaded() const
- {
- return m_verts.getSize() > 0;
- }
- static ANKI_USE_RESULT Error checkFormat(
- const Format& fmt, const CString& attrib, Bool cannotBeEmpty);
- };
- /// @}
- } // end namespace anki
|