Fixed materials/normals

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@325 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
marksibly 2009-01-31 23:24:11 +00:00
parent ed42533cce
commit b2b083cc87
2 changed files with 44 additions and 32 deletions

View File

@ -80,7 +80,7 @@ void B3DImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
// check whether the .b3d file is large enough to contain // check whether the .b3d file is large enough to contain
// at least one chunk. // at least one chunk.
size_t fileSize = file->FileSize(); size_t fileSize = file->FileSize();
if( fileSize < 8) throw new ImportErrorException( "B3D File is too small."); if( fileSize<8 ) throw new ImportErrorException( "B3D File is too small.");
_pos=0; _pos=0;
_buf.resize( fileSize ); _buf.resize( fileSize );
@ -94,22 +94,28 @@ void B3DImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
ReadBB3D(); ReadBB3D();
//materials //materials
aiMaterial **mats=new aiMaterial*[_materials.size()]; if( _materials.size() ){
for( unsigned i=0;i<_materials.size();++i ){ aiMaterial **mats=new aiMaterial*[_materials.size()];
mats[i]=_materials[i]; for( unsigned i=0;i<_materials.size();++i ){
mats[i]=_materials[i];
}
pScene->mNumMaterials=_materials.size();
pScene->mMaterials=mats;
} }
pScene->mNumMaterials=_materials.size();
pScene->mMaterials=mats;
//meshes //meshes
aiMesh **meshes=new aiMesh*[_meshes.size()]; if( _meshes.size() ){
for( unsigned i=0;i<_meshes.size();++i ){ aiMesh **meshes=new aiMesh*[_meshes.size()];
meshes[i]=_meshes[i]; for( unsigned i=0;i<_meshes.size();++i ){
meshes[i]=_meshes[i];
}
pScene->mNumMeshes=_meshes.size();
pScene->mMeshes=meshes;
}else{
throw new ImportErrorException( "B3D: No meshes loaded" );
} }
pScene->mNumMeshes=_meshes.size();
pScene->mMeshes=meshes;
//nodes - NOTE: Have to create mMeshes array here or crash 'n' burn. //create root node
aiNode *node=new aiNode( "root" ); aiNode *node=new aiNode( "root" );
node->mNumMeshes=_meshes.size(); node->mNumMeshes=_meshes.size();
node->mMeshes=new unsigned[_meshes.size()]; node->mMeshes=new unsigned[_meshes.size()];
@ -275,11 +281,11 @@ void B3DImporter::ReadBRUS(){
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void B3DImporter::ReadVRTS(){ void B3DImporter::ReadVRTS(){
int vertFlags=ReadInt(); _vertFlags=ReadInt();
int tc_sets=ReadInt(); _tcSets=ReadInt();
int tc_size=ReadInt(); _tcSize=ReadInt();
if( tc_sets<0 || tc_sets>4 || tc_size<0 || tc_size>4 ) throw new ImportErrorException( "B3D Param Error" ); if( _tcSets<0 || _tcSets>4 || _tcSize<0 || _tcSize>4 ) throw new ImportErrorException( "B3D Param Error" );
while( ChunkSize() ){ while( ChunkSize() ){
Vertex vert; Vertex vert;
@ -287,18 +293,18 @@ void B3DImporter::ReadVRTS(){
vert.position=ReadVec3(); vert.position=ReadVec3();
std::swap( vert.position.y,vert.position.z ); std::swap( vert.position.y,vert.position.z );
if( vertFlags & 1 ){ if( _vertFlags & 1 ){
vert.normal=ReadVec3(); vert.normal=ReadVec3();
std::swap( vert.normal.y,vert.normal.z ); std::swap( vert.normal.y,vert.normal.z );
} }
if( vertFlags & 2 ){ if( _vertFlags & 2 ){
Vec4 color=ReadVec4(); Vec4 color=ReadVec4();
} }
for( int i=0;i<tc_sets;++i ){ for( int i=0;i<_tcSets;++i ){
float texcoords[4]={0,0,0,0}; float texcoords[4]={0,0,0,0};
for( int j=0;j<tc_size;++j ){ for( int j=0;j<_tcSize;++j ){
texcoords[j]=ReadFloat(); texcoords[j]=ReadFloat();
} }
texcoords[1]=1-texcoords[1]; texcoords[1]=1-texcoords[1];
@ -323,9 +329,11 @@ void B3DImporter::ReadTRIS(){
mesh->mNumFaces=n_tris; mesh->mNumFaces=n_tris;
mesh->mPrimitiveTypes=aiPrimitiveType_TRIANGLE; mesh->mPrimitiveTypes=aiPrimitiveType_TRIANGLE;
aiVector3D *mv=mesh->mVertices=new aiVector3D[n_verts]; aiVector3D *mv,*mn=0,*mc=0;
aiVector3D *mn=mesh->mNormals=new aiVector3D[n_verts];
aiVector3D *mc=mesh->mTextureCoords[0]=new aiVector3D[n_verts]; mv=mesh->mVertices=new aiVector3D[n_verts];
if( _vertFlags & 1 ) mn=mesh->mNormals=new aiVector3D[n_verts];
if( _tcSets ) mc=mesh->mTextureCoords[0]=new aiVector3D[n_verts];
aiFace *face=mesh->mFaces=new aiFace[n_tris]; aiFace *face=mesh->mFaces=new aiFace[n_tris];
@ -337,11 +345,11 @@ void B3DImporter::ReadTRIS(){
v[2]=ReadInt(); v[2]=ReadInt();
v[1]=ReadInt(); v[1]=ReadInt();
for( unsigned j=0;j<3;++j ){ for( unsigned j=0;j<3;++j ){
int k=v[j];//ReadInt(); int k=v[j];
const Vertex &v=_vertices[k]; const Vertex &v=_vertices[k];
memcpy( mv++,&v.position.x,12 ); memcpy( mv++,&v.position.x,12 );
memcpy( mn++,&v.normal.x,12 ); if( mn ) memcpy( mn++,&v.normal.x,12 );
memcpy( mc++,&v.texcoords.x,12 ); if( mc ) memcpy( mc++,&v.texcoords.x,12 );
*ip++=i+j; *ip++=i+j;
} }
++face; ++face;
@ -372,10 +380,13 @@ void B3DImporter::ReadNODE(){
string name=ReadString(); string name=ReadString();
Vec3 trans=ReadVec3(); Vec3 trans=ReadVec3();
std::swap( trans.y,trans.z );
Vec3 scale=ReadVec3(); Vec3 scale=ReadVec3();
Vec4 rot=ReadVec4(); Vec4 rot=ReadVec4();
std::swap( trans.y,trans.z );
std::swap( scale.y,scale.z );
//do something to rot?!?
while( ChunkSize() ){ while( ChunkSize() ){
string t=ReadChunk(); string t=ReadChunk();
if( t=="MESH" ){ if( t=="MESH" ){

View File

@ -95,6 +95,7 @@ private:
std::vector<unsigned char> _buf; std::vector<unsigned char> _buf;
std::vector<unsigned> _stack; std::vector<unsigned> _stack;
int _vertFlags,_tcSets,_tcSize;
std::vector<Texture> _textures; std::vector<Texture> _textures;
std::vector<MaterialHelper*> _materials; std::vector<MaterialHelper*> _materials;
std::vector<Vertex> _vertices; std::vector<Vertex> _vertices;