瀏覽代碼

- update pyassimp genstructs script to work with the latest headers, add rudimentary test script to batch-load all test files using pyassimp

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@951 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
aramis_acg 14 年之前
父節點
當前提交
9350d0e1a6
共有 5 個文件被更改,包括 326 次插入684 次删除
  1. 8 3
      port/PyAssimp/README
  2. 5 1
      port/PyAssimp/pyassimp/pyassimp.py
  3. 219 610
      port/PyAssimp/pyassimp/structs.py
  4. 71 67
      port/PyAssimp/sample.py
  5. 23 3
      scripts/structsgen.py

+ 8 - 3
port/PyAssimp/README

@@ -3,8 +3,13 @@
 
 
 
 
 -- a simple Python wrapper for Assimp using ctypes to access
 -- a simple Python wrapper for Assimp using ctypes to access
-the library. Tested for Python 2.6, should work with
-older versions as well.
+the library. Tested for Python 2.6. Known not to work with
+Python 2.4.
+
+
+Note that pyassimp is by no means considered mature. It works,
+but it is far away from wrapping Assimp perfectly.
+
 
 
 USAGE
 USAGE
 =====
 =====
@@ -58,4 +63,4 @@ There's an 'additional_dirs' list waiting for your entries.
 
 
 
 
 
 
-	
+	

+ 5 - 1
port/PyAssimp/pyassimp/pyassimp.py

@@ -6,6 +6,10 @@ PyAssimp
 This is the main-module of PyAssimp.
 This is the main-module of PyAssimp.
 """
 """
 
 
+import sys
+if sys.version_info < (2,5):
+	raise 'pyassimp: need python 2.5 or newer'
+
 import structs
 import structs
 import ctypes
 import ctypes
 import os
 import os
@@ -160,7 +164,7 @@ def _init(self):
 Python magic to add the _init() function to all C struct classes.
 Python magic to add the _init() function to all C struct classes.
 """
 """
 for struct in dir(structs):
 for struct in dir(structs):
-    if not (struct.startswith('_') or struct.startswith('c_') or struct == "Structure" or struct == "POINTER"):
+    if not (struct.startswith('_') or struct.startswith('c_') or struct == "Structure" or struct == "POINTER") and not isinstance(getattr(structs, struct),int):
         setattr(getattr(structs, struct), '_init', _init)
         setattr(getattr(structs, struct), '_init', _init)
 
 
 
 

File diff suppressed because it is too large
+ 219 - 610
port/PyAssimp/pyassimp/structs.py


+ 71 - 67
port/PyAssimp/sample.py

@@ -1,67 +1,71 @@
-#-*- coding: UTF-8 -*-
-
-"""
-This module demonstrates the functionality of PyAssimp.
-"""
-
-
-from pyassimp import pyassimp
-import os
-
-#get a model out of assimp's test-data
-MODEL = os.path.join(os.path.dirname(__file__),
-                     "..", "..",
-                     "test", "models", "MDL", "MDL3 (3DGS A4)", "minigun.MDL")
-
-def main():
-    scene = pyassimp.load(MODEL)
-    
-    #the model we load
-    print "MODEL:", MODEL
-    print
-    
-    #write some statistics
-    print "SCENE:"
-    print "  meshes:", len(scene.meshes)
-    print "  materials:", len(scene.materials)
-    print "  textures:", len(scene.textures)
-    print
-    
-    print "MESHES:"
-    for index, mesh in enumerate(scene.meshes):
-        print "  MESH", index+1
-        print "    material:", mesh.mMaterialIndex+1
-        print "    vertices:", len(mesh.vertices)
-        print "    first:", mesh.vertices[:3]
-        print "    colors:", len(mesh.colors)
-        tc = mesh.texcoords
-        print "    texture-coords 1:", len(tc[0]), "first:", tc[0][:3]
-        print "    texture-coords 2:", len(tc[1]), "first:", tc[1][:3]
-        print "    texture-coords 3:", len(tc[2]), "first:", tc[2][:3]
-        print "    texture-coords 4:", len(tc[3]), "first:", tc[3][:3]
-        print "    uv-component-count:", len(mesh.mNumUVComponents)
-        print "    faces:", len(mesh.faces), "first:", [f.indices for f in mesh.faces[:3]]
-        print "    bones:", len(mesh.bones), "first:", [b.mName for b in mesh.bones[:3]]
-        print
-
-    print "MATERIALS:"
-    for index, material in enumerate(scene.materials):
-        print "  MATERIAL", index+1
-        properties = pyassimp.GetMaterialProperties(material)
-        for key in properties:
-            print "    %s: %s" % (key, properties[key])
-    print
-    
-    print "TEXTURES:"
-    for index, texture in enumerate(scene.textures):
-        print "  TEXTURE", index+1
-        print "    width:", texture.mWidth
-        print "    height:", texture.mHeight
-        print "    hint:", texture.achFormatHint
-        print "    data (size):", texture.mWidth*texture.mHeight
-   
-    # Finally release the model
-    pyassimp.release(scene)
-
-if __name__ == "__main__":
-    main()
+#!/usr/bin/env python
+#-*- coding: UTF-8 -*-
+
+"""
+This module demonstrates the functionality of PyAssimp.
+"""
+
+
+from pyassimp import 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 main(filename=None):
+    filename = filename or DEFAULT_MODEL
+    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 "MESHES:"
+    for index, mesh in enumerate(scene.meshes):
+        print "  MESH", index+1
+        print "    material:", mesh.mMaterialIndex+1
+        print "    vertices:", len(mesh.vertices)
+        print "    first 3 verts:", mesh.vertices[:3]
+        #if len(mesh.normals):
+        #        print "    first 3 normals:", mesh.normals[:3]
+        print "    colors:", len(mesh.colors)
+        tc = mesh.texcoords
+        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]
+        print "    uv-component-count:", len(mesh.mNumUVComponents)
+        print "    faces:", len(mesh.faces), "first:", [f.indices for f in mesh.faces[:3]]
+        print "    bones:", len(mesh.bones), "first:", [b.mName for b in mesh.bones[:3]]
+        print
+
+    print "MATERIALS:"
+    for index, material in enumerate(scene.materials):
+        print "  MATERIAL", index+1
+        properties = pyassimp.GetMaterialProperties(material)
+        for key in properties:
+            print "    %s: %s" % (key, properties[key])
+    print
+    
+    print "TEXTURES:"
+    for index, texture in enumerate(scene.textures):
+        print "  TEXTURE", index+1
+        print "    width:", texture.mWidth
+        print "    height:", texture.mHeight
+        print "    hint:", texture.achFormatHint
+        print "    data (size):", texture.mWidth*texture.mHeight
+   
+    # Finally release the model
+    pyassimp.release(scene)
+
+if __name__ == "__main__":
+    main(sys.argv[1] if len(sys.argv)>1 else None)

