BSP Splitting Algorithm supplement-after the document on splitting a triangle is completed, a complicated scenario is created. After segmentation, problems with the original algorithm are discovered. According to this supplement, the original document will be deleted and modified again, causing inconvenience to readers. I hope you will forgive me. In the segmentation algorithm mentioned in the previous article, the processing of the split surface is based on a policy that directly places the plus and minus sides of the split surface. At that time, I thought this would only have an impact on AABB's computation, so I wrote it down. Although this algorithm is simple, it will face many difficulties in subsequent portal processing, which I did not consider at first. After the scenario becomes complex, this problem becomes more and more apparent: some leaves will only contain several split shared triangles, and these triangles cannot constitute a closed space at all. However, these leaves are sent to portal computing, and the final portal is very strange, even including several portals on the same surface. Using more ideas to change the portal algorithm is not as reasonable as simply dividing the space, that is, adopting the standard practice: Split the split triangle into multiple triangles, put them into the corresponding space. In fact, this algorithm is very simple. If a triangle is divided by a plane, there are two situations: one is to generate a triangle in the positive and negative sides; there is a triangle on one side and two triangles on the other side. Intuitively, in either case, the key algorithm flow is to access the edge of the original triangle sequentially. The first vertex of the edge is v0, and the second vertex is V1. If the two vertices of this edge are on the plane side, the two vertices are included in the new Polygon on the corresponding side of the plane. If there is a point on the plane, if the point is the first vertex of the edge, it should be placed in the new Polygon on both sides of the plane. If it is the second vertex, You need to determine which side of the plane the first vertex is on, and put it in the corresponding space (only once ). For more information, see (left. If this side is cut by a plane, calculate the vertex VIP after the cutting. Note that the vertices must be separated according to the vertex format. The normal and texture coordinates must be separated. In this case, it is also to determine which side of the plane the first vertex is on. Based on this, V0, VIP, and V1 are combined in the corresponding order and placed in the Polygon on both sides (in this process, VIP will be placed on both sides ). This algorithm has several points to note: first, in order to generate a triangle with the same vertex sequence as the original triangle (that is, after the clockwise triangle is generated, it is still clockwise, and after the clockwise triangle is generated, it is still counterclockwise ), we must traverse the sides of the original triangle in the corresponding order: v0-v1, V1-V2, v2-v0, only the side of the original triangle can be accessed in order to ensure the order of the generated triangle. If the order at the beginning is very strange, the order of the triangle generated at the end is difficult to guarantee, and the code is not intuitive. Second, the two sides are divided by a polygon rather than a triangle. This requires separate judgment. If the number of vertices in the polygon is 3, it indicates that a triangle is generated on this side, so it is easy to do it, use this triangle directly. If it is 4, it indicates a quadrilateral. If the order of the Quadrilateral vertices is V0 V1 V2 V3, the two triangles that make up the Quadrilateral should be the v0-v1-v2 and the v0-v2-v3, respectively. The specific derivation process will not be mentioned. If you find it difficult to understand, you can refer to the figure below to understand it easily. OV refers to the three vertices of the original triangle, and V refers to the four vertices of the Quadrilateral after segmentation. Pay attention to the order. Third, pay attention to the division of the normal. If the normal direction of the two vertices is the opposite (of course, this is a special case), the normal of the last generated new vertex will be 0! In this case, the normal needs to be processed separately. My processing is to assign the entire normal to this vertex. Of course, you may also have a better way. Fourth, new vertices and faces are generated in the segmentation. Therefore, the number of vertices and faces in the BSP often exceeds the number of vertices and faces in the original data of the model. But now there is no triangle shared by two leaves. Therefore, you can create an IB uniform triangle in one leaf and render it at a time, which is faster than using a shared surface. The splitting algorithm is not unique. Just as the BSP splitting method is not unique, the key is to select the algorithm that is the easiest to master and most advantageous to you.