Method, medium and device for procedural generation of a terrain city based on unreal engine
Through the Unreal Engine's procedural terrain and city generation method, the terrain points are initialized using Poisson Disk and Voronoi diagrams, combined with multi-scale noise and Gaussian blur processing, and terrain and city layout are generated in stages. This solves the problem of comprehensive processing of terrain and urban elements in existing technologies and realizes efficient and flexible city and terrain generation.
Patent Information
- Application Number
- CN202411866689.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-18
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2044-12-18
AI Technical Summary
Existing procedural generation methods have difficulty in simultaneously processing multiple elements such as terrain, urban planning, buildings, vegetation, etc. when generating large-scale terrain and urban layouts. They lack flexible adjustment capabilities, and it is difficult to achieve a balance between generation efficiency and quality.
A procedural terrain city generation method based on Unreal Engine is adopted. The terrain points are initialized through Poisson Disk and Voronoi diagram, and the landform features are calculated by combining multi-scale noise. The terrain and urban layout are processed in stages. The vegetation layout is generated using PCG Graph. Gaussian blur is used to process the urban area. The road network and plot information are calculated to generate urban decorative elements.
It improves the efficiency and controllability of large-scale scene generation, ensures natural and diverse terrain details, reasonable vegetation distribution, flexible adjustment of urban layout, supports real-time effect optimization, and improves design efficiency and user interaction experience.
Smart Images

