mirror of
https://github.com/lubosz/overte.git
synced 2025-08-06 01:50:56 +02:00
Merge pull request #14966 from raveenajain/gltf_model_parts
Case: 21139 gltf model parts
This commit is contained in:
commit
d96038fd70
1 changed files with 24 additions and 23 deletions
|
@ -739,8 +739,10 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) {
|
||||||
//Build dependencies
|
//Build dependencies
|
||||||
QVector<QVector<int>> nodeDependencies(_file.nodes.size());
|
QVector<QVector<int>> nodeDependencies(_file.nodes.size());
|
||||||
int nodecount = 0;
|
int nodecount = 0;
|
||||||
|
bool hasChildren = false;
|
||||||
foreach(auto &node, _file.nodes) {
|
foreach(auto &node, _file.nodes) {
|
||||||
//nodes_transforms.push_back(getModelTransform(node));
|
//nodes_transforms.push_back(getModelTransform(node));
|
||||||
|
hasChildren |= !node.children.isEmpty();
|
||||||
foreach(int child, node.children) nodeDependencies[child].push_back(nodecount);
|
foreach(int child, node.children) nodeDependencies[child].push_back(nodecount);
|
||||||
nodecount++;
|
nodecount++;
|
||||||
}
|
}
|
||||||
|
@ -763,17 +765,25 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) {
|
||||||
nodecount++;
|
nodecount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Build default joints
|
HFMJoint joint;
|
||||||
hfmModel.joints.resize(1);
|
joint.isSkeletonJoint = true;
|
||||||
hfmModel.joints[0].parentIndex = -1;
|
joint.bindTransformFoundInCluster = false;
|
||||||
hfmModel.joints[0].distanceToParent = 0;
|
joint.distanceToParent = 0;
|
||||||
hfmModel.joints[0].translation = glm::vec3(0, 0, 0);
|
joint.parentIndex = -1;
|
||||||
hfmModel.joints[0].rotationMin = glm::vec3(0, 0, 0);
|
hfmModel.joints.resize(_file.nodes.size());
|
||||||
hfmModel.joints[0].rotationMax = glm::vec3(0, 0, 0);
|
hfmModel.jointIndices["x"] = _file.nodes.size();
|
||||||
hfmModel.joints[0].name = "OBJ";
|
int jointInd = 0;
|
||||||
hfmModel.joints[0].isSkeletonJoint = true;
|
for (auto& node : _file.nodes) {
|
||||||
|
int size = node.transforms.size();
|
||||||
hfmModel.jointIndices["x"] = 1;
|
if (hasChildren) { size--; }
|
||||||
|
joint.preTransform = glm::mat4(1);
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
joint.preTransform = node.transforms[i] * joint.preTransform;
|
||||||
|
}
|
||||||
|
joint.name = node.name;
|
||||||
|
hfmModel.joints[jointInd] = joint;
|
||||||
|
jointInd++;
|
||||||
|
}
|
||||||
|
|
||||||
//Build materials
|
//Build materials
|
||||||
QVector<QString> materialIDs;
|
QVector<QString> materialIDs;
|
||||||
|
@ -804,7 +814,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) {
|
||||||
hfmModel.meshes.append(HFMMesh());
|
hfmModel.meshes.append(HFMMesh());
|
||||||
HFMMesh& mesh = hfmModel.meshes[hfmModel.meshes.size() - 1];
|
HFMMesh& mesh = hfmModel.meshes[hfmModel.meshes.size() - 1];
|
||||||
HFMCluster cluster;
|
HFMCluster cluster;
|
||||||
cluster.jointIndex = 0;
|
cluster.jointIndex = nodecount;
|
||||||
cluster.inverseBindMatrix = glm::mat4(1, 0, 0, 0,
|
cluster.inverseBindMatrix = glm::mat4(1, 0, 0, 0,
|
||||||
0, 1, 0, 0,
|
0, 1, 0, 0,
|
||||||
0, 0, 1, 0,
|
0, 0, 1, 0,
|
||||||
|
@ -907,7 +917,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) {
|
||||||
int stride = (accessor.type == GLTFAccessorType::VEC4) ? 4 : 3;
|
int stride = (accessor.type == GLTFAccessorType::VEC4) ? 4 : 3;
|
||||||
for (int n = 0; n < tangents.size() - 3; n += stride) {
|
for (int n = 0; n < tangents.size() - 3; n += stride) {
|
||||||
float tanW = stride == 4 ? tangents[n + 3] : 1;
|
float tanW = stride == 4 ? tangents[n + 3] : 1;
|
||||||
mesh.tangents.push_back(glm::vec3(tanW * tangents[n], tangents[n + 1], tangents[n + 2]));
|
mesh.tangents.push_back(glm::vec3(tanW * tangents[n], tangents[n + 1], tanW * tangents[n + 2]));
|
||||||
}
|
}
|
||||||
} else if (key == "TEXCOORD_0") {
|
} else if (key == "TEXCOORD_0") {
|
||||||
QVector<float> texcoords;
|
QVector<float> texcoords;
|
||||||
|
@ -957,16 +967,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) {
|
||||||
mesh.meshExtents.addPoint(vertex);
|
mesh.meshExtents.addPoint(vertex);
|
||||||
hfmModel.meshExtents.addPoint(vertex);
|
hfmModel.meshExtents.addPoint(vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// since mesh.modelTransform seems to not have any effect I apply the transformation the model
|
|
||||||
for (int h = 0; h < mesh.vertices.size(); h++) {
|
|
||||||
glm::vec4 ver = glm::vec4(mesh.vertices[h], 1);
|
|
||||||
if (node.transforms.size() > 0) {
|
|
||||||
ver = node.transforms[0] * ver; // for model dependency should multiply also by parents transforms?
|
|
||||||
mesh.vertices[h] = glm::vec3(ver[0], ver[1], ver[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mesh.meshIndex = hfmModel.meshes.size();
|
mesh.meshIndex = hfmModel.meshes.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue