objc2_model_io/generated/MDLAsset.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11 /// An MDLAsset represents the contents of a model file.
12 ///
13 ///
14 /// Each asset contains a collection of hierarchies of objects, where
15 /// each object in the asset is the top level of a hierarchy. Objects
16 /// include transforms, lights, cameras, and meshes.
17 ///
18 /// MDLAssets are typically instantiated from NSURLs that refer to a model resource.
19 ///
20 /// The model resource may represented timed information, for example, a series of
21 /// mesh morphs. If the asset is timed, then the framerate will be non-zero, and the
22 /// firstFrame and lastFrame properties will indicate the range for which sample
23 /// data exists. Samples before or after that range will be clamped. Some model
24 /// resource representations allow continuous sampling, others are discrete. In the
25 /// discrete case, if a requested sample time is not on a discrete boundary the
26 /// returned sample will be the sample exactly on the sample time, or if no such is
27 /// available, the immediately preceding sample. If no time is specified for a
28 /// sample, the first data will be returned.
29 ///
30 /// An asset's bounding box can be queried without traversing the hierarchy of
31 /// objects.
32 ///
33 /// Fast enumeration of an MDLAsset iterates the top level objects contained within.
34 ///
35 /// See also [Apple's documentation](https://developer.apple.com/documentation/modelio/mdlasset?language=objc)
36 #[unsafe(super(NSObject))]
37 #[derive(Debug, PartialEq, Eq, Hash)]
38 pub struct MDLAsset;
39);
40
41extern_conformance!(
42 unsafe impl NSCopying for MDLAsset {}
43);
44
45unsafe impl CopyingHelper for MDLAsset {
46 type Result = Self;
47}
48
49extern_conformance!(
50 unsafe impl NSFastEnumeration for MDLAsset {}
51);
52
53extern_conformance!(
54 unsafe impl NSObjectProtocol for MDLAsset {}
55);
56
57impl MDLAsset {
58 extern_methods!(
59 /// Initialize an MDLAsset using the contents of the resource located at
60 /// the indicated URL
61 ///
62 /// Vertex layout (i.e. vertexDescriptor) will be specified by ModelIO
63 /// depending on attributes of the resource. Buffers will be allocated
64 /// using a default NSData based allocator
65 ///
66 /// Submeshes will be converted to triangle topology.
67 #[unsafe(method(initWithURL:))]
68 #[unsafe(method_family = init)]
69 pub unsafe fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Retained<Self>;
70
71 #[cfg(all(feature = "MDLMeshBuffer", feature = "MDLVertexDescriptor"))]
72 /// Initialize an MDLAsset using the contents of the resource located at
73 /// URL, ensuring that the asset conforms to the supplied vertexDescriptor,
74 /// and buffers are allocated in the supplied allocator
75 ///
76 ///
77 /// The default behavior is to triangulate any discovered meshes and to
78 /// conform the mesh to the supplied vertexDescriptor.
79 ///
80 /// If nil is passed as the vertexDescriptor, then a vertexDescriptor
81 /// will be created according to the attributes of the resource.
82 ///
83 /// If nil is passed as the bufferAllocator, buffers will be allocated
84 /// using a default NSData based allocator.
85 ///
86 /// Submeshes will be converted to triangle topology.
87 #[unsafe(method(initWithURL:vertexDescriptor:bufferAllocator:))]
88 #[unsafe(method_family = init)]
89 pub unsafe fn initWithURL_vertexDescriptor_bufferAllocator(
90 this: Allocated<Self>,
91 url: Option<&NSURL>,
92 vertex_descriptor: Option<&MDLVertexDescriptor>,
93 buffer_allocator: Option<&ProtocolObject<dyn MDLMeshBufferAllocator>>,
94 ) -> Retained<Self>;
95
96 #[cfg(feature = "MDLMeshBuffer")]
97 /// Initialize an empty MDLAsset with a buffer allocator to be used during
98 /// other operations.
99 #[unsafe(method(initWithBufferAllocator:))]
100 #[unsafe(method_family = init)]
101 pub unsafe fn initWithBufferAllocator(
102 this: Allocated<Self>,
103 buffer_allocator: Option<&ProtocolObject<dyn MDLMeshBufferAllocator>>,
104 ) -> Retained<Self>;
105
106 #[cfg(all(feature = "MDLMeshBuffer", feature = "MDLVertexDescriptor"))]
107 /// Same as initWithURL:vertexDescriptor:bufferAllocator: except that
108 /// if preserveTopology is YES, a topology buffer might be created on the
109 /// submeshes.
110 ///
111 ///
112 /// If all faces in a submesh have the same vertex count, then the
113 /// submesh will a geometry type corresponding to that vertex count.
114 /// For example, if all faces have four vertices, then the geometry
115 /// type will be MDLGeometryTypeQuads. If faces have a varying number
116 /// of vertices, then the the submesh type will be
117 /// MDLGeometryTypeVariableTopology, and a faceTopologyBuffer will be
118 /// created.
119 #[unsafe(method(initWithURL:vertexDescriptor:bufferAllocator:preserveTopology:error:))]
120 #[unsafe(method_family = init)]
121 pub unsafe fn initWithURL_vertexDescriptor_bufferAllocator_preserveTopology_error(
122 this: Allocated<Self>,
123 url: &NSURL,
124 vertex_descriptor: Option<&MDLVertexDescriptor>,
125 buffer_allocator: Option<&ProtocolObject<dyn MDLMeshBufferAllocator>>,
126 preserve_topology: bool,
127 error: Option<&mut Option<Retained<NSError>>>,
128 ) -> Retained<Self>;
129
130 /// Export an asset to the specified URL.
131 ///
132 /// Returns: YES is returned if exporting proceeded successfully,
133 #[unsafe(method(exportAssetToURL:))]
134 #[unsafe(method_family = none)]
135 pub unsafe fn exportAssetToURL(&self, url: &NSURL) -> bool;
136
137 /// Export an asset to the specified URL.
138 ///
139 /// Returns: YES is returned if exporting proceeded successfully,
140 #[unsafe(method(exportAssetToURL:error:_))]
141 #[unsafe(method_family = none)]
142 pub unsafe fn exportAssetToURL_error(&self, url: &NSURL) -> Result<(), Retained<NSError>>;
143
144 #[cfg(feature = "MDLObject")]
145 /// Return the object at the specified path, or nil if none exists there
146 #[unsafe(method(objectAtPath:))]
147 #[unsafe(method_family = none)]
148 pub unsafe fn objectAtPath(&self, path: &NSString) -> Retained<MDLObject>;
149
150 /// Indicates whether MDLAsset object can be initialized with resource
151 /// with the given extension
152 ///
153 /// Returns: YES is returned if MDLAsset is able to load and represent assets with
154 /// the given extension
155 #[unsafe(method(canImportFileExtension:))]
156 #[unsafe(method_family = none)]
157 pub unsafe fn canImportFileExtension(extension: &NSString) -> bool;
158
159 /// Indicates whether MDLAsset object can export asset to resource with
160 /// the given extension
161 ///
162 /// Returns: YES is returned if MDLAsset is able is able to export assets to
163 /// resources with the given extension
164 #[unsafe(method(canExportFileExtension:))]
165 #[unsafe(method_family = none)]
166 pub unsafe fn canExportFileExtension(extension: &NSString) -> bool;
167
168 #[cfg(feature = "MDLObject")]
169 /// Inspects an asset's hierarchy for objects of the specified class type
170 ///
171 /// Returns: returns an NSArray of all objects in the asset matching the requested class
172 ///
173 /// This can be used to get references to all MDLMesh objects, MDLLights,
174 /// etc. if objectClass is not a subclass of MDLObject, an exception will be
175 /// raised.
176 ///
177 /// # Safety
178 ///
179 /// `object_class` probably has further requirements.
180 #[unsafe(method(childObjectsOfClass:))]
181 #[unsafe(method_family = none)]
182 pub unsafe fn childObjectsOfClass(
183 &self,
184 object_class: &AnyClass,
185 ) -> Retained<NSArray<MDLObject>>;
186
187 /// Iterates over all material properties on all materials. If they are string
188 /// values or NSURL values, and can be resolved as textures, then the string
189 /// and NSURL values will be replaced by MDLTextureSampler values.
190 #[unsafe(method(loadTextures))]
191 #[unsafe(method_family = none)]
192 pub unsafe fn loadTextures(&self);
193
194 /// Inherent frame rate of an asset
195 ///
196 /// If no framerate was specified by resource or resource uncapable of
197 /// specifying framerate, this value defaults to 0
198 #[unsafe(method(frameInterval))]
199 #[unsafe(method_family = none)]
200 pub unsafe fn frameInterval(&self) -> NSTimeInterval;
201
202 /// Setter for [`frameInterval`][Self::frameInterval].
203 #[unsafe(method(setFrameInterval:))]
204 #[unsafe(method_family = none)]
205 pub unsafe fn setFrameInterval(&self, frame_interval: NSTimeInterval);
206
207 /// Start time bracket of animation data
208 ///
209 /// If no animation data was specified by resource or resource incapable
210 /// of specifying animation data, this value defaults to 0. If startTime
211 /// was set explicitly, then the value of startTime will be the lesser
212 /// of the set value and the animated values.
213 #[unsafe(method(startTime))]
214 #[unsafe(method_family = none)]
215 pub unsafe fn startTime(&self) -> NSTimeInterval;
216
217 /// Setter for [`startTime`][Self::startTime].
218 #[unsafe(method(setStartTime:))]
219 #[unsafe(method_family = none)]
220 pub unsafe fn setStartTime(&self, start_time: NSTimeInterval);
221
222 /// End time bracket of animation data
223 ///
224 /// If no animation data was specified by resource or resource incapable
225 /// of specifying animation data, this value defaults to 0. If the
226 /// endTime was set explicitly, then the value of endTime will be the
227 /// greater of the set value and the animated values.
228 #[unsafe(method(endTime))]
229 #[unsafe(method_family = none)]
230 pub unsafe fn endTime(&self) -> NSTimeInterval;
231
232 /// Setter for [`endTime`][Self::endTime].
233 #[unsafe(method(setEndTime:))]
234 #[unsafe(method_family = none)]
235 pub unsafe fn setEndTime(&self, end_time: NSTimeInterval);
236
237 /// URL used to create the asset
238 ///
239 /// If the asset was not created with a URL, nil will be returned.
240 #[unsafe(method(URL))]
241 #[unsafe(method_family = none)]
242 pub unsafe fn URL(&self) -> Option<Retained<NSURL>>;
243
244 #[cfg(feature = "MDLAssetResolver")]
245 /// Resolver asset that helps find associated files
246 ///
247 /// The default asset resolver is the RelativeAssetResolver
248 #[unsafe(method(resolver))]
249 #[unsafe(method_family = none)]
250 pub unsafe fn resolver(&self) -> Option<Retained<ProtocolObject<dyn MDLAssetResolver>>>;
251
252 #[cfg(feature = "MDLAssetResolver")]
253 /// Setter for [`resolver`][Self::resolver].
254 #[unsafe(method(setResolver:))]
255 #[unsafe(method_family = none)]
256 pub unsafe fn setResolver(&self, resolver: Option<&ProtocolObject<dyn MDLAssetResolver>>);
257
258 #[cfg(feature = "MDLMeshBuffer")]
259 /// Allocator used to create vertex and index buffers
260 #[unsafe(method(bufferAllocator))]
261 #[unsafe(method_family = none)]
262 pub unsafe fn bufferAllocator(
263 &self,
264 ) -> Retained<ProtocolObject<dyn MDLMeshBufferAllocator>>;
265
266 #[cfg(feature = "MDLVertexDescriptor")]
267 /// Vertex descriptor set upon asset initialization
268 ///
269 /// Will be nil if there was no descriptor set
270 #[unsafe(method(vertexDescriptor))]
271 #[unsafe(method_family = none)]
272 pub unsafe fn vertexDescriptor(&self) -> Option<Retained<MDLVertexDescriptor>>;
273
274 #[cfg(feature = "MDLObject")]
275 /// Add a top level object to an asset.
276 ///
277 /// If the object was already in the asset, this has no effect.
278 #[unsafe(method(addObject:))]
279 #[unsafe(method_family = none)]
280 pub unsafe fn addObject(&self, object: &MDLObject);
281
282 #[cfg(feature = "MDLObject")]
283 /// Remove a top level object from an asset.
284 ///
285 /// If the object not in the asset, this has no effect.
286 #[unsafe(method(removeObject:))]
287 #[unsafe(method_family = none)]
288 pub unsafe fn removeObject(&self, object: &MDLObject);
289
290 /// The number of top level objects
291 #[unsafe(method(count))]
292 #[unsafe(method_family = none)]
293 pub unsafe fn count(&self) -> NSUInteger;
294
295 #[cfg(feature = "MDLObject")]
296 /// return the indexed top level object
297 #[unsafe(method(objectAtIndexedSubscript:))]
298 #[unsafe(method_family = none)]
299 pub unsafe fn objectAtIndexedSubscript(
300 &self,
301 index: NSUInteger,
302 ) -> Option<Retained<MDLObject>>;
303
304 #[cfg(feature = "MDLObject")]
305 /// return the indexed top level object
306 #[unsafe(method(objectAtIndex:))]
307 #[unsafe(method_family = none)]
308 pub unsafe fn objectAtIndex(&self, index: NSUInteger) -> Retained<MDLObject>;
309
310 #[cfg(feature = "MDLTypes")]
311 #[deprecated]
312 #[unsafe(method(masters))]
313 #[unsafe(method_family = none)]
314 pub unsafe fn masters(&self) -> Retained<ProtocolObject<dyn MDLObjectContainerComponent>>;
315
316 #[cfg(feature = "MDLTypes")]
317 /// Setter for [`masters`][Self::masters].
318 #[deprecated]
319 #[unsafe(method(setMasters:))]
320 #[unsafe(method_family = none)]
321 pub unsafe fn setMasters(&self, masters: &ProtocolObject<dyn MDLObjectContainerComponent>);
322
323 #[cfg(feature = "MDLTypes")]
324 /// Original objects that can be instanced into the asset's object hierarchy
325 ///
326 /// See: MDLObjectContainerComponent
327 #[unsafe(method(originals))]
328 #[unsafe(method_family = none)]
329 pub unsafe fn originals(&self)
330 -> Retained<ProtocolObject<dyn MDLObjectContainerComponent>>;
331
332 #[cfg(feature = "MDLTypes")]
333 /// Setter for [`originals`][Self::originals].
334 #[unsafe(method(setOriginals:))]
335 #[unsafe(method_family = none)]
336 pub unsafe fn setOriginals(
337 &self,
338 originals: &ProtocolObject<dyn MDLObjectContainerComponent>,
339 );
340
341 #[cfg(feature = "MDLTypes")]
342 /// Animations that can be bound to MDLObjects (
343 ///
344 /// See: MDLAnimationBindComponent)
345 ///
346 /// See: MDLObjectContainerComponent
347 #[unsafe(method(animations))]
348 #[unsafe(method_family = none)]
349 pub unsafe fn animations(
350 &self,
351 ) -> Retained<ProtocolObject<dyn MDLObjectContainerComponent>>;
352
353 #[cfg(feature = "MDLTypes")]
354 /// Setter for [`animations`][Self::animations].
355 #[unsafe(method(setAnimations:))]
356 #[unsafe(method_family = none)]
357 pub unsafe fn setAnimations(
358 &self,
359 animations: &ProtocolObject<dyn MDLObjectContainerComponent>,
360 );
361 );
362}
363
364/// Methods declared on superclass `NSObject`.
365impl MDLAsset {
366 extern_methods!(
367 #[unsafe(method(init))]
368 #[unsafe(method_family = init)]
369 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
370
371 #[unsafe(method(new))]
372 #[unsafe(method_family = new)]
373 pub unsafe fn new() -> Retained<Self>;
374 );
375}
376
377extern_protocol!(
378 /// [Apple's documentation](https://developer.apple.com/documentation/modelio/mdllightprobeirradiancedatasource?language=objc)
379 pub unsafe trait MDLLightProbeIrradianceDataSource: NSObjectProtocol {
380 /// Spherical harmonics level used to calculate the spherical harmonics coefficients.
381 #[optional]
382 #[unsafe(method(sphericalHarmonicsLevel))]
383 #[unsafe(method_family = none)]
384 unsafe fn sphericalHarmonicsLevel(&self) -> NSUInteger;
385
386 /// Setter for [`sphericalHarmonicsLevel`][Self::sphericalHarmonicsLevel].
387 #[optional]
388 #[unsafe(method(setSphericalHarmonicsLevel:))]
389 #[unsafe(method_family = none)]
390 unsafe fn setSphericalHarmonicsLevel(&self, spherical_harmonics_level: NSUInteger);
391 }
392);
393
394/// MDLLightBaking.
395///
396/// Given a light probe density, method places light probes in the scene according to the
397/// passed in placement heuristic type. The higher the density, the greater the number of
398/// light probes placed in the scene.
399///
400/// Using the placement heuristic MDLProbePlacementUniformGrid places the light probes in the
401/// scene as a uniform grid. The placement heuristic MDLProbePlacementIrradianceDistribution
402/// places the light probes in areas of greatest irradiance change.
403impl MDLAsset {
404 extern_methods!(
405 #[cfg(all(feature = "MDLLight", feature = "MDLObject", feature = "MDLTypes"))]
406 #[unsafe(method(placeLightProbesWithDensity:heuristic:usingIrradianceDataSource:))]
407 #[unsafe(method_family = none)]
408 pub unsafe fn placeLightProbesWithDensity_heuristic_usingIrradianceDataSource(
409 value: c_float,
410 r#type: MDLProbePlacement,
411 data_source: &ProtocolObject<dyn MDLLightProbeIrradianceDataSource>,
412 ) -> Retained<NSArray<MDLLightProbe>>;
413 );
414}