Crate blend_converter

source ·
Expand description

Blend Converter provides a convenient way to automatically convert blender files (.blend) to other 3D file formats that are easier to work with. Currently the only formats specified are gltf based (see OutputFormat).

Blender Executable

To convert blends we need a blender executable. By default we check the path for blender and flatpak but if you need to specify a path use ConversionOptions::blender_path. For more details about the search strategy see BlenderExecutable.

Example

use std::path::Path;
use blend_converter::ConversionOptions;

let input_dir = Path::new("blends");
let output_dir = Path::new("gltfs");
ConversionOptions::new().convert_dir(input_dir, output_dir).unwrap();

Build Script

You can use this in your build.rs to automatically convert blender files when they change. To do so your build.rs should look something like:

use std::path::Path;

let input_dir = Path::new("blends");
blend_converter::ConversionOptions::default()
    .convert_dir_build_script(input_dir)
    .expect("failed to convert blends");
println!("cargo:rerun-if-changed={}", input_dir.display());
println!("cargo:rerun-if-changed=build.rs");

Then assuming you have blends/test.blend, in your code you can open the converted files using something like:

use std::path::Path;

let path = Path::new(env!("OUT_DIR")).join("blends").join("test.glb");
let f = std::fs::File::open(path);

Structs

Enums