diff options
author | Seraph Linden <none@none> | 2011-04-03 17:25:17 -0400 |
---|---|---|
committer | Seraph Linden <none@none> | 2011-04-03 17:25:17 -0400 |
commit | f433ad353131cc1df581be11a9ff6184767a0ed6 (patch) | |
tree | f8008192bc74e74a3f8b75e8f5c9fd18e8958349 /indra/newview | |
parent | e8f2380489b9ce58f7a7bb047231256ae7833309 (diff) |
Changed _driven params to cross wearables; major fix so they wouldn't keep getting reset to default values from wearable.
Took out smoothing param.
Redefined maxeffect param to affect range of motion.
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/character/avatar_lad.xml | 127 | ||||
-rw-r--r-- | indra/newview/llphysicsmotion.cpp | 73 | ||||
-rw-r--r-- | indra/newview/llpolymesh.cpp | 1812 |
3 files changed, 998 insertions, 1014 deletions
diff --git a/indra/newview/character/avatar_lad.xml b/indra/newview/character/avatar_lad.xml index 35f88a7a5c..f8229ec465 100644 --- a/indra/newview/character/avatar_lad.xml +++ b/indra/newview/character/avatar_lad.xml @@ -4324,6 +4324,7 @@ group="1" name="Belly_Physics_Torso_UpDown_Driven" wearable="physics" + cross_wearable="true" edit_group="driven" value_default="0" value_min="-1" @@ -4336,6 +4337,7 @@ group="1" name="Breast_Physics_LeftRight_Driven" wearable="physics" + cross_wearable="true" edit_group="driven" value_default="0" value_min="-2" @@ -4856,20 +4858,24 @@ group="1" name="Belly_Physics_Legs_UpDown_Driven" wearable="physics" + cross_wearable="true" edit_group="driven" value_min="-1" value_max="1"> <param_morph /> </param> - + <param id="1205" group="1" name="Butt_Physics_UpDown_Driven" wearable="physics" + cross_wearable="true" edit_group="driven" - value_default="0"> + value_default="0" + value_min="-1" + value_max="1"> <param_morph /> </param> @@ -4878,10 +4884,11 @@ group="1" name="Butt_Physics_LeftRight_Driven" wearable="physics" + cross_wearable="true" edit_group="driven" value_default="0" - value_min="-2" - value_max="2"> + value_min="-1" + value_max="1"> <param_morph /> </param> @@ -5268,6 +5275,7 @@ group="1" name="Belly_Physics_Skirt_UpDown_Driven" wearable="physics" + cross_wearable="true" edit_group="driven" value_default="0" value_min="-1" @@ -11829,19 +11837,6 @@ render_pass="bump"> id="10001" group="0" sex="female" - name="Breast_Physics_Smoothing" - label="Breast Physics Smoothing" - wearable="physics" - edit_group="physics_advanced" - value_default="2" - value_min="1" - value_max="10"> - <param_driver /> - </param> - <param - id="10002" - group="0" - sex="female" name="Breast_Physics_Gravity" label="Breast Physics Gravity" wearable="physics" @@ -11853,7 +11848,7 @@ render_pass="bump"> </param> <param - id="10003" + id="10002" group="0" sex="female" name="Breast_Physics_Drag" @@ -11867,7 +11862,7 @@ render_pass="bump"> </param> <param - id="10004" + id="10003" group="0" sex="female" name="Breast_Physics_UpDown_Max_Effect" @@ -11876,11 +11871,11 @@ render_pass="bump"> edit_group="physics_breasts_updown" value_default="0" value_min="0" - value_max="10"> + value_max="1"> <param_driver /> </param> <param - id="10005" + id="10004" group="0" sex="female" name="Breast_Physics_UpDown_Spring" @@ -11893,7 +11888,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10006" + id="10005" group="0" sex="female" name="Breast_Physics_UpDown_Gain" @@ -11906,7 +11901,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10007" + id="10006" group="0" sex="female" name="Breast_Physics_UpDown_Damping" @@ -11922,7 +11917,7 @@ render_pass="bump"> </param> <param - id="10008" + id="10007" group="0" sex="female" name="Breast_Physics_InOut_Max_Effect" @@ -11931,11 +11926,11 @@ render_pass="bump"> edit_group="physics_breasts_inout" value_default="0" value_min="0" - value_max="10"> + value_max="1"> <param_driver /> </param> <param - id="10009" + id="10008" group="0" sex="female" name="Breast_Physics_InOut_Spring" @@ -11948,7 +11943,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10010" + id="10009" group="0" sex="female" name="Breast_Physics_InOut_Gain" @@ -11961,7 +11956,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10011" + id="10010" group="0" sex="female" name="Breast_Physics_InOut_Damping" @@ -11975,7 +11970,7 @@ render_pass="bump"> </param> <param - id="10012" + id="10011" group="0" name="Belly_Physics_Mass" label="Belly Physics Mass" @@ -11987,19 +11982,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10013" - group="0" - name="Belly_Physics_Smoothing" - label="Belly Physics Smoothing" - wearable="physics" - edit_group="physics_advanced" - value_default="2" - value_min="1" - value_max="10"> - <param_driver /> - </param> - <param - id="10014" + id="10012" group="0" name="Belly_Physics_Gravity" label="Belly Physics Gravity" @@ -12011,7 +11994,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10015" + id="10013" group="0" name="Belly_Physics_Drag" label="Belly Physics Drag" @@ -12023,7 +12006,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10016" + id="10014" group="0" name="Belly_Physics_UpDown_Max_Effect" label="Belly Physics UpDown Max Effect" @@ -12031,11 +12014,11 @@ render_pass="bump"> edit_group="physics_belly_updown" value_default="0" value_min="0" - value_max="10"> + value_max="1"> <param_driver /> </param> <param - id="10017" + id="10015" group="0" name="Belly_Physics_UpDown_Spring" label="Belly Physics UpDown Spring" @@ -12047,7 +12030,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10018" + id="10016" group="0" name="Belly_Physics_UpDown_Gain" label="Belly Physics UpDown Gain" @@ -12059,7 +12042,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10019" + id="10017" group="0" name="Belly_Physics_UpDown_Damping" label="Belly Physics UpDown Damping" @@ -12072,7 +12055,7 @@ render_pass="bump"> </param> <param - id="10020" + id="10018" group="0" name="Butt_Physics_Mass" label="Butt Physics Mass" @@ -12084,19 +12067,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10021" - group="0" - name="Butt_Physics_Smoothing" - label="Butt Physics Smoothing" - wearable="physics" - edit_group="physics_advanced" - value_default="2" - value_min="1" - value_max="10"> - <param_driver /> - </param> - <param - id="10022" + id="10019" group="0" name="Butt_Physics_Gravity" label="Butt Physics Gravity" @@ -12108,7 +12079,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10023" + id="10020" group="0" name="Butt_Physics_Drag" label="Butt Physics Drag" @@ -12121,7 +12092,7 @@ render_pass="bump"> </param> <param - id="10024" + id="10021" group="0" name="Butt_Physics_UpDown_Max_Effect" label="Butt Physics UpDown Max Effect" @@ -12129,11 +12100,11 @@ render_pass="bump"> edit_group="physics_butt_updown" value_default="0" value_min="0" - value_max="10"> + value_max="1"> <param_driver /> </param> <param - id="10025" + id="10022" group="0" name="Butt_Physics_UpDown_Spring" label="Butt Physics UpDown Spring" @@ -12145,7 +12116,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10026" + id="10023" group="0" name="Butt_Physics_UpDown_Gain" label="Butt Physics UpDown Gain" @@ -12157,7 +12128,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10027" + id="10024" group="0" name="Butt_Physics_UpDown_Damping" label="Butt Physics UpDown Damping" @@ -12170,7 +12141,7 @@ render_pass="bump"> </param> <param - id="10028" + id="10025" group="0" name="Butt_Physics_LeftRight_Max_Effect" label="Butt Physics LeftRight Max Effect" @@ -12178,11 +12149,11 @@ render_pass="bump"> edit_group="physics_butt_leftright" value_default="0" value_min="0" - value_max="10"> + value_max="1"> <param_driver /> </param> <param - id="10029" + id="10026" group="0" name="Butt_Physics_LeftRight_Spring" label="Butt Physics LeftRight Spring" @@ -12194,7 +12165,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10030" + id="10027" group="0" name="Butt_Physics_LeftRight_Gain" label="Butt Physics LeftRight Gain" @@ -12206,7 +12177,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10031" + id="10028" group="0" name="Butt_Physics_LeftRight_Damping" label="Butt Physics LeftRight Damping" @@ -12219,7 +12190,7 @@ render_pass="bump"> </param> <param - id="10032" + id="10029" group="0" name="Breast_Physics_LeftRight_Max_Effect" label="Breast Physics LeftRight Max Effect" @@ -12227,11 +12198,11 @@ render_pass="bump"> edit_group="physics_breasts_leftright" value_default="0" value_min="0" - value_max="10"> + value_max="1"> <param_driver /> </param> <param - id="10033" + id="10030" group="0" name="Breast_Physics_LeftRight_Spring" label="Breast Physics LeftRight Spring" @@ -12243,7 +12214,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10034" + id="10031" group="0" name="Breast_Physics_LeftRight_Gain" label="Breast Physics LeftRight Gain" @@ -12255,7 +12226,7 @@ render_pass="bump"> <param_driver /> </param> <param - id="10035" + id="10032" group="0" name="Breast_Physics_LeftRight_Damping" label="Breast Physics LeftRight Damping" diff --git a/indra/newview/llphysicsmotion.cpp b/indra/newview/llphysicsmotion.cpp index 7b5ae0199a..57ba76cf6d 100644 --- a/indra/newview/llphysicsmotion.cpp +++ b/indra/newview/llphysicsmotion.cpp @@ -176,11 +176,10 @@ default_controller_map_t initDefaultController() {
default_controller_map_t controller;
controller["Mass"] = 0.2f;
- controller["Smoothing"] = 2.0f;
controller["Gravity"] = 0.0f;
controller["Damping"] = .05f;
controller["Drag"] = 0.15f;
- controller["MaxSpeed"] = 0.1f;
+ controller["MaxEffect"] = 0.1f;
controller["Spring"] = 0.1f;
controller["Gain"] = 10.0f;
return controller;
@@ -242,11 +241,10 @@ LLMotion::LLMotionInitStatus LLPhysicsMotionController::onInitialize(LLCharacter {
controller_map_t controller;
controller["Mass"] = "Breast_Physics_Mass";
- controller["Smoothing"] = "Breast_Physics_Smoothing";
controller["Gravity"] = "Breast_Physics_Gravity";
controller["Drag"] = "Breast_Physics_Drag";
controller["Damping"] = "Breast_Physics_InOut_Damping";
- controller["MaxSpeed"] = "Breast_Physics_InOut_Max_Effect";
+ controller["MaxEffect"] = "Breast_Physics_InOut_Max_Effect";
controller["Spring"] = "Breast_Physics_InOut_Spring";
controller["Gain"] = "Breast_Physics_InOut_Gain";
LLPhysicsMotion *motion = new LLPhysicsMotion("Breast_Physics_InOut_Controller",
@@ -267,11 +265,10 @@ LLMotion::LLMotionInitStatus LLPhysicsMotionController::onInitialize(LLCharacter {
controller_map_t controller;
controller["Mass"] = "Breast_Physics_Mass";
- controller["Smoothing"] = "Breast_Physics_Smoothing";
controller["Gravity"] = "Breast_Physics_Gravity";
controller["Drag"] = "Breast_Physics_Drag";
controller["Damping"] = "Breast_Physics_UpDown_Damping";
- controller["MaxSpeed"] = "Breast_Physics_UpDown_Max_Effect";
+ controller["MaxEffect"] = "Breast_Physics_UpDown_Max_Effect";
controller["Spring"] = "Breast_Physics_UpDown_Spring";
controller["Gain"] = "Breast_Physics_UpDown_Gain";
LLPhysicsMotion *motion = new LLPhysicsMotion("Breast_Physics_UpDown_Controller",
@@ -292,11 +289,10 @@ LLMotion::LLMotionInitStatus LLPhysicsMotionController::onInitialize(LLCharacter {
controller_map_t controller;
controller["Mass"] = "Breast_Physics_Mass";
- controller["Smoothing"] = "Breast_Physics_Smoothing";
controller["Gravity"] = "Breast_Physics_Gravity";
controller["Drag"] = "Breast_Physics_Drag";
controller["Damping"] = "Breast_Physics_LeftRight_Damping";
- controller["MaxSpeed"] = "Breast_Physics_LeftRight_Max_Effect";
+ controller["MaxEffect"] = "Breast_Physics_LeftRight_Max_Effect";
controller["Spring"] = "Breast_Physics_LeftRight_Spring";
controller["Gain"] = "Breast_Physics_LeftRight_Gain";
LLPhysicsMotion *motion = new LLPhysicsMotion("Breast_Physics_LeftRight_Controller",
@@ -312,23 +308,21 @@ LLMotion::LLMotionInitStatus LLPhysicsMotionController::onInitialize(LLCharacter }
addMotion(motion);
}
-
// Butt Bounce
{
controller_map_t controller;
controller["Mass"] = "Butt_Physics_Mass";
- controller["Smoothing"] = "Butt_Physics_Smoothing";
controller["Gravity"] = "Butt_Physics_Gravity";
controller["Drag"] = "Butt_Physics_Drag";
controller["Damping"] = "Butt_Physics_UpDown_Damping";
- controller["MaxSpeed"] = "Butt_Physics_UpDown_Max_Effect";
+ controller["MaxEffect"] = "Butt_Physics_UpDown_Max_Effect";
controller["Spring"] = "Butt_Physics_UpDown_Spring";
controller["Gain"] = "Butt_Physics_UpDown_Gain";
LLPhysicsMotion *motion = new LLPhysicsMotion("Butt_Physics_UpDown_Controller",
"",
"mPelvis",
character,
- LLVector3(0,0,1),
+ LLVector3(0,0,-1),
controller);
if (!motion->initialize())
{
@@ -342,11 +336,10 @@ LLMotion::LLMotionInitStatus LLPhysicsMotionController::onInitialize(LLCharacter {
controller_map_t controller;
controller["Mass"] = "Butt_Physics_Mass";
- controller["Smoothing"] = "Butt_Physics_Smoothing";
controller["Gravity"] = "Butt_Physics_Gravity";
controller["Drag"] = "Butt_Physics_Drag";
controller["Damping"] = "Butt_Physics_LeftRight_Damping";
- controller["MaxSpeed"] = "Butt_Physics_LeftRight_Max_Effect";
+ controller["MaxEffect"] = "Butt_Physics_LeftRight_Max_Effect";
controller["Spring"] = "Butt_Physics_LeftRight_Spring";
controller["Gain"] = "Butt_Physics_LeftRight_Gain";
LLPhysicsMotion *motion = new LLPhysicsMotion("Butt_Physics_LeftRight_Controller",
@@ -367,11 +360,10 @@ LLMotion::LLMotionInitStatus LLPhysicsMotionController::onInitialize(LLCharacter {
controller_map_t controller;
controller["Mass"] = "Belly_Physics_Mass";
- controller["Smoothing"] = "Belly_Physics_Smoothing";
controller["Gravity"] = "Belly_Physics_Gravity";
controller["Drag"] = "Belly_Physics_Drag";
controller["Damping"] = "Belly_Physics_UpDown_Damping";
- controller["MaxSpeed"] = "Belly_Physics_UpDown_Max_Effect";
+ controller["MaxEffect"] = "Belly_Physics_UpDown_Max_Effect";
controller["Spring"] = "Belly_Physics_UpDown_Spring";
controller["Gain"] = "Belly_Physics_UpDown_Gain";
LLPhysicsMotion *motion = new LLPhysicsMotion("Belly_Physics_UpDown_Controller",
@@ -427,7 +419,8 @@ F32 LLPhysicsMotion::calculateVelocity_local(const F32 time_delta) F32 LLPhysicsMotion::calculateAcceleration_local(const F32 velocity_local,
const F32 time_delta)
{
- const F32 smoothing = getParamValue("Smoothing");
+// const F32 smoothing = getParamValue("Smoothing");
+ static const F32 smoothing = 3.0f; // Removed smoothing param since it's probably not necessary
const F32 acceleration_local = velocity_local - mVelocityJoint_local;
const F32 smoothed_acceleration_local =
@@ -504,16 +497,17 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) const F32 behavior_drag = getParamValue("Drag");
const BOOL physics_test = gSavedSettings.getBOOL("AvatarPhysicsTest");
- F32 behavior_maxspeed = getParamValue("MaxSpeed");
+ F32 behavior_maxeffect = getParamValue("MaxEffect");
if (physics_test)
- behavior_maxspeed = 100.0f;
-
- if (behavior_maxspeed == 0)
- return FALSE;
+ behavior_maxeffect = 1.0f;
+ // Maximum effect is [0,1] range.
+ const F32 min_val = 0.5f-behavior_maxeffect/2.0;
+ const F32 max_val = 0.5f+behavior_maxeffect/2.0;
+ // mPositon_local should be in normalized 0,1 range already. Just making sure...
F32 position_current_local = llclamp(mPosition_local,
0.0f,
- 1.0f); // Normalized [0,1] range
+ 1.0f);
// Normalize the param position to be from [0,1].
// We have to use normalized values because there may be more than one driven param,
@@ -522,6 +516,13 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) F32 position_user_local = mParamUser->getWeight();
position_user_local = (position_user_local - mParamUser->getMinWeight()) / (mParamUser->getMaxWeight() - mParamUser->getMinWeight());
+ // If the effect is turned off then don't process unless we need one more update
+ // to set the position to the default (i.e. user) position.
+ if ((behavior_maxeffect == 0) && (position_current_local == position_user_local))
+ {
+ return FALSE;
+ }
+
//
// End parameters and settings
////////////////////////////////////////////////////////////////////////////////
@@ -583,9 +584,10 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) // Calculate the new acceleration based on the net force.
// a = F/m
const F32 acceleration_new_local = force_net / behavior_mass;
+ const F32 max_acceleration = 10.0f; // magic number, used to be customizable.
F32 velocity_new_local = mVelocity_local + acceleration_new_local;
velocity_new_local = llclamp(velocity_new_local,
- -behavior_maxspeed, behavior_maxspeed);
+ -max_acceleration, max_acceleration);
// Temporary debugging setting to cause all avatars to move, for profiling purposes.
if (physics_test)
@@ -593,19 +595,20 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) velocity_new_local = sin(time*4.0);
}
// Calculate the new parameters, or remain unchanged if max speed is 0.
- const F32 position_new_local = (behavior_maxspeed != 0) ?
- (position_current_local + velocity_new_local*time_delta) :
- position_user_local;
+ F32 position_new_local = position_current_local + velocity_new_local*time_delta;
+ if (behavior_maxeffect == 0)
+ position_new_local = position_user_local;
// Zero out the velocity if the param is being pushed beyond its limits.
- if (position_new_local < 0 || position_new_local > 1)
+ if ((position_new_local < min_val && velocity_new_local < 0) ||
+ (position_new_local > max_val && velocity_new_local > 0))
{
velocity_new_local = 0;
}
const F32 position_new_local_clamped = llclamp(position_new_local,
- 0.0f,
- 1.0f);
+ min_val,
+ max_val);
// Set the new param.
// If a specific param has been declared, then set that one.
@@ -621,6 +624,16 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) llassert_always(driver_param);
if (driver_param)
{
+ // If this is one of our "hidden" driver params, then make sure it's
+ // the default value.
+ if ((driver_param->getGroup() != VISUAL_PARAM_GROUP_TWEAKABLE) &&
+ (driver_param->getGroup() != VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT) &&
+ (driver_param->getVisualParamWeight() != 0))
+ {
+ mCharacter->setVisualParamWeight(driver_param,
+ 0,
+ FALSE);
+ }
for (LLDriverParam::entry_list_t::iterator iter = driver_param->mDriven.begin();
iter != driver_param->mDriven.end();
++iter)
diff --git a/indra/newview/llpolymesh.cpp b/indra/newview/llpolymesh.cpp index c1144958eb..7a2ecffb34 100644 --- a/indra/newview/llpolymesh.cpp +++ b/indra/newview/llpolymesh.cpp @@ -44,11 +44,11 @@ #define HEADER_ASCII "Linden Mesh 1.0" #define HEADER_BINARY "Linden Binary Mesh 1.0" -extern LLControlGroup gSavedSettings; // read only +extern LLControlGroup gSavedSettings; // read only LLPolyMorphData *clone_morph_param(const LLPolyMorphData *src_data, - const LLVector3 &direction, - const std::string &name); + const LLVector3 &direction, + const std::string &name); LLPolyMorphData *clone_morph_param_cleavage(const LLPolyMorphData *src_data, F32 scale, const std::string &name); @@ -63,28 +63,28 @@ LLPolyMesh::LLPolyMeshSharedDataTable LLPolyMesh::sGlobalSharedMeshList; //----------------------------------------------------------------------------- LLPolyMeshSharedData::LLPolyMeshSharedData() { - mNumVertices = 0; - mBaseCoords = NULL; - mBaseNormals = NULL; - mBaseBinormals = NULL; - mTexCoords = NULL; - mDetailTexCoords = NULL; - mWeights = NULL; - mHasWeights = FALSE; - mHasDetailTexCoords = FALSE; + mNumVertices = 0; + mBaseCoords = NULL; + mBaseNormals = NULL; + mBaseBinormals = NULL; + mTexCoords = NULL; + mDetailTexCoords = NULL; + mWeights = NULL; + mHasWeights = FALSE; + mHasDetailTexCoords = FALSE; - mNumFaces = 0; - mFaces = NULL; + mNumFaces = 0; + mFaces = NULL; - mNumJointNames = 0; - mJointNames = NULL; + mNumJointNames = 0; + mJointNames = NULL; - mTriangleIndices = NULL; - mNumTriangleIndices = 0; + mTriangleIndices = NULL; + mNumTriangleIndices = 0; - mReferenceData = NULL; + mReferenceData = NULL; - mLastIndexOffset = -1; + mLastIndexOffset = -1; } //----------------------------------------------------------------------------- @@ -92,9 +92,9 @@ LLPolyMeshSharedData::LLPolyMeshSharedData() //----------------------------------------------------------------------------- LLPolyMeshSharedData::~LLPolyMeshSharedData() { - freeMeshData(); - for_each(mMorphData.begin(), mMorphData.end(), DeletePointer()); - mMorphData.clear(); + freeMeshData(); + for_each(mMorphData.begin(), mMorphData.end(), DeletePointer()); + mMorphData.clear(); } //----------------------------------------------------------------------------- @@ -102,19 +102,19 @@ LLPolyMeshSharedData::~LLPolyMeshSharedData() //----------------------------------------------------------------------------- void LLPolyMeshSharedData::setupLOD(LLPolyMeshSharedData* reference_data) { - mReferenceData = reference_data; - - if (reference_data) - { - mBaseCoords = reference_data->mBaseCoords; - mBaseNormals = reference_data->mBaseNormals; - mBaseBinormals = reference_data->mBaseBinormals; - mTexCoords = reference_data->mTexCoords; - mDetailTexCoords = reference_data->mDetailTexCoords; - mWeights = reference_data->mWeights; - mHasWeights = reference_data->mHasWeights; - mHasDetailTexCoords = reference_data->mHasDetailTexCoords; - } + mReferenceData = reference_data; + + if (reference_data) + { + mBaseCoords = reference_data->mBaseCoords; + mBaseNormals = reference_data->mBaseNormals; + mBaseBinormals = reference_data->mBaseBinormals; + mTexCoords = reference_data->mTexCoords; + mDetailTexCoords = reference_data->mDetailTexCoords; + mWeights = reference_data->mWeights; + mHasWeights = reference_data->mHasWeights; + mHasDetailTexCoords = reference_data->mHasDetailTexCoords; + } } //----------------------------------------------------------------------------- @@ -122,41 +122,41 @@ void LLPolyMeshSharedData::setupLOD(LLPolyMeshSharedData* reference_data) //----------------------------------------------------------------------------- void LLPolyMeshSharedData::freeMeshData() { - if (!mReferenceData) - { - mNumVertices = 0; + if (!mReferenceData) + { + mNumVertices = 0; - delete [] mBaseCoords; - mBaseCoords = NULL; + delete [] mBaseCoords; + mBaseCoords = NULL; - delete [] mBaseNormals; - mBaseNormals = NULL; + delete [] mBaseNormals; + mBaseNormals = NULL; - delete [] mBaseBinormals; - mBaseBinormals = NULL; + delete [] mBaseBinormals; + mBaseBinormals = NULL; - delete [] mTexCoords; - mTexCoords = NULL; + delete [] mTexCoords; + mTexCoords = NULL; - delete [] mDetailTexCoords; - mDetailTexCoords = NULL; + delete [] mDetailTexCoords; + mDetailTexCoords = NULL; - delete [] mWeights; - mWeights = NULL; - } + delete [] mWeights; + mWeights = NULL; + } - mNumFaces = 0; - delete [] mFaces; - mFaces = NULL; + mNumFaces = 0; + delete [] mFaces; + mFaces = NULL; - mNumJointNames = 0; - delete [] mJointNames; - mJointNames = NULL; + mNumJointNames = 0; + delete [] mJointNames; + mJointNames = NULL; - delete [] mTriangleIndices; - mTriangleIndices = NULL; + delete [] mTriangleIndices; + mTriangleIndices = NULL; -// mVertFaceMap.deleteAllData(); +// mVertFaceMap.deleteAllData(); } // compate_int is used by the qsort function to sort the index array @@ -167,26 +167,26 @@ int compare_int(const void *a, const void *b); //----------------------------------------------------------------------------- void LLPolyMeshSharedData::genIndices(S32 index_offset) { - if (index_offset == mLastIndexOffset) - { - return; - } - - delete []mTriangleIndices; - mTriangleIndices = new U32[mNumTriangleIndices]; - - S32 cur_index = 0; - for (S32 i = 0; i < mNumFaces; i++) - { - mTriangleIndices[cur_index] = mFaces[i][0] + index_offset; - cur_index++; - mTriangleIndices[cur_index] = mFaces[i][1] + index_offset; - cur_index++; - mTriangleIndices[cur_index] = mFaces[i][2] + index_offset; - cur_index++; - } - - mLastIndexOffset = index_offset; + if (index_offset == mLastIndexOffset) + { + return; + } + + delete []mTriangleIndices; + mTriangleIndices = new U32[mNumTriangleIndices]; + + S32 cur_index = 0; + for (S32 i = 0; i < mNumFaces; i++) + { + mTriangleIndices[cur_index] = mFaces[i][0] + index_offset; + cur_index++; + mTriangleIndices[cur_index] = mFaces[i][1] + index_offset; + cur_index++; + mTriangleIndices[cur_index] = mFaces[i][2] + index_offset; + cur_index++; + } + + mLastIndexOffset = index_offset; } //-------------------------------------------------------------------- @@ -194,30 +194,30 @@ void LLPolyMeshSharedData::genIndices(S32 index_offset) //-------------------------------------------------------------------- U32 LLPolyMeshSharedData::getNumKB() { - U32 num_kb = sizeof(LLPolyMesh); - - if (!isLOD()) - { - num_kb += mNumVertices * - ( sizeof(LLVector3) + // coords - sizeof(LLVector3) + // normals - sizeof(LLVector2) ); // texCoords - } - - if (mHasDetailTexCoords && !isLOD()) - { - num_kb += mNumVertices * sizeof(LLVector2); // detailTexCoords - } - - if (mHasWeights && !isLOD()) - { - num_kb += mNumVertices * sizeof(float); // weights - } - - num_kb += mNumFaces * sizeof(LLPolyFace); // faces - - num_kb /= 1024; - return num_kb; + U32 num_kb = sizeof(LLPolyMesh); + + if (!isLOD()) + { + num_kb += mNumVertices * + ( sizeof(LLVector3) + // coords + sizeof(LLVector3) + // normals + sizeof(LLVector2) ); // texCoords + } + + if (mHasDetailTexCoords && !isLOD()) + { + num_kb += mNumVertices * sizeof(LLVector2); // detailTexCoords + } + + if (mHasWeights && !isLOD()) + { + num_kb += mNumVertices * sizeof(float); // weights + } + + num_kb += mNumFaces * sizeof(LLPolyFace); // faces + + num_kb /= 1024; + return num_kb; } //----------------------------------------------------------------------------- @@ -225,19 +225,19 @@ U32 LLPolyMeshSharedData::getNumKB() //----------------------------------------------------------------------------- BOOL LLPolyMeshSharedData::allocateVertexData( U32 numVertices ) { - U32 i; - mBaseCoords = new LLVector3[ numVertices ]; - mBaseNormals = new LLVector3[ numVertices ]; - mBaseBinormals = new LLVector3[ numVertices ]; - mTexCoords = new LLVector2[ numVertices ]; - mDetailTexCoords = new LLVector2[ numVertices ]; - mWeights = new F32[ numVertices ]; - for (i = 0; i < numVertices; i++) - { - mWeights[i] = 0.f; - } - mNumVertices = numVertices; - return TRUE; + U32 i; + mBaseCoords = new LLVector3[ numVertices ]; + mBaseNormals = new LLVector3[ numVertices ]; + mBaseBinormals = new LLVector3[ numVertices ]; + mTexCoords = new LLVector2[ numVertices ]; + mDetailTexCoords = new LLVector2[ numVertices ]; + mWeights = new F32[ numVertices ]; + for (i = 0; i < numVertices; i++) + { + mWeights[i] = 0.f; + } + mNumVertices = numVertices; + return TRUE; } //----------------------------------------------------------------------------- @@ -245,10 +245,10 @@ BOOL LLPolyMeshSharedData::allocateVertexData( U32 numVertices ) //----------------------------------------------------------------------------- BOOL LLPolyMeshSharedData::allocateFaceData( U32 numFaces ) { - mFaces = new LLPolyFace[ numFaces ]; - mNumFaces = numFaces; - mNumTriangleIndices = mNumFaces * 3; - return TRUE; + mFaces = new LLPolyFace[ numFaces ]; + mNumFaces = numFaces; + mNumTriangleIndices = mNumFaces * 3; + return TRUE; } //----------------------------------------------------------------------------- @@ -256,9 +256,9 @@ BOOL LLPolyMeshSharedData::allocateFaceData( U32 numFaces ) //----------------------------------------------------------------------------- BOOL LLPolyMeshSharedData::allocateJointNames( U32 numJointNames ) { - mJointNames = new std::string[ numJointNames ]; - mNumJointNames = numJointNames; - return TRUE; + mJointNames = new std::string[ numJointNames ]; + mNumJointNames = numJointNames; + return TRUE; } //-------------------------------------------------------------------- @@ -266,434 +266,434 @@ BOOL LLPolyMeshSharedData::allocateJointNames( U32 numJointNames ) //-------------------------------------------------------------------- BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) { - //------------------------------------------------------------------------- - // Open the file - //------------------------------------------------------------------------- - if(fileName.empty()) - { - llerrs << "Filename is Empty!" << llendl; - return FALSE; - } - LLFILE* fp = LLFile::fopen(fileName, "rb"); /*Flawfinder: ignore*/ - if (!fp) - { - llerrs << "can't open: " << fileName << llendl; - return FALSE; - } - - //------------------------------------------------------------------------- - // Read a chunk - //------------------------------------------------------------------------- - char header[128]; /*Flawfinder: ignore*/ - if (fread(header, sizeof(char), 128, fp) != 128) - { - llwarns << "Short read" << llendl; - } - - //------------------------------------------------------------------------- - // Check for proper binary header - //------------------------------------------------------------------------- - BOOL status = FALSE; - if ( strncmp(header, HEADER_BINARY, strlen(HEADER_BINARY)) == 0 ) /*Flawfinder: ignore*/ - { - lldebugs << "Loading " << fileName << llendl; - - //---------------------------------------------------------------- - // File Header (seek past it) - //---------------------------------------------------------------- - fseek(fp, 24, SEEK_SET); - - //---------------------------------------------------------------- - // HasWeights - //---------------------------------------------------------------- - U8 hasWeights; - size_t numRead = fread(&hasWeights, sizeof(U8), 1, fp); - if (numRead != 1) - { - llerrs << "can't read HasWeights flag from " << fileName << llendl; - return FALSE; - } - if (!isLOD()) - { - mHasWeights = (hasWeights==0) ? FALSE : TRUE; - } - - //---------------------------------------------------------------- - // HasDetailTexCoords - //---------------------------------------------------------------- - U8 hasDetailTexCoords; - numRead = fread(&hasDetailTexCoords, sizeof(U8), 1, fp); - if (numRead != 1) - { - llerrs << "can't read HasDetailTexCoords flag from " << fileName << llendl; - return FALSE; - } - - //---------------------------------------------------------------- - // Position - //---------------------------------------------------------------- - LLVector3 position; - numRead = fread(position.mV, sizeof(float), 3, fp); - llendianswizzle(position.mV, sizeof(float), 3); - if (numRead != 3) - { - llerrs << "can't read Position from " << fileName << llendl; - return FALSE; - } - setPosition( position ); - - //---------------------------------------------------------------- - // Rotation - //---------------------------------------------------------------- - LLVector3 rotationAngles; - numRead = fread(rotationAngles.mV, sizeof(float), 3, fp); - llendianswizzle(rotationAngles.mV, sizeof(float), 3); - if (numRead != 3) - { - llerrs << "can't read RotationAngles from " << fileName << llendl; - return FALSE; - } - - U8 rotationOrder; - numRead = fread(&rotationOrder, sizeof(U8), 1, fp); - - if (numRead != 1) - { - llerrs << "can't read RotationOrder from " << fileName << llendl; - return FALSE; - } - - rotationOrder = 0; - - setRotation( mayaQ( rotationAngles.mV[0], - rotationAngles.mV[1], - rotationAngles.mV[2], - (LLQuaternion::Order)rotationOrder ) ); - - //---------------------------------------------------------------- - // Scale - //---------------------------------------------------------------- - LLVector3 scale; - numRead = fread(scale.mV, sizeof(float), 3, fp); - llendianswizzle(scale.mV, sizeof(float), 3); - if (numRead != 3) - { - llerrs << "can't read Scale from " << fileName << llendl; - return FALSE; - } - setScale( scale ); - - //------------------------------------------------------------------------- - // Release any existing mesh geometry - //------------------------------------------------------------------------- - freeMeshData(); - - U16 numVertices = 0; - - //---------------------------------------------------------------- - // NumVertices - //---------------------------------------------------------------- - if (!isLOD()) - { - numRead = fread(&numVertices, sizeof(U16), 1, fp); - llendianswizzle(&numVertices, sizeof(U16), 1); - if (numRead != 1) - { - llerrs << "can't read NumVertices from " << fileName << llendl; - return FALSE; - } - - allocateVertexData( numVertices ); - - //---------------------------------------------------------------- - // Coords - //---------------------------------------------------------------- - numRead = fread(mBaseCoords, 3*sizeof(float), numVertices, fp); - llendianswizzle(mBaseCoords, sizeof(float), 3*numVertices); - if (numRead != numVertices) - { - llerrs << "can't read Coordinates from " << fileName << llendl; - return FALSE; - } - - //---------------------------------------------------------------- - // Normals - //---------------------------------------------------------------- - numRead = fread(mBaseNormals, 3*sizeof(float), numVertices, fp); - llendianswizzle(mBaseNormals, sizeof(float), 3*numVertices); - if (numRead != numVertices) - { - llerrs << " can't read Normals from " << fileName << llendl; - return FALSE; - } - - //---------------------------------------------------------------- - // Binormals - //---------------------------------------------------------------- - numRead = fread(mBaseBinormals, 3*sizeof(float), numVertices, fp); - llendianswizzle(mBaseBinormals, sizeof(float), 3*numVertices); - if (numRead != numVertices) - { - llerrs << " can't read Binormals from " << fileName << llendl; - return FALSE; - } - - - //---------------------------------------------------------------- - // TexCoords - //---------------------------------------------------------------- - numRead = fread(mTexCoords, 2*sizeof(float), numVertices, fp); - llendianswizzle(mTexCoords, sizeof(float), 2*numVertices); - if (numRead != numVertices) - { - llerrs << "can't read TexCoords from " << fileName << llendl; - return FALSE; - } - - //---------------------------------------------------------------- - // DetailTexCoords - //---------------------------------------------------------------- - if (mHasDetailTexCoords) - { - numRead = fread(mDetailTexCoords, 2*sizeof(float), numVertices, fp); - llendianswizzle(mDetailTexCoords, sizeof(float), 2*numVertices); - if (numRead != numVertices) - { - llerrs << "can't read DetailTexCoords from " << fileName << llendl; - return FALSE; - } - } - - //---------------------------------------------------------------- - // Weights - //---------------------------------------------------------------- - if (mHasWeights) - { - numRead = fread(mWeights, sizeof(float), numVertices, fp); - llendianswizzle(mWeights, sizeof(float), numVertices); - if (numRead != numVertices) - { - llerrs << "can't read Weights from " << fileName << llendl; - return FALSE; - } - } - } - - //---------------------------------------------------------------- - // NumFaces - //---------------------------------------------------------------- - U16 numFaces; - numRead = fread(&numFaces, sizeof(U16), 1, fp); - llendianswizzle(&numFaces, sizeof(U16), 1); - if (numRead != 1) - { - llerrs << "can't read NumFaces from " << fileName << llendl; - return FALSE; - } - allocateFaceData( numFaces ); - - - //---------------------------------------------------------------- - // Faces - //---------------------------------------------------------------- - U32 i; - U32 numTris = 0; - for (i = 0; i < numFaces; i++) - { - S16 face[3]; - numRead = fread(face, sizeof(U16), 3, fp); - llendianswizzle(face, sizeof(U16), 3); - if (numRead != 3) - { - llerrs << "can't read Face[" << i << "] from " << fileName << llendl; - return FALSE; - } - if (mReferenceData) - { - llassert(face[0] < mReferenceData->mNumVertices); - llassert(face[1] < mReferenceData->mNumVertices); - llassert(face[2] < mReferenceData->mNumVertices); - } - - if (isLOD()) - { - // store largest index in case of LODs - for (S32 j = 0; j < 3; j++) - { - if (face[j] > mNumVertices - 1) - { - mNumVertices = face[j] + 1; - } - } - } - mFaces[i][0] = face[0]; - mFaces[i][1] = face[1]; - mFaces[i][2] = face[2]; - -// S32 j; -// for(j = 0; j < 3; j++) -// { -// LLDynamicArray<S32> *face_list = mVertFaceMap.getIfThere(face[j]); -// if (!face_list) -// { -// face_list = new LLDynamicArray<S32>; -// mVertFaceMap.addData(face[j], face_list); -// } -// face_list->put(i); -// } - - numTris++; - } - - lldebugs << "verts: " << numVertices - << ", faces: " << numFaces - << ", tris: " << numTris - << llendl; - - //---------------------------------------------------------------- - // NumSkinJoints - //---------------------------------------------------------------- - if (!isLOD()) - { - U16 numSkinJoints = 0; - if ( mHasWeights ) - { - numRead = fread(&numSkinJoints, sizeof(U16), 1, fp); - llendianswizzle(&numSkinJoints, sizeof(U16), 1); - if (numRead != 1) - { - llerrs << "can't read NumSkinJoints from " << fileName << llendl; - return FALSE; - } - allocateJointNames( numSkinJoints ); - } - - //---------------------------------------------------------------- - // SkinJoints - //---------------------------------------------------------------- - for (i=0; i < numSkinJoints; i++) - { - char jointName[64+1]; - numRead = fread(jointName, sizeof(jointName)-1, 1, fp); - jointName[sizeof(jointName)-1] = '\0'; // ensure nul-termination - if (numRead != 1) - { - llerrs << "can't read Skin[" << i << "].Name from " << fileName << llendl; - return FALSE; - } - - std::string *jn = &mJointNames[i]; - *jn = jointName; - } - - //------------------------------------------------------------------------- - // look for morph section - //------------------------------------------------------------------------- - char morphName[64+1]; - morphName[sizeof(morphName)-1] = '\0'; // ensure nul-termination - while(fread(&morphName, sizeof(char), 64, fp) == 64) - { - if (!strcmp(morphName, "End Morphs")) - { - // we reached the end of the morphs - break; - } - LLPolyMorphData* morph_data = new LLPolyMorphData(std::string(morphName)); - - BOOL result = morph_data->loadBinary(fp, this); - - if (!result) - { - delete morph_data; - continue; - } - - mMorphData.insert(morph_data); - - if (!strcmp(morphName, "Breast_Female_Cleavage")) - { - mMorphData.insert(clone_morph_param_cleavage(morph_data, - 0.5f, - "Breast_Physics_LeftRight_Driven")); - } - - if (!strcmp(morphName, "Big_Belly_Torso")) - { - mMorphData.insert(clone_morph_param(morph_data, - LLVector3(0,0,0.03f), - "Belly_Physics_Torso_UpDown_Driven")); - } - - if (!strcmp(morphName, "Big_Belly_Legs")) - { - mMorphData.insert(clone_morph_param(morph_data, - LLVector3(0,0,0.03f), - "Belly_Physics_Legs_UpDown_Driven")); - } - - if (!strcmp(morphName, "skirt_belly")) - { - mMorphData.insert(clone_morph_param(morph_data, - LLVector3(0,0,0.03f), - "Belly_Physics_Skirt_UpDown_Driven")); - } - - if (!strcmp(morphName, "Small_Butt")) - { - mMorphData.insert(clone_morph_param(morph_data, - LLVector3(0,0,0.015f), - "Butt_Physics_UpDown_Driven")); - } - if (!strcmp(morphName, "Small_Butt")) - { - mMorphData.insert(clone_morph_param(morph_data, - LLVector3(0,0.015f,0), - "Butt_Physics_LeftRight_Driven")); - } - } - - S32 numRemaps; - if (fread(&numRemaps, sizeof(S32), 1, fp) == 1) - { - llendianswizzle(&numRemaps, sizeof(S32), 1); - for (S32 i = 0; i < numRemaps; i++) - { - S32 remapSrc; - S32 remapDst; - if (fread(&remapSrc, sizeof(S32), 1, fp) != 1) - { - llerrs << "can't read source vertex in vertex remap data" << llendl; - break; - } - if (fread(&remapDst, sizeof(S32), 1, fp) != 1) - { - llerrs << "can't read destination vertex in vertex remap data" << llendl; - break; - } - llendianswizzle(&remapSrc, sizeof(S32), 1); - llendianswizzle(&remapDst, sizeof(S32), 1); - - mSharedVerts[remapSrc] = remapDst; - } - } - } - - status = TRUE; - } - else - { - llerrs << "invalid mesh file header: " << fileName << llendl; - status = FALSE; - } - - if (0 == mNumJointNames) - { - allocateJointNames(1); - } - - fclose( fp ); - - return status; + //------------------------------------------------------------------------- + // Open the file + //------------------------------------------------------------------------- + if(fileName.empty()) + { + llerrs << "Filename is Empty!" << llendl; + return FALSE; + } + LLFILE* fp = LLFile::fopen(fileName, "rb"); /*Flawfinder: ignore*/ + if (!fp) + { + llerrs << "can't open: " << fileName << llendl; + return FALSE; + } + + //------------------------------------------------------------------------- + // Read a chunk + //------------------------------------------------------------------------- + char header[128]; /*Flawfinder: ignore*/ + if (fread(header, sizeof(char), 128, fp) != 128) + { + llwarns << "Short read" << llendl; + } + + //------------------------------------------------------------------------- + // Check for proper binary header + //------------------------------------------------------------------------- + BOOL status = FALSE; + if ( strncmp(header, HEADER_BINARY, strlen(HEADER_BINARY)) == 0 ) /*Flawfinder: ignore*/ + { + lldebugs << "Loading " << fileName << llendl; + + //---------------------------------------------------------------- + // File Header (seek past it) + //---------------------------------------------------------------- + fseek(fp, 24, SEEK_SET); + + //---------------------------------------------------------------- + // HasWeights + //---------------------------------------------------------------- + U8 hasWeights; + size_t numRead = fread(&hasWeights, sizeof(U8), 1, fp); + if (numRead != 1) + { + llerrs << "can't read HasWeights flag from " << fileName << llendl; + return FALSE; + } + if (!isLOD()) + { + mHasWeights = (hasWeights==0) ? FALSE : TRUE; + } + + //---------------------------------------------------------------- + // HasDetailTexCoords + //---------------------------------------------------------------- + U8 hasDetailTexCoords; + numRead = fread(&hasDetailTexCoords, sizeof(U8), 1, fp); + if (numRead != 1) + { + llerrs << "can't read HasDetailTexCoords flag from " << fileName << llendl; + return FALSE; + } + + //---------------------------------------------------------------- + // Position + //---------------------------------------------------------------- + LLVector3 position; + numRead = fread(position.mV, sizeof(float), 3, fp); + llendianswizzle(position.mV, sizeof(float), 3); + if (numRead != 3) + { + llerrs << "can't read Position from " << fileName << llendl; + return FALSE; + } + setPosition( position ); + + //---------------------------------------------------------------- + // Rotation + //---------------------------------------------------------------- + LLVector3 rotationAngles; + numRead = fread(rotationAngles.mV, sizeof(float), 3, fp); + llendianswizzle(rotationAngles.mV, sizeof(float), 3); + if (numRead != 3) + { + llerrs << "can't read RotationAngles from " << fileName << llendl; + return FALSE; + } + + U8 rotationOrder; + numRead = fread(&rotationOrder, sizeof(U8), 1, fp); + + if (numRead != 1) + { + llerrs << "can't read RotationOrder from " << fileName << llendl; + return FALSE; + } + + rotationOrder = 0; + + setRotation( mayaQ( rotationAngles.mV[0], + rotationAngles.mV[1], + rotationAngles.mV[2], + (LLQuaternion::Order)rotationOrder ) ); + + //---------------------------------------------------------------- + // Scale + //---------------------------------------------------------------- + LLVector3 scale; + numRead = fread(scale.mV, sizeof(float), 3, fp); + llendianswizzle(scale.mV, sizeof(float), 3); + if (numRead != 3) + { + llerrs << "can't read Scale from " << fileName << llendl; + return FALSE; + } + setScale( scale ); + + //------------------------------------------------------------------------- + // Release any existing mesh geometry + //------------------------------------------------------------------------- + freeMeshData(); + + U16 numVertices = 0; + + //---------------------------------------------------------------- + // NumVertices + //---------------------------------------------------------------- + if (!isLOD()) + { + numRead = fread(&numVertices, sizeof(U16), 1, fp); + llendianswizzle(&numVertices, sizeof(U16), 1); + if (numRead != 1) + { + llerrs << "can't read NumVertices from " << fileName << llendl; + return FALSE; + } + + allocateVertexData( numVertices ); + + //---------------------------------------------------------------- + // Coords + //---------------------------------------------------------------- + numRead = fread(mBaseCoords, 3*sizeof(float), numVertices, fp); + llendianswizzle(mBaseCoords, sizeof(float), 3*numVertices); + if (numRead != numVertices) + { + llerrs << "can't read Coordinates from " << fileName << llendl; + return FALSE; + } + + //---------------------------------------------------------------- + // Normals + //---------------------------------------------------------------- + numRead = fread(mBaseNormals, 3*sizeof(float), numVertices, fp); + llendianswizzle(mBaseNormals, sizeof(float), 3*numVertices); + if (numRead != numVertices) + { + llerrs << " can't read Normals from " << fileName << llendl; + return FALSE; + } + + //---------------------------------------------------------------- + // Binormals + //---------------------------------------------------------------- + numRead = fread(mBaseBinormals, 3*sizeof(float), numVertices, fp); + llendianswizzle(mBaseBinormals, sizeof(float), 3*numVertices); + if (numRead != numVertices) + { + llerrs << " can't read Binormals from " << fileName << llendl; + return FALSE; + } + + + //---------------------------------------------------------------- + // TexCoords + //---------------------------------------------------------------- + numRead = fread(mTexCoords, 2*sizeof(float), numVertices, fp); + llendianswizzle(mTexCoords, sizeof(float), 2*numVertices); + if (numRead != numVertices) + { + llerrs << "can't read TexCoords from " << fileName << llendl; + return FALSE; + } + + //---------------------------------------------------------------- + // DetailTexCoords + //---------------------------------------------------------------- + if (mHasDetailTexCoords) + { + numRead = fread(mDetailTexCoords, 2*sizeof(float), numVertices, fp); + llendianswizzle(mDetailTexCoords, sizeof(float), 2*numVertices); + if (numRead != numVertices) + { + llerrs << "can't read DetailTexCoords from " << fileName << llendl; + return FALSE; + } + } + + //---------------------------------------------------------------- + // Weights + //---------------------------------------------------------------- + if (mHasWeights) + { + numRead = fread(mWeights, sizeof(float), numVertices, fp); + llendianswizzle(mWeights, sizeof(float), numVertices); + if (numRead != numVertices) + { + llerrs << "can't read Weights from " << fileName << llendl; + return FALSE; + } + } + } + + //---------------------------------------------------------------- + // NumFaces + //---------------------------------------------------------------- + U16 numFaces; + numRead = fread(&numFaces, sizeof(U16), 1, fp); + llendianswizzle(&numFaces, sizeof(U16), 1); + if (numRead != 1) + { + llerrs << "can't read NumFaces from " << fileName << llendl; + return FALSE; + } + allocateFaceData( numFaces ); + + + //---------------------------------------------------------------- + // Faces + //---------------------------------------------------------------- + U32 i; + U32 numTris = 0; + for (i = 0; i < numFaces; i++) + { + S16 face[3]; + numRead = fread(face, sizeof(U16), 3, fp); + llendianswizzle(face, sizeof(U16), 3); + if (numRead != 3) + { + llerrs << "can't read Face[" << i << "] from " << fileName << llendl; + return FALSE; + } + if (mReferenceData) + { + llassert(face[0] < mReferenceData->mNumVertices); + llassert(face[1] < mReferenceData->mNumVertices); + llassert(face[2] < mReferenceData->mNumVertices); + } + + if (isLOD()) + { + // store largest index in case of LODs + for (S32 j = 0; j < 3; j++) + { + if (face[j] > mNumVertices - 1) + { + mNumVertices = face[j] + 1; + } + } + } + mFaces[i][0] = face[0]; + mFaces[i][1] = face[1]; + mFaces[i][2] = face[2]; + +// S32 j; +// for(j = 0; j < 3; j++) +// { +// LLDynamicArray<S32> *face_list = mVertFaceMap.getIfThere(face[j]); +// if (!face_list) +// { +// face_list = new LLDynamicArray<S32>; +// mVertFaceMap.addData(face[j], face_list); +// } +// face_list->put(i); +// } + + numTris++; + } + + lldebugs << "verts: " << numVertices + << ", faces: " << numFaces + << ", tris: " << numTris + << llendl; + + //---------------------------------------------------------------- + // NumSkinJoints + //---------------------------------------------------------------- + if (!isLOD()) + { + U16 numSkinJoints = 0; + if ( mHasWeights ) + { + numRead = fread(&numSkinJoints, sizeof(U16), 1, fp); + llendianswizzle(&numSkinJoints, sizeof(U16), 1); + if (numRead != 1) + { + llerrs << "can't read NumSkinJoints from " << fileName << llendl; + return FALSE; + } + allocateJointNames( numSkinJoints ); + } + + //---------------------------------------------------------------- + // SkinJoints + //---------------------------------------------------------------- + for (i=0; i < numSkinJoints; i++) + { + char jointName[64+1]; + numRead = fread(jointName, sizeof(jointName)-1, 1, fp); + jointName[sizeof(jointName)-1] = '\0'; // ensure nul-termination + if (numRead != 1) + { + llerrs << "can't read Skin[" << i << "].Name from " << fileName << llendl; + return FALSE; + } + + std::string *jn = &mJointNames[i]; + *jn = jointName; + } + + //------------------------------------------------------------------------- + // look for morph section + //------------------------------------------------------------------------- + char morphName[64+1]; + morphName[sizeof(morphName)-1] = '\0'; // ensure nul-termination + while(fread(&morphName, sizeof(char), 64, fp) == 64) + { + if (!strcmp(morphName, "End Morphs")) + { + // we reached the end of the morphs + break; + } + LLPolyMorphData* morph_data = new LLPolyMorphData(std::string(morphName)); + + BOOL result = morph_data->loadBinary(fp, this); + + if (!result) + { + delete morph_data; + continue; + } + + mMorphData.insert(morph_data); + + if (!strcmp(morphName, "Breast_Female_Cleavage")) + { + mMorphData.insert(clone_morph_param_cleavage(morph_data, + .75f, + "Breast_Physics_LeftRight_Driven")); + } + + if (!strcmp(morphName, "Big_Belly_Torso")) + { + mMorphData.insert(clone_morph_param(morph_data, + LLVector3(0,0,0.05f), + "Belly_Physics_Torso_UpDown_Driven")); + } + + if (!strcmp(morphName, "Big_Belly_Legs")) + { + mMorphData.insert(clone_morph_param(morph_data, + LLVector3(0,0,0.05f), + "Belly_Physics_Legs_UpDown_Driven")); + } + + if (!strcmp(morphName, "skirt_belly")) + { + mMorphData.insert(clone_morph_param(morph_data, + LLVector3(0,0,0.05f), + "Belly_Physics_Skirt_UpDown_Driven")); + } + + if (!strcmp(morphName, "Small_Butt")) + { + mMorphData.insert(clone_morph_param(morph_data, + LLVector3(0,0,0.05f), + "Butt_Physics_UpDown_Driven")); + } + if (!strcmp(morphName, "Small_Butt")) + { + mMorphData.insert(clone_morph_param(morph_data, + LLVector3(0,0.02f,0), + "Butt_Physics_LeftRight_Driven")); + } + } + + S32 numRemaps; + if (fread(&numRemaps, sizeof(S32), 1, fp) == 1) + { + llendianswizzle(&numRemaps, sizeof(S32), 1); + for (S32 i = 0; i < numRemaps; i++) + { + S32 remapSrc; + S32 remapDst; + if (fread(&remapSrc, sizeof(S32), 1, fp) != 1) + { + llerrs << "can't read source vertex in vertex remap data" << llendl; + break; + } + if (fread(&remapDst, sizeof(S32), 1, fp) != 1) + { + llerrs << "can't read destination vertex in vertex remap data" << llendl; + break; + } + llendianswizzle(&remapSrc, sizeof(S32), 1); + llendianswizzle(&remapDst, sizeof(S32), 1); + + mSharedVerts[remapSrc] = remapDst; + } + } + } + + status = TRUE; + } + else + { + llerrs << "invalid mesh file header: " << fileName << llendl; + status = FALSE; + } + + if (0 == mNumJointNames) + { + allocateJointNames(1); + } + + fclose( fp ); + + return status; } //----------------------------------------------------------------------------- @@ -701,11 +701,11 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) //----------------------------------------------------------------------------- const S32 *LLPolyMeshSharedData::getSharedVert(S32 vert) { - if (mSharedVerts.count(vert) > 0) - { - return &mSharedVerts[vert]; - } - return NULL; + if (mSharedVerts.count(vert) > 0) + { + return &mSharedVerts[vert]; + } + return NULL; } //----------------------------------------------------------------------------- @@ -713,69 +713,69 @@ const S32 *LLPolyMeshSharedData::getSharedVert(S32 vert) //----------------------------------------------------------------------------- const LLVector2 &LLPolyMeshSharedData::getUVs(U32 index) { - // TODO: convert all index variables to S32 - llassert((S32)index < mNumVertices); + // TODO: convert all index variables to S32 + llassert((S32)index < mNumVertices); - return mTexCoords[index]; + return mTexCoords[index]; } //----------------------------------------------------------------------------- // LLPolyMesh() //----------------------------------------------------------------------------- LLPolyMesh::LLPolyMesh(LLPolyMeshSharedData *shared_data, LLPolyMesh *reference_mesh) -{ - LLMemType mt(LLMemType::MTYPE_AVATAR_MESH); - - llassert(shared_data); - - mSharedData = shared_data; - mReferenceMesh = reference_mesh; - mAvatarp = NULL; - mVertexData = NULL; - - mCurVertexCount = 0; - mFaceIndexCount = 0; - mFaceIndexOffset = 0; - mFaceVertexCount = 0; - mFaceVertexOffset = 0; - - if (shared_data->isLOD() && reference_mesh) - { - mCoords = reference_mesh->mCoords; - mNormals = reference_mesh->mNormals; - mScaledNormals = reference_mesh->mScaledNormals; - mBinormals = reference_mesh->mBinormals; - mScaledBinormals = reference_mesh->mScaledBinormals; - mTexCoords = reference_mesh->mTexCoords; - mClothingWeights = reference_mesh->mClothingWeights; - } - else - { -#if 1 // Allocate memory without initializing every vector - // NOTE: This makes asusmptions about the size of LLVector[234] - int nverts = mSharedData->mNumVertices; - int nfloats = nverts * (3*5 + 2 + 4); - mVertexData = new F32[nfloats]; - int offset = 0; - mCoords = (LLVector3*)(mVertexData + offset); offset += 3*nverts; - mNormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts; - mScaledNormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts; - mBinormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts; - mScaledBinormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts; - mTexCoords = (LLVector2*)(mVertexData + offset); offset += 2*nverts; - mClothingWeights = (LLVector4*)(mVertexData + offset); offset += 4*nverts; +{ + LLMemType mt(LLMemType::MTYPE_AVATAR_MESH); + + llassert(shared_data); + + mSharedData = shared_data; + mReferenceMesh = reference_mesh; + mAvatarp = NULL; + mVertexData = NULL; + + mCurVertexCount = 0; + mFaceIndexCount = 0; + mFaceIndexOffset = 0; + mFaceVertexCount = 0; + mFaceVertexOffset = 0; + + if (shared_data->isLOD() && reference_mesh) + { + mCoords = reference_mesh->mCoords; + mNormals = reference_mesh->mNormals; + mScaledNormals = reference_mesh->mScaledNormals; + mBinormals = reference_mesh->mBinormals; + mScaledBinormals = reference_mesh->mScaledBinormals; + mTexCoords = reference_mesh->mTexCoords; + mClothingWeights = reference_mesh->mClothingWeights; + } + else + { +#if 1 // Allocate memory without initializing every vector + // NOTE: This makes asusmptions about the size of LLVector[234] + int nverts = mSharedData->mNumVertices; + int nfloats = nverts * (3*5 + 2 + 4); + mVertexData = new F32[nfloats]; + int offset = 0; + mCoords = (LLVector3*)(mVertexData + offset); offset += 3*nverts; + mNormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts; + mScaledNormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts; + mBinormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts; + mScaledBinormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts; + mTexCoords = (LLVector2*)(mVertexData + offset); offset += 2*nverts; + mClothingWeights = (LLVector4*)(mVertexData + offset); offset += 4*nverts; #else - mCoords = new LLVector3[mSharedData->mNumVertices]; - mNormals = new LLVector3[mSharedData->mNumVertices]; - mScaledNormals = new LLVector3[mSharedData->mNumVertices]; - mBinormals = new LLVector3[mSharedData->mNumVertices]; - mScaledBinormals = new LLVector3[mSharedData->mNumVertices]; - mTexCoords = new LLVector2[mSharedData->mNumVertices]; - mClothingWeights = new LLVector4[mSharedData->mNumVertices]; - memset(mClothingWeights, 0, sizeof(LLVector4) * mSharedData->mNumVertices); + mCoords = new LLVector3[mSharedData->mNumVertices]; + mNormals = new LLVector3[mSharedData->mNumVertices]; + mScaledNormals = new LLVector3[mSharedData->mNumVertices]; + mBinormals = new LLVector3[mSharedData->mNumVertices]; + mScaledBinormals = new LLVector3[mSharedData->mNumVertices]; + mTexCoords = new LLVector2[mSharedData->mNumVertices]; + mClothingWeights = new LLVector4[mSharedData->mNumVertices]; + memset(mClothingWeights, 0, sizeof(LLVector4) * mSharedData->mNumVertices); #endif - initializeForMorph(); - } + initializeForMorph(); + } } @@ -784,22 +784,22 @@ LLPolyMesh::LLPolyMesh(LLPolyMeshSharedData *shared_data, LLPolyMesh *reference_ //----------------------------------------------------------------------------- LLPolyMesh::~LLPolyMesh() { - S32 i; - for (i = 0; i < mJointRenderData.count(); i++) - { - delete mJointRenderData[i]; - mJointRenderData[i] = NULL; - } + S32 i; + for (i = 0; i < mJointRenderData.count(); i++) + { + delete mJointRenderData[i]; + mJointRenderData[i] = NULL; + } #if 0 // These are now allocated as one big uninitialized chunk - delete [] mCoords; - delete [] mNormals; - delete [] mScaledNormals; - delete [] mBinormals; - delete [] mScaledBinormals; - delete [] mClothingWeights; - delete [] mTexCoords; + delete [] mCoords; + delete [] mNormals; + delete [] mScaledNormals; + delete [] mBinormals; + delete [] mScaledBinormals; + delete [] mClothingWeights; + delete [] mTexCoords; #else - delete [] mVertexData; + delete [] mVertexData; #endif } @@ -809,40 +809,40 @@ LLPolyMesh::~LLPolyMesh() //----------------------------------------------------------------------------- LLPolyMesh *LLPolyMesh::getMesh(const std::string &name, LLPolyMesh* reference_mesh) { - //------------------------------------------------------------------------- - // search for an existing mesh by this name - //------------------------------------------------------------------------- - LLPolyMeshSharedData* meshSharedData = get_if_there(sGlobalSharedMeshList, name, (LLPolyMeshSharedData*)NULL); - if (meshSharedData) - { -// llinfos << "Polymesh " << name << " found in global mesh table." << llendl; - LLPolyMesh *poly_mesh = new LLPolyMesh(meshSharedData, reference_mesh); - return poly_mesh; - } - - //------------------------------------------------------------------------- - // if not found, create a new one, add it to the list - //------------------------------------------------------------------------- - std::string full_path; - full_path = gDirUtilp->getExpandedFilename(LL_PATH_CHARACTER,name); - - LLPolyMeshSharedData *mesh_data = new LLPolyMeshSharedData(); - if (reference_mesh) - { - mesh_data->setupLOD(reference_mesh->getSharedData()); - } - if ( ! mesh_data->loadMesh( full_path ) ) - { - delete mesh_data; - return NULL; - } - - LLPolyMesh *poly_mesh = new LLPolyMesh(mesh_data, reference_mesh); - -// llinfos << "Polymesh " << name << " added to global mesh table." << llendl; - sGlobalSharedMeshList[name] = poly_mesh->mSharedData; - - return poly_mesh; + //------------------------------------------------------------------------- + // search for an existing mesh by this name + //------------------------------------------------------------------------- + LLPolyMeshSharedData* meshSharedData = get_if_there(sGlobalSharedMeshList, name, (LLPolyMeshSharedData*)NULL); + if (meshSharedData) + { +// llinfos << "Polymesh " << name << " found in global mesh table." << llendl; + LLPolyMesh *poly_mesh = new LLPolyMesh(meshSharedData, reference_mesh); + return poly_mesh; + } + + //------------------------------------------------------------------------- + // if not found, create a new one, add it to the list + //------------------------------------------------------------------------- + std::string full_path; + full_path = gDirUtilp->getExpandedFilename(LL_PATH_CHARACTER,name); + + LLPolyMeshSharedData *mesh_data = new LLPolyMeshSharedData(); + if (reference_mesh) + { + mesh_data->setupLOD(reference_mesh->getSharedData()); + } + if ( ! mesh_data->loadMesh( full_path ) ) + { + delete mesh_data; + return NULL; + } + + LLPolyMesh *poly_mesh = new LLPolyMesh(mesh_data, reference_mesh); + +// llinfos << "Polymesh " << name << " added to global mesh table." << llendl; + sGlobalSharedMeshList[name] = poly_mesh->mSharedData; + + return poly_mesh; } //----------------------------------------------------------------------------- @@ -850,14 +850,14 @@ LLPolyMesh *LLPolyMesh::getMesh(const std::string &name, LLPolyMesh* reference_m //----------------------------------------------------------------------------- void LLPolyMesh::freeAllMeshes() { - // delete each item in the global lists - for_each(sGlobalSharedMeshList.begin(), sGlobalSharedMeshList.end(), DeletePairedPointer()); - sGlobalSharedMeshList.clear(); + // delete each item in the global lists + for_each(sGlobalSharedMeshList.begin(), sGlobalSharedMeshList.end(), DeletePairedPointer()); + sGlobalSharedMeshList.clear(); } LLPolyMeshSharedData *LLPolyMesh::getSharedData() const { - return mSharedData; + return mSharedData; } @@ -866,41 +866,41 @@ LLPolyMeshSharedData *LLPolyMesh::getSharedData() const //-------------------------------------------------------------------- void LLPolyMesh::dumpDiagInfo() { - // keep track of totals - U32 total_verts = 0; - U32 total_faces = 0; - U32 total_kb = 0; - - std::string buf; - - llinfos << "-----------------------------------------------------" << llendl; - llinfos << " Global PolyMesh Table (DEBUG only)" << llendl; - llinfos << " Verts Faces Mem(KB) Name" << llendl; - llinfos << "-----------------------------------------------------" << llendl; - - // print each loaded mesh, and it's memory usage - for(LLPolyMeshSharedDataTable::iterator iter = sGlobalSharedMeshList.begin(); - iter != sGlobalSharedMeshList.end(); ++iter) - { - const std::string& mesh_name = iter->first; - LLPolyMeshSharedData* mesh = iter->second; - - S32 num_verts = mesh->mNumVertices; - S32 num_faces = mesh->mNumFaces; - U32 num_kb = mesh->getNumKB(); - - buf = llformat("%8d %8d %8d %s", num_verts, num_faces, num_kb, mesh_name.c_str()); - llinfos << buf << llendl; - - total_verts += num_verts; - total_faces += num_faces; - total_kb += num_kb; - } - - llinfos << "-----------------------------------------------------" << llendl; - buf = llformat("%8d %8d %8d TOTAL", total_verts, total_faces, total_kb ); - llinfos << buf << llendl; - llinfos << "-----------------------------------------------------" << llendl; + // keep track of totals + U32 total_verts = 0; + U32 total_faces = 0; + U32 total_kb = 0; + + std::string buf; + + llinfos << "-----------------------------------------------------" << llendl; + llinfos << " Global PolyMesh Table (DEBUG only)" << llendl; + llinfos << " Verts Faces Mem(KB) Name" << llendl; + llinfos << "-----------------------------------------------------" << llendl; + + // print each loaded mesh, and it's memory usage + for(LLPolyMeshSharedDataTable::iterator iter = sGlobalSharedMeshList.begin(); + iter != sGlobalSharedMeshList.end(); ++iter) + { + const std::string& mesh_name = iter->first; + LLPolyMeshSharedData* mesh = iter->second; + + S32 num_verts = mesh->mNumVertices; + S32 num_faces = mesh->mNumFaces; + U32 num_kb = mesh->getNumKB(); + + buf = llformat("%8d %8d %8d %s", num_verts, num_faces, num_kb, mesh_name.c_str()); + llinfos << buf << llendl; + + total_verts += num_verts; + total_faces += num_faces; + total_kb += num_kb; + } + + llinfos << "-----------------------------------------------------" << llendl; + buf = llformat("%8d %8d %8d TOTAL", total_verts, total_faces, total_kb ); + llinfos << buf << llendl; + llinfos << "-----------------------------------------------------" << llendl; } //----------------------------------------------------------------------------- @@ -908,7 +908,7 @@ void LLPolyMesh::dumpDiagInfo() //----------------------------------------------------------------------------- LLVector3 *LLPolyMesh::getWritableCoords() { - return mCoords; + return mCoords; } //----------------------------------------------------------------------------- @@ -916,7 +916,7 @@ LLVector3 *LLPolyMesh::getWritableCoords() //----------------------------------------------------------------------------- LLVector3 *LLPolyMesh::getWritableNormals() { - return mNormals; + return mNormals; } //----------------------------------------------------------------------------- @@ -924,24 +924,24 @@ LLVector3 *LLPolyMesh::getWritableNormals() //----------------------------------------------------------------------------- LLVector3 *LLPolyMesh::getWritableBinormals() { - return mBinormals; + return mBinormals; } //----------------------------------------------------------------------------- // getWritableClothingWeights() //----------------------------------------------------------------------------- -LLVector4 *LLPolyMesh::getWritableClothingWeights() +LLVector4 *LLPolyMesh::getWritableClothingWeights() { - return mClothingWeights; + return mClothingWeights; } //----------------------------------------------------------------------------- // getWritableTexCoords() //----------------------------------------------------------------------------- -LLVector2 *LLPolyMesh::getWritableTexCoords() +LLVector2 *LLPolyMesh::getWritableTexCoords() { - return mTexCoords; + return mTexCoords; } //----------------------------------------------------------------------------- @@ -949,7 +949,7 @@ LLVector2 *LLPolyMesh::getWritableTexCoords() //----------------------------------------------------------------------------- LLVector3 *LLPolyMesh::getScaledNormals() { - return mScaledNormals; + return mScaledNormals; } //----------------------------------------------------------------------------- @@ -957,7 +957,7 @@ LLVector3 *LLPolyMesh::getScaledNormals() //----------------------------------------------------------------------------- LLVector3 *LLPolyMesh::getScaledBinormals() { - return mScaledBinormals; + return mScaledBinormals; } @@ -966,66 +966,66 @@ LLVector3 *LLPolyMesh::getScaledBinormals() //----------------------------------------------------------------------------- void LLPolyMesh::initializeForMorph() { - if (!mSharedData) - return; - - memcpy(mCoords, mSharedData->mBaseCoords, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/ - memcpy(mNormals, mSharedData->mBaseNormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/ - memcpy(mScaledNormals, mSharedData->mBaseNormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/ - memcpy(mBinormals, mSharedData->mBaseBinormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/ - memcpy(mScaledBinormals, mSharedData->mBaseBinormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/ - memcpy(mTexCoords, mSharedData->mTexCoords, sizeof(LLVector2) * mSharedData->mNumVertices); /*Flawfinder: ignore*/ - memset(mClothingWeights, 0, sizeof(LLVector4) * mSharedData->mNumVertices); + if (!mSharedData) + return; + + memcpy(mCoords, mSharedData->mBaseCoords, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/ + memcpy(mNormals, mSharedData->mBaseNormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/ + memcpy(mScaledNormals, mSharedData->mBaseNormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/ + memcpy(mBinormals, mSharedData->mBaseBinormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/ + memcpy(mScaledBinormals, mSharedData->mBaseBinormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/ + memcpy(mTexCoords, mSharedData->mTexCoords, sizeof(LLVector2) * mSharedData->mNumVertices); /*Flawfinder: ignore*/ + memset(mClothingWeights, 0, sizeof(LLVector4) * mSharedData->mNumVertices); } //----------------------------------------------------------------------------- // getMorphData() //----------------------------------------------------------------------------- -LLPolyMorphData* LLPolyMesh::getMorphData(const std::string& morph_name) +LLPolyMorphData* LLPolyMesh::getMorphData(const std::string& morph_name) { - if (!mSharedData) - return NULL; - for (LLPolyMeshSharedData::morphdata_list_t::iterator iter = mSharedData->mMorphData.begin(); - iter != mSharedData->mMorphData.end(); ++iter) - { - LLPolyMorphData *morph_data = *iter; - if (morph_data->getName() == morph_name) - { - return morph_data; - } - } - return NULL; + if (!mSharedData) + return NULL; + for (LLPolyMeshSharedData::morphdata_list_t::iterator iter = mSharedData->mMorphData.begin(); + iter != mSharedData->mMorphData.end(); ++iter) + { + LLPolyMorphData *morph_data = *iter; + if (morph_data->getName() == morph_name) + { + return morph_data; + } + } + return NULL; } //----------------------------------------------------------------------------- // removeMorphData() //----------------------------------------------------------------------------- // // erasing but not deleting seems bad, but fortunately we don't actually use this... -// void LLPolyMesh::removeMorphData(LLPolyMorphData *morph_target) +// void LLPolyMesh::removeMorphData(LLPolyMorphData *morph_target) // { -// if (!mSharedData) -// return; -// mSharedData->mMorphData.erase(morph_target); +// if (!mSharedData) +// return; +// mSharedData->mMorphData.erase(morph_target); // } //----------------------------------------------------------------------------- // deleteAllMorphData() //----------------------------------------------------------------------------- -// void LLPolyMesh::deleteAllMorphData() +// void LLPolyMesh::deleteAllMorphData() // { -// if (!mSharedData) -// return; +// if (!mSharedData) +// return; -// for_each(mSharedData->mMorphData.begin(), mSharedData->mMorphData.end(), DeletePointer()); -// mSharedData->mMorphData.clear(); +// for_each(mSharedData->mMorphData.begin(), mSharedData->mMorphData.end(), DeletePointer()); +// mSharedData->mMorphData.clear(); // } //----------------------------------------------------------------------------- // getWritableWeights() //----------------------------------------------------------------------------- -F32* LLPolyMesh::getWritableWeights() const +F32* LLPolyMesh::getWritableWeights() const { - return mSharedData->mWeights; + return mSharedData->mWeights; } //----------------------------------------------------------------------------- @@ -1037,58 +1037,58 @@ LLPolySkeletalDistortionInfo::LLPolySkeletalDistortionInfo() BOOL LLPolySkeletalDistortionInfo::parseXml(LLXmlTreeNode* node) { - llassert( node->hasName( "param" ) && node->getChildByName( "param_skeleton" ) ); - - if (!LLViewerVisualParamInfo::parseXml(node)) - return FALSE; - - LLXmlTreeNode* skeletalParam = node->getChildByName("param_skeleton"); - - if (NULL == skeletalParam) - { - llwarns << "Failed to getChildByName(\"param_skeleton\")" - << llendl; - return FALSE; - } - - for( LLXmlTreeNode* bone = skeletalParam->getFirstChild(); bone; bone = skeletalParam->getNextChild() ) - { - if (bone->hasName("bone")) - { - std::string name; - LLVector3 scale; - LLVector3 pos; - BOOL haspos = FALSE; - - static LLStdStringHandle name_string = LLXmlTree::addAttributeString("name"); - if (!bone->getFastAttributeString(name_string, name)) - { - llwarns << "No bone name specified for skeletal param." << llendl; - continue; - } - - static LLStdStringHandle scale_string = LLXmlTree::addAttributeString("scale"); - if (!bone->getFastAttributeVector3(scale_string, scale)) - { - llwarns << "No scale specified for bone " << name << "." << llendl; - continue; - } - - // optional offset deformation (translation) - static LLStdStringHandle offset_string = LLXmlTree::addAttributeString("offset"); - if (bone->getFastAttributeVector3(offset_string, pos)) - { - haspos = TRUE; - } - mBoneInfoList.push_back(LLPolySkeletalBoneInfo(name, scale, pos, haspos)); - } - else - { - llwarns << "Unrecognized element " << bone->getName() << " in skeletal distortion" << llendl; - continue; - } - } - return TRUE; + llassert( node->hasName( "param" ) && node->getChildByName( "param_skeleton" ) ); + + if (!LLViewerVisualParamInfo::parseXml(node)) + return FALSE; + + LLXmlTreeNode* skeletalParam = node->getChildByName("param_skeleton"); + + if (NULL == skeletalParam) + { + llwarns << "Failed to getChildByName(\"param_skeleton\")" + << llendl; + return FALSE; + } + + for( LLXmlTreeNode* bone = skeletalParam->getFirstChild(); bone; bone = skeletalParam->getNextChild() ) + { + if (bone->hasName("bone")) + { + std::string name; + LLVector3 scale; + LLVector3 pos; + BOOL haspos = FALSE; + + static LLStdStringHandle name_string = LLXmlTree::addAttributeString("name"); + if (!bone->getFastAttributeString(name_string, name)) + { + llwarns << "No bone name specified for skeletal param." << llendl; + continue; + } + + static LLStdStringHandle scale_string = LLXmlTree::addAttributeString("scale"); + if (!bone->getFastAttributeVector3(scale_string, scale)) + { + llwarns << "No scale specified for bone " << name << "." << llendl; + continue; + } + + // optional offset deformation (translation) + static LLStdStringHandle offset_string = LLXmlTree::addAttributeString("offset"); + if (bone->getFastAttributeVector3(offset_string, pos)) + { + haspos = TRUE; + } + mBoneInfoList.push_back(LLPolySkeletalBoneInfo(name, scale, pos, haspos)); + } + else + { + llwarns << "Unrecognized element " << bone->getName() << " in skeletal distortion" << llendl; + continue; + } + } + return TRUE; } //----------------------------------------------------------------------------- @@ -1096,8 +1096,8 @@ BOOL LLPolySkeletalDistortionInfo::parseXml(LLXmlTreeNode* node) //----------------------------------------------------------------------------- LLPolySkeletalDistortion::LLPolySkeletalDistortion(LLVOAvatar *avatarp) { - mAvatar = avatarp; - mDefaultVec.setVec(0.001f, 0.001f, 0.001f); + mAvatar = avatarp; + mDefaultVec.setVec(0.001f, 0.001f, 0.001f); } //----------------------------------------------------------------------------- @@ -1109,62 +1109,62 @@ LLPolySkeletalDistortion::~LLPolySkeletalDistortion() BOOL LLPolySkeletalDistortion::setInfo(LLPolySkeletalDistortionInfo *info) { - llassert(mInfo == NULL); - if (info->mID < 0) - return FALSE; - mInfo = info; - mID = info->mID; - setWeight(getDefaultWeight(), FALSE ); - - LLPolySkeletalDistortionInfo::bone_info_list_t::iterator iter; - for (iter = getInfo()->mBoneInfoList.begin(); iter != getInfo()->mBoneInfoList.end(); iter++) - { - LLPolySkeletalBoneInfo *bone_info = &(*iter); - LLJoint* joint = mAvatar->getJoint(bone_info->mBoneName); - if (!joint) - { - llwarns << "Joint " << bone_info->mBoneName << " not found." << llendl; - continue; - } - - if (mJointScales.find(joint) != mJointScales.end()) - { - llwarns << "Scale deformation already supplied for joint " << joint->getName() << "." << llendl; - } - - // store it - mJointScales[joint] = bone_info->mScaleDeformation; - - // apply to children that need to inherit it - for (LLJoint::child_list_t::iterator iter = joint->mChildren.begin(); - iter != joint->mChildren.end(); ++iter) - { - LLViewerJoint* child_joint = (LLViewerJoint*)(*iter); - if (child_joint->inheritScale()) - { - LLVector3 childDeformation = LLVector3(child_joint->getScale()); - childDeformation.scaleVec(bone_info->mScaleDeformation); - mJointScales[child_joint] = childDeformation; - } - } - - if (bone_info->mHasPositionDeformation) - { - if (mJointOffsets.find(joint) != mJointOffsets.end()) - { - llwarns << "Offset deformation already supplied for joint " << joint->getName() << "." << llendl; - } - mJointOffsets[joint] = bone_info->mPositionDeformation; - } - } - return TRUE; + llassert(mInfo == NULL); + if (info->mID < 0) + return FALSE; + mInfo = info; + mID = info->mID; + setWeight(getDefaultWeight(), FALSE ); + + LLPolySkeletalDistortionInfo::bone_info_list_t::iterator iter; + for (iter = getInfo()->mBoneInfoList.begin(); iter != getInfo()->mBoneInfoList.end(); iter++) + { + LLPolySkeletalBoneInfo *bone_info = &(*iter); + LLJoint* joint = mAvatar->getJoint(bone_info->mBoneName); + if (!joint) + { + llwarns << "Joint " << bone_info->mBoneName << " not found." << llendl; + continue; + } + + if (mJointScales.find(joint) != mJointScales.end()) + { + llwarns << "Scale deformation already supplied for joint " << joint->getName() << "." << llendl; + } + + // store it + mJointScales[joint] = bone_info->mScaleDeformation; + + // apply to children that need to inherit it + for (LLJoint::child_list_t::iterator iter = joint->mChildren.begin(); + iter != joint->mChildren.end(); ++iter) + { + LLViewerJoint* child_joint = (LLViewerJoint*)(*iter); + if (child_joint->inheritScale()) + { + LLVector3 childDeformation = LLVector3(child_joint->getScale()); + childDeformation.scaleVec(bone_info->mScaleDeformation); + mJointScales[child_joint] = childDeformation; + } + } + + if (bone_info->mHasPositionDeformation) + { + if (mJointOffsets.find(joint) != mJointOffsets.end()) + { + llwarns << "Offset deformation already supplied for joint " << joint->getName() << "." << llendl; + } + mJointOffsets[joint] = bone_info->mPositionDeformation; + } + } + return TRUE; } /*virtual*/ LLViewerVisualParam* LLPolySkeletalDistortion::cloneParam(LLWearable* wearable) const { - LLPolySkeletalDistortion *new_param = new LLPolySkeletalDistortion(mAvatar); - *new_param = *this; - return new_param; + LLPolySkeletalDistortion *new_param = new LLPolySkeletalDistortion(mAvatar); + *new_param = *this; + return new_param; } //----------------------------------------------------------------------------- @@ -1172,75 +1172,75 @@ BOOL LLPolySkeletalDistortion::setInfo(LLPolySkeletalDistortionInfo *info) //----------------------------------------------------------------------------- void LLPolySkeletalDistortion::apply( ESex avatar_sex ) { - F32 effective_weight = ( getSex() & avatar_sex ) ? mCurWeight : getDefaultWeight(); - - LLJoint* joint; - joint_vec_map_t::iterator iter; - - for (iter = mJointScales.begin(); - iter != mJointScales.end(); - iter++) - { - joint = iter->first; - LLVector3 newScale = joint->getScale(); - LLVector3 scaleDelta = iter->second; - newScale = newScale + (effective_weight * scaleDelta) - (mLastWeight * scaleDelta); - joint->setScale(newScale); - } - - for (iter = mJointOffsets.begin(); - iter != mJointOffsets.end(); - iter++) - { - joint = iter->first; - LLVector3 newPosition = joint->getPosition(); - LLVector3 positionDelta = iter->second; - newPosition = newPosition + (effective_weight * positionDelta) - (mLastWeight * positionDelta); - joint->setPosition(newPosition); - } - - if (mLastWeight != mCurWeight && !mIsAnimating) - { - mAvatar->setSkeletonSerialNum(mAvatar->getSkeletonSerialNum() + 1); - } - mLastWeight = mCurWeight; + F32 effective_weight = ( getSex() & avatar_sex ) ? mCurWeight : getDefaultWeight(); + + LLJoint* joint; + joint_vec_map_t::iterator iter; + + for (iter = mJointScales.begin(); + iter != mJointScales.end(); + iter++) + { + joint = iter->first; + LLVector3 newScale = joint->getScale(); + LLVector3 scaleDelta = iter->second; + newScale = newScale + (effective_weight * scaleDelta) - (mLastWeight * scaleDelta); + joint->setScale(newScale); + } + + for (iter = mJointOffsets.begin(); + iter != mJointOffsets.end(); + iter++) + { + joint = iter->first; + LLVector3 newPosition = joint->getPosition(); + LLVector3 positionDelta = iter->second; + newPosition = newPosition + (effective_weight * positionDelta) - (mLastWeight * positionDelta); + joint->setPosition(newPosition); + } + + if (mLastWeight != mCurWeight && !mIsAnimating) + { + mAvatar->setSkeletonSerialNum(mAvatar->getSkeletonSerialNum() + 1); + } + mLastWeight = mCurWeight; } LLPolyMorphData *clone_morph_param(const LLPolyMorphData *src_data, - const LLVector3 &direction, - const std::string &name) + const LLVector3 &direction, + const std::string &name) { - LLPolyMorphData* cloned_morph_data = new LLPolyMorphData(*src_data); - cloned_morph_data->mName = name; - for (U32 v=0; v < cloned_morph_data->mNumIndices; v++) - { - cloned_morph_data->mCoords[v] = direction; - cloned_morph_data->mNormals[v] = LLVector3(0,0,0); - cloned_morph_data->mBinormals[v] = LLVector3(0,0,0); - } - return cloned_morph_data; + LLPolyMorphData* cloned_morph_data = new LLPolyMorphData(*src_data); + cloned_morph_data->mName = name; + for (U32 v=0; v < cloned_morph_data->mNumIndices; v++) + { + cloned_morph_data->mCoords[v] = direction; + cloned_morph_data->mNormals[v] = LLVector3(0,0,0); + cloned_morph_data->mBinormals[v] = LLVector3(0,0,0); + } + return cloned_morph_data; } LLPolyMorphData *clone_morph_param_cleavage(const LLPolyMorphData *src_data, F32 scale, const std::string &name) { - LLPolyMorphData* cloned_morph_data = new LLPolyMorphData(*src_data); - cloned_morph_data->mName = name; - for (U32 v=0; v < cloned_morph_data->mNumIndices; v++) - { - cloned_morph_data->mCoords[v] = src_data->mCoords[v]*scale; - cloned_morph_data->mNormals[v] = src_data->mNormals[v]*scale; - cloned_morph_data->mBinormals[v] = src_data->mBinormals[v]*scale; - if (cloned_morph_data->mCoords[v][1] < 0) - { - cloned_morph_data->mCoords[v][1] *= -1; - cloned_morph_data->mNormals[v][1] *= -1; - cloned_morph_data->mBinormals[v][1] *= -1; - } - } - return cloned_morph_data; + LLPolyMorphData* cloned_morph_data = new LLPolyMorphData(*src_data); + cloned_morph_data->mName = name; + for (U32 v=0; v < cloned_morph_data->mNumIndices; v++) + { + cloned_morph_data->mCoords[v] = src_data->mCoords[v]*scale; + cloned_morph_data->mNormals[v] = src_data->mNormals[v]*scale; + cloned_morph_data->mBinormals[v] = src_data->mBinormals[v]*scale; + if (cloned_morph_data->mCoords[v][1] < 0) + { + cloned_morph_data->mCoords[v][1] *= -1; + cloned_morph_data->mNormals[v][1] *= -1; + cloned_morph_data->mBinormals[v][1] *= -1; + } + } + return cloned_morph_data; } // End |