|
@@ -117,20 +117,8 @@ const aiImporterDesc* B3DImporter::GetInfo () const
|
|
return &desc;
|
|
return &desc;
|
|
}
|
|
}
|
|
|
|
|
|
-#ifdef DEBUG_B3D
|
|
|
|
- extern "C"{ void _stdcall AllocConsole(); }
|
|
|
|
-#endif
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
void B3DImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler){
|
|
void B3DImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler){
|
|
-
|
|
|
|
-#ifdef DEBUG_B3D
|
|
|
|
- AllocConsole();
|
|
|
|
- freopen( "conin$","r",stdin );
|
|
|
|
- freopen( "conout$","w",stdout );
|
|
|
|
- freopen( "conout$","w",stderr );
|
|
|
|
- cout<<"Hello world from the B3DImporter!"<<endl;
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
std::unique_ptr<IOStream> file( pIOHandler->Open( pFile));
|
|
std::unique_ptr<IOStream> file( pIOHandler->Open( pFile));
|
|
|
|
|
|
// Check whether we can read from the file
|
|
// Check whether we can read from the file
|
|
@@ -158,7 +146,7 @@ AI_WONT_RETURN void B3DImporter::Oops(){
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
AI_WONT_RETURN void B3DImporter::Fail( string str ){
|
|
AI_WONT_RETURN void B3DImporter::Fail( string str ){
|
|
#ifdef DEBUG_B3D
|
|
#ifdef DEBUG_B3D
|
|
- cout<<"Error in B3D file data: "<<str<<endl;
|
|
|
|
|
|
+ ASSIMP_LOG_ERROR_F("Error in B3D file data: %s", str.c_str());
|
|
#endif
|
|
#endif
|
|
throw DeadlyImportError( "B3D Importer - error in B3D file data: "+str );
|
|
throw DeadlyImportError( "B3D Importer - error in B3D file data: "+str );
|
|
}
|
|
}
|
|
@@ -238,7 +226,7 @@ string B3DImporter::ReadChunk(){
|
|
tag+=char( ReadByte() );
|
|
tag+=char( ReadByte() );
|
|
}
|
|
}
|
|
#ifdef DEBUG_B3D
|
|
#ifdef DEBUG_B3D
|
|
-// cout<<"ReadChunk:"<<tag<<endl;
|
|
|
|
|
|
+ ASSIMP_LOG_DEBUG_F("ReadChunk: %s", tag.c_str());
|
|
#endif
|
|
#endif
|
|
unsigned sz=(unsigned)ReadInt();
|
|
unsigned sz=(unsigned)ReadInt();
|
|
_stack.push_back( _pos+sz );
|
|
_stack.push_back( _pos+sz );
|
|
@@ -392,47 +380,47 @@ void B3DImporter::ReadVRTS(){
|
|
}
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-void B3DImporter::ReadTRIS( int v0 ){
|
|
|
|
- int matid=ReadInt();
|
|
|
|
- if( matid==-1 ){
|
|
|
|
- matid=0;
|
|
|
|
- }else if( matid<0 || matid>=(int)_materials.size() ){
|
|
|
|
|
|
+void B3DImporter::ReadTRIS(int v0) {
|
|
|
|
+ int matid = ReadInt();
|
|
|
|
+ if (matid == -1) {
|
|
|
|
+ matid = 0;
|
|
|
|
+ } else if (matid < 0 || matid >= (int)_materials.size()) {
|
|
#ifdef DEBUG_B3D
|
|
#ifdef DEBUG_B3D
|
|
- cout<<"material id="<<matid<<endl;
|
|
|
|
|
|
+ ASSIMP_LOG_ERROR_F("material id=%d", matid);
|
|
#endif
|
|
#endif
|
|
- Fail( "Bad material id" );
|
|
|
|
- }
|
|
|
|
|
|
+ Fail("Bad material id");
|
|
|
|
+ }
|
|
|
|
|
|
- std::unique_ptr<aiMesh> mesh(new aiMesh);
|
|
|
|
|
|
+ std::unique_ptr<aiMesh> mesh(new aiMesh);
|
|
|
|
|
|
- mesh->mMaterialIndex=matid;
|
|
|
|
- mesh->mNumFaces=0;
|
|
|
|
- mesh->mPrimitiveTypes=aiPrimitiveType_TRIANGLE;
|
|
|
|
|
|
+ mesh->mMaterialIndex = matid;
|
|
|
|
+ mesh->mNumFaces = 0;
|
|
|
|
+ mesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
|
|
|
|
|
- int n_tris=ChunkSize()/12;
|
|
|
|
- aiFace *face=mesh->mFaces=new aiFace[n_tris];
|
|
|
|
|
|
+ int n_tris = ChunkSize() / 12;
|
|
|
|
+ aiFace *face = mesh->mFaces = new aiFace[n_tris];
|
|
|
|
|
|
- for( int i=0;i<n_tris;++i ){
|
|
|
|
- int i0=ReadInt()+v0;
|
|
|
|
- int i1=ReadInt()+v0;
|
|
|
|
- int i2=ReadInt()+v0;
|
|
|
|
- if( i0<0 || i0>=(int)_vertices.size() || i1<0 || i1>=(int)_vertices.size() || i2<0 || i2>=(int)_vertices.size() ){
|
|
|
|
|
|
+ for (int i = 0; i < n_tris; ++i) {
|
|
|
|
+ int i0 = ReadInt() + v0;
|
|
|
|
+ int i1 = ReadInt() + v0;
|
|
|
|
+ int i2 = ReadInt() + v0;
|
|
|
|
+ if (i0 < 0 || i0 >= (int)_vertices.size() || i1 < 0 || i1 >= (int)_vertices.size() || i2 < 0 || i2 >= (int)_vertices.size()) {
|
|
#ifdef DEBUG_B3D
|
|
#ifdef DEBUG_B3D
|
|
- cout<<"Bad triangle index: i0="<<i0<<", i1="<<i1<<", i2="<<i2<<endl;
|
|
|
|
|
|
+ ASSIMP_LOG_ERROR_F("Bad triangle index: i0=%d, i1=%d, i2=%d", i0, i1, i2);
|
|
#endif
|
|
#endif
|
|
- Fail( "Bad triangle index" );
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- face->mNumIndices=3;
|
|
|
|
- face->mIndices=new unsigned[3];
|
|
|
|
- face->mIndices[0]=i0;
|
|
|
|
- face->mIndices[1]=i1;
|
|
|
|
- face->mIndices[2]=i2;
|
|
|
|
- ++mesh->mNumFaces;
|
|
|
|
- ++face;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _meshes.emplace_back( std::move(mesh) );
|
|
|
|
|
|
+ Fail("Bad triangle index");
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ face->mNumIndices = 3;
|
|
|
|
+ face->mIndices = new unsigned[3];
|
|
|
|
+ face->mIndices[0] = i0;
|
|
|
|
+ face->mIndices[1] = i1;
|
|
|
|
+ face->mIndices[2] = i2;
|
|
|
|
+ ++mesh->mNumFaces;
|
|
|
|
+ ++face;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _meshes.emplace_back(std::move(mesh));
|
|
}
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
@@ -453,29 +441,23 @@ void B3DImporter::ReadMESH(){
|
|
}
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|
|
-void B3DImporter::ReadBONE( int id ){
|
|
|
|
- while( ChunkSize() ){
|
|
|
|
- int vertex=ReadInt();
|
|
|
|
- float weight=ReadFloat();
|
|
|
|
- if( vertex<0 || vertex>=(int)_vertices.size() ){
|
|
|
|
- Fail( "Bad vertex index" );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Vertex &v=_vertices[vertex];
|
|
|
|
- int i;
|
|
|
|
- for( i=0;i<4;++i ){
|
|
|
|
- if( !v.weights[i] ){
|
|
|
|
- v.bones[i]=id;
|
|
|
|
- v.weights[i]=weight;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-#ifdef DEBUG_B3D
|
|
|
|
- if( i==4 ){
|
|
|
|
- cout<<"Too many bone weights"<<endl;
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
- }
|
|
|
|
|
|
+void B3DImporter::ReadBONE(int id) {
|
|
|
|
+ while (ChunkSize()) {
|
|
|
|
+ int vertex = ReadInt();
|
|
|
|
+ float weight = ReadFloat();
|
|
|
|
+ if (vertex < 0 || vertex >= (int)_vertices.size()) {
|
|
|
|
+ Fail("Bad vertex index");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Vertex &v = _vertices[vertex];
|
|
|
|
+ for (int i = 0; i < 4; ++i) {
|
|
|
|
+ if (!v.weights[i]) {
|
|
|
|
+ v.bones[i] = id;
|
|
|
|
+ v.weights[i] = weight;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
// ------------------------------------------------------------------------------------------------
|