Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® FBX® / FBX SDK / THE way to import texture, materials, normals?
  RSS 2.0 ATOM  

THE way to import texture, materials, normals?
Rate this thread
 
53767
 
Permlink of this thread  
avatar
  • Total Posts: 1
  • Joined: 28 March 2011 11:22 PM

Hi all,

I am making a fbx importer in my engine and I have looked at the examples, at alot of posts and other sources and I can’t seem to find the answer to a simple question. What is the recommended way to import materials, texture and normals while covering all/most of the way they can be set in the scene.

for example for the materials I can use:

Way A

int MaterialIndex;
for (
MaterialIndex 0MaterialIndex NbMatMaterialIndex++)
{
    KFbxSurfaceMaterial 
*Material Node->GetMaterial(MaterialIndex);
...
}

or
Way B

for (int l 0pMesh->GetLayerCount(); l++)
{
    KFbxLayerElementMaterial
leMat pMesh->GetLayer(l)->GetMaterials();
...
}

Are those way equivalent? Are they all traversing all material on every layer? I would like to know the same thing for normals and textures. It seems there is alot of supposition around layer 0. But what if someday I need to get a material or normal on layer 3?

So is this the way?

for (int i 0pMesh->GetLayerCount(); i++)
{
    
/// GetNormals for layer i

    /// GetMaterials for layer i

    /// GetTextures for layer i

}

I hope this make sense, if not i’ll clarify.

thanks



Replies: 1
/userdata/avatar/vx3501hqr_small.jpg

Hello, to import materials correctly, you need both Way A and Way B.
Way A is to import the material itself, and Way B is to tell you how the material should be applied on a mesh.
For example, by Way A you can get all materials in the scene, define parameters of them, such as diffuse, specular, etc. Then by way B you can get the index array which tell you how there materials are mapped to the mesh.
For how the layerelement describe the mapping between material/uv and mesh, please take a look at FBX SDK Programmer’s Guide, the section “Applying Textures and Materials to Meshes->Using layers to control how a model is rendered->Creating layer elements for materials and textures”

To get the material or UV on all layers, yes, you need to use a loop.

Texture is different, they are connected to materials, so you need to get material first and then get the connected texture on certain property, for example, if you want to get the diffuse texture, you need to do :
lProperty = lSurfaceMaterial->FindProperty(KFbxSurfaceMaterial::sDiffuse);
if(lProperty.IsValid())
{
lDiffuseTexture = KFbxCast <KFbxTexture>(lProperty.GetSrcObject(KFbxTexture::ClassId, 0));
}

Please also take a look at ViewScene sample, GlDrawMesh() in GlFunction.cxx.

All the above are based on FBX SDK 2011.3.1, if you are using a earlier version, there might be difference.

Author: Jiayang Xu

Replied: 29 March 2011 07:13 PM