secondlife / viewer

🖥️ Second Life's official client
GNU Lesser General Public License v2.1
211 stars 53 forks source link

Update animesh size by manual edit and script #2877

Open canny[bot] opened 2 weeks ago

canny[bot] commented 2 weeks ago

Currently we can't update animesh size and have to upload multiple versions of the mesh in different sizes, and upload all animations for each size.

I did some research in the viewer's code, and it appears to me that it's extremely easy to add a feature to adjust the global size of an animesh by modifying the llcontrolavatar.cpp file. Here is the current setGlobalScale() function:

void LLControlAvatar::setGlobalScale(F32 scale)

{

if (scale <= 0.0)

{

    LL_WARNS() << "invalid global scale " << scale << LL_ENDL;

    return;

}

if (scale != mGlobalScale)

{

    F32 adjust_scale = scale/mGlobalScale;

    LL_INFOS() << "scale " << scale << " adjustment " << adjust_scale << LL_ENDL;

    // should we be scaling from the pelvis or the root?

    recursiveScaleJoint(mPelvisp,adjust_scale);

    mGlobalScale = scale;

}

}

And here is a modified version that currently takes into account the X size of the main prim:

void LLControlAvatar::setGlobalScale(F32 scale)

{

if (scale <= 0.0)

{

    LL_WARNS() << "invalid global scale " << scale << LL_ENDL;

    return;

}

scale *= mRootVolp->getScale().mV[0];

if (scale != mGlobalScale)

{

    F32 adjust_scale = scale/mGlobalScale;

    LL_INFOS() << "scale " << scale << " adjustment " << adjust_scale << LL_ENDL;

    recursiveScaleJoint(mRoot,adjust_scale);

    mGlobalScale = scale;

}

}

Note that I replaced mPelvisp by mRoot because using mPelvisp does not correctly adjust the animesh's movement during the animation."

It works wonderfully. Of course, this modification as it stands could affect many existing animesh objects, so we need to add a parameter to the object, 'ANIMESH_SCALE_FACTOR', which would be set to 1 by default, adjustable via script and by manual editing of the object. We would then have something like this:

scale *= mRootVolp->getAnimeshScaleFactor;

Here is a gif, you can take a look, the 4 dogs are all the exact same animesh, I only changed there main prim X scale :

https://gyazo.com/de2dc2904bcb4e6b8737514aa7db7d2c

https://secondlife.canny.io/admin/board/feature-requests/p/update-animesh-size-by-manual-edit-and-script

canny[bot] commented 2 weeks ago

This issue has been linked to a Canny post: Update animesh size by manual edit and script :tada: