Three-dimensional dynamic collision detection method and device and storage medium
By using filtering conditions and WebWorker technology in three-dimensional dynamic collision detection, the calculation amount is streamlined and tasks are allocated to the main thread and child thread, the problem of long calculation time under the large data volume is solved, and efficiency and user experience are improved.
Patent Information
- Application Number
- CN202510407282.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-05-02
- 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 CN119917246A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computing technology, and in particular to a three-dimensional dynamic collision detection method, device and storage medium. Background Art
[0002] In the 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 accurately simulate and test the interactions between physical structures, such as the assembly of mechanical parts, structural analysis of buildings, etc. In the prior art, the bounding sphere and bounding box of the constructed object are mainly used for intersection detection. This solution is fast in execution, but the results are inaccurate, and irregular objects directly lose their correctness. On this basis, traversing the triangular mesh data of the two objects and performing pairwise intersection detection of the triangular faces can solve the problem of accuracy. However, this technical solution has a large amount of calculation and a long calculation time when the amount of data is large, which will cause the browser page to freeze and lose response, resulting in a poor user experience.
[0003] Therefore, how to improve computing efficiency and reduce user waiting time while ensuring correct collision detection is a technical problem that needs to be solved urgently. Summary of the invention
[0004] The embodiments of the present disclosure provide a three-dimensional dynamic collision detection method, device and storage medium to at least solve the technical problems existing in the prior art such as large amount of calculation and long collision detection calculation time when the amount of data is large, which may cause the browser page to freeze, lose response and have a poor user experience.
[0005] According to one aspect of an embodiment of the present disclosure, a three-dimensional dynamic collision detection method is provided, comprising: 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.
[0006] According to another aspect of the embodiments of the present disclosure, a three-dimensional dynamic collision detection device is further provided, including 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.
[0007] 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 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.
[0008] The dynamic collision detection method of the present invention can filter through layers of screening conditions to reduce the number of triangles that need to be compared and calculated, and use WebWorker to dynamically load the required data, which can effectively solve the problem of memory management, improve computing efficiency, and reduce user waiting time. The present invention divides tasks into main threads and sub-threads, reduces unnecessary calculations, improves the operating efficiency of the software, and enables designers to obtain feedback faster and optimize design solutions. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] The drawings described herein are used to provide a further understanding of the present disclosure and constitute a part of the present application. The illustrative embodiments of the present disclosure and their descriptions are used to explain the present disclosure and do not constitute an improper limitation on the present disclosure. In the drawings: Figure 1 is a hardware structure block diagram of a computing device for implementing the method according to Embodiment 1 of the present disclosure; Figure 2 is a schematic diagram of a system for executing a three-dimensional dynamic collision detection method according to Embodiment 1 of the present disclosure; Figure 3 is a thread division schematic diagram according to the first aspect of Embodiment 1 of the present disclosure; Figure 4 is a schematic flow chart of a three-dimensional dynamic collision detection method according to the first aspect of Embodiment 1 of the present disclosure; Figure 5 is a schematic flow chart of the steps of determining whether there is a collision in a grid according to the first aspect of Embodiment 1 of the present disclosure; Figure 6 is a schematic diagram of a three-dimensional dynamic collision device according to Embodiment 2 of the present disclosure; Figure 7 It is a schematic diagram of another three-dimensional dynamic collision device described in Example 3 of the present disclosure. DETAILED DESCRIPTION
[0010] In order 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 drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only embodiments of a part of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative work should fall within the scope of protection of the present disclosure.
[0011] 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 are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, 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 "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.
[0012] Definition of terms: Mesh, in CAD (computer-aided design) and CAE (computer-aided engineering), Mesh refers to "mesh" or "meshing". A mesh is a data structure that is usually used to represent objects or scenes in three-dimensional space. It consists of a series of interconnected nodes, edges, and faces. In finite element analysis, a mesh is the result of discretizing a complex geometric model for numerical calculation and simulation analysis. 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 the 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 relationship of the nodes defines the topological structure of the unit and determines how the mesh is divided. The shape and structure of the mesh are determined by the location and connection relationship of the nodes.
[0013] The octant intersection box refers to the division form of the bounding box, which divides the space into eight parts (i.e., octant space) through a specific center point, and each part can be regarded as a subspace.
[0014] Worker refers to a thread, which is used to process tasks in parallel.
[0015] WebWorker is a technology that implements multithreading in browsers, allowing JavaScript scripts to run in background threads, thus avoiding long-running tasks blocking the main thread.
[0016] In the 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 accurately simulate and test the interactions between physical structures, such as the assembly of mechanical parts, structural analysis of buildings, etc. Accurate collision detection is essential to ensure the accuracy and safety of the design. The three-dimensional dynamic collision detection method provided by the present invention improves the operating efficiency of the software by reducing unnecessary calculations, allowing designers to obtain feedback faster and optimize design solutions. In the simulation and training system, the user's operations can be simulated in real time to provide timely feedback on whether the user's operations are correct. At the same time, in applications such as WebWorker, it is ensured that the software interface can remain responsive even when performing large-scale calculations, thereby improving the user experience.
[0017] Example 1 According to this embodiment, a three-dimensional dynamic method embodiment 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 an order different from that shown here.
[0018] 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 FIG. 1 shows a hardware structure block diagram of a computing device for implementing three-dimensional dynamic collision detection. Figure 1 As shown, the computing device may include one or more processors (the processor may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory for storing data, a transmission device for communication functions, and an input / output interface. The memory, the transmission device, and the input / output interface are connected to the processor via a bus. In addition, it may also include: a display, a keyboard, and a cursor control device connected to the input / output interface. A person skilled in the art can understand that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0019] It should be noted that the one or more processors and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computing device. As involved in the embodiments of the present disclosure, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0020] 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 embodiment 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, realizing the three-dimensional dynamic collision detection of the above-mentioned application. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the computing device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0021] The transmission device is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computing device. In one example, the transmission device includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0022] The display may be, for example, a touch screen liquid crystal display (LCD) that may enable a user to interact with a user interface of the computing device.
[0023] It should be noted that, in some optional embodiments, the above Figure 1 The computing device shown may 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. Figure 1 This is merely one example of a particular embodiment and is intended to illustrate the types of components that may be present in the computing devices described above.
[0024] Figure 2 is a schematic diagram of a system for implementing the three-dimensional dynamic collision detection method of the present invention according to this embodiment. Figure 2As 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 via a network, and the server 200 and the database 300 are connected via a network. In the present invention, the sub-thread and the main thread can be run in the same computing device, for example, both are run in the server 200. It is also possible that the sub-thread and the main thread are run in different computing devices and interact through the network, that is, distributed computing is realized. For example, the main thread can be carried out in the computing terminal 100, and the sub-thread can be run in the server 200, and the main thread and the sub-thread interact through the network connection. As an optional example, the database 300 can be separated from the computing terminal 100 and the server 200, and the interaction is realized through the network connection, or the database 300 can be set in the computing terminal 100 or in 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.
[0025] As an optional example, Figure 2 The computing terminal 100, server 200 and database 300 shown in the figure can be implemented in the form of virtual devices, integrating the three virtual devices into the same computer device.
[0026] As an optional 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 child thread are different threads running on the same processor, and 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.
[0027] In the above operating environment, according to the first aspect of this embodiment, a three-dimensional dynamic collision detection method is provided, which runs in the main thread and the sub-thread. In the main thread, data preprocessing is performed, and in the sub-thread, whether a node collides is calculated. Figure 3 As shown, the main thread and the child threads can communicate with each other.
[0028] Specifically, Figure 4 As shown, a three-dimensional dynamic collision detection method includes: Main thread processing flow and sub-thread processing flow; The main thread processing flow includes: S402, dynamically load scene data and store object group data into a database; S404, constructing a node array that needs to be compared two by two according to the object group data; S406, extracting one or a combination of the following information according to the node array: bounding box, node, index and matrix; The sub-thread processing flow includes: S408, calculating the distances between nodes according to the node array, sorting the nodes according to the distances between nodes and recording them in a first list; S410, determining a second list in which node positions have been changed according to the first list; S412, reading a third list recording whether a node collision occurs; S414. If a node in the second list is in the third list, delete the node from the third list; S416, 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; S418: Detect whether the nodes in the fourth list collide, and record the detection result in the third list.
[0029] In the present invention, three-dimensional dynamic collision detection is divided into a main thread and a sub-thread for separate execution. The main thread is responsible for data preprocessing, while the sub-thread dynamically calculates whether a collision occurs. In the main thread, the first list is obtained according to the distance between nodes, and then the second list is determined according to the position change. Through these two layers of screening, a list of nodes that need to be collided is obtained. In the sub-thread, the third screening is performed according to the position change amount to obtain a set of nodes that may collide. On this basis, the fifth list is further screened again according to the collision threshold to obtain a fifth list. Then the sixth list in which the collision result changes is determined, and finally the nodes in the sixth list are detected to see if a collision occurs. Through the method of the present invention, the number of triangular faces that need to be compared and calculated is simplified by filtering through the screening conditions layer by layer, and the required data is dynamically loaded using WebWorker, which can effectively solve the problem of memory management, improve computing efficiency, and reduce user waiting time.
[0030] Optionally, in S402, the object group data refers to the data of the object shape displayed in three dimensions, that is, the mesh (Mesh) and the relationship between the node (Node) and the mesh (Mesh). The mesh (Mesh) contains geometric shape information (Geometry), the geometric shape information contains the node position (Position) and the node index (Index) and the grouping information (Group), and the grouping information contains the starting index subscript (Start) and the number of draws (Count), as well as the bounding box information (Box). In S402, for example, the scene is dynamically loaded, and some data has been stored in IndexedDB, and a node array that needs to be compared two by two is constructed based on the input object group data.
[0031] Optionally, in S406, after constructing the node array that needs to be compared two by two in S404, the node array is processed, including extracting bounding boxes, nodes, indexes, matrices and other information and transmitting them to WebWorker. This information will be used 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 use a geometric body with a slightly larger volume but simpler characteristics to approximate complex geometric objects. Mesh is a data structure used to represent shapes in three-dimensional space. A mesh consists of nodes, edges and faces. Nodes are the most basic components, and they are the points that make up the shape of the mesh. Node indexes are digital identifiers used to reference these nodes. It should be noted that in the mesh, nodes are also known as vertices.
[0032] The main role of node index is to reuse node data when creating a mesh, thereby reducing the amount of data and optimizing memory usage. For example, a cube only needs 8 nodes, but can have 12 edges and 6 faces. By using indexes, you can avoid repeatedly storing node coordinates for each face, and instead reference these nodes by index.
[0033] Here is an example of node indexing: Assume there is a simple triangle mesh consisting of the following three nodes: Node A: (x1, y1, z1), node B: (x2, y2, z2) and node C: (x3, y3, z3), x, y, z are three-dimensional coordinate systems, node A, node B, node C are three points on the coordinate system.
[0034] If you define the node coordinates directly in each triangle, then each triangle will store the coordinates of these three nodes repeatedly. The method of using node indexes is as follows: 1. Define nodes: vertices = [(x1, y1, z1),(x2, y2, z2),(x3, y3, z3)] 2. Define the index: indices = [0, 1, 2 # For the first triangle, use nodes 0, 1, 2 / / Or for the second triangle, add more indices referencing the same or new nodes if they exist].
[0035] In the above example, each number in the indices array is an index that points to an element in the vertices array. This approach can reduce data redundancy, especially when dealing with complex meshes.
[0036] The 3D transformation matrix is a mathematical tool used in computer graphics to process geometric transformations in 3D space. It uniformly represents the translation, rotation, and scaling of geometric bodies through a 4×4 homogeneous coordinate matrix.
[0037] As an optional example, extracting bounding box, node, index, matrix and other information according to the node array can also be performed in the main thread, while calculating the distance between nodes, sorting according to the distance between nodes and recording them in the first list can be completed by the child thread.
[0038] Optionally, the main thread may also receive the result of whether the nodes collided sent by the child thread, and store the result in a third list recording whether the nodes collided. In other words, the third list is used to store information on whether the nodes collided. The main thread performs a write operation on the third list, and the child thread can read the third list information to determine which nodes need to be detected for collision.
[0039] Optionally, after the child thread detects whether there is a collision, it does not send the detection result to the main thread, but 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.
[0040] Optionally, in S408, the nodes are sorted according to the distances between the nodes and recorded in the first list. The sorting according to the distances between the nodes may be one of the following: sorting from large to small according to the distances between the nodes, or sorting from small to large according to the distances between the nodes.
[0041] Optionally, in S410, a second list of nodes whose positions have changed is determined based on the first list. For example, all nodes are traversed and nodes whose positions have changed are screened out to form a second list. These nodes serve as basic objects for dynamic collision detection to further determine which nodes need to be detected for collision.
[0042] Optionally, in S412, a third list recording whether a node has collided is read, and if a node in the second list is in the third list, the node is deleted from the third list. Because if a node is included in the second list, it means that the position of the node has changed, and the result of the last collision detection may also change and cannot be used again, so the record of the node needs to be deleted from the third list.
[0043] Optionally, in S414, the calculating of the position changes of all nodes in the second list and determining, according to the position changes, a fourth list of nodes that need to be detected for collision comprises: 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.
[0044] In S416, first calculate the position change of all nodes in the second list. Because the second list only records the nodes whose positions have changed, but the specific position change still needs to be calculated, the child thread calculates the position change of all nodes in the second list. Then, according to the data (node b) of the first list obtained in step S404 and the position change calculated in this step, the nodes that may collide are screened. For example, if the distance of a node a in the second list changes by 3, then the other nodes (node b) in the first list whose distance to the node a is less than 3 need to be recalculated, and if the other nodes (node b) in the first list whose distance to the node a is greater than 3 did not collide last time, they will not collide this time. Finally, for the nodes in the fourth list, update the distance to other nodes and re-sort them. Among them, the sorting method can be sorting from small to large or from large to small.
[0045] Optionally, in S418, detecting whether a collision occurs between nodes in the fourth list includes: Step 418-1, determining a fifth list for which collision detection is required according to the collision threshold and the fourth list; Step 418-2, determining the sixth list of collision results that have changed; Step 418-3, reading geometric data from the database, and sending a request message to the main thread if data is missing; Step 418-4: Determine whether nodes collide based on the geometric data and the sixth list.
[0046] Optionally, in step 418-1, determining a fifth list for which collision detection is required according to the collision threshold and the fourth list includes: 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.
[0047] It should be noted that the collision threshold is a collision threshold set before the child thread detects whether there is a collision. The collision threshold for each detection can be different. Compared with the last detection, the collision threshold can be larger or smaller. For example, the collision threshold for the last detection was 5, and the collision threshold for this detection is 7. For another example, the collision threshold for the last detection was 6, and the collision threshold for this detection is 4.
[0048] That is to say, in step 418-1, it is determined whether the collision threshold has changed. If the collision threshold this time is smaller than the last time, the nodes that did not collide last time will not collide this time, and the result this time will be a subset of the last collision. The changed nodes are directly selected from the last result for comparison, that is, the fifth list. If the collision threshold this time is larger than the last time, the nodes that collided last time must have collided this time, so they are added on the basis of the last collision result, that is, the nodes that collided last time do not need to be recalculated, and the results are used directly; the nodes that did not collide last time are added to the list of nodes that need to be calculated this time, and the fifth list is obtained.
[0049] Optionally, in step 418 - 2 , for the nodes in the fifth list, it is determined whether there is a bounding box of the last collision, and whether the last collision point exists in the current intersection box. If so, it is considered that a collision occurs.
[0050] Optionally, in step 418 - 2 , a sixth list of changed collision results is determined, which is a set of points where the last collision point does not exist in the current intersection box.
[0051] Optionally, in step 418-4, judging whether a node collides with another node based on the geometric data and the sixth list is as follows: Figure 5 As shown, including S502, S504, S506, S508, S510, S512, S514 and S516: S502, namely step A: determine in turn whether the bounding boxes of the grids intersect, and if so, execute step B; wherein the shape and structure of the grid are determined by the positions and connection relationships of the nodes.
[0052] As another optional solution, in this step, if they do not intersect, it is determined that there is no collision. If they do intersect, step B is executed: S504, namely 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.
[0053] As another optional solution, in this step, for any two groups GroupA and GroupB in the grid, it is determined whether the bounding boxes of GroupA and GroupB intersect, if not, it is determined that there is no collision, if so, step C is executed; Each grid includes multiple groups. All the groups in the grid are judged in pairs. For the convenience of description, the two judged groups are respectively recorded as Group A and Group B.
[0054] S506, namely 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.
[0055] As another optional solution, in this step, the intersection of the bounding boxes of GroupA and GroupB is obtained, and it is determined whether the intersection is empty. If the intersection is empty, it is determined that there is no collision. If the intersection is not empty, step D is executed; In this step, the intersection of groupA and groupB bounding boxes is calculated to determine whether the intersection box is empty. If it is not empty, it means there is a possibility of collision, and the next step is performed.
[0056] S508, i.e. step D: dividing the intersection of the bounding boxes into 8 octant intersection boxes according to space; S510, i.e., step E: traverse the triangular faces in GroupA and GroupB respectively, determine in turn whether a node is in the octant intersection boxes No. 1 to 8 or whether a triangular face intersects with the octant intersection boxes No. 1 to 8, 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; Each octant intersection box corresponds to a pair of triListA and triListB, that is, there are 8 pairs in total. triListA represents the set (array) of triangles belonging to GroupA that may collide in the current octant intersection box, and triListB represents the set (array) of triangles belonging to GroupB that may collide in the same octant intersection box.
[0057] A triangular face is a triangle composed of three nodes. The data structure can be simply represented as: [ [(x1, y1, z1),(x2, y2, z2),(x3, y3, z3)], [(x1', y1', z1'), (x2',y2', z2'),(x3', y3', z3') ],•••].
[0058] S512, i.e., 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 respectively; if both are greater than 0, execute step G.
[0059] As another optional solution, in this step, the eight octant intersection boxes are traversed in a loop to determine whether the lengths of the array triListA and the array triListB are greater than 0, and if both are greater than 0, step G is executed; if not, it is determined that there is no collision; In this step, the variable 8 octant intersection boxes are looped, and then the length of the array triListA and the array triListB are determined to be greater than 0. If both are greater than zero, it indicates that there is a potential collision point, and then the next step is performed. In the present invention, the purpose of dividing the octant intersection box is to optimize the number of triangles required for comparison, especially when the mesh is particularly complex, the triangles are unevenly distributed in space, strips, bands, hollows, etc.
[0060] S514, i.e., step G: calculating the minimum distance between each pair of triangle face groups in the eight octant intersection boxes respectively, and determining 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 the process returns to step A.
[0061] As another optional solution, in this step, the minimum distance of each triangle face group is calculated in pairs in the eight 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 occurs and step H is executed; if the minimum distance is less than the preset collision threshold, it is considered that a collision occurs and the process returns to step A. S516, i.e. step H: sending the result of determining whether a collision occurs to the main thread.
[0062] In the present invention, when S516 is executed, a collision detection of the child thread is completed, and the child 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.
[0063] Optionally, as an optional example, the child thread may write the collision detection result directly into the third list by itself without sending the detection result to the main thread.
[0064] The three-dimensional dynamic collision detection method of the present invention is used to screen whether the node position has changed, the position change amount, the position enlargement or reduction, the collision threshold, the intersection box, the bounding box, etc. layer by layer, and the number of triangular faces that need to be compared and calculated is simplified, and the required data is dynamically loaded using WebWorker, 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 uses the child thread for dynamic collision detection, thereby further improving the calculation efficiency and reducing the user's waiting time.
[0065] In addition, reference 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 is run, a processor executes any one of the above three-dimensional dynamic collision detection methods.
[0066] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but 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 required by the present invention.
[0067] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0068] Example 2 Figure 6 3D dynamic collision detection device 600 according to this embodiment is shown, and the device 600 corresponds to the method according to the first aspect of embodiment 1. Figure 6 As shown, the apparatus 600 includes: a sub-thread module 620; the sub-thread module 620 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.
[0069] Optionally, the device 600 further includes a main thread module 610; the main thread module 610 is configured to: Dynamically load scene data and store object group data into the database; An array of nodes that need to be compared pairwise is constructed according to the object group data.
[0070] According to the node array, extract one or a combination of the following information: bounding box, node, index and matrix.
[0071] Optionally, the calculating of the position changes of all nodes in the second list and determining, according to the position changes, a fourth list of nodes that need to be detected for collision comprises: 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.
[0072] Optionally, detecting whether the nodes in the fourth list collide with each other includes: 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 message to the main thread if data is missing; It is determined whether nodes collide based on the geometric data and the sixth list.
[0073] Optionally, determining the fifth list for which collision detection is required according to the collision threshold and the fourth list includes: 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.
[0074] Optionally, judging whether a node collides according to the geometric data and the sixth list includes: 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.
[0075] It should be noted that the device of Example 2 and the method of Example 1 belong to the same inventive concept, solve the same technical problem, and achieve the same technical effect. The device of Example 2 can implement all the methods of Example 1, and the similarities will not be repeated here.
[0076] Thus, according to this embodiment, the three-dimensional dynamic collision detection device of the present invention is used, through the main thread module and the sub-thread module, to screen layer by layer whether the node position has changed, the position change amount, the position enlargement or reduction, the collision threshold, the intersection box, the bounding box, etc., to simplify the number of triangular faces that ultimately need to be compared and calculated, and use WebWorker to dynamically load the required data, which can effectively solve the problem of memory management, improve the calculation efficiency, and reduce the user's waiting time. In addition, the three-dimensional dynamic collision detection method of the present invention uses the main thread for data preprocessing and uses the sub-thread for dynamic collision detection, thereby further improving the calculation efficiency and reducing the user's waiting time.
[0077] Example 3 Figure 7 FIG. 7 shows a three-dimensional dynamic collision detection device 700 according to this embodiment, which corresponds to the method described in the first aspect of Embodiment 1. Figure 7 As shown, the device 700 includes: Processor 710; and The memory 720 is connected to the processor and is used 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.
[0078] Optionally, 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.
[0079] Optionally, the calculating of the position changes of all nodes in the second list and determining, according to the position changes, a fourth list of nodes that need to be detected for collision comprises: 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.
[0080] Optionally, detecting whether the nodes in the fourth list collide with each other includes: 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 message to the main thread if data is missing; It is determined whether nodes collide based on the geometric data and the sixth list.
[0081] Optionally, determining the fifth list for which collision detection is required according to the collision threshold and the fourth list includes: 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.
[0082] Optionally, judging whether a node collides according to the geometric data and the sixth list includes: 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.
[0083] The three-dimensional dynamic collision detection device of the present embodiment is used, through the main thread module and the sub-thread module, to screen layer by layer whether the node position has changed, the position change amount, the position enlargement or reduction, the collision threshold, the intersection box, the bounding box, etc., to simplify the number of triangular faces that need to be compared and calculated in the end, and use WebWorker to dynamically load the required data, which can effectively solve the problem of memory management, improve the calculation efficiency, and reduce the user's waiting time. In addition, the three-dimensional dynamic collision detection method of the present invention uses the main thread for data preprocessing and uses the sub-thread for dynamic collision detection, thereby further improving the calculation efficiency and reducing the user's waiting time.
[0084] It should be noted that the device of Example 3 and the method of Example 1 belong to the same inventive concept, solve the same technical problem, and achieve the same technical effect. The device of Example 3 can implement all the methods of Example 1, and the similarities will not be repeated here.
[0085] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0086] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0087] In the several embodiments provided in this 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 schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. 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 mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0088] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0089] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0090] 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 this 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, including several instructions for a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk, etc. Various media that can store program codes.
[0091] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection 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.
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 calculating of the position changes of all nodes in the second list and determining the fourth list of nodes to be detected for collision according to the position changes comprises: 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.
4. The method according to claim 3, 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.
5. The method according to claim 4, 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.
6. The method according to claim 4, 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.
7. 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 6.
8. 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.
9. The device according to claim 8, 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.
10. 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.
Citation Information
Patent Citations
Collision detection method for objects in large-scale scene
CN104766371A
Double-arm self-collision detecting method and computer readable storage medium
CN111360824A
Polygon cutting method based on bounding box tree, electronic equipment and storage medium
CN113034515A
Automobile body structure deformation evaluation method and system for automobile side collision simulation
CN114925449A
Constellation network collision early warning method and device, equipment and storage medium
CN116886171A