[Bf-blender-cvs] [a41bef88abd] asset-greasepencil: GPencil: Cleanup of function names, variables and comments
Antonio Vazquez
noreply at git.blender.org
Tue Jul 20 18:03:05 CEST 2021
Commit: a41bef88abd3d873a080423481a5557d54a7ce24
Author: Antonio Vazquez
Date: Tue Jul 20 18:02:06 2021 +0200
Branches: asset-greasepencil
https://developer.blender.org/rBa41bef88abd3d873a080423481a5557d54a7ce24
GPencil: Cleanup of function names, variables and comments
Also some code reorganization.
===================================================================
M source/blender/editors/gpencil/gpencil_asset.c
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_asset.c b/source/blender/editors/gpencil/gpencil_asset.c
index 85c7a6e7b33..96fc91f6a0d 100644
--- a/source/blender/editors/gpencil/gpencil_asset.c
+++ b/source/blender/editors/gpencil/gpencil_asset.c
@@ -13,9 +13,6 @@
* 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) 2021, Blender Foundation
- * This is a new part of Blender
- * Operators for editing Grease Pencil strokes
*/
/** \file
@@ -108,36 +105,40 @@ typedef struct tGPDasset {
rctf rect_cage;
/** 2D cage center. */
float cage_center[2];
- /** Transform centerr. */
+ /** Normal vector for cage. */
+ float cage_normal[3];
+ /** Transform center. */
float transform_center[2];
+
/** 2D cage manipulator points *
*
- * 8 9 (Rotation)
+ * NW-R NE-R (Rotation)
* \ /
- * 0----1----2
- * | |
- * 7 3
- * | |
- * 6----5----4
+ * NW----N----NE
+ * | |
+ * W E
+ * | |
+ * SW----S----SE
* / \
- * 11 10
+ * SW-R SE-R
*/
float manipulator[12][2];
/** Manipulator index (-1 means not set). */
int manipulator_index;
/** Manipulator vector used to determine the effect. */
float manipulator_vector[3];
- /** Normal vector for cage. */
- float normal_vec[3];
/** Vector with the original orientation for rotation. */
float vinit_rotation[2];
+ /* All the hash below are used to keep a reference of the asset data inserted in the target
+ * object. */
+
/** Hash of new created layers. */
struct GHash *asset_layers;
/** Hash of new created frames. */
struct GHash *asset_frames;
- /** Hash of new created strokes. */
- struct GHash *asset_strokes;
+ /** Hash of new created strokes linked to frame. */
+ struct GHash *asset_strokes_frame;
/** Hash of new created strokes linked to layer. */
struct GHash *asset_strokes_layer;
/** Hash of new created materials. */
@@ -318,8 +319,8 @@ void GPENCIL_OT_asset_create(wmOperatorType *ot)
RNA_def_boolean(ot->srna,
"reset_origin",
1,
- "Reset Origin to Strokes",
- "Set origin of the strokes in the center of the bounding box");
+ "Reset Origin to Geometry",
+ "Set origin of the asset in the center of the strokes bounding box");
}
/** \} */
@@ -336,177 +337,6 @@ static void gpencil_asset_import_update_strokes(bContext *C, tGPDasset *tgpa)
WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);
}
-/* Helper: Draw status message while the user is running the operator */
-static void gpencil_asset_import_status_indicators(bContext *C, tGPDasset *tgpa)
-{
- char status_str[UI_MAX_DRAW_STR];
- char msg_str[UI_MAX_DRAW_STR];
- bGPdata *gpd_asset = tgpa->gpd_asset;
- const char *mode_txt[] = {"", "(Location)", "(Rotation)", "(Scale)"};
-
- BLI_strncpy(msg_str, TIP_("Importing Asset"), UI_MAX_DRAW_STR);
-
- BLI_snprintf(status_str,
- sizeof(status_str),
- "%s %s %s",
- msg_str,
- gpd_asset->id.name + 2,
- mode_txt[tgpa->mode]);
-
- ED_area_status_text(tgpa->area, status_str);
- ED_workspace_status_text(
- C, TIP_("ESC/RMB to cancel, Enter/LMB(outside cage) to confirm, Shift to Scale uniform"));
-}
-
-/* Update screen and stroke */
-static void gpencil_asset_import_update(bContext *C, wmOperator *op, tGPDasset *tgpa)
-{
- /* Update shift indicator in header. */
- gpencil_asset_import_status_indicators(C, tgpa);
- /* Update points position. */
- gpencil_asset_import_update_strokes(C, tgpa);
-}
-
-/* ----------------------- */
-
-/* Exit and free memory */
-static void gpencil_asset_import_exit(bContext *C, wmOperator *op)
-{
- tGPDasset *tgpa = op->customdata;
- bGPdata *gpd = tgpa->gpd;
-
- /* don't assume that operator data exists at all */
- if (tgpa) {
- /* clear status message area */
- ED_area_status_text(tgpa->area, NULL);
- ED_workspace_status_text(C, NULL);
-
- /* Clear any temp stroke. */
- // TODO
-
- /* Free Hash tablets. */
- if (tgpa->asset_layers != NULL) {
- BLI_ghash_free(tgpa->asset_layers, NULL, NULL);
- }
- if (tgpa->asset_frames != NULL) {
- BLI_ghash_free(tgpa->asset_frames, NULL, NULL);
- }
- if (tgpa->asset_strokes != NULL) {
- BLI_ghash_free(tgpa->asset_strokes, NULL, NULL);
- BLI_ghash_free(tgpa->asset_strokes_layer, NULL, NULL);
- }
-
- if (tgpa->asset_materials != NULL) {
- BLI_ghash_free(tgpa->asset_materials, NULL, NULL);
- }
-
- /* Remove drawing handler. */
- if (tgpa->draw_handle_3d) {
- ED_region_draw_cb_exit(tgpa->region->type, tgpa->draw_handle_3d);
- }
-
- MEM_SAFE_FREE(tgpa);
- }
- DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
- WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);
-
- /* clear pointer */
- op->customdata = NULL;
-}
-
-/* Init new temporary interpolation data */
-static bool gpencil_asset_import_set_init_values(bContext *C,
- wmOperator *op,
- ID *id,
- tGPDasset *tgpa)
-{
- /* Save current settings. */
- tgpa->win = CTX_wm_window(C);
- tgpa->bmain = CTX_data_main(C);
- tgpa->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- tgpa->scene = CTX_data_scene(C);
- tgpa->area = CTX_wm_area(C);
- tgpa->region = CTX_wm_region(C);
- tgpa->rv3d = CTX_wm_region_view3d(C);
- tgpa->ob = CTX_data_active_object(C);
-
- /* Setup space conversions data. */
- gpencil_point_conversion_init(C, &tgpa->gsc);
-
- /* Save current frame number. */
- tgpa->cframe = tgpa->scene->r.cfra;
-
- /* Target GP datablock. */
- tgpa->gpd = tgpa->ob->data;
- /* Asset GP datablock. */
- tgpa->gpd_asset = (bGPdata *)id;
-
- tgpa->mode = GP_ASSET_TRANSFORM_LOC;
- tgpa->flag |= GP_ASSET_FLAG_IDLE;
-
- /* Manipulator point is not set yet. */
- tgpa->manipulator_index = -1;
-
- tgpa->asset_layers = NULL;
- tgpa->asset_frames = NULL;
- tgpa->asset_strokes = NULL;
- tgpa->asset_strokes_layer = NULL;
- tgpa->asset_materials = NULL;
-
- return true;
-}
-
-/* Allocate memory and initialize values */
-static tGPDasset *gpencil_session_init_asset_import(bContext *C, wmOperator *op)
-{
- Main *bmain = CTX_data_main(C);
- ID *id = NULL;
-
- PropertyRNA *prop_name = RNA_struct_find_property(op->ptr, "name");
- PropertyRNA *prop_type = RNA_struct_find_property(op->ptr, "type");
-
- /* These shouldn't fail when created by outliner dropping as it checks the ID is valid. */
- if (!RNA_property_is_set(op->ptr, prop_name) || !RNA_property_is_set(op->ptr, prop_type)) {
- return NULL;
- }
- const short id_type = RNA_property_enum_get(op->ptr, prop_type);
- char name[MAX_ID_NAME - 2];
- RNA_property_string_get(op->ptr, prop_name, name);
- id = BKE_libblock_find_name(bmain, id_type, name);
- if (id == NULL) {
- return NULL;
- }
- const int object_type = BKE_object_obdata_to_type(id);
- if (object_type == -1) {
- return NULL;
- }
-
- tGPDasset *tgpa = MEM_callocN(sizeof(tGPDasset), "GPencil Asset Import Data");
-
- /* Save initial values. */
- gpencil_asset_import_set_init_values(C, op, id, tgpa);
-
- /* return context data for running operator */
- return tgpa;
-}
-
-/* Init interpolation: Allocate memory and set init values */
-static int gpencil_asset_import_init(bContext *C, wmOperator *op)
-{
- tGPDasset *tgpa;
-
- /* check context */
- tgpa = op->customdata = gpencil_session_init_asset_import(C, op);
- if (tgpa == NULL) {
- /* something wasn't set correctly in context */
- gpencil_asset_import_exit(C, op);
- return 0;
- }
-
- /* everything is now setup ok */
- return 1;
-}
-
/* Helper: Compute 2D cage size in screen pixels. */
static void gpencil_2d_cage_calc(tGPDasset *tgpa)
{
@@ -592,9 +422,85 @@ static void gpencil_2d_cage_calc(tGPDasset *tgpa)
gpencil_point_xy_to_3d(&tgpa->gsc, tgpa->scene, tgpa->manipulator[CAGE_CORNER_SW], co3);
sub_v3_v3v3(vec1, co2, co1);
sub_v3_v3v3(vec2, co3, co2);
+
/* Vector orthogonal to polygon plane. */
- cross_v3_v3v3(tgpa->normal_vec, vec1, vec2);
- normalize_v3(tgpa->normal_vec);
+ cross_v3_v3v3(tgpa->cage_normal, vec1, vec2);
+ normalize_v3(tgpa->cage_normal);
+}
+
+/* Draw a cage for manipulate asset */
+static void gpencil_2d_cage_draw(tGPDasset *tgpa)
+{
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+
+ GPU_blend(GPU_BLEND_ALPHA);
+
+ /* Draw dash box. */
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+ GPU_line_width(1.0f);
+
+ float viewport_size[4];
+ GPU_viewport_size_get_f(viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("colors_len", 0); /* "simple" mode */
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
+
+ float box_color[4];
+ UI_GetThemeColor4fv(TH_VERTEX_SELECT, box_color);
+ immUniformColor4fv(box_color);
+
+ immBegin(GPU_PRIM_LINE_LOOP, 4);
+ immVertex2f(pos, tgpa->manipulator[CAGE_CORNER_NW][0], tgpa->manipulator[CAGE_CORNER_NW][1]);
+ immVertex2f(pos, tgpa->manipulator[CAGE_CORNER_NE][0], tgpa->manipulator[CAGE_CORNER_NE][1]);
+ immVertex2f(pos, tgpa->manipulator[CAGE_CORNER_SE][0], tgpa->manipulator[CAGE_CORNER_SE][1]);
+ immVertex2f(pos, tgpa->manipulator[CAGE_CORNER_SW][0], tgpa->manipulator[CAGE_CORNER_SW][1]);
+ immEnd();
+
+ /* Rotation box */
+ const float gap = 2.0f;
+ for (int i = 0; i < 4; i++) {
+ imm_draw_box_wire_2d(pos,
+ tgpa->manipulator[CAGE_CORNER_ROT_NW + i][0] - gap,
+ tgpa->manipulator[CAGE_CORNER_ROT_NW + i][1] - gap,
+ tgpa->manipulator[CAGE_CORNER_ROT_NW + i][0] + gap,
+ tgpa->manipulator[CAGE
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list