1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
use crate::error::Result;
use crate::ffi;
use crate::handle::ObjectHandle;
use crate::material::Material;
use crate::mesh::MeshBuffer;
use crate::protocols::Named;
use crate::types::{GeometryType, IndexBitDepth};
use crate::util::{c_string, take_string};
#[derive(Debug, Clone)]
/// Wraps the corresponding Model I/O submesh counterpart.
pub struct Submesh {
handle: ObjectHandle,
}
impl Named for Submesh {
fn name(&self) -> Option<String> {
self.name()
}
fn set_name(&self, name: &str) -> Result<()> {
self.set_name(name)
}
}
impl Submesh {
/// Builds this wrapper from the retained handle of the wrapped Model I/O submesh counterpart.
pub(crate) fn from_handle(handle: ObjectHandle) -> Self {
Self { handle }
}
/// Returns the opaque pointer used to call the wrapped Model I/O submesh counterpart.
pub(crate) fn as_ptr(&self) -> *mut core::ffi::c_void {
self.handle.as_ptr()
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh counterpart.
pub fn name(&self) -> Option<String> {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
take_string(unsafe { ffi::mdl_submesh_name_string(self.handle.as_ptr()) })
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh counterpart.
pub fn set_name(&self, name: &str) -> Result<()> {
let name = c_string(name)?;
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
unsafe { ffi::mdl_submesh_set_name(self.handle.as_ptr(), name.as_ptr()) };
Ok(())
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh counterpart.
pub fn index_count(&self) -> usize {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
unsafe { ffi::mdl_submesh_index_count(self.handle.as_ptr()) as usize }
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh counterpart.
pub fn index_type(&self) -> Option<IndexBitDepth> {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
IndexBitDepth::from_raw(unsafe { ffi::mdl_submesh_index_type(self.handle.as_ptr()) })
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh counterpart.
pub fn geometry_type(&self) -> Option<GeometryType> {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
GeometryType::from_raw(unsafe { ffi::mdl_submesh_geometry_type(self.handle.as_ptr()) })
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh counterpart.
pub fn index_buffer(&self) -> Option<MeshBuffer> {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
let ptr = unsafe { ffi::mdl_submesh_index_buffer(self.handle.as_ptr()) };
// SAFETY: The unsafe operation is valid in this context.
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(MeshBuffer::from_handle)
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh counterpart.
pub fn index_buffer_as_type(&self, index_type: IndexBitDepth) -> Option<MeshBuffer> {
// SAFETY: The unsafe operation is valid in this context.
let ptr = unsafe {
ffi::mdl_submesh_index_buffer_as_type(self.handle.as_ptr(), index_type.as_raw())
};
// SAFETY: The unsafe operation is valid in this context.
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(MeshBuffer::from_handle)
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh counterpart.
pub fn material(&self) -> Option<Material> {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
let ptr = unsafe { ffi::mdl_submesh_material(self.handle.as_ptr()) };
// SAFETY: The unsafe operation is valid in this context.
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(Material::from_handle)
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh counterpart.
pub fn topology(&self) -> Option<SubmeshTopology> {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
let ptr = unsafe { ffi::mdl_submesh_topology(self.handle.as_ptr()) };
// SAFETY: The unsafe operation is valid in this context.
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(SubmeshTopology::from_handle)
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh counterpart.
pub fn set_topology(&self, topology: Option<&SubmeshTopology>) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_submesh_set_topology(
self.handle.as_ptr(),
topology.map_or(std::ptr::null_mut(), SubmeshTopology::as_ptr),
);
};
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh counterpart.
pub fn set_material(&self, material: Option<&Material>) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_submesh_set_material(
self.handle.as_ptr(),
material.map_or(std::ptr::null_mut(), Material::as_ptr),
);
};
}
}
#[derive(Debug, Clone)]
/// Wraps the corresponding Model I/O submesh topology counterpart.
pub struct SubmeshTopology {
handle: ObjectHandle,
}
impl SubmeshTopology {
/// Builds this wrapper from the retained handle of the wrapped Model I/O submesh topology counterpart.
pub(crate) fn from_handle(handle: ObjectHandle) -> Self {
Self { handle }
}
/// Returns the opaque pointer used to call the wrapped Model I/O submesh topology counterpart.
pub(crate) fn as_ptr(&self) -> *mut core::ffi::c_void {
self.handle.as_ptr()
}
/// Wraps the corresponding Model I/O initializer for the wrapped Model I/O submesh topology counterpart.
pub fn new(submesh: &Submesh) -> Result<Self> {
let mut out_topology = std::ptr::null_mut();
let mut out_error = std::ptr::null_mut();
// SAFETY: The unsafe operation is valid in this context.
let status = unsafe {
ffi::mdl_submesh_topology_new(submesh.as_ptr(), &mut out_topology, &mut out_error)
};
crate::util::status_result(status, out_error)?;
Ok(Self::from_handle(crate::util::required_handle(
out_topology,
"MDLSubmeshTopology",
)?))
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn face_topology(&self) -> Option<MeshBuffer> {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
let ptr = unsafe { ffi::mdl_submesh_topology_face_topology(self.handle.as_ptr()) };
// SAFETY: The unsafe operation is valid in this context.
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(MeshBuffer::from_handle)
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn set_face_topology(&self, buffer: Option<&MeshBuffer>) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_submesh_topology_set_face_topology(
self.handle.as_ptr(),
buffer.map_or(std::ptr::null_mut(), MeshBuffer::as_ptr),
);
};
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn face_count(&self) -> usize {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
unsafe { ffi::mdl_submesh_topology_face_count(self.handle.as_ptr()) as usize }
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn set_face_count(&self, count: usize) {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
unsafe { ffi::mdl_submesh_topology_set_face_count(self.handle.as_ptr(), count as u64) };
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn vertex_crease_indices(&self) -> Option<MeshBuffer> {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
let ptr = unsafe { ffi::mdl_submesh_topology_vertex_crease_indices(self.handle.as_ptr()) };
// SAFETY: The unsafe operation is valid in this context.
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(MeshBuffer::from_handle)
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn set_vertex_crease_indices(&self, buffer: Option<&MeshBuffer>) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_submesh_topology_set_vertex_crease_indices(
self.handle.as_ptr(),
buffer.map_or(std::ptr::null_mut(), MeshBuffer::as_ptr),
);
};
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn vertex_creases(&self) -> Option<MeshBuffer> {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
let ptr = unsafe { ffi::mdl_submesh_topology_vertex_creases(self.handle.as_ptr()) };
// SAFETY: The unsafe operation is valid in this context.
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(MeshBuffer::from_handle)
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn set_vertex_creases(&self, buffer: Option<&MeshBuffer>) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_submesh_topology_set_vertex_creases(
self.handle.as_ptr(),
buffer.map_or(std::ptr::null_mut(), MeshBuffer::as_ptr),
);
};
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn vertex_crease_count(&self) -> usize {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
unsafe { ffi::mdl_submesh_topology_vertex_crease_count(self.handle.as_ptr()) as usize }
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn set_vertex_crease_count(&self, count: usize) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_submesh_topology_set_vertex_crease_count(self.handle.as_ptr(), count as u64);
};
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn edge_crease_indices(&self) -> Option<MeshBuffer> {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
let ptr = unsafe { ffi::mdl_submesh_topology_edge_crease_indices(self.handle.as_ptr()) };
// SAFETY: The unsafe operation is valid in this context.
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(MeshBuffer::from_handle)
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn set_edge_crease_indices(&self, buffer: Option<&MeshBuffer>) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_submesh_topology_set_edge_crease_indices(
self.handle.as_ptr(),
buffer.map_or(std::ptr::null_mut(), MeshBuffer::as_ptr),
);
};
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn edge_creases(&self) -> Option<MeshBuffer> {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
let ptr = unsafe { ffi::mdl_submesh_topology_edge_creases(self.handle.as_ptr()) };
// SAFETY: The unsafe operation is valid in this context.
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(MeshBuffer::from_handle)
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn set_edge_creases(&self, buffer: Option<&MeshBuffer>) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_submesh_topology_set_edge_creases(
self.handle.as_ptr(),
buffer.map_or(std::ptr::null_mut(), MeshBuffer::as_ptr),
);
};
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn edge_crease_count(&self) -> usize {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
unsafe { ffi::mdl_submesh_topology_edge_crease_count(self.handle.as_ptr()) as usize }
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O submesh topology counterpart.
pub fn set_edge_crease_count(&self, count: usize) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_submesh_topology_set_edge_crease_count(self.handle.as_ptr(), count as u64);
};
}
}