Skip to content

Commit

Permalink
Merge branch 'master-1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Oct 17, 2023
2 parents c702efd + 012d264 commit 9935ce3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ The format is based on [Keep a Changelog].

### Security

## [1.5.6-rc.1] - 2023-10-17
### Removed
- Error for Read/Write Mesh off Mesh [`#615`](https://github.com/anatawa12/AvatarOptimizer/pull/615)
- Since AAO creates Mesh every time, no more error is required!

### Fixed
- BindPose Optimization may break mesh with scale 0 bone [`#612`](https://github.com/anatawa12/AvatarOptimizer/pull/612)
- Error from Preview System when opening inspector of GameObject without SkinnedMeshRenderer [`#613`](https://github.com/anatawa12/AvatarOptimizer/pull/613)

## [1.5.6-beta.2] - 2023-10-16
### Changed
- Make no-op as possible if no AAO component attached for your avatar [`#603`](https://github.com/anatawa12/AvatarOptimizer/pull/603)
Expand Down Expand Up @@ -911,7 +920,8 @@ This release is mistake.
- Merge Bone
- Clear Endpoint Position

[Unreleased]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.6-beta.2...HEAD
[Unreleased]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.6-rc.1...HEAD
[1.5.6-rc.1]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.6-beta.2...v1.5.6-rc.1
[1.5.6-beta.2]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.6-beta.1...v1.5.6-beta.2
[1.5.6-beta.1]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.5...v1.5.6-beta.1
[1.5.5]: https://github.com/anatawa12/AvatarOptimizer/compare/v1.5.5-rc.1...v1.5.5
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ The format is based on [Keep a Changelog].
### Deprecated

### Removed
- Error for Read/Write Mesh off Mesh `#615`
- Since AAO creates Mesh every time, no more error is required!

### Fixed
- Multi-frame BlendShape can be broken `#601`
- Update notice may show incorrect version `#602`
- `Preview` button is not disabled even if mesh is none `#605`
- BindPose Optimization may break mesh with scale 0 bone `#612`

### Security

Expand Down
1 change: 1 addition & 0 deletions Editor/EditModePreview/MeshPreviewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private void Update()
{
var editorObj = ActiveEditor();
if (editorObj is GameObject go &&
go.GetComponent<SkinnedMeshRenderer>() &&
go.GetComponent<SkinnedMeshRenderer>().sharedMesh &&
RemoveMeshPreviewController.EditorTypes.Any(t => go.GetComponent(t)))
{
Expand Down
4 changes: 4 additions & 0 deletions Editor/Math/Matrix3x3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ struct Matrix3x3 : IEquatable<Matrix3x3>
public static Matrix3x3 zero = new Matrix3x3(0, 0, 0, 0, 0, 0, 0, 0, 0);
public static Matrix3x3 identity = new Matrix3x3(1, 0, 0, 0, 1, 0, 0, 0, 1);

public float determinant =>
(m00 * m11 * m22) + (m01 * m12 * m20) + (m02 * m10 * m21)
- (m00 * m12 * m21) - (m01 * m10 * m22) - (m02 * m11 * m20);

// @formatter:off
public float m00;
public float m10;
Expand Down
27 changes: 25 additions & 2 deletions Editor/Processors/MergeBoneProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void DoBoneMap2(MeshInfo2 meshInfo2, Dictionary<Transform, Transform> me
else
{
// we assume fist bone we find is the most natural bone.
if (!primaryBones.ContainsKey(bone.Transform))
if (!primaryBones.ContainsKey(bone.Transform) && ValidBindPose(bone.Bindpose))
primaryBones.Add(bone.Transform, bone);
}
}
Expand Down Expand Up @@ -162,7 +162,7 @@ private void DoBoneMap2(MeshInfo2 meshInfo2, Dictionary<Transform, Transform> me
vertex.Tangent = new Vector4(tangentVec3.x, tangentVec3.y, tangentVec3.z, vertex.Tangent.w);
foreach (var frames in vertex.BlendShapes.Values)
{
for (var i = 0; i < frames.Length; i++)
for (var i = 0; i < frames.Length; i++)
{
var frame = frames[i];
frames[i] = new Vertex.BlendShapeFrame(
Expand Down Expand Up @@ -205,6 +205,29 @@ private void DoBoneMap2(MeshInfo2 meshInfo2, Dictionary<Transform, Transform> me
}
}

private bool ValidBindPose(Matrix4x4 matrix)
{
const float SMALL = 0.001f;
const float BIG = 10000;

// if scaling part of bindpose is too small or too big, it can lead to invalid bind pose optimization
var scaling = Mathf.Abs(new Matrix3x3(matrix).determinant);

if (float.IsInfinity(scaling)) return false;
if (float.IsNaN(scaling)) return false;
if (scaling < SMALL) return false;
if (scaling > BIG) return false;

// if offset part of bindpose is too big, it may lead to invalid bind pose optimization

var offset = matrix.offset;
if (Mathf.Abs(offset.x) > BIG) return false;
if (Mathf.Abs(offset.y) > BIG) return false;
if (Mathf.Abs(offset.z) > BIG) return false;

return true;
}

private readonly struct BoneUniqKey : IEquatable<BoneUniqKey>
{
private readonly Matrix4x4 _bindPoseInfo;
Expand Down
10 changes: 0 additions & 10 deletions Editor/Processors/SkinnedMeshes/MeshInfo2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public MeshInfo2(SkinnedMeshRenderer renderer)
{
SourceRenderer = renderer;
var mesh = renderer.sharedMesh;
if (mesh && !mesh.isReadable)
{
BuildReport.LogFatal("The Mesh is not readable. Please Check Read/Write")?.WithContext(mesh);
return;
}

BuildReport.ReportingObject(renderer, true, () =>
{
Expand Down Expand Up @@ -80,11 +75,6 @@ public MeshInfo2(MeshRenderer renderer)
{
var meshFilter = renderer.GetComponent<MeshFilter>();
var mesh = meshFilter ? meshFilter.sharedMesh : null;
if (mesh && !mesh.isReadable)
{
BuildReport.LogFatal("The Mesh is not readable. Please Check Read/Write")?.WithContext(mesh);
return;
}
if (mesh)
ReadStaticMesh(mesh);

Expand Down

0 comments on commit 9935ce3

Please sign in to comment.