# Converting bsp collision brushes to polygon meshes

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

## 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->finalize();
++numbrushes;

}

##### Share on other sites
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 on other sites
I'll try that. Thanks.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633284
• Total Posts
3011212
• ### Who's Online (See full list)

There are no registered users currently online

×