X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=cxr%2Fcxr.h;h=e1c1679f405ff2fda3080bcc67ea304acc20b0b7;hb=8e1b6889db7ce10f8d594539ef74dc4390e8e891;hp=c3f7d868d71262110ce28bb89089e4f2c0a8cb28;hpb=dde10aa01dd64855de4328fcd4f3af8b4e013026;p=convexer.git diff --git a/cxr/cxr.h b/cxr/cxr.h index c3f7d86..e1c1679 100644 --- a/cxr/cxr.h +++ b/cxr/cxr.h @@ -1,11 +1,13 @@ /* - CONVEXER v0.91 + CONVEXER v0.95 A GNU/Linux-first Source1 Hammer replacement built with Blender, for mapmakers Copyright (C) 2022 Harry Godden (hgn) +LICENSE: GPLv3.0, please see COPYING and LICENSE for more information + Features: - Brush decomposition into convex pieces for well defined geometry - Freely form displacements without limits @@ -99,6 +101,7 @@ typedef struct cxr_tri_mesh cxr_tri_mesh; #ifdef CXR_VALVE_MAP_FILE typedef struct cxr_vdf cxr_vdf; typedef struct cxr_texinfo cxr_texinfo; + typedef struct cxr_visgroup cxr_visgroup; typedef struct cxr_vmf_context cxr_vmf_context; #endif /* CXR_VALVE_MAP_FILE */ @@ -156,6 +159,7 @@ struct cxr_static_mesh i32 index, edge_index; v2f uv; + double alpha; } *loops; @@ -189,6 +193,7 @@ struct cxr_loop edge_index, index; v2f uv; + float alpha; }; struct cxr_solid @@ -242,6 +247,11 @@ struct cxr_texinfo double winding; }; +struct cxr_visgroup +{ + const char *name; +}; + /* * Simplified VDF writing interface. No allocations or nodes, just write to file */ @@ -259,10 +269,14 @@ struct cxr_vmf_context *detailvbsp, *detailmaterial; + cxr_visgroup *visgroups; + i32 visgroup_count; + /* Transform settings */ double scale; v3f offset; - i32 lightmap_scale; + i32 lightmap_scale, + visgroupid; /* Current stats */ i32 brush_count, @@ -280,7 +294,8 @@ enum cxr_soliderr k_soliderr_degenerate_implicit, k_soliderr_non_coplanar_vertices, k_soliderr_non_convex_poly, - k_soliderr_bad_result + k_soliderr_bad_result, + k_soliderr_invalid_input }; /* @@ -292,6 +307,13 @@ enum cxr_soliderr const char *cxr_build_time = __DATE__ " @" __TIME__; #endif +#if _WIN32 || _WIN64 +#if _WIN64 +#else +#warning 32 bit is not supported in blender 3.0 +#endif +#endif + static void (*cxr_log_func)(const char *str); static void (*cxr_line_func)( v3f p0, v3f p1, v4f colour ); @@ -494,9 +516,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" ); @@ -2064,6 +2089,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; @@ -2278,6 +2304,16 @@ CXR_API void cxr_free_tri_mesh( cxr_tri_mesh *mesh ) CXR_API cxr_world *cxr_decompose( cxr_static_mesh *src, i32 *perrcode ) { + /* Make sure data is in the mesh and isn't empty */ + if( !src->edge_count || !src->loop_count || !src->poly_count ) + { + cxr_log( "Error %d\n", k_soliderr_invalid_input ); + if( perrcode ) + *perrcode = k_soliderr_invalid_input; + + return NULL; + } + u32 error = 0x00; cxr_world *world = malloc( sizeof(*world) ); @@ -2747,6 +2783,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); @@ -2949,6 +2992,8 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, if( !newvert ) { + free( graph ); + free( vertinfo ); return 0; } } @@ -3011,9 +3056,6 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, } } -#ifdef CXR_DEBUG - cxr_log( "Broken displacement!\n" ); -#endif free( graph ); free( vertinfo ); return 0; @@ -3065,6 +3107,8 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, v3_muladds( face_center, refn, 1.5, pn ); v3_muladds( face_center, refv, 1.5, pv ); v3_muladds( face_center, refu, 1.5, pu ); + + v3_muladds( face_center, refn, 2.0, face_center ); } /* Create world coordinates */ @@ -3114,6 +3158,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; @@ -3138,6 +3183,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; } } @@ -3184,6 +3231,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 @@ -3202,11 +3254,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, @@ -3228,7 +3275,8 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, cxr_vdf_node( output, "editor"); cxr_vdf_colour255( output, "color", colours_random[cxr_range(ctx->brush_count,8)]); - + + cxr_vdf_ki32( output, "visgroupid", ctx->visgroupid ); cxr_vdf_ki32( output, "visgroupshown",1); cxr_vdf_ki32( output, "visgroupautoshown",1); cxr_vdf_edon( output ); @@ -3258,6 +3306,15 @@ CXR_API void cxr_begin_vmf( cxr_vmf_context *ctx, cxr_vdf *output ) cxr_vdf_edon( output ); cxr_vdf_node( output, "visgroups" ); + + for( int i=0; ivisgroup_count; i++ ) + { + cxr_vdf_node( output, "visgroup" ); + cxr_vdf_kv( output, "name", ctx->visgroups[i].name ); + cxr_vdf_ki32( output, "visgroupid", i+1 ); + cxr_vdf_edon( output ); + } + cxr_vdf_edon( output ); cxr_vdf_node( output, "viewsettings" ); @@ -3303,7 +3360,10 @@ CXR_API void cxr_push_world_vmf( cxr_world *world, cxr_vmf_context *ctx, if( solid->displacement ) { - cxr_write_disp( solid->pmesh, world, ctx, output ); + if( !cxr_write_disp( solid->pmesh, world, ctx, output ) ) + { + cxr_log( "Warning: Invalid displacement\n" ); + } continue; } @@ -3362,6 +3422,7 @@ CXR_API void cxr_push_world_vmf( cxr_world *world, cxr_vmf_context *ctx, cxr_vdf_colour255( output, "color", colours_random[cxr_range(ctx->brush_count,8)]); + cxr_vdf_ki32( output, "visgroupid", ctx->visgroupid ); cxr_vdf_ki32( output, "visgroupshown", 1 ); cxr_vdf_ki32( output, "visgroupautoshown", 1 ); cxr_vdf_edon( output );