| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#define MAP_C |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
#include "q3map2.h" |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#define USE_HASHING |
| 45 |
#define PLANE_HASHES 8192 |
| 46 |
|
| 47 |
int planehash[ PLANE_HASHES ]; |
| 48 |
|
| 49 |
int c_boxbevels; |
| 50 |
int c_edgebevels; |
| 51 |
int c_areaportals; |
| 52 |
int c_detail; |
| 53 |
int c_structural; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
qboolean PlaneEqual( plane_t *p, vec3_t normal, vec_t dist ){ |
| 63 |
float ne, de; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
ne = normalEpsilon; |
| 68 |
de = distanceEpsilon; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
if ( ( p->dist == dist || fabs( p->dist - dist ) < de ) && |
| 76 |
( p->normal[0] == normal[0] || fabs( p->normal[0] - normal[0] ) < ne ) && |
| 77 |
( p->normal[1] == normal[1] || fabs( p->normal[1] - normal[1] ) < ne ) && |
| 78 |
( p->normal[2] == normal[2] || fabs( p->normal[2] - normal[2] ) < ne ) ) { |
| 79 |
return qtrue; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
return qfalse; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
void AddPlaneToHash( plane_t *p ){ |
| 93 |
int hash; |
| 94 |
|
| 95 |
|
| 96 |
hash = ( PLANE_HASHES - 1 ) & (int) fabs( p->dist ); |
| 97 |
|
| 98 |
p->hash_chain = planehash[hash]; |
| 99 |
planehash[hash] = p - mapplanes + 1; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
int CreateNewFloatPlane( vec3_t normal, vec_t dist ){ |
| 108 |
plane_t *p, temp; |
| 109 |
|
| 110 |
if ( VectorLength( normal ) < 0.5 ) { |
| 111 |
Sys_Printf( "FloatPlane: bad normal\n" ); |
| 112 |
return -1; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
AUTOEXPAND_BY_REALLOC( mapplanes, nummapplanes + 1, allocatedmapplanes, 1024 ); |
| 117 |
|
| 118 |
p = &mapplanes[nummapplanes]; |
| 119 |
VectorCopy( normal, p->normal ); |
| 120 |
p->dist = dist; |
| 121 |
p->type = ( p + 1 )->type = PlaneTypeForNormal( p->normal ); |
| 122 |
|
| 123 |
VectorSubtract( vec3_origin, normal, ( p + 1 )->normal ); |
| 124 |
( p + 1 )->dist = -dist; |
| 125 |
|
| 126 |
nummapplanes += 2; |
| 127 |
|
| 128 |
|
| 129 |
if ( p->type < 3 ) { |
| 130 |
if ( p->normal[0] < 0 || p->normal[1] < 0 || p->normal[2] < 0 ) { |
| 131 |
|
| 132 |
temp = *p; |
| 133 |
*p = *( p + 1 ); |
| 134 |
*( p + 1 ) = temp; |
| 135 |
|
| 136 |
AddPlaneToHash( p ); |
| 137 |
AddPlaneToHash( p + 1 ); |
| 138 |
return nummapplanes - 1; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
AddPlaneToHash( p ); |
| 143 |
AddPlaneToHash( p + 1 ); |
| 144 |
return nummapplanes - 2; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
qboolean SnapNormal( vec3_t normal ){ |
| 156 |
#if Q3MAP2_EXPERIMENTAL_SNAP_NORMAL_FIX |
| 157 |
int i; |
| 158 |
qboolean adjusted = qfalse; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
if ( ( normal[0] != 0.0 || normal[1] != 0.0 ) && fabs(normal[0]) < 0.00025 && fabs(normal[1]) < 0.00025){ |
| 172 |
normal[0] = normal[1] = 0.0; |
| 173 |
adjusted = qtrue; |
| 174 |
} |
| 175 |
else if ( ( normal[0] != 0.0 || normal[2] != 0.0 ) && fabs(normal[0]) < 0.00025 && fabs(normal[2]) < 0.00025){ |
| 176 |
normal[0] = normal[2] = 0.0; |
| 177 |
adjusted = qtrue; |
| 178 |
} |
| 179 |
else if ( ( normal[2] != 0.0 || normal[1] != 0.0 ) && fabs(normal[2]) < 0.00025 && fabs(normal[1]) < 0.00025){ |
| 180 |
normal[2] = normal[1] = 0.0; |
| 181 |
adjusted = qtrue; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
for ( i = 0; i < 3; i++ ) |
| 206 |
{ |
| 207 |
if ( normal[i] != 0.0 && -normalEpsilon < normal[i] && normal[i] < normalEpsilon ) { |
| 208 |
normal[i] = 0.0; |
| 209 |
adjusted = qtrue; |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
if ( adjusted ) { |
| 214 |
VectorNormalize( normal, normal ); |
| 215 |
return qtrue; |
| 216 |
} |
| 217 |
return qfalse; |
| 218 |
#else |
| 219 |
int i; |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
for ( i = 0; i < 3; i++ ) |
| 255 |
{ |
| 256 |
if ( fabs( normal[ i ] - 1 ) < normalEpsilon ) { |
| 257 |
VectorClear( normal ); |
| 258 |
normal[ i ] = 1; |
| 259 |
return qtrue; |
| 260 |
} |
| 261 |
if ( fabs( normal[ i ] - -1 ) < normalEpsilon ) { |
| 262 |
VectorClear( normal ); |
| 263 |
normal[ i ] = -1; |
| 264 |
return qtrue; |
| 265 |
} |
| 266 |
} |
| 267 |
return qfalse; |
| 268 |
#endif |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
void SnapPlane( vec3_t normal, vec_t *dist ){ |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
SnapNormal( normal ); |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
if ( fabs( *dist - Q_rint( *dist ) ) < distanceEpsilon ) { |
| 310 |
*dist = Q_rint( *dist ); |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
void SnapPlaneImproved( vec3_t normal, vec_t *dist, int numPoints, const vec3_t *points ){ |
| 319 |
int i; |
| 320 |
vec3_t center; |
| 321 |
vec_t distNearestInt; |
| 322 |
|
| 323 |
if ( SnapNormal( normal ) ) { |
| 324 |
if ( numPoints > 0 ) { |
| 325 |
|
| 326 |
VectorClear( center ); |
| 327 |
for ( i = 0; i < numPoints; i++ ) |
| 328 |
{ |
| 329 |
VectorAdd( center, points[i], center ); |
| 330 |
} |
| 331 |
for ( i = 0; i < 3; i++ ) { center[i] = center[i] / numPoints; } |
| 332 |
*dist = DotProduct( normal, center ); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
if ( VectorIsOnAxis( normal ) ) { |
| 337 |
|
| 338 |
|
| 339 |
distNearestInt = Q_rint( *dist ); |
| 340 |
if ( -distanceEpsilon < *dist - distNearestInt && *dist - distNearestInt < distanceEpsilon ) { |
| 341 |
*dist = distNearestInt; |
| 342 |
} |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
int FindFloatPlane( vec3_t innormal, vec_t dist, int numPoints, vec3_t *points ) |
| 355 |
|
| 356 |
#ifdef USE_HASHING |
| 357 |
|
| 358 |
{ |
| 359 |
int i, j, hash, h; |
| 360 |
int pidx; |
| 361 |
plane_t *p; |
| 362 |
vec_t d; |
| 363 |
vec3_t normal; |
| 364 |
|
| 365 |
VectorCopy( innormal, normal ); |
| 366 |
#if Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX |
| 367 |
SnapPlaneImproved( normal, &dist, numPoints, (const vec3_t *) points ); |
| 368 |
#else |
| 369 |
SnapPlane( normal, &dist ); |
| 370 |
#endif |
| 371 |
|
| 372 |
hash = ( PLANE_HASHES - 1 ) & (int) fabs( dist ); |
| 373 |
|
| 374 |
|
| 375 |
for ( i = -1; i <= 1; i++ ) |
| 376 |
{ |
| 377 |
h = ( hash + i ) & ( PLANE_HASHES - 1 ); |
| 378 |
for ( pidx = planehash[ h ] - 1; pidx != -1; pidx = mapplanes[pidx].hash_chain - 1 ) |
| 379 |
{ |
| 380 |
p = &mapplanes[pidx]; |
| 381 |
|
| 382 |
|
| 383 |
if ( !PlaneEqual( p, normal, dist ) ) { |
| 384 |
continue; |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
for ( j = 0; j < numPoints; j++ ) |
| 392 |
{ |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
d = DotProduct( points[ j ], p->normal ) - p->dist; |
| 399 |
d = fabs( d ); |
| 400 |
if ( d != 0.0 && d >= distanceEpsilon ) { |
| 401 |
break; |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
if ( j >= numPoints ) { |
| 407 |
return p - mapplanes; |
| 408 |
} |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
return CreateNewFloatPlane( normal, dist ); |
| 414 |
} |
| 415 |
|
| 416 |
#else |
| 417 |
|
| 418 |
{ |
| 419 |
int i; |
| 420 |
plane_t *p; |
| 421 |
vec3_t normal; |
| 422 |
|
| 423 |
VectorCopy( innormal, normal ); |
| 424 |
#if Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX |
| 425 |
SnapPlaneImproved( normal, &dist, numPoints, (const vec3_t *) points ); |
| 426 |
#else |
| 427 |
SnapPlane( normal, &dist ); |
| 428 |
#endif |
| 429 |
for ( i = 0, p = mapplanes; i < nummapplanes; i++, p++ ) |
| 430 |
{ |
| 431 |
if ( !PlaneEqual( p, normal, dist ) ) { |
| 432 |
continue; |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
for ( j = 0; j < numPoints; j++ ) |
| 440 |
{ |
| 441 |
d = DotProduct( points[ j ], p->normal ) - p->dist; |
| 442 |
if ( fabs( d ) > distanceEpsilon ) { |
| 443 |
break; |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
if ( j >= numPoints ) { |
| 449 |
return i; |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
} |
| 455 |
|
| 456 |
return CreateNewFloatPlane( normal, dist ); |
| 457 |
} |
| 458 |
|
| 459 |
#endif |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
int MapPlaneFromPoints( vec3_t *p ){ |
| 469 |
#if Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES |
| 470 |
vec3_accu_t paccu[3]; |
| 471 |
vec3_accu_t t1, t2, normalAccu; |
| 472 |
vec3_t normal; |
| 473 |
vec_t dist; |
| 474 |
|
| 475 |
VectorCopyRegularToAccu( p[0], paccu[0] ); |
| 476 |
VectorCopyRegularToAccu( p[1], paccu[1] ); |
| 477 |
VectorCopyRegularToAccu( p[2], paccu[2] ); |
| 478 |
|
| 479 |
VectorSubtractAccu( paccu[0], paccu[1], t1 ); |
| 480 |
VectorSubtractAccu( paccu[2], paccu[1], t2 ); |
| 481 |
CrossProductAccu( t1, t2, normalAccu ); |
| 482 |
VectorNormalizeAccu( normalAccu, normalAccu ); |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
dist = (vec_t) DotProductAccu( paccu[0], normalAccu ); |
| 487 |
VectorCopyAccuToRegular( normalAccu, normal ); |
| 488 |
|
| 489 |
return FindFloatPlane( normal, dist, 3, p ); |
| 490 |
#else |
| 491 |
vec3_t t1, t2, normal; |
| 492 |
vec_t dist; |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
VectorSubtract( p[ 0 ], p[ 1 ], t1 ); |
| 497 |
VectorSubtract( p[ 2 ], p[ 1 ], t2 ); |
| 498 |
CrossProduct( t1, t2, normal ); |
| 499 |
VectorNormalize( normal, normal ); |
| 500 |
|
| 501 |
|
| 502 |
dist = DotProduct( p[ 0 ], normal ); |
| 503 |
|
| 504 |
|
| 505 |
return FindFloatPlane( normal, dist, 3, p ); |
| 506 |
#endif |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
void SetBrushContents( brush_t *b ){ |
| 517 |
int contentFlags, compileFlags; |
| 518 |
side_t *s; |
| 519 |
int i; |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
s = &b->sides[ 0 ]; |
| 525 |
contentFlags = s->contentFlags; |
| 526 |
compileFlags = s->compileFlags; |
| 527 |
b->contentShader = s->shaderInfo; |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
for ( i = 1; i < b->numsides; i++ ) |
| 533 |
{ |
| 534 |
s = &b->sides[ i ]; |
| 535 |
if ( s->shaderInfo == NULL ) { |
| 536 |
continue; |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
contentFlags |= s->contentFlags; |
| 542 |
compileFlags |= s->compileFlags; |
| 543 |
|
| 544 |
|
| 545 |
if ( b->contentShader->compileFlags & C_LIQUID ){ |
| 546 |
continue; |
| 547 |
} |
| 548 |
else if ( s->compileFlags & C_LIQUID ){ |
| 549 |
b->contentShader = s->shaderInfo; |
| 550 |
} |
| 551 |
else if ( b->contentShader->compileFlags & C_FOG ){ |
| 552 |
continue; |
| 553 |
} |
| 554 |
else if ( s->compileFlags & C_FOG ){ |
| 555 |
b->contentShader = s->shaderInfo; |
| 556 |
} |
| 557 |
|
| 558 |
else if ( b->contentShader->contentFlags & 0x10000 ){ |
| 559 |
continue; |
| 560 |
} |
| 561 |
else if ( s->contentFlags & 0x10000 ){ |
| 562 |
b->contentShader = s->shaderInfo; |
| 563 |
} |
| 564 |
else if (!( b->contentShader->compileFlags & C_SOLID )){ |
| 565 |
continue; |
| 566 |
} |
| 567 |
else if (!( s->compileFlags & C_SOLID )){ |
| 568 |
b->contentShader = s->shaderInfo; |
| 569 |
} |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
if ( ( compileFlags & C_DETAIL ) && ( compileFlags & C_STRUCTURAL ) ) { |
| 578 |
xml_Select( "Mixed detail and structural (defaulting to structural)", mapEnt->mapEntityNum, entitySourceBrushes, qfalse ); |
| 579 |
compileFlags &= ~C_DETAIL; |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
if ( fulldetail ) { |
| 584 |
compileFlags &= ~C_DETAIL; |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
if ( ( compileFlags & C_TRANSLUCENT ) && !( compileFlags & C_STRUCTURAL ) ) { |
| 589 |
compileFlags |= C_DETAIL; |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
if ( compileFlags & C_DETAIL ) { |
| 594 |
c_detail++; |
| 595 |
b->detail = qtrue; |
| 596 |
} |
| 597 |
else |
| 598 |
{ |
| 599 |
c_structural++; |
| 600 |
b->detail = qfalse; |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
if ( compileFlags & C_TRANSLUCENT ) { |
| 605 |
b->opaque = qfalse; |
| 606 |
} |
| 607 |
else{ |
| 608 |
b->opaque = qtrue; |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
if ( compileFlags & C_AREAPORTAL ) { |
| 613 |
c_areaportals++; |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
b->contentFlags = contentFlags; |
| 618 |
b->compileFlags = compileFlags; |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
void AddBrushBevels( void ){ |
| 631 |
int axis, dir; |
| 632 |
int i, j, k, l, order; |
| 633 |
side_t sidetemp; |
| 634 |
side_t *s, *s2; |
| 635 |
winding_t *w, *w2; |
| 636 |
vec3_t normal; |
| 637 |
float dist; |
| 638 |
vec3_t vec, vec2; |
| 639 |
float d, minBack; |
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
order = 0; |
| 645 |
for ( axis = 0; axis < 3; axis++ ) { |
| 646 |
for ( dir = -1; dir <= 1; dir += 2, order++ ) { |
| 647 |
|
| 648 |
for ( i = 0, s = buildBrush->sides; i < buildBrush->numsides; i++, s++ ) |
| 649 |
{ |
| 650 |
|
| 651 |
#if 0 |
| 652 |
if ( dir > 0 ) { |
| 653 |
if ( mapplanes[s->planenum].normal[axis] >= 0.9999f ) { |
| 654 |
break; |
| 655 |
} |
| 656 |
} |
| 657 |
else { |
| 658 |
if ( mapplanes[s->planenum].normal[axis] <= -0.9999f ) { |
| 659 |
break; |
| 660 |
} |
| 661 |
} |
| 662 |
#else |
| 663 |
if ( ( dir > 0 && mapplanes[ s->planenum ].normal[ axis ] == 1.0f ) || |
| 664 |
( dir < 0 && mapplanes[ s->planenum ].normal[ axis ] == -1.0f ) ) { |
| 665 |
break; |
| 666 |
} |
| 667 |
#endif |
| 668 |
} |
| 669 |
|
| 670 |
if ( i == buildBrush->numsides ) { |
| 671 |
|
| 672 |
if ( buildBrush->numsides == MAX_BUILD_SIDES ) { |
| 673 |
xml_Select( "MAX_BUILD_SIDES", buildBrush->entityNum, buildBrush->brushNum, qtrue ); |
| 674 |
} |
| 675 |
memset( s, 0, sizeof( *s ) ); |
| 676 |
buildBrush->numsides++; |
| 677 |
VectorClear( normal ); |
| 678 |
normal[axis] = dir; |
| 679 |
|
| 680 |
if ( dir == 1 ) { |
| 681 |
|
| 682 |
if ( bevelSnap > 0 ) { |
| 683 |
dist = floor( buildBrush->maxs[ axis ] / bevelSnap ) * bevelSnap; |
| 684 |
} |
| 685 |
else{ |
| 686 |
dist = buildBrush->maxs[ axis ]; |
| 687 |
} |
| 688 |
} |
| 689 |
else |
| 690 |
{ |
| 691 |
|
| 692 |
if ( bevelSnap > 0 ) { |
| 693 |
dist = -ceil( buildBrush->mins[ axis ] / bevelSnap ) * bevelSnap; |
| 694 |
} |
| 695 |
else{ |
| 696 |
dist = -buildBrush->mins[ axis ]; |
| 697 |
} |
| 698 |
} |
| 699 |
|
| 700 |
s->planenum = FindFloatPlane( normal, dist, 0, NULL ); |
| 701 |
s->contentFlags = buildBrush->sides[ 0 ].contentFlags; |
| 702 |
s->bevel = qtrue; |
| 703 |
c_boxbevels++; |
| 704 |
} |
| 705 |
|
| 706 |
|
| 707 |
if ( i != order ) { |
| 708 |
sidetemp = buildBrush->sides[order]; |
| 709 |
buildBrush->sides[order] = buildBrush->sides[i]; |
| 710 |
buildBrush->sides[i] = sidetemp; |
| 711 |
} |
| 712 |
} |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
if ( buildBrush->numsides == 6 ) { |
| 719 |
return; |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
for ( i = 6; i < buildBrush->numsides; i++ ) { |
| 724 |
s = buildBrush->sides + i; |
| 725 |
w = s->winding; |
| 726 |
if ( !w ) { |
| 727 |
continue; |
| 728 |
} |
| 729 |
for ( j = 0; j < w->numpoints; j++ ) { |
| 730 |
k = ( j + 1 ) % w->numpoints; |
| 731 |
VectorSubtract( w->p[j], w->p[k], vec ); |
| 732 |
if ( VectorNormalize( vec, vec ) < 0.5f ) { |
| 733 |
continue; |
| 734 |
} |
| 735 |
SnapNormal( vec ); |
| 736 |
for ( k = 0; k < 3; k++ ) { |
| 737 |
if ( vec[k] == -1.0f || vec[k] == 1.0f || ( vec[k] == 0.0f && vec[( k + 1 ) % 3] == 0.0f ) ) { |
| 738 |
break; |
| 739 |
} |
| 740 |
} |
| 741 |
if ( k != 3 ) { |
| 742 |
continue; |
| 743 |
} |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
for ( axis = 0; axis < 3; axis++ ) { |
| 750 |
for ( dir = -1; dir <= 1; dir += 2 ) { |
| 751 |
|
| 752 |
VectorClear( vec2 ); |
| 753 |
vec2[axis] = dir; |
| 754 |
CrossProduct( vec, vec2, normal ); |
| 755 |
if ( VectorNormalize( normal, normal ) < 0.5f ) { |
| 756 |
continue; |
| 757 |
} |
| 758 |
dist = DotProduct( w->p[j], normal ); |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
for ( k = 0; k < buildBrush->numsides; k++ ) { |
| 763 |
|
| 764 |
|
| 765 |
if ( PlaneEqual( &mapplanes[buildBrush->sides[k].planenum], normal, dist ) ) { |
| 766 |
break; |
| 767 |
} |
| 768 |
|
| 769 |
w2 = buildBrush->sides[k].winding; |
| 770 |
if ( !w2 ) { |
| 771 |
continue; |
| 772 |
} |
| 773 |
minBack = 0.0f; |
| 774 |
for ( l = 0; l < w2->numpoints; l++ ) { |
| 775 |
d = DotProduct( w2->p[l], normal ) - dist; |
| 776 |
if ( d > 0.1f ) { |
| 777 |
break; |
| 778 |
} |
| 779 |
if ( d < minBack ) { |
| 780 |
minBack = d; |
| 781 |
} |
| 782 |
} |
| 783 |
|
| 784 |
if ( l != w2->numpoints ) { |
| 785 |
break; |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
if ( minBack > -0.1f ) { |
| 790 |
|
| 791 |
break; |
| 792 |
} |
| 793 |
} |
| 794 |
|
| 795 |
if ( k != buildBrush->numsides ) { |
| 796 |
continue; |
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
if ( buildBrush->numsides == MAX_BUILD_SIDES ) { |
| 804 |
xml_Select( "MAX_BUILD_SIDES", buildBrush->entityNum, buildBrush->brushNum, qtrue ); |
| 805 |
} |
| 806 |
s2 = &buildBrush->sides[buildBrush->numsides]; |
| 807 |
buildBrush->numsides++; |
| 808 |
memset( s2, 0, sizeof( *s2 ) ); |
| 809 |
|
| 810 |
s2->planenum = FindFloatPlane( normal, dist, 1, &w->p[ j ] ); |
| 811 |
s2->contentFlags = buildBrush->sides[0].contentFlags; |
| 812 |
s2->bevel = qtrue; |
| 813 |
c_edgebevels++; |
| 814 |
} |
| 815 |
} |
| 816 |
} |
| 817 |
} |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
static void MergeOrigin( entity_t *ent, vec3_t origin ){ |
| 829 |
vec3_t adjustment; |
| 830 |
char string[128]; |
| 831 |
|
| 832 |
|
| 833 |
GetVectorForKey( ent, "origin", ent->origin ); |
| 834 |
|
| 835 |
VectorMA( origin, -1, ent->originbrush_origin, adjustment ); |
| 836 |
VectorAdd( adjustment, ent->origin, ent->origin ); |
| 837 |
VectorCopy( origin, ent->originbrush_origin ); |
| 838 |
|
| 839 |
sprintf( string, "%f %f %f", ent->origin[0], ent->origin[1], ent->origin[2] ); |
| 840 |
SetKeyValue( ent, "origin", string ); |
| 841 |
} |
| 842 |
|
| 843 |
brush_t *FinishBrush( qboolean noCollapseGroups ){ |
| 844 |
brush_t *b; |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
if ( !CreateBrushWindings( buildBrush ) ) { |
| 849 |
return NULL; |
| 850 |
} |
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
if ( buildBrush->compileFlags & C_ORIGIN ) { |
| 855 |
vec3_t origin; |
| 856 |
|
| 857 |
Sys_Printf( "Entity %i, Brush %i: origin brush detected\n", |
| 858 |
mapEnt->mapEntityNum, entitySourceBrushes ); |
| 859 |
|
| 860 |
if ( numEntities == 1 ) { |
| 861 |
Sys_Printf( "Entity %i, Brush %i: origin brushes not allowed in world\n", |
| 862 |
mapEnt->mapEntityNum, entitySourceBrushes ); |
| 863 |
return NULL; |
| 864 |
} |
| 865 |
|
| 866 |
VectorAdd( buildBrush->mins, buildBrush->maxs, origin ); |
| 867 |
VectorScale( origin, 0.5, origin ); |
| 868 |
|
| 869 |
MergeOrigin( &entities[ numEntities - 1 ], origin ); |
| 870 |
|
| 871 |
|
| 872 |
return NULL; |
| 873 |
} |
| 874 |
|
| 875 |
|
| 876 |
if ( buildBrush->compileFlags & C_AREAPORTAL ) { |
| 877 |
if ( numEntities != 1 ) { |
| 878 |
Sys_Printf( "Entity %i, Brush %i: areaportals only allowed in world\n", numEntities - 1, entitySourceBrushes ); |
| 879 |
return NULL; |
| 880 |
} |
| 881 |
} |
| 882 |
|
| 883 |
|
| 884 |
if ( !noCollapseGroups ) { |
| 885 |
AddBrushBevels(); |
| 886 |
} |
| 887 |
|
| 888 |
|
| 889 |
b = CopyBrush( buildBrush ); |
| 890 |
|
| 891 |
|
| 892 |
b->entityNum = mapEnt->mapEntityNum; |
| 893 |
b->brushNum = entitySourceBrushes; |
| 894 |
|
| 895 |
|
| 896 |
b->original = b; |
| 897 |
|
| 898 |
|
| 899 |
if ( b->opaque || mapEnt->lastBrush == NULL ) { |
| 900 |
b->next = mapEnt->brushes; |
| 901 |
mapEnt->brushes = b; |
| 902 |
if ( mapEnt->lastBrush == NULL ) { |
| 903 |
mapEnt->lastBrush = b; |
| 904 |
} |
| 905 |
} |
| 906 |
else |
| 907 |
{ |
| 908 |
b->next = NULL; |
| 909 |
mapEnt->lastBrush->next = b; |
| 910 |
mapEnt->lastBrush = b; |
| 911 |
} |
| 912 |
|
| 913 |
|
| 914 |
if ( b->contentShader != NULL && |
| 915 |
b->contentShader->colorMod != NULL && |
| 916 |
b->contentShader->colorMod->type == CM_VOLUME ) { |
| 917 |
b->nextColorModBrush = mapEnt->colorModBrushes; |
| 918 |
mapEnt->colorModBrushes = b; |
| 919 |
} |
| 920 |
|
| 921 |
|
| 922 |
return b; |
| 923 |
} |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
vec3_t baseaxis[18] = |
| 934 |
{ |
| 935 |
{0,0,1}, {1,0,0}, {0,-1,0}, |
| 936 |
{0,0,-1}, {1,0,0}, {0,-1,0}, |
| 937 |
{1,0,0}, {0,1,0}, {0,0,-1}, |
| 938 |
{-1,0,0}, {0,1,0}, {0,0,-1}, |
| 939 |
{0,1,0}, {1,0,0}, {0,0,-1}, |
| 940 |
{0,-1,0}, {1,0,0}, {0,0,-1} |
| 941 |
}; |
| 942 |
|
| 943 |
void TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv ){ |
| 944 |
int bestaxis; |
| 945 |
vec_t dot,best; |
| 946 |
int i; |
| 947 |
|
| 948 |
best = 0; |
| 949 |
bestaxis = 0; |
| 950 |
|
| 951 |
for ( i = 0 ; i < 6 ; i++ ) |
| 952 |
{ |
| 953 |
dot = DotProduct( pln->normal, baseaxis[i * 3] ); |
| 954 |
if ( dot > best + 0.0001f ) { |
| 955 |
best = dot; |
| 956 |
bestaxis = i; |
| 957 |
} |
| 958 |
} |
| 959 |
|
| 960 |
VectorCopy( baseaxis[bestaxis * 3 + 1], xv ); |
| 961 |
VectorCopy( baseaxis[bestaxis * 3 + 2], yv ); |
| 962 |
} |
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
void QuakeTextureVecs( plane_t *plane, vec_t shift[ 2 ], vec_t rotate, vec_t scale[ 2 ], vec_t mappingVecs[ 2 ][ 4 ] ){ |
| 972 |
vec3_t vecs[2]; |
| 973 |
int sv, tv; |
| 974 |
vec_t ang, sinv, cosv; |
| 975 |
vec_t ns, nt; |
| 976 |
int i, j; |
| 977 |
|
| 978 |
|
| 979 |
TextureAxisFromPlane( plane, vecs[0], vecs[1] ); |
| 980 |
|
| 981 |
if ( !scale[0] ) { |
| 982 |
scale[0] = 1; |
| 983 |
} |
| 984 |
if ( !scale[1] ) { |
| 985 |
scale[1] = 1; |
| 986 |
} |
| 987 |
|
| 988 |
|
| 989 |
if ( rotate == 0 ) { |
| 990 |
sinv = 0 ; cosv = 1; |
| 991 |
} |
| 992 |
else if ( rotate == 90 ) { |
| 993 |
sinv = 1 ; cosv = 0; |
| 994 |
} |
| 995 |
else if ( rotate == 180 ) { |
| 996 |
sinv = 0 ; cosv = -1; |
| 997 |
} |
| 998 |
else if ( rotate == 270 ) { |
| 999 |
sinv = -1 ; cosv = 0; |
| 1000 |
} |
| 1001 |
else |
| 1002 |
{ |
| 1003 |
ang = rotate / 180 * Q_PI; |
| 1004 |
sinv = sin( ang ); |
| 1005 |
cosv = cos( ang ); |
| 1006 |
} |
| 1007 |
|
| 1008 |
if ( vecs[0][0] ) { |
| 1009 |
sv = 0; |
| 1010 |
} |
| 1011 |
else if ( vecs[0][1] ) { |
| 1012 |
sv = 1; |
| 1013 |
} |
| 1014 |
else{ |
| 1015 |
sv = 2; |
| 1016 |
} |
| 1017 |
|
| 1018 |
if ( vecs[1][0] ) { |
| 1019 |
tv = 0; |
| 1020 |
} |
| 1021 |
else if ( vecs[1][1] ) { |
| 1022 |
tv = 1; |
| 1023 |
} |
| 1024 |
else{ |
| 1025 |
tv = 2; |
| 1026 |
} |
| 1027 |
|
| 1028 |
for ( i = 0 ; i < 2 ; i++ ) { |
| 1029 |
ns = cosv * vecs[i][sv] - sinv * vecs[i][tv]; |
| 1030 |
nt = sinv * vecs[i][sv] + cosv * vecs[i][tv]; |
| 1031 |
vecs[i][sv] = ns; |
| 1032 |
vecs[i][tv] = nt; |
| 1033 |
} |
| 1034 |
|
| 1035 |
for ( i = 0 ; i < 2 ; i++ ) |
| 1036 |
for ( j = 0 ; j < 3 ; j++ ) |
| 1037 |
mappingVecs[i][j] = vecs[i][j] / scale[i]; |
| 1038 |
|
| 1039 |
mappingVecs[0][3] = shift[0]; |
| 1040 |
mappingVecs[1][3] = shift[1]; |
| 1041 |
} |
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
static void ParseRawBrush( qboolean onlyLights ){ |
| 1060 |
side_t *side; |
| 1061 |
vec3_t planePoints[ 3 ]; |
| 1062 |
int planenum; |
| 1063 |
shaderInfo_t *si; |
| 1064 |
vec_t shift[ 2 ]; |
| 1065 |
vec_t rotate = 0; |
| 1066 |
vec_t scale[ 2 ]; |
| 1067 |
char name[ MAX_QPATH ]; |
| 1068 |
char shader[ MAX_QPATH ]; |
| 1069 |
int flags; |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
buildBrush->numsides = 0; |
| 1074 |
buildBrush->detail = qfalse; |
| 1075 |
|
| 1076 |
|
| 1077 |
if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) { |
| 1078 |
MatchToken( "{" ); |
| 1079 |
} |
| 1080 |
|
| 1081 |
|
| 1082 |
while ( 1 ) |
| 1083 |
{ |
| 1084 |
if ( !GetToken( qtrue ) ) { |
| 1085 |
break; |
| 1086 |
} |
| 1087 |
if ( !strcmp( token, "}" ) ) { |
| 1088 |
break; |
| 1089 |
} |
| 1090 |
|
| 1091 |
|
| 1092 |
if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) { |
| 1093 |
while ( 1 ) |
| 1094 |
{ |
| 1095 |
if ( strcmp( token, "(" ) ) { |
| 1096 |
GetToken( qfalse ); |
| 1097 |
} |
| 1098 |
else{ |
| 1099 |
break; |
| 1100 |
} |
| 1101 |
GetToken( qtrue ); |
| 1102 |
} |
| 1103 |
} |
| 1104 |
UnGetToken(); |
| 1105 |
|
| 1106 |
|
| 1107 |
if ( buildBrush->numsides >= MAX_BUILD_SIDES ) { |
| 1108 |
xml_Select( "MAX_BUILD_SIDES", buildBrush->entityNum, buildBrush->brushNum, qtrue ); |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
side = &buildBrush->sides[ buildBrush->numsides ]; |
| 1113 |
memset( side, 0, sizeof( *side ) ); |
| 1114 |
buildBrush->numsides++; |
| 1115 |
|
| 1116 |
|
| 1117 |
Parse1DMatrix( 3, planePoints[ 0 ] ); |
| 1118 |
Parse1DMatrix( 3, planePoints[ 1 ] ); |
| 1119 |
Parse1DMatrix( 3, planePoints[ 2 ] ); |
| 1120 |
|
| 1121 |
|
| 1122 |
if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) { |
| 1123 |
Parse2DMatrix( 2, 3, (float*) side->texMat ); |
| 1124 |
} |
| 1125 |
|
| 1126 |
|
| 1127 |
GetToken( qfalse ); |
| 1128 |
strcpy( name, token ); |
| 1129 |
|
| 1130 |
|
| 1131 |
if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) { |
| 1132 |
GetToken( qfalse ); |
| 1133 |
shift[ 0 ] = atof( token ); |
| 1134 |
GetToken( qfalse ); |
| 1135 |
shift[ 1 ] = atof( token ); |
| 1136 |
GetToken( qfalse ); |
| 1137 |
rotate = atof( token ); |
| 1138 |
GetToken( qfalse ); |
| 1139 |
scale[ 0 ] = atof( token ); |
| 1140 |
GetToken( qfalse ); |
| 1141 |
scale[ 1 ] = atof( token ); |
| 1142 |
} |
| 1143 |
|
| 1144 |
|
| 1145 |
sprintf( shader, "textures/%s", name ); |
| 1146 |
if ( onlyLights ) { |
| 1147 |
si = &shaderInfo[ 0 ]; |
| 1148 |
} |
| 1149 |
else{ |
| 1150 |
si = ShaderInfoForShader( shader ); |
| 1151 |
} |
| 1152 |
side->shaderInfo = si; |
| 1153 |
side->surfaceFlags = si->surfaceFlags; |
| 1154 |
side->contentFlags = si->contentFlags; |
| 1155 |
side->compileFlags = si->compileFlags; |
| 1156 |
side->value = si->value; |
| 1157 |
|
| 1158 |
|
| 1159 |
if ( si->globalTexture == qfalse ) { |
| 1160 |
shift[ 0 ] -= ( floor( shift[ 0 ] / si->shaderWidth ) * si->shaderWidth ); |
| 1161 |
shift[ 1 ] -= ( floor( shift[ 1 ] / si->shaderHeight ) * si->shaderHeight ); |
| 1162 |
} |
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
if ( TokenAvailable() ) { |
| 1176 |
|
| 1177 |
GetToken( qfalse ); |
| 1178 |
flags = atoi( token ); |
| 1179 |
if ( flags & C_DETAIL ) { |
| 1180 |
side->compileFlags |= C_DETAIL; |
| 1181 |
} |
| 1182 |
|
| 1183 |
|
| 1184 |
GetToken( qfalse ); |
| 1185 |
|
| 1186 |
GetToken( qfalse ); |
| 1187 |
|
| 1188 |
} |
| 1189 |
|
| 1190 |
|
| 1191 |
planenum = MapPlaneFromPoints( planePoints ); |
| 1192 |
side->planenum = planenum; |
| 1193 |
|
| 1194 |
|
| 1195 |
if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) { |
| 1196 |
QuakeTextureVecs( &mapplanes[ planenum ], shift, rotate, scale, side->vecs ); |
| 1197 |
} |
| 1198 |
} |
| 1199 |
|
| 1200 |
|
| 1201 |
if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) { |
| 1202 |
UnGetToken(); |
| 1203 |
MatchToken( "}" ); |
| 1204 |
MatchToken( "}" ); |
| 1205 |
} |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
qboolean RemoveDuplicateBrushPlanes( brush_t *b ){ |
| 1218 |
int i, j, k; |
| 1219 |
side_t *sides; |
| 1220 |
|
| 1221 |
sides = b->sides; |
| 1222 |
|
| 1223 |
for ( i = 1 ; i < b->numsides ; i++ ) { |
| 1224 |
|
| 1225 |
|
| 1226 |
if ( sides[i].planenum == -1 ) { |
| 1227 |
xml_Select( "degenerate plane", b->entityNum, b->brushNum, qfalse ); |
| 1228 |
|
| 1229 |
for ( k = i + 1 ; k < b->numsides ; k++ ) { |
| 1230 |
sides[k - 1] = sides[k]; |
| 1231 |
} |
| 1232 |
b->numsides--; |
| 1233 |
i--; |
| 1234 |
continue; |
| 1235 |
} |
| 1236 |
|
| 1237 |
|
| 1238 |
for ( j = 0 ; j < i ; j++ ) { |
| 1239 |
if ( sides[i].planenum == sides[j].planenum ) { |
| 1240 |
xml_Select( "duplicate plane", b->entityNum, b->brushNum, qfalse ); |
| 1241 |
|
| 1242 |
for ( k = i + 1 ; k < b->numsides ; k++ ) { |
| 1243 |
sides[k - 1] = sides[k]; |
| 1244 |
} |
| 1245 |
b->numsides--; |
| 1246 |
i--; |
| 1247 |
break; |
| 1248 |
} |
| 1249 |
|
| 1250 |
if ( sides[i].planenum == ( sides[j].planenum ^ 1 ) ) { |
| 1251 |
|
| 1252 |
xml_Select( "mirrored plane", b->entityNum, b->brushNum, qfalse ); |
| 1253 |
return qfalse; |
| 1254 |
} |
| 1255 |
} |
| 1256 |
} |
| 1257 |
return qtrue; |
| 1258 |
} |
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
static void ParseBrush( qboolean onlyLights, qboolean noCollapseGroups ){ |
| 1268 |
|
| 1269 |
ParseRawBrush( onlyLights ); |
| 1270 |
|
| 1271 |
|
| 1272 |
if ( onlyLights ) { |
| 1273 |
return; |
| 1274 |
} |
| 1275 |
|
| 1276 |
|
| 1277 |
buildBrush->portalareas[ 0 ] = -1; |
| 1278 |
buildBrush->portalareas[ 1 ] = -1; |
| 1279 |
buildBrush->entityNum = numMapEntities - 1; |
| 1280 |
buildBrush->brushNum = entitySourceBrushes; |
| 1281 |
|
| 1282 |
|
| 1283 |
if ( !RemoveDuplicateBrushPlanes( buildBrush ) ) { |
| 1284 |
return; |
| 1285 |
} |
| 1286 |
|
| 1287 |
|
| 1288 |
SetBrushContents( buildBrush ); |
| 1289 |
|
| 1290 |
|
| 1291 |
if ( nodetail && ( buildBrush->compileFlags & C_DETAIL ) ) { |
| 1292 |
|
| 1293 |
return; |
| 1294 |
} |
| 1295 |
|
| 1296 |
|
| 1297 |
if ( nowater && ( buildBrush->compileFlags & C_LIQUID ) ) { |
| 1298 |
|
| 1299 |
return; |
| 1300 |
} |
| 1301 |
|
| 1302 |
|
| 1303 |
if ( noHint && ( buildBrush->compileFlags & C_HINT ) ) { |
| 1304 |
|
| 1305 |
return; |
| 1306 |
} |
| 1307 |
|
| 1308 |
|
| 1309 |
FinishBrush( noCollapseGroups ); |
| 1310 |
} |
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
void AdjustBrushesForOrigin( entity_t *ent ); |
| 1322 |
void MoveBrushesToWorld( entity_t *ent ){ |
| 1323 |
brush_t *b, *next; |
| 1324 |
parseMesh_t *pm; |
| 1325 |
|
| 1326 |
|
| 1327 |
VectorScale( ent->origin, -1, ent->originbrush_origin ); |
| 1328 |
AdjustBrushesForOrigin( ent ); |
| 1329 |
VectorClear( ent->originbrush_origin ); |
| 1330 |
|
| 1331 |
|
| 1332 |
for ( b = ent->brushes; b != NULL; b = next ) |
| 1333 |
{ |
| 1334 |
|
| 1335 |
next = b->next; |
| 1336 |
|
| 1337 |
|
| 1338 |
if ( b->opaque || entities[ 0 ].lastBrush == NULL ) { |
| 1339 |
b->next = entities[ 0 ].brushes; |
| 1340 |
entities[ 0 ].brushes = b; |
| 1341 |
if ( entities[ 0 ].lastBrush == NULL ) { |
| 1342 |
entities[ 0 ].lastBrush = b; |
| 1343 |
} |
| 1344 |
} |
| 1345 |
else |
| 1346 |
{ |
| 1347 |
b->next = NULL; |
| 1348 |
entities[ 0 ].lastBrush->next = b; |
| 1349 |
entities[ 0 ].lastBrush = b; |
| 1350 |
} |
| 1351 |
} |
| 1352 |
ent->brushes = NULL; |
| 1353 |
|
| 1354 |
|
| 1355 |
if ( ent->colorModBrushes != NULL ) { |
| 1356 |
for ( b = ent->colorModBrushes; b->nextColorModBrush != NULL; b = b->nextColorModBrush ) ; |
| 1357 |
|
| 1358 |
b->nextColorModBrush = entities[ 0 ].colorModBrushes; |
| 1359 |
entities[ 0 ].colorModBrushes = ent->colorModBrushes; |
| 1360 |
|
| 1361 |
ent->colorModBrushes = NULL; |
| 1362 |
} |
| 1363 |
|
| 1364 |
|
| 1365 |
if ( ent->patches != NULL ) { |
| 1366 |
for ( pm = ent->patches; pm->next != NULL; pm = pm->next ) ; |
| 1367 |
|
| 1368 |
pm->next = entities[ 0 ].patches; |
| 1369 |
entities[ 0 ].patches = ent->patches; |
| 1370 |
|
| 1371 |
ent->patches = NULL; |
| 1372 |
} |
| 1373 |
} |
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
void AdjustBrushesForOrigin( entity_t *ent ){ |
| 1382 |
|
| 1383 |
int i; |
| 1384 |
side_t *s; |
| 1385 |
vec_t newdist; |
| 1386 |
brush_t *b; |
| 1387 |
parseMesh_t *p; |
| 1388 |
|
| 1389 |
|
| 1390 |
for ( b = ent->brushes; b != NULL; b = b->next ) |
| 1391 |
{ |
| 1392 |
|
| 1393 |
for ( i = 0; i < b->numsides; i++ ) |
| 1394 |
{ |
| 1395 |
|
| 1396 |
s = &b->sides[ i ]; |
| 1397 |
|
| 1398 |
|
| 1399 |
newdist = mapplanes[ s->planenum ].dist - DotProduct( mapplanes[ s->planenum ].normal, ent->originbrush_origin ); |
| 1400 |
|
| 1401 |
|
| 1402 |
s->planenum = FindFloatPlane( mapplanes[ s->planenum ].normal, newdist, 0, NULL ); |
| 1403 |
} |
| 1404 |
|
| 1405 |
|
| 1406 |
CreateBrushWindings( b ); |
| 1407 |
} |
| 1408 |
|
| 1409 |
|
| 1410 |
for ( p = ent->patches; p != NULL; p = p->next ) |
| 1411 |
{ |
| 1412 |
for ( i = 0; i < ( p->mesh.width * p->mesh.height ); i++ ) |
| 1413 |
VectorSubtract( p->mesh.verts[ i ].xyz, ent->originbrush_origin, p->mesh.verts[ i ].xyz ); |
| 1414 |
} |
| 1415 |
} |
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
void SetEntityBounds( entity_t *e ){ |
| 1425 |
int i; |
| 1426 |
brush_t *b; |
| 1427 |
parseMesh_t *p; |
| 1428 |
vec3_t mins, maxs; |
| 1429 |
const char *value; |
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
ClearBounds( mins, maxs ); |
| 1436 |
for ( b = e->brushes; b; b = b->next ) |
| 1437 |
{ |
| 1438 |
AddPointToBounds( b->mins, mins, maxs ); |
| 1439 |
AddPointToBounds( b->maxs, mins, maxs ); |
| 1440 |
} |
| 1441 |
for ( p = e->patches; p; p = p->next ) |
| 1442 |
{ |
| 1443 |
for ( i = 0; i < ( p->mesh.width * p->mesh.height ); i++ ) |
| 1444 |
AddPointToBounds( p->mesh.verts[ i ].xyz, mins, maxs ); |
| 1445 |
} |
| 1446 |
|
| 1447 |
|
| 1448 |
value = ValueForKey( e, "min" ); |
| 1449 |
if ( value[ 0 ] != '\0' ) { |
| 1450 |
GetVectorForKey( e, "min", mins ); |
| 1451 |
} |
| 1452 |
value = ValueForKey( e, "max" ); |
| 1453 |
if ( value[ 0 ] != '\0' ) { |
| 1454 |
GetVectorForKey( e, "max", maxs ); |
| 1455 |
} |
| 1456 |
|
| 1457 |
|
| 1458 |
for ( b = e->brushes; b; b = b->next ) |
| 1459 |
{ |
| 1460 |
VectorCopy( mins, b->eMins ); |
| 1461 |
VectorCopy( maxs, b->eMaxs ); |
| 1462 |
} |
| 1463 |
for ( p = e->patches; p; p = p->next ) |
| 1464 |
{ |
| 1465 |
VectorCopy( mins, p->eMins ); |
| 1466 |
VectorCopy( maxs, p->eMaxs ); |
| 1467 |
} |
| 1468 |
} |
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
void LoadEntityIndexMap( entity_t *e ){ |
| 1478 |
int i, size, numLayers, w, h; |
| 1479 |
const char *value, *indexMapFilename, *shader; |
| 1480 |
char ext[ MAX_QPATH ], offset[ 4096 ], *search, *space; |
| 1481 |
byte *pixels; |
| 1482 |
unsigned int *pixels32; |
| 1483 |
indexMap_t *im; |
| 1484 |
brush_t *b; |
| 1485 |
parseMesh_t *p; |
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
if ( e->brushes == NULL && e->patches == NULL ) { |
| 1490 |
return; |
| 1491 |
} |
| 1492 |
|
| 1493 |
|
| 1494 |
value = ValueForKey( e, "_indexmap" ); |
| 1495 |
if ( value[ 0 ] == '\0' ) { |
| 1496 |
value = ValueForKey( e, "alphamap" ); |
| 1497 |
} |
| 1498 |
if ( value[ 0 ] == '\0' ) { |
| 1499 |
return; |
| 1500 |
} |
| 1501 |
indexMapFilename = value; |
| 1502 |
|
| 1503 |
|
| 1504 |
value = ValueForKey( e, "_layers" ); |
| 1505 |
if ( value[ 0 ] == '\0' ) { |
| 1506 |
value = ValueForKey( e, "layers" ); |
| 1507 |
} |
| 1508 |
if ( value[ 0 ] == '\0' ) { |
| 1509 |
Sys_FPrintf( SYS_WRN, "WARNING: Entity with index/alpha map \"%s\" has missing \"_layers\" or \"layers\" key\n", indexMapFilename ); |
| 1510 |
Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" ); |
| 1511 |
return; |
| 1512 |
} |
| 1513 |
numLayers = atoi( value ); |
| 1514 |
if ( numLayers < 1 ) { |
| 1515 |
Sys_FPrintf( SYS_WRN, "WARNING: Entity with index/alpha map \"%s\" has < 1 layer (%d)\n", indexMapFilename, numLayers ); |
| 1516 |
Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" ); |
| 1517 |
return; |
| 1518 |
} |
| 1519 |
|
| 1520 |
|
| 1521 |
value = ValueForKey( mapEnt, "_shader" ); |
| 1522 |
if ( value[ 0 ] == '\0' ) { |
| 1523 |
value = ValueForKey( e, "shader" ); |
| 1524 |
} |
| 1525 |
if ( value[ 0 ] == '\0' ) { |
| 1526 |
Sys_FPrintf( SYS_WRN, "WARNING: Entity with index/alpha map \"%s\" has missing \"_shader\" or \"shader\" key\n", indexMapFilename ); |
| 1527 |
Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" ); |
| 1528 |
return; |
| 1529 |
} |
| 1530 |
shader = value; |
| 1531 |
|
| 1532 |
|
| 1533 |
Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n", mapEnt->mapEntityNum, ValueForKey( e, "classname" ), indexMapFilename ); |
| 1534 |
|
| 1535 |
|
| 1536 |
ExtractFileExtension( indexMapFilename, ext ); |
| 1537 |
|
| 1538 |
|
| 1539 |
if ( !Q_stricmp( ext, "tga" ) ) { |
| 1540 |
|
| 1541 |
Load32BitImage( indexMapFilename, &pixels32, &w, &h ); |
| 1542 |
|
| 1543 |
|
| 1544 |
size = w * h; |
| 1545 |
pixels = safe_malloc( size ); |
| 1546 |
for ( i = 0; i < size; i++ ) |
| 1547 |
{ |
| 1548 |
pixels[ i ] = ( ( pixels32[ i ] & 0xFF ) * numLayers ) / 256; |
| 1549 |
if ( pixels[ i ] >= numLayers ) { |
| 1550 |
pixels[ i ] = numLayers - 1; |
| 1551 |
} |
| 1552 |
} |
| 1553 |
|
| 1554 |
|
| 1555 |
free( pixels32 ); |
| 1556 |
} |
| 1557 |
else |
| 1558 |
{ |
| 1559 |
|
| 1560 |
Load256Image( indexMapFilename, &pixels, NULL, &w, &h ); |
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
size = w * h; |
| 1567 |
for ( i = 0; i < size; i++ ) |
| 1568 |
{ |
| 1569 |
if ( pixels[ i ] >= numLayers ) { |
| 1570 |
pixels[ i ] = numLayers - 1; |
| 1571 |
} |
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
} |
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
} |
| 1582 |
|
| 1583 |
|
| 1584 |
if ( w < 2 || h < 2 ) { |
| 1585 |
Sys_FPrintf( SYS_WRN, "WARNING: Entity with index/alpha map \"%s\" is smaller than 2x2 pixels\n", indexMapFilename ); |
| 1586 |
Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" ); |
| 1587 |
free( pixels ); |
| 1588 |
return; |
| 1589 |
} |
| 1590 |
|
| 1591 |
|
| 1592 |
im = safe_malloc0( sizeof( *im ) ); |
| 1593 |
|
| 1594 |
|
| 1595 |
im->w = w; |
| 1596 |
im->h = h; |
| 1597 |
im->numLayers = numLayers; |
| 1598 |
strcpy( im->name, indexMapFilename ); |
| 1599 |
strcpy( im->shader, shader ); |
| 1600 |
im->pixels = pixels; |
| 1601 |
|
| 1602 |
|
| 1603 |
value = ValueForKey( mapEnt, "_offsets" ); |
| 1604 |
if ( value[ 0 ] == '\0' ) { |
| 1605 |
value = ValueForKey( e, "offsets" ); |
| 1606 |
} |
| 1607 |
if ( value[ 0 ] != '\0' ) { |
| 1608 |
|
| 1609 |
strcpy( offset, value ); |
| 1610 |
search = offset; |
| 1611 |
|
| 1612 |
|
| 1613 |
for ( i = 0; i < 256 && *search != '\0'; i++ ) |
| 1614 |
{ |
| 1615 |
space = strstr( search, " " ); |
| 1616 |
if ( space != NULL ) { |
| 1617 |
*space = '\0'; |
| 1618 |
} |
| 1619 |
im->offsets[ i ] = atof( search ); |
| 1620 |
if ( space == NULL ) { |
| 1621 |
break; |
| 1622 |
} |
| 1623 |
search = space + 1; |
| 1624 |
} |
| 1625 |
} |
| 1626 |
|
| 1627 |
|
| 1628 |
for ( b = e->brushes; b != NULL; b = b->next ) |
| 1629 |
b->im = im; |
| 1630 |
for ( p = e->patches; p != NULL; p = p->next ) |
| 1631 |
p->im = im; |
| 1632 |
} |
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups ){ |
| 1646 |
epair_t *ep; |
| 1647 |
const char *classname, *value; |
| 1648 |
float lightmapScale, shadeAngle; |
| 1649 |
int lightmapSampleSize; |
| 1650 |
char shader[ MAX_QPATH ]; |
| 1651 |
shaderInfo_t *celShader = NULL; |
| 1652 |
brush_t *brush; |
| 1653 |
parseMesh_t *patch; |
| 1654 |
qboolean funcGroup; |
| 1655 |
int castShadows, recvShadows; |
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
if ( !GetToken( qtrue ) ) { |
| 1660 |
return qfalse; |
| 1661 |
} |
| 1662 |
|
| 1663 |
|
| 1664 |
if ( strcmp( token, "{" ) ) { |
| 1665 |
Sys_FPrintf( SYS_WRN, "WARNING: ParseEntity: { not found, found %s on line %d - last entity was at: <%4.2f, %4.2f, %4.2f>...\n" |
| 1666 |
"Continuing to process map, but resulting BSP may be invalid.\n", |
| 1667 |
token, scriptline, entities[ numEntities ].origin[ 0 ], entities[ numEntities ].origin[ 1 ], entities[ numEntities ].origin[ 2 ] ); |
| 1668 |
return qfalse; |
| 1669 |
} |
| 1670 |
|
| 1671 |
|
| 1672 |
AUTOEXPAND_BY_REALLOC( entities, numEntities, allocatedEntities, 32 ); |
| 1673 |
|
| 1674 |
|
| 1675 |
entitySourceBrushes = 0; |
| 1676 |
mapEnt = &entities[ numEntities ]; |
| 1677 |
numEntities++; |
| 1678 |
memset( mapEnt, 0, sizeof( *mapEnt ) ); |
| 1679 |
|
| 1680 |
|
| 1681 |
mapEnt->mapEntityNum = numMapEntities; |
| 1682 |
numMapEntities++; |
| 1683 |
|
| 1684 |
|
| 1685 |
while ( 1 ) |
| 1686 |
{ |
| 1687 |
|
| 1688 |
if ( !GetToken( qtrue ) ) { |
| 1689 |
Sys_FPrintf( SYS_WRN, "WARNING: ParseEntity: EOF without closing brace\n" |
| 1690 |
"Continuing to process map, but resulting BSP may be invalid.\n" ); |
| 1691 |
return qfalse; |
| 1692 |
} |
| 1693 |
|
| 1694 |
if ( !strcmp( token, "}" ) ) { |
| 1695 |
break; |
| 1696 |
} |
| 1697 |
|
| 1698 |
if ( !strcmp( token, "{" ) ) { |
| 1699 |
|
| 1700 |
if ( !GetToken( qtrue ) ) { |
| 1701 |
break; |
| 1702 |
} |
| 1703 |
|
| 1704 |
|
| 1705 |
if ( !strcmp( token, "patchDef2" ) ) { |
| 1706 |
numMapPatches++; |
| 1707 |
ParsePatch( onlyLights ); |
| 1708 |
} |
| 1709 |
else if ( !strcmp( token, "terrainDef" ) ) { |
| 1710 |
|
| 1711 |
Sys_FPrintf( SYS_WRN, "WARNING: Terrain entity parsing not supported in this build.\n" ); |
| 1712 |
} |
| 1713 |
else if ( !strcmp( token, "brushDef" ) ) { |
| 1714 |
if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) { |
| 1715 |
Error( "Old brush format not allowed in new brush format map" ); |
| 1716 |
} |
| 1717 |
g_bBrushPrimit = BPRIMIT_NEWBRUSHES; |
| 1718 |
|
| 1719 |
|
| 1720 |
ParseBrush( onlyLights, noCollapseGroups ); |
| 1721 |
} |
| 1722 |
else |
| 1723 |
{ |
| 1724 |
if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) { |
| 1725 |
Error( "New brush format not allowed in old brush format map" ); |
| 1726 |
} |
| 1727 |
g_bBrushPrimit = BPRIMIT_OLDBRUSHES; |
| 1728 |
|
| 1729 |
|
| 1730 |
UnGetToken(); |
| 1731 |
ParseBrush( onlyLights, noCollapseGroups ); |
| 1732 |
} |
| 1733 |
entitySourceBrushes++; |
| 1734 |
} |
| 1735 |
else |
| 1736 |
{ |
| 1737 |
|
| 1738 |
ep = ParseEPair(); |
| 1739 |
|
| 1740 |
|
| 1741 |
if ( ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' ) { |
| 1742 |
ep->next = mapEnt->epairs; |
| 1743 |
mapEnt->epairs = ep; |
| 1744 |
} |
| 1745 |
} |
| 1746 |
} |
| 1747 |
|
| 1748 |
|
| 1749 |
classname = ValueForKey( mapEnt, "classname" ); |
| 1750 |
|
| 1751 |
|
| 1752 |
if ( onlyLights && Q_strncasecmp( classname, "light", 5 ) ) { |
| 1753 |
numEntities--; |
| 1754 |
return qtrue; |
| 1755 |
} |
| 1756 |
|
| 1757 |
|
| 1758 |
if ( !Q_stricmp( "func_group", classname ) ) { |
| 1759 |
funcGroup = qtrue; |
| 1760 |
} |
| 1761 |
else{ |
| 1762 |
funcGroup = qfalse; |
| 1763 |
} |
| 1764 |
|
| 1765 |
|
| 1766 |
if ( funcGroup || mapEnt->mapEntityNum == 0 ) { |
| 1767 |
|
| 1768 |
castShadows = WORLDSPAWN_CAST_SHADOWS; |
| 1769 |
recvShadows = WORLDSPAWN_RECV_SHADOWS; |
| 1770 |
} |
| 1771 |
|
| 1772 |
|
| 1773 |
else |
| 1774 |
{ |
| 1775 |
|
| 1776 |
castShadows = ENTITY_CAST_SHADOWS; |
| 1777 |
recvShadows = ENTITY_RECV_SHADOWS; |
| 1778 |
} |
| 1779 |
|
| 1780 |
|
| 1781 |
GetEntityShadowFlags( mapEnt, NULL, &castShadows, &recvShadows ); |
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
lightmapScale = 0.0f; |
| 1786 |
if ( strcmp( "", ValueForKey( mapEnt, "lightmapscale" ) ) || |
| 1787 |
strcmp( "", ValueForKey( mapEnt, "_lightmapscale" ) ) || |
| 1788 |
strcmp( "", ValueForKey( mapEnt, "_ls" ) ) ) { |
| 1789 |
|
| 1790 |
lightmapScale = FloatForKey( mapEnt, "lightmapscale" ); |
| 1791 |
if ( lightmapScale <= 0.0f ) { |
| 1792 |
lightmapScale = FloatForKey( mapEnt, "_lightmapscale" ); |
| 1793 |
} |
| 1794 |
if ( lightmapScale <= 0.0f ) { |
| 1795 |
lightmapScale = FloatForKey( mapEnt, "_ls" ); |
| 1796 |
} |
| 1797 |
if ( lightmapScale < 0.0f ) { |
| 1798 |
lightmapScale = 0.0f; |
| 1799 |
} |
| 1800 |
if ( lightmapScale > 0.0f ) { |
| 1801 |
Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt->mapEntityNum, classname, lightmapScale ); |
| 1802 |
} |
| 1803 |
} |
| 1804 |
|
| 1805 |
|
| 1806 |
value = ValueForKey( mapEnt, "_celshader" ); |
| 1807 |
if ( value[ 0 ] == '\0' ) { |
| 1808 |
value = ValueForKey( &entities[ 0 ], "_celshader" ); |
| 1809 |
} |
| 1810 |
if ( value[ 0 ] != '\0' ) { |
| 1811 |
if ( strcmp( value, "none" ) ) { |
| 1812 |
sprintf( shader, "textures/%s", value ); |
| 1813 |
celShader = ShaderInfoForShader( shader ); |
| 1814 |
Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader ); |
| 1815 |
} |
| 1816 |
else |
| 1817 |
{ |
| 1818 |
celShader = NULL; |
| 1819 |
} |
| 1820 |
} |
| 1821 |
else{ |
| 1822 |
celShader = ( *globalCelShader ? ShaderInfoForShader( globalCelShader ) : NULL ); |
| 1823 |
} |
| 1824 |
|
| 1825 |
|
| 1826 |
shadeAngle = 0.0f; |
| 1827 |
if ( strcmp( "", ValueForKey( mapEnt, "_shadeangle" ) ) ) { |
| 1828 |
shadeAngle = FloatForKey( mapEnt, "_shadeangle" ); |
| 1829 |
} |
| 1830 |
|
| 1831 |
else if ( strcmp( "", ValueForKey( mapEnt, "_smoothnormals" ) ) ) { |
| 1832 |
shadeAngle = FloatForKey( mapEnt, "_smoothnormals" ); |
| 1833 |
} |
| 1834 |
else if ( strcmp( "", ValueForKey( mapEnt, "_sn" ) ) ) { |
| 1835 |
shadeAngle = FloatForKey( mapEnt, "_sn" ); |
| 1836 |
} |
| 1837 |
else if ( strcmp( "", ValueForKey( mapEnt, "_sa" ) ) ) { |
| 1838 |
shadeAngle = FloatForKey( mapEnt, "_sa" ); |
| 1839 |
} |
| 1840 |
else if ( strcmp( "", ValueForKey( mapEnt, "_smooth" ) ) ) { |
| 1841 |
shadeAngle = FloatForKey( mapEnt, "_smooth" ); |
| 1842 |
} |
| 1843 |
|
| 1844 |
if ( shadeAngle < 0.0f ) { |
| 1845 |
shadeAngle = 0.0f; |
| 1846 |
} |
| 1847 |
|
| 1848 |
if ( shadeAngle > 0.0f ) { |
| 1849 |
Sys_Printf( "Entity %d (%s) has shading angle of %.4f\n", mapEnt->mapEntityNum, classname, shadeAngle ); |
| 1850 |
} |
| 1851 |
|
| 1852 |
|
| 1853 |
lightmapSampleSize = 0; |
| 1854 |
if ( strcmp( "", ValueForKey( mapEnt, "_lightmapsamplesize" ) ) ) { |
| 1855 |
lightmapSampleSize = IntForKey( mapEnt, "_lightmapsamplesize" ); |
| 1856 |
} |
| 1857 |
else if ( strcmp( "", ValueForKey( mapEnt, "_samplesize" ) ) ) { |
| 1858 |
lightmapSampleSize = IntForKey( mapEnt, "_samplesize" ); |
| 1859 |
} |
| 1860 |
else if ( strcmp( "", ValueForKey( mapEnt, "_ss" ) ) ) { |
| 1861 |
lightmapSampleSize = IntForKey( mapEnt, "_ss" ); |
| 1862 |
} |
| 1863 |
|
| 1864 |
if ( lightmapSampleSize < 0 ) { |
| 1865 |
lightmapSampleSize = 0; |
| 1866 |
} |
| 1867 |
|
| 1868 |
if ( lightmapSampleSize > 0 ) { |
| 1869 |
Sys_Printf( "Entity %d (%s) has lightmap sample size of %d\n", mapEnt->mapEntityNum, classname, lightmapSampleSize ); |
| 1870 |
} |
| 1871 |
|
| 1872 |
|
| 1873 |
for ( brush = mapEnt->brushes; brush != NULL; brush = brush->next ) |
| 1874 |
{ |
| 1875 |
brush->entityNum = mapEnt->mapEntityNum; |
| 1876 |
brush->castShadows = castShadows; |
| 1877 |
brush->recvShadows = recvShadows; |
| 1878 |
brush->lightmapSampleSize = lightmapSampleSize; |
| 1879 |
brush->lightmapScale = lightmapScale; |
| 1880 |
brush->celShader = celShader; |
| 1881 |
brush->shadeAngleDegrees = shadeAngle; |
| 1882 |
} |
| 1883 |
|
| 1884 |
for ( patch = mapEnt->patches; patch != NULL; patch = patch->next ) |
| 1885 |
{ |
| 1886 |
patch->entityNum = mapEnt->mapEntityNum; |
| 1887 |
patch->castShadows = castShadows; |
| 1888 |
patch->recvShadows = recvShadows; |
| 1889 |
patch->lightmapSampleSize = lightmapSampleSize; |
| 1890 |
patch->lightmapScale = lightmapScale; |
| 1891 |
patch->celShader = celShader; |
| 1892 |
} |
| 1893 |
|
| 1894 |
|
| 1895 |
SetEntityBounds( mapEnt ); |
| 1896 |
|
| 1897 |
|
| 1898 |
LoadEntityIndexMap( mapEnt ); |
| 1899 |
|
| 1900 |
|
| 1901 |
GetVectorForKey( mapEnt, "origin", mapEnt->origin ); |
| 1902 |
if ( mapEnt->originbrush_origin[ 0 ] || mapEnt->originbrush_origin[ 1 ] || mapEnt->originbrush_origin[ 2 ] ) { |
| 1903 |
AdjustBrushesForOrigin( mapEnt ); |
| 1904 |
} |
| 1905 |
|
| 1906 |
|
| 1907 |
if ( !noCollapseGroups && !Q_stricmp( "group_info", classname ) ) { |
| 1908 |
numEntities--; |
| 1909 |
return qtrue; |
| 1910 |
} |
| 1911 |
|
| 1912 |
|
| 1913 |
if ( !noCollapseGroups && funcGroup ) { |
| 1914 |
MoveBrushesToWorld( mapEnt ); |
| 1915 |
numEntities--; |
| 1916 |
return qtrue; |
| 1917 |
} |
| 1918 |
|
| 1919 |
|
| 1920 |
return qtrue; |
| 1921 |
} |
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
void LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups ){ |
| 1931 |
FILE *file; |
| 1932 |
brush_t *b; |
| 1933 |
int oldNumEntities = 0, numMapBrushes; |
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
Sys_FPrintf( SYS_VRB, "--- LoadMapFile ---\n" ); |
| 1938 |
Sys_Printf( "Loading %s\n", filename ); |
| 1939 |
|
| 1940 |
|
| 1941 |
file = SafeOpenRead( filename ); |
| 1942 |
fclose( file ); |
| 1943 |
|
| 1944 |
|
| 1945 |
LoadScriptFile( filename, -1 ); |
| 1946 |
|
| 1947 |
|
| 1948 |
if ( onlyLights ) { |
| 1949 |
oldNumEntities = numEntities; |
| 1950 |
} |
| 1951 |
else{ |
| 1952 |
numEntities = 0; |
| 1953 |
} |
| 1954 |
|
| 1955 |
|
| 1956 |
numMapDrawSurfs = 0; |
| 1957 |
c_detail = 0; |
| 1958 |
g_bBrushPrimit = BPRIMIT_UNDEFINED; |
| 1959 |
|
| 1960 |
|
| 1961 |
buildBrush = AllocBrush( MAX_BUILD_SIDES ); |
| 1962 |
|
| 1963 |
|
| 1964 |
while ( ParseMapEntity( onlyLights, noCollapseGroups ) ) ; |
| 1965 |
|
| 1966 |
|
| 1967 |
if ( onlyLights ) { |
| 1968 |
|
| 1969 |
Sys_FPrintf( SYS_VRB, "%9d light entities\n", numEntities - oldNumEntities ); |
| 1970 |
} |
| 1971 |
else |
| 1972 |
{ |
| 1973 |
|
| 1974 |
ClearBounds( mapMins, mapMaxs ); |
| 1975 |
for ( b = entities[ 0 ].brushes; b; b = b->next ) |
| 1976 |
{ |
| 1977 |
AddPointToBounds( b->mins, mapMins, mapMaxs ); |
| 1978 |
AddPointToBounds( b->maxs, mapMins, mapMaxs ); |
| 1979 |
} |
| 1980 |
|
| 1981 |
|
| 1982 |
numMapBrushes = CountBrushList( entities[ 0 ].brushes ); |
| 1983 |
if ( (float) c_detail / (float) numMapBrushes < 0.10f && numMapBrushes > 500 ) { |
| 1984 |
Sys_FPrintf( SYS_WRN, "WARNING: Over 90 percent structural map detected. Compile time may be adversely affected.\n" ); |
| 1985 |
} |
| 1986 |
|
| 1987 |
|
| 1988 |
Sys_FPrintf( SYS_VRB, "%9d total world brushes\n", numMapBrushes ); |
| 1989 |
Sys_FPrintf( SYS_VRB, "%9d detail brushes\n", c_detail ); |
| 1990 |
Sys_FPrintf( SYS_VRB, "%9d patches\n", numMapPatches ); |
| 1991 |
Sys_FPrintf( SYS_VRB, "%9d boxbevels\n", c_boxbevels ); |
| 1992 |
Sys_FPrintf( SYS_VRB, "%9d edgebevels\n", c_edgebevels ); |
| 1993 |
Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities ); |
| 1994 |
Sys_FPrintf( SYS_VRB, "%9d planes\n", nummapplanes ); |
| 1995 |
Sys_Printf( "%9d areaportals\n", c_areaportals ); |
| 1996 |
Sys_Printf( "Size: %5.0f, %5.0f, %5.0f to %5.0f, %5.0f, %5.0f\n", |
| 1997 |
mapMins[ 0 ], mapMins[ 1 ], mapMins[ 2 ], |
| 1998 |
mapMaxs[ 0 ], mapMaxs[ 1 ], mapMaxs[ 2 ] ); |
| 1999 |
|
| 2000 |
|
| 2001 |
if ( fakemap ) { |
| 2002 |
WriteBSPBrushMap( "fakemap.map", entities[ 0 ].brushes ); |
| 2003 |
} |
| 2004 |
} |
| 2005 |
} |