diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-08-01 16:43:57 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-08-01 19:42:59 +0300 |
commit | 4fe14d6a26e101a32e6a0ec9722248d215287a9d (patch) | |
tree | f8ace27ca928a36f2e1fad8d2603324878772b0a | |
parent | 63058490a3da932d2c9224aa4555f23eebb77264 (diff) |
Subsurf: Support subdivision of mesh with just loose elements
-rw-r--r-- | source/blender/blenkernel/intern/subdiv.c | 22 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subdiv_eval.c | 8 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_subsurf.c | 6 |
3 files changed, 25 insertions, 11 deletions
diff --git a/source/blender/blenkernel/intern/subdiv.c b/source/blender/blenkernel/intern/subdiv.c index d8e0c517d91..bae5491c079 100644 --- a/source/blender/blenkernel/intern/subdiv.c +++ b/source/blender/blenkernel/intern/subdiv.c @@ -29,6 +29,8 @@ #include "BKE_subdiv.h" +#include "DNA_mesh_types.h" + #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" @@ -52,11 +54,18 @@ Subdiv *BKE_subdiv_new_from_converter(const SubdivSettings *settings, OpenSubdiv_TopologyRefinerSettings topology_refiner_settings; topology_refiner_settings.level = settings->level; topology_refiner_settings.is_adaptive = settings->is_adaptive; - struct OpenSubdiv_TopologyRefiner *osd_topology_refiner = - openSubdiv_createTopologyRefinerFromConverter( - converter, &topology_refiner_settings); - if (osd_topology_refiner == NULL) { - return NULL; + struct OpenSubdiv_TopologyRefiner *osd_topology_refiner = NULL; + if (converter->getNumVertices(converter) != 0) { + osd_topology_refiner = + openSubdiv_createTopologyRefinerFromConverter( + converter, &topology_refiner_settings); + + } + else { + /* TODO(sergey): Check whether original geometry had any vertices. + * The thing here is: OpenSubdiv can only deal with faces, but our + * side of subdiv also deals with loose vertices and edges. + */ } Subdiv *subdiv = MEM_callocN(sizeof(Subdiv), "subdiv from converetr"); subdiv->settings = *settings; @@ -75,6 +84,9 @@ Subdiv *BKE_subdiv_new_from_mesh(const SubdivSettings *settings, struct Mesh *mesh) { #ifdef WITH_OPENSUBDIV + if (mesh->totvert == 0) { + return NULL; + } OpenSubdiv_Converter converter; BKE_subdiv_converter_init_for_mesh(&converter, settings, mesh); Subdiv *subdiv = BKE_subdiv_new_from_converter(settings, &converter); diff --git a/source/blender/blenkernel/intern/subdiv_eval.c b/source/blender/blenkernel/intern/subdiv_eval.c index 7c90a2a25cd..0f928331724 100644 --- a/source/blender/blenkernel/intern/subdiv_eval.c +++ b/source/blender/blenkernel/intern/subdiv_eval.c @@ -48,7 +48,10 @@ void BKE_subdiv_eval_begin(Subdiv *subdiv) { #ifdef WITH_OPENSUBDIV - if (subdiv->evaluator == NULL) { + if (subdiv->topology_refiner == NULL) { + /* Happens on input mesh with just loose geometry. */ + } + else if (subdiv->evaluator == NULL) { BKE_subdiv_stats_begin(&subdiv->stats, SUBDIV_STATS_EVALUATOR_CREATE); subdiv->evaluator = openSubdiv_createEvaluatorFromTopologyRefiner( subdiv->topology_refiner); @@ -132,6 +135,9 @@ void BKE_subdiv_eval_update_from_mesh(Subdiv *subdiv, const Mesh *mesh) { #ifdef WITH_OPENSUBDIV BKE_subdiv_eval_begin(subdiv); + if (subdiv->evaluator == NULL) { + return; + } /* Set coordinates of base mesh vertices. */ set_coarse_positions(subdiv, mesh); /* Set face-varyign data to UV maps. */ diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c index 08dc7c92693..1b25b4f62dc 100644 --- a/source/blender/modifiers/intern/MOD_subsurf.c +++ b/source/blender/modifiers/intern/MOD_subsurf.c @@ -236,11 +236,7 @@ static Mesh *applyModifier_subdiv(ModifierData *md, /* TODO(sergey): Try to re-use subdiv when possible. */ Subdiv *subdiv = BKE_subdiv_new_from_mesh(&subdiv_settings, mesh); if (subdiv == NULL) { - /* Happens on bad topology. */ - /* TODO(sergey): This also happens on meshes without faces, so probably - * need to handle those differently (i.e. set modifier error when - * topology itself is bad, and not do anything when there are no faces). - */ + /* Happens on bad topology, ut also on empty input mesh. */ return result; } SubdivToMeshSettings mesh_settings; |