選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

172 行
5.2 KiB

  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file Export.cpp
  35. * @brief Implementation of the 'assimp export' utility
  36. */
  37. #include "Main.h"
  38. #ifndef ASSIMP_BUILD_NO_EXPORT
  39. const char* AICMD_MSG_EXPORT_HELP_E =
  40. "assimp export <model> [<out>] [-f<h>] [common parameters]\n"
  41. "\t -f<h> Specify the file format. If omitted, the output format is \n"
  42. "\t\tderived from the file extension of the given output file \n"
  43. "\t[See the assimp_cmd docs for a full list of all common parameters] \n"
  44. ;
  45. // -----------------------------------------------------------------------------------
  46. size_t GetMatchingFormat(const std::string& outf,bool byext=false)
  47. {
  48. for(size_t i = 0, end = globalExporter->GetExportFormatCount(); i < end; ++i) {
  49. const aiExportFormatDesc* const e = globalExporter->GetExportFormatDescription(i);
  50. if (outf == (byext ? e->fileExtension : e->id)) {
  51. return i;
  52. }
  53. }
  54. return SIZE_MAX;
  55. }
  56. // -----------------------------------------------------------------------------------
  57. int Assimp_Export(const char* const* params, unsigned int num)
  58. {
  59. const char* const invalid = "assimp export: Invalid number of arguments. See \'assimp export --help\'\n";
  60. if (num < 1) {
  61. printf(invalid);
  62. return 1;
  63. }
  64. // --help
  65. if (!strcmp( params[0], "-h") || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) {
  66. printf("%s",AICMD_MSG_EXPORT_HELP_E);
  67. return 0;
  68. }
  69. std::string in = std::string(params[0]);
  70. std::string out = (num > 1 ? std::string(params[1]) : "-"), outext;
  71. //
  72. const std::string::size_type s = out.find_last_of('.');
  73. if (s != std::string::npos) {
  74. outext = out.substr(s+1);
  75. out = out.substr(0,s);
  76. }
  77. // get import flags
  78. ImportData import;
  79. ProcessStandardArguments(import,params+1,num-1);
  80. // process other flags
  81. std::string outf = "";
  82. for (unsigned int i = (out[0] == '-' ? 1 : 2); i < num;++i) {
  83. if (!params[i]) {
  84. continue;
  85. }
  86. if (!strncmp( params[i], "-f",2)) {
  87. outf = std::string(params[i]+2);
  88. }
  89. else if ( !strncmp( params[i], "--format=",9)) {
  90. outf = std::string(params[i]+9);
  91. }
  92. }
  93. std::transform(outf.begin(),outf.end(),outf.begin(),::tolower);
  94. // convert the output format to a format id
  95. size_t outfi = GetMatchingFormat(outf);
  96. if (outfi == SIZE_MAX) {
  97. if (outf.length()) {
  98. printf("assimp export: warning, format id \'%s\' is unknown\n",outf.c_str());
  99. }
  100. // retry to see if we know it as file extension
  101. outfi = GetMatchingFormat(outf,true);
  102. if (outfi == SIZE_MAX) {
  103. // retry to see if we know the file extension of the output file
  104. outfi = GetMatchingFormat(outext,true);
  105. if (outfi == SIZE_MAX) {
  106. // still no match -> failure
  107. printf("assimp export: no output format specified and I failed to guess it\n");
  108. return -23;
  109. }
  110. }
  111. else {
  112. outext = outf;
  113. }
  114. }
  115. // if no output file is specified, take the file name from input file
  116. if (out[0] == '-') {
  117. std::string::size_type s = in.find_last_of('.');
  118. if (s == std::string::npos) {
  119. s = in.length();
  120. }
  121. out = in.substr(0,s);
  122. }
  123. const aiExportFormatDesc* const e = globalExporter->GetExportFormatDescription(outfi);
  124. printf("assimp export: select file format: \'%s\' (%s)\n",e->id,e->description);
  125. // import the model
  126. const aiScene* scene = ImportModel(import,in);
  127. if (!scene) {
  128. return -39;
  129. }
  130. // derive the final file name
  131. out += "."+outext;
  132. // and call the export routine
  133. if(!ExportModel(scene, import, out,e->id)) {
  134. return -25;
  135. }
  136. printf("assimp export: wrote output file: %s\n",out.c_str());
  137. return 0;
  138. }
  139. #endif // no export