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 eyelids bugs #235

Merged
merged 5 commits into from
Jun 18, 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
3 changes: 3 additions & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ The format is based on [Keep a Changelog].
### Added

### Changed
- Show error with user friendly message if blendshape for eyelids are removed / frozen. `#253`

### Deprecated

### Removed

### Fixed
- eyelids BlendShape settings are mapped even if it's disabled `#235`
- This fixes error if internally eyelids BlendShape are frozen.

### Security

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ The format is based on [Keep a Changelog].
### Added

### Changed
- Show error with user friendly message if blendshape for eyelids are removed / frozen. `#253`

### Deprecated

### Removed

### Fixed
- eyelids BlendShape settings are mapped even if it's disabled `#235`
- This fixes error if internally eyelids BlendShape are frozen.

### Security

Expand Down
41 changes: 26 additions & 15 deletions Editor/Processors/ApplyObjectMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public void Apply(OptimizerSession session)
var mapping = session.MappingBuilder.BuildObjectMapping();

// replace all objects
foreach (var component in session.GetComponents<Component>())
BuildReport.ReportingObjects(session.GetComponents<Component>(), component =>
{
if (component is Transform) return;
var serialized = new SerializedObject(component);
if (component is Transform) continue;
AnimatorControllerMapper mapper = null;
SpecialMappingApplier.Apply(component.GetType(), serialized, mapping, ref mapper);
var p = serialized.GetIterator();
Expand All @@ -35,7 +35,8 @@ public void Apply(OptimizerSession session)
if (p.objectReferenceValue is AnimatorController controller)
{
if (mapper == null)
mapper = new AnimatorControllerMapper(mapping.CreateAnimationMapper(component.gameObject),
mapper = new AnimatorControllerMapper(
mapping.CreateAnimationMapper(component.gameObject),
session.RelativePath(component.transform), session);

// ReSharper disable once AccessToModifiedClosure
Expand Down Expand Up @@ -83,7 +84,7 @@ public void Apply(OptimizerSession session)
}

serialized.ApplyModifiedProperties();
}
});
}
}

Expand All @@ -100,23 +101,33 @@ public static void Apply(Type type, SerializedObject serialized,
private static void VRCAvatarDescriptor(SerializedObject serialized,
ObjectMapping mapping, ref AnimatorControllerMapper mapper)
{
var eyelidsEnabled = serialized.FindProperty("enableEyeLook");
var eyelidType = serialized.FindProperty("customEyeLookSettings.eyelidType");
var eyelidsSkinnedMesh = serialized.FindProperty("customEyeLookSettings.eyelidsSkinnedMesh");
var eyelidsBlendshapes = serialized.FindProperty("customEyeLookSettings.eyelidsBlendshapes");
if (eyelidsSkinnedMesh == null || eyelidsBlendshapes == null) return;

var info = mapping.GetComponentMapping(eyelidsSkinnedMesh.objectReferenceInstanceIDValue);
if (info == null) return;
if (eyelidsEnabled.boolValue &&
eyelidType.enumValueIndex == (int)VRC.SDK3.Avatars.Components.VRCAvatarDescriptor.EyelidType.Blendshapes)
{
var info = mapping.GetComponentMapping(eyelidsSkinnedMesh.objectReferenceInstanceIDValue);
if (info == null) return;

eyelidsSkinnedMesh.objectReferenceValue = EditorUtility.InstanceIDToObject(info.MergedInto);
eyelidsSkinnedMesh.objectReferenceValue = EditorUtility.InstanceIDToObject(info.MergedInto);

for (var i = 0; i < eyelidsBlendshapes.arraySize; i++)
{
var indexProp = eyelidsBlendshapes.GetArrayElementAtIndex(i);
if (info.PropertyMapping.TryGetValue(
VProp.BlendShapeIndex(indexProp.intValue),
out var mappedPropName))
for (var i = 0; i < eyelidsBlendshapes.arraySize; i++)
{
indexProp.intValue = VProp.ParseBlendShapeIndex(mappedPropName);
var indexProp = eyelidsBlendshapes.GetArrayElementAtIndex(i);
if (info.PropertyMapping.TryGetValue(
VProp.BlendShapeIndex(indexProp.intValue),
out var mappedPropName))
{
if (mappedPropName == null)
{
BuildReport.LogFatal("ApplyObjectMapping:VRCAvatarDescriptor:eyelids BlendShape Removed");
return;
}
indexProp.intValue = VProp.ParseBlendShapeIndex(mappedPropName);
}
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions Internal/ErrorReporter/Editor/BuildReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ internal AvatarReport Initialize(VRCAvatarDescriptor descriptor)
}

[CanBeNull]
internal static ErrorLog Log(ReportLevel level, string code, object[] strings)
internal static ErrorLog Log(ReportLevel level, string code, params string[] strings)
{
var errorLog = new ErrorLog(level, code, strings: strings.Select(s => s.ToString()).ToArray());
for (var i = 0; i < strings.Length; i++)
strings[i] = strings[i] ?? "";
var errorLog = new ErrorLog(level, code, strings);

var avatarReport = CurrentReport.CurrentAvatar;
if (avatarReport == null)
Expand All @@ -143,7 +145,7 @@ internal static ErrorLog Log(ReportLevel level, string code, object[] strings)
}

[CanBeNull]
internal static ErrorLog LogFatal(string code, object[] strings)
public static ErrorLog LogFatal(string code, params string[] strings)
{
var log = Log(ReportLevel.Error, code, strings: strings);
if (CurrentReport.CurrentAvatar != null)
Expand Down
7 changes: 7 additions & 0 deletions Localization/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ msgstr "If checked, this tool does not remove bones with non-bone children."

# endregion

#region ApplyObjectMapping

msgid "ApplyObjectMapping:VRCAvatarDescriptor:eyelids BlendShape Removed"
msgstr "BlendShape(s) for eyelids are Removed / frozen."

#endregion

# region ErrorReporter

msgid "ErrorReporter:error.internal_error"
Expand Down
7 changes: 7 additions & 0 deletions Localization/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ msgstr "チェックされている場合、子にボーン以外を持つボー

# endregion

#region ApplyObjectMapping

msgid "ApplyObjectMapping:VRCAvatarDescriptor:eyelids BlendShape Removed"
msgstr "瞬き用のBlendShapeが削除・固定されています"

#endregion

# region ErrorReporter

msgid "ErrorReporter:error.internal_error"
Expand Down