[Bf-blender-cvs] [7168f8a] temp-material-remap: add support for non-editmode text
Campbell Barton
noreply at git.blender.org
Mon Apr 27 22:34:01 CEST 2015
Commit: 7168f8ae12b4780e3c6acac93da4630db3f7c8d2
Author: Campbell Barton
Date: Tue Apr 28 06:33:30 2015 +1000
Branches: temp-material-remap
https://developer.blender.org/rB7168f8ae12b4780e3c6acac93da4630db3f7c8d2
add support for non-editmode text
also correct remapping range check
===================================================================
M source/blender/blenkernel/BKE_material.h
M source/blender/blenkernel/intern/material.c
M source/blender/editors/render/render_shading.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h
index f8c658a..6cc9465b 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -50,7 +50,7 @@ void BKE_material_free_ex(struct Material *ma, bool do_id_user);
void test_object_materials(struct Main *bmain, struct ID *id);
void BKE_material_resize_object(struct Object *ob, const short totcol, bool do_id_user);
void init_material(struct Material *ma);
-void BKE_material_id_remap(struct Object *ob, unsigned int remap[]);
+void BKE_material_remap_object(struct Object *ob, unsigned int remap[]);
struct Material *BKE_material_add(struct Main *bmain, const char *name);
struct Material *BKE_material_copy(struct Material *ma);
struct Material *localize_material(struct Material *ma);
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index c50d52f..109e0d3 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -926,38 +926,45 @@ void assign_material(Object *ob, Material *ma, short act, int assign_type)
}
-void BKE_material_id_remap(Object *ob, unsigned int remap[])
+void BKE_material_remap_object(Object *ob, unsigned int remap[])
{
- short mat_nr_max = ob->totcol;
+ Material ***matar = give_matarar(ob);
+ const short *totcol_p = give_totcolp(ob);
+ const short mat_nr_max = ob->totcol;
BLI_array_permute(ob->mat, ob->totcol, remap);
- if (ob->matbits)
+
+ if (ob->matbits) {
BLI_array_permute(ob->matbits, ob->totcol, remap);
+ }
- Material ***matarrar = give_matarar(ob);
- if(matarrar)
- BLI_array_permute(*matarrar, ob->totcol, remap);
+ if(matar) {
+ BLI_array_permute(*matar, *totcol_p, remap);
+ }
/* Now reassign the new material order to the affected items in the object*/
if (ob->type == OB_MESH) {
-
if (ob->mode == OB_MODE_EDIT) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
- BMFace *efa;
- BMIter iter;
if (em) {
+ BMIter iter;
+ BMFace *efa;
+
BM_ITER_MESH(efa, &iter, em->bm, BM_FACES_OF_MESH) {
- if (remap[efa->mat_nr] < mat_nr_max)
+ if (efa->mat_nr < mat_nr_max) {
efa->mat_nr = remap[efa->mat_nr];
+ }
}
}
}
else {
Mesh *me = ob->data;
- for (int index = 0; index < me->totpoly; index++)
- if (remap[me->mpoly[index].mat_nr] < mat_nr_max)
+ for (int index = 0; index < me->totpoly; index++) {
+ if (me->mpoly[index].mat_nr < mat_nr_max) {
me->mpoly[index].mat_nr = remap[me->mpoly[index].mat_nr];
+ }
+ }
}
}
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
@@ -965,19 +972,38 @@ void BKE_material_id_remap(Object *ob, unsigned int remap[])
ListBase *nurbs = BKE_curve_editNurbs_get((Curve *)ob->data);
if (nurbs) {
- for (nu = nurbs->first; nu; nu = nu->next)
- if (remap[nu->charidx] < mat_nr_max)
- nu->mat_nr = remap[nu->charidx];
+ for (nu = nurbs->first; nu; nu = nu->next) {
+ if (nu->mat_nr < mat_nr_max) {
+ nu->mat_nr = remap[nu->mat_nr];
+ }
+ }
}
}
else if (ob->type == OB_FONT) {
- EditFont *ef = ((Curve *)ob->data)->editfont;
- if (ef) {
- for (int i = 0; i <= ef->len; i++)
- if (remap[ef->textbufinfo[i].mat_nr] < mat_nr_max)
- ef->textbufinfo[i].mat_nr = remap[ef->textbufinfo[i].mat_nr];
+ Curve *cu = ob->data;
+ struct CharInfo *strinfo;
+ int charinfo_len;
+
+ if (cu->editfont) {
+ EditFont *ef = cu->editfont;
+ strinfo = ef->textbufinfo;
+ charinfo_len = ef->len;
+ }
+ else {
+ strinfo = cu->strinfo;
+ charinfo_len = cu->len_wchar;
+ }
+
+ for (int i = 0; i <= charinfo_len; i++) {
+ if (strinfo[i].mat_nr < mat_nr_max) {
+ strinfo[i].mat_nr = remap[strinfo[i].mat_nr];
+ }
}
}
+ else {
+ /* add support for this object data! */
+ BLI_assert(matar == NULL);
+ }
}
diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c
index b854664..2ea49e3 100644
--- a/source/blender/editors/render/render_shading.c
+++ b/source/blender/editors/render/render_shading.c
@@ -386,37 +386,43 @@ static int material_slot_move_exec(bContext *C, wmOperator *op)
{
Object *ob = ED_object_context(C);
- unsigned int *slotremap;
+ unsigned int *slot_remap;
+ int index_a, index_b;
int dir = RNA_enum_get(op->ptr, "direction");
- if (!ob || ob->totcol ==0) {
+ if (!ob || ob->totcol < 2) {
return OPERATOR_CANCELLED;
}
- slotremap = MEM_mallocN(sizeof(unsigned int) * ob->totcol, "Temp remap array BKE_material_id_remap");
- for (int index = 0; index < ob->totcol; index++)
- slotremap[index] = index;
-
/* up */
if (dir == 1 && ob->actcol > 1) {
- slotremap[ob->actcol - 2] = ob->actcol - 1;
- slotremap[ob->actcol - 1] = ob->actcol - 2;
+ index_a = ob->actcol - 2;
+ index_b = ob->actcol - 1;
ob->actcol--;
}
/* down */
else if (dir == -1 && ob->actcol < ob->totcol) {
- slotremap[ob->actcol - 1] = ob->actcol - 0;
- slotremap[ob->actcol - 0] = ob->actcol - 1;
+ index_a = ob->actcol - 1;
+ index_b = ob->actcol - 0;
ob->actcol++;
}
else {
- MEM_freeN(slotremap);
return OPERATOR_CANCELLED;
}
- BKE_material_id_remap(ob, slotremap);
- MEM_freeN(slotremap);
+ slot_remap = MEM_mallocN(sizeof(unsigned int) * ob->totcol, __func__);
+
+ for (int index = 0; index < ob->totcol; index++) {
+ slot_remap[index] = index;
+ }
+
+ slot_remap[index_a] = index_b;
+ slot_remap[index_b] = index_a;
+
+ BKE_material_remap_object(ob, slot_remap);
+
+ MEM_freeN(slot_remap);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW | ND_DATA, ob);
More information about the Bf-blender-cvs
mailing list