Map rendering method for unity, electronic device and readable storage medium

文档序号:170506 发布日期:2021-10-29 浏览:30次 中文

阅读说明:本技术 一种用于unity的渲染地图方法、电子设备及可读存储介质 (Map rendering method for unity, electronic device and readable storage medium ) 是由 白启扉 于 2021-07-29 设计创作,主要内容包括:本发明公开了一种用于unity的渲染地图方法、电子设备及可读存储介质,方法步骤依次为,根据地图最大zoom等级定义地图网格的最大长宽,利用unity API创建mesh,mesh中的网格对应地图网格;根据当前zoom等级和经纬度信息,获取地图瓦片图片地址;获取地图瓦片图片,将其作为uv纹理贴到mesh上;地图缩放时,根据当前zoom等级,动态调整mesh,实现地图快速渲染。本发明可以控制地图渲染的细节,在地图层上覆盖unity内容,并且能够在编辑器上方便开发。(The invention discloses a map rendering method for unity, an electronic device and a readable storage medium, wherein the method comprises the steps of defining the maximum length and width of a map grid according to the maximum zoom level of a map, and creating a mesh by utilizing unity API, wherein the grid in the mesh corresponds to the map grid; acquiring a map tile picture address according to the current zoom grade and the longitude and latitude information; obtaining a map tile picture, and pasting the map tile picture as a uv texture to the mesh; and when the map is zoomed, dynamically adjusting the mesh according to the current zoom level, and realizing the rapid rendering of the map. The invention can control the details of map rendering, cover unity content on the map layer and can be developed conveniently on an editor.)

1. A map rendering method for unity, comprising the steps of:

(1) defining the maximum length and width of a map grid according to the maximum zoom level of the map, and creating a mesh by using a unity API (application programming interface), wherein the grid in the mesh corresponds to the map grid;

(2) acquiring a map tile picture address according to the current zoom grade and the longitude and latitude information;

(3) obtaining a map tile picture, and pasting the map tile picture as a uv texture to the mesh;

(4) and when the map is zoomed, dynamically adjusting the mesh according to the current zoom level, and realizing the rapid rendering of the map.

2. The map rendering method for unity according to claim 1, wherein in step (2), the tile map service based on the OSM map data is built by mapnik2, apache2 and mod _ tile.

3. The map rendering method for unity according to claim 1, wherein in step (3), the map tile picture is obtained through API of unity, resources.

4. The map rendering method for unity according to claim 1, wherein in step (4), when the zoom level is switched from high to low, the meshes in the mesh are merged; when the zoom level is switched from low to high, the grid in the mesh is split.

5. The unit map rendering method of claim 4, wherein when the zoom level is switched from a to b, a > b, determining vertices a to be deleted, recording all vertices connected to the vertices a, deleting the connection lines between the recorded vertices and the vertices a, and finally connecting two vertices of the recorded vertices which are farthest from the vertices a;

when the zoom level is switched from b to a, the operation process is the reverse of the above process.

6. An electronic device, comprising a processor and a memory, wherein the memory stores execution instructions of the processor, and the processor is configured to execute the execution instructions to implement the map rendering method for unity according to any one of claims 1-5.

7. A computer-readable storage medium storing a program, wherein the program is executed to implement the map rendering method for unity according to any one of claims 1 to 5.

Technical Field

The invention belongs to the field of unity development, and particularly relates to a unity map rendering technology.

Background

At present, maps are increasingly widely applied to interactive apps such as take-out, navigation and scene display, and the Unity integrates the maps mainly by calling an SDK (security description key) for packaging android and ios provided by Baidu and the like.

The existing method has more limitations:

1. SDK provided by Baidu Gade realizes view interfaces under different platforms, and unity cannot interact with and cover more contents on the SDK;

2. baidu God only provides a mobile SDK, and the unit pc editor cannot be debugged and is inconvenient to develop;

3. the SDK of the Baidu God map rendering does not open source codes, and rendering efficiency cannot be optimized.

Disclosure of Invention

In order to solve the technical problems mentioned in the background art, the present invention provides a method, an electronic device, and a readable storage medium for rendering a map for unity, which can control details of map rendering, cover unity content on a map layer, and can be conveniently developed on an editor.

In order to achieve the technical purpose, the technical scheme of the invention is as follows:

a map rendering method for unity, comprising the steps of:

(1) defining the maximum length and width of a map grid according to the maximum zoom level of the map, and creating a mesh by using a unity API (application programming interface), wherein the grid in the mesh corresponds to the map grid;

