NodeHelpers.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <string>
  3. #include <sstream>
  4. #include <fbxsdk.h>
  5. #include <DirectXMath.h>
  6. inline std::wstring getNodeId(FbxNode* node) {
  7. auto nId = node->GetUniqueID();
  8. std::wstringstream strstream;
  9. strstream << nId;
  10. auto name = node->GetName();
  11. if (name) {
  12. strstream << L"_" << name;
  13. }
  14. return strstream.str();
  15. }
  16. const double Euler2Rad = 3.141592653589793238462 / 180;
  17. inline FbxMatrix GetGeometryTransformation(FbxNode* inNode)
  18. {
  19. if (!inNode)
  20. {
  21. throw std::exception("Null for mesh geometry");
  22. }
  23. const FbxVector4 lT = inNode->GetGeometricTranslation(FbxNode::eSourcePivot);
  24. const FbxVector4 lR = inNode->GetGeometricRotation(FbxNode::eSourcePivot);
  25. const FbxVector4 lS = inNode->GetGeometricScaling(FbxNode::eSourcePivot);
  26. return FbxMatrix(lT, lR, lS);
  27. }
  28. inline FbxMatrix ConvertToBabylonCoordinateSystem(const FbxMatrix& origin){
  29. FbxVector4 trans;
  30. FbxQuaternion rot;
  31. FbxVector4 shearing;
  32. FbxVector4 scaling;
  33. double sign;
  34. origin.GetElements(trans, rot, shearing, scaling, sign);
  35. trans[2] = -trans[2]; // This negate Z of Translation Component of the matrix
  36. rot[0] = -rot[0];
  37. rot[1] = -rot[1];
  38. return FbxMatrix (trans, rot, scaling);
  39. }