Animation WIP
This commit is contained in:
parent
52fc8132d9
commit
6615f0c2b8
|
@ -45,7 +45,10 @@ namespace SH_COMP
|
|||
static BufferData buffer;
|
||||
|
||||
static inline void LoadFromFile(AssetPath path, ModelRef asset) noexcept;
|
||||
static inline void ProcessModel(ModelData const&, ModelRef asset) noexcept;
|
||||
|
||||
static inline void ProcessModel(ModelData const& model, ModelRef asset) noexcept;
|
||||
static inline void ProcessAnimations(ModelData const& model, ModelRef asset) noexcept;
|
||||
|
||||
static inline void BuildHeaders(ModelRef asset) noexcept;
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace SH_COMP
|
|||
BufferViewReference MeshCompiler::bufferViews{ nullptr };
|
||||
BufferData MeshCompiler::buffer{ nullptr };
|
||||
|
||||
void MeshCompiler::LoadFromFile(AssetPath path, ModelRef asset) noexcept
|
||||
inline void MeshCompiler::LoadFromFile(AssetPath path, ModelRef asset) noexcept
|
||||
{
|
||||
ModelData model;
|
||||
tinygltf::TinyGLTF loader;
|
||||
|
@ -57,9 +57,10 @@ namespace SH_COMP
|
|||
}
|
||||
|
||||
ProcessModel(model, asset);
|
||||
ProcessAnimations(model, asset);
|
||||
}
|
||||
|
||||
void MeshCompiler::ProcessModel(ModelData const& data, ModelRef asset) noexcept
|
||||
inline void MeshCompiler::ProcessModel(ModelData const& data, ModelRef asset) noexcept
|
||||
{
|
||||
#if 0
|
||||
for (auto i {0}; i < 2; ++i)
|
||||
|
@ -86,11 +87,7 @@ namespace SH_COMP
|
|||
FetchData(primitive.attributes.at(ATT_POSITION.data()), meshIn.vertexPosition);
|
||||
FetchData(primitive.attributes.at(ATT_NORMAL.data()), meshIn.vertexNormal);
|
||||
FetchData(primitive.attributes.at(ATT_TEXCOORD.data()), meshIn.texCoords);
|
||||
|
||||
std::vector<unsigned short> indices_ushort;
|
||||
FetchData(primitive.indices, indices_ushort);
|
||||
meshIn.indices.resize(indices_ushort.size());
|
||||
std::ranges::copy(indices_ushort, meshIn.indices.begin());
|
||||
FetchData(primitive.indices, meshIn.indices);
|
||||
|
||||
std::vector<SHVec4> intermediate;
|
||||
FetchData(primitive.attributes.at(ATT_TANGENT.data()), intermediate);
|
||||
|
@ -120,9 +117,10 @@ namespace SH_COMP
|
|||
auto const& view = (*bufferViews)[accessor.bufferView];
|
||||
auto const typeIdentifier{ static_cast<ACCESSOR_COMPONENT_TYPE>(accessor.componentType) };
|
||||
auto const sizeIdentifier{ SizeOfType(typeIdentifier) };
|
||||
auto const componentCount{ CountOfType(accessor.type) };
|
||||
auto const componentCount{ CountOfType(static_cast<ACCESSOR_DATA_TYPE>(accessor.type))};
|
||||
auto const totalStrideBytes{ sizeIdentifier * componentCount };
|
||||
dst.resize(accessor.count);
|
||||
if (sizeof(T) == sizeIdentifier * componentCount)
|
||||
if (sizeof(T) == totalStrideBytes)
|
||||
{
|
||||
std::memcpy(
|
||||
dst.data(),
|
||||
|
@ -140,9 +138,13 @@ namespace SH_COMP
|
|||
);
|
||||
|
||||
auto srcPtr{ tempData.data() };
|
||||
auto dstPtr{ dst.data() };
|
||||
T* dstPtr{ dst.data() };
|
||||
size_t index{ 0 };
|
||||
for (auto i{0}; i < accessor.count; ++i, ++index)
|
||||
{
|
||||
auto srcCompPtr{ srcPtr };
|
||||
auto dstCompPtr{ reinterpret_cast<IndexType*>(dstPtr)};
|
||||
for (auto j{0}; j < componentCount; ++j)
|
||||
{
|
||||
std::memcpy(
|
||||
dstPtr,
|
||||
|
@ -150,8 +152,13 @@ namespace SH_COMP
|
|||
sizeIdentifier
|
||||
);
|
||||
|
||||
srcPtr += sizeIdentifier;
|
||||
dstPtr += sizeof(T);
|
||||
srcCompPtr += sizeIdentifier;
|
||||
++dstCompPtr;
|
||||
}
|
||||
|
||||
srcPtr += totalStrideBytes;
|
||||
|
||||
++dstPtr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,4 +189,18 @@ namespace SH_COMP
|
|||
|
||||
delete asset;
|
||||
}
|
||||
|
||||
inline void MeshCompiler::ProcessAnimations(ModelData const& model, ModelRef asset) noexcept
|
||||
{
|
||||
asset.anims.resize(model.animations.size());
|
||||
for (auto i {0}; i < model.animations.size(); ++i)
|
||||
{
|
||||
auto& animData{ model.animations[i] };
|
||||
auto& anim{ asset.anims[i] };
|
||||
|
||||
anim.name = animData.name;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,4 +35,7 @@ namespace SH_COMP
|
|||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
using IndexType = uint32_t;
|
||||
|
||||
}
|
|
@ -41,7 +41,7 @@ namespace SH_COMP
|
|||
std::vector<SHVec3> vertexTangent;
|
||||
std::vector<SHVec3> vertexNormal;
|
||||
std::vector<SHVec2> texCoords;
|
||||
std::vector<uint32_t> indices;
|
||||
std::vector<IndexType> indices;
|
||||
std::vector<MeshBoneInfo> bonesInfo;
|
||||
std::vector<MeshBone> bones;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue