PageRenderTime 36ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcharacter/llvisualparam.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 321 lines | 185 code | 28 blank | 108 comment | 29 complexity | af51eb8377959c636f3a682ebb83808d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llvisualparam.cpp
  3. * @brief Implementation of LLPolyMesh class.
  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. // Header Files
  28. //-----------------------------------------------------------------------------
  29. #include "linden_common.h"
  30. #include "llvisualparam.h"
  31. //-----------------------------------------------------------------------------
  32. // LLVisualParamInfo()
  33. //-----------------------------------------------------------------------------
  34. LLVisualParamInfo::LLVisualParamInfo()
  35. :
  36. mID( -1 ),
  37. mGroup( VISUAL_PARAM_GROUP_TWEAKABLE ),
  38. mMinWeight( 0.f ),
  39. mMaxWeight( 1.f ),
  40. mDefaultWeight( 0.f ),
  41. mSex( SEX_BOTH )
  42. {
  43. }
  44. //-----------------------------------------------------------------------------
  45. // parseXml()
  46. //-----------------------------------------------------------------------------
  47. BOOL LLVisualParamInfo::parseXml(LLXmlTreeNode *node)
  48. {
  49. // attribute: id
  50. static LLStdStringHandle id_string = LLXmlTree::addAttributeString("id");
  51. node->getFastAttributeS32( id_string, mID );
  52. // attribute: group
  53. U32 group = 0;
  54. static LLStdStringHandle group_string = LLXmlTree::addAttributeString("group");
  55. if( node->getFastAttributeU32( group_string, group ) )
  56. {
  57. if( group < NUM_VISUAL_PARAM_GROUPS )
  58. {
  59. mGroup = (EVisualParamGroup)group;
  60. }
  61. }
  62. // attribute: value_min, value_max
  63. static LLStdStringHandle value_min_string = LLXmlTree::addAttributeString("value_min");
  64. static LLStdStringHandle value_max_string = LLXmlTree::addAttributeString("value_max");
  65. node->getFastAttributeF32( value_min_string, mMinWeight );
  66. node->getFastAttributeF32( value_max_string, mMaxWeight );
  67. // attribute: value_default
  68. F32 default_weight = 0;
  69. static LLStdStringHandle value_default_string = LLXmlTree::addAttributeString("value_default");
  70. if( node->getFastAttributeF32( value_default_string, default_weight ) )
  71. {
  72. mDefaultWeight = llclamp( default_weight, mMinWeight, mMaxWeight );
  73. if( default_weight != mDefaultWeight )
  74. {
  75. llwarns << "value_default attribute is out of range in node " << mName << " " << default_weight << llendl;
  76. }
  77. }
  78. // attribute: sex
  79. std::string sex = "both";
  80. static LLStdStringHandle sex_string = LLXmlTree::addAttributeString("sex");
  81. node->getFastAttributeString( sex_string, sex ); // optional
  82. if( sex == "both" )
  83. {
  84. mSex = SEX_BOTH;
  85. }
  86. else if( sex == "male" )
  87. {
  88. mSex = SEX_MALE;
  89. }
  90. else if( sex == "female" )
  91. {
  92. mSex = SEX_FEMALE;
  93. }
  94. else
  95. {
  96. llwarns << "Avatar file: <param> has invalid sex attribute: " << sex << llendl;
  97. return FALSE;
  98. }
  99. // attribute: name
  100. static LLStdStringHandle name_string = LLXmlTree::addAttributeString("name");
  101. if( !node->getFastAttributeString( name_string, mName ) )
  102. {
  103. llwarns << "Avatar file: <param> is missing name attribute" << llendl;
  104. return FALSE;
  105. }
  106. // attribute: label
  107. static LLStdStringHandle label_string = LLXmlTree::addAttributeString("label");
  108. if( !node->getFastAttributeString( label_string, mDisplayName ) )
  109. {
  110. mDisplayName = mName;
  111. }
  112. // JC - make sure the display name includes the capitalization in the XML file,
  113. // not the lowercased version.
  114. LLStringUtil::toLower(mName);
  115. // attribute: label_min
  116. static LLStdStringHandle label_min_string = LLXmlTree::addAttributeString("label_min");
  117. if( !node->getFastAttributeString( label_min_string, mMinName ) )
  118. {
  119. mMinName = "Less";
  120. }
  121. // attribute: label_max
  122. static LLStdStringHandle label_max_string = LLXmlTree::addAttributeString("label_max");
  123. if( !node->getFastAttributeString( label_max_string, mMaxName ) )
  124. {
  125. mMaxName = "More";
  126. }
  127. return TRUE;
  128. }
  129. //virtual
  130. void LLVisualParamInfo::toStream(std::ostream &out)
  131. {
  132. out << mID << "\t";
  133. out << mName << "\t";
  134. out << mDisplayName << "\t";
  135. out << mMinName << "\t";
  136. out << mMaxName << "\t";
  137. out << mGroup << "\t";
  138. out << mMinWeight << "\t";
  139. out << mMaxWeight << "\t";
  140. out << mDefaultWeight << "\t";
  141. out << mSex << "\t";
  142. }
  143. //-----------------------------------------------------------------------------
  144. // LLVisualParam()
  145. //-----------------------------------------------------------------------------
  146. LLVisualParam::LLVisualParam()
  147. :
  148. mCurWeight( 0.f ),
  149. mLastWeight( 0.f ),
  150. mNext( NULL ),
  151. mTargetWeight( 0.f ),
  152. mIsAnimating( FALSE ),
  153. mID( -1 ),
  154. mInfo( 0 ),
  155. mIsDummy(FALSE)
  156. {
  157. }
  158. //-----------------------------------------------------------------------------
  159. // ~LLVisualParam()
  160. //-----------------------------------------------------------------------------
  161. LLVisualParam::~LLVisualParam()
  162. {
  163. delete mNext;
  164. }
  165. /*
  166. //=============================================================================
  167. // These virtual functions should always be overridden,
  168. // but are included here for use as templates
  169. //=============================================================================
  170. //-----------------------------------------------------------------------------
  171. // setInfo()
  172. //-----------------------------------------------------------------------------
  173. BOOL LLVisualParam::setInfo(LLVisualParamInfo *info)
  174. {
  175. llassert(mInfo == NULL);
  176. if (info->mID < 0)
  177. return FALSE;
  178. mInfo = info;
  179. mID = info->mID;
  180. setWeight(getDefaultWeight(), FALSE );
  181. return TRUE;
  182. }
  183. //-----------------------------------------------------------------------------
  184. // parseData()
  185. //-----------------------------------------------------------------------------
  186. BOOL LLVisualParam::parseData(LLXmlTreeNode *node)
  187. {
  188. LLVisualParamInfo *info = new LLVisualParamInfo;
  189. info->parseXml(node);
  190. if (!setInfo(info))
  191. return FALSE;
  192. return TRUE;
  193. }
  194. */
  195. //-----------------------------------------------------------------------------
  196. // setWeight()
  197. //-----------------------------------------------------------------------------
  198. void LLVisualParam::setWeight(F32 weight, BOOL upload_bake)
  199. {
  200. if (mIsAnimating)
  201. {
  202. //RN: allow overshoot
  203. mCurWeight = weight;
  204. }
  205. else if (mInfo)
  206. {
  207. mCurWeight = llclamp(weight, mInfo->mMinWeight, mInfo->mMaxWeight);
  208. }
  209. else
  210. {
  211. mCurWeight = weight;
  212. }
  213. if (mNext)
  214. {
  215. mNext->setWeight(weight, upload_bake);
  216. }
  217. }
  218. //-----------------------------------------------------------------------------
  219. // setAnimationTarget()
  220. //-----------------------------------------------------------------------------
  221. void LLVisualParam::setAnimationTarget(F32 target_value, BOOL upload_bake)
  222. {
  223. // don't animate dummy parameters
  224. if (mIsDummy)
  225. {
  226. setWeight(target_value, upload_bake);
  227. return;
  228. }
  229. if (mInfo)
  230. {
  231. if (isTweakable())
  232. {
  233. mTargetWeight = llclamp(target_value, mInfo->mMinWeight, mInfo->mMaxWeight);
  234. }
  235. }
  236. else
  237. {
  238. mTargetWeight = target_value;
  239. }
  240. mIsAnimating = TRUE;
  241. if (mNext)
  242. {
  243. mNext->setAnimationTarget(target_value, upload_bake);
  244. }
  245. }
  246. //-----------------------------------------------------------------------------
  247. // setNextParam()
  248. //-----------------------------------------------------------------------------
  249. void LLVisualParam::setNextParam( LLVisualParam *next )
  250. {
  251. llassert(!mNext);
  252. llassert(getWeight() == getDefaultWeight()); // need to establish mNext before we start changing values on this, else initial value won't get mirrored (we can fix that, but better to forbid this pattern)
  253. mNext = next;
  254. }
  255. //-----------------------------------------------------------------------------
  256. // animate()
  257. //-----------------------------------------------------------------------------
  258. void LLVisualParam::animate( F32 delta, BOOL upload_bake )
  259. {
  260. if (mIsAnimating)
  261. {
  262. F32 new_weight = ((mTargetWeight - mCurWeight) * delta) + mCurWeight;
  263. setWeight(new_weight, upload_bake);
  264. }
  265. }
  266. //-----------------------------------------------------------------------------
  267. // stopAnimating()
  268. //-----------------------------------------------------------------------------
  269. void LLVisualParam::stopAnimating(BOOL upload_bake)
  270. {
  271. if (mIsAnimating && isTweakable())
  272. {
  273. mIsAnimating = FALSE;
  274. setWeight(mTargetWeight, upload_bake);
  275. }
  276. }
  277. //virtual
  278. BOOL LLVisualParam::linkDrivenParams(visual_param_mapper mapper, BOOL only_cross_params)
  279. {
  280. // nothing to do for non-driver parameters
  281. return TRUE;
  282. }
  283. //virtual
  284. void LLVisualParam::resetDrivenParams()
  285. {
  286. // nothing to do for non-driver parameters
  287. return;
  288. }