summaryrefslogtreecommitdiff
path: root/indra/newview/llskinningutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llskinningutil.cpp')
-rw-r--r--indra/newview/llskinningutil.cpp114
1 files changed, 94 insertions, 20 deletions
diff --git a/indra/newview/llskinningutil.cpp b/indra/newview/llskinningutil.cpp
index dba690242a..0878cee1a3 100644
--- a/indra/newview/llskinningutil.cpp
+++ b/indra/newview/llskinningutil.cpp
@@ -31,26 +31,24 @@
#include "llvoavatar.h"
#include "llviewercontrol.h"
#include "llmeshrepository.h"
+#include "llvolume.h"
+#include "llrigginginfo.h"
-// static
void LLSkinningUtil::initClass()
{
}
-// static
U32 LLSkinningUtil::getMaxJointCount()
{
U32 result = LL_MAX_JOINTS_PER_MESH_OBJECT;
return result;
}
-// static
U32 LLSkinningUtil::getMeshJointCount(const LLMeshSkinInfo *skin)
{
return llmin((U32)getMaxJointCount(), (U32)skin->mJointNames.size());
}
-// static
void LLSkinningUtil::scrubInvalidJoints(LLVOAvatar *avatar, LLMeshSkinInfo* skin)
{
if (skin->mInvalidJointsScrubbed)
@@ -71,28 +69,16 @@ void LLSkinningUtil::scrubInvalidJoints(LLVOAvatar *avatar, LLMeshSkinInfo* skin
skin->mInvalidJointsScrubbed = true;
}
-// static
void LLSkinningUtil::initSkinningMatrixPalette(
LLMatrix4* mat,
S32 count,
const LLMeshSkinInfo* skin,
LLVOAvatar *avatar)
{
+ initJointNums(const_cast<LLMeshSkinInfo*>(skin), avatar);
for (U32 j = 0; j < count; ++j)
{
- LLJoint *joint = NULL;
- if (skin->mJointNums[j] == -1)
- {
- joint = avatar->getJoint(skin->mJointNames[j]);
- if (joint)
- {
- skin->mJointNums[j] = joint->getJointNum();
- }
- }
- else
- {
- joint = avatar->getJoint(skin->mJointNums[j]);
- }
+ LLJoint *joint = avatar->getJoint(skin->mJointNums[j]);
if (joint)
{
#define MAT_USE_SSE
@@ -119,7 +105,6 @@ void LLSkinningUtil::initSkinningMatrixPalette(
}
}
-// static
void LLSkinningUtil::checkSkinWeights(LLVector4a* weights, U32 num_vertices, const LLMeshSkinInfo* skin)
{
#ifdef SHOW_ASSERT // same condition that controls llassert()
@@ -159,7 +144,6 @@ void LLSkinningUtil::scrubSkinWeights(LLVector4a* weights, U32 num_vertices, con
checkSkinWeights(weights, num_vertices, skin);
}
-// static
void LLSkinningUtil::getPerVertexSkinMatrix(
F32* weights,
LLMatrix4a* mat,
@@ -216,3 +200,93 @@ void LLSkinningUtil::getPerVertexSkinMatrix(
llassert(valid_weights);
}
+void LLSkinningUtil::initJointNums(LLMeshSkinInfo* skin, LLVOAvatar *avatar)
+{
+ if (!skin->mJointNumsInitialized)
+ {
+ for (U32 j = 0; j < skin->mJointNames.size(); ++j)
+ {
+ LLJoint *joint = NULL;
+ if (skin->mJointNums[j] == -1)
+ {
+ joint = avatar->getJoint(skin->mJointNames[j]);
+ if (joint)
+ {
+ skin->mJointNums[j] = joint->getJointNum();
+ }
+ }
+ }
+ skin->mJointNumsInitialized = true;
+ }
+}
+
+static LLTrace::BlockTimerStatHandle FTM_FACE_RIGGING_INFO("Face Rigging Info");
+
+void LLSkinningUtil::updateRiggingInfo(const LLMeshSkinInfo* skin, LLVOAvatar *avatar, LLVolumeFace& vol_face)
+{
+ LL_RECORD_BLOCK_TIME(FTM_FACE_RIGGING_INFO);
+
+ if (vol_face.mJointRiggingInfoTab.needsUpdate())
+ {
+ S32 num_verts = vol_face.mNumVertices;
+ if (num_verts>0 && vol_face.mWeights && (skin->mJointNames.size()>0))
+ {
+ initJointNums(const_cast<LLMeshSkinInfo*>(skin), avatar);
+ if (vol_face.mJointRiggingInfoTab.size()==0)
+ {
+ //std::set<S32> active_joints;
+ //S32 active_verts = 0;
+ vol_face.mJointRiggingInfoTab.resize(LL_CHARACTER_MAX_ANIMATED_JOINTS);
+ LLJointRiggingInfoTab &rig_info_tab = vol_face.mJointRiggingInfoTab;
+ for (S32 i=0; i<vol_face.mNumVertices; i++)
+ {
+ LLVector4a& pos = vol_face.mPositions[i];
+ F32 *w = vol_face.mWeights[i].getF32ptr();
+ for (U32 k=0; k<4; ++k)
+ {
+ S32 joint_index = llfloor(w[k]);
+ if (w[k]-joint_index > 0.0f)
+ {
+ S32 joint_num = skin->mJointNums[joint_index];
+ if (joint_num >= 0 && joint_num < LL_CHARACTER_MAX_ANIMATED_JOINTS)
+ {
+ rig_info_tab[joint_num].setIsRiggedTo(true);
+ //active_joints.insert(joint_num);
+ //active_verts++;
+
+ // AXON can precompute these matMuls.
+ LLMatrix4a bind_shape;
+ bind_shape.loadu(skin->mBindShapeMatrix);
+ LLMatrix4a inv_bind;
+ inv_bind.loadu(skin->mInvBindMatrix[joint_index]);
+ LLMatrix4a mat;
+ matMul(bind_shape, inv_bind, mat);
+ LLVector4a pos_joint_space;
+ mat.affineTransform(pos, pos_joint_space);
+ LLVector4a *extents = rig_info_tab[joint_num].getRiggedExtents();
+ update_min_max(extents[0], extents[1], pos_joint_space);
+ }
+ }
+ }
+ }
+ //LL_DEBUGS("RigSpammish") << "built rigging info for vf " << &vol_face
+ // << " num_verts " << vol_face.mNumVertices
+ // << " active joints " << active_joints.size()
+ // << " active verts " << active_verts
+ // << LL_ENDL;
+ vol_face.mJointRiggingInfoTab.setNeedsUpdate(false);
+ }
+ }
+ if (vol_face.mJointRiggingInfoTab.size()!=0)
+ {
+ LL_DEBUGS("RigSpammish") << "we have rigging info for vf " << &vol_face
+ << " num_verts " << vol_face.mNumVertices << LL_ENDL;
+ }
+ else
+ {
+ LL_DEBUGS("RigSpammish") << "no rigging info for vf " << &vol_face
+ << " num_verts " << vol_face.mNumVertices << LL_ENDL;
+ }
+
+ }
+}