From 09df9f4e2d91656414c4104c31cf62d6ff30d1c8 Mon Sep 17 00:00:00 2001 From: Andreew Gregory Date: Thu, 5 Feb 2026 13:15:53 +0300 Subject: [PATCH] Syntax error fix + partially wrote GltfNode and GltfScene structures. Sometimes I do wonder if writing 'Gltf' look good or not... --- src/l1/anne/codegen.c | 2 ++ src/l1/anne/gltf_structures.h | 10 ++++++++++ src/l1_5/core/quaternion.h | 2 +- src/l2/alice/model_file.h | 30 ++++++++++++++++++++++++++++++ src/l2/core/glb_file.h | 28 ++++++++++++++++++++++++++++ src/l2/core/json.h | 20 ++++++++++++++++++++ src/l3/r4/r4.c | 2 +- 7 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 src/l1/anne/gltf_structures.h diff --git a/src/l1/anne/codegen.c b/src/l1/anne/codegen.c index 19a20d1..832b627 100644 --- a/src/l1/anne/codegen.c +++ b/src/l1/anne/codegen.c @@ -15,6 +15,7 @@ #include "lucy.h" #include "alice.h" #include "precise_integers.h" +#include "gltf_structures.h" int main() { mkdir_nofail("l1"); @@ -33,6 +34,7 @@ int main() { generate_l1_lucy_headers(); generate_code_for_alice_on_l1(); generate_l1_header_for_precise_integers(); + generate_l1_gltf_headers(); finish_layer(cstr("l1")); return 0; } diff --git a/src/l1/anne/gltf_structures.h b/src/l1/anne/gltf_structures.h new file mode 100644 index 0000000..ca9a4c3 --- /dev/null +++ b/src/l1/anne/gltf_structures.h @@ -0,0 +1,10 @@ +#pragma once +/* This file covers codegen for GLTF structures (that represent GLTF objects in memory) */ + +#include "../codegen/util_template_inst.h" + +void generate_l1_gltf_headers() { + SpanU8 l = cstr("l1"), ns = cstr(""); + generate_eve_span_company_for_non_primitive_non_clonable(l, ns, cstr("GltfScene"), true, false); + generate_eve_span_company_for_non_primitive_non_clonable(l, ns, cstr("GltfNode"), true, false); +} diff --git a/src/l1_5/core/quaternion.h b/src/l1_5/core/quaternion.h index 320dae9..448dd3b 100644 --- a/src/l1_5/core/quaternion.h +++ b/src/l1_5/core/quaternion.h @@ -59,4 +59,4 @@ mat3 unit_quaternion_fl_to_rot3d_mat3(vec4 q){ // e_vc = sinf(t *fi) / qva; // } // return (vec4){e_x, e_vc * q.y, e_vc * q.z, e_vc * q.w}; -} +// } diff --git a/src/l2/alice/model_file.h b/src/l2/alice/model_file.h index 2cc620f..da523e7 100644 --- a/src/l2/alice/model_file.h +++ b/src/l2/alice/model_file.h @@ -6,6 +6,7 @@ #include "../../l1/system/fileio.h" #include "assets.h" #include "stdalign.h" +#include "../core/glb_file.h" static_assert(sizeof(float) == 4, "..."); static_assert(sizeof(GenericMeshVertexInc) == 4 * (3 + 2), "..."); @@ -237,3 +238,32 @@ GenericMeshTopology alice_expect_read_generic_mesh_from_obj_file(VecU8 file_path OptionGenericMeshTopology option = alice_read_generic_mesh_from_obj_file(file_path); return OptionGenericMeshTopology_expect(option); } + +/* Temporary function for some experiments. Will rewrite/delete later */ +GenericMeshTopology alice_expect_read_generic_mesh_from_glb_file(VecU8 file_path) { + GLBFileSegments segments; + int code = glb_file_get_segments(VecU8_to_span(&file_path), &segments); + if (code) { + abortf("Something went wrong when reading glb container\n"); + } + + /* default_scene "scene" : Option + * + * scenes "scenes" : Vec { + * if "scenes" field is not present, it counts as empty vector } + * + * nodes "nodes" : Vec { + * if "nodes" field is not present, it counts as empty vector } + */ + + OptionU32 default_scene = None_U32(); + + + + VecU8_print(VecU8_fmt("default_scene: %v\n", + default_scene.variant == Option_None ? vcstr("None") : U64_stringification(default_scene.some))); + + VecGenericMeshVertexInc vertices = VecGenericMeshVertexInc_new(); + VecU32 indexes = VecU32_new(); + return (GenericMeshTopology){.vertices = vertices, .indexes = indexes}; +} \ No newline at end of file diff --git a/src/l2/core/glb_file.h b/src/l2/core/glb_file.h index 245d472..0ae1cee 100644 --- a/src/l2/core/glb_file.h +++ b/src/l2/core/glb_file.h @@ -1,6 +1,9 @@ #pragma once #include "json_encoded.h" +#include "../../../gen/l1/VecAndSpan_U64.h" +#include "../../../gen/l1/OptionU32.h" +#include "../../l1_5/core/quaternion.h" /* todo: add big endian support */ @@ -71,3 +74,28 @@ int glb_file_get_segments(SpanU8 file, GLBFileSegments* ret){ *ret = (GLBFileSegments){.version = version, .gltf = parsed_json.some, .bin_segment = bin_segment}; return 0; } + +typedef struct { + VecU8 name; + VecU64 nodes; +} GltfScene; + +void GltfScene_drop(GltfScene self) { + VecU8_drop(self.name); + VecU64_drop(self.nodes); +} + +#include "../../../gen/l1/eve/VecGltfScene.h" + +typedef struct { + VecU8 name; + VecU64 children; + OptionU32 mesh; +} GltfNode; + +void GltfNode_drop(GltfNode self) { + VecU8_drop(self.name); + VecU64_drop(self.children); +} + +#include "../../../gen/l1/eve/VecGltfNode.h" diff --git a/src/l2/core/json.h b/src/l2/core/json.h index c914702..cc7f07d 100644 --- a/src/l2/core/json.h +++ b/src/l2/core/json.h @@ -92,3 +92,23 @@ Json Json_from_MapVecU8ToJson(json_dictionary_t dict){ // Bonus #include "../../../gen/l1/eve/OptionJson.h" + +// todo: implement _find method in RBTREE template (yes, I WILL do it eventually) +/* Returns nullptr if there is no such field or object is not an */ +const Json* Json_dict_at(const Json* self, SpanU8 key) { + if (self->variant != Json_dict) + return NULL; + const json_dictionary_t* d = &self->dict; + RBTreeNode* cur = d->root; + while (cur != d->NIL) { + RBTreeNode_KVPVecU8ToJson* n = (RBTreeNode_KVPVecU8ToJson*)cur; + if (SpanU8_less_SpanU8(VecU8_to_span(&n->key), key)) { + cur = cur->left; + } else if (SpanU8_less_SpanU8(key, VecU8_to_span(&n->key))) { + cur = cur->right; + } else { + return &n->value; + } + } + return NULL; +} diff --git a/src/l3/r4/r4.c b/src/l3/r4/r4.c index cd49d1f..c803dda 100644 --- a/src/l3/r4/r4.c +++ b/src/l3/r4/r4.c @@ -403,5 +403,5 @@ void run_app(){ } int main(){ - run_app(); + alice_expect_read_generic_mesh_from_glb_file(vcstr("./src/l3/models/skeleton.glb")); }