use geometric center and not sog root position in culling

LSLKeyTest
UbitUmarov 2016-07-13 22:29:09 +01:00
parent e0a1025497
commit 00687d5b0f
2 changed files with 25 additions and 17 deletions

View File

@ -4115,12 +4115,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if(!inview) if(!inview)
{ {
Vector3 partpos = grp.AbsolutePosition; float bradius = grp.GetBoundsRadius(); // needs to be called before getBoundsCenter
Vector3 partpos = grp.AbsolutePosition + grp.getBoundsCenter();
// float dcam = (partpos - mycamera).LengthSquared(); // float dcam = (partpos - mycamera).LengthSquared();
float dpos = (partpos - mypos).LengthSquared(); float dpos = (partpos - mypos).LengthSquared();
// if(dcam < dpos) // if(dcam < dpos)
// dpos = dcam; // dpos = dcam;
dpos = (float)Math.Sqrt(dpos) - grp.GetBoundsRadius(); dpos = (float)Math.Sqrt(dpos) - bradius;
if(dpos > cullingrange) if(dpos > cullingrange)
continue; continue;
@ -4418,13 +4419,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if(grp.IsDeleted || grp.IsAttachment) if(grp.IsDeleted || grp.IsAttachment)
continue; continue;
Vector3 grppos = grp.AbsolutePosition; float bradius = grp.GetBoundsRadius(); // needs to be called before getBoundsCenter
Vector3 grppos = grp.AbsolutePosition + grp.getBoundsCenter();
// float dcam = (grppos - mycamera).LengthSquared(); // float dcam = (grppos - mycamera).LengthSquared();
float dpos = (grppos - mypos).LengthSquared(); float dpos = (grppos - mypos).LengthSquared();
// if(dcam < dpos) // if(dcam < dpos)
// dpos = dcam; // dpos = dcam;
dpos = (float)Math.Sqrt(dpos) - grp.GetBoundsRadius(); dpos = (float)Math.Sqrt(dpos) - bradius;
bool inview; bool inview;
lock(GroupsInView) lock(GroupsInView)

View File

@ -1573,6 +1573,12 @@ namespace OpenSim.Region.Framework.Scenes
m_boundsRadius = null; m_boundsRadius = null;
} }
private Vector3 m_boundsCenter;
public Vector3 getBoundsCenter()
{
// this needs to be called after GetBoundsRadius() so its updated
return m_boundsCenter;
}
public float GetBoundsRadius() public float GetBoundsRadius()
{ {
// this may need more threading work // this may need more threading work
@ -1582,6 +1588,7 @@ namespace OpenSim.Region.Framework.Scenes
SceneObjectPart p; SceneObjectPart p;
SceneObjectPart[] parts; SceneObjectPart[] parts;
float partR; float partR;
Vector3 offset = Vector3.Zero;
lock (m_parts) lock (m_parts)
{ {
parts = m_parts.GetArray(); parts = m_parts.GetArray();
@ -1593,10 +1600,19 @@ namespace OpenSim.Region.Framework.Scenes
p = parts[i]; p = parts[i];
partR = 0.5f * p.Scale.Length(); partR = 0.5f * p.Scale.Length();
if(p != RootPart) if(p != RootPart)
{
partR += p.OffsetPosition.Length(); partR += p.OffsetPosition.Length();
offset += p.OffsetPosition;
}
if(partR > res) if(partR > res)
res = partR; res = partR;
} }
if(parts.Length > 1)
{
offset /= parts.Length; // basicly geometric center
offset = offset * RootPart.RotationOffset;
}
m_boundsCenter = offset;
m_boundsRadius = res; m_boundsRadius = res;
return res; return res;
} }
@ -4646,26 +4662,16 @@ namespace OpenSim.Region.Framework.Scenes
Vector3 gc = Vector3.Zero; Vector3 gc = Vector3.Zero;
int nparts = m_parts.Count;
if (nparts <= 1)
return gc;
SceneObjectPart[] parts = m_parts.GetArray(); SceneObjectPart[] parts = m_parts.GetArray();
nparts = parts.Length; // just in case it changed int nparts = parts.Length;
if (nparts <= 1) if (nparts < 2)
return gc; return gc;
Vector3 pPos;
// average all parts positions // average all parts positions
for (int i = 0; i < nparts; i++) for (int i = 0; i < nparts; i++)
{ {
if (parts[i] != RootPart) if (parts[i] != RootPart)
{ gc += parts[i].OffsetPosition;
pPos = parts[i].OffsetPosition;
gc += pPos;
}
} }
gc /= nparts; gc /= nparts;