commit
3e19545dc7
|
@ -6,20 +6,18 @@ This is the main-module of PyAssimp.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
if sys.version_info < (2,6):
|
if sys.version_info < (2,6):
|
||||||
raise 'pyassimp: need python 2.6 or newer'
|
raise RuntimeError('pyassimp: need python 2.6 or newer')
|
||||||
|
|
||||||
# xrange was renamed range in Python 3 and the original range from Python 2 was removed.
|
# xrange was renamed range in Python 3 and the original range from Python 2 was removed.
|
||||||
# To keep compatibility with both Python 2 and 3, xrange is set to range for version 3.0 and up.
|
# To keep compatibility with both Python 2 and 3, xrange is set to range for version 3.0 and up.
|
||||||
if sys.version_info >= (3,0):
|
if sys.version_info >= (3,0):
|
||||||
xrange = range
|
xrange = range
|
||||||
|
|
||||||
import ctypes
|
|
||||||
import os
|
|
||||||
|
|
||||||
try: import numpy
|
try: import numpy
|
||||||
except: numpy = None
|
except ImportError: numpy = None
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import ctypes
|
||||||
logger = logging.getLogger("pyassimp")
|
logger = logging.getLogger("pyassimp")
|
||||||
# attach default null handler to logger so it doesn't complain
|
# attach default null handler to logger so it doesn't complain
|
||||||
# even if you don't attach another handler to logger
|
# even if you don't attach another handler to logger
|
||||||
|
@ -67,10 +65,10 @@ def make_tuple(ai_obj, type = None):
|
||||||
|
|
||||||
# Returns unicode object for Python 2, and str object for Python 3.
|
# Returns unicode object for Python 2, and str object for Python 3.
|
||||||
def _convert_assimp_string(assimp_string):
|
def _convert_assimp_string(assimp_string):
|
||||||
try:
|
if sys.version_info >= (3, 0):
|
||||||
return unicode(assimp_string.data, errors='ignore')
|
|
||||||
except:
|
|
||||||
return str(assimp_string.data, errors='ignore')
|
return str(assimp_string.data, errors='ignore')
|
||||||
|
else:
|
||||||
|
return unicode(assimp_string.data, errors='ignore')
|
||||||
|
|
||||||
# It is faster and more correct to have an init function for each assimp class
|
# It is faster and more correct to have an init function for each assimp class
|
||||||
def _init_face(aiFace):
|
def _init_face(aiFace):
|
||||||
|
@ -305,7 +303,7 @@ def load(filename,
|
||||||
# unsigned int pLength,
|
# unsigned int pLength,
|
||||||
# unsigned int pFlags,
|
# unsigned int pFlags,
|
||||||
# const char* pHint)
|
# const char* pHint)
|
||||||
if file_type == None:
|
if file_type is None:
|
||||||
raise AssimpError('File type must be specified when passing file objects!')
|
raise AssimpError('File type must be specified when passing file objects!')
|
||||||
data = filename.read()
|
data = filename.read()
|
||||||
model = _assimp_lib.load_mem(data,
|
model = _assimp_lib.load_mem(data,
|
||||||
|
@ -343,8 +341,7 @@ def export(scene,
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ctypes import pointer
|
exportStatus = _assimp_lib.export(ctypes.pointer(scene), file_type.encode("ascii"), filename.encode(sys.getfilesystemencoding()), processing)
|
||||||
exportStatus = _assimp_lib.export(pointer(scene), file_type.encode("ascii"), filename.encode(sys.getfilesystemencoding()), processing)
|
|
||||||
|
|
||||||
if exportStatus != 0:
|
if exportStatus != 0:
|
||||||
raise AssimpError('Could not export scene!')
|
raise AssimpError('Could not export scene!')
|
||||||
|
@ -369,16 +366,14 @@ def export_blob(scene,
|
||||||
---------
|
---------
|
||||||
Pointer to structs.ExportDataBlob
|
Pointer to structs.ExportDataBlob
|
||||||
'''
|
'''
|
||||||
from ctypes import pointer
|
exportBlobPtr = _assimp_lib.export_blob(ctypes.pointer(scene), file_type.encode("ascii"), processing)
|
||||||
exportBlobPtr = _assimp_lib.export_blob(pointer(scene), file_type.encode("ascii"), processing)
|
|
||||||
|
|
||||||
if exportBlobPtr == 0:
|
if exportBlobPtr == 0:
|
||||||
raise AssimpError('Could not export scene to blob!')
|
raise AssimpError('Could not export scene to blob!')
|
||||||
return exportBlobPtr
|
return exportBlobPtr
|
||||||
|
|
||||||
def release(scene):
|
def release(scene):
|
||||||
from ctypes import pointer
|
_assimp_lib.release(ctypes.pointer(scene))
|
||||||
_assimp_lib.release(pointer(scene))
|
|
||||||
|
|
||||||
def _finalize_texture(tex, target):
|
def _finalize_texture(tex, target):
|
||||||
setattr(target, "achformathint", tex.achFormatHint)
|
setattr(target, "achformathint", tex.achFormatHint)
|
||||||
|
@ -442,24 +437,22 @@ def _finalize_mesh(mesh, target):
|
||||||
setattr(target, 'faces', faces)
|
setattr(target, 'faces', faces)
|
||||||
|
|
||||||
def _init_metadata_entry(entry):
|
def _init_metadata_entry(entry):
|
||||||
from ctypes import POINTER, c_bool, c_int32, c_uint64, c_float, c_double, cast
|
|
||||||
|
|
||||||
entry.type = entry.mType
|
entry.type = entry.mType
|
||||||
if entry.type == structs.MetadataEntry.AI_BOOL:
|
if entry.type == structs.MetadataEntry.AI_BOOL:
|
||||||
entry.data = cast(entry.mData, POINTER(c_bool)).contents.value
|
entry.data = ctypes.cast(entry.mData, ctypes.POINTER(ctypes.c_bool)).contents.value
|
||||||
elif entry.type == structs.MetadataEntry.AI_INT32:
|
elif entry.type == structs.MetadataEntry.AI_INT32:
|
||||||
entry.data = cast(entry.mData, POINTER(c_int32)).contents.value
|
entry.data = ctypes.cast(entry.mData, ctypes.POINTER(ctypes.c_int32)).contents.value
|
||||||
elif entry.type == structs.MetadataEntry.AI_UINT64:
|
elif entry.type == structs.MetadataEntry.AI_UINT64:
|
||||||
entry.data = cast(entry.mData, POINTER(c_uint64)).contents.value
|
entry.data = ctypes.cast(entry.mData, ctypes.POINTER(ctypes.c_uint64)).contents.value
|
||||||
elif entry.type == structs.MetadataEntry.AI_FLOAT:
|
elif entry.type == structs.MetadataEntry.AI_FLOAT:
|
||||||
entry.data = cast(entry.mData, POINTER(c_float)).contents.value
|
entry.data = ctypes.cast(entry.mData, ctypes.POINTER(ctypes.c_float)).contents.value
|
||||||
elif entry.type == structs.MetadataEntry.AI_DOUBLE:
|
elif entry.type == structs.MetadataEntry.AI_DOUBLE:
|
||||||
entry.data = cast(entry.mData, POINTER(c_double)).contents.value
|
entry.data = ctypes.cast(entry.mData, ctypes.POINTER(ctypes.c_double)).contents.value
|
||||||
elif entry.type == structs.MetadataEntry.AI_AISTRING:
|
elif entry.type == structs.MetadataEntry.AI_AISTRING:
|
||||||
assimp_string = cast(entry.mData, POINTER(structs.String)).contents
|
assimp_string = ctypes.cast(entry.mData, ctypes.POINTER(structs.String)).contents
|
||||||
entry.data = _convert_assimp_string(assimp_string)
|
entry.data = _convert_assimp_string(assimp_string)
|
||||||
elif entry.type == structs.MetadataEntry.AI_AIVECTOR3D:
|
elif entry.type == structs.MetadataEntry.AI_AIVECTOR3D:
|
||||||
assimp_vector = cast(entry.mData, POINTER(structs.Vector3D)).contents
|
assimp_vector = ctypes.cast(entry.mData, ctypes.POINTER(structs.Vector3D)).contents
|
||||||
entry.data = make_tuple(assimp_vector)
|
entry.data = make_tuple(assimp_vector)
|
||||||
|
|
||||||
return entry
|
return entry
|
||||||
|
@ -513,15 +506,18 @@ def _get_properties(properties, length):
|
||||||
key = (key.split('.')[1], p.mSemantic)
|
key = (key.split('.')[1], p.mSemantic)
|
||||||
|
|
||||||
#the data
|
#the data
|
||||||
from ctypes import POINTER, cast, c_int, c_float, sizeof
|
|
||||||
if p.mType == 1:
|
if p.mType == 1:
|
||||||
arr = cast(p.mData, POINTER(c_float * int(p.mDataLength/sizeof(c_float)) )).contents
|
arr = ctypes.cast(p.mData,
|
||||||
|
ctypes.POINTER(ctypes.c_float * int(p.mDataLength/ctypes.sizeof(ctypes.c_float)))
|
||||||
|
).contents
|
||||||
value = [x for x in arr]
|
value = [x for x in arr]
|
||||||
elif p.mType == 3: #string can't be an array
|
elif p.mType == 3: #string can't be an array
|
||||||
value = _convert_assimp_string(cast(p.mData, POINTER(structs.MaterialPropertyString)).contents)
|
value = _convert_assimp_string(ctypes.cast(p.mData, ctypes.POINTER(structs.MaterialPropertyString)).contents)
|
||||||
|
|
||||||
elif p.mType == 4:
|
elif p.mType == 4:
|
||||||
arr = cast(p.mData, POINTER(c_int * int(p.mDataLength/sizeof(c_int)) )).contents
|
arr = ctypes.cast(p.mData,
|
||||||
|
ctypes.POINTER(ctypes.c_int * int(p.mDataLength/ctypes.sizeof(ctypes.c_int)))
|
||||||
|
).contents
|
||||||
value = [x for x in arr]
|
value = [x for x in arr]
|
||||||
else:
|
else:
|
||||||
value = p.mData[:p.mDataLength]
|
value = p.mData[:p.mDataLength]
|
||||||
|
@ -541,7 +537,9 @@ def decompose_matrix(matrix):
|
||||||
rotation = structs.Quaternion()
|
rotation = structs.Quaternion()
|
||||||
position = structs.Vector3D()
|
position = structs.Vector3D()
|
||||||
|
|
||||||
from ctypes import byref, pointer
|
_assimp_lib.dll.aiDecomposeMatrix(ctypes.pointer(matrix),
|
||||||
_assimp_lib.dll.aiDecomposeMatrix(pointer(matrix), byref(scaling), byref(rotation), byref(position))
|
ctypes.byref(scaling),
|
||||||
|
ctypes.byref(rotation),
|
||||||
|
ctypes.byref(position))
|
||||||
return scaling._init(), rotation._init(), position._init()
|
return scaling._init(), rotation._init(), position._init()
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ FORMATS = ["CSM",
|
||||||
"STL",
|
"STL",
|
||||||
"IRR",
|
"IRR",
|
||||||
"Q3O",
|
"Q3O",
|
||||||
"Q3D"
|
"Q3D",
|
||||||
"MS3D",
|
"MS3D",
|
||||||
"Q3S",
|
"Q3S",
|
||||||
"ZGL",
|
"ZGL",
|
||||||
|
|
|
@ -6,7 +6,6 @@ Some fancy helper functions.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import ctypes
|
import ctypes
|
||||||
from ctypes import POINTER
|
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
from distutils.sysconfig import get_python_lib
|
from distutils.sysconfig import get_python_lib
|
||||||
|
@ -14,7 +13,7 @@ import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try: import numpy
|
try: import numpy
|
||||||
except: numpy = None
|
except ImportError: numpy = None
|
||||||
|
|
||||||
import logging;logger = logging.getLogger("pyassimp")
|
import logging;logger = logging.getLogger("pyassimp")
|
||||||
|
|
||||||
|
@ -193,9 +192,9 @@ def try_load_functions(library_path, dll):
|
||||||
|
|
||||||
# library found!
|
# library found!
|
||||||
from .structs import Scene, ExportDataBlob
|
from .structs import Scene, ExportDataBlob
|
||||||
load.restype = POINTER(Scene)
|
load.restype = ctype.POINTER(Scene)
|
||||||
load_mem.restype = POINTER(Scene)
|
load_mem.restype = ctype.POINTER(Scene)
|
||||||
export2blob.restype = POINTER(ExportDataBlob)
|
export2blob.restype = ctype.POINTER(ExportDataBlob)
|
||||||
return (library_path, load, load_mem, export, export2blob, release, dll)
|
return (library_path, load, load_mem, export, export2blob, release, dll)
|
||||||
|
|
||||||
def search_library():
|
def search_library():
|
||||||
|
@ -276,5 +275,5 @@ def hasattr_silent(object, name):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return hasattr(object, name)
|
return hasattr(object, name)
|
||||||
except:
|
except AttributeError:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -435,6 +435,7 @@ aiProcess_Debone = 0x4000000
|
||||||
aiProcess_GenEntityMeshes = 0x100000
|
aiProcess_GenEntityMeshes = 0x100000
|
||||||
aiProcess_OptimizeAnimations = 0x200000
|
aiProcess_OptimizeAnimations = 0x200000
|
||||||
aiProcess_FixTexturePaths = 0x200000
|
aiProcess_FixTexturePaths = 0x200000
|
||||||
|
aiProcess_EmbedTextures = 0x10000000,
|
||||||
|
|
||||||
## @def aiProcess_ConvertToLeftHanded
|
## @def aiProcess_ConvertToLeftHanded
|
||||||
# @brief Shortcut flag for Direct3D-based applications.
|
# @brief Shortcut flag for Direct3D-based applications.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#-*- coding: UTF-8 -*-
|
#-*- coding: UTF-8 -*-
|
||||||
|
|
||||||
from ctypes import POINTER, c_void_p, c_int, c_uint, c_char, c_float, Structure, c_char_p, c_double, c_ubyte, c_size_t, c_uint32
|
from ctypes import POINTER, c_void_p, c_uint, c_char, c_float, Structure, c_char_p, c_double, c_ubyte, c_size_t, c_uint32
|
||||||
|
|
||||||
|
|
||||||
class Vector2D(Structure):
|
class Vector2D(Structure):
|
||||||
|
|
|
@ -24,12 +24,13 @@ This sample is based on several sources, including:
|
||||||
- ASSIMP's C++ SimpleOpenGL viewer
|
- ASSIMP's C++ SimpleOpenGL viewer
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os, sys
|
import sys
|
||||||
from OpenGL.GLUT import *
|
from OpenGL.GLUT import *
|
||||||
from OpenGL.GLU import *
|
from OpenGL.GLU import *
|
||||||
from OpenGL.GL import *
|
from OpenGL.GL import *
|
||||||
|
|
||||||
import logging;logger = logging.getLogger("pyassimp_opengl")
|
import logging
|
||||||
|
logger = logging.getLogger("pyassimp_opengl")
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
This module demonstrates the functionality of PyAssimp.
|
This module demonstrates the functionality of PyAssimp.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os, sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ def main(filename=None):
|
||||||
print(" colors:" + str(len(mesh.colors)))
|
print(" colors:" + str(len(mesh.colors)))
|
||||||
tcs = mesh.texturecoords
|
tcs = mesh.texturecoords
|
||||||
if tcs.any():
|
if tcs.any():
|
||||||
for index, tc in enumerate(tcs):
|
for tc_index, tc in enumerate(tcs):
|
||||||
print(" texture-coords "+ str(index) + ":" + str(len(tcs[index])) + "first3:" + str(tcs[index][:3]))
|
print(" texture-coords "+ str(tc_index) + ":" + str(len(tcs[tc_index])) + "first3:" + str(tcs[tc_index][:3]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(" no texture coordinates")
|
print(" no texture coordinates")
|
||||||
|
|
|
@ -292,6 +292,8 @@ def main():
|
||||||
|
|
||||||
output.write(templt.replace("<HERE>",s))
|
output.write(templt.replace("<HERE>",s))
|
||||||
|
|
||||||
|
# we got here, so no error
|
||||||
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
|
@ -151,11 +151,8 @@ def handle_unset_args(field,entity,schema,argnum):
|
||||||
return n+template_allow_optional.format()
|
return n+template_allow_optional.format()
|
||||||
|
|
||||||
def get_single_conversion(field,schema,argnum=0,classname='?'):
|
def get_single_conversion(field,schema,argnum=0,classname='?'):
|
||||||
typen = field.type
|
|
||||||
name = field.name
|
name = field.name
|
||||||
if field.collection:
|
return template_convert_single.format(name=name,argnum=argnum,classname=classname,full_type=field.fullspec)
|
||||||
typen = 'LIST'
|
|
||||||
return template_convert_single.format(type=typen,name=name,argnum=argnum,classname=classname,full_type=field.fullspec)
|
|
||||||
|
|
||||||
def count_args_up(entity,schema):
|
def count_args_up(entity,schema):
|
||||||
return len(entity.members) + (count_args_up(schema.entities[entity.parent],schema) if entity.parent else 0)
|
return len(entity.members) + (count_args_up(schema.entities[entity.parent],schema) if entity.parent else 0)
|
||||||
|
@ -218,7 +215,7 @@ def get_derived(e,schema):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def get_hierarchy(e,schema):
|
def get_hierarchy(e,schema):
|
||||||
return get_derived(e.schema)+[e.name]+get_base_classes(e,schema)
|
return get_derived(e, schema)+[e.name]+get_base_classes(e,schema)
|
||||||
|
|
||||||
def sort_entity_list(schema):
|
def sort_entity_list(schema):
|
||||||
deps = []
|
deps = []
|
||||||
|
@ -300,5 +297,8 @@ def work(filename):
|
||||||
with open(output_file_cpp,'wt') as outp:
|
with open(output_file_cpp,'wt') as outp:
|
||||||
outp.write(inp.read().replace('{schema-static-table}',schema_table).replace('{converter-impl}',converters))
|
outp.write(inp.read().replace('{schema-static-table}',schema_table).replace('{converter-impl}',converters))
|
||||||
|
|
||||||
|
# Finished without error, so return 0
|
||||||
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(work(sys.argv[1] if len(sys.argv)>1 else 'schema.exp'))
|
sys.exit(work(sys.argv[1] if len(sys.argv)>1 else 'schema.exp'))
|
||||||
|
|
|
@ -43,7 +43,8 @@
|
||||||
"""Parse an EXPRESS file and extract basic information on all
|
"""Parse an EXPRESS file and extract basic information on all
|
||||||
entities and data types contained"""
|
entities and data types contained"""
|
||||||
|
|
||||||
import sys, os, re
|
import sys
|
||||||
|
import re
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
re_match_entity = re.compile(r"""
|
re_match_entity = re.compile(r"""
|
||||||
|
|
Loading…
Reference in New Issue