A real-time rigid body simulation method and system based on position

By adopting position-based real-time simulation method and parallel GPU calculation in rigid body simulation, the problems of complex external force calculation and poor simulation results in the existing technology are solved, and efficient and accurate rigid body motion simulation is achieved.

CN114528744BActive Publication Date: 2025-04-25FUJIAN TIANQUAN EDUCATION TECH LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011330029.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2020-11-23
Filing Date
2020-11-24
Publication Date
2025-04-25
Estimated Expiration
2040-11-24

AI Technical Summary

Technical Problem

The existing rigid body simulation scheme is complex and difficult to accurately calculate external forces, resulting in poor simulation results and requires manual adjustment of multiple coefficients, which lacks convenience.

Method used

The position-based real-time rigid body simulation method is adopted, and the parallel computing power of the GPU is used to accurately simulate the rigid body movement by setting the data structure of the rigid body particles, applying external forces, performing collision processing and shape matching algorithms.

Benefits of technology

It realizes more accurate rigid body motion simulation, improves calculation efficiency, and has real-time simulation capabilities, avoiding the tedious process of manually adjusting external force coefficients.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114528744B_ABST
    Figure CN114528744B_ABST
Patent Text Reader

Abstract

The present invention provides a position-based real-time rigid body simulation method, which comprises the following steps: step S1, setting a data structure of rigid body particles; step S2, applying external force to rigid body particles to obtain predicted positions of each rigid body particle after being subjected to the external force; step S3, performing collision processing between the rigid body particles and other objects in a scene to obtain position offsets of the rigid body particles after the collision; step S4, restoring the rigid body particles after the collision to a static shape by using a shape matching algorithm to obtain the final predicted positions of the rigid body particles; step S5, updating the rigid body position information and speed of the current frame according to the predicted position and the position offset; the present invention simulates rigid body motion more accurately by means of the powerful parallel computing capability of a GPU.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention utilizes Compute Shader technology to improve the computational efficiency of rigid body simulation and has the ability to simulate rigid body motion in real time, in particular, is a position-based real-time rigid body simulation method and system. Background Art

[0002] The mainstream rigid body simulation solution uses several particles to simulate the rigid body and calculates the force of each particle. The speed and position of the particle are updated according to the force. It is necessary to accurately calculate various external forces to achieve a realistic simulation effect. Each external force has a corresponding coefficient. For different rigid bodies or different environments, each coefficient needs to be manually adjusted, which is not convenient enough. The force calculation is complex and difficult to calculate accurately, and the performance is poor. There is room for further improvement. Summary of the invention

[0003] To overcome the above problems, the purpose of the present invention is to provide a position-based real-time rigid body simulation method, which can simulate rigid body motion more accurately by leveraging the powerful parallel computing capability of GPU.

[0004] The present invention is implemented by the following scheme: a real-time rigid body simulation method based on position, the method comprising the following steps:

[0005] Step S1, setting the data structure of rigid body particles;

[0006] Step S2, applying external force to the rigid body particles to obtain the predicted position of each rigid body particle after being subjected to the external force;

[0007] Step S3, performing collision processing between the rigid body particles and other objects in the scene to obtain the position offset of the rigid body particles after the collision;

[0008] Step S4: Use the shape matching algorithm to restore the rigid body particles after collision to the static shape to obtain the final rigid body

[0009] The predicted position of the particle;

[0010] Step S5: Update the rigid body position information and speed of the current frame according to the predicted position and position offset.

[0011] Furthermore, the step S1 is further specified as follows: the data structure of the rigid body particles is: ComputeBuffer positions, ComputeBuffer predictedPos, ComputeBuffer velocities; wherein positions saves the actual position of the particles, predictedPos and velocities are used to calculate the predicted position and velocity data of each rigid body particle in the simulation, and finally the value of the predicted position is assigned to positions.

