Crahs because of ?

This commit is contained in:
Sam Gateau 2019-10-22 01:43:08 -07:00 committed by sabrina-shanman
parent 465e8c3e18
commit e9ce467eb9
6 changed files with 53 additions and 30 deletions

View file

@ -174,7 +174,6 @@ void appendIndex(MeshData& data, QVector<int>& indices, int index, bool deduplic
data.indices.insert(vertex, newIndex);
data.extracted.newIndices.insert(vertexIndex, newIndex);
data.extracted.mesh.vertices.append(position);
data.extracted.mesh.positions.emplace_back(position);
data.extracted.mesh.originalIndices.append(vertexIndex);
data.extracted.mesh.normals.append(normal);
data.extracted.mesh.texCoords.append(vertex.texCoord);

View file

@ -229,14 +229,22 @@ public:
bool needTangentSpace() const;
};
/// Simple Triangle List <esh
struct TriangleListMesh {
std::vector<glm::vec3> vertices;
std::vector<uint32_t> indices;
std::vector<glm::ivec2> parts; // Offset in the indices, Number of indices
};
/// A single mesh (with optional blendshapes).
class Mesh {
public:
std::vector<MeshPart> parts;
std::vector<glm::vec3> positions;
QVector<glm::vec3> vertices;
std::vector<glm::vec3> _vertices;
QVector<glm::vec3> normals;
QVector<glm::vec3> tangents;
QVector<glm::vec3> colors;
@ -255,6 +263,8 @@ public:
// Blendshape attributes
QVector<Blendshape> blendshapes;
// Simple Triangle List Mesh generated during baking
hfm::TriangleListMesh triangleListMesh;
QVector<int32_t> originalIndices; // Original indices of the vertices
unsigned int meshIndex; // the order the meshes appeared in the object file
@ -262,8 +272,6 @@ public:
graphics::MeshPointer _mesh;
bool wasCompressed { false };
std::vector<glm::vec3> uniqueVertices;
std::vector<uint32_t> trianglesIndices;
};
/// A single animation frame.

View file

