Hierarchical pathfinding method and device, electronic equipment and readable medium

Through hierarchical pathfinding methods and dynamic loading technology, the problems of inaccurate multi-layer spatial pathfinding and memory waste in three-dimensional scenes are solved, and efficient and accurate multi-layer spatial pathfinding and memory optimization are achieved.

CN114159777BActive Publication Date: 2025-10-10NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111479477.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-06
Publication Date
2025-10-10
Estimated Expiration
2041-12-06

AI Technical Summary

Technical Problem

Existing 3D scene pathfinding methods cannot effectively distinguish the layers in multi-layer spatial scenes, resulting in inaccurate pathfinding, and the Recast algorithm consumes too much memory in large game scenes.

Method used

A hierarchical pathfinding method is used to determine the area and level of the starting and ending points through dynamic loading of regional grid and polygon information. The path is calculated using the A* algorithm to reduce memory usage.

Benefits of technology

It achieves efficient and accurate pathfinding in multi-layer spatial scenes, reduces memory consumption and improves game performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114159777B_ABST
    Figure CN114159777B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a hierarchical pathfinding method and device, electronic equipment and readable medium, the method comprising: in response to a pathfinding instruction, determining a starting point and an end point of a virtual object in a three-dimensional map; determining a starting point area grid and an end point area grid where the starting point and the end point are located, wherein the area grid covers a plurality of areas including areas on different layer maps and / or areas on the same layer map, determining a starting point area where the starting point is located from a plurality of areas of the starting point area grid, and determining an end point area where the end point is located from a plurality of areas of the end point area grid; and determining a target path of the virtual object according to the starting point area and the end point area. By applying the embodiments of the present application, the map layer and the area where the starting point and the end point are located can be determined from the starting point area grid and the end point area grid covering the areas of different layer maps, so that the pathfinding of the multi-layer map scene can be performed according to the map layer and the area where the starting point and the end point are located.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of map pathfinding technology, and in particular to a hierarchical pathfinding method, a hierarchical pathfinding device, an electronic device, and a computer-readable medium. Background Art

[0002] Pathfinding is a fundamental requirement throughout existing games, and how to achieve efficient, accurate, and fast pathfinding in 3D games has always been a hot topic of research.

[0003] Currently, the pathfinding method for three-dimensional scenes is to convert the three-dimensional scene into a two-dimensional projection for pathfinding. This method is only applicable to pathfinding on a single-layer map. For multi-layer space scenes, multiple layers of space are projected on the same projection surface, and it is impossible to distinguish which layer of space the points on the projection are located. Therefore, it is not suitable for scenes with multiple layers of space, such as in buildings. Summary of the Invention

[0004] The embodiments of the present invention provide a hierarchical pathfinding method, device, electronic device and computer-readable storage medium to solve the problem of difficult pathfinding in multi-layer spatial scenes.

[0005] An embodiment of the present invention discloses a hierarchical pathfinding method applied to a three-dimensional map, wherein the three-dimensional map includes one or more maps, wherein the three-dimensional map is constructed with multiple regional grids, wherein each map layer is divided into multiple regions, and the regional grids cover multiple regions, wherein the multiple regions covered by the regional grids include regions on different map layers and / or regions on the same map layer, including:

[0006] In response to a pathfinding instruction, determining a starting point and an end point of a virtual object in the three-dimensional map;

[0007] Determine a starting point area grid and an ending point area grid where the starting point and the ending point are located;

[0008] Determine a starting area where the starting point is located from a plurality of areas of the starting area grid, and determine an end area where the end point is located from a plurality of areas of the end area grid;

[0009] A target path of the virtual object is determined according to the starting area and the ending area.

[0010] Optionally, determining the starting area where the starting point is located from the multiple areas of the starting area grid includes:

[0011] Projecting the starting point and multiple areas of the starting point area grid onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection starting point and a plane projection area;

[0012] Extending a ray from the starting point of the plane projection to intersect the plane projection area, and determining an area corresponding to the plane projection area where the ray intersects an odd number of times;

[0013] If there is only one area corresponding to the plane projection area that intersects the ray an odd number of times, determining the area corresponding to the plane projection area that intersects the ray an odd number of times as the starting point area;

[0014] If there are multiple areas corresponding to the plane projection area whose number of intersections with the ray is odd, projecting the areas corresponding to the plane projection area whose number of intersections with the ray is odd and the starting point onto the vertical axis to obtain the vertical axis projection starting point and the vertical axis projection area;

[0015] If the area corresponding to the vertical axis projection area including the vertical axis projection starting point is one, determine the area corresponding to the vertical axis projection area including the vertical axis projection starting point as the starting point area;

[0016] If there are multiple areas corresponding to the vertical axis projection area including the vertical axis projection starting point, multiple points are selected from the areas corresponding to the vertical axis projection area including the vertical axis projection starting point to form multiple planes;

[0017] An area corresponding to a plane closest to the starting point is determined as the starting point area.

[0018] Optionally, determining the destination area where the destination is located from the multiple areas of the destination area grid includes:

[0019] Projecting the end point and the multiple regions of the end point region grid onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection end point and a plane projection region;

[0020] Extending a ray from the plane projection endpoint to intersect the plane projection area, and determining an area corresponding to the plane projection area where the ray intersects an odd number of times;

[0021] If there is only one area corresponding to the plane projection area that intersects the ray an odd number of times, determining the area corresponding to the plane projection area that intersects the ray an odd number of times as the end point area;

[0022] If there are multiple areas corresponding to the plane projection area that intersects the ray an odd number of times, projecting the areas corresponding to the plane projection area that intersects the ray an odd number of times and the end point onto the vertical axis to obtain the vertical axis projection end point and the vertical axis projection area;

[0023] If the area corresponding to the vertical axis projection area including the vertical axis projection end point is one, determining the area corresponding to the vertical axis projection area including the vertical axis projection end point as the end point area;

[0024] If there are multiple areas corresponding to the vertical axis projection area including the vertical axis projection end point, multiple points are selected from the areas corresponding to the vertical axis projection area including the vertical axis projection end point to form multiple planes;

[0025] The end point area is determined as an area corresponding to a plane closest to the end point.

[0026] Optionally, the area is divided into a plurality of polygons, and determining the target path of the virtual object according to the starting area and the end area includes:

[0027] Acquiring area information of the three-dimensional map;

[0028] Determine a target area that the virtual object needs to pass through according to the area information, the starting area, and the end area;

[0029] Obtaining polygon information of the polygon corresponding to the target area;

[0030] Determining a target polygon that the virtual object needs to pass through according to the polygon information, the starting point, and the end point;

[0031] A target path of the virtual object is determined based on the target polygon.

[0032] Optionally, the area information includes a midpoint of the area and an area-related distance, and determining the target area that the virtual object needs to pass through based on the area information, the starting area, and the end area includes:

[0033] Based on the midpoint of the area, the area-related distance, the starting area and the end area, an A* algorithm is used to calculate an area path, wherein the area passed by the area path is the target area that the virtual object needs to pass through.

[0034] Optionally, the polygon information is cached in an internal cache, and obtaining the polygon information of the polygon corresponding to the target area includes:

[0035] Detecting whether polygon information of a polygon corresponding to the target area is cached in an internal cache;

[0036] If the polygon information is not cached in the internal cache, or the cached polygon information is incomplete, the polygon information not cached in the internal cache is cached.

[0037] Optionally, the polygon information includes a polygon midpoint and a polygon-related distance, and determining a target polygon that the virtual object needs to pass through based on the polygon information, the starting point, and the end point includes:

[0038] Projecting the starting point and the polygon corresponding to the starting point area onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection starting point and a plane projection polygon;

[0039] Extending a ray from the plane projection starting point to intersect the plane projection polygon, and determining a polygon corresponding to the plane projection polygon that intersects the ray an odd number of times as the starting polygon;

[0040] Projecting the end point and the polygon corresponding to the end point area onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection end point and a plane projection polygon;

[0041] Extending a ray from the plane projection end point to intersect the plane projection polygon, and determining a polygon corresponding to the plane projection polygon that intersects the ray an odd number of times as the end point polygon;

[0042] Based on the polygon midpoint, the polygon related distance, the starting polygon and the end polygon, the polygon path is calculated using the A* algorithm, wherein the polygon passed by the polygon path is the target polygon that the virtual object needs to pass through.

[0043] Optionally, before acquiring the area information of the three-dimensional map, the method further includes:

[0044] The area information of the three-dimensional map is generated by the following steps:

[0045] Dividing the three-dimensional map into regions to obtain region vertices;