[0012] Furthermore, the step S2 is further specifically as follows: when the rigid body particle simulation process starts, the rigid body particles will be affected by gravity, and the number of threads of the total number of rigid body particles is started to calculate the predicted position predictedPos of each rigid body particle after being affected by the external force:

[0013] predictedPos[id]=positions[id]+deltaTime(velocities[id]+gravity·deltaTime); where id is the index value of the current particle, positions is the actual position of the saved particle, velocities is the velocity of the particle, deltaTime is the time step of each frame, and gravity is the gravity value.

[0014] Furthermore, the step S3 is further specifically as follows: performing collision processing between rigid body particles and other objects in the scene; starting the number of threads of the total number of rigid body particles, obtaining particle information of the surrounding neighborhood for each rigid body particle, and obtaining the distance d between two particles; when the distance between particles is less than the diameter of the particle, the position offset of the particle is calculated using the collision detection formula; the collision detection formula is as follows:

[0015]

[0016]

[0017]

[0018] Where Δx i is the position offset of the current particle, Δx j is the position offset of particle j that collides with particle i, ω is the inverse of mass, and d is the distance between particles;

[0019] After this step, the predicted collision position of the particle is:

[0020] collidepredictedPos[id]=predictedPos[id]+Δx i

[0021] Among them, id is the index value of the current particle, Δx i It is the position offset of the current particle after collision detection.

[0022] Furthermore, the step S4 is further specifically as follows: using a shape matching algorithm to restore the rigid body particles after the collision to a static shape. Shape matching is essentially to find the and x i The optimal transformation between them is: there exists a rotation matrix R and translation vectors t and t 0 ;

[0023]

[0024]

[0025]

[0026] x cm =t

[0027] Among them, m i is the mass of the particle, is the initial position of the particle, x i is the current position of the particle, represents the sum of the product of the mass and the initial position of each particle, represents the sum of the mass of each particle, It means to sum the product of the mass of each particle and the current position; that is, the optimal transformation vector is the center of mass of the initial shape. and the centroid x of the actual shape cm ;

[0028] R=A pq S -1

[0029]

[0030]

[0031] p i =x i -x cm

[0032]

[0033] Among them, p i is the current position x of the particle i The centroid x of the actual shape cm The difference, q i is the initial position of the particle The centroid of the initial shape The difference, Denotes the mass m of each particle i With p i as well as The product of is summed up, Indicates q i The transpose of (A pq ) T Indicates A pq The transpose of S -1 represents the inverse of S, and R is the required rotation matrix;

[0034] The position offset is:

[0035] After this step, the final predicted position of the particle is:

[0036] finalpredictedPos[id]=collidepredictedPos[id]+Δx i

[0037] Among them, id is the index value of the current particle, Δx i It is the position offset of the current particle after shape matching, and collidepredictedPos[id] is the predicted collision position.

[0038] Furthermore, the step S5 is further specifically as follows: starting the number of threads of the total number of particles, calculating the speed of the particles according to the final predicted position and initial position of the particles, and then assigning the calculated final predicted position data of the particles to the actual position data of the particles,

[0039] velocity[id]=(finalpredictedPos[id]-positions[id]) / deltaTime

[0040] positions[id]=finalpredictedPos[id]

[0041] Among them, id is the index value of the current particle, and deltaTime is the time step of each frame;

[0042] Finally, the position information of all rigid body particles is obtained, and the position information is drawn on the screen using a graphics drawing interface to achieve real-time simulation of rigid body particles.

[0043] The present invention also provides a position-based real-time rigid body simulation system, the system comprising a data structure setting module, an external force application module, a collision processing module, a shape matching module, and an update module;

[0044] The data structure setting module is used to set the data structure of rigid body particles;

[0045] The external force application module is used to apply external force to the rigid body particles to obtain the predicted position of each rigid body particle after being subjected to the external force; the collision processing module is used to perform collision processing between the rigid body particles and other objects in the scene to obtain the position offset of the rigid body particles after the collision;

