道具切换时涉及两个过程:
1、互斥协同逻辑的穿和脱
FUEAResultModel *nowResultModel = [self.AEViewModel.avatarModel.avatar handleExcludeAndAssociateWithFileIds:@[item.fileId]];
[self.AEViewModel.avatarModel.avatar updateComponentsWithExcludeAssociateResultModel:nowResultModel assetRootPath:[FUResourceManager sharedManager].downloadRootPath];
2、更新选中状态
/// 更新 subCategoryModels 中的子 item的选中状态
/// @param subCategoryModels FUAESubCategoryModel 集合
- (void)updateSelectedItemForSubCategoryModels:(NSArray *)subCategoryModels;
所有颜色的设置统一调用下面的接口即可。比如:肤色、发色、眉毛颜色、瞳孔颜色等
/// 选中颜色模型【有历史记录】
/// @param colorItem 颜色模型
/// @param colorCategory 颜色模型所在的颜色类别模型
/// @param subCategory 颜色类别模型所在的三级菜单模型
- (void)selectedColorItem:(FUAEColorItemModel *)colorItem inColorCategory:(FUAEColorCategoryModel *)colorCategory inSubCategory:(FUAESubCategoryModel *)subCategory;
/// 颜色滑杆数值改变【滑杆滑动过程中会产生太多值,所以不做历史记录,当滑动取消滑动时建议调用上面的 selectedColorItem: 方法产生一个历史记录】
/// @param colorItem 颜色模型
/// @param colorCategory 颜色模型所在的颜色类别模型
/// @param subCategory 颜色类别模型所在的三级菜单模型
- (void)colorSliderColorValueChanged:(FUAEColorItemModel *)colorItem inColorCategory:(FUAEColorCategoryModel *)colorCategory inSubCategory:(FUAESubCategoryModel *)subCategory;
添加一个动画,添加完会自动循环播放
// animationPath 动画道具.Bundle文件的绝对路径。
// animationName 动画道具名称,这个名称可以在后面根据名称移除动画
FUAnimation *animation = [FUAnimation animationWithPath:animationPath name:animationName];
[avatar playAnimation:animation];
根据动画名称得到Avatar动画数组中对应的动画
FUAnimation *animation = [avatar animationForName:@"pose"];
移除所有的动画
[avatar removeAllAnimations];
更多动画接口详见: FUAvatar (Animation)分类头文件
// 为场景设置背景组件
// backgroundPath 背景道具.Bundle文件的绝对路径
// backgroundName 背景道具名称
FUBackground *background = [FUBackground itemWithPath:backgroundPath name:backgroundName];
scene.background = background;
scene就是当前FURenderKit正在渲染的场景可以这样获取:
[FURenderKit shareRenderKit].currentScene
// 为场景设置灯光组件
// lightPath 灯光道具.Bundle文件的绝对路径
// lightName 灯光道具名称
FULight *light = [[FULight alloc] initWithPath:lightPath name:lightName];
scene.light = selectedAvatarModel.light;
scene就是当前FURenderKit正在渲染的场景可以这样获取:
[FURenderKit shareRenderKit].currentScene
如果想出现倒影,那么一定要添加灯光才行。
想达到拉近拉远的效果,有两种方法:
1、切换机位【推荐,效果好】。近的机位那么Avatar就比较大,远的机位那么Avatar就显得比较小。所谓机位也是一种 Bundle资源。
// cameraPath 机位道具.Bundle 文件的绝对路径
// cameraName 机位道具名称,不是很重要。
FUSceneCamera *camera = [[FUSceneCamera alloc] initWithPath:cameraPath name:cameraName];
scene.sceneCamera = camera
scene就是当前FURenderKit正在渲染的场景可以这样获取:
[FURenderKit shareRenderKit].currentScene
2、给Avatar设置 position
avatar.position = FUPositionMake(x, y, z);
默认中心点在屏幕中心,
x>0 身体往屏幕右边移动
y>0 身体离开地面,y<0 身体部分隐藏在地面下
z>0 身体往屏幕外移动,z<0 身体往屏幕里移动
一般设置 z值就可以达到变大变小。
1、判断是否可以重置、撤销、重做,方便更新按钮是否可用:
------------------------ FUAvatarEditViewModel 接口 --------------------------
/// 是否可以重置
@property (nonatomic, assign) BOOL canReset;
/// 是否可以撤销
@property (nonatomic, assign) BOOL canUndo;
/// 是否可以重做
@property (nonatomic, assign) BOOL canRedo;
调用 FUAvatarEditViewModel 的这几个属性值就可以知道了。
2、执行重置、撤销、重做
------------------------ FUAvatarEditViewModel 接口 --------------------------
/// 重置到上次保存的状态
- (void)resetAvatarModel;
/// 取消上一步操作
- (void)undoAvatarModel;
/// 重做上一步操作
- (void)redoAvatarModel;