[0046] Determine a bounding box of the region according to the vertices of the region, and use the midpoint of the bounding box as the region midpoint of the region;

[0047] Traversing the region vertices, taking regions with the same two region vertices as adjacent regions, and the edge between the two region vertices as the adjacent edge;

[0048] The sum of the distances from the midpoint of the region to the midpoints of the two adjacent sides is calculated as the region-related distance.

[0049] Optionally, it also includes:

[0050] The polygon information of the three-dimensional map is generated by the following steps:

[0051] Performing polygon division on the area to obtain a corresponding relationship between the polygons and the area, as well as vertices of the polygons;

[0052] Determine the midpoint of the polygon according to the vertices of the polygon;

[0053] Traversing the polygon vertices, taking polygons with the same two polygon vertices as adjacent polygons, and the edge between the two polygon vertices as the adjacent edge;

[0054] The sum of the distances from the midpoint of the polygon to the midpoints of the two adjacent sides is calculated as the polygon-related distance.

[0055] An embodiment of the present invention further discloses a hierarchical pathfinding device, which is applied to a three-dimensional map. The three-dimensional map includes one or more maps, and the three-dimensional map is constructed with multiple regional grids. Each map layer is divided into multiple regions. The regional grids cover multiple regions, and the multiple regions covered by the regional grids include regions on different map layers and / or regions on the same map layer. The device includes:

[0056] a position determination module, configured to respond to a pathfinding instruction and determine a starting point and an end point of a virtual object in the three-dimensional map;

[0057] A grid determination module, used to determine the starting area grid and the ending area grid where the starting point and the ending point are located;

[0058] an area determination module, configured to determine a starting area where the starting point is located from a plurality of areas of the starting area grid, and to determine an end area where the end point is located from a plurality of areas of the end area grid;

[0059] A path determination module is used to determine a target path of the virtual object according to the starting area and the end area.

[0060] Optionally, the region determination module includes:

[0061] A region projection submodule, configured to project the starting point and multiple regions of the starting point region grid onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection starting point and a plane projection region;

[0062] an area determination submodule, configured to extend a ray from the plane projection starting point to intersect the plane projection area, and determine an area corresponding to the plane projection area that intersects the ray an odd number of times;

[0063] The region determination submodule is further configured to, if there is only one region corresponding to the plane projection region that intersects the ray an odd number of times, determine the region corresponding to the plane projection region that intersects the ray an odd number of times as a starting region;

[0064] The area projection submodule is further configured to, if there are multiple areas corresponding to the plane projection area having an odd number of intersections with the ray, project the areas corresponding to the plane projection area having an odd number of intersections with the ray and the starting point onto the vertical axis to obtain a vertical axis projection starting point and a vertical axis projection area;

[0065] The region determining submodule is further configured to determine the region corresponding to the vertical axis projection region including the vertical axis projection starting point as a starting point region if the region corresponding to the vertical axis projection region including the vertical axis projection starting point is one;

[0066] a plane forming submodule, configured to select a plurality of points from the area corresponding to the vertical axis projection area including the vertical axis projection starting point to form a plurality of planes if there are multiple areas corresponding to the vertical axis projection area including the vertical axis projection starting point;

[0067] The region determination submodule is further configured to determine the region corresponding to the plane closest to the starting point as the starting point region.

[0068] Optionally, the region determination module includes:

[0069] The area projection submodule is further used to project the end point and multiple areas of the end point area grid onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection end point and a plane projection area;

[0070] The region determination submodule is further configured to extend a ray from the plane projection endpoint to intersect the plane projection region, and determine a region corresponding to the plane projection region that intersects the ray an odd number of times;

[0071] The region determination submodule is further configured to, if there is only one region corresponding to the plane projection region that intersects the ray an odd number of times, determine the region corresponding to the plane projection region that intersects the ray an odd number of times as an end region;

[0072] The area projection submodule is further configured to, if there are multiple areas corresponding to the plane projection area having an odd number of intersections with the ray, project the areas corresponding to the plane projection area having an odd number of intersections with the ray and the end point onto the vertical axis to obtain a vertical axis projection end point and a vertical axis projection area;

[0073] The region determining submodule is further configured to determine the region corresponding to the vertical axis projection region including the vertical axis projection end point as the end point region if the region corresponding to the vertical axis projection region including the vertical axis projection end point is one;

[0074] a plane forming submodule, configured to select a plurality of points from the area corresponding to the vertical axis projection area including the vertical axis projection end point to form a plurality of planes if there are multiple areas corresponding to the vertical axis projection area including the vertical axis projection end point;

[0075] The region determination submodule is further configured to determine the end point region by using the region corresponding to the plane closest to the end point.

[0076] Optionally, the area is divided into a plurality of polygons, and the path determination module includes:

[0077] An information acquisition submodule, configured to acquire regional information of the three-dimensional map;

[0078] The area determination submodule is further configured to determine a target area that the virtual object needs to pass through based on the area information, the starting area, and the ending area;

[0079] The information acquisition submodule is further used to obtain polygon information of the polygon corresponding to the target area;

[0080] A polygon determination submodule, configured to determine a target polygon that the virtual object needs to pass through based on the polygon information, the starting point, and the end point;

[0081] The path determination submodule is configured to determine a target path of the virtual object according to the target polygon.

[0082] Optionally, the region information includes a midpoint of the region and a related distance of the region, and the region determination submodule includes:

[0083] The area determination unit is used to calculate the area path using the A* algorithm based on the midpoint of the area, the relevant distance of the area, the starting area and the end area, wherein the area passed by the area path is the target area that the virtual object needs to pass through.

[0084] Optionally, the polygon information is cached in an internal cache, and the information acquisition submodule includes:

[0085] An information detection unit, configured to detect whether polygon information of a polygon corresponding to the target area is cached in an internal cache;

[0086] The information caching unit is configured to cache the polygon information not cached in the internal cache if the polygon information is not cached in the internal cache or the cached polygon information is incomplete.

[0087] Optionally, the polygon information includes polygon midpoints and polygon-related distances, and the polygon determination submodule according to the polygon information includes:

[0088] A polygon projection unit, configured to project the polygon corresponding to the starting point and the starting point area onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection starting point and a plane projection polygon;

[0089] A polygon determination unit is configured to extend a ray from a plane projection starting point to intersect with the plane projection polygon, and determine a polygon corresponding to the plane projection polygon that intersects the ray an odd number of times as a starting polygon;

[0090] The polygon projection unit is further used to project the polygon corresponding to the end point and the end point area onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection end point and a plane projection polygon;

[0091] The polygon determination unit is further configured to extend a ray from the plane projection end point to intersect the plane projection polygon, and determine a polygon corresponding to the plane projection polygon that intersects the ray an odd number of times as the end point polygon;

[0092] The polygon determination unit is used to calculate the polygon path based on the polygon midpoint, the polygon related distance, the starting polygon and the end polygon using the A* algorithm, wherein the polygon passed by the polygon path is the target polygon that the virtual object needs to pass through.

[0093] Optionally, it also includes:

[0094] The area information of the three-dimensional map is generated by the following steps:

[0095] A map division module, configured to divide the three-dimensional map into regions and obtain region vertices;

[0096] a midpoint determination module, configured to determine a bounding box of the region according to the vertices of the region, and use the midpoint of the bounding box as the region midpoint of the region;

[0097] an adjacent region determining module, configured to traverse the region vertices and define regions having two identical region vertices as adjacent regions, and an edge between the two region vertices as an adjacent edge;

[0098] The distance calculation module is used to calculate the sum of the distances from the midpoint of the region to the midpoints of the two adjacent sides as the region-related distance.

[0099] Optionally, it also includes:

[0100] The polygon information of the three-dimensional map is generated by the following steps:

[0101] A region division module, configured to divide the region into polygons, and obtain a corresponding relationship between the polygons and the region, as well as vertices of the polygons;

[0102] The midpoint determination module is further used to determine the midpoint of the polygon according to the vertices of the polygon;

[0103] an adjacent polygon determination module, configured to traverse the polygon vertices and define polygons having the same two polygon vertices as adjacent polygons, and an edge between the two polygon vertices as an adjacent edge;

[0104] The distance calculation module is further used to calculate the sum of the distances from the midpoint of the polygon to the midpoints of two adjacent sides as the polygon-related distance.

[0105] An embodiment of the present invention further discloses an electronic device, comprising a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;

[0106] The memory is used to store computer programs;

[0107] The processor is configured to implement the method described in the embodiment of the present invention when executing the program stored in the memory.

[0108] The embodiments of the present invention further disclose one or more computer-readable media having instructions stored thereon. When executed by one or more processors, the processors are enabled to perform the method according to the embodiments of the present invention.

