2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 ----------------------------------------------------------------------------------
23 This code has been altered significantly from its original form, to support
24 several games based on the Quake III Arena engine, in the form of "Q3Map2."
26 ------------------------------------------------------------------------------- */
42 returns an 50/50 interpolated vert
45 void LerpDrawVert( bspDrawVert_t *a, bspDrawVert_t *b, bspDrawVert_t *out )
50 out->xyz[ 0 ] = 0.5 * (a->xyz[ 0 ] + b->xyz[ 0 ]);
51 out->xyz[ 1 ] = 0.5 * (a->xyz[ 1 ] + b->xyz[ 1 ]);
52 out->xyz[ 2 ] = 0.5 * (a->xyz[ 2 ] + b->xyz[ 2 ]);
54 out->st[ 0 ] = 0.5 * (a->st[ 0 ] + b->st[ 0 ]);
55 out->st[ 1 ] = 0.5 * (a->st[ 1 ] + b->st[ 1 ]);
57 for( k = 0; k < MAX_LIGHTMAPS; k++ )
59 out->lightmap[ k ][ 0 ] = 0.5f * (a->lightmap[ k ][ 0 ] + b->lightmap[ k ][ 0 ]);
60 out->lightmap[ k ][ 1 ] = 0.5f * (a->lightmap[ k ][ 1 ] + b->lightmap[ k ][ 1 ]);
61 out->color[ k ][ 0 ] = (a->color[ k ][ 0 ] + b->color[ k ][ 0 ]) >> 1;
62 out->color[ k ][ 1 ] = (a->color[ k ][ 1 ] + b->color[ k ][ 1 ]) >> 1;
63 out->color[ k ][ 2 ] = (a->color[ k ][ 2 ] + b->color[ k ][ 2 ]) >> 1;
64 out->color[ k ][ 3 ] = (a->color[ k ][ 3 ] + b->color[ k ][ 3 ]) >> 1;
67 /* ydnar: added normal interpolation */
68 out->normal[ 0 ] = 0.5f * (a->normal[ 0 ] + b->normal[ 0 ]);
69 out->normal[ 1 ] = 0.5f * (a->normal[ 1 ] + b->normal[ 1 ]);
70 out->normal[ 2 ] = 0.5f * (a->normal[ 2 ] + b->normal[ 2 ]);
72 /* if the interpolant created a bogus normal, just copy the normal from a */
73 if( VectorNormalize( out->normal, out->normal ) == 0 )
74 VectorCopy( a->normal, out->normal );
81 returns a biased interpolated vert
84 void LerpDrawVertAmount( bspDrawVert_t *a, bspDrawVert_t *b, float amount, bspDrawVert_t *out )
89 out->xyz[ 0 ] = a->xyz[ 0 ] + amount * (b->xyz[ 0 ] - a->xyz[ 0 ]);
90 out->xyz[ 1 ] = a->xyz[ 1 ] + amount * (b->xyz[ 1 ] - a->xyz[ 1 ]);
91 out->xyz[ 2 ] = a->xyz[ 2 ] + amount * (b->xyz[ 2 ] - a->xyz[ 2 ]);
93 out->st[ 0 ] = a->st[ 0 ] + amount * (b->st[ 0 ] - a->st[ 0 ]);
94 out->st[ 1 ] = a->st[ 1 ] + amount * (b->st[ 1 ] - a->st[ 1 ]);
96 for( k = 0; k < MAX_LIGHTMAPS; k++ )
98 out->lightmap[ k ][ 0 ] = a->lightmap[ k ][ 0 ] + amount * (b->lightmap[ k ][ 0 ] - a->lightmap[ k ][ 0 ]);
99 out->lightmap[ k ][ 1 ] = a->lightmap[ k ][ 1 ] + amount * (b->lightmap[ k ][ 1 ] - a->lightmap[ k ][ 1 ]);
100 out->color[ k ][ 0 ] = a->color[ k ][ 0 ] + amount * (b->color[ k ][ 0 ] - a->color[ k ][ 0 ]);
101 out->color[ k ][ 1 ] = a->color[ k ][ 1 ] + amount * (b->color[ k ][ 1 ] - a->color[ k ][ 1 ]);
102 out->color[ k ][ 2 ] = a->color[ k ][ 2 ] + amount * (b->color[ k ][ 2 ] - a->color[ k ][ 2 ]);
103 out->color[ k ][ 3 ] = a->color[ k ][ 3 ] + amount * (b->color[ k ][ 3 ] - a->color[ k ][ 3 ]);
106 out->normal[ 0 ] = a->normal[ 0 ] + amount * (b->normal[ 0 ] - a->normal[ 0 ]);
107 out->normal[ 1 ] = a->normal[ 1 ] + amount * (b->normal[ 1 ] - a->normal[ 1 ]);
108 out->normal[ 2 ] = a->normal[ 2 ] + amount * (b->normal[ 2 ] - a->normal[ 2 ]);
110 /* if the interpolant created a bogus normal, just copy the normal from a */
111 if( VectorNormalize( out->normal, out->normal ) == 0 )
112 VectorCopy( a->normal, out->normal );
116 void FreeMesh( mesh_t *m ) {
121 void PrintMesh( mesh_t *m ) {
124 for ( i = 0 ; i < m->height ; i++ ) {
125 for ( j = 0 ; j < m->width ; j++ ) {
126 Sys_Printf("(%5.2f %5.2f %5.2f) "
127 , m->verts[i*m->width+j].xyz[0]
128 , m->verts[i*m->width+j].xyz[1]
129 , m->verts[i*m->width+j].xyz[2] );
136 mesh_t *CopyMesh( mesh_t *mesh ) {
140 out = safe_malloc( sizeof( *out ) );
141 out->width = mesh->width;
142 out->height = mesh->height;
144 size = out->width * out->height * sizeof( *out->verts );
145 out->verts = safe_malloc( size );
146 memcpy( out->verts, mesh->verts, size );
154 returns a transposed copy of the mesh, freeing the original
157 mesh_t *TransposeMesh( mesh_t *in ) {
161 out = safe_malloc( sizeof( *out ) );
162 out->width = in->height;
163 out->height = in->width;
164 out->verts = safe_malloc( out->width * out->height * sizeof( bspDrawVert_t ) );
166 for ( h = 0 ; h < in->height ; h++ ) {
167 for ( w = 0 ; w < in->width ; w++ ) {
168 out->verts[ w * in->height + h ] = in->verts[ h * in->width + w ];
177 void InvertMesh( mesh_t *in ) {
181 for ( h = 0 ; h < in->height ; h++ ) {
182 for ( w = 0 ; w < in->width / 2 ; w++ ) {
183 temp = in->verts[ h * in->width + w ];
184 in->verts[ h * in->width + w ] = in->verts[ h * in->width + in->width - 1 - w ];
185 in->verts[ h * in->width + in->width - 1 - w ] = temp;
196 void MakeMeshNormals( mesh_t in )
206 vec3_t around[8], temp;
208 qboolean wrapWidth, wrapHeight;
210 int neighbors[8][2] =
212 {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1}, {-1,-1}, {-1,0}, {-1,1}
217 for ( i = 0 ; i < in.height ; i++ ) {
218 VectorSubtract( in.verts[i*in.width].xyz,
219 in.verts[i*in.width+in.width-1].xyz, delta );
220 len = VectorLength( delta );
225 if ( i == in.height ) {
230 for ( i = 0 ; i < in.width ; i++ ) {
231 VectorSubtract( in.verts[i].xyz,
232 in.verts[i + (in.height-1)*in.width].xyz, delta );
233 len = VectorLength( delta );
238 if ( i == in.width) {
243 for ( i = 0 ; i < in.width ; i++ ) {
244 for ( j = 0 ; j < in.height ; j++ ) {
246 dv = &in.verts[j*in.width+i];
247 VectorCopy( dv->xyz, base );
248 for ( k = 0 ; k < 8 ; k++ ) {
249 VectorClear( around[k] );
252 for ( dist = 1 ; dist <= 3 ; dist++ ) {
253 x = i + neighbors[k][0] * dist;
254 y = j + neighbors[k][1] * dist;
257 x = in.width - 1 + x;
258 } else if ( x >= in.width ) {
259 x = 1 + x - in.width;
264 y = in.height - 1 + y;
265 } else if ( y >= in.height ) {
266 y = 1 + y - in.height;
270 if ( x < 0 || x >= in.width || y < 0 || y >= in.height ) {
271 break; // edge of patch
273 VectorSubtract( in.verts[y*in.width+x].xyz, base, temp );
274 if ( VectorNormalize( temp, temp ) == 0 ) {
275 continue; // degenerate edge, get more dist
278 VectorCopy( temp, around[k] );
285 for ( k = 0 ; k < 8 ; k++ ) {
286 if ( !good[k] || !good[(k+1)&7] ) {
287 continue; // didn't get two points
289 CrossProduct( around[(k+1)&7], around[k], normal );
290 if ( VectorNormalize( normal, normal ) == 0 ) {
293 VectorAdd( normal, sum, sum );
297 //Sys_Printf("bad normal\n");
300 VectorNormalize( sum, dv->normal );
307 drops the aproximating points onto the curve
308 ydnar: fixme: make this use LerpDrawVert() rather than this complicated mess
311 void PutMeshOnCurve( mesh_t in ) {
316 // put all the aproximating points on the curve
317 for ( i = 0 ; i < in.width ; i++ ) {
318 for ( j = 1 ; j < in.height ; j += 2 ) {
319 for ( l = 0 ; l < 3 ; l++ ) {
320 prev = ( in.verts[j*in.width+i].xyz[l] + in.verts[(j+1)*in.width+i].xyz[l] ) * 0.5;
321 next = ( in.verts[j*in.width+i].xyz[l] + in.verts[(j-1)*in.width+i].xyz[l] ) * 0.5;
322 in.verts[j*in.width+i].xyz[l] = ( prev + next ) * 0.5;
324 /* ydnar: interpolating st coords */
327 prev = ( in.verts[j*in.width+i].st[l] + in.verts[(j+1)*in.width+i].st[l] ) * 0.5;
328 next = ( in.verts[j*in.width+i].st[l] + in.verts[(j-1)*in.width+i].st[l] ) * 0.5;
329 in.verts[j*in.width+i].st[l] = ( prev + next ) * 0.5;
331 for( m = 0; m < MAX_LIGHTMAPS; m++ )
333 prev = ( in.verts[j*in.width+i].lightmap[ m ][l] + in.verts[(j+1)*in.width+i].lightmap[ m ][l] ) * 0.5;
334 next = ( in.verts[j*in.width+i].lightmap[ m ][l] + in.verts[(j-1)*in.width+i].lightmap[ m ][l] ) * 0.5;
335 in.verts[j*in.width+i].lightmap[ m ][l] = ( prev + next ) * 0.5;
342 for ( j = 0 ; j < in.height ; j++ ) {
343 for ( i = 1 ; i < in.width ; i += 2 ) {
344 for ( l = 0 ; l < 3 ; l++ ) {
345 prev = ( in.verts[j*in.width+i].xyz[l] + in.verts[j*in.width+i+1].xyz[l] ) * 0.5;
346 next = ( in.verts[j*in.width+i].xyz[l] + in.verts[j*in.width+i-1].xyz[l] ) * 0.5;
347 in.verts[j*in.width+i].xyz[l] = ( prev + next ) * 0.5;
349 /* ydnar: interpolating st coords */
352 prev = ( in.verts[j*in.width+i].st[l] + in.verts[j*in.width+i+1].st[l] ) * 0.5;
353 next = ( in.verts[j*in.width+i].st[l] + in.verts[j*in.width+i-1].st[l] ) * 0.5;
354 in.verts[j*in.width+i].st[l] = ( prev + next ) * 0.5;
356 for( m = 0; m < MAX_LIGHTMAPS; m++ )
358 prev = ( in.verts[j*in.width+i].lightmap[ m ][l] + in.verts[j*in.width+i+1].lightmap[ m ][l] ) * 0.5;
359 next = ( in.verts[j*in.width+i].lightmap[ m ][l] + in.verts[j*in.width+i-1].lightmap[ m ][l] ) * 0.5;
360 in.verts[j*in.width+i].lightmap[ m ][l] = ( prev + next ) * 0.5;
375 mesh_t *SubdivideMesh( mesh_t in, float maxError, float minLength )
378 bspDrawVert_t prev, next, mid;
379 vec3_t prevxyz, nextxyz, midxyz;
384 static bspDrawVert_t expand[MAX_EXPANDED_AXIS][MAX_EXPANDED_AXIS];
387 out.width = in.width;
388 out.height = in.height;
390 for ( i = 0 ; i < in.width ; i++ ) {
391 for ( j = 0 ; j < in.height ; j++ ) {
392 expand[j][i] = in.verts[j*in.width+i];
396 // horizontal subdivisions
397 for ( j = 0 ; j + 2 < out.width ; j += 2 ) {
398 // check subdivided midpoints against control points
399 for ( i = 0 ; i < out.height ; i++ ) {
400 for ( l = 0 ; l < 3 ; l++ ) {
401 prevxyz[l] = expand[i][j+1].xyz[l] - expand[i][j].xyz[l];
402 nextxyz[l] = expand[i][j+2].xyz[l] - expand[i][j+1].xyz[l];
403 midxyz[l] = (expand[i][j].xyz[l] + expand[i][j+1].xyz[l] * 2
404 + expand[i][j+2].xyz[l] ) * 0.25;
407 // if the span length is too long, force a subdivision
408 if ( VectorLength( prevxyz ) > minLength
409 || VectorLength( nextxyz ) > minLength ) {
413 // see if this midpoint is off far enough to subdivide
414 VectorSubtract( expand[i][j+1].xyz, midxyz, delta );
415 len = VectorLength( delta );
416 if ( len > maxError ) {
421 if ( out.width + 2 >= MAX_EXPANDED_AXIS ) {
422 break; // can't subdivide any more
425 if ( i == out.height ) {
426 continue; // didn't need subdivision
429 // insert two columns and replace the peak
432 for ( i = 0 ; i < out.height ; i++ ) {
433 LerpDrawVert( &expand[i][j], &expand[i][j+1], &prev );
434 LerpDrawVert( &expand[i][j+1], &expand[i][j+2], &next );
435 LerpDrawVert( &prev, &next, &mid );
437 for ( k = out.width - 1 ; k > j + 3 ; k-- ) {
438 expand[i][k] = expand[i][k-2];
440 expand[i][j + 1] = prev;
441 expand[i][j + 2] = mid;
442 expand[i][j + 3] = next;
445 // back up and recheck this set again, it may need more subdivision
450 // vertical subdivisions
451 for ( j = 0 ; j + 2 < out.height ; j += 2 ) {
452 // check subdivided midpoints against control points
453 for ( i = 0 ; i < out.width ; i++ ) {
454 for ( l = 0 ; l < 3 ; l++ ) {
455 prevxyz[l] = expand[j+1][i].xyz[l] - expand[j][i].xyz[l];
456 nextxyz[l] = expand[j+2][i].xyz[l] - expand[j+1][i].xyz[l];
457 midxyz[l] = (expand[j][i].xyz[l] + expand[j+1][i].xyz[l] * 2
458 + expand[j+2][i].xyz[l] ) * 0.25;
461 // if the span length is too long, force a subdivision
462 if ( VectorLength( prevxyz ) > minLength
463 || VectorLength( nextxyz ) > minLength ) {
466 // see if this midpoint is off far enough to subdivide
467 VectorSubtract( expand[j+1][i].xyz, midxyz, delta );
468 len = VectorLength( delta );
469 if ( len > maxError ) {
474 if ( out.height + 2 >= MAX_EXPANDED_AXIS ) {
475 break; // can't subdivide any more
478 if ( i == out.width ) {
479 continue; // didn't need subdivision
482 // insert two columns and replace the peak
485 for ( i = 0 ; i < out.width ; i++ ) {
486 LerpDrawVert( &expand[j][i], &expand[j+1][i], &prev );
487 LerpDrawVert( &expand[j+1][i], &expand[j+2][i], &next );
488 LerpDrawVert( &prev, &next, &mid );
490 for ( k = out.height - 1 ; k > j + 3 ; k-- ) {
491 expand[k][i] = expand[k-2][i];
493 expand[j+1][i] = prev;
494 expand[j+2][i] = mid;
495 expand[j+3][i] = next;
498 // back up and recheck this set again, it may need more subdivision
503 // collapse the verts
505 out.verts = &expand[0][0];
506 for ( i = 1 ; i < out.height ; i++ ) {
507 memmove( &out.verts[i*out.width], expand[i], out.width * sizeof(bspDrawVert_t) );
510 return CopyMesh(&out);
516 IterationsForCurve() - ydnar
517 given a curve of a certain length, return the number of subdivision iterations
518 note: this is affected by subdivision amount
521 int IterationsForCurve( float len, int subdivisions )
523 int iterations, facets;
526 /* calculate the number of subdivisions */
527 for( iterations = 0; iterations < 3; iterations++ )
529 facets = subdivisions * 16 * pow( 2, iterations );
534 /* return to caller */
540 SubdivideMesh2() - ydnar
541 subdivides each mesh quad a specified number of times
544 mesh_t *SubdivideMesh2( mesh_t in, int iterations )
547 bspDrawVert_t prev, next, mid;
550 static bspDrawVert_t expand[ MAX_EXPANDED_AXIS ][ MAX_EXPANDED_AXIS ];
554 out.width = in.width;
555 out.height = in.height;
556 for( i = 0; i < in.width; i++ )
558 for( j = 0; j < in.height; j++ )
559 expand[ j ][ i ] = in.verts[ j * in.width + i ];
563 for( iterations; iterations > 0; iterations-- )
565 /* horizontal subdivisions */
566 for( j = 0; j + 2 < out.width; j += 4 )
568 /* check size limit */
569 if( out.width + 2 >= MAX_EXPANDED_AXIS )
572 /* insert two columns and replace the peak */
574 for( i = 0; i < out.height; i++ )
576 LerpDrawVert( &expand[ i ][ j ], &expand[ i ][ j + 1 ], &prev );
577 LerpDrawVert( &expand[ i ][ j + 1 ], &expand[ i ][ j + 2 ], &next );
578 LerpDrawVert( &prev, &next, &mid );
580 for ( k = out.width - 1 ; k > j + 3; k-- )
581 expand [ i ][ k ] = expand[ i ][ k - 2 ];
582 expand[ i ][ j + 1 ] = prev;
583 expand[ i ][ j + 2 ] = mid;
584 expand[ i ][ j + 3 ] = next;
589 /* vertical subdivisions */
590 for ( j = 0; j + 2 < out.height; j += 4 )
592 /* check size limit */
593 if( out.height + 2 >= MAX_EXPANDED_AXIS )
596 /* insert two columns and replace the peak */
598 for( i = 0; i < out.width; i++ )
600 LerpDrawVert( &expand[ j ][ i ], &expand[ j + 1 ][ i ], &prev );
601 LerpDrawVert( &expand[ j + 1 ][ i ], &expand[ j + 2 ][ i ], &next );
602 LerpDrawVert( &prev, &next, &mid );
604 for( k = out.height - 1; k > j + 3; k-- )
605 expand[ k ][ i ] = expand[ k - 2 ][ i ];
606 expand[ j + 1 ][ i ] = prev;
607 expand[ j + 2 ][ i ] = mid;
608 expand[ j + 3 ][ i ] = next;
613 /* collapse the verts */
614 out.verts = &expand[ 0 ][ 0 ];
615 for( i = 1; i < out.height; i++ )
616 memmove( &out.verts[ i * out.width ], expand[ i ], out.width * sizeof( bspDrawVert_t ) );
618 /* return to sender */
619 return CopyMesh( &out );
630 ProjectPointOntoVector
633 void ProjectPointOntoVector( vec3_t point, vec3_t vStart, vec3_t vEnd, vec3_t vProj )
637 VectorSubtract( point, vStart, pVec );
638 VectorSubtract( vEnd, vStart, vec );
639 VectorNormalize( vec, vec );
640 // project onto the directional vector for this segment
641 VectorMA( vStart, DotProduct( pVec, vec ), vec, vProj );
646 RemoveLinearMeshColumsRows
649 mesh_t *RemoveLinearMeshColumnsRows( mesh_t *in ) {
651 float len, maxLength;
655 static bspDrawVert_t expand[MAX_EXPANDED_AXIS][MAX_EXPANDED_AXIS];
658 out.width = in->width;
659 out.height = in->height;
661 for ( i = 0 ; i < in->width ; i++ ) {
662 for ( j = 0 ; j < in->height ; j++ ) {
663 expand[j][i] = in->verts[j*in->width+i];
667 for ( j = 1 ; j < out.width - 1; j++ ) {
669 for ( i = 0 ; i < out.height ; i++ ) {
670 ProjectPointOntoVector(expand[i][j].xyz, expand[i][j-1].xyz, expand[i][j+1].xyz, proj);
671 VectorSubtract(expand[i][j].xyz, proj, dir);
672 len = VectorLength(dir);
673 if (len > maxLength) {
680 for ( i = 0 ; i < out.height ; i++ ) {
681 for (k = j; k < out.width; k++) {
682 expand[i][k] = expand[i][k+1];
688 for ( j = 1 ; j < out.height - 1; j++ ) {
690 for ( i = 0 ; i < out.width ; i++ ) {
691 ProjectPointOntoVector(expand[j][i].xyz, expand[j-1][i].xyz, expand[j+1][i].xyz, proj);
692 VectorSubtract(expand[j][i].xyz, proj, dir);
693 len = VectorLength(dir);
694 if (len > maxLength) {
701 for ( i = 0 ; i < out.width ; i++ ) {
702 for (k = j; k < out.height; k++) {
703 expand[k][i] = expand[k+1][i];
709 // collapse the verts
710 out.verts = &expand[0][0];
711 for ( i = 1 ; i < out.height ; i++ ) {
712 memmove( &out.verts[i*out.width], expand[i], out.width * sizeof(bspDrawVert_t) );
715 return CopyMesh(&out);
725 mesh_t *SubdivideMeshQuads( mesh_t *in, float minLength, int maxsize, int *widthtable, int *heighttable )
727 int i, j, k, w, h, maxsubdivisions, subdivisions;
729 float length, maxLength, amount;
732 static bspDrawVert_t expand[MAX_EXPANDED_AXIS][MAX_EXPANDED_AXIS];
734 out.width = in->width;
735 out.height = in->height;
737 for ( i = 0 ; i < in->width ; i++ ) {
738 for ( j = 0 ; j < in->height ; j++ ) {
739 expand[j][i] = in->verts[j*in->width+i];
743 if (maxsize > MAX_EXPANDED_AXIS)
744 Error("SubdivideMeshQuads: maxsize > MAX_EXPANDED_AXIS");
746 // horizontal subdivisions
748 maxsubdivisions = (maxsize - in->width) / (in->width - 1);
750 for ( w = 0, j = 0 ; w < in->width - 1; w++, j += subdivisions + 1) {
752 for ( i = 0 ; i < out.height ; i++ ) {
753 VectorSubtract(expand[i][j+1].xyz, expand[i][j].xyz, dir);
754 length = VectorLength( dir );
755 if (length > maxLength) {
760 subdivisions = (int) (maxLength / minLength);
761 if (subdivisions > maxsubdivisions)
762 subdivisions = maxsubdivisions;
764 widthtable[w] = subdivisions + 1;
765 if (subdivisions <= 0)
768 out.width += subdivisions;
770 for ( i = 0 ; i < out.height ; i++ ) {
771 for ( k = out.width - 1 ; k > j + subdivisions; k-- ) {
772 expand[i][k] = expand[i][k-subdivisions];
774 for (k = 1; k <= subdivisions; k++)
776 amount = (float) k / (subdivisions + 1);
777 LerpDrawVertAmount(&expand[i][j], &expand[i][j+subdivisions+1], amount, &expand[i][j+k]);
782 maxsubdivisions = (maxsize - in->height) / (in->height - 1);
784 for ( h = 0, j = 0 ; h < in->height - 1; h++, j += subdivisions + 1) {
786 for ( i = 0 ; i < out.width ; i++ ) {
787 VectorSubtract(expand[j+1][i].xyz, expand[j][i].xyz, dir);
788 length = VectorLength( dir );
789 if (length > maxLength) {
794 subdivisions = (int) (maxLength / minLength);
795 if (subdivisions > maxsubdivisions)
796 subdivisions = maxsubdivisions;
798 heighttable[h] = subdivisions + 1;
799 if (subdivisions <= 0)
802 out.height += subdivisions;
804 for ( i = 0 ; i < out.width ; i++ ) {
805 for ( k = out.height - 1 ; k > j + subdivisions; k-- ) {
806 expand[k][i] = expand[k-subdivisions][i];
808 for (k = 1; k <= subdivisions; k++)
810 amount = (float) k / (subdivisions + 1);
811 LerpDrawVertAmount(&expand[j][i], &expand[j+subdivisions+1][i], amount, &expand[j+k][i]);
816 // collapse the verts
817 out.verts = &expand[0][0];
818 for ( i = 1 ; i < out.height ; i++ ) {
819 memmove( &out.verts[i*out.width], expand[i], out.width * sizeof(bspDrawVert_t) );
822 return CopyMesh(&out);