mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 00:17:35 +02:00
GLTF WIP
This commit is contained in:
parent
30680e027b
commit
da4ffcd91b
1 changed files with 7 additions and 22 deletions
|
@ -1005,8 +1005,6 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
|
||||||
// Build joints
|
// Build joints
|
||||||
HFMJoint joint;
|
HFMJoint joint;
|
||||||
hfmModel.jointIndices["x"] = numNodes;
|
hfmModel.jointIndices["x"] = numNodes;
|
||||||
QVector<glm::mat4> globalTransforms;
|
|
||||||
globalTransforms.resize(numNodes);
|
|
||||||
|
|
||||||
for (int nodeIndex = 0; nodeIndex < numNodes; ++nodeIndex) {
|
for (int nodeIndex = 0; nodeIndex < numNodes; ++nodeIndex) {
|
||||||
auto& node = _file.nodes[nodeIndex];
|
auto& node = _file.nodes[nodeIndex];
|
||||||
|
@ -1022,10 +1020,12 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
|
||||||
joint.rotation = glmExtractRotation(joint.transform);
|
joint.rotation = glmExtractRotation(joint.transform);
|
||||||
glm::vec3 scale = extractScale(joint.transform);
|
glm::vec3 scale = extractScale(joint.transform);
|
||||||
joint.postTransform = glm::scale(glm::mat4(), scale);
|
joint.postTransform = glm::scale(glm::mat4(), scale);
|
||||||
globalTransforms[nodeIndex] = joint.transform;
|
|
||||||
|
|
||||||
if (joint.parentIndex != -1) {
|
joint.globalTransform = joint.transform;
|
||||||
globalTransforms[nodeIndex] = globalTransforms[joint.parentIndex] * globalTransforms[nodeIndex];
|
// Nodes are sorted, so we can apply the full transform just by getting the global transform of the already defined parent
|
||||||
|
if (joint.parentIndex != -1 && joint.parentIndex != nodeIndex) {
|
||||||
|
const auto& parentJoint = hfmModel.joints[(size_t)nodeIndex];
|
||||||
|
joint.globalTransform = parentJoint.globalTransform * joint.globalTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
joint.name = node.name;
|
joint.name = node.name;
|
||||||
|
@ -1368,7 +1368,6 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
|
||||||
mesh.normals.push_back(glm::vec3(normals[n], normals[n + 1], normals[n + 2]));
|
mesh.normals.push_back(glm::vec3(normals[n], normals[n + 1], normals[n + 2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add correct tangent generation
|
|
||||||
if (tangents.size() == partVerticesCount * tangentStride) {
|
if (tangents.size() == partVerticesCount * tangentStride) {
|
||||||
mesh.tangents.reserve(partVerticesCount);
|
mesh.tangents.reserve(partVerticesCount);
|
||||||
for (int n = 0; n < tangents.size(); n += tangentStride) {
|
for (int n = 0; n < tangents.size(); n += tangentStride) {
|
||||||
|
@ -1582,22 +1581,8 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
for(const glm::vec3& vertex : mesh.vertices) {
|
|
||||||
glm::vec3 transformedVertex = glm::vec3(globalTransforms[nodeIndex] * glm::vec4(vertex, 1.0f));
|
|
||||||
mesh.meshExtents.addPoint(transformedVertex);
|
|
||||||
hfmModel.meshExtents.addPoint(transformedVertex);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add epsilon to mesh extents to compensate for planar meshes
|
|
||||||
mesh.meshExtents.minimum -= glm::vec3(EPSILON, EPSILON, EPSILON);
|
|
||||||
mesh.meshExtents.maximum += glm::vec3(EPSILON, EPSILON, EPSILON);
|
|
||||||
hfmModel.meshExtents.minimum -= glm::vec3(EPSILON, EPSILON, EPSILON);
|
|
||||||
hfmModel.meshExtents.maximum += glm::vec3(EPSILON, EPSILON, EPSILON);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1611,7 +1596,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
|
||||||
int primCount = (int)mesh.primitives.size();
|
int primCount = (int)mesh.primitives.size();
|
||||||
for (int primIndex = 0; primIndex < primCount; ++primIndex) {
|
for (int primIndex = 0; primIndex < primCount; ++primIndex) {
|
||||||
const auto& primitive = mesh.primitives[primIndex];
|
const auto& primitive = mesh.primitives[primIndex];
|
||||||
hfmModel.shapes.push_back({});
|
hfmModel.shapes.emplace_back();
|
||||||
auto& hfmShape = hfmModel.shapes.back();
|
auto& hfmShape = hfmModel.shapes.back();
|
||||||
hfmShape.transform = nodeIndex;
|
hfmShape.transform = nodeIndex;
|
||||||
hfmShape.mesh = node.mesh;
|
hfmShape.mesh = node.mesh;
|
||||||
|
|
Loading…
Reference in a new issue