~wahn/rs-pbrt

665102576a6485e00d548615f18aceccc99f3284 — Jan Walter 3 months ago d3ac327
Use blend_info v0.2.1. That should at least render some scenes.
3 files changed, 7 insertions(+), 145 deletions(-)

M Cargo.lock
M Cargo.toml
M examples/parse_blend_file.rs
M Cargo.lock => Cargo.lock +2 -2
@@ 84,9 84,9 @@ checksum = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"

[[package]]
name = "blend_info"
version = "0.1.1"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d393f43eb1cf649203108e6b7ec4cc1aa63201d8bec3053226f338772ba0b37"
checksum = "403b05df6fe601c77ce99f4af81ea22127a20d6ef3d39547c7dc4495b926d12f"
dependencies = [
 "structopt",
]

M Cargo.toml => Cargo.toml +1 -1
@@ 12,7 12,7 @@ homepage = "https://www.rs-pbrt.org"
[dependencies]
atom = "0.4.0"
atomic = "0.5.1"
blend_info = "0.1.1"
blend_info = "0.2.1"
byteorder = "1.4.3"
crossbeam = "0.8.1"
crossbeam-channel = "0.5.2"

M examples/parse_blend_file.rs => examples/parse_blend_file.rs +4 -142
@@ 23,7 23,10 @@ use std::mem;
use std::path::Path;
use std::sync::Arc;
// others
use blend_info::{calc_mem_tlen, read_dna, use_dna, DnaStrC, DnaStrMember};
use blend_info::{
    calc_mem_tlen, get_float, get_float2, get_float3, get_id_name, get_int, get_matrix, get_short,
    get_short3, read_dna, use_dna, DnaStrC, DnaStrMember,
};
// pbrt
use rs_pbrt::core::api::{make_accelerator, make_camera, make_film, make_filter, make_sampler};
use rs_pbrt::core::camera::Camera;


@@ 111,147 114,6 @@ struct Cli {
    path: std::path::PathBuf,
}

// blend_info

fn get_id_name(
    member: &DnaStrMember,
    bytes_read: &[u8],
    byte_index: usize,
    dna_structs_hm: &HashMap<String, DnaStrC>,
    dna_types_hm: &HashMap<String, u16>,
) -> String {
    let mut return_str: String = String::new();
    if let Some(struct_found2) = dna_structs_hm.get(member.mem_type.as_str()) {
        let mut byte_index2: usize = 0;
        for member2 in &struct_found2.members {
            if let Some(type_found2) = dna_types_hm.get(&member2.mem_type) {
                let mem_tlen2: u16 = calc_mem_tlen(member2, *type_found2);
                if member2.mem_name.contains("name") {
                    let mut id = String::with_capacity(mem_tlen2 as usize);
                    for i in 0..mem_tlen2 as usize {
                        if bytes_read[byte_index + byte_index2 + i] == 0 {
                            break;
                        }
                        if (bytes_read[byte_index + byte_index2 + i] as char)
                            .is_ascii_alphanumeric()
                        {
                            id.push(bytes_read[byte_index + byte_index2 + i] as char);
                        }
                    }
                    // this will be returned
                    return_str = id;
                    byte_index2 += mem_tlen2 as usize;
                } else {
                    byte_index2 += mem_tlen2 as usize;
                }
            }
        }
    }
    return_str
}

fn get_float(member: &DnaStrMember, bytes_read: &[u8], byte_index: usize) -> f32 {
    let mut float_value: f32 = 0.0;
    if member.mem_type.as_str() == "float" {
        let mut float_buf: [u8; 4] = [0_u8; 4];
        for i in 0..4 as usize {
            float_buf[i] = bytes_read[byte_index + i];
        }
        float_value = unsafe { mem::transmute(float_buf) };
    } else {
        println!("WARNING: \"float\" expected, {:?} found", member.mem_type);
    }
    float_value
}

fn get_float2(member: &DnaStrMember, bytes_read: &[u8], byte_index: usize) -> [f32; 2] {
    let mut float_values: [f32; 2] = [0.0; 2];
    if member.mem_type.as_str() == "float" {
        for i in 0..2 {
            let mut float_buf: [u8; 4] = [0_u8; 4];
            for i in 0..4 as usize {
                float_buf[i] = bytes_read[byte_index + i];
            }
            float_values[i] = unsafe { mem::transmute(float_buf) };
        }
    } else {
        println!("WARNING: \"float\" expected, {:?} found", member.mem_type);
    }
    float_values
}

fn get_float3(member: &DnaStrMember, bytes_read: &[u8], byte_index: usize) -> [f32; 3] {
    let mut float_values: [f32; 3] = [0.0; 3];
    if member.mem_type.as_str() == "float" {
        for i in 0..3 {
            let mut float_buf: [u8; 4] = [0_u8; 4];
            for i in 0..4 as usize {
                float_buf[i] = bytes_read[byte_index + i];
            }
            float_values[i] = unsafe { mem::transmute(float_buf) };
        }
    } else {
        println!("WARNING: \"float\" expected, {:?} found", member.mem_type);
    }
    float_values
}

fn get_int(member: &DnaStrMember, bytes_read: &[u8], byte_index: usize) -> i32 {
    let mut int_value: i32 = 0;
    if member.mem_type.as_str() == "int" {
        int_value += (bytes_read[byte_index] as i32) << 0;
        int_value += (bytes_read[byte_index + 1] as i32) << 8;
        int_value += (bytes_read[byte_index + 2] as i32) << 16;
        int_value += (bytes_read[byte_index + 3] as i32) << 24;
    } else {
        println!("WARNING: \"int\" expected, {:?} found", member.mem_type);
    }
    int_value
}

fn get_short(member: &DnaStrMember, bytes_read: &[u8], byte_index: usize) -> i16 {
    let mut short_value: i16 = 0;
    if member.mem_type.as_str() == "short" {
        short_value += (bytes_read[byte_index] as i16) << 0;
        short_value += (bytes_read[byte_index + 1] as i16) << 8;
    } else {
        println!("WARNING: \"short\" expected, {:?} found", member.mem_type);
    }
    short_value
}

fn get_short3(member: &DnaStrMember, bytes_read: &[u8], byte_index: usize) -> [i16; 3] {
    let mut short_values: [i16; 3] = [0; 3];
    if member.mem_type.as_str() == "short" {
        for i in 0..3 {
            let mut short_value: i16 = 0;
            short_value += (bytes_read[byte_index] as i16) << 0;
            short_value += (bytes_read[byte_index + 1] as i16) << 8;
            short_values[i] = short_value;
        }
    } else {
        println!("WARNING: \"short\" expected, {:?} found", member.mem_type);
    }
    short_values
}

fn get_matrix(member: &DnaStrMember, bytes_read: &[u8], byte_index: usize) -> [f32; 16] {
    let mut mat_values: [f32; 16] = [0.0_f32; 16];
    let mut skip_bytes: usize = 0;
    for i in 0..4 {
        for j in 0..4 {
            let mut mat_buf: [u8; 4] = [0_u8; 4];
            for b in 0..4 as usize {
                mat_buf[b] = bytes_read[byte_index + skip_bytes + b];
            }
            let mat: f32 = unsafe { mem::transmute(mat_buf) };
            mat_values[i * 4 + j] = mat;
            skip_bytes += 4;
        }
    }
    mat_values
}

// PBRT

#[derive(Debug, Default, Copy, Clone)]