A virtual terrain generation method, system, storage medium and electronic device
Patent Information
- Application Number
- CN202211136190.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-19
- Publication Date
- 2026-10-16
- Estimated Expiration
- 2042-09-19
AI Technical Summary
[0003]通过地形生成算法在3D虚拟场景中实现虚拟地形生成的方式多种多样,但是要实现在3D虚拟场景中虚拟地形生成会涉及到3D引擎各个方面,包括底层场景管理,光照模型,底层Shader,底层物理碰撞,粒子系统,实时演算等多个方面,由于在虚拟地形生成的过程中涉及到3D引擎的多个方面,使得在3D虚拟场景中生成虚拟地形的效率低
[0044] As can be seen from the above technical solution, this application discloses a virtual terrain generation method, system, storage medium, and electronic device. By using a pre-created planar water area segmentation grid, the terrain region is divided into multiple blocks. The terrain region is used to represent the space where the mesh data of the 3D terrain model in the rendering engine is located. The multiple blocks are allocated to a thread pool, and the thread pool performs terrain sand falling processing to obtain the sand falling point position. The sand falling point position is determined by the falling point coordinate values in the linked list of the multiple blocks. The thread pool includes multiple threads. Based on the type of sand falling at the sand falling point position and the contact surface, the target terrain is determined. The target terrain is used to represent a stable terrain where all the sand at the sand falling point has fallen and the sand force is 0. The contact surface type includes planar type or inclined type. A virtual terrain file is generated from the terrain rendering data of the target terrain. Based on the above scheme, by using the threads corresponding to multiple blocks in the thread pool and combining them with the multiprocessor mechanism of the computer, multi-threaded processing can be used to process terrain sandfall more efficiently in parallel, obtain the location of the sandfall point, and determine the precise target terrain where the sandfall force at the sandfall point is 0 based on the sandfall point location and the contact surface, thereby improving the efficiency of virtual terrain generation.
Smart Images

