summaryrefslogtreecommitdiff
path: root/convmodel.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-01-01 18:43:31 +1100
committerquou <quou@disroot.org>2025-01-01 18:43:31 +1100
commitd26100734623f37063206b9b144c2a29fd71d414 (patch)
tree11aefe54b4110109a841cb656b2f309ee69a1893 /convmodel.c
parent568ba73c71b650f905bd1b3f60f10871316eefdc (diff)
material system
Diffstat (limited to 'convmodel.c')
-rw-r--r--convmodel.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/convmodel.c b/convmodel.c
index 1a09f99..4e7184b 100644
--- a/convmodel.c
+++ b/convmodel.c
@@ -12,6 +12,7 @@
typedef struct {
const char* shader;
+ const char* material;
} Node_Config;
typedef struct Shader_Attrib {
@@ -84,6 +85,17 @@ void parse_node_cfg(const cgltf_node* n, Node_Config* cfg) {
}
i++;
}
+ if (tcmp(json, "material", t)) {
+ cfg->material = read_str(json, &t[1]);
+ if (string_len(cfg->material) > 27) {
+ print_err(
+ "Material name %s too long (max 27 chars).\n",
+ cfg->material
+ );
+ pbreak(3479);
+ }
+ i++;
+ }
}
}
@@ -120,11 +132,11 @@ void read_vertex(
Shader_Attrib* t = target_attribs[i];
if (!t) continue;
int ec = t->size / 4;
- if (a->component_type != cgltf_component_type_r_32f) {
- print_err("Only float attributes are supported.\n");
- pbreak(33);
- }
if (a) {
+ if (a->component_type != cgltf_component_type_r_32f) {
+ print_err("Only float attributes are supported.\n");
+ pbreak(33);
+ }
const cgltf_buffer_view* v = a->buffer_view;
int j, off = t->offset / 4;
int sec = (a->stride / 4);
@@ -233,14 +245,17 @@ void parse_node_mesh(
int i, c = m->primitives_count;
char buf[28];
float matrix[16];
- zero(buf, sizeof buf);
- string_copy(buf, cfg->shader);
vertex_count = 0;
index_count = 0;
for (i = 0; i < c; i++)
parse_prim(&m->primitives[i], desired);
cgltf_node_transform_local(n, matrix);
fwrite("MESH", 4, 1, outfile);
+ zero(buf, sizeof buf);
+ string_copy(buf, cfg->shader);
+ fwrite(buf, 1, sizeof buf, outfile);
+ zero(buf, sizeof buf);
+ string_copy(buf, cfg->material);
fwrite(buf, 1, sizeof buf, outfile);
fwrite(&vertex_size, 4, 1, outfile);
fwrite(&index_count, 4, 1, outfile);
@@ -370,6 +385,13 @@ void parse_node(
);
pbreak(48);
}
+ if (!cfg.material) {
+ print_err(
+ "Node %s has a mesh, but doesn't specify a material.\n",
+ n->name
+ );
+ pbreak(49);
+ }
desired = parse_shader_attribs(cfg.shader);
vertex_size = calc_vertex_size(desired);
current_vertex = arena_alloc(&arena, vertex_size);