|
@@ -362,7 +362,31 @@ void glTF2Importer::ImportMeshes(glTF2::Asset& r)
|
|
attr.position[0]->ExtractData(aim->mVertices);
|
|
attr.position[0]->ExtractData(aim->mVertices);
|
|
}
|
|
}
|
|
|
|
|
|
- if (attr.normal.size() > 0 && attr.normal[0]) attr.normal[0]->ExtractData(aim->mNormals);
|
|
|
|
|
|
+ if (attr.normal.size() > 0 && attr.normal[0]) {
|
|
|
|
+ attr.normal[0]->ExtractData(aim->mNormals);
|
|
|
|
+
|
|
|
|
+ // only extract tangents if normals are present
|
|
|
|
+ if (attr.tangent.size() > 0 && attr.tangent[0]) {
|
|
|
|
+ // generate bitangents from normals and tangents according to spec
|
|
|
|
+ struct Tangent
|
|
|
|
+ {
|
|
|
|
+ aiVector3D xyz;
|
|
|
|
+ ai_real w;
|
|
|
|
+ } *tangents = nullptr;
|
|
|
|
+
|
|
|
|
+ attr.tangent[0]->ExtractData(tangents);
|
|
|
|
+
|
|
|
|
+ aim->mTangents = new aiVector3D[aim->mNumVertices];
|
|
|
|
+ aim->mBitangents = new aiVector3D[aim->mNumVertices];
|
|
|
|
+
|
|
|
|
+ for (unsigned int i = 0; i < aim->mNumVertices; ++i) {
|
|
|
|
+ aim->mTangents[i] = tangents[i].xyz;
|
|
|
|
+ aim->mBitangents[i] = (aim->mNormals[i] ^ tangents[i].xyz) * tangents[i].w;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ delete tangents;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
for (size_t tc = 0; tc < attr.texcoord.size() && tc < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++tc) {
|
|
for (size_t tc = 0; tc < attr.texcoord.size() && tc < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++tc) {
|
|
attr.texcoord[tc]->ExtractData(aim->mTextureCoords[tc]);
|
|
attr.texcoord[tc]->ExtractData(aim->mTextureCoords[tc]);
|
|
@@ -492,7 +516,7 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector<unsigned int>&
|
|
{
|
|
{
|
|
Node& node = *ptr;
|
|
Node& node = *ptr;
|
|
|
|
|
|
- aiNode* ainode = new aiNode(node.id);
|
|
|
|
|
|
+ aiNode* ainode = new aiNode(node.name);
|
|
|
|
|
|
if (!node.children.empty()) {
|
|
if (!node.children.empty()) {
|
|
ainode->mNumChildren = unsigned(node.children.size());
|
|
ainode->mNumChildren = unsigned(node.children.size());
|
|
@@ -515,7 +539,13 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector<unsigned int>&
|
|
CopyValue(node.translation.value, trans);
|
|
CopyValue(node.translation.value, trans);
|
|
aiMatrix4x4 t;
|
|
aiMatrix4x4 t;
|
|
aiMatrix4x4::Translation(trans, t);
|
|
aiMatrix4x4::Translation(trans, t);
|
|
- matrix = t * matrix;
|
|
|
|
|
|
+ matrix = matrix * t;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (node.rotation.isPresent) {
|
|
|
|
+ aiQuaternion rot;
|
|
|
|
+ CopyValue(node.rotation.value, rot);
|
|
|
|
+ matrix = matrix * aiMatrix4x4(rot.GetMatrix());
|
|
}
|
|
}
|
|
|
|
|
|
if (node.scale.isPresent) {
|
|
if (node.scale.isPresent) {
|
|
@@ -523,14 +553,7 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector<unsigned int>&
|
|
CopyValue(node.scale.value, scal);
|
|
CopyValue(node.scale.value, scal);
|
|
aiMatrix4x4 s;
|
|
aiMatrix4x4 s;
|
|
aiMatrix4x4::Scaling(scal, s);
|
|
aiMatrix4x4::Scaling(scal, s);
|
|
- matrix = s * matrix;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if (node.rotation.isPresent) {
|
|
|
|
- aiQuaternion rot;
|
|
|
|
- CopyValue(node.rotation.value, rot);
|
|
|
|
- matrix = aiMatrix4x4(rot.GetMatrix()) * matrix;
|
|
|
|
|
|
+ matrix = matrix * s;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|