Merge pull request #2150 from vjf/pyassimp_export_blob
Added interface to 'aiExportSceneToBlob()' for pyassimppull/2155/head
commit
7d36c12dc4
|
@ -35,7 +35,7 @@ class AssimpLib(object):
|
||||||
"""
|
"""
|
||||||
Assimp-Singleton
|
Assimp-Singleton
|
||||||
"""
|
"""
|
||||||
load, load_mem, export, release, dll = helper.search_library()
|
load, load_mem, export, export_blob, release, dll = helper.search_library()
|
||||||
_assimp_lib = AssimpLib()
|
_assimp_lib = AssimpLib()
|
||||||
|
|
||||||
def make_tuple(ai_obj, type = None):
|
def make_tuple(ai_obj, type = None):
|
||||||
|
@ -352,6 +352,33 @@ def export(scene,
|
||||||
if exportStatus != 0:
|
if exportStatus != 0:
|
||||||
raise AssimpError('Could not export scene!')
|
raise AssimpError('Could not export scene!')
|
||||||
|
|
||||||
|
def export_blob(scene,
|
||||||
|
file_type = None,
|
||||||
|
processing = postprocess.aiProcess_Triangulate):
|
||||||
|
'''
|
||||||
|
Export a scene and return a blob in the correct format. On failure throws AssimpError.
|
||||||
|
|
||||||
|
Arguments
|
||||||
|
---------
|
||||||
|
scene: scene to export.
|
||||||
|
file_type: string of file exporter to use. For example "collada".
|
||||||
|
processing: assimp postprocessing parameters. Verbose keywords are imported
|
||||||
|
from postprocessing, and the parameters can be combined bitwise to
|
||||||
|
generate the final processing value. Note that the default value will
|
||||||
|
triangulate quad faces. Example of generating other possible values:
|
||||||
|
processing = (pyassimp.postprocess.aiProcess_Triangulate |
|
||||||
|
pyassimp.postprocess.aiProcess_OptimizeMeshes)
|
||||||
|
Returns
|
||||||
|
---------
|
||||||
|
Pointer to structs.ExportDataBlob
|
||||||
|
'''
|
||||||
|
from ctypes import pointer
|
||||||
|
exportBlobPtr = _assimp_lib.export_blob(pointer(scene), file_type.encode("ascii"), processing)
|
||||||
|
|
||||||
|
if exportBlobPtr == 0:
|
||||||
|
raise AssimpError('Could not export scene to blob!')
|
||||||
|
return exportBlobPtr
|
||||||
|
|
||||||
def release(scene):
|
def release(scene):
|
||||||
from ctypes import pointer
|
from ctypes import pointer
|
||||||
_assimp_lib.release(pointer(scene))
|
_assimp_lib.release(pointer(scene))
|
||||||
|
|
|
@ -176,6 +176,7 @@ def try_load_functions(library_path, dll):
|
||||||
load from filename function,
|
load from filename function,
|
||||||
load from memory function,
|
load from memory function,
|
||||||
export to filename function,
|
export to filename function,
|
||||||
|
export to blob function,
|
||||||
release function,
|
release function,
|
||||||
ctypes handle to assimp library)
|
ctypes handle to assimp library)
|
||||||
'''
|
'''
|
||||||
|
@ -185,15 +186,17 @@ def try_load_functions(library_path, dll):
|
||||||
release = dll.aiReleaseImport
|
release = dll.aiReleaseImport
|
||||||
load_mem = dll.aiImportFileFromMemory
|
load_mem = dll.aiImportFileFromMemory
|
||||||
export = dll.aiExportScene
|
export = dll.aiExportScene
|
||||||
|
export2blob = dll.aiExportSceneToBlob
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
#OK, this is a library, but it doesn't have the functions we need
|
#OK, this is a library, but it doesn't have the functions we need
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# library found!
|
# library found!
|
||||||
from .structs import Scene
|
from .structs import Scene, ExportDataBlob
|
||||||
load.restype = POINTER(Scene)
|
load.restype = POINTER(Scene)
|
||||||
load_mem.restype = POINTER(Scene)
|
load_mem.restype = POINTER(Scene)
|
||||||
return (library_path, load, load_mem, export, release, dll)
|
export2blob.restype = POINTER(ExportDataBlob)
|
||||||
|
return (library_path, load, load_mem, export, export2blob, release, dll)
|
||||||
|
|
||||||
def search_library():
|
def search_library():
|
||||||
'''
|
'''
|
||||||
|
@ -203,6 +206,7 @@ def search_library():
|
||||||
Returns: tuple, (load from filename function,
|
Returns: tuple, (load from filename function,
|
||||||
load from memory function,
|
load from memory function,
|
||||||
export to filename function,
|
export to filename function,
|
||||||
|
export to blob function,
|
||||||
release function,
|
release function,
|
||||||
dll)
|
dll)
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -996,6 +996,39 @@ class Animation(Structure):
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
class ExportDataBlob(Structure):
|
||||||
|
"""
|
||||||
|
See 'cexport.h' for details.
|
||||||
|
|
||||||
|
Note that the '_fields_' definition is outside the class to allow the 'next' field to be recursive
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
ExportDataBlob._fields_ = [
|
||||||
|
# Size of the data in bytes
|
||||||
|
("size", c_size_t),
|
||||||
|
|
||||||
|
# The data.
|
||||||
|
("data", c_void_p),
|
||||||
|
|
||||||
|
# Name of the blob. An empty string always
|
||||||
|
# indicates the first (and primary) blob,
|
||||||
|
# which contains the actual file data.
|
||||||
|
# Any other blobs are auxiliary files produced
|
||||||
|
# by exporters (i.e. material files). Existence
|
||||||
|
# of such files depends on the file format. Most
|
||||||
|
# formats don't split assets across multiple files.
|
||||||
|
#
|
||||||
|
# If used, blob names usually contain the file
|
||||||
|
# extension that should be used when writing
|
||||||
|
# the data to disc.
|
||||||
|
("name", String),
|
||||||
|
|
||||||
|
# Pointer to the next blob in the chain or NULL if there is none.
|
||||||
|
("next", POINTER(ExportDataBlob)),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class Scene(Structure):
|
class Scene(Structure):
|
||||||
"""
|
"""
|
||||||
See 'aiScene.h' for details.
|
See 'aiScene.h' for details.
|
||||||
|
|
Loading…
Reference in New Issue