impact[2] = origin[2] - node->plane->normal[2] * ndist;
}
- for (surface = model->brushq1.surfaces + node->firstsurface, endsurface = surface + node->numsurfaces;surface < endsurface;surface++)
+ for (surface = model->brush.data_surfaces + node->firstsurface, endsurface = surface + node->numsurfaces;surface < endsurface;surface++)
{
if (surface->stainsamples)
{
static void RSurfShader_Transparent_Callback(const void *calldata1, int calldata2)
{
const entity_render_t *ent = calldata1;
- const msurface_t *surface = ent->model->brushq1.surfaces + calldata2;
+ const msurface_t *surface = ent->model->brush.data_surfaces + calldata2;
rmeshstate_t m;
float currentalpha;
float base, colorscale;
R_Mesh_Matrix(&ent->matrix);
Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
- texture = surface->texinfo->texture;
+ texture = surface->texture;
if (texture->animated)
texture = texture->anim_frames[ent->frame != 0][(texture->anim_total[ent->frame != 0] >= 2) ? ((int) (r_refdef.time * 5.0f) % texture->anim_total[ent->frame != 0]) : 0];
currentalpha = ent->alpha;
- if (surface->flags & SURF_WATERALPHA)
+ if (texture->flags & SURF_WATERALPHA)
currentalpha *= r_wateralpha.value;
GL_DepthTest(!(ent->effects & EF_NODEPTHTEST));
GL_DepthMask(!(ent->effects & EF_NODEPTHTEST));
}
- turb = (surface->flags & SURF_DRAWTURB) && r_waterscroll.value;
- fullbright = !(ent->flags & RENDER_LIGHT) || (surface->flags & SURF_DRAWFULLBRIGHT) || !surface->samples;
+ turb = (texture->flags & SURF_DRAWTURB) && r_waterscroll.value;
+ fullbright = !(ent->flags & RENDER_LIGHT) || (texture->flags & SURF_DRAWFULLBRIGHT) || !surface->samples;
base = fullbright ? 2.0f : r_ambient.value * (1.0f / 64.0f);
- if (surface->flags & SURF_DRAWTURB)
+ if (texture->flags & SURF_DRAWTURB)
base *= 0.5f;
- if ((surface->flags & SURF_DRAWTURB) && gl_textureshader && r_watershader.value && !fogenabled && fullbright && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
+ if ((texture->flags & SURF_DRAWTURB) && gl_textureshader && r_watershader.value && !fogenabled && fullbright && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
{
// NVIDIA Geforce3 distortion texture shader on water
GL_Color(1, 1, 1, currentalpha);
{
int texturesurfaceindex;
vec3_t center, modelorg;
+ msurface_t *surface;
rmeshstate_t m;
Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
if (gl_lightmaps.integer)
memset(&m, 0, sizeof(m));
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.tex[0] = R_GetTexture(surface->lightmaptexture);
m.pointer_vertex = surface->mesh.data_vertex3f;
m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
// transparent vertex shaded from lightmap
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
vec3_t tempcenter;
tempcenter[0] = (surface->mins[0] + surface->maxs[0]) * 0.5f;
tempcenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
tempcenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
Matrix4x4_Transform(&ent->matrix, tempcenter, center);
- R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : center, RSurfShader_Transparent_Callback, ent, surface - ent->model->brushq1.surfaces);
+ R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : center, RSurfShader_Transparent_Callback, ent, surface - ent->model->brush.data_surfaces);
}
}
else if (texture->flags & SURF_LIGHTMAP)
doglow = false;
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.tex[1] = R_GetTexture(surface->lightmaptexture);
m.pointer_vertex = surface->mesh.data_vertex3f;
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
{
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.tex[1] = R_GetTexture(surface->lightmaptexture);
m.pointer_vertex = surface->mesh.data_vertex3f;
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
doglow = false;
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.tex[1] = R_GetTexture(surface->lightmaptexture);
m.pointer_vertex = surface->mesh.data_vertex3f;
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
m.tex[0] = R_GetTexture(texture->skin.base);
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.pointer_vertex = surface->mesh.data_vertex3f;
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
R_Mesh_State(&m);
m.tex[0] = R_GetTexture(texture->skin.base);
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.tex[0] = R_GetTexture(surface->lightmaptexture);
m.pointer_vertex = surface->mesh.data_vertex3f;
m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
m.tex[0] = R_GetTexture(texture->skin.base);
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.pointer_vertex = surface->mesh.data_vertex3f;
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
R_Mesh_State(&m);
m.tex[0] = R_GetTexture(texture->skin.detail);
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.pointer_vertex = surface->mesh.data_vertex3f;
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
R_Mesh_State(&m);
m.tex[0] = R_GetTexture(texture->skin.glow);
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.pointer_vertex = surface->mesh.data_vertex3f;
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
R_Mesh_State(&m);
m.tex[0] = R_GetTexture(texture->skin.glow);
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.pointer_vertex = surface->mesh.data_vertex3f;
if (m.tex[0])
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
{
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
- RSurfShader_Transparent_Callback(ent, surface - ent->model->brushq1.surfaces);
+ surface = texturesurfacelist[texturesurfaceindex];
+ RSurfShader_Transparent_Callback(ent, surface - ent->model->brush.data_surfaces);
}
}
else if (texture->flags & SURF_DRAWSKY)
memset(&m, 0, sizeof(m));
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.pointer_vertex = surface->mesh.data_vertex3f;
R_Mesh_State(&m);
GL_LockArrays(0, surface->mesh.num_vertices);
if (ent != r_refdef.worldentity)
{
// because bmodels can be reused, we have to clear dlightframe every time
- surface = model->brushq1.surfaces + model->firstmodelsurface;
+ surface = model->brush.data_surfaces + model->firstmodelsurface;
for (i = 0;i < model->nummodelsurfaces;i++, surface++)
surface->dlightframe = -1;
}
{
if (ent != r_refdef.worldentity || r_worldsurfacevisible[j])
{
- surface = model->brushq1.surfaces + j;
- if (t != surface->texinfo->texture)
+ surface = model->brush.data_surfaces + j;
+ if (t != surface->texture)
{
if (numsurfacelist)
{
R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
numsurfacelist = 0;
}
- t = surface->texinfo->texture;
+ t = surface->texture;
f = t->flags & flagsmask;
texture = t->currentframe;
}
{
int i, j;
mleaf_t *leaf;
- memset(r_worldsurfacevisible, 0, r_refdef.worldmodel->brushq3.num_faces);
+ memset(r_worldsurfacevisible, 0, r_refdef.worldmodel->brush.num_surfaces);
for (j = 0, leaf = r_refdef.worldmodel->brush.data_leafs;j < r_refdef.worldmodel->brush.num_leafs;j++, leaf++)
{
if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
if (!viewleaf)
return;
- memset(r_worldsurfacevisible, 0, r_refdef.worldmodel->brushq1.numsurfaces);
+ memset(r_worldsurfacevisible, 0, r_refdef.worldmodel->brush.num_surfaces);
if (viewleaf->clusterindex < 0 || r_surfaceworldnode.integer)
{
// equivilant to quake's RecursiveWorldNode but faster and more effective
surfaceindex = leaf->firstleafsurface[leafsurfaceindex];
if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
{
- surface = model->brushq1.surfaces + surfaceindex;
- if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && (surface->flags & SURF_LIGHTMAP) && !surface->texinfo->texture->skin.fog)
+ surface = model->brush.data_surfaces + surfaceindex;
+ if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && (surface->texture->flags & SURF_LIGHTMAP) && !surface->texture->skin.fog)
{
for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
{
R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
{
- surface = model->brushq1.surfaces + surfacelist[surfacelistindex];
+ surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->mesh.num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
}
R_Shadow_VolumeFromList(model->brush.shadowmesh->numverts, model->brush.shadowmesh->numtriangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, model->brush.shadowmesh->neighbor3i, relativelightorigin, lightradius + model->radius + r_shadow_projectdistance.value, numshadowmark, shadowmarklist);
R_UpdateTextureInfo(ent);
for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
{
- surface = model->brushq1.surfaces + surfacelist[surfacelistindex];
+ surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
if (r_shadow_compilingrtlight)
{
// if compiling an rtlight, capture the mesh
- t = surface->texinfo->texture;
+ t = surface->texture;
if (t->flags & SURF_LIGHTMAP && t->skin.fog == NULL)
- Mod_ShadowMesh_AddMesh(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_light, surface->texinfo->texture->skin.base, surface->texinfo->texture->skin.gloss, surface->texinfo->texture->skin.nmap, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, surface->mesh.num_triangles, surface->mesh.data_element3i);
+ Mod_ShadowMesh_AddMesh(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_light, surface->texture->skin.base, surface->texture->skin.gloss, surface->texture->skin.nmap, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, surface->mesh.num_triangles, surface->mesh.data_element3i);
}
- else if (ent != r_refdef.worldentity || r_worldsurfacevisible[surface - ent->model->brushq1.surfaces])
+ else if (ent != r_refdef.worldentity || r_worldsurfacevisible[surface - ent->model->brush.data_surfaces])
{
- t = surface->texinfo->texture->currentframe;
+ t = surface->texture->currentframe;
// FIXME: transparent surfaces need to be lit later
if (t->flags & SURF_LIGHTMAP && t->rendertype == SURFRENDER_OPAQUE)
R_Shadow_RenderLighting(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, relativelightorigin, relativeeyeorigin, lightcolor, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, t->skin.base, t->skin.nmap, t->skin.gloss, lightcubemap, ambientscale, diffusescale, specularscale);
GL_LockArrays(0, 0);
}
-void R_Q3BSP_DrawCollisionFace(entity_render_t *ent, q3msurface_t *surface)
+void R_Q3BSP_DrawCollisionSurface(entity_render_t *ent, msurface_t *surface)
{
int i;
rmeshstate_t m;
memset(&m, 0, sizeof(m));
m.pointer_vertex = surface->mesh.data_collisionvertex3f;
R_Mesh_State(&m);
- i = (int)(((size_t)surface) / sizeof(q3msurface_t));
+ i = (int)(((size_t)surface) / sizeof(msurface_t));
GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
GL_LockArrays(0, surface->mesh.num_collisionvertices);
R_Mesh_Draw(surface->mesh.num_collisionvertices, surface->mesh.num_collisiontriangles, surface->mesh.data_collisionelement3i);
void R_Q3BSP_DrawFace_TransparentCallback(const void *voident, int surfacenumber)
{
const entity_render_t *ent = voident;
- q3msurface_t *surface = ent->model->brushq3.data_faces + surfacenumber;
+ msurface_t *surface = ent->model->brush.data_surfaces + surfacenumber;
rmeshstate_t m;
R_Mesh_Matrix(&ent->matrix);
memset(&m, 0, sizeof(m));
qglEnable(GL_CULL_FACE);
}
-void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurfaces, q3msurface_t **texturesurfacelist)
+void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurfaces, msurface_t **texturesurfacelist)
{
int i, texturesurfaceindex;
+ msurface_t *surface;
qboolean dolightmap;
qboolean dobase;
qboolean doambient;
memset(&m, 0, sizeof(m));
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.tex[0] = R_GetTexture(surface->lightmaptexture);
m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
if (surface->lightmaptexture)
return;
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
facecenter[0] = (surface->mins[0] + surface->maxs[0]) * 0.5f;
facecenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
facecenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
Matrix4x4_Transform(&ent->matrix, facecenter, center);
- R_MeshQueue_AddTransparent(center, R_Q3BSP_DrawFace_TransparentCallback, ent, surface - ent->model->brushq3.data_faces);
+ R_MeshQueue_AddTransparent(center, R_Q3BSP_DrawFace_TransparentCallback, ent, surface - ent->model->brush.data_surfaces);
}
return;
}
memset(&m, 0, sizeof(m));
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.pointer_vertex = surface->mesh.data_vertex3f;
R_Mesh_State(&m);
GL_LockArrays(0, surface->mesh.num_vertices);
m.tex[0] = R_GetTexture(t->skin.base);
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
m.pointer_vertex = surface->mesh.data_vertex3f;
R_Mesh_State(&m);
memset(&m, 0, sizeof(m));
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.pointer_vertex = surface->mesh.data_vertex3f;
R_Mesh_State(&m);
GL_LockArrays(0, surface->mesh.num_vertices);
m.pointer_color = NULL;
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
if (!surface->lightmaptexture)
continue;
m.tex[1] = R_GetTexture(surface->lightmaptexture);
{
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
if (surface->lightmaptexture)
continue;
m.tex[1] = R_GetTexture(surface->lightmaptexture);
{
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
if (surface->lightmaptexture)
continue;
m.tex[1] = R_GetTexture(surface->lightmaptexture);
memset(&m, 0, sizeof(m));
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.tex[0] = R_GetTexture(surface->lightmaptexture);
m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
if (surface->lightmaptexture)
m.tex[0] = R_GetTexture(t->skin.base);
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
m.pointer_vertex = surface->mesh.data_vertex3f;
R_Mesh_State(&m);
m.tex[0] = R_GetTexture(t->skin.base);
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
m.pointer_vertex = surface->mesh.data_vertex3f;
R_Mesh_State(&m);
m.tex[0] = R_GetTexture(t->skin.glow);
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
m.pointer_vertex = surface->mesh.data_vertex3f;
R_Mesh_State(&m);
m.pointer_color = varray_color4f;
for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
{
- q3msurface_t *surface = texturesurfacelist[texturesurfaceindex];
+ surface = texturesurfacelist[texturesurfaceindex];
if (m.tex[0])
m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
m.pointer_vertex = surface->mesh.data_vertex3f;
void R_Q3BSP_DrawFaces(entity_render_t *ent, int skyfaces)
{
int i, j, f, flagsmask, flags;
- q3msurface_t *surface;
+ msurface_t *surface;
model_t *model = ent->model;
texture_t *t;
const int maxfaces = 1024;
int numsurfaces = 0;
- q3msurface_t *surfacelist[1024];
+ msurface_t *surfacelist[1024];
R_Mesh_Matrix(&ent->matrix);
flagsmask = Q3SURFACEFLAG_NODRAW | Q3SURFACEFLAG_SKY;
if (skyfaces)
{
if (ent != r_refdef.worldentity || r_worldsurfacevisible[j])
{
- surface = model->brushq3.data_faces + j;
+ surface = model->brush.data_surfaces + j;
if (t != surface->texture)
{
if (numsurfaces)
{
int i;
model_t *model = ent->model;
- q3msurface_t *surface;
+ msurface_t *surface;
GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
GL_DepthMask(false);
GL_DepthTest(true);
R_DrawCollisionBrush(model->brushq3.data_models[model->brush.submodel].firstbrush[i].colbrushf);
for (i = 0, surface = model->brushq3.data_models[model->brush.submodel].firstsurface;i < model->brushq3.data_models[model->brush.submodel].numsurfaces;i++, surface++)
if (surface->mesh.num_collisiontriangles)
- R_Q3BSP_DrawCollisionFace(ent, surface);
+ R_Q3BSP_DrawCollisionSurface(ent, surface);
qglPolygonOffset(0, 0);
}
}
int t, leafindex, leafsurfaceindex, surfaceindex, triangleindex, outnumclusters = 0, outnumsurfaces = 0;
const int *e;
const float *v[3];
- q3msurface_t *surface;
+ msurface_t *surface;
mleaf_t *leaf;
const qbyte *pvs;
lightmins[0] = relativelightorigin[0] - lightradius;
for (leafsurfaceindex = 0;leafsurfaceindex < leaf->numleafsurfaces;leafsurfaceindex++)
{
surfaceindex = leaf->firstleafsurface[leafsurfaceindex];
- surface = model->brushq3.data_faces + surfaceindex;
+ surface = model->brush.data_surfaces + surfaceindex;
if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
{
if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && !(surface->texture->surfaceparms & Q3SURFACEPARM_TRANS) && !(surface->texture->surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NODRAW)) && surface->mesh.num_triangles)
{
model_t *model = ent->model;
vec3_t lightmins, lightmaxs;
- q3msurface_t *surface;
+ msurface_t *surface;
int surfacelistindex;
if (r_drawcollisionbrushes.integer < 2)
{
R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
{
- surface = model->brushq3.data_faces + surfacelist[surfacelistindex];
+ surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
// FIXME: check some manner of surface->rendermode here?
if (!(surface->texture->surfaceflags & Q3SURFACEFLAG_NODRAW) && !(surface->texture->surfaceparms & (Q3SURFACEPARM_SKY | Q3SURFACEPARM_TRANS)) && !(surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED))
R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->mesh.num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
{
model_t *model = ent->model;
vec3_t lightmins, lightmaxs, modelorg;
- q3msurface_t *surface;
+ msurface_t *surface;
int surfacelistindex;
if (r_drawcollisionbrushes.integer < 2)
{
Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
{
- surface = model->brushq3.data_faces + surfacelist[surfacelistindex];
+ surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
if (r_shadow_compilingrtlight)
{
// if compiling an rtlight, capture the mesh
msurface_t *surface;
for (surfacenum = 0, mark = leaf->firstleafsurface;surfacenum < leaf->numleafsurfaces;surfacenum++, mark++)
{
- surface = info->model->brushq1.surfaces + *mark;
+ surface = info->model->brush.data_surfaces + *mark;
if (surface->flags & SURF_SOLIDCLIP)
{
#if 0
int i, ds, dt;
msurface_t *surface;
- surface = r_refdef.worldmodel->brushq1.surfaces + node->firstsurface;
+ surface = r_refdef.worldmodel->brush.data_surfaces + node->firstsurface;
for (i = 0;i < node->numsurfaces;i++, surface++)
{
- if (!(surface->flags & SURF_LIGHTMAP) || !surface->samples)
+ if (!(surface->texture->flags & SURF_LIGHTMAP) || !surface->samples)
continue; // no lightmaps
ds = (int) (x * surface->texinfo->vecs[0][0] + y * surface->texinfo->vecs[0][1] + mid * surface->texinfo->vecs[0][2] + surface->texinfo->vecs[0][3]) - surface->texturemins[0];
if (l->filelen % sizeof(*in))
Host_Error("Mod_Q1BSP_LoadFaces: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in);
- loadmodel->brushq1.surfaces = Mem_Alloc(loadmodel->mempool, count*sizeof(msurface_t));
+ loadmodel->brush.data_surfaces = Mem_Alloc(loadmodel->mempool, count*sizeof(msurface_t));
- loadmodel->brushq1.numsurfaces = count;
+ loadmodel->brush.num_surfaces = count;
totalverts = 0;
totaltris = 0;
totalverts = 0;
totaltris = 0;
- for (surfacenum = 0, in = (void *)(mod_base + l->fileofs), surface = loadmodel->brushq1.surfaces;surfacenum < count;surfacenum++, in++, surface++)
+ for (surfacenum = 0, in = (void *)(mod_base + l->fileofs), surface = loadmodel->brush.data_surfaces;surfacenum < count;surfacenum++, in++, surface++)
{
- surface->number = surfacenum;
// FIXME: validate edges, texinfo, etc?
firstedge = LittleLong(in->firstedge);
numedges = LittleShort(in->numedges);
if ((unsigned int) i >= (unsigned int) loadmodel->brushq1.numtexinfo)
Host_Error("Mod_Q1BSP_LoadFaces: invalid texinfo index %i(model has %i texinfos)\n", i, loadmodel->brushq1.numtexinfo);
surface->texinfo = loadmodel->brushq1.texinfo + i;
- surface->flags = surface->texinfo->texture->flags;
+ surface->texture = surface->texinfo->texture;
+ surface->flags = surface->texture->flags;
planenum = LittleShort(in->planenum);
if ((unsigned int) planenum >= (unsigned int) loadmodel->brush.num_planes)
VectorCopy(loadmodel->brushq1.vertexes[loadmodel->brushq1.edges[-lindex].v[1]].position, surface->mesh.data_vertex3f + i * 3);
s = DotProduct((surface->mesh.data_vertex3f + i * 3), surface->texinfo->vecs[0]) + surface->texinfo->vecs[0][3];
t = DotProduct((surface->mesh.data_vertex3f + i * 3), surface->texinfo->vecs[1]) + surface->texinfo->vecs[1][3];
- surface->mesh.data_texcoordtexture2f[i * 2 + 0] = s / surface->texinfo->texture->width;
- surface->mesh.data_texcoordtexture2f[i * 2 + 1] = t / surface->texinfo->texture->height;
+ surface->mesh.data_texcoordtexture2f[i * 2 + 0] = s / surface->texture->width;
+ surface->mesh.data_texcoordtexture2f[i * 2 + 1] = t / surface->texture->height;
surface->mesh.data_texcoorddetail2f[i * 2 + 0] = s * (1.0f / 16.0f);
surface->mesh.data_texcoorddetail2f[i * 2 + 1] = t * (1.0f / 16.0f);
surface->mesh.data_texcoordlightmap2f[i * 2 + 0] = 0;
else // LordHavoc: white lighting (bsp version 29)
surface->samples = loadmodel->brushq1.lightdata + (i * 3);
- if (surface->texinfo->texture->flags & SURF_LIGHTMAP)
+ if (surface->texture->flags & SURF_LIGHTMAP)
{
if (ssize > 256 || tsize > 256)
Host_Error("Bad surface extents");
memset(surface->stainsamples, 255, ssize * tsize * 3);
}
- if (surface->texinfo->texture->flags & SURF_LIGHTMAP)
+ if (surface->texture->flags & SURF_LIGHTMAP)
{
int i, iu, iv;
float u, v, ubase, vbase, uscale, vscale;
for (i = 0;i < loadmodel->brush.num_leafsurfaces;i++)
{
j = (unsigned) LittleShort(in[i]);
- if (j >= loadmodel->brushq1.numsurfaces)
+ if (j >= loadmodel->brush.num_surfaces)
Host_Error("Mod_Q1BSP_LoadLeaffaces: bad surface number");
loadmodel->brush.data_leafsurfaces[i] = j;
}
memset(stylecounts, 0, sizeof(stylecounts));
for (i = 0;i < model->nummodelsurfaces;i++)
{
- surface = model->brushq1.surfaces + model->firstmodelsurface + i;
+ surface = model->brush.data_surfaces + model->firstmodelsurface + i;
for (j = 0;j < MAXLIGHTMAPS;j++)
stylecounts[surface->styles[j]]++;
}
}
for (i = 0;i < model->nummodelsurfaces;i++)
{
- surface = model->brushq1.surfaces + model->firstmodelsurface + i;
+ surface = model->brush.data_surfaces + model->firstmodelsurface + i;
for (j = 0;j < MAXLIGHTMAPS;j++)
if (surface->styles[j] != 255)
*model->brushq1.light_styleupdatechains[remapstyles[surface->styles[j]]]++ = surface;
{
for (leafsurfacenum = 0;leafsurfacenum < leaf->numleafsurfaces;leafsurfacenum++)
{
- surface = model->brushq1.surfaces + leaf->firstleafsurface[leafsurfacenum];
+ surface = model->brush.data_surfaces + leaf->firstleafsurface[leafsurfacenum];
if (surface->shadowmark != shadowmarkcount)
{
surface->shadowmark = shadowmarkcount;
// make a single combined shadow mesh to allow optimized shadow volume creation
numshadowmeshtriangles = 0;
- for (j = 0, surface = loadmodel->brushq1.surfaces;j < loadmodel->brushq1.numsurfaces;j++, surface++)
+ for (j = 0, surface = loadmodel->brush.data_surfaces;j < loadmodel->brush.num_surfaces;j++, surface++)
{
surface->num_firstshadowmeshtriangle = numshadowmeshtriangles;
numshadowmeshtriangles += surface->mesh.num_triangles;
}
loadmodel->brush.shadowmesh = Mod_ShadowMesh_Begin(loadmodel->mempool, numshadowmeshtriangles * 3, numshadowmeshtriangles, NULL, NULL, NULL, false, false, true);
- for (j = 0, surface = loadmodel->brushq1.surfaces;j < loadmodel->brushq1.numsurfaces;j++, surface++)
+ for (j = 0, surface = loadmodel->brush.data_surfaces;j < loadmodel->brush.num_surfaces;j++, surface++)
Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, surface->mesh.data_vertex3f, NULL, NULL, NULL, NULL, surface->mesh.num_triangles, surface->mesh.data_element3i);
loadmodel->brush.shadowmesh = Mod_ShadowMesh_Finish(loadmodel->mempool, loadmodel->brush.shadowmesh, false, true);
Mod_BuildTriangleNeighbors(loadmodel->brush.shadowmesh->neighbor3i, loadmodel->brush.shadowmesh->element3i, loadmodel->brush.shadowmesh->numtriangles);
mod->normalmaxs[0] = mod->normalmaxs[1] = mod->normalmaxs[2] = -1000000000.0f;
modelyawradius = 0;
modelradius = 0;
- for (j = 0, surface = &mod->brushq1.surfaces[mod->firstmodelsurface];j < mod->nummodelsurfaces;j++, surface++)
+ for (j = 0, surface = &mod->brush.data_surfaces[mod->firstmodelsurface];j < mod->nummodelsurfaces;j++, surface++)
{
// we only need to have a drawsky function if it is used(usually only on world model)
- if (surface->texinfo->texture->flags & SURF_DRAWSKY)
+ if (surface->texture->flags & SURF_DRAWSKY)
mod->DrawSky = R_Q1BSP_DrawSky;
// LordHavoc: submodels always clip, even if water
- if (mod->brush.numsubmodels - 1)
+ if (i)
surface->flags |= SURF_SOLIDCLIP;
// calculate bounding shapes
for (k = 0, vec = surface->mesh.data_vertex3f;k < surface->mesh.num_vertices;k++, vec += 3)
//Mod_Q1BSP_ProcessLightList();
if (developer.integer)
- Con_Printf("Some stats for q1bsp model \"%s\": %i faces, %i nodes, %i leafs, %i visleafs, %i visleafportals\n", loadmodel->name, loadmodel->brushq1.numsurfaces, loadmodel->brush.num_nodes, loadmodel->brush.num_leafs, mod->brushq1.submodels[i].visleafs, loadmodel->brush.num_portals);
+ Con_Printf("Some stats for q1bsp model \"%s\": %i faces, %i nodes, %i leafs, %i visleafs, %i visleafportals\n", loadmodel->name, loadmodel->brush.num_surfaces, loadmodel->brush.num_nodes, loadmodel->brush.num_leafs, mod->brushq1.submodels[i].visleafs, loadmodel->brush.num_portals);
}
static void Mod_Q2BSP_LoadEntities(lump_t *l)
static void Mod_Q3BSP_LoadFaces(lump_t *l)
{
q3dface_t *in, *oldin;
- q3msurface_t *out, *oldout;
+ msurface_t *out, *oldout;
int i, oldi, j, n, count, invalidelements, patchsize[2], finalwidth, finalheight, xtess, ytess, finalvertices, finaltriangles, firstvertex, firstelement, type, oldnumtriangles, oldnumtriangles2, meshnum, meshvertices, meshtriangles, numvertices, numtriangles;
//int *originalelement3i;
//int *originalneighbor3i;
count = l->filelen / sizeof(*in);
out = Mem_Alloc(loadmodel->mempool, count * sizeof(*out));
- loadmodel->brushq3.data_faces = out;
- loadmodel->brushq3.num_faces = count;
+ loadmodel->brush.data_surfaces = out;
+ loadmodel->brush.num_surfaces = count;
i = 0;
for (meshnum = 0;i < count;meshnum++)
}
n = LittleLong(in->firstface);
c = LittleLong(in->numfaces);
- if (n < 0 || n + c > loadmodel->brushq3.num_faces)
- Host_Error("Mod_Q3BSP_LoadModels: invalid face range %i : %i (%i faces)\n", n, n + c, loadmodel->brushq3.num_faces);
- out->firstsurface = loadmodel->brushq3.data_faces + n;
+ if (n < 0 || n + c > loadmodel->brush.num_surfaces)
+ Host_Error("Mod_Q3BSP_LoadModels: invalid face range %i : %i (%i faces)\n", n, n + c, loadmodel->brush.num_surfaces);
+ out->firstsurface = loadmodel->brush.data_surfaces + n;
out->numsurfaces = c;
n = LittleLong(in->firstbrush);
c = LittleLong(in->numbrushes);
for (i = 0;i < count;i++, in++, out++)
{
n = LittleLong(*in);
- if (n < 0 || n >= loadmodel->brushq3.num_faces)
- Host_Error("Mod_Q3BSP_LoadLeafFaces: invalid face index %i (%i faces)\n", n, loadmodel->brushq3.num_faces);
+ if (n < 0 || n >= loadmodel->brush.num_surfaces)
+ Host_Error("Mod_Q3BSP_LoadLeafFaces: invalid face index %i (%i faces)\n", n, loadmodel->brush.num_surfaces);
*out = n;
}
}
int i, startside, endside;
float dist1, dist2, midfrac, mid[3], nodesegmentmins[3], nodesegmentmaxs[3];
mleaf_t *leaf;
- q3msurface_t *surface;
+ msurface_t *surface;
colbrushf_t *brush;
if (startfrac > trace->realfraction)
return;
// line trace the curves
for (i = 0;i < leaf->numleafsurfaces;i++)
{
- surface = model->brushq3.data_faces + leaf->firstleafsurface[i];
+ surface = model->brush.data_surfaces + leaf->firstleafsurface[i];
if (surface->mesh.num_collisiontriangles && surface->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, surface->mins, surface->maxs))
{
surface->collisionmarkframe = markframe;
float nodesegmentmins[3], nodesegmentmaxs[3];
mleaf_t *leaf;
colbrushf_t *brush;
- q3msurface_t *surface;
+ msurface_t *surface;
/*
// find which nodes the line is in and recurse for them
while (node->plane)
{
for (i = 0;i < leaf->numleafsurfaces;i++)
{
- surface = model->brushq3.data_faces + leaf->firstleafsurface[i];
+ surface = model->brush.data_surfaces + leaf->firstleafsurface[i];
if (surface->mesh.num_collisiontriangles && surface->collisionmarkframe != markframe && BoxesOverlap(nodesegmentmins, nodesegmentmaxs, surface->mins, surface->maxs))
{
surface->collisionmarkframe = markframe;
colbrushf_t *thisbrush_start, *thisbrush_end;
matrix4x4_t startmatrix, endmatrix;
static int markframe = 0;
- q3msurface_t *surface;
+ msurface_t *surface;
memset(trace, 0, sizeof(*trace));
trace->fraction = 1;
trace->realfraction = 1;
int i, j, numshadowmeshtriangles;
q3dheader_t *header;
float corner[3], yawradius, modelradius;
- q3msurface_t *surface;
+ msurface_t *surface;
mod->type = mod_brushq3;
mod->numframes = 2; // although alternate textures are not supported it is annoying to complain about no such frame 1
// make a single combined shadow mesh to allow optimized shadow volume creation
numshadowmeshtriangles = 0;
- for (j = 0, surface = loadmodel->brushq3.data_faces;j < loadmodel->brushq3.num_faces;j++, surface++)
+ for (j = 0, surface = loadmodel->brush.data_surfaces;j < loadmodel->brush.num_surfaces;j++, surface++)
{
surface->num_firstshadowmeshtriangle = numshadowmeshtriangles;
numshadowmeshtriangles += surface->mesh.num_triangles;
}
loadmodel->brush.shadowmesh = Mod_ShadowMesh_Begin(loadmodel->mempool, numshadowmeshtriangles * 3, numshadowmeshtriangles, NULL, NULL, NULL, false, false, true);
- for (j = 0, surface = loadmodel->brushq3.data_faces;j < loadmodel->brushq3.num_faces;j++, surface++)
+ for (j = 0, surface = loadmodel->brush.data_surfaces;j < loadmodel->brush.num_surfaces;j++, surface++)
Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, surface->mesh.data_vertex3f, NULL, NULL, NULL, NULL, surface->mesh.num_triangles, surface->mesh.data_element3i);
loadmodel->brush.shadowmesh = Mod_ShadowMesh_Finish(loadmodel->mempool, loadmodel->brush.shadowmesh, false, true);
Mod_BuildTriangleNeighbors(loadmodel->brush.shadowmesh->neighbor3i, loadmodel->brush.shadowmesh->element3i, loadmodel->brush.shadowmesh->numtriangles);
mod->brush.submodel = i;
// make the model surface list (used by shadowing/lighting)
- mod->firstmodelsurface = mod->brushq3.data_models[i].firstsurface - mod->brushq3.data_faces;
+ mod->firstmodelsurface = mod->brushq3.data_models[i].firstsurface - mod->brush.data_surfaces;
mod->nummodelsurfaces = mod->brushq3.data_models[i].numsurfaces;
mod->surfacelist = Mem_Alloc(loadmodel->mempool, mod->nummodelsurfaces * sizeof(*mod->surfacelist));
for (j = 0;j < mod->nummodelsurfaces;j++)
}
mtexinfo_t;
+struct q3meffect_s;
typedef struct msurface_s
{
// bounding box for onscreen checks
vec3_t mins;
vec3_t maxs;
-
- // the node plane this is on, backwards if SURF_PLANEBACK flag set
- mplane_t *plane;
- // SURF_ flags
- int flags;
- // texture mapping properties used by this surface
- mtexinfo_t *texinfo;
-
+ // the texture to use on the surface
+ texture_t *texture;
// the lightmap texture fragment to use on the rendering mesh
rtexture_t *lightmaptexture;
// mesh for rendering
surfmesh_t mesh;
- // if lightmap settings changed, this forces update
- int cached_dlight;
-
- // surface number, to avoid having to do a divide to find the number of a surface from it's address
- int number;
+ // index into model->brush.shadowmesh
+ int num_firstshadowmeshtriangle;
+ // the node plane this is on, backwards if SURF_PLANEBACK flag set
+ mplane_t *plane; // q1bsp
+ // SURF_ flags
+ int flags; // q1bsp
+ // texture mapping properties used by this surface
+ mtexinfo_t *texinfo; // q1bsp
+ // if lightmap settings changed, this forces update
+ int cached_dlight; // q1bsp
// index into d_lightstylevalue array, 255 means not used (black)
- qbyte styles[MAXLIGHTMAPS];
+ qbyte styles[MAXLIGHTMAPS]; // q1bsp
// RGB lighting data [numstyles][height][width][3]
- qbyte *samples;
+ qbyte *samples; // q1bsp
// stain to apply on lightmap (soot/dirt/blood/whatever)
- qbyte *stainsamples;
+ qbyte *stainsamples; // q1bsp
// the stride when building lightmaps to comply with fragment update
- int lightmaptexturestride;
- int texturemins[2];
- int extents[2];
-
+ int lightmaptexturestride; // q1bsp
+ int texturemins[2]; // q1bsp
+ int extents[2]; // q1bsp
// if this == r_framecount there are dynamic lights on the surface
- int dlightframe;
+ int dlightframe; // q1bsp
// which dynamic lights are touching this surface
// (only access this if dlightframe is current)
- int dlightbits[8];
- // avoid redundent addition of dlights
- int lightframe;
-
- // avoid multiple collision traces with a surface polygon
- int colframe;
-
- // index into model->brush.shadowmesh
- int num_firstshadowmeshtriangle;
+ int dlightbits[8]; // q1bsp
- // currently used only for generating static shadow volumes
- int lighttemp_castshadow;
-
- // avoid redundent surface shadows
- int shadowmark;
+ struct q3meffect_s *effect; // q3bsp
+ // FIXME: collisionmarkframe should be kept in a separate array
+ int collisionmarkframe; // q3bsp // don't collide twice in one trace
}
msurface_t;
#define Q3TEXTUREFLAG_AUTOSPRITE2 32
#define Q3TEXTUREFLAG_ALPHATEST 64
-struct q3msurface_s;
-
typedef struct q3mmodel_s
{
vec3_t mins;
vec3_t maxs;
int numsurfaces;
- struct q3msurface_s *firstsurface;
+ struct msurface_s *firstsurface;
int numbrushes;
struct q3mbrush_s *firstbrush;
}
}
q3meffect_t;
-typedef struct q3msurface_s
-{
- // bounding box for culling
- vec3_t mins;
- vec3_t maxs;
-
- // FIXME: collisionmarkframe should be kept in a separate array
- // FIXME: shadowmark should be kept in a separate array
-
- struct texture_s *texture;
- struct q3meffect_s *effect;
- rtexture_t *lightmaptexture;
- int collisionmarkframe; // don't collide twice in one trace
-
- surfmesh_t mesh;
-
- // index into model->brush.shadowmesh
- int num_firstshadowmeshtriangle;
-
- // used for shadow volume generation
- int shadowmark;
-}
-q3msurface_t;
-
#define CHECKPVSBIT(pvs,b) ((b) >= 0 ? ((pvs)[(b) >> 3] & (1 << ((b) & 7))) : false)
#define SETPVSBIT(pvs,b) ((b) >= 0 ? ((pvs)[(b) >> 3] |= (1 << ((b) & 7))) : false)
#define CLEARPVSBIT(pvs,b) ((b) >= 0 ? ((pvs)[(b) >> 3] &= ~(1 << ((b) & 7))) : false)
{
if (mod_known[i].name[0] && mod_known[i].type == mod_brushq1)
{
- for (surfacenum = 0, surface = mod_known[i].brushq1.surfaces;surfacenum < mod_known[i].brushq1.numsurfaces;surfacenum++, surface++)
+ for (surfacenum = 0, surface = mod_known[i].brush.data_surfaces;surfacenum < mod_known[i].brush.num_surfaces;surfacenum++, surface++)
{
- if (surface->texinfo->texture->flags & SURF_LIGHTMAP)
+ if (surface->texture->flags & SURF_LIGHTMAP)
{
ssize = (surface->extents[0] >> 4) + 1;
tsize = (surface->extents[1] >> 4) + 1;
int num_textures;
texture_t *data_textures;
+ int num_surfaces;
+ msurface_t *data_surfaces;
+
// pvs
int num_pvsclusters;
int num_pvsclusterbytes;
int numtexinfo;
mtexinfo_t *texinfo;
- int numsurfaces;
- msurface_t *surfaces;
- msurface_t *surfacepvsnext;
-
int numsurfedges;
int *surfedges;
int num_effects;
q3meffect_t *data_effects;
- int num_faces;
- q3msurface_t *data_faces;
-
// lightmap textures
int num_lightmaps;
rtexture_t **data_lightmaps;
if (!info->surfacemark[*mark])
{
// FIXME? this assumes q1bsp polygon surfaces
- surface = info->model->brushq1.surfaces + *mark;
- if (surface->mesh.num_vertices)
+ surface = info->model->brush.data_surfaces + *mark;
+ for (j = 0, elements = surface->mesh.data_element3i;j < surface->mesh.num_triangles;j++, elements += 3)
{
- if (surface->flags & SURF_PLANEBACK)
+ VectorCopy((surface->mesh.data_vertex3f + elements[0] * 3), trianglepoints[0]);
+ VectorCopy((surface->mesh.data_vertex3f + elements[1] * 3), trianglepoints[1]);
+ VectorCopy((surface->mesh.data_vertex3f + elements[2] * 3), trianglepoints[2]);
+ if (PointInfrontOfTriangle(info->eye, trianglepoints[0], trianglepoints[1], trianglepoints[2]))
{
- if (DotProduct(info->eye, surface->plane->normal) > surface->plane->dist)
- continue;
+ trimins[0] = min(trianglepoints[0][0], min(trianglepoints[1][0], trianglepoints[2][0]));
+ trimaxs[0] = max(trianglepoints[0][0], max(trianglepoints[1][0], trianglepoints[2][0]));
+ trimins[1] = min(trianglepoints[0][1], min(trianglepoints[1][1], trianglepoints[2][1]));
+ trimaxs[1] = max(trianglepoints[0][1], max(trianglepoints[1][1], trianglepoints[2][1]));
+ trimins[2] = min(trianglepoints[0][2], min(trianglepoints[1][2], trianglepoints[2][2]));
+ trimaxs[2] = max(trianglepoints[0][2], max(trianglepoints[1][2], trianglepoints[2][2]));
+ if (BoxesOverlap(trimins, trimaxs, info->boxmins, info->boxmaxs))
+ if (Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, trianglepoints[0], 3, &portaltemppoints2[0][0], 256) >= 3)
+ break;
}
- else
- {
- if (DotProduct(info->eye, surface->plane->normal) < surface->plane->dist)
- continue;
- }
- if (Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, surface->mesh.data_vertex3f, surface->mesh.num_vertices, &portaltemppoints2[0][0], 256) < 3)
- continue;
- }
- else
- {
- for (j = 0, elements = surface->mesh.data_element3i;j < surface->mesh.num_triangles;j++, elements += 3)
- {
- VectorCopy((surface->mesh.data_vertex3f + elements[0] * 3), trianglepoints[0]);
- VectorCopy((surface->mesh.data_vertex3f + elements[1] * 3), trianglepoints[1]);
- VectorCopy((surface->mesh.data_vertex3f + elements[2] * 3), trianglepoints[2]);
- if (PointInfrontOfTriangle(info->eye, trianglepoints[0], trianglepoints[1], trianglepoints[2]))
- {
- trimins[0] = min(trianglepoints[0][0], min(trianglepoints[1][0], trianglepoints[2][0]));
- trimaxs[0] = max(trianglepoints[0][0], max(trianglepoints[1][0], trianglepoints[2][0]));
- trimins[1] = min(trianglepoints[0][1], min(trianglepoints[1][1], trianglepoints[2][1]));
- trimaxs[1] = max(trianglepoints[0][1], max(trianglepoints[1][1], trianglepoints[2][1]));
- trimins[2] = min(trianglepoints[0][2], min(trianglepoints[1][2], trianglepoints[2][2]));
- trimaxs[2] = max(trianglepoints[0][2], max(trianglepoints[1][2], trianglepoints[2][2]));
- if (BoxesOverlap(trimins, trimaxs, info->boxmins, info->boxmaxs))
- if (Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, trianglepoints[0], 3, &portaltemppoints2[0][0], 256) >= 3)
- break;
- }
- }
- if (j == surface->mesh.num_triangles)
- continue;
}
+ if (j == surface->mesh.num_triangles)
+ continue;
info->surfacemark[*mark] = true;
}
}
static void clippointtosurface(msurface_t *surface, vec3_t p, vec3_t out)
{
- int i, j;
- vec3_t v1, clipplanenormal, normal;
- vec_t clipplanedist, clipdist;
+ int i, j, k;
+ float *v[3], facenormal[3], edgenormal[3], sidenormal[3], temp[3], offsetdist, dist, bestdist;
+ bestdist = 1000000000;
VectorCopy(p, out);
- if (surface->flags & SURF_PLANEBACK)
- VectorNegate(surface->plane->normal, normal);
- else
- VectorCopy(surface->plane->normal, normal);
- for (i = 0, j = surface->mesh.num_vertices - 1;i < surface->mesh.num_vertices;j = i, i++)
- {
- VectorSubtract(&surface->mesh.data_vertex3f[j * 3], &surface->mesh.data_vertex3f[i * 3], v1);
- VectorNormalizeFast(v1);
- CrossProduct(v1, normal, clipplanenormal);
- clipplanedist = DotProduct(&surface->mesh.data_vertex3f[i * 3], clipplanenormal);
- clipdist = DotProduct(out, clipplanenormal) - clipplanedist;
- if (clipdist > 0)
+ for (i = 0;i < surface->mesh.num_triangles;i++)
+ {
+ // clip original point to each triangle of the surface and find the
+ // triangle that is closest
+ v[0] = surface->mesh.data_vertex3f + surface->mesh.data_element3i[i * 3 + 0] * 3;
+ v[1] = surface->mesh.data_vertex3f + surface->mesh.data_element3i[i * 3 + 1] * 3;
+ v[2] = surface->mesh.data_vertex3f + surface->mesh.data_element3i[i * 3 + 2] * 3;
+ TriangleNormal(v[0], v[1], v[2], facenormal);
+ VectorNormalize(facenormal);
+ offsetdist = DotProduct(v[0], facenormal) - DotProduct(p, facenormal);
+ VectorMA(p, offsetdist, facenormal, temp);
+ for (j = 0, k = 2;j < 3;k = j, j++)
+ {
+ VectorSubtract(v[k], v[j], edgenormal);
+ CrossProduct(edgenormal, facenormal, sidenormal);
+ VectorNormalize(sidenormal);
+ offsetdist = DotProduct(v[k], sidenormal) - DotProduct(temp, sidenormal);
+ if (offsetdist < 0)
+ VectorMA(temp, offsetdist, sidenormal, temp);
+ }
+ dist = VectorDistance2(temp, p);
+ if (bestdist > dist)
{
- clipdist = -clipdist;
- VectorMA(out, clipdist, clipplanenormal, out);
+ bestdist = dist;
+ VectorCopy(temp, out);
}
}
}
model = sv.models[modelindex];
if (surfacenum < 0 || surfacenum >= model->nummodelsurfaces)
return NULL;
- return model->brushq1.surfaces + surfacenum + model->firstmodelsurface;
+ return model->brush.data_surfaces + surfacenum + model->firstmodelsurface;
}
return;
}
+ // note: this (incorrectly) assumes it is a simple polygon
G_FLOAT(OFS_RETURN) = surface->mesh.num_vertices;
}
//PF_getsurfacepoint, // #435 vector(entity e, float s, float n) getsurfacepoint = #435;
return;
if (!(surface = getsurface(ed, G_FLOAT(OFS_PARM1))))
return;
+ // note: this (incorrectly) assumes it is a simple polygon
pointnum = G_FLOAT(OFS_PARM2);
if (pointnum < 0 || pointnum >= surface->mesh.num_vertices)
return;
void PF_getsurfacenormal(void)
{
msurface_t *surface;
+ vec3_t normal;
VectorClear(G_VECTOR(OFS_RETURN));
if (!(surface = getsurface(G_EDICT(OFS_PARM0), G_FLOAT(OFS_PARM1))))
return;
// FIXME: implement rotation/scaling
- if (surface->flags & SURF_PLANEBACK)
- VectorNegate(surface->plane->normal, G_VECTOR(OFS_RETURN));
- else
- VectorCopy(surface->plane->normal, G_VECTOR(OFS_RETURN));
+ // note: this (incorrectly) assumes it is a simple polygon
+ // note: this only returns the first triangle, so it doesn't work very
+ // well for curved surfaces or arbitrary meshes
+ TriangleNormal(surface->mesh.data_vertex3f, surface->mesh.data_vertex3f + 3, surface->mesh.data_vertex3f + 6, normal);
+ VectorNormalize(normal);
+ VectorCopy(normal, G_VECTOR(OFS_RETURN));
}
//PF_getsurfacetexture, // #437 string(entity e, float s) getsurfacetexture = #437;
void PF_getsurfacetexture(void)
G_INT(OFS_RETURN) = 0;
if (!(surface = getsurface(G_EDICT(OFS_PARM0), G_FLOAT(OFS_PARM1))))
return;
- G_INT(OFS_RETURN) = PR_SetString(surface->texinfo->texture->name);
+ G_INT(OFS_RETURN) = PR_SetString(surface->texture->name);
}
//PF_getsurfacenearpoint, // #438 float(entity e, vector p) getsurfacenearpoint = #438;
void PF_getsurfacenearpoint(void)
if (modelindex < 1 || modelindex >= MAX_MODELS)
return;
model = sv.models[modelindex];
- if (!model->brushq1.numsurfaces)
+ if (!model->brush.num_surfaces)
return;
// FIXME: implement rotation/scaling
bestdist = 1000000000;
for (surfacenum = 0;surfacenum < model->nummodelsurfaces;surfacenum++)
{
- surface = model->brushq1.surfaces + surfacenum + model->firstmodelsurface;
- dist = PlaneDiff(p, surface->plane);
- dist = dist * dist;
+ surface = model->brush.data_surfaces + surfacenum + model->firstmodelsurface;
+ // first see if the nearest point on the surface's box is closer than the previous match
+ clipped[0] = bound(surface->mins[0], p[0], surface->maxs[0]) - p[0];
+ clipped[1] = bound(surface->mins[1], p[1], surface->maxs[1]) - p[1];
+ clipped[2] = bound(surface->mins[2], p[2], surface->maxs[2]) - p[2];
+ dist = VectorLength2(clipped);
if (dist < bestdist)
{
+ // it is, check the nearest point on the actual geometry
clippointtosurface(surface, p, clipped);
VectorSubtract(clipped, p, clipped);
- dist += DotProduct(clipped, clipped);
+ dist += VectorLength2(clipped);
if (dist < bestdist)
{
+ // that's closer too, store it as the best match
best = surfacenum;
bestdist = dist;
}
{
if (ent == r_refdef.worldentity && !r_worldsurfacevisible[leaf->firstleafsurface[i]])
continue;
- surface = ent->model->brushq1.surfaces + leaf->firstleafsurface[i];
+ surface = ent->model->brush.data_surfaces + leaf->firstleafsurface[i];
dist = sdist = PlaneDiff(lightorigin, surface->plane);
if (surface->flags & SURF_PLANEBACK)
dist = -dist;
- if (dist < -0.25f && !(surface->flags & SURF_LIGHTBOTHSIDES))
+ if (dist < -0.25f && !(surface->texture->flags & SURF_LIGHTBOTHSIDES))
continue;
dist2 = dist * dist;