Files
NazaraEngine/include/Nazara/Utility/Formats/OBJParser.hpp
Lynix bcb05f13f8 Utility: First code cleaning pass
Former-commit-id: 834097e149f393c278e47ff31c8c4d12b0628d2b [formerly 5eb47a1c307a874555e07106b0d484ecc0958345] [formerly fab49feb40dbc3bfdc959659ff74a6d3a2b59606 [formerly a2be53055f8fb8123035e145ea2edb0043d780e2]]
Former-commit-id: d44f84cccad74434dc02a97a2a9b7a72dca49f5c [formerly d21b193e02096275d145af82ca4468f67ce1f74c]
Former-commit-id: 618d73318ca6c9ad86b091312858b38024b3a5e0
2016-09-04 20:39:34 +02:00

109 lines
2.9 KiB
C++

// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_FORMATS_OBJPARSER_HPP
#define NAZARA_FORMATS_OBJPARSER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Stream.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
#include <Nazara/Utility/Config.hpp>
#include <vector>
namespace Nz
{
class NAZARA_UTILITY_API OBJParser
{
public:
struct Face;
struct FaceVertex;
struct Mesh;
OBJParser() = default;
~OBJParser() = default;
inline void Clear();
inline String* GetMaterials();
inline const String* GetMaterials() const;
inline UInt32 GetMaterialCount() const;
inline Mesh* GetMeshes();
inline const Mesh* GetMeshes() const;
inline UInt32 GetMeshCount() const;
inline const String& GetMtlLib() const;
inline Vector3f* GetNormals();
inline const Vector3f* GetNormals() const;
inline UInt32 GetNormalCount() const;
inline Vector4f* GetPositions();
inline const Vector4f* GetPositions() const;
inline UInt32 GetPositionCount() const;
inline Vector3f* GetTexCoords();
inline const Vector3f* GetTexCoords() const;
inline UInt32 GetTexCoordCount() const;
bool Parse(Stream& stream, UInt32 reservedVertexCount = 100);
bool Save(Stream& stream) const;
inline String* SetMaterialCount(UInt32 materialCount);
inline Mesh* SetMeshCount(UInt32 meshCount);
inline void SetMtlLib(const String& mtlLib);
inline Vector3f* SetNormalCount(UInt32 normalCount);
inline Vector4f* SetPositionCount(UInt32 positionCount);
inline Vector3f* SetTexCoordCount(UInt32 texCoordCount);
struct Face
{
UInt32 firstVertex;
UInt32 vertexCount;
};
struct FaceVertex
{
UInt32 normal;
UInt32 position;
UInt32 texCoord;
};
struct Mesh
{
std::vector<Face> faces;
std::vector<FaceVertex> vertices;
String name;
UInt32 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(const String& message);
inline void Flush() const;
inline void Warning(const String& message);
inline bool UnrecognizedLine(bool error = false);
std::vector<Mesh> m_meshes;
std::vector<String> m_materials;
std::vector<Vector3f> m_normals;
std::vector<Vector4f> m_positions;
std::vector<Vector3f> m_texCoords;
mutable Stream* m_currentStream;
String m_currentLine;
String m_mtlLib;
mutable StringStream m_outputStream;
bool m_keepLastLine;
unsigned int m_lineCount;
unsigned int m_errorCount;
};
}
#include <Nazara/Utility/Formats/OBJParser.inl>
#endif // NAZARA_FORMATS_OBJPARSER_HPP