Subdiv: Set edge render flags according to Optimal Display
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 3 Dec 2018 15:59:11 +0000 (16:59 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 3 Dec 2018 16:05:28 +0000 (17:05 +0100)
This is a part of T58609, but work is still needed to properly
support this flag in the draw manager.

source/blender/blenkernel/BKE_subdiv_mesh.h
source/blender/blenkernel/intern/multires_subdiv.c
source/blender/blenkernel/intern/subdiv_mesh.c
source/blender/modifiers/intern/MOD_subsurf.c

index f719527..6f1ffb2 100644 (file)
@@ -45,6 +45,8 @@ typedef struct SubdivToMeshSettings {
         * `resolution - 1`.
         */
        int resolution;
+       /* When true, only edges emitted from coarse ones will be displayed. */
+       bool use_optimal_display;
 } SubdivToMeshSettings;
 
 /* Create real hi-res mesh from subdivision, all geometry is "real". */
index e0b316d..3de007d 100644 (file)
@@ -64,4 +64,6 @@ void BKE_multires_subdiv_mesh_settings_init(
        const int level = multires_get_level(
                scene, object, mmd, use_render_params, ignore_simplify);
        mesh_settings->resolution = (1 << level) + 1;
+       mesh_settings->use_optimal_display =
+               (mmd->flags & eMultiresModifierFlag_ControlEdges);
 }
index d9fcdf5..4d9e899 100644 (file)
@@ -53,6 +53,7 @@
  */
 
 typedef struct SubdivMeshContext {
+       const SubdivToMeshSettings *settings;
        const Mesh *coarse_mesh;
        Subdiv *subdiv;
        Mesh *subdiv_mesh;
@@ -766,6 +767,9 @@ static void subdiv_copy_edge_data(
                subdiv_edge->crease = 0;
                subdiv_edge->bweight = 0;
                subdiv_edge->flag = 0;
+               if (!ctx->settings->use_optimal_display) {
+                       subdiv_edge->flag |= ME_EDGERENDER;
+               }
                if (ctx->edge_origindex != NULL) {
                        ctx->edge_origindex[subdiv_edge_index] = ORIGINDEX_NONE;
                }
@@ -777,6 +781,7 @@ static void subdiv_copy_edge_data(
                             coarse_edge_index,
                             subdiv_edge_index,
                             1);
+       subdiv_edge->flag |= ME_EDGERENDER;
 }
 
 static void subdiv_mesh_edge(
@@ -1123,6 +1128,7 @@ Mesh *BKE_subdiv_to_mesh(
        }
        /* Initialize subdivion mesh creation context/ */
        SubdivMeshContext subdiv_context = {0};
+       subdiv_context.settings = settings;
        subdiv_context.coarse_mesh = coarse_mesh;
        subdiv_context.subdiv = subdiv;
        /* Multi-threaded traversal/evaluation. */
index 9c6bff6..3b81ec1 100644 (file)
@@ -130,6 +130,8 @@ static void subdiv_mesh_settings_init(SubdivToMeshSettings *settings,
 {
        const int level = subdiv_levels_for_modifier_get(smd, ctx);
        settings->resolution = (1 << level) + 1;
+       settings->use_optimal_display =
+               (smd->flags & eSubsurfModifierFlag_ControlEdges);
 }
 
 static Mesh *subdiv_as_mesh(SubsurfModifierData *smd,