1 /* -------------------------------------------------------------------------------
2 
3 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 
6 This file is part of GtkRadiant.
7 
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.
12 
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.
17 
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
21 
22 ----------------------------------------------------------------------------------
23 
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."
26 
27 ------------------------------------------------------------------------------- */
28 
29 
30 
31 /* marker */
32 #define MODEL_C
33 
34 
35 
36 /* dependencies */
37 #include "q3map2.h"
38 
39 
40 
41 /*
42 PicoPrintFunc()
43 callback for picomodel.lib
44 */
45 
PicoPrintFunc(int level,const char * str)46 void PicoPrintFunc( int level, const char *str )
47 {
48 	if( str == NULL )
49 		return;
50 	switch( level )
51 	{
52 		case PICO_NORMAL:
53 			Sys_Printf( "%s\n", str );
54 			break;
55 
56 		case PICO_VERBOSE:
57 			Sys_FPrintf( SYS_VRB, "%s\n", str );
58 			break;
59 
60 		case PICO_WARNING:
61 			Sys_Printf( "WARNING: %s\n", str );
62 			break;
63 
64 		case PICO_ERROR:
65 			Sys_Printf( "ERROR: %s\n", str );
66 			break;
67 
68 		case PICO_FATAL:
69 			Error( "ERROR: %s\n", str );
70 			break;
71 	}
72 }
73 
74 
75 
76 /*
77 PicoLoadFileFunc()
78 callback for picomodel.lib
79 */
80 
PicoLoadFileFunc(char * name,byte ** buffer,int * bufSize)81 void PicoLoadFileFunc( char *name, byte **buffer, int *bufSize )
82 {
83 	*bufSize = vfsLoadFile( (const char*) name, (void**) buffer, 0 );
84 }
85 
86 
87 
88 /*
89 FindModel() - ydnar
90 finds an existing picoModel and returns a pointer to the picoModel_t struct or NULL if not found
91 */
92 
FindModel(char * name,int frame)93 picoModel_t *FindModel( char *name, int frame )
94 {
95 	int			i;
96 
97 
98 	/* init */
99 	if( numPicoModels <= 0 )
100 		memset( picoModels, 0, sizeof( picoModels ) );
101 
102 	/* dummy check */
103 	if( name == NULL || name[ 0 ] == '\0' )
104 		return NULL;
105 
106 	/* search list */
107 	for( i = 0; i < MAX_MODELS; i++ )
108 	{
109 		if( picoModels[ i ] != NULL &&
110 			!strcmp( PicoGetModelName( picoModels[ i ] ), name ) &&
111 			PicoGetModelFrameNum( picoModels[ i ] ) == frame )
112 			return picoModels[ i ];
113 	}
114 
115 	/* no matching picoModel found */
116 	return NULL;
117 }
118 
119 
120 
121 /*
122 LoadModel() - ydnar
123 loads a picoModel and returns a pointer to the picoModel_t struct or NULL if not found
124 */
125 
LoadModel(char * name,int frame)126 picoModel_t *LoadModel( char *name, int frame )
127 {
128 	int				i;
129 	picoModel_t		*model, **pm;
130 
131 
132 	/* init */
133 	if( numPicoModels <= 0 )
134 		memset( picoModels, 0, sizeof( picoModels ) );
135 
136 	/* dummy check */
137 	if( name == NULL || name[ 0 ] == '\0' )
138 		return NULL;
139 
140 	/* try to find existing picoModel */
141 	model = FindModel( name, frame );
142 	if( model != NULL )
143 		return model;
144 
145 	/* none found, so find first non-null picoModel */
146 	pm = NULL;
147 	for( i = 0; i < MAX_MODELS; i++ )
148 	{
149 		if( picoModels[ i ] == NULL )
150 		{
151 			pm = &picoModels[ i ];
152 			break;
153 		}
154 	}
155 
156 	/* too many picoModels? */
157 	if( pm == NULL )
158 		Error( "MAX_MODELS (%d) exceeded, there are too many model files referenced by the map.", MAX_MODELS );
159 
160 	/* attempt to parse model */
161 	*pm = PicoLoadModel( (char*) name, frame );
162 
163 	/* if loading failed, make a bogus model to silence the rest of the warnings */
164 	if( *pm == NULL )
165 	{
166 		/* allocate a new model */
167 		*pm = PicoNewModel();
168 		if( *pm == NULL )
169 			return NULL;
170 
171 		/* set data */
172 		PicoSetModelName( *pm, name );
173 		PicoSetModelFrameNum( *pm, frame );
174 	}
175 
176 	/* debug code */
177 	#if 0
178 	{
179 		int				numSurfaces, numVertexes;
180 		picoSurface_t	*ps;
181 
182 
183 		Sys_Printf( "Model %s\n", name );
184 		numSurfaces = PicoGetModelNumSurfaces( *pm );
185 		for( i = 0; i < numSurfaces; i++ )
186 		{
187 			ps = PicoGetModelSurface( *pm, i );
188 			numVertexes = PicoGetSurfaceNumVertexes( ps );
189 			Sys_Printf( "Surface %d has %d vertexes\n", i, numVertexes );
190 		}
191 	}
192 	#endif
193 
194 	/* set count */
195 	if( *pm != NULL )
196 		numPicoModels++;
197 
198 	/* return the picoModel */
199 	return *pm;
200 }
201 
202 
203 
204 /*
205 InsertModel() - ydnar
206 adds a picomodel into the bsp
207 */
208 
InsertModel(char * name,int frame,m4x4_t transform,remap_t * remap,shaderInfo_t * celShader,int eNum,int castShadows,int recvShadows,int spawnFlags,float lightmapScale)209 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 )
210 {
211 	int					i, j, k, s, numSurfaces;
212 	m4x4_t				identity, nTransform;
213 	picoModel_t			*model;
214 	picoShader_t		*shader;
215 	picoSurface_t		*surface;
216 	shaderInfo_t		*si;
217 	mapDrawSurface_t	*ds;
218 	bspDrawVert_t		*dv;
219 	char				*picoShaderName;
220 	char				shaderName[ MAX_QPATH ];
221 	picoVec_t			*xyz, *normal, *st;
222 	byte				*color;
223 	picoIndex_t			*indexes;
224 	remap_t				*rm, *glob;
225 
226 
227 	/* get model */
228 	model = LoadModel( name, frame );
229 	if( model == NULL )
230 		return;
231 
232 	/* handle null matrix */
233 	if( transform == NULL )
234 	{
235 		m4x4_identity( identity );
236 		transform = identity;
237 	}
238 
239 	/* hack: Stable-1_2 and trunk have differing row/column major matrix order
240 	   this transpose is necessary with Stable-1_2
241 	   uncomment the following line with old m4x4_t (non 1.3/spog_branch) code */
242 	//%	m4x4_transpose( transform );
243 
244 	/* create transform matrix for normals */
245 	memcpy( nTransform, transform, sizeof( m4x4_t ) );
246 	if( m4x4_invert( nTransform ) )
247 		Sys_FPrintf( SYS_VRB, "WARNING: Can't invert model transform matrix, using transpose instead\n" );
248 	m4x4_transpose( nTransform );
249 
250 	/* fix bogus lightmap scale */
251 	if( lightmapScale <= 0.0f )
252 		lightmapScale = 1.0f;
253 
254 	/* each surface on the model will become a new map drawsurface */
255 	numSurfaces = PicoGetModelNumSurfaces( model );
256 	//%	Sys_FPrintf( SYS_VRB, "Model %s has %d surfaces\n", name, numSurfaces );
257 	for( s = 0; s < numSurfaces; s++ )
258 	{
259 		/* get surface */
260 		surface = PicoGetModelSurface( model, s );
261 		if( surface == NULL )
262 			continue;
263 
264 		/* only handle triangle surfaces initially (fixme: support patches) */
265 		if( PicoGetSurfaceType( surface ) != PICO_TRIANGLES )
266 			continue;
267 
268 		/* fix the surface's normals */
269 		PicoFixSurfaceNormals( surface );
270 
271 		/* allocate a surface (ydnar: gs mods) */
272 		ds = AllocDrawSurface( SURFACE_TRIANGLES );
273 		ds->entityNum = eNum;
274 		ds->castShadows = castShadows;
275 		ds->recvShadows = recvShadows;
276 
277 		/* get shader name */
278         shader = PicoGetSurfaceShader( surface );
279 		if( shader == NULL )
280 			picoShaderName = "";
281 		else
282 			picoShaderName = PicoGetShaderName( shader );
283 
284 		/* handle shader remapping */
285 		glob = NULL;
286 		for( rm = remap; rm != NULL; rm = rm->next )
287 		{
288 			if( rm->from[ 0 ] == '*' && rm->from[ 1 ] == '\0' )
289 				glob = rm;
290 			else if( !Q_stricmp( picoShaderName, rm->from ) )
291 			{
292 				Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", picoShaderName, rm->to );
293 				picoShaderName = rm->to;
294 				glob = NULL;
295 				break;
296 			}
297 		}
298 
299 		if( glob != NULL )
300 		{
301 			Sys_FPrintf( SYS_VRB, "Globbing %s to %s\n", picoShaderName, glob->to );
302 			picoShaderName = glob->to;
303 		}
304 
305 		/* shader renaming for sof2 */
306 		if( renameModelShaders )
307 		{
308 			strcpy( shaderName, picoShaderName );
309 			StripExtension( shaderName );
310 			if( spawnFlags & 1 )
311 				strcat( shaderName, "_RMG_BSP" );
312 			else
313 				strcat( shaderName, "_BSP" );
314 			si = ShaderInfoForShader( shaderName );
315 		}
316 		else
317 			si = ShaderInfoForShader( picoShaderName );
318 
319 		/* set shader */
320 		ds->shaderInfo = si;
321 
322 		/* set lightmap scale */
323 		ds->lightmapScale = lightmapScale;
324 
325 		/* force to meta? */
326 		if( (si != NULL && si->forceMeta) || (spawnFlags & 4) )	/* 3rd bit */
327 			ds->type = SURFACE_FORCED_META;
328 
329 		/* set particulars */
330 		ds->numVerts = PicoGetSurfaceNumVertexes( surface );
331 		ds->verts = safe_malloc( ds->numVerts * sizeof( ds->verts[ 0 ] ) );
332 		memset( ds->verts, 0, ds->numVerts * sizeof( ds->verts[ 0 ] ) );
333 
334 		ds->numIndexes = PicoGetSurfaceNumIndexes( surface );
335 		ds->indexes = safe_malloc( ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
336 		memset( ds->indexes, 0, ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
337 
338 		/* copy vertexes */
339 		for( i = 0; i < ds->numVerts; i++ )
340 		{
341 			/* get vertex */
342 			dv = &ds->verts[ i ];
343 
344 			/* xyz and normal */
345 			xyz = PicoGetSurfaceXYZ( surface, i );
346 			VectorCopy( xyz, dv->xyz );
347 			m4x4_transform_point( transform, dv->xyz );
348 
349 			normal = PicoGetSurfaceNormal( surface, i );
350 			VectorCopy( normal, dv->normal );
351 			m4x4_transform_normal( nTransform, dv->normal );
352 			VectorNormalize( dv->normal, dv->normal );
353 
354 			/* ydnar: tek-fu celshading support for flat shaded shit */
355 			if( flat )
356 			{
357 				dv->st[ 0 ] = si->stFlat[ 0 ];
358 				dv->st[ 1 ] = si->stFlat[ 1 ];
359 			}
360 
361 			/* ydnar: gs mods: added support for explicit shader texcoord generation */
362 			else if( si->tcGen )
363 			{
364 				/* project the texture */
365 				dv->st[ 0 ] = DotProduct( si->vecs[ 0 ], dv->xyz );
366 				dv->st[ 1 ] = DotProduct( si->vecs[ 1 ], dv->xyz );
367 			}
368 
369 			/* normal texture coordinates */
370 			else
371 			{
372 				st = PicoGetSurfaceST( surface, 0, i );
373 				dv->st[ 0 ] = st[ 0 ];
374 				dv->st[ 1 ] = st[ 1 ];
375 			}
376 
377 			/* set lightmap/color bits */
378 			color = PicoGetSurfaceColor( surface, 0, i );
379 			for( j = 0; j < MAX_LIGHTMAPS; j++ )
380 			{
381 				dv->lightmap[ j ][ 0 ] = 0.0f;
382 				dv->lightmap[ j ][ 1 ] = 0.0f;
383 				dv->color[ j ][ 0 ] = color[ 0 ];
384 				dv->color[ j ][ 1 ] = color[ 1 ];
385 				dv->color[ j ][ 2 ] = color[ 2 ];
386 				dv->color[ j ][ 3 ] = color[ 3 ];
387 			}
388 		}
389 
390 		/* copy indexes */
391 		indexes = PicoGetSurfaceIndexes( surface, 0 );
392 		for( i = 0; i < ds->numIndexes; i++ )
393 			ds->indexes[ i ] = indexes[ i ];
394 
395 		/* set cel shader */
396 		ds->celShader = celShader;
397 
398 		/* ydnar: giant hack land: generate clipping brushes for model triangles */
399 		if( si->clipModel || (spawnFlags & 2) )	/* 2nd bit */
400 		{
401 			vec3_t		points[ 3 ], backs[ 3 ];
402 			vec4_t		plane, reverse, pa, pb, pc;
403 			vec3_t		nadir;
404 
405 
406 			/* temp hack */
407 			if( !si->clipModel &&
408 				((si->compileFlags & C_TRANSLUCENT) || !(si->compileFlags & C_SOLID)) )
409 				continue;
410 
411 			/* overflow check */
412 			if( (nummapplanes + 64) >= (MAX_MAP_PLANES >> 1) )
413 				continue;
414 
415 			/* walk triangle list */
416 			for( i = 0; i < ds->numIndexes; i += 3 )
417 			{
418 				/* overflow hack */
419 				if( (nummapplanes + 64) >= (MAX_MAP_PLANES >> 1) )
420 				{
421 					Sys_Printf( "WARNING: MAX_MAP_PLANES (%d) hit generating clip brushes for model %s.\n",
422 						MAX_MAP_PLANES, name );
423 					break;
424 				}
425 
426 				/* make points and back points */
427 				for( j = 0; j < 3; j++ )
428 				{
429 					/* get vertex */
430 					dv = &ds->verts[ ds->indexes[ i + j ] ];
431 
432 					/* copy xyz */
433 					VectorCopy( dv->xyz, points[ j ] );
434 					VectorCopy( dv->xyz, backs[ j ] );
435 
436 					/* find nearest axial to normal and push back points opposite */
437 					/* note: this doesn't work as well as simply using the plane of the triangle, below */
438 					for( k = 0; k < 3; k++ )
439 					{
440 						if( fabs( dv->normal[ k ] ) > fabs( dv->normal[ (k + 1) % 3 ] ) &&
441 							fabs( dv->normal[ k ] ) > fabs( dv->normal[ (k + 2) % 3 ] ) )
442 						{
443 							backs[ j ][ k ] += dv->normal[ k ] < 0.0f ? 64.0f : -64.0f;
444 							break;
445 						}
446 					}
447 				}
448 
449 				/* make plane for triangle */
450 				if( PlaneFromPoints( plane, points[ 0 ], points[ 1 ], points[ 2 ] ) )
451 				{
452 					/* regenerate back points */
453 					for( j = 0; j < 3; j++ )
454 					{
455 						/* get vertex */
456 						dv = &ds->verts[ ds->indexes[ i + j ] ];
457 
458 						/* copy xyz */
459 						VectorCopy( dv->xyz, backs[ j ] );
460 
461 						/* find nearest axial to plane normal and push back points opposite */
462 						for( k = 0; k < 3; k++ )
463 						{
464 							if( fabs( plane[ k ] ) > fabs( plane[ (k + 1) % 3 ] ) &&
465 								fabs( plane[ k ] ) > fabs( plane[ (k + 2) % 3 ] ) )
466 							{
467 								backs[ j ][ k ] += plane[ k ] < 0.0f ? 64.0f : -64.0f;
468 								break;
469 							}
470 						}
471 					}
472 
473 					/* make back plane */
474 					VectorScale( plane, -1.0f, reverse );
475 					reverse[ 3 ] = -(plane[ 3 ] - 1);
476 
477 					/* make back pyramid point */
478 					VectorCopy( points[ 0 ], nadir );
479 					VectorAdd( nadir, points[ 1 ], nadir );
480 					VectorAdd( nadir, points[ 2 ], nadir );
481 					VectorScale( nadir, 0.3333333333333f, nadir );
482 					VectorMA( nadir, -2.0f, plane, nadir );
483 
484 					/* make 3 more planes */
485 					//%	if( PlaneFromPoints( pa, points[ 2 ], points[ 1 ], nadir ) &&
486 					//%		PlaneFromPoints( pb, points[ 1 ], points[ 0 ], nadir ) &&
487 					//%		PlaneFromPoints( pc, points[ 0 ], points[ 2 ], nadir ) )
488 					if( PlaneFromPoints( pa, points[ 2 ], points[ 1 ], backs[ 1 ] ) &&
489 						PlaneFromPoints( pb, points[ 1 ], points[ 0 ], backs[ 0 ] ) &&
490 						PlaneFromPoints( pc, points[ 0 ], points[ 2 ], backs[ 2 ] ) )
491 					{
492 						/* build a brush */
493 						buildBrush = AllocBrush( 48 );
494 
495 						buildBrush->entityNum = mapEntityNum;
496 						buildBrush->original = buildBrush;
497 						buildBrush->contentShader = si;
498 						buildBrush->compileFlags = si->compileFlags;
499 						buildBrush->contentFlags = si->contentFlags;
500 						buildBrush->detail = qtrue;
501 
502 						/* set up brush sides */
503 						buildBrush->numsides = 5;
504 						for( j = 0; j < buildBrush->numsides; j++ )
505 							buildBrush->sides[ j ].shaderInfo = si;
506 						buildBrush->sides[ 0 ].planenum = FindFloatPlane( plane, plane[ 3 ], 3, points );
507 						buildBrush->sides[ 1 ].planenum = FindFloatPlane( pa, pa[ 3 ], 1, &points[ 2 ] );
508 						buildBrush->sides[ 2 ].planenum = FindFloatPlane( pb, pb[ 3 ], 1, &points[ 1 ] );
509 						buildBrush->sides[ 3 ].planenum = FindFloatPlane( pc, pc[ 3 ], 1, &points[ 0 ] );
510 						buildBrush->sides[ 4 ].planenum = FindFloatPlane( reverse, reverse[ 3 ], 3, points );
511 
512 						/* add to entity */
513 						if( CreateBrushWindings( buildBrush ) )
514 						{
515 							AddBrushBevels();
516 							//%	EmitBrushes( buildBrush, NULL, NULL );
517 							buildBrush->next = entities[ mapEntityNum ].brushes;
518 							entities[ mapEntityNum ].brushes = buildBrush;
519 							entities[ mapEntityNum ].numBrushes++;
520 						}
521 						else
522 							free( buildBrush );
523 					}
524 				}
525 			}
526 		}
527 	}
528 }
529 
530 
531 
532 /*
533 AddTriangleModels()
534 adds misc_model surfaces to the bsp
535 */
536 
AddTriangleModels(entity_t * e)537 void AddTriangleModels( entity_t *e )
538 {
539 	int				num, frame, castShadows, recvShadows, spawnFlags;
540 	entity_t		*e2;
541 	const char		*targetName;
542 	const char		*target, *model, *value;
543 	char			shader[ MAX_QPATH ];
544 	shaderInfo_t	*celShader;
545 	float			temp, baseLightmapScale, lightmapScale;
546 	vec3_t			origin, scale, angles;
547 	m4x4_t			transform;
548 	epair_t			*ep;
549 	remap_t			*remap, *remap2;
550 	char			*split;
551 
552 
553 	/* note it */
554 	Sys_FPrintf( SYS_VRB, "--- AddTriangleModels ---\n" );
555 
556 	/* get current brush entity targetname */
557 	if( e == entities )
558 		targetName = "";
559 	else
560 	{
561 		targetName = ValueForKey( e, "targetname" );
562 
563 		/* misc_model entities target non-worldspawn brush model entities */
564 		if( targetName[ 0 ] == '\0' )
565 			return;
566 	}
567 
568 	/* get lightmap scale */
569 	baseLightmapScale = FloatForKey( e, "_lightmapscale" );
570 	if( baseLightmapScale <= 0.0f )
571 		baseLightmapScale = 0.0f;
572 
573 	/* walk the entity list */
574 	for( num = 1; num < numEntities; num++ )
575 	{
576 		/* get e2 */
577 		e2 = &entities[ num ];
578 
579 		/* convert misc_models into raw geometry */
580 		if( Q_stricmp( "misc_model", ValueForKey( e2, "classname" ) ) )
581 			continue;
582 
583 		/* ydnar: added support for md3 models on non-worldspawn models */
584 		target = ValueForKey( e2, "target" );
585 		if( strcmp( target, targetName ) )
586 			continue;
587 
588 		/* get model name */
589 		model = ValueForKey( e2, "model" );
590 		if( model[ 0 ] == '\0' )
591 		{
592 			Sys_Printf( "WARNING: misc_model at %i %i %i without a model key\n",
593 				(int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] );
594 			continue;
595 		}
596 
597 		/* get model frame */
598 		frame = IntForKey( e2, "_frame" );
599 
600 		/* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */
601 		if( e == entities )
602 		{
603 			castShadows = WORLDSPAWN_CAST_SHADOWS;
604 			recvShadows = WORLDSPAWN_RECV_SHADOWS;
605 		}
606 
607 		/* other entities don't cast any shadows, but recv worldspawn shadows */
608 		else
609 		{
610 			castShadows = ENTITY_CAST_SHADOWS;
611 			recvShadows = ENTITY_RECV_SHADOWS;
612 		}
613 
614 		/* get explicit shadow flags */
615 		GetEntityShadowFlags( e2, e, &castShadows, &recvShadows );
616 
617 		/* get spawnflags */
618 		spawnFlags = IntForKey( e2, "spawnflags" );
619 
620 		/* get origin */
621 		GetVectorForKey( e2, "origin", origin );
622 		VectorSubtract( origin, e->origin, origin );	/* offset by parent */
623 
624 		/* get scale */
625 		scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = 1.0f;
626 		temp = FloatForKey( e2, "modelscale" );
627 		if( temp != 0.0f )
628 			scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = temp;
629 		value = ValueForKey( e2, "modelscale_vec" );
630 		if( value[ 0 ] != '\0' )
631 			sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] );
632 
633 		/* get "angle" (yaw) or "angles" (pitch yaw roll) */
634 		angles[ 0 ] = angles[ 1 ] = angles[ 2 ] = 0.0f;
635 		angles[ 2 ] = FloatForKey( e2, "angle" );
636 		value = ValueForKey( e2, "angles" );
637 		if( value[ 0 ] != '\0' )
638 			sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] );
639 
640 		/* set transform matrix (thanks spog) */
641 		m4x4_identity( transform );
642 		m4x4_pivoted_transform_by_vec3( transform, origin, angles, eXYZ, scale, vec3_origin );
643 
644 		/* get shader remappings */
645 		remap = NULL;
646 		for( ep = e2->epairs; ep != NULL; ep = ep->next )
647 		{
648 			/* look for keys prefixed with "_remap" */
649 			if( ep->key != NULL && ep->value != NULL &&
650 				ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' &&
651 				!Q_strncasecmp( ep->key, "_remap", 6 ) )
652 			{
653 				/* create new remapping */
654 				remap2 = remap;
655 				remap = safe_malloc( sizeof( *remap ) );
656 				remap->next = remap2;
657 				strcpy( remap->from, ep->value );
658 
659 				/* split the string */
660 				split = strchr( remap->from, ';' );
661 				if( split == NULL )
662 				{
663 					Sys_Printf( "WARNING: Shader _remap key found in misc_model without a ; character\n" );
664 					free( remap );
665 					remap = remap2;
666 					continue;
667 				}
668 
669 				/* store the split */
670 				*split = '\0';
671 				strcpy( remap->to, (split + 1) );
672 
673 				/* note it */
674 				//%	Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", remap->from, remap->to );
675 			}
676 		}
677 
678 		/* ydnar: cel shader support */
679 		value = ValueForKey( e2, "_celshader" );
680 		if( value[ 0 ] == '\0' )
681 			value = ValueForKey( &entities[ 0 ], "_celshader" );
682 		if( value[ 0 ] != '\0' )
683 		{
684 			sprintf( shader, "textures/%s", value );
685 			celShader = ShaderInfoForShader( shader );
686 		}
687 		else
688 			celShader = NULL;
689 
690 		/* get lightmap scale */
691 		lightmapScale = FloatForKey( e2, "_lightmapscale" );
692 		if( lightmapScale <= 0.0f )
693 			lightmapScale = baseLightmapScale;
694 
695 		/* insert the model */
696 		InsertModel( (char*) model, frame, transform, remap, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale );
697 
698 		/* free shader remappings */
699 		while( remap != NULL )
700 		{
701 			remap2 = remap->next;
702 			free( remap );
703 			remap = remap2;
704 		}
705 	}
706 }
707