port/PyAssimp/pyassimp/: Fix new warnings

pull/2392/head
Charlie Gettys 2019-03-27 13:54:21 -04:00
parent efbb85721c
commit 5a53fbd65f
2 changed files with 20 additions and 22 deletions

View File

@ -366,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)
@ -439,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
@ -510,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]
@ -538,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()

View File

@ -151,10 +151,7 @@ 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:
typen = 'LIST'
return template_convert_single.format(name=name,argnum=argnum,classname=classname,full_type=field.fullspec) return template_convert_single.format(name=name,argnum=argnum,classname=classname,full_type=field.fullspec)
def count_args_up(entity,schema): def count_args_up(entity,schema):