ref: 545d3c6c2a053007d1a1b032f9e0359d44a9a358
parent: 1af782b52c796fd341621b0c9de2dea3a1c7c660
author: rodri <[email protected]>
date: Sat Sep 28 07:45:26 EDT 2024
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.
--- a/obj.c
+++ b/obj.c
@@ -325,7 +325,7 @@
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 @@
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);
}
--- a/readme
+++ b/readme
@@ -94,11 +94,14 @@
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