mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-27 14:51:58 +00:00
Add generic XModel Export dumper without bone support yet
This commit is contained in:
0
src/ObjCommon/Model/Obj/ObjCommon.h
Normal file
0
src/ObjCommon/Model/Obj/ObjCommon.h
Normal file
63
src/ObjCommon/Model/VertexMerger.cpp
Normal file
63
src/ObjCommon/Model/VertexMerger.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include "VertexMerger.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
bool operator==(const VertexMergerPos& lhs, const VertexMergerPos& rhs)
|
||||
{
|
||||
return std::fabs(lhs.x - rhs.x) < std::numeric_limits<float>::epsilon()
|
||||
&& std::fabs(lhs.y - rhs.y) < std::numeric_limits<float>::epsilon()
|
||||
&& std::fabs(lhs.z - rhs.z) < std::numeric_limits<float>::epsilon();
|
||||
}
|
||||
|
||||
bool operator!=(const VertexMergerPos& lhs, VertexMergerPos& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
bool operator<(const VertexMergerPos& lhs, const VertexMergerPos& rhs)
|
||||
{
|
||||
return std::tie(lhs.x, lhs.y, lhs.z) < std::tie(rhs.x, rhs.y, rhs.z);
|
||||
}
|
||||
/*
|
||||
VertexMerger::VertexMerger()
|
||||
: m_current_vertex_index(0)
|
||||
{
|
||||
}
|
||||
|
||||
VertexMerger::VertexMerger(const size_t totalVertexCount)
|
||||
: m_current_vertex_index(0)
|
||||
{
|
||||
m_position_lookup.reserve(totalVertexCount);
|
||||
}
|
||||
|
||||
void VertexMerger::ProcessVertex(VertexPos pos)
|
||||
{
|
||||
const auto mapEntry = m_vertex_index_map.find(pos);
|
||||
if (mapEntry == m_vertex_index_map.end())
|
||||
{
|
||||
m_position_lookup.push_back(m_current_vertex_index);
|
||||
m_unique_vertex_position_indices.push_back(m_current_vertex_index);
|
||||
m_vertex_index_map.emplace(std::make_pair(pos, m_current_vertex_index));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_position_lookup.push_back(mapEntry->second);
|
||||
}
|
||||
|
||||
m_current_vertex_index++;
|
||||
}
|
||||
|
||||
size_t VertexMerger::GetUniqueVertexIndexForVertexIndex(const size_t vertexIndex)
|
||||
{
|
||||
if (vertexIndex >= m_position_lookup.size())
|
||||
return 0;
|
||||
|
||||
return m_position_lookup[vertexIndex];
|
||||
}
|
||||
|
||||
const std::vector<size_t>& VertexMerger::GetUniqueVertexIndices() const
|
||||
{
|
||||
return m_unique_vertex_position_indices;
|
||||
}
|
||||
*/
|
51
src/ObjCommon/Model/VertexMerger.h
Normal file
51
src/ObjCommon/Model/VertexMerger.h
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "Utils/DistinctMapper.h"
|
||||
|
||||
struct VertexMergerPos
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
friend bool operator==(const VertexMergerPos& lhs, const VertexMergerPos& rhs);
|
||||
friend bool operator!=(const VertexMergerPos& lhs, const VertexMergerPos& rhs);
|
||||
friend bool operator<(const VertexMergerPos& lhs, const VertexMergerPos& rhs);
|
||||
};
|
||||
|
||||
typedef DistinctMapper<VertexMergerPos> VertexMerger;
|
||||
|
||||
/*
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
class VertexMerger
|
||||
{
|
||||
public:
|
||||
struct VertexPos
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
friend bool operator==(const VertexPos& lhs, const VertexPos& rhs);
|
||||
friend bool operator!=(const VertexPos& lhs, const VertexPos& rhs);
|
||||
friend bool operator<(const VertexPos& lhs, const VertexPos& rhs);
|
||||
};
|
||||
|
||||
VertexMerger();
|
||||
explicit VertexMerger(size_t totalVertexCount);
|
||||
|
||||
void ProcessVertex(VertexPos pos);
|
||||
size_t GetUniqueVertexIndexForVertexIndex(size_t vertexIndex);
|
||||
_NODISCARD const std::vector<size_t>& GetUniqueVertexIndices() const;
|
||||
|
||||
private:
|
||||
size_t m_current_vertex_index;
|
||||
std::vector<size_t> m_unique_vertex_position_indices;
|
||||
std::vector<size_t> m_position_lookup;
|
||||
std::map<VertexPos, int> m_vertex_index_map;
|
||||
};
|
||||
*/
|
44
src/ObjCommon/Model/XModel/XModelCommon.cpp
Normal file
44
src/ObjCommon/Model/XModel/XModelCommon.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include "XModelCommon.h"
|
||||
|
||||
void XModelMaterial::ApplyDefaults()
|
||||
{
|
||||
// Phong = Color, Bump, Spec, CosinePower
|
||||
// Blinn = Color, Bump, Spec, Eccentricity
|
||||
// Lambert = Color, Bump
|
||||
materialTypeName = "Phong";
|
||||
color[0] = 0;
|
||||
color[1] = 0;
|
||||
color[2] = 0;
|
||||
color[3] = 1;
|
||||
transparency[0] = 0;
|
||||
transparency[1] = 0;
|
||||
transparency[2] = 0;
|
||||
transparency[3] = 1;
|
||||
ambientColor[0] = 0;
|
||||
ambientColor[1] = 0;
|
||||
ambientColor[2] = 0;
|
||||
ambientColor[3] = 1;
|
||||
incandescence[0] = 0;
|
||||
incandescence[1] = 0;
|
||||
incandescence[2] = 0;
|
||||
incandescence[3] = 1;
|
||||
coeffs[0] = 0.8f;
|
||||
coeffs[1] = 0;
|
||||
glow.x = 0;
|
||||
glow.y = 0;
|
||||
refractive.x = 6;
|
||||
refractive.y = 1;
|
||||
specularColor[0] = -1;
|
||||
specularColor[1] = -1;
|
||||
specularColor[2] = -1;
|
||||
specularColor[3] = 1;
|
||||
reflectiveColor[0] = -1;
|
||||
reflectiveColor[1] = -1;
|
||||
reflectiveColor[2] = -1;
|
||||
reflectiveColor[3] = 1;
|
||||
reflective.x = -1;
|
||||
reflective.y = -1;
|
||||
blinn[0] = -1;
|
||||
blinn[1] = -1;
|
||||
phong = -1;
|
||||
}
|
66
src/ObjCommon/Model/XModel/XModelCommon.h
Normal file
66
src/ObjCommon/Model/XModel/XModelCommon.h
Normal file
@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Math/Quaternion.h"
|
||||
|
||||
struct XModelObject
|
||||
{
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct XModelBone
|
||||
{
|
||||
std::string name;
|
||||
int parentIndex;
|
||||
float scale[3];
|
||||
float offset[3];
|
||||
Quaternion32 rotation;
|
||||
};
|
||||
|
||||
struct XModelVertex
|
||||
{
|
||||
float coordinates[3];
|
||||
float normal[3];
|
||||
float color[4];
|
||||
float uv[2];
|
||||
};
|
||||
|
||||
struct XModelFace
|
||||
{
|
||||
int vertexIndex[3];
|
||||
int objectIndex;
|
||||
int materialIndex;
|
||||
};
|
||||
|
||||
struct XModelMaterial
|
||||
{
|
||||
std::string name;
|
||||
std::string materialTypeName;
|
||||
float color[4];
|
||||
float transparency[4];
|
||||
float ambientColor[4];
|
||||
float incandescence[4];
|
||||
float coeffs[2];
|
||||
struct {
|
||||
float x;
|
||||
int y;
|
||||
} glow;
|
||||
struct
|
||||
{
|
||||
int x;
|
||||
float y;
|
||||
} refractive;
|
||||
float specularColor[4];
|
||||
float reflectiveColor[4];
|
||||
struct
|
||||
{
|
||||
int x;
|
||||
float y;
|
||||
} reflective;
|
||||
float blinn[2];
|
||||
float phong;
|
||||
std::string colorMapName;
|
||||
|
||||
void ApplyDefaults();
|
||||
};
|
133
src/ObjCommon/Utils/DistinctMapper.h
Normal file
133
src/ObjCommon/Utils/DistinctMapper.h
Normal file
@ -0,0 +1,133 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#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
|
||||
{
|
||||
public:
|
||||
DistinctMapper()
|
||||
: m_input_entry_index(0),
|
||||
m_distinct_entry_index(0)
|
||||
{
|
||||
}
|
||||
|
||||
explicit DistinctMapper(const size_t totalInputCount)
|
||||
: m_input_entry_index(0),
|
||||
m_distinct_entry_index(0)
|
||||
{
|
||||
m_distinct_position_by_input_position.reserve(totalInputCount);
|
||||
}
|
||||
|
||||
bool Add(T inputValue)
|
||||
{
|
||||
const auto mapEntry = m_distinct_position_by_value_map.find(inputValue);
|
||||
if (mapEntry == m_distinct_position_by_value_map.end())
|
||||
{
|
||||
m_distinct_position_by_input_position.push_back(m_distinct_entry_index);
|
||||
m_input_position_by_distinct_position.push_back(m_input_entry_index);
|
||||
m_distinct_values.push_back(inputValue);
|
||||
m_distinct_position_by_value_map.emplace(std::make_pair(std::move(inputValue), m_distinct_entry_index));
|
||||
m_distinct_entry_index++;
|
||||
m_input_entry_index++;
|
||||
return true;
|
||||
}
|
||||
|
||||
m_distinct_position_by_input_position.push_back(mapEntry->second);
|
||||
m_input_entry_index++;
|
||||
return false;
|
||||
}
|
||||
|
||||
_NODISCARD size_t GetDistinctPositionByInputPosition(const size_t inputPosition) const
|
||||
{
|
||||
if (inputPosition >= m_distinct_position_by_input_position.size())
|
||||
return 0;
|
||||
|
||||
return m_distinct_position_by_input_position[inputPosition];
|
||||
}
|
||||
|
||||
_NODISCARD T GetDistinctValueByInputPosition(const size_t inputPosition) const
|
||||
{
|
||||
if (inputPosition >= m_distinct_values.size())
|
||||
return T{};
|
||||
|
||||
return m_distinct_values[inputPosition];
|
||||
}
|
||||
|
||||
_NODISCARD size_t GetInputPositionByDistinctPosition(const size_t distinctPosition) const
|
||||
{
|
||||
if (distinctPosition >= m_input_position_by_distinct_position.size())
|
||||
return 0;
|
||||
|
||||
return m_input_position_by_distinct_position[distinctPosition];
|
||||
}
|
||||
|
||||
_NODISCARD const std::vector<T>& GetDistinctValues() const
|
||||
{
|
||||
return m_distinct_values;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_input_entry_index;
|
||||
size_t m_distinct_entry_index;
|
||||
std::map<T, size_t> m_distinct_position_by_value_map;
|
||||
std::vector<size_t> m_distinct_position_by_input_position;
|
||||
std::vector<size_t> m_input_position_by_distinct_position;
|
||||
std::vector<T> m_distinct_values;
|
||||
};
|
Reference in New Issue
Block a user