浏览代码

test cases

apply transform to root before importing scene
marauder2k7 9 月之前
父节点
当前提交
dcedcdd6f8
共有 2 个文件被更改,包括 48 次插入9 次删除
  1. 7 5
      Engine/source/ts/assimp/assimpAppNode.cpp
  2. 41 4
      Engine/source/ts/assimp/assimpShapeLoader.cpp

+ 7 - 5
Engine/source/ts/assimp/assimpAppNode.cpp

@@ -71,8 +71,8 @@ MatrixF AssimpAppNode::getTransform(F32 time)
       // no parent (ie. root level) => scale by global shape <unit>
       mLastTransform.identity();
       mLastTransform.scale(ColladaUtils::getOptions().unit * ColladaUtils::getOptions().formatScaleFactor);
-      if (!isBounds())
-         convertMat(mLastTransform);
+      /*if (!isBounds())
+         convertMat(mLastTransform);*/
    }
 
    // If this node is animated in the active sequence, fetch the animated transform
@@ -272,9 +272,11 @@ void AssimpAppNode::convertMat(MatrixF& outMat)
 
    case UPAXISTYPE_Y_UP:
       // rotate 180 around Y-axis, then 90 around X-axis
-      rot(0, 0) = -1.0f;
-      rot(1, 1) = 0.0f;	rot(2, 1) = 1.0f;
-      rot(1, 2) = 1.0f;	rot(2, 2) = 0.0f;
+      rot(0, 0) = 1.0f;
+      rot(1, 1) = 0.0f;
+      rot(1, 2) = -1.0f;
+      rot(2, 1) = 1.0f;
+      rot(2, 2) = 0.0f;
 
       // pre-multiply the transform by the rotation matrix
       outMat.mulL(rot);

+ 41 - 4
Engine/source/ts/assimp/assimpShapeLoader.cpp

@@ -182,10 +182,9 @@ void AssimpShapeLoader::enumerateScene()
    Con::printf("[ASSIMP] Attempting to load file: %s", shapePath.getFullPath().c_str());
 
    // Define post-processing steps
-   U32 ppsteps = aiProcess_Triangulate | aiProcess_ConvertToLeftHanded & ~aiProcess_FlipWindingOrder;
+   U32 ppsteps = aiProcess_Triangulate | /*aiProcess_PreTransformVertices |*/ aiProcess_ConvertToLeftHanded & ~aiProcess_MakeLeftHanded;
 
    const auto& options = ColladaUtils::getOptions();
-   if (options.reverseWindingOrder) ppsteps |= aiProcess_FlipWindingOrder;
    if (options.calcTangentSpace) ppsteps |= aiProcess_CalcTangentSpace;
    if (options.joinIdenticalVerts) ppsteps |= aiProcess_JoinIdenticalVertices;
    if (options.removeRedundantMats) ppsteps |= aiProcess_RemoveRedundantMaterials;
@@ -210,7 +209,14 @@ void AssimpShapeLoader::enumerateScene()
 #ifdef TORQUE_DEBUG
    aiEnableVerboseLogging(true);
 #endif
-   
+
+   /*mImporter.SetPropertyInteger(AI_CONFIG_PP_PTV_KEEP_HIERARCHY, 1);
+   mImporter.SetPropertyInteger(AI_CONFIG_PP_PTV_ADD_ROOT_TRANSFORMATION, 1);
+   mImporter.SetPropertyMatrix(AI_CONFIG_PP_PTV_ROOT_TRANSFORMATION, aiMatrix4x4(1, 0, 0, 0,
+                                                                                 0, 0, -1, 0,
+                                                                                 0, 1, 0, 0,
+                                                                                 0, 0, 0, 1));*/
+
    // Read the file
    mScene = mImporter.ReadFile(shapePath.getFullPath().c_str(), ppsteps);
 
@@ -248,6 +254,9 @@ void AssimpShapeLoader::enumerateScene()
       }
    }
 
+   if (fileExt == String::ToString("glb"))
+      ColladaUtils::getOptions().upAxis = UPAXISTYPE_X_UP;
+
    for (U32 i = 0; i < mScene->mNumTextures; ++i) {
       extractTexture(i, mScene->mTextures[i]);
    }
@@ -261,6 +270,29 @@ void AssimpShapeLoader::enumerateScene()
    // Setup LOD checks
    detectDetails();
 
+
+   aiMatrix4x4 sceneRoot;
+
+   if (ColladaUtils::getOptions().upAxis == UPAXISTYPE_X_UP) {
+      sceneRoot = aiMatrix4x4(1, 0, 0, 0,
+                              0, 0, 1, 0,
+                              0, 1, 0, 0,
+                              0, 0, 0, 1);
+   }
+
+   if (ColladaUtils::getOptions().upAxis == UPAXISTYPE_Z_UP) {
+      sceneRoot = aiMatrix4x4(1, 0, 0, 0,
+                              0, 0, -1, 0,
+                              0, 1, 0, 0,
+                              0, 0, 0, 1);
+   }
+
+   if (ColladaUtils::getOptions().upAxis == UPAXISTYPE_Y_UP) {
+      sceneRoot = aiMatrix4x4::RotationX(AI_MATH_PI / 2, sceneRoot);
+   }
+
+   applyTransformation(mScene->mRootNode, sceneRoot);
+
    // Process the scene graph
    AssimpAppNode* rootNode = new AssimpAppNode(mScene, mScene->mRootNode, 0);
    if (!processNode(rootNode)) {
@@ -273,7 +305,7 @@ void AssimpShapeLoader::enumerateScene()
    if (!boundsNode) {
       aiNode* reqNode = new aiNode("bounds");
       mScene->mRootNode->addChildren(1, &reqNode);
-      reqNode->mTransformation = mScene->mRootNode->mTransformation;
+      //reqNode->mTransformation = mScene->mRootNode->mTransformation;
       AssimpAppNode* appBoundsNode = new AssimpAppNode(mScene, reqNode);
       if (!processNode(appBoundsNode)) {
          delete appBoundsNode;
@@ -305,6 +337,11 @@ void AssimpShapeLoader::configureImportUnits() {
       }
       options.unit = static_cast<F32>(unitScaleFactor);
    }
+
+   int upAxis = UPAXISTYPE_Z_UP;
+   if (getMetaInt("UpAxis", upAxis)) {
+      options.upAxis = static_cast<domUpAxisType>(upAxis);
+   }
 }
 
 void AssimpShapeLoader::processAssimpNode(const aiNode* node, const aiScene* scene, AssimpAppNode* parentNode)