[Bf-blender-cvs] [6cba20a] master: OpenSubdiv: Tweaks to AABB calculation when using opensubdiv for subsurf

Sergey Sharybin noreply at git.blender.org
Wed Aug 5 14:47:15 CEST 2015


Commit: 6cba20a8e60513ce73c4a75f44caafb854b359a1
Author: Sergey Sharybin
Date:   Wed Aug 5 14:43:51 2015 +0200
Branches: master
https://developer.blender.org/rB6cba20a8e60513ce73c4a75f44caafb854b359a1

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.

===================================================================

M	source/blender/blenkernel/intern/CCGSubSurf.h
M	source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/blenkernel/intern/subsurf_ccg.c

===================================================================

diff --git a/source/blender/blenkernel/intern/CCGSubSurf.h b/source/blender/blenkernel/intern/CCGSubSurf.h
index 1649cec..e9ad4c5 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.h
+++ b/source/blender/blenkernel/intern/CCGSubSurf.h
@@ -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__ */
diff --git a/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c b/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
index 81f9ea6..882ede0 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
@@ -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 */
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index b52bd08..6c13c79 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -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");
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index a3e4b47..617bf70 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -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))




More information about the Bf-blender-cvs mailing list