High-precision cloth simulation method for Unreal
Through Spatial Hashing and impact domain optimization processing, the problems of low fabric simulation accuracy and insufficient scalability in the Unreal engine are solved, and high-precision fabric simulation is achieved, enhancing the authenticity and customization capabilities of the simulation.
Patent Information
- Application Number
- CN202411091598.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-09
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2044-08-09
AI Technical Summary
The fabric simulation methods in the existing Unreal engine have problems such as low simulation accuracy, fewer constraint types and low scalability, which leads to unreal simulation effects and difficult to customize.
Using Spatial Hashing accelerated collision detection and impact domain optimization processing methods, high-precision fabric triangular face collision detection and vertex position optimization are carried out by constructing a spatial hash table and AABB bounding box, and high-precision fabric simulation is achieved.
It improves the accuracy of fabric simulation, reduces penetration, provides a method to directly modify the underlying data, avoids animation nodes and user interface operations, and enhances the scalability of the simulation.
Smart Images

Figure CN119092015A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a cloth simulation method in the field of computer-aided design (CAD), and in particular to a high-precision cloth simulation method for Unreal. Background Art
[0002] Computer-aided design (CAD) technology is widely used in various design fields. There is a lot of relevant expertise in the application of game physics engines. As a very mature and advanced game engine, Unreal has a complete Chaos engine framework for cloth simulation, which can easily bind simulation-related structures to the FBX data constructed by users. However, most simulations are based on the structure of skeletal meshes. UE itself can perform "point brushing" operations on Cloth components to add simulation-related bindings to specific vertices. Some cloth plug-ins on UE stores use the control points of the skeletal model imported by users in combination with UE's animation system to simulate cloth in a dynamic way. These methods have some shortcomings. The main problems are as follows:
[0003] (1) Low simulation accuracy: In order to improve the running efficiency of the scene, the simulation generally uses bone vertices and bounding boxes to reduce the calculation scale during the simulation runtime. Compared with the detection accuracy of each triangle, it is bound to be lower.
[0004] (2) Few types of constraints: UE's existing constraints are mainly concentrated on joint distance and rotation. In many scenarios, developers need to customize constraints, such as handling friction or deformation.
[0005] (3) Low scalability: The UE's skeletal mesh structure is highly encapsulated. Developers cannot directly modify and calculate simulations by obtaining information about LOD and the underlying Mesh structure. They must call and implement it through the external interface of the user interface. High-precision simulations require real-time updates of the underlying data about the cloth. Summary of the invention
[0006] In view of the above problems, the present invention aims to construct a cloth simulation method that can read FBX cloth data and generate cloth data that can be modified and rendered in real time through a high-precision cloth simulation method in each step. The present invention uses an accelerated collision detection method, Spatial Hashing, so that objects in a certain range of motion space can quickly perform collision elimination and classification. The present invention adopts an impact zone collision optimization processing method to construct a triangular face set for CCD continuous collision detection in each time step and the next time step, which greatly reduces the number of detection pairs.
[0007] The technical solution of the present invention is as follows:
[0008] 1. A high-precision cloth simulation method for Unreal
[0009] Step 1: After reading the cloth data imported by Unreal and binding the structure, obtain the original cloth data set;
[0010] Step 2: Extract the vertices and position information of the cloth patches in the original cloth data set and construct a simulation data set;
[0011] Step 3: Add a corresponding AABB bounding box for each cloth triangle in the simulation data set; and construct a spatial hash table and set an index value for each cloth triangle, and store the cloth triangle corresponding to the spatial position in each hash cell of the spatial hash table;
[0012] Step 4: Based on the AABB bounding box and the spatial hash table, collision detection is performed on the cloth triangles in the simulation data set to obtain the collision impact domain;
[0013] Step 5: Construct the vertex position optimization equation according to the collision impact domain, and use the gradient descent method to iteratively solve the vertex position optimization equation so that there is no collision and penetration between all cloth triangles, obtain the mesh model data and render it into the scene.
[0014] The simulation method further comprises the following steps:
[0015] Step 6: Repeat steps 2 to 5 to render the cloth data of the next time step to achieve continuous rendering of the cloth data.
[0016] In step 3, a corresponding AABB bounding box is added to each cloth triangle patch in the simulation data set, specifically:
[0017] First, get each vertex position from the vertex position buffer and build the corresponding vertex structure object; then get the index according to the vertex index buffer and determine the connection relationship between each vertex position, so as to build the edge, face and triangle structure objects; then build the corresponding AABB bounding box and normal cone from the triangle structure according to the three vertices contained in it.
[0018] The step 4 is specifically as follows:
[0019] Firstly, a wide-stage AABB bounding box collision detection is performed on the cloth triangles in the simulation data set to obtain a wide-stage collision cloth triangle set. Based on the wide-stage collision cloth triangle set, a narrow-stage CCD continuous collision detection is performed to obtain the final collision cloth triangle set and store it in the impact domain, which is recorded as the collision impact domain.
[0020] The narrow phase CCD continuous collision detection is performed based on the collision detection result of the wide phase to obtain the final collision cloth triangle facet set, specifically:
[0021] The set of cloth triangles except the wide-stage collision cloth triangle set Td is recorded as the safe cloth triangle set Ts. The triangles in the wide-stage collision cloth triangle set Td are subjected to CCD continuous collision detection in pairs, and the triangles between the wide-stage collision cloth triangle set Td and the safe cloth triangle set Ts are subjected to CCD continuous collision detection in pairs to obtain the final collision cloth triangle set.
[0022] In step 5, the formula of the vertex position optimization equation is as follows:
[0023] min{g(X)+λ T c^(X,s)+μ 2 ||c^(X,s)||2}
[0024] Where g(X) is the momentum difference between the modified vertex position and the unmodified vertex position, c^(X,s) represents the constraint equation containing the slack variable s, λ is the Lagrange multiplier, μ is the penalty function coefficient, T represents the transpose, and ||||2 represents the spectral norm.
[0025] In step 5, the mesh model data is passed to the executable mesh component in Unreal, and the executable mesh component performs rendering and effect display in the user visual interface.
[0026] 2. A computer device
[0027] The device includes a memory and a processor, the memory stores a computer program, and the processor implements the steps of the high-precision cloth simulation method for Unreal when executing the computer program.
[0028] 3. A computer-readable storage medium
[0029] The medium stores a computer program, and when the computer program is executed by a processor, the steps of the high-precision cloth simulation method for Unreal are implemented.
[0030] IV. A COMPUTER PROGRAM PRODUCT
[0031] The product includes a computer program / instruction, which, when executed by a processor, implements the steps of a high-precision cloth simulation method for Unreal.
[0032] 5. A high-precision cloth simulation system for Unreal
[0033] The cloth original data set generation module is used to read the cloth data imported by Unreal and generate the cloth original data set after binding the structure;
[0034] A simulation data set construction module is used to extract the vertices and position information of the cloth patches in the original cloth data set to obtain the simulation data set;
[0035] A spatial hash table generator, used to generate a spatial hash table and store each cloth triangle patch in the simulation data set;
[0036] The collision impact domain generation module is used to perform collision detection on the cloth triangles in the simulation data set based on the AABB bounding box and combined with the spatial hash table to obtain the collision impact domain;
[0037] The optimizer and renderer is used to construct the vertex position optimization equation according to the collision impact domain, and use the gradient descent method to iteratively solve the vertex position optimization equation so that there is no collision and penetration between all cloth triangles, obtain the mesh model data and render it into the scene.
[0038] The beneficial effects of the present invention are as follows:
[0039] The present invention improves the accuracy of cloth simulation in the UE engine, optimizes the general simulation method to deal with the shortcomings of penetration, unreality, etc. that may be caused by cloth simulation, avoids the use of animation nodes and user interface operations in the UE, and instead provides a method that can directly modify the underlying data and transmit it to the rendering pipeline. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 This is a flow chart of cloth simulation in an embodiment of the present invention;
[0041] Figure 2 A schematic diagram of a spatial hash structure in an embodiment of the present invention;
[0042] Figure 3 Schematic diagram of two stages of collision detection in an embodiment of the present invention. DETAILED DESCRIPTION
[0043] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.
[0044] The present invention proposes a high-precision cloth simulation method for Unreal. Figure 1 and Figure 3 As shown, the simulation method includes the following steps:
[0045] Step 1: After reading the cloth data imported by Unreal and binding the structure, obtain the original cloth data set. The structure is usually a skeletal mesh.
[0046] Based on the way to create C++ classes in UE, a custom Cloth class is created. In the constructor, CreateDefaultSubobject is first used <uproceduralmeshcomponent>Method to define an executable mesh component, which stores the actual vertex positions of the Mesh calculated in the algorithm and passes them to the UE rendering pipeline each frame to display the cloth motion effect in real time in the Play interface.
[0047] In this step, the Cloth class will obtain the skeletal mesh of the cloth object instance in the Play space through the method of obtaining components in UE using the data imported by the user, that is, the object structure used in general cloth simulation in UE, and then obtain its rendering data through the method of obtaining rendering resources. The rendering data includes its LOD level data. It is necessary to obtain its vertex index buffer and vertex position buffer to build the basic data of the executable mesh for simulation rendering, including the actual position and sequential index of all vertices involved in the cloth mesh in the geometric space. These data have corresponding Get methods in UE, but they are all read-only. For developers, they generally need to use the corresponding user interface of the UE interface to modify them.
[0048] The basic simulation structures needed include vertices, edges, faces, triangles, etc.:
[0049] The code is as follows (taking Vertex as an example):
[0050]
[0051]
[0052] Step 2: Extract the vertices and position information of the cloth patches in the original cloth data set, construct a simulation data set, and add simulation attributes including mass and elastic coefficient;
[0053] Step 3: Add corresponding AABB bounding boxes for each cloth triangle patch in the simulation data set obtained by the Unreal engine;
[0054] Add the corresponding AABB bounding box for each cloth triangle patch in the simulation data set obtained by the Unreal engine, specifically:
[0055] First, get each vertex position from the vertex position buffer and build the corresponding vertex structure object. Then get the index according to the vertex index buffer and determine the connection relationship between each vertex position, so as to build the edge, face and triangle structure objects. Then build the corresponding AABB bounding box and normal cone from the triangle structure according to the three vertices contained in it.
[0056] Brief analysis of AABB structure:
[0057] Struct AABB{
[0058] Double Xmin;
[0059] Double Xmax;
[0060] Double Ymin;
[0061] Double Ymax;
[0062] Double Zmin;
[0063] Double Zmax;
[0064] It can be seen that we only need to compare the XYZ values of each vertex to calculate the maximum and minimum values.
[0065] In each time step, the bounding box data of the triangle is calculated and modified in real time according to the vertex position.
[0066] Among them, the specific structure of the spatial hash table is:
[0067] The triangles of all entities that can collide in space are covered by the hash grids of their AABB bounding boxes. These hash grids can directly calculate the index according to the spatial coordinates and store the pointers of all the included triangles. The node addresses of the spatial hash are stored in a hash table with the key Key =<xAxis,yAxis,zAxis> (the location of the spatial coordinate grid), value = vector <triangle>(array storing triangle data structures) method.
[0068] After the basic structure operation is completed, a spatial hash table is constructed and an index value is set for each cloth triangle patch. At the same time, the cloth triangle patch corresponding to the spatial position is stored in each hash grid of the spatial hash table according to the values of the bounding box X coordinate, Y coordinate, and Z coordinate, such as Figure 2 As shown;
[0069] The specific process of this step is as follows:
[0070] 1. Determine the size of the hash grid based on the range of motion of all objects in the space and the number of triangles in the grid. For example, a 20*20*20 grid has a maximum of 800 hash grids, which are evenly divided into 20 parts along each coordinate axis. Then, all the hash grids involved in the AABB bounding box of a triangle can be calculated and placed in each hash grid.
[0071] 2. A hash grid with multiple triangles is considered to contain potential triangle pairs that may collide. Of course, before that, the normal cone can be used to remove some triangles on the adjacent Mesh;
[0072] Step 4: Based on the AABB bounding box and the spatial hash table, collision detection is performed on the cloth triangles in the simulation data set to obtain the collision impact domain;
[0073] Step 4 is as follows:
[0074] First, perform wide-stage AABB bounding box collision detection on the cloth triangles in the simulation data set to obtain a wide-stage collision cloth triangle set; perform narrow-stage CCD continuous collision detection based on the wide-stage collision cloth triangle set to obtain the final collision cloth triangle set and store it in the impact zone, which is recorded as the collision impact zone. The structure of the impact zone includes a vertex array that stores pointers to all vertex objects related to the collision triangles, an impacts array that stores each impact instance, and this structure will be shown later, as well as an enable variable active to indicate whether this area is activated for collision detection. Construct point-to-face constraints and edge-to-edge constraints for all colliding triangles.
[0075] Based on the collision detection results of the wide stage, CCD continuous collision detection is performed in the narrow stage to obtain the final collision cloth triangle patch set, specifically:
[0076] The set of cloth triangles except the wide-stage collision cloth triangle set Td is recorded as the safe cloth triangle set Ts, and CCD continuous collision detection is performed on the triangles in the wide-stage collision cloth triangle set Td in pairs, and CCD continuous collision detection is performed on the triangles between the wide-stage collision cloth triangle set Td and the safe cloth triangle set Ts in pairs, to obtain the final collision cloth triangle set. The result corresponding to a collision is stored as an impact, and an impact domain contains multiple impacts. A impact stores the constraint type, the index of the involved vertices, and the collision time.
[0077] The impact structure code is as follows:
[0078]
[0079] Step 5: Construct the vertex position optimization equation according to the collision impact domain, and use the gradient descent method to iteratively solve the vertex position optimization equation so that there is no collision and penetration between all cloth triangles, and obtain the mesh model data. The formula of the vertex position optimization equation is as follows:
[0080] min{g(X)+λ T c^(X,s)+μ 2 ||c^(X,s)||2}
[0081] Among them, g(X) is the momentum difference between the modified vertex position and the vertex position before modification, c(X) is the constraint equation to be solved, if the sum of all point-surface constraints and edge-edge constraints that need to be calculated is set to c*(X), then c(X)=-c*(X), c^(X,s) represents the constraint equation containing the slack variable s, λ is the Lagrange multiplier, μ is the penalty function coefficient, T represents the transpose, ||A||2 represents the spectral norm, that is, AH*the square root of the largest of the A eigenvalues λi, where AH is the transposed conjugate matrix of A.
[0082] The results of iterative solution can be divided into the following two cases:
[0083] 1. A solution with a residual less than a certain value is obtained within the specified maximum number of iterations. The position of this solution is used to modify the vertex in the impact domain where the collision occurs. The speed change is inferred based on the position difference before and after. Then, these data are applied to modify all relevant vertices involved in the cloth to complete the collision processing.
[0084] 2. The equation reaches convergence within the maximum number of iterations specified, and the solution fails. At this time, it returns to the situation where no penetration occurred at the previous moment.
[0085] Finally, a set of vertex position and velocity data is obtained to form the mesh model data and passed to the executable mesh component in Unreal. After being processed in the UE rendering pipeline, the executable mesh component displays the simulation results in the game operation interface.
[0086] On the other hand, the present invention also proposes a high-precision cloth simulation system for Unreal
[0087] The cloth original data set generation module is used to read the cloth data imported by Unreal and generate the cloth original data set after binding the structure;
[0088] A simulation data set construction module is used to extract the vertices and position information of the cloth patches in the original cloth data set to obtain the simulation data set;
[0089] A spatial hash table generator, used to generate a spatial hash table and store each cloth triangle patch in the simulation data set;
[0090] The collision impact domain generation module is used to perform collision detection on the cloth triangles in the simulation data set based on the AABB bounding box and combined with the spatial hash table to obtain the collision impact domain;
[0091] The optimizer and renderer is used to construct the vertex position optimization equation according to the collision impact domain, and use the gradient descent method to iteratively solve the vertex position optimization equation so that there is no collision and penetration between all cloth triangles, obtain the mesh model data and render it into the scene.
[0092] Finally, it should be noted that the above embodiments and explanations are only used to illustrate the technical solution of the present invention rather than to limit it. Those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope disclosed in the technical solution of the present invention, which should be included in the scope of protection of the claims of the present invention.< / triangle> < / uproceduralmeshcomponent>
Claims
1. A high-precision cloth simulation method for Unreal, characterized in that: The steps include: Step 1: After reading the cloth data imported by Unreal and binding the structure, obtain the original cloth data set; Step 2: Extract the vertices and position information of the cloth patches in the original cloth data set and construct a simulation data set; Step 3: Add the corresponding AABB bounding box for each cloth triangle in the simulation data set; and constructing a spatial hash table and setting an index value for each cloth triangle patch, and storing the cloth triangle patch corresponding to the spatial position in each hash grid of the spatial hash table; Step 4: Based on the AABB bounding box and the spatial hash table, collision detection is performed on the cloth triangles in the simulation data set to obtain the collision impact domain; Step 5: Construct the vertex position optimization equation according to the collision impact domain, and use the gradient descent method to iteratively solve the vertex position optimization equation so that there is no collision and penetration between all cloth triangles, obtain the mesh model data and render it into the scene.
2. The high-precision cloth simulation method for Unreal according to claim 1, characterized in that: The simulation method further comprises the following steps: Step 6: Repeat steps 2 to 5 to render the cloth data of the next time step to achieve continuous rendering of the cloth data.
3. The high-precision cloth simulation method for Unreal according to claim 1, characterized in that: In step 3, a corresponding AABB bounding box is added to each cloth triangle patch in the simulation data set, specifically: First, get each vertex position from the vertex position buffer and build the corresponding vertex structure object; then get the index according to the vertex index buffer and determine the connection relationship between each vertex position, so as to build the edge, face and triangle structure objects; then build the corresponding AABB bounding box and normal cone from the triangle structure according to the three vertices contained in it.
4. The high-precision cloth simulation method for Unreal according to claim 1, characterized in that: The step 4 is specifically as follows: Firstly, a wide-stage AABB bounding box collision detection is performed on the cloth triangles in the simulation data set to obtain a wide-stage collision cloth triangle set. Based on the wide-stage collision cloth triangle set, a narrow-stage CCD continuous collision detection is performed to obtain the final collision cloth triangle set and store it in the impact domain, which is recorded as the collision impact domain.
5. The high-precision cloth simulation method for Unreal according to claim 4, characterized in that: The narrow phase CCD continuous collision detection is performed based on the collision detection result of the wide phase to obtain the final collision cloth triangle facet set, specifically: The set of cloth triangles except the wide-stage collision cloth triangle set Td is recorded as the safe cloth triangle set Ts. The triangles in the wide-stage collision cloth triangle set Td are subjected to CCD continuous collision detection in pairs, and the triangles between the wide-stage collision cloth triangle set Td and the safe cloth triangle set Ts are subjected to CCD continuous collision detection in pairs to obtain the final collision cloth triangle set.
6. The high-precision cloth simulation method for Unreal according to claim 1, characterized in that: In step 5, the formula of the vertex position optimization equation is as follows: min{g(X)+λ T c^(X,s)+μ 2 ||c^(X,s)||2} Where g(X) is the momentum difference between the modified vertex position and the unmodified vertex position, c^(X,s) represents the constraint equation containing the slack variable s, λ is the Lagrange multiplier, μ is the penalty function coefficient, T represents the transpose, and ||||2 represents the spectral norm.
7. The high-precision cloth simulation method for Unreal according to claim 1, characterized in that: In step 5, the mesh model data is passed to the executable mesh component in Unreal, and the executable mesh component performs rendering and effect display in the user visual interface.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Three-dimensional garment and human model collision detection method and device
CN106354959A
Continuous collision detection method based on spatial subdivision and dynamic bounding box
CN110047143A
Feature-based spatial hash continuous collision detection method
CN112802203A
Novel continuous collision detection method
CN117576289A
Contact geometry calculation device, contact geometry calculation method, and computer program product
US20080034023A1
