polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

compile-model.c (1320B)


      1 
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include <assert.h>
      5 
      6 #include "debug.h"
      7 #include "mdl.h"
      8 #include "ply.h"
      9 
     10 
     11 void usage()
     12 {
     13     printf("usage: compile-model <model.dae> <out.mdl>\n");
     14     exit(1);
     15 }
     16 
     17 // ext len must be 3
     18 static const char *replace_ext(char *filename, int len, const char *ext)
     19 {
     20     int replaced = 0;
     21     bool replacing = false;
     22     for (int i = 0; i < len; i++) {
     23         if (replacing) {
     24             if (replaced == 3) {
     25                 filename[replaced] = 0;
     26                 return filename;
     27             }
     28             filename[i] = ext[replaced++];
     29         }
     30         else if (filename[i] == '.')  {
     31             replacing = true;
     32         }
     33     }
     34 
     35     return NULL;
     36 }
     37 
     38 int main(int argc, char *argv[])
     39 {
     40     if (argc != 3)
     41         usage();
     42 
     43     init_node_manager();
     44     init_geometry_manager();
     45     init_model_manager();
     46 
     47     char *filename = argv[1];
     48     const char *outfile = argv[2];
     49 
     50     struct model model;
     51     struct mdl_geometry mdl_geom;
     52     struct make_geometry *mkgeom = &mdl_geom.mkgeom;
     53 
     54     init_model(&model);
     55     init_mdl_geometry(&mdl_geom);
     56 
     57     /* load_dae(filename, &model, NULL); */
     58     /* replace_ext(filename, strlen(filename), "dae"); */
     59 
     60     int ok = parse_ply_with_mkgeom(filename, &mdl_geom);
     61     assert(ok);
     62 
     63     save_mdl(outfile, &model, &mdl_geom);
     64 
     65     return 0;
     66 }