[pyassimp] Updated sample.py to match the new API

While here, added simple node walking
pull/8/merge^2
Séverin Lemaignan 2012-10-17 00:18:55 +02:00 committed by Séverin Lemaignan
parent 7000ea05c5
commit b20b1dfceb
1 changed files with 33 additions and 19 deletions

52
port/PyAssimp/sample.py 100644 → 100755
View File

@ -6,7 +6,7 @@ This module demonstrates the functionality of PyAssimp.
""" """
from pyassimp import pyassimp import pyassimp
import os, sys import os, sys
#get a model out of assimp's test-data if none is provided on the command line #get a model out of assimp's test-data if none is provided on the command line
@ -14,6 +14,12 @@ DEFAULT_MODEL = os.path.join(os.path.dirname(__file__),
"..", "..", "..", "..",
"test", "models", "MDL", "MDL3 (3DGS A4)", "minigun.MDL") "test", "models", "MDL", "MDL3 (3DGS A4)", "minigun.MDL")
def recur_node(node,level = 0):
print(" " + "\t" * level + "- " + str(node))
for child in node.children:
recur_node(child, level + 1)
def main(filename=None): def main(filename=None):
filename = filename or DEFAULT_MODEL filename = filename or DEFAULT_MODEL
scene = pyassimp.load(filename) scene = pyassimp.load(filename)
@ -29,40 +35,48 @@ def main(filename=None):
print " textures:", len(scene.textures) print " textures:", len(scene.textures)
print print
print "NODES:"
recur_node(scene.rootnode)
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
print " material:", mesh.mMaterialIndex+1 print " material id:", mesh.materialindex+1
print " vertices:", len(mesh.vertices) print " vertices:", len(mesh.vertices)
print " first 3 verts:", mesh.vertices[:3] print " first 3 verts:", mesh.vertices[:3]
#if len(mesh.normals): if mesh.normals:
# print " first 3 normals:", mesh.normals[:3] print " first 3 normals:", mesh.normals[:3]
else:
print " no normals"
print " colors:", len(mesh.colors) print " colors:", len(mesh.colors)
tc = mesh.texcoords tc = mesh.texturecoords
print " texture-coords 1:", len(tc[0]), "first3:", tc[0][:3] if tc:
print " texture-coords 2:", len(tc[1]), "first3:", tc[1][:3] print " texture-coords 1:", len(tc[0]), "first3:", tc[0][:3]
print " texture-coords 3:", len(tc[2]), "first3:", tc[2][:3] print " texture-coords 2:", len(tc[1]), "first3:", tc[1][:3]
print " texture-coords 4:", len(tc[3]), "first3:", tc[3][:3] print " texture-coords 3:", len(tc[2]), "first3:", tc[2][:3]
print " uv-component-count:", len(mesh.mNumUVComponents) print " texture-coords 4:", len(tc[3]), "first3:", tc[3][:3]
else:
print " no texture coordinates"
print " uv-component-count:", len(mesh.numuvcomponents)
print " faces:", len(mesh.faces), "first:", [f.indices for f in mesh.faces[:3]] print " faces:", len(mesh.faces), "first:", [f.indices for f in mesh.faces[:3]]
print " bones:", len(mesh.bones), "first:", [b.mName for b in mesh.bones[:3]] print " bones:", len(mesh.bones), "first:", [str(b) for b in mesh.bones[:3]]
print print
print "MATERIALS:" print "MATERIALS:"
for index, material in enumerate(scene.materials): for index, material in enumerate(scene.materials):
print " MATERIAL", index+1 print(" MATERIAL (id:" + str(index+1) + ")")
properties = pyassimp.GetMaterialProperties(material) for key, value in material.properties.items():
for key in properties: print " %s: %s" % (key, value)
print " %s: %s" % (key, properties[key])
print print
print "TEXTURES:" print "TEXTURES:"
for index, texture in enumerate(scene.textures): for index, texture in enumerate(scene.textures):
print " TEXTURE", index+1 print " TEXTURE", index+1
print " width:", texture.mWidth print " width:", texture.width
print " height:", texture.mHeight print " height:", texture.height
print " hint:", texture.achFormatHint print " hint:", texture.achformathint
print " data (size):", texture.mWidth*texture.mHeight print " data (size):", len(texture.data)
# Finally release the model # Finally release the model
pyassimp.release(scene) pyassimp.release(scene)