Skip to content

Commit

Permalink
fix: various bugs in wearable preview and add blendshape sync preview (
Browse files Browse the repository at this point in the history
  • Loading branch information
poi-vrc authored Aug 29, 2023
1 parent bbe562c commit 51c1336
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License along with DressingTools. If not, see <https://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using Chocopoi.AvatarLib.Animations;
using Chocopoi.DressingTools.Cabinet.Modules;
Expand Down Expand Up @@ -243,7 +244,7 @@ private void OnWearableOnWearBlendshapeAddEvent()
UpdateAnimationGenerationWearableOnWear();
}

private void UpdateToggles(Transform root, List<AnimationToggle> toggles, List<ToggleData> toggleDataList)
private void UpdateToggles(Transform root, List<AnimationToggle> toggles, List<ToggleData> toggleDataList, Action updateView = null)
{
toggleDataList.Clear();
foreach (var toggle in toggles)
Expand Down Expand Up @@ -276,6 +277,7 @@ private void UpdateToggles(Transform root, List<AnimationToggle> toggles, List<T
toggles.Remove(toggle);
toggleDataList.Remove(toggleData);
_parentView.UpdateAvatarPreview();
updateView?.Invoke();
};

toggleDataList.Add(toggleData);
Expand All @@ -297,7 +299,7 @@ private string[] GetBlendshapeNames(Mesh mesh)
return names;
}

private void UpdateBlendshapes(Transform root, List<AnimationBlendshapeValue> blendshapes, List<BlendshapeData> blendshapeDataList)
private void UpdateBlendshapes(Transform root, List<AnimationBlendshapeValue> blendshapes, List<BlendshapeData> blendshapeDataList, Action updateView = null)
{
blendshapeDataList.Clear();
foreach (var blendshape in blendshapes)
Expand Down Expand Up @@ -349,20 +351,29 @@ private void UpdateBlendshapes(Transform root, List<AnimationBlendshapeValue> bl
blendshapeData.isInvalid = true;
}
};
blendshapeData.blendshapeNameChangeEvent = () => blendshape.blendshapeName = blendshapeData.availableBlendshapeNames[blendshapeData.selectedBlendshapeIndex];
blendshapeData.sliderChangeEvent = () => blendshape.value = blendshapeData.value;
blendshapeData.blendshapeNameChangeEvent = () =>
{
blendshape.blendshapeName = blendshapeData.availableBlendshapeNames[blendshapeData.selectedBlendshapeIndex];
_parentView.UpdateAvatarPreview();
};
blendshapeData.sliderChangeEvent = () =>
{
blendshape.value = blendshapeData.value;
_parentView.UpdateAvatarPreview();
};
blendshapeData.removeButtonClickEvent = () =>
{
blendshapes.Remove(blendshape);
blendshapeDataList.Remove(blendshapeData);
_parentView.UpdateAvatarPreview();
updateView?.Invoke();
};

blendshapeDataList.Add(blendshapeData);
}
}

private void UpdateAnimationPreset(Transform root, Dictionary<string, AnimationPreset> savedPresets, AnimationPreset preset, PresetViewData presetData)
private void UpdateAnimationPreset(Transform root, Dictionary<string, AnimationPreset> savedPresets, AnimationPreset preset, PresetViewData presetData, Action updateView)
{
if (savedPresets != null)
{
Expand All @@ -376,8 +387,8 @@ private void UpdateAnimationPreset(Transform root, Dictionary<string, AnimationP
presetData.savedPresetKeys = new string[] { SavedPresetUnselectedPlaceholder };
}

UpdateToggles(root, preset.toggles, presetData.toggles);
UpdateBlendshapes(root, preset.blendshapes, presetData.blendshapes);
UpdateToggles(root, preset.toggles, presetData.toggles, updateView);
UpdateBlendshapes(root, preset.blendshapes, presetData.blendshapes, updateView);
}

private bool IsGameObjectUsedInToggles(GameObject go, List<ToggleData> toggleData)
Expand Down Expand Up @@ -487,7 +498,7 @@ private void UpdateAnimationGenerationAvatarOnWear()
}

_view.ShowCannotRenderPresetWithoutTargetAvatarHelpBox = false;
UpdateAnimationPreset(_parentView.TargetAvatar.transform, savedPresets, _module.avatarAnimationOnWear, _view.AvatarOnWearPresetData);
UpdateAnimationPreset(_parentView.TargetAvatar.transform, savedPresets, _module.avatarAnimationOnWear, _view.AvatarOnWearPresetData, () => UpdateAnimationGenerationAvatarOnWear());
UpdateAvatarOnWearToggleSuggestions(_view.AvatarOnWearPresetData);
}
else
Expand All @@ -511,7 +522,7 @@ private void UpdateAnimationGenerationWearableOnWear()
}

_view.ShowCannotRenderPresetWithoutTargetWearableHelpBox = false;
UpdateAnimationPreset(_parentView.TargetWearable.transform, savedPresets, _module.wearableAnimationOnWear, _view.WearableOnWearPresetData);
UpdateAnimationPreset(_parentView.TargetWearable.transform, savedPresets, _module.wearableAnimationOnWear, _view.WearableOnWearPresetData, () => UpdateAnimationGenerationWearableOnWear());
UpdateWearableOnWearToggleSuggestions(_view.WearableOnWearPresetData);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,17 @@ public override bool OnAfterApplyCabinet(ApplyCabinetContext cabCtx)
}
return true;
}

public override bool OnPreviewWearable(ApplyCabinetContext cabCtx, ApplyWearableContext wearCtx, WearableModule module)
{
if (module == null)
{
return true;
}

FollowBlendshapeSyncValues(cabCtx.avatarGameObject, wearCtx.wearableGameObject, module);

return true;
}
}
}

0 comments on commit 51c1336

Please sign in to comment.