Virtual building cluster generation method and apparatus, and electronic device
Through the use of seed algorithms and constraints in virtual scenarios to automatically determine the location of virtual buildings, the problems of low efficiency and high labor costs in existing technologies have been solved, and high -efficiency and automated virtual building cluster generation has been realized.
Patent Information
- Application Number
- CN202411360715.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-26
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2044-09-26
AI Technical Summary
The prior art is less efficient and labor costs when building virtual villages and cities in virtual scenarios, especially when artificially creating villages and roads on complex terrain is a difficult task.
By obtaining the initial position of the preset, based on the preset seed algorithm, initial location and constraint conditions, multiple target positions are automatically determined, and virtual buildings are set at these locations to form a virtual building cluster. The constraint conditions are used to limit the slope of the target position to ensure that the location of the building is gentle.
The location of virtual buildings is automatically determined, and the virtual building cluster quickly generates the efficiency of building virtual settlements and reduces labor costs.
Smart Images

Figure CN119378059A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of virtual scenes, and in particular to a method, device and electronic device for generating a virtual building cluster. Background Art
[0002] In order to simulate the real world in a virtual scene, a large number of virtual villages, virtual cities and other biological settlements need to be established. In related technologies, artists usually set the range of biological settlements according to the topography of the virtual scene and set up virtual buildings within the range. However, this method is inefficient and has high labor costs. Summary of the invention
[0003] In view of this, the purpose of the present disclosure is to provide a method, device and electronic device for generating a virtual building cluster, so as to automatically determine multiple locations for setting up virtual buildings, quickly generate a virtual building cluster, improve the efficiency of building a virtual settlement, and reduce labor costs.
[0004] In a first aspect, an embodiment of the present disclosure provides a method for generating a virtual building cluster, the method comprising: obtaining a preset initial position; the initial position is located on the terrain surface of a preset virtual scene; based on a preset seed algorithm, the initial position and preset constraints, multiple target positions are determined; the constraints are used to limit the slope of the target position; and virtual buildings are set at multiple target positions to form a virtual building cluster.
[0005] In a second aspect, an embodiment of the present disclosure provides a device for generating a virtual building cluster, the device comprising: an initial position acquisition module, used to acquire a preset initial position; the initial position is located at a terrain surface of a preset virtual scene; a target position determination module, used to determine multiple target positions based on a preset seed algorithm, the initial position and preset constraints; the constraints are used to limit the slope of the target position; a virtual building setting module, used to set virtual buildings at multiple target positions to form a virtual building cluster.
[0006] In a third aspect, an embodiment of the present invention provides an electronic device, including a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the above-mentioned method for generating a virtual building cluster.
[0007] In a fourth aspect, an embodiment of the present invention provides a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned method for generating a virtual building cluster.
[0008] The embodiments of the present invention bring the following beneficial effects:
[0009] The above-mentioned method, device and electronic device for generating a virtual building cluster obtain a preset initial position; the initial position is located on the terrain surface of a preset virtual scene; based on a preset seed algorithm, the initial position and preset constraints, multiple target positions are determined; the constraints are used to limit the slope of the target position; virtual buildings are set at multiple target positions to form a virtual building cluster. This method can automatically determine multiple positions for setting virtual buildings, quickly generate virtual building clusters, improve the efficiency of building virtual settlements, and reduce labor costs.
[0010] Other features and advantages of the present disclosure will be described in the following description, and partly become apparent from the description, or understood by practicing the present disclosure. The purpose and other advantages of the present disclosure are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0011] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the specific embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the specific embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0013] Figure 1 A flowchart of a method for generating a virtual building cluster provided by an embodiment of the present disclosure;
[0014] Figure 2 A schematic diagram of a post-diffusion position provided by an embodiment of the present disclosure;
[0015] Figure 3 A schematic diagram of another post-diffusion position provided for an embodiment of the present disclosure;
[0016] Figure 4 A schematic diagram of a normal direction provided in an embodiment of the present disclosure;
[0017] Figure 5 A schematic diagram of the positions of seed points before and after disturbance provided in an embodiment of the present disclosure;
[0018] Figure 6 A schematic diagram of a waypoint provided in an embodiment of the present disclosure;
[0019] Figure 7 A schematic diagram of two road comparisons provided in an embodiment of the present disclosure;
[0020] Figure 8 A schematic diagram of two road comparisons provided in an embodiment of the present disclosure;
[0021] Fig. 9 A schematic diagram of a virtual village and roads provided in an embodiment of the present disclosure;
[0022] Fig.10 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0023] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present disclosure, rather than all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.
[0024] In virtual scenes, in order to simulate the real world, a large number of virtual villages, virtual cities and other biological settlements need to be established. In related technologies, artists usually set the scope of biological settlements according to the topography of the virtual scene and set up virtual buildings within the scope. It is a difficult task to artificially create villages on complex terrain and generate roads between villages. These details generally take a lot of time for relevant staff and are inefficient.
[0025] Based on this, the embodiments of the present disclosure provide a method, device and electronic device for generating a virtual building cluster. The technology can be applied to the scene of generating a biological settlement in a virtual environment.
[0026] See also Figure 1 First, a method for generating a virtual building cluster provided by an embodiment of the present invention is introduced, and a graphical user interface is provided through a terminal device. The method comprises the following steps:
[0027] Step S102, obtaining a preset initial position; the initial position is located on the terrain surface of a preset virtual scene.
[0028] The above initial position can be specified by relevant personnel or randomly generated within a preset terrain surface range. The initial position is consistent with the number of virtual building clusters to be generated, which can be one or more. The initial position can be the center position of the virtual building cluster to be generated by the user, or it can be an edge position, which is related to the parameters such as the diffusion direction used in the subsequent seed algorithm.
[0029] Generally speaking, virtual building clusters are usually built in relatively flat terrain areas. It can be determined in advance whether the terrain at the initial position is flat, for example, whether the slope of the initial position is less than a preset slope threshold. If it is greater than or equal to the slope threshold, it can be considered that the currently acquired initial position is not suitable as the initial position in the method, so the user is prompted to request to provide the initial position again.
[0030] Step S104, determining a plurality of target positions based on a preset seed algorithm, an initial position and preset constraint conditions; the constraint conditions are used to limit the slope of the target position.
[0031] The seed filling algorithm is an algorithm that starts from a seed point in a connected region and gradually expands to the surrounding area to fill the entire region. This algorithm is very common in computer graphics and is often used for region filling operations. The application scenarios of seed algorithms are very wide, mainly used in image processing, computer graphics and other fields. For example, in image processing, seed algorithms can be used to fill polygonal areas and process connected domains of images.
[0032] In this method, the initial position can be used as a seed and diffused to the surroundings to obtain multiple seed positions after diffusion. Then, diffusion is performed again based on the diffused position to obtain the position after diffusion again, until the diffusion times reach a specified number or the obtained seed positions reach a specified number. Among them, the diffusion direction and diffusion distance can be pre-specified. The diffusion direction and diffusion distance can be constant or change with the diffusion times. They can be set according to needs and are not limited here.
[0033] It is worth noting that since buildings usually need to be set up on a relatively flat surface, it is necessary to determine whether the location after diffusion is flat. Specifically, constraints can be set, such as pre-setting a slope threshold, and judging whether the slope of each seed location is less than the preset slope threshold. If it is greater than or equal to the slope threshold, the seed location is considered unsuitable for building a virtual building and is deleted.
[0034] The step of judging whether the seed position satisfies the constraint conditions can be performed after the diffusion is completed, or after a certain seed position is obtained by diffusion, that is, judging whether the seed position satisfies the constraint conditions. If not, diffusion will not be performed based on the seed position to obtain other seed positions. The specific setting can be made according to the needs and is not made here.
[0035] The obtained seed position can be directly used as the target position. At this time, the distance between adjacent seed positions is related to the diffusion distance. When the diffusion distance remains unchanged, the distance between seed positions is usually unchanged. When the distance between each building in the building cluster needs to be random, the obtained seed position can also be disturbed. When the scale of the disturbance is larger, the distance between the disturbed positions is more random. However, when the disturbance scale is too large, it is easy for each seed position to overlap, so it is necessary to control the disturbance scale not to be too large. Then the disturbed seed position can be determined as the target position.
[0036] Step S106, setting up virtual buildings at multiple target locations to form a virtual building cluster.
[0037] After the target location is determined, virtual buildings can be set at the target location in a certain order. For example, virtual buildings can be set at each target location in the order of the generation time of the seed location corresponding to the target location, or in the order from south to north or from west to east, without limitation.
[0038] When setting a virtual building, there may already be virtual buildings set up at other target locations around the virtual building, and each virtual building has a certain volume. It is necessary to determine whether the virtual building set up at the current location will overlap with other virtual buildings. If so, the current target location can be appropriately adjusted, or a virtual building with a smaller volume can be selected, or the virtual building set up at the target location can be abandoned. The specific setting is based on the needs and is not limited here.
[0039] The above-mentioned method for generating a virtual building cluster obtains a preset initial position; the initial position is located on the terrain surface of a preset virtual scene; based on a preset seed algorithm, the initial position and preset constraints, multiple target positions are determined; the constraints are used to limit the slope of the target position; virtual buildings are set at multiple target positions to form a virtual building cluster. This method can automatically determine multiple positions for setting virtual buildings, quickly generate virtual building clusters, improve the efficiency of building virtual settlements, and reduce labor costs.
[0040] The following embodiment provides a specific method for determining multiple target positions based on a preset seed algorithm, an initial position, and preset constraints.
[0041] In the specific implementation, the initial position is first determined as the initial seed position. Then, based on the preset seed algorithm and the initial seed position, multiple diffused positions are determined. During the diffusion process, the seed algorithm is used to determine multiple diffused positions corresponding to the initial seed position based on the initial seed position, multiple preset diffusion directions, and diffusion distances. The seed position usually diffuses in multiple directions, and unidirectional diffusion will result in a single row of virtual buildings, which does not meet the visual requirements of building clusters.
[0042] In practical applications, the terrain surface in a virtual scene can usually be formed by connecting multiple quadrilaterals, and adjacent quadrilaterals share two vertices. The above diffusion distance can be a multiple of the side length of the quadrilateral. When the initial seed position is the vertex of the quadrilateral, diffusion is performed along the edge of the quadrilateral, and the obtained diffused position is at the vertex of the quadrilateral.
[0043] The quadrilateral may be a square. In this case, the plurality of diffusion directions may be a plurality of the following directions: a first direction, a second direction, a third direction, and a fourth direction along the terrain surface. The first direction is opposite to the second direction, the third direction is opposite to the fourth direction, and the first direction is perpendicular to the third direction. Figure 2 As shown in FIG. 1 , a, b, c and d represent the first direction, the second direction, the third direction and the fourth direction respectively. When diffusion is performed once in the first direction, the second direction and the third direction, the obtained diffused position is represented by a black dot, and the initial seed position is represented by a hollow dot.
[0044] After obtaining multiple diffused positions, it is necessary to determine the target seed position from the multiple diffused positions, and the slope of the determined target seed position needs to meet the preset constraint conditions. In a specific implementation, the slope of the diffused position can be represented by the normal direction at the diffused position. At this time, the constraint condition can be that the dot product result of the normal direction of the target seed position and the target normal direction is greater than a preset first threshold, and the target normal direction is vertically upward. When the dot product result is larger, the slope of the diffused position is smaller, so that the slope of the target seed position can be limited by the constraint condition.
[0045] Specifically, for each of the multiple diffused positions, it is necessary to calculate the dot product result of the normal direction of the diffused position and the target normal direction; if the dot product result is greater than a first threshold, the diffused position is determined to be a target seed position, otherwise, the diffused position is determined to be a non-target seed position.
[0046] After each diffusion process, it is necessary to determine whether the diffusion termination condition is met. The diffusion termination condition may be that the number of diffusions reaches a preset number threshold, or the number of target seed positions is greater than or equal to a preset number threshold, or both of the above conditions may be used as diffusion termination conditions. If not met, multiple diffusion positions are further determined through a preset seed algorithm and target seed position, and the target seed position is determined from the multiple diffusion positions until the preset diffusion termination condition is met. Finally, multiple target positions need to be determined based on the initial seed position and the target seed position.
[0047] After obtaining each seed position, the initial position and the target seed position can be perturbed based on a preset perturbation scale to obtain the perturbed position. It is worth noting that in order to reduce the overlap between seed positions, the perturbation scale needs to be controlled to be less than half of the distance between the initial position and the target seed position adjacent to the initial position; and the perturbed position is determined as the target position.
[0048] In practical applications, multiple virtual building clusters are usually established, and roads between different virtual building clusters need to be established. Taking a virtual scene including a first virtual building cluster, a second virtual building cluster and a third virtual building cluster as an example, the method of establishing roads is described.
[0049] Generally speaking, the first virtual building cluster has a first starting waypoint, the second virtual building cluster has a second starting waypoint, and the third virtual building cluster has a third starting waypoint. The above starting waypoints can be inside the area where the corresponding virtual building cluster is located, or near the area, which is not limited here.
[0050] A road between the first virtual building cluster and the second virtual building cluster may be established first. The two virtual building clusters may be randomly selected or selected according to preset conditions, such as the shortest or longest distance between the two building clusters. The specific conditions may be set according to demand and are not limited here.
[0051] In a specific implementation, the first target waypoint can be determined based on the terrain parameters of the terrain surface, the first starting waypoint and the second starting waypoint. Among them, the first target waypoint usually includes multiple. Multiple first target waypoints constitute the first virtual road between the first starting waypoint and the second starting waypoint. Specifically, a variety of pathfinding algorithms can be used. For example: depth first search (DFS), breadth first search (BFS), Dijkstra algorithm (Dijkstra), A* algorithm, etc., which are not limited here. Since the road is usually required to be relatively flat, when determining the waypoint, the terrain parameters of the waypoint also need to be considered, and a position with a smaller slope can be selected as a waypoint.
[0052] After determining the first target waypoint, it is necessary to determine the second target waypoint based on the third starting waypoint and the first target waypoint. There are usually multiple second target waypoints, and multiple second target waypoints constitute a second virtual road connected by the third starting waypoint and the first virtual road. Specifically, it is usually necessary to determine the first waypoint closest to the third starting waypoint among multiple first target waypoints, and the distance between each first target waypoint and the third starting waypoint can be calculated respectively, and the distance can be compared to determine the first waypoint. Then, based on a preset path-finding algorithm, the second target waypoint located between the third starting waypoint and the first waypoint can be determined. In this process, it is also necessary to consider whether the slope of the second target waypoint is smaller, so as to establish a smoother road.
[0053] The present disclosure also provides another method for generating a virtual building cluster. Figure 1 The method is implemented based on the method shown in . This method uses villages to represent virtual building clusters, analyzes the terrain, defines suitable areas for villages, and generates roads connecting them. The area demarcated by each village is determined by the terrain features, and the road system is generated by the improved A* algorithm. In this method, users can easily modify the relevant parameters to better meet their needs. Since this method does not need to fully iterate all terrain elevation points, it is much faster than existing procedural methods. In addition, the improved A* algorithm allows users to control the radius of the search waypoints, which can also speed up the generation of roads.
[0054] This method is mainly divided into two steps: generating village building locations and generating roads:
[0055] In the first step, in order to speed up the generation, the user needs to specify the seed position (equivalent to the above "initial position"). Then, four new seed points are generated along the horizontal and vertical directions according to the seed point position given by the user. Next, it is determined whether the slope of the seed point is within the threshold. If it is not within the threshold, the seed point is discarded. Otherwise, these new seeds are used for the next step of expansion.
[0056] In the specific implementation, firstly, the user specifies the seed point position, and searches for a suitable seed point position along the radius set by the user in both horizontal and vertical directions. If the seed point position is found, the search continues based on the currently found seed point. Figure 3 Shown are the seed point locations after three iterations with an expansion radius of 2. Figure 3 In the figure, S is the seed point specified by the user, and 1 and 2 are the seed points of two iterative expansions. The search radius used in the figure above is 2, and the user can set the search radius and number of iterations as needed.
[0057] In order to determine whether the seed point is suitable, you can determine it by judging the slope of the current seed point. The slope of the seed point is determined by calculating the dot product of the normal of the current point and the vertical upward vector. When the dot product value is smaller, it means that the slope is larger and the seed point is less suitable. Figure 4 As shown, P represents the candidate seed point, P0 and P1 represent its neighboring points, N is the normal of P, and N' is the upward direction.
[0058] To calculate the normal of the seed point, its gradient is used to calculate the horizontal and vertical vectors, that is, the vectors from P1 to P and P0 to P. The cross product of these two vectors is calculated to obtain N. Finally, the dot product of N and N' is calculated to obtain the slope. In the second step, when the number of expansion steps specified by the user is reached (equivalent to the "number of diffusion times" mentioned above), the expansion is stopped. Then, the generated seed points are randomly perturbed, and the perturbation radius is half of the expansion radius. Next, seed points are randomly selected and buildings are placed step by step. Each placement needs to first determine whether it overlaps with the previous building. If it overlaps, the seed point is abandoned.
[0059] After obtaining the final seed point, all seed points need to be randomly perturbed in the horizontal and vertical directions to obtain an irregular distribution, such as Figure 5 As shown, the left picture shows the undisturbed seed point distribution, and the right picture shows the undisturbed seed point distribution. Note that the perturbation radius should be less than half of the expansion radius to avoid overlapping seed points. Finally, random points can be selected as the locations of village buildings.
[0060] The third step is to use the A* algorithm to find a path for the village seed point given by the user. The cost function of the path needs to consider the slope of the current point and the surrounding points. The higher the slope, the higher the cost. After the first road is created, the end point of the subsequent road should be the point closest to the starting point in the existing road to create a T-junction.
[0061] In the specific implementation, in order to generate a road connecting two villages, the improved A* algorithm is used. First, the search radius of the A* algorithm is user-customizable. This can generate roads faster, such as Figure 6 As shown in the figure, white dots are confirmed waypoints, black dots are candidate points, and the search radius is 2 to speed up the pathfinding calculation. The waypoints are determined using the following formula:
[0062] Weight=DistXY(p1, p2)+DistXY(p1, p2)×(1-a)×β
[0063] Where is the Euler distance or Manhattan distance from the current waypoint to the end point. α is the slope, which directly takes the slope value (partial derivative) of the current waypoint and the candidate waypoint. β determines the impact of the slope on pathfinding. The impact of different values of β on pathfinding is as follows Figure 7As shown, the slope in the left figure has a small impact, while the slope in the right figure has a large impact.
[0064] After calculation, the candidate point with the smallest weight is taken as the waypoint. When the first road is created, the end point of the subsequent road should be the point closest to the starting point in the existing road to create a T-junction. In order to simplify the calculation and get the point with the closest distance, this method directly uses the Euler distance from the current point to all points on the road.
[0065] When the user specifies three village points, the automatically generated building locations and roads are as follows: Figure 8 shown.
[0066] This method does not need to fully iterate all terrain elevation points, and it is much faster than the existing procedural method. In addition, the improved A* algorithm allows users to control the radius of the search point, which can also speed up the generation of roads. The biggest advantage of this method is that it is flexible and fast, and it can generate T-junctions in real situations.
[0067] For the above method embodiments, see Fig. 9 A device for generating a virtual building cluster is shown, the device comprising:
[0068] The initial position acquisition module 802 is used to acquire a preset initial position; the initial position is located on the terrain surface of the preset virtual scene;
[0069] The target position determination module 804 is used to determine multiple target positions based on a preset seed algorithm, an initial position and preset constraint conditions; the constraint conditions are used to limit the slope of the target position;
[0070] The virtual building setting module 806 is used to set virtual buildings at multiple target locations to form a virtual building cluster.
[0071] The above-mentioned device for generating a virtual building cluster obtains a preset initial position; the initial position is located on the terrain surface of a preset virtual scene; based on a preset seed algorithm, the initial position and preset constraints, multiple target positions are determined; the constraints are used to limit the slope of the target position; virtual buildings are set at the multiple target positions to form a virtual building cluster. This method can automatically determine multiple positions for setting virtual buildings, quickly generate virtual building clusters, improve the efficiency of building virtual settlements, and reduce labor costs.
[0072] The above-mentioned target position determination module is also used to: determine the initial position as the initial seed position; determine multiple diffused positions based on a preset seed algorithm and the initial seed position; determine the target seed position from the multiple diffused positions, and the slope of the target seed position meets the preset constraint conditions; judge whether the diffusion termination condition is met; the diffusion termination condition includes at least one of the following: the number of diffusions reaches a preset number threshold, and\or, the number of target seed positions is greater than or equal to a preset number threshold; if not met, determine multiple diffused positions through a preset seed algorithm and the target seed position, and continue to execute the step of determining the target seed position from the multiple diffused positions based on the terrain parameters corresponding to the multiple diffused positions until the preset diffusion termination condition is met; determine multiple target positions based on the initial seed position and the target seed position.
[0073] The slope of the above-mentioned diffused position is represented by the normal direction at the diffused position; the constraint conditions include that the dot product result of the normal direction of the target seed position and the target normal direction is greater than a preset first threshold; the target normal direction is vertically upward; the above-mentioned target position determination module is also used to: for each of the multiple diffused positions, calculate the dot product result of the normal direction of the diffused position and the target normal direction; if the dot product result is greater than the first threshold, determine that the diffused position is the target seed position.
[0074] The target position determination module is also used to determine multiple diffused positions corresponding to the initial seed position based on the initial seed position, multiple preset diffusion directions and diffusion distances through a preset seed algorithm.
[0075] The above-mentioned multiple diffusion directions include at least two of the following: a first direction, a second direction, a third direction and a fourth direction along the terrain surface; the first direction is opposite to the second direction, the third direction is opposite to the fourth direction, and the first direction is perpendicular to the third direction.
[0076] The target position determination module is also used to: perform disturbance processing on the initial position and the target seed position based on a preset disturbance scale to obtain a disturbed position; the disturbance scale is less than half of the distance between the initial position and the target seed position adjacent to the initial position; and determine the disturbed position as the target position.
[0077] The above-mentioned virtual scene includes a first virtual building cluster, a second virtual building cluster and a third virtual building cluster; the first virtual building cluster has a first starting waypoint; the second virtual building cluster has a second starting waypoint; the third virtual building cluster has a third starting waypoint; the above-mentioned device also includes: a first target waypoint determination module, which is used to determine the first target waypoint based on the terrain parameters of the terrain surface, the first starting waypoint and the second starting waypoint; the first target waypoint constitutes a first virtual road between the first starting waypoint and the second starting waypoint; the second target waypoint determination module is used to determine the second target waypoint based on the third starting waypoint and the first target waypoint; the second target waypoint constitutes a second virtual road connected by the third starting waypoint and the first virtual road.
[0078] The above-mentioned first target waypoint includes multiple ones; the second target waypoint determination module is also used to: determine the first waypoint closest to the third starting waypoint among the multiple first target waypoints; based on a preset pathfinding algorithm, determine the second target waypoint located between the third starting waypoint and the first waypoint.
[0079] This embodiment also provides an electronic device, including a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the above-mentioned method for generating a virtual building cluster, for example:
[0080] A preset initial position is obtained; the initial position is located on the terrain surface of a preset virtual scene; multiple target positions are determined based on a preset seed algorithm, the initial position and preset constraints; the constraints are used to limit the slope of the target position; virtual buildings are set at multiple target positions to form a virtual building cluster.
[0081] The above method can automatically determine multiple locations for setting up virtual buildings, quickly generate virtual building clusters, improve the efficiency of building virtual settlements, and reduce labor costs.
[0082] Optionally, the above-mentioned step of determining multiple target positions based on a preset seed algorithm, an initial position and preset constraints includes: determining the initial position as the initial seed position; determining multiple diffused positions based on the preset seed algorithm and the initial seed position; determining the target seed position from the multiple diffused positions, wherein the slope of the target seed position satisfies the preset constraints; judging whether the diffusion termination condition is met; the diffusion termination condition includes at least one of the following: the number of diffusions reaches a preset number threshold, and\or, the number of target seed positions is greater than or equal to a preset number threshold; if not met, determining multiple diffused positions through the preset seed algorithm and the target seed position, and continuing to execute the step of determining the target seed position from the multiple diffused positions based on the terrain parameters corresponding to the multiple diffused positions until the preset diffusion termination condition is met; determining multiple target positions based on the initial seed position and the target seed position.
[0083] Optionally, the slope of the above-mentioned diffused position is represented by the normal direction at the diffused position; the constraint conditions include that the dot product result of the normal direction of the target seed position and the target normal direction is greater than a preset first threshold; the target normal direction is vertically upward; the step of determining the target seed position from multiple diffused positions, wherein the slope of the target seed position satisfies the preset constraint conditions, includes: for each diffused position among the multiple diffused positions, calculating the dot product result of the normal direction of the diffused position and the target normal direction; if the dot product result is greater than the first threshold, determining that the diffused position is the target seed position.
[0084] Optionally, the step of determining multiple diffused positions based on a preset seed algorithm and an initial seed position includes: determining multiple diffused positions corresponding to the initial seed position based on the initial seed position, multiple preset diffusion directions and diffusion distances through a preset seed algorithm.
[0085] Optionally, the above-mentioned multiple diffusion directions include at least two of the following: a first direction, a second direction, a third direction and a fourth direction along the terrain surface; the first direction is opposite to the second direction, the third direction is opposite to the fourth direction, and the first direction is perpendicular to the third direction.
[0086] Optionally, the step of determining multiple target positions based on the initial seed position and the target seed position includes: perturbing the initial position and the target seed position based on a preset disturbance scale to obtain a disturbed position; the disturbance scale is smaller than half of the distance between the initial position and the target seed position adjacent to the initial position; and determining the disturbed position as the target position.
[0087] Optionally, the above-mentioned virtual scene includes a first virtual building cluster, a second virtual building cluster and a third virtual building cluster; the first virtual building cluster has a first starting waypoint; the second virtual building cluster has a second starting waypoint; the third virtual building cluster has a third starting waypoint; the above-mentioned method also includes: determining a first target waypoint based on terrain parameters of the terrain surface, the first starting waypoint and the second starting waypoint; the first target waypoint constitutes a first virtual road between the first starting waypoint and the second starting waypoint; determining a second target waypoint based on the third starting waypoint and the first target waypoint; and the second target waypoint constitutes a second virtual road connected by the third starting waypoint and the first virtual road.
[0088] Optionally, the above-mentioned first target waypoint includes multiple; the step of determining the second target waypoint based on the third starting waypoint and the first target waypoint includes: determining the first waypoint closest to the third starting waypoint among the multiple first target waypoints; based on a preset pathfinding algorithm, determining the second target waypoint located between the third starting waypoint and the first waypoint.
[0089] See also Fig.10 As shown, the electronic device includes a processor 100 and a memory 101. The memory 101 stores machine executable instructions that can be executed by the processor 100. The processor 100 executes the machine executable instructions to implement the above-mentioned method for generating a virtual building cluster.
[0090] Further, Fig.10 The electronic device shown further includes a bus 102 and a communication interface 103 , and the processor 100 , the communication interface 103 and the memory 101 are connected via the bus 102 .
[0091] The memory 101 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 102 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.10 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0092] The processor 100 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 100. The above processor 100 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 101, and the processor 100 reads the information in the memory 101 and completes the steps of the method of the above embodiment in combination with its hardware.
[0093] This embodiment also provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned method for generating a virtual building cluster.
[0094] The present disclosure provides a method, device and electronic device for generating a virtual building cluster, including a computer-readable storage medium storing program code, wherein the program code includes instructions that can be used to execute the method described in the above method embodiments, for example:
[0095] A preset initial position is obtained; the initial position is located on the terrain surface of a preset virtual scene; multiple target positions are determined based on a preset seed algorithm, the initial position and preset constraints; the constraints are used to limit the slope of the target position; virtual buildings are set at multiple target positions to form a virtual building cluster.
[0096] The above method can automatically determine multiple locations for setting up virtual buildings, quickly generate virtual building clusters, improve the efficiency of building virtual settlements, and reduce labor costs.
[0097] Optionally, the above-mentioned step of determining multiple target positions based on a preset seed algorithm, an initial position and preset constraints includes: determining the initial position as the initial seed position; determining multiple diffused positions based on the preset seed algorithm and the initial seed position; determining the target seed position from the multiple diffused positions, wherein the slope of the target seed position satisfies the preset constraints; judging whether the diffusion termination condition is met; the diffusion termination condition includes at least one of the following: the number of diffusions reaches a preset number threshold, and\or, the number of target seed positions is greater than or equal to a preset number threshold; if not met, determining multiple diffused positions through the preset seed algorithm and the target seed position, and continuing to execute the step of determining the target seed position from the multiple diffused positions based on the terrain parameters corresponding to the multiple diffused positions until the preset diffusion termination condition is met; determining multiple target positions based on the initial seed position and the target seed position.
[0098] Optionally, the slope of the above-mentioned diffused position is represented by the normal direction at the diffused position; the constraint conditions include that the dot product result of the normal direction of the target seed position and the target normal direction is greater than a preset first threshold; the target normal direction is vertically upward; the step of determining the target seed position from multiple diffused positions, wherein the slope of the target seed position satisfies the preset constraint conditions, includes: for each diffused position among the multiple diffused positions, calculating the dot product result of the normal direction of the diffused position and the target normal direction; if the dot product result is greater than the first threshold, determining that the diffused position is the target seed position.
[0099] Optionally, the step of determining multiple diffused positions based on a preset seed algorithm and an initial seed position includes: determining multiple diffused positions corresponding to the initial seed position based on the initial seed position, multiple preset diffusion directions and diffusion distances through a preset seed algorithm.
[0100] Optionally, the above-mentioned multiple diffusion directions include at least two of the following: a first direction, a second direction, a third direction and a fourth direction along the terrain surface; the first direction is opposite to the second direction, the third direction is opposite to the fourth direction, and the first direction is perpendicular to the third direction.
[0101] Optionally, the step of determining multiple target positions based on the initial seed position and the target seed position includes: perturbing the initial position and the target seed position based on a preset disturbance scale to obtain a disturbed position; the disturbance scale is smaller than half of the distance between the initial position and the target seed position adjacent to the initial position; and determining the disturbed position as the target position.
[0102] Optionally, the above-mentioned virtual scene includes a first virtual building cluster, a second virtual building cluster and a third virtual building cluster; the first virtual building cluster has a first starting waypoint; the second virtual building cluster has a second starting waypoint; the third virtual building cluster has a third starting waypoint; the above-mentioned method also includes: determining a first target waypoint based on terrain parameters of the terrain surface, the first starting waypoint and the second starting waypoint; the first target waypoint constitutes a first virtual road between the first starting waypoint and the second starting waypoint; determining a second target waypoint based on the third starting waypoint and the first target waypoint; and the second target waypoint constitutes a second virtual road connected by the third starting waypoint and the first virtual road.
[0103] Optionally, the above-mentioned first target waypoint includes multiple; the step of determining the second target waypoint based on the third starting waypoint and the first target waypoint includes: determining the first waypoint closest to the third starting waypoint among the multiple first target waypoints; based on a preset pathfinding algorithm, determining the second target waypoint located between the third starting waypoint and the first waypoint.
[0104] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0105] In addition, in the description of the embodiments of the present disclosure, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For those skilled in the art, the specific meanings of the above terms in the present disclosure can be understood according to specific circumstances.
[0106] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0107] In the description of the present disclosure, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present disclosure and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation of the present disclosure. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0108] Finally, it should be noted that the above embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above embodiments, those skilled in the art should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A method for generating a virtual building cluster, characterized in that: The method comprises: Acquire a preset initial position; the initial position is located on the terrain surface of a preset virtual scene; Determine multiple target positions based on a preset seed algorithm, the initial position and preset constraints; the constraints are used to limit the slope of the target position; Virtual buildings are set at the multiple target locations to form a virtual building cluster.
2. The method according to claim 1, characterized in that The step of determining a plurality of target positions based on a preset seed algorithm, the initial position and preset constraints includes: Determining the initial position as an initial seed position; Based on a preset seed algorithm and the initial seed position, determining a plurality of diffusion positions; Determining a target seed position from the plurality of diffused positions, wherein the slope of the target seed position satisfies a preset constraint condition; Determine whether a diffusion termination condition is met; the diffusion termination condition includes at least one of the following: the diffusion times reaches a preset times threshold, and / or the number of the target seed positions is greater than or equal to a preset times threshold; If not, a plurality of diffusion positions are determined by a preset seed algorithm and the target seed position, and the step of determining the target seed position from the plurality of diffusion positions based on the terrain parameters corresponding to the plurality of diffusion positions is continued until a preset diffusion termination condition is met; Based on the initial seed position and the target seed position, a plurality of target positions are determined.
3. The method according to claim 2, characterized in that The slope of the diffused position is represented by the normal direction at the diffused position; the constraint condition includes that the dot product result of the normal direction of the target seed position and the target normal direction is greater than a preset first threshold; The target normal direction is vertically upward; The step of determining a target seed position from a plurality of diffusion positions comprises: For each of the plurality of diffused positions, calculating a dot product of a normal direction of the diffused position and a normal direction of the target; If the dot product result is greater than the first threshold, the diffused position is determined to be the target seed position.
4. The method according to claim 2, characterized in that: The step of determining a plurality of diffusion positions based on a preset seed algorithm and the initial seed position includes: A plurality of post-diffusion positions corresponding to the initial seed position are determined based on the initial seed position, a plurality of preset diffusion directions and diffusion distances through a preset seed algorithm.
5. The method according to claim 4, characterized in that The multiple diffusion directions include at least two of the following: a first direction, a second direction, a third direction and a fourth direction along the terrain surface; the first direction is opposite to the second direction, the third direction is opposite to the fourth direction, and the first direction is perpendicular to the third direction.
6. The method according to claim 2, characterized in that The step of determining a plurality of target positions based on the initial seed position and the target seed position comprises: Performing disturbance processing on the initial position and the target seed position based on a preset disturbance scale to obtain a disturbed position; the disturbance scale is smaller than half of the distance between the initial position and the target seed position adjacent to the initial position; The disturbed position is determined as the target position.
7. The method according to claim 1, characterized in that The virtual scene includes a first virtual building cluster, a second virtual building cluster and a third virtual building cluster; the first virtual building cluster has a first starting waypoint; The second virtual building cluster has a second starting waypoint; The third virtual building cluster has a third starting waypoint; The method further comprises: Determining a first target waypoint based on the terrain parameters of the terrain surface, the first starting waypoint and the second starting waypoint; the first target waypoint constitutes a first virtual road between the first starting waypoint and the second starting waypoint; Based on the third starting waypoint and the first target waypoint, a second target waypoint is determined; the second target waypoint constitutes a second virtual road connected by the third starting waypoint and the first virtual road.
8. The method according to claim 7, characterized in that The first target waypoints include a plurality of; The step of determining a second target waypoint based on the third starting waypoint and the first target waypoint includes: Determine a first waypoint among the plurality of first target waypoints that is closest to the third starting waypoint; Based on a preset path-finding algorithm, a second target waypoint located between the third starting waypoint and the first waypoint is determined.
9. A device for generating a virtual building cluster, characterized in that: The device comprises: An initial position acquisition module, used to acquire a preset initial position; the initial position is located on the terrain surface of a preset virtual scene; A target position determination module, used to determine multiple target positions based on a preset seed algorithm, the initial position and preset constraints; the constraints are used to limit the slope of the target position; The virtual building setting module is used to set virtual buildings at the multiple target locations to form a virtual building cluster.
10. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the method for generating a virtual building cluster according to any one of claims 1 to 8.
11. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the method for generating a virtual building cluster according to any one of claims 1 to 8.
Citation Information
Patent Citations
Method for determining gradient of geographical position of transmission line pole tower
CN102645204A
Vegetation generation method and device in virtual scene and electronic equipment
CN115518374A
Virtual scene generation method and device
CN115531883A
Virtual scene generation method and device, readable medium and electronic equipment
CN116416404A
Multi-target freight vehicle path planning method based on seed optimization algorithm
CN117129000A