/* ================ DrawSurfaceForMesh ================ */ mapDrawSurface_t *DrawSurfaceForMesh( mesh_t *m ) { mapDrawSurface_t *ds; int i, j; mesh_t *copy; // to make valid normals for patches with degenerate edges, // we need to make a copy of the mesh and put the aproximating // points onto the curve copy = CopyMesh( m ); PutMeshOnCurve( *copy ); MakeMeshNormals( *copy ); for ( j = 0 ; j < m->width ; j++ ) { for ( i = 0 ; i < m->height ; i++ ) { VectorCopy( copy->verts[i*m->width+j].normal, m->verts[i*m->width+j].normal ); } } FreeMesh( copy ); ds = AllocDrawSurf(); ds->mapBrush = NULL; ds->side = NULL; ds->patch = qtrue; ds->patchWidth = m->width; ds->patchHeight = m->height; ds->numVerts = ds->patchWidth * ds->patchHeight; ds->verts = malloc( ds->numVerts * sizeof( *ds->verts ) ); memcpy( ds->verts, m->verts, ds->numVerts * sizeof( *ds->verts ) ); ds->lightmapNum = -1; ds->fogNum = -1; return ds; }
/* ================ CreateTerrainSurface ================ */ void CreateTerrainSurface( terrainSurf_t *surf, shaderInfo_t *shader ) { int i, j, k; drawVert_t *out; drawVert_t *in; mapDrawSurface_t *newsurf; newsurf = AllocDrawSurf(); newsurf->miscModel = qtrue; newsurf->shaderInfo = shader; newsurf->lightmapNum = -1; newsurf->fogNum = -1; newsurf->numIndexes = surf->numIndexes; newsurf->numVerts = surf->numVerts; // copy the indices newsurf->indexes = malloc( surf->numIndexes * sizeof( *newsurf->indexes ) ); memcpy( newsurf->indexes, surf->indexes, surf->numIndexes * sizeof( *newsurf->indexes ) ); // allocate the vertices newsurf->verts = malloc( surf->numVerts * sizeof( *newsurf->verts ) ); memset( newsurf->verts, 0, surf->numVerts * sizeof( *newsurf->verts ) ); // calculate the surface verts out = newsurf->verts; for( i = 0; i < newsurf->numVerts; i++, out++ ) { VectorCopy( surf->verts[ i ].xyz, out->xyz ); // set the texture coordinates out->st[ 0 ] = surf->verts[ i ].st[ 0 ]; out->st[ 1 ] = surf->verts[ i ].st[ 1 ]; // the colors will be set by the lighting pass out->color[0] = 255; out->color[1] = 255; out->color[2] = 255; out->color[3] = surf->verts[ i ].color[ 3 ]; // calculate the vertex normal VectorClear( out->normal ); for( j = 0; j < numsurfaces; j++ ) { in = surfaces[ j ].verts; for( k = 0; k < surfaces[ j ].numVerts; k++, in++ ) { if ( CompareVert( out, in, qfalse ) ) { VectorAdd( out->normal, in->normal, out->normal ); } } } VectorNormalize( out->normal, out->normal ); } }