How to use the yoga.model._assimp.ffi 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 / helpers.py View on Github external
# Optimizing the texture if requested
        if optimize_textures:
            if not quiet:
                if valid_image_path is not None:
                    print("Optimizing texture %s..." % valid_image_path)
                else:
                    print("Optimizing fallback texture...")
            output_io = io.BytesIO()
            yoga.image.optimize(image_io, output_io, image_options)
            image_io = output_io

        image_io.seek(0)
        image_bytes = image_io.read()

        # Convert to cffi
        image_bytes_c = ffi.new("char[%d]" % len(image_bytes), image_bytes)
        image.bytes_length = len(image_bytes)
        image.bytes = image_bytes_c
        image.id = len(optimized_textures)

        optimized_textures[valid_image_path] = image
        image = image.next

        # @note Save the bytes to a dictionnary so that the garbage collector
        # does not occur before exporting the scene a bit later
        images_bytes[valid_image_path] = image_bytes_c
github wanadev / yoga / yoga / model / assimp.py View on Github external
:param verbose: whether verbose is active
    :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
github wanadev / yoga / yoga / model / assimp.py View on Github external
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
github wanadev / yoga / yoga / model / helpers.py View on Github external
def model_embed_images(images, images_bytes,
                       optimize_textures, fallback_texture, root_path,
                       image_options, textures, quiet):
    optimized_textures = {}
    normalized_textures = normalize_textures(textures)

    image = images
    while image:
        if image.bytes_length > 0:
            continue

        image_path = ffi.string(image.path).decode("utf-8")

        # If textures exists, we don't look for files on the file system
        valid_image_path = None
        if normalized_textures is not None:
            valid_image_path = normalize_path(image_path)
            valid_image_path = find_valid_texture_path(valid_image_path, normalized_textures) # noqa
        else:
            valid_image_path = find_valid_path(image_path, root_path)
            if valid_image_path is not None:
                valid_image_path = os.path.abspath(valid_image_path)

        # Unable to find a valid image path
        if valid_image_path is None:
            if fallback_texture is not None:
                if not quiet:
                    print("Warning: Cannot resolve file %s, using the fallback texture instead." % image_path) # noqa