Ignore:
Timestamp:
10/06/06 17:10:18 (18 years ago)
Author:
gumbau
Message:

Fixed bones bug constructing LOD objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsConstructor.cpp

    r1552 r1578  
    522522         
    523523        this->GenerarModeloCompleto(upb); 
    524  
    525         //      Sort submesh bones. 
    526         this->sortBones(); 
    527524} 
    528525 
     
    974971void LodStripsConstructor::sortBones() 
    975972{ 
    976         bool                                                                    shared_found; 
    977         int                                                                             n; 
    978         int                                                                             o; 
    979         int                                                                             p; 
    980         VertexBoneAssignment    assign; 
    981         SubMesh                                                         *submesh; 
    982         SubMesh                                                         *copysubmesh; 
    983973        VertexBuffer                                    *mesh_vb; 
    984974        VertexBuffer                                    *copy_vb; 
     
    987977        std::vector<VertexBoneAssignment>       *copy_bones; 
    988978 
    989         //      Initialize shared vertex flag. 
    990         shared_found    =       false; 
    991  
    992         //      For each submesh. 
    993         for (size_t     i = 0;  i       <       mGeoMesh->mSubMeshCount;        i++) 
    994         { 
    995                 submesh                 =       &mGeoMesh->mSubMesh[i]; 
    996                 copysubmesh     =       &mInitialMesh->mSubMesh[i]; 
    997  
    998                 //      If submesh has shared vertex. 
    999                 if (submesh->mSharedVertexBuffer) 
    1000                 { 
    1001                         if (shared_found) 
    1002                         { 
    1003                                 continue; 
    1004                         } 
    1005  
    1006                         shared_found    =       true; 
    1007                          
    1008                         //      Vertex buffers. 
    1009                         mesh_vb =       mGeoMesh->mVertexBuffer; 
    1010                         copy_vb =       mInitialMesh->mVertexBuffer; 
    1011  
    1012                         //      Bones. 
    1013                         mesh_bones      =       &mGeoMesh->mBones; 
    1014                         copy_bones      =       &mInitialMesh->mBones; 
    1015                 } 
    1016                 else 
    1017                 { 
    1018                         //      Vertex buffers. 
    1019                         mesh_vb =       submesh->mVertexBuffer; 
    1020                         copy_vb =       copysubmesh->mVertexBuffer; 
    1021  
    1022                         //      Bones. 
    1023                         mesh_bones      =       &submesh->mBones; 
    1024                         copy_bones      =       &copysubmesh->mBones; 
    1025                 } 
     979        // After simplifying, the object always is shared vertex 
     980        // so, the bones must be placed in the GeoMesh 
     981        mesh_bones      =       &mGeoMesh->mBones; 
     982        mesh_vb =       mGeoMesh->mVertexBuffer; 
     983 
     984        // we assume the original mesh is shared vertex  
     985        // because before the simplification process 
     986        // the mesh becomes converted to shared vertex 
     987        // so, the original bones must be searched in the 
     988        // Mesh, not in every submesh 
     989 
     990        mesh_bones->clear(); 
     991 
     992        //      Vertex buffers. 
     993        copy_vb =       mInitialMesh->mVertexBuffer; 
     994 
     995        //      Bones. 
     996        copy_bones = &mInitialMesh->mBones; 
     997         
     998        //      If there are submesh bones. 
     999        for (int b = 0; b < copy_bones->size(); b++) 
     1000        { 
     1001                VertexBoneAssignment    assign; 
     1002 
     1003                int n   =       (*copy_bones)[b].vertexIndex; 
     1004 
     1005                //      Initialize o. 
    10261006                 
    1027                 if (!mesh_bones->empty()) 
    1028                 { 
    1029                         assign.boneIndex        =       0; 
    1030                         assign.weight           =       1; 
    1031  
    1032                         for (size_t     m = copy_vb->mVertexCount; 
    1033                                                 m < mesh_vb->mVertexCount; 
    1034                                                 m++) 
    1035                         { 
    1036                                 assign.vertexIndex      =       (unsigned int)m; 
     1007                int o=0; 
     1008                for (o=0; o<mesh_vb->mVertexCount; o++) 
     1009                { 
     1010                        if (mesh_vb->mPosition[o].x == copy_vb->mPosition[n].x && 
     1011                                mesh_vb->mPosition[o].y == copy_vb->mPosition[n].y && 
     1012                                mesh_vb->mPosition[o].z == copy_vb->mPosition[n].z) 
     1013                        { 
     1014                                assign.vertexIndex = o; 
     1015                                assign.boneIndex   = (*copy_bones)[b].boneIndex; 
     1016                                assign.weight      = 1.0f; 
    10371017                                mesh_bones->push_back(assign); 
    1038                         } 
    1039  
    1040                         //      Change bones. 
    1041                         for (size_t     m = 0;  m < mesh_bones->size(); m++) 
    1042                         { 
    1043                                 n       =       (*mesh_bones)[m].vertexIndex; 
    1044                                 o       =       0; 
    1045                                  
    1046                                 while (!(       (mesh_vb->mPosition[n].x == copy_vb->mPosition[o].x)    && 
    1047                                                         (mesh_vb->mPosition[n].y == copy_vb->mPosition[o].y)    && 
    1048                                                         (mesh_vb->mPosition[n].z == copy_vb->mPosition[o].z))) 
    1049                                 { 
    1050                                         o++; 
    1051                                 } 
    1052  
    1053                                 p = 0; 
    1054                                  
    1055                                 while ((*copy_bones)[p].vertexIndex != o) 
    1056                                         p++; 
    1057  
    1058                                 //      Same bone for 'm' and 'p'. 
    1059                                 (*mesh_bones)[m].boneIndex      =       (*copy_bones)[p].boneIndex; 
    1060                         } 
    1061  
    1062                         //      Look for repeated bones. 
    1063                         for (size_t     m       =       0;      m < mesh_vb->mVertexCount;      m++) 
    1064                         { 
    1065                                 for (size_t     n       =       m + 1;  n < mesh_vb->mVertexCount;      n++) 
    1066                                 { 
    1067                                         if ((mesh_vb->mPosition[m].x == mesh_vb->mPosition[n].x) 
    1068                                                         && 
    1069                                                         (mesh_vb->mPosition[m].y == mesh_vb->mPosition[n].y) 
    1070                                                         && 
    1071                                                         (mesh_vb->mPosition[m].z == mesh_vb->mPosition[n].z)) 
    1072                                         { 
    1073                                                 o       =       0; 
    1074                                                  
    1075                                                 while ((*mesh_bones)[o].vertexIndex != m) 
    1076                                                 { 
    1077                                                         o++; 
    1078                                                 } 
    1079  
    1080                                                 p       =       0; 
    1081                                                  
    1082                                                 while ((*mesh_bones)[p].vertexIndex != n) 
    1083                                                 { 
    1084                                                         p++; 
    1085                                                 } 
    1086  
    1087                                                 if ((*mesh_bones)[o].boneIndex != (*mesh_bones)[p].boneIndex) 
    1088                                                 { 
    1089                                                         printf("-->Error en los vertices %d y %d\n",m,n); 
    1090                                                 } 
    1091                                         } 
    1092                                 } 
    1093                         } 
     1018                        }                        
    10941019                } 
    10951020        } 
     
    12861211                } 
    12871212        } 
     1213 
     1214        //      Sort submesh bones. 
     1215        this->sortBones(); 
    12881216} 
    12891217 
Note: See TracChangeset for help on using the changeset viewer.