Remove Utility module and move its content to Core and TextRenderer modules
This commit is contained in:
committed by
Jérôme Leclercq
parent
965a00182c
commit
e64c2b036e
83
include/Nazara/Core/Formats/MD5AnimParser.hpp
Normal file
83
include/Nazara/Core/Formats/MD5AnimParser.hpp
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_FORMATS_MD5ANIMPARSER_HPP
|
||||
#define NAZARA_CORE_FORMATS_MD5ANIMPARSER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Stream;
|
||||
|
||||
class NAZARA_CORE_API MD5AnimParser
|
||||
{
|
||||
public:
|
||||
struct FrameJoint
|
||||
{
|
||||
Quaternionf orient;
|
||||
Vector3f pos;
|
||||
};
|
||||
|
||||
struct Frame
|
||||
{
|
||||
std::vector<FrameJoint> joints;
|
||||
Boxf bounds;
|
||||
};
|
||||
|
||||
struct Joint
|
||||
{
|
||||
std::string name;
|
||||
Int32 parent;
|
||||
Quaternionf bindOrient;
|
||||
Vector3f bindPos;
|
||||
UInt32 flags;
|
||||
UInt32 index;
|
||||
};
|
||||
|
||||
MD5AnimParser(Stream& stream);
|
||||
~MD5AnimParser();
|
||||
|
||||
bool Check();
|
||||
|
||||
UInt32 GetAnimatedComponentCount() const;
|
||||
const Frame* GetFrames() const;
|
||||
UInt32 GetFrameCount() const;
|
||||
UInt32 GetFrameRate() const;
|
||||
const Joint* GetJoints() const;
|
||||
UInt32 GetJointCount() const;
|
||||
|
||||
bool Parse();
|
||||
|
||||
private:
|
||||
bool Advance(bool required = true);
|
||||
void Error(std::string_view message);
|
||||
bool ParseBaseframe();
|
||||
bool ParseBounds();
|
||||
bool ParseFrame();
|
||||
bool ParseHierarchy();
|
||||
void Warning(std::string_view message);
|
||||
void UnrecognizedLine(bool error = false);
|
||||
|
||||
std::vector<float> m_animatedComponents;
|
||||
std::vector<Frame> m_frames;
|
||||
std::vector<Joint> m_joints;
|
||||
Stream& m_stream;
|
||||
StreamOptionFlags m_streamFlags;
|
||||
std::string m_currentLine;
|
||||
bool m_keepLastLine;
|
||||
unsigned int m_frameIndex;
|
||||
unsigned int m_frameRate;
|
||||
unsigned int m_lineCount;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_FORMATS_MD5ANIMPARSER_HPP
|
||||
88
include/Nazara/Core/Formats/MD5MeshParser.hpp
Normal file
88
include/Nazara/Core/Formats/MD5MeshParser.hpp
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_FORMATS_MD5MESHPARSER_HPP
|
||||
#define NAZARA_CORE_FORMATS_MD5MESHPARSER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Stream;
|
||||
|
||||
class NAZARA_CORE_API MD5MeshParser
|
||||
{
|
||||
public:
|
||||
struct Joint
|
||||
{
|
||||
std::string name;
|
||||
Int32 parent;
|
||||
Quaternionf bindOrient;
|
||||
Vector3f bindPos;
|
||||
};
|
||||
|
||||
using Triangle = Vector3ui;
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
Vector2f uv;
|
||||
unsigned int startWeight;
|
||||
unsigned int weightCount;
|
||||
};
|
||||
|
||||
struct Weight
|
||||
{
|
||||
Vector3f pos;
|
||||
float bias;
|
||||
unsigned int joint;
|
||||
};
|
||||
|
||||
struct Mesh
|
||||
{
|
||||
std::vector<Triangle> triangles;
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<Weight> weights;
|
||||
std::string shader;
|
||||
};
|
||||
|
||||
MD5MeshParser(Stream& stream);
|
||||
~MD5MeshParser();
|
||||
|
||||
bool Check();
|
||||
|
||||
const Joint* GetJoints() const;
|
||||
UInt32 GetJointCount() const;
|
||||
const Mesh* GetMeshes() const;
|
||||
UInt32 GetMeshCount() const;
|
||||
|
||||
bool Parse();
|
||||
|
||||
private:
|
||||
bool Advance(bool required = true);
|
||||
void Error(std::string_view message);
|
||||
bool ParseJoints();
|
||||
bool ParseMesh();
|
||||
void Warning(std::string_view message);
|
||||
void UnrecognizedLine(bool error = false);
|
||||
|
||||
std::vector<Joint> m_joints;
|
||||
std::vector<Mesh> m_meshes;
|
||||
Stream& m_stream;
|
||||
StreamOptionFlags m_streamFlags;
|
||||
std::string m_currentLine;
|
||||
bool m_keepLastLine;
|
||||
unsigned int m_lineCount;
|
||||
unsigned int m_meshIndex;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_FORMATS_MD5MESHPARSER_HPP
|
||||
80
include/Nazara/Core/Formats/MTLParser.hpp
Normal file
80
include/Nazara/Core/Formats/MTLParser.hpp
Normal file
@@ -0,0 +1,80 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_FORMATS_MTLPARSER_HPP
|
||||
#define NAZARA_CORE_FORMATS_MTLPARSER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <NazaraUtils/StringHash.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API MTLParser
|
||||
{
|
||||
public:
|
||||
struct Material;
|
||||
|
||||
MTLParser() = default;
|
||||
~MTLParser() = default;
|
||||
|
||||
inline Material* AddMaterial(std::string matName);
|
||||
|
||||
inline void Clear();
|
||||
|
||||
inline const Material* GetMaterial(std::string_view materialName) const;
|
||||
inline const std::unordered_map<std::string, Material, StringHash<>, std::equal_to<>>& GetMaterials() const;
|
||||
|
||||
bool Parse(Stream& stream);
|
||||
|
||||
bool Save(Stream& stream) const;
|
||||
|
||||
struct Material
|
||||
{
|
||||
Color ambient = Color::White();
|
||||
Color diffuse = Color::White();
|
||||
Color specular = Color::White();
|
||||
std::string alphaMap;
|
||||
std::string ambientMap;
|
||||
std::string bumpMap;
|
||||
std::string decalMap;
|
||||
std::string diffuseMap;
|
||||
std::string displacementMap;
|
||||
std::string emissiveMap; //< <!> Custom addition: not present in MTL
|
||||
std::string normalMap; //< <!> Custom addition: not present in MTL
|
||||
std::string reflectionMap;
|
||||
std::string shininessMap;
|
||||
std::string specularMap;
|
||||
float alpha = 1.f;
|
||||
float refractionIndex = 1.f;
|
||||
float shininess = 1.f;
|
||||
unsigned int illumModel = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
bool Advance(bool required = true);
|
||||
template<typename T> void Emit(const T& text) const;
|
||||
inline void EmitLine() const;
|
||||
template<typename T> void EmitLine(const T& line) const;
|
||||
inline void Error(std::string_view message);
|
||||
inline void Flush() const;
|
||||
inline void Warning(std::string_view message);
|
||||
inline void UnrecognizedLine(bool error = false);
|
||||
|
||||
std::unordered_map<std::string, Material, StringHash<>, std::equal_to<>> m_materials;
|
||||
mutable Stream* m_currentStream;
|
||||
std::string m_currentLine;
|
||||
mutable std::ostringstream m_outputStream;
|
||||
bool m_keepLastLine;
|
||||
unsigned int m_lineCount;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Formats/MTLParser.inl>
|
||||
|
||||
#endif // NAZARA_CORE_FORMATS_MTLPARSER_HPP
|
||||
81
include/Nazara/Core/Formats/MTLParser.inl
Normal file
81
include/Nazara/Core/Formats/MTLParser.inl
Normal file
@@ -0,0 +1,81 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline MTLParser::Material* MTLParser::AddMaterial(std::string matName)
|
||||
{
|
||||
return &m_materials[std::move(matName)];
|
||||
}
|
||||
|
||||
inline void MTLParser::Clear()
|
||||
{
|
||||
m_materials.clear();
|
||||
}
|
||||
|
||||
inline const MTLParser::Material* MTLParser::GetMaterial(std::string_view materialName) const
|
||||
{
|
||||
auto it = m_materials.find(materialName);
|
||||
if (it != m_materials.end())
|
||||
return &it->second;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline auto MTLParser::GetMaterials() const -> const std::unordered_map<std::string, Material, StringHash<>, std::equal_to<>>&
|
||||
{
|
||||
return m_materials;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void MTLParser::Emit(const T& text) const
|
||||
{
|
||||
m_outputStream << text;
|
||||
if (m_outputStream.rdbuf()->str().size() > 1024 * 1024)
|
||||
Flush();
|
||||
}
|
||||
|
||||
inline void MTLParser::EmitLine() const
|
||||
{
|
||||
Emit('\n');
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void MTLParser::EmitLine(const T& line) const
|
||||
{
|
||||
Emit(line);
|
||||
Emit('\n');
|
||||
}
|
||||
|
||||
inline void MTLParser::Error(std::string_view message)
|
||||
{
|
||||
NazaraErrorFmt("{0} at line #{1}", message, m_lineCount);
|
||||
}
|
||||
|
||||
inline void MTLParser::Flush() const
|
||||
{
|
||||
m_currentStream->Write(std::move(m_outputStream).str());
|
||||
m_outputStream.str({});
|
||||
}
|
||||
|
||||
inline void MTLParser::Warning(std::string_view message)
|
||||
{
|
||||
NazaraWarningFmt("{0} at line #{1}", message, m_lineCount);
|
||||
}
|
||||
|
||||
inline void MTLParser::UnrecognizedLine(bool error)
|
||||
{
|
||||
std::string message = "Unrecognized \"" + m_currentLine + '"';
|
||||
|
||||
if (error)
|
||||
Error(message);
|
||||
else
|
||||
Warning(message);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
108
include/Nazara/Core/Formats/OBJParser.hpp
Normal file
108
include/Nazara/Core/Formats/OBJParser.hpp
Normal file
@@ -0,0 +1,108 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_FORMATS_OBJPARSER_HPP
|
||||
#define NAZARA_CORE_FORMATS_OBJPARSER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Stream;
|
||||
|
||||
class NAZARA_CORE_API OBJParser
|
||||
{
|
||||
public:
|
||||
struct Mesh;
|
||||
|
||||
OBJParser() = default;
|
||||
~OBJParser() = default;
|
||||
|
||||
inline void Clear();
|
||||
|
||||
bool Check(Stream& stream);
|
||||
|
||||
inline std::string* GetMaterials();
|
||||
inline const std::string* GetMaterials() const;
|
||||
inline std::size_t GetMaterialCount() const;
|
||||
inline Mesh* GetMeshes();
|
||||
inline const Mesh* GetMeshes() const;
|
||||
inline std::size_t GetMeshCount() const;
|
||||
inline const std::filesystem::path& GetMtlLib() const;
|
||||
inline Vector3f* GetNormals();
|
||||
inline const Vector3f* GetNormals() const;
|
||||
inline std::size_t GetNormalCount() const;
|
||||
inline Vector4f* GetPositions();
|
||||
inline const Vector4f* GetPositions() const;
|
||||
inline std::size_t GetPositionCount() const;
|
||||
inline Vector3f* GetTexCoords();
|
||||
inline const Vector3f* GetTexCoords() const;
|
||||
inline std::size_t GetTexCoordCount() const;
|
||||
|
||||
bool Parse(Stream& stream, std::size_t reservedVertexCount = 100);
|
||||
|
||||
bool Save(Stream& stream) const;
|
||||
|
||||
inline std::string* SetMaterialCount(std::size_t materialCount);
|
||||
inline Mesh* SetMeshCount(std::size_t meshCount);
|
||||
inline void SetMtlLib(const std::filesystem::path& mtlLib);
|
||||
inline Vector3f* SetNormalCount(std::size_t normalCount);
|
||||
inline Vector4f* SetPositionCount(std::size_t positionCount);
|
||||
inline Vector3f* SetTexCoordCount(std::size_t texCoordCount);
|
||||
|
||||
struct Face
|
||||
{
|
||||
std::size_t firstVertex;
|
||||
std::size_t vertexCount;
|
||||
};
|
||||
|
||||
struct FaceVertex
|
||||
{
|
||||
std::size_t normal;
|
||||
std::size_t position;
|
||||
std::size_t texCoord;
|
||||
};
|
||||
|
||||
struct Mesh
|
||||
{
|
||||
std::vector<Face> faces;
|
||||
std::vector<FaceVertex> vertices;
|
||||
std::string name;
|
||||
std::size_t material;
|
||||
};
|
||||
|
||||
private:
|
||||
bool Advance(bool required = true);
|
||||
template<typename T> void Emit(const T& text) const;
|
||||
inline void EmitLine() const;
|
||||
template<typename T> void EmitLine(const T& line) const;
|
||||
inline void Error(std::string_view message);
|
||||
void Flush() const;
|
||||
inline void Warning(std::string_view message);
|
||||
inline bool UnrecognizedLine(bool error = false);
|
||||
|
||||
std::vector<Mesh> m_meshes;
|
||||
std::vector<std::string> m_materials;
|
||||
std::vector<Vector3f> m_normals;
|
||||
std::vector<Vector4f> m_positions;
|
||||
std::vector<Vector3f> m_texCoords;
|
||||
mutable Stream* m_currentStream;
|
||||
std::string m_currentLine;
|
||||
std::filesystem::path m_mtlLib;
|
||||
mutable std::ostringstream m_outputStream;
|
||||
bool m_keepLastLine;
|
||||
unsigned int m_lineCount;
|
||||
unsigned int m_errorCount;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Formats/OBJParser.inl>
|
||||
|
||||
#endif // NAZARA_CORE_FORMATS_OBJPARSER_HPP
|
||||
185
include/Nazara/Core/Formats/OBJParser.inl
Normal file
185
include/Nazara/Core/Formats/OBJParser.inl
Normal file
@@ -0,0 +1,185 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline void OBJParser::Clear()
|
||||
{
|
||||
m_materials.clear();
|
||||
m_meshes.clear();
|
||||
m_positions.clear();
|
||||
m_normals.clear();
|
||||
m_texCoords.clear();
|
||||
}
|
||||
|
||||
inline std::string* OBJParser::GetMaterials()
|
||||
{
|
||||
return m_materials.data();
|
||||
}
|
||||
|
||||
inline const std::string* OBJParser::GetMaterials() const
|
||||
{
|
||||
return m_materials.data();
|
||||
}
|
||||
|
||||
inline std::size_t OBJParser::GetMaterialCount() const
|
||||
{
|
||||
return m_materials.size();
|
||||
}
|
||||
|
||||
inline OBJParser::Mesh* OBJParser::GetMeshes()
|
||||
{
|
||||
return m_meshes.data();
|
||||
}
|
||||
|
||||
inline const OBJParser::Mesh* OBJParser::GetMeshes() const
|
||||
{
|
||||
return m_meshes.data();
|
||||
}
|
||||
|
||||
inline std::size_t OBJParser::GetMeshCount() const
|
||||
{
|
||||
return m_meshes.size();
|
||||
}
|
||||
|
||||
inline const std::filesystem::path& OBJParser::GetMtlLib() const
|
||||
{
|
||||
return m_mtlLib;
|
||||
}
|
||||
|
||||
inline Vector3f* OBJParser::GetNormals()
|
||||
{
|
||||
return m_normals.data();
|
||||
}
|
||||
|
||||
inline const Vector3f* OBJParser::GetNormals() const
|
||||
{
|
||||
return m_normals.data();
|
||||
}
|
||||
|
||||
inline std::size_t OBJParser::GetNormalCount() const
|
||||
{
|
||||
return m_normals.size();
|
||||
}
|
||||
|
||||
inline Vector4f* OBJParser::GetPositions()
|
||||
{
|
||||
return m_positions.data();
|
||||
}
|
||||
|
||||
inline const Vector4f* OBJParser::GetPositions() const
|
||||
{
|
||||
return m_positions.data();
|
||||
}
|
||||
|
||||
inline std::size_t OBJParser::GetPositionCount() const
|
||||
{
|
||||
return m_positions.size();
|
||||
}
|
||||
|
||||
inline Vector3f* OBJParser::GetTexCoords()
|
||||
{
|
||||
return m_texCoords.data();
|
||||
}
|
||||
|
||||
inline const Vector3f* OBJParser::GetTexCoords() const
|
||||
{
|
||||
return m_texCoords.data();
|
||||
}
|
||||
|
||||
inline std::size_t OBJParser::GetTexCoordCount() const
|
||||
{
|
||||
return m_texCoords.size();
|
||||
}
|
||||
|
||||
inline std::string* OBJParser::SetMaterialCount(std::size_t materialCount)
|
||||
{
|
||||
m_materials.resize(materialCount);
|
||||
return m_materials.data();
|
||||
}
|
||||
|
||||
inline OBJParser::Mesh* OBJParser::SetMeshCount(std::size_t meshCount)
|
||||
{
|
||||
m_meshes.resize(meshCount);
|
||||
return m_meshes.data();
|
||||
}
|
||||
|
||||
inline void OBJParser::SetMtlLib(const std::filesystem::path& mtlLib)
|
||||
{
|
||||
m_mtlLib = mtlLib;
|
||||
}
|
||||
|
||||
inline Vector3f* OBJParser::SetNormalCount(std::size_t normalCount)
|
||||
{
|
||||
m_normals.resize(normalCount);
|
||||
return m_normals.data();
|
||||
}
|
||||
|
||||
inline Vector4f* OBJParser::SetPositionCount(std::size_t positionCount)
|
||||
{
|
||||
m_positions.resize(positionCount);
|
||||
return m_positions.data();
|
||||
}
|
||||
|
||||
inline Vector3f* OBJParser::SetTexCoordCount(std::size_t texCoordCount)
|
||||
{
|
||||
m_texCoords.resize(texCoordCount);
|
||||
return m_texCoords.data();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void OBJParser::Emit(const T& text) const
|
||||
{
|
||||
m_outputStream << text;
|
||||
if (m_outputStream.rdbuf()->str().size() > 1024 * 1024)
|
||||
Flush();
|
||||
}
|
||||
|
||||
inline void OBJParser::EmitLine() const
|
||||
{
|
||||
Emit('\n');
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void OBJParser::EmitLine(const T& line) const
|
||||
{
|
||||
Emit(line);
|
||||
Emit('\n');
|
||||
}
|
||||
|
||||
inline void OBJParser::Error(std::string_view message)
|
||||
{
|
||||
NazaraErrorFmt("{0} on line #{1}", message, m_lineCount);
|
||||
}
|
||||
|
||||
inline void OBJParser::Warning(std::string_view message)
|
||||
{
|
||||
NazaraWarningFmt("{0} on line #{1}", message, m_lineCount);
|
||||
}
|
||||
|
||||
inline bool OBJParser::UnrecognizedLine(bool error)
|
||||
{
|
||||
std::string message = "Unrecognized \"" + m_currentLine + '"';
|
||||
|
||||
if (error)
|
||||
Error(message);
|
||||
else
|
||||
Warning(message);
|
||||
|
||||
m_errorCount++;
|
||||
|
||||
if (m_errorCount > 10 && (m_errorCount * 100 / m_lineCount) > 50)
|
||||
{
|
||||
NazaraError("aborting parsing because of error percentage");
|
||||
return false; //< Abort parsing if error percentage is too high
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user