From c5936b5e28c8f81e974bd8d9eb901832921c2b78 Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 6 Feb 2023 00:30:41 -0600 Subject: add kai_read_vertices() --- src/geometry/geometry.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/geometry/geometry.c') diff --git a/src/geometry/geometry.c b/src/geometry/geometry.c index 0bc8602..ea04fd3 100644 --- a/src/geometry/geometry.c +++ b/src/geometry/geometry.c @@ -205,3 +205,56 @@ void kai_release_input(struct ka_input_t i) free(i.source); } + +int kai_read_vertices(struct ka_vertices_t *dest, struct kai_tag_t *src) +{ + CHECK_TAG_TYPE("vertices"); + + char *id = kai_tag_attr_to_dup(src, "id"); + if (id == NULL) { return -1; } + + dest->id = id; + dest->name = kai_tag_attr_to_dup(src, "name"); + + /* count input children */ + int count = 0; + struct kai_tag_t *child; + for (child = src->children; child != NULL; child = child->next) { + if (strcmp(child->type, "input") == 0) { count += 1; } + } + + dest->input_count = count; + dest->input = malloc(count * sizeof(struct ka_input_t)); + if (dest->input == NULL) { + kai_release_vertices(*dest); + return -1; + } + + int i=0; + for (child = src->children; child != NULL; child = child->next) { + if (strcmp(child->type, "input") == 0) { + int result = kai_read_input_unshared(dest->input + i, child); + if (result != 0) { + dest->input_count = i; + kai_release_vertices(*dest); + return -1; + } + i += 1; + } + } + + return 0; +} + +void kai_release_vertices(struct ka_vertices_t v) +{ + free(v.id); + free(v.name); + int i; + for (i=0; i