Merge pull request #3718 from MalcolmTyrrell/MalcolmTyrrell/tangentCheck
Malcolm tyrrell/tangent checkpull/3739/head
commit
eb261c6581
|
@ -527,8 +527,8 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
|
||||||
std::fill(aim->mAnimMeshes, aim->mAnimMeshes + aim->mNumAnimMeshes, nullptr);
|
std::fill(aim->mAnimMeshes, aim->mAnimMeshes + aim->mNumAnimMeshes, nullptr);
|
||||||
for (size_t i = 0; i < targets.size(); i++) {
|
for (size_t i = 0; i < targets.size(); i++) {
|
||||||
bool needPositions = targets[i].position.size() > 0;
|
bool needPositions = targets[i].position.size() > 0;
|
||||||
bool needNormals = targets[i].normal.size() > 0;
|
bool needNormals = (targets[i].normal.size() > 0) && aim->HasNormals();
|
||||||
bool needTangents = targets[i].tangent.size() > 0;
|
bool needTangents = (targets[i].tangent.size() > 0) && aim->HasTangentsAndBitangents();
|
||||||
// GLTF morph does not support colors and texCoords
|
// GLTF morph does not support colors and texCoords
|
||||||
aim->mAnimMeshes[i] = aiCreateAnimMesh(aim,
|
aim->mAnimMeshes[i] = aiCreateAnimMesh(aim,
|
||||||
needPositions, needNormals, needTangents, false, false);
|
needPositions, needNormals, needTangents, false, false);
|
||||||
|
@ -536,35 +536,47 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
|
||||||
Mesh::Primitive::Target &target = targets[i];
|
Mesh::Primitive::Target &target = targets[i];
|
||||||
|
|
||||||
if (needPositions) {
|
if (needPositions) {
|
||||||
aiVector3D *positionDiff = nullptr;
|
if (target.position[0]->count != aim->mNumVertices) {
|
||||||
target.position[0]->ExtractData(positionDiff);
|
ASSIMP_LOG_WARN_F("Positions of target ", i, " in mesh \"", mesh.name, "\" does not match the vertex count");
|
||||||
for (unsigned int vertexId = 0; vertexId < aim->mNumVertices; vertexId++) {
|
} else {
|
||||||
aiAnimMesh.mVertices[vertexId] += positionDiff[vertexId];
|
aiVector3D *positionDiff = nullptr;
|
||||||
|
target.position[0]->ExtractData(positionDiff);
|
||||||
|
for (unsigned int vertexId = 0; vertexId < aim->mNumVertices; vertexId++) {
|
||||||
|
aiAnimMesh.mVertices[vertexId] += positionDiff[vertexId];
|
||||||
|
}
|
||||||
|
delete[] positionDiff;
|
||||||
}
|
}
|
||||||
delete[] positionDiff;
|
|
||||||
}
|
}
|
||||||
if (needNormals) {
|
if (needNormals) {
|
||||||
aiVector3D *normalDiff = nullptr;
|
if (target.normal[0]->count != aim->mNumVertices) {
|
||||||
target.normal[0]->ExtractData(normalDiff);
|
ASSIMP_LOG_WARN_F("Normals of target ", i, " in mesh \"", mesh.name, "\" does not match the vertex count");
|
||||||
for (unsigned int vertexId = 0; vertexId < aim->mNumVertices; vertexId++) {
|
} else {
|
||||||
aiAnimMesh.mNormals[vertexId] += normalDiff[vertexId];
|
aiVector3D *normalDiff = nullptr;
|
||||||
|
target.normal[0]->ExtractData(normalDiff);
|
||||||
|
for (unsigned int vertexId = 0; vertexId < aim->mNumVertices; vertexId++) {
|
||||||
|
aiAnimMesh.mNormals[vertexId] += normalDiff[vertexId];
|
||||||
|
}
|
||||||
|
delete[] normalDiff;
|
||||||
}
|
}
|
||||||
delete[] normalDiff;
|
|
||||||
}
|
}
|
||||||
if (needTangents) {
|
if (needTangents) {
|
||||||
Tangent *tangent = nullptr;
|
if (target.tangent[0]->count != aim->mNumVertices) {
|
||||||
attr.tangent[0]->ExtractData(tangent);
|
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);
|
||||||
|
|
||||||
aiVector3D *tangentDiff = nullptr;
|
aiVector3D *tangentDiff = nullptr;
|
||||||
target.tangent[0]->ExtractData(tangentDiff);
|
target.tangent[0]->ExtractData(tangentDiff);
|
||||||
|
|
||||||
for (unsigned int vertexId = 0; vertexId < aim->mNumVertices; ++vertexId) {
|
for (unsigned int vertexId = 0; vertexId < aim->mNumVertices; ++vertexId) {
|
||||||
tangent[vertexId].xyz += tangentDiff[vertexId];
|
tangent[vertexId].xyz += tangentDiff[vertexId];
|
||||||
aiAnimMesh.mTangents[vertexId] = tangent[vertexId].xyz;
|
aiAnimMesh.mTangents[vertexId] = tangent[vertexId].xyz;
|
||||||
aiAnimMesh.mBitangents[vertexId] = (aiAnimMesh.mNormals[vertexId] ^ tangent[vertexId].xyz) * tangent[vertexId].w;
|
aiAnimMesh.mBitangents[vertexId] = (aiAnimMesh.mNormals[vertexId] ^ tangent[vertexId].xyz) * tangent[vertexId].w;
|
||||||
|
}
|
||||||
|
delete[] tangent;
|
||||||
|
delete[] tangentDiff;
|
||||||
}
|
}
|
||||||
delete[] tangent;
|
|
||||||
delete[] tangentDiff;
|
|
||||||
}
|
}
|
||||||
if (mesh.weights.size() > i) {
|
if (mesh.weights.size() > i) {
|
||||||
aiAnimMesh.mWeight = mesh.weights[i];
|
aiAnimMesh.mWeight = mesh.weights[i];
|
||||||
|
|
Loading…
Reference in New Issue