Ticket #2026: cleanedup.patch

File cleanedup.patch, 4.4 KB (added by wraitii, 10 years ago)
  • Model.cpp

     
    178178
    179179        // extend bounds by vertex positions at the frame
    180180        for (size_t i=0;i<numverts;i++)
    181         {
    182             result += CModelDef::SkinPoint(verts[i], GetAnimatedBoneMatrices());
    183         }
     181            CModelDef::SkinPoint(verts[i], GetAnimatedBoneMatrices(), result);
    184182        // advance to next frame
    185183        m_AnimTime += anim->GetFrameTime();
    186184    }
     
    424424
    425425    if (m_BoneMatrices)
    426426    {
     427        CMatrix3D* inverseBoneMatrices = m_pModelDef->GetInverseBindBoneMatrices();
    427428        for (size_t i = 0; i < m_pModelDef->GetNumBones(); i++)
    428429        {
    429             m_BoneMatrices[i] = m_BoneMatrices[i] * m_pModelDef->GetInverseBindBoneMatrices()[i];
     430            m_BoneMatrices[i] *= inverseBoneMatrices[i];
    430431        }
    431432
    432433        // Note: there is a special case of joint influence, in which the vertex
  • ModelDef.cpp

     
    3030# include <xmmintrin.h>
    3131#endif
    3232
    33 CVector3D CModelDef::SkinPoint(const SModelVertex& vtx,
    34                                const CMatrix3D newPoseMatrices[])
     33void CModelDef::SkinPoint(const SModelVertex& vtx, const CMatrix3D newPoseMatrices[],
     34                               CVector3D &result)
    3535{
    36     CVector3D result (0, 0, 0);
    37 
    3836    for (int i = 0; i < SVertexBlend::SIZE && vtx.m_Blend.m_Bone[i] != 0xff; ++i)
    39     {
    4037        result += newPoseMatrices[vtx.m_Blend.m_Bone[i]].Transform(vtx.m_Coords) * vtx.m_Blend.m_Weight[i];
    41     }
     38
     39}
    4240
    43     return result;
     41void CModelDef::SkinPoint(const SModelVertex& vtx, const CMatrix3D newPoseMatrices[],
     42                          CBoundingBoxAligned &result)
     43{
     44    for (int i = 0; i < SVertexBlend::SIZE && vtx.m_Blend.m_Bone[i] != 0xff; ++i)
     45    result += newPoseMatrices[vtx.m_Blend.m_Bone[i]].Transform(vtx.m_Coords) * vtx.m_Blend.m_Weight[i];
     46   
    4447}
    4548
    46 CVector3D CModelDef::SkinNormal(const SModelVertex& vtx,
    47                                 const CMatrix3D newPoseMatrices[])
     49void CModelDef::SkinNormal(const SModelVertex& vtx, const CMatrix3D newPoseMatrices[],
     50                                CVector3D &result)
    4851{
    4952    // To be correct, the normal vectors apparently need to be multiplied by the
    5053    // inverse of the transpose. Unfortunately inverses are slow.
     
    6972    // (This isn't very good as a proof, but it's better than assuming M is
    7073    // orthogonal when it's clearly not.)
    7174
    72     CVector3D result (0, 0, 0);
    73 
    7475    for (int i = 0; i < SVertexBlend::SIZE && vtx.m_Blend.m_Bone[i] != 0xff; ++i)
    75     {
    7676        result += newPoseMatrices[vtx.m_Blend.m_Bone[i]].Rotate(vtx.m_Norm) * vtx.m_Blend.m_Weight[i];
    77     }
    7877   
    7978    // If there was more than one influence, the result is probably not going
    8079    // to be of unit length (since it's a weighted sum of several independent
     
    8382    // optimise that case a bit.)
    8483    if (vtx.m_Blend.m_Bone[1] != 0xff) // if more than one influence
    8584        result.Normalize();
    86 
    87     return result;
    8885}
    8986
    9087void CModelDef::SkinPointsAndNormals(
     
    400397
    401398            for (size_t i = 0; i < mdef->m_NumVertices; ++i)
    402399            {
    403                 mdef->m_pVertices[i].m_Coords = SkinPoint(mdef->m_pVertices[i], &bindPose[0]);
    404                 mdef->m_pVertices[i].m_Norm = SkinNormal(mdef->m_pVertices[i], &bindPose[0]);
     400                SkinPoint(mdef->m_pVertices[i], &bindPose[0], mdef->m_pVertices[i].m_Coords);
     401                SkinNormal(mdef->m_pVertices[i], &bindPose[0], mdef->m_pVertices[i].m_Norm);
    405402            }
    406403        }
    407404    }
  • ModelDef.h

     
    2323#define INCLUDED_MODELDEF
    2424
    2525#include "ps/CStr.h"
     26#include "maths/BoundingBoxAligned.h"
    2627#include "maths/Vector2D.h"
    2728#include "maths/Vector3D.h"
    2829#include "maths/Quaternion.h"
     
    192193     *
    193194     * @return new world-space vertex coordinates
    194195     */
    195     static CVector3D SkinPoint(const SModelVertex& vtx,
    196         const CMatrix3D newPoseMatrices[]);
     196    static void SkinPoint(const SModelVertex& vtx, const CMatrix3D newPoseMatrices[],
     197                          CVector3D &result);
     198    static void SkinPoint(const SModelVertex& vtx, const CMatrix3D newPoseMatrices[],
     199                          CBoundingBoxAligned &result);
    197200
    198201    /**
    199202     * Transform the given vertex's normal from the bind pose into the new pose.
    200203     *
    201204     * @return new world-space vertex normal
    202205     */
    203     static CVector3D SkinNormal(const SModelVertex& vtx,
    204         const CMatrix3D newPoseMatrices[]);
     206    static void SkinNormal(const SModelVertex& vtx, const CMatrix3D newPoseMatrices[], CVector3D &result);
    205207
    206208    /**
    207209     * Transform vertices' positions and normals.