materials
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@161 67173fc5-114c-0410-ac8e-9d2fd5bffc1fpull/1/head
parent
23ec92092a
commit
64c431b5eb
|
@ -44,6 +44,51 @@ class AssimpBase(object):
|
||||||
return []
|
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):
|
class Matrix(AssimpBase):
|
||||||
"""
|
"""
|
||||||
Assimp 4x4-matrix
|
Assimp 4x4-matrix
|
||||||
|
@ -173,6 +218,11 @@ class Scene(AssimpBase):
|
||||||
model.mNumMeshes,
|
model.mNumMeshes,
|
||||||
lambda x: Mesh(x.contents))
|
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):
|
def list_flags(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -266,25 +266,25 @@ class MATERIALPROPERTY(Structure):
|
||||||
_fields_ = [
|
_fields_ = [
|
||||||
#Specifies the name of the property (key)
|
#Specifies the name of the property (key)
|
||||||
#Keys are case insensitive.
|
#Keys are case insensitive.
|
||||||
("mKey", STRING),
|
("mKey", STRING), #OK
|
||||||
|
|
||||||
#Size of the buffer mData is pointing to, in bytes
|
#Size of the buffer mData is pointing to, in bytes
|
||||||
#This value may not be 0.
|
#This value may not be 0.
|
||||||
("mDataLength", c_uint),
|
("mDataLength", c_uint), #OK
|
||||||
|
|
||||||
#Type information for the property.
|
#Type information for the property.
|
||||||
#Defines the data layout inside the
|
#Defines the data layout inside the
|
||||||
#data buffer. This is used by the library
|
#data buffer. This is used by the library
|
||||||
#internally to perform debug checks.
|
#internally to perform debug checks.
|
||||||
#THIS IS AN ENUM!
|
#THIS IS AN ENUM!
|
||||||
("mType", c_int),
|
("mType", c_int), #IGNORED
|
||||||
|
|
||||||
#Binary buffer to hold the property's value
|
#Binary buffer to hold the property's value
|
||||||
#The buffer has no terminal character. However,
|
#The buffer has no terminal character. However,
|
||||||
#if a string is stored inside it may use 0 as terminal,
|
#if a string is stored inside it may use 0 as terminal,
|
||||||
#but it would be contained in mDataLength. This member
|
#but it would be contained in mDataLength. This member
|
||||||
#is never 0
|
#is never 0
|
||||||
("mData", c_char_p)
|
("mData", c_char_p) #OK
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -300,11 +300,11 @@ class MATERIAL(Structure):
|
||||||
|
|
||||||
_fields_ = [
|
_fields_ = [
|
||||||
#List of all material properties loaded.
|
#List of all material properties loaded.
|
||||||
("mProperties", POINTER(POINTER(MATERIALPROPERTY))),
|
("mProperties", POINTER(POINTER(MATERIALPROPERTY))), #OK
|
||||||
|
|
||||||
#Number of properties loaded
|
#Number of properties loaded
|
||||||
("mNumProperties", c_uint),
|
("mNumProperties", c_uint), #OK
|
||||||
("mNumAllocated", c_uint)
|
("mNumAllocated", c_uint) #IGNORED
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -497,12 +497,12 @@ class SCENE(Structure):
|
||||||
("mMeshes", POINTER(POINTER(MESH))), #OK
|
("mMeshes", POINTER(POINTER(MESH))), #OK
|
||||||
|
|
||||||
#The number of materials in the scene.
|
#The number of materials in the scene.
|
||||||
("mNumMaterials", c_uint),
|
("mNumMaterials", c_uint), #OK
|
||||||
|
|
||||||
#The array of materials.
|
#The array of materials.
|
||||||
#Use the index given in each aiMesh structure to access this
|
#Use the index given in each aiMesh structure to access this
|
||||||
#array. The array is mNumMaterials in size.
|
#array. The array is mNumMaterials in size.
|
||||||
("mMaterials", POINTER(POINTER(MATERIAL))),
|
("mMaterials", POINTER(POINTER(MATERIAL))), #OK
|
||||||
|
|
||||||
#The number of animations in the scene.
|
#The number of animations in the scene.
|
||||||
("mNumAnimations", c_uint),
|
("mNumAnimations", c_uint),
|
||||||
|
|
|
@ -24,7 +24,15 @@ def main():
|
||||||
print "SCENE:"
|
print "SCENE:"
|
||||||
print " flags:", ", ".join(scene.list_flags())
|
print " flags:", ", ".join(scene.list_flags())
|
||||||
print " meshes:", len(scene.meshes)
|
print " meshes:", len(scene.meshes)
|
||||||
|
print " materials:", len(scene.materials)
|
||||||
print
|
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:"
|
print "MESHES:"
|
||||||
for index, mesh in enumerate(scene.meshes):
|
for index, mesh in enumerate(scene.meshes):
|
||||||
print " MESH", index+1
|
print " MESH", index+1
|
||||||
|
|
Loading…
Reference in New Issue