Merge pull request #3623 from ey6es/master

For FBX files with marked "skeleton" joints, only show those marked nodes in the upload dialog.  Also added some more default node names to look for on upload.
This commit is contained in:
AndrewMeadows 2014-10-20 09:00:06 -07:00
commit 2569f70ac3
3 changed files with 42 additions and 7 deletions

View file

@ -157,17 +157,19 @@ bool ModelUploader::zip() {
// mixamo/autodesk defaults // mixamo/autodesk defaults
if (!mapping.contains(SCALE_FIELD)) { if (!mapping.contains(SCALE_FIELD)) {
mapping.insert(SCALE_FIELD, geometry.author == "www.makehuman.org" ? 150.0 : 15.0); mapping.insert(SCALE_FIELD, 15.0);
} }
QVariantHash joints = mapping.value(JOINT_FIELD).toHash(); QVariantHash joints = mapping.value(JOINT_FIELD).toHash();
if (!joints.contains("jointEyeLeft")) { if (!joints.contains("jointEyeLeft")) {
joints.insert("jointEyeLeft", geometry.jointIndices.contains("EyeLeft") ? "EyeLeft" : "LeftEye"); joints.insert("jointEyeLeft", geometry.jointIndices.contains("jointEyeLeft") ? "jointEyeLeft" :
(geometry.jointIndices.contains("EyeLeft") ? "EyeLeft" : "LeftEye"));
} }
if (!joints.contains("jointEyeRight")) { if (!joints.contains("jointEyeRight")) {
joints.insert("jointEyeRight", geometry.jointIndices.contains("EyeRight") ? "EyeRight" : "RightEye"); joints.insert("jointEyeRight", geometry.jointIndices.contains("jointEyeRight") ? "jointEyeRight" :
geometry.jointIndices.contains("EyeRight") ? "EyeRight" : "RightEye");
} }
if (!joints.contains("jointNeck")) { if (!joints.contains("jointNeck")) {
joints.insert("jointNeck", "Neck"); joints.insert("jointNeck", geometry.jointIndices.contains("jointNeck") ? "jointNeck" : "Neck");
} }
if (!joints.contains("jointRoot")) { if (!joints.contains("jointRoot")) {
joints.insert("jointRoot", "Hips"); joints.insert("jointRoot", "Hips");
@ -785,7 +787,9 @@ QComboBox* ModelPropertiesDialog::createJointBox(bool withNone) const {
box->addItem("(none)"); box->addItem("(none)");
} }
foreach (const FBXJoint& joint, _geometry.joints) { foreach (const FBXJoint& joint, _geometry.joints) {
box->addItem(joint.name); if (joint.isSkeletonJoint || !_geometry.hasSkeletonJoints) {
box->addItem(joint.name);
}
} }
return box; return box;
} }

View file

