Skip to content

Commit

Permalink
Flatten and simplify curves further
Browse files Browse the repository at this point in the history
  • Loading branch information
alteous committed Dec 19, 2023
1 parent 02e394f commit 16cfd7d
Show file tree
Hide file tree
Showing 5 changed files with 743 additions and 370 deletions.
34 changes: 17 additions & 17 deletions examples/generate/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn join(a: &str, b: &str) -> String {
///
/// See [`GLTF_BINARY_ALIGNMENT`] for more information.
pub fn pad_to_align(v: &mut Vec<u8>, padding: u8) {
while v.len() as u32 % 4 != 0 {
while v.len() % 4 != 0 {
v.push(padding);
}
}
Expand Down Expand Up @@ -58,7 +58,7 @@ fn package(mut json: Vec<u8>, mut bin: Vec<u8>) -> Result<Vec<u8>> {
Ok(data)
}

const VERTEX_SIZE: u32 = 44;
const VERTEX_SIZE: usize = 44;

// 3-2
// | |
Expand Down Expand Up @@ -93,13 +93,13 @@ fn main() -> UnitResult {
let mut bin = Vec::new();

// Write vertices
let vertex_data_offset = 0;
let vertex_data_offset = 0usize;
let mut vertex_data_length = 0;
for position in QUAD_POSITIONS {
let mut bytes_written = 0u32;
let mut bytes_written = 0;
for x in position {
bin.write_f32::<LittleEndian>(*x).unwrap();
bytes_written += std::mem::size_of::<f32>() as u32;
bytes_written += std::mem::size_of::<f32>();
}
while bytes_written < VERTEX_SIZE {
bin.push(0);
Expand All @@ -109,11 +109,11 @@ fn main() -> UnitResult {
}

// Write indices
let index_data_offset = bin.len() as u32;
let index_data_offset = bin.len();
let mut index_data_length = 0;
for index in QUAD_INDICES {
bin.write_u32::<LittleEndian>(*index)?;
index_data_length += std::mem::size_of::<u32>() as u32;
index_data_length += std::mem::size_of::<u32>();
}

let mut root = gltf::json::Root {
Expand All @@ -126,7 +126,7 @@ fn main() -> UnitResult {
};

root.buffers.push(gltf::json::Buffer {
byte_length: bin.len() as u32,
byte_length: bin.len().into(),
extensions: None,
extras: Default::default(),
name: None,
Expand All @@ -139,18 +139,18 @@ fn main() -> UnitResult {
});
root.buffer_views.push(gltf::json::buffer::View {
buffer: gltf::json::Index::new(0),
byte_length: vertex_data_length,
byte_offset: Some(vertex_data_offset),
byte_stride: Some(VERTEX_SIZE),
byte_length: vertex_data_length.into(),
byte_offset: Some(vertex_data_offset.into()),
byte_stride: Some(gltf::json::buffer::Stride(VERTEX_SIZE)),
extensions: None,
extras: Default::default(),
name: Some("vertex-buffer".to_string()),
target: Some(Valid(gltf::json::buffer::Target::ArrayBuffer)),
});
root.buffer_views.push(gltf::json::buffer::View {
buffer: gltf::json::Index::new(0),
byte_length: index_data_length,
byte_offset: Some(index_data_offset),
byte_length: index_data_length.into(),
byte_offset: Some(index_data_offset.into()),
byte_stride: None,
extensions: None,
extras: Default::default(),
Expand All @@ -159,8 +159,8 @@ fn main() -> UnitResult {
});
root.accessors.push(gltf::json::Accessor {
buffer_view: Some(gltf::json::Index::new(0)),
byte_offset: 0,
count: QUAD_POSITIONS.len() as u32,
byte_offset: Some(0usize.into()),
count: QUAD_POSITIONS.len().into(),
component_type: Valid(gltf::json::accessor::GenericComponentType(
gltf::json::accessor::ComponentType::F32,
)),
Expand All @@ -175,8 +175,8 @@ fn main() -> UnitResult {
});
root.accessors.push(gltf::json::Accessor {
buffer_view: Some(gltf::json::Index::new(0)),
byte_offset: 0,
count: QUAD_INDICES.len() as u32,
byte_offset: Some(0usize.into()),
count: QUAD_INDICES.len().into(),
component_type: Valid(gltf::json::accessor::GenericComponentType(
gltf::json::accessor::ComponentType::U32,
)),
Expand Down
Loading

0 comments on commit 16cfd7d

Please sign in to comment.