private double GetPriorityByOOBDistance(IScenePresence presence, IEntity entity) { // If this is an update for our own avatar give it the highest priority if (presence == entity) { return(0.0); } // Use the camera position for local agents and avatar position for remote agents Vector3 presencePos = (presence.IsChildAgent) ? presence.AbsolutePosition : presence.CameraPosition; // Use group position for child prims Vector3 entityPos; float distsq; if (entity is SceneObjectGroup) { SceneObjectGroup g = (SceneObjectGroup)entity; entityPos = g.AbsolutePosition; distsq = Vector3.DistanceSquared(presencePos, entityPos); if (g.IsAttachment) { return(0.0); } } else if (entity is SceneObjectPart) { SceneObjectPart p = (SceneObjectPart)entity; if (p.IsRoot) { SceneObjectGroup g = p.ParentGroup; entityPos = g.AbsolutePosition; distsq = Vector3.DistanceSquared(presencePos, entityPos); if (g.IsAttachment) { return(0.0); } } else { distsq = p.clampedAABdistanceToSQ(presencePos) + 1.0f; if (p.ParentGroup.RootChild.IsAttachment) { return(1.0); } } } else { entityPos = entity.AbsolutePosition; distsq = Vector3.DistanceSquared(presencePos, entityPos); } return(distsq); }