[pyassimp] Update, fix and beautify structs.py

structgen.py has been modified to make the resulting structs.py
more readable: comments should now correctly appear next to the
fields in the generated structs.py

Do not discard the size_t type. size_t was wrongly replaced by uint in ctypes
This caused corruptions when running pyassimp with a 64bits assimp library

While here, updated the max size of some meshes attributes (that leads
to corruptions as well)

While here, update paths to find the assimp headers

Updated structs.py to match assimp 2.0.863 (Ubuntu 12.04). It has been
also tested with libassimp as build from the trunk.
pull/8/merge^2
Séverin Lemaignan 2012-10-15 11:40:00 +02:00
parent 9687531b20
commit 848c875ec2
2 changed files with 883 additions and 419 deletions

View File

@ -41,7 +41,11 @@
# ---------------------------------------------------------------------------
"""Update PyAssimp's data structures to keep up with the
C/C++ headers."""
C/C++ headers.
This script is meant to be executed in the source tree, directly from
port/PyAssimp/gen
"""
import os
import re
@ -96,7 +100,7 @@ def GetType(type, prefix='c_'):
return None
t = t.strip()
types = {'unsigned int':'uint', 'unsigned char':'ubyte', 'size_t':'uint',}
types = {'unsigned int':'uint', 'unsigned char':'ubyte',}
if t in types:
t = types[t]
t = prefix + t
@ -210,9 +214,11 @@ def Structify(fileName):
# Restructure
text = RErestruc.sub(restructure, text)
# Replace comments
text = RErpcom.sub('#\g<line>', text)
text = RErpcom.sub('# \g<line>', text)
text = text.replace("),#", "),\n#")
text = text.replace("#", "\n#")
text = "".join([l for l in text.splitlines(True) if not l.strip().endswith("#")]) # remove empty comment lines
# Whether it's selfreferencing: ex. struct Node { Node* parent; };
selfreferencing = text.find('POINTER('+name+')') != -1
@ -245,20 +251,21 @@ def Structify(fileName):
text = text.replace('$DEFINES$', defines)
else:
text = text.replace('$DEFINES$', '')
result.append((primitive, selfreferencing, complex, text))
return result
text = "#-*- coding: UTF-8 -*-\n\n"
text += "from ctypes import POINTER, c_int, c_uint, c_char, c_float, Structure, c_char_p, c_double, c_ubyte\n\n"
text += "from ctypes import POINTER, c_int, c_uint, c_size_t, c_char, c_float, Structure, c_char_p, c_double, c_ubyte\n\n"
structs1 = ""
structs2 = ""
structs3 = ""
structs4 = ""
path = '../include/'
path = '../../../include/assimp'
files = os.listdir (path)
#files = ["aiScene.h", "aiTypes.h"]
for fileName in files:
@ -276,6 +283,8 @@ for fileName in files:
text += structs1 + structs2 + structs3 + structs4
file = open('structs.txt', 'w')
file = open('structs.py', 'w')
file.write(text)
file.close()
print("Generation done. You can now review the file 'structs.py' and merge it.")

File diff suppressed because it is too large Load Diff