302
335
/* could be ldata or pdata */
303
336
CustomData *pdata = GET_CD_DATA(me, pdata);
304
337
const int layernum = CustomData_get_active_layer_index(pdata, CD_MTEXPOLY);
305
return ED_mesh_uv_loop_reset_ex(C, me, layernum);
338
int retval = ED_mesh_uv_loop_reset_ex(me, layernum);
340
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
308
345
/* note: keep in sync with ED_mesh_color_add */
309
346
int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_set)
314
351
short is_init = FALSE;
316
353
if (me->edit_btmesh) {
317
354
em = me->edit_btmesh;
319
layernum = CustomData_number_of_layers(&em->bm->pdata, CD_MTEXPOLY);
320
if (layernum >= MAX_MTFACE)
356
layernum_dst = CustomData_number_of_layers(&em->bm->pdata, CD_MTEXPOLY);
357
if (layernum_dst >= MAX_MTFACE)
323
360
/* CD_MTEXPOLY */
324
361
BM_data_layer_add_named(em->bm, &em->bm->pdata, CD_MTEXPOLY, name);
325
362
/* copy data from active UV */
327
const int layernum_dst = CustomData_get_active_layer(&em->bm->pdata, CD_MTEXPOLY);
328
BM_data_layer_copy(em->bm, &em->bm->pdata, CD_MTEXPOLY, layernum, layernum_dst);
364
const int layernum_src = CustomData_get_active_layer(&em->bm->pdata, CD_MTEXPOLY);
365
BM_data_layer_copy(em->bm, &em->bm->pdata, CD_MTEXPOLY, layernum_src, layernum_dst);
330
if (active_set || layernum == 0) {
331
CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum);
367
if (active_set || layernum_dst == 0) {
368
CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum_dst);
335
372
BM_data_layer_add_named(em->bm, &em->bm->ldata, CD_MLOOPUV, name);
336
373
/* copy data from active UV */
338
const int layernum_dst = CustomData_get_active_layer(&em->bm->ldata, CD_MLOOPUV);
339
BM_data_layer_copy(em->bm, &em->bm->ldata, CD_MLOOPUV, layernum, layernum_dst);
375
const int layernum_src = CustomData_get_active_layer(&em->bm->ldata, CD_MLOOPUV);
376
BM_data_layer_copy(em->bm, &em->bm->ldata, CD_MLOOPUV, layernum_src, layernum_dst);
343
if (active_set || layernum == 0) {
344
CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPUV, layernum);
380
if (active_set || layernum_dst == 0) {
381
CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPUV, layernum_dst);
348
layernum = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
349
if (layernum >= MAX_MTFACE)
385
layernum_dst = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
386
if (layernum_dst >= MAX_MTFACE)
352
389
if (me->mtpoly) {
361
398
CustomData_add_layer_named(&me->fdata, CD_MTFACE, CD_DEFAULT, NULL, me->totface, name);
364
if (active_set || layernum == 0) {
365
CustomData_set_layer_active(&me->pdata, CD_MTEXPOLY, layernum);
366
CustomData_set_layer_active(&me->ldata, CD_MLOOPUV, layernum);
401
if (active_set || layernum_dst == 0) {
402
CustomData_set_layer_active(&me->pdata, CD_MTEXPOLY, layernum_dst);
403
CustomData_set_layer_active(&me->ldata, CD_MLOOPUV, layernum_dst);
368
CustomData_set_layer_active(&me->fdata, CD_MTFACE, layernum);
405
CustomData_set_layer_active(&me->fdata, CD_MTFACE, layernum_dst);
371
408
mesh_update_customdata_pointers(me, TRUE);
538
575
Main *bmain = CTX_data_main(C);
539
576
Scene *scene = CTX_data_scene(C);
540
577
View3D *v3d = CTX_wm_view3d(C);
541
Base *base = ED_view3d_give_base_under_cursor(C, event->mval);
542
579
Image *ima = NULL;
545
582
int exitmode = 0;
546
char name[MAX_ID_NAME - 2];
585
BKE_report(op->reports, RPT_ERROR, "No 3D View Available");
586
return OPERATOR_CANCELLED;
589
base = ED_view3d_give_base_under_cursor(C, event->mval);
548
591
/* Check context */
549
592
if (base == NULL || base->object->type != OB_MESH) {
550
BKE_report(op->reports, RPT_ERROR, "Not an Object or Mesh");
593
BKE_report(op->reports, RPT_ERROR, "Not an object or mesh");
551
594
return OPERATOR_CANCELLED;
701
745
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
704
/*********************** sticky operators ************************/
706
static int mesh_sticky_add_exec(bContext *C, wmOperator *UNUSED(op))
708
Scene *scene = CTX_data_scene(C);
709
View3D *v3d = CTX_wm_view3d(C);
748
/* *** CustomData clear functions, we need an operator for each *** */
750
static int mesh_customdata_clear_exec__internal(bContext *C,
751
char htype, int type)
753
Object *obedit = ED_object_context(C);
754
Mesh *me = obedit->data;
757
CustomData *data = mesh_customdata_get_type(me, htype, &tot);
759
BLI_assert(CustomData_layertype_is_singleton(type) == TRUE);
761
if (CustomData_has_layer(data, type)) {
762
if (me->edit_btmesh) {
763
BM_data_layer_free(me->edit_btmesh->bm, data, type);
766
CustomData_free_layers(data, type, tot);
769
DAG_id_tag_update(&me->id, 0);
770
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
772
return OPERATOR_FINISHED;
775
return OPERATOR_CANCELLED;
780
static int mesh_customdata_clear_mask_poll(bContext *C)
710
782
Object *ob = ED_object_context(C);
713
/* why is this commented out? */
783
if (ob && ob->type == OB_MESH) {
786
/* special case - can't run this if we're in sculpt mode */
787
if (ob->mode & OB_MODE_SCULPT) {
791
if (me->id.lib == NULL) {
792
CustomData *data = GET_CD_DATA(me, vdata);
793
if (CustomData_has_layer(data, CD_PAINT_MASK)) {
796
data = GET_CD_DATA(me, ldata);
797
if (CustomData_has_layer(data, CD_GRID_PAINT_MASK)) {
804
static int mesh_customdata_clear_mask_exec(bContext *C, wmOperator *UNUSED(op))
806
int ret_a = mesh_customdata_clear_exec__internal(C, BM_VERT, CD_PAINT_MASK);
807
int ret_b = mesh_customdata_clear_exec__internal(C, BM_LOOP, CD_GRID_PAINT_MASK);
809
if (ret_a == OPERATOR_FINISHED ||
810
ret_b == OPERATOR_FINISHED)
812
return OPERATOR_FINISHED;
716
815
return OPERATOR_CANCELLED;
719
RE_make_sticky(scene, v3d);
721
DAG_id_tag_update(&me->id, 0);
722
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
724
return OPERATOR_FINISHED;
727
void MESH_OT_sticky_add(wmOperatorType *ot)
819
void MESH_OT_customdata_clear_mask(wmOperatorType *ot)
729
822
/* identifiers */
730
ot->name = "Add Sticky";
731
ot->description = "Add sticky UV texture layer";
732
ot->idname = "MESH_OT_sticky_add";
823
ot->name = "Clear Sculpt-Mask Data";
824
ot->idname = "MESH_OT_customdata_clear_mask";
825
ot->description = "Clear vertex sculpt masking data from the mesh";
734
827
/* api callbacks */
735
ot->poll = layers_poll;
736
ot->exec = mesh_sticky_add_exec;
828
ot->exec = mesh_customdata_clear_mask_exec;
829
ot->poll = mesh_customdata_clear_mask_poll;
739
832
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
742
static int mesh_sticky_remove_exec(bContext *C, wmOperator *UNUSED(op))
836
static int mesh_customdata_clear_skin_poll(bContext *C)
744
838
Object *ob = ED_object_context(C);
748
return OPERATOR_CANCELLED;
750
CustomData_free_layer_active(&me->vdata, CD_MSTICKY, me->totvert);
753
DAG_id_tag_update(&me->id, 0);
754
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
756
return OPERATOR_FINISHED;
759
void MESH_OT_sticky_remove(wmOperatorType *ot)
840
if (ob && ob->type == OB_MESH) {
842
if (me->id.lib == NULL) {
843
CustomData *data = GET_CD_DATA(me, vdata);
844
if (CustomData_has_layer(data, CD_MVERT_SKIN)) {
851
static int mesh_customdata_clear_skin_exec(bContext *C, wmOperator *UNUSED(op))
853
return mesh_customdata_clear_exec__internal(C, BM_VERT, CD_MVERT_SKIN);
856
void MESH_OT_customdata_clear_skin(wmOperatorType *ot)
761
858
/* identifiers */
762
ot->name = "Remove Sticky";
763
ot->description = "Remove sticky UV texture layer";
764
ot->idname = "MESH_OT_sticky_remove";
859
ot->name = "Clear Skin Data";
860
ot->idname = "MESH_OT_customdata_clear_skin";
861
ot->description = "Clear vertex skin layer";
766
863
/* api callbacks */
767
ot->poll = layers_poll;
768
ot->exec = mesh_sticky_remove_exec;
864
ot->exec = mesh_customdata_clear_skin_exec;
865
ot->poll = mesh_customdata_clear_skin_poll;
771
868
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
803
900
* so rather then add poly-index layer and calculate normals for it
804
901
* calculate normals only for the mvert's. - campbell */
805
902
#ifdef USE_BMESH_MPOLY_NORMALS
806
polyindex = CustomData_get_layer(&mesh->fdata, CD_POLYINDEX);
903
polyindex = CustomData_get_layer(&mesh->fdata, CD_ORIGINDEX);
807
904
/* add a normals layer for tessellated faces, a tessface normal will
808
905
* contain the normal of the poly the face was tessellated from. */
809
906
face_nors = CustomData_add_layer(&mesh->fdata, CD_NORMAL, CD_CALLOC, NULL, mesh->totface);
811
mesh_calc_normals_mapping_ex(mesh->mvert, mesh->totvert,
812
mesh->mloop, mesh->mpoly,
813
mesh->totloop, mesh->totpoly,
814
NULL /* polyNors_r */,
815
mesh->mface, mesh->totface,
816
polyindex, face_nors, FALSE);
908
BKE_mesh_calc_normals_mapping_ex(mesh->mvert, mesh->totvert,
909
mesh->mloop, mesh->mpoly,
910
mesh->totloop, mesh->totpoly,
911
NULL /* polyNors_r */,
912
mesh->mface, mesh->totface,
913
polyindex, face_nors, FALSE);
818
mesh_calc_normals(mesh->mvert, mesh->totvert,
819
mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly,
915
BKE_mesh_calc_normals(mesh->mvert, mesh->totvert,
916
mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly,
1138
1236
void ED_mesh_calc_normals(Mesh *mesh)
1140
1238
#ifdef USE_BMESH_MPOLY_NORMALS
1141
mesh_calc_normals_mapping_ex(mesh->mvert, mesh->totvert,
1142
mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly,
1143
NULL, NULL, 0, NULL, NULL, FALSE);
1239
BKE_mesh_calc_normals_mapping_ex(mesh->mvert, mesh->totvert,
1240
mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly,
1241
NULL, NULL, 0, NULL, NULL, FALSE);
1145
mesh_calc_normals(mesh->mvert, mesh->totvert,
1146
mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly,
1243
BKE_mesh_calc_normals(mesh->mvert, mesh->totvert,
1244
mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly,