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

fix: blendshape customizable #184

Merged
merged 1 commit into from
Aug 31, 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
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
Loading