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

CMCL-1574: zero member targetgroup behaves better #954

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.cinemachine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreeleased] - 2024-01-02
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## [Unreeleased] - 2024-01-02
## [2.11.0] - 2024-01-02

To fix the tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done

- Bugfix: Solo not updating when brain is in FixedUpdate.
- Bugfix: Target Groups with zero active members now report their last valid position and dimensions.


## [2.10.0] - 2024-01-01
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ public void DoUpdate()

UpdateMemberValidity();
m_AveragePos = CalculateAveragePosition(out m_MaxWeight);
BoundingBox = CalculateBoundingBox();

BoundingBox = CalculateBoundingBox(m_MaxWeight);
m_BoundingSphere = CalculateBoundingSphere(m_MaxWeight);

switch (m_PositionMode)
Expand Down Expand Up @@ -364,7 +365,7 @@ void UpdateMemberValidity()
for (int i = 0; i < count; ++i)
{
m_MemberValidity.Add(m_Targets[i].target != null
&& m_Targets[i].weight > UnityVectorExtensions.Epsilon
&& m_Targets[i].weight > UnityVectorExtensions.Epsilon
&& m_Targets[i].target.gameObject.activeInHierarchy);
if (m_MemberValidity[i])
m_ValidMembers.Add(i);
Expand Down Expand Up @@ -394,17 +395,16 @@ Vector3 CalculateAveragePosition(out float maxWeight)
}

// Assumes that CalculateAveragePosition() has been called
Bounds CalculateBoundingBox()
Bounds CalculateBoundingBox(float maxWeight)
{
if (maxWeight < UnityVectorExtensions.Epsilon)
return BoundingBox;
var b = new Bounds(m_AveragePos, Vector3.zero);
if (m_MaxWeight > UnityVectorExtensions.Epsilon)
var count = m_ValidMembers.Count;
for (int i = 0; i < count; ++i)
{
var count = m_ValidMembers.Count;
for (int i = 0; i < count; ++i)
{
var s = WeightedMemberBoundsForValidMember(ref m_Targets[m_ValidMembers[i]], m_AveragePos, m_MaxWeight);
b.Encapsulate(new Bounds(s.position, s.radius * 2 * Vector3.one));
}
var s = WeightedMemberBoundsForValidMember(ref m_Targets[m_ValidMembers[i]], m_AveragePos, m_MaxWeight);
b.Encapsulate(new Bounds(s.position, s.radius * 2 * Vector3.one));
}
return b;
}
Expand All @@ -417,19 +417,14 @@ Bounds CalculateBoundingBox()
/// <returns>An approximate bounding sphere. Will be slightly large.</returns>
BoundingSphere CalculateBoundingSphere(float maxWeight)
{
var sphere = new BoundingSphere { position = transform.position };
bool gotOne = false;

var count = m_ValidMembers.Count;
for (int i = 0; i < count; ++i)
if (count == 0 || maxWeight < UnityVectorExtensions.Epsilon)
return m_BoundingSphere;

var sphere = WeightedMemberBoundsForValidMember(ref m_Targets[m_ValidMembers[0]], m_AveragePos, maxWeight);
for (int i = 1; i < count; ++i)
{
var s = WeightedMemberBoundsForValidMember(ref m_Targets[m_ValidMembers[i]], m_AveragePos, maxWeight);
if (!gotOne)
{
gotOne = true;
sphere = s;
continue;
}
var distance = (s.position - sphere.position).magnitude + s.radius;
if (distance > sphere.radius)
{
Expand Down Expand Up @@ -499,8 +494,9 @@ void LateUpdate()
if (!Matrix4x4.Inverse3DAffine(observer, ref world2local))
world2local = observer.inverse;

zRange = Vector2.zero;
var b = new Bounds();
var r = m_BoundingSphere.radius;
var b = new Bounds() { center = world2local.MultiplyPoint3x4(m_AveragePos), extents = new Vector3(r, r, r) };
zRange = new Vector2(b.center.z - r, b.center.z + r);
if (CachedCountIsValid)
{
bool haveOne = false;
Expand Down

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