ref: 57373e4d56945d7c8b7ce85becf1440e58e3a604
parent: 6af5bb94f6feedb6c929eb6cafc57da4a1be64bc
author: rodri <rgl@antares-labs.eu>
date: Tue Oct 8 09:24:46 EDT 2024
med: let the user load a model from a file.
--- a/med.c
+++ b/med.c
@@ -797,7 +797,7 @@
void
usage(void)
{
- fprint(2, "usage: %s\n", argv0);
+ fprint(2, "usage: %s [mdlfile]\n", argv0);
exits("usage");
}
@@ -806,13 +806,18 @@
{
Renderer *rctl;
Channel *keyc;
+ char *mdlpath;
+ int fd;
GEOMfmtinstall();
+ mdlpath = nil;
ARGBEGIN{
case 'p': doprof++; break;
default: usage();
}ARGEND;
- if(argc != 0)
+ if(argc == 1)
+ mdlpath = argv[0];
+ else if(argc > 1)
usage();
confproc();
@@ -821,7 +826,16 @@
sysfatal("couldn't find main shader");
scene = newscene(nil);
- model = newmodel();
+ if(mdlpath != nil){
+ fd = open(mdlpath, OREAD);
+ if(fd < 0)
+ sysfatal("open: %r");
+ model = readmodel(fd);
+ if(model == nil)
+ sysfatal("readmodel: %r");
+ close(fd);
+ }else
+ model = newmodel();
subject = newentity("main", model);
scene->addent(scene, subject);