BSP (binary space partitioning) tree is another type of space segmentation, and its industrial application has been in the game for many years (Doom was the first commercial game using the BSP tree). Despite the BSP tree is not today as in the past so popular, but now the technology is still widely used.
BSP when you look at it in terms of collision detection is extremely clean and nice and high efficiency, and immediately make you themselves. not only the BSP tree, polygon Cut outstanding performance, but also allows us to effectively use free-style world-object collision detection. BSP BSP tree traversal is to use a basic technique. The collision detection is essentially to reduce the tree traversal or search. This approach is useful because it excluded a large number of polygons in the early, so in the end we were only a small number of side collision detection. As I said before, with the separation between two objects identified surface method is suitable for two objects to determine whether the intersection. If there is separation surface, there is no collision. Therefore, we recursively traverse the world face the tree and determine whether partitioning or bounding box and bounding sphere intersection. We can also test each polygon of an object to improve accuracy. for this One of the simplest kinds of testing is to test to see whether all parts of the object surface in the side split. This operation is really simple, we use the Cartesian plane equation ax + by + cz + d = 0 to determine point at which side of the plane. if the equation, the point in the plane; if ax + by + cz + d> 0 then the points in the plane of the front; if ax + by + cz + d <0 above the plane the back.
did not happen in the time of the collision there is an important thing to note is that an object (or its bounding box) must face the front or back split. If both the front and back surface vertex, that intersects the object and the plane. (upload selected from Baidu Encyclopedia)
Bsp segmentation brief
Preview
BSP also has many articles segmentation algorithm can learn to grasp the information I present point of view, generalities and gone, but the actual time to always be thrown off balance for. know how to do what is always better to know, BSP BSP segmentation is the basis of analysis, although it is very simple, but, if even the simplest of all will not do, how complex the job as competent?
free to take advantage of this time, then study hard at BSP, a week later, segmentation and automatic generation Portal have been resolved, then do this article, hoping for beginners help, also hope to initiate, several experts to the wing.
paper first to BSP in the division of some relatively simple introduction to a simple, automatically generated data being compiled Portal, hoping to release.
BSP
Consider the basic principle of our living space, certainly by the large number of ceiling, wall and floor components, for each After the board all the boards in front of the object after object occlusion).
BSP were, the principle is simple: it tries to all the board (called in the BSP in the plane) organized into a tree, each plane were to split it in the space before and after the two parts, the two parts of the plane they were also divided into smaller spaces hh until finally, in accordance with the previously mentioned algorithm to determine each room (called a leaf in the BSP) relative to the eyes of the block order. This is a very standard
dichotomy, only in accordance with the indoor scene is the best choice. Why? will show you:
in determining when the block order, BSP algorithm space is extremely simple: just start from the roots, the simple position to judge people before and after the relationship with all the plane : the former is being sub-tree (in the plane . this recursively to the leaves (the leaves are always a room), you can determine which people in a room among other rooms of the relationship between occlusion.
This is actually very simple: because all the planes in which all of its space divided into two parts, so each room are made from a number of planes of the Among the needed room. This is so special about BSP algorithm.
Figure: Space ABC by the A, B, C composed of three separate rooms, first of all, split the space into a flat plane 1 Forward A-room and space plane negative BC, BC space is divided into plane 2 2 followed by positive and negative C room B room. Note that the direction of the plane for the general direction of the wall may be.
If there is one person in the room C, then blocked all the rooms how to determine the order of it? start from the roots, because people in the plane 1 of the negative and then positive), and then, because people in the division plane 2 of the order to be identified: CBA. only need two planes before and after the judge (a total of six multiplications, two additions, twice the size of judgments), we can determine the order of space, the algorithm can be seen the power!
BSP aims to partition the space into a leaf of a convex body, which is a convex body. one convex body may be ordered only hard to imagine a non-convex body in space, how to order. Figure Left: from an arrow the direction of look at the past, in the end concave polyhedron A is in front of B? A or B in front of the concave polyhedron? and if it is right, the two convex polyhedron, is not the case, A and B before and after the direction, according to the viewpoint position is always unique. This is the BSP's advantage, only need to know the location of point of view, the space of all convex bodies can immediately determine the location of the order, but if it is concave body, I'm sorry, it sure can not, therefore, BSP by spatial structure of the surface must be a result of a convex body.
would like to stress that the only thing there is that if you analyzed the Quake3 BSP format, sometimes you will find a room over the past few columns will be split a mess, just to a small number of surface rendering. now do not have such a large scaled, a room to stay out of the six structural surfaces, pillars of what counts as only the details of Mesh, not involved in segmentation, the result of this, and the Portal Filter binding, the efficiency may not be sent. Moreover, the structure more logical, automated way point in the future and the path computation time, there will be some advantage. Think about it, is a very regular column (or boxes and other objects) into mess room, a room had lots of leaves, in the end which leaves a person can go to? which leaves a person come to the stage of? which leaves need to be considered in the AI? which leaves can be excluded? a non-logical constitutes the space, the handling of the inevitable logic to being blocked. Therefore, the best is a room or a leaf, or a corridor; columns, ah, what's all the box with the details of the Mesh, on it.
note, BSP in fact carved out of the convex body is mainly carried out to the back of the BSP, but not rendering. earlier, when the hardware is bad, no Z buffer, then province of a triangle is much more important than it is now. Now? sometimes prefer to draw a more heap that the triangle does not waste CPU resources to individual selection triangle. Therefore, to minimize the structural side, the structure of a room with a composition of convex bodies, but details of the surface to decorate the room into what, it does not matter, even if details of the surface of this space is transformed into a concave body, but also does not matter, as shown:
Because it is an old method, so the segmentation algorithm already BSP is not something mysterious, there are many examples of this algorithm, recommended Detailed BSP technology The code is complete, although the look down also difficult to understand than the pseudo-code, but each function is basically still clear, is a rare alternative information.
, of course, most people may still prefer to see Quake and the HL2 code. To make their deeper impression, I have chosen their own from scratch, according to data on the only views and processes DIY, without reference to the code. I often refer to the reference was to into the working state, the first problem is the configuration of scene data. BSP is not difficult to a certain extent, brought about the algorithm itself, BSP algorithm is simple and clear and not too many complicated things in there. Generally, the complex is good BSP and editors need to combine for Portal, Brush, Entity and Path Point sort of customization, directly from 3D Max and then export a Mesh analysis, the restrictions from the practice too much, so, instead of BSP split that is difficult, it is more difficult BSP editor. I remember an old book once said, BSP BSP editor's code is more than 10 times the segmentation algorithm, think, true, and only will be greater than that.
In practice, I used the surface is a good idea, structure of the surface, to participate in the BSP segmentation and analysis, is that this Sphere01 DSphere01 split in BSP and analysis will be ignored. This is the middle of the main work focused on 3DMAX Script writing (or plug-in writing), so do not say more on this technology is still relatively unfamiliar, refer to relevant content online.
3DMAX read out from the Object, its index of all vertices and faces are known, and will be organized into a vertex all vertices tables, all organized into a structured triangular structure of triangular form (in this triangle is the vertex index), this relatively simple and should not be a problem.
data into our program, the first thing is to first calculate the All of the plane, because the different structure of the surface may share a plane, so the first need to figure out where all the planes and surfaces in the plane and structured to build relationships in order to prevent a plane is more than twice with the use of BSP half logical correctness. D3DX given a special function D3DXPlaneFromPoints, can be easily generated from a triangle to a plane. A new operator came out flat, check whether the plane had been generated, and if not, even for a new plane and record the ID, or we need to discard the new plane, the plane turned to the original ID. until finally, for all of the structured surface corresponding to the triangle given its ID. This is the middle note of the plane equation D3DX is ax + by + cz + d = 0, using a + d, not-d, after the calculation of the need to pay attention.
ready to peak form, the structure of the triangular table and graphic form, the segmentation can formally began. relative to the terms of 3DMax Script and plug-ins, BSP segmentation algorithm itself easy to get people to crash, not much to say, let's start!
BSP split
First of all, naturally produce a first root, and all the vertices form, structure, table and graphic form of the triangle will fall slightly into the root node.
Then, the process probably split as follows:
1 traverse all options of the current node plane, looking for a suitable split plane.
2 If you can not split the right plane, the node is a leaf, Return.
3 If found, Mark the plane has been used.
4 New two new nodes A node is positive, a negative to the node, attached to the node.
5 through all of the structured surface.
6 split if the structure of the surface in the plane:
forward to: This structure of the surface and structured surface corresponding to the positive node into the plane.
negative, add to the negative node.
be split if the structure of the surface plane division, the division of this triangle, and the result will be split into the appropriate child node.
(Note that this step when the structure of the plane that the plane corresponding to the time Mark has been to just put a structured surface, and hold separate plane, and to prevent the same plane used to separate two or more, violation of BSP only logical space of two minutes)
7 through all of the details of the surface. details of the surface structure of the surface treatment and a similar, but here do not take into account the details of the face should be the plane problem, more simple.
8 traverse is completed, since all of the structural triangle, plane, and details of the surface has been transferred to two child nodes, so the solution out from all the nodes in the structure of the triangle, and the details of the surface plane references. nodes required to retain data only if the split plane, and two pointers to subordinate nodes.
9 of the two child nodes, respectively, starting from a recursive implementation.
so, and all end is a complete BSP tree, and all the nodes in a node split to retain only the plane and the two lower nodes, and rendering the structure of the triangular serious and relevant details are all in a leaf surface. Finally, only along the root recursion, all the nodes can be organized into the node table. I here are organized into nodes in the node table, organized into leaf table leaves. You can also add a node through the property to them Is Leaf uniform into a node table.
now facing the most important problem is the structure of the surface at all, how to find a split plane?
First, the division plane must be for the purposes of concave polyhedron has the formation of a convex polyhedron of space unnecessarily fragmented. For a concave body, the division plane to be positive or negative direction in the plane there are triangles. so go on recursive partitioning, we can guarantee a lot of space eventually split into a collection of convex polyhedron. below left, 1,4 a party does not appear in the plane of the triangle, should be discarded, 2,3 can be split as an alternative plane:
division plane selection is a more lazy little chance for each of the judge only. For each plane, calculate the value of one for the judge, the largest of all values (or minimum, depending on the algorithm may be) that the plane is the best split plane. the most simple, always select only the first structured triangle plane division, but this space will be split down the sight. segmentation is to get the best results out of a tree that balanced approach. because of the operation than non-balanced binary tree balanced binary tree to be fast, much smaller redundancy.
calculate the optimal balanced binary tree is almost impossible, but similar levels to ensure a balanced binary tree algorithm as much, N + 8 t S
the minimum value that this is the best plane. In other words, the number of positive and negative to the closest triangle and triangle cut at least that is the best split plane surface.
above At right, 7,3,5 can be used as separate plane, however, is clear: 3 to 7 and 5, much better than that, because the number of positive and negative direction of the triangle closest to, and did not cut any triangle.
this algorithm in actual use, not necessarily generate the best tree, but it is simple and intuitive. not the best algorithm, only the most suitable method, algorithm selection is not the only, basically, should be based on the characteristics of space, So here is not to repeat them here. In short, to try to separate out the balanced binary tree method is a good way.
BSP split after, arising out of the node table and leaves the table, which constitutes a BSP node table tree trunk, leaves the table there and all the details of the structure of the triangular Mesh, after the analysis will be used as the basic data source. and in all the analysis, the first should be the analysis is the Portal, Portal After analysis, PVS such analysis possible. The Portal and PVS, BSP space partition is the most attractive of the two parts of the business in the latest engines, can still see their shadows, and, compared to the early 90s, there will only be no less than the supplementary and correction
hh
split a triangle
on the document on the articles written, made a more complex scene, and found the original algorithm to segment some of the problems, do a a supplement. According to this supplement, the original document will be deleted and then re-modifying hair, the inconvenience of you readers, I hope you can forgive me.
mentioned in the article in the segmentation algorithm is divided in the face on The deal, to take the direct positive and negative side will be split strategies are put. at that time that would only affect the calculation of AABB, and therefore would write so openly go up. The algorithm is simple, but after the deal Portal will face many difficulties, this is what I did not start to take into account.
complicated in the scene later, the problem is more and more apparent: in some leaves, it will only include the sharing of certain triangle is split, and These could not constitute a closed space triangle. However, these leaves been calculated into the Portal, the last out of the Portal is very strange, even in the same side of the number of Portal.
Portal with more ideas to change algorithm better to split from the fundamental space will be more reasonable, that is to take the standard approach: separating the triangle will be split, divided into several triangles, respectively, into the appropriate space.
fact, this algorithm is very simple, a If the triangle is a plane partition, intuitive point of view, and only two situations: one is to generate a positive and negative of each triangle; the other is a triangle on one side, the other side of two triangles. intuitively that In either case, the key algorithm process are:
side of the triangle in order to access the original, set the first vertex is the edge of v0, the second vertex is v1.
two vertices if the edge were flat side, then the two corresponding vertex operator into the flat side of the new polygon.
If there is a point in the plane, then this point if it is the first vertex of this edge should be the new polygon in the plane both sides To put. If the second vertex, you need to first determine which side of the vertex in the plane, and the into the appropriate space (only put in once.) refer to the following figure (left) to be understood.
If the cutting edge is flat, then: after cutting the first calculated peak vip, vertex format, need to pay attention to this division, normals, texture coordinates should be divided. At this time, the same first vertex is to determine which side of the plane, According to this, the v0, vip, v1 order by the appropriate combination of, respectively, into both sides of the polygon (in this process, vip will be placed on both sides).
this algorithm there are several areas need attention: < br> First, to generate triangle vertices consistent with the original order of the triangle (that is, after generating the triangle is clockwise clockwise, counterclockwise triangle is counter-clockwise after generation), we have to traverse the original order in accordance with the corresponding side of the triangle: v0-v1, v1-v2, v2-v0, only sequential access to the original edge of the triangle after triangle guarantee that the generated sequence. If the order is very strange start, then the triangle out of the order of the last generation will be difficult to ensure code also very intuitive.
second, segmented on both sides of the polygon and not a triangle, which requires separate judgments, if the number of polygon vertices is 3, that is generated on this side of a triangle, then be easy to handle , the direct use of the triangle can be. If it is 4, that is a quadrilateral. If you set the order of quadrilateral vertices v0 v1 v2 v3, then, form the quadrilateral, respectively, the two triangles should be v0-v1-v2 and v0-v2- v3. specific derivation did not say, if you feel difficult to understand, you can refer to the following chart, it is easy to understand. which, OV is the original triangle's three vertices, V is split after the four vertices of the quadrilateral Please note that order.
Third, note the normal cut points, if the two vertices opposite the normal direction (of course, this is a special case), then the resulting new vertex normals will be 0! In this case, the normal need for a separate deal for what my deal is to assign the entire surface of the vertex normals, of course, you may be a better way.
Fourth, in the segmentation will generate new vertices and faces, the final BSP number of vertices and faces are often more than the original data in the model where the number of vertices and faces. But now the absence of a common shared by two triangular leaves, so, one leaves build a triangle can be unified IB, once rendered, and the speed of course will be faster than the use of shared surfaces.
segmentation algorithm is not unique, as the BSP is not the only division the way, the key or choose The most easy to grasp their own, the most favorable method.
switched:
No comments:
Post a Comment