ptex/types.rs
1use crate::sys;
2
3/// How to handle mesh border when filtering.
4pub type BorderMode = sys::BorderMode;
5
6/// Type of data stored in texture file.
7pub type DataType = sys::DataType;
8
9/// How to handle transformation across edges when filtering.
10pub type EdgeFilterMode = sys::EdgeFilterMode;
11
12/// Edge IDs used in adjacency data in the Ptex::FaceInfo struct.
13/// Edge ID usage for triangle meshes is TBD.
14pub type EdgeId = sys::EdgeId;
15
16/// Type of base mesh for which the textures are defined. A mesh
17/// can be triangle-based (with triangular textures) or quad-based
18/// (with rectangular textures). */
19pub type MeshType = sys::MeshType;
20
21/// Type of meta data entry.
22pub type MetaDataType = sys::MetaDataType;
23
24/// Pixel resolution of a given texture.
25/// The resolution is stored in log form: ulog2 = log2(ures), vlog2 = log2(vres)).
26/// Note: negative ulog2 or vlog2 values are reserved for internal use.
27#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
28pub struct Res(sys::Res);
29
30impl Res {
31 pub fn from_uv(u: i8, v: i8) -> Self {
32 Self(sys::res_from_uv(u, v))
33 }
34
35 pub fn from_value(value: u16) -> Self {
36 Self(sys::res_from_value(value))
37 }
38 /// Get value of resolution with u and v swapped.
39 pub fn clone_swapped(&self) -> Self {
40 Self(sys::res_swappeduv(&self.0))
41 }
42
43 /// Total size of specified texture in texels (u * v).
44 pub fn size(&self) -> usize {
45 self.0.size() as usize
46 }
47
48 /// U resolution in texels.
49 pub fn u(&self) -> i32 {
50 self.0.u()
51 }
52
53 /// V resolution in texels.
54 pub fn v(&self) -> i32 {
55 self.0.v()
56 }
57
58 /// Resolution as a single 16-bit integer value.
59 pub fn value(&self) -> u16 {
60 self.0.val()
61 }
62
63 /// Swap the u and v resolution values in place.
64 pub fn swap_uv(&mut self) {
65 sys::res_swapuv(&mut self.0);
66 }
67
68 /// Clamp the resolution value against the given value.
69 pub fn clamp(&mut self, res: Res) {
70 sys::res_clamp(&mut self.0, &res.0);
71 }
72
73 /// Determine the number of tiles in the u direction for the given tile res.
74 pub fn ntilesu(&self, tileres: Res) -> i32 {
75 sys::res_ntilesu(&self.0, tileres.0)
76 }
77
78 /// Determine the number of tiles in the v direction for the given tile res.
79 pub fn ntilesv(&self, tileres: Res) -> i32 {
80 sys::res_ntilesv(&self.0, tileres.0)
81 }
82
83 /// Determine the total number of tiles for the given tile res.
84 pub fn ntiles(&self, tileres: Res) -> i32 {
85 sys::res_ntiles(&self.0, tileres.0)
86 }
87}
88
89impl From<Res> for sys::Res {
90 /// Res can be used in place of a sys::Res.
91 fn from(res: Res) -> sys::Res {
92 res.0
93 }
94}
95
96/// Information about a face, as stored in the Ptex file header.
97///
98/// The FaceInfo data contains the face resolution and neighboring face
99/// adjacency information as well as a set of flags describing the face.
100///
101/// The adjfaces data member contains the face ids of the four neighboring faces.
102/// The neighbors are accessed in EdgeId order, CCW, starting with the bottom edge.
103/// The adjedges data member contains the corresponding edge id for each neighboring face.
104///
105/// If a face has no neighbor for a given edge, the adjface id should be -1, and the
106/// adjedge id doesn't matter (but is typically zero).
107///
108/// If an adjacent face is a pair of subfaces, the id of the first subface as encountered
109/// in a CCW traversal should be stored as the adjface id.
110pub type FaceInfo = sys::FaceInfo;
111
112/// Return the value of "1.0" for the specified DataType (1.0 (float), 255.0 (8bit), ...).
113pub struct OneValue;
114
115impl OneValue {
116 /// Return the value of "1.0" for the specified DataType (1.0 (float), 255.0 (8bit), ...).
117 pub fn get(data_type: crate::DataType) -> f32 {
118 sys::one_value(data_type)
119 }
120
121 /// Return the 1.0/value of "1.0" for the specified DataType (1/1.0 (float), 1/255.0 (8bit), ...).
122 pub fn get_inverse(data_type: crate::DataType) -> f32 {
123 sys::one_value_inverse(data_type)
124 }
125}
126
127/// Query the size in bytes for each DataType.
128pub struct DataSize;
129
130impl DataSize {
131 /// Return the size in bytes for the DataType.
132 pub fn get(data_type: crate::DataType) -> i32 {
133 sys::data_size(data_type)
134 }
135}