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)
----------------------------------------------------------------------
@ -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())) {

File diff suppressed because it is too large Load Diff

View File

@ -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;

View File

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