[0046] The shape matching module uses a shape matching algorithm to restore the rigid body particles after the collision to a static shape to obtain the final predicted position of the rigid body particles;

[0047] The updating module updates the rigid body position information and speed of the current frame according to the predicted position and the position offset.

[0048] Furthermore, the implementation method of the data structure setting module is further specified as follows: the data structure of the rigid body particles is: ComputeBuffer positions, ComputeBuffer predictedPos, ComputeBuffervelocities; among them, positions saves the actual position of the particles, predictedPos and velocities are used to calculate the predicted position and velocity data of each rigid body particle in the simulation, and finally the value of the predicted position is assigned to positions.

[0049] Furthermore, the implementation method of the external force application module is further specifically as follows: when the rigid body particle simulation process starts, the rigid body particles will be affected by gravity, and the number of threads of the total number of rigid body particles is started to calculate the predicted position predictedPos of each rigid body particle after being affected by the external force:

[0050] predictedPos[id]=positions[id]+deltaTime(velocities[id]+gravity·deltaTime); where id is the index value of the current particle, positions is the actual position of the saved particle, velocities is the velocity of the particle, deltaTime is the time step of each frame, and gravity is the gravity value.

[0051] Furthermore, the implementation method of the collision processing module is further specifically as follows: performing collision processing between rigid body particles and other objects in the scene; starting the number of threads of the total number of rigid body particles, for each rigid body particle, obtaining the particle information of the surrounding neighborhood, and obtaining the distance d between the two particles. When the distance between the particles is less than the diameter of the particle, the position offset of the particle is calculated using the collision detection formula; the collision detection formula is as follows:

[0052]

[0053]

[0054]

[0055] Where Δx i is the position offset of the current particle, Δx j is the position offset of particle j that collides with particle i, ω is the inverse of mass, and d is the distance between particles;

[0056] After this step, the predicted collision position of the particle is:

[0057] collidepredictedPos[id]=predictedPos[id]+Δx i

[0058] Among them, id is the index value of the current particle, Δx i It is the position offset of the current particle after collision detection.

[0059] Furthermore, the implementation of the shape matching module is further specific as follows: using the shape matching algorithm to restore the rigid body particles after the collision to a static shape. Shape matching is essentially to find the shape of two point sets. and x i The optimal transformation between them, that is: there exists a rotation matrix R and translation vector t and t0;

[0060]

[0061]

[0062]

[0063] x cm =t

[0064] Among them, m i is the mass of the particle, is the initial position of the particle, x i is the current position of the particle, represents the sum of the product of the mass and the initial position of each particle, represents the sum of the mass of each particle, It means to sum the product of the mass of each particle and the current position; that is, the optimal transformation vector is the center of mass of the initial shape. and the centroid x of the actual shape cm ;

[0065] R=A pq S-1

[0066]

[0067]

[0068] p i =x i -x cm

[0069]

[0070] Among them, p i is the current position x of the particle i The centroid x of the actual shape cm The difference, q i is the initial position of the particle The centroid of the initial shape The difference, Denotes the mass m of each particle i With p i as well as The product of is summed up, Indicates q i The transpose of (A pq ) T Indicates A pq The transpose of S -1 represents the inverse of S, and R is the required rotation matrix;

[0071] The position offset is:

[0072] After this step, the final predicted position of the particle is:

[0073] finalpredictedPos[id]=collidepredictedPos[id]+Δx i

[0074] Among them, id is the index value of the current particle, Δx i It is the position offset of the current particle after shape matching, and collidepredictedPos[id] is the predicted collision position.

[0075] Furthermore, the implementation of the update module is further specifically as follows: start the number of threads of the total number of particles, calculate the speed of the particle according to the final predicted position and initial position of the particle, and then assign the calculated final predicted position data of the particle to the actual position data of the particle,

[0076] velocity[id]=(finalpredictedPos[id]-positions[id]) / deltaTime

[0077] positions[id]=finalpredictedPos[id]

