WIP Retrofit new data into existing structure
This commit is contained in:
parent
af944b3083
commit
f083147806
|
@ -61,9 +61,9 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
AnimationInterpolation interpolation;
|
AnimationInterpolation interpolation;
|
||||||
|
|
||||||
std::vector<PositionKey> positionKeys;
|
std::vector<PositionKey> positionKeys{};
|
||||||
std::vector<RotationKey> rotationKeys;
|
std::vector<RotationKey> rotationKeys{};
|
||||||
std::vector<ScaleKey> scaleKeys;
|
std::vector<ScaleKey> scaleKeys{};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SH_API SHAnimAsset final : SHAssetData
|
struct SH_API SHAnimAsset final : SHAssetData
|
||||||
|
|
|
@ -28,12 +28,6 @@ namespace SHADE
|
||||||
bool hasWeights;
|
bool hasWeights;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexWeight
|
|
||||||
{
|
|
||||||
SHVec4 weights;
|
|
||||||
SHVec4U joints;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SH_API SHMeshAsset : SHAssetData
|
struct SH_API SHMeshAsset : SHAssetData
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
|
@ -44,6 +38,9 @@ namespace SHADE
|
||||||
std::vector<uint32_t> Indices{};
|
std::vector<uint32_t> Indices{};
|
||||||
|
|
||||||
//Variables
|
//Variables
|
||||||
std::vector<VertexWeight> VertexWeights{};
|
std::vector<SHVec4> VertexBoneWeights{};
|
||||||
|
std::vector<SHVec4U> VertexBoneIndices{};
|
||||||
|
|
||||||
|
uint32_t BoneCount;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
#include "SHpch.h"
|
#include "SHpch.h"
|
||||||
#include "SHRigAsset.h"
|
#include "SHRigAsset.h"
|
||||||
|
|
||||||
#include <queue>
|
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
SHRigAsset::~SHRigAsset()
|
SHRigAsset::~SHRigAsset()
|
||||||
{
|
{
|
||||||
if (root != nullptr)
|
if (root != nullptr)
|
||||||
delete[] root;
|
delete[] root;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,7 @@ namespace SHADE
|
||||||
struct SHRigNodeData
|
struct SHRigNodeData
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<double>
|
SHMatrix transform;
|
||||||
rotation,
|
|
||||||
scale,
|
|
||||||
translation,
|
|
||||||
matrix;
|
|
||||||
SHMatrix inverseBindMatrix;
|
SHMatrix inverseBindMatrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,52 @@
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
inline SHVec3 GetVec3FromVector(std::vector<double> const& vec)
|
||||||
|
{
|
||||||
|
assert(vec.size() == NODE_COMPONENT_COUNT_TRANSLATION);
|
||||||
|
|
||||||
|
return SHVec3{
|
||||||
|
static_cast<float>(vec[0]),
|
||||||
|
static_cast<float>(vec[1]),
|
||||||
|
static_cast<float>(vec[2])
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline SHVec4 GetVec4FromVector(std::vector<double> const& vec)
|
||||||
|
{
|
||||||
|
assert(vec.size() == NODE_COMPONENT_COUNT_ROTATION);
|
||||||
|
return SHVec4{
|
||||||
|
static_cast<float>(vec[0]),
|
||||||
|
static_cast<float>(vec[1]),
|
||||||
|
static_cast<float>(vec[2]),
|
||||||
|
static_cast<float>(vec[3])
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline SHMatrix GetMatrixFromVector(std::vector<double> const& vec)
|
||||||
|
{
|
||||||
|
assert(vec.size() == NODE_COMPONENT_COUNT_MATRIX);
|
||||||
|
|
||||||
|
return SHMatrix{
|
||||||
|
static_cast<float>(vec[0]),
|
||||||
|
static_cast<float>(vec[1]),
|
||||||
|
static_cast<float>(vec[2]),
|
||||||
|
static_cast<float>(vec[3]),
|
||||||
|
static_cast<float>(vec[4]),
|
||||||
|
static_cast<float>(vec[5]),
|
||||||
|
static_cast<float>(vec[6]),
|
||||||
|
static_cast<float>(vec[7]),
|
||||||
|
static_cast<float>(vec[8]),
|
||||||
|
static_cast<float>(vec[9]),
|
||||||
|
static_cast<float>(vec[10]),
|
||||||
|
static_cast<float>(vec[11]),
|
||||||
|
static_cast<float>(vec[12]),
|
||||||
|
static_cast<float>(vec[13]),
|
||||||
|
static_cast<float>(vec[14]),
|
||||||
|
static_cast<float>(vec[15])
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void SHModelLoader::ReadHeaders(FileReference file, SHModelAsset& asset)
|
void SHModelLoader::ReadHeaders(FileReference file, SHModelAsset& asset)
|
||||||
{
|
{
|
||||||
file.read(
|
file.read(
|
||||||
|
@ -57,6 +103,11 @@ namespace SHADE
|
||||||
ReadRigHeader(file, asset.rig.header);
|
ReadRigHeader(file, asset.rig.header);
|
||||||
ReadRigData(file, asset.rig.header, asset.rig.nodeDataCollection);
|
ReadRigData(file, asset.rig.header, asset.rig.nodeDataCollection);
|
||||||
ReadRigTree(file, asset.rig.header, asset.rig.root);
|
ReadRigTree(file, asset.rig.header, asset.rig.root);
|
||||||
|
|
||||||
|
for (auto& mesh : asset.meshes)
|
||||||
|
{
|
||||||
|
mesh->BoneCount = asset.rig.nodeDataCollection.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,48 +166,64 @@ namespace SHADE
|
||||||
auto& node = data[i];
|
auto& node = data[i];
|
||||||
node.name.resize(header.charCounts[i]);
|
node.name.resize(header.charCounts[i]);
|
||||||
file.read(
|
file.read(
|
||||||
data[i].name.data(),
|
node.name.data(),
|
||||||
header.charCounts[i]
|
header.charCounts[i]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
file.read(
|
||||||
|
reinterpret_cast<char*>(&node.inverseBindMatrix),
|
||||||
|
sizeof(SHMatrix)
|
||||||
|
);
|
||||||
|
|
||||||
NodeDataFlag flag;
|
NodeDataFlag flag;
|
||||||
file.get(reinterpret_cast<char&>(flag));
|
file.get(reinterpret_cast<char&>(flag));
|
||||||
|
|
||||||
|
SHVec3 scale{ SHVec3::One }, translation{ SHVec3::Zero };
|
||||||
|
SHVec4 rotation{ SHVec4::UnitW };
|
||||||
|
SHMatrix matrix{ SHMatrix::Identity };
|
||||||
|
std::vector<double> carrier;
|
||||||
|
|
||||||
if (flag & NODE_DATA_ROTATION)
|
if (flag & NODE_DATA_ROTATION)
|
||||||
{
|
{
|
||||||
node.rotation.resize(NODE_COMPONENT_COUNT_ROTATION);
|
carrier.resize(NODE_COMPONENT_COUNT_ROTATION);
|
||||||
file.read(
|
file.read(
|
||||||
reinterpret_cast<char*>(node.rotation.data()),
|
reinterpret_cast<char*>(carrier.data()),
|
||||||
sizeof(double) * NODE_COMPONENT_COUNT_ROTATION
|
sizeof(double) * NODE_COMPONENT_COUNT_ROTATION
|
||||||
);
|
);
|
||||||
|
rotation = GetVec4FromVector(carrier);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag & NODE_DATA_SCALE)
|
if (flag & NODE_DATA_SCALE)
|
||||||
{
|
{
|
||||||
node.scale.resize(NODE_COMPONENT_COUNT_SCALE);
|
carrier.resize(NODE_COMPONENT_COUNT_SCALE);
|
||||||
file.read(
|
file.read(
|
||||||
reinterpret_cast<char*>(node.scale.data()),
|
reinterpret_cast<char*>(carrier.data()),
|
||||||
sizeof(double) * NODE_COMPONENT_COUNT_SCALE
|
sizeof(double) * NODE_COMPONENT_COUNT_SCALE
|
||||||
);
|
);
|
||||||
|
scale = GetVec3FromVector(carrier);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag & NODE_DATA_TRANSLATION)
|
if (flag & NODE_DATA_TRANSLATION)
|
||||||
{
|
{
|
||||||
node.translation.resize(NODE_COMPONENT_COUNT_TRANSLATION);
|
carrier.resize(NODE_COMPONENT_COUNT_TRANSLATION);
|
||||||
file.read(
|
file.read(
|
||||||
reinterpret_cast<char*>(node.translation.data()),
|
reinterpret_cast<char*>(carrier.data()),
|
||||||
sizeof(double) * NODE_COMPONENT_COUNT_TRANSLATION
|
sizeof(double) * NODE_COMPONENT_COUNT_TRANSLATION
|
||||||
);
|
);
|
||||||
|
translation = GetVec3FromVector(carrier);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag & NODE_DATA_MATRIX)
|
if (flag & NODE_DATA_MATRIX)
|
||||||
{
|
{
|
||||||
node.matrix.resize(NODE_COMPONENT_COUNT_MATRIX);
|
carrier.resize(NODE_COMPONENT_COUNT_MATRIX);
|
||||||
file.read(
|
file.read(
|
||||||
reinterpret_cast<char*>(node.matrix.data()),
|
reinterpret_cast<char*>(carrier.data()),
|
||||||
sizeof(double) * NODE_DATA_MATRIX
|
sizeof(double) * NODE_COMPONENT_COUNT_MATRIX
|
||||||
);
|
);
|
||||||
|
matrix = GetMatrixFromVector(carrier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto result{ SHMatrix::Transform(translation, rotation, scale) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,8 +297,18 @@ namespace SHADE
|
||||||
|
|
||||||
if (header.hasWeights)
|
if (header.hasWeights)
|
||||||
{
|
{
|
||||||
data.VertexWeights.resize(header.vertexCount);
|
data.VertexBoneIndices.resize(header.vertexCount);
|
||||||
file.read(reinterpret_cast<char*>(data.VertexWeights.data()), sizeof(VertexWeight) * header.vertexCount);
|
data.VertexBoneWeights.resize(header.vertexCount);
|
||||||
|
|
||||||
|
file.read(
|
||||||
|
reinterpret_cast<char*>(data.VertexBoneWeights.data()),
|
||||||
|
sizeof(SHVec4) * header.vertexCount
|
||||||
|
);
|
||||||
|
|
||||||
|
file.read(
|
||||||
|
reinterpret_cast<char*>(data.VertexBoneIndices.data()),
|
||||||
|
sizeof(SHVec4U) * header.vertexCount
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
meshes[i] = &data;
|
meshes[i] = &data;
|
||||||
|
|
Loading…
Reference in New Issue