llvoavatar.h
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:40k
源码类别:

游戏引擎

开发平台:

C++ Builder

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