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
309
310
311
312
313
314
315
316
use std::path::Path;
use std::ptr;
use crate::error::Result;
use crate::ffi;
use crate::handle::ObjectHandle;
use crate::light::Light;
use crate::object::Object;
use crate::texture::Texture;
use crate::types::{AreaLightInfo, PhotometricLightInfo, PhysicallyPlausibleLightInfo};
use crate::util::{parse_json, path_to_c_string, required_handle};
#[derive(Debug, Clone)]
/// Wraps the corresponding Model I/O physically plausible light counterpart.
pub struct PhysicallyPlausibleLight {
handle: ObjectHandle,
}
impl PhysicallyPlausibleLight {
/// Builds this wrapper from the retained handle of the wrapped Model I/O physically plausible light counterpart.
pub(crate) fn from_handle(handle: ObjectHandle) -> Self {
Self { handle }
}
/// Wraps the corresponding Model I/O initializer for the wrapped Model I/O physically plausible light counterpart.
pub fn new() -> Result<Self> {
let mut out_light = ptr::null_mut();
let mut out_error = ptr::null_mut();
let status =
// SAFETY: Output pointers are initialized and managed; FFI function is called safely.
unsafe { ffi::mdl_physically_plausible_light_new(&mut out_light, &mut out_error) };
crate::util::status_result(status, out_error)?;
Ok(Self::from_handle(required_handle(
out_light,
"MDLPhysicallyPlausibleLight",
)?))
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O physically plausible light counterpart.
pub fn info(&self) -> Result<PhysicallyPlausibleLightInfo> {
parse_json(
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
unsafe { ffi::mdl_physically_plausible_light_info_json(self.handle.as_ptr()) },
"MDLPhysicallyPlausibleLight",
)
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O physically plausible light counterpart.
pub fn set_color_temperature(&self, temperature: f32) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_physically_plausible_light_set_color_temperature(
self.handle.as_ptr(),
temperature,
);
};
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O physically plausible light counterpart.
pub fn set_color(&self, color: [f32; 4]) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_physically_plausible_light_set_color(
self.handle.as_ptr(),
color[0],
color[1],
color[2],
color[3],
);
};
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O physically plausible light counterpart.
pub fn set_lumens(&self, lumens: f32) {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
unsafe { ffi::mdl_physically_plausible_light_set_lumens(self.handle.as_ptr(), lumens) };
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O physically plausible light counterpart.
pub fn set_inner_cone_angle(&self, angle: f32) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_physically_plausible_light_set_inner_cone_angle(self.handle.as_ptr(), angle);
};
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O physically plausible light counterpart.
pub fn set_outer_cone_angle(&self, angle: f32) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_physically_plausible_light_set_outer_cone_angle(self.handle.as_ptr(), angle);
};
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O physically plausible light counterpart.
pub fn set_attenuation_start_distance(&self, distance: f32) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_physically_plausible_light_set_attenuation_start_distance(
self.handle.as_ptr(),
distance,
);
};
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O physically plausible light counterpart.
pub fn set_attenuation_end_distance(&self, distance: f32) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_physically_plausible_light_set_attenuation_end_distance(
self.handle.as_ptr(),
distance,
);
};
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O physically plausible light counterpart.
pub fn as_light(&self) -> Light {
Light::from_handle(self.handle.clone())
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O physically plausible light counterpart.
pub fn as_object(&self) -> Object {
Object::from_handle(self.handle.clone())
}
}
#[derive(Debug, Clone)]
/// Wraps the corresponding Model I/O area light counterpart.
pub struct AreaLight {
handle: ObjectHandle,
}
impl AreaLight {
/// Builds this wrapper from the retained handle of the wrapped Model I/O area light counterpart.
pub(crate) fn from_handle(handle: ObjectHandle) -> Self {
Self { handle }
}
/// Wraps the corresponding Model I/O initializer for the wrapped Model I/O area light counterpart.
pub fn new() -> Result<Self> {
let mut out_light = ptr::null_mut();
let mut out_error = ptr::null_mut();
// SAFETY: Output pointers are initialized and managed; FFI function is called safely.
let status = unsafe { ffi::mdl_area_light_new(&mut out_light, &mut out_error) };
crate::util::status_result(status, out_error)?;
Ok(Self::from_handle(required_handle(
out_light,
"MDLAreaLight",
)?))
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O area light counterpart.
pub fn info(&self) -> Result<AreaLightInfo> {
parse_json(
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
unsafe { ffi::mdl_area_light_info_json(self.handle.as_ptr()) },
"MDLAreaLight",
)
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O area light counterpart.
pub fn set_area_radius(&self, value: f32) {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
unsafe { ffi::mdl_area_light_set_area_radius(self.handle.as_ptr(), value) };
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O area light counterpart.
pub fn set_super_elliptic_power(&self, value: [f32; 2]) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_area_light_set_super_elliptic_power(self.handle.as_ptr(), value[0], value[1]);
};
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O area light counterpart.
pub fn set_aspect(&self, value: f32) {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
unsafe { ffi::mdl_area_light_set_aspect(self.handle.as_ptr(), value) };
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O area light counterpart.
pub fn as_physically_plausible_light(&self) -> PhysicallyPlausibleLight {
PhysicallyPlausibleLight::from_handle(self.handle.clone())
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O area light counterpart.
pub fn as_light(&self) -> Light {
Light::from_handle(self.handle.clone())
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O area light counterpart.
pub fn as_object(&self) -> Object {
Object::from_handle(self.handle.clone())
}
}
#[derive(Debug, Clone)]
/// Wraps the corresponding Model I/O photometric light counterpart.
pub struct PhotometricLight {
handle: ObjectHandle,
}
impl PhotometricLight {
/// Builds this wrapper from the retained handle of the wrapped Model I/O photometric light counterpart.
pub(crate) fn from_handle(handle: ObjectHandle) -> Self {
Self { handle }
}
/// Wraps the corresponding Model I/O initializer for the wrapped Model I/O photometric light counterpart.
pub fn new() -> Result<Self> {
let mut out_light = ptr::null_mut();
let mut out_error = ptr::null_mut();
// SAFETY: Output pointers are initialized and managed; FFI function is called safely.
let status = unsafe { ffi::mdl_photometric_light_new(&mut out_light, &mut out_error) };
crate::util::status_result(status, out_error)?;
Ok(Self::from_handle(required_handle(
out_light,
"MDLPhotometricLight",
)?))
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O photometric light counterpart.
pub fn from_ies_profile(path: impl AsRef<Path>) -> Result<Self> {
let path = path_to_c_string(path.as_ref())?;
let mut out_light = ptr::null_mut();
let mut out_error = ptr::null_mut();
// SAFETY: The unsafe operation is valid in this context.
let status = unsafe {
ffi::mdl_photometric_light_new_with_ies_profile(
path.as_ptr(),
&mut out_light,
&mut out_error,
)
};
crate::util::status_result(status, out_error)?;
Ok(Self::from_handle(required_handle(
out_light,
"MDLPhotometricLight",
)?))
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O photometric light counterpart.
pub fn info(&self) -> Result<PhotometricLightInfo> {
parse_json(
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
unsafe { ffi::mdl_photometric_light_info_json(self.handle.as_ptr()) },
"MDLPhotometricLight",
)
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O photometric light counterpart.
pub fn generate_spherical_harmonics_from_light(&self, level: usize) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_photometric_light_generate_spherical_harmonics_from_light(
self.handle.as_ptr(),
level as u64,
);
};
}
/// Calls the corresponding Model I/O method on the wrapped Model I/O photometric light counterpart.
pub fn generate_cubemap_from_light(&self, texture_size: usize) {
// SAFETY: The unsafe operation is valid in this context.
unsafe {
ffi::mdl_photometric_light_generate_cubemap_from_light(
self.handle.as_ptr(),
texture_size as u64,
);
};
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O photometric light counterpart.
pub fn generate_texture(&self, texture_size: usize) -> Option<Texture> {
// SAFETY: The unsafe operation is valid in this context.
let ptr = unsafe {
ffi::mdl_photometric_light_generate_texture(self.handle.as_ptr(), texture_size as u64)
};
// SAFETY: The unsafe operation is valid in this context.
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(Texture::from_handle)
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O photometric light counterpart.
pub fn light_cube_map(&self) -> Option<Texture> {
// SAFETY: ObjectHandle wraps a valid opaque pointer from Swift; FFI function accepts it safely.
let ptr = unsafe { ffi::mdl_photometric_light_light_cube_map(self.handle.as_ptr()) };
// SAFETY: The unsafe operation is valid in this context.
unsafe { ObjectHandle::from_retained_ptr(ptr) }.map(Texture::from_handle)
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O photometric light counterpart.
pub fn as_physically_plausible_light(&self) -> PhysicallyPlausibleLight {
PhysicallyPlausibleLight::from_handle(self.handle.clone())
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O photometric light counterpart.
pub fn as_light(&self) -> Light {
Light::from_handle(self.handle.clone())
}
#[must_use]
/// Calls the corresponding Model I/O method on the wrapped Model I/O photometric light counterpart.
pub fn as_object(&self) -> Object {
Object::from_handle(self.handle.clone())
}
}