std::shared_ptr<Material> FbxUtil::CreateMaterial(FbxSurfaceMaterial *fbxMaterial) { // a,d,s, Intensity(Factor), Shininess, Reflectivity, Transparency //GetImplementation(material, FBXSDK_IMP) FbxSurfacePhong *fbxPhong = static_cast<FbxSurfacePhong*>(fbxMaterial); Material::Ptr material = Material::Create(fbxPhong->GetName()); // read uniforms material->SetUniform(Material::SHININESS, Uniform1f::Create({ (float)fbxPhong->Shininess })); material->SetUniform(Material::AMBIENT_FACTOR, Uniform1f::Create({ (float)fbxPhong->AmbientFactor })); material->SetUniform(Material::DIFFUSE_FACTOR, Uniform1f::Create({ (float)fbxPhong->DiffuseFactor })); material->SetUniform(Material::SPECULAR_FACTOR, Uniform1f::Create({ (float)fbxPhong->SpecularFactor })); auto GetUniform3f = [](FbxPropertyT<FbxDouble3> &data) -> UniformBase::Ptr { return Uniform3f::Create({ (float)data.Get()[0], (float)data.Get()[1], (float)data.Get()[2] }); }; // read colors material->SetUniform(Material::AMBIENT_COLOR, GetUniform3f(fbxPhong->Ambient)); material->SetUniform(Material::DIFFUSE_COLOR, GetUniform3f(fbxPhong->Diffuse)); material->SetUniform(Material::SPECULAR_COLOR, GetUniform3f(fbxPhong->Specular)); material->SetUniform(Material::MATERIAL_ID, Uniform1ui::Create({ material->GetID() })); auto GetTexture = [&](FbxPropertyT<FbxDouble3> prop) -> Texture::Ptr { if (prop.IsValid() && prop.GetSrcObjectCount<FbxTexture>() > 0) { FbxTexture *fbxTexture = prop.GetSrcObject<FbxTexture>(0); FbxFileTexture *fileTexture = FbxCast<FbxFileTexture>(fbxTexture); if (fileTexture) { bool mipMap = (bool)fileTexture->UseMipMap; std::string filePath = FileUtil::Instance()->GetAbsPath(fileTexture->GetRelativeFileName(), true); auto texture = Texture::Create(fileTexture->GetName()); texture->SetFilterMode(mipMap ? FilterMode::LINEAR_MIPMAP_LINEAR : FilterMode::LINEAR); texture->CreateFromImage(filePath, mipMap); return texture; } else { LOGW << "FbxProceduralTexture not supported!"; } } return nullptr; }; // read tetxures. if(m_Options & Options::DIFFUSE_MAP) material->SetTexture(Material::DIFFUSE_TEXTURE, GetTexture(fbxPhong->Diffuse)); if(m_Options & Options::SPECULAR_MAP) material->SetTexture(Material::SPECULAR_TEXTURE, GetTexture(fbxPhong->Specular)); if(m_Options & Options::NORMAL_MAP) material->SetTexture(Material::NORMAL_TEXTURE, GetTexture(fbxPhong->NormalMap)); LOGD << fbxMaterial->GetName(); return material; }