2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-06-27 14:51:58 +00:00

Add ObjDumper for general use

This commit is contained in:
Jan
2021-08-13 22:34:42 +02:00
parent 0478a88d15
commit 76a7ca99c3
8 changed files with 480 additions and 194 deletions

View File

@ -0,0 +1,54 @@
#include "ObjCommon.h"
#include <cmath>
#include <limits>
bool operator==(const ObjVertex& lhs, const ObjVertex& rhs)
{
return std::fabs(lhs.coordinates[0] - rhs.coordinates[0]) < std::numeric_limits<float>::epsilon()
&& std::fabs(lhs.coordinates[1] - rhs.coordinates[1]) < std::numeric_limits<float>::epsilon()
&& std::fabs(lhs.coordinates[2] - rhs.coordinates[2]) < std::numeric_limits<float>::epsilon();
}
bool operator!=(const ObjVertex& lhs, const ObjVertex& rhs)
{
return !(lhs == rhs);
}
bool operator<(const ObjVertex& lhs, const ObjVertex& rhs)
{
return std::tie(lhs.coordinates[0], lhs.coordinates[1], lhs.coordinates[2]) < std::tie(rhs.coordinates[0], rhs.coordinates[1], rhs.coordinates[2]);
}
bool operator==(const ObjNormal& lhs, const ObjNormal& rhs)
{
return std::fabs(lhs.normal[0] - rhs.normal[0]) < std::numeric_limits<float>::epsilon()
&& std::fabs(lhs.normal[1] - rhs.normal[1]) < std::numeric_limits<float>::epsilon()
&& std::fabs(lhs.normal[2] - rhs.normal[2]) < std::numeric_limits<float>::epsilon();
}
bool operator!=(const ObjNormal& lhs, const ObjNormal& rhs)
{
return !(lhs == rhs);
}
bool operator<(const ObjNormal& lhs, const ObjNormal& rhs)
{
return std::tie(lhs.normal[0], lhs.normal[1], lhs.normal[2]) < std::tie(rhs.normal[0], rhs.normal[1], rhs.normal[2]);
}
bool operator==(const ObjUv& lhs, const ObjUv& rhs)
{
return std::fabs(lhs.uv[0] - rhs.uv[0]) < std::numeric_limits<float>::epsilon()
&& std::fabs(lhs.uv[1] - rhs.uv[1]) < std::numeric_limits<float>::epsilon();
}
bool operator!=(const ObjUv& lhs, const ObjUv& rhs)
{
return !(lhs == rhs);
}
bool operator<(const ObjUv& lhs, const ObjUv& rhs)
{
return std::tie(lhs.uv[0], lhs.uv[1]) < std::tie(rhs.uv[0], rhs.uv[1]);
}

View File

@ -0,0 +1,51 @@
#pragma once
#include <string>
struct ObjObject
{
std::string name;
int materialIndex;
};
struct ObjVertex
{
float coordinates[3];
friend bool operator==(const ObjVertex& lhs, const ObjVertex& rhs);
friend bool operator!=(const ObjVertex& lhs, const ObjVertex& rhs);
friend bool operator<(const ObjVertex& lhs, const ObjVertex& rhs);
};
struct ObjNormal
{
float normal[3];
friend bool operator==(const ObjNormal& lhs, const ObjNormal& rhs);
friend bool operator!=(const ObjNormal& lhs, const ObjNormal& rhs);
friend bool operator<(const ObjNormal& lhs, const ObjNormal& rhs);
};
struct ObjUv
{
float uv[2];
friend bool operator==(const ObjUv& lhs, const ObjUv& rhs);
friend bool operator!=(const ObjUv& lhs, const ObjUv& rhs);
friend bool operator<(const ObjUv& lhs, const ObjUv& rhs);
};
struct ObjFace
{
int vertexIndex[3];
int normalIndex[3];
int uvIndex[3];
};
struct MtlMaterial
{
std::string materialName;
std::string colorMapName;
std::string normalMapName;
std::string specularMapName;
};

View File

@ -5,59 +5,6 @@
#include "Utils/ClassUtils.h"
/*
template <typename T>
class Deduplicator
{
public:
Deduplicator()
: m_current_entry_index(0)
{
}
explicit Deduplicator(const size_t totalEntryCount)
: m_current_entry_index(0)
{
m_position_lookup.reserve(totalEntryCount);
}
bool AddEntry(T pos)
{
const auto mapEntry = m_index_map.find(pos);
if (mapEntry == m_index_map.end())
{
m_position_lookup.push_back(m_current_entry_index);
m_unique_entry_position_indices.push_back(m_current_entry_index);
m_index_map.emplace(std::make_pair(pos, m_current_entry_index));
m_current_entry_index++;
return true;
}
m_position_lookup.push_back(mapEntry->second);
m_current_entry_index++;
return false;
}
size_t GetUniqueIndexForIndex(const size_t entryIndex)
{
if (entryIndex >= m_position_lookup.size())
return 0;
return m_position_lookup[entryIndex];
}
_NODISCARD const std::vector<size_t>& GetUniqueEntryIndices() const
{
return m_unique_entry_position_indices;
}
private:
size_t m_current_entry_index;
std::vector<size_t> m_unique_entry_position_indices;
std::vector<size_t> m_position_lookup;
std::map<T, int> m_index_map;
};*/
template <typename T>
class DistinctMapper
{
@ -123,6 +70,16 @@ public:
return m_distinct_values;
}
_NODISCARD size_t GetInputValueCount() const
{
return m_input_entry_index;
}
_NODISCARD size_t GetDistinctValueCount() const
{
return m_distinct_entry_index;
}
private:
size_t m_input_entry_index;
size_t m_distinct_entry_index;