polyadvent

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

commit 19d6829dbeb93837ea4a977b43949c41b1972a46
parent dc89b8f94e1a66c66e00691a7a121421b4f83c7b
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 21 Jul 2019 15:08:04 -0700

use ply for vertices for now

dae is pretty complicated

Diffstat:
Msrc/dae.c | 13+++++++------
Mtools/compile-model.c | 31+++++++++++++++++++++++++++++--
2 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/src/dae.c b/src/dae.c @@ -263,19 +263,19 @@ static void dae_tagbody(struct xmlparser *x, const char *d, size_t dl) if (data->state == PARSING_JOINT_MATRIX) { parse_joint_matrix(data, d, dl); } - else if (data->state == PARSING_POSITIONS) { + else if (data->geom && data->state == PARSING_POSITIONS) { parse_vertices(data, d, dl); } - else if (data->state == PARSING_WEIGHTS) { + else if (data->geom && data->state == PARSING_WEIGHTS) { parse_weights(data, d, dl); } - else if (data->state == PARSING_NORMALS) { + else if (data->geom && data->state == PARSING_NORMALS) { parse_normals(data, d, dl); } - else if (data->state == PARSING_COLORS) { + else if (data->geom && data->state == PARSING_COLORS) { parse_colors(data, d, dl); } - else if (data->state == PARSING_INDICES) { + else if (data->geom && data->state == PARSING_INDICES) { parse_indices(data, d, dl); } /* else if (data->state == PARSING_TEX_COORDS) { */ @@ -518,7 +518,8 @@ void load_dae(const char *filename, struct model *model, process_joint_children(pose->joints, pose->njoints); } - process_indices(&data); + if (geom) + process_indices(&data); fclose(data.dae_file); } diff --git a/tools/compile-model.c b/tools/compile-model.c @@ -6,6 +6,7 @@ #include "dae.h" #include "debug.h" #include "mdl.h" +#include "ply.h" void usage() @@ -14,6 +15,27 @@ void usage() exit(1); } +// ext len must be 3 +static const char *replace_ext(char *filename, int len, const char *ext) +{ + int replaced = 0; + bool replacing = false; + for (int i = 0; i < len; i++) { + if (replacing) { + if (replaced == 3) { + filename[replaced] = 0; + return filename; + } + filename[i] = ext[replaced++]; + } + else if (filename[i] == '.') { + replacing = true; + } + } + + return NULL; +} + int main(int argc, char *argv[]) { if (argc != 3) @@ -23,16 +45,21 @@ int main(int argc, char *argv[]) init_geometry_manager(); init_model_manager(); - const char *filename = argv[1]; + char *filename = argv[1]; const char *outfile = argv[2]; struct model model; struct mdl_geometry mdl_geom; + struct make_geometry *mkgeom = &mdl_geom.mkgeom; init_model(&model); init_mdl_geometry(&mdl_geom); - load_dae(filename, &model, &mdl_geom.mkgeom); + load_dae(filename, &model, NULL); + replace_ext(filename, strlen(filename), "ply"); + + int ok = parse_ply_with_mkgeom(filename, &mdl_geom); + assert(ok); save_mdl(outfile, &model, &mdl_geom);