Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_image_proj.c')
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_proj.c277
1 files changed, 125 insertions, 152 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 5e3204b6d5a..5991032536b 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -100,8 +100,6 @@
#include "RNA_define.h"
#include "RNA_enum_types.h"
-#include "GPU_draw.h"
-
#include "IMB_colormanagement.h"
//#include "bmesh_tools.h"
@@ -557,12 +555,11 @@ static Image *project_paint_face_paint_image(const ProjPaintState *ps, int tri_i
if (ps->do_stencil_brush) {
return ps->stencil_ima;
}
- else {
- const MPoly *mp = ps_tri_index_to_mpoly(ps, tri_index);
- Material *ma = ps->mat_array[mp->mat_nr];
- TexPaintSlot *slot = ma ? ma->texpaintslot + ma->paint_active_slot : NULL;
- return slot ? slot->ima : ps->canvas_ima;
- }
+
+ const MPoly *mp = ps_tri_index_to_mpoly(ps, tri_index);
+ Material *ma = ps->mat_array[mp->mat_nr];
+ TexPaintSlot *slot = ma ? ma->texpaintslot + ma->paint_active_slot : NULL;
+ return slot ? slot->ima : ps->canvas_ima;
}
static TexPaintSlot *project_paint_face_clone_slot(const ProjPaintState *ps, int tri_index)
@@ -605,9 +602,7 @@ static int project_bucket_offset_safe(const ProjPaintState *ps, const float proj
if (bucket_index < 0 || bucket_index >= ps->buckets_x * ps->buckets_y) {
return -1;
}
- else {
- return bucket_index;
- }
+ return bucket_index;
}
static float VecZDepthOrtho(
@@ -811,7 +806,7 @@ static bool project_paint_PickColor(
}
/**
- * Check if 'pt' is infront of the 3 verts on the Z axis (used for screenspace occlusion test)
+ * Check if 'pt' is in front of the 3 verts on the Z axis (used for screen-space occlusion test)
* \return
* - `0`: no occlusion
* - `-1`: no occlusion but 2D intersection is true
@@ -836,22 +831,21 @@ static int project_paint_occlude_ptv(const float pt[3],
}
/* From here on we know there IS an intersection */
- /* if ALL of the verts are infront of us then we know it intersects ? */
+ /* if ALL of the verts are in front of us then we know it intersects ? */
if (v1[2] < pt[2] && v2[2] < pt[2] && v3[2] < pt[2]) {
return 1;
}
- else {
- /* we intersect? - find the exact depth at the point of intersection */
- /* Is this point is occluded by another face? */
- if (is_ortho) {
- if (VecZDepthOrtho(pt, v1, v2, v3, w) < pt[2]) {
- return 2;
- }
+
+ /* we intersect? - find the exact depth at the point of intersection */
+ /* Is this point is occluded by another face? */
+ if (is_ortho) {
+ if (VecZDepthOrtho(pt, v1, v2, v3, w) < pt[2]) {
+ return 2;
}
- else {
- if (VecZDepthPersp(pt, v1, v2, v3, w) < pt[2]) {
- return 2;
- }
+ }
+ else {
+ if (VecZDepthPersp(pt, v1, v2, v3, w) < pt[2]) {
+ return 2;
}
}
return -1;
@@ -977,14 +971,12 @@ static int line_isect_y(const float p1[2], const float p2[2], const float y_leve
*x_isect = (p2[0] * (p1[1] - y_level) + p1[0] * (y_level - p2[1])) / y_diff;
return ISECT_TRUE;
}
- else if (p1[1] < y_level && p2[1] > y_level) {
+ if (p1[1] < y_level && p2[1] > y_level) {
/* (p2[1] - p1[1]); */
*x_isect = (p2[0] * (y_level - p1[1]) + p1[0] * (p2[1] - y_level)) / y_diff;
return ISECT_TRUE;
}
- else {
- return 0;
- }
+ return 0;
}
static int line_isect_x(const float p1[2], const float p2[2], const float x_level, float *y_isect)
@@ -1014,14 +1006,12 @@ static int line_isect_x(const float p1[2], const float p2[2], const float x_leve
*y_isect = (p2[1] * (p1[0] - x_level) + p1[1] * (x_level - p2[0])) / x_diff;
return ISECT_TRUE;
}
- else if (p1[0] < x_level && p2[0] > x_level) {
+ if (p1[0] < x_level && p2[0] > x_level) {
/* (p2[0] - p1[0]); */
*y_isect = (p2[1] * (x_level - p1[0]) + p1[1] * (p2[0] - x_level)) / x_diff;
return ISECT_TRUE;
}
- else {
- return 0;
- }
+ return 0;
}
/* simple func use for comparing UV locations to check if there are seams.
@@ -1204,10 +1194,8 @@ static bool check_seam(const ProjPaintState *ps,
// printf("SEAM (NONE)\n");
return false;
}
- else {
- // printf("SEAM (UV GAP)\n");
- return true;
- }
+ // printf("SEAM (UV GAP)\n");
+ return true;
}
}
}
@@ -1436,7 +1424,7 @@ static void insert_seam_vert_array(const ProjPaintState *ps,
* Be tricky with flags, first 4 bits are #PROJ_FACE_SEAM0 to 4,
* last 4 bits are #PROJ_FACE_NOSEAM0 to 4. `1 << i` - where i is `(0..3)`.
*
- * If we're multithreadng, make sure threads are locked when this is called.
+ * If we're multi-threading, make sure threads are locked when this is called.
*/
static void project_face_seams_init(const ProjPaintState *ps,
MemArena *arena,
@@ -1788,7 +1776,7 @@ static float project_paint_uvpixel_mask(const ProjPaintState *ps,
/* outsize the normal limit*/
return 0.0f;
}
- else if (angle_cos < ps->normal_angle_inner__cos) {
+ if (angle_cos < ps->normal_angle_inner__cos) {
mask *= (ps->normal_angle - acosf(angle_cos)) / ps->normal_angle_range;
} /* otherwise no mask normal is needed, we're within the limit */
}
@@ -1805,9 +1793,7 @@ static int project_paint_pixel_sizeof(const short tool)
if ((tool == PAINT_TOOL_CLONE) || (tool == PAINT_TOOL_SMEAR)) {
return sizeof(ProjPixelClone);
}
- else {
- return sizeof(ProjPixel);
- }
+ return sizeof(ProjPixel);
}
static int project_paint_undo_subtiles(const TileInfo *tinf, int tx, int ty)
@@ -2083,9 +2069,7 @@ static bool line_clip_rect2f(const rctf *cliprect,
copy_v2_v2(l2_clip, l2);
return true;
}
- else {
- return false;
- }
+ return false;
}
copy_v2_v2(l1_clip, l1);
@@ -2094,7 +2078,7 @@ static bool line_clip_rect2f(const rctf *cliprect,
CLAMP(l2_clip[0], rect->xmin, rect->xmax);
return true;
}
- else if (fabsf(l1[0] - l2[0]) < PROJ_PIXEL_TOLERANCE) {
+ if (fabsf(l1[0] - l2[0]) < PROJ_PIXEL_TOLERANCE) {
/* is the line out of range on its X axis? */
if (l1[0] < rect->xmin || l1[0] > rect->xmax) {
return 0;
@@ -2112,9 +2096,7 @@ static bool line_clip_rect2f(const rctf *cliprect,
copy_v2_v2(l2_clip, l2);
return true;
}
- else {
- return false;
- }
+ return false;
}
copy_v2_v2(l1_clip, l1);
@@ -2123,106 +2105,103 @@ static bool line_clip_rect2f(const rctf *cliprect,
CLAMP(l2_clip[1], rect->ymin, rect->ymax);
return true;
}
- else {
- float isect;
- short ok1 = 0;
- short ok2 = 0;
- /* Done with vertical lines */
+ float isect;
+ short ok1 = 0;
+ short ok2 = 0;
- /* are either of the points inside the rectangle ? */
- if (BLI_rctf_isect_pt_v(rect, l1)) {
- copy_v2_v2(l1_clip, l1);
- ok1 = 1;
- }
+ /* Done with vertical lines */
- if (BLI_rctf_isect_pt_v(rect, l2)) {
- copy_v2_v2(l2_clip, l2);
- ok2 = 1;
- }
+ /* are either of the points inside the rectangle ? */
+ if (BLI_rctf_isect_pt_v(rect, l1)) {
+ copy_v2_v2(l1_clip, l1);
+ ok1 = 1;
+ }
- /* line inside rect */
- if (ok1 && ok2) {
- return 1;
- }
+ if (BLI_rctf_isect_pt_v(rect, l2)) {
+ copy_v2_v2(l2_clip, l2);
+ ok2 = 1;
+ }
- /* top/bottom */
- if (line_isect_y(l1, l2, rect->ymin, &isect) && (isect >= cliprect->xmin) &&
- (isect <= cliprect->xmax)) {
- if (l1[1] < l2[1]) { /* line 1 is outside */
- l1_clip[0] = isect;
- l1_clip[1] = rect->ymin;
- ok1 = 1;
- }
- else {
- l2_clip[0] = isect;
- l2_clip[1] = rect->ymin;
- ok2 = 2;
- }
- }
+ /* line inside rect */
+ if (ok1 && ok2) {
+ return 1;
+ }
- if (ok1 && ok2) {
- return true;
+ /* top/bottom */
+ if (line_isect_y(l1, l2, rect->ymin, &isect) && (isect >= cliprect->xmin) &&
+ (isect <= cliprect->xmax)) {
+ if (l1[1] < l2[1]) { /* line 1 is outside */
+ l1_clip[0] = isect;
+ l1_clip[1] = rect->ymin;
+ ok1 = 1;
}
-
- if (line_isect_y(l1, l2, rect->ymax, &isect) && (isect >= cliprect->xmin) &&
- (isect <= cliprect->xmax)) {
- if (l1[1] > l2[1]) { /* line 1 is outside */
- l1_clip[0] = isect;
- l1_clip[1] = rect->ymax;
- ok1 = 1;
- }
- else {
- l2_clip[0] = isect;
- l2_clip[1] = rect->ymax;
- ok2 = 2;
- }
+ else {
+ l2_clip[0] = isect;
+ l2_clip[1] = rect->ymin;
+ ok2 = 2;
}
+ }
- if (ok1 && ok2) {
- return true;
- }
+ if (ok1 && ok2) {
+ return true;
+ }
- /* left/right */
- if (line_isect_x(l1, l2, rect->xmin, &isect) && (isect >= cliprect->ymin) &&
- (isect <= cliprect->ymax)) {
- if (l1[0] < l2[0]) { /* line 1 is outside */
- l1_clip[0] = rect->xmin;
- l1_clip[1] = isect;
- ok1 = 1;
- }
- else {
- l2_clip[0] = rect->xmin;
- l2_clip[1] = isect;
- ok2 = 2;
- }
+ if (line_isect_y(l1, l2, rect->ymax, &isect) && (isect >= cliprect->xmin) &&
+ (isect <= cliprect->xmax)) {
+ if (l1[1] > l2[1]) { /* line 1 is outside */
+ l1_clip[0] = isect;
+ l1_clip[1] = rect->ymax;
+ ok1 = 1;
}
-
- if (ok1 && ok2) {
- return true;
+ else {
+ l2_clip[0] = isect;
+ l2_clip[1] = rect->ymax;
+ ok2 = 2;
}
+ }
- if (line_isect_x(l1, l2, rect->xmax, &isect) && (isect >= cliprect->ymin) &&
- (isect <= cliprect->ymax)) {
- if (l1[0] > l2[0]) { /* line 1 is outside */
- l1_clip[0] = rect->xmax;
- l1_clip[1] = isect;
- ok1 = 1;
- }
- else {
- l2_clip[0] = rect->xmax;
- l2_clip[1] = isect;
- ok2 = 2;
- }
+ if (ok1 && ok2) {
+ return true;
+ }
+
+ /* left/right */
+ if (line_isect_x(l1, l2, rect->xmin, &isect) && (isect >= cliprect->ymin) &&
+ (isect <= cliprect->ymax)) {
+ if (l1[0] < l2[0]) { /* line 1 is outside */
+ l1_clip[0] = rect->xmin;
+ l1_clip[1] = isect;
+ ok1 = 1;
}
+ else {
+ l2_clip[0] = rect->xmin;
+ l2_clip[1] = isect;
+ ok2 = 2;
+ }
+ }
- if (ok1 && ok2) {
- return true;
+ if (ok1 && ok2) {
+ return true;
+ }
+
+ if (line_isect_x(l1, l2, rect->xmax, &isect) && (isect >= cliprect->ymin) &&
+ (isect <= cliprect->ymax)) {
+ if (l1[0] > l2[0]) { /* line 1 is outside */
+ l1_clip[0] = rect->xmax;
+ l1_clip[1] = isect;
+ ok1 = 1;
}
else {
- return false;
+ l2_clip[0] = rect->xmax;
+ l2_clip[1] = isect;
+ ok2 = 2;
}
}
+
+ if (ok1 && ok2) {
+ return true;
+ }
+ return false;
}
/**
@@ -2299,7 +2278,7 @@ static bool project_bucket_isect_circle(const float cent[2],
false;
}
/* top left test */
- else if (cent[1] > bucket_bounds->ymax) {
+ if (cent[1] > bucket_bounds->ymax) {
return (len_squared_v2v2_alt(cent, bucket_bounds->xmin, bucket_bounds->ymax) <
radius_squared) ?
true :
@@ -2315,7 +2294,7 @@ static bool project_bucket_isect_circle(const float cent[2],
false;
}
/* top right test */
- else if (cent[1] > bucket_bounds->ymax) {
+ if (cent[1] > bucket_bounds->ymax) {
return (len_squared_v2v2_alt(cent, bucket_bounds->xmax, bucket_bounds->ymax) <
radius_squared) ?
true :
@@ -2670,7 +2649,8 @@ static void project_bucket_clip_face(const bool is_ortho,
*tot = 4;
return;
}
- else {
+
+ {
/* The Complicated Case!
*
* The 2 cases above are where the face is inside the bucket
@@ -3584,8 +3564,8 @@ static bool project_bucket_face_isect(ProjPaintState *ps,
int bucket_y,
const MLoopTri *lt)
{
- /* TODO - replace this with a tricker method that uses sideofline for all
- * screenCoords's edges against the closest bucket corner */
+ /* TODO - replace this with a trickier method that uses side-of-line for all
+ * #ProjPaintState.screenCoords edges against the closest bucket corner. */
const int lt_vtri[3] = {PS_LOOPTRI_AS_VERT_INDEX_3(ps, lt)};
rctf bucket_bounds;
float p1[2], p2[2], p3[2], p4[2];
@@ -4209,9 +4189,7 @@ static bool project_paint_check_face_sel(const ProjPaintState *ps,
return ((mp->flag & ME_FACE_SEL) != 0);
}
- else {
- return true;
- }
+ return true;
}
typedef struct {
@@ -5906,8 +5884,6 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int
ps->dither = settings->imapaint.dither;
ps->use_colormanagement = BKE_scene_check_color_management_enabled(CTX_data_scene(C));
-
- return;
}
void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int mode)
@@ -6146,19 +6122,18 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_ERROR, "Could not get valid evaluated mesh");
return OPERATOR_CANCELLED;
}
- else {
- float pos[2] = {0.0, 0.0};
- float lastpos[2] = {0.0, 0.0};
- int a;
- project_paint_op(&ps, lastpos, pos);
+ float pos[2] = {0.0, 0.0};
+ float lastpos[2] = {0.0, 0.0};
+ int a;
- project_image_refresh_tagged(&ps);
+ project_paint_op(&ps, lastpos, pos);
- for (a = 0; a < ps.image_tot; a++) {
- GPU_free_image(ps.projImages[a].ima);
- WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ps.projImages[a].ima);
- }
+ project_image_refresh_tagged(&ps);
+
+ for (a = 0; a < ps.image_tot; a++) {
+ BKE_image_free_gputextures(ps.projImages[a].ima);
+ WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ps.projImages[a].ima);
}
project_paint_end(&ps);
@@ -6699,9 +6674,7 @@ static int texture_paint_add_texture_paint_slot_exec(bContext *C, wmOperator *op
if (proj_paint_add_slot(C, op)) {
return OPERATOR_FINISHED;
}
- else {
- return OPERATOR_CANCELLED;
- }
+ return OPERATOR_CANCELLED;
}
static void get_default_texture_layer_name_for_object(Object *ob,