Added (basic) Blender 2.63 support. No uvs or colours supported yet.
parent
358cb9b4c7
commit
eaf9cbc120
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
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;
|
||||
if (!mesh->totface || !mesh->totvert) {
|
||||
if ((!mesh->totface && !mesh->totloop) || !mesh->totvert) {
|
||||
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");
|
||||
}
|
||||
|
||||
if (static_cast<size_t> ( mesh->totloop ) > mesh->mloop.size()) {
|
||||
ThrowException("Number of vertices is larger than the corresponding array");
|
||||
}
|
||||
|
||||
// collect per-submesh numbers
|
||||
std::map<int,size_t> per_mat;
|
||||
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];
|
||||
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
|
||||
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
|
||||
if (mesh->mtface) {
|
||||
if (mesh->totface > static_cast<int> ( mesh->mtface.size())) {
|
||||
|
|
|
@ -316,6 +316,8 @@ template <> void Structure :: Convert<Mesh> (
|
|||
ReadField<ErrorPolicy_Fail>(dest.totface,"totface",db);
|
||||
ReadField<ErrorPolicy_Fail>(dest.totedge,"totedge",db);
|
||||
ReadField<ErrorPolicy_Fail>(dest.totvert,"totvert",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.totloop,"totloop",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.totpoly,"totpoly",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.subdiv,"subdiv",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.subdivr,"subdivr",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.subsurftype,"subsurftype",db);
|
||||
|
@ -325,6 +327,8 @@ template <> void Structure :: Convert<Mesh> (
|
|||
ReadFieldPtr<ErrorPolicy_Igno>(dest.tface,"*tface",db);
|
||||
ReadFieldPtr<ErrorPolicy_Fail>(dest.mvert,"*mvert",db);
|
||||
ReadFieldPtr<ErrorPolicy_Warn>(dest.medge,"*medge",db);
|
||||
ReadFieldPtr<ErrorPolicy_Igno>(dest.mloop,"*mloop",db);
|
||||
ReadFieldPtr<ErrorPolicy_Igno>(dest.mpoly,"*mpoly",db);
|
||||
ReadFieldPtr<ErrorPolicy_Igno>(dest.dvert,"*dvert",db);
|
||||
ReadFieldPtr<ErrorPolicy_Igno>(dest.mcol,"*mcol",db);
|
||||
ReadFieldPtr<ErrorPolicy_Fail>(dest.mat,"**mat",db);
|
||||
|
@ -416,6 +420,19 @@ template <> void Structure :: Convert<ListBase> (
|
|||
db.reader->IncPtr(size);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
template <> void Structure :: Convert<MLoop> (
|
||||
MLoop& dest,
|
||||
const FileDatabase& db
|
||||
) const
|
||||
{
|
||||
|
||||
ReadField<ErrorPolicy_Igno>(dest.v,"v",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.e,"e",db);
|
||||
|
||||
db.reader->IncPtr(size);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
template <> void Structure :: Convert<ModifierData> (
|
||||
ModifierData& dest,
|
||||
|
@ -461,34 +478,16 @@ template <> void Structure :: Convert<MCol> (
|
|||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
template <> void Structure :: Convert<Image> (
|
||||
Image& dest,
|
||||
template <> void Structure :: Convert<MPoly> (
|
||||
MPoly& dest,
|
||||
const FileDatabase& db
|
||||
) const
|
||||
{
|
||||
|
||||
ReadField<ErrorPolicy_Fail>(dest.id,"id",db);
|
||||
ReadFieldArray<ErrorPolicy_Warn>(dest.name,"name",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.ok,"ok",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.loopstart,"loopstart",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.totloop,"totloop",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.mat_nr,"mat_nr",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.flag,"flag",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.source,"source",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.type,"type",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.pad,"pad",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.pad1,"pad1",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.lastframe,"lastframe",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.tpageflag,"tpageflag",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.totbind,"totbind",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.xrep,"xrep",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.yrep,"yrep",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.twsta,"twsta",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.twend,"twend",db);
|
||||
ReadFieldPtr<ErrorPolicy_Igno>(dest.packedfile,"*packedfile",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.lastupdate,"lastupdate",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.lastused,"lastused",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.animspeed,"animspeed",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.gen_x,"gen_x",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.gen_y,"gen_y",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.gen_type,"gen_type",db);
|
||||
|
||||
db.reader->IncPtr(size);
|
||||
}
|
||||
|
@ -568,6 +567,39 @@ template <> void Structure :: Convert<MirrorModifierData> (
|
|||
db.reader->IncPtr(size);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
template <> void Structure :: Convert<Image> (
|
||||
Image& dest,
|
||||
const FileDatabase& db
|
||||
) const
|
||||
{
|
||||
|
||||
ReadField<ErrorPolicy_Fail>(dest.id,"id",db);
|
||||
ReadFieldArray<ErrorPolicy_Warn>(dest.name,"name",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.ok,"ok",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.flag,"flag",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.source,"source",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.type,"type",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.pad,"pad",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.pad1,"pad1",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.lastframe,"lastframe",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.tpageflag,"tpageflag",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.totbind,"totbind",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.xrep,"xrep",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.yrep,"yrep",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.twsta,"twsta",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.twend,"twend",db);
|
||||
ReadFieldPtr<ErrorPolicy_Igno>(dest.packedfile,"*packedfile",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.lastupdate,"lastupdate",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.lastused,"lastused",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.animspeed,"animspeed",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.gen_x,"gen_x",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.gen_y,"gen_y",db);
|
||||
ReadField<ErrorPolicy_Igno>(dest.gen_type,"gen_type",db);
|
||||
|
||||
db.reader->IncPtr(size);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
void DNA::RegisterConverters() {
|
||||
|
||||
|
@ -590,15 +622,17 @@ void DNA::RegisterConverters() {
|
|||
converters["MEdge"] = DNA::FactoryPair( &Structure::Allocate<MEdge>, &Structure::Convert<MEdge> );
|
||||
converters["GroupObject"] = DNA::FactoryPair( &Structure::Allocate<GroupObject>, &Structure::Convert<GroupObject> );
|
||||
converters["ListBase"] = DNA::FactoryPair( &Structure::Allocate<ListBase>, &Structure::Convert<ListBase> );
|
||||
converters["MLoop"] = DNA::FactoryPair( &Structure::Allocate<MLoop>, &Structure::Convert<MLoop> );
|
||||
converters["ModifierData"] = DNA::FactoryPair( &Structure::Allocate<ModifierData>, &Structure::Convert<ModifierData> );
|
||||
converters["ID"] = DNA::FactoryPair( &Structure::Allocate<ID>, &Structure::Convert<ID> );
|
||||
converters["MCol"] = DNA::FactoryPair( &Structure::Allocate<MCol>, &Structure::Convert<MCol> );
|
||||
converters["Image"] = DNA::FactoryPair( &Structure::Allocate<Image>, &Structure::Convert<Image> );
|
||||
converters["MPoly"] = DNA::FactoryPair( &Structure::Allocate<MPoly>, &Structure::Convert<MPoly> );
|
||||
converters["Scene"] = DNA::FactoryPair( &Structure::Allocate<Scene>, &Structure::Convert<Scene> );
|
||||
converters["Library"] = DNA::FactoryPair( &Structure::Allocate<Library>, &Structure::Convert<Library> );
|
||||
converters["Tex"] = DNA::FactoryPair( &Structure::Allocate<Tex>, &Structure::Convert<Tex> );
|
||||
converters["Camera"] = DNA::FactoryPair( &Structure::Allocate<Camera>, &Structure::Convert<Camera> );
|
||||
converters["MirrorModifierData"] = DNA::FactoryPair( &Structure::Allocate<MirrorModifierData>, &Structure::Convert<MirrorModifierData> );
|
||||
converters["Image"] = DNA::FactoryPair( &Structure::Allocate<Image>, &Structure::Convert<Image> );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -156,6 +156,19 @@ struct MEdge : ElemBase {
|
|||
short flag;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MLoop : ElemBase {
|
||||
int v, e;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MPoly : ElemBase {
|
||||
int loopstart;
|
||||
int totloop;
|
||||
short mat_nr;
|
||||
char flag;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
struct MCol : ElemBase {
|
||||
char r,g,b,a FAIL;
|
||||
|
@ -235,6 +248,8 @@ struct Mesh : ElemBase {
|
|||
int totface FAIL;
|
||||
int totedge FAIL;
|
||||
int totvert FAIL;
|
||||
int totloop;
|
||||
int totpoly;
|
||||
|
||||
short subdiv;
|
||||
short subdivr;
|
||||
|
@ -246,6 +261,8 @@ struct Mesh : ElemBase {
|
|||
vector<TFace> tface;
|
||||
vector<MVert> mvert FAIL;
|
||||
vector<MEdge> medge WARN;
|
||||
vector<MLoop> mloop;
|
||||
vector<MPoly> mpoly;
|
||||
vector<MDeformVert> dvert;
|
||||
vector<MCol> mcol;
|
||||
|
||||
|
|
|
@ -162,6 +162,12 @@ template <> void Structure :: Convert<ListBase> (
|
|||
) const
|
||||
;
|
||||
|
||||
template <> void Structure :: Convert<MLoop> (
|
||||
MLoop& dest,
|
||||
const FileDatabase& db
|
||||
) const
|
||||
;
|
||||
|
||||
template <> void Structure :: Convert<ModifierData> (
|
||||
ModifierData& dest,
|
||||
const FileDatabase& db
|
||||
|
@ -180,8 +186,8 @@ template <> void Structure :: Convert<MCol> (
|
|||
) const
|
||||
;
|
||||
|
||||
template <> void Structure :: Convert<Image> (
|
||||
Image& dest,
|
||||
template <> void Structure :: Convert<MPoly> (
|
||||
MPoly& dest,
|
||||
const FileDatabase& db
|
||||
) const
|
||||
;
|
||||
|
@ -216,6 +222,12 @@ template <> void Structure :: Convert<MirrorModifierData> (
|
|||
) const
|
||||
;
|
||||
|
||||
template <> void Structure :: Convert<Image> (
|
||||
Image& dest,
|
||||
const FileDatabase& db
|
||||
) const
|
||||
;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,8 @@ def main():
|
|||
# Parse structure definitions from BlenderScene.h
|
||||
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)
|
||||
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)
|
||||
|
@ -143,7 +144,8 @@ def main():
|
|||
|
||||
input = input[match.end():]
|
||||
|
||||
[print ("Enum: "+e) for e in enums]
|
||||
for e in enums:
|
||||
print("Enum: "+e)
|
||||
for k,v in hits.items():
|
||||
out = []
|
||||
for line in v:
|
||||
|
@ -177,7 +179,8 @@ def main():
|
|||
|
||||
v[:] = out
|
||||
print("Structure {0}".format(k))
|
||||
[print("\t"+"\t".join(elem)) for elem in out]
|
||||
for elem in out:
|
||||
print("\t"+"\t".join(elem))
|
||||
print("")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue