PageRenderTime 577ms CodeModel.GetById 262ms app.highlight 82ms RepoModel.GetById 229ms app.codeStats 1ms

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