[0078] Among them, id is the index value of the current particle, and deltaTime is the time step of each frame;

[0079] Finally, the position information of all rigid body particles is obtained, and the position information is drawn on the screen using the GPU graphics drawing interface to achieve real-time simulation of rigid body particles.

[0080] The beneficial effect of the present invention is that: in view of the shortcomings of the rigid body simulation based on force that cannot accurately calculate the external force and needs to manually adjust the coefficients of various external forces according to different situations, this patent proposes a real-time rigid body simulation method based on position, and with the help of the powerful parallel computing capability of GPU, it can simulate the rigid body motion more accurately. It improves the computational efficiency of rigid body simulation and has the ability to simulate rigid body motion in real time. BRIEF DESCRIPTION OF THE DRAWINGS

[0081] Figure 1 It is a schematic flow chart of the method of the present invention.

[0082] Figure 2 It is a system principle block diagram of the present invention. DETAILED DESCRIPTION

[0083] The present invention will be further described below in conjunction with the accompanying drawings.

[0084] See also Figure 1 As shown, a position-based real-time rigid body simulation method of the present invention comprises the following steps:

[0085] Step S1, setting the data structure of rigid body particles;

[0086] Step S2, applying external force to the rigid body particles to obtain the predicted position of each rigid body particle after being subjected to the external force;

[0087] Step S3, performing collision processing between the rigid body particles and other objects in the scene to obtain the position offset of the rigid body particles after the collision;

[0088] Step S4: Use the shape matching algorithm to restore the rigid body particles after collision to the static shape to obtain the final rigid body

[0089] The predicted position of the particle;

[0090] Step S5: Update the rigid body position information and speed of the current frame according to the predicted position and position offset.

[0091] The present invention will be further described below in conjunction with a specific embodiment:

[0092] Rigid body simulation is divided into the following 5 steps:

[0093] 1. Rigid body particle data structure

[0094] The data structure of rigid body particles is as follows:

[0095] ComputeBuffer positions;

[0096] ComputeBuffer predictedPos;

[0097] ComputeBuffer velocities;

[0098] Among them, positions saves the actual position of the particle, predictedPos and velocities are used to calculate the predicted position and velocity data of each rigid body particle in the simulation, and finally the value of the predicted position is assigned to positions.

[0099] 2. Apply external force to rigid body particles

[0100] At the beginning of the simulation process, particles will be affected by external forces such as gravity and gravitation. The number of threads for the total number of rigid body particles is turned on to calculate the predicted position of each rigid body particle after being affected by external forces:

[0101] predictedPos[id]=positions[id]+deltaTime(velocities[id]+gravity·deltaTime)

[0102] Where id is the index value of the current particle, deltaTime is the time step of each frame, and gravity is the gravity value.

[0103] 3. Collision Detection

[0104] This step calculates the collision between rigid body particles and other objects in the scene. Particles in the same rigid body do not need to calculate collisions. Open the number of threads for the total number of rigid body particles. For each rigid body particle, obtain the particle information of the surrounding neighborhood. First, calculate the distance d between two particles. When the distance between particles is less than the diameter of the particle, use the collision detection formula to calculate the position offset of the particle. The collision detection formula is as follows:

[0105]

[0106]

[0107]

[0108] Where Δx i is the position offset of the current particle, Δx j is the position offset of particle j that collides with particle i, ω is the inverse of the mass, and d is the distance between particles.

[0109] After this step, the predicted collision position of the particle is:

[0110] collidepredictedPos[id]=predictedPos[id]+Δx i

[0111] Among them, id is the index value of the current particle, Δx i It is the position offset of the current particle after collision detection.

[0112] 4. Shape matching

[0113] After the calculation in step 3, the shape of the rigid body has changed. In this step, the shape matching algorithm is used to restore the rigid body to its static shape.

[0114] Shape matching is essentially finding two point sets and x i The optimal transformation between them is: there exists a rotation matrix R and translation vectors t and t 0 ;

