Merge branch 'pugi_xml' of https://github.com/assimp/assimp into pugi_xml

pull/2966/head
Kim Kulling 2020-02-03 21:19:30 +01:00
commit bd2ffc8d58
68 changed files with 163 additions and 83 deletions

View File

@ -413,7 +413,8 @@ protected:
Write<unsigned int>(&chunk,tex->mWidth); Write<unsigned int>(&chunk,tex->mWidth);
Write<unsigned int>(&chunk,tex->mHeight); Write<unsigned int>(&chunk,tex->mHeight);
chunk.Write( tex->achFormatHint, sizeof(char), 4 ); // Write the texture format, but don't include the null terminator.
chunk.Write( tex->achFormatHint, sizeof(char), HINTMAXTEXTURELEN - 1 );
if(!shortened) { if(!shortened) {
if (!tex->mHeight) { if (!tex->mHeight) {

View File

@ -535,7 +535,7 @@ void AssbinImporter::ReadBinaryTexture(IOStream * stream, aiTexture* tex) {
tex->mWidth = Read<unsigned int>(stream); tex->mWidth = Read<unsigned int>(stream);
tex->mHeight = Read<unsigned int>(stream); tex->mHeight = Read<unsigned int>(stream);
stream->Read( tex->achFormatHint, sizeof(char), 4 ); stream->Read( tex->achFormatHint, sizeof(char), HINTMAXTEXTURELEN - 1 );
if(!shortened) { if(!shortened) {
if (!tex->mHeight) { if (!tex->mHeight) {

View File

@ -1213,10 +1213,6 @@ SET_TARGET_PROPERTIES( assimp PROPERTIES
) )
if (APPLE) if (APPLE)
SET_TARGET_PROPERTIES( assimp PROPERTIES
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${ASSIMP_LIB_INSTALL_DIR}"
)
if (BUILD_FRAMEWORK) if (BUILD_FRAMEWORK)
SET_TARGET_PROPERTIES( assimp PROPERTIES SET_TARGET_PROPERTIES( assimp PROPERTIES
FRAMEWORK TRUE FRAMEWORK TRUE

View File

@ -182,6 +182,13 @@ void HL1MDLLoader::load_file() {
read_global_info(); read_global_info();
if (!header_->numbodyparts) {
// This could be an MDL external texture file. In this case,
// add this flag to allow the scene to be loaded even if it
// has no meshes.
scene_->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
}
// Append children to root node. // Append children to root node.
if (rootnode_children_.size()) { if (rootnode_children_.size()) {
scene_->mRootNode->addChildren( scene_->mRootNode->addChildren(
@ -218,21 +225,6 @@ void HL1MDLLoader::validate_header(const Header_HL1 *header, bool is_texture_hea
} }
} else { } else {
// Every single Half-Life model is assumed to have at least one bodypart.
if (!header->numbodyparts) {
throw DeadlyImportError(MDL_HALFLIFE_LOG_HEADER "Model has no bodyparts");
}
// Every single Half-Life model is assumed to have at least one bone.
if (!header->numbones) {
throw DeadlyImportError(MDL_HALFLIFE_LOG_HEADER "Model has no bones");
}
// Every single Half-Life model is assumed to have at least one sequence group,
// which is the "default" sequence group.
if (!header->numseqgroups) {
throw DeadlyImportError(MDL_HALFLIFE_LOG_HEADER "Model has no sequence groups");
}
if (header->numbodyparts > AI_MDL_HL1_MAX_BODYPARTS) { if (header->numbodyparts > AI_MDL_HL1_MAX_BODYPARTS) {
log_warning_limit_exceeded<AI_MDL_HL1_MAX_BODYPARTS>(header->numbodyparts, "bodyparts"); log_warning_limit_exceeded<AI_MDL_HL1_MAX_BODYPARTS>(header->numbodyparts, "bodyparts");
@ -381,9 +373,9 @@ void HL1MDLLoader::read_texture(const Texture_HL1 *ptexture,
pResult->mFilename = ptexture->name; pResult->mFilename = ptexture->name;
pResult->mWidth = outwidth; pResult->mWidth = outwidth;
pResult->mHeight = outheight; pResult->mHeight = outheight;
pResult->achFormatHint[0] = 'b'; pResult->achFormatHint[0] = 'r';
pResult->achFormatHint[1] = 'g'; pResult->achFormatHint[1] = 'g';
pResult->achFormatHint[2] = 'r'; pResult->achFormatHint[2] = 'b';
pResult->achFormatHint[3] = 'a'; pResult->achFormatHint[3] = 'a';
pResult->achFormatHint[4] = '8'; pResult->achFormatHint[4] = '8';
pResult->achFormatHint[5] = '8'; pResult->achFormatHint[5] = '8';
@ -498,6 +490,10 @@ void HL1MDLLoader::read_skins() {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void HL1MDLLoader::read_bones() { void HL1MDLLoader::read_bones() {
if (!header_->numbones) {
return;
}
const Bone_HL1 *pbone = (const Bone_HL1 *)((uint8_t *)header_ + header_->boneindex); const Bone_HL1 *pbone = (const Bone_HL1 *)((uint8_t *)header_ + header_->boneindex);
std::vector<std::string> unique_bones_names(header_->numbones); std::vector<std::string> unique_bones_names(header_->numbones);
@ -588,6 +584,9 @@ void HL1MDLLoader::read_bones() {
triangles, respectively (3 indices per face). triangles, respectively (3 indices per face).
*/ */
void HL1MDLLoader::read_meshes() { void HL1MDLLoader::read_meshes() {
if (!header_->numbodyparts) {
return;
}
int total_verts = 0; int total_verts = 0;
int total_triangles = 0; int total_triangles = 0;
@ -964,8 +963,9 @@ void HL1MDLLoader::read_meshes() {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void HL1MDLLoader::read_animations() { void HL1MDLLoader::read_animations() {
if (!header_->numseq) if (!header_->numseq) {
return; return;
}
const SequenceDesc_HL1 *pseqdesc = (const SequenceDesc_HL1 *)((uint8_t *)header_ + header_->seqindex); const SequenceDesc_HL1 *pseqdesc = (const SequenceDesc_HL1 *)((uint8_t *)header_ + header_->seqindex);
const SequenceGroup_HL1 *pseqgroup = nullptr; const SequenceGroup_HL1 *pseqgroup = nullptr;
@ -1067,6 +1067,9 @@ void HL1MDLLoader::read_animations() {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void HL1MDLLoader::read_sequence_groups_info() { void HL1MDLLoader::read_sequence_groups_info() {
if (!header_->numseqgroups) {
return;
}
aiNode *sequence_groups_node = new aiNode(AI_MDL_HL1_NODE_SEQUENCE_GROUPS); aiNode *sequence_groups_node = new aiNode(AI_MDL_HL1_NODE_SEQUENCE_GROUPS);
rootnode_children_.push_back(sequence_groups_node); rootnode_children_.push_back(sequence_groups_node);

View File

@ -798,7 +798,7 @@ void ValidateDSProcess::Validate( const aiTexture* pTexture)
if (!pTexture->mWidth) { if (!pTexture->mWidth) {
ReportError("aiTexture::mWidth is zero (compressed texture)"); ReportError("aiTexture::mWidth is zero (compressed texture)");
} }
if ('\0' != pTexture->achFormatHint[3]) { if ('\0' != pTexture->achFormatHint[HINTMAXTEXTURELEN - 1]) {
ReportWarning("aiTexture::achFormatHint must be zero-terminated"); ReportWarning("aiTexture::achFormatHint must be zero-terminated");
} }
else if ('.' == pTexture->achFormatHint[0]) { else if ('.' == pTexture->achFormatHint[0]) {

View File

@ -207,8 +207,7 @@ struct aiTexture {
, mHeight(0) , mHeight(0)
, pcData(nullptr) , pcData(nullptr)
, mFilename() { , mFilename() {
achFormatHint[0] = achFormatHint[1] = 0; memset(achFormatHint, 0, sizeof(achFormatHint));
achFormatHint[2] = achFormatHint[3] = 0;
} }
// Destruction // Destruction

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 KiB

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 265 KiB

After

Width:  |  Height:  |  Size: 265 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 KiB

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 273 KiB

After

Width:  |  Height:  |  Size: 274 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 KiB

After

Width:  |  Height:  |  Size: 768 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 KiB

After

Width:  |  Height:  |  Size: 228 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 KiB

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 KiB

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 277 KiB

After

Width:  |  Height:  |  Size: 277 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 179 KiB

After

Width:  |  Height:  |  Size: 179 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 610 KiB

After

Width:  |  Height:  |  Size: 610 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 412 KiB

After

Width:  |  Height:  |  Size: 412 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 258 KiB

After

Width:  |  Height:  |  Size: 258 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 315 KiB

After

Width:  |  Height:  |  Size: 315 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 KiB

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 KiB

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 902 KiB

After

Width:  |  Height:  |  Size: 902 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -57,13 +57,24 @@ public:
virtual bool importerTest() { virtual bool importerTest() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(MDL_HL1_FILE_MAN, 0); importerTest_HL1(&importer);
EXPECT_NE(nullptr, scene);
// Add further MDL tests... // Add further MDL tests...
return true; return true;
} }
private:
void importerTest_HL1(Assimp::Importer* const importer) {
const aiScene *scene = importer->ReadFile(MDL_HL1_FILE_MAN, 0);
EXPECT_NE(nullptr, scene);
// Test that the importer can directly load an HL1 MDL external texture file.
scene = importer->ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "manT.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene);
EXPECT_NE(0u, scene->mNumTextures);
EXPECT_NE(0u, scene->mNumMaterials);
}
}; };
TEST_F(utMDLImporter, importMDLFromFileTest) { TEST_F(utMDLImporter, importMDLFromFileTest) {

View File

@ -800,6 +800,10 @@ void CompareOnTheFlyTexture(comparer_context& comp) {
comp.cmp<char>("achFormatHint[1]"); comp.cmp<char>("achFormatHint[1]");
comp.cmp<char>("achFormatHint[2]"); comp.cmp<char>("achFormatHint[2]");
comp.cmp<char>("achFormatHint[3]"); comp.cmp<char>("achFormatHint[3]");
comp.cmp<char>("achFormatHint[4]");
comp.cmp<char>("achFormatHint[5]");
comp.cmp<char>("achFormatHint[6]");
comp.cmp<char>("achFormatHint[7]");
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
@ -881,19 +885,19 @@ int Assimp_CompareDump (const char* const* params, unsigned int num)
// --help // --help
if ((num == 1 && !strcmp( params[0], "-h")) || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) { if ((num == 1 && !strcmp( params[0], "-h")) || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) {
printf("%s",AICMD_MSG_CMPDUMP_HELP); printf("%s",AICMD_MSG_CMPDUMP_HELP);
return 0; return AssimpCmdError::Success;
} }
// assimp cmpdump actual expected // assimp cmpdump actual expected
if (num < 2) { if (num < 2) {
std::cout << "assimp cmpdump: Invalid number of arguments. " std::cout << "assimp cmpdump: Invalid number of arguments. "
"See \'assimp cmpdump --help\'\r\n" << std::endl; "See \'assimp cmpdump --help\'\r\n" << std::endl;
return 1; return AssimpCmdError::InvalidNumberOfArguments;
} }
if(!strcmp(params[0],params[1])) { if(!strcmp(params[0],params[1])) {
std::cout << "assimp cmpdump: same file, same content." << std::endl; std::cout << "assimp cmpdump: same file, same content." << std::endl;
return 0; return AssimpCmdError::Success;
} }
class file_ptr class file_ptr
@ -920,13 +924,13 @@ int Assimp_CompareDump (const char* const* params, unsigned int num)
if (!actual) { if (!actual) {
std::cout << "assimp cmpdump: Failure reading ACTUAL data from " << std::cout << "assimp cmpdump: Failure reading ACTUAL data from " <<
params[0] << std::endl; params[0] << std::endl;
return -5; return AssimpCmdError::FailedToLoadInputFile;
} }
file_ptr expected(fopen(params[1],"rb")); file_ptr expected(fopen(params[1],"rb"));
if (!expected) { if (!expected) {
std::cout << "assimp cmpdump: Failure reading EXPECT data from " << std::cout << "assimp cmpdump: Failure reading EXPECT data from " <<
params[1] << std::endl; params[1] << std::endl;
return -6; return AssimpCmdCompareDumpError::FailedToLoadExpectedInputFile;
} }
comparer_context comp(actual,expected); comparer_context comp(actual,expected);
@ -936,17 +940,17 @@ int Assimp_CompareDump (const char* const* params, unsigned int num)
} }
catch(const compare_fails_exception& ex) { catch(const compare_fails_exception& ex) {
printf("%s",ex.what()); printf("%s",ex.what());
return -1; return AssimpCmdCompareDumpError::FileComparaisonFailure;
} }
catch(...) { catch(...) {
// we don't bother checking too rigourously here, so // we don't bother checking too rigourously here, so
// we might end up here ... // we might end up here ...
std::cout << "Unknown failure, are the input files well-defined?"; std::cout << "Unknown failure, are the input files well-defined?";
return -3; return AssimpCmdCompareDumpError::UnknownFailure;
} }
std::cout << "Success (totally " << std::dec << comp.get_num_chunks() << std::cout << "Success (totally " << std::dec << comp.get_num_chunks() <<
" chunks)" << std::endl; " chunks)" << std::endl;
return 0; return AssimpCmdError::Success;
} }

View File

@ -76,13 +76,13 @@ int Assimp_Export(const char* const* params, unsigned int num)
const char* const invalid = "assimp export: Invalid number of arguments. See \'assimp export --help\'\n"; const char* const invalid = "assimp export: Invalid number of arguments. See \'assimp export --help\'\n";
if (num < 1) { if (num < 1) {
printf(invalid); printf(invalid);
return 1; return AssimpCmdError::InvalidNumberOfArguments;
} }
// --help // --help
if (!strcmp( params[0], "-h") || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) { if (!strcmp( params[0], "-h") || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) {
printf("%s",AICMD_MSG_EXPORT_HELP_E); printf("%s",AICMD_MSG_EXPORT_HELP_E);
return 0; return AssimpCmdError::Success;
} }
std::string in = std::string(params[0]); std::string in = std::string(params[0]);
@ -156,7 +156,7 @@ int Assimp_Export(const char* const* params, unsigned int num)
// import the model // import the model
const aiScene* scene = ImportModel(import,in); const aiScene* scene = ImportModel(import,in);
if (!scene) { if (!scene) {
return -39; return AssimpCmdExportError::FailedToImportModel;
} }
// derive the final file name // derive the final file name
@ -164,10 +164,10 @@ int Assimp_Export(const char* const* params, unsigned int num)
// and call the export routine // and call the export routine
if(!ExportModel(scene, import, out,e->id)) { if(!ExportModel(scene, import, out,e->id)) {
return -25; return AssimpCmdExportError::FailedToExportModel;
} }
printf("assimp export: wrote output file: %s\n",out.c_str()); printf("assimp export: wrote output file: %s\n",out.c_str());
return 0; return AssimpCmdError::Success;
} }
#endif // no export #endif // no export

View File

@ -219,9 +219,9 @@ int DoExport(const aiTexture* tx, FILE* p, const std::string& extension,
} }
else { else {
printf("assimp extract: No available texture encoder found for %s\n", extension.c_str()); printf("assimp extract: No available texture encoder found for %s\n", extension.c_str());
return 1; return AssimpCmdExtractError::NoAvailableTextureEncoderFound;
} }
return 0; return AssimpCmdError::Success;
} }
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------
@ -232,13 +232,13 @@ int Assimp_Extract (const char* const* params, unsigned int num)
// assimp extract in out [options] // assimp extract in out [options]
if (num < 1) { if (num < 1) {
printf(invalid); printf(invalid);
return 1; return AssimpCmdError::InvalidNumberOfArguments;
} }
// --help // --help
if (!strcmp( params[0], "-h") || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) { if (!strcmp( params[0], "-h") || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) {
printf("%s",AICMD_MSG_DUMP_HELP_E); printf("%s",AICMD_MSG_DUMP_HELP_E);
return 0; return AssimpCmdError::Success;
} }
@ -308,7 +308,7 @@ int Assimp_Extract (const char* const* params, unsigned int num)
const aiScene* scene = ImportModel(import,in); const aiScene* scene = ImportModel(import,in);
if (!scene) { if (!scene) {
printf("assimp extract: Unable to load input file %s\n",in.c_str()); printf("assimp extract: Unable to load input file %s\n",in.c_str());
return 5; return AssimpCmdError::FailedToLoadInputFile;
} }
// get the texture(s) to be exported // get the texture(s) to be exported
@ -318,7 +318,7 @@ int Assimp_Extract (const char* const* params, unsigned int num)
if (texIdx >= scene->mNumTextures) { if (texIdx >= scene->mNumTextures) {
::printf("assimp extract: Texture %i requested, but there are just %i textures\n", ::printf("assimp extract: Texture %i requested, but there are just %i textures\n",
texIdx, scene->mNumTextures); texIdx, scene->mNumTextures);
return 6; return AssimpCmdExtractError::TextureIndexIsOutOfRange;
} }
} }
else { else {
@ -358,12 +358,14 @@ int Assimp_Extract (const char* const* params, unsigned int num)
FILE* p = ::fopen(out_cpy.c_str(),"wb"); FILE* p = ::fopen(out_cpy.c_str(),"wb");
if (!p) { if (!p) {
printf("assimp extract: Unable to open output file %s\n",out_cpy.c_str()); printf("assimp extract: Unable to open output file %s\n",out_cpy.c_str());
return 7; return AssimpCmdError::FailedToOpenOutputFile;
} }
int m; int m;
if (!tex->mHeight) { if (!tex->mHeight) {
m = (1 != fwrite(tex->pcData,tex->mWidth,1,p)); m = (1 != fwrite(tex->pcData,tex->mWidth,1,p))
? static_cast<int>(AssimpCmdError::Success)
: static_cast<int>(AssimpCmdExtractError::FailedToExportCompressedTexture);
} }
else m = DoExport(tex,p,extension,flags); else m = DoExport(tex,p,extension,flags);
::fclose(p); ::fclose(p);
@ -372,5 +374,5 @@ int Assimp_Extract (const char* const* params, unsigned int num)
if (texIdx != 0xffffffff) if (texIdx != 0xffffffff)
return m; return m;
} }
return 0; return AssimpCmdError::Success;
} }

View File

@ -283,14 +283,14 @@ int Assimp_Info (const char* const* params, unsigned int num) {
// --help // --help
if (!strcmp( params[0],"-h")||!strcmp( params[0],"--help")||!strcmp( params[0],"-?") ) { if (!strcmp( params[0],"-h")||!strcmp( params[0],"--help")||!strcmp( params[0],"-?") ) {
printf("%s",AICMD_MSG_INFO_HELP_E); printf("%s",AICMD_MSG_INFO_HELP_E);
return 0; return AssimpCmdError::Success;
} }
// asssimp info <file> [-r] // asssimp info <file> [-r]
if (num < 1) { if (num < 1) {
printf("assimp info: Invalid number of arguments. " printf("assimp info: Invalid number of arguments. "
"See \'assimp info --help\'\n"); "See \'assimp info --help\'\n");
return 1; return AssimpCmdError::InvalidNumberOfArguments;
} }
const std::string in = std::string(params[0]); const std::string in = std::string(params[0]);
@ -314,7 +314,7 @@ int Assimp_Info (const char* const* params, unsigned int num) {
// Verbose and silent at the same time are not allowed // Verbose and silent at the same time are not allowed
if ( verbose && silent ) { if ( verbose && silent ) {
printf("assimp info: Invalid arguments, verbose and silent at the same time are forbitten. "); printf("assimp info: Invalid arguments, verbose and silent at the same time are forbitten. ");
return 1; return AssimpCmdInfoError::InvalidCombinaisonOfArguments;
} }
// Parse post-processing flags unless -r was specified // Parse post-processing flags unless -r was specified
@ -333,7 +333,7 @@ int Assimp_Info (const char* const* params, unsigned int num) {
if (!scene) { if (!scene) {
printf("assimp info: Unable to load input file %s\n", printf("assimp info: Unable to load input file %s\n",
in.c_str()); in.c_str());
return 5; return AssimpCmdError::FailedToLoadInputFile;
} }
aiMemoryInfo mem; aiMemoryInfo mem;
@ -391,7 +391,7 @@ int Assimp_Info (const char* const* params, unsigned int num) {
if (silent) if (silent)
{ {
printf("\n"); printf("\n");
return 0; return AssimpCmdError::Success;
} }
// meshes // meshes
@ -473,5 +473,5 @@ int Assimp_Info (const char* const* params, unsigned int num) {
PrintHierarchy(scene->mRootNode,"",verbose); PrintHierarchy(scene->mRootNode,"",verbose);
printf("\n"); printf("\n");
return 0; return AssimpCmdError::Success;
} }

View File

@ -85,7 +85,7 @@ int main (int argc, char* argv[])
{ {
if (argc <= 1) { if (argc <= 1) {
printf("assimp: No command specified. Use \'assimp help\' for a detailed command list\n"); printf("assimp: No command specified. Use \'assimp help\' for a detailed command list\n");
return 0; return AssimpCmdError::Success;
} }
// assimp version // assimp version
@ -102,7 +102,7 @@ int main (int argc, char* argv[])
(flags & ASSIMP_CFLAGS_STLPORT ? "-stlport " : ""), (flags & ASSIMP_CFLAGS_STLPORT ? "-stlport " : ""),
aiGetVersionRevision()); aiGetVersionRevision());
return 0; return AssimpCmdError::Success;
} }
// assimp help // assimp help
@ -110,7 +110,7 @@ int main (int argc, char* argv[])
// because people could try them intuitively) // because people could try them intuitively)
if (!strcmp(argv[1], "help") || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) { if (!strcmp(argv[1], "help") || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) {
printf("%s",AICMD_MSG_HELP); printf("%s",AICMD_MSG_HELP);
return 0; return AssimpCmdError::Success;
} }
// assimp cmpdump // assimp cmpdump
@ -137,7 +137,7 @@ int main (int argc, char* argv[])
imp.GetExtensionList(s); imp.GetExtensionList(s);
printf("%s\n",s.data); printf("%s\n",s.data);
return 0; return AssimpCmdError::Success;
} }
#ifndef ASSIMP_BUILD_NO_EXPORT #ifndef ASSIMP_BUILD_NO_EXPORT
@ -155,7 +155,7 @@ int main (int argc, char* argv[])
} }
printf("%s\n",s.data); printf("%s\n",s.data);
return 0; return AssimpCmdError::Success;
} }
@ -166,19 +166,19 @@ int main (int argc, char* argv[])
if (argc<3) { if (argc<3) {
printf("Expected file format id\n"); printf("Expected file format id\n");
return -11; return AssimpCmdError::NoFileFormatSpecified;
} }
for(size_t i = 0, end = exp.GetExportFormatCount(); i < end; ++i) { for(size_t i = 0, end = exp.GetExportFormatCount(); i < end; ++i) {
const aiExportFormatDesc* const e = exp.GetExportFormatDescription(i); const aiExportFormatDesc* const e = exp.GetExportFormatDescription(i);
if (!strcmp(e->id,argv[2])) { if (!strcmp(e->id,argv[2])) {
printf("%s\n%s\n%s\n",e->id,e->fileExtension,e->description); printf("%s\n%s\n%s\n",e->id,e->fileExtension,e->description);
return 0; return AssimpCmdError::Success;
} }
} }
printf("Unknown file format id: \'%s\'\n",argv[2]); printf("Unknown file format id: \'%s\'\n",argv[2]);
return -12; return AssimpCmdError::UnknownFileFormat;
} }
// assimp export // assimp export
@ -194,11 +194,11 @@ int main (int argc, char* argv[])
if (! strcmp(argv[1], "knowext")) { if (! strcmp(argv[1], "knowext")) {
if (argc<3) { if (argc<3) {
printf("Expected file extension"); printf("Expected file extension");
return -10; return AssimpCmdError::NoFileExtensionSpecified;
} }
const bool b = imp.IsExtensionSupported(argv[2]); const bool b = imp.IsExtensionSupported(argv[2]);
printf("File extension \'%s\' is %sknown\n",argv[2],(b?"":"not ")); printf("File extension \'%s\' is %sknown\n",argv[2],(b?"":"not "));
return b?0:-1; return b? AssimpCmdError::Success : AssimpCmdError::UnknownFileExtension;
} }
// assimp info // assimp info
@ -228,7 +228,7 @@ int main (int argc, char* argv[])
} }
printf("Unrecognized command. Use \'assimp help\' for a detailed command list\n"); printf("Unrecognized command. Use \'assimp help\' for a detailed command list\n");
return 1; return AssimpCmdError::UnrecognizedCommand;
} }
@ -505,7 +505,7 @@ int ProcessStandardArguments(
fill.log = true; fill.log = true;
} }
return 0; return AssimpCmdError::Success;
} }
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
@ -517,5 +517,5 @@ int Assimp_TestBatchLoad (
globalImporter->ReadFile(params[i],aiProcessPreset_TargetRealtime_MaxQuality); globalImporter->ReadFile(params[i],aiProcessPreset_TargetRealtime_MaxQuality);
// we're totally silent. scene destructs automatically. // we're totally silent. scene destructs automatically.
} }
return 0; return AssimpCmdError::Success;
} }

View File

@ -114,13 +114,31 @@ struct ImportData {
bool log; bool log;
}; };
/// \enum AssimpCmdError
/// \brief General error codes used among assimp_cmd's utilities.
enum AssimpCmdError {
Success = 0,
InvalidNumberOfArguments,
UnrecognizedCommand,
FailedToLoadInputFile,
FailedToOpenOutputFile,
NoFileFormatSpecified,
UnknownFileFormat,
NoFileExtensionSpecified,
UnknownFileExtension,
// Add new error codes here...
LastAssimpCmdError, // Must be last.
};
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
/** Process standard arguments /** Process standard arguments
* *
* @param fill Filled by function * @param fill Filled by function
* @param params Command line parameters to be processed * @param params Command line parameters to be processed
* @param num NUmber of params * @param num NUmber of params
* @return 0 for success */ * @return An #AssimpCmdError value. */
int ProcessStandardArguments(ImportData& fill, int ProcessStandardArguments(ImportData& fill,
const char* const* params, const char* const* params,
unsigned int num); unsigned int num);
@ -151,43 +169,88 @@ bool ExportModel(const aiScene* pOut,
/** assimp_dump utility /** assimp_dump utility
* @param params Command line parameters to 'assimp dumb' * @param params Command line parameters to 'assimp dumb'
* @param Number of params * @param Number of params
* @return 0 for success*/ * @return An #AssimpCmdError value.*/
int Assimp_Dump ( int Assimp_Dump (
const char* const* params, const char* const* params,
unsigned int num); unsigned int num);
/// \enum AssimpCmdExportError
/// \brief Error codes used by the 'Export' utility.
enum AssimpCmdExportError {
FailedToImportModel = AssimpCmdError::LastAssimpCmdError,
FailedToExportModel,
// Add new error codes here...
LastAssimpCmdExportError, // Must be last.
};
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
/** assimp_export utility /** assimp_export utility
* @param params Command line parameters to 'assimp export' * @param params Command line parameters to 'assimp export'
* @param Number of params * @param Number of params
* @return 0 for success*/ * @return Either an #AssimpCmdError or #AssimpCmdExportError value. */
int Assimp_Export ( int Assimp_Export (
const char* const* params, const char* const* params,
unsigned int num); unsigned int num);
/// \enum AssimpCmdExtractError
/// \brief Error codes used by the 'Image Extractor' utility.
enum AssimpCmdExtractError {
TextureIndexIsOutOfRange = AssimpCmdError::LastAssimpCmdError,
NoAvailableTextureEncoderFound,
FailedToExportCompressedTexture,
// Add new error codes here...
LastAssimpCmdExtractError, // Must be last.
};
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
/** assimp_extract utility /** assimp_extract utility
* @param params Command line parameters to 'assimp extract' * @param params Command line parameters to 'assimp extract'
* @param Number of params * @param Number of params
* @return 0 for success*/ * @return Either an #AssimpCmdError or #AssimpCmdExtractError value. */
int Assimp_Extract ( int Assimp_Extract (
const char* const* params, const char* const* params,
unsigned int num); unsigned int num);
/// \enum AssimpCmdCompareDumpError
/// \brief Error codes used by the 'Compare Dump' utility.
enum AssimpCmdCompareDumpError {
FailedToLoadExpectedInputFile = AssimpCmdError::LastAssimpCmdError,
FileComparaisonFailure,
UnknownFailure,
// Add new error codes here...
LastAssimpCmdCompareDumpError, // Must be last.
};
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
/** assimp_cmpdump utility /** assimp_cmpdump utility
* @param params Command line parameters to 'assimp cmpdump' * @param params Command line parameters to 'assimp cmpdump'
* @param Number of params * @param Number of params
* @return 0 for success*/ * @return Either an #AssimpCmdError or #AssimpCmdCompareDumpError. */
int Assimp_CompareDump ( int Assimp_CompareDump (
const char* const* params, const char* const* params,
unsigned int num); unsigned int num);
/// \enum AssimpCmdInfoError
/// \brief Error codes used by the 'Info' utility.
enum AssimpCmdInfoError {
InvalidCombinaisonOfArguments = AssimpCmdError::LastAssimpCmdError,
// Add new error codes here...
LastAssimpCmdInfoError, // Must be last.
};
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
/** @brief assimp info utility /** @brief assimp info utility
* @param params Command line parameters to 'assimp info' * @param params Command line parameters to 'assimp info'
* @param Number of params * @param Number of params
* @return 0 for success */ * @return Either an #AssimpCmdError or #AssimpCmdInfoError value. */
int Assimp_Info ( int Assimp_Info (
const char* const* params, const char* const* params,
unsigned int num); unsigned int num);
@ -196,7 +259,7 @@ int Assimp_Info (
/** @brief assimp testbatchload utility /** @brief assimp testbatchload utility
* @param params Command line parameters to 'assimp testbatchload' * @param params Command line parameters to 'assimp testbatchload'
* @param Number of params * @param Number of params
* @return 0 for success */ * @return An #AssimpCmdError value. */
int Assimp_TestBatchLoad ( int Assimp_TestBatchLoad (
const char* const* params, const char* const* params,
unsigned int num); unsigned int num);

View File

@ -312,7 +312,8 @@ uint32_t WriteBinaryTexture(const aiTexture* tex)
len += Write<unsigned int>(tex->mWidth); len += Write<unsigned int>(tex->mWidth);
len += Write<unsigned int>(tex->mHeight); len += Write<unsigned int>(tex->mHeight);
len += static_cast<uint32_t>(fwrite(tex->achFormatHint,1,4,out)); // Write the texture format, but don't include the null terminator.
len += static_cast<uint32_t>(fwrite(tex->achFormatHint,sizeof(char),HINTMAXTEXTURELEN - 1,out));
if(!shortened) { if(!shortened) {
if (!tex->mHeight) { if (!tex->mHeight) {
@ -1340,13 +1341,13 @@ int Assimp_Dump (const char* const* params, unsigned int num)
// --help // --help
if (!strcmp( params[0], "-h") || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) { if (!strcmp( params[0], "-h") || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) {
printf("%s",AICMD_MSG_DUMP_HELP); printf("%s",AICMD_MSG_DUMP_HELP);
return 0; return AssimpCmdError::Success;
} }
// asssimp dump in out [options] // asssimp dump in out [options]
if (num < 1) { if (num < 1) {
printf("%s", fail); printf("%s", fail);
return 1; return AssimpCmdError::InvalidNumberOfArguments;
} }
std::string in = std::string(params[0]); std::string in = std::string(params[0]);
@ -1404,14 +1405,14 @@ int Assimp_Dump (const char* const* params, unsigned int num)
const aiScene* scene = ImportModel(import,in); const aiScene* scene = ImportModel(import,in);
if (!scene) { if (!scene) {
printf("assimp dump: Unable to load input file %s\n",in.c_str()); printf("assimp dump: Unable to load input file %s\n",in.c_str());
return 5; return AssimpCmdError::FailedToLoadInputFile;
} }
// open the output file and build the dump // open the output file and build the dump
FILE* o = ::fopen(out.c_str(),(binary ? "wb" : "wt")); FILE* o = ::fopen(out.c_str(),(binary ? "wb" : "wt"));
if (!o) { if (!o) {
printf("assimp dump: Unable to open output file %s\n",out.c_str()); printf("assimp dump: Unable to open output file %s\n",out.c_str());
return 12; return AssimpCmdError::FailedToOpenOutputFile;
} }
if (binary) { if (binary) {
@ -1425,6 +1426,6 @@ int Assimp_Dump (const char* const* params, unsigned int num)
} }
printf("assimp dump: Wrote output dump %s\n",out.c_str()); printf("assimp dump: Wrote output dump %s\n",out.c_str());
return 0; return AssimpCmdError::Success;
} }