mod3d_gltf/
types.rs

1//a Imports
2#[cfg(feature = "serde")]
3use serde::{self, Deserialize, Serialize};
4
5//a Indexable and index_type macro
6//tt Indexable
7pub trait Indexable:
8    Sized + std::ops::Deref<Target = usize> + std::ops::DerefMut + std::convert::From<usize>
9{
10    fn as_usize(&self) -> usize;
11}
12
13//mi index_type
14macro_rules! index_type {
15    ( $t:ident ) => {
16        #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
17        #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
18        #[cfg_attr(feature = "serde", serde(transparent))]
19        pub struct $t(usize);
20        impl std::ops::Deref for $t {
21            type Target = usize;
22            fn deref(&self) -> &Self::Target {
23                &self.0
24            }
25        }
26        impl std::ops::DerefMut for $t {
27            fn deref_mut(&mut self) -> &mut Self::Target {
28                &mut self.0
29            }
30        }
31        impl From<$t> for usize {
32            fn from(value: $t) -> usize {
33                value.0
34            }
35        }
36        impl From<usize> for $t {
37            fn from(value: usize) -> Self {
38                Self(value)
39            }
40        }
41        impl From<$t> for mod3d_base::ShortIndex {
42            fn from(value: $t) -> mod3d_base::ShortIndex {
43                value.0.into()
44            }
45        }
46        impl From<&$t> for mod3d_base::ShortIndex {
47            fn from(value: &$t) -> mod3d_base::ShortIndex {
48                value.0.into()
49            }
50        }
51        impl std::fmt::Display for $t {
52            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53                self.0.fmt(f)
54            }
55        }
56        impl Indexable for $t {
57            fn as_usize(&self) -> usize {
58                self.0
59            }
60        }
61    };
62}
63
64//a Index types
65index_type!(NHIndex);
66
67index_type!(MeshIndex);
68index_type!(NodeIndex);
69index_type!(CameraIndex);
70index_type!(SkinIndex);
71index_type!(SceneIndex);
72index_type!(ViewIndex);
73index_type!(BufferIndex);
74index_type!(AccessorIndex);
75index_type!(ImageIndex);
76index_type!(TextureIndex);
77index_type!(MaterialIndex);
78index_type!(SamplerIndex);
79index_type!(PrimitiveIndex);
80
81index_type!(ODBufIndex);
82index_type!(ODBufDataIndex);
83index_type!(ODBufDescIndex);
84index_type!(ODAccIndex);
85index_type!(ODVerticesIndex);
86index_type!(ODImagesIndex);
87index_type!(ODTexturesIndex);
88index_type!(ODMaterialsIndex);