Changeset 475

Show
Ignore:
Timestamp:
02/07/12 10:36:33 (4 months ago)
Author:
Carsten
Message:

Model code: Add per-mesh settings for tangent-space method and cast shadows.

Continuing r474, this change adds new members to the CafuModelT::MeshT class for setting

  • the method for generating the tangent-space axes, and
  • if the mesh should cast dynamic shadows.

The new settings are saved to and loaded from the Cafu cmdl model files, and have been made available to the user in the Model Editor's "Mesh Inspector" dialogs.

References #100 and #101.

Location:
cafu/trunk
Files:
4 added
6 modified

Legend:

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

    r455 r475  
    2525#include "Commands/Rename.hpp" 
    2626#include "Commands/SetMaterial.hpp" 
     27#include "Commands/SetMeshShadows.hpp" 
     28#include "Commands/SetMeshTSMethod.hpp" 
    2729 
    2830#include "../EditorMaterial.hpp" 
     
    179181            "Material", Mat ? Mat->Name : "<NULL>", m_ModelDoc)); 
    180182 
    181         wxPGProperty* UseGivenTS=Append(new wxBoolProperty("Use given TS", wxPG_LABEL, false)); 
    182         DisableProperty(UseGivenTS); 
    183  
    184         wxPGProperty* CastShadows=Append(new wxBoolProperty("Cast Shadows", wxPG_LABEL, true)); 
    185         DisableProperty(CastShadows); 
     183        const wxChar* TSM_Strings[] = { wxT("HARD"), wxT("GLOBAL"), wxT("SG_LOCAL"), wxT("SG_GLOBAL"), NULL }; 
     184        const long    TSM_Indices[] = { CafuModelT::MeshT::HARD, CafuModelT::MeshT::GLOBAL, CafuModelT::MeshT::SG_LOCAL, CafuModelT::MeshT::SG_GLOBAL }; 
     185        wxPGProperty* TSMethod=Append(new wxEnumProperty("Tangent-space method", wxPG_LABEL, TSM_Strings, TSM_Indices, Mesh.TSMethod)); 
     186        TSMethod->SetHelpString("The method that is used for generating the tangent-space axes at the vertices of this mesh. See the documentation for details."); 
     187 
     188        wxPGProperty* CastShadows=Append(new wxBoolProperty("Cast Shadows", wxPG_LABEL, Mesh.CastShadows)); 
     189        CastShadows->SetHelpString("If checked, this mesh casts shadows when lit by dynamic light sources."); 
    186190 
    187191        wxPGProperty* NumTriangles=Append(new wxIntProperty("Num Triangles", wxPG_LABEL, Mesh.Triangles.Size())); 
     
    227231    bool ok=true; 
    228232 
    229          if (PropName=="Name"    ) ok=m_Parent->SubmitCommand(new CommandRenameT(m_ModelDoc, MESH, MeshNr, Event.GetValue().GetString())); 
    230     else if (PropName=="Material") ok=m_Parent->SubmitCommand(new CommandSetMaterialT(m_ModelDoc, MeshNr, m_ModelDoc->GetSelSkinNr(), Event.GetValue().GetString())); 
     233         if (PropName=="Name"    )             ok=m_Parent->SubmitCommand(new CommandRenameT(m_ModelDoc, MESH, MeshNr, Event.GetValue().GetString())); 
     234    else if (PropName=="Material")             ok=m_Parent->SubmitCommand(new CommandSetMaterialT(m_ModelDoc, MeshNr, m_ModelDoc->GetSelSkinNr(), Event.GetValue().GetString())); 
     235    else if (PropName=="Tangent-space method") ok=m_Parent->SubmitCommand(new CommandSetMeshTSMethodT(m_ModelDoc, MeshNr, CafuModelT::MeshT::TangentSpaceMethodT(Event.GetValue().GetInteger()))); 
     236    else if (PropName=="Cast Shadows")         ok=m_Parent->SubmitCommand(new CommandSetMeshShadowsT(m_ModelDoc, MeshNr, Event.GetValue().GetBool())); 
    231237    else 
    232238    { 
  • cafu/trunk/CaWE/ModelEditor/MeshInspector.hpp

    r457 r475  
    5454        DECLARE_EVENT_TABLE() 
    5555 
    56         ModelDocumentT*      m_ModelDoc; 
    57         ChildFrameT*         m_Parent; 
    58         bool                 m_IsRecursiveSelfNotify; 
     56        ModelDocumentT* m_ModelDoc; 
     57        ChildFrameT*    m_Parent; 
     58        bool            m_IsRecursiveSelfNotify; 
    5959    }; 
    6060} 
  • cafu/trunk/Libs/Models/AnimPose.cpp

    r469 r475  
    514514                const MaterialT* MeshMat =m_Model.GetMaterial(MeshNr, SkinNr); 
    515515 
     516                if (!Mesh.CastShadows) continue; 
    516517                if (MeshMat==NULL || MeshMat->NoShadows) continue; 
    517518 
  • cafu/trunk/Libs/Models/Loader_cmdl.cpp

    r474 r475  
    197197                        Mesh.Material=MaterialMan.RegisterMaterial(CreateDefaultMaterial(MatName)); 
    198198                    } 
     199                } 
     200                lua_pop(m_LuaState, 1); 
     201 
     202                lua_getfield(m_LuaState, -1, "tsMethod"); 
     203                { 
     204                    const char* Method=lua_tostring(m_LuaState, -1); 
     205                    Mesh.SetTSMethod(Method ? Method : "default"); 
     206                } 
     207                lua_pop(m_LuaState, 1); 
     208 
     209                lua_getfield(m_LuaState, -1, "castShadows"); 
     210                { 
     211                    Mesh.CastShadows=lua_isnumber(m_LuaState, -1) ? (lua_tonumber(m_LuaState, -1)!=0) : (lua_toboolean(m_LuaState, -1)!=0); 
    199212                } 
    200213                lua_pop(m_LuaState, 1); 
  • cafu/trunk/Libs/Models/Model_cmdl.cpp

    r474 r475  
    125125    // All weights were equal - the vertices are geodups of each other! 
    126126    return true; 
     127} 
     128 
     129 
     130std::string CafuModelT::MeshT::GetTSMethod() const 
     131{ 
     132    switch (TSMethod) 
     133    { 
     134        case HARD:      return "HARD"; 
     135        case GLOBAL:    return "GLOBAL"; 
     136        case SG_LOCAL:  return "SG_LOCAL"; 
     137        case SG_GLOBAL: return "SG_GLOBAL"; 
     138    } 
     139 
     140    return "?"; 
     141} 
     142 
     143 
     144void CafuModelT::MeshT::SetTSMethod(const std::string& m) 
     145{ 
     146    TSMethod=GLOBAL; 
     147 
     148         if (m=="HARD")      TSMethod=HARD; 
     149    else if (m=="GLOBAL")    TSMethod=GLOBAL; 
     150    else if (m=="SG_LOCAL")  TSMethod=SG_LOCAL; 
     151    else if (m=="SG_GLOBAL") TSMethod=SG_GLOBAL; 
    127152} 
    128153 
     
    681706        OutStream << "\t\t" << "name=\"" << Mesh.Name << "\";\n"; 
    682707        OutStream << "\t\t" << "Material=\"" << (Mesh.Material ? Mesh.Material->Name : "") << "\";\n"; 
     708        OutStream << "\t\t" << "tsMethod=\"" << Mesh.GetTSMethod() << "\";\n"; 
     709        OutStream << "\t\t" << "castShadows=" << (Mesh.CastShadows ? "true" : "false") << ";\n";    // Don't rely on the proper locale being set... 
    683710 
    684711        // Write the mesh weights. 
  • cafu/trunk/Libs/Models/Model_cmdl.hpp

    r474 r475  
    4747namespace ModelEditor { class CommandSetAnimNextT; } 
    4848namespace ModelEditor { class CommandSetMaterialT; } 
     49namespace ModelEditor { class CommandSetMeshTSMethodT; } 
     50namespace ModelEditor { class CommandSetMeshShadowsT; } 
    4951namespace ModelEditor { class CommandTransformJointT; } 
    5052namespace ModelEditor { class CommandUpdateAnimT; } 
     
    7678    struct MeshT 
    7779    { 
     80        /// The methods that can be used to generate the tangent-space axes at the vertices of a mesh. 
     81        /// 
     82        /// In this context, "global" smoothing means that when the side of a pyramid or cone is considered, 
     83        /// for computing the tangent-space of its tip vertex, all sides of the pyramid enter the average, 
     84        /// because they all share the common tip vertex. 
     85        /// As a result, the normal vector at the tip is straight (axial), the same for all sides, and the 
     86        /// interpolated "shape" in tangent-space is really a half-sphere rather than a cone. 
     87        /// 
     88        /// In contrast, "local" smoothing averages only the current side with its left and right neighbours. 
     89        /// The resulting tangent-space normal vectors at the tip vertices remain orthogonal to their triangle, 
     90        /// and the interpolated tangent-space shape is a cone rather than a half-sphere. 
     91        enum TangentSpaceMethodT 
     92        { 
     93            HARD,       ///< Hard edges, no smoothing: The tangent-space of the triangle is used as the tangent-space of its vertices. (Any smoothing groups info, if available, is ignored.) 
     94            GLOBAL,     ///< Considers all triangles in the mesh to be in the same common smoothing group, and smoothes them globally. (Any smoothing groups info, if available, is ignored.) This method is equivalent to SG_GLOBAL when all triangles are in the same smoothing group. It is also the default method, as it requires no smoothing groups info at all, provides better performance than SG_GLOBAL, and was implemented in earlier versions of Cafu. 
     95            SG_LOCAL,   ///< Takes the given smoothing groups into account and provides "local" smoothing. 
     96            SG_GLOBAL   ///< [NOT YET IMPLEMENTED! At this time, this is the same as GLOBAL.] Takes the given smoothing groups into account and provides "global" smoothing. 
     97        }; 
     98 
    7899        /// A single triangle. 
    79100        struct TriangleT 
     
    118139 
    119140        /// The default constructor. 
    120         MeshT() : Material(NULL), RenderMaterial(NULL) {} 
     141        MeshT() : Material(NULL), RenderMaterial(NULL), TSMethod(GLOBAL), CastShadows(true) {} 
    121142 
    122143        /// Determines whether the two vertices with array indices Vertex1Nr and Vertex2Nr are geometrical duplicates of each other. 
     
    131152        bool AreGeoDups(unsigned int Vertex1Nr, unsigned int Vertex2Nr) const; 
    132153 
     154        /// Returns a string representation of the TSMethod enum member. 
     155        std::string GetTSMethod() const; 
     156 
     157        /// Sets the TSMethod enum member by string. 
     158        /// The given string should be one of the strings returned by GetTSMethod(). 
     159        /// If the string does not match a known method, TSMethod is set to GLOBAL. 
     160        /// @param m   The method to set TSMethod to. 
     161        void SetTSMethod(const std::string& m); 
     162 
    133163        std::string              Name;            ///< Name of this mesh. 
    134164        MaterialT*               Material;        ///< The material of this mesh. 
    135165        MatSys::RenderMaterialT* RenderMaterial;  ///< The render material used to render this mesh. 
    136      // bool                     CastShadows;     ///< Should this mesh cast shadows? 
     166        TangentSpaceMethodT      TSMethod;        ///< How to generate the tangent-space axes at the vertices of this mesh? For meshes with normal-maps, the method should match the one that was used in the program that created the normal-maps. 
     167        bool                     CastShadows;     ///< Should this mesh cast shadows? 
    137168        ArrayT<TriangleT>        Triangles;       ///< List of triangles this mesh consists of. 
    138169        ArrayT<VertexT>          Vertices;        ///< List of vertices this mesh consists of. 
     
    312343    friend class ModelEditor::CommandSetAnimNextT; 
    313344    friend class ModelEditor::CommandSetMaterialT; 
     345    friend class ModelEditor::CommandSetMeshTSMethodT; 
     346    friend class ModelEditor::CommandSetMeshShadowsT; 
    314347    friend class ModelEditor::CommandTransformJointT; 
    315348    friend class ModelEditor::CommandUpdateAnimT;