A three-dimensional terrain clipping method, device, equipment and readable storage medium

By projecting the polygons to be cropped in the three-dimensional terrain model to a plane and drawing them in the texture object, combined with the texture value judgment of the piece shader, three-dimensional terrain cropping of any complex polygon is achieved, solving the problem of only supporting convex polygon cropping in the existing technology, and improving computing efficiency and system stability.

CN115131513BActive Publication Date: 2025-06-27BEIJING MAPABC CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210785918.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2022-04-20
Filing Date
2022-07-04
Publication Date
2025-06-27
Estimated Expiration
2042-07-04

AI Technical Summary

Technical Problem

The existing three-dimensional terrain cutting method only supports convex polygon cutting, and it is impossible to directly cut concave polygons. When the shape of the cropped polygon is complex or the number of edges is large, the calculation amount is large, resulting in reduced efficiency and lag in operation.

Method used

By projecting the polygon to be cropped to the plane, drawing it in the texture object, and projecting the fragment coordinates to the plane in the fragment shader, we can determine whether the fragment is in the cropped polygon based on the texture value, and achieve terrain cropping.

Benefits of technology

This method supports the cutting of concave, convex or arbitrary complex polygons, reducing the dependence on the judgment of crop shapes, improving calculation efficiency, ensuring stable and smooth system operation, and meeting practical application needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115131513B_ABST
    Figure CN115131513B_ABST
Patent Text Reader

Abstract

The present invention discloses a three-dimensional terrain clipping method. In this method, the clipping polygon is projected onto a plane and then drawn on a texture map. After converting the fragment position into texture coordinates in the fragment shader, the corresponding texture value is obtained through texture mapping. Whether the fragment is located inside the clipping polygon for terrain clipping is determined based on whether the texture value is the filling value set for the projected polygon. Among them, the distinction of texture values can ignore the clipping shape, so it can be widely applied to clipping polygons of different shapes; moreover, in the recognition and judgment of texture values, it is not necessary to judge one by one according to each side of the clipping polygon, and it basically does not affect the calculation efficiency even when the number of sides is large, thereby ensuring the stable and smooth operation of the system. The present invention also discloses a three-dimensional terrain clipping device, equipment and readable storage medium, which have corresponding technical effects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of three-dimensional information processing, and in particular to a three-dimensional terrain clipping method, device, equipment and readable storage medium. Background Art

[0002] Three-dimensional geographic information systems use terrain data to overlay remote sensing images or raster maps to truly represent the undulating terrain and landforms in the real world, thereby forming the basic data of three-dimensional geographic information. In project development, three-dimensional models such as roads, buildings, and trees are overlaid on the terrain to construct a complete virtual reality three-dimensional scene. In addition to the three-dimensional models above the ground surface, there are also some models below the ground surface that need to be represented, such as underground parking lots, underground mines, and underpass highway bridges. These objects below the ground surface will be blocked by the terrain and cannot be observed. Therefore, in a three-dimensional scene, a method is needed to clip and remove the terrain according to the specified regional range coordinates, so as to facilitate the user to clearly view the scene objects below the ground surface by clipping the terrain.

[0003] Currently, the commonly used three-dimensional terrain clipping method is to write a custom fragment shader in the programmable rendering pipeline based on the GPU (Graphics Processing Unit). Multiple vertical clipping planes are generated from the sides of the clipping area, the spatial relationship between the fragment and these clipping planes is calculated, and the fragment is determined to be culled or retained according to the result, so as to achieve the effect of terrain clipping in the finally presented rendering result, such as the plane clipping method based on Cesium (an open-source js library for displaying the three-dimensional earth and maps). However, this method only supports the clipping of terrain by convex polygons. When dealing with concave polygons, it needs to be split into several convex polygons before performing terrain clipping, and does not support the direct clipping of concave polygons, which cannot meet the flexible usage requirements. Moreover, when the shape of the clipped polygon is complex or the number of sides is large, the number of generated clipping planes also increases accordingly, and the calculation amount will increase significantly, resulting in problems such as decreased efficiency and running jams, affecting the usage experience.

[0004] In summary, how to achieve flexible and fast three-dimensional terrain clipping is an urgent technical problem that needs to be solved by those skilled in the art at present. Summary of the Invention

[0005] The purpose of the present invention is to provide a three-dimensional terrain clipping method, device, equipment and readable storage medium to achieve flexible and fast three-dimensional terrain clipping.

[0006] To solve the above technical problems, the present invention provides the following technical solutions:

[0007] A three-dimensional terrain clipping method includes:

[0008] Determine the polygon to be cropped and the corresponding projection plane in the three-dimensional terrain model;

[0009] Project the polygon to be cropped onto the projection plane to obtain a projected polygon, and determine the bounding rectangle of the projected polygon;

[0010] Draw the projected polygon in the texture object and fill it according to the set fill color;

[0011] Call the fragment shader to project the coordinates of each fragment in the three-dimensional terrain model onto the projection plane, and determine the texture coordinates of each fragment according to the bounding rectangle;

[0012] Obtain the texture value corresponding to the texture coordinates in the texture object, and determine whether the texture value is the fill color;

[0013] If so, cull the fragment in the fragment shader.

[0014] Optionally, before determining the texture coordinates of each fragment according to the bounding rectangle, it further includes:

[0015] Determine whether the projection position of each fragment is within the bounding rectangle;

[0016] If it is within the bounding rectangle, perform the step of determining the texture coordinates of each fragment according to the bounding rectangle.

[0017] Optionally, determining the bounding rectangle of the projected polygon includes:

[0018] Taking the centroid of the polygon to be cropped as the origin, determine the coordinate axes of the projection plane;

[0019] Obtain the bounding rectangle of the projected polygon parallel to the coordinate axes in the projection plane.

[0020] Optionally, determining the bounding rectangle of the projected polygon parallel to the coordinate system in the projection plane includes: determining the minimum bounding rectangle of the projected polygon parallel to the coordinate system in the projection plane.

[0021] Optionally, projecting the polygon to be cropped onto the projection plane includes:

[0022] Project each vertex of the polygon to be cropped onto the projection plane, and use the polygon generated by connecting the projected vertices in sequence as the projected polygon.

[0023] Optionally, before drawing the projected polygon in the texture object, it further includes: obtaining a square texture object with a default size.

[0024] Optionally, before drawing the projected polygon in the texture object, it further includes:

[0025] Create a texture object with a matching size according to the aspect ratio of the bounding rectangle.

[0026] A computer device includes:

[0027] A memory for storing a computer program;

[0028] A processor for implementing the steps of the above three-dimensional terrain clipping method when executing the computer program.

[0029] A readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the steps of the above three-dimensional terrain clipping method.

[0030] In the method provided by the embodiments of the present invention, the clipping polygon is projected onto a plane and then drawn on a texture map. After converting the fragment position into texture coordinates in the fragment shader, the corresponding texture value is obtained through texture mapping. Whether the fragment is located inside the clipping polygon is determined by whether the texture value is the filling value set for the projected polygon to achieve terrain clipping. Among them, this method realizes the distinction between inside and outside the clipping polygon through the texture value. The distinction of the texture value can ignore the clipping shape, and concave, convex or any complex polygon can be projected onto the plane and drawn on the texture map. Therefore, this method can be widely applicable to clipping polygons of different shapes; moreover, in the recognition and judgment of the texture value, it is not necessary to judge each side of the clipping polygon one by one, that is, when the number of sides of the clipping polygon is large, it basically does not affect the calculation efficiency, so as to ensure the stable and smooth operation of the system and can well meet the actual application requirements.

[0031] Correspondingly, the embodiments of the present invention also provide a three-dimensional terrain clipping device, device and readable storage medium corresponding to the above three-dimensional terrain clipping method, which have the above technical effects and will not be elaborated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or related technologies, the following will briefly introduce the drawings required for use in the description of the embodiments or related technologies. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0033] Figure 1 It is the flowchart of the implementation of a three-dimensional terrain clipping method in the embodiments of the present invention;

[0034] Figure 2Schematic diagram of a three-dimensional terrain clipping device in an embodiment of the present invention;

