projects
/
convexer.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
first windows distributions
[convexer.git]
/
cxr
/
cxr.h
diff --git
a/cxr/cxr.h
b/cxr/cxr.h
index 9f11096925ab8b105784ec411a5ced306951b39b..0585f1a240bcc66165bb3a1081844734eab2a04a 100644
(file)
--- a/
cxr/cxr.h
+++ b/
cxr/cxr.h
@@
-1,11
+1,13
@@
/*
/*
- CONVEXER v0.9
+ CONVEXER v0.9
5
A GNU/Linux-first Source1 Hammer replacement
built with Blender, for mapmakers
Copyright (C) 2022 Harry Godden (hgn)
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
Features:
- Brush decomposition into convex pieces for well defined geometry
- Freely form displacements without limits
@@
-13,7
+15,8
@@
- Compile models and model groups easily
- It runs at an ok speed!
- Light patch BSP files; remove unwanted realtime effects
- Compile models and model groups easily
- It runs at an ok speed!
- Light patch BSP files; remove unwanted realtime effects
- - Fastest VTF compressor (thanks to Richgel999 and stb)
+ - Bestest VTF compressor (thanks to Richgel999 and stb)
+ - Pack content automatically
Program structure:
Program structure:
@@
-98,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;
#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 */
typedef struct cxr_vmf_context cxr_vmf_context;
#endif /* CXR_VALVE_MAP_FILE */
@@
-241,6
+245,11
@@
struct cxr_texinfo
double winding;
};
double winding;
};
+struct cxr_visgroup
+{
+ const char *name;
+};
+
/*
* Simplified VDF writing interface. No allocations or nodes, just write to file
*/
/*
* Simplified VDF writing interface. No allocations or nodes, just write to file
*/
@@
-258,10
+267,14
@@
struct cxr_vmf_context
*detailvbsp,
*detailmaterial;
*detailvbsp,
*detailmaterial;
+ cxr_visgroup *visgroups;
+ i32 visgroup_count;
+
/* Transform settings */
double scale;
v3f offset;
/* Transform settings */
double scale;
v3f offset;
- i32 lightmap_scale;
+ i32 lightmap_scale,
+ visgroupid;
/* Current stats */
i32 brush_count,
/* Current stats */
i32 brush_count,
@@
-279,7
+292,8
@@
enum cxr_soliderr
k_soliderr_degenerate_implicit,
k_soliderr_non_coplanar_vertices,
k_soliderr_non_convex_poly,
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
};
/*
};
/*
@@
-291,6
+305,13
@@
enum cxr_soliderr
const char *cxr_build_time = __DATE__ " @" __TIME__;
#endif
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 );
static void (*cxr_log_func)(const char *str);
static void (*cxr_line_func)( v3f p0, v3f p1, v4f colour );
@@
-1335,10
+1356,10
@@
static void cxr_link_manifold(
int init_reverse = 0;
int unique_edge_count = 0;
int init_reverse = 0;
int unique_edge_count = 0;
- int discard_splits = 1;
/* Try remove splitting faces first */
{
/* Try remove splitting faces first */
{
+ int split_total = 0;
for( int j=0; j<solid->count; j++ )
{
cxr_polygon *poly = &mesh->polys[ solid_buffer[solid->start+j] ];
for( int j=0; j<solid->count; j++ )
{
cxr_polygon *poly = &mesh->polys[ solid_buffer[solid->start+j] ];
@@
-1359,19
+1380,16
@@
static void cxr_link_manifold(
}
if( interior_count < poly->loop_total-1 )
}
if( interior_count < poly->loop_total-1 )
+ {
+ split_total ++;
continue;
continue;
+ }
temp_solid[ temp_solid_len ++ ] = solid_buffer[solid->start+j];
}
temp_solid[ temp_solid_len ++ ] = solid_buffer[solid->start+j];
}
- if( temp_solid_len < 3 )
+ if( temp_solid_len < 3
|| (split_total & 0x2) /* unkown reasons */
)
{
{
- /* Revert back to normal */
- free( temp_solid );
-
- temp_solid = &solid_buffer[ solid->start ];
- temp_solid_len = solid->count;
- discard_splits = 0;
}
else
{
}
else
{
@@
-1382,8
+1400,7
@@
static void cxr_link_manifold(
solid->count = temp_solid_len;
}
solid->count = temp_solid_len;
}
- if( discard_splits )
- free( temp_solid );
+ free( temp_solid );
}
for( int j=0; j<solid->count; j++ )
}
for( int j=0; j<solid->count; j++ )
@@
-2281,6
+2298,16
@@
CXR_API void cxr_free_tri_mesh( cxr_tri_mesh *mesh )
CXR_API cxr_world *cxr_decompose( cxr_static_mesh *src, i32 *perrcode )
{
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) );
u32 error = 0x00;
cxr_world *world = malloc( sizeof(*world) );
@@
-2952,6
+2979,8
@@
static int cxr_write_disp( cxr_mesh *mesh, cxr_world *world,
if( !newvert )
{
if( !newvert )
{
+ free( graph );
+ free( vertinfo );
return 0;
}
}
return 0;
}
}
@@
-3014,9
+3043,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;
free( graph );
free( vertinfo );
return 0;
@@
-3068,6
+3094,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, 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 */
}
/* Create world coordinates */
@@
-3231,7
+3259,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_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 );
cxr_vdf_ki32( output, "visgroupshown",1);
cxr_vdf_ki32( output, "visgroupautoshown",1);
cxr_vdf_edon( output );
@@
-3261,6
+3290,15
@@
CXR_API void cxr_begin_vmf( cxr_vmf_context *ctx, cxr_vdf *output )
cxr_vdf_edon( output );
cxr_vdf_node( output, "visgroups" );
cxr_vdf_edon( output );
cxr_vdf_node( output, "visgroups" );
+
+ for( int i=0; i<ctx->visgroup_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" );
cxr_vdf_edon( output );
cxr_vdf_node( output, "viewsettings" );
@@
-3306,7
+3344,10
@@
CXR_API void cxr_push_world_vmf( cxr_world *world, cxr_vmf_context *ctx,
if( solid->displacement )
{
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;
}
continue;
}
@@
-3365,6
+3406,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_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 );
cxr_vdf_ki32( output, "visgroupshown", 1 );
cxr_vdf_ki32( output, "visgroupautoshown", 1 );
cxr_vdf_edon( output );