00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "llvotextbubble.h"
00035
00036 #include "imageids.h"
00037 #include "llviewercontrol.h"
00038 #include "llprimitive.h"
00039 #include "llrendersphere.h"
00040
00041 #include "llagent.h"
00042 #include "llbox.h"
00043 #include "lldrawable.h"
00044 #include "llface.h"
00045 #include "llviewerimagelist.h"
00046 #include "llvolume.h"
00047 #include "pipeline.h"
00048 #include "llviewerregion.h"
00049
00050 LLVOTextBubble::LLVOTextBubble(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
00051 : LLAlphaObject(id, pcode, regionp)
00052 {
00053 setScale(LLVector3(1.5f, 1.5f, 0.25f));
00054 mbCanSelect = FALSE;
00055 mLOD = MIN_LOD;
00056 mVolumeChanged = TRUE;
00057 setVelocity(LLVector3(0.f, 0.f, 0.75f));
00058 LLVolumeParams volume_params;
00059 volume_params.setType(LL_PCODE_PROFILE_CIRCLE, LL_PCODE_PATH_LINE);
00060 volume_params.setBeginAndEndS(0.f, 1.f);
00061 volume_params.setBeginAndEndT(0.f, 1.f);
00062 volume_params.setRatio(0.25f, 0.25f);
00063 volume_params.setShear(0.f, 0.f);
00064 setVolume(volume_params, 0);
00065 mColor = LLColor4(1.0f, 0.0f, 0.0f, 1.f);
00066 S32 i;
00067 for (i = 0; i < getNumTEs(); i++)
00068 {
00069 setTEColor(i, mColor);
00070 setTETexture(i, LLUUID(IMG_DEFAULT));
00071 }
00072 }
00073
00074
00075 LLVOTextBubble::~LLVOTextBubble()
00076 {
00077 }
00078
00079
00080 BOOL LLVOTextBubble::isActive() const
00081 {
00082 return TRUE;
00083 }
00084
00085 BOOL LLVOTextBubble::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time)
00086 {
00087 F32 dt = mUpdateTimer.getElapsedTimeF32();
00088
00089 if (dt > 1.5f)
00090 {
00091 return FALSE;
00092 }
00093
00094 LLViewerObject::idleUpdate(agent, world, time);
00095
00096 setScale(0.5f * (1.f+dt) * LLVector3(1.5f, 1.5f, 0.5f));
00097
00098 F32 alpha = 0.35f*dt;
00099
00100 LLColor4 color = mColor;
00101 color.mV[VALPHA] -= alpha;
00102 if (color.mV[VALPHA] <= 0.05f)
00103 {
00104 return FALSE;
00105 }
00106 S32 i;
00107 for (i = 0; i < getNumTEs(); i++)
00108 {
00109 setTEColor(i, color);
00110 setTEFullbright(i, TRUE);
00111 }
00112
00113 gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE);
00114 return TRUE;
00115 }
00116
00117
00118 void LLVOTextBubble::updateTextures(LLAgent &agent)
00119 {
00120
00121
00122 U32 i;
00123
00124
00125
00126
00127 LLVector3 position_local = getPositionAgent() - agent.getCameraPositionAgent();
00128 F32 dot_product = position_local * agent.getFrameAgent().getAtAxis();
00129 F32 cos_angle = dot_product / position_local.magVec();
00130
00131 if (cos_angle > 1.f)
00132 {
00133 cos_angle = 1.f;
00134 }
00135
00136 for (i = 0; i < getNumTEs(); i++)
00137 {
00138 const LLTextureEntry *te = getTE(i);
00139 F32 texel_area_ratio = fabs(te->mScaleS * te->mScaleT);
00140
00141 LLViewerImage *imagep = getTEImage(i);
00142 if (imagep)
00143 {
00144 imagep->addTextureStats(mPixelArea, texel_area_ratio, cos_angle);
00145 }
00146 }
00147 }
00148
00149
00150 LLDrawable *LLVOTextBubble::createDrawable(LLPipeline *pipeline)
00151 {
00152 pipeline->allocDrawable(this);
00153 mDrawable->setLit(FALSE);
00154 mDrawable->setRenderType(LLPipeline::RENDER_TYPE_VOLUME);
00155
00156 for (U32 i = 0; i < getNumTEs(); i++)
00157 {
00158 LLViewerImage *imagep;
00159 const LLTextureEntry *texture_entry = getTE(i);
00160 imagep = gImageList.getImage(texture_entry->getID());
00161
00162 mDrawable->addFace((LLFacePool*) NULL, imagep);
00163 }
00164
00165 return mDrawable;
00166 }
00167
00168
00169 BOOL LLVOTextBubble::setVolume(const LLVolumeParams &volume_params, const S32 detail, bool unique_volume)
00170 {
00171 if (LLPrimitive::setVolume(volume_params, mLOD))
00172 {
00173 if (mDrawable)
00174 {
00175 gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME, TRUE);
00176 mVolumeChanged = TRUE;
00177 }
00178 return TRUE;
00179 }
00180 return FALSE;
00181 }
00182
00183
00184 BOOL LLVOTextBubble::updateLOD()
00185 {
00186 return FALSE;
00187 }
00188
00189 BOOL LLVOTextBubble::updateGeometry(LLDrawable *drawable)
00190 {
00191 if (!(gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_VOLUME)))
00192 return TRUE;
00193
00194 if (mVolumeChanged)
00195 {
00196 LLVolumeParams volume_params = getVolume()->getParams();
00197 setVolume(volume_params, 0);
00198
00199 LLPipeline::sCompiles++;
00200
00201 drawable->setNumFaces(getVolume()->getNumFaces(), drawable->getFace(0)->getPool(), getTEImage(0));
00202 }
00203
00204 LLMatrix4 identity4;
00205 LLMatrix3 identity3;
00206 for (S32 i = 0; i < drawable->getNumFaces(); i++)
00207 {
00208 LLFace *face = drawable->getFace(i);
00209 face->setTEOffset(i);
00210 face->setTexture(LLViewerImage::sSmokeImagep);
00211 face->setState(LLFace::FULLBRIGHT);
00212 }
00213
00214 mVolumeChanged = FALSE;
00215
00216 mDrawable->movePartition();
00217 return TRUE;
00218 }
00219
00220 void LLVOTextBubble::updateFaceSize(S32 idx)
00221 {
00222 LLFace* face = mDrawable->getFace(idx);
00223
00224 if (idx == 0 || idx == 2)
00225 {
00226 face->setSize(0,0);
00227 }
00228 else
00229 {
00230 const LLVolumeFace& vol_face = getVolume()->getVolumeFace(idx);
00231 face->setSize(vol_face.mVertices.size(), vol_face.mIndices.size());
00232 }
00233 }
00234
00235 void LLVOTextBubble::getGeometry(S32 idx,
00236 LLStrider<LLVector3>& verticesp,
00237 LLStrider<LLVector3>& normalsp,
00238 LLStrider<LLVector2>& texcoordsp,
00239 LLStrider<LLColor4U>& colorsp,
00240 LLStrider<U16>& indicesp)
00241 {
00242 if (idx == 0 || idx == 2)
00243 {
00244 return;
00245 }
00246
00247 const LLVolumeFace& face = getVolume()->getVolumeFace(idx);
00248
00249 LLVector3 pos = getPositionAgent();
00250 LLColor4U color = LLColor4U(getTE(idx)->getColor());
00251 U32 offset = mDrawable->getFace(idx)->getGeomIndex();
00252
00253 for (U32 i = 0; i < face.mVertices.size(); i++)
00254 {
00255 *verticesp++ = face.mVertices[i].mPosition.scaledVec(getScale()) + pos;
00256 *normalsp++ = face.mVertices[i].mNormal;
00257 *texcoordsp++ = face.mVertices[i].mTexCoord;
00258 *colorsp++ = color;
00259 }
00260
00261 for (U32 i = 0; i < face.mIndices.size(); i++)
00262 {
00263 *indicesp++ = face.mIndices[i] + offset;
00264 }
00265 }
00266
00267 U32 LLVOTextBubble::getPartitionType() const
00268 {
00269 return LLViewerRegion::PARTITION_PARTICLE;
00270 }