paint: merge minic_api
This commit is contained in:
+60
-14
@@ -1,9 +1,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "engine.h"
|
||||
#include "enums.h"
|
||||
#include "iron_draw.h"
|
||||
#include "iron_obj.h"
|
||||
#include "iron_ui.h"
|
||||
#include "types.h"
|
||||
#include <iron.h>
|
||||
|
||||
f32 ui_MENUBAR_H(ui_t *ui);
|
||||
f32 ui_nodes_INPUT_Y(ui_node_canvas_t *canvas, ui_node_t *node, i32 pos);
|
||||
@@ -116,13 +119,6 @@ void config_load_theme(char *theme, bool tag_redraw);
|
||||
void config_enable_plugin(char *f);
|
||||
void config_disable_plugin(char *f);
|
||||
bool config_is_iphone();
|
||||
physics_body_t *physics_body_create();
|
||||
void physics_body_init(physics_body_t *body, object_t *obj);
|
||||
void physics_body_remove(physics_body_t *body);
|
||||
void physics_body_set_mass(physics_body_t *body, f32 mass);
|
||||
void physics_body_apply_impulse(physics_body_t *body, vec4_t dir);
|
||||
void physics_body_sync_transform(physics_body_t *body);
|
||||
void physics_body_update(physics_body_t *body);
|
||||
void box_export_show_textures();
|
||||
void box_export_show_bake_material();
|
||||
void box_export_show_mesh();
|
||||
@@ -269,6 +265,7 @@ void context_set_viewport_mode(viewport_mode_t mode);
|
||||
void context_load_envmap();
|
||||
void context_update_envmap();
|
||||
void context_set_viewport_shader(void *viewport_shader);
|
||||
void context_set_camera_controls(int i);
|
||||
void context_set_render_path();
|
||||
bool context_enable_import_plugin(char *file);
|
||||
void node_shader_add_out(node_shader_t *raw, char *s);
|
||||
@@ -388,10 +385,6 @@ void viewport_capture_video_begin();
|
||||
void viewport_capture_video_end();
|
||||
void tab_fonts_draw(ui_handle_t *htab);
|
||||
void tab_sounds_draw(ui_handle_t *htab);
|
||||
physics_world_t *physics_world_create();
|
||||
void physics_world_update(physics_world_t *world);
|
||||
physics_pair_t_array_t *physics_world_get_contact_pairs(physics_world_t *world, physics_body_t *body);
|
||||
float physics_world_get_speed(physics_world_t *world, physics_body_t *body);
|
||||
void ui_menu_render();
|
||||
void ui_menu_draw(void (*commands)(void), i32 x, i32 y);
|
||||
void ui_menu_separator();
|
||||
@@ -429,6 +422,56 @@ void tab_stages_rename_object(char *old_name, char *new_nam
|
||||
void tab_stages_rename_layer(char *old_name, char *new_name);
|
||||
void script_set_stage(char *name);
|
||||
void script_fade_to_stage(char *stage);
|
||||
void script_paint(f32 x, f32 y);
|
||||
void script_paint_world(f32 x, f32 y, f32 z);
|
||||
void script_paint_end(void);
|
||||
void script_fill_layer(void);
|
||||
slot_material_t *script_material_create(char *name);
|
||||
void script_material_set(slot_material_t *m);
|
||||
void script_material_delete(slot_material_t *m);
|
||||
ui_node_t *script_material_create_node(char *type);
|
||||
ui_node_t *script_material_create_node_at(char *type, f32 x, f32 y);
|
||||
ui_node_t *script_material_get_node(char *type);
|
||||
ui_node_t *script_material_get_node_id(i32 id);
|
||||
void script_material_connect(ui_node_t *from, i32 from_socket, ui_node_t *to, i32 to_socket);
|
||||
void script_material_disconnect(ui_node_t *to, i32 to_socket);
|
||||
void script_material_remove_node(ui_node_t *node);
|
||||
void script_material_set_float(ui_node_t *node, i32 is_input, i32 socket, f32 value);
|
||||
void script_material_set_color(ui_node_t *node, i32 is_input, i32 socket, f32 r, f32 g, f32 b, f32 a);
|
||||
void script_material_set_vector(ui_node_t *node, i32 is_input, i32 socket, f32 x, f32 y, f32 z);
|
||||
void script_material_update(void);
|
||||
void script_show_envmap(bool b);
|
||||
char *script_get_stage();
|
||||
void script_set_tilesheet_anim(object_t *o, char *anim);
|
||||
void script_tween_to(object_t *o, vec4_t to, f32 speed);
|
||||
void script_timer(f32 delay, void *fn);
|
||||
void script_notify_on_update(void *fn);
|
||||
void script_notify_on_next_frame(void *fn);
|
||||
context_t *script_get_context();
|
||||
config_t *script_get_config();
|
||||
project_t *script_get_project();
|
||||
object_t *script_get_object(char *s);
|
||||
void script_draw_particles(gpu_texture_t *texture, float x, float y, float w, float h, int atlas_x, int atlas_frames);
|
||||
void ui_files_show2(char *filters, bool is_save, bool open_multiple, void *files_done);
|
||||
char *project_filepath_get();
|
||||
char *project_basepath_get();
|
||||
void project_filepath_set(char *s);
|
||||
void plugin_register_texture(char *format, void *fn);
|
||||
void plugin_unregister_texture(char *format);
|
||||
void plugin_register_mesh(char *format, void *fn);
|
||||
void plugin_unregister_mesh(char *format);
|
||||
void plugin_register_text(char *format, void *fn);
|
||||
void plugin_unregister_text(char *format);
|
||||
raw_mesh_t *plugin_make_raw_mesh(char *name, i16_array_t *posa, i16_array_t *nora, u32_array_t *inda, float scale_pos);
|
||||
void plugin_material_category_add(char *category_name, any_array_t *node_list);
|
||||
void plugin_brush_category_add(char *category_name, any_array_t *node_list);
|
||||
void plugin_material_category_remove(char *category_name);
|
||||
void plugin_brush_category_remove(char *category_name);
|
||||
void plugin_material_custom_nodes_set(char *node_type, void *fn);
|
||||
void plugin_brush_custom_nodes_set(char *node_type, void *fn);
|
||||
void plugin_material_custom_nodes_remove(char *node_type);
|
||||
void plugin_brush_custom_nodes_remove(char *node_type);
|
||||
void *plugin_material_kong_get();
|
||||
void tab_stages_prune();
|
||||
void project_open();
|
||||
void project_save(bool save_and_quit);
|
||||
@@ -438,6 +481,7 @@ void project_new_box();
|
||||
void project_new(bool reset_layers);
|
||||
void project_set_default_envmap();
|
||||
void project_import_material();
|
||||
ui_node_link_t *project_create_node_link(ui_node_link_t_array_t *links, i32 from_id, i32 from_socket, i32 to_id, i32 to_socket);
|
||||
void project_import_brush();
|
||||
void project_import_mesh(bool replace_existing, void (*done)(void));
|
||||
void project_append_mesh();
|
||||
@@ -472,8 +516,7 @@ void sim_init();
|
||||
void sim_update();
|
||||
void sim_play();
|
||||
void sim_stop();
|
||||
void sim_add_body(object_t *o, physics_shape_t shape, f32 mass);
|
||||
void sim_remove_body(physics_body_t *pb);
|
||||
void sim_add_body(object_t *o, asim_shape_t shape, f32 mass);
|
||||
void sim_duplicate();
|
||||
void sim_delete();
|
||||
ui_node_link_t *parser_material_get_input_link(ui_node_socket_t *inp);
|
||||
@@ -521,12 +564,14 @@ void util_touch_update();
|
||||
void tab_materials_draw(ui_handle_t *htab);
|
||||
void tab_materials_accept_swatch_drop(swatch_color_t *swatch);
|
||||
void tab_materials_accept_material_drop(slot_material_t *material);
|
||||
void tab_materials_delete_material(slot_material_t *m);
|
||||
void tab_brushes_accept_brush_drop(slot_brush_t *brush);
|
||||
void tab_fonts_accept_font_drop(slot_font_t *font);
|
||||
void tab_textures_accept_asset_drop(asset_t *asset);
|
||||
void tab_browser_show_directory(char *directory);
|
||||
void tab_browser_draw(ui_handle_t *htab);
|
||||
mesh_object_t_array_t *util_mesh_get_visible();
|
||||
mesh_data_t *util_mesh_data_duplicate(mesh_data_t *source);
|
||||
void util_mesh_merge(mesh_object_t_array_t *paint_objects);
|
||||
void util_mesh_merge_geometry();
|
||||
void util_mesh_swap_axis(i32 a, i32 b);
|
||||
@@ -810,6 +855,7 @@ void text_to_image_node_init();
|
||||
void texture_mesh_node_init();
|
||||
void text_to_text_node_clear();
|
||||
void text_to_text_node_run(char *prompt, void (*done)(char *));
|
||||
char *minic_api_header_generate();
|
||||
char *neural_node_vector(ui_node_t *node, ui_node_socket_t *socket);
|
||||
char *neural_node_value(ui_node_t *node, ui_node_socket_t *socket);
|
||||
ui_node_t *neural_from_node(ui_node_socket_t *inp, i32 socket);
|
||||
|
||||
@@ -188,7 +188,6 @@
|
||||
#include "util/util_raycast.c"
|
||||
#include "util/util_render.c"
|
||||
#include "util/util_resize.c"
|
||||
#include "util/util_script.c"
|
||||
#include "util/util_select.c"
|
||||
#include "util/util_shortcut.c"
|
||||
#include "util/util_stage.c"
|
||||
@@ -207,6 +206,7 @@
|
||||
#include "history.c"
|
||||
#include "keymap.c"
|
||||
#include "logic_node.c"
|
||||
#include "minic_impl.c"
|
||||
#include "node_shader.c"
|
||||
#include "nodes_brush.c"
|
||||
#include "nodes_material.c"
|
||||
|
||||
+663
-489
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
|
||||
#include "../global.h"
|
||||
#include "global.h"
|
||||
|
||||
void script_set_stage(char *name) {
|
||||
if (g_project->stages == NULL) {
|
||||
@@ -164,6 +164,398 @@ object_t *script_get_object(char *s) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool script_paint_active = false;
|
||||
static bool script_paint_first = true;
|
||||
|
||||
static bool script_paint_allowed(void) {
|
||||
if (g_context == NULL || g_context->layer == NULL || g_context->material == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (slot_layer_is_group(g_context->layer)) {
|
||||
return false;
|
||||
}
|
||||
if (g_context->layer->fill_material != NULL && g_context->tool != TOOL_TYPE_PICKER && g_context->tool != TOOL_TYPE_MATERIAL &&
|
||||
g_context->tool != TOOL_TYPE_COLORID) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void script_paint_begin_stroke(void) {
|
||||
if (script_paint_active) {
|
||||
return;
|
||||
}
|
||||
make_material_parse_paint_material(false);
|
||||
render_path_base_draw_gbuffer();
|
||||
|
||||
history_push_undo = true;
|
||||
sculpt_push_undo = true;
|
||||
if (history_undo_layers != NULL) {
|
||||
history_paint();
|
||||
}
|
||||
|
||||
script_paint_active = true;
|
||||
script_paint_first = true;
|
||||
g_context->brush_time = sys_delta();
|
||||
g_context->prev_paint_vec_x = -1.0f;
|
||||
g_context->prev_paint_vec_y = -1.0f;
|
||||
}
|
||||
|
||||
static void script_paint_at(f32 x, f32 y) {
|
||||
if (!script_paint_allowed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpu_texture_t *current = _draw_current;
|
||||
bool in_use = gpu_in_use;
|
||||
if (in_use) {
|
||||
draw_end();
|
||||
}
|
||||
|
||||
script_paint_begin_stroke();
|
||||
|
||||
f32 prev_x = script_paint_first ? x : g_context->paint_vec.x;
|
||||
f32 prev_y = script_paint_first ? y : g_context->paint_vec.y;
|
||||
|
||||
g_context->decal_x = x;
|
||||
g_context->decal_y = y;
|
||||
g_context->paint_vec.x = x;
|
||||
g_context->paint_vec.y = y;
|
||||
g_context->last_paint_vec_x = prev_x;
|
||||
g_context->last_paint_vec_y = prev_y;
|
||||
g_context->prev_paint_vec_x = prev_x;
|
||||
g_context->prev_paint_vec_y = prev_y;
|
||||
g_context->pdirty = 1;
|
||||
|
||||
render_path_paint_commands_paint(false);
|
||||
|
||||
script_paint_first = false;
|
||||
|
||||
if (in_use) {
|
||||
draw_begin(current, false, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void script_paint(f32 x, f32 y) {
|
||||
script_paint_at(x, y);
|
||||
}
|
||||
|
||||
void script_paint_world(f32 x, f32 y, f32 z) {
|
||||
vec4_t clip = vec4_apply_mat4((vec4_t){x, y, z, 1.0f}, scene_camera->vp);
|
||||
if (clip.w <= 0.0f) {
|
||||
return;
|
||||
}
|
||||
f32 sx = (clip.x / clip.w + 1.0f) * 0.5f;
|
||||
f32 sy = (-clip.y / clip.w + 1.0f) * 0.5f;
|
||||
script_paint_at(sx, sy);
|
||||
}
|
||||
|
||||
void script_paint_end(void) {
|
||||
if (!script_paint_active) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpu_texture_t *current = _draw_current;
|
||||
bool in_use = gpu_in_use;
|
||||
if (in_use) {
|
||||
draw_end();
|
||||
}
|
||||
|
||||
render_path_paint_dilate(true, true);
|
||||
layers_update_linked_layers();
|
||||
|
||||
g_context->pdirty = 0;
|
||||
g_context->rtdirty = 1;
|
||||
g_context->rdirty = 2;
|
||||
g_context->ddirty = 2;
|
||||
g_context->brush_time = 0.0f;
|
||||
g_context->brush_blend_dirty = true;
|
||||
g_context->layer_preview_dirty = true;
|
||||
g_context->prev_paint_vec_x = -1.0f;
|
||||
g_context->prev_paint_vec_y = -1.0f;
|
||||
|
||||
script_paint_active = false;
|
||||
script_paint_first = true;
|
||||
|
||||
if (in_use) {
|
||||
draw_begin(current, false, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void script_fill_layer(void) {
|
||||
if (g_context == NULL || g_context->layer == NULL || g_context->material == NULL) {
|
||||
return;
|
||||
}
|
||||
if (slot_layer_is_group(g_context->layer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
history_push_undo = true;
|
||||
if (history_undo_layers != NULL) {
|
||||
history_paint();
|
||||
}
|
||||
layers_update_fill_layer(true);
|
||||
g_context->layer_preview_dirty = true;
|
||||
g_context->rtdirty = 1;
|
||||
g_context->rdirty = 2;
|
||||
g_context->ddirty = 2;
|
||||
}
|
||||
|
||||
static ui_node_canvas_t *script_material_canvas(void) {
|
||||
if (g_context == NULL || g_context->material == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return g_context->material->canvas;
|
||||
}
|
||||
|
||||
static void script_material_gpu_begin(gpu_texture_t **out_current, bool *out_in_use) {
|
||||
*out_current = _draw_current;
|
||||
*out_in_use = gpu_in_use;
|
||||
if (*out_in_use) {
|
||||
draw_end();
|
||||
}
|
||||
}
|
||||
|
||||
static void script_material_gpu_end(gpu_texture_t *current, bool in_use) {
|
||||
if (in_use) {
|
||||
draw_begin(current, false, 0);
|
||||
}
|
||||
}
|
||||
|
||||
slot_material_t *script_material_create(char *name) {
|
||||
if (g_project == NULL || g_project->_ == NULL || g_project->_->materials == NULL || g_project->_->materials->length == 0) {
|
||||
return NULL;
|
||||
}
|
||||
material_data_t *data = g_project->_->materials->buffer[0]->data;
|
||||
slot_material_t *m = slot_material_create(data, NULL);
|
||||
if (name != NULL && name[0] != '\0') {
|
||||
m->canvas->name = string_copy(name);
|
||||
}
|
||||
any_array_push(g_project->_->materials, m);
|
||||
|
||||
gpu_texture_t *current;
|
||||
bool in_use;
|
||||
script_material_gpu_begin(¤t, &in_use);
|
||||
context_set_material(m);
|
||||
util_render_make_material_preview();
|
||||
script_material_gpu_end(current, in_use);
|
||||
|
||||
history_new_material();
|
||||
if (ui_base_hwnds != NULL && ui_base_hwnds->length > 1) {
|
||||
ui_base_hwnds->buffer[1]->redraws = 2;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
void script_material_set(slot_material_t *m) {
|
||||
if (m == NULL) {
|
||||
return;
|
||||
}
|
||||
gpu_texture_t *current;
|
||||
bool in_use;
|
||||
script_material_gpu_begin(¤t, &in_use);
|
||||
context_set_material(m);
|
||||
util_render_make_material_preview();
|
||||
script_material_gpu_end(current, in_use);
|
||||
}
|
||||
|
||||
void script_material_delete(slot_material_t *m) {
|
||||
if (m == NULL || g_project == NULL || g_project->_ == NULL || g_project->_->materials == NULL) {
|
||||
return;
|
||||
}
|
||||
if (g_project->_->materials->length <= 1) {
|
||||
return;
|
||||
}
|
||||
if (array_index_of(g_project->_->materials, m) < 0) {
|
||||
return;
|
||||
}
|
||||
tab_materials_delete_material(m);
|
||||
}
|
||||
|
||||
ui_node_t *script_material_create_node(char *type) {
|
||||
if (type == NULL || g_context == NULL || g_context->material == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
nodes_material_init();
|
||||
ui_node_t *node = nodes_material_create_node(type, NULL);
|
||||
if (node != NULL && ui_nodes_hwnd != NULL) {
|
||||
ui_nodes_hwnd->redraws = 2;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
ui_node_t *script_material_create_node_at(char *type, f32 x, f32 y) {
|
||||
ui_node_t *node = script_material_create_node(type);
|
||||
if (node != NULL) {
|
||||
node->x = x;
|
||||
node->y = y;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
ui_node_t *script_material_get_node(char *type) {
|
||||
ui_node_canvas_t *canvas = script_material_canvas();
|
||||
if (canvas == NULL || type == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
for (i32 i = 0; i < canvas->nodes->length; ++i) {
|
||||
ui_node_t *n = canvas->nodes->buffer[i];
|
||||
if (string_equals(n->type, type)) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ui_node_t *script_material_get_node_id(i32 id) {
|
||||
ui_node_canvas_t *canvas = script_material_canvas();
|
||||
if (canvas == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return ui_get_node(canvas->nodes, id);
|
||||
}
|
||||
|
||||
static void script_material_remove_links_to(ui_node_canvas_t *canvas, i32 to_id, i32 to_socket) {
|
||||
i32 i = 0;
|
||||
while (i < canvas->links->length) {
|
||||
ui_node_link_t *l = canvas->links->buffer[i];
|
||||
if (l->to_id == to_id && l->to_socket == to_socket) {
|
||||
for (i32 j = i; j < canvas->links->length - 1; ++j) {
|
||||
canvas->links->buffer[j] = canvas->links->buffer[j + 1];
|
||||
}
|
||||
canvas->links->length--;
|
||||
}
|
||||
else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void script_material_connect(ui_node_t *from, i32 from_socket, ui_node_t *to, i32 to_socket) {
|
||||
ui_node_canvas_t *canvas = script_material_canvas();
|
||||
if (canvas == NULL || from == NULL || to == NULL) {
|
||||
return;
|
||||
}
|
||||
if (from_socket < 0 || from_socket >= from->outputs->length) {
|
||||
return;
|
||||
}
|
||||
if (to_socket < 0 || to_socket >= to->inputs->length) {
|
||||
return;
|
||||
}
|
||||
|
||||
script_material_remove_links_to(canvas, to->id, to_socket);
|
||||
|
||||
ui_node_link_t *link = project_create_node_link(canvas->links, from->id, from_socket, to->id, to_socket);
|
||||
any_array_push(canvas->links, link);
|
||||
|
||||
if (ui_nodes_hwnd != NULL) {
|
||||
ui_nodes_hwnd->redraws = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void script_material_disconnect(ui_node_t *to, i32 to_socket) {
|
||||
ui_node_canvas_t *canvas = script_material_canvas();
|
||||
if (canvas == NULL || to == NULL) {
|
||||
return;
|
||||
}
|
||||
script_material_remove_links_to(canvas, to->id, to_socket);
|
||||
if (ui_nodes_hwnd != NULL) {
|
||||
ui_nodes_hwnd->redraws = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void script_material_remove_node(ui_node_t *node) {
|
||||
ui_node_canvas_t *canvas = script_material_canvas();
|
||||
if (canvas == NULL || node == NULL) {
|
||||
return;
|
||||
}
|
||||
if (string_equals(node->type, "OUTPUT_MATERIAL_PBR")) {
|
||||
return;
|
||||
}
|
||||
ui_remove_node(node, canvas);
|
||||
if (ui_nodes_hwnd != NULL) {
|
||||
ui_nodes_hwnd->redraws = 2;
|
||||
}
|
||||
}
|
||||
|
||||
static ui_node_socket_t *script_material_socket(ui_node_t *node, bool is_input, i32 socket) {
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (is_input) {
|
||||
if (socket < 0 || socket >= node->inputs->length) {
|
||||
return NULL;
|
||||
}
|
||||
return node->inputs->buffer[socket];
|
||||
}
|
||||
if (socket < 0 || socket >= node->outputs->length) {
|
||||
return NULL;
|
||||
}
|
||||
return node->outputs->buffer[socket];
|
||||
}
|
||||
|
||||
void script_material_set_float(ui_node_t *node, i32 is_input, i32 socket, f32 value) {
|
||||
ui_node_socket_t *soc = script_material_socket(node, is_input != 0, socket);
|
||||
if (soc == NULL || soc->default_value == NULL || soc->default_value->length < 1) {
|
||||
return;
|
||||
}
|
||||
soc->default_value->buffer[0] = value;
|
||||
}
|
||||
|
||||
void script_material_set_color(ui_node_t *node, i32 is_input, i32 socket, f32 r, f32 g, f32 b, f32 a) {
|
||||
ui_node_socket_t *soc = script_material_socket(node, is_input != 0, socket);
|
||||
if (soc == NULL || soc->default_value == NULL || soc->default_value->length < 3) {
|
||||
return;
|
||||
}
|
||||
soc->default_value->buffer[0] = r;
|
||||
soc->default_value->buffer[1] = g;
|
||||
soc->default_value->buffer[2] = b;
|
||||
if (soc->default_value->length >= 4) {
|
||||
soc->default_value->buffer[3] = a;
|
||||
}
|
||||
}
|
||||
|
||||
void script_material_set_vector(ui_node_t *node, i32 is_input, i32 socket, f32 x, f32 y, f32 z) {
|
||||
ui_node_socket_t *soc = script_material_socket(node, is_input != 0, socket);
|
||||
if (soc == NULL || soc->default_value == NULL || soc->default_value->length < 3) {
|
||||
return;
|
||||
}
|
||||
soc->default_value->buffer[0] = x;
|
||||
soc->default_value->buffer[1] = y;
|
||||
soc->default_value->buffer[2] = z;
|
||||
}
|
||||
|
||||
void script_material_update(void) {
|
||||
if (g_context == NULL || g_context->material == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpu_texture_t *current;
|
||||
bool in_use;
|
||||
script_material_gpu_begin(¤t, &in_use);
|
||||
|
||||
make_material_parse_paint_material(true);
|
||||
util_render_make_material_preview();
|
||||
if (context_is_decal()) {
|
||||
util_render_make_decal_preview();
|
||||
}
|
||||
base_update_workflow_nodes();
|
||||
|
||||
script_material_gpu_end(current, in_use);
|
||||
|
||||
if (ui_nodes_hwnd != NULL) {
|
||||
ui_nodes_hwnd->redraws = 2;
|
||||
}
|
||||
if (ui_header_handle != NULL) {
|
||||
ui_header_handle->redraws = 2;
|
||||
}
|
||||
if (ui_base_hwnds != NULL && ui_base_hwnds->length > 1) {
|
||||
ui_base_hwnds->buffer[1]->redraws = 2;
|
||||
}
|
||||
g_context->ddirty = 2;
|
||||
g_context->rtdirty = 1;
|
||||
}
|
||||
|
||||
extern string_array_t *_path_texture_formats;
|
||||
extern string_array_t *_path_mesh_formats;
|
||||
extern string_array_t *_path_text_formats;
|
||||
@@ -1,28 +1,71 @@
|
||||
|
||||
#include "../global.h"
|
||||
|
||||
string_array_t *text_to_text_node_qwen_args(char *dir) {
|
||||
char *history_file = string("%s%shistory.txt", dir, PATH_SEP);
|
||||
char *prompt = sys_buffer_to_string(iron_load_blob(history_file));
|
||||
static i32 text_to_text_node_backend = CONSOLE_MODEL_QWEN;
|
||||
|
||||
static char *text_to_text_node_guide = "Reply with C code only - no explanations. Do not chain statements - declare intermediary variables. Place the code "
|
||||
"inside 'void main()' function. Wrap the code in a ```c markdown fence.";
|
||||
|
||||
static char *text_to_text_node_project_contents(void) {
|
||||
buffer_t *encoded = util_encode_project(g_project);
|
||||
char *json = armpack_decode_to_json_omit_buffers(encoded);
|
||||
return string("/* Current project state:\n%s\n*/\n", json);
|
||||
}
|
||||
|
||||
string_array_t *text_to_text_node_qwen_args(char *dir) {
|
||||
char *prompt_file = string("%s%sprompt.txt", dir, PATH_SEP);
|
||||
string_array_t *argv = any_array_create_from_raw(
|
||||
(void *[]){
|
||||
string("%s/%s", dir, neural_node_llama_bin()),
|
||||
"-m",
|
||||
string("%s/Qwen3.6-27B-Q4_K_M.gguf", dir),
|
||||
"-ngl",
|
||||
"99",
|
||||
"-c",
|
||||
"20000",
|
||||
"--single-turn",
|
||||
"--prompt-cache",
|
||||
string("%s/context.bin", dir),
|
||||
"--file",
|
||||
prompt_file,
|
||||
NULL,
|
||||
},
|
||||
13);
|
||||
return argv;
|
||||
}
|
||||
|
||||
string_array_t *text_to_text_node_grok_args(char *dir) {
|
||||
char *prompt_file = string("%s%sprompt.txt", dir, PATH_SEP);
|
||||
string_array_t *argv = any_array_create_from_raw(
|
||||
(void *[]){
|
||||
"grok",
|
||||
"--prompt-file",
|
||||
prompt_file,
|
||||
"--output-format",
|
||||
"plain",
|
||||
"--tools",
|
||||
"",
|
||||
NULL,
|
||||
},
|
||||
10);
|
||||
return argv;
|
||||
}
|
||||
|
||||
string_array_t *text_to_text_node_claude_args(char *dir, char *prompt) {
|
||||
string_array_t *argv = any_array_create_from_raw(
|
||||
(void *[]){
|
||||
string("%s/%s", dir, neural_node_llama_bin()),
|
||||
"-m",
|
||||
string("%s/Qwen3.6-27B-Q4_K_M.gguf", dir),
|
||||
"-ngl",
|
||||
"99",
|
||||
"-c",
|
||||
"20000",
|
||||
"--single-turn",
|
||||
"--prompt-cache",
|
||||
string("%s/context.bin", dir),
|
||||
"--prompt-cache-all",
|
||||
"--prompt",
|
||||
string("'%s'", prompt),
|
||||
"claude",
|
||||
"--print",
|
||||
"--output-format",
|
||||
"text",
|
||||
"--tools",
|
||||
"",
|
||||
"--append-system-prompt-file",
|
||||
string("%s%sapi.h", dir, PATH_SEP),
|
||||
prompt,
|
||||
NULL,
|
||||
},
|
||||
14);
|
||||
10);
|
||||
return argv;
|
||||
}
|
||||
|
||||
@@ -33,12 +76,15 @@ void text_to_text_node_check_result(void (*done)(char *)) {
|
||||
if (iron_file_exists(file)) {
|
||||
buffer_t *b = iron_load_blob(file);
|
||||
char *s = sys_buffer_to_string(b);
|
||||
s = substring(s, string_last_index_of(s, "</think>\n\n") + 10, string_last_index_of(s, "[end of text]"));
|
||||
|
||||
char *history_file = string("%s%shistory.txt", neural_node_dir(), PATH_SEP);
|
||||
char *existing = sys_buffer_to_string(iron_load_blob(history_file));
|
||||
char *entry = string("%s%s\n", existing, s);
|
||||
iron_file_save_bytes(history_file, (buffer_t *)u8_array_create_from_string(entry), 0);
|
||||
if (text_to_text_node_backend == CONSOLE_MODEL_QWEN) {
|
||||
i32 think_end = string_last_index_of(s, "</think>\n\n");
|
||||
i32 eot = string_last_index_of(s, "[end of text]");
|
||||
if (think_end >= 0 && eot > think_end) {
|
||||
s = substring(s, think_end + 10, eot);
|
||||
}
|
||||
}
|
||||
s = trim_end(s);
|
||||
|
||||
done(s);
|
||||
base_redraw_console();
|
||||
@@ -49,19 +95,34 @@ void text_to_text_node_check_result(void (*done)(char *)) {
|
||||
|
||||
void text_to_text_node_clear(void) {
|
||||
char *dir = neural_node_dir();
|
||||
iron_delete_file(string("%s%shistory.txt", dir, PATH_SEP));
|
||||
iron_delete_file(string("%s%sprompt.txt", dir, PATH_SEP));
|
||||
iron_delete_file(string("%s%scontext.bin", dir, PATH_SEP));
|
||||
iron_delete_file(string("%s%soutput.txt", dir, PATH_SEP));
|
||||
iron_delete_file(string("%s%sapi.h", dir, PATH_SEP));
|
||||
}
|
||||
|
||||
void text_to_text_node_run(char *prompt, void (*done)(char *)) {
|
||||
char *dir = neural_node_dir();
|
||||
char *history_file = string("%s%shistory.txt", dir, PATH_SEP);
|
||||
char *existing = iron_file_exists(history_file) ? sys_buffer_to_string(iron_load_blob(history_file)) : "";
|
||||
char *entry = string("%suser\n%s\nassistant\n", existing, prompt);
|
||||
iron_file_save_bytes(history_file, (buffer_t *)u8_array_create_from_string(entry), 0);
|
||||
char *dir = neural_node_dir();
|
||||
if (string_equals(file_read_directory(dir)->buffer[0], "")) {
|
||||
iron_create_directory(dir);
|
||||
}
|
||||
text_to_text_node_backend = g_config->console_model;
|
||||
|
||||
char *reference = string("%s\n%s\n%s\n", minic_api_header_generate(), text_to_text_node_project_contents(), text_to_text_node_guide);
|
||||
|
||||
string_array_t *argv;
|
||||
if (text_to_text_node_backend == CONSOLE_MODEL_CLAUDE) {
|
||||
iron_file_save_bytes(string("%s%sapi.h", dir, PATH_SEP), (buffer_t *)u8_array_create_from_string(reference), 0);
|
||||
argv = text_to_text_node_claude_args(dir, prompt);
|
||||
}
|
||||
else {
|
||||
char *prompt_file = string("%s%sprompt.txt", dir, PATH_SEP);
|
||||
char *full = string("%s%s", reference, prompt);
|
||||
iron_file_save_bytes(prompt_file, (buffer_t *)u8_array_create_from_string(full), 0);
|
||||
argv = text_to_text_node_backend == CONSOLE_MODEL_GROK ? text_to_text_node_grok_args(dir) : text_to_text_node_qwen_args(dir);
|
||||
}
|
||||
|
||||
iron_exec_async_output_file = string("%s%soutput.txt", dir, PATH_SEP);
|
||||
string_array_t *argv = text_to_text_node_qwen_args(dir);
|
||||
iron_exec_async(argv->buffer[0], argv->buffer);
|
||||
sys_notify_on_update(text_to_text_node_check_result, done);
|
||||
}
|
||||
|
||||
+16
-37
@@ -1,6 +1,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "iron_physics.h"
|
||||
#include "enums.h"
|
||||
#include "minic.h"
|
||||
|
||||
@@ -142,6 +143,7 @@ typedef struct config {
|
||||
bool grid_snap;
|
||||
bool experimental;
|
||||
i32 neural_res;
|
||||
i32 console_model;
|
||||
render_mode_t render_mode;
|
||||
workspace_t workspace;
|
||||
workflow_t workflow;
|
||||
@@ -150,16 +152,6 @@ typedef struct config {
|
||||
bool view2d_grid_snap;
|
||||
} config_t;
|
||||
|
||||
typedef struct physics_body {
|
||||
void *_body;
|
||||
physics_shape_t shape;
|
||||
f32 mass;
|
||||
f32 dimx;
|
||||
f32 dimy;
|
||||
f32 dimz;
|
||||
struct object *obj;
|
||||
} physics_body_t;
|
||||
|
||||
typedef struct slot_material {
|
||||
struct ui_nodes *nodes;
|
||||
struct ui_node_canvas *canvas;
|
||||
@@ -404,21 +396,21 @@ typedef struct context {
|
||||
f32 last_particle_hit_x;
|
||||
f32 last_particle_hit_y;
|
||||
f32 last_particle_hit_z;
|
||||
struct physics_body *paint_body;
|
||||
struct asim_body *paint_body;
|
||||
struct {
|
||||
f32 hit_x;
|
||||
f32 hit_y;
|
||||
f32 hit_z;
|
||||
f32 hit_last_x;
|
||||
f32 hit_last_y;
|
||||
f32 hit_last_z;
|
||||
f32 hit_nor_x;
|
||||
f32 hit_nor_y;
|
||||
f32 hit_nor_z;
|
||||
f32 contact_time;
|
||||
struct tween_anim *timer;
|
||||
struct physics_body *body;
|
||||
struct object *bullet;
|
||||
f32 hit_x;
|
||||
f32 hit_y;
|
||||
f32 hit_z;
|
||||
f32 hit_last_x;
|
||||
f32 hit_last_y;
|
||||
f32 hit_last_z;
|
||||
f32 hit_nor_x;
|
||||
f32 hit_nor_y;
|
||||
f32 hit_nor_z;
|
||||
f32 contact_time;
|
||||
struct tween_anim *timer;
|
||||
struct asim_body *body;
|
||||
struct object *bullet;
|
||||
} particles[32];
|
||||
i32 particle_index;
|
||||
f32 particle_friction;
|
||||
@@ -525,10 +517,6 @@ typedef struct logic_node_input {
|
||||
i32 from; // Socket index
|
||||
} logic_node_input_t;
|
||||
|
||||
typedef struct physics_world {
|
||||
i32 empty;
|
||||
} physics_world_t;
|
||||
|
||||
typedef struct node_group {
|
||||
struct ui_nodes *nodes;
|
||||
struct ui_node_canvas *canvas;
|
||||
@@ -827,15 +815,6 @@ typedef struct gpu_texture_t_array {
|
||||
int capacity;
|
||||
} gpu_texture_t_array_t;
|
||||
|
||||
#ifdef WITH_PHYSICS
|
||||
#include "../libs/asim.h"
|
||||
typedef struct physics_pair_t_array {
|
||||
physics_pair_t **buffer;
|
||||
int length;
|
||||
int capacity;
|
||||
} physics_pair_t_array_t;
|
||||
#endif
|
||||
|
||||
typedef struct ui_node_socket_t_array {
|
||||
ui_node_socket_t **buffer;
|
||||
int length;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
|
||||
#include "../global.h"
|
||||
|
||||
bool tab_console_prompt_entered = false;
|
||||
|
||||
void tab_console_draw_export_on_file_picked(char *path) {
|
||||
char *str = string_array_join(console_last_traces, "\n");
|
||||
char *f = ui_files_filename;
|
||||
@@ -22,17 +20,12 @@ void tab_console_run_done(char *s) {
|
||||
if (starts_with(s, "```c")) {
|
||||
s = substring(s, 5, string_length(s) - 4);
|
||||
}
|
||||
|
||||
tab_scripts_get();
|
||||
g_project->script_datas->buffer[0] = string_copy(s);
|
||||
tab_scripts_minimap_dirty = true;
|
||||
|
||||
ui_base_hwnds->buffer[TAB_AREA_SIDEBAR0]->redraws = 2;
|
||||
|
||||
// any_array_t *parts = string_split(s, "\n\n");
|
||||
// for (i32 i = 0; i < parts->length; ++i) {
|
||||
// console_log(parts->buffer[i]);
|
||||
// if (i < parts->length - 1) {
|
||||
// console_log(""); // new-line
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
#if defined(IRON_WINDOWS) || defined(IRON_LINUX) || defined(IRON_MACOS)
|
||||
@@ -43,9 +36,13 @@ void tab_console_run_button_on_next_frame(void *_) {
|
||||
}
|
||||
|
||||
bool tab_console_run_button(ui_handle_t *h_input, bool press_run) {
|
||||
char *url = box_preferneces_model_url_from_name("Qwen");
|
||||
char *file_name = box_preferences_file_name_from_url(url);
|
||||
bool found = box_preferences_model_exists(file_name);
|
||||
bool use_cli = g_config->console_model != CONSOLE_MODEL_QWEN;
|
||||
bool found = true;
|
||||
if (!use_cli) {
|
||||
char *url = box_preferneces_model_url_from_name("Qwen");
|
||||
char *file_name = box_preferences_file_name_from_url(url);
|
||||
found = box_preferences_model_exists(file_name);
|
||||
}
|
||||
|
||||
if (iron_exec_async_done == 0) {
|
||||
ui_icon_button(tr("Processing..."), ICON_STOP, UI_ALIGN_CENTER);
|
||||
@@ -55,20 +52,8 @@ bool tab_console_run_button(ui_handle_t *h_input, bool press_run) {
|
||||
}
|
||||
else if (found && (ui_icon_button(tr("Run"), ICON_PLAY, UI_ALIGN_CENTER) || press_run)) {
|
||||
|
||||
char *prompt = h_input->text;
|
||||
|
||||
if (!tab_console_prompt_entered) {
|
||||
tab_console_prompt_entered = true;
|
||||
text_to_text_node_clear();
|
||||
|
||||
buffer_t *api_blob = data_get_blob("api.h"); // TODO: Generate dynamically
|
||||
char *api = sys_buffer_to_string(api_blob);
|
||||
char *guide = "Write C code only. Do not chain statements - declare intermediary variables. Place the code inside 'void main()' function.";
|
||||
prompt = string("%s\n%s\n%s", api, guide, prompt);
|
||||
}
|
||||
|
||||
console_log(string(">%s", h_input->text));
|
||||
text_to_text_node_run(prompt, tab_console_run_done);
|
||||
text_to_text_node_run(h_input->text, tab_console_run_done);
|
||||
h_input->text = "";
|
||||
|
||||
return true;
|
||||
@@ -109,8 +94,8 @@ void tab_console_draw(ui_handle_t *htab) {
|
||||
gc_unroot(console_last_traces);
|
||||
console_last_traces = any_array_create_from_raw((void *[]){}, 0);
|
||||
gc_root(console_last_traces);
|
||||
h_input->text = "";
|
||||
tab_console_prompt_entered = false;
|
||||
h_input->text = "";
|
||||
text_to_text_node_clear();
|
||||
}
|
||||
if (ui_icon_button(tr("Export"), ICON_EXPORT, UI_ALIGN_CENTER)) {
|
||||
ui_files_show("txt", true, false, &tab_console_draw_export_on_file_picked);
|
||||
|
||||
Reference in New Issue
Block a user