/Horde3D/Source/ColladaConverter/main.cpp

https://github.com/mgottschlag/horde3d · C++ · 171 lines · 126 code · 20 blank · 25 comment · 30 complexity · 763b4feaf341461f07a089c5bcd99984 MD5 · raw file

  1. // *************************************************************************************************
  2. //
  3. // Horde3D
  4. // Next-Generation Graphics Engine
  5. // --------------------------------------
  6. // Copyright (C) 2006-2009 Nicolas Schulz
  7. //
  8. //
  9. // This library is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU Lesser General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2.1 of the License, or (at your option) any later version.
  13. //
  14. // This library is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. // Lesser General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU Lesser General Public
  20. // License along with this library; if not, write to the Free Software
  21. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. //
  23. // *************************************************************************************************
  24. #include "daeMain.h"
  25. #include "converter.h"
  26. #include "utPlatform.h"
  27. #ifdef PLATFORM_WIN
  28. # define WIN32_LEAN_AND_MEAN 1
  29. # define NOMINMAX
  30. # include <windows.h>
  31. # include <direct.h>
  32. #else
  33. # include <sys/stat.h>
  34. #endif
  35. using namespace std;
  36. int main( int argc, char **argv )
  37. {
  38. log( "Horde3D Collada Converter" );
  39. log( "Version 1.0.0 Beta3" );
  40. log( "" );
  41. if( argc < 2 )
  42. {
  43. log( "Usage:" );
  44. log( "ColladaConv inputFile [-o outputName] [-s shaderName] [-noopt]" );
  45. log( "" );
  46. log( "inputFile: filename of the COLLADA document" );
  47. log( "-o outputName: name of the output files (without extension)" );
  48. log( "-s shaderName: filename of the default shader for materials" );
  49. log( "-noopt: disable geometry optimization" );
  50. log( "-anim: export animations only" );
  51. log( "-lodDist1: distance for LOD1" );
  52. log( "-lodDist2: distance for LOD2" );
  53. log( "-lodDist3: distance for LOD3" );
  54. log( "-lodDist4: distance for LOD4" );
  55. return 0;
  56. }
  57. string inName = argv[1];
  58. string outName = extractFileName( inName, false );
  59. bool optimize = true, animsOnly = false;
  60. float lodDists[4] = { 10, 20, 40, 80 };
  61. for( int i = 2; i < argc; ++i )
  62. {
  63. if( strcmp( argv[i], "-o" ) == 0 )
  64. {
  65. if( argc > i + 1 )
  66. {
  67. outName = argv[++i];
  68. }
  69. else
  70. {
  71. log( "Invalid argument" );
  72. return 0;
  73. }
  74. }
  75. else if( strcmp( argv[i], "-noopt" ) == 0 )
  76. {
  77. optimize = false;
  78. }
  79. else if( strcmp( argv[i], "-anim" ) == 0 )
  80. {
  81. animsOnly = true;
  82. }
  83. else if( strcmp( argv[i], "-lodDist1" ) == 0 ||
  84. strcmp( argv[i], "-lodDist2" ) == 0 ||
  85. strcmp( argv[i], "-lodDist3" ) == 0 ||
  86. strcmp( argv[i], "-lodDist4" ) == 0 )
  87. {
  88. if( argc > i + 1 )
  89. {
  90. int index = 0;
  91. if( strcmp( argv[i], "-lodDist2" ) == 0 ) index = 1;
  92. else if( strcmp( argv[i], "-lodDist3" ) == 0 ) index = 2;
  93. else if( strcmp( argv[i], "-lodDist4" ) == 0 ) index = 3;
  94. lodDists[index] = (float)atof( argv[++i] );
  95. }
  96. else
  97. {
  98. log( "Invalid argument" );
  99. return 0;
  100. }
  101. }
  102. else
  103. {
  104. log( "Invalid argument" );
  105. return 0;
  106. }
  107. }
  108. ColladaDocument *colladaFile = new ColladaDocument();
  109. log( "Parsing collada file " + inName + "..." );
  110. if( !colladaFile->parseFile( inName ) )
  111. {
  112. return 0;
  113. }
  114. else
  115. {
  116. log( "Done." );
  117. }
  118. // Set output directory (needed when using drag&drop of input file on application)
  119. #ifdef PLATFORM_WIN
  120. SetCurrentDirectory( extractFilePath( inName ).c_str() );
  121. #endif
  122. // Convert
  123. log( "Converting data for model " + outName + "..." );
  124. if( !optimize ) log( "Geometry optimization disabled" );
  125. Converter *converter = new Converter( lodDists );
  126. converter->convertModel( *colladaFile, optimize );
  127. log( "Done." );
  128. _mkdir( "animations" );
  129. _mkdir( "models" );
  130. _mkdir( ("models/" + outName).c_str() );
  131. if( !animsOnly )
  132. {
  133. log( "Writing geometry..." );
  134. converter->saveModel( outName );
  135. log( "Done." );
  136. log( "Writing materials..." );
  137. converter->writeMaterials( *colladaFile, outName );
  138. log( "Done." );
  139. }
  140. if( converter->hasAnimation() )
  141. {
  142. log( "Writing animation..." );
  143. converter->writeAnimation( outName );
  144. log( "Done." );
  145. }
  146. log( "" );
  147. log( "Finished conversion." );
  148. delete colladaFile; colladaFile = 0x0;
  149. delete converter; converter = 0x0;
  150. return 1;
  151. }