[Bf-blender-cvs] [8bab103f42f] greasepencil-object: WIP: Fisrt step to implement Vertex Groups
Antonio Vazquez
noreply at git.blender.org
Mon Jul 31 13:19:33 CEST 2017
Commit: 8bab103f42ffa0f2e73dd0e06ed3f6a77eb60019
Author: Antonio Vazquez
Date: Sun Jul 30 19:08:41 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB8bab103f42ffa0f2e73dd0e06ed3f6a77eb60019
WIP: Fisrt step to implement Vertex Groups
Still more work is required to use the vertex groups, but this commit add the data to bGPDspoint struct and basic functionalities.
===================================================================
M release/scripts/startup/bl_ui/properties_data_gpencil.py
M release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/deform.c
M source/blender/blenkernel/intern/gpencil.c
M source/blender/blenkernel/intern/object_deform.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/versioning_280.c
M source/blender/blenloader/intern/writefile.c
M source/blender/editors/gpencil/editaction_gpencil.c
M source/blender/editors/gpencil/gpencil_brush.c
M source/blender/editors/gpencil/gpencil_data.c
M source/blender/editors/gpencil/gpencil_edit.c
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_interpolate.c
M source/blender/editors/gpencil/gpencil_ops.c
M source/blender/editors/gpencil/gpencil_paint.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/include/ED_gpencil.h
M source/blender/editors/object/object_vgroup.c
M source/blender/makesdna/DNA_gpencil_types.h
M source/blender/makesdna/DNA_object_types.h
M source/blender/makesrna/intern/rna_gpencil.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_gpencil.py b/release/scripts/startup/bl_ui/properties_data_gpencil.py
index 0f2915414d5..d77275457c8 100644
--- a/release/scripts/startup/bl_ui/properties_data_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_data_gpencil.py
@@ -23,7 +23,8 @@ from bl_ui.properties_grease_pencil_common import (
GreasePencilDataPanel,
GreasePencilLayerOptionPanel,
GreasePencilOnionPanel,
- GreasePencilParentLayerPanel
+ GreasePencilParentLayerPanel,
+ GreasePencilVertexGroupPanel,
)
@@ -86,6 +87,11 @@ class DATA_PT_gpencilparentpanel(GreasePencilParentLayerPanel, Panel):
# NOTE: this is just a wrapper around the generic GP Panel
+class DATA_PT_gpencilvertexpanel(GreasePencilVertexGroupPanel, Panel):
+ bl_space_type = 'PROPERTIES'
+ bl_region_type = 'WINDOW'
+ bl_context = "data"
+ bl_label = "Vertex Groups"
class DATA_PT_gpencil_display(DataButtonsPanel, Panel):
bl_label = "Display"
@@ -115,6 +121,7 @@ classes = (
DATA_PT_gpencil_datapanel,
DATA_PT_gpencil_onionpanel,
DATA_PT_gpencil_layeroptionpanel,
+ DATA_PT_gpencilvertexpanel,
DATA_PT_gpencilparentpanel,
DATA_PT_gpencil_display,
)
diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index f80ec5e0363..e75d3c7c07c 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -1209,6 +1209,57 @@ class GreasePencilParentLayerPanel:
if parent and gpl.parent_type == 'BONE' and parent.type == 'ARMATURE':
sub.prop_search(gpl, "parent_bone", parent.data, "bones", text="")
+class GPENCIL_UL_vgroups(UIList):
+ def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
+ # assert(isinstance(item, bpy.types.VertexGroup))
+ vgroup = item
+ if self.layout_type in {'DEFAULT', 'COMPACT'}:
+ layout.prop(vgroup, "name", text="", emboss=False, icon_value=icon)
+ # icon = 'LOCKED' if vgroup.lock_weight else 'UNLOCKED'
+ # layout.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
+ elif self.layout_type == 'GRID':
+ layout.alignment = 'CENTER'
+ layout.label(text="", icon_value=icon)
+
+class GreasePencilVertexGroupPanel:
+ bl_label = "Vertex Groups"
+ bl_region_type = 'UI'
+
+ @classmethod
+ def poll(cls, context):
+ obj = context.object
+ return obj and obj.type == 'GPENCIL'
+
+ def draw(self, context):
+ layout = self.layout
+
+ ob = context.object
+ group = ob.vertex_groups.active
+
+ rows = 2
+ if group:
+ rows = 4
+
+ row = layout.row()
+ row.template_list("GPENCIL_UL_vgroups", "", ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
+
+ col = row.column(align=True)
+ col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
+ col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="").all = False
+
+ if ob.vertex_groups: # and (ob.mode == 'EDIT' or (ob.mode == 'WEIGHT_PAINT' and ob.type == 'MESH' and ob.data.use_paint_mask_vertex)):
+ row = layout.row()
+
+ sub = row.row(align=True)
+ sub.operator("gpencil.vertex_group_assign", text="Assign")
+ sub.operator("gpencil.vertex_group_remove_from", text="Remove")
+
+ sub = row.row(align=True)
+ sub.operator("gpencil.vertex_group_select", text="Select")
+ sub.operator("gpencil.vertex_group_deselect", text="Deselect")
+
+ layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
+
class GreasePencilPaletteColorPanel:
# subclass must set
@@ -1505,6 +1556,7 @@ classes = (
GPENCIL_MT_layer_specials,
GPENCIL_MT_brush_specials,
GPENCIL_MT_palettecolor_specials,
+ GPENCIL_UL_vgroups
)
if __name__ == "__main__": # only for live edit.
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 961c744bf88..b77aa009cfc 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -43,6 +43,7 @@ struct Main;
struct PaletteColor;
struct BoundBox;
struct Object;
+struct bDeformGroup;
struct GpencilNoiseModifierData;
struct GpencilSubdivModifierData;
struct GpencilThickModifierData;
@@ -55,6 +56,8 @@ struct GpencilLatticeModifierData;
/* ------------ Grease-Pencil API ------------------ */
+void BKE_gpencil_free_point_weights(struct bGPDspoint *pt);
+void BKE_gpencil_free_stroke_weights(struct bGPDstroke *gps);
void BKE_gpencil_free_stroke(struct bGPDstroke *gps);
bool BKE_gpencil_free_strokes(struct bGPDframe *gpf);
bool BKE_gpencil_free_layer_temp_data(struct bGPDlayer *gpl, struct bGPDframe *derived_gpf);
@@ -144,6 +147,13 @@ void BKE_gpencil_palettecolor_delete_allstrokes(struct bContext *C, struct Palet
struct BoundBox *BKE_gpencil_boundbox_get(struct Object *ob);
void BKE_gpencil_centroid_3D(struct bGPdata *gpd, float r_centroid[3]);
+/* vertex groups */
+float BKE_gpencil_vgroup_use_index(struct bGPDspoint *pt, int index);
+void BKE_gpencil_vgroup_remove(struct Object *ob, struct bDeformGroup *defgroup);
+struct bGPDweight *BKE_gpencil_vgroup_add_point_weight(struct bGPDspoint *pt, int index, float weight);
+bool BKE_gpencil_vgroup_remove_point_weight(struct bGPDspoint *pt, int index);
+void BKE_gpencil_stroke_weights_duplicate(struct bGPDstroke *gps_src, struct bGPDstroke *gps_dst);
+
/* modifiers */
void ED_gpencil_reset_modifiers(struct Object *ob);
bool ED_gpencil_has_geometry_modifiers(struct Object *ob);
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index 584942628fa..3fcabf47df6 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -74,7 +74,9 @@ bDeformGroup *BKE_defgroup_new(Object *ob, const char *name)
BLI_addtail(&ob->defbase, defgroup);
defgroup_unique_name(defgroup, ob);
- BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_NOCHECK);
+ if (ob->type != OB_GPENCIL) {
+ BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_NOCHECK);
+ }
return defgroup;
}
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 103b3dfdcd4..c4a49ad05a0 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -93,6 +93,25 @@ void BKE_gpencil_batch_cache_free(bGPdata *gpd)
/* GENERAL STUFF */
/* --------- Memory Management ------------ */
+/* clean vertex groups weights */
+void BKE_gpencil_free_point_weights(bGPDspoint *pt)
+{
+ if (pt == NULL) {
+ return;
+ }
+ MEM_SAFE_FREE(pt->weights);
+}
+
+void BKE_gpencil_free_stroke_weights(bGPDstroke *gps)
+{
+ if (gps == NULL) {
+ return;
+ }
+ for (int i = 0; i < gps->totpoints; ++i) {
+ bGPDspoint *pt = &gps->points[i];
+ BKE_gpencil_free_point_weights(pt);
+ }
+}
/* free stroke, doesn't unlink from any listbase */
void BKE_gpencil_free_stroke(bGPDstroke *gps)
@@ -100,10 +119,11 @@ void BKE_gpencil_free_stroke(bGPDstroke *gps)
if (gps == NULL) {
return;
}
-
/* free stroke memory arrays, then stroke itself */
- if (gps->points)
+ if (gps->points) {
+ BKE_gpencil_free_stroke_weights(gps);
MEM_freeN(gps->points);
+ }
if (gps->triangles)
MEM_freeN(gps->triangles);
@@ -765,6 +785,19 @@ bGPdata *BKE_gpencil_data_addnew(const char name[])
}
/* -------- Data Duplication ---------- */
+/* make a copy of a given gpencil point weights*/
+void BKE_gpencil_stroke_weights_duplicate(bGPDstroke *gps_src, bGPDstroke *gps_dst)
+{
+ if (gps_src == NULL) {
+ return;
+ }
+ for (int i = 0; i < gps_src->totpoints; ++i) {
+ bGPDspoint *pt_dst = &gps_dst->points[i];
+ bGPDspoint *pt_src = &gps_src->points[i];
+ pt_dst->weights = MEM_dupallocN(pt_src->weights);
+ }
+}
+
/* make a copy of a given gpencil frame */
bGPDframe *BKE_gpencil_frame_duplicate(const bGPDframe *gpf_src)
@@ -787,6 +820,8 @@ bGPDframe *BKE_gpencil_frame_duplicate(const bGPDframe *gpf_src)
/* make copy of source stroke, then adjust pointer to points too */
gps_dst = MEM_dupallocN(gps_src);
gps_dst->points = MEM_dupallocN(gps_src->points);
+ BKE_gpencil_stroke_weights_duplicate(gps_src, gps_dst);
+
gps_dst->triangles = MEM_dupallocN(gps_src->triangles);
gps_dst->flag |= GP_STROKE_RECALC_CACHES;
BLI_addtail(&gpf_dst->strokes, gps_dst);
@@ -817,6 +852,8 @@ bGPDframe *BKE_gpencil_frame_color_duplicate(const bGPDframe *gpf_src)
/* make copy of source stroke */
gps_dst = MEM_dupallocN(gps_src);
gps_dst->points = MEM_dupallocN(gps_src->points);
+ BKE_gpencil_stroke_weights_duplicate(gps_src, gps_dst);
+
gps_dst->triangles = MEM_dupallocN(gps_src->triangles);
gps_dst->palcolor = MEM_dupallocN(gps_src->palcolor);
BLI_addtail(&gpf_dst->strokes, gps_dst);
@@ -985,7 +1022,10 @@ void BKE_gpencil_frame_delete_laststroke(bGPDlayer *gpl, bGPDframe *gpf)
return;
/* free the stroke and its data */
- MEM_freeN(gps->points);
+ if (gps->points) {
+ BKE_gpencil_free_stroke_weights(gps);
+ MEM_freeN(gps->points);
+ }
MEM_freeN(gps->triangles);
BLI_freelinkN(&gpf->strokes, gps);
@@ -1464,7 +1504,10 @@ void BKE_gpencil_palettecolor_delete_allstrokes(bContext *C, PaletteColor *palco
gpsn = gps->next;
if (gps->palcolor == palcolor) {
- if (gps->points) MEM_freeN(gps->points);
+ if (gps->points) {
+ BKE_gpencil_free_stroke_weights(gps);
+ MEM_freeN(gps->points);
+ }
if (gps->triangles) MEM_freeN(gps->triangles);
BLI_freelinkN(&gpf->strokes, gps);
}
@@ -1656,6 +1699,93 @@ BoundBox *BKE_gpencil_boundbox_get(Object *ob)
return ob->bb;
}
+/******************** Vertex Groups **********************************/
+/* remove a vertex group */
+void BKE_gpencil_vgroup_remove(Object *ob, bDeformGroup *defgroup)
+{
+ /* Remove points data */
+
+ /* Remove the group */
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list