[0109] The embodiment of the present invention includes the following features: in response to a pathfinding instruction, determining the starting point and end point of a virtual object in a three-dimensional map, determining the starting point area grid and the end point area grid where the starting point and end point are located, wherein the multiple areas covered by the area grid include areas on different map layers and / or areas on the same map layer, determining the starting point area where the starting point is located from the multiple areas of the starting point area grid, and determining the end point area where the end point is located from the multiple areas of the end point area grid, and determining the target path of the virtual object based on the starting point area grid and the end point area grid. Applying the embodiment of the present invention, after determining the starting point area grid and the end point area grid where the starting point and end point are located, the map layer and area where the starting point and end point are located can be determined from the starting point area grid and the end point area grid covering the different map layers, thereby enabling pathfinding in a multi-layer map scene based on the map layer and area where the starting point and end point are located, thereby solving the problem of projecting multiple maps onto the same projection surface when pathfinding is performed by converting a three-dimensional scene into a two-dimensional projection, and being unable to distinguish which map layer the location on the projection surface is located on. BRIEF DESCRIPTION OF THE DRAWINGS

[0110] Figure 1 This is a flowchart of the steps of a hierarchical pathfinding method provided in an embodiment of the present invention;

[0111] Figure 2 is a flowchart of another hierarchical pathfinding method provided in an embodiment of the present invention;

[0112] Figure 3 is a schematic diagram of area division provided in an embodiment of the present invention;

[0113] Figure 4 is a schematic diagram of regional pathfinding results provided in an embodiment of the present invention;

[0114] Figure 5 is a schematic diagram of the final pathfinding result provided in an embodiment of the present invention;

[0115] Figure 6 This is a schematic diagram of the hierarchical pathfinding process provided in an embodiment of the present invention;

[0116] Figure 7 is a schematic diagram of edge contour information provided in an embodiment of the present invention;

[0117] Figure 8 This is a schematic diagram of generating regional information provided in an embodiment of the present invention;

[0118] Figure 9 is a schematic diagram of the correspondence between regions and polygons provided in an embodiment of the present invention;

[0119] Figure 10 is a schematic diagram of polygonal structure information provided in an embodiment of the present invention;

[0120] Figure 11 This is a schematic diagram of a pathfinding flow chart provided in an embodiment of the present invention;

[0121] Figure 12 It is a reading area information relationship diagram provided in an embodiment of the present invention;

[0122] Figure 13 This is a schematic diagram of a process from obtaining a polygon to obtaining a specific path provided in an embodiment of the present invention;

[0123] Figure 14 is a structural block diagram of a hierarchical pathfinding device provided in an embodiment of the present invention;

[0124] Figure 15 is a block diagram of an electronic device provided in an embodiment of the present invention;

[0125] Figure 16 is a schematic diagram of a computer-readable medium provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0126] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0127] In recent years, with the rapid improvement in the performance of computers and smart mobile devices, the number of people owning these devices has also grown rapidly. People are constantly demanding more expressive and higher-quality games, and creating more efficient and high-quality games has become a constant goal for existing game developers. Pathfinding is a fundamental requirement throughout existing games. In particular, efficient, accurate, and fast pathfinding in 3D (three-dimensional) games has long been a hot research topic.

[0128] Currently, the pathfinding method for three-dimensional scenes is to convert the three-dimensional scene into a two-dimensional projection for pathfinding. This method is only applicable to pathfinding on a single-layer map. For multi-layer space scenes, multiple layers of space are projected on the same projection surface, and it is impossible to distinguish which layer of space the points on the projection are located. Therefore, it is not suitable for scenes with multiple layers of space, such as in buildings.

[0129] Furthermore, while the Recast pathfinding algorithm boasts high computational speed and accuracy, it consumes a significant amount of memory to store pathfinding data when used in large game scenes. While increasing the size of the Recast algorithm's voxelized primitives can reduce the final data size, this decreases voxelization accuracy and affects the generation of walkable areas. In actual gameplay, all pathfinding data for a map is not needed most of the time. However, the Recast algorithm loads all data into memory, resulting in wasted memory.

[0130] To solve the above technical problems, an embodiment of the present invention provides a hierarchical pathfinding method, which can determine the map layer and area where the starting point and the end point are located from the starting point area grid and the end point area grid covering different layers of map areas. Therefore, pathfinding of multi-layer map scenes can be performed based on the map layer and area where the starting point and the end point are located, solving the problem that when pathfinding is performed by converting a three-dimensional scene into a two-dimensional projection, multiple layers of maps are projected on the same projection surface, and it is impossible to distinguish which layer of the map the location on the projection surface is located.

[0131] Furthermore, to address the primary memory usage issue, the data in the Recast algorithm is manipulated to construct high-level region information. After loading this high-level region information, regional pathfinding is performed, identifying which detailed information, such as polygons, will be used, and then dynamically loading this detailed information. This approach effectively reduces the amount of information required to be loaded into memory, mitigating a series of performance issues associated with pathfinding in large scenes.

[0132] Reference Figure 1 , shows a flowchart of the steps of a hierarchical pathfinding method provided in an embodiment of the present invention, which is applied to a three-dimensional map, wherein the three-dimensional map includes one or more maps on one layer, the three-dimensional map is constructed with multiple area grids, each map layer is divided into multiple areas, the area grids cover multiple areas, and the multiple areas covered by the area grids include areas on different map layers and / or areas on the same map layer. Specifically, the method may include the following steps:

[0133] Step 101: responding to a pathfinding instruction, determining a starting point and an end point of a virtual object in the three-dimensional map.

[0134] The virtual object may also be referred to as a virtual character or a game character; and the three-dimensional map may be a scene map containing multiple scene elements, such as a 3D game map containing architectural elements such as a castle. It should be noted that the Sen pathfinding method in the embodiments of the present invention can be applied not only to three-dimensional maps but also to other maps, such as two-dimensional maps.

[0135] Specifically, in response to a pathfinding instruction for a virtual object, the location information of the virtual object is determined. The location information includes the starting point and end point of the virtual object in the three-dimensional map. For example, if a player (also known as a game player or user) controls a virtual object to perform a task, the location corresponding to the task is the end point of the virtual object, and the pathfinding operation is the execution of the task.

[0136] Step 102: Determine the starting point area grid and the ending point area grid where the starting point and the ending point are located.

[0137] Among them, the regional grid is a number of three-dimensional grids of equal size constructed on a three-dimensional map. For example, 100 regional grids can be constructed on a map. Each regional grid has a corresponding coordinate position. A regional grid can cover multiple areas. The covered multiple areas include areas on different layers of maps and / or areas on the same layer of maps, such as in a map of a multi-layer spatial scene.

[0138] Specifically, according to the position of the starting point and the position of the end point, the regional grid corresponding to the position of the starting point is used as the starting regional grid, and the regional grid corresponding to the position of the end point is used as the end regional grid, thereby determining the starting regional grid and the end regional grid where the starting point and the end point are located.

[0139] Step 103: determining a starting area where the starting point is located from the multiple areas of the starting area grid, and determining an ending area where the ending point is located from the multiple areas of the ending area grid.

[0140] Specifically, after determining the starting area grid and the end area grid where the starting point and the end point are located, the map layer and the area where the starting point and the end point are located can be determined from the starting area grid and the end area grid covering different layers of map areas, that is, the starting area and the end area where the point and the end point are located can be determined.

[0141] Step 104: Determine a target path of the virtual object according to the starting area and the ending area.

[0142] Specifically, after determining the starting area and the ending area where the exit and the ending point are located, a pathfinding operation of the three-dimensional map can be performed based on the starting area and the ending area to determine the target path of the virtual object from the starting point to the ending point.

[0143] In an embodiment of the present invention, after determining the starting area grid and the end area grid where the starting point and the end point are located, the map layer and the area where the starting point and the end point are located can be determined from the starting area grid and the end area grid covering different layers of map areas. Therefore, path finding of multi-layer map scenes can be performed based on the map layer and the area where the starting point and the end point are located, solving the problem that when path finding is performed by converting a three-dimensional scene into a two-dimensional projection, multi-layer maps are projected on the same projection surface, and it is impossible to distinguish which layer of the map the position on the projection surface is located.

[0144] Reference Figure 2 , shows a flowchart of the steps of another hierarchical pathfinding method provided in an embodiment of the present invention, wherein the three-dimensional map includes one or more maps, the three-dimensional map is constructed with multiple area grids, each map layer is divided into multiple areas, the area grids cover multiple areas, and the multiple areas covered by the area grids include areas on different map layers and / or areas on the same map layer. Specifically, the following steps may be included:

