PageRenderTime 347ms CodeModel.GetById 120ms app.highlight 103ms RepoModel.GetById 119ms app.codeStats 0ms

/indra/llcharacter/llcharacter.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 297 lines | 142 code | 69 blank | 86 comment | 11 complexity | 8c6208880b3a976cb1ea467d3ff5b961 MD5 | raw file
  1/** 
  2 * @file llcharacter.h
  3 * @brief Implementation of LLCharacter 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#ifndef LL_LLCHARACTER_H
 28#define LL_LLCHARACTER_H
 29
 30//-----------------------------------------------------------------------------
 31// Header Files
 32//-----------------------------------------------------------------------------
 33#include <string>
 34
 35#include "lljoint.h"
 36#include "llmotioncontroller.h"
 37#include "llvisualparam.h"
 38#include "string_table.h"
 39#include "llpointer.h"
 40#include "llthread.h"
 41
 42class LLPolyMesh;
 43
 44class LLPauseRequestHandle : public LLThreadSafeRefCount
 45{
 46public:
 47	LLPauseRequestHandle() {};
 48};
 49
 50typedef LLPointer<LLPauseRequestHandle> LLAnimPauseRequest;
 51
 52//-----------------------------------------------------------------------------
 53// class LLCharacter
 54//-----------------------------------------------------------------------------
 55class LLCharacter
 56{
 57public:
 58	// Constructor
 59	LLCharacter();
 60
 61	// Destructor
 62	virtual ~LLCharacter();
 63
 64	//-------------------------------------------------------------------------
 65	// LLCharacter Interface
 66	// These functions must be implemented by subclasses.
 67	//-------------------------------------------------------------------------
 68
 69	// get the prefix to be used to lookup motion data files
 70	// from the viewer data directory
 71	virtual const char *getAnimationPrefix() = 0;
 72
 73	// get the root joint of the character
 74	virtual LLJoint *getRootJoint() = 0;
 75
 76	// get the specified joint
 77	// default implementation does recursive search,
 78	// subclasses may optimize/cache results.
 79	virtual LLJoint *getJoint( const std::string &name );
 80
 81	// get the position of the character
 82	virtual LLVector3 getCharacterPosition() = 0;
 83
 84	// get the rotation of the character
 85	virtual LLQuaternion getCharacterRotation() = 0;
 86
 87	// get the velocity of the character
 88	virtual LLVector3 getCharacterVelocity() = 0;
 89
 90	// get the angular velocity of the character
 91	virtual LLVector3 getCharacterAngularVelocity() = 0;
 92
 93	// get the height & normal of the ground under a point
 94	virtual void getGround(const LLVector3 &inPos, LLVector3 &outPos, LLVector3 &outNorm) = 0;
 95
 96	// allocate an array of joints for the character skeleton
 97	// this must be overloaded to support joint subclasses,
 98	// and is called implicitly from buildSkeleton().
 99	// Note this must handle reallocation as it will be called
100	// each time buildSkeleton() is called.
101	virtual BOOL allocateCharacterJoints( U32 num ) = 0;
102
103	// skeleton joint accessor to support joint subclasses
104	virtual LLJoint *getCharacterJoint( U32 i ) = 0;
105
106	// get the physics time dilation for the simulator
107	virtual F32 getTimeDilation() = 0;
108
109	// gets current pixel area of this character
110	virtual F32 getPixelArea() const = 0;
111
112	// gets the head mesh of the character
113	virtual LLPolyMesh*	getHeadMesh() = 0;
114
115	// gets the upper body mesh of the character
116	virtual LLPolyMesh*	getUpperBodyMesh() = 0;
117
118	// gets global coordinates from agent local coordinates
119	virtual LLVector3d	getPosGlobalFromAgent(const LLVector3 &position) = 0;
120
121	// gets agent local coordinates from global coordinates
122	virtual LLVector3	getPosAgentFromGlobal(const LLVector3d &position) = 0;
123
124	// updates all visual parameters for this character
125	virtual void updateVisualParams();
126
127	virtual void addDebugText( const std::string& text ) = 0;
128
129	virtual const LLUUID&	getID() = 0;
130	//-------------------------------------------------------------------------
131	// End Interface
132	//-------------------------------------------------------------------------
133	// registers a motion with the character
134	// returns true if successfull
135	BOOL registerMotion( const LLUUID& id, LLMotionConstructor create );
136
137	void removeMotion( const LLUUID& id );
138
139	// returns an instance of a registered motion, creating one if necessary
140	LLMotion* createMotion( const LLUUID &id );
141
142	// returns an existing instance of a registered motion
143	LLMotion* findMotion( const LLUUID &id );
144	
145	// start a motion
146	// returns true if successful, false if an error occurred
147	virtual BOOL startMotion( const LLUUID& id, F32 start_offset = 0.f);
148
149	// stop a motion
150	virtual BOOL stopMotion( const LLUUID& id, BOOL stop_immediate = FALSE );
151
152	// is this motion active?
153	BOOL isMotionActive( const LLUUID& id );
154
155	// Event handler for motion deactivation.
156	// Called when a motion has completely stopped and has been deactivated.
157	// Subclasses may optionally override this.
158	// The default implementation does nothing.
159	virtual void requestStopMotion( LLMotion* motion );
160	
161	// periodic update function, steps the motion controller
162	enum e_update_t { NORMAL_UPDATE, HIDDEN_UPDATE, FORCE_UPDATE };
163	void updateMotions(e_update_t update_type);
164
165	LLAnimPauseRequest requestPause();
166	BOOL areAnimationsPaused() const { return mMotionController.isPaused(); }
167	void setAnimTimeFactor(F32 factor) { mMotionController.setTimeFactor(factor); }
168	void setTimeStep(F32 time_step) { mMotionController.setTimeStep(time_step); }
169
170	LLMotionController& getMotionController() { return mMotionController; }
171	
172	// Releases all motion instances which should result in
173	// no cached references to character joint data.  This is 
174	// useful if a character wants to rebuild it's skeleton.
175	virtual void flushAllMotions();
176	
177	// Flush only wipes active animations. 
178	virtual void deactivateAllMotions();
179
180	// dumps information for debugging
181	virtual void dumpCharacter( LLJoint *joint = NULL );
182
183	virtual F32 getPreferredPelvisHeight() { return mPreferredPelvisHeight; }
184
185	virtual LLVector3 getVolumePos(S32 joint_index, LLVector3& volume_offset) { return LLVector3::zero; }
186	
187	virtual LLJoint* findCollisionVolume(U32 volume_id) { return NULL; }
188
189	virtual S32 getCollisionVolumeID(std::string &name) { return -1; }
190
191	void setAnimationData(std::string name, void *data);
192	
193	void *getAnimationData(std::string name);
194
195	void removeAnimationData(std::string name);
196	
197	void addVisualParam(LLVisualParam *param);
198	void addSharedVisualParam(LLVisualParam *param);
199
200	virtual BOOL setVisualParamWeight(LLVisualParam *which_param, F32 weight, BOOL upload_bake = FALSE );
201	virtual BOOL setVisualParamWeight(const char* param_name, F32 weight, BOOL upload_bake = FALSE );
202	virtual BOOL setVisualParamWeight(S32 index, F32 weight, BOOL upload_bake = FALSE );
203
204	// get visual param weight by param or name
205	F32 getVisualParamWeight(LLVisualParam *distortion);
206	F32 getVisualParamWeight(const char* param_name);
207	F32 getVisualParamWeight(S32 index);
208
209	// set all morph weights to defaults
210	void clearVisualParamWeights();
211
212	// visual parameter accessors
213	LLVisualParam*	getFirstVisualParam()
214	{
215		mCurIterator = mVisualParamIndexMap.begin();
216		return getNextVisualParam();
217	}
218	LLVisualParam*	getNextVisualParam()
219	{
220		if (mCurIterator == mVisualParamIndexMap.end())
221			return 0;
222		return (mCurIterator++)->second;
223	}
224
225	S32 getVisualParamCountInGroup(const EVisualParamGroup group) const
226	{
227		S32 rtn = 0;
228		for (visual_param_index_map_t::const_iterator iter = mVisualParamIndexMap.begin();
229		     iter != mVisualParamIndexMap.end();
230		     /**/ )
231		{
232			if ((iter++)->second->getGroup() == group)
233			{
234				++rtn;
235			}
236		}
237		return rtn;
238	}
239
240	LLVisualParam*	getVisualParam(S32 id) const
241	{
242		visual_param_index_map_t::const_iterator iter = mVisualParamIndexMap.find(id);
243		return (iter == mVisualParamIndexMap.end()) ? 0 : iter->second;
244	}
245	S32 getVisualParamID(LLVisualParam *id)
246	{
247		visual_param_index_map_t::iterator iter;
248		for (iter = mVisualParamIndexMap.begin(); iter != mVisualParamIndexMap.end(); iter++)
249		{
250			if (iter->second == id)
251				return iter->first;
252		}
253		return 0;
254	}
255	S32				getVisualParamCount() const { return (S32)mVisualParamIndexMap.size(); }
256	LLVisualParam*	getVisualParam(const char *name);
257
258
259	ESex getSex() const			{ return mSex; }
260	void setSex( ESex sex )		{ mSex = sex; }
261
262	U32				getAppearanceSerialNum() const		{ return mAppearanceSerialNum; }
263	void			setAppearanceSerialNum( U32 num )	{ mAppearanceSerialNum = num; }
264	
265	U32				getSkeletonSerialNum() const		{ return mSkeletonSerialNum; }
266	void			setSkeletonSerialNum( U32 num )	{ mSkeletonSerialNum = num; }
267
268	static std::vector< LLCharacter* > sInstances;
269	static BOOL sAllowInstancesChange ; //debug use
270
271protected:
272	LLMotionController	mMotionController;
273
274	typedef std::map<std::string, void *> animation_data_map_t;
275	animation_data_map_t mAnimationData;
276
277	F32					mPreferredPelvisHeight;
278	ESex				mSex;
279	U32					mAppearanceSerialNum;
280	U32					mSkeletonSerialNum;
281	LLAnimPauseRequest	mPauseRequest;
282
283
284private:
285	// visual parameter stuff
286	typedef std::map<S32, LLVisualParam *> 		visual_param_index_map_t;
287	typedef std::map<char *, LLVisualParam *> 	visual_param_name_map_t;
288
289	visual_param_index_map_t::iterator 			mCurIterator;
290	visual_param_index_map_t 					mVisualParamIndexMap;
291	visual_param_name_map_t  					mVisualParamNameMap;
292
293	static LLStringTable sVisualParamNames;	
294};
295
296#endif // LL_LLCHARACTER_H
297