Three-dimensional fluid display method, device, electronic device and storage medium
By meshing the three-dimensional virtual environment and combining the motion simulation of fluid particles, the problems of high intensity and low accuracy of fluid simulation calculation in the prior art are solved, and more efficient and accurate fluid motion simulation is achieved.
Patent Information
- Application Number
- CN202110183976.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-10
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2041-02-10
AI Technical Summary
The prior art uses high computational intensity and difficult to realistically simulate the effects of bounded space when simulating fluid behavior, especially in the simulation of diffusion, turbulence and surface tension. The particle-based fluid simulation method has problems of low calculation accuracy of boundary particles and unstable tension.
By meshing the three-dimensional virtual environment, using grid-assisted particles to calculate the motion simulation of grid-assisted particles, the impact of external forces and fluid pressure on fluid movement is handled. Specific steps include: grid processing, obtaining the three-dimensional coordinates and velocity of the fluid particles, updating the mesh and particle velocity, calculating the new position of the fluid particles, and displaying the fluid in a three-dimensional virtual environment.
This method can better deal with complex phenomena in fluid movement, reduce numerical dissipation, and improve the efficiency and accuracy of fluid simulation.
Smart Images

Figure CN114912303B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of fluid simulation, and in particular to a method, device, electronic device and storage medium for displaying three-dimensional fluid. 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 simulation method and fluid particle-based fluid simulation method.
[0004] The network-based fluid simulation 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] The model used in particle-based fluid simulation methods 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 simulation method is the smooth particle fluid dynamics method, which has inherent defects such as low boundary particle calculation accuracy and unstable tension. Summary of the invention
[0006] The embodiments of the present disclosure provide a method, device, electronic device and storage medium for displaying three-dimensional fluids that overcome the above-mentioned problems or at least partially solve the above-mentioned problems.
[0007] In a first aspect, a method for displaying a three-dimensional fluid is provided, the method comprising:
[0008] Performing grid processing on a three-dimensional virtual environment displaying a three-dimensional fluid to obtain a grid set;
[0009] 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;
[0010] For each grid, the speed of each grid in the current frame is obtained according to the speed of the fluid particles in each grid and the surrounding grids within a preset range in the current frame;
[0011] Add the acceleration in the preset direction to the speed of each grid in the current frame to obtain the speed of each grid in the next frame;
[0012] According to the speed change of each grid from the current frame to the next frame, the speed of the fluid particles in each grid is updated to obtain the speed of the fluid particles in the next frame;
[0013] 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;
[0014] 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.
[0015] In a second aspect, a three-dimensional fluid display device is provided, comprising:
[0016] A gridding module, used for gridding a three-dimensional virtual environment showing a three-dimensional fluid to obtain a grid set;
[0017] The basic data acquisition module is used to 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;
[0018] A grid speed acquisition module is used to obtain the speed of each grid in the current frame according to the speed of the fluid particles in each grid and the surrounding grids within a preset range in the current frame.
[0019] A grid speed update module is used to increase the acceleration in a preset direction to the speed of each grid in the current frame to obtain the speed of each grid in the next frame;
[0020] The particle speed update module is used to update the speed of the fluid particles in each grid according to the speed change of each grid from the current frame to the next frame, and obtain the speed of the fluid particles in the next frame;
[0021] A fluid position updating module, used 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;
[0022] The display module is used to display the three-dimensional fluid of the next frame in the three-dimensional virtual environment according to the three-dimensional coordinates of all fluid particles in the next frame.
[0023] In a third aspect, an embodiment of the present disclosure provides an electronic device, including 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.
[0024] In a fourth aspect, an embodiment of the present disclosure 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.
[0025] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, which includes computer instructions, and when the computer instructions are executed by a processor, the method provided in the first aspect is implemented.
[0026] The three-dimensional fluid display method, device, electronic device and storage medium provided by the embodiments of the present disclosure use a grid to assist in the motion simulation calculation of particles, which can better handle the influence of external forces and fluid pressure on fluid motion, and has 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 into the grid velocity and then into the particle velocity. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] 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.
[0028] Figure 1 A schematic flow chart of a three-dimensional fluid display method provided in an embodiment of the present disclosure;
[0029] Figure 2 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;
[0030] Figure 3 A position relationship diagram of a basic grid and surrounding grids provided in an embodiment of the present disclosure;
[0031] Figure 4 A flow chart for calculating grid divergence provided in an embodiment of the present disclosure;
[0032] Figure 5 A schematic diagram of the positional relationship between a transition grid and an adjacent grid provided in an embodiment of the present disclosure;
[0033] Figure 6 A schematic structural diagram of a three-dimensional fluid display device provided in an embodiment of the present disclosure;
[0034] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0035] 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 disclosure.
[0036] 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.
[0037] 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.
[0038] The three-dimensional fluid display method, device, electronic device and computer-readable storage medium provided in the present disclosure are intended to solve the above technical problems in the prior art.
[0039] 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.
[0040] The present disclosure provides a method for simulating a three-dimensional fluid. Figure 1 As shown, the method includes:
[0041] S101, gridding a three-dimensional virtual environment displaying a three-dimensional fluid to obtain a grid set.
[0042] It should be understood that the three-dimensional fluid is displayed in a preset three-dimensional virtual environment. The display method of the three-dimensional fluid disclosed in the present invention first performs grid processing on the three-dimensional virtual environment, that is, the three-dimensional space is divided into a plurality of grids of a cubic structure to obtain a grid set. Such an operation can lay the foundation for the subsequent conversion of the particle velocity into the grid velocity. The grid in the present disclosure is a hexahedral grid, and the two faces perpendicular to the Z axis in the grid 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 grid has a total of 12 edges and 8 vertices, and accordingly, each edge contacts 4 hexahedral grids, and each vertex contacts 8 hexahedrons.
[0043] After the three-dimensional virtual environment is divided into grids, 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.
[0044] S102, obtaining the three-dimensional coordinates and velocity of each fluid particle in the three-dimensional fluid in the current frame, and determining the grid where each fluid particle is located.
[0045] 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. Of course, the three-dimensional coordinates and speed of each frame of the three-dimensional fluid can also 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). Considering that if the speed of the fluid particles is updated directly, 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 space, a large number of fluid particles are represented by a small number of grids. By updating the speed of the grid, the computational overhead can be greatly reduced. More importantly, when considering the influence of fluid pressure on the movement of the fluid, it is more accurate to use the speed of the grid than to use the particle speed for calculation.
[0046] S103 . For each grid, obtain the speed of each grid in the current frame according to the speed of the fluid particles in each grid and in the surrounding grids within a preset range in the current frame.
[0047] 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.
[0048] 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 three-dimensional space rather than in a two-dimensional plane.
[0049] 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 ), the surrounding grids within the preset range include the grids of the following coordinates: (c X ,c Y ,c Z )、(cX +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.
[0050] S104: Add an acceleration in a preset direction to the speed of each grid in the current frame to obtain the speed of each grid in the next frame.
[0051] 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 environment.
[0052] S105 , updating the speed of the fluid particles in each grid according to the speed change of each grid from the current frame to the next frame, and obtaining the speed of the fluid particles in the next frame.
[0053] The present disclosure discovers that the speed change of the grid can reflect the speed change of the particles in the grid. Therefore, the speed change of the grid vertices from the current frame to the next 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.
[0054] By using the velocity of the grid to update the velocity of the fluid particles, the foundation is laid for subsequently determining the three-dimensional coordinates of the fluid particles in the next frame.
[0055] S106 . 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.
[0056] 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 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] S107 . Display the three-dimensional fluid of the next frame in the three-dimensional virtual environment according to the three-dimensional coordinates of all fluid particles 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 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 space.
[0059] The three-dimensional fluid display method provided by the present disclosure uses a grid to assist in the motion simulation calculation of particles, which can better handle the influence of external forces and fluid pressure on fluid motion, and has 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 into the grid velocity and then into the particle velocity.
[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 realize the method of displaying three-dimensional fluid using only GPU, based on the above embodiments, as an optional embodiment, the three-dimensional coordinates of the fluid particles in the next frame are obtained, and then the following is further included:
[0062] S108. Map the fluid particles to the first two-dimensional texture image and the second two-dimensional texture image of the next frame according to the three-dimensional coordinates of the fluid particles in the next frame, and 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.
[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 space in the Z-axis direction.
[0064] For example, if the size of the three-dimensional space is 3*4*5, it can be known that the width of the three-dimensional space in the Z-axis direction is 5. If the three-dimensional coordinates of a fluid particle in the next frame are (1,2,3), then the horizontal coordinate of the fluid particle mapped to the two-dimensional texture image is 1+5*3=16, and the vertical coordinate is 2, that is, the two-dimensional coordinate of the fluid particle in the two-dimensional texture image is (16,2). Through the above method, the three-dimensional coordinates of all fluid particles can be mapped to the two-dimensional texture image. It can be further known that the size of the two-dimensional texture image is 28*4.
[0065] S109, converting the three-dimensional coordinates of the fluid particles in the next frame into the RGB values of the corresponding pixels of the fluid particles in the first two-dimensional texture image of the next frame; converting the speed of the fluid particles in the next frame into the RGB values of the corresponding pixels of the fluid particles in the second two-dimensional texture image of the next frame.
[0066] 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.
[0067] 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.
[0068] 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:
[0069] Get the first two-dimensional texture image and the second two-dimensional texture image of the current frame;
[0070] 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;
[0071] 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.
[0072] 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.
[0073] 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 three-dimensional 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 three-dimensional space and two-dimensional space.
[0074] See also Figure 2 , 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 space, but after being mapped to the two-dimensional texture image, grids 1 and 5 are separated by grid 2.
[0075] Based on this, the embodiment of the present disclosure obtains the speed of each grid in the current frame according to the speed of the fluid particles in each grid and the surrounding grids within a preset range in the current frame, including:
[0076] Take each mesh as a base mesh, and for each base mesh, do the following:
[0077] S201, taking the fluid particles inside each basic grid 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.
[0078] 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.
[0079] After determining the reference fluid particles, the target grid corresponding to the reference fluid particles is further determined. The present disclosure sets two target grid determination methods according to whether the grid where the reference fluid particles are located is in the same plane as the base grid. For each base grid:
[0080] (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;
[0081] (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.
[0082] See also Figure 3 , 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 the basic grid, grid 2 and grid 3 are both surrounding grids of basic grid 1, 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.
[0083] According to the above rules, for a reference fluid particle in the basic grid 1, the target grid of the reference fluid particle is the grid where it is located, that is, the basic grid 1;
[0084] 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;
[0085] For a grid in a different plane from grid 1 , the target grid of the reference fluid particles in the grid is reference grid 1 , for example, the target grid of the reference fluid particles in grid 3 is grid 1 .
[0086] 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).
[0087] S202. Obtain the weight of the reference fluid particle relative to the corresponding target grid according to the relative position.
[0088] 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.
[0089] S203. 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.
[0090] 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.
[0091] 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.
[0092] 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.
[0093] 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.
[0094] S204. 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.
[0095] 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.
[0096] The present invention determines the weights of reference fluid particles and corresponding target grids according to the relative positions of reference fluid particles and corresponding target grids, uses the weights to weight the speed of the reference fluid particles in the current frame, obtains the 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 whole 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 three-dimensional space.
[0097] 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:
[0098] S301, taking each axis of the coordinate system of the three-dimensional virtual environment as a target axis, taking a surface perpendicular to the target axis in the corresponding target grid as a target surface, and obtaining the projection length of the distance between the reference fluid particle and the midpoint of the target surface in the three-axis directions.
[0099] 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.
[0100] 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.
[0101] 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.
[0102] 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 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.
[0103] S302, 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;
[0104] S303, obtaining 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 obtaining the weight of the reference fluid particle for the corresponding target grid according to the component.
[0105] 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.
[0106] Step S202 of the present disclosure can also be calculated based on the following formula:
[0107] w=(k(PC X ),k(PC Y ),k(PC Z ));
[0108] k(u)=h(u x)·h(u y )·h(u z );
[0109] h(x) = max{0, 1-|x|};
[0110] 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.
[0111] For example, if the particle position is P(p X ,p Y ,p Z ), the three-dimensional coordinates of the target 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 );
[0112] k(PC X ) as an example, k(PC X )=h(p X -c X )*h(p Y -cY -0.5)*h(p Z -c Z -0.5);
[0113] h(p X -c X )=max{0,1-|p X -c X |};
[0114] h(p Y -c Y -0.5)=max{0,1-|p Y -c Y -0.5|};
[0115] h(p Z -c Z )=max{0,1-|p Z -c Z -0.5|}.
[0116] 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 weighted value of the speed 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 weighted values of the speeds 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.
[0117] Based on the above embodiments, as an optional embodiment, step S104 further includes:
[0118] S401, adding an acceleration in a preset direction to the velocity of each grid in the current frame to obtain an initial velocity of each grid in the next frame.
[0119] For example, define the velocity of the grid in the current frame as v t , the acceleration of the external force is a, and the time step is dt, then the initial velocity v of the next frame grid t+1 It can be expressed as v t+1 =v t +a*dt.
[0120] Furthermore, the present disclosure can set a speed threshold, so that after calculating the initial speed of each frame, the calculated initial speed is compared with the speed threshold, and the smaller value of the two is used as the initial speed of the next frame grid. By setting the speed threshold, the overall movement of the simulated three-dimensional fluid can be made smoother and less abrupt, and the simulation effect is higher.
[0121] S402: Obtain the divergence of each grid according to the initial velocity of each grid in the next frame.
[0122] 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.
[0123] S403, performing Jacobi iteration according to the divergence of the grid to obtain the pressure field gradient of the grid.
[0124] Specifically, 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.
[0125] Furthermore, in the present disclosure, for a grid without fluid particles, the pressure is always set to 0.
[0126] 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.
[0127] S404. Obtain the velocity of the grid in the next frame according to the initial velocity and pressure field gradient of the grid in the next frame.
[0128] Specifically, the present disclosure subtracts the pressure field gradient from the initial velocity of the grid in the next frame to obtain the velocity of the grid in the next frame.
[0129] After calculating the initial velocity, the present invention further calculates the pressure field gradient of the grid, and uses the difference between the initial velocity and the pressure field gradient to obtain the velocity of the grid in the next frame, which can prevent the fluid from being too aggregated after external force is applied, and the simulation effect is more realistic.
[0130] Based on the above embodiments, as an optional embodiment, step S402 includes:
[0131] S501 . For each mesh vertex, obtain the initial velocity of the mesh vertex in the next frame according to the initial velocities of all meshes that the mesh vertex contacts in the next frame.
[0132] Specifically, since each mesh vertex contacts 8 meshes, the average of the initial velocities of the contacting 8 meshes in the next frame is used as the initial velocity of the mesh vertex in the next frame.
[0133] S502 : For each face of the mesh, take the average value of the initial velocities of all mesh vertices of each face in the next frame as the velocity of each face.
[0134] After determining the velocity of each mesh vertex, considering that each face has 4 mesh vertices, the average of the initial velocities of the 4 mesh vertices in the next frame can be used as the velocity of each face.
[0135] S503. 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.
[0136] See also Figure 4 , 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.
[0137] 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.
[0138] 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:
[0139] S601 , 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.
[0140] 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, half of 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 purpose of the transition position 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 the time difference between the current frame and the next frame (for example, 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 intermediate 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.
[0141] S602, determining the grid where the transition position of the fluid particle is located as the transition grid.
[0142] S603 , obtaining a transition velocity of the fluid particle at the transition position according to the coordinates and velocities of the transition grid and the adjacent grids adjacent to the transition grid on the extension lines of the three coordinate axes.
[0143] 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.
[0144] Specifically, step S603 includes:
[0145] 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.
[0146] See also Figure 5, 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 transition grid G1 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 G1 in the X-axis direction, the adjacent grid L2 is located on the extension line of the transition grid G1 in the Y-axis direction, and the adjacent grid L3 is located on the extension line of the transition grid G1 in the Z-axis direction.
[0147] 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.
[0148] When calculating the speed of the center point of the target surface, the present disclosure first calculates the speed of the grid vertex and then takes the average of the speeds of the four grid 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 grid vertex is the average of the speeds of the 8 grids that the grid vertex contacts.
[0149] 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).
[0150] The coordinates of the adjacent grids of the transition grid in the direction of the Z-axis extension line 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).
[0151] 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.
[0152] 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:
[0153] First, a first weight is obtained according to a difference between the components of the three-dimensional coordinates of the adjacent 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 transition grid on the target axis;
[0154] 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.
[0155] 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 :
[0156] V z =(c3+1-P z )*v6+(P z -c3)*v3
[0157] 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.
[0158] 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 ).
[0159] 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.
[0160] 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.
[0161] 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.
[0162] According to the method for displaying three-dimensional fluids in the embodiment of the present disclosure, a grid is used to assist in the motion simulation calculation of particles, which can better handle the influence of external forces and fluid pressure on fluid motion, and has 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 velocity and then to the particle velocity.
[0163] The present disclosure provides a three-dimensional fluid display device, such as Figure 6 As shown, the device may include: a gridding module 101, a basic data acquisition module 102, a grid speed acquisition module 103, a grid speed update module 104, a particle speed update module 105, a fluid position update module 106 and a display module 107. Specifically:
[0164] A gridding module 101 is used to perform gridding processing on a three-dimensional virtual environment displaying a three-dimensional fluid to obtain a grid set;
[0165] The basic data acquisition module 102 is used to 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;
[0166] A grid speed acquisition module 103 is used to obtain the speed of each grid in the current frame according to the speed of the fluid particles in each grid and the surrounding grids within a preset range in the current frame.
[0167] A grid speed updating module 104 is used to increase the acceleration in a preset direction to the speed of each grid in the current frame to obtain the speed of each grid in the next frame;
[0168] The particle speed updating module 105 is used to update the speed of the fluid particles in each grid according to the speed change of each grid from the current frame to the next frame, and obtain the speed of the fluid particles in the next frame;
[0169] The fluid position updating module 106 is used 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;
[0170] The display module 107 is used to display the three-dimensional fluid of the next frame in the three-dimensional virtual environment according to the three-dimensional coordinates of all fluid particles in the next frame.
[0171] The three-dimensional fluid display device provided in the embodiment of the present disclosure specifically executes the above-mentioned method embodiment process. For details, please refer to the content of the above-mentioned three-dimensional fluid display method embodiment, which will not be repeated here. The three-dimensional fluid display device provided in the embodiment of the present disclosure uses a grid to assist in the motion simulation calculation of particles, which can better handle the effects of external forces 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 into the grid velocity and then into the particle velocity.
[0172] Based on the above embodiments, as an optional embodiment, the basic data acquisition module includes:
[0173] A texture image acquisition unit is used to acquire a first two-dimensional texture image and a second two-dimensional texture image of a current frame, wherein the pixels in the first two-dimensional texture image and the second two-dimensional texture image are mappings of fluid particles of a three-dimensional fluid in the first two-dimensional texture image and the second two-dimensional texture image, and the RGB values of the pixels in the first two-dimensional texture image and the second two-dimensional texture image are respectively used to represent the three-dimensional coordinates and speeds of the corresponding fluid particles in the current frame;
[0174] A coordinate acquisition unit, for determining, for each pixel point in the first two-dimensional texture image, 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;
[0175] The speed acquisition unit is used to determine the speed of the fluid particle corresponding to each pixel point in the second two-dimensional texture image according to the RGB value in the pixel point in the current frame.
[0176] Based on the above embodiments, as an optional embodiment, the display device further includes:
[0177] A mapping module, used to map the fluid particles to the first two-dimensional texture image and the second two-dimensional texture image of the next frame according to the three-dimensional coordinates of the fluid particles in the next frame, and obtain the corresponding pixel points of the fluid particles in the first two-dimensional texture image and the second two-dimensional texture image of the next frame;
[0178] A coordinate marking module, used for converting the three-dimensional coordinates of the fluid particles in the next frame into RGB values of the corresponding pixels of the fluid particles in the first two-dimensional texture image of the next frame;
[0179] The speed marking module is used to convert the speed of the fluid particle in the next frame into the RGB value of the pixel point corresponding to the fluid particle in the second two-dimensional texture image in the next frame.
[0180] Based on the above embodiments, as an optional embodiment, the grid speed acquisition module includes:
[0181] 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;
[0182] 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;
[0183] 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;
[0184] 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 speed 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.
[0185] When the reference fluid particles corresponding to the base grid are located in the base grid or the grid where they are located is at the same level as the base grid, the target grid corresponding to the reference fluid particles is the grid where the reference fluid particles are located. When the grid where the reference fluid particles are located is at different levels from the base grid, the target grid corresponding to the reference fluid particles is the base grid.
[0186] Based on the above embodiments, as an optional embodiment, the weight acquisition submodule includes:
[0187] A projection unit is used to take each axis of the coordinate system of the three-dimensional virtual environment 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;
[0188] 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;
[0189] The weight calculation unit is used to obtain the component of the weight of the reference fluid particle to 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 to the corresponding target grid according to the component.
[0190] Based on the above embodiments, as an optional embodiment, the grid speed update module includes:
[0191] An initial speed calculation unit, used to increase the acceleration in a preset direction to the speed of each grid in the current frame to obtain the initial speed of each grid in the next frame;
[0192] A divergence calculation unit, used for obtaining the divergence of the grid according to the initial velocity of each grid in the next frame;
[0193] The pressure field calculation unit is used to perform Jacobi iteration according to the divergence of the grid to obtain the pressure field gradient of the grid;
[0194] The grid speed update unit is used to obtain the speed of the grid in the next frame according to the initial speed and pressure field gradient of the grid in the next frame.
[0195] Based on the above embodiments, as an optional embodiment, each grid includes a hexahedral grid;
[0196] The divergence calculation unit includes:
[0197] The vertex initial velocity calculation subunit is used to obtain the initial velocity of the mesh vertex in the next frame for each mesh vertex according to the initial velocities of all meshes that the mesh vertex contacts in the next frame;
[0198] The surface velocity calculation subunit is used to calculate the average value of the initial velocities of all mesh vertices of each surface in the next frame as the velocity of each surface for each surface of the mesh;
[0199] The divergence determination subunit is used to obtain the speed difference of any two opposite surfaces in the grid 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.
[0200] Based on the above embodiments, as an optional embodiment, the fluid position updating module includes:
[0201] 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;
[0202] A transition grid submodule is used to determine the grid where the transition position of the fluid particles is located as the transition grid;
[0203] 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;
[0204] 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.
[0205] Based on the above embodiments, as an optional embodiment, the transition speed submodule includes:
[0206] The adjacent grid determination unit is used to take each axis of the coordinate system of the three-dimensional virtual environment 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;
[0207] 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;
[0208] 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 target axis, and obtain the transition speed based on the components of the transition speed on all coordinate axes.
[0209] In an embodiment of the present disclosure, an electronic device is provided, which includes: a memory and a processor; at least one program stored in the memory, which is used to perform grid processing on a three-dimensional virtual environment displaying a three-dimensional fluid when executed by the processor to obtain a grid set; obtain the three-dimensional coordinates and speed of each fluid particle in the three-dimensional fluid in the current frame, and determine the grid where each fluid particle is located; for each grid, according to the speed of the fluid particles in each grid and the surrounding grids within a preset range in the current frame, obtain the speed of each grid in the current frame; increase the acceleration of the preset direction to the speed of each grid in the current frame to obtain the speed of each grid in the next frame; according to the speed change of each grid from the current frame to the next frame, update the speed of the fluid particles in each grid to obtain the speed 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, obtain the three-dimensional coordinates of the fluid particles in the next frame; according to the three-dimensional coordinates of all fluid particles in the next frame, display the three-dimensional fluid of the next frame in the three-dimensional virtual environment. Compared with the prior art, it can be achieved that: using grids to assist the motion simulation calculation of particles can better handle the influence of external forces and fluid pressure on fluid motion, and the additional cost is small. 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 into the grid velocity and then into the particle velocity.
[0210] In an alternative embodiment, an electronic device is provided, such as Figure 7 As shown, Figure 7 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.
[0211] 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 7The 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.
[0212] 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 external forces 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 into the grid velocity and then into the particle velocity.
[0213] 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-transitory computer-readable medium, and the computer program contains 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 the communication device 609, or installed from the storage device 606, or installed from the ROM 602. When the computer program product is executed by the processing device 601, the above-mentioned functions defined in the display method of the three-dimensional fluid of the embodiment of the present disclosure are executed.
[0214] 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.
[0215] The above are only some embodiments of the present disclosure. 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 disclosure. These improvements and modifications should also be regarded as the scope of protection of the present disclosure.
Claims
1. A method for displaying a three-dimensional fluid, characterized in that: include: Performing grid processing on a three-dimensional virtual environment displaying a 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, and determining the grid where each fluid particle is located; For each grid, according to the velocity of the fluid particles in the current frame inside each grid and in the surrounding grids within a preset range, the velocity of each grid in the current frame is obtained; Adding an acceleration in a preset direction to the speed of each grid in the current frame to obtain the speed of each grid in the next frame; The speed of each grid in the next frame is obtained by using the initial speed of each grid in the next frame and the pressure field gradient; the initial speed of each grid in the next frame is obtained by adding the acceleration in a preset direction to the speed of each grid in the current frame; the pressure field gradient is obtained by counting the pressure difference between each grid and another grid adjacent to it in the speed direction; According to the speed change of each grid from the current frame to the next frame, the speed of the fluid particles in each grid is updated to obtain the speed of the fluid particles in the next frame; 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 three-dimensional fluid of the next frame is displayed in the three-dimensional virtual environment according to the three-dimensional coordinates of all fluid particles in the next frame.
2. The method for displaying three-dimensional fluid according to claim 1, characterized in that: The obtaining of the three-dimensional coordinates and velocity of each fluid particle in the three-dimensional fluid in the current frame includes: Acquire a first two-dimensional texture image and a second two-dimensional texture image of a current frame, wherein the pixels in the first two-dimensional texture image and the second two-dimensional texture image are 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 pixels in the first two-dimensional texture image and the second two-dimensional texture image are respectively used to represent the three-dimensional coordinates and speeds of the corresponding fluid particles in the current frame; 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; 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.
3. The method for displaying a three-dimensional fluid according to claim 1 or 2, characterized in that: The step of obtaining the three-dimensional coordinates of the fluid particles in the next frame further includes: According to the three-dimensional coordinates of the fluid particles in the next frame, mapping the fluid particles to the first two-dimensional texture image and the second two-dimensional texture image of the next frame, and obtaining 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; Converting the three-dimensional coordinates of the fluid particles in the next frame into RGB values of pixels corresponding to the fluid particles in the first two-dimensional texture image of the next frame; The velocity of the fluid particle in the next frame is converted into the RGB value of the pixel point corresponding to the fluid particle in the second two-dimensional texture image of the next frame.
4. The method for displaying a three-dimensional fluid according to claim 1, characterized in that: According to the velocity of the fluid particles in each grid and the surrounding grids within the preset range in the current frame, the velocity of each grid in the current frame is obtained, including: Take each mesh as a base mesh, and for each base mesh, do the following: Taking the fluid particles inside each basic grid 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.
5. The method for displaying three-dimensional fluid according to claim 4, 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.
6. The method for displaying three-dimensional fluid according to claim 4, 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 of the three-dimensional virtual environment as a target axis, taking a surface in the corresponding target grid perpendicular to the target axis 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; Obtaining a 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; The weight of the reference fluid particle for the corresponding target grid is obtained according to the component.
7. The method for displaying three-dimensional fluid according to claim 1, characterized in that: The step of increasing the acceleration in a preset direction to the speed of each grid in the current frame to obtain the speed of each grid in the next frame includes: Obtaining the divergence of each grid according to the initial velocity of each grid in the next frame; Performing Jacobi iteration according to the divergence of the grid to obtain the pressure field gradient of the grid; The velocity of the grid in the next frame is obtained according to the initial velocity of the grid in the next frame and the pressure field gradient.
8. The method for displaying three-dimensional fluid according to claim 7, characterized in that: Each grid includes a hexahedral grid; The step of obtaining the divergence of each grid according to the initial velocity of each grid in the next frame comprises: For each mesh vertex, obtaining the initial velocity of the mesh vertex in the next frame according to the initial velocities of all meshes contacted by the mesh vertex in the next frame; For each face of the mesh, taking an average value of initial velocities of all mesh vertices of each face in the next frame as the velocity of each face; For any two opposite surfaces in the grid, obtaining a velocity difference between the two opposite surfaces according to the velocities of the two opposite surfaces; The divergence of the grid is obtained according to the sum of the velocity differences of all opposite surfaces of the grid.
9. 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.
10. The method for displaying three-dimensional fluid according to claim 9, 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 of the three-dimensional virtual environment 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; Obtaining the speed of the first center point of the target surface of the transition mesh according to the speeds of all meshes contacted by mesh vertices of the target surface of the transition mesh in the next frame; Obtaining the speed of the second center point of the target surface of the adjacent mesh according to the speeds of all meshes contacted by the mesh vertices of the target surface of the adjacent mesh in the next frame; 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.
11. A three-dimensional fluid display device, characterized in that: include: A gridding module, used for gridding a three-dimensional virtual environment showing a three-dimensional fluid to obtain a grid set; A basic data acquisition module, used to 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; A grid speed acquisition module, for obtaining, for each grid, the speed of each grid in the current frame according to the speed of fluid particles in each grid and surrounding grids within a preset range in the current frame; A grid speed updating module, used to increase the acceleration in a preset direction to the speed of each grid in the current frame, so as to obtain the speed of each grid in the next frame; The speed of each grid in the next frame is obtained by using the initial speed of each grid in the next frame and the pressure field gradient; the initial speed of each grid in the next frame is obtained by adding the acceleration in a preset direction to the speed of each grid in the current frame; the pressure field gradient is obtained by counting the pressure difference between each grid and another grid adjacent to it in the speed direction; A particle speed updating module, used for updating the speed of the fluid particles in each grid according to the speed change of each grid from the current frame to the next frame, so as to obtain the speed of the fluid particles in the next frame; A fluid position updating module, used for 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; The display module is used to display the three-dimensional fluid of the next frame in the three-dimensional virtual environment according to the three-dimensional coordinates of all fluid particles in the next frame.
12. 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 three-dimensional fluid display method according to any one of claims 1 to 10 are implemented.
13. 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 three-dimensional fluid display method according to any one of claims 1 to 10.
14. A computer program product, characterized in that It comprises computer instructions, which, when executed by a processor, implement the three-dimensional fluid display method as described in any one of claims 1-10.
Citation Information
Patent Citations
Fluid dynamics framework for animated special effects
CA2783770A1
Uranium tailing pond dam break three-dimensional numerical simulation method based on computational fluid mechanics
CN111241757A