mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 05:58:27 +02:00
Fix for models exported from Blender: remove type prefix from IDs.
This commit is contained in:
parent
968544152f
commit
1e5ec3e84f
1 changed files with 41 additions and 34 deletions
|
@ -415,6 +415,16 @@ glm::vec3 parseVec3(const QString& string) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString processID(const QString& id) {
|
||||||
|
// Blender (at least) prepends a type to the ID, so strip it out
|
||||||
|
int index = id.indexOf("::");
|
||||||
|
return (index == -1) ? id : id.mid(index + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString getID(const QVariantList& properties, int index = 0) {
|
||||||
|
return processID(properties.at(index).toString());
|
||||||
|
}
|
||||||
|
|
||||||
const char* FACESHIFT_BLENDSHAPES[] = {
|
const char* FACESHIFT_BLENDSHAPES[] = {
|
||||||
"EyeBlink_L",
|
"EyeBlink_L",
|
||||||
"EyeBlink_R",
|
"EyeBlink_R",
|
||||||
|
@ -469,7 +479,7 @@ const char* FACESHIFT_BLENDSHAPES[] = {
|
||||||
|
|
||||||
class FBXModel {
|
class FBXModel {
|
||||||
public:
|
public:
|
||||||
QByteArray name;
|
QString name;
|
||||||
|
|
||||||
int parentIndex;
|
int parentIndex;
|
||||||
|
|
||||||
|
@ -680,12 +690,12 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
QHash<QString, QString> bumpTextures;
|
QHash<QString, QString> bumpTextures;
|
||||||
|
|
||||||
QVariantHash joints = mapping.value("joint").toHash();
|
QVariantHash joints = mapping.value("joint").toHash();
|
||||||
QByteArray jointEyeLeftName = joints.value("jointEyeLeft", "jointEyeLeft").toByteArray();
|
QString jointEyeLeftName = processID(joints.value("jointEyeLeft", "jointEyeLeft").toString());
|
||||||
QByteArray jointEyeRightName = joints.value("jointEyeRight", "jointEyeRight").toByteArray();
|
QString jointEyeRightName = processID(joints.value("jointEyeRight", "jointEyeRight").toString());
|
||||||
QByteArray jointNeckName = joints.value("jointNeck", "jointNeck").toByteArray();
|
QString jointNeckName = processID(joints.value("jointNeck", "jointNeck").toString());
|
||||||
QByteArray jointRootName = joints.value("jointRoot", "jointRoot").toByteArray();
|
QString jointRootName = processID(joints.value("jointRoot", "jointRoot").toString());
|
||||||
QByteArray jointLeanName = joints.value("jointLean", "jointLean").toByteArray();
|
QString jointLeanName = processID(joints.value("jointLean", "jointLean").toString());
|
||||||
QByteArray jointHeadName = joints.value("jointHead", "jointHead").toByteArray();
|
QString jointHeadName = processID(joints.value("jointHead", "jointHead").toString());
|
||||||
QString jointEyeLeftID;
|
QString jointEyeLeftID;
|
||||||
QString jointEyeRightID;
|
QString jointEyeRightID;
|
||||||
QString jointNeckID;
|
QString jointNeckID;
|
||||||
|
@ -718,10 +728,10 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
foreach (const FBXNode& object, child.children) {
|
foreach (const FBXNode& object, child.children) {
|
||||||
if (object.name == "Geometry") {
|
if (object.name == "Geometry") {
|
||||||
if (object.properties.at(2) == "Mesh") {
|
if (object.properties.at(2) == "Mesh") {
|
||||||
meshes.insert(object.properties.at(0).toString(), extractMesh(object));
|
meshes.insert(getID(object.properties), extractMesh(object));
|
||||||
|
|
||||||
} else { // object.properties.at(2) == "Shape"
|
} else { // object.properties.at(2) == "Shape"
|
||||||
ExtractedBlendshape extracted = { object.properties.at(0).toString() };
|
ExtractedBlendshape extracted = { getID(object.properties) };
|
||||||
|
|
||||||
foreach (const FBXNode& data, object.children) {
|
foreach (const FBXNode& data, object.children) {
|
||||||
if (data.name == "Indexes") {
|
if (data.name == "Indexes") {
|
||||||
|
@ -740,31 +750,31 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
blendshapes.append(extracted);
|
blendshapes.append(extracted);
|
||||||
}
|
}
|
||||||
} else if (object.name == "Model") {
|
} else if (object.name == "Model") {
|
||||||
QByteArray name;
|
QString name;
|
||||||
if (object.properties.size() == 3) {
|
if (object.properties.size() == 3) {
|
||||||
name = object.properties.at(1).toByteArray();
|
name = object.properties.at(1).toString();
|
||||||
name = name.left(name.indexOf('\0'));
|
name = name.left(name.indexOf(QChar('\0')));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
name = object.properties.at(0).toByteArray();
|
name = getID(object.properties);
|
||||||
}
|
}
|
||||||
if (name == jointEyeLeftName || name == "EyeL" || name == "joint_Leye") {
|
if (name == jointEyeLeftName || name == "EyeL" || name == "joint_Leye") {
|
||||||
jointEyeLeftID = object.properties.at(0).toString();
|
jointEyeLeftID = getID(object.properties);
|
||||||
|
|
||||||
} else if (name == jointEyeRightName || name == "EyeR" || name == "joint_Reye") {
|
} else if (name == jointEyeRightName || name == "EyeR" || name == "joint_Reye") {
|
||||||
jointEyeRightID = object.properties.at(0).toString();
|
jointEyeRightID = getID(object.properties);
|
||||||
|
|
||||||
} else if (name == jointNeckName || name == "NeckRot" || name == "joint_neck") {
|
} else if (name == jointNeckName || name == "NeckRot" || name == "joint_neck") {
|
||||||
jointNeckID = object.properties.at(0).toString();
|
jointNeckID = getID(object.properties);
|
||||||
|
|
||||||
} else if (name == jointRootName) {
|
} else if (name == jointRootName) {
|
||||||
jointRootID = object.properties.at(0).toString();
|
jointRootID = getID(object.properties);
|
||||||
|
|
||||||
} else if (name == jointLeanName) {
|
} else if (name == jointLeanName) {
|
||||||
jointLeanID = object.properties.at(0).toString();
|
jointLeanID = getID(object.properties);
|
||||||
|
|
||||||
} else if (name == jointHeadName) {
|
} else if (name == jointHeadName) {
|
||||||
jointHeadID = object.properties.at(0).toString();
|
jointHeadID = getID(object.properties);
|
||||||
}
|
}
|
||||||
glm::vec3 translation;
|
glm::vec3 translation;
|
||||||
glm::vec3 rotationOffset;
|
glm::vec3 rotationOffset;
|
||||||
|
@ -817,7 +827,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
}
|
}
|
||||||
} else if (subobject.name == "Vertices") {
|
} else if (subobject.name == "Vertices") {
|
||||||
// it's a mesh as well as a model
|
// it's a mesh as well as a model
|
||||||
meshes.insert(object.properties.at(0).toString(), extractMesh(object));
|
meshes.insert(getID(object.properties), extractMesh(object));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// see FBX documentation, http://download.autodesk.com/us/fbx/20112/FBX_SDK_HELP/index.html
|
// see FBX documentation, http://download.autodesk.com/us/fbx/20112/FBX_SDK_HELP/index.html
|
||||||
|
@ -828,7 +838,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
model.postRotation = glm::quat(glm::radians(postRotation));
|
model.postRotation = glm::quat(glm::radians(postRotation));
|
||||||
model.postTransform = glm::translate(-rotationPivot) * glm::translate(scalePivot) *
|
model.postTransform = glm::translate(-rotationPivot) * glm::translate(scalePivot) *
|
||||||
glm::scale(scale) * glm::translate(-scalePivot);
|
glm::scale(scale) * glm::translate(-scalePivot);
|
||||||
models.insert(object.properties.at(0).toString(), model);
|
models.insert(getID(object.properties), model);
|
||||||
|
|
||||||
} else if (object.name == "Texture") {
|
} else if (object.name == "Texture") {
|
||||||
foreach (const FBXNode& subobject, object.children) {
|
foreach (const FBXNode& subobject, object.children) {
|
||||||
|
@ -836,7 +846,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
// trim off any path information
|
// trim off any path information
|
||||||
QByteArray filename = subobject.properties.at(0).toByteArray();
|
QByteArray filename = subobject.properties.at(0).toByteArray();
|
||||||
filename = filename.mid(qMax(filename.lastIndexOf('\\'), filename.lastIndexOf('/')) + 1);
|
filename = filename.mid(qMax(filename.lastIndexOf('\\'), filename.lastIndexOf('/')) + 1);
|
||||||
textureFilenames.insert(object.properties.at(0).toString(), filename);
|
textureFilenames.insert(getID(object.properties), filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (object.name == "Material") {
|
} else if (object.name == "Material") {
|
||||||
|
@ -871,7 +881,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
materials.insert(object.properties.at(0).toString(), material);
|
materials.insert(getID(object.properties), material);
|
||||||
|
|
||||||
} else if (object.name == "Deformer") {
|
} else if (object.name == "Deformer") {
|
||||||
if (object.properties.last() == "Cluster") {
|
if (object.properties.last() == "Cluster") {
|
||||||
|
@ -888,7 +898,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
cluster.transformLink = createMat4(values);
|
cluster.transformLink = createMat4(values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clusters.insert(object.properties.at(0).toString(), cluster);
|
clusters.insert(getID(object.properties), cluster);
|
||||||
|
|
||||||
} else if (object.properties.last() == "BlendShapeChannel") {
|
} else if (object.properties.last() == "BlendShapeChannel") {
|
||||||
QByteArray name = object.properties.at(1).toByteArray();
|
QByteArray name = object.properties.at(1).toByteArray();
|
||||||
|
@ -897,8 +907,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
// try everything after the dot
|
// try everything after the dot
|
||||||
name = name.mid(name.lastIndexOf('.') + 1);
|
name = name.mid(name.lastIndexOf('.') + 1);
|
||||||
}
|
}
|
||||||
blendshapeChannelIndices.insert(object.properties.at(0).toString(),
|
blendshapeChannelIndices.insert(getID(object.properties), blendshapeIndices.value(name));
|
||||||
blendshapeIndices.value(name));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -908,16 +917,14 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
if (connection.properties.at(0) == "OP") {
|
if (connection.properties.at(0) == "OP") {
|
||||||
QByteArray type = connection.properties.at(3).toByteArray().toLower();
|
QByteArray type = connection.properties.at(3).toByteArray().toLower();
|
||||||
if (type.contains("diffuse")) {
|
if (type.contains("diffuse")) {
|
||||||
diffuseTextures.insert(connection.properties.at(2).toString(),
|
diffuseTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||||
connection.properties.at(1).toString());
|
|
||||||
|
|
||||||
} else if (type.contains("bump")) {
|
} else if (type.contains("bump")) {
|
||||||
bumpTextures.insert(connection.properties.at(2).toString(),
|
bumpTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||||
connection.properties.at(1).toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parentMap.insert(connection.properties.at(1).toString(), connection.properties.at(2).toString());
|
parentMap.insert(getID(connection.properties, 1), getID(connection.properties, 2));
|
||||||
childMap.insert(connection.properties.at(2).toString(), connection.properties.at(1).toString());
|
childMap.insert(getID(connection.properties, 2), getID(connection.properties, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1159,12 +1166,12 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
|
||||||
QVariantHash attachments = mapping.value("attach").toHash();
|
QVariantHash attachments = mapping.value("attach").toHash();
|
||||||
for (QVariantHash::const_iterator it = attachments.constBegin(); it != attachments.constEnd(); it++) {
|
for (QVariantHash::const_iterator it = attachments.constBegin(); it != attachments.constEnd(); it++) {
|
||||||
FBXAttachment attachment;
|
FBXAttachment attachment;
|
||||||
attachment.jointIndex = modelIDs.indexOf(it.key());
|
attachment.jointIndex = modelIDs.indexOf(processID(it.key()));
|
||||||
attachment.scale = glm::vec3(1.0f, 1.0f, 1.0f);
|
attachment.scale = glm::vec3(1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
QVariantList properties = it->toList();
|
QVariantList properties = it->toList();
|
||||||
if (properties.isEmpty()) {
|
if (properties.isEmpty()) {
|
||||||
attachment.url = it->toUrl();
|
attachment.url = it->toString();
|
||||||
} else {
|
} else {
|
||||||
attachment.url = properties.at(0).toString();
|
attachment.url = properties.at(0).toString();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue