A three-dimensional dynamic collision detection method, device, and storage medium
By using layer-by-layer screening and WebWorker dynamic loading technology in three-dimensional dynamic collision detection, the problem of large amount of computing is solved under the volume of big data, and the computing efficiency and user experience are improved.
Patent Information
- Application Number
- CN202510407282.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2045-04-02
AI Technical Summary
The existing technology has a large amount of computing when the amount of big data, and the collision detection calculation time is long, resulting in the browser page being stuck, loss of response, and poor user experience.
Through filtering conditions layer by layer, the number of triangle faces that need to be compared in the final comparison, and the required data is dynamically loaded using WebWorker. The main thread is responsible for data preprocessing and the child thread performs dynamic collision detection.
Effectively solve memory management problems, improve computing efficiency, reduce user waiting time, enable designers to obtain feedback faster and optimize design solutions.
Smart Images

Figure CN119917246B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computing technologies, and in particular, to a three-dimensional dynamic collision detection method, apparatus, and storage medium. Background Art
[0002] In Web-based CAD (Computer-Aided Design) and CAE (Computer-Aided Engineering) software, as well as simulation and training software, in the usage scenario, users need to accurately simulate and test the interactions between physical structures, such as the assembly of mechanical components and the structural analysis of buildings. In the prior art, mainly the bounding spheres and bounding boxes of the constructed objects are used for intersection detection. This solution has a fast execution speed, but the results are inaccurate, and the correctness of irregular objects is directly lost. On this basis, traversing the composed triangular mesh data of two objects and performing pairwise intersection detection of triangular faces can solve the accuracy problem. However, this technical solution has a large amount of computation and a long calculation time when dealing with a large amount of data, which will cause the browser page to freeze and lose response, resulting in a poor user experience.
[0003] Therefore, how to improve the calculation efficiency and reduce the user waiting time while ensuring the correctness of collision detection is a technical problem that needs to be solved urgently. Summary of the Invention
[0004] Embodiments of the present disclosure provide a three-dimensional dynamic collision detection method, apparatus, and storage medium to at least solve the technical problems in the prior art that there is a large amount of computation, a long collision detection calculation time, which will cause the browser page to freeze and lose response, resulting in a poor user experience when dealing with a large amount of data.
[0005] According to one aspect of the embodiments of the present disclosure, a three-dimensional dynamic collision detection method is provided, including:
[0006] Calculating the distance between nodes according to the node array, sorting according to the distance between the nodes and recording it in the first list; wherein, the node array is a pre-constructed node array that needs to be pairwise compared;
[0007] Determining a second list of nodes whose positions have changed according to the first list;
[0008] Reading a third list that records whether a node has collided;
[0009] If the nodes in the second list are in the third list, delete the nodes from the third list;
[0010] Calculating the amount of position change of all nodes in the second list, and determining a fourth list of nodes that need to be detected for collision according to the amount of position change;
[0011] Detect whether the nodes in the fourth list collide, and record the detection result in the third list.
[0012] According to another aspect of the embodiments of the present disclosure, there is also provided a three-dimensional dynamic collision detection device, including a sub-thread module, and the sub-thread module is configured to:
[0013] Calculate the distances between nodes according to the node array, sort according to the distances between nodes, and record them in the first list; wherein, the node array is a pre-constructed node array that needs to be pairwise compared;
[0014] Determine the second list in which the positions of the nodes change according to the first list;
[0015] Read the third list recording whether the nodes collide;
[0016] If the nodes in the second list are in the third list, delete the nodes from the third list;
[0017] Calculate the amount of position change of all the nodes in the second list, and determine the fourth list of nodes that need to be detected for collision according to the amount of position change;
[0018] Detect whether the nodes in the fourth list collide, and record the detection result in the third list.
[0019] According to another aspect of the embodiments of the present disclosure, there is also provided a three-dimensional dynamic collision detection device, including: a processor; and
[0020] a memory connected to the processor for providing instructions for the processor to perform the following processing steps:
[0021] Calculate the distances between nodes according to the node array, sort according to the distances between nodes, and record them in the first list; wherein, the node array is a pre-constructed node array that needs to be pairwise compared;
[0022] Determine the second list in which the positions of the nodes change according to the first list;
[0023] Read the third list recording whether the nodes collide;
[0024] If the nodes in the second list are in the third list, delete the nodes from the third list;
[0025] Calculate the amount of position change of all the nodes in the second list, and determine the fourth list of nodes that need to be detected for collision according to the amount of position change;
[0026] Detect whether there is a collision among the nodes in the fourth list, and record the detection result in the third list.
[0027] Through the dynamic collision detection method of the present invention, by filtering layer by layer through screening conditions, the number of triangular faces that finally need to be compared and calculated is streamlined, and WebWorker is used to dynamically load the required data, which can effectively solve the problem of memory management, improve the calculation efficiency, and reduce the user waiting time. The present invention divides tasks into the main thread and the sub-thread, and improves the operating efficiency of the software by reducing unnecessary calculations, enabling designers to obtain feedback faster and optimize the design scheme. Brief Description of the Drawings
[0028] The drawings described herein are used to provide a further understanding of the present disclosure, and constitute a part of this application. The schematic embodiments of the present disclosure and their descriptions are used to explain the present disclosure, and do not constitute an improper limitation to the present disclosure. In the drawings:
[0029] Figure 1 is a hardware structure block diagram of a computing device for implementing the method according to Embodiment 1 of the present disclosure;
[0030] Figure 2 is a schematic diagram of a system for performing a three-dimensional dynamic collision detection method according to Embodiment 1 of the present disclosure;
[0031] Figure 3 is a schematic diagram of thread division according to the first aspect of Embodiment 1 of the present disclosure;
[0032] Figure 4 is a schematic diagram of the process of a three-dimensional dynamic collision detection method according to the first aspect of Embodiment 1 of the present disclosure;
[0033] Figure 5 is a schematic diagram of the step process for determining whether there is a collision in a grid according to the first aspect of Embodiment 1 of the present disclosure;
[0034] Figure 6 is a schematic diagram of a three-dimensional dynamic collision device according to Embodiment 2 of the present disclosure;
[0035] Figure 7 is a schematic diagram of another three-dimensional dynamic collision device according to Embodiment 3 of the present disclosure. Detailed Description of the Invention
[0036] To enable those skilled in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present disclosure without creative efforts shall fall within the scope of protection of the present disclosure.
[0037] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0038] Term definitions:
[0039] Mesh, in CAD (Computer-Aided Design) and CAE (Computer-Aided Engineering), Mesh refers to "mesh" or "meshing". A mesh is a data structure, usually used to represent objects or scenes in three-dimensional space, consisting of a series of interconnected nodes, edges and faces. In finite element analysis, a mesh is the result of discretizing a complex geometric model and is used for numerical calculation and simulation analysis;
[0040] Node: A node is a basic point in a mesh, and each node represents a spatial position. In a finite element mesh, nodes define the geometric shape of elements and link the elements together through connection relationships to form the entire finite element model. The connections between nodes form the edges and faces of the mesh. In a finite element mesh, the connection relationships of nodes define the topological structure of elements and determine the meshing method. The shape and structure of the mesh are determined by the positions and connection relationships of nodes.
[0041] Octant intersection box refers to a form of division of a bounding box. The space is divided into eight parts (i.e., octant space) through a specific center point, and each part can be regarded as a subspace.
[0042] Worker refers to a thread used for parallel processing of tasks.
[0043] WebWorker is a technology for implementing multi-threaded processing in browsers, which allows JavaScript scripts to run in background threads, thus avoiding long-running tasks from blocking the main thread.
[0044] In CAD (Computer-Aided Design) and CAE (Computer-Aided Engineering) software on the web, as well as simulation and training software, in the usage scenarios, users need to precisely simulate and test the interactions between physical structures, such as the assembly of mechanical components and the structural analysis of buildings. Precise collision detection is crucial for ensuring the accuracy and safety of the design. The three-dimensional dynamic collision detection method provided by the present invention improves the running efficiency of the software by reducing unnecessary calculations, enabling designers to obtain feedback faster and optimize the design scheme. In simulation and training systems, it can simulate and synchronize users' operations in real time and promptly feedback whether the users' operations are correct. At the same time, in applications such as WebWorker, it ensures that even when performing large-scale calculations, the software interface can still respond in a timely manner, enhancing the user experience.
[0045] Embodiment 1
[0046] According to this embodiment, a method embodiment of three-dimensional dynamics is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. And although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0047] The method embodiment provided in this embodiment can be executed in a mobile computing device, a computer terminal, a server, or a similar computing device. Figure 1 A hardware structure block diagram of a computing device for implementing three-dimensional dynamic collision detection is shown. As Figure 1 shown, the computing device may include one or more processors (the processors may include, but are not limited to, processing devices such as microprocessor MCUs or programmable logic devices FPGAs), a memory for storing data, a transmission device for communication functions, and an input / output interface. Among them, the memory, the transmission device, and the input / output interface are connected to the processor through a bus. In addition, it may further include: a display, a keyboard, and a cursor control device connected to the input / output interface. Those of ordinary skill in the art can understand that Figure 1 the structure shown is only schematic and does not limit the structure of the above-mentioned electronic device. For example, the computing device may also include more or fewer components than Figure 1 shown, or have a different configuration from Figure 1 shown.
[0048] It should be noted that the one or more processors and / or other data processing circuits described above can generally be referred to as "data processing circuits" herein. The data processing circuit can be embodied in software, hardware, firmware, or any combination thereof, in whole or in part. In addition, the data processing circuit can be a single independent processing module, or can be incorporated in whole or in part into any one of other elements in the computing device. As involved in the embodiments of the present disclosure, the data processing circuit is a kind of processor control (such as the selection of a variable resistance terminal path connected to an interface).
[0049] The memory can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the three-dimensional dynamic collision detection method in the embodiments of the present disclosure. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizes the three-dimensional dynamic collision detection of the above application program. The memory can include high-speed random access memory, and can also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memories. In some instances, the memory can further include a memory remotely set relative to the processor, and these remote memories can be connected to the computing device through a network. Examples of the above network include but are not limited to the Internet, intranet, local area network, mobile communication network, and combinations thereof.
[0050] The transmission device is used to receive or send data via a network. Specific examples of the above network can include a wireless network provided by a communication provider of the computing device. In one instance, the transmission device includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station and thus can communicate with the Internet. In one instance, the transmission device can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0051] The display can be, for example, a touch-screen liquid crystal display (LCD), which enables a user to interact with the user interface of the computing device.
[0052] It should be noted here that in some alternative embodiments, the above Figure 1 illustrated computing device can include hardware elements (including circuits), software elements (including computer code stored on a computer-readable medium), or a combination of both hardware elements and software elements. It should be pointed out that Figure 1 is only an example of a specific specific instance and is intended to show the types of components that can exist in the above computing device.
[0053] Figure 2It is a schematic diagram of a system for implementing the three-dimensional dynamic collision detection method of the present invention according to the present embodiment. Refer to Figure 2 As shown, the system includes: a computing terminal 100, a server 200, and a database 300. The computing terminal 100 and the server 200 are connected through a network, and the server 200 and the database 300 are connected through a network. In the present invention, the sub-thread and the main thread can run in the same computing device, for example, both run in the server 200. It is also possible that the sub-thread and the main thread run in different computing devices and interact through the network, that is, distributed computing is achieved. For example, the main thread can be carried out in the computing terminal 100, while the sub-thread can run in the server 200, and the main thread and the sub-thread interact through a network connection. As an alternative example, the database 300 can be separated from the computing terminal 100 and the server 200 and achieve interaction through a network connection, or the database 300 can be set in the computing terminal 100 or the server 200. In the present invention, the first list, the second list, the third list, the fourth list, the fifth list, and the sixth list are stored in the database 300.
[0054] As an alternative example, Figure 2 The computing terminal 100, the server 200, and the database 300 shown can be implemented in the form of virtual devices, and the three virtual devices are integrated in the same computer device.
[0055] As an alternative example, the three-dimensional dynamic collision detection method of the present invention can also run in an independent computer device. The main thread and the sub-thread are respectively different threads running on the same processor. A database component is installed in the computer device, and the first list, the second list, the third list, the fourth list, the fifth list, and the sixth list are stored in the database component.
[0056] Under the above operating environment, according to the first aspect of the present embodiment, a three-dimensional dynamic collision detection method is provided, which runs in the main thread and the sub-thread. Among them, data preprocessing is performed in the main thread, and it is calculated in the sub-thread whether a node collides. As Figure 3 shown, the main thread and the sub-thread can communicate with each other.
[0057] Specifically, as Figure 4 shown, a three-dimensional dynamic collision detection method includes:
[0058] The main thread processing flow and the sub-thread processing flow;
[0059] The main thread processing flow includes:
[0060] S402. Dynamically load scene data and store object group data in the database;
[0061] S404. Construct a node array that needs to be pairwise compared based on the object group data;
[0062] S406. Extract one or a combination of the following information according to the node array: bounding box, node, index, and matrix;
[0063] The sub - thread processing flow includes:
[0064] S408. Calculate the distance between nodes according to the node array, sort according to the distance between nodes, and record it in the first list;
[0065] S410. Determine the second list in which the positions of the nodes have changed according to the first list;
[0066] S412. Read the third list that records whether the nodes have collided;
[0067] S414. If the nodes in the second list are in the third list, delete the nodes from the third list;
[0068] S416. Calculate the position change amount of all nodes in the second list, and determine the fourth list of nodes that need to be detected for collision according to the position change amount;
[0069] S418. Detect whether the nodes in the fourth list have collided, and record the detection results in the third list.
[0070] In the present invention, three - dimensional dynamic collision detection is carried out separately in the main thread and the sub - thread. The main thread is responsible for data pre - processing, while the sub - thread dynamically calculates whether a collision occurs. In the main thread, sorting is performed according to the distance between nodes to obtain the first list, and then the second list is determined according to the position change situation. Through these two - layer screenings, a node list that needs to be subjected to collision detection is obtained. In the sub - thread, a third screening is performed according to the position change amount to obtain a set of nodes that may collide. On this basis, further screening is performed according to the collision threshold to obtain the fifth list. Then, a sixth list in which the collision results have changed is determined, and finally, whether the nodes in the sixth list have collided is detected. Through the method of the present invention, through layer - by - layer filtering of the screening conditions, the number of triangular faces that finally need to be compared and calculated is streamlined, and WebWorker is used to dynamically load the required data, which can effectively solve the memory management problem, improve the calculation efficiency, and reduce the user waiting time.
[0071] Optionally, in S402, the object group data refers to the data of the object shape displayed in three dimensions, that is, the association relationship between the mesh, nodes, and the mesh. The mesh contains geometric shape information, and the geometric shape information contains node positions, node indices, and grouping information. The grouping information contains the starting index subscript for drawing, the number of draws, and bounding box information. In S402, for example, in the case of dynamic scene loading, some data has been stored in IndexedDB, and a node array for pairwise comparison is constructed based on the input object group data.
[0072] Optionally, in S406, after the node array for pairwise comparison is constructed in S404, the node array is processed, including extracting information such as bounding boxes, nodes, indices, and matrices and transmitting them to WebWorker. This information will be used later by the child thread to calculate whether the nodes collide. Among them, the bounding box is a geometric body used to represent the spatial range of an object. Its core idea is to approximately replace a complex geometric object with a geometric body that is slightly larger in volume but has simple characteristics. The mesh is a data structure used to represent shapes in three-dimensional space. The mesh consists of nodes, edges, and faces. Nodes are the most basic components and are the points that make up the mesh shape. The node index is a numerical identifier used to reference these nodes. It should be noted that in the mesh, nodes are also known as vertices.
[0073] The main function of the node index is to reuse node data when creating a mesh, thereby reducing the data volume and optimizing memory usage. For example, a cube only requires 8 nodes, but can have 12 edges and 6 faces. By using indices, it is possible to avoid repeatedly storing the node coordinates for each face and instead reference these nodes through indices.
[0074] The following gives an example of a node index: Suppose there is a simple triangular mesh composed of the following three nodes:
[0075] Node A: (x1, y1, z1), Node B: (x2, y2, z2), and Node C: (x3, y3, z3), where x, y, z are in a three-dimensional coordinate system, and Node A, Node B, and Node C are three points on the coordinate system.
[0076] If the node coordinates are directly defined in each triangle, then the coordinates of these three nodes will be repeatedly stored in each triangle. The method of using node indices is as follows:
[0077] 1. Define nodes:
[0078] vertices = [(x1, y1, z1),(x2, y2, z2),(x3, y3, z3)]
[0079] 2. Define indices:
[0080] indices = [0, 1, 2 # The first triangle, using nodes 0, 1, 2 / / or for the second triangle, if any, more index references to the same or new nodes can be added].
[0081] In the above example, each number in the indices array is an index that points to an element in the vertices array. This way can reduce data redundancy and is very effective especially when dealing with complex meshes.
[0082] The 3D transformation matrix is a mathematical tool for handling geometric transformations in 3D space in computer graphics. Through a 4×4 homogeneous coordinate matrix, translation, rotation, and scaling of geometric bodies are represented uniformly.
[0083] As an optional example, information such as the bounding box, nodes, indices, and matrix can be extracted according to the node array on the main thread, while the operations of calculating the distance between nodes, sorting according to the distance between nodes, and recording them in the first list can be completed by a child thread.
[0084] Optionally, the main thread can also receive the result of whether the nodes collide sent by the child thread and store the result in a third list for recording whether the nodes collide. That is to say, the third list is used to store information on whether the nodes collide. The main thread performs the write operation on the third list, and the child thread can read the information in the third list to determine which nodes need to be detected for collision.
[0085] Optionally, after the child thread detects the result of whether there is a collision, instead of sending the detection result to the main thread, the child thread directly writes the detection result into the third list. When the next collision detection is required, the child thread directly reads the content of the third list for further detection.
[0086] Optionally, in S408, sorting according to the distance between nodes and recording them in the first list, sorting according to the distance between nodes can be one of the following: sorting from largest to smallest according to the distance between nodes, or sorting from smallest to largest according to the distance between nodes.
[0087] Optionally, in S410, a second list in which the node positions have changed is determined according to the first list. For example, by traversing all nodes, the nodes whose positions have changed are filtered out to form the second list, and these nodes serve as the basic objects for dynamic collision detection to further determine which nodes need to be detected for collisions.
[0088] Optionally, in S412, a third list recording whether nodes have collided is read. If a node in the second list is in the third list, the node is deleted from the third list. Because if a certain node is included in the second list, it means that the position of this node has changed, and the result of the previous collision detection may also change and cannot be used anymore. Therefore, the record of this node needs to be deleted from the third list.
[0089] Optionally, in S414, the calculation of the position change amounts of all nodes in the second list, and the determination of a fourth list of nodes that need to be detected for collisions according to the position change amounts includes:
[0090] Calculate the position change amounts of all nodes in the second list;
[0091] For each node a in the second list, check whether the distance between the node b recorded in the first list and the node a is less than the position change amount of the node a. If the distance between the node b and the node a is less than the position change amount of the node a, then the node b needs to be detected for collisions and the node b is written into the fourth list;
[0092] Update the distances from other nodes according to the position of the node b and re - sort.
[0093] In S416, first calculate the position change amounts of all nodes in the second list. Because the second list only records the nodes whose positions have changed, but the specific position change amount still needs to be calculated. Therefore, the child thread calculates the position change amounts of all nodes in the second list. Then, according to the data (node b) in the first list obtained in step S404 and the position change amounts calculated in this step, filter out the nodes that may collide. For example, if the distance of a certain node a in the second list has changed by 3, then other nodes (node b) in the first list whose distance from the node a is less than 3 need to be recalculated, and other nodes (node b) in the first list whose distance from the node a is greater than 3 will not collide this time if they did not collide last time. Finally, for the nodes in the fourth list, update the distances from other nodes and re - sort. Among them, the sorting method can be sorting from small to large or from large to small.
[0094] Optionally, in S418, detecting whether the nodes in the fourth list have collided includes:
[0095] Step 418-1: Determine a fifth list of nodes that need to be detected for collisions based on the collision threshold and the fourth list.
[0096] Step 418-2: Determine a sixth list of nodes where the collision results have changed.
[0097] Step 418-3: Read geometric data from the database. If data is missing, send a request message to the main thread.
[0098] Step 418-4: Determine whether a collision has occurred for the nodes based on the geometric data and the sixth list.
[0099] Optionally, in Step 418-1, determining the fifth list of nodes that need to be detected for collisions based on the collision threshold and the fourth list includes:
[0100] If the current collision threshold is smaller than the previous one, directly select the changed nodes from the previous result to obtain the fifth list of nodes that need to be detected for collisions.
[0101] If the current collision threshold is larger than the previous one, append the nodes that did not collide in the previous collision result to obtain the fifth list of nodes that need to be detected for collisions.
[0102] It should be noted that the collision threshold is a threshold set before the child thread detects collisions. The collision threshold for each detection can be different. Compared with the previous detection, this collision threshold can be larger or smaller. For example, the collision threshold was 5 in the previous detection and 7 in this detection. Another example is that the collision threshold was 6 in the previous detection and 4 in this detection.
[0103] That is to say, in Step 418-1, it is determined whether the collision threshold has changed. If the current collision threshold is smaller than the previous one, the nodes that did not collide in the previous time will not collide this time either, and the current result will be a subset of the previous collision. Directly select the changed nodes from the previous result for comparison, that is, the fifth list. If the current collision threshold is larger than the previous one, the nodes that collided in the previous time will definitely collide this time. Then, append based on the previous collision result, that is, the nodes that collided in the previous time do not need to be recalculated and the results can be directly used; the nodes that did not collide in the previous time are appended to the list of nodes that need to be calculated this time to obtain the fifth list.
[0104] Optionally, in Step 418-2, for the nodes in the fifth list, determine whether there was a bounding box for the previous collision and whether the previous collision point exists in the current intersection box. If so, it is considered that a collision has occurred.
[0105] Optionally, in step 418-2, determine the sixth list where the collision result changes, which is the set of points in the current intersection box where the last collision point does not exist.
[0106] Optionally, in step 418-4, according to the geometric data and the sixth list, determine whether a node collides. Specifically, as Figure 5 shown, it includes S502, S504, S506, S508, S510, S512, S514, and S516:
[0107] S502, that is, step A: successively determine whether the bounding boxes of the grids intersect. If they intersect, execute step B; where the shape and structure of the grid are determined by the positions and connection relationships of the nodes.
[0108] As another alternative, in this step, if they do not intersect, it is determined that there is no collision. If they intersect, execute step B:
[0109] S504, that is, step B: for any two groups GroupA and GroupB in the grid, determine whether the bounding boxes of GroupA and GroupB intersect. If they intersect, execute step C.
[0110] As another alternative, in this step, for any two groups GroupA and GroupB in the grid, determine whether the bounding boxes of GroupA and GroupB intersect. If they do not intersect, it is determined that there is no collision. If they intersect, execute step C;
[0111] where each grid includes multiple groups Group. For all Groups in the grid, make pairwise judgments. For the sake of description, the two Groups being judged are respectively denoted as GroupA and GroupB.
[0112] S506, that is, step C: find the intersection of the bounding boxes of GroupA and GroupB, and determine whether the intersection is empty. If the intersection is not empty, execute step D.
[0113] As another alternative, in this step, find the intersection of the bounding boxes of GroupA and GroupB, and determine whether the intersection is empty. If the intersection is empty, it is determined that there is no collision. If the intersection is not empty, execute step D;
[0114] In this step, find the intersection of the bounding boxes of groupA and groupB, and determine whether the intersection box is empty. If it is not empty, it means there may be a collision, and proceed to the next step.
[0115] S508, that is, step D: divide the intersection of the bounding boxes into 8 octant intersection boxes by space;
[0116] S510, that is, step E: Traverse the triangular faces in the Group A and the Group B respectively, and sequentially determine whether the nodes are within the octant intersection boxes numbered from 1 to 8 or whether the triangular faces intersect with the octant intersection boxes numbered from 1 to 8. Store the qualified triangular faces into the arrays triListA and triListB of the octant intersection boxes numbered from 1 to 8 respectively;
[0117] Each octant intersection box corresponds to a pair of triListA and triListB, that is, there are a total of 8 pairs. triListA represents the set (array) of triangular faces belonging to Group A that may collide within the current octant intersection box, and triListB represents the set (array) of triangular faces belonging to Group B that may collide under the same octant intersection box.
[0118] A triangular face is a triangle composed of three nodes. The data structure can be simply represented as:
[0119] [ [(x1, y1, z1),(x2, y2, z2),(x3, y3, z3)], [(x1', y1', z1'), (x2',y2', z2'),(x3', y3', z3') ],•••].
[0120] S512, that is, step F: Loop through the 8 octant intersection boxes, and respectively determine whether the lengths of the arrays triListA and triListB are greater than 0. If both are greater than 0, then execute step G.
[0121] As another alternative, in this step, loop through the 8 octant intersection boxes, and respectively determine whether the lengths of the arrays triListA and triListB are greater than 0. If both are greater than 0, then execute step G. If not, then it is determined that there is no collision;
[0122] In this step, loop through the 8 octant intersection boxes, and then respectively determine whether the lengths of the arrays triListA and triListB are greater than 0. If both are greater than zero, it indicates that there are potential collision points, and then proceed to the next step. In the present invention, the purpose of dividing the octant intersection boxes is to optimize the number of triangular faces to be compared, especially in cases where the mesh is particularly complex, the spatial distribution of triangular faces is uneven, strip-shaped, belt-shaped, hollowed out, etc.
[0123] S514, that is, step G: Calculate the minimum distance between pairs of triangular face groups within the 8 octant intersection boxes respectively, and determine whether the minimum distance is less than a preset collision threshold. If the minimum distance is less than the preset collision threshold, it is considered that a collision has occurred, and return to execute step A.
[0124] As another alternative, in this step, the minimum distance between each pair of triangular face groups is calculated respectively within the 8 octant intersection boxes, and it is determined whether the minimum distance is less than a preset collision threshold. If the minimum distance is greater than the preset collision threshold, it is considered that no collision has occurred and step H is executed; if the minimum distance is less than the preset collision threshold, it is considered that a collision has occurred, and step A is executed again.
[0125] S516, that is, step H: Send the result of determining whether a collision has occurred to the main thread.
[0126] In the present invention, when it reaches S516, a collision detection of the sub-thread is completed, and the sub-thread sends the detection result to the main thread. After receiving the detection result, the main thread writes the detection result into the third list.
[0127] Optionally, as an alternative example, the sub-thread can directly write the collision detection result into the third list by itself without sending the detection result to the main thread.
[0128] Using the three-dimensional dynamic collision detection method of the present invention, through layer-by-layer screening of whether the node position changes, the amount of position change, whether the position becomes larger or smaller, the collision threshold, the intersection box, the bounding box, etc., the number of triangular faces that finally need to be compared and calculated is streamlined, and WebWorker is used to dynamically load the required data, which can effectively solve the problem of memory management, improve the calculation efficiency, and reduce the user waiting time. In addition, the three-dimensional dynamic collision detection method of the present invention uses the main thread for data preprocessing and the sub-thread for dynamic collision detection, thereby further improving the calculation efficiency and reducing the user waiting time.
[0129] In addition, referring to Figure 1 As shown, according to the second aspect of this embodiment, a storage medium is provided. The storage medium includes a stored program, wherein when the program runs, the three-dimensional dynamic collision detection method described in any one of the above is executed by a processor.
[0130] It should be noted that for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.
[0131] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation. Based on such an understanding, the technical solution of the present invention, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions for causing a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in various embodiments of the present invention.
[0132] Embodiment 2
[0133] Figure 6 Fig. shows a three-dimensional dynamic collision detection device 600 according to the present embodiment. The device 600 corresponds to the method described in the first aspect of Embodiment 1. Refer to Figure 6 As shown, the device 600 includes: a sub-thread module 620; the sub-thread module 620 is configured to:
[0134] Calculate the distance between nodes according to the node array, sort according to the distance between nodes and record it in the first list; wherein, the node array is a pre-constructed node array that needs to be pairwise compared;
[0135] Determine a second list of nodes whose positions have changed according to the first list;
[0136] Read the third list recording whether the nodes have collided;
[0137] If the nodes in the second list are in the third list, delete the nodes from the third list;
[0138] Calculate the position change amount of all nodes in the second list, and determine a fourth list of nodes that need to be detected for collision according to the position change amount;
[0139] Detect whether the nodes in the fourth list have collided, and record the detection result in the third list.
[0140] Optionally, the device 600 further includes a main-thread module 610; the main-thread module 610 is configured to:
[0141] Dynamically load scene data and store object group data in the database;
[0142] Construct a node array that needs to be pairwise compared according to the object group data.
[0143] Extract one or a combination of the following information based on the node array: bounding box, nodes, indices, and matrices.
[0144] Optionally, calculating the position change amounts of all nodes in the second list, and the fourth list of nodes for which it is necessary to detect collisions according to the position change amounts includes:
[0145] Calculate the position change amounts of all nodes in the second list;
[0146] For each node a in the second list, check whether the distance between the node b recorded in the first list and the node a is less than the position change amount of the node a. If the distance between the node b and the node a is less than the position change amount of the node a, then it is necessary to detect whether the node b collides, and write the node b into the fourth list;
[0147] Update the distances from other nodes according to the position of the node b, and re - sort.
[0148] Optionally, detecting whether the nodes in the fourth list collide includes:
[0149] Determine a fifth list of nodes for which it is necessary to detect collisions according to the collision threshold and the fourth list;
[0150] Determine a sixth list of nodes for which the collision results have changed;
[0151] Read geometric data from the database. If the data is missing, send a request message to the main thread;
[0152] Judge whether the nodes collide according to the geometric data and the sixth list.
[0153] Optionally, determining a fifth list of nodes for which it is necessary to detect collisions according to the collision threshold and the fourth list includes:
[0154] If the current collision threshold is smaller than the previous collision threshold, directly select the changed nodes from the previous result to obtain the fifth list of nodes for which it is necessary to detect collisions;
[0155] If the current collision threshold is larger than the previous collision threshold, append the nodes that did not collide last time to the previous collision result to obtain the fifth list of nodes for which it is necessary to detect collisions.
[0156] Optionally, judging whether the nodes collide according to the geometric data and the sixth list includes:
[0157] Step A: Sequentially judge whether the bounding boxes of the grids intersect. If they intersect, execute Step B: Among them, the shape and structure of the grid are determined by the positions and connection relationships of the nodes;
[0158] Step B: For any two groups GroupA and GroupB in the grid, determine whether the bounding boxes of GroupA and GroupB intersect. If they intersect, execute Step C;
[0159] Step C: Find the intersection of the bounding boxes of GroupA and GroupB, and determine whether the intersection is empty. If the intersection is not empty, execute Step D;
[0160] Step D: Divide the intersection of the bounding boxes into 8 octant intersection boxes by space;
[0161] Step E: Traverse the triangular faces in GroupA and GroupB respectively, and sequentially determine whether the triangular faces meet the conditions. Store the triangular faces that meet the conditions into the arrays triListA and triListB of the 1st to 8th octant intersection boxes respectively; where whether they meet the conditions includes: determining whether the nodes of the triangular face are inside the 1st to 8th octant intersection boxes or whether the triangular face intersects with the 1st to 8th octant intersection boxes;
[0162] Step F: Loop through the 8 octant intersection boxes, and respectively determine whether the lengths of the arrays triListA and triListB are greater than 0. If both are greater than 0, execute Step G;
[0163] Step G: Calculate the minimum distance between pairs of triangular faces in each of the 8 octant intersection boxes respectively, and determine whether the minimum distance is less than a preset collision threshold. If the minimum distance is less than the preset collision threshold, it is considered that a collision has occurred, and return to execute Step A;
[0164] Step H: Send the result of determining whether a collision has occurred to the main thread.
[0165] It should be noted that the device in Embodiment 2 and the method in Embodiment 1 belong to the same inventive concept, solve the same technical problem, and achieve the same technical effect. The device in Embodiment 2 can implement all the methods in Embodiment 1, and the same parts will not be elaborated here.
[0166] Thus, according to this embodiment, by using the three-dimensional dynamic collision detection device of the present invention, through the main thread module and the sub-thread module, layer-by-layer screening is performed on whether the node positions change, the amount of position change, whether the position becomes larger or smaller, the collision threshold, the intersection box, the bounding box, etc., to streamline the number of triangular faces that ultimately need to be compared and calculated. And by using WebWorker to dynamically load the required data, the problem of memory management can be effectively solved, the calculation efficiency can be improved, and the user waiting time can be reduced. In addition, the three-dimensional dynamic collision detection method of the present invention uses the main thread for data preprocessing and the sub-thread for dynamic collision detection, thereby further improving the calculation efficiency and reducing the user waiting time.
[0167] Embodiment 3
[0168] Figure 7 Fig. shows a three-dimensional dynamic collision detection device 700 according to this embodiment, and this device 700 corresponds to the method described in the first aspect of Embodiment 1. Refer to Figure 7 As shown, the device 700 includes:
[0169] A processor 710; and
[0170] A memory 720, connected to the processor, for providing instructions for the processor to perform the following processing steps:
[0171] Calculate the distances between nodes according to the node array, sort according to the distances between nodes and record them in the first list; wherein, the node array is a pre-constructed node array that needs to be pairwise compared;
[0172] Determine a second list of nodes whose positions have changed according to the first list;
[0173] Read a third list recording whether nodes have collided;
[0174] If the nodes in the second list are in the third list, delete the nodes from the third list;
[0175] Calculate the amount of position change of all nodes in the second list, and determine a fourth list of nodes that need to be detected for collision according to the amount of position change;
[0176] Detect whether the nodes in the fourth list have collided, and record the detection results in the third list.
[0177] Optionally, before the operation of calculating the distances between nodes according to the node array, it further includes:
[0178] Dynamically load the scene data and store the object group data into the database;
[0179] Construct a node array that needs to be pairwise compared based on the object group data; and
[0180] Extract one or a combination of the following information based on the node array: bounding box, node, index, and matrix.
[0181] Optionally, the fourth list of nodes that need to detect whether a collision occurs according to the position change amount of all nodes in the second list includes:
[0182] Calculate the position change amount of all nodes in the second list;
[0183] For each node a in the second list, check whether the distance between the node b recorded in the first list and the node a is less than the position change amount of the node a. If the distance between the node b and the node a is less than the position change amount of the node a, then the node b needs to detect whether a collision occurs, and write the node b into the fourth list;
[0184] Update the distances from other nodes according to the position of the node b and re - sort.
[0185] Optionally, the detection of whether a collision occurs among the nodes in the fourth list includes:
[0186] Determine a fifth list of nodes that need to detect collisions according to the collision threshold and the fourth list;
[0187] Determine a sixth list of nodes where the collision result has changed;
[0188] Read geometric data from the database. If the data is missing, send a request message to the main thread;
[0189] Judge whether a collision occurs to the nodes according to the geometric data and the sixth list.
[0190] Optionally, the determination of a fifth list of nodes that need to detect collisions according to the collision threshold and the fourth list includes:
[0191] If the current collision threshold is smaller than the previous collision threshold, directly select the changed nodes from the previous result to obtain the fifth list of nodes that need to detect collisions;
[0192] If the current collision threshold is larger than the previous collision threshold, append the nodes that did not collide last time to the previous collision result to obtain the fifth list of nodes that need to detect collisions.
[0193] Optionally, the judgment of whether a collision occurs to the nodes according to the geometric data and the sixth list includes:
[0194] Step A: Determine in sequence whether the bounding boxes of the meshes intersect. If they intersect, execute Step B. Herein, the shape and structure of the mesh are determined by the positions and connection relationships of the nodes.
[0195] Step B: For any two groups GroupA and GroupB in the mesh, determine whether the bounding boxes of GroupA and GroupB intersect. If they intersect, execute Step C.
[0196] Step C: Obtain the intersection of the bounding boxes of GroupA and GroupB, and determine whether the intersection is empty. If the intersection is not empty, execute Step D.
[0197] Step D: Divide the intersection of the bounding boxes into 8 octant intersection boxes according to space.
[0198] Step E: Traverse the triangular faces in GroupA and GroupB respectively, and determine in sequence whether the triangular faces meet the conditions. Store the triangular faces that meet the conditions into the arrays triListA and triListB of the 1st to 8th octant intersection boxes respectively. Whether meeting the conditions includes: determining whether the nodes of the triangular face are within the 1st to 8th octant intersection boxes or whether the triangular face intersects with the 1st to 8th octant intersection boxes.
[0199] Step F: Loop through the 8 octant intersection boxes, and determine respectively whether the lengths of the arrays triListA and triListB are greater than 0. If both are greater than 0, execute Step G.
[0200] Step G: Calculate the minimum distance between pairs of triangular faces respectively within the 8 octant intersection boxes, and determine whether the minimum distance is less than a preset collision threshold. If the minimum distance is less than the preset collision threshold, it is considered that a collision occurs, and return to execute Step A.
[0201] Step H: Send the result of determining whether a collision occurs to the main thread.
[0202] Using the three-dimensional dynamic collision detection device of this embodiment, through the main thread module and the sub-thread module, it respectively screens layer by layer through whether the node positions change, the amount of position change, whether the position becomes larger or smaller, the collision threshold, the intersection box, the bounding box, etc., streamlines the number of triangular faces that ultimately need to be compared and calculated, and uses WebWorker to dynamically load the required data, which can effectively solve the problem of memory management, improve the calculation efficiency, and reduce the user waiting time. In addition, the three-dimensional dynamic collision detection method of the present invention uses the main thread for data preprocessing and the sub-thread for dynamic collision detection, thereby further improving the calculation efficiency and reducing the user waiting time.
[0203] It should be noted that the device in Embodiment 3 and the method in Embodiment 1 belong to the same inventive concept, solve the same technical problems, and achieve the same technical effects. The device in Embodiment 3 can implement all the methods in Embodiment 1, and the similarities will not be elaborated here.
[0204] The serial numbers of the embodiments of the present invention above are only for description and do not represent the superiority or inferiority of the embodiments.
[0205] In the above embodiments of the present invention, the descriptions of the respective embodiments have their own emphases. For the parts not elaborated in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
[0206] In the several embodiments provided in the present application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the couplings or direct couplings or communication connections shown or discussed with each other can be through some interfaces. The indirect couplings or communication connections of the units or modules can be in electrical or other forms.
[0207] The units described as separate components may or may not be physically separated. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0208] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.
[0209] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media that can store program codes, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disc.
[0210] The foregoing are only the preferred embodiments of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present invention.
Claims
1. A three-dimensional dynamic collision detection method, characterized in that: include: According to the node array, the distance between nodes is calculated, and the nodes are sorted according to the distance between nodes and recorded in the first list; wherein the node array is a pre-built node array that needs to be compared two by two; Determine a second list of node positions changed according to the first list; Read the third list that records whether the nodes collide; If a node in the second list is in the third list, deleting the node from the third list; Calculating the position changes of all nodes in the second list, and determining a fourth list of nodes that need to be checked for collision according to the position changes; and Detect whether the nodes in the fourth list collide, and record the detection result in the third list; The step of calculating the position changes of all nodes in the second list and determining the fourth list of nodes that need to be detected for collision according to the position changes includes: Calculate the position changes of all nodes in the second list; For each node a in the second list, check whether the distance between the node b recorded in the first list and the node a is less than the position change of the node a; if the distance between the node b and the node a is less than the position change of the node a, the node b needs to detect whether there is a collision, and write the node b into the fourth list; According to the position of the node b, the distances to other nodes are updated and re-sorted.
2. The method according to claim 1, characterized in that Before the operation of calculating the distance between nodes according to the node array, the method further includes: Dynamically load scene data and store object group data into the database; Constructing a node array that needs to be compared two by two according to the object group data; and According to the node array, extract one or a combination of the following information: bounding box, node, index and matrix.
3. The method according to claim 1, characterized in that: The detecting whether the nodes in the fourth list collide with each other comprises: Determine a fifth list for which collision detection is required according to the collision threshold and the fourth list; A sixth table determining changes in collision results; Read geometric data from the database and send a request to the main thread if data is missing; It is determined whether nodes collide based on the geometric data and the sixth list.
4. The method according to claim 3, characterized in that The fifth list that needs to be detected for collision is determined according to the collision threshold and the fourth list, comprising: If the current collision threshold is smaller than the previous collision threshold, the changed nodes are directly selected from the previous result to obtain the fifth list that needs to be detected for collision; If the current collision threshold is larger than the previous collision threshold, then based on the previous collision result, the nodes that did not collide last time are added to obtain a fifth list that needs to be detected for collision.
5. The method according to claim 3, characterized in that: The determining, according to the geometric data and the sixth list, whether the nodes collide comprises: Step A: determine whether the bounding boxes of the grids intersect in turn, and if they do, execute step B: wherein the shape and structure of the grid are determined by the position and connection relationship of the nodes; Step B: for any two groups GroupA and GroupB in the grid, determine whether the bounding boxes of GroupA and GroupB intersect, and if so, execute step C; Step C: finding the intersection of the bounding boxes of Group A and Group B, and determining whether the intersection is empty. If the intersection is not empty, executing step D; Step D: Divide the intersection of the bounding boxes into 8 octant intersection boxes according to space; Step E: traverse the triangular faces in GroupA and GroupB respectively, determine whether the triangular faces meet the conditions in turn, and store the triangular faces that meet the conditions in the arrays triListA and triListB of the octant intersection boxes No. 1 to 8 respectively; wherein whether the conditions are met includes: determining whether the nodes of the triangular face are within the octant intersection boxes No. 1 to 8 or whether the triangular face intersects with the octant intersection boxes No. 1 to 8; Step F: loop through the eight octant intersection boxes, and determine whether the lengths of the array triListA and the array triListB are greater than 0, and if both are greater than 0, execute step G; Step G: Calculate the minimum distance between two triangle face groups in the eight octant intersection boxes respectively, and determine whether the minimum distance is less than a preset collision threshold. If the minimum distance is less than the preset collision threshold, it is considered that a collision occurs, and return to step A. Step H: Send the result of determining whether a collision occurs to the main thread.
6. A storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is run, the processor executes the method according to any one of claims 1 to 5.
7. A three-dimensional dynamic collision detection device, characterized in that: The invention comprises a sub-thread module, wherein the sub-thread module is configured to: According to the node array, the distance between nodes is calculated, and the nodes are sorted according to the distance between nodes and recorded in the first list; wherein the node array is a pre-built node array that needs to be compared two by two; Determine a second list of node positions changed according to the first list; Read the third list that records whether the nodes collide; If a node in the second list is in the third list, deleting the node from the third list; Calculating the position changes of all nodes in the second list, and determining a fourth list of nodes that need to be detected for collision according to the position changes; Detect whether the nodes in the fourth list collide, and record the detection result in the third list; The step of calculating the position changes of all nodes in the second list and determining the fourth list of nodes that need to be detected for collision according to the position changes includes: Calculate the position changes of all nodes in the second list; For each node a in the second list, check whether the distance between the node b recorded in the first list and the node a is less than the position change of the node a; if the distance between the node b and the node a is less than the position change of the node a, the node b needs to detect whether there is a collision, and write the node b into the fourth list; According to the position of the node b, the distances to other nodes are updated and re-sorted.
8. The device according to claim 7, characterized in that Also included is a main thread module, the main thread module being configured to: Dynamically load scene data and store object group data into the database; Constructing a node array that needs to be compared two by two according to the object group data; and According to the node array, extract one or a combination of the following information: bounding box, node, index and matrix.
9. A three-dimensional dynamic collision detection device, characterized in that: include: processor; as well as A memory, connected to the processor, configured to provide the processor with instructions for processing the following processing steps: According to the node array, the distance between nodes is calculated, and the nodes are sorted according to the distance between nodes and recorded in the first list; wherein the node array is a pre-built node array that needs to be compared two by two; Determine a second list of node positions changed according to the first list; Read the third list that records whether the nodes collide; If a node in the second list is in the third list, deleting the node from the third list; Calculating the position changes of all nodes in the second list, and determining a fourth list of nodes that need to be detected for collision according to the position changes; Detect whether the nodes in the fourth list collide, and record the detection result in the third list; The step of calculating the position changes of all nodes in the second list and determining the fourth list of nodes that need to be detected for collision according to the position changes includes: Calculate the position changes of all nodes in the second list; For each node a in the second list, check whether the distance between the node b recorded in the first list and the node a is less than the position change of the node a; if the distance between the node b and the node a is less than the position change of the node a, the node b needs to detect whether there is a collision, and write the node b into the fourth list; According to the position of the node b, the distances to other nodes are updated and re-sorted.
Citation Information
Patent Citations
Polygon cutting method based on bounding box tree, electronic equipment and storage medium
CN113034515A
Space collision detection method and apparatus, and electronic device
WO2023159882A1