Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Import of colors when material is not lambert

battila8QBEN
Explorer
Explorer

Import of colors when material is not lambert

battila8QBEN
Explorer
Explorer

Hi All,

 

I'm new to fbx but have an issue in my program when importing specific fbx files.

I have a code which does something like this:

const int matCount = node->GetMaterialCount( );
for( int matIdx = 0; matIdx < matCount; matIdx++ )

{

    FbxSurfaceMaterial *fbxMaterial = node->GetMaterial( matIdx );

    bool isLam = fbxMaterial->GetClassId( ).Is( FbxSurfaceLambert::ClassId );

    //the value above is never true (I would query the color here with:

         //FbxSurfaceLambert *lambert = FbxCast<FbxSurfaceLambert>( fbxMaterial );

        //lambert->Diffuse.Get( ))

    const FbxProperty lProperty = fbxMaterial ->FindProperty(FbxSurfaceMaterial::sDiffuse);

    //then I do the same check for emissive, ambient, specular color

   //diffuse, amient is always 0,0,0 (only specular is not 0,0,0)

}

I found that blender and fbx review is able to import with some greyscale colors

I downloaded fbx sdk and compiled for myself. I ran the project from ViewScene.sln but it worked as my program, so no colors at all. All black.

Is there any other place where you think blender or fbx review is reading color info from?

 

Thanks,

Attila

0 Likes
Reply
479 Views
4 Replies
Replies (4)

ilan.keshet
Enthusiast
Enthusiast

Are you talking about vertex color?   -- Colors can be received at the vertex level from
fbxMesh->GetElementVertexColor();

 

Or are you trying to get the diffuse color texture?  There is a way to embed a material into the fbx file itself as an option when creating the FBX file

 

The level you are at is getting colors from the material itself used for rendering the object -- not the colors baked into the geometry nor colors from say a texture -- that gets later combined with the material used for rendering

0 Likes

battila8QBEN
Explorer
Explorer

Thanks for the answer. I think it would be enough for me if the whole model would not be all black.

I compiled ImportScene.sln from the sdk library and ran it on my example. I placed breakpoints at DisplayPolygons (no breakpoint was hit in the GetElementVertexColorCount() loop so there are no meshes with this attribute) and also put breakpoints to DisplayTextureNames function and nothing was hit.

One intersting result in output console was that there were Color information at DisplayProperties function. For example:

Display Name: Color

Internal Name: Color

Type: Color

Is Animatable: false

Default value: X=0.023..., Y=0.529..., Z=0.023...

So the only useful information is here. Maybe I should find these properties and use it for display? Maybe the Blender and FbxViewer uses also these values? Sounds not a good method for me.

 

Thanks

 

0 Likes

ilan.keshet
Enthusiast
Enthusiast

I think the first question -- should be why you are trying to extract color only.

 

Generally, -- and this pretty much almost always done, -- models use textures to show colors.   Models have UV coordinates at the vertex level that get mapped to a texture file. -- I'm sure if you examine your vertices you will see the UVs are set

 

-- Colors at the vertex level is more of an optional attribute, -- that can be used to bake in additional lighting information into a shader -- since you said your model doesn't appear to have any colors at the vertex level, -- then I'm sure you get your colors from a texture file. 

 

Without a diffuse texture file, you can have lightning calcuations that can shade faces based upon the normals. -- and color will be some shade of white to black based upon the direct it is facing to the light source. 

0 Likes

battila8QBEN
Explorer
Explorer

Dear Ilan,

 

You are right, I would prefere textures instead of colors embedded to vertices. I start my import with importing textures. I use a code that iterates through FbxNode::GetMaterialCount() and gets each FbxSurfaceMaterial with the GetMaterial() function. For each material I call FindProperty() func with sDiffuse, sEmissive, sNormalMap, sAmbient, sReflection... All of these have 0 results in this example when I call GetSrcObjectCount<FbxTexture>() on the corresponding FbxProperty. Also, during the iteration of materials I try to find if the material is valid for FbxCast<FbxSurfaceLambert> or FbxCast<FbxSurfacePhong>. None succeeds.

I try to attach my example fbx. I have some jpg files next to the model file but I can not get any texture file reference path from the model file. So I can not attach any of these existing jpg files.

 

Thanks,

Attila

0 Likes