Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add smr suggestions and customizable toggle/bs suggestions #181

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -403,83 +403,106 @@ private bool IsGameObjectUsedInToggles(GameObject go, List<ToggleData> toggleDat
return false;
}

private void UpdateAvatarOnWearToggleSuggestions(PresetViewData presetData)
private bool IsGameObjectUsedInBlendshapes(GameObject go, List<BlendshapeData> blendshapeData)
{
presetData.toggleSuggestions.Clear();
foreach (var blendshape in blendshapeData)
{
if (blendshape.gameObject == go)
{
return true;
}
}
return false;
}

var targetAvatar = _parentView.TargetAvatar;
var targetWearable = _parentView.TargetWearable;
private void UpdateToggleAndSmrSuggestions(Transform root, List<AnimationToggle> realToggles, List<ToggleData> toggles,
List<ToggleSuggestionData> toggleSuggestions, List<AnimationBlendshapeValue> realBlendshapes, List<BlendshapeData> blendshapes,
List<SmrSuggestionData> smrSuggestions, Action updateView, bool inverted, string armatureName = null, Transform skipTransform = null)
{
toggleSuggestions.Clear();
smrSuggestions.Clear();

if (targetAvatar != null && targetWearable != null && _cabinetConfig != null)
// iterate through childs
for (var i = 0; i < root.childCount; i++)
{
var armatureName = _cabinetConfig.avatarArmatureName;
var avatarTrans = targetAvatar.transform;
var childTrans = root.GetChild(i);

// iterate through childs
for (var i = 0; i < avatarTrans.childCount; i++)
if ((skipTransform == null || skipTransform != childTrans) &&
(armatureName == null || childTrans.name != armatureName))
{
var childTrans = avatarTrans.GetChild(i);
if (childTrans != targetWearable.transform && childTrans.name != armatureName && !IsGameObjectUsedInToggles(childTrans.gameObject, presetData.toggles))
if (!IsGameObjectUsedInToggles(childTrans.gameObject, toggles))
{
var toggleSuggestion = new ToggleSuggestionData
{
gameObject = childTrans.gameObject,
state = !childTrans.gameObject.activeSelf,
state = childTrans.gameObject.activeSelf ^ inverted,
addButtonClickEvent = () =>
{
_module.avatarAnimationOnWear.toggles.Add(new AnimationToggle()
realToggles.Add(new AnimationToggle()
{
path = AnimationUtils.GetRelativePath(childTrans, avatarTrans),
state = !childTrans.gameObject.activeSelf
path = AnimationUtils.GetRelativePath(childTrans, root),
state = childTrans.gameObject.activeSelf ^ inverted
});
UpdateAnimationGenerationAvatarOnWear();
_parentView.UpdateAvatarPreview();
updateView.Invoke();
}
};
presetData.toggleSuggestions.Add(toggleSuggestion);
toggleSuggestions.Add(toggleSuggestion);
}

if (childTrans.TryGetComponent<SkinnedMeshRenderer>(out _) &&
!IsGameObjectUsedInBlendshapes(childTrans.gameObject, blendshapes))
{
var smrSuggestion = new SmrSuggestionData
{
gameObject = childTrans.gameObject,
addButtonClickEvent = () =>
{
realBlendshapes.Add(new AnimationBlendshapeValue()
{
path = AnimationUtils.GetRelativePath(childTrans, root),
blendshapeName = "",
value = 0
});
_parentView.UpdateAvatarPreview();
updateView.Invoke();
}
};
smrSuggestions.Add(smrSuggestion);
}
}
}
}

private void UpdateWearableOnWearToggleSuggestions(PresetViewData presetData)
private void UpdateAvatarOnWearToggleAndSmrSuggestions(PresetViewData presetData)
{
presetData.toggleSuggestions.Clear();

var targetAvatar = _parentView.TargetAvatar;
var targetWearable = _parentView.TargetWearable;

if (targetWearable != null)
if (targetAvatar != null && targetWearable != null && _cabinetConfig != null)
{
return;
}
var armatureName = _cabinetConfig.avatarArmatureName;
var avatarTrans = targetAvatar.transform;
var wearableTrans = targetWearable.transform;

var wearableTrans = targetWearable.transform;
UpdateToggleAndSmrSuggestions(
avatarTrans, _module.avatarAnimationOnWear.toggles, presetData.toggles, presetData.toggleSuggestions,
_module.avatarAnimationOnWear.blendshapes, presetData.blendshapes, presetData.smrSuggestions,
() => UpdateAnimationGenerationAvatarOnWear(), true, armatureName, wearableTrans);
}
}

