Commit: 2ab102fbd5d9b867af884fb9b85b45237a297248
Author: Julian Eisel
Date:   Sat May 21 01:08:01 2016 +0200
Branches: temp_facegroups
https://developer.blender.org/rB2ab102fbd5d9b867af884fb9b85b45237a297248

Added face map UI, operators and RNA defines

Added as in - copy & paste from Antony's work in wiggly-widgets ;)

===================================================================

M       release/scripts/startup/bl_ui/properties_data_mesh.py
M       source/blender/blenkernel/intern/facegroup.c
M       source/blender/blenkernel/intern/object.c
M       source/blender/editors/include/ED_mesh.h
M       source/blender/editors/object/CMakeLists.txt
A       source/blender/editors/object/object_fmap.c
M       source/blender/editors/object/object_intern.h
M       source/blender/editors/object/object_ops.c
M       source/blender/makesrna/RNA_access.h
M       source/blender/makesrna/intern/rna_object.c
M       source/blenderplayer/bad_level_call_stubs/stubs.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py 
b/release/scripts/startup/bl_ui/properties_data_mesh.py
index 5416735..2b926d4 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -75,6 +75,17 @@ class MESH_UL_vgroups(UIList):
             layout.label(text="", icon_value=icon)
 
 
+class MESH_UL_fmaps(UIList):
+    def draw_item(self, context, layout, data, item, icon, active_data, 
active_propname, index):
+        # assert(isinstance(item, bpy.types.VertexGroup))
+        fmap = item
+        if self.layout_type in {'DEFAULT', 'COMPACT'}:
+            layout.prop(fmap, "name", text="", emboss=False, icon_value=icon)
+        elif self.layout_type in {'GRID'}:
+            layout.alignment = 'CENTER'
+            layout.label(text="", icon_value=icon)
+
+
 class MESH_UL_shape_keys(UIList):
     def draw_item(self, context, layout, data, item, icon, active_data, 
active_propname, index):
         # assert(isinstance(item, bpy.types.ShapeKey))
@@ -226,6 +237,48 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
             layout.prop(context.tool_settings, "vertex_group_weight", 
text="Weight")
 
 
+class DATA_PT_face_maps(MeshButtonsPanel, Panel):
+    bl_label = "Face Maps"
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
+
+    @classmethod
+    def poll(cls, context):
+        obj = context.object
+        return (obj and obj.type == 'MESH')
+
+    def draw(self, context):
+        layout = self.layout
+
+        ob = context.object
+        facemap = ob.face_maps.active
+
+        rows = 2
+        if facemap:
+            rows = 4
+
+        row = layout.row()
+        row.template_list("MESH_UL_fmaps", "", ob, "face_maps", ob.face_maps, 
"active_index", rows=rows)
+
+        col = row.column(align=True)
+        col.operator("object.face_map_add", icon='ZOOMIN', text="")
+        col.operator("object.face_map_remove", icon='ZOOMOUT', text="")
+        if facemap:
+            col.separator()
+            col.operator("object.face_map_move", icon='TRIA_UP', 
text="").direction = 'UP'
+            col.operator("object.face_map_move", icon='TRIA_DOWN', 
text="").direction = 'DOWN'
+
+        if ob.face_maps and (ob.mode == 'EDIT' and ob.type == 'MESH'):
+            row = layout.row()
+
+            sub = row.row(align=True)
+            sub.operator("object.face_map_assign", text="Assign")
+            sub.operator("object.face_map_remove_from", text="Remove")
+
+            sub = row.row(align=True)
+            sub.operator("object.face_map_select", text="Select")
+            sub.operator("object.face_map_deselect", text="Deselect")
+
+
 class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
     bl_label = "Shape Keys"
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
diff --git a/source/blender/blenkernel/intern/facegroup.c 
b/source/blender/blenkernel/intern/facegroup.c
index eaecdc4..8af52f2 100644
--- a/source/blender/blenkernel/intern/facegroup.c
+++ b/source/blender/blenkernel/intern/facegroup.c
@@ -32,9 +32,6 @@
 #include "DNA_object_types.h"
 #include "DNA_mesh_types.h"
 
-#include "WM_types.h"
-#include "WM_api.h"
-
 #include "BKE_context.h"
 #include "BKE_customdata.h"
 #include "BKE_facegroup.h"
diff --git a/source/blender/blenkernel/intern/object.c 
b/source/blender/blenkernel/intern/object.c
index 65ee153..aed206d 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -86,6 +86,7 @@
 #include "BKE_curve.h"
 #include "BKE_displist.h"
 #include "BKE_effect.h"
+#include "BKE_facegroup.h"
 #include "BKE_fcurve.h"
 #include "BKE_group.h"
 #include "BKE_icons.h"
@@ -1539,6 +1540,7 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, bool 
copy_caches)
                        BKE_pose_rebuild(obn, obn->data);
        }
        defgroup_copy_list(&obn->defbase, &ob->defbase);
+       fmap_copy_list(&obn->fmaps, &ob->fmaps);
        BKE_constraints_copy(&obn->constraints, &ob->constraints, true);
 
        obn->mode = OB_MODE_OBJECT;
diff --git a/source/blender/editors/include/ED_mesh.h 
b/source/blender/editors/include/ED_mesh.h
index de798b1..30b702f 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -39,6 +39,7 @@ struct ID;
 struct View3D;
 struct ARegion;
 struct bContext;
+struct bFaceMap;
 struct wmOperator;
 struct wmKeyConfig;
 struct ReportList;
