llmorphview.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /**
  2. * @file llmorphview.cpp
  3. * @brief Container for Morph functionality
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, 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. #include "llmorphview.h"
  34. #include "llanimationstates.h"
  35. #include "lljoint.h"
  36. #include "llagent.h"
  37. #include "llagentwearables.h"
  38. #include "llfirstuse.h"
  39. #include "llfloatercustomize.h"
  40. #include "llfloatertools.h"
  41. #include "lltoolmgr.h"
  42. #include "llviewercamera.h"
  43. #include "llvisualparamhint.h"
  44. #include "llvoavatarself.h"
  45. // Instance created in LLViewerWindow::initWorldUI()
  46. LLMorphView* gMorphViewp = NULL;
  47. constexpr F32 MORPH_NEAR_CLIP = 0.1f;
  48. LLMorphView::LLMorphView(const LLRect& rect)
  49. : LLView("morph view", rect, false, FOLLOWS_ALL),
  50. mCameraTargetJoint(NULL),
  51. mCameraOffset(-0.5f, 0.05f, 0.07f),
  52. mCameraTargetOffset(0.f, 0.f, 0.05f),
  53. mOldCameraNearClip(0.f),
  54. mCameraPitch(0.f),
  55. mCameraYaw(0.f),
  56. mCameraDrivenByKeys(false)
  57. {
  58. }
  59. LLMorphView::~LLMorphView()
  60. {
  61. gMorphViewp = NULL;
  62. }
  63. void LLMorphView::initialize()
  64. {
  65. mCameraPitch = 0.f;
  66. mCameraYaw = 0.f;
  67. if (!isAgentAvatarValid())
  68. {
  69. gAgent.changeCameraToDefault();
  70. return;
  71. }
  72. gAgentAvatarp->stopMotion(ANIM_AGENT_BODY_NOISE);
  73. gAgentAvatarp->mSpecialRenderMode = 3;
  74. // Set up camera for close look at avatar
  75. mOldCameraNearClip = gViewerCamera.getNear();
  76. gViewerCamera.setNear(MORPH_NEAR_CLIP);
  77. }
  78. void LLMorphView::shutdown()
  79. {
  80. if (isAgentAvatarValid())
  81. {
  82. gAgentAvatarp->startMotion(ANIM_AGENT_BODY_NOISE);
  83. gAgentAvatarp->mSpecialRenderMode = 0;
  84. // Reset camera
  85. gViewerCamera.setNear(mOldCameraNearClip);
  86. }
  87. }
  88. void LLMorphView::setVisible(bool visible)
  89. {
  90. if (visible &&
  91. (!gAgentWearables.getWearableCount(LLWearableType::WT_SHAPE) ||
  92. !gAgentWearables.getWearableCount(LLWearableType::WT_HAIR) ||
  93. !gAgentWearables.getWearableCount(LLWearableType::WT_EYES) ||
  94. !gAgentWearables.getWearableCount(LLWearableType::WT_SKIN)))
  95. {
  96. // Do not let the user edit wearables if avatar is cloud due to missing
  97. // parts.
  98. visible = false;
  99. llwarns << "Cannot edit appearance while mandatory wearables are missing from outfit."
  100. << llendl;
  101. }
  102. if (gFloaterViewp && visible != getVisible())
  103. {
  104. LLView::setVisible(visible);
  105. if (visible)
  106. {
  107. llassert(!gFloaterCustomizep);
  108. gFloaterCustomizep = new LLFloaterCustomize();
  109. gFloaterCustomizep->fetchInventory();
  110. gFloaterCustomizep->open();
  111. gFloaterCustomizep->switchToDefaultSubpart();
  112. initialize();
  113. // First run dialog
  114. LLFirstUse::useAppearance();
  115. }
  116. else
  117. {
  118. if (gFloaterCustomizep)
  119. {
  120. gFloaterViewp->removeChild(gFloaterCustomizep);
  121. delete gFloaterCustomizep;
  122. gFloaterCustomizep = NULL;
  123. }
  124. shutdown();
  125. }
  126. }
  127. }
  128. void LLMorphView::updateCamera()
  129. {
  130. if (!isAgentAvatarValid())
  131. {
  132. return;
  133. }
  134. if (!mCameraTargetJoint)
  135. {
  136. setCameraTargetJoint(gAgentAvatarp->getJoint(LL_JOINT_KEY_HEAD));
  137. }
  138. LLJoint* root_joint = gAgentAvatarp->getRootJoint();
  139. if (!root_joint)
  140. {
  141. return;
  142. }
  143. const LLQuaternion& avatar_rot = root_joint->getWorldRotation();
  144. LLVector3d joint_pos =
  145. gAgent.getPosGlobalFromAgent(mCameraTargetJoint->getWorldPosition());
  146. LLVector3d target_pos = joint_pos + mCameraTargetOffset * avatar_rot;
  147. LLQuaternion camera_rot_yaw(mCameraYaw, LLVector3::z_axis);
  148. LLQuaternion camera_rot_pitch(mCameraPitch, LLVector3::y_axis);
  149. LLVector3d camera_pos = joint_pos +
  150. mCameraOffset * camera_rot_pitch *
  151. camera_rot_yaw * avatar_rot;
  152. gAgent.setCameraPosAndFocusGlobal(camera_pos, target_pos, gAgentID);
  153. }
  154. void LLMorphView::setCameraDrivenByKeys(bool b)
  155. {
  156. if (mCameraDrivenByKeys != b)
  157. {
  158. if (b)
  159. {
  160. // Reset to the default camera position specified by mCameraPitch,
  161. // mCameraYaw, etc.
  162. updateCamera();
  163. }
  164. mCameraDrivenByKeys = b;
  165. }
  166. }