From 17c8a62e24a9f721024f4acb953cd2053345e6f8 Mon Sep 17 00:00:00 2001 From: Gellule Xg Date: Mon, 12 Dec 2011 21:22:23 -1000 Subject: [PATCH] PyAssimp3: Fixes getting all the information out of an assimp material. Before, neither the texture index nor its semantic were kept in the returned output. Now GetMaterialProperties returns a (name, color, material, texture) tuple. Name is the name of the material. Color is a dictionary of color properties. Material is a dictionary of material properties. Textures is a triply nested dictionary addressed by the following: textures[index][semantic][key]. See assimp documentation for the meaning of index, semantic, and keys in general. --- port/PyAssimp3/pyassimp/pyassimp.py | 30 ++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/port/PyAssimp3/pyassimp/pyassimp.py b/port/PyAssimp3/pyassimp/pyassimp.py index decb290c6..3c253764a 100644 --- a/port/PyAssimp3/pyassimp/pyassimp.py +++ b/port/PyAssimp3/pyassimp/pyassimp.py @@ -250,10 +250,18 @@ def aiGetMaterialString(material, key): def GetMaterialProperties(material): """ - Convenience Function to get the material properties as a dict - and values in a python format. + Convenience Function to get the material properties. + This function returns the following tuple: (name, clr, mat, tex) where: + name: is the name of the material + clr: is a dictionary of color parameters + mat: is a dictionary of material parameters + tex: is a triply nested dictionary than can be indexed by index, semantic, and then key: + tex[index][semantic][key] """ - result = {} + name = "" + clr = {} + mat = {} + tex = {} #read all properties for p in material.properties: #the name @@ -276,9 +284,21 @@ def GetMaterialProperties(material): else: value = p.mData[:p.mDataLength] - result[key] = value + #store in the appropriate dict + if key == b'?mat.name': + name = value + elif key[:5] == b'$mat.': + mat[key[5:]] = value + elif key[:5] == b'$clr.': + clr[key[5:]] = value + elif key[:5] == b'$tex.': + if p.mIndex not in tex: + tex[p.mIndex] = {} + if p.mSemantic not in tex[p.mIndex]: + tex[p.mIndex][p.mSemantic] = {} + tex[p.mIndex][p.mSemantic][key[5:]] = value - return result + return (name, clr, mat, tex) def aiDecomposeMatrix(matrix):