From 8c95027334b24130dfdc1a51b3020156f371d538 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Tue, 24 Aug 2010 11:54:22 -0400 Subject: Moved BreastMotion class to its own separate file out of llvoavatar. Changed range of some breast motion params. Updated icon. --- indra/newview/llbreastmotion.cpp | 360 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 360 insertions(+) create mode 100644 indra/newview/llbreastmotion.cpp (limited to 'indra/newview/llbreastmotion.cpp') diff --git a/indra/newview/llbreastmotion.cpp b/indra/newview/llbreastmotion.cpp new file mode 100644 index 0000000000..c773655f35 --- /dev/null +++ b/indra/newview/llbreastmotion.cpp @@ -0,0 +1,360 @@ +/** + * @file llbreastmotion.cpp + * @brief Implementation of LLBreastMotion class. + * + * $LicenseInfo:firstyear=2001&license=viewergpl$ + * + * Copyright (c) 2001-2009, 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$ + */ + +//----------------------------------------------------------------------------- +// Header Files +//----------------------------------------------------------------------------- +#include "llviewerprecompiledheaders.h" +#include "linden_common.h" + +#include "m3math.h" +#include "v3dmath.h" + +#include "llbreastmotion.h" +#include "llcharacter.h" +#include "llviewercontrol.h" +#include "llviewervisualparam.H" + +// #define OUTPUT_BREAST_DATA + +//----------------------------------------------------------------------------- +// LLBreastMotion() +// Class Constructor +//----------------------------------------------------------------------------- +LLBreastMotion::LLBreastMotion(const LLUUID &id) : + LLMotion(id), + mCharacter(NULL), + mFileWrite(NULL) +{ + mName = "breast_motion"; + mChestState = new LLJointState; + + mBreastMassParam = (F32)1.0; + mBreastDragParam = LLVector3((F32)0.1, (F32)0.1, (F32)0.1); + mBreastSmoothingParam = (U32)2; + mBreastGravityParam = (F32)0.0; + + mBreastSpringParam = LLVector3((F32)3.0, (F32)0.0, (F32)3.0); + mBreastGainParam = LLVector3((F32)50.0, (F32)0.0, (F32)50.0); + mBreastDampingParam = LLVector3((F32)0.3, (F32)0.0, (F32)0.3); + mBreastMaxVelocityParam = LLVector3((F32)10.0, (F32)0.0, (F32)10.0); + + mBreastParamsUser[0] = mBreastParamsUser[1] = mBreastParamsUser[2] = NULL; + mBreastParamsDriven[0] = mBreastParamsDriven[1] = mBreastParamsDriven[2] = NULL; + + mCharLastPosition_world_pt = LLVector3(0,0,0); + mCharLastVelocity_local_vec = LLVector3(0,0,0); + mCharLastAcceleration_local_vec = LLVector3(0,0,0); + mBreastLastPosition_local_pt = LLVector3(0,0,0); + mBreastVelocity_local_vec = LLVector3(0,0,0); +} + + + +//----------------------------------------------------------------------------- +// ~LLBreastMotion() +// Class Destructor +//----------------------------------------------------------------------------- +LLBreastMotion::~LLBreastMotion() +{ +} + +BOOL LLBreastMotion::onActivate() +{ + return TRUE; +} + +void LLBreastMotion::onDeactivate() +{ +} + +LLMotion::LLMotionInitStatus LLBreastMotion::onInitialize(LLCharacter *character) +{ + mCharacter = character; + BOOL success = true; + + if ( !mChestState->setJoint( character->getJoint( "mChest" ) ) ) { success = false; } + + if (!success) + { + return STATUS_FAILURE; + } + + mChestState->setUsage(LLJointState::ROT); + addJointState( mChestState ); + + // User-set params + static const std::string breast_param_names_user[3] = + { + "Breast_Female_Cleavage_Driver", + "", + "Breast_Gravity_Driver" + }; + + // Params driven by this algorithm + static const std::string breast_param_names_driven[3] = + { + "Breast_Female_Cleavage", + "", + "Breast_Gravity" + }; + + for (U32 i=0; i < 3; i++) + { + mBreastParamsUser[i] = NULL; + mBreastParamsDriven[i] = NULL; + mBreastParamsMin[i] = 0; + mBreastParamsMax[i] = 0; + if (breast_param_names_user[i] != "" && breast_param_names_driven[i] != "") + { + mBreastParamsUser[i] = (LLViewerVisualParam*)mCharacter->getVisualParam(breast_param_names_user[i].c_str()); + mBreastParamsDriven[i] = (LLViewerVisualParam*)mCharacter->getVisualParam(breast_param_names_driven[i].c_str()); + if (mBreastParamsDriven[i]) + { + mBreastParamsMin[i] = mBreastParamsDriven[i]->getMinWeight(); + mBreastParamsMax[i] = mBreastParamsDriven[i]->getMaxWeight(); + } + } + } + +#ifdef OUTPUT_BREAST_DATA + //if (mCharacter->getSex() == SEX_FEMALE) + if (dynamic_cast(mCharacter)) + { + mFileWrite = fopen("c:\\temp\\data.txt","w"); + if (mFileWrite != NULL) + { + fprintf(mFileWrite,"Pos\tParam\tNet\tVel\t\tAccel\tSpring\tDamp\n"); + } + } +#endif + + mTimer.reset(); + return STATUS_SUCCESS; +} + + + +F32 LLBreastMotion::calculateTimeDelta() +{ + const F32 time = mTimer.getElapsedTimeF32(); + const F32 time_delta = time - mLastTime; + + mLastTime = time; + + return time_delta; +} + +LLVector3 LLBreastMotion::toLocal(const LLVector3 &world_vector) +{ + LLVector3 local_vec(0,0,0); + + LLJoint *chest_joint = mChestState->getJoint(); + const LLQuaternion world_rot = chest_joint->getWorldRotation(); + + // -1 because cleavage param changes opposite to direction. + LLVector3 breast_dir_world_vec = LLVector3(-1,0,0) * world_rot; + breast_dir_world_vec.normalize(); + local_vec[0] = world_vector * breast_dir_world_vec; + + LLVector3 breast_up_dir_world_vec = LLVector3(0,0,1) * world_rot; + breast_up_dir_world_vec.normalize(); + local_vec[2] = world_vector * breast_up_dir_world_vec; + + /* + { + llinfos << "Dir: " << breast_dir_world_vec << "V: " << world_vector << "DP: " << local_vec[0] << " time: " << llendl; + } + */ + + return local_vec; +} + +LLVector3 LLBreastMotion::calculateVelocity_local(const F32 time_delta) +{ + LLJoint *chest_joint = mChestState->getJoint(); + const LLVector3 world_pos_pt = chest_joint->getWorldPosition(); + const LLQuaternion world_rot = chest_joint->getWorldRotation(); + const LLVector3 last_world_pos_pt = mCharLastPosition_world_pt; + const LLVector3 char_velocity_world_vec = (world_pos_pt-last_world_pos_pt) / time_delta; + const LLVector3 char_velocity_local_vec = toLocal(char_velocity_world_vec); + + return char_velocity_local_vec; +} + +LLVector3 LLBreastMotion::calculateAcceleration_local(const LLVector3 &new_char_velocity_local_vec, + const F32 time_delta) +{ + LLVector3 char_acceleration_local_vec = new_char_velocity_local_vec - mCharLastVelocity_local_vec; + + char_acceleration_local_vec = + char_acceleration_local_vec * 1.0/mBreastSmoothingParam + + mCharLastAcceleration_local_vec * (mBreastSmoothingParam-1.0)/mBreastSmoothingParam; + + mCharLastAcceleration_local_vec = char_acceleration_local_vec; + + return char_acceleration_local_vec; +} + +// called per time step +// must return TRUE while it is active, and +// must return FALSE when the motion is completed. +BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) +{ + if (!gSavedSettings.getBOOL("AvatarPhysics")) + { + return TRUE; + } + + /* TEST: + 1. Change outfits + 2. FPS effect + 3. Add disable + 4. Disappearing chests + 5. Overwrites breast params + 6. Threshold for not setting param + 7. Switch params or take off wearable makes breasts jump + */ + + mBreastMassParam = mCharacter->getVisualParamWeight("Breast_Physics_Mass"); + mBreastSmoothingParam = mCharacter->getVisualParamWeight("Breast_Physics_Smoothing"); + mBreastGravityParam = mCharacter->getVisualParamWeight("Breast_Physics_Gravity"); + + mBreastSpringParam[0] = mCharacter->getVisualParamWeight("Breast_Physics_Side_Spring"); + mBreastGainParam[0] = mCharacter->getVisualParamWeight("Breast_Physics_Side_Gain"); + mBreastDampingParam[0] = mCharacter->getVisualParamWeight("Breast_Physics_Side_Damping"); + mBreastMaxVelocityParam[0] = mCharacter->getVisualParamWeight("Breast_Physics_Side_Max_Velocity"); + mBreastDragParam[0] = mCharacter->getVisualParamWeight("Breast_Physics_Side_Drag"); + + mBreastSpringParam[2] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Spring"); + mBreastGainParam[2] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Gain"); + mBreastDampingParam[2] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Damping"); + mBreastMaxVelocityParam[2] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Max_Velocity"); + mBreastDragParam[2] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Drag"); + + if (mCharacter->getSex() != SEX_FEMALE) return TRUE; + const F32 time_delta = calculateTimeDelta(); + if (time_delta < .01 || time_delta > 10.0) return TRUE; + + + LLVector3 breast_user_local_pt(0,0,0); + + for (U32 i=0; i < 3; i++) + { + if (mBreastParamsUser[i] != NULL) + { + breast_user_local_pt[i] = mBreastParamsUser[i]->getWeight(); + } + } + + LLVector3 breast_current_local_pt = mBreastLastPosition_local_pt; + + const LLVector3 char_velocity_local_vec = calculateVelocity_local(time_delta); + const LLVector3 char_acceleration_local_vec = calculateAcceleration_local(char_velocity_local_vec, time_delta); + mCharLastVelocity_local_vec = char_velocity_local_vec; + + LLJoint *chest_joint = mChestState->getJoint(); + mCharLastPosition_world_pt = chest_joint->getWorldPosition(); + + + const LLVector3 spring_length_local = breast_current_local_pt-breast_user_local_pt; + LLVector3 force_spring_local_vec = -spring_length_local; force_spring_local_vec *= mBreastSpringParam; + + LLVector3 force_accel_local_vec = char_acceleration_local_vec * mBreastMassParam; + const LLVector3 force_gravity_local_vec = toLocal(LLVector3(0,0,1))* mBreastGravityParam * mBreastMassParam; + force_accel_local_vec += force_gravity_local_vec; + force_accel_local_vec[0] *= mBreastGainParam[0]; + force_accel_local_vec[1] *= mBreastGainParam[1]; + force_accel_local_vec[2] *= mBreastGainParam[2]; + + LLVector3 force_damping_local_vec = -mBreastDampingParam; force_damping_local_vec *= mBreastVelocity_local_vec; + + LLVector3 force_drag_local_vec = .5*char_velocity_local_vec; // should square char_velocity_vec + force_drag_local_vec[0] *= mBreastDragParam[0]; + force_drag_local_vec[1] *= mBreastDragParam[1]; + force_drag_local_vec[2] *= mBreastDragParam[2]; + + LLVector3 force_net_local_vec = + force_accel_local_vec + + force_gravity_local_vec + + force_spring_local_vec + + force_damping_local_vec + + force_drag_local_vec; + + + LLVector3 acceleration_local_vec = force_net_local_vec / mBreastMassParam; + mBreastVelocity_local_vec += acceleration_local_vec; + mBreastVelocity_local_vec.clamp(-mBreastMaxVelocityParam, mBreastMaxVelocityParam); + + LLVector3 new_local_pt = breast_current_local_pt + mBreastVelocity_local_vec*time_delta; + new_local_pt.clamp(mBreastParamsMin,mBreastParamsMax); + + + for (U32 i=0; i < 3; i++) + { + if (mBreastMaxVelocityParam[0] == 0) + { + new_local_pt[i] = breast_user_local_pt[i]; + } + if (mBreastParamsDriven[i]) + { + mCharacter->setVisualParamWeight(mBreastParamsDriven[i], + new_local_pt[i], + FALSE); + } + } + + if (mFileWrite != NULL) + { + fprintf(mFileWrite,"%f\t%f\t%f\t%f\t\t%f\t%f\t%f\t \t%f\t%f\t%f\t%f\t%f\t%f\n", + mCharLastPosition_world_pt[2], + breast_current_local_pt[2], + acceleration_local_vec[2], + mBreastVelocity_local_vec[2], + + force_accel_local_vec[2], + force_spring_local_vec[2], + force_damping_local_vec[2], + + force_accel_local_vec[2], + force_damping_local_vec[2], + force_drag_local_vec[2], + force_net_local_vec[2], + time_delta, + mBreastMassParam + ); + } + + mBreastLastPosition_local_pt = new_local_pt; + mCharacter->updateVisualParams(); + return TRUE; +} -- cgit v1.3 From d52913bdbfdffd7ce4b1b2ace0b6eecd28a5ae43 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Tue, 24 Aug 2010 17:18:45 -0400 Subject: Fixed bug where wrong max velocity param was being used. --- indra/newview/llbreastmotion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/llbreastmotion.cpp') diff --git a/indra/newview/llbreastmotion.cpp b/indra/newview/llbreastmotion.cpp index c773655f35..8d3571e83d 100644 --- a/indra/newview/llbreastmotion.cpp +++ b/indra/newview/llbreastmotion.cpp @@ -321,7 +321,7 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) for (U32 i=0; i < 3; i++) { - if (mBreastMaxVelocityParam[0] == 0) + if (mBreastMaxVelocityParam[i] == 0) { new_local_pt[i] = breast_user_local_pt[i]; } -- cgit v1.3 From 5e110169701c8438a2c8191f03d3c5a4f080728c Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Wed, 25 Aug 2010 17:51:01 -0400 Subject: Fixed an issue where you go into appearance pose when editing physics if you were formerly in edit outfit. Miscellaneous code cleanup. --- indra/newview/llagentwearables.cpp | 2 +- indra/newview/llagentwearables.h | 2 +- indra/newview/llbreastmotion.cpp | 3 ++- indra/newview/llsidepanelappearance.cpp | 18 +++++++++++++----- 4 files changed, 17 insertions(+), 8 deletions(-) (limited to 'indra/newview/llbreastmotion.cpp') diff --git a/indra/newview/llagentwearables.cpp b/indra/newview/llagentwearables.cpp index 91a09cd886..c1aae867ef 100644 --- a/indra/newview/llagentwearables.cpp +++ b/indra/newview/llagentwearables.cpp @@ -821,7 +821,7 @@ void LLAgentWearables::popWearable(const LLWearableType::EType type, U32 index) } } -U32 LLAgentWearables::getWearableIndex(LLWearable *wearable) +U32 LLAgentWearables::getWearableIndex(const LLWearable *wearable) const { if (wearable == NULL) { diff --git a/indra/newview/llagentwearables.h b/indra/newview/llagentwearables.h index d7e77a5a5b..3ef50f14da 100644 --- a/indra/newview/llagentwearables.h +++ b/indra/newview/llagentwearables.h @@ -124,7 +124,7 @@ public: void setWearableOutfit(const LLInventoryItem::item_array_t& items, const LLDynamicArray< LLWearable* >& wearables, BOOL remove); void setWearableName(const LLUUID& item_id, const std::string& new_name); void addLocalTextureObject(const LLWearableType::EType wearable_type, const LLVOAvatarDefines::ETextureIndex texture_type, U32 wearable_index); - U32 getWearableIndex(LLWearable *wearable); + U32 getWearableIndex(const LLWearable *wearable) const; protected: void setWearableFinal(LLInventoryItem* new_item, LLWearable* new_wearable, bool do_append = false); diff --git a/indra/newview/llbreastmotion.cpp b/indra/newview/llbreastmotion.cpp index 8d3571e83d..036aa2ff39 100644 --- a/indra/newview/llbreastmotion.cpp +++ b/indra/newview/llbreastmotion.cpp @@ -42,7 +42,8 @@ #include "llbreastmotion.h" #include "llcharacter.h" #include "llviewercontrol.h" -#include "llviewervisualparam.H" +#include "llviewervisualparam.h" +#include "llvoavatarself.h" // #define OUTPUT_BREAST_DATA diff --git a/indra/newview/llsidepanelappearance.cpp b/indra/newview/llsidepanelappearance.cpp index e8733bf3e4..1422971b52 100644 --- a/indra/newview/llsidepanelappearance.cpp +++ b/indra/newview/llsidepanelappearance.cpp @@ -185,18 +185,26 @@ void LLSidepanelAppearance::onVisibilityChange(const LLSD &new_visibility) { if (new_visibility.asBoolean()) { - bool is_outfit_edit_visible = mOutfitEdit && mOutfitEdit->getVisible(); - bool is_wearable_edit_visible = mEditWearable && mEditWearable->getVisible(); + const BOOL is_outfit_edit_visible = mOutfitEdit && mOutfitEdit->getVisible(); + const BOOL is_wearable_edit_visible = mEditWearable && mEditWearable->getVisible(); if (is_outfit_edit_visible || is_wearable_edit_visible) { - if (!gAgentCamera.cameraCustomizeAvatar() && gSavedSettings.getBOOL("AppearanceCameraMovement")) + const LLWearable *wearable_ptr = mEditWearable->getWearable(); + if (!wearable_ptr) + { + llwarns << "Visibility change to invalid wearable" << llendl; + return; + } + const BOOL disable_camera_motion = LLWearableType::getDisableCameraSwitch(wearable_ptr->getType()); + if (!gAgentCamera.cameraCustomizeAvatar() && + !disable_camera_motion && + gSavedSettings.getBOOL("AppearanceCameraMovement")) { gAgentCamera.changeCameraToCustomizeAvatar(); } if (is_wearable_edit_visible) { - LLWearable *wearable_ptr = mEditWearable->getWearable(); if (gAgentWearables.getWearableIndex(wearable_ptr) == LLAgentWearables::MAX_CLOTHING_PER_TYPE) { // we're no longer wearing the wearable we were last editing, switch back to outfit editor @@ -380,7 +388,7 @@ void LLSidepanelAppearance::toggleWearableEditPanel(BOOL visible, LLWearable *we { gAgentCamera.changeCameraToCustomizeAvatar(); } - mEditWearable->setWearable(wearable); + mEditWearable->setWearable(wearable, disable_camera_switch); mEditWearable->onOpen(LLSD()); // currently no-op, just for consistency } else -- cgit v1.3 From 635128f353758e59c1ae158b2f01d291b0cea30f Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Thu, 26 Aug 2010 11:44:08 -0400 Subject: Added graphics preference setting for physics. --- indra/newview/app_settings/high_graphics.xml | 2 ++ indra/newview/app_settings/low_graphics.xml | 2 ++ indra/newview/app_settings/mid_graphics.xml | 2 ++ indra/newview/app_settings/settings.xml | 20 +++++++++--- indra/newview/app_settings/ultra_graphics.xml | 2 ++ indra/newview/llappviewer.cpp | 1 + indra/newview/llbreastmotion.cpp | 23 +++++++++++-- indra/newview/llbreastmotion.h | 1 + indra/newview/llfloaterpreference.cpp | 1 + indra/newview/llviewercontrol.cpp | 7 ++++ indra/newview/llvoavatar.cpp | 1 + indra/newview/llvoavatar.h | 1 + .../default/xui/en/panel_preferences_graphics1.xml | 38 +++++++++++++++++++--- 13 files changed, 90 insertions(+), 11 deletions(-) (limited to 'indra/newview/llbreastmotion.cpp') diff --git a/indra/newview/app_settings/high_graphics.xml b/indra/newview/app_settings/high_graphics.xml index 587b2f2a89..45236284f4 100644 --- a/indra/newview/app_settings/high_graphics.xml +++ b/indra/newview/app_settings/high_graphics.xml @@ -4,6 +4,8 @@ + + diff --git a/indra/newview/app_settings/low_graphics.xml b/indra/newview/app_settings/low_graphics.xml index a5bbdfc1d0..ad0073dfac 100644 --- a/indra/newview/app_settings/low_graphics.xml +++ b/indra/newview/app_settings/low_graphics.xml @@ -5,6 +5,8 @@ + + diff --git a/indra/newview/app_settings/mid_graphics.xml b/indra/newview/app_settings/mid_graphics.xml index a1430a58f9..d9d8682055 100644 --- a/indra/newview/app_settings/mid_graphics.xml +++ b/indra/newview/app_settings/mid_graphics.xml @@ -4,6 +4,8 @@ + + diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 8310c50b1e..d190ac7136 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -607,7 +607,17 @@ Value 10 - + AvatarPhysics + + Comment + Enable avatar physics, such as breast physics. + Persist + 1 + Type + Boolean + Value + 1 + AvatarSex Comment @@ -620,16 +630,16 @@ 0 - AvatarPhysics + RenderAvatarPhysicsLODFactor Comment - Enable avatar physics, such as breast physics. + Controls level of detail of avatar physics (such as breast physics). Persist 1 Type - Boolean + F32 Value - 1 + 1.0 BackgroundYieldTime diff --git a/indra/newview/app_settings/ultra_graphics.xml b/indra/newview/app_settings/ultra_graphics.xml index f741089ca2..3d588cf57d 100644 --- a/indra/newview/app_settings/ultra_graphics.xml +++ b/indra/newview/app_settings/ultra_graphics.xml @@ -4,6 +4,8 @@ + + diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index bfe3e52657..15e91b57fa 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -443,6 +443,7 @@ static void settings_to_globals() LLVolumeImplFlexible::sUpdateFactor = gSavedSettings.getF32("RenderFlexTimeFactor"); LLVOTree::sTreeFactor = gSavedSettings.getF32("RenderTreeLODFactor"); LLVOAvatar::sLODFactor = gSavedSettings.getF32("RenderAvatarLODFactor"); + LLVOAvatar::sPhysicsLODFactor = gSavedSettings.getF32("RenderAvatarPhysicsLODFactor"); LLVOAvatar::sMaxVisible = (U32)gSavedSettings.getS32("RenderAvatarMaxVisible"); LLVOAvatar::sVisibleInFirstPerson = gSavedSettings.getBOOL("FirstPersonAvatarVisible"); // clamp auto-open time to some minimum usable value diff --git a/indra/newview/llbreastmotion.cpp b/indra/newview/llbreastmotion.cpp index 036aa2ff39..2c8a38710a 100644 --- a/indra/newview/llbreastmotion.cpp +++ b/indra/newview/llbreastmotion.cpp @@ -76,6 +76,7 @@ LLBreastMotion::LLBreastMotion(const LLUUID &id) : mCharLastVelocity_local_vec = LLVector3(0,0,0); mCharLastAcceleration_local_vec = LLVector3(0,0,0); mBreastLastPosition_local_pt = LLVector3(0,0,0); + mBreastLastUpdatePosition_local_pt = LLVector3(0,0,0); mBreastVelocity_local_vec = LLVector3(0,0,0); } @@ -236,6 +237,12 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) return TRUE; } + const F32 lod_factor = LLVOAvatar::sPhysicsLODFactor; + if (lod_factor == 0) + { + return TRUE; + } + /* TEST: 1. Change outfits 2. FPS effect @@ -354,8 +361,20 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) mBreastMassParam ); } - + + LLVector3 position_diff = mBreastLastUpdatePosition_local_pt-new_local_pt; + for (U32 i=0; i < 3; i++) + { + const F32 min_delta = (1.0-lod_factor)*(mBreastParamsMax[i]-mBreastParamsMin[i])/2.0; + if (llabs(position_diff[i]) > min_delta) + { + mCharacter->updateVisualParams(); + mBreastLastUpdatePosition_local_pt = new_local_pt; + break; + } + } + mBreastLastPosition_local_pt = new_local_pt; - mCharacter->updateVisualParams(); + return TRUE; } diff --git a/indra/newview/llbreastmotion.h b/indra/newview/llbreastmotion.h index 7dbe604a76..6a2e3788ad 100644 --- a/indra/newview/llbreastmotion.h +++ b/indra/newview/llbreastmotion.h @@ -138,6 +138,7 @@ private: LLVector3 mBreastLastPosition_local_pt; // Last parameters for breast LLVector3 mBreastVelocity_local_vec; // How fast the breast params are moving + LLVector3 mBreastLastUpdatePosition_local_pt; // Last parameters when visual update was sent F32 mBreastMassParam; diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp index 3804a1b858..dbc50ddbea 100644 --- a/indra/newview/llfloaterpreference.cpp +++ b/indra/newview/llfloaterpreference.cpp @@ -1064,6 +1064,7 @@ void LLFloaterPreference::refresh() updateSliderText(getChild("FlexibleMeshDetail", true), getChild("FlexibleMeshDetailText", true)); updateSliderText(getChild("TreeMeshDetail", true), getChild("TreeMeshDetailText", true)); updateSliderText(getChild("AvatarMeshDetail", true), getChild("AvatarMeshDetailText", true)); + updateSliderText(getChild("AvatarPhysicsDetail", true), getChild("AvatarPhysicsDetailText", true)); updateSliderText(getChild("TerrainMeshDetail", true), getChild("TerrainMeshDetailText", true)); updateSliderText(getChild("RenderPostProcess", true), getChild("PostProcessText", true)); updateSliderText(getChild("SkyMeshDetail", true), getChild("SkyMeshDetailText", true)); diff --git a/indra/newview/llviewercontrol.cpp b/indra/newview/llviewercontrol.cpp index 522b5a7dfa..df5a376631 100644 --- a/indra/newview/llviewercontrol.cpp +++ b/indra/newview/llviewercontrol.cpp @@ -144,6 +144,12 @@ static bool handleAvatarLODChanged(const LLSD& newvalue) return true; } +static bool handleAvatarPhysicsLODChanged(const LLSD& newvalue) +{ + LLVOAvatar::sPhysicsLODFactor = (F32) newvalue.asReal(); + return true; +} + static bool handleAvatarMaxVisibleChanged(const LLSD& newvalue) { LLVOAvatar::sMaxVisible = (U32) newvalue.asInteger(); @@ -509,6 +515,7 @@ void settings_setup_listeners() gSavedSettings.getControl("RenderAvatarMaxVisible")->getSignal()->connect(boost::bind(&handleAvatarMaxVisibleChanged, _2)); gSavedSettings.getControl("RenderVolumeLODFactor")->getSignal()->connect(boost::bind(&handleVolumeLODChanged, _2)); gSavedSettings.getControl("RenderAvatarLODFactor")->getSignal()->connect(boost::bind(&handleAvatarLODChanged, _2)); + gSavedSettings.getControl("RenderAvatarPhysicsLODFactor")->getSignal()->connect(boost::bind(&handleAvatarPhysicsLODChanged, _2)); gSavedSettings.getControl("RenderTerrainLODFactor")->getSignal()->connect(boost::bind(&handleTerrainLODChanged, _2)); gSavedSettings.getControl("RenderTreeLODFactor")->getSignal()->connect(boost::bind(&handleTreeLODChanged, _2)); gSavedSettings.getControl("RenderFlexTimeFactor")->getSignal()->connect(boost::bind(&handleFlexLODChanged, _2)); diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp index b98c64310d..be55c5b5c2 100644 --- a/indra/newview/llvoavatar.cpp +++ b/indra/newview/llvoavatar.cpp @@ -619,6 +619,7 @@ BOOL LLVOAvatar::sShowAnimationDebug = FALSE; BOOL LLVOAvatar::sShowFootPlane = FALSE; BOOL LLVOAvatar::sVisibleInFirstPerson = FALSE; F32 LLVOAvatar::sLODFactor = 1.f; +F32 LLVOAvatar::sPhysicsLODFactor = 1.f; BOOL LLVOAvatar::sUseImpostors = FALSE; BOOL LLVOAvatar::sJointDebug = FALSE; diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h index c522af7d55..4417e37abb 100644 --- a/indra/newview/llvoavatar.h +++ b/indra/newview/llvoavatar.h @@ -230,6 +230,7 @@ public: static BOOL sDebugInvisible; static BOOL sShowAttachmentPoints; static F32 sLODFactor; // user-settable LOD factor + static F32 sPhysicsLODFactor; // user-settable physics LOD factor static BOOL sJointDebug; // output total number of joints being touched for each avatar static BOOL sDebugAvatarRotation; diff --git a/indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml b/indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml index 113d5fb6dc..23024cd0eb 100644 --- a/indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml +++ b/indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml @@ -2,7 +2,7 @@ + + + + Low + + @@ -662,7 +692,7 @@ left="358" left_pad="-30" name="TerrainDetailText" - top="226" + top="250" width="155"> Terrain detail: @@ -700,7 +730,7 @@ layout="topleft" left="10" name="Apply" - top="383" + top="390" width="115" > -- cgit v1.3 From a37057717d243596b92108590d56a0d3021ad840 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Thu, 26 Aug 2010 14:02:51 -0400 Subject: Miscellaneous fixes for how we're doing graphics settings for the avatar physics. Fixed a cast issue that was causing a linux compile error. --- indra/newview/app_settings/high_graphics.xml | 2 +- indra/newview/app_settings/mid_graphics.xml | 2 +- indra/newview/app_settings/settings.xml | 23 ++++---- indra/newview/featuretable.txt | 4 ++ indra/newview/llagentcamera.cpp | 2 +- indra/newview/llbreastmotion.cpp | 2 +- .../default/xui/en/panel_preferences_graphics1.xml | 64 +++++++++++----------- 7 files changed, 52 insertions(+), 47 deletions(-) (limited to 'indra/newview/llbreastmotion.cpp') diff --git a/indra/newview/app_settings/high_graphics.xml b/indra/newview/app_settings/high_graphics.xml index 45236284f4..f1862f9d72 100644 --- a/indra/newview/app_settings/high_graphics.xml +++ b/indra/newview/app_settings/high_graphics.xml @@ -5,7 +5,7 @@ - + diff --git a/indra/newview/app_settings/mid_graphics.xml b/indra/newview/app_settings/mid_graphics.xml index d9d8682055..6c4afbd7f0 100644 --- a/indra/newview/app_settings/mid_graphics.xml +++ b/indra/newview/app_settings/mid_graphics.xml @@ -5,7 +5,7 @@ - + diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index d190ac7136..ecb36273ec 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -630,18 +630,6 @@ 0 - RenderAvatarPhysicsLODFactor - - Comment - Controls level of detail of avatar physics (such as breast physics). - Persist - 1 - Type - F32 - Value - 1.0 - - BackgroundYieldTime Comment @@ -6646,6 +6634,17 @@ Value 12 + RenderAvatarPhysicsLODFactor + + Comment + Controls level of detail of avatar physics (such as breast physics). + Persist + 1 + Type + F32 + Value + 1.0 + RenderAvatarVP Comment diff --git a/indra/newview/featuretable.txt b/indra/newview/featuretable.txt index 9440e877df..5f843ad912 100644 --- a/indra/newview/featuretable.txt +++ b/indra/newview/featuretable.txt @@ -26,6 +26,7 @@ list all RenderAnisotropic 1 1 RenderAvatarCloth 1 1 RenderAvatarLODFactor 1 1.0 +RenderAvatarPhysicsLODFactor 1 1.0 RenderAvatarMaxVisible 1 12 RenderAvatarVP 1 1 RenderCubeMap 1 1 @@ -69,6 +70,7 @@ list Low RenderAnisotropic 1 0 RenderAvatarCloth 1 0 RenderAvatarLODFactor 1 0 +RenderAvatarPhysicsLODFactor 1 0 RenderAvatarMaxVisible 1 3 RenderAvatarVP 1 0 RenderFarClip 1 64 @@ -98,6 +100,7 @@ list Mid RenderAnisotropic 1 0 RenderAvatarCloth 1 0 RenderAvatarLODFactor 1 0.5 +RenderAvatarPhysicsLODFactor 1 0.75 RenderAvatarVP 1 1 RenderFarClip 1 96 RenderFlexTimeFactor 1 1.0 @@ -125,6 +128,7 @@ list High RenderAnisotropic 1 1 RenderAvatarCloth 1 0 RenderAvatarLODFactor 1 1.0 +RenderAvatarPhysicsLODFactor 1 0.9 RenderAvatarVP 1 1 RenderFarClip 1 128 RenderFlexTimeFactor 1 1.0 diff --git a/indra/newview/llagentcamera.cpp b/indra/newview/llagentcamera.cpp index 01a4cce700..f0ab8bd311 100644 --- a/indra/newview/llagentcamera.cpp +++ b/indra/newview/llagentcamera.cpp @@ -277,7 +277,7 @@ LLAgentCamera::~LLAgentCamera() //----------------------------------------------------------------------------- void LLAgentCamera::resetView(BOOL reset_camera, BOOL change_camera) { - if (TRUE) return; // SERAPH DON'T CHECKIN + if (TRUE) return; // Disabling reset for avatar physics demo-ing. if (gAgent.getAutoPilot()) { gAgent.stopAutoPilot(TRUE); diff --git a/indra/newview/llbreastmotion.cpp b/indra/newview/llbreastmotion.cpp index 2c8a38710a..902c5af892 100644 --- a/indra/newview/llbreastmotion.cpp +++ b/indra/newview/llbreastmotion.cpp @@ -254,7 +254,7 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) */ mBreastMassParam = mCharacter->getVisualParamWeight("Breast_Physics_Mass"); - mBreastSmoothingParam = mCharacter->getVisualParamWeight("Breast_Physics_Smoothing"); + mBreastSmoothingParam = (U32)(mCharacter->getVisualParamWeight("Breast_Physics_Smoothing")); mBreastGravityParam = mCharacter->getVisualParamWeight("Breast_Physics_Gravity"); mBreastSpringParam[0] = mCharacter->getVisualParamWeight("Breast_Physics_Side_Spring"); diff --git a/indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml b/indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml index 23024cd0eb..bd5473e7bf 100644 --- a/indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml +++ b/indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml @@ -317,6 +317,37 @@ value="4"/> + + + + + Low + + - - - - Low - - @@ -638,6 +639,7 @@ width="128"> Low + - Avatar rendering: + Avatar Rendering: Date: Thu, 26 Aug 2010 16:05:43 -0400 Subject: Changed parameter scale for max velocity so it's easier to turn off various physics. --- indra/newview/character/avatar_lad.xml | 8 ++++---- indra/newview/llbreastmotion.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/newview/llbreastmotion.cpp') diff --git a/indra/newview/character/avatar_lad.xml b/indra/newview/character/avatar_lad.xml index 6fa1111223..453ed1baf7 100644 --- a/indra/newview/character/avatar_lad.xml +++ b/indra/newview/character/avatar_lad.xml @@ -9209,9 +9209,9 @@ render_pass="bump"> edit_group="physics" label_min="Less" label_max="More" - value_default="5" + value_default="0" value_min="0" - value_max="1000" + value_max="10" camera_elevation=".3" camera_distance=".8"> @@ -9300,9 +9300,9 @@ render_pass="bump"> edit_group="physics" label_min="Less" label_max="More" - value_default="5" + value_default="1" value_min="0" - value_max="1000" + value_max="10" camera_elevation=".3" camera_distance=".8"> diff --git a/indra/newview/llbreastmotion.cpp b/indra/newview/llbreastmotion.cpp index 902c5af892..5bbab8a0a6 100644 --- a/indra/newview/llbreastmotion.cpp +++ b/indra/newview/llbreastmotion.cpp @@ -321,7 +321,7 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) LLVector3 acceleration_local_vec = force_net_local_vec / mBreastMassParam; mBreastVelocity_local_vec += acceleration_local_vec; - mBreastVelocity_local_vec.clamp(-mBreastMaxVelocityParam, mBreastMaxVelocityParam); + mBreastVelocity_local_vec.clamp(-mBreastMaxVelocityParam*100.0, mBreastMaxVelocityParam*100.0); LLVector3 new_local_pt = breast_current_local_pt + mBreastVelocity_local_vec*time_delta; new_local_pt.clamp(mBreastParamsMin,mBreastParamsMax); -- cgit v1.3 From c859923cf63fc66d4f73b04ec57d56a2e4fe6955 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Tue, 31 Aug 2010 14:42:09 -0400 Subject: Physics no longer perform for avatars that are smaller than some certain screenspace metric. Physics no longer removed when outfits changed. --- indra/newview/llagentwearables.cpp | 1 - indra/newview/llbreastmotion.cpp | 63 ++++++++++++++++++++++---------------- indra/newview/llbreastmotion.h | 3 +- 3 files changed, 38 insertions(+), 29 deletions(-) (limited to 'indra/newview/llbreastmotion.cpp') diff --git a/indra/newview/llagentwearables.cpp b/indra/newview/llagentwearables.cpp index c1aae867ef..34f7e2578f 100644 --- a/indra/newview/llagentwearables.cpp +++ b/indra/newview/llagentwearables.cpp @@ -1717,7 +1717,6 @@ void LLAgentWearables::userRemoveAllClothesStep2(BOOL proceed) gAgentWearables.removeWearable(LLWearableType::WT_SKIRT,true,0); gAgentWearables.removeWearable(LLWearableType::WT_ALPHA,true,0); gAgentWearables.removeWearable(LLWearableType::WT_TATTOO,true,0); - gAgentWearables.removeWearable(LLWearableType::WT_PHYSICS,true,0); } } diff --git a/indra/newview/llbreastmotion.cpp b/indra/newview/llbreastmotion.cpp index 5bbab8a0a6..d4d0a78543 100644 --- a/indra/newview/llbreastmotion.cpp +++ b/indra/newview/llbreastmotion.cpp @@ -45,12 +45,10 @@ #include "llviewervisualparam.h" #include "llvoavatarself.h" +#define MIN_REQUIRED_PIXEL_AREA_BREAST_MOTION 1000.f; + // #define OUTPUT_BREAST_DATA -//----------------------------------------------------------------------------- -// LLBreastMotion() -// Class Constructor -//----------------------------------------------------------------------------- LLBreastMotion::LLBreastMotion(const LLUUID &id) : LLMotion(id), mCharacter(NULL), @@ -80,12 +78,6 @@ LLBreastMotion::LLBreastMotion(const LLUUID &id) : mBreastVelocity_local_vec = LLVector3(0,0,0); } - - -//----------------------------------------------------------------------------- -// ~LLBreastMotion() -// Class Destructor -//----------------------------------------------------------------------------- LLBreastMotion::~LLBreastMotion() { } @@ -164,7 +156,11 @@ LLMotion::LLMotionInitStatus LLBreastMotion::onInitialize(LLCharacter *character return STATUS_SUCCESS; } - +F32 LLBreastMotion::getMinPixelArea() +{ + return MIN_REQUIRED_PIXEL_AREA_BREAST_MOTION; +} + F32 LLBreastMotion::calculateTimeDelta() { @@ -243,15 +239,17 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) return TRUE; } - /* TEST: - 1. Change outfits - 2. FPS effect - 3. Add disable - 4. Disappearing chests - 5. Overwrites breast params - 6. Threshold for not setting param - 7. Switch params or take off wearable makes breasts jump - */ + if (!dynamic_cast(mCharacter)) + { + static int ticks=0; + ticks = (ticks + 1) % 10; + if (!ticks) + llinfos << "Pixel Area: " << mCharacter->getPixelArea() << " rt: " << fsqrtf(mCharacter->getPixelArea()) << llendl; + } + + if (mCharacter->getSex() != SEX_FEMALE) return TRUE; + const F32 time_delta = calculateTimeDelta(); + if (time_delta < .01 || time_delta > 10.0) return TRUE; mBreastMassParam = mCharacter->getVisualParamWeight("Breast_Physics_Mass"); mBreastSmoothingParam = (U32)(mCharacter->getVisualParamWeight("Breast_Physics_Smoothing")); @@ -269,11 +267,9 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) mBreastMaxVelocityParam[2] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Max_Velocity"); mBreastDragParam[2] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Drag"); - if (mCharacter->getSex() != SEX_FEMALE) return TRUE; - const F32 time_delta = calculateTimeDelta(); - if (time_delta < .01 || time_delta > 10.0) return TRUE; - + const BOOL is_self = (dynamic_cast(this) != NULL); + LLVector3 breast_user_local_pt(0,0,0); for (U32 i=0; i < 3; i++) @@ -361,7 +357,23 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) mBreastMassParam ); } + + mBreastLastPosition_local_pt = new_local_pt; + if (!is_self) + { + const F32 area_for_max_settings = 300.0; + const F32 area_for_min_settings = 1400.0; + + const F32 area_for_this_setting = area_for_max_settings + (area_for_min_settings-area_for_max_settings)*(1.0-lod_factor); + const F32 pixel_area = fsqrtf(mCharacter->getPixelArea()); + if (pixel_area < area_for_this_setting) + { + return TRUE; + } + } + + LLVector3 position_diff = mBreastLastUpdatePosition_local_pt-new_local_pt; for (U32 i=0; i < 3; i++) { @@ -370,11 +382,10 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) { mCharacter->updateVisualParams(); mBreastLastUpdatePosition_local_pt = new_local_pt; - break; + return TRUE; } } - mBreastLastPosition_local_pt = new_local_pt; return TRUE; } diff --git a/indra/newview/llbreastmotion.h b/indra/newview/llbreastmotion.h index 6a2e3788ad..da71962453 100644 --- a/indra/newview/llbreastmotion.h +++ b/indra/newview/llbreastmotion.h @@ -39,7 +39,6 @@ #include "llmotion.h" #include "llframetimer.h" -#define MIN_REQUIRED_PIXEL_AREA_BREAST_MOTION 500.f; #define BREAST_MOTION_FADEIN_TIME 1.0f #define BREAST_MOTION_FADEOUT_TIME 1.0f @@ -85,7 +84,7 @@ public: virtual F32 getEaseOutDuration() { return BREAST_MOTION_FADEOUT_TIME; } // called to determine when a motion should be activated/deactivated based on avatar pixel coverage - virtual F32 getMinPixelArea() { return MIN_REQUIRED_PIXEL_AREA_BREAST_MOTION; } + virtual F32 getMinPixelArea(); // motions must report their priority virtual LLJoint::JointPriority getPriority() { return LLJoint::MEDIUM_PRIORITY; } -- cgit v1.3 From 9039af33723382058cd422a360cda535c28ebc84 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Tue, 31 Aug 2010 15:45:43 -0400 Subject: Code cleanup. --- indra/newview/llbreastmotion.cpp | 227 ++++++++++++++++++++------------------- indra/newview/llbreastmotion.h | 1 - 2 files changed, 116 insertions(+), 112 deletions(-) (limited to 'indra/newview/llbreastmotion.cpp') diff --git a/indra/newview/llbreastmotion.cpp b/indra/newview/llbreastmotion.cpp index d4d0a78543..b38e818dbd 100644 --- a/indra/newview/llbreastmotion.cpp +++ b/indra/newview/llbreastmotion.cpp @@ -47,12 +47,27 @@ #define MIN_REQUIRED_PIXEL_AREA_BREAST_MOTION 1000.f; -// #define OUTPUT_BREAST_DATA +#define N_PARAMS 2 + +// User-set params +static const std::string breast_param_names_user[N_PARAMS] = +{ + "Breast_Female_Cleavage_Driver", + "Breast_Gravity_Driver" +}; + +// Params driven by this algorithm +static const std::string breast_param_names_driven[N_PARAMS] = +{ + "Breast_Female_Cleavage", + "Breast_Gravity" +}; + + LLBreastMotion::LLBreastMotion(const LLUUID &id) : LLMotion(id), - mCharacter(NULL), - mFileWrite(NULL) + mCharacter(NULL) { mName = "breast_motion"; mChestState = new LLJointState; @@ -94,35 +109,16 @@ void LLBreastMotion::onDeactivate() LLMotion::LLMotionInitStatus LLBreastMotion::onInitialize(LLCharacter *character) { mCharacter = character; - BOOL success = true; - - if ( !mChestState->setJoint( character->getJoint( "mChest" ) ) ) { success = false; } - if (!success) + if (!mChestState->setJoint(character->getJoint("mChest"))) { return STATUS_FAILURE; } - + mChestState->setUsage(LLJointState::ROT); addJointState( mChestState ); - - // User-set params - static const std::string breast_param_names_user[3] = - { - "Breast_Female_Cleavage_Driver", - "", - "Breast_Gravity_Driver" - }; - - // Params driven by this algorithm - static const std::string breast_param_names_driven[3] = - { - "Breast_Female_Cleavage", - "", - "Breast_Gravity" - }; - - for (U32 i=0; i < 3; i++) + + for (U32 i=0; i < N_PARAMS; i++) { mBreastParamsUser[i] = NULL; mBreastParamsDriven[i] = NULL; @@ -139,19 +135,7 @@ LLMotion::LLMotionInitStatus LLBreastMotion::onInitialize(LLCharacter *character } } } - -#ifdef OUTPUT_BREAST_DATA - //if (mCharacter->getSex() == SEX_FEMALE) - if (dynamic_cast(mCharacter)) - { - mFileWrite = fopen("c:\\temp\\data.txt","w"); - if (mFileWrite != NULL) - { - fprintf(mFileWrite,"Pos\tParam\tNet\tVel\t\tAccel\tSpring\tDamp\n"); - } - } -#endif - + mTimer.reset(); return STATUS_SUCCESS; } @@ -166,33 +150,27 @@ F32 LLBreastMotion::calculateTimeDelta() { const F32 time = mTimer.getElapsedTimeF32(); const F32 time_delta = time - mLastTime; - mLastTime = time; - return time_delta; } +// Local space means "parameter space". LLVector3 LLBreastMotion::toLocal(const LLVector3 &world_vector) { LLVector3 local_vec(0,0,0); LLJoint *chest_joint = mChestState->getJoint(); const LLQuaternion world_rot = chest_joint->getWorldRotation(); - - // -1 because cleavage param changes opposite to direction. - LLVector3 breast_dir_world_vec = LLVector3(-1,0,0) * world_rot; + + // Cleavage + LLVector3 breast_dir_world_vec = LLVector3(-1,0,0) * world_rot; // -1 b/c cleavage param changes opposite to direction breast_dir_world_vec.normalize(); local_vec[0] = world_vector * breast_dir_world_vec; - + + // Up-Down Bounce LLVector3 breast_up_dir_world_vec = LLVector3(0,0,1) * world_rot; breast_up_dir_world_vec.normalize(); - local_vec[2] = world_vector * breast_up_dir_world_vec; - - /* - { - llinfos << "Dir: " << breast_dir_world_vec << "V: " << world_vector << "DP: " << local_vec[0] << " time: " << llendl; - } - */ + local_vec[1] = world_vector * breast_up_dir_world_vec; return local_vec; } @@ -213,7 +191,7 @@ LLVector3 LLBreastMotion::calculateAcceleration_local(const LLVector3 &new_char_ const F32 time_delta) { LLVector3 char_acceleration_local_vec = new_char_velocity_local_vec - mCharLastVelocity_local_vec; - + char_acceleration_local_vec = char_acceleration_local_vec * 1.0/mBreastSmoothingParam + mCharLastAcceleration_local_vec * (mBreastSmoothingParam-1.0)/mBreastSmoothingParam; @@ -223,34 +201,31 @@ LLVector3 LLBreastMotion::calculateAcceleration_local(const LLVector3 &new_char_ return char_acceleration_local_vec; } -// called per time step -// must return TRUE while it is active, and -// must return FALSE when the motion is completed. BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) { + // Skip if disabled globally. if (!gSavedSettings.getBOOL("AvatarPhysics")) { return TRUE; } + // Higher LOD is better. This controls the granularity + // and frequency of updates for the motions. const F32 lod_factor = LLVOAvatar::sPhysicsLODFactor; if (lod_factor == 0) { return TRUE; } - - if (!dynamic_cast(mCharacter)) - { - static int ticks=0; - ticks = (ticks + 1) % 10; - if (!ticks) - llinfos << "Pixel Area: " << mCharacter->getPixelArea() << " rt: " << fsqrtf(mCharacter->getPixelArea()) << llendl; - } - + if (mCharacter->getSex() != SEX_FEMALE) return TRUE; const F32 time_delta = calculateTimeDelta(); if (time_delta < .01 || time_delta > 10.0) return TRUE; + + //////////////////////////////////////////////////////////////////////////////// + // Get all parameters and settings + // + mBreastMassParam = mCharacter->getVisualParamWeight("Breast_Physics_Mass"); mBreastSmoothingParam = (U32)(mCharacter->getVisualParamWeight("Breast_Physics_Smoothing")); mBreastGravityParam = mCharacter->getVisualParamWeight("Breast_Physics_Gravity"); @@ -261,51 +236,72 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) mBreastMaxVelocityParam[0] = mCharacter->getVisualParamWeight("Breast_Physics_Side_Max_Velocity"); mBreastDragParam[0] = mCharacter->getVisualParamWeight("Breast_Physics_Side_Drag"); - mBreastSpringParam[2] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Spring"); - mBreastGainParam[2] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Gain"); - mBreastDampingParam[2] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Damping"); - mBreastMaxVelocityParam[2] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Max_Velocity"); - mBreastDragParam[2] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Drag"); + mBreastSpringParam[1] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Spring"); + mBreastGainParam[1] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Gain"); + mBreastDampingParam[1] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Damping"); + mBreastMaxVelocityParam[1] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Max_Velocity"); + mBreastDragParam[1] = mCharacter->getVisualParamWeight("Breast_Physics_UpDown_Drag"); - const BOOL is_self = (dynamic_cast(this) != NULL); - + // Get the current morph parameters. LLVector3 breast_user_local_pt(0,0,0); - - for (U32 i=0; i < 3; i++) + for (U32 i=0; i < N_PARAMS; i++) { if (mBreastParamsUser[i] != NULL) { breast_user_local_pt[i] = mBreastParamsUser[i]->getWeight(); } } - + LLVector3 breast_current_local_pt = mBreastLastPosition_local_pt; - + + // + // End parameters and settings + //////////////////////////////////////////////////////////////////////////////// + + + //////////////////////////////////////////////////////////////////////////////// + // Calculate velocity and acceleration in parameter space. + // + const LLVector3 char_velocity_local_vec = calculateVelocity_local(time_delta); const LLVector3 char_acceleration_local_vec = calculateAcceleration_local(char_velocity_local_vec, time_delta); mCharLastVelocity_local_vec = char_velocity_local_vec; LLJoint *chest_joint = mChestState->getJoint(); mCharLastPosition_world_pt = chest_joint->getWorldPosition(); - + // + // End velocity and acceleration + //////////////////////////////////////////////////////////////////////////////// + + + //////////////////////////////////////////////////////////////////////////////// + // Calculate the total force + // + + // Spring force is a restoring force towards the original user-set breast position. + // F = kx const LLVector3 spring_length_local = breast_current_local_pt-breast_user_local_pt; LLVector3 force_spring_local_vec = -spring_length_local; force_spring_local_vec *= mBreastSpringParam; + // Acceleration is the force that comes from the change in velocity of the torso. + // F = ma + mg LLVector3 force_accel_local_vec = char_acceleration_local_vec * mBreastMassParam; const LLVector3 force_gravity_local_vec = toLocal(LLVector3(0,0,1))* mBreastGravityParam * mBreastMassParam; force_accel_local_vec += force_gravity_local_vec; - force_accel_local_vec[0] *= mBreastGainParam[0]; - force_accel_local_vec[1] *= mBreastGainParam[1]; - force_accel_local_vec[2] *= mBreastGainParam[2]; - - LLVector3 force_damping_local_vec = -mBreastDampingParam; force_damping_local_vec *= mBreastVelocity_local_vec; + force_accel_local_vec *= mBreastGainParam; - LLVector3 force_drag_local_vec = .5*char_velocity_local_vec; // should square char_velocity_vec - force_drag_local_vec[0] *= mBreastDragParam[0]; - force_drag_local_vec[1] *= mBreastDragParam[1]; - force_drag_local_vec[2] *= mBreastDragParam[2]; + // Damping is a restoring force that opposes the current velocity. + // F = -kv + LLVector3 force_damping_local_vec = -mBreastDampingParam; + force_damping_local_vec *= mBreastVelocity_local_vec; + + // Drag is a force imparted by velocity, intuitively it is similar to wind resistance. + // F = .5v*v + LLVector3 force_drag_local_vec = .5*char_velocity_local_vec; + force_drag_local_vec *= char_velocity_local_vec; + force_drag_local_vec *= mBreastDragParam[0]; LLVector3 force_net_local_vec = force_accel_local_vec + @@ -314,17 +310,29 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) force_damping_local_vec + force_drag_local_vec; + // + // End total force + //////////////////////////////////////////////////////////////////////////////// + + + //////////////////////////////////////////////////////////////////////////////// + // Calculate new params + // + // Calculate the new acceleration based on the net force. + // a = F/m LLVector3 acceleration_local_vec = force_net_local_vec / mBreastMassParam; mBreastVelocity_local_vec += acceleration_local_vec; mBreastVelocity_local_vec.clamp(-mBreastMaxVelocityParam*100.0, mBreastMaxVelocityParam*100.0); + // Calculate the new parameters and clamp them to the min/max ranges. LLVector3 new_local_pt = breast_current_local_pt + mBreastVelocity_local_vec*time_delta; new_local_pt.clamp(mBreastParamsMin,mBreastParamsMax); - + // Set the new parameters. for (U32 i=0; i < 3; i++) { + // If the param is disabled, just set the param to the user value. if (mBreastMaxVelocityParam[i] == 0) { new_local_pt[i] = breast_user_local_pt[i]; @@ -337,32 +345,26 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) } } - if (mFileWrite != NULL) - { - fprintf(mFileWrite,"%f\t%f\t%f\t%f\t\t%f\t%f\t%f\t \t%f\t%f\t%f\t%f\t%f\t%f\n", - mCharLastPosition_world_pt[2], - breast_current_local_pt[2], - acceleration_local_vec[2], - mBreastVelocity_local_vec[2], - - force_accel_local_vec[2], - force_spring_local_vec[2], - force_damping_local_vec[2], - - force_accel_local_vec[2], - force_damping_local_vec[2], - force_drag_local_vec[2], - force_net_local_vec[2], - time_delta, - mBreastMassParam - ); - } - mBreastLastPosition_local_pt = new_local_pt; + // + // End calculate new params + //////////////////////////////////////////////////////////////////////////////// + + + //////////////////////////////////////////////////////////////////////////////// + // Conditionally update the visual params + // + + // Updating the visual params (i.e. what the user sees) is fairly expensive. + // So only update if the params have changed enough, and also take into account + // the graphics LOD settings. + + // For non-self, if the avatar is small enough visually, then don't update. + const BOOL is_self = (dynamic_cast(this) != NULL); if (!is_self) { - const F32 area_for_max_settings = 300.0; + const F32 area_for_max_settings = 200.0; const F32 area_for_min_settings = 1400.0; const F32 area_for_this_setting = area_for_max_settings + (area_for_min_settings-area_for_max_settings)*(1.0-lod_factor); @@ -373,7 +375,7 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) } } - + // If the parameter hasn't changed enough, then don't update. LLVector3 position_diff = mBreastLastUpdatePosition_local_pt-new_local_pt; for (U32 i=0; i < 3; i++) { @@ -385,7 +387,10 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) return TRUE; } } - + + // + // End update visual params + //////////////////////////////////////////////////////////////////////////////// return TRUE; } diff --git a/indra/newview/llbreastmotion.h b/indra/newview/llbreastmotion.h index da71962453..8578d4ad1a 100644 --- a/indra/newview/llbreastmotion.h +++ b/indra/newview/llbreastmotion.h @@ -153,7 +153,6 @@ private: LLFrameTimer mTimer; F32 mLastTime; - FILE *mFileWrite; U32 mFileTicks; }; -- cgit v1.3 From db28075a8db2f1eff8f318688e57ae0c76931508 Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Tue, 31 Aug 2010 18:06:03 -0400 Subject: Added debug setting for profiling. --- indra/newview/app_settings/settings.xml | 13 ++++++++++++- indra/newview/llbreastmotion.cpp | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'indra/newview/llbreastmotion.cpp') diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index ecb36273ec..58ed998ba0 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -610,7 +610,7 @@ AvatarPhysics Comment - Enable avatar physics, such as breast physics. + Enable avatar physics. Persist 1 Type @@ -618,6 +618,17 @@ Value 1 + AvatarPhysicsTest + + Comment + Simulate continuous physics behavior on all nearby avatars. + Persist + 1 + Type + Boolean + Value + 0 + AvatarSex Comment diff --git a/indra/newview/llbreastmotion.cpp b/indra/newview/llbreastmotion.cpp index b38e818dbd..57dc169ff3 100644 --- a/indra/newview/llbreastmotion.cpp +++ b/indra/newview/llbreastmotion.cpp @@ -325,6 +325,12 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) mBreastVelocity_local_vec += acceleration_local_vec; mBreastVelocity_local_vec.clamp(-mBreastMaxVelocityParam*100.0, mBreastMaxVelocityParam*100.0); + // Temporary debugging setting to cause all avatars to move, for profiling purposes. + if (gSavedSettings.getBOOL("AvatarPhysicsTest")) + { + mBreastVelocity_local_vec[0] = sin(mTimer.getElapsedTimeF32()*4.0)*5.0; + mBreastVelocity_local_vec[1] = sin(mTimer.getElapsedTimeF32()*3.0)*5.0; + } // Calculate the new parameters and clamp them to the min/max ranges. LLVector3 new_local_pt = breast_current_local_pt + mBreastVelocity_local_vec*time_delta; new_local_pt.clamp(mBreastParamsMin,mBreastParamsMax); -- cgit v1.3 From 45639aa0d1889a6cbd9223e987740d25d96ed8fd Mon Sep 17 00:00:00 2001 From: Loren Shih Date: Tue, 31 Aug 2010 18:19:42 -0400 Subject: Removed min pixel area for debugging performance. --- indra/newview/llbreastmotion.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/llbreastmotion.cpp') diff --git a/indra/newview/llbreastmotion.cpp b/indra/newview/llbreastmotion.cpp index 57dc169ff3..7c205a8b9f 100644 --- a/indra/newview/llbreastmotion.cpp +++ b/indra/newview/llbreastmotion.cpp @@ -45,7 +45,7 @@ #include "llviewervisualparam.h" #include "llvoavatarself.h" -#define MIN_REQUIRED_PIXEL_AREA_BREAST_MOTION 1000.f; +#define MIN_REQUIRED_PIXEL_AREA_BREAST_MOTION 0.f; #define N_PARAMS 2 @@ -370,7 +370,7 @@ BOOL LLBreastMotion::onUpdate(F32 time, U8* joint_mask) const BOOL is_self = (dynamic_cast(this) != NULL); if (!is_self) { - const F32 area_for_max_settings = 200.0; + const F32 area_for_max_settings = 0.0; const F32 area_for_min_settings = 1400.0; const F32 area_for_this_setting = area_for_max_settings + (area_for_min_settings-area_for_max_settings)*(1.0-lod_factor); -- cgit v1.3