@@ -260,6 +261,10 @@ float                ED_vgroup_vert_weight(struct Object 
*ob, struct bDeformGrou
 void                 ED_vgroup_vert_active_mirror(struct Object *ob, int 
def_nr);
 
 
+/* object_fmap.c */
+void ED_fmap_face_add(struct Object *ob, struct bFaceMap *fmap, int facenum);
+void ED_fmap_face_remove(struct Object *ob, struct bFaceMap *fmap, int 
facenum);
+
 /* mesh_data.c */
 // void ED_mesh_geometry_add(struct Mesh *mesh, struct ReportList *reports, 
int verts, int edges, int faces);
 void ED_mesh_polys_add(struct Mesh *mesh, struct ReportList *reports, int 
count);
diff --git a/source/blender/editors/object/CMakeLists.txt 
b/source/blender/editors/object/CMakeLists.txt
index b3d02d4..60f4766 100644
--- a/source/blender/editors/object/CMakeLists.txt
+++ b/source/blender/editors/object/CMakeLists.txt
@@ -46,6 +46,7 @@ set(SRC
        object_bake_api.c
        object_constraint.c
        object_edit.c
+       object_fmap.c
        object_group.c
        object_hook.c
        object_lattice.c
diff --git a/source/blender/editors/object/object_fmap.c 
b/source/blender/editors/object/object_fmap.c
new file mode 100644
index 0000000..fee01a4
--- /dev/null
+++ b/source/blender/editors/object/object_fmap.c
@@ -0,0 +1,495 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/object/object_fmap.c
+ *  \ingroup edobj
+ */
+
+#include <string.h>
+
+#include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
+
+#include "WM_types.h"
+#include "WM_api.h"
+
+#include "BKE_context.h"
+#include "BKE_customdata.h"
+#include "BKE_facegroup.h"
+#include "BKE_editmesh.h"
+#include "BKE_object.h"
+#include "BKE_object_deform.h"
+
+#include "BKE_depsgraph.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_listbase.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "ED_mesh.h"
+#include "ED_object.h"
+
+#include "RNA_define.h"
+#include "RNA_access.h"
+
+#include "object_intern.h"
+
+/* called while not in editmode */
+void ED_fmap_face_add(Object *ob, bFaceMap *fmap, int facenum)
+{
+       int fmap_nr;
+       if (GS(((ID *)ob->data)->name) != ID_ME)
+               return;
+
+       /* get the face map number, exit if it can't be found */
+       fmap_nr = BLI_findindex(&ob->fmaps, fmap);
+
+       if (fmap_nr != -1) {
+               int *facemap;
+               Mesh *me = ob->data;
+
+               /* if there's is no facemap layer then create one */
+               if ((facemap = CustomData_get_layer(&me->pdata, CD_FACEMAP)) == 
NULL)
+                       facemap = CustomData_add_layer(&me->pdata, CD_FACEMAP, 
CD_DEFAULT, NULL, me->totpoly);
+
+               facemap[facenum] = fmap_nr;
+       }
+}
+
+/* called while not in editmode */
+void ED_fmap_face_remove(Object *ob, bFaceMap *fmap, int facenum)
+{
+       int fmap_nr;
+       if (GS(((ID *)ob->data)->name) != ID_ME)
+               return;
+
+       /* get the face map number, exit if it can't be found */
+       fmap_nr = BLI_findindex(&ob->fmaps, fmap);
+
+       if (fmap_nr != -1) {
+               int *facemap;
+               Mesh *me = ob->data;
+
+               /* if there's is no facemap layer then create one */
+               if ((facemap = CustomData_get_layer(&me->pdata, CD_FACEMAP)) == 
NULL)
+                       return;
+
+               facemap[facenum] = -1;
+       }
+}
+
+static void object_fmap_swap_edit_mode(Object *ob, int num1, int num2)
+{
+       if (ob->type == OB_MESH) {
+               Mesh *me = ob->data;
+
+               if (me->edit_btmesh) {
+                       BMEditMesh *em = me->edit_btmesh;
+                       const int cd_fmap_offset = 
CustomData_get_offset(&em->bm->pdata, CD_FACEMAP);
+
+                       if (cd_fmap_offset != -1) {
+                               BMFace *efa;
+                               BMIter iter;
+                               int *map;
+
+                               BM_ITER_MESH (efa, &iter, em->bm, 
BM_FACES_OF_MESH) {
+                                       map = BM_ELEM_CD_GET_VOID_P(efa, 
cd_fmap_offset);
+
+                                       if (map) {
+                                               if (num1 != -1) {
+                                                       if (*map == num1)
+                                                               *map = num2;
+                                                       else if (*map == num2)
+                                                               *map = num1;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
+static void object_fmap_swap_object_mode(Object *ob, int num1, int num2)
+{
+       if (ob->type == OB_MESH) {
+               Mesh *me = ob->data;
+
+               if (CustomData_has_layer(&me->pdata, CD_FACEMAP)) {
+                       int *map = CustomData_get_layer(&me->pdata, CD_FACEMAP);
+                       int i;
+
+                       if (map) {
+                               for (i = 0; i < me->totpoly; i++) {
+                                       if (num1 != -1) {
+                                               if (map[i] == num1)
+                                                       map[i] = num2;
+                                               else if (map[i]== num2)
+                                                       map[i] = num1;
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
+static void object_facemap_swap(Object *ob, int num1, int num2)
+{
+       if (BKE_object_is_in_editmode(ob))
+               object_fmap_swap_edit_mode(ob, num1, num2);
+       else
+               object_fmap_swap_object_mode(ob, num1, num2);
+}
+
+static int face_map_supported_poll(bContext *C)
+{
+       Object *ob = ED_object_context(C);
+       ID *data = (ob) ? ob->data : NULL;
+       return (ob && !ob->id.lib && ob->type == OB_MESH && data && !data->lib);
+}
+
+static int face_map_supported_edit_mode_poll(bContext *C)
+{
+       Object *ob = ED_object_context(C);
+       ID *data = (ob) ? ob->data : NULL;
+       return (ob && !ob->id.lib && ob->type == OB_MESH && data && !data->lib 
&& ob->mode == OB_MODE_EDIT);
+}
+
+static int face_map_add_exec(bContext

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to