diff options
-rw-r--r-- | source/blender/blenkernel/BKE_paint.h | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_pbvh.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pbvh_bmesh.c | 3 | ||||
-rw-r--r-- | source/blender/editors/include/ED_sculpt.h | 2 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_intern.h | 14 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_utils.c | 159 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 31 |
8 files changed, 36 insertions, 189 deletions
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 12c4e0b8435..60c448608d7 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -126,7 +126,7 @@ typedef struct SculptSession { struct MPoly *mpoly; struct MLoop *mloop; int totvert, totpoly; - float *face_normals; + float (*face_normals)[3]; struct KeyBlock *kb; float *vmask; @@ -135,7 +135,7 @@ typedef struct SculptSession { /* BMesh for dynamic topology sculpting */ struct BMesh *bm; - int bm_smooth_shading; + bool bm_smooth_shading; /* Undo/redo log for dynamic topology sculpting */ struct BMLog *bm_log; @@ -144,13 +144,13 @@ typedef struct SculptSession { bool show_diffuse_color; /* Paiting on deformed mesh */ - int modifiers_active; /* object is deformed with some modifiers */ + bool modifiers_active; /* object is deformed with some modifiers */ float (*orig_cos)[3]; /* coords of undeformed mesh */ float (*deform_cos)[3]; /* coords of deformed mesh but without stroke displacement */ float (*deform_imats)[3][3]; /* crazyspace deformation matrices */ /* Partial redraw */ - int partial_redraw; + bool partial_redraw; /* Used to cache the render of the active texture */ unsigned int texcache_side, *texcache, texcache_actual; @@ -163,7 +163,7 @@ typedef struct SculptSession { struct StrokeCache *cache; /* last paint/sculpt stroke location */ - int last_stroke_valid; + bool last_stroke_valid; float last_stroke[3]; float average_stroke_accum[3]; diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h index b6f7a2b0e1a..73ca60d40b9 100644 --- a/source/blender/blenkernel/BKE_pbvh.h +++ b/source/blender/blenkernel/BKE_pbvh.h @@ -67,8 +67,7 @@ void BKE_pbvh_build_grids(PBVH *bvh, struct CCGElem **grid_elems, struct DMGridAdjacency *gridadj, int totgrid, struct CCGKey *key, void **gridfaces, struct DMFlagMat *flagmats, unsigned int **grid_hidden); -void BKE_pbvh_build_bmesh(PBVH *bvh, struct BMesh *bm, int smooth_shading, - struct BMLog *log); +void BKE_pbvh_build_bmesh(PBVH *bvh, struct BMesh *bm, bool smooth_shading, struct BMLog *log); void BKE_pbvh_free(PBVH *bvh); void BKE_pbvh_free_layer_disp(PBVH *bvh); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index d7ae8e30698..1189b5715bb 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -413,8 +413,7 @@ static void sculptsession_bm_to_me_update_data_only(Object *ob, bool reorder) BMIter iter; BMFace *efa; BM_ITER_MESH (efa, &iter, ss->bm, BM_FACES_OF_MESH) { - BM_elem_flag_set(efa, BM_ELEM_SMOOTH, - ss->bm_smooth_shading); + BM_elem_flag_set(efa, BM_ELEM_SMOOTH, ss->bm_smooth_shading); } if (reorder) BM_log_mesh_elems_reorder(ss->bm, ss->bm_log); diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c index 8680b3e3a4b..ae2f9b2824b 100644 --- a/source/blender/blenkernel/intern/pbvh_bmesh.c +++ b/source/blender/blenkernel/intern/pbvh_bmesh.c @@ -1140,8 +1140,7 @@ void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode) /***************************** Public API *****************************/ /* Build a PBVH from a BMesh */ -void BKE_pbvh_build_bmesh(PBVH *bvh, BMesh *bm, int smooth_shading, - BMLog *log) +void BKE_pbvh_build_bmesh(PBVH *bvh, BMesh *bm, bool smooth_shading, BMLog *log) { BMIter iter; BMFace *f; diff --git a/source/blender/editors/include/ED_sculpt.h b/source/blender/editors/include/ED_sculpt.h index 6105db14d6a..ab8a65e9ef9 100644 --- a/source/blender/editors/include/ED_sculpt.h +++ b/source/blender/editors/include/ED_sculpt.h @@ -45,7 +45,7 @@ void ED_operatortypes_sculpt(void); void sculpt_get_redraw_planes(float planes[4][4], struct ARegion *ar, struct RegionView3D *rv3d, struct Object *ob); void ED_sculpt_get_average_stroke(struct Object *ob, float stroke[3]); -int ED_sculpt_minmax(struct bContext *C, float min[3], float max[3]); +bool ED_sculpt_minmax(struct bContext *C, float min[3], float max[3]); int ED_sculpt_mask_layers_ensure(struct Object *ob, struct MultiresModifierData *mmd); int do_sculpt_mask_box_select(struct ViewContext *vc, struct rcti *rect, bool select, bool extend); diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index af9ac6dd89d..cae785973bf 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -181,12 +181,12 @@ void SCULPT_OT_uv_sculpt_stroke(struct wmOperatorType *ot); /* Convert the object-space axis-aligned bounding box (expressed as * its minimum and maximum corners) into a screen-space rectangle, * returns zero if the result is empty */ -int paint_convert_bb_to_rect(struct rcti *rect, - const float bb_min[3], - const float bb_max[3], - const struct ARegion *ar, - struct RegionView3D *rv3d, - struct Object *ob); +bool paint_convert_bb_to_rect(struct rcti *rect, + const float bb_min[3], + const float bb_max[3], + const struct ARegion *ar, + struct RegionView3D *rv3d, + struct Object *ob); /* Get four planes in object-space that describe the projection of * screen_rect from screen into object-space (essentially converting a @@ -200,8 +200,6 @@ void paint_calc_redraw_planes(float planes[4][4], float paint_calc_object_space_radius(struct ViewContext *vc, const float center[3], float pixel_radius); float paint_get_tex_pixel(struct MTex *mtex, float u, float v, struct ImagePool *pool, int thread); void paint_get_tex_pixel_col(struct MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread); -int imapaint_pick_face(struct ViewContext *vc, const int mval[2], unsigned int *index, unsigned int totface); -void imapaint_pick_uv(struct Scene *scene, struct Object *ob, unsigned int faceindex, const int xy[2], float uv[2]); void brush_drawcursor_texpaint_uvsculpt(struct bContext *C, int x, int y, void *customdata); void paint_sample_color(const struct bContext *C, struct ARegion *ar, int x, int y); diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 5364ac6e26a..4c86862fae8 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -75,12 +75,12 @@ /* Convert the object-space axis-aligned bounding box (expressed as * its minimum and maximum corners) into a screen-space rectangle, * returns zero if the result is empty */ -int paint_convert_bb_to_rect(rcti *rect, - const float bb_min[3], - const float bb_max[3], - const ARegion *ar, - RegionView3D *rv3d, - Object *ob) +bool paint_convert_bb_to_rect(rcti *rect, + const float bb_min[3], + const float bb_max[3], + const ARegion *ar, + RegionView3D *rv3d, + Object *ob) { float projection_mat[4][4]; int i, j, k; @@ -195,153 +195,6 @@ void paint_get_tex_pixel_col(MTex *mtex, float u, float v, float rgba[4], struct CLAMP(rgba[3], 0.0f, 1.0f); } -/* 3D Paint */ - -static void imapaint_project(Object *ob, float model[4][4], float proj[4][4], const float co[3], float pco[4]) -{ - copy_v3_v3(pco, co); - pco[3] = 1.0f; - - mul_m4_v3(ob->obmat, pco); - mul_m4_v3(model, pco); - mul_m4_v4(proj, pco); -} - -static void imapaint_tri_weights(Object *ob, - const float v1[3], const float v2[3], const float v3[3], - const float co[2], float w[3]) -{ - float pv1[4], pv2[4], pv3[4], h[3], divw; - float model[4][4], proj[4][4], wmat[3][3], invwmat[3][3]; - GLint view[4]; - - /* compute barycentric coordinates */ - - /* get the needed opengl matrices */ - glGetIntegerv(GL_VIEWPORT, view); - glGetFloatv(GL_MODELVIEW_MATRIX, (float *)model); - glGetFloatv(GL_PROJECTION_MATRIX, (float *)proj); - view[0] = view[1] = 0; - - /* project the verts */ - imapaint_project(ob, model, proj, v1, pv1); - imapaint_project(ob, model, proj, v2, pv2); - imapaint_project(ob, model, proj, v3, pv3); - - /* do inverse view mapping, see gluProject man page */ - h[0] = (co[0] - view[0]) * 2.0f / view[2] - 1; - h[1] = (co[1] - view[1]) * 2.0f / view[3] - 1; - h[2] = 1.0f; - - /* solve for (w1,w2,w3)/perspdiv in: - * h * perspdiv = Project * Model * (w1 * v1 + w2 * v2 + w3 * v3) */ - - wmat[0][0] = pv1[0]; wmat[1][0] = pv2[0]; wmat[2][0] = pv3[0]; - wmat[0][1] = pv1[1]; wmat[1][1] = pv2[1]; wmat[2][1] = pv3[1]; - wmat[0][2] = pv1[3]; wmat[1][2] = pv2[3]; wmat[2][2] = pv3[3]; - - invert_m3_m3(invwmat, wmat); - mul_m3_v3(invwmat, h); - - copy_v3_v3(w, h); - - /* w is still divided by perspdiv, make it sum to one */ - divw = w[0] + w[1] + w[2]; - if (divw != 0.0f) { - mul_v3_fl(w, 1.0f / divw); - } -} - -/* compute uv coordinates of mouse in face */ -void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, const int xy[2], float uv[2]) -{ - DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); - MTFace *tface = dm->getTessFaceDataArray(dm, CD_MTFACE), *tf; - int numfaces = dm->getNumTessFaces(dm), a, findex; - float p[2], w[3], absw, minabsw; - MFace mf; - MVert mv[4]; - - /* double lookup */ - const int *index_mf_to_mpoly = dm->getTessFaceDataArray(dm, CD_ORIGINDEX); - const int *index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX); - if (index_mf_to_mpoly == NULL) { - index_mp_to_orig = NULL; - } - - minabsw = 1e10; - uv[0] = uv[1] = 0.0; - - /* test all faces in the derivedmesh with the original index of the picked face */ - for (a = 0; a < numfaces; a++) { - findex = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, a) : a; - - if (findex == faceindex) { - dm->getTessFace(dm, a, &mf); - - dm->getVert(dm, mf.v1, &mv[0]); - dm->getVert(dm, mf.v2, &mv[1]); - dm->getVert(dm, mf.v3, &mv[2]); - if (mf.v4) - dm->getVert(dm, mf.v4, &mv[3]); - - tf = &tface[a]; - - p[0] = xy[0]; - p[1] = xy[1]; - - if (mf.v4) { - /* the triangle with the largest absolute values is the one - * with the most negative weights */ - imapaint_tri_weights(ob, mv[0].co, mv[1].co, mv[3].co, p, w); - absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]); - if (absw < minabsw) { - uv[0] = tf->uv[0][0] * w[0] + tf->uv[1][0] * w[1] + tf->uv[3][0] * w[2]; - uv[1] = tf->uv[0][1] * w[0] + tf->uv[1][1] * w[1] + tf->uv[3][1] * w[2]; - minabsw = absw; - } - - imapaint_tri_weights(ob, mv[1].co, mv[2].co, mv[3].co, p, w); - absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]); - if (absw < minabsw) { - uv[0] = tf->uv[1][0] * w[0] + tf->uv[2][0] * w[1] + tf->uv[3][0] * w[2]; - uv[1] = tf->uv[1][1] * w[0] + tf->uv[2][1] * w[1] + tf->uv[3][1] * w[2]; - minabsw = absw; - } - } - else { - imapaint_tri_weights(ob, mv[0].co, mv[1].co, mv[2].co, p, w); - absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]); - if (absw < minabsw) { - uv[0] = tf->uv[0][0] * w[0] + tf->uv[1][0] * w[1] + tf->uv[2][0] * w[2]; - uv[1] = tf->uv[0][1] * w[0] + tf->uv[1][1] * w[1] + tf->uv[2][1] * w[2]; - minabsw = absw; - } - } - } - } - - dm->release(dm); -} - -/* returns 0 if not found, otherwise 1 */ -int imapaint_pick_face(ViewContext *vc, const int mval[2], unsigned int *index, unsigned int totface) -{ - if (totface == 0) - return 0; - - /* sample only on the exact position */ - *index = view3d_sample_backbuf(vc, mval[0], mval[1]); - - if ((*index) == 0 || (*index) > (unsigned int)totface) { - return 0; - } - - (*index)--; - - return 1; -} - /* Uses symm to selectively flip any axis of a coordinate. */ void flip_v3_v3(float out[3], const float in[3], const char symm) { diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 50df1821fa2..4608a25cc00 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -116,7 +116,7 @@ void ED_sculpt_get_average_stroke(Object *ob, float stroke[3]) } } -int ED_sculpt_minmax(bContext *C, float min[3], float max[3]) +bool ED_sculpt_minmax(bContext *C, float min[3], float max[3]) { Object *ob = CTX_data_active_object(C); @@ -165,7 +165,7 @@ MultiresModifierData *sculpt_multires_active(Scene *scene, Object *ob) } /* Check if there are any active modifiers in stack (used for flushing updates at enter/exit sculpt mode) */ -static int sculpt_has_active_modifiers(Scene *scene, Object *ob) +static bool sculpt_has_active_modifiers(Scene *scene, Object *ob) { ModifierData *md; VirtualModifierData virtualModifierData; @@ -182,7 +182,7 @@ static int sculpt_has_active_modifiers(Scene *scene, Object *ob) } /* Checks if there are any supported deformation modifiers active */ -static int sculpt_modifiers_active(Scene *scene, Sculpt *sd, Object *ob) +static bool sculpt_modifiers_active(Scene *scene, Sculpt *sd, Object *ob) { ModifierData *md; Mesh *me = (Mesh *)ob->data; @@ -249,7 +249,7 @@ typedef struct StrokeCache { /* The rest is temporary storage that isn't saved as a property */ - int first_time; /* Beginning of stroke may do some things special */ + bool first_time; /* Beginning of stroke may do some things special */ /* from ED_view3d_ob_project_mat_get() */ float projection_mat[4][4]; @@ -284,7 +284,7 @@ typedef struct StrokeCache { int radial_symmetry_pass; float symm_rot_mat[4][4]; float symm_rot_mat_inv[4][4]; - int original; + bool original; float anchored_location[3]; float vertex_rotation; /* amount to rotate the vertices when using rotate brush */ @@ -297,7 +297,7 @@ typedef struct StrokeCache { char saved_active_brush_name[MAX_ID_NAME]; char saved_mask_brush_tool; int saved_smooth_size; /* smooth tool copies the size of the current tool */ - int alt_smooth; + bool alt_smooth; float plane_trim_squared; @@ -485,9 +485,9 @@ static void paint_mesh_restore_co(Sculpt *sd, Object *ob) } if (ss->face_normals) { - float *fn = ss->face_normals; - for (i = 0; i < ss->totpoly; ++i, fn += 3) - copy_v3_v3(fn, cache->face_norms[i]); + for (i = 0; i < ss->totpoly; i++) { + copy_v3_v3(ss->face_normals[i], cache->face_norms[i]); + } } if (nodes) @@ -513,8 +513,8 @@ static void sculpt_extend_redraw_rect_previous(Object *ob, rcti *rect) } /* Get a screen-space rectangle of the modified area */ -static int sculpt_get_redraw_rect(ARegion *ar, RegionView3D *rv3d, - Object *ob, rcti *rect) +static bool sculpt_get_redraw_rect(ARegion *ar, RegionView3D *rv3d, + Object *ob, rcti *rect) { PBVH *pbvh = ob->sculpt->pbvh; float bb_min[3], bb_max[3]; @@ -3979,10 +3979,10 @@ static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSessio /* Make copies of the mesh vertex locations and normals for some tools */ if (brush->flag & BRUSH_ANCHORED) { if (ss->face_normals) { - float *fn = ss->face_normals; cache->face_norms = MEM_mallocN(sizeof(float) * 3 * ss->totpoly, "Sculpt face norms"); - for (i = 0; i < ss->totpoly; ++i, fn += 3) - copy_v3_v3(cache->face_norms[i], fn); + for (i = 0; i < ss->totpoly; ++i) { + copy_v3_v3(cache->face_norms[i], ss->face_normals[i]); + } } cache->original = 1; @@ -4815,8 +4815,7 @@ void sculpt_dynamic_topology_enable(bContext *C) sculpt_pbvh_clear(ob); - ss->bm_smooth_shading = (scene->toolsettings->sculpt->flags & - SCULPT_DYNTOPO_SMOOTH_SHADING); + ss->bm_smooth_shading = (scene->toolsettings->sculpt->flags & SCULPT_DYNTOPO_SMOOTH_SHADING) != 0; /* Dynamic topology doesn't ensure selection state is valid, so remove [#36280] */ BKE_mesh_mselect_clear(me); |