X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=cxr%2Fcxr.h;h=644c8ed83e39381e88ceb5c3beeb4772e29f3be3;hb=0d0b6bf37c8a9c4494071973103a89b4aa82574a;hp=0585f1a240bcc66165bb3a1081844734eab2a04a;hpb=2b81894272ade16dbe3f71514e8eb25b2962bf9e;p=convexer.git diff --git a/cxr/cxr.h b/cxr/cxr.h index 0585f1a..644c8ed 100644 --- a/cxr/cxr.h +++ b/cxr/cxr.h @@ -48,7 +48,6 @@ LICENSE: GPLv3.0, please see COPYING and LICENSE for more information IMPLEMENTATION */ -#define CXR_API #define CXR_EPSILON 0.001 #define CXR_PLANE_SIMILARITY_MAX 0.998 #define CXR_BIG_NUMBER 1e300 @@ -60,31 +59,17 @@ LICENSE: GPLv3.0, please see COPYING and LICENSE for more information #include #include -#include -#include #include #include -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; -typedef int8_t i8; -typedef int16_t i16; -typedef int32_t i32; -typedef int64_t i64; - -typedef unsigned int uint; - -typedef double v2f[2]; -typedef double v3f[3]; -typedef double v4f[4]; -typedef v3f m3x3f[3]; -typedef v3f m4x3f[4]; -typedef v3f boxf[2]; - +#include "cxr_types.h" #include "cxr_math.h" #include "cxr_mem.h" +#include "cxr_log.h" + +#ifdef CXR_VALVE_BIN + #include "cxr_valve_bin.h" +#endif typedef struct cxr_world cxr_world; typedef struct cxr_solid cxr_solid; @@ -159,6 +144,7 @@ struct cxr_static_mesh i32 index, edge_index; v2f uv; + double alpha; } *loops; @@ -192,6 +178,7 @@ struct cxr_loop edge_index, index; v2f uv; + float alpha; }; struct cxr_solid @@ -230,8 +217,11 @@ struct cxr_mesh /* Simple mesh type mainly for debugging */ struct cxr_tri_mesh { - v3f *vertices; + v3f *vertices, + *normals; + v2f *uvs; v4f *colours; + i32 *indices, indices_count, vertex_count; @@ -312,9 +302,6 @@ enum cxr_soliderr #endif #endif -static void (*cxr_log_func)(const char *str); -static void (*cxr_line_func)( v3f p0, v3f p1, v4f colour ); - static int cxr_range(int x, int bound) { if( x < 0 ) @@ -389,21 +376,6 @@ static void colour_random_brush(int n, v4f colour) #ifdef CXR_DEBUG -static void cxr_log( const char *fmt, ... ) -{ - char buf[512]; - - va_list args; - va_start( args, fmt ); - vsnprintf( buf, sizeof(buf)-1, fmt, args ); - va_end(args); - - if( cxr_log_func ) - cxr_log_func( buf ); - - fputs(buf,stdout); -} - static void cxr_debug_line( v3f p0, v3f p1, v4f colour ) { if( cxr_line_func ) @@ -514,9 +486,12 @@ CXR_API void cxr_write_test_data( cxr_static_mesh *src ) fprintf( fp, "cxr_static_loop test_loops[] = {\n" ); for( int i=0; iloop_count; i ++ ) { - fprintf( fp, " {%d, %d},\n", + fprintf( fp, " {%d, %d, {%f, %f}, %f},\n", src->loops[i].index, - src->loops[i].edge_index); + src->loops[i].edge_index, + src->loops[i].uv[0], + src->loops[i].uv[1], + src->loops[i].alpha ); } fprintf( fp, "};\n" ); @@ -2084,6 +2059,7 @@ static cxr_mesh *cxr_to_internal_format( lp->index = src->loops[i].index; lp->edge_index = src->loops[i].edge_index; v2_copy( src->loops[i].uv, lp->uv ); + lp->alpha = src->loops[i].alpha; } abverts->count = src->vertex_count; @@ -2212,6 +2188,8 @@ CXR_API cxr_tri_mesh *cxr_world_preview( cxr_world *world ) out->colours = malloc( sizeof(v4f)*out->vertex_count ); out->vertices = malloc( sizeof(v3f)*out->vertex_count ); out->indices = malloc( sizeof(i32)*out->indices_count ); + out->uvs = NULL; + out->normals = NULL; v3f *overts = out->vertices; v4f *colours = out->colours; @@ -2293,6 +2271,8 @@ CXR_API void cxr_free_tri_mesh( cxr_tri_mesh *mesh ) free( mesh->colours ); free( mesh->indices ); free( mesh->vertices ); + free( mesh->normals ); + free( mesh->uvs ); free( mesh ); } @@ -2777,6 +2757,13 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, } } + /* Collect alphas from loops. This discards hard blend information */ + for( int i=0; iabloops.count; i++ ) + { + cxr_loop *loop = &mesh->loops[i]; + vertinfo[loop->index].alpha = loop->alpha * 255.0; + } + v3f refv, refu, refn; v3_zero(refv); v3_zero(refu); v3_zero(refn); @@ -3145,6 +3132,7 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, v3f normals[25]; double distances[25]; + double alphas[25]; v3f lside0, lside1, lref, vdelta, vworld; double tx, ty; @@ -3169,6 +3157,8 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, v3_copy( vdelta, normals[index] ); v3_normalize( normals[index] ); distances[index] = v3_dot( vdelta, normals[index] ); + + alphas[index] = vertinfo[grid[index]].alpha; } } @@ -3215,6 +3205,11 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, cxr_vdf_karrdouble( output, "row", k, &distances[k*5], 5 ); cxr_vdf_edon( output ); + cxr_vdf_node( output, "alphas" ); + for( int k=0; k<5; k++ ) + cxr_vdf_karrdouble( output, "row", k, &alphas[k*5], 5 ); + cxr_vdf_edon( output ); + /* * TODO: This might be needed for the compilers. Opens fine in * hammer @@ -3233,11 +3228,6 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, "\"row%d\" \"0 0 1 0 0 1 0 0 1 0 0 1 0 0 1\"\n", k ); cxr_vdf_edon( output ); - cxr_vdf_node( output, "alphas" ); - for( int k=0; k<5; k++ ) - cxr_vdf_printf( output, "\"row%d\" \"0 0 0 0 0\"\n", k ); - cxr_vdf_edon( output ); - cxr_vdf_node( output, "triangle_tags" ); for( int k=0; k<5-1; k++ ) cxr_vdf_printf( output, @@ -3519,5 +3509,6 @@ CXR_API int cxr_lightpatch_bsp( const char *path ) return 1; } + #endif /* CXR_VALVE_MAP_FILE */ #endif /* CXR_IMPLEMENTATION */