新接入FaceUnity美颜SDK
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
package com.yunbao.faceunity.data;
|
||||
|
||||
import com.faceunity.core.controller.bodyBeauty.BodyBeautyParam;
|
||||
import com.faceunity.core.entity.FUBundleData;
|
||||
import com.faceunity.core.faceunity.FURenderKit;
|
||||
import com.faceunity.core.model.bodyBeauty.BodyBeauty;
|
||||
|
||||
import com.yunbao.faceunity.entity.BodyBeautyBean;
|
||||
import com.yunbao.faceunity.entity.ModelAttributeData;
|
||||
import com.yunbao.faceunity.infe.AbstractBodyBeautyDataFactory;
|
||||
import com.yunbao.faceunity.repo.BodyBeautySource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
/**
|
||||
* DESC:美体业务工厂
|
||||
* Created on 2021/3/2
|
||||
*/
|
||||
public class BodyBeautyDataFactory extends AbstractBodyBeautyDataFactory {
|
||||
|
||||
|
||||
interface BodyBeautySetParamInterface {
|
||||
void setValue(double value);
|
||||
}
|
||||
|
||||
interface BodyBeautyGetParamInterface {
|
||||
double getValue();
|
||||
}
|
||||
|
||||
|
||||
/*渲染控制器*/
|
||||
private final FURenderKit mFURenderKit = FURenderKit.getInstance();
|
||||
|
||||
/*美体数据模型*/
|
||||
public final BodyBeauty bodyBeauty;
|
||||
|
||||
public BodyBeautyDataFactory() {
|
||||
bodyBeauty = new BodyBeauty(new FUBundleData(BodyBeautySource.BUNDLE_BODY_BEAUTY));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取美体属性列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ArrayList<BodyBeautyBean> getBodyBeautyParam() {
|
||||
return BodyBeautySource.buildBodyBeauty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取美体扩展参数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public HashMap<String, ModelAttributeData> getModelAttributeRange() {
|
||||
return BodyBeautySource.buildModelAttributeRange();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取模型参数
|
||||
*
|
||||
* @param key 名称标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public double getParamIntensity(String key) {
|
||||
if (bodyBeautyGetMapping.containsKey(key)) {
|
||||
return bodyBeautyGetMapping.get(key).getValue();
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置属性参数
|
||||
*
|
||||
* @param key 名称标识
|
||||
* @param value 结果值
|
||||
*/
|
||||
@Override
|
||||
public void updateParamIntensity(String key, double value) {
|
||||
if (bodyBeautySetMapping.containsKey(key)) {
|
||||
bodyBeautySetMapping.get(key).setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前模型
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private BodyBeauty getCurrentBodyBeautyModel() {
|
||||
return bodyBeauty;
|
||||
}
|
||||
|
||||
/**
|
||||
* 美体开关设置
|
||||
*
|
||||
* @param enable
|
||||
*/
|
||||
@Override
|
||||
public void enableBodyBeauty(boolean enable) {
|
||||
if (mFURenderKit.getBodyBeauty() != null) {
|
||||
mFURenderKit.getBodyBeauty().setEnable(enable);
|
||||
}
|
||||
}
|
||||
|
||||
/*模型映射设置模型值*/
|
||||
private final HashMap<String, BodyBeautySetParamInterface> bodyBeautySetMapping = new HashMap<String, BodyBeautySetParamInterface>() {
|
||||
{
|
||||
put(BodyBeautyParam.BODY_SLIM_INTENSITY, value -> getCurrentBodyBeautyModel().setBodySlimIntensity(value));
|
||||
put(BodyBeautyParam.LEG_STRETCH_INTENSITY, value -> getCurrentBodyBeautyModel().setLegStretchIntensity(value));
|
||||
put(BodyBeautyParam.WAIST_SLIM_INTENSITY, value -> getCurrentBodyBeautyModel().setWaistSlimIntensity(value));
|
||||
put(BodyBeautyParam.SHOULDER_SLIM_INTENSITY, value -> getCurrentBodyBeautyModel().setShoulderSlimIntensity(value));
|
||||
put(BodyBeautyParam.HIP_SLIM_INTENSITY, value -> getCurrentBodyBeautyModel().setHipSlimIntensity(value));
|
||||
put(BodyBeautyParam.HEAD_SLIM_INTENSITY, value -> getCurrentBodyBeautyModel().setHeadSlimIntensity(value));
|
||||
put(BodyBeautyParam.LEG_SLIM_INTENSITY, value -> getCurrentBodyBeautyModel().setLegSlimIntensity(value));
|
||||
}
|
||||
};
|
||||
|
||||
/*模型映射获取模型值*/
|
||||
HashMap<String, BodyBeautyGetParamInterface> bodyBeautyGetMapping = new HashMap<String, BodyBeautyGetParamInterface>() {
|
||||
{
|
||||
put(BodyBeautyParam.BODY_SLIM_INTENSITY, () -> getCurrentBodyBeautyModel().getBodySlimIntensity());
|
||||
put(BodyBeautyParam.LEG_STRETCH_INTENSITY, () -> getCurrentBodyBeautyModel().getLegStretchIntensity());
|
||||
put(BodyBeautyParam.WAIST_SLIM_INTENSITY, () -> getCurrentBodyBeautyModel().getWaistSlimIntensity());
|
||||
put(BodyBeautyParam.SHOULDER_SLIM_INTENSITY, () -> getCurrentBodyBeautyModel().getShoulderSlimIntensity());
|
||||
put(BodyBeautyParam.HIP_SLIM_INTENSITY, () -> getCurrentBodyBeautyModel().getHipSlimIntensity());
|
||||
put(BodyBeautyParam.HEAD_SLIM_INTENSITY, () -> getCurrentBodyBeautyModel().getHeadSlimIntensity());
|
||||
put(BodyBeautyParam.LEG_SLIM_INTENSITY, () -> getCurrentBodyBeautyModel().getLegSlimIntensity());
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* FURenderKit加载当前特效
|
||||
*/
|
||||
public void bindCurrentRenderer() {
|
||||
mFURenderKit.setBodyBeauty(bodyBeauty);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
package com.yunbao.faceunity.data;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.faceunity.core.controller.facebeauty.FaceBeautyParam;
|
||||
import com.faceunity.core.faceunity.FURenderKit;
|
||||
import com.faceunity.core.model.facebeauty.FaceBeauty;
|
||||
import com.yunbao.faceunity.entity.FaceBeautyBean;
|
||||
import com.yunbao.faceunity.entity.FaceBeautyFilterBean;
|
||||
import com.yunbao.faceunity.entity.ModelAttributeData;
|
||||
import com.yunbao.faceunity.infe.AbstractFaceBeautyDataFactory;
|
||||
import com.yunbao.faceunity.repo.FaceBeautySource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
/**
|
||||
* DESC:美颜业务工厂
|
||||
* Created on 2021/3/1
|
||||
*/
|
||||
public class FaceBeautyDataFactory extends AbstractFaceBeautyDataFactory {
|
||||
|
||||
|
||||
interface FaceBeautySetParamInterface {
|
||||
/**
|
||||
* 设置属性值
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
void setValue(double value);
|
||||
}
|
||||
|
||||
interface FaceBeautyGetParamInterface {
|
||||
/**
|
||||
* 获取属性值
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
double getValue();
|
||||
}
|
||||
|
||||
/*渲染控制器*/
|
||||
private FURenderKit mFURenderKit = FURenderKit.getInstance();
|
||||
|
||||
/*当前生效美颜数据模型*/
|
||||
public FaceBeauty defaultFaceBeauty = FaceBeautySource.getDefaultFaceBeauty();
|
||||
|
||||
/*默认滤镜选中下标*/
|
||||
private int currentFilterIndex = 0;
|
||||
|
||||
/**
|
||||
* 获取美肤参数列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayList<FaceBeautyBean> getSkinBeauty() {
|
||||
return FaceBeautySource.buildSkinParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取美型参数列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayList<FaceBeautyBean> getShapeBeauty() {
|
||||
return FaceBeautySource.buildShapeParams();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取美肤、美型扩展参数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public HashMap<String, ModelAttributeData> getModelAttributeRange() {
|
||||
return FaceBeautySource.buildModelAttributeRange();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取滤镜参数列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public ArrayList<FaceBeautyFilterBean> getBeautyFilters() {
|
||||
ArrayList<FaceBeautyFilterBean> filterBeans = FaceBeautySource.buildFilters();
|
||||
for (int i = 0; i < filterBeans.size(); i++) {
|
||||
if (filterBeans.get(i).getKey().equals(defaultFaceBeauty.getFilterName())) {
|
||||
filterBeans.get(i).setIntensity(defaultFaceBeauty.getFilterIntensity());
|
||||
currentFilterIndex = i;
|
||||
}
|
||||
|
||||
}
|
||||
return filterBeans;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前滤镜下标
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getCurrentFilterIndex() {
|
||||
return currentFilterIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前滤镜下标
|
||||
*
|
||||
* @param currentFilterIndex
|
||||
*/
|
||||
@Override
|
||||
public void setCurrentFilterIndex(int currentFilterIndex) {
|
||||
this.currentFilterIndex = currentFilterIndex;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 美颜开关设置
|
||||
*
|
||||
* @param enable
|
||||
*/
|
||||
@Override
|
||||
public void enableFaceBeauty(boolean enable) {
|
||||
if (mFURenderKit.getFaceBeauty() != null) {
|
||||
mFURenderKit.getFaceBeauty().setEnable(enable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模型参数
|
||||
*
|
||||
* @param key 名称标识
|
||||
* @return 属性值
|
||||
*/
|
||||
@Override
|
||||
public double getParamIntensity(@NonNull String key) {
|
||||
if (faceBeautyGetMapping.containsKey(key)) {
|
||||
return faceBeautyGetMapping.get(key).getValue();
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置模型参数
|
||||
*
|
||||
* @param key 名称标识
|
||||
* @param value 属性值
|
||||
*/
|
||||
@Override
|
||||
public void updateParamIntensity(@NonNull String key, double value) {
|
||||
if (faceBeautySetMapping.containsKey(key)) {
|
||||
faceBeautySetMapping.get(key).setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换滤镜
|
||||
*
|
||||
* @param name 滤镜名称标识
|
||||
* @param intensity 滤镜强度
|
||||
* @param resID 滤镜名称
|
||||
*/
|
||||
@Override
|
||||
public void onFilterSelected(@NonNull String name, double intensity, int resID) {
|
||||
defaultFaceBeauty.setFilterName(name);
|
||||
defaultFaceBeauty.setFilterIntensity(intensity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更换滤镜强度
|
||||
*
|
||||
* @param intensity 滤镜强度
|
||||
*/
|
||||
@Override
|
||||
public void updateFilterIntensity(double intensity) {
|
||||
defaultFaceBeauty.setFilterIntensity(intensity);
|
||||
}
|
||||
|
||||
|
||||
/*模型映射设置模型值*/
|
||||
private final HashMap<String, FaceBeautySetParamInterface> faceBeautySetMapping = new HashMap<String, FaceBeautySetParamInterface>() {{
|
||||
put(FaceBeautyParam.COLOR_INTENSITY, defaultFaceBeauty::setColorIntensity);
|
||||
put(FaceBeautyParam.BLUR_INTENSITY, defaultFaceBeauty::setBlurIntensity);
|
||||
put(FaceBeautyParam.RED_INTENSITY, defaultFaceBeauty::setRedIntensity);
|
||||
put(FaceBeautyParam.SHARPEN_INTENSITY, defaultFaceBeauty::setSharpenIntensity);
|
||||
put(FaceBeautyParam.EYE_BRIGHT_INTENSITY, defaultFaceBeauty::setEyeBrightIntensity);
|
||||
put(FaceBeautyParam.TOOTH_WHITEN_INTENSITY, defaultFaceBeauty::setToothIntensity);
|
||||
put(FaceBeautyParam.REMOVE_POUCH_INTENSITY, defaultFaceBeauty::setRemovePouchIntensity);
|
||||
put(FaceBeautyParam.REMOVE_NASOLABIAL_FOLDS_INTENSITY, defaultFaceBeauty::setRemoveLawPatternIntensity);
|
||||
/*美型*/
|
||||
put(FaceBeautyParam.FACE_SHAPE_INTENSITY, defaultFaceBeauty::setSharpenIntensity);
|
||||
put(FaceBeautyParam.CHEEK_THINNING_INTENSITY, defaultFaceBeauty::setCheekThinningIntensity);
|
||||
put(FaceBeautyParam.CHEEK_V_INTENSITY, defaultFaceBeauty::setCheekVIntensity);
|
||||
put(FaceBeautyParam.CHEEK_NARROW_INTENSITY_V2, defaultFaceBeauty::setCheekNarrowIntensityV2);
|
||||
put(FaceBeautyParam.CHEEK_SHORT_INTENSITY, defaultFaceBeauty::setCheekShortIntensity);
|
||||
put(FaceBeautyParam.CHEEK_SMALL_INTENSITY_V2, defaultFaceBeauty::setCheekSmallIntensityV2);
|
||||
put(FaceBeautyParam.INTENSITY_CHEEKBONES_INTENSITY, defaultFaceBeauty::setCheekBonesIntensity);
|
||||
put(FaceBeautyParam.INTENSITY_LOW_JAW_INTENSITY, defaultFaceBeauty::setLowerJawIntensity);
|
||||
put(FaceBeautyParam.EYE_ENLARGING_INTENSITY_V2, defaultFaceBeauty::setEyeEnlargingIntensityV2);
|
||||
put(FaceBeautyParam.EYE_CIRCLE_INTENSITY, defaultFaceBeauty::setEyeCircleIntensity);
|
||||
put(FaceBeautyParam.CHIN_INTENSITY, defaultFaceBeauty::setChinIntensity);
|
||||
put(FaceBeautyParam.FOREHEAD_INTENSITY_V2, defaultFaceBeauty::setForHeadIntensityV2);
|
||||
put(FaceBeautyParam.NOSE_INTENSITY_V2, defaultFaceBeauty::setNoseIntensityV2);
|
||||
put(FaceBeautyParam.MOUTH_INTENSITY_V2, defaultFaceBeauty::setMouthIntensityV2);
|
||||
put(FaceBeautyParam.CANTHUS_INTENSITY, defaultFaceBeauty::setCanthusIntensity);
|
||||
put(FaceBeautyParam.EYE_SPACE_INTENSITY, defaultFaceBeauty::setEyeSpaceIntensity);
|
||||
put(FaceBeautyParam.EYE_ROTATE_INTENSITY, defaultFaceBeauty::setEyeRotateIntensity);
|
||||
put(FaceBeautyParam.LONG_NOSE_INTENSITY, defaultFaceBeauty::setLongNoseIntensity);
|
||||
put(FaceBeautyParam.PHILTRUM_INTENSITY, defaultFaceBeauty::setPhiltrumIntensity);
|
||||
put(FaceBeautyParam.SMILE_INTENSITY, defaultFaceBeauty::setSmileIntensity);
|
||||
}};
|
||||
|
||||
/*模型映射获取模型值*/
|
||||
HashMap<String, FaceBeautyGetParamInterface> faceBeautyGetMapping = new HashMap<String, FaceBeautyGetParamInterface>() {
|
||||
{
|
||||
put(FaceBeautyParam.COLOR_INTENSITY, defaultFaceBeauty::getColorIntensity);
|
||||
put(FaceBeautyParam.BLUR_INTENSITY, defaultFaceBeauty::getBlurIntensity);
|
||||
put(FaceBeautyParam.RED_INTENSITY, defaultFaceBeauty::getRedIntensity);
|
||||
put(FaceBeautyParam.SHARPEN_INTENSITY, defaultFaceBeauty::getSharpenIntensity);
|
||||
put(FaceBeautyParam.EYE_BRIGHT_INTENSITY, defaultFaceBeauty::getEyeBrightIntensity);
|
||||
put(FaceBeautyParam.TOOTH_WHITEN_INTENSITY, defaultFaceBeauty::getToothIntensity);
|
||||
put(FaceBeautyParam.REMOVE_POUCH_INTENSITY, defaultFaceBeauty::getRemovePouchIntensity);
|
||||
put(FaceBeautyParam.REMOVE_NASOLABIAL_FOLDS_INTENSITY, defaultFaceBeauty::getRemoveLawPatternIntensity);
|
||||
/*美型*/
|
||||
put(FaceBeautyParam.FACE_SHAPE_INTENSITY, defaultFaceBeauty::getSharpenIntensity);
|
||||
put(FaceBeautyParam.CHEEK_THINNING_INTENSITY, defaultFaceBeauty::getCheekThinningIntensity);
|
||||
put(FaceBeautyParam.CHEEK_V_INTENSITY, defaultFaceBeauty::getCheekVIntensity);
|
||||
put(FaceBeautyParam.CHEEK_NARROW_INTENSITY_V2, defaultFaceBeauty::getCheekNarrowIntensityV2);
|
||||
put(FaceBeautyParam.CHEEK_SHORT_INTENSITY, defaultFaceBeauty::getCheekShortIntensity);
|
||||
put(FaceBeautyParam.CHEEK_SMALL_INTENSITY_V2, defaultFaceBeauty::getCheekSmallIntensityV2);
|
||||
put(FaceBeautyParam.INTENSITY_CHEEKBONES_INTENSITY, defaultFaceBeauty::getCheekBonesIntensity);
|
||||
put(FaceBeautyParam.INTENSITY_LOW_JAW_INTENSITY, defaultFaceBeauty::getLowerJawIntensity);
|
||||
put(FaceBeautyParam.EYE_ENLARGING_INTENSITY_V2, defaultFaceBeauty::getEyeEnlargingIntensityV2);
|
||||
put(FaceBeautyParam.EYE_CIRCLE_INTENSITY, defaultFaceBeauty::getEyeCircleIntensity);
|
||||
put(FaceBeautyParam.CHIN_INTENSITY, defaultFaceBeauty::getChinIntensity);
|
||||
put(FaceBeautyParam.FOREHEAD_INTENSITY_V2, defaultFaceBeauty::getForHeadIntensityV2);
|
||||
put(FaceBeautyParam.NOSE_INTENSITY_V2, defaultFaceBeauty::getNoseIntensityV2);
|
||||
put(FaceBeautyParam.MOUTH_INTENSITY_V2, defaultFaceBeauty::getMouthIntensityV2);
|
||||
put(FaceBeautyParam.CANTHUS_INTENSITY, defaultFaceBeauty::getCanthusIntensity);
|
||||
put(FaceBeautyParam.EYE_SPACE_INTENSITY, defaultFaceBeauty::getEyeSpaceIntensity);
|
||||
put(FaceBeautyParam.EYE_ROTATE_INTENSITY, defaultFaceBeauty::getEyeRotateIntensity);
|
||||
put(FaceBeautyParam.LONG_NOSE_INTENSITY, defaultFaceBeauty::getLongNoseIntensity);
|
||||
put(FaceBeautyParam.PHILTRUM_INTENSITY, defaultFaceBeauty::getPhiltrumIntensity);
|
||||
put(FaceBeautyParam.SMILE_INTENSITY, defaultFaceBeauty::getSmileIntensity);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* FURenderKit加载当前特效
|
||||
*/
|
||||
public void bindCurrentRenderer() {
|
||||
mFURenderKit.setFaceBeauty(defaultFaceBeauty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.yunbao.faceunity.data;
|
||||
|
||||
import com.faceunity.core.enumeration.FUAIProcessorEnum;
|
||||
import com.faceunity.core.faceunity.FURenderKit;
|
||||
import com.yunbao.faceunity.utils.FURenderer;
|
||||
|
||||
/**
|
||||
* DESC:
|
||||
* Created on 2021/4/25
|
||||
*/
|
||||
public class FaceUnityDataFactory {
|
||||
|
||||
/**
|
||||
* 道具数据工厂
|
||||
*/
|
||||
public FaceBeautyDataFactory mFaceBeautyDataFactory;
|
||||
public BodyBeautyDataFactory mBodyBeautyDataFactory;
|
||||
public MakeupDataFactory mMakeupDataFactory;
|
||||
public PropDataFactory mPropDataFactory;
|
||||
|
||||
|
||||
private FURenderKit mFURenderKit = FURenderKit.getInstance();
|
||||
private FURenderer mFURenderer = FURenderer.getInstance();
|
||||
|
||||
private static FaceUnityDataFactory sInstance;
|
||||
public static FaceUnityDataFactory getInstance() {
|
||||
if (sInstance == null) {
|
||||
synchronized (FaceUnityDataFactory.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new FaceUnityDataFactory(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public static void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 道具加载标识
|
||||
*/
|
||||
public int currentFunctionIndex;
|
||||
private boolean hasFaceBeautyLoaded = false;
|
||||
private boolean hasBodyBeautyLoaded = false;
|
||||
private boolean hasMakeupLoaded = false;
|
||||
private boolean hasPropLoaded = false;
|
||||
|
||||
|
||||
public FaceUnityDataFactory(int index) {
|
||||
currentFunctionIndex = index;
|
||||
mFaceBeautyDataFactory = new FaceBeautyDataFactory();
|
||||
mBodyBeautyDataFactory = new BodyBeautyDataFactory();
|
||||
mMakeupDataFactory = new MakeupDataFactory(0);
|
||||
mPropDataFactory = new PropDataFactory(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* FURenderKit加载当前特效
|
||||
*/
|
||||
public void bindCurrentRenderer() {
|
||||
switch (currentFunctionIndex) {
|
||||
case 0:
|
||||
mFaceBeautyDataFactory.bindCurrentRenderer();
|
||||
hasFaceBeautyLoaded = true;
|
||||
break;
|
||||
case 1:
|
||||
mPropDataFactory.bindCurrentRenderer();
|
||||
hasPropLoaded = true;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
mMakeupDataFactory.bindCurrentRenderer();
|
||||
hasMakeupLoaded = true;
|
||||
break;
|
||||
case 3:
|
||||
mBodyBeautyDataFactory.bindCurrentRenderer();
|
||||
hasBodyBeautyLoaded = true;
|
||||
break;
|
||||
}
|
||||
if (hasFaceBeautyLoaded && currentFunctionIndex != 0) {
|
||||
mFaceBeautyDataFactory.bindCurrentRenderer();
|
||||
}
|
||||
if (hasPropLoaded && currentFunctionIndex != 1) {
|
||||
mPropDataFactory.bindCurrentRenderer();
|
||||
}
|
||||
if (hasMakeupLoaded && currentFunctionIndex != 2) {
|
||||
mMakeupDataFactory.bindCurrentRenderer();
|
||||
}
|
||||
if (hasBodyBeautyLoaded && currentFunctionIndex != 3) {
|
||||
mBodyBeautyDataFactory.bindCurrentRenderer();
|
||||
}
|
||||
if (currentFunctionIndex == 3) {
|
||||
mFURenderKit.getFUAIController().setMaxFaces(1);
|
||||
mFURenderer.setAIProcessTrackType(FUAIProcessorEnum.HUMAN_PROCESSOR);
|
||||
} else {
|
||||
mFURenderKit.getFUAIController().setMaxFaces(4);
|
||||
mFURenderer.setAIProcessTrackType(FUAIProcessorEnum.FACE_PROCESSOR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 道具功能切换
|
||||
*/
|
||||
public void onFunctionSelected(int index) {
|
||||
currentFunctionIndex = index;
|
||||
switch (index) {
|
||||
case 0:
|
||||
if (!hasFaceBeautyLoaded) {
|
||||
mFaceBeautyDataFactory.bindCurrentRenderer();
|
||||
hasFaceBeautyLoaded = true;
|
||||
}
|
||||
mFURenderKit.getFUAIController().setMaxFaces(4);
|
||||
mFURenderer.setAIProcessTrackType(FUAIProcessorEnum.FACE_PROCESSOR);
|
||||
break;
|
||||
case 1:
|
||||
if (!hasPropLoaded) {
|
||||
mPropDataFactory.bindCurrentRenderer();
|
||||
hasPropLoaded = true;
|
||||
}
|
||||
mFURenderKit.getFUAIController().setMaxFaces(4);
|
||||
mFURenderer.setAIProcessTrackType(FUAIProcessorEnum.FACE_PROCESSOR);
|
||||
break;
|
||||
case 2:
|
||||
if (!hasMakeupLoaded) {
|
||||
mMakeupDataFactory.bindCurrentRenderer();
|
||||
hasMakeupLoaded = true;
|
||||
}
|
||||
mFURenderKit.getFUAIController().setMaxFaces(4);
|
||||
mFURenderer.setAIProcessTrackType(FUAIProcessorEnum.FACE_PROCESSOR);
|
||||
break;
|
||||
case 3:
|
||||
if (!hasBodyBeautyLoaded) {
|
||||
mBodyBeautyDataFactory.bindCurrentRenderer();
|
||||
hasBodyBeautyLoaded = true;
|
||||
}
|
||||
mFURenderKit.getFUAIController().setMaxFaces(1);
|
||||
mFURenderer.setAIProcessTrackType(FUAIProcessorEnum.HUMAN_PROCESSOR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.yunbao.faceunity.data;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.faceunity.core.entity.FUBundleData;
|
||||
import com.faceunity.core.faceunity.FURenderKit;
|
||||
import com.faceunity.core.model.makeup.SimpleMakeup;
|
||||
|
||||
import com.yunbao.faceunity.entity.MakeupCombinationBean;
|
||||
import com.yunbao.faceunity.infe.AbstractMakeupDataFactory;
|
||||
import com.yunbao.faceunity.repo.MakeupSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* DESC:美妆业务工厂
|
||||
* Created on 2021/3/1
|
||||
*/
|
||||
public class MakeupDataFactory extends AbstractMakeupDataFactory {
|
||||
|
||||
|
||||
/*渲染控制器*/
|
||||
private FURenderKit mFURenderKit = FURenderKit.getInstance();
|
||||
|
||||
/*组合妆容列表*/
|
||||
private ArrayList<MakeupCombinationBean> makeupCombinations;
|
||||
/*组合妆容当前下标*/
|
||||
private int currentCombinationIndex;//-1:自定义
|
||||
/*美妆数据模型*/
|
||||
private SimpleMakeup currentMakeup;
|
||||
/*美妆数据模型缓存*/
|
||||
private HashMap<String, SimpleMakeup> makeupMap = new HashMap<>();
|
||||
|
||||
|
||||
public MakeupDataFactory(int index) {
|
||||
makeupCombinations = MakeupSource.buildCombinations();
|
||||
currentCombinationIndex = index;
|
||||
currentMakeup = getMakeupModel(makeupCombinations.get(currentCombinationIndex)); // 当前生效模型
|
||||
}
|
||||
|
||||
//region 组合妆
|
||||
|
||||
/**
|
||||
* 获取当前组合妆容列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@NonNull
|
||||
public ArrayList<MakeupCombinationBean> getMakeupCombinations() {
|
||||
return makeupCombinations;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前组合妆容下标
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getCurrentCombinationIndex() {
|
||||
return currentCombinationIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置组合妆容下标
|
||||
*
|
||||
* @param currentCombinationIndex
|
||||
*/
|
||||
@Override
|
||||
public void setCurrentCombinationIndex(int currentCombinationIndex) {
|
||||
this.currentCombinationIndex = currentCombinationIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换组合妆容
|
||||
*
|
||||
* @param bean
|
||||
*/
|
||||
@Override
|
||||
public void onMakeupCombinationSelected(MakeupCombinationBean bean) {
|
||||
currentMakeup = getMakeupModel(bean);
|
||||
mFURenderKit.setMakeup(currentMakeup);
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换美妆模型整体强度
|
||||
*
|
||||
* @param intensity
|
||||
*/
|
||||
@Override
|
||||
public void updateCombinationIntensity(double intensity) {
|
||||
currentMakeup.setMakeupIntensity(intensity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造美妆模型
|
||||
*
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
private SimpleMakeup getMakeupModel(MakeupCombinationBean bean) {
|
||||
if (bean.getBundlePath() == null) {
|
||||
return null;
|
||||
} else {
|
||||
if (makeupMap.containsKey(bean.getKey())) {
|
||||
return makeupMap.get(bean.getKey());
|
||||
}
|
||||
SimpleMakeup makeup = new SimpleMakeup(new FUBundleData(MakeupSource.BUNDLE_FACE_MAKEUP));
|
||||
makeup.setCombinedConfig(new FUBundleData(bean.getBundlePath()));
|
||||
makeup.setMakeupIntensity(bean.getIntensity());
|
||||
makeupMap.put(bean.getKey(), makeup);
|
||||
return makeup;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//endregion 组合妆
|
||||
|
||||
/**
|
||||
* FURenderKit加载当前特效
|
||||
*/
|
||||
public void bindCurrentRenderer() {
|
||||
mFURenderKit.setMakeup(currentMakeup);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.yunbao.faceunity.data;
|
||||
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.faceunity.core.entity.FUBundleData;
|
||||
import com.faceunity.core.faceunity.FURenderKit;
|
||||
import com.faceunity.core.model.prop.Prop;
|
||||
import com.faceunity.core.model.prop.sticker.Sticker;
|
||||
|
||||
import com.yunbao.faceunity.entity.PropBean;
|
||||
import com.yunbao.faceunity.infe.AbstractPropDataFactory;
|
||||
import com.yunbao.faceunity.repo.PropSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* DESC:道具业务工厂
|
||||
* Created on 2021/3/2
|
||||
*/
|
||||
public class PropDataFactory extends AbstractPropDataFactory {
|
||||
|
||||
/*渲染控制器*/
|
||||
private final FURenderKit mFURenderKit = FURenderKit.getInstance();
|
||||
/*道具列表*/
|
||||
private final ArrayList<PropBean> propBeans;
|
||||
/*默认选中下标*/
|
||||
private int currentPropIndex;
|
||||
/*当前道具*/
|
||||
public Prop currentProp;
|
||||
|
||||
public PropDataFactory(int index) {
|
||||
currentPropIndex = index;
|
||||
propBeans = PropSource.buildPropBeans();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前选中下标
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getCurrentPropIndex() {
|
||||
return currentPropIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前选中下标
|
||||
*
|
||||
* @param currentPropIndex
|
||||
*/
|
||||
@Override
|
||||
public void setCurrentPropIndex(int currentPropIndex) {
|
||||
this.currentPropIndex = currentPropIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取道具队列
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@NonNull
|
||||
public ArrayList<PropBean> getPropBeans() {
|
||||
return propBeans;
|
||||
}
|
||||
|
||||
/**
|
||||
* 道具选中
|
||||
*
|
||||
* @param bean
|
||||
*/
|
||||
@Override
|
||||
public void onItemSelected(PropBean bean) {
|
||||
String path = bean.getPath();
|
||||
if (path == null || path.trim().length() == 0) {
|
||||
mFURenderKit.getPropContainer().removeAllProp();
|
||||
currentProp = null;
|
||||
return;
|
||||
}
|
||||
Prop prop = new Sticker(new FUBundleData(path));
|
||||
mFURenderKit.getPropContainer().replaceProp(currentProp, prop);
|
||||
currentProp = prop;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* FURenderKit加载当前特效
|
||||
*/
|
||||
public void bindCurrentRenderer() {
|
||||
PropBean propBean = propBeans.get(currentPropIndex);
|
||||
onItemSelected(propBean);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user