[Bf-blender-cvs] [b0067db8527] blender2.8: Cleanup: Split function up

Sergey Sharybin noreply at git.blender.org
Mon Sep 3 17:07:51 CEST 2018


Commit: b0067db85274b8d0775c4c096a14e2ab6d5d47ff
Author: Sergey Sharybin
Date:   Mon Sep 3 17:06:50 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBb0067db85274b8d0775c4c096a14e2ab6d5d47ff

Cleanup: Split function up

We would need to at least support one more PBVH building
here, trying to squeeze everything into one function will
make it really hard to read and follow.

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

M	source/blender/blenkernel/intern/paint.c

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

diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 6ccf4c1b761..12cdb4586c1 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1127,69 +1127,70 @@ static bool check_sculpt_object_deformed(Object *object, const bool for_construc
 	return deformed;
 }
 
-PBVH *BKE_sculpt_object_pbvh_ensure(Object *ob, Mesh *me_eval_deform)
+static PBVH *build_pbvh_for_dynamic_topology(Object *ob)
 {
-	if (!ob) {
-		return NULL;
+	PBVH *pbvh = BKE_pbvh_new();
+	BKE_pbvh_build_bmesh(pbvh, ob->sculpt->bm,
+	                     ob->sculpt->bm_smooth_shading,
+	                     ob->sculpt->bm_log, ob->sculpt->cd_vert_node_offset,
+	                     ob->sculpt->cd_face_node_offset);
+	pbvh_show_diffuse_color_set(pbvh, ob->sculpt->show_diffuse_color);
+	pbvh_show_mask_set(pbvh, ob->sculpt->show_mask);
+	return pbvh;
+}
+
+static PBVH *build_regular_mesh_pbvh(Object *ob, Mesh *me_eval_deform)
+{
+	Mesh *me = BKE_object_get_original_mesh(ob);
+	const int looptris_num = poly_to_tri_count(me->totpoly, me->totloop);
+	PBVH *pbvh = BKE_pbvh_new();
+
+	MLoopTri *looptri = MEM_malloc_arrayN(
+	        looptris_num, sizeof(*looptri), __func__);
+
+	BKE_mesh_recalc_looptri(
+	        me->mloop, me->mpoly,
+	        me->mvert,
+	        me->totloop, me->totpoly,
+	        looptri);
+
+	BKE_pbvh_build_mesh(
+	        pbvh,
+	        me->mpoly, me->mloop,
+	        me->mvert, me->totvert, &me->vdata,
+	        looptri, looptris_num);
+
+	pbvh_show_diffuse_color_set(pbvh, ob->sculpt->show_diffuse_color);
+	pbvh_show_mask_set(pbvh, ob->sculpt->show_mask);
+
+	const bool is_deformed = check_sculpt_object_deformed(ob, true);
+	if (is_deformed && me_eval_deform != NULL) {
+		int totvert;
+		float (*v_cos)[3] = BKE_mesh_vertexCos_get(me_eval_deform, &totvert);
+		BKE_pbvh_apply_vertCos(pbvh, v_cos, totvert);
+		MEM_freeN(v_cos);
 	}
 
-	if (!ob->sculpt) {
+	return pbvh;
+}
+
+PBVH *BKE_sculpt_object_pbvh_ensure(Object *ob, Mesh *me_eval_deform)
+{
+	if (ob == NULL || ob->sculpt == NULL) {
 		return NULL;
 	}
-
 	PBVH *pbvh = ob->sculpt->pbvh;
-
-	/* Sculpting on a BMesh (dynamic-topology) gets a special PBVH */
-	if (!pbvh && ob->sculpt->bm) {
-		pbvh = BKE_pbvh_new();
-
-		BKE_pbvh_build_bmesh(pbvh, ob->sculpt->bm,
-		                     ob->sculpt->bm_smooth_shading,
-		                     ob->sculpt->bm_log, ob->sculpt->cd_vert_node_offset,
-		                     ob->sculpt->cd_face_node_offset);
-
-		pbvh_show_diffuse_color_set(pbvh, ob->sculpt->show_diffuse_color);
-		pbvh_show_mask_set(pbvh, ob->sculpt->show_mask);
+	if (pbvh != NULL) {
+		/* Nothing to do, PBVH is already up to date. */
+		return pbvh;
 	}
 
-	/* always build pbvh from original mesh, and only use it for drawing if
-	 * this evaluated mesh is just original mesh. it's the multires subsurf dm
-	 * that this is actually for, to support a pbvh on a modified mesh */
-	if (!pbvh && ob->type == OB_MESH) {
-		Mesh *me = BKE_object_get_original_mesh(ob);
-		const int looptris_num = poly_to_tri_count(me->totpoly, me->totloop);
-		MLoopTri *looptri;
-		bool deformed;
-
-		pbvh = BKE_pbvh_new();
-
-		looptri = MEM_malloc_arrayN(looptris_num, sizeof(*looptri), __func__);
-
-		BKE_mesh_recalc_looptri(
-		        me->mloop, me->mpoly,
-		        me->mvert,
-		        me->totloop, me->totpoly,
-		        looptri);
-
-		BKE_pbvh_build_mesh(
-		        pbvh,
-		        me->mpoly, me->mloop,
-		        me->mvert, me->totvert, &me->vdata,
-		        looptri, looptris_num);
-
-		pbvh_show_diffuse_color_set(pbvh, ob->sculpt->show_diffuse_color);
-		pbvh_show_mask_set(pbvh, ob->sculpt->show_mask);
-
-		deformed = check_sculpt_object_deformed(ob, true);
-
-		if (deformed && me_eval_deform) {
-			int totvert;
-			float (*v_cos)[3];
-
-			v_cos = BKE_mesh_vertexCos_get(me_eval_deform, &totvert);
-			BKE_pbvh_apply_vertCos(pbvh, v_cos, totvert);
-			MEM_freeN(v_cos);
-		}
+	if (ob->sculpt->bm != NULL) {
+		/* Sculpting on a BMesh (dynamic-topology) gets a special PBVH. */
+		pbvh = build_pbvh_for_dynamic_topology(ob);
+	}
+	else if (ob->type == OB_MESH) {
+		pbvh = build_regular_mesh_pbvh(ob, me_eval_deform);
 	}
 
 	ob->sculpt->pbvh = pbvh;



More information about the Bf-blender-cvs mailing list