2012-11-10 16:01:55 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#-*- coding: UTF-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
This module demonstrates the functionality of PyAssimp.
|
|
|
|
"""
|
|
|
|
|
2019-03-27 17:28:56 +00:00
|
|
|
import sys
|
2012-11-10 16:01:55 +00:00
|
|
|
import logging
|
2012-11-07 21:56:54 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
2012-11-10 16:01:55 +00:00
|
|
|
|
2012-11-07 21:56:54 +00:00
|
|
|
import pyassimp
|
2013-07-27 23:57:31 +00:00
|
|
|
import pyassimp.postprocess
|
2012-11-10 16:01:55 +00:00
|
|
|
|
|
|
|
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):
|
|
|
|
|
2017-06-25 13:10:11 +00:00
|
|
|
scene = pyassimp.load(filename, processing=pyassimp.postprocess.aiProcess_Triangulate)
|
2012-11-10 16:01:55 +00:00
|
|
|
|
|
|
|
#the model we load
|
|
|
|
print("MODEL:" + filename)
|
|
|
|
print
|
|
|
|
|
|
|
|
#write some statistics
|
|
|
|
print("SCENE:")
|
|
|
|
print(" meshes:" + str(len(scene.meshes)))
|
|
|
|
print(" materials:" + str(len(scene.materials)))
|
|
|
|
print(" textures:" + str(len(scene.textures)))
|
|
|
|
print
|
|
|
|
|
|
|
|
print("NODES:")
|
|
|
|
recur_node(scene.rootnode)
|
|
|
|
|
|
|
|
print
|
|
|
|
print("MESHES:")
|
|
|
|
for index, mesh in enumerate(scene.meshes):
|
|
|
|
print(" MESH" + str(index+1))
|
|
|
|
print(" material id:" + str(mesh.materialindex+1))
|
|
|
|
print(" vertices:" + str(len(mesh.vertices)))
|
|
|
|
print(" first 3 verts:\n" + str(mesh.vertices[:3]))
|
2013-07-28 23:24:22 +00:00
|
|
|
if mesh.normals.any():
|
2012-11-10 16:01:55 +00:00
|
|
|
print(" first 3 normals:\n" + str(mesh.normals[:3]))
|
|
|
|
else:
|
|
|
|
print(" no normals")
|
|
|
|
print(" colors:" + str(len(mesh.colors)))
|
|
|
|
tcs = mesh.texturecoords
|
2013-03-23 22:40:01 +00:00
|
|
|
if tcs.any():
|
2019-03-27 17:21:18 +00:00
|
|
|
for tc_index, tc in enumerate(tcs):
|
|
|
|
print(" texture-coords "+ str(tc_index) + ":" + str(len(tcs[tc_index])) + "first3:" + str(tcs[tc_index][:3]))
|
2012-11-10 16:01:55 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
print(" no texture coordinates")
|
|
|
|
print(" uv-component-count:" + str(len(mesh.numuvcomponents)))
|
|
|
|
print(" faces:" + str(len(mesh.faces)) + " -> first:\n" + str(mesh.faces[:3]))
|
|
|
|
print(" bones:" + str(len(mesh.bones)) + " -> first:" + str([str(b) for b in mesh.bones[:3]]))
|
|
|
|
print
|
|
|
|
|
|
|
|
print("MATERIALS:")
|
|
|
|
for index, material in enumerate(scene.materials):
|
|
|
|
print(" MATERIAL (id:" + str(index+1) + ")")
|
|
|
|
for key, value in material.properties.items():
|
|
|
|
print(" %s: %s" % (key, value))
|
|
|
|
print
|
|
|
|
|
|
|
|
print("TEXTURES:")
|
|
|
|
for index, texture in enumerate(scene.textures):
|
|
|
|
print(" TEXTURE" + str(index+1))
|
|
|
|
print(" width:" + str(texture.width))
|
|
|
|
print(" height:" + str(texture.height))
|
|
|
|
print(" hint:" + str(texture.achformathint))
|
|
|
|
print(" data (size):" + str(len(texture.data)))
|
|
|
|
|
|
|
|
# Finally release the model
|
|
|
|
pyassimp.release(scene)
|
|
|
|
|
2013-06-03 08:37:48 +00:00
|
|
|
def usage():
|
|
|
|
print("Usage: sample.py <3d model>")
|
|
|
|
|
2012-11-10 16:01:55 +00:00
|
|
|
if __name__ == "__main__":
|
2013-06-03 08:37:48 +00:00
|
|
|
|
|
|
|
if len(sys.argv) != 2:
|
|
|
|
usage()
|
|
|
|
else:
|
|
|
|
main(sys.argv[1])
|