loader_aw

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

commit 88e888a79ca7cc6a3ebfc6d856bfd8262cded043
parent 71bce8f2ae0d67a8de610251f641e12cfd594c0d
Author: vaplv <vaplv@free.fr>
Date:   Fri, 31 Jan 2020 15:22:45 +0100

Add the test_aw program

Load the obj file submitted on the command line.

Diffstat:
Mcmake/CMakeLists.txt | 3+++
Msrc/aw_obj.c | 6+++++-
Asrc/test_aw.c | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -76,6 +76,9 @@ if(NOT NO_TEST) target_link_libraries(test_aw_mtl aw) add_test(test_aw_mtl test_aw_mtl) rcmake_set_test_runtime_dirs(test_aw_mtl _runtime_dirs) + + add_executable(test_aw ${AW_SOURCE_DIR}/test_aw.c) + target_link_libraries(test_aw aw) endif(NOT NO_TEST) ################################################################################ diff --git a/src/aw_obj.c b/src/aw_obj.c @@ -33,6 +33,10 @@ #pragma warning(disable:4706) /* Assignment within a condition */ #endif +static const char* MSG_PREFIX_INFO = "load-obj:info: "; +static const char* MSG_PREFIX_ERROR = "load-obj:error: "; +static const char* MSG_PREFIX_WARNING = "load-obj:warning: "; + /* Generate the darray_vertex data structure */ #define DARRAY_NAME vertex #define DARRAY_DATA struct aw_obj_vertex @@ -692,7 +696,7 @@ aw_obj_create obj->logger = logger; } else { res = setup_default_logger(obj->allocator, &obj->logger__, - "load-obj:info: ", "load-obj:error: ", "load-obj:warning: "); + MSG_PREFIX_INFO, MSG_PREFIX_ERROR, MSG_PREFIX_WARNING); if(res != RES_OK) goto error; obj->logger = &obj->logger__; } diff --git a/src/test_aw.c b/src/test_aw.c @@ -0,0 +1,63 @@ +/* Copyright (C) 2014-2017, 2020 Vincent Forest (vaplv@free.fr) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "aw.h" + +#include <rsys/clock_time.h> +#include <rsys/mem_allocator.h> + +int +main(int argc, char** argv) +{ + struct aw_obj* obj = NULL; + struct aw_mtl* mtl = NULL; + struct time t0, t1; + struct aw_obj_desc desc; + char buf[128]; + size_t i; + + if(argc < 2) { + fprintf(stderr, "Usage: %s OBJ-FILENAME\n", argv[0]); + return -1; + } + + CHK(aw_obj_create(NULL, &mem_default_allocator, 1, &obj) == RES_OK); + CHK(aw_mtl_create(NULL, &mem_default_allocator, 1, &mtl) == RES_OK); + + time_current(&t0); + CHK(aw_obj_load(obj, argv[1]) == RES_OK); + CHK(aw_obj_get_desc(obj, &desc) == RES_OK); + FOR_EACH(i, 0, desc.mtllibs_count) { + const char* mtllib = NULL; + CHK(aw_obj_get_mtllib(obj, i, &mtllib) == RES_OK); + aw_mtl_load(mtl, mtllib); + } + time_current(&t1); + time_sub(&t0, &t1, &t0); + time_dump(&t0, TIME_MIN|TIME_SEC|TIME_MSEC, NULL, buf, sizeof(buf)); + + fprintf(stdout, "load `%s' in %s\n", argv[1], buf); + fprintf(stdout, "faces count = %lu\n", (unsigned long)desc.faces_count); + fprintf(stdout, "groups count = %lu\n", (unsigned long)desc.groups_count); + fprintf(stdout, "usemtls count = %lu\n", (unsigned long)desc.usemtls_count); + fprintf(stdout, "mtllibs count = %lu\n", (unsigned long)desc.mtllibs_count); + + CHK(aw_obj_ref_put(obj) == RES_OK); + CHK(aw_mtl_ref_put(mtl) == RES_OK); + + CHK(MEM_ALLOCATED_SIZE(&mem_default_allocator) == 0); + CHK(mem_allocated_size() == 0); + return 0; +}