SL-395 - partial support for joint scale locking via flag in skin info

master
Brad Payne (Vir Linden) 2016-09-02 16:44:57 -04:00
parent a2875ba53e
commit 34ced1aa2c
6 changed files with 70 additions and 65 deletions

View File

@ -404,16 +404,16 @@ void showJointScaleOverrides( const LLJoint& joint, const std::string& note, con
LL_DEBUGS("Avatar") << av_info << " joint " << joint.getName() << " " << note << " " << os.str() << LL_ENDL;
}
bool above_joint_pos_threshold(const LLVector3& diff)
bool LLJoint::aboveJointPosThreshold(const LLVector3& pos) const
{
//return !diff.isNull();
LLVector3 diff = pos - getDefaultPosition();
const F32 max_joint_pos_offset = 0.0001f; // 0.1 mm
return diff.lengthSquared() > max_joint_pos_offset * max_joint_pos_offset;
}
bool above_joint_scale_threshold(const LLVector3& diff)
bool LLJoint::aboveJointScaleThreshold(const LLVector3& scale) const
{
//return !diff.isNull();
LLVector3 diff = scale - getDefaultScale();
const F32 max_joint_scale_offset = 0.0001f; // 0.1 mm
return diff.lengthSquared() > max_joint_scale_offset * max_joint_scale_offset;
}
@ -434,15 +434,6 @@ void LLJoint::addAttachmentPosOverride( const LLVector3& pos, const LLUUID& mesh
//{
// return;
//}
if (!above_joint_pos_threshold(pos-getDefaultPosition()))
{
if (do_debug_joint(getName()))
{
LL_DEBUGS("Avatar") << "Attachment pos override ignored for " << getName()
<< ", pos " << pos << " is same as default pos" << LL_ENDL;
}
return;
}
LLVector3 before_pos;
LLUUID before_mesh_id;
@ -627,15 +618,6 @@ void LLJoint::addAttachmentScaleOverride( const LLVector3& scale, const LLUUID&
{
return;
}
if (!above_joint_scale_threshold(scale-getDefaultScale()))
{
if (do_debug_joint(getName()))
{
LL_DEBUGS("Avatar") << "Attachment scale override ignored for " << getName()
<< ", scale " << scale << " is same as default scale" << LL_ENDL;
}
return;
}
if (!m_attachmentScaleOverrides.count())
{
if (do_debug_joint(getName()))

View File

@ -278,6 +278,10 @@ public:
void clearAttachmentScaleOverrides();
void showAttachmentScaleOverrides(const std::string& av_info) const;
// These are used in checks of whether a pos/scale override is considered significant.
bool aboveJointPosThreshold(const LLVector3& pos) const;
bool aboveJointScaleThreshold(const LLVector3& scale) const;
//Accessor for the joint id
LLUUID getId( void ) { return mId; }
//Setter for the joints id

View File

@ -1379,6 +1379,16 @@ void LLDAELoader::processDomModel(LLModel* model, DAE* dae, daeElement* root, do
if ( !missingSkeletonOrScene )
{
// FIXME: mesh_id is used to determine which mesh gets to
// set the joint offset, in the event of a conflict. Since
// we don't know the mesh id yet, we can't guarantee that
// joint offsets will be applied with the same priority as
// in the uploaded model. If the file contains multiple
// meshes with conflicting joint offsets, preview may be
// incorrect.
LLUUID fake_mesh_id;
fake_mesh_id.generate();
//Set the joint translations on the avatar
JointMap :: const_iterator masterJointIt = mJointMap.begin();
JointMap :: const_iterator masterJointItEnd = mJointMap.end();
@ -1393,19 +1403,16 @@ void LLDAELoader::processDomModel(LLModel* model, DAE* dae, daeElement* root, do
LLJoint* pJoint = mJointLookupFunc(lookingForJoint,mOpaqueData);
if ( pJoint )
{
// FIXME: mesh_id is used to determine which
// mesh gets to set the joint offset, in the
// event of a conflict. Since we don't know
// the mesh id yet, we can't guarantee that
// joint offsets will be applied with the same
// priority as in the uploaded model. If the
// file contains multiple meshes with
// conflicting joint offsets, preview may be
// incorrect.
LLUUID fake_mesh_id;
fake_mesh_id.generate();
bool dummy; // not used
pJoint->addAttachmentPosOverride( jointTransform.getTranslation(), fake_mesh_id, "", dummy);
const LLVector3& joint_pos = jointTransform.getTranslation();
if (pJoint->aboveJointPosThreshold(joint_pos))
{
bool override_changed; // not used
pJoint->addAttachmentPosOverride(joint_pos, fake_mesh_id, "", override_changed);
if (model->mSkinInfo.mLockScaleIfJointPosition)
{
pJoint->addAttachmentScaleOverride(pJoint->getDefaultScale(), fake_mesh_id, "");
}
}
}
else
{

View File

@ -50,8 +50,12 @@ std::string model_names[] =
const int MODEL_NAMES_LENGTH = sizeof(model_names) / sizeof(std::string);
LLModel::LLModel(LLVolumeParams& params, F32 detail)
: LLVolume(params, detail), mNormalizedScale(1,1,1), mNormalizedTranslation(0,0,0)
, mPelvisOffset( 0.0f ), mStatus(NO_ERRORS), mSubmodelID(0)
: LLVolume(params, detail),
mNormalizedScale(1,1,1),
mNormalizedTranslation(0,0,0),
mPelvisOffset( 0.0f ),
mStatus(NO_ERRORS),
mSubmodelID(0)
{
mDecompID = -1;
mLocalID = -1;
@ -1446,6 +1450,9 @@ void LLMeshSkinInfo::fromLLSD(LLSD& skin)
{
mPelvisOffset = skin["pelvis_offset"].asReal();
}
// FIXME BENTO check contents of asset.
mLockScaleIfJointPosition = true;
}
LLSD LLMeshSkinInfo::asLLSD(bool include_joints) const

View File

@ -54,6 +54,7 @@ public:
LLSD asLLSD(bool include_joints) const;
LLMatrix4 mBindShapeMatrix;
float mPelvisOffset;
bool mLockScaleIfJointPosition;
};
class LLModel : public LLVolume

View File

@ -5539,16 +5539,25 @@ void LLVOAvatar::addAttachmentOverridesForObject(LLViewerObject *vo)
{
pJoint->setId( currentId );
const LLVector3& jointPos = pSkinData->mAlternateBindMatrix[i].getTranslation();
bool override_changed;
pJoint->addAttachmentPosOverride( jointPos, mesh_id, avString(), override_changed );
if (override_changed)
if (pJoint->aboveJointPosThreshold(jointPos))
{
//If joint is a pelvis then handle old/new pelvis to foot values
if ( lookingForJoint == "mPelvis" )
{
pelvisGotSet = true;
}
bool override_changed;
pJoint->addAttachmentPosOverride( jointPos, mesh_id, avString(), override_changed );
if (override_changed)
{
//If joint is a pelvis then handle old/new pelvis to foot values
if ( lookingForJoint == "mPelvis" )
{
pelvisGotSet = true;
}
}
if (pSkinData->mLockScaleIfJointPosition)
{
// Note that unlike positions, there's no threshold check here,
// just a lock at the default value.
pJoint->addAttachmentScaleOverride(pJoint->getDefaultScale(), mesh_id, avString());
}
}
}
}
@ -5567,25 +5576,6 @@ void LLVOAvatar::addAttachmentOverridesForObject(LLViewerObject *vo)
}
}
}
// Set the joint scales
// FIXME replace with real logic for finding scale, probably inside the bindcnt loop above
const LLUUID& mesh_id = pSkinData->mMeshID;
for (int i = 0; i < jointCnt; ++i)
{
std::string lookingForJoint = pSkinData->mJointNames[i].c_str();
LLJoint* pJoint = getJoint(lookingForJoint);
if (pJoint)
{
if (pJoint->getName() == "mCollarRight" ||
pJoint->getName() == "mShoulderRight" ||
pJoint->getName() == "mElbowRight" ||
pJoint->getName() == "mHandRight")
{
LLVector3 jointScale(2.0f, 2.0f, 2.0f);
pJoint->addAttachmentScaleOverride(jointScale, mesh_id, avString());
}
}
}
}
//Rebuild body data if we altered joints/pelvis
@ -8491,6 +8481,20 @@ void LLVOAvatar::dumpArchetypeXML(const std::string& prefix, bool group_by_weara
pJoint->getName().c_str(), pos[0], pos[1], pos[2], mesh_id.asString().c_str());
}
}
// Joint scale overrides
for (iter = mSkeleton.begin(); iter != end; ++iter)
{
LLJoint* pJoint = (*iter);
LLVector3 scale;
LLUUID mesh_id;
if (pJoint->hasAttachmentScaleOverride(scale,mesh_id))
{
apr_file_printf( file, "\t\t<joint_scale name=\"%s\" scale=\"%f %f %f\" mesh_id=\"%s\"/>\n",
pJoint->getName().c_str(), scale[0], scale[1], scale[2], mesh_id.asString().c_str());
}
}
F32 pelvis_fixup;
LLUUID mesh_id;
if (hasPelvisFixup(pelvis_fixup, mesh_id))