You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

90 lines
2.7 KiB

  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.INFO)
  9. import pyassimp
  10. import pyassimp.postprocess
  11. def recur_node(node,level = 0):
  12. print(" " + "\t" * level + "- " + str(node))
  13. for child in node.children:
  14. recur_node(child, level + 1)
  15. def main(filename=None):
  16. scene = pyassimp.load(filename, pyassimp.postprocess.aiProcess_Triangulate)
  17. #the model we load
  18. print("MODEL:" + filename)
  19. print
  20. #write some statistics
  21. print("SCENE:")
  22. print(" meshes:" + str(len(scene.meshes)))
  23. print(" materials:" + str(len(scene.materials)))
  24. print(" textures:" + str(len(scene.textures)))
  25. print
  26. print("NODES:")
  27. recur_node(scene.rootnode)
  28. print
  29. print("MESHES:")
  30. for index, mesh in enumerate(scene.meshes):
  31. print(" MESH" + str(index+1))
  32. print(" material id:" + str(mesh.materialindex+1))
  33. print(" vertices:" + str(len(mesh.vertices)))
  34. print(" first 3 verts:\n" + str(mesh.vertices[:3]))
  35. if mesh.normals.any():
  36. print(" first 3 normals:\n" + str(mesh.normals[:3]))
  37. else:
  38. print(" no normals")
  39. print(" colors:" + str(len(mesh.colors)))
  40. tcs = mesh.texturecoords
  41. if tcs.any():
  42. for index, tc in enumerate(tcs):
  43. print(" texture-coords "+ str(index) + ":" + str(len(tcs[index])) + "first3:" + str(tcs[index][:3]))
  44. else:
  45. print(" no texture coordinates")
  46. print(" uv-component-count:" + str(len(mesh.numuvcomponents)))
  47. print(" faces:" + str(len(mesh.faces)) + " -> first:\n" + str(mesh.faces[:3]))
  48. print(" bones:" + str(len(mesh.bones)) + " -> first:" + str([str(b) for b in mesh.bones[:3]]))
  49. print
  50. print("MATERIALS:")
  51. for index, material in enumerate(scene.materials):
  52. print(" MATERIAL (id:" + str(index+1) + ")")
  53. for key, value in material.properties.items():
  54. print(" %s: %s" % (key, value))
  55. print
  56. print("TEXTURES:")
  57. for index, texture in enumerate(scene.textures):
  58. print(" TEXTURE" + str(index+1))
  59. print(" width:" + str(texture.width))
  60. print(" height:" + str(texture.height))
  61. print(" hint:" + str(texture.achformathint))
  62. print(" data (size):" + str(len(texture.data)))
  63. # Finally release the model
  64. pyassimp.release(scene)
  65. def usage():
  66. print("Usage: sample.py <3d model>")
  67. if __name__ == "__main__":
  68. if len(sys.argv) != 2:
  69. usage()
  70. else:
  71. main(sys.argv[1])