Added ability to export scenes with PyAssimp

pull/847/head
Steven Thompson 2016-04-03 13:03:16 +01:00
parent d094dfc3a1
commit 06e262f892
3 changed files with 34 additions and 5 deletions

View File

@ -6,8 +6,7 @@ Requires Python >= 2.6.
Python 3 support is mostly here, but not well tested.
Note that pyassimp is not complete. Many ASSIMP features are missing. In
particular, only loading of models is currently supported (no export).
Note that pyassimp is not complete. Many ASSIMP features are missing.
USAGE
-----

View File

@ -35,7 +35,7 @@ class AssimpLib(object):
"""
Assimp-Singleton
"""
load, load_mem, release, dll = helper.search_library()
load, load_mem, export, release, dll = helper.search_library()
_assimp_lib = AssimpLib()
def make_tuple(ai_obj, type = None):
@ -316,6 +316,33 @@ def load(filename,
recur_pythonize(scene.rootnode, scene)
return scene
def export(scene,
filename,
file_type = None,
processing = postprocess.aiProcess_Triangulate):
'''
Export a scene. On failure throws AssimpError.
Arguments
---------
scene: scene to export.
filename: Filename that the scene should be exported to.
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)
'''
from ctypes import pointer
exportStatus = _assimp_lib.export(pointer(scene), file_type.encode("ascii"), filename.encode("ascii"), processing)
if exportStatus != 0:
raise AssimpError('Could not export scene!')
def release(scene):
from ctypes import pointer
_assimp_lib.release(pointer(scene))

View File

@ -161,7 +161,8 @@ def try_load_functions(library_path, dll):
If successful:
Tuple containing (library_path,
load from filename function,
load from memory function
load from memory function,
export to filename function,
release function,
ctypes handle to assimp library)
'''
@ -170,6 +171,7 @@ def try_load_functions(library_path, dll):
load = dll.aiImportFile
release = dll.aiReleaseImport
load_mem = dll.aiImportFileFromMemory
export = dll.aiExportScene
except AttributeError:
#OK, this is a library, but it doesn't have the functions we need
return None
@ -178,7 +180,7 @@ def try_load_functions(library_path, dll):
from .structs import Scene
load.restype = POINTER(Scene)
load_mem.restype = POINTER(Scene)
return (library_path, load, load_mem, release, dll)
return (library_path, load, load_mem, export, release, dll)
def search_library():
'''
@ -187,6 +189,7 @@ def search_library():
Returns: tuple, (load from filename function,
load from memory function,
export to filename function,
release function,
dll)
'''