Subsurf: Add API to provide vertex sharpness
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 1 Aug 2018 14:04:22 +0000 (16:04 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 1 Aug 2018 16:42:59 +0000 (18:42 +0200)
Currently unused, added for the future and API completeness.

intern/opensubdiv/internal/opensubdiv_converter_factory.cc
intern/opensubdiv/opensubdiv_converter_capi.h
source/blender/blenkernel/intern/subdiv_converter_mesh.c

index 321f580af97881b35a27373e42e5eca4415ee517..901a421314a964dbac8e297f48a171a59abdab95 100644 (file)
@@ -379,13 +379,18 @@ inline bool TopologyRefinerFactory<TopologyRefinerData>::assignComponentTags(
     if (converter->isInfiniteSharpVertex(converter, vertex_index)) {
       setBaseVertexSharpness(
           refiner, vertex_index, Crease::SHARPNESS_INFINITE);
-    } else if (vertex_edges.size() == 2) {
+      continue;
+    }
+    float sharpness = converter->getVertexSharpness(converter, vertex_index);
+    if (vertex_edges.size() == 2) {
       const int edge0 = vertex_edges[0], edge1 = vertex_edges[1];
       const float sharpness0 = refiner._levels[0]->getEdgeSharpness(edge0);
       const float sharpness1 = refiner._levels[0]->getEdgeSharpness(edge1);
-      const float sharpness = std::min(sharpness0, sharpness1);
-      setBaseVertexSharpness(refiner, vertex_index, sharpness);
+      // TODO(sergey): Find a better mixing between edge and vertex sharpness.
+      sharpness += std::min(sharpness0, sharpness1);
+      sharpness = std::min(sharpness, 1.0f);
     }
+    setBaseVertexSharpness(refiner, vertex_index, sharpness);
   }
   return true;
 }
index 1dd68f43c322427aa5ab709b7674c091bd902a30..9f559ee208b67c8eaff144b52950b131cd8673e7 100644 (file)
@@ -111,6 +111,10 @@ typedef struct OpenSubdiv_Converter {
   bool (*isInfiniteSharpVertex)(const struct OpenSubdiv_Converter* converter,
                                 const int vertex_index);
 
+  // If vertex is not infinitely sharp, this is it's actual sharpness.
+  float (*getVertexSharpness)(const struct OpenSubdiv_Converter* converter,
+                              const int vertex_index);
+
   //////////////////////////////////////////////////////////////////////////////
   // Face-varying data.
 
index 5e320678814d8b3e8644fb5fe4a6047505d8d86d..b1e3be6c7993686c7d553c6886fd5af309f02706 100644 (file)
@@ -171,6 +171,12 @@ static bool is_infinite_sharp_vertex(const OpenSubdiv_Converter *converter,
                                    vertex_index);
 }
 
+static float get_vertex_sharpness(const OpenSubdiv_Converter *UNUSED(converter),
+                                  int UNUSED(manifold_vertex_index))
+{
+       return 0.0f;
+}
+
 static int get_num_uv_layers(const OpenSubdiv_Converter *converter)
 {
        ConverterStorage *storage = converter->user_data;
@@ -278,6 +284,7 @@ static void init_functions(OpenSubdiv_Converter *converter)
        converter->getNumVertexFaces = NULL;
        converter->getVertexFaces = NULL;
        converter->isInfiniteSharpVertex = is_infinite_sharp_vertex;
+       converter->getVertexSharpness = get_vertex_sharpness;
 
        converter->getNumUVLayers = get_num_uv_layers;
        converter->precalcUVLayer = precalc_uv_layer;