llvoavatar.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:225k
- /**
- * @File llvoavatar.cpp
- * @brief Implementation of LLVOAvatar class which is a derivation fo LLViewerObject
- *
- * $LicenseInfo:firstyear=2001&license=viewergpl$
- *
- * Copyright (c) 2001-2010, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- #if LL_MSVC
- // disable warning about boost::lexical_cast returning uninitialized data
- // when it fails to parse the string
- #pragma warning (disable:4701)
- #endif
- #include "llviewerprecompiledheaders.h"
- #include "llvoavatar.h"
- #include <stdio.h>
- #include <ctype.h>
- #include "llaudioengine.h"
- #include "noise.h"
- #include "sound_ids.h"
- #include "llagent.h" // Get state values from here
- #include "llagentwearables.h"
- #include "llanimationstates.h"
- #include "llavatarpropertiesprocessor.h"
- #include "llviewercontrol.h"
- #include "lldrawpoolavatar.h"
- #include "lldriverparam.h"
- #include "lleditingmotion.h"
- #include "llemote.h"
- //#include "llfirstuse.h"
- #include "llheadrotmotion.h"
- #include "llhudeffecttrail.h"
- #include "llhudmanager.h"
- #include "llkeyframefallmotion.h"
- #include "llkeyframestandmotion.h"
- #include "llkeyframewalkmotion.h"
- #include "llmutelist.h"
- #include "llmoveview.h"
- #include "llquantize.h"
- #include "llregionhandle.h"
- #include "llresmgr.h"
- #include "llselectmgr.h"
- #include "llsprite.h"
- #include "lltargetingmotion.h"
- #include "lltexlayer.h"
- #include "lltoolmorph.h"
- #include "llviewercamera.h"
- #include "llviewertexturelist.h"
- #include "llviewermenu.h"
- #include "llviewerobjectlist.h"
- #include "llviewerparcelmgr.h"
- #include "llviewerstats.h"
- #include "llvoavatarself.h"
- #include "llvovolume.h"
- #include "llworld.h"
- #include "pipeline.h"
- #include "llviewershadermgr.h"
- #include "llsky.h"
- #include "llanimstatelabels.h"
- #include "lltrans.h"
- #include "llappearancemgr.h"
- #include "llgesturemgr.h" //needed to trigger the voice gesticulations
- #include "llvoiceclient.h"
- #include "llvoicevisualizer.h" // Ventrella
- #if LL_MSVC
- // disable boost::lexical_cast warning
- #pragma warning (disable:4702)
- #endif
- #include <boost/lexical_cast.hpp>
- using namespace LLVOAvatarDefines;
- //-----------------------------------------------------------------------------
- // Global constants
- //-----------------------------------------------------------------------------
- const LLUUID ANIM_AGENT_BODY_NOISE = LLUUID("9aa8b0a6-0c6f-9518-c7c3-4f41f2c001ad"); //"body_noise"
- const LLUUID ANIM_AGENT_BREATHE_ROT = LLUUID("4c5a103e-b830-2f1c-16bc-224aa0ad5bc8"); //"breathe_rot"
- const LLUUID ANIM_AGENT_EDITING = LLUUID("2a8eba1d-a7f8-5596-d44a-b4977bf8c8bb"); //"editing"
- const LLUUID ANIM_AGENT_EYE = LLUUID("5c780ea8-1cd1-c463-a128-48c023f6fbea"); //"eye"
- const LLUUID ANIM_AGENT_FLY_ADJUST = LLUUID("db95561f-f1b0-9f9a-7224-b12f71af126e"); //"fly_adjust"
- const LLUUID ANIM_AGENT_HAND_MOTION = LLUUID("ce986325-0ba7-6e6e-cc24-b17c4b795578"); //"hand_motion"
- const LLUUID ANIM_AGENT_HEAD_ROT = LLUUID("e6e8d1dd-e643-fff7-b238-c6b4b056a68d"); //"head_rot"
- const LLUUID ANIM_AGENT_PELVIS_FIX = LLUUID("0c5dd2a2-514d-8893-d44d-05beffad208b"); //"pelvis_fix"
- const LLUUID ANIM_AGENT_TARGET = LLUUID("0e4896cb-fba4-926c-f355-8720189d5b55"); //"target"
- const LLUUID ANIM_AGENT_WALK_ADJUST = LLUUID("829bc85b-02fc-ec41-be2e-74cc6dd7215d"); //"walk_adjust"
- //-----------------------------------------------------------------------------
- // Constants
- //-----------------------------------------------------------------------------
- const std::string AVATAR_DEFAULT_CHAR = "avatar";
- const S32 MIN_PIXEL_AREA_FOR_COMPOSITE = 1024;
- const F32 SHADOW_OFFSET_AMT = 0.03f;
- const F32 DELTA_TIME_MIN = 0.01f; // we clamp measured deltaTime to this
- const F32 DELTA_TIME_MAX = 0.2f; // range to insure stability of computations.
- const F32 PELVIS_LAG_FLYING = 0.22f;// pelvis follow half life while flying
- const F32 PELVIS_LAG_WALKING = 0.4f; // ...while walking
- const F32 PELVIS_LAG_MOUSELOOK = 0.15f;
- const F32 MOUSELOOK_PELVIS_FOLLOW_FACTOR = 0.5f;
- const F32 PELVIS_LAG_WHEN_FOLLOW_CAM_IS_ON = 0.0001f; // not zero! - something gets divided by this!
- const F32 PELVIS_ROT_THRESHOLD_SLOW = 60.0f; // amount of deviation allowed between
- const F32 PELVIS_ROT_THRESHOLD_FAST = 2.0f; // the pelvis and the view direction
- // when moving fast & slow
- const F32 TORSO_NOISE_AMOUNT = 1.0f; // Amount of deviation from up-axis, in degrees
- const F32 TORSO_NOISE_SPEED = 0.2f; // Time scale factor on torso noise.
- const F32 BREATHE_ROT_MOTION_STRENGTH = 0.05f;
- const F32 BREATHE_SCALE_MOTION_STRENGTH = 0.005f;
- const F32 MIN_SHADOW_HEIGHT = 0.f;
- const F32 MAX_SHADOW_HEIGHT = 0.3f;
- const S32 MIN_REQUIRED_PIXEL_AREA_BODY_NOISE = 10000;
- const S32 MIN_REQUIRED_PIXEL_AREA_BREATHE = 10000;
- const S32 MIN_REQUIRED_PIXEL_AREA_PELVIS_FIX = 40;
- const S32 TEX_IMAGE_SIZE_SELF = 512;
- const S32 TEX_IMAGE_AREA_SELF = TEX_IMAGE_SIZE_SELF * TEX_IMAGE_SIZE_SELF;
- const S32 TEX_IMAGE_SIZE_OTHER = 512 / 4; // The size of local textures for other (!isSelf()) avatars
- const F32 HEAD_MOVEMENT_AVG_TIME = 0.9f;
- const S32 MORPH_MASK_REQUESTED_DISCARD = 0;
- // Discard level at which to switch to baked textures
- // Should probably be 4 or 3, but didn't want to change it while change other logic - SJB
- const S32 SWITCH_TO_BAKED_DISCARD = 5;
- const F32 FOOT_COLLIDE_FUDGE = 0.04f;
- const F32 HOVER_EFFECT_MAX_SPEED = 3.f;
- const F32 HOVER_EFFECT_STRENGTH = 0.f;
- const F32 UNDERWATER_EFFECT_STRENGTH = 0.1f;
- const F32 UNDERWATER_FREQUENCY_DAMP = 0.33f;
- const F32 APPEARANCE_MORPH_TIME = 0.65f;
- const F32 TIME_BEFORE_MESH_CLEANUP = 5.f; // seconds
- const S32 AVATAR_RELEASE_THRESHOLD = 10; // number of avatar instances before releasing memory
- const F32 FOOT_GROUND_COLLISION_TOLERANCE = 0.25f;
- const F32 AVATAR_LOD_TWEAK_RANGE = 0.7f;
- const S32 MAX_BUBBLE_CHAT_LENGTH = 1023;
- const S32 MAX_BUBBLE_CHAT_UTTERANCES = 12;
- const F32 CHAT_FADE_TIME = 8.0;
- const F32 BUBBLE_CHAT_TIME = CHAT_FADE_TIME * 3.f;
- const LLColor4 DUMMY_COLOR = LLColor4(0.5,0.5,0.5,1.0);
- enum ERenderName
- {
- RENDER_NAME_NEVER,
- RENDER_NAME_ALWAYS,
- RENDER_NAME_FADE
- };
- //-----------------------------------------------------------------------------
- // Callback data
- //-----------------------------------------------------------------------------
- struct LLTextureMaskData
- {
- LLTextureMaskData( const LLUUID& id ) :
- mAvatarID(id),
- mLastDiscardLevel(S32_MAX)
- {}
- LLUUID mAvatarID;
- S32 mLastDiscardLevel;
- };
- /*********************************************************************************
- ** **
- ** Begin private LLVOAvatar Support classes
- **
- **/
- //------------------------------------------------------------------------
- // LLVOBoneInfo
- // Trans/Scale/Rot etc. info about each avatar bone. Used by LLVOAvatarSkeleton.
- //------------------------------------------------------------------------
- class LLVOAvatarBoneInfo
- {
- friend class LLVOAvatar;
- friend class LLVOAvatarSkeletonInfo;
- public:
- LLVOAvatarBoneInfo() : mIsJoint(FALSE) {}
- ~LLVOAvatarBoneInfo()
- {
- std::for_each(mChildList.begin(), mChildList.end(), DeletePointer());
- }
- BOOL parseXml(LLXmlTreeNode* node);
-
- private:
- std::string mName;
- BOOL mIsJoint;
- LLVector3 mPos;
- LLVector3 mRot;
- LLVector3 mScale;
- LLVector3 mPivot;
- typedef std::vector<LLVOAvatarBoneInfo*> child_list_t;
- child_list_t mChildList;
- };
- //------------------------------------------------------------------------
- // LLVOAvatarSkeletonInfo
- // Overall avatar skeleton
- //------------------------------------------------------------------------
- class LLVOAvatarSkeletonInfo
- {
- friend class LLVOAvatar;
- public:
- LLVOAvatarSkeletonInfo() :
- mNumBones(0), mNumCollisionVolumes(0) {}
- ~LLVOAvatarSkeletonInfo()
- {
- std::for_each(mBoneInfoList.begin(), mBoneInfoList.end(), DeletePointer());
- }
- BOOL parseXml(LLXmlTreeNode* node);
- S32 getNumBones() const { return mNumBones; }
- S32 getNumCollisionVolumes() const { return mNumCollisionVolumes; }
-
- private:
- S32 mNumBones;
- S32 mNumCollisionVolumes;
- typedef std::vector<LLVOAvatarBoneInfo*> bone_info_list_t;
- bone_info_list_t mBoneInfoList;
- };
- //-----------------------------------------------------------------------------
- // class LLBodyNoiseMotion
- //-----------------------------------------------------------------------------
- class LLBodyNoiseMotion :
- public LLMotion
- {
- public:
- // Constructor
- LLBodyNoiseMotion(const LLUUID &id)
- : LLMotion(id)
- {
- mName = "body_noise";
- mTorsoState = new LLJointState;
- }
- // Destructor
- virtual ~LLBodyNoiseMotion() { }
- public:
- //-------------------------------------------------------------------------
- // functions to support MotionController and MotionRegistry
- //-------------------------------------------------------------------------
- // static constructor
- // all subclasses must implement such a function and register it
- static LLMotion *create(const LLUUID &id) { return new LLBodyNoiseMotion(id); }
- public:
- //-------------------------------------------------------------------------
- // animation callbacks to be implemented by subclasses
- //-------------------------------------------------------------------------
- // motions must specify whether or not they loop
- virtual BOOL getLoop() { return TRUE; }
- // motions must report their total duration
- virtual F32 getDuration() { return 0.0; }
- // motions must report their "ease in" duration
- virtual F32 getEaseInDuration() { return 0.0; }
- // motions must report their "ease out" duration.
- virtual F32 getEaseOutDuration() { return 0.0; }
- // motions must report their priority
- virtual LLJoint::JointPriority getPriority() { return LLJoint::HIGH_PRIORITY; }
- virtual LLMotionBlendType getBlendType() { return ADDITIVE_BLEND; }
- // called to determine when a motion should be activated/deactivated based on avatar pixel coverage
- virtual F32 getMinPixelArea() { return MIN_REQUIRED_PIXEL_AREA_BODY_NOISE; }
- // run-time (post constructor) initialization,
- // called after parameters have been set
- // must return true to indicate success and be available for activation
- virtual LLMotionInitStatus onInitialize(LLCharacter *character)
- {
- if( !mTorsoState->setJoint( character->getJoint("mTorso") ))
- {
- return STATUS_FAILURE;
- }
- mTorsoState->setUsage(LLJointState::ROT);
- addJointState( mTorsoState );
- return STATUS_SUCCESS;
- }
- // called when a motion is activated
- // must return TRUE to indicate success, or else
- // it will be deactivated
- virtual BOOL onActivate() { return TRUE; }
- // called per time step
- // must return TRUE while it is active, and
- // must return FALSE when the motion is completed.
- virtual BOOL onUpdate(F32 time, U8* joint_mask)
- {
- F32 nx[2];
- nx[0]=time*TORSO_NOISE_SPEED;
- nx[1]=0.0f;
- F32 ny[2];
- ny[0]=0.0f;
- ny[1]=time*TORSO_NOISE_SPEED;
- F32 noiseX = noise2(nx);
- F32 noiseY = noise2(ny);
- F32 rx = TORSO_NOISE_AMOUNT * DEG_TO_RAD * noiseX / 0.42f;
- F32 ry = TORSO_NOISE_AMOUNT * DEG_TO_RAD * noiseY / 0.42f;
- LLQuaternion tQn;
- tQn.setQuat( rx, ry, 0.0f );
- mTorsoState->setRotation( tQn );
- return TRUE;
- }
- // called when a motion is deactivated
- virtual void onDeactivate() {}
- private:
- //-------------------------------------------------------------------------
- // joint states to be animated
- //-------------------------------------------------------------------------
- LLPointer<LLJointState> mTorsoState;
- };
- //-----------------------------------------------------------------------------
- // class LLBreatheMotionRot
- //-----------------------------------------------------------------------------
- class LLBreatheMotionRot :
- public LLMotion
- {
- public:
- // Constructor
- LLBreatheMotionRot(const LLUUID &id) :
- LLMotion(id),
- mBreatheRate(1.f),
- mCharacter(NULL)
- {
- mName = "breathe_rot";
- mChestState = new LLJointState;
- }
- // Destructor
- virtual ~LLBreatheMotionRot() {}
- public:
- //-------------------------------------------------------------------------
- // functions to support MotionController and MotionRegistry
- //-------------------------------------------------------------------------
- // static constructor
- // all subclasses must implement such a function and register it
- static LLMotion *create(const LLUUID &id) { return new LLBreatheMotionRot(id); }
- public:
- //-------------------------------------------------------------------------
- // animation callbacks to be implemented by subclasses
- //-------------------------------------------------------------------------
- // motions must specify whether or not they loop
- virtual BOOL getLoop() { return TRUE; }
- // motions must report their total duration
- virtual F32 getDuration() { return 0.0; }
- // motions must report their "ease in" duration
- virtual F32 getEaseInDuration() { return 0.0; }
- // motions must report their "ease out" duration.
- virtual F32 getEaseOutDuration() { return 0.0; }
- // motions must report their priority
- virtual LLJoint::JointPriority getPriority() { return LLJoint::MEDIUM_PRIORITY; }
- virtual LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
- // called to determine when a motion should be activated/deactivated based on avatar pixel coverage
- virtual F32 getMinPixelArea() { return MIN_REQUIRED_PIXEL_AREA_BREATHE; }
- // run-time (post constructor) initialization,
- // called after parameters have been set
- // must return true to indicate success and be available for activation
- virtual LLMotionInitStatus onInitialize(LLCharacter *character)
- {
- mCharacter = character;
- BOOL success = true;
- if ( !mChestState->setJoint( character->getJoint( "mChest" ) ) ) { success = false; }
- if ( success )
- {
- mChestState->setUsage(LLJointState::ROT);
- addJointState( mChestState );
- }
- if ( success )
- {
- return STATUS_SUCCESS;
- }
- else
- {
- return STATUS_FAILURE;
- }
- }
- // called when a motion is activated
- // must return TRUE to indicate success, or else
- // it will be deactivated
- virtual BOOL onActivate() { return TRUE; }
- // called per time step
- // must return TRUE while it is active, and
- // must return FALSE when the motion is completed.
- virtual BOOL onUpdate(F32 time, U8* joint_mask)
- {
- mBreatheRate = 1.f;
- F32 breathe_amt = (sinf(mBreatheRate * time) * BREATHE_ROT_MOTION_STRENGTH);
- mChestState->setRotation(LLQuaternion(breathe_amt, LLVector3(0.f, 1.f, 0.f)));
- return TRUE;
- }
- // called when a motion is deactivated
- virtual void onDeactivate() {}
- private:
- //-------------------------------------------------------------------------
- // joint states to be animated
- //-------------------------------------------------------------------------
- LLPointer<LLJointState> mChestState;
- F32 mBreatheRate;
- LLCharacter* mCharacter;
- };
- //-----------------------------------------------------------------------------
- // class LLPelvisFixMotion
- //-----------------------------------------------------------------------------
- class LLPelvisFixMotion :
- public LLMotion
- {
- public:
- // Constructor
- LLPelvisFixMotion(const LLUUID &id)
- : LLMotion(id), mCharacter(NULL)
- {
- mName = "pelvis_fix";
- mPelvisState = new LLJointState;
- }
- // Destructor
- virtual ~LLPelvisFixMotion() { }
- public:
- //-------------------------------------------------------------------------
- // functions to support MotionController and MotionRegistry
- //-------------------------------------------------------------------------
- // static constructor
- // all subclasses must implement such a function and register it
- static LLMotion *create(const LLUUID& id) { return new LLPelvisFixMotion(id); }
- public:
- //-------------------------------------------------------------------------
- // animation callbacks to be implemented by subclasses
- //-------------------------------------------------------------------------
- // motions must specify whether or not they loop
- virtual BOOL getLoop() { return TRUE; }
- // motions must report their total duration
- virtual F32 getDuration() { return 0.0; }
- // motions must report their "ease in" duration
- virtual F32 getEaseInDuration() { return 0.5f; }
- // motions must report their "ease out" duration.
- virtual F32 getEaseOutDuration() { return 0.5f; }
- // motions must report their priority
- virtual LLJoint::JointPriority getPriority() { return LLJoint::LOW_PRIORITY; }
- virtual LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
- // called to determine when a motion should be activated/deactivated based on avatar pixel coverage
- virtual F32 getMinPixelArea() { return MIN_REQUIRED_PIXEL_AREA_PELVIS_FIX; }
- // run-time (post constructor) initialization,
- // called after parameters have been set
- // must return true to indicate success and be available for activation
- virtual LLMotionInitStatus onInitialize(LLCharacter *character)
- {
- mCharacter = character;
- if (!mPelvisState->setJoint( character->getJoint("mPelvis")))
- {
- return STATUS_FAILURE;
- }
- mPelvisState->setUsage(LLJointState::POS);
- addJointState( mPelvisState );
- return STATUS_SUCCESS;
- }
- // called when a motion is activated
- // must return TRUE to indicate success, or else
- // it will be deactivated
- virtual BOOL onActivate() { return TRUE; }
- // called per time step
- // must return TRUE while it is active, and
- // must return FALSE when the motion is completed.
- virtual BOOL onUpdate(F32 time, U8* joint_mask)
- {
- mPelvisState->setPosition(LLVector3::zero);
- return TRUE;
- }
- // called when a motion is deactivated
- virtual void onDeactivate() {}
- private:
- //-------------------------------------------------------------------------
- // joint states to be animated
- //-------------------------------------------------------------------------
- LLPointer<LLJointState> mPelvisState;
- LLCharacter* mCharacter;
- };
- /**
- **
- ** End LLVOAvatar Support classes
- ** **
- *********************************************************************************/
- //-----------------------------------------------------------------------------
- // Static Data
- //-----------------------------------------------------------------------------
- LLXmlTree LLVOAvatar::sXMLTree;
- LLXmlTree LLVOAvatar::sSkeletonXMLTree;
- LLVOAvatarSkeletonInfo* LLVOAvatar::sAvatarSkeletonInfo = NULL;
- LLVOAvatar::LLVOAvatarXmlInfo* LLVOAvatar::sAvatarXmlInfo = NULL;
- LLVOAvatarDictionary *LLVOAvatar::sAvatarDictionary = NULL;
- S32 LLVOAvatar::sFreezeCounter = 0;
- S32 LLVOAvatar::sMaxVisible = 50;
- F32 LLVOAvatar::sRenderDistance = 256.f;
- S32 LLVOAvatar::sNumVisibleAvatars = 0;
- S32 LLVOAvatar::sNumLODChangesThisFrame = 0;
- const LLUUID LLVOAvatar::sStepSoundOnLand = LLUUID("e8af4a28-aa83-4310-a7c4-c047e15ea0df");
- const LLUUID LLVOAvatar::sStepSounds[LL_MCODE_END] =
- {
- LLUUID(SND_STONE_RUBBER),
- LLUUID(SND_METAL_RUBBER),
- LLUUID(SND_GLASS_RUBBER),
- LLUUID(SND_WOOD_RUBBER),
- LLUUID(SND_FLESH_RUBBER),
- LLUUID(SND_RUBBER_PLASTIC),
- LLUUID(SND_RUBBER_RUBBER)
- };
- S32 LLVOAvatar::sRenderName = RENDER_NAME_ALWAYS;
- BOOL LLVOAvatar::sRenderGroupTitles = TRUE;
- S32 LLVOAvatar::sNumVisibleChatBubbles = 0;
- BOOL LLVOAvatar::sDebugInvisible = FALSE;
- BOOL LLVOAvatar::sShowAttachmentPoints = FALSE;
- BOOL LLVOAvatar::sShowAnimationDebug = FALSE;
- BOOL LLVOAvatar::sShowFootPlane = FALSE;
- BOOL LLVOAvatar::sVisibleInFirstPerson = FALSE;
- F32 LLVOAvatar::sLODFactor = 1.f;
- BOOL LLVOAvatar::sUseImpostors = FALSE;
- BOOL LLVOAvatar::sJointDebug = FALSE;
- F32 LLVOAvatar::sUnbakedTime = 0.f;
- F32 LLVOAvatar::sUnbakedUpdateTime = 0.f;
- F32 LLVOAvatar::sGreyTime = 0.f;
- F32 LLVOAvatar::sGreyUpdateTime = 0.f;
- //-----------------------------------------------------------------------------
- // Helper functions
- //-----------------------------------------------------------------------------
- static F32 calc_bouncy_animation(F32 x);
- //-----------------------------------------------------------------------------
- // LLVOAvatar()
- //-----------------------------------------------------------------------------
- LLVOAvatar::LLVOAvatar(const LLUUID& id,
- const LLPCode pcode,
- LLViewerRegion* regionp) :
- LLViewerObject(id, pcode, regionp),
- mIsDummy(FALSE),
- mSpecialRenderMode(0),
- mTurning(FALSE),
- mPelvisToFoot(0.f),
- mLastSkeletonSerialNum( 0 ),
- mHeadOffset(),
- mIsSitting(FALSE),
- mTimeVisible(),
- mTyping(FALSE),
- mMeshValid(FALSE),
- mVisible(FALSE),
- mWindFreq(0.f),
- mRipplePhase( 0.f ),
- mBelowWater(FALSE),
- mLastAppearanceBlendTime(0.f),
- mAppearanceAnimating(FALSE),
- mNameString(),
- mTitle(),
- mNameAway(FALSE),
- mNameBusy(FALSE),
- mNameMute(FALSE),
- mRenderGroupTitles(sRenderGroupTitles),
- mNameAppearance(FALSE),
- mFirstTEMessageReceived( FALSE ),
- mFirstAppearanceMessageReceived( FALSE ),
- mCulled( FALSE ),
- mVisibilityRank(0),
- mTexSkinColor( NULL ),
- mTexHairColor( NULL ),
- mTexEyeColor( NULL ),
- mNeedsSkin(FALSE),
- mUpdatePeriod(1),
- mFullyLoadedInitialized(FALSE),
- mSupportsAlphaLayers(FALSE)
- {
- LLMemType mt(LLMemType::MTYPE_AVATAR);
- //VTResume(); // VTune
-
- // mVoiceVisualizer is created by the hud effects manager and uses the HUD Effects pipeline
- const BOOL needsSendToSim = false; // currently, this HUD effect doesn't need to pack and unpack data to do its job
- mVoiceVisualizer = ( LLVoiceVisualizer *)LLHUDManager::getInstance()->createViewerEffect( LLHUDObject::LL_HUD_EFFECT_VOICE_VISUALIZER, needsSendToSim );
- lldebugs << "LLVOAvatar Constructor (0x" << this << ") id:" << mID << llendl;
- mPelvisp = NULL;
- mBakedTextureDatas.resize(BAKED_NUM_INDICES);
- for (U32 i = 0; i < mBakedTextureDatas.size(); i++ )
- {
- mBakedTextureDatas[i].mLastTextureIndex = IMG_DEFAULT_AVATAR;
- mBakedTextureDatas[i].mTexLayerSet = NULL;
- mBakedTextureDatas[i].mIsLoaded = false;
- mBakedTextureDatas[i].mIsUsed = false;
- mBakedTextureDatas[i].mMaskTexName = 0;
- mBakedTextureDatas[i].mTextureIndex = LLVOAvatarDictionary::bakedToLocalTextureIndex((EBakedTextureIndex)i);
- }
- mDirtyMesh = TRUE; // Dirty geometry, need to regenerate.
- mMeshTexturesDirty = FALSE;
- mShadow0Facep = NULL;
- mShadow1Facep = NULL;
- mHeadp = NULL;
- mIsBuilt = FALSE;
- mNumJoints = 0;
- mSkeleton = NULL;
- mNumCollisionVolumes = 0;
- mCollisionVolumes = NULL;
- // set up animation variables
- mSpeed = 0.f;
- setAnimationData("Speed", &mSpeed);
- mNeedsImpostorUpdate = TRUE;
- mNeedsAnimUpdate = TRUE;
- mImpostorDistance = 0;
- mImpostorPixelArea = 0;
- setNumTEs(TEX_NUM_INDICES);
- mbCanSelect = TRUE;
- mSignaledAnimations.clear();
- mPlayingAnimations.clear();
- mWasOnGroundLeft = FALSE;
- mWasOnGroundRight = FALSE;
- mTimeLast = 0.0f;
- mSpeedAccum = 0.0f;
- mRippleTimeLast = 0.f;
- mShadowImagep = LLViewerTextureManager::getFetchedTextureFromFile("foot_shadow.j2c");
-
- // GL NOT ACTIVE HERE
- //gGL.getTexUnit(0)->bind(mShadowImagep.get());
- //mShadowImagep->setAddressMode(LLTexUnit::TAM_CLAMP);
-
- mInAir = FALSE;
- mStepOnLand = TRUE;
- mStepMaterial = 0;
- mLipSyncActive = false;
- mOohMorph = NULL;
- mAahMorph = NULL;
- mCurrentGesticulationLevel = 0;
- }
- //------------------------------------------------------------------------
- // LLVOAvatar::~LLVOAvatar()
- //------------------------------------------------------------------------
- LLVOAvatar::~LLVOAvatar()
- {
- lldebugs << "LLVOAvatar Destructor (0x" << this << ") id:" << mID << llendl;
- if (isSelf())
- {
- gAgent.setAvatarObject(NULL);
- }
- mRoot.removeAllChildren();
- deleteAndClearArray(mSkeleton);
- deleteAndClearArray(mCollisionVolumes);
- mNumJoints = 0;
- for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
- {
- deleteAndClear(mBakedTextureDatas[i].mTexLayerSet);
- mBakedTextureDatas[i].mMeshes.clear();
- for (morph_list_t::iterator iter2 = mBakedTextureDatas[i].mMaskedMorphs.begin();
- iter2 != mBakedTextureDatas[i].mMaskedMorphs.end(); iter2++)
- {
- LLMaskedMorph* masked_morph = (*iter2);
- delete masked_morph;
- }
- }
- std::for_each(mAttachmentPoints.begin(), mAttachmentPoints.end(), DeletePairedPointer());
- mAttachmentPoints.clear();
- deleteAndClear(mTexSkinColor);
- deleteAndClear(mTexHairColor);
- deleteAndClear(mTexEyeColor);
- std::for_each(mMeshes.begin(), mMeshes.end(), DeletePairedPointer());
- mMeshes.clear();
- for (std::vector<LLViewerJoint*>::iterator jointIter = mMeshLOD.begin();
- jointIter != mMeshLOD.end();
- ++jointIter)
- {
- LLViewerJoint* joint = (LLViewerJoint *) *jointIter;
- std::for_each(joint->mMeshParts.begin(), joint->mMeshParts.end(), DeletePointer());
- joint->mMeshParts.clear();
- }
- std::for_each(mMeshLOD.begin(), mMeshLOD.end(), DeletePointer());
- mMeshLOD.clear();
-
- mDead = TRUE;
-
- mAnimationSources.clear();
- lldebugs << "LLVOAvatar Destructor end" << llendl;
- }
- void LLVOAvatar::markDead()
- {
- if (mNameText)
- {
- mNameText->markDead();
- mNameText = NULL;
- sNumVisibleChatBubbles--;
- }
- mVoiceVisualizer->markDead();
- LLViewerObject::markDead();
- }
- BOOL LLVOAvatar::isFullyBaked()
- {
- if (mIsDummy) return TRUE;
- if (getNumTEs() == 0) return FALSE;
- for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
- {
- if (!isTextureDefined(mBakedTextureDatas[i].mTextureIndex)
- && ( (i != BAKED_SKIRT) || isWearingWearableType(WT_SKIRT) ) )
- {
- return FALSE;
- }
- }
- return TRUE;
- }
- void LLVOAvatar::deleteLayerSetCaches(bool clearAll)
- {
- for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
- {
- if (mBakedTextureDatas[i].mTexLayerSet)
- {
- // ! BACKWARDS COMPATIBILITY !
- // Can be removed after hair baking is mandatory on the grid
- if ((i != BAKED_HAIR || isSelf()) && !clearAll)
- {
- mBakedTextureDatas[i].mTexLayerSet->deleteCaches();
- }
- }
- if (mBakedTextureDatas[i].mMaskTexName)
- {
- glDeleteTextures(1, (GLuint*)&(mBakedTextureDatas[i].mMaskTexName));
- mBakedTextureDatas[i].mMaskTexName = 0 ;
- }
- }
- }
- // static
- BOOL LLVOAvatar::areAllNearbyInstancesBaked(S32& grey_avatars)
- {
- BOOL res = TRUE;
- grey_avatars = 0;
- for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
- iter != LLCharacter::sInstances.end(); ++iter)
- {
- LLVOAvatar* inst = (LLVOAvatar*) *iter;
- if( inst->isDead() )
- {
- continue;
- }
- else if( !inst->isFullyBaked() )
- {
- res = FALSE;
- if (inst->mHasGrey)
- {
- ++grey_avatars;
- }
- }
- }
- return res;
- }
- // static
- void LLVOAvatar::dumpBakedStatus()
- {
- LLVector3d camera_pos_global = gAgent.getCameraPositionGlobal();
- for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
- iter != LLCharacter::sInstances.end(); ++iter)
- {
- LLVOAvatar* inst = (LLVOAvatar*) *iter;
- llinfos << "Avatar ";
- LLNameValue* firstname = inst->getNVPair("FirstName");
- LLNameValue* lastname = inst->getNVPair("LastName");
- if( firstname )
- {
- llcont << firstname->getString();
- }
- if( lastname )
- {
- llcont << " " << lastname->getString();
- }
- llcont << " " << inst->mID;
- if( inst->isDead() )
- {
- llcont << " DEAD ("<< inst->getNumRefs() << " refs)";
- }
- if( inst->isSelf() )
- {
- llcont << " (self)";
- }
- F64 dist_to_camera = (inst->getPositionGlobal() - camera_pos_global).length();
- llcont << " " << dist_to_camera << "m ";
- llcont << " " << inst->mPixelArea << " pixels";
- if( inst->isVisible() )
- {
- llcont << " (visible)";
- }
- else
- {
- llcont << " (not visible)";
- }
- if( inst->isFullyBaked() )
- {
- llcont << " Baked";
- }
- else
- {
- llcont << " Unbaked (";
-
- for (LLVOAvatarDictionary::BakedTextures::const_iterator iter = LLVOAvatarDictionary::getInstance()->getBakedTextures().begin();
- iter != LLVOAvatarDictionary::getInstance()->getBakedTextures().end();
- ++iter)
- {
- const LLVOAvatarDictionary::BakedEntry *baked_dict = iter->second;
- const ETextureIndex index = baked_dict->mTextureIndex;
- if (!inst->isTextureDefined(index))
- {
- llcont << " " << LLVOAvatarDictionary::getInstance()->getTexture(index)->mName;
- }
- }
- llcont << " ) " << inst->getUnbakedPixelAreaRank();
- if( inst->isCulled() )
- {
- llcont << " culled";
- }
- }
- llcont << llendl;
- }
- }
- //static
- void LLVOAvatar::restoreGL()
- {
- LLVOAvatar* self = gAgent.getAvatarObject();
- if (!self)
- return;
- self->setCompositeUpdatesEnabled(TRUE);
- for (U32 i = 0; i < self->mBakedTextureDatas.size(); i++)
- {
- self->invalidateComposite(self->mBakedTextureDatas[i].mTexLayerSet, FALSE);
- }
- self->updateMeshTextures();
- }
- //static
- void LLVOAvatar::destroyGL()
- {
- deleteCachedImages();
- resetImpostors();
- }
- //static
- void LLVOAvatar::resetImpostors()
- {
- for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
- iter != LLCharacter::sInstances.end(); ++iter)
- {
- LLVOAvatar* avatar = (LLVOAvatar*) *iter;
- avatar->mImpostor.release();
- }
- }
- // static
- void LLVOAvatar::deleteCachedImages(bool clearAll)
- {
- if (LLTexLayerSet::sHasCaches)
- {
- lldebugs << "Deleting layer set caches" << llendl;
- for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
- iter != LLCharacter::sInstances.end(); ++iter)
- {
- LLVOAvatar* inst = (LLVOAvatar*) *iter;
- inst->deleteLayerSetCaches(clearAll);
- }
- LLTexLayerSet::sHasCaches = FALSE;
- }
- LLVOAvatarSelf::deleteScratchTextures();
- LLTexLayerStaticImageList::getInstance()->deleteCachedImages();
- }
- //------------------------------------------------------------------------
- // static
- // LLVOAvatar::initClass()
- //------------------------------------------------------------------------
- void LLVOAvatar::initClass()
- {
- std::string xmlFile;
- xmlFile = gDirUtilp->getExpandedFilename(LL_PATH_CHARACTER,AVATAR_DEFAULT_CHAR) + "_lad.xml";
- BOOL success = sXMLTree.parseFile( xmlFile, FALSE );
- if (!success)
- {
- llerrs << "Problem reading avatar configuration file:" << xmlFile << llendl;
- }
- // now sanity check xml file
- LLXmlTreeNode* root = sXMLTree.getRoot();
- if (!root)
- {
- llerrs << "No root node found in avatar configuration file: " << xmlFile << llendl;
- return;
- }
- //-------------------------------------------------------------------------
- // <linden_avatar version="1.0"> (root)
- //-------------------------------------------------------------------------
- if( !root->hasName( "linden_avatar" ) )
- {
- llerrs << "Invalid avatar file header: " << xmlFile << llendl;
- }
-
- std::string version;
- static LLStdStringHandle version_string = LLXmlTree::addAttributeString("version");
- if( !root->getFastAttributeString( version_string, version ) || (version != "1.0") )
- {
- llerrs << "Invalid avatar file version: " << version << " in file: " << xmlFile << llendl;
- }
- S32 wearable_def_version = 1;
- static LLStdStringHandle wearable_definition_version_string = LLXmlTree::addAttributeString("wearable_definition_version");
- root->getFastAttributeS32( wearable_definition_version_string, wearable_def_version );
- LLWearable::setCurrentDefinitionVersion( wearable_def_version );
- std::string mesh_file_name;
- LLXmlTreeNode* skeleton_node = root->getChildByName( "skeleton" );
- if (!skeleton_node)
- {
- llerrs << "No skeleton in avatar configuration file: " << xmlFile << llendl;
- return;
- }
-
- std::string skeleton_file_name;
- static LLStdStringHandle file_name_string = LLXmlTree::addAttributeString("file_name");
- if (!skeleton_node->getFastAttributeString(file_name_string, skeleton_file_name))
- {
- llerrs << "No file name in skeleton node in avatar config file: " << xmlFile << llendl;
- }
-
- std::string skeleton_path;
- skeleton_path = gDirUtilp->getExpandedFilename(LL_PATH_CHARACTER,skeleton_file_name);
- if (!parseSkeletonFile(skeleton_path))
- {
- llerrs << "Error parsing skeleton file: " << skeleton_path << llendl;
- }
- // Process XML data
- // avatar_skeleton.xml
- llassert(!sAvatarSkeletonInfo);
- sAvatarSkeletonInfo = new LLVOAvatarSkeletonInfo;
- if (!sAvatarSkeletonInfo->parseXml(sSkeletonXMLTree.getRoot()))
- {
- llerrs << "Error parsing skeleton XML file: " << skeleton_path << llendl;
- }
- // parse avatar_lad.xml
- llassert(!sAvatarXmlInfo);
- sAvatarXmlInfo = new LLVOAvatarXmlInfo;
- if (!sAvatarXmlInfo->parseXmlSkeletonNode(root))
- {
- llerrs << "Error parsing skeleton node in avatar XML file: " << skeleton_path << llendl;
- }
- if (!sAvatarXmlInfo->parseXmlMeshNodes(root))
- {
- llerrs << "Error parsing skeleton node in avatar XML file: " << skeleton_path << llendl;
- }
- if (!sAvatarXmlInfo->parseXmlColorNodes(root))
- {
- llerrs << "Error parsing skeleton node in avatar XML file: " << skeleton_path << llendl;
- }
- if (!sAvatarXmlInfo->parseXmlLayerNodes(root))
- {
- llerrs << "Error parsing skeleton node in avatar XML file: " << skeleton_path << llendl;
- }
- if (!sAvatarXmlInfo->parseXmlDriverNodes(root))
- {
- llerrs << "Error parsing skeleton node in avatar XML file: " << skeleton_path << llendl;
- }
- if (!sAvatarXmlInfo->parseXmlMorphNodes(root))
- {
- llerrs << "Error parsing skeleton node in avatar XML file: " << skeleton_path << llendl;
- }
- }
- void LLVOAvatar::cleanupClass()
- {
- deleteAndClear(sAvatarXmlInfo);
- sSkeletonXMLTree.cleanup();
- sXMLTree.cleanup();
- }
- void LLVOAvatar::initInstance(void)
- {
- //-------------------------------------------------------------------------
- // initialize joint, mesh and shape members
- //-------------------------------------------------------------------------
- mRoot.setName( "mRoot" );
-
- for (LLVOAvatarDictionary::Meshes::const_iterator iter = LLVOAvatarDictionary::getInstance()->getMeshes().begin();
- iter != LLVOAvatarDictionary::getInstance()->getMeshes().end();
- ++iter)
- {
- const EMeshIndex mesh_index = iter->first;
- const LLVOAvatarDictionary::MeshEntry *mesh_dict = iter->second;
- LLViewerJoint* joint = new LLViewerJoint();
- joint->setName(mesh_dict->mName);
- joint->setMeshID(mesh_index);
- mMeshLOD.push_back(joint);
-
- /* mHairLOD.setName("mHairLOD");
- mHairMesh0.setName("mHairMesh0");
- mHairMesh0.setMeshID(MESH_ID_HAIR);
- mHairMesh1.setName("mHairMesh1"); */
- for (U32 lod = 0; lod < mesh_dict->mLOD; lod++)
- {
- LLViewerJointMesh* mesh = new LLViewerJointMesh();
- std::string mesh_name = "m" + mesh_dict->mName + boost::lexical_cast<std::string>(lod);
- // We pre-pended an m - need to capitalize first character for camelCase
- mesh_name[1] = toupper(mesh_name[1]);
- mesh->setName(mesh_name);
- mesh->setMeshID(mesh_index);
- mesh->setPickName(mesh_dict->mPickName);
- mesh->setIsTransparent(FALSE);
- switch((int)mesh_index)
- {
- case MESH_ID_HAIR:
- mesh->setIsTransparent(TRUE);
- break;
- case MESH_ID_SKIRT:
- mesh->setIsTransparent(TRUE);
- break;
- case MESH_ID_EYEBALL_LEFT:
- case MESH_ID_EYEBALL_RIGHT:
- mesh->setSpecular( LLColor4( 1.0f, 1.0f, 1.0f, 1.0f ), 1.f );
- break;
- }
-
- joint->mMeshParts.push_back(mesh);
- }
- }
-
- //-------------------------------------------------------------------------
- // associate baked textures with meshes
- //-------------------------------------------------------------------------
- for (LLVOAvatarDictionary::Meshes::const_iterator iter = LLVOAvatarDictionary::getInstance()->getMeshes().begin();
- iter != LLVOAvatarDictionary::getInstance()->getMeshes().end();
- ++iter)
- {
- const EMeshIndex mesh_index = iter->first;
- const LLVOAvatarDictionary::MeshEntry *mesh_dict = iter->second;
- const EBakedTextureIndex baked_texture_index = mesh_dict->mBakedID;
- // Skip it if there's no associated baked texture.
- if (baked_texture_index == BAKED_NUM_INDICES) continue;
-
- for (std::vector<LLViewerJointMesh* >::iterator iter = mMeshLOD[mesh_index]->mMeshParts.begin();
- iter != mMeshLOD[mesh_index]->mMeshParts.end();
- ++iter)
- {
- LLViewerJointMesh* mesh = (LLViewerJointMesh*) *iter;
- mBakedTextureDatas[(int)baked_texture_index].mMeshes.push_back(mesh);
- }
- }
-
-
- //-------------------------------------------------------------------------
- // register motions
- //-------------------------------------------------------------------------
- if (LLCharacter::sInstances.size() == 1)
- {
- LLKeyframeMotion::setVFS(gStaticVFS);
- registerMotion( ANIM_AGENT_BUSY, LLNullMotion::create );
- registerMotion( ANIM_AGENT_CROUCH, LLKeyframeStandMotion::create );
- registerMotion( ANIM_AGENT_CROUCHWALK, LLKeyframeWalkMotion::create );
- registerMotion( ANIM_AGENT_EXPRESS_AFRAID, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_ANGER, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_BORED, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_CRY, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_DISDAIN, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_EMBARRASSED, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_FROWN, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_KISS, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_LAUGH, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_OPEN_MOUTH, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_REPULSED, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_SAD, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_SHRUG, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_SMILE, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_SURPRISE, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_TONGUE_OUT, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_TOOTHSMILE, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_WINK, LLEmote::create );
- registerMotion( ANIM_AGENT_EXPRESS_WORRY, LLEmote::create );
- registerMotion( ANIM_AGENT_RUN, LLKeyframeWalkMotion::create );
- registerMotion( ANIM_AGENT_STAND, LLKeyframeStandMotion::create );
- registerMotion( ANIM_AGENT_STAND_1, LLKeyframeStandMotion::create );
- registerMotion( ANIM_AGENT_STAND_2, LLKeyframeStandMotion::create );
- registerMotion( ANIM_AGENT_STAND_3, LLKeyframeStandMotion::create );
- registerMotion( ANIM_AGENT_STAND_4, LLKeyframeStandMotion::create );
- registerMotion( ANIM_AGENT_STANDUP, LLKeyframeFallMotion::create );
- registerMotion( ANIM_AGENT_TURNLEFT, LLKeyframeWalkMotion::create );
- registerMotion( ANIM_AGENT_TURNRIGHT, LLKeyframeWalkMotion::create );
- registerMotion( ANIM_AGENT_WALK, LLKeyframeWalkMotion::create );
-
- // motions without a start/stop bit
- registerMotion( ANIM_AGENT_BODY_NOISE, LLBodyNoiseMotion::create );
- registerMotion( ANIM_AGENT_BREATHE_ROT, LLBreatheMotionRot::create );
- registerMotion( ANIM_AGENT_EDITING, LLEditingMotion::create );
- registerMotion( ANIM_AGENT_EYE, LLEyeMotion::create );
- registerMotion( ANIM_AGENT_FEMALE_WALK, LLKeyframeWalkMotion::create );
- registerMotion( ANIM_AGENT_FLY_ADJUST, LLFlyAdjustMotion::create );
- registerMotion( ANIM_AGENT_HAND_MOTION, LLHandMotion::create );
- registerMotion( ANIM_AGENT_HEAD_ROT, LLHeadRotMotion::create );
- registerMotion( ANIM_AGENT_PELVIS_FIX, LLPelvisFixMotion::create );
- registerMotion( ANIM_AGENT_SIT_FEMALE, LLKeyframeMotion::create );
- registerMotion( ANIM_AGENT_TARGET, LLTargetingMotion::create );
- registerMotion( ANIM_AGENT_WALK_ADJUST, LLWalkAdjustMotion::create );
-
- }
-
- if (gNoRender)
- {
- return;
- }
-
- buildCharacter();
-
- if (gNoRender)
- {
- return;
- }
-
- // preload specific motions here
- createMotion( ANIM_AGENT_CUSTOMIZE);
- createMotion( ANIM_AGENT_CUSTOMIZE_DONE);
-
- //VTPause(); // VTune
-
- mVoiceVisualizer->setVoiceEnabled( gVoiceClient->getVoiceEnabled( mID ) );
- }
- const LLVector3 LLVOAvatar::getRenderPosition() const
- {
- if (mDrawable.isNull() || mDrawable->getGeneration() < 0)
- {
- return getPositionAgent();
- }
- else if (isRoot())
- {
- return mDrawable->getPositionAgent();
- }
- else
- {
- return getPosition() * mDrawable->getParent()->getRenderMatrix();
- }
- }
- void LLVOAvatar::updateDrawable(BOOL force_damped)
- {
- clearChanged(SHIFTED);
- }
- void LLVOAvatar::onShift(const LLVector3& shift_vector)
- {
- mLastAnimExtents[0] += shift_vector;
- mLastAnimExtents[1] += shift_vector;
- mNeedsImpostorUpdate = TRUE;
- mNeedsAnimUpdate = TRUE;
- }
- void LLVOAvatar::updateSpatialExtents(LLVector3& newMin, LLVector3 &newMax)
- {
- if (isImpostor() && !needsImpostorUpdate())
- {
- LLVector3 delta = getRenderPosition() -
- ((LLVector3(mDrawable->getPositionGroup())-mImpostorOffset));
-
- newMin = mLastAnimExtents[0] + delta;
- newMax = mLastAnimExtents[1] + delta;
- }
- else
- {
- getSpatialExtents(newMin,newMax);
- mLastAnimExtents[0] = newMin;
- mLastAnimExtents[1] = newMax;
- LLVector3 pos_group = (newMin+newMax)*0.5f;
- mImpostorOffset = pos_group-getRenderPosition();
- mDrawable->setPositionGroup(pos_group);
- }
- }
- void LLVOAvatar::getSpatialExtents(LLVector3& newMin, LLVector3& newMax)
- {
- LLVector3 buffer(0.25f, 0.25f, 0.25f);
- LLVector3 pos = getRenderPosition();
- newMin = pos - buffer;
- newMax = pos + buffer;
- float max_attachment_span = DEFAULT_MAX_PRIM_SCALE * 5.0f;
-
- //stretch bounding box by joint positions
- for (polymesh_map_t::iterator i = mMeshes.begin(); i != mMeshes.end(); ++i)
- {
- LLPolyMesh* mesh = i->second;
- for (S32 joint_num = 0; joint_num < mesh->mJointRenderData.count(); joint_num++)
- {
- update_min_max(newMin, newMax,
- mesh->mJointRenderData[joint_num]->mWorldMatrix->getTranslation());
- }
- }
- mPixelArea = LLPipeline::calcPixelArea((newMin+newMax)*0.5f, (newMax-newMin)*0.5f, *LLViewerCamera::getInstance());
- //stretch bounding box by attachments
- for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
- iter != mAttachmentPoints.end();
- ++iter)
- {
- LLViewerJointAttachment* attachment = iter->second;
- if (!attachment->getValid())
- {
- continue ;
- }
- for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
- attachment_iter != attachment->mAttachedObjects.end();
- ++attachment_iter)
- {
- const LLViewerObject* attached_object = (*attachment_iter);
- if (attached_object && !attached_object->isHUDAttachment())
- {
- LLDrawable* drawable = attached_object->mDrawable;
- if (drawable)
- {
- LLSpatialBridge* bridge = drawable->getSpatialBridge();
- if (bridge)
- {
- const LLVector3* ext = bridge->getSpatialExtents();
- LLVector3 distance = (ext[1] - ext[0]);
-
- // Only add the prim to spatial extents calculations if it isn't a megaprim.
- // max_attachment_span calculated at the start of the function
- // (currently 5 times our max prim size)
- if (distance.mV[0] < max_attachment_span
- && distance.mV[1] < max_attachment_span
- && distance.mV[2] < max_attachment_span)
- {
- update_min_max(newMin,newMax,ext[0]);
- update_min_max(newMin,newMax,ext[1]);
- }
- }
- }
- }
- }
- }
- //pad bounding box
- newMin -= buffer;
- newMax += buffer;
- }
- //-----------------------------------------------------------------------------
- // renderCollisionVolumes()
- //-----------------------------------------------------------------------------
- void LLVOAvatar::renderCollisionVolumes()
- {
- for (S32 i = 0; i < mNumCollisionVolumes; i++)
- {
- mCollisionVolumes[i].renderCollision();
- }
- if (mNameText.notNull())
- {
- LLVector3 unused;
- mNameText->lineSegmentIntersect(LLVector3(0,0,0), LLVector3(0,0,1), unused, TRUE);
- }
- }
- BOOL LLVOAvatar::lineSegmentIntersect(const LLVector3& start, const LLVector3& end,
- S32 face,
- BOOL pick_transparent,
- S32* face_hit,
- LLVector3* intersection,
- LLVector2* tex_coord,
- LLVector3* normal,
- LLVector3* bi_normal)
- {
- if ((isSelf() && !gAgent.needsRenderAvatar()) || !LLPipeline::sPickAvatar)
- {
- return FALSE;
- }
- if (lineSegmentBoundingBox(start, end))
- {
- for (S32 i = 0; i < mNumCollisionVolumes; ++i)
- {
- mCollisionVolumes[i].updateWorldMatrix();
- glh::matrix4f mat((F32*) mCollisionVolumes[i].getXform()->getWorldMatrix().mMatrix);
- glh::matrix4f inverse = mat.inverse();
- glh::matrix4f norm_mat = inverse.transpose();
- glh::vec3f p1(start.mV);
- glh::vec3f p2(end.mV);
- inverse.mult_matrix_vec(p1);
- inverse.mult_matrix_vec(p2);
- LLVector3 position;
- LLVector3 norm;
- if (linesegment_sphere(LLVector3(p1.v), LLVector3(p2.v), LLVector3(0,0,0), 1.f, position, norm))
- {
- glh::vec3f res_pos(position.mV);
- mat.mult_matrix_vec(res_pos);
-
- norm.normalize();
- glh::vec3f res_norm(norm.mV);
- norm_mat.mult_matrix_dir(res_norm);
- if (intersection)
- {
- *intersection = LLVector3(res_pos.v);
- }
- if (normal)
- {
- *normal = LLVector3(res_norm.v);
- }
- return TRUE;
- }
- }
- }
-
- LLVector3 position;
- if (mNameText.notNull() && mNameText->lineSegmentIntersect(start, end, position))
- {
- if (intersection)
- {
- *intersection = position;
- }
- return TRUE;
- }
- return FALSE;
- }
- //-----------------------------------------------------------------------------
- // parseSkeletonFile()
- //-----------------------------------------------------------------------------
- BOOL LLVOAvatar::parseSkeletonFile(const std::string& filename)
- {
- LLMemType mt(LLMemType::MTYPE_AVATAR);
-
- //-------------------------------------------------------------------------
- // parse the file
- //-------------------------------------------------------------------------
- BOOL parsesuccess = sSkeletonXMLTree.parseFile( filename, FALSE );
- if (!parsesuccess)
- {
- llerrs << "Can't parse skeleton file: " << filename << llendl;
- return FALSE;
- }
- // now sanity check xml file
- LLXmlTreeNode* root = sSkeletonXMLTree.getRoot();
- if (!root)
- {
- llerrs << "No root node found in avatar skeleton file: " << filename << llendl;
- return FALSE;
- }
- if( !root->hasName( "linden_skeleton" ) )
- {
- llerrs << "Invalid avatar skeleton file header: " << filename << llendl;
- return FALSE;
- }
- std::string version;
- static LLStdStringHandle version_string = LLXmlTree::addAttributeString("version");
- if( !root->getFastAttributeString( version_string, version ) || (version != "1.0") )
- {
- llerrs << "Invalid avatar skeleton file version: " << version << " in file: " << filename << llendl;
- return FALSE;
- }
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- // setupBone()
- //-----------------------------------------------------------------------------
- BOOL LLVOAvatar::setupBone(const LLVOAvatarBoneInfo* info, LLViewerJoint* parent, S32 &volume_num, S32 &joint_num)
- {
- LLMemType mt(LLMemType::MTYPE_AVATAR);
-
- LLViewerJoint* joint = NULL;
- if (info->mIsJoint)
- {
- joint = (LLViewerJoint*)getCharacterJoint(joint_num);
- if (!joint)
- {
- llwarns << "Too many bones" << llendl;
- return FALSE;
- }
- joint->setName( info->mName );
- }
- else // collision volume
- {
- if (volume_num >= (S32)mNumCollisionVolumes)
- {
- llwarns << "Too many bones" << llendl;
- return FALSE;
- }
- joint = (LLViewerJoint*)(&mCollisionVolumes[volume_num]);
- joint->setName( info->mName );
- }
- // add to parent
- if (parent)
- {
- parent->addChild( joint );
- }
- joint->setPosition(info->mPos);
- joint->setRotation(mayaQ(info->mRot.mV[VX], info->mRot.mV[VY],
- info->mRot.mV[VZ], LLQuaternion::XYZ));
- joint->setScale(info->mScale);
- if (info->mIsJoint)
- {
- joint->setSkinOffset( info->mPivot );
- joint_num++;
- }
- else // collision volume
- {
- volume_num++;
- }
- // setup children
- LLVOAvatarBoneInfo::child_list_t::const_iterator iter;
- for (iter = info->mChildList.begin(); iter != info->mChildList.end(); ++iter)
- {
- LLVOAvatarBoneInfo *child_info = *iter;
- if (!setupBone(child_info, joint, volume_num, joint_num))
- {
- return FALSE;
- }
- }
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- // buildSkeleton()
- //-----------------------------------------------------------------------------
- BOOL LLVOAvatar::buildSkeleton(const LLVOAvatarSkeletonInfo *info)
- {
- LLMemType mt(LLMemType::MTYPE_AVATAR);
-
- //-------------------------------------------------------------------------
- // allocate joints
- //-------------------------------------------------------------------------
- if (!allocateCharacterJoints(info->mNumBones))
- {
- llerrs << "Can't allocate " << info->mNumBones << " joints" << llendl;
- return FALSE;
- }
-
- //-------------------------------------------------------------------------
- // allocate volumes
- //-------------------------------------------------------------------------
- if (info->mNumCollisionVolumes)
- {
- if (!allocateCollisionVolumes(info->mNumCollisionVolumes))
- {
- llerrs << "Can't allocate " << info->mNumCollisionVolumes << " collision volumes" << llendl;
- return FALSE;
- }
- }
- S32 current_joint_num = 0;
- S32 current_volume_num = 0;
- LLVOAvatarSkeletonInfo::bone_info_list_t::const_iterator iter;
- for (iter = info->mBoneInfoList.begin(); iter != info->mBoneInfoList.end(); ++iter)
- {
- LLVOAvatarBoneInfo *info = *iter;
- if (!setupBone(info, NULL, current_volume_num, current_joint_num))
- {
- llerrs << "Error parsing bone in skeleton file" << llendl;
- return FALSE;
- }
- }
- return TRUE;
- }
- LLVOAvatar* LLVOAvatar::asAvatar()
- {
- return this;
- }
- //-----------------------------------------------------------------------------
- // LLVOAvatar::startDefaultMotions()
- //-----------------------------------------------------------------------------
- void LLVOAvatar::startDefaultMotions()
- {
- //-------------------------------------------------------------------------
- // start default motions
- //-------------------------------------------------------------------------
- startMotion( ANIM_AGENT_HEAD_ROT );
- startMotion( ANIM_AGENT_EYE );
- startMotion( ANIM_AGENT_BODY_NOISE );
- startMotion( ANIM_AGENT_BREATHE_ROT );
- startMotion( ANIM_AGENT_HAND_MOTION );
- startMotion( ANIM_AGENT_PELVIS_FIX );
- //-------------------------------------------------------------------------
- // restart any currently active motions
- //-------------------------------------------------------------------------
- processAnimationStateChanges();
- }
- //-----------------------------------------------------------------------------
- // LLVOAvatar::buildCharacter()
- // Deferred initialization and rebuild of the avatar.
- //-----------------------------------------------------------------------------
- void LLVOAvatar::buildCharacter()
- {
- LLMemType mt(LLMemType::MTYPE_AVATAR);
-
- //-------------------------------------------------------------------------
- // remove all references to our existing skeleton
- // so we can rebuild it
- //-------------------------------------------------------------------------
- flushAllMotions();
- //-------------------------------------------------------------------------
- // remove all of mRoot's children
- //-------------------------------------------------------------------------
- mRoot.removeAllChildren();
- mIsBuilt = FALSE;
- //-------------------------------------------------------------------------
- // clear mesh data
- //-------------------------------------------------------------------------
- for (std::vector<LLViewerJoint*>::iterator jointIter = mMeshLOD.begin();
- jointIter != mMeshLOD.end(); ++jointIter)
- {
- LLViewerJoint* joint = (LLViewerJoint*) *jointIter;
- for (std::vector<LLViewerJointMesh*>::iterator meshIter = joint->mMeshParts.begin();
- meshIter != joint->mMeshParts.end(); ++meshIter)
- {
- LLViewerJointMesh * mesh = (LLViewerJointMesh *) *meshIter;
- mesh->setMesh(NULL);
- }
- }
- //-------------------------------------------------------------------------
- // (re)load our skeleton and meshes
- //-------------------------------------------------------------------------
- LLTimer timer;
- BOOL status = loadAvatar();
- stop_glerror();
- if (gNoRender)
- {
- // Still want to load the avatar skeleton so visual parameters work.
- return;
- }
- // gPrintMessagesThisFrame = TRUE;
- lldebugs << "Avatar load took " << timer.getElapsedTimeF32() << " seconds." << llendl;
- if (!status)
- {
- if (isSelf())
- {
- llerrs << "Unable to load user's avatar" << llendl;
- }
- else
- {
- llwarns << "Unable to load other's avatar" << llendl;
- }
- return;
- }
- //-------------------------------------------------------------------------
- // initialize "well known" joint pointers
- //-------------------------------------------------------------------------
- mPelvisp = (LLViewerJoint*)mRoot.findJoint("mPelvis");
- mTorsop = (LLViewerJoint*)mRoot.findJoint("mTorso");
- mChestp = (LLViewerJoint*)mRoot.findJoint("mChest");
- mNeckp = (LLViewerJoint*)mRoot.findJoint("mNeck");
- mHeadp = (LLViewerJoint*)mRoot.findJoint("mHead");
- mSkullp = (LLViewerJoint*)mRoot.findJoint("mSkull");
- mHipLeftp = (LLViewerJoint*)mRoot.findJoint("mHipLeft");
- mHipRightp = (LLViewerJoint*)mRoot.findJoint("mHipRight");
- mKneeLeftp = (LLViewerJoint*)mRoot.findJoint("mKneeLeft");
- mKneeRightp = (LLViewerJoint*)mRoot.findJoint("mKneeRight");
- mAnkleLeftp = (LLViewerJoint*)mRoot.findJoint("mAnkleLeft");
- mAnkleRightp = (LLViewerJoint*)mRoot.findJoint("mAnkleRight");
- mFootLeftp = (LLViewerJoint*)mRoot.findJoint("mFootLeft");
- mFootRightp = (LLViewerJoint*)mRoot.findJoint("mFootRight");
- mWristLeftp = (LLViewerJoint*)mRoot.findJoint("mWristLeft");
- mWristRightp = (LLViewerJoint*)mRoot.findJoint("mWristRight");
- mEyeLeftp = (LLViewerJoint*)mRoot.findJoint("mEyeLeft");
- mEyeRightp = (LLViewerJoint*)mRoot.findJoint("mEyeRight");
- //-------------------------------------------------------------------------
- // Make sure "well known" pointers exist
- //-------------------------------------------------------------------------
- if (!(mPelvisp &&
- mTorsop &&
- mChestp &&
- mNeckp &&
- mHeadp &&
- mSkullp &&
- mHipLeftp &&
- mHipRightp &&
- mKneeLeftp &&
- mKneeRightp &&
- mAnkleLeftp &&
- mAnkleRightp &&
- mFootLeftp &&
- mFootRightp &&
- mWristLeftp &&
- mWristRightp &&
- mEyeLeftp &&
- mEyeRightp))
- {
- llerrs << "Failed to create avatar." << llendl;
- return;
- }
- //-------------------------------------------------------------------------
- // initialize the pelvis
- //-------------------------------------------------------------------------
- mPelvisp->setPosition( LLVector3(0.0f, 0.0f, 0.0f) );
-
- //-------------------------------------------------------------------------
- // set head offset from pelvis
- //-------------------------------------------------------------------------
- updateHeadOffset();
- //-------------------------------------------------------------------------
- // initialize lip sync morph pointers
- //-------------------------------------------------------------------------
- mOohMorph = getVisualParam( "Lipsync_Ooh" );
- mAahMorph = getVisualParam( "Lipsync_Aah" );
- // If we don't have the Ooh morph, use the Kiss morph
- if (!mOohMorph)
- {
- llwarns << "Missing 'Ooh' morph for lipsync, using fallback." << llendl;
- mOohMorph = getVisualParam( "Express_Kiss" );
- }
- // If we don't have the Aah morph, use the Open Mouth morph
- if (!mAahMorph)
- {
- llwarns << "Missing 'Aah' morph for lipsync, using fallback." << llendl;
- mAahMorph = getVisualParam( "Express_Open_Mouth" );
- }
- startDefaultMotions();
- //-------------------------------------------------------------------------
- // restart any currently active motions
- //-------------------------------------------------------------------------
- processAnimationStateChanges();
- mIsBuilt = TRUE;
- stop_glerror();
- mMeshValid = TRUE;
- }
- //-----------------------------------------------------------------------------
- // releaseMeshData()
- //-----------------------------------------------------------------------------
- void LLVOAvatar::releaseMeshData()
- {
- LLMemType mt(LLMemType::MTYPE_AVATAR);
-
- if (sInstances.size() < AVATAR_RELEASE_THRESHOLD || mIsDummy)
- {
- return;
- }
- //llinfos << "Releasing" << llendl;
- // cleanup mesh data
- for (std::vector<LLViewerJoint*>::iterator iter = mMeshLOD.begin();
- iter != mMeshLOD.end();
- ++iter)
- {
- LLViewerJoint* joint = (LLViewerJoint*) *iter;
- joint->setValid(FALSE, TRUE);
- }
- //cleanup data
- if (mDrawable.notNull())
- {
- LLFace* facep = mDrawable->getFace(0);
- facep->setSize(0, 0);
- for(S32 i = mNumInitFaces ; i < mDrawable->getNumFaces(); i++)
- {
- facep = mDrawable->getFace(i);
- facep->setSize(0, 0);
- }
- }
-
- for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
- iter != mAttachmentPoints.end();
- ++iter)
- {
- LLViewerJointAttachment* attachment = iter->second;
- if (!attachment->getIsHUDAttachment())
- {
- attachment->setAttachmentVisibility(FALSE);
- }
- }
- mMeshValid = FALSE;
- }
- //-----------------------------------------------------------------------------
- // restoreMeshData()
- //-----------------------------------------------------------------------------
- // virtual
- void LLVOAvatar::restoreMeshData()
- {
- llassert(!isSelf());
- LLMemType mt(LLMemType::MTYPE_AVATAR);
-
- //llinfos << "Restoring" << llendl;
- mMeshValid = TRUE;
- updateJointLODs();
- for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
- iter != mAttachmentPoints.end();
- ++iter)
- {
- LLViewerJointAttachment* attachment = iter->second;
- if (!attachment->getIsHUDAttachment())
- {
- attachment->setAttachmentVisibility(TRUE);
- }
- }
- // force mesh update as LOD might not have changed to trigger this
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY, TRUE);
- }
- //-----------------------------------------------------------------------------
- // updateMeshData()
- //-----------------------------------------------------------------------------
- void LLVOAvatar::updateMeshData()
- {
- if (mDrawable.notNull())
- {
- stop_glerror();
- S32 f_num = 0 ;
- const U32 VERTEX_NUMBER_THRESHOLD = 128 ;//small number of this means each part of an avatar has its own vertex buffer.
- const S32 num_parts = mMeshLOD.size();
- // this order is determined by number of LODS
- // if a mesh earlier in this list changed LODs while a later mesh doesn't,
- // the later mesh's index offset will be inaccurate
- for(S32 part_index = 0 ; part_index < num_parts ;)
- {
- S32 j = part_index ;
- U32 last_v_num = 0, num_vertices = 0 ;
- U32 last_i_num = 0, num_indices = 0 ;
- while(part_index < num_parts && num_vertices < VERTEX_NUMBER_THRESHOLD)
- {
- last_v_num = num_vertices ;
- last_i_num = num_indices ;
- mMeshLOD[part_index++]->updateFaceSizes(num_vertices, num_indices, mAdjustedPixelArea);
- }
- if(num_vertices < 1)//skip empty meshes
- {
- break ;
- }
- if(last_v_num > 0)//put the last inserted part into next vertex buffer.
- {
- num_vertices = last_v_num ;
- num_indices = last_i_num ;
- part_index-- ;
- }
-
- LLFace* facep ;
- if(f_num < mDrawable->getNumFaces())
- {
- facep = mDrawable->getFace(f_num);
- }
- else
- {
- facep = mDrawable->addFace(mDrawable->getFace(0)->getPool(), mDrawable->getFace(0)->getTexture()) ;
- }
-
- // resize immediately
- facep->setSize(num_vertices, num_indices);
- if(facep->mVertexBuffer.isNull())
- {
- facep->mVertexBuffer = new LLVertexBufferAvatar();
- facep->mVertexBuffer->allocateBuffer(num_vertices, num_indices, TRUE);
- }
- else
- {
- facep->mVertexBuffer->resizeBuffer(num_vertices, num_indices) ;
- }
-
- facep->setGeomIndex(0);
- facep->setIndicesIndex(0);
-
- // This is a hack! Avatars have their own pool, so we are detecting
- // the case of more than one avatar in the pool (thus > 0 instead of >= 0)
- if (facep->getGeomIndex() > 0)
- {
- llerrs << "non-zero geom index: " << facep->getGeomIndex() << " in LLVOAvatar::restoreMeshData" << llendl;
- }
- for(S32 k = j ; k < part_index ; k++)
- {
- mMeshLOD[k]->updateFaceData(facep, mAdjustedPixelArea, k == MESH_ID_HAIR);
- }
- stop_glerror();
- facep->mVertexBuffer->setBuffer(0);
- if(!f_num)
- {
- f_num += mNumInitFaces ;
- }
- else
- {
- f_num++ ;
- }
- }
- }
- }
- //------------------------------------------------------------------------
- //------------------------------------------------------------------------
- // The viewer can only suggest a good size for the agent,
- // the simulator will keep it inside a reasonable range.
- void LLVOAvatar::computeBodySize()
- {
- LLVector3 pelvis_scale = mPelvisp->getScale();
- // some of the joints have not been cached
- LLVector3 skull = mSkullp->getPosition();
- LLVector3 skull_scale = mSkullp->getScale();
- LLVector3 neck = mNeckp->getPosition();
- LLVector3 neck_scale = mNeckp->getScale();
- LLVector3 chest = mChestp->getPosition();
- LLVector3 chest_scale = mChestp->getScale();
- // the rest of the joints have been cached
- LLVector3 head = mHeadp->getPosition();
- LLVector3 head_scale = mHeadp->getScale();
- LLVector3 torso = mTorsop->getPosition();
- LLVector3 torso_scale = mTorsop->getScale();
- LLVector3 hip = mHipLeftp->getPosition();
- LLVector3 hip_scale = mHipLeftp->getScale();
- LLVector3 knee = mKneeLeftp->getPosition();
- LLVector3 knee_scale = mKneeLeftp->getScale();
- LLVector3 ankle = mAnkleLeftp->getPosition();
- LLVector3 ankle_scale = mAnkleLeftp->getScale();
- LLVector3 foot = mFootLeftp->getPosition();
- mPelvisToFoot = hip.mV[VZ] * pelvis_scale.mV[VZ] -
- knee.mV[VZ] * hip_scale.mV[VZ] -
- ankle.mV[VZ] * knee_scale.mV[VZ] -
- foot.mV[VZ] * ankle_scale.mV[VZ];
- mBodySize.mV[VZ] = mPelvisToFoot +
- // the sqrt(2) correction below is an approximate
- // correction to get to the top of the head
- F_SQRT2 * (skull.mV[VZ] * head_scale.mV[VZ]) +
- head.mV[VZ] * neck_scale.mV[VZ] +
- neck.mV[VZ] * chest_scale.mV[VZ] +
- chest.mV[VZ] * torso_scale.mV[VZ] +
- torso.mV[VZ] * pelvis_scale.mV[VZ];
- // TODO -- measure the real depth and width
- mBodySize.mV[VX] = DEFAULT_AGENT_DEPTH;
- mBodySize.mV[VY] = DEFAULT_AGENT_WIDTH;
- /* debug spam
- std::cout << "skull = " << skull << std::endl; // adebug
- std::cout << "head = " << head << std::endl; // adebug
- std::cout << "head_scale = " << head_scale << std::endl; // adebug
- std::cout << "neck = " << neck << std::endl; // adebug
- std::cout << "neck_scale = " << neck_scale << std::endl; // adebug
- std::cout << "chest = " << chest << std::endl; // adebug
- std::cout << "chest_scale = " << chest_scale << std::endl; // adebug
- std::cout << "torso = " << torso << std::endl; // adebug
- std::cout << "torso_scale = " << torso_scale << std::endl; // adebug
- std::cout << std::endl; // adebug
- std::cout << "pelvis_scale = " << pelvis_scale << std::endl;// adebug
- std::cout << std::endl; // adebug
- std::cout << "hip = " << hip << std::endl; // adebug
- std::cout << "hip_scale = " << hip_scale << std::endl; // adebug
- std::cout << "ankle = " << ankle << std::endl; // adebug
- std::cout << "ankle_scale = " << ankle_scale << std::endl; // adebug
- std::cout << "foot = " << foot << std::endl; // adebug
- std::cout << "mBodySize = " << mBodySize << std::endl; // adebug
- std::cout << "mPelvisToFoot = " << mPelvisToFoot << std::endl; // adebug
- std::cout << std::endl; // adebug
- */
- }
- //------------------------------------------------------------------------
- // LLVOAvatar::processUpdateMessage()
- //------------------------------------------------------------------------
- U32 LLVOAvatar::processUpdateMessage(LLMessageSystem *mesgsys,
- void **user_data,
- U32 block_num, const EObjectUpdateType update_type,
- LLDataPacker *dp)
- {
- LLMemType mt(LLMemType::MTYPE_AVATAR);
-
- LLVector3 old_vel = getVelocity();
- // Do base class updates...
- U32 retval = LLViewerObject::processUpdateMessage(mesgsys, user_data, block_num, update_type, dp);
- if(retval & LLViewerObject::INVALID_UPDATE)
- {
- if(this == gAgent.getAvatarObject())
- {
- //tell sim to cancel this update
- gAgent.teleportViaLocation(gAgent.getPositionGlobal());
- }
- }
- //llinfos << getRotation() << llendl;
- //llinfos << getPosition() << llendl;
- return retval;
- }
- // virtual
- S32 LLVOAvatar::setTETexture(const U8 te, const LLUUID& uuid)
- {
- // The core setTETexture() method requests images, so we need
- // to redirect certain avatar texture requests to different sims.
- if (isIndexBakedTexture((ETextureIndex)te))
- {
- LLHost target_host = getObjectHost();
- return setTETextureCore(te, uuid, target_host);
- }
- else
- {
- return setTETextureCore(te, uuid, LLHost::invalid);
- }
- }
- static LLFastTimer::DeclareTimer FTM_AVATAR_UPDATE("Update Avatar");
- static LLFastTimer::DeclareTimer FTM_JOINT_UPDATE("Update Joints");
- //------------------------------------------------------------------------
- // idleUpdate()
- //------------------------------------------------------------------------
- BOOL LLVOAvatar::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time)
- {
- LLMemType mt(LLMemType::MTYPE_AVATAR);
- LLFastTimer t(FTM_AVATAR_UPDATE);
- if (isDead())
- {
- llinfos << "Warning! Idle on dead avatar" << llendl;
- return TRUE;
- }
- if (!(gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_AVATAR)))
- {
- return TRUE;
- }
-
- // force immediate pixel area update on avatars using last frames data (before drawable or camera updates)
- setPixelAreaAndAngle(gAgent);
- // force asynchronous drawable update
- if(mDrawable.notNull() && !gNoRender)
- {
- LLFastTimer t(FTM_JOINT_UPDATE);
-
- if (mIsSitting && getParent())
- {
- LLViewerObject *root_object = (LLViewerObject*)getRoot();
- LLDrawable* drawablep = root_object->mDrawable;
- // if this object hasn't already been updated by another avatar...
- if (drawablep) // && !drawablep->isState(LLDrawable::EARLY_MOVE))
- {
- if (root_object->isSelected())
- {
- gPipeline.updateMoveNormalAsync(drawablep);
- }
- else
- {
- gPipeline.updateMoveDampedAsync(drawablep);
- }
- }
- }
- else
- {
- gPipeline.updateMoveDampedAsync(mDrawable);
- }
- }
- //--------------------------------------------------------------------
- // set alpha flag depending on state
- //--------------------------------------------------------------------
- if (isSelf())
- {
- LLViewerObject::idleUpdate(agent, world, time);
-
- // trigger fidget anims
- if (isAnyAnimationSignaled(AGENT_STAND_ANIMS, NUM_AGENT_STAND_ANIMS))
- {
- agent.fidget();
- }
- }
- else
- {
- // Should override the idleUpdate stuff and leave out the angular update part.
- LLQuaternion rotation = getRotation();
- LLViewerObject::idleUpdate(agent, world, time);
- setRotation(rotation);
- }
- // attach objects that were waiting for a drawable
- lazyAttach();
-
- // animate the character
- // store off last frame's root position to be consistent with camera position
- LLVector3 root_pos_last = mRoot.getWorldPosition();
- BOOL detailed_update = updateCharacter(agent);
- if (gNoRender)
- {
- return TRUE;
- }
- static LLUICachedControl<bool> visualizers_in_calls("ShowVoiceVisualizersInCalls", false);
- bool voice_enabled = (visualizers_in_calls || gVoiceClient->inProximalChannel()) &&
- gVoiceClient->getVoiceEnabled(mID);
- idleUpdateVoiceVisualizer( voice_enabled );
- idleUpdateMisc( detailed_update );
- idleUpdateAppearanceAnimation();
- if (detailed_update)
- {
- idleUpdateLipSync( voice_enabled );
- idleUpdateLoadingEffect();
- idleUpdateBelowWater(); // wind effect uses this
- idleUpdateWindEffect();
- }
-
- idleUpdateNameTag( root_pos_last );
- idleUpdateRenderCost();
- idleUpdateTractorBeam();
- return TRUE;
- }
- void LLVOAvatar::idleUpdateVoiceVisualizer(bool voice_enabled)
- {
- // disable voice visualizer when in mouselook
- mVoiceVisualizer->setVoiceEnabled( voice_enabled && !(isSelf() && gAgent.cameraMouselook()) );
- if ( voice_enabled )
- {
- //----------------------------------------------------------------
- // Only do gesture triggering for your own avatar, and only when you're in a proximal channel.
- //----------------------------------------------------------------
- if( isSelf() )
- {
- //----------------------------------------------------------------------------------------
- // The following takes the voice signal and uses that to trigger gesticulations.
- //----------------------------------------------------------------------------------------
- int lastGesticulationLevel = mCurrentGesticulationLevel;
- mCurrentGesticulationLevel = mVoiceVisualizer->getCurrentGesticulationLevel();
-
- //---------------------------------------------------------------------------------------------------
- // If "current gesticulation level" changes, we catch this, and trigger the new gesture
- //---------------------------------------------------------------------------------------------------
- if ( lastGesticulationLevel != mCurrentGesticulationLevel )
- {
- if ( mCurrentGesticulationLevel != VOICE_GESTICULATION_LEVEL_OFF )
- {
- std::string gestureString = "unInitialized";
- if ( mCurrentGesticulationLevel == 0 ) { gestureString = "/voicelevel1"; }
- else if ( mCurrentGesticulationLevel == 1 ) { gestureString = "/voicelevel2"; }
- else if ( mCurrentGesticulationLevel == 2 ) { gestureString = "/voicelevel3"; }
- else { llinfos << "oops - CurrentGesticulationLevel can be only 0, 1, or 2" << llendl; }
-
- // this is the call that Karl S. created for triggering gestures from within the code.
- LLGestureManager::instance().triggerAndReviseString( gestureString );
- }
- }
-
- } //if( isSelf() )
-
- //-----------------------------------------------------------------------------------------------------------------
- // If the avatar is speaking, then the voice amplitude signal is passed to the voice visualizer.
- // Also, here we trigger voice visualizer start and stop speaking, so it can animate the voice symbol.
- //
- // Notice the calls to "gAwayTimer.reset()". This resets the timer that determines how long the avatar has been
- // "away", so that the avatar doesn't lapse into away-mode (and slump over) while the user is still talking.
- //-----------------------------------------------------------------------------------------------------------------
- if (gVoiceClient->getIsSpeaking( mID ))
- {
- if (!mVoiceVisualizer->getCurrentlySpeaking())
- {
- mVoiceVisualizer->setStartSpeaking();
-
- //printf( "gAwayTimer.reset();n" );
- }
-
- mVoiceVisualizer->setSpeakingAmplitude( gVoiceClient->getCurrentPower( mID ) );
-
- if( isSelf() )
- {
- gAgent.clearAFK();
- }
- }
- else
- {
- if ( mVoiceVisualizer->getCurrentlySpeaking() )
- {
- mVoiceVisualizer->setStopSpeaking();
-
- if ( mLipSyncActive )
- {
- if( mOohMorph ) mOohMorph->setWeight(mOohMorph->getMinWeight(), FALSE);
- if( mAahMorph ) mAahMorph->setWeight(mAahMorph->getMinWeight(), FALSE);
-
- mLipSyncActive = false;
- LLCharacter::updateVisualParams();
- dirtyMesh();
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------
- // here we get the approximate head position and set as sound source for the voice symbol
- // (the following version uses a tweak of "mHeadOffset" which handle sitting vs. standing)
- //--------------------------------------------------------------------------------------------
- LLVector3 headOffset = LLVector3( 0.0f, 0.0f, mHeadOffset.mV[2] );
- mVoiceVisualizer->setVoiceSourceWorldPosition( mRoot.getWorldPosition() + headOffset );
-
- }//if ( voiceEnabled )
- }
- static LLFastTimer::DeclareTimer FTM_ATTACHMENT_UPDATE("Update Attachments");
- void LLVOAvatar::idleUpdateMisc(bool detailed_update)
- {
- if (LLVOAvatar::sJointDebug)
- {
- llinfos << getFullname() << ": joint touches: " << LLJoint::sNumTouches << " updates: " << LLJoint::sNumUpdates << llendl;
- }
- LLJoint::sNumUpdates = 0;
- LLJoint::sNumTouches = 0;
- // *NOTE: this is necessary for the floating name text above your head.
- if (mDrawable.notNull())
- {
- gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_SHADOW, TRUE);
- }
- BOOL visible = isVisible() || mNeedsAnimUpdate;
- // update attachments positions
- if (detailed_update || !sUseImpostors)
- {
- LLFastTimer t(FTM_ATTACHMENT_UPDATE);
- for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
- iter != mAttachmentPoints.end();
- ++iter)
- {
- LLViewerJointAttachment* attachment = iter->second;
- for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
- attachment_iter != attachment->mAttachedObjects.end();
- ++attachment_iter)
- {
- LLViewerObject* attached_object = (*attachment_iter);
- BOOL visibleAttachment = visible || (attached_object &&
- !(attached_object->mDrawable->getSpatialBridge() &&
- attached_object->mDrawable->getSpatialBridge()->getRadius() < 2.0));
-
- if (visibleAttachment && attached_object && !attached_object->isDead() && attachment->getValid())
- {
- // if selecting any attachments, update all of them as non-damped
- if (LLSelectMgr::getInstance()->getSelection()->getObjectCount() && LLSelectMgr::getInstance()->getSelection()->isAttachment())
- {
- gPipeline.updateMoveNormalAsync(attached_object->mDrawable);
- }
- else
- {
- gPipeline.updateMoveDampedAsync(attached_object->mDrawable);
- }
-
- LLSpatialBridge* bridge = attached_object->mDrawable->getSpatialBridge();
- if (bridge)
- {
- gPipeline.updateMoveNormalAsync(bridge);
- }
- attached_object->updateText();
- }
- }
- }
- }
- mNeedsAnimUpdate = FALSE;
- if (isImpostor() && !mNeedsImpostorUpdate)
- {
- LLVector3 ext[2];
- F32 distance;
- LLVector3 angle;
- getImpostorValues(ext, angle, distance);
- for (U32 i = 0; i < 3 && !mNeedsImpostorUpdate; i++)
- {
- F32 cur_angle = angle.mV[i];
- F32 old_angle = mImpostorAngle.mV[i];
- F32 angle_diff = fabsf(cur_angle-old_angle);
-
- if (angle_diff > F_PI/512.f*distance*mUpdatePeriod)
- {
- mNeedsImpostorUpdate = TRUE;
- }
- }
- if (detailed_update && !mNeedsImpostorUpdate)
- { //update impostor if view angle, distance, or bounding box change
- //significantly
-
- F32 dist_diff = fabsf(distance-mImpostorDistance);
- if (dist_diff/mImpostorDistance > 0.1f)
- {
- mNeedsImpostorUpdate = TRUE;
- }
- else
- {
- getSpatialExtents(ext[0], ext[1]);
- if ((ext[1]-mImpostorExtents[1]).length() > 0.05f ||
- (ext[0]-mImpostorExtents[0]).length() > 0.05f)
- {
- mNeedsImpostorUpdate = TRUE;
- }
- }
- }
- }
- mDrawable->movePartition();
-
- //force a move if sitting on an active object
- if (getParent() && ((LLViewerObject*) getParent())->mDrawable->isActive())
- {
- gPipeline.markMoved(mDrawable, TRUE);
- }
- }
- void LLVOAvatar::idleUpdateAppearanceAnimation()
- {
- // update morphing params
- if (mAppearanceAnimating)
- {
- ESex avatar_sex = getSex();
- F32 appearance_anim_time = mAppearanceMorphTimer.getElapsedTimeF32();
- if (appearance_anim_time >= APPEARANCE_MORPH_TIME)
- {
- mAppearanceAnimating = FALSE;
- for (LLVisualParam *param = getFirstVisualParam();
- param;
- param = getNextVisualParam())
- {
- if (param->getGroup() == VISUAL_PARAM_GROUP_TWEAKABLE)
- {
- param->stopAnimating(FALSE);
- }
- }
- updateVisualParams();
- if (isSelf())
- {
- gAgent.sendAgentSetAppearance();
- }
- }
- else
- {
- F32 morph_amt = calcMorphAmount();
- LLVisualParam *param;
- if (!isSelf())
- {
- // animate only top level params for non-self avatars
- for (param = getFirstVisualParam();
- param;
- param = getNextVisualParam())
- {
- if (param->getGroup() == VISUAL_PARAM_GROUP_TWEAKABLE)
- {
- param->animate(morph_amt, FALSE);
- }
- }
- }
- // apply all params
- for (param = getFirstVisualParam();
- param;
- param = getNextVisualParam())
- {
- param->apply(avatar_sex);
- }
- mLastAppearanceBlendTime = appearance_anim_time;
- }
- dirtyMesh();
- }
- }
- F32 LLVOAvatar::calcMorphAmount()
- {
- F32 appearance_anim_time = mAppearanceMorphTimer.getElapsedTimeF32();
- F32 blend_frac = calc_bouncy_animation(appearance_anim_time / APPEARANCE_MORPH_TIME);
- F32 last_blend_frac = calc_bouncy_animation(mLastAppearanceBlendTime / APPEARANCE_MORPH_TIME);
- F32 morph_amt;
- if (last_blend_frac == 1.f)
- {
- morph_amt = 1.f;
- }
- else
- {
- morph_amt = (blend_frac - last_blend_frac) / (1.f - last_blend_frac);
- }
- return morph_amt;
- }
- void LLVOAvatar::idleUpdateLipSync(bool voice_enabled)
- {
- // Use the Lipsync_Ooh and Lipsync_Aah morphs for lip sync
- if ( voice_enabled && (gVoiceClient->lipSyncEnabled()) && gVoiceClient->getIsSpeaking( mID ) )
- {
- F32 ooh_morph_amount = 0.0f;
- F32 aah_morph_amount = 0.0f;
- mVoiceVisualizer->lipSyncOohAah( ooh_morph_amount, aah_morph_amount );
- if( mOohMorph )
- {
- F32 ooh_weight = mOohMorph->getMinWeight()
- + ooh_morph_amount * (mOohMorph->getMaxWeight() - mOohMorph->getMinWeight());
- mOohMorph->setWeight( ooh_weight, FALSE );
- }
- if( mAahMorph )
- {
- F32 aah_weight = mAahMorph->getMinWeight()
- + aah_morph_amount * (mAahMorph->getMaxWeight() - mAahMorph->getMinWeight());
- mAahMorph->setWeight( aah_weight, FALSE );
- }
- mLipSyncActive = true;
- LLCharacter::updateVisualParams();
- dirtyMesh();
- }
- }
- void LLVOAvatar::idleUpdateLoadingEffect()
- {
- // update visibility when avatar is partially loaded
- if (updateIsFullyLoaded()) // changed?
- {
- if (isFullyLoaded() && isSelf())
- {
- static bool first_fully_visible = true;
- if (first_fully_visible)
- {
- llinfos << "self isFullyLoaded, first_fully_visible" << llendl;
- first_fully_visible = false;
- LLAppearanceManager::instance().onFirstFullyVisible();
- }
- }
- if (isFullyLoaded())
- {
- deleteParticleSource();
- updateLOD();
- }
- else
- {
- LLPartSysData particle_parameters;
- // fancy particle cloud designed by Brent
- particle_parameters.mPartData.mMaxAge = 4.f;
- particle_parameters.mPartData.mStartScale.mV[VX] = 0.8f;
- particle_parameters.mPartData.mStartScale.mV[VX] = 0.8f;
- particle_parameters.mPartData.mStartScale.mV[VY] = 1.0f;
- particle_parameters.mPartData.mEndScale.mV[VX] = 0.02f;
- particle_parameters.mPartData.mEndScale.mV[VY] = 0.02f;
- particle_parameters.mPartData.mStartColor = LLColor4(1, 1, 1, 0.5f);
- particle_parameters.mPartData.mEndColor = LLColor4(1, 1, 1, 0.0f);
- particle_parameters.mPartData.mStartScale.mV[VX] = 0.8f;
- LLViewerTexture* cloud = LLViewerTextureManager::getFetchedTextureFromFile("cloud-particle.j2c");
- particle_parameters.mPartImageID = cloud->getID();
- particle_parameters.mMaxAge = 0.f;
- particle_parameters.mPattern = LLPartSysData::LL_PART_SRC_PATTERN_ANGLE_CONE;
- particle_parameters.mInnerAngle = F_PI;
- particle_parameters.mOuterAngle = 0.f;
- particle_parameters.mBurstRate = 0.02f;
- particle_parameters.mBurstRadius = 0.0f;
- particle_parameters.mBurstPartCount = 1;
- particle_parameters.mBurstSpeedMin = 0.1f;
- particle_parameters.mBurstSpeedMax = 1.f;
- particle_parameters.mPartData.mFlags = ( LLPartData::LL_PART_INTERP_COLOR_MASK | LLPartData::LL_PART_INTERP_SCALE_MASK |
- LLPartData::LL_PART_EMISSIVE_MASK | // LLPartData::LL_PART_FOLLOW_SRC_MASK |
- LLPartData::LL_PART_TARGET_POS_MASK );
-
- setParticleSource(particle_parameters, getID());
- }
- }
- }
- void LLVOAvatar::idleUpdateWindEffect()
- {
- // update wind effect
- if ((LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_AVATAR) >= LLDrawPoolAvatar::SHADER_LEVEL_CLOTH))
- {
- F32 hover_strength = 0.f;
- F32 time_delta = mRippleTimer.getElapsedTimeF32() - mRippleTimeLast;
- mRippleTimeLast = mRippleTimer.getElapsedTimeF32();
- LLVector3 velocity = getVelocity();
- F32 speed = velocity.length();
- //RN: velocity varies too much frame to frame for this to work
- mRippleAccel.clearVec();//lerp(mRippleAccel, (velocity - mLastVel) * time_delta, LLCriticalDamp::getInterpolant(0.02f));
- mLastVel = velocity;
- LLVector4 wind;
- wind.setVec(getRegion()->mWind.getVelocityNoisy(getPositionAgent(), 4.f) - velocity);
- if (mInAir)
- {
- hover_strength = HOVER_EFFECT_STRENGTH * llmax(0.f, HOVER_EFFECT_MAX_SPEED - speed);
- }
- if (mBelowWater)
- {
- // TODO: make cloth flow more gracefully when underwater
- hover_strength += UNDERWATER_EFFECT_STRENGTH;
- }
- wind.mV[VZ] += hover_strength;
- wind.normalize();
- wind.mV[VW] = llmin(0.025f + (speed * 0.015f) + hover_strength, 0.5f);
- F32 interp;
- if (wind.mV[VW] > mWindVec.mV[VW])
- {
- interp = LLCriticalDamp::getInterpolant(0.2f);
- }
- else
- {
- interp = LLCriticalDamp::getInterpolant(0.4f);
- }
- mWindVec = lerp(mWindVec, wind, interp);
-
- F32 wind_freq = hover_strength + llclamp(8.f + (speed * 0.7f) + (noise1(mRipplePhase) * 4.f), 8.f, 25.f);
- mWindFreq = lerp(mWindFreq, wind_freq, interp);
- if (mBelowWater)
- {
- mWindFreq *= UNDERWATER_FREQUENCY_DAMP;
- }
- mRipplePhase += (time_delta * mWindFreq);
- if (mRipplePhase > F_TWO_PI)
- {
- mRipplePhase = fmodf(mRipplePhase, F_TWO_PI);
- }
- }
- }
- void LLVOAvatar::idleUpdateNameTag(const LLVector3& root_pos_last)
- {
- // update chat bubble
- //--------------------------------------------------------------------
- // draw text label over characters head
- //--------------------------------------------------------------------
- if (mChatTimer.getElapsedTimeF32() > BUBBLE_CHAT_TIME)
- {
- mChats.clear();
- }
-
- const F32 time_visible = mTimeVisible.getElapsedTimeF32();
- const F32 NAME_SHOW_TIME = gSavedSettings.getF32("RenderNameShowTime"); // seconds
- const F32 FADE_DURATION = gSavedSettings.getF32("RenderNameFadeDuration"); // seconds
- BOOL visible_avatar = isVisible() || mNeedsAnimUpdate;
- BOOL visible_chat = gSavedSettings.getBOOL("UseChatBubbles") && (mChats.size() || mTyping);
- BOOL render_name = visible_chat ||
- (visible_avatar &&
- ((sRenderName == RENDER_NAME_ALWAYS) ||
- (sRenderName == RENDER_NAME_FADE && time_visible < NAME_SHOW_TIME)));
- // If it's your own avatar, don't draw in mouselook, and don't
- // draw if we're specifically hiding our own name.
- if (isSelf())
- {
- render_name = render_name
- && !gAgent.cameraMouselook()
- && (visible_chat || (gSavedSettings.getBOOL("RenderNameShowSelf")
- && gSavedSettings.getS32("AvatarNameTagMode") ));
- }
- if ( render_name )
- {
- BOOL new_name = FALSE;
- if (visible_chat != mVisibleChat)
- {
- mVisibleChat = visible_chat;
- new_name = TRUE;
- }
-
- if (sRenderGroupTitles != mRenderGroupTitles)
- {
- mRenderGroupTitles = sRenderGroupTitles;
- new_name = TRUE;
- }
- // First Calculate Alpha
- // If alpha > 0, create mNameText if necessary, otherwise delete it
- {
- F32 alpha = 0.f;
- if (mAppAngle > 5.f)
- {
- const F32 START_FADE_TIME = NAME_SHOW_TIME - FADE_DURATION;
- if (!visible_chat && sRenderName == RENDER_NAME_FADE && time_visible > START_FADE_TIME)
- {
- alpha = 1.f - (time_visible - START_FADE_TIME) / FADE_DURATION;
- }
- else
- {
- // ...not fading, full alpha
- alpha = 1.f;
- }
- }
- else if (mAppAngle > 2.f)
- {
- // far away is faded out also
- alpha = (mAppAngle-2.f)/3.f;
- }
- if (alpha > 0.f)
- {
- if (!mNameText)
- {
- mNameText = (LLHUDText *)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_TEXT);
- mNameText->setMass(10.f);
- mNameText->setSourceObject(this);
- mNameText->setVertAlignment(LLHUDText::ALIGN_VERT_TOP);
- mNameText->setVisibleOffScreen(TRUE);
- mNameText->setMaxLines(11);
- mNameText->setFadeDistance(CHAT_NORMAL_RADIUS, 5.f);
- mNameText->setUseBubble(TRUE);
- sNumVisibleChatBubbles++;
- new_name = TRUE;
- }
-
- LLColor4 avatar_name_color = LLUIColorTable::instance().getColor( "AvatarNameColor" );
- avatar_name_color.setAlpha(alpha);
- mNameText->setColor(avatar_name_color);
-
- LLQuaternion root_rot = mRoot.getWorldRotation();
- mNameText->setUsePixelSize(TRUE);
- LLVector3 pixel_right_vec;
- LLVector3 pixel_up_vec;
- LLViewerCamera::getInstance()->getPixelVectors(root_pos_last, pixel_up_vec, pixel_right_vec);
- LLVector3 camera_to_av = root_pos_last - LLViewerCamera::getInstance()->getOrigin();
- camera_to_av.normalize();
- LLVector3 local_camera_at = camera_to_av * ~root_rot;
- LLVector3 local_camera_up = camera_to_av % LLViewerCamera::getInstance()->getLeftAxis();
- local_camera_up.normalize();
- local_camera_up = local_camera_up * ~root_rot;
-
- local_camera_up.scaleVec(mBodySize * 0.5f);
- local_camera_at.scaleVec(mBodySize * 0.5f);
- LLVector3 name_position = mRoot.getWorldPosition() +
- (local_camera_up * root_rot) -
- (projected_vec(local_camera_at * root_rot, camera_to_av));
- name_position += pixel_up_vec * 15.f;
- mNameText->setPositionAgent(name_position);
- }
- else if (mNameText)
- {
- mNameText->markDead();
- mNameText = NULL;
- sNumVisibleChatBubbles--;
- }
- }
-
- LLNameValue *title = getNVPair("Title");
- LLNameValue* firstname = getNVPair("FirstName");
- LLNameValue* lastname = getNVPair("LastName");
- if (mNameText.notNull() && firstname && lastname)
- {
- BOOL is_away = mSignaledAnimations.find(ANIM_AGENT_AWAY) != mSignaledAnimations.end();
- BOOL is_busy = mSignaledAnimations.find(ANIM_AGENT_BUSY) != mSignaledAnimations.end();
- BOOL is_appearance = mSignaledAnimations.find(ANIM_AGENT_CUSTOMIZE) != mSignaledAnimations.end();
- BOOL is_muted;
- if (isSelf())
- {
- is_muted = FALSE;
- }
- else
- {
- is_muted = LLMuteList::getInstance()->isMuted(getID());
- }
- if (mNameString.empty() ||
- new_name ||
- (!title && !mTitle.empty()) ||
- (title && mTitle != title->getString()) ||
- (is_away != mNameAway || is_busy != mNameBusy || is_muted != mNameMute)
- || is_appearance != mNameAppearance)
- {
- std::string line;
- if (!sRenderGroupTitles)
- {
- // If all group titles are turned off, stack first name
- // on a line above last name
- line += firstname->getString();
- line += "n";
- }
- else if (title && title->getString() && title->getString()[0] != ' ')
- {
- line += title->getString();
- LLStringFn::replace_ascii_controlchars(line,LL_UNKNOWN_CHAR);
- line += "n";
- line += firstname->getString();
- }
- else
- {
- line += firstname->getString();
- }
- line += " ";
- line += lastname->getString();
- BOOL need_comma = FALSE;
- if (is_away || is_muted || is_busy)
- {
- line += " (";
- if (is_away)
- {
- line += LLTrans::getString("AvatarAway");
- need_comma = TRUE;
- }
- if (is_busy)
- {
- if (need_comma)
- {
- line += ", ";
- }
- line += LLTrans::getString("AvatarBusy");
- need_comma = TRUE;
- }
- if (is_muted)
- {
- if (need_comma)
- {
- line += ", ";
- }
- line += LLTrans::getString("AvatarMuted");
- need_comma = TRUE;
- }
- line += ")";
- }
- if (is_appearance)
- {
- line += "n";
- line += LLTrans::getString("AvatarEditingAppearance");
- }
- mNameAway = is_away;
- mNameBusy = is_busy;
- mNameMute = is_muted;
- mNameAppearance = is_appearance;
- mTitle = title ? title->getString() : "";
- LLStringFn::replace_ascii_controlchars(mTitle,LL_UNKNOWN_CHAR);
- mNameString = utf8str_to_wstring(line);
- new_name = TRUE;
- }
- if (visible_chat)
- {
- mNameText->setDropShadow(TRUE);
- mNameText->setFont(LLFontGL::getFontSansSerif());
- mNameText->setTextAlignment(LLHUDText::ALIGN_TEXT_LEFT);
- mNameText->setFadeDistance(CHAT_NORMAL_RADIUS * 2.f, 5.f);
- if (new_name)
- {
- mNameText->setLabel(mNameString);
- }
-
- char line[MAX_STRING]; /* Flawfinder: ignore */
- line[0] = ' ';
- std::deque<LLChat>::iterator chat_iter = mChats.begin();
- mNameText->clearString();
- LLColor4 new_chat = LLUIColorTable::instance().getColor( "AvatarNameColor" );
- LLColor4 normal_chat = lerp(new_chat, LLColor4(0.8f, 0.8f, 0.8f, 1.f), 0.7f);
- LLColor4 old_chat = lerp(normal_chat, LLColor4(0.6f, 0.6f, 0.6f, 1.f), 0.7f);
- if (mTyping && mChats.size() >= MAX_BUBBLE_CHAT_UTTERANCES)
- {
- ++chat_iter;
- }
- for(; chat_iter != mChats.end(); ++chat_iter)
- {
- F32 chat_fade_amt = llclamp((F32)((LLFrameTimer::getElapsedSeconds() - chat_iter->mTime) / CHAT_FADE_TIME), 0.f, 4.f);
- LLFontGL::StyleFlags style;
- switch(chat_iter->mChatType)
- {
- case CHAT_TYPE_WHISPER:
- style = LLFontGL::ITALIC;
- break;
- case CHAT_TYPE_SHOUT:
- style = LLFontGL::BOLD;
- break;
- default:
- style = LLFontGL::NORMAL;
- break;
- }
- if (chat_fade_amt < 1.f)
- {
- F32 u = clamp_rescale(chat_fade_amt, 0.9f, 1.f, 0.f, 1.f);
- mNameText->addLine(utf8str_to_wstring(chat_iter->mText), lerp(new_chat, normal_chat, u), style);
- }
- else if (chat_fade_amt < 2.f)
- {
- F32 u = clamp_rescale(chat_fade_amt, 1.9f, 2.f, 0.f, 1.f);
- mNameText->addLine(utf8str_to_wstring(chat_iter->mText), lerp(normal_chat, old_chat, u), style);
- }
- else if (chat_fade_amt < 3.f)
- {
- // *NOTE: only remove lines down to minimum number
- mNameText->addLine(utf8str_to_wstring(chat_iter->mText), old_chat, style);
- }
- }
- mNameText->setVisibleOffScreen(TRUE);
- if (mTyping)
- {
- S32 dot_count = (llfloor(mTypingTimer.getElapsedTimeF32() * 3.f) + 2) % 3 + 1;
- switch(dot_count)
- {
- case 1:
- mNameText->addLine(".", new_chat);
- break;
- case 2:
- mNameText->addLine("..", new_chat);
- break;
- case 3:
- mNameText->addLine("...", new_chat);
- break;
- }
- }
- }
- else
- {
- if (gSavedSettings.getBOOL("SmallAvatarNames"))
- {
- mNameText->setFont(LLFontGL::getFontSansSerif());
- }
- else
- {
- mNameText->setFont(LLFontGL::getFontSansSerifBig());
- }
- mNameText->setTextAlignment(LLHUDText::ALIGN_TEXT_CENTER);
- mNameText->setFadeDistance(CHAT_NORMAL_RADIUS, 5.f);
- mNameText->setVisibleOffScreen(FALSE);
- if (new_name)
- {
- mNameText->setLabel("");
- mNameText->setString(mNameString);
- }
- }
- }
- }
- else if (mNameText)
- {
- mNameText->markDead();
- mNameText = NULL;
- sNumVisibleChatBubbles--;
- }
- }
- //--------------------------------------------------------------------
- // draw tractor beam when editing objects
- //--------------------------------------------------------------------
- // virtual
- void LLVOAvatar::idleUpdateTractorBeam()
- {
- }
- void LLVOAvatar::idleUpdateBelowWater()
- {
- F32 avatar_height = (F32)(getPositionGlobal().mdV[VZ]);
- F32 water_height;
- water_height = getRegion()->getWaterHeight();
- mBelowWater = avatar_height < water_height;
- }
- void LLVOAvatar::slamPosition()
- {
- gAgent.setPositionAgent(getPositionAgent());
- mRoot.setWorldPosition(getPositionAgent()); // teleport
- setChanged(TRANSLATED);
- if (mDrawable.notNull())
- {
- gPipeline.updateMoveNormalAsync(mDrawable);
- }
- mRoot.updateWorldMatrixChildren();
- }
- //------------------------------------------------------------------------
- // updateCharacter()
- // called on both your avatar and other avatars
- //------------------------------------------------------------------------
- BOOL LLVOAvatar::updateCharacter(LLAgent &agent)
- {
- LLMemType mt(LLMemType::MTYPE_AVATAR);
- // clear debug text
- mDebugText.clear();
- if (LLVOAvatar::sShowAnimationDebug)
- {
- for (LLMotionController::motion_list_t::iterator iter = mMotionController.getActiveMotions().begin();
- iter != mMotionController.getActiveMotions().end(); ++iter)
- {
- LLMotion* motionp = *iter;
- if (motionp->getMinPixelArea() < getPixelArea())
- {
- std::string output;
- if (motionp->getName().empty())
- {
- output = llformat("%s - %d",
- motionp->getID().asString().c_str(),
- (U32)motionp->getPriority());
- }
- else
- {
- output = llformat("%s - %d",
- motionp->getName().c_str(),
- (U32)motionp->getPriority());
- }
- addDebugText(output);
- }
- }
- }
- if (gNoRender)
- {
- // Hack if we're running drones...
- if (isSelf())
- {
- gAgent.setPositionAgent(getPositionAgent());
- }
- return FALSE;
- }
- LLVector3d root_pos_global;
- if (!mIsBuilt)
- {
- return FALSE;
- }
- BOOL visible = isVisible();
- // For fading out the names above heads, only let the timer
- // run if we're visible.
- if (mDrawable.notNull() && !visible)
- {
- mTimeVisible.reset();
- }
- //--------------------------------------------------------------------
- // the rest should only be done occasionally for far away avatars
- //--------------------------------------------------------------------
- if (visible && !isSelf() && !mIsDummy && sUseImpostors && !mNeedsAnimUpdate && !sFreezeCounter)
- {
- F32 impostor_area = 256.f*512.f*(8.125f - LLVOAvatar::sLODFactor*8.f);
- if (LLMuteList::getInstance()->isMuted(getID()))
- { // muted avatars update at 16 hz
- mUpdatePeriod = 16;
- }
- else if (visible && mVisibilityRank <= LLVOAvatar::sMaxVisible * 0.25f)
- { //first 25% of max visible avatars are not impostored
- mUpdatePeriod = 1;
- }
- else if (visible && mVisibilityRank > LLVOAvatar::sMaxVisible * 0.75f)
- { //back 25% of max visible avatars are slow updating impostors
- mUpdatePeriod = 8;
- }
- else if (visible && mVisibilityRank > (U32) LLVOAvatar::sMaxVisible)
- { //background avatars are REALLY slow updating impostors
- mUpdatePeriod = 16;
- }
- else if (visible && mImpostorPixelArea <= impostor_area)
- { // stuff in between gets an update period based on pixel area
- mUpdatePeriod = llclamp((S32) sqrtf(impostor_area*4.f/mImpostorPixelArea), 2, 8);
- }
- else if (visible && mVisibilityRank > LLVOAvatar::sMaxVisible * 0.25f)
- { // force nearby impostors in ultra crowded areas
- mUpdatePeriod = 2;
- }
- else
- { // not impostored
- mUpdatePeriod = 1;
- }
- visible = (LLDrawable::getCurrentFrame()+mID.mData[0])%mUpdatePeriod == 0 ? TRUE : FALSE;
- }
- if (!visible)
- {
- updateMotions(LLCharacter::HIDDEN_UPDATE);
- return FALSE;
- }
- // change animation time quanta based on avatar render load
- if (!isSelf() && !mIsDummy)
- {
- F32 time_quantum = clamp_rescale((F32)sInstances.size(), 10.f, 35.f, 0.f, 0.25f);
- F32 pixel_area_scale = clamp_rescale(mPixelArea, 100, 5000, 1.f, 0.f);
- F32 time_step = time_quantum * pixel_area_scale;
- if (time_step != 0.f)
- {
- // disable walk motion servo controller as it doesn't work with motion timesteps
- stopMotion(ANIM_AGENT_WALK_ADJUST);
- removeAnimationData("Walk Speed");
- }
- mMotionController.setTimeStep(time_step);
- // llinfos << "Setting timestep to " << time_quantum * pixel_area_scale << llendl;
- }
- if (getParent() && !mIsSitting)
- {
- sitOnObject((LLViewerObject*)getParent());
- }
- else if (!getParent() && mIsSitting && !isMotionActive(ANIM_AGENT_SIT_GROUND_CONSTRAINED))
- {
- getOffObject();
- }
- //--------------------------------------------------------------------
- // create local variables in world coords for region position values
- //--------------------------------------------------------------------
- F32 speed;
- LLVector3 normal;
- LLVector3 xyVel = getVelocity();
- xyVel.mV[VZ] = 0.0f;
- speed = xyVel.length();
- BOOL throttle = TRUE;
- if (!(mIsSitting && getParent()))
- {
- //--------------------------------------------------------------------
- // get timing info
- // handle initial condition case
- //--------------------------------------------------------------------
- F32 animation_time = mAnimTimer.getElapsedTimeF32();
- if (mTimeLast == 0.0f)
- {
- mTimeLast = animation_time;
- throttle = FALSE;
- // put the pelvis at slaved position/mRotation
- mRoot.setWorldPosition( getPositionAgent() ); // first frame
- mRoot.setWorldRotation( getRotation() );
- }
-
- //--------------------------------------------------------------------
- // dont' let dT get larger than 1/5th of a second
- //--------------------------------------------------------------------
- F32 deltaTime = animation_time - mTimeLast;
- deltaTime = llclamp( deltaTime, DELTA_TIME_MIN, DELTA_TIME_MAX );
- mTimeLast = animation_time;
- mSpeedAccum = (mSpeedAccum * 0.95f) + (speed * 0.05f);
- //--------------------------------------------------------------------
- // compute the position of the avatar's root
- //--------------------------------------------------------------------
- LLVector3d root_pos;
- LLVector3d ground_under_pelvis;
- if (isSelf())
- {
- gAgent.setPositionAgent(getRenderPosition());
- }
- root_pos = gAgent.getPosGlobalFromAgent(getRenderPosition());
- resolveHeightGlobal(root_pos, ground_under_pelvis, normal);
- F32 foot_to_ground = (F32) (root_pos.mdV[VZ] - mPelvisToFoot - ground_under_pelvis.mdV[VZ]);
- BOOL in_air = ((!LLWorld::getInstance()->getRegionFromPosGlobal(ground_under_pelvis)) ||
- foot_to_ground > FOOT_GROUND_COLLISION_TOLERANCE);
- if (in_air && !mInAir)
- {
- mTimeInAir.reset();
- }
- mInAir = in_air;
- // correct for the fact that the pelvis is not necessarily the center
- // of the agent's physical representation
- root_pos.mdV[VZ] -= (0.5f * mBodySize.mV[VZ]) - mPelvisToFoot;
-
- LLVector3 newPosition = gAgent.getPosAgentFromGlobal(root_pos);
- if (newPosition != mRoot.getXform()->getWorldPosition())
- {
- mRoot.touch();
- mRoot.setWorldPosition(newPosition ); // regular update
- }
- //--------------------------------------------------------------------
- // Propagate viewer object rotation to root of avatar
- //--------------------------------------------------------------------
- if (!isAnyAnimationSignaled(AGENT_NO_ROTATE_ANIMS, NUM_AGENT_NO_ROTATE_ANIMS))
- {
- LLQuaternion iQ;
- LLVector3 upDir( 0.0f, 0.0f, 1.0f );
-
- // Compute a forward direction vector derived from the primitive rotation
- // and the velocity vector. When walking or jumping, don't let body deviate
- // more than 90 from the view, if necessary, flip the velocity vector.
- LLVector3 primDir;
- if (isSelf())
- {
- primDir = agent.getAtAxis() - projected_vec(agent.getAtAxis(), agent.getReferenceUpVector());
- primDir.normalize();
- }
- else
- {
- primDir = getRotation().getMatrix3().getFwdRow();
- }
- LLVector3 velDir = getVelocity();
- velDir.normalize();
- if ( mSignaledAnimations.find(ANIM_AGENT_WALK) != mSignaledAnimations.end())
- {
- F32 vpD = velDir * primDir;
- if (vpD < -0.5f)
- {
- velDir *= -1.0f;
- }
- }
- LLVector3 fwdDir = lerp(primDir, velDir, clamp_rescale(speed, 0.5f, 2.0f, 0.0f, 1.0f));
- if (isSelf() && gAgent.cameraMouselook())
- {
- // make sure fwdDir stays in same general direction as primdir
- if (gAgent.getFlying())
- {
- fwdDir = LLViewerCamera::getInstance()->getAtAxis();
- }
- else
- {
- LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis();
- LLVector3 up_vector = gAgent.getReferenceUpVector();
- at_axis -= up_vector * (at_axis * up_vector);
- at_axis.normalize();
-
- F32 dot = fwdDir * at_axis;
- if (dot < 0.f)
- {
- fwdDir -= 2.f * at_axis * dot;
- fwdDir.normalize();
- }
- }
-
- }
- LLQuaternion root_rotation = mRoot.getWorldMatrix().quaternion();
- F32 root_roll, root_pitch, root_yaw;
- root_rotation.getEulerAngles(&root_roll, &root_pitch, &root_yaw);
- // When moving very slow, the pelvis is allowed to deviate from the
- // forward direction to allow it to hold it's position while the torso
- // and head turn. Once in motion, it must conform however.
- BOOL self_in_mouselook = isSelf() && gAgent.cameraMouselook();
- LLVector3 pelvisDir( mRoot.getWorldMatrix().getFwdRow4().mV );
- F32 pelvis_rot_threshold = clamp_rescale(speed, 0.1f, 1.0f, PELVIS_ROT_THRESHOLD_SLOW, PELVIS_ROT_THRESHOLD_FAST);
-
- if (self_in_mouselook)
- {
- pelvis_rot_threshold *= MOUSELOOK_PELVIS_FOLLOW_FACTOR;
- }
- pelvis_rot_threshold *= DEG_TO_RAD;
- F32 angle = angle_between( pelvisDir, fwdDir );
- // The avatar's root is allowed to have a yaw that deviates widely
- // from the forward direction, but if roll or pitch are off even
- // a little bit we need to correct the rotation.
- if(root_roll < 1.f * DEG_TO_RAD
- && root_pitch < 5.f * DEG_TO_RAD)
- {
- // smaller correction vector means pelvis follows prim direction more closely
- if (!mTurning && angle > pelvis_rot_threshold*0.75f)
- {
- mTurning = TRUE;
- }
- // use tighter threshold when turning
- if (mTurning)
- {
- pelvis_rot_threshold *= 0.4f;
- }
- // am I done turning?
- if (angle < pelvis_rot_threshold)
- {
- mTurning = FALSE;
- }
- LLVector3 correction_vector = (pelvisDir - fwdDir) * clamp_rescale(angle, pelvis_rot_threshold*0.75f, pelvis_rot_threshold, 1.0f, 0.0f);
- fwdDir += correction_vector;
- }
- else
- {
- mTurning = FALSE;
- }
- // Now compute the full world space rotation for the whole body (wQv)
- LLVector3 leftDir = upDir % fwdDir;
- leftDir.normalize();
- fwdDir = leftDir % upDir;
- LLQuaternion wQv( fwdDir, leftDir, upDir );
- if (isSelf() && mTurning)
- {
- if ((fwdDir % pelvisDir) * upDir > 0.f)
- {
- gAgent.setControlFlags(AGENT_CONTROL_TURN_RIGHT);
- }
- else
- {
- gAgent.setControlFlags(AGENT_CONTROL_TURN_LEFT);
- }
- }
- // Set the root rotation, but do so incrementally so that it
- // lags in time by some fixed amount.
- //F32 u = LLCriticalDamp::getInterpolant(PELVIS_LAG);
- F32 pelvis_lag_time = 0.f;
- if (self_in_mouselook)
- {
- pelvis_lag_time = PELVIS_LAG_MOUSELOOK;
- }
- else if (mInAir)
- {
- pelvis_lag_time = PELVIS_LAG_FLYING;
- // increase pelvis lag time when moving slowly
- pelvis_lag_time *= clamp_rescale(mSpeedAccum, 0.f, 15.f, 3.f, 1.f);
- }
- else
- {
- pelvis_lag_time = PELVIS_LAG_WALKING;
- }
- F32 u = llclamp((deltaTime / pelvis_lag_time), 0.0f, 1.0f);
- mRoot.setWorldRotation( slerp(u, mRoot.getWorldRotation(), wQv) );
-
- }
- }
- else if (mDrawable.notNull())
- {
- mRoot.setPosition(mDrawable->getPosition());
- mRoot.setRotation(mDrawable->getRotation());
- }
-
- //-------------------------------------------------------------------------
- // Update character motions
- //-------------------------------------------------------------------------
- // store data relevant to motions
- mSpeed = speed;
- // update animations
- if (mSpecialRenderMode == 1) // Animation Preview
- updateMotions(LLCharacter::FORCE_UPDATE);
- else
- updateMotions(LLCharacter::NORMAL_UPDATE);
- // update head position
- updateHeadOffset();
- //-------------------------------------------------------------------------
- // Find the ground under each foot, these are used for a variety
- // of things that follow
- //-------------------------------------------------------------------------
- LLVector3 ankle_left_pos_agent = mFootLeftp->getWorldPosition();
- LLVector3 ankle_right_pos_agent = mFootRightp->getWorldPosition();
- LLVector3 ankle_left_ground_agent = ankle_left_pos_agent;
- LLVector3 ankle_right_ground_agent = ankle_right_pos_agent;
- resolveHeightAgent(ankle_left_pos_agent, ankle_left_ground_agent, normal);
- resolveHeightAgent(ankle_right_pos_agent, ankle_right_ground_agent, normal);
- F32 leftElev = llmax(-0.2f, ankle_left_pos_agent.mV[VZ] - ankle_left_ground_agent.mV[VZ]);
- F32 rightElev = llmax(-0.2f, ankle_right_pos_agent.mV[VZ] - ankle_right_ground_agent.mV[VZ]);
- if (!mIsSitting)
- {
- //-------------------------------------------------------------------------
- // Figure out which foot is on ground
- //-------------------------------------------------------------------------
- if (!mInAir)
- {
- if ((leftElev < 0.0f) || (rightElev < 0.0f))
- {
- ankle_left_pos_agent = mFootLeftp->getWorldPosition();
- ankle_right_pos_agent = mFootRightp->getWorldPosition();
- leftElev = ankle_left_pos_agent.mV[VZ] - ankle_left_ground_agent.mV[VZ];
- rightElev = ankle_right_pos_agent.mV[VZ] - ankle_right_ground_agent.mV[VZ];
- }
- }
- }
-
- //-------------------------------------------------------------------------
- // Generate footstep sounds when feet hit the ground
- //-------------------------------------------------------------------------
- const LLUUID AGENT_FOOTSTEP_ANIMS[] = {ANIM_AGENT_WALK, ANIM_AGENT_RUN, ANIM_AGENT_LAND};
- const S32 NUM_AGENT_FOOTSTEP_ANIMS = LL_ARRAY_SIZE(AGENT_FOOTSTEP_ANIMS);
- if ( gAudiop && isAnyAnimationSignaled(AGENT_FOOTSTEP_ANIMS, NUM_AGENT_FOOTSTEP_ANIMS) )
- {
- BOOL playSound = FALSE;
- LLVector3 foot_pos_agent;
- BOOL onGroundLeft = (leftElev <= 0.05f);
- BOOL onGroundRight = (rightElev <= 0.05f);
- // did left foot hit the ground?
- if ( onGroundLeft && !mWasOnGroundLeft )
- {
- foot_pos_agent = ankle_left_pos_agent;
- playSound = TRUE;
- }
- // did right foot hit the ground?
- if ( onGroundRight && !mWasOnGroundRight )
- {
- foot_pos_agent = ankle_right_pos_agent;
- playSound = TRUE;
- }
- mWasOnGroundLeft = onGroundLeft;
- mWasOnGroundRight = onGroundRight;
- if ( playSound )
- {
- // F32 gain = clamp_rescale( mSpeedAccum,
- // AUDIO_STEP_LO_SPEED, AUDIO_STEP_HI_SPEED,
- // AUDIO_STEP_LO_GAIN, AUDIO_STEP_HI_GAIN );
- const F32 STEP_VOLUME = 0.5f;
- const LLUUID& step_sound_id = getStepSound();
- LLVector3d foot_pos_global = gAgent.getPosGlobalFromAgent(foot_pos_agent);
- if (LLViewerParcelMgr::getInstance()->canHearSound(foot_pos_global)
- && !LLMuteList::getInstance()->isMuted(getID(), LLMute::flagObjectSounds))
- {
- gAudiop->triggerSound(step_sound_id, getID(), STEP_VOLUME, LLAudioEngine::AUDIO_TYPE_AMBIENT, foot_pos_global);
- }
- }
- }
- mRoot.updateWorldMatrixChildren();
- if (!mDebugText.size() && mText.notNull())
- {
- mText->markDead();
- mText = NULL;
- }
- else if (mDebugText.size())
- {
- setDebugText(mDebugText);
- }
- //mesh vertices need to be reskinned
- mNeedsSkin = TRUE;
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- // updateHeadOffset()
- //-----------------------------------------------------------------------------
- void LLVOAvatar::updateHeadOffset()
- {
- // since we only care about Z, just grab one of the eyes
- LLVector3 midEyePt = mEyeLeftp->getWorldPosition();
- midEyePt -= mDrawable.notNull() ? mDrawable->getWorldPosition() : mRoot.getWorldPosition();
- midEyePt.mV[VZ] = llmax(-mPelvisToFoot + LLViewerCamera::getInstance()->getNear(), midEyePt.mV[VZ]);
- if (mDrawable.notNull())
- {
- midEyePt = midEyePt * ~mDrawable->getWorldRotation();
- }
- if (mIsSitting)
- {
- mHeadOffset = midEyePt;
- }
- else
- {
- F32 u = llmax(0.f, HEAD_MOVEMENT_AVG_TIME - (1.f / gFPSClamped));
- mHeadOffset = lerp(midEyePt, mHeadOffset, u);
- }
- }
- //------------------------------------------------------------------------
- // updateVisibility()
- //------------------------------------------------------------------------
- void LLVOAvatar::updateVisibility()
- {
- BOOL visible = FALSE;
- if (mIsDummy)
- {
- visible = TRUE;
- }
- else if (mDrawable.isNull())
- {
- visible = FALSE;
- }
- else
- {
- if (!mDrawable->getSpatialGroup() || mDrawable->getSpatialGroup()->isVisible())
- {
- visible = TRUE;
- }
- else
- {
- visible = FALSE;
- }
- if(isSelf())
- {
- if (!gAgentWearables.areWearablesLoaded())
- {
- visible = FALSE;
- }
- }
- else if( !mFirstAppearanceMessageReceived )
- {
- visible = FALSE;
- }
- if (sDebugInvisible)
- {
- LLNameValue* firstname = getNVPair("FirstName");
- if (firstname)
- {
- llinfos << "Avatar " << firstname->getString() << " updating visiblity" << llendl;
- }
- else
- {
- llinfos << "Avatar " << this << " updating visiblity" << llendl;
- }
- if (visible)
- {
- llinfos << "Visible" << llendl;
- }
- else
- {
- llinfos << "Not visible" << llendl;
- }
- /*if (avatar_in_frustum)
- {
- llinfos << "Avatar in frustum" << llendl;
- }
- else
- {
- llinfos << "Avatar not in frustum" << llendl;
- }*/
- /*if (LLViewerCamera::getInstance()->sphereInFrustum(sel_pos_agent, 2.0f))
- {
- llinfos << "Sel pos visible" << llendl;
- }
- if (LLViewerCamera::getInstance()->sphereInFrustum(wrist_right_pos_agent, 0.2f))
- {
- llinfos << "Wrist pos visible" << llendl;
- }
- if (LLViewerCamera::getInstance()->sphereInFrustum(getPositionAgent(), getMaxScale()*2.f))
- {
- llinfos << "Agent visible" << llendl;
- }*/
- llinfos << "PA: " << getPositionAgent() << llendl;
- /*llinfos << "SPA: " << sel_pos_agent << llendl;
- llinfos << "WPA: " << wrist_right_pos_agent << llendl;*/
- for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
- iter != mAttachmentPoints.end();
- ++iter)
- {
- LLViewerJointAttachment* attachment = iter->second;
- for (LLViewerJointAttachment::attachedobjs_vec_t::iterator attachment_iter = attachment->mAttachedObjects.begin();
- attachment_iter != attachment->mAttachedObjects.end();
- ++attachment_iter)
- {
- if (LLViewerObject *attached_object = (*attachment_iter))
- {
- if(attached_object->mDrawable->isVisible())
- {
- llinfos << attachment->getName() << " visible" << llendl;
- }
- else
- {
- llinfos << attachment->getName() << " not visible at " << mDrawable->getWorldPosition() << " and radius " << mDrawable->getRadius() << llendl;
- }
- }
- }
- }
- }
- }
- if (!visible && mVisible)
- {
- mMeshInvisibleTime.reset();
- }
- if (visible)
- {
- if (!mMeshValid)
- {
- restoreMeshData();
- }
- }
- else
- {
- if (mMeshValid && mMeshInvisibleTime.getElapsedTimeF32() > TIME_BEFORE_MESH_CLEANUP)
- {
- releaseMeshData();
- }
- // this breaks off-screen chat bubbles
- //if (mNameText)
- //{
- // mNameText->markDead();
- // mNameText = NULL;
- // sNumVisibleChatBubbles--;
- //}
- }
- mVisible = visible;
- }
- // private
- bool LLVOAvatar::shouldAlphaMask()
- {
- const bool should_alpha_mask = mSupportsAlphaLayers && !LLDrawPoolAlpha::sShowDebugAlpha // Don't alpha mask if "Highlight Transparent" checked
- && !LLDrawPoolAvatar::sSkipTransparent;
- return should_alpha_mask;
- }
- //-----------------------------------------------------------------------------
- // renderSkinned()
- //-----------------------------------------------------------------------------
- U32 LLVOAvatar::renderSkinned(EAvatarRenderPass pass)
- {
- U32 num_indices = 0;
- if (!mIsBuilt)
- {
- return num_indices;
- }
- if (mDirtyMesh || mDrawable->isState(LLDrawable::REBUILD_GEOMETRY))
- { //LOD changed or new mesh created, allocate new vertex buffer if needed
- updateMeshData();
- mDirtyMesh = FALSE;
- mNeedsSkin = TRUE;
- mDrawable->clearState(LLDrawable::REBUILD_GEOMETRY);
- }
- if (LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_AVATAR) <= 0)
- {
- if (mNeedsSkin)
- {
- //generate animated mesh
- mMeshLOD[MESH_ID_LOWER_BODY]->updateJointGeometry();
- mMeshLOD[MESH_ID_UPPER_BODY]->updateJointGeometry();
- if( isWearingWearableType( WT_SKIRT ) )
- {
- mMeshLOD[MESH_ID_SKIRT]->updateJointGeometry();
- }
- if (!isSelf() || gAgent.needsRenderHead() || LLPipeline::sShadowRender)
- {
- mMeshLOD[MESH_ID_EYELASH]->updateJointGeometry();
- mMeshLOD[MESH_ID_HEAD]->updateJointGeometry();
- mMeshLOD[MESH_ID_HAIR]->updateJointGeometry();
- }
- mNeedsSkin = FALSE;
-
- LLVertexBuffer* vb = mDrawable->getFace(0)->mVertexBuffer;
- if (vb)
- {
- vb->setBuffer(0);
- }
- }
- }
- else
- {
- mNeedsSkin = FALSE;
- }
- if (sDebugInvisible)
- {
- LLNameValue* firstname = getNVPair("FirstName");
- if (firstname)
- {
- llinfos << "Avatar " << firstname->getString() << " in render" << llendl;
- }
- else
- {
- llinfos << "Avatar " << this << " in render" << llendl;
- }
- if (!mIsBuilt)
- {
- llinfos << "Not built!" << llendl;
- }
- else if (!gAgent.needsRenderAvatar())
- {
- llinfos << "Doesn't need avatar render!" << llendl;
- }
- else
- {
- llinfos << "Rendering!" << llendl;
- }
- }
- if (!mIsBuilt)
- {
- return num_indices;
- }
- if (isSelf() && !gAgent.needsRenderAvatar())
- {
- return num_indices;
- }
- // render collision normal
- // *NOTE: this is disabled (there is no UI for enabling sShowFootPlane) due
- // to DEV-14477. the code is left here to aid in tracking down the cause
- // of the crash in the future. -brad
- if (!gRenderForSelect && sShowFootPlane && mDrawable.notNull())
- {
- LLVector3 slaved_pos = mDrawable->getPositionAgent();
- LLVector3 foot_plane_normal(mFootPlane.mV[VX], mFootPlane.mV[VY], mFootPlane.mV[VZ]);
- F32 dist_from_plane = (slaved_pos * foot_plane_normal) - mFootPlane.mV[VW];
- LLVector3 collide_point = slaved_pos;
- collide_point.mV[VZ] -= foot_plane_normal.mV[VZ] * (dist_from_plane + COLLISION_TOLERANCE - FOOT_COLLIDE_FUDGE);
- gGL.begin(LLRender::LINES);
- {
- F32 SQUARE_SIZE = 0.2f;
- gGL.color4f(1.f, 0.f, 0.f, 1.f);
-
- gGL.vertex3f(collide_point.mV[VX] - SQUARE_SIZE, collide_point.mV[VY] - SQUARE_SIZE, collide_point.mV[VZ]);
- gGL.vertex3f(collide_point.mV[VX] + SQUARE_SIZE, collide_point.mV[VY] - SQUARE_SIZE, collide_point.mV[VZ]);
- gGL.vertex3f(collide_point.mV[VX] + SQUARE_SIZE, collide_point.mV[VY] - SQUARE_SIZE, collide_point.mV[VZ]);
- gGL.vertex3f(collide_point.mV[VX] + SQUARE_SIZE, collide_point.mV[VY] + SQUARE_SIZE, collide_point.mV[VZ]);
-
- gGL.vertex3f(collide_point.mV[VX] + SQUARE_SIZE, collide_point.mV[VY] + SQUARE_SIZE, collide_point.mV[VZ]);
- gGL.vertex3f(collide_point.mV[VX] - SQUARE_SIZE, collide_point.mV[VY] + SQUARE_SIZE, collide_point.mV[VZ]);
-
- gGL.vertex3f(collide_point.mV[VX] - SQUARE_SIZE, collide_point.mV[VY] + SQUARE_SIZE, collide_point.mV[VZ]);
- gGL.vertex3f(collide_point.mV[VX] - SQUARE_SIZE, collide_point.mV[VY] - SQUARE_SIZE, collide_point.mV[VZ]);
-
- gGL.vertex3f(collide_point.mV[VX], collide_point.mV[VY], collide_point.mV[VZ]);
- gGL.vertex3f(collide_point.mV[VX] + mFootPlane.mV[VX], collide_point.mV[VY] + mFootPlane.mV[VY], collide_point.mV[VZ] + mFootPlane.mV[VZ]);
- }
- gGL.end();
- gGL.flush();
- }
- //--------------------------------------------------------------------
- // render all geometry attached to the skeleton
- //--------------------------------------------------------------------
- static LLStat render_stat;
- LLViewerJointMesh::sRenderPass = pass;
- if (pass == AVATAR_RENDER_PASS_SINGLE)
- {
- bool should_alpha_mask = shouldAlphaMask();
- LLGLState test(GL_ALPHA_TEST, should_alpha_mask);
-
- if (should_alpha_mask)
- {
- gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.5f);
- }
-
- BOOL first_pass = TRUE;
- if (!LLDrawPoolAvatar::sSkipOpaque)
- {
- if (!isSelf() || gAgent.needsRenderHead() || LLPipeline::sShadowRender)
- {
- if (isTextureVisible(TEX_HEAD_BAKED) || mIsDummy)
- {
- num_indices += mMeshLOD[MESH_ID_HEAD]->render(mAdjustedPixelArea, TRUE, mIsDummy);
- first_pass = FALSE;
- }
- }
- if (isTextureVisible(TEX_UPPER_BAKED) || mIsDummy)
- {
- num_indices += mMeshLOD[MESH_ID_UPPER_BODY]->render(mAdjustedPixelArea, first_pass, mIsDummy);
- first_pass = FALSE;
- }
-
- if (isTextureVisible(TEX_LOWER_BAKED) || mIsDummy)
- {
- num_indices += mMeshLOD[MESH_ID_LOWER_BODY]->render(mAdjustedPixelArea, first_pass, mIsDummy);
- first_pass = FALSE;
- }
- }
- gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
- if (!LLDrawPoolAvatar::sSkipTransparent || LLPipeline::sImpostorRender)
- {
- LLGLState blend(GL_BLEND, !mIsDummy);
- LLGLState test(GL_ALPHA_TEST, !mIsDummy);
- num_indices += renderTransparent(first_pass);
- }
- }
-
- LLViewerJointMesh::sRenderPass = AVATAR_RENDER_PASS_SINGLE;
-
- //llinfos << "Avatar render: " << render_timer.getElapsedTimeF32() << llendl;
- //render_stat.addValue(render_timer.getElapsedTimeF32()*1000.f);
- return num_indices;
- }
- U32 LLVOAvatar::renderTransparent(BOOL first_pass)
- {
- U32 num_indices = 0;
- if( isWearingWearableType( WT_SKIRT ) && (mIsDummy || isTextureVisible(TEX_SKIRT_BAKED)) )
- {
- gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.25f);
- num_indices += mMeshLOD[MESH_ID_SKIRT]->render(mAdjustedPixelArea, FALSE);
- first_pass = FALSE;
- gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
- }
- if (!isSelf() || gAgent.needsRenderHead() || LLPipeline::sShadowRender)
- {
- if (LLPipeline::sImpostorRender)
- {
- gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.5f);
- }
-
- if (isTextureVisible(TEX_HEAD_BAKED))
- {
- num_indices += mMeshLOD[MESH_ID_EYELASH]->render(mAdjustedPixelArea, first_pass, mIsDummy);
- first_pass = FALSE;
- }
- // Can't test for baked hair being defined, since that won't always be the case (not all viewers send baked hair)
- // TODO: 1.25 will be able to switch this logic back to calling isTextureVisible();
- if (getImage(TEX_HAIR_BAKED, 0)->getID() != IMG_INVISIBLE || LLDrawPoolAlpha::sShowDebugAlpha)
- {
- num_indices += mMeshLOD[MESH_ID_HAIR]->render(mAdjustedPixelArea, first_pass, mIsDummy);
- first_pass = FALSE;
- }
- if (LLPipeline::sImpostorRender)
- {
- gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
- }
- }
- return num_indices;
- }
- //-----------------------------------------------------------------------------
- // renderRigid()
- //-----------------------------------------------------------------------------
- U32 LLVOAvatar::renderRigid()
- {
- U32 num_indices = 0;
- if (!mIsBuilt)
- {
- return 0;
- }
- if (isSelf() && (!gAgent.needsRenderAvatar() || !gAgent.needsRenderHead()))
- {
- return 0;
- }
-
- if (!mIsBuilt)
- {
- return 0;
- }
- bool should_alpha_mask = shouldAlphaMask();