star-meshtool

Mesh transformation
git clone git://git.meso-star.fr/star-meshtool.git
Log | Files | Refs | README | LICENSE

commit 5533fc9565670009bac3f364528ef9d9c87cc5d0
parent c7b3656e27de08966ebab27230599a0cbfa76e7e
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri, 14 Mar 2025 15:51:53 +0100

Add new features; -d -Sx,y,z

Add -d to get file description.
Add -Sx,y,z to apply a scale operation to the geometry.

Diffstat:
Msrc/mtool.c | 6++++++
Msrc/mtool_actions.c | 6++++++
Msrc/mtool_actions.h | 8+++++---
Msrc/mtool_args.c | 27++++++++++++++++++++++++---
Msrc/mtool_utils.c | 24+++++++++++++++++++++++-
Msrc/mtool_utils.h | 6++++++
6 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/src/mtool.c b/src/mtool.c @@ -78,6 +78,12 @@ main(int argc, char** argv) /* Get access to data */ ERR(sstl_get_desc(sstl, &desc)); + /* If description requested, print it and quit */ + if(ctx.d) { + if(ctx.d) print_description(&desc); + goto end; + } + /* Apply specified actions */ ERR(apply_actions(&ctx, &desc)); diff --git a/src/mtool_actions.c b/src/mtool_actions.c @@ -48,6 +48,12 @@ apply_actions(const struct ctx* ctx, struct sstl_desc* desc) const struct actions* action = darray_actions_cdata_get(&ctx->actions) + a; size_t i; switch(action->type) { + case SCALE: + for(i = 0; i < desc->vertices_count; i++) { + f3_mul(desc->vertices+i*3, action->what.scale, desc->vertices+3*i); + } + break; + case TRANSLATION: for(i = 0; i < desc->vertices_count; i++) { f3_add(desc->vertices+i*3, action->what.translation, desc->vertices+3*i); diff --git a/src/mtool_actions.h b/src/mtool_actions.h @@ -23,12 +23,14 @@ struct logger; struct sstl_desc; enum action_type { + SCALE, TRANSLATION }; struct actions { enum action_type type; union { + float scale[3]; float translation[3]; } what; }; @@ -38,13 +40,13 @@ struct actions { #include <rsys/dynamic_array.h> struct ctx { - int a, b, h, v, V; - char *i, *o; + int a, b, d, h, v, V; + char *in, *out; struct darray_actions actions; }; #define CTX_NULL__ \ -{ 0, 0, 0, 0, 0, NULL, NULL, {NULL,0,0,NULL} } +{ 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[] = "abhi:o:T:vV:"; + const char option_list[] = "abdhi:o:S:T:vV:"; res_T res = RES_OK; ASSERT(argv && ctx && logger && allocator); @@ -66,18 +66,39 @@ parse_args ctx->b = 1; break; + case 'd': + ctx->d = 1; + break; + case 'h': ctx->h = 1; break; case 'i': - ctx->i = optarg; + ctx->in = optarg; break; case 'o': - ctx->o = optarg; + ctx->out = optarg; break; + case 'S': + { + struct actions action; + res = cstr_to_list_float(optarg, ',', action.what.scale, &len, 3); + if(res != RES_OK + || len != 3) + { + logger_print(logger, LOG_ERROR, + "Error parsing translation: `%s'\n", optarg); + if(res == RES_OK) res = RES_BAD_ARG; + goto error; + } + action.type = SCALE; + ERR(darray_actions_push_back(&ctx->actions, &action)); + break; + } + case 'T': { struct actions action; diff --git a/src/mtool_utils.c b/src/mtool_utils.c @@ -20,6 +20,7 @@ #include <rsys/mem_allocator.h> #include <rsys/logger.h> #include <rsys/rsys.h> +#include <rsys/float3.h> #include <stdio.h> @@ -53,7 +54,7 @@ log_prt_fn void usage(FILE* stream) { - fprintf(stream, "mesh-tool [-abhv] [-T tx,ty,tz] [-V verbosity_level]\n"); + fprintf(stream, "mesh-tool [-abdIv] [-S sx,sy,sz]] [-T tx,ty,tz] [-V verbosity_level]\n"); } void @@ -65,3 +66,24 @@ print_version "mesh-tool version %i.%i.%i\n", MTOOL_VERSION_MAJOR, MTOOL_VERSION_MINOR, MTOOL_VERSION_PATCH); } + +void +print_description + (struct sstl_desc* desc) +{ + size_t i; + float minb[3], maxb[3]; + f3_splat(minb, FLT_MAX); + f3_splat(maxb, -FLT_MAX); + for(i = 0; i < desc->vertices_count; i++) { + f3_min(minb, minb, desc->vertices+3*i); + f3_max(maxb, maxb, desc->vertices+3*i); + } + fprintf(stderr, + "Type: %s, Vertice count: %ld, Triangle count: %ld\n" + "Xrange: [%g %g], Yrange: [%g %g], Zrange: [%g %g]\n", + (desc->read_type == SSTL_ASCII ? "ACII" : "BINARY"), + desc->vertices_count, desc->triangles_count, + minb[0], maxb[0], minb[1], maxb[1], minb[2], maxb[2]); +} + diff --git a/src/mtool_utils.h b/src/mtool_utils.h @@ -18,6 +18,8 @@ #include <stdio.h> +struct sstl_desc; + /* Utility macros */ #define ERR(Expr) if((res = (Expr)) != RES_OK) goto error; else (void)0 @@ -40,4 +42,8 @@ void print_version (FILE* stream); +void +print_description + (struct sstl_desc* desc); + #endif /* MTOOL_UTILS_H */