GeezerVison is showing github.com — Finished loading of MD2, MD3, MDL2, MDL3, MDL4, MDL5, MDL7, MDL. Firs… · wise86-android/assimp@b422d4e
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: code/3DSConverter.cpp +26-23Lines changed: 26 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,19 +40,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 40 | 40 | */ | 41 | 41 |
| 42 | 42 | /** @file Implementation of the 3ds importer class */ | | 43 | + | | 44 | +// internal headers | 43 | 45 | #include "3DSLoader.h" | 44 | 46 | #include "MaterialSystem.h" | 45 | 47 | #include "TextureTransform.h" | 46 | 48 | #include "StringComparison.h" | | 49 | +#include "qnan.h" | 47 | 50 |
| | 51 | +// public ASSIMP headers | 48 | 52 | #include "../include/DefaultLogger.h" | 49 | 53 | #include "../include/IOStream.h" | 50 | 54 | #include "../include/IOSystem.h" | 51 | 55 | #include "../include/aiMesh.h" | 52 | 56 | #include "../include/aiScene.h" | 53 | 57 | #include "../include/aiAssert.h" | 54 | 58 |
| 55 | | -#include <boost/scoped_ptr.hpp> | 56 | 59 |
| 57 | 60 | using namespace Assimp; | 58 | 61 |
| @@ -427,10 +430,12 @@ void Dot3DSImporter::ConvertMeshes(aiScene* pcOut) | 427 | 430 | a != (*i).mFaceMaterials.end();++a,++iNum) | 428 | 431 | { | 429 | 432 | // check range | 430 | | - if ((*a) >= this->mScene->mMaterials.size()) | | 433 | + if ((*a) >= this->mScene->mMaterials.size()) | 431 | 434 | { | 432 | | - // use the last material instead | 433 | | - aiSplit[this->mScene->mMaterials.size()-1].push_back(iNum); | | 435 | + DefaultLogger::get()->error("Face material index is out of range"); | | 436 | + | | 437 | + // use the last material instead | | 438 | + aiSplit[this->mScene->mMaterials.size()-1].push_back(iNum); | 434 | 439 | } | 435 | 440 | else aiSplit[*a].push_back(iNum); | 436 | 441 | } | @@ -450,15 +455,15 @@ void Dot3DSImporter::ConvertMeshes(aiScene* pcOut) | 450 | 455 | p_pcOut->mColors[0] = (aiColor4D*)new std::string((*i).mName); | 451 | 456 | avOutMeshes.push_back(p_pcOut); | 452 | 457 |
| 453 | | - | | 458 | +// (code for keyframe animation. however, this is currently not supported by Assimp) | | 459 | +#if 0 | 454 | 460 | if (bFirst) | 455 | 461 | { | 456 | 462 | p_pcOut->mColors[1] = (aiColor4D*)new aiMatrix4x4(); | 457 | | - | 458 | 463 | *((aiMatrix4x4*)p_pcOut->mColors[1]) = (*i).mMat; | 459 | 464 | bFirst = false; | 460 | 465 | } | 461 | | - | | 466 | +#endif | 462 | 467 |
| 463 | 468 | // convert vertices | 464 | 469 | p_pcOut->mNumVertices = (unsigned int)aiSplit[p].size()*3; | @@ -519,16 +524,6 @@ void Dot3DSImporter::ConvertMeshes(aiScene* pcOut) | 519 | 524 | // apply texture coordinate scalings | 520 | 525 | TextureTransform::BakeScaleNOffset ( p_pcOut, &this->mScene->mMaterials[ | 521 | 526 | p_pcOut->mMaterialIndex] ); | 522 | | - | 523 | | - // setup bitflags to indicate which texture coordinate | 524 | | - // channels are used | 525 | | - p_pcOut->mNumUVComponents[0] = 2; | 526 | | - if (p_pcOut->HasTextureCoords(1)) | 527 | | - p_pcOut->mNumUVComponents[1] = 2; | 528 | | - if (p_pcOut->HasTextureCoords(2)) | 529 | | - p_pcOut->mNumUVComponents[2] = 2; | 530 | | - if (p_pcOut->HasTextureCoords(3)) | 531 | | - p_pcOut->mNumUVComponents[3] = 2; | 532 | 527 | } | 533 | 528 | } | 534 | 529 | } | @@ -579,6 +574,8 @@ void Dot3DSImporter::AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,Dot3DS::Node* | 579 | 574 | { | 580 | 575 | const unsigned int iIndex = iArray[i]; | 581 | 576 |
| | 577 | +// (code for keyframe animation. however, this is currently not supported by Assimp) | | 578 | +#if 0 | 582 | 579 | if (NULL != pcSOut->mMeshes[iIndex]->mColors[1]) | 583 | 580 | { | 584 | 581 | pcOut->mTransformation = *((aiMatrix4x4*) | @@ -587,7 +584,7 @@ void Dot3DSImporter::AddNodeToGraph(aiScene* pcSOut,aiNode* pcOut,Dot3DS::Node* | 587 | 584 | delete (aiMatrix4x4*)pcSOut->mMeshes[iIndex]->mColors[1]; | 588 | 585 | pcSOut->mMeshes[iIndex]->mColors[1] = NULL; | 589 | 586 | } | 590 | | - | | 587 | +#endif | 591 | 588 | pcOut->mMeshes[i] = iIndex; | 592 | 589 | } | 593 | 590 |
| @@ -681,11 +678,17 @@ void Dot3DSImporter::GenerateNodeGraph(aiScene* pcOut) | 681 | 678 | pcNode->mMeshes[0] = i; | 682 | 679 | pcNode->mNumMeshes = 1; | 683 | 680 |
| 684 | | - std::string s; | 685 | | - std::stringstream ss(s); | 686 | | - ss << "UNNAMED[" << i << + "]"; | 687 | | - | 688 | | - pcNode->mName.Set(s); | | 681 | + char szBuffer[128]; | | 682 | + int iLen; | | 683 | +#if _MSC_VER >= 1400 | | 684 | + iLen = sprintf_s(szBuffer,"UNNAMED_%i",i); | | 685 | +#else | | 686 | + iLen = sprintf(szBuffer,"UNNAMED_%i",i); | | 687 | +#endif | | 688 | + ai_assert(0 < iLen); | | 689 | + ::memcpy(pcNode->mName.data,szBuffer,iLen); | | 690 | + pcNode->mName.data[iLen] = '\0'; | | 691 | + pcNode->mName.length = iLen; | 689 | 692 |
| 690 | 693 | // add the new child to the parent node | 691 | 694 | pcOut->mRootNode->mChildren[i] = pcNode; | |
Collapse file Copy file name to clipboardExpand all lines: code/3DSHelper.h +26-30Lines changed: 26 additions & 30 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,10 +93,22 @@ class Dot3DSFile | 93 | 93 | //! From AutoDesk 3ds SDK | 94 | 94 | typedef enum | 95 | 95 | { | | 96 | + // translated to gouraud shading with wireframe active | 96 | 97 | Wire = 0, | | 98 | + | | 99 | + // if this material is set, no vertex normals will | | 100 | + // be calculated for the model. Face normals + gouraud | 97 | 101 | Flat = 1, | | 102 | + | | 103 | + // standard gouraud shading | 98 | 104 | Gouraud = 2, | | 105 | + | | 106 | + // phong shading | 99 | 107 | Phong = 3, | | 108 | + | | 109 | + // cooktorrance or anistropic phong shading ... | | 110 | + // the exact meaning is unknown, if you know it | | 111 | + // feel free to tell me ;-) | 100 | 112 | Metal = 4, | 101 | 113 |
| 102 | 114 | // required by the ASE loader | @@ -127,7 +139,8 @@ class Dot3DSFile | 127 | 139 | CHUNK_PERCENTF = 0x0031, // float4 percentage | 128 | 140 | // ************************************************************** | 129 | 141 |
| 130 | | - // Unknown and ignored | | 142 | + // Unknown and ignored. Possibly a chunk used by PROJ ( | | 143 | + // Discreet 3DS max Project File)? | 131 | 144 | CHUNK_PRJ = 0xC23D, | 132 | 145 |
| 133 | 146 | // Unknown. Possibly a reference to an external .mli file? | @@ -387,9 +400,10 @@ struct Material | 387 | 400 | mTwoSided (false) | 388 | 401 | { | 389 | 402 | static int iCnt = 0; | 390 | | - std::stringstream ss; | 391 | | - ss << "$$_UNNAMED_" << iCnt++ << "_$$"; | 392 | | - ss >> mName; | | 403 | + | | 404 | + char szTemp[128]; | | 405 | + sprintf(szTemp,"$$_UNNAMED_%i_$$",iCnt++); | | 406 | + mName = szTemp; | 393 | 407 | } | 394 | 408 |
| 395 | 409 | //! Name of the material | @@ -442,9 +456,10 @@ struct Mesh | 442 | 456 | Mesh() | 443 | 457 | { | 444 | 458 | static int iCnt = 0; | 445 | | - std::stringstream ss; | 446 | | - ss << "$$_UNNAMED_" << iCnt++ << "_$$"; | 447 | | - ss >> mName; | | 459 | + | | 460 | + char szTemp[128]; | | 461 | + sprintf(szTemp,"$$_UNNAMED_%i_$$",iCnt++); | | 462 | + mName = szTemp; | 448 | 463 | } | 449 | 464 |
| 450 | 465 | //! Name of the mesh | @@ -481,9 +496,10 @@ struct Node | 481 | 496 |
| 482 | 497 | { | 483 | 498 | static int iCnt = 0; | 484 | | - std::stringstream ss; | 485 | | - ss << "$$_UNNAMED_" << iCnt++ << "_$$"; | 486 | | - ss >> mName; | | 499 | + | | 500 | + char szTemp[128]; | | 501 | + sprintf(szTemp,"$$_UNNAMED_%i_$$",iCnt++); | | 502 | + mName = szTemp; | 487 | 503 |
| 488 | 504 | mHierarchyPos = 0; | 489 | 505 | mHierarchyIndex = 0; | @@ -538,26 +554,6 @@ struct Scene | 538 | 554 | Node* pcRootNode; | 539 | 555 | }; | 540 | 556 |
| 541 | | -// --------------------------------------------------------------------------- | 542 | | -inline bool is_qnan(float p_fIn) | 543 | | -{ | 544 | | - // NOTE: Comparison against qnan is generally problematic | 545 | | - // because qnan == qnan is false AFAIK | 546 | | - union FTOINT | 547 | | - { | 548 | | - float fFloat; | 549 | | - int32_t iInt; | 550 | | - } one, two; | 551 | | - one.fFloat = std::numeric_limits<float>::quiet_NaN(); | 552 | | - two.fFloat = p_fIn; | 553 | | - | 554 | | - return (one.iInt == two.iInt); | 555 | | -} | 556 | | -// --------------------------------------------------------------------------- | 557 | | -inline bool is_not_qnan(float p_fIn) | 558 | | -{ | 559 | | - return !is_qnan(p_fIn); | 560 | | -} | 561 | 557 |
| 562 | 558 | } // end of namespace Dot3DS | 563 | 559 | } // end of namespace Assimp | |
Collapse file Copy file name to clipboardExpand all lines: code/3DSLoader.cpp +21-29Lines changed: 21 additions & 29 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,26 +40,33 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 40 | 40 | */ | 41 | 41 |
| 42 | 42 | /** @file Implementation of the 3ds importer class */ | | 43 | + | | 44 | +// internal headers | 43 | 45 | #include "3DSLoader.h" | 44 | 46 | #include "MaterialSystem.h" | 45 | 47 | #include "TextureTransform.h" | 46 | 48 | #include "StringComparison.h" | | 49 | +#include "qnan.h" | 47 | 50 |
| | 51 | +// public ASSIMP headers | 48 | 52 | #include "../include/DefaultLogger.h" | 49 | 53 | #include "../include/IOStream.h" | 50 | 54 | #include "../include/IOSystem.h" | 51 | 55 | #include "../include/aiMesh.h" | 52 | 56 | #include "../include/aiScene.h" | 53 | 57 | #include "../include/aiAssert.h" | 54 | 58 |
| | 59 | +// boost headers | 55 | 60 | #include <boost/scoped_ptr.hpp> | 56 | 61 |
| 57 | 62 | using namespace Assimp; | 58 | 63 |
| 59 | | -#define ASSIMP_3DS_WARN_CHUNK_OVERFLOW_MSG \ | 60 | | - "WARNING: Size of chunk data plus size of " \ | 61 | | - "subordinate chunks is larger than the size " \ | 62 | | - "specified in the higher-level chunk header." \ | | 64 | +#if (!defined ASSIMP_3DS_WARN_CHUNK_OVERFLOW_MSG) | | 65 | +# define ASSIMP_3DS_WARN_CHUNK_OVERFLOW_MSG \ | | 66 | + "WARNING: Size of chunk data plus size of " \ | | 67 | + "subordinate chunks is larger than the size " \ | | 68 | + "specified in the top-level chunk header." | | 69 | +#endif | 63 | 70 |
| 64 | 71 | // ------------------------------------------------------------------------------------------------ | 65 | 72 | // Constructor to be privately used by Importer | @@ -92,22 +99,6 @@ bool Dot3DSImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler) co | 92 | 99 | return false; | 93 | 100 | } | 94 | 101 | // ------------------------------------------------------------------------------------------------ | 95 | | -// recursively delete a given node | 96 | | -void DeleteNodeRecursively (aiNode* p_piNode) | 97 | | -{ | 98 | | - if (!p_piNode)return; | 99 | | - | 100 | | - if (p_piNode->mChildren) | 101 | | - { | 102 | | - for (unsigned int i = 0 ; i < p_piNode->mNumChildren;++i) | 103 | | - { | 104 | | - DeleteNodeRecursively(p_piNode->mChildren[i]); | 105 | | - } | 106 | | - } | 107 | | - delete p_piNode; | 108 | | - return; | 109 | | -} | 110 | | -// ------------------------------------------------------------------------------------------------ | 111 | 102 | // Imports the given file into the given scene structure. | 112 | 103 | void Dot3DSImporter::InternReadFile( | 113 | 104 | const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) | @@ -125,7 +116,7 @@ void Dot3DSImporter::InternReadFile( | 125 | 116 | size_t fileSize = file->FileSize(); | 126 | 117 | if( fileSize < 16) | 127 | 118 | { | 128 | | - throw new ImportErrorException( ".3ds File is too small."); | | 119 | + throw new ImportErrorException( "3DS File is too small."); | 129 | 120 | } | 130 | 121 |
| 131 | 122 | this->mScene = new Dot3DS::Scene(); | @@ -780,8 +771,9 @@ void Dot3DSImporter::ParseFaceChunk(int* piRemaining) | 780 | 771 | case Dot3DSFile::CHUNK_FACEMAT: | 781 | 772 |
| 782 | 773 | // at fist an asciiz with the material name | 783 | | - while (*sz++ != '\0') | | 774 | + while (*sz++) | 784 | 775 | { | | 776 | + // make sure we don't run over the end of the chunk | 785 | 777 | if (sz > pcCurNext-1)break; | 786 | 778 | } | 787 | 779 |
| @@ -800,7 +792,7 @@ void Dot3DSImporter::ParseFaceChunk(int* piRemaining) | 800 | 792 | break; | 801 | 793 | } | 802 | 794 | } | 803 | | - if (iIndex == 0xFFFFFFFF) | | 795 | + if (0xFFFFFFFF == iIndex) | 804 | 796 | { | 805 | 797 | // this material is not known. Ignore this. We will later | 806 | 798 | // assign the default material to all faces using *this* | @@ -818,13 +810,14 @@ void Dot3DSImporter::ParseFaceChunk(int* piRemaining) | 818 | 810 |
| 819 | 811 | // check range | 820 | 812 | if (iTemp >= mMesh.mFaceMaterials.size()) | 821 | | - { | | 813 | + { | | 814 | + DefaultLogger::get()->error("Invalid face index in face material list"); | 822 | 815 | mMesh.mFaceMaterials[mMesh.mFaceMaterials.size()-1] = iIndex; | 823 | | - } | | 816 | + } | 824 | 817 | else | 825 | | - { | | 818 | + { | 826 | 819 | mMesh.mFaceMaterials[iTemp] = iIndex; | 827 | | - } | | 820 | + } | 828 | 821 | this->mCurrent += sizeof(uint16_t); | 829 | 822 | } | 830 | 823 |
| @@ -959,8 +952,7 @@ void Dot3DSImporter::ParseMeshChunk(int* piRemaining) | 959 | 952 | } | 960 | 953 | break; | 961 | 954 |
| 962 | | -#if (defined _DEBUG) | 963 | | - | | 955 | +#if 0 | 964 | 956 | case Dot3DSFile::CHUNK_TXTINFO: | 965 | 957 |
| 966 | 958 | // for debugging purposes. Read two bytes to determine the mapping type | |
Collapse file Copy file name to clipboardExpand all lines: code/ASELoader.cpp +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,13 +40,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 40 | 40 | */ | 41 | 41 |
| 42 | 42 | /** @file Implementation of the ASE importer class */ | | 43 | + | | 44 | +// internal headers | 43 | 45 | #include "ASELoader.h" | 44 | 46 | #include "3DSSpatialSort.h" | 45 | 47 | #include "MaterialSystem.h" | 46 | 48 | #include "StringComparison.h" | 47 | 49 | #include "TextureTransform.h" | | 50 | + | | 51 | +// utilities | 48 | 52 | #include "fast_atof.h" | | 53 | +#include "qnan.h" | 49 | 54 |
| | 55 | +// ASSIMP public headers | 50 | 56 | #include "../include/IOStream.h" | 51 | 57 | #include "../include/IOSystem.h" | 52 | 58 | #include "../include/aiMesh.h" | |
Collapse file Copy file name to clipboardExpand all lines: code/BaseImporter.h +10-2Lines changed: 10 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -111,7 +111,7 @@ class BaseImporter | 111 | 111 | // ------------------------------------------------------------------- | 112 | 112 | /** Imports the given file and returns the imported data. | 113 | 113 | * If the import succeeds, ownership of the data is transferred to | 114 | | - * the caller. If the import failes, NULL is returned. The function | | 114 | + * the caller. If the import fails, NULL is returned. The function | 115 | 115 | * takes care that any partially constructed data is destroyed | 116 | 116 | * beforehand. | 117 | 117 | * | @@ -154,7 +154,15 @@ class BaseImporter | 154 | 154 | * an error. If it terminates normally, the data in aiScene is | 155 | 155 | * expected to be correct. Override this function to implement the | 156 | 156 | * actual importing. | 157 | | - * | | 157 | + * <br> | | 158 | + * The output scene must meet the following conditions:<br> | | 159 | + * - at least one mesh must be there<br> | | 160 | + * - at least a root node must be there<br> | | 161 | + * - at least one material must be there<br> | | 162 | + * - there may be no meshes with 0 vertices or faces<br> | | 163 | + * This won't be checked (except by the validation step), Assimp will | | 164 | + * crash if one of the conditions is not met! | | 165 | + * | 158 | 166 | * @param pFile Path of the file to be imported. | 159 | 167 | * @param pScene The scene object to hold the imported data. | 160 | 168 | * NULL is not a valid parameter. | |
|