+ 23 - 3
scripts/structsgen.py

@@ -79,7 +79,7 @@ RErmifdef = re.compile(r''
                 
                 
 # Replace comments
 # Replace comments
 RErpcom = re.compile(r''
 RErpcom = re.compile(r''
-                r'[ ]*(/\*\*\s|\*/|\B\*\s|//!)'             # /**
+                r'\s*(/\*+\s|\*+/|\B\*\s|///?!?)'             # /**
                 r'(?P<line>.*?)'                            #  * line 
                 r'(?P<line>.*?)'                            #  * line 
                 , re.IGNORECASE + re.DOTALL)
                 , re.IGNORECASE + re.DOTALL)
                 
                 
@@ -88,6 +88,14 @@ def GetType(type, prefix='c_'):
     t = type
     t = type
     while t.endswith('*'):
     while t.endswith('*'):
         t = t[:-1]
         t = t[:-1]
+    if t[:5] == 'const':
+        t = t[5:]
+
+    # skip some types
+    if t in skiplist:
+           return None
+
+    t = t.strip()
     types = {'unsigned int':'uint', 'unsigned char':'ubyte', 'size_t':'uint',}
     types = {'unsigned int':'uint', 'unsigned char':'ubyte', 'size_t':'uint',}
     if t in types:
     if t in types:
         t = types[t]
         t = types[t]
@@ -105,6 +113,8 @@ def restructure( match ):
         type = "c_uint"
         type = "c_uint"
     else:
     else:
         type = GetType(type[2:], '')
         type = GetType(type[2:], '')
+        if type is None:
+           return ''
     if match.group("index"):
     if match.group("index"):
         type = type + "*" + match.group("index")
         type = type + "*" + match.group("index")
         
         
@@ -144,6 +154,9 @@ $NAME$._fields_ = [
             $FIELDS$
             $FIELDS$
         ]
         ]
 """
 """
+
+skiplist = ("FileIO", "File", "locateFromAssimpHeap",'LogStream','MeshAnim','AnimMesh')
+
 #============================================================
 #============================================================
 def Structify(fileName):
 def Structify(fileName):
     file = open(fileName, 'r')
     file = open(fileName, 'r')
@@ -160,7 +173,14 @@ def Structify(fileName):
         # Replace comments
         # Replace comments
         desc = RErpcom.sub('#\g<line>', desc)
         desc = RErpcom.sub('#\g<line>', desc)
         defines += desc
         defines += desc
-        defines += " "*4 + define[1] + " = " + define[2] + "\n"  
+	if len(define[2].strip()):
+            # skip non-integral defines, we can support them right now
+            try:
+                int(define[2],0)
+            except:
+                continue
+            defines += " "*4 + define[1] + " = " + define[2] + "\n"  
+            
     
     
     # Get structs
     # Get structs
     rs = REstructs.finditer(text)
     rs = REstructs.finditer(text)
@@ -172,7 +192,7 @@ def Structify(fileName):
         desc = r.group('desc')
         desc = r.group('desc')
         
         
         # Skip some structs
         # Skip some structs
-        if name == "FileIO" or name == "File" or name == "locateFromAssimpHeap":
+        if name in skiplist:
             continue
             continue
 
 
         text = r.group('code')
         text = r.group('code')

Some files were not shown because too many files changed in this diff