Merge pull request #847 from stevenjt/python-scene-export

Added ability to export scenes with PyAssimp
pull/850/head
Kim Kulling 2016-04-03 17:43:05 +02:00
commit 001eede34c
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. Python 3 support is mostly here, but not well tested.
Note that pyassimp is not complete. Many ASSIMP features are missing. In Note that pyassimp is not complete. Many ASSIMP features are missing.
particular, only loading of models is currently supported (no export).
USAGE USAGE
----- -----

View File

@ -35,7 +35,7 @@ class AssimpLib(object):
""" """
Assimp-Singleton Assimp-Singleton
""" """
load, load_mem, release, dll = helper.search_library() load, load_mem, export, 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):
@ -316,6 +316,33 @@ def load(filename,
recur_pythonize(scene.rootnode, scene) recur_pythonize(scene.rootnode, scene)
return 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): def release(scene):
from ctypes import pointer from ctypes import pointer
_assimp_lib.release(pointer(scene)) _assimp_lib.release(pointer(scene))

View File

@ -161,7 +161,8 @@ def try_load_functions(library_path, dll):
If successful: If successful:
Tuple containing (library_path, Tuple containing (library_path,
load from filename function, load from filename function,
load from memory function load from memory function,
export to filename function,
release function, release function,
ctypes handle to assimp library) ctypes handle to assimp library)
''' '''
@ -170,6 +171,7 @@ def try_load_functions(library_path, dll):
load = dll.aiImportFile load = dll.aiImportFile
release = dll.aiReleaseImport release = dll.aiReleaseImport
load_mem = dll.aiImportFileFromMemory load_mem = dll.aiImportFileFromMemory
export = dll.aiExportScene
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
@ -178,7 +180,7 @@ def try_load_functions(library_path, dll):
from .structs import Scene from .structs import Scene
load.restype = POINTER(Scene) load.restype = POINTER(Scene)
load_mem.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(): def search_library():
''' '''
@ -187,6 +189,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,
release function, release function,
dll) dll)
''' '''