2
\$\begingroup\$

I have the following piece of C++ code which I use to load triangle vertices from an FBX file:

FbxNode *node = scene->GetRootNode()->GetChild(0);
FbxGeometryConverter fbx_converter(node->GetFbxManager());
fbx_converter.Triangulate(node->GetNodeAttribute(), true);
mesh = node->GetMesh();
int num_vertices = mesh->GetPolygonVertexCount();
FbxVector4 *fbx_vertices = mesh->GetControlPoints();
int *fbx_triangle_vertices = mesh->GetPolygonVertices();
double x, y, z;
vector<vertex> vertices;
for (int vertex_index = 0; vertex_index < num_vertices; ++vertex_index)
{
    int index = fbx_triangle_vertices[vertex_index];
    x = (double)fbx_vertices[index][0];
    y = (double)fbx_vertices[index][1];
    z = (double)fbx_vertices[index][2];
    vertices.push_back(vertex(vector3(x, y, z), material(color(1, 0.5, 0.5), 0, 0, 0, 0, 1, 0)));
}

Currently, I am only loading vertex coordinates from the file. Now I want to load the vertex's material data (instead of assigning it manually like I did in the code snippet using material(color(1, 0.5, 0.5)...).

I see that an FbxNode object has a GetMaterial() method, but I don't know how to obtain this data since I am working with fbx vertices which are FbxVector4s, not nodes.

\$\endgroup\$
  • \$\begingroup\$ You forgot to mention what library you're using. \$\endgroup\$ – Pharap Apr 23 '17 at 16:56
  • 2
    \$\begingroup\$ @Pharap I am using the official FBX SDK available here: help.autodesk.com/view/FBX/2017/ENU/… \$\endgroup\$ – Eutherpy Apr 23 '17 at 16:58
1
\$\begingroup\$

It seems materials can be obtained from the node by FbxNode::GetMaterial(int pIndex) and FbxNode::GetMaterialIndex(const char *pName).

This data should be stored in the node you are reading, alongside the vector information, i.e. it is stored in the node and not bound to the vectors themselves.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ I saw that the material is stored inside nodes, but I don't know how to obtain nodes; for example, I have a vertex, fbx_vertices[index]. How do I "convert" this to a node, i.e. if I read all nodes, how do I know which node corresponds to this vertex? \$\endgroup\$ – Eutherpy Apr 23 '17 at 17:20
  • \$\begingroup\$ @Eutherpy You don't convert a vertex to a node, you acquire the vertices from a node. The file is loaded into a big tree of nodes, and you traverse the tree to find the other nodes. \$\endgroup\$ – Pharap Apr 23 '17 at 17:26
  • 1
    \$\begingroup\$ Oh, I see. I found the scene->GetNode(node_index) method, is this the correct way of doing this? \$\endgroup\$ – Eutherpy Apr 23 '17 at 17:38
  • \$\begingroup\$ @Eutherpy The FbxScene consists of a tree of nodes, which means it has one root node and each node has a list of child nodes. I'm fairly certain that you're supposed to traverse the tree to discover all the data. See the documentation for an example on how to traverse the tree nodes. \$\endgroup\$ – Pharap Apr 23 '17 at 17:50
  • 1
    \$\begingroup\$ I found a helpful example here: help.autodesk.com/view/FBX/2015/ENU/…, it seems you have to do this manually. Thanks for your help! \$\endgroup\$ – Eutherpy Apr 23 '17 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.