[0145] Step 201: In response to a path-finding instruction, determine the starting point and the ending point of the virtual object in the three-dimensional map.

[0146] In one embodiment of the present invention, before step 201, the method further includes: generating the region information of the three-dimensional map by the following steps: dividing the three-dimensional map into regions to obtain region vertices; determining a bounding box of the region based on the region vertices, and taking the midpoint of the bounding box as the region midpoint of the region; traversing the region vertices, and taking regions with the same two region vertices as adjacent regions, and the edge between the two region vertices as an adjacent edge; and calculating the sum of the distances from the region midpoint to the midpoints of the two adjacent edges as the region-related distance.

[0147] In one embodiment of the present invention, it also includes: the polygon information of the three-dimensional map is generated by the following steps: polygonal division of the area to obtain the correspondence between the polygon and the area, as well as the polygon vertices; determining the polygon midpoint based on the polygon vertices; traversing the polygon vertices, and taking polygons with the same two polygon vertices as adjacent polygons, and the edges between the two polygon vertices as adjacent edges; calculating the sum of the distances from the polygon midpoint to the midpoints of the two adjacent edges as the polygon-related distance.

[0148] Among them, the midpoint of a region can also be called the region center point, and the midpoint of a polygon can also be called the polygon center point.

[0149] Specifically, before performing map pathfinding, pathfinding data preparation is required. The original three-dimensional map can be obtained through the Recast pathfinding engine. The original three-dimensional map is then voxelized to obtain a map composed of voxels. The voxels are then filtered to remove the unwalkable areas in the map. The remaining walkable areas in the map are then divided into regions, and the following can be obtained: Figure 3 , each independent region represented by a frame, such as Region 1, Region 2, and Region 3, is shown. By dividing the region into polygons based on its contours, polygons corresponding to each walkable region can be obtained. It should be noted that the specific implementation method of voxelization can be implemented using existing technologies, and this disclosure does not limit the specific process of voxelization.

[0150] After dividing the map into multiple regions, we can obtain the region's outline information, such as vertex information. The AABB bounding box of the region is determined based on the region's vertices, and the midpoint of the AABB bounding box is used as the region's regional midpoint, thereby obtaining the regional midpoint of all regions. We traverse the region vertices and regard regions with the same two region vertices as adjacent regions. The edge between the two region vertices is the adjacent edge. The sum of the distances from the midpoint of the adjacent edge to the regional midpoint of the two adjacent regions is calculated as the region-related distance. For example, region A has region vertex 1, region vertex 2, region vertex 3, and region vertex 4, region B has region vertex 1 and region vertex 2, and region C has region vertex 3 and region vertex 4. This means that region A is adjacent to regions B and C respectively, the edge between region vertex 1 and region vertex 2 is adjacent edge a, and the edge between region vertex 3 and region vertex 4 is adjacent edge b. The sum of the distance from the midpoint of region A to adjacent edge a and the distance from the midpoint of region A to adjacent edge b is region A's related distance.

[0151] It should be noted that since the region is not necessarily a plane, there may be slopes or concave and convex areas within the region and between regions. Therefore, directly calculating the distance between the midpoints of two adjacent regions is often inaccurate. In the embodiment of the present invention, the midpoint of the AABB bounding box is used as the midpoint of the region, and the sum of the distances from the midpoint of the region to the midpoints of the two adjacent sides is calculated as the region-related distance. This can improve the accuracy of the region-related distance, thereby improving the accuracy of the target path finally obtained.

[0152] In addition, while dividing the three-dimensional map into multiple areas, the three-dimensional map is divided into multiple area grids of the same size. The multiple areas covered by the area grids include areas on different layers of maps and / or areas on the same layer of maps. The grid where the area is located can be determined based on the bounding box of the area, thereby determining the correspondence between the area grid and the area.

[0153] After the Recast pathfinding engine generates the area outline, each area is further divided into multiple polygons to obtain the correspondence between polygons and areas. An index array is generated, which records the correspondence between each area and polygon in units of areas. The generated index is placed at the beginning of the file for quick access.

[0154] After dividing the area into multiple polygons, the polygon vertex information is obtained, and the polygon midpoint can be directly determined based on the polygon vertices. By traversing the polygon vertices, polygons with the same two polygon vertices are considered adjacent polygons, and the edge between the two polygon vertices is the adjacent edge. The sum of the distances from the midpoint of the adjacent edge to the midpoints of the two adjacent polygons is calculated as the polygon-related distance. For example, polygon A has polygon vertices 1, 2, 3, and 4, polygon B has both polygon vertices 1 and 2, and polygon C has both polygon vertices 3 and 4. This means that polygon A is adjacent to polygons B and C respectively, the edge between polygon vertices 1 and 2 is adjacent edge a, and the edge between polygon vertices 3 and 4 is adjacent edge b. The sum of the distance from the midpoint of polygon A to adjacent edge a and the distance from the midpoint of polygon A to adjacent edge b is polygon A's related distance.

[0155] It should be noted that polygons are not necessarily planes. There may be slopes or concave and convex areas between polygons and between polygons. Therefore, directly calculating the distance between the midpoints of two adjacent polygons is often inaccurate. In the embodiment of the present invention, by calculating the sum of the distances from the midpoint of the polygon to the midpoints of the two adjacent sides as the polygon-related distance, the accuracy of the polygon-related distance can be improved, thereby improving the accuracy of the target path finally obtained.

[0156] Step 202: Determine the starting point area grid and the ending point area grid where the starting point and the ending point are located.

[0157] Step 203: Determine the starting area where the starting point is located from the multiple areas of the starting area grid, and determine the end area where the end point is located from the multiple areas of the end area grid.

[0158] In one embodiment of the present invention, step 203 includes: projecting the starting point and multiple areas of the starting area grid onto a plane composed of a horizontal axis and a vertical axis to obtain a plane projection starting point and a plane projection area; extending a ray from the plane projection starting point to intersect with the plane projection area, and determining an area corresponding to the plane projection area with an odd number of intersections with the ray; if the area corresponding to the plane projection area with an odd number of intersections with the ray is one, determining the area corresponding to the plane projection area with an odd number of intersections with the ray as the starting point area; if the area corresponding to the plane projection area with an odd number of intersections with the ray is If there are multiple domains, the area corresponding to the plane projection area that intersects the ray an odd number of times and the starting point are projected onto the vertical axis to obtain the vertical axis projection starting point and the vertical axis projection area; if there is only one area corresponding to the vertical axis projection area containing the vertical axis projection starting point, the area corresponding to the vertical axis projection area containing the vertical axis projection starting point is determined as the starting point area; if there are multiple areas corresponding to the vertical axis projection area containing the vertical axis projection starting point, multiple points are selected from the area corresponding to the vertical axis projection area containing the vertical axis projection starting point to form multiple planes; and the area corresponding to the plane closest to the starting point is determined as the starting point area.

[0159] In one embodiment of the present invention, step 203 includes: projecting the end point and multiple areas of the end point area grid onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection end point and a plane projection area; extending a ray from the plane projection end point to intersect the plane projection area, and determining an area corresponding to the plane projection area with an odd number of intersections with the ray; if there is only one area corresponding to the plane projection area with an odd number of intersections with the ray, determining the area corresponding to the plane projection area with an odd number of intersections with the ray as the end point area; if there is only one area corresponding to the plane projection area with an odd number of intersections with the ray, determining the area corresponding to the plane projection area with an odd number of intersections with the ray as the end point area; If there are multiple domains, the area corresponding to the plane projection area that intersects the ray an odd number of times and the end point are projected onto the vertical axis to obtain the vertical axis projection end point and the vertical axis projection area; if there is only one area corresponding to the vertical axis projection area containing the vertical axis projection end point, the area corresponding to the vertical axis projection area containing the vertical axis projection end point is determined as the end point area; if there are multiple areas corresponding to the vertical axis projection area containing the vertical axis projection end point, multiple points are selected from the area corresponding to the vertical axis projection area containing the vertical axis projection end point to form multiple planes; and the area corresponding to the plane closest to the end point is determined as the end point area.

[0160] The ray method is a simple way to determine whether a point is inside a polygon. This involves drawing a ray from the point and counting the number of intersections between it and the polygon's boundary. If the number of intersections is odd, the point is inside the polygon; otherwise, it is outside.

[0161] The horizontal axis is x, the vertical axis is y, and the vertical axis is z. The horizontal and vertical axes form an xy plane, and the vertical axis z can be the height. Since the starting point area and the ending point area are determined in the same way, the starting point and the ending point are collectively referred to as target points as an example for explanation, as follows.

[0162] Specifically, because there may be a complex multi-layer spatial structure in the scene, there may be multiple regions of different layers of maps in a regional grid. The spatial position of the target point may be close to the relevant distances of multiple regions. In order to accurately determine the region to which the target point belongs, the target point and the region contained in the regional grid are projected on the xy plane, and the projected region is processed by ray method to determine whether the target point is in the xy plane of the region. Specifically, a ray is extended from the target point to intersect with the projected region (plane projection region), and the region corresponding to the plane projection region with an odd number of intersections with the ray is determined. There is only one region with an odd number of intersections with the ray, and this region is used as the region where the target point is located (the starting area or the end area).

[0163] If there are multiple areas with an odd number of intersections with the ray, it means that there are multiple areas in different layers of the map in the area grid, and the target point is in the xy plane of these areas. This is to solve the problem of overlapping areas at different heights (different layers of the map). These areas are carefully compared. The detailed comparison is divided into two steps. First, the above-mentioned areas with an odd number of intersections with the ray and the target point are projected onto the vertical axis to obtain the vertical axis projection starting point and the vertical axis projection area; determine whether there is a vertical axis projection area that includes the vertical axis projection starting point, that is, whether the height range of the area includes the height of the target point. If the area corresponding to the vertical axis projection area that includes the vertical axis projection starting point is one, the area corresponding to the vertical axis projection area is determined as the area where the target point is located.

[0164] If multiple vertical axis projection areas include the vertical axis projection starting point, then among the areas corresponding to the above multiple vertical axis projection areas, if there is no vertical axis projection area including the vertical axis projection starting point (for example, when the target point is in an inaccessible area), then traverse the above areas where the number of intersections with the ray is an odd number, and randomly select 3 points from the area, such as area contour points (the xy coordinate axes of the target point can also be divided into four quadrants. For one area, take an area contour point in each quadrant. If there are 3 points or more, take 3 points). A plane is formed by the 3 points, that is, each of the above areas corresponds to a plane, and the distance from each plane to the target point is calculated. The area corresponding to the plane closest to the target point is determined as the area where the target point is located.

[0165] In an embodiment of the present invention, after determining the starting area grid and the end area grid where the starting point and the end point are located, the map layer and the area where the starting point and the end point are located can be determined from the starting area grid and the end area grid covering different layers of map areas. Therefore, path finding of multi-layer map scenes can be performed based on the map layer and the area where the starting point and the end point are located, solving the problem that when path finding is performed by converting a three-dimensional scene into a two-dimensional projection, multi-layer maps are projected on the same projection surface, and it is impossible to distinguish which layer of the map the position on the projection surface is located.

[0166] Step 204: Acquire the area information of the three-dimensional map.

[0167] Step 205: Determine a target area that the virtual object needs to pass through according to the area information, the starting area, and the end area.

[0168] In one embodiment of the present invention, the area information includes the area midpoint and the area-related distance. Determining the target area that the virtual object needs to pass through based on the area information, the starting area and the end area includes: using the A* algorithm to calculate the area path based on the area midpoint, the area-related distance, the starting area and the end area, wherein the area passed by the area path is the target area that the virtual object needs to pass through.

[0169] Specifically, the core of the A* (A-Star) algorithm is to design a cost evaluation function: F(n) = G(n) + H(n), where the evaluation function F(n) is an estimate of the minimum cost path from the starting area through the current area n to the destination area; the function G(n) is the actual cost of the path traveled from the starting area to the current area n, calculated using the area-related distance. For example, if the starting area passes through area 1 and then reaches the current area n, then G(n) is equal to the distance from the midpoint of the starting area to the midpoint of the adjacent edge of area 1, plus the area-related distance, plus the distance from the midpoint of the current area n to the midpoint of the adjacent edge of area 1 (which can be calculated offline); and the function H(n) is the estimated cost of the optimal possible path from the current area n to the destination area, which can be the straight-line distance from the midpoint of the current area to the midpoint of the destination area. Based on F(n), the estimated cost of the current area can be calculated and the next reachable area can be evaluated. The process of searching outwards by finding the area with the smallest cost value each time is adopted, and the optimal path area list is found step by step. Finally, the path of the actual movement process is calculated based on the searched path area list. The path area list is the area path, and the area in the path area list is the target area. Figure 4 , shows a schematic diagram of the regional path finding result provided in an embodiment of the present invention. As can be seen from the figure, the regional path (black arc with arrow) is formed between star (starting point area) and end (end point area), and the target area (dark area) passed by the regional path.

[0170] Step 206: Obtain polygon information of the polygon corresponding to the target area.

[0171] In one embodiment of the present invention, the polygon information is cached in an internal cache, and obtaining the polygon information of the polygon corresponding to the target area includes: detecting whether the polygon information of the polygon corresponding to the target area is cached in the internal cache; if the polygon information is not cached in the internal cache, or the cached polygon information is incomplete, caching the polygon information not cached in the internal cache.

[0172] Specifically, using the LRU cache mechanism, the polygon information is recorded in the cache, and the polygon information required for this pathfinding is checked to see if it is all present in the cache. Following the previous step, the polygon information not cached in the internal cache is cached.

[0173] In the embodiment of the present invention, polygon information of most commonly used areas is cached in the internal cache, thereby avoiding reading all the data when loading the map.

[0174] Step 207: Determine the target polygon that the virtual object needs to pass through based on the polygon information, the starting point and the end point.

[0175] In one embodiment of the present invention, the polygon information includes a polygon midpoint and a polygon-related distance, and the step 207 includes: projecting the polygon corresponding to the starting point and the starting point area onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection starting point and a plane projection polygon; extending a ray from the plane projection starting point to intersect with the plane projection polygon, and determining a polygon corresponding to a plane projection polygon that intersects with the ray an odd number of times as a starting point polygon; projecting the polygon corresponding to the end point and the end point area onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection end point and a plane projection polygon; extending a ray from the plane projection end point to intersect with the plane projection polygon, and determining a polygon corresponding to a plane projection polygon that intersects with the ray an odd number of times as an end point polygon; and calculating a polygon path based on the polygon midpoint, the polygon-related distance, the starting point polygon, and the end point polygon using the A* algorithm, wherein the polygon passed by the polygon path is the target polygon that the virtual object needs to pass through.

[0176] Among them, the horizontal axis is x, the vertical axis is y, and the horizontal axis and the vertical axis constitute the xy plane. Since the method of determining the starting point polygon where the starting point is located is the same as the method of determining the midpoint polygon where the end point is located, the starting point and the end point are collectively referred to as target points as an example for explanation, as follows.

[0177] Specifically, a region grid includes multiple polygons. In order to accurately determine the polygon to which the target point belongs, the target point and the polygons contained in the region are projected on the xy plane, and the projected polygons are processed by the ray method to determine whether the target point is in the xy plane of the polygon. Rays are extended from the target point to intersect with the projected polygons (plane projection polygons), and the polygons corresponding to the plane polygons that intersect with the rays an odd number of times are determined as the region where the target point is located (the starting point polygon or the end point polygon).

[0178] After the start point polygon or the end point polygon is determined, the A* algorithm is used to calculate the polygons through which the virtual object passes: F(n)=G(n)+H(n), wherein the evaluation function F(n) is an estimated value of the minimum cost path from the start point polygon to the end point polygon through the current polygon n; the function G(n) is the actual cost of the path that has been passed from the start point polygon to the current polygon n, which is calculated by the polygon related distance, for example, if the start point polygon passes the polygon 1 and then reaches the current polygon n, then G(n) is equal to the distance from the midpoint of the start point polygon to the midpoint of the adjacent edge of the polygon 1, plus the related distance of the polygon 1, plus the distance from the midpoint of the current polygon n to the midpoint of the adjacent edge of the polygon 1 (which can be calculated offline); the function H(n) is the estimated cost of the possible optimal path from the current polygon n to the end point polygon, which can be the straight line distance from the midpoint of the current polygon to the midpoint of the end point polygon. According to F(n), the estimated cost of the current polygon can be calculated, and the polygon that can be reached next time can be evaluated. The process of searching for the polygon with the minimum cost value each time is continued to search outward, and the optimal path polygon list is found step by step, and finally the path in the actual moving process is calculated according to the searched path polygon list. The polygon list is the polygon path, and the polygons in the polygon list are target polygons.

[0179] In the embodiment of the present application, in order to solve the main problem of memory occupation, the data in the Recast algorithm is operated to construct high-level region information. After the high-level region information is loaded, the region routing is performed, it is confirmed which part of the detail information such as polygon information will be used, and then the detail information of this part is dynamically loaded. This method effectively reduces the amount of information that needs to be loaded into the memory, and reduces a series of performance problems caused by the routing of a large scene.

[0180] Step 208: determining a target path of the virtual object according to the start point region and the end point region.

[0181] The inflection point method is to select the point of the most narrow adjacent edge as an inflection point from a plurality of connected polygons, and repeatedly find a final point set.

[0182] Specifically, after the target polygons through which the virtual object passes are confirmed, the inflection point method is used to select the point of the most narrow adjacent edge as an inflection point from a plurality of connected target polygons, and repeatedly find a final point set, and the point set is connected to become a final target path. Figure 5 , which shows a final routing result schematic diagram provided in the embodiment of the present application. As shown in the figure, the target path (black broken line) is formed between the star (start point region) and the end (end point region).

[0183] To address the primary memory usage issue, this embodiment of the present invention manipulates the data in the Recast algorithm to construct high-level region information. After loading this high-level region information, regional pathfinding is performed, determining which detailed information, such as polygons, will be used, and then dynamically loading this detailed information. This method effectively reduces the amount of information required to be loaded into memory, alleviating a series of performance issues associated with pathfinding in large scenes.

[0184] In addition, the internal cache caches the polygon information of most commonly used areas, avoiding the need to read all the data when the map is loaded.

[0185] After determining the starting area grid and the ending area grid where the starting point and the ending point are located, the map layer and the area where the starting point and the ending point are located can be determined from the starting area grid and the ending area grid covering different layers of map areas. Therefore, path finding in multi-layer map scenes can be performed based on the map layer and the area where the starting point and the ending point are located, which solves the problem that when path finding is performed by converting a three-dimensional scene into a two-dimensional projection, multiple layers of maps are projected on the same projection surface, and it is impossible to distinguish which layer of the map the position on the projection surface is located.

[0186] In order to better understand the above embodiments, the following exemplary description is given with reference to the accompanying drawings:

[0187] Reference Figure 6 , shows a schematic diagram of the hierarchical pathfinding process provided in an embodiment of the present invention. As can be seen from the figure: Recast is used to pre-offline calculate and store all Region (region) and Poly (polygon) information. When performing the pathfinding step, Detour is used to read the data and provide a pathfinding algorithm for pathfinding. The pathfinding steps specifically include: obtaining all Region information, obtaining a rough path (region path) through the Region, confirming the required polygons for the rough path, polygon pathfinding, and obtaining a detailed path (target path). The detailed steps are as follows:

[0188] S100: Region data preparation.

[0189] This step is mainly to build high-level data (referred to as Region data) based on Recast. The basis for building Region data is rcContourSet (region contour information), which contains the basic information of the region and all rcContour (edge ​​contour information). rcContour records the specific region contour vertex information and region connection relationship, as follows:

[0190] Reference Figure 7, shows a schematic diagram of edge contour information provided in an embodiment of the present invention. In the figure, verts is the coordinates of each vertex (v[0], v[1], v[2]) and the region id (v[3]) to which it belongs calculated clockwise, and nverts is the number of verts arrays. rverts is the coordinates of each vertex counterclockwise, and nrverts is the number of rverts arrays. Reg is the region id to which the contour belongs, and area is the label required for the contour to generate the next step of data. These data themselves are intended to generate contours and generate polygons based on the contours. We use this information to construct the required Region information, named rcRegionInfo.

[0191] Reference Figure 8 , shows a schematic diagram of generating regional information provided in an embodiment of the present invention, including:

[0192] S101: Generate RegionGeneral (region basic information), including adjacent regions, number of vertices, and region endpoints.

[0193] S102: Generate RegionVert (region vertex information), including a region fixed point array.

[0194] S103: Generate RegionTile (region grid information), including grid (region grid) index information, index array, and region array contained in the grid (region grid).

[0195] Most of the above information is recorded in rcContourSet, and there is also information that is processed separately according to our needs, such as:

[0196] Midpoint of the region: Calculate the AABB bounding box of the region and take the midpoint of the bounding box.

[0197] Adjacent regions: traverse the verts data in rcContour, define the regions with the same two vertices as adjacent regions, take the edges between the two vertices as adjacent edges, calculate the sum of the distances from the midpoint of the region to the midpoints of the two adjacent edges, and record it as the region-related distance.

[0198] Regional grid information: The map is divided into several regional grids, and the regional grids cover multiple areas. The multiple areas covered by the regional grids include areas on different layers of the map and / or areas on the same layer of the map.

[0199] S200: Region and polygon relationship data preparation.

[0200] Reference Figure 9Fig. 4 shows a schematic diagram of the correspondence between regions and polygons according to an embodiment of the present application. As shown in the figure, after generating the region contour, Recast further divides each region to generate polygons, and stores all the polygons in the structure rcPolyMesh. We obtain the correspondence between regions and polygons and the specific information of the polygons from this structure.

[0201] S201: Generate rcRegPolyInfo: record the poly (polygon) relationship information rcPolygon of the current Region.

[0202] S202: Generate rcPolygon: record the relationship information between the polygon and the Region, and the vertex information of the polygon. Refer to Fig. 4. Figure 10 Fig. 5 shows a schematic diagram of the polygon structure information according to an embodiment of the present application. As shown in the figure, the structure information includes polygon id, number of vertices, polygon characteristic (flag), vertex array, polygon midpoint and adjacent polygon array.

[0203] Among the specially constructed data are:

[0204] Index array: record the size of the storage data occupied by each region in the unit of region. The generated index is placed at the beginning of the file for fast access.

[0205] poly_id+region_id: use Cantor pairing function to combine the two values, in order to quickly access the subsequent process.

[0206] S300: Perform path finding between Regions.

[0207] Refer to Fig. 6. Figure 11 Fig. 7 shows a schematic diagram of the path finding process according to an embodiment of the present application. Refer to Fig. 8. Figure 12 Fig. 9 shows a schematic diagram of reading the region information according to an embodiment of the present application. As shown in the figure:

[0208] S301: Read the region information.

[0209] S302: Read the basic information RegionGeneral of all the regions, which is used for path finding between regions.

[0210] S303: Read the region vertex information RegionVert around the player, which is used to determine the start and end points.

[0211] S304: Read the region tile information RegionTile around the player, which is used to determine the start and end points.

[0212] Among the region vertex information and the region tile information, dynamic reading can be performed according to the needs.

[0213] S305: Calculate the area where the target point (starting point or end point) is located.

[0214] S306: Calculate the regional path.

[0215] Pathfinding between regions is performed using the region midpoint and information about neighboring regions. Using the A* algorithm, f = g + h, where h is the Euclidean distance between the midpoints of the two regions and g is the inter-region distance calculated offline and stored in the region basic information. The inter-region distance here is the sum of the distances from the region midpoint to the midpoints of its two adjacent edges.

[0216] S400: Obtain a specific path according to the regional path.

[0217] Reference Figure 13 , shows a schematic diagram of a process from obtaining a polygon to obtaining a specific path provided in an embodiment of the present invention, as shown in the figure:

[0218] S401: Calculate the required polygons and obtain region-related polygon information.

[0219] In step S202, the recorded index array data is used to dynamically read the rcPolygon information of the relevant region and record the poly_id.

[0220] S402: Check whether the required polygon information is in the cache.

[0221] Using the LRU cache mechanism, polygon information is recorded in the cache, and it is checked whether all polygon information required for this pathfinding exists in the cache.

[0222] S403: Read the polygon information that does not exist in the storage:

[0223] Following the previous step, polygon information that does not exist in the cache is recorded in the cache. The caching mechanism here caches the polygon information of most commonly used areas during use, avoiding the need to read all the data when the map is loaded.

[0224] S404: Calculate the polygons where the starting and ending points are located.

[0225] Since we already have the start and end region IDs, we can perform a raycast comparison on all polygons in the region to get the start and end polygons. Giving each polygon a unique ID facilitates subsequent pathfinding.

[0226] S405: Use the A* algorithm to perform polygon pathfinding.

[0227] Pathfinding is done based on the distance between polygon midpoints and polygonal relationships. The A* algorithm uses Euclidean distance to calculate estimates, which provides high precision and accuracy.

[0228] S406: Find the final path based on the polygonal path using the inflection point method.

[0229] The embodiments of the present invention bring the following effects:

[0230] Beneficial effects brought by the technical solution of the present invention

[0231] Small memory usage: Based on the high-level pathfinding results, detailed polygon data is dynamically read and the required relevant information is flexibly accessed using a caching mechanism to reduce memory usage.

[0232] Pathfinding speed balance: Based on the speed of hierarchical pathfinding in regions, the average pathfinding time in large maps is within the preset time, which is within an acceptable range in actual games.

[0233] Friendly to existing frameworks: The data and methods used are based on the existing Recast project, making project improvement and iteration easy without spending a lot of time on integration and adaptation.

[0234] It should be noted that for the sake of simplicity, the method embodiments are described as a series of actions. However, those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0235] Reference Figure 14 , shows a structural block diagram of a hierarchical pathfinding device provided in an embodiment of the present invention, which is applied to a three-dimensional map. The three-dimensional map includes one or more maps on one layer. The three-dimensional map is constructed with multiple regional grids. Each map layer is divided into multiple regions. The regional grids cover multiple regions. The multiple regions covered by the regional grids include regions on different map layers and / or regions on the same map layer. Specifically, the device may include the following modules:

[0236] A position determination module 1401 is configured to respond to a pathfinding instruction and determine a starting point and an end point of a virtual object in the three-dimensional map;

[0237] A grid determination module 1402 is configured to determine a starting area grid and an ending area grid where the starting point and the ending point are located;

[0238] An area determination module 1403 is configured to determine a starting area where the starting point is located from among the multiple areas of the starting area grid, and to determine an end area where the end point is located from among the multiple areas of the end area grid;

[0239] The path determination module 1404 is configured to determine a target path of the virtual object according to the starting area and the ending area.

[0240] Optionally, the region determination module 1403 includes:

[0241] A region projection submodule, configured to project the starting point and multiple regions of the starting point region grid onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection starting point and a plane projection region;

[0242] an area determination submodule, configured to extend a ray from the plane projection starting point to intersect the plane projection area, and determine an area corresponding to the plane projection area that intersects the ray an odd number of times;

[0243] The region determination submodule is further configured to, if there is only one region corresponding to the plane projection region that intersects the ray an odd number of times, determine the region corresponding to the plane projection region that intersects the ray an odd number of times as a starting region;

[0244] The area projection submodule is further configured to, if there are multiple areas corresponding to the plane projection area having an odd number of intersections with the ray, project the areas corresponding to the plane projection area having an odd number of intersections with the ray and the starting point onto the vertical axis to obtain a vertical axis projection starting point and a vertical axis projection area;

[0245] The region determining submodule is further configured to determine the region corresponding to the vertical axis projection region including the vertical axis projection starting point as a starting point region if the region corresponding to the vertical axis projection region including the vertical axis projection starting point is one;

[0246] a plane forming submodule, configured to select a plurality of points from the area corresponding to the vertical axis projection area including the vertical axis projection starting point to form a plurality of planes if there are multiple areas corresponding to the vertical axis projection area including the vertical axis projection starting point;

[0247] The region determination submodule is further configured to determine the region corresponding to the plane closest to the starting point as the starting point region.

[0248] Optionally, the region determination module 1403 includes:

[0249] The area projection submodule is further used to project the end point and multiple areas of the end point area grid onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection end point and a plane projection area;

[0250] The region determination submodule is further configured to extend a ray from the plane projection endpoint to intersect the plane projection region, and determine a region corresponding to the plane projection region that intersects the ray an odd number of times;

[0251] The region determination submodule is further configured to, if there is only one region corresponding to the plane projection region that intersects the ray an odd number of times, determine the region corresponding to the plane projection region that intersects the ray an odd number of times as an end region;

[0252] The area projection submodule is further configured to, if there are multiple areas corresponding to the plane projection area having an odd number of intersections with the ray, project the areas corresponding to the plane projection area having an odd number of intersections with the ray and the end point onto the vertical axis to obtain a vertical axis projection end point and a vertical axis projection area;

[0253] The region determining submodule is further configured to determine the region corresponding to the vertical axis projection region including the vertical axis projection end point as the end point region if the region corresponding to the vertical axis projection region including the vertical axis projection end point is one;

[0254] a plane forming submodule, configured to select a plurality of points from the area corresponding to the vertical axis projection area including the vertical axis projection end point to form a plurality of planes if there are multiple areas corresponding to the vertical axis projection area including the vertical axis projection end point;

[0255] The region determination submodule is further configured to determine the end point region by using the region corresponding to the plane closest to the end point.

[0256] Optionally, the area is divided into multiple polygons, and the path determination module 1304 includes:

[0257] An information acquisition submodule, configured to acquire regional information of the three-dimensional map;

[0258] The area determination submodule is further configured to determine a target area that the virtual object needs to pass through based on the area information, the starting area, and the ending area;

[0259] The information acquisition submodule is further used to obtain polygon information of the polygon corresponding to the target area;

[0260] A polygon determination submodule, configured to determine a target polygon that the virtual object needs to pass through based on the polygon information, the starting point, and the end point;

[0261] The path determination submodule is configured to determine a target path of the virtual object according to the target polygon.

[0262] Optionally, the region information includes a midpoint of the region and a related distance of the region, and the region determination submodule includes:

[0263] The area determination unit is used to calculate the area path using the A* algorithm based on the midpoint of the area, the relevant distance of the area, the starting area and the end area, wherein the area passed by the area path is the target area that the virtual object needs to pass through.

[0264] Optionally, the polygon information is cached in an internal cache, and the information acquisition submodule includes:

[0265] An information detection unit, configured to detect whether polygon information of a polygon corresponding to the target area is cached in an internal cache;

[0266] The information caching unit is configured to cache the polygon information not cached in the internal cache if the polygon information is not cached in the internal cache or the cached polygon information is incomplete.

[0267] Optionally, the polygon information includes polygon midpoints and polygon-related distances, and the polygon determination submodule according to the polygon information includes:

[0268] A polygon projection unit, configured to project the polygon corresponding to the starting point and the starting point area onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection starting point and a plane projection polygon;

[0269] A polygon determination unit is configured to extend a ray from a plane projection starting point to intersect with the plane projection polygon, and determine a polygon corresponding to the plane projection polygon that intersects the ray an odd number of times as a starting polygon;

[0270] The polygon projection unit is further used to project the polygon corresponding to the end point and the end point area onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection end point and a plane projection polygon;

[0271] The polygon determination unit is further configured to extend a ray from the plane projection end point to intersect the plane projection polygon, and determine a polygon corresponding to the plane projection polygon that intersects the ray an odd number of times as the end point polygon;

[0272] The polygon determination unit is used to calculate the polygon path based on the polygon midpoint, the polygon related distance, the starting polygon and the end polygon using the A* algorithm, wherein the polygon passed by the polygon path is the target polygon that the virtual object needs to pass through.

[0273] Optionally, it also includes:

[0274] The area information of the three-dimensional map is generated by the following steps:

[0275] The map division module is configured to divide the three-dimensional map into regions to obtain region vertices;

[0276] The midpoint determination module is configured to determine a bounding box of the region according to the region vertices, and take a midpoint of the bounding box as a region midpoint of the region.

[0277] The adjacent region determination module is configured to traverse the region vertices, and take a region with two region vertices as adjacent regions, and an edge between the two region vertices as a neighboring edge.

[0278] The distance calculation module is configured to calculate a sum of distances from the region midpoint to midpoints of two neighboring edges as a region-related distance.

[0279] Optionally, the method further comprises:

[0280] The polygon information of the three-dimensional map is generated by the following steps:

[0281] The region division module is configured to divide the region into polygons to obtain a correspondence between the polygons and the region, and polygon vertices.

[0282] The midpoint determination module is further configured to determine a polygon midpoint according to the polygon vertices.

[0283] The adjacent polygon determination module is configured to traverse the polygon vertices, and take a polygon with two polygon vertices as adjacent polygons, and an edge between the two polygon vertices as a neighboring edge.

[0284] The distance calculation module is further configured to calculate a sum of distances from the polygon midpoint to midpoints of two neighboring edges as a polygon-related distance.

[0285] For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the related parts can be referred to the part of the method embodiment.

[0286] In addition, the embodiment of the present application further provides an electronic device, such as Figure 15 As shown in the figure, the electronic device comprises a processor 1501, a communication interface 1502, a memory 1503 and a communication bus 1504, wherein the processor 1501, the communication interface 1502 and the memory 1503 complete mutual communication through the communication bus 1504,

[0287] The memory 1503 is configured to store a computer program.

[0288] The processor 1501 is configured to execute the program stored in the memory 1503 to implement the hierarchical routing method described in the above embodiment.

[0289] The communication bus mentioned in the terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not mean that there is only one bus or only one type of bus.

[0290] The communication interface is used for communication between the above terminal and other devices.

[0291] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor.

[0292] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.

