/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. #include "llviewerprecompiledheaders.h"
  27. // File includes
  28. #include "lltoolmorph.h"
  29. #include "llrender.h"
  30. // Library includes
  31. #include "llaudioengine.h"
  32. #include "llviewercontrol.h"
  33. #include "llfontgl.h"
  34. #include "sound_ids.h"
  35. #include "v3math.h"
  36. #include "v3color.h"
  37. // Viewer includes
  38. #include "llagent.h"
  39. #include "lldrawable.h"
  40. #include "lldrawpoolavatar.h"
  41. #include "llface.h"
  42. #include "llmorphview.h"
  43. #include "llresmgr.h"
  44. #include "llselectmgr.h"
  45. #include "llsky.h"
  46. #include "lltexlayer.h"
  47. #include "lltoolmgr.h"
  48. #include "llui.h"
  49. #include "llviewercamera.h"
  50. #include "llviewertexturelist.h"
  51. #include "llviewerobject.h"
  52. #include "llviewerwindow.h"
  53. #include "llvoavatarself.h"
  54. #include "pipeline.h"
  55. //static
  56. LLVisualParamHint::instance_list_t LLVisualParamHint::sInstances;
  57. BOOL LLVisualParamReset::sDirty = FALSE;
  58. //-----------------------------------------------------------------------------
  59. // LLVisualParamHint()
  60. //-----------------------------------------------------------------------------
  61. // static
  62. LLVisualParamHint::LLVisualParamHint(
  63. S32 pos_x, S32 pos_y,
  64. S32 width, S32 height,
  65. LLViewerJointMesh *mesh,
  66. LLViewerVisualParam *param,
  67. LLWearable *wearable,
  68. F32 param_weight,
  69. LLJoint* jointp)
  70. :
  71. LLViewerDynamicTexture(width, height, 3, LLViewerDynamicTexture::ORDER_MIDDLE, TRUE ),
  72. mNeedsUpdate( TRUE ),
  73. mIsVisible( FALSE ),
  74. mJointMesh( mesh ),
  75. mVisualParam( param ),
  76. mWearablePtr( wearable ),
  77. mVisualParamWeight( param_weight ),
  78. mAllowsUpdates( TRUE ),
  79. mDelayFrames( 0 ),
  80. mRect( pos_x, pos_y + height, pos_x + width, pos_y ),
  81. mLastParamWeight(0.f),
  82. mCamTargetJoint(jointp)
  83. {
  84. LLVisualParamHint::sInstances.insert( this );
  85. mBackgroundp = LLUI::getUIImage("avatar_thumb_bkgrnd.png");
  86. llassert(width != 0);
  87. llassert(height != 0);
  88. }
  89. //-----------------------------------------------------------------------------
  90. // ~LLVisualParamHint()
  91. //-----------------------------------------------------------------------------
  92. LLVisualParamHint::~LLVisualParamHint()
  93. {
  94. LLVisualParamHint::sInstances.erase( this );
  95. }
  96. //virtual
  97. S8 LLVisualParamHint::getType() const
  98. {
  99. return LLViewerDynamicTexture::LL_VISUAL_PARAM_HINT ;
  100. }
  101. //-----------------------------------------------------------------------------
  102. // static
  103. // requestHintUpdates()
  104. // Requests updates for all instances (excluding two possible exceptions) Grungy but efficient.
  105. //-----------------------------------------------------------------------------
  106. void LLVisualParamHint::requestHintUpdates( LLVisualParamHint* exception1, LLVisualParamHint* exception2 )
  107. {
  108. S32 delay_frames = 0;
  109. for (instance_list_t::iterator iter = sInstances.begin();
  110. iter != sInstances.end(); ++iter)
  111. {
  112. LLVisualParamHint* instance = *iter;
  113. if( (instance != exception1) && (instance != exception2) )
  114. {
  115. if( instance->mAllowsUpdates )
  116. {
  117. instance->mNeedsUpdate = TRUE;
  118. instance->mDelayFrames = delay_frames;
  119. delay_frames++;
  120. }
  121. else
  122. {
  123. instance->mNeedsUpdate = TRUE;
  124. instance->mDelayFrames = 0;
  125. }
  126. }
  127. }
  128. }
  129. BOOL LLVisualParamHint::needsRender()
  130. {
  131. return mNeedsUpdate && mDelayFrames-- <= 0 && !gAgentAvatarp->getIsAppearanceAnimating() && mAllowsUpdates;
  132. }
  133. void LLVisualParamHint::preRender(BOOL clear_depth)
  134. {
  135. mLastParamWeight = mVisualParam->getWeight();
  136. mWearablePtr->setVisualParamWeight(mVisualParam->getID(), mVisualParamWeight, FALSE);
  137. gAgentAvatarp->setVisualParamWeight(mVisualParam->getID(), mVisualParamWeight, FALSE);
  138. gAgentAvatarp->setVisualParamWeight("Blink_Left", 0.f);
  139. gAgentAvatarp->setVisualParamWeight("Blink_Right", 0.f);
  140. gAgentAvatarp->updateComposites();
  141. gAgentAvatarp->updateVisualParams();
  142. gAgentAvatarp->updateGeometry(gAgentAvatarp->mDrawable);
  143. gAgentAvatarp->updateLOD();
  144. LLViewerDynamicTexture::preRender(clear_depth);
  145. }
  146. //-----------------------------------------------------------------------------
  147. // render()
  148. //-----------------------------------------------------------------------------
  149. BOOL LLVisualParamHint::render()
  150. {
  151. LLVisualParamReset::sDirty = TRUE;
  152. gGL.pushUIMatrix();
  153. gGL.loadUIIdentity();
  154. gGL.matrixMode(LLRender::MM_PROJECTION);
  155. gGL.pushMatrix();
  156. gGL.loadIdentity();
  157. gGL.ortho(0.0f, mFullWidth, 0.0f, mFullHeight, -1.0f, 1.0f);
  158. gGL.matrixMode(LLRender::MM_MODELVIEW);
  159. gGL.pushMatrix();
  160. gGL.loadIdentity();
  161. if (LLGLSLShader::sNoFixedFunction)
  162. {
  163. gUIProgram.bind();
  164. }
  165. LLGLSUIDefault gls_ui;
  166. //LLGLState::verify(TRUE);
  167. mBackgroundp->draw(0, 0, mFullWidth, mFullHeight);
  168. gGL.matrixMode(LLRender::MM_PROJECTION);
  169. gGL.popMatrix();
  170. gGL.matrixMode(LLRender::MM_MODELVIEW);
  171. gGL.popMatrix();
  172. mNeedsUpdate = FALSE;
  173. mIsVisible = TRUE;
  174. LLQuaternion avatar_rotation;
  175. LLJoint* root_joint = gAgentAvatarp->getRootJoint();
  176. if( root_joint )
  177. {
  178. avatar_rotation = root_joint->getWorldRotation();
  179. }
  180. LLVector3 target_joint_pos = mCamTargetJoint->getWorldPosition();
  181. LLVector3 target_offset( 0, 0, mVisualParam->getCameraElevation() );
  182. LLVector3 target_pos = target_joint_pos + (target_offset * avatar_rotation);
  183. F32 cam_angle_radians = mVisualParam->getCameraAngle() * DEG_TO_RAD;
  184. LLVector3 camera_snapshot_offset(
  185. mVisualParam->getCameraDistance() * cosf( cam_angle_radians ),
  186. mVisualParam->getCameraDistance() * sinf( cam_angle_radians ),
  187. mVisualParam->getCameraElevation() );
  188. LLVector3 camera_pos = target_joint_pos + (camera_snapshot_offset * avatar_rotation);
  189. gGL.flush();
  190. LLViewerCamera::getInstance()->setAspect((F32)mFullWidth / (F32)mFullHeight);
  191. LLViewerCamera::getInstance()->setOriginAndLookAt(
  192. camera_pos, // camera
  193. LLVector3::z_axis, // up
  194. target_pos ); // point of interest
  195. LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight, FALSE);
  196. if (gAgentAvatarp->mDrawable.notNull())
  197. {
  198. LLDrawPoolAvatar *avatarPoolp = (LLDrawPoolAvatar *)gAgentAvatarp->mDrawable->getFace(0)->getPool();
  199. LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE);
  200. gGL.setAlphaRejectSettings(LLRender::CF_ALWAYS);
  201. gGL.setSceneBlendType(LLRender::BT_REPLACE);
  202. avatarPoolp->renderAvatars(gAgentAvatarp); // renders only one avatar
  203. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  204. gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
  205. }
  206. gAgentAvatarp->setVisualParamWeight(mVisualParam->getID(), mLastParamWeight);
  207. mWearablePtr->setVisualParamWeight(mVisualParam->getID(), mLastParamWeight, FALSE);
  208. gAgentAvatarp->updateVisualParams();
  209. gGL.color4f(1,1,1,1);
  210. mGLTexturep->setGLTextureCreated(true);
  211. gGL.popUIMatrix();
  212. return TRUE;
  213. }
  214. //-----------------------------------------------------------------------------
  215. // draw()
  216. //-----------------------------------------------------------------------------
  217. void LLVisualParamHint::draw(F32 alpha)
  218. {
  219. if (!mIsVisible) return;
  220. gGL.getTexUnit(0)->bind(this);
  221. gGL.color4f(1.f, 1.f, 1.f, alpha);
  222. LLGLSUIDefault gls_ui;
  223. gGL.begin(LLRender::QUADS);
  224. {
  225. gGL.texCoord2i(0, 1);
  226. gGL.vertex2i(0, mFullHeight);
  227. gGL.texCoord2i(0, 0);
  228. gGL.vertex2i(0, 0);
  229. gGL.texCoord2i(1, 0);
  230. gGL.vertex2i(mFullWidth, 0);
  231. gGL.texCoord2i(1, 1);
  232. gGL.vertex2i(mFullWidth, mFullHeight);
  233. }
  234. gGL.end();
  235. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  236. }
  237. //-----------------------------------------------------------------------------
  238. // LLVisualParamReset()
  239. //-----------------------------------------------------------------------------
  240. LLVisualParamReset::LLVisualParamReset() : LLViewerDynamicTexture(1, 1, 1, ORDER_RESET, FALSE)
  241. {
  242. }
  243. //virtual
  244. S8 LLVisualParamReset::getType() const
  245. {
  246. return LLViewerDynamicTexture::LL_VISUAL_PARAM_RESET ;
  247. }
  248. //-----------------------------------------------------------------------------
  249. // render()
  250. //-----------------------------------------------------------------------------
  251. BOOL LLVisualParamReset::render()
  252. {
  253. if (sDirty)
  254. {
  255. gAgentAvatarp->updateComposites();
  256. gAgentAvatarp->updateVisualParams();
  257. gAgentAvatarp->updateGeometry(gAgentAvatarp->mDrawable);
  258. sDirty = FALSE;
  259. }
  260. return FALSE;
  261. }