Subsurf: Support subdivision of mesh with just loose elements

This commit is contained in:
2018-08-01 15:43:57 +02:00
parent 63058490a3
commit 4fe14d6a26
3 changed files with 25 additions and 11 deletions

View File

@@ -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);

View File

@@ -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. */

View File

@@ -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;