[Bf-blender-cvs] [55f31b1] bmesh-boolean-experiment: Merge branch 'master' into bmesh-boolean-experiment

Campbell Barton noreply at git.blender.org
Fri Dec 11 03:53:58 CET 2015


Commit: 55f31b11ef9a8b37ddca762ab6bb89161ba902b8
Author: Campbell Barton
Date:   Fri Dec 11 13:46:45 2015 +1100
Branches: bmesh-boolean-experiment
https://developer.blender.org/rB55f31b11ef9a8b37ddca762ab6bb89161ba902b8

Merge branch 'master' into bmesh-boolean-experiment

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



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

diff --cc source/blender/bmesh/tools/bmesh_intersect.c
index fd12ba6,0283004..8804b09
--- a/source/blender/bmesh/tools/bmesh_intersect.c
+++ b/source/blender/bmesh/tools/bmesh_intersect.c
@@@ -1046,8 -808,7 +1045,8 @@@ bool BM_mesh_intersect
          BMesh *bm,
          struct BMLoop *(*looptris)[3], const int looptris_tot,
          int (*test_fn)(BMFace *f, void *user_data), void *user_data,
-         const bool use_self, const bool use_separate, const bool use_dissolve,
 -        const bool use_self, const bool use_separate, const bool use_island_connect,
++        const bool use_self, const bool use_separate, const bool use_dissolve, const bool use_island_connect,
 +        const int boolean_mode,
          const float eps)
  {
  	struct ISectState s;
diff --cc source/blender/bmesh/tools/bmesh_intersect.h
index c584fec,a733815..1049013
--- a/source/blender/bmesh/tools/bmesh_intersect.h
+++ b/source/blender/bmesh/tools/bmesh_intersect.h
@@@ -29,8 -29,7 +29,8 @@@ bool BM_mesh_intersect
          BMesh *bm,
          struct BMLoop *(*looptris)[3], const int looptris_tot,
          int (*test_fn)(BMFace *f, void *user_data), void *user_data,
-         const bool use_self, const bool use_separate, const bool use_dissolve,
 -        const bool use_self, const bool use_separate, const bool use_island_connect,
++        const bool use_self, const bool use_separate, const bool use_dissolve, const bool use_island_connect,
 +        const int boolean_mode,
          const float eps);
  
  #endif /* __BMESH_INTERSECT_H__ */
diff --cc source/blender/editors/mesh/editmesh_intersect.c
index 813fa90,bd5faff..0641701
--- a/source/blender/editors/mesh/editmesh_intersect.c
+++ b/source/blender/editors/mesh/editmesh_intersect.c
@@@ -123,8 -123,7 +123,8 @@@ static int edbm_intersect_exec(bContex
  	        bm,
  	        em->looptris, em->tottri,
  	        test_fn, NULL,
- 	        use_self, use_separate, false,
 -	        use_self, use_separate, true,
++	        use_self, use_separate, true, true,
 +	        -1,
  	        eps);
  
  
