YOGA Model Python API
This module allows to convert and optimize 3D models.
Usage
converting and optimizing a model:
import yoga.model
yoga.model.optimize("./input.fbx", "./output.glb")
You can also tune the output by passing options:
yoga.model.optimize("./input.fbx", "./output.glb", options={
# Model options
"output_format": "glb", # "glb"|"gltf"
"fallback_texture": None, # None|<FileLike>|"./image.png"
"no_graph_optimization": False, # True|False
"no_meshes_optimization": False, # True|False
"no_textures_optimization": False, # True|False
"no_fix_infacing_normals": False, # True|False
# Images (textures) options
"image_output_format": "orig", # "orig"|"auto"|"jpeg"|"png"|"webp"|"webpl"
"image_resize": "orig", # "orig"|[width,height]
"image_jpeg_quality": 0.84, # 0.00-1.0
"image_webp_quality": 0.90, # 0.00-1.0
"image_opacity_threshold": 254, # 0-255
"image_png_slow_optimization": False, # True|False
})
Available Model Options
output_format
The format of the output model.
yoga.model.optimize("./input.fbx", "./output.glb", options={
"output_format": "glb",
})
The following formats are supported:
glb(default)gltf
fallback_texture
This option allows you to provide a fallback texture that will be used when YOGA is unable to find one of the model textures.
The following values are allowed:
None: no fallback texture,a Python
str(andunicodefor Python 2): path of a fallback image file (e.g."./fallback.png"),a “File-like” object (file,
BytesIO, etc.).
yoga.model.optimize("./input.fbx", "./output.glb", options={
"fallback_texture": None,
})
yoga.model.optimize("./input.fbx", "./output.glb", options={
"fallback_texture": "./fallback.png",
})
image_file = open("./fallback.png", "rb")
yoga.model.optimize("./input.fbx", "./output.glb", options={
"fallback_texture": image_file,
})
no_graph_optimization
Disables empty graph nodes merging.
yoga.model.optimize("./input.fbx", "./output.glb", options={
"no_graph_optimization": False,
})
no_meshes_optimization
Disable mesh optimization.
yoga.model.optimize("./input.fbx", "./output.glb", options={
"no_meshes_optimization": False,
})
no_textures_optimization
Disable texture optimizations (textures will not be optimized using YOGA Image).
yoga.model.optimize("./input.fbx", "./output.glb", options={
"no_textures_optimization": False,
})
no_fix_infacing_normals
Disables the assimp’s infacing normals fix. This postprocess tries to determine which meshes have normal vectors that are facing inwards and inverts them. See the assimp documentation for more details.
yoga.model.optimize("./input.fbx", "./output.glb", options={
"no_fix_infacing_normals": False,
})
Available Image Options
YOGA Model optimizes textures using YOGA Images, so there are options equivalent to the YOGA Image ones available:
The YOGA Model
image_output_formatoption is equivalent to theoutput_formatof YOGA Image,The YOGA Model
image_resizeoption is equivalent to theresizeof YOGA Image,The YOGA Model
image_jpeg_qualityoption is equivalent to thejpeg_qualityof YOGA Image,The YOGA Model
image_webp_qualityoption is equivalent to thewebp_qualityof YOGA Image,The YOGA Model
image_opacity_thresholdoption is equivalent to theopacity_thresholdof YOGA Image,The YOGA Model
image_png_slow_optimizationoption is equivalent to thepng_slow_optimizationof YOGA Image,The YOGA Model
image_enable_quantizationoption is equivalent to theenable_quantizationof YOGA Image,The YOGA Model
image_quantization_dithering_leveloption is equivalent to thequantization_dithering_levelof YOGA Image,The YOGA Model
image_quantization_max_colorsoption is equivalent to thequantization_max_colorsof YOGA Image,
See YOGA Image options for more information.
API
- yoga.model.optimize(input_file, output_file, options={}, textures=None, verbose=False, quiet=False)
Optimize given model.
- Parameters:
input_file (str,file-like) – The input model file.
output_file (str,file-like) – The output model file.
options (dict) – Optimization options (see above).
textures (dict) – A dictionary that maps textures path to bytes. When not
None, there will be no file system reads in order to find referenced textures. YOGA will look into that dictionary instead.verbose (bool) – If
True, Assmimp debug message will be print to stdout.quiet (bool) – If
True, YOGA will not write any warning on stdout or stderr.
Example
texturesdictionary:textures = { "images/texture1.png": open("./images/texture1.png", "rb").read(), "texture2.png": open("./texture1.png", "rb").read(), }