commit 3495b827f95a8200e6297fd7fdf7a6aeb1a323b1
parent 1d31ec18b4c3104e64ddb5ae14063c6255ad1e46
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 21 Mar 2025 11:27:11 +0100
Add new feature -r to revert the normals of the output mesh
Diffstat:
4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/mtool.c b/src/mtool.c
@@ -33,6 +33,7 @@ main(int argc, char** argv)
struct sstl* sstl = NULL;
struct sstl_desc desc;
struct sstl_write_data data;
+ size_t i;
int allocator_initialized = 0;
int logger_initialized = 0;
int wbin;
@@ -91,6 +92,13 @@ main(int argc, char** argv)
wbin = (ctx.b ? 1 : (ctx.a ? 0 : desc.read_type == SSTL_BINARY));
ERR(sstl_pack_write_data(sstl, &data));
+ /* Revert normals if requiered */
+ if(ctx.r) {
+ for(i = 0; i < desc.triangles_count; i++) {
+ SWAP(unsigned, desc.indices[3*i], desc.indices[3*i+1]);
+ }
+ }
+
/* Write data */
if(ctx.in != NULL) {
ERR(sstl_write(&data, wbin, ctx.out));
diff --git a/src/mtool_actions.h b/src/mtool_actions.h
@@ -40,13 +40,13 @@ struct actions {
#include <rsys/dynamic_array.h>
struct ctx {
- int a, b, d, h, v, V;
+ int a, b, d, h, r, v, V;
char *in, *out;
struct darray_actions actions;
};
#define CTX_NULL__ \
-{ 0, 0, 0, 0, 0, 0, NULL, NULL, {NULL,0,0,NULL} }
+{ 0, 0, 0, 0, 0, 0, 0, NULL, NULL, {NULL,0,0,NULL} }
res_T
parse_args
diff --git a/src/mtool_args.c b/src/mtool_args.c
@@ -34,7 +34,7 @@ parse_args
{
int opt = 0;
size_t len = 0;
- const char option_list[] = "abdhi:o:S:T:vV:";
+ const char option_list[] = "abdhi:o:rS:T:vV:";
res_T res = RES_OK;
ASSERT(argv && ctx && logger && allocator);
@@ -82,6 +82,10 @@ parse_args
ctx->out = optarg;
break;
+ case 'r':
+ ctx->r = 1;
+ break;
+
case 'S':
{
struct actions action;
diff --git a/src/mtool_utils.c b/src/mtool_utils.c
@@ -54,7 +54,7 @@ log_prt_fn
void
usage(FILE* stream)
{
- fprintf(stream, "mesh-tool [-abdIv] [-S sx,sy,sz]] [-T tx,ty,tz] [-V verbosity_level]\n");
+ fprintf(stream, "mesh-tool [-abdIrv] [-S sx,sy,sz]] [-T tx,ty,tz] [-V verbosity_level]\n");
}
void