mirror of
https://github.com/Garux/netradiant-custom.git
synced 2026-09-28 00:00:03 +02:00
minor tweaks
This commit is contained in:
@@ -491,7 +491,7 @@ void ProcessDecals(){
|
||||
projects a decal onto a winding
|
||||
*/
|
||||
|
||||
static void ProjectDecalOntoWinding( decalProjector_t *dp, mapDrawSurface_t *ds, winding_t& w ){
|
||||
static void ProjectDecalOntoWinding( decalProjector_t& dp, const mapDrawSurface_t& ds, winding_t& w ){
|
||||
/* dummy check */
|
||||
if ( w.size() < 3 ) {
|
||||
return;
|
||||
@@ -508,15 +508,15 @@ static void ProjectDecalOntoWinding( decalProjector_t *dp, mapDrawSurface_t *ds,
|
||||
}
|
||||
|
||||
/* backface check */
|
||||
if ( vector3_dot( dp->planes[ 0 ].normal(), plane.normal() ) < -0.0001f ) {
|
||||
if ( vector3_dot( dp.planes[ 0 ].normal(), plane.normal() ) < -0.0001f ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* walk list of planes */
|
||||
for ( int i = 0; i < dp->numPlanes; ++i )
|
||||
for ( int i = 0; i < dp.numPlanes; ++i )
|
||||
{
|
||||
/* chop winding by the plane */
|
||||
auto [front, back] = ClipWindingEpsilonStrict( w, dp->planes[ i ], 0.0625f ); /* strict, if identical plane we don't want to keep it */
|
||||
auto [front, back] = ClipWindingEpsilonStrict( w, dp.planes[ i ], 0.0625f ); /* strict, if identical plane we don't want to keep it */
|
||||
|
||||
/* lose the front fragment */
|
||||
/* if nothing left in back, then bail */
|
||||
@@ -537,36 +537,36 @@ static void ProjectDecalOntoWinding( decalProjector_t *dp, mapDrawSurface_t *ds,
|
||||
numDecalSurfaces++;
|
||||
|
||||
/* make a new surface */
|
||||
mapDrawSurface_t *ds2 = AllocDrawSurface( ESurfaceType::Decal );
|
||||
mapDrawSurface_t& ds2 = AllocDrawSurface( ESurfaceType::Decal );
|
||||
|
||||
/* set it up */
|
||||
ds2->entityNum = ds->entityNum;
|
||||
ds2->castShadows = ds->castShadows;
|
||||
ds2->recvShadows = ds->recvShadows;
|
||||
ds2->shaderInfo = dp->si;
|
||||
ds2->fogNum = ds->fogNum; /* why was this -1? */
|
||||
ds2->lightmapScale = ds->lightmapScale;
|
||||
ds2->shadeAngleDegrees = ds->shadeAngleDegrees;
|
||||
ds2->ambientColor = ds->ambientColor;
|
||||
ds2->numVerts = w.size();
|
||||
ds2->verts = safe_calloc( ds2->numVerts * sizeof( *ds2->verts ) );
|
||||
ds2.entityNum = ds.entityNum;
|
||||
ds2.castShadows = ds.castShadows;
|
||||
ds2.recvShadows = ds.recvShadows;
|
||||
ds2.shaderInfo = dp.si;
|
||||
ds2.fogNum = ds.fogNum; /* why was this -1? */
|
||||
ds2.lightmapScale = ds.lightmapScale;
|
||||
ds2.shadeAngleDegrees = ds.shadeAngleDegrees;
|
||||
ds2.ambientColor = ds.ambientColor;
|
||||
ds2.numVerts = w.size();
|
||||
ds2.verts = safe_calloc( ds2.numVerts * sizeof( *ds2.verts ) );
|
||||
|
||||
/* set vertexes */
|
||||
for ( int i = 0; i < ds2->numVerts; ++i )
|
||||
for ( int i = 0; i < ds2.numVerts; ++i )
|
||||
{
|
||||
/* get vertex */
|
||||
bspDrawVert_t& dv = ds2->verts[ i ];
|
||||
bspDrawVert_t& dv = ds2.verts[ i ];
|
||||
|
||||
/* set alpha */
|
||||
const float d = plane3_distance_to_point( dp->planes[ 0 ], w[ i ] );
|
||||
const float d2 = plane3_distance_to_point( dp->planes[ 1 ], w[ i ] );
|
||||
const float d = plane3_distance_to_point( dp.planes[ 0 ], w[ i ] );
|
||||
const float d2 = plane3_distance_to_point( dp.planes[ 1 ], w[ i ] );
|
||||
const float alpha = 255.0f * d2 / ( d + d2 );
|
||||
|
||||
/* set misc */
|
||||
dv.xyz = w[ i ] - entityOrigin;
|
||||
dv.normal = plane.normal();
|
||||
dv.st[ 0 ] = vector3_dot( dv.xyz, dp->texMat[ 0 ].vec3() ) + dp->texMat[ 0 ][ 3 ];
|
||||
dv.st[ 1 ] = vector3_dot( dv.xyz, dp->texMat[ 1 ].vec3() ) + dp->texMat[ 1 ][ 3 ];
|
||||
dv.st[ 0 ] = vector3_dot( dv.xyz, dp.texMat[ 0 ].vec3() ) + dp.texMat[ 0 ][ 3 ];
|
||||
dv.st[ 1 ] = vector3_dot( dv.xyz, dp.texMat[ 1 ].vec3() ) + dp.texMat[ 1 ][ 3 ];
|
||||
|
||||
/* set color */
|
||||
for ( int j = 0; j < MAX_LIGHTMAPS; ++j )
|
||||
@@ -583,15 +583,15 @@ static void ProjectDecalOntoWinding( decalProjector_t *dp, mapDrawSurface_t *ds,
|
||||
projects a decal onto a brushface surface
|
||||
*/
|
||||
|
||||
static void ProjectDecalOntoFace( decalProjector_t *dp, mapDrawSurface_t *ds ){
|
||||
static void ProjectDecalOntoFace( decalProjector_t& dp, const mapDrawSurface_t& ds ){
|
||||
/* dummy check */
|
||||
if ( ds->sideRef == nullptr || ds->sideRef->side == nullptr ) {
|
||||
if ( ds.sideRef == nullptr || ds.sideRef->side == nullptr ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* backface check */
|
||||
if ( ds->planar ) {
|
||||
if ( vector3_dot( dp->planes[ 0 ].normal(), mapplanes[ ds->planeNum ].normal() ) < -0.0001f ) {
|
||||
if ( ds.planar ) {
|
||||
if ( vector3_dot( dp.planes[ 0 ].normal(), mapplanes[ ds.planeNum ].normal() ) < -0.0001f ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -608,18 +608,18 @@ static void ProjectDecalOntoFace( decalProjector_t *dp, mapDrawSurface_t *ds ){
|
||||
projects a decal onto a patch surface
|
||||
*/
|
||||
|
||||
static void ProjectDecalOntoPatch( decalProjector_t *dp, mapDrawSurface_t *ds ){
|
||||
static void ProjectDecalOntoPatch( decalProjector_t& dp, const mapDrawSurface_t& ds ){
|
||||
/* backface check */
|
||||
if ( ds->planar )
|
||||
if ( vector3_dot( dp->planes[ 0 ].normal(), mapplanes[ ds->planeNum ].normal() ) < -0.0001f )
|
||||
if ( ds.planar )
|
||||
if ( vector3_dot( dp.planes[ 0 ].normal(), mapplanes[ ds.planeNum ].normal() ) < -0.0001f )
|
||||
return;
|
||||
|
||||
/* tesselate the patch */
|
||||
mesh_t src;
|
||||
src.width = ds->patchWidth;
|
||||
src.height = ds->patchHeight;
|
||||
src.verts = ds->verts;
|
||||
const int iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions );
|
||||
src.width = ds.patchWidth;
|
||||
src.height = ds.patchHeight;
|
||||
src.verts = ds.verts;
|
||||
const int iterations = IterationsForCurve( ds.longestCurve, patchSubdivisions );
|
||||
mesh_t *subdivided = SubdivideMesh2( src, iterations );
|
||||
|
||||
/* fit it to the curve and remove colinear verts on rows/columns */
|
||||
@@ -670,28 +670,28 @@ static void ProjectDecalOntoPatch( decalProjector_t *dp, mapDrawSurface_t *ds ){
|
||||
projects a decal onto a triangle surface
|
||||
*/
|
||||
|
||||
static void ProjectDecalOntoTriangles( decalProjector_t *dp, mapDrawSurface_t *ds ){
|
||||
static void ProjectDecalOntoTriangles( decalProjector_t& dp, const mapDrawSurface_t& ds ){
|
||||
|
||||
/* triangle surfaces without shaders don't get marks by default */
|
||||
if ( ds->type == ESurfaceType::Triangles && ds->shaderInfo->shaderText == nullptr ) {
|
||||
if ( ds.type == ESurfaceType::Triangles && ds.shaderInfo->shaderText == nullptr ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* backface check */
|
||||
if ( ds->planar ) {
|
||||
if ( vector3_dot( dp->planes[ 0 ].normal(), mapplanes[ ds->planeNum ].normal() ) < -0.0001f ) {
|
||||
if ( ds.planar ) {
|
||||
if ( vector3_dot( dp.planes[ 0 ].normal(), mapplanes[ ds.planeNum ].normal() ) < -0.0001f ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* iterate through triangles */
|
||||
for ( int i = 0; i < ds->numIndexes; i += 3 )
|
||||
for ( int i = 0; i < ds.numIndexes; i += 3 )
|
||||
{
|
||||
/* generate decal */
|
||||
winding_t w{
|
||||
ds->verts[ ds->indexes[ i + 0 ] ].xyz,
|
||||
ds->verts[ ds->indexes[ i + 1 ] ].xyz,
|
||||
ds->verts[ ds->indexes[ i + 2 ] ].xyz };
|
||||
ds.verts[ ds.indexes[ i + 0 ] ].xyz,
|
||||
ds.verts[ ds.indexes[ i + 1 ] ].xyz,
|
||||
ds.verts[ ds.indexes[ i + 2 ] ].xyz };
|
||||
ProjectDecalOntoWinding( dp, ds, w );
|
||||
}
|
||||
}
|
||||
@@ -706,7 +706,6 @@ static void ProjectDecalOntoTriangles( decalProjector_t *dp, mapDrawSurface_t *d
|
||||
void MakeEntityDecals( const entity_t& e ){
|
||||
int i, j, fOld;
|
||||
decalProjector_t dp;
|
||||
mapDrawSurface_t *ds;
|
||||
|
||||
|
||||
/* note it */
|
||||
@@ -735,36 +734,36 @@ void MakeEntityDecals( const entity_t& e ){
|
||||
for ( j = e.firstDrawSurf; j < numMapDrawSurfs; ++j )
|
||||
{
|
||||
/* get surface */
|
||||
ds = &mapDrawSurfs[ j ];
|
||||
if ( ds->numVerts <= 0 ) {
|
||||
mapDrawSurface_t& ds = mapDrawSurfs[ j ];
|
||||
if ( ds.numVerts <= 0 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* ignore autosprite or nomarks */
|
||||
if ( ds->shaderInfo->autosprite || ( ds->shaderInfo->compileFlags & C_NOMARKS ) ) {
|
||||
if ( ds.shaderInfo->autosprite || ( ds.shaderInfo->compileFlags & C_NOMARKS ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* bounds check */
|
||||
if ( !ds->minmax.test( dp.center, dp.radius ) ) {
|
||||
if ( !ds.minmax.test( dp.center, dp.radius ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* switch on type */
|
||||
switch ( ds->type )
|
||||
switch ( ds.type )
|
||||
{
|
||||
case ESurfaceType::Face:
|
||||
ProjectDecalOntoFace( &dp, ds );
|
||||
ProjectDecalOntoFace( dp, ds );
|
||||
break;
|
||||
|
||||
case ESurfaceType::Patch:
|
||||
ProjectDecalOntoPatch( &dp, ds );
|
||||
ProjectDecalOntoPatch( dp, ds );
|
||||
break;
|
||||
|
||||
case ESurfaceType::Triangles:
|
||||
case ESurfaceType::ForcedMeta:
|
||||
case ESurfaceType::Meta:
|
||||
ProjectDecalOntoTriangles( &dp, ds );
|
||||
ProjectDecalOntoTriangles( dp, ds );
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
+39
-39
@@ -43,12 +43,12 @@ static int numFogPatchFragments;
|
||||
converts a patch drawsurface to a mesh_t
|
||||
*/
|
||||
|
||||
static mesh_t *DrawSurfToMesh( mapDrawSurface_t *ds ){
|
||||
static mesh_t *DrawSurfToMesh( const mapDrawSurface_t& ds ){
|
||||
mesh_t *m = safe_malloc( sizeof( *m ) );
|
||||
m->width = ds->patchWidth;
|
||||
m->height = ds->patchHeight;
|
||||
m->width = ds.patchWidth;
|
||||
m->height = ds.patchHeight;
|
||||
m->verts = safe_malloc( sizeof( m->verts[ 0 ] ) * m->width * m->height );
|
||||
memcpy( m->verts, ds->verts, sizeof( m->verts[ 0 ] ) * m->width * m->height );
|
||||
memcpy( m->verts, ds.verts, sizeof( m->verts[ 0 ] ) * m->width * m->height );
|
||||
|
||||
return m;
|
||||
}
|
||||
@@ -241,7 +241,7 @@ static void SplitMeshByPlane( mesh_t *in, const Plane3f& plane, mesh_t **front,
|
||||
chops a patch up by a fog brush
|
||||
*/
|
||||
|
||||
static bool ChopPatchSurfaceByBrush( mapDrawSurface_t *ds, const brush_t *b ){
|
||||
static bool ChopPatchSurfaceByBrush( mapDrawSurface_t& ds, const brush_t *b ){
|
||||
int i, j;
|
||||
mesh_t *outside[MAX_BRUSH_SIDES];
|
||||
int numOutside;
|
||||
@@ -285,13 +285,13 @@ static bool ChopPatchSurfaceByBrush( mapDrawSurface_t *ds, const brush_t *b ){
|
||||
InvertMesh( outside[ i ] );
|
||||
|
||||
/* ydnar: do this the hacky right way */
|
||||
mapDrawSurface_t *newds = AllocDrawSurface( ESurfaceType::Patch );
|
||||
memcpy( newds, ds, sizeof( *ds ) );
|
||||
newds->patchWidth = outside[ i ]->width;
|
||||
newds->patchHeight = outside[ i ]->height;
|
||||
newds->numVerts = outside[ i ]->width * outside[ i ]->height;
|
||||
newds->verts = safe_malloc( newds->numVerts * sizeof( *newds->verts ) );
|
||||
memcpy( newds->verts, outside[ i ]->verts, newds->numVerts * sizeof( *newds->verts ) );
|
||||
mapDrawSurface_t& newds = AllocDrawSurface( ESurfaceType::Patch );
|
||||
newds = ds;
|
||||
newds.patchWidth = outside[ i ]->width;
|
||||
newds.patchHeight = outside[ i ]->height;
|
||||
newds.numVerts = outside[ i ]->width * outside[ i ]->height;
|
||||
newds.verts = safe_malloc( newds.numVerts * sizeof( *newds.verts ) );
|
||||
memcpy( newds.verts, outside[ i ]->verts, newds.numVerts * sizeof( *newds.verts ) );
|
||||
|
||||
/* free the source mesh */
|
||||
FreeMesh( outside[ i ] );
|
||||
@@ -305,12 +305,12 @@ static bool ChopPatchSurfaceByBrush( mapDrawSurface_t *ds, const brush_t *b ){
|
||||
InvertMesh( m );
|
||||
|
||||
/* replace ds with m */
|
||||
ds->patchWidth = m->width;
|
||||
ds->patchHeight = m->height;
|
||||
ds->numVerts = m->width * m->height;
|
||||
free( ds->verts );
|
||||
ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
|
||||
memcpy( ds->verts, m->verts, ds->numVerts * sizeof( *ds->verts ) );
|
||||
ds.patchWidth = m->width;
|
||||
ds.patchHeight = m->height;
|
||||
ds.numVerts = m->width * m->height;
|
||||
free( ds.verts );
|
||||
ds.verts = safe_malloc( ds.numVerts * sizeof( *ds.verts ) );
|
||||
memcpy( ds.verts, m->verts, ds.numVerts * sizeof( *ds.verts ) );
|
||||
}
|
||||
|
||||
/* free the source mesh and return */
|
||||
@@ -325,22 +325,22 @@ static bool ChopPatchSurfaceByBrush( mapDrawSurface_t *ds, const brush_t *b ){
|
||||
creates a winding from a surface's verts
|
||||
*/
|
||||
|
||||
winding_t WindingFromDrawSurf( const mapDrawSurface_t *ds ){
|
||||
winding_t WindingFromDrawSurf( const mapDrawSurface_t& ds ){
|
||||
// we use the first point of the surface, maybe something more clever would be useful
|
||||
// (actually send the whole draw surface would be cool?)
|
||||
if ( ds->numVerts >= MAX_POINTS_ON_WINDING ) {
|
||||
const int max = std::min( ds->numVerts, 256 );
|
||||
if ( ds.numVerts >= MAX_POINTS_ON_WINDING ) {
|
||||
const int max = std::min( ds.numVerts, 256 );
|
||||
Vector3 p[256];
|
||||
|
||||
for ( int i = 0; i < max; ++i ) {
|
||||
p[i] = ds->verts[i].xyz;
|
||||
p[i] = ds.verts[i].xyz;
|
||||
}
|
||||
|
||||
xml_Winding( "WindingFromDrawSurf failed: MAX_POINTS_ON_WINDING exceeded", p, max, true );
|
||||
}
|
||||
|
||||
winding_t w = AllocWinding( ds->numVerts );
|
||||
for ( const bspDrawVert_t& vert : Span( ds->verts, ds->numVerts ) ) {
|
||||
winding_t w = AllocWinding( ds.numVerts );
|
||||
for ( const bspDrawVert_t& vert : Span( ds.verts, ds.numVerts ) ) {
|
||||
w.push_back( vert.xyz );
|
||||
}
|
||||
return w;
|
||||
@@ -353,13 +353,13 @@ winding_t WindingFromDrawSurf( const mapDrawSurface_t *ds ){
|
||||
chops up a face drawsurface by a fog brush, with a potential fragment left inside
|
||||
*/
|
||||
|
||||
static bool ChopFaceSurfaceByBrush( const entity_t& e, mapDrawSurface_t *ds, const brush_t *b ){
|
||||
static bool ChopFaceSurfaceByBrush( const entity_t& e, mapDrawSurface_t& ds, const brush_t *b ){
|
||||
std::list<winding_t> outside;
|
||||
mapDrawSurface_t *newds;
|
||||
|
||||
|
||||
/* dummy check */
|
||||
if ( ds->sideRef == nullptr || ds->sideRef->side == nullptr ) {
|
||||
if ( ds.sideRef == nullptr || ds.sideRef->side == nullptr ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -373,12 +373,12 @@ static bool ChopFaceSurfaceByBrush( const entity_t& e, mapDrawSurface_t *ds, con
|
||||
const plane_t& plane = mapplanes[ side.planenum ];
|
||||
|
||||
/* handle coplanar outfacing (don't fog) */
|
||||
if ( ds->sideRef->side->planenum == side.planenum ) {
|
||||
if ( ds.sideRef->side->planenum == side.planenum ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* handle coplanar infacing (keep inside) */
|
||||
if ( ( ds->sideRef->side->planenum ^ 1 ) == side.planenum ) {
|
||||
if ( ( ds.sideRef->side->planenum ^ 1 ) == side.planenum ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -404,11 +404,11 @@ static bool ChopFaceSurfaceByBrush( const entity_t& e, mapDrawSurface_t *ds, con
|
||||
|
||||
/* all of outside fragments become separate drawsurfs */
|
||||
numFogFragments += outside.size();
|
||||
const side_t *s = ds->sideRef->side;
|
||||
const side_t *s = ds.sideRef->side;
|
||||
for ( const winding_t& wi : outside )
|
||||
{
|
||||
newds = DrawSurfaceForSide( e, *ds->mapBrush, *s, wi );
|
||||
newds->fogNum = ds->fogNum;
|
||||
newds = DrawSurfaceForSide( e, *ds.mapBrush, *s, wi );
|
||||
newds->fogNum = ds.fogNum;
|
||||
}
|
||||
|
||||
/* ydnar: the old code neglected to snap to 0.125 for the fragment
|
||||
@@ -416,14 +416,14 @@ static bool ChopFaceSurfaceByBrush( const entity_t& e, mapDrawSurface_t *ds, con
|
||||
the right thing and uses the original surface's brush side */
|
||||
|
||||
/* build a drawsurf for it */
|
||||
newds = DrawSurfaceForSide( e, *ds->mapBrush, *s, w );
|
||||
newds = DrawSurfaceForSide( e, *ds.mapBrush, *s, w );
|
||||
if ( newds == nullptr ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* copy new to original */
|
||||
ClearSurface( ds );
|
||||
memcpy( ds, newds, sizeof( mapDrawSurface_t ) );
|
||||
ds = *newds;
|
||||
|
||||
/* didn't really add a new drawsurface... :) */
|
||||
numMapDrawSurfs--;
|
||||
@@ -462,17 +462,17 @@ void FogDrawSurfaces( const entity_t& e ){
|
||||
for ( int i = 0; i < numBaseDrawSurfs; ++i )
|
||||
{
|
||||
/* get the drawsurface */
|
||||
mapDrawSurface_t *ds = &mapDrawSurfs[ i ];
|
||||
mapDrawSurface_t& ds = mapDrawSurfs[ i ];
|
||||
|
||||
/* no fog? */
|
||||
if ( ds->shaderInfo->noFog ) {
|
||||
if ( ds.shaderInfo->noFog ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* global fog doesn't have a brush */
|
||||
if ( fog.brush == nullptr ) {
|
||||
/* don't re-fog already fogged surfaces */
|
||||
if ( ds->fogNum > FOG_INVALID ) {
|
||||
if ( ds.fogNum > FOG_INVALID ) {
|
||||
continue;
|
||||
}
|
||||
fogged = 1;
|
||||
@@ -481,7 +481,7 @@ void FogDrawSurfaces( const entity_t& e ){
|
||||
{
|
||||
/* find drawsurface bounds */
|
||||
MinMax minmax;
|
||||
for ( const bspDrawVert_t& vert : Span( ds->verts, ds->numVerts ) )
|
||||
for ( const bspDrawVert_t& vert : Span( ds.verts, ds.numVerts ) )
|
||||
minmax.extend( vert.xyz );
|
||||
|
||||
/* check against the fog brush */
|
||||
@@ -490,7 +490,7 @@ void FogDrawSurfaces( const entity_t& e ){
|
||||
}
|
||||
|
||||
/* ydnar: gs mods: handle the various types of surfaces */
|
||||
switch ( ds->type )
|
||||
switch ( ds.type )
|
||||
{
|
||||
/* handle brush faces */
|
||||
case ESurfaceType::Face:
|
||||
@@ -519,7 +519,7 @@ void FogDrawSurfaces( const entity_t& e ){
|
||||
/* is this surface fogged? */
|
||||
if ( fogged ) {
|
||||
numFogged += fogged;
|
||||
ds->fogNum = fogNum;
|
||||
ds.fogNum = fogNum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ static void make_brush_sides( const Plane3f plane, const Plane3f (&p)[3], const
|
||||
buildBrush.sides[4].planenum = FindFloatPlane( reverse, 0, nullptr );
|
||||
}
|
||||
|
||||
static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t& si, const mapDrawSurface_t *ds, const char *modelName, entity_t& entity ){
|
||||
static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t& si, const mapDrawSurface_t& ds, const char *modelName, entity_t& entity ){
|
||||
const int spf = ( spawnFlags & ( eClipFlags & ~eClipModel ) );
|
||||
|
||||
/* ydnar: giant hack land: generate clipping brushes for model triangles */
|
||||
@@ -467,9 +467,9 @@ static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t& si, const
|
||||
|
||||
if ( ( spf & eMaxExtrude ) || ( spf & eExtrudeTerrain ) ){
|
||||
|
||||
for ( i = 0; i < ds->numIndexes; i += 3 ){
|
||||
for ( i = 0; i < ds.numIndexes; i += 3 ){
|
||||
for ( j = 0; j < 3; ++j ){
|
||||
points[j] = ds->verts[ds->indexes[i + j]].xyz;
|
||||
points[j] = ds.verts[ds.indexes[i + j]].xyz;
|
||||
}
|
||||
if ( PlaneFromPoints( plane, points ) ){
|
||||
if ( spf & eExtrudeTerrain )
|
||||
@@ -498,11 +498,11 @@ static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t& si, const
|
||||
buildBrush.detail = true;
|
||||
|
||||
/* walk triangle list */
|
||||
for ( i = 0; i < ds->numIndexes; i += 3 ){
|
||||
for ( i = 0; i < ds.numIndexes; i += 3 ){
|
||||
/* make points */
|
||||
for ( j = 0; j < 3; ++j ){
|
||||
/* copy xyz */
|
||||
points[j] = ds->verts[ds->indexes[i + j] ].xyz;
|
||||
points[j] = ds.verts[ds.indexes[i + j] ].xyz;
|
||||
}
|
||||
|
||||
/* make plane for triangle */
|
||||
@@ -799,7 +799,7 @@ static void ClipModel( int spawnFlags, float clipDepth, shaderInfo_t& si, const
|
||||
/* get vertex normals */
|
||||
for ( j = 0; j < 3; ++j ){
|
||||
/* copy normal */
|
||||
Vnorm[j] = ds->verts[ds->indexes[i + j]].normal;
|
||||
Vnorm[j] = ds.verts[ds.indexes[i + j]].normal;
|
||||
}
|
||||
|
||||
//avg normals for side planes
|
||||
@@ -988,7 +988,6 @@ void InsertModel( const char *name, const char *skin, int frame, const Matrix4&
|
||||
const Matrix4 nTransform( matrix4_for_normal_transform( transform ) );
|
||||
const bool transform_lefthanded = MATRIX4_LEFTHANDED == matrix4_handedness( transform );
|
||||
AssModel *model;
|
||||
mapDrawSurface_t *ds;
|
||||
const char *picoShaderName;
|
||||
|
||||
|
||||
@@ -1111,53 +1110,53 @@ void InsertModel( const char *name, const char *skin, int frame, const Matrix4&
|
||||
: ShaderInfoForShader( picoShaderName );
|
||||
|
||||
/* allocate a surface (ydnar: gs mods) */
|
||||
ds = AllocDrawSurface( ESurfaceType::Triangles );
|
||||
ds->entityNum = entity.mapEntityNum;
|
||||
ds->castShadows = params.castShadows;
|
||||
ds->recvShadows = params.recvShadows;
|
||||
ds->celShader = params.celShader;
|
||||
ds->ambientColor = params.ambientColor;
|
||||
mapDrawSurface_t& ds = AllocDrawSurface( ESurfaceType::Triangles );
|
||||
ds.entityNum = entity.mapEntityNum;
|
||||
ds.castShadows = params.castShadows;
|
||||
ds.recvShadows = params.recvShadows;
|
||||
ds.celShader = params.celShader;
|
||||
ds.ambientColor = params.ambientColor;
|
||||
|
||||
/* set shader */
|
||||
ds->shaderInfo = &si;
|
||||
ds.shaderInfo = &si;
|
||||
|
||||
/* force to meta? */
|
||||
if ( si.forceMeta || ( spawnFlags & eForceMeta ) ) { /* 3rd bit */
|
||||
ds->type = ESurfaceType::ForcedMeta;
|
||||
ds.type = ESurfaceType::ForcedMeta;
|
||||
}
|
||||
|
||||
/* fix the surface's normals (jal: conditioned by shader info) */
|
||||
if ( !( spawnFlags & eNoSmooth ) && ( params.shadeAngle == 0.0f || ds->type != ESurfaceType::ForcedMeta ) ) {
|
||||
if ( !( spawnFlags & eNoSmooth ) && ( params.shadeAngle == 0.0f || ds.type != ESurfaceType::ForcedMeta ) ) {
|
||||
// PicoFixSurfaceNormals( surface );
|
||||
}
|
||||
|
||||
/* set sample size */
|
||||
if ( params.lightmapSampleSize > 0.0f ) {
|
||||
ds->sampleSize = params.lightmapSampleSize;
|
||||
ds.sampleSize = params.lightmapSampleSize;
|
||||
}
|
||||
|
||||
/* set lightmap scale */
|
||||
if ( params.lightmapScale > 0.0f ) {
|
||||
ds->lightmapScale = params.lightmapScale;
|
||||
ds.lightmapScale = params.lightmapScale;
|
||||
}
|
||||
|
||||
/* set shading angle */
|
||||
if ( params.shadeAngle > 0.0f ) {
|
||||
ds->shadeAngleDegrees = params.shadeAngle;
|
||||
ds.shadeAngleDegrees = params.shadeAngle;
|
||||
}
|
||||
|
||||
/* set particulars */
|
||||
ds->numVerts = mesh->mNumVertices;
|
||||
ds->verts = safe_calloc( ds->numVerts * sizeof( ds->verts[ 0 ] ) );
|
||||
ds.numVerts = mesh->mNumVertices;
|
||||
ds.verts = safe_calloc( ds.numVerts * sizeof( ds.verts[ 0 ] ) );
|
||||
|
||||
ds->numIndexes = mesh->mNumFaces * 3;
|
||||
ds->indexes = safe_calloc( ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
|
||||
// Sys_Printf( "verts %i idx %i\n", ds->numVerts, ds->numIndexes );
|
||||
ds.numIndexes = mesh->mNumFaces * 3;
|
||||
ds.indexes = safe_calloc( ds.numIndexes * sizeof( ds.indexes[ 0 ] ) );
|
||||
// Sys_Printf( "verts %i idx %i\n", ds.numVerts, ds.numIndexes );
|
||||
/* copy vertexes */
|
||||
for ( i = 0; i < ds->numVerts; ++i )
|
||||
for ( i = 0; i < ds.numVerts; ++i )
|
||||
{
|
||||
/* get vertex */
|
||||
bspDrawVert_t& dv = ds->verts[ i ];
|
||||
bspDrawVert_t& dv = ds.verts[ i ];
|
||||
|
||||
/* xyz and normal */
|
||||
dv.xyz = { mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z };
|
||||
@@ -1214,10 +1213,10 @@ void InsertModel( const char *name, const char *skin, int frame, const Matrix4&
|
||||
for ( const aiFace& face : Span( mesh->mFaces, mesh->mNumFaces ) ){
|
||||
// if( face.mNumIndices == 3 )
|
||||
for ( size_t i = 0; i < 3; ++i ){
|
||||
ds->indexes[idCopied++] = face.mIndices[i];
|
||||
ds.indexes[idCopied++] = face.mIndices[i];
|
||||
}
|
||||
if( transform_lefthanded ){
|
||||
std::swap( ds->indexes[idCopied - 1], ds->indexes[idCopied - 2] );
|
||||
std::swap( ds.indexes[idCopied - 1], ds.indexes[idCopied - 2] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,7 +441,7 @@ void PatchMapDrawSurfs( entity_t& e ){
|
||||
//% Sys_Printf( "Longest curve: %f Iterations: %d\n", mesh.mesh.longestCurve, mesh.mesh.maxIterations );
|
||||
|
||||
/* create drawsurf */
|
||||
mapDrawSurface_t *ds = DrawSurfaceForMesh( e, &mesh.mesh, nullptr ); /* ydnar */
|
||||
mapDrawSurface_t *ds = DrawSurfaceForMesh( e, mesh.mesh, nullptr ); /* ydnar */
|
||||
ds->bounds = bounds;
|
||||
}
|
||||
|
||||
|
||||
@@ -1574,7 +1574,7 @@ void FixTJunctions( const entity_t& e );
|
||||
|
||||
|
||||
/* fog.c */
|
||||
winding_t WindingFromDrawSurf( const mapDrawSurface_t *ds );
|
||||
winding_t WindingFromDrawSurf( const mapDrawSurface_t& ds );
|
||||
void FogDrawSurfaces( const entity_t& e );
|
||||
int FogForPoint( const Vector3& point, float epsilon );
|
||||
int FogForBounds( const MinMax& minmax, float epsilon );
|
||||
@@ -1595,17 +1595,17 @@ void AddTriangleModels( entity_t& eparent );
|
||||
|
||||
|
||||
/* surface.c */
|
||||
mapDrawSurface_t *AllocDrawSurface( ESurfaceType type );
|
||||
void StripFaceSurface( mapDrawSurface_t *ds );
|
||||
void MaxAreaFaceSurface( mapDrawSurface_t *ds );
|
||||
mapDrawSurface_t& AllocDrawSurface( ESurfaceType type );
|
||||
void StripFaceSurface( mapDrawSurface_t& ds );
|
||||
void MaxAreaFaceSurface( mapDrawSurface_t& ds );
|
||||
Vector3 CalcLightmapAxis( const Vector3& normal );
|
||||
void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds );
|
||||
void ClassifySurface( mapDrawSurface_t& ds );
|
||||
void ClassifyEntitySurfaces( const entity_t& e );
|
||||
void TidyEntitySurfaces( const entity_t& e );
|
||||
mapDrawSurface_t *CloneSurface( mapDrawSurface_t *src, shaderInfo_t *si );
|
||||
void ClearSurface( mapDrawSurface_t *ds );
|
||||
mapDrawSurface_t *CloneSurface( const mapDrawSurface_t& src, shaderInfo_t *si );
|
||||
void ClearSurface( mapDrawSurface_t& ds );
|
||||
mapDrawSurface_t *DrawSurfaceForSide( const entity_t& e, const brush_t& b, const side_t& s, const winding_t& w );
|
||||
mapDrawSurface_t *DrawSurfaceForMesh( const entity_t& e, parseMesh_t *p, mesh_t *mesh );
|
||||
mapDrawSurface_t *DrawSurfaceForMesh( const entity_t& e, parseMesh_t& p, mesh_t *mesh );
|
||||
mapDrawSurface_t *DrawSurfaceForFlare( int entNum, const Vector3& origin, const Vector3& normal, const Vector3& color, const char *flareShader, int lightStyle );
|
||||
void ClipSidesIntoTree( entity_t& e, const tree_t& tree );
|
||||
void MakeDebugPortalSurfs( const tree_t& tree );
|
||||
@@ -1616,11 +1616,11 @@ void FilterDrawsurfsIntoTree( entity_t& e, tree_t& tree )
|
||||
|
||||
|
||||
/* surface_fur.c */
|
||||
void Fur( mapDrawSurface_t *src );
|
||||
void Fur( mapDrawSurface_t& src );
|
||||
|
||||
|
||||
/* surface_foliage.c */
|
||||
void Foliage( mapDrawSurface_t *src, entity_t& entity );
|
||||
void Foliage( mapDrawSurface_t& src, entity_t& entity );
|
||||
|
||||
|
||||
/* ydnar: surface_meta.c */
|
||||
|
||||
+432
-473
File diff suppressed because it is too large
Load Diff
@@ -45,7 +45,7 @@ static foliageInstance_t foliageInstances[ MAX_FOLIAGE_INSTANCES ];
|
||||
the desired density, then pseudo-randomly sets a point
|
||||
*/
|
||||
|
||||
static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, const foliage_t& foliage, const TriRef& tri ){
|
||||
static void SubdivideFoliageTriangle_r( const foliage_t& foliage, const TriRef& tri ){
|
||||
int max;
|
||||
|
||||
|
||||
@@ -139,12 +139,12 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, const foliage_t& f
|
||||
/* recurse to first triangle */
|
||||
TriRef tri2 = tri;
|
||||
tri2[ max ] = ∣
|
||||
SubdivideFoliageTriangle_r( ds, foliage, tri2 );
|
||||
SubdivideFoliageTriangle_r( foliage, tri2 );
|
||||
|
||||
/* recurse to second triangle */
|
||||
tri2 = tri;
|
||||
tri2[ ( max + 1 ) % 3 ] = ∣
|
||||
SubdivideFoliageTriangle_r( ds, foliage, tri2 );
|
||||
SubdivideFoliageTriangle_r( foliage, tri2 );
|
||||
}
|
||||
|
||||
|
||||
@@ -154,9 +154,9 @@ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, const foliage_t& f
|
||||
generates a foliage file for a bsp
|
||||
*/
|
||||
|
||||
void Foliage( mapDrawSurface_t *src, entity_t& entity ){
|
||||
void Foliage( mapDrawSurface_t& src, entity_t& entity ){
|
||||
/* get shader */
|
||||
shaderInfo_t *si = src->shaderInfo;
|
||||
shaderInfo_t *si = src.shaderInfo;
|
||||
if ( si == nullptr || si->foliage.empty() ) {
|
||||
return;
|
||||
}
|
||||
@@ -168,21 +168,21 @@ void Foliage( mapDrawSurface_t *src, entity_t& entity ){
|
||||
numFoliageInstances = 0;
|
||||
|
||||
/* map the surface onto the lightmap origin/cluster/normal buffers */
|
||||
switch ( src->type )
|
||||
switch ( src.type )
|
||||
{
|
||||
case ESurfaceType::Meta:
|
||||
case ESurfaceType::ForcedMeta:
|
||||
case ESurfaceType::Triangles:
|
||||
{
|
||||
/* get verts */
|
||||
const bspDrawVert_t *verts = src->verts;
|
||||
const bspDrawVert_t *verts = src.verts;
|
||||
|
||||
/* map the triangles */
|
||||
for ( int i = 0; i < src->numIndexes; i += 3 )
|
||||
SubdivideFoliageTriangle_r( src, foliage, TriRef{
|
||||
&verts[ src->indexes[ i + 0 ] ],
|
||||
&verts[ src->indexes[ i + 1 ] ],
|
||||
&verts[ src->indexes[ i + 2 ] ]
|
||||
for ( int i = 0; i < src.numIndexes; i += 3 )
|
||||
SubdivideFoliageTriangle_r( foliage, TriRef{
|
||||
&verts[ src.indexes[ i + 0 ] ],
|
||||
&verts[ src.indexes[ i + 1 ] ],
|
||||
&verts[ src.indexes[ i + 2 ] ]
|
||||
} );
|
||||
break;
|
||||
}
|
||||
@@ -190,9 +190,9 @@ void Foliage( mapDrawSurface_t *src, entity_t& entity ){
|
||||
{
|
||||
/* make a mesh from the drawsurf */
|
||||
mesh_t srcMesh;
|
||||
srcMesh.width = src->patchWidth;
|
||||
srcMesh.height = src->patchHeight;
|
||||
srcMesh.verts = src->verts;
|
||||
srcMesh.width = src.patchWidth;
|
||||
srcMesh.height = src.patchHeight;
|
||||
srcMesh.verts = src.verts;
|
||||
mesh_t *subdivided = SubdivideMesh( srcMesh, 8, 512 );
|
||||
|
||||
/* fit it to the curve and remove colinear verts on rows/columns */
|
||||
@@ -220,13 +220,13 @@ void Foliage( mapDrawSurface_t *src, entity_t& entity ){
|
||||
const int r = ( x + y ) & 1;
|
||||
|
||||
/* get drawverts and map first triangle */
|
||||
SubdivideFoliageTriangle_r( src, foliage, TriRef{
|
||||
SubdivideFoliageTriangle_r( foliage, TriRef{
|
||||
&verts[ pw[ r + 0 ] ],
|
||||
&verts[ pw[ r + 1 ] ],
|
||||
&verts[ pw[ r + 2 ] ]
|
||||
} );
|
||||
/* get drawverts and map second triangle */
|
||||
SubdivideFoliageTriangle_r( src, foliage, TriRef{
|
||||
SubdivideFoliageTriangle_r( foliage, TriRef{
|
||||
&verts[ pw[ r + 0 ] ],
|
||||
&verts[ pw[ r + 2 ] ],
|
||||
&verts[ pw[ r + 3 ] ]
|
||||
@@ -253,13 +253,13 @@ void Foliage( mapDrawSurface_t *src, entity_t& entity ){
|
||||
/* add the model to the bsp */
|
||||
InsertModel( foliage.model.c_str(), nullptr, 0, matrix4_scale_for_vec3( Vector3( foliage.scale ) ), nullptr, entity, 0, clipDepthGlobal,
|
||||
EntityCompileParams {
|
||||
.castShadows = src->castShadows,
|
||||
.recvShadows = src->recvShadows,
|
||||
.castShadows = src.castShadows,
|
||||
.recvShadows = src.recvShadows,
|
||||
.celShader = nullptr,
|
||||
.lightmapSampleSize = 0,
|
||||
.lightmapScale = src->lightmapScale,
|
||||
.lightmapScale = src.lightmapScale,
|
||||
.shadeAngle = 0,
|
||||
.ambientColor = src->ambientColor
|
||||
.ambientColor = src.ambientColor
|
||||
} );
|
||||
|
||||
/* walk each new surface */
|
||||
@@ -277,7 +277,7 @@ void Foliage( mapDrawSurface_t *src, entity_t& entity ){
|
||||
ds.patchHeight = ds.numVerts;
|
||||
|
||||
/* set fog to be same as source surface */
|
||||
ds.fogNum = src->fogNum;
|
||||
ds.fogNum = src.fogNum;
|
||||
|
||||
/* add a drawvert for every instance */
|
||||
bspDrawVert_t *verts = safe_calloc( ( ds.numVerts + ds.numFoliageInstances ) * sizeof( *verts ) );
|
||||
|
||||
@@ -45,23 +45,23 @@
|
||||
runs the fur processing algorithm on a map drawsurface
|
||||
*/
|
||||
|
||||
void Fur( mapDrawSurface_t *ds ){
|
||||
void Fur( mapDrawSurface_t& ds ){
|
||||
/* dummy check */
|
||||
if ( ds == nullptr || ds->fur || ds->shaderInfo->furNumLayers < 1 ) {
|
||||
if ( ds.fur || ds.shaderInfo->furNumLayers < 1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* get basic info */
|
||||
const int numLayers = ds->shaderInfo->furNumLayers;
|
||||
const float offset = ds->shaderInfo->furOffset;
|
||||
const float fade = ds->shaderInfo->furFade * 255.0f;
|
||||
const int numLayers = ds.shaderInfo->furNumLayers;
|
||||
const float offset = ds.shaderInfo->furOffset;
|
||||
const float fade = ds.shaderInfo->furFade * 255.0f;
|
||||
|
||||
/* debug code */
|
||||
//% Sys_FPrintf( SYS_VRB, "Fur(): layers: %d offset: %f fade: %f %s\n",
|
||||
//% numLayers, offset, fade, ds->shaderInfo->shader );
|
||||
//% numLayers, offset, fade, ds.shaderInfo->shader );
|
||||
|
||||
/* initial offset */
|
||||
for ( bspDrawVert_t& dv : Span( ds->verts, ds->numVerts ) )
|
||||
for ( bspDrawVert_t& dv : Span( ds.verts, ds.numVerts ) )
|
||||
{
|
||||
/* offset is scaled by original vertex alpha */
|
||||
const float a = dv.color[ 0 ].alpha() / 255.0;
|
||||
@@ -74,7 +74,7 @@ void Fur( mapDrawSurface_t *ds ){
|
||||
for ( int i = 1; i < numLayers; ++i )
|
||||
{
|
||||
/* clone the surface */
|
||||
mapDrawSurface_t *fur = CloneSurface( ds, ds->shaderInfo );
|
||||
mapDrawSurface_t *fur = CloneSurface( ds, ds.shaderInfo );
|
||||
if ( fur == nullptr ) {
|
||||
return;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ void Fur( mapDrawSurface_t *ds ){
|
||||
for ( int j = 0; j < fur->numVerts; ++j )
|
||||
{
|
||||
/* offset is scaled by original vertex alpha */
|
||||
const float a = ds->verts[ j ].color[ 0 ].alpha() / 255.0;
|
||||
const float a = ds.verts[ j ].color[ 0 ].alpha() / 255.0;
|
||||
|
||||
/* get fur vert */
|
||||
bspDrawVert_t& dv = fur->verts[ j ];
|
||||
|
||||
@@ -296,46 +296,46 @@ static void metaTriangle_insert( metaTriangle_t& src, std::array<bspDrawVert_t,
|
||||
converts a classified surface to metatriangles
|
||||
*/
|
||||
|
||||
static void SurfaceToMetaTriangles( mapDrawSurface_t *ds ){
|
||||
static void SurfaceToMetaTriangles( mapDrawSurface_t& ds ){
|
||||
/* only handle certain types of surfaces */
|
||||
if ( ds->type != ESurfaceType::Face &&
|
||||
ds->type != ESurfaceType::Meta &&
|
||||
ds->type != ESurfaceType::ForcedMeta &&
|
||||
ds->type != ESurfaceType::Decal ) {
|
||||
if ( ds.type != ESurfaceType::Face &&
|
||||
ds.type != ESurfaceType::Meta &&
|
||||
ds.type != ESurfaceType::ForcedMeta &&
|
||||
ds.type != ESurfaceType::Decal ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* only handle valid surfaces */
|
||||
if ( ds->type != ESurfaceType::Bad && ds->numVerts >= 3 && ds->numIndexes >= 3 ) {
|
||||
if ( ds.type != ESurfaceType::Bad && ds.numVerts >= 3 && ds.numIndexes >= 3 ) {
|
||||
/* walk the indexes and create triangles */
|
||||
for ( int i = 0; i < ds->numIndexes; i += 3 )
|
||||
for ( int i = 0; i < ds.numIndexes; i += 3 )
|
||||
{
|
||||
/* sanity check the indexes */
|
||||
if ( ds->indexes[ i ] == ds->indexes[ i + 1 ] ||
|
||||
ds->indexes[ i ] == ds->indexes[ i + 2 ] ||
|
||||
ds->indexes[ i + 1 ] == ds->indexes[ i + 2 ] ) {
|
||||
//% Sys_Printf( "%d! ", ds->numVerts );
|
||||
if ( ds.indexes[ i ] == ds.indexes[ i + 1 ] ||
|
||||
ds.indexes[ i ] == ds.indexes[ i + 2 ] ||
|
||||
ds.indexes[ i + 1 ] == ds.indexes[ i + 2 ] ) {
|
||||
//% Sys_Printf( "%d! ", ds.numVerts );
|
||||
continue;
|
||||
}
|
||||
|
||||
/* build a metatriangle */
|
||||
metaTriangle_t src;
|
||||
src.si = ds->shaderInfo;
|
||||
src.side = ( ds->sideRef != nullptr ? ds->sideRef->side : nullptr );
|
||||
src.entityNum = ds->entityNum;
|
||||
src.surfaceNum = ds->surfaceNum;
|
||||
src.planeNum = ds->planeNum;
|
||||
src.castShadows = ds->castShadows;
|
||||
src.recvShadows = ds->recvShadows;
|
||||
src.fogNum = ds->fogNum;
|
||||
src.sampleSize = ds->sampleSize;
|
||||
src.shadeAngleDegrees = ds->shadeAngleDegrees;
|
||||
src.ambientColor = ds->ambientColor;
|
||||
src.lightmapAxis = ds->lightmapAxis;
|
||||
src.si = ds.shaderInfo;
|
||||
src.side = ( ds.sideRef != nullptr ? ds.sideRef->side : nullptr );
|
||||
src.entityNum = ds.entityNum;
|
||||
src.surfaceNum = ds.surfaceNum;
|
||||
src.planeNum = ds.planeNum;
|
||||
src.castShadows = ds.castShadows;
|
||||
src.recvShadows = ds.recvShadows;
|
||||
src.fogNum = ds.fogNum;
|
||||
src.sampleSize = ds.sampleSize;
|
||||
src.shadeAngleDegrees = ds.shadeAngleDegrees;
|
||||
src.ambientColor = ds.ambientColor;
|
||||
src.lightmapAxis = ds.lightmapAxis;
|
||||
|
||||
metaTriangle_insert( src, { ds->verts[ ds->indexes[ i ] ],
|
||||
ds->verts[ ds->indexes[ i + 1 ] ],
|
||||
ds->verts[ ds->indexes[ i + 2 ] ] }, ds->planeNum );
|
||||
metaTriangle_insert( src, { ds.verts[ ds.indexes[ i ] ],
|
||||
ds.verts[ ds.indexes[ i + 1 ] ],
|
||||
ds.verts[ ds.indexes[ i + 2 ] ] }, ds.planeNum );
|
||||
}
|
||||
|
||||
/* add to count */
|
||||
@@ -353,31 +353,31 @@ static void SurfaceToMetaTriangles( mapDrawSurface_t *ds ){
|
||||
creates triangles from a patch
|
||||
*/
|
||||
|
||||
static void TriangulatePatchSurface( const entity_t& e, mapDrawSurface_t *ds ){
|
||||
static void TriangulatePatchSurface( const entity_t& e, mapDrawSurface_t& ds ){
|
||||
/* vortex: _patchMeta, _patchQuality, _patchSubdivide support */
|
||||
const bool forcePatchMeta = e.boolForKey( "_patchMeta", "patchMeta" );
|
||||
|
||||
/* try to early out */
|
||||
if ( ds->numVerts == 0 || ds->type != ESurfaceType::Patch || ( !patchMeta && !forcePatchMeta ) ) {
|
||||
if ( ds.numVerts == 0 || ds.type != ESurfaceType::Patch || ( !patchMeta && !forcePatchMeta ) ) {
|
||||
return;
|
||||
}
|
||||
/* make a mesh from the drawsurf */
|
||||
mesh_t src;
|
||||
src.width = ds->patchWidth;
|
||||
src.height = ds->patchHeight;
|
||||
src.verts = ds->verts;
|
||||
src.width = ds.patchWidth;
|
||||
src.height = ds.patchHeight;
|
||||
src.verts = ds.verts;
|
||||
//% mesh_t *subdivided = SubdivideMesh( src, 8, 999 );
|
||||
|
||||
int iterations;
|
||||
if ( int patchSubdivision; e.read_keyvalue( patchSubdivision, "_patchSubdivide", "patchSubdivide" ) ) {
|
||||
iterations = IterationsForCurve( ds->longestCurve, patchSubdivision );
|
||||
iterations = IterationsForCurve( ds.longestCurve, patchSubdivision );
|
||||
}
|
||||
else{
|
||||
const int patchQuality = e.intForKey( "_patchQuality", "patchQuality" );
|
||||
iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions / ( patchQuality == 0? 1 : patchQuality ) );
|
||||
iterations = IterationsForCurve( ds.longestCurve, patchSubdivisions / ( patchQuality == 0? 1 : patchQuality ) );
|
||||
}
|
||||
|
||||
mesh_t *subdivided = SubdivideMesh2( src, iterations ); //% ds->maxIterations
|
||||
mesh_t *subdivided = SubdivideMesh2( src, iterations ); //% ds.maxIterations
|
||||
|
||||
/* fit it to the curve and remove colinear verts on rows/columns */
|
||||
PutMeshOnCurve( *subdivided );
|
||||
@@ -386,25 +386,22 @@ static void TriangulatePatchSurface( const entity_t& e, mapDrawSurface_t *ds ){
|
||||
//% MakeMeshNormals( mesh );
|
||||
|
||||
/* make a copy of the drawsurface */
|
||||
mapDrawSurface_t *dsNew = AllocDrawSurface( ESurfaceType::Meta );
|
||||
memcpy( dsNew, ds, sizeof( *ds ) );
|
||||
mapDrawSurface_t& dsNew = AllocDrawSurface( ESurfaceType::Meta );
|
||||
dsNew = ds;
|
||||
|
||||
/* if the patch is nonsolid, then discard it */
|
||||
if ( !( ds->shaderInfo->compileFlags & C_SOLID ) && !( ds->shaderInfo->contentFlags & GetRequiredSurfaceParm<"playerclip">().contentFlags ) ) {
|
||||
if ( !( ds.shaderInfo->compileFlags & C_SOLID ) && !( ds.shaderInfo->contentFlags & GetRequiredSurfaceParm<"playerclip">().contentFlags ) ) {
|
||||
ClearSurface( ds );
|
||||
}
|
||||
|
||||
/* set new pointer */
|
||||
ds = dsNew;
|
||||
|
||||
/* basic transmogrification */
|
||||
ds->type = ESurfaceType::Meta;
|
||||
ds->numIndexes = 0;
|
||||
ds->indexes = safe_malloc( mesh->width * mesh->height * 6 * sizeof( int ) );
|
||||
dsNew.type = ESurfaceType::Meta;
|
||||
dsNew.numIndexes = 0;
|
||||
dsNew.indexes = safe_malloc( mesh->width * mesh->height * 6 * sizeof( int ) );
|
||||
|
||||
/* copy the verts in */
|
||||
ds->numVerts = ( mesh->width * mesh->height );
|
||||
ds->verts = mesh->verts;
|
||||
dsNew.numVerts = ( mesh->width * mesh->height );
|
||||
dsNew.verts = mesh->verts;
|
||||
|
||||
/* iterate through the mesh quads */
|
||||
for ( int y = 0; y < ( mesh->height - 1 ); ++y )
|
||||
@@ -423,14 +420,14 @@ static void TriangulatePatchSurface( const entity_t& e, mapDrawSurface_t *ds ){
|
||||
const int r = ( x + y ) & 1;
|
||||
|
||||
/* make first triangle */
|
||||
ds->indexes[ ds->numIndexes++ ] = pw[ r + 0 ];
|
||||
ds->indexes[ ds->numIndexes++ ] = pw[ r + 1 ];
|
||||
ds->indexes[ ds->numIndexes++ ] = pw[ r + 2 ];
|
||||
dsNew.indexes[ dsNew.numIndexes++ ] = pw[ r + 0 ];
|
||||
dsNew.indexes[ dsNew.numIndexes++ ] = pw[ r + 1 ];
|
||||
dsNew.indexes[ dsNew.numIndexes++ ] = pw[ r + 2 ];
|
||||
|
||||
/* make second triangle */
|
||||
ds->indexes[ ds->numIndexes++ ] = pw[ r + 0 ];
|
||||
ds->indexes[ ds->numIndexes++ ] = pw[ r + 2 ];
|
||||
ds->indexes[ ds->numIndexes++ ] = pw[ r + 3 ];
|
||||
dsNew.indexes[ dsNew.numIndexes++ ] = pw[ r + 0 ];
|
||||
dsNew.indexes[ dsNew.numIndexes++ ] = pw[ r + 2 ];
|
||||
dsNew.indexes[ dsNew.numIndexes++ ] = pw[ r + 3 ];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,7 +438,7 @@ static void TriangulatePatchSurface( const entity_t& e, mapDrawSurface_t *ds ){
|
||||
numPatchMetaSurfaces++;
|
||||
|
||||
/* classify it */
|
||||
ClassifySurfaces( 1, ds );
|
||||
ClassifySurface( dsNew );
|
||||
}
|
||||
|
||||
#define TINY_AREA 1.0
|
||||
@@ -610,42 +607,42 @@ static int MaxAreaIndexes( bspDrawVert_t *vert, int cnt, int *indexes ){
|
||||
creates a triangle list using max area indexes
|
||||
*/
|
||||
|
||||
void MaxAreaFaceSurface( mapDrawSurface_t *ds ){
|
||||
void MaxAreaFaceSurface( mapDrawSurface_t& ds ){
|
||||
int n;
|
||||
/* try to early out */
|
||||
if ( !ds->numVerts || ( ds->type != ESurfaceType::Face && ds->type != ESurfaceType::Decal ) ) {
|
||||
if ( !ds.numVerts || ( ds.type != ESurfaceType::Face && ds.type != ESurfaceType::Decal ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* is this a simple triangle? */
|
||||
if ( ds->numVerts == 3 ) {
|
||||
ds->numIndexes = 3;
|
||||
ds->indexes = safe_malloc( ds->numIndexes * sizeof( int ) );
|
||||
ds->indexes[0] = 0;
|
||||
ds->indexes[1] = 1;
|
||||
ds->indexes[2] = 2;
|
||||
if ( ds.numVerts == 3 ) {
|
||||
ds.numIndexes = 3;
|
||||
ds.indexes = safe_malloc( ds.numIndexes * sizeof( int ) );
|
||||
ds.indexes[0] = 0;
|
||||
ds.indexes[1] = 1;
|
||||
ds.indexes[2] = 2;
|
||||
numMaxAreaSurfaces++;
|
||||
return;
|
||||
}
|
||||
|
||||
/* do it! */
|
||||
ds->numIndexes = 3 * ds->numVerts - 6;
|
||||
ds->indexes = safe_malloc( ds->numIndexes * sizeof( int ) );
|
||||
n = MaxAreaIndexes( ds->verts, ds->numVerts, ds->indexes );
|
||||
ds.numIndexes = 3 * ds.numVerts - 6;
|
||||
ds.indexes = safe_malloc( ds.numIndexes * sizeof( int ) );
|
||||
n = MaxAreaIndexes( ds.verts, ds.numVerts, ds.indexes );
|
||||
if ( n < 0 ) {
|
||||
/* whatever we do, it's degenerate */
|
||||
free( ds->indexes );
|
||||
ds->numIndexes = 0;
|
||||
free( ds.indexes );
|
||||
ds.numIndexes = 0;
|
||||
StripFaceSurface( ds );
|
||||
return;
|
||||
}
|
||||
ds->numIndexes = n;
|
||||
ds.numIndexes = n;
|
||||
|
||||
/* add to count */
|
||||
numMaxAreaSurfaces++;
|
||||
|
||||
/* classify it */
|
||||
ClassifySurfaces( 1, ds );
|
||||
ClassifySurface( ds );
|
||||
}
|
||||
|
||||
|
||||
@@ -655,7 +652,7 @@ void MaxAreaFaceSurface( mapDrawSurface_t *ds ){
|
||||
loosely based on SurfaceAsTriFan()
|
||||
*/
|
||||
|
||||
static void FanFaceSurface( mapDrawSurface_t *ds ){
|
||||
static void FanFaceSurface( mapDrawSurface_t& ds ){
|
||||
int i, k, a, b, c;
|
||||
Color4f color[ MAX_LIGHTMAPS ];
|
||||
for ( auto& co : color )
|
||||
@@ -665,20 +662,20 @@ static void FanFaceSurface( mapDrawSurface_t *ds ){
|
||||
|
||||
|
||||
/* try to early out */
|
||||
if ( !ds->numVerts || ( ds->type != ESurfaceType::Face && ds->type != ESurfaceType::Decal ) ) {
|
||||
if ( !ds.numVerts || ( ds.type != ESurfaceType::Face && ds.type != ESurfaceType::Decal ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* add a new vertex at the beginning of the surface */
|
||||
verts = safe_malloc( ( ds->numVerts + 1 ) * sizeof( bspDrawVert_t ) );
|
||||
verts = safe_malloc( ( ds.numVerts + 1 ) * sizeof( bspDrawVert_t ) );
|
||||
memset( verts, 0, sizeof( bspDrawVert_t ) );
|
||||
memcpy( &verts[ 1 ], ds->verts, ds->numVerts * sizeof( bspDrawVert_t ) );
|
||||
free( ds->verts );
|
||||
ds->verts = verts;
|
||||
memcpy( &verts[ 1 ], ds.verts, ds.numVerts * sizeof( bspDrawVert_t ) );
|
||||
free( ds.verts );
|
||||
ds.verts = verts;
|
||||
|
||||
/* add up the drawverts to create a centroid */
|
||||
centroid = &verts[ 0 ];
|
||||
for ( i = 1, dv = &verts[ 1 ]; i < ( ds->numVerts + 1 ); ++i, ++dv )
|
||||
for ( i = 1, dv = &verts[ 1 ]; i < ( ds.numVerts + 1 ); ++i, ++dv )
|
||||
{
|
||||
centroid->xyz += dv->xyz;
|
||||
centroid->normal += dv->normal;
|
||||
@@ -690,7 +687,7 @@ static void FanFaceSurface( mapDrawSurface_t *ds ){
|
||||
}
|
||||
|
||||
/* average the centroid */
|
||||
iv = 1.0f / ds->numVerts;
|
||||
iv = 1.0f / ds.numVerts;
|
||||
centroid->xyz *= iv;
|
||||
if ( VectorNormalize( centroid->normal ) == 0 ) {
|
||||
centroid->normal = verts[ 1 ].normal;
|
||||
@@ -698,31 +695,31 @@ static void FanFaceSurface( mapDrawSurface_t *ds ){
|
||||
centroid->st *= iv;
|
||||
for ( k = 0; k < MAX_LIGHTMAPS; ++k ){
|
||||
centroid->lightmap[ k ] *= iv;
|
||||
centroid->color[ k ] = color_to_byte( color[ k ] / ds->numVerts );
|
||||
centroid->color[ k ] = color_to_byte( color[ k ] / ds.numVerts );
|
||||
}
|
||||
|
||||
/* add to vert count */
|
||||
ds->numVerts++;
|
||||
ds.numVerts++;
|
||||
|
||||
/* fill indexes in triangle fan order */
|
||||
ds->numIndexes = 0;
|
||||
ds->indexes = safe_malloc( ds->numVerts * 3 * sizeof( int ) );
|
||||
for ( i = 1; i < ds->numVerts; ++i )
|
||||
ds.numIndexes = 0;
|
||||
ds.indexes = safe_malloc( ds.numVerts * 3 * sizeof( int ) );
|
||||
for ( i = 1; i < ds.numVerts; ++i )
|
||||
{
|
||||
a = 0;
|
||||
b = i;
|
||||
c = ( i + 1 ) % ds->numVerts;
|
||||
c = ( i + 1 ) % ds.numVerts;
|
||||
c = c ? c : 1;
|
||||
ds->indexes[ ds->numIndexes++ ] = a;
|
||||
ds->indexes[ ds->numIndexes++ ] = b;
|
||||
ds->indexes[ ds->numIndexes++ ] = c;
|
||||
ds.indexes[ ds.numIndexes++ ] = a;
|
||||
ds.indexes[ ds.numIndexes++ ] = b;
|
||||
ds.indexes[ ds.numIndexes++ ] = c;
|
||||
}
|
||||
|
||||
/* add to count */
|
||||
numFanSurfaces++;
|
||||
|
||||
/* classify it */
|
||||
ClassifySurfaces( 1, ds );
|
||||
ClassifySurface( ds );
|
||||
}
|
||||
|
||||
|
||||
@@ -735,16 +732,16 @@ static void FanFaceSurface( mapDrawSurface_t *ds ){
|
||||
|
||||
#define MAX_INDEXES 1024
|
||||
|
||||
void StripFaceSurface( mapDrawSurface_t *ds ){
|
||||
void StripFaceSurface( mapDrawSurface_t& ds ){
|
||||
int numIndexes, indexes[ MAX_INDEXES ];
|
||||
|
||||
/* try to early out */
|
||||
if ( !ds->numVerts || ( ds->type != ESurfaceType::Face && ds->type != ESurfaceType::Decal ) ) {
|
||||
if ( !ds.numVerts || ( ds.type != ESurfaceType::Face && ds.type != ESurfaceType::Decal ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* is this a simple triangle? */
|
||||
if ( ds->numVerts == 3 ) {
|
||||
if ( ds.numVerts == 3 ) {
|
||||
numIndexes = 3;
|
||||
indexes[0] = 0;
|
||||
indexes[1] = 1;
|
||||
@@ -754,12 +751,12 @@ void StripFaceSurface( mapDrawSurface_t *ds ){
|
||||
{
|
||||
/* ydnar: find smallest coordinate */
|
||||
int least = 0;
|
||||
if ( ds->shaderInfo != nullptr && !ds->shaderInfo->autosprite ) {
|
||||
for ( int i = 0; i < ds->numVerts; ++i )
|
||||
if ( ds.shaderInfo != nullptr && !ds.shaderInfo->autosprite ) {
|
||||
for ( int i = 0; i < ds.numVerts; ++i )
|
||||
{
|
||||
/* get points */
|
||||
const Vector3& v1 = ds->verts[ i ].xyz;
|
||||
const Vector3& v2 = ds->verts[ least ].xyz;
|
||||
const Vector3& v1 = ds.verts[ i ].xyz;
|
||||
const Vector3& v2 = ds.verts[ least ].xyz;
|
||||
|
||||
/* compare */
|
||||
if ( v1[ 0 ] < v2[ 0 ] ||
|
||||
@@ -771,9 +768,9 @@ void StripFaceSurface( mapDrawSurface_t *ds ){
|
||||
}
|
||||
|
||||
/* determine the triangle strip order */
|
||||
numIndexes = ( ds->numVerts - 2 ) * 3;
|
||||
numIndexes = ( ds.numVerts - 2 ) * 3;
|
||||
if ( numIndexes > MAX_INDEXES ) {
|
||||
Error( "MAX_INDEXES exceeded for surface (%d > %d) (%d verts)", numIndexes, MAX_INDEXES, ds->numVerts );
|
||||
Error( "MAX_INDEXES exceeded for surface (%d > %d) (%d verts)", numIndexes, MAX_INDEXES, ds.numVerts );
|
||||
}
|
||||
|
||||
class TriEval
|
||||
@@ -794,18 +791,18 @@ void StripFaceSurface( mapDrawSurface_t *ds ){
|
||||
void reset(){
|
||||
*this = TriEval( m_verts );
|
||||
}
|
||||
} triEval( ds->verts );
|
||||
} triEval( ds.verts );
|
||||
|
||||
const auto idx = [n = ds->numVerts]( int i ){ return i < 0? i + n : i < n? i : i - n; };
|
||||
const auto idx = [n = ds.numVerts]( int i ){ return i < 0? i + n : i < n? i : i - n; };
|
||||
|
||||
/* try all possible orderings of the points looking for a non-degenerate strip order */
|
||||
for ( int r = 0; r < ds->numVerts; ++r )
|
||||
for ( int r = 0; r < ds.numVerts; ++r )
|
||||
{
|
||||
triEval.reset();
|
||||
/* walk the winding in both directions */
|
||||
for( int i = idx( r + least ), j = idx( i - 1 ), k, swap = 0, out = 0;
|
||||
( swap ^= bspDrawVert_is_tjunc( ds->verts[idx( swap? i + 1 : j - 1 )] )
|
||||
>= bspDrawVert_is_tjunc( ds->verts[idx( swap? j - 1 : i + 1 )] ) )
|
||||
( swap ^= bspDrawVert_is_tjunc( ds.verts[idx( swap? i + 1 : j - 1 )] )
|
||||
>= bspDrawVert_is_tjunc( ds.verts[idx( swap? j - 1 : i + 1 )] ) )
|
||||
? ( k = j, j = idx( --j ) ) : ( k = i, i = idx( ++i ) ), i != j; )
|
||||
{
|
||||
/* test this triangle */
|
||||
@@ -826,15 +823,15 @@ void StripFaceSurface( mapDrawSurface_t *ds ){
|
||||
}
|
||||
okej:
|
||||
/* copy strip triangle indexes */
|
||||
ds->numIndexes = numIndexes;
|
||||
ds->indexes = safe_malloc( ds->numIndexes * sizeof( int ) );
|
||||
memcpy( ds->indexes, indexes, ds->numIndexes * sizeof( int ) );
|
||||
ds.numIndexes = numIndexes;
|
||||
ds.indexes = safe_malloc( ds.numIndexes * sizeof( int ) );
|
||||
memcpy( ds.indexes, indexes, ds.numIndexes * sizeof( int ) );
|
||||
|
||||
/* add to count */
|
||||
numStripSurfaces++;
|
||||
|
||||
/* classify it */
|
||||
ClassifySurfaces( 1, ds );
|
||||
ClassifySurface( ds );
|
||||
}
|
||||
|
||||
|
||||
@@ -877,23 +874,23 @@ void MakeEntityMetaTriangles( const entity_t& e ){
|
||||
}
|
||||
|
||||
/* get surface */
|
||||
mapDrawSurface_t *ds = &mapDrawSurfs[ i ];
|
||||
if ( ds->numVerts <= 0 ) {
|
||||
mapDrawSurface_t& ds = mapDrawSurfs[ i ];
|
||||
if ( ds.numVerts <= 0 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* ignore autosprite surfaces */
|
||||
if ( ds->shaderInfo->autosprite ) {
|
||||
if ( ds.shaderInfo->autosprite ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* meta this surface? */
|
||||
if ( !meta && !ds->shaderInfo->forceMeta ) {
|
||||
if ( !meta && !ds.shaderInfo->forceMeta ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* switch on type */
|
||||
switch ( ds->type )
|
||||
switch ( ds.type )
|
||||
{
|
||||
case ESurfaceType::Face:
|
||||
case ESurfaceType::Decal:
|
||||
@@ -1304,13 +1301,13 @@ int>; // index of bspDrawVert_t in mapDrawSurface_t::verts array
|
||||
returns the index of that vert (or < 0 on failure)
|
||||
*/
|
||||
|
||||
static int AddMetaVertToSurface( mapDrawSurface_t *ds, const bspDrawVert_t& dv1, const Sorted_indices& sorted_indices, int *coincident ){
|
||||
static int AddMetaVertToSurface( mapDrawSurface_t& ds, const bspDrawVert_t& dv1, const Sorted_indices& sorted_indices, int *coincident ){
|
||||
/* go through the verts and find a suitable candidate */
|
||||
const auto begin = sorted_indices.lower_bound( spatial_distance( dv1.xyz ) - c_spatial_EQUAL_EPSILON );
|
||||
const auto end = sorted_indices.upper_bound( spatial_distance( dv1.xyz ) + c_spatial_EQUAL_EPSILON );
|
||||
for( auto it = begin; it != end; ++it ){
|
||||
/* get test vert */
|
||||
const bspDrawVert_t& dv2 = ds->verts[ it->second ];
|
||||
const bspDrawVert_t& dv2 = ds.verts[ it->second ];
|
||||
|
||||
/* compare xyz and normal */
|
||||
if ( !VectorCompare( dv1.xyz, dv2.xyz ) ) {
|
||||
@@ -1337,13 +1334,13 @@ static int AddMetaVertToSurface( mapDrawSurface_t *ds, const bspDrawVert_t& dv1,
|
||||
}
|
||||
|
||||
/* overflow check */
|
||||
if ( ds->numVerts >= ( ( ds->shaderInfo->compileFlags & C_VERTEXLIT ) ? maxSurfaceVerts : maxLMSurfaceVerts ) ) {
|
||||
if ( ds.numVerts >= ( ( ds.shaderInfo->compileFlags & C_VERTEXLIT ) ? maxSurfaceVerts : maxLMSurfaceVerts ) ) {
|
||||
return VERTS_EXCEEDED;
|
||||
}
|
||||
|
||||
/* made it this far, add the vert and return */
|
||||
ds->verts[ ds->numVerts ] = dv1;
|
||||
return ds->numVerts++;
|
||||
ds.verts[ ds.numVerts ] = dv1;
|
||||
return ds.numVerts++;
|
||||
}
|
||||
|
||||
|
||||
@@ -1369,45 +1366,45 @@ static int AddMetaVertToSurface( mapDrawSurface_t *ds, const bspDrawVert_t& dv1,
|
||||
#define ADEQUATE_SCORE ( metaAdequateScore >= 0 ? metaAdequateScore : DEFAULT_ADEQUATE_SCORE )
|
||||
#define GOOD_SCORE ( metaGoodScore >= 0 ? metaGoodScore : DEFAULT_GOOD_SCORE )
|
||||
|
||||
static int AddMetaTriangleToSurface( mapDrawSurface_t *ds, const metaTriangle_t& tri, MinMax& texMinMax, Sorted_indices& sorted_indices, bool testAdd ){
|
||||
static int AddMetaTriangleToSurface( mapDrawSurface_t& ds, const metaTriangle_t& tri, MinMax& texMinMax, Sorted_indices& sorted_indices, bool testAdd ){
|
||||
int i, score, coincident, ai, bi, ci;
|
||||
|
||||
|
||||
/* test the triangle */
|
||||
#if 0
|
||||
if ( !( ds->shaderInfo->compileFlags & C_VERTEXLIT ) &&
|
||||
//% !VectorCompare( ds->lightmapAxis, tri.lightmapAxis ) )
|
||||
vector3_dot( ds->lightmapAxis, tri.plane.normal() ) < 0.25f ) {
|
||||
if ( !( ds.shaderInfo->compileFlags & C_VERTEXLIT ) &&
|
||||
//% !VectorCompare( ds.lightmapAxis, tri.lightmapAxis ) )
|
||||
vector3_dot( ds.lightmapAxis, tri.plane.normal() ) < 0.25f ) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* planar surfaces will only merge with triangles in the same plane */
|
||||
if ( npDegrees == 0.0f && !ds->shaderInfo->nonplanar && ds->planeNum >= 0 ) {
|
||||
if ( tri.planeNum >= 0 && tri.planeNum != ds->planeNum ) {
|
||||
if ( npDegrees == 0.0f && !ds.shaderInfo->nonplanar && ds.planeNum >= 0 ) {
|
||||
if ( tri.planeNum >= 0 && tri.planeNum != ds.planeNum ) {
|
||||
return 0;
|
||||
}
|
||||
if ( !VectorCompare( mapplanes[ ds->planeNum ].normal(), tri.plane.normal() ) || mapplanes[ ds->planeNum ].dist() != tri.plane.dist() ) {
|
||||
if ( !VectorCompare( mapplanes[ ds.planeNum ].normal(), tri.plane.normal() ) || mapplanes[ ds.planeNum ].dist() != tri.plane.dist() ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* set initial score */
|
||||
score = tri.surfaceNum == ds->surfaceNum ? SURFACE_SCORE : 0;
|
||||
score = tri.surfaceNum == ds.surfaceNum ? SURFACE_SCORE : 0;
|
||||
|
||||
/* score the the dot product of lightmap axis to plane */
|
||||
if ( ( ds->shaderInfo->compileFlags & C_VERTEXLIT ) || VectorCompare( ds->lightmapAxis, tri.lightmapAxis ) ) {
|
||||
if ( ( ds.shaderInfo->compileFlags & C_VERTEXLIT ) || VectorCompare( ds.lightmapAxis, tri.lightmapAxis ) ) {
|
||||
score += AXIS_SCORE;
|
||||
}
|
||||
else{
|
||||
score += AXIS_SCORE * vector3_dot( ds->lightmapAxis, tri.plane.normal() );
|
||||
score += AXIS_SCORE * vector3_dot( ds.lightmapAxis, tri.plane.normal() );
|
||||
}
|
||||
|
||||
/* preserve old drawsurface if this fails */
|
||||
mapDrawSurface_t old( *ds );
|
||||
mapDrawSurface_t old( ds );
|
||||
|
||||
/* attempt to add the verts */
|
||||
const int numVerts_original = ds->numVerts;
|
||||
const int numVerts_original = ds.numVerts;
|
||||
coincident = 0;
|
||||
ai = AddMetaVertToSurface( ds, *tri.m_vertices[ 0 ], sorted_indices, &coincident );
|
||||
bi = AddMetaVertToSurface( ds, *tri.m_vertices[ 1 ], sorted_indices, &coincident );
|
||||
@@ -1415,7 +1412,7 @@ static int AddMetaTriangleToSurface( mapDrawSurface_t *ds, const metaTriangle_t&
|
||||
|
||||
/* check vertex underflow */
|
||||
if ( ai < 0 || bi < 0 || ci < 0 ) {
|
||||
memcpy( ds, &old, sizeof( *ds ) );
|
||||
ds = old;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1423,23 +1420,23 @@ static int AddMetaTriangleToSurface( mapDrawSurface_t *ds, const metaTriangle_t&
|
||||
score += ( coincident * VERT_SCORE );
|
||||
|
||||
/* add new vertex bounds to mins/maxs */
|
||||
MinMax minmax( ds->minmax );
|
||||
MinMax minmax( ds.minmax );
|
||||
minmax.extend( tri.m_vertices[ 0 ]->xyz );
|
||||
minmax.extend( tri.m_vertices[ 1 ]->xyz );
|
||||
minmax.extend( tri.m_vertices[ 2 ]->xyz );
|
||||
|
||||
/* check lightmap bounds overflow (after at least 1 triangle has been added) */
|
||||
if ( !( ds->shaderInfo->compileFlags & C_VERTEXLIT ) &&
|
||||
ds->numIndexes > 0 && ds->lightmapAxis != g_vector3_identity &&
|
||||
( !VectorCompare( ds->minmax.mins, minmax.mins ) || !VectorCompare( ds->minmax.maxs, minmax.maxs ) ) ) {
|
||||
if ( !( ds.shaderInfo->compileFlags & C_VERTEXLIT ) &&
|
||||
ds.numIndexes > 0 && ds.lightmapAxis != g_vector3_identity &&
|
||||
( !VectorCompare( ds.minmax.mins, minmax.mins ) || !VectorCompare( ds.minmax.maxs, minmax.maxs ) ) ) {
|
||||
/* set maximum size before lightmap scaling (normally 2032 units) */
|
||||
/* 2004-02-24: scale lightmap test size by 2 to catch larger brush faces */
|
||||
/* 2004-04-11: reverting to actual lightmap size */
|
||||
const float lmMax = ( ds->sampleSize * ( ds->shaderInfo->lmCustomWidth - 1 ) );
|
||||
const float lmMax = ( ds.sampleSize * ( ds.shaderInfo->lmCustomWidth - 1 ) );
|
||||
for ( i = 0; i < 3; ++i )
|
||||
{
|
||||
if ( ( minmax.maxs[ i ] - minmax.mins[ i ] ) > lmMax ) {
|
||||
memcpy( ds, &old, sizeof( *ds ) );
|
||||
ds = old;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1455,7 +1452,7 @@ static int AddMetaTriangleToSurface( mapDrawSurface_t *ds, const metaTriangle_t&
|
||||
score += 4 * ST_SCORE;
|
||||
}
|
||||
else{
|
||||
const Vector2 wh( ds->shaderInfo->shaderWidth, ds->shaderInfo->shaderHeight );
|
||||
const Vector2 wh( ds.shaderInfo->shaderWidth, ds.shaderInfo->shaderHeight );
|
||||
BasicVector2<int> oldTexRange( ( texMinMax.maxs - texMinMax.mins ).vec2() * wh );
|
||||
BasicVector2<int> newTexRange( ( newTexMinMax.maxs - newTexMinMax.mins ).vec2() * wh );
|
||||
/* score texture range */
|
||||
@@ -1477,40 +1474,40 @@ static int AddMetaTriangleToSurface( mapDrawSurface_t *ds, const metaTriangle_t&
|
||||
|
||||
|
||||
/* check index overflow */
|
||||
if ( ds->numIndexes + 3 > maxSurfaceIndexes ) {
|
||||
memcpy( ds, &old, sizeof( *ds ) );
|
||||
if ( ds.numIndexes + 3 > maxSurfaceIndexes ) {
|
||||
ds = old;
|
||||
return 0;
|
||||
}
|
||||
else{ /* add the triangle indexes */
|
||||
ds->indexes[ ds->numIndexes++ ] = ai;
|
||||
ds->indexes[ ds->numIndexes++ ] = bi;
|
||||
ds->indexes[ ds->numIndexes++ ] = ci;
|
||||
ds.indexes[ ds.numIndexes++ ] = ai;
|
||||
ds.indexes[ ds.numIndexes++ ] = bi;
|
||||
ds.indexes[ ds.numIndexes++ ] = ci;
|
||||
}
|
||||
|
||||
/* sanity check the indexes */
|
||||
if ( ds->numIndexes >= 3 &&
|
||||
( ds->indexes[ ds->numIndexes - 3 ] == ds->indexes[ ds->numIndexes - 2 ] ||
|
||||
ds->indexes[ ds->numIndexes - 3 ] == ds->indexes[ ds->numIndexes - 1 ] ||
|
||||
ds->indexes[ ds->numIndexes - 2 ] == ds->indexes[ ds->numIndexes - 1 ] ) ) {
|
||||
Sys_Printf( "DEG:%d! ", ds->numVerts );
|
||||
if ( ds.numIndexes >= 3 &&
|
||||
( ds.indexes[ ds.numIndexes - 3 ] == ds.indexes[ ds.numIndexes - 2 ] ||
|
||||
ds.indexes[ ds.numIndexes - 3 ] == ds.indexes[ ds.numIndexes - 1 ] ||
|
||||
ds.indexes[ ds.numIndexes - 2 ] == ds.indexes[ ds.numIndexes - 1 ] ) ) {
|
||||
Sys_Printf( "DEG:%d! ", ds.numVerts );
|
||||
}
|
||||
|
||||
/* testing only? */
|
||||
if ( testAdd ) {
|
||||
memcpy( ds, &old, sizeof( *ds ) );
|
||||
ds = old;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* store new bounds */
|
||||
ds->minmax = minmax;
|
||||
ds.minmax = minmax;
|
||||
texMinMax = newTexMinMax;
|
||||
|
||||
/* add a side reference */
|
||||
ds->sideRef = AllocSideRef( tri.side, ds->sideRef );
|
||||
ds.sideRef = AllocSideRef( tri.side, ds.sideRef );
|
||||
|
||||
for( const auto id : { ai, bi, ci } ){
|
||||
if( id >= numVerts_original )
|
||||
sorted_indices.emplace( spatial_distance( ds->verts[id].xyz ), id );
|
||||
sorted_indices.emplace( spatial_distance( ds.verts[id].xyz ), id );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1543,24 +1540,24 @@ static void MetaTrianglesToSurface( int *fOld, int *numAdded ){
|
||||
----------------------------------------------------------------- */
|
||||
|
||||
/* start a new drawsurface */
|
||||
mapDrawSurface_t *ds = AllocDrawSurface( ESurfaceType::Meta );
|
||||
ds->entityNum = seed.entityNum;
|
||||
ds->surfaceNum = seed.surfaceNum;
|
||||
ds->castShadows = seed.castShadows;
|
||||
ds->recvShadows = seed.recvShadows;
|
||||
mapDrawSurface_t& ds = AllocDrawSurface( ESurfaceType::Meta );
|
||||
ds.entityNum = seed.entityNum;
|
||||
ds.surfaceNum = seed.surfaceNum;
|
||||
ds.castShadows = seed.castShadows;
|
||||
ds.recvShadows = seed.recvShadows;
|
||||
|
||||
ds->shaderInfo = seed.si;
|
||||
ds->planeNum = seed.planeNum;
|
||||
ds->fogNum = seed.fogNum;
|
||||
ds->sampleSize = seed.sampleSize;
|
||||
ds->shadeAngleDegrees = seed.shadeAngleDegrees;
|
||||
ds->ambientColor = seed.ambientColor;
|
||||
ds->verts = verts;
|
||||
ds->indexes = indexes;
|
||||
ds->lightmapAxis = seed.lightmapAxis;
|
||||
ds->sideRef = AllocSideRef( seed.side, nullptr );
|
||||
ds.shaderInfo = seed.si;
|
||||
ds.planeNum = seed.planeNum;
|
||||
ds.fogNum = seed.fogNum;
|
||||
ds.sampleSize = seed.sampleSize;
|
||||
ds.shadeAngleDegrees = seed.shadeAngleDegrees;
|
||||
ds.ambientColor = seed.ambientColor;
|
||||
ds.verts = verts;
|
||||
ds.indexes = indexes;
|
||||
ds.lightmapAxis = seed.lightmapAxis;
|
||||
ds.sideRef = AllocSideRef( seed.side, nullptr );
|
||||
|
||||
ds->minmax.clear();
|
||||
ds.minmax.clear();
|
||||
|
||||
MinMax texMinMax;
|
||||
|
||||
@@ -1659,18 +1656,18 @@ static void MetaTrianglesToSurface( int *fOld, int *numAdded ){
|
||||
}
|
||||
|
||||
/* copy the verts and indexes to the new surface */
|
||||
ds->verts = safe_malloc( ds->numVerts * sizeof( bspDrawVert_t ) );
|
||||
memcpy( ds->verts, verts, ds->numVerts * sizeof( bspDrawVert_t ) );
|
||||
ds->indexes = safe_malloc( ds->numIndexes * sizeof( int ) );
|
||||
memcpy( ds->indexes, indexes, ds->numIndexes * sizeof( int ) );
|
||||
ds.verts = safe_malloc( ds.numVerts * sizeof( bspDrawVert_t ) );
|
||||
memcpy( ds.verts, verts, ds.numVerts * sizeof( bspDrawVert_t ) );
|
||||
ds.indexes = safe_malloc( ds.numIndexes * sizeof( int ) );
|
||||
memcpy( ds.indexes, indexes, ds.numIndexes * sizeof( int ) );
|
||||
|
||||
/* classify the surface */
|
||||
ClassifySurfaces( 1, ds );
|
||||
//% Sys_Warning( "numV: %d numIdx: %d\n", ds->numVerts, ds->numIndexes );
|
||||
/* ClassifySurfaces() sets axis from vertex normals
|
||||
ClassifySurface( ds );
|
||||
//% Sys_Warning( "numV: %d numIdx: %d\n", ds.numVerts, ds.numIndexes );
|
||||
/* ClassifySurface() sets axis from vertex normals
|
||||
method is very questionable and axis actually happens to be wrong after normals passed through SmoothMetaTriangles()
|
||||
use metaTriangle_t::lightmapAxis which is guaranteedly set and used as main factor for triangles merge */
|
||||
ds->lightmapAxis = seed.lightmapAxis;
|
||||
ds.lightmapAxis = seed.lightmapAxis;
|
||||
|
||||
/* add to count */
|
||||
numMergedSurfaces++;
|
||||
|
||||
@@ -573,7 +573,7 @@ void FixTJunctions( const entity_t& ent ){
|
||||
FixSurfaceJunctions( ds );
|
||||
if ( !FixBrokenSurface( ds ) ) {
|
||||
c_broken++;
|
||||
ClearSurface( &ds );
|
||||
ClearSurface( ds );
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user