[0115]

[0116]

[0117]

[0118] x cm =t

[0119] Among them, m i is the mass of the particle, is the initial position of the particle, x i is the current position of the particle, represents the sum of the product of the mass and the initial position of each particle, represents the sum of the mass of each particle, It means to sum the product of the mass of each particle and its current position. That is, the optimal transformation vectors are the center of mass of the initial shape. and the centroid x of the actual shape cm .

[0120] R=A pq S -1

[0121]

[0122]

[0123] p i =x i -x cm

[0124]

[0125] Among them, p i is the current position x of the particle i The centroid x of the actual shape cm The difference, q i is the initial position of the particle The centroid of the initial shape The difference, Denotes the mass m of each particle i With p i as well as The product of is summed up, Indicates q i The transpose of (A pq ) T Indicates A pq The transpose of S -1 represents the inverse of S, and R is the required rotation matrix.

[0126] The position offset is:

[0127] After this step, the final predicted position of the particle is:

[0128] finalpredictedPos[id]=collidepredictedPos[id]+Δx i

[0129] Among them, id is the index value of the current particle, Δx i It is the position offset of the current particle after shape matching, and collidepredictedPos[id] is the predicted collision position.

[0130] 5. Update the rigid body position information and speed of the current frame

[0131] The number of threads for the total number of particles is turned on, the particle speed is calculated according to the predicted position and initial position of the particle, and then the calculated predicted position data of the particle is assigned to the actual position data of the particle.

[0132] velocity[id]=(finalpredictedPos[id]-positions[id]) / deltaTime

[0133] positions[id]=finalpredictedPos[id]

[0134] Among them, id is the index value of the current particle, and deltaTime is the time step of each frame;.

[0135] Finally, the position information of all rigid body particles is obtained, and the position information is drawn on the screen using a graphics drawing interface to achieve real-time rigid body simulation.

[0136] like Figure 2 As shown, the present invention also provides a position-based real-time rigid body simulation system, the system comprising a data structure setting module, an external force application module, a collision processing module, a shape matching module, and an update module;

[0137] The data structure setting module is used to set the data structure of rigid body particles;

[0138] The external force applying module is used to apply external force to the rigid body particles to obtain the predicted position of each rigid body particle after being subjected to the external force;

[0139] The collision processing module is used to process the collision between the rigid body particles and other objects in the scene to obtain the position offset of the rigid body particles after the collision;

[0140] The shape matching module uses a shape matching algorithm to restore the rigid body particles after the collision to a static shape to obtain the final predicted position of the rigid body particles;

[0141] The updating module updates the rigid body position information and speed of the current frame according to the predicted position and the position offset.

[0142] Among them, the implementation method of the data structure setting module is further specified as follows: the data structure of the rigid body particles is: ComputeBuffer positions, ComputeBuffer predictedPos, ComputeBuffervelocities; among them, positions saves the actual position of the particles, predictedPos and velocities are used to calculate the predicted position and velocity data of each rigid body particle in the simulation, and finally the value of the predicted position is assigned to positions.

[0143] The implementation method of the external force application module is further specifically as follows: when the rigid body particle simulation process starts, the rigid body particles will be affected by gravity, and the number of threads of the total number of rigid body particles is started to calculate the predicted position predictedPos of each rigid body particle after being affected by the external force:

[0144] predictedPos[id]=positions[id]+deltaTime(velocities[id]+gravity·deltaTime); where id is the index value of the current particle, positions is the actual position of the saved particle, velocities is the velocity of the particle, deltaTime is the time step of each frame, and gravity is the gravity value.

[0145] The implementation method of the collision processing module is further specifically as follows: performing collision processing between rigid body particles and other objects in the scene; starting the number of threads of the total number of rigid body particles, for each rigid body particle, obtaining the particle information of the surrounding neighborhood, and obtaining the distance d between the two particles. When the distance between the particles is less than the diameter of the particle, the position offset of the particle is calculated using the collision detection formula; the collision detection formula is as follows:

[0146]

[0147]

[0148]

[0149] Where Δx i is the position offset of the current particle, Δx j is the position offset of particle j that collides with particle i, ω is the inverse of mass, and d is the distance between particles;

[0150] After this step, the predicted collision position of the particle is:

[0151] collidepredictedPos[id]=predictedPos[id]+Δx i

[0152] Among them, id is the index value of the current particle, Δx i It is the position offset of the current particle after collision detection.

[0153] In addition, the implementation method of the shape matching module is further specific as follows: using the shape matching algorithm to restore the rigid body particles after collision to a static shape. Shape matching is essentially to find two point sets and x i The optimal transformation between them is: there exists a rotation matrix R and translation vectors t and t0 ;

[0154]

[0155]

[0156]

[0157] x cm =t

[0158] Among them, m i is the mass of the particle, is the initial position of the particle, x i is the current position of the particle, represents the sum of the product of the mass and the initial position of each particle, represents the sum of the mass of each particle, It means to sum the product of the mass of each particle and the current position; that is, the optimal transformation vector is the center of mass of the initial shape. and the centroid x of the actual shape cm ;

[0159] R=A pq S -1

[0160]

[0161]

[0162] p i =x i -x cm

[0163]

[0164] Among them, p i is the current position x of the particle i The centroid x of the actual shape cm The difference, q i is the initial position of the particle The centroid of the initial shape The difference, Denotes the mass m of each particle i With p i as well as The product of is summed up, Indicates q i The transpose of (A pq ) T Indicates A pq The transpose of S -1 represents the inverse of S, and R is the required rotation matrix;

[0165] The position offset is:

[0166] After this step, the final predicted position of the particle is:

[0167] finalpredictedPos[id]=collidepredictedPos[id]+Δx i

[0168] Among them, id is the index value of the current particle, Δx i It is the position offset of the current particle after shape matching, and collidepredictedPos[id] is the predicted collision position.

[0169] Furthermore, the implementation of the update module is further specifically as follows: start the number of threads of the total number of particles, calculate the speed of the particle according to the final predicted position and initial position of the particle, and then assign the calculated final predicted position data of the particle to the actual position data of the particle,

[0170] velocity[id]=(finalpredictedPos[id]-positions[id]) / deltaTime

[0171] positions[id]=finalpredictedPos[id]

[0172] Among them, id is the index value of the current particle, and deltaTime is the time step of each frame;

[0173] Finally, the position information of all rigid body particles is obtained, and the position information is drawn on the screen using the GPU graphics drawing interface to achieve real-time simulation of rigid body particles.

[0174] The above description is only a preferred embodiment of the present invention. All equivalent changes and modifications made according to the scope of the patent application of the present invention should fall within the scope of the present invention.

Claims

1. A real-time position-based rigid body simulation method, characterized in that: The method comprises the following steps: Step S1, setting the data structure of rigid body particles; Step S2, applying external force to the rigid body particles to obtain the predicted position of each rigid body particle after being subjected to the external force; Step S3, performing collision processing between the rigid body particles and other objects in the scene to obtain the position offset of the rigid body particles after the collision; Step S4, using a shape matching algorithm to restore the rigid body particles after the collision to a static shape to obtain the final predicted position of the rigid body particles; Step S5, updating the rigid body position information and speed of the current frame according to the predicted position and position offset; The step S2 is further specifically as follows: when the rigid body particle simulation process starts, the rigid body particles will be affected by gravity, and the number of threads of the total number of rigid body particles is started to calculate the predicted position predictedPos of each rigid body particle after being affected by the external force: predictedPos[id]=positions[id]+deltaTime·gravity; wherein id is the index value of the current particle, positions is the actual position of the saved particle, deltaTime is the time step of each frame, and gravity is the gravity value; The step S3 is further specifically as follows: performing collision processing between rigid body particles and other objects in the scene; starting the number of threads of the total number of rigid body particles, obtaining particle information of the surrounding neighborhood for each rigid body particle, and obtaining the distance d between two particles; when the distance between particles is less than the diameter of the particle, calculating the position offset of the particle using the collision detection formula; the collision detection formula is as follows: Where Δx i is the position offset of the current particle, Δx j is the position offset of particle j that collides with particle i, ω is the inverse of mass, and d is the distance between particles; After this step, the predicted collision position of the particle is: collidepredictedPos[id]=predictedPos[id]+Δx i Among them, id is the index value of the current particle, Δx i It is the position offset of the current particle after collision detection; The step S5 is further specifically as follows: opening the number of threads of the total number of particles, calculating the speed of the particles according to the final predicted position and initial position of the particles, and then assigning the calculated final predicted position data of the particles to the actual position data of the particles, and finally obtaining the position information of all rigid body particles, and using the graphics drawing interface to draw the position information on the screen to realize the real-time simulation of rigid body particles.

2. A position-based real-time rigid body simulation method according to claim 1, characterized in that: The step S1 is further specified as follows: the data structure of the rigid body particles is: ComputeBuffer positions, ComputeBufferpredictedPos, ComputeBuffer velocities; wherein positions stores the actual position of the particles, predictedPos and velocities are used to calculate the predicted position and velocity data of each rigid body particle in the simulation, and finally the value of the predicted position is assigned to positions.

3. The position-based real-time rigid body simulation method according to claim 1, characterized in that: The step S4 is further specifically as follows: using a shape matching algorithm to restore the rigid body particles after the collision to a static shape. Shape matching is essentially to find two point sets. and x i The optimal transformation between them, that is: there exists a rotation matrix R and translation vector t and t0; x cm =t Among them, m i is the mass of the particle, is the initial position of the particle, x i is the current position of the particle, represents the sum of the product of the mass and the initial position of each particle, represents the sum of the mass of each particle, It means to sum the product of the mass of each particle and the current position; that is, the optimal transformation vector is the center of mass of the initial shape. and the centroid x of the actual shape cm ; R=A pq S -1 p i =x i -x cm Among them, p i is the current position x of the particle i The centroid x of the actual shape cm The difference, q i is the initial position of the particle The centroid of the initial shape The difference, Denotes the mass m of each particle i With p i as well as The product of is summed up, Indicates q i The transpose of (A pq ) T Indicates A pq The transpose of S -1 represents the inverse of S, R is the required rotation matrix; then the position offset is: After this step, the final predicted position of the particle is: finalpredictedPos[id]=collidepredictedPos[id]+Δx i Among them, id is the index value of the current particle, Δx i It is the position offset of the current particle after shape matching, and collidepredictedPos[id] is the predicted collision position.

4. A position-based real-time rigid body simulation method according to claim 3, characterized in that: The formula for assigning the calculated final predicted position data of the particle to the actual position data of the particle is: velocity[id]=(finalpredictedPos[id]-positions[id]) / deltaTime positions[id]=finalpredictedPos[id] Among them, id is the index value of the current particle, and deltaTime is the time step of each frame.

5. A position-based real-time rigid body simulation system, characterized in that: The system includes a data structure setting module, an external force applying module, a collision processing module, a shape matching module, and an updating module; The data structure setting module is used to set the data structure of rigid body particles; The external force applying module is used to apply external force to the rigid body particles to obtain the predicted position of each rigid body particle after being subjected to the external force; The collision processing module is used to process the collision between the rigid body particles and other objects in the scene to obtain the position offset of the rigid body particles after the collision; The shape matching module uses a shape matching algorithm to restore the rigid body particles after the collision to a static shape to obtain the final predicted position of the rigid body particles; The updating module updates the rigid body position information and speed of the current frame according to the predicted position and the position offset; the implementation method of the external force applying module is further specifically as follows: when the rigid body particle simulation process starts, the rigid body particles will be affected by gravity, then the number of threads of the total number of rigid body particles is started to calculate the predicted position predictedPos of each rigid body particle after being affected by the external force: predictedPos[id]=positions[id]+deltaTime·gravity; wherein id is the index value of the current particle, positions is the actual position of the saved particle, deltaTime is the time step of each frame, and gravity is the gravity value; The implementation method of the collision processing module is further specifically as follows: performing collision processing between rigid body particles and other objects in the scene; starting the number of threads of the total number of rigid body particles, for each rigid body particle, obtaining the particle information of the surrounding neighborhood, and obtaining the distance d between the two particles. When the distance between the particles is less than the diameter of the particle, the position offset of the particle is calculated using the collision detection formula; the collision detection formula is as follows: Where Δx i is the position offset of the current particle, Δx j is the position offset of particle j that collides with particle i, ω is the inverse of mass, and d is the distance between particles; After this step, the predicted collision position of the particle is: collidepredictedPos[id]=predictedPos[id]+Δx i Among them, id is the index value of the current particle, Δx i It is the position offset of the current particle after collision detection; The implementation method of the update module is further specifically as follows: the number of threads for the total number of particles is turned on, the speed of the particles is calculated according to the final predicted position and initial position of the particles, and then the calculated final predicted position data of the particles is assigned to the actual position data of the particles, and finally the position information of all rigid body particles is obtained, and the position information is drawn on the screen using a graphics drawing interface to realize real-time simulation of rigid body particles.

6. A position-based real-time rigid body simulation system according to claim 5, characterized in that: The implementation method of the data structure setting module is further specified as follows: the data structure of the rigid body particles is: ComputeBufferpositions, ComputeBuffer predictedPos, ComputeBuffer velocities; among them, positions saves the actual position of the particles, predictedPos and velocities are used to calculate the predicted position and velocity data of each rigid body particle in the simulation, and finally the value of the predicted position is assigned to positions.

7. A position-based real-time rigid body simulation system according to claim 5, characterized in that: The implementation method of the shape matching module is further specifically as follows: using the shape matching algorithm to restore the rigid body particles after collision to a static shape. Shape matching is essentially to find two point sets and x i The optimal transformation between them, that is: there exists a rotation matrix R and translation vector t and t0; x cm =t Among them, m i is the mass of the particle, is the initial position of the particle, x i is the current position of the particle, represents the sum of the product of the mass and the initial position of each particle, represents the sum of the mass of each particle, It means to sum the product of the mass of each particle and the current position; that is, the optimal transformation vector is the center of mass of the initial shape. and the centroid x of the actual shape cm ; R=A pq S -1 p i =x i -x cm Among them, p i is the current position x of the particle i The centroid x of the actual shape cm The difference, q i is the initial position of the particle The centroid of the initial shape The difference, Denotes the mass m of each particle i With p i as well as The product of is summed up, Indicates q i The transpose of (A pq ) T Indicates A pq The transpose of S -1 represents the inverse of S, R is the required rotation matrix; then the position offset is: After this step, the final predicted position of the particle is: finalpredictedPos[id]=collidepredictedPos[id]+Δx i Among them, id is the index value of the current particle, Δx i It is the position offset of the current particle after shape matching, and collidepredictedPos[id] is the predicted collision position.

8. A position-based real-time rigid body simulation system according to claim 7, characterized in that: The formula for assigning the calculated final predicted position data of the particle to the actual position data of the particle is: velocity[id]=(finalpredictedPos[id]-positions[id]) / deltaTime positions[id]=finalpredictedPos[id] Among them, id is the index value of the current particle, and deltaTime is the time step of each frame.

Citation Information

Patent Citations

  • Fluid interactive simulation method and system based on GPUs cluster

    CN107657131A

  • Real-time soft tissue burning simulation method based on position dynamics and biological conduction equation

    CN107688720A