@ -145,11 +145,12 @@ ReweightedDeformers getReweightedDeformers(const size_t numMeshVertices, const s
}
const MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector<glm::vec3>& srcVertices, const std::vector<HFMMeshPart>& srcParts) {
const TriangleListMesh generateTriangleListMesh(const std::vector<glm::vec3>& srcVertices, const std::vector<HFMMeshPart>& srcParts) {
MeshIndexedTrianglesPos dest;
// dest.vertices.resize(srcVertices.size());
dest.vertices = srcVertices;
TriangleListMesh dest;
// just copy vertices
dest.vertices.insert(dest.vertices.end(), srcVertices.cbegin(), srcVertices.cend());
/* std::vector<uint32_t> remap(srcVertices.size());
{

View file

@ -25,8 +25,7 @@ void calculateExtentsForShape(hfm::Shape& shape, const std::vector<hfm::Mesh>& m
void calculateExtentsForModel(Extents& modelExtents, const std::vector<hfm::Shape>& shapes);
class ReweightedDeformers {
public:
struct ReweightedDeformers {
std::vector<uint16_t> indices;
std::vector<uint16_t> weights;
uint16_t weightsPerVertex { 0 };
@ -37,15 +36,7 @@ const uint16_t DEFAULT_SKINNING_WEIGHTS_PER_VERTEX = 4;
ReweightedDeformers getReweightedDeformers(const size_t numMeshVertices, const std::vector<hfm::SkinCluster> skinClusters, const uint16_t weightsPerVertex = DEFAULT_SKINNING_WEIGHTS_PER_VERTEX);
struct MeshIndexedTrianglesPos {
public:
std::vector<glm::vec3> vertices;
std::vector<uint32_t> indices;
std::vector<glm::ivec2> parts; // Offset in the indices, Number of indices
};
const MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector<glm::vec3>& srcVertices, const std::vector<HFMMeshPart>& srcParts);
const TriangleListMesh generateTriangleListMesh(const std::vector<glm::vec3>& srcVertices, const std::vector<HFMMeshPart>& srcParts);
};

View file

@ -23,6 +23,7 @@
#include "CalculateExtentsTask.h"
#include "BuildDracoMeshTask.h"
#include "ParseFlowDataTask.h"
#include <hfm/HFMModelMath.h>
namespace baker {
@ -49,6 +50,29 @@ namespace baker {
}
};
class BuildMeshTriangleListTask {
public:
using Input = std::vector<hfm::Mesh>;
using Output = std::vector<hfm::TriangleListMesh>;
using JobModel = Job::ModelIO<BuildMeshTriangleListTask, Input, Output>;
void run(const BakeContextPointer& context, const Input& input, Output& output) {
const auto& meshesIn = input;
auto& indexedTrianglesMeshOut = output;
indexedTrianglesMeshOut.clear();
indexedTrianglesMeshOut.resize(meshesIn.size());
for (int i = 0; i < meshesIn.size(); i++) {
auto& mesh = meshesIn[i];
auto meshPointer = const_cast<HFMMesh*> (&mesh);
meshPointer->_vertices = meshPointer->vertices.toStdVector();
indexedTrianglesMeshOut[i] = hfm::generateTriangleListMesh(meshPointer->_vertices, mesh.parts);
}
}
};
class BuildBlendshapesTask {
public:
using Input = VaryingSet3<BlendshapesPerMesh, std::vector<NormalsPerBlendshape>, std::vector<TangentsPerBlendshape>>;
@ -80,21 +104,23 @@ namespace baker {
class BuildMeshesTask {
public:
using Input = VaryingSet5<std::vector<hfm::Mesh>, std::vector<graphics::MeshPointer>, NormalsPerMesh, TangentsPerMesh, BlendshapesPerMesh>;
using Input = VaryingSet6<std::vector<hfm::Mesh>, std::vector<hfm::TriangleListMesh>, std::vector<graphics::MeshPointer>, NormalsPerMesh, TangentsPerMesh, BlendshapesPerMesh>;
using Output = std::vector<hfm::Mesh>;
using JobModel = Job::ModelIO<BuildMeshesTask, Input, Output>;
void run(const BakeContextPointer& context, const Input& input, Output& output) {
auto& meshesIn = input.get0();
int numMeshes = (int)meshesIn.size();
auto& graphicsMeshesIn = input.get1();
auto& normalsPerMeshIn = input.get2();
auto& tangentsPerMeshIn = input.get3();
auto& blendshapesPerMeshIn = input.get4();
auto& triangleListMeshesIn = input.get1();
auto& graphicsMeshesIn = input.get2();
auto& normalsPerMeshIn = input.get3();
auto& tangentsPerMeshIn = input.get4();
auto& blendshapesPerMeshIn = input.get5();
auto meshesOut = meshesIn;
for (int i = 0; i < numMeshes; i++) {
auto& meshOut = meshesOut[i];
meshOut.triangleListMesh = triangleListMeshesIn[i];
meshOut._mesh = safeGet(graphicsMeshesIn, i);
meshOut.normals = QVector<glm::vec3>::fromStdVector(safeGet(normalsPerMeshIn, i));
meshOut.tangents = QVector<glm::vec3>::fromStdVector(safeGet(tangentsPerMeshIn, i));
@ -162,6 +188,9 @@ namespace baker {
const auto collectShapeVerticesInputs = CollectShapeVerticesTask::Input(meshesIn, shapesIn, jointsIn, skinDeformersIn).asVarying();
const auto shapeVerticesPerJoint = model.addJob<CollectShapeVerticesTask>("CollectShapeVertices", collectShapeVerticesInputs);
// Build the slim triangle list mesh for each hfm::mesh
const auto triangleListMeshes = model.addJob<BuildMeshTriangleListTask>("BuildMeshTriangleListTask", meshesIn);
// Build the graphics::MeshPointer for each hfm::Mesh
const auto buildGraphicsMeshInputs = BuildGraphicsMeshTask::Input(meshesIn, url, meshIndicesToModelNames, normalsPerMesh, tangentsPerMesh, shapesIn, skinDeformersIn).asVarying();
const auto graphicsMeshes = model.addJob<BuildGraphicsMeshTask>("BuildGraphicsMesh", buildGraphicsMeshInputs);
@ -200,7 +229,7 @@ namespace baker {
// Combine the outputs into a new hfm::Model
const auto buildBlendshapesInputs = BuildBlendshapesTask::Input(blendshapesPerMeshIn, normalsPerBlendshapePerMesh, tangentsPerBlendshapePerMesh).asVarying();
const auto blendshapesPerMeshOut = model.addJob<BuildBlendshapesTask>("BuildBlendshapes", buildBlendshapesInputs);
const auto buildMeshesInputs = BuildMeshesTask::Input(meshesIn, graphicsMeshes, normalsPerMesh, tangentsPerMesh, blendshapesPerMeshOut).asVarying();
const auto buildMeshesInputs = BuildMeshesTask::Input(meshesIn, triangleListMeshes, graphicsMeshes, normalsPerMesh, tangentsPerMesh, blendshapesPerMeshOut).asVarying();
const auto meshesOut = model.addJob<BuildMeshesTask>("BuildMeshes", buildMeshesInputs);
const auto buildModelInputs = BuildModelTask::Input(hfmModelIn, meshesOut, jointsOut, jointRotationOffsets, jointIndices, flowData, shapeVerticesPerJoint, shapesOut, modelExtentsOut).asVarying();
const auto hfmModelOut = model.addJob<BuildModelTask>("BuildModel", buildModelInputs);

View file

@ -331,16 +331,11 @@ void ModelResource::setGeometryDefinition(HFMModel::Pointer hfmModel, const Mate
}
std::shared_ptr<GeometryMeshes> meshes = std::make_shared<GeometryMeshes>();
std::vector<hfm::MeshIndexedTrianglesPos> triangleListMeshes = std::vector<hfm::MeshIndexedTrianglesPos>();
int meshID = 0;
for (const HFMMesh& mesh : _hfmModel->meshes) {
// Copy mesh pointers
meshes->emplace_back(mesh._mesh);
meshID++;
auto simpleMesh = hfm::generateMeshIndexedTrianglePos(mesh.positions, mesh.parts);
triangleListMeshes.emplace_back(simpleMesh);
}
_meshes = meshes;