Syntax error fix + partially wrote GltfNode and GltfScene structures. Sometimes I do wonder if writing 'Gltf' look good or not...

This commit is contained in:
Андреев Григорий 2026-02-05 13:15:53 +03:00
parent 1fbd4f0413
commit 09df9f4e2d
7 changed files with 92 additions and 2 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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};
}
// }

View File

@ -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<index into scenes>
*
* scenes "scenes" : Vec<Scene> {
* if "scenes" field is not present, it counts as empty vector }
*
* nodes "nodes" : Vec<Node> {
* 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};
}

View File

@ -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"

View File

@ -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;
}

View File

@ -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"));
}