diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py index fba3fa9c635..ee6e432b1c8 100644 --- a/release/scripts/startup/bl_ui/properties_data_mesh.py +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py @@ -326,9 +326,9 @@ class DATA_PT_customdata(MeshButtonsPanel, Panel): # me = context.mesh col = layout.column(align=True) - # row = col.row(align=True) - # row.operator("mesh.customdata_add_sticky", icon='ZOOMIN') - col.operator("mesh.customdata_clear_sticky", icon='X') + row = col.row(align=True) + row.operator("mesh.customdata_create_sticky") + row.operator("mesh.customdata_clear_sticky", icon='X') col.operator("mesh.customdata_clear_mask", icon='X') col.operator("mesh.customdata_clear_skin", icon='X') diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index f186603d6ca..1417641e803 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -47,6 +47,8 @@ #include "BLI_array.h" #include "BLI_math.h" #include "BLI_edgehash.h" +#include "BLI_linklist.h" +#include "BLI_listbase.h" #include "BKE_context.h" #include "BKE_depsgraph.h" @@ -143,24 +145,10 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la int i, actindex, rndindex, cloneindex, stencilindex, tot; if (layer->type == CD_MLOOPCOL || layer->type == CD_MLOOPUV) { - if (me->edit_btmesh) { - data = &me->edit_btmesh->bm->ldata; - tot = me->edit_btmesh->bm->totloop; - } - else { - data = &me->ldata; - tot = me->totloop; - } + data = mesh_customdata_get_type(me, BM_LOOP, &tot); } else { - if (me->edit_btmesh) { - data = &me->edit_btmesh->bm->pdata; - tot = me->edit_btmesh->bm->totface; - } - else { - data = &me->pdata; - tot = me->totpoly; - } + data = mesh_customdata_get_type(me, BM_FACE, &tot); } index = CustomData_get_layer_index(data, type); @@ -761,38 +749,111 @@ void MESH_OT_vertex_color_remove(wmOperatorType *ot) /*********************** sticky operators ************************/ -/* FIXME - this operator is broken - only updates active but operates on selected */ -static int mesh_sticky_add_exec(bContext *C, wmOperator *UNUSED(op)) +static Object *mesh_customdata_get_camera_for_sticky(wmOperator *op, Scene *scene, View3D *v3d) +{ + /* report an error if we can't find the camera */ + + Object *camera = NULL; + if (scene->obedit) { + BKE_report(op->reports, RPT_ERROR, "Unable to make sticky in Edit Mode"); + } + else { + if (v3d) camera = V3D_CAMERA_LOCAL(v3d); + if (camera == NULL) camera = scene->camera; + + if (camera == NULL) { + BKE_report(op->reports, RPT_ERROR, "Need camera to make sticky"); + } + } + + return camera; +} + +static int mesh_customdata_add_sticky_selected_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); - Object *ob = ED_object_context(C); - Mesh *me = ob->data; + Object *camera = mesh_customdata_get_camera_for_sticky(op, scene, v3d); + LinkNode *objects = NULL; + LinkNode *ob_iter; - /* why is this commented out? */ -#if 0 - if (me->msticky) + if (camera == NULL) { return OPERATOR_CANCELLED; -#endif + } - RE_make_sticky(scene, v3d); + CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects) + { + if (ob->type == OB_MESH) { + BLI_linklist_prepend(&objects, ob); + } + } + CTX_DATA_END; - DAG_id_tag_update(&me->id, 0); - WM_event_add_notifier(C, NC_GEOM | ND_DATA, me); + if (objects == NULL) { + return OPERATOR_CANCELLED; + } + + RE_make_sticky(scene, camera, objects); + + for (ob_iter = objects; ob_iter; ob_iter = ob_iter->next) { + Object *ob = ob_iter->link; + DAG_id_tag_update(ob->data, 0); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); + } + + BLI_linklist_free(objects, NULL); return OPERATOR_FINISHED; } -void MESH_OT_customdata_add_sticky(wmOperatorType *ot) +void MESH_OT_customdata_create_sticky_selected(wmOperatorType *ot) { /* identifiers */ - ot->name = "Add Sticky"; - ot->description = "Add sticky UV texture layer"; - ot->idname = "MESH_OT_customdata_add_sticky"; - + ot->name = "Calculate Sticky for Selection"; + ot->description = "Calculate sticky UV texture layer from the camera on selected objects"; + ot->idname = "MESH_OT_customdata_create_sticky_selected"; + /* api callbacks */ ot->poll = layers_poll; - ot->exec = mesh_sticky_add_exec; + ot->exec = mesh_customdata_add_sticky_selected_exec; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +static int mesh_customdata_add_sticky_exec(bContext *C, wmOperator *op) +{ + Object *obedit = ED_object_context(C); + Scene *scene = CTX_data_scene(C); + View3D *v3d = CTX_wm_view3d(C); + Object *camera = mesh_customdata_get_camera_for_sticky(op, scene, v3d); + LinkNode objects = {NULL}; + + if (camera == NULL) { + return OPERATOR_CANCELLED; /* error is set */ + } + + objects.link = obedit; + objects.next = NULL; + + RE_make_sticky(scene, camera, &objects); + + DAG_id_tag_update(obedit->data, 0); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); + + return OPERATOR_FINISHED; +} + +void MESH_OT_customdata_create_sticky(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Calculate Sticky"; + ot->description = "Calculate sticky UV texture layer from the camera"; + ot->idname = "MESH_OT_customdata_create_sticky"; + + /* api callbacks */ + ot->poll = layers_poll; + ot->exec = mesh_customdata_add_sticky_exec; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h index 0f34815c06a..82da2aedd47 100644 --- a/source/blender/editors/mesh/mesh_intern.h +++ b/source/blender/editors/mesh/mesh_intern.h @@ -187,9 +187,10 @@ void MESH_OT_uv_texture_add(struct wmOperatorType *ot); void MESH_OT_uv_texture_remove(struct wmOperatorType *ot); void MESH_OT_vertex_color_add(struct wmOperatorType *ot); void MESH_OT_vertex_color_remove(struct wmOperatorType *ot); -void MESH_OT_customdata_add_sticky(struct wmOperatorType *ot); +void MESH_OT_customdata_create_sticky_selected(struct wmOperatorType *ot); +void MESH_OT_customdata_create_sticky(struct wmOperatorType *ot); void MESH_OT_customdata_clear_sticky(struct wmOperatorType *ot); -/* no add mask yet */ +/* no create_mask yet */ void MESH_OT_customdata_clear_mask(struct wmOperatorType *ot); void MESH_OT_customdata_clear_skin(struct wmOperatorType *ot); diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c index 14b27856c8b..840f0498e7e 100644 --- a/source/blender/editors/mesh/mesh_ops.c +++ b/source/blender/editors/mesh/mesh_ops.c @@ -143,7 +143,8 @@ void ED_operatortypes_mesh(void) WM_operatortype_append(MESH_OT_uv_texture_remove); WM_operatortype_append(MESH_OT_vertex_color_add); WM_operatortype_append(MESH_OT_vertex_color_remove); - WM_operatortype_append(MESH_OT_customdata_add_sticky); + WM_operatortype_append(MESH_OT_customdata_create_sticky_selected); + WM_operatortype_append(MESH_OT_customdata_create_sticky); WM_operatortype_append(MESH_OT_customdata_clear_sticky); WM_operatortype_append(MESH_OT_customdata_clear_mask); WM_operatortype_append(MESH_OT_customdata_clear_skin); diff --git a/source/blender/render/extern/include/RE_render_ext.h b/source/blender/render/extern/include/RE_render_ext.h index c07ed42332f..2a9a1becc42 100644 --- a/source/blender/render/extern/include/RE_render_ext.h +++ b/source/blender/render/extern/include/RE_render_ext.h @@ -39,10 +39,11 @@ /* called by meshtools */ struct View3D; struct Scene; +struct LinkNode; -void RE_make_sticky(struct Scene *scene, struct View3D *v3d); - -/* for radiosity module */ +void RE_make_sticky(struct Scene *scene, struct Object *camera, struct LinkNode *objects); + +/* for radiosity module */ struct RadView; struct RNode; struct Render; diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 81697cc55c3..d04cca8552c 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -41,6 +41,7 @@ #include "BLI_rand.h" #include "BLI_memarena.h" #include "BLI_ghash.h" +#include "BLI_linklist.h" #include "DNA_armature_types.h" #include "DNA_camera_types.h" @@ -5819,36 +5820,43 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, /* Sticky texture coords */ /* ------------------------------------------------------------------------- */ -void RE_make_sticky(Scene *scene, View3D *v3d) +static void re_make_sticky_object(Render *re, Object *ob) { - Object *ob; - Base *base; MVert *mvert; Mesh *me; MSticky *ms; - Render *re; - float ho[4], mat[4][4]; + float mat[4][4]; + float ho[4]; int a; - Object *camera= NULL; - if (v3d==NULL) { - printf("Need a 3d view to make sticky\n"); - return; + me = ob->data; + mvert = me->mvert; + + if (me->msticky) { + CustomData_free_layer_active(&me->vdata, CD_MSTICKY, me->totvert); } - if (v3d) camera= V3D_CAMERA_LOCAL(v3d); - if (camera == NULL) camera= scene->camera; + me->msticky = CustomData_add_layer(&me->vdata, CD_MSTICKY, CD_CALLOC, NULL, me->totvert); - if (camera==NULL) { - printf("Need camera to make sticky\n"); - return; + mult_m4_m4m4(mat, re->viewmat, ob->obmat); + + ms = me->msticky; + for (a=0; a < me->totvert; a++, ms++, mvert++) { + copy_v3_v3(ho, mvert->co); + mul_m4_v3(mat, ho); + projectverto(ho, re->winmat, ho); + ms->co[0] = ho[0] / ho[3]; + ms->co[1] = ho[1] / ho[3]; } - if (scene->obedit) { - printf("Unable to make sticky in Edit Mode\n"); - return; - } - - re= RE_NewRender("_make sticky_"); +} + +void RE_make_sticky(Scene *scene, Object *camera, LinkNode *objects) +{ + Render *re; + float mat[4][4]; + LinkNode *ob_iter; + + re = RE_NewRender("_make sticky_"); RE_InitState(re, NULL, &scene->r, NULL, scene->r.xsch, scene->r.ysch, NULL); /* use renderdata and camera to set viewplane */ @@ -5859,31 +5867,8 @@ void RE_make_sticky(Scene *scene, View3D *v3d) invert_m4_m4(mat, camera->obmat); RE_SetView(re, mat); - for (base= FIRSTBASE; base; base= base->next) { - if (TESTBASELIB(v3d, base)) { - if (base->object->type==OB_MESH) { - ob= base->object; - - me= ob->data; - mvert= me->mvert; - if (me->msticky) - CustomData_free_layer_active(&me->vdata, CD_MSTICKY, me->totvert); - me->msticky= CustomData_add_layer(&me->vdata, CD_MSTICKY, - CD_CALLOC, NULL, me->totvert); - - BKE_object_where_is_calc(scene, ob); - mult_m4_m4m4(mat, re->viewmat, ob->obmat); - - ms= me->msticky; - for (a=0; atotvert; a++, ms++, mvert++) { - copy_v3_v3(ho, mvert->co); - mul_m4_v3(mat, ho); - projectverto(ho, re->winmat, ho); - ms->co[0]= ho[0]/ho[3]; - ms->co[1]= ho[1]/ho[3]; - } - } - } + for (ob_iter = objects; ob_iter; ob_iter = ob_iter->next) { + re_make_sticky_object(re, ob_iter->link); } }