[0035] Figure 3 Schematic diagram of a computer device in an embodiment of the present invention. Detailed implementation manners

[0036] The core of the present invention is to provide a three-dimensional terrain clipping method, which can achieve flexible and fast three-dimensional terrain clipping.

[0037] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific implementation manners. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0038] In the traditional GPU-based programmable rendering pipeline, the three-dimensional terrain clipping method of writing a custom fragment shader has low calculation efficiency. Taking the plane clipping method based on Cesium as an example. The plane clipping of Cesium is completed in the view space coordinate system in the fragment shader. Its principle is to convert the position and normal vector of the clipping plane from the world coordinate system to the view space coordinate system, then convert the position of the current fragment of the model from the window coordinate system to the view space coordinate system, calculate the vector between the plane position and the fragment position, and dot multiply it with the plane normal vector to obtain the projection length of the vector in the plane normal direction; if the length is equal to 0, the fragment is located on the clipping plane, if it is greater than or less than 0, the fragment is located on the front or back side of the clipping plane, so as to cull or retain the fragment, and finally realize the clipping of the entire model.

[0039] Currently, to implement terrain clipping along a specified polygon area in Cesium, based on the above plane clipping algorithm, each side of the polygon is passed through to form a clipping plane perpendicular to the ground and with the normal direction to the right. All clipping planes are traversed. If a fragment is on the culled side of all clipping planes, the fragment is culled, otherwise, the fragment is retained.

[0040] This algorithm realizes the function of terrain clipping based on polygons, but at the same time has certain limitations. Since it judges whether it belongs to the clipping polygon by judging the orientation of the clipping plane on each side of the polygon, it only supports convex polygons. When applied to concave polygons, the results obtained are chaotic and incorrect, which is caused by the limitations of the algorithm itself. In addition, since it needs to judge the orientation of the sides of each clipping polygon when judging each clipping plane, when the polygon shape is complex or the number of sides is large, the calculation amount will increase significantly, causing problems such as efficiency decline and running lag.

[0041] In view of this, the present invention proposes a three-dimensional terrain clipping method, which can support the three-dimensional terrain clipping of various shaped polygons such as concave and convex polygons. Moreover, even when the polygon shape is complex and the number of sides is large, the system operation efficiency will not be significantly reduced. It has high practical value and can meet the requirements of terrain clipping in actual project applications.

[0042] Please refer to Figure 1 , Figure 1 which is a flowchart of a three-dimensional terrain clipping method in an embodiment of the present invention. The method includes the following steps:

[0043] S101. Determine the polygon to be clipped in the three-dimensional terrain model and the corresponding projection plane;

[0044] The three-dimensional terrain model is the object to be clipped in this method. The terrain model refers to a map model produced according to a unified specification that details basic geographical elements such as residential areas, roads, water systems, boundaries, soil quality, and vegetation on the ground surface and represents the ground undulation with contour lines.

[0045] The polygon to be clipped is a polygon that the user customizes in the three-dimensional terrain model and needs to perform terrain clipping. The present invention supports the terrain clipping of concave, convex, or arbitrarily complex polygons. Therefore, the shape of the polygon to be clipped is not limited and can be drawn or edited and set according to actual usage needs.

[0046] The role of the projection plane is to provide a common coordinate system for the clipped polygon and the fragments of the three-dimensional terrain model in the fragment shader, so as to realize the data processing between the clipped polygon and the fragments. Regarding the determination method of the projection plane, it is not limited in this embodiment and can refer to the determination method of the reference plane in related technologies. For example, all vertices of the clipped polygon can be converted to the world coordinate system, and then the coordinates of the centroid of the clipped polygon are calculated as a point on the projection plane; then the vector formed by the connection between the origin of the world coordinate system and the centroid is normalized and used as the normal vector of the plane; then a plane is determined according to a point on the projection plane and the normal vector as the projection plane. For the convenience of further calculation, the projection plane determined by the above method can also be rotated into a horizontal plane as the finally determined projection plane. Only the above two generation methods of the projection plane are used as examples for introduction in this embodiment, and other implementation methods can refer to the introduction of this embodiment and will not be elaborated here.

[0047] S102. Project the polygon to be clipped onto the projection plane to obtain a projected polygon, and determine the bounding rectangle of the projected polygon;

[0048] Project the polygon to be clipped onto the projection plane, and use the polygon obtained after projection as the projected polygon. The specific implementation method of the projection can refer to the related technology. To improve the projection efficiency, specifically, each vertex of the polygon to be clipped can be projected onto the projection plane, and after projecting each vertex, the polygon formed by connecting the projected vertices in sequence is used as the projected polygon.

[0049] After obtaining the projected polygon, determine the bounding rectangle of the projected polygon (referring to the rectangle whose edge lines and interior contain all the projected polygons) to facilitate the subsequent determination of texture coordinates. Among them, the calculation method of the bounding rectangle is not limited and can refer to the introduction in the related technology, which will not be elaborated here.

[0050] S103. Draw the projected polygon in the texture object and fill it according to the set fill color;

[0051] Create a texture object (a storage type that can be read and written by a shader), draw and fill the projected clipped polygon in the texture object, and write it into the texture buffer. Among them, the set fill color can be custom-set and is not limited here.

[0052] S104. Call the fragment shader to project the coordinates of each fragment in the three-dimensional terrain model onto the projection plane, and determine the texture coordinates of each fragment according to the bounding rectangle;

[0053] In the fragment shader of the terrain model rendering pipeline, convert the position of the current fragment of the terrain to the world coordinate system, and then project it onto the projection plane to achieve the purpose of fragment coordinate projection.

[0054] In the conventional rendering process, the last stage of programmatically controlling the color displayed on the screen is called the fragment shading stage. In this stage, the fragment shader calculates the final color and its depth value of the fragment, and processes the independent fragments generated after OpenGL rasterization. Among them, rasterization is the process of converting a primitive into a two-dimensional image. Each point on the two-dimensional image contains color, depth, and texture data, and this point and related information are called a fragment. In this method, the fragment shader is called to project the fragment coordinates onto the projection plane, and after projection, it is unified with the coordinate system of the clipped polygon, so as to facilitate clipping.

[0055] S105. Obtain the texture value corresponding to the texture coordinate in the texture object, and determine whether the texture value is the fill color; if so, execute step S106;

[0056] The projected fragment position is further converted into texture coordinates. Through texture mapping, texture values are obtained by sampling on the texture object. If the texture value is the filling color, it indicates that the current fragment is within the clipped polygon, and then step S106 is executed to cull the fragment in the fragment shader. Otherwise, the fragment is retained. For this case, no limitation is made in this embodiment, and other rendering processes can be further performed, which will not be elaborated here.

[0057] After performing the above processing for each fragment, all the terrain model fragments within the clipped polygon are culled, thus realizing the clipping operation of an arbitrary concave-convex polygon on the three-dimensional terrain model.

[0058] S106. Cull the fragment in the fragment shader.

[0059] Based on the above introduction, for the technical solution provided by the embodiment of the present invention, the clipped polygon is projected onto a plane and drawn on a texture map. After converting the fragment position into texture coordinates in the fragment shader, the corresponding texture value is obtained through texture mapping. Whether the fragment is within the clipped polygon is determined according to whether the texture value is the filling value set for the projected polygon to achieve terrain clipping. Among them, this method uses the texture value to distinguish between inside and outside the clipped polygon. The distinction of the texture value can ignore the clipped shape, and concave, convex, or arbitrarily complex polygons can be projected onto the plane and drawn on the texture map. Therefore, this method can be widely applicable to clipped polygons of different shapes; moreover, in the recognition and judgment of the texture value, it is not necessary to judge each side of the clipped polygon one by one, that is, when the number of sides of the clipped polygon is large, it basically does not affect the calculation efficiency, so as to ensure the stable and smooth operation of the system and can well meet the actual application requirements.

[0060] It should be noted that based on the above embodiments, the embodiment of the present invention also provides corresponding improvement solutions. In the preferred / improved embodiments, the same steps or corresponding steps involved in the above embodiments can be referred to each other, and the corresponding beneficial effects can also be referred to each other, which will not be elaborated one by one in the preferred / improved embodiments of this article.

