-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.cpp
More file actions
134 lines (114 loc) · 4.78 KB
/
Copy pathsample.cpp
File metadata and controls
134 lines (114 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <fbxsdk.h>
/* Tab character ("\t") counter */
int numTabs = 0;
/**
* Print the required number of tabs.
*/
void PrintTabs() {
for (int i = 0; i < numTabs; i++)
printf("\t");
}
/**
* Return a string-based representation based on the attribute type.
*/
FbxString GetAttributeTypeName(FbxNodeAttribute::EType type) {
switch (type) {
case FbxNodeAttribute::eUnknown: return "unidentified";
case FbxNodeAttribute::eNull: return "null";
case FbxNodeAttribute::eMarker: return "marker";
case FbxNodeAttribute::eSkeleton: return "skeleton";
case FbxNodeAttribute::eMesh: return "mesh";
case FbxNodeAttribute::eNurbs: return "nurbs";
case FbxNodeAttribute::ePatch: return "patch";
case FbxNodeAttribute::eCamera: return "camera";
case FbxNodeAttribute::eCameraStereo: return "stereo";
case FbxNodeAttribute::eCameraSwitcher: return "camera switcher";
case FbxNodeAttribute::eLight: return "light";
case FbxNodeAttribute::eOpticalReference: return "optical reference";
case FbxNodeAttribute::eOpticalMarker: return "marker";
case FbxNodeAttribute::eNurbsCurve: return "nurbs curve";
case FbxNodeAttribute::eTrimNurbsSurface: return "trim nurbs surface";
case FbxNodeAttribute::eBoundary: return "boundary";
case FbxNodeAttribute::eNurbsSurface: return "nurbs surface";
case FbxNodeAttribute::eShape: return "shape";
case FbxNodeAttribute::eLODGroup: return "lodgroup";
case FbxNodeAttribute::eSubDiv: return "subdiv";
default: return "unknown";
}
}
/**
* Print an attribute.
*/
void PrintAttribute(FbxNodeAttribute* pAttribute) {
if (!pAttribute) return;
FbxString typeName = GetAttributeTypeName(pAttribute->GetAttributeType());
FbxString attrName = pAttribute->GetName();
PrintTabs();
// Note: to retrieve the character array of a FbxString, use its Buffer() method.
printf("<attribute type='%s' name='%s'/>\n", typeName.Buffer(), attrName.Buffer());
}
/**
* Print a node, its attributes, and all its children recursively.
*/
void PrintNode(FbxNode* pNode) {
PrintTabs();
const char* nodeName = pNode->GetName();
FbxDouble3 translation = pNode->LclTranslation.Get();
FbxDouble3 rotation = pNode->LclRotation.Get();
FbxDouble3 scaling = pNode->LclScaling.Get();
// Print the contents of the node.
printf("<node name='%s' translation='(%f, %f, %f)' rotation='(%f, %f, %f)' scaling='(%f, %f, %f)'>\n",
nodeName,
translation[0], translation[1], translation[2],
rotation[0], rotation[1], rotation[2],
scaling[0], scaling[1], scaling[2]
);
numTabs++;
// Print the node's attributes.
for (int i = 0; i < pNode->GetNodeAttributeCount(); i++)
PrintAttribute(pNode->GetNodeAttributeByIndex(i));
// Recursively print the children.
for (int j = 0; j < pNode->GetChildCount(); j++)
PrintNode(pNode->GetChild(j));
numTabs--;
PrintTabs();
printf("</node>\n");
}
/**
* Main function - loads the hard-coded fbx file,
* and prints its contents in an xml format to stdout.
*/
int main(int argc, char** argv) {
// Change the following filename to a suitable filename value.
const char* lFilename = "CAT.fbx";
// Initialize the SDK manager. This object handles all our memory management.
FbxManager* lSdkManager = FbxManager::Create();
// Create the IO settings object.
FbxIOSettings* ios = FbxIOSettings::Create(lSdkManager, IOSROOT);
lSdkManager->SetIOSettings(ios);
// Create an importer using the SDK manager.
FbxImporter* lImporter = FbxImporter::Create(lSdkManager, "");
// Use the first argument as the filename for the importer.
if (!lImporter->Initialize(lFilename, -1, lSdkManager->GetIOSettings())) {
printf("Call to FbxImporter::Initialize() failed.\n");
printf("Error returned: %s\n\n", lImporter->GetStatus().GetErrorString());
exit(-1);
}
// Create a new scene so that it can be populated by the imported file.
FbxScene* lScene = FbxScene::Create(lSdkManager, "myScene");
// Import the contents of the file into the scene.
lImporter->Import(lScene);
// The file is imported; so get rid of the importer.
lImporter->Destroy();
// Print the nodes of the scene and their attributes recursively.
// Note that we are not printing the root node because it should
// not contain any attributes.
FbxNode* lRootNode = lScene->GetRootNode();
if (lRootNode) {
for (int i = 0; i < lRootNode->GetChildCount(); i++)
PrintNode(lRootNode->GetChild(i));
}
// Destroy the SDK manager and all the other objects it was handling.
lSdkManager->Destroy();
return 0;
}