]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/model.c
Merge branch 'master' of ssh://git.xonotic.org/netradiant
[xonotic/netradiant.git] / tools / quake3 / q3map2 / model.c
index 82bf307baa79506a674fd3459a040b58079f1626..cbba5c5d3b29001bf0ab15cbb2727344fb6ef46e 100644 (file)
@@ -206,7 +206,7 @@ InsertModel() - ydnar
 adds a picomodel into the bsp
 */
 
-void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale )
+void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle )
 {
        int                                     i, j, k, s, numSurfaces;
        m4x4_t                          identity, nTransform;
@@ -252,6 +252,10 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade
        /* fix bogus lightmap scale */
        if( lightmapScale <= 0.0f )
                lightmapScale = 1.0f;
+
+       /* fix bogus shade angle */
+       if( shadeAngle <= 0.0f )
+               shadeAngle = 0.0f;
        
        /* each surface on the model will become a new map drawsurface */
        numSurfaces = PicoGetModelNumSurfaces( model );
@@ -267,9 +271,6 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade
                if( PicoGetSurfaceType( surface ) != PICO_TRIANGLES )
                        continue;
                
-               /* fix the surface's normals */
-               PicoFixSurfaceNormals( surface );
-               
                /* allocate a surface (ydnar: gs mods) */
                ds = AllocDrawSurface( SURFACE_TRIANGLES );
                ds->entityNum = eNum;
@@ -320,13 +321,26 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade
                
                /* set shader */
                ds->shaderInfo = si;
-               
-               /* set lightmap scale */
-               ds->lightmapScale = lightmapScale;
-               
+
                /* force to meta? */
                if( (si != NULL && si->forceMeta) || (spawnFlags & 4) ) /* 3rd bit */
                        ds->type = SURFACE_FORCED_META;
+
+               /* fix the surface's normals (jal: conditioned by shader info) */
+               if( !(spawnFlags & 64) && ( shadeAngle == 0.0f || ds->type != SURFACE_FORCED_META ) )
+                       PicoFixSurfaceNormals( surface );
+
+               /* set sample size */
+               if( lightmapSampleSize > 0.0f )
+                       ds->sampleSize = lightmapSampleSize;
+               
+               /* set lightmap scale */
+               if( lightmapScale > 0.0f )
+                       ds->lightmapScale = lightmapScale;
+
+               /* set shading angle */
+               if( shadeAngle > 0.0f )
+                       ds->shadeAngleDegrees = shadeAngle;
                
                /* set particulars */
                ds->numVerts = PicoGetSurfaceNumVertexes( surface );
@@ -382,10 +396,20 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade
                        {
                                dv->lightmap[ j ][ 0 ] = 0.0f;
                                dv->lightmap[ j ][ 1 ] = 0.0f;
-                               dv->color[ j ][ 0 ] = color[ 0 ];
-                               dv->color[ j ][ 1 ] = color[ 1 ];
-                               dv->color[ j ][ 2 ] = color[ 2 ];
-                               dv->color[ j ][ 3 ] = color[ 3 ];
+                               if(spawnFlags & 32) // spawnflag 32: model color -> alpha hack
+                               {
+                                       dv->color[ j ][ 0 ] = 255.0f;
+                                       dv->color[ j ][ 1 ] = 255.0f;
+                                       dv->color[ j ][ 2 ] = 255.0f;
+                                       dv->color[ j ][ 3 ] = RGBTOGRAY( color );
+                               }
+                               else
+                               {
+                                       dv->color[ j ][ 0 ] = color[ 0 ];
+                                       dv->color[ j ][ 1 ] = color[ 1 ];
+                                       dv->color[ j ][ 2 ] = color[ 2 ];
+                                       dv->color[ j ][ 3 ] = color[ 3 ];
+                               }
                        }
                }
                
@@ -405,8 +429,7 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade
                        
                        
                        /* temp hack */
-                       if( !si->clipModel &&
-                               ((si->compileFlags & C_TRANSLUCENT) || !(si->compileFlags & C_SOLID)) )
+                       if( !si->clipModel && !(si->compileFlags & C_SOLID) )
                                continue;
                        
                        /* walk triangle list */
@@ -587,6 +610,8 @@ void AddTriangleModels( entity_t *e )
        char                    shader[ MAX_QPATH ];
        shaderInfo_t    *celShader;
        float                   temp, baseLightmapScale, lightmapScale;
+       float                   shadeAngle;
+       int                             lightmapSampleSize;
        vec3_t                  origin, scale, angles;
        m4x4_t                  transform;
        epair_t                 *ep;