diff --cc source/blender/makesdna/DNA_modifier_types.h
index 3744ff3,6f07d18..831de91
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@@ -650,16 -649,6 +650,17 @@@ typedef enum 
  	eBooleanModifierOp_Difference = 2,
  } BooleanModifierOp;
  
 +typedef enum {
 +	eBooleanModifierMethod_Carve  = 0,
 +	eBooleanModifierMethod_BMesh  = 1,
 +} BooleanModifierMethod;
 +
 +typedef enum {
- 	eBooleanModifierFlag_Dissolve   = (1 << 0),
- 	eBooleanModifierFlag_Separate   = (1 << 1),
++	eBooleanModifierFlag_Dissolve           = (1 << 0),
++	eBooleanModifierFlag_Separate           = (1 << 1),
++	eBooleanModifierFlag_ConnectRegions     = (1 << 2),
 +} BooleanModifierFlag;
 +
  typedef struct MDefInfluence {
  	int vertex;
  	float weight;
diff --cc source/blender/makesrna/intern/rna_modifier.c
index 69a3380,4ca7493..09a0f05
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@@ -1868,18 -1868,6 +1868,19 @@@ static void rna_def_modifier_boolean(Bl
  		{0, NULL, 0, NULL, NULL}
  	};
  
 +	static EnumPropertyItem prop_method_items[] = {
 +		{eBooleanModifierMethod_Carve, "CARVE", 0, "Carve", ""},
 +		{eBooleanModifierMethod_BMesh, "BMESH", 0, "BMesh", ""},
 +		{0, NULL, 0, NULL, NULL}
 +	};
 +
 +	static EnumPropertyItem prop_option_items[] = {
 +		{eBooleanModifierFlag_Dissolve, "DISSOLVE", 0, "Dissolve", ""},
 +		{eBooleanModifierFlag_Separate, "SEPARATE", 0, "Separate", ""},
++		{eBooleanModifierFlag_ConnectRegions, "CONNECT_REGIONS", 0, "Fill Holes", ""},
 +		{0, NULL, 0, NULL, NULL}
 +	};
 +
  	srna = RNA_def_struct(brna, "BooleanModifier", "Modifier");
  	RNA_def_struct_ui_text(srna, "Boolean Modifier", "Boolean operations modifier");
  	RNA_def_struct_sdna(srna, "BooleanModifierData");
diff --cc source/blender/modifiers/intern/MOD_boolean.c
index cefd5b1,3fd2c8a..4a72926
--- a/source/blender/modifiers/intern/MOD_boolean.c
+++ b/source/blender/modifiers/intern/MOD_boolean.c
@@@ -50,25 -48,6 +50,25 @@@
  #include "MOD_boolean_util.h"
  #include "MOD_util.h"
  
 +#ifdef USE_BMESH
 +#include "BLI_math_geom.h"
 +#include "MEM_guardedalloc.h"
 +
 +#include "bmesh.h"
 +#include "bmesh_tools.h"
 +#include "tools/bmesh_intersect.h"
 +#endif
 +
 +#include "PIL_time.h"
 +#include "PIL_time_utildefines.h"
 +
 +static void initData(ModifierData *md)
 +{
 +	BooleanModifierData *bmd = (BooleanModifierData *)md;
 +
- 	bmd->flag = eBooleanModifierFlag_Dissolve;
++	bmd->flag = eBooleanModifierFlag_Dissolve | eBooleanModifierFlag_ConnectRegions;
 +}
 +
  static void copyData(ModifierData *md, ModifierData *target)
  {
  #if 0
@@@ -151,156 -129,10 +151,157 @@@ static DerivedMesh *get_quick_derivedMe
  
  	return result;
  }
 +#endif  /* defined(USE_CARVE) || defined(USE_BMESH) */
 +
 +
 +/* -------------------------------------------------------------------- */
 +/* BMESH */
 +
 +#ifdef USE_BMESH
 +
 +/* has no meaning for faces, do this so we can tell which face is which */
 +#define BM_FACE_TAG BM_ELEM_DRAW
 +
 +/**
 + * Compare selected/unselected.
 + */
 +static int bm_face_isect_pair(BMFace *f, void *UNUSED(user_data))
 +{
 +	return BM_elem_flag_test_bool(f, BM_FACE_TAG);
 +}
 +
 +static DerivedMesh *applyModifier_bmesh(
 +        ModifierData *md, Object *ob,
 +        DerivedMesh *dm,
 +        ModifierApplyFlag flag)
 +{
 +	BooleanModifierData *bmd = (BooleanModifierData *) md;
 +	DerivedMesh *dm_other;
 +
 +	if (!bmd->object)
 +		return dm;
 +
 +	dm_other = get_dm_for_modifier(bmd->object, flag);
 +
 +	if (dm_other) {
 +		DerivedMesh *result;
 +
 +		/* when one of objects is empty (has got no faces) we could speed up
 +		 * calculation a bit returning one of objects' derived meshes (or empty one)
 +		 * Returning mesh is depended on modifiers operation (sergey) */
 +		result = get_quick_derivedMesh(dm, dm_other, bmd->operation);
 +
 +		if (result == NULL) {
 +			BMesh *bm;
 +			const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_DM(dm, dm_other);
 +
 +			TIMEIT_START(boolean_bmesh);
 +			bm = BM_mesh_create(&allocsize);
 +
 +			DM_to_bmesh_ex(dm_other, bm, true);
 +			DM_to_bmesh_ex(dm, bm, true);
 +
 +			if (1) {
 +				/* create tessface & intersect */
 +				const int looptris_tot = poly_to_tri_count(bm->totface, bm->totloop);
 +				int tottri;
 +				BMLoop *(*looptris)[3];
 +
 +				looptris = MEM_mallocN(sizeof(*looptris) * looptris_tot, __func__);
 +
 +				BM_bmesh_calc_tessellation(bm, looptris, &tottri);
 +
 +				/* postpone this until after tessellating
 +				 * so we can use the original normals before the vertex are moved */
 +				{
 +					BMIter iter;
 +					int i;
 +					const int i_verts_end = dm_other->getNumVerts(dm_other);
 +					const int i_faces_end = dm_other->getNumPolys(dm_other);
 +
 +					float imat[4][4];
 +					float omat[4][4];
 +
 +					invert_m4_m4(imat, ob->obmat);
 +					mul_m4_m4m4(omat, imat, bmd->object->obmat);
 +
 +
 +					BMVert *eve;
 +					i = 0;
 +					BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
 +						mul_m4_v3(omat, eve->co);
 +						if (++i == i_verts_end) {
 +							break;
 +						}
 +					}
 +
 +					/* we need face normals because of 'BM_face_split_edgenet'
 +					 * we could calculate on the fly too (before calling split). */
 +					float nmat[4][4];
 +					invert_m4_m4(nmat, omat);
 +
 +					BMFace *efa;
 +					i = 0;
 +					BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
 +						mul_transposed_mat3_m4_v3(nmat, efa->no);
 +						normalize_v3(efa->no);
 +						BM_elem_flag_enable(efa, BM_FACE_TAG);  /* temp tag to test which side split faces are from */
 +						if (++i == i_faces_end) {
 +							break;
 +						}
 +					}
 +				}
 +
 +				/* not needed, but normals for 'dm' will be invalid,
 +				 * currently this is ok for 'BM_mesh_intersect' */
 +				// BM_mesh_normals_update(bm);
 +
 +				BM_mesh_intersect(
 +				        bm,
 +				        looptris, tottri,
 +				        bm_face_isect_pair, NULL,
 +				        false,
 +				        (bmd->flag & eBooleanModifierFlag_Separate) != 0,
 +				        (bmd->flag & eBooleanModifierFlag_Dissolve) != 0,
++				        (bmd->flag & eBooleanModifierFlag_ConnectRegions) != 0,
 +				        bmd->operation,
 +				        bmd->threshold);
 +
 +				MEM_freeN(looptris);
 +			}
 +
 +			result = CDDM_from_bmesh(bm, true);
 +
 +			BM_mesh_free(bm);
 +
 +			result->dirty |= DM_DIRTY_NORMALS;
 +
 +			TIMEIT_END(boolean_bmesh);
 +
 +			return result;
 +		}
 +
 +		/* if new mesh returned, return it; otherwise there was
 +		 * an error, so delete the modifier object */
 +		if (result)
 +			return result;
 +		else
 +			modifier_setError(md, "Cannot execute boolean operation");
 +	}
 +
 +	return dm;
 +}
 +#endif  /* USE_BMESH */
 +
  
 -static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 -                                  DerivedMesh *derivedData,
 -                                  ModifierApplyFlag flag)
 +/* -------------------------------------------------------------------- */
 +/* CARVE */
 +
 +#ifdef USE_CARVE
 +static DerivedMesh *applyModifier_carve(
 +        ModifierData *md, Object *ob,
 +        DerivedMesh *derivedData,
 +        ModifierApplyFlag flag)
  {
  	BooleanModifierData *bmd = (BooleanModifierData *) md;
  	DerivedMesh *dm;




More information about the Bf-blender-cvs mailing list