fix for EXT-4632: LLViewerMediaTexture::getMaxVirtualSize() sometimes returns bad values.

meow-7.2.2
Xiaohong Bao 2010-02-10 18:08:00 -08:00
parent fd4aee8f83
commit 60cb3f8fd2
3 changed files with 58 additions and 11 deletions

View File

@ -1327,6 +1327,21 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
return TRUE;
}
//check if the face has a media
BOOL LLFace::hasMedia() const
{
if(mHasMedia)
{
return TRUE ;
}
if(mTexture.notNull())
{
return mTexture->hasParcelMedia() ; //if has a parcel media
}
return FALSE ; //no media.
}
const F32 LEAST_IMPORTANCE = 0.05f ;
const F32 LEAST_IMPORTANCE_FOR_LARGE_IMAGE = 0.3f ;
@ -1336,7 +1351,7 @@ F32 LLFace::getTextureVirtualSize()
F32 cos_angle_to_view_dir;
mPixelArea = calcPixelArea(cos_angle_to_view_dir, radius);
if (mPixelArea <= 0)
if (mPixelArea < 0.0001f)
{
return 0.f;
}
@ -1381,14 +1396,38 @@ F32 LLFace::calcPixelArea(F32& cos_angle_to_view_dir, F32& radius)
{
//get area of circle around face
LLVector3 center = getPositionAgent();
LLVector3 size = (mExtents[1] - mExtents[0]) * 0.5f;
LLVector3 size = (mExtents[1] - mExtents[0]) * 0.5f;
LLViewerCamera* camera = LLViewerCamera::getInstance();
//if has media, check if the face is out of the view frustum.
BOOL has_media = hasMedia() ;
if(has_media && !camera->AABBInFrustum(center, size))
{
mImportanceToCamera = 0.f ;
return 0.f ;
}
F32 size_squared = size.lengthSquared() ;
LLVector3 lookAt = center - camera->getOrigin();
F32 dist = lookAt.normVec() ;
cos_angle_to_view_dir = lookAt * camera->getXAxis() ;
if(has_media)
{
if(cos_angle_to_view_dir > camera->getCosHalfFov()) //the center is within the view frustum
{
cos_angle_to_view_dir = 1.0f ;
}
else
{
if(dist * dist * (lookAt - camera->getXAxis()).lengthSquared() < size_squared)
{
cos_angle_to_view_dir = 1.0f ;
}
}
}
//get area of circle around node
F32 app_angle = atanf(size.length()/dist);
F32 app_angle = atanf(fsqrtf(size_squared) / dist);
radius = app_angle*LLDrawable::sCurPixelAngle;
F32 face_area = radius*radius * 3.14159f;
@ -1398,8 +1437,7 @@ F32 LLFace::calcPixelArea(F32& cos_angle_to_view_dir, F32& radius)
mImportanceToCamera = 1.0f ;
}
else
{
cos_angle_to_view_dir = lookAt * camera->getXAxis() ;
{
mImportanceToCamera = LLFace::calcImportanceToCamera(cos_angle_to_view_dir, dist) ;
}

View File

@ -194,6 +194,9 @@ public:
F32 getTextureVirtualSize() ;
F32 getImportanceToCamera()const {return mImportanceToCamera ;}
void setHasMedia(bool has_media) { mHasMedia = has_media ;}
BOOL hasMedia() const ;
//for atlas
LLTextureAtlasSlot* getAtlasInfo() ;
void setAtlasInUse(BOOL flag);
@ -262,7 +265,7 @@ private:
//based on the distance from the face to the view point and the angle from the face center to the view direction.
F32 mImportanceToCamera ;
F32 mBoundingSphereRadius ;
bool mHasMedia ;
//atlas
LLPointer<LLTextureAtlasSlot> mAtlasInfop ;

View File

@ -2995,6 +2995,10 @@ void LLViewerMediaTexture::initVirtualSize()
void LLViewerMediaTexture::addMediaToFace(LLFace* facep)
{
if(facep)
{
facep->setHasMedia(true) ;
}
if(!mIsPlaying)
{
return ; //no need to add the face because the media is not in playing.
@ -3005,14 +3009,16 @@ void LLViewerMediaTexture::addMediaToFace(LLFace* facep)
void LLViewerMediaTexture::removeMediaFromFace(LLFace* facep)
{
if(!mIsPlaying)
{
return ; //no need to remove the face because the media is not in playing.
}
if(!facep)
{
return ;
}
facep->setHasMedia(false) ;
if(!mIsPlaying)
{
return ; //no need to remove the face because the media is not in playing.
}
mIsPlaying = FALSE ; //set to remove the media from the face.
switchTexture(facep) ;