Browse Source

Noticed that the model's bounds were flipped.

David Piuva 5 years ago
parent
commit
dd23994c14
2 changed files with 10 additions and 19 deletions
  1. 6 6
      Source/DFPSR/render/model/Model.cpp
  2. 4 13
      Source/SDK/sandbox/sprite/spriteAPI.cpp

+ 6 - 6
Source/DFPSR/render/model/Model.cpp

@@ -292,12 +292,12 @@ int ModelImpl::getNumberOfPoints() const {
 	return this->positionBuffer.length();
 }
 void ModelImpl::expandBound(const FVector3D& point) {
-	if (this->minBound.x < point.x) { this->minBound.x = point.x; }
-	if (this->minBound.y < point.y) { this->minBound.y = point.y; }
-	if (this->minBound.z < point.z) { this->minBound.z = point.z; }
-	if (this->maxBound.x > point.x) { this->maxBound.x = point.x; }
-	if (this->maxBound.y > point.y) { this->maxBound.y = point.y; }
-	if (this->maxBound.z > point.z) { this->maxBound.z = point.z; }
+	if (this->minBound.x > point.x) { this->minBound.x = point.x; }
+	if (this->minBound.y > point.y) { this->minBound.y = point.y; }
+	if (this->minBound.z > point.z) { this->minBound.z = point.z; }
+	if (this->maxBound.x < point.x) { this->maxBound.x = point.x; }
+	if (this->maxBound.y < point.y) { this->maxBound.y = point.y; }
+	if (this->maxBound.z < point.z) { this->maxBound.z = point.z; }
 }
 int ModelImpl::findPoint(const FVector3D &position, float threshold) const {
 	float bestDistance = threshold;

+ 4 - 13
Source/SDK/sandbox/sprite/spriteAPI.cpp

@@ -805,8 +805,8 @@ static FVector3D unpackNormals(FVector4D packedNormals) {
 // 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);
+	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);
@@ -904,17 +904,8 @@ void sprite_generateFromModel(ImageRgbaU8& targetAtlas, String& targetConfigText
 		return;
 	} else {
 		// Measure the bounding cylinder for determining the uncropped image size
-		FVector3D minBound = FVector3D(std::numeric_limits<float>::max());
-		FVector3D maxBound = FVector3D(-std::numeric_limits<float>::max());
-		for (int p = 0; p < model_getNumberOfPoints(visibleModel); p++) {
-			FVector3D point = model_getPoint(visibleModel, p);
-			if (point.x < minBound.x) { minBound.x = point.x; }
-			if (point.y < minBound.y) { minBound.y = point.y; }
-			if (point.z < minBound.z) { minBound.z = point.z; }
-			if (point.x > maxBound.x) { maxBound.x = point.x; }
-			if (point.y > maxBound.y) { maxBound.y = point.y; }
-			if (point.z > maxBound.z) { maxBound.z = point.z; }
-		}
+		FVector3D minBound, maxBound;
+		model_getBoundingBox(visibleModel, minBound, maxBound);
 		// Check if generating a bound failed
 		if (minBound.x > maxBound.x) {
 			printText("  There's nothing visible in the model, because the 3D bounding box had no points to be created from!\n");