Jump to content
  • Advertisement
Sign in to follow this  
Erkokite

Converting bsp collision brushes to polygon meshes

This topic is 4526 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to convert the convex hulls that quake 3 bsp maps use for collision detection to polygon meshes. I am using the approach described here: http://folk.uio.no/stefanha/MAPFiles.pdf. I am not trying to load the MAP files themselves, just the collision brushes from quake 3 bsp files. However this is the result when I render the resultant meshes: http://infernalandroid.tripod.com/brush_problems.jpg any ideas? PS Here is my code:
     numbrushes = 0;
     for(vector<TBrush>::iterator br_it=bspmap.qmap.mBrushes.begin(); br_it != bspmap.qmap.mBrushes.end(); ++br_it){
            TBrush curbrush = *br_it;
            int numfaces=curbrush.mNbBrushSides;
            cout<<"numfaces "<<numfaces<<endl;
            poly_from_qhull *temp_poly_list = new poly_from_qhull[numfaces];
            vector<TPlane> temp_plane_list;
            for(int aa=0; aa<numfaces; ++aa){
                temp_plane_list.push_back(bspmap.qmap.mPlanes.at(bspmap.qmap.mBrushSides.at(curbrush.mBrushSide+aa).mPlaneIndex));
            }
            for(int ii=0; ii<=numfaces-3; ++ii){
                for(int jj=ii; jj<=numfaces-2; ++jj){
                    for(int kk=jj; kk<=numfaces-1; ++kk){
                    	if((ii != jj) && (ii != kk) && (kk != jj)){
                            glm::vec3 point;
                            TPlane pl1 = bspmap.qmap.mPlanes.at(bspmap.qmap.mBrushSides.at(ii+curbrush.mBrushSide).mPlaneIndex);
                            TPlane pl2 = bspmap.qmap.mPlanes.at(bspmap.qmap.mBrushSides.at(jj+curbrush.mBrushSide).mPlaneIndex);
                            TPlane pl3 = bspmap.qmap.mPlanes.at(bspmap.qmap.mBrushSides.at(kk+curbrush.mBrushSide).mPlaneIndex);
                            bool di = intersect_three_planes(pl1, pl2, pl3, point);
                            if(di){
                                bool is_out = is_outside_qhull(point, temp_plane_list);
                                if(!is_out){
                                    temp_poly_list[ii].verts.push_back(point);
                                    temp_poly_list[jj].verts.push_back(point);
                                    temp_poly_list[kk].verts.push_back(point);
                                }
                            }
                        }
                    }
                }
            }            
            
            br = new brush;
            br->phys_properties.ColModel = newCollisionModel3D();
            for(int aa=0; aa<numfaces; ++aa){
            	if(temp_poly_list[aa].verts.size()>=3){
                    for(int bb=0; bb<temp_poly_list[aa].verts.size()-2; ++bb){
                        
                        glm::vec3 v1 = temp_poly_list[aa].verts.at(1);
                        glm::vec3 v2 = temp_poly_list[aa].verts.at(bb+1);
                        glm::vec3 v3 = temp_poly_list[aa].verts.at(bb+2);
                        
                        v1.x=v1.x*0.1;
                        v1.z=v1.z*0.1;
                        v1.y=v1.y*0.1;
                        v2.x=v2.x*0.1;
                        v2.z=v2.z*0.1;
                        v2.y=v2.y*0.1;
                        v3.x=v3.x*0.1;
                        v3.z=v3.z*0.1;
                        v3.y=v3.y*0.1;
                        temp_debug_tri tdt;
                        tdt.a=v1;
                        tdt.b=v2;
                        tdt.c=v3;
                        debug_tris.push_back(tdt);
                        br->phys_properties.ColModel->addTriangle(v1, v2, v3);
                        
                    }
            	}
            }
            br->phys_properties.ColModel->finalize();
            Global_Physics_Manager.add_built_brush(br);
            ++numbrushes;
            
     }


Share this post


Link to post
Share on other sites
Advertisement
I'm not sure from looking at the code what the problem is, but perhaps you need to sort the polygon vertices after they're created. I haven't written a 'serious' .map to .bsp converter, but I do remember doing exactly what you're doing to visualize fog brushes in Q3 maps (which actually turned out to be unnecessary since they're always axis aligned).

In any case, it seems that without sorting, the polygon vertices could end up in an arbitrary order. In my code I sorted them as a last step, which seemed to produce the correct results.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!