diff --git a/code/BlenderLoader.cpp b/code/BlenderLoader.cpp index a475b7442..3b9200b14 100644 --- a/code/BlenderLoader.cpp +++ b/code/BlenderLoader.cpp @@ -838,7 +838,7 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co } // collect texture coordinates, they're stored in a separate per-face buffer - if (mesh->mtface) { + if (mesh->mtface || mesh->mloopuv) { if (mesh->totface > static_cast ( mesh->mtface.size())) { ThrowException("Number of UV faces is larger than the corresponding UV face array (#1)"); } @@ -861,6 +861,20 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co vo->y = v->uv[i][1]; } } + + for (int i = 0; i < mesh->totpoly; ++i) { + const MPoly& v = mesh->mpoly[i]; + aiMesh* const out = temp[ mat_num_to_mesh_idx[ v.mat_nr ] ]; + const aiFace& f = out->mFaces[out->mNumFaces++]; + + aiVector3D* vo = &out->mTextureCoords[0][out->mNumVertices]; + for (unsigned int j = 0; j < f.mNumIndices; ++j,++vo,++out->mNumVertices) { + const MLoopUV& uv = mesh->mloopuv[v.loopstart + j]; + vo->x = uv.uv[0]; + vo->y = uv.uv[1]; + } + + } } // collect texture coordinates, old-style (marked as deprecated in current blender sources) @@ -890,7 +904,7 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co } // collect vertex colors, stored separately as well - if (mesh->mcol) { + if (mesh->mcol || mesh->mloopcol) { if (mesh->totface > static_cast ( (mesh->mcol.size()/4)) ) { ThrowException("Number of faces is larger than the corresponding color face array"); } @@ -917,6 +931,23 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co } for (unsigned int n = f.mNumIndices; n < 4; ++n); } + + for (int i = 0; i < mesh->totpoly; ++i) { + const MPoly& v = mesh->mpoly[i]; + aiMesh* const out = temp[ mat_num_to_mesh_idx[ v.mat_nr ] ]; + const aiFace& f = out->mFaces[out->mNumFaces++]; + + aiColor4D* vo = &out->mColors[0][out->mNumVertices]; + for (unsigned int j = 0; j < f.mNumIndices; ++j,++vo,++out->mNumVertices) { + const MLoopCol& col = mesh->mloopcol[v.loopstart + j]; + vo->r = col.r; + vo->g = col.g; + vo->b = col.b; + vo->a = col.a; + } + + } + } return; diff --git a/code/BlenderScene.cpp b/code/BlenderScene.cpp index 435db07bc..1ee9e1cf9 100644 --- a/code/BlenderScene.cpp +++ b/code/BlenderScene.cpp @@ -305,6 +305,27 @@ template <> void Structure :: Convert ( db.reader->IncPtr(size); } +//-------------------------------------------------------------------------------- +template <> void Structure :: Convert ( + MTexPoly& dest, + const FileDatabase& db + ) const +{ + + { + boost::shared_ptr tpage; + ReadFieldPtr(tpage,"*tpage",db); + dest.tpage = tpage.get(); + } + ReadField(dest.flag,"flag",db); + ReadField(dest.transp,"transp",db); + ReadField(dest.mode,"mode",db); + ReadField(dest.tile,"tile",db); + ReadField(dest.pad,"pad",db); + + db.reader->IncPtr(size); +} + //-------------------------------------------------------------------------------- template <> void Structure :: Convert ( Mesh& dest, @@ -328,7 +349,10 @@ template <> void Structure :: Convert ( ReadFieldPtr(dest.mvert,"*mvert",db); ReadFieldPtr(dest.medge,"*medge",db); ReadFieldPtr(dest.mloop,"*mloop",db); + ReadFieldPtr(dest.mloopuv,"*mloopuv",db); + ReadFieldPtr(dest.mloopcol,"*mloopcol",db); ReadFieldPtr(dest.mpoly,"*mpoly",db); + ReadFieldPtr(dest.mtpoly,"*mtpoly",db); ReadFieldPtr(dest.dvert,"*dvert",db); ReadFieldPtr(dest.mcol,"*mcol",db); ReadFieldPtr(dest.mat,"**mat",db); @@ -361,6 +385,21 @@ template <> void Structure :: Convert ( db.reader->IncPtr(size); } +//-------------------------------------------------------------------------------- +template <> void Structure :: Convert ( + MLoopCol& dest, + const FileDatabase& db + ) const +{ + + ReadField(dest.r,"r",db); + ReadField(dest.g,"g",db); + ReadField(dest.b,"b",db); + ReadField(dest.a,"a",db); + + db.reader->IncPtr(size); +} + //-------------------------------------------------------------------------------- template <> void Structure :: Convert ( MVert& dest, @@ -393,6 +432,19 @@ template <> void Structure :: Convert ( db.reader->IncPtr(size); } +//-------------------------------------------------------------------------------- +template <> void Structure :: Convert ( + MLoopUV& dest, + const FileDatabase& db + ) const +{ + + ReadFieldArray(dest.uv,"uv",db); + ReadField(dest.flag,"flag",db); + + db.reader->IncPtr(size); +} + //-------------------------------------------------------------------------------- template <> void Structure :: Convert ( GroupObject& dest, @@ -615,11 +667,14 @@ void DNA::RegisterConverters() { converters["Base"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); converters["MTFace"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); converters["Material"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); + converters["MTexPoly"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); converters["Mesh"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); converters["MDeformVert"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); converters["World"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); + converters["MLoopCol"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); converters["MVert"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); converters["MEdge"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); + converters["MLoopUV"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); converters["GroupObject"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); converters["ListBase"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); converters["MLoop"] = DNA::FactoryPair( &Structure::Allocate, &Structure::Convert ); diff --git a/code/BlenderScene.h b/code/BlenderScene.h index cc4a7ab50..ec56fc300 100644 --- a/code/BlenderScene.h +++ b/code/BlenderScene.h @@ -94,6 +94,7 @@ namespace Assimp { struct Object; struct MTex; +struct Image; #define AI_BLEND_MESH_MAX_VERTS 2000000000L @@ -161,6 +162,18 @@ struct MLoop : ElemBase { int v, e; }; +// ------------------------------------------------------------------------------- +struct MLoopUV : ElemBase { + float uv[2]; + int flag; +}; + +// ------------------------------------------------------------------------------- +// Note that red and blue are not swapped, as with MCol +struct MLoopCol : ElemBase { + char r, g, b, a; +}; + // ------------------------------------------------------------------------------- struct MPoly : ElemBase { int loopstart; @@ -169,6 +182,13 @@ struct MPoly : ElemBase { char flag; }; +// ------------------------------------------------------------------------------- +struct MTexPoly : ElemBase { + Image* tpage; + char flag, transp; + short mode, tile, pad; +}; + // ------------------------------------------------------------------------------- struct MCol : ElemBase { char r,g,b,a FAIL; @@ -262,7 +282,10 @@ struct Mesh : ElemBase { vector mvert FAIL; vector medge WARN; vector mloop; + vector mloopuv; + vector mloopcol; vector mpoly; + vector mtpoly; vector dvert; vector mcol; diff --git a/code/BlenderSceneGen.h b/code/BlenderSceneGen.h index a243b6db5..4420ce358 100644 --- a/code/BlenderSceneGen.h +++ b/code/BlenderSceneGen.h @@ -120,6 +120,12 @@ template <> void Structure :: Convert ( ) const ; +template <> void Structure :: Convert ( + MTexPoly& dest, + const FileDatabase& db + ) const +; + template <> void Structure :: Convert ( Mesh& dest, const FileDatabase& db @@ -138,6 +144,12 @@ template <> void Structure :: Convert ( ) const ; +template <> void Structure :: Convert ( + MLoopCol& dest, + const FileDatabase& db + ) const +; + template <> void Structure :: Convert ( MVert& dest, const FileDatabase& db @@ -150,6 +162,12 @@ template <> void Structure :: Convert ( ) const ; +template <> void Structure :: Convert ( + MLoopUV& dest, + const FileDatabase& db + ) const +; + template <> void Structure :: Convert ( GroupObject& dest, const FileDatabase& db