Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]

X:/dropbox/visualizationlibrary/src/tools/vlxtool.cpp

Go to the documentation of this file.
00001 
00002 
00003 #include <cstdio>
00004 #include <cstdlib>
00005 #include <string.h>
00006 #include <string>
00007 #include <vector>
00008 #include <vlCore/VisualizationLibrary.hpp>
00009 #include <vlCore/Time.hpp>
00010 #include <vlCore/ResourceDatabase.hpp>
00011 #include <vlGraphics/plugins/ioVLX.hpp>
00012 #include <vlGraphics/expandResourceDatabase.hpp>
00013 
00014 using namespace vl;
00015 
00016 void printHelp()
00017 {
00018   printf("\nusage:\n");
00019   printf("  vlxtool -in file1 file file3 ... -out file_out\n");
00020   printf("\nexamples:\n");
00021   printf("  >  vlxtool -in file1.obj file2.3ds file3.vlb -out file_out.vlt\n");
00022   printf("     Merges the contents of file1.obj, file2.3ds and file3.vlb into file_out.vlt:\n\n");
00023   printf("  >  vlxtool -in file.vlt -out file.vlb\n");
00024   printf("     Converts a VLT file to its VLB representation:\n\n");
00025   printf("  >  vlxtool -in file.vlb -out file.vlt\n");
00026   printf("     Converts a VLB file to its VLT representation:\n\n");
00027 }
00028 
00029 int main(int argc, const char* argv[])
00030 {
00031   VisualizationLibrary::init(true);
00032 
00033   printf("vlxtool 1.0 - Visualization Library VLX Utility\n");
00034   printf("Converts any type of resource to .vlt/.vlb\n\n");
00035 
00036   std::vector<std::string> in_files;
00037   String out_file;
00038 
00039   bool input = false;
00040   bool output = false;
00041 
00042   for(int i=1; i<argc; ++i)
00043   {
00044     if ( strcmp(argv[i], "-in") == 0)
00045     {
00046       input = true;
00047       output = false;
00048     }
00049     else
00050     if ( strcmp(argv[i], "-out") == 0)
00051     {
00052       input = false;
00053       output = true;
00054     }
00055     else
00056     if (input)
00057     {
00058       in_files.push_back(argv[i]);
00059     }
00060     else
00061     if (output)
00062     {
00063       if (out_file.empty())
00064         out_file = argv[i];
00065       else
00066       {
00067         printf("too many output files.\n");
00068         return 1;
00069       }
00070     }
00071     else
00072     {
00073       printf("Unknown option:'%s'\n", argv[i]);
00074       printHelp();
00075       return 1;
00076     }
00077   }
00078 
00079   if (in_files.empty() || out_file.empty())
00080   {
00081     if (in_files.empty())
00082       printf("Missing input file list.\n");
00083     
00084     if (out_file.empty())
00085       printf("Missing output file.\n");
00086 
00087     printHelp();
00088     return 1;
00089   }
00090 
00091   printf("Loading...\n");
00092   ref<ResourceDatabase> db = new ResourceDatabase;
00093   for(size_t i=0; i<in_files.size(); ++i)
00094   {
00095     Time timer; timer.start();
00096     printf("\t%s ", in_files[i].c_str());
00097     ref<ResourceDatabase> res = vl::loadResource(in_files[i].c_str(), true);
00098     if (res)
00099     {
00100       printf("\t... %.2fs\n", timer.elapsed());
00101       db->resources().insert(db->resources().end(), res->resources().begin(), res->resources().end());
00102     }
00103     else
00104     {
00105       printf("\t... FAILED\n");
00106       return 1;
00107     }
00108   }
00109 
00110   expandResourceDatabase(db.get());
00111 
00112   Time timer; timer.start();
00113   if (out_file.endsWith(".vlt"))
00114   {
00115     printf("Saving VLT...\n");
00116     printf("\t%s ", out_file.toStdString().c_str());
00117     vl::saveVLT(out_file, db.get());
00118     printf("\t... %.2fs\n", timer.elapsed());
00119   }
00120   else
00121   if (out_file.endsWith(".vlb"))
00122   {
00123     printf("Saving VLB...\n");
00124     printf("\t%s ", out_file.toStdString().c_str());
00125     vl::saveVLB(out_file, db.get());
00126     printf("\t... %.2fs\n", timer.elapsed());
00127   }
00128   else
00129   {
00130     printf("FAILED: output file must be either a .vlt or .vlb\n");
00131     return 1;
00132   }
00133 
00134   return 0;
00135 }

Visualization Library 2011.09.1160 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 2 2013 13:40:28.
Permission is granted to use this page to write and publish articles regarding Visualization Library.