-
-
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 #1181 from anatawa12/optimize-texture-as-possible
feat: Optimize Texture (UV Packing)
- Loading branch information
Showing
25 changed files
with
2,856 additions
and
7 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using Anatawa12.AvatarOptimizer.ndmf; | ||
using nadena.dev.ndmf; | ||
using UnityEditor; | ||
using UnityEditor.Animations; | ||
using UnityEngine; | ||
using Object = UnityEngine.Object; | ||
|
||
namespace Anatawa12.AvatarOptimizer.Processors; | ||
|
||
/// <summary> | ||
/// The class to clone something for future in-place modification | ||
/// | ||
/// Currently this class is intended to clone | ||
/// </summary> | ||
internal class DupliacteAssets : Pass<DupliacteAssets> | ||
{ | ||
protected override void Execute(BuildContext context) | ||
{ | ||
if (!context.GetState<AAOEnabled>().Enabled) return; | ||
|
||
var cloner = new Cloner(); | ||
|
||
foreach (var component in context.GetComponents<Component>()) | ||
{ | ||
switch (component) | ||
{ | ||
case SkinnedMeshRenderer renderer: | ||
{ | ||
var meshInfo2 = context.GetMeshInfoFor(renderer); | ||
foreach (var subMesh in meshInfo2.SubMeshes) | ||
foreach (ref var material in subMesh.SharedMaterials.AsSpan()) | ||
material = cloner.MapObject(material); | ||
} | ||
break; | ||
default: | ||
{ | ||
using var serializedObject = new SerializedObject(component); | ||
|
||
foreach (var objectReferenceProperty in serializedObject.ObjectReferenceProperties()) | ||
{ | ||
objectReferenceProperty.objectReferenceValue = cloner.MapObject(objectReferenceProperty.objectReferenceValue); | ||
} | ||
|
||
serializedObject.ApplyModifiedPropertiesWithoutUndo(); | ||
|
||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
class Cloner : DeepCloneHelper | ||
{ | ||
protected override Object? CustomClone(Object o) => null; | ||
|
||
protected override ComponentSupport GetComponentSupport(Object o) | ||
{ | ||
switch (o) | ||
{ | ||
// Target Objects | ||
case Material: | ||
return ComponentSupport.Clone; | ||
|
||
// intermediate objects | ||
case Motion: | ||
case AnimatorController: | ||
case AnimatorOverrideController: | ||
case AnimatorState: | ||
case AnimatorStateMachine: | ||
case AnimatorTransitionBase: | ||
case StateMachineBehaviour: | ||
|
||
#if AAO_VRM0 | ||
case VRM.BlendShapeAvatar: | ||
case VRM.BlendShapeClip: | ||
#endif | ||
#if AAO_VRM1 | ||
case UniVRM10.VRM10Object: | ||
case UniVRM10.VRM10Expression: | ||
#endif | ||
return ComponentSupport.Clone; | ||
|
||
case Texture: | ||
case MonoScript: | ||
case Component: | ||
case GameObject: | ||
return ComponentSupport.NoClone; | ||
|
||
case ScriptableObject: | ||
return ComponentSupport.NoClone; | ||
|
||
default: | ||
return ComponentSupport.NoClone; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.