mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-22 20:57:46 +00:00
Add Texture structure, begin reading header
This commit is contained in:
parent
42ec97d70c
commit
7292ad930a
3 changed files with 54 additions and 9 deletions
22
src/dat.rs
22
src/dat.rs
|
@ -310,18 +310,26 @@ impl DatFile {
|
||||||
|
|
||||||
let texture_file_info = file_info.texture_info.unwrap();
|
let texture_file_info = file_info.texture_info.unwrap();
|
||||||
|
|
||||||
|
// write the header if it exists
|
||||||
|
if texture_file_info.lods[0].compressed_offset != 0 {
|
||||||
|
let original_pos = self.file.stream_position().unwrap();
|
||||||
|
|
||||||
|
self.file.seek(SeekFrom::Start(offset + file_info.size as u64));
|
||||||
|
let mut header = vec![0u8; texture_file_info.lods[0].compressed_offset as usize];
|
||||||
|
self.file.read(&mut header);
|
||||||
|
data.append(&mut header);
|
||||||
|
|
||||||
|
self.file.seek(SeekFrom::Start(original_pos));
|
||||||
|
}
|
||||||
|
|
||||||
for i in 0..texture_file_info.num_blocks {
|
for i in 0..texture_file_info.num_blocks {
|
||||||
let mut running_block_total = (texture_file_info.lods[i as usize].compressed_offset as u64) + offset + (file_info.size as u64);
|
let mut running_block_total = (texture_file_info.lods[i as usize].compressed_offset as u64) + offset + (file_info.size as u64);
|
||||||
|
|
||||||
data.append(&mut read_data_block(&self.file, running_block_total).unwrap());
|
for _ in 0..texture_file_info.lods[i as usize].block_count {
|
||||||
|
|
||||||
for _ in 1..texture_file_info.lods[i as usize].block_count {
|
|
||||||
running_block_total += i16::read(&mut self.file).unwrap() as u64;
|
|
||||||
data.append(&mut read_data_block(&self.file, running_block_total).unwrap());
|
data.append(&mut read_data_block(&self.file, running_block_total).unwrap());
|
||||||
|
self.file.seek(SeekFrom::Start(running_block_total));
|
||||||
|
running_block_total += i16::read(&mut self.file).unwrap() as u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy?
|
|
||||||
i16::read(&mut self.file).unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(data)
|
Some(data)
|
||||||
|
|
|
@ -57,5 +57,8 @@ pub mod skeleton;
|
||||||
// Reading file into files (FIIN).
|
// Reading file into files (FIIN).
|
||||||
pub mod fiin;
|
pub mod fiin;
|
||||||
|
|
||||||
// Reading and writing chat logs (LOG)
|
// Reading and writing chat logs (LOG).
|
||||||
pub mod log;
|
pub mod log;
|
||||||
|
|
||||||
|
// Reading textures (TEX).
|
||||||
|
pub mod tex;
|
34
src/tex.rs
Normal file
34
src/tex.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
use std::io::Cursor;
|
||||||
|
use binrw::binread;
|
||||||
|
use crate::gamedata::MemoryBuffer;
|
||||||
|
use binrw::BinRead;
|
||||||
|
|
||||||
|
#[binread]
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct TexHeader {
|
||||||
|
attribute : u32,
|
||||||
|
format: u32,
|
||||||
|
|
||||||
|
width : u16,
|
||||||
|
height : u16,
|
||||||
|
depth : u16,
|
||||||
|
mip_levels : u16,
|
||||||
|
|
||||||
|
lod_offsets : [u32; 3],
|
||||||
|
offset_to_surface : [u32; 13]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Texture {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Texture {
|
||||||
|
pub fn from_existing(buffer: &MemoryBuffer) -> Option<Texture> {
|
||||||
|
let mut cursor = Cursor::new(buffer);
|
||||||
|
let header = TexHeader::read(&mut cursor).unwrap();
|
||||||
|
|
||||||
|
println!("{:#?}", header);
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue