diff options
Diffstat (limited to 'source/blender/editors/mesh/mesh_data.c')
-rw-r--r-- | source/blender/editors/mesh/mesh_data.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 050152821f5..90764388029 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -46,6 +46,7 @@ #include "BKE_depsgraph.h" #include "BKE_displist.h" #include "BKE_global.h" +#include "BKE_library.h" #include "BKE_material.h" #include "BKE_mesh.h" #include "BKE_report.h" @@ -62,6 +63,7 @@ #include "ED_mesh.h" #include "ED_object.h" +#include "ED_uvedit.h" #include "ED_view3d.h" #include "RE_render_ext.h" @@ -309,6 +311,68 @@ void MESH_OT_uv_texture_add(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + Scene *scene= CTX_data_scene(C); + Base *base= ED_view3d_give_base_under_cursor(C, event->mval); + Image *ima; + Mesh *me; + Object *obedit; + int exitmode= 0; + char name[32]; + + /* check input variables */ + RNA_string_get(op->ptr, "name", name); + ima= (Image *)find_id("IM", name); + if(base==NULL || base->object->type!=OB_MESH || ima==NULL) { + BKE_report(op->reports, RPT_ERROR, "Not a Mesh or no Image."); + return OPERATOR_CANCELLED; + } + + /* turn mesh in editmode */ + /* BKE_mesh_get/end_editmesh: ED_uvedit_assign_image also calls this */ + + obedit= base->object; + me= obedit->data; + if(me->edit_mesh==NULL) { + make_editMesh(scene, obedit); + exitmode= 1; + } + if(me->edit_mesh==NULL) + return OPERATOR_CANCELLED; + + ED_uvedit_assign_image(scene, obedit, ima, NULL); + + if(exitmode) { + load_editMesh(scene, obedit); + free_editMesh(me->edit_mesh); + MEM_freeN(me->edit_mesh); + me->edit_mesh= NULL; + } + + WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); + + return OPERATOR_FINISHED; +} + +void MESH_OT_drop_named_image(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Assign Image to UV Texture"; + ot->description= "Assigns Image to active UV layer, or creates a UV layer"; + ot->idname= "MESH_OT_drop_named_image"; + + /* api callbacks */ + ot->poll= layers_poll; + ot->invoke= drop_named_image_invoke; + + /* flags */ + ot->flag= OPTYPE_UNDO; + + /* properties */ + RNA_def_string(ot->srna, "name", "Image", 24, "Name", "Image name to assign."); +} + static int uv_texture_remove_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; |