Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
MeshImporter.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the
14Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27IN CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_MESH_IMPORTER_H_
34#define DVD_MESH_IMPORTER_H_
35
40
41namespace Divide {
42 enum class GeometryFormat : U8
43 {
44 _3DS = 0, //Studio max format
45 ASE, //ASCII Scene Export. Old Unreal format
46 FBX,
47 MD2,
48 MD5,
49 OBJ,
50 X, //DirectX format
51 DAE, //Collada
52 GLTF,
55 COUNT
56 };
57
58 GeometryFormat GetGeometryFormatForExtension(const char* extension) noexcept;
59
60 const char* const g_geometryExtensions[] = {
61 "3ds", "ase", "fbx", "md2", "md5mesh", "obj", "x", "dae", "gltf", "glb", "DVDAnim", "DVDGeom"
62 };
63
64 class PlatformContext;
65 class ByteBuffer;
66 class VertexBuffer;
67 namespace Import {
68 constexpr U8 MAX_LOD_LEVELS = 3;
69
70 struct TextureEntry {
71 bool serialize(ByteBuffer& dataOut) const;
72 bool deserialize(ByteBuffer& dataIn);
73
74 PROPERTY_RW(Str<256>, textureName);
76
77 // Only Albedo/Diffuse should be sRGB
78 // Normals, specular, etc should be in linear space
79 PROPERTY_RW(bool, srgb, false);
80 PROPERTY_RW(bool, useDDSCache, false);
81 PROPERTY_RW(bool, isNormalMap, false);
82 PROPERTY_RW(bool, alphaForTransparency, false);
87 };
88
89 struct MaterialData {
90 bool serialize(ByteBuffer& dataOut) const;
91 bool deserialize(ByteBuffer& dataIn);
92
94
95 PROPERTY_RW(bool, ignoreTexDiffuseAlpha, false);
96 PROPERTY_RW(bool, doubleSided, true);
100
106 PROPERTY_RW(F32, metallic, 0.0f);
107 PROPERTY_RW(F32, roughness, 1.0f);
108 PROPERTY_RW(F32, parallaxFactor, 1.0f);
110 };
111
112 struct SubMeshData {
113 struct Vertex {
114 vec3<F32> position = {0.f, 0.f, 0.f };
115 vec3<F32> normal = {0.f, 0.f, 0.f };
116 vec4<F32> tangent = { 0.f, 0.f, 0.f, 0.f };
117 vec3<F32> texcoord = { 0.f, 0.f, 0.f };
118 vec4<F32> weights = {0.f, 0.f, 0.f, 0.f};
119 vec4<U8> indices = {0u, 0u, 0u, 0u};
120 };
121
122 bool serialize(ByteBuffer& dataOut) const;
123 bool deserialize(ByteBuffer& dataIn);
124
126 PROPERTY_RW(U32, index, 0u);
127 PROPERTY_RW(U8, lodCount, 0u);
128 PROPERTY_RW(U8, boneCount, 0u);
131 PROPERTY_RW(vec3<F32>, worldOffset);
132
133 std::array<U16, MAX_LOD_LEVELS> _partitionIDs{};
137
139
141 };
142
144 {
145 ImportData(ResourcePath modelPath, const std::string_view modelName) noexcept
146 : _modelName(modelName)
147 , _modelPath(MOV(modelPath))
148 {
149 }
150
151 bool saveToFile(PlatformContext& context, const ResourcePath& path, std::string_view fileName);
152 bool loadFromFile(PlatformContext& context, const ResourcePath& path, std::string_view fileName);
153
154 Bone* _skeleton = nullptr;
155
156 // Was it loaded from file, or just created?
157 PROPERTY_RW(bool, loadedFromFile, false);
158 // Geometry
159 VertexBuffer_ptr _vertexBuffer = nullptr;
160
161 // Name and path
164 PROPERTY_RW(bool, fromFile, false);
168
169 size_t _animationCount{0u};
171 };
172 };
173
175
177 {
178 public:
179 static bool loadMesh( PlatformContext& context, ResourcePtr<Mesh> mesh );
180
181 protected:
182 static bool loadMeshDataFromFile( PlatformContext& context, Import::ImportData& dataOut);
183 static Handle<Material> loadSubMeshMaterial(const Import::MaterialData& importData, bool loadedFromCache, bool skinned, std::atomic_uint& taskCounter);
184 };
185
186}; // namespace Divide
187
188#endif //DVD_MESH_IMPORTER_H_
#define MOV(...)
#define FWD_DECLARE_MANAGED_CLASS(T)
static bool loadMesh(PlatformContext &context, ResourcePtr< Mesh > mesh)
static Handle< Material > loadSubMeshMaterial(const Import::MaterialData &importData, bool loadedFromCache, bool skinned, std::atomic_uint &taskCounter)
Load the material for the current SubMesh.
static bool loadMeshDataFromFile(PlatformContext &context, Import::ImportData &dataOut)
FColour4 WHITE
Random stuff added for convenience.
Definition: Colours.cpp:8
constexpr U8 MAX_LOD_LEVELS
Definition: MeshImporter.h:68
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
std::array< bool, to_base(AttribLocation::COUNT)> AttributeFlags
T * ResourcePtr
Definition: Resource.h:112
const char *const g_geometryExtensions[]
Definition: MeshImporter.h:60
uint8_t U8
GeometryFormat
Definition: MeshImporter.h:43
GeometryFormat GetGeometryFormatForExtension(const char *extension) noexcept
TextureOperation
How should each texture be added.
eastl::vector< Type > vector
Definition: Vector.h:42
uint32_t U32
constexpr auto to_base(const Type value) -> Type
VertexBuffer_ptr _vertexBuffer
Definition: MeshImporter.h:159
vector< SubMeshData > _subMeshData
Definition: MeshImporter.h:167
ImportData(ResourcePath modelPath, const std::string_view modelName) noexcept
Definition: MeshImporter.h:145
Divide::MeshNodeData _nodeData
Definition: MeshImporter.h:166
PROPERTY_RW(ResourcePath, modelPath)
PROPERTY_RW(bool, loadedFromFile, false)
PROPERTY_RW(bool, fromFile, false)
vector< Bone * > _bones
Definition: MeshImporter.h:165
bool loadFromFile(PlatformContext &context, const ResourcePath &path, std::string_view fileName)
vector< AnimEvaluator * > _animations
Definition: MeshImporter.h:170
bool saveToFile(PlatformContext &context, const ResourcePath &path, std::string_view fileName)
PROPERTY_RW(Str< 256 >, modelName)
PROPERTY_RW(bool, doubleSided, true)
bool deserialize(ByteBuffer &dataIn)
PROPERTY_RW(BumpMethod, bumpMethod, BumpMethod::NONE)
PROPERTY_RW(bool, ignoreTexDiffuseAlpha, false)
bool serialize(ByteBuffer &dataOut) const
PROPERTY_RW(Str< 128 >, name)
PROPERTY_RW(SpecularGlossiness, specGloss)
PROPERTY_RW(FColour3, emissive, DefaultColours::BLACK)
PROPERTY_RW(ShadingMode, shadingMode, ShadingMode::FLAT)
PROPERTY_RW(FColour4, specular, DefaultColours::BLACK)
PROPERTY_RW(F32, roughness, 1.0f)
PROPERTY_RW(F32, metallic, 0.0f)
PROPERTY_RW(FColour4, baseColour, DefaultColours::WHITE)
PROPERTY_RW(FColour3, ambient, DefaultColours::BLACK)
std::array< TextureEntry, to_base(TextureSlot::COUNT)> _textures
Definition: MeshImporter.h:109
PROPERTY_RW(F32, parallaxFactor, 1.0f)
vector< Vertex > _vertices[MAX_LOD_LEVELS]
Definition: MeshImporter.h:136
vector< U32 > _indices[MAX_LOD_LEVELS]
Definition: MeshImporter.h:135
vector< vec3< U32 > > _triangles[MAX_LOD_LEVELS]
Definition: MeshImporter.h:134
AttributeFlags _useAttribute
Definition: MeshImporter.h:138
PROPERTY_RW(Str< 64 >, name)
PROPERTY_RW(U8, boneCount, 0u)
std::array< U16, MAX_LOD_LEVELS > _partitionIDs
Definition: MeshImporter.h:133
bool serialize(ByteBuffer &dataOut) const
PROPERTY_RW(U8, lodCount, 0u)
PROPERTY_RW(U32, index, 0u)
PROPERTY_RW(vec3< F32 >, maxPos)
bool deserialize(ByteBuffer &dataIn)
PROPERTY_RW(vec3< F32 >, worldOffset)
PROPERTY_RW(vec3< F32 >, minPos)
Definition: MeshImporter.h:70
PROPERTY_RW(TextureWrap, wrapV, TextureWrap::REPEAT)
bool serialize(ByteBuffer &dataOut) const
PROPERTY_RW(Str< 256 >, textureName)
PROPERTY_RW(bool, alphaForTransparency, false)
PROPERTY_RW(ResourcePath, texturePath)
bool deserialize(ByteBuffer &dataIn)
PROPERTY_RW(TextureWrap, wrapW, TextureWrap::REPEAT)
PROPERTY_RW(TextureWrap, wrapU, TextureWrap::REPEAT)
PROPERTY_RW(bool, srgb, false)
PROPERTY_RW(TextureOperation, operation, TextureOperation::NONE)
PROPERTY_RW(bool, useDDSCache, false)
PROPERTY_RW(bool, isNormalMap, false)