Add passthrough config to PrepareJointsTask

This commit is contained in:
sabrina-shanman 2019-02-20 14:28:44 -08:00
parent 9c9dc553a2
commit aef696efe6
2 changed files with 47 additions and 25 deletions

View file

@ -50,37 +50,46 @@ QMap<QString, glm::quat> getJointRotationOffsets(const QVariantHash& mapping) {
return jointRotationOffsets; return jointRotationOffsets;
} }
void PrepareJointsTask::configure(const Config& config) {
_passthrough = config.passthrough;
}
void PrepareJointsTask::run(const baker::BakeContextPointer& context, const Input& input, Output& output) { void PrepareJointsTask::run(const baker::BakeContextPointer& context, const Input& input, Output& output) {
const auto& jointsIn = input.get0(); const auto& jointsIn = input.get0();
const auto& mapping = input.get1();
auto& jointsOut = output.edit0(); auto& jointsOut = output.edit0();
auto& jointRotationOffsets = output.edit1();
auto& jointIndices = output.edit2();
// Get joint renames if (_passthrough) {
auto jointNameMapping = getJointNameMapping(mapping); jointsOut = jointsIn;
// Apply joint metadata from FST file mappings } else {
for (const auto& jointIn : jointsIn) { const auto& mapping = input.get1();
jointsOut.push_back(jointIn); auto& jointRotationOffsets = output.edit1();
auto& jointOut = jointsOut.back(); auto& jointIndices = output.edit2();
auto jointNameMapKey = jointNameMapping.key(jointIn.name); // Get joint renames
if (jointNameMapping.contains(jointNameMapKey)) { auto jointNameMapping = getJointNameMapping(mapping);
jointOut.name = jointNameMapKey; // Apply joint metadata from FST file mappings
for (const auto& jointIn : jointsIn) {
jointsOut.push_back(jointIn);
auto& jointOut = jointsOut.back();
auto jointNameMapKey = jointNameMapping.key(jointIn.name);
if (jointNameMapping.contains(jointNameMapKey)) {
jointOut.name = jointNameMapKey;
}
jointIndices.insert(jointOut.name, (int)jointsOut.size());
} }
jointIndices.insert(jointOut.name, (int)jointsOut.size()); // Get joint rotation offsets from FST file mappings
} auto offsets = getJointRotationOffsets(mapping);
for (auto itr = offsets.begin(); itr != offsets.end(); itr++) {
// Get joint rotation offsets from FST file mappings QString jointName = itr.key();
auto offsets = getJointRotationOffsets(mapping); int jointIndex = jointIndices.value(jointName) - 1;
for (auto itr = offsets.begin(); itr != offsets.end(); itr++) { if (jointIndex != -1) {
QString jointName = itr.key(); glm::quat rotationOffset = itr.value();
int jointIndex = jointIndices.value(jointName) - 1; jointRotationOffsets.insert(jointIndex, rotationOffset);
if (jointIndex != -1) { qCDebug(model_baker) << "Joint Rotation Offset added to Rig._jointRotationOffsets : " << " jointName: " << jointName << " jointIndex: " << jointIndex << " rotation offset: " << rotationOffset;
glm::quat rotationOffset = itr.value(); }
jointRotationOffsets.insert(jointIndex, rotationOffset);
qCDebug(model_baker) << "Joint Rotation Offset added to Rig._jointRotationOffsets : " << " jointName: " << jointName << " jointIndex: " << jointIndex << " rotation offset: " << rotationOffset;
} }
} }
} }

View file

@ -18,13 +18,26 @@
#include "Engine.h" #include "Engine.h"
// The property "passthrough", when enabled, will let the input joints flow to the output unmodified, unlike the disabled property, which discards the data
class PrepareJointsTaskConfig : public baker::JobConfig {
Q_OBJECT
Q_PROPERTY(bool passthrough MEMBER passthrough)
public:
bool passthrough { false };
};
class PrepareJointsTask { class PrepareJointsTask {
public: public:
using Config = PrepareJointsTaskConfig;
using Input = baker::VaryingSet2<std::vector<hfm::Joint>, QVariantHash /*mapping*/>; using Input = baker::VaryingSet2<std::vector<hfm::Joint>, QVariantHash /*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, Config>;
void configure(const Config& config);
void run(const baker::BakeContextPointer& context, const Input& input, Output& output); void run(const baker::BakeContextPointer& context, const Input& input, Output& output);
protected:
bool _passthrough { false };
}; };
#endif // hifi_PrepareJointsTask_h #endif // hifi_PrepareJointsTask_h