PageRenderTime 21ms CodeModel.GetById 2ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lltoolmorph.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 304 lines | 205 code | 43 blank | 56 comment | 17 complexity | 35bc1939678a4baa4a6e886052941ff3 MD5 | raw file
  1/** 
  2 * @file lltoolmorph.cpp
  3 * @brief A tool to manipulate faces..
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29// File includes
 30#include "lltoolmorph.h" 
 31#include "llrender.h"
 32
 33// Library includes
 34#include "llaudioengine.h"
 35#include "llviewercontrol.h"
 36#include "llfontgl.h"
 37#include "sound_ids.h"
 38#include "v3math.h"
 39#include "v3color.h"
 40
 41// Viewer includes
 42#include "llagent.h"
 43#include "lldrawable.h"
 44#include "lldrawpoolavatar.h"
 45#include "llface.h"
 46#include "llmorphview.h"
 47#include "llresmgr.h"
 48#include "llselectmgr.h"
 49#include "llsky.h"
 50#include "lltexlayer.h"
 51#include "lltoolmgr.h"
 52#include "llui.h"
 53#include "llviewercamera.h"
 54#include "llviewertexturelist.h"
 55#include "llviewerobject.h"
 56#include "llviewerwindow.h"
 57#include "llvoavatarself.h"
 58#include "pipeline.h"
 59
 60
 61//static
 62LLVisualParamHint::instance_list_t LLVisualParamHint::sInstances;
 63BOOL LLVisualParamReset::sDirty = FALSE;
 64
 65//-----------------------------------------------------------------------------
 66// LLVisualParamHint()
 67//-----------------------------------------------------------------------------
 68
 69// static
 70LLVisualParamHint::LLVisualParamHint(
 71	S32 pos_x, S32 pos_y,
 72	S32 width, S32 height, 
 73	LLViewerJointMesh *mesh, 
 74	LLViewerVisualParam *param,
 75	LLWearable *wearable,
 76	F32 param_weight,
 77	LLJoint* jointp)
 78	:
 79	LLViewerDynamicTexture(width, height, 3, LLViewerDynamicTexture::ORDER_MIDDLE, TRUE ),
 80	mNeedsUpdate( TRUE ),
 81	mIsVisible( FALSE ),
 82	mJointMesh( mesh ),
 83	mVisualParam( param ),
 84	mWearablePtr( wearable ),
 85	mVisualParamWeight( param_weight ),
 86	mAllowsUpdates( TRUE ),
 87	mDelayFrames( 0 ),
 88	mRect( pos_x, pos_y + height, pos_x + width, pos_y ),
 89	mLastParamWeight(0.f),
 90	mCamTargetJoint(jointp)
 91{
 92	LLVisualParamHint::sInstances.insert( this );
 93	mBackgroundp = LLUI::getUIImage("avatar_thumb_bkgrnd.png");
 94
 95	llassert(width != 0);
 96	llassert(height != 0);
 97}
 98
 99//-----------------------------------------------------------------------------
100// ~LLVisualParamHint()
101//-----------------------------------------------------------------------------
102LLVisualParamHint::~LLVisualParamHint()
103{
104	LLVisualParamHint::sInstances.erase( this );
105}
106
107//virtual
108S8 LLVisualParamHint::getType() const
109{
110	return LLViewerDynamicTexture::LL_VISUAL_PARAM_HINT ;
111}
112
113//-----------------------------------------------------------------------------
114// static
115// requestHintUpdates()
116// Requests updates for all instances (excluding two possible exceptions)  Grungy but efficient.
117//-----------------------------------------------------------------------------
118void LLVisualParamHint::requestHintUpdates( LLVisualParamHint* exception1, LLVisualParamHint* exception2 )
119{
120	S32 delay_frames = 0;
121	for (instance_list_t::iterator iter = sInstances.begin();
122		 iter != sInstances.end(); ++iter)
123	{
124		LLVisualParamHint* instance = *iter;
125		if( (instance != exception1) && (instance != exception2) )
126		{
127			if( instance->mAllowsUpdates )
128			{
129				instance->mNeedsUpdate = TRUE;
130				instance->mDelayFrames = delay_frames;
131				delay_frames++;
132			}
133			else
134			{
135				instance->mNeedsUpdate = TRUE;
136				instance->mDelayFrames = 0;
137			}
138		}
139	}
140}
141
142BOOL LLVisualParamHint::needsRender()
143{
144	return mNeedsUpdate && mDelayFrames-- <= 0 && !gAgentAvatarp->getIsAppearanceAnimating() && mAllowsUpdates;
145}
146
147void LLVisualParamHint::preRender(BOOL clear_depth)
148{
149	mLastParamWeight = mVisualParam->getWeight();
150	mWearablePtr->setVisualParamWeight(mVisualParam->getID(), mVisualParamWeight, FALSE);
151	gAgentAvatarp->setVisualParamWeight(mVisualParam->getID(), mVisualParamWeight, FALSE);
152	gAgentAvatarp->setVisualParamWeight("Blink_Left", 0.f);
153	gAgentAvatarp->setVisualParamWeight("Blink_Right", 0.f);
154	gAgentAvatarp->updateComposites();
155	gAgentAvatarp->updateVisualParams();
156	gAgentAvatarp->updateGeometry(gAgentAvatarp->mDrawable);
157	gAgentAvatarp->updateLOD();
158
159	LLViewerDynamicTexture::preRender(clear_depth);
160}
161
162//-----------------------------------------------------------------------------
163// render()
164//-----------------------------------------------------------------------------
165BOOL LLVisualParamHint::render()
166{
167	LLVisualParamReset::sDirty = TRUE;
168
169	gGL.pushUIMatrix();
170	gGL.loadUIIdentity();
171
172	gGL.matrixMode(LLRender::MM_PROJECTION);
173	gGL.pushMatrix();
174	gGL.loadIdentity();
175	gGL.ortho(0.0f, mFullWidth, 0.0f, mFullHeight, -1.0f, 1.0f);
176
177	gGL.matrixMode(LLRender::MM_MODELVIEW);
178	gGL.pushMatrix();
179	gGL.loadIdentity();
180
181	if (LLGLSLShader::sNoFixedFunction)
182	{
183		gUIProgram.bind();
184	}
185
186	LLGLSUIDefault gls_ui;
187	//LLGLState::verify(TRUE);
188	mBackgroundp->draw(0, 0, mFullWidth, mFullHeight);
189
190	gGL.matrixMode(LLRender::MM_PROJECTION);
191	gGL.popMatrix();
192
193	gGL.matrixMode(LLRender::MM_MODELVIEW);
194	gGL.popMatrix();
195
196	mNeedsUpdate = FALSE;
197	mIsVisible = TRUE;
198
199	LLQuaternion avatar_rotation;
200	LLJoint* root_joint = gAgentAvatarp->getRootJoint();
201	if( root_joint )
202	{
203		avatar_rotation = root_joint->getWorldRotation();
204	}
205
206	LLVector3 target_joint_pos = mCamTargetJoint->getWorldPosition();
207
208	LLVector3 target_offset( 0, 0, mVisualParam->getCameraElevation() );
209	LLVector3 target_pos = target_joint_pos + (target_offset * avatar_rotation);
210
211	F32 cam_angle_radians = mVisualParam->getCameraAngle() * DEG_TO_RAD;
212	LLVector3 camera_snapshot_offset( 
213		mVisualParam->getCameraDistance() * cosf( cam_angle_radians ),
214		mVisualParam->getCameraDistance() * sinf( cam_angle_radians ),
215		mVisualParam->getCameraElevation() );
216	LLVector3 camera_pos = target_joint_pos + (camera_snapshot_offset * avatar_rotation);
217	
218	gGL.flush();
219	
220	LLViewerCamera::getInstance()->setAspect((F32)mFullWidth / (F32)mFullHeight);
221	LLViewerCamera::getInstance()->setOriginAndLookAt(
222		camera_pos,			// camera
223		LLVector3::z_axis,	// up
224		target_pos );		// point of interest
225
226	LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight, FALSE);
227
228	if (gAgentAvatarp->mDrawable.notNull())
229	{
230		LLDrawPoolAvatar *avatarPoolp = (LLDrawPoolAvatar *)gAgentAvatarp->mDrawable->getFace(0)->getPool();
231		LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE);
232		gGL.setAlphaRejectSettings(LLRender::CF_ALWAYS);
233		gGL.setSceneBlendType(LLRender::BT_REPLACE);
234		avatarPoolp->renderAvatars(gAgentAvatarp);  // renders only one avatar
235		gGL.setSceneBlendType(LLRender::BT_ALPHA);
236		gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
237	}
238	gAgentAvatarp->setVisualParamWeight(mVisualParam->getID(), mLastParamWeight);
239	mWearablePtr->setVisualParamWeight(mVisualParam->getID(), mLastParamWeight, FALSE);
240	gAgentAvatarp->updateVisualParams();
241	gGL.color4f(1,1,1,1);
242	mGLTexturep->setGLTextureCreated(true);
243	gGL.popUIMatrix();
244
245	return TRUE;
246}
247
248
249//-----------------------------------------------------------------------------
250// draw()
251//-----------------------------------------------------------------------------
252void LLVisualParamHint::draw(F32 alpha)
253{
254	if (!mIsVisible) return;
255
256	gGL.getTexUnit(0)->bind(this);
257
258	gGL.color4f(1.f, 1.f, 1.f, alpha);
259
260	LLGLSUIDefault gls_ui;
261	gGL.begin(LLRender::QUADS);
262	{
263		gGL.texCoord2i(0, 1);
264		gGL.vertex2i(0, mFullHeight);
265		gGL.texCoord2i(0, 0);
266		gGL.vertex2i(0, 0);
267		gGL.texCoord2i(1, 0);
268		gGL.vertex2i(mFullWidth, 0);
269		gGL.texCoord2i(1, 1);
270		gGL.vertex2i(mFullWidth, mFullHeight);
271	}
272	gGL.end();
273
274	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
275}
276
277//-----------------------------------------------------------------------------
278// LLVisualParamReset()
279//-----------------------------------------------------------------------------
280LLVisualParamReset::LLVisualParamReset() : LLViewerDynamicTexture(1, 1, 1, ORDER_RESET, FALSE)
281{	
282}
283
284//virtual
285S8 LLVisualParamReset::getType() const
286{
287	return LLViewerDynamicTexture::LL_VISUAL_PARAM_RESET ;
288}
289
290//-----------------------------------------------------------------------------
291// render()
292//-----------------------------------------------------------------------------
293BOOL LLVisualParamReset::render()
294{
295	if (sDirty)
296	{
297		gAgentAvatarp->updateComposites();
298		gAgentAvatarp->updateVisualParams();
299		gAgentAvatarp->updateGeometry(gAgentAvatarp->mDrawable);
300		sDirty = FALSE;
301	}
302
303	return FALSE;
304}