-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from anatawa12/freeze-unused-blend-shapes
Freeze meaningless blend shapes
- Loading branch information
Showing
15 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Editor/Processors/SkinnedMeshes/InternalAutoFreezeMeaninglessBlendShapeProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEditor; | ||
|
||
namespace Anatawa12.AvatarOptimizer.Processors.SkinnedMeshes | ||
{ | ||
internal class InternalAutoFreezeMeaninglessBlendShapeProcessor : EditSkinnedMeshProcessor<InternalAutoFreezeMeaninglessBlendShape> | ||
{ | ||
public InternalAutoFreezeMeaninglessBlendShapeProcessor(InternalAutoFreezeMeaninglessBlendShape component) : base(component) | ||
{ | ||
} | ||
|
||
public override EditSkinnedMeshProcessorOrder ProcessOrder => EditSkinnedMeshProcessorOrder.AfterRemoveMesh; | ||
|
||
public override void Process(OptimizerSession session, MeshInfo2 target, MeshInfo2Holder meshInfo2Holder) | ||
{ | ||
var meaningfulBlendShapes = new HashSet<string>(); | ||
|
||
foreach (var vertex in target.Vertices) | ||
foreach (var kvp in vertex.BlendShapes.Where(kvp => kvp.Value != default)) | ||
meaningfulBlendShapes.Add(kvp.Key); | ||
|
||
var freezeBlendShape = Target.GetComponent<FreezeBlendShape>(); | ||
var serialized = new SerializedObject(freezeBlendShape); | ||
var editorUtil = PrefabSafeSet.EditorUtil<string>.Create( | ||
serialized.FindProperty(nameof(FreezeBlendShape.shapeKeysSet)), | ||
0, p => p.stringValue, (p, v) => p.stringValue = v); | ||
foreach (var (meaningLess, _) in target.BlendShapes.Where(x => !meaningfulBlendShapes.Contains(x.name))) | ||
editorUtil.GetElementOf(meaningLess).EnsureAdded(); | ||
serialized.ApplyModifiedPropertiesWithoutUndo(); | ||
} | ||
|
||
// nothing to do | ||
public override IMeshInfoComputer GetComputer(IMeshInfoComputer upstream) => upstream; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Editor/Processors/SkinnedMeshes/InternalAutoFreezeMeaninglessBlendShapeProcessor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using UnityEngine; | ||
|
||
namespace Anatawa12.AvatarOptimizer | ||
{ | ||
// TODO move to somewhere else? e.g. in editor module if possible | ||
[AddComponentMenu("")] | ||
[DisallowMultipleComponent] | ||
internal class InternalAutoFreezeMeaninglessBlendShape : EditSkinnedMeshComponent | ||
{ | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.