materials

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@161 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
sebastianhempel 2008-09-23 12:38:39 +00:00
parent 23ec92092a
commit 64c431b5eb
3 changed files with 67 additions and 9 deletions

View File

@ -44,6 +44,51 @@ class AssimpBase(object):
return []
class Material(object):
"""
A Material.
"""
def __init__(self, material):
"""
Converts the raw material data to a material.
"""
self.properties = self._load_properties(material.mProperties,
material.mNumProperties)
def _load_properties(self, data, size):
"""
Loads all properties of this mateiral.
data - properties
size - elements in properties
"""
result = {}
#read all properties
for i in range(size):
p = data[i].contents
#the name
key = p.mKey.data
#the data
value = p.mData[:p.mDataLength]
result[key] = str(value)
return result
def __repr__(self):
return repr(self.properties)
def __str__(self):
return str(self.properties)
class Matrix(AssimpBase):
"""
Assimp 4x4-matrix
@ -172,6 +217,11 @@ class Scene(AssimpBase):
self.meshes = self._load_array(model.mMeshes,
model.mNumMeshes,
lambda x: Mesh(x.contents))
#load materials
self.materials = self._load_array(model.mMaterials,
model.mNumMaterials,
lambda x: Material(x.contents))
def list_flags(self):

View File

@ -266,25 +266,25 @@ class MATERIALPROPERTY(Structure):
_fields_ = [
#Specifies the name of the property (key)
#Keys are case insensitive.
("mKey", STRING),
("mKey", STRING), #OK
#Size of the buffer mData is pointing to, in bytes
#This value may not be 0.
("mDataLength", c_uint),
("mDataLength", c_uint), #OK
#Type information for the property.
#Defines the data layout inside the
#data buffer. This is used by the library
#internally to perform debug checks.
#THIS IS AN ENUM!
("mType", c_int),
("mType", c_int), #IGNORED
#Binary buffer to hold the property's value
#The buffer has no terminal character. However,
#if a string is stored inside it may use 0 as terminal,
#but it would be contained in mDataLength. This member
#is never 0
("mData", c_char_p)
("mData", c_char_p) #OK
]
@ -300,11 +300,11 @@ class MATERIAL(Structure):
_fields_ = [
#List of all material properties loaded.
("mProperties", POINTER(POINTER(MATERIALPROPERTY))),
("mProperties", POINTER(POINTER(MATERIALPROPERTY))), #OK
#Number of properties loaded
("mNumProperties", c_uint),
("mNumAllocated", c_uint)
("mNumProperties", c_uint), #OK
("mNumAllocated", c_uint) #IGNORED
]
@ -497,12 +497,12 @@ class SCENE(Structure):
("mMeshes", POINTER(POINTER(MESH))), #OK
#The number of materials in the scene.
("mNumMaterials", c_uint),
("mNumMaterials", c_uint), #OK
#The array of materials.
#Use the index given in each aiMesh structure to access this
#array. The array is mNumMaterials in size.
("mMaterials", POINTER(POINTER(MATERIAL))),
("mMaterials", POINTER(POINTER(MATERIAL))), #OK
#The number of animations in the scene.
("mNumAnimations", c_uint),

View File

@ -24,7 +24,15 @@ def main():
print "SCENE:"
print " flags:", ", ".join(scene.list_flags())
print " meshes:", len(scene.meshes)
print " materials:", len(scene.materials)
print
for index, material in enumerate(scene.materials):
print "MATERIAL", index+1
for key, value in material.properties.iteritems():
print " %s: %s" % (key, value)
print
print "MESHES:"
for index, mesh in enumerate(scene.meshes):
print " MESH", index+1