Skip to content

Rust lib for SEGA txp Image format

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

diva-rust-modding/txp

Repository files navigation

txp

txp is a rust library for manipulating SEGA’s proprietary texture format (`_tex.bin`) used in various games. The games that use this format are (but are not limited to):

  • Hatsune Miku: Project DIVA (versions based on Virtua Fighter 5; Arcade, Dreamy Theater, F…)

Features

txp can be built with extra features:

ddsfile
Enables integration with the ddsfile library to convert to/from .dds
pyo3
Python integration

Usage

txp can be embedded into any standard rust crate, and thus can be used to create any utilities.

Rust Examples

txp has examples which can be executed and test the library.

metadata
print information about a particular txp
extract
extract textures from a txp

Examples can be run like the following

cargo run --example metadata

You can even install an example if you frequently use it,

cargo install --example metadata

FFI

Python

txp exposes an `abi3` Python FFI using the `pyo3` crate. The built bindings can be used in any python v3.7+ interpreter. An example is the blender_io_scene_bin plugin which is the de facto user. The main entry point of this FFI is src/py_ffi.rs.

import txp
atlas = txp.read("your_txp_here.bin")
for tex in atlas.textures:
    print(tex)
    for subtex in tex.subtextures:
        for mip in subtex:
            print("\t", mip)

Other

See #6 on the progress of other language FFI

Building

Cargo

This method produces a dynamically linked library, which is useful for the Python FFI

cargo build --release --all-features
mv ./target/release/
ln -s libtxp.dylib txp.so

For *nix OSes, the extension of the txp file should be .so, meanwhile for Windows it should be .pyd

You can verify that your built objects are working by importing the module in a python repl.

import txp

If everything worked, you should not get any exceptions

Maturin (Recommended for Python FFI)

This method produces wheels that could be installed using pip which can be generated by the following command,

# for maturin >= 0.13.0
maturin build --release --no-sdist --all-features
# for older versions
maturin build --release --no-sdist --cargo-extra-args="--all-features"

If prompted to specify the interpreter, use the default system interpreter `-i python`.

For more information, please visit the official maturin docs.

Nix (Recommended)

txp also exposes a nix flake for Nix users. The default package to be built is the rust crate.

nix build github:waelwindows/txp

To build the python wheel, build the txp-python package as following,

nix build github:waelwindows/txp#txp-python

Overlay

The flake also has an overlay which exposes the library and python bindings. It can be imported as such

import nixpkgs {
  inherit system;
  overlays = [ txp.overlays.default ];
}

And used like the following

yourDerivationHere {
  buildInputs = with pkgs; [
    # the rust crate
    txp
    # or the python bindings
    (python3.withPackages (p: [ p.txp ]))
  ];
}

Development Environment

The flake also has a devshell which contains all the necessary tools to compile the project.

nix develop

The python bindings can be tested using

nix develop .#python
Direnv

There’s also direnv integration in the project to make using the devshell easier. When first opening the project

$ direnv: error txp/.envrc is blocked. Run `direnv allow` to approve its content
direnv allow

License

txp is licensed under either of

at your option.

Contribution

See CONTRIBUTING.org

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Special Thanks to