Updating PyAssimp to the latest data structures. Many thanks to sueastside for the patch.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@402 67173fc5-114c-0410-ac8e-9d2fd5bffc1fpull/1/head
parent
897a7f7ae3
commit
760bcbbf69
|
@ -299,7 +299,8 @@ struct aiScene
|
||||||
|
|
||||||
|
|
||||||
/** The number of light sources in the scene. Light sources
|
/** The number of light sources in the scene. Light sources
|
||||||
are fully optional, in most cases this attribute will be 0 */
|
* are fully optional, in most cases this attribute will be 0
|
||||||
|
*/
|
||||||
unsigned int mNumLights;
|
unsigned int mNumLights;
|
||||||
|
|
||||||
/** The array of light sources.
|
/** The array of light sources.
|
||||||
|
@ -311,7 +312,8 @@ struct aiScene
|
||||||
|
|
||||||
|
|
||||||
/** The number of cameras in the scene. Cameras
|
/** The number of cameras in the scene. Cameras
|
||||||
are fully optional, in most cases this attribute will be 0 */
|
* are fully optional, in most cases this attribute will be 0
|
||||||
|
*/
|
||||||
unsigned int mNumCameras;
|
unsigned int mNumCameras;
|
||||||
|
|
||||||
/** The array of cameras.
|
/** The array of cameras.
|
||||||
|
|
|
@ -30,6 +30,8 @@ def search_library():
|
||||||
#this path
|
#this path
|
||||||
folder = os.path.dirname(__file__)
|
folder = os.path.dirname(__file__)
|
||||||
|
|
||||||
|
ctypes.windll.kernel32.SetErrorMode(0x8007)
|
||||||
|
|
||||||
candidates = []
|
candidates = []
|
||||||
|
|
||||||
#test every file
|
#test every file
|
||||||
|
@ -62,4 +64,4 @@ def search_library():
|
||||||
else:
|
else:
|
||||||
#get the newest library
|
#get the newest library
|
||||||
candidates = map(lambda x: (os.lstat(x[0])[-2], x), candidates)
|
candidates = map(lambda x: (os.lstat(x[0])[-2], x), candidates)
|
||||||
return max(candidates, key=operator.itemgetter(0))[1][1:]
|
return max(candidates, key=operator.itemgetter(0))[1][1:]
|
||||||
|
|
|
@ -86,10 +86,20 @@ class Material(object):
|
||||||
|
|
||||||
#the name
|
#the name
|
||||||
key = p.mKey.data
|
key = p.mKey.data
|
||||||
|
|
||||||
#the data
|
#the data
|
||||||
value = p.mData[:p.mDataLength]
|
from ctypes import POINTER, cast, c_int, c_float, sizeof
|
||||||
|
if p.mType == 1:
|
||||||
|
arr = cast(p.mData, POINTER(c_float*(p.mDataLength/sizeof(c_float)) )).contents
|
||||||
|
value = [x for x in arr]
|
||||||
|
elif p.mType == 3: #string can't be an array
|
||||||
|
value = cast(p.mData, POINTER(structs.STRING)).contents.data
|
||||||
|
elif p.mType == 4:
|
||||||
|
arr = cast(p.mData, POINTER(c_int*(p.mDataLength/sizeof(c_int)) )).contents
|
||||||
|
value = [x for x in arr]
|
||||||
|
else:
|
||||||
|
value = p.mData[:p.mDataLength]
|
||||||
|
|
||||||
result[key] = str(value)
|
result[key] = str(value)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -247,8 +257,10 @@ class Scene(AssimpBase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#possible flags
|
#possible flags
|
||||||
FLAGS = {1 : "AI_SCENE_FLAGS_ANIM_SKELETON_ONLY"}
|
FLAGS = {}
|
||||||
|
for key in structs.SCENE.__dict__:
|
||||||
|
if key.startswith("AI_SCENE_FLAGS_"):
|
||||||
|
FLAGS[structs.SCENE.__dict__[key]] = key
|
||||||
|
|
||||||
def __init__(self, model):
|
def __init__(self, model):
|
||||||
"""
|
"""
|
||||||
|
@ -267,7 +279,7 @@ class Scene(AssimpBase):
|
||||||
model - pointer to data
|
model - pointer to data
|
||||||
"""
|
"""
|
||||||
#store scene flags
|
#store scene flags
|
||||||
self.flags = model.flags
|
self.flags = model.mFlags
|
||||||
|
|
||||||
#load mesh-data
|
#load mesh-data
|
||||||
self.meshes = Scene._load_array(model.mMeshes,
|
self.meshes = Scene._load_array(model.mMeshes,
|
||||||
|
@ -500,4 +512,4 @@ def load(filename, processing=0):
|
||||||
return Scene(model.contents)
|
return Scene(model.contents)
|
||||||
finally:
|
finally:
|
||||||
#forget raw data
|
#forget raw data
|
||||||
_assimp_lib.release(model)
|
_assimp_lib.release(model)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,216 @@
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
#==[regexps]=================================================
|
||||||
|
|
||||||
|
# Clean desc
|
||||||
|
REdefine = re.compile(r''
|
||||||
|
r'(?P<desc>)' # /** *desc */
|
||||||
|
r'#\s*define\s(?P<name>[^(\n]+?)\s(?P<code>.+)$' # #define name value
|
||||||
|
, re.MULTILINE)
|
||||||
|
|
||||||
|
# Get structs
|
||||||
|
REstructs = re.compile(r''
|
||||||
|
#r'//\s?[\-]*\s(?P<desc>.*?)\*/\s' # /** *desc */
|
||||||
|
#r'//\s?[\-]*(?P<desc>.*?)\*/(?:.*?)' # garbage
|
||||||
|
r'//\s?[\-]*\s(?P<desc>.*?)\*/\W*?' # /** *desc */
|
||||||
|
r'struct\s(?:ASSIMP_API\s)?(?P<name>[a-z][a-z0-9_]\w+\b)' # struct name
|
||||||
|
r'[^{]*?\{' # {
|
||||||
|
r'(?P<code>.*?)' # code
|
||||||
|
r'\}\s*(PACK_STRUCT)?;' # };
|
||||||
|
, re.IGNORECASE + re.DOTALL + re.MULTILINE)
|
||||||
|
|
||||||
|
# Clean desc
|
||||||
|
REdesc = re.compile(r''
|
||||||
|
r'^\s*?([*]|/\*\*)(?P<line>.*?)' # * line
|
||||||
|
, re.IGNORECASE + re.DOTALL + re.MULTILINE)
|
||||||
|
|
||||||
|
# Remove #ifdef __cplusplus
|
||||||
|
RErmifdef = re.compile(r''
|
||||||
|
r'#ifdef __cplusplus' # #ifdef __cplusplus
|
||||||
|
r'(?P<code>.*)' # code
|
||||||
|
r'#endif(\s*//\s*!?\s*__cplusplus)*' # #endif
|
||||||
|
, re.IGNORECASE + re.DOTALL)
|
||||||
|
|
||||||
|
# Replace comments
|
||||||
|
RErpcom = re.compile(r''
|
||||||
|
r'[ ]*(/\*\*\s|\*/|\B\*\s|//!)' # /**
|
||||||
|
r'(?P<line>.*?)' # * line
|
||||||
|
, re.IGNORECASE + re.DOTALL)
|
||||||
|
|
||||||
|
# Restructure
|
||||||
|
def GetType(type, prefix='c_'):
|
||||||
|
t = type
|
||||||
|
while t.endswith('*'):
|
||||||
|
t = t[:-1]
|
||||||
|
types = {'unsigned int':'uint', 'unsigned char':'ubyte', 'size_t':'uint',}
|
||||||
|
if t in types:
|
||||||
|
t = types[t]
|
||||||
|
t = prefix + t
|
||||||
|
while type.endswith('*'):
|
||||||
|
t = "POINTER(" + t + ")"
|
||||||
|
type = type[:-1]
|
||||||
|
return t
|
||||||
|
|
||||||
|
def restructure( match ):
|
||||||
|
type = match.group("type")
|
||||||
|
if match.group("struct") == "":
|
||||||
|
type = GetType(type)
|
||||||
|
elif match.group("struct") == "C_ENUM ":
|
||||||
|
type = "c_uint"
|
||||||
|
else:
|
||||||
|
type = GetType(type[2:].upper(), '')
|
||||||
|
if match.group("index"):
|
||||||
|
type = type + "*" + match.group("index")
|
||||||
|
|
||||||
|
result = ""
|
||||||
|
for name in match.group("name").split(','):
|
||||||
|
result += "(\"" + name.strip() + "\", "+ type + "),"
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
RErestruc = re.compile(r''
|
||||||
|
r'(?P<struct>C_STRUCT\s|C_ENUM\s|)' # [C_STRUCT]
|
||||||
|
r'(?P<type>\w+\s?\w+?[*]*)\s' # type
|
||||||
|
#r'(?P<name>\w+)' # name
|
||||||
|
r'(?P<name>\w+|[a-z0-9_, ]+)' # name
|
||||||
|
r'(:?\[(?P<index>\w+)\])?;' # []; (optional)
|
||||||
|
, re.DOTALL)
|
||||||
|
#==[template]================================================
|
||||||
|
template = """
|
||||||
|
class $NAME$(Structure):
|
||||||
|
\"\"\"
|
||||||
|
$DESCRIPTION$
|
||||||
|
\"\"\"
|
||||||
|
$DEFINES$
|
||||||
|
_fields_ = [
|
||||||
|
$FIELDS$
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
|
||||||
|
templateSR = """
|
||||||
|
class $NAME$(Structure):
|
||||||
|
\"\"\"
|
||||||
|
$DESCRIPTION$
|
||||||
|
\"\"\"
|
||||||
|
$DEFINES$
|
||||||
|
|
||||||
|
$NAME$._fields_ = [
|
||||||
|
$FIELDS$
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
#============================================================
|
||||||
|
def Structify(fileName):
|
||||||
|
file = open(fileName, 'r')
|
||||||
|
text = file.read()
|
||||||
|
result = []
|
||||||
|
|
||||||
|
# Get defines.
|
||||||
|
defs = REdefine.findall(text)
|
||||||
|
# Create defines
|
||||||
|
defines = "\n"
|
||||||
|
for define in defs:
|
||||||
|
# Clean desc
|
||||||
|
desc = REdesc.sub('', define[0])
|
||||||
|
# Replace comments
|
||||||
|
desc = RErpcom.sub('#\g<line>', desc)
|
||||||
|
defines += desc
|
||||||
|
defines += " "*4 + define[1] + " = " + define[2] + "\n"
|
||||||
|
|
||||||
|
# Get structs
|
||||||
|
rs = REstructs.finditer(text)
|
||||||
|
|
||||||
|
fileName = os.path.basename(fileName)
|
||||||
|
print fileName
|
||||||
|
for r in rs:
|
||||||
|
name = r.group('name')[2:].upper()
|
||||||
|
desc = r.group('desc')
|
||||||
|
|
||||||
|
# Skip some structs
|
||||||
|
if name == "FILEIO" or name == "FILE" or name == "LOCATEFROMASSIMPHEAP":
|
||||||
|
continue
|
||||||
|
|
||||||
|
text = r.group('code')
|
||||||
|
|
||||||
|
# Clean desc
|
||||||
|
desc = REdesc.sub('', desc)
|
||||||
|
|
||||||
|
desc = "See '"+ fileName +"' for details." #TODO
|
||||||
|
|
||||||
|
# Remove #ifdef __cplusplus
|
||||||
|
text = RErmifdef.sub('', text)
|
||||||
|
|
||||||
|
# Whether the struct contains more than just POD
|
||||||
|
primitive = text.find('C_STRUCT') == -1
|
||||||
|
|
||||||
|
# Restructure
|
||||||
|
text = RErestruc.sub(restructure, text)
|
||||||
|
|
||||||
|
# Replace comments
|
||||||
|
text = RErpcom.sub('#\g<line>', text)
|
||||||
|
|
||||||
|
# Whether it's selfreferencing: ex. struct Node { Node* parent; };
|
||||||
|
selfreferencing = text.find('POINTER('+name+')') != -1
|
||||||
|
|
||||||
|
complex = name == "SCENE"
|
||||||
|
|
||||||
|
# Create description
|
||||||
|
description = ""
|
||||||
|
for line in desc.split('\n'):
|
||||||
|
description += " "*4 + line.strip() + "\n"
|
||||||
|
description = description.rstrip()
|
||||||
|
|
||||||
|
# Create fields
|
||||||
|
fields = ""
|
||||||
|
for line in text.split('\n'):
|
||||||
|
fields += " "*12 + line.strip() + "\n"
|
||||||
|
fields = fields.strip()
|
||||||
|
|
||||||
|
if selfreferencing:
|
||||||
|
templ = templateSR
|
||||||
|
else:
|
||||||
|
templ = template
|
||||||
|
|
||||||
|
# Put it all together
|
||||||
|
text = templ.replace('$NAME$', name)
|
||||||
|
text = text.replace('$DESCRIPTION$', description)
|
||||||
|
text = text.replace('$FIELDS$', fields)
|
||||||
|
|
||||||
|
if ((name == fileName.split('.')[0][2:].upper()) and (name != 'MATERIAL')) or name == "STRING":
|
||||||
|
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"
|
||||||
|
|
||||||
|
structs1 = ""
|
||||||
|
structs2 = ""
|
||||||
|
structs3 = ""
|
||||||
|
structs4 = ""
|
||||||
|
|
||||||
|
path = '../include/'
|
||||||
|
files = os.listdir (path)
|
||||||
|
#files = ["aiScene.h", "aiTypes.h"]
|
||||||
|
for fileName in files:
|
||||||
|
if fileName.endswith('.h'):
|
||||||
|
for struct in Structify(os.path.join(path, fileName)):
|
||||||
|
primitive, sr, complex, struct = struct
|
||||||
|
if primitive:
|
||||||
|
structs1 += struct
|
||||||
|
elif sr:
|
||||||
|
structs2 += struct
|
||||||
|
elif complex:
|
||||||
|
structs4 += struct
|
||||||
|
else:
|
||||||
|
structs3 += struct
|
||||||
|
|
||||||
|
text += structs1 + structs2 + structs3 + structs4
|
||||||
|
|
||||||
|
file = open('structs.txt', 'w')
|
||||||
|
file.write(text)
|
||||||
|
file.close()
|
Loading…
Reference in New Issue