Skip to content

Commit

Permalink
fix culling group bugs
Browse files Browse the repository at this point in the history
1. fix bug: the instance's bounding sphere doesn't update when it's not in camera view
2. fix bug: the instance doesn't initialize the visibility
  • Loading branch information
CloudJin committed May 18, 2018
1 parent 94389d5 commit f6e1326
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Assets/AniInstancing/Scripts/AnimationInstancing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void Start()
}
visible = true;
CalcBoundingSphere();
AnimationInstancingMgr.Instance.AddBoundingSphere(boundingSpere);
AnimationInstancingMgr.Instance.AddBoundingSphere(this);
AnimationInstancingMgr.Instance.AddInstance(gameObject);
}

Expand Down
19 changes: 9 additions & 10 deletions Assets/AniInstancing/Scripts/AnimationInstancingMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,15 @@ void ApplyBoneMatrix()
if (instance.aniIndex < 0 && instance.parentInstance == null)
continue;

if (instance.applyRootMotion)
ApplyRootMotion(instance);

instance.UpdateAnimation();
instance.boundingSpere.position = instance.transform.position;
boundingSphere[i] = instance.boundingSpere;

if (!instance.visible)
continue;

if (instance.applyRootMotion)
ApplyRootMotion(instance);
instance.UpdateLod(cameraPosition);

AnimationInstancing.LodInfo lod = instance.lodInfo[instance.lodLevel];
Expand Down Expand Up @@ -421,11 +424,6 @@ void ApplyBoneMatrix()
frameIndex = instance.aniInfo[instance.aniIndex].animationIndex + instance.curFrame;

data.frameIndex[aniTextureIndex][index][count] = frameIndex;

instance.boundingSpere.position.x = worldMat.m03;
instance.boundingSpere.position.y = worldMat.m13;
instance.boundingSpere.position.z = worldMat.m23;
boundingSphere[i] = instance.boundingSpere;
}


Expand Down Expand Up @@ -1043,10 +1041,11 @@ private void SetupVertexCache(VertexCache vertexCache,
}


public void AddBoundingSphere(BoundingSphere sphere)
public void AddBoundingSphere(AnimationInstancing instance)
{
boundingSphere[usedBoundingSphereCount++] = sphere;
boundingSphere[usedBoundingSphereCount++] = instance.boundingSpere;
cullingGroup.SetBoundingSphereCount(usedBoundingSphereCount);
instance.visible = cullingGroup.IsVisible(usedBoundingSphereCount - 1);
}


Expand Down

0 comments on commit f6e1326

Please sign in to comment.