diff options
| author | tech kaczynski <tk@techkaczynski.dev> | 2026-11-02 03:23:17 +1000 |
|---|---|---|
| committer | tech kaczynski <tk@techkaczynski.dev> | 2026-11-02 03:23:17 +1000 |
| commit | b47b2e022bfa74cd94d3296aae6bd34ca4afff02 (patch) | |
| tree | 5fa05b743289e1ab877a85c1bf1874be2736f04f /editor.c | |
| parent | 040a896cb98963c74916c0b833efa9df2ef965e3 (diff) | |
new shaders for foliage, new material settings, added lots of assets.
Diffstat (limited to 'editor.c')
| -rw-r--r-- | editor.c | 113 |
1 files changed, 106 insertions, 7 deletions
@@ -76,12 +76,14 @@ static struct { } command_menu; static const cstr material_shader_keys[] = { - "model", - "model_cutoff" + "default", + "alpha_cutoff", + "alpha_cutoff_nocull", + "foliage", }; static const char material_shader_labels[] = - "Model;Model (cutoff)"; + "default;alpha_cutoff;alpha_cutoff_nocull;foliage"; /* forward decl */ static bool selection_root(Entity *ent); @@ -613,13 +615,19 @@ action_commit(EditorAction *action) { changed |= strcmp(a->tex_key ? a->tex_key : "", b->tex_key ? - b->tex_key : "") != 0; + b->tex_key : + "") != 0; changed |= strcmp(a->shader_key ? a->shader_key : "", b->shader_key ? b->shader_key : "") != 0; + + changed |= a->uv_scale.x != b->uv_scale.x || + a->uv_scale.y != b->uv_scale.y || + a->uv_offset.x != b->uv_offset.x || + a->uv_offset.y != b->uv_offset.y; } } break; @@ -875,7 +883,9 @@ editor_update(void) { /* sorry about the indentation :^) */ switch (ed.interact) { case ED_INTERACT_NONE: - if (!ed.focus_captured && IsKeyPressed(KEY_SPACE)) { + if (!ed.focus_captured && + ed.mode == ED_MODE_SCENE && + IsKeyPressed(KEY_SPACE)) { ed.panel[ED_PNL_CENTER].type = ED_PNL_TYPE_SPACE; ed.panel[ED_PNL_CENTER].enabled = true; } @@ -2909,7 +2919,7 @@ panel_properties(EditorPanelContainer container, bool input) { } group.y = next_y; - group.height = material_count ? 170 : 80; + group.height = material_count ? 230 : 80; GuiGroupBox(group, "Model"); row = (Rect){ @@ -3035,7 +3045,7 @@ panel_properties(EditorPanelContainer container, bool input) { row.x, row.y, 64, row.height }, "Shader"); - cstr shader_key = "model"; + cstr shader_key = "default"; if ((u32)mat_idx < model->mat_cnt) { cstr key = model->materials[mat_idx].shader_key; @@ -3057,6 +3067,90 @@ panel_properties(EditorPanelContainer container, bool input) { shader_bounds = control; shader_visible = true; + Vec2 uv[2] = { + {1, 1}, + {0, 0}, + }; + + if ((u32)mat_idx < model->mat_cnt) { + uv[0] = model->materials[mat_idx].uv_scale; + uv[1] = model->materials[mat_idx].uv_offset; + } + + cstr uv_labels[2] = {"Tiling", "Offset"}; + + for (int i = 0; i < 2; ++i) { + row.y += 30; + + GuiLabel((Rect){ + row.x, row.y, 64, row.height + }, uv_labels[i]); + + f32 width = control.width / 2; + f32 *values[2] = {&uv[i].x, &uv[i].y}; + + for (int axis = 0; axis < 2; ++axis) { + Rect box = { + control.x + axis * width, + row.y, + width - 4, + row.height, + }; + + f32 value = *values[axis]; + + if (!panel_float(&edit, box, &value, false)) { + continue; + } + + if (!isfinite(value) || value == *values[axis]) { + continue; + } + + EditorAction action = + action_begin(ED_ACTION_MODEL, false); + + if ((u32)mat_idx >= model->mat_cnt) { + u32 count = material_count; + MaterialOverride *materials; + + materials = realloc(model->materials, + count * sizeof(*materials)); + + if (!materials) { + perror("material UV: alloc failed."); + exit(1); + } + + memset(materials + model->mat_cnt, 0, + (count - model->mat_cnt) * + sizeof(*materials)); + + for (u32 j = model->mat_cnt; j < count; ++j) { + materials[j].uv_scale = (Vec2){1, 1}; + } + + model->materials = materials; + model->mat_cnt = count; + } + + MaterialOverride *material; + material = &model->materials[mat_idx]; + + Vec2 *target = i == 0 ? + &material->uv_scale : &material->uv_offset; + + if (axis == 0) { + target->x = value; + } else { + target->y = value; + } + + *values[axis] = value; + action_commit(&action); + } + } + model_end: next_y = group.y + group.height + pad + 20 + 16; @@ -3378,10 +3472,15 @@ editor_set_material(cstr key, u32 mat_idx, MaterialProperty prop) { (count - model->mat_cnt) * sizeof(*materials)); + for (u32 i = model->mat_cnt; i < count; ++i) { + materials[i].uv_scale = (Vec2){1, 1}; + } + model->materials = materials; model->mat_cnt = count; } + MaterialOverride *material; material = &model->materials[mat_idx]; |
