- 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-9d2fd5bffc1fpull/1/head
parent
6e74e066a2
commit
9350d0e1a6
|
@ -3,8 +3,13 @@
|
|||
|
||||
|
||||
-- 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
|
||||
=====
|
||||
|
|
|
@ -6,6 +6,10 @@ 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 ctypes
|
||||
import os
|
||||
|
@ -160,7 +164,7 @@ def _init(self):
|
|||
Python magic to add the _init() function to all C struct classes.
|
||||
"""
|
||||
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)
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#-*- coding: UTF-8 -*-
|
||||
|
||||
"""
|
||||
|
@ -6,18 +7,19 @@ This module demonstrates the functionality of PyAssimp.
|
|||
|
||||
|
||||
from pyassimp import pyassimp
|
||||
import os
|
||||
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")
|
||||
|
||||
def main():
|
||||
scene = pyassimp.load(MODEL)
|
||||
def main(filename=None):
|
||||
filename = filename or DEFAULT_MODEL
|
||||
scene = pyassimp.load(filename)
|
||||
|
||||
#the model we load
|
||||
print "MODEL:", MODEL
|
||||
print "MODEL:", filename
|
||||
print
|
||||
|
||||
#write some statistics
|
||||
|
@ -32,13 +34,15 @@ def main():
|
|||
print " MESH", index+1
|
||||
print " material:", mesh.mMaterialIndex+1
|
||||
print " vertices:", len(mesh.vertices)
|
||||
print " first:", mesh.vertices[:3]
|
||||
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]), "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 " 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]]
|
||||
|
@ -64,4 +68,4 @@ def main():
|
|||
pyassimp.release(scene)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main(sys.argv[1] if len(sys.argv)>1 else None)
|
||||
|
|
|
@ -79,7 +79,7 @@ RErmifdef = re.compile(r''
|
|||
|
||||
# Replace comments
|
||||
RErpcom = re.compile(r''
|
||||
r'[ ]*(/\*\*\s|\*/|\B\*\s|//!)' # /**
|
||||
r'\s*(/\*+\s|\*+/|\B\*\s|///?!?)' # /**
|
||||
r'(?P<line>.*?)' # * line
|
||||
, re.IGNORECASE + re.DOTALL)
|
||||
|
||||
|
@ -88,6 +88,14 @@ def GetType(type, prefix='c_'):
|
|||
t = type
|
||||
while t.endswith('*'):
|
||||
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',}
|
||||
if t in types:
|
||||
t = types[t]
|
||||
|
@ -105,6 +113,8 @@ def restructure( match ):
|
|||
type = "c_uint"
|
||||
else:
|
||||
type = GetType(type[2:], '')
|
||||
if type is None:
|
||||
return ''
|
||||
if match.group("index"):
|
||||
type = type + "*" + match.group("index")
|
||||
|
||||
|
@ -144,6 +154,9 @@ $NAME$._fields_ = [
|
|||
$FIELDS$
|
||||
]
|
||||
"""
|
||||
|
||||
skiplist = ("FileIO", "File", "locateFromAssimpHeap",'LogStream','MeshAnim','AnimMesh')
|
||||
|
||||
#============================================================
|
||||
def Structify(fileName):
|
||||
file = open(fileName, 'r')
|
||||
|
@ -160,7 +173,14 @@ def Structify(fileName):
|
|||
# Replace comments
|
||||
desc = RErpcom.sub('#\g<line>', 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
|
||||
rs = REstructs.finditer(text)
|
||||
|
@ -172,7 +192,7 @@ def Structify(fileName):
|
|||
desc = r.group('desc')
|
||||
|
||||
# Skip some structs
|
||||
if name == "FileIO" or name == "File" or name == "locateFromAssimpHeap":
|
||||
if name in skiplist:
|
||||
continue
|
||||
|
||||
text = r.group('code')
|
||||
|
|
Loading…
Reference in New Issue