Browse Source

Made a public getter for model bounding boxes.

David Piuva 5 years ago
parent
commit
b81656e5b2

+ 6 - 0
Source/DFPSR/api/modelAPI.cpp

@@ -203,6 +203,12 @@ void model_renderDepth(const Model& model, const Transform3D &modelToWorldTransf
 	}
 }
 
+void model_getBoundingBox(const Model& model, FVector3D& minimum, FVector3D& maximum) {
+	MUST_EXIST(model,model_getBoundingBox);
+	minimum = model->minBound;
+	maximum = model->maxBound;
+}
+
 // Context for rendering multiple models at the same time for improved speed
 class RendererImpl {
 private:

+ 3 - 0
Source/DFPSR/api/modelAPI.h

@@ -125,6 +125,9 @@ namespace dsr {
 	//   If multiple existing points are within the same distance,
 	//   then the point with the lowest index is preferred, just like in model_findPoint.
 	int model_addPointIfNeeded(Model& model, const FVector3D &position, float threshold);
+	// Get the bounding box, which expands automatically when adding or moving points in the model.
+	// Side-effect: Writes model's bounding box to minimum and maximum by reference.
+	void model_getBoundingBox(const Model& model, FVector3D& minimum, FVector3D& maximum);
 
 	// Get the vertex position's index, which refers to a shared point in the model.
 	// Pre-condition: model must refer to an existing model.

+ 6 - 1
Source/SDK/sandbox/sprite/spriteAPI.cpp

@@ -804,6 +804,11 @@ static FVector3D unpackNormals(FVector4D packedNormals) {
 // worldOrigin is the perceived world's origin in target pixel coordinates
 // modelToWorldSpace is used to place the model freely in the world
 static IRect renderModel(Model model, OrthoView view, ImageF32 depthBuffer, ImageRgbaU8 diffuseTarget, ImageRgbaU8 normalTarget, FVector2D worldOrigin, Transform3D modelToWorldSpace) {
+	// Get the model's 3D bound
+	//FVector3D minBound, maxBound;
+	//model_getBoundingBox(model, minBound, maxBound);
+	// TODO: Quick culling test based on the 3D bounding box using only 8 points.
+
 	int pointCount = model_getNumberOfPoints(model);
 	IRect clipBound = image_getBound(depthBuffer);
 
@@ -823,7 +828,7 @@ static IRect renderModel(Model model, OrthoView view, ImageF32 depthBuffer, Imag
 		dirtyBox = IRect::merge(dirtyBox, IRect((int)(screenProjection.x), (int)(screenProjection.y), 1, 1));
 	}
 
-	// Skip early if the culling test fails
+	// Skip early if the more precise culling test fails
 	if (!(IRect::cut(clipBound, dirtyBox).hasArea())) {
 		// Nothing drawn, no dirty rectangle
 		return IRect();