Merge pull request #3718 from MalcolmTyrrell/MalcolmTyrrell/tangentCheck

Malcolm tyrrell/tangent check
pull/3739/head
Kim Kulling 2021-04-03 18:28:03 +02:00 committed by GitHub
commit eb261c6581
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 22 deletions

View File

@ -527,8 +527,8 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
std::fill(aim->mAnimMeshes, aim->mAnimMeshes + aim->mNumAnimMeshes, nullptr);
for (size_t i = 0; i < targets.size(); i++) {
bool needPositions = targets[i].position.size() > 0;
bool needNormals = targets[i].normal.size() > 0;
bool needTangents = targets[i].tangent.size() > 0;
bool needNormals = (targets[i].normal.size() > 0) && aim->HasNormals();
bool needTangents = (targets[i].tangent.size() > 0) && aim->HasTangentsAndBitangents();
// GLTF morph does not support colors and texCoords
aim->mAnimMeshes[i] = aiCreateAnimMesh(aim,
needPositions, needNormals, needTangents, false, false);
@ -536,6 +536,9 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
Mesh::Primitive::Target &target = targets[i];
if (needPositions) {
if (target.position[0]->count != aim->mNumVertices) {
ASSIMP_LOG_WARN_F("Positions of target ", i, " in mesh \"", mesh.name, "\" does not match the vertex count");
} else {
aiVector3D *positionDiff = nullptr;
target.position[0]->ExtractData(positionDiff);
for (unsigned int vertexId = 0; vertexId < aim->mNumVertices; vertexId++) {
@ -543,7 +546,11 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
}
delete[] positionDiff;
}
}
if (needNormals) {
if (target.normal[0]->count != aim->mNumVertices) {
ASSIMP_LOG_WARN_F("Normals of target ", i, " in mesh \"", mesh.name, "\" does not match the vertex count");
} else {
aiVector3D *normalDiff = nullptr;
target.normal[0]->ExtractData(normalDiff);
for (unsigned int vertexId = 0; vertexId < aim->mNumVertices; vertexId++) {
@ -551,7 +558,11 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
}
delete[] normalDiff;
}
}
if (needTangents) {
if (target.tangent[0]->count != aim->mNumVertices) {
ASSIMP_LOG_WARN_F("Tangents of target ", i, " in mesh \"", mesh.name, "\" does not match the vertex count");
} else {
Tangent *tangent = nullptr;
attr.tangent[0]->ExtractData(tangent);
@ -566,6 +577,7 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
delete[] tangent;
delete[] tangentDiff;
}
}
if (mesh.weights.size() > i) {
aiAnimMesh.mWeight = mesh.weights[i];
}