Method and device for path finding in three-dimensional space of scene, electronic equipment and storage medium
By constructing octree node voxel encoding and dynamically loading and unloading map tiles, the problem of excessive memory consumption in large-scale 3D scenes is solved, and efficient path planning is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NETEASE (HANGZHOU) NETWORK CO LTD
- Filing Date
- 2023-06-08
- Publication Date
- 2026-07-31
AI Technical Summary
Existing technologies consume excessive memory when planning paths in large-scale 3D scenes. While the improved Morton coding method saves memory, it has high redundancy overhead and cannot support path planning in complex areas.
An octree node voxel encoding is constructed, blocking voxels are marked, and dynamic loading and unloading of map tiles are combined with the intelligent agent's position to determine the loading operation, thereby reducing memory consumption.
It improves the accuracy of path planning, reduces memory consumption, and supports path planning for large and complex areas.
Smart Images

Figure CN116672715B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of spatial pathfinding technology, and in particular to a pathfinding method, apparatus, electronic device and storage medium in a three-dimensional scene space. Background Technology
[0002] In 3D pathfinding within games, traditional 3D path planning methods (such as the A* algorithm) consume excessive memory when the scene size is large. While path planning methods using Merton coding can save some memory, the recording of node indices leads to redundant memory overhead. Furthermore, the sheer number of nodes in large 3D scenes is enormous, and the number of nodes that Merton coding-based methods can represent is very limited, thus still unable to support large-scale 3D scenes. In addition, large 3D spaces often contain complex regions, which traditional path planning methods cannot support. Summary of the Invention
[0003] The purpose of this application is to provide a pathfinding method, device, electronic device, and storage medium in a three-dimensional scene space, which improves the accuracy of pathfinding and reduces memory consumption during the pathfinding process.
[0004] In a first aspect, the present invention provides a pathfinding method in a three-dimensional space of a scene, the method comprising:
[0005] For each node voxel in the octree structure in a 3D scene, an octree node voxel encoding is constructed; the octree node voxel encoding is used to represent the spatial position information of each node voxel in the pathfinding space.
[0006] Calculate the number of node voxels occupied by physical obstacles in the pathfinding space in the 3D scene, and mark the occupied node voxels as obstacle voxels.
[0007] Based on the relationship between the agent's position in world space and the map tile update constraints, it is determined whether to perform a loading or unloading operation of map tiles in the 3D scene to dynamically update the map tiles, and to perform pathfinding processing based on the position of the blocking voxels in the updated map tiles; wherein, each map tile corresponds to an octree structure, and each octree structure has octree node voxel encoding for representing spatial location information.
[0008] Secondly, the present invention provides a pathfinding device in a three-dimensional space of a scene, the device comprising:
[0009] The encoding construction module is used to construct octree node voxel encoding for each node voxel in the octree structure in the 3D scene; the octree node voxel encoding is used to represent the spatial position information of each node voxel in the pathfinding space.
[0010] The voxel partitioning module is used to calculate the number of node voxels occupied by physical obstacles in the pathfinding space in the 3D scene, and to mark the occupied node voxels as obstacle voxels.
[0011] The pathfinding module is used to determine whether to perform loading or unloading operations on map tiles in the 3D scene based on the relationship between the location in world space and the map tile update constraints, so as to dynamically update the map tiles and perform pathfinding processing based on the position of the blocking voxels in the updated map tiles. Each map tile corresponds to an octree structure, and each octree structure has octree node voxel encodings for representing spatial location information.
[0012] Thirdly, the present invention provides an electronic device including a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the pathfinding method in a three-dimensional space of a scene as described in any of the foregoing embodiments.
[0013] Fourthly, the present invention provides a computer-readable storage medium storing computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the pathfinding method in a three-dimensional space of a scene as described in any of the foregoing embodiments.
[0014] The beneficial effects of the pathfinding method, device, electronic device, and storage medium in three-dimensional space provided in this application are as follows:
[0015] By constructing node voxel encoding and determining obstruction voxels based on octree node voxel encoding, obstruction and non-obstruction information in a 3D scene can be determined. For scenes with complex regions, pathfinding can be determined more accurately. Furthermore, by dynamically loading / unloading map tiles based on the relationship between the agent's position in world space and map tile update constraints, only the map tiles used in the pathfinding process can be loaded during pathfinding, thus greatly reducing memory consumption during the pathfinding process. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the specific embodiments of this application or the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0017] Figure 1 A flowchart illustrating a pathfinding method in a three-dimensional scene provided in this application embodiment;
[0018] Figure 2 A schematic diagram of each node in an octree provided in an embodiment of this application;
[0019] Figure 3 This application provides voxel representation data in three-dimensional space for embodiments of the present application;
[0020] Figure 4 A schematic diagram showing the distribution and size of voxels in a fully partitioned octree with three layers, provided for an embodiment of this application;
[0021] Figure 5 A schematic diagram of a world space and a pathfinding space provided for an embodiment of this application;
[0022] Figure 6 The spatial range of a pre-configured pathfinding space provided in the embodiments of this application;
[0023] Figure 7 A simplified schematic diagram illustrating a complex enclosed cave scene configuration provided in an embodiment of this application;
[0024] Figure 8 A schematic diagram of cave determination provided in an embodiment of this application;
[0025] Figure 9 A structural diagram of a pathfinding device in a three-dimensional scene provided in an embodiment of this application;
[0026] Figure 10 This is a structural diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0028] Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0029] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0030] First, let me introduce the terms used in this application:
[0031] (1) Map Tile Cell: refers to the evenly divided area within the range selected by the user, with each area generating a corresponding sparse octree.
[0032] (2) Complex cave scene (Hole): refers to the cave area selected by the user, and the corresponding sparse octree will be calculated separately for this area.
[0033] For path planning in 3D space, traditional techniques can support small 3D scenes, but due to excessive memory overhead, they fail to support larger scenes (e.g., 1024m*1024m*1024m). While using Merton coding-based sparse octree nodes can save some memory, the need to record node indices leads to redundant memory overhead. For large-scale 3D scenes, the number of nodes is enormous, while the number of nodes that Merton coding-based sparse octree nodes can represent is very limited, making it unsuitable for large scenes (e.g., 4096m*4096m*4096m). Furthermore, large-scale 3D spaces often contain complex regions, and traditional methods cannot adequately support path planning in these complex regions.
[0034] Based on this, embodiments of this application provide a pathfinding method, apparatus, electronic device, and storage medium in a three-dimensional space of a scene, which can improve the accuracy of pathfinding and reduce memory consumption during the pathfinding process.
[0035] This application provides a pathfinding method in a three-dimensional scene space, see [link to relevant documentation]. Figure 1 As shown, the method mainly includes the following steps:
[0036] Step S110: For each node voxel of the octree structure in the 3D scene, construct the octree node voxel encoding; the octree node voxel encoding is used to represent the spatial location information of each node voxel in the pathfinding space.
[0037] Step S120: Calculate the number of node voxels occupied by physical obstacles in the 3D scene in the pathfinding space, and mark the occupied node voxels as obstacle voxels.
[0038] Step S130: Based on the relationship between the agent's position in the world space and the map tile update constraints, determine whether to perform a loading or unloading operation of map tiles in the 3D scene to dynamically update the map tiles, and perform pathfinding processing based on the position of the blocking voxels in the updated map tiles; wherein, each map tile corresponds to an octree structure, and each octree structure has octree node voxel encoding for representing spatial location information.
[0039] The pathfinding method in the three-dimensional space of the scene provided in this application constructs node voxel encoding and determines the blocking voxels based on the octree node voxel encoding. This can determine the blocking and non-blocking information in the three-dimensional scene. For large scenes with complex areas, the pathfinding path can be determined more accurately. Furthermore, by dynamically loading / unloading map tiles, only the map tiles used in the pathfinding process can be loaded during the pathfinding process, thus greatly reducing the memory consumption during the pathfinding process.
[0040] The following provides a detailed description of the pathfinding method in three-dimensional space provided in the embodiments of this application.
[0041] In an optional implementation, for each node voxel of the octree structure in the 3D scene, an octree node voxel encoding is constructed. In specific implementation, this may include the following steps 1-1 to 1-3:
[0042] Step 1-1: For each voxel in the octree structure of the 3D scene, obtain the bounding box information of the voxel.
[0043] Steps 1-2: Calculate the voxel coordinates of each voxel based on the bounding box information of the voxels.
[0044] Steps 1-3: For each node voxel, determine its coordinates and level, and construct the octree node voxel encoding corresponding to that node voxel in the octree structure.
[0045] In an octree, each node has a center coordinate. Relative to the center coordinate of its parent node, the offset in three directions can include three different cases. Therefore, only three bits are needed to number the child nodes, with a numbering range of 0 to 7. Figure 2 As shown.
[0046] The bounding box information of octree node voxels described in this application embodiment can be used to characterize the distribution of node voxels, node levels, and node sizes. In one embodiment, the bounding box of a node voxel can be represented using (Min, Size). Figure 3The diagram shows that Min and Size represent the representation data of a voxel in three-dimensional space. Min refers to the coordinates of the lower left corner of the node voxel, represented by three 16-bit unsigned integers; Size represents the size of the node voxel's bounding box, represented by a 16-bit unsigned integer.
[0047] The above octree node voxel encoding can be done using the (Index, Layer) method. Here, Index refers to the coordinates of the node voxel, which occupies 27 bits in a 32-bit encoding. Layer refers to the level of the node in the octree, which is counted from the leaf node to the root node, occupying 4 bits. In total, it occupies 31 bits. The remaining bit is used to mark whether the encoding is valid, with 0 indicating valid and 1 indicating invalid.
[0048] Figure 4 This diagram illustrates the voxel distribution and size in a fully partitioned octree with three levels. The root node is at level 2, and the levels down to the leaf nodes are at level 0. The voxel distribution and size differ at different levels. The left diagram shows the root node voxel, which is 4m in size. The middle diagram shows the voxel distribution at level 1, with each voxel measuring 2m. The right diagram shows the voxel distribution and size of each leaf node at level 0, with each voxel measuring 1m.
[0049] When calculating the voxel coordinates of each node, the Min value of the bottom-left node is uniformly denoted as (0,0,0) and treated as the origin. The coordinates of each node voxel can be calculated using the following formula, and the result will be converted to an integer:
[0050]
[0051]
[0052]
[0053] For the Size of each layer, as long as Size is a power of two, the relationship between Size and the number of layers is as follows: size = 2 layer .
[0054] Furthermore, the encoding of the octree node voxel can be calculated according to the following computer program expression: HashCode = dz << 22 | dy << 13 | dx << 4 | layer.
[0055] For example, for a node voxel with a level of 1 and a size of 2, the calculated d for point A is... x d y d zIf the values are (0, 2, 0), then the corresponding octree node voxel encoding is 0 << 22 | 2 << 13 | 2 << 4 | 1; the d calculated from point B is... x d y d z Given (2, 1, 0) respectively, the corresponding octree node voxel encoding is 0 << 22 | 1 << 13 | 2 << 4 | 1; the d calculated from point C is... x d y d z If the values are (1,2,2), then the corresponding octree node voxel encoding is 2<<22|2<<13|1<<4|1.
[0056] To facilitate pathfinding, this embodiment uses a pathfinding space for pathfinding calculations, where the pathfinding space refers to the space of the octree itself. However, since a 3D scene is a world space, this embodiment provides a method for converting between the pathfinding space and world controls.
[0057] See Figure 5 As shown, the larger cube region represents the world space contained within a map tile cell, and the cube regions within it represent the pathfinding space. The bottom left corners of the two regions overlap, which is the location of the pathfinding space origin in world space. Since both regions are cubes, there will be a scaling factor between them. Figure 5 In the diagram, the point pointed to by the dashed line is a point in world space. Converting it to pathfinding space involves calculating its offset relative to the origin of pathfinding space and scaling it. The result is the point in pathfinding space. Correspondingly, the conversion from pathfinding space to world space is the reverse process.
[0058] Pathfinding algorithms operate within the pathfinding space. The input world space data (position coordinates, distance, and bounding box data) needs to be transformed into the pathfinding space to calculate and smooth the path. The output path of the pathfinding algorithm is in the pathfinding space, requiring data transformation back to world space. The scaling factor and the conversion formula between pathfinding space and world space are as follows:
[0059]
[0060]
[0061] P World =rigin+P cell *cale
[0062] Wherein, WorldSize represents the size of the map tile (Tile Cell) region in world space (the size of the blue area in the image above), and CellSize represents the size of the pathfinding space of the map tile region (the size of the green area in the image above). Pworld and Pcell represent points in world space and pathfinding space, respectively. Origin represents the origin of the map tile in world space (the lower left corner of the blue area in the image above). Scale represents the scaling factor.
[0063] To improve the universality of the method, enabling it to be used for pathfinding even in large scenes including complex areas, the aforementioned 3D scene can include open-world scenes and cave scenes, with the cave scene being a relatively complex enclosed cave. For open-world scenes within a 3D scene, in one optional implementation, the calculation of the number of voxels occupied by physical obstacles in the 3D scene within the pathfinding space, and the marking of these occupied voxels as obstacle voxels, can, in specific implementation, include steps 2-1 to 2-4:
[0064] Step 2-1: Pre-configure the spatial extent of the pathfinding space within the map tiles. See also... Figure 6 As shown, the cubic region is a pre-configured region.
[0065] Step 2-2: Based on the scaling factor of the pathfinding space relative to the world space corresponding to the 3D scene and the spatial range of the pathfinding space corresponding to each map tile, calculate the number of map tiles contained in the world space. In one implementation, the size of each map tile in the world space can be calculated based on the scaling factor of the pathfinding space configured by the user and the size of the pathfinding space of each map tile, and then the number of tiles in each direction within the large world range can be calculated based on the size of the map tile.
[0066] Steps 2-3 involve extracting collision geometry data from world space and converting it to the pathfinding space corresponding to the map tile containing the world space. Methods such as collision testing can be used to extract the collision geometry data, which will not be detailed here. The conversion from pathfinding space to world space is calculated using the aforementioned conversion formula.
[0067] Steps 2-4 involve dividing the octree node voxel encoding of the pathfinding space to obtain the node voxels occupied by the collision geometry in the pathfinding space, and marking the occupied node voxels as blocking voxels.
[0068] Furthermore, to facilitate the processing of each map tile and prevent pathfinding failures due to the inability of map tiles to communicate with each other during overall pathfinding, in one implementation, the connected regions between each adjacent map tile can be determined sequentially to identify the final overall connected region capable of pathfinding, as well as multiple connected points within that region. In specific implementation, steps 3-1 to 3-6 can be used for processing:
[0069] Step 3-1: Divide the octree node voxel encoding of the pathfinding space to obtain non-blocking voxels;
[0070] Step 3-2: Cluster the interconnected regions in the top map tiles of the pathfinding space, and determine the connected region with the largest area on the top surface after clustering as the global connected region.
[0071] Step 3-3: Starting from the global connected regions and working downwards, generate connected regions on the connected surfaces between each map tile;
[0072] Steps 3-4: Perform connectivity tests between the connected components and the global connected components, and merge the connected components that pass the test into the set of global connected components;
[0073] Steps 3-5: Delete the connected regions corresponding to the top map tiles, and determine the remaining connected regions in the global connected region set as the connected regions between each map tile.
[0074] Steps 3-6: Calculate and generate the connected points of each connected surface based on the non-blocking voxels that constitute each connected region.
[0075] In practical applications, to enable interconnection between map tiles, connected points can be generated on the connecting surfaces of the tiles. First, a global connected region (Section) needs to be constructed. Connected regions are composed of non-blocking voxels attached to the connected surfaces. The algorithm first constructs the connected regions of the top-level map tile, clusters interconnected regions, and then selects the connected region with the largest top area as the global connected region. Subsequently, from top to bottom, connected regions are generated on the connecting surfaces between each map tile. Based on a path planning algorithm, a connectivity test is performed between the newly generated connected regions and the global connected region, and regions that pass the test are added to the set of global connected regions. Next, the topmost connected region is removed from the global connected regions, and the remaining connected regions are the regions connecting each map tile. Finally, based on the non-blocking voxels constituting each connected region, connected points are calculated and generated on each connected surface.
[0076] Furthermore, for enclosed caves in a 3D scene, when calculating the number of voxels occupied by physical obstacles in the 3D scene in the pathfinding space and marking the occupied voxels as obstacle voxels, the following steps 4-1 to 4-4 may be included:
[0077] Step 4-1: Pre-mark the cave's boundaries, exit, and entrance; both the cave exit and entrance contain connecting points on either side.
[0078] Step 4-2: Mark the cave exit, cave entrance, and the area outside the cave's enclosure as blocked areas in advance;
[0079] Step 4-3: Extract the obstruction geometry data within the obstruction area and convert the obstruction geometry data to the pathfinding space corresponding to the map tile where the world space is located.
[0080] Step 4-4: Divide the octree node voxel encoding of the pathfinding space to obtain the node voxels occupied by the blocking region in the pathfinding space, and mark the occupied node voxels as blocking voxels.
[0081] For complex, enclosed cave scenes (Hole Cell), users need to manually mark the extent and entrances / exits of the enclosed cave. The extent of the cave is represented by an AABB bounding box, and the entrances / exits are coordinate points in two world spaces. Figure 7 This diagram illustrates a simplified configuration of a complex, enclosed cave scene (Hole Cell). The outermost box represents a map tile (Tile Cell) in the external world, the inner box represents a cave configured by the user, and the irregular area inside is the geometry that constitutes the cave. There are two points on either side of the cave's entrance and exit indicating that they are connected.
[0082] When generating a sparse octree representing a complex closed cave, it is necessary to... Figure 7 The entrance to the central cave and the area outside the cave are marked as blocked areas, see reference. Figure 8 In the pathfinding algorithm, when the input point is in the shaded area within the small box, it can be considered that the point is inside the cave; otherwise, the input point is considered to be outside the cave.
[0083] The construction of the sparse octree for complex enclosed caves involves extracting obstructing geometry data within the green box area of the scene. The geometric data from world space is then transformed into the corresponding pathfinding space using the aforementioned spatial transformation formula. The sparse octree representing this space is then partitioned to obtain the sparse octree data. Next, starting from the connected points outside the cave entrance / exit, a filling algorithm is used to traverse and fill the obstructing voxels. Finally, the entrance / exit data is stored in data structures representing the cave and the corresponding map tiles (Tile Cells), respectively. The entrance / exit data includes two 3D coordinate points in world space, representing the exit point and the entrance point, respectively. Further, the voxel encoding of the octree nodes in the pathfinding space is partitioned, which can be based on AABB bounding boxes and / or triangle data. Specifically, the sparse octree partitioning method is bottom-up. First, within the range represented by the sparse octree, all the smallest voxels intersecting with the input geometry are queried and input, and the voxel encoding set is obtained. For each encoding, check if the voxel represented by that encoding is already within a blocking voxel in the sparse octree. If it is not blocked, start from that encoding and recursively generate parent voxels upwards until an existing voxel node is reached. Then, remove the input encoding from the set of nodes representing the sparse octree, and traverse the parent nodes to mark the corresponding child nodes as blocked. During this process, when all child nodes of a parent node are marked as blocked, the marking process is recursively executed.
[0084] For triangular data, this invention implements an intersection algorithm between triangles and AABBs based on the separating axis theorem, calculating all the smallest voxels intersecting with triangles within the sparse octree representation. For AABB bounding box data, this invention utilizes an AABB bounding box intersection algorithm to calculate all the smallest voxels intersecting with the input AABB bounding boxes within the sparse octree representation.
[0085] After the above steps, all data can be saved to a file. The algorithm first saves the entire scene data to a single file with the extension .cellinfo. This file records the number of map tiles and the number of complex closed holes. For each map tile, it also saves the tile's extent in world space, scaling factor, connected point grouping data, and the entrance / exit data of closed holes within that tile. For each closed hole, it saves the extent marked by the user in world space, scaling factor, and corresponding entrance / exit data. The sparse octree data representing the pathfinding space for each map tile and complex hole is saved separately as a file with the extension .mp.
[0086] The sparse octree structure calculated in this embodiment stores map data upon which the pathfinding algorithm relies. Since the pathfinding algorithm doesn't need to focus on blocking node voxels in the structure, and storing these voxels consumes a significant amount of memory, the proposed solution removes blocking node voxels to save memory. To enable the querying of this blocking information, a bit is used on the parent node of the blocking node voxel to mark it as blocking. In practical applications, this can be integrated into a path planning game program. A dictionary can be used to store the sparse octree, where the key is the voxel's encoding, and the corresponding value represents the blocking status of that node's byte points for spatial pathfinding.
[0087] Furthermore, based on the agent's location in world space, it is determined whether to perform a loading or unloading operation of map tiles in the 3D scene to dynamically update the map tiles. In specific implementation, this may include the following steps 5-1 to 5-3:
[0088] Step 5-1: Pre-configure the loading and unloading distances for each map tile;
[0089] Step 5-2: Determine the target map tile where the agent is located based on the agent's position in world space;
[0090] Step 5-3: Based on the loading distance and unloading distance corresponding to the target map tile, determine whether to perform the loading or unloading operation of the map tile in the 3D scene in order to dynamically update the map tile.
[0091] Since the map is tiled, and further subdivided into cave areas, to avoid runtime memory overhead caused by loading all data simultaneously, the corresponding octree data can be loaded and unloaded based on the agent's location. In one implementation, the map tile update constraints include a load distance and an unload distance for each map tile, used to determine whether to unload the current map tile or load a new one. In practical applications, a load padding and an unload padding can be defined for each Tile Cell, where the unload distance can be set greater than the load distance. The agent is registered in the streaming loader, and based on the location of the registered agent, the following judgment is made:
[0092] (1) For all loaded Tile Cells, determine whether the Agent is outside the Unload Padding range and whether the Tile Cell is not locked. If the above conditions are met, unload the octree data of the Tile Cell;
[0093] (2) For the Tile Cells around the Agent, determine whether the Agent is within the Load Padding range. If it is, load the Tile Cell.
[0094] (3) For all loaded holes, determine whether the Agent is outside the bounding box of the hole and whether the Hole Cell is not locked. If the above conditions are met, unload the Hole Cell.
[0095] (4) For all holes, determine whether the Agent is inside the bounding box of the hole. If it is, load the Hole Cell.
[0096] In addition, to facilitate handling other special situations or emergency processing, an interface is provided that can force the loading and unloading of Cells.
[0097] Furthermore, performing pathfinding processing after updating the map tiles may include the following steps 6-1 and 6-2:
[0098] Step 6-1: Search for connecting paths between tiles in the higher-level tiles contained in the updated map tiles; wherein, the connecting paths are determined based on the connecting points of each connected surface.
[0099] Step 6-2: Perform pathfinding processing in the pathfinding block based on the connected path to determine the pathfinding path.
[0100] In one implementation, pathfinding can employ a hierarchical A* algorithm. First, the large map is divided into tiles. During pathfinding, connecting paths between tiles are searched at higher levels, and then pathfinding is performed within smaller tiles to obtain the final path. In the cell-level pathfinding algorithm, caves are treated as special areas. When the target point is determined to be inside a cave, the cell-level pathfinding direction expands towards the cave. In the game, the algorithm first calculates the cell-level pathfinding result each time it performs a pathfinding task. Then, the pathfinding task can be divided into multiple segments. When the agent moves to the next map tile, a new octree is used to calculate a new path. This amortizes the pathfinding across multiple frames. Furthermore, when the player intervenes, movement can be stopped, and the pathfinding task can be terminated.
[0101] In pathfinding algorithms, all data needs to be transformed into the pathfinding space, and after the result is calculated, it is transformed back into the world space.
[0102] The aforementioned Cell-level pathfinding algorithm considers both the large map tiles and the hole-representing tiles. To facilitate pathfinding in complex 3D spaces (such as areas including caves), this application's embodiments support the following three cases:
[0103] 1. Outside world->Inside the cave
[0104] 2. Inside the cave -> outside world
[0105] 3. Inside the cave -> outside world -> inside the cave
[0106] In one implementation, it is first determined whether the starting and ending points are inside the hole, obtaining the corresponding Cell (Tile Cell or Hole Cell). If the starting and ending points are in the same Cell, pathfinding is performed directly within that area. Otherwise, the Cell path is calculated. Then, the A* pathfinding algorithm is used to implement the Cell-level pathfinding process. First, it is determined whether the starting point is inside the hole; based on the determination result, an initial expansion is performed, and the OpenSet is initialized. Then, the A* pathfinding process is performed, and finally, the Cell-level pathfinding result (Cell Path) is output.
[0107] Based on the above method, after obtaining the connected paths at the Cell level, the starting point of the path can be determined, so the first path segment is calculated. Then, the character moves along the path. When the distance between the character's position and the cave's exit point is less than a certain threshold, the path from the exit point to the starting point of the next connected point is calculated. If the next target is a connected point on a door or the target endpoint, only one path needs to be calculated. If it is a connected component, there are many connected points on the connected component, so it is necessary to select a better path as the next new path segment. The path selection is not completed within one frame, but is calculated frame by frame, which reduces the time consumption of each frame. After selecting a new path segment and smoothing the path, it is returned to the application layer, which moves the character according to the path. This process is repeated until the target endpoint is reached.
[0108] In summary, the solution proposed in this application for addressing path planning in large-scale 3D scene spaces can quickly calculate the target path with minimal memory overhead. Based on the aforementioned octree voxel encoding scheme and the method for storing and representing octree voxels, the memory overhead in 3D spatial pathfinding can be reduced. This 3D spatial pathfinding scheme can quickly calculate the target path and supports spatial pathfinding in large-scale 3D scenes, while also meeting the path planning requirements of complex scenes. When integrated into a 3D game system, the path between the input start and end points can be quickly calculated with minimal memory overhead.
[0109] Based on the above method embodiments, this application also provides a pathfinding device in a three-dimensional scene space, see [link to relevant documentation]. Figure 9 As shown, the device mainly includes the following parts:
[0110] Encoding construction module 92 is used to construct octree node voxel encoding for each node voxel in the octree structure in the 3D scene; the octree node voxel encoding is used to represent the spatial position information of each node voxel in the pathfinding space.
[0111] The voxel partitioning module 94 is used to calculate the number of node voxels occupied by physical obstacles in the pathfinding space in the 3D scene, and to mark the occupied node voxels as obstacle voxels.
[0112] The pathfinding module 96 is used to determine whether to perform loading or unloading operations on map tiles in the 3D scene based on the relationship between the position of the agent in the world space and the map tile update constraints, so as to dynamically update the map tiles, and perform pathfinding processing based on the position of the blocking voxels in the updated map tiles; wherein, each map tile corresponds to an octree structure, and each octree structure has octree node voxel encoding for representing spatial location information.
[0113] The pathfinding device in the three-dimensional space of the scene provided in this application embodiment can determine the obstruction information and non-obstruction information in the three-dimensional scene by constructing node voxel encoding and determining the obstruction voxel based on the octree node voxel encoding. For large scenes with complex areas, the pathfinding path can be determined more accurately. Furthermore, by dynamically loading / unloading map tiles, only the map tiles used for pathfinding can be loaded during pathfinding, thus greatly reducing the memory consumption during the pathfinding process.
[0114] In one feasible implementation, the above-mentioned encoding construction module 92 is further configured to: obtain the bounding box information of each node voxel in the octree structure in the three-dimensional scene; calculate the node voxel coordinates of each node voxel based on the bounding box information of the node voxel; and construct the octree node voxel encoding corresponding to the node voxel in the octree structure based on the node voxel coordinates and node level of each node voxel.
[0115] In one feasible implementation, the three-dimensional scene includes a large-world scene;
[0116] The aforementioned voxel partitioning module 94 is also used for: pre-configuring the spatial range of the pathfinding space in the map tiles; calculating the number of map tiles contained in the world space based on the scaling factor of the pathfinding space relative to the world space corresponding to the 3D scene and the spatial range of the pathfinding space corresponding to each map tile; extracting collision geometry data in the world space and converting the collision geometry data to the pathfinding space corresponding to the map tile where the world space is located; partitioning the octree node voxel encoding of the pathfinding space to obtain the node voxels occupied by the collision geometry in the pathfinding space, and marking the occupied node voxels as blocking voxels.
[0117] In one feasible implementation, the above-mentioned apparatus further includes a connectivity point determination module, configured to: divide the octree node voxel encoding of the pathfinding space to obtain non-blocking voxels; cluster the interconnected regions in the top-level map tiles of the pathfinding space, and determine the connected region with the largest area on the top surface after clustering as the global connected region; generate connected regions on the connected surfaces between each map tile from top to bottom, starting from the global connected region; perform connectivity tests between the connected regions and the global connected regions, and merge the connected regions that pass the test into the set of global connected regions; delete the connected regions corresponding to the top-level map tiles, and determine the remaining connected regions in the set of global connected regions as the connected regions between each map tile; and calculate and generate the connectivity points of each connected surface based on the non-blocking voxels constituting each connected region.
[0118] In one feasible implementation, the three-dimensional scene also includes enclosed caves;
[0119] The aforementioned voxel partitioning module 94 is also used for: pre-marking the cave range, cave exit, and cave entrance of a closed cave; wherein both sides of the cave exit and cave entrance contain connected points; pre-marking the cave exit, cave entrance, and areas outside the cave range of the closed cave as blocked areas; extracting the blocking geometry data within the blocked areas and converting the blocking geometry data to the pathfinding space corresponding to the map tile where the world space is located; partitioning the octree node voxel encoding of the pathfinding space to obtain the node voxels occupied by the blocked areas in the pathfinding space, and marking the occupied node voxels as blocking voxels.
[0120] In one feasible implementation, the voxel partitioning module 94 is further configured to partition the octree node voxel encoding of the pathfinding space based on AABB bounding box and / or triangle data.
[0121] In one feasible implementation, the map tile update constraints include the loading distance and unloading distance corresponding to each map tile; the pathfinding module 96 is further configured to: pre-configure the loading distance and unloading distance corresponding to each map tile; determine the target map tile where the agent is located based on the agent's position in world space; and determine whether to perform loading or unloading operations on map tiles in the 3D scene based on the loading distance and unloading distance corresponding to the target map tile, so as to dynamically update the map tiles.
[0122] In one feasible implementation, the pathfinding module 96 is further configured to: search for connecting paths between blocks in the higher-level blocks contained in the updated map blocks; wherein the connecting paths are determined based on the connecting points of each connecting surface; and perform pathfinding processing in the pathfinding block based on the connecting paths to determine the pathfinding path.
[0123] The pathfinding device in the three-dimensional space of the scene provided in this application has the same implementation principle and technical effect as the aforementioned method embodiment. For the sake of brevity, any parts of the pathfinding device in the three-dimensional space of the scene not mentioned in the embodiment can be referred to the corresponding content in the aforementioned pathfinding method embodiment of the three-dimensional space of the scene.
[0124] This application also provides an electronic device, such as... Figure 10 The diagram shows the structure of the electronic device, which includes a processor 101 and a memory 100. The memory 100 stores computer-executable instructions that can be executed by the processor 101. The processor 101 executes the computer-executable instructions to implement the pathfinding method in three-dimensional space for any of the above-mentioned scenarios.
[0125] exist Figure 10 In the illustrated embodiment, the electronic device further includes a bus 102 and a communication interface 103, wherein the processor 101, the communication interface 103, and the memory 100 are connected via the bus 102.
[0126] The memory 100 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 103 (which can be wired or wireless), such as the Internet, wide area network, local area network, metropolitan area network, etc. The bus 102 may be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The bus 102 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 10 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0127] Processor 101 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 101 or by instructions in software form. Processor 101 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, or discrete hardware components. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in the memory. The processor 101 reads the information in the memory and, in conjunction with its hardware, completes the steps of the pathfinding method in the three-dimensional space of the scene described in the foregoing embodiment.
[0128] This application also provides a computer-readable storage medium storing computer-executable instructions. When these computer-executable instructions are called and executed by a processor, they cause the processor to implement the pathfinding method in the three-dimensional space of the above-mentioned scene. For specific implementation, please refer to the foregoing method embodiments, which will not be repeated here.
[0129] The computer program products of the pathfinding method, apparatus, electronic device and storage medium in the three-dimensional space of the scene provided in the embodiments of this application include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementation, please refer to the method embodiments, which will not be repeated here.
[0130] Unless otherwise specifically stated, the relative steps, numerical expressions, and values of the components and steps described in these embodiments do not limit the scope of this application.
[0131] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0132] In the description of this application, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, or the orientation or positional relationship commonly used when the product of the invention is in use. They are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application.
[0133] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A pathfinding method in a three-dimensional scene space, characterized in that, The method includes: For each node voxel in the octree structure in the 3D scene, an octree node voxel encoding is constructed; the octree node voxel encoding is constructed based on the node voxel coordinates and node level of the node voxel, and is used to characterize the spatial position information of each node voxel in the pathfinding space. Calculate the number of node voxels occupied by physical obstacles in the pathfinding space in the 3D scene, and mark the occupied node voxels as obstacle voxels; the calculation includes: based on the scaling factor of the pathfinding space relative to the world space, converting the collision geometry data in the world space to the corresponding pathfinding space, and dividing the octree node voxel encoding of the pathfinding space to determine the number of node voxels occupied by the physical obstacles, and marking the occupied node voxels as obstacle voxels. Based on the relationship between the agent's position in world space and the map tile update constraints, it is determined whether to perform a loading or unloading operation of map tiles in the 3D scene to dynamically update the map tiles, and to perform pathfinding processing based on the position of the blocking voxels in the updated map tiles; wherein, each map tile corresponds to an octree structure, and each octree structure has octree node voxel encoding for representing spatial location information.
2. The pathfinding method in a three-dimensional space according to claim 1, characterized in that, For each voxel node in the octree structure of a 3D scene, construct the octree node voxel encoding, including: For each voxel in the octree structure of a 3D scene, obtain the bounding box information of the voxel. Calculate the node voxel coordinates of each node voxel based on the bounding box information of the node voxels; For each node voxel, the node voxel coordinates and node level are used to construct the octree node voxel encoding corresponding to that node voxel in the octree structure.
3. The pathfinding method in a three-dimensional space according to claim 1, characterized in that, The three-dimensional scene includes a large-scale world scene; Calculate the number of node voxels occupied by physical obstacles in the 3D scene within the pathfinding space, and mark the occupied node voxels as obstacle voxels, including: Pre-configure the spatial range of the pathfinding space in map tiles; The number of map tiles contained in the world space is calculated based on the scaling factor of the pathfinding space relative to the world space corresponding to the 3D scene and the spatial range of the pathfinding space corresponding to each map tile. Extract the collision geometry data from the world space and convert the collision geometry data into the pathfinding space corresponding to the map tile where the world space is located; The octree node voxel encoding of the pathfinding space is divided to obtain the node voxels occupied by the collision geometry in the pathfinding space, and the occupied node voxels are marked as blocking voxels.
4. The pathfinding method in a three-dimensional space according to claim 3, characterized in that, The method further includes: The octree node voxel encoding of the pathfinding space is divided to obtain non-blocking voxels; Cluster the interconnected regions in the top map tiles of the wayfinding space, and determine the interconnected region with the largest area on the top surface after clustering as the global interconnected region. Starting from the global connected region and working downwards, a connected region is generated on the connected surface between each map tile; The connectivity of the connected regions is tested with the global connected regions, and the connected regions that pass the test are added to the set of global connected regions. Delete the connected regions corresponding to the top map tiles, and determine the remaining connected regions in the global connected region set as the connected regions between each map tile; Based on the non-blocking voxels that constitute each connected region, calculate and generate the connected points of each connected surface.
5. The pathfinding method in a three-dimensional space according to claim 3, characterized in that, The three-dimensional scene also includes enclosed caves; Calculate the number of node voxels occupied by physical obstacles in the 3D scene within the pathfinding space, and mark the occupied node voxels as obstacle voxels, including: The cave's boundaries, exit, and entrance are pre-marked; wherein, both sides of the cave exit and entrance contain connecting points; The cave exit, cave entrance, and areas outside the cave's enclosure are all marked as blocked areas in advance; Extract the obstruction geometry data within the obstruction area and convert the obstruction geometry data into the pathfinding space corresponding to the map tile where the world space is located; The octree node voxel encoding of the pathfinding space is divided to obtain the node voxels occupied by the blocking region in the pathfinding space, and the occupied node voxels are marked as blocking voxels.
6. The pathfinding method in a three-dimensional space according to claim 5, characterized in that, The octree node voxel encoding of the pathfinding space is divided, including: The octree node voxel encoding of the pathfinding space is divided based on AABB bounding box and / or triangle data.
7. The pathfinding method in a three-dimensional space according to claim 1, characterized in that, The map tile update constraints include the loading distance and unloading distance corresponding to each map tile; based on the relationship between the agent's position in world space and the map tile update constraints, it is determined whether to perform loading or unloading operations on map tiles in the 3D scene to dynamically update the map tiles, including: Pre-configure the loading and unloading distances for each map tile; Based on the agent's location in world space, determine the target map tile where the agent is located; Based on the loading and unloading distances corresponding to the target map tiles, determine whether to perform loading or unloading operations on map tiles in the 3D scene in order to dynamically update the map tiles.
8. The pathfinding method in a three-dimensional space according to claim 1, characterized in that, Pathfinding is performed based on the location of obstructing voxels in the updated map tiles, including: Search for connecting paths between tiles in the higher-level tiles contained in the updated map tiles; wherein the connecting paths are determined based on the connecting points of each connecting surface; Based on the connected path, pathfinding processing is performed in the pathfinding block to determine the pathfinding path.
9. A pathfinding device in a three-dimensional scene space, characterized in that, The device includes: The encoding construction module is used to construct octree node voxel encoding for each node voxel in the octree structure in the 3D scene; the octree node voxel encoding is constructed based on the node voxel coordinates and node level of the node voxel, and is used to characterize the spatial position information of each node voxel in the pathfinding space. The voxel partitioning module is used to calculate the number of voxels occupied by physical obstacles in the 3D scene in the pathfinding space, and to mark the occupied voxels as obstacle voxels. The calculation includes: based on the scaling factor of the pathfinding space relative to the world space, converting the collision geometry data in the world space to the corresponding pathfinding space, and partitioning the octree node voxel encoding of the pathfinding space to determine the number of voxels occupied by the physical obstacles, and marking the occupied voxels as obstacle voxels. The pathfinding module is used to determine whether to perform a loading or unloading operation of a map tile in the 3D scene based on the distance relationship between the location of the agent and the loading or unloading distance of the map tile, so as to dynamically update the map tile and perform pathfinding processing after the updated map tile; wherein, each map tile corresponds to an octree structure, and each octree structure has an octree node voxel encoding for representing spatial location information.
10. An electronic device, characterized in that, The method includes a processor and a memory, the memory storing computer-executable instructions that can be executed by the processor, the processor executing the computer-executable instructions to implement the pathfinding method in a three-dimensional space of a scene as described in any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the pathfinding method in the three-dimensional space of the scene as described in any one of claims 1 to 8.