Commit: c084520b0376c4ab92cb0193577a79cf23e5bb80
Author: Reinier de Blois
Date:   Tue Apr 5 20:38:42 2016 +0200
Branches: master
https://developer.blender.org/rBc084520b0376c4ab92cb0193577a79cf23e5bb80

Expose new Recast partitioning methods for navmesh generation

This patch depends on D1747, which upgrades the Recast version.  It exposes the 
new Recast partitioning methods in the navmesh generation.

Reviewers: campbellbarton, moguri

Reviewed By: moguri

Projects: #bf_blender

Differential Revision: https://developer.blender.org/D1748

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

M       release/scripts/startup/bl_ui/properties_game.py
M       source/blender/editors/mesh/mesh_navmesh.c
M       source/blender/makesdna/DNA_scene_types.h
M       source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/properties_game.py 
b/release/scripts/startup/bl_ui/properties_game.py
index ed1253e..8baad4e 100644
--- a/release/scripts/startup/bl_ui/properties_game.py
+++ b/release/scripts/startup/bl_ui/properties_game.py
@@ -510,7 +510,11 @@ class SCENE_PT_game_navmesh(SceneButtonsPanel, Panel):
         col.label(text="Region:")
         row = col.row()
         row.prop(rd, "region_min_size")
-        row.prop(rd, "region_merge_size")
+        if rd.partitioning != 'LAYERS':
+            row.prop(rd, "region_merge_size")
+
+        col = layout.column()
+        col.prop(rd, "partitioning")
 
         col = layout.column()
         col.label(text="Polygonization:")
diff --git a/source/blender/editors/mesh/mesh_navmesh.c 
b/source/blender/editors/mesh/mesh_navmesh.c
index 4d07d50..b959219 100644
--- a/source/blender/editors/mesh/mesh_navmesh.c
+++ b/source/blender/editors/mesh/mesh_navmesh.c
@@ -245,20 +245,41 @@ static bool buildNavMesh(const RecastData *recastParams, 
int nverts, float *vert
                return false;
        }
 
-       /* Prepare for region partitioning, by calculating distance field along 
the walkable surface */
-       if (!recast_buildDistanceField(chf)) {
-               recast_destroyCompactHeightfield(chf);
+       if (recastParams->partitioning == RC_PARTITION_WATERSHED) {
+               /* Prepare for region partitioning, by calculating distance 
field along the walkable surface */
+               if (!recast_buildDistanceField(chf)) {
+                       recast_destroyCompactHeightfield(chf);
 
-               BKE_report(reports, RPT_ERROR, "Failed to build distance 
field");
-               return false;
-       }
+                       BKE_report(reports, RPT_ERROR, "Failed to build 
distance field");
+                       return false;
+               }
 
-       /* Partition the walkable surface into simple regions without holes */
-       if (!recast_buildRegions(chf, 0, minRegionArea, mergeRegionArea)) {
-               recast_destroyCompactHeightfield(chf);
+               /* Partition the walkable surface into simple regions without 
holes */
+               if (!recast_buildRegions(chf, 0, minRegionArea, 
mergeRegionArea)) {
+                       recast_destroyCompactHeightfield(chf);
 
-               BKE_report(reports, RPT_ERROR, "Failed to build regions");
-               return false;
+                       BKE_report(reports, RPT_ERROR, "Failed to build 
watershed regions");
+                       return false;
+               }
+       }
+       else if (recastParams->partitioning == RC_PARTITION_MONOTONE) {
+               /* Partition the walkable surface into simple regions without 
holes */
+               /* Monotone partitioning does not need distancefield. */
+               if (!recast_buildRegionsMonotone(chf, 0, minRegionArea, 
mergeRegionArea)) {
+                       recast_destroyCompactHeightfield(chf);
+
+                       BKE_report(reports, RPT_ERROR, "Failed to build 
monotone regions");
+                       return false;
+               }
+       }
+       else { /* RC_PARTITION_LAYERS */
+               /* Partition the walkable surface into simple regions without 
holes */
+               if (!recast_buildLayerRegions(chf, 0, minRegionArea)) {
+                       recast_destroyCompactHeightfield(chf);
+
+                       BKE_report(reports, RPT_ERROR, "Failed to build layer 
regions");
+                       return false;
+               }
        }
 
        /* ** Step 5: Trace and simplify region contours ** */
diff --git a/source/blender/makesdna/DNA_scene_types.h 
b/source/blender/makesdna/DNA_scene_types.h
index fd37bde..a8f78f6 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -795,9 +795,15 @@ typedef struct RecastData {
        int vertsperpoly;
        float detailsampledist;
        float detailsamplemaxerror;
-       short pad1, pad2;
+       char partitioning;
+       char pad1;
+       short pad2;
 } RecastData;
 
+#define RC_PARTITION_WATERSHED 0
+#define RC_PARTITION_MONOTONE 1
+#define RC_PARTITION_LAYERS 2
+
 typedef struct GameData {
 
        /* standalone player */
diff --git a/source/blender/makesrna/intern/rna_scene.c 
b/source/blender/makesrna/intern/rna_scene.c
index 2af58a9..94223f7 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -3565,6 +3565,13 @@ static void rna_def_scene_game_recast_data(BlenderRNA 
*brna)
        StructRNA *srna;
        PropertyRNA *prop;
 
+       static EnumPropertyItem rna_enum_partitioning_items[] = {
+               {RC_PARTITION_WATERSHED, "WATERSHED", 0, "Watershed", "Classic 
Recast partitioning method generating the nicest tessellation"},
+               {RC_PARTITION_MONOTONE, "MONOTONE", 0, "Monotone", "Fastest 
navmesh generation method, may create long thin polygons"},
+               {RC_PARTITION_LAYERS, "LAYERS", 0, "Layers", "Reasonably fast 
method that produces better triangles than monotone partitioning"},
+               {0, NULL, 0, NULL, NULL}
+       };
+
        srna = RNA_def_struct(brna, "SceneGameRecastData", NULL);
        RNA_def_struct_sdna(srna, "RecastData");
        RNA_def_struct_nested(brna, srna, "Scene");
@@ -3627,6 +3634,13 @@ static void rna_def_scene_game_recast_data(BlenderRNA 
*brna)
        RNA_def_property_ui_text(prop, "Merged Region Size", "Minimum regions 
size (smaller regions will be merged)");
        RNA_def_property_update(prop, NC_SCENE, NULL);
 
+       prop = RNA_def_property(srna, "partitioning", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_bitflag_sdna(prop, NULL, "partitioning");
+       RNA_def_property_enum_items(prop, rna_enum_partitioning_items);
+       RNA_def_property_enum_default(prop, RC_PARTITION_WATERSHED);
+       RNA_def_property_ui_text(prop, "Partitioning", "Choose partitioning 
method");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
+
        prop = RNA_def_property(srna, "edge_max_len", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_sdna(prop, NULL, "edgemaxlen");
        RNA_def_property_ui_range(prop, 0, 50, 1, 2);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to