]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/surface_meta.c
Fix/add grayscale-to-RGB in PNG loader
[xonotic/netradiant.git] / tools / quake3 / q3map2 / surface_meta.c
index c9606d11b71521e5d73dcedc91f216cb97a448a8..315b67d1220759aad00ae4b5fa9a8f11625a1753 100644 (file)
@@ -288,6 +288,7 @@ static void SurfaceToMetaTriangles( mapDrawSurface_t *ds )
                        src.recvShadows = ds->recvShadows;
                        src.fogNum = ds->fogNum;
                        src.sampleSize = ds->sampleSize;
+                       src.shadeAngleDegrees = ds->shadeAngleDegrees;
                        VectorCopy( ds->lightmapAxis, src.lightmapAxis );
                        
                        /* copy drawverts */
@@ -312,23 +313,41 @@ TriangulatePatchSurface()
 creates triangles from a patch
 */
 
-void TriangulatePatchSurface( mapDrawSurface_t *ds )
+void TriangulatePatchSurface( entity_t *e , mapDrawSurface_t *ds )
 {
        int                                     iterations, x, y, pw[ 5 ], r;
        mapDrawSurface_t        *dsNew;
        mesh_t                          src, *subdivided, *mesh;
-       
-       
+       int                                     forcePatchMeta;
+       int                                     patchQuality;
+       int                                     patchSubdivision;
+
+       /* vortex: _patchMeta, _patchQuality, _patchSubdivide support */
+       forcePatchMeta = IntForKey(e, "_patchMeta" );
+       if (!forcePatchMeta)
+               forcePatchMeta = IntForKey(e, "patchMeta" );
+       patchQuality = IntForKey(e, "_patchQuality" );
+       if (!patchQuality)
+               patchQuality = IntForKey(e, "patchQuality" );
+       if (!patchQuality)
+               patchQuality = 1.0;
+       patchSubdivision = IntForKey(e, "_patchSubdivide" );
+       if (!patchSubdivision)
+               patchSubdivision = IntForKey(e, "patchSubdivide" );
+
        /* try to early out */
-       if( ds->numVerts == 0 || ds->type != SURFACE_PATCH || patchMeta == qfalse )
+       if(ds->numVerts == 0 || ds->type != SURFACE_PATCH || ( patchMeta == qfalse && !forcePatchMeta) )
                return;
-       
        /* make a mesh from the drawsurf */ 
        src.width = ds->patchWidth;
        src.height = ds->patchHeight;
        src.verts = ds->verts;
        //%     subdivided = SubdivideMesh( src, 8, 999 );
-       iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions );
+       if (patchSubdivision)
+               iterations = IterationsForCurve( ds->longestCurve, patchSubdivision );
+       else
+               iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions / patchQuality );
+
        subdivided = SubdivideMesh2( src, iterations ); //%     ds->maxIterations
        
        /* fit it to the curve and remove colinear verts on rows/columns */
@@ -492,7 +511,7 @@ attempts to create a valid tri-strip w/o degenerate triangles from a brush face
 based on SurfaceAsTriStrip()
 */
 
-#define MAX_INDEXES            4096
+#define MAX_INDEXES            1024
 
 void StripFaceSurface( mapDrawSurface_t *ds ) 
 {
@@ -597,8 +616,23 @@ void StripFaceSurface( mapDrawSurface_t *ds )
        /* classify it */
        ClassifySurfaces( 1, ds );
 }
+/*
+EmitMetaStatictics
+vortex: prints meta statistics in general output
+*/
 
