Added (basic) Blender 2.63 support. No uvs or colours supported yet.

pull/21/head
Kester Maddock 2012-12-24 15:11:46 +00:00 committed by Alexander Gessler
parent 358cb9b4c7
commit eaf9cbc120
5 changed files with 844 additions and 721 deletions

View File

@ -1,3 +1,4 @@
/* /*
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
@ -624,7 +625,7 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co
) )
{ {
typedef std::pair<const int,size_t> MyPair; typedef std::pair<const int,size_t> MyPair;
if (!mesh->totface || !mesh->totvert) { if ((!mesh->totface && !mesh->totloop) || !mesh->totvert) {
return; return;
} }
@ -637,6 +638,10 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co
ThrowException("Number of vertices is larger than the corresponding array"); ThrowException("Number of vertices is larger than the corresponding array");
} }
if (static_cast<size_t> ( mesh->totloop ) > mesh->mloop.size()) {
ThrowException("Number of vertices is larger than the corresponding array");
}
// collect per-submesh numbers // collect per-submesh numbers
std::map<int,size_t> per_mat; std::map<int,size_t> per_mat;
for (int i = 0; i < mesh->totface; ++i) { for (int i = 0; i < mesh->totface; ++i) {
@ -644,6 +649,10 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co
const MFace& mf = mesh->mface[i]; const MFace& mf = mesh->mface[i];
per_mat[ mf.mat_nr ]++; per_mat[ mf.mat_nr ]++;
} }
for (int i = 0; i < mesh->totpoly; ++i) {
const MPoly& mp = mesh->mpoly[i];
per_mat[ mp.mat_nr ]++;
}
// ... and allocate the corresponding meshes // ... and allocate the corresponding meshes
const size_t old = temp->size(); const size_t old = temp->size();
@ -780,6 +789,54 @@ void BlenderImporter::ConvertMesh(const Scene& /*in*/, const Object* /*obj*/, co
// } // }
} }
for (int i = 0; i < mesh->totpoly; ++i) {
const MPoly& mf = mesh->mpoly[i];
aiMesh* const out = temp[ mat_num_to_mesh_idx[ mf.mat_nr ] ];
aiFace& f = out->mFaces[out->mNumFaces++];
f.mIndices = new unsigned int[ f.mNumIndices = mf.totloop ];
aiVector3D* vo = out->mVertices + out->mNumVertices;
aiVector3D* vn = out->mNormals + out->mNumVertices;
// XXX we can't fold this easily, because we are restricted
// to the member names from the BLEND file (v1,v2,v3,v4)
// which are assigned by the genblenddna.py script and
// cannot be changed without breaking the entire
// import process.
for (int j = 0;j < mf.totloop; ++j)
{
const MLoop& loop = mesh->mloop[mf.loopstart + j];
if (loop.v >= mesh->totvert) {
ThrowException("Vertex index out of range");
}
const MVert& v = mesh->mvert[loop.v];
vo->x = v.co[0];
vo->y = v.co[1];
vo->z = v.co[2];
vn->x = v.no[0];
vn->y = v.no[1];
vn->z = v.no[2];
f.mIndices[j] = out->mNumVertices++;
++vo;
++vn;
}
if (mf.totloop == 3)
{
out->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE;
}
else
{
out->mPrimitiveTypes |= aiPrimitiveType_POLYGON;
}
}
// collect texture coordinates, they're stored in a separate per-face buffer // collect texture coordinates, they're stored in a separate per-face buffer
if (mesh->mtface) { if (mesh->mtface) {
if (mesh->totface > static_cast<int> ( mesh->mtface.size())) { if (mesh->totface > static_cast<int> ( mesh->mtface.size())) {

File diff suppressed because it is too large Load Diff

View File

@ -156,6 +156,19 @@ struct MEdge : ElemBase {
short flag; short flag;
}; };
// -------------------------------------------------------------------------------
struct MLoop : ElemBase {
int v, e;
};
// -------------------------------------------------------------------------------
struct MPoly : ElemBase {
int loopstart;
int totloop;
short mat_nr;
char flag;
};
// ------------------------------------------------------------------------------- // -------------------------------------------------------------------------------
struct MCol : ElemBase { struct MCol : ElemBase {
char r,g,b,a FAIL; char r,g,b,a FAIL;
@ -235,6 +248,8 @@ struct Mesh : ElemBase {
int totface FAIL; int totface FAIL;
int totedge FAIL; int totedge FAIL;
int totvert FAIL; int totvert FAIL;
int totloop;
int totpoly;
short subdiv; short subdiv;
short subdivr; short subdivr;
@ -246,6 +261,8 @@ struct Mesh : ElemBase {
vector<TFace> tface; vector<TFace> tface;
vector<MVert> mvert FAIL; vector<MVert> mvert FAIL;
vector<MEdge> medge WARN; vector<MEdge> medge WARN;
vector<MLoop> mloop;
vector<MPoly> mpoly;
vector<MDeformVert> dvert; vector<MDeformVert> dvert;
vector<MCol> mcol; vector<MCol> mcol;

View File

@ -47,174 +47,186 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Assimp { namespace Assimp {
namespace Blender { namespace Blender {
template <> void Structure :: Convert<Object> ( template <> void Structure :: Convert<Object> (
Object& dest, Object& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<Group> ( template <> void Structure :: Convert<Group> (
Group& dest, Group& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<MTex> ( template <> void Structure :: Convert<MTex> (
MTex& dest, MTex& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<TFace> ( template <> void Structure :: Convert<TFace> (
TFace& dest, TFace& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<SubsurfModifierData> ( template <> void Structure :: Convert<SubsurfModifierData> (
SubsurfModifierData& dest, SubsurfModifierData& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<MFace> ( template <> void Structure :: Convert<MFace> (
MFace& dest, MFace& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<Lamp> ( template <> void Structure :: Convert<Lamp> (
Lamp& dest, Lamp& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<MDeformWeight> ( template <> void Structure :: Convert<MDeformWeight> (
MDeformWeight& dest, MDeformWeight& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<PackedFile> ( template <> void Structure :: Convert<PackedFile> (
PackedFile& dest, PackedFile& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<Base> ( template <> void Structure :: Convert<Base> (
Base& dest, Base& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<MTFace> ( template <> void Structure :: Convert<MTFace> (
MTFace& dest, MTFace& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<Material> ( template <> void Structure :: Convert<Material> (
Material& dest, Material& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<Mesh> ( template <> void Structure :: Convert<Mesh> (
Mesh& dest, Mesh& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<MDeformVert> ( template <> void Structure :: Convert<MDeformVert> (
MDeformVert& dest, MDeformVert& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<World> ( template <> void Structure :: Convert<World> (
World& dest, World& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<MVert> ( template <> void Structure :: Convert<MVert> (
MVert& dest, MVert& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<MEdge> ( template <> void Structure :: Convert<MEdge> (
MEdge& dest, MEdge& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<GroupObject> ( template <> void Structure :: Convert<GroupObject> (
GroupObject& dest, GroupObject& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<ListBase> ( template <> void Structure :: Convert<ListBase> (
ListBase& dest, ListBase& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<ModifierData> ( template <> void Structure :: Convert<MLoop> (
ModifierData& dest, MLoop& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<ID> ( template <> void Structure :: Convert<ModifierData> (
ID& dest, ModifierData& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<MCol> ( template <> void Structure :: Convert<ID> (
MCol& dest, ID& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<Image> ( template <> void Structure :: Convert<MCol> (
Image& dest, MCol& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<Scene> ( template <> void Structure :: Convert<MPoly> (
Scene& dest, MPoly& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<Library> ( template <> void Structure :: Convert<Scene> (
Library& dest, Scene& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<Tex> ( template <> void Structure :: Convert<Library> (
Tex& dest, Library& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<Camera> ( template <> void Structure :: Convert<Tex> (
Camera& dest, Tex& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<MirrorModifierData> ( template <> void Structure :: Convert<Camera> (
MirrorModifierData& dest, Camera& dest,
const FileDatabase& db const FileDatabase& db
) const ) const
; ;
template <> void Structure :: Convert<MirrorModifierData> (
MirrorModifierData& dest,
const FileDatabase& db
) const
;
template <> void Structure :: Convert<Image> (
Image& dest,
const FileDatabase& db
) const
;
} }

View File

@ -105,7 +105,8 @@ def main():
# Parse structure definitions from BlenderScene.h # Parse structure definitions from BlenderScene.h
input = open(inputfile,"rt").read() input = open(inputfile,"rt").read()
flags = re.ASCII|re.DOTALL|re.MULTILINE #flags = re.ASCII|re.DOTALL|re.MULTILINE
flags = re.DOTALL|re.MULTILINE
#stripcoms = re.compile(r"/\*(.*?)*\/",flags) #stripcoms = re.compile(r"/\*(.*?)*\/",flags)
getstruct = re.compile(r"struct\s+(\w+?)\s*(:\s*ElemBase)?\s*\{(.*?)^\}\s*;",flags) getstruct = re.compile(r"struct\s+(\w+?)\s*(:\s*ElemBase)?\s*\{(.*?)^\}\s*;",flags)
getsmartx = re.compile(r"(std\s*::\s*)?(vector)\s*<\s*(boost\s*::\s*)?shared_(ptr)\s*<\s*(\w+)\s*>\s*>\s*",flags) getsmartx = re.compile(r"(std\s*::\s*)?(vector)\s*<\s*(boost\s*::\s*)?shared_(ptr)\s*<\s*(\w+)\s*>\s*>\s*",flags)
@ -143,7 +144,8 @@ def main():
input = input[match.end():] input = input[match.end():]
[print ("Enum: "+e) for e in enums] for e in enums:
print("Enum: "+e)
for k,v in hits.items(): for k,v in hits.items():
out = [] out = []
for line in v: for line in v:
@ -177,7 +179,8 @@ def main():
v[:] = out v[:] = out
print("Structure {0}".format(k)) print("Structure {0}".format(k))
[print("\t"+"\t".join(elem)) for elem in out] for elem in out:
print("\t"+"\t".join(elem))
print("") print("")