Figure CN115512057B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of graphics and image technology, and more specifically, to a method, system, storage medium, and electronic device for generating virtual terrain. Background Technology
[0002] With the development of computer network technology and mobile device platforms, people have an increasing demand for various styles of 3D virtual scenes, and virtual terrain is almost an indispensable component of 3D virtual scenes.
[0003] There are many ways to generate virtual terrain in 3D virtual scenes using terrain generation algorithms. However, generating virtual terrain in 3D virtual scenes involves various aspects of the 3D engine, including underlying scene management, lighting models, underlying shaders, underlying physical collisions, particle systems, real-time calculations, and so on. Because the generation of virtual terrain involves multiple aspects of the 3D engine, the efficiency of generating virtual terrain in 3D virtual scenes is low. Summary of the Invention
[0004] In view of this, this application discloses a virtual terrain generation method, system, storage medium, and electronic device, aiming to improve the efficiency of virtual terrain generation.
[0005] To achieve the above objectives, the disclosed technical solution is as follows:
[0006] The first aspect of this application discloses a method for generating virtual terrain, the method comprising:
[0007] The terrain region is divided into multiple blocks by a pre-created planar water area segmentation mesh; the terrain region is used to represent the space where the mesh data of the 3D terrain model in the rendering engine is located;
[0008] The multiple blocks are allocated to a thread pool, and the thread pool is used to process the terrain sandfall to obtain the location of the quicksand landing point; the location of the quicksand landing point is determined by the landing point coordinate value in the linked list of the multiple blocks; the thread pool includes multiple threads;
[0009] Based on the type of quicksand falling at the designated landing point and the contact surface, the target terrain is determined; the target terrain is used to characterize a stable terrain where all the quicksand at the landing point has fallen and the force on the quicksand is zero; the type of the contact surface includes a planar type or an inclined type.
[0010] A virtual terrain file is generated using the terrain rendering data of the target terrain.
[0011] Preferably, the step of dividing the terrain region into multiple blocks using a pre-created planar water area segmentation grid includes:
[0012] Determine the size of the terrain region and obtain the corresponding two-dimensional planar space of the terrain region;
[0013] The two-dimensional planar space is divided equally by a pre-created planar water area segmentation grid to divide the terrain region into multiple blocks.
[0014] Preferred options also include:
[0015] Establish a linked list of the multiple blocks; the linked list is used to store the information of the quicksand landing point; the quicksand landing point information includes at least the coordinates and direction of the quicksand landing point.
[0016] Preferably, the step of allocating the multiple blocks to a thread pool and using the thread pool to perform terrain sandfall processing to obtain the location of the quicksand landing point includes:
[0017] Each thread corresponding to the multiple blocks is created using a thread pool;
[0018] The sandfall point is obtained by executing the sandfall process in parallel by each thread corresponding to the multiple blocks; the sandfall point is located within the area corresponding to the multiple blocks.
[0019] The process of parallelly executing the sandfall processing through threads corresponding to the multiple blocks to obtain the location of the quicksand landing point includes:
[0020] The coordinates of the falling sand are set in the area corresponding to the multiple blocks by each thread through a preset setting method.
[0021] By setting the preset sand-spraying direction and preset spraying angle, sand is sprayed from the coordinate position of the sand-spraying location to obtain the landing point of the quicksand.
[0022] Preferably, determining the target terrain based on the type of quicksand falling at the location of the quicksand impact and the contact surface includes:
[0023] When the contact surface coincides with the horizontal plane, the type of the contact surface is determined to be planar.
[0024] When the contact surface type is planar, determine the target terrain corresponding to the quicksand falling at the quicksand landing point and the planar contact surface;
[0025] When there is a preset angle between the contact surface and the horizontal plane, the type of the contact surface is determined to be an inclined surface.
[0026] When the contact surface is of the inclined type, the target terrain corresponding to the quicksand falling at the location of the quicksand landing point is determined.
[0027] Preferably, generating a terrain file from the terrain rendering data of the target terrain includes:
[0028] Obtain the intersection point of the quicksand's landing point and the contact surface;
[0029] After the sandfall at the specified coordinates is completed, the grid data of the target terrain is obtained; the grid data consists of multiple triangular faces.
[0030] Obtain the height values of the triangle vertices in the mesh data that are closest to the intersection point;
[0031] The target height value is obtained by summing the multiple height values.
[0032] The target height value is stored in a two-dimensional texture to obtain terrain rendering data;
[0033] A terrain rendering file is generated from the terrain rendering data.
[0034] A second aspect of this application discloses a virtual terrain generation system, the system comprising:
[0035] A segmentation unit is used to divide a terrain region into multiple blocks using a pre-created planar water segmentation grid; the terrain region is used to represent the space where the mesh data of the 3D terrain model in the rendering engine is located;
[0036] The processing unit is used to allocate the multiple blocks to a thread pool, and to perform terrain sandfall processing through the thread pool to obtain the sandfall location; the sandfall location is determined by the landing coordinate values in the linked list of the multiple blocks; the thread pool includes multiple threads.
[0037] The determining unit is used to determine the target terrain based on the type of quicksand falling at the location of the quicksand landing point and the contact surface; the target terrain is used to characterize a stable terrain where all the quicksand at the landing point has fallen and the force on the quicksand is 0; the type of the contact surface includes a planar type or an inclined type;
[0038] The generation unit is used to generate a virtual terrain file using the terrain rendering data of the target terrain.
[0039] Preferably, the segmentation unit includes:
[0040] The determination module is used to determine the size of the terrain region and obtain the two-dimensional planar space corresponding to the terrain region;
[0041] The segmentation module is used to divide the two-dimensional planar space equally using a pre-created planar water area segmentation grid, so as to divide the terrain area into multiple blocks.
[0042] A third aspect of this application discloses a storage medium comprising stored instructions, wherein, when the instructions are executed, the device in which the storage medium resides executes the virtual terrain generation method as described in any one of the first aspects.
[0043] The fourth aspect of this application discloses an electronic device including a memory and one or more instructions, wherein one or more instructions are stored in the memory and configured to be executed by one or more processors using the virtual terrain generation method as described in any of the first aspects.
[0044] As can be seen from the above technical solution, this application discloses a virtual terrain generation method, system, storage medium, and electronic device. By using a pre-created planar water area segmentation grid, the terrain region is divided into multiple blocks. The terrain region is used to represent the space where the mesh data of the 3D terrain model in the rendering engine is located. The multiple blocks are allocated to a thread pool, and the thread pool performs terrain sand falling processing to obtain the sand falling point position. The sand falling point position is determined by the falling point coordinate values in the linked list of the multiple blocks. The thread pool includes multiple threads. Based on the type of sand falling at the sand falling point position and the contact surface, the target terrain is determined. The target terrain is used to represent a stable terrain where all the sand at the sand falling point has fallen and the sand force is 0. The contact surface type includes planar type or inclined type. A virtual terrain file is generated from the terrain rendering data of the target terrain. Based on the above scheme, by using the threads corresponding to multiple blocks in the thread pool and combining them with the multiprocessor mechanism of the computer, multi-threaded processing can be used to process terrain sandfall more efficiently in parallel, obtain the location of the sandfall point, and determine the precise target terrain where the sandfall force at the sandfall point is 0 based on the sandfall point location and the contact surface, thereby improving the efficiency of virtual terrain generation. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0046] Figure 1 This is a flowchart illustrating a virtual terrain generation method disclosed in an embodiment of this application;
[0047] Figure 2 This is a schematic diagram illustrating the location of the quicksand drop point as disclosed in the embodiments of this application;
[0048] Figure 3 This is a schematic diagram illustrating the intersection of falling sand and a planar contact surface as disclosed in the embodiments of this application;
[0049] Figure 4 This is a schematic diagram illustrating the intersection of a sand-falling surface and a sloped surface as disclosed in an embodiment of this application.
[0050] Figure 5 This is a schematic diagram of the forces acting on a sloped contact surface as disclosed in the embodiments of this application.
[0051] Figure 6 This is a schematic diagram of the structure of a virtual terrain generation system disclosed in an embodiment of this application;
[0052] Figure 7 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of this application. Detailed Implementation
[0053] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0054] In this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0055] As the background technology shows, there are various ways to generate virtual terrain in 3D virtual scenes through terrain generation algorithms. However, generating virtual terrain in 3D virtual scenes involves various aspects of the 3D engine, including underlying scene management, lighting models, underlying shaders, underlying physical collision, particle systems, real-time calculations, and so on. Because the generation of virtual terrain involves multiple aspects of the 3D engine, the efficiency of generating virtual terrain in 3D virtual scenes is low.
[0056] To address the aforementioned issues, this application discloses a virtual terrain generation method, system, storage medium, and electronic device. By utilizing multiple threads corresponding to various blocks in a thread pool, combined with the multiprocessor mechanism of a computer, multi-threaded processing can more efficiently perform parallel processing of terrain sandfall, obtaining the location of the quicksand landing point. Based on the location of the quicksand landing point and the contact surface, a precise target terrain where the force on the quicksand at the landing point is zero is determined, thereby improving the efficiency of virtual terrain generation. The specific implementation method is described in detail in the following embodiments.
[0057] refer to Figure 1 The image shows a virtual terrain generation method disclosed in an embodiment of this application. This virtual terrain generation method mainly includes the following steps:
[0058] S101: The terrain region is divided into multiple blocks by a pre-created planar water area segmentation mesh; the terrain region is used to represent the space where the mesh data of the 3D terrain model in the rendering engine is located.
[0059] In S101, the size of the terrain region is determined and the corresponding two-dimensional planar space is obtained. The two-dimensional planar space is divided equally by a pre-created planar water area segmentation grid to divide the terrain region into multiple blocks.
[0060] The terrain region refers to the entire terrain model mesh data in the 3D scene, which is the space where the entire mesh data of the terrain 3D model is located in the rendering engine.
[0061] Create a linked list of multiple blocks; the linked list is used to store the information of the sand landing point; the information of the sand landing point includes at least the coordinates of the sand landing point (i.e., the coordinates of the sand landing point to the ground v2 in the following formula, v2=v1+dir*d) and the direction of the sand landing point.
[0062] The size of a terrain region can be determined using the AABB bounding box algorithm. This involves traversing all vertices in the terrain model mesh and finding the minimum and maximum coordinates. If A(0,0) is the minimum coordinate and B(100,100) is the maximum coordinate, the rectangular area enclosed by A and B is the entire terrain region. The terrain region may be an irregular area, so the AABB algorithm can also include it.
[0063] To facilitate understanding of determining the size of a terrain region and obtaining its corresponding two-dimensional planar space, a pre-created planar water area segmentation grid is used to equally divide the two-dimensional planar space, thus dividing the terrain region into multiple blocks. An example is provided below to illustrate this process:
[0064] For example, the size of the terrain must first be determined, and then the two-dimensional plane space of that size is divided equally. For example, if the size of the terrain is 1024x1024, the water area is generally divided equally, according to the size of 32x32. Therefore, it can be divided into 32x32 resolution squares (blocks) with a length and width of 32x32.
[0065] Then, each block contains a linked list structure, which stores the information of each quicksand landing point, including (coordinates v, direction dir). Each 32x32 space of water area segmentation is an independent 3D mesh data and its own vertex shader (the terrain does not use a pixel shader). It is rendered in the graphics processing unit (GPU) (rendering the water area segmentation, which is the rendering of the entire terrain, because the water segmentation is the whole terrain. In the rendering engine, the basic data for rendering is the vertex array, and the water segmentation linked list is the container for storing the vertex array, or data structure. The vertices of the entire terrain are stored in the water segmentation linked list in nodes with blocks as units. Each node contains the vertex array of the segmented area of the terrain).
[0066] The coordinates in the 32x32 block are calculated by segmentation. For example, in a 1024x1024 block with the top left corner as the origin coordinate (0, 0, 0), the width and height resolution of each block is (100x100). Moving the coordinates of each block to the right is the sum of the previous left block (32x100, 0), and moving it down one block is the sum of the previous top block (0, 32x100).
[0067] S102: Assign multiple blocks to a thread pool, and use the thread pool to process the terrain sandfall to obtain the sandfall location; the sandfall location (v2, i.e., the sandfall location) is determined by the landing coordinate values in the linked list of the multiple blocks; the thread pool includes multiple threads.
[0068] The specific process of obtaining the location of the quicksand's fall point, combined with... Figure 2 To explain, Figure 2 A schematic diagram showing the location of the quicksand's fall point is provided.
[0069] Figure 2 In this process, after dividing the area into a certain number of square regions, a square is randomly selected from these squares as the landing point of the quicksand. Of course, the size of each square region can also be calculated. Since the coordinates of points A and B of this large rectangle are known, the specific coordinate value of each square can be calculated based on the number of divisions. The coordinates of this area can be randomly selected as the landing point of the quicksand.
[0070] Specifically, multiple blocks are allocated to a thread pool, and the process of using the thread pool to process the terrain sandfall and obtain the location of the quicksand landing point is shown in A1-A2.
[0071] A1: Create threads corresponding to multiple blocks using a thread pool.
[0072] In this process, after dividing the terrain area into water features, a thread pool is used to create threads for each 32x32 block. The thread pool allocates thread creation operations (the thread pool allocation principle is based on the number of CPU cores; for example, if there are 20 CPU cores (a quad-core, five-thread CPU supports a maximum of 20 concurrent threads), and we plan to use 20 threads to process the sandfall, the number of sandfall blocks is randomly selected based on the nodes of the water feature division, for example, 50 blocks. The thread allocation is a maximum of 20 threads, and each thread is allocated two and a half blocks of sandfall to process (the processing method is an average calculation method of 50 / 20=2.5) to ensure that each thread processes the sandfall evenly and achieves the highest efficiency). In this way, each 32x32 block can be processed in parallel on the GPU to calculate the sandfall accumulation algorithm, which greatly improves the efficiency of parallel processing.
[0073] A2: The location of the quicksand landing point is obtained by executing the sand-falling process in parallel by the threads corresponding to multiple blocks; the location of the quicksand landing point is within the area corresponding to multiple blocks.
[0074] Specifically, the process of obtaining the location of the quicksand landing point by having multiple threads corresponding to multiple blocks execute the sand-falling process in parallel is shown in B1-B2.
[0075] B1: Set the coordinates of the falling sand (v1) within the area corresponding to multiple blocks using preset settings through the threads corresponding to multiple blocks.
[0076] The preset setting method can be random setting or manual setting, etc. This application does not specifically limit the determination of the specific preset setting method.
[0077] B2: By setting the sand-falling spray direction and the preset spray angle, sand is dropped from the coordinate position (v1) to obtain the landing point position (v2) of the quicksand.
[0078] The preset sand spray direction is a 360-degree downward spray around the Y-axis, and the preset spray angle is less than 30 degrees.
[0079] After dividing the terrain area into a certain number of square areas (i.e. blocks), a block is randomly selected from these square blocks as the landing point. Of course, the size of each square area can also be calculated. Since the coordinates of points A and B of this large rectangle are known, the specific coordinate value of each block can be calculated based on the number of terrain areas divided. The coordinates of this block area are randomly selected as the landing point to obtain the location of the quicksand landing point.
[0080] Next is the core sand-falling algorithm (sand-falling processing). It randomly or manually specifies fixed coordinate positions and directions within a 32x32 block area. For example, in a 32x32 block (such as each resolution of 100x100), the sand-falling starts at the position with coordinates (10, 5, 20). However, this coordinate is relative to the coordinate position of the 32x32 block. The actual sand-falling coordinates are (x0+10, y0+5, z0+20), where (x0, y0, z0) are the block coordinates calculated by the block segmentation. Then, each time the sand-falling point is launched, the preset sand-falling spray direction sprays downwards at an angle of 360 degrees around the y-axis. However, the preset spray elevation angle cannot exceed 30 degrees to prevent the sand from being sprayed outside the 32x32 area. If the falling sand particle exceeds the 32x32 area, it is ignored. The area is a rectangular space from (x0, y0, z0) to (x0+100, y0+100, z0+100).
[0081] Since the water area segmentation is two-dimensional, the influence of the Y-axis height is ignored. Sand particles exceeding the xz plane can be neglected. Simulated sandfall is only affected by gravity, so external forces during fall are ignored. Under ideal conditions, the mass is infinite, and initially the surface is completely flat, meaning all y-coordinates are 0. When a sand particle lands (the point where it lands on the terrain), the coordinates of the landing point are (x1, y1, z1), i.e., (x0+10, y+5, z0+20) are (x1, y1, z1) + dir*d, where dir is a randomly generated sandfall orientation vector, and d is the length of the intersection between the sandfall point and the surface. The key is to determine d. This is done by directly obtaining the height y0 of the segmented sandfall point and calculating d using the principle of vector product. Specifically... Figure 3 As shown. Figure 3 A schematic diagram is shown showing the intersection of falling sand and a planar contact surface.
[0082] Figure 3 In the equation, the length d where the sand drop point intersects with the ground surface is equal to the vertical height of the sand drop d1 / sin(90 - random angle of the sand drop).
[0083] The random angle of falling sand is calculated as follows: angle = arccos(dot(vertical vector of falling sand v1, jet vector of falling sand v2) / (abs(Length(vertical vector of falling sand)) * abs(Length(jet vector of falling sand)))).
[0084] Where dot is the dot product (i.e., scalar product) of two vectors v1(x1, y1, z1)*v2(x2, y2, z2), which is x1*x2+y1*y2+z1*z2.
[0085] Meanwhile, the dot product represents the geometric meaning of the projection of the inclined plane onto the plane. Therefore, the dot product can also be expressed as abs(Length(v1))*abs(Length(v2))*cos(angle), where angle is the angle between the inclined plane and the plane.
[0086] Therefore, the coordinates of the sand falling to the ground can be calculated as v2 = v1 + dir * d, where d is the length of the intersection between the sand falling point and the ground surface, v1 is the coordinate position of the sand falling at the start of the simulated descent, and (x1, y1, z1) = v1, dir is a randomly generated sand falling azimuth vector.
[0087] Once the point of the falling sand relative to the ground surface is calculated, the grid data in the 32x32 block is traversed to find the focal point (this focal point is the intersection of the ground surface and the falling sand, calculated by the intersection of the triangular face and the falling sand ray as described below. This triangular face is actually the terrain grid data, which is actually composed of countless triangular faces. Therefore, regardless of whether the terrain is flat or not, the ray will always be relative to one of the triangular faces) in which grid it is located. The grid is composed of two triangles (6 vertices, 2 of which are overlapping).
[0088] The process involves determining which point a given point is closer to and accumulating the y-value of that vertex. However, this only applies to the initial sandfall scenario. When the sandfall reaches a certain height (this height should be defined as the highest point of the terrain; in reality, random sandfall points are viewed from above, and the terrain is actually two-dimensional for the sandfall point, but in addition to its area, it should also have a height. Therefore, area and height constitute the actual volume occupied by the terrain, and a height greater than this is the best position for the sandfall point. The sandfall will not stop even if the accumulated sandfall exceeds the sandfall point. This height value is adjusted based on external factors, but in reality, it can be determined according to the laws of nature. For example, the highest peak in the world, Mount Everest, has an altitude of 8848.86 meters. Mapping the space of the real world to the three-dimensional world, converting meters into pixels in the engine (for example, 1 pixel is equivalent to 100 meters, 8848.86 meters is equivalent to 88 pixels in height, meaning that if the height exceeds 88 pixels, the sandfall point will not be lower than the mountain peak), the approach needs to be changed. In this case, the positions of rays and intersections need to be recalculated using triangular faces. First, iterate through all the triangular faces in the 32x32 grid, then calculate the intersection points. For example, if the three vertices of the current triangular face are... You can go Perform intersection point calculations. First, calculate the normal to the triangular face; then calculate the vector through the vector product. ; after calculating the block landing point to Vertex vector ,calculate The actual projection length of the vector onto the normal vector ,Right now In calculating the unit vector of sandfall jets Projection unit length of the normal vector ,Right now After calculating the actual See details Figure 4 As shown. Figure 4 This is a schematic diagram showing the intersection of a sand-falling surface and a slope-type contact surface.
[0089] Figure 4 middle, All three vertices of the current triangle face; c represents the position where the falling sand intersects with the triangle face of the ground model when it falls to the ground, that is, the precise position where the sand falls to the ground.
[0090] S103: Determine the target terrain based on the type of quicksand falling at the landing point and the contact surface; the target terrain is used to characterize a stable terrain where all the quicksand at the landing point has fallen and the force on the quicksand is 0; the contact surface type includes planar type or inclined type.
[0091] The water area is created and allocated to the thread pool. Irregular terrain is generated by controlling the amount and direction of falling sand. When the sand falls to the ground, there are two situations. The first situation is that it initially falls on a flat surface with only downward gravity. The sand falls steadily on the ground and begins to accumulate height. The second situation is that the sand falls on top of the sand that has already accumulated to a certain height.
[0092] The process of determining the target terrain based on the type of quicksand that falls at the point of impact and the contact surface is shown in C1-C4.
[0093] C1: When the contact surface coincides with the horizontal plane, the contact surface type is determined to be planar.
[0094] In this case, the contact surface coincides with the horizontal plane, meaning there is no angle between the contact surface and the horizontal plane.
[0095] C2: When the contact surface type is planar, determine the target terrain corresponding to the falling quicksand and the contact surface of the planar type.
[0096] C3: When there is a preset angle between the contact surface and the horizontal plane, the contact surface type is determined to be inclined.
[0097] The preset angle can be 10 degrees, 15 degrees, etc., and this application does not make specific limitations on the determination of the specific preset angle.
[0098] C4: When the contact surface type is sloped, determine the location of the falling quicksand and the target terrain corresponding to the sloped contact surface.
[0099] S104: Generate a virtual terrain file using the terrain rendering data of the target terrain.
[0100] The specific process of generating virtual terrain files from the terrain rendering data of the target terrain is shown in D1-D6.
[0101] D1: Obtain the intersection of the location where the quicksand falls and the contact surface.
[0102] When the falling sand intersects with the contact surface, the intersection of the falling sand point and the contact surface is obtained. Since the law of conservation of energy is satisfied, the sand was originally only subject to gravity. Now, the gravity force is decomposed into the direction of the falling surface and the direction of its normal vector. Based on the decomposition of forces, the final falling point can be calculated (based on the decomposition of forces, the direction of the sand moving downward can be known).
[0103] D2: After the sandfall at the coordinates of the sandfall location is completed, the grid data of the target terrain is obtained; the grid data consists of multiple triangular faces.
[0104] D3: Obtain the height values of the triangle vertices in the grid data that are closest to the intersection point.
[0105] D4: Summing up multiple height values to obtain the target height value.
[0106] Consider these two scenarios: one where the sand falls on a planar contact surface, and the other where it falls on an inclined plane with accumulated height (i.e., an inclined plane contact surface). Then, proceed to the crucial step: in the second scenario (where the sand falls on an inclined plane with accumulated height), the sand is broken down by gravity, except for the downward force of gravity. The effect also includes a downward component of the force. and forces perpendicular to the inclined plane In addition, there is an upward frictional force. This friction force A range of values can be randomly assigned (for the friction force value). No more than Figure 5 of , yes ,in, It is gravity, 9.8 m / s². , The mass of the falling sand; The acceleration is downward, therefore the frictional force Less than If greater than According to the principle of force decomposition, greater than Part of the force is an external force exerting an upward force to maintain balance, but falling sand rolls downwards, and the downward force of gravity is constant. Therefore, the frictional reaction force is... In this situation, the falling sand either rolls downwards or remains in equilibrium on the slope, only if the frictional force is less than or equal to This ensures that the falling sand either falls downwards or remains balanced on the slope. If friction... Greater than (Then the quicksand moves upwards). When sand falls onto a slope, it slides downwards, but it shouldn't be allowed to move upwards, thus reducing friction. Less than gravity And less than gravity Component force The calculation of the component of gravity should be the cosine of the angle between gravity and the downward force. Figure 5 This is a schematic diagram of the forces acting on a sand-falling object on an inclined surface.
[0107] Figure 5 middle, The normal vector of the inclined plane; For gravity; The component force is downwards at an angle; The force is perpendicular to the inclined plane; The frictional force exerted by the inclined plane on the falling sand; for and The angle formed.
[0108] You can see The gravity is 9.8. Downward force It is the normal vector of the inclined plane. It is the force in the opposite direction of the normal vector. The upward frictional force is calculated. and The included angle This calculation has been explained before using the dot product, so it will not be repeated here.
[0109] After calculating , and thus The force is Obtain a downward force, through This frictional force results in a downward net force. According to Newton's second law, Find the downward acceleration The initial velocity is ,this You can set a fixed value. , calculate , The calculated time interval and the new initial velocity formed after acceleration are used to determine the distance traveled on the inclined plane. However, as the sand moves downwards, the slope also changes. Therefore, the sand moves along the slope closely, and the slope may not eventually stop. Therefore, the judgment condition is that the cumulative distance from the next vertex to the landing point is less than this distance. It redecomposes the forces and recalculates. The value is used to recalculate the composition of forces, and then the acceleration is calculated. This process is repeated iteratively, following the steps above, with the initial velocity being the same as the previous value. and , Then recalculate Until calculated The result is 0, or it is only subject to gravity. Stop. Determine which triangle the stop position is on, and which vertex of the triangle it is closest to. Accumulate the y-value of that vertex (the terrain rendering data of the target terrain).
[0110] G1 and G2 form a triangle. Since the sum of the three angles of a triangle is 180 degrees, one of which is a right angle of 90 degrees, and one of the angles is... 90+ + =180, according to conversion =90- ,therefore yes The supplementary angle. The reason for using... instead of Because the method for calculating friction force here is... g, instead of These two can be interchanged, but it's just for more rigorous calculations.
[0111] Specifically, new accelerations are calculated through continuous iteration. Calculate the new distance traveled. until the end The sand generally tends to flow onto a plane. However, this is under ideal conditions where there is no reverse friction. In reality, due to the presence of reverse friction, the sand may eventually be offset by the reverse friction, causing the force to reach zero and the flow to stop. Therefore, simply stopping the iteration when the acceleration reaches zero is insufficient. At least F = 0 and a = 0 should be required to stop the sand movement. The sand may not necessarily stay on the plane. All the sand at the randomly assigned sand points must be completely washed away, and all the sand must stop when the force reaches zero. At this point, the entire area is stable and represents the target terrain. Only then is the target terrain grid point data saved, i.e., the terrain rendering data of the target terrain. This data can then be used for 3D rendering, such as terrain exploration and games.
[0112] acceleration The force depends only on the downward gravitational force of the falling sand and the angle of the slope. Ultimately, the downward force F on the slope can be calculated, divided by the mass m of the falling sand, and the acceleration can be obtained. acceleration It may be random, but it is related to the slope of the mountain that is eventually formed by the falling sand.
[0113] D5: Store the target height value in a 2D texture to obtain terrain rendering data.
[0114] For example, after all the falling sand has been released, grid data will be obtained in 32x32 segmented regions. The y-values of these grids are extracted and stored in an 8-bit L8 2D texture (height map). Then, the 32x32 height maps are stitched together in a preset order to form a single texture, which can also be used independently. When this height map is needed, this large texture or the 32x32 texture is loaded into memory in sequence, and finally loaded into the CPU to read the height, reconstructing the height of the irregular terrain. The pixel positions represent the terrain's... Coordinates or relative coordinates; if the texture is fragmented, the texture number, after conversion, corresponds to the coordinates of that fragment. The absolute coordinates are The formula for calculating block coordinates is , .
[0115] in, It's about looping through positive integers from 0 to 32, based on... The specific coordinates of each segmented area after the 32x32 block can be calculated. Water segmentation helps to optimize the number of calculations, without having to traverse and process the entire terrain grid. It only needs to traverse and process the sandfall in that segmented area.
[0116] The preset order can be the water area division order. Since the water area division order is from point A to point B, it is generally from left to right and from top to bottom, but other orders are also possible. The preset order is determined by technical personnel according to the actual situation, and this application does not impose specific limitations. The preset order of this application takes precedence over the water area division order.
[0117] D6: Generates terrain rendering files from terrain rendering data.
[0118] This algorithm is used to quickly generate terrain and can generate multiple textures to save the height map of the segmented region. If combined with the computer's multi-processor mechanism, since all height generation calculations and rendering are processed on the GPU, multi-threaded processing can be more efficient because the GPU is better at parallel processing.
[0119] In this embodiment, by using the threads corresponding to multiple blocks in the thread pool and combining them with the computer's multiprocessor mechanism, multi-threaded processing can be used to process terrain sandfall more efficiently in parallel, obtain the location of the sandfall point, and determine the precise target terrain where the sandfall force on the sandfall point is 0 based on the sandfall point location and the contact surface, thereby improving the efficiency of virtual terrain generation.
[0120] Based on the above embodiments Figure 1 The present application discloses a virtual terrain generation method and a corresponding virtual terrain generation system. Figure 6 As shown, the virtual terrain generation system includes a segmentation unit 601, a processing unit 602, a determination unit 603, and a generation unit 604.
[0121] The segmentation unit 601 is used to divide the terrain region into multiple blocks using a pre-created planar water segmentation grid; the terrain region is used to represent the space where the grid data of the 3D terrain model in the rendering engine is located.
[0122] The processing unit 602 is used to allocate multiple blocks to a thread pool, and to process the terrain sandfall through the thread pool to obtain the sandfall location; the sandfall location is determined by the landing coordinate values in the linked list of multiple blocks; the thread pool includes multiple threads.
[0123] The determination unit 603 is used to determine the target terrain based on the type of quicksand falling at the quicksand landing point and the contact surface. The target terrain is used to characterize a stable terrain where all the quicksand at the quicksand landing point has fallen and the quicksand is subjected to zero force. The contact surface type includes a planar type or an inclined type.
[0124] The generation unit 604 is used to generate a virtual terrain file from the terrain rendering data of the target terrain.
[0125] Furthermore, the segmentation unit 601 includes a first determining module and a segmentation module.
[0126] The first determining module is used to determine the size of the terrain region and obtain the corresponding two-dimensional planar space of the terrain region.
[0127] The segmentation module is used to divide a two-dimensional planar space into multiple blocks by using a pre-created planar water segmentation grid.
[0128] Furthermore, the virtual terrain generation system also includes a building unit.
[0129] A unit is created to establish a linked list of multiple blocks; the linked list is used to store information about the landing points of the quicksand; the information about the landing points of the quicksand includes the coordinates and direction of the landing points.
[0130] Furthermore, the processing unit 602 includes a creation module and a processing module.
[0131] Create a module to create threads corresponding to multiple blocks using a thread pool.
[0132] The processing module is used to execute the sand-falling process in parallel through various threads corresponding to multiple blocks to obtain the location of the quicksand landing point; the location of the quicksand landing point is within the area corresponding to multiple blocks.
[0133] Furthermore, the processing module includes a settings submodule and an execution submodule.
[0134] The settings submodule is used to set the coordinates of the falling sand within the area corresponding to multiple blocks using preset settings through the threads corresponding to multiple blocks.
[0135] The execution submodule is used to drop sand from the coordinate position of the sand drop point by using a preset sand drop spray direction and a preset spray angle.
[0136] Furthermore, the determining unit 603 includes a second determining module, a third determining module, a fourth determining module, and a fifth determining module.
[0137] The second determining module is used to determine the type of the contact surface as planar when the contact surface coincides with the horizontal plane.
[0138] The third determination module is used to determine the target terrain corresponding to the falling quicksand and the planar contact surface when the contact surface type is planar.
[0139] The fourth determining module is used to determine the type of the contact surface as an inclined surface when there is a preset angle between the contact surface and the horizontal plane.
[0140] The fifth determination module is used to determine the target terrain corresponding to the falling quicksand and the slope-type contact surface when the contact surface type is a slope type.
[0141] Furthermore, the generation unit 604 includes a first acquisition module, a second acquisition module, a third acquisition module, an accumulation module, a storage module, and a generation module.
[0142] The first acquisition module is used to acquire the intersection point of the quicksand landing point and the contact surface.
[0143] The second acquisition module is used to obtain grid data of the target terrain after the sand has been released at the coordinates of the sandfall location; the grid data consists of multiple triangular faces.
[0144] The third acquisition module is used to acquire the height values of the triangle vertices in the grid data that are closest to the intersection point.
[0145] The accumulation module is used to accumulate multiple height values to obtain the target height value.
[0146] The storage module is used to store the target height value into a two-dimensional texture to obtain terrain rendering data;
[0147] The generation module is used to generate terrain rendering files from terrain rendering data.
[0148] In this embodiment, by using the threads corresponding to multiple blocks in the thread pool and combining them with the computer's multiprocessor mechanism, multi-threaded processing can be used to process terrain sandfall more efficiently in parallel, obtain the location of the sandfall point, and determine the precise target terrain where the sandfall force on the sandfall point is 0 based on the sandfall point location and the contact surface, thereby improving the efficiency of virtual terrain generation.
[0149] This application embodiment also provides a storage medium, which includes stored instructions, wherein, when the instructions are executed, the device where the storage medium is located controls the execution of the above-described virtual terrain generation method.
[0150] This application also provides an electronic device, the structural schematic diagram of which is shown below. Figure 7As shown, it specifically includes a memory 701 and one or more instructions 702, wherein one or more instructions 702 are stored in the memory 701 and configured to be executed by one or more processors 703 to perform the above-mentioned virtual terrain generation method.
[0151] For the foregoing method embodiments, in order to simplify the description, they are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0152] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For system-type embodiments, since they are basically similar to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0153] The steps in the methods of the various embodiments of this application can be adjusted, combined, or deleted according to actual needs.
[0154] Finally, it should be noted that in this paper, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0155] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0156] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A method for generating virtual terrain, characterized in that, The method includes: The terrain region is divided into multiple blocks by a pre-created planar water area segmentation mesh; the terrain region is used to represent the space where the mesh data of the 3D terrain model in the rendering engine is located; The multiple blocks are allocated to a thread pool, and the thread pool performs terrain sandfall processing to obtain the sandfall location. The sandfall location is determined by the landing coordinates in the linked list of the multiple blocks. The sandfall location is the position after sandfall processing. The sandfall location is obtained by sandfalling from the coordinates of the sandfall location according to a preset sandfall spray direction and a preset spray angle. The preset sandfall spray direction is a 360-degree downward spray centered on the Y-axis. The preset spray angle is less than 30 degrees. The thread pool includes multiple threads. Based on the type of quicksand falling at the designated sandfall point and the contact surface, the target terrain is determined; the target terrain is used to characterize a stable terrain where all the quicksand at the sandfall point has fallen and the force on the quicksand is zero; the type of the contact surface includes a planar type or an inclined type. A virtual terrain file is generated using the terrain rendering data of the target terrain.
2. The method according to claim 1, characterized in that, The process of dividing the terrain region into multiple blocks using a pre-created planar water area segmentation grid includes: Determine the size of the terrain region and obtain the corresponding two-dimensional planar space of the terrain region; The two-dimensional planar space is divided equally by a pre-created planar water area segmentation grid to divide the terrain region into multiple blocks.
3. The method according to claim 2, characterized in that, Also includes: Establish a linked list of the multiple blocks; The linked list is used to store information about the sandfall point; the sandfall point information includes at least the coordinates and direction of the sandfall point.
4. The method according to claim 1, characterized in that, The step of allocating the multiple blocks to a thread pool and using the thread pool to perform terrain sandfall processing to obtain the sandfall location includes: Each thread corresponding to the multiple blocks is created using a thread pool; The sandfall point is obtained by executing the sandfall processing in parallel by each thread corresponding to the multiple blocks; the sandfall point is located within the area corresponding to the multiple blocks. The process of parallelly executing the sandfall processing through threads corresponding to the multiple blocks to obtain the sandfall location includes: The coordinates of the falling sand are set in the area corresponding to the multiple blocks by each thread through a preset setting method. By setting the preset sand-spraying direction and preset spraying angle, sand is sprayed from the coordinate position of the sand-spraying location to obtain the sand-spraying landing point position.
5. The method according to claim 1, characterized in that, The determination of the target terrain based on the type of quicksand falling at the location of the sandfall and the contact surface includes: When the contact surface coincides with the horizontal plane, the type of the contact surface is determined to be planar. When the contact surface type is planar, determine the target terrain corresponding to the quicksand falling at the sandfall point and the planar contact surface; When there is a preset angle between the contact surface and the horizontal plane, the type of the contact surface is determined to be an inclined surface. When the contact surface is of the inclined type, the target terrain corresponding to the quicksand falling at the sandfall point and the inclined contact surface is determined.
6. The method according to claim 1, characterized in that, The process of generating a terrain file from the terrain rendering data of the target terrain includes: Obtain the intersection point of the sand's impact point and the contact surface; After the sandfall at the specified coordinates is completed, the grid data of the target terrain is obtained; the grid data consists of multiple triangular faces. Obtain the height values of the triangle vertices in the mesh data that are closest to the intersection point; The target height value is obtained by summing the multiple height values. The target height value is stored in a two-dimensional texture to obtain terrain rendering data; A terrain rendering file is generated from the terrain rendering data.
7. A virtual terrain generation system, characterized in that, The system includes: A segmentation unit is used to divide a terrain region into multiple blocks using a pre-created planar water segmentation grid; the terrain region is used to represent the space where the mesh data of the 3D terrain model in the rendering engine is located; The processing unit is used to allocate the multiple blocks to a thread pool, and perform terrain sandfall processing through the thread pool to obtain the sandfall point position. The sandfall point position is determined by the landing point coordinate values in the linked list of the multiple blocks. The sandfall point position is the position after sandfall processing. The sandfall point position is obtained from the sandfall coordinate position according to a preset sandfall spray direction and a preset spray angle. The preset sandfall spray direction is a 360-degree downward spray centered on the Y-axis. The preset spray angle is less than 30 degrees. The thread pool includes multiple threads. The determining unit is used to determine the target terrain based on the type of quicksand falling at the landing point and the contact surface; the target terrain is used to characterize a stable terrain where all the quicksand at the landing point has fallen and the force on the quicksand is 0; the type of the contact surface includes a planar type or an inclined type. The generation unit is used to generate a virtual terrain file using the terrain rendering data of the target terrain.
8. The system according to claim 7, characterized in that, The segmentation unit includes: The determination module is used to determine the size of the terrain region and obtain the two-dimensional planar space corresponding to the terrain region; The segmentation module is used to divide the two-dimensional planar space equally using a pre-created planar water area segmentation grid, so as to divide the terrain area into multiple blocks.
9. A storage medium, characterized in that, The storage medium includes stored instructions, wherein, when the instructions are executed, the device containing the storage medium is controlled to perform the virtual terrain generation method as described in any one of claims 1 to 6.
10. An electronic device, characterized in that, It includes a memory, and one or more instructions, wherein one or more instructions are stored in the memory and configured to be executed by one or more processors as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Real-time snowflake deposition simulation method based on particle system model
CN102867334A
Sand painting drawing method based on Leap Motion gesture recognition
CN107024989A