A path generation method and device of a virtual scene, an electronic device, a computer readable storage medium and a computer program product
Patent Information
- Application Number
- CN202510479734.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-15
- Publication Date
- 2026-10-23
AI Technical Summary
然而,相关技术中的动态烘焙,通常会导致虚拟场景的路径生成效率较低
[0034]本申请实施例提供一种计算机可读存储介质,存储有计算机程序或计算机可执行指令,用于被处理器执行时实现本申请实施例提供的虚拟场景中的路径生成方法。
Smart Images

Figure CN122955201A_ABST
Abstract
Description
Technical Field
[0001] This application relates to computer technology, and more particularly to a method, apparatus, electronic device, computer-readable storage medium, and computer program product for generating paths in a virtual scene. Background Technology
[0002] Pathfinding systems in virtual environments plan the optimal path from start to finish for virtual objects, enabling them to move more efficiently within the virtual environment. Pathfinding systems require navigation mesh data for path planning. One related technology uses dynamic baking to generate navigation mesh data for the virtual environment in real time and store it in memory for later use. However, dynamic baking in this technology often results in low path generation efficiency for virtual environments. Summary of the Invention
[0003] This application provides a path generation method, apparatus, electronic device, computer-readable storage medium, and computer program product in a virtual scene, which can improve the efficiency of path planning in a virtual scene.
[0004] The technical solution of this application embodiment is implemented as follows:
[0005] This application provides a path generation method in a virtual scene, the method comprising:
[0006] In response to a path planning request for a first virtual object in a virtual scene, the path coverage area of the first virtual object is determined based on the path start point and path end point of the path planning request.
[0007] Determine the data maintenance area of the second virtual object in the virtual scene; wherein, the data maintenance area refers to the area where the navigation grid data of the spatial blocks needs to be maintained in the latest state;
[0008] Based on the path coverage area and the data maintenance area, a first data loading area is determined, and navigation grid data is generated for the spatial blocks in the first data loading area;
[0009] Based on the navigation grid data of the spatial blocks, a target path from the path start point to the path end point is determined for the first virtual object.
[0010] This application provides a path generation device in a virtual scene, including:
[0011] The first region module is used to respond to a path planning request for a first virtual object in a virtual scene and determine the path coverage area of the first virtual object based on the path start point and path end point of the path planning request.
[0012] The second region module is used to determine the data maintenance region of the second virtual object in the virtual scene; wherein, the data maintenance region refers to the region where the navigation grid data of the spatial blocks needs to be maintained in the latest state;
[0013] The data determination module is used to determine a first data loading area based on the path coverage area and the data maintenance area, and to generate navigation grid data for the spatial blocks in the first data loading area;
[0014] The path determination module is used to determine a target path from the path start point to the path end point for the first virtual object based on the navigation grid data of the spatial blocks.
[0015] In the above scheme, the data determination module is further configured to determine a first sub-region and a second sub-region from the first data loading region based on the second data loading region, wherein the second data loading region is a region where navigation mesh data generation has been completed with spatial segmentation; for the spatial segmentation in the second sub-region, the navigation mesh data is obtained from the storage space, and for the spatial segmentation in the first sub-region, the navigation mesh data is generated.
[0016] In the above scheme, the data determination module is further configured to determine the sub-region overlapping with the second data loading region in the first data loading region as the second sub-region; and to determine the sub-regions in the first data loading region other than the second sub-region as the first sub-region.
[0017] In the above scheme, the storage space includes: memory and disk; the data determination module is further configured to determine a first spatial block and a second spatial block from the spatial blocks of the second sub-region; obtain the navigation mesh data of the first spatial block from the offline mesh resource package of the virtual scene stored on the disk; and obtain the navigation mesh data of the second spatial block from the data cache space of the navigation mesh data in the memory.
[0018] In the above scheme, the data determination module is further configured to obtain from the disk a block list for recording that the navigation mesh data has been generated and stored offline; determine the spatial blocks in the second sub-region that match the block list as the first spatial block; and determine the spatial blocks in the second sub-region other than the first spatial block as the second spatial block.
[0019] In the above scheme, the virtual scene path generation device further includes: a data download module, used to download the offline grid resource package and the block list of the virtual scene, wherein the offline grid data package stores the navigation grid data of the spatial blocks in the virtual scene whose spatial complexity is higher than the complexity threshold, and the spatial complexity characterizes the complexity of the scene part located in the spatial block in the virtual scene; and writes the block list and the offline grid resource package to the disk.
[0020] In the above scheme, the data determination module is further configured to obtain the status markers of the spatial blocks in the first data loading area; determine the spatial blocks in the first data loading area whose status markers indicate that the generation of navigation mesh data has not been completed as the third spatial block, and determine the sub-regions generated by the third spatial block as the first sub-region; determine the spatial blocks in the first data loading area whose status markers indicate that the generation of navigation mesh data has been completed as the fourth spatial block, and determine the sub-regions generated by the fourth spatial block as the second sub-region.
[0021] In the above scheme, the data determination module is further configured to acquire geometric data for the spatial blocks in the first sub-region, wherein the geometric data records the physical structure of the passable area in each spatial block; convert the geometric data into voxel mesh data; extract passable surfaces from the voxel mesh data and generate polygonal outlines using the passable surfaces; and generate the navigation mesh data using the polygonal outlines.
[0022] In the above scheme, the path determination module is further configured to stitch together the navigation grid data of the spatial blocks into the navigation grid data of the first data loading area; and based on the navigation grid data of the first data loading area, determine the target path from the path starting point to the path ending point.
[0023] In the above scheme, the path determination module is further configured to determine the first mapping grid of the path starting point and the second mapping grid of the path ending point from the navigation grid data of the first data loading area; construct navigation map data through the connection relationship between the grids in the navigation grid data of the first data loading area; and determine the target path based on the first mapping grid, the second mapping grid and the navigation map data.
[0024] In the above scheme, the first area module is further used to obtain the location information of the second virtual object, and determine the data maintenance area of the second virtual object based on the location information of the second virtual object and a preset distance;
[0025] The second region module is further configured to determine the intersection of the path coverage area and the data maintenance area as the first data loading area.
[0026] In the above scheme, there are virtual obstacles in the first data loading area; the data determination module is further used to determine the spatial block where the virtual obstacle is located from the spatial blocks of the first data loading area; and to add an obstruction status mark to the navigation grid data of the spatial block where the virtual obstacle is located, wherein the obstruction status mark is a mark that indicates that the navigation grid data does not participate in the target path calculation.
[0027] In the above scheme, the data determination module is further configured to, in response to the second virtual object's clearing operation on the virtual obstacle, clear the virtual obstacle; and delete the obstruction status marker of the navigation grid data in the spatial block where the virtual obstacle is located.
[0028] In the above scheme, the virtual scene path generation device further includes: an obstacle generation module, used to generate the virtual obstacles in the first data loading area through an obstacle generation sub-thread.
[0029] In the above scheme, the path determination module is further configured to determine the target path from the path start point to the path end point for the first virtual object based on the navigation grid data of the spatial blocks through the path planning sub-thread.
[0030] In the above scheme, the data determination module is further configured to generate the navigation grid data for the spatial blocks in the first sub-region through a grid generation sub-thread.
[0031] This application provides an electronic device, the electronic device comprising:
[0032] Memory is used to store executable instructions or computer programs.
[0033] The processor, when executing computer-executable instructions or computer programs stored in the memory, implements the path generation method in the virtual scene provided in the embodiments of this application.
[0034] This application provides a computer-readable storage medium storing a computer program or computer-executable instructions for implementing the path generation method in a virtual scene provided in this application when executed by a processor.
[0035] This application provides a computer program product, including a computer program or computer executable instructions. When the computer program or computer executable instructions are executed by a processor, they implement the path generation method in the virtual scene provided in this application.
[0036] The embodiments of this application have the following beneficial effects: Based on the path start and path end points of the path planning request, the path coverage area of the first virtual object is determined. Then, by combining the path coverage area of the first virtual object and the data maintenance area of the second virtual object, a first data loading area for generating navigation mesh data is determined for the path planning request. Navigation mesh data is generated only for the spatial blocks in the first data loading area, while navigation mesh data is not generated for other spatial blocks, thereby reducing the redundancy of navigation mesh data. This achieves on-demand dynamic baking for the path planning request, reducing the amount of navigation mesh data that needs to be generated during path planning. In this way, not only can the time required to generate navigation mesh data before path calculation be reduced, but the memory consumption can also be reduced, increasing the available memory during path planning calculation, thereby improving the path generation efficiency of the virtual scene. Attached Figure Description
[0037] Figure 1 This is a schematic diagram of the path planning process in related technologies;
[0038] Figure 2 This is a schematic diagram of the architecture of the virtual scene path generation system provided in the embodiments of this application;
[0039] Figure 3 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application;
[0040] Figure 4 This is a flowchart illustrating the path generation method for a virtual scene provided in this application embodiment. Figure 1 ;
[0041] Figure 5 This is a flowchart illustrating the path generation method for a virtual scene provided in this application embodiment. Figure 2 ;
[0042] Figure 6 This is a flowchart illustrating the path generation method for a virtual scene provided in this application embodiment. Figure 3 ;
[0043] Figure 7 This is a flowchart illustrating the path generation method for a virtual scene provided in this application embodiment. Figure 4 ;
[0044] Figure 8 This is a flowchart illustrating the path generation method for a virtual scene provided in this application embodiment. Figure 5 ;
[0045] Figure 9 This is a schematic diagram illustrating the path planning process for an intelligent agent (NPC) provided in an embodiment of this application.
[0046] Figure 10 This is a schematic diagram of the baking range provided in the embodiments of this application. Figure 1 ;
[0047] Figure 11 This is a schematic diagram of the baking range provided in the embodiments of this application. Figure 2 ;
[0048] Figure 12 This is a schematic diagram of the baking range provided in the embodiments of this application;
[0049] Figure 13 This is a schematic diagram of dynamic obstacle adaptation provided in an embodiment of this application;
[0050] Figure 14 This is a schematic diagram of the baking results provided in the embodiments of this application;
[0051] Figure 15 This is a schematic diagram of the sub-thread processing provided in the embodiment itself. Detailed Implementation
[0052] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0053] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0054] In the following description, the terms "first, second, third, fourth" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, third, fourth" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0055] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0056] Unless otherwise defined, all technical and scientific terms used in the embodiments of this application have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used in the embodiments of this application is for the purpose of describing the embodiments of this application only and is not intended to limit this application.
[0057] In the implementation of this application, the collection and processing of relevant data should strictly comply with the requirements of relevant laws and regulations, obtain the informed consent or separate consent of the personal information subject, and carry out subsequent data use and processing within the scope of laws and regulations and the authorization of the personal information subject.
[0058] Before providing a further detailed description of the embodiments of this application, the nouns and terms involved in the embodiments of this application will be explained, and the nouns and terms involved in the embodiments of this application shall be interpreted as follows.
[0059] 1) A virtual scene refers to a scene used to provide virtual activities for virtual objects, such as a game scene, a simulation scene, an animation scene, etc. This virtual scene can be a simulation environment of the real world, a semi-simulated / semi-fictional virtual environment, or a purely fictional virtual environment. A virtual scene can be any of a two-dimensional, 2.5-dimensional, or three-dimensional virtual scene; this application does not limit the dimension of the virtual scene. For example, a virtual scene may include the sky, land, ocean, etc., and the land may include environmental elements such as deserts and cities. Virtual objects can be controlled to perform virtual activities within this virtual scene.
[0060] 2) Virtual objects refer to the images of various people and things that can be interacted with in a virtual scene, or movable objects in a virtual scene, or objects that can be interacted with in a virtual scene. These movable objects can be virtual characters, virtual animals, anime characters, and virtual props, such as people and animals displayed in a virtual scene; a virtual object can also be a virtual character representing the user in a virtual scene. A virtual scene can include multiple virtual objects, each with its own shape and volume, occupying a portion of the space in the virtual scene. In the embodiments of this application, different virtual objects can be distinguished by using terms such as "first virtual object" and "second virtual object."
[0061] 3) Navmesh data is a set of convex polygons obtained by dividing the movable area of a virtual object in a virtual scene. These convex polygons are interconnected, and each polygon represents a passable navigation unit. The movable area of a virtual object in a virtual scene can refer to areas such as the ground or platforms.
[0062] 4) Baking refers to the process of generating and storing dynamic or complex real-time data, such as lighting, physical collision, and navigation mesh data, as static data in advance.
[0063] 5) The data loading area refers to the region in the virtual scene where navigation mesh data needs to be generated and stored in advance. Therefore, the data loading area limits the scope of navigation mesh data generation in advance; navigation mesh data in other areas outside this area will not be generated and stored in advance. In this embodiment, the data loading area can be a specific region, such as a room in the virtual scene.
[0064] 6) Spatial segmentation is the process of dividing a virtual scene into smaller regions or blocks. Each spatial segment can be baked as a separate unit.
[0065] 7) Voxel mesh data is a discrete data structure used to represent the three-dimensional space of a virtual scene. Voxel mesh data includes a large number of voxels, each voxel representing a point in three-dimensional space. It can store information related to that point, such as color, material, physical properties, etc.
[0066] 8) In response to, used to indicate the conditions or states on which the operation performed depends. When the conditions or states on which it depends are met, one or more operations performed may be performed in real time or with a set delay. Unless otherwise specified, there is no restriction on the order in which the multiple operations are performed.
[0067] A pathfinding system in a virtual environment plans the optimal path from a starting point to a destination for virtual objects, enabling them to move more efficiently within the virtual environment. The pathfinding system needs to incorporate navigation mesh data for path planning; this data can be generated through baking for use by the pathfinding system.
[0068] In related technologies, navigation grid data can be baked offline for use by pathfinding systems. Offline baking refers to pre-generating and storing navigation grid data during the development process. For example, Figure 1 This is a schematic diagram of the path planning process in related technologies, from Figure 1 As can be seen, during the development phase, the navigation mesh data is stored on disk 1-1 through offline baking. Then, the pathfinding system in the virtual scene loads the offline baked navigation mesh data 1-2 from the disk at runtime, and then uses the navigation mesh data to calculate the optimal path 1-3.
[0069] However, once generated, offline baked navigation grid data is difficult to adapt to real-time changes in the virtual scene. For example, when virtual obstacles in the virtual scene are destroyed or the layout of the virtual scene changes, the original navigation grid data will become invalid, resulting in low accuracy of path planning.
[0070] In response to this, related technologies can also use dynamic baking to generate navigation mesh data for virtual scenes in real time and store it in memory. However, dynamic baking in these technologies typically generates navigation mesh data for a large number of spatial blocks, such as generating navigation mesh data for all spatial blocks of the virtual scene, or generating navigation mesh data for a certain range around the user's virtual object. However, not all of this navigation mesh data is necessarily needed for path planning calculations, so there may be redundancy in the dynamically baked navigation mesh data. As a result, not only is dynamic baking required to complete before path calculation, but it also consumes a lot of memory for storage, reducing the memory available for path calculation and ultimately leading to low path generation efficiency in the virtual scene.
[0071] This application provides a method, apparatus, electronic device, computer-readable storage medium, and computer program product for generating paths in virtual scenes, which can improve the efficiency of path planning in virtual scenes. The following describes exemplary applications of the electronic device provided in this application. The electronic device provided in this application can be implemented as various types of terminals such as laptops, tablets, desktop computers, smartphones, smartwatches, smart TVs, and in-vehicle terminals, or it can be implemented as a server. The following will describe exemplary applications when the electronic device is implemented as a server.
[0072] See Figure 2 , Figure 2 This is a schematic diagram of the architecture of a virtual scene path generation system provided in this application embodiment. To support a path generation application for a virtual scene, in the virtual scene path generation system 100, a terminal 400 (terminals 400-1 and 400-2 are shown as examples) connects to a server 200 via a network 300. The network 300 can be a wide area network (WAN), a local area network (LAN), or a combination of both. The virtual scene path generation system 100 also includes a database 500 for providing data support to the server 200. The database 500 can be independent of the server 200 or it can be located within the server 200. Figure 2 This illustrates the scenario where database 500 is independent of server 200.
[0073] This application embodiment can be implemented collaboratively by a server and a terminal. For example, the terminal 400 sends a path planning request for a virtual object in a virtual scene to the server 200. The server 200 obtains the path start and path end of the path planning request, generates a target path using the virtual scene path generation method in this application embodiment, and sends the target path to the terminal 400. The terminal 400 controls the virtual objects in the virtual scene displayed by the graphical interface (graphical interfaces 400-11 and 400-21 are shown as examples) to move according to the target path.
[0074] The virtual scene path generation method provided in this application can be applied to various scenarios that require generating paths for virtual objects in a virtual scene, such as the activity path generation scenario for non-player characters (NPCs) in the game field, and the user exploration path generation scenario in the virtual reality field. The following describes the scenarios in which the virtual scene path generation method provided in this application can be applied.
[0075] 1) NPC activity path generation scenario: For example, the terminal sends a path planning request carrying the start and end points of the NPC's activity path to the server. The server generates the best activity path for the NPC according to the path generation method of the virtual scene provided in the embodiments of this application, and sends the activity path to the terminal so that the terminal can control the virtual object to move from the start point to the end point according to the target path.
[0076] 2) User exploration path generation scenario: For example, the terminal sends a path planning request carrying the start and end points of the exploration path to the server. The server generates the best exploration path for the user based on the virtual scene path generation method provided in the embodiments of this application, and sends the exploration path to the terminal so that the user can experience virtual reality according to the exploration path.
[0077] In some embodiments, server 200 may be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. Terminals and servers can be connected directly or indirectly via wired or wireless communication, which is not limited in this embodiment.
[0078] See Figure 3 , Figure 3 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Figure 3 The illustrated electronic device 600 includes at least one processor 610, a memory 650, at least one network interface 620, and a user interface 630. The various components in the electronic device 600 are coupled together via a bus system 640. It is understood that the bus system 640 is used to implement communication between these components. In addition to a data bus, the bus system 640 also includes a power bus, a control bus, and a status signal bus. However, for clarity, ... Figure 3 The general labeled all buses as Bus System 640.
[0079] The processor 610 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.
[0080] User interface 630 includes one or more output devices 631 that enable the presentation of media content, including one or more speakers and / or one or more visual displays. User interface 630 also includes one or more input devices 632, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0081] The memory 650 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state storage, hard disk drives, optical disk drives, etc. The memory 650 may optionally include one or more storage devices physically located away from the processor 610.
[0082] The memory 650 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), and the volatile memory may be random access memory (RAM). The memory 650 described in this application embodiment is intended to include any suitable type of memory.
[0083] In some embodiments, memory 650 is capable of storing data to support various operations, examples of which include programs, modules, and data structures or subsets or supersets thereof, as illustrated below.
[0084] Operating system 651 includes system programs for handling various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, driver layer, etc., for implementing various basic business functions and handling hardware-based tasks;
[0085] The network communication module 652 is used to reach other electronic devices via one or more (wired or wireless) network interfaces 620, exemplary network interfaces 620 including: Bluetooth, WiFi, and Universal Serial Bus (USB), etc.
[0086] Presentation module 653 is configured to enable the presentation of information (e.g., a user interface for operating peripheral devices and displaying content and information) via one or more output devices 631 (e.g., a display screen, a speaker, etc.) associated with user interface 630;
[0087] The input processing module 654 is used to detect and translate one or more user inputs or interactions from one or more input devices 632.
[0088] In some embodiments, the virtual scene path generation device provided in this application can be implemented in software. Figure 3 A path generation device 655 for a virtual scene stored in memory 650 is shown. This device can be software in the form of programs or plugins, and includes the following software modules: a first region module 6551, a second region module 6552, a data determination module 6553, a path determination module 6554, a data download module 6555, and an obstacle generation module 6556. These modules are logically connected and can therefore be arbitrarily combined or further separated according to their implemented functions. The functions of each module will be described below.
[0089] In other embodiments, the virtual scene path generation device provided in this application can be implemented in hardware. As an example, the virtual scene path generation device provided in this application can be a processor in the form of a hardware decoding processor, which is programmed to execute the virtual scene path generation method provided in this application. For example, the processor in the form of a hardware decoding processor can be one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), or other electronic components.
[0090] In some embodiments, an electronic device can implement the virtual scene path generation method provided in this application embodiment by running various computer-executable instructions or computer programs. For example, computer-executable instructions can be microprogram-level commands, machine instructions, or software instructions. Computer programs can be native programs or software modules in an operating system; they can be native applications (APPs), i.e., programs that need to be installed in the operating system to run, such as game APPs; or they can be applets that can be embedded in any APP, i.e., programs that only need to be downloaded to a browser environment to run. In summary, the aforementioned computer-executable instructions can be any form of instruction, and the aforementioned computer programs can be any form of application, module, or plugin.
[0091] The following will describe the virtual scene path generation method provided in this application embodiment, with reference to exemplary applications and implementations of the electronic device provided in this application embodiment. As mentioned above, the electronic device implementing the virtual scene path generation method of this application embodiment can be a terminal, a server, or a combination of both. Therefore, the executing entity of each step will not be described again below.
[0092] See Figure 4 , Figure 4 This is a flowchart illustrating the path generation method for a virtual scene provided in this application embodiment. Figure 1 , will combine Figure 4 The steps shown are explained below. Figure 4 The main component of the process is electronic equipment.
[0093] Step 101: In response to the path planning request for the first virtual object in the virtual scene, determine the path coverage area of the first virtual object based on the path start point and path end point of the path planning request.
[0094] When an electronic device receives a path planning request for the first virtual object in a virtual scene, it determines that a path needs to be generated for the first virtual object in the virtual scene. At this time, the electronic device first parses the path planning request to determine the path start and path end of the first virtual object. Then, it determines a rectangular area based on the path start and path end, and defines this rectangular area as the path coverage area of the first virtual object.
[0095] It should be noted that the first virtual object refers to any movable virtual object in the virtual scene other than the virtual object representing the user. Examples include non-player characters (NPCs), virtual monsters, or movable virtual structures. The first virtual object can be controlled by an artificial intelligence agent, which is an AI entity capable of making autonomous decisions and acting within the virtual scene. This allows the first virtual object to act autonomously within the virtual scene, such as moving randomly or actively interacting with other virtual objects (which can be user-controlled virtual objects or other NPCs).
[0096] In this embodiment, the path planning request can be generated automatically by the electronic device based on the preset behavior rules of the first virtual object. For example, when the electronic device checks the preset behavior rules of the first virtual object and determines that the first virtual object needs to start patrolling in the virtual scene, it will generate a path planning request for the first virtual object. The path planning request can also be generated by an intelligent agent. For example, when the intelligent agent determines that the first virtual object needs to move based on the interaction between the first virtual object and other virtual objects in the virtual scene, it will generate a path planning request.
[0097] It should be noted that electronic devices can determine a minimum rectangular area by taking the coordinates of the starting point and ending point of the path, and then directly define this rectangular area as the path coverage area, or expand the rectangular area outward and define the expanded rectangular area as the path coverage area.
[0098] Step 102: Determine the data maintenance area of the second virtual object in the virtual scene.
[0099] The second virtual object in the virtual scene refers to a user-controlled virtual object, that is, a virtual object representing the user in the virtual scene. The user can control the second virtual object to move within the virtual scene and interact with the first virtual object in the virtual scene. In this embodiment, the electronic device needs to first determine the data maintenance area for the second virtual object. The data maintenance area refers to the area where the navigation grid data of the spatial blocks needs to be maintained in the latest state. In other words, the data maintenance area is the dynamic baking range of the second virtual object. This range extends outward from the second virtual object by a certain distance, such as 100 meters. Only scene changes occurring within this range will cause dynamic baking of the navigation grid data, while scene changes occurring outside this range will not cause dynamic baking of the navigation grid data. In this way, the electronic device can maintain only the navigation grid data of the spatial blocks near the second virtual object, rather than maintaining the navigation grid data of all spatial blocks in the entire virtual scene, thereby saving memory resources and responding promptly to dynamic changes near the second virtual object.
[0100] In the embodiments of this application, Figure 4 Step 102, namely determining the data maintenance area of the second virtual object in the virtual scene, can be achieved through the following process: obtaining the location information of the second virtual object, and determining the data maintenance area of the second virtual object based on the location information of the second virtual object and a preset distance.
[0101] The electronic device first obtains the position information of the second virtual object in the virtual scene and obtains the preset distance. Then, it determines the data maintenance area of the second virtual object as a square area centered on the position of the second virtual object and with the preset distance as the side length. Alternatively, it can determine the data maintenance area of the second virtual object as a circular area centered on the position of the second virtual object and with the preset distance as the radius.
[0102] It should be noted that in the embodiments of this application, steps 101 and 102 can also be executed in a different order than the above order. That is, the electronic device can execute step 102 first and then execute step 101, or the electronic device can execute steps 101 and 102 simultaneously. The embodiments of this application do not limit this.
[0103] Step 103: Determine the first data loading area based on the path coverage area and the data maintenance area.
[0104] After obtaining the path coverage area of the first virtual object and the data maintenance area of the second virtual object, the electronic device will combine these two areas to determine the first data loading area that needs to be extracted, generated and stored for navigation mesh data, which is also the area where dynamic baking of navigation mesh data is actually needed.
[0105] It should be noted that, since the data maintenance area defines the range within which navigation grid data can be rebaked when the virtual scene undergoes dynamic changes, and the path coverage area defines the area where path search needs to be performed for the first virtual object during path planning, the electronic device needs to combine the data maintenance area to determine whether each spatial block in the area where path search needs to be performed needs to be dynamically baked at the current time. In other words, whether the path coverage area needs to be dynamically baked depends on whether it is within the baking range of the second virtual object, that is, the virtual object controlled by the user.
[0106] In some embodiments of this application, Figure 4 Step 103, namely determining the first data loading area based on the path coverage area and the data maintenance area, can be achieved by the following process: determining the intersection of the path coverage area and the data maintenance area as the first data loading area.
[0107] The electronic device can find the intersection of the path coverage area and the data maintenance area, and then directly determine the intersection area as the first data loading area. As a result, the electronic device will only generate navigation grid data for the spatial blocks in the intersection of the path coverage area and the data maintenance area, and perform path search based on the navigation grid data of these spatial blocks.
[0108] In other embodiments of this application, Figure 4 Step 103, namely determining the first data loading area based on the path coverage area and the data maintenance area, can also be achieved through the following process: determining whether the path coverage area is completely within the data maintenance area. If the path coverage area is completely within the data maintenance area, the path coverage area is taken as the first data loading area.
[0109] In other words, the electronic device will only determine the path coverage area as the first data loading area for dynamic baking of navigation mesh data when each spatial block in the path coverage area is within the data maintenance area, so that navigation mesh data can be generated and stored for all spatial blocks of the entire path coverage area.
[0110] Step 104: Generate navigation grid data for the spatial blocks in the first data loading area.
[0111] It should be noted that, to facilitate data processing of virtual scenes, the virtual scene is typically segmented during the development phase to obtain a large number of spatial blocks. Therefore, these spatial blocks can be considered predefined. In this embodiment, the electronic device first determines the spatial blocks within the first data loading area, then generates and stores navigation mesh data only for these spatial blocks. The first data loading area is the range determined by the path planning request and dynamically baked according to the current actual needs. Therefore, generating navigation mesh data only for these spatial blocks achieves the effect of dynamic baking according to the needs of the path planning request, i.e., on-demand baking.
[0112] In some embodiments of this application, Figure 4 Step 104, which is to generate navigation mesh data for the spatial blocks in the first data loading area, can be achieved through the following processing: acquiring geometric data for the spatial blocks in the first data loading area; converting the geometric data into voxel mesh data; extracting passable surfaces from the voxel mesh data and generating polygonal contours using the passable surfaces; and generating navigation mesh data using the polygonal contours.
[0113] Among them, geometric data records the physical structure of passable areas in each spatial block, such as virtual ground and virtual obstacles in a virtual scene.
[0114] The electronic device can traverse all spatial blocks in the first data loading area, accessing the storage space for each spatial block to store its geometric data, thereby obtaining the geometric data for each spatial block. Then, the electronic device determines a 3D shape based on the geometric data of all spatial blocks, discretizes this 3D shape into uniform voxel mesh data, and determines whether each voxel in the voxel mesh data is passable through collision detection or visibility judgment, assigning label information, such as Boolean values or weights, to each voxel to indicate its passability, cost of passage, and other attributes. Next, the electronic device can cluster adjacent passable voxels in the voxel mesh data based on this label information to obtain connected regions. Then, using a contour generation algorithm, the voxels in the connected regions are converted into polygonal contours, which are then segmented into triangular or polygonal facets. The mesh data composed of these facets falling into each spatial block is used as navigation mesh data, or further operations such as removing redundant vertices and optimizing mesh density are performed on the mesh data composed of triangular or polygonal facets to obtain navigation mesh data.
[0115] It should be noted that, since the virtual scene changes dynamically, each dynamic change involves dynamic baking of a portion of the virtual scene. Therefore, there may be areas in the virtual scene where navigation mesh data has already been dynamically baked, i.e., areas where spatial block navigation mesh data has already been generated. These areas can be referred to as the second data loading area. Therefore, in this embodiment, the electronic device can not only directly generate navigation mesh data for all spatial blocks in the first data loading area, but also, in conjunction with the second data loading area, determine whether there are spatial blocks in the first data loading area that have already had navigation mesh data generated, i.e., have been baked. Then, when generating navigation mesh data for spatial blocks in the first data loading area, the existing baked navigation mesh data for spatial blocks can be reused directly, thereby reducing the number of spatial blocks for which navigation mesh data needs to be generated and further improving the efficiency of path planning.
[0116] Therefore, see Figure 5 , Figure 5 This is a flowchart illustrating the path generation method for a virtual scene provided in this application embodiment. Figure 2 In some embodiments of this application, Figure 4 Step 104, which involves generating navigation mesh data for spatial blocks within the first data loading area, can also be achieved through the following processing:
[0117] Step 1041: Based on the second data loading area, determine the first sub-region and the second sub-region from the first data loading area.
[0118] It should be noted that the second data loading area is the area where the navigation mesh data has been generated after spatial segmentation. Therefore, based on the second data loading area, the electronic device can divide the first data loading area into a first sub-area and a second sub-area. The first sub-area includes the spatial segments that need to generate navigation mesh data, while the second sub-area includes the spatial segments that have already generated navigation mesh data. That is, the spatial segments in the second sub-area have already completed the baking of navigation mesh data and can be directly reused.
[0119] In some embodiments of this application, Figure 5 Step 1041, namely, determining the first sub-region and the second sub-region from the first data loading region based on the second data loading region, can be achieved through the following processing: determining the sub-region in the first data loading region that overlaps with the second data loading region as the second sub-region; and determining the sub-region in the first data loading region other than the second sub-region as the first sub-region.
[0120] In this embodiment of the application, the electronic device can find the intersection of the first data loading area and the second data loading area, that is, the overlapping sub-region, and take the sub-region as the second sub-region, that is, the sub-region formed by the spatial blocks that have completed the generation of navigation grid data. Then, the complement of the second sub-region in the first data loading area, that is, the remaining sub-region excluding the second sub-region, is taken as the sub-region formed by the spatial blocks that need to generate navigation grid data.
[0121] Understandably, in this way, electronic devices can combine the existing second data loading area to quickly divide the first data loading area into two different sub-areas, thereby further improving the efficiency of path planning.
[0122] In other embodiments of this application, Figure 5 Step 1041, which is to determine the first sub-region and the second sub-region from the first data loading region based on the second data loading region, can also be implemented through the following processing: obtaining the status markers of the spatial blocks in the first data loading region; determining the spatial blocks in the first data loading region whose status markers indicate that the generation of navigation mesh data has not been completed as the third spatial block, and determining the sub-region generated by the third spatial block as the first sub-region; determining the spatial blocks in the first data loading region whose status markers indicate that the generation of navigation mesh data has been completed as the fourth spatial block, and determining the sub-region generated by the fourth spatial block as the second sub-region.
[0123] In other words, the electronic device divides multiple spatial blocks in the first data loading area into two categories based on the status markers of the spatial blocks: one category is the third spatial block where navigation mesh data generation is incomplete, and the other category is the fourth spatial block where navigation mesh data generation is complete. The sub-region formed by the third spatial block is then designated as the first sub-region, and the sub-region formed by the fourth spatial block is designated as the second sub-region. In this way, the electronic device can also complete the division of the first and second sub-regions. The status markers of the spatial blocks can be updated by the electronic device during each dynamic baking process. The initial status markers of the spatial blocks can be generated by the electronic device when loading the virtual scene or when a set time is reached.
[0124] It is understood that in this embodiment of the application, the electronic device can divide the first data loading area into a first sub-region and a second sub-region simply by reading the marking status of the spatial blocks of the first data loading area itself. In this way, the electronic device does not need to obtain the second data loading area for division, making the division of the first sub-region and the second sub-region simpler and easier.
[0125] Step 1042: For the spatial blocks in the second sub-region, retrieve navigation grid data from the storage space.
[0126] Since the navigation grid data of the spatial blocks in the second sub-region has been generated, the electronic device can directly obtain the navigation grid data of these spatial blocks from the storage space to reuse the already baked navigation grid data. At the same time, the electronic device will generate navigation grid data for the spatial blocks in the first sub-region and store it in memory, so that each spatial block in the first data loading area has its own navigation grid data.
[0127] It should be noted that the storage space can include memory or disk. That is, the navigation grid data of the spatial blocks of the second sub-region can be stored in memory or on disk. Therefore, when the electronic device obtains the navigation grid data, it needs to determine the specific storage location of the navigation grid data before it can obtain it.
[0128] See Figure 6 , Figure 6 This is a flowchart illustrating the path generation method for a virtual scene provided in this application embodiment. Figure 3 In some embodiments of this application, Figure 5 Step 1042, which involves retrieving navigation mesh data from storage space for spatial partitioning in the second sub-region, can be achieved through the following processing:
[0129] Step 10421: Determine the first spatial block and the second spatial block from the spatial blocks of the second sub-region.
[0130] In this embodiment of the application, the electronic device first divides the multiple spatial blocks contained in the second sub-region into a first spatial block and a second spatial block. The first spatial block refers to the spatial block in which the navigation mesh data is stored on the disk, and the second spatial block refers to the spatial block in which the navigation mesh data is stored in memory.
[0131] It should be noted that the first spatial block can be any spatial block within the second sub-region, or it can be a spatial block within the second sub-region with a spatial complexity greater than or equal to a complexity threshold; the second spatial block can be any spatial block within the second sub-region, or it can be a spatial block within the second sub-region with a spatial complexity less than a complexity threshold. The spatial complexity of a spatial block characterizes the complexity of the scene portion located within the spatial block in the virtual scene, such as the polygon density of passable areas and the number of virtual obstacles.
[0132] In some embodiments of this application, Figure 6Step 10421, namely determining the first spatial block and the second spatial block from the spatial blocks of the second sub-region, can be achieved through the following process: obtaining from the disk a block list of spatial blocks used to record navigation mesh data that has been generated and stored offline; identifying the spatial blocks in the second sub-region that match the block list as the first spatial block; and identifying the spatial blocks in the second sub-region other than the first spatial block as the second spatial block.
[0133] The electronic device first retrieves and stores the navigation mesh data from the disk. This data is generated offline; that is, the navigation mesh data is a list of spatial blocks baked offline. Each spatial block in the list has already had its navigation mesh data baked during the virtual scene development phase. Next, the electronic device iterates through each spatial block in the second sub-region, determining whether it matches the block list. Spatial blocks that match the list are designated as first spatial blocks, while those that don't are designated as second spatial blocks. In this way, the electronic device can distinguish which spatial blocks in the second sub-region need to retrieve their navigation mesh data from memory.
[0134] It is understood that, in this embodiment of the application, the electronic device can quickly determine the storage location of the navigation grid data of each spatial block in the second sub-region through the block list already stored on the disk, so that the data can be directly obtained in the future without having to query the storage location of the navigation grid data for each spatial block, so that the electronic device can obtain the navigation grid data faster.
[0135] Step 10422: Obtain the navigation grid data of the first spatial block from the offline grid resource package of the virtual scene stored on the disk.
[0136] After identifying the first spatial block, the electronic device locates and retrieves the navigation mesh data for that block from the offline mesh resource package of the virtual scene stored on the disk. The offline mesh resource package, generated during the virtual scene's development phase, stores the navigation mesh data pre-generated and stored by the virtual scene's developers for each spatial block. This offline mesh resource package, along with other files required during the virtual scene's implementation, is packaged into the virtual scene's installation package.
[0137] Step 10423: Obtain the navigation grid data of the second spatial block from the data cache space of the navigation grid data in memory.
[0138] For spatial blocks in the second sub-region where the corresponding navigation grid data is not stored on the disk, the navigation grid data will be dynamically generated by the electronic device at an earlier time and cached in memory to store this navigation grid data. Therefore, the electronic device can directly locate and retrieve the navigation grid data of the second spatial block from memory or from the data cache space used to store the generated navigation grid data.
[0139] It is understood that, in the embodiments of this application, the electronic device can first determine the spatial blocks from the first data loading area that have completed the generation of navigation mesh data, and directly obtain the navigation mesh data of these spatial blocks for reuse, thereby further reducing the number of spatial blocks that need to dynamically generate navigation mesh data in real time; and during reuse, it can achieve mixed reuse of dynamically generated navigation mesh data and pre-generated offline navigation mesh data, thereby making the reuse of navigation mesh data more flexible.
[0140] Step 1043: Generate navigation grid data for the spatial blocks in the first sub-region.
[0141] The electronic device dynamically generates navigation grid data for each spatial block in the first sub-region to obtain the latest navigation grid data for the spatial blocks in the first sub-region.
[0142] In some embodiments of this application, Figure 5 Step 1043, which is to generate navigation mesh data for the spatial blocks in the first sub-region, can be achieved through the following processing: for the spatial blocks in the first sub-region, obtain geometric data, wherein the geometric data records the physical structure of the passable area in each spatial block; convert the geometric data into voxel mesh data; extract the passable surface from the voxel mesh data, and generate polygonal contours using the passable surfaces; and generate navigation mesh data using the polygonal contours.
[0143] It should be noted that the above implementation process is quite similar to the specific process of generating navigation mesh data for spatial blocks in the first data loading area, and will not be repeated here.
[0144] It is understood that in this embodiment of the application, the electronic device will first divide the first data loading area into a first sub-area that actually needs to generate navigation mesh data, and a second sub-area that can directly reuse the already generated navigation mesh data, thereby reducing the number of spatial blocks that need to generate navigation mesh data, so that the navigation mesh data of each spatial block in the first data loading area can be obtained quickly, which helps to improve the efficiency of path generation.
[0145] Step 105: Based on the spatially segmented navigation grid data, determine the target path from the path start point to the path end point for the first virtual object.
[0146] After obtaining the navigation grid data of all spatial blocks in the first data loading area, the electronic device will search for a path for the first virtual object based on the navigation grid data of these spatial blocks. This path is the target path.
[0147] See Figure 7 , Figure 7 This is a flowchart illustrating the path generation method for a virtual scene provided in this application embodiment. Figure 4 In some embodiments of this application, Figure 4 Step 105, which involves determining the target path from the path start point to the path end point for the first virtual object based on the spatially segmented navigation mesh data, can be achieved through the following processing:
[0148] Step 1051: Combine the spatially segmented navigation grid data into the navigation grid data of the first data loading area.
[0149] The electronic device uses vertex alignment and adjacency indexing to stitch together the various spatial blocks in the first data loading area, thereby obtaining a seamless navigation mesh data, which is the navigation mesh data of the first data loading area. Vertex alignment means that the boundary vertex coordinates of adjacent spatial blocks are strictly consistent, while adjacency indexing means that each spatial block stores the index of its adjacent spatial blocks, such as the spatial block identifier or memory pointer. Thus, through vertex alignment and adjacency indexing, the stitching of different spatial blocks can be achieved.
[0150] Step 1052: Based on the navigation grid data of the first data loading area, determine the target path from the path start point to the path end point.
[0151] Based on the navigation grid data in the first data loading area, the electronic device generates a path for the path start and end points, thereby obtaining the target path.
[0152] In the embodiments of this application, Figure 7 Step 1052, namely determining the target path from the path start point to the path end point based on the navigation grid data of the first data loading area, can be achieved through the following processing: determining the first mapping grid of the path start point and the second mapping grid of the path end point from the navigation grid data of the first data loading area; constructing navigation map data through the connection relationship between the grids in the navigation grid data of the first data loading area; and determining the target path based on the first mapping grid, the second mapping grid, and the navigation map data.
[0153] The electronic device maps the starting point of the path to the navigation grid data in the first data loading area to obtain the first mapped grid, and simultaneously maps the ending point of the path to the navigation grid data in the first data loading area to obtain the second mapped grid. At the same time, the electronic device uses each grid in the navigation grid data in the first data loading area as a graph node, records the adjacency relationships between the grids as edges, and calculates the Euclidean distance between the center of each grid and the centers of its adjacent grids. This Euclidean distance is used as the weight of the edges in the navigation graph data. In this way, an image data structure can be constructed, which is the navigation graph data. Next, the electronic device starts moving from the first mapped grid. During each move, it uses navigation map data to determine the next grid to move to. It also checks if there are edges between nodes in the navigation map data to determine if movement is possible. Based on the total cost from the current grid to the second mapped grid according to the edge weights, it selects the grid with the lowest total cost to move to, thus obtaining a grid sequence with minimum cost. A funnel algorithm is then applied to this grid sequence to obtain a smooth target path. Alternatively, the electronic device can select the grid with the lowest current cost (i.e., the closest grid to the current grid) to move to, also obtaining a grid sequence. A funnel algorithm is then applied to this grid sequence to obtain a smooth target path.
[0154] In other embodiments of this application, Figure 4 Step 105, which is to determine the target path from the starting point to the ending point of the path based on the navigation grid data of the spatial blocks, can also be achieved by the following processing: quickly generating a rough straight path using the center point of the spatial blocks, and optimizing the straight path using the navigation grid data of the spatial blocks contained in the straight path to obtain the target path.
[0155] The electronic device can first simplify a spatial block into a node, and treat the connections between spatial blocks as edges to obtain graph data. Then, from this graph data, it can find a sequence of nodes that can lead from the node in the spatial block where the path starts to the node in the spatial block where the path ends. Connecting the center points of the spatial blocks corresponding to these nodes yields a straight path, such as a polyline segment. Next, the electronic device can load the necessary navigation mesh data for the spatial blocks along this straight path, search for paths within this navigation mesh data, and replace the straight path with the found paths. In this way, the electronic device can also obtain the target path from the path start to the path end.
[0156] Understandably, compared to dynamic baking in related technologies, which typically generates navigation mesh data for a large number of spatial blocks, resulting in low path generation efficiency in virtual scenes, the electronic device in this embodiment can determine the path coverage area of the first virtual object based on the path start and end points of the path planning request. Then, by combining the path coverage area of the first virtual object with the data maintenance area of the second virtual object, a first data loading area for generating navigation mesh data is determined for the path planning request. Navigation mesh data is generated only for the spatial blocks in the first data loading area, while navigation mesh data is not generated for other spatial blocks. This reduces the redundancy of navigation mesh data, achieving on-demand dynamic baking for path planning requests. This reduces the amount of navigation mesh data that needs to be generated during path planning. In this way, not only is the time required to generate navigation mesh data before path calculation reduced, but memory consumption is also reduced, increasing the available memory during path planning calculation and thus improving the path generation efficiency of the virtual scene.
[0157] The following section explains the process of obtaining the offline grid data packets and chunk lists mentioned above.
[0158] In some embodiments of this application, in Figure 4 Before step 101, that is, before determining the path coverage area of the first virtual object based on the path start and path end points of the path planning request in response to the path planning request for the first virtual object in the virtual scene, the method further includes the following processing: downloading the offline mesh resource package of the virtual scene and the tile list; writing the tile list and the offline mesh resource package to the disk.
[0159] Electronic devices need to download offline mesh data packages and tile lists from a backend server that provides relevant resources for the virtual scene via the network. Both the offline mesh data packages and tile lists are generated by developers during the development phase of the virtual scene.
[0160] It's important to note that the offline mesh data package stores navigation mesh data for spatial blocks in the virtual scene whose spatial complexity exceeds a certain threshold. Spatial complexity characterizes the complexity of the scene portion within a spatial block, such as the number of obstacles, the degree of terrain undulation, and the magnitude of height differences. Spatial blocks with higher spatial complexity require more computational resources to generate navigation mesh data, and the computation time may be longer. Therefore, to avoid these spatial blocks consuming excessive computational resources, their navigation mesh data can be generated offline by developers during the development phase and packaged into an offline mesh resource package. A block list is also generated. Electronic devices only need to download the offline mesh resource package and the block list to directly retrieve the corresponding navigation mesh data from the offline mesh resource package on the disk when needed.
[0161] It is understood that, in the embodiments of this application, the electronic device can pre-store navigation grid data of spatial blocks with high spatial complexity by downloading offline grid resource packages and block lists, so that these navigation grid data can be directly obtained from the disk when needed, without generating these navigation grid data in real time, thereby saving computing resources.
[0162] based on Figure 4 See Figure 8 , Figure 8 This is a flowchart illustrating the path generation method for a virtual scene provided in this application embodiment. Figure 5 In some embodiments of this application, virtual obstacles exist in the first data loading area. Figure 4 After step 104 and before step 105, that is, after generating navigation mesh data for spatial blocks in the first data loading area and before determining the target path from the path start point to the path end point for the first virtual object based on the navigation mesh data of the spatial blocks, the method may further include the following processing:
[0163] Step 106: Determine the spatial block where the virtual obstacle is located from the spatial blocks of the first data loading area.
[0164] It should be noted that the virtual obstacles in the first data loading area can be generated by the electronic device when a set time is reached, or they can be generated by the electronic device according to the task progress of the second virtual object. The electronic device can dynamically update the virtual scene by generating virtual obstacles. In this embodiment, the electronic device first locates the spatial block where the virtual obstacle is located from each spatial block of the first data loading area to obtain the spatial block where the virtual obstacle is located.
[0165] Step 107: Add obstruction status markers to the navigation grid data of the spatial blocks where the virtual obstacles are located.
[0166] It's important to note that the obstruction status marker indicates that navigation grid data is not involved in path calculation. In other words, after determining the spatial block containing the virtual obstacle, the electronic device can use the obstruction status marker to mask the navigation grid data of that block during path calculation. This allows the electronic device to determine the target path using only the navigation grid data of other spatial blocks within the first data loading area, thus achieving obstacle avoidance. In other words, when determining the target path based on the navigation grid data of the spatial blocks in the first data loading area, the electronic device first checks whether the navigation grid data of each spatial block has been marked with an obstruction status marker. Then, during the target path determination process, the navigation grid data with the obstruction status marker is skipped, and only the remaining navigation grid data is used to determine the final target path.
[0167] In some embodiments of this application, in Figure 8 After step 107, that is, after adding obstruction status markers to the navigation grid data of the spatial block where the virtual obstacle is located, the method may further include the following processing: in response to the second virtual object's clearing operation on the virtual obstacle, clearing the virtual obstacle; deleting the obstruction status markers from the navigation grid data of the spatial block where the virtual obstacle is located.
[0168] In other words, when the second virtual object, i.e. the user-controlled virtual object, performs a clearing operation on the virtual obstacle, the electronic device will not only cancel the display of the virtual obstacle, but also simultaneously delete the obstruction status mark of the navigation grid data of the spatial block where the virtual obstacle is located, so that the navigation grid data can be automatically restored.
[0169] It is understood that, in this embodiment of the application, the electronic device can determine the spatial block where the virtual obstacle is located by using the virtual obstacle in the first data loading area, and add an obstruction status mark to the navigation grid data of the spatial block, so that the navigation grid data of the spatial block will not participate in the generation of the subsequent target path, and thus the target path will not pass through the virtual obstacle, thereby achieving the purpose of obstacle avoidance. After the second virtual object performs a clearing operation on the virtual obstacle, the obstruction status mark of the navigation grid data of the spatial block is deleted, so that the navigation grid data of the spatial block can be automatically restored. In this way, the effect of dynamic obstacle adaptation can be achieved.
[0170] In some embodiments of this application, in Figure 8 Before step 106, that is, before determining the spatial block where the virtual obstacle is located from the spatial blocks of the first data loading area, the method may also include the following processing: generating virtual obstacles in the first data loading area through an obstacle generation sub-thread.
[0171] It should be noted that the obstacle generation sub-thread can be a separate sub-thread set up by the developer for generating virtual obstacles, or it can be a sub-thread created by the main thread of the virtual scene in the electronic device. This allows the generation of virtual obstacles to be migrated from the main thread to a sub-thread, thus avoiding lag on the main thread.
[0172] Similarly, in some embodiments of this application, Figure 4 Step 105, namely, determining the target path from the path start point to the path end point for the first virtual object based on the spatially segmented navigation grid data, can be achieved through the following process: using a path planning sub-thread, determining the target path from the path start point to the path end point for the first virtual object based on the spatially segmented navigation grid data.
[0173] It should be noted that the path planning sub-thread can be a separate sub-thread set up by the developer for generating virtual obstacles, or it can be a sub-thread created by the main thread of the virtual scene in the electronic device. In this way, the path planning process can be migrated from the main thread to the sub-thread, thus avoiding lag on the main thread.
[0174] In some embodiments of this application, Figure 5 Step 1042, which is to obtain navigation grid data from the storage space for the spatial blocks in the second sub-region, can be achieved through the following process: obtain navigation grid data from the storage space for the spatial blocks in the second sub-region through the grid acquisition sub-thread.
[0175] It should also be noted that the grid acquisition sub-thread, path planning sub-thread, and obstacle generation sub-thread mentioned above can be implemented by the same sub-thread or by different sub-threads.
[0176] In some embodiments of this application, Figure 5 Step 1043, which is to generate navigation grid data for the spatial blocks in the first sub-region, can also be achieved through the following process: generating navigation grid data for the spatial blocks in the first sub-region through a grid generation sub-thread.
[0177] It should be noted that the mesh generation sub-thread can be a separate sub-thread set up by the developer for generating virtual obstacles, or it can be a sub-thread created by the main thread of the virtual scene in the electronic device. This allows the generation process of navigation mesh data to be migrated from the main thread to a sub-thread, thus avoiding lag on the main thread.
[0178] The following will describe an exemplary application of the embodiments of this application in a real-world application scenario.
[0179] The embodiments of this application are implemented by a terminal (referred to as an electronic device) in a scenario where a smart agent NPC (referred to as a first virtual object) in a game (referred to as a virtual scene) is performing path planning.
[0180] Figure 9 This is a schematic diagram illustrating the path planning process for an intelligent agent (NPC) provided in an embodiment of this application. See also... Figure 9 The process, after it begins, includes:
[0181] Step 201: Obtain the path planning request initiated by the intelligent agent NPC.
[0182] Step 202: Determine the baking range of the path planning request (referred to as the first data loading area) and initiate the baking of the navigation mesh data (Navmesh).
[0183] The terminal can determine the baking range of the path planning request based on the starting point S (called the path start point) and the ending point T (called the path end point) of the path planning, as well as the baking range (called the data maintenance area) of the player's game character (called the second virtual object). For example, the baking range of the player's game character is 100 meters around the player's game character.
[0184] For example, Figure 10 This is a schematic diagram of the baking range provided in the embodiments of this application. Figure 1 See also Figure 10 The game scene is divided into two-dimensional grids (called spatial blocks). The baking range determined based on the position information of the player's game character is region 10-1. Region 10-2 is the region determined based on the starting point S and the ending point T. Region 10-2 is the baking range requested by the path planning.
[0185] In some embodiments, there are already baked regions (referred to as second data loading regions) where the navigation grid data can be directly reused for both the baking range requested by the term path planning request and the already baked regions.
[0186] For example, based on Figure 10 , Figure 11 This is a schematic diagram of the baking range provided in the embodiments of this application. Figure 2 See also Figure 11 Region 11-1 is the already baked region, so the terminal can directly reuse the navigation grid data of the cells in region 11-1.
[0187] During reuse, the terminal can mix and reuse navigation grid data in memory and grid data on disk.
[0188] For example, based on Figure 11 , Figure 12This is a schematic diagram of the baking range provided in the embodiments of this application. Figure 3 ,from Figure 12 It can be seen that the navigation mesh data for cell 12-1 in region 11-1 can be obtained from the disk, meaning the navigation mesh data for cell 12-1 is baked offline. The navigation mesh data for the remaining cells in region 11-1, however, can be obtained from memory, meaning the navigation mesh data for the remaining cells is baked at runtime. Cell 12-1 can be a region in the virtual scene with high complexity, requiring significant computational resources for runtime baking.
[0189] In this embodiment of the application, the terminal can also dynamically adapt to obstacles in the game (referred to as virtual obstacles). Figure 13 This is a schematic diagram of dynamic obstacle adaptation provided in an embodiment of this application. A box exists in grid 13-1. When the user's game character opens the box, the box disappears from the game world, and the navigation grid data of grid 13-1 is automatically restored. It should be noted that the navigation grid data of grid 13-1 is not deleted here; rather, a marker (called an obstruction status marker) is used to mask the navigation grid data of grid 13-1. This masking is also removed after the box disappears.
[0190] Step 203: Wait for the navigation grid data baking to complete.
[0191] For example, Figure 14 This is a schematic diagram of the baking result provided in an embodiment of this application. The navigation mesh data in region 14-1 has been baked, so that subsequent path calculation can be performed.
[0192] Step 204: Calculate the path and return it to the intelligent agent NPC.
[0193] Then, the process ends.
[0194] In this embodiment, a sub-thread can be introduced to handle tasks such as path planning and baking data, in order to avoid lag in the main thread of the game.
[0195] For example, Figure 15 This is a schematic diagram illustrating the processing of sub-threads provided in the embodiment itself. See also... Figure 15 The path planning and data reuse in the main thread 15-1 of the game can be migrated to the sub-thread 15-2 for processing. At the same time, the sub-thread 15-2 can also perform dynamic obstacle sculpting. The data baking task in the main thread 15-1 of the game can be migrated to the sub-thread 15-3 for processing. In this way, the main thread 15-1 of the game can only run the collision manager and the baking manager, thereby reducing the computational burden of the main thread 15-1 of the game.
[0196] It is understood that in the embodiments of this application, user information is involved, such as the location information of the second virtual object controlled by the user. When the embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with relevant laws, regulations and standards.
[0197] The following description continues to illustrate the exemplary structure of the virtual scene path generation device 655 provided in the embodiments of this application as a software module. In some embodiments, such as... Figure 3 As shown, the software module in the path generation device 655 of the virtual scene stored in the memory 650 may include:
[0198] The first region module 6551 is used to respond to a path planning request for a first virtual object in a virtual scene and determine the path coverage area of the first virtual object based on the path start point and path end point of the path planning request.
[0199] The second region module 6552 is used to determine the data maintenance region of the second virtual object in the virtual scene; wherein, the data maintenance region refers to the region where the navigation grid data of the spatial blocks needs to be maintained in the latest state;
[0200] The data determination module 6553 is used to determine a first data loading area based on the path coverage area and the data maintenance area, and to generate navigation grid data for the spatial blocks in the first data loading area;
[0201] The path determination module 6554 is used to determine a target path from the path start point to the path end point for the first virtual object based on the navigation grid data of the spatial blocks.
[0202] In the above scheme, the data determination module 6553 is further configured to determine a first sub-region and a second sub-region from the first data loading region based on the second data loading region, wherein the second data loading region is a region where navigation grid data generation has been completed with spatial segmentation; for the spatial segmentation in the second sub-region, the navigation grid data is obtained from the storage space, and for the spatial segmentation in the first sub-region, the navigation grid data is generated.
[0203] In the above scheme, the data determination module 6553 is further configured to determine the sub-region overlapping with the second data loading region in the first data loading region as the second sub-region; and to determine the sub-regions in the first data loading region other than the second sub-region as the first sub-region.
[0204] In the above scheme, the storage space includes: memory and disk; the data determination module 6553 is further configured to determine a first spatial block and a second spatial block from the spatial blocks of the second sub-region; obtain the navigation grid data of the first spatial block from the offline grid resource package of the virtual scene stored on the disk; and obtain the navigation grid data of the second spatial block from the data cache space of the navigation grid data in the memory.
[0205] In the above scheme, the data determination module 6553 is further configured to obtain from the disk a block list for recording that the navigation mesh data has been generated and stored offline; determine the spatial blocks in the second sub-region that match the block list as the first spatial block; and determine the spatial blocks in the second sub-region other than the first spatial block as the second spatial block.
[0206] In the above scheme, the virtual scene path generation device 655 further includes: a data download module 6555, used to download the offline grid resource package of the virtual scene and the block list, wherein the offline grid data package stores the navigation grid data of the spatial blocks in the virtual scene whose spatial complexity is higher than the complexity threshold, and the spatial complexity characterizes the complexity of the scene part located within the spatial block in the virtual scene; and writes the block list and the offline grid resource package into the disk.
[0207] In the above scheme, the data determination module 6553 is further configured to obtain the status marker of the spatial block in the first data loading area; determine the spatial block in the first data loading area whose status marker indicates that the generation of navigation mesh data has not been completed as the third spatial block, and determine the sub-region generated by the third spatial block as the first sub-region; determine the spatial block in the first data loading area whose status marker indicates that the generation of navigation mesh data has been completed as the fourth spatial block, and determine the sub-region generated by the fourth spatial block as the second sub-region.
[0208] In the above scheme, the data determination module 6553 is further configured to acquire geometric data for the spatial blocks in the first sub-region, wherein the geometric data records the physical structure of the passable area in each spatial block; convert the geometric data into voxel mesh data; extract passable surfaces from the voxel mesh data and generate polygonal outlines using the passable surfaces; and generate the navigation mesh data using the polygonal outlines.
[0209] In the above scheme, the path determination module 6554 is further configured to stitch together the navigation grid data of the spatial blocks into the navigation grid data of the first data loading area; and based on the navigation grid data of the first data loading area, determine the target path from the path starting point to the path ending point.
[0210] In the above scheme, the path determination module 6554 is further configured to determine the first mapping grid of the path starting point and the second mapping grid of the path ending point from the navigation grid data of the first data loading area; construct navigation map data through the connection relationship between the grids in the navigation grid data of the first data loading area; and determine the target path based on the first mapping grid, the second mapping grid and the navigation map data.
[0211] In the above scheme, the first area module 6551 is further used to obtain the location information of the second virtual object, and determine the data maintenance area of the second virtual object based on the location information of the second virtual object and a preset distance;
[0212] The second region module 6552 is further configured to determine the intersection of the path coverage area and the data maintenance area as the first data loading area.
[0213] In the above scheme, there are virtual obstacles in the first data loading area; the data determination module 6553 is further used to determine the spatial block where the virtual obstacle is located from the spatial blocks of the first data loading area; and to add an obstruction status mark to the navigation grid data of the spatial block where the virtual obstacle is located, wherein the obstruction status mark is a mark that indicates that the navigation grid data does not participate in the target path calculation.
[0214] In the above scheme, the data determination module 6553 is further configured to, in response to the second virtual object's clearing operation on the virtual obstacle, clear the virtual obstacle; and delete the obstruction status marker of the navigation grid data in the spatial block where the virtual obstacle is located.
[0215] In the above scheme, the virtual scene path generation device 655 further includes an obstacle generation module 6556, which is used to generate the virtual obstacles in the first data loading area through an obstacle generation sub-thread.
[0216] In the above scheme, the path determination module 6554 is further configured to determine the target path from the path start point to the path end point for the first virtual object based on the navigation grid data of the spatial blocks through the path planning sub-thread.
[0217] In the above scheme, the data determination module 6553 is further configured to generate the navigation grid data for the spatial blocks in the first sub-region through a grid generation sub-thread.
[0218] This application provides a computer program product, which includes a computer program or computer-executable instructions stored in a computer-readable storage medium. The processor of an electronic device reads the computer-executable instructions from the computer-readable storage medium and executes the computer-executable instructions, causing the electronic device to perform the virtual scene path generation method described above in this application.
[0219] This application provides a computer-readable storage medium storing computer-executable instructions or a computer program. When the computer-executable instructions or the computer program are executed by a processor, the processor will execute the virtual scene path generation method provided in this application. For example, ... Figure 4 The method for generating paths in a virtual scene is shown.
[0220] In some embodiments, the computer-readable storage medium may be a memory such as RAM, ROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or it may be a variety of devices including one or any combination of the above-mentioned memories.
[0221] In some embodiments, computer-executable instructions may take the form of programs, software, software modules, scripts, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as stand-alone programs or as modules, components, subroutines, or other units suitable for use in a computing environment.
[0222] As an example, computer-executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple co-located files (e.g., files that store one or more modules, subroutines, or code sections).
[0223] As an example, computer-executable instructions can be deployed to execute on a single electronic device, or on multiple electronic devices located at one location, or on multiple electronic devices distributed across multiple locations and interconnected via a communication network.
[0224] In summary, through the embodiments of this application, the path coverage area of the first virtual object is determined based on the path start and path end points of the path planning request. Then, by combining the path coverage area of the first virtual object with the data maintenance area of the second virtual object, a first data loading area for generating navigation mesh data is determined for the path planning request. Navigation mesh data is generated only for the spatial blocks within the first data loading area, while navigation mesh data is not generated for other spatial blocks. This reduces the redundancy of navigation mesh data, achieving on-demand dynamic baking for the path planning request. This reduces the amount of navigation mesh data that needs to be generated during path planning. Thus, it not only reduces the time required to generate navigation mesh data before path calculation but also reduces memory consumption, increasing the available memory during path planning calculation and improving the path generation efficiency of the virtual scene. Dividing the first data loading area into a first sub-area that actually needs to generate navigation mesh data and a second sub-area that can directly reuse the already generated navigation mesh data reduces the number of spatial blocks that need to generate navigation mesh data, enabling the rapid acquisition of navigation mesh data for each spatial block within the first data loading area, which helps improve the efficiency of path generation.
[0225] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.
Claims
1. A path generation method for a virtual scene, characterized in that, The method includes: In response to a path planning request for a first virtual object in a virtual scene, the path coverage area of the first virtual object is determined based on the path start point and path end point of the path planning request. Determine the data maintenance area of the second virtual object in the virtual scene; wherein, the data maintenance area refers to the area where the navigation grid data of the spatial blocks needs to be maintained in the latest state; Based on the path coverage area and the data maintenance area, a first data loading area is determined, and navigation grid data is generated for the spatial blocks in the first data loading area; Based on the navigation grid data of the spatial blocks, a target path from the path start point to the path end point is determined for the first virtual object.
2. The method according to claim 1, characterized in that, The step of generating navigation grid data for spatial segmentation of the first data loading area includes: Based on the second data loading area, a first sub-region and a second sub-region are determined from the first data loading area, wherein the second data loading area is the area where navigation mesh data generation has been completed with spatial segmentation; For the spatial blocks in the second sub-region, the navigation grid data is obtained from the storage space, and for the spatial blocks in the first sub-region, the navigation grid data is generated.
3. The method according to claim 2, characterized in that, The step of determining the first sub-region and the second sub-region from the first data loading region based on the second data loading region includes: The sub-region that overlaps with the second data loading region in the first data loading region is determined as the second sub-region; The sub-regions in the first data loading area other than the second sub-region are defined as the first sub-region.
4. The method according to claim 2, characterized in that, The storage space includes: memory and disk; the step of retrieving the navigation mesh data from the storage space for the spatial blocks in the second sub-region includes: From the spatial blocks of the second sub-region, determine the first spatial block and the second spatial block; Obtain the navigation grid data of the first spatial block from the offline grid resource package of the virtual scene stored on the disk; The navigation grid data of the second spatial block is obtained from the data cache space of the navigation grid data in the memory.
5. The method according to claim 4, characterized in that, Determining the first spatial block and the second spatial block from the spatial blocks of the second sub-region includes: Obtain from the disk a block list of spatial blocks used to record that the navigation mesh data has been generated and stored offline; The spatial block in the second sub-region that matches the block list is determined as the first spatial block; The spatial blocks in the second sub-region other than the first spatial block are defined as the second spatial block.
6. The method according to claim 5, characterized in that, Before determining the path coverage area of the first virtual object based on the path start and path end points of the path planning request in response to a path planning request for a first virtual object in a virtual scene, the method further includes: Download the offline mesh resource package and the block list of the virtual scene. The offline mesh data package stores the navigation mesh data of the spatial blocks in the virtual scene whose spatial complexity is higher than the complexity threshold. The spatial complexity characterizes the complexity of the scene part located in the spatial block in the virtual scene. Write the block list and the offline grid resource package to the disk.
7. The method according to claim 2, characterized in that, The step of determining the first sub-region and the second sub-region from the first data loading region based on the second data loading region includes: Obtain the status marker of the spatial block in the first data loading area; The spatial block in the first data loading area that represents the incomplete generation of navigation mesh data by the status marker is determined as the third spatial block, and the sub-region generated by the third spatial block is determined as the first sub-region; The spatial block in the first data loading area that represents the completion of the generation of the navigation mesh data by the status marker is determined as the fourth spatial block, and the sub-region generated by the fourth spatial block is determined as the second sub-region.
8. The method according to any one of claims 2 to 7, characterized in that, The step of generating the navigation mesh data for the spatial blocks in the first sub-region includes: For the spatial blocks in the first sub-region, geometric data is obtained, wherein the geometric data records the physical structure of the passable area in each spatial block; The geometric data is converted into voxel mesh data; Accessible surfaces are extracted from the voxel mesh data, and polygonal outlines are generated using the accessible surfaces; The navigation mesh data is generated using the polygonal outline.
9. The method according to any one of claims 1 to 6, characterized in that, The navigation mesh data based on the spatial blocks, for the first virtual object, determines a target path from the path start point to the path end point, including: The navigation grid data of the spatial blocks are spliced together to form the navigation grid data of the first data loading area; Based on the navigation grid data in the first data loading area, the target path from the path start point to the path end point is determined.
10. The method according to claim 9, characterized in that, Determining the target path from the path start point to the path end point based on the navigation grid data of the first data loading area includes: From the navigation grid data in the first data loading area, determine the first mapping grid of the path starting point and the second mapping grid of the path ending point respectively; Navigation map data is constructed by utilizing the connection relationships between the grids in the navigation grid data of the first data loading area; The target path is determined based on the first mapping grid, the second mapping grid, and the navigation map data.
11. The method according to any one of claims 1 to 7, characterized in that, Determining the data maintenance area of the second virtual object in the virtual scene includes: Obtain the location information of the second virtual object, and determine the data maintenance area of the second virtual object based on the location information of the second virtual object and a preset distance; The determination of the first data loading area based on the path coverage area and the data maintenance area includes: The intersection of the path coverage area and the data maintenance area is determined as the first data loading area.
12. The method according to any one of claims 1 to 7, characterized in that, The first data loading area contains virtual obstacles; after generating navigation mesh data for spatial blocks in the first data loading area, and before determining the target path from the path start point to the path end point for the first virtual object based on the navigation mesh data of the spatial blocks, the method further includes: The spatial block where the virtual obstacle is located is determined from the spatial blocks of the first data loading area; For the navigation grid data of the spatial block where the virtual obstacle is located, an obstruction status marker is added. The obstruction status marker is a marker that indicates that the navigation grid data does not participate in the target path calculation.
13. The method according to claim 12, characterized in that, After adding obstruction status markers to the navigation grid data of the spatial blocks where the virtual obstacle is located, the method further includes: In response to the second virtual object's clearing operation on the virtual obstacle, the virtual obstacle is cleared; Delete the obstruction status marker of the navigation grid data in the spatial block where the virtual obstacle is located.
14. The method according to claim 12, characterized in that, Before determining the spatial block where the virtual obstacle is located from the spatial blocks of the first data loading area, the method further includes: The virtual obstacles are generated in the first data loading area through an obstacle generation sub-thread.
15. The method according to any one of claims 1 to 7, characterized in that, The navigation mesh data based on the spatial blocks, for the first virtual object, determines a target path from the path start point to the path end point, including: Using a path planning sub-thread, the target path from the path start point to the path end point is determined for the first virtual object based on the navigation grid data of the spatial blocks.
16. The method according to any one of claims 2 to 7, characterized in that, The step of generating the navigation mesh data for the spatial blocks in the first sub-region includes: The navigation grid data is generated by a sub-thread that generates a grid for the spatial blocks in the first sub-region.
17. A path generation device for a virtual scene, characterized in that, The device includes: The first region module is used to respond to a path planning request for a first virtual object in a virtual scene and determine the path coverage area of the first virtual object based on the path start point and path end point of the path planning request. The second region module is used to determine the data maintenance region of the second virtual object in the virtual scene; wherein, the data maintenance region refers to the region where the navigation grid data of the spatial blocks needs to be maintained in the latest state; The data determination module is used to determine a first data loading area based on the path coverage area and the data maintenance area, and to generate navigation grid data for the spatial blocks in the first data loading area; The path determination module is used to determine a target path from the path start point to the path end point for the first virtual object based on the navigation grid data of the spatial blocks.
18. An electronic device, characterized in that, The electronic device includes: Memory is used to store executable instructions or computer programs. A processor, when executing computer-executable instructions or computer programs stored in the memory, implements the method according to any one of claims 1 to 16.
19. A computer-readable storage medium storing computer-executable instructions or a computer program, characterized in that, When the computer-executable instructions or computer program are executed by a processor, they implement the method described in any one of claims 1 to 16.
20. A computer program product comprising computer-executable instructions or a computer program, characterized in that, When the computer-executable instructions or computer program are executed by a processor, they implement the method according to any one of claims 1 to 16.