Created
April 25, 2023 17:19
-
-
Save adamchalmers/b983eff34d2578884888f58a249ddc77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From bea85b28a25dcc23711a681d8620e3d3e371eb36 Mon Sep 17 00:00:00 2001 | |
From: Adam Chalmers <[email protected]> | |
Date: Tue, 25 Apr 2023 12:17:43 -0500 | |
Subject: [PATCH] no macro | |
--- | |
src/obj.rs | 52 +++++++++++++++++++++++++--------------------------- | |
1 file changed, 25 insertions(+), 27 deletions(-) | |
diff --git a/src/obj.rs b/src/obj.rs | |
index 4ff9423..78749b1 100644 | |
--- a/src/obj.rs | |
+++ b/src/obj.rs | |
@@ -2,12 +2,10 @@ use crate::{align, make_glb, pad_to_align, Options}; | |
use anyhow::Result; | |
use serde_json::json; | |
-macro_rules! push { | |
- ($vec:expr, $item:expr) => {{ | |
- let index = $vec.len() as u32; | |
- $vec.push($item); | |
- ::gltf::json::Index::new(index) | |
- }}; | |
+fn push<T>(vec: &mut Vec<T>, item: T) -> gltf::json::Index<T> { | |
+ let index = vec.len() as u32; | |
+ vec.push(item); | |
+ gltf::json::Index::new(index) | |
} | |
const NORMAL_BIT: u32 = 1 << 0; | |
@@ -129,8 +127,8 @@ fn make_mesh( | |
}); | |
} | |
- let buffer_view_index = push!( | |
- gltf.buffer_views, | |
+ let buffer_view_index = push( | |
+ &mut gltf.buffer_views, | |
gltf::json::buffer::View { | |
buffer: buffer_index, | |
byte_length: buffer_view_size, | |
@@ -144,12 +142,12 @@ fn make_mesh( | |
name: None, | |
extensions: Default::default(), | |
extras: Default::default(), | |
- } | |
+ }, | |
); | |
let mut attribute_offset = 0; | |
- let position_accessor_index = push!( | |
- gltf.accessors, | |
+ let position_accessor_index = push( | |
+ &mut gltf.accessors, | |
gltf::json::Accessor { | |
buffer_view: Some(buffer_view_index), | |
byte_offset: attribute_offset, | |
@@ -165,14 +163,14 @@ fn make_mesh( | |
sparse: None, | |
extensions: Default::default(), | |
extras: Default::default(), | |
- } | |
+ }, | |
); | |
attributes.insert(Valid(Semantic::Positions), position_accessor_index); | |
if geometry.feature_bits & NORMAL_BIT != 0 { | |
attribute_offset += f32x3_size; | |
- let normal_accessor_index = push!( | |
- gltf.accessors, | |
+ let normal_accessor_index = push( | |
+ &mut gltf.accessors, | |
gltf::json::Accessor { | |
buffer_view: Some(buffer_view_index), | |
byte_offset: attribute_offset, | |
@@ -188,15 +186,15 @@ fn make_mesh( | |
sparse: None, | |
extensions: Default::default(), | |
extras: Default::default(), | |
- } | |
+ }, | |
); | |
attributes.insert(Valid(Semantic::Normals), normal_accessor_index); | |
} | |
if geometry.feature_bits & TEX_COORD_BIT != 0 { | |
attribute_offset += f32x3_size; | |
- let tex_coord_accessor_index = push!( | |
- gltf.accessors, | |
+ let tex_coord_accessor_index = push( | |
+ &mut gltf.accessors, | |
gltf::json::Accessor { | |
buffer_view: Some(buffer_view_index), | |
byte_offset: attribute_offset, | |
@@ -212,13 +210,13 @@ fn make_mesh( | |
sparse: None, | |
extensions: Default::default(), | |
extras: Default::default(), | |
- } | |
+ }, | |
); | |
attributes.insert(Valid(Semantic::TexCoords(0)), tex_coord_accessor_index); | |
} | |
- let mesh_index = push!( | |
- gltf.meshes, | |
+ let mesh_index = push( | |
+ &mut gltf.meshes, | |
gltf::json::Mesh { | |
extensions: Default::default(), | |
extras: Default::default(), | |
@@ -233,11 +231,11 @@ fn make_mesh( | |
mode: Valid(mode), | |
targets: None, | |
}], | |
- } | |
+ }, | |
); | |
- let node_index = push!( | |
- gltf.nodes, | |
+ let node_index = push( | |
+ &mut gltf.nodes, | |
gltf::json::Node { | |
camera: None, | |
children: None, | |
@@ -251,18 +249,18 @@ fn make_mesh( | |
translation: None, | |
skin: None, | |
weights: None, | |
- } | |
+ }, | |
); | |
if gltf.scene.is_none() { | |
- let scene_index = push!( | |
- gltf.scenes, | |
+ let scene_index = push( | |
+ &mut gltf.scenes, | |
gltf::json::Scene { | |
extensions: None, | |
extras: Default::default(), | |
name: None, | |
nodes: vec![node_index], | |
- } | |
+ }, | |
); | |
gltf.scene = Some(scene_index); | |
} else { | |
-- | |
2.39.2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment