2011-04-19 20:48:33 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#-*- coding: UTF-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
This module demonstrates the functionality of PyAssimp.
|
|
|
|
"""
|
|
|
|
|
2012-11-29 18:06:26 +00:00
|
|
|
import pyassimp.core as pyassimp
|
2011-04-19 20:48:33 +00:00
|
|
|
import os, sys
|
|
|
|
|
|
|
|
#get a model out of assimp's test-data if none is provided on the command line
|
|
|
|
DEFAULT_MODEL = os.path.join(os.path.dirname(__file__),
|
|
|
|
"..", "..",
|
|
|
|
"test", "models", "MDL", "MDL3 (3DGS A4)", "minigun.MDL")
|
|
|
|
|
2012-11-09 11:39:34 +00:00
|
|
|
def recur_node(node,level = 0):
|
|
|
|
print(" " + "\t" * level + "- " + str(node))
|
|
|
|
for child in node.children:
|
|
|
|
recur_node(child, level + 1)
|
|
|
|
|
|
|
|
|
2011-04-19 20:48:33 +00:00
|
|
|
def main(filename=None):
|
|
|
|
filename = filename or DEFAULT_MODEL
|
2012-11-29 18:06:26 +00:00
|
|
|
|
|
|
|
print "Reading model", filename
|
2011-04-19 20:48:33 +00:00
|
|
|
scene = pyassimp.load(filename)
|
|
|
|
|
|
|
|
#the model we load
|
|
|
|
print "MODEL:", filename
|
|
|
|
print
|
|
|
|
|
|
|
|
#write some statistics
|
|
|
|
print "SCENE:"
|
|
|
|
print " meshes:", len(scene.meshes)
|
|
|
|
print " materials:", len(scene.materials)
|
|
|
|
print " textures:", len(scene.textures)
|
|
|
|
print
|
|
|
|
|
2012-11-09 11:39:34 +00:00
|
|
|
print "NODES:"
|
|
|
|
recur_node(scene.rootnode)
|
|
|
|
|
|
|
|
print
|
2011-04-19 20:48:33 +00:00
|
|
|
print "MESHES:"
|
|
|
|
for index, mesh in enumerate(scene.meshes):
|
|
|
|
print " MESH", index+1
|
2012-11-09 11:39:34 +00:00
|
|
|
print " material id:", mesh.materialindex+1
|
2011-04-19 20:48:33 +00:00
|
|
|
print " vertices:", len(mesh.vertices)
|
|
|
|
print " first 3 verts:", mesh.vertices[:3]
|
2012-11-29 18:06:26 +00:00
|
|
|
if len(mesh.normals) > 0:
|
2012-11-09 11:39:34 +00:00
|
|
|
print " first 3 normals:", mesh.normals[:3]
|
|
|
|
else:
|
|
|
|
print " no normals"
|
2011-04-19 20:48:33 +00:00
|
|
|
print " colors:", len(mesh.colors)
|
2012-11-09 11:39:34 +00:00
|
|
|
tc = mesh.texturecoords
|
2012-11-29 18:06:26 +00:00
|
|
|
if len(tc) >= 4:
|
2012-11-09 11:39:34 +00:00
|
|
|
print " texture-coords 1:", len(tc[0]), "first3:", tc[0][:3]
|
|
|
|
print " texture-coords 2:", len(tc[1]), "first3:", tc[1][:3]
|
|
|
|
print " texture-coords 3:", len(tc[2]), "first3:", tc[2][:3]
|
|
|
|
print " texture-coords 4:", len(tc[3]), "first3:", tc[3][:3]
|
2012-11-29 18:06:26 +00:00
|
|
|
elif len(tc) == 0:
|
2012-11-09 11:39:34 +00:00
|
|
|
print " no texture coordinates"
|
2012-11-29 18:06:26 +00:00
|
|
|
else:
|
|
|
|
print " tc is an unexpected number of elements (expect 4, got", len(tc), ")"
|
2012-11-09 11:39:34 +00:00
|
|
|
print " uv-component-count:", len(mesh.numuvcomponents)
|
2012-11-29 18:06:26 +00:00
|
|
|
print " faces:", len(mesh.faces), "first:", [f for f in mesh.faces[:3]]
|
2012-11-09 11:39:34 +00:00
|
|
|
print " bones:", len(mesh.bones), "first:", [str(b) for b in mesh.bones[:3]]
|
2011-04-19 20:48:33 +00:00
|
|
|
print
|
|
|
|
|
|
|
|
print "MATERIALS:"
|
|
|
|
for index, material in enumerate(scene.materials):
|
2012-11-09 11:39:34 +00:00
|
|
|
print(" MATERIAL (id:" + str(index+1) + ")")
|
|
|
|
for key, value in material.properties.items():
|
|
|
|
print " %s: %s" % (key, value)
|
2011-04-19 20:48:33 +00:00
|
|
|
print
|
|
|
|
|
|
|
|
print "TEXTURES:"
|
|
|
|
for index, texture in enumerate(scene.textures):
|
|
|
|
print " TEXTURE", index+1
|
2012-11-09 11:39:34 +00:00
|
|
|
print " width:", texture.width
|
|
|
|
print " height:", texture.height
|
|
|
|
print " hint:", texture.achformathint
|
|
|
|
print " data (size):", len(texture.data)
|
2011-04-19 20:48:33 +00:00
|
|
|
|
|
|
|
# Finally release the model
|
|
|
|
pyassimp.release(scene)
|
|
|
|
|
2012-11-29 18:06:26 +00:00
|
|
|
print "Finished parsing the model."
|
|
|
|
|
2011-04-19 20:48:33 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv[1] if len(sys.argv)>1 else None)
|