- 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
pull/1/head
aramis_acg 2011-04-19 20:48:33 +00:00
parent 6e74e066a2
commit 9350d0e1a6
5 changed files with 401 additions and 839 deletions

View File

@ -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 the library. Tested for Python 2.6. Known not to work with
older versions as well. 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.

View File

@ -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 Load Diff

View File

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

View File

@ -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')