From 6722ef01e34f75bde72ba29e3279c0d1df030593 Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 11 Feb 2023 19:46:23 -0600 Subject: add materials and images processing --- src/material/CMakeLists.txt | 3 ++ src/material/material.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ src/material/material.h | 16 ++++++++++ 3 files changed, 96 insertions(+) create mode 100644 src/material/CMakeLists.txt create mode 100644 src/material/material.c create mode 100644 src/material/material.h (limited to 'src/material') diff --git a/src/material/CMakeLists.txt b/src/material/CMakeLists.txt new file mode 100644 index 0000000..b5941da --- /dev/null +++ b/src/material/CMakeLists.txt @@ -0,0 +1,3 @@ +project(kalmia) + +target_sources(kalmia PUBLIC material.c) diff --git a/src/material/material.c b/src/material/material.c new file mode 100644 index 0000000..65e13d2 --- /dev/null +++ b/src/material/material.c @@ -0,0 +1,77 @@ +#include +#include "util/util.h" +#include "xml/xml.h" + + +int kai_read_instance_effect(struct ka_instance_effect_t *dest, struct kai_tag_t *src) +{ + KAI_CHECK_TAG_TYPE("instance_effect"); + + char *url = kai_tag_attr_to_dup(src, "url"); + if (url == NULL) { return -1; } + + dest->sid = kai_tag_attr_to_dup(src, "sid"); + dest->name = kai_tag_attr_to_dup(src, "name"); + dest->url = url; + + return 0; +} + +void kai_release_instance_effect(struct ka_instance_effect_t i) +{ + free(i.sid); + free(i.name); + free(i.url); +} + + +int kai_read_material(struct ka_material_t *dest, struct kai_tag_t *src) +{ + KAI_CHECK_TAG_TYPE("material"); + + struct kai_tag_t *child = kai_tag_get_first_child_with_type(src, "instance_effect"); + if (child == NULL) { return -1; } + int result = kai_read_instance_effect(&(dest->instance_effect), child); + if (result != 0) { return -1; } + + dest->id = kai_tag_attr_to_dup(src, "id"); + dest->name = kai_tag_attr_to_dup(src, "name"); + + return 0; +} + +void kai_release_material(struct ka_material_t m) +{ + free(m.id); + free(m.name); + kai_release_instance_effect(m.instance_effect); +} + + +int kai_read_library_materials(struct ka_library_materials_t *dest, struct kai_tag_t *src) +{ + int result; + KAI_FILL_ARRAY_FROM_TAGS( + result, + dest->material, dest->material_count, struct ka_material_t, + src, "material", + kai_read_material, kai_release_material + ); + if (result != 0) { return -1; } + + dest->id = kai_tag_attr_to_dup(src, "id"); + dest->name = kai_tag_attr_to_dup(src, "name"); + + return 0; +} + +void kai_release_library_materials(struct ka_library_materials_t l) +{ + free(l.id); + free(l.name); + int i; + for (i=0; i +#include "xml/xml.h" + +int kai_read_instance_effect(struct ka_instance_effect_t *dest, struct kai_tag_t *src); +void kai_release_instance_effect(struct ka_instance_effect_t i); + +int kai_read_material(struct ka_material_t *dest, struct kai_tag_t *src); +void kai_release_material(struct ka_material_t m); + +int kai_read_library_materials(struct ka_library_materials_t *dest, struct kai_tag_t *src); +void kai_release_library_materials(struct ka_library_materials_t l); + +#endif -- cgit v1.2.1