Changeset 429 for cafu/trunk

Show
Ignore:
Timestamp:
11/23/11 10:59:48 (6 months ago)
Author:
Carsten
Message:

Model code:
Added support for skipping triangles when drawing the mesh (but not for casting stencil shadows and not for collision detection).
This is useful for hiding triangles that are in the same plane as GUI panels and would otherwise cause z-fighting.

Location:
cafu/trunk
Files:
2 added
7 modified

Legend:

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

    r428 r429  
    2525#include "ScenePropGrid.hpp" 
    2626#include "Commands/UpdateGuiFixture.hpp" 
     27#include "Commands/UpdateTriangle.hpp" 
    2728#include "../AppCaWE.hpp" 
    2829#include "../Camera.hpp" 
     
    228229        ID_MENU_SET_GUIFIX_ORIGIN, 
    229230        ID_MENU_SET_GUIFIX_ENDPOINT_X, 
    230         ID_MENU_SET_GUIFIX_ENDPOINT_Y 
     231        ID_MENU_SET_GUIFIX_ENDPOINT_Y, 
     232        ID_MENU_TRIANGLE_INFO, 
     233        ID_MENU_TRIANGLE_SKIPDRAW 
    231234    }; 
    232235 
     
    244247    } 
    245248 
     249 
    246250    wxMenu Menu; 
    247251    const ArrayT<unsigned int>& Sel=m_Parent->GetModelDoc()->GetSelection(GFIX); 
     
    269273    } 
    270274 
    271     const int PointNr=GetPopupMenuSelectionFromUser(Menu)-ID_MENU_SET_GUIFIX_ORIGIN; 
    272  
    273     if (HaveModelHit && PointNr>=0 && PointNr<=2) 
    274     { 
    275         CafuModelT::GuiFixtureT GF=Model->GetGuiFixtures()[Sel[0]]; 
    276  
    277         GF.Points[PointNr].MeshNr  =ModelTR.MeshNr; 
    278         GF.Points[PointNr].VertexNr=BestVertexNr; 
    279  
    280         m_Parent->SubmitCommand(new CommandUpdateGuiFixtureT(m_Parent->GetModelDoc(), Sel[0], GF)); 
     275    if (HaveModelHit) 
     276    { 
     277        const bool SkipDraw=Model->GetMeshes()[ModelTR.MeshNr].Triangles[ModelTR.TriNr].SkipDraw; 
     278 
     279        Menu.AppendSeparator(); 
     280        Menu.Append(ID_MENU_TRIANGLE_INFO, wxString::Format("Mesh %u, Triangle %u:", ModelTR.MeshNr, ModelTR.TriNr))->Enable(false); 
     281        Menu.AppendCheckItem(ID_MENU_TRIANGLE_SKIPDRAW, "Hide Triangle (skip drawing)")->Check(SkipDraw); 
     282    } 
     283 
     284 
     285    const int MenuSelID=GetPopupMenuSelectionFromUser(Menu); 
     286 
     287    switch (MenuSelID) 
     288    { 
     289        case ID_MENU_TRIANGLE_SKIPDRAW: 
     290        { 
     291            if (HaveModelHit) 
     292            { 
     293                const bool SkipDraw=Model->GetMeshes()[ModelTR.MeshNr].Triangles[ModelTR.TriNr].SkipDraw; 
     294 
     295                m_Parent->SubmitCommand(new CommandUpdateTriangleT(m_Parent->GetModelDoc(), ModelTR.MeshNr, ModelTR.TriNr, !SkipDraw)); 
     296            } 
     297        } 
     298 
     299        default: 
     300        { 
     301            const int PointNr=MenuSelID-ID_MENU_SET_GUIFIX_ORIGIN; 
     302 
     303            if (HaveModelHit && PointNr>=0 && PointNr<=2) 
     304            { 
     305                CafuModelT::GuiFixtureT GF=Model->GetGuiFixtures()[Sel[0]]; 
     306 
     307                GF.Points[PointNr].MeshNr  =ModelTR.MeshNr; 
     308                GF.Points[PointNr].VertexNr=BestVertexNr; 
     309 
     310                m_Parent->SubmitCommand(new CommandUpdateGuiFixtureT(m_Parent->GetModelDoc(), Sel[0], GF)); 
     311            } 
     312        } 
    281313    } 
    282314} 
  • cafu/trunk/Games/DeathMatch/Code/StaticDetailModel.hpp

    r427 r429  
    7676    float             m_FrameNr;    ///< The current frame of the played animation sequence. Used <em>independently</em> on the server and the clients; only a <em>restart</em> of a sequence is sync'ed over the network via the EventID_RestartSequ event. 
    7777    std::string       GuiName;      ///< If our "gui" entity key is set, store the value here. 
    78     cf::GuiSys::GuiI* Gui;          ///< If the Model can display a GUI (it has a "Textures/meta/EntityGUI" surface), we load it here, *both* on the server- as well as on the client-side. 
     78    cf::GuiSys::GuiI* Gui;          ///< If the model has GUI fixtures, we load the GUI here, *both* on the server- as well as on the client-side. 
    7979 
    8080 
  • cafu/trunk/Libs/MaterialSystem/MapComposition.cpp

    r308 r429  
    712712{ 
    713713    const static MapCompositionT RefMapComp;    // Use a reference object here, just in case we ever change the defaults. 
     714    const std::string            BaseString=GetString(); 
    714715    std::string                  OptionsString=""; 
     716 
     717    if (BaseString=="") 
     718    { 
     719        // If the base string is empty, don't attempt to attach any options. 
     720        return ""; 
     721    } 
    715722 
    716723    if (MinFilter!=RefMapComp.MinFilter) 
     
    779786    } 
    780787 
    781     return GetString() + OptionsString; 
     788    return BaseString + OptionsString; 
    782789} 
    783790 
  • cafu/trunk/Libs/Models/AnimPose.cpp

    r428 r429  
    9191     // m_Draw_Meshes[MeshNr].Winding=MatSys::MeshT::CW;    // CW is the default. 
    9292 
    93         if (m_Draw_Meshes[MeshNr].Vertices.Size()!=Mesh.Triangles.Size()*3) 
     93        unsigned long NumDrawTris=0; 
     94        for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) 
     95            if (!Mesh.Triangles[TriNr].SkipDraw) 
     96                NumDrawTris++; 
     97 
     98        if (m_Draw_Meshes[MeshNr].Vertices.Size()!=NumDrawTris*3) 
    9499        { 
    95100            m_Draw_Meshes[MeshNr].Vertices.Overwrite(); 
    96             m_Draw_Meshes[MeshNr].Vertices.PushBackEmptyExact(Mesh.Triangles.Size()*3); 
     101            m_Draw_Meshes[MeshNr].Vertices.PushBackEmptyExact(NumDrawTris*3); 
    97102        } 
    98103    } 
     
    398403    for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 
    399404    { 
    400         const MeshT&     Mesh    =Meshes[MeshNr]; 
    401         const MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 
     405        const MeshT&     Mesh     =Meshes[MeshNr]; 
     406        const MeshInfoT& MeshInfo =m_MeshInfos[MeshNr]; 
     407        unsigned long    DrawTriNr=0; 
    402408 
    403409        for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) 
    404410        { 
     411            if (Mesh.Triangles[TriNr].SkipDraw) 
     412                continue; 
     413 
    405414            for (unsigned long i=0; i<3; i++) 
    406415            { 
     
    408417                const MeshInfoT::VertexT& VertexInfo=MeshInfo.Vertices[VertexIdx]; 
    409418 
    410                 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetOrigin(VertexInfo.Pos.x, VertexInfo.Pos.y, VertexInfo.Pos.z); 
    411                 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetTextureCoord(Mesh.Vertices[VertexIdx].u, Mesh.Vertices[VertexIdx].v); 
    412                 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetNormal  (VertexInfo.Normal.x,   VertexInfo.Normal.y,   VertexInfo.Normal.z  ); 
    413                 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetTangent (VertexInfo.Tangent.x,  VertexInfo.Tangent.y,  VertexInfo.Tangent.z ); 
    414                 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetBiNormal(VertexInfo.BiNormal.x, VertexInfo.BiNormal.y, VertexInfo.BiNormal.z); 
    415             } 
     419                m_Draw_Meshes[MeshNr].Vertices[DrawTriNr*3+i].SetOrigin(VertexInfo.Pos.x, VertexInfo.Pos.y, VertexInfo.Pos.z); 
     420                m_Draw_Meshes[MeshNr].Vertices[DrawTriNr*3+i].SetTextureCoord(Mesh.Vertices[VertexIdx].u, Mesh.Vertices[VertexIdx].v); 
     421                m_Draw_Meshes[MeshNr].Vertices[DrawTriNr*3+i].SetNormal  (VertexInfo.Normal.x,   VertexInfo.Normal.y,   VertexInfo.Normal.z  ); 
     422                m_Draw_Meshes[MeshNr].Vertices[DrawTriNr*3+i].SetTangent (VertexInfo.Tangent.x,  VertexInfo.Tangent.y,  VertexInfo.Tangent.z ); 
     423                m_Draw_Meshes[MeshNr].Vertices[DrawTriNr*3+i].SetBiNormal(VertexInfo.BiNormal.x, VertexInfo.BiNormal.y, VertexInfo.BiNormal.z); 
     424            } 
     425 
     426            DrawTriNr++; 
    416427        } 
    417428    } 
  • cafu/trunk/Libs/Models/Loader_cmdl.cpp

    r428 r429  
    272272                                lua_pop(m_LuaState, 1); 
    273273                            } 
     274 
     275                            lua_getfield(m_LuaState, -1, "skipDraw"); 
     276                            Triangle.SkipDraw=lua_toboolean(m_LuaState, -1)!=0; 
     277                            lua_pop(m_LuaState, 1); 
    274278                        } 
    275279                        lua_pop(m_LuaState, 1); 
  • cafu/trunk/Libs/Models/Model_cmdl.cpp

    r428 r429  
    8080 
    8181CafuModelT::MeshT::TriangleT::TriangleT(unsigned int v0, unsigned int v1, unsigned int v2) 
    82     : Polarity(false) 
     82    : Polarity(false), 
     83      SkipDraw(false) 
    8384{ 
    8485    VertexIdx[0]=v0; 
     
    706707            OutStream << "\t\t\t" 
    707708                      << "{ " 
    708                       << Triangle.VertexIdx[0] << ", " << Triangle.VertexIdx[1] << ", " << Triangle.VertexIdx[2] << " " 
     709                      << Triangle.VertexIdx[0] << ", " << Triangle.VertexIdx[1] << ", " << Triangle.VertexIdx[2]; 
     710            if (Triangle.SkipDraw) OutStream << ", skipDraw=true;"; 
     711            OutStream << " " 
    709712                      << "},\n"; 
    710713        } 
  • cafu/trunk/Libs/Models/Model_cmdl.hpp

    r428 r429  
    5050namespace ModelEditor { class CommandUpdateChannelT; } 
    5151namespace ModelEditor { class CommandUpdateGuiFixtureT; } 
     52namespace ModelEditor { class CommandUpdateTriangleT; } 
    5253 
    5354 
     
    8283            int          NeighbIdx[3];  ///< The array indices of the three neighbouring triangles at the edges 01, 12 and 20. -1 indicates no neighbour, -2 indicates more than one neighbour. 
    8384            bool         Polarity;      ///< True if this triangle has positive polarity (texture is not mirrored), or false if it has negative polarity (texture is mirrored, SxT points inward). 
     85            bool         SkipDraw;      ///< True if this triangle should be skipped when drawing the mesh (but not for casting stencil shadows and not for collision detection). This is useful for hiding triangles that are in the same plane as GUI panels and would otherwise cause z-fighting. 
    8486 
    8587            Vector3fT    gts_Normal;    ///< The draw normal for this triangle, required for the shadow-silhouette determination. 
     
    303305    friend class ModelEditor::CommandUpdateChannelT; 
    304306    friend class ModelEditor::CommandUpdateGuiFixtureT; 
     307    friend class ModelEditor::CommandUpdateTriangleT; 
    305308 
    306309    CafuModelT(const CafuModelT&);                  ///< Use of the Copy    Constructor is not allowed.