Skip to content

Commit

Permalink
Merge branch 'master' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayamame-beans authored Nov 24, 2024
2 parents 7a82c9f + 25a44c7 commit 3248160
Show file tree
Hide file tree
Showing 50 changed files with 1,538 additions and 67 deletions.
8 changes: 8 additions & 0 deletions API-Editor/ShaderInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ internal MaterialInformationCallback()
[PublicAPI]
public abstract Vector4? GetVector(string propertyName, bool considerAnimation = true);

/// <summary>
/// Returns if the local Shader Keyword is enabled or not.
/// </summary>
/// <param name="keywordName">The name of local shader keyword</param>
/// <returns>true if the local shader keyword is enabled, false if disabled, null if unknown or mixed.</returns>
[PublicAPI]
public abstract bool? IsShaderKeywordEnabled(string keywordName);

/// <summary>
/// Registers UV Usage that are not considered by Avatar Optimizer.
///
Expand Down
43 changes: 40 additions & 3 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ The format is based on [Keep a Changelog].

## [Unreleased]
### Added
- Automatically Merge Material Slot `#1334`
- If you have multile material slots with same material, it will be merged automatically.

### Changed

Expand All @@ -21,6 +19,41 @@ The format is based on [Keep a Changelog].

### Security

## [1.8.0-rc.8] - 2024-11-17
### Fixed
- NRE when saving Prefab with PrefabSafeUniqueCollection [`#1348`](https://github.com/anatawa12/AvatarOptimizer/pull/1348)

## [1.8.0-rc.7] - 2024-11-15
### Added
- Optimize Texture support for Unity Standard, VRChat SDK Standard Lite, VRChat SDK Toon Lit Shaders [`#1346`](https://github.com/anatawa12/AvatarOptimizer/pull/1346)
- If you want more shader support, please comment to [`#1183`](https://github.com/anatawa12/AvatarOptimizer/issues/1183) with shader name and link!

### Changed
- Make error for MergeBone with MergePB rotation mode fix [`#1345`](https://github.com/anatawa12/AvatarOptimizer/pull/1345)
- This was not working as expected in previous version so I made this error.
- We may add support or change behavior in the future release

### Fixed
- Error with nested merge skinned mesh [`#1340`](https://github.com/anatawa12/AvatarOptimizer/pull/1340)
- Broken synced Layer support [`#1341`](https://github.com/anatawa12/AvatarOptimizer/pull/1341)
- Unpacking prefab might look like some data lost in PrefabSafeUniqueCollection [`#1342`](https://github.com/anatawa12/AvatarOptimizer/pull/1342)
- InvalidCastException with RenderTexture [`#1334`](https://github.com/anatawa12/AvatarOptimizer/pull/1334)

## [1.8.0-rc.6] - 2024-11-08
### Changed
- Added animation validation warning for MergePhysBone limit rotation mode Fix [`#1336`](https://github.com/anatawa12/AvatarOptimizer/pull/1336)

### Fixed
- Broken Optimize Texture [`#1338`](https://github.com/anatawa12/AvatarOptimizer/pull/1338)

## [1.8.0-rc.5] - 2024-11-07
### Added
- Automatically Merge Material Slot [`#1334`](https://github.com/anatawa12/AvatarOptimizer/pull/1334)
- If you have multile material slots with same material, it will be merged automatically.

### Changed
- Improved performance in RemoveUnusedMaterialProperties [`#1326`](https://github.com/anatawa12/AvatarOptimizer/pull/1326)

## [1.8.0-rc.4] - 2024-11-06
### Fixed
- Animation bindings for BoxCollider generated by VRCStation will be removed [`#1331`](https://github.com/anatawa12/AvatarOptimizer/pull/1331)
Expand Down Expand Up @@ -1744,7 +1777,11 @@ This release is mistake.
- Merge Bone
- Clear Endpoint Position

[Unreleased]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.8.0-rc.4...HEAD
[Unreleased]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.8.0-rc.8...HEAD
[1.8.0-rc.8]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.8.0-rc.7...v1.8.0-rc.8
[1.8.0-rc.7]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.8.0-rc.6...v1.8.0-rc.7
[1.8.0-rc.6]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.8.0-rc.5...v1.8.0-rc.6
[1.8.0-rc.5]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.8.0-rc.4...v1.8.0-rc.5
[1.8.0-rc.4]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.8.0-rc.3...v1.8.0-rc.4
[1.8.0-rc.3]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.8.0-rc.2...v1.8.0-rc.3
[1.8.0-rc.2]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.8.0-rc.1...v1.8.0-rc.2
Expand Down
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The format is based on [Keep a Changelog].
- We may relax some restriction in the future.
- Because we have to check for each condition if we use AnyState but we can check for only one (in best case) with entry/exit, this generally reduces cost for checking an parameter in a state.
- Combined with Entry / Exit to 1D BlendTree optimization, which is implemented in previous release, your AnyState layer may be optimized to 1D BlendTree.
- Optimize Texture in Trace nad Optimize `#1181` `#1184` `#1193` `#1215` `#1225` `#1235` `#1268` `#1278` `#1313` `#1328`
- Optimize Texture in Trace nad Optimize `#1181` `#1184` `#1193` `#1215` `#1225` `#1235` `#1268` `#1278` `#1313` `#1328` `#1338` `#1334` `#1346`
- Avatar Optimizer will pack texture and tries to reduce the VRAM usage.
- Currently liltoon is only supported.
- `Copy Enablement Animation` to Merge Skinned Mesh `#1173`
Expand Down Expand Up @@ -55,7 +55,7 @@ The format is based on [Keep a Changelog].
- AAO 1.8.0 introduced BlendShape support for Merge Skinned Mesh, but new default mode "Rename to avoid conflicts" would increase number of BlendShape.
- This feature is added to relax this problem by automatically merging multiple BlendShapes of one Mesh.
- With this feature, you can use rename mode without performance loss.
- Fix mode for PhysBone Limits in Merge PhysBone `#665`
- Fix mode for PhysBone Limits in Merge PhysBone `#665` `#1336` `#1345`
- In addition to existing `Copy` and `Override`, we added `Fix` mode.
- This mode will try to correct roll axis by rotating bone.
- This feature allows you to configure the mode for PhysBone Limits in Merge PhysBone.
Expand All @@ -82,7 +82,7 @@ The format is based on [Keep a Changelog].
- Reimplement Preview system with NDMF Preview System `#1131` `#1195` `#1218` `#1270`
- This will prevent issues relates to Animation Mode bug.
- This allows you to preview Remove Mesh components without selecting Mesh OR while in Animation Mode.
- Improved Prefab Safe Set, which are used in MergePhysBone, MergeSkinnedMesh, FreezeBlendShape and more components `#1212` `#1219` `#1221` `#1236` `#1287` `#1294`
- Improved Prefab Safe Set, which are used in MergePhysBone, MergeSkinnedMesh, FreezeBlendShape and more components `#1212` `#1219` `#1221` `#1236` `#1287` `#1294` `#1348`
- This should improve compatibility with replacing base prefab, which is added in Unity 2022.
- Allow multiple component for Remove Mesh components with API `#1216` `#1218`
- This allows non-destructive tools to add Remove Mesh components even if Remove Mesh component are added before.
Expand All @@ -91,7 +91,7 @@ The format is based on [Keep a Changelog].
- Renamed debug options internally `#1228`
- This will lose previously configured debug options.
- However, debug options are not considered as Public API as stated in documents so this is not backward incompatible changes in semver 2.0.0 section 8.
- Performance Improvements `#1234` `#1243` `#1240` `#1288` `#1304` `#1307` `#1314` `#1325` `#1327`
- Performance Improvements `#1234` `#1243` `#1240` `#1288` `#1304` `#1307` `#1314` `#1325` `#1327` `#1326` `#1341`
- Transform gizmo are now hidden while you're editing box of Remove Mesh in Box `#1259`
- This prevents mistakenly moving the Skinned Mesh Renderer while editing the box.
- Make MergePhysBone implement `INetworkID` `#1260`
Expand Down
61 changes: 61 additions & 0 deletions Editor/APIInternal/ShaderInformation.Standard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Anatawa12.AvatarOptimizer.API;
using UnityEditor;
using UnityEngine;

namespace Anatawa12.AvatarOptimizer.APIInternal;

// Unity builtin "Standard" shader
// https://github.com/TwoTailsGames/Unity-Built-in-Shaders/blob/master/DefaultResourcesExtra/Standard.shader
[InitializeOnLoad]
class StandardShaderInformation : ShaderInformation
{
static StandardShaderInformation()
{
Register();
}

private static void Register()
{
var information = new StandardShaderInformation();
if (!GlobalObjectId.TryParse("GlobalObjectId_V1-4-0000000000000000f000000000000000-46-0", out var id)) return;
var shader = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(id) as Shader;
if (shader == null) return;
ShaderInformationRegistry.RegisterShaderInformation(shader, information);
}

public override ShaderInformationKind SupportedInformationKind =>
ShaderInformationKind.VertexIndexUsage | ShaderInformationKind.TextureAndUVUsage;
public override void GetMaterialInformation(MaterialInformationCallback matInfo)
{
var mainTexST = matInfo.GetVector("_MainTex_ST");
Matrix2x3? mainTexSTMat = mainTexST is { } st ? Matrix2x3.NewScaleOffset(st) : null;
var mainTexSTMatParallex = mainTexSTMat;
if (matInfo.IsShaderKeywordEnabled("_PARALLAXMAP") != false)
mainTexSTMat = null;

matInfo.RegisterTextureUVUsage("_ParallaxMap", "_ParallaxMap", UsingUVChannels.UV0, mainTexSTMatParallex);

matInfo.RegisterTextureUVUsage("_MainTex", "_MainTex", UsingUVChannels.UV0, mainTexSTMat);
matInfo.RegisterTextureUVUsage("_MetallicGlossMap", "_MetallicGlossMap", UsingUVChannels.UV0, mainTexSTMat);
matInfo.RegisterTextureUVUsage("_BumpMap", "_BumpMap", UsingUVChannels.UV0, mainTexSTMat);
matInfo.RegisterTextureUVUsage("_OcclusionMap", "_OcclusionMap", UsingUVChannels.UV0, mainTexSTMat);
matInfo.RegisterTextureUVUsage("_EmissionMap", "_EmissionMap", UsingUVChannels.UV0, mainTexSTMat);
matInfo.RegisterTextureUVUsage("_DetailMask", "_DetailMask", UsingUVChannels.UV0, mainTexSTMat);

var detailMapST = matInfo.GetVector("_DetailAlbedoMap_ST");
Matrix2x3? detailMapSTMat = detailMapST is { } st2 ? Matrix2x3.NewScaleOffset(st2) : null;

if (matInfo.IsShaderKeywordEnabled("_PARALLAXMAP") != false)
detailMapSTMat = null;

var detailMapUV = matInfo.GetFloat("_UVSec") switch
{
null => UsingUVChannels.UV0 | UsingUVChannels.UV1,
0 => UsingUVChannels.UV0,
_ => UsingUVChannels.UV1,
};

matInfo.RegisterTextureUVUsage("_DetailAlbedoMap", "_DetailAlbedoMap", detailMapUV, detailMapSTMat);
matInfo.RegisterTextureUVUsage("_DetailNormalMap", "_DetailNormalMap", detailMapUV, detailMapSTMat);
}
}
3 changes: 3 additions & 0 deletions Editor/APIInternal/ShaderInformation.Standard.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions Editor/APIInternal/ShaderInformation.VRCSDK.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Anatawa12.AvatarOptimizer.API;
using UnityEditor;
using UnityEngine;

namespace Anatawa12.AvatarOptimizer.APIInternal;

// VRChat SDK Mobile Shaders

[InitializeOnLoad]
class VRCSDKStandardLiteShaderInformation : ShaderInformation
{
static VRCSDKStandardLiteShaderInformation()
{
Register();
}

private static void Register()
{
var information = new VRCSDKStandardLiteShaderInformation();
ShaderInformationRegistry.RegisterShaderInformationWithGUID("0b7113dea2069fc4e8943843eff19f70", information);
}

public override ShaderInformationKind SupportedInformationKind =>
ShaderInformationKind.VertexIndexUsage | ShaderInformationKind.TextureAndUVUsage;
public override void GetMaterialInformation(MaterialInformationCallback matInfo)
{
var mainTexST = matInfo.GetVector("_MainTex_ST");
Matrix2x3? mainTexSTMat = mainTexST is { } st ? Matrix2x3.NewScaleOffset(st) : null;

matInfo.RegisterTextureUVUsage("_MetallicGlossMap", "_MetallicGlossMap", UsingUVChannels.UV0, mainTexSTMat);
matInfo.RegisterTextureUVUsage("_MainTex", "_MainTex", UsingUVChannels.UV0, mainTexSTMat);
matInfo.RegisterTextureUVUsage("_BumpMap", "_BumpMap", UsingUVChannels.UV0, mainTexSTMat);
matInfo.RegisterTextureUVUsage("_OcclusionMap", "_OcclusionMap", UsingUVChannels.UV0, mainTexSTMat);
matInfo.RegisterTextureUVUsage("_EmissionMap", "_EmissionMap", UsingUVChannels.UV0, mainTexSTMat);
matInfo.RegisterTextureUVUsage("_DetailMask", "_DetailMask", UsingUVChannels.UV0, mainTexSTMat);

var detailMapST = matInfo.GetVector("_DetailAlbedoMap_ST");
Matrix2x3? detailMapSTMat = detailMapST is { } st2 ? Matrix2x3.NewScaleOffset(st2) : null;
matInfo.RegisterTextureUVUsage("_DetailAlbedoMap", "_DetailAlbedoMap", UsingUVChannels.UV0, mainTexSTMat);

var detailMapUV = matInfo.GetFloat("_UVSec") switch
{
null => UsingUVChannels.UV0 | UsingUVChannels.UV1,
0 => UsingUVChannels.UV0,
_ => UsingUVChannels.UV1,
};

matInfo.RegisterTextureUVUsage("_DetailAlbedoMap", "_DetailAlbedoMap", detailMapUV, detailMapSTMat);
matInfo.RegisterTextureUVUsage("_DetailNormalMap", "_DetailNormalMap", detailMapUV, detailMapSTMat);
}
}

[InitializeOnLoad]
class VRCSDKToonLitShaderInformation : ShaderInformation
{
static VRCSDKToonLitShaderInformation()
{
Register();
}

private static void Register()
{
var information = new VRCSDKToonLitShaderInformation();
ShaderInformationRegistry.RegisterShaderInformationWithGUID("affc81f3d164d734d8f13053effb1c5c", information);
}

public override ShaderInformationKind SupportedInformationKind =>
ShaderInformationKind.VertexIndexUsage | ShaderInformationKind.TextureAndUVUsage;
public override void GetMaterialInformation(MaterialInformationCallback matInfo)
{
var mainTexST = matInfo.GetVector("_MainTex_ST");
Matrix2x3? mainTexSTMat = mainTexST is { } st ? Matrix2x3.NewScaleOffset(st) : null;
matInfo.RegisterTextureUVUsage("_MainTex", "_MainTex", UsingUVChannels.UV0, mainTexSTMat);
}
}
3 changes: 3 additions & 0 deletions Editor/APIInternal/ShaderInformation.VRCSDK.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions Editor/ObjectMapping/ObjectMappingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,17 @@ public void FixAnimatorController(AnimatorController? controller)
foreach (var layer in layers)
{
FixAvatarMask(layer.avatarMask);
foreach (var animatorState in ACUtils.AllStates(layer.stateMachine))
animatorState.motion = MapMotion(animatorState.motion);
if (layer.syncedLayerIndex != -1)
{
foreach (var animatorState in ACUtils.AllStates(layers[layer.syncedLayerIndex].stateMachine))
if (layer.GetOverrideMotion(animatorState) is {} motion)
layer.SetOverrideMotion(animatorState, motion);
}
else
{
foreach (var animatorState in ACUtils.AllStates(layer.stateMachine))
animatorState.motion = MapMotion(animatorState.motion);
}
}
controller.layers = layers;
foreach (var stateMachineBehaviour in ACUtils.StateMachineBehaviours(controller))
Expand Down
42 changes: 34 additions & 8 deletions Editor/Processors/MergePhysBoneProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,39 @@ internal static void DoMerge(MergePhysBone merge, BuildContext? context)
// yaw / pitch fix
if (merge.limitRotationConfig.@override == MergePhysBone.CurveVector3Config.CurveOverride.Fix)
{
var newIgnores = new List<Transform>();
if (context != null)
{
var animations = new HashSet<ObjectReference>();
foreach (var physBone in sourceComponents)
foreach (var affectedTransform in physBone.GetAffectedTransforms())
{
var component = context.GetAnimationComponent(affectedTransform);
foreach (var property in TransformRotationAndPositionAnimationKeys)
{
var node = component.GetFloatNode(property);
animations.UnionWith(node.ComponentNodes.OfType<AnimatorPropModNode<FloatValueInfo>>()
.SelectMany(x => x.ContextReferences));
}
}

if (animations.Count != 0)
{
BuildLog.LogWarning("MergePhysBone:warning:limit-rotation-fix-animation", animations);
}
}

var originalBones = new List<Transform>();
// fix rotations
foreach (var physBone in sourceComponents)
FixYawPitch(physBone, root, context, newIgnores);
FixYawPitch(physBone, root, context, originalBones);

if (originalBones.Any(x => x.GetComponent<MergeBone>()))
{
BuildLog.LogError("MergePhysBone:error:limit-rotation-fix-merge-bone");
}

// fix configurations
merged.ignoreTransforms = merged.ignoreTransforms.Concat(newIgnores).ToList();
merged.ignoreTransforms = merged.ignoreTransforms.Concat(originalBones).ToList();

var sourceComponent = sourceComponents[0];
var chainLength = sourceComponent.BoneChainLength();
Expand Down Expand Up @@ -215,7 +241,7 @@ public static void FixYawPitch(
VRCPhysBoneBase physBone,
Transform root,
BuildContext? context,
List<Transform> newIgnores)
List<Transform> originalBones)
{
// Already fixed; nothing to do!
if (physBone.limitRotation.Equals(Vector3.zero)) return;
Expand All @@ -225,7 +251,7 @@ public static void FixYawPitch(

var ignoreTransforms = new HashSet<Transform>(physBone.ignoreTransforms);

RotateRecursive(physBone, physBone.GetTarget(), root, maxChainLength, 0, ignoreTransforms, newIgnores);
RotateRecursive(physBone, physBone.GetTarget(), root, maxChainLength, 0, ignoreTransforms, originalBones);
}

/*
Expand Down Expand Up @@ -272,7 +298,7 @@ private static void RotateRecursive(VRCPhysBoneBase physBone,
int totalDepth,
int depth,
HashSet<Transform> ignoreTransforms,
List<Transform> newIgnores)
List<Transform> originalBones)
{
Vector3 targetLocation;

Expand Down Expand Up @@ -344,7 +370,7 @@ private static void RotateRecursive(VRCPhysBoneBase physBone,
// move old bone to child of newBone
transform.SetParent(newBone.transform, true);

newIgnores.Add(transform);
originalBones.Add(transform);

//var rotationQuaternion = Quaternion.Euler(0, -thisRotation, 0);

Expand All @@ -354,7 +380,7 @@ private static void RotateRecursive(VRCPhysBoneBase physBone,
//child.localRotation = rotationQuaternion * child.localRotation;

if (ignoreTransforms.Contains(child)) continue;
RotateRecursive(physBone, child, newBone.transform, totalDepth, depth + 1, ignoreTransforms, newIgnores);
RotateRecursive(physBone, child, newBone.transform, totalDepth, depth + 1, ignoreTransforms, originalBones);
}
}

Expand Down
Loading

0 comments on commit 3248160

Please sign in to comment.