+
+
+ else if ( ( spf == 128 ) || //EXTRUDE_VERTEX_NORMALS
+ ( spf == 384 ) ){ //EXTRUDE_VERTEX_NORMALS + PYRAMIDAL_CLIP - vertex normals + don't check for sides, sticking outwards
+ /* get vertex normals */
+ for ( j = 0; j < 3; j++ )
+ {
+ /* get vertex */
+ dv = &ds->verts[ ds->indexes[ i + j ] ];
+ /* copy normal */
+ VectorCopy( dv->normal, Vnorm[ j ] );
+ }
+
+ //avg normals for side planes
+ for ( j = 0; j < 3; j++ )
+ {
+ VectorAdd( Vnorm[ j ], Vnorm[ (j+1)%3 ], Enorm[ j ] );
+ VectorNormalize( Enorm[ j ], Enorm[ j ] );
+ //check fuer bad ones
+ VectorSubtract( points[(j+1)%3], points[ j ], cnt );
+ CrossProduct( plane, cnt, nrm );
+ VectorNormalize( nrm, nrm );
+ //check for negative or outside direction
+ if ( DotProduct( Enorm[ j ], plane ) > 0.1 ){
+ if ( ( DotProduct( Enorm[ j ], nrm ) > -0.2 ) || ( spawnFlags & 256 ) ){
+ //ok++;
+ continue;
+ }
+ }
+ //notok++;
+ //Sys_Printf( "faulty Enormal %i/%i\n", notok, ok );
+ //use 45 normal
+ VectorAdd( plane, nrm, Enorm[ j ] );
+ VectorNormalize( Enorm[ j ], Enorm[ j ] );
+ }
+
+ /* make side planes */
+ for ( j = 0; j < 3; j++ )
+ {
+ VectorSubtract( points[(j+1)%3], points[ j ], nrm );
+ CrossProduct( Enorm[ j ], nrm, p[ j ] );
+ VectorNormalize( p[ j ], p[ j ] );
+ p[j][3] = DotProduct( points[j], p[j] );
+ //snap nearly axial side planes
+ snpd = qfalse;
+ for ( k = 0; k < 3; k++ )
+ {
+ if ( fabs(p[j][k]) < 0.00025 && p[j][k] != 0.0 ){
+ //Sys_Printf( "init plane %6.8f %6.8f %6.8f %6.8f\n", p[j][0], p[j][1], p[j][2], p[j][3]);
+ p[j][k] = 0.0;
+ snpd = qtrue;
+ }
+ }
+ if ( snpd ){
+ VectorNormalize( p[j], p[j] );
+ //Sys_Printf( "nrm plane %6.8f %6.8f %6.8f %6.8f\n", p[j][0], p[j][1], p[j][2], p[j][3]);
+ VectorAdd( points[j], points[(j+1)%3], cnt );
+ VectorScale( cnt, 0.5f, cnt );
+ p[j][3] = DotProduct( cnt, p[j] );
+ //Sys_Printf( "dst plane %6.8f %6.8f %6.8f %6.8f\n", p[j][0], p[j][1], p[j][2], p[j][3]);
+ }
+ }
+
+ /* make back plane */
+ VectorScale( plane, -1.0f, reverse );
+ reverse[ 3 ] = -plane[ 3 ];
+ reverse[3] += clipDepth;
+
+ /* set up brush sides */
+ buildBrush->numsides = 5;
+ buildBrush->sides[ 0 ].shaderInfo = si;
+ for ( j = 1; j < buildBrush->numsides; j++ ) {
+ if ( debugClip ) {
+ buildBrush->sides[ 0 ].shaderInfo = ShaderInfoForShader( "debugclip2" );
+ buildBrush->sides[ j ].shaderInfo = ShaderInfoForShader( "debugclip" );
+ }
+ else {
+ buildBrush->sides[ j ].shaderInfo = NULL; // don't emit these faces as draw surfaces, should make smaller BSPs; hope this works
+ }
+ }
+ VectorCopy( points[0], points[3] ); // for cyclic usage
+
+ buildBrush->sides[ 0 ].planenum = FindFloatPlane( plane, plane[ 3 ], 3, points );
+ buildBrush->sides[ 1 ].planenum = FindFloatPlane( p[0], p[0][ 3 ], 2, &points[ 0 ] ); // p[0] contains points[0] and points[1]
+ buildBrush->sides[ 2 ].planenum = FindFloatPlane( p[1], p[1][ 3 ], 2, &points[ 1 ] ); // p[1] contains points[1] and points[2]
+ buildBrush->sides[ 3 ].planenum = FindFloatPlane( p[2], p[2][ 3 ], 2, &points[ 2 ] ); // p[2] contains points[2] and points[0] (copied to points[3]
+ buildBrush->sides[ 4 ].planenum = FindFloatPlane( reverse, reverse[ 3 ], 0, NULL );