Skip to content

Commit

Permalink
fix json issues & clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
amPerl committed Aug 2, 2024
1 parent bbf5b7c commit 6798baf
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 36 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nif"
version = "0.4.2"
version = "0.5.0"
edition = "2021"
authors = ["Romet Tagobert <[email protected]>"]
categories = []
Expand All @@ -27,7 +27,7 @@ gltf_export = ["gltf", "gltf-json"]
[dependencies]
anyhow = "1.0.72"
thiserror = "1.0.43"
glam = "0.24.1"
gltf = { version = "1.2.0", optional = true }
gltf-json = { version = "1.2.0", optional = true }
binrw = "0.11.2"
glam = "0.28.0"
gltf = { version = "1.4.1", optional = true }
gltf-json = { version = "1.4.1", optional = true }
binrw = "0.14.0"
12 changes: 11 additions & 1 deletion src/blocks/ni_particle/ni_psys_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct NiPSysData {
pub base: NiParticlesData,

#[br(count = base.base.num_vertices)]
pub particle_info: Vec<(Vector3, f32, f32, f32, u32)>,
pub particle_info: Vec<NiParticleInfo>,

#[br(map = |x: u8| x > 0)]
pub has_unknown_floats: bool,
Expand All @@ -21,6 +21,16 @@ pub struct NiPSysData {
pub unknown_short_2: u16,
}

#[derive(Debug, PartialEq, BinRead)]
pub struct NiParticleInfo {
pub velocity: Vector3,
pub age: f32,
pub life_span: f32,
pub last_update: f32,
pub spawn_generation: u16,
pub code: u16,
}

impl NiPSysData {
pub fn parse<R: Read + Seek>(reader: &mut R) -> anyhow::Result<Self> {
Ok(reader.read_le()?)
Expand Down
50 changes: 25 additions & 25 deletions src/collectors/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Gltf {
let buffer_path = gltf_path.with_file_name(&relative_buffer_path);

gltf.buffers.push(json::Buffer {
byte_length: buffer_vec.len() as u32,
byte_length: buffer_vec.len().into(),
name: Some(format!("{}_Buffer{}", gltf_filename, buffer_idx)),
uri: Some(relative_buffer_path),
extensions: Default::default(),
Expand Down Expand Up @@ -800,9 +800,9 @@ impl Gltf {
Some(vertices) => {
self.root.buffer_views.push(json::buffer::View {
buffer: buffer_index,
byte_length: expected_vertices_length as u32,
byte_offset: Some(offset_so_far),
byte_stride: Some(12),
byte_length: expected_vertices_length.into(),
byte_offset: Some(json::validation::USize64(offset_so_far as _)),
byte_stride: Some(json::buffer::Stride(12)),
name: Some(format!("{}_Buffer_Vertices", name)),
target: Some(Valid(json::buffer::Target::ArrayBuffer)),
extensions: Default::default(),
Expand All @@ -813,8 +813,8 @@ impl Gltf {
json::Index::new(self.root.buffer_views.len() as u32 - 1);
self.root.accessors.push(json::Accessor {
buffer_view: Some(buffer_view_index),
byte_offset: Some(0),
count: vertices.len() as u32,
byte_offset: Some(json::validation::USize64(0)),
count: vertices.len().into(),
component_type: Valid(json::accessor::GenericComponentType(
json::accessor::ComponentType::F32,
)),
Expand Down Expand Up @@ -844,9 +844,9 @@ impl Gltf {
Some(normals) => {
self.root.buffer_views.push(json::buffer::View {
buffer: buffer_index,
byte_length: expected_normals_length as u32,
byte_offset: Some(offset_so_far),
byte_stride: Some(12),
byte_length: expected_normals_length.into(),
byte_offset: Some(json::validation::USize64(offset_so_far as _)),
byte_stride: Some(json::buffer::Stride(12)),
name: Some(format!("{}_Buffer_Normals", name)),
target: Some(Valid(json::buffer::Target::ArrayBuffer)),
extensions: Default::default(),
Expand All @@ -857,8 +857,8 @@ impl Gltf {
json::Index::new(self.root.buffer_views.len() as u32 - 1);
self.root.accessors.push(json::Accessor {
buffer_view: Some(buffer_view_index),
byte_offset: Some(0),
count: normals.len() as u32,
byte_offset: Some(json::validation::USize64(0)),
count: normals.len().into(),
component_type: Valid(json::accessor::GenericComponentType(
json::accessor::ComponentType::F32,
)),
Expand Down Expand Up @@ -888,9 +888,9 @@ impl Gltf {
Some(colors) => {
self.root.buffer_views.push(json::buffer::View {
buffer: buffer_index,
byte_length: expected_colors_length as u32,
byte_offset: Some(offset_so_far),
byte_stride: Some(16),
byte_length: expected_colors_length.into(),
byte_offset: Some(json::validation::USize64(offset_so_far as _)),
byte_stride: Some(json::buffer::Stride(16)),
name: Some(format!("{}_Buffer_Colors", name)),
target: Some(Valid(json::buffer::Target::ArrayBuffer)),
extensions: Default::default(),
Expand All @@ -901,8 +901,8 @@ impl Gltf {
json::Index::new(self.root.buffer_views.len() as u32 - 1);
self.root.accessors.push(json::Accessor {
buffer_view: Some(buffer_view_index),
byte_offset: Some(0),
count: colors.len() as u32,
byte_offset: Some(json::validation::USize64(0)),
count: colors.len().into(),
component_type: Valid(json::accessor::GenericComponentType(
json::accessor::ComponentType::F32,
)),
Expand Down Expand Up @@ -936,9 +936,9 @@ impl Gltf {
Some(uv_set) => {
self.root.buffer_views.push(json::buffer::View {
buffer: buffer_index,
byte_length: expected_uvs_length as u32,
byte_offset: Some(offset_so_far),
byte_stride: Some(8),
byte_length: expected_uvs_length.into(),
byte_offset: Some(json::validation::USize64(offset_so_far as _)),
byte_stride: Some(json::buffer::Stride(8)),
name: Some(format!("{}_Buffer_UVs", name)),
target: Some(Valid(json::buffer::Target::ArrayBuffer)),
extensions: Default::default(),
Expand All @@ -949,8 +949,8 @@ impl Gltf {
json::Index::new(self.root.buffer_views.len() as u32 - 1);
self.root.accessors.push(json::Accessor {
buffer_view: Some(buffer_view_index),
byte_offset: Some(0),
count: uv_set.uvs.len() as u32,
byte_offset: Some(json::validation::USize64(0)),
count: uv_set.uvs.len().into(),
component_type: Valid(json::accessor::GenericComponentType(
json::accessor::ComponentType::F32,
)),
Expand All @@ -972,8 +972,8 @@ impl Gltf {
Some(triangles) => {
self.root.buffer_views.push(json::buffer::View {
buffer: buffer_index,
byte_length: expected_triangles_length as u32,
byte_offset: Some(offset_so_far),
byte_length: expected_triangles_length.into(),
byte_offset: Some(json::validation::USize64(offset_so_far as _)),
byte_stride: None, //Some(6),
name: Some(format!("{}_Buffer_Triangles", name)),
target: Some(Valid(json::buffer::Target::ElementArrayBuffer)),
Expand All @@ -984,8 +984,8 @@ impl Gltf {
json::Index::new(self.root.buffer_views.len() as u32 - 1);
self.root.accessors.push(json::Accessor {
buffer_view: Some(buffer_view_index),
byte_offset: Some(0),
count: triangles.len() as u32 * 3,
byte_offset: Some(json::validation::USize64(0)),
count: (triangles.len() * 3).into(),
component_type: Valid(json::accessor::GenericComponentType(
json::accessor::ComponentType::U16,
)),
Expand Down
2 changes: 1 addition & 1 deletion src/collectors/single_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Mesh {

impl Mesh {
pub fn add_nif(&mut self, nif: &Nif, lod_distance: f32) -> anyhow::Result<()> {
if let Some(Block::NiNode(ni_node)) = nif.blocks.get(0) {
if let Some(Block::NiNode(ni_node)) = nif.blocks.first() {
self.visit_ni_node(nif, ni_node, None, lod_distance)?;
}

Expand Down
8 changes: 4 additions & 4 deletions src/parse_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use super::blocks::{Block, *};
use super::common;
use crate::error::NifError;
use binrw::{io::Read, BinRead, BinResult};
use std::io::SeekFrom;

#[binrw::parser(reader, endian)]
pub fn parse_keys<T: BinRead>(
pub fn parse_keys<T>(
num_keys: u32,
key_type: Option<common::KeyType>,
) -> BinResult<Vec<common::Key<T>>>
where
T: BinRead,
T: for<'a> BinRead<Args<'a> = ()>,
{
if num_keys == 0 {
Expand Down Expand Up @@ -330,7 +330,7 @@ pub fn parse_blocks(strings: Vec<String>, block_type_indices: Vec<u16>) -> BinRe
),
_ => {
return Err(binrw::Error::Custom {
pos: reader.seek(SeekFrom::Current(0))?,
pos: reader.stream_position()?,
err: Box::new(NifError::UnknownBlock(blocks.len(), block_type.clone())),
});
}
Expand All @@ -339,7 +339,7 @@ pub fn parse_blocks(strings: Vec<String>, block_type_indices: Vec<u16>) -> BinRe
}
None => {
return Err(binrw::Error::Custom {
pos: reader.seek(SeekFrom::Current(0))?,
pos: reader.stream_position()?,
err: Box::new(NifError::InvalidBlockTypeIndex),
});
}
Expand Down

0 comments on commit 6798baf

Please sign in to comment.