paint: expose physics combo

This commit is contained in:
luboslenco
2026-07-18 15:45:49 +02:00
parent 24365994f0
commit b83184d8fd
6 changed files with 55 additions and 29 deletions
+7 -2
View File
@@ -408,11 +408,16 @@ void base_update(void *_) {
ui_base_update(NULL);
camera_update(NULL);
// Render
if (g_context->tool == TOOL_TYPE_CURSOR) {
if (g_config->workspace == WORKSPACE_PLAYER) {
sim_init();
if (!sim_running) {
sim_play();
}
sim_update();
}
else if (sim_running) {
sim_stop();
}
if (g_context->frame == 2) {
util_render_make_material_preview();
+2
View File
@@ -119,6 +119,7 @@ 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);
@@ -140,6 +141,7 @@ void tab_timeline_prepare_save();
void tab_timeline_finish_save();
void tab_timeline_play();
void tab_timeline_player_update();
void tab_timeline_edit_script(i32 row, i32 frame);
void tab_console_draw(ui_handle_t *htab);
void tab_textures_draw(ui_handle_t *htab);
void render_path_forward_init();
+7
View File
@@ -53,6 +53,13 @@ void physics_body_remove(physics_body_t *body) {
asim_body_remove(body->_body);
}
void physics_body_set_mass(physics_body_t *body, f32 mass) {
body->mass = mass;
if (body->shape == PHYSICS_SHAPE_SPHERE) {
asim_body_set_mass(body->_body, mass);
}
}
void physics_body_apply_impulse(physics_body_t *body, vec4_t dir) {
asim_body_apply_impulse(body->_body, dir.x, dir.y, dir.z);
}
+1
View File
@@ -82,6 +82,7 @@ void sim_stop() {
}
void sim_add_body(object_t *o, physics_shape_t shape, f32 mass) {
sim_init();
physics_body_t *body = physics_body_create();
body->shape = shape;
body->mass = mass;
+37 -26
View File
@@ -279,6 +279,10 @@ void tab_meshes_draw_context_menu() {
sim_duplicate();
return;
}
if (ui_menu_button(tr("Edit Script"), "", ICON_EDIT)) {
tab_timeline_edit_script(g_project->_->layers->length + i, 0);
return;
}
#ifdef WITH_PLUGINS
if (ui_menu_button(tr("UV Unwrap"), "", ICON_NONE)) {
@@ -337,32 +341,6 @@ void tab_meshes_draw_context_menu() {
transform_compute_dim(t);
}
// physics_body_t *pb = any_imap_get(physics_body_object_map, g_context->selected_object->uid);
// ui_handle_t *hshape = ui_handle(__ID__);
// string_array_t *shape_combo = any_array_create_from_raw(
// (void *[]){
// tr("None"),
// tr("Box"),
// tr("Sphere"),
// tr("Convex Hull"),
// tr("Terrain"),
// tr("Mesh"),
// },
// 6);
// hshape->i = pb != NULL ? pb->shape + 1 : 0;
// ui_combo(hshape, shape_combo, tr("Shape"), true, UI_ALIGN_LEFT, true);
// ui_handle_t *hdynamic = ui_handle(__ID__);
// hdynamic->b = pb != NULL ? pb->mass > 0 : false;
// ui_check(hdynamic, "Dynamic", "");
// if (hshape->changed || hdynamic->changed) {
// sim_remove_body(g_context->selected_object->uid);
// if (hshape->i > 0) {
// sim_add_body(g_context->selected_object, hshape->i - 1, hdynamic->b ? 1.0 : 0.0);
// }
// }
// Material override
string_array_t *mat_combo = string_array_create(0);
string_array_push(mat_combo, ""); // Empty = use painted layers
@@ -400,6 +378,39 @@ void tab_meshes_draw_context_menu() {
g_project->mesh_parents = i32_array_create(0);
}
// Physics
if (g_config->experimental) {
physics_body_t *pb = any_imap_get(physics_body_object_map, o->base->uid);
string_array_t *phys_combo = string_array_create(0);
string_array_push(phys_combo, ""); // Empty = no physics
string_array_push(phys_combo, tr("Sphere"));
string_array_push(phys_combo, tr("Mesh"));
ui_handle_t *hphys = ui_handle(__ID__);
hphys->i = pb == NULL ? 0 : (pb->shape == PHYSICS_SHAPE_SPHERE ? 1 : 2);
ui_combo(hphys, phys_combo, tr("Physics"), true, UI_ALIGN_LEFT, false);
if (hphys->changed) {
if (pb != NULL) {
sim_remove_body(pb);
pb = NULL;
}
if (hphys->i > 0) {
sim_add_body(o->base, hphys->i == 1 ? PHYSICS_SHAPE_SPHERE : PHYSICS_SHAPE_MESH, hphys->i == 1 ? 1.0 : 0.0);
pb = any_imap_get(physics_body_object_map, o->base->uid);
}
}
if (pb != NULL) {
ui_handle_t *hmass = ui_handle(__ID__);
hmass->f = pb->mass;
ui_slider(hmass, tr("Mass"), 0.0, 10.0, true, 100, true, UI_ALIGN_LEFT, true);
if (hmass->changed) {
physics_body_set_mass(pb, hmass->f); // Zero mass = static
ui_menu_keep_open = true;
}
}
}
if (g_ui->changed || g_ui->is_typing) {
ui_menu_keep_open = true;
}
+1 -1
View File
@@ -775,7 +775,7 @@ static bool tab_timeline_has_script(i32 row, i32 frame) {
return string_array_index_of(g_project->script_names, tab_timeline_script_name(row, frame)) >= 0;
}
static void tab_timeline_edit_script(i32 row, i32 frame) {
void tab_timeline_edit_script(i32 row, i32 frame) {
tab_scripts_create(tab_timeline_script_name(row, frame));
ui_base_htabs->buffer[TAB_AREA_SIDEBAR0]->i = 2; // Scripts tab
ui_base_hwnds->buffer[TAB_AREA_SIDEBAR0]->redraws = 2;