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
41unsafe impl NSCopying for MDLAsset {}
42
43unsafe impl CopyingHelper for MDLAsset {
44    type Result = Self;
45}
46
47unsafe impl NSFastEnumeration for MDLAsset {}
48
49unsafe impl NSObjectProtocol for MDLAsset {}
50
51impl MDLAsset {
52    extern_methods!(
53        /// Initialize an MDLAsset using the contents of the resource located at
54        /// the indicated URL
55        ///
56        /// Vertex layout (i.e. vertexDescriptor) will be specified by ModelIO
57        /// depending on attributes of the resource.  Buffers will be allocated
58        /// using a default NSData based allocator
59        ///
60        /// Submeshes will be converted to triangle topology.
61        #[unsafe(method(initWithURL:))]
62        #[unsafe(method_family = init)]
63        pub unsafe fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Retained<Self>;
64
65        #[cfg(all(feature = "MDLMeshBuffer", feature = "MDLVertexDescriptor"))]
66        /// Initialize an MDLAsset using the contents of the resource located at
67        /// URL, ensuring that the asset conforms to the supplied vertexDescriptor,
68        /// and buffers are allocated in the supplied allocator
69        ///
70        ///
71        /// The default behavior is to triangulate any discovered meshes and to
72        /// conform the mesh to the supplied vertexDescriptor.
73        ///
74        /// If nil is passed as the vertexDescriptor, then a vertexDescriptor
75        /// will be created according to the attributes of the resource.
76        ///
77        /// If nil is passed as the bufferAllocator, buffers will be allocated
78        /// using a default NSData based allocator.
79        ///
80        /// Submeshes will be converted to triangle topology.
81        #[unsafe(method(initWithURL:vertexDescriptor:bufferAllocator:))]
82        #[unsafe(method_family = init)]
83        pub unsafe fn initWithURL_vertexDescriptor_bufferAllocator(
84            this: Allocated<Self>,
85            url: Option<&NSURL>,
86            vertex_descriptor: Option<&MDLVertexDescriptor>,
87            buffer_allocator: Option<&ProtocolObject<dyn MDLMeshBufferAllocator>>,
88        ) -> Retained<Self>;
89
90        #[cfg(feature = "MDLMeshBuffer")]
91        /// Initialize an empty MDLAsset with a buffer allocator to be used during
92        /// other operations.
93        #[unsafe(method(initWithBufferAllocator:))]
94        #[unsafe(method_family = init)]
95        pub unsafe fn initWithBufferAllocator(
96            this: Allocated<Self>,
97            buffer_allocator: Option<&ProtocolObject<dyn MDLMeshBufferAllocator>>,
98        ) -> Retained<Self>;
99
100        /// Export an asset to the specified URL.
101        ///
102        /// Returns: YES is returned if exporting proceeded successfully,
103        #[unsafe(method(exportAssetToURL:))]
104        #[unsafe(method_family = none)]
105        pub unsafe fn exportAssetToURL(&self, url: &NSURL) -> bool;
106
107        /// Export an asset to the specified URL.
108        ///
109        /// Returns: YES is returned if exporting proceeded successfully,
110        #[unsafe(method(exportAssetToURL:error:_))]
111        #[unsafe(method_family = none)]
112        pub unsafe fn exportAssetToURL_error(&self, url: &NSURL) -> Result<(), Retained<NSError>>;
113
114        #[cfg(feature = "MDLObject")]
115        /// Return the object at the specified path, or nil if none exists there
116        #[unsafe(method(objectAtPath:))]
117        #[unsafe(method_family = none)]
118        pub unsafe fn objectAtPath(&self, path: &NSString) -> Retained<MDLObject>;
119
120        /// Indicates whether MDLAsset object can be initialized with resource
121        /// with the given extension
122        ///
123        /// Returns: YES is returned if MDLAsset is able to load and represent assets with
124        /// the given extension
125        #[unsafe(method(canImportFileExtension:))]
126        #[unsafe(method_family = none)]
127        pub unsafe fn canImportFileExtension(extension: &NSString) -> bool;
128
129        /// Indicates whether MDLAsset object can export asset to resource with
130        /// the given extension
131        ///
132        /// Returns: YES is returned if MDLAsset is able is able to export assets to
133        /// resources with the given extension
134        #[unsafe(method(canExportFileExtension:))]
135        #[unsafe(method_family = none)]
136        pub unsafe fn canExportFileExtension(extension: &NSString) -> bool;
137
138        #[cfg(feature = "MDLObject")]
139        /// Inspects an asset's hierarchy for objects of the specified class type
140        ///
141        /// Returns: returns an NSArray of all objects in the asset matching the requested class
142        ///
143        /// This can be used to get references to all MDLMesh objects, MDLLights,
144        /// etc. if objectClass is not a subclass of MDLObject, an exception will be
145        /// raised.
146        #[unsafe(method(childObjectsOfClass:))]
147        #[unsafe(method_family = none)]
148        pub unsafe fn childObjectsOfClass(
149            &self,
150            object_class: &AnyClass,
151        ) -> Retained<NSArray<MDLObject>>;
152
153        /// Iterates over all material properties on all materials. If they are string
154        /// values or NSURL values, and can be resolved as textures, then the string
155        /// and NSURL values will be replaced by MDLTextureSampler values.
156        #[unsafe(method(loadTextures))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn loadTextures(&self);
159
160        /// Inherent frame rate of an asset
161        ///
162        /// If no framerate was specified by resource or resource uncapable of
163        /// specifying framerate, this value defaults to 0
164        #[unsafe(method(frameInterval))]
165        #[unsafe(method_family = none)]
166        pub unsafe fn frameInterval(&self) -> NSTimeInterval;
167
168        /// Setter for [`frameInterval`][Self::frameInterval].
169        #[unsafe(method(setFrameInterval:))]
170        #[unsafe(method_family = none)]
171        pub unsafe fn setFrameInterval(&self, frame_interval: NSTimeInterval);
172
173        /// Start time bracket of animation data
174        ///
175        /// If no animation data was specified by resource or resource incapable
176        /// of specifying animation data, this value defaults to 0. If startTime
177        /// was set explicitly, then the value of startTime will be the lesser
178        /// of the set value and the animated values.
179        #[unsafe(method(startTime))]
180        #[unsafe(method_family = none)]
181        pub unsafe fn startTime(&self) -> NSTimeInterval;
182
183        /// Setter for [`startTime`][Self::startTime].
184        #[unsafe(method(setStartTime:))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn setStartTime(&self, start_time: NSTimeInterval);
187
188        /// End time bracket of animation data
189        ///
190        /// If no animation data was specified by resource or resource incapable
191        /// of specifying animation data, this value defaults to 0. If the
192        /// endTime was set explicitly, then the value of endTime will be the
193        /// greater of the set value and the animated values.
194        #[unsafe(method(endTime))]
195        #[unsafe(method_family = none)]
196        pub unsafe fn endTime(&self) -> NSTimeInterval;
197
198        /// Setter for [`endTime`][Self::endTime].
199        #[unsafe(method(setEndTime:))]
200        #[unsafe(method_family = none)]
201        pub unsafe fn setEndTime(&self, end_time: NSTimeInterval);
202
203        /// URL used to create the asset
204        ///
205        /// If the asset was not created with a URL, nil will be returned.
206        #[unsafe(method(URL))]
207        #[unsafe(method_family = none)]
208        pub unsafe fn URL(&self) -> Option<Retained<NSURL>>;
209
210        #[cfg(feature = "MDLAssetResolver")]
211        /// Resolver asset that helps find associated files
212        ///
213        /// The default asset resolver is the RelativeAssetResolver
214        #[unsafe(method(resolver))]
215        #[unsafe(method_family = none)]
216        pub unsafe fn resolver(&self) -> Option<Retained<ProtocolObject<dyn MDLAssetResolver>>>;
217
218        #[cfg(feature = "MDLAssetResolver")]
219        /// Setter for [`resolver`][Self::resolver].
220        #[unsafe(method(setResolver:))]
221        #[unsafe(method_family = none)]
222        pub unsafe fn setResolver(&self, resolver: Option<&ProtocolObject<dyn MDLAssetResolver>>);
223
224        #[cfg(feature = "MDLMeshBuffer")]
225        /// Allocator used to create vertex and index buffers
226        #[unsafe(method(bufferAllocator))]
227        #[unsafe(method_family = none)]
228        pub unsafe fn bufferAllocator(
229            &self,
230        ) -> Retained<ProtocolObject<dyn MDLMeshBufferAllocator>>;
231
232        #[cfg(feature = "MDLVertexDescriptor")]
233        /// Vertex descriptor set upon asset initialization
234        ///
235        /// Will be nil if there was no descriptor set
236        #[unsafe(method(vertexDescriptor))]
237        #[unsafe(method_family = none)]
238        pub unsafe fn vertexDescriptor(&self) -> Option<Retained<MDLVertexDescriptor>>;
239
240        #[cfg(feature = "MDLObject")]
241        /// Add a top level object to an asset.
242        ///
243        /// If the object was already in the asset, this has no effect.
244        #[unsafe(method(addObject:))]
245        #[unsafe(method_family = none)]
246        pub unsafe fn addObject(&self, object: &MDLObject);
247
248        #[cfg(feature = "MDLObject")]
249        /// Remove a top level object from an asset.
250        ///
251        /// If the object not in the asset, this has no effect.
252        #[unsafe(method(removeObject:))]
253        #[unsafe(method_family = none)]
254        pub unsafe fn removeObject(&self, object: &MDLObject);
255
256        /// The number of top level objects
257        #[unsafe(method(count))]
258        #[unsafe(method_family = none)]
259        pub unsafe fn count(&self) -> NSUInteger;
260
261        #[cfg(feature = "MDLObject")]
262        /// return the indexed top level object
263        #[unsafe(method(objectAtIndexedSubscript:))]
264        #[unsafe(method_family = none)]
265        pub unsafe fn objectAtIndexedSubscript(
266            &self,
267            index: NSUInteger,
268        ) -> Option<Retained<MDLObject>>;
269
270        #[cfg(feature = "MDLObject")]
271        /// return the indexed top level object
272        #[unsafe(method(objectAtIndex:))]
273        #[unsafe(method_family = none)]
274        pub unsafe fn objectAtIndex(&self, index: NSUInteger) -> Retained<MDLObject>;
275
276        #[cfg(feature = "MDLTypes")]
277        #[deprecated]
278        #[unsafe(method(masters))]
279        #[unsafe(method_family = none)]
280        pub unsafe fn masters(&self) -> Retained<ProtocolObject<dyn MDLObjectContainerComponent>>;
281
282        #[cfg(feature = "MDLTypes")]
283        /// Setter for [`masters`][Self::masters].
284        #[deprecated]
285        #[unsafe(method(setMasters:))]
286        #[unsafe(method_family = none)]
287        pub unsafe fn setMasters(&self, masters: &ProtocolObject<dyn MDLObjectContainerComponent>);
288
289        #[cfg(feature = "MDLTypes")]
290        /// Original objects that can be instanced into the asset's object hierarchy
291        ///
292        /// See: MDLObjectContainerComponent
293        #[unsafe(method(originals))]
294        #[unsafe(method_family = none)]
295        pub unsafe fn originals(&self)
296            -> Retained<ProtocolObject<dyn MDLObjectContainerComponent>>;
297
298        #[cfg(feature = "MDLTypes")]
299        /// Setter for [`originals`][Self::originals].
300        #[unsafe(method(setOriginals:))]
301        #[unsafe(method_family = none)]
302        pub unsafe fn setOriginals(
303            &self,
304            originals: &ProtocolObject<dyn MDLObjectContainerComponent>,
305        );
306
307        #[cfg(feature = "MDLTypes")]
308        /// Animations that can be bound to MDLObjects (
309        ///
310        /// See: MDLAnimationBindComponent)
311        ///
312        /// See: MDLObjectContainerComponent
313        #[unsafe(method(animations))]
314        #[unsafe(method_family = none)]
315        pub unsafe fn animations(
316            &self,
317        ) -> Retained<ProtocolObject<dyn MDLObjectContainerComponent>>;
318
319        #[cfg(feature = "MDLTypes")]
320        /// Setter for [`animations`][Self::animations].
321        #[unsafe(method(setAnimations:))]
322        #[unsafe(method_family = none)]
323        pub unsafe fn setAnimations(
324            &self,
325            animations: &ProtocolObject<dyn MDLObjectContainerComponent>,
326        );
327    );
328}
329
330/// Methods declared on superclass `NSObject`.
331impl MDLAsset {
332    extern_methods!(
333        #[unsafe(method(init))]
334        #[unsafe(method_family = init)]
335        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
336
337        #[unsafe(method(new))]
338        #[unsafe(method_family = new)]
339        pub unsafe fn new() -> Retained<Self>;
340    );
341}
342
343extern_protocol!(
344    /// [Apple's documentation](https://developer.apple.com/documentation/modelio/mdllightprobeirradiancedatasource?language=objc)
345    pub unsafe trait MDLLightProbeIrradianceDataSource: NSObjectProtocol {
346        /// Spherical harmonics level used to calculate the spherical harmonics coefficients.
347        #[optional]
348        #[unsafe(method(sphericalHarmonicsLevel))]
349        #[unsafe(method_family = none)]
350        unsafe fn sphericalHarmonicsLevel(&self) -> NSUInteger;
351
352        /// Setter for [`sphericalHarmonicsLevel`][Self::sphericalHarmonicsLevel].
353        #[optional]
354        #[unsafe(method(setSphericalHarmonicsLevel:))]
355        #[unsafe(method_family = none)]
356        unsafe fn setSphericalHarmonicsLevel(&self, spherical_harmonics_level: NSUInteger);
357    }
358);
359
360/// MDLLightBaking.
361/// Given a light probe density, method places light probes in the scene according to the
362/// passed in placement heuristic type. The higher the density, the greater the number of
363/// light probes placed in the scene.
364///
365/// Using the placement heuristic MDLProbePlacementUniformGrid places the light probes in the
366/// scene as a uniform grid. The placement heuristic MDLProbePlacementIrradianceDistribution
367/// places the light probes in areas of greatest irradiance change.
368impl MDLAsset {
369    extern_methods!(
370        #[cfg(all(feature = "MDLLight", feature = "MDLObject", feature = "MDLTypes"))]
371        #[unsafe(method(placeLightProbesWithDensity:heuristic:usingIrradianceDataSource:))]
372        #[unsafe(method_family = none)]
373        pub unsafe fn placeLightProbesWithDensity_heuristic_usingIrradianceDataSource(
374            value: c_float,
375            r#type: MDLProbePlacement,
376            data_source: &ProtocolObject<dyn MDLLightProbeIrradianceDataSource>,
377        ) -> Retained<NSArray<MDLLightProbe>>;
378    );
379}