lltoolmorph.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:9k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file lltoolmorph.cpp
  3.  * @brief A tool to manipulate faces..
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. // File includes
  34. #include "lltoolmorph.h" 
  35. #include "llrender.h"
  36. // Library includes
  37. #include "llaudioengine.h"
  38. #include "llviewercontrol.h"
  39. #include "llfontgl.h"
  40. #include "sound_ids.h"
  41. #include "v3math.h"
  42. #include "v3color.h"
  43. // Viewer includes
  44. #include "llagent.h"
  45. #include "lldrawable.h"
  46. #include "lldrawpoolavatar.h"
  47. #include "llface.h"
  48. #include "llfloatercustomize.h"
  49. #include "llmorphview.h"
  50. #include "llresmgr.h"
  51. #include "llselectmgr.h"
  52. #include "llsky.h"
  53. #include "lltexlayer.h"
  54. #include "lltoolmgr.h"
  55. #include "llui.h"
  56. #include "llviewercamera.h"
  57. #include "llviewertexturelist.h"
  58. #include "llviewerobject.h"
  59. #include "llviewerwindow.h"
  60. #include "llvoavatarself.h"
  61. #include "pipeline.h"
  62. //static
  63. LLVisualParamHint::instance_list_t LLVisualParamHint::sInstances;
  64. BOOL LLVisualParamReset::sDirty = FALSE;
  65. //-----------------------------------------------------------------------------
  66. // LLVisualParamHint()
  67. //-----------------------------------------------------------------------------
  68. // static
  69. LLVisualParamHint::LLVisualParamHint(
  70. S32 pos_x, S32 pos_y,
  71. S32 width, S32 height, 
  72. LLViewerJointMesh *mesh, 
  73. LLViewerVisualParam *param,
  74. F32 param_weight)
  75. :
  76. LLViewerDynamicTexture(width, height, 3, LLViewerDynamicTexture::ORDER_MIDDLE, TRUE ),
  77. mNeedsUpdate( TRUE ),
  78. mIsVisible( FALSE ),
  79. mJointMesh( mesh ),
  80. mVisualParam( param ),
  81. mVisualParamWeight( param_weight ),
  82. mAllowsUpdates( TRUE ),
  83. mDelayFrames( 0 ),
  84. mRect( pos_x, pos_y + height, pos_x + width, pos_y ),
  85. mLastParamWeight(0.f)
  86. {
  87. LLVisualParamHint::sInstances.insert( this );
  88. mBackgroundp = LLUI::getUIImage("avatar_thumb_bkgrnd.j2c");
  89. llassert(width != 0);
  90. llassert(height != 0);
  91. }
  92. //-----------------------------------------------------------------------------
  93. // ~LLVisualParamHint()
  94. //-----------------------------------------------------------------------------
  95. LLVisualParamHint::~LLVisualParamHint()
  96. {
  97. LLVisualParamHint::sInstances.erase( this );
  98. }
  99. //-----------------------------------------------------------------------------
  100. // static
  101. // requestHintUpdates()
  102. // Requests updates for all instances (excluding two possible exceptions)  Grungy but efficient.
  103. //-----------------------------------------------------------------------------
  104. void LLVisualParamHint::requestHintUpdates( LLVisualParamHint* exception1, LLVisualParamHint* exception2 )
  105. {
  106. S32 delay_frames = 0;
  107. for (instance_list_t::iterator iter = sInstances.begin();
  108.  iter != sInstances.end(); ++iter)
  109. {
  110. LLVisualParamHint* instance = *iter;
  111. if( (instance != exception1) && (instance != exception2) )
  112. {
  113. if( instance->mAllowsUpdates )
  114. {
  115. instance->mNeedsUpdate = TRUE;
  116. instance->mDelayFrames = delay_frames;
  117. delay_frames++;
  118. }
  119. else
  120. {
  121. instance->mNeedsUpdate = TRUE;
  122. instance->mDelayFrames = 0;
  123. }
  124. }
  125. }
  126. }
  127. BOOL LLVisualParamHint::needsRender()
  128. {
  129. return mNeedsUpdate && mDelayFrames-- <= 0 && !gAgent.getAvatarObject()->mAppearanceAnimating && mAllowsUpdates;
  130. }
  131. void LLVisualParamHint::preRender(BOOL clear_depth)
  132. {
  133. LLVOAvatarSelf* avatarp = gAgent.getAvatarObject();
  134. mLastParamWeight = mVisualParam->getWeight();
  135. mVisualParam->setWeight(mVisualParamWeight, FALSE);
  136. avatarp->setVisualParamWeight(mVisualParam->getID(), mVisualParamWeight, FALSE);
  137. avatarp->setVisualParamWeight("Blink_Left", 0.f);
  138. avatarp->setVisualParamWeight("Blink_Right", 0.f);
  139. avatarp->updateComposites();
  140. avatarp->updateVisualParams();
  141. avatarp->updateGeometry(avatarp->mDrawable);
  142. avatarp->updateLOD();
  143. LLViewerDynamicTexture::preRender(clear_depth);
  144. }
  145. //-----------------------------------------------------------------------------
  146. // render()
  147. //-----------------------------------------------------------------------------
  148. BOOL LLVisualParamHint::render()
  149. {
  150. LLVisualParamReset::sDirty = TRUE;
  151. LLVOAvatar* avatarp = gAgent.getAvatarObject();
  152. glMatrixMode(GL_PROJECTION);
  153. glPushMatrix();
  154. glLoadIdentity();
  155. glOrtho(0.0f, mFullWidth, 0.0f, mFullHeight, -1.0f, 1.0f);
  156. glMatrixMode(GL_MODELVIEW);
  157. glPushMatrix();
  158. glLoadIdentity();
  159. LLGLSUIDefault gls_ui;
  160. //LLGLState::verify(TRUE);
  161. mBackgroundp->draw(0, 0, mFullWidth, mFullHeight);
  162. glMatrixMode(GL_PROJECTION);
  163. glPopMatrix();
  164. glMatrixMode(GL_MODELVIEW);
  165. glPopMatrix();
  166. mNeedsUpdate = FALSE;
  167. mIsVisible = TRUE;
  168. LLViewerJointMesh* cam_target_joint = NULL;
  169. const std::string& cam_target_mesh_name = mVisualParam->getCameraTargetName();
  170. if( !cam_target_mesh_name.empty() )
  171. {
  172. cam_target_joint = (LLViewerJointMesh*)avatarp->getJoint( cam_target_mesh_name );
  173. }
  174. if( !cam_target_joint )
  175. {
  176. cam_target_joint = (LLViewerJointMesh*)gMorphView->getCameraTargetJoint();
  177. }
  178. if( !cam_target_joint )
  179. {
  180. cam_target_joint = (LLViewerJointMesh*)avatarp->getJoint("mHead");
  181. }
  182. LLQuaternion avatar_rotation;
  183. LLJoint* root_joint = avatarp->getRootJoint();
  184. if( root_joint )
  185. {
  186. avatar_rotation = root_joint->getWorldRotation();
  187. }
  188. LLVector3 target_joint_pos = cam_target_joint->getWorldPosition();
  189. LLVector3 target_offset( 0, 0, mVisualParam->getCameraElevation() );
  190. LLVector3 target_pos = target_joint_pos + (target_offset * avatar_rotation);
  191. F32 cam_angle_radians = mVisualParam->getCameraAngle() * DEG_TO_RAD;
  192. LLVector3 camera_snapshot_offset( 
  193. mVisualParam->getCameraDistance() * cosf( cam_angle_radians ),
  194. mVisualParam->getCameraDistance() * sinf( cam_angle_radians ),
  195. mVisualParam->getCameraElevation() );
  196. LLVector3 camera_pos = target_joint_pos + (camera_snapshot_offset * avatar_rotation);
  197. gGL.flush();
  198. LLViewerCamera::getInstance()->setAspect((F32)mFullWidth / (F32)mFullHeight);
  199. LLViewerCamera::getInstance()->setOriginAndLookAt(
  200. camera_pos, // camera
  201. LLVector3(0.f, 0.f, 1.f), // up
  202. target_pos ); // point of interest
  203. LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight, FALSE);
  204. if (avatarp->mDrawable.notNull())
  205. {
  206. LLDrawPoolAvatar *avatarPoolp = (LLDrawPoolAvatar *)avatarp->mDrawable->getFace(0)->getPool();
  207. LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE);
  208. gGL.setAlphaRejectSettings(LLRender::CF_ALWAYS);
  209. gGL.setSceneBlendType(LLRender::BT_REPLACE);
  210. avatarPoolp->renderAvatars(avatarp);  // renders only one avatar
  211. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  212. gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
  213. }
  214. avatarp->setVisualParamWeight(mVisualParam->getID(), mLastParamWeight);
  215. mVisualParam->setWeight(mLastParamWeight, FALSE);
  216. gGL.color4f(1,1,1,1);
  217. mGLTexturep->setGLTextureCreated(true);
  218. return TRUE;
  219. }
  220. //-----------------------------------------------------------------------------
  221. // draw()
  222. //-----------------------------------------------------------------------------
  223. void LLVisualParamHint::draw()
  224. {
  225. if (!mIsVisible) return;
  226. gGL.getTexUnit(0)->bind(this);
  227. gGL.color4f(1.f, 1.f, 1.f, 1.f);
  228. LLGLSUIDefault gls_ui;
  229. gGL.begin(LLRender::QUADS);
  230. {
  231. gGL.texCoord2i(0, 1);
  232. gGL.vertex2i(0, mFullHeight);
  233. gGL.texCoord2i(0, 0);
  234. gGL.vertex2i(0, 0);
  235. gGL.texCoord2i(1, 0);
  236. gGL.vertex2i(mFullWidth, 0);
  237. gGL.texCoord2i(1, 1);
  238. gGL.vertex2i(mFullWidth, mFullHeight);
  239. }
  240. gGL.end();
  241. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  242. }
  243. //-----------------------------------------------------------------------------
  244. // LLVisualParamReset()
  245. //-----------------------------------------------------------------------------
  246. LLVisualParamReset::LLVisualParamReset() : LLViewerDynamicTexture(1, 1, 1, ORDER_RESET, FALSE)
  247. {
  248. }
  249. //-----------------------------------------------------------------------------
  250. // render()
  251. //-----------------------------------------------------------------------------
  252. BOOL LLVisualParamReset::render()
  253. {
  254. if (sDirty)
  255. {
  256. LLVOAvatarSelf* avatarp = gAgent.getAvatarObject();
  257. avatarp->updateComposites();
  258. avatarp->updateVisualParams();
  259. avatarp->updateGeometry(avatarp->mDrawable);
  260. sDirty = FALSE;
  261. }
  262. return FALSE;
  263. }