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_FPrintf( SYS_WRN, "WARNING: %s\n", str );
65 Sys_FPrintf( SYS_ERR, "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 ){
82 *bufSize = vfsLoadFile( name, (void**) buffer, 0 );
89 finds an existing picoModel and returns a pointer to the picoModel_t struct or NULL if not found
92 picoModel_t *FindModel( const char *name, int frame ){
97 if ( numPicoModels <= 0 ) {
98 memset( picoModels, 0, sizeof( picoModels ) );
102 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 ];
116 /* no matching picoModel found */
124 loads a picoModel and returns a pointer to the picoModel_t struct or NULL if not found
127 picoModel_t *LoadModel( const char *name, int frame ){
129 picoModel_t *model, **pm;
133 if ( numPicoModels <= 0 ) {
134 memset( picoModels, 0, sizeof( picoModels ) );
138 if ( name == NULL || name[ 0 ] == '\0' ) {
142 /* try to find existing picoModel */
143 model = FindModel( name, frame );
144 if ( model != NULL ) {
148 /* none found, so find first non-null picoModel */
150 for ( i = 0; i < MAX_MODELS; i++ )
152 if ( picoModels[ i ] == NULL ) {
153 pm = &picoModels[ i ];
158 /* too many picoModels? */
160 Error( "MAX_MODELS (%d) exceeded, there are too many model files referenced by the map.", MAX_MODELS );
163 /* attempt to parse model */
164 *pm = PicoLoadModel( name, frame );
166 /* if loading failed, make a bogus model to silence the rest of the warnings */
168 /* allocate a new model */
169 *pm = PicoNewModel();
175 PicoSetModelName( *pm, name );
176 PicoSetModelFrameNum( *pm, frame );
182 int numSurfaces, numVertexes;
186 Sys_Printf( "Model %s\n", name );
187 numSurfaces = PicoGetModelNumSurfaces( *pm );
188 for ( i = 0; i < numSurfaces; i++ )
190 ps = PicoGetModelSurface( *pm, i );
191 numVertexes = PicoGetSurfaceNumVertexes( ps );
192 Sys_Printf( "Surface %d has %d vertexes\n", i, numVertexes );
202 /* return the picoModel */
209 InsertModel() - ydnar
210 adds a picomodel into the bsp
213 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 ){
214 int i, j, s, numSurfaces;
215 m4x4_t identity, nTransform;
217 picoShader_t *shader;
218 picoSurface_t *surface;
220 mapDrawSurface_t *ds;
222 char *picoShaderName;
223 char shaderName[ MAX_QPATH ];
224 picoVec_t *xyz, *normal, *st;
226 picoIndex_t *indexes;
228 skinfile_t *sf, *sf2;
229 double normalEpsilon_save;
230 double distanceEpsilon_save;
231 char skinfilename[ MAX_QPATH ];
232 char *skinfilecontent;
234 char *skinfileptr, *skinfilenextptr;
238 model = LoadModel( name, frame );
239 if ( model == NULL ) {
244 snprintf( skinfilename, sizeof( skinfilename ), "%s_%d.skin", name, skin );
245 skinfilename[sizeof( skinfilename ) - 1] = 0;
246 skinfilesize = vfsLoadFile( skinfilename, (void**) &skinfilecontent, 0 );
247 if ( skinfilesize < 0 && skin != 0 ) {
248 /* fallback to skin 0 if invalid */
249 snprintf( skinfilename, sizeof( skinfilename ), "%s_0.skin", name );
250 skinfilename[sizeof( skinfilename ) - 1] = 0;
251 skinfilesize = vfsLoadFile( skinfilename, (void**) &skinfilecontent, 0 );
252 if ( skinfilesize >= 0 ) {
253 Sys_Printf( "Skin %d of %s does not exist, using 0 instead\n", skin, name );
257 if ( skinfilesize >= 0 ) {
258 Sys_Printf( "Using skin %d of %s\n", skin, name );
260 for ( skinfileptr = skinfilecontent; *skinfileptr; skinfileptr = skinfilenextptr )
265 skinfilenextptr = strchr( skinfileptr, '\r' );
266 if ( skinfilenextptr ) {
267 *skinfilenextptr++ = 0;
271 skinfilenextptr = strchr( skinfileptr, '\n' );
272 if ( skinfilenextptr ) {
273 *skinfilenextptr++ = 0;
276 skinfilenextptr = skinfileptr + strlen( skinfileptr );
280 /* create new item */
282 sf = safe_malloc( sizeof( *sf ) );
285 sprintf( format, "replace %%%ds %%%ds", (int)sizeof( sf->name ) - 1, (int)sizeof( sf->to ) - 1 );
286 if ( sscanf( skinfileptr, format, sf->name, sf->to ) == 2 ) {
289 sprintf( format, " %%%d[^, ] ,%%%ds", (int)sizeof( sf->name ) - 1, (int)sizeof( sf->to ) - 1 );
290 if ( ( pos = sscanf( skinfileptr, format, sf->name, sf->to ) ) == 2 ) {
294 /* invalid input line -> discard sf struct */
295 Sys_Printf( "Discarding skin directive in %s: %s\n", skinfilename, skinfileptr );
299 free( skinfilecontent );
302 /* handle null matrix */
303 if ( transform == NULL ) {
304 m4x4_identity( identity );
305 transform = identity;
308 /* hack: Stable-1_2 and trunk have differing row/column major matrix order
309 this transpose is necessary with Stable-1_2
310 uncomment the following line with old m4x4_t (non 1.3/spog_branch) code */
311 //% m4x4_transpose( transform );
313 /* create transform matrix for normals */
314 memcpy( nTransform, transform, sizeof( m4x4_t ) );
315 if ( m4x4_invert( nTransform ) ) {
316 Sys_FPrintf( SYS_VRB, "WARNING: Can't invert model transform matrix, using transpose instead\n" );
318 m4x4_transpose( nTransform );
320 /* fix bogus lightmap scale */
321 if ( lightmapScale <= 0.0f ) {
322 lightmapScale = 1.0f;
325 /* fix bogus shade angle */
326 if ( shadeAngle <= 0.0f ) {
330 /* each surface on the model will become a new map drawsurface */
331 numSurfaces = PicoGetModelNumSurfaces( model );
332 //% Sys_FPrintf( SYS_VRB, "Model %s has %d surfaces\n", name, numSurfaces );
333 for ( s = 0; s < numSurfaces; s++ )
336 surface = PicoGetModelSurface( model, s );
337 if ( surface == NULL ) {
341 /* only handle triangle surfaces initially (fixme: support patches) */
342 if ( PicoGetSurfaceType( surface ) != PICO_TRIANGLES ) {
346 /* get shader name */
347 shader = PicoGetSurfaceShader( surface );
348 if ( shader == NULL ) {
352 picoShaderName = PicoGetShaderName( shader );
355 /* handle .skin file */
357 picoShaderName = NULL;
358 for ( sf2 = sf; sf2 != NULL; sf2 = sf2->next )
360 if ( !Q_stricmp( surface->name, sf2->name ) ) {
361 Sys_FPrintf( SYS_VRB, "Skin file: mapping %s to %s\n", surface->name, sf2->to );
362 picoShaderName = sf2->to;
366 if ( !picoShaderName ) {
367 Sys_FPrintf( SYS_VRB, "Skin file: not mapping %s\n", surface->name );
372 /* handle shader remapping */
374 for ( rm = remap; rm != NULL; rm = rm->next )
376 if ( rm->from[ 0 ] == '*' && rm->from[ 1 ] == '\0' ) {
379 else if ( !Q_stricmp( picoShaderName, rm->from ) ) {
380 Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", picoShaderName, rm->to );
381 picoShaderName = rm->to;
387 if ( glob != NULL ) {
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 ) {
394 strcpy( shaderName, picoShaderName );
395 StripExtension( shaderName );
396 if ( spawnFlags & 1 ) {
397 strcat( shaderName, "_RMG_BSP" );
400 strcat( shaderName, "_BSP" );
402 si = ShaderInfoForShader( shaderName );
405 si = ShaderInfoForShader( picoShaderName );
408 /* allocate a surface (ydnar: gs mods) */
409 ds = AllocDrawSurface( SURFACE_TRIANGLES );
410 ds->entityNum = eNum;
411 ds->castShadows = castShadows;
412 ds->recvShadows = recvShadows;
418 if ( ( si != NULL && si->forceMeta ) || ( spawnFlags & 4 ) ) { /* 3rd bit */
419 ds->type = SURFACE_FORCED_META;
422 /* fix the surface's normals (jal: conditioned by shader info) */
423 if ( !( spawnFlags & 64 ) && ( shadeAngle == 0.0f || ds->type != SURFACE_FORCED_META ) ) {
424 PicoFixSurfaceNormals( surface );
427 /* set sample size */
428 if ( lightmapSampleSize > 0.0f ) {
429 ds->sampleSize = lightmapSampleSize;
432 /* set lightmap scale */
433 if ( lightmapScale > 0.0f ) {
434 ds->lightmapScale = lightmapScale;
437 /* set shading angle */
438 if ( shadeAngle > 0.0f ) {
439 ds->shadeAngleDegrees = shadeAngle;
442 /* set particulars */
443 ds->numVerts = PicoGetSurfaceNumVertexes( surface );
444 ds->verts = safe_malloc0( ds->numVerts * sizeof( ds->verts[ 0 ] ) );
446 ds->numIndexes = PicoGetSurfaceNumIndexes( surface );
447 ds->indexes = safe_malloc0( ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
450 for ( i = 0; i < ds->numVerts; i++ )
453 dv = &ds->verts[ i ];
456 xyz = PicoGetSurfaceXYZ( surface, i );
457 VectorCopy( xyz, dv->xyz );
458 m4x4_transform_point( transform, dv->xyz );
460 normal = PicoGetSurfaceNormal( surface, i );
461 VectorCopy( normal, dv->normal );
462 m4x4_transform_normal( nTransform, dv->normal );
463 VectorNormalize( dv->normal, dv->normal );
465 /* ydnar: tek-fu celshading support for flat shaded shit */
467 dv->st[ 0 ] = si->stFlat[ 0 ];
468 dv->st[ 1 ] = si->stFlat[ 1 ];
471 /* ydnar: gs mods: added support for explicit shader texcoord generation */
472 else if ( si->tcGen ) {
473 /* project the texture */
474 dv->st[ 0 ] = DotProduct( si->vecs[ 0 ], dv->xyz );
475 dv->st[ 1 ] = DotProduct( si->vecs[ 1 ], dv->xyz );
478 /* normal texture coordinates */
481 st = PicoGetSurfaceST( surface, 0, i );
482 dv->st[ 0 ] = st[ 0 ];
483 dv->st[ 1 ] = st[ 1 ];
486 /* set lightmap/color bits */
487 color = PicoGetSurfaceColor( surface, 0, i );
488 for ( j = 0; j < MAX_LIGHTMAPS; j++ )
490 dv->lightmap[ j ][ 0 ] = 0.0f;
491 dv->lightmap[ j ][ 1 ] = 0.0f;
492 if ( spawnFlags & 32 ) { // spawnflag 32: model color -> alpha hack
493 dv->color[ j ][ 0 ] = 255.0f;
494 dv->color[ j ][ 1 ] = 255.0f;
495 dv->color[ j ][ 2 ] = 255.0f;
496 dv->color[ j ][ 3 ] = RGBTOGRAY( color );
500 dv->color[ j ][ 0 ] = color[ 0 ];
501 dv->color[ j ][ 1 ] = color[ 1 ];
502 dv->color[ j ][ 2 ] = color[ 2 ];
503 dv->color[ j ][ 3 ] = color[ 3 ];
509 indexes = PicoGetSurfaceIndexes( surface, 0 );
510 for ( i = 0; i < ds->numIndexes; i++ )
511 ds->indexes[ i ] = indexes[ i ];
514 ds->celShader = celShader;
516 /* ydnar: giant hack land: generate clipping brushes for model triangles */
517 if ( si->clipModel || ( spawnFlags & 2 ) ) { /* 2nd bit */
518 vec3_t points[ 4 ], backs[ 3 ];
519 vec4_t plane, reverse, pa, pb, pc;
523 if ( !si->clipModel && !( si->compileFlags & C_SOLID ) ) {
527 /* walk triangle list */
528 for ( i = 0; i < ds->numIndexes; i += 3 )
531 AUTOEXPAND_BY_REALLOC( mapplanes, ( nummapplanes + 64 ) << 1, allocatedmapplanes, 1024 );
533 /* make points and back points */
534 for ( j = 0; j < 3; j++ )
537 dv = &ds->verts[ ds->indexes[ i + j ] ];
540 VectorCopy( dv->xyz, points[ j ] );
543 VectorCopy( points[0], points[3] ); // for cyclic usage
545 /* make plane for triangle */
546 // div0: add some extra spawnflags:
547 // 0: snap normals to axial planes for extrusion
548 // 8: extrude with the original normals
549 // 16: extrude only with up/down normals (ideal for terrain)
550 // 24: extrude by distance zero (may need engine changes)
551 if ( PlaneFromPoints( plane, points[ 0 ], points[ 1 ], points[ 2 ] ) ) {
553 float backPlaneDistance = 2;
555 if ( spawnFlags & 8 ) { // use a DOWN normal
556 if ( spawnFlags & 16 ) {
557 // 24: normal as is, and zero width (broken)
558 VectorCopy( plane, bestNormal );
563 VectorCopy( plane, bestNormal );
568 if ( spawnFlags & 16 ) {
569 // 16: UP/DOWN normal
570 VectorSet( bestNormal, 0, 0, ( plane[2] >= 0 ? 1 : -1 ) );
575 if ( fabs( plane[0] ) > fabs( plane[1] ) ) { // x>y
576 if ( fabs( plane[1] ) > fabs( plane[2] ) ) { // x>y, y>z
577 VectorSet( bestNormal, ( plane[0] >= 0 ? 1 : -1 ), 0, 0 );
580 if ( fabs( plane[0] ) > fabs( plane[2] ) ) { // x>z, z>=y
581 VectorSet( bestNormal, ( plane[0] >= 0 ? 1 : -1 ), 0, 0 );
584 VectorSet( bestNormal, 0, 0, ( plane[2] >= 0 ? 1 : -1 ) );
588 if ( fabs( plane[1] ) > fabs( plane[2] ) ) { // y>z, y>=x
589 VectorSet( bestNormal, 0, ( plane[1] >= 0 ? 1 : -1 ), 0 );
592 VectorSet( bestNormal, 0, 0, ( plane[2] >= 0 ? 1 : -1 ) );
598 buildBrush = AllocBrush( 48 );
599 buildBrush->entityNum = mapEntityNum;
600 buildBrush->original = buildBrush;
601 buildBrush->contentShader = si;
602 buildBrush->compileFlags = si->compileFlags;
603 buildBrush->contentFlags = si->contentFlags;
604 normalEpsilon_save = normalEpsilon;
605 distanceEpsilon_save = distanceEpsilon;
606 if ( si->compileFlags & C_STRUCTURAL ) { // allow forced structural brushes here
607 buildBrush->detail = qfalse;
609 // only allow EXACT matches when snapping for these (this is mostly for caulk brushes inside a model)
610 if ( normalEpsilon > 0 ) {
613 if ( distanceEpsilon > 0 ) {
618 buildBrush->detail = qtrue;
621 /* regenerate back points */
622 for ( j = 0; j < 3; j++ )
625 dv = &ds->verts[ ds->indexes[ i + j ] ];
627 // shift by some units
628 VectorMA( dv->xyz, -64.0f, bestNormal, backs[j] ); // 64 prevents roundoff errors a bit
631 /* make back plane */
632 VectorScale( plane, -1.0f, reverse );
633 reverse[ 3 ] = -plane[ 3 ];
634 if ( ( spawnFlags & 24 ) != 24 ) {
635 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 ] ) ) {
642 /* set up brush sides */
643 buildBrush->numsides = 5;
644 buildBrush->sides[ 0 ].shaderInfo = si;
645 for ( j = 1; j < buildBrush->numsides; j++ )
646 buildBrush->sides[ j ].shaderInfo = NULL; // don't emit these faces as draw surfaces, should make smaller BSPs; hope this works
648 buildBrush->sides[ 0 ].planenum = FindFloatPlane( plane, plane[ 3 ], 3, points );
649 buildBrush->sides[ 1 ].planenum = FindFloatPlane( pa, pa[ 3 ], 2, &points[ 1 ] ); // pa contains points[1] and points[2]
650 buildBrush->sides[ 2 ].planenum = FindFloatPlane( pb, pb[ 3 ], 2, &points[ 0 ] ); // pb contains points[0] and points[1]
651 buildBrush->sides[ 3 ].planenum = FindFloatPlane( pc, pc[ 3 ], 2, &points[ 2 ] ); // pc contains points[2] and points[0] (copied to points[3]
652 buildBrush->sides[ 4 ].planenum = FindFloatPlane( reverse, reverse[ 3 ], 3, backs );
660 normalEpsilon = normalEpsilon_save;
661 distanceEpsilon = distanceEpsilon_save;
664 if ( CreateBrushWindings( buildBrush ) ) {
666 //% EmitBrushes( buildBrush, NULL, NULL );
667 buildBrush->next = entities[ mapEntityNum ].brushes;
668 entities[ mapEntityNum ].brushes = buildBrush;
669 entities[ mapEntityNum ].numBrushes++;
684 adds misc_model surfaces to the bsp
687 void AddTriangleModels( entity_t *e ){
688 int num, frame, skin, castShadows, recvShadows, spawnFlags;
690 const char *targetName;
691 const char *target, *model, *value;
692 char shader[ MAX_QPATH ];
693 shaderInfo_t *celShader;
694 float temp, baseLightmapScale, lightmapScale;
696 int lightmapSampleSize;
697 vec3_t origin, scale, angles;
700 remap_t *remap, *remap2;
705 Sys_FPrintf( SYS_VRB, "--- AddTriangleModels ---\n" );
707 /* get current brush entity targetname */
708 if ( e == entities ) {
713 targetName = ValueForKey( e, "targetname" );
715 /* misc_model entities target non-worldspawn brush model entities */
716 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" ) ) ) {
727 baseLightmapScale = FloatForKey( e, "lightmapscale" );
728 if ( baseLightmapScale <= 0.0f ) {
729 baseLightmapScale = FloatForKey( e, "_lightmapscale" );
731 if ( baseLightmapScale <= 0.0f ) {
732 baseLightmapScale = FloatForKey( e, "_ls" );
734 if ( baseLightmapScale < 0.0f ) {
735 baseLightmapScale = 0.0f;
737 if ( baseLightmapScale > 0.0f ) {
738 Sys_Printf( "World Entity has lightmap scale of %.4f\n", baseLightmapScale );
742 /* walk the entity list */
743 for ( num = 1; num < numEntities; num++ )
746 e2 = &entities[ num ];
748 /* convert misc_models into raw geometry */
749 if ( Q_stricmp( "misc_model", ValueForKey( e2, "classname" ) ) ) {
753 /* ydnar: added support for md3 models on non-worldspawn models */
754 target = ValueForKey( e2, "target" );
755 if ( strcmp( target, targetName ) ) {
760 model = ValueForKey( e2, "model" );
761 if ( model[ 0 ] == '\0' ) {
762 Sys_FPrintf( SYS_WRN, "WARNING: misc_model at %i %i %i without a model key\n",
763 (int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] );
767 /* get model frame */
769 if ( strcmp( "", ValueForKey( e2, "_frame" ) ) ) {
770 frame = IntForKey( e2, "_frame" );
772 else if ( strcmp( "", ValueForKey( e2, "frame" ) ) ) {
773 frame = IntForKey( e2, "frame" );
776 /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */
777 if ( e == entities ) {
778 castShadows = WORLDSPAWN_CAST_SHADOWS;
779 recvShadows = WORLDSPAWN_RECV_SHADOWS;
782 /* other entities don't cast any shadows, but recv worldspawn shadows */
785 castShadows = ENTITY_CAST_SHADOWS;
786 recvShadows = ENTITY_RECV_SHADOWS;
789 /* get explicit shadow flags */
790 GetEntityShadowFlags( e2, e, &castShadows, &recvShadows );
793 spawnFlags = IntForKey( e2, "spawnflags" );
796 GetVectorForKey( e2, "origin", origin );
797 VectorSubtract( origin, e->origin, origin ); /* offset by parent */
800 scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = 1.0f;
801 temp = FloatForKey( e2, "modelscale" );
802 if ( temp != 0.0f ) {
803 scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = temp;
805 value = ValueForKey( e2, "modelscale_vec" );
806 if ( value[ 0 ] != '\0' ) {
807 sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] );
810 /* get "angle" (yaw) or "angles" (pitch yaw roll) */
811 angles[ 0 ] = angles[ 1 ] = angles[ 2 ] = 0.0f;
812 angles[ 2 ] = FloatForKey( e2, "angle" );
813 value = ValueForKey( e2, "angles" );
814 if ( value[ 0 ] != '\0' ) {
815 sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] );
818 /* set transform matrix (thanks spog) */
819 m4x4_identity( transform );
820 m4x4_pivoted_transform_by_vec3( transform, origin, angles, eXYZ, scale, vec3_origin );
822 /* get shader remappings */
824 for ( ep = e2->epairs; ep != NULL; ep = ep->next )
826 /* look for keys prefixed with "_remap" */
827 if ( ep->key != NULL && ep->value != NULL &&
828 ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' &&
829 !Q_strncasecmp( ep->key, "_remap", 6 ) ) {
830 /* create new remapping */
832 remap = safe_malloc( sizeof( *remap ) );
833 remap->next = remap2;
834 strcpy( remap->from, ep->value );
836 /* split the string */
837 split = strchr( remap->from, ';' );
838 if ( split == NULL ) {
839 Sys_FPrintf( SYS_WRN, "WARNING: Shader _remap key found in misc_model without a ; character\n" );
845 /* store the split */
847 strcpy( remap->to, ( split + 1 ) );
850 //% Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", remap->from, remap->to );
854 /* ydnar: cel shader support */
855 value = ValueForKey( e2, "_celshader" );
856 if ( value[ 0 ] == '\0' ) {
857 value = ValueForKey( &entities[ 0 ], "_celshader" );
859 if ( value[ 0 ] != '\0' ) {
860 sprintf( shader, "textures/%s", value );
861 celShader = ShaderInfoForShader( shader );
864 celShader = *globalCelShader ? ShaderInfoForShader( globalCelShader ) : NULL;
867 /* jal : entity based _samplesize */
868 lightmapSampleSize = 0;
869 if ( strcmp( "", ValueForKey( e2, "_lightmapsamplesize" ) ) ) {
870 lightmapSampleSize = IntForKey( e2, "_lightmapsamplesize" );
872 else if ( strcmp( "", ValueForKey( e2, "_samplesize" ) ) ) {
873 lightmapSampleSize = IntForKey( e2, "_samplesize" );
876 if ( lightmapSampleSize < 0 ) {
877 lightmapSampleSize = 0;
880 if ( lightmapSampleSize > 0.0f ) {
881 Sys_Printf( "misc_model has lightmap sample size of %.d\n", lightmapSampleSize );
884 /* get lightmap scale */
885 /* vortex: added _ls key (short name of lightmapscale) */
886 lightmapScale = 0.0f;
887 if ( strcmp( "", ValueForKey( e2, "lightmapscale" ) ) ||
888 strcmp( "", ValueForKey( e2, "_lightmapscale" ) ) ||
889 strcmp( "", ValueForKey( e2, "_ls" ) ) ) {
890 lightmapScale = FloatForKey( e2, "lightmapscale" );
891 if ( lightmapScale <= 0.0f ) {
892 lightmapScale = FloatForKey( e2, "_lightmapscale" );
894 if ( lightmapScale <= 0.0f ) {
895 lightmapScale = FloatForKey( e2, "_ls" );
897 if ( lightmapScale < 0.0f ) {
898 lightmapScale = 0.0f;
900 if ( lightmapScale > 0.0f ) {
901 Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale );
905 /* jal : entity based _shadeangle */
907 if ( strcmp( "", ValueForKey( e2, "_shadeangle" ) ) ) {
908 shadeAngle = FloatForKey( e2, "_shadeangle" );
910 /* vortex' aliases */
911 else if ( strcmp( "", ValueForKey( e2, "_smoothnormals" ) ) ) {
912 shadeAngle = FloatForKey( e2, "_smoothnormals" );
914 else if ( strcmp( "", ValueForKey( e2, "_sn" ) ) ) {
915 shadeAngle = FloatForKey( e2, "_sn" );
917 else if ( strcmp( "", ValueForKey( e2, "_smooth" ) ) ) {
918 shadeAngle = FloatForKey( e2, "_smooth" );
921 if ( shadeAngle < 0.0f ) {
925 if ( shadeAngle > 0.0f ) {
926 Sys_Printf( "misc_model has shading angle of %.4f\n", shadeAngle );
930 if ( strcmp( "", ValueForKey( e2, "_skin" ) ) ) {
931 skin = IntForKey( e2, "_skin" );
933 else if ( strcmp( "", ValueForKey( e2, "skin" ) ) ) {
934 skin = IntForKey( e2, "skin" );
937 /* insert the model */
938 InsertModel( model, skin, frame, transform, remap, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale, lightmapSampleSize, shadeAngle );
940 /* free shader remappings */
941 while ( remap != NULL )
943 remap2 = remap->next;