As in these functions
Is it possible to call a Sprite's Convert to Mesh 2D, Create CollisionPolygon2D Sibling via code
I'll hate to use a custom vectorization algo just because of this
It doesn't look like there is anything exposed in the Sprite class, but I'm not sure if the code would be there anyway. This might be a good proposal for the Godot proposal repository (assuming its not already exposed to GDScript)
https://github.com/godotengine/godot/blob/master/editor/plugins/sprite_2d_editor_plugin.cpp
That menu comes from there(far as I can tell), starting from line 114:
void Sprite2DEditor::_menu_option(int p_option) {
if (!node) {
return;
}
selected_menu_item = (Menu)p_option;
switch (p_option) {
case MENU_OPTION_CONVERT_TO_MESH_2D: {
debug_uv_dialog->get_ok_button()->set_text(TTR("Create Mesh2D"));
debug_uv_dialog->set_title(TTR("Mesh2D Preview"));
_update_mesh_data();
debug_uv_dialog->popup_centered();
debug_uv->update();
} break;
case MENU_OPTION_CONVERT_TO_POLYGON_2D: {
debug_uv_dialog->get_ok_button()->set_text(TTR("Create Polygon2D"));
debug_uv_dialog->set_title(TTR("Polygon2D Preview"));
_update_mesh_data();
debug_uv_dialog->popup_centered();
debug_uv->update();
} break;
case MENU_OPTION_CREATE_COLLISION_POLY_2D: {
debug_uv_dialog->get_ok_button()->set_text(TTR("Create CollisionPolygon2D"));
debug_uv_dialog->set_title(TTR("CollisionPolygon2D Preview"));
_update_mesh_data();
debug_uv_dialog->popup_centered();
debug_uv->update();
} break;
case MENU_OPTION_CREATE_LIGHT_OCCLUDER_2D: {
debug_uv_dialog->get_ok_button()->set_text(TTR("Create LightOccluder2D"));
debug_uv_dialog->set_title(TTR("LightOccluder2D Preview"));
_update_mesh_data();
debug_uv_dialog->popup_centered();
debug_uv->update();
} break;
}
}
It looks like the _update_mesh_data function has the code that converts the image actually to the mesh, from my. limited understanding, and unfortunately it doesn’t seem accessible from GDScript...