The experience of simulating the fabric operations.

xiaoxiao2021-03-06  42

First of all, this is an article involved in mathematics and physical knowledge. If you do not understand the formula involved in the text, please put a "higher mathematics" and some physics common sense.

First of all, the first question is: Why do you want to simulate the exercise of the cloth? There are many places in the game, so what is most of the current practices? At present, the method used by most games is to establish a bone in the cloth, and then made different fabric skeletal animations for each action. This approach is that the fabric does not change with the changes of the surrounding environment. For example, there is a wind around, or on the horse, the cloak can not be shared on horseback, and so on. And if there are many actions in the game, there is a need to do different fabric bones, increase the workload of the art and the work complex, and if the number of bones of the cloak, it will also cause Even the action that is toned will also produce a very beautiful effect.

OK, Luo Zuoyi is a lot, then what do we want to achieve? We have to achieve a physical system for the fabric, requiring that the fabric will be affected by gravity without wind, slowly falling, and when there is a wind, your cloth can be "floating ".

Let's take a look at the model of the fabric in traditional physics. Based on fluid mechanics, the force of each vertex on the fabric can be used to seek the San Division, but in the middle of the math, the Shengwei South Corporation is not intensive, then we need to design a model. To seek the approximate solution of this equation. Countless physical masters, in the process of simulated cloth, summed up two classic models, a set of "quality point-spring" model, and another set of "semi-steel-complex pendulums" research by Microsoft Chinese Institute "Model, in my fabric engine is" quality point-spring "model, the reason is that the time exists than" semi-steel-complex pendulum "model for a long time, almost in terms of stability, and efficiency There is no risk. And if "semi-steel-complicated pendulum", this is just a experiment, and there is no application in this model, and this model has certain risks.

Then let's take a look at how the classic "quality point-spring" model is what is going on: in the "Quality Point-Spring" model, any fluid (soft body) is decomposed by n quality, each A spring between a variety of different ways is connected between the sequestration. There are three main connections, one is a rectangular connection method, that is, each mass point and his "up and down left and right" four points are connected. The other is a cross-connect method, that is, each mass point and his "left, upper right, left, right" four points "are connected. The last method is called the separation point connection method, both of the mass point and his "left left, the right side of the right, the upper and the following" above "four points are connected with the spring body, which is mainly used. To simplify the calculation of the curved stress of the spring, it is generally used in combination with the first two connections. In Demo, in my fabric operation, I used the first middle rectangular connection method, and then accurately calculates the curved stress of the spring.

After the physical model is selected, we need to program to model the vertex of the transfer. The general method is to transfer the vertices of the fabric, according to the left to right, from top to bottom, then follow the width of the fabric. To conduct a physical modeling. When the model is established, we need each frame to physical operations for each quality point in the model: So what is the force of each quality point? It is divided into two steps to calculate, first is internal force, then external force: Each mass point is subject to the tension of the spring that is brought by the model formed by the spring, and the bending stress of the spring itself. Then first, the tension of the spring is first obtained, first obtain the position P0 in the space in the space, then obtain the position P1-P5 of each of the respective mass points connected to the spring, then circulate the distance from P1-P5 and P0, and use this distance The length of the spring itself is subtracted, then multiplied by a spring tiger coefficient, that is, this point is in this frame. In addition, the bending stress of the spring is to be used in the rectangular model, by calculating the angle of "upper mass point" and "lower quality points" and "left mass" and "right sides" angle. The coefficients are obtained by a force in the tangential direction of the neighboring point of the neighborhood point of the radius of the current mass.

Here, the internal force of the fabric has been calculated, then it needs to calculate the external force of the fabric. First of all, gravity, gravity is based on the density (quality) of the mass point by a gravity acceleration, and then a global resistance, otherwise the spring will not play, not finish, pay attention, here, the multiplier Since the speed vector of the previous frame, not the current force vector. The next is the wind, I can understand the wind's processing, which is a force applied to the normal point of the normal point, and the force size is related to the angle of the wind vector and the direction of the position. When the angle is 2 * pi, the wind is to reach maximum.

At this point, the internal force and external force of the quality point are calculated, then if this is the position of the next frame of the next frame? First, according to the quality and synergistic size of the mass point, this step only needs to multiply the calculated force by the quality of the 1 / mass point, after the acceleration, it can calculate this according to VT = V0 AT. The speed vector of the frame, then plus the position of the current mass in the space, the position of the mass point of the next frame.

At this point, the simulation of the cloth has been completely fixed, don't doubt, it is so simple, but what is currently realized is still applicable, why? Very simple, because there is no collision that has not been made, if a cloak passes through the people, what does it mean to do not do?

Accurate collision detection against cloth? This is impossible, if you want to do this, you will have only 20 frames that are not only 20 frames, with a AABB enclose box collision? You want to see a wind blow, your cloak is sticker in a "person" "people"? Then, a new concept "ellipsoid envelop" collision is proposed. Note that the ellipsoid here is not existed, just a mathematical model, is not composed of triangle, such an ellipsoid can be bound to the human bones, moving with the movement of the human bones, such as a human head It is an ellipsoid, hip bone, basin, and scapula, etc., an XYZ axis, can be embodied in an ellipsoid.

The ellipsoid is a very interesting thing. When doing the FPS game, you have to achieve the effect of the upper and lower stairs. It is a very good way to collide with an ellipsoid, but here, not the ellipsoid with the triangle, but The vertex touched the ellipsoid. Then look at how it is better to describe, and use a ellipsoid: ellipsoid with three vectors to describe, one is the midpoint of ellipsoid in space, and another vector is stored ellipsoid The length of the radius of the X, Y, the Z axis, and the other vector is the direction specified by the ellipsoid, and I am in the direction of the ellipsoid X-axis in DEMO. The equation of the ellipsoid is: (x ^ 2 / a ^ 2 y ^ 2 / b ^ 2 z ^ 2 / c ^ 2) = 1 So corresponding collision detection is to put a vertex x, y, z The value is brought into equation, and the results are greater than 1 or less than 1, and the collision occurs if less than 1. So what do you do after a collision? First, you need to move this vertex to the nearest point of the ellipsoid surface, this step is to solve it from the middle of the ellipsoid, and you can get that point, you can get that point, the specific derivation is not Listed, the equation is as follows: set: X0, Y0, Z0 is the ellipsoid, X1, Y1, Z1 is in the ellipsoid: then the nearest ellipsoid surface is: t = SQRT 1 / (SQR ((x1-x0) / a) SQR ((Y1-Y0) / B) SQR ((Z1-Z0) / C))))); x = x0 t * (x1-x0); Y = Y0 T * (Y1-Y0); z = z0 t * (z1-z0); It is, it should give it a support force in the normal direction of this point on the ellipsoid. The calculation of the normal of the ellipsoid is subjected to: D3DXVector3 (SQR (x - x0) / a), SQR ((Y - Y0) / B), SQR ((Z - Z0) / C)); then By multiplying the weight of the force in the negative method in the negative method of the current point by one point, then subtract this component with the current force to subtilize the coefficient of frictional coefficients of this ellipsoid.

At this point, the model of the entire fabric calculation ellipsoid collision is completed.

转载请注明原文地址:https://www.9cbs.com/read-59147.html

New Post(0)