Skip to main content

modelio/
types.rs

1use serde::Deserialize;
2
3#[derive(Debug, Clone, Copy, PartialEq, Deserialize)]
4pub struct BoundingBox {
5    pub min: [f32; 3],
6    pub max: [f32; 3],
7}
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10#[repr(i32)]
11pub enum GeometryType {
12    Points = 0,
13    Lines = 1,
14    Triangles = 2,
15    TriangleStrips = 3,
16    Quads = 4,
17    VariableTopology = 5,
18}
19
20impl GeometryType {
21    #[must_use]
22    pub const fn as_raw(self) -> i32 {
23        self as i32
24    }
25
26    #[must_use]
27    pub const fn from_raw(raw: i32) -> Option<Self> {
28        match raw {
29            0 => Some(Self::Points),
30            1 => Some(Self::Lines),
31            2 => Some(Self::Triangles),
32            3 => Some(Self::TriangleStrips),
33            4 => Some(Self::Quads),
34            5 => Some(Self::VariableTopology),
35            _ => None,
36        }
37    }
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41#[repr(u32)]
42pub enum IndexBitDepth {
43    UInt8 = 8,
44    UInt16 = 16,
45    UInt32 = 32,
46}
47
48impl IndexBitDepth {
49    #[must_use]
50    pub const fn as_raw(self) -> u32 {
51        self as u32
52    }
53
54    #[must_use]
55    pub const fn from_raw(raw: u32) -> Option<Self> {
56        match raw {
57            8 => Some(Self::UInt8),
58            16 => Some(Self::UInt16),
59            32 => Some(Self::UInt32),
60            _ => None,
61        }
62    }
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66#[repr(u32)]
67pub enum MeshBufferType {
68    Vertex = 1,
69    Index = 2,
70    Custom = 3,
71}
72
73impl MeshBufferType {
74    #[must_use]
75    pub const fn from_raw(raw: u32) -> Option<Self> {
76        match raw {
77            1 => Some(Self::Vertex),
78            2 => Some(Self::Index),
79            3 => Some(Self::Custom),
80            _ => None,
81        }
82    }
83}
84
85#[derive(Debug, Clone, Copy, PartialEq, Eq)]
86#[repr(u32)]
87pub enum MaterialSemantic {
88    BaseColor = 0,
89    Subsurface = 1,
90    Metallic = 2,
91    Specular = 3,
92    SpecularExponent = 4,
93    SpecularTint = 5,
94    Roughness = 6,
95    Anisotropic = 7,
96    AnisotropicRotation = 8,
97    Sheen = 9,
98    SheenTint = 10,
99    Clearcoat = 11,
100    ClearcoatGloss = 12,
101    Emission = 13,
102    Bump = 14,
103    Opacity = 15,
104    InterfaceIndexOfRefraction = 16,
105    MaterialIndexOfRefraction = 17,
106    ObjectSpaceNormal = 18,
107    TangentSpaceNormal = 19,
108    Displacement = 20,
109    DisplacementScale = 21,
110    AmbientOcclusion = 22,
111    AmbientOcclusionScale = 23,
112    None = 0x8000,
113    UserDefined = 0x8001,
114}
115
116impl MaterialSemantic {
117    #[must_use]
118    pub const fn from_raw(raw: u32) -> Option<Self> {
119        match raw {
120            0 => Some(Self::BaseColor),
121            1 => Some(Self::Subsurface),
122            2 => Some(Self::Metallic),
123            3 => Some(Self::Specular),
124            4 => Some(Self::SpecularExponent),
125            5 => Some(Self::SpecularTint),
126            6 => Some(Self::Roughness),
127            7 => Some(Self::Anisotropic),
128            8 => Some(Self::AnisotropicRotation),
129            9 => Some(Self::Sheen),
130            10 => Some(Self::SheenTint),
131            11 => Some(Self::Clearcoat),
132            12 => Some(Self::ClearcoatGloss),
133            13 => Some(Self::Emission),
134            14 => Some(Self::Bump),
135            15 => Some(Self::Opacity),
136            16 => Some(Self::InterfaceIndexOfRefraction),
137            17 => Some(Self::MaterialIndexOfRefraction),
138            18 => Some(Self::ObjectSpaceNormal),
139            19 => Some(Self::TangentSpaceNormal),
140            20 => Some(Self::Displacement),
141            21 => Some(Self::DisplacementScale),
142            22 => Some(Self::AmbientOcclusion),
143            23 => Some(Self::AmbientOcclusionScale),
144            0x8000 => Some(Self::None),
145            0x8001 => Some(Self::UserDefined),
146            _ => None,
147        }
148    }
149}
150
151#[derive(Debug, Clone, Copy, PartialEq, Eq)]
152#[repr(u32)]
153pub enum MaterialPropertyType {
154    None = 0,
155    String = 1,
156    Url = 2,
157    Texture = 3,
158    Color = 4,
159    Float = 5,
160    Float2 = 6,
161    Float3 = 7,
162    Float4 = 8,
163    Matrix44 = 9,
164    Buffer = 10,
165}
166
167impl MaterialPropertyType {
168    #[must_use]
169    pub const fn from_raw(raw: u32) -> Option<Self> {
170        match raw {
171            0 => Some(Self::None),
172            1 => Some(Self::String),
173            2 => Some(Self::Url),
174            3 => Some(Self::Texture),
175            4 => Some(Self::Color),
176            5 => Some(Self::Float),
177            6 => Some(Self::Float2),
178            7 => Some(Self::Float3),
179            8 => Some(Self::Float4),
180            9 => Some(Self::Matrix44),
181            10 => Some(Self::Buffer),
182            _ => None,
183        }
184    }
185}
186
187#[derive(Debug, Clone, Copy, PartialEq, Eq)]
188#[repr(u32)]
189pub enum MaterialFace {
190    Front = 0,
191    Back = 1,
192    DoubleSided = 2,
193}
194
195impl MaterialFace {
196    #[must_use]
197    pub const fn as_raw(self) -> u32 {
198        self as u32
199    }
200
201    #[must_use]
202    pub const fn from_raw(raw: u32) -> Option<Self> {
203        match raw {
204            0 => Some(Self::Front),
205            1 => Some(Self::Back),
206            2 => Some(Self::DoubleSided),
207            _ => None,
208        }
209    }
210}
211
212#[derive(Debug, Clone, Copy, PartialEq, Eq)]
213#[repr(u32)]
214pub enum LightType {
215    Unknown = 0,
216    Ambient = 1,
217    Directional = 2,
218    Spot = 3,
219    Point = 4,
220    Linear = 5,
221    DiscArea = 6,
222    RectangularArea = 7,
223    SuperElliptical = 8,
224    Photometric = 9,
225    Probe = 10,
226    Environment = 11,
227}
228
229impl LightType {
230    #[must_use]
231    pub const fn as_raw(self) -> u32 {
232        self as u32
233    }
234
235    #[must_use]
236    pub const fn from_raw(raw: u32) -> Option<Self> {
237        match raw {
238            0 => Some(Self::Unknown),
239            1 => Some(Self::Ambient),
240            2 => Some(Self::Directional),
241            3 => Some(Self::Spot),
242            4 => Some(Self::Point),
243            5 => Some(Self::Linear),
244            6 => Some(Self::DiscArea),
245            7 => Some(Self::RectangularArea),
246            8 => Some(Self::SuperElliptical),
247            9 => Some(Self::Photometric),
248            10 => Some(Self::Probe),
249            11 => Some(Self::Environment),
250            _ => None,
251        }
252    }
253}
254
255#[derive(Debug, Clone, Copy, PartialEq, Eq)]
256#[repr(u32)]
257pub enum CameraProjection {
258    Perspective = 0,
259    Orthographic = 1,
260}
261
262impl CameraProjection {
263    #[must_use]
264    pub const fn as_raw(self) -> u32 {
265        self as u32
266    }
267
268    #[must_use]
269    pub const fn from_raw(raw: u32) -> Option<Self> {
270        match raw {
271            0 => Some(Self::Perspective),
272            1 => Some(Self::Orthographic),
273            _ => None,
274        }
275    }
276}
277
278#[derive(Debug, Clone, Copy, PartialEq, Eq)]
279#[repr(u32)]
280pub enum DataPrecision {
281    Undefined = 0,
282    Float = 1,
283    Double = 2,
284}
285
286impl DataPrecision {
287    #[must_use]
288    pub const fn from_raw(raw: u32) -> Option<Self> {
289        match raw {
290            0 => Some(Self::Undefined),
291            1 => Some(Self::Float),
292            2 => Some(Self::Double),
293            _ => None,
294        }
295    }
296}
297
298#[derive(Debug, Clone, Copy, PartialEq, Eq)]
299#[repr(u32)]
300pub enum AnimatedValueInterpolation {
301    Constant = 0,
302    Linear = 1,
303}
304
305impl AnimatedValueInterpolation {
306    #[must_use]
307    pub const fn as_raw(self) -> u32 {
308        self as u32
309    }
310
311    #[must_use]
312    pub const fn from_raw(raw: u32) -> Option<Self> {
313        match raw {
314            0 => Some(Self::Constant),
315            1 => Some(Self::Linear),
316            _ => None,
317        }
318    }
319}
320
321#[derive(Debug, Clone, Copy, PartialEq, Eq)]
322#[repr(i32)]
323pub enum ObjectKind {
324    Unknown = 0,
325    Object = 1,
326    Mesh = 2,
327    Light = 3,
328    PhysicallyPlausibleLight = 4,
329    Camera = 5,
330    VoxelArray = 6,
331    Skeleton = 7,
332    PackedJointAnimation = 8,
333}
334
335impl ObjectKind {
336    #[must_use]
337    pub const fn from_raw(raw: i32) -> Option<Self> {
338        match raw {
339            0 => Some(Self::Unknown),
340            1 => Some(Self::Object),
341            2 => Some(Self::Mesh),
342            3 => Some(Self::Light),
343            4 => Some(Self::PhysicallyPlausibleLight),
344            5 => Some(Self::Camera),
345            6 => Some(Self::VoxelArray),
346            7 => Some(Self::Skeleton),
347            8 => Some(Self::PackedJointAnimation),
348            _ => None,
349        }
350    }
351}
352
353#[derive(Debug, Clone, Copy, PartialEq, Eq)]
354#[repr(i32)]
355pub enum TextureChannelEncoding {
356    UInt8 = 1,
357    UInt16 = 2,
358    UInt24 = 3,
359    UInt32 = 4,
360    Float16 = 0x102,
361    Float16Sr = 0x302,
362    Float32 = 0x104,
363}
364
365impl TextureChannelEncoding {
366    #[must_use]
367    pub const fn from_raw(raw: i32) -> Option<Self> {
368        match raw {
369            1 => Some(Self::UInt8),
370            2 => Some(Self::UInt16),
371            3 => Some(Self::UInt24),
372            4 => Some(Self::UInt32),
373            0x102 => Some(Self::Float16),
374            0x302 => Some(Self::Float16Sr),
375            0x104 => Some(Self::Float32),
376            _ => None,
377        }
378    }
379}
380
381#[derive(Debug, Clone, Deserialize)]
382pub struct MeshBufferInfo {
383    pub length: usize,
384    pub buffer_type: u32,
385}
386
387impl MeshBufferInfo {
388    #[must_use]
389    pub fn buffer_type_enum(&self) -> Option<MeshBufferType> {
390        MeshBufferType::from_raw(self.buffer_type)
391    }
392}
393
394#[derive(Debug, Clone, Deserialize)]
395pub struct VertexAttributeInfo {
396    pub stride: usize,
397    pub format: u32,
398    pub buffer_size: usize,
399}
400
401#[derive(Debug, Clone, Deserialize)]
402pub struct TextureInfo {
403    pub name: Option<String>,
404    pub dimensions: [i32; 2],
405    pub row_stride: isize,
406    pub channel_count: usize,
407    pub mip_level_count: usize,
408    pub channel_encoding: i32,
409    pub is_cube: bool,
410    pub has_alpha_values: bool,
411    pub url: Option<String>,
412}
413
414impl TextureInfo {
415    #[must_use]
416    pub fn channel_encoding_enum(&self) -> Option<TextureChannelEncoding> {
417        TextureChannelEncoding::from_raw(self.channel_encoding)
418    }
419}
420
421#[derive(Debug, Clone, Deserialize)]
422pub struct MaterialPropertyInfo {
423    pub name: String,
424    pub semantic: u32,
425    pub property_type: u32,
426    pub string_value: Option<String>,
427    pub url_value: Option<String>,
428    pub float_value: Option<f32>,
429    pub float2_value: Option<[f32; 2]>,
430    pub float3_value: Option<[f32; 3]>,
431    pub float4_value: Option<[f32; 4]>,
432    pub matrix4x4: Option<[f32; 16]>,
433    pub color: Option<[f32; 4]>,
434    pub luminance: Option<f32>,
435    pub texture: Option<TextureInfo>,
436}
437
438impl MaterialPropertyInfo {
439    #[must_use]
440    pub fn semantic_enum(&self) -> Option<MaterialSemantic> {
441        MaterialSemantic::from_raw(self.semantic)
442    }
443
444    #[must_use]
445    pub fn property_type_enum(&self) -> Option<MaterialPropertyType> {
446        MaterialPropertyType::from_raw(self.property_type)
447    }
448}
449
450#[derive(Debug, Clone, Deserialize)]
451pub struct MaterialInfo {
452    pub name: String,
453    pub count: usize,
454    pub material_face: u32,
455}
456
457impl MaterialInfo {
458    #[must_use]
459    pub fn material_face_enum(&self) -> Option<MaterialFace> {
460        MaterialFace::from_raw(self.material_face)
461    }
462}
463
464#[derive(Debug, Clone, Deserialize)]
465pub struct AssetInfo {
466    pub count: usize,
467    pub frame_interval: f64,
468    pub start_time: f64,
469    pub end_time: f64,
470    pub bounding_box: BoundingBox,
471    pub up_axis: [f32; 3],
472    pub url: Option<String>,
473}
474
475#[derive(Debug, Clone, Deserialize)]
476pub struct ObjectInfo {
477    pub kind: i32,
478    pub name: String,
479    pub path: String,
480    pub hidden: bool,
481    pub component_count: usize,
482    pub child_count: usize,
483    pub has_parent: bool,
484    pub has_instance: bool,
485    pub bounding_box: BoundingBox,
486}
487
488impl ObjectInfo {
489    #[must_use]
490    pub fn kind_enum(&self) -> Option<ObjectKind> {
491        ObjectKind::from_raw(self.kind)
492    }
493}
494
495#[derive(Debug, Clone, Deserialize)]
496pub struct LightInfo {
497    pub light_type: u32,
498    pub color_space: String,
499}
500
501impl LightInfo {
502    #[must_use]
503    pub fn light_type_enum(&self) -> Option<LightType> {
504        LightType::from_raw(self.light_type)
505    }
506}
507
508#[derive(Debug, Clone, Deserialize)]
509pub struct PhysicallyPlausibleLightInfo {
510    pub light_type: u32,
511    pub color_space: String,
512    pub color: Option<[f32; 4]>,
513    pub lumens: f32,
514    pub inner_cone_angle: f32,
515    pub outer_cone_angle: f32,
516    pub attenuation_start_distance: f32,
517    pub attenuation_end_distance: f32,
518}
519
520impl PhysicallyPlausibleLightInfo {
521    #[must_use]
522    pub fn light_type_enum(&self) -> Option<LightType> {
523        LightType::from_raw(self.light_type)
524    }
525}
526
527#[derive(Debug, Clone, Deserialize)]
528pub struct CameraInfo {
529    pub projection: u32,
530    pub projection_matrix: [f32; 16],
531    pub near_visibility_distance: f32,
532    pub far_visibility_distance: f32,
533    pub world_to_meters_conversion_scale: f32,
534    pub barrel_distortion: f32,
535    pub fisheye_distortion: f32,
536    pub optical_vignetting: f32,
537    pub chromatic_aberration: f32,
538    pub focal_length: f32,
539    pub focus_distance: f32,
540    pub field_of_view: f32,
541    pub f_stop: f32,
542    pub aperture_blade_count: usize,
543    pub maximum_circle_of_confusion: f32,
544    pub shutter_open_interval: f64,
545    pub sensor_vertical_aperture: f32,
546    pub sensor_aspect: f32,
547    pub sensor_enlargement: [f32; 2],
548    pub sensor_shift: [f32; 2],
549    pub flash: [f32; 3],
550    pub exposure_compression: [f32; 2],
551    pub exposure: [f32; 3],
552}
553
554impl CameraInfo {
555    #[must_use]
556    pub fn projection_enum(&self) -> Option<CameraProjection> {
557        CameraProjection::from_raw(self.projection)
558    }
559}
560
561#[derive(Debug, Clone, Deserialize)]
562pub struct VoxelIndexExtent {
563    pub minimum_extent: [i32; 4],
564    pub maximum_extent: [i32; 4],
565}
566
567#[derive(Debug, Clone, Deserialize)]
568pub struct VoxelArrayInfo {
569    pub count: usize,
570    pub bounding_box: BoundingBox,
571    pub voxel_index_extent: VoxelIndexExtent,
572    pub is_valid_signed_shell_field: bool,
573    pub shell_field_interior_thickness: f32,
574    pub shell_field_exterior_thickness: f32,
575}
576
577#[derive(Debug, Clone, Deserialize)]
578pub struct AnimatedValueInfo {
579    pub is_animated: bool,
580    pub precision: u32,
581    pub time_sample_count: usize,
582    pub minimum_time: f64,
583    pub maximum_time: f64,
584    pub interpolation: u32,
585    pub key_times: Vec<f64>,
586    pub element_count: Option<usize>,
587}
588
589impl AnimatedValueInfo {
590    #[must_use]
591    pub fn precision_enum(&self) -> Option<DataPrecision> {
592        DataPrecision::from_raw(self.precision)
593    }
594
595    #[must_use]
596    pub fn interpolation_enum(&self) -> Option<AnimatedValueInterpolation> {
597        AnimatedValueInterpolation::from_raw(self.interpolation)
598    }
599}
600
601#[derive(Debug, Clone, Deserialize)]
602pub struct PackedJointAnimationInfo {
603    pub name: String,
604    pub path: String,
605    pub joint_paths: Vec<String>,
606    pub joint_count: usize,
607}
608
609#[derive(Debug, Clone, Deserialize)]
610pub struct AnimationBindComponentInfo {
611    pub has_skeleton: bool,
612    pub has_joint_animation: bool,
613    pub joint_paths: Option<Vec<String>>,
614    pub geometry_bind_transform: [f32; 16],
615}
616
617#[derive(Debug, Clone, Deserialize)]
618pub struct SkeletonInfo {
619    pub name: String,
620    pub path: String,
621    pub joint_paths: Vec<String>,
622    pub joint_count: usize,
623    pub joint_bind_transform_count: usize,
624    pub joint_rest_transform_count: usize,
625}
626
627#[derive(Debug, Clone, Deserialize)]
628pub struct VertexAttributeDescriptorInfo {
629    pub name: String,
630    pub format: u32,
631    pub offset: usize,
632    pub buffer_index: usize,
633    pub time: f64,
634    pub initialization_value: [f32; 4],
635}
636
637#[derive(Debug, Clone, Deserialize)]
638pub struct VertexDescriptorInfo {
639    pub attribute_count: usize,
640    pub attributes: Vec<VertexAttributeDescriptorInfo>,
641    pub layout_strides: Vec<usize>,
642}
643
644pub mod vertex_format {
645    pub const INVALID: u32 = 0;
646    pub const PACKED_BIT: u32 = 0x1000;
647
648    pub const UCHAR_BITS: u32 = 0x10000;
649    pub const CHAR_BITS: u32 = 0x20000;
650    pub const UCHAR_NORMALIZED_BITS: u32 = 0x30000;
651    pub const CHAR_NORMALIZED_BITS: u32 = 0x40000;
652    pub const USHORT_BITS: u32 = 0x50000;
653    pub const SHORT_BITS: u32 = 0x60000;
654    pub const USHORT_NORMALIZED_BITS: u32 = 0x70000;
655    pub const SHORT_NORMALIZED_BITS: u32 = 0x80000;
656    pub const UINT_BITS: u32 = 0x90000;
657    pub const INT_BITS: u32 = 0xA0000;
658    pub const HALF_BITS: u32 = 0xB0000;
659    pub const FLOAT_BITS: u32 = 0xC0000;
660
661    pub const UCHAR: u32 = UCHAR_BITS | 1;
662    pub const UCHAR2: u32 = UCHAR_BITS | 2;
663    pub const UCHAR3: u32 = UCHAR_BITS | 3;
664    pub const UCHAR4: u32 = UCHAR_BITS | 4;
665
666    pub const CHAR: u32 = CHAR_BITS | 1;
667    pub const CHAR2: u32 = CHAR_BITS | 2;
668    pub const CHAR3: u32 = CHAR_BITS | 3;
669    pub const CHAR4: u32 = CHAR_BITS | 4;
670
671    pub const UCHAR_NORMALIZED: u32 = UCHAR_NORMALIZED_BITS | 1;
672    pub const UCHAR2_NORMALIZED: u32 = UCHAR_NORMALIZED_BITS | 2;
673    pub const UCHAR3_NORMALIZED: u32 = UCHAR_NORMALIZED_BITS | 3;
674    pub const UCHAR4_NORMALIZED: u32 = UCHAR_NORMALIZED_BITS | 4;
675
676    pub const CHAR_NORMALIZED: u32 = CHAR_NORMALIZED_BITS | 1;
677    pub const CHAR2_NORMALIZED: u32 = CHAR_NORMALIZED_BITS | 2;
678    pub const CHAR3_NORMALIZED: u32 = CHAR_NORMALIZED_BITS | 3;
679    pub const CHAR4_NORMALIZED: u32 = CHAR_NORMALIZED_BITS | 4;
680
681    pub const USHORT: u32 = USHORT_BITS | 1;
682    pub const USHORT2: u32 = USHORT_BITS | 2;
683    pub const USHORT3: u32 = USHORT_BITS | 3;
684    pub const USHORT4: u32 = USHORT_BITS | 4;
685
686    pub const SHORT: u32 = SHORT_BITS | 1;
687    pub const SHORT2: u32 = SHORT_BITS | 2;
688    pub const SHORT3: u32 = SHORT_BITS | 3;
689    pub const SHORT4: u32 = SHORT_BITS | 4;
690
691    pub const USHORT_NORMALIZED: u32 = USHORT_NORMALIZED_BITS | 1;
692    pub const USHORT2_NORMALIZED: u32 = USHORT_NORMALIZED_BITS | 2;
693    pub const USHORT3_NORMALIZED: u32 = USHORT_NORMALIZED_BITS | 3;
694    pub const USHORT4_NORMALIZED: u32 = USHORT_NORMALIZED_BITS | 4;
695
696    pub const SHORT_NORMALIZED: u32 = SHORT_NORMALIZED_BITS | 1;
697    pub const SHORT2_NORMALIZED: u32 = SHORT_NORMALIZED_BITS | 2;
698    pub const SHORT3_NORMALIZED: u32 = SHORT_NORMALIZED_BITS | 3;
699    pub const SHORT4_NORMALIZED: u32 = SHORT_NORMALIZED_BITS | 4;
700
701    pub const UINT: u32 = UINT_BITS | 1;
702    pub const UINT2: u32 = UINT_BITS | 2;
703    pub const UINT3: u32 = UINT_BITS | 3;
704    pub const UINT4: u32 = UINT_BITS | 4;
705
706    pub const INT: u32 = INT_BITS | 1;
707    pub const INT2: u32 = INT_BITS | 2;
708    pub const INT3: u32 = INT_BITS | 3;
709    pub const INT4: u32 = INT_BITS | 4;
710
711    pub const HALF: u32 = HALF_BITS | 1;
712    pub const HALF2: u32 = HALF_BITS | 2;
713    pub const HALF3: u32 = HALF_BITS | 3;
714    pub const HALF4: u32 = HALF_BITS | 4;
715
716    pub const FLOAT: u32 = FLOAT_BITS | 1;
717    pub const FLOAT2: u32 = FLOAT_BITS | 2;
718    pub const FLOAT3: u32 = FLOAT_BITS | 3;
719    pub const FLOAT4: u32 = FLOAT_BITS | 4;
720
721    pub const INT1010102_NORMALIZED: u32 = INT_BITS | PACKED_BIT | 4;
722    pub const UINT1010102_NORMALIZED: u32 = UINT_BITS | PACKED_BIT | 4;
723}