bool CModelExporter::ExportNode( IGameNode* pNode ) { IGameMesh* pMesh = (IGameMesh*)pNode->GetIGameObject(); IGameMaterial* pRootMat = pNode->GetNodeMaterial(); pMesh->SetUseWeightedNormals(); pMesh->InitializeData(); int uFaceCount = pMesh->GetNumberOfFaces(); for(int i = 0; i < uFaceCount; ++i) { FaceEx* pFace = pMesh->GetFace(i); for(int j = 0; j < 3; ++j) { DWORD mapIndex[3]; Point3 ptUV; int indexUV = pFace->texCoord[j]; IGameTextureMap* pMap = GetTextureMap(pRootMat, ID_DI); int nChannel = pMap->GetMapChannel(); if(pMesh->GetMapFaceIndex(nChannel, pFace->meshFaceIndex, mapIndex)) ptUV = pMesh->GetMapVertex(nChannel, mapIndex[j]); else ptUV = pMesh->GetMapVertex(nChannel, indexUV); int indexPos = pFace->vert[j]; Point3 pos = pMesh->GetVertex(indexPos); } } return true; }
void CModelExporter::ExportMeshVertex(IGameNode* /*pNode*/, IGameMesh* pMesh, IGameMaterial* pMat, size_t uMatID, BOOL bMultiMat) { pMesh->SetUseWeightedNormals(); pMesh->InitializeData(); Tab<FaceEx*> faceTab; CollectMeshFaces(faceTab, pMesh, uMatID, bMultiMat); size_t uFaceCount = faceTab.Count(); size_t uVertexCount = uFaceCount * 3; m_serializer << uVertexCount; BOOL bDiffusemap = GetTextureMap(pMat, ID_DI) == NULL ? FALSE : TRUE; BOOL bNormalmap = GetTextureMap(pMat, ID_BU) == NULL ? FALSE : TRUE; BOOL bSpecularmap = GetTextureMap(pMat, ID_SS) == NULL ? FALSE : TRUE; BOOL bLightmap = GetTextureMap(pMat, ID_AM) == NULL ? FALSE : TRUE; float centerX = 0; float centerY = 0; float centerZ = 0; for(size_t i = 0; i < uFaceCount; ++i) { FaceEx* pFace = faceTab[i]; for(int j = 0; j < 3; ++j) { DWORD mapIndex[3]; Point3 ptUV; int indexUV = pFace->texCoord[j]; int nChannel = 0; if(bDiffusemap || bNormalmap || bSpecularmap) { IGameTextureMap* pMap = GetTextureMap(pMat, ID_DI); nChannel = pMap->GetMapChannel(); } else if(bLightmap) { IGameTextureMap* pMap = GetTextureMap(pMat, ID_AM); nChannel = pMap->GetMapChannel(); } if(pMesh->GetMapFaceIndex(nChannel, pFace->meshFaceIndex, mapIndex)) ptUV = pMesh->GetMapVertex(nChannel, mapIndex[j]); else ptUV = pMesh->GetMapVertex(nChannel, indexUV); int indexPos = pFace->vert[j]; Point3 pos = pMesh->GetVertex(indexPos); m_serializer << pos.x << pos.y << pos.z; m_serializer << ptUV.x << ptUV.y; centerX += pos.x; centerY += pos.y; centerZ += pos.z; } } if (uFaceCount > 0) { centerX /= (uFaceCount * 3); centerY /= (uFaceCount * 3); centerZ /= (uFaceCount * 3); m_serializer << centerX << centerY << centerZ; } }
IGameTextureMap* GetTextureMap(IGameMaterial* pMat, int nSlot) { IGameTextureMap* pTex = NULL; int nTexCnt = pMat->GetNumberOfTextureMaps(); for(int x = 0; x < nTexCnt; x++) { pTex = pMat->GetIGameTextureMap(x); if(pTex->GetStdMapSlot() == nSlot) return pTex; } return NULL; }
void CModelExporter::ExportMaterialTexture( IGameNode* pNode, IGameMaterial* pMat ) { IGameTextureMap* pTex = GetTextureMap(pMat, ID_DI); if(pTex != NULL) { this->ExportTexture(pNode, pMat, pTex); } bool bSetOpacityTexture = GetTextureMap(pMat, ID_OP) != NULL; if (bSetOpacityTexture) { IGameTextureMap* pTex = GetTextureMap(pMat, ID_OP); const TCHAR* pszTexFileName = pTex->GetBitmapFileName(); BEATS_ASSERT(pszTexFileName != NULL); std::string textureName = GetFileFullNameFromPathName(pszTexFileName, (size_t)_tcslen(pszTexFileName)); bSetOpacityTexture = textureName.length() > 0; } m_serializer << bSetOpacityTexture; }
//bool MaterialExporter::streamPass(std::ostream &of, Mtl *mtl) { bool MaterialExporter::streamPass(std::ostream &of, IGameMaterial *mtl) { of << "\t\tpass" << std::endl; of << "\t\t{" << std::endl; int subMtlCt = mtl->GetSubMaterialCount(); Point4 val4; Point3 val3; PropType pt; IGameProperty* p = mtl->GetAmbientData(); if (p) { pt = p->GetType(); if (pt == IGAME_POINT3_PROP) { p->GetPropertyValue(val3); of << "\t\t\tambient " << val3.x << " " << val3.y << " " << val3.z << " " << std::endl; } if (pt == IGAME_POINT4_PROP) { p->GetPropertyValue(val4); of << "\t\t\tambient " << val4.x << " " << val4.y << " " << val4.z << " " << val4.w << " " << std::endl; } } p = mtl->GetDiffuseData(); if (p) { pt = p->GetType(); if (pt == IGAME_POINT3_PROP) { p->GetPropertyValue(val3); of << "\t\t\tdiffuse " << val3.x << " " << val3.y << " " << val3.z << " " << std::endl; } if (pt == IGAME_POINT4_PROP) { p->GetPropertyValue(val4); of << "\t\t\tdiffuse " << val4.x << " " << val4.y << " " << val4.z << " " << val4.w << " " << std::endl; } } p = mtl->GetSpecularData(); if (p) { pt = p->GetType(); if (pt == IGAME_POINT3_PROP) { p->GetPropertyValue(val3); of << "\t\t\tspecular " << val3.x << " " << val3.y << " " << val3.z << " " << std::endl; } if (pt == IGAME_POINT4_PROP) { p->GetPropertyValue(val4); of << "\t\t\tspecular " << val4.x << " " << val4.y << " " << val4.z << " " << val4.w << " " << std::endl; } } p = mtl->GetEmissiveData(); if (p) { pt = p->GetType(); if (pt == IGAME_POINT3_PROP) { p->GetPropertyValue(val3); of << "\t\t\temissive " << val3.x << " " << val3.y << " " << val3.z << " " << std::endl; } if (pt == IGAME_POINT4_PROP) { p->GetPropertyValue(val4); of << "\t\t\temissive " << val4.x << " " << val4.y << " " << val4.z << " " << val4.w << " " << std::endl; } } int numTexMaps = mtl->GetNumberOfTextureMaps(); if (numTexMaps > 0) { for (int texMapIdx = 0; texMapIdx < numTexMaps; texMapIdx++) { IGameTextureMap* tmap = mtl->GetIGameTextureMap(texMapIdx); if (tmap) { of << "\n\t\t\ttexture_unit " << std::endl; of << "\t\t\t{" << std::endl; std::string bmap(tmap->GetBitmapFileName()); bmap = bmap.substr(bmap.find_last_of('\\') + 1); of << "\t\t\t\ttexture " << bmap << std::endl; of << "\t\t\t}" << std::endl; } } } of << "\t\t}" << std::endl; return true; }
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()); } }
//---------------------------------------------------------------------------------- // dump material textures void DumpTexture(m_material *pMat, IGameMaterial *pGMaxMat) { std::vector<tex_channel> bk_tex_channel; std::vector<unsigned int> bk_tex_idx; std::vector<MatTextureInfo> TexInfos; int texCount = pGMaxMat->GetNumberOfTextureMaps(); for (int i = 0; i < texCount; ++i) { IGameTextureMap * pGMaxTex = pGMaxMat->GetIGameTextureMap(i); int tex_type = pGMaxTex->GetStdMapSlot(); if (pGMaxTex->IsEntitySupported() && tex_type >= 0) //its a bitmap texture { MatTextureInfo TexInfo; tex_channel tc; TexInfo.mat_id = pMat->id; m_texture * pTex = new m_texture; std::string pathname = pGMaxTex->GetBitmapFileName(); int idx = (int)pathname.rfind('\\'); if (idx == INDEX_NONE){ idx = (int)pathname.rfind('/'); } std::string filename = pathname.substr(idx + 1, INDEX_NONE); pTex->name = filename; // set the texture xform... IGameUVGen *pUVGen = pGMaxTex->GetIGameUVGen(); GMatrix UVMat = pUVGen->GetUVTransform(); TexInfo.tex_mat = pTex->tex_mat = (scalar*)UVMat.GetAddr(); // save mapping matrix // get the uv channel to use... Texmap *pTMap = pGMaxTex->GetMaxTexmap(); BitmapTex *pBTex = (BitmapTex*)pTMap; StdUVGen *pStdUVGen = pBTex->GetUVGen(); if (pStdUVGen){ tc.channel = pStdUVGen->GetMapChannel() - 1; } IParamBlock2 *pUVWCropParam = (IParamBlock2*)(pBTex->GetReference(1)); if (pUVWCropParam) { pUVWCropParam->GetValue(0, ExporterMAX::GetExporter()->GetStaticFrame(), TexInfo.uv_offset.x, FOREVER); pUVWCropParam->GetValue(1, ExporterMAX::GetExporter()->GetStaticFrame(), TexInfo.uv_offset.y, FOREVER); pUVWCropParam->GetValue(2, ExporterMAX::GetExporter()->GetStaticFrame(), TexInfo.uv_scale.x, FOREVER); pUVWCropParam->GetValue(3, ExporterMAX::GetExporter()->GetStaticFrame(), TexInfo.uv_scale.y, FOREVER); } // set the type of texture... pTex->type = texture_type[tex_type]; // if we have a bump map, we create a normal map with the convention // that the filename will be the same name as the bump map + "_normal" // appended to it. if (pTex->type == m_texture::BUMP) { std::string normal_map = pTex->name; std::string::size_type pos = normal_map.rfind("."); normal_map.insert(pos, "_normal"); m_texture *pTexNormal = new m_texture; *pTexNormal = *pTex; pTexNormal->name = normal_map; pTexNormal->type = m_texture::NORMAL; tc.pTex = pTexNormal; bk_tex_channel.push_back(tc); // add the new texture to the local TOC TexInfos.push_back(TexInfo); } tc.pTex = pTex; bk_tex_channel.push_back(tc); // add the new texture to the local TOC TexInfos.push_back(TexInfo); } } // lets check if we don't have them already in our global TOC... for (size_t index = 0; index < bk_tex_channel.size(); ++index) { m_texture * pTex = bk_tex_channel[index].pTex; unsigned int idx = ExporterMAX::GetExporter()->FindTexture(pTex); if (idx == INDEX_NONE){ idx = ExporterMAX::GetExporter()->AddTexture(pTex); // add the new texture to the TOC } bk_tex_idx.push_back(idx); pMat->tex_channel.push_back(bk_tex_channel[index].channel); TexInfos[index].base_channel = bk_tex_channel[index].channel; bk_texs.insert(IdxBKTexMapPair(idx, TexInfos[index])); } // set the texture indices... for (size_t index = 0; index < bk_tex_idx.size(); ++index){ pMat->textures.push_back(bk_tex_idx[index]); } }
int MaxExporter::DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts, DWORD options) { /*if(!suppressPrompts) DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_PANEL), GetActiveWindow(), MaxExporterOptionsDlgProc, (LPARAM)this);*/ #pragma message(TODO("return TRUE If the file is exported properly")) Node::s_nextID = 1; ofstream myFile; myFile.open("DebugExporter.txt"); wstring wFileName( name ); string fileName( wFileName.begin(), wFileName.end() ); //f= fopen( fileName.c_str(),"wb"); BinaryFile = loadSave( fileName.c_str() ); //BinaryFile.saveInt( 5 ); //BinaryFile.close(); myFile << "Start Export\n"; IGameScene* gameScene = GetIGameInterface(); gameScene->InitialiseIGame(); int nodeCount = gameScene->GetTopLevelNodeCount(); myFile << "Number of top level nodes: " << nodeCount << "\n"; //get all of the materials for( int nodeNumber = 0; nodeNumber < nodeCount; ++nodeNumber) { IGameNode* gameNode = gameScene->GetTopLevelNode( nodeNumber ); Node* myNode = new Node( gameNode ); m_NodeList.push_back( myNode ); findFaces( myNode, myFile ); } myFile << "Number of materials\n"; myFile << m_materialSet.size() << "\n"; int totalBatches = 0; //myFile<< "Number of triangleBatchMaps: " << m_triangleBatchesPerNode.size() << "\n"; for( auto nodeIter = m_NodeList.begin(); nodeIter != m_NodeList.end(); ++nodeIter ) { std::map< IGameMaterial*, TriangleBatch* > triangleBatches = (*nodeIter)->m_triangleBatchesPerMaterial; myFile << "Invidiual triangleBatch size: " << triangleBatches.size() << "\n"; for( auto materialIter = m_materialSet.begin(); materialIter != m_materialSet.end(); ++materialIter ) { auto found = triangleBatches.find( * materialIter ); if( found != triangleBatches.end() ) { ++totalBatches; } } } BinaryFile.saveInt( m_NodeList.size() ); myFile << "Number of Nodes: " << m_NodeList.size() << "\n"; for( auto nodeIter = m_NodeList.begin(); nodeIter != m_NodeList.end(); ++nodeIter ) { std::map< IGameMaterial*, TriangleBatch* > triangleBatches = (*nodeIter)->m_triangleBatchesPerMaterial; std::map<IGameMaterial*, std::vector< NodeFace > > facesPerMaterial = (*nodeIter)->m_facesPerMaterial; IGameNode* currentNode = (*nodeIter)->m_gameNode; IGameNode* parentNode; GMatrix parentWTM; GMatrix toParentMatrix; GMatrix worldTM; GMatrix localTM; int time = gameScene->GetSceneStartTime(); for( ; time < gameScene->GetSceneEndTime(); time += 4800/30 ) { if( (*nodeIter)->m_parentID != 0 ) { myFile << "Trying to find parent... \n"; parentNode = (*nodeIter)->m_parent->m_gameNode; if( parentNode != nullptr ) { myFile << "Parent found \n"; parentWTM = parentNode->GetWorldTM( time ); toParentMatrix = parentWTM.Inverse(); worldTM = currentNode->GetWorldTM( time ) * toParentMatrix; } } else { worldTM = currentNode->GetWorldTM( time ); } (*nodeIter)->m_toParentMatrix.push_back( Matrix4x4( worldTM[0], worldTM[1], worldTM[2], worldTM[3] ) ); } localTM = currentNode->GetWorldTM().Inverse(); (*nodeIter)->m_worldToLocal = Matrix4x4( localTM[0], localTM[1], localTM[2], localTM[3] ); //Save the node BinaryFile.saveNode( *nodeIter, myFile ); BinaryFile.saveInt( (*nodeIter)->m_triangleBatchesPerMaterial.size() ); for( auto materialIter = m_materialSet.begin(); materialIter != m_materialSet.end(); ++materialIter ) { //Set the current material's VBO and IBO // IGameMaterial* currentMaterial = *materialIter; TriangleBatch* currentBatch = triangleBatches[ currentMaterial ]; GMatrix localTMNoTrans = localTM; localTMNoTrans.SetRow( 3, Point4( 0,0,0,1) ); if( currentBatch != nullptr ) { MaxMaterial* currentMaxMaterial = currentBatch->m_material; VBO* currentVBO = currentBatch->m_vbo; IBO* currentIBO = currentBatch->m_ibo; vector< NodeFace >& faceVector = facesPerMaterial.find( currentMaterial )->second; //Get texture materials and export them // if( currentMaterial != nullptr ) { int numOfTexMaps = currentMaterial->GetNumberOfTextureMaps(); myFile << "Number of texture maps: " << numOfTexMaps << "\n"; for( int i = 0; i < numOfTexMaps; ++i ) { IGameTextureMap* gameTextureMap = currentMaterial->GetIGameTextureMap( i ); if( gameTextureMap != nullptr && gameTextureMap->IsEntitySupported() ) { int stdMapSlot = gameTextureMap->GetStdMapSlot(); if( stdMapSlot == ID_DI ) { wstring wBitmapFileName; wBitmapFileName = gameTextureMap->GetBitmapFileName(); if( wBitmapFileName.size() > 0 ) { BitmapInfo bi( gameTextureMap->GetBitmapFileName() ); BMMGetFullFilename( &bi ); wBitmapFileName = bi.Name(); std::string fullBitmapFileName( wBitmapFileName.begin(), wBitmapFileName.end() ); if( fullBitmapFileName.size() > 0 ) { int lastSlash = fullBitmapFileName.find_last_of('\\') + 1; if( lastSlash != string::npos ) { const std::string bitmapFileName = fullBitmapFileName.substr( lastSlash ); wstring nameAsWString( name ); std::string nameAsString( nameAsWString.begin(), nameAsWString.end() ); const std::string extension = nameAsString.substr( 0, nameAsString.find_last_of('\\') + 1 ); std::string newFileName = extension; newFileName.append( bitmapFileName ); wstring wNewFileName(newFileName.begin(), newFileName.end()); if( CopyFile( wBitmapFileName.c_str(), wNewFileName.c_str(), false ) ) { if( stdMapSlot == ID_DI ) { currentMaxMaterial->m_diffuseTexture = bitmapFileName; currentMaxMaterial->bHasDiffuseTexture = true; } //BinaryFile.saveString( bitmapFileName ); } else { myFile << GetLastError() << "\n"; myFile << "copying the file FAILED.\n"; } } } } } } } } myFile<< "Number of faces for this material: " << faceVector.size() << "\n"; for( int face = 0; face < faceVector.size(); ++face ) { FaceEx* meshFace = faceVector[face].m_face; IGameMesh* gameMesh = faceVector[face].m_mesh; IGameSkin* gameSkin = gameMesh->GetIGameSkin(); int position, normal, color, texCoordinate, maxPosition; for( int i = 0; i < 3; ++i) { maxPosition = (int)meshFace->vert[i]; Point3 tempPos = gameMesh->GetVertex( maxPosition ); tempPos = tempPos * localTM; Vector3D positionVec3( tempPos.x, tempPos.y, tempPos.z ); position = currentVBO->insertPosition(positionVec3); normal = (int)meshFace->norm[i]; Point3 tempNormal = gameMesh->GetNormal( normal ); tempNormal = tempNormal * localTMNoTrans; tempNormal = tempNormal.Normalize(); Vector3D normalVec3( tempNormal.x, tempNormal.y, tempNormal.z ); normal = currentVBO->insertNormal(normalVec3); //IBO texCoordinate = (int)meshFace->texCoord[i]; Point2 tempTexCoord = gameMesh->GetTexVertex( texCoordinate ); Vector2 texCoordVec2( tempTexCoord.x, tempTexCoord.y ); texCoordinate = currentVBO->insertTexCoord(texCoordVec2); VertexIndex VI( position, normal, texCoordinate ); if( gameSkin != nullptr ) { int numberOfBones = gameSkin->GetNumberOfBones( maxPosition ); for( int boneIndex = 0; boneIndex < numberOfBones; ++boneIndex ) { float boneWeight = gameSkin->GetWeight( maxPosition, boneIndex ); IGameNode* bone = gameSkin->GetIGameBone( maxPosition, boneIndex ); myFile << "Bone node ID: " << bone->GetNodeID() << "\n"; int nodeIDForBone = m_boneIDToNodeID[ bone->GetNodeID() ]; myFile << "Node ID: " << nodeIDForBone << "\n"; VI.addBoneWeight( nodeIDForBone, boneWeight ); /*for( auto boneIter = m_NodeList.begin(); boneIter != m_NodeList.end(); ++boneIter ) { if( (*boneIter)->m_gameNode == bone ) { myFile << "Found the bone!\n"; } }*/ } VI.topBoneWeights(); } int vertIndex = currentVBO->insertVertex( VI ); currentIBO->addIndex( vertIndex ); } } BinaryFile.saveTriangleMesh( currentBatch, myFile ); } } } myFile.close(); for( int nodeNumber = 0; nodeNumber < nodeCount; ++nodeNumber) { IGameNode* gameNode = gameScene->GetTopLevelNode( nodeNumber ); if( gameNode != nullptr ) { tearDown( gameNode ); } } BinaryFile.close(); return TRUE; //return FALSE; }