diff options
author | sanine <sanine.not@pm.me> | 2022-03-04 10:47:15 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-03-04 10:47:15 -0600 |
commit | 058f98a63658dc1a2579826ba167fd61bed1e21f (patch) | |
tree | bcba07a1615a14d943f3af3f815a42f3be86b2f3 /src/mesh/assimp-master/port/PyAssimp/scripts/sample.py | |
parent | 2f8028ac9e0812cb6f3cbb08f0f419e4e717bd22 (diff) |
add assimp submodule
Diffstat (limited to 'src/mesh/assimp-master/port/PyAssimp/scripts/sample.py')
-rwxr-xr-x | src/mesh/assimp-master/port/PyAssimp/scripts/sample.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/mesh/assimp-master/port/PyAssimp/scripts/sample.py b/src/mesh/assimp-master/port/PyAssimp/scripts/sample.py new file mode 100755 index 0000000..3cd4b3e --- /dev/null +++ b/src/mesh/assimp-master/port/PyAssimp/scripts/sample.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python +#-*- coding: UTF-8 -*- + +""" +This module demonstrates the functionality of PyAssimp. +""" + +import sys +import logging +logging.basicConfig(level=logging.INFO) + +import pyassimp +import pyassimp.postprocess + +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): + + scene = pyassimp.load(filename, processing=pyassimp.postprocess.aiProcess_Triangulate) + + #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])) + if mesh.normals.any(): + print(" first 3 normals:\n" + str(mesh.normals[:3])) + else: + print(" no normals") + print(" colors:" + str(len(mesh.colors))) + tcs = mesh.texturecoords + if tcs.any(): + for tc_index, tc in enumerate(tcs): + print(" texture-coords "+ str(tc_index) + ":" + str(len(tcs[tc_index])) + "first3:" + str(tcs[tc_index][:3])) + + 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) + +def usage(): + print("Usage: sample.py <3d model>") + +if __name__ == "__main__": + + if len(sys.argv) != 2: + usage() + else: + main(sys.argv[1]) |