[0061] To further improve the three-dimensional terrain clipping efficiency, before step S104 executes to determine the texture coordinates of each fragment, the following steps can be further executed:

[0062] S107. Judge whether the projected position of each fragment is within the bounding rectangle; if it is within the bounding rectangle, trigger step S104 to execute the step of determining the texture coordinates of each fragment according to the bounding rectangle.

[0063] Before calculating the texture coordinates of each fragment, this embodiment adds a step of determining whether the projection position is within the bounding rectangle. If the position of the projected fragment is not within the bounding rectangle of the clipping polygon, it is retained; if it is within the bounding rectangle of the clipping polygon, it is further converted into texture coordinates, and texture values are obtained by sampling on the texture object through texture mapping.

[0064] By first performing a pre-judgment of the fragment position before judging the texture values one by one, this method is equivalent to adding a pre-screening step for the fragments, pre-screening the fragments located within the bounding rectangle corresponding to the clipping polygon. Among them, the calculation efficiency of the position judgment for the rectangle is high, and a large number of fragments far from the polygon can be quickly excluded. Therefore, only the fragments within the bounding rectangle need to be used for the calculation of texture values and the judgment of filling colors, realizing the accurate distinction of fragment positions, effectively saving computing resources, and improving computing efficiency.

[0065] Among them, the calculation and determination method for the bounding rectangle in the above embodiment is not limited. To simplify the calculation amount and improve the calculation efficiency, optionally, a calculation method for the bounding rectangle of the projected polygon is as follows:

[0066] (1) Taking the centroid of the polygon to be clipped as the origin, determine the coordinate axes of the projection plane;

[0067] The coordinate axes of the projection plane can be set according to the actual calculation needs, and the determination method is not limited here. For example, the vector between the world coordinate origin and the centroid point can be cross-multiplied with the positive z-axis vector, and the obtained vector is used as the positive y-axis direction of the projection plane, and rotated 90 degrees clockwise to obtain the positive x-axis direction of the projection plane. When the projection plane is horizontal, the xy-axis directions of the world coordinate system can also be directly used as the xy-axis directions of the projection plane. Only the above two methods for determining the coordinate axes are used as examples in this embodiment, and other determination methods can refer to the introduction of this embodiment and will not be elaborated here.

[0068] (2) Obtain the bounding rectangle parallel to the coordinate axes of the projected polygon in the projection plane.

[0069] The rectangle being parallel to the coordinate axes means that the adjacent sides of the rectangle are respectively parallel to the x-axis and y-axis of the coordinate axes. For example, the long side of the rectangle is parallel to the x-axis and the short side is parallel to the y-axis; or, the long side is parallel to the y-axis and the short side is parallel to the x-axis.

[0070] The above method obtains the bounding rectangle parallel to the coordinate axes of the projection plane, so that the calculation amount caused by the offset of the bounding rectangle can be ignored when calculating whether the projection position of the fragment is within the bounding rectangle, thereby realizing the simplification of the calculation and the improvement of the efficiency.

[0071] Among them, in order to further reduce the amount of calculation and maximize the elimination of fragments that are not close to the projected polygon at one time, in step (2), the bounding rectangle of the projected polygon parallel to the coordinate system in the projection plane is determined. Specifically, it can be: determining the minimum bounding rectangle of the projected polygon parallel to the coordinate system in the projection plane.

[0072] By determining the minimum bounding rectangle of the projected polygon to exclude the projected positions of the fragments, only the fragments within the minimum bounding rectangle are retained for further refined comparison, which can significantly reduce the amount of calculation.

[0073] It should be noted that only the above calculation method of the bounding rectangle is used as an example for introduction in this embodiment. Other calculation methods can refer to the introduction of this embodiment and can be regarded as within the protection scope of the present invention.

[0074] Based on the above embodiment, the texture object is a raster image. The larger its size and the higher its resolution, the higher the accuracy of the final clipping result and the smoother the boundary of the clipping area. However, too high a resolution will affect the efficiency of texture mapping, thereby reducing the system operation efficiency. In general actual application scenarios, generally not too high clipping accuracy is required. Therefore, in order to further improve the system operation efficiency, further technical restrictions are imposed on the texture object in this embodiment.

