Avatar SDK Local Compute Unity plugin  3.1.0
Realistic avatar generation toolset for Unity3D
Scene #03: Full Body Additional Assets Generation

You can generate haircuts and outfits for an avatar that is already computed.
It is useful for reducing the calculation time. Firstly, you cangenerate an avatar with some initial outfit and haircut. After that, you can generate additional assets that are necessary.

To be able generate additional assets, some intermediate data should be stored for the avatar. Specify the second argument of the GenerateAvatarAsync method as True for saving intermediate data.
GenerateAdditionalAssetsAsync method is used for assets generation. The lists of additional outfits and haircuts are provided in the FullbodyAvatarComputationParameters.
Once all required assets are generated, you can delete the intermediate data by calling the DeleteIntermediateData method.

public IEnumerator GenerateAdditionalAssets(LocalComputeFullbodyAvatarProvider fullbodyAvatarProvider, byte[] photoBytes)
{
// Generate avatar with "generated" haircut and "outfit_0".
FullbodyAvatarComputationParameters computationParameters = new FullbodyAvatarComputationParameters();
computationParameters.haircuts.names.Add("generated");
computationParameters.haircuts.embed = false;
computationParameters.outfits.names.Add("outfit_0");
computationParameters.outfits.embed = false;
var initializeRequest = fullbodyAvatarProvider.InitializeFullbodyAvatarAsync(photoBytes, computationParameters, PipelineType.FIT_PERSON);
yield return initializeRequest;
string avatarCode = initializeRequest.Result;
// Wait avatar to be calculated
var calculateRequest = fullbodyAvatarProvider.GenerateAvatarAsync(avatarCode, PipelineType.FIT_PERSON, true);
yield return calculateRequest;
//Show the generated avatar
FullbodyAvatarLoader avatarLoader = new FullbodyAvatarLoader(fullbodyAvatarProvider);
yield return avatarLoader.LoadAvatarAsync(currentAvatarCode);
var showHaircutRequest = avatarLoader.ShowHaircutAsync("generated");
yield return showHaircutRequest;
var showOutfitRequest = avatarLoader.ShowOutfitAsync("outfit_0");
yield return showOutfitRequest;
//Avatar is compute, generate one more haircut and one more outfit for it.
FullbodyAvatarComputationParameters additionalComputationParameters = new FullbodyAvatarComputationParameters();
additionalComputationParameters.haircuts.names.Add("long_bob");
additionalComputationParameters.haircuts.embed = false;
additionalComputationParameters.outfits.names.Add("outfit_1");
additionalComputationParameters.outfits.embed = false;
var generationRequest = fullbodyAvatarProvider.GenerateAdditionalAssetsAsync(currentAvatarCode, computationParameters);
yield return generationRequest;
// Need to call this method to find just generated assets
avatarLoader.UpdateAvailableHaircutsAndOutfits();
// Show new haircut
var updateHaircutRequest = avatarLoader.ShowHaircutAsync("long_bob");
yield return updateHaircutRequest;
// Show new outfit
var updateOutfitRequest = avatarLoader.ShowOutfitAsync("outfit_1");
yield return updateOutfitRequest;
//Delete intermediate data
fullbodyAvatarProvider.DeleteIntermediateData(currentAvatarCode);
}

Implementation

Implementation details of this sample can be found in the FullbodyAdditionalAssetsGenerationSample.cs script.

Location: Assets/itseez3d/avatar_sdk/samples_local_compute/03_fullbody_additional_assets_generation_sample_local_compute/scenes/03_fullbody_additional_assets_generation_sample_local_compute.unity.