Method, device, electronic device and storage medium for displaying fluid collision effect
By meshing the three-dimensional virtual space, the particle velocity is updated using the velocity change of the grid, and the positional relationship between the grid and the container wall and rebound velocity are considered, the existing fluid display methods are solved in simulating the fluid collision effect, achieving a more realistic and natural fluid collision effect.
Patent Information
- Application Number
- CN202110183955.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-10
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2041-02-10
AI Technical Summary
The existing fluid display methods have problems of low accuracy and unstable tension when simulating the effect of fluid collisions, especially when particles move to the space wall, the velocity is forced to be set to 0, which cannot truly simulate the fluid behavior.
By meshing the three-dimensional virtual space, the particle velocity is updated using the velocity change of the grid, and the positional relationship between the grid and the container wall and rebound velocity are considered to show a more realistic and natural fluid collision effect.
This method can better handle the impact of acceleration and fluid pressure on fluid movement, reduce numerical dissipation, and demonstrate a more realistic fluid collision effect.
Smart Images

Figure CN114912376B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of computer graphics, and in particular to a method, device, electronic device and storage medium for displaying fluid collision effects. Background Art
[0002] Fluid simulation is a very important technology in computer graphics and animation. Realistic fluids will bring users a more realistic experience. However, fluid simulation is difficult because the correct simulation of fluid behavior, including convection, diffusion, turbulence and surface tension, is very complex.
[0003] There are generally two methods for fluid simulation: grid-based fluid display method and fluid particle-based fluid display method.
[0004] 1) The network-based fluid display method treats the fluid as continuous, discretizes the spatial region into grids, and then uses the finite difference method, i.e. the Euler model, to implement the entire process of grid-based fluid simulation. The disadvantages of the grid-based fluid simulation method are: the simulation process of diffusion, turbulence and surface tension requires high computational intensity, and the entire simulation process cannot realistically simulate some simulation effects such as the bounded simulation space.
[0005] 2) The model used by the particle-based fluid display method is the Lagrangian model, which represents the fluid as a group of discrete fluid particles and simulates the entire process of fluid movement by solving particle dynamics. The currently widely used particle-based fluid display method is the smooth particle fluid dynamics method, which has the inherent defects of low boundary particle calculation accuracy and unstable tension.
[0006] In the current fluid display effect, when particles move to the wall of space, the particle speed is forcibly set to 0. Obviously, this is very different from the real fluid collision effect. The simulated fluid simulation is very poor, and some fluid particles will move to the outside of the three-dimensional virtual space, resulting in loss of display effect. Summary of the invention
[0007] Embodiments of the present invention provide a method, device, electronic device and storage medium for displaying fluid collision effects that overcome the above problems or at least partially solve the above problems.
[0008] In a first aspect, a method for displaying a fluid collision effect is provided, the method comprising:
[0009] Gridding the three-dimensional virtual space showing the three-dimensional fluid to obtain a grid set, and obtaining the three-dimensional coordinates and velocity of each fluid particle in the three-dimensional fluid in the current frame to determine the grid where each fluid particle is located in the current frame;
[0010] For each grid in the grid set, the speed of the grid in the current frame is obtained according to the speed of the fluid particles in the grid and the surrounding grids within a preset range in the current frame;
[0011] The speed of the grid in the current frame is adjusted according to the preset acceleration to obtain the adjusted speed of the grid, and the speed of the grid in the next frame is obtained according to the adjusted speed of the grid, the positional relationship between the grid and the preset container wall in the three-dimensional virtual space, and the preset rebound speed;
[0012] According to the speed of the grid in the next frame and the speed of the fluid particles in the grid in the current frame, the speed of the fluid particles in the next frame is obtained, and according to the speed of the fluid particles in the next frame and the three-dimensional coordinates in the current frame, the three-dimensional coordinates of the fluid particles in the next frame are obtained;
[0013] According to the three-dimensional coordinates of all fluid particles in the three-dimensional fluid in the next frame, the three-dimensional fluid of the next frame is displayed in the three-dimensional virtual space.
[0014] In a second aspect, a fluid collision effect display device is provided, comprising:
[0015] A grid processing module is used to perform grid processing on the three-dimensional virtual space displaying the three-dimensional fluid, obtain a grid set, obtain the three-dimensional coordinates and velocity of each fluid particle in the three-dimensional fluid in the current frame, and determine the grid where each fluid particle is located in the current frame;
[0016] A grid speed module is used to obtain the speed of each grid in the grid set in the current frame according to the speed of the fluid particles in the grid and the surrounding grids within a preset range in the current frame;
[0017] A mesh speed update module, used to adjust the speed of the mesh in the current frame according to a preset acceleration, obtain the adjusted speed of the mesh, and obtain the speed of the mesh in the next frame according to the adjusted speed of the mesh, the positional relationship between the mesh and a preset container wall in the three-dimensional virtual space, and a preset rebound speed;
[0018] A particle coordinate determination module is used to obtain the velocity of the fluid particles in the next frame according to the velocity of the grid in the next frame and the velocity of the fluid particles in the grid in the current frame, and to obtain the three-dimensional coordinates of the fluid particles in the next frame according to the velocity of the fluid particles in the next frame and the three-dimensional coordinates in the current frame;
[0019] The display module is used to display the next frame of three-dimensional fluid in the three-dimensional virtual space according to the three-dimensional coordinates of all fluid particles in the three-dimensional fluid in the next frame.
[0020] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the method provided in the first aspect are implemented.
[0021] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method provided in the first aspect.
[0022] In a fifth aspect, an embodiment of the present invention provides a computer program, which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. When a processor of a computer device reads the computer instructions from the computer-readable storage medium, the processor executes the computer instructions, so that the computer device executes the steps of implementing the method provided in the first aspect.
[0023] The method, device, electronic device and storage medium for displaying fluid collision effects provided by the embodiments of the present invention use a grid to assist in the motion simulation calculation of particles, which can better handle the effects of acceleration and fluid pressure on fluid motion with less additional overhead. In addition, the particle velocity is updated using the velocity change of the grid, rather than directly converting the grid velocity to the particle velocity, which can reduce the numerical dissipation caused by converting the particle velocity to the grid and then back to the particle, and by considering the positional relationship between the grid and the container wall in the three-dimensional virtual space and the rebound velocity, a more realistic and natural fluid collision effect can be displayed. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure, the drawings required for describing the embodiments of the present disclosure are briefly introduced below.
[0025] Figure 1 A schematic flow chart of a method for displaying fluid collision effects provided by an embodiment of the present disclosure;
[0026] Figure 2 A schematic diagram of the spatial position relationship between a grid, a first reference grid, a second reference grid and a container wall provided in an embodiment of the present disclosure;
[0027] Figure 3 A schematic diagram of mapping a grid in a three-dimensional virtual space to a two-dimensional texture image provided by an embodiment of the present disclosure;
[0028] Figure 4 A position relationship diagram of a basic grid and surrounding grids provided in an embodiment of the present disclosure;
[0029] Figure 5 A flow chart for calculating grid divergence provided in an embodiment of the present disclosure;
[0030] Figure 6 A schematic diagram of the positional relationship between a transition grid and an adjacent grid provided in an embodiment of the present disclosure;
[0031] Figure 7 A schematic diagram of the structure of a device for displaying fluid collision effects provided by an embodiment of the present disclosure;
[0032] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0033] Embodiments of the present disclosure are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present disclosure, and cannot be interpreted as limiting the present invention.
[0034] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "an" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present disclosure refers to the presence of features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.
[0035] In order to make the objectives, technical solutions and advantages of the present disclosure more clear, the embodiments of the present disclosure will be further described in detail below with reference to the accompanying drawings.
[0036] The method, device, electronic device and computer-readable storage medium for displaying fluid collision effects provided by the present disclosure are intended to solve the above technical problems in the prior art.
[0037] The technical solution of the present invention and how the technical solution of the present invention solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present invention will be described below in conjunction with the accompanying drawings.
[0038] See also Figure 1, which is a flow chart of a method for displaying a fluid collision effect provided by an embodiment of the present disclosure, as shown in the figure, comprising:
[0039] S101, gridding the three-dimensional virtual space displaying the three-dimensional fluid to obtain a grid set, and obtaining the three-dimensional coordinates and velocity of each fluid particle in the three-dimensional fluid in the current frame to determine the grid where each fluid particle is located in the current frame.
[0040] It should be understood that the three-dimensional fluid is displayed in a preset three-dimensional virtual space. The display method of the three-dimensional fluid collision effect disclosed in the present invention (hereinafter referred to as the display method) first grids the three-dimensional virtual space, that is, divides the three-dimensional virtual space into several cubic structure grids. This operation can lay the foundation for the subsequent conversion of particle velocity into grid velocity.
[0041] The mesh in the present disclosure is a hexahedral mesh, and the two faces perpendicular to the Z axis in the mesh are called the bottom face and the top face, and the Z axis coordinate of any point in the top face is greater than the Z axis coordinate of any point in the bottom face; the two faces perpendicular to the X axis are called the left side face and the right side face, and the X axis coordinate of any point in the right side face is greater than the X axis coordinate of any point in the left side face; the two faces perpendicular to the Y axis are called the front side face and the rear side face, and the Y axis coordinate of any point in the rear side face is greater than the Y axis coordinate of any point in the front side face. The hexahedral mesh has 12 edges and 8 vertices, and accordingly, each edge contacts 4 hexahedral meshes, and each vertex contacts 8 hexahedrons.
[0042] Furthermore, after the three-dimensional virtual space is divided into grids, the three-dimensional coordinates of each grid can be determined, and the three-dimensional coordinates of each grid can be determined according to the length of each edge in the grid. The present disclosure can use the three-dimensional coordinates of the vertices in each grid that have the minimum components of the X, Y, and Z axis coordinates as the coordinates of the grid. In addition, the coordinates of the center point of the grid can also be used as the coordinates of the grid, or the three-dimensional coordinates of the vertices in the grid that have the maximum components of the X, Y, and Z axis coordinates can be used as the coordinates of the grid. The present disclosure does not make further limitations. For the convenience of description, the subsequent embodiments of the present disclosure all use the three-dimensional coordinates of the vertices in the grid that have the minimum components of the X, Y, and Z axes as the coordinates of the grid.
[0043] It should be understood that in the process of displaying three-dimensional fluid, at least the three-dimensional coordinates and speed of the fluid particles in the current frame will be stored. After obtaining the three-dimensional coordinates of the fluid particles in the current frame, combined with the coordinates of each grid, the grid where each fluid particle is located in the current frame can be determined. For example, the three-dimensional coordinates of a fluid particle are (5.1, 7.2, 6.1). Since the coordinates of each grid are defined by the coordinates of the vertex with the minimum components of the X, Y and Z axes at the same time, and the side length of the grid is unit length, it can be known that the fluid particle is located in the grid with coordinates (5, 7, 6).
[0044] S102 . For each grid in the grid set, obtain the speed of the grid in the current frame according to the speed of the fluid particles in the grid and in the surrounding grids within a preset range in the current frame.
[0045] The present disclosure will at least store the three-dimensional coordinates and speed of the current frame of the fluid particles during the display of the three-dimensional fluid. Of course, the three-dimensional coordinates and speed of each frame of the three-dimensional fluid can also be stored. Considering that if the speed of the fluid particles is directly updated, the efficiency of drawing the three-dimensional fluid will be seriously affected due to the huge number of fluid particles. By gridding the three-dimensional virtual space, a large number of fluid particles are represented by a small number of grids, and updating the speed of the grids, the computational overhead can be greatly reduced. More importantly, when considering the influence of fluid pressure on the movement of the fluid, the speed of the grid is more accurate than the particle speed.
[0046] The grid itself is fixed, and it is the fluid particles in the grid that actually move. The present invention sets an influence radius for each particle. The speed and coordinates of each particle will affect the speed and coordinates of the grid vertices within the influence radius of the particle. For each grid, the fluid particles inside the grid and in the surrounding grids within a preset range are all regarded as fluid particles that affect the grid. The speed of the grid in the current frame is obtained through the speed of these influencing fluid particles, so that the speed of the grid is first updated, and then the speed of the fluid particles is updated using the updated grid speed, which can improve the updating efficiency of the fluid particle speed.
[0047] In the embodiment of the present disclosure, the surrounding grids within the preset range of each grid include surrounding grids in the same plane as the grid and surrounding grids in different planes, that is, including multiple surrounding grids of the grid in a three-dimensional virtual space rather than in a two-dimensional plane.
[0048] Optionally, the present disclosure may set the preset range to 2, and the side length of the grid is 1, then for a grid coordinate (c X ,c Y ,c Z ) grid, where c X 、c Y and c Z Respectively represent the coordinate components of the grid on the X-axis, Y-axis and Z-axis, and the surrounding grids within the preset range include the grids of the following coordinates: (c X ,c Y ,c Z )、(c X +1,c Y ,c Z )、(c X-1,c Y ,c Z )、(c X +2,c Y ,c Z )、(c X -2,c Y ,c Z )、(c X ,c Y +1,c Z )、(c X ,c Y -1,c Z )、(c X ,c Y +2,c Z )、(c X ,c Y- 2,c Z )、(c X ,c Y ,c Z +1)、(c X ,c Y ,c Z -1)、(c X ,c Y ,c Z +2)、(c X ,c Y ,c Z -2)、(c X +1,c Y +1,c Z )、(c X +1,c Y- 1,c Z )、(c X +2,c Y +1,c Z )、(c X +1,c Y +2,c Z It should be noted that the specific values of the above preset ranges are only examples, and the embodiments of the present disclosure do not limit the specific size of the preset ranges, which can be set according to actual conditions, such as the number of grids for dividing the three-dimensional fluid.
[0049] S103, adjusting the speed of the grid in the current frame according to a preset acceleration, and obtaining the speed of the grid in the next frame according to the adjusted speed of the grid, the positional relationship between the grid and a preset container wall in the three-dimensional virtual space, and a preset rebound speed.
[0050] By adding a preset direction of acceleration to the velocity of the mesh in the current frame, the velocity of the mesh vertex in the next frame can be updated in the preset direction. The present disclosure does not impose any specific restrictions on the direction of the external force, for example, it can be the direction of the coordinate axis corresponding to the gravity direction in the three-dimensional virtual space.
[0051] In order to achieve the collision effect of three-dimensional fluid, the present invention, after adjusting the speed of the grid in the current frame, will also combine the positional relationship between the grid and the preset container wall in the three-dimensional virtual space and the rebound speed to obtain the speed of the grid in the next frame, thereby laying the foundation for the subsequent collision effect of fluid particles.
[0052] It should be understood that the container wall is used to limit the range of motion of the three-dimensional fluid and can be understood as the boundary of the three-dimensional virtual space. The container wall of the present disclosure can be a plane or a curved surface, and no further limitation is made on this.
[0053] The present invention can adjust the speed of the grid in the current frame according to the preset acceleration, and obtain the speed of the grid in the next frame according to the adjusted speed of the grid, the positional relationship between the grid and the preset container wall in the three-dimensional virtual space, and the preset rebound speed.
[0054] S104. Obtain the velocity of the fluid particles in the next frame according to the velocity of the grid in the next frame and the velocity of the fluid particles in the grid in the current frame, and obtain the three-dimensional coordinates of the fluid particles in the next frame according to the velocity of the fluid particles in the next frame and the three-dimensional coordinates in the current frame.
[0055] Since the speed change of the grid can reflect the speed change of the particles in the grid, the difference between the speed of the grid in the next frame and the speed of the current frame is used as the speed change of the fluid particles. The speed change is added to the speed of the fluid particles in the current frame to obtain the speed of the fluid particles in the next frame. By using the speed of the grid to update the speed of the fluid particles, the foundation is laid for the subsequent determination of the three-dimensional coordinates of the fluid particles in the next frame.
[0056] Furthermore, the present disclosure can obtain the displacement of the fluid particles from the current frame to the next frame based on the product of the velocity of the fluid particles in the next frame and the time step, and then accumulate the displacement on the three-dimensional coordinates of the fluid particles in the current frame to obtain the three-dimensional coordinates of the fluid particles in the next frame.
[0057] S105. Display the three-dimensional fluid of the next frame in the three-dimensional virtual space according to the three-dimensional coordinates of all fluid particles in the three-dimensional fluid in the next frame.
[0058] The above method can be used to obtain the three-dimensional coordinates of all fluid particles in the three-dimensional fluid in the next frame. According to the three-dimensional coordinates of the fluid particles in the next frame, the positions of the fluid particles in the three-dimensional virtual space are updated to obtain the three-dimensional fluid of the next frame, thereby displaying the three-dimensional fluid of the next frame in the three-dimensional virtual space.
[0059] The method for displaying fluid collision effects provided by the present disclosure uses a grid to assist in the motion simulation calculation of particles, which can better handle the effects of acceleration and fluid pressure on fluid motion, and has a small additional cost. In addition, the particle velocity is updated using the velocity change of the grid, rather than directly converting the grid velocity to the particle velocity, which can reduce the numerical dissipation caused by converting the particle velocity to the grid and then back to the particle, and by considering the positional relationship between the grid and the container wall in the three-dimensional virtual space and the rebound velocity, a more realistic and natural fluid collision effect can be displayed.
[0060] It should be understood that GPU (Graphics Processing Unit) has obvious advantages over CPU (central processing unit) in image processing, but because GPU can only process two-dimensional images and cannot directly process three-dimensional images, the existing three-dimensional fluid display is often completed by CPU. When using GPU for three-dimensional fluid simulation, it is still necessary to use CPU to pre-process the three-dimensional fluid data, that is, there is currently no method to achieve three-dimensional fluid display using only GPU.
[0061] In order to implement the method for displaying three-dimensional fluid using GPU, based on the above embodiments, as an optional embodiment, after step S104, the following is further included:
[0062] According to the three-dimensional coordinates of the fluid particles in the next frame, the fluid particles are mapped to the first two-dimensional texture image and the second two-dimensional texture image of the next frame to obtain the pixel points corresponding to the fluid particles in the first two-dimensional texture image and the second two-dimensional texture image of the next frame; the three-dimensional coordinates of the fluid particles in the next frame are converted into the RGB values of the pixel points corresponding to the fluid particles in the first two-dimensional texture image of the next frame; the speed of the fluid particles in the next frame is converted into the RGB values of the pixel points corresponding to the fluid particles in the second two-dimensional texture image of the next frame.
[0063] Specifically, the horizontal coordinate of the fluid particle in the two-dimensional texture image is x+width*z, where x is the X-axis component of the three-dimensional coordinate of the fluid particle in the next frame, z is the Z-axis component of the three-dimensional coordinate of the fluid particle in the next frame, and width is the width of the three-dimensional virtual space in the Z-axis direction.
[0064] For example, if the size of the 3D virtual space is 3*4*5, it can be known that the width of the 3D virtual space in the Z-axis direction is 5. If the 3D coordinates of a fluid particle in the next frame are (1,2,3), then the horizontal coordinate of the fluid particle mapped to the 2D texture image is 1+5*3=16, and the vertical coordinate is 2, that is, the 2D coordinate of the fluid particle in the 2D texture image is (16,2). Through the above method, the 3D coordinates of all fluid particles can be mapped to the 2D texture image. It can be further known that the size of the 2D texture image is 28*4.
[0065] Since the three-dimensional coordinates, velocity and RGB values of fluid particles are all three-dimensional vectors, the components of the three-dimensional coordinates and velocity on the three axes can be directly used as the values of R, G, and B. For example, if the three-dimensional coordinates of a fluid particle are (1,2,3) and the velocity is (4,5,6), then the RGB value of the fluid particle in the first two-dimensional texture image is: the value of the red channel (R) is 1, the value of the green channel (G) is 2, and the value of the blue channel (B) is 3. Then the RGB value of the fluid particle in the second two-dimensional texture image is: the value of the red channel (R) is 4, the value of the green channel (G) is 5, and the value of the blue channel (B) is 6; it should be understood that 4, 5, and 6 in the above velocity represent the velocity components of the fluid particle on the X, Y, and Z axes, respectively.
[0066] The disclosed embodiment can map the three-dimensional coordinates of the fluid particles into two two-dimensional texture images according to the same method, and then represent the three-dimensional coordinates and velocity of the fluid particles in the two two-dimensional texture images with RGB values, respectively, so that the GPU can directly read the two two-dimensional texture images, determine the three-dimensional coordinates and velocity of the fluid particles by parsing the RGB values, and achieve the effect of performing three-dimensional fluid simulation entirely on the GPU.
[0067] Based on the above embodiments, as an optional embodiment, obtaining the three-dimensional coordinates and velocity of each fluid particle in the three-dimensional fluid in the current frame includes:
[0068] Get the first two-dimensional texture image and the second two-dimensional texture image of the current frame;
[0069] For each pixel point in the first two-dimensional texture image, determine the three-dimensional coordinates of the fluid particle corresponding to the pixel point in the current frame according to the RGB value of the pixel point;
[0070] For each pixel point in the second two-dimensional texture image, the speed of the fluid particle corresponding to the pixel point in the current frame is determined according to the RGB value of the pixel point.
[0071] The pixel points in the first two-dimensional texture image and the second two-dimensional texture image of the present invention are respectively mappings of fluid particles of the three-dimensional fluid in the first two-dimensional texture image and the second two-dimensional texture image, and the RGB values of the pixel points in the first two-dimensional texture image and the second two-dimensional texture image are respectively used to characterize the three-dimensional coordinates and speed of the corresponding fluid particles in the current frame.
[0072] Based on the above embodiments, as an optional embodiment, in step S103, according to the adjusted speed of the grid, the positional relationship between the grid and the preset container wall in the three-dimensional virtual space, and the preset rebound speed, the speed of the grid in the next frame is obtained, including:
[0073] S201. Use the adjusted speed as the first speed.
[0074] The present disclosure can obtain a first speed by adding an acceleration to the speed of the grid in the current frame. For example, the speed of the grid in the current frame is defined as v t , the added acceleration is a, the time step is dt, then the first velocity v t ' can be expressed as v t '=v t +a*dt.
[0075] S202. Update the first speed according to the positional relationship between the grid and the container wall to obtain a second speed of the grid.
[0076] When calculating the second speed, the present disclosure can calculate the component of the second speed on each coordinate axis respectively. The present disclosure takes each coordinate axis in the coordinate system where the three-dimensional virtual space is located as the target axis, takes the grid adjacent to the grid in the positive direction of the target axis as the first reference grid, and takes the grid adjacent to the grid in the negative direction of the target axis as the second reference grid. Taking the X-axis as an example, if the coordinate P of the grid is (p1, p2, p3), wherein p1, p2 and p3 are the components of the coordinates of the grid in the X-axis, Y-axis and Z-axis respectively, the coordinates of the grid adjacent to the grid in the positive direction of the X-axis are P1=(p1+1, p2, p3), and the coordinates of the grid adjacent to the grid in the negative direction of the X-axis are P2=(p1-1, p2, p3); and, when calculating the second speed, the present disclosure can obtain the component of the second speed of the grid in the target axis according to whether the grid and the first reference grid intersect with the container wall and whether the grid and the second reference grid intersect with the container wall.
[0077] S203. Solve the pressure field of the three-dimensional fluid according to the second velocity to obtain a third velocity of the grid.
[0078] The present invention determines the divergence of the grid according to the second velocity of the grid, obtains the pressure field gradient of the grid by performing Jacobi iteration on the divergence of the grid, and then obtains the third velocity of the grid according to the difference between the second velocity and the pressure field gradient.
[0079] Divergence can be used to characterize the strength of the divergence of the vector field at each point in space. In fluid mechanics, the rate of change of density is equal to the divergence of momentum. If the divergence is positive, it means that the vector field is spreading outward, and if it is negative, it means that these vector fields are concentrated inward. In other words, the divergence indicates the direction of the flow of the vector, and the greater the degree of this flow, the faster the divergence, and the greater the corresponding divergence value.
[0080] In the process of performing Jacobi iteration on the divergence of the grid, the pressure of each grid is first initialized to 0. In each iteration, the pressure of the six grids above, below, front, back, left, and right in the previous iteration is first determined, and the sum of the six pressures is calculated; then the difference between the sum of the six pressures and the divergence of the grid is calculated; the difference is divided by 6 to obtain the pressure of the grid in the current iteration. The present disclosure does not specifically limit the number of iterations, for example, it can be 20 times.
[0081] Furthermore, in the present disclosure, for a grid without fluid particles, the pressure is always set to 0.
[0082] The pressure field gradient is the pressure change per unit length along the direction of fluid flow (movement). The pressure field gradient of the grid can be obtained by counting the pressure difference between each grid and another grid adjacent to it in the velocity direction.
[0083] After calculating the second velocity, the present invention further calculates the pressure field gradient of the grid, and uses the difference between the second velocity and the pressure field gradient to obtain the third velocity of the grid, which can prevent the fluid from being too aggregated after an external force is applied, and the simulation effect is more realistic.
[0084] S204: Update the third speed according to the positional relationship between the grid and the container wall and the preset rebound speed to obtain the speed of the grid in the next frame.
[0085] When calculating the speed of the grid in the next frame, the present disclosure will respectively calculate the component of the speed of the next frame on each coordinate axis. Similar to the calculation of the second speed, it is also necessary to consider the judgment result of whether the line connecting the grid and the first reference grid intersects with the container wall and the judgment result of whether the line connecting the grid and the second reference grid intersects with the container wall. Combined with the preset rebound speed, the component of the third speed on the target axis is updated to obtain the component of the speed of the next frame on each coordinate axis.
[0086] Based on the above embodiments, as an optional embodiment, the step S202 of updating the first speed according to the positional relationship between the grid and the container wall to obtain the second speed of the grid includes:
[0087] S301, taking any coordinate axis in the coordinate system where the three-dimensional virtual space is located as a target axis, taking the grid adjacent to the target axis in the positive direction of the grid as a first reference grid, and taking the grid adjacent to the target axis in the negative direction of the grid as a second reference grid;
[0088] S302, updating the component of the first velocity on the target axis according to whether the line connecting the grid and the first reference grid intersects with the container wall, and obtaining the component of the first reference velocity on the target axis;
[0089] S303 . According to whether the line connecting the grid and the second reference grid intersects with the container wall, update the component of the first reference velocity on the target axis to obtain the component of the second velocity on the target axis.
[0090] In the process of obtaining the second speed from the first speed, the present disclosure first obtains the first reference speed according to whether the line connecting the grid and the first reference grid intersects with the container wall, and then updates the first reference speed according to whether the line connecting the grid and the second reference grid intersects with the container wall to obtain the second speed. Specifically:
[0091] If the line connecting the grid and the first reference grid does not intersect with the container wall, the component of the first speed on the target axis is used as the component of the first reference speed on the target axis; if the line connecting the grid and the first reference grid intersects with the container wall, the smaller value between the component of the first speed on the target axis and the component of the preset speed threshold on the target axis is used as the component of the first reference speed on the target axis.
[0092] If the line connecting the grid and the second reference grid does not intersect with the container wall, the component of the first reference speed on the target axis is used as the component of the second speed on the target axis; if the line connecting the grid and the second reference grid intersects with the container wall, the larger value between the updated component of the first reference speed on the target axis and the component of the preset speed threshold on the target axis is used as the component of the second speed on the target axis.
[0093] See also Figure 2 , which exemplarily shows a schematic diagram of the spatial position relationship between the grid, the first reference grid, the second reference grid and the container wall provided by the embodiment of the present disclosure. As shown in the figure, grid C1 and grid C2 are the first reference grid and the second reference grid on the X-axis with grid G1, respectively. R1 and R2 are both container walls in the three-dimensional virtual space. The line between one grid and another grid can be the line between any point in one grid and any point in another grid. For convenience, the embodiment of the present disclosure uses the line between the points that define the grid coordinates as the line between the two grids. By Figure 2 It can be seen that the line connecting the grid G1 and the grid C1 intersects with the container wall R1, and the line connecting the grid G1 and the grid C2 does not intersect with the container walls R1 and R2.
[0094] Take the calculation of the second velocity component of the grid G1 on the X axis as an example. If the velocity of the grid G1 is defined as (v X ,v Y ,v Z ), where v X ,v Y ,v Z are the components of the velocity of the grid G1 on the X, Y, and Z axes respectively, and the preset velocity threshold is (v Xa ,v Ya ,v Za ), v Xa ,v Ya ,v Za are the components of the preset speed threshold on the X, Y, and Z axes, respectively, and v X >v Xa , v Y >v Ya , v Z >v Za .
[0095] First, since the line connecting the grid G1 and the grid C1 intersects the container wall, the component of the first reference velocity on the X-axis is the smaller value between the component of the first velocity on the X-axis and the preset velocity threshold, that is, v Xa ; Since the line connecting the grid G1 and the grid C2 does not intersect the container wall, the component of the second velocity on the X-axis is the component of the first reference velocity on the X-axis, that is, v Xa .
[0096] Optionally, the preset speed threshold of the present disclosure is 0, that is, if the line connecting the grid and the first reference grid intersects with the container wall, and the line connecting the grid and the second reference grid does not intersect with the container wall, then the second speed of the grid will be updated to 0.
[0097] Based on the above embodiments, as an optional embodiment, in step S204, updating the third speed according to the positional relationship between the grid and the container wall and the preset rebound speed to obtain the speed of the grid in the next frame includes:
[0098] S401, taking any coordinate axis in the three-dimensional virtual space as a target axis, taking a grid adjacent to the target axis in a positive direction as a first reference grid, and taking a grid adjacent to the target axis in a negative direction as a second reference grid;
[0099] S402: According to a preset rebound speed and whether a line connecting the grid and the first reference grid intersects with a container wall, update a component of the third speed on the target axis to obtain a component of the second reference speed on the target axis.
[0100] Specifically, if the line connecting the grid and the first reference grid does not intersect the container wall, the component of the third speed at the target value is used as the component of the second reference speed at the target axis;
[0101] If the line connecting the grid and the first reference grid intersects the container wall, the smaller value between the component of the third velocity at the target value and the negative value of the component of the rebound velocity at the target axis is used as the component of the second reference velocity at the target axis.
[0102] S403, according to the preset rebound speed and whether the line connecting the grid and the second reference grid intersects with the container wall, update the component of the second reference speed on the target axis, and obtain the component of the speed of the grid on the target axis in the next frame.
[0103] If the line connecting the grid and the second reference grid does not intersect the container wall, the component of the second reference velocity on the target axis is used as the component of the velocity of the grid vertex on the target axis in the next frame;
[0104] If the line connecting the mesh and the second reference mesh intersects the container wall, the larger value between the component of the third velocity in the target axis and the component of the rebound velocity in the target axis is used as the component of the velocity of the mesh vertex in the next frame in the target axis.
[0105] by Figure 2 Taking the spatial position relationship shown in the figure as an example, firstly, since the line connecting the grid G1 and the grid C1 intersects with the container wall, the component of the second reference velocity on the X-axis is the smaller value between the negative value of the component of the first velocity on the X-axis and the component of the rebound velocity on the target axis; and since the line connecting the grid G1 and the grid C2 does not intersect with the container wall, the component of the second velocity on the X-axis is the component of the second reference velocity on the X-axis.
[0106] Based on the above embodiments, as an optional embodiment, the speed of the grid in the next frame is obtained, and then the following steps are further included:
[0107] If the component of the speed of the grid in the next frame in any axis of the coordinate system where the three-dimensional virtual space is located is greater than a preset threshold, the component of any axis is updated to a preset value.
[0108] It should be noted that in order to avoid the problem that the fluid particles cannot be rendered and displayed due to the movement of the particles outside the three-dimensional virtual space, after obtaining the speed of the grid in the next frame, the present disclosure will also detect whether the component of each axis is greater than the preset value. If it is greater than the preset value, the component of the axis is updated to the preset value. Since a gravitational acceleration is usually applied to the fluid particles in the Z axis, the component of the speed of the fluid particles in the next frame in the Z axis is most likely to exceed the preset value.
[0109] On the basis of the above embodiments, as an optional embodiment, when obtaining the speed of the grid in the current frame, the embodiment of the present disclosure divides the surrounding grids of the grid into two different situations: surrounding grids that are in the same horizontal plane as the grid and surrounding grids that are in different horizontal planes, and obtains the speed of the grid in the current frame for the two different situations. The reason for this operation is that when mapping points in a three-dimensional virtual space to a two-dimensional texture image, the relative positions of two points that were originally in the same horizontal plane in the two-dimensional texture image do not change, while the relative positions of two points that were originally in different horizontal planes in the two-dimensional texture image will change, which causes the interaction between fluid particles at different horizontal planes to be different in the three-dimensional virtual space and the two-dimensional space.
[0110] See also Figure 3 , which exemplarily shows a schematic diagram of mapping a grid in a three-dimensional virtual space to a two-dimensional texture image. As shown in the figure, there are 8 grids in the three-dimensional virtual space, and the side length of the grid is unit length, including 4 grids 1 to 4 located in the lower layer and 4 grids 5 to 8 located in the upper layer. The process of 8 grids to the two-dimensional texture image is actually a tiling process, that is, tiling the grids of each layer on the two-dimensional texture image. The original 2*2*2 three-dimensional structure becomes a 4*2 rectangle after tiling. Originally, grids 1 and 5 are directly in contact in the three-dimensional virtual space, but after being mapped to the two-dimensional texture image, grids 1 and 5 are separated by grid 2.
[0111] Based on this, the speed of the grid in the current frame is obtained according to the speed of the fluid particles in the grid and the surrounding grids within the preset range in the current frame, including:
[0112] Take each mesh as a base mesh, and for each base mesh, do the following:
[0113] S501: taking fluid particles inside each basic grid and in surrounding grids within a preset range as reference fluid particles, and determining the relative position of the reference fluid particles and the corresponding target grid.
[0114] When calculating the speed of each grid in the current frame, the present invention takes each grid as a basic grid, and first takes the fluid particles inside the basic grid and in the surrounding grids within a preset range as reference fluid particles. Taking the preset range as the unit length as an example, for each basic grid, the fluid particles in the 8 grids on the same horizontal plane and the 18 grids on the upper and lower horizontal planes, a total of 26 grids, are all reference fluid particles.
[0115] After determining the reference fluid particles, the target grid corresponding to the reference fluid particles is further determined. The present disclosure sets two methods for determining the target grid according to whether the grid where the reference fluid particles are located is in the same plane as the base grid:
[0116] (1) When the reference fluid particle corresponding to the base grid is located in the base grid or the grid where it is located is on the same horizontal plane as the base grid, the target grid corresponding to the reference fluid particle is the grid where the reference fluid particle is located;
[0117] (2) When the grid where the reference fluid particle corresponding to the base grid is located is on a different level from the base grid, the target grid corresponding to the reference fluid particle is the base grid.
[0118] See also Figure 4 , which exemplarily shows a positional relationship diagram of a basic grid and surrounding grids of an embodiment of the present disclosure. As shown in the figure, grid 1 is a basic grid, grid 2 and grid 3 are both surrounding grids of the basic grid, and the XY plane is defined as a horizontal plane. Grid 2 and grid 1 are in the same horizontal plane, and grid 3 and grid 1 are in a different horizontal plane.
[0119] For a reference fluid particle in a base grid, the target grid of the reference fluid particle is the grid where it is located, that is, the base grid;
[0120] For a grid in the same plane as grid 1, the target grid of the reference fluid particle in the grid is the grid where the reference fluid particle is located, for example, the target grid of the reference fluid particle in grid 2 is grid 2;
[0121] For a grid in a different plane from grid 1 , the target grid for the reference fluid particles in the grid is reference grid 1 , for example, the target grid for the reference fluid particles in grid 3 is grid 1 .
[0122] After determining the target grid of each reference fluid particle, the relative position between the reference fluid particle and the target grid can be determined based on the coordinates of the reference fluid particle and the coordinates of the target grid. For example, the present disclosure can define the difference between the coordinates of the target grid and the coordinates of the reference fluid particle as the relative position between the reference fluid particle and the target grid. For example, if the coordinates of the target grid are (2,2,2) and the coordinates of the reference fluid particle are (3,3,3), then the relative position between the reference fluid particle and the target grid is (1,1,1).
[0123] S502: Obtain the weight of the reference fluid particle relative to the corresponding target grid according to the relative position.
[0124] The relative position can characterize the distance between the reference fluid particle and the target grid on each coordinate axis. For example, if the reference fluid particle is closer to the surface of the target grid perpendicular to the X-axis, it can be considered that the component of the velocity of the reference fluid particle in the X-axis has a greater impact on the velocity of the target grid, while the components of the velocity of the reference fluid particle in the Y-axis and Z-axis have less impact on the velocity of the target grid. Based on this, the present disclosure can convert the relative position into the weight of the reference fluid particle relative to the target grid. The weight in the present disclosure can be represented by a vector, and the elements in the vector correspond to the components of the weight of the reference fluid particle for the target grid on each coordinate axis.
[0125] S503. Obtain a weighted value of the speed of the reference fluid particle relative to the corresponding target grid according to the speed of the reference fluid particle in the current frame and the weight of the reference fluid particle relative to the corresponding target grid.
[0126] The present disclosure may use the product of the velocity of the reference fluid particle in the current frame and the weight of the reference fluid particle relative to the corresponding target grid as the velocity weighted value of the reference fluid particle relative to the corresponding target grid.
[0127] For example, the velocity of the reference fluid particle in the current frame is (v X ,v Y ,v Z ), v X ,v Y ,v Z They respectively represent the components of the velocity of the reference fluid particle in the current frame on the X-axis, Y-axis, and Z-axis.
[0128] The weight of the reference fluid particle relative to the corresponding target grid is (w X ,w Y ,w Z ), w X ,w Y ,w Z They represent the weight of the reference fluid particles relative to the corresponding target grid on the X-axis, Y-axis, and Z-axis respectively.
[0129] The velocity weight of the reference fluid particle relative to the corresponding target grid is (v X *w X ,v Y *w Y ,v Z *w Z ), where * represents a multiplication operation.
[0130] S504. Obtain the velocity of the base grid in the current frame according to the sum of the velocity weighted values of all reference fluid particles relative to the corresponding target grid and the sum of the weights of all reference fluid particles relative to the corresponding target grid.
[0131] Specifically, the present invention obtains the velocity weighted values of all reference fluid particles for the target grid by summing them up to obtain a total velocity weighted value; sums the weights of all reference fluid particles for the target grid to obtain a total weight, and divides the total velocity weighted value by the total weight as the velocity of the grid in the current frame.
[0132] The present invention determines the weights of reference fluid particles and corresponding target grids according to their relative positions, uses the weights to weight the speed of the reference fluid particles in the current frame, obtains a weighted value of the speed of the reference fluid particles relative to the corresponding target grid, and finally obtains the speed of the basic grid in the current frame according to the sum of the weighted values of the speeds of all reference fluid particles relative to the corresponding target grid and the sum of the weights of all reference fluid particles relative to the corresponding target grid. The entire process fully considers the positional relationship between the reference fluid particles and the target grid, so that the speed of the obtained grid is more in line with the movement law of the fluid in the three-dimensional virtual space.
[0133] Based on the above embodiments, as an optional embodiment, obtaining the weight of the reference fluid particle for the corresponding target grid according to the relative position includes:
[0134] S601. Take each axis in the coordinate system of the three-dimensional virtual space as a target axis, take a surface in the corresponding target grid that is perpendicular to the target axis as a target surface, and obtain the projection length of the distance between the reference fluid particle and the midpoint of the target surface in the three-axis directions.
[0135] The present disclosure characterizes the relative position of the reference fluid particle in the grid by the distance between the reference fluid particle and the middle points of the three surfaces of the grid in the X, Y and Z axis directions.
[0136] It should be understood that the three faces selected in the X, Y and Z axis directions of all meshes should be uniform. The present disclosure selects three faces that are in contact with the vertex with the minimum components of the X, Y and Z axes in the mesh. That is, if the three-dimensional coordinates of the mesh are (c X ,c Y ,c Z ), that is, the three-dimensional coordinates of the vertex with the smallest components of the X, Y and Z axes are (c X ,c Y ,c Z ), and the side length of the grid is unit length 1, then the middle point of the three faces of the grid in the X, Y and Z axis directions can be: (c X ,c Y +0.5,c Z +0.5)、(c X +0.5,c Y ,c Z +0.5) and (c X +0.5,c Y +0.5,c Z ), it can be understood that the surface of the grid in the direction of a certain axis of the present invention is also the surface perpendicular to the axis.
[0137] Since the fluid of the present disclosure is a three-dimensional fluid, when calculating the weight, the weight component on each axis should also be calculated. When calculating the weight component on each axis, the present disclosure calculates the distance between the reference fluid particle and the center point of the surface of the grid in the direction of the axis.
[0138] For example, when calculating the weight component on the X-axis, the distance between the reference fluid particle and the center point of the surface of the grid in the X-direction is obtained. Since the distance is the distance between two points in a three-dimensional virtual space, the present disclosure further obtains the projection length of the distance in the X, Y and Z-axis directions. In fact, the X, Y and Z-axis coordinate values of the reference fluid particle are respectively subtracted from the X, Y and Z-axis coordinate values of the center point of the surface of the grid in the X-direction to obtain the projection length. For example, if the coordinates of the reference fluid particle are (a, b, c), and the coordinates of the center point of the surface of the grid in the X-direction are (e, f, g), then the projection lengths of the distance between the reference fluid particle and the midpoint of the surface of the grid in the target axis direction in the X, Y and Z-axis directions are |ae|, |bf| and |cg| respectively.
[0139] S602, respectively comparing the differences between the three projection lengths and the unit length to obtain a first difference, a second difference, and a third difference, taking the larger number between the first difference and the preset value as the first parameter, taking the larger number between the second difference and the preset value as the second parameter, and taking the larger number between the third difference and the preset value as the third parameter;
[0140] S603. Obtain the component of the weight of the reference fluid particle for the target grid on the target axis according to the product of the first parameter, the second parameter and the third parameter, and obtain the weight of the reference fluid particle for the corresponding target grid according to the component.
[0141] Specifically, the present disclosure may use the product of the first parameter, the second parameter, and the third parameter as the component of the weight of the reference fluid particle for the corresponding target grid on the target axis.
[0142] The weight of the reference fluid particle for the corresponding target grid obtained according to the relative position of the present disclosure can also be calculated based on the following formula:
[0143] w=(k(PC X ),k(PC Y ),k(PC Z ));
[0144] k(u)=h(u x )·h(u y )·h(u z );
[0145] h(x)=max{0,1-|x|};
[0146] Where w represents the weight of the reference fluid particle P for the target grid, k(u) represents the function k with independent variable u, k(PC X ) represents the midpoint C of the surface between the reference fluid particle P and the target grid in the X-axis direction. X The obtained reference fluid particle P weight for the target grid is the component on the X axis, k(PC Y ) represents the midpoint C of the surface between the reference fluid particle P and the target grid in the Y-axis direction Y The weight of the reference fluid particle P for the target grid on the Y axis, k(PC Z ) represents the midpoint C of the surface between the reference fluid particle P and the target grid in the Z-axis direction. Z The weight of the reference fluid particle P for the target grid in the Z-axis component, h(u x ) represents the component of parameter u on the X-axis, h(u y ) represents the component of parameter u on the Y axis, h(u z ) represents the component of parameter u on the Z axis. h(x) represents the function h with independent variable X.
[0147] For example, if the particle position is P(p X ,p Y ,p Z ), the three-dimensional coordinates of the grid are C(c X ,c Y,c Z ), the boundary center points of the grid in the X, Y and Z axis directions are C X (c X ,c Y +0.5,c Z +0.5), C Y (c X +0.5,c Y ,c Z +0.5), C Z (c X +0.5,c Y +0.5,c Z );
[0148] k(PC X ) as an example, k(PC X )=h(p X -c X )*h(p Y -c Y -0.5)*h(p Z -c Z -0.5);
[0149] h(p X -c X )=max{0,1-|p X -c X |};
[0150] h(p Y -c Y -0.5)=max{0,1-|p Y -c Y -0.5|};
[0151] h(p Z -c Z )=max{0,1-|p Z -c Z -0.5|}.
[0152] The present invention obtains the component of the weight of the reference fluid particle for the target grid in the target axis according to the distance between the reference fluid particle and the midpoint of the surface of the target grid in the target axis direction, further obtains the speed weighted value of the reference fluid particle for the target grid according to the weight and the speed of the reference fluid particle in the current frame, and then uses the sum of the speed weighted values of all reference fluid particles for the target grid and the sum of the weights of all reference fluid particles for the target grid to obtain the speed of the basic grid in the current frame. Since the basic grid takes into account the influence of the reference fluid particles within a certain range, the speed of the obtained grid is more accurate.
[0153] Based on the above embodiments, as an optional embodiment, the present disclosure solves the pressure field of the three-dimensional fluid according to the second velocity to obtain the third velocity of the grid, including: obtaining the divergence of the grid according to the second velocity of each grid, performing Jacobi iteration according to the divergence of the grid to obtain the pressure field gradient of the grid, and obtaining the third velocity of the grid according to the difference between the second velocity of the grid and the pressure field gradient.
[0154] Based on the above embodiments, as an optional embodiment, obtaining the divergence of each grid according to the second speed of each grid includes:
[0155] S701 . For each mesh vertex, obtain a velocity of the mesh vertex according to second velocities of all meshes that the mesh vertex contacts.
[0156] Specifically, since each mesh vertex contacts 8 meshes, the average value of the second velocities of the 8 contacting meshes is used as the velocity of the mesh vertex.
[0157] S702 . For each face of the mesh, take the average of the speeds of all mesh vertices on each face as the speed of each face.
[0158] After determining the speed of each mesh vertex, considering that each face has 4 mesh vertices, the average of the speeds of the 4 mesh vertices in the next frame can be used as the speed of each face.
[0159] S703. For any two opposite surfaces in the grid, obtain the speed difference between the two opposite surfaces according to the speeds of the two opposite surfaces, and obtain the divergence of the grid according to the sum of the speed differences of all the opposite surfaces of the grid.
[0160] See also Figure 5 , which exemplarily shows a calculation flow chart of the grid divergence provided by an embodiment of the present disclosure. As shown in the figure, the surfaces perpendicular to the X-axis in the grid are X1 and X2, respectively, wherein the X-axis component of the coordinates of any point on X1 is greater than the X-axis component of the coordinates of any point on X2; the surfaces perpendicular to the Y-axis are Y1 and Y2, respectively, wherein the Y-axis component of the coordinates of any point on Y1 is greater than the Y-axis component of the coordinates of any point on Y2; the surfaces perpendicular to the Z-axis are Z1 and Z2, respectively, wherein the Z-axis component of the coordinates of any point on Z1 is greater than the Z-axis component of the coordinates of any point on Z2; after obtaining the velocities of the above six surfaces, the difference in velocities of the two opposite surfaces is calculated respectively, that is, the difference dX between the velocities of surface X1 and surface X2, the difference dY between the velocities of surface Y1 and surface Y2, and the difference dZ between the velocities of surface Z1 and surface Z2 are calculated, and the divergence of the grid can be obtained by summing dX, dY and dZ.
[0161] Furthermore, after calculating the divergence, the present disclosure can also compare the divergence with a preset maximum divergence. If the divergence is greater than the preset maximum divergence, the divergence is updated to the maximum divergence. If the divergence is not greater than the preset maximum divergence, no update is required. By setting a limit on the maximum divergence, the expansion (fluid particle diffusion) and compression (fluid particle condensation) of the simulated three-dimensional fluid can be made more consistent with the real fluid motion effect.
[0162] On the basis of the above embodiments, according to the velocity of the fluid particle in the next frame and the three-dimensional coordinates in the current frame, the three-dimensional coordinates of the fluid particle in the next frame are obtained, including:
[0163] S801. Obtain a transition position of the fluid particle according to the velocity of the fluid particle in the next frame, the time difference between the current frame and the next frame, and the three-dimensional coordinates of the fluid particle in the current frame.
[0164] When determining the position of a fluid particle in the next frame, the present disclosure first calculates the transition position of the fluid particle according to the speed of the fluid particle in the next frame, the time difference between the current frame and the next frame, and the three-dimensional coordinates of the fluid particle in the current frame. The transition position is a hypothetical position of the present disclosure, the purpose of which is to update the position of the fluid particle more smoothly. From the parameters required for calculating the transition position, it can be seen that half of the time difference between the current frame and the next frame is selected in order to obtain the position of the particle at the middle moment in the period from the moment corresponding to the current frame to the moment corresponding to the next frame when the particle moves according to the speed of the fluid particle in the next frame and the three-dimensional coordinates of the current frame.
[0165] S802. Determine the grid where the transition position of the fluid particle is located as the transition grid.
[0166] S803, obtaining the transition speed of the fluid particles at the transition position according to the coordinates and speeds of the transition grid and the adjacent grids adjacent to the transition grid on the extension lines of the three coordinate axes.
[0167] For each fluid particle, after determining the transition grid corresponding to the fluid particle, the transition speed of the fluid at the transition position is calculated using the coordinates and speeds of the transition grid and the adjacent grids adjacent to the transition grid on the extension lines of the three coordinate axes. The transition speed can more smoothly connect with the speed of the previous frame in terms of speed magnitude and speed direction compared to the speed of the next frame, laying the foundation for the subsequent recalculation of the three-dimensional coordinates of the fluid particle in the next frame based on the transition speed.
[0168] Specifically, step S803 includes:
[0169] Each axis of the coordinate system of the three-dimensional virtual environment is taken as a target axis, adjacent grids of the transition grid on the extension line of the target axis are determined, and a target surface of the transition grid and the adjacent grid perpendicular to the target axis is determined.
[0170] See also Figure 6 , which exemplarily shows a schematic diagram of the positional relationship between the transition grid and the adjacent grids provided in the embodiment of the present disclosure. As shown in the figure, the grid G1 is the transition grid. The transition grid in the embodiment of the present disclosure has three adjacent grids, wherein the adjacent grid L1 is located on the extension line of the transition grid in the X-axis direction, the adjacent grid L2 is located on the extension line of the transition grid in the Y-axis direction, and the adjacent grid L3 is located on the extension line of the transition grid in the Z-axis direction.
[0171] The speed of the first center point of the target surface of the transition mesh is obtained according to the speed of all meshes touched by the mesh vertices of the target surface of the transition mesh in the next frame; the speed of the second center point of the target surface of the adjacent mesh is obtained according to the speed of all meshes touched by the mesh vertices of the target surface of the adjacent mesh in the next frame.
[0172] When calculating the speed of the center point of the target surface, the present disclosure first calculates the speed of the mesh vertex and then takes the average of the speeds of the four mesh vertices on the target surface to obtain the speed of the center point of the target surface. It can be seen from the above embodiment that the speed of each mesh vertex is the average of the speeds of the 8 meshes that the mesh vertex contacts.
[0173] For example, taking the Z axis as an example, the transition position is defined as (P X ,P Y ,P Z ), the coordinates of the transition grid are Then the center point of the transition mesh in the Z-axis direction (that is, the surface perpendicular to the Z-axis), that is, the first center point is C z,1 =(c1+0.5,c2+0.5,c3), for the velocity of the center point on the surface, the present disclosure uses the average velocity of the four mesh vertices on the surface in the next frame to characterize it, and defines the calculated velocity of the first center point as v Z,1 =(v1,v2,v3).
[0174] The coordinates of the adjacent grids of the transition grid in the direction of the Z-axis extension line, that is, the adjacent grids, are Then the center point of the surface of the adjacent grid in the Z-axis direction, that is, the second center point is C z,2 =(c1+0.5,c2+0.5,c3+1), define the calculated velocity of the second center point as v z,1 =(v4,v5,v6).
[0175] The component of the transition speed on the target axis is obtained according to the coordinates of the adjacent grids, the transition position, the components of the coordinates of the transition grid on the coordinate axis, and the components of the speeds of the first center point and the second center point on the target axis. The transition speed is obtained according to the components of the transition speed on all coordinate axes.
[0176] Based on the above embodiments, as an optional embodiment, according to the coordinates of the adjacent grids, the transition position, and the components of the coordinates of the transition grids on the coordinate axis and the components of the velocities of the first center point and the second center point on the coordinate axis, obtaining the components of the transition velocity on the coordinate axis includes:
[0177] First, a first weight is obtained according to a difference between the components of the three-dimensional coordinates of the reference grid and the transition position on the target axis; a second weight is obtained according to a difference between the components of the three-dimensional coordinates of the transition position and the target grid on the target axis;
[0178] The product of the first weight and the component of the velocity of the second center point on the target axis is taken as the first velocity, the product of the second weight and the component of the velocity of the first center point on the target axis is taken as the second velocity, and the sum of the first velocity and the second velocity is taken as the component of the transition velocity of the fluid particle on the target axis.
[0179] Taking the Z axis as an example, the present disclosure can calculate the component V of the transition velocity of the fluid particle on the Z axis according to the following formula: z :
[0180] V z =(c3+1-P z )*v6+(P z -c3)*v3
[0181] In this formula, c3+1-P z is the difference between the components of the adjacent grid on the Z axis and the three-dimensional coordinates of the transition position on the Z axis, which is also the first weight; P z -c3 is the difference between the transition position and the three-dimensional coordinates of the transition grid on the target axis, which is also the second weight; (c3+1-P z )*v6 is the first speed, (P z -c3)*v3 is the second speed.
[0182] The above method can be used to determine the component V of the transition velocity of the fluid particles on the X-axis. X and the component V on the X-axis Y , so the transition speed of fluid particles can be expressed as (V X ,V Y ,V z ).
[0183] S604: Obtain the three-dimensional coordinates of the fluid particles in the next frame according to the transition speed of the fluid particles, the time step, and the three-dimensional coordinates of the fluid in the current frame.
[0184] Specifically, the present disclosure can obtain the displacement of the fluid particles from the current frame to the next frame according to the product of the transition speed of the fluid particles and the time step, and then add the displacement to the three-dimensional coordinates of the current frame to obtain the three-dimensional coordinates of the fluid particles in the next frame. Further, according to the three-dimensional coordinates of all fluid particles in the next frame, the three-dimensional fluid of the next frame is displayed in the three-dimensional virtual environment.
[0185] In the process of obtaining the three-dimensional coordinates of the fluid particles in the next frame according to the speed of the fluid particles in the next frame and the three-dimensional coordinates in the current frame, the embodiment of the present disclosure first obtains the transition position of the fluid particles according to the speed of the fluid particles in the next frame, the time difference between two adjacent frames and the three-dimensional coordinates of the fluid particles in the current frame, which can update the position of the fluid particles more smoothly, and further obtains the transition speed of the fluid particles at the transition position according to the coordinates and speeds of the adjacent grids on the extension line of the coordinate axis of the grid where the transition position is located. The transition speed can more smoothly connect with the speed of the previous frame in terms of speed size and speed direction compared with the speed of the next frame. Subsequently, the three-dimensional coordinates of the fluid particles calculated using the transition speed are more in line with the movement characteristics of the fluid.
[0186] According to the method for displaying the fluid collision effect of the embodiment of the present disclosure, a grid can be used to assist in the motion simulation calculation of particles, which can better handle the effects of acceleration and fluid pressure on fluid motion with less additional overhead. In addition, using the velocity change of the grid to update the particle velocity, rather than directly converting the grid velocity to the particle velocity, can reduce the numerical dissipation caused by converting the particle velocity to the grid and then back to the particle, and by considering the positional relationship between the grid and the container wall in the three-dimensional virtual space and the rebound velocity, a more realistic and natural fluid collision effect can be displayed.
[0187] The present disclosure provides a device for displaying fluid collision effects, such as Figure 7 As shown, the device may include: a grid processing module 101, a grid speed module 102, a grid speed updating module 103, a particle coordinate determining module 104 and a display module 105. Specifically:
[0188] The grid processing module 101 is used to perform grid processing on the three-dimensional virtual space showing the three-dimensional fluid, obtain a grid set, obtain the three-dimensional coordinates and velocity of each fluid particle in the three-dimensional fluid in the current frame, and determine the grid where each fluid particle is located in the current frame;
[0189] A grid speed module 102 is used for each grid in the grid set to obtain the speed of the grid in the current frame according to the speed of the fluid particles in the grid and the surrounding grids within a preset range in the current frame;
[0190] The grid speed updating module 103 is used to adjust the speed of the grid in the current frame according to the preset acceleration, and obtain the speed of the grid in the next frame according to the adjusted speed of the grid, the position relationship between the grid and the preset container wall in the three-dimensional virtual space, and the preset rebound speed;
[0191] The particle coordinate determination module 104 is used to obtain the velocity of the fluid particle in the next frame according to the velocity of the grid in the next frame and the velocity of the fluid particle in the grid in the current frame, and obtain the three-dimensional coordinates of the fluid particle in the next frame according to the velocity of the fluid particle in the next frame and the three-dimensional coordinates in the current frame;
[0192] The display module 105 is used to display the next frame of three-dimensional fluid in the three-dimensional virtual space according to the three-dimensional coordinates of all fluid particles in the three-dimensional fluid in the next frame.
[0193] The display device for fluid collision effects provided in the embodiment of the present invention specifically executes the above-mentioned method embodiment process. For details, please refer to the content of the above-mentioned fluid collision effect display method embodiment, which will not be repeated here. The display device for fluid collision effects provided in the embodiment of the present invention uses a grid to assist in the motion simulation calculation of particles, which can better handle the effects of acceleration and fluid pressure on fluid motion, and has less additional overhead. In addition, using the velocity change of the grid to update the particle velocity, rather than directly converting the grid velocity to the particle velocity, can reduce the numerical dissipation caused by converting the particle velocity to the grid and then back to the particle, and by considering the positional relationship between the grid and the container wall in the three-dimensional virtual space and the rebound velocity, a more realistic and natural fluid collision effect can be displayed.
[0194] Based on the above embodiments, as an optional embodiment, the grid speed update module includes:
[0195] A second speed acquisition module is used to use the adjusted speed as the first speed, update the first speed according to the positional relationship between the grid and the container wall, and obtain the second speed of the grid;
[0196] A third velocity acquisition module, used to solve the pressure field of the three-dimensional fluid according to the second velocity to obtain the third velocity of the grid;
[0197] The third speed updating module is used to update the third speed according to the positional relationship between the grid and the container wall and the preset rebound speed to obtain the speed of the grid in the next frame.
[0198] Based on the above embodiments, as an optional embodiment, the second speed acquisition module includes:
[0199] A first reference grid determination submodule is used to use any coordinate axis in the coordinate system of the three-dimensional virtual space as a target axis, use the grid adjacent to the target axis in the positive direction as a first reference grid, and use the grid adjacent to the target axis in the negative direction as a second reference grid;
[0200] A first reference speed updating submodule, used for updating the component of the first speed on the target axis according to whether the line connecting the grid and the first reference grid intersects with the container wall, and obtaining the component of the first reference speed on the target axis;
[0201] The second speed acquisition submodule is used to update the component of the first reference speed on the target axis and obtain the component of the second speed on the target axis according to whether the line connecting the grid and the second reference grid intersects with the container wall.
[0202] On the basis of the above embodiments, as an optional embodiment, the first reference speed updating submodule is specifically used to: if the line connecting the grid and the first reference grid does not intersect with the container wall, then the component of the first speed on the target axis is used as the component of the first reference speed on the target axis; if the line connecting the grid and the first reference grid intersects with the container wall, then the smaller value between the component of the first speed on the target axis and the component of the preset speed threshold on the target axis is used as the component of the first reference speed on the target axis.
[0203] On the basis of the above embodiments, as an optional embodiment, the second speed acquisition submodule is specifically used to: if the line connecting the grid and the second reference grid does not intersect with the container wall, then the component of the first reference speed on the target axis is used as the component of the second speed on the target axis; if the line connecting the grid and the second reference grid intersects with the container wall, then the larger value between the updated component of the first reference speed on the target axis and the component of the preset speed threshold on the target axis is used as the component of the second speed on the target axis.
[0204] Based on the above embodiments, as an optional embodiment, the third speed update module includes:
[0205] A second reference grid determination submodule, used to take any coordinate axis in the three-dimensional virtual space as a target axis, take a grid adjacent to the grid in the positive direction of the target axis as a first reference grid, and take a grid adjacent to the grid in the negative direction of the target axis as a second reference grid;
[0206] A second reference speed acquisition submodule is used to update the component of the third speed on the target axis according to a preset rebound speed and whether the line connecting the grid and the first reference grid intersects with the container wall, and obtain the component of the second reference speed on the target axis;
[0207] The next frame speed acquisition submodule is used to update the component of the second reference speed on the target axis according to the preset rebound speed and whether the line connecting the grid and the second reference grid intersects with the container wall, and obtain the component of the speed of the grid in the next frame on the target axis.
[0208] Based on the above embodiments, as an optional embodiment, the second reference speed acquisition submodule is specifically used for:
[0209] If the line connecting the grid and the first reference grid does not intersect with the container wall, the component of the third velocity at the target value is used as the component of the second reference velocity at the target axis; if the line connecting the grid and the first reference grid intersects with the container wall, the smaller value between the component of the third velocity at the target value and the negative value of the component of the rebound velocity at the target axis is used as the component of the second reference velocity at the target axis.
[0210] Based on the above embodiments, as an optional embodiment, the next frame speed acquisition submodule is specifically used for:
[0211] If the line connecting the mesh and the second reference mesh does not intersect with the container wall, the component of the second reference velocity in the target axis is used as the component of the velocity of the mesh vertex in the next frame in the target axis; if the line connecting the mesh and the second reference mesh intersects with the container wall, the larger value between the component of the third velocity in the target axis and the component of the rebound velocity in the target axis is used as the component of the velocity of the mesh vertex in the next frame in the target axis.
[0212] Based on the above embodiments, as an optional embodiment, the display device further includes:
[0213] The speed limiting module is used to update the component of any axis to the preset value after obtaining the speed of the grid in the next frame if the component of any axis of the speed of the grid in the next frame in the three-dimensional virtual space is greater than the preset value.
[0214] Based on the above embodiments, as an optional embodiment, the grid speed module includes:
[0215] A reference information determination submodule is used to take each grid as a basic grid, and, for each basic grid, take the fluid particles inside the basic grid and the surrounding grids within a preset range as reference fluid particles, and determine the relative position of the reference fluid particles and the corresponding target grid;
[0216] A weight acquisition submodule is used to obtain the weight of the reference fluid particle relative to the corresponding target grid according to the relative position;
[0217] A speed weighted acquisition submodule, used to obtain a speed weighted value of a reference fluid particle relative to a corresponding target grid according to the speed of the reference fluid particle in the current frame and the weight of the reference fluid particle relative to the corresponding target grid;
[0218] The grid speed acquisition submodule is used to obtain the speed of the base grid in the current frame according to the sum of the weighted values of the speeds of all reference fluid particles relative to the corresponding target grid and the sum of the weights of all reference fluid particles relative to the corresponding target grid.
[0219] Based on the above embodiments, as an optional embodiment, for each basic grid, when the reference fluid particle corresponding to the basic grid is located in the basic grid or the grid where it is located is on the same horizontal plane as the basic grid, then the target grid corresponding to the reference fluid particle is the grid where the reference fluid particle is located; when the grid where the reference fluid particle is located is on different horizontal planes from the basic grid, then the target grid corresponding to the reference fluid particle is the basic grid.
[0220] Based on the above embodiments, as an optional embodiment, the weight acquisition submodule includes:
[0221] A projection unit is used to take each axis of the coordinate system of the three-dimensional virtual space as a target axis, take a surface perpendicular to the target axis direction in the corresponding target grid as a target surface, and obtain the projection length of the distance between the reference fluid particle and the midpoint of the target surface in the three-axis directions;
[0222] a parameter calculation unit, for comparing the differences between the three projection lengths and the unit length respectively, obtaining a first difference, a second difference and a third difference, taking the larger number between the first difference and the preset value as the first parameter, taking the larger number between the second difference and the preset value as the second parameter, and taking the larger number between the third difference and the preset value as the third parameter;
[0223] The weight calculation unit is used to obtain the component of the weight of the reference fluid particle for the grid in which it is located on the target axis according to the product of the first parameter, the second parameter and the third parameter, and obtain the weight of the reference fluid particle for the corresponding target grid according to the component.
[0224] Based on the above embodiments, as an optional embodiment, the third speed acquisition module includes:
[0225] A divergence calculation submodule, used for obtaining the divergence of each grid according to the second speed of each grid;
[0226] The pressure field calculation submodule is used to perform Jacobi iteration according to the divergence of the grid to obtain the pressure field gradient of the grid;
[0227] The difference determination submodule is used to obtain the third velocity of the grid according to the difference between the second velocity of the grid and the pressure field gradient.
[0228] Based on the above embodiments, as an optional embodiment, the particle coordinate determination module includes:
[0229] A transition position submodule is used to obtain the transition position of the fluid particle according to the velocity of the fluid particle in the next frame, the time difference between the current frame and the next frame, and the three-dimensional coordinates of the fluid particle in the current frame;
[0230] A transition grid submodule is used to determine the grid where the transition position of the fluid particles is located as the transition grid;
[0231] A transition speed submodule is used to obtain the transition speed of the fluid particles at the transition position according to the coordinates and speeds of the transition grid and the adjacent grids adjacent to the transition grid on the extension lines of the three coordinate axes;
[0232] The coordinate determination submodule is used to obtain the three-dimensional coordinates of the fluid particles in the next frame according to the transition speed of the fluid particles, the time step and the three-dimensional coordinates of the fluid in the current frame.
[0233] Based on the above embodiments, as an optional embodiment, the transition speed submodule includes:
[0234] The adjacent grid determination unit is used to take each axis of the coordinate system where the three-dimensional virtual space is located as a target axis, determine the adjacent grids adjacent to the transition grid on the extension line of the target axis, and determine the target surface of the transition grid and the adjacent grid perpendicular to the target axis;
[0235] The surface center point speed determination unit is used to obtain the speed of the first center point of the target surface of the transition mesh according to the speeds of all meshes that the mesh vertices of the target surface of the transition mesh touch in the next frame; and obtain the speed of the second center point of the target surface of the adjacent mesh according to the speeds of all meshes that the mesh vertices of the target surface of the adjacent mesh touch in the next frame;
[0236] The transition speed determination unit is used to obtain the component of the transition speed on the target axis based on the coordinates of the adjacent grids, the transition position, the components of the coordinates of the transition grids on the target axis, and the components of the speeds of the first center point and the second center point on the coordinate axis, and obtain the transition speed based on the components of the transition speed on all coordinate axes.
[0237] An electronic device is provided in an embodiment of the present disclosure, and the electronic device includes: a memory and a processor; at least one program, which is stored in the memory and is used for, when executed by the processor, to grid a three-dimensional virtual space displaying a three-dimensional fluid, obtain a grid set, obtain the three-dimensional coordinates and speed of each fluid particle in the three-dimensional fluid in the current frame, so as to determine the grid where each fluid particle is located in the current frame; for each grid in the grid set, according to the speed of the fluid particles in the grid and in the surrounding grids within a preset range in the current frame, obtain the speed of the grid in the current frame; adjust the speed of the grid in the current frame according to a preset acceleration to obtain the adjusted speed of the grid, and obtain the speed of the grid in the next frame according to the adjusted speed of the grid, the positional relationship between the grid and a preset container wall in the three-dimensional virtual space, and the preset rebound speed; obtain the speed of the fluid particles in the next frame according to the speed of the grid in the next frame and the speed of the fluid particles in the grid in the current frame, and obtain the three-dimensional coordinates of the fluid particles in the next frame according to the speed of the fluid particles in the next frame and the three-dimensional coordinates in the current frame; and display the three-dimensional fluid of the next frame in the three-dimensional virtual space according to the three-dimensional coordinates of all fluid particles in the three-dimensional fluid in the next frame. Compared with the existing technology, the following can be achieved: using the grid to assist the motion simulation calculation of particles, which can better handle the influence of acceleration and fluid pressure on fluid motion, and has less additional overhead. In addition, using the velocity change of the grid to update the particle velocity, rather than directly converting the grid velocity to the particle velocity, can reduce the numerical dissipation caused by converting the particle velocity to the grid and then back to the particle, and by considering the positional relationship between the grid and the container wall in the three-dimensional virtual space and the rebound velocity, it can show a more realistic and natural fluid collision effect.
[0238] In an alternative embodiment, an electronic device is provided, such as Figure 8 As shown, Figure 8 The electronic device 600 shown includes: a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 606 or a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0239] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 606 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 8 The electronic device 600 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0240] The disclosed embodiments provide a computer-readable storage medium having a computer program stored thereon, which, when executed on a computer, enables the computer to execute the corresponding contents of the aforementioned method embodiments. Compared with the prior art, the use of a grid to assist in the motion simulation calculation of particles can better handle the effects of acceleration and fluid pressure on fluid motion, and has less additional overhead. In addition, the use of the velocity change of the grid to update the particle velocity, rather than directly converting the grid velocity to the particle velocity, can reduce the numerical dissipation caused by converting the particle velocity to the grid and then back to the particle, and by considering the positional relationship between the grid and the container wall in the three-dimensional virtual space and the rebound velocity, a more realistic and natural fluid collision effect can be displayed.
[0241] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer program product. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transient computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program product can be downloaded and installed from the network through a communication device 609, or installed from a storage device 606, or installed from a ROM 602. When the computer program product is executed by a processing device 601, the above-mentioned functions defined in the method for displaying the fluid collision effect of the embodiment of the present disclosure are executed. Compared with the prior art, the use of a grid to assist the motion simulation calculation of particles can better handle the effects of acceleration and fluid pressure on fluid motion, and the additional overhead is small. In addition, the particle velocity is updated using the velocity change of the grid, rather than directly converting the grid velocity to the particle velocity, which can reduce the numerical dissipation caused by the particle velocity being converted to the grid and then back to the particle, and by considering the positional relationship between the grid and the container wall in the three-dimensional virtual space and the rebound velocity, a more realistic and natural fluid collision effect can be displayed.
[0242] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0243] The above are only some embodiments of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for displaying fluid collision effects, characterized in that: include: Performing grid processing on the three-dimensional virtual space displaying the three-dimensional fluid to obtain a grid set, obtaining the three-dimensional coordinates and velocity of each fluid particle in the three-dimensional fluid in the current frame, so as to determine the grid where each fluid particle is located in the current frame; For each grid in the grid set, obtaining a speed of the grid in the current frame according to the speed of fluid particles in the grid and in surrounding grids within a preset range in the current frame; adjusting the speed of the grid in the current frame according to a preset acceleration to obtain the adjusted speed of the grid, and obtaining the speed of the grid in the next frame according to the adjusted speed of the grid, a positional relationship between the grid and a preset container wall in the three-dimensional virtual space, and a preset rebound speed; According to the velocity variation of the grid and the velocity of the fluid particles in the grid in the current frame, the particle velocity is updated using the velocity variation of the grid to obtain the velocity of the fluid particles in the next frame, and according to the velocity of the fluid particles in the next frame and the three-dimensional coordinates in the current frame, the three-dimensional coordinates of the fluid particles in the next frame are obtained; According to the three-dimensional coordinates of all fluid particles in the three-dimensional fluid in the next frame, the three-dimensional fluid of the next frame is displayed in the three-dimensional virtual space; wherein, The obtaining the speed of the grid in the next frame according to the adjusted speed of the grid, the positional relationship between the grid and the preset container wall in the three-dimensional virtual space, and the preset rebound speed includes: Taking any coordinate axis in the coordinate system of the three-dimensional virtual space as a target axis, taking a grid adjacent to the grid in the positive direction of the target axis as a first reference grid, and taking a grid adjacent to the grid in the negative direction of the target axis as a second reference grid; Taking the adjusted speed as a first speed, updating the first speed according to the positional relationship between the grid, the first reference grid, the second reference grid and the container wall, and obtaining a second speed of the grid; Solving the pressure field of the three-dimensional fluid according to the second velocity to obtain a third velocity of the grid; The third speed is updated according to the positional relationship between the grid, the first reference grid, the second reference grid and the container wall and a preset rebound speed to obtain the speed of the grid in the next frame.
2. The method for displaying fluid collision effect according to claim 1, characterized in that: The updating of the first speed according to the positional relationship between the grid, the first reference grid, the second reference grid and the container wall to obtain the second speed of the grid includes: According to whether a line connecting the grid and the first reference grid intersects the container wall, updating a component of the first velocity on the target axis to obtain a component of the first reference velocity on the target axis; According to whether a line connecting the grid and the second reference grid intersects the container wall, the component of the first reference velocity on the target axis is updated to obtain the component of the second velocity on the target axis.
3. The method for displaying fluid collision effect according to claim 2, characterized in that: The updating of the component of the first speed on the target axis according to whether the line connecting the grid and the first reference grid intersects the container wall, and obtaining the component of the first reference speed on the target axis, comprises: If the line connecting the grid and the first reference grid does not intersect the container wall, the component of the first velocity on the target axis is used as the component of the first reference velocity on the target axis; If the line connecting the grid and the first reference grid intersects the container wall, the smaller value between the component of the first speed on the target axis and the component of the preset speed threshold on the target axis is used as the component of the first reference speed on the target axis.
4. The method for displaying fluid collision effect according to claim 2, characterized in that: The updating of the component of the first reference velocity on the target axis according to whether the line connecting the mesh vertex and the second reference mesh vertex intersects the container wall, and obtaining the component of the second velocity on the target axis, comprises: If the line connecting the grid and the second reference grid does not intersect the container wall, the component of the first reference velocity on the target axis is used as the component of the second velocity on the target axis; If the line connecting the grid and the second reference grid intersects the container wall, the larger value between the component of the first reference speed updated on the target axis and the component of the preset speed threshold on the target axis is used as the component of the second speed on the target axis.
5. The method for displaying fluid collision effect according to claim 1, characterized in that: The updating of the third speed according to the positional relationship between the grid, the first reference grid, the second reference grid and the container wall and a preset rebound speed to obtain the speed of the grid in the next frame includes: According to a preset rebound speed and whether a line connecting the grid and the first reference grid intersects with the container wall, updating a component of the third speed on the target axis to obtain a component of the second reference speed on the target axis; According to the preset rebound speed and whether the line connecting the grid and the second reference grid intersects with the container wall, the component of the second reference speed on the target axis is updated to obtain the component of the speed of the grid on the target axis in the next frame.
6. The method for displaying fluid collision effect according to claim 5, characterized in that: The updating of the component of the second reference speed on the target axis according to the preset rebound speed and whether the line connecting the grid and the first reference grid intersects with the container wall, and obtaining the component of the second reference speed on the target axis includes: If the line connecting the grid and the first reference grid does not intersect the container wall, the component of the third velocity on the target axis is used as the component of the second reference velocity on the target axis; If the line connecting the grid and the first reference grid intersects the container wall, the smaller value between the component of the third velocity on the target axis and the negative value of the component of the rebound velocity on the target axis is used as the component of the second reference velocity on the target axis.
7. The method for displaying fluid collision effect according to claim 5, characterized in that: The updating of the component of the second reference speed on the target axis according to the preset rebound speed and whether the line connecting the grid and the second reference grid intersects with the container wall, and obtaining the component of the speed of the grid on the target axis in the next frame, comprises: If the line connecting the grid and the second reference grid does not intersect the container wall, the component of the second reference velocity on the target axis is used as the component of the velocity of the grid vertex on the target axis in the next frame; If the line connecting the mesh and the second reference mesh intersects the container wall, a larger value between the component of the third velocity on the target axis and the component of the rebound velocity on the target axis is used as the component of the velocity of the mesh vertex on the target axis in the next frame.
8. The method for displaying fluid collision effect according to claim 1, characterized in that: The obtaining of the speed of the grid in the next frame further comprises: If the component of the speed of the grid in the next frame on any axis of the coordinate system where the three-dimensional virtual space is located is greater than a preset value, the component on any axis is updated to the preset value.
9. The method for displaying fluid collision effect according to claim 1, characterized in that: The obtaining the speed of the grid in the current frame according to the speed of the fluid particles in the grid and the surrounding grids within the preset range in the current frame comprises: Take each mesh as a base mesh, and for each base mesh, do the following: Taking the fluid particles inside each of the base grids and the surrounding grids within a preset range as reference fluid particles, and determining the relative position of the reference fluid particles and the corresponding target grid; Obtaining a weight of the reference fluid particle relative to the corresponding target grid according to the relative position; Obtaining a weighted value of the velocity of the reference fluid particle relative to the corresponding target grid according to the velocity of the reference fluid particle in the current frame and the weight of the reference fluid particle relative to the corresponding target grid; The speed of the base grid in the current frame is obtained according to the sum of the weighted values of the speeds of all reference fluid particles relative to the corresponding target grid and the sum of the weights of all reference fluid particles relative to the corresponding target grid.
10. The method for displaying fluid collision effect according to claim 9, characterized in that: For each base grid, when the reference fluid particle corresponding to the base grid is located in the base grid or the grid where it is located is on the same horizontal plane as the base grid, the target grid corresponding to the reference fluid particle is the grid where the reference fluid particle is located; when the grid where the reference fluid particle is located is on different horizontal planes from the base grid, the target grid corresponding to the reference fluid particle is the base grid.
11. The method for displaying three-dimensional fluid according to claim 9, characterized in that: The step of obtaining the weight of the reference fluid particle for the corresponding target grid according to the relative position includes: Taking each axis of the coordinate system where the three-dimensional virtual space is located as a target axis, taking a surface in the corresponding target grid that is perpendicular to the target axis direction as a target surface, and obtaining the projection lengths of the distance between the reference fluid particle and the midpoint of the target surface in the three-axis directions respectively; Compare the three differences between the projection lengths and the unit length respectively to obtain a first difference, a second difference and a third difference, take the larger number between the first difference and the preset value as a first parameter, take the larger number between the second difference and the preset value as a second parameter, and take the larger number between the third difference and the preset value as a third parameter; The component of the weight of the reference fluid particle to the grid in which it is located on the target axis is obtained according to the product of the first parameter, the second parameter and the third parameter, and the weight of the reference fluid particle to the corresponding target grid is obtained according to the component.
12. The method for displaying three-dimensional fluid according to claim 1, characterized in that: The step of solving the pressure field of the three-dimensional fluid according to the second velocity to obtain a third velocity of the grid includes: Obtaining the divergence of the grid according to the second speed of each grid; Performing Jacobi iteration according to the divergence of the grid to obtain the pressure field gradient of the grid; A third velocity of the grid is obtained according to the difference between the second velocity of the grid and the pressure field gradient.
13. The method for displaying three-dimensional fluid according to claim 1, characterized in that: The step of obtaining the three-dimensional coordinates of the fluid particles in the next frame according to the speed of the fluid particles in the next frame and the three-dimensional coordinates in the current frame comprises: Obtaining a transition position of the fluid particle according to the velocity of the fluid particle in the next frame, the time difference between the current frame and the next frame, and the three-dimensional coordinates of the fluid particle in the current frame; Determine a grid where the transition position of the fluid particle is located as a transition grid; Obtaining a transition velocity of the fluid particle at the transition position according to the coordinates and velocities of the transition grid and adjacent grids of the transition grid on the extension lines of the three coordinate axes; The three-dimensional coordinates of the fluid particles in the next frame are obtained according to the transition speed of the fluid particles, the time step, and the three-dimensional coordinates of the fluid in the current frame.
14. The method for displaying three-dimensional fluid according to claim 13, characterized in that: The step of obtaining the transition speed of the fluid particle at the transition position according to the coordinates and speeds of the transition grid and adjacent grids of the transition grid on the extension lines of the three coordinate axes comprises: Taking each axis of the coordinate system where the three-dimensional virtual space is located as a target axis, determining adjacent grids of the transition grid on the extension line of the target axis, and determining a target surface of the transition grid and the adjacent grids perpendicular to the target axis; According to the speeds of all meshes that the mesh vertices of the target surface of the transition mesh contact in the next frame, the speed of the first center point of the target surface of the transition mesh is obtained; according to the speeds of all meshes that the mesh vertices of the target surface of the adjacent mesh contact in the next frame, the speed of the second center point of the target surface of the adjacent mesh is obtained; The component of the transition speed on the target axis is obtained according to the coordinates of the adjacent grids, the transition position, the components of the coordinates of the transition grid on the target axis, and the components of the speeds of the first center point and the second center point on the target axis, and the transition speed is obtained according to the components of the transition speed on all coordinate axes.
15. A device for displaying fluid collision effects, characterized in that: include: A grid processing module is used to perform grid processing on the three-dimensional virtual space displaying the three-dimensional fluid, obtain a grid set, obtain the three-dimensional coordinates and velocity of each fluid particle in the three-dimensional fluid in the current frame, and determine the grid where each fluid particle is located in the current frame; A grid speed module, for obtaining, for each grid in the grid set, a speed of the grid in the current frame according to the speed of fluid particles in the grid and in surrounding grids within a preset range in the current frame; A mesh speed update module, used to adjust the speed of the mesh in the current frame according to a preset acceleration to obtain the adjusted speed of the mesh, and obtain the speed of the mesh in the next frame according to the adjusted speed of the mesh, the positional relationship between the mesh and a preset container wall in the three-dimensional virtual space, and a preset rebound speed; a particle coordinate determination module, for updating the particle velocity using the velocity variation of the grid according to the velocity variation of the grid and the velocity of the fluid particles in the grid in the current frame, obtaining the velocity of the fluid particles in the next frame, and obtaining the three-dimensional coordinates of the fluid particles in the next frame according to the velocity of the fluid particles in the next frame and the three-dimensional coordinates in the current frame; A display module, used for displaying the next frame of the three-dimensional fluid in the three-dimensional virtual space according to the three-dimensional coordinates of all fluid particles in the three-dimensional fluid in the next frame; The grid speed updating module is further used to use any coordinate axis in the coordinate system where the three-dimensional virtual space is located as a target axis, use a grid adjacent to the grid in the positive direction of the target axis as a first reference grid, and use a grid adjacent to the grid in the negative direction of the target axis as a second reference grid; Taking the adjusted speed as a first speed, updating the first speed according to the positional relationship between the grid, the first reference grid, the second reference grid and the container wall, and obtaining a second speed of the grid; Solving the pressure field of the three-dimensional fluid according to the second velocity to obtain a third velocity of the grid; The third speed is updated according to the positional relationship between the grid, the first reference grid, the second reference grid and the container wall and a preset rebound speed to obtain the speed of the grid in the next frame.
16. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the method for displaying the fluid collision effect as claimed in any one of claims 1 to 14 are implemented.
17. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute the steps of the method for displaying fluid collision effects according to any one of claims 1 to 14.
18. A computer program, characterized in that The computer program includes computer instructions, which are stored in a computer-readable storage medium. When a processor of a computer device reads the computer instructions from the computer-readable storage medium, the processor executes the computer instructions, so that the computer device executes the steps of the method for displaying fluid collision effects as described in any one of claims 1-14.
Citation Information
Patent Citations
Fluid animation processing method and device, electronic equipment and storage medium
CN114299199A
Device for simulating impact erosion coupling wear of underground abrasive particles
CN117074228A
Computer system for simulating physical process using lattice boltzmann based scalar transport enforcing galilean invariance for scalar transport
EP3816842A1
High quality high resolution 3-d medical imaging using ultrasound
WO2024095273A1