Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/paint_image_proj.c
| Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_mesh_mapping.h" | #include "BKE_mesh_mapping.h" | ||||
| #include "BKE_mesh_runtime.h" | #include "BKE_mesh_runtime.h" | ||||
| #include "BKE_node.h" | #include "BKE_node.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_screen.h" | |||||
| #include "BKE_texture.h" | #include "BKE_texture.h" | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "ED_object.h" | #include "ED_object.h" | ||||
| ▲ Show 20 Lines • Show All 5,512 Lines • ▼ Show 20 Lines | void PAINT_OT_project_image(wmOperatorType *ot) | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| prop = RNA_def_enum(ot->srna, "image", DummyRNA_NULL_items, 0, "Image", ""); | prop = RNA_def_enum(ot->srna, "image", DummyRNA_NULL_items, 0, "Image", ""); | ||||
| RNA_def_enum_funcs(prop, RNA_image_itemf); | RNA_def_enum_funcs(prop, RNA_image_itemf); | ||||
| RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); | RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); | ||||
| ot->prop = prop; | ot->prop = prop; | ||||
| } | } | ||||
| static bool texture_paint_image_from_poll(bContext *C) | |||||
| { | |||||
| if (BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_VIEW3D, 0) == NULL) { | |||||
| CTX_wm_operator_poll_msg_set(C, "Failed to get a 3d viewport"); | |||||
brecht: This could be a bit more informative: "No 3D viewport found to create image from"
Otherwise… | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) | static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Image *image; | Image *image; | ||||
| ImBuf *ibuf; | ImBuf *ibuf; | ||||
| char filename[FILE_MAX]; | char filename[FILE_MAX]; | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_depsgraph(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ToolSettings *settings = scene->toolsettings; | ToolSettings *settings = scene->toolsettings; | ||||
| View3D *v3d = CTX_wm_view3d(C); | |||||
| RegionView3D *rv3d = CTX_wm_region_view3d(C); | |||||
| int w = settings->imapaint.screen_grab_size[0]; | int w = settings->imapaint.screen_grab_size[0]; | ||||
| int h = settings->imapaint.screen_grab_size[1]; | int h = settings->imapaint.screen_grab_size[1]; | ||||
| int maxsize; | int maxsize; | ||||
| char err_out[256] = "unknown"; | char err_out[256] = "unknown"; | ||||
| ScrArea *sa = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_VIEW3D, 0); | |||||
| if (!sa) { | |||||
| BKE_report(op->reports, RPT_ERROR, "Failed to get a 3d viewport"); | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| View3D *v3d = sa->spacedata.first; | |||||
| ARegion *ar = BKE_area_find_region_active_win(sa); | |||||
| if (!ar) { | |||||
| BKE_report(op->reports, RPT_ERROR, "Failed to get a 3d viewport"); | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| RNA_string_get(op->ptr, "filepath", filename); | RNA_string_get(op->ptr, "filepath", filename); | ||||
| maxsize = GPU_max_texture_size(); | maxsize = GPU_max_texture_size(); | ||||
| if (w > maxsize) w = maxsize; | if (w > maxsize) w = maxsize; | ||||
| if (h > maxsize) h = maxsize; | if (h > maxsize) h = maxsize; | ||||
| ibuf = ED_view3d_draw_offscreen_imbuf( | ibuf = ED_view3d_draw_offscreen_imbuf( | ||||
| depsgraph, scene, v3d->shading.type, | depsgraph, scene, v3d->shading.type, | ||||
| v3d, CTX_wm_region(C), | v3d, ar, | ||||
| w, h, IB_rect, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL, | w, h, IB_rect, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL, | ||||
| NULL, err_out); | NULL, err_out); | ||||
| if (!ibuf) { | if (!ibuf) { | ||||
| /* Mostly happens when OpenGL offscreen buffer was failed to create, */ | /* Mostly happens when OpenGL offscreen buffer was failed to create, */ | ||||
| /* but could be other reasons. Should be handled in the future. nazgul */ | /* but could be other reasons. Should be handled in the future. nazgul */ | ||||
| BKE_reportf(op->reports, RPT_ERROR, "Failed to create OpenGL off-screen buffer: %s", err_out); | BKE_reportf(op->reports, RPT_ERROR, "Failed to create OpenGL off-screen buffer: %s", err_out); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| Show All 34 Lines | |||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Image from View"; | ot->name = "Image from View"; | ||||
| ot->idname = "PAINT_OT_image_from_view"; | ot->idname = "PAINT_OT_image_from_view"; | ||||
| ot->description = "Make an image from the current 3D view for re-projection"; | ot->description = "Make an image from the current 3D view for re-projection"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = texture_paint_image_from_view_exec; | ot->exec = texture_paint_image_from_view_exec; | ||||
| ot->poll = ED_operator_region_view3d_active; | ot->poll = texture_paint_image_from_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER; | ot->flag = OPTYPE_REGISTER; | ||||
| RNA_def_string_file_name(ot->srna, "filepath", NULL, FILE_MAX, "File Path", "Name of the file"); | RNA_def_string_file_name(ot->srna, "filepath", NULL, FILE_MAX, "File Path", "Name of the file"); | ||||
| } | } | ||||
| /********************************************* | /********************************************* | ||||
| ▲ Show 20 Lines • Show All 458 Lines • Show Last 20 Lines | |||||
This could be a bit more informative: "No 3D viewport found to create image from"
Otherwise sounds a bit like an internal failure.