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 {
public:
using Input = VaryingSet2<hfm::Model::Pointer, QVariantHash>;
using Input = VaryingSet2<hfm::Model::Pointer, GeometryMappingPair>;
using Output = VaryingSet2<hfm::Model::Pointer, MaterialMapping>;
using JobModel = Task::ModelIO<BakerEngineBuilder, Input, Output>;
void build(JobModel& model, const Varying& input, Varying& output) {
@ -155,8 +155,7 @@ namespace baker {
const auto jointIndices = jointInfoOut.getN<PrepareJointsTask::Output>(2);
// Parse material mapping
const auto parseMaterialMappingInputs = ParseMaterialMappingTask::Input(url, mapping).asVarying();
const auto materialMapping = model.addJob<ParseMaterialMappingTask>("ParseMaterialMapping", parseMaterialMappingInputs);
const auto materialMapping = model.addJob<ParseMaterialMappingTask>("ParseMaterialMapping", mapping);
// Combine the outputs into a new hfm::Model
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->feedInput<BakerEngineBuilder::Input>(0, hfmModel);
_engine->feedInput<BakerEngineBuilder::Input>(1, mapping);

View file

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

View file

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

View file

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

View file

@ -14,12 +14,13 @@
#include <hfm/HFM.h>
#include "Engine.h"
#include "BakerTypes.h"
#include <material-networking/MaterialCache.h>
class ParseMaterialMappingTask {
public:
using Input = baker::VaryingSet2 <QUrl, QVariantHash>;
using Input = baker::GeometryMappingPair;
using Output = MaterialMapping;
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();
// Get joint renames
auto jointNameMapping = getJointNameMapping(mapping);
auto jointNameMapping = getJointNameMapping(mapping.second);
// Apply joint metadata from FST file mappings
for (const auto& jointIn : jointsIn) {
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
auto offsets = getJointRotationOffsets(mapping);
auto offsets = getJointRotationOffsets(mapping.second);
for (auto itr = offsets.begin(); itr != offsets.end(); itr++) {
QString jointName = itr.key();
int jointIndex = jointIndices.value(jointName) - 1;

View file

@ -17,10 +17,11 @@
#include <hfm/HFM.h>
#include "Engine.h"
#include "BakerTypes.h"
class PrepareJointsTask {
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 JobModel = baker::Job::ModelIO<PrepareJointsTask, Input, Output>;

View file

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

View file

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