bool ExporterF3D::ExportMaterial(IGameMaterial* gameMaterial, MaterialPtr& material, STileUV& tile) { if (!m_settings->isExportMaterials()) { return true; } if (!gameMaterial) { LOG_WARNING("Material don't apply for this Node. Skipping Export Material"); return true; //maybe need false } std::string materialName = TCHARToString(gameMaterial->GetMaterialName()); std::string materialClass = TCHARToString(gameMaterial->GetMaterialClass()); auto predMaterialExist = [&materialName](const MaterialPtr& material) -> bool { return material->getResourseName() == materialName; }; const std::vector<MaterialPtr>& materials = m_scene->getMaterialList(); std::vector<MaterialPtr>::const_iterator iter = std::find_if(materials.begin(), materials.end(), predMaterialExist); if (iter != materials.end()) { material = (*iter); return true; } LOG_INFO("ExportMaterial : %s, class: %s", materialName.c_str(), materialClass.c_str()); if (gameMaterial->IsMultiType()) { LOG_DEBUG("ExportMaterial Export muliType"); s32 countSubMaterial = gameMaterial->GetSubMaterialCount(); LOG_INFO("Num Sub Materials : %d", countSubMaterial); for (u32 i = 0; i < countSubMaterial; ++i) { if (i == 0) //Use only first { IGameMaterial* subGameMaterial = gameMaterial->GetSubMaterial(i); s32 materialId = gameMaterial->GetMaterialID(i); LOG_INFO("Material ID : %d", materialId); return ExporterF3D::ExportMaterial(subGameMaterial, material, tile); } } } else { LOG_DEBUG("ExportMaterial Export singleType"); material->setResourseName(materialName); //Texture for (u32 i = 0; i < gameMaterial->GetNumberOfTextureMaps(); ++i) { LOG_DEBUG("ExportMaterial Textures"); IGameTextureMap* textureMap = gameMaterial->GetIGameTextureMap(i); std::string textureName = TCHARToString(textureMap->GetTextureName()); LOG_INFO("Texture Name[%d] : %s", i, textureName.c_str()); s32 textureType = textureMap->GetStdMapSlot(); switch (textureType) { case ID_DI: { std::string diffuseMapName = getBitmapNameWithoutPath(TCHARToString(textureMap->GetBitmapFileName())); LOG_INFO("DiffuseMap Texture File : %s", diffuseMapName.c_str()); CImage* texture = new CImage(); texture->setResourseName(diffuseMapName); //material->setTexture(i, texture); m_scene->addTexture(material, texture); IGameUVGen* uvGen = textureMap->GetIGameUVGen(); if (uvGen) { IGameProperty* u = uvGen->GetUTilingData(); IGameProperty* v = uvGen->GetVTilingData(); if (u->GetType() == IGAME_FLOAT_PROP) { u->GetPropertyValue(tile._u); } if (v->GetType() == IGAME_FLOAT_PROP) { v->GetPropertyValue(tile._v); } } } break; case ID_DP: { std::string heightMapName = getBitmapNameWithoutPath(TCHARToString(textureMap->GetBitmapFileName())); LOG_INFO("HeightMap Texture File : %s", heightMapName.c_str()); CImage* texture = new CImage(); texture->setResourseName(heightMapName); // material->setTexture(i, texture); m_scene->addTexture(material, texture); } break; case ID_BU: { std::string normalMapName = getBitmapNameWithoutPath(TCHARToString(textureMap->GetBitmapFileName())); LOG_INFO("NormalMap Texture File : %s", normalMapName.c_str()); CImage* texture = new CImage(); texture->setResourseName(normalMapName); //material->setTexture(i, texture); m_scene->addTexture(material, texture); } break; case ID_SP: case ID_OP: default: break; } } LOG_DEBUG("ExportMaterial Props"); //Diffuse Color IGameProperty* propertyDiffuseColor = gameMaterial->GetDiffuseData(); if (propertyDiffuseColor && propertyDiffuseColor->GetType() == IGAME_POINT3_PROP) { Point3 color; propertyDiffuseColor->GetPropertyValue(color); LOG_DEBUG("add DiffuseColor : (%f, %f, %f)", color.x, color.y, color.z); material->setDiffuseColor(convertPointToVector3(color)); } //Ambient Color IGameProperty* propertyAmbientColor = gameMaterial->GetAmbientData(); if (propertyAmbientColor && propertyAmbientColor->GetType() == IGAME_POINT3_PROP) { Point3 color; propertyAmbientColor->GetPropertyValue(color); LOG_DEBUG("add AmbientColor : (%f, %f, %f)", color.x, color.y, color.z); material->setAmbientColor(convertPointToVector3(color)); } //Specular Color IGameProperty* propertySpecularColor = gameMaterial->GetSpecularData(); if (propertySpecularColor && propertySpecularColor->GetType() == IGAME_POINT3_PROP) { Point3 color; propertySpecularColor->GetPropertyValue(color); LOG_DEBUG("add SpecularColor : (%f, %f, %f)", color.x, color.y, color.z); material->setSpecularColor(convertPointToVector3(color)); } //Emission Color IGameProperty* propertyEmissionColor = gameMaterial->GetEmissiveData(); if (propertyEmissionColor && propertyEmissionColor->GetType() == IGAME_POINT3_PROP) { Point3 color; propertyEmissionColor->GetPropertyValue(color); LOG_DEBUG("add EmissionColor : (%f, %f, %f)", color.x, color.y, color.z); material->setEmissionColor(convertPointToVector3(color)); } //Opacity Color IGameProperty* propertyOpacity = gameMaterial->GetOpacityData(); if (propertyOpacity && propertyOpacity->GetType() == IGAME_FLOAT_PROP) { f32 opacity; propertyOpacity->GetPropertyValue(opacity); LOG_DEBUG("add Transparency : %f", opacity); material->setTransparency(opacity); } //Specular Level IGameProperty* propertySpecularLevel = gameMaterial->GetSpecularLevelData(); if (propertySpecularLevel && propertySpecularLevel->GetType() == IGAME_FLOAT_PROP) { f32 level; propertySpecularLevel->GetPropertyValue(level); LOG_DEBUG("add SpecularLevel : %f", level); material->setShininess(level); } //Glossiness IGameProperty* propertyGlossiness = gameMaterial->GetGlossinessData(); if (propertyGlossiness && propertyGlossiness->GetType() == IGAME_FLOAT_PROP) { f32 glossiness; propertyGlossiness->GetPropertyValue(glossiness); LOG_DEBUG("add Glossiness : %f", glossiness); material->setGlossiness(glossiness); } } m_scene->addMaterial(material); return true; }
void MeshExporter::_dumpMaterial(Rad::Material * m, IGameMaterial * mtl) { Point4 val4; Point3 val3; PropType pt; IGameProperty* p = NULL; p = mtl->GetAmbientData(); if (p) { pt = p->GetType(); if (pt == IGAME_POINT3_PROP && p->GetPropertyValue(val3)) { m->ambient = Float3(val3.x, val3.y, val3.z); } } p = mtl->GetDiffuseData(); if (p) { pt = p->GetType(); if (pt == IGAME_POINT3_PROP && p->GetPropertyValue(val3)) { m->diffuse = Float3(val3.x, val3.y, val3.z); } } p = mtl->GetSpecularData(); if (p) { pt = p->GetType(); if (pt == IGAME_POINT3_PROP && p->GetPropertyValue(val3)) { m->specular = Float3(val3.x, val3.y, val3.z); } } p = mtl->GetSpecularLevelData(); if (p) { float specularPower; if (p->GetPropertyValue(specularPower)) { m->shininess = specularPower; } } p = mtl->GetEmissiveData(); if (p) { pt = p->GetType(); if (pt == IGAME_POINT3_PROP && p->GetPropertyValue(val3)) { m->emissive = Float3(val3.x, val3.y, val3.z); } } Mtl * maxMtl = mtl->GetMaxMaterial(); ULONG flag = maxMtl->Requirements(0); if (flag & MTLREQ_2SIDE) { m->cullMode = eCullMode::NONE; } d_assert (!mtl->IsMultiType()); int numTextures = mtl->GetNumberOfTextureMaps(); for ( int index = 0; index < numTextures; ++index ) { IGameTextureMap * pMap = mtl->GetIGameTextureMap(index); if (!pMap) continue; const int type = pMap->GetStdMapSlot(); const char * tex = pMap->GetBitmapFileName(); const char * ttt = pMap->GetTextureName(); std::string bmap = tex; bmap = bmap.substr(bmap.find_last_of('\\') + 1); if (type == ID_DI) m->maps[eMapType::DIFFUSE] = HWBufferManager::Instance()->LoadTexture(bmap.c_str()); else if (type == ID_BU) m->maps[eMapType::NORMAL] = HWBufferManager::Instance()->LoadTexture(bmap.c_str()); else if (type == ID_SP) m->maps[eMapType::SPECULAR] = HWBufferManager::Instance()->LoadTexture(bmap.c_str()); else if (type == ID_SI) m->maps[eMapType::EMISSIVE] = HWBufferManager::Instance()->LoadTexture(bmap.c_str()); if (type == ID_OP) m->blendMode = eBlendMode::ALPHA_TEST; TextureExporter::Instance()->Push(pMap->GetBitmapFileName()); } }