From 902256324777a78fea430cd36b134391accc0618 Mon Sep 17 00:00:00 2001 From: gbrochar Date: Fri, 4 Oct 2024 18:22:49 +0200 Subject: [PATCH] stuff --- inc/scop.h | 3 ++- resources/test.obj | 9 +++++++++ src/parse_line.c | 19 +++++++++++++------ src/parse_token.c | 4 +++- 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 resources/test.obj diff --git a/inc/scop.h b/inc/scop.h index 04b851c..d5a5e33 100644 --- a/inc/scop.h +++ b/inc/scop.h @@ -37,7 +37,8 @@ enum e_gl_buf_type { UV, NORMAL, INDEX, - OTHER + OTHER, + INVALID }; typedef struct s_cam t_cam; diff --git a/resources/test.obj b/resources/test.obj new file mode 100644 index 0000000..af2ef42 --- /dev/null +++ b/resources/test.obj @@ -0,0 +1,9 @@ +v -10 -10 -10 +v 10 10 10 +v 0 0 0 +v 30 30 30 +v -20 10 30 +f 1 2 3 +f 1 2 4 +f 3 2 4 +f 1 3 5 diff --git a/src/parse_line.c b/src/parse_line.c index baaa858..8534b46 100644 --- a/src/parse_line.c +++ b/src/parse_line.c @@ -6,7 +6,7 @@ /* By: gbrochar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/22 18:41:28 by gbrochar #+# #+# */ -/* Updated: 2020/12/23 21:15:54 by gbrochar ### ########.fr */ +/* Updated: 2024/10/04 18:09:40 by gbrochar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,15 @@ t_gl_buf_type parse_gl_buf_type(char *token) return (NORMAL); if (strcmp(token, "f") == SUCCESS) return (INDEX); - return (OTHER); + if (strcmp(token, "#") == SUCCESS + || strcmp(token, "l") == SUCCESS + || strcmp(token, "o") == SUCCESS + || strcmp(token, "mtllib") == SUCCESS + || strcmp(token, "s") == SUCCESS + || strcmp(token, "g") == SUCCESS + || strcmp(token, "usemtl") == SUCCESS) + return (OTHER); + return INVALID; } void parse_append_data_tmp( @@ -91,11 +99,11 @@ void parse_triangulate2(t_buf_ui *indices, int vertex_count) void parse_triangulate_dispatcher(t_env *e, int vertex_count) { if (e->object.properties & VERTEX_FLAG) - parse_triangulate(&(e->object.vertices_indices), vertex_count); + parse_triangulate(&(e->object.vertices_indices), vertex_count); if (e->object.properties & UV_FLAG) - parse_triangulate2(&(e->object.uvs_indices), vertex_count); + parse_triangulate2(&(e->object.uvs_indices), vertex_count); if (e->object.properties & NORMAL_FLAG) - parse_triangulate(&(e->object.normals_indices), vertex_count); + parse_triangulate(&(e->object.normals_indices), vertex_count); } void strtrim(char *line) { @@ -129,7 +137,6 @@ int parse_line(t_env *e, char *line) token_count++; } if (gl_buf_type == INDEX && token_count > 4) { - //printf("spongebob squared face\n"); parse_triangulate_dispatcher(e, token_count - 1); } return (SUCCESS); diff --git a/src/parse_token.c b/src/parse_token.c index 085b07b..cb3b77a 100644 --- a/src/parse_token.c +++ b/src/parse_token.c @@ -6,7 +6,7 @@ /* By: gbrochar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/23 17:33:33 by gbrochar #+# #+# */ -/* Updated: 2024/04/25 16:33:25 by gbrochar ### ########.fr */ +/* Updated: 2024/10/04 17:47:15 by gbrochar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,6 +71,8 @@ int parse_token( if (gl_buf_type == OTHER) ret = BREAK; + if (gl_buf_type == INVALID) + ret = FAILURE; if (gl_buf_type == VERTEX) ret = parse_append_data_d(&(e->object.vertices), token); if (gl_buf_type == UV && token_count < 3)