llavatarjoint.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /**
  2. * @file llavatarjoint.cpp
  3. * @brief Implementation of LLAvatarJoint class
  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 "llavatarjoint.h"
  33. #include "llavatarappearance.h"
  34. #include "llgl.h"
  35. #include "llmath.h"
  36. #include "llrender.h"
  37. //static
  38. bool LLAvatarJoint::sDisableLOD = false;
  39. //-----------------------------------------------------------------------------
  40. // LLAvatarJoint class
  41. //-----------------------------------------------------------------------------
  42. LLAvatarJoint::LLAvatarJoint()
  43. : LLJoint()
  44. {
  45. init();
  46. }
  47. LLAvatarJoint::LLAvatarJoint(const std::string& name, LLJoint* parent)
  48. : LLJoint(name, parent)
  49. {
  50. init();
  51. }
  52. void LLAvatarJoint::init()
  53. {
  54. mVisible = true;
  55. mValid = mIsTransparent = false;
  56. mComponents = SC_JOINT | SC_BONE | SC_AXES;
  57. mMinPixelArea = DEFAULT_AVATAR_JOINT_LOD;
  58. mPickName = PN_DEFAULT;
  59. mMeshID = 0;
  60. }
  61. void LLAvatarJoint::setValid(bool valid, bool recursive)
  62. {
  63. // Set visibility for this joint
  64. mValid = valid;
  65. // Set visibility for children
  66. if (recursive)
  67. {
  68. for (child_list_t::iterator iter = mChildren.begin(),
  69. end = mChildren.end();
  70. iter != end; ++iter)
  71. {
  72. LLJoint* jointp = *iter;
  73. if (jointp)
  74. {
  75. LLAvatarJoint* avjointp = jointp->asAvatarJoint();
  76. if (avjointp)
  77. {
  78. avjointp->setValid(valid, true);
  79. }
  80. }
  81. }
  82. }
  83. }
  84. void LLAvatarJoint::setSkeletonComponents(U32 comp, bool recursive)
  85. {
  86. mComponents = comp;
  87. if (recursive)
  88. {
  89. for (child_list_t::iterator iter = mChildren.begin(),
  90. end = mChildren.end();
  91. iter != end; ++iter)
  92. {
  93. LLJoint* jointp = *iter;
  94. if (jointp)
  95. {
  96. LLAvatarJoint* avjointp = jointp->asAvatarJoint();
  97. if (avjointp)
  98. {
  99. avjointp->setSkeletonComponents(comp, recursive);
  100. }
  101. }
  102. }
  103. }
  104. }
  105. void LLAvatarJoint::setVisible(bool visible, bool recursive)
  106. {
  107. mVisible = visible;
  108. if (recursive)
  109. {
  110. for (child_list_t::iterator iter = mChildren.begin(),
  111. end = mChildren.end();
  112. iter != end; ++iter)
  113. {
  114. LLJoint* jointp = *iter;
  115. if (jointp)
  116. {
  117. LLAvatarJoint* avjointp = jointp->asAvatarJoint();
  118. if (avjointp)
  119. {
  120. avjointp->setVisible(visible, recursive);
  121. }
  122. }
  123. }
  124. }
  125. }
  126. void LLAvatarJoint::updateFaceSizes(U32& num_vertices, U32& num_indices,
  127. F32 pixel_area)
  128. {
  129. for (child_list_t::iterator iter = mChildren.begin(),
  130. end = mChildren.end();
  131. iter != end; ++iter)
  132. {
  133. LLJoint* jointp = *iter;
  134. if (jointp)
  135. {
  136. LLAvatarJoint* avjointp = jointp->asAvatarJoint();
  137. if (avjointp)
  138. {
  139. avjointp->updateFaceSizes(num_vertices, num_indices,
  140. pixel_area);
  141. }
  142. }
  143. }
  144. }
  145. void LLAvatarJoint::updateFaceData(LLFace* face, F32 pixel_area,
  146. bool damp_wind, bool terse_update)
  147. {
  148. for (child_list_t::iterator iter = mChildren.begin(),
  149. end = mChildren.end();
  150. iter != end; ++iter)
  151. {
  152. LLJoint* jointp = *iter;
  153. if (jointp)
  154. {
  155. LLAvatarJoint* avjointp = jointp->asAvatarJoint();
  156. if (avjointp)
  157. {
  158. avjointp->updateFaceData(face, pixel_area, damp_wind,
  159. terse_update);
  160. }
  161. }
  162. }
  163. }
  164. void LLAvatarJoint::updateJointGeometry()
  165. {
  166. for (child_list_t::iterator iter = mChildren.begin(),
  167. end = mChildren.end();
  168. iter != end; ++iter)
  169. {
  170. LLJoint* jointp = *iter;
  171. if (jointp)
  172. {
  173. LLAvatarJoint* avjointp = jointp->asAvatarJoint();
  174. if (avjointp)
  175. {
  176. avjointp->updateJointGeometry();
  177. }
  178. }
  179. }
  180. }
  181. bool LLAvatarJoint::updateLOD(F32 pixel_area, bool activate)
  182. {
  183. bool lod_changed = false;
  184. bool found_lod = false;
  185. for (child_list_t::iterator iter = mChildren.begin(),
  186. end = mChildren.end();
  187. iter != end; ++iter)
  188. {
  189. LLJoint* jointp = *iter;
  190. if (!jointp) continue;
  191. LLAvatarJoint* avjointp = jointp->asAvatarJoint();
  192. if (!avjointp) continue;
  193. F32 joint_lod = avjointp->getLOD();
  194. if (found_lod || joint_lod == DEFAULT_AVATAR_JOINT_LOD)
  195. {
  196. // We have already found a joint to enable, so enable the rest as
  197. // alternatives
  198. lod_changed |= avjointp->updateLOD(pixel_area, true);
  199. }
  200. else if (pixel_area >= joint_lod || sDisableLOD)
  201. {
  202. lod_changed |= avjointp->updateLOD(pixel_area, true);
  203. found_lod = true;
  204. }
  205. else
  206. {
  207. lod_changed |= avjointp->updateLOD(pixel_area, false);
  208. }
  209. }
  210. return lod_changed;
  211. }
  212. void LLAvatarJoint::dump()
  213. {
  214. for (child_list_t::iterator iter = mChildren.begin(),
  215. end = mChildren.end();
  216. iter != end; ++iter)
  217. {
  218. LLJoint* jointp = *iter;
  219. if (jointp)
  220. {
  221. LLAvatarJoint* avjointp = jointp->asAvatarJoint();
  222. if (avjointp)
  223. {
  224. avjointp->dump();
  225. }
  226. }
  227. }
  228. }
  229. void LLAvatarJoint::setMeshesToChildren()
  230. {
  231. removeAllChildren();
  232. for (avatar_joint_mesh_list_t::iterator iter = mMeshParts.begin(),
  233. end = mMeshParts.end();
  234. iter != end; ++iter)
  235. {
  236. addChild(*iter);
  237. }
  238. }
  239. //-----------------------------------------------------------------------------
  240. // LLAvatarJointCollisionVolume class
  241. //-----------------------------------------------------------------------------
  242. LLAvatarJointCollisionVolume::LLAvatarJointCollisionVolume()
  243. {
  244. mUpdateXform = false;
  245. }
  246. //virtual
  247. U32 LLAvatarJointCollisionVolume::render(F32 pixelArea, bool first_pass,
  248. bool is_dummy)
  249. {
  250. llerrs << "Cannot call render() on LLAvatarJointCollisionVolume" << llendl;
  251. return 0;
  252. }
  253. LLVector3 LLAvatarJointCollisionVolume::getVolumePos(const LLVector3& offset)
  254. {
  255. mUpdateXform = true;
  256. LLVector3 result = offset;
  257. result.scaleVec(getScale());
  258. result.rotVec(getWorldRotation());
  259. result += getWorldPosition();
  260. return result;
  261. }
  262. void LLAvatarJointCollisionVolume::renderCollision()
  263. {
  264. updateWorldMatrix();
  265. gGL.pushMatrix();
  266. gGL.multMatrix(mXform.getWorldMatrix().getF32ptr());
  267. gGL.diffuseColor3f(0.f, 0.f, 1.f);
  268. gGL.begin(LLRender::LINES);
  269. static LLVector3 v[] = {
  270. LLVector3::x_axis,
  271. LLVector3::x_axis_neg,
  272. LLVector3::y_axis,
  273. LLVector3::y_axis_neg,
  274. LLVector3::z_axis_neg,
  275. LLVector3::z_axis,
  276. };
  277. // Sides
  278. gGL.vertex3fv(v[0].mV);
  279. gGL.vertex3fv(v[2].mV);
  280. gGL.vertex3fv(v[0].mV);
  281. gGL.vertex3fv(v[3].mV);
  282. gGL.vertex3fv(v[1].mV);
  283. gGL.vertex3fv(v[2].mV);
  284. gGL.vertex3fv(v[1].mV);
  285. gGL.vertex3fv(v[3].mV);
  286. // Top
  287. gGL.vertex3fv(v[0].mV);
  288. gGL.vertex3fv(v[4].mV);
  289. gGL.vertex3fv(v[1].mV);
  290. gGL.vertex3fv(v[4].mV);
  291. gGL.vertex3fv(v[2].mV);
  292. gGL.vertex3fv(v[4].mV);
  293. gGL.vertex3fv(v[3].mV);
  294. gGL.vertex3fv(v[4].mV);
  295. // Bottom
  296. gGL.vertex3fv(v[0].mV);
  297. gGL.vertex3fv(v[5].mV);
  298. gGL.vertex3fv(v[1].mV);
  299. gGL.vertex3fv(v[5].mV);
  300. gGL.vertex3fv(v[2].mV);
  301. gGL.vertex3fv(v[5].mV);
  302. gGL.vertex3fv(v[3].mV);
  303. gGL.vertex3fv(v[5].mV);
  304. gGL.end();
  305. gGL.popMatrix();
  306. }