MotionRes/avatarRes
directory in the SDK package after decompression. Like other animated effect materials, you need to copy them to the assets
directory of your project.
Face customization process | Photo-based face customization process |
| |
XMagicApi
, including the APIs for data loading, avatar customization, and photo-based avatar customization.getAvatarConfig
)+ (NSDictionary <NSString *, NSArray *>* _Nullable)getAvatarConfig:(NSString * _Nullable)resPath exportedAvatar:(NSString *_Nullable)exportedAvatar;
resPath
: The absolute path of avatar materials on the user's mobile device, such as /var/mobile/Containers/Data/Application/C82F1F7A-01A1-4404-8CF6-131B26B4DA1A/Library/Caches/avatarMotionRes.bundle/avatar_v2.0_male
.exportedAvatar
: The avatar configuration data (a JSON string) saved from the last time the user customized an avatar. If an avatar is customized for the first time or no configuration data is saved, pass in nil
.NSDictionary
object, in which key
is the category (for details, see the TEDefine
class below) and value
is the data of the category. After the application layer gets the dictionary data, display it on the UI as needed.loadAvatar
)- (void)loadAvatar:(NSString * _Nullable)resPath exportedAvatar:(NSString * _Nullable)exportedAvatar;
resPath
: The absolute path of avatar materials on the user's mobile device, such as /var/mobile/Containers/Data/Application/C82F1F7A-01A1-4404-8CF6-131B26B4DA1A/Library/Caches/avatarMotionRes.bundle/avatar_v2.0_male
.exportedAvatar
: The data saved after the user's last face customization, which is a JSON string. If the user uses the face customization feature for the first time or no data has been saved before, the parameter value will be nil
.NSDictionary
object, in which key
is the category (for details, see the TEDefine
class below) and value
is the data of the category. After the application layer gets the dictionary data, display it on the UI as needed.updateAvatar
)- (void)updateAvatar:(NSArray<AvatarData *> *_Nonnull)avatarDataList;
AvatarData
object corresponds to a configuration (such as changing the hairstyle). You can pass multiple AvatarData
objects to an API call to edit multiple aspects of an avatar, for example, change the hairstyle and hair color. The API will validate the AvatarData
objects passed in. If an object is valid, it will be passed to the SDK; if not, a callback will be sent.AvatarData
object is passed in to change the hairstyle, but the hair model file (specified by value
in AvatarData
) cannot be found on the local device, the AvatarData
object will be considered invalid.AvatarData
object is passed in to change the iris image, but the image file (specified by value
in AvatarData
) cannot be found on the local device, the AvatarData
object will be considered invalid.exportAvatar
)+ (NSString *_Nullable)exportAvatar:(NSArray <AvatarData *>*_Nullable)avatarDataList;
selected
or shape values in AvatarData
will change. After editing, a new AvatarData
list will be generated and can be exported as a JSON string. You can save it locally or upload it to the server.
The string is exported for the following purposes:getAllAvatarData
to update selected
and the shape values in the avatar source data.createAvatarByPhoto
)+ (void)createAvatarByPhoto:(NSString * _Nullable)photoPath avatarResPaths:(NSArray <NSString *>* _Nullable)avatarResPaths isMale:(BOOL)isMale success:(nullable void (^)(NSString *_Nullable matchedResPath, NSString *_Nullable srcData))success failure:(nullable void (^)(NSInteger code, NSString *_Nullable msg))failure;
matchedResPath
indicates the path of the matched materials and srcData
indicates the matching result (same as the return value of exportAvatar
).code
indicates the error code and msg
indicates the error message.addAvatarResource
)+ (void)addAvatarResource:(NSString * _Nullable)rootPath category:(NSString * _Nullable)category filePath:(NSString * _Nullable)filePath completion:(nullable void (^)(NSError * _Nullable error, NSArray <AvatarData *>* _Nullable avatarList))completion;
getAllAvatarData
the next time, the SDK will return the newly added data./var/mobile/Containers/Data/Application/C82F1F7A-01A1-4404-8CF6-131B26B4DA1A/Library/Caches/avatarMotionRes.bundle/avatar_v2.0_male
.error
indicates the error message, and avatarList
indicates the avatar data array obtained after parsing.sendCustomEvent
)- (void)sendCustomEvent:(NSString * _Nullable)eventKey eventValue:(NSString * _Nullable)eventValue;
AvatarCustomEventKey
of TEDefine
.@{@"enable" : @(YES)}
to a JSON string or directly enter @"{\\\\"enable\\\\" : true}"
.AvatarData
AvatarData
class is at the core of the above APIs. AvatarData
contains the following fields:/// @brief The configuration type.@interface AvatarData : NSObject// Such as face shape changing or eye adjustment. If the standard categories defined in `TEDefine` cannot meet your requirements, you can customize a category (make sure it’s not the same as an existing one). This filed cannot be empty.@property (nonatomic, copy) NSString * _Nonnull category;// The ID of an avatar configuration item. For example, each type of glasses has a unique ID. So does each adjustment item. This field cannot be empty.@property (nonatomic, copy) NSString * _Nonnull Id;// The type, which can be `selector` or `AvatarDataTypeSlider`.@property (nonatomic, assign) AvatarDataType type;/// If `type` is `selector`, this field indicates whether the item is selected.@property (nonatomic, assign) BOOL isSelected;/// The part of an avatar to be edited, for example, face, eyes, hair, shirt, or shoes. For how to configure this, refer to our documentation.@property (nonatomic, copy) NSString * _Nonnull entityName;/// The action to be performed on `entityName`. For details, see our documentation.@property (nonatomic, copy) NSString * _Nonnull action;/// The details of the action to be performed on `entityName`. For details, see our documentation.@property (nonatomic, copy) NSDictionary * _Nonnull value;@end
AvatarData
object is the smallest unit of configuration, for example, hairstyle change or cheek adjustment.Hairstyle change | Cheek adjustment |
| |
selected
in AvatarData
. For example, suppose there are four types of glasses: A, B, C, and D. If the user selects A, set selected
of A to true
and that of B, C, and D to false
. If the user selects B, set selected
of B to true
and that of A, C, and D to false
.value
in AvatarData
. The value
field is a JSON object that includes multiple key-value pairs. Set the value
of a key-value pair to the slider value.AvatarData
AvatarData
by parsing the custom_configs
directory of the material root directory and sends it to the application layer. Generally, you don't need to manually construct AvatarData
.
The three key fields of AvatarData
are entityName, action, and value, whose values are automatically entered when the SDK parses the configuration data. In most cases, you won't need to deal with the details of these three fields. However, for slider data, you need to parse the key-value pairs in the value
field and configure them based on the slider values set on the UI.entityName
entityName
specifies which part of an avatar is to be edited, for example, face, eyes, hair, shirt, or shoes.action
and value
action
field indicates the action to be performed on entityName
. Five action
options are defined in the SDK, which are detailed below:action | Description | Requirements for value |
changeColor | Changes the color of the current material. Color attributes include basic color and emission color. | This field is of JsonObject type and is required. It is generated automatically by the material customization tool. |
changeTexture | Modifies the maps of the current material, including color texture map, metal/roughness texture map, ambient occlusion (AO) map, normal map, and emission map. | This field is of JsonObject type and is required. It is generated automatically by the material customization tool. |
shapeValue | Modifies the shape change value of blendShape . This parameter is generally used for slight adjustment of detailed facial features. | This field is of JsonObject type and is required. Its key is the shape change name and value is of float type. It is generated automatically by the material customization tool. |
replace | Replaces a submodel, for example, glasses, hairstyles, or clothes. | value must be a JSON object that describes the 3D transformation information, model path, and material path of the new submodel. It is generated automatically by the material customization tool. To hide a submodel, set it to null . |
basicTransform | Adjusts the position, rotation, and scaling settings. This field is generally used to adjust the camera distance and angle so as to switch between the full and half-length views of the model. | This field is of JsonObject type and is required. It is generated automatically by the material customization tool. |
resources
folder (in material/custom_configs/resources
):
Was this page helpful?