llviewerjointmesh_vec.cpp

Go to the documentation of this file.
00001 
00035 //-----------------------------------------------------------------------------
00036 // Header Files
00037 //-----------------------------------------------------------------------------
00038 #include "llviewerprecompiledheaders.h"
00039 
00040 #include "llviewerjointmesh.h"
00041 
00042 #include "llface.h"
00043 #include "llpolymesh.h"
00044 #include "llv4math.h"
00045 #include "llv4matrix3.h"
00046 #include "llv4matrix4.h"
00047 
00048 // Generic vectorized code, uses compiler defaults, works well for Altivec
00049 // on PowerPC.
00050 
00051 // static
00052 void LLViewerJointMesh::updateGeometryVectorized(LLFace *face, LLPolyMesh *mesh)
00053 {
00054         static LLV4Matrix4      sJointMat[32];
00055         LLDynamicArray<LLJointRenderData*>& joint_data = mesh->getReferenceMesh()->mJointRenderData;
00056         S32 j, joint_num, joint_end = joint_data.count();
00057         LLV4Vector3 pivot;
00058 
00059         //upload joint pivots/matrices
00060         for(j = joint_num = 0; joint_num < joint_end ; ++joint_num )
00061         {
00062                 LLSkinJoint *sj;
00063                 const LLMatrix4 *       wm = joint_data[joint_num]->mWorldMatrix;
00064                 if (NULL == (sj = joint_data[joint_num]->mSkinJoint))
00065                 {
00066                                 sj = joint_data[++joint_num]->mSkinJoint;
00067                                 ((LLV4Matrix3)(sJointMat[j] = *wm)).multiply(sj->mRootToParentJointSkinOffset, pivot);
00068                                 sJointMat[j++].translate(pivot);
00069                                 wm = joint_data[joint_num]->mWorldMatrix;
00070                 }
00071                 ((LLV4Matrix3)(sJointMat[j] = *wm)).multiply(sj->mRootToJointSkinOffset, pivot);
00072                 sJointMat[j++].translate(pivot);
00073         }
00074 
00075         F32                                     weight          = F32_MAX;
00076         LLV4Matrix4                     blend_mat;
00077 
00078         LLStrider<LLVector3> o_vertices;
00079         LLStrider<LLVector3> o_normals;
00080 
00081         LLVertexBuffer *buffer = face->mVertexBuffer;
00082         buffer->getVertexStrider(o_vertices,  mesh->mFaceVertexOffset);
00083         buffer->getNormalStrider(o_normals,   mesh->mFaceVertexOffset);
00084 
00085         const F32*                      weights                 = mesh->getWeights();
00086         const LLVector3*        coords                  = mesh->getCoords();
00087         const LLVector3*        normals                 = mesh->getNormals();
00088         for (U32 index = 0, index_end = mesh->getNumVertices(); index < index_end; ++index)
00089         {
00090                 if( weight != weights[index])
00091                 {
00092                         S32 joint = llfloor(weight = weights[index]);
00093                         blend_mat.lerp(sJointMat[joint], sJointMat[joint+1], weight - joint);
00094                 }
00095                 blend_mat.multiply(coords[index], o_vertices[index]);
00096                 ((LLV4Matrix3)blend_mat).multiply(normals[index], o_normals[index]);
00097         }
00098 }

Generated on Thu Jul 1 06:09:28 2010 for Second Life Viewer by  doxygen 1.4.7