Changeset 401

Show
Ignore:
Timestamp:
10/06/11 10:50:23 (8 months ago)
Author:
Carsten
Message:

Model support: Better member and variable names in AnimPoseT code.

Location:
cafu/trunk/Libs/Models
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/Libs/Models/AnimPose.cpp

    r400 r401  
    3232    : m_Model(Model), 
    3333      m_SequNr(SequNr), 
     34      m_FrameNr(FrameNr), 
    3435      m_Super(NULL), 
    35       m_FrameNr(FrameNr), 
    3636      m_NeedsRecache(true), 
    3737      m_BoundingBox() 
     
    131131        case MatSys::RendererI::AMBIENT: 
    132132        { 
    133             for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
     133            for (unsigned long MeshNr=0; MeshNr<m_Draw_Meshes.Size(); MeshNr++) 
    134134            { 
    135135                MatSys::Renderer->SetCurrentMaterial(m_Model.GetRenderMaterial(MeshNr, SkinNr)); 
     
    190190        case MatSys::RendererI::LIGHTING: 
    191191        { 
    192             for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
     192            for (unsigned long MeshNr=0; MeshNr<m_Draw_Meshes.Size(); MeshNr++) 
    193193            { 
    194194                MatSys::Renderer->SetCurrentMaterial(m_Model.GetRenderMaterial(MeshNr, SkinNr)); 
     
    200200        case MatSys::RendererI::STENCILSHADOW: 
    201201        { 
    202             const Vector3fT LightPos(MatSys::Renderer->GetCurrentLightSourcePosition()); 
    203  
    204             for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
    205             { 
    206                 const CafuModelT::MeshT& Mesh    =m_Model.GetMeshes()[MeshNr]; 
    207                 const AnimPoseT::MeshT&  PoseMesh=m_Meshes[MeshNr]; 
    208                 const MaterialT*         MeshMat =m_Model.GetMaterial(MeshNr, SkinNr); 
     202            typedef CafuModelT::MeshT MeshT; 
     203 
     204            const ArrayT<MeshT>& Meshes=m_Model.GetMeshes(); 
     205            const Vector3fT      LightPos(MatSys::Renderer->GetCurrentLightSourcePosition()); 
     206 
     207            for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 
     208            { 
     209                const MeshT&     Mesh    =Meshes[MeshNr]; 
     210                const MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 
     211                const MaterialT* MeshMat =m_Model.GetMaterial(MeshNr, SkinNr); 
    209212 
    210213                if (MeshMat==NULL || MeshMat->NoShadows) continue; 
     
    216219                for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) 
    217220                { 
    218                     const CafuModelT::MeshT::TriangleT& Tri    =Mesh.Triangles[TriNr]; 
    219                     const AnimPoseT::MeshT::TriangleT&  PoseTri=PoseMesh.Triangles[TriNr]; 
    220  
    221                     const float Dot=(LightPos-PoseMesh.Vertices[Tri.VertexIdx[0]].Draw_Pos).dot(PoseTri.Draw_Normal); 
     221                    const MeshT::TriangleT&    Tri    =Mesh.Triangles[TriNr]; 
     222                    const MeshInfoT::TriangleT& TriInfo=MeshInfo.Triangles[TriNr]; 
     223 
     224                    const float Dot=(LightPos-MeshInfo.Vertices[Tri.VertexIdx[0]].Pos).dot(TriInfo.Normal); 
    222225 
    223226                    TriangleIsFrontFacing[TriNr]=Dot>0; 
     
    234237 
    235238                    // This triangle is front-facing wrt. the light source. 
    236                     const CafuModelT::MeshT::TriangleT& Tri=Mesh.Triangles[TriNr]; 
     239                    const MeshT::TriangleT& Tri=Mesh.Triangles[TriNr]; 
    237240 
    238241                    for (unsigned long EdgeNr=0; EdgeNr<3; EdgeNr++) 
     
    246249                            const unsigned long v1=EdgeNr; 
    247250                            const unsigned long v2=(EdgeNr+1) % 3; 
    248                             const Vector3fT     LA=PoseMesh.Vertices[Tri.VertexIdx[v1]].Draw_Pos-LightPos; 
    249                             const Vector3fT     LB=PoseMesh.Vertices[Tri.VertexIdx[v2]].Draw_Pos-LightPos; 
     251                            const Vector3fT     LA=MeshInfo.Vertices[Tri.VertexIdx[v1]].Pos-LightPos; 
     252                            const Vector3fT     LB=MeshInfo.Vertices[Tri.VertexIdx[v2]].Pos-LightPos; 
    250253 
    251254                            MeshSilhouette.Vertices.PushBackEmpty(4); 
     
    253256                            const unsigned long MeshSize=MeshSilhouette.Vertices.Size(); 
    254257 
    255                             MeshSilhouette.Vertices[MeshSize-4].SetOrigin(PoseMesh.Vertices[Tri.VertexIdx[v2]].Draw_Pos); 
    256                             MeshSilhouette.Vertices[MeshSize-3].SetOrigin(PoseMesh.Vertices[Tri.VertexIdx[v1]].Draw_Pos); 
     258                            MeshSilhouette.Vertices[MeshSize-4].SetOrigin(MeshInfo.Vertices[Tri.VertexIdx[v2]].Pos); 
     259                            MeshSilhouette.Vertices[MeshSize-3].SetOrigin(MeshInfo.Vertices[Tri.VertexIdx[v1]].Pos); 
    257260                            MeshSilhouette.Vertices[MeshSize-2].SetOrigin(LA, 0.0); 
    258261                            MeshSilhouette.Vertices[MeshSize-1].SetOrigin(LB, 0.0); 
     
    279282 
    280283                    // Render the occluder (front-facing wrt. the light source). 
    281                     const Vector3fT& A=PoseMesh.Vertices[Tri.VertexIdx[0]].Draw_Pos; 
    282                     const Vector3fT& B=PoseMesh.Vertices[Tri.VertexIdx[1]].Draw_Pos; 
    283                     const Vector3fT& C=PoseMesh.Vertices[Tri.VertexIdx[2]].Draw_Pos; 
     284                    const Vector3fT& A=MeshInfo.Vertices[Tri.VertexIdx[0]].Pos; 
     285                    const Vector3fT& B=MeshInfo.Vertices[Tri.VertexIdx[1]].Pos; 
     286                    const Vector3fT& C=MeshInfo.Vertices[Tri.VertexIdx[2]].Pos; 
    284287 
    285288                    MeshCaps.Vertices[MeshSize-6].SetOrigin(A); 
     
    308311bool AnimPoseT::TraceRay(int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, ModelT::TraceResultT& Result) const 
    309312{ 
     313    Recache(); 
     314 
     315    // If we miss the bounding-box, then we miss all the triangles as well. 
    310316    float Fraction=0.0f; 
    311  
    312     Recache(); 
    313  
    314     // If we miss the bounding-box, then we miss all the triangles as well. 
    315317    if (!GetBB().TraceRay(RayOrigin, RayDir, Fraction)) return false; 
    316318 
    317     for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
    318     { 
    319         const CafuModelT::MeshT& Mesh    =m_Model.GetMeshes()[MeshNr]; 
    320         const MeshT&             DrawMesh=m_Meshes[MeshNr]; 
    321         const MaterialT*         MeshMat =m_Model.GetMaterial(MeshNr, SkinNr); 
     319    typedef CafuModelT::MeshT MeshT; 
     320 
     321    const ArrayT<MeshT>& Meshes=m_Model.GetMeshes(); 
     322 
     323    for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 
     324    { 
     325        const MeshT&     Mesh    =Meshes[MeshNr]; 
     326        const MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 
     327        const MaterialT* MeshMat =m_Model.GetMaterial(MeshNr, SkinNr); 
    322328 
    323329        // If the ClipFlags don't match the ClipMask, this polygon doesn't interfere with the trace. 
     
    330336            // see there for details and additional information. 
    331337            using namespace cf::math; 
    332             const CafuModelT::MeshT::TriangleT& Tri    =Mesh.Triangles[TriNr]; 
    333             const AnimPoseT::MeshT::TriangleT&  DrawTri=DrawMesh.Triangles[TriNr]; 
    334  
    335             const Vector3fT& A=DrawMesh.Vertices[Tri.VertexIdx[0]].Draw_Pos; 
    336             const Vector3fT& B=DrawMesh.Vertices[Tri.VertexIdx[1]].Draw_Pos; 
    337             const Vector3fT& C=DrawMesh.Vertices[Tri.VertexIdx[2]].Draw_Pos; 
     338            const MeshT::TriangleT&    Tri    =Mesh.Triangles[TriNr]; 
     339            const MeshInfoT::TriangleT& TriInfo=MeshInfo.Triangles[TriNr]; 
     340 
     341            const Vector3fT& A=MeshInfo.Vertices[Tri.VertexIdx[0]].Pos; 
     342            const Vector3fT& B=MeshInfo.Vertices[Tri.VertexIdx[1]].Pos; 
     343            const Vector3fT& C=MeshInfo.Vertices[Tri.VertexIdx[2]].Pos; 
    338344 
    339345            const PlueckerfT R=PlueckerfT::CreateFromRay(RayOrigin, RayDir); 
     
    361367 
    362368            // The "aperture" test passed, now compute the fraction at which RayDir intersects the triangle plane. 
    363             const float Nenner=dot(DrawTri.Draw_Normal, RayDir); 
    364  
    365             if (Nenner==0) continue;                                // If Nenner==0, then RayDir is parallel to the triangle plane (no intersection). 
    366             assert(MeshMat->TwoSided || Nenner<0);                  // If the material is single sided, then Nenner<0, a consequence of the Pluecker tests above. 
    367  
    368             const float Dist=dot(DrawTri.Draw_Normal, RayOrigin-A); // The distance of RayOrigin to the triangle plane. 
     369            const float Nenner=dot(TriInfo.Normal, RayDir); 
     370 
     371            if (Nenner==0) continue;                            // If Nenner==0, then RayDir is parallel to the triangle plane (no intersection). 
     372            assert(MeshMat->TwoSided || Nenner<0);              // If the material is single sided, then Nenner<0, a consequence of the Pluecker tests above. 
     373 
     374            const float Dist=dot(TriInfo.Normal, RayOrigin-A); // The distance of RayOrigin to the triangle plane. 
    369375            const float F   =-(Dist-0.03125f)/Nenner; 
    370376 
     
    374380            // Hit the triangle! 
    375381            Result.Fraction=F; 
    376             Result.Normal  =(Nenner<0) ? DrawTri.Draw_Normal : -DrawTri.Draw_Normal;    // Handle two-sided materials properly. 
     382            Result.Normal  =(Nenner<0) ? TriInfo.Normal : -TriInfo.Normal;  // Handle two-sided materials properly. 
    377383            Result.Material=MeshMat; 
    378384            Result.MeshNr  =MeshNr; 
     
    396402    { 
    397403        const unsigned int VertexNr=m_Model.GetMeshes()[MeshNr].Triangles[TriNr].VertexIdx[i]; 
    398         const Vector3fT&   DrawPos =m_Meshes[MeshNr].Vertices[VertexNr].Draw_Pos; 
     404        const Vector3fT&   DrawPos =m_MeshInfos[MeshNr].Vertices[VertexNr].Pos; 
    399405        const float        Dist    =length(DrawPos-P); 
    400406 
     
    414420    Recache(); 
    415421 
    416     return m_Meshes[MeshNr].Vertices[VertexNr].Draw_Pos; 
     422    return m_MeshInfos[MeshNr].Vertices[VertexNr].Pos; 
    417423} 
    418424 
     
    464470    } 
    465471 
    466     if (m_Meshes.Size()!=m_Model.GetMeshes().Size()) 
    467     { 
    468         m_Meshes.Overwrite(); 
    469         m_Meshes.PushBackEmptyExact(m_Model.GetMeshes().Size()); 
     472    if (m_MeshInfos.Size()!=m_Model.GetMeshes().Size()) 
     473    { 
     474        m_MeshInfos.Overwrite(); 
     475        m_MeshInfos.PushBackEmptyExact(m_Model.GetMeshes().Size()); 
    470476    } 
    471477 
     
    481487        const CafuModelT::MeshT& Mesh=m_Model.GetMeshes()[MeshNr]; 
    482488 
    483         if (m_Meshes[MeshNr].Vertices.Size()!=Mesh.Vertices.Size()) 
    484         { 
    485             m_Meshes[MeshNr].Vertices.Overwrite(); 
    486             m_Meshes[MeshNr].Vertices.PushBackEmptyExact(Mesh.Vertices.Size()); 
    487         } 
    488  
    489         if (m_Meshes[MeshNr].Triangles.Size()!=Mesh.Triangles.Size()) 
    490         { 
    491             m_Meshes[MeshNr].Triangles.Overwrite(); 
    492             m_Meshes[MeshNr].Triangles.PushBackEmptyExact(Mesh.Triangles.Size()); 
     489        if (m_MeshInfos[MeshNr].Vertices.Size()!=Mesh.Vertices.Size()) 
     490        { 
     491            m_MeshInfos[MeshNr].Vertices.Overwrite(); 
     492            m_MeshInfos[MeshNr].Vertices.PushBackEmptyExact(Mesh.Vertices.Size()); 
     493        } 
     494 
     495        if (m_MeshInfos[MeshNr].Triangles.Size()!=Mesh.Triangles.Size()) 
     496        { 
     497            m_MeshInfos[MeshNr].Triangles.Overwrite(); 
     498            m_MeshInfos[MeshNr].Triangles.PushBackEmptyExact(Mesh.Triangles.Size()); 
    493499        } 
    494500 
     
    519525void AnimPoseT::UpdateData() const 
    520526{ 
    521     const int     SequenceNr=m_SequNr; 
    522     const float   FrameNr   =m_FrameNr; 
    523     const SuperT* Super     =m_Super; 
    524     const bool m_UseGivenTangentSpace=m_Model.GetUseGivenTS(); 
    525  
    526     const ArrayT<CafuModelT::JointT>& m_Joints=m_Model.GetJoints(); 
    527     const ArrayT<CafuModelT::AnimT>&  m_Anims =m_Model.GetAnims(); 
    528527    typedef CafuModelT::JointT JointT; 
    529     typedef CafuModelT::AnimT AnimT; 
     528    typedef CafuModelT::MeshT  MeshT; 
     529    typedef CafuModelT::AnimT  AnimT; 
     530 
     531    const ArrayT<JointT>& Joints=m_Model.GetJoints(); 
     532    const ArrayT<MeshT>&  Meshes=m_Model.GetMeshes(); 
     533    const ArrayT<AnimT>&  Anims =m_Model.GetAnims(); 
    530534 
    531535 
    532536    // ************************************************************************************************************** 
    533     //  Obtain a joints (bone) hierarchy for the desired frame FrameNr of the desired animation sequence SequenceNr. 
     537    //  Obtain a joints (bone) hierarchy for the desired frame m_FrameNr of the desired animation sequence m_SequNr. 
    534538    //  The result will be a transformation matrix for each joint (bone). 
    535539    // ************************************************************************************************************** 
    536540 
    537     if (SequenceNr==-1) 
     541    if (m_SequNr==-1) 
    538542    { 
    539543        // Don't animate, just use the bind pose defined in the model file. 
    540         for (unsigned long JointNr=0; JointNr<m_Joints.Size(); JointNr++) 
    541         { 
    542             if (Super && Super->HasMatrix(JointNr)) 
    543             { 
    544                 m_JointMatrices[JointNr]=Super->GetMatrix(JointNr); 
     544        for (unsigned long JointNr=0; JointNr<Joints.Size(); JointNr++) 
     545        { 
     546            if (m_Super && m_Super->HasMatrix(JointNr)) 
     547            { 
     548                m_JointMatrices[JointNr]=m_Super->GetMatrix(JointNr); 
    545549                continue; 
    546550            } 
    547551 
    548             const JointT& J=m_Joints[JointNr]; 
     552            const JointT& J=Joints[JointNr]; 
    549553            const MatrixT RelMatrix(J.Pos, cf::math::QuaternionfT::FromXYZ(J.Qtr), J.Scale); 
    550554 
     
    554558    else 
    555559    { 
    556         // SequenceNr is a valid index into m_Anims, so use that. 
    557         const AnimT& Anim=m_Anims[SequenceNr]; 
    558         const int    Frame_0=int(FrameNr);                                          // If FrameNr == 17.83, then Frame_0 == 17 
    559         const float  Frame_f=FrameNr-Frame_0;                                       //                           Frame_f ==  0.83 
    560         const int    Frame_1=(Frame_0+1>=int(Anim.Frames.Size())) ? 0 : Frame_0+1;  //                           Frame_1 == 18 
    561  
    562         for (unsigned long JointNr=0; JointNr<m_Joints.Size(); JointNr++) 
    563         { 
    564             if (Super && Super->HasMatrix(JointNr)) 
    565             { 
    566                 m_JointMatrices[JointNr]=Super->GetMatrix(JointNr); 
     560        // m_SequNr is a valid index into Anims, so use that. 
     561        const AnimT& Anim=Anims[m_SequNr]; 
     562        const int    Frame_0=int(m_FrameNr);                                        // If m_FrameNr == 17.83, then Frame_0 == 17 
     563        const float  Frame_f=m_FrameNr-Frame_0;                                     //                             Frame_f ==  0.83 
     564        const int    Frame_1=(Frame_0+1>=int(Anim.Frames.Size())) ? 0 : Frame_0+1;  //                             Frame_1 == 18 
     565 
     566        for (unsigned long JointNr=0; JointNr<Joints.Size(); JointNr++) 
     567        { 
     568            if (m_Super && m_Super->HasMatrix(JointNr)) 
     569            { 
     570                m_JointMatrices[JointNr]=m_Super->GetMatrix(JointNr); 
    567571                continue; 
    568572            } 
    569573 
    570574            const AnimT::AnimJointT& AJ=Anim.AnimJoints[JointNr]; 
    571             Vector3fT                Data_0[3]={ AJ.DefaultPos, AJ.DefaultQtr, AJ.DefaultScale }; 
    572             Vector3fT                Data_1[3]={ AJ.DefaultPos, AJ.DefaultQtr, AJ.DefaultScale }; 
     575 
     576            Vector3fT Data_0[3]={ AJ.DefaultPos, AJ.DefaultQtr, AJ.DefaultScale }; 
     577            Vector3fT Data_1[3]={ AJ.DefaultPos, AJ.DefaultQtr, AJ.DefaultScale }; 
    573578 
    574579            // Determine the position, quaternion and scale for Frame_0 and Frame_1. 
     
    593598            // Compute the matrix that is relative to the parent bone, and finally obtain the absolute matrix for that bone! 
    594599            const MatrixT RelMatrix(Pos, Quat, Scale); 
    595             const JointT& J=m_Joints[JointNr]; 
     600            const JointT& J=Joints[JointNr]; 
    596601 
    597602            m_JointMatrices[JointNr]=(J.Parent==-1) ? RelMatrix : m_JointMatrices[J.Parent]*RelMatrix; 
     
    605610    // ******************************************************************************************************************* 
    606611 
    607     for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
    608     { 
    609         const CafuModelT::MeshT& Mesh=m_Model.GetMeshes()[MeshNr]; 
    610         MeshT& DrawMesh=m_Meshes[MeshNr]; 
     612    for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 
     613    { 
     614        const MeshT& Mesh    =Meshes[MeshNr]; 
     615        MeshInfoT&   MeshInfo=m_MeshInfos[MeshNr]; 
    611616 
    612617        for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    613618        { 
    614             const CafuModelT::MeshT::VertexT& Vertex=Mesh.Vertices[VertexNr]; 
    615             MeshT::VertexT& DrawVertex=DrawMesh.Vertices[VertexNr]; 
     619            const MeshT::VertexT& Vertex    =Mesh.Vertices[VertexNr]; 
     620            MeshInfoT::VertexT&   VertexInfo=MeshInfo.Vertices[VertexNr]; 
    616621 
    617622            if (Vertex.GeoDups.Size()>0 && Vertex.GeoDups[0]<VertexNr) 
     
    619624                // This vertex has a geometrically identical duplicate that has already been computed. 
    620625                // Therefore, don't bother to recompute the same position again, just copy it from the duplicate. 
    621                 DrawVertex.Draw_Pos=DrawMesh.Vertices[Vertex.GeoDups[0]].Draw_Pos; 
     626                VertexInfo.Pos=MeshInfo.Vertices[Vertex.GeoDups[0]].Pos; 
    622627                continue; 
    623628            } 
     
    625630            if (Vertex.NumWeights==1) 
    626631            { 
    627                 const CafuModelT::MeshT::WeightT& Weight=Mesh.Weights[Vertex.FirstWeightIdx]; 
    628  
    629                 DrawVertex.Draw_Pos=m_JointMatrices[Weight.JointIdx].Mul_xyz1(Weight.Pos); 
     632                const MeshT::WeightT& Weight=Mesh.Weights[Vertex.FirstWeightIdx]; 
     633 
     634                VertexInfo.Pos=m_JointMatrices[Weight.JointIdx].Mul_xyz1(Weight.Pos); 
    630635            } 
    631636            else 
    632637            { 
    633                 DrawVertex.Draw_Pos=Vector3fT(0.0f, 0.0f, 0.0f); 
     638                VertexInfo.Pos=Vector3fT(0.0f, 0.0f, 0.0f); 
    634639 
    635640                for (unsigned int WeightNr=0; WeightNr<Vertex.NumWeights; WeightNr++) 
    636641                { 
    637                     const CafuModelT::MeshT::WeightT& Weight=Mesh.Weights[Vertex.FirstWeightIdx+WeightNr]; 
    638  
    639                     DrawVertex.Draw_Pos+=m_JointMatrices[Weight.JointIdx].Mul_xyz1(Weight.Pos) * Weight.Weight; 
     642                    const MeshT::WeightT& Weight=Mesh.Weights[Vertex.FirstWeightIdx+WeightNr]; 
     643 
     644                    VertexInfo.Pos+=m_JointMatrices[Weight.JointIdx].Mul_xyz1(Weight.Pos) * Weight.Weight; 
    640645                } 
    641646            } 
     
    651656    // ******************************************************************************************* 
    652657 
    653     if (m_UseGivenTangentSpace) 
    654     { 
    655         assert(m_Anims.Size()==0);  // It doesn't make sense to have statically given tangent-space axes with *animated* geometry... 
     658    if (m_Model.GetUseGivenTS()) 
     659    { 
     660        assert(Anims.Size()==0);  // It doesn't make sense to have statically given tangent-space axes with *animated* geometry... 
    656661        goto DoneComputingTS; 
    657662    } 
    658663 
    659664    // For all vertices, zero the tangent-space vectors for the subsequent average accumulation. 
    660     for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
    661     { 
    662         MeshT& Mesh=m_Meshes[MeshNr]; 
    663  
    664         for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    665         { 
    666             MeshT::VertexT& Vertex=Mesh.Vertices[VertexNr]; 
    667  
    668             Vertex.Draw_Normal  =Vector3fT(0, 0, 0); 
    669             Vertex.Draw_Tangent =Vector3fT(0, 0, 0); 
    670             Vertex.Draw_BiNormal=Vector3fT(0, 0, 0); 
     665    for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 
     666    { 
     667        MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 
     668 
     669        for (unsigned long VertexNr=0; VertexNr<MeshInfo.Vertices.Size(); VertexNr++) 
     670        { 
     671            MeshInfoT::VertexT& VertexInfo=MeshInfo.Vertices[VertexNr]; 
     672 
     673            VertexInfo.Normal  =Vector3fT(0, 0, 0); 
     674            VertexInfo.Tangent =Vector3fT(0, 0, 0); 
     675            VertexInfo.BiNormal=Vector3fT(0, 0, 0); 
    671676        } 
    672677    } 
    673678 
    674679    // Compute the per-triangle tangent-space axes and distribute them over the relevant vertices appropriately. 
    675     for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
    676     { 
    677         const CafuModelT::MeshT& Mesh=m_Model.GetMeshes()[MeshNr]; 
    678         MeshT& DrawMesh=m_Meshes[MeshNr]; 
     680    for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 
     681    { 
     682        const MeshT& Mesh    =Meshes[MeshNr]; 
     683        MeshInfoT&   MeshInfo=m_MeshInfos[MeshNr]; 
    679684 
    680685        for (unsigned long TriangleNr=0; TriangleNr<Mesh.Triangles.Size(); TriangleNr++) 
    681686        { 
    682             const CafuModelT::MeshT::TriangleT& Tri=Mesh.Triangles[TriangleNr]; 
    683             const CafuModelT::MeshT::VertexT&   V_0=Mesh.Vertices[Tri.VertexIdx[0]]; 
    684             const CafuModelT::MeshT::VertexT&   V_1=Mesh.Vertices[Tri.VertexIdx[1]]; 
    685             const CafuModelT::MeshT::VertexT&   V_2=Mesh.Vertices[Tri.VertexIdx[2]]; 
    686  
    687             MeshT::TriangleT& DrawTri=DrawMesh.Triangles[TriangleNr]; 
    688             MeshT::VertexT&   DrawV_0=DrawMesh.Vertices[Tri.VertexIdx[0]]; 
    689             MeshT::VertexT&   DrawV_1=DrawMesh.Vertices[Tri.VertexIdx[1]]; 
    690             MeshT::VertexT&   DrawV_2=DrawMesh.Vertices[Tri.VertexIdx[2]]; 
    691  
    692             const Vector3fT Edge01=DrawV_1.Draw_Pos-DrawV_0.Draw_Pos; 
    693             const Vector3fT Edge02=DrawV_2.Draw_Pos-DrawV_0.Draw_Pos; 
     687            const MeshT::TriangleT& Tri=Mesh.Triangles[TriangleNr]; 
     688            const MeshT::VertexT&   V_0=Mesh.Vertices[Tri.VertexIdx[0]]; 
     689            const MeshT::VertexT&   V_1=Mesh.Vertices[Tri.VertexIdx[1]]; 
     690            const MeshT::VertexT&   V_2=Mesh.Vertices[Tri.VertexIdx[2]]; 
     691 
     692            MeshInfoT::TriangleT&   TriInfo=MeshInfo.Triangles[TriangleNr]; 
     693            MeshInfoT::VertexT&     V_0Info=MeshInfo.Vertices[Tri.VertexIdx[0]]; 
     694            MeshInfoT::VertexT&     V_1Info=MeshInfo.Vertices[Tri.VertexIdx[1]]; 
     695            MeshInfoT::VertexT&     V_2Info=MeshInfo.Vertices[Tri.VertexIdx[2]]; 
     696 
     697            const Vector3fT         Edge01=V_1Info.Pos-V_0Info.Pos; 
     698            const Vector3fT         Edge02=V_2Info.Pos-V_0Info.Pos; 
    694699 
    695700            // Triangles are ordered CW for md5 models and CCW for ase models, so we write 
    696701            // Normal=VectorCross(Edge02, Edge01) for md5 models and Normal=VectorCross(Edge01, Edge02) for ase models. 
    697             DrawTri.Draw_Normal=myNormalize(Edge02.cross(Edge01)); 
     702            TriInfo.Normal=myNormalize(Edge02.cross(Edge01)); 
    698703 
    699704            // Understanding what's going on here is easy. The key statement is 
     
    705710            const float     f   =uv01.x*uv02.y-uv01.y*uv02.x>0.0 ? 1.0f : -1.0f; 
    706711 
    707             const Vector3fT Tri_Draw_Tangent =myNormalize(Edge02.GetScaled(-uv01.y*f) + Edge01.GetScaled(uv02.y*f)); 
    708             const Vector3fT Tri_Draw_BiNormal=myNormalize(Edge02.GetScaled( uv01.x*f) - Edge01.GetScaled(uv02.x*f)); 
     712            const Vector3fT TriInfo_Draw_Tangent =myNormalize(Edge02.GetScaled(-uv01.y*f) + Edge01.GetScaled(uv02.y*f)); 
     713            const Vector3fT TriInfo_Draw_BiNormal=myNormalize(Edge02.GetScaled( uv01.x*f) - Edge01.GetScaled(uv02.x*f)); 
    709714 
    710715 
     
    714719 
    715720            const float c0=dot(myNormalize(Edge01), myNormalize(Edge02)); 
    716             const float c1=dot(myNormalize(Edge01), myNormalize(DrawV_1.Draw_Pos-DrawV_2.Draw_Pos)); 
     721            const float c1=dot(myNormalize(Edge01), myNormalize(V_1Info.Pos-V_2Info.Pos)); 
    717722 
    718723            const float w0=(c0>=1.0f) ? 0.0f : ( (c0<=-1.0f) ? Pi : acos(c0) ); 
     
    726731            for (int i=0; i<3; i++) 
    727732            { 
    728                 const CafuModelT::MeshT::VertexT& Vertex=Mesh.Vertices[Tri.VertexIdx[i]]; 
    729                 MeshT::VertexT& DrawVertex=DrawMesh.Vertices[Tri.VertexIdx[i]]; 
     733                const MeshT::VertexT& Vertex    =Mesh.Vertices[Tri.VertexIdx[i]]; 
     734                MeshInfoT::VertexT&   VertexInfo=MeshInfo.Vertices[Tri.VertexIdx[i]]; 
    730735 
    731736                assert(Tri.Polarity==Vertex.Polarity); 
    732737 
    733                 DrawVertex.Draw_Normal  +=DrawTri.Draw_Normal*TriWeight[i]; 
    734                 DrawVertex.Draw_Tangent +=Tri_Draw_Tangent*TriWeight[i]; 
    735                 DrawVertex.Draw_BiNormal+=Tri_Draw_BiNormal*TriWeight[i]; 
     738                VertexInfo.Normal  +=TriInfo.Normal*TriWeight[i]; 
     739                VertexInfo.Tangent +=TriInfo_Draw_Tangent*TriWeight[i]; 
     740                VertexInfo.BiNormal+=TriInfo_Draw_BiNormal*TriWeight[i]; 
    736741 
    737742                for (unsigned long DupNr=0; DupNr<Vertex.GeoDups.Size(); DupNr++) 
    738743                { 
    739                     const CafuModelT::MeshT::VertexT& DupVertex=Mesh.Vertices[Vertex.GeoDups[DupNr]]; 
    740                     MeshT::VertexT&                   DrawDupVertex=DrawMesh.Vertices[Vertex.GeoDups[DupNr]]; 
    741  
    742                     DrawDupVertex.Draw_Normal  +=DrawTri.Draw_Normal*TriWeight[i]; 
    743                     DrawDupVertex.Draw_Tangent +=Tri_Draw_Tangent*(Tri.Polarity==DupVertex.Polarity ? TriWeight[i] : -TriWeight[i]); 
    744                     DrawDupVertex.Draw_BiNormal+=Tri_Draw_BiNormal*TriWeight[i]; 
     744                    const MeshT::VertexT& DupVertex    =Mesh.Vertices[Vertex.GeoDups[DupNr]]; 
     745                    MeshInfoT::VertexT&   DupVertexInfo=MeshInfo.Vertices[Vertex.GeoDups[DupNr]]; 
     746 
     747                    DupVertexInfo.Normal  +=TriInfo.Normal*TriWeight[i]; 
     748                    DupVertexInfo.Tangent +=TriInfo_Draw_Tangent*(Tri.Polarity==DupVertex.Polarity ? TriWeight[i] : -TriWeight[i]); 
     749                    DupVertexInfo.BiNormal+=TriInfo_Draw_BiNormal*TriWeight[i]; 
    745750                } 
    746751            } 
     
    749754 
    750755    // Finally normalize the per-vertex tangent-space axes; this is quasi the "division" in the average computations. 
    751     for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
    752     { 
    753         MeshT& Mesh=m_Meshes[MeshNr]; 
    754  
    755         for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 
    756         { 
    757             MeshT::VertexT& Vertex=Mesh.Vertices[VertexNr]; 
     756    for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 
     757    { 
     758        MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 
     759 
     760        for (unsigned long VertexNr=0; VertexNr<MeshInfo.Vertices.Size(); VertexNr++) 
     761        { 
     762            MeshInfoT::VertexT& VertexInfo=MeshInfo.Vertices[VertexNr]; 
    758763 
    759764            // Normalize the tangent-space axes. 
    760             Vertex.Draw_Normal  =myNormalize(Vertex.Draw_Normal  ); 
    761             Vertex.Draw_Tangent =myNormalize(Vertex.Draw_Tangent ); 
    762             Vertex.Draw_BiNormal=myNormalize(Vertex.Draw_BiNormal); 
     765            VertexInfo.Normal  =myNormalize(VertexInfo.Normal  ); 
     766            VertexInfo.Tangent =myNormalize(VertexInfo.Tangent ); 
     767            VertexInfo.BiNormal=myNormalize(VertexInfo.BiNormal); 
    763768        } 
    764769    } 
     
    772777    // *************************************************************************************************************** 
    773778 
    774     for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
    775     { 
    776         const CafuModelT::MeshT& Mesh    =m_Model.GetMeshes()[MeshNr]; 
    777         const AnimPoseT::MeshT&  DrawMesh=m_Meshes[MeshNr]; 
     779    for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 
     780    { 
     781        const MeshT&     Mesh    =Meshes[MeshNr]; 
     782        const MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 
    778783 
    779784        for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) 
     
    781786            for (unsigned long i=0; i<3; i++) 
    782787            { 
    783                 unsigned long VertexIdx=Mesh.Triangles[TriNr].VertexIdx[i]; 
    784                 const MeshT::VertexT& DrawVertex=DrawMesh.Vertices[VertexIdx]; 
    785  
    786                 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetOrigin(DrawVertex.Draw_Pos.x, DrawVertex.Draw_Pos.y, DrawVertex.Draw_Pos.z); 
     788                const unsigned long       VertexIdx =Mesh.Triangles[TriNr].VertexIdx[i]; 
     789                const MeshInfoT::VertexT& VertexInfo=MeshInfo.Vertices[VertexIdx]; 
     790 
     791                m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetOrigin(VertexInfo.Pos.x, VertexInfo.Pos.y, VertexInfo.Pos.z); 
    787792                m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetTextureCoord(Mesh.Vertices[VertexIdx].u, Mesh.Vertices[VertexIdx].v); 
    788                 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetNormal  (DrawVertex.Draw_Normal.x,   DrawVertex.Draw_Normal.y,   DrawVertex.Draw_Normal.z  ); 
    789                 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetTangent (DrawVertex.Draw_Tangent.x,  DrawVertex.Draw_Tangent.y,  DrawVertex.Draw_Tangent.z ); 
    790                 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetBiNormal(DrawVertex.Draw_BiNormal.x, DrawVertex.Draw_BiNormal.y, DrawVertex.Draw_BiNormal.z); 
     793                m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetNormal  (VertexInfo.Normal.x,   VertexInfo.Normal.y,   VertexInfo.Normal.z  ); 
     794                m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetTangent (VertexInfo.Tangent.x,  VertexInfo.Tangent.y,  VertexInfo.Tangent.z ); 
     795                m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetBiNormal(VertexInfo.BiNormal.x, VertexInfo.BiNormal.y, VertexInfo.BiNormal.z); 
    791796            } 
    792797        } 
     
    800805    m_BoundingBox=BoundingBox3fT(); 
    801806 
    802     for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 
    803     { 
    804         const MeshT& DrawMesh=m_Meshes[MeshNr]; 
    805  
    806         for (unsigned long VertexNr=0; VertexNr<DrawMesh.Vertices.Size(); VertexNr++) 
    807             m_BoundingBox+=DrawMesh.Vertices[VertexNr].Draw_Pos; 
     807    for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 
     808    { 
     809        const MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 
     810 
     811        for (unsigned long VertexNr=0; VertexNr<MeshInfo.Vertices.Size(); VertexNr++) 
     812            m_BoundingBox+=MeshInfo.Vertices[VertexNr].Pos; 
    808813    } 
    809814} 
  • cafu/trunk/Libs/Models/AnimPose.hpp

    r400 r401  
    133133 
    134134    /// The instances of this struct parallel and augment the \c CafuModelT::MeshT instances in the related \c CafuModelT. 
    135     struct MeshT 
     135    struct MeshInfoT 
    136136    { 
    137137        struct TriangleT 
    138138        { 
    139             Vector3fT Draw_Normal;      ///< The normal vector of this triangle, required for the shadow-silhouette determination. 
     139            Vector3fT Normal;       ///< The normal vector of this triangle, required for the shadow-silhouette determination. 
    140140        }; 
    141141 
    142142        struct VertexT 
    143143        { 
    144             Vector3fT Draw_Pos;         ///< The spatial position of this vertex. 
    145             Vector3fT Draw_Normal;      ///< The tangent-space normal   vector of this vertex. 
    146             Vector3fT Draw_Tangent;     ///< The tangent-space tangent  vector of this vertex. 
    147             Vector3fT Draw_BiNormal;    ///< The tangent-space binormal vector of this vertex. 
     144            Vector3fT Pos;          ///< The spatial position of this vertex. 
     145            Vector3fT Normal;       ///< The tangent-space normal   vector of this vertex. 
     146            Vector3fT Tangent;      ///< The tangent-space tangent  vector of this vertex. 
     147            Vector3fT BiNormal;     ///< The tangent-space binormal vector of this vertex. 
    148148        }; 
    149149 
     
    158158    void Recache() const; 
    159159 
    160     const CafuModelT&     m_Model; 
    161     int                   m_SequNr;             ///< The animation sequence number at which we have computed the cache data. 
    162     float                 m_FrameNr;            ///< The animation frame    number at which we have computed the cache data. 
    163     const SuperT*         m_Super; 
    164  // ArrayT<...>           m_Def;                ///< Array of { channel, sequence, framenr, (forceloop), blendweight } tuples. 
    165  // bool                  m_DoCache;            ///< Cache the computed data? (Set to true by the user if he want to re-use this instance.) 
     160    const CafuModelT&             m_Model;              ///< The related model that this is a pose for. 
     161    int                           m_SequNr;             ///< The animation sequence number at which we have computed the cache data. 
     162    float                         m_FrameNr;            ///< The animation frame    number at which we have computed the cache data. 
     163    const SuperT*                 m_Super; 
     164 // ArrayT<...>                   m_Def;                ///< Array of { channel, sequence, framenr, (forceloop), blendweight } tuples. 
     165 // bool                          m_DoCache;            ///< Cache the computed data? (Set to true by the user if he want to re-use this instance.) 
    166166 
    167167    mutable bool                  m_NeedsRecache;       ///< wird auf 'true' gesetzt wann immer SetSequ(), SetFrameNr() oder AdvanceAll() o.ä. aufgerufen wird, übernimmt m_Draw_CachedDataAt*Nr Funktionalität. 
    168168    mutable ArrayT<MatrixT>       m_JointMatrices;      ///< The transformation matrices that represent the pose of the skeleton at the given animation sequence and frame number. 
    169     mutable ArrayT<MeshT>         m_Meshes; 
    170     mutable ArrayT<MatSys::MeshT> m_Draw_Meshes;        ///< The draw meshes resulting from m_JointMatrices. 
    171     mutable BoundingBox3fT        m_BoundingBox; 
     169    mutable ArrayT<MeshInfoT>     m_MeshInfos;          ///< Additional data for each mesh in m_Model. 
     170    mutable ArrayT<MatSys::MeshT> m_Draw_Meshes;        ///< The draw meshes resulting from the m_JointMatrices. 
     171    mutable BoundingBox3fT        m_BoundingBox;        ///< The bounding-box for the model in this pose. 
    172172}; 
    173173