chore: move xmodel packages

This commit is contained in:
Jan
2024-03-30 15:19:11 +01:00
parent abc3003b5b
commit d4ef9fa3d9
22 changed files with 18 additions and 18 deletions

View File

@ -0,0 +1,54 @@
#include "ObjCommon.h"
#include <cmath>
#include <limits>
#include <tuple>
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

@ -0,0 +1,101 @@
#include "XModelCommon.h"
#include <cmath>
#include <limits>
#include <tuple>
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;
}
bool operator==(const VertexMergerPos& lhs, const VertexMergerPos& rhs)
{
const auto coordinatesMatch = 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();
if (!coordinatesMatch || lhs.weightCount != rhs.weightCount)
return false;
for (auto weightIndex = 0u; weightIndex < lhs.weightCount; weightIndex++)
{
if (lhs.weights[weightIndex].boneIndex != rhs.weights[weightIndex].boneIndex
|| std::fabs(lhs.weights[weightIndex].weight - rhs.weights[weightIndex].weight) >= std::numeric_limits<float>::epsilon())
{
return false;
}
}
return true;
}
bool operator!=(const VertexMergerPos& lhs, VertexMergerPos& rhs)
{
return !(lhs == rhs);
}
bool operator<(const VertexMergerPos& lhs, const VertexMergerPos& rhs)
{
const auto t0 = std::tie(lhs.x, lhs.y, lhs.z, rhs.weightCount);
const auto t1 = std::tie(rhs.x, rhs.y, rhs.z, rhs.weightCount);
if (t0 < t1)
return true;
if (!(t0 == t1))
return false;
for (auto weightIndex = 0u; weightIndex < lhs.weightCount; weightIndex++)
{
const auto& lhsWeight = lhs.weights[weightIndex];
const auto& rhsWeight = rhs.weights[weightIndex];
const auto t2 = std::tie(lhsWeight.boneIndex, lhsWeight.weight);
const auto t3 = std::tie(rhsWeight.boneIndex, rhsWeight.weight);
if (t2 < t3)
return true;
if (!(t2 == t3))
return false;
}
return false;
}

View File

@ -0,0 +1,109 @@
#pragma once
#include "Math/Quaternion.h"
#include "Utils/DistinctMapper.h"
#include <memory>
#include <string>
struct XModelObject
{
std::string name;
};
struct XModelBone
{
std::string name;
int parentIndex;
float scale[3];
float globalOffset[3];
float localOffset[3];
Quaternion32 globalRotation;
Quaternion32 localRotation;
};
struct XModelBoneWeight
{
int boneIndex;
float weight;
};
struct XModelVertexBoneWeightCollection
{
std::unique_ptr<XModelBoneWeight[]> weights;
size_t totalWeightCount;
};
struct XModelVertexBoneWeights
{
const XModelBoneWeight* weights;
size_t weightCount;
};
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();
};
struct VertexMergerPos
{
float x;
float y;
float z;
const XModelBoneWeight* weights;
size_t weightCount;
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;