loader_aw

Load OBJ/MTL file formats
git clone git://git.meso-star.fr/loader_aw.git
Log | Files | Refs | README | LICENSE

test_aw.c (2161B)


      1 /* Copyright (C) 2014-2017, 2020-2023 Vincent Forest (vaplv@free.fr)
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU Lesser General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU Lesser General Public License
     14  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #include "aw.h"
     17 
     18 #include <rsys/clock_time.h>
     19 #include <rsys/mem_allocator.h>
     20 
     21 int
     22 main(int argc, char** argv)
     23 {
     24   struct aw_obj* obj = NULL;
     25   struct aw_mtl* mtl = NULL;
     26   struct time t0, t1;
     27   struct aw_obj_desc desc;
     28   char buf[128];
     29   size_t i;
     30 
     31   if(argc < 2) {
     32     fprintf(stderr, "Usage: %s OBJ-FILENAME\n", argv[0]);
     33     return -1;
     34   }
     35 
     36   CHK(aw_obj_create(NULL, &mem_default_allocator, 1, &obj) == RES_OK);
     37   CHK(aw_mtl_create(NULL, &mem_default_allocator, 1, &mtl) == RES_OK);
     38 
     39   time_current(&t0);
     40   CHK(aw_obj_load(obj, argv[1]) == RES_OK);
     41   CHK(aw_obj_get_desc(obj, &desc) == RES_OK);
     42   FOR_EACH(i, 0, desc.mtllibs_count) {
     43     const char* mtllib = NULL;
     44     CHK(aw_obj_get_mtllib(obj, i, &mtllib) == RES_OK);
     45     aw_mtl_load(mtl, mtllib);
     46   }
     47   time_current(&t1);
     48   time_sub(&t0, &t1, &t0);
     49   time_dump(&t0, TIME_MIN|TIME_SEC|TIME_MSEC, NULL, buf, sizeof(buf));
     50 
     51   fprintf(stdout, "load `%s' in %s\n", argv[1], buf);
     52   fprintf(stdout, "faces count   = %lu\n", (unsigned long)desc.faces_count);
     53   fprintf(stdout, "groups count  = %lu\n", (unsigned long)desc.groups_count);
     54   fprintf(stdout, "usemtls count = %lu\n", (unsigned long)desc.usemtls_count);
     55   fprintf(stdout, "mtllibs count = %lu\n", (unsigned long)desc.mtllibs_count);
     56 
     57   CHK(aw_obj_ref_put(obj) == RES_OK);
     58   CHK(aw_mtl_ref_put(mtl) == RES_OK);
     59 
     60   CHK(MEM_ALLOCATED_SIZE(&mem_default_allocator) == 0);
     61   CHK(mem_allocated_size() == 0);
     62   return 0;
     63 }