diff --git a/port/PyAssimp/README.md b/port/PyAssimp/README.md index 77db57fae..201d3ed7d 100644 --- a/port/PyAssimp/README.md +++ b/port/PyAssimp/README.md @@ -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 ----- diff --git a/port/PyAssimp/pyassimp/core.py b/port/PyAssimp/pyassimp/core.py index a183dc79c..27ec44c97 100644 --- a/port/PyAssimp/pyassimp/core.py +++ b/port/PyAssimp/pyassimp/core.py @@ -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)) diff --git a/port/PyAssimp/pyassimp/helper.py b/port/PyAssimp/pyassimp/helper.py index ad38e3b71..5113e895a 100644 --- a/port/PyAssimp/pyassimp/helper.py +++ b/port/PyAssimp/pyassimp/helper.py @@ -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) '''