-
+void EmitMetaStats()
+{
+       Sys_Printf( "--- EmitMetaStats ---\n" );
+       Sys_Printf( "%9d total meta surfaces\n", numMetaSurfaces );
+       Sys_Printf( "%9d stripped surfaces\n", numStripSurfaces );
+       Sys_Printf( "%9d fanned surfaces\n", numFanSurfaces );
+       Sys_Printf( "%9d patch meta surfaces\n", numPatchMetaSurfaces );
+       Sys_Printf( "%9d meta verts\n", numMetaVerts );
+       Sys_Printf( "%9d meta triangles\n", numMetaTriangles );
+}
 
 /*
 MakeEntityMetaTriangles()
@@ -652,12 +686,12 @@ void MakeEntityMetaTriangles( entity_t *e )
                                break;
                        
                        case SURFACE_PATCH:
-                               TriangulatePatchSurface( ds );
+                               TriangulatePatchSurface(e, ds );
                                break;
                        
                        case SURFACE_TRIANGLES:
                                break;
-                       
+               
                        case SURFACE_FORCED_META:
                        case SURFACE_META:
                                SurfaceToMetaTriangles( ds );
@@ -973,7 +1007,6 @@ void SmoothMetaTriangles( void )
        int                             indexes[ MAX_SAMPLES ];
        vec3_t                  votes[ MAX_SAMPLES ];
        
-       
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- SmoothMetaTriangles ---\n" );
        
@@ -994,11 +1027,18 @@ void SmoothMetaTriangles( void )
           and set per-vertex smoothing angle */
        for( i = 0, tri = &metaTriangles[ i ]; i < numMetaTriangles; i++, tri++ )
        {
-               /* get shader for shade angle */
+               shadeAngle = defaultShadeAngle;
+
+               /* get shade angle from shader */
                if( tri->si->shadeAngleDegrees > 0.0f )
                        shadeAngle = DEG2RAD( tri->si->shadeAngleDegrees );
-               else
+               /* get shade angle from entity */
+               else if( tri->shadeAngleDegrees > 0.0f )
+                       shadeAngle = DEG2RAD( tri->shadeAngleDegrees );
+               
+               if( shadeAngle <= 0.0f ) 
                        shadeAngle = defaultShadeAngle;
+
                if( shadeAngle > maxShadeAngle )
                        maxShadeAngle = shadeAngle;
                
@@ -1186,14 +1226,15 @@ returns the score of the triangle added
 #define ST_SCORE2                      (2 * (ST_SCORE))
 
 #define ADEQUATE_SCORE         ((AXIS_MIN) + 1 * (VERT_SCORE))
-#define GOOD_SCORE                     ((AXIS_MIN) + 2 * (VERT_SCORE) + 4 * (ST_SCORE))
-#define PERFECT_SCORE          ((AXIS_MIN) + + 3 * (VERT_SCORE) + (SURFACE_SCORE) + 4 * (ST_SCORE))
+#define GOOD_SCORE                     ((AXIS_MIN) + 2 * (VERT_SCORE)                   + 4 * (ST_SCORE))
+#define PERFECT_SCORE          ((AXIS_MIN) + 3 * (VERT_SCORE) + (SURFACE_SCORE) + 4 * (ST_SCORE))
+//#define MAX_BBOX_DISTANCE   16
 
 static int AddMetaTriangleToSurface( mapDrawSurface_t *ds, metaTriangle_t *tri, qboolean testAdd )
 {
        int                                     i, score, coincident, ai, bi, ci, oldTexRange[ 2 ];
        float                           lmMax;
-       vec3_t                          mins, maxs;
+       vec3_t                          mins, maxs, p;
        qboolean                        inTexRange, es, et;
        mapDrawSurface_t        old;
        
@@ -1224,6 +1265,32 @@ static int AddMetaTriangleToSurface( mapDrawSurface_t *ds, metaTriangle_t *tri,
                if( tri->planeNum >= 0 && tri->planeNum != ds->planeNum )
                        return 0;
        }
+
+#if MAX_BBOX_DISTANCE > 0
+       VectorCopy( ds->mins, mins );
+       VectorCopy( ds->maxs, maxs );
+       mins[0] -= MAX_BBOX_DISTANCE;
+       mins[1] -= MAX_BBOX_DISTANCE;
+       mins[2] -= MAX_BBOX_DISTANCE;
+       maxs[0] += MAX_BBOX_DISTANCE;
+       maxs[1] += MAX_BBOX_DISTANCE;
+       maxs[2] += MAX_BBOX_DISTANCE;
+#define CHECK_1D(mins, v, maxs) ((mins) <= (v) && (v) <= (maxs))
+#define CHECK_3D(mins, v, maxs) (CHECK_1D((mins)[0], (v)[0], (maxs)[0]) && CHECK_1D((mins)[1], (v)[1], (maxs)[1]) && CHECK_1D((mins)[2], (v)[2], (maxs)[2]))
+       VectorCopy(metaVerts[ tri->indexes[ 0 ] ].xyz, p);
+       if(!CHECK_3D(mins, p, maxs))
+       {
+               VectorCopy(metaVerts[ tri->indexes[ 1 ] ].xyz, p);
+               if(!CHECK_3D(mins, p, maxs))
+               {
+                       VectorCopy(metaVerts[ tri->indexes[ 2 ] ].xyz, p);
+                       if(!CHECK_3D(mins, p, maxs))
+                               return 0;
+               }
+       }
+#undef CHECK_3D
+#undef CHECK_1D
+#endif
        
        /* set initial score */
        score = tri->surfaceNum == ds->surfaceNum ? SURFACE_SCORE : 0;
@@ -1422,6 +1489,7 @@ static void MetaTrianglesToSurface( int numPossibles, metaTriangle_t *possibles,
                ds->planeNum = seed->planeNum;
                ds->fogNum = seed->fogNum;
                ds->sampleSize = seed->sampleSize;
+               ds->shadeAngleDegrees = seed->shadeAngleDegrees;
                ds->verts = verts;
                ds->indexes = indexes;
                VectorCopy( seed->lightmapAxis, ds->lightmapAxis );