Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:param scene_p: the abstract scene (a CFFI pointer)
:param output_format: either "glb" or "gltf"
:returns: the generated bytes making a glb or gltf file
:rtype: bytes
:raises ValueError: Assimp was not able to export the model
"""
if output_format not in ("glb", "gltf"):
raise ValueError("Invalid output format: should be glb or gltf but is %s" % output_format) # noqa
output_format_dict = dict({
"glb": lib.OUTPUT_FORMAT_GLB,
"gltf": lib.OUTPUT_FORMAT_GLTF
})
bytes_out_p = ffi.new("char**")
bytes_out_p_gc = ffi.gc(bytes_out_p, lib.assimp_free_bytes)
length = lib.assimp_export_to_bytes(
scene_p,
output_format_dict[output_format],
bytes_out_p
)
if length == 0:
raise ValueError("Invalid model: Assimp was not able to export")
bytes_out = ffi.cast("char*", bytes_out_p_gc[0])
return ffi.unpack(bytes_out, length)