[0293] like Figure 16 As shown, in another embodiment provided by the present invention, a computer-readable storage medium 1601 is also provided, in which instructions are stored. When the computer-readable storage medium 1601 is run on a computer, the computer executes the hierarchical pathfinding method described in the above embodiment.

[0294] In another embodiment of the present invention, a computer program product including instructions is provided. When the computer program product is run on a computer, the computer is enabled to execute the hierarchical pathfinding method described in the above embodiment.

[0295] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).

[0296] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0297] Each embodiment in this specification is described in a related manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiment is generally similar to the method embodiment, so the description is relatively simple. For related parts, refer to the description of the method embodiment.

[0298] The above description is only a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention are included in the scope of protection of the present invention.

Claims

1. A hierarchical pathfinding method, characterized in that: Applied to a three-dimensional map, the three-dimensional map includes one or more maps, the three-dimensional map is constructed with multiple regional grids, each map layer is divided into multiple regions, the regional grid covers multiple regions, and the multiple regions covered by the regional grid include regions on different map layers and / or regions on the same map layer, including: Dividing the three-dimensional map into regions to obtain region vertices; Determine a bounding box of the region according to the vertices of the region, and use the midpoint of the bounding box as the region midpoint of the region; Traversing the region vertices, taking regions with the same two region vertices as adjacent regions, and the edge between the two region vertices as the adjacent edge; Calculate the sum of the distances from the midpoint of the region to the midpoints of the two adjacent sides as the relevant distance of the region; In response to a pathfinding instruction, determining a starting point and an end point of a virtual object in the three-dimensional map; Determine a starting point area grid and an ending point area grid where the starting point and the ending point are located; Determine a starting area where the starting point is located from a plurality of areas of the starting area grid, and determine an end area where the end point is located from a plurality of areas of the end area grid; A target path of the virtual object is determined according to the area-related distance, the starting area, and the end area.

2. The method according to claim 1, characterized in that The determining the starting area where the starting point is located from the multiple areas of the starting area grid includes: Projecting the starting point and multiple areas of the starting point area grid onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection starting point and a plane projection area; Extending a ray from the starting point of the plane projection to intersect the plane projection area, and determining an area corresponding to the plane projection area where the ray intersects an odd number of times; If there is only one area corresponding to the plane projection area that intersects the ray an odd number of times, determining the area corresponding to the plane projection area that intersects the ray an odd number of times as the starting point area; If there are multiple areas corresponding to the plane projection area whose number of intersections with the ray is odd, projecting the areas corresponding to the plane projection area whose number of intersections with the ray is odd and the starting point onto the vertical axis to obtain the vertical axis projection starting point and the vertical axis projection area; If the area corresponding to the vertical axis projection area including the vertical axis projection starting point is one, determine the area corresponding to the vertical axis projection area including the vertical axis projection starting point as the starting point area; If there are multiple areas corresponding to the vertical axis projection area including the vertical axis projection starting point, multiple points are selected from the areas corresponding to the vertical axis projection area including the vertical axis projection starting point to form multiple planes; An area corresponding to a plane closest to the starting point is determined as the starting point area.

3. The method according to claim 1, characterized in that The step of determining the destination area where the destination is located from the plurality of areas of the destination area grid includes: Projecting the end point and the multiple regions of the end point region grid onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection end point and a plane projection region; Extending a ray from the plane projection endpoint to intersect the plane projection area, and determining an area corresponding to the plane projection area where the ray intersects an odd number of times; If there is only one area corresponding to the plane projection area that intersects the ray an odd number of times, determining the area corresponding to the plane projection area that intersects the ray an odd number of times as the end point area; If there are multiple areas corresponding to the plane projection area that intersects the ray an odd number of times, projecting the areas corresponding to the plane projection area that intersects the ray an odd number of times and the end point onto the vertical axis to obtain the vertical axis projection end point and the vertical axis projection area; If the area corresponding to the vertical axis projection area including the vertical axis projection end point is one, determining the area corresponding to the vertical axis projection area including the vertical axis projection end point as the end point area; If there are multiple areas corresponding to the vertical axis projection area including the vertical axis projection end point, multiple points are selected from the areas corresponding to the vertical axis projection area including the vertical axis projection end point to form multiple planes; The end point area is determined as an area corresponding to a plane closest to the end point.

4. The method according to any one of claims 1 to 3, characterized in that The area is divided into a plurality of polygons, and determining a target path of the virtual object according to the starting area and the end area includes: Acquiring area information of the three-dimensional map; Determine a target area that the virtual object needs to pass through according to the area information, the starting area, and the end area; Obtaining polygon information of the polygon corresponding to the target area; Determining a target polygon that the virtual object needs to pass through according to the polygon information, the starting point, and the end point; A target path of the virtual object is determined based on the target polygon.

5. The method according to claim 4, characterized in that The area information includes a midpoint of the area and a related distance of the area. The determining of the target area that the virtual object needs to pass through based on the area information, the starting area, and the end area includes: Based on the midpoint of the area, the area-related distance, the starting area and the end area, an A* algorithm is used to calculate an area path, wherein the area passed by the area path is the target area that the virtual object needs to pass through.

6. The method according to claim 4, characterized in that The polygon information is cached in an internal cache, and the obtaining of polygon information corresponding to the target area includes: Detecting whether polygon information of a polygon corresponding to the target area is cached in an internal cache; If the polygon information is not cached in the internal cache, or the cached polygon information is incomplete, the polygon information not cached in the internal cache is cached.

7. The method according to claim 4, characterized in that The polygon information includes a polygon midpoint and a polygon-related distance, and determining a target polygon that the virtual object needs to pass through based on the polygon information, the starting point, and the end point includes: Projecting the starting point and the polygon corresponding to the starting point area onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection starting point and a plane projection polygon; Extending a ray from the plane projection starting point to intersect the plane projection polygon, and determining a polygon corresponding to the plane projection polygon that intersects the ray an odd number of times as the starting polygon; Projecting the end point and the polygon corresponding to the end point area onto a plane formed by a horizontal axis and a vertical axis to obtain a plane projection end point and a plane projection polygon; Extending a ray from the plane projection end point to intersect the plane projection polygon, and determining a polygon corresponding to the plane projection polygon that intersects the ray an odd number of times as the end point polygon; Based on the polygon midpoint, the polygon related distance, the starting polygon and the end polygon, the polygon path is calculated using the A* algorithm, wherein the polygon passed by the polygon path is the target polygon that the virtual object needs to pass through.

8. The method according to claim 1, characterized in that Also includes: The polygon information of the three-dimensional map is generated by the following steps: Performing polygon division on the area to obtain a corresponding relationship between the polygons and the area, as well as vertices of the polygons; Determine the midpoint of the polygon according to the vertices of the polygon; Traversing the polygon vertices, taking polygons with the same two polygon vertices as adjacent polygons, and the edge between the two polygon vertices as the adjacent edge; The sum of the distances from the midpoint of the polygon to the midpoints of the two adjacent sides is calculated as the polygon-related distance.

9. A hierarchical pathfinding device, characterized in that: Applied to a three-dimensional map, the three-dimensional map includes one or more maps, the three-dimensional map is constructed with multiple regional grids, each map layer is divided into multiple regions, the regional grids cover multiple regions, and the multiple regions covered by the regional grids include regions on different map layers and / or regions on the same map layer. The device includes: A map division module, configured to divide the three-dimensional map into regions and obtain region vertices; a midpoint determination module, configured to determine a bounding box of the region according to the vertices of the region, and use the midpoint of the bounding box as the region midpoint of the region; an adjacent region determining module, configured to traverse the region vertices and define regions having two identical region vertices as adjacent regions, and an edge between the two region vertices as an adjacent edge; A distance calculation module, configured to calculate the sum of the distances from the midpoint of the region to the midpoints of the two adjacent sides as the region-related distance; a position determination module, configured to respond to a pathfinding instruction and determine a starting point and an end point of a virtual object in the three-dimensional map; A grid determination module, used to determine the starting area grid and the ending area grid where the starting point and the ending point are located; an area determination module, configured to determine a starting area where the starting point is located from a plurality of areas of the starting area grid, and to determine an end area where the end point is located from a plurality of areas of the end area grid; A path determination module is used to determine a target path of the virtual object according to the area-related distance, the starting area and the end area.

10. An electronic device, characterized in that: comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; The memory is used to store computer programs; The processor is configured to implement the method according to any one of claims 1 to 8 when executing a program stored in the memory.

11. One or more computer-readable media having instructions stored thereon, which, when executed by one or more processors, cause the processors to perform the method of any one of claims 1-8.

Citation Information

Patent Citations

  • Three-dimensional scene path finding method and device and three-dimensional scene map processing method and device

    CN112221144A