jkvargas / russimp

Assimp bindings for Rust
Other
84 stars 27 forks source link

How can I get a texture filename from a scene #10

Closed ThomasT75 closed 3 years ago

ThomasT75 commented 3 years ago

I'm following a OpenGL tutorial but after a while trying to figure out how to get a texture filename all I can get from the scene is a part of the filename

This is what I got so far

Note: this is the obj I'm using is from the tutorial

let scene = Scene::from_file("path/to/obj",
      vec![
          PostProcess::Triangulate,
          PostProcess::FlipUVs,
          PostProcess::EmbedTextures
      ]      
).unwrap();

let material = &scene.materials[1];

for i in 0..material.0.len() {
    match &material.0[i].key[..] {
        "$tex.file" => println!("{:?}", std::str::from_utf8(&material.0[i].data).unwrap()),
        _ => {},
    }
}

Prints:

"\u{b}\u{0}\u{0}\u{0}*0\u{0}fuse.jpg\u{0}"
"\u{c}\u{0}\u{0}\u{0}*1\u{0}cular.jpg\u{0}"
"\n\u{0}\u{0}\u{0}*2\u{0}mal.png\u{0}"

Note: I can get only the letters by converting only this range [7..len - 1] but is not the full filename

the full texture filenames are

also the scene.textures is like this:

[
    Texture {
        filename: "",
        height: 0,
        width: 6108855,
        ach_format_hint: "jpg",
        data: [],
    },
    Texture {
        filename: "",
        height: 0,
        width: 6722296,
        ach_format_hint: "jpg",
        data: [],
    },
    Texture {
        filename: "",
        height: 0,
        width: 15214871,
        ach_format_hint: "png",
        data: [],
    },
]

Idk if I'm doing something wrong or the data is just like that, but any help is appreciated :D also Thanks for porting this to rust :+1:

jkvargas commented 3 years ago

Hey dude. I am doing some refactors on the material side. This week I will release it and I will let you know about it :)

jkvargas commented 3 years ago

Hey dude, I am releasing version 1.8 Today. I did some refactors on the material side. the property info will be delivered with the wanted data instead of a byte array. I was able to glance at your issue. made a small test inside the crate with your file locally and the filenames return correctly, doing a small application referencing the crate return those weird characters. I will continue to investigate it during the week.

pub enum PropertyTypeInfo { Buffer(Vec<u8>), IntegerArray(Vec<i32>), FloatArray(Vec<f32>), String(String), }

jkvargas commented 3 years ago

hey mate, just released 0.1.9. Doing a small test here with your backpack file:

use russimp::{ scene::{Scene, PostProcess}, };

fn main() { let scene = Scene::from_file("/home/vargasj/dev/backpack/model/backpack.obj", vec![ PostProcess::Triangulate, PostProcess::FlipUVs, ]).unwrap();

dbg!(&scene.materials); }

this has returned to me the correct content for your obj file. since your texture files are not embedded you can read them manually. Would that work for you? Let me know if you have any issues.