int main(int argc, const char* argv[]) { if(argc < 3) { printf("[Importer] - too few arguments.\n"); PrintHelp(); return 0; } printf("[Importer] starting..."); std::string filename(argv[1]); const char* inputFile = argv[argc - 2]; const char* outputFile = argv[argc - 1]; //Model model; //std::vector<std::string> textureNames; printf("Importing model..."); ImportModel(inputFile, outputFile); printf("[Importer] finished."); printf("Press any key to exit."); while(!_kbhit()) { } return 0; }
void CInv3DDoc::OnModelDefine() { CDlgDefineModel dlg; dlg.m_pInvFcs = &m_inv; dlg.DoModal(); if( m_inv.IsForwardModel() ) { ImportModel(m_inv.GetFilePathFrwInv(), FALSE); m_grdFld.Close(); int row, col, nx, ny, nz; double x0, y0, xSize, ySize, tmp; m_inv.GetModelPtsNum(col, row); m_inv.GetModelSize(nx, ny, nz); m_inv.GetCellSize(xSize, ySize, tmp); xSize = xSize*(nx)/(double)(col-1); ySize = ySize*(ny)/(double)(row-1); m_inv.GetOrigo(x0, y0); m_grdFld.New(row, col, x0, y0, xSize, ySize); m_inv.FldToGrd(m_grdFld.GetData()); m_grdFld.UpdateMinMaxValue(); } UpdateAllViews(NULL, UPDATE_MODEL_NEW); }
bool ModelImporter::Import() { String modelAssetFilename = asset_->GetPath(); importNode_ = new Node(context_); // skip external animations, they will be brought in when importing their // corresponding model if (!modelAssetFilename.Contains("@")) { ImportModel(); if (importAnimations_) { ImportAnimations(); } } File outFile(context_); if (!outFile.Open(asset_->GetCachePath(), FILE_WRITE)) ErrorExit("Could not open output file " + asset_->GetCachePath()); importNode_->SaveXML(outFile); importNode_ = 0; return true; }
void CInv3DDoc::OnModelImportAppend() { CFileDialog fileDlg (TRUE, _T(""), _T("*.*"), OFN_HIDEREADONLY, _T("")); OPENFILENAME& ofn = fileDlg.GetOFN(); CString strDlg("Append model"); ofn.lpstrTitle = strDlg; if( fileDlg.DoModal() == IDOK ) { CString strFilePath = fileDlg.GetPathName(); ImportModel(strFilePath, TRUE); } }
void CInv3DDoc::OnModelInvert() { CDlgInvert dlg; dlg.m_pInvFcs = &m_inv; dlg.DoModal(); if( m_inv.IsForwardModel() ) { if(m_nModels>1) DeleteModels(1, m_nModels-1); ImportModel(m_inv.GetFilePathInv(), TRUE); } }
T* GameResources::AddMapObject(T** &mapObjects, int &mapObjectsCount, char* tableName, char* modelPath) { char path[256]; char query[256]; sprintf(query, "SELECT * FROM `%s` WHERE id=%d", tableName, sqlite3_last_insert_rowid(Game::instance->db)); SqliteResult sqliteResult = SqliteGetRows(Game::instance->db, query)[0]; //Warning! 'Double' model files in 'path' (e. g. if we put *.3ds after *.md2 that loaded with an editor) can cause 'any model loading' (e. g. *.3ds instead of *.md2, that we loaded earlier in editor) sprintf(path, "editor/%s/model/%s", Game::instance->name, tableName); ImportModel(modelPath, path, sqliteResult.integers["id"]); T* mapObject = new T(sqliteResult, path); SpawnMapObject<T>(mapObjects, mapObjectsCount, mapObject); return mapObject; }
// ----------------------------------------------------------------------------------- // Implementation of the assimp extract utility int Assimp_Extract (const char* const* params, unsigned int num) { const char* const invalid = "assimp extract: Invalid number of arguments. See \'assimp extract --help\'\n"; if (num < 1) { printf(invalid); return 1; } // --help if (!strcmp( params[0], "-h") || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) { printf("%s",AICMD_MSG_DUMP_HELP_E); return 0; } // asssimp extract in out [options] if (num < 1) { printf(invalid); return 1; } std::string in = std::string(params[0]); std::string out = (num > 1 ? std::string(params[1]) : "-"); // get import flags ImportData import; ProcessStandardArguments(import,params+1,num-1); bool nosuffix = false; unsigned int texIdx = 0xffffffff, flags = 0; // process other flags std::string extension = "bmp"; for (unsigned int i = (out[0] == '-' ? 1 : 2); i < num;++i) { if (!params[i]) { continue; } if (!strncmp( params[i], "-f",2)) { extension = std::string(params[i]+2); } else if ( !strncmp( params[i], "--format=",9)) { extension = std::string(params[i]+9); } else if ( !strcmp( params[i], "--nosuffix") || !strcmp(params[i],"-s")) { nosuffix = true; } else if ( !strncmp( params[i], "--texture=",10)) { texIdx = Assimp::strtoul10(params[i]+10); } else if ( !strncmp( params[i], "-t",2)) { texIdx = Assimp::strtoul10(params[i]+2); } else if ( !strcmp( params[i], "-ba") || !strcmp( params[i], "--bmp-with-alpha")) { flags |= AI_EXTRACT_WRITE_BMP_ALPHA; } #if 0 else { printf("Unknown parameter: %s\n",params[i]); return 10; } #endif } std::transform(extension.begin(),extension.end(),extension.begin(),::tolower); if (out[0] == '-') { // take file name from input file std::string::size_type s = in.find_last_of('.'); if (s == std::string::npos) s = in.length(); out = in.substr(0,s); } // take file extension from file name, if given std::string::size_type s = out.find_last_of('.'); if (s != std::string::npos) { extension = out.substr(s+1,in.length()-(s+1)); out = out.substr(0,s); } // import the main model const aiScene* scene = ImportModel(import,in); if (!scene) { printf("assimp extract: Unable to load input file %s\n",in.c_str()); return 5; } // get the texture(s) to be exported if (texIdx != 0xffffffff) { // check whether the requested texture is existing if (texIdx >= scene->mNumTextures) { ::printf("assimp extract: Texture %i requested, but there are just %i textures\n", texIdx, scene->mNumTextures); return 6; } } else { ::printf("assimp extract: Exporting %i textures\n",scene->mNumTextures); } // now write all output textures for (unsigned int i = 0; i < scene->mNumTextures;++i) { if (texIdx != 0xffffffff && texIdx != i) { continue; } const aiTexture* tex = scene->mTextures[i]; std::string out_cpy = out, out_ext = extension; // append suffix if necessary - always if all textures are exported if (!nosuffix || (texIdx == 0xffffffff)) { out_cpy.append ("_img"); char tmp[10]; Assimp::ASSIMP_itoa10(tmp,i); out_cpy.append(std::string(tmp)); } // if the texture is a compressed one, we'll export // it to its native file format if (!tex->mHeight) { printf("assimp extract: Texture %i is compressed (%s). Writing native file format.\n", i,tex->achFormatHint); // modify file extension out_ext = std::string(tex->achFormatHint); } out_cpy.append("."+out_ext); // open output file FILE* p = ::fopen(out_cpy.c_str(),"wb"); if (!p) { printf("assimp extract: Unable to open output file %s\n",out_cpy.c_str()); return 7; } int m; if (!tex->mHeight) { m = (1 != fwrite(tex->pcData,tex->mWidth,1,p)); } else m = DoExport(tex,p,extension,flags); ::fclose(p); printf("assimp extract: Wrote texture %i to %s\n",i, out_cpy.c_str()); if (texIdx != 0xffffffff) return m; } return 0; }
bool ModelImporter::Import() { String ext = asset_->GetExtension(); String modelAssetFilename = asset_->GetPath(); importNode_ = new Node(context_); if (ext == ".mdl") { FileSystem* fs = GetSubsystem<FileSystem>(); ResourceCache* cache = GetSubsystem<ResourceCache>(); // mdl files are native file format that doesn't need to be converted // doesn't allow scale, animations legacy primarily for ToonTown if (!fs->Copy(asset_->GetPath(), asset_->GetCachePath() + ".mdl")) { importNode_= 0; return false; } Model* mdl = cache->GetResource<Model>( asset_->GetCachePath() + ".mdl"); if (!mdl) { importNode_= 0; return false; } // Force a reload, though file watchers will catch this delayed and load again cache->ReloadResource(mdl); importNode_->CreateComponent<StaticModel>()->SetModel(mdl); } else { // skip external animations, they will be brought in when importing their // corresponding model if (!modelAssetFilename.Contains("@")) { ImportModel(); if (importAnimations_) { ImportAnimations(); } AnimatedModel* animatedModel = importNode_->GetComponent<AnimatedModel>(); if (animatedModel) { Model* model = animatedModel->GetModel(); if (model && model->GetAnimationCount()) { // resave with animation info File mdlFile(context_); if (!mdlFile.Open(asset_->GetCachePath() + ".mdl", FILE_WRITE)) { ErrorExit("Could not open output file " + asset_->GetCachePath() + ".mdl"); return false; } model->Save(mdlFile); } } } } File outFile(context_); if (!outFile.Open(asset_->GetCachePath(), FILE_WRITE)) ErrorExit("Could not open output file " + asset_->GetCachePath()); importNode_->SaveXML(outFile); importNode_ = 0; return true; }
// ----------------------------------------------------------------------------------- // Implementation of the assimp info utility to print basic file info int Assimp_Info (const char* const* params, unsigned int num) { if (num < 1) { printf("assimp info: Invalid number of arguments. " "See \'assimp info --help\'\n"); return 1; } // --help if (!strcmp( params[0],"-h")||!strcmp( params[0],"--help")||!strcmp( params[0],"-?") ) { printf("%s",AICMD_MSG_INFO_HELP_E); return 0; } // asssimp info <file> [-r] if (num < 1) { printf("assimp info: Invalid number of arguments. " "See \'assimp info --help\'\n"); return 1; } const std::string in = std::string(params[0]); // do maximum post-processing unless -r was specified ImportData import; import.ppFlags = num>1&&(!strcmp(params[1],"--raw")||!strcmp(params[1],"-r")) ? 0 : aiProcessPreset_TargetRealtime_MaxQuality; // import the main model import.log = true; import.showLog = true; const aiScene* scene = ImportModel(import,in); if (!scene) { printf("assimp info: Unable to load input file %s\n", in.c_str()); return 5; } aiMemoryInfo mem; globalImporter->GetMemoryRequirements(mem); static const char* format_string = "Memory consumption: %i B\n" "Nodes: %i\n" "Maximum depth %i\n" "Meshes: %i\n" "Animations: %i\n" "Textures (embed.): %i\n" "Materials: %i\n" "Cameras: %i\n" "Lights: %i\n" "Vertices: %i\n" "Faces: %i\n" "Bones: %i\n" "Animation Channels: %i\n" "Primitive Types: %s\n" "Average faces/mesh %i\n" "Average verts/mesh %i\n" "Minimum point (%f %f %f)\n" "Maximum point (%f %f %f)\n" "Center point (%f %f %f)\n" ; aiVector3D special_points[3]; FindSpecialPoints(scene,special_points); printf(format_string, mem.total, CountNodes(scene->mRootNode), GetMaxDepth(scene->mRootNode), scene->mNumMeshes, scene->mNumAnimations, scene->mNumTextures, scene->mNumMaterials, scene->mNumCameras, scene->mNumLights, CountVertices(scene), CountFaces(scene), CountBones(scene), CountAnimChannels(scene), FindPTypes(scene).c_str(), GetAvgFacePerMesh(scene), GetAvgVertsPerMesh(scene), special_points[0][0],special_points[0][1],special_points[0][2], special_points[1][0],special_points[1][1],special_points[1][2], special_points[2][0],special_points[2][1],special_points[2][2] ) ; unsigned int total=0; for(unsigned int i = 0;i < scene->mNumMaterials; ++i) { aiString name; if (AI_SUCCESS==aiGetMaterialString(scene->mMaterials[i],AI_MATKEY_NAME,&name)) { printf("%s\n \'%s\'",(total++?"":"\nNamed Materials:" ),name.data); } } if(total) { printf("\n"); } total=0; for(unsigned int i = 0;i < scene->mNumMaterials; ++i) { aiString name; static const aiTextureType types[] = { aiTextureType_NONE, aiTextureType_DIFFUSE, aiTextureType_SPECULAR, aiTextureType_AMBIENT, aiTextureType_EMISSIVE, aiTextureType_HEIGHT, aiTextureType_NORMALS, aiTextureType_SHININESS, aiTextureType_OPACITY, aiTextureType_DISPLACEMENT, aiTextureType_LIGHTMAP, aiTextureType_REFLECTION, aiTextureType_UNKNOWN }; for(unsigned int type = 0; type < sizeof(types)/sizeof(types[0]); ++type) { for(unsigned int idx = 0;AI_SUCCESS==aiGetMaterialString(scene->mMaterials[i], AI_MATKEY_TEXTURE(types[type],idx),&name); ++idx) { printf("%s\n \'%s\'",(total++?"":"\nTexture Refs:" ),name.data); } } } if(total) { printf("\n"); } total=0; for(unsigned int i = 0;i < scene->mNumAnimations; ++i) { if (scene->mAnimations[i]->mName.length) { printf("%s\n \'%s\'",(total++?"":"\nNamed Animations:" ),scene->mAnimations[i]->mName.data); } } if(total) { printf("\n"); } printf("\nNode hierarchy:\n"); unsigned int cline=0; PrintHierarchy(scene->mRootNode,20,1000,cline); printf("\n"); return 0; }
// ----------------------------------------------------------------------------------- int Assimp_Dump (const char* const* params, unsigned int num) { const char* fail = "assimp dump: Invalid number of arguments. " "See \'assimp dump --help\'\r\n"; if (num < 1) { printf(fail); return 1; } // --help if (!strcmp( params[0], "-h") || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) { printf("%s",AICMD_MSG_DUMP_HELP); return 0; } // asssimp dump in out [options] if (num < 1) { printf(fail); return 1; } std::string in = std::string(params[0]); std::string out = (num > 1 ? std::string(params[1]) : std::string("-")); // store full command line std::string cmd; for (unsigned int i = (out[0] == '-' ? 1 : 2); i < num;++i) { if (!params[i])continue; cmd.append(params[i]); cmd.append(" "); } // get import flags ImportData import; ProcessStandardArguments(import,params+1,num-1); bool binary = false, shortened = false,compressed=false; // process other flags for (unsigned int i = 1; i < num;++i) { if (!params[i])continue; if (!strcmp( params[i], "-b") || !strcmp( params[i], "--binary")) { binary = true; } else if (!strcmp( params[i], "-s") || !strcmp( params[i], "--short")) { shortened = true; } else if (!strcmp( params[i], "-z") || !strcmp( params[i], "--compressed")) { compressed = true; } #if 0 else if (i > 2 || params[i][0] == '-') { ::printf("Unknown parameter: %s\n",params[i]); return 10; } #endif } if (out[0] == '-') { // take file name from input file std::string::size_type s = in.find_last_of('.'); if (s == std::string::npos) { s = in.length(); } out = in.substr(0,s); out.append((binary ? ".assbin" : ".assxml")); if (shortened && binary) { out.append(".regress"); } } // import the main model const aiScene* scene = ImportModel(import,in); if (!scene) { printf("assimp dump: Unable to load input file %s\n",in.c_str()); return 5; } // open the output file and build the dump FILE* o = ::fopen(out.c_str(),(binary ? "wb" : "wt")); if (!o) { printf("assimp dump: Unable to open output file %s\n",out.c_str()); return 12; } if (binary) { WriteBinaryDump (scene,o,in.c_str(),cmd.c_str(),shortened,compressed,import); } else WriteDump (scene,o,in.c_str(),cmd.c_str(),shortened); fclose(o); if (compressed && binary) { CompressBinaryDump(out.c_str(),ASSBIN_HEADER_LENGTH); } printf("assimp dump: Wrote output dump %s\n",out.c_str()); return 0; }