PageRenderTime 93ms CodeModel.GetById 13ms app.highlight 71ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llvoavatar.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 1103 lines | 678 code | 132 blank | 293 comment | 2 complexity | 7ae31b1830d0d5dbfad005df628f7938 MD5 | raw file
   1/**
   2 * @file llvoavatar.h
   3 * @brief Declaration of LLVOAvatar class which is a derivation of
   4 * LLViewerObject
   5 *
   6 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
   7 * Second Life Viewer Source Code
   8 * Copyright (C) 2010, Linden Research, Inc.
   9 * 
  10 * This library is free software; you can redistribute it and/or
  11 * modify it under the terms of the GNU Lesser General Public
  12 * License as published by the Free Software Foundation;
  13 * version 2.1 of the License only.
  14 * 
  15 * This library is distributed in the hope that it will be useful,
  16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18 * Lesser General Public License for more details.
  19 * 
  20 * You should have received a copy of the GNU Lesser General Public
  21 * License along with this library; if not, write to the Free Software
  22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  23 * 
  24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  25 * $/LicenseInfo$
  26 */
  27
  28#ifndef LL_LLVOAVATAR_H
  29#define LL_LLVOAVATAR_H
  30
  31#include <map>
  32#include <deque>
  33#include <string>
  34#include <vector>
  35
  36#include <boost/signals2.hpp>
  37
  38#include "imageids.h"			// IMG_INVISIBLE
  39#include "llchat.h"
  40#include "lldrawpoolalpha.h"
  41#include "llviewerobject.h"
  42#include "llcharacter.h"
  43#include "llcontrol.h"
  44#include "llviewerjointmesh.h"
  45#include "llviewerjointattachment.h"
  46#include "llrendertarget.h"
  47#include "llvoavatardefines.h"
  48#include "lltexglobalcolor.h"
  49#include "lldriverparam.h"
  50#include "material_codes.h"		// LL_MCODE_END
  51
  52extern const LLUUID ANIM_AGENT_BODY_NOISE;
  53extern const LLUUID ANIM_AGENT_BREATHE_ROT;
  54extern const LLUUID ANIM_AGENT_PHYSICS_MOTION;
  55extern const LLUUID ANIM_AGENT_EDITING;
  56extern const LLUUID ANIM_AGENT_EYE;
  57extern const LLUUID ANIM_AGENT_FLY_ADJUST;
  58extern const LLUUID ANIM_AGENT_HAND_MOTION;
  59extern const LLUUID ANIM_AGENT_HEAD_ROT;
  60extern const LLUUID ANIM_AGENT_PELVIS_FIX;
  61extern const LLUUID ANIM_AGENT_TARGET;
  62extern const LLUUID ANIM_AGENT_WALK_ADJUST;
  63
  64class LLTexLayerSet;
  65class LLVoiceVisualizer;
  66class LLHUDNameTag;
  67class LLHUDEffectSpiral;
  68class LLTexGlobalColor;
  69class LLVOAvatarBoneInfo;
  70class LLVOAvatarSkeletonInfo;
  71
  72//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73// LLVOAvatar
  74// 
  75//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76class LLVOAvatar :
  77	public LLViewerObject,
  78	public LLCharacter,
  79	public boost::signals2::trackable
  80{
  81public:
  82	friend class LLVOAvatarSelf;
  83protected:
  84	struct LLVOAvatarXmlInfo;
  85	struct LLMaskedMorph;
  86
  87/********************************************************************************
  88 **                                                                            **
  89 **                    INITIALIZATION
  90 **/
  91
  92public:
  93	LLVOAvatar(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);
  94	virtual void		markDead();
  95	static void			initClass(); // Initialize data that's only init'd once per class.
  96	static void			cleanupClass();	// Cleanup data that's only init'd once per class.
  97	virtual void 		initInstance(); // Called after construction to initialize the class.
  98protected:
  99	virtual				~LLVOAvatar();
 100	BOOL				loadSkeletonNode();
 101	BOOL				loadMeshNodes();
 102	virtual BOOL		loadLayersets();
 103
 104/**                    Initialization
 105 **                                                                            **
 106 *******************************************************************************/
 107
 108/********************************************************************************
 109 **                                                                            **
 110 **                    INHERITED
 111 **/
 112
 113	//--------------------------------------------------------------------
 114	// LLViewerObject interface and related
 115	//--------------------------------------------------------------------
 116public:
 117	virtual void			updateGL();
 118	virtual	LLVOAvatar*		asAvatar();
 119	virtual U32    	 	 	processUpdateMessage(LLMessageSystem *mesgsys,
 120													 void **user_data,
 121													 U32 block_num,
 122													 const EObjectUpdateType update_type,
 123													 LLDataPacker *dp);
 124	virtual BOOL   	 	 	idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time);
 125	virtual BOOL   	 	 	updateLOD();
 126	BOOL  	 	 	 	 	updateJointLODs();
 127	void					updateLODRiggedAttachments( void );
 128	virtual BOOL   	 	 	isActive() const; // Whether this object needs to do an idleUpdate.
 129	virtual void   	 	 	updateTextures();
 130	virtual S32    	 	 	setTETexture(const U8 te, const LLUUID& uuid); // If setting a baked texture, need to request it from a non-local sim.
 131	virtual void   	 	 	onShift(const LLVector4a& shift_vector);
 132	virtual U32    	 	 	getPartitionType() const;
 133	virtual const  	 	 	LLVector3 getRenderPosition() const;
 134	virtual void   	 	 	updateDrawable(BOOL force_damped);
 135	virtual LLDrawable* 	createDrawable(LLPipeline *pipeline);
 136	virtual BOOL   	 	 	updateGeometry(LLDrawable *drawable);
 137	virtual void   	 	 	setPixelAreaAndAngle(LLAgent &agent);
 138	virtual void   	 	 	updateRegion(LLViewerRegion *regionp);
 139	virtual void   	 	 	updateSpatialExtents(LLVector4a& newMin, LLVector4a &newMax);
 140	virtual void   	 	 	getSpatialExtents(LLVector4a& newMin, LLVector4a& newMax);
 141	virtual BOOL   	 	 	lineSegmentIntersect(const LLVector3& start, const LLVector3& end,
 142												 S32 face = -1,                    // which face to check, -1 = ALL_SIDES
 143												 BOOL pick_transparent = FALSE,
 144												 S32* face_hit = NULL,             // which face was hit
 145												 LLVector3* intersection = NULL,   // return the intersection point
 146												 LLVector2* tex_coord = NULL,      // return the texture coordinates of the intersection point
 147												 LLVector3* normal = NULL,         // return the surface normal at the intersection point
 148												 LLVector3* bi_normal = NULL);     // return the surface bi-normal at the intersection point
 149	LLViewerObject*	lineSegmentIntersectRiggedAttachments(const LLVector3& start, const LLVector3& end,
 150												 S32 face = -1,                    // which face to check, -1 = ALL_SIDES
 151												 BOOL pick_transparent = FALSE,
 152												 S32* face_hit = NULL,             // which face was hit
 153												 LLVector3* intersection = NULL,   // return the intersection point
 154												 LLVector2* tex_coord = NULL,      // return the texture coordinates of the intersection point
 155												 LLVector3* normal = NULL,         // return the surface normal at the intersection point
 156												 LLVector3* bi_normal = NULL);     // return the surface bi-normal at the intersection point
 157
 158	//--------------------------------------------------------------------
 159	// LLCharacter interface and related
 160	//--------------------------------------------------------------------
 161public:
 162	virtual LLVector3    	getCharacterPosition();
 163	virtual LLQuaternion 	getCharacterRotation();
 164	virtual LLVector3    	getCharacterVelocity();
 165	virtual LLVector3    	getCharacterAngularVelocity();
 166	virtual LLJoint*		getCharacterJoint(U32 num);
 167	virtual BOOL			allocateCharacterJoints(U32 num);
 168
 169	virtual LLUUID			remapMotionID(const LLUUID& id);
 170	virtual BOOL			startMotion(const LLUUID& id, F32 time_offset = 0.f);
 171	virtual BOOL			stopMotion(const LLUUID& id, BOOL stop_immediate = FALSE);
 172	virtual void			stopMotionFromSource(const LLUUID& source_id);
 173	virtual void			requestStopMotion(LLMotion* motion);
 174	LLMotion*				findMotion(const LLUUID& id) const;
 175	void					startDefaultMotions();
 176	void					dumpAnimationState();
 177
 178	virtual LLJoint*		getJoint(const std::string &name);
 179	virtual LLJoint*     	getRootJoint() { return &mRoot; }
 180	
 181	void					resetJointPositions( void );
 182	void					resetJointPositionsToDefault( void );
 183	void					resetSpecificJointPosition( const std::string& name );
 184	
 185	virtual const char*		getAnimationPrefix() { return "avatar"; }
 186	virtual const LLUUID&   getID();
 187	virtual LLVector3		getVolumePos(S32 joint_index, LLVector3& volume_offset);
 188	virtual LLJoint*		findCollisionVolume(U32 volume_id);
 189	virtual S32				getCollisionVolumeID(std::string &name);
 190	virtual void			addDebugText(const std::string& text);
 191	virtual F32          	getTimeDilation();
 192	virtual void			getGround(const LLVector3 &inPos, LLVector3 &outPos, LLVector3 &outNorm);
 193	virtual F32				getPixelArea() const;
 194	virtual LLPolyMesh*		getHeadMesh();
 195	virtual LLPolyMesh*		getUpperBodyMesh();
 196	virtual LLVector3d		getPosGlobalFromAgent(const LLVector3 &position);
 197	virtual LLVector3		getPosAgentFromGlobal(const LLVector3d &position);
 198	virtual void			updateVisualParams();
 199
 200
 201/**                    Inherited
 202 **                                                                            **
 203 *******************************************************************************/
 204
 205/********************************************************************************
 206 **                                                                            **
 207 **                    STATE
 208 **/
 209
 210public:
 211	virtual bool 	isSelf() const { return false; } // True if this avatar is for this viewer's agent
 212	bool isBuilt() const { return mIsBuilt; }
 213
 214private: //aligned members
 215	LLVector4a	mImpostorExtents[2];
 216
 217private:
 218	BOOL			mSupportsAlphaLayers; // For backwards compatibility, TRUE for 1.23+ clients
 219
 220	//--------------------------------------------------------------------
 221	// Updates
 222	//--------------------------------------------------------------------
 223public:
 224	virtual BOOL 	updateCharacter(LLAgent &agent);
 225	void 			idleUpdateVoiceVisualizer(bool voice_enabled);
 226	void 			idleUpdateMisc(bool detailed_update);
 227	virtual void	idleUpdateAppearanceAnimation();
 228	void 			idleUpdateLipSync(bool voice_enabled);
 229	void 			idleUpdateLoadingEffect();
 230	void 			idleUpdateWindEffect();
 231	void 			idleUpdateNameTag(const LLVector3& root_pos_last);
 232	void			idleUpdateNameTagText(BOOL new_name);
 233	LLVector3		idleUpdateNameTagPosition(const LLVector3& root_pos_last);
 234	void			idleUpdateNameTagAlpha(BOOL new_name, F32 alpha);
 235	LLColor4		getNameTagColor(bool is_friend);
 236	void			clearNameTag();
 237	static void		invalidateNameTag(const LLUUID& agent_id);
 238	// force all name tags to rebuild, useful when display names turned on/off
 239	static void		invalidateNameTags();
 240	void			addNameTagLine(const std::string& line, const LLColor4& color, S32 style, const LLFontGL* font);
 241	void 			idleUpdateRenderCost();
 242	void 			idleUpdateBelowWater();
 243
 244	//--------------------------------------------------------------------
 245	// Static preferences (controlled by user settings/menus)
 246	//--------------------------------------------------------------------
 247public:
 248	static S32		sRenderName;
 249	static BOOL		sRenderGroupTitles;
 250	static U32		sMaxVisible; //(affected by control "RenderAvatarMaxVisible")
 251	static F32		sRenderDistance; //distance at which avatars will render.
 252	static BOOL		sShowAnimationDebug; // show animation debug info
 253	static BOOL		sUseImpostors; //use impostors for far away avatars
 254	static BOOL		sShowFootPlane;	// show foot collision plane reported by server
 255	static BOOL		sShowCollisionVolumes;	// show skeletal collision volumes
 256	static BOOL		sVisibleInFirstPerson;
 257	static S32		sNumLODChangesThisFrame;
 258	static S32		sNumVisibleChatBubbles;
 259	static BOOL		sDebugInvisible;
 260	static BOOL		sShowAttachmentPoints;
 261	static F32		sLODFactor; // user-settable LOD factor
 262	static F32		sPhysicsLODFactor; // user-settable physics LOD factor
 263	static BOOL		sJointDebug; // output total number of joints being touched for each avatar
 264	static BOOL		sDebugAvatarRotation;
 265
 266	//--------------------------------------------------------------------
 267	// Region state
 268	//--------------------------------------------------------------------
 269public:
 270	LLHost			getObjectHost() const;
 271
 272	//--------------------------------------------------------------------
 273	// Loading state
 274	//--------------------------------------------------------------------
 275public:
 276	BOOL			isFullyLoaded() const;
 277	bool			isTooComplex() const;
 278	bool visualParamWeightsAreDefault();
 279protected:
 280	virtual BOOL	getIsCloud();
 281	BOOL			updateIsFullyLoaded();
 282	BOOL			processFullyLoadedChange(bool loading);
 283	void			updateRuthTimer(bool loading);
 284	F32 			calcMorphAmount();
 285private:
 286	BOOL			mFullyLoaded;
 287	BOOL			mPreviousFullyLoaded;
 288	BOOL			mFullyLoadedInitialized;
 289	S32				mFullyLoadedFrameCounter;
 290	S32				mVisualComplexity;
 291	LLFrameTimer	mFullyLoadedTimer;
 292	LLFrameTimer	mRuthTimer;
 293protected:
 294	LLFrameTimer    mInvisibleTimer;
 295	
 296/**                    State
 297 **                                                                            **
 298 *******************************************************************************/
 299
 300/********************************************************************************
 301 **                                                                            **
 302 **                    SKELETON
 303 **/
 304
 305public:
 306	void				updateHeadOffset();
 307	F32					getPelvisToFoot() const { return mPelvisToFoot; }
 308	void				setPelvisOffset( bool hasOffset, const LLVector3& translation, F32 offset ) ;
 309	bool				hasPelvisOffset( void ) { return mHasPelvisOffset; }
 310	void				postPelvisSetRecalc( void );
 311	void				setPelvisOffset( F32 pelvixFixupAmount );
 312
 313	bool				mHasPelvisOffset;
 314	LLVector3			mPelvisOffset;
 315	F32					mLastPelvisToFoot;
 316	F32					mPelvisFixup;
 317	F32					mLastPelvisFixup;
 318
 319	LLVector3			mHeadOffset; // current head position
 320	LLViewerJoint		mRoot;
 321protected:
 322	static BOOL			parseSkeletonFile(const std::string& filename);
 323	void				buildCharacter();
 324	virtual BOOL		loadAvatar();
 325
 326	BOOL				setupBone(const LLVOAvatarBoneInfo* info, LLViewerJoint* parent, S32 &current_volume_num, S32 &current_joint_num);
 327	BOOL				buildSkeleton(const LLVOAvatarSkeletonInfo *info);
 328private:
 329	BOOL				mIsBuilt; // state of deferred character building
 330	S32					mNumJoints;
 331	LLViewerJoint*		mSkeleton;
 332	
 333	//--------------------------------------------------------------------
 334	// Pelvis height adjustment members.
 335	//--------------------------------------------------------------------
 336public:
 337	LLVector3			mBodySize;
 338	S32					mLastSkeletonSerialNum;
 339private:
 340	F32					mPelvisToFoot;
 341
 342	//--------------------------------------------------------------------
 343	// Cached pointers to well known joints
 344	//--------------------------------------------------------------------
 345public:
 346	LLViewerJoint* 		mPelvisp;
 347	LLViewerJoint* 		mTorsop;
 348	LLViewerJoint* 		mChestp;
 349	LLViewerJoint* 		mNeckp;
 350	LLViewerJoint* 		mHeadp;
 351	LLViewerJoint* 		mSkullp;
 352	LLViewerJoint* 		mEyeLeftp;
 353	LLViewerJoint* 		mEyeRightp;
 354	LLViewerJoint* 		mHipLeftp;
 355	LLViewerJoint* 		mHipRightp;
 356	LLViewerJoint* 		mKneeLeftp;
 357	LLViewerJoint* 		mKneeRightp;
 358	LLViewerJoint* 		mAnkleLeftp;
 359	LLViewerJoint* 		mAnkleRightp;
 360	LLViewerJoint* 		mFootLeftp;
 361	LLViewerJoint* 		mFootRightp;
 362	LLViewerJoint* 		mWristLeftp;
 363	LLViewerJoint* 		mWristRightp;
 364
 365	//--------------------------------------------------------------------
 366	// XML parse tree
 367	//--------------------------------------------------------------------
 368private:
 369	static LLXmlTree 	sXMLTree; // avatar config file
 370	static LLXmlTree 	sSkeletonXMLTree; // avatar skeleton file
 371
 372/**                    Skeleton
 373 **                                                                            **
 374 *******************************************************************************/
 375
 376/********************************************************************************
 377 **                                                                            **
 378 **                    RENDERING
 379 **/
 380
 381public:
 382	U32 		renderImpostor(LLColor4U color = LLColor4U(255,255,255,255), S32 diffuse_channel = 0);
 383	U32 		renderRigid();
 384	U32 		renderSkinned(EAvatarRenderPass pass);
 385	F32			getLastSkinTime() { return mLastSkinTime; }
 386	U32			renderSkinnedAttachments();
 387	U32 		renderTransparent(BOOL first_pass);
 388	void 		renderCollisionVolumes();
 389	static void	deleteCachedImages(bool clearAll=true);
 390	static void	destroyGL();
 391	static void	restoreGL();
 392	BOOL 		mIsDummy; // for special views
 393	S32			mSpecialRenderMode; // special lighting
 394private:
 395	bool		shouldAlphaMask();
 396
 397	BOOL 		mNeedsSkin; // avatar has been animated and verts have not been updated
 398	F32			mLastSkinTime; //value of gFrameTimeSeconds at last skin update
 399
 400	S32	 		mUpdatePeriod;
 401	S32  		mNumInitFaces; //number of faces generated when creating the avatar drawable, does not inculde splitted faces due to long vertex buffer.
 402
 403	//--------------------------------------------------------------------
 404	// Morph masks
 405	//--------------------------------------------------------------------
 406public:
 407	BOOL 		morphMaskNeedsUpdate(LLVOAvatarDefines::EBakedTextureIndex index = LLVOAvatarDefines::BAKED_NUM_INDICES);
 408	void 		addMaskedMorph(LLVOAvatarDefines::EBakedTextureIndex index, LLPolyMorphTarget* morph_target, BOOL invert, std::string layer);
 409	void 		applyMorphMask(U8* tex_data, S32 width, S32 height, S32 num_components, LLVOAvatarDefines::EBakedTextureIndex index = LLVOAvatarDefines::BAKED_NUM_INDICES);
 410
 411	//--------------------------------------------------------------------
 412	// Visibility
 413	//--------------------------------------------------------------------
 414protected:
 415	void 		updateVisibility();
 416private:
 417	U32	 		mVisibilityRank;
 418	BOOL 		mVisible;
 419	
 420	//--------------------------------------------------------------------
 421	// Shadowing
 422	//--------------------------------------------------------------------
 423public:
 424	void 		updateShadowFaces();
 425	LLDrawable*	mShadow;
 426private:
 427	LLFace* 	mShadow0Facep;
 428	LLFace* 	mShadow1Facep;
 429	LLPointer<LLViewerTexture> mShadowImagep;
 430
 431	//--------------------------------------------------------------------
 432	// Impostors
 433	//--------------------------------------------------------------------
 434public:
 435	BOOL 		isImpostor() const;
 436	BOOL 	    needsImpostorUpdate() const;
 437	const LLVector3& getImpostorOffset() const;
 438	const LLVector2& getImpostorDim() const;
 439	void 		getImpostorValues(LLVector4a* extents, LLVector3& angle, F32& distance) const;
 440	void 		cacheImpostorValues();
 441	void 		setImpostorDim(const LLVector2& dim);
 442	static void	resetImpostors();
 443	static void updateImpostors();
 444	LLRenderTarget mImpostor;
 445	BOOL		mNeedsImpostorUpdate;
 446private:
 447	LLVector3	mImpostorOffset;
 448	LLVector2	mImpostorDim;
 449	BOOL		mNeedsAnimUpdate;
 450	LLVector3	mImpostorAngle;
 451	F32			mImpostorDistance;
 452	F32			mImpostorPixelArea;
 453	LLVector3	mLastAnimExtents[2];  
 454	
 455	LLCachedControl<bool> mRenderUnloadedAvatar;
 456
 457	//--------------------------------------------------------------------
 458	// Wind rippling in clothes
 459	//--------------------------------------------------------------------
 460public:
 461	LLVector4	mWindVec;
 462	F32			mRipplePhase;
 463	BOOL		mBelowWater;
 464private:
 465	F32			mWindFreq;
 466	LLFrameTimer mRippleTimer;
 467	F32			mRippleTimeLast;
 468	LLVector3	mRippleAccel;
 469	LLVector3	mLastVel;
 470
 471	//--------------------------------------------------------------------
 472	// Culling
 473	//--------------------------------------------------------------------
 474public:
 475	static void	cullAvatarsByPixelArea();
 476	BOOL		isCulled() const { return mCulled; }
 477private:
 478	BOOL		mCulled;
 479
 480	//--------------------------------------------------------------------
 481	// Freeze counter
 482	//--------------------------------------------------------------------
 483public:
 484	static void updateFreezeCounter(S32 counter = 0);
 485private:
 486	static S32  sFreezeCounter;
 487
 488	//--------------------------------------------------------------------
 489	// Constants
 490	//--------------------------------------------------------------------
 491public:
 492	virtual LLViewerTexture::EBoostLevel 	getAvatarBoostLevel() const { return LLViewerTexture::BOOST_AVATAR; }
 493	virtual LLViewerTexture::EBoostLevel 	getAvatarBakedBoostLevel() const { return LLViewerTexture::BOOST_AVATAR_BAKED; }
 494	virtual S32 						getTexImageSize() const;
 495	virtual S32 						getTexImageArea() const { return getTexImageSize()*getTexImageSize(); }
 496
 497/**                    Rendering
 498 **                                                                            **
 499 *******************************************************************************/
 500
 501/********************************************************************************
 502 **                                                                            **
 503 **                    TEXTURES
 504 **/
 505
 506	//--------------------------------------------------------------------
 507	// Loading status
 508	//--------------------------------------------------------------------
 509public:
 510	virtual BOOL    isTextureDefined(LLVOAvatarDefines::ETextureIndex type, U32 index = 0) const;
 511	virtual BOOL	isTextureVisible(LLVOAvatarDefines::ETextureIndex type, U32 index = 0) const;
 512	virtual BOOL	isTextureVisible(LLVOAvatarDefines::ETextureIndex type, LLWearable *wearable) const;
 513
 514protected:
 515	BOOL			isFullyBaked();
 516	static BOOL		areAllNearbyInstancesBaked(S32& grey_avatars);
 517
 518	//--------------------------------------------------------------------
 519	// Baked textures
 520	//--------------------------------------------------------------------
 521public:
 522	void			releaseComponentTextures(); // ! BACKWARDS COMPATIBILITY !
 523protected:
 524	static void		onBakedTextureMasksLoaded(BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata);
 525	static void		onInitialBakedTextureLoaded(BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata);
 526	static void		onBakedTextureLoaded(BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata);
 527	virtual void	removeMissingBakedTextures();
 528	void			useBakedTexture(const LLUUID& id);
 529
 530	typedef std::deque<LLMaskedMorph *> 	morph_list_t;
 531	struct BakedTextureData
 532	{
 533		LLUUID								mLastTextureIndex;
 534		LLTexLayerSet* 						mTexLayerSet; // Only exists for self
 535		bool								mIsLoaded;
 536		bool								mIsUsed;
 537		LLVOAvatarDefines::ETextureIndex 	mTextureIndex;
 538		U32									mMaskTexName;
 539		// Stores pointers to the joint meshes that this baked texture deals with
 540		std::vector< LLViewerJointMesh * > 	mMeshes;  // std::vector<LLViewerJointMesh> mJoints[i]->mMeshParts
 541		morph_list_t						mMaskedMorphs;
 542	};
 543	typedef std::vector<BakedTextureData> 	bakedtexturedata_vec_t;
 544	bakedtexturedata_vec_t 					mBakedTextureDatas;
 545	LLLoadedCallbackEntry::source_callback_list_t mCallbackTextureList ; 
 546	BOOL mLoadedCallbacksPaused;
 547	//--------------------------------------------------------------------
 548	// Local Textures
 549	//--------------------------------------------------------------------
 550protected:
 551	virtual void	setLocalTexture(LLVOAvatarDefines::ETextureIndex type, LLViewerTexture* tex, BOOL baked_version_exits, U32 index = 0);
 552	virtual void	addLocalTextureStats(LLVOAvatarDefines::ETextureIndex type, LLViewerFetchedTexture* imagep, F32 texel_area_ratio, BOOL rendered, BOOL covered_by_baked, U32 index = 0);
 553	// MULTI-WEARABLE: make self-only?
 554	virtual void	setBakedReady(LLVOAvatarDefines::ETextureIndex type, BOOL baked_version_exists, U32 index = 0);
 555
 556	//--------------------------------------------------------------------
 557	// Texture accessors
 558	//--------------------------------------------------------------------
 559private:
 560	virtual	void				setImage(const U8 te, LLViewerTexture *imagep, const U32 index); 
 561	virtual LLViewerTexture*	getImage(const U8 te, const U32 index) const;
 562
 563	virtual const LLTextureEntry* getTexEntry(const U8 te_num) const;
 564	virtual void setTexEntry(const U8 index, const LLTextureEntry &te);
 565
 566	void checkTextureLoading() ;
 567	//--------------------------------------------------------------------
 568	// Layers
 569	//--------------------------------------------------------------------
 570protected:
 571	void			deleteLayerSetCaches(bool clearAll = true);
 572	void			addBakedTextureStats(LLViewerFetchedTexture* imagep, F32 pixel_area, F32 texel_area_ratio, S32 boost_level);
 573
 574	//--------------------------------------------------------------------
 575	// Composites
 576	//--------------------------------------------------------------------
 577public:
 578	virtual void	invalidateComposite(LLTexLayerSet* layerset, BOOL upload_result);
 579	virtual void	invalidateAll();
 580	virtual void	setCompositeUpdatesEnabled(bool b) {}
 581	virtual void 	setCompositeUpdatesEnabled(U32 index, bool b) {}
 582	virtual bool 	isCompositeUpdateEnabled(U32 index) { return false; }
 583
 584	//--------------------------------------------------------------------
 585	// Static texture/mesh/baked dictionary
 586	//--------------------------------------------------------------------
 587public:
 588	static BOOL 	isIndexLocalTexture(LLVOAvatarDefines::ETextureIndex i);
 589	static BOOL 	isIndexBakedTexture(LLVOAvatarDefines::ETextureIndex i);
 590private:
 591	static const LLVOAvatarDefines::LLVOAvatarDictionary *getDictionary() { return sAvatarDictionary; }
 592	static LLVOAvatarDefines::LLVOAvatarDictionary* sAvatarDictionary;
 593	static LLVOAvatarSkeletonInfo* 					sAvatarSkeletonInfo;
 594	static LLVOAvatarXmlInfo* 						sAvatarXmlInfo;
 595
 596	//--------------------------------------------------------------------
 597	// Messaging
 598	//--------------------------------------------------------------------
 599public:
 600	void 			onFirstTEMessageReceived();
 601private:
 602	BOOL			mFirstTEMessageReceived;
 603	BOOL			mFirstAppearanceMessageReceived;
 604	
 605/**                    Textures
 606 **                                                                            **
 607 *******************************************************************************/
 608
 609/********************************************************************************
 610 **                                                                            **
 611 **                    MESHES
 612 **/
 613
 614public:
 615	void 			updateMeshTextures();
 616	void 			updateSexDependentLayerSets(BOOL upload_bake);
 617	void 			dirtyMesh(); // Dirty the avatar mesh
 618	void 			updateMeshData();
 619protected:
 620	void 			releaseMeshData();
 621	virtual void restoreMeshData();
 622private:
 623	void 			dirtyMesh(S32 priority); // Dirty the avatar mesh, with priority
 624	S32 			mDirtyMesh; // 0 -- not dirty, 1 -- morphed, 2 -- LOD
 625	BOOL			mMeshTexturesDirty;
 626
 627	typedef std::multimap<std::string, LLPolyMesh*> polymesh_map_t;
 628	polymesh_map_t 									mMeshes;
 629	std::vector<LLViewerJoint *> 					mMeshLOD;
 630
 631	//--------------------------------------------------------------------
 632	// Destroy invisible mesh
 633	//--------------------------------------------------------------------
 634protected:
 635	BOOL			mMeshValid;
 636	LLFrameTimer	mMeshInvisibleTime;
 637
 638/**                    Meshes
 639 **                                                                            **
 640 *******************************************************************************/
 641
 642/********************************************************************************
 643 **                                                                            **
 644 **                    APPEARANCE
 645 **/
 646
 647public:
 648	void 			processAvatarAppearance(LLMessageSystem* mesgsys);
 649	void 			hideSkirt();
 650	void			startAppearanceAnimation();
 651	
 652	//--------------------------------------------------------------------
 653	// Appearance morphing
 654	//--------------------------------------------------------------------
 655public:
 656	BOOL			getIsAppearanceAnimating() const { return mAppearanceAnimating; }
 657private:
 658	BOOL			mAppearanceAnimating;
 659	LLFrameTimer	mAppearanceMorphTimer;
 660	F32				mLastAppearanceBlendTime;
 661
 662	//--------------------------------------------------------------------
 663	// Clothing colors (convenience functions to access visual parameters)
 664	//--------------------------------------------------------------------
 665public:
 666	void			setClothesColor(LLVOAvatarDefines::ETextureIndex te, const LLColor4& new_color, BOOL upload_bake);
 667	LLColor4		getClothesColor(LLVOAvatarDefines::ETextureIndex te);
 668	static BOOL			teToColorParams(LLVOAvatarDefines::ETextureIndex te, U32 *param_name);
 669
 670	//--------------------------------------------------------------------
 671	// Global colors
 672	//--------------------------------------------------------------------
 673public:
 674	LLColor4		getGlobalColor(const std::string& color_name ) const;
 675	void			onGlobalColorChanged(const LLTexGlobalColor* global_color, BOOL upload_bake);
 676private:
 677	LLTexGlobalColor* mTexSkinColor;
 678	LLTexGlobalColor* mTexHairColor;
 679	LLTexGlobalColor* mTexEyeColor;
 680
 681	//--------------------------------------------------------------------
 682	// Visibility
 683	//--------------------------------------------------------------------
 684public:
 685	BOOL			isVisible() const;
 686	void			setVisibilityRank(U32 rank);
 687	U32				getVisibilityRank()  const { return mVisibilityRank; } // unused
 688	static S32 		sNumVisibleAvatars; // Number of instances of this class
 689	static LLColor4 getDummyColor();
 690/**                    Appearance
 691 **                                                                            **
 692 *******************************************************************************/
 693
 694/********************************************************************************
 695 **                                                                            **
 696 **                    WEARABLES
 697 **/
 698
 699public:
 700	virtual BOOL			isWearingWearableType(LLWearableType::EType type ) const;
 701	
 702	//--------------------------------------------------------------------
 703	// Attachments
 704	//--------------------------------------------------------------------
 705public:
 706	void 				clampAttachmentPositions();
 707	virtual const LLViewerJointAttachment* attachObject(LLViewerObject *viewer_object);
 708	virtual BOOL 		detachObject(LLViewerObject *viewer_object);
 709	void				cleanupAttachedMesh( LLViewerObject* pVO );
 710	static LLVOAvatar*  findAvatarFromAttachment(LLViewerObject* obj);
 711protected:
 712	LLViewerJointAttachment* getTargetAttachmentPoint(LLViewerObject* viewer_object);
 713	void 				lazyAttach();
 714	void				rebuildRiggedAttachments( void );
 715
 716	//--------------------------------------------------------------------
 717	// Map of attachment points, by ID
 718	//--------------------------------------------------------------------
 719public:
 720	S32 				getAttachmentCount(); // Warning: order(N) not order(1) // currently used only by -self
 721	typedef std::map<S32, LLViewerJointAttachment*> attachment_map_t;
 722	attachment_map_t 								mAttachmentPoints;
 723	std::vector<LLPointer<LLViewerObject> > 		mPendingAttachment;
 724
 725	//--------------------------------------------------------------------
 726	// HUD functions
 727	//--------------------------------------------------------------------
 728public:
 729	BOOL 				hasHUDAttachment() const;
 730	LLBBox 				getHUDBBox() const;
 731	void 				rebuildHUD();
 732	void 				resetHUDAttachments();
 733	BOOL				canAttachMoreObjects() const;
 734	BOOL				canAttachMoreObjects(U32 n) const;
 735protected:
 736	U32					getNumAttachments() const; // O(N), not O(1)
 737
 738/**                    Wearables
 739 **                                                                            **
 740 *******************************************************************************/
 741
 742/********************************************************************************
 743 **                                                                            **
 744 **                    ACTIONS
 745 **/
 746
 747	//--------------------------------------------------------------------
 748	// Animations
 749	//--------------------------------------------------------------------
 750public:
 751	BOOL 			isAnyAnimationSignaled(const LLUUID *anim_array, const S32 num_anims) const;
 752	void 			processAnimationStateChanges();
 753protected:
 754	BOOL 			processSingleAnimationStateChange(const LLUUID &anim_id, BOOL start);
 755	void 			resetAnimations();
 756private:
 757	LLTimer			mAnimTimer;
 758	F32				mTimeLast;	
 759
 760	//--------------------------------------------------------------------
 761	// Animation state data
 762	//--------------------------------------------------------------------
 763public:
 764	typedef std::map<LLUUID, S32>::iterator AnimIterator;
 765	std::map<LLUUID, S32> 					mSignaledAnimations; // requested state of Animation name/value
 766	std::map<LLUUID, S32> 					mPlayingAnimations; // current state of Animation name/value
 767
 768	typedef std::multimap<LLUUID, LLUUID> 	AnimationSourceMap;
 769	typedef AnimationSourceMap::iterator 	AnimSourceIterator;
 770	AnimationSourceMap 						mAnimationSources; // object ids that triggered anim ids
 771
 772	//--------------------------------------------------------------------
 773	// Chat
 774	//--------------------------------------------------------------------
 775public:
 776	void			addChat(const LLChat& chat);
 777	void	   		clearChat();
 778	void	   		startTyping() { mTyping = TRUE; mTypingTimer.reset(); }
 779	void			stopTyping() { mTyping = FALSE; }
 780private:
 781	BOOL			mVisibleChat;
 782
 783	//--------------------------------------------------------------------
 784	// Lip synch morphs
 785	//--------------------------------------------------------------------
 786private:
 787	bool 		   	mLipSyncActive; // we're morphing for lip sync
 788	LLVisualParam* 	mOohMorph; // cached pointers morphs for lip sync
 789	LLVisualParam* 	mAahMorph; // cached pointers morphs for lip sync
 790
 791	//--------------------------------------------------------------------
 792	// Flight
 793	//--------------------------------------------------------------------
 794public:
 795	BOOL			mInAir;
 796	LLFrameTimer	mTimeInAir;
 797
 798/**                    Actions
 799 **                                                                            **
 800 *******************************************************************************/
 801
 802/********************************************************************************
 803 **                                                                            **
 804 **                    PHYSICS
 805 **/
 806
 807private:
 808	F32 		mSpeedAccum; // measures speed (for diagnostics mostly).
 809	BOOL 		mTurning; // controls hysteresis on avatar rotation
 810	F32			mSpeed; // misc. animation repeated state
 811
 812	//--------------------------------------------------------------------
 813	// Collision volumes
 814	//--------------------------------------------------------------------
 815public:
 816  	S32			mNumCollisionVolumes;
 817	LLViewerJointCollisionVolume* mCollisionVolumes;
 818protected:
 819	BOOL		allocateCollisionVolumes(U32 num);
 820
 821	//--------------------------------------------------------------------
 822	// Dimensions
 823	//--------------------------------------------------------------------
 824public:
 825	void 		resolveHeightGlobal(const LLVector3d &inPos, LLVector3d &outPos, LLVector3 &outNorm);
 826	bool		distanceToGround( const LLVector3d &startPoint, LLVector3d &collisionPoint, F32 distToIntersectionAlongRay );
 827	void 		resolveHeightAgent(const LLVector3 &inPos, LLVector3 &outPos, LLVector3 &outNorm);
 828	void 		resolveRayCollisionAgent(const LLVector3d start_pt, const LLVector3d end_pt, LLVector3d &out_pos, LLVector3 &out_norm);
 829	void 		slamPosition(); // Slam position to transmitted position (for teleport);
 830protected:
 831	void 		computeBodySize();
 832
 833	//--------------------------------------------------------------------
 834	// Material being stepped on
 835	//--------------------------------------------------------------------
 836private:
 837	BOOL		mStepOnLand;
 838	U8			mStepMaterial;
 839	LLVector3	mStepObjectVelocity;
 840
 841/**                    Physics
 842 **                                                                            **
 843 *******************************************************************************/
 844
 845/********************************************************************************
 846 **                                                                            **
 847 **                    HIERARCHY
 848 **/
 849
 850public:
 851	virtual BOOL 	setParent(LLViewerObject* parent);
 852	virtual void 	addChild(LLViewerObject *childp);
 853	virtual void 	removeChild(LLViewerObject *childp);
 854
 855	//--------------------------------------------------------------------
 856	// Sitting
 857	//--------------------------------------------------------------------
 858public:
 859	void			sitDown(BOOL bSitting);
 860	BOOL			isSitting(){return mIsSitting;}
 861	void 			sitOnObject(LLViewerObject *sit_object);
 862	void 			getOffObject();
 863private:
 864	// set this property only with LLVOAvatar::sitDown method
 865	BOOL 			mIsSitting;
 866
 867/**                    Hierarchy
 868 **                                                                            **
 869 *******************************************************************************/
 870
 871/********************************************************************************
 872 **                                                                            **
 873 **                    NAME
 874 **/
 875
 876public:
 877	std::string		getFullname() const; // Returns "FirstName LastName"
 878protected:
 879	static void		getAnimLabels(LLDynamicArray<std::string>* labels);
 880	static void		getAnimNames(LLDynamicArray<std::string>* names);	
 881private:
 882	std::string		mNameString;		// UTF-8 title + name + status
 883	std::string  	mTitle;
 884	bool	  		mNameAway;
 885	bool	  		mNameBusy;
 886	bool	  		mNameMute;
 887	bool      		mNameAppearance;
 888	bool			mNameFriend;
 889	bool			mNameCloud;
 890	F32				mNameAlpha;
 891	BOOL      		mRenderGroupTitles;
 892
 893	//--------------------------------------------------------------------
 894	// Display the name (then optionally fade it out)
 895	//--------------------------------------------------------------------
 896public:
 897	LLFrameTimer	mChatTimer;
 898	LLPointer<LLHUDNameTag> mNameText;
 899private:
 900	LLFrameTimer	mTimeVisible;
 901	std::deque<LLChat> mChats;
 902	BOOL			mTyping;
 903	LLFrameTimer	mTypingTimer;
 904
 905/**                    Name
 906 **                                                                            **
 907 *******************************************************************************/
 908
 909/********************************************************************************
 910 **                                                                            **
 911 **                    SOUNDS
 912 **/
 913
 914	//--------------------------------------------------------------------
 915	// Voice visualizer
 916	//--------------------------------------------------------------------
 917public:
 918	// Responsible for detecting the user's voice signal (and when the
 919	// user speaks, it puts a voice symbol over the avatar's head) and gesticulations
 920	LLPointer<LLVoiceVisualizer>  mVoiceVisualizer;
 921	int					mCurrentGesticulationLevel;
 922
 923	//--------------------------------------------------------------------
 924	// Step sound
 925	//--------------------------------------------------------------------
 926protected:
 927	const LLUUID& 		getStepSound() const;
 928private:
 929	// Global table of sound ids per material, and the ground
 930	const static LLUUID	sStepSounds[LL_MCODE_END];
 931	const static LLUUID	sStepSoundOnLand;
 932
 933	//--------------------------------------------------------------------
 934	// Foot step state (for generating sounds)
 935	//--------------------------------------------------------------------
 936public:
 937	void 				setFootPlane(const LLVector4 &plane) { mFootPlane = plane; }
 938	LLVector4			mFootPlane;
 939private:
 940	BOOL				mWasOnGroundLeft;
 941	BOOL				mWasOnGroundRight;
 942
 943/**                    Sounds
 944 **                                                                            **
 945 *******************************************************************************/
 946
 947/********************************************************************************
 948 **                                                                            **
 949 **                    DIAGNOSTICS
 950 **/
 951	
 952	//--------------------------------------------------------------------
 953	// General
 954	//--------------------------------------------------------------------
 955public:
 956	static void			dumpArchetypeXML(void*);
 957	static void			dumpBakedStatus();
 958	const std::string 	getBakedStatusForPrintout() const;
 959	void				dumpAvatarTEs(const std::string& context) const;
 960
 961	static F32 			sUnbakedTime; // Total seconds with >=1 unbaked avatars
 962	static F32 			sUnbakedUpdateTime; // Last time stats were updated (to prevent multiple updates per frame) 
 963	static F32 			sGreyTime; // Total seconds with >=1 grey avatars	
 964	static F32 			sGreyUpdateTime; // Last time stats were updated (to prevent multiple updates per frame) 
 965protected:
 966	S32					getUnbakedPixelAreaRank();
 967	BOOL				mHasGrey;
 968private:
 969	F32					mMinPixelArea;
 970	F32					mMaxPixelArea;
 971	F32					mAdjustedPixelArea;
 972	std::string  		mDebugText;
 973
 974
 975	//--------------------------------------------------------------------
 976	// Avatar Rez Metrics
 977	//--------------------------------------------------------------------
 978public:
 979	F32				debugGetExistenceTimeElapsedF32() const { return mDebugExistenceTimer.getElapsedTimeF32(); }
 980protected:
 981	LLFrameTimer	mRuthDebugTimer; // For tracking how long it takes for av to rez
 982	LLFrameTimer	mDebugExistenceTimer; // Debugging for how long the avatar has been in memory.
 983
 984/**                    Diagnostics
 985 **                                                                            **
 986 *******************************************************************************/
 987
 988/********************************************************************************
 989 **                                                                            **
 990 **                    SUPPORT CLASSES
 991 **/
 992
 993protected: // Shared with LLVOAvatarSelf
 994
 995	struct LLVOAvatarXmlInfo
 996	{
 997		LLVOAvatarXmlInfo();
 998		~LLVOAvatarXmlInfo();
 999
1000		BOOL 	parseXmlSkeletonNode(LLXmlTreeNode* root);
1001		BOOL 	parseXmlMeshNodes(LLXmlTreeNode* root);
1002		BOOL 	parseXmlColorNodes(LLXmlTreeNode* root);
1003		BOOL 	parseXmlLayerNodes(LLXmlTreeNode* root);
1004		BOOL 	parseXmlDriverNodes(LLXmlTreeNode* root);
1005		BOOL	parseXmlMorphNodes(LLXmlTreeNode* root);
1006
1007		struct LLVOAvatarMeshInfo
1008		{
1009			typedef std::pair<LLPolyMorphTargetInfo*,BOOL> morph_info_pair_t;
1010			typedef std::vector<morph_info_pair_t> morph_info_list_t;
1011
1012			LLVOAvatarMeshInfo() : mLOD(0), mMinPixelArea(.1f) {}
1013			~LLVOAvatarMeshInfo()
1014			{
1015				morph_info_list_t::iterator iter;
1016				for (iter = mPolyMorphTargetInfoList.begin(); iter != mPolyMorphTargetInfoList.end(); iter++)
1017				{
1018					delete iter->first;
1019				}
1020				mPolyMorphTargetInfoList.clear();
1021			}
1022
1023			std::string mType;
1024			S32			mLOD;
1025			std::string	mMeshFileName;
1026			std::string	mReferenceMeshName;
1027			F32			mMinPixelArea;
1028			morph_info_list_t mPolyMorphTargetInfoList;
1029		};
1030		typedef std::vector<LLVOAvatarMeshInfo*> mesh_info_list_t;
1031		mesh_info_list_t mMeshInfoList;
1032
1033		typedef std::vector<LLPolySkeletalDistortionInfo*> skeletal_distortion_info_list_t;
1034		skeletal_distortion_info_list_t mSkeletalDistortionInfoList;
1035	
1036		struct LLVOAvatarAttachmentInfo
1037		{
1038			LLVOAvatarAttachmentInfo()
1039				: mGroup(-1), mAttachmentID(-1), mPieMenuSlice(-1), mVisibleFirstPerson(FALSE),
1040				  mIsHUDAttachment(FALSE), mHasPosition(FALSE), mHasRotation(FALSE) {}
1041			std::string mName;
1042			std::string mJointName;
1043			LLVector3 mPosition;
1044			LLVector3 mRotationEuler;
1045			S32 mGroup;
1046			S32 mAttachmentID;
1047			S32 mPieMenuSlice;
1048			BOOL mVisibleFirstPerson;
1049			BOOL mIsHUDAttachment;
1050			BOOL mHasPosition;
1051			BOOL mHasRotation;
1052		};
1053		typedef std::vector<LLVOAvatarAttachmentInfo*> attachment_info_list_t;
1054		attachment_info_list_t mAttachmentInfoList;
1055	
1056		LLTexGlobalColorInfo *mTexSkinColorInfo;
1057		LLTexGlobalColorInfo *mTexHairColorInfo;
1058		LLTexGlobalColorInfo *mTexEyeColorInfo;
1059
1060		typedef std::vector<LLTexLayerSetInfo*> layer_info_list_t;
1061		layer_info_list_t mLayerInfoList;
1062
1063		typedef std::vector<LLDriverParamInfo*> driver_info_list_t;
1064		driver_info_list_t mDriverInfoList;
1065
1066		struct LLVOAvatarMorphInfo
1067		{
1068			LLVOAvatarMorphInfo()
1069				: mInvert(FALSE) {}
1070			std::string mName;
1071			std::string mRegion;
1072			std::string mLayer;
1073			BOOL mInvert;
1074		};
1075
1076		typedef std::vector<LLVOAvatarMorphInfo*> morph_info_list_t;
1077		morph_info_list_t	mMorphMaskInfoList;
1078	};
1079
1080	struct LLMaskedMorph
1081	{
1082		LLMaskedMorph(LLPolyMorphTarget *morph_target, BOOL invert, std::string layer) :
1083			mMorphTarget(morph_target), 
1084			mInvert(invert),
1085			mLayer(layer)
1086		{
1087			morph_target->addPendingMorphMask();
1088		}
1089	
1090		LLPolyMorphTarget	*mMorphTarget;
1091		BOOL				mInvert;
1092		std::string			mLayer;
1093	};
1094
1095/**                    Support classes
1096 **                                                                            **
1097 *******************************************************************************/
1098
1099}; // LLVOAvatar
1100extern const F32 SELF_ADDITIONAL_PRI;
1101extern const S32 MAX_TEXTURE_VIRTURE_SIZE_RESET_INTERVAL;
1102
1103#endif // LL_VO_AVATAR_H