(2) acquiring a map tile picture address according to the current zoom grade and the longitude and latitude information;

(3) obtaining a map tile picture, and pasting the map tile picture as a uv texture to the mesh;

(4) and when the map is zoomed, dynamically adjusting the mesh according to the current zoom level, and realizing the rapid rendering of the map.

Further, in step (2), a tile map service based on OSM map data is built through mapnik2, apache2, and mod _ tile.

Further, in step (3), the map tile picture is obtained through the API of unity, resources.

Further, in step (4), when the zoom level is switched from high to low, merging the grids in the mesh; when the zoom level is switched from low to high, the grid in the mesh is split.

Further, when the zoom level is switched from a to b, a > b, determining vertexes A needing to be deleted, recording all vertexes connected with the vertexes A, deleting connecting lines between the recorded vertexes and the vertexes A, and finally connecting two vertexes which are farthest away from the vertexes A in the recorded vertexes;

when the zoom level is switched from b to a, the operation process is the reverse of the above process.

An electronic device comprises a processor and a memory, wherein the memory stores execution instructions of the processor, and the processor is configured to execute the execution instructions to realize the map rendering method for unity.

A computer-readable storage medium for storing a program, which is executed to implement the above-described map rendering method for unity.

Adopt the beneficial effect that above-mentioned technical scheme brought:

1. according to the invention, the tile map is directly rendered by using the C # without depending on other SDKs, so that the tile map of each level can be rapidly rendered;

2. the source code of the bottom rendering part of the invention is controllable and can be directly debugged in an editor;

3. the invention can make any customization to the map and cover the unity content.

Drawings

FIG. 1 is a flow chart of a method of the present invention;

FIG. 2 is a schematic diagram of mesh generation in the present invention;

fig. 3 is a schematic diagram of zoom level switching mesh change in the present invention.

Detailed Description

The technical scheme of the invention is explained in detail in the following with the accompanying drawings.

The invention designs a map rendering method for unity, which comprises the following steps as shown in figure 1:

step 1: and defining the maximum length and width of the map grid according to the maximum zoom level of the map, and creating a mesh by using a unity API (application programming interface), wherein the grid in the mesh corresponds to the map grid. As shown in fig. 2, for example, if a region zoom is 4, 4 × 4 tiles are to be displayed, the generated mesh needs 4 × 4=16 grids, and a total of 32 triangular surfaces.

Step 2: and obtaining the map tile picture address according to the current zoom grade and the latitude and longitude information. In the present embodiment, the tile map service based on OSM map data is built by mapnik2, apache2, and mod _ tile.

And step 3: and acquiring a map tile picture, and pasting the map tile picture as a uv texture to the mesh. In this embodiment, the map tile picture is obtained through the API of unity, resources.

And 4, step 4: and when the map is zoomed, dynamically adjusting the mesh according to the current zoom level, and realizing the rapid rendering of the map. For example, when the map zoom level is switched from 4 to 3, the original graph is as the left graph (a) in fig. 3, and it is necessary to find out the vertex (1, 1) to be deleted, and record all the vertices connected by (1, 1): (0, 1), (1, 0), (1, 2), (2, 1), (0, 2), (2, 0), all connecting lines are deleted to obtain a middle graph (b), and finally two points (0, 2), (2, 0) farthest from the point (1, 1) are connected to obtain a right graph (c).

Expressed algorithmically, the following are:

For i in 0:n:

For j in 0:n:

X = i + 1;

Y = j + 1;

i+=2;

j+=2;

clear (X, Y);/Clear (X, Y) all the connecting lines at the point

MakeSquareIn (X, Y);/create a new square of two triangles at point (X, Y).

If the map level is switched from 3 to 4, the reverse operation of the above steps is performed. In the step, all grid points of the maximum zoom level are cached, and the mesh grid is dynamically adjusted according to different zoom levels operated by the current user, so that the effect of quick rendering is achieved.

The invention also designs an electronic device, which comprises a processor and a memory, wherein the memory stores execution instructions of the processor, and the processor is configured to execute the execution instructions to realize the map rendering method for unity.

The present invention also contemplates a computer-readable storage medium storing a program, which is executed to implement the above-described map rendering method for unity.

The embodiments are only for illustrating the technical idea of the present invention, and the technical idea of the present invention is not limited thereto, and any modifications made on the basis of the technical scheme according to the technical idea of the present invention fall within the scope of the present invention.

7页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:线路模型的地形自适应方法、装置、电子设备及存储介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!