From 76d2eb7057b779083036242160ed5c5f1a919af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9verin=20Lemaignan?= Date: Fri, 9 Nov 2012 18:06:31 +0100 Subject: [PATCH] [pyassimp] Rework material dict - Normalize the names - Do not create numpy arrays for the properties --- port/PyAssimp/pyassimp/core.py | 9 ++++++--- port/PyAssimp/scripts/opengl_viewer.py | 14 +++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/port/PyAssimp/pyassimp/core.py b/port/PyAssimp/pyassimp/core.py index 731dcd5a3..6844b2e73 100644 --- a/port/PyAssimp/pyassimp/core.py +++ b/port/PyAssimp/pyassimp/core.py @@ -348,21 +348,24 @@ def _get_properties(properties, length): for p in [properties[i] for i in range(length)]: #the name p = p.contents - key = str(p.mKey.data) + key = str(p.mKey.data).split('.')[1] #the data from ctypes import POINTER, cast, c_int, c_float, sizeof if p.mType == 1: arr = cast(p.mData, POINTER(c_float * int(p.mDataLength/sizeof(c_float)) )).contents - value = numpy.array([x for x in arr]) + value = [x for x in arr] elif p.mType == 3: #string can't be an array value = cast(p.mData, POINTER(structs.String)).contents.data elif p.mType == 4: arr = cast(p.mData, POINTER(c_int * int(p.mDataLength/sizeof(c_int)) )).contents - value = numpy.array([x for x in arr]) + value = [x for x in arr] else: value = p.mData[:p.mDataLength] + if len(value) == 1: + [value] = value + result[key] = value return result diff --git a/port/PyAssimp/scripts/opengl_viewer.py b/port/PyAssimp/scripts/opengl_viewer.py index 2cfc4748c..f7f4a95f8 100755 --- a/port/PyAssimp/scripts/opengl_viewer.py +++ b/port/PyAssimp/scripts/opengl_viewer.py @@ -200,13 +200,13 @@ class GLRenderer(): if not hasattr(mat, "gl_mat"): # evaluate once the mat properties, and cache the values in a glDisplayList. - diffuse = mat.properties.get("$clr.diffuse", numpy.array([0.8, 0.8, 0.8, 1.0])) - specular = mat.properties.get("$clr.specular", numpy.array([0., 0., 0., 1.0])) - ambient = mat.properties.get("$clr.ambient", numpy.array([0.2, 0.2, 0.2, 1.0])) - emissive = mat.properties.get("$clr.emissive", numpy.array([0., 0., 0., 1.0])) - shininess = min(mat.properties.get("$mat.shininess", 1.0), 128) - wireframe = mat.properties.get("$mat.wireframe", 0) - twosided = mat.properties.get("$mat.twosided", 1) + diffuse = numpy.array(mat.properties.get("diffuse", [0.8, 0.8, 0.8, 1.0])) + specular = numpy.array(mat.properties.get("specular", [0., 0., 0., 1.0])) + ambient = numpy.array(mat.properties.get("ambient", [0.2, 0.2, 0.2, 1.0])) + emissive = numpy.array(mat.properties.get("emissive", [0., 0., 0., 1.0])) + shininess = min(mat.properties.get("shininess", 1.0), 128) + wireframe = mat.properties.get("wireframe", 0) + twosided = mat.properties.get("twosided", 1) from OpenGL.raw import GL setattr(mat, "gl_mat", GL.GLuint(0))