Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
vlxtool.cpp
Go to the documentation of this file.
1 
2 
3 #include <cstdio>
4 #include <cstdlib>
5 #include <string.h>
6 #include <string>
7 #include <vector>
9 #include <vlCore/Time.hpp>
11 #include <vlX/ioVLX.hpp>
13 
14 using namespace vl;
15 
16 void printHelp()
17 {
18  printf("\nusage:\n");
19  printf(" vlxtool -in file1 file file3 ... -out file_out\n");
20  printf("\nexamples:\n");
21  printf(" > vlxtool -in file1.obj file2.3ds file3.vlb -out file_out.vlt\n");
22  printf(" Merges the contents of file1.obj, file2.3ds and file3.vlb into file_out.vlt:\n\n");
23  printf(" > vlxtool -in file.vlt -out file.vlb\n");
24  printf(" Converts a VLT file to its VLB representation:\n\n");
25  printf(" > vlxtool -in file.vlb -out file.vlt\n");
26  printf(" Converts a VLB file to its VLT representation:\n\n");
27 }
28 
29 int main(int argc, const char* argv[])
30 {
32 
33  printf("vlxtool 1.0 - Visualization Library VLX Utility\n");
34  printf("Converts any type of resource to .vlt/.vlb\n\n");
35 
36  std::vector<std::string> in_files;
37  String out_file;
38 
39  bool input = false;
40  bool output = false;
41 
42  for(int i=1; i<argc; ++i)
43  {
44  if ( strcmp(argv[i], "-in") == 0)
45  {
46  input = true;
47  output = false;
48  }
49  else
50  if ( strcmp(argv[i], "-out") == 0)
51  {
52  input = false;
53  output = true;
54  }
55  else
56  if (input)
57  {
58  in_files.push_back(argv[i]);
59  }
60  else
61  if (output)
62  {
63  if (out_file.empty())
64  out_file = argv[i];
65  else
66  {
67  printf("too many output files.\n");
68  return 1;
69  }
70  }
71  else
72  {
73  printf("Unknown option:'%s'\n", argv[i]);
74  printHelp();
75  return 1;
76  }
77  }
78 
79  if (in_files.empty() || out_file.empty())
80  {
81  if (in_files.empty())
82  printf("Missing input file list.\n");
83 
84  if (out_file.empty())
85  printf("Missing output file.\n");
86 
87  printHelp();
88  return 1;
89  }
90 
91  printf("Loading...\n");
93  for(size_t i=0; i<in_files.size(); ++i)
94  {
95  Time timer; timer.start();
96  printf("\t%s ", in_files[i].c_str());
97  ref<ResourceDatabase> res = vl::loadResource(in_files[i].c_str(), true);
98  if (res)
99  {
100  printf("\t... %.2fs\n", timer.elapsed());
101  db->resources().insert(db->resources().end(), res->resources().begin(), res->resources().end());
102  }
103  else
104  {
105  printf("\t... FAILED\n");
106  return 1;
107  }
108  }
109 
111 
112  Time timer; timer.start();
113  if (out_file.endsWith(".vlt"))
114  {
115  printf("Saving VLT...\n");
116  printf("\t%s ", out_file.toStdString().c_str());
117  vlX::saveVLT(out_file, db.get());
118  printf("\t... %.2fs\n", timer.elapsed());
119  }
120  else
121  if (out_file.endsWith(".vlb"))
122  {
123  printf("Saving VLB...\n");
124  printf("\t%s ", out_file.toStdString().c_str());
125  vlX::saveVLB(out_file, db.get());
126  printf("\t... %.2fs\n", timer.elapsed());
127  }
128  else
129  {
130  printf("FAILED: output file must be either a .vlt or .vlb\n");
131  return 1;
132  }
133 
134  return 0;
135 }
VLX_EXPORT bool saveVLT(vl::VirtualFile *file, const vl::ResourceDatabase *)
Definition: ioVLX.cpp:90
void start(int index=0)
Definition: Time.hpp:76
real elapsed(int index=0) const
Definition: Time.hpp:82
int main(int argc, const char *argv[])
Definition: vlxtool.cpp:29
const T * get() const
Definition: Object.hpp:128
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
VLCORE_EXPORT ref< ResourceDatabase > loadResource(const String &path, bool quick=true)
Short version of defLoadWriterManager()->loadResource(path, quick).
Visualization Library main namespace.
VLGRAPHICS_EXPORT void expandResourceDatabase(ResourceDatabase *db)
Extracts and sorts Shaders, Effects, Renderables, RenderStates, Transforms etc. from their parent obj...
static VLMAIN_EXPORT void init(bool log_info=true)
Initializes VLCore and VLGraphics libraries.
Simple class to be used as a timer and to retrieve the current time and date.
Definition: Time.hpp:49
const std::vector< ref< Object > > & resources() const
bool empty() const
Returns true if length() == 0.
Definition: String.hpp:136
void printHelp()
Definition: vlxtool.cpp:16
VLX_EXPORT bool saveVLB(vl::VirtualFile *file, const vl::ResourceDatabase *)
Definition: ioVLX.cpp:111
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
std::string toStdString() const
Returns a UTF8 encoded std::string.
Definition: String.cpp:1156
bool endsWith(const String &str) const
Returns true if a String ends with the specified String str.
Definition: String.cpp:705
The ResourceDatabase class contains and manipulates a set of resources.