1 /* -------------------------------------------------------------------------------
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 ----------------------------------------------------------------------------------
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
27 ------------------------------------------------------------------------------- */
43 callback for picomodel.lib
46 void PicoPrintFunc( int level, const char *str )
53 Sys_Printf( "%s\n", str );
57 Sys_FPrintf( SYS_VRB, "%s\n", str );
61 Sys_Printf( "WARNING: %s\n", str );
65 Sys_Printf( "ERROR: %s\n", str );
69 Error( "ERROR: %s\n", str );
78 callback for picomodel.lib
81 void PicoLoadFileFunc( const char *name, byte **buffer, int *bufSize )
83 *bufSize = vfsLoadFile( name, (void**) buffer, 0 );
90 finds an existing picoModel and returns a pointer to the picoModel_t struct or NULL if not found
93 picoModel_t *FindModel( const char *name, int frame )
99 if( numPicoModels <= 0 )
100 memset( picoModels, 0, sizeof( picoModels ) );
103 if( name == NULL || name[ 0 ] == '\0' )
107 for( i = 0; i < MAX_MODELS; i++ )
109 if( picoModels[ i ] != NULL &&
110 !strcmp( PicoGetModelName( picoModels[ i ] ), name ) &&
111 PicoGetModelFrameNum( picoModels[ i ] ) == frame )
112 return picoModels[ i ];
115 /* no matching picoModel found */
123 loads a picoModel and returns a pointer to the picoModel_t struct or NULL if not found
126 picoModel_t *LoadModel( const char *name, int frame )
129 picoModel_t *model, **pm;
133 if( numPicoModels <= 0 )
134 memset( picoModels, 0, sizeof( picoModels ) );
137 if( name == NULL || name[ 0 ] == '\0' )
140 /* try to find existing picoModel */
141 model = FindModel( name, frame );
145 /* none found, so find first non-null picoModel */
147 for( i = 0; i < MAX_MODELS; i++ )
149 if( picoModels[ i ] == NULL )
151 pm = &picoModels[ i ];
156 /* too many picoModels? */
158 Error( "MAX_MODELS (%d) exceeded, there are too many model files referenced by the map.", MAX_MODELS );
160 /* attempt to parse model */
161 *pm = PicoLoadModel( name, frame );
163 /* if loading failed, make a bogus model to silence the rest of the warnings */
166 /* allocate a new model */
167 *pm = PicoNewModel();
172 PicoSetModelName( *pm, name );
173 PicoSetModelFrameNum( *pm, frame );
179 int numSurfaces, numVertexes;
183 Sys_Printf( "Model %s\n", name );
184 numSurfaces = PicoGetModelNumSurfaces( *pm );
185 for( i = 0; i < numSurfaces; i++ )
187 ps = PicoGetModelSurface( *pm, i );
188 numVertexes = PicoGetSurfaceNumVertexes( ps );
189 Sys_Printf( "Surface %d has %d vertexes\n", i, numVertexes );
198 /* return the picoModel */
205 InsertModel() - ydnar
206 adds a picomodel into the bsp
209 void InsertModel( const char *name, int skin, 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 )
211 int i, j, k, s, numSurfaces;
212 m4x4_t identity, nTransform;
214 picoShader_t *shader;
215 picoSurface_t *surface;
217 mapDrawSurface_t *ds;
219 char *picoShaderName;
220 char shaderName[ MAX_QPATH ];
221 picoVec_t *xyz, *normal, *st;
223 picoIndex_t *indexes;
225 skinfile_t *sf, *sf2;
226 double normalEpsilon_save;
227 double distanceEpsilon_save;
228 char skinfilename[ MAX_QPATH ];
229 char *skinfilecontent;
231 char *skinfileptr, *skinfilenextptr;
232 FILE *skinfilehandle;
236 model = LoadModel( name, frame );
241 snprintf(skinfilename, sizeof(skinfilename), "%s_%d.skin", name, skin);
242 skinfilename[sizeof(skinfilename)-1] = 0;
243 skinfilehandle = fopen(skinfilename, "r");
244 skinfilesize = vfsLoadFile(skinfilename, (void**) &skinfilecontent, 0);
245 if(skinfilesize < 0 && skin != 0)
247 /* fallback to skin 0 if invalid */
248 snprintf(skinfilename, sizeof(skinfilename), "%s_0.skin", name);
249 skinfilename[sizeof(skinfilename)-1] = 0;
250 skinfilesize = vfsLoadFile(skinfilename, (void**) &skinfilecontent, 0);
251 if(skinfilesize >= 0)
252 Sys_Printf( "Skin %d of %s does not exist, using 0 instead\n", skin, name );
255 if(skinfilesize >= 0)
257 Sys_Printf( "Using skin %d of %s\n", skin, name );
259 for(skinfileptr = skinfilecontent; *skinfileptr; skinfileptr = skinfilenextptr)
264 skinfilenextptr = strchr(skinfileptr, '\r');
267 *skinfilenextptr++ = 0;
271 skinfilenextptr = strchr(skinfileptr, '\n');
273 *skinfilenextptr++ = 0;
275 skinfilenextptr = skinfileptr + strlen(skinfileptr);
278 /* create new item */
280 sf = safe_malloc( sizeof( *sf ) );
283 sprintf(format, "replace %%%ds %%%ds", (int)sizeof(sf->name)-1, (int)sizeof(sf->to)-1);
284 if(sscanf(skinfileptr, format, sf->name, sf->to) == 2)
286 sprintf(format, " %%%d[^, ] ,%%%ds", (int)sizeof(sf->name)-1, (int)sizeof(sf->to)-1);
287 if((pos = sscanf(skinfileptr, format, sf->name, sf->to)) == 2)
290 /* invalid input line -> discard sf struct */
291 Sys_Printf( "Discarding skin directive in %s: %s\n", skinfilename, skinfileptr );
295 free(skinfilecontent);
298 /* handle null matrix */
299 if( transform == NULL )
301 m4x4_identity( identity );
302 transform = identity;
305 /* hack: Stable-1_2 and trunk have differing row/column major matrix order
306 this transpose is necessary with Stable-1_2
307 uncomment the following line with old m4x4_t (non 1.3/spog_branch) code */
308 //% m4x4_transpose( transform );
310 /* create transform matrix for normals */
311 memcpy( nTransform, transform, sizeof( m4x4_t ) );
312 if( m4x4_invert( nTransform ) )
313 Sys_FPrintf( SYS_VRB, "WARNING: Can't invert model transform matrix, using transpose instead\n" );
314 m4x4_transpose( nTransform );
316 /* fix bogus lightmap scale */
317 if( lightmapScale <= 0.0f )
318 lightmapScale = 1.0f;
320 /* fix bogus shade angle */
321 if( shadeAngle <= 0.0f )
324 /* each surface on the model will become a new map drawsurface */
325 numSurfaces = PicoGetModelNumSurfaces( model );
326 //% Sys_FPrintf( SYS_VRB, "Model %s has %d surfaces\n", name, numSurfaces );
327 for( s = 0; s < numSurfaces; s++ )
330 surface = PicoGetModelSurface( model, s );
331 if( surface == NULL )
334 /* only handle triangle surfaces initially (fixme: support patches) */
335 if( PicoGetSurfaceType( surface ) != PICO_TRIANGLES )
338 /* allocate a surface (ydnar: gs mods) */
339 ds = AllocDrawSurface( SURFACE_TRIANGLES );
340 ds->entityNum = eNum;
341 ds->castShadows = castShadows;
342 ds->recvShadows = recvShadows;
344 /* get shader name */
345 shader = PicoGetSurfaceShader( surface );
349 picoShaderName = PicoGetShaderName( shader );
351 /* handle .skin file */
354 picoShaderName = NULL;
355 for(sf2 = sf; sf2 != NULL; sf2 = sf2->next)
357 if( !Q_stricmp( surface->name, sf2->name ) )
359 Sys_FPrintf( SYS_VRB, "Skin file: mapping %s to %s\n", surface->name, sf2->to );
360 picoShaderName = sf2->to;
366 Sys_FPrintf( SYS_VRB, "Skin file: not mapping %s\n", surface->name );
371 /* handle shader remapping */
373 for( rm = remap; rm != NULL; rm = rm->next )
375 if( rm->from[ 0 ] == '*' && rm->from[ 1 ] == '\0' )
377 else if( !Q_stricmp( picoShaderName, rm->from ) )
379 Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", picoShaderName, rm->to );
380 picoShaderName = rm->to;
388 Sys_FPrintf( SYS_VRB, "Globbing %s to %s\n", picoShaderName, glob->to );
389 picoShaderName = glob->to;
392 /* shader renaming for sof2 */
393 if( renameModelShaders )
395 strcpy( shaderName, picoShaderName );
396 StripExtension( shaderName );
398 strcat( shaderName, "_RMG_BSP" );
400 strcat( shaderName, "_BSP" );
401 si = ShaderInfoForShader( shaderName );
404 si = ShaderInfoForShader( picoShaderName );
410 if( (si != NULL && si->forceMeta) || (spawnFlags & 4) ) /* 3rd bit */
411 ds->type = SURFACE_FORCED_META;
413 /* fix the surface's normals (jal: conditioned by shader info) */
414 if( !(spawnFlags & 64) && ( shadeAngle == 0.0f || ds->type != SURFACE_FORCED_META ) )
415 PicoFixSurfaceNormals( surface );
417 /* set sample size */
418 if( lightmapSampleSize > 0.0f )
419 ds->sampleSize = lightmapSampleSize;
421 /* set lightmap scale */
422 if( lightmapScale > 0.0f )
423 ds->lightmapScale = lightmapScale;
425 /* set shading angle */
426 if( shadeAngle > 0.0f )
427 ds->shadeAngleDegrees = shadeAngle;
429 /* set particulars */
430 ds->numVerts = PicoGetSurfaceNumVertexes( surface );
431 ds->verts = safe_malloc( ds->numVerts * sizeof( ds->verts[ 0 ] ) );
432 memset( ds->verts, 0, ds->numVerts * sizeof( ds->verts[ 0 ] ) );
434 ds->numIndexes = PicoGetSurfaceNumIndexes( surface );
435 ds->indexes = safe_malloc( ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
436 memset( ds->indexes, 0, ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
439 for( i = 0; i < ds->numVerts; i++ )
442 dv = &ds->verts[ i ];
445 xyz = PicoGetSurfaceXYZ( surface, i );
446 VectorCopy( xyz, dv->xyz );
447 m4x4_transform_point( transform, dv->xyz );
449 normal = PicoGetSurfaceNormal( surface, i );
450 VectorCopy( normal, dv->normal );
451 m4x4_transform_normal( nTransform, dv->normal );
452 VectorNormalize( dv->normal, dv->normal );
454 /* ydnar: tek-fu celshading support for flat shaded shit */
457 dv->st[ 0 ] = si->stFlat[ 0 ];
458 dv->st[ 1 ] = si->stFlat[ 1 ];
461 /* ydnar: gs mods: added support for explicit shader texcoord generation */
464 /* project the texture */
465 dv->st[ 0 ] = DotProduct( si->vecs[ 0 ], dv->xyz );
466 dv->st[ 1 ] = DotProduct( si->vecs[ 1 ], dv->xyz );
469 /* normal texture coordinates */
472 st = PicoGetSurfaceST( surface, 0, i );
473 dv->st[ 0 ] = st[ 0 ];
474 dv->st[ 1 ] = st[ 1 ];
477 /* set lightmap/color bits */
478 color = PicoGetSurfaceColor( surface, 0, i );
479 for( j = 0; j < MAX_LIGHTMAPS; j++ )
481 dv->lightmap[ j ][ 0 ] = 0.0f;
482 dv->lightmap[ j ][ 1 ] = 0.0f;
483 if(spawnFlags & 32) // spawnflag 32: model color -> alpha hack
485 dv->color[ j ][ 0 ] = 255.0f;
486 dv->color[ j ][ 1 ] = 255.0f;
487 dv->color[ j ][ 2 ] = 255.0f;
488 dv->color[ j ][ 3 ] = RGBTOGRAY( color );
492 dv->color[ j ][ 0 ] = color[ 0 ];
493 dv->color[ j ][ 1 ] = color[ 1 ];
494 dv->color[ j ][ 2 ] = color[ 2 ];
495 dv->color[ j ][ 3 ] = color[ 3 ];
501 indexes = PicoGetSurfaceIndexes( surface, 0 );
502 for( i = 0; i < ds->numIndexes; i++ )
503 ds->indexes[ i ] = indexes[ i ];
506 ds->celShader = celShader;
508 /* ydnar: giant hack land: generate clipping brushes for model triangles */
509 if( si->clipModel || (spawnFlags & 2) ) /* 2nd bit */
511 vec3_t points[ 4 ], backs[ 3 ];
512 vec4_t plane, reverse, pa, pb, pc;
516 if( !si->clipModel && !(si->compileFlags & C_SOLID) )
519 /* walk triangle list */
520 for( i = 0; i < ds->numIndexes; i += 3 )
523 AUTOEXPAND_BY_REALLOC(mapplanes, (nummapplanes+64) << 1, allocatedmapplanes, 1024);
525 /* make points and back points */
526 for( j = 0; j < 3; j++ )
529 dv = &ds->verts[ ds->indexes[ i + j ] ];
532 VectorCopy( dv->xyz, points[ j ] );
533 VectorCopy( dv->xyz, backs[ j ] );
535 /* find nearest axial to normal and push back points opposite */
536 /* note: this doesn't work as well as simply using the plane of the triangle, below */
537 for( k = 0; k < 3; k++ )
539 if( fabs( dv->normal[ k ] ) >= fabs( dv->normal[ (k + 1) % 3 ] ) &&
540 fabs( dv->normal[ k ] ) >= fabs( dv->normal[ (k + 2) % 3 ] ) )
542 backs[ j ][ k ] += dv->normal[ k ] < 0.0f ? 64.0f : -64.0f;
548 VectorCopy( points[0], points[3] ); // for cyclic usage
550 /* make plane for triangle */
551 // div0: add some extra spawnflags:
552 // 0: snap normals to axial planes for extrusion
553 // 8: extrude with the original normals
554 // 16: extrude only with up/down normals (ideal for terrain)
555 // 24: extrude by distance zero (may need engine changes)
556 if( PlaneFromPoints( plane, points[ 0 ], points[ 1 ], points[ 2 ] ) )
559 float backPlaneDistance = 2;
561 if(spawnFlags & 8) // use a DOWN normal
565 // 24: normal as is, and zero width (broken)
566 VectorCopy(plane, bestNormal);
571 VectorCopy(plane, bestNormal);
578 // 16: UP/DOWN normal
579 VectorSet(bestNormal, 0, 0, (plane[2] >= 0 ? 1 : -1));
584 if(fabs(plane[0]) > fabs(plane[1])) // x>y
585 if(fabs(plane[1]) > fabs(plane[2])) // x>y, y>z
586 VectorSet(bestNormal, (plane[0] >= 0 ? 1 : -1), 0, 0);
588 if(fabs(plane[0]) > fabs(plane[2])) // x>z, z>=y
589 VectorSet(bestNormal, (plane[0] >= 0 ? 1 : -1), 0, 0);
591 VectorSet(bestNormal, 0, 0, (plane[2] >= 0 ? 1 : -1));
593 if(fabs(plane[1]) > fabs(plane[2])) // y>z, y>=x
594 VectorSet(bestNormal, 0, (plane[1] >= 0 ? 1 : -1), 0);
596 VectorSet(bestNormal, 0, 0, (plane[2] >= 0 ? 1 : -1));
601 buildBrush = AllocBrush( 48 );
602 buildBrush->entityNum = mapEntityNum;
603 buildBrush->original = buildBrush;
604 buildBrush->contentShader = si;
605 buildBrush->compileFlags = si->compileFlags;
606 buildBrush->contentFlags = si->contentFlags;
607 normalEpsilon_save = normalEpsilon;
608 distanceEpsilon_save = distanceEpsilon;
609 if(si->compileFlags & C_STRUCTURAL) // allow forced structural brushes here
611 buildBrush->detail = qfalse;
613 // only allow EXACT matches when snapping for these (this is mostly for caulk brushes inside a model)
614 if(normalEpsilon > 0)
616 if(distanceEpsilon > 0)
620 buildBrush->detail = qtrue;
622 /* regenerate back points */
623 for( j = 0; j < 3; j++ )
626 dv = &ds->verts[ ds->indexes[ i + j ] ];
628 // shift by some units
629 VectorMA(dv->xyz, -64.0f, bestNormal, backs[j]); // 64 prevents roundoff errors a bit
632 /* make back plane */
633 VectorScale( plane, -1.0f, reverse );
634 reverse[ 3 ] = -plane[ 3 ];
635 if((spawnFlags & 24) != 24)
636 reverse[3] += DotProduct(bestNormal, plane) * backPlaneDistance;
637 // that's at least sqrt(1/3) backPlaneDistance, unless in DOWN mode; in DOWN mode, we are screwed anyway if we encounter a plane that's perpendicular to the xy plane)
639 if( PlaneFromPoints( pa, points[ 2 ], points[ 1 ], backs[ 1 ] ) &&
640 PlaneFromPoints( pb, points[ 1 ], points[ 0 ], backs[ 0 ] ) &&
641 PlaneFromPoints( pc, points[ 0 ], points[ 2 ], backs[ 2 ] ) )
643 /* set up brush sides */
644 buildBrush->numsides = 5;
645 buildBrush->sides[ 0 ].shaderInfo = si;
646 for( j = 1; j < buildBrush->numsides; j++ )
647 buildBrush->sides[ j ].shaderInfo = NULL; // don't emit these faces as draw surfaces, should make smaller BSPs; hope this works
649 buildBrush->sides[ 0 ].planenum = FindFloatPlane( plane, plane[ 3 ], 3, points );
650 buildBrush->sides[ 1 ].planenum = FindFloatPlane( pa, pa[ 3 ], 2, &points[ 1 ] ); // pa contains points[1] and points[2]
651 buildBrush->sides[ 2 ].planenum = FindFloatPlane( pb, pb[ 3 ], 2, &points[ 0 ] ); // pb contains points[0] and points[1]
652 buildBrush->sides[ 3 ].planenum = FindFloatPlane( pc, pc[ 3 ], 2, &points[ 2 ] ); // pc contains points[2] and points[0] (copied to points[3]
653 buildBrush->sides[ 4 ].planenum = FindFloatPlane( reverse, reverse[ 3 ], 3, backs );
661 normalEpsilon = normalEpsilon_save;
662 distanceEpsilon = distanceEpsilon_save;
665 if( CreateBrushWindings( buildBrush ) )
668 //% EmitBrushes( buildBrush, NULL, NULL );
669 buildBrush->next = entities[ mapEntityNum ].brushes;
670 entities[ mapEntityNum ].brushes = buildBrush;
671 entities[ mapEntityNum ].numBrushes++;
685 adds misc_model surfaces to the bsp
688 void AddTriangleModels( entity_t *e )
690 int num, frame, skin, castShadows, recvShadows, spawnFlags;
692 const char *targetName;
693 const char *target, *model, *value;
694 char shader[ MAX_QPATH ];
695 shaderInfo_t *celShader;
696 float temp, baseLightmapScale, lightmapScale;
698 int lightmapSampleSize;
699 vec3_t origin, scale, angles;
702 remap_t *remap, *remap2;
707 Sys_FPrintf( SYS_VRB, "--- AddTriangleModels ---\n" );
709 /* get current brush entity targetname */
714 targetName = ValueForKey( e, "targetname" );
716 /* misc_model entities target non-worldspawn brush model entities */
717 if( targetName[ 0 ] == '\0' )
721 /* get lightmap scale */
722 /* vortex: added _ls key (short name of lightmapscale) */
723 baseLightmapScale = 0.0f;
724 if( strcmp( "", ValueForKey( e, "lightmapscale" ) ) ||
725 strcmp( "", ValueForKey( e, "_lightmapscale" ) ) ||
726 strcmp( "", ValueForKey( e, "_ls" ) ) )
728 baseLightmapScale = FloatForKey( e, "lightmapscale" );
729 if( baseLightmapScale <= 0.0f )
730 baseLightmapScale = FloatForKey( e, "_lightmapscale" );
731 if( baseLightmapScale <= 0.0f )
732 baseLightmapScale = FloatForKey( e, "_ls" );
733 if( baseLightmapScale < 0.0f )
734 baseLightmapScale = 0.0f;
735 if( baseLightmapScale > 0.0f )
736 Sys_Printf( "World Entity has lightmap scale of %.4f\n", baseLightmapScale );
740 /* walk the entity list */
741 for( num = 1; num < numEntities; num++ )
744 e2 = &entities[ num ];
746 /* convert misc_models into raw geometry */
747 if( Q_stricmp( "misc_model", ValueForKey( e2, "classname" ) ) )
750 /* ydnar: added support for md3 models on non-worldspawn models */
751 target = ValueForKey( e2, "target" );
752 if( strcmp( target, targetName ) )
756 model = ValueForKey( e2, "model" );
757 if( model[ 0 ] == '\0' )
759 Sys_Printf( "WARNING: misc_model at %i %i %i without a model key\n",
760 (int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] );
764 /* get model frame */
765 frame = IntForKey( e2, "_frame" );
767 /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */
770 castShadows = WORLDSPAWN_CAST_SHADOWS;
771 recvShadows = WORLDSPAWN_RECV_SHADOWS;
774 /* other entities don't cast any shadows, but recv worldspawn shadows */
777 castShadows = ENTITY_CAST_SHADOWS;
778 recvShadows = ENTITY_RECV_SHADOWS;
781 /* get explicit shadow flags */
782 GetEntityShadowFlags( e2, e, &castShadows, &recvShadows );
785 spawnFlags = IntForKey( e2, "spawnflags" );
788 GetVectorForKey( e2, "origin", origin );
789 VectorSubtract( origin, e->origin, origin ); /* offset by parent */
792 scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = 1.0f;
793 temp = FloatForKey( e2, "modelscale" );
795 scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = temp;
796 value = ValueForKey( e2, "modelscale_vec" );
797 if( value[ 0 ] != '\0' )
798 sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] );
800 /* get "angle" (yaw) or "angles" (pitch yaw roll) */
801 angles[ 0 ] = angles[ 1 ] = angles[ 2 ] = 0.0f;
802 angles[ 2 ] = FloatForKey( e2, "angle" );
803 value = ValueForKey( e2, "angles" );
804 if( value[ 0 ] != '\0' )
805 sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] );
807 /* set transform matrix (thanks spog) */
808 m4x4_identity( transform );
809 m4x4_pivoted_transform_by_vec3( transform, origin, angles, eXYZ, scale, vec3_origin );
811 /* get shader remappings */
813 for( ep = e2->epairs; ep != NULL; ep = ep->next )
815 /* look for keys prefixed with "_remap" */
816 if( ep->key != NULL && ep->value != NULL &&
817 ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' &&
818 !Q_strncasecmp( ep->key, "_remap", 6 ) )
820 /* create new remapping */
822 remap = safe_malloc( sizeof( *remap ) );
823 remap->next = remap2;
824 strcpy( remap->from, ep->value );
826 /* split the string */
827 split = strchr( remap->from, ';' );
830 Sys_Printf( "WARNING: Shader _remap key found in misc_model without a ; character\n" );
836 /* store the split */
838 strcpy( remap->to, (split + 1) );
841 //% Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", remap->from, remap->to );
845 /* ydnar: cel shader support */
846 value = ValueForKey( e2, "_celshader" );
847 if( value[ 0 ] == '\0' )
848 value = ValueForKey( &entities[ 0 ], "_celshader" );
849 if( value[ 0 ] != '\0' )
851 sprintf( shader, "textures/%s", value );
852 celShader = ShaderInfoForShader( shader );
855 celShader = *globalCelShader ? ShaderInfoForShader(globalCelShader) : NULL;
857 /* jal : entity based _samplesize */
858 lightmapSampleSize = 0;
859 if ( strcmp( "", ValueForKey( e2, "_lightmapsamplesize" ) ) )
860 lightmapSampleSize = IntForKey( e2, "_lightmapsamplesize" );
861 else if ( strcmp( "", ValueForKey( e2, "_samplesize" ) ) )
862 lightmapSampleSize = IntForKey( e2, "_samplesize" );
864 if( lightmapSampleSize < 0 )
865 lightmapSampleSize = 0;
867 if( lightmapSampleSize > 0.0f )
868 Sys_Printf( "misc_model has lightmap sample size of %.d\n", lightmapSampleSize );
870 /* get lightmap scale */
871 /* vortex: added _ls key (short name of lightmapscale) */
872 lightmapScale = 0.0f;
873 if( strcmp( "", ValueForKey( e2, "lightmapscale" ) ) ||
874 strcmp( "", ValueForKey( e2, "_lightmapscale" ) ) ||
875 strcmp( "", ValueForKey( e2, "_ls" ) ) )
877 lightmapScale = FloatForKey( e2, "lightmapscale" );
878 if( lightmapScale <= 0.0f )
879 lightmapScale = FloatForKey( e2, "_lightmapscale" );
880 if( lightmapScale <= 0.0f )
881 lightmapScale = FloatForKey( e2, "_ls" );
882 if( lightmapScale < 0.0f )
883 lightmapScale = 0.0f;
884 if( lightmapScale > 0.0f )
885 Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale );
888 /* jal : entity based _shadeangle */
890 if ( strcmp( "", ValueForKey( e2, "_shadeangle" ) ) )
891 shadeAngle = FloatForKey( e2, "_shadeangle" );
892 /* vortex' aliases */
893 else if ( strcmp( "", ValueForKey( e2, "_smoothnormals" ) ) )
894 shadeAngle = FloatForKey( e2, "_smoothnormals" );
895 else if ( strcmp( "", ValueForKey( e2, "_sn" ) ) )
896 shadeAngle = FloatForKey( e2, "_sn" );
897 else if ( strcmp( "", ValueForKey( e2, "_smooth" ) ) )
898 shadeAngle = FloatForKey( e2, "_smooth" );
900 if( shadeAngle < 0.0f )
903 if( shadeAngle > 0.0f )
904 Sys_Printf( "misc_model has shading angle of %.4f\n", shadeAngle );
906 skin = IntForKey(e2, "skin");
908 /* insert the model */
909 InsertModel( model, skin, frame, transform, remap, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale, lightmapSampleSize, shadeAngle );
911 /* free shader remappings */
912 while( remap != NULL )
914 remap2 = remap->next;