Skip to main content

A small module for baking textures from MaterialX (.mtlx) format.

Project description

from src.materialx_baker import bake_to_numpy

materialx-baker

Description

A small library for baking textures from .mtlx files. Given an .mtlx it produces a series of .exr files, one for each node graph inside the file.

Table of Contents

Features

  • Baking textures to numpy arrays for in memory usage.
  • Baking textures to .exr files.

Prerequisites

Installation

Use pre-build wheel on PYPI. pip install materialx_baker

Or clone the repository and use uv.

On linux

git clone https://github.com/KidziaK/materialx-baker
cd materialx-baker
uv pip install .

Usage

The main API is very simple and consists of 2 functions: bake_to_numpy(mtlx_path) and bake_to_file(mtlx_path, output_path). As the names suggest, the first one will output the dictionary of N-dictionaries (where N is the number of node graphs inside the .mtlx). Each inner dictionary is a key-value pair, where key is the name of the output for the given graph and value is the numpy array holding a texture.

from materialx_baker import bake_to_numpy
from pathlib import Path

mtlx_path = Path("path_to_mtlx.mtlx")

textures = bake_to_numpy(mtlx_path)

for graph, tex in textures.items():
    ...

The second function bake_to_file() produces N .exr files with the appropriate textures.

from materialx_baker import bake_to_file
from pathlib import Path

mtlx_path = Path("path_to_mtlx.mtlx")
output_path = Path("output_dir/")

bake_to_file(mtlx_path, output_path)  # <mtlx_name>_<graph_name>.mtlx

If you need custom logic for parsing, validating or controlling docs and graphs, you can import and use MTLXBaker class, however it is not recommended.

Testing

# Using pytest
pytest src/

Limitations

  • Only works for geometry independent graphs. Geometry nodes like position will cause an error.
  • Lacks support for certain nodes. These will be added in later versions.
  • Output only support .exr. I'm not planning on adding other formats in the future.
  • This is not a production ready project and requires some polishing. Use at your own risk.

License

The MIT License (MIT) - see LICENSE.txt

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

materialx_baker-0.1.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

materialx_baker-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file materialx_baker-0.1.0.tar.gz.

File metadata

  • Download URL: materialx_baker-0.1.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.5

File hashes

Hashes for materialx_baker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 173e53f46e643a7114a090dd5a88ed92aee99ac0e5419276a48eb9bdfebc1af6
MD5 1dd412e5712a33e0c7d69a263b61937c
BLAKE2b-256 2a146aa643189c3b482e992f97b09018b30792b22b928a8eeb90d8c062c919ca

See more details on using hashes here.

File details

Details for the file materialx_baker-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for materialx_baker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e314c53d04ab38279f4b9f0282bb5c7e0aab7cc0a91e9f43ab274d7077b4f2b
MD5 01fd5ef09681fbff6207550d6bf321d6
BLAKE2b-256 efcccc92dd0d2bddbe1dbc80cc788c9dbec67382402649a20a2ded7094928a36

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page