bool SGMExporter::ExportCams(BinaryWriter *bw) { scene = GetIGameInterface(); assert(scene != NULL); scene ->SetStaticFrame(0); IGameConversionManager *cm = GetConversionManager(); assert(cm != NULL); cm ->SetCoordSystem(IGameConversionManager::IGAME_OGL); if (!scene ->InitialiseIGame(false)) { Log::LogT("error: couldnt initialize scene"); return false; } // get only cam nodes std::vector<IGameNode*> meshNodes; for (int i = 0; i < scene ->GetTopLevelNodeCount(); i++) ExportCam(scene ->GetTopLevelNode(i), bw); scene ->ReleaseIGame(); return true; }
bool SGMExporter::DoExport(const TCHAR *name, ExpInterface *ei, Interface *max_interface) { scene = GetIGameInterface(); assert(scene != NULL); std::string sceneName = StringUtils::ToNarrow(scene->GetSceneFileName()); sceneName.replace(sceneName.find(".max"), 4, ""); fileName = StringUtils::ToNarrow(name) + sceneName + ".skm"; Log::StartLog(true, false, false); Log::LogT("=== exporting skinned mesh to file '%s'", fileName.c_str()); scene->SetStaticFrame(0); IGameConversionManager *cm = GetConversionManager(); assert(cm != NULL); cm->SetCoordSystem(IGameConversionManager::IGAME_OGL); if (!scene->InitialiseIGame(false)) { Log::LogT("error: couldnt initialize scene"); return false; } meshesCount = 0; std::ofstream fileStream(fileName.c_str(), std::ios::binary); BinaryWriter bw(&fileStream); /* 1.2 - vertex channels in mesh part */ bw.Write("FTSMDL", 6); bw.Write((unsigned short)((1 << 8) | 2)); // version 1.2 bw.Write((int)0); std::vector<Scene3DMesh*> meshes; if (!GetMeshes(meshes, &bw)) return false; fileStream.seekp(8, std::ios::beg); //fileStream.seekp(0, std::ios::beg); bw.Write((int)meshesCount); fileStream.close(); return true; }
void SGMExporter::ExportScene(std::ostream &os) { IGameScene *igame_scene = GetIGameInterface(); IGameConversionManager *cm = GetConversionManager(); cm ->SetCoordSystem(IGameConversionManager::IGAME_OGL); igame_scene ->InitialiseIGame(false); igame_scene ->SetStaticFrame(0); ExportObjects(igame_scene, os); igame_scene ->ReleaseIGame(); }
int DoExport( const MCHAR* name, ExpInterface* ei, Interface* i, BOOL suppressPrompts, DWORD options ) { UserCoord exporterCoord = { 1, // right-handed coordinate 1, // X axis goes right 2, // Y axis goes up 5, // Z axis goes out 1, // U goes right 0, // V goes up }; //// d3d setup //UserCoord exporterCoord = //{ // 0, // left-handed coordinate // 0, // X axis goes left // 2, // Y axis goes up // 5, // Z axis goes out // 1, // U goes right // 1, // V goes down //}; IGameScene* igScene = GetIGameInterface(); IGameConversionManager* cm = GetConversionManager(); cm->SetUserCoordSystem(exporterCoord); igScene->InitialiseIGame(); // export the very first frame igScene->SetStaticFrame( 0 ); RootExporter rootExporter; // go through all top nodes for ( int i=0; i<igScene->GetTopLevelNodeCount(); i++ ) { IGameNode* gameNode = igScene->GetTopLevelNode( i ); rootExporter.AddNode( gameNode ); } rootExporter.SaveToFile( name ); // done igScene->ReleaseIGame(); return TRUE; }
void Unreal3DExport::Init() { // Init CheckCancel(); pScene = GetIGameInterface(); GetConversionManager()->SetUserCoordSystem(UnrealCoords); if( bExportSelected ) { Tab<INode*> selnodes;; for( int i=0; i<pInt->GetSelNodeCount(); ++i ) { INode* n = pInt->GetSelNode(i); selnodes.Append(1,&n); } if( !pScene->InitialiseIGame(selnodes,false) ) throw MAXException(GetString(IDS_ERR_IGAME)); } else { if( !pScene->InitialiseIGame() ) throw MAXException(GetString(IDS_ERR_IGAME)); } // Enumerate scene NodeCount = pScene->GetTotalNodeCount(); for( int i=0; i<pScene->GetTopLevelNodeCount(); ++i ) { IGameNode * n = pScene->GetTopLevelNode(i); ExportNode(n); } Progress += U3D_PROGRESS_ENUM; // Get animation info FrameStart = pScene->GetSceneStartTime() / pScene->GetSceneTicks(); FrameEnd = pScene->GetSceneEndTime() / pScene->GetSceneTicks(); FrameCount = FrameEnd - FrameStart+1; if( FrameCount <= 0 || FrameEnd < FrameStart ) { ProgressMsg.printf(GetString(IDS_ERR_FRAMERANGE),FrameStart,FrameEnd); throw MAXException(ProgressMsg.data()); } pScene->SetStaticFrame(FrameStart); }
bool SGMExporter::ExportScene(BinaryWriter *fh) { gScene = GetIGameInterface(); assert(gScene != NULL); IGameConversionManager *cm = GetConversionManager(); assert(cm != NULL); cm ->SetCoordSystem(IGameConversionManager::IGAME_OGL); gScene ->InitialiseIGame(false); gScene ->SetStaticFrame(0); ExportObjects(fh); gScene ->ReleaseIGame(); return true; }
int TrianExporter::DoExport( const TCHAR * name, ExpInterface *ei, Interface *i, BOOL suppressPrompts, DWORD options ) { //Open the file to export to. m_of.open( name ); //Create an Error procedure. MyErrorProc pErrorProc; SetErrorCallBack( &pErrorProc ); //Get the game interface m_pIGame = GetIGameInterface(); //Start the progress bar. i->ProgressStart( _T( "Exporting to .trian file..." ), TRUE, fn, NULL ); //Set up the conversion manager. IGameConversionManager * cm = GetConversionManager(); //Set up the whacky coordinate system that 3DS Max uses. UserCoord whacky = { 1, //Right-Handed. 1, //X Axis goes right. 4, //Y Axis goes in. 3, //Z Axis goes down. 0, //U Tex Axis is left. 1 //V Tex Axis is down. }; cm->SetUserCoordSystem( whacky ); //Set the coordinate system. cm->SetCoordSystem( IGameConversionManager::IGAME_MAX ); //Initialize the game scene. m_pIGame->InitialiseIGame( options & SCENE_EXPORT_SELECTED ); //Go through all the nodes of the scene and export only the Game Meshes. for( int l = 0; l < m_pIGame->GetTopLevelNodeCount(); l++ ) { //Get the current Game node. IGameNode * node = m_pIGame->GetTopLevelNode( l ); //Check for selected state. if( node->IsTarget() ) continue; ExportNodeInfo( node ); } //End the progress bar. i->ProgressEnd(); //Release the scene. m_pIGame->ReleaseIGame(); m_pIGame = 0; //Close the output stream. m_of.close(); return TRUE; }
void MaxAWDExporter::ProcessGeoBlocks() { AWDTriGeom *geoBlock; AWDBlockIterator *it; int proccessed=0; it = new AWDBlockIterator(awd->get_mesh_data_blocks()); UpdateProgressBar(MAXAWD_PHASE_PROCESS_GEOMETRY, (double)proccessed/(double)awd->get_mesh_data_blocks()->get_num_blocks()); INodeTab lNodes; while ((geoBlock = (AWDTriGeom * ) it->next()) != NULL){ INode * node = (INode *)INodeToGeoBlockCache->Get(geoBlock); if (node==NULL){ AWDMessageBlock * newWarning = new AWDMessageBlock(geoBlock->get_name(), "ERROR: Could not find the INode for this AWDGeometry."); awd->get_message_blocks()->append(newWarning); return; } lNodes.AppendNode( node ); } IGameScene* _pIgame = NULL; _pIgame = GetIGameInterface(); _pIgame->InitialiseIGame( lNodes ); it->reset(); while ((geoBlock = (AWDTriGeom * ) it->next()) != NULL){ INode * node = (INode *)INodeToGeoBlockCache->Get(geoBlock); if (node==NULL){ AWDMessageBlock * newWarning = new AWDMessageBlock(geoBlock->get_name(), "ERROR: Could not find the INode for this AWDGeometry."); awd->get_message_blocks()->append(newWarning); } else{ int exportThis=false; IGameObject * gobj = NULL; IGameMesh * igame_mesh = NULL; gobj = GetIGameInterface()->GetIGameNode(node)->GetIGameObject(); if(gobj->GetIGameType()==IGameObject::IGAME_MESH){ igame_mesh = (IGameMesh*)gobj; if (igame_mesh!=NULL){ igame_mesh->InitializeData(); if(igame_mesh->GetNumberOfFaces()>0){ exportThis=true; } } } if (exportThis){ Object *obj; obj = node->GetObjectRef(); int skinIdx; ObjectState os; IDerivedObject *derivedObject = NULL; skinIdx = IndexOfSkinMod(node->GetObjectRef(), &derivedObject); if (skinIdx >= 0) { // Flatten all modifiers up to but not including // the skin modifier. // to do: get the correct time for the neutral-pose os = derivedObject->Eval(0, skinIdx + 1); } else { // Flatten entire modifier stack // to do: get the correct time for the neutral-pose os = node->EvalWorldState(maxInterface->GetTime()); } obj = os.obj; ISkin *skin = NULL; if (derivedObject != NULL && skinIdx >= 0) { Modifier *mod = derivedObject->GetModifier(skinIdx); skin = (ISkin *)mod->GetInterface(I_SKIN); } ExportTriGeom(geoBlock,obj,node,skin, igame_mesh); RETURN_IF_ERROR; } } proccessed++; UpdateProgressBar(MAXAWD_PHASE_PROCESS_GEOMETRY, (double)proccessed/(double)awd->get_mesh_data_blocks()->get_num_blocks()); } delete it; _pIgame->ReleaseIGame(); }
bool MeshXMLExporter::Export(OutputMap& output) { try { // write XML to a strstream std::stringstream of; while (!m_submeshNames.empty()) m_submeshNames.pop(); if (m_pGame) { m_pGame->ReleaseIGame(); m_pGame = 0; } m_ei->theScene->EnumTree(this); m_pGame = GetIGameInterface(); IGameConversionManager* cm = GetConversionManager(); cm->SetCoordSystem(IGameConversionManager::IGAME_OGL); m_pGame->InitialiseIGame(m_nodeTab, false); m_pGame->SetStaticFrame(0); int nodeCount = m_pGame->GetTopLevelNodeCount(); if (nodeCount == 0) { MessageBox(GetActiveWindow(), "No nodes available to export, aborting...", "Nothing To Export", MB_ICONINFORMATION); m_pGame->ReleaseIGame(); return false; } // if we are writing everything to one file, use the name provided when the user first started the export; // otherwise, create filenames on the basis of the node (submesh) names std::string fileName; IGameNode* node = m_pGame->GetTopLevelNode(0); if (!m_config.getExportMultipleFiles()) fileName = m_config.getExportFilename(); else { fileName = m_config.getExportPath() + "\\"; fileName += node->GetName(); fileName += ".mesh.xml"; } // write start of XML data streamFileHeader(of); int nodeIdx = 0; std::map<std::string, std::string> materialScripts; while (nodeIdx < nodeCount) { std::string mtlName; IGameNode* node = m_pGame->GetTopLevelNode(nodeIdx); IGameObject* obj = node->GetIGameObject(); // InitializeData() is important -- it performs all of the WSM/time eval for us; no data without it obj->InitializeData(); IGameMaterial* mtl = node->GetNodeMaterial(); if (mtl == NULL) mtlName = m_config.getDefaultMaterialName(); else mtlName = mtl->GetMaterialName(); // clean out any spaces the user left in their material name std::string::size_type pos; while ((pos = mtlName.find_first_of(' ')) != std::string::npos) mtlName.replace(pos, 1, _T("_")); if (materialScripts.find(mtlName) == materialScripts.end()) { // export new material script MaterialExporter mexp(m_config, m_materialMap); std::string script; mexp.buildMaterial(mtl, mtlName, script); materialScripts[mtlName] = script; } //if (streamSubmesh(of, node, mtlName)) if (streamSubmesh(of, obj, mtlName)) m_submeshNames.push(std::string(node->GetName())); node->ReleaseIGameObject(); nodeIdx++; if (m_config.getExportMultipleFiles() || nodeIdx == nodeCount) { // write end of this file's XML streamFileFooter(of); // insert new filename --> stream pair into output map output[fileName] = std::string(of.str()); of.str(""); if (nodeIdx != nodeCount) { fileName = m_config.getExportPath() + "\\"; node = m_pGame->GetTopLevelNode(nodeIdx); fileName += node->GetName(); fileName += ".mesh.xml"; // start over again with new data streamFileHeader(of); } } } m_pGame->ReleaseIGame(); // export materials if we are writing those if (m_config.getExportMaterial()) { std::ofstream materialFile; materialFile.open((m_config.getExportPath() + "\\" + m_config.getMaterialFilename()).c_str(), std::ios::out); if (materialFile.is_open()) { for (std::map<std::string, std::string>::iterator it = materialScripts.begin(); it != materialScripts.end(); ++it) { materialFile << it->second; } materialFile.close(); } } return true; } catch (...) { MessageBox(GetActiveWindow(), "An unexpected error has occurred while trying to export, aborting", "Error", MB_ICONEXCLAMATION); if (m_pGame) m_pGame->ReleaseIGame(); return false; } }
CModelExporter::CModelExporter() { m_pIGameScene = GetIGameInterface(); m_pIGameScene ->InitialiseIGame(); }