@ -1015,6 +1015,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
QHash<QString, QByteArray> textureFilenames; QHash<QString, QByteArray> textureFilenames;
QHash<QByteArray, QByteArray> textureContent; QHash<QByteArray, QByteArray> textureContent;
QHash<QString, Material> materials; QHash<QString, Material> materials;
QHash<QString, QString> typeFlags;
QHash<QString, QString> diffuseTextures; QHash<QString, QString> diffuseTextures;
QHash<QString, QString> bumpTextures; QHash<QString, QString> bumpTextures;
QHash<QString, QString> specularTextures; QHash<QString, QString> specularTextures;
@ -1072,6 +1073,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
QMultiHash<QString, WeightedIndex> blendshapeChannelIndices; QMultiHash<QString, WeightedIndex> blendshapeChannelIndices;
FBXGeometry geometry; FBXGeometry geometry;
float unitScaleFactor = 1.0f;
foreach (const FBXNode& child, node.children) { foreach (const FBXNode& child, node.children) {
if (child.name == "FBXHeaderExtension") { if (child.name == "FBXHeaderExtension") {
foreach (const FBXNode& object, child.children) { foreach (const FBXNode& object, child.children) {
@ -1094,6 +1096,17 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
} }
} }
} }
} else if (child.name == "GlobalSettings") {
foreach (const FBXNode& object, child.children) {
if (object.name == "Properties70") {
foreach (const FBXNode& subobject, object.children) {
if (subobject.name == "P" && subobject.properties.size() >= 5 &&
subobject.properties.at(0) == "UnitScaleFactor") {
unitScaleFactor = subobject.properties.at(4).toFloat();
}
}
}
}
} else if (child.name == "Objects") { } else if (child.name == "Objects") {
foreach (const FBXNode& object, child.children) { foreach (const FBXNode& object, child.children) {
if (object.name == "Geometry") { if (object.name == "Geometry") {
@ -1323,6 +1336,12 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
material.id = getID(object.properties); material.id = getID(object.properties);
materials.insert(material.id, material); materials.insert(material.id, material);
} else if (object.name == "NodeAttribute") {
foreach (const FBXNode& subobject, object.children) {
if (subobject.name == "TypeFlags") {
typeFlags.insert(getID(object.properties), subobject.properties.at(0).toString());
}
}
} else if (object.name == "Deformer") { } else if (object.name == "Deformer") {
if (object.properties.last() == "Cluster") { if (object.properties.last() == "Cluster") {
Cluster cluster; Cluster cluster;
@ -1405,7 +1424,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
} }
// get offset transform from mapping // get offset transform from mapping
float offsetScale = mapping.value("scale", 1.0f).toFloat(); float offsetScale = mapping.value("scale", 1.0f).toFloat() * unitScaleFactor;
glm::quat offsetRotation = glm::quat(glm::radians(glm::vec3(mapping.value("rx").toFloat(), glm::quat offsetRotation = glm::quat(glm::radians(glm::vec3(mapping.value("rx").toFloat(),
mapping.value("ry").toFloat(), mapping.value("rz").toFloat()))); mapping.value("ry").toFloat(), mapping.value("rz").toFloat())));
geometry.offset = glm::translate(glm::vec3(mapping.value("tx").toFloat(), mapping.value("ty").toFloat(), geometry.offset = glm::translate(glm::vec3(mapping.value("tx").toFloat(), mapping.value("ty").toFloat(),
@ -1461,12 +1480,13 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
// convert the models to joints // convert the models to joints
QVariantList freeJoints = mapping.values("freeJoint"); QVariantList freeJoints = mapping.values("freeJoint");
geometry.hasSkeletonJoints = false;
foreach (const QString& modelID, modelIDs) { foreach (const QString& modelID, modelIDs) {
const FBXModel& model = models[modelID]; const FBXModel& model = models[modelID];
FBXJoint joint; FBXJoint joint;
joint.isFree = freeJoints.contains(model.name); joint.isFree = freeJoints.contains(model.name);
joint.parentIndex = model.parentIndex; joint.parentIndex = model.parentIndex;
// get the indices of all ancestors starting with the first free one (if any) // get the indices of all ancestors starting with the first free one (if any)
int jointIndex = geometry.joints.size(); int jointIndex = geometry.joints.size();
joint.freeLineage.append(jointIndex); joint.freeLineage.append(jointIndex);
@ -1506,6 +1526,15 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
joint.name = model.name; joint.name = model.name;
joint.shapePosition = glm::vec3(0.f); joint.shapePosition = glm::vec3(0.f);
joint.shapeType = UNKNOWN_SHAPE; joint.shapeType = UNKNOWN_SHAPE;
foreach (const QString& childID, childMap.values(modelID)) {
QString type = typeFlags.value(childID);
if (!type.isEmpty()) {
geometry.hasSkeletonJoints |= (joint.isSkeletonJoint = type.toLower().contains("Skeleton"));
break;
}
}
geometry.joints.append(joint); geometry.joints.append(joint);
geometry.jointIndices.insert(model.name, geometry.joints.size()); geometry.jointIndices.insert(model.name, geometry.joints.size());

View file

@ -80,6 +80,7 @@ public:
glm::vec3 shapePosition; // in joint frame glm::vec3 shapePosition; // in joint frame
glm::quat shapeRotation; // in joint frame glm::quat shapeRotation; // in joint frame
Shape::Type shapeType; Shape::Type shapeType;
bool isSkeletonJoint;
}; };
@ -182,6 +183,7 @@ public:
QVector<FBXJoint> joints; QVector<FBXJoint> joints;
QHash<QString, int> jointIndices; ///< 1-based, so as to more easily detect missing indices QHash<QString, int> jointIndices; ///< 1-based, so as to more easily detect missing indices
bool hasSkeletonJoints;
QVector<FBXMesh> meshes; QVector<FBXMesh> meshes;