Changeset 402 for cafu/trunk

Show
Ignore:
Timestamp:
10/09/11 12:17:14 (8 months ago)
Author:
Carsten
Message:

Model Editor: Added support for rendering

  • the normal vectors of the mesh triangles, with the color of the normal indicating the polarity of the triangle,
  • the tangent-space axes at each vertex.

References #90.

Location:
cafu/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • cafu/trunk/CaWE/ModelEditor/ScenePropGrid.cpp

    r400 r402  
    5151      m_Model_ShowMesh(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/Model_ShowMesh", 1l)!=0), 
    5252      m_Model_ShowSkeleton(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/Model_ShowSkeleton", 0l)!=0), 
     53      m_Model_ShowTriangleNormals(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/Model_ShowTriangleNormals", 0l)!=0), 
     54      m_Model_ShowTangentSpace(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/Model_ShowTangentSpace", 0l)!=0), 
    5355      m_AmbientLightColor(wxColour(wxConfigBase::Get()->Read("ModelEditor/SceneSetup/AmbientLightColor", "rgb(96, 96, 96)"))), 
    5456      m_AmbientTexture(NULL), 
     
    129131    AppendIn(ModelProps, new wxBoolProperty("Show Mesh", wxPG_LABEL, m_Model_ShowMesh)); 
    130132    AppendIn(ModelProps, new wxBoolProperty("Show Skeleton", wxPG_LABEL, m_Model_ShowSkeleton)); 
     133    AppendIn(ModelProps, new wxBoolProperty("Show triangle normals", wxPG_LABEL, m_Model_ShowTriangleNormals)); 
     134    AppendIn(ModelProps, new wxBoolProperty("Show tangent-space", wxPG_LABEL, m_Model_ShowTangentSpace)); 
    131135 
    132136 
     
    216220        } 
    217221    } 
    218     else if (PropName=="Model.Show Mesh")     m_Model_ShowMesh    =Prop->GetValue().GetBool(); 
    219     else if (PropName=="Model.Show Skeleton") m_Model_ShowSkeleton=Prop->GetValue().GetBool(); 
     222    else if (PropName=="Model.Show Mesh")             m_Model_ShowMesh           =Prop->GetValue().GetBool(); 
     223    else if (PropName=="Model.Show Skeleton")         m_Model_ShowSkeleton       =Prop->GetValue().GetBool(); 
     224    else if (PropName=="Model.Show triangle normals") m_Model_ShowTriangleNormals=Prop->GetValue().GetBool(); 
     225    else if (PropName=="Model.Show tangent-space")    m_Model_ShowTangentSpace   =Prop->GetValue().GetBool(); 
    220226    else if (PropName=="Frame No.") { AnimState.Pose.SetFrameNr(PropValueF); m_IsRecursiveSelfNotify=true; m_Parent->GetModelDoc()->UpdateAllObservers_AnimStateChanged(); m_IsRecursiveSelfNotify=false; } 
    221227    else if (PropName=="Speed")     { AnimState.Speed=PropValueF; m_IsRecursiveSelfNotify=true; m_Parent->GetModelDoc()->UpdateAllObservers_AnimStateChanged(); m_IsRecursiveSelfNotify=false; } 
  • cafu/trunk/CaWE/ModelEditor/ScenePropGrid.hpp

    r381 r402  
    5858        bool                 m_Model_ShowMesh; 
    5959        bool                 m_Model_ShowSkeleton; 
     60        bool                 m_Model_ShowTriangleNormals; 
     61        bool                 m_Model_ShowTangentSpace; 
    6062        wxColour             m_AmbientLightColor; 
    6163        MatSys::TextureMapI* m_AmbientTexture;    ///< A uniform 2x2 texture colored in the ambient light color, used as lightmap for the ground plane. 
  • cafu/trunk/CaWE/ModelEditor/SceneView3D.cpp

    r400 r402  
    411411 
    412412 
     413    // Render the triangle normals and/or the tangent-space axes of the model in this pose. 
     414    if ((ScenePropGrid->m_Model_ShowTriangleNormals || ScenePropGrid->m_Model_ShowTangentSpace) && MatSys::Renderer->GetCurrentRenderAction()==MatSys::RendererI::AMBIENT) 
     415    { 
     416        static MatSys::MeshT TangentSpace(MatSys::MeshT::Lines); 
     417 
     418        TangentSpace.Vertices.Overwrite(); 
     419 
     420        for (unsigned long MeshNr=0; MeshNr<Model->GetMeshes().Size(); MeshNr++) 
     421        { 
     422            const CafuModelT::MeshT&    Mesh    =Model->GetMeshes()[MeshNr]; 
     423            const AnimPoseT::MeshInfoT& MeshInfo=Anim.Pose.GetMeshInfos()[MeshNr]; 
     424 
     425            for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) 
     426            { 
     427                const CafuModelT::MeshT::TriangleT& Tri=Mesh.Triangles[TriNr]; 
     428                Vector3fT Center; 
     429 
     430                for (unsigned int i=0; i<3; i++) 
     431                { 
     432                    const AnimPoseT::MeshInfoT::VertexT& VertexInfo=MeshInfo.Vertices[Tri.VertexIdx[i]]; 
     433 
     434                    Center+=VertexInfo.Pos; 
     435 
     436                    if (ScenePropGrid->m_Model_ShowTangentSpace) 
     437                    { 
     438                        // Render the tangent-space axes at each vertex. 
     439                        for (unsigned int AxisNr=0; AxisNr<3; AxisNr++) 
     440                        { 
     441                            Vector3fT Axis; Axis[AxisNr]=1.0f; 
     442 
     443                            TangentSpace.Vertices.PushBackEmpty(2); 
     444                            MatSys::MeshT::VertexT& V1=TangentSpace.Vertices[TangentSpace.Vertices.Size()-2]; 
     445                            MatSys::MeshT::VertexT& V2=TangentSpace.Vertices[TangentSpace.Vertices.Size()-1]; 
     446 
     447                            V1.SetOrigin(VertexInfo.Pos); 
     448                            V1.SetColor(Axis.x, Axis.y, Axis.z); 
     449 
     450                            const Vector3fT Vec=(AxisNr==0) ? VertexInfo.Normal : 
     451                                                (AxisNr==1) ? VertexInfo.Tangent : 
     452                                                              VertexInfo.BiNormal; 
     453 
     454                            V2.SetOrigin(VertexInfo.Pos + Vec); 
     455                            V2.SetColor(Axis.x, Axis.y, Axis.z); 
     456                        } 
     457                    } 
     458                } 
     459 
     460                // Render the triangle's normal vector. 
     461                if (ScenePropGrid->m_Model_ShowTriangleNormals) 
     462                { 
     463                    Center/=3.0f; 
     464 
     465                    TangentSpace.Vertices.PushBackEmpty(2); 
     466                    MatSys::MeshT::VertexT& V1=TangentSpace.Vertices[TangentSpace.Vertices.Size()-2]; 
     467                    MatSys::MeshT::VertexT& V2=TangentSpace.Vertices[TangentSpace.Vertices.Size()-1]; 
     468 
     469                    V1.SetOrigin(Center); 
     470                    V1.SetColor(0.5f, Tri.Polarity ? 0 : 0.5f, 0); 
     471 
     472                    V2.SetOrigin(Center + MeshInfo.Triangles[TriNr].Normal); 
     473                    V2.SetColor(0.5f, Tri.Polarity ? 0 : 0.5f, 0); 
     474                } 
     475            } 
     476        } 
     477 
     478        MatSys::Renderer->SetCurrentMaterial(m_Renderer.GetRMatWireframe()); 
     479        MatSys::Renderer->RenderMesh(TangentSpace); 
     480    } 
     481 
     482 
    413483    // Render the GUI fixtures. 
    414484    if (MatSys::Renderer->GetCurrentRenderAction()==MatSys::RendererI::AMBIENT) 
     
    425495                if (!Model->IsVertexNrOK(GF, PointNr)) continue; 
    426496 
    427                 Points[PointNr]=Anim.Pose.GetVertexPos(GF.Points[PointNr].MeshNr, GF.Points[PointNr].VertexNr); 
     497                Points[PointNr]=Anim.Pose.GetMeshInfos()[GF.Points[PointNr].MeshNr].Vertices[GF.Points[PointNr].VertexNr].Pos; 
    428498                PointsOK|=(1 << PointNr); 
    429499            } 
  • cafu/trunk/Libs/Models/AnimPose.cpp

    r401 r402  
    3737      m_BoundingBox() 
    3838{ 
     39    NormalizeInput(); 
    3940} 
    4041 
     
    135136                MatSys::Renderer->SetCurrentMaterial(m_Model.GetRenderMaterial(MeshNr, SkinNr)); 
    136137                MatSys::Renderer->RenderMesh(m_Draw_Meshes[MeshNr]); 
    137  
    138 #if 0 
    139                 // Render the tangent space axes for each vertex. 
    140                 static MaterialT SolidColorMaterial; 
    141                 SolidColorMaterial.UseMeshColors=true; 
    142  
    143                 static MatSys::MeshT TangentSpaceAxes(MatSys::MeshT::Lines); 
    144                 TangentSpaceAxes.Vertices.Overwrite(); 
    145  
    146                 for (unsigned long VertexNr=0; VertexNr<m_Draw_Meshes[MeshNr].Vertices.Size(); VertexNr++) 
    147                 { 
    148                     const float         scale=1.0f; 
    149                     const Vector3fT     Orig =Vector3fT(m_Draw_Meshes[MeshNr].Vertices[VertexNr].Origin); 
    150                     const Vector3fT     S_   =Vector3fT(m_Draw_Meshes[MeshNr].Vertices[VertexNr].Tangent); 
    151                     const Vector3fT     T_   =Vector3fT(m_Draw_Meshes[MeshNr].Vertices[VertexNr].BiNormal); 
    152                     const Vector3fT     N_   =Vector3fT(m_Draw_Meshes[MeshNr].Vertices[VertexNr].Normal); 
    153                     const float         col_ =m_Meshes[MeshNr].Triangles[VertexNr / 3].Polarity ? 0.5f : 0.0f; 
    154                     const unsigned long Ofs  =TangentSpaceAxes.Vertices.Size(); 
    155  
    156                     TangentSpaceAxes.Vertices.PushBackEmpty(6); 
    157  
    158                     TangentSpaceAxes.Vertices[Ofs+0].SetOrigin(Orig); 
    159                     TangentSpaceAxes.Vertices[Ofs+0].SetColor(1, col_, col_); 
    160                     TangentSpaceAxes.Vertices[Ofs+1].SetOrigin(Orig+S_*scale); 
    161                     TangentSpaceAxes.Vertices[Ofs+1].SetColor(1, col_, col_); 
    162  
    163                     TangentSpaceAxes.Vertices[Ofs+2].SetOrigin(Orig); 
    164                     TangentSpaceAxes.Vertices[Ofs+2].SetColor(col_, 1, col_); 
    165                     TangentSpaceAxes.Vertices[Ofs+3].SetOrigin(Orig+T_*scale); 
    166                     TangentSpaceAxes.Vertices[Ofs+3].SetColor(col_, 1, col_); 
    167  
    168                     TangentSpaceAxes.Vertices[Ofs+4].SetOrigin(Orig); 
    169                     TangentSpaceAxes.Vertices[Ofs+4].SetColor(col_, col_, 1); 
    170                     TangentSpaceAxes.Vertices[Ofs+5].SetOrigin(Orig+N_*scale); 
    171                     TangentSpaceAxes.Vertices[Ofs+5].SetColor(col_, col_, 1); 
    172                 } 
    173  
    174                 MatSys::RenderMaterialT* SolidColorRenderMat=MatSys::Renderer->RegisterMaterial(&SolidColorMaterial); 
    175  
    176                 MatSys::Renderer->SetCurrentMaterial(SolidColorRenderMat); 
    177                 MatSys::Renderer->RenderMesh(TangentSpaceAxes); 
    178  
    179                 MatSys::Renderer->FreeMaterial(SolidColorRenderMat); 
    180  
    181                 // FIXME! Rendering the stencil shadows uses the same material as the ambient pass does! 
    182                 // (The call to FreeMaterial() above implies that no material is being set, and thus without this line, 
    183                 //  no stencil shadows get rendered!) 
    184                 MatSys::Renderer->SetCurrentMaterial(m_Meshes[MeshNr].RenderMaterial); 
    185 #endif 
    186138            } 
    187139            break; 
     
    416368 
    417369 
    418 const Vector3fT& AnimPoseT::GetVertexPos(unsigned int MeshNr, unsigned int VertexNr) const 
     370const ArrayT<MatrixT>& AnimPoseT::GetJointMatrices() const 
    419371{ 
    420372    Recache(); 
    421373 
    422     return m_MeshInfos[MeshNr].Vertices[VertexNr].Pos; 
    423 } 
    424  
    425  
    426 const ArrayT<MatrixT>& AnimPoseT::GetJointMatrices() const 
     374    return m_JointMatrices; 
     375} 
     376 
     377 
     378const ArrayT<AnimPoseT::MeshInfoT>& AnimPoseT::GetMeshInfos() const 
    427379{ 
    428380    Recache(); 
    429381 
    430     return m_JointMatrices; 
     382    return m_MeshInfos; 
    431383} 
    432384 
     
    710662            const float     f   =uv01.x*uv02.y-uv01.y*uv02.x>0.0 ? 1.0f : -1.0f; 
    711663 
    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)); 
     664            const Vector3fT TriInfo_Tangent =myNormalize(Edge02.GetScaled(-uv01.y*f) + Edge01.GetScaled(uv02.y*f)); 
     665            const Vector3fT TriInfo_BiNormal=myNormalize(Edge02.GetScaled( uv01.x*f) - Edge01.GetScaled(uv02.x*f)); 
    714666 
    715667 
     
    737689 
    738690                VertexInfo.Normal  +=TriInfo.Normal*TriWeight[i]; 
    739                 VertexInfo.Tangent +=TriInfo_Draw_Tangent*TriWeight[i]; 
    740                 VertexInfo.BiNormal+=TriInfo_Draw_BiNormal*TriWeight[i]; 
     691                VertexInfo.Tangent +=TriInfo_Tangent*TriWeight[i]; 
     692                VertexInfo.BiNormal+=TriInfo_BiNormal*TriWeight[i]; 
    741693 
    742694                for (unsigned long DupNr=0; DupNr<Vertex.GeoDups.Size(); DupNr++) 
     
    746698 
    747699                    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]; 
     700                    DupVertexInfo.Tangent +=TriInfo_Tangent*(Tri.Polarity==DupVertex.Polarity ? TriWeight[i] : -TriWeight[i]); 
     701                    DupVertexInfo.BiNormal+=TriInfo_BiNormal*TriWeight[i]; 
    750702                } 
    751703            } 
  • cafu/trunk/Libs/Models/AnimPose.hpp

    r401 r402  
    5353{ 
    5454    public: 
     55 
     56    /// The instances of this struct parallel and augment the \c CafuModelT::MeshT instances in the related \c CafuModelT. 
     57    struct MeshInfoT 
     58    { 
     59        struct TriangleT 
     60        { 
     61            Vector3fT Normal;       ///< The normal vector of this triangle, required for the shadow-silhouette determination. 
     62        }; 
     63 
     64        struct VertexT 
     65        { 
     66            Vector3fT Pos;          ///< The spatial position of this vertex. 
     67            Vector3fT Normal;       ///< The tangent-space normal   vector of this vertex. 
     68            Vector3fT Tangent;      ///< The tangent-space tangent  vector of this vertex. 
     69            Vector3fT BiNormal;     ///< The tangent-space binormal vector of this vertex. 
     70        }; 
     71 
     72        ArrayT<TriangleT> Triangles; 
     73        ArrayT<VertexT>   Vertices; 
     74    }; 
     75 
    5576 
    5677    /// This struct describes information about a parent or "super" model whose skeleton pose 
     
    117138    unsigned int FindClosestVertex(unsigned int MeshNr, unsigned int TriNr, const Vector3fT& P) const; 
    118139 
    119     /// Returns the spatial position of the given vertex in the specified mesh. 
    120     const Vector3fT& GetVertexPos(unsigned int MeshNr, unsigned int VertexNr) const; 
    121  
    122     /// This method returns the set of transformation matrices (one per joint) at the given sequence and frame number. 
     140    /// Returns the set of transformation matrices (one per joint) at the given sequence and frame number. 
    123141    const ArrayT<MatrixT>& GetJointMatrices() const; 
    124142 
    125     /// This method returns the MatSys meshes for this pose. 
     143    /// Returns the mesh infos with additional data for each mesh in this pose. 
     144    const ArrayT<MeshInfoT>& GetMeshInfos() const; 
     145 
     146    /// Returns the MatSys meshes for this pose. 
    126147    const ArrayT<MatSys::MeshT>& GetDrawMeshes() const; 
    127148 
    128     /// This method returns the bounding-box for this pose. 
     149    /// Returns the bounding-box for this pose. 
    129150    const BoundingBox3fT& GetBB() const; 
    130151 
    131152 
    132153    private: 
    133  
    134     /// The instances of this struct parallel and augment the \c CafuModelT::MeshT instances in the related \c CafuModelT. 
    135     struct MeshInfoT 
    136     { 
    137         struct TriangleT 
    138         { 
    139             Vector3fT Normal;       ///< The normal vector of this triangle, required for the shadow-silhouette determination. 
    140         }; 
    141  
    142         struct VertexT 
    143         { 
    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. 
    148         }; 
    149  
    150         ArrayT<TriangleT> Triangles; 
    151         ArrayT<VertexT>   Vertices; 
    152     }; 
    153  
    154154 
    155155    void NormalizeInput(); 
     
    158158    void Recache() const; 
    159159 
    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. 
     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. 
    163163    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.) 
     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 
    167     mutable bool                  m_NeedsRecache;       ///< wird auf 'true' gesetzt wann immer SetSequ(), SetFrameNr() oder AdvanceAll() o.ä. aufgerufen wird, übernimmt m_Draw_CachedDataAt*Nr Funktionalität. 
    168     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<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. 
     167    mutable bool                  m_NeedsRecache;   ///< wird auf 'true' gesetzt wann immer SetSequ(), SetFrameNr() oder AdvanceAll() o.ä. aufgerufen wird, übernimmt m_Draw_CachedDataAt*Nr Funktionalität. 
     168    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<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