mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:35:08 +02:00
Harden model-baker Engine against random tasks being disabled
This commit is contained in:
parent
e4d6d5af89
commit
4ae0c79130
5 changed files with 23 additions and 12 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <shared/HifiTypes.h>
|
||||
|
||||
#include "BakerTypes.h"
|
||||
#include "ModelMath.h"
|
||||
#include "BuildGraphicsMeshTask.h"
|
||||
#include "CalculateMeshNormalsTask.h"
|
||||
#include "CalculateMeshTangentsTask.h"
|
||||
|
@ -59,12 +60,12 @@ namespace baker {
|
|||
blendshapesPerMeshOut = blendshapesPerMeshIn;
|
||||
|
||||
for (int i = 0; i < (int)blendshapesPerMeshOut.size(); i++) {
|
||||
const auto& normalsPerBlendshape = normalsPerBlendshapePerMesh[i];
|
||||
const auto& tangentsPerBlendshape = tangentsPerBlendshapePerMesh[i];
|
||||
const auto& normalsPerBlendshape = safeGet(normalsPerBlendshapePerMesh, i);
|
||||
const auto& tangentsPerBlendshape = safeGet(tangentsPerBlendshapePerMesh, i);
|
||||
auto& blendshapesOut = blendshapesPerMeshOut[i];
|
||||
for (int j = 0; j < (int)blendshapesOut.size(); j++) {
|
||||
const auto& normals = normalsPerBlendshape[j];
|
||||
const auto& tangents = tangentsPerBlendshape[j];
|
||||
const auto& normals = safeGet(normalsPerBlendshape, j);
|
||||
const auto& tangents = safeGet(tangentsPerBlendshape, j);
|
||||
auto& blendshape = blendshapesOut[j];
|
||||
blendshape.normals = QVector<glm::vec3>::fromStdVector(normals);
|
||||
blendshape.tangents = QVector<glm::vec3>::fromStdVector(tangents);
|
||||
|
@ -90,10 +91,10 @@ namespace baker {
|
|||
auto meshesOut = meshesIn;
|
||||
for (int i = 0; i < numMeshes; i++) {
|
||||
auto& meshOut = meshesOut[i];
|
||||
meshOut._mesh = graphicsMeshesIn[i];
|
||||
meshOut.normals = QVector<glm::vec3>::fromStdVector(normalsPerMeshIn[i]);
|
||||
meshOut.tangents = QVector<glm::vec3>::fromStdVector(tangentsPerMeshIn[i]);
|
||||
meshOut.blendshapes = QVector<hfm::Blendshape>::fromStdVector(blendshapesPerMeshIn[i]);
|
||||
meshOut._mesh = safeGet(graphicsMeshesIn, i);
|
||||
meshOut.normals = QVector<glm::vec3>::fromStdVector(safeGet(normalsPerMeshIn, i));
|
||||
meshOut.tangents = QVector<glm::vec3>::fromStdVector(safeGet(tangentsPerMeshIn, i));
|
||||
meshOut.blendshapes = QVector<hfm::Blendshape>::fromStdVector(safeGet(blendshapesPerMeshIn, i));
|
||||
}
|
||||
output = meshesOut;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include <LogHandler.h>
|
||||
#include "ModelBakerLogging.h"
|
||||
#include "ModelMath.h"
|
||||
|
||||
using vec2h = glm::tvec2<glm::detail::hdata>;
|
||||
|
||||
|
@ -385,7 +386,7 @@ void BuildGraphicsMeshTask::run(const baker::BakeContextPointer& context, const
|
|||
auto& graphicsMesh = graphicsMeshes[i];
|
||||
|
||||
// Try to create the graphics::Mesh
|
||||
buildGraphicsMesh(meshes[i], graphicsMesh, normalsPerMesh[i], tangentsPerMesh[i]);
|
||||
buildGraphicsMesh(meshes[i], graphicsMesh, baker::safeGet(normalsPerMesh, i), baker::safeGet(tangentsPerMesh, i));
|
||||
|
||||
// Choose a name for the mesh
|
||||
if (graphicsMesh) {
|
||||
|
|
|
@ -24,7 +24,7 @@ void CalculateBlendshapeTangentsTask::run(const baker::BakeContextPointer& conte
|
|||
|
||||
tangentsPerBlendshapePerMeshOut.reserve(normalsPerBlendshapePerMesh.size());
|
||||
for (size_t i = 0; i < blendshapesPerMesh.size(); i++) {
|
||||
const auto& normalsPerBlendshape = normalsPerBlendshapePerMesh[i];
|
||||
const auto& normalsPerBlendshape = baker::safeGet(normalsPerBlendshapePerMesh, i);
|
||||
const auto& blendshapes = blendshapesPerMesh[i];
|
||||
const auto& mesh = meshes[i];
|
||||
tangentsPerBlendshapePerMeshOut.emplace_back();
|
||||
|
@ -43,7 +43,7 @@ void CalculateBlendshapeTangentsTask::run(const baker::BakeContextPointer& conte
|
|||
for (size_t j = 0; j < blendshapes.size(); j++) {
|
||||
const auto& blendshape = blendshapes[j];
|
||||
const auto& tangentsIn = blendshape.tangents;
|
||||
const auto& normals = normalsPerBlendshape[j];
|
||||
const auto& normals = baker::safeGet(normalsPerBlendshape, j);
|
||||
tangentsPerBlendshapeOut.emplace_back();
|
||||
auto& tangentsOut = tangentsPerBlendshapeOut[tangentsPerBlendshapeOut.size()-1];
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ void CalculateMeshTangentsTask::run(const baker::BakeContextPointer& context, co
|
|||
for (int i = 0; i < (int)meshes.size(); i++) {
|
||||
const auto& mesh = meshes[i];
|
||||
const auto& tangentsIn = mesh.tangents;
|
||||
const auto& normals = normalsPerMesh[i];
|
||||
const auto& normals = baker::safeGet(normalsPerMesh, i);
|
||||
tangentsPerMeshOut.emplace_back();
|
||||
auto& tangentsOut = tangentsPerMeshOut[tangentsPerMeshOut.size()-1];
|
||||
|
||||
|
|
|
@ -14,6 +14,15 @@
|
|||
#include "BakerTypes.h"
|
||||
|
||||
namespace baker {
|
||||
template<typename T>
|
||||
T safeGet(const std::vector<T>& data, size_t i) {
|
||||
if (data.size() > i) {
|
||||
return data[i];
|
||||
} else {
|
||||
return T();
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a reference to the normal at the specified index, or nullptr if it cannot be accessed
|
||||
using NormalAccessor = std::function<glm::vec3*(int index)>;
|
||||
|
||||
|
|
Loading…
Reference in a new issue