chore: make XModelCommon use offset instead of pointer

This commit is contained in:
Jan
2024-07-28 20:46:06 +02:00
parent d45f0ffab7
commit f8b5734f86
8 changed files with 41 additions and 36 deletions

View File

@ -18,12 +18,16 @@ protected:
auto vertexOffset = 0u;
for (const auto& vertex : xmodel.m_vertices)
{
XModelVertexBoneWeights weights{nullptr, 0};
XModelVertexBoneWeights weights{0, 0};
if (vertexOffset < xmodel.m_vertex_bone_weights.size())
weights = xmodel.m_vertex_bone_weights[vertexOffset];
m_vertex_merger.Add(VertexMergerPos{vertex.coordinates[0], vertex.coordinates[1], vertex.coordinates[2], weights.weights, weights.weightCount});
m_vertex_merger.Add(VertexMergerPos{vertex.coordinates[0],
vertex.coordinates[1],
vertex.coordinates[2],
&xmodel.m_bone_weight_data.weights[weights.weightOffset],
weights.weightCount});
vertexOffset++;
}

View File

@ -496,14 +496,15 @@ namespace
auto* weights = reinterpret_cast<float*>(&bufferData[currentBufferOffset + sizeof(uint8_t) * 4u * xmodel.m_vertex_bone_weights.size()]);
for (const auto& commonVertexWeights : xmodel.m_vertex_bone_weights)
{
assert(commonVertexWeights.weights != nullptr);
assert(commonVertexWeights.weightOffset < xmodel.m_bone_weight_data.weights.size());
assert(commonVertexWeights.weightCount <= 4u);
const auto commonVertexWeightCount = std::min(commonVertexWeights.weightCount, 4u);
const auto* commonVertexWeightData = &xmodel.m_bone_weight_data.weights[commonVertexWeights.weightOffset];
for (auto i = 0u; i < commonVertexWeightCount; i++)
{
joints[i] = static_cast<unsigned char>(commonVertexWeights.weights[i].boneIndex);
weights[i] = commonVertexWeights.weights[i].weight;
joints[i] = static_cast<unsigned char>(commonVertexWeightData[i].boneIndex);
weights[i] = commonVertexWeightData[i].weight;
}
for (auto i = commonVertexWeightCount; i < 4u; i++)