Browse Source

[pyassimp] Make sure sample.py and quicktest.py work

Séverin Lemaignan 12 years ago
parent
commit
3574b6973c
3 changed files with 20 additions and 107 deletions
  1. 0 90
      port/PyAssimp/sample.py
  2. 19 16
      port/PyAssimp/scripts/quicktest.py
  3. 1 1
      port/PyAssimp/scripts/sample.py

+ 0 - 90
port/PyAssimp/sample.py

@@ -1,90 +0,0 @@
-#!/usr/bin/env python
-#-*- coding: UTF-8 -*-
-
-"""
-This module demonstrates the functionality of PyAssimp.
-"""
-
-import pyassimp.core as pyassimp
-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")
-
-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):
-    filename = filename or DEFAULT_MODEL
-    
-    print "Reading model", filename
-    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
-    
-    print "NODES:"
-    recur_node(scene.rootnode)
-
-    print
-    print "MESHES:"
-    for index, mesh in enumerate(scene.meshes):
-        print "  MESH", index+1
-        print "    material id:", mesh.materialindex+1
-        print "    vertices:", len(mesh.vertices)
-        print "    first 3 verts:", mesh.vertices[:3]
-        if len(mesh.normals) > 0:
-                print "    first 3 normals:", mesh.normals[:3]
-        else:
-                print "    no normals"
-        print "    colors:", len(mesh.colors)
-        tc = mesh.texturecoords
-        if len(tc) >= 4:
-            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]
-        elif len(tc) == 0:
-            print "    no texture coordinates"
-        else:
-            print "    tc is an unexpected number of elements (expect 4, got", len(tc), ")"
-        print "    uv-component-count:", len(mesh.numuvcomponents)
-        print "    faces:", len(mesh.faces), "first:", [f for f in mesh.faces[:3]]
-        print "    bones:", len(mesh.bones), "first:", [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", index+1
-        print "    width:", texture.width
-        print "    height:", texture.height
-        print "    hint:", texture.achformathint
-        print "    data (size):", len(texture.data)
-   
-    # Finally release the model
-    pyassimp.release(scene)
-
-    print "Finished parsing the model."
-    
-if __name__ == "__main__":
-    main(sys.argv[1] if len(sys.argv)>1 else None)

+ 19 - 16
port/PyAssimp/scripts/quicktest.py

@@ -12,29 +12,32 @@ loading and querying of 3d models using pyassimp works.
 
 
 import sys,os
 import sys,os
 import sample
 import sample
-from pyassimp import pyassimp,errors
+from pyassimp import errors
 
 
 # paths to be walkd recursively
 # paths to be walkd recursively
-basepaths = [os.path.join('..','..','test','models'), os.path.join('..','..','test','models-nonbsd')]
+basepaths = [os.path.join('..','..','..','test','models'), os.path.join('..','..','..','test','models-nonbsd')]
 
 
 # file extensions to be considered
 # file extensions to be considered
 extensions = ['.3ds','.x','.lwo','.obj','.md5mesh','.dxf','.ply','.stl','.dae','.md5anim','.lws','.irrmesh','.nff','.off','.blend']
 extensions = ['.3ds','.x','.lwo','.obj','.md5mesh','.dxf','.ply','.stl','.dae','.md5anim','.lws','.irrmesh','.nff','.off','.blend']
 
 
 def run_tests():
 def run_tests():
-	ok,err = 0,0
-	for path in basepaths:
-		for root, dirs, files in os.walk(path):
-			for afile in files:
-				base,ext = os.path.splitext(afile)	
-				if ext in extensions:		
-					try:
-						sample.main(os.path.join(root,afile))
-						ok += 1
-					except errors.AssimpError as error:
-						# assimp error is fine, this is a controlled case
-						print error
-						err += 1
-	print '** Loaded %s models, got controlled errors for %s files' % (ok,err)
+    ok,err = 0,0
+    for path in basepaths:
+        print("Looking for models in %s..." % path)
+        for root, dirs, files in os.walk(path):
+            for afile in files:
+                base,ext = os.path.splitext(afile)
+                if ext in extensions:
+                    try:
+                        sample.main(os.path.join(root,afile))
+                        ok += 1
+                    except errors.AssimpError as error:
+                        # assimp error is fine, this is a controlled case
+                        print error
+                        err += 1
+                    except Exception:
+                        print("Error encountered while loading <%s>"%os.path.join(root,afile))
+    print('** Loaded %s models, got controlled errors for %s files' % (ok,err))
 
 
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':

+ 1 - 1
port/PyAssimp/scripts/sample.py

@@ -48,7 +48,7 @@ def main(filename=None):
                 print("    no normals")
                 print("    no normals")
         print("    colors:" + str(len(mesh.colors)))
         print("    colors:" + str(len(mesh.colors)))
         tcs = mesh.texturecoords
         tcs = mesh.texturecoords
-        if tcs:
+        if tcs.any():
             for index, tc in enumerate(tcs):
             for index, tc in enumerate(tcs):
                 print("    texture-coords "+ str(index) + ":" + str(len(tcs[index])) + "first3:" + str(tcs[index][:3]))
                 print("    texture-coords "+ str(index) + ":" + str(len(tcs[index])) + "first3:" + str(tcs[index][:3]))