OpenSubdiv: Properly respect Subdivide UVs option
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 22 Jul 2016 15:52:30 +0000 (17:52 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 22 Jul 2016 15:53:00 +0000 (17:53 +0200)
intern/opensubdiv/opensubdiv_converter.cc
intern/opensubdiv/opensubdiv_converter_capi.h
source/blender/blenkernel/intern/CCGSubSurf.c
source/blender/blenkernel/intern/CCGSubSurf.h
source/blender/blenkernel/intern/CCGSubSurf_intern.h
source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
source/blender/blenkernel/intern/CCGSubSurf_opensubdiv_converter.c
source/blender/blenkernel/intern/subsurf_ccg.c

index 9b2fb19808c1e4a7b436778c0504423bdeeff8ce..ea41a56768fd3c62329b09b588553ba8f3d857b9 100644 (file)
@@ -567,9 +567,12 @@ struct OpenSubdiv_TopologyRefinerDescr *openSubdiv_createTopologyRefinerDescr(
        Options options;
        options.SetVtxBoundaryInterpolation(Options::VTX_BOUNDARY_EDGE_ONLY);
        options.SetCreasingMethod(Options::CREASE_UNIFORM);
-       /* TODO(sergey): Get proper UV subdivide flag. */
-       // options.SetFVarLinearInterpolation(Options::FVAR_LINEAR_ALL);
-       options.SetFVarLinearInterpolation(Options::FVAR_LINEAR_CORNERS_ONLY);
+       if (converter->get_subdiv_uvs(converter)) {
+               options.SetFVarLinearInterpolation(Options::FVAR_LINEAR_CORNERS_ONLY);
+       }
+       else {
+               options.SetFVarLinearInterpolation(Options::FVAR_LINEAR_ALL);
+       }
 
        TopologyRefinerFactory<TopologyRefinerData>::Options
                topology_options(scheme_type, options);
@@ -649,6 +652,7 @@ int openSubdiv_topologyRefnerCompareConverter(
         const OpenSubdiv_TopologyRefinerDescr *topology_refiner,
         OpenSubdiv_Converter *converter)
 {
+       typedef OpenSubdiv::Sdc::Options Options;
        using OpenSubdiv::Far::ConstIndexArray;
        using OpenSubdiv::Far::TopologyRefiner;
        using OpenSubdiv::Far::TopologyLevel;
@@ -663,6 +667,12 @@ int openSubdiv_topologyRefnerCompareConverter(
        if (scheme_type != refiner->GetSchemeType()) {
                return false;
        }
+       const Options options = refiner->GetSchemeOptions();
+       Options::FVarLinearInterpolation interp = options.GetFVarLinearInterpolation();
+       const bool subdiv_uvs = (interp != Options::FVAR_LINEAR_ALL);
+       if (converter->get_subdiv_uvs(converter) != subdiv_uvs) {
+               return false;
+       }
        if (converter->get_num_verts(converter) != num_verts ||
            converter->get_num_edges(converter) != num_edges ||
            converter->get_num_faces(converter) != num_faces)
index 4448f108e8a12737a36715b8c9a9586aa4fd62d4..6eda6ae5d8ab79efefb23cfa77591e460e69d56a 100644 (file)
@@ -47,6 +47,8 @@ typedef struct OpenSubdiv_Converter {
 
        OpenSubdiv_SchemeType (*get_type)(const OpenSubdiv_Converter *converter);
 
+       bool (*get_subdiv_uvs)(const OpenSubdiv_Converter *converter);
+
        int (*get_num_faces)(const OpenSubdiv_Converter *converter);
        int (*get_num_edges)(const OpenSubdiv_Converter *converter);
        int (*get_num_verts)(const OpenSubdiv_Converter *converter);
index c4886a2174039a6baae6df70dc85a5ad71e5f7a2..792e9195f121b8aa3e67060e9cedf5d88b1b8d16 100644 (file)
@@ -316,6 +316,7 @@ CCGSubSurf *ccgSubSurf_new(CCGMeshIFC *ifc, int subdivLevels, CCGAllocatorIFC *a
                ss->osd_next_face_ptex_index = 0;
                ss->osd_coarse_coords = NULL;
                ss->osd_num_coarse_coords = 0;
+               ss->osd_subdiv_uvs = false;
 #endif
 
                return ss;
index 72f386bf246051e5091b41bd960967c0c6e78533..4c913e79586a0312d801cb97fdc666d776ccb43e 100644 (file)
@@ -244,6 +244,8 @@ void ccgSubSurf_free_osd_mesh(CCGSubSurf *ss);
 
 void ccgSubSurf_getMinMax(CCGSubSurf *ss, float r_min[3], float r_max[3]);
 
+void ccgSubSurf__sync_subdivUvs(CCGSubSurf *ss, bool subsurf_uvs);
+
 #endif
 
 #endif  /* __CCGSUBSURF_H__ */
index 7e8059e62fc0bfc615409ca64efb42939eb42e8e..9df1c9021efdd2aedf4fc9733e375cc28b616151 100644 (file)
@@ -254,6 +254,8 @@ struct CCGSubSurf {
         * to fill in PTex index of CCGFace.
         */
        int osd_next_face_ptex_index;
+
+       bool osd_subdiv_uvs;
 #endif
 };
 
index 9dc1a71adab9348d7b069e16d7d3e1df50b45d88..65cf899b42b60bd6061f9b9e9b626cc8c24fcce2 100644 (file)
@@ -984,6 +984,11 @@ void ccgSubSurf__delete_pending(void)
        BLI_spin_unlock(&delete_spin);
 }
 
+void ccgSubSurf__sync_subdivUvs(CCGSubSurf *ss, bool subdiv_uvs)
+{
+    ss->osd_subdiv_uvs = subdiv_uvs;
+}
+
 /* ** Public API ** */
 
 void BKE_subsurf_osd_init(void)
index 5c68e500300a357fdced45ae9fe6364ba5ac2c16..f1f82f458aa2c4af5ce2845bdd5fc62a52aa1465 100644 (file)
@@ -84,6 +84,13 @@ static OpenSubdiv_SchemeType conv_dm_get_type(
                return OSD_SCHEME_CATMARK;
 }
 
+static bool conv_dm_get_subdiv_uvs(
+        const OpenSubdiv_Converter *converter)
+{
+       ConvDMStorage *storage = converter->user_data;
+       return (storage->ss->osd_subdiv_uvs);
+}
+
 static int conv_dm_get_num_faces(const OpenSubdiv_Converter *converter)
 {
        ConvDMStorage *storage = converter->user_data;
@@ -424,6 +431,8 @@ void ccgSubSurf_converter_setup_from_derivedmesh(
 
        converter->get_type = conv_dm_get_type;
 
+       converter->get_subdiv_uvs = conv_dm_get_subdiv_uvs;
+
        converter->get_num_faces = conv_dm_get_num_faces;
        converter->get_num_edges = conv_dm_get_num_edges;
        converter->get_num_verts = conv_dm_get_num_verts;
@@ -517,6 +526,13 @@ static OpenSubdiv_SchemeType conv_ccg_get_bilinear_type(
        }
 }
 
+static bool conv_ccg_get_subdiv_uvs(
+        const OpenSubdiv_Converter *converter)
+{
+       CCGSubSurf *ss = converter->user_data;
+       return (ss->osd_subdiv_uvs);
+}
+
 static int conv_ccg_get_num_faces(const OpenSubdiv_Converter *converter)
 {
        CCGSubSurf *ss = converter->user_data;
@@ -696,6 +712,8 @@ void ccgSubSurf_converter_setup_from_ccg(CCGSubSurf *ss,
 {
        converter->get_type = conv_ccg_get_bilinear_type;
 
+       converter->get_subdiv_uvs = conv_ccg_get_subdiv_uvs;
+
        converter->get_num_faces = conv_ccg_get_num_faces;
        converter->get_num_edges = conv_ccg_get_num_edges;
        converter->get_num_verts = conv_ccg_get_num_verts;
index 7239566b59ddd5fc2e86d6bc8a19a344935c4627..02e529542be5b53e5aca1ad8bb1d512979899c4a 100644 (file)
@@ -794,7 +794,8 @@ static void ss_sync_osd_from_derivedmesh(CCGSubSurf *ss,
 static void ss_sync_from_derivedmesh(CCGSubSurf *ss,
                                      DerivedMesh *dm,
                                      float (*vertexCos)[3],
-                                     int use_flat_subdiv)
+                                     int use_flat_subdiv,
+                                     bool use_subdiv_uvs)
 {
 #ifdef WITH_OPENSUBDIV
        /* Reset all related descriptors if actual mesh topology changed or if
@@ -802,6 +803,7 @@ static void ss_sync_from_derivedmesh(CCGSubSurf *ss,
         */
        if (!ccgSubSurf_needGrids(ss)) {
                /* TODO(sergey): Use vertex coordinates and flat subdiv flag. */
+               ccgSubSurf__sync_subdivUvs(ss, use_subdiv_uvs);
                ccgSubSurf_checkTopologyChanged(ss, dm);
                ss_sync_osd_from_derivedmesh(ss, dm);
        }
@@ -5029,7 +5031,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
 #ifdef WITH_OPENSUBDIV
                ccgSubSurf_setSkipGrids(smd->emCache, use_gpu_backend);
 #endif
-               ss_sync_from_derivedmesh(smd->emCache, dm, vertCos, useSimple);
+               ss_sync_from_derivedmesh(smd->emCache, dm, vertCos, useSimple, useSubsurfUv);
                result = getCCGDerivedMesh(smd->emCache,
                                           drawInteriorEdges,
                                           useSubsurfUv, dm, use_gpu_backend);
@@ -5044,7 +5046,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
                
                ss = _getSubSurf(NULL, levels, 3, useSimple | CCG_USE_ARENA | CCG_CALC_NORMALS);
 
-               ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple);
+               ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple, useSubsurfUv);
 
                result = getCCGDerivedMesh(ss,
                                           drawInteriorEdges, useSubsurfUv, dm, false);
@@ -5075,7 +5077,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
                if (useIncremental && (flags & SUBSURF_IS_FINAL_CALC)) {
                        smd->mCache = ss = _getSubSurf(smd->mCache, levels, 3, useSimple | useAging | CCG_CALC_NORMALS);
 
-                       ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple);
+                       ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple, useSubsurfUv);
 
                        result = getCCGDerivedMesh(smd->mCache,
                                                   drawInteriorEdges,
@@ -5115,7 +5117,7 @@ struct DerivedMesh *subsurf_make_derived_from_derived(
 #ifdef WITH_OPENSUBDIV
                        ccgSubSurf_setSkipGrids(ss, use_gpu_backend);
 #endif
-                       ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple);
+                       ss_sync_from_derivedmesh(ss, dm, vertCos, useSimple, useSubsurfUv);
 
                        result = getCCGDerivedMesh(ss, drawInteriorEdges, useSubsurfUv, dm, use_gpu_backend);
 
@@ -5144,7 +5146,7 @@ void subsurf_calculate_limit_positions(Mesh *me, float (*r_positions)[3])
        CCGVertIterator vi;
        DerivedMesh *dm = CDDM_from_mesh(me);
 
-       ss_sync_from_derivedmesh(ss, dm, NULL, 0);
+       ss_sync_from_derivedmesh(ss, dm, NULL, 0, 0);
 
        for (ccgSubSurf_initVertIterator(ss, &vi); !ccgVertIterator_isStopped(&vi); ccgVertIterator_next(&vi)) {
                CCGVert *v = ccgVertIterator_getCurrent(&vi);