// TODO: we can't obtain wearable armature name here, listing everything at the root for now
private void UpdateWearableOnWearToggleAndSmrSuggestions(PresetViewData presetData)
{
var targetWearable = _parentView.TargetWearable;

// iterate through childs
for (var i = 0; i < wearableTrans.childCount; i++)
if (targetWearable != null)
{
var childTrans = wearableTrans.GetChild(i);
if (!IsGameObjectUsedInToggles(childTrans.gameObject, presetData.toggles))
{
var toggleSuggestion = new ToggleSuggestionData
{
gameObject = childTrans.gameObject,
state = childTrans.gameObject.activeSelf,
addButtonClickEvent = () =>
{
_module.wearableAnimationOnWear.toggles.Add(new AnimationToggle()
{
path = AnimationUtils.GetRelativePath(childTrans, wearableTrans),
state = !childTrans.gameObject.activeSelf
});
UpdateAnimationGenerationWearableOnWear();
_parentView.UpdateAvatarPreview();
}
};
presetData.toggleSuggestions.Add(toggleSuggestion);
}
var wearableTrans = targetWearable.transform;
UpdateToggleAndSmrSuggestions(
wearableTrans, _module.wearableAnimationOnWear.toggles, presetData.toggles, presetData.toggleSuggestions,
_module.avatarAnimationOnWear.blendshapes, presetData.blendshapes, presetData.smrSuggestions,
() => UpdateAnimationGenerationWearableOnWear(), false);
}
}

Expand All @@ -499,7 +522,7 @@ private void UpdateAnimationGenerationAvatarOnWear()

_view.ShowCannotRenderPresetWithoutTargetAvatarHelpBox = false;
UpdateAnimationPreset(_parentView.TargetAvatar.transform, savedPresets, _module.avatarAnimationOnWear, _view.AvatarOnWearPresetData, () => UpdateAnimationGenerationAvatarOnWear());
UpdateAvatarOnWearToggleSuggestions(_view.AvatarOnWearPresetData);
UpdateAvatarOnWearToggleAndSmrSuggestions(_view.AvatarOnWearPresetData);
}
else
{
Expand All @@ -523,18 +546,49 @@ private void UpdateAnimationGenerationWearableOnWear()

_view.ShowCannotRenderPresetWithoutTargetWearableHelpBox = false;
UpdateAnimationPreset(_parentView.TargetWearable.transform, savedPresets, _module.wearableAnimationOnWear, _view.WearableOnWearPresetData, () => UpdateAnimationGenerationWearableOnWear());
UpdateWearableOnWearToggleSuggestions(_view.WearableOnWearPresetData);
UpdateWearableOnWearToggleAndSmrSuggestions(_view.WearableOnWearPresetData);
}
else
{
_view.ShowCannotRenderPresetWithoutTargetWearableHelpBox = true;
}
}

private void UpdateCustomizableAvatarToggles(WearableCustomizable wearable, CustomizableViewData customizableData) => UpdateToggles(_parentView.TargetAvatar.transform, wearable.avatarToggles, customizableData.avatarToggles);
private void UpdateCustomizableWearableToggles(WearableCustomizable wearable, CustomizableViewData customizableData) => UpdateToggles(_parentView.TargetWearable.transform, wearable.wearableToggles, customizableData.wearableToggles);
private void UpdateCustomizableAvatarBlendshapes(WearableCustomizable wearable, CustomizableViewData customizableData) => UpdateBlendshapes(_parentView.TargetAvatar.transform, wearable.avatarBlendshapes, customizableData.avatarBlendshapes);
private void UpdateCustomizableWearableBlendshapes(WearableCustomizable wearable, CustomizableViewData customizableData) => UpdateBlendshapes(_parentView.TargetWearable.transform, wearable.wearableBlendshapes, customizableData.wearableBlendshapes);
private void UpdateCustomizableAvatarTogglesAndBlendshapes(WearableCustomizable wearable, CustomizableViewData customizableData)
{
var targetAvatar = _parentView.TargetAvatar;
var targetWearable = _parentView.TargetWearable;

if (targetAvatar != null && targetWearable != null && _cabinetConfig != null)
{
var armatureName = _cabinetConfig.avatarArmatureName;
var avatarTrans = targetAvatar.transform;
var wearableTrans = targetWearable.transform;

UpdateToggles(avatarTrans, wearable.avatarToggles, customizableData.avatarToggles);
UpdateBlendshapes(_parentView.TargetAvatar.transform, wearable.avatarBlendshapes, customizableData.avatarBlendshapes);
UpdateToggleAndSmrSuggestions(avatarTrans, wearable.avatarToggles, customizableData.avatarToggles, customizableData.avatarToggleSuggestions,
wearable.avatarBlendshapes, customizableData.avatarBlendshapes, customizableData.avatarSmrSuggestions,
() => UpdateCustomizableAvatarTogglesAndBlendshapes(wearable, customizableData), true, armatureName, wearableTrans);
}
}

