X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=cxr%2Fcxr.h;fp=cxr%2Fcxr.h;h=518d197695dc37ac8d5d9085a5201d315eec578a;hb=9a92cec0e25c758d12c535bb737be598f053b56d;hp=bb904c4d00ba8ce0522935f03787d0145e11c4e8;hpb=e6de1b2b1d8456cdebd75ccc7640bc0a5740a3b0;p=convexer.git diff --git a/cxr/cxr.h b/cxr/cxr.h index bb904c4..518d197 100644 --- a/cxr/cxr.h +++ b/cxr/cxr.h @@ -45,7 +45,7 @@ IMPLEMENTATION */ -#define CXR_API +#define CXR_API #define CXR_EPSILON 0.001 #define CXR_PLANE_SIMILARITY_MAX 0.998 #define CXR_BIG_NUMBER 1e300 @@ -170,7 +170,7 @@ struct cxr_static_mesh struct cxr_material { i32 res[2]; - const char *name; + char *name; } *materials; @@ -489,7 +489,7 @@ CXR_API void cxr_write_test_data( cxr_static_mesh *src ) } fprintf( fp, "};\n" ); - fprintf( fp, "struct cxr_static_loop test_loops[] = {\n" ); + fprintf( fp, "cxr_static_loop test_loops[] = {\n" ); for( int i=0; iloop_count; i ++ ) { fprintf( fp, " {%d, %d},\n", @@ -498,7 +498,7 @@ CXR_API void cxr_write_test_data( cxr_static_mesh *src ) } fprintf( fp, "};\n" ); - fprintf( fp, "struct cxr_polygon test_polys[] = {\n" ); + fprintf( fp, "cxr_polygon test_polys[] = {\n" ); for( int i=0; i poly_count; i++ ) { fprintf( fp, " {%d, %d, {%f, %f, %f}, {%f, %f, %f}},\n", @@ -513,7 +513,7 @@ CXR_API void cxr_write_test_data( cxr_static_mesh *src ) } fprintf( fp, "};\n" ); - fprintf( fp, "struct cxr_edge test_edges[] = {\n" ); + fprintf( fp, "cxr_edge test_edges[] = {\n" ); for( int i=0; iedge_count; i++ ) { fprintf( fp, " {%d, %d, %d},\n", @@ -524,7 +524,7 @@ CXR_API void cxr_write_test_data( cxr_static_mesh *src ) } fprintf( fp, "};\n" ); - fprintf( fp, "struct cxr_static_mesh test_mesh = {\n" ); + fprintf( fp, "cxr_static_mesh test_mesh = {\n" ); fprintf( fp, " .vertices = test_verts,\n" ); fprintf( fp, " .loops = test_loops,\n" ); fprintf( fp, " .edges = test_edges,\n" ); @@ -2050,7 +2050,14 @@ CXR_API void cxr_free_world( cxr_world *world ) cxr_ab_free( &world->abverts ); cxr_ab_free( &world->absolids ); - free( world->materials ); + + if( world->materials ) + { + for( int i=0; imaterial_count; i++ ) + free( world->materials[i].name ); + + free( world->materials ); + } free( world ); } @@ -2176,6 +2183,13 @@ CXR_API cxr_world *cxr_decompose( cxr_static_mesh *src, i32 *perrcode ) size_t dsize = sizeof(cxr_material) * src->material_count; world->materials = malloc( dsize ); memcpy( world->materials, src->materials, dsize ); + + for( int i=0; imaterial_count; i++ ) + { + world->materials[i].name = malloc(strlen(src->materials[i].name) +1); + strcpy( world->materials[i].name, src->materials[i].name ); + } + world->material_count = src->material_count; } else world->materials = NULL; @@ -2726,7 +2740,7 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, * TODO(harry): Error checking is needed here for bad input data */ - int dispedge[16]; + int dispedge[17]; v2f corner_uvs[4]; int dispedge_count; int disp_count = 0; @@ -3011,7 +3025,7 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, tx = (double)k/(double)(5-1); v3_lerp( lside0, lside1, tx, lref ); v3_muls( verts[grid[index]], ctx->scale, vworld ); - v3_add( ctx->offset, vworld, ctx->offset ); + v3_add( ctx->offset, vworld, vworld ); v3_sub( vworld, lref, vdelta ); v3_copy( vdelta, normals[index] ); @@ -3031,7 +3045,6 @@ static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world, world_corners[side[0]] ); cxr_vdf_kv( output, "material", matptr->name ); - cxr_vdf_kaxis( output, "uaxis", texinfo_shared.uaxis, texinfo_shared.offset[0],