From 4e9214c624085d4f8f1e16fa932db197c20bd0ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9verin=20Lemaignan?= Date: Wed, 17 Oct 2012 17:17:51 +0200 Subject: [PATCH] [pyassimp] Apply post-processing on ctypes ASSIMP structure - bind meshes to their materials - add transformations to cameras --- port/PyAssimp/pyassimp/__init__.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/port/PyAssimp/pyassimp/__init__.py b/port/PyAssimp/pyassimp/__init__.py index 72a7dae3a..cad308201 100644 --- a/port/PyAssimp/pyassimp/__init__.py +++ b/port/PyAssimp/pyassimp/__init__.py @@ -205,6 +205,7 @@ def pythonize_assimp(type, obj, scene): Supported operations: - MESH: replace a list of mesh IDs by reference to these meshes + - ADDTRANSFORMATION: add a reference to an object's transformation taken from their associated node. :param type: the type of modification to operate (cf above) :param obj: the input object to modify @@ -217,6 +218,19 @@ def pythonize_assimp(type, obj, scene): meshes.append(scene.meshes[i]) return meshes + if type == "ADDTRANSFORMATION": + + def getnode(node, name): + if node.name == name: return node + for child in node.children: + n = getnode(child, name) + if n: return n + + node = getnode(scene.rootnode, obj.name) + if not node: + raise AssimpError("Object " + str(obj) + " has no associated node!") + setattr(obj, "transformation", node.transformation) + def recur_pythonize(node, scene): """ Recursively call pythonize_assimp on @@ -226,6 +240,15 @@ def recur_pythonize(node, scene): node.meshes = pythonize_assimp("MESH", node.meshes, scene) + for mesh in node.meshes: + mesh.material = scene.materials[mesh.materialindex] + + for cam in scene.cameras: + pythonize_assimp("ADDTRANSFORMATION", cam, scene) + + #for light in scene.lights: + # pythonize_assimp("ADDTRANSFORMATION", light, scene) + for c in node.children: recur_pythonize(c, scene) @@ -293,9 +316,9 @@ def _finalize_mesh(mesh, target): data = [] for index, mSubAttr in enumerate(mAttr): if mSubAttr: - data.append([make_tuple(getattr(mesh, name)[index][i]) for i in xrange(nb_vertices)], dtype=numpy.float32) + data.append([make_tuple(getattr(mesh, name)[index][i]) for i in xrange(nb_vertices)]) - setattr(target, name[1:].lower(), numpy.array(data)) + setattr(target, name[1:].lower(), numpy.array(data, dtype=numpy.float32)) fill("mNormals") fill("mTangents")