private void UpdateCustomizableWearableTogglesAndBlendshapes(WearableCustomizable wearable, CustomizableViewData customizableData)
{
var targetAvatar = _parentView.TargetAvatar;
var targetWearable = _parentView.TargetWearable;

if (targetAvatar != null && targetWearable != null)
{
var wearableTrans = targetWearable.transform;

UpdateToggles(wearableTrans, wearable.wearableToggles, customizableData.wearableToggles);
UpdateBlendshapes(_parentView.TargetWearable.transform, wearable.wearableBlendshapes, customizableData.wearableBlendshapes);
UpdateToggleAndSmrSuggestions(wearableTrans, wearable.wearableToggles, customizableData.wearableToggles, customizableData.wearableToggleSuggestions,
wearable.wearableBlendshapes, customizableData.wearableBlendshapes, customizableData.wearableSmrSuggestions,
() => UpdateCustomizableWearableTogglesAndBlendshapes(wearable, customizableData), true);
}
}

private void UpdateCustomizables()
{
Expand Down Expand Up @@ -570,28 +624,28 @@ private void UpdateCustomizables()
customizableData.addAvatarToggleEvent = () =>
{
wearable.avatarToggles.Add(new AnimationToggle());
UpdateCustomizableAvatarToggles(wearable, customizableData);
UpdateCustomizableAvatarTogglesAndBlendshapes(wearable, customizableData);
};
customizableData.addAvatarBlendshapeEvent = () =>
{
wearable.avatarBlendshapes.Add(new AnimationBlendshapeValue());
UpdateCustomizableAvatarBlendshapes(wearable, customizableData);
UpdateCustomizableAvatarTogglesAndBlendshapes(wearable, customizableData);
};
customizableData.addWearableToggleEvent = () =>
{
wearable.wearableToggles.Add(new AnimationToggle());
UpdateCustomizableWearableToggles(wearable, customizableData);
UpdateCustomizableWearableTogglesAndBlendshapes(wearable, customizableData);
};
customizableData.addWearableBlendshapeEvent = () =>
{
wearable.wearableBlendshapes.Add(new AnimationBlendshapeValue());
UpdateCustomizableWearableBlendshapes(wearable, customizableData);
UpdateCustomizableWearableTogglesAndBlendshapes(wearable, customizableData);
};

UpdateCustomizableAvatarToggles(wearable, customizableData);
UpdateCustomizableAvatarBlendshapes(wearable, customizableData);
UpdateCustomizableWearableToggles(wearable, customizableData);
UpdateCustomizableWearableBlendshapes(wearable, customizableData);
UpdateCustomizableAvatarTogglesAndBlendshapes(wearable, customizableData);
UpdateCustomizableAvatarTogglesAndBlendshapes(wearable, customizableData);
UpdateCustomizableWearableTogglesAndBlendshapes(wearable, customizableData);
UpdateCustomizableWearableTogglesAndBlendshapes(wearable, customizableData);

_view.Customizables.Add(customizableData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void DrawToggles(string title, List<ToggleData> toggles, List<ToggleSugg
EndFoldoutBox();
}

private void DrawBlendshapes(string title, List<BlendshapeData> blendshapes, Action addButtonOnClickedEvent, ref bool foldoutAnimationPresetBlendshapes, bool hideSlider = false)
private void DrawBlendshapes(string title, List<BlendshapeData> blendshapes, List<SmrSuggestionData> smrSuggestions, Action addButtonOnClickedEvent, ref bool foldoutAnimationPresetBlendshapes, bool hideSlider = false)
{
BeginFoldoutBox(ref foldoutAnimationPresetBlendshapes, title);
if (foldoutAnimationPresetBlendshapes)
Expand Down Expand Up @@ -179,6 +179,27 @@ private void DrawBlendshapes(string title, List<BlendshapeData> blendshapes, Act
}
EndHorizontal();
}

HorizontalLine();

Label("Suggestions:");

Separator();

var smrSuggestionCopy = new List<SmrSuggestionData>(smrSuggestions);
foreach (var smrSuggestion in smrSuggestionCopy)
{
BeginHorizontal();
{
Button("+", smrSuggestion.addButtonClickEvent, GUILayout.ExpandWidth(false));
BeginDisabled(true);
{
GameObjectField(ref smrSuggestion.gameObject, true, null);
}
EndDisabled();
}
EndHorizontal();
}
}
EndFoldoutBox();
}
Expand All @@ -196,7 +217,7 @@ private void DrawAnimationPreset(PresetViewData presetData, Action changeEvent,
Separator();

DrawToggles("Toggles", presetData.toggles, presetData.toggleSuggestions, toggleAddEvent, ref foldoutAnimationPresetToggles);
DrawBlendshapes("Blendshapes", presetData.blendshapes, blendshapeAddEvent, ref foldoutAnimationPresetBlendshapes);
DrawBlendshapes("Blendshapes", presetData.blendshapes, presetData.smrSuggestions, blendshapeAddEvent, ref foldoutAnimationPresetBlendshapes);
}

