Skip to main content

Python bindings for ufbx - Single source file FBX loader

Project description

ufbx-python

PyPI version Tests Python Versions License: MIT

Python bindings for ufbx - a single source file FBX loader library.

Status

🚧 In Progress - Core API is available, broader coverage is under active development.

Currently implemented:

  • Core scene loading and querying (Scene, Node, Mesh, Material)
  • Zero-copy numpy arrays for vertex data
  • Basic math types (Vec2/Vec3/Vec4/Quat/Matrix/Transform)
  • Core enums and error types
  • Type hints via .pyi

Installation

pip install pyufbx

Note: The PyPI package name is pyufbx, but you import it as ufbx:

import ufbx  # Not "import pyufbx"

Install from source:

git clone https://github.com/popomore/ufbx-python.git
cd ufbx-python
pip install .

Technical Stack

  • Binding Method: Cython with thin C wrapper
  • Performance: Zero-copy numpy arrays for vertex data
  • Architecture: C wrapper layer hides complex ufbx structures, Cython provides Pythonic API
  • Dependency Management: Using sfs.py to manage dependencies with exact commit hashes

Quick Start

Build from Source

# Install dependencies
pip install Cython numpy

# Update ufbx C library (if needed)
python3 sfs.py update --all

# Build Cython extension
python setup.py build_ext --inplace

# Or install in development mode
pip install -e .

Usage Example

import ufbx

# Load FBX file
with ufbx.load_file("model.fbx") as scene:
    # Basic scene info
    print(f"Nodes: {len(scene.nodes)}")
    print(f"Meshes: {len(scene.meshes)}")
    print(f"Materials: {len(scene.materials)}")

    # Access scene hierarchy
    for node in scene.nodes:
        print(f"Node: {node.name}")
        if node.mesh:
            mesh = node.mesh
            print(f"  Mesh: {mesh.num_vertices} vertices, {mesh.num_faces} faces")
        # Light/Camera/etc. wrappers are placeholders for now

    # Access mesh data
    for mesh in scene.meshes:
        positions = mesh.vertex_positions
        normals = mesh.vertex_normals
        uvs = mesh.vertex_uvs
        print(f"Mesh '{mesh.name}': {len(positions)} vertices")

    # Math operations
    node = scene.find_node("MyNode")
    if node:
        local_matrix = node.local_transform
        print(f"Local matrix: {local_matrix}")

# Or use class method
scene = ufbx.Scene.load_file("model.fbx")
try:
    # Use scene
    print(scene)
finally:
    scene.close()

Run example script:

python3 examples/basic_usage.py tests/data/your_model.fbx

Current Progress

  • Project structure setup
  • Dependency management with sfs.py
  • Download ufbx source (commit: 6ecd6177af59c82ec363356ac36c3a4245b85321)
  • Build system (setup.py, pyproject.toml)
  • Cython implementation with C wrapper
  • Implement core API (Scene, Node, Mesh, Material classes)
  • Zero-copy numpy array support for vertex data
  • Proper lifetime management with context managers
  • Write example code
  • Add more element types (Light, Camera, Animation, Deformers, etc.)
  • Add math types (Vec2, Vec3, Vec4, Quat, Matrix, Transform)
  • Add enum types (core set used by tests)
  • Add type hints (.pyi files)

Dependency Management

This project uses sfs.py for dependency management:

# Update dependencies
python3 sfs.py update --all

# View current version
cat sfs-deps.json.lock

Features

  • High Performance: Cython-based bindings compiled to native code
  • Zero-Copy Access: Numpy arrays directly reference ufbx memory
  • Memory Management: Automatic resource cleanup with context managers
  • Pythonic API: Context managers, property access, Python idioms
  • Core Functionality: Scene loading, mesh data, materials, node hierarchy
  • 🚧 Expanding Coverage: More element types, enums, and APIs are being added

Development

Build from Source

# Clone repository
git clone https://github.com/popomore/ufbx-python.git
cd ufbx-python

# Download dependencies
python3 sfs.py update --all

# Install development dependencies
pip install -e .[dev]

# Build
python setup.py build_ext --inplace

# Run tests
pytest tests/ -v

Publishing to PyPI

See Release Guide for how to publish new versions to PyPI.

References

License

MIT - See LICENSE file for details.

This project includes ufbx, also under the MIT License.

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

pyufbx-0.0.7.tar.gz (678.0 kB view details)

Uploaded Source

File details

Details for the file pyufbx-0.0.7.tar.gz.

File metadata

  • Download URL: pyufbx-0.0.7.tar.gz
  • Upload date:
  • Size: 678.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyufbx-0.0.7.tar.gz
Algorithm Hash digest
SHA256 aabe7cb568f538719c5b7d3efc19f0f578678f99c1e5b3d52689bfc9a15e0e4b
MD5 66ecfa33fbfa1b49fb5acd12f8990992
BLAKE2b-256 4eb2288f8affd43ceb15d60f47a17e661671eeec297c8c21fb23db8eff54ed3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyufbx-0.0.7.tar.gz:

Publisher: publish.yml on popomore/ufbx-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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