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…)
txp
can be built with extra features:
ddsfile
- Enables integration with the
ddsfile
library to convert to/from .dds pyo3
- Python integration
txp
can be embedded into any standard rust crate, and thus can be used to create any utilities.
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
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)
See #6 on the progress of other language FFI
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
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.
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
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 ]))
];
}
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
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
txp
is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
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.