OpenSubdiv: Tweaks to AABB calculation when using opensubdiv for subsurf

Use coarse coordinates to calculate AABB which gives much better approximation
of AABB than using unity AABB size.
This commit is contained in:
2015-08-05 14:43:51 +02:00
parent 5b76f72904
commit 6cba20a8e6
4 changed files with 20 additions and 21 deletions

View File

@@ -236,6 +236,8 @@ void ccgSubSurf_evaluatorFVarUV(CCGSubSurf *ss,
void ccgSubSurf_free_osd_mesh(CCGSubSurf *ss);
void ccgSubSurf_getMinMax(CCGSubSurf *ss, float r_min[3], float r_max[3]);
#endif
#endif /* __CCGSUBSURF_H__ */

View File

@@ -876,4 +876,13 @@ void ccgSubSurf_free_osd_mesh(CCGSubSurf *ss)
}
}
void ccgSubSurf_getMinMax(CCGSubSurf *ss, float r_min[3], float r_max[3])
{
int i;
BLI_assert(ss->use_grids == false);
for (i = 0; i < ss->osd_num_coarse_coords; i++) {
DO_MINMAX(ss->osd_coarse_coords[i], r_min, r_max);
}
}
#endif /* WITH_OPENSUBDIV */

View File

@@ -78,8 +78,6 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm);
#ifdef WITH_OPENSUBDIV
# include "DNA_userdef_types.h"
# include "BKE_subsurf.h"
# include "CCGSubSurf.h"
#endif
/* very slow! enable for testing only! */
@@ -3523,25 +3521,8 @@ void DM_set_object_boundbox(Object *ob, DerivedMesh *dm)
{
float min[3], max[3];
#ifdef WITH_OPENSUBDIV
/* TODO(sergey): Currently no way to access bounding box from hi-res mesh. */
if (dm->type == DM_TYPE_CCGDM) {
CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
if (!ccgSubSurf_needGrids(ccgdm->ss)) {
copy_v3_fl3(min, -1.0f, -1.0f, -1.0f);
copy_v3_fl3(max, 1.0f, 1.0f, 1.0f);
}
else {
INIT_MINMAX(min, max);
dm->getMinMax(dm, min, max);
}
}
else
#endif
{
INIT_MINMAX(min, max);
dm->getMinMax(dm, min, max);
}
INIT_MINMAX(min, max);
dm->getMinMax(dm, min, max);
if (!ob->bb)
ob->bb = MEM_callocN(sizeof(BoundBox), "DM-BoundBox");

View File

@@ -848,6 +848,13 @@ static void ccgDM_getMinMax(DerivedMesh *dm, float r_min[3], float r_max[3])
int i, edgeSize = ccgSubSurf_getEdgeSize(ss);
int gridSize = ccgSubSurf_getGridSize(ss);
#ifdef WITH_OPENSUBDIV
if (ccgdm->useGpuBackend) {
ccgSubSurf_getMinMax(ccgdm->ss, r_min, r_max);
return;
}
#endif
CCG_key_top_level(&key, ss);
if (!ccgSubSurf_getNumVerts(ss))