Showing the changes to libraries/render-utils/src/Model.cpp (1 of 2 files). Show all
Unified · Split
| @@ -81,6 +81,7 @@ Model::Model(QObject* parent) : · 80 unmodified lines | ||
| 81 | 81 | _url("http://invalid.com"), |
| 82 | 82 | _blendNumber(0), |
| 83 | 83 | _appliedBlendNumber(0), |
| 84 | + _calculatedMeshPartBoxesValid(false), | |
| 84 | 85 | _calculatedMeshBoxesValid(false), |
| 85 | 86 | _calculatedMeshTrianglesValid(false), |
| 86 | 87 | _meshGroupsKnown(false), |
| @@ -666,12 +667,13 @@ bool Model::convexHullContains(glm::vec3 point) { · 579 unmodified lines | ||
| 666 | 667 | void Model::recalculateMeshBoxes(bool pickAgainstTriangles) { |
| 667 | 668 | bool calculatedMeshTrianglesNeeded = pickAgainstTriangles && !_calculatedMeshTrianglesValid; |
| 668 | 669 | |
| 669 | − if (!_calculatedMeshBoxesValid || calculatedMeshTrianglesNeeded) { | |
| 670 | + if (!_calculatedMeshBoxesValid || calculatedMeshTrianglesNeeded || (!_calculatedMeshPartBoxesValid && pickAgainstTriangles) ) { | |
| 670 | 671 | const FBXGeometry& geometry = _geometry->getFBXGeometry(); |
| 671 | 672 | int numberOfMeshes = geometry.meshes.size(); |
| 672 | 673 | _calculatedMeshBoxes.resize(numberOfMeshes); |
| 673 | 674 | _calculatedMeshTriangles.clear(); |
| 674 | 675 | _calculatedMeshTriangles.resize(numberOfMeshes); |
| 676 | + _calculatedMeshPartBoxes.clear(); | |
| 675 | 677 | for (int i = 0; i < numberOfMeshes; i++) { |
| 676 | 678 | const FBXMesh& mesh = geometry.meshes.at(i); |
| 677 | 679 | Extents scaledMeshExtents = calculateScaledOffsetExtents(mesh.meshExtents); |
| @@ -682,6 +684,9 @@ void Model::recalculateMeshBoxes(bool pickAgainstTriangles) { · 4 unmodified lines | ||
| 682 | 684 | QVector<Triangle> thisMeshTriangles; |
| 683 | 685 | for (int j = 0; j < mesh.parts.size(); j++) { |
| 684 | 686 | const FBXMeshPart& part = mesh.parts.at(j); |
| 687 | + | |
| 688 | + bool atLeastOnePointInBounds = false; | |
| 689 | + AABox thisPartBounds; | |
| 685 | 690 | |
| 686 | 691 | const int INDICES_PER_TRIANGLE = 3; |
| 687 | 692 | const int INDICES_PER_QUAD = 4; |
| @@ -710,6 +715,15 @@ void Model::recalculateMeshBoxes(bool pickAgainstTriangles) { · 22 unmodified lines | ||
| 710 | 715 | |
| 711 | 716 | thisMeshTriangles.push_back(tri1); |
| 712 | 717 | thisMeshTriangles.push_back(tri2); |
| 718 | + | |
| 719 | + if (!atLeastOnePointInBounds) { | |
| 720 | + thisPartBounds.setBox(v0, 0.0f); | |
| 721 | + atLeastOnePointInBounds = true; | |
| 722 | + } | |
| 723 | + thisPartBounds += v0; | |
| 724 | + thisPartBounds += v1; | |
| 725 | + thisPartBounds += v2; | |
| 726 | + thisPartBounds += v3; | |
| 713 | 727 | } |
| 714 | 728 | } |
| 715 | 729 | |
| @@ -728,10 +742,20 @@ void Model::recalculateMeshBoxes(bool pickAgainstTriangles) { · 12 unmodified lines | ||
| 728 | 742 | Triangle tri = { v0, v1, v2 }; |
| 729 | 743 | |
| 730 | 744 | thisMeshTriangles.push_back(tri); |
| 745 | + | |
| 746 | + if (!atLeastOnePointInBounds) { | |
| 747 | + thisPartBounds.setBox(v0, 0.0f); | |
| 748 | + atLeastOnePointInBounds = true; | |
| 749 | + } | |
| 750 | + thisPartBounds += v0; | |
| 751 | + thisPartBounds += v1; | |
| 752 | + thisPartBounds += v2; | |
| 731 | 753 | } |
| 732 | 754 | } |
| 755 | + _calculatedMeshPartBoxes[QPair<int,int>(i, j)] = thisPartBounds; | |
| 733 | 756 | } |
| 734 | 757 | _calculatedMeshTriangles[i] = thisMeshTriangles; |
| 758 | + _calculatedMeshPartBoxesValid = true; | |
| 735 | 759 | } |
| 736 | 760 | } |
| 737 | 761 | _calculatedMeshBoxesValid = true; |
| @@ -2176,7 +2200,13 @@ bool Model::renderInScene(float alpha, RenderArgs* args) { · 1438 unmodified lines | ||
| 2176 | 2200 | } |
| 2177 | 2201 | |
| 2178 | 2202 | AABox Model::getPartBounds(int meshIndex, int partIndex) { |
| 2179 | − if (_calculatedMeshBoxesValid) { | |
| 2203 | + if (!_calculatedMeshPartBoxesValid) { | |
| 2204 | + recalculateMeshBoxes(true); | |
| 2205 | + } | |
| 2206 | + if (_calculatedMeshPartBoxesValid && _calculatedMeshPartBoxes.contains(QPair<int,int>(meshIndex, partIndex))) { | |
| 2207 | + return _calculatedMeshPartBoxes[QPair<int,int>(meshIndex, partIndex)]; | |
| 2208 | + } | |
| 2209 | + if (!_calculatedMeshBoxesValid) { | |
| 2180 | 2210 | return _calculatedMeshBoxes[meshIndex]; |
| 2181 | 2211 | } |
| 2182 | 2212 | return AABox(); |