Created
February 29, 2020 12:27
-
-
Save fereria/28c7510da18aa5b0ad634d26c63c9cb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define NOMINMAX | |
#include "classTest.h" | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
void | |
ClassTest::getRecursiveNode(FbxNode* pNode, FbxArray<FbxNode*>& nodeArray) { | |
/* | |
pNode以下のノードを再帰的に取得する | |
*/ | |
nodeArray.Add(pNode); | |
int childNodeNum = pNode->GetChildCount(); | |
for (int i = 0; i < childNodeNum; i++) { | |
FbxNode* pChild = pNode->GetChild(i); | |
getRecursiveNode(pChild, nodeArray); | |
} | |
} | |
vector<string> | |
split(string str, string separator) { | |
/* | |
文字列を separatorで分割する | |
*/ | |
if (separator == "") | |
return {str}; | |
vector<string> result; | |
string tstr = str + separator; | |
long l = tstr.length(), sl = separator.length(); | |
string::size_type pos = 0, prev = 0; | |
for (; pos < l && (pos = tstr.find(separator, pos)) != string::npos; prev = (pos += sl)) { | |
result.emplace_back(tstr, prev, pos - prev); | |
} | |
return result; | |
} | |
void | |
ClassTest::getFullNodePath(FbxNode* cNode, string& DAGPath) { | |
/* | |
cNodeのフルパスを / で取得する | |
Namespaceは削除する | |
*/ | |
FbxNode* pNode = cNode->GetParent(); | |
if (pNode) { | |
getFullNodePath(pNode, DAGPath); | |
string currentNodeName(cNode->GetName()); | |
vector<string> buff = split(currentNodeName, ":"); | |
DAGPath = DAGPath + "/" + buff[buff.size() - 1]; | |
} | |
} | |
ClassTest::ClassTest(char* fbxFile) { | |
//コンストラクタでシーンをロードする | |
this->fbxFile = fbxFile; | |
this->manager = FbxManager::Create(); | |
FbxIOSettings* ioSettings = FbxIOSettings::Create(manager, IOSROOT); | |
FbxImporter* importer = FbxImporter::Create(manager, ""); | |
importer->Initialize(this->fbxFile, -1, manager->GetIOSettings()); | |
// Fbxにシーンをロード | |
this->scene = FbxScene::Create(manager, "scene"); | |
importer->Import(scene); | |
importer->Destroy(); | |
} | |
ClassTest::~ClassTest() { | |
// デストラクタのときにmanagerをDestroyする | |
this->manager->Destroy(); | |
this->scene->Destroy(); | |
} | |
void | |
ClassTest::getAllMesh(FbxArray<FbxMesh*>& meshArray) { | |
for (int i = 0; i < this->scene->GetSrcObjectCount<FbxMesh>(); i++) { | |
FbxMesh* mesh = this->scene->GetSrcObject<FbxMesh>(i); | |
meshArray.Add(mesh); | |
} | |
} | |
void | |
ClassTest::showSkeletonNodeTree() { | |
FbxNode* rootNode = this->scene->GetRootNode(); | |
for (int i = 0; i < rootNode->GetChildCount(); i++) { | |
FbxNode* childNode = rootNode->GetChild(i); | |
FbxSkeleton* skel = childNode->GetSkeleton(); | |
// Skeletonだった場ののみ処理 | |
if (skel) { | |
FbxArray<FbxNode*>* nodes = new FbxArray<FbxNode*>(); | |
getRecursiveNode(childNode, *nodes); | |
for (int j = 0; j < nodes->Size(); j++) { | |
string skelPath = ""; | |
getFullNodePath(nodes->GetAt(j), skelPath); | |
cout << skelPath << endl; | |
} | |
} | |
} | |
} | |
void | |
ClassTest::getMeshData(FbxMesh* pMesh, USDMeshData* meshData) { | |
//引数のpMeshDataをstrcutで取得する | |
FbxNode* pNode = pMesh->GetNode(); | |
// FullPathをセット | |
getFullNodePath(pNode, meshData->sdfPath); | |
int polyCount = pMesh->GetPolygonCount(); // Polyの数 | |
int vtxCount = pMesh->GetControlPointsCount(); // Vertexの数 | |
FbxVector4* position = pMesh->GetControlPoints(); // 頂点座標 | |
// 頂点情報を取得 | |
for (int i = 0; i < vtxCount; i++) { | |
meshData->vtxPoints.push_back(GfVec3f(position[i][0], position[i][1], position[i][2])); | |
} | |
for (int i = 0; i < polyCount; i++) { | |
int polySize = pMesh->GetPolygonSize(i); | |
meshData->polyVtx.push_back(polySize); | |
for (int j = 0; j < polySize; j++) { | |
int index = pMesh->GetPolygonVertex(i, j); | |
meshData->polyIndex.push_back(index); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment