How to use the yoga.model._assimp.ffi.gc function in yoga

To help you get started, we’ve selected a few yoga examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wanadev / yoga / yoga / model / assimp.py View on Github external
: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)
github wanadev / yoga / yoga / model / assimp.py View on Github external
:returns: An abstract scene dict
    :raises ValueError: Assimp was not able to import the model
    """

    optimization_flags = 0
    if optimize_graph:
        optimization_flags |= lib.OPTIMIZATION_FLAG_GRAPH
    if optimize_meshes:
        optimization_flags |= lib.OPTIMIZATION_FLAG_MESHES

    scene = {
        "cffi_pointer": None,
        "cffi_gc": None
    }
    scene["cffi_pointer"] = ffi.new("Scene*")
    scene["cffi_gc"] = ffi.gc(scene["cffi_pointer"], lib.assimp_free_scene)

    lib.assimp_import_from_bytes(
        bytes_in,
        len(bytes_in),
        optimization_flags,
        scene["cffi_pointer"],
        verbose
        )

    if scene["cffi_pointer"].assimp_scene == ffi.NULL:
        raise ValueError("Invalid model: Assimp was not able to import the model")  # noqa

    return scene