@@ -610,9 +635,23 @@ void AddTriangleModels( entity_t *e )
        }
        
        /* get lightmap scale */
-       baseLightmapScale = FloatForKey( e, "_lightmapscale" );
-       if( baseLightmapScale <= 0.0f )
-               baseLightmapScale = 0.0f;
+       /* vortex: added _ls key (short name of lightmapscale) */
+       baseLightmapScale = 0.0f;
+       if( strcmp( "", ValueForKey( e, "lightmapscale" ) ) ||
+               strcmp( "", ValueForKey( e, "_lightmapscale" ) ) || 
+               strcmp( "", ValueForKey( e, "_ls" ) ) )
+       {
+               baseLightmapScale = FloatForKey( e, "lightmapscale" );
+               if( baseLightmapScale <= 0.0f )
+                       baseLightmapScale = FloatForKey( e, "_lightmapscale" );
+               if( baseLightmapScale <= 0.0f )
+                       baseLightmapScale = FloatForKey( e, "_ls" );
+               if( baseLightmapScale < 0.0f )
+                       baseLightmapScale = 0.0f;
+               if( baseLightmapScale > 0.0f )
+                       Sys_Printf( "World Entity has lightmap scale of %.4f\n", baseLightmapScale );
+       }
+       
        
        /* walk the entity list */
        for( num = 1; num < numEntities; num++ )
@@ -730,14 +769,58 @@ void AddTriangleModels( entity_t *e )
                }
                else
                        celShader = *globalCelShader ? ShaderInfoForShader(globalCelShader) : NULL;
-               
+
+               /* jal : entity based _samplesize */
+               lightmapSampleSize = 0;
+               if ( strcmp( "", ValueForKey( e2, "_lightmapsamplesize" ) ) )
+                       lightmapSampleSize = IntForKey( e2, "_lightmapsamplesize" );
+               else if ( strcmp( "", ValueForKey( e2, "_samplesize" ) ) )
+                       lightmapSampleSize = IntForKey( e2, "_samplesize" );
+
+               if( lightmapSampleSize < 0 )
+                       lightmapSampleSize = 0;
+
+               if( lightmapSampleSize > 0.0f )
+                       Sys_Printf( "misc_model has lightmap sample size of %.d\n", lightmapSampleSize );
+
                /* get lightmap scale */
-               lightmapScale = FloatForKey( e2, "_lightmapscale" );
-               if( lightmapScale <= 0.0f )
-                       lightmapScale = baseLightmapScale;
+               /* vortex: added _ls key (short name of lightmapscale) */
+               lightmapScale = 0.0f;
+               if( strcmp( "", ValueForKey( e2, "lightmapscale" ) ) ||
+                       strcmp( "", ValueForKey( e2, "_lightmapscale" ) ) || 
+                       strcmp( "", ValueForKey( e2, "_ls" ) ) )
+               {
+                       lightmapScale = FloatForKey( e2, "lightmapscale" );
+                       if( lightmapScale <= 0.0f )
+                               lightmapScale = FloatForKey( e2, "_lightmapscale" );
+                       if( lightmapScale <= 0.0f )
+                               lightmapScale = FloatForKey( e2, "_ls" );
+                       if( lightmapScale < 0.0f )
+                               lightmapScale = 0.0f;
+                       if( lightmapScale > 0.0f )
+                               Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale );
+               }
+
+               /* jal : entity based _shadeangle */
+               shadeAngle = 0.0f;
+               if ( strcmp( "", ValueForKey( e2, "_shadeangle" ) ) )
+                       shadeAngle = FloatForKey( e2, "_shadeangle" );
+               /* vortex' aliases */
+               else if ( strcmp( "", ValueForKey( mapEnt, "_smoothnormals" ) ) )
+                       shadeAngle = FloatForKey( mapEnt, "_smoothnormals" );
+               else if ( strcmp( "", ValueForKey( mapEnt, "_sn" ) ) )
+                       shadeAngle = FloatForKey( mapEnt, "_sn" );
+               else if ( strcmp( "", ValueForKey( mapEnt, "_smooth" ) ) )
+                       shadeAngle = FloatForKey( mapEnt, "_smooth" );
+
+               if( shadeAngle < 0.0f )
+                       shadeAngle = 0.0f;
+
+               if( shadeAngle > 0.0f )
+                       Sys_Printf( "misc_model has shading angle of %.4f\n", shadeAngle );
                
                /* insert the model */
-               InsertModel( (char*) model, frame, transform, remap, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale );
+               InsertModel( (char*) model, frame, transform, remap, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale, lightmapSampleSize, shadeAngle );
                
                /* free shader remappings */
                while( remap != NULL )