Protocol

MDLComponent

The base protocol for extensible file format support in Model I/O.

Declaration

protocol MDLComponent

Overview

By extending this protocol in your own custom protocols, you can define new functionality to add to the MDLObject instances in the object graph corresponding to a MDLAsset instance.

Model I/O adopts this pattern to support container objects (with the MDLObjectContainerComponent protocol) and objects with associated transformations (with the MDLTransformComponent protocol). To work with these aspects of a Model I/O object, call the object’s componentConforming(to:) method with the appropriate protocol. (The MDLObject class also provides convenience methods and properties for accessing features of these components without directly accessing the component instances.)

To add your own object features, first define a protocol that extends the MDLComponent protocol, implement a class that adopts that protocol, and then use the setComponent(_:for:) method to add your component to each object that needs it. The example below shows how you might implement a file format that associates scripting event triggers with parts of a game scene.

@protocol MyScriptTriggerComponent <MDLComponent>
// key: trigger identifier, value: scripting-language code
@property NSDictionary<NSString *, NSString *> *scriptTriggers;
@end
 
@interface MyScriptTriggerStorage <MyScriptTriggerComponent>
@property NSDictionary<NSString *, NSString *> *scriptTriggers;
@end
 
@implementation MDLObject (MyScriptTriggers)
- (void)setScriptTriggers:(NSDictionary<NSString *, NSString *>)triggers {
    MyScriptTriggerStorage *storage = [self componentConformingToProtocol:@protocol(MyScriptTriggerComponent)];
    if (storage == nil) {
        storage = // ... allocate / manage storage ...
        [self setComponent:storage forProtocol:@protocol(MyScriptTriggerComponent)];
    }
    storage.scriptTriggers = triggers;
}
@end

See Also

Extensible Asset Format Support

class MDLObjectContainer

A default implementation for handling object hierarchy relationships in a 3D asset.

protocol MDLObjectContainerComponent

The general interface for classes that can act as containers in an object hierarchy.

protocol MDLTransformComponent

The general interface for classes that manage local coordinate space transforms for 3D objects

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software