Commit: 9283c5e96cc2d9549b2a749ab1610f7459b50168
Author: Martin Felke
Date:   Thu Nov 13 00:12:39 2014 +0100
Branches: fracture_modifier
https://developer.blender.org/rB9283c5e96cc2d9549b2a749ab1610f7459b50168

fix normals improvement: take only normals pointing to same direction into 
account inside a certain search radius

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

M       release/scripts/startup/bl_ui/properties_physics_fracture.py
M       source/blender/makesdna/DNA_modifier_types.h
M       source/blender/makesrna/intern/rna_modifier.c
M       source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_fracture.py 
b/release/scripts/startup/bl_ui/properties_physics_fracture.py
index e142927..919ee6e 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fracture.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fracture.py
@@ -153,7 +153,8 @@ class PHYSICS_PT_fracture_simulation(PhysicButtonsPanel, 
Panel):
             box.prop_search(md, "inner_vertex_group", ob, "vertex_groups", 
text = "")
             box.prop(md, "autohide_dist")
 
-            box.prop(md, "fix_normals");
+            box.prop(md, "fix_normals")
+            box.prop(md, "nor_range")
             if not(md.refresh):
                 box.prop(md, "execute_threaded")
             box.operator("object.rigidbody_convert_to_objects", text = 
"Convert To Objects")
diff --git a/source/blender/makesdna/DNA_modifier_types.h 
b/source/blender/makesdna/DNA_modifier_types.h
index bd50271..65fe44e 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1462,6 +1462,7 @@ typedef struct FractureModifierData {
        float cluster_breaking_threshold;
        float contact_dist, autohide_dist;
        float splinter_length;
+       float nor_range;
 
        /* flags */
        int refresh;
@@ -1488,7 +1489,7 @@ typedef struct FractureModifierData {
        /* internal values */
        float max_vol;
 
-       char pad[4];
+       //char pad[4];
 } FractureModifierData;
 
 #endif  /* __DNA_MODIFIER_TYPES_H__ */
diff --git a/source/blender/makesrna/intern/rna_modifier.c 
b/source/blender/makesrna/intern/rna_modifier.c
index 2cb3ad2..18f99d6 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -4021,7 +4021,7 @@ static void rna_def_modifier_fracture(BlenderRNA *brna)
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
        prop = RNA_def_property(srna, "splinter_length", PROP_FLOAT, PROP_NONE);
-       RNA_def_property_range(prop, 1.0f, 1000.0f);
+       RNA_def_property_range(prop, 1.0f, FLT_MAX);
        RNA_def_property_ui_text(prop, "Splinter length", "Length of 
splinters");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
@@ -4031,6 +4031,11 @@ static void rna_def_modifier_fracture(BlenderRNA *brna)
        RNA_def_property_int_funcs(prop, NULL, 
"rna_RigidBodyModifier_cluster_solver_iterations_override_set", NULL);
        RNA_def_property_ui_text(prop, "Cluster Solver Iterations Override", 
"Override the world constraint solver iteration value for INSIDE clusters with 
this value, 0 means no override");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+       prop = RNA_def_property(srna, "nor_range", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_range(prop, 0.0f, FLT_MAX);
+       RNA_def_property_ui_text(prop, "Normal Search Radius", "Radius in which 
to search for valid normals");
+       RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
 void RNA_def_modifier(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_fracture.c 
b/source/blender/modifiers/intern/MOD_fracture.c
index 097b3ae..6d80459 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -126,6 +126,7 @@ static void initData(ModifierData *md)
         * default use case is with this flag being enabled, disable at own 
risk */
        fmd->use_particle_birth_coordinates = true;
        fmd->splinter_length = 1.0f;
+       fmd->nor_range = 1.0f;
 }
 
 static void freeMeshIsland(FractureModifierData *rmd, MeshIsland *mi, bool 
remove_rigidbody)
@@ -442,17 +443,38 @@ static KDTree *build_nor_tree(DerivedMesh *dm)
        return tree;
 }
 
-static void find_normal(DerivedMesh *dm, KDTree *tree, float co[3], short 
no[3])
+static void find_normal(DerivedMesh *dm, KDTree *tree, float co[3], short 
no[3], short rno[3], float range)
 {
-       KDTreeNearest n;
-       int index = 0;
+       KDTreeNearest *n = NULL, n2;
+       int index = 0, i = 0, count = 0;
        MVert mvert;
+       float fno[3], vno[3];
 
-       index = BLI_kdtree_find_nearest(tree, co, &n);
+       normal_short_to_float_v3(fno, no);
 
-       dm->getVert(dm, index, &mvert);
+       count = BLI_kdtree_range_search(tree, co, &n, range);
+       for (i = 0; i < count; i++)
+       {
+               index = n[i].index;
+               dm->getVert(dm, index, &mvert);
+               normal_short_to_float_v3(vno, mvert.no);
+               if ((dot_v3v3(fno, vno) > 0.0f)){
+                       copy_v3_v3_short(rno, mvert.no);
+
+                       if (n != NULL) {
+                               MEM_freeN(n);
+                               n = NULL;
+                       }
+
+                       return;
+               }
+       }
 
-       copy_v3_v3_short(no, mvert.no);
+       /*fallback if no valid normal in searchrange....*/
+       BLI_kdtree_find_nearest(tree, co, &n2);
+       index = n2.index;
+       dm->getVert(dm, index, &mvert);
+       copy_v3_v3_short(rno, mvert.no);
 }
 
 static DerivedMesh *get_clean_dm(Object *ob, DerivedMesh *dm)
@@ -1328,6 +1350,7 @@ static void 
mesh_separate_loose_partition(FractureModifierData *rmd, Object *ob,
                if (!BM_elem_flag_test(v_seed, BM_ELEM_TAG) && 
!BM_elem_flag_test(v_seed, BM_ELEM_INTERNAL_TAG)) {
 
                        short no[3];
+                       short vno[3];
 
                        v_tag = MEM_callocN(sizeof(BMVert *), "v_tag");
                        startco = MEM_callocN(sizeof(float), 
"mesh_separate_loose->startco");
@@ -1345,7 +1368,8 @@ static void 
mesh_separate_loose_partition(FractureModifierData *rmd, Object *ob,
 
                        startno = MEM_reallocN(startno, (tag_counter + 1) * 3 * 
sizeof(short));
 
-                       find_normal(dm, rmd->nor_tree, v_seed->co, no);
+                       normal_float_to_short_v3(vno, v_seed->no);
+                       find_normal(dm, rmd->nor_tree, v_seed->co, vno, no, 
rmd->nor_range);
                        startno[3 * tag_counter] = no[0];
                        startno[3 * tag_counter + 1] = no[1];
                        startno[3 * tag_counter + 2] = no[2];
@@ -1366,6 +1390,7 @@ static void 
mesh_separate_loose_partition(FractureModifierData *rmd, Object *ob,
                for (; e; e = BMW_step(&walker)) {
                        if (!BM_elem_flag_test(e->v1, BM_ELEM_TAG) && 
!BM_elem_flag_test(e->v1, BM_ELEM_INTERNAL_TAG)) {
                                short no[3];
+                               short vno[3];
 
                                BM_elem_flag_enable(e->v1, BM_ELEM_TAG);
                                BM_elem_flag_enable(e->v1, 
BM_ELEM_INTERNAL_TAG);
@@ -1380,7 +1405,8 @@ static void 
mesh_separate_loose_partition(FractureModifierData *rmd, Object *ob,
 
                                startno = MEM_reallocN(startno, (tag_counter + 
1) * 3 * sizeof(short));
 
-                               find_normal(dm, rmd->nor_tree, e->v1->co, no);
+                               normal_float_to_short_v3(vno, e->v1->no);
+                               find_normal(dm, rmd->nor_tree, e->v1->co, vno, 
no, rmd->nor_range);
                                startno[3 * tag_counter] = no[0];
                                startno[3 * tag_counter + 1] = no[1];
                                startno[3 * tag_counter + 2] = no[2];
@@ -1390,6 +1416,7 @@ static void 
mesh_separate_loose_partition(FractureModifierData *rmd, Object *ob,
                        }
                        if (!BM_elem_flag_test(e->v2, BM_ELEM_TAG) && 
!BM_elem_flag_test(e->v2, BM_ELEM_INTERNAL_TAG)) {
                                short no[3];
+                               short vno[3];
 
                                BM_elem_flag_enable(e->v2, BM_ELEM_TAG);
                                BM_elem_flag_enable(e->v2, 
BM_ELEM_INTERNAL_TAG);
@@ -1404,7 +1431,8 @@ static void 
mesh_separate_loose_partition(FractureModifierData *rmd, Object *ob,
 
                                startno = MEM_reallocN(startno, (tag_counter + 
1) * 3 * sizeof(short));
 
-                               find_normal(dm, rmd->nor_tree, e->v2->co, no);
+                               normal_float_to_short_v3(vno, e->v2->no);
+                               find_normal(dm, rmd->nor_tree, e->v2->co, vno, 
no, rmd->nor_range);
                                startno[3 * tag_counter] = no[0];
                                startno[3 * tag_counter + 1] = no[1];
                                startno[3 * tag_counter + 2] = no[2];
@@ -2240,7 +2268,7 @@ static DerivedMesh *doSimulate(FractureModifierData *fmd, 
Object *ob, DerivedMes
                                                mi->vertco[j * 3 + 2] = 
mv->co[2];
 
                                                /* either take orignormals or 
take ones from fractured mesh */
-                                               find_normal(orig_dm, 
fmd->nor_tree, mv->co, no);
+                                               find_normal(orig_dm, 
fmd->nor_tree, mv->co, mv->no, no, fmd->nor_range);
 
                                                mi->vertno[j * 3] = no[0];
                                                mi->vertno[j * 3 + 1] = no[1];

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to