Changeset 474 for cafu/trunk

Show
Ignore:
Timestamp:
02/02/12 00:29:44 (4 months ago)
Author:
Carsten
Message:

Model code: Add support for importing smoothing groups to all model loaders.

The loaders of all model file formats have been augmented to import smoothing groups, whenever such information is available in the imported file.
The imported smoothing groups data is stored in our appropriately extended cmdl files, and the CafuModelT class has been extended accordingly.

Still missing is

  • the actual use of the newly available information (at this time, we continue to compute tangent-space as before),
  • thorough testing for each of the supported file formats.

References #100 and #101.

Location:
cafu/trunk
Files:
13 modified

Legend:

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

    r473 r474  
    193193    const ArrayT<unsigned int>& Sel=m_ModelDoc->GetSelection(m_TYPE); 
    194194 
     195    // When a command is done or undone, it can indirectly call our Notify_*() methods, 
     196    // which in turn call InitListItems(). Our calls to Select() unfortunately cause a 
     197    // wxEVT_COMMAND_LIST_ITEM_SELECTED event, which in turn calls our OnSelectionChanged() 
     198    // handler. Thus we set m_IsRecursiveSelfNotify in order to prevent the handler 
     199    // from inadvertently submitting another command. 
    195200    m_IsRecursiveSelfNotify=true; 
    196201    Freeze(); 
  • cafu/trunk/CaWE/ModelEditor/TransformDialog.cpp

    r455 r474  
    103103    wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); 
    104104 
    105     wxStaticText *item1 = new wxStaticText(this, -1, wxT("The transformation is applied to the entire model in the selected animation sequence or bind pose:"), wxDefaultPosition, wxSize(220,48), 0 ); 
     105    wxStaticText *item1 = new wxStaticText(this, -1, wxT("The transformation is applied to the currently selected animation sequence(s):"), wxDefaultPosition, wxSize(220, 32), 0 ); 
    106106    item0->Add( item1, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); 
    107107 
  • cafu/trunk/Libs/Models/Loader_ase.cpp

    r455 r474  
    156156                    // remeber to not ignore the "*MATERIAL_REF" keyword any longer, and fix all faces with no "*MESH_MTLID" after loading! 
    157157                    if (SmoothGroupString=="*MESH_MTLID") break; 
    158                     Triangles[FaceNr].SmoothGroups.PushBack(strtoul(SmoothGroupString.c_str(), NULL, 0)); 
     158 
     159                    const unsigned long SG=strtoul(SmoothGroupString.c_str(), NULL, 0); 
     160 
     161                    if (SG > 31) 
     162                        printf("Mesh is in smoothing group %lu, but should be in 0...31.\n", SG); 
     163 
     164                    Triangles[FaceNr].SmoothGroups.PushBack(SG); 
     165                    Triangles[FaceNr].SmoothGrps=uint32_t(1) << SG; 
     166 
    159167                    if (Triangles[FaceNr].SmoothGroups.Size()>32) throw TextParserT::ParseError();   // Safe-Guard... 
    160168                } 
     
    580588            } 
    581589 
     590            CafuTri.SmoothGroups=AseTri.SmoothGrps; 
    582591            CafuTri.gts_Normal=AseTri.Normal.AsVectorOfFloat(); 
    583592        } 
  • cafu/trunk/Libs/Models/Loader_ase.hpp

    r457 r474  
    5757            /// Constructor. 
    5858            TriangleT() 
     59                : SmoothGrps(0) 
    5960            { 
    6061                for (unsigned long i=0; i<3; i++) 
     
    6970            unsigned long         IndTexCoords[3];  ///< Indices into the TexCoords array. 
    7071            ArrayT<unsigned long> SmoothGroups;     ///< The SmoothGroups this triangle is in. 
     72            uint32_t              SmoothGrps;       ///< The smoothing groups that this triangle is in: If bit \c i is set, the triangle is in smoothing group \c i. 
    7173 
    7274            // This data is computed after loading. 
  • cafu/trunk/Libs/Models/Loader_cmdl.cpp

    r455 r474  
    272272                                lua_pop(m_LuaState, 1); 
    273273                            } 
     274 
     275                            lua_getfield(m_LuaState, -1, "sg"); 
     276                            Triangle.SmoothGroups=uint32_t(lua_tonumber(m_LuaState, -1)); 
     277                            lua_pop(m_LuaState, 1); 
    274278 
    275279                            lua_getfield(m_LuaState, -1, "skipDraw"); 
  • cafu/trunk/Libs/Models/Loader_dummy.cpp

    r455 r474  
    9494    { 
    9595        Mesh.Triangles.PushBack(CafuModelT::MeshT::TriangleT(0, ((i+1) % Facets)+1, i+1)); 
     96        Mesh.Triangles[i].SmoothGroups=0x01; 
    9697    } 
    9798 
  • cafu/trunk/Libs/Models/Loader_fbx.cpp

    r455 r474  
    573573        const KFbxLayerElement::EMappingMode        MappingMode=(Mesh->GetLayer(0) && Mesh->GetLayer(0)->GetUVs()) ? Mesh->GetLayer(0)->GetUVs()->GetMappingMode() : KFbxLayerElement::eNONE; 
    574574        KFbxLayerElementArrayTemplate<KFbxVector2>* UVArray    =NULL; 
     575        const KFbxLayerElementSmoothing*            SmoothingLE=NULL; 
    575576        std::map<uint64_t, unsigned int>            UniqueVertices;     // Maps tuples of (Mesh->GetPolygonVertex(), Mesh->GetTextureUVIndex()) to indices into CafuMesh.Vertices. 
    576577 
    577578        Mesh->GetTextureUV(&UVArray, KFbxLayerElement::eDIFFUSE_TEXTURES); 
    578579 
     580        if (Mesh->GetLayer(0)) 
     581        { 
     582            SmoothingLE=Mesh->GetLayer(0)->GetSmoothing(); 
     583 
     584            if (SmoothingLE) 
     585                Log << "    The mesh has a smoothing layer element with mapping mode " 
     586                    << SmoothingLE->GetMappingMode() << " and reference mode " 
     587                    << SmoothingLE->GetReferenceMode() << ".\n"; 
     588            else 
     589                Log << "    The mesh has no smoothing layer element.\n"; 
     590        } 
     591 
    579592        for (int PolyNr=0; PolyNr<Mesh->GetPolygonCount(); PolyNr++) 
    580593        { 
     594            uint32_t SmoothingGroups=0x01;    // Per default, all triangles are in a common smoothing group. 
     595 
     596            if (SmoothingLE) 
     597            { 
     598                if (SmoothingLE->GetMappingMode() == KFbxGeometryElement::eBY_POLYGON) 
     599                { 
     600                    switch (SmoothingLE->GetReferenceMode()) 
     601                    { 
     602                        case KFbxGeometryElement::eDIRECT: 
     603                            SmoothingGroups = SmoothingLE->GetDirectArray().GetAt(PolyNr); 
     604                            break; 
     605 
     606                        case KFbxGeometryElement::eINDEX_TO_DIRECT: 
     607                            SmoothingGroups = SmoothingLE->GetDirectArray().GetAt(SmoothingLE->GetIndexArray().GetAt(PolyNr)); 
     608                            break; 
     609 
     610                        default: 
     611                            // Ignore any unknown reference mode. 
     612                            break; 
     613                    } 
     614                } 
     615                else if (SmoothingLE->GetMappingMode() == KFbxGeometryElement::eBY_EDGE) 
     616                { 
     617                    // Unfortunately, we cannot deal with Maya-style smoothing info (hard vs. soft edges). 
     618                } 
     619            } 
     620 
    581621            for (int PolyTriNr=0; PolyTriNr < Mesh->GetPolygonSize(PolyNr)-2; PolyTriNr++) 
    582622            { 
     
    612652                } 
    613653 
     654                Tri.SmoothGroups=SmoothingGroups; 
    614655                CafuMesh.Triangles.PushBack(Tri); 
    615656            } 
  • cafu/trunk/Libs/Models/Loader_lwo.cpp

    r455 r474  
    394394                    Triangle.VertexIdx[2]=PolygonMeshVertices[VertexNr+1]; 
    395395 
     396                    if (Poly.smoothgrp<0 || Poly.smoothgrp>31) 
     397                        Console->Warning(cf::va("Polygon %i is in smoothing group %i, but should be in 0...31.\n", PolyNr, Poly.smoothgrp)); 
     398 
     399                    Triangle.SmoothGroups=uint32_t(1) << Poly.smoothgrp; 
    396400                    Triangle.gts_Normal=Vector3fT(Poly.norm); 
    397401 
  • cafu/trunk/Libs/Models/Loader_md5.cpp

    r473 r474  
    179179                        Mesh.Triangles[TriIdx].VertexIdx[1]=TP.GetNextTokenAsInt(); 
    180180                        Mesh.Triangles[TriIdx].VertexIdx[2]=TP.GetNextTokenAsInt(); 
     181 
     182                        // All triangles are in a common smoothing group. 
     183                        Mesh.Triangles[TriIdx].SmoothGroups=0x01; 
    181184                    } 
    182185                    else if (Token=="vert") 
  • cafu/trunk/Libs/Models/Loader_mdl.cpp

    r455 r474  
    346346                    CafuModelT::MeshT::TriangleT CafuTri; 
    347347 
     348                    // All triangles are in a common smoothing group. 
     349                    CafuTri.SmoothGroups=0x01; 
     350 
    348351                    for (unsigned int i=0; i<3; i++) 
    349352                    { 
  • cafu/trunk/Libs/Models/Model_cmdl.cpp

    r472 r474  
    8585 
    8686CafuModelT::MeshT::TriangleT::TriangleT(unsigned int v0, unsigned int v1, unsigned int v2) 
    87     : Polarity(false), 
     87    : SmoothGroups(0), 
     88      Polarity(false), 
    8889      SkipDraw(false) 
    8990{ 
     
    719720            OutStream << "\t\t\t" 
    720721                      << "{ " 
    721                       << Triangle.VertexIdx[0] << ", " << Triangle.VertexIdx[1] << ", " << Triangle.VertexIdx[2]; 
    722             if (Triangle.SkipDraw) OutStream << ", skipDraw=true;"; 
     722                      << Triangle.VertexIdx[0] << ", " << Triangle.VertexIdx[1] << ", " << Triangle.VertexIdx[2] 
     723                      << ", sg=" << Triangle.SmoothGroups; 
     724            if (Triangle.SkipDraw) OutStream << ", skipDraw=true"; 
    723725            OutStream << " " 
    724726                      << "},\n"; 
  • cafu/trunk/Libs/Models/Model_cmdl.hpp

    r472 r474  
    8282 
    8383            unsigned int VertexIdx[3];  ///< The indices to the three vertices that define this triangle. 
     84            uint32_t     SmoothGroups;  ///< The smoothing groups that this triangle is in: If bit \c i is set, the triangle is in smoothing group \c i. 
    8485 
    8586            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.