sample.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python
  2. #-*- coding: UTF-8 -*-
  3. """
  4. This module demonstrates the functionality of PyAssimp.
  5. """
  6. import os, sys
  7. import logging
  8. logging.basicConfig(level=logging.DEBUG)
  9. from pyassimp import core as pyassimp
  10. def recur_node(node,level = 0):
  11. print(" " + "\t" * level + "- " + str(node))
  12. for child in node.children:
  13. recur_node(child, level + 1)
  14. def main(filename=None):
  15. scene = pyassimp.load(filename)
  16. #the model we load
  17. print("MODEL:" + filename)
  18. print
  19. #write some statistics
  20. print("SCENE:")
  21. print(" meshes:" + str(len(scene.meshes)))
  22. print(" materials:" + str(len(scene.materials)))
  23. print(" textures:" + str(len(scene.textures)))
  24. print
  25. print("NODES:")
  26. recur_node(scene.rootnode)
  27. print
  28. print("MESHES:")
  29. for index, mesh in enumerate(scene.meshes):
  30. print(" MESH" + str(index+1))
  31. print(" material id:" + str(mesh.materialindex+1))
  32. print(" vertices:" + str(len(mesh.vertices)))
  33. print(" first 3 verts:\n" + str(mesh.vertices[:3]))
  34. if mesh.normals.any():
  35. print(" first 3 normals:\n" + str(mesh.normals[:3]))
  36. else:
  37. print(" no normals")
  38. print(" colors:" + str(len(mesh.colors)))
  39. tcs = mesh.texturecoords
  40. if tcs:
  41. for index, tc in enumerate(tcs):
  42. print(" texture-coords "+ str(index) + ":" + str(len(tcs[index])) + "first3:" + str(tcs[index][:3]))
  43. else:
  44. print(" no texture coordinates")
  45. print(" uv-component-count:" + str(len(mesh.numuvcomponents)))
  46. print(" faces:" + str(len(mesh.faces)) + " -> first:\n" + str(mesh.faces[:3]))
  47. print(" bones:" + str(len(mesh.bones)) + " -> first:" + str([str(b) for b in mesh.bones[:3]]))
  48. print
  49. print("MATERIALS:")
  50. for index, material in enumerate(scene.materials):
  51. print(" MATERIAL (id:" + str(index+1) + ")")
  52. for key, value in material.properties.items():
  53. print(" %s: %s" % (key, value))
  54. print
  55. print("TEXTURES:")
  56. for index, texture in enumerate(scene.textures):
  57. print(" TEXTURE" + str(index+1))
  58. print(" width:" + str(texture.width))
  59. print(" height:" + str(texture.height))
  60. print(" hint:" + str(texture.achformathint))
  61. print(" data (size):" + str(len(texture.data)))
  62. # Finally release the model
  63. pyassimp.release(scene)
  64. if __name__ == "__main__":
  65. main(sys.argv[1] if len(sys.argv)>1 else None)