void BSPTree::BuildDrawOrder(const UniquePtr<BSPTreeNode>& aNode, nsTArray<LayerPolygon>& aLayers) const { const gfx::Point3D& normal = aNode->First().GetNormal(); UniquePtr<BSPTreeNode> *front = &aNode->front; UniquePtr<BSPTreeNode> *back = &aNode->back; // Since the goal is to return the draw order from back to front, we reverse // the traversal order if the current polygon is facing towards the camera. const bool reverseOrder = normal.z > 0.0f; if (reverseOrder) { std::swap(front, back); } if (*front) { BuildDrawOrder(*front, aLayers); } for (LayerPolygon& layer : aNode->layers) { MOZ_ASSERT(layer.geometry); if (layer.geometry->GetPoints().Length() >= 3) { aLayers.AppendElement(Move(layer)); } } if (*back) { BuildDrawOrder(*back, aLayers); } }
void BSPTree::BuildDrawOrder(const UniquePtr<BSPTreeNode>& aNode, nsTArray<gfx::Polygon3D>& aPolygons) const { const gfx::Point3D& normal = aNode->First().GetNormal(); UniquePtr<BSPTreeNode> *front = &aNode->front; UniquePtr<BSPTreeNode> *back = &aNode->back; // Since the goal is to return the draw order from back to front, we reverse // the traversal order if the current polygon is facing towards the camera. const bool reverseOrder = normal.z > 0.0f; if (reverseOrder) { std::swap(front, back); } if (*front) { BuildDrawOrder(*front, aPolygons); } for (gfx::Polygon3D& polygon : aNode->polygons) { aPolygons.AppendElement(std::move(polygon)); } if (*back) { BuildDrawOrder(*back, aPolygons); } }
void BSPTree::BuildTree(UniquePtr<BSPTreeNode>& aRoot, std::deque<LayerPolygon>& aLayers) { if (aLayers.empty()) { return; } const gfx::Polygon& plane = aRoot->First(); std::deque<LayerPolygon> backLayers, frontLayers; for (LayerPolygon& layerPolygon : aLayers) { const Maybe<gfx::Polygon>& geometry = layerPolygon.geometry; size_t pos = 0, neg = 0; nsTArray<float> dots = geometry->CalculateDotProducts(plane, pos, neg); // Back polygon if (pos == 0 && neg > 0) { backLayers.push_back(Move(layerPolygon)); } // Front polygon else if (pos > 0 && neg == 0) { frontLayers.push_back(Move(layerPolygon)); } // Coplanar polygon else if (pos == 0 && neg == 0) { aRoot->layers.push_back(Move(layerPolygon)); } // Polygon intersects with the splitting plane. else if (pos > 0 && neg > 0) { nsTArray<gfx::Point4D> backPoints, frontPoints; geometry->SplitPolygon(plane.GetNormal(), dots, backPoints, frontPoints); const gfx::Point4D& normal = geometry->GetNormal(); Layer *layer = layerPolygon.layer; if (backPoints.Length() >= 3) { backLayers.push_back(LayerPolygon(layer, Move(backPoints), normal)); } if (frontPoints.Length() >= 3) { frontLayers.push_back(LayerPolygon(layer, Move(frontPoints), normal)); } } } if (!backLayers.empty()) { aRoot->back.reset(new BSPTreeNode(PopFront(backLayers))); BuildTree(aRoot->back, backLayers); } if (!frontLayers.empty()) { aRoot->front.reset(new BSPTreeNode(PopFront(frontLayers))); BuildTree(aRoot->front, frontLayers); } }
void BSPTree::BuildTree(UniquePtr<BSPTreeNode>& aRoot, std::deque<gfx::Polygon3D>& aPolygons) { if (aPolygons.empty()) { return; } const gfx::Polygon3D& splittingPlane = aRoot->First(); std::deque<gfx::Polygon3D> backPolygons, frontPolygons; for (gfx::Polygon3D& polygon : aPolygons) { size_t pos = 0, neg = 0; nsTArray<float> dots = CalculateDotProduct(splittingPlane, polygon, pos, neg); // Back polygon if (pos == 0 && neg > 0) { backPolygons.push_back(std::move(polygon)); } // Front polygon else if (pos > 0 && neg == 0) { frontPolygons.push_back(std::move(polygon)); } // Coplanar polygon else if (pos == 0 && neg == 0) { aRoot->polygons.push_back(std::move(polygon)); } // Polygon intersects with the splitting plane. else if (pos > 0 && neg > 0) { nsTArray<gfx::Point3D> backPoints, frontPoints; SplitPolygon(splittingPlane, polygon, dots, backPoints, frontPoints); backPolygons.push_back(gfx::Polygon3D(std::move(backPoints))); frontPolygons.push_back(gfx::Polygon3D(std::move(frontPoints))); } } if (!backPolygons.empty()) { aRoot->back.reset(new BSPTreeNode(PopFront(backPolygons))); BuildTree(aRoot->back, backPolygons); } if (!frontPolygons.empty()) { aRoot->front.reset(new BSPTreeNode(PopFront(frontPolygons))); BuildTree(aRoot->front, frontPolygons); } }