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