From 545d3c6c2a053007d1a1b032f9e0359d44a9a358 Mon Sep 17 00:00:00 2001 From: rodri Date: Sat, 28 Sep 2024 11:45:26 +0000 Subject: obj: add more conversion possibilities. this brings back the < in.obj obj >out.mdl mechanic that's so handy for simpler models where there are no textures. --- obj.c | 21 ++++++++++++++++----- readme | 5 ++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/obj.c b/obj.c index a2e5936..7095e58 100644 --- a/obj.c +++ b/obj.c @@ -325,7 +325,7 @@ readobjmodel(char *path) static void usage(void) { - fprint(2, "usage: %s objfile dstdir\n", argv0); + fprint(2, "usage: %s [objfile [dstdir]]\n", argv0); exits("usage"); } @@ -333,17 +333,28 @@ void threadmain(int argc, char *argv[]) { Model *m; + char *infile, *dstdir; ARGBEGIN{ default: usage(); }ARGEND; - if(argc != 2) + if(argc > 2) usage(); - m = readobjmodel(argv[0]); + infile = argc > 0? argv[0]: "/fd/0"; + dstdir = argc == 2? argv[1]: nil; + + m = readobjmodel(infile); if(m == nil) sysfatal("readobjmodel: %r"); - if(exportmodel(argv[1], m) < 0) - sysfatal("exportmodel: %r"); + + if(dstdir == nil){ + if(writemodel(1, m) == 0) + sysfatal("writemodel: %r"); + }else{ + if(exportmodel(dstdir, m) < 0) + sysfatal("exportmodel: %r"); + } + exits(nil); } diff --git a/readme b/readme index a888d60..37d91ac 100644 --- a/readme +++ b/readme @@ -94,12 +94,15 @@ USAGE positions. - obj objfile dir + obj [objfile [dir]] This tool will take a Wavefront OBJ file objfile, with all its materials, and convert it into a model(6) file (see libgraphics/model.6.txt) that's written, along with its assets, inside the directory dir. + If no dir is specified, it writes the model(6) to stdout. And if no + arguments are given, it reads the OBJ file from stdin. + CUBEMAPS The skyboxes for vis and solar are stored in the cubemap/ folder. To use -- cgit v1.2.3