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

Remove always disabled objects #278

Merged
merged 5 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -11,6 +11,8 @@ weight: 1
現在、以下の機能の自動設定が可能です。
- [FreezeBlendShape](../freeze-blendshape)
アニメーションなどで使われていないBlendShapeを自動的に固定・除去します。
- `使われていないGameObjectを自動的に削除する`
使われていない、存在価値のないGameObjectを自動的に削除します
anatawa12 marked this conversation as resolved.
Show resolved Hide resolved

また、以下の設定で自動設定を調節できます。
- `MMDワールドとの互換性`
Expand Down
2 changes: 2 additions & 0 deletions .docs/content/docs/reference/automatic-configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ You can enable/disable some automatic configuration features with checkboxes.
Currently the following features can be configured automatically
- [FreezeBlendShape](../freeze-blendshape)
Automatically freezes unused BlendShapes in animation or else.
- `Remove unused GameObjects`
Automatically removes unused (meaningless) GameObjects.

Also, You can adjust automatic configuration with the following settings
- `MMD World Compatibility`
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog].

## [Unreleased]
### Added
- Remove always disabled objects `#278`

### Changed
- Use UnityEditor api to compress texture `#276`
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog].

## [Unreleased]
### Added
- Remove always disabled objects `#278`

### Changed
- Use UnityEditor api to compress texture `#276`
Expand Down
3 changes: 3 additions & 0 deletions Editor/AutomaticConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ namespace Anatawa12.AvatarOptimizer
internal class AutomaticConfigurationEditor : AvatarGlobalComponentEditorBase
{
private SerializedProperty _freezeBlendShape;
private SerializedProperty _removeUnusedObjects;
private SerializedProperty _mmdWorldCompatibility;

private void OnEnable()
{
_freezeBlendShape = serializedObject.FindProperty(nameof(AutomaticConfiguration.freezeBlendShape));
_removeUnusedObjects = serializedObject.FindProperty(nameof(AutomaticConfiguration.removeUnusedObjects));
_mmdWorldCompatibility = serializedObject.FindProperty(nameof(AutomaticConfiguration.mmdWorldCompatibility));
}

Expand All @@ -24,6 +26,7 @@ protected override void OnInspectorGUIInner()
EditorGUILayout.PropertyField(_mmdWorldCompatibility);
GUILayout.Label("Features", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(_freezeBlendShape);
EditorGUILayout.PropertyField(_removeUnusedObjects);

serializedObject.ApplyModifiedProperties();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,20 @@ private void GatherAnimationModificationsInController(GameObject root, RuntimeAn

readonly struct ParsedAnimation
{
public readonly IReadOnlyDictionary<Component, IReadOnlyDictionary<string, AnimationProperty>> Components;
public readonly IReadOnlyDictionary<Object, IReadOnlyDictionary<string, AnimationProperty>> Components;

public ParsedAnimation(IReadOnlyDictionary<Component, IReadOnlyDictionary<string, AnimationProperty>> components)
public ParsedAnimation(IReadOnlyDictionary<Object, IReadOnlyDictionary<string, AnimationProperty>> components)
{
Components = components;
}

public static ParsedAnimation Parse(GameObject root, AnimationClip clip)
{
var components = new Dictionary<Component, IReadOnlyDictionary<string, AnimationProperty>>();
var components = new Dictionary<Object, IReadOnlyDictionary<string, AnimationProperty>>();

foreach (var binding in AnimationUtility.GetCurveBindings(clip))
{
if (!typeof(Component).IsAssignableFrom(binding.type)) continue;
var obj = (Component)AnimationUtility.GetAnimatedObject(root, binding);
var obj = AnimationUtility.GetAnimatedObject(root, binding);
if (obj == null) continue;

var curve = AnimationUtility.GetEditorCurve(clip, binding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Anatawa12.AvatarOptimizer.Processors
{
Expand All @@ -10,8 +11,8 @@ internal partial class AutomaticConfigurationProcessor
private AutomaticConfiguration _config;
private OptimizerSession _session;

private Dictionary<Component, Dictionary<string, AnimationProperty>> _modifiedProperties =
new Dictionary<Component, Dictionary<string, AnimationProperty>>();
private Dictionary<Object, Dictionary<string, AnimationProperty>> _modifiedProperties =
new Dictionary<Object, Dictionary<string, AnimationProperty>>();

public void Process(OptimizerSession session)
{
Expand All @@ -23,13 +24,20 @@ public void Process(OptimizerSession session)
GatherAnimationModifications();
if (_config.freezeBlendShape)
AutoFreezeBlendShape();
if (_config.removeUnusedObjects)
FindUnusedObjects();
}

private IReadOnlyDictionary<string, AnimationProperty> GetModifiedProperties(Component component)
{
return _modifiedProperties.TryGetValue(component, out var value) ? value : EmptyProperties;
}

private IReadOnlyDictionary<string, AnimationProperty> GetModifiedProperties(GameObject component)
{
return _modifiedProperties.TryGetValue(component, out var value) ? value : EmptyProperties;
}

private static readonly IReadOnlyDictionary<string, AnimationProperty> EmptyProperties =
new ReadOnlyDictionary<string, AnimationProperty>(new Dictionary<string, AnimationProperty>());

Expand Down
6 changes: 6 additions & 0 deletions Localization/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ msgstr "Configure Freeze Blend Shape"
msgid "AutomaticConfiguration:prop:mmdWorldCompatibility"
msgstr "MMD World Compatibility"

msgid "AutomaticConfiguration:prop:removeUnusedObjects"
msgstr "Remove unused GameObjects"

msgid "AutomaticConfiguration:tooltip:removeUnusedObjects"
msgstr "Removes GameObjects doesn't have meaning."

msgid "AutomaticConfiguration:tooltip:mmdWorldCompatibility"
msgstr "Enable MMD World Compatibility features such as keeping some BlendShapes"

Expand Down
6 changes: 6 additions & 0 deletions Localization/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ msgstr "このコンポーネントをアバターにつけると、アニメー
msgid "AutomaticConfiguration:prop:freezeBlendShape"
msgstr "Freeze Blend Shapeを自動設定する"

msgid "AutomaticConfiguration:prop:removeUnusedObjects"
msgstr "使われていないGameObjectを自動的に削除する"

msgid "AutomaticConfiguration:tooltip:removeUnusedObjects"
msgstr "存在価値のないGameObjectを自動的に削除します。"
anatawa12 marked this conversation as resolved.
Show resolved Hide resolved

msgid "AutomaticConfiguration:prop:mmdWorldCompatibility"
msgstr "MMDワールドとの互換性"

Expand Down
4 changes: 4 additions & 0 deletions Runtime/AutomaticConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ internal class AutomaticConfiguration : AvatarGlobalComponent
[CL4EELocalized("AutomaticConfiguration:prop:freezeBlendShape")]
[ToggleLeft]
public bool freezeBlendShape = true;
[CL4EELocalized("AutomaticConfiguration:prop:removeUnusedObjects",
"AutomaticConfiguration:tooltip:removeUnusedObjects")]
[ToggleLeft]
public bool removeUnusedObjects = true;
[CL4EELocalized("AutomaticConfiguration:prop:mmdWorldCompatibility",
"AutomaticConfiguration:tooltip:mmdWorldCompatibility")]
[ToggleLeft]
Expand Down