|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
| how to extract material properties
|
|
|
Hi evryone,
i want to extract the material properties that are in a mesh. i am catching the node with the mesh attribute then i do not understand how to extract the material properties from the layer material. can some one gives to me the steps to arrive to the material properties.
|
|
|
|
Please refer to the DisplayMaterial(KFbxGeometry* pGeometry) in ImportScene example.
Basically, you can get the material from the node like this:
for(int lIndex=0; lIndex < lNode->GetMaterialCount() lIndex++)
{
KFbxSurfaceMaterial *lMaterial = lNode->GetMaterial(lIndex)
//Then for each lMaterial, you can get the property from it according to its type.
if(lMaterial->GetClassId().Is(KFbxSurfaceLambert::ClassId) )
{
((KFbxSurfaceLambert *)lMaterial)->GetAmbientColor()
((KFbxSurfaceLambert *)lMaterial)->GetDiffuseColor()
...
}
else if(lMaterial->GetClassId().Is(KFbxSurfacePhong::ClassId))
{
((KFbxSurfacePhong *) lMaterial)->GetAmbientColor()
((KFbxSurfacePhong *) lMaterial)->GetDiffuseColor()
...
}
}
Jiayang Xu
Maya Data Platform
Autodesk
|
|
|
|
LayerElementTexture: 0 {
Version: 101
Name: ""
MappingInformationType: "ByPolygon"
ReferenceInformationType: "IndexToDirect"
BlendMode: "Translucent"
TextureAlpha: 1
TextureId: 1,-1,1,-1,0,0
}
The above shows a texture that is assigned to only certain faces. As best as I can tell, textures are assigned the same way that materials are assigned, and presumably the combination of those are applied during rendering? The thing is, in Maya, a material and its associated textures really isn’t separate at all. Is that a bad assumption to make? I’m not very familiar with Max or Mudbox (or other packages).
Further, are the values in the texture index array referring to the KFbxScene’s list of all textures, or is there some way to get the ones that are associated with the mesh, similar to how materials are done?
Please, somebody make this make sense. So far, I’ve spent half a day trying to figure this out, and there’s almost zero useful documentation or samples about this.
Thanks,
JH
|
|
|
|
Hi Jason,
For question 1, material indices and texture indices are independent since you can have material on certain face with no texture. e.g.
LayerElementMaterial: 0 {
Version: 101
Name: ""
MappingInformationType: "ByPolygon"
ReferenceInformationType: "IndexToDirect"
Materials: 1,0,0,3,1,2
}
LayerElementTexture: 0 {
Version: 101
Name: ""
MappingInformationType: "ByPolygon"
ReferenceInformationType: "IndexToDirect"
BlendMode: "Translucent"
TextureAlpha: 1
TextureId: -1,0,0,-1,-1,1
}
Material 1 and 3 are mapped on face 0 and 3 with no texture attached(-1).
For question 2, texture indices in layer element texture are the indices of textures which connect to current object not the indices of all textures in scene.
FYI, there is an example named ImportScene in our SDK, please take a good look at it since it tells the user the basic things about getting information(mesh, material, texture, animation, etc) from fbx file.
Thank you,
Eric Feng, Framestore
|
|
|
|
Wow, amazingly fast response. Thanks for that.
Something I’m very confused about--after looking at the example, and simultaneously debugging it and my own import code loading the same scene, I figured out the tiny piece that was wrong in my codebase.
int const numLayers = mesh->GetLayerCount(KFbxLayerElement::eMATERIAL)
KFbxLayer *layer = mesh->GetLayer(0)
KFbxLayerElementMaterial *materials = layer->GetMaterials()
The above does NOT get the correct materials for a mesh. This is odd, because it certainly appears to be the right way to do things from the documentation.
int lNbMat = mesh->GetNode()->GetSrcObjectCount(KFbxSurfaceMaterial::ClassId) for (int lMaterialIndex = 0; lMaterialIndex < lNbMat; lMaterialIndex++)
{
KFbxSurfaceMaterial *lMaterial = (KFbxSurfaceMaterial *)mesh->GetNode()->GetSrcObject(KFbxSurfaceMaterial::ClassId, lMaterialIndex)
if(lMaterial)
{ // do something with material
}
}
The above snippet comes from the sample. Yes, you will get the same number of materials in both blocks of code, they will give you the same names and most of their properties will be similar, but in the first block (my code), no textures will be found, and in the second block, they will.
This kind of impenetrable obtuseness is what makes working with art packages such a nightmare. Doesn’t matter if it’s FBX or Maya API or what--having two apparently valid ways to get the data, but one is missing info, is a terrible design.
Maybe there’s a reason for it. Can you explain why I would want this behavior?
Thanks,
JH
|
|
|
|
Hi Jason,
Yes, I need to tell you the history of fbx to answer your question.
Since fbx came from Motion Builder(previous known as Film Box), the layers way of getting material, texture are inherited from it.
That is what we call “the old” way internally: texture connected to node, material connected to node.
However, this way is so odd that many software do not deal with material this way.
So we got “the new way"(or we can call that normal way which is used by current fbx sdk) to deal with material: material connected node, texture connected to material.
But the fbx v6 file is still written with the old way(for compatible reason), while the scene graph in memory is “the new way” converted by a material converter after importing the scene.
And writing out a fbx v6 file is the opposite process of reading: convert the new way to the old way then write the data out to file.
So for the users, they dont need to know anything about the old way of dealing with material , which means u can just follow what the examples say.
For the next release, we will upgrade fbx file version from v6 to v7 and v7 is the new way to deal with material natively in file, which means no more convertion of reading/writing file, and smaller file size, faster performance.
Thank you,
Eric Feng, Framestore
|
|
|
|
Well, thanks for the explanation. I would really like to see something in the documentation showing how this works, as one of the advanced programmers reference guide articles. The only ones there show you how to look at materials and apply them, which in practice is damn near useless. And there should be mentions that the “old way” doesn’t work to get textures, in the functions that a user going through the reference manual would be reading, such as mesh->GetMaterials(). If the only verifiably good way to learn the FBX API is by copying the examples, we can only be expected to do things that FBX has samples for.
But again, thanks for the explanation.
JH
|
|
|
|
| Settings
| Choose Theme color:
|
|
|
|
|
|
|