private void DrawAnimationGenerationAvatarOnWear()
Expand Down Expand Up @@ -251,19 +272,19 @@ private void DrawCustomizable(CustomizableViewData customizable)
HorizontalLine();

DrawToggles("Avatar Toggles", customizable.avatarToggles, customizable.avatarToggleSuggestions, customizable.addAvatarToggleEvent, ref customizable.foldoutAvatarToggles);
DrawBlendshapes("Avatar Blendshapes", customizable.avatarBlendshapes, customizable.addAvatarBlendshapeEvent, ref customizable.foldoutAvatarBlendshapes);
DrawBlendshapes("Wearable Blendshapes", customizable.wearableBlendshapes, customizable.addWearableBlendshapeEvent, ref customizable.foldoutWearableBlendshapes);
DrawBlendshapes("Avatar Blendshapes", customizable.avatarBlendshapes, customizable.avatarSmrSuggestions, customizable.addAvatarBlendshapeEvent, ref customizable.foldoutAvatarBlendshapes);
DrawBlendshapes("Wearable Blendshapes", customizable.wearableBlendshapes, customizable.wearableSmrSuggestions, customizable.addWearableBlendshapeEvent, ref customizable.foldoutWearableBlendshapes);
}
else
{
DrawBlendshapes("Wearable Blendshapes", customizable.wearableBlendshapes, customizable.addWearableBlendshapeEvent, ref customizable.foldoutWearableBlendshapes, true);
DrawBlendshapes("Wearable Blendshapes", customizable.wearableBlendshapes, customizable.wearableSmrSuggestions, customizable.addWearableBlendshapeEvent, ref customizable.foldoutWearableBlendshapes, true);

HorizontalLine();

// radial blendshape mode
DrawToggles("Avatar Toggles", customizable.avatarToggles, customizable.avatarToggleSuggestions, customizable.addAvatarToggleEvent, ref customizable.foldoutAvatarToggles);
DrawToggles("Wearable Toggles", customizable.wearableToggles, customizable.wearableToggleSuggestions, customizable.addWearableToggleEvent, ref customizable.foldoutWearableToggles);
DrawBlendshapes("Avatar Blendshapes", customizable.avatarBlendshapes, customizable.addAvatarBlendshapeEvent, ref customizable.foldoutAvatarBlendshapes);
DrawBlendshapes("Avatar Blendshapes", customizable.avatarBlendshapes, customizable.avatarSmrSuggestions, customizable.addAvatarBlendshapeEvent, ref customizable.foldoutAvatarBlendshapes);
}
}
EndFoldoutBox();
Expand Down
Loading
Loading