Former-commit-id: 27f09e4351e6721eab338576075a161f62a4c262 [formerly d2cc64b6b6ec984210fd187adfc0797087ea3a0a] [formerly 58c7a39be0a0fdb8c89c516d5e8d19b18d34ba60 [formerly a9d80e257c27b60319e0d1b03b1534e133e1244e]] Former-commit-id: 9ccaa30b87462af58390478d4d6b956d9b5faa5f [formerly 615171770a9a8c87b37b50940c7342bdeb6876a2] Former-commit-id: c49b38dc42936ba3f696f9436fd9f6b5527244c0
111 lines
2.9 KiB
C++
111 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();
|
|
|
|
bool Check(Stream& stream);
|
|
|
|
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
|