[0075] Optionally, before step S103 of drawing the projected polygon in the texture object, the following steps can be further executed:

[0076] Step S108: Obtain the default size to create a square texture object.

[0077] Obtain the default size to create a square texture object, where the default size is, for example, a resolution of 512*512. The specific value setting of the default size is not limited in this embodiment.

[0078] The implementation method of fixing the polygon size is simple. A corresponding texture object can be directly created without calculation, thereby improving the implementation efficiency of clipping; at the same time, this method can simplify the background deployment steps and improve the method online efficiency.

[0079] Alternatively, before step S103 of drawing the projected polygon in the texture object, the following steps can be further executed:

[0080] Step S109: Create a texture object with a size matching the aspect ratio of the bounding rectangle accordingly.

[0081] In this method, a texture object of a rectangle is defined by adopting the same aspect ratio as that of the trimmed polygon bounding rectangle. Among them, the created texture object has the same size ratio as the bounding rectangle, which can ensure the high definition and high resolution of the drawn projected polygon, avoid the situation of limited resolution caused by size compression, and thus can achieve the purpose of higher trimming accuracy at the same resolution.

[0082] It should be noted that in this embodiment, two ways of creating texture objects are provided, and one or more of them can be configured according to actual usage needs, which are not limited herein.

[0083] Corresponding to the above method embodiment, an embodiment of the present invention further provides a three-dimensional terrain trimming device, and the three-dimensional terrain trimming device described below can be mutually referred to with the three-dimensional terrain trimming method described above.

[0084] See Figure 2 As shown, the device includes the following modules:

[0085] The polygon determination unit 110 is mainly used to determine the polygon to be trimmed and the corresponding projection plane in the three-dimensional terrain model;

[0086] The projection processing unit 120 is mainly used to project the polygon to be trimmed onto the projection plane to obtain a projected polygon and determine the bounding rectangle of the projected polygon;

[0087] The texture drawing unit 130 is mainly used to draw the projected polygon in the texture object and fill it according to the set filling color;

[0088] The texture coordinate determination unit 140 is mainly used to call the fragment shader to project the coordinates of each fragment in the three-dimensional terrain model onto the projection plane and determine the texture coordinates of each fragment according to the bounding rectangle;

[0089] The filling judgment unit 150 is mainly used to obtain the texture value corresponding to the texture coordinate in the texture object and judge whether the texture value is the filling color; if so, trigger the fragment culling unit 160;

[0090] The fragment culling unit 160 is mainly used to cull fragments in the fragment shader.

[0091] Corresponding to the above method embodiment, an embodiment of the present invention further provides a computer device, and a computer device described below can be mutually referred to with a three-dimensional terrain trimming method described above.

[0092] The computer device includes:

[0093] A memory for storing a computer program;

[0094] A processor, which is configured to implement the steps of the three-dimensional terrain clipping method in the above method embodiments when executing a computer program.

[0095] Specifically, please refer to Figure 3 , which is a schematic structural diagram of a computer device provided in this embodiment. The computer device may vary greatly due to different configurations or performances, and may include one or more processors (central processing units, CPUs) 322 (for example, one or more processors) and a memory 332. The memory 332 stores one or more computer application programs 342 or data 344. Among them, the memory 332 may be short-term storage or persistent storage. The program stored in the memory 332 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the data processing device. Further, the central processor 322 may be configured to communicate with the memory 332 and execute a series of instruction operations in the memory 332 on the computer device 301.

[0096] The computer device 301 may further include one or more power supplies 326, one or more wired or wireless network interfaces 350, one or more input / output interfaces 358, and / or one or more operating systems 341.

[0097] The steps in the three-dimensional terrain clipping method described above may be implemented by the structure of the computer device.

[0098] Corresponding to the above method embodiments, an embodiment of the present invention further provides a readable storage medium. The following-described readable storage medium may be correspondingly referred to the above-described three-dimensional terrain clipping method.

[0099] A readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the three-dimensional terrain clipping method in the above method embodiments are implemented.

[0100] The readable storage medium may specifically be a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc, etc., which are various readable storage media that can store program codes.

[0101] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.

Claims

1. A three-dimensional terrain clipping method, characterized in that, include: Determine a polygon to be clipped in the three-dimensional terrain model and a corresponding projection plane, wherein the projection plane is used to provide a common coordinate system for the clipping polygon and the fragment of the three-dimensional terrain model in the fragment shader; Projecting the polygon to be clipped onto the projection plane to obtain a projection polygon, and determining an enclosing rectangle of the projection polygon; Draw the projected polygon in the texture object and fill it with the set fill color; Calling a fragment shader to project the coordinates of each fragment in the three-dimensional terrain model onto the projection plane, and determining the texture coordinates of each fragment according to the enclosing rectangle; Obtaining a texture value corresponding to the texture coordinate in the texture object, and determining whether the texture value is the fill color; If so, the fragment is culled in the fragment shader.

2. The three-dimensional terrain clipping method according to claim 1, wherein Before determining the texture coordinates of each of the fragments according to the enclosing rectangle, the method further includes: Determine whether the projection position of each of the fragments is within the enclosing rectangle; If it is within the enclosing rectangle, the step of determining the texture coordinates of each of the fragments according to the enclosing rectangle is performed.

3. The three-dimensional terrain clipping method according to claim 2, characterized in that, The determining of the enclosing rectangle of the projected polygon comprises: Taking the centroid of the polygon to be clipped as the origin, determining the coordinate axis of the projection plane; Obtain an enclosing rectangle of the projection polygon in the projection plane that is parallel to the coordinate axis.

4. The three-dimensional terrain clipping method according to claim 3, wherein, The obtaining of an enclosing rectangle of the projected polygon in the projection plane that is parallel to the coordinate axis includes: determining a minimum enclosing rectangle of the projected polygon in the projection plane that is parallel to the coordinate axis.

5. The three-dimensional terrain clipping method according to claim 1, characterized in that, The projecting the to-be-cut polygon onto the projection plane comprises: Each vertex of the polygon to be clipped is projected onto the projection plane, and a polygon generated by sequentially connecting each projected vertex is used as the projection polygon.

6. The three-dimensional terrain clipping method according to claim 1, characterized in that Before drawing the projection polygon in the texture object, the method further includes: obtaining a default size to create a square texture object.

7. The three-dimensional terrain clipping method according to claim 1, wherein Before drawing the projection polygon in the texture object, the method further includes: A texture object with a matching size is created according to the aspect ratio of the enclosing rectangle.

8. A three-dimensional terrain clipping device, characterized in that include: A polygon determination unit, used to determine a polygon to be clipped in a three-dimensional terrain model and a corresponding projection plane, wherein the projection plane is used to provide a common coordinate system for the clipping polygon and the fragment of the three-dimensional terrain model in the fragment shader; A projection processing unit, used for projecting the polygon to be clipped onto the projection plane to obtain a projection polygon, and determining an enclosing rectangle of the projection polygon; A texture drawing unit, used for drawing the projection polygon in the texture object and filling it according to a set fill color; A texture coordinate determination unit, configured to call a fragment shader to project the coordinates of each fragment in the three-dimensional terrain model onto the projection plane, and determine the texture coordinates of each fragment according to the enclosing rectangle; A filling judgment unit, used for obtaining a texture value corresponding to the texture coordinate in the texture object, and judging whether the texture value is the filling color; if so, triggering a fragment culling unit; The fragment culling unit is used to cull the fragment in the fragment shader.

9. A computer device, characterized in that, include: A memory for storing a computer program; A processor for implementing the steps of the three-dimensional terrain clipping method according to any one of claims 1 to 7 when executing the computer program.

10. A readable storage medium, characterized in that, A computer program is stored on the readable storage medium, and when the computer program is executed by a processor, the steps of the three-dimensional terrain clipping method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Web end real-time interaction flood routing simulation visualization method

    CN110555234A

  • Data processing method and device for terrain matching

    CN114155346A