Skip to content

Commit

Permalink
fix: blendshape customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
poi-vrc committed Aug 31, 2023
1 parent f0ebac4 commit 3d18f12
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Packages/com.chocopoi.vrc.avatarlib
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,22 @@ private void UpdateToggles(Transform root, List<AnimationToggle> toggles, List<T

private string[] GetBlendshapeNames(Mesh mesh)
{
var names = new List<string>
{
"---"
};

if (mesh == null)
{
return null;
return names.ToArray();
}

string[] names = new string[mesh.blendShapeCount];
for (var i = 0; i < names.Length; i++)
for (var i = 0; i < mesh.blendShapeCount; i++)
{
names[i] = mesh.GetBlendShapeName(i);
names.Add(mesh.GetBlendShapeName(i));
}
return names;

return names.ToArray();
}

private void UpdateBlendshapes(Transform root, List<AnimationBlendshapeValue> blendshapes, List<BlendshapeData> blendshapeDataList, Action updateView = null)
Expand Down Expand Up @@ -341,10 +346,11 @@ private void UpdateBlendshapes(Transform root, List<AnimationBlendshapeValue> bl
blendshapeData.availableBlendshapeNames = GetBlendshapeNames(newMesh);
blendshapeData.selectedBlendshapeIndex = 0;
blendshapeData.value = 0;
blendshapeData.isInvalid = true;
blendshape.blendshapeName = blendshapeData.availableBlendshapeNames[blendshapeData.selectedBlendshapeIndex];
blendshape.value = blendshapeData.value;
_parentView.UpdateAvatarPreview();
// blendshape.blendshapeName = blendshapeData.availableBlendshapeNames[blendshapeData.selectedBlendshapeIndex];
// blendshape.value = blendshapeData.value;
// _parentView.UpdateAvatarPreview();
}
else
{
Expand All @@ -353,8 +359,15 @@ private void UpdateBlendshapes(Transform root, List<AnimationBlendshapeValue> bl
};
blendshapeData.blendshapeNameChangeEvent = () =>
{
blendshape.blendshapeName = blendshapeData.availableBlendshapeNames[blendshapeData.selectedBlendshapeIndex];
_parentView.UpdateAvatarPreview();
if (blendshapeData.selectedBlendshapeIndex != 0)
{
blendshape.blendshapeName = blendshapeData.availableBlendshapeNames[blendshapeData.selectedBlendshapeIndex];
_parentView.UpdateAvatarPreview();
}
else
{
blendshapeData.isInvalid = true;
}
};
blendshapeData.sliderChangeEvent = () =>
{
Expand Down Expand Up @@ -612,6 +625,7 @@ private void UpdateCustomizables()
{
_module.wearableCustomizables.Remove(wearable);
_view.Customizables.Remove(customizableData);
UpdateCustomizableAvatarTogglesAndBlendshapes(wearable, customizableData);
};

customizableData.customizableSettingsChangeEvent = () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ private void DrawCustomizable(CustomizableViewData customizable)
BeginFoldoutBoxWithButtonRight(ref customizable.foldout, customizable.name, "x Remove", customizable.removeButtonClickEvent);
if (customizable.foldout)
{
if (customizable.IsInvalid())
{
HelpBox("This customizable is invalid.", MessageType.Error);
}

TextField("Name", ref customizable.name, customizable.customizableSettingsChangeEvent);
Popup("Type:", ref customizable.type, new string[] { "Toggle", "Blendshape" }, customizable.customizableSettingsChangeEvent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,35 @@ public CustomizableViewData()
addWearableBlendshapeEvent = null;
removeButtonClickEvent = null;
}

public bool IsInvalid()
{
var result = false;

result |= name == null || name == "";

foreach (var toggle in avatarToggles)
{
result |= toggle.isInvalid;
}

foreach (var toggle in wearableToggles)
{
result |= toggle.isInvalid;
}

foreach (var blendshape in avatarBlendshapes)
{
result |= blendshape.isInvalid;
}

foreach (var blendshape in wearableBlendshapes)
{
result |= blendshape.isInvalid;
}

return result;
}
}

internal interface IAnimationGenerationWearableModuleEditorView : IEditorView
Expand Down

0 comments on commit 3d18f12

Please sign in to comment.