use fst mapping path as reference instead of model path

This commit is contained in:
Thijs Wenker 2019-02-28 23:22:55 +01:00
parent de3c5e0ffe
commit 6aede024f4
9 changed files with 40 additions and 29 deletions

View file

@ -117,7 +117,7 @@ namespace baker {
class BakerEngineBuilder { class BakerEngineBuilder {
public: public:
using Input = VaryingSet2<hfm::Model::Pointer, QVariantHash>; using Input = VaryingSet2<hfm::Model::Pointer, GeometryMappingPair>;
using Output = VaryingSet2<hfm::Model::Pointer, MaterialMapping>; using Output = VaryingSet2<hfm::Model::Pointer, MaterialMapping>;
using JobModel = Task::ModelIO<BakerEngineBuilder, Input, Output>; using JobModel = Task::ModelIO<BakerEngineBuilder, Input, Output>;
void build(JobModel& model, const Varying& input, Varying& output) { void build(JobModel& model, const Varying& input, Varying& output) {
@ -155,8 +155,7 @@ namespace baker {
const auto jointIndices = jointInfoOut.getN<PrepareJointsTask::Output>(2); const auto jointIndices = jointInfoOut.getN<PrepareJointsTask::Output>(2);
// Parse material mapping // Parse material mapping
const auto parseMaterialMappingInputs = ParseMaterialMappingTask::Input(url, mapping).asVarying(); const auto materialMapping = model.addJob<ParseMaterialMappingTask>("ParseMaterialMapping", mapping);
const auto materialMapping = model.addJob<ParseMaterialMappingTask>("ParseMaterialMapping", parseMaterialMappingInputs);
// Combine the outputs into a new hfm::Model // Combine the outputs into a new hfm::Model
const auto buildBlendshapesInputs = BuildBlendshapesTask::Input(blendshapesPerMeshIn, normalsPerBlendshapePerMesh, tangentsPerBlendshapePerMesh).asVarying(); const auto buildBlendshapesInputs = BuildBlendshapesTask::Input(blendshapesPerMeshIn, normalsPerBlendshapePerMesh, tangentsPerBlendshapePerMesh).asVarying();
@ -170,7 +169,7 @@ namespace baker {
} }
}; };
Baker::Baker(const hfm::Model::Pointer& hfmModel, const QVariantHash& mapping) : Baker::Baker(const hfm::Model::Pointer& hfmModel, const GeometryMappingPair& mapping) :
_engine(std::make_shared<Engine>(BakerEngineBuilder::JobModel::create("Baker"), std::make_shared<BakeContext>())) { _engine(std::make_shared<Engine>(BakerEngineBuilder::JobModel::create("Baker"), std::make_shared<BakeContext>())) {
_engine->feedInput<BakerEngineBuilder::Input>(0, hfmModel); _engine->feedInput<BakerEngineBuilder::Input>(0, hfmModel);
_engine->feedInput<BakerEngineBuilder::Input>(1, mapping); _engine->feedInput<BakerEngineBuilder::Input>(1, mapping);

View file

@ -17,13 +17,14 @@
#include <hfm/HFM.h> #include <hfm/HFM.h>
#include "Engine.h" #include "Engine.h"
#include "BakerTypes.h"
#include "ParseMaterialMappingTask.h" #include "ParseMaterialMappingTask.h"
namespace baker { namespace baker {
class Baker { class Baker {
public: public:
Baker(const hfm::Model::Pointer& hfmModel, const QVariantHash& mapping); Baker(const hfm::Model::Pointer& hfmModel, const GeometryMappingPair& mapping);
void run(); void run();

View file

@ -12,6 +12,7 @@
#ifndef hifi_BakerTypes_h #ifndef hifi_BakerTypes_h
#define hifi_BakerTypes_h #define hifi_BakerTypes_h
#include <QUrl>
#include <hfm/HFM.h> #include <hfm/HFM.h>
namespace baker { namespace baker {
@ -35,6 +36,7 @@ namespace baker {
using TangentsPerBlendshape = std::vector<std::vector<glm::vec3>>; using TangentsPerBlendshape = std::vector<std::vector<glm::vec3>>;
using MeshIndicesToModelNames = QHash<int, QString>; using MeshIndicesToModelNames = QHash<int, QString>;
using GeometryMappingPair = std::pair<QUrl, QVariantHash>;
}; };
#endif // hifi_BakerTypes_h #endif // hifi_BakerTypes_h

View file

@ -11,8 +11,8 @@
#include "ModelBakerLogging.h" #include "ModelBakerLogging.h"
void ParseMaterialMappingTask::run(const baker::BakeContextPointer& context, const Input& input, Output& output) { void ParseMaterialMappingTask::run(const baker::BakeContextPointer& context, const Input& input, Output& output) {
const auto& url = input.get0(); const auto& url = input.first;
const auto& mapping = input.get1(); const auto& mapping = input.second;
MaterialMapping materialMapping; MaterialMapping materialMapping;
auto mappingIter = mapping.find("materialMap"); auto mappingIter = mapping.find("materialMap");

View file

@ -14,12 +14,13 @@
#include <hfm/HFM.h> #include <hfm/HFM.h>
#include "Engine.h" #include "Engine.h"
#include "BakerTypes.h"
#include <material-networking/MaterialCache.h> #include <material-networking/MaterialCache.h>
class ParseMaterialMappingTask { class ParseMaterialMappingTask {
public: public:
using Input = baker::VaryingSet2 <QUrl, QVariantHash>; using Input = baker::GeometryMappingPair;
using Output = MaterialMapping; using Output = MaterialMapping;
using JobModel = baker::Job::ModelIO<ParseMaterialMappingTask, Input, Output>; using JobModel = baker::Job::ModelIO<ParseMaterialMappingTask, Input, Output>;

View file

@ -58,7 +58,7 @@ void PrepareJointsTask::run(const baker::BakeContextPointer& context, const Inpu
auto& jointIndices = output.edit2(); auto& jointIndices = output.edit2();
// Get joint renames // Get joint renames
auto jointNameMapping = getJointNameMapping(mapping); auto jointNameMapping = getJointNameMapping(mapping.second);
// Apply joint metadata from FST file mappings // Apply joint metadata from FST file mappings
for (const auto& jointIn : jointsIn) { for (const auto& jointIn : jointsIn) {
jointsOut.push_back(jointIn); jointsOut.push_back(jointIn);
@ -73,7 +73,7 @@ void PrepareJointsTask::run(const baker::BakeContextPointer& context, const Inpu
} }
// Get joint rotation offsets from FST file mappings // Get joint rotation offsets from FST file mappings
auto offsets = getJointRotationOffsets(mapping); auto offsets = getJointRotationOffsets(mapping.second);
for (auto itr = offsets.begin(); itr != offsets.end(); itr++) { for (auto itr = offsets.begin(); itr != offsets.end(); itr++) {
QString jointName = itr.key(); QString jointName = itr.key();
int jointIndex = jointIndices.value(jointName) - 1; int jointIndex = jointIndices.value(jointName) - 1;

View file

@ -17,10 +17,11 @@
#include <hfm/HFM.h> #include <hfm/HFM.h>
#include "Engine.h" #include "Engine.h"
#include "BakerTypes.h"
class PrepareJointsTask { class PrepareJointsTask {
public: public:
using Input = baker::VaryingSet2<std::vector<hfm::Joint>, QVariantHash /*mapping*/>; using Input = baker::VaryingSet2<std::vector<hfm::Joint>, baker::GeometryMappingPair /*mapping*/>;
using Output = baker::VaryingSet3<std::vector<hfm::Joint>, QMap<int, glm::quat> /*jointRotationOffsets*/, QHash<QString, int> /*jointIndices*/>; using Output = baker::VaryingSet3<std::vector<hfm::Joint>, QMap<int, glm::quat> /*jointRotationOffsets*/, QHash<QString, int> /*jointIndices*/>;
using JobModel = baker::Job::ModelIO<PrepareJointsTask, Input, Output>; using JobModel = baker::Job::ModelIO<PrepareJointsTask, Input, Output>;

View file

@ -35,11 +35,13 @@ class GeometryReader;
class GeometryExtra { class GeometryExtra {
public: public:
const QVariantHash& mapping; const GeometryMappingPair& mapping;
const QUrl& textureBaseUrl; const QUrl& textureBaseUrl;
bool combineParts; bool combineParts;
}; };
int geometryMappingPairTypeId = qRegisterMetaType<GeometryMappingPair>("GeometryMappingPair");
// From: https://stackoverflow.com/questions/41145012/how-to-hash-qvariant // From: https://stackoverflow.com/questions/41145012/how-to-hash-qvariant
class QVariantHasher { class QVariantHasher {
public: public:
@ -78,7 +80,7 @@ namespace std {
struct hash<GeometryExtra> { struct hash<GeometryExtra> {
size_t operator()(const GeometryExtra& geometryExtra) const { size_t operator()(const GeometryExtra& geometryExtra) const {
size_t result = 0; size_t result = 0;
hash_combine(result, geometryExtra.mapping, geometryExtra.textureBaseUrl, geometryExtra.combineParts); hash_combine(result, geometryExtra.mapping.second, geometryExtra.textureBaseUrl, geometryExtra.combineParts);
return result; return result;
} }
}; };
@ -151,7 +153,7 @@ void GeometryMappingResource::downloadFinished(const QByteArray& data) {
} }
auto modelCache = DependencyManager::get<ModelCache>(); auto modelCache = DependencyManager::get<ModelCache>();
GeometryExtra extra { _mapping, _textureBaseUrl, false }; GeometryExtra extra { GeometryMappingPair(_url, _mapping), _textureBaseUrl, false };
// Get the raw GeometryResource // Get the raw GeometryResource
_geometryResource = modelCache->getResource(url, QUrl(), &extra, std::hash<GeometryExtra>()(extra)).staticCast<GeometryResource>(); _geometryResource = modelCache->getResource(url, QUrl(), &extra, std::hash<GeometryExtra>()(extra)).staticCast<GeometryResource>();
@ -191,7 +193,7 @@ void GeometryMappingResource::onGeometryMappingLoaded(bool success) {
class GeometryReader : public QRunnable { class GeometryReader : public QRunnable {
public: public:
GeometryReader(const ModelLoader& modelLoader, QWeakPointer<Resource>& resource, const QUrl& url, const QVariantHash& mapping, GeometryReader(const ModelLoader& modelLoader, QWeakPointer<Resource>& resource, const QUrl& url, const GeometryMappingPair& mapping,
const QByteArray& data, bool combineParts, const QString& webMediaType) : const QByteArray& data, bool combineParts, const QString& webMediaType) :
_modelLoader(modelLoader), _resource(resource), _url(url), _mapping(mapping), _data(data), _combineParts(combineParts), _webMediaType(webMediaType) { _modelLoader(modelLoader), _resource(resource), _url(url), _mapping(mapping), _data(data), _combineParts(combineParts), _webMediaType(webMediaType) {
@ -204,7 +206,7 @@ private:
ModelLoader _modelLoader; ModelLoader _modelLoader;
QWeakPointer<Resource> _resource; QWeakPointer<Resource> _resource;
QUrl _url; QUrl _url;
QVariantHash _mapping; GeometryMappingPair _mapping;
QByteArray _data; QByteArray _data;
bool _combineParts; bool _combineParts;
QString _webMediaType; QString _webMediaType;
@ -244,7 +246,7 @@ void GeometryReader::run() {
} }
HFMModel::Pointer hfmModel; HFMModel::Pointer hfmModel;
QVariantHash serializerMapping = _mapping; QVariantHash serializerMapping = _mapping.second;
serializerMapping["combineParts"] = _combineParts; serializerMapping["combineParts"] = _combineParts;
if (_url.path().toLower().endsWith(".gz")) { if (_url.path().toLower().endsWith(".gz")) {
@ -270,15 +272,14 @@ void GeometryReader::run() {
} }
// Add scripts to hfmModel // Add scripts to hfmModel
if (!_mapping.value(SCRIPT_FIELD).isNull()) { if (!serializerMapping.value(SCRIPT_FIELD).isNull()) {
QVariantList scripts = _mapping.values(SCRIPT_FIELD); QVariantList scripts = serializerMapping.values(SCRIPT_FIELD);
for (auto &script : scripts) { for (auto &script : scripts) {
hfmModel->scripts.push_back(script.toString()); hfmModel->scripts.push_back(script.toString());
} }
} }
QMetaObject::invokeMethod(resource.data(), "setGeometryDefinition", QMetaObject::invokeMethod(resource.data(), "setGeometryDefinition",
Q_ARG(HFMModel::Pointer, hfmModel), Q_ARG(QVariantHash, _mapping)); Q_ARG(HFMModel::Pointer, hfmModel), Q_ARG(GeometryMappingPair, _mapping));
} catch (const std::exception&) { } catch (const std::exception&) {
auto resource = _resource.toStrongRef(); auto resource = _resource.toStrongRef();
if (resource) { if (resource) {
@ -312,17 +313,17 @@ public:
void setExtra(void* extra) override; void setExtra(void* extra) override;
protected: protected:
Q_INVOKABLE void setGeometryDefinition(HFMModel::Pointer hfmModel, QVariantHash mapping); Q_INVOKABLE void setGeometryDefinition(HFMModel::Pointer hfmModel, const GeometryMappingPair& mapping);
private: private:
ModelLoader _modelLoader; ModelLoader _modelLoader;
QVariantHash _mapping; GeometryMappingPair _mapping;
bool _combineParts; bool _combineParts;
}; };
void GeometryDefinitionResource::setExtra(void* extra) { void GeometryDefinitionResource::setExtra(void* extra) {
const GeometryExtra* geometryExtra = static_cast<const GeometryExtra*>(extra); const GeometryExtra* geometryExtra = static_cast<const GeometryExtra*>(extra);
_mapping = geometryExtra ? geometryExtra->mapping : QVariantHash(); _mapping = geometryExtra ? geometryExtra->mapping : GeometryMappingPair(QUrl(), QVariantHash());
_textureBaseUrl = geometryExtra ? resolveTextureBaseUrl(_url, geometryExtra->textureBaseUrl) : QUrl(); _textureBaseUrl = geometryExtra ? resolveTextureBaseUrl(_url, geometryExtra->textureBaseUrl) : QUrl();
_combineParts = geometryExtra ? geometryExtra->combineParts : true; _combineParts = geometryExtra ? geometryExtra->combineParts : true;
} }
@ -335,7 +336,7 @@ void GeometryDefinitionResource::downloadFinished(const QByteArray& data) {
QThreadPool::globalInstance()->start(new GeometryReader(_modelLoader, _self, _effectiveBaseURL, _mapping, data, _combineParts, _request->getWebMediaType())); QThreadPool::globalInstance()->start(new GeometryReader(_modelLoader, _self, _effectiveBaseURL, _mapping, data, _combineParts, _request->getWebMediaType()));
} }
void GeometryDefinitionResource::setGeometryDefinition(HFMModel::Pointer hfmModel, QVariantHash mapping) { void GeometryDefinitionResource::setGeometryDefinition(HFMModel::Pointer hfmModel, const GeometryMappingPair& mapping) {
// Do processing on the model // Do processing on the model
baker::Baker modelBaker(hfmModel, mapping); baker::Baker modelBaker(hfmModel, mapping);
modelBaker.run(); modelBaker.run();
@ -398,7 +399,7 @@ QSharedPointer<Resource> ModelCache::createResourceCopy(const QSharedPointer<Res
} }
GeometryResource::Pointer ModelCache::getGeometryResource(const QUrl& url, GeometryResource::Pointer ModelCache::getGeometryResource(const QUrl& url,
const QVariantHash& mapping, const QUrl& textureBaseUrl) { const GeometryMappingPair& mapping, const QUrl& textureBaseUrl) {
bool combineParts = true; bool combineParts = true;
GeometryExtra geometryExtra = { mapping, textureBaseUrl, combineParts }; GeometryExtra geometryExtra = { mapping, textureBaseUrl, combineParts };
GeometryResource::Pointer resource = getResource(url, QUrl(), &geometryExtra, std::hash<GeometryExtra>()(geometryExtra)).staticCast<GeometryResource>(); GeometryResource::Pointer resource = getResource(url, QUrl(), &geometryExtra, std::hash<GeometryExtra>()(geometryExtra)).staticCast<GeometryResource>();
@ -411,7 +412,8 @@ GeometryResource::Pointer ModelCache::getGeometryResource(const QUrl& url,
} }
GeometryResource::Pointer ModelCache::getCollisionGeometryResource(const QUrl& url, GeometryResource::Pointer ModelCache::getCollisionGeometryResource(const QUrl& url,
const QVariantHash& mapping, const QUrl& textureBaseUrl) { const GeometryMappingPair& mapping,
const QUrl& textureBaseUrl) {
bool combineParts = false; bool combineParts = false;
GeometryExtra geometryExtra = { mapping, textureBaseUrl, combineParts }; GeometryExtra geometryExtra = { mapping, textureBaseUrl, combineParts };
GeometryResource::Pointer resource = getResource(url, QUrl(), &geometryExtra, std::hash<GeometryExtra>()(geometryExtra)).staticCast<GeometryResource>(); GeometryResource::Pointer resource = getResource(url, QUrl(), &geometryExtra, std::hash<GeometryExtra>()(geometryExtra)).staticCast<GeometryResource>();

View file

@ -26,6 +26,9 @@ class MeshPart;
class GeometryMappingResource; class GeometryMappingResource;
using GeometryMappingPair = std::pair<QUrl, QVariantHash>;
Q_DECLARE_METATYPE(GeometryMappingPair)
class Geometry { class Geometry {
public: public:
using Pointer = std::shared_ptr<Geometry>; using Pointer = std::shared_ptr<Geometry>;
@ -145,11 +148,13 @@ class ModelCache : public ResourceCache, public Dependency {
public: public:
GeometryResource::Pointer getGeometryResource(const QUrl& url, GeometryResource::Pointer getGeometryResource(const QUrl& url,
const QVariantHash& mapping = QVariantHash(), const GeometryMappingPair& mapping =
GeometryMappingPair(QUrl(), QVariantHash()),
const QUrl& textureBaseUrl = QUrl()); const QUrl& textureBaseUrl = QUrl());
GeometryResource::Pointer getCollisionGeometryResource(const QUrl& url, GeometryResource::Pointer getCollisionGeometryResource(const QUrl& url,
const QVariantHash& mapping = QVariantHash(), const GeometryMappingPair& mapping =
GeometryMappingPair(QUrl(), QVariantHash()),
const QUrl& textureBaseUrl = QUrl()); const QUrl& textureBaseUrl = QUrl());
protected: protected: