Merge pull request #16402 from sabrina-shanman/instancing_gltf

(DEV-561) GLTF fixes
This commit is contained in:
Sabrina Shanman 2019-10-24 15:53:56 -07:00 committed by GitHub
commit b49c1b615d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 9 deletions

View file

@ -28,7 +28,7 @@ AnimSkeleton::AnimSkeleton(const HFMModel& hfmModel) {
const auto& defor = hfmModel.skinDeformers[i];
std::vector<HFMCluster> dummyClustersList;
for (int j = 0; j < (uint32_t) defor.clusters.size(); j++) {
for (uint32_t j = 0; j < (uint32_t)defor.clusters.size(); j++) {
// cast into a non-const reference, so we can mutate the FBXCluster
HFMCluster& cluster = const_cast<HFMCluster&>(defor.clusters.at(j));

View file

@ -1315,8 +1315,6 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
float tanW = tangentStride == 4 ? tangents[n + 3] : 1;
mesh.tangents.push_back(glm::vec3(tanW * tangents[n], tangents[n + 1], tanW * tangents[n + 2]));
}
} else if (primitiveAttributes.contains("TANGENT")) {
mesh.tangents.resize(mesh.tangents.size() + partVerticesCount);
}
if (texcoords.size() == partVerticesCount * TEX_COORD_STRIDE) {
@ -1391,9 +1389,10 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
mesh.clusterWeights.reserve(newWeightsEnd);
for (int weightIndex = 0; weightIndex < clusterWeights.size(); ++weightIndex) {
// Per the GLTF specification
uint16_t weight = std::round(clusterWeights[weightIndex] * 65535.0);
uint16_t weight = std::round(clusterWeights[weightIndex] * 65535.0f);
mesh.clusterWeights.push_back(weight);
}
mesh.clusterWeightsPerVertex = WEIGHTS_PER_VERTEX;
}
if (joints.size() == partVerticesCount * jointStride) {
@ -1542,6 +1541,25 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash&
}
}
// TODO: Fix skinning and remove this workaround which disables skinning
// TODO: Restore after testing
{
std::vector<int> meshToRootJoint;
meshToRootJoint.resize(hfmModel.meshes.size(), -1);
std::vector<uint16_t> meshToClusterSize;
meshToClusterSize.resize(hfmModel.meshes.size());
for (auto& shape : hfmModel.shapes) {
shape.skinDeformer = hfm::UNDEFINED_KEY;
}
for (auto& mesh : hfmModel.meshes) {
mesh.clusterWeights.clear();
mesh.clusterIndices.clear();
mesh.clusterWeightsPerVertex = 0;
}
}
return true;
}
@ -1855,7 +1873,6 @@ bool GLTFSerializer::addArrayFromAttribute(GLTFVertexAttribute::Value vertexAttr
qWarning(modelformat) << "Invalid accessor type on glTF TANGENT data for model " << _url;
return false;
}
break;
if (!addArrayFromAccessor(accessor, outarray)) {
qWarning(modelformat) << "There was a problem reading glTF TANGENT data for model " << _url;

View file

@ -1008,8 +1008,8 @@ HFMModel::Pointer OBJSerializer::read(const hifi::ByteArray& data, const hifi::V
modelMaterial->setOpacity(hfmMaterial.opacity);
}
// GO over the shapes once more to assign hte material index correctly
for (int i = 0; i < (uint32_t) hfmModel.shapes.size(); ++i) {
// GO over the shapes once more to assign the material index correctly
for (uint32_t i = 0; i < (uint32_t)hfmModel.shapes.size(); ++i) {
auto foundMaterialIndex = materialNameToIndex.find(materialNamePerShape[i]);
if (foundMaterialIndex != materialNameToIndex.end()) {
hfmModel.shapes[i].material = foundMaterialIndex.value();

View file

@ -63,9 +63,8 @@ void CauterizedModel::createRenderItemSet() {
Transform::mult(transform, transform, offset);
// Run through all of the meshes, and place them into their segregated, but unsorted buckets
int shapeID = 0;
const auto& shapes = _renderGeometry->getHFMModel().shapes;
for (shapeID; shapeID < (int) shapes.size(); shapeID++) {
for (int shapeID = 0; shapeID < (int) shapes.size(); shapeID++) {
const auto& shape = shapes[shapeID];
_modelMeshRenderItems << std::make_shared<CauterizedMeshPartPayload>(shared_from_this(), shape.mesh, shape.meshPart, shapeID, transform);