Figure CN119830400B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer graphics, and in particular to a method, medium and device for procedurally generating a terrain city based on an Unreal Engine. Background Art
[0002] With the continuous development of computer graphics, virtual reality (VR), and augmented reality (AR) technologies, the construction of virtual environments has become a critical issue in many fields. In particular, in applications such as game development, architectural design, urban planning, and environmental simulation, the rapid and accurate generation of large-scale terrain and urban scenes has become crucial for improving production efficiency, reducing costs, and achieving high-quality virtual worlds.
[0003] Traditional scene modeling methods typically rely on manual design and editing. While this approach can ensure high-precision details, the generation process is cumbersome and time-consuming, making it impractical for building large-scale scenes. As scene complexity increases, especially for large-scale terrain and urban environments, manual modeling becomes both inefficient and difficult to adapt to the demands of real-time generation and dynamic adjustment. Therefore, developing a technology that can automatically generate terrain and urban scenes while supporting flexible customization and optimization has become a key goal of current technological development.
[0004] Procedural generation technology is an effective approach to addressing this problem. By defining a set of rules or algorithms to automatically generate large-scale scene content, it can significantly improve modeling efficiency and enhance scene diversity and realism. Especially when generating complex terrain and urban layouts, procedural generation not only reduces development costs but also ensures the coordination between scene elements. However, most existing procedural generation methods suffer from the following issues:
[0005] 1. Single-element generation: Many existing methods focus solely on the generation of terrain or urban layout, lacking a comprehensive generation framework. This makes it difficult to simultaneously address multiple elements, including terrain, urban planning, architecture, and vegetation. These methods often require separate treatment of terrain and urban design, lacking an effective integration of terrain and urban elements.
[0006] 2. Insufficient parameter adjustment capabilities: Traditional procedural generation methods generally lack comprehensive control and flexible adjustment capabilities over the generation process. While some methods support a certain degree of parameter adjustment, in practice, these methods lack sufficient dynamic adjustment space, resulting in a low degree of user customization of the generated results.
[0007] 3. Balancing generation efficiency and quality: In large-scale scene generation, generation algorithms need to balance efficiency and quality. Especially when dealing with complex terrain features and urban layouts, how to maintain the quality and details of the scene while ensuring generation speed remains a challenge.
[0008] To address these issues, researchers have recently explored combining advanced graphics engines (such as Unreal Engine) with procedural generation algorithms, proposing new generation frameworks and techniques. Unreal Engine, with its powerful graphics rendering capabilities and flexible development platform, has become a crucial tool for building virtual worlds. However, existing Unreal Engine-based procedural generation methods still face challenges in maintaining efficiency while ensuring scene quality, detail, and flexibility when dealing with large-scale terrain and urban features. Summary of the Invention
[0009] In view of the defects in the prior art, the purpose of the present invention is to provide a method, medium and equipment for procedural generation of terrain cities based on Unreal Engine.
[0010] The method for procedurally generating a terrain city based on Unreal Engine provided by the present invention includes:
[0011] Step 1: Initialize terrain points based on Poisson Disk sampling and Voronoi diagram;
[0012] Step 2: Calculate the elevation information of peaks and hills by mixing multi-scale noise;
[0013] Step 3: Sampling and generating surface vegetation layout information;
[0014] Step 4: Calculate the city generation area based on terrain information;
[0015] Step 5: Calculate and generate urban road network information;
[0016] Step 6: Calculate the polygon information of the plot and divide the layout information of houses and green spaces;
[0017] Step 7: Calculate the remaining city decoration element information.
[0018] Preferably, the step 1 comprises:
[0019] Two types of point sets, common terrain points and local peak points, are generated based on the Poisson Disk sampling method. Specifically, random points are generated on a two-dimensional plane. During the generation process, Poisson Disk sampling ensures that a certain distance is maintained between the generated points by setting a minimum distance parameter.
[0020] According to the existing point set, the Delaunay triangulation algorithm is used to construct a Voronoi diagram on the two-dimensional plane, and the initial Dual-Mesh data structure for terrain generation is constructed. Among them, triangles are used to describe the geometric structure of the terrain, and dual polygons are used to describe the logical results of the terrain.
[0021] Preferably, the step 2 includes:
[0022] Input multi-scale noise information and mix them;
[0023] Calculate the altitude and humidity information of local peak points based on the sampling results of mixed noise and combined with parameter settings;
[0024] Interpolate the altitude and humidity information of common terrain points based on local peak point information;
[0025] Generate grids and perform mapping based on altitude and humidity information;
[0026] Among them, high-frequency noise is used to describe the characteristics of mountain peaks, and low-frequency noise is used to describe the characteristics of hills and basins. Noises of multiple scales are mixed together to generate details of multiple scales on the surface.
[0027] Preferably, the step 3 includes:
[0028] Calculate surface vegetation layout information of different terrain types based on PCG Graph;
[0029] Calculate and set the terrain vegetation layout type based on altitude, humidity and parameter setting information;
[0030] Among them, the PCG Graph based on UE5 performs point sampling on the surface area, and by adjusting the sampling density parameter information, calculates the vegetation layout suitable for different surface types, and finally generates surface vegetation layout information that matches the terrain characteristics, ensuring that the generated surface scene is natural and diverse.
[0031] Preferably, step 4 includes:
[0032] Calculate the slope of each point: Calculate the height difference between each point (i, j) and its four neighbors:
[0033] Horizontal gradient: dx = (height_map[i+1][j] - height_map[i-1][j]) / 2;
[0034] Vertical gradient: dy = (height_map[i][j+1] - height_map[i][j-1]) / 2;
[0035] Among them, height_map[i+1][j] represents the height of point (i+1, j);
[0036] Then calculate the slope at each point:
[0037] If the slope is less than the set threshold, the point is considered to belong to a flat area; otherwise, the point is considered to be an area not suitable for urban construction;
[0038] Generate a binary array mask of the same size as the input height map, where the value of the flat area is 1 and the non-flat area is 0;
[0039] In manual generation mode, users manually define the city generation area by drawing a closed curve on the terrain map. The system generates the corresponding city area mask based on the curve drawn by the user, and directly marks the construction area specified by the user;
[0040] The generated urban area mask is Gaussian blurred. Gaussian blur gradually transitions the value of the area edge from 1 in the center area to 0 in the edge area, thereby softening the area boundary. The urban area mask after Gaussian blur processing will be used as the input of the subsequent city generation pipeline to calculate the urban road network, building distribution and green space layout.
[0041] By analyzing the terrain data of the area covered by the Mask, the terrain points with significant height differences are adjusted to make the terrain surface smoother while maintaining a natural transition between the edge of the area and the surrounding terrain.
[0042] Preferably, the step 5 includes:
[0043] Perform sampling based on the Gaussian blurred Mask to find the road direction;
[0044] Randomly generate bypass information based on preset rules and set main and secondary roads;
[0045] Conduct rationality checks and connectivity processing on road sections;
[0046] At the end of the road network generation, a road connectivity check is performed. After the road growth and expansion are completed, a procedural grid is generated based on the preset road width and road category information.
[0047] Preferably, step 6 includes:
[0048] A vector closure algorithm is used for land parcel detection and generation. Vectors with opposite directions are generated on both sides of each road segment. If these vectors can form a closed area, the area is considered a land parcel. This method effectively identifies and constructs land parcel polygons, laying the foundation for the subsequent layout of buildings and green spaces. Within the land parcel polygons, a key vertical polygon segmentation algorithm is used for further segmentation to obtain sub-polygon information.
[0049] Calculate housing polygons and urban green space polygons based on polygon partitioning algorithm;
[0050] Calculate the layout information of green space trees and shrubs according to parameter settings and sampling specifications.
[0051] Preferably, the step 7 includes:
[0052] Based on road information, the relative position of vehicle flow lines is calculated using the road section location and road width parameters. The corresponding mesh is generated using Procedural Mesh, and the flow line map is set to achieve the layout of vehicle flow lines.
[0053] Based on the city plot information, the layout of the sidewalk is generated according to the location information of the plot polygons and the preset sidewalk width and height parameters. The corresponding mesh is created through Procedural Mesh and the sidewalk texture is set to complete the generation of the sidewalk.
[0054] Calculate the layout of streetlights along arterial roads based on the location information and sampling intervals of urban land polygons. This includes determining the location and rotation of streetlights and passing this information to downstream asset generation nodes to generate a complete streetlight layout.
[0055] Using the location information of the parcel polygons and the sampling interval, the position and rotation information of trees along the main road are calculated. The calculation results are then passed to the asset generation node to generate the tree layout along the main road, further enriching the city's green features.
[0056] Through the adjacent plot detection algorithm, adjacent plot pairs are identified, the location information of the zebra crossing is calculated between adjacent edges, and the corresponding mesh is generated using Procedural Mesh. The zebra crossing map is set to realize the generation of the zebra crossing layout;
[0057] Based on the zebra crossing layout information and the detection results of adjacent plots, the position and rotation information of the traffic light are calculated. The generated position of the traffic light is passed to the asset generation node to complete the traffic light layout;
[0058] Based on the location information of the land polygons and the sampling density parameters, the location and rotation information of the fire hydrants are calculated. The final result is passed to the asset generation node to generate the layout of the city fire hydrants.
[0059] The computer readable storage medium storing the computer program is provided according to the application, and the computer program is executed by a processor to implement the steps of the procedural generation method of a terrain city based on Unreal Engine.
[0060] The electronic device is provided according to the application, and includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is executed by the processor to implement the steps of the procedural generation method of a terrain city based on Unreal Engine.
[0061] Compared with the prior art, the application has the following beneficial effects:
[0062] (1) The application adopts a phased processing method, and the terrain generation and city planning are processed separately in two stages to solve the problems of terrain features and city layout respectively, thereby improving the efficiency and controllability of large-scale scene generation;
[0063] (2) The application initializes the terrain points by Poisson Disk and Veno diagram, and calculates the elevation information of landforms such as mountains and hills in combination with multi-scale noise, so as to accurately describe complex terrain features, ensure the naturalness and diversity of terrain details, and improve the realism of the generated terrain;
[0064] (3) The application generates ground vegetation layout information by sampling, and classifies according to rules such as elevation and humidity to generate vegetation layout conforming to terrain features for each region, so as to ensure the rationality and naturalness of ground plant distribution;
[0065] (4) The application realizes flexible adjustment of city area, road network, land block and green land layout by dynamic parameter control, and users can easily adjust the city generation effect according to requirements, thereby improving the efficiency and flexibility of design;
[0066] (5) The application uses random number seeds and parameterized control to enable the system to quickly generate all-element content in a large-scale scene, support real-time adjustment of generation effect, and greatly improve the design efficiency and user interaction experience. BRIEF DESCRIPTION OF DRAWINGS
[0067] Other features, objects and advantages of the application will become more apparent after reading the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0068] Figure 1 The figure shows the overall flowchart of the procedural generation method of a terrain city based on Unreal Engine in the application example. DETAILED DESCRIPTION
[0069] The present invention will be described in detail below with reference to specific embodiments. The following examples will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those skilled in the art, several changes and improvements can be made without departing from the scope of the present invention. These all fall within the scope of protection of the present invention.
[0070] Example
[0071] Specifically, if Figure 1 As shown, this embodiment provides a method for procedurally generating a terrain city based on the Unreal Engine, and the method for procedurally generating a terrain city based on the Unreal Engine includes:
[0072] Step S11, initializing terrain points based on Poisson Disk and Voronoi diagram;
[0073] Step S12, calculating the altitude and other information of landforms such as mountains and hills by mixing multi-scale noise;
[0074] Step S13, sampling and generating surface vegetation layout information;
[0075] Step S14, calculating the city generation area;
[0076] Step S15, calculating and generating urban road network information;
[0077] Step S16, calculating the polygon information of the plot and dividing the layout information of houses and green spaces;
[0078] Step S17: Calculate the remaining city decoration element information.
[0079] The following describes in detail steps S11 to S17 of the Unreal Engine-based method for procedurally generating a terrain city in this embodiment with reference to the accompanying diagrams:
[0080] Step S11 : Initializing terrain points based on Poisson Disk and Voronoi diagram.
[0081] 1) Generate two types of point sets: general terrain points and local peak points
[0082] Poisson Disk sampling is used here. It is an effective method for generating random points on a two-dimensional plane, aiming to ensure that the generated point set is evenly distributed and not densely packed. This method is particularly suitable for terrain generation, effectively describing the diversity and complexity of terrain. During the generation process, Poisson Disk sampling ensures a certain spacing between generated points by setting a minimum distance parameter, thus avoiding excessive point clustering. This spacing not only increases the diversity of the samples but also enables the generated points to better reflect the characteristics of the natural terrain. The generated point set is divided into two categories: common terrain points and local peak points. These peak points are important topographic features in the overall terrain. They not only determine the contour and shape of the terrain but also influence the details generated subsequently.
[0083] 2) Dual-Mesh structure construction
[0084] Based on the existing point set, the Delaunay triangulation algorithm is used to construct a Voronoi diagram on a two-dimensional plane, creating the initial Dual-Mesh data structure for terrain generation. This dual representation method uses triangles to describe the terrain's geometric structure, while dual polygons describe the terrain's logical characteristics, such as altitude and humidity, making data organization more efficient. This dual-mesh representation allows for interpolation and conversion between the two data structures, supporting accurate modeling of complex terrains and enabling flexible querying and processing of attribute data. This design enhances the expressive power and application potential of terrain models.
[0085] Step S12, calculating the altitude and other information of landforms such as mountains and hills by mixing multi-scale noise.
[0086] The method of constructing global terrain features adopts a variety of noise aliasing methods. In actual processing, this project uses high-frequency noise to describe the characteristics of mountain peaks, and low-frequency noise to describe the characteristics of hills and basins. The noise of multiple scales is mixed together to generate details of multiple scales on the surface. The change of phase will cause the noise function to shift in space, thereby changing the appearance of the generated terrain. Superimposing noise with different phases can increase the randomness of the terrain and make it look more natural. Users can adjust and control the degree of peaks and hills of the overall terrain according to the UI panel. The two can respectively represent the final contribution of low-frequency noise and high-frequency noise to the altitude of a peak point. The formula is as follows:
[0087] elevation peak =samplingValue m *e m +samplingValue h *e h
[0088] Among them, samplingValue m with samplingValue h Represent the sampling results of high-frequency noise and low-frequency noise respectively, e m With e h They represent the peak degree and hill degree of the global terrain that can be adjusted by the UI respectively. Finally, the information of the global terrain point can be obtained by interpolating the information of the peak point.
[0089] In addition, the terrain generation system also supports manual editing to meet the user's local adjustment needs. The system supports setting a certain hardness and strength of the blueprint brush, and by fine-tuning the height information, the generated terrain can be adjusted in real time. Landforms such as lakes and rivers can adapt to the altitude.
[0090] Step S13: Calculate and generate surface vegetation layout information.
[0091] This method implements vegetation layout features for three different surface types: desert, forest, and snow. Based on UE5's PCG Graph, point sampling is performed on the surface area. By adjusting parameters such as sampling density, vegetation layouts suitable for different surface types are calculated. Ultimately, surface vegetation layout information is generated that matches the terrain characteristics, ensuring the naturalness and diversity of the generated surface scenes.
[0092] Step S14: Calculate the city generation area.
[0093] The first step in city generation is to determine the generation area. The core task of this step is to calculate the area suitable for city construction based on the terrain information. The specific process is as follows:
[0094] 1) Automatic generation mode: calculated based on terrain slope
[0095] In automatic generation mode, the system calculates the slope (steepness) of each surface point by analyzing the terrain data generated upstream. The terrain slope value reflects the undulations of the surface. A smaller slope value indicates a relatively flat terrain, which is suitable for urban construction. Based on the preset threshold, the system automatically identifies areas with smaller slopes and generates corresponding urban area masks, marking them as target areas suitable for construction. At the same time, areas with larger slopes are excluded to ensure that the generated area meets planning requirements.
[0096] The specific calculation method is as follows:
[0097] 1. Calculate the slope (height difference) of each point: We calculate the height difference between each point and its four neighbors:
[0098] Horizontal gradient: dx = (height_map[i+1][j] - height_map[i-1][j]) / 2;
[0099] Vertical gradient: dy = (height_map[i][j+1] - height_map[i][j-1]) / 2;
[0100] The slope (magnitude of the gradient) can then be calculated for each point:
[0101]
[0102] 2. Mark the flat area:
[0103] If the slope is less than the set threshold, the point is considered to belong to the flat area.
[0104] Otherwise, the point is considered an area unsuitable for urban construction.
[0105] 3. Output the mask of the flat area:
[0106] Generates a binary array mask of the same size as the input heightmap, where the value is 1 for flat areas and 0 for non-flat areas.
[0107] 2) Manual generation mode: user-defined area
[0108] In manual generation mode, users manually define the city generation area by drawing a closed curve on the terrain map. The system generates a corresponding city mask based on the user-drawn curve, directly marking the user-specified construction area. This mode does not rely on terrain slope calculations and completely defines the city area based on the user's intent.
[0109] 3) Gaussian blur processing
[0110] Whether automatically generated or manually defined, the system applies a Gaussian blur to the generated urban area mask. This Gaussian blur gradually transitions the value of the area edge from 1 (center area) to 0 (edge area), softening the area boundary. This process creates a natural transition between the generated urban area and the non-development area, avoiding illogical layouts caused by hard boundaries.
[0111] 4) Regional input and subsequent processes
[0112] The Gaussian-blurred urban area mask serves as input to the subsequent city generation pipeline, calculating elements such as the urban road network, building distribution, and green space layout. This process not only ensures precise control of city boundaries but also ensures that the generated urban structure matches the terrain characteristics, avoiding exceeding the suitable construction area.
[0113] Using this method, the system accurately delineates city generation areas based on the user's selected mode. Automatic mode utilizes terrain slope calculations to ensure scientific planning, while manual mode offers flexibility and supports user customization. Gaussian blurring further optimizes boundary transitions, ensuring a reasonable city layout that conforms to the actual terrain.
[0114] 5) Post-processing of terrain based on urban areas
[0115] Based on the generated urban area mask, the system flattens the terrain within the area to ensure that the urban construction area has smooth terrain conditions. Specifically, the system analyzes the terrain data of the area covered by the mask and adjusts terrain points with significant elevation differences to smooth the terrain surface while maintaining a natural transition between the area's edges and the surrounding terrain. Through this processing step, the system can effectively ensure that the urban generation area is located on flat ground, providing a reliable terrain foundation for the subsequent layout and generation of urban structures.
[0116] Step S15: Calculate and generate urban road network information.
[0117] In the city generation process, the construction of the urban road network is a crucial step. This step calculates the road layout within the urban area and forms a road network structure suitable for urban planning. The specific process is as follows:
[0118] 1) Input urban area Mask for sampling
[0119] First, the system performs sampling based on the input urban area mask information. This mask defines the boundaries of the urban area, and after Gaussian blurring, a smooth boundary region is formed. Sampling points are selected according to specific rules, mainly based on the size of the sample value, with areas with smaller sample values being preferred as the starting points of the road. This ensures that the road is built within a relatively flat area suitable for construction.
[0120] 2) Road growth and priority queue management
[0121] The core method of road growth is to use a priority queue to determine the direction of expansion. Each time the system grows, it starts from the end of the current road segment (end point p2) and calculates and selects the growth direction of the next road segment. Based on preset parameters, the system will evaluate multiple possible road growth directions and select the direction with a smaller sampling value and in line with planning requirements to expand the new road segment. In this process, the priority queue is sorted based on factors including the sampling value of the current road direction, the curvature of the road, and the distance from the existing road. After considering these factors comprehensively, it can be ensured that the generated road network not only conforms to the terrain characteristics, but also has a certain degree of randomness and naturalness. The growth of the road is carried out step by step. Whenever a new road segment is expanded, it will be added to the priority queue to continue calculating the next expansion direction. The sorting comparison formula of the priority queue is:
[0122] priorityValue=pointValue(roadMiddle)+detriment
[0123] The calculation formula for detriment is:
[0124]
[0125] The function of detriment is to optimize the global road network layout and prevent the distances between main roads from being too close. Through this design, the system can generate a reasonable road layout, balance the distances between main roads, and optimize the overall road network structure. priorityValue indicates that the processing priority of a road segment is determined by its weight, and sections with lower weights are processed first. roadMiddle indicates that since a road segment is represented by a line segment, the midpoint of the line segment is used as the noise sampling point when sampling the noise information of the road segment. detriment indicates that since road segments cannot be too close to each other, a penalty weight is set. If a road segment is surrounded by many sections, it has a larger penalty weight. detrimentRange indicates the range in which the penalty item is effective. detrimentImpact indicates the weight coefficient of the penalty item. road indicates the location of the road segment, where the midpoint of the road segment is used to represent the road segment location. roads indicates all sections within the detrimentRange of the current section. num_roads indicates the total number of sections. n indicates the current number of iterations.
[0126] 3) Road curvature control and diversity generation
[0127] To prevent the generated roads from being too regular, the system allows for control over the curvature of the roads. Specifically, users can adjust the curvature weight of the roads through the UI panel to determine the degree of offset during road growth. During the expansion process, the system will attempt to generate new road segments by offsetting the previous road segment by a certain angle based on the current direction and maximum angle variation of the road. By adjusting the curvature weight, you can control whether the generated roads are straighter or more curved, thereby increasing the complexity and diversity of the road network.
[0128] 4) Road network structure characteristics and intersection generation
[0129] In order to enhance the richness and feasibility of the urban road network, the system will also add a certain probability of bypass generation when generating the road network. For example, in the middle part of the road, vertical bypasses will be randomly generated according to certain rules to form crossroads or T-junctions. These intersections can further enrich the city's road network structure, avoid an overly monotonous road layout, and provide greater traffic convenience. In this process, the system will divide the forks in the road network into main roads and secondary roads based on certain rules and random numbers. Main roads usually connect the core areas of the city and carry the main traffic flow, while secondary roads are used to connect the main roads with surrounding areas, forming a hierarchical road network structure.
[0130] 5) Avoid inspections and adjustments where roads are too close to each other
[0131] During the road network generation process, the system also checks the spacing between adjacent roads to prevent them from being too close together. During this process, the system performs a "midpoint check" on each newly added road segment. This means that each time a new road segment is added, it checks whether it is too close to an existing segment. If the system detects that the distance between roads is too small, it adjusts the position or growth direction of the road segment to ensure appropriate spacing between roads.
[0132] 6) Road connectivity and extension detection
[0133] At the end of the road network generation, the system performs a road connectivity check. Specifically, for each terminal road segment, the system attempts to extend it and checks whether it intersects with other road segments. If an intersection is detected between two roads, the system automatically extends one of the roads and connects them, thus ensuring the integrity and connectivity of the urban road network.
[0134] 7) Generate procedural grids and distinguish between primary and secondary roads
[0135] After the road growth and expansion is completed, the system generates a procedural mesh based on the preset road width, road category and other information.
[0136] Step S16: Calculate the polygon information of the plot and divide the layout information of houses and green spaces.
[0137] Land parcel detection and generation utilizes a vector closure algorithm. Vectors with opposite directions are generated on either side of each road segment. If these vectors form a closed region, the region is considered a land parcel. This method effectively identifies and constructs land parcel polygons, laying the foundation for subsequent building and green space layout. Within the land parcel polygons, the system further segments them into sub-polygons using a key vertical polygon segmentation algorithm.
[0138] Subdivision is determined based on the plot's size and a specific random number rule. These polygons are then processed as building blocks, with a certain probability of being transformed into green space. Within these green spaces, the system will randomly place trees, shrubs, and flowers, enhancing the natural atmosphere and aesthetics of the urban environment.
[0139] Step S17: Calculate the remaining city decoration element information.
[0140] 1) Calculation of vehicle flow line layout information
[0141] Based on road information, the system calculates the relative position of vehicle flow lines using parameters such as road segment location and road width. It then uses Procedural Mesh to generate the corresponding mesh and sets a flow line map to achieve the layout of the vehicle flow lines.
[0142] The specific processing method is to calculate the following based on the number of lanes, the width of each road section, and the size (length and width) and spacing of the vehicle guide lines:
[0143] 1. Vertical layout: By dividing the road section length by the sum of the length and spacing of the vehicle guide line, calculate the number of rectangles required to represent the vehicle guide line polygon in the vertical direction.
[0144] 2. Horizontal layout: By dividing the road section width by the sum of the width and spacing of the vehicle guide line, calculate the number of rectangles required to represent the vehicle guide line polygon in the horizontal direction.
[0145] Finally, the system saves the polygon information and uses Procedural Mesh technology to generate the corresponding mesh, while setting the drainage line map to complete the layout.
[0146] 2) Calculation of sidewalk layout information
[0147] Based on the city plot information, the system generates the sidewalk layout according to the location information of the plot polygons and the preset sidewalk width and height parameters. The corresponding mesh is created through Procedural Mesh and the sidewalk texture is set to complete the sidewalk generation.
[0148] The specific processing methods are:
[0149] 1. Extracting plot information: The system first obtains the location information of the global plot polygon and extracts the vertex coordinates of each plot.
[0150] 2. Calculate sidewalk dimensions: Calculate the polygonal organization information and vertex positions of each sidewalk based on the sidewalk width and height parameters specified by the user.
[0151] 3. Mesh generation: Combined with Procedural Mesh technology, the vertex positions and preset sizes of the plot polygons are used to generate the corresponding sidewalk mesh.
[0152] 4. Texture design and application: Design a texture that suits the characteristics of the sidewalk and apply it to the generated grid to complete the layout of the sidewalk.
[0153] 3) Calculation of street light layout information along the trunk road
[0154] The system calculates the layout of streetlights along arterial roads based on the location information and sampling intervals of urban parcel polygons. This involves determining the position and rotation of streetlights and passing this information to downstream asset generation nodes to generate the complete streetlight layout.
[0155] The specific processing methods are:
[0156] 1. Extracting plot information: The system first obtains the location information of the global plot polygon and extracts the boundary data of the polygon to determine the scope of the street light layout.
[0157] 2. Uniform Sampling: Samples are taken at uniform intervals along the edges of the polygon. The sampling interval is determined by user-entered parameters. Each sampling point represents a potential location for streetlight installation.
[0158] 3. Calculate streetlight rotation information: Based on the direction of the polygon edges and the location of the sampling points, the rotation angle of each streetlight is calculated. This rotation information ensures that the streetlight faces the correct direction, meeting the actual requirements of urban layout.
[0159] 4. Output position and rotation information: The sampled streetlight positions and calculated rotation information are passed to the downstream asset generation node for subsequent generation of the complete streetlight layout and related assets.
[0160] 4) Calculation of tree layout information along main roads
[0161] The system utilizes the position information of the plot polygons and combines the sampling interval to calculate the position and rotation information of the trees along the road. The calculation results will be passed to the asset generation node to generate the tree layout along the road, further enriching the green features of the city.
[0162] The specific processing method is:
[0163] 1. Extract plot information: The system first obtains the position information of the global plot polygons, extracts the boundary data of the polygons, and determines the range of the streetlight layout.
[0164] 2. Uniform sampling: Uniform and equal-interval sampling is performed on the edges of the polygon. The sampling interval is determined by the user input parameter. Each sampling point is a potential installation location for the tree.
[0165] 3. Calculate the rotation information of the trees along the road: According to the direction of the polygon edge and the position of the sampling point, calculate the rotation angle (Rotation) of each streetlight. This rotation information ensures that the streetlight is oriented in the correct direction, meeting the actual needs of the city layout.
[0166] 4. Output position and rotation information: Pass the tree position obtained by sampling and the calculated rotation information to the downstream asset generation node for subsequent generation of complete tree layout and related assets.
[0167] 5) Zebra crossing layout information calculation
[0168] The system identifies adjacent plot pairs through the adjacent plot detection algorithm. Calculate the position information of the zebra crossing between adjacent edges, and use Procedural Mesh to generate the corresponding mesh, set the zebra crossing map to achieve the generation of zebra crossing layout.
[0169] The specific processing method is:
[0170] 1. Adjacent plot determination: According to the position information of the global plot polygons, take polygon A as an example, check the distance between each edge of A and the edges of other polygons.
[0171] If the distance between the edges of two polygons is less than the preset road width, then the two plots are adjacent.
[0172] 2. Zebra crossing position calculation: After determining the adjacent plots, the system calculates the position of the zebra crossing according to the interval of the zebra crossing, the road width, and the length of the zebra crossing
[0173] 3. Map design and application: Attach a map that meets the characteristics of the zebra crossing and apply it to the generated mesh to complete the zebra crossing layout.
[0174] 6) Red light layout information calculation
[0175] The system calculates the position and rotation information of the traffic light according to the zebra crossing layout information combined with the detection results of adjacent plots. The generated position of the traffic light is passed to the asset generation node to complete the traffic light layout.
[0176] The specific processing method is:
[0177] 1. Plot adjacent judgment: According to the position information of the global plot polygon, take polygon A as an example, check the distance between each edge of A and the edge of other polygons.
[0178] For each edge of polygon A, check the distance between it and the edge of other polygons.
[0179] If the distance between the edges of two polygons is less than the preset road width, it is considered that the two plots are adjacent.
[0180] 2. Traffic light position calculation: After determining the adjacent plots, the system calculates the position and rotation of the zebra crossing according to the following parameters
[0181] According to the width of the road and the direction of the road section, the specific position of the traffic light is calculated.
[0182] The position of the traffic light will be set on both sides of the road, and the direction will be opposite.
[0183] Combined with the direction of the road and the road width, the rotation angle of the traffic light is calculated to ensure the correct orientation of the traffic light.
[0184] 3. Generation and transmission: The position information and rotation angle of the traffic light will be passed to the asset generation node to complete the layout generation of the traffic light.
[0185] 7) Fire hydrant layout information calculation
[0186] The system calculates the position and rotation information of the fire hydrant according to the position information of the plot polygon and the sampling density parameter. The final result is passed to the asset generation node to generate the layout of the city fire hydrant.
[0187] 1. Extract plot information: The system first obtains the position information of the global plot polygon, extracts the boundary data of the polygon to determine the range of street lamp layout.
[0188] 2. Random sampling: Random sampling is performed on the edges of the polygon. The sampling frequency is determined by the user input parameter. Each sampling point is a potential generation position of the fire hydrant.
[0189] 3. Calculate the rotation information of the fire hydrant: According to the direction of the polygon edge and the position of the sampling point, calculate the rotation angle of each fire hydrant. This rotation information ensures that the fire hydrant is oriented in the correct direction, meeting the actual needs of urban layout.
[0190] 4. Output position and rotation information: The sampled fire hydrant position and calculated rotation information are passed to the downstream asset generation node for subsequent generation of the complete fire hydrant layout and related assets.
[0191] The Unreal Engine-based procedural generation method for terrain cities of the present invention achieves efficient and flexible city and terrain generation through a two-stage process. First, terrain points are initialized through Poisson Disk and Voronoi diagrams, and multi-scale noise is combined to generate landform features such as mountains and hills and their altitude, humidity and other information, so that natural and complex terrain can be quickly created. Secondly, on this basis, urban areas, road networks, land layouts, housing and green space distribution and other decorative elements are automatically generated, which greatly simplifies the complexity of urban planning and design. Compared with traditional methods, the present invention enables users to adjust generation parameters in real time through parametric design and random number seed settings, dynamically optimize scene effects, improve design efficiency and flexibility, and can quickly generate large-scale, full-factor urban terrain scenes that meet expectations, with significant technical advantages.
[0192] Those skilled in the art will appreciate that, in addition to implementing the system, device, and various modules provided by the present invention in purely computer-readable program code, it is entirely possible to implement the same program in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, embedded microcontrollers, and the like by logically programming the method steps. Therefore, the system, device, and various modules provided by the present invention can be considered a hardware component, and the modules included therein for implementing various programs can also be considered structures within the hardware component; the modules for implementing various functions can also be considered both software programs for implementing the method and structures within the hardware component.
[0193] The above describes specific embodiments of the present invention. It should be understood that the present invention is not limited to the specific embodiments described above, and those skilled in the art may make various changes or modifications within the scope of the claims, which do not affect the essence of the present invention. The embodiments of this application and the features in the embodiments may be combined with each other in any manner unless there is a conflict.
Claims
1. A method for procedurally generating terrain cities based on Unreal Engine, characterized in that: include: Step 1: Generate initial terrain points based on Poisson Disk sampling and Voronoi diagram; Step 2: Calculate the elevation information of peaks and hills by mixing multi-scale noise; Step 3: Sampling and generating surface vegetation layout information; Step 4: Calculate the city generation area based on terrain information; Step 5: Calculate and generate urban road network information; Step 6: Calculate the polygon information of the plot and divide the layout information of houses and green spaces; Step 7: Calculate the remaining city decoration element information; The step 4 comprises: 1) Automatic generation mode: calculated based on terrain slope; Calculate the slope of each point: Calculate the height difference between each point (i, j) and its four neighbors: Horizontal gradient: =(height_map[i+1][j]-height_map[i-1][j]) / 2; Vertical Gradient: =(height_map[i][j+1]-height_map[i][j-1]) / 2; Among them, height_map[i+1][j] represents the height of point (i+1, j); Then calculate the slope at each point: ; If the slope is less than the set threshold, the point is considered to belong to a flat area; otherwise, the point is considered to be an area not suitable for urban construction; Generate a binary array mask of the same size as the input height map, where the value of the flat area is 1 and the non-flat area is 0; 2) Manual generation mode: user-defined area; In manual generation mode, users manually define the city generation area by drawing a closed curve on the terrain map. The system generates the corresponding city area mask based on the curve drawn by the user, and directly marks the construction area specified by the user; 3) Gaussian blur processing; The generated urban area mask is Gaussian blurred. Gaussian blur gradually transitions the value of the area edge from 1 in the center area to 0 in the edge area, thereby softening the area boundary. The urban area mask after Gaussian blur processing will be used as the input of the subsequent city generation pipeline to calculate the urban road network, building distribution and green space layout. By analyzing the terrain data of the area covered by the Mask, the terrain points with significant height differences are adjusted to make the terrain surface smoother while maintaining a natural transition between the edge of the area and the surrounding terrain.
2. The method for procedurally generating a terrain city based on Unreal Engine according to claim 1, characterized in that: The step 1 comprises: Two types of point sets, common terrain points and local peak points, are generated based on the Poisson Disk sampling method. Specifically, random points are generated on a two-dimensional plane. During the generation process, Poisson Disk sampling ensures that a certain distance is maintained between the generated points by setting a minimum distance parameter. According to the existing point set, the Delaunay triangulation algorithm is used to construct a Voronoi diagram on the two-dimensional plane, and the initial Dual-Mesh data structure for terrain generation is constructed. Among them, triangles are used to describe the geometric structure of the terrain, and dual polygons are used to describe the logical results of the terrain.
3. The method for procedurally generating a terrain city based on Unreal Engine according to claim 1, characterized in that: The step 2 includes: Input multi-scale noise information and mix them; Calculate the altitude and humidity information of local peak points based on the sampling results of mixed noise and combined with parameter settings; Interpolate the altitude and humidity information of common terrain points based on local peak point information; Generate grids and perform mapping based on altitude and humidity information; Among them, high-frequency noise is used to describe the characteristics of mountain peaks, and low-frequency noise is used to describe the characteristics of hills and basins. Noises of multiple scales are mixed together to generate details of multiple scales on the surface.
4. The method for procedurally generating a terrain city based on Unreal Engine according to claim 1, characterized in that: The step 3 includes: Calculate surface vegetation layout information of different terrain types based on PCG Graph; Calculate and set the terrain vegetation layout type based on altitude, humidity and parameter setting information; Among them, the PCG Graph based on UE5 performs point sampling on the surface area, and by adjusting the sampling density parameter information, calculates the vegetation layout suitable for different surface types, and finally generates surface vegetation layout information that matches the terrain characteristics, ensuring that the generated surface scene is natural and diverse.
5. The method for procedurally generating a terrain city based on Unreal Engine according to claim 1, characterized in that: The step 5 comprises: Perform sampling based on the Gaussian blurred Mask to find the road direction; Randomly generate bypass information based on preset rules and set main and secondary roads; Conduct rationality checks and connectivity processing on road sections; At the end of the road network generation, a road connectivity check is performed. After the road growth and expansion are completed, a procedural grid is generated based on the preset road width and road category information.
6. The method for procedurally generating a terrain city based on Unreal Engine according to claim 1, characterized in that: The step 6 comprises: A vector closure algorithm is used for land parcel detection and generation. Vectors with opposite directions are generated on both sides of each road segment. If these vectors can form a closed area, the area is considered a land parcel. This method effectively identifies and constructs land parcel polygons, laying the foundation for the subsequent layout of buildings and green spaces. Within the land parcel polygons, a key vertical polygon segmentation algorithm is used for further segmentation to obtain sub-polygon information. Calculate housing polygons and urban green space polygons based on polygon partitioning algorithm; Calculate the layout information of green space trees and shrubs according to parameter settings and sampling specifications.
7. The method for procedurally generating a terrain city based on Unreal Engine according to claim 1, characterized in that: The step 7 comprises: Based on road information, the relative position of vehicle flow lines is calculated using the road section location and road width parameters. The corresponding mesh is generated using Procedural Mesh, and the flow line map is set to achieve the layout of vehicle flow lines. Based on the city plot information, the layout of the sidewalk is generated according to the location information of the plot polygons and the preset sidewalk width and height parameters. The corresponding mesh is created through Procedural Mesh and the sidewalk texture is set to complete the generation of the sidewalk. Calculate the layout of streetlights along arterial roads based on the location information and sampling intervals of urban land polygons. This includes determining the location and rotation of streetlights and passing this information to downstream asset generation nodes to generate a complete streetlight layout. Using the location information of the parcel polygons and the sampling interval, the position and rotation information of trees along the main road are calculated. The calculation results are then passed to the asset generation node to generate the tree layout along the main road, further enriching the city's green features. Through the adjacent plot detection algorithm, adjacent plot pairs are identified, the location information of the zebra crossing is calculated between adjacent edges, and the corresponding mesh is generated using Procedural Mesh. The zebra crossing map is set to realize the generation of the zebra crossing layout; Based on the zebra crossing layout information and the detection results of adjacent plots, the position and rotation information of the traffic light are calculated. The generated position of the traffic light is passed to the asset generation node to complete the traffic light layout; Based on the location information of the land polygons and the sampling density parameters, the location and rotation information of the fire hydrants are calculated. The final result is passed to the asset generation node to generate the layout of the city fire hydrants.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method for procedurally generating a terrain city based on an Unreal Engine according to any one of claims 1 to 7 are implemented.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the computer program is executed by a processor, the steps of the method for procedurally generating a terrain city based on an Unreal Engine according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Method for high-precision reverse time migration imaging based on severe relief surface ground penetrating radar data
CN106707277A
Scene line virtual design system
CN118196353A