Method and device for drawing three-dimensional model in Unity3D based on map data

By extracting lines and closed lines in map data, and using Unity3D material spheres and three-dimensional model drawing algorithms to build a three-dimensional model in Unity3D, the problem of converting map data into three-dimensional models in the existing technology is solved, and efficient and accurate three-dimensional map display is achieved.

CN114022623BActive Publication Date: 2025-03-07WUHAN FIBERHOME INFORMATION INTEGRATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111275039.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-29
Publication Date
2025-03-07
Estimated Expiration
2041-10-29

AI Technical Summary

Technical Problem

There is no method for converting map data into three-dimensional models in the prior art, especially in the Unity3D game engine, which leads to difficulties in displaying map data in three-dimensional ways.

Method used

By extracting lines and closed lines in map data, Unity3D material balls are created, and the lines and closed lines are modeled using preset and set three-dimensional model drawing algorithms, and the material balls are assigned to build a three-dimensional model.

Benefits of technology

It realizes efficient construction of a three-dimensional model of map data in Unity3D. The construction method is simple and efficient, avoids manual errors, significantly reduces the workload of scene construction, and improves rendering performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114022623B_ABST
    Figure CN114022623B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for drawing a three-dimensional model in Unity3D based on map data, and relates to the technical field of three-dimensional display of map data. The method comprises extracting the line and closed line required for three-dimensional model creation based on the data source of map data; creating a Unity3D material ball according to the model of the line, and creating a Unity3D material ball according to the model of the closed line; modeling the closed line based on a preset three-dimensional model drawing algorithm, and assigning it to the created Unity3D material ball; modeling the line based on a set three-dimensional model drawing algorithm, and assigning it to the created Unity3D material ball. The present invention has a simple construction method and high efficiency, and modeling based on real map data can effectively avoid human errors.
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 display of map data, and in particular to a method and device for drawing a three-dimensional model in Unity3D based on map data. Background Art

[0002] Unity3D is a 3D game production engine. With its cross-platform and open advantages, it has gradually become the mainstream game engine in the world. Unity 3D is well-known for its powerful cross-platform features and gorgeous 3D rendering effects. Now many commercial games and virtual reality products are developed using the Unity 3D engine. The reason why the Unity3D game development engine is so popular is inseparable from its perfect technology and rich personalized functions. The Unity 3D game development engine is easy to use, which reduces the requirements for game developers.

[0003] In the field of map making, three-dimensional maps are now widely used. However, when converting map data into three-dimensional models, different processing is required on different platforms, and there is currently no method for converting map data into three-dimensional models in the Unity3D game engine. Summary of the invention

[0004] In view of the defects existing in the prior art, the purpose of the present invention is to provide a method and device for drawing a three-dimensional model in Unity3D based on map data. The construction method is simple and efficient. At the same time, modeling according to real map data can effectively avoid human errors.

[0005] To achieve the above objectives, the present invention provides a method for drawing a three-dimensional model in Unity3D based on map data, which specifically includes the following steps:

[0006] Based on the data source of map data, extract the lines and closed lines required for 3D model creation;

[0007] Create a Unity3D material ball according to the line model, and create a Unity3D material ball according to the closed line model;

[0008] Model the closed line based on the preset 3D model drawing algorithm and assign it to the created Unity3D material ball;

[0009] The line is modeled based on the set 3D model drawing algorithm and assigned to the created Unity3D material ball.

[0010] Based on the above technical solutions,

[0011] The route is a road network on a map;

[0012] The closed line includes lakes, buildings, and administrative divisions on the map.

[0013] On the basis of the above technical solution, the closed line is modeled based on a preset three-dimensional model drawing algorithm, and the specific steps include:

[0014] Constructing a first coordinate data linked list based on the coordinates of the closed line, and drawing the model bottom surface of the closed line according to a planar polygon drawing algorithm;

[0015] Constructing a second coordinate data linked list based on the sum of the coordinates and the height of the closed line, and drawing the top surface of the model of the closed line according to the planar polygon drawing algorithm;

[0016] Draw the model side of the closed line according to the first coordinate data linked list and the second coordinate data linked list;

[0017] Corresponding UV and Unity3D materials are assigned to the bottom surface, top surface and side surface of the model.

[0018] On the basis of the above technical solution, the model side of the closed line is drawn according to the first coordinate data linked list and the second coordinate data linked list, specifically:

[0019] Draw triangles in the order of [P1(0), P2(0), P1(1)], [P1(0), P2(1), P1(1)], [P1(1), P2(1), P1(2)], [P1(1), P2(2), P1(2)]…[P1(i), P2(i), P1(i+1)], [P1(i), P2(i+1), P1(i+1)]…[P1(n), P2(n), P1(0)], [P1(n), P2(0), P1(0)] to obtain the model side of the closed line;

[0020] Wherein, P1 represents the first coordinate data linked list, P2 represents the second coordinate data linked list, n represents the total number of coordinates in the first coordinate data linked list and the second coordinate data linked list, and the total number of coordinates in the first coordinate data linked list is the same as the total number of coordinates in the second coordinate data linked list;

[0021] Wherein, P1(i) represents the i-th coordinate in the first coordinate data linked list, P2(i) represents the i-th coordinate in the second coordinate data linked list, P1(n) represents the n-th coordinate in the first coordinate data linked list, and P2(n) represents the n-th coordinate in the second coordinate data linked list;

[0022] Among them, [P1(i), P2(i), P1(i+1)] represents the triangle formed by the three coordinates P1(i), P2(i) and P1(i+1); [P1(i), P2(i+1), P1(i+1)] represents the triangle formed by the three coordinates P1(i), P2(i+1) and P1(i+1); [P1(n), P2(n), P1(0)] represents the triangle formed by the three coordinates P1(n), P2(n) and P1(0); [P1(n), P2(0), P1(0)] represents the triangle formed by the three coordinates P1(n), P2(0) and P1(0).

[0023] On the basis of the above technical solution, the specific steps of the planar polygon drawing algorithm for polygon drawing are:

[0024] S201: Acquire the coordinates of the polygon to be drawn and construct a coordinate data linked list, and number the coordinates in the coordinate data linked list, and go to S202;

[0025] S202: Determine whether the number of coordinates in the coordinate data linked list is greater than 3, if so, go to S203, if not, go to S209;

[0026] S203: based on the numbering sequence of the coordinates in the coordinate data linked list, obtain a coordinate as the current coordinate, and go to S204;

[0027] S204: Obtain the previous coordinate and the next coordinate adjacent to the current coordinate, and determine whether the three coordinate points are on the same straight line. If so, go to S206; if not, go to S207;

[0028] S206: Delete the current coordinate from the coordinate data linked list, and then go to S202;

[0029] S207: Based on the vector normal algorithm, determine whether the three coordinates are all convex points of the polygon to be drawn, and whether the three coordinates do not contain other coordinates in the coordinate data linked list; if yes, go to S208; otherwise, go to S209;

[0030] S208: Draw a triangle based on the three coordinates, then delete the three coordinates from the coordinate data linked list, and then go to S202;

[0031] S208: taking the coordinates adjacent to the current coordinates as the current coordinates, and then going to S204;

[0032] S209: Based on the number of coordinates in the coordinate data linked list, when a triangle can be drawn, a triangle is drawn, and then a polygon is drawn based on all the drawn triangles; when a triangle cannot be drawn, a polygon is drawn based on all the drawn triangles.

[0033] On the basis of the above technical solution, the line modeling is performed based on the setting of the three-dimensional model drawing algorithm, and the specific steps include:

[0034] Calculate the left and right coordinates of the starting point of the route corresponding to the road surface based on the first preset algorithm;

[0035] The coordinates of the left and right sides of the road surface corresponding to the middle point of the line are calculated based on the second preset algorithm;

[0036] The coordinates of the left and right sides of the road surface corresponding to the end point of the route are calculated based on the third preset algorithm;

[0037] According to all the left coordinates in the obtained left and right coordinates of the starting point, the middle point and the end point, a left coordinate data linked list is established;

[0038] According to all the right side coordinates in the obtained left and right side coordinates of the starting point, the middle point and the end point, a right side coordinate data linked list is established;

[0039] According to the established left coordinate data linked list and right coordinate data linked list, triangles are drawn in the order of [PR(0), PR(1), PL(0)], [PL(0), PR(1), PL(1)], [PR(1), PR(2), PL(1)], [PR(1), PR(2), PL(2)] ... [PR(i), PR(i+1), PL(i)], [PL(i), PR(i+1), PL(i+1)] ... [PR(m-1), PR(m), PL(m-1)], [PR(m-1), PR(m), PL(m)] to obtain a line model;

[0040] Assign corresponding UV and Unity3D materials to the line model;

[0041] Wherein, PL(i) represents the i-th coordinate in the left coordinate data linked list PL, PR(i) represents the i-th coordinate in the right coordinate data linked list PR, m represents the total number of coordinates in the left coordinate data linked list and the right coordinate data linked list, and the total number of coordinates in the left coordinate data linked list is the same as the total number of coordinates in the right coordinate data linked list, PL(m) represents the m-th coordinate in the left coordinate data linked list, and PR(m) represents the m-th coordinate in the right coordinate data linked list;

[0042] Among them, [PR(i), PR(i+1), PL(i)] represents the triangle formed by the three coordinates PR(i), PR(i+1) and PL(i), [PL(i), PR(i+1), PL(i+1)] represents the triangle formed by the three coordinates PL(i), PR(i+1) and PL(i+1), [PR(m-1), PR(m), PL(m-1)] represents the triangle formed by the three coordinates PR(m-1), PR(m) and PL(m-1), and [PR(m-1), PR(m), PL(m)] represents the triangle formed by the three coordinates PR(m-1), PR(m), PL(m).

[0043] On the basis of the above technical solution, the coordinates of the left and right sides of the road surface corresponding to the starting point of the route are calculated based on the first preset algorithm, wherein:

[0044] The calculation formula for the right coordinate of the starting point of the line corresponding to the road surface is:

[0045] PR(0)=P(0)+dlrn×up×width*0.5

[0046] Where PR(0) represents the right coordinate of the starting point P(0) of the line, up represents the unit vector in the upward direction in Unity3d, dlrn=P(1)-P(0), dlrn represents the direction vector at the starting point of the line, P(1) represents the second point of the line, and width represents the width of the road surface;

[0047] The calculation formula for the right coordinate of the starting point of the line corresponding to the road surface is:

[0048] PL(0)=P(0)-dlrn×up×width*0.5

[0049] Among them, PL(0) represents the left coordinate of the starting point P(0) of the line.

[0050] On the basis of the above technical solution, the coordinates of the left and right sides of the road surface corresponding to the middle point of the line are calculated based on the second preset algorithm, specifically including:

[0051] The line direction angle is calculated based on the line direction vector. The calculation formula is:

[0052] dlr1=P(i+1)-P(i)

[0053] dlr2=P(i)-P(i-1)

[0054] α=arccos(dlr 1×dlr 2) / (|dlr 1|×|dlr 2|)

[0055] Wherein, dlr1 and dlr 2 both represent the line direction vector, P(i) represents the i-th midpoint of the line, α represents the line direction angle, and arccos represents the arccosine calculation;

[0056] Determine the calculated line direction angle:

[0057] When α<180°,

[0058] PR(i)=P(i)+Normalize((dlr1-dlr2)×width*0.5

[0059] PL(i)=P(i)-Normalize((dlr1-dlr2)×width*0.5

[0060] Among them, PR(i) represents the right coordinate of the i-th middle point of the line, PL(i) represents the left coordinate of the i-th middle point of the line, Normalize is the vector normalization calculation method in Unity, and width represents the width of the road surface;

[0061] When α=180°,

[0062] PR(i)=P(i)-Normalize(dlr1-dlr2)×width*0.5

[0063] PL(i)=P(i)+Normalize(dlr1-dlr2)×width*0.5.

[0064] On the basis of the above technical solution, the coordinates of the left and right sides of the road surface corresponding to the end point of the route are calculated based on the third preset algorithm, wherein:

[0065] The calculation formula for the right coordinate of the road surface corresponding to the end point of the line is:

[0066] PR(m)=P(m)+dlrm×up×width*0.5

[0067] Wherein, PR(m) represents the right coordinate of the end point P(m) of the line, up represents the unit vector in the upward direction in Unity3d, dlrm=P(m)-P(m-1), dlrm represents the line direction vector, and width represents the width of the road surface;

[0068] The calculation formula for the right coordinate of the road surface corresponding to the end point of the line is:

[0069] PL(m)=P(m)-dlrm×up×width*0.5

[0070] Wherein, PL(m) represents the left coordinate of the end point P(m) of the line.

[0071] The present invention provides a device for drawing a three-dimensional model in Unity3D based on map data, comprising:

[0072] An extraction module is used to extract the lines and closed lines required for creating a three-dimensional model based on the data source of the map data;

[0073] A creation module, which is used to create a Unity3D material ball according to the model of the line, and to create a Unity3D material ball according to the model of the closed line;

[0074] A first assigning module is used to model the closed line based on a preset three-dimensional model drawing algorithm, and assign it to the created Unity3D material ball accordingly;

[0075] The second assignment module is used to model the line based on the set three-dimensional model drawing algorithm and assign it to the created Unity3D material ball accordingly.

[0076] Compared with the prior art, the advantages of the present invention are: through a data source based on map data, lines and closed lines that need to be created for three-dimensional modeling are extracted, and then according to the models of the lines and closed lines, Unity3D material balls are created accordingly, and the closed lines are modeled, and the constructed models are assigned to the created Unity3D material balls accordingly, and the lines are modeled, and the constructed models are assigned to the created Unity3D material balls accordingly, thereby constructing a Unity3D scene of the map data, and the construction method is simple and efficient. At the same time, modeling according to real map data can effectively avoid human errors. BRIEF DESCRIPTION OF THE DRAWINGS

[0077] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0078] Figure 1 It is a flowchart of a method for drawing a three-dimensional model in Unity3D based on map data in an embodiment of the present invention;

[0079] Figure 2 The present invention is a schematic diagram of the structure of a device for drawing a three-dimensional model in Unity3D based on map data in an embodiment of the present invention. DETAILED DESCRIPTION

[0080] The embodiment of the present invention provides a method for drawing a three-dimensional model in Unity3D based on map data. Through a data source based on map data, the lines and closed lines required for the three-dimensional model creation are extracted, and then a Unity3D material ball is created according to the models of the lines and closed lines, and the closed lines are modeled, and the constructed models are assigned to the created Unity3D material ball, and the lines are modeled, and the constructed models are assigned to the created Unity3D material ball, so as to construct a Unity3D scene of the map data. The construction method is simple and efficient, and modeling according to real map data can effectively avoid human errors. The embodiment of the present invention also provides a device for drawing a three-dimensional model in Unity3D based on map data.

[0081] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0082] See also Figure 1 As shown, a method for drawing a three-dimensional model in Unity3D based on map data provided by an embodiment of the present invention specifically includes the following steps:

[0083] S1: Based on the data source of the map data, extract the lines and closed lines required for creating the three-dimensional model; in the embodiment of the present invention, the lines are the road network on the map; the closed lines are the closed units on the map, such as lakes, buildings and administrative divisions.

[0084] S2: Create a Unity3D material ball according to the line model, and create a Unity3D material ball according to the closed line model, which is equivalent to preparing the corresponding Unity3D material ball for the line and closed line models; the Unity3D material ball is the material ball of the Unity3D game engine, similar to the fabric and pattern of clothes, as well as the material of buildings and roads. For example, create a Unity3D material ball for the road network model, and create a Unity3D material ball for the building model.

[0085] S3: Modeling the closed line based on a preset three-dimensional model drawing algorithm, and assigning it to the created Unity3D material ball accordingly; that is, based on the actual shape of the closed line, modeling is performed using a preset three-dimensional model drawing algorithm, and then the established model is assigned to the corresponding Unity3D material ball created in step S2.

[0086] S4: Modeling the line based on the set 3D model drawing algorithm, and assigning it to the created Unity3D material ball. That is, based on the actual shape of the line, modeling is performed by setting the 3D model drawing algorithm, and then the established model is assigned to the corresponding Unity3D material ball created in step S2.

[0087] When the closed circuit and the model of the circuit are assigned to the Unity3D material ball, the Unity3D scene can be constructed. The Unity3D scene is a small world built by the Unity3D game engine.

[0088] In the embodiment of the present invention, the closed line is modeled based on a preset three-dimensional model drawing algorithm, and the specific steps include:

[0089] S301: constructing a first coordinate data linked list based on the coordinates of the closed line, and drawing the model bottom surface of the closed line according to the planar polygon drawing algorithm; the coordinate data linked list is an array or list composed of coordinate data.

[0090] S302: Construct a second coordinate data linked list based on the sum of the coordinates and the height of the closed line, and draw the model top surface of the closed line according to the planar polygon drawing algorithm; that is, add the coordinates and the height of the closed line to obtain the coordinates to construct the second coordinate data linked list. For closed lines without height such as lakes, administrative divisions, etc., a height can be customized.

[0091] S303: Draw the model side of the closed line according to the first coordinate data linked list and the second coordinate data linked list;

[0092] S304: assigning corresponding UV (used to record how the texture on the model should be pasted and the coordinate data of where to paste it) and Unity3D material to the bottom surface, top surface and side surface of the model.

[0093] In the embodiment of the present invention, the model side of the closed line is drawn according to the first coordinate data linked list and the second coordinate data linked list, specifically:

[0094] Draw triangles in the order of [P1(0), P2(0), P1(1)], [P1(0), P2(1), P1(1)], [P1(1), P2(1), P1(2)], [P1(1), P2(2), P1(2)]…[P1(i), P2(i), P1(i+1)], [P1(i), P2(i+1), P1(i+1)]…[P1(n), P2(n), P1(0)], [P1(n), P2(0), P1(0)] to obtain a closed circuit model. Side surface; that is, draw triangles in the order of [P1(0), P2(0), P1(1)], [P1(0), P2(1), P1(1)], [P1(1), P2(1), P1(2)], [P1(1), P2(2), P1(2)], [P1(2), P2(2), P1(3)], [P1(2), P2(3), P1(3)], [P1(3), P2(3), P1(4)], [P1(3), P2(4), P1(4)]… to obtain the model side surface of the closed circuit.

[0095] Wherein, P1 represents the first coordinate data linked list, P2 represents the second coordinate data linked list, n represents the total number of coordinates in the first coordinate data linked list and the second coordinate data linked list, and the total number of coordinates in the first coordinate data linked list is the same as the total number of coordinates in the second coordinate data linked list;

[0096] Wherein, P1(i) represents the i-th coordinate in the first coordinate data linked list, P2(i) represents the i-th coordinate in the second coordinate data linked list, P1(n) represents the n-th coordinate in the first coordinate data linked list, and P2(n) represents the n-th coordinate in the second coordinate data linked list;

[0097] Among them, [P1(i), P2(i), P1(i+1)] represents the triangle formed by the three coordinates P1(i), P2(i) and P1(i+1); [P1(i), P2(i+1), P1(i+1)] represents the triangle formed by the three coordinates P1(i), P2(i+1) and P1(i+1); [P1(n), P2(n), P1(0)] represents the triangle formed by the three coordinates P1(n), P2(n) and P1(0); [P1(n), P2(0), P1(0)] represents the triangle formed by the three coordinates P1(n), P2(0) and P1(0).

[0098] In the embodiment of the present invention, the specific steps of drawing polygons by the planar polygon drawing algorithm are as follows:

[0099] S201: Acquire the coordinates of the polygon to be drawn and construct a coordinate data linked list, and number the coordinates in the coordinate data linked list, and go to S202;

[0100] S202: Determine whether the number of coordinates in the coordinate data linked list is greater than 3, if so, go to S203, if not, go to S209;

[0101] S203: based on the numbering sequence of the coordinates in the coordinate data linked list, obtain a coordinate as the current coordinate, and go to S204;

[0102] S204: Obtain the previous coordinate and the next coordinate adjacent to the current coordinate, and determine whether the three coordinate points are on the same straight line. If so, go to S206; if not, go to S207;

[0103] S206: Delete the current coordinate from the coordinate data linked list, and then go to S202;

[0104] S207: Based on the vector normal algorithm, determine whether the three coordinates are all convex points of the polygon to be drawn, and whether the three coordinates do not contain other coordinates in the coordinate data linked list; if yes, go to S208; otherwise, go to S209;

[0105] S208: Draw a triangle based on the three coordinates, then delete the three coordinates from the coordinate data linked list, and then go to S202;

[0106] S208: taking the coordinates adjacent to the current coordinates as the current coordinates, and then going to S204;

[0107] S209: Based on the number of coordinates in the coordinate data linked list, when a triangle can be drawn, a triangle is drawn, and then a polygon is drawn based on all the drawn triangles; when a triangle cannot be drawn, a polygon is drawn based on all the drawn triangles.

[0108] For step S209, for example, when the number of coordinates in the coordinate data linked list is 3, it indicates that it is possible to draw triangles again, and when these 3 can draw a triangle, triangle drawing is performed, and then polygons are drawn based on all the drawn triangles; for example, when the number of coordinates in the coordinate data linked list is 0, 1 or 2, it indicates that triangle drawing is no longer possible, and polygons are drawn based on all the drawn triangles.

[0109] According to the planar polygon drawing algorithm of the present invention, at most N-2 triangles will be drawn (where N is the number of polygon vertices). If three adjacent vertices are on the same straight line during the drawing process, the algorithm will eliminate the middle coordinate point. At this time, the number of triangles drawn will be further optimized, and the number of triangles drawn will be less than N-2.

[0110] In the embodiment of the present invention, the line is modeled based on a set three-dimensional model drawing algorithm, and the specific steps include:

[0111] S401: Calculating the left and right coordinates of the starting point of the route corresponding to the road surface based on a first preset algorithm;

[0112] S402: Calculating the left and right coordinates of the road surface corresponding to the middle point of the line based on a second preset algorithm;

[0113] S403: Calculating the left and right coordinates of the road surface corresponding to the end point of the route based on the third preset algorithm;

[0114] S404: Establish a left coordinate data linked list according to all the left coordinates of the left and right coordinates of the starting point, the left and right coordinates of the middle point, and the left and right coordinates of the end point;

[0115] S405: establishing a right coordinate data linked list according to all the right coordinates of the left and right sides of the starting point, the left and right sides of the middle point, and the left and right sides of the end point;

[0116] S406: According to the established left coordinate data linked list and right coordinate data linked list, according to [PR(0), PR(1), PL(0)], [PL(0), PR(1), PL(1)], [PR(1), PR(2), PL(1)], [PR(1), PR(2), PL(2)] ... [PR(i), PR(i+1), PL(i)], [PL(i), PR(i+1), PL(i+1)] ... [PR(m-1), PR(m), PL(m-1) ], [PR(m-1), PR(m), PL(m)] to obtain a line model; that is, triangles are drawn in the order of [PR(0), PR(1), PL(0)], [PL(0), PR(1), PL(1)], [PR(1), PR(2), PL(1)], [PR(1), PR(2), PL(2)], [PR(2), PR(3), PL(2)], [PL(2), PR(3), PL(3)]… to obtain a line model.

[0117] S407: assigning corresponding UV and Unity3D materials to the line model;

[0118] Wherein, PL(i) represents the i-th coordinate in the left coordinate data linked list PL, PR(i) represents the i-th coordinate in the right coordinate data linked list PR, m represents the total number of coordinates in the left coordinate data linked list and the right coordinate data linked list, and the total number of coordinates in the left coordinate data linked list is the same as the total number of coordinates in the right coordinate data linked list, PL(m) represents the m-th coordinate in the left coordinate data linked list, and PR(m) represents the m-th coordinate in the right coordinate data linked list;

[0119] Among them, [PR(i), PR(i+1), PL(i)] represents the triangle formed by the three coordinates PR(i), PR(i+1) and PL(i), [PL(i), PR(i+1), PL(i+1)] represents the triangle formed by the three coordinates PL(i), PR(i+1) and PL(i+1), [PR(m-1), PR(m), PL(m-1)] represents the triangle formed by the three coordinates PR(m-1), PR(m) and PL(m-1), and [PR(m-1), PR(m), PL(m)] represents the triangle formed by the three coordinates PR(m-1), PR(m), PL(m).

[0120] It should be noted that the present invention stipulates that all lines are drawn horizontally in three-dimensional space by default, P(0), P(1)...P(m) are sequential points of the line, and each point extends width×0.5 on both sides to form a road surface with a width of width.

[0121] In the embodiment of the present invention, the coordinates of the left and right sides of the road surface corresponding to the starting point of the route are calculated based on the first preset algorithm, where:

[0122] The calculation formula for the right coordinate of the starting point of the line corresponding to the road surface is:

[0123] PR(0)=P(0)+dlrn×up×width*0.5

[0124] Where PR(0) represents the right coordinate of the starting point P(0) of the line, up represents the unit vector in the upward direction in Unity3d, dlrn=P(1)-P(0), dlrn represents the direction vector at the starting point of the line, P(1) represents the second point of the line, and width represents the width of the road surface;

[0125] The calculation formula for the right coordinate of the starting point of the line corresponding to the road surface is:

[0126] PL(0)=P(0)-dlrn×up×width*0.5

[0127] Among them, PL(0) represents the left coordinate of the starting point P(0) of the line.

[0128] In the embodiment of the present invention, the coordinates of the left and right sides of the road surface corresponding to the middle point of the line are calculated based on the second preset algorithm, specifically including:

[0129] S4021: The line direction angle is calculated based on the line direction vector. The calculation formula is:

[0130] dlr1=P(i+1)-P(i)

[0131] dlr2=P(i)-P(i-1)

[0132] α=arccos(dlr 1×dlr 2) / (|dlr 1|×|dlr 2|)

[0133] Wherein, dlr1 and dlr 2 both represent the line direction vector, P(i) represents the i-th midpoint of the line, α represents the line direction angle, and arccos represents the arccosine calculation;

[0134] S4022: Determine the calculated line direction angle:

[0135] When α<180°,

[0136] PR(i)=P(i)+Normalize((dlr1-dlr2)×width*0.5

[0137] PL(i)=P(i)-Normalize((dlr1-dlr2)×width*0.5

[0138] Among them, PR(i) represents the right coordinate of the i-th middle point of the line, PL(i) represents the left coordinate of the i-th middle point of the line, Normalize is the vector normalization calculation method in Unity, and width represents the width of the road surface;

[0139] When α=180°,

[0140] PR(i)=P(i)-Normalize(dlr1-dlr2)×width*0.5

[0141] PL(i)=P(i)+Normalize(dlr1-dlr2)×width*0.5.

[0142] In the embodiment of the present invention, the coordinates of the left and right sides of the road surface corresponding to the end point of the route are calculated based on the third preset algorithm, where:

[0143] S4031: The calculation formula for obtaining the coordinates of the right side of the road surface corresponding to the end point of the line is:

[0144] PR(m)=P(m)+dlrm×up×width*0.5

[0145] Wherein, PR(m) represents the right coordinate of the end point P(m) of the line, up represents the unit vector in the upward direction in Unity3d, dlrm=P(m)-P(m-1), dlrm represents the line direction vector, and width represents the width of the road surface;

[0146] S4032: The calculation formula for obtaining the right coordinate of the road surface corresponding to the end point of the route is:

[0147] PL(m)=P(m)-dlrm×up×width*0.5

[0148] Wherein, PL(m) represents the left coordinate of the end point P(m) of the line.

[0149] The following is a specific description of the method of drawing a three-dimensional model in Unity3D based on map data in the present invention, combined with an example of generating a Unity3D model based on OSM (OpenStreetMap, a freely editable world map) data. The specific steps include:

[0150] (1) Download map data in OSM format from OpenStreetMap;

[0151] (2) Changing the suffix of OSM data files to .xml enables XML format file inspection;

[0152] (3) Import XML point data into MySQL database;

[0153] (4) Delete nodes in the XML file and extract data such as buildings, lakes, and road networks;

[0154] (5) Read the XML file in step (4) in Unity3D, then select the line data (road network) and read the coordinate list information of the road network from the database, and use the above-mentioned set three-dimensional model drawing algorithm to draw the road network model;

[0155] (6) Read the XML file of step (4) in Unity3D, then select the closed road network data (lakes, buildings, administrative divisions, etc.) and read the coordinate list information of the closed line from the database, and use the above-mentioned preset 3D model drawing algorithm to draw various closed line models;

[0156] (7) Assigning a material ball of the corresponding type to the model drawn in steps (5) and (6);

[0157] (8) Take the model generated in steps (5) and (6) and use Unity's built-in lighting to build a basic environment scene.

[0158] The present invention avoids human errors by modeling based on real map data; automatically generates a relatively simple three-dimensional model, which greatly reduces the workload brought by building a Unity3D scene environment in some cases; generates very few triangles, which significantly improves the rendering consumption after the computer drawing is completed.

[0159] The method for drawing a three-dimensional model in Unity3D based on map data in an embodiment of the present invention extracts the lines and closed lines required for three-dimensional model creation through a data source based on the map data, then creates a Unity3D material ball according to the models of the lines and closed lines, models the closed lines, assigns the created models to the created Unity3D material ball, models the lines, and assigns the created models to the created Unity3D material ball, thereby constructing a Unity3D scene of the map data. The construction method is simple and efficient, and modeling based on real map data can effectively avoid human errors.

[0160] See also Figure 2 As shown, an embodiment of the present invention provides a device for drawing a three-dimensional model in Unity3D based on map data, including an extraction module, a creation module, a first assignment module and a second assignment module.

[0161] The extraction module is used to extract the lines and closed lines required for three-dimensional model creation based on the data source of map data; the creation module is used to create a Unity3D material ball according to the model of the line, and to create a Unity3D material ball according to the model of the closed line; the first assignment module is used to model the closed line based on a preset three-dimensional model drawing algorithm, and assign it to the created Unity3D material ball; the second assignment module is used to model the line based on the set three-dimensional model drawing algorithm, and assign it to the created Unity3D material ball.

[0162] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.

[0163] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems) and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the process in the flowchart. Figure 1 A process or multiple processes and / or boxes Figure 1A device that provides the functions specified in a block or multiple blocks.

Claims

1. A method for drawing a three-dimensional model in Unity3D based on map data, characterized in that: The specific steps include: Based on the data source of map data, extract the lines and closed lines required for 3D model creation; Create a Unity3D material ball according to the line model, and create a Unity3D material ball according to the closed line model; Model the closed line based on the preset 3D model drawing algorithm and assign it to the created Unity3D material ball; Model the line based on the set 3D model drawing algorithm and assign it to the created Unity3D material ball; The step of modeling the line based on setting the three-dimensional model drawing algorithm specifically includes: Calculate the left and right coordinates of the starting point of the route corresponding to the road surface based on the first preset algorithm; The coordinates of the left and right sides of the road surface corresponding to the middle point of the line are calculated based on the second preset algorithm; The coordinates of the left and right sides of the road surface corresponding to the end point of the route are calculated based on the third preset algorithm; According to all the left coordinates in the obtained left and right coordinates of the starting point, the middle point and the end point, a left coordinate data linked list is established; According to all the right side coordinates in the obtained left and right side coordinates of the starting point, the middle point and the end point, a right side coordinate data linked list is established; According to the established left coordinate data linked list and right coordinate data linked list, triangles are drawn in the order of [PR(0), PR(1), PL(0)], [PL(0), PR(1), PL(1)], [PR(1), PR(2), PL(1)], [PR(1), PR(2), PL(2)] ... [PR(i), PR(i+1), PL(i)], [PL(i), PR(i+1), PL(i+1)] ... [PR(m-1), PR(m), PL(m-1)], [PR(m-1), PR(m), PL(m)] to obtain a line model; Assign corresponding UV and Unity3D materials to the line model; Wherein, PL(i) represents the i-th coordinate in the left coordinate data linked list PL, PR(i) represents the i-th coordinate in the right coordinate data linked list PR, m represents the total number of coordinates in the left coordinate data linked list and the right coordinate data linked list, and the total number of coordinates in the left coordinate data linked list is the same as the total number of coordinates in the right coordinate data linked list, PL(m) represents the m-th coordinate in the left coordinate data linked list, and PR(m) represents the m-th coordinate in the right coordinate data linked list; Among them, [PR(i), PR(i+1), PL(i)] represents the triangle formed by the three coordinates PR(i), PR(i+1) and PL(i), [PL(i), PR(i+1), PL(i+1)] represents the triangle formed by the three coordinates PL(i), PR(i+1) and PL(i+1), [PR(m-1), PR(m), PL(m-1)] represents the triangle formed by the three coordinates PR(m-1), PR(m) and PL(m-1), and [PR(m-1), PR(m), PL(m)] represents the triangle formed by the three coordinates PR(m-1), PR(m), PL(m).

2. A method for drawing a three-dimensional model in Unity3D based on map data as claimed in claim 1, characterized in that: The route is a road network on a map; The closed line includes lakes, buildings, and administrative divisions on the map.

3. The method for drawing a three-dimensional model in Unity3D based on map data according to claim 1, characterized in that: The method of modeling a closed line based on a preset three-dimensional model drawing algorithm specifically includes the following steps: Constructing a first coordinate data linked list based on the coordinates of the closed line, and drawing the model bottom surface of the closed line according to a planar polygon drawing algorithm; Constructing a second coordinate data linked list based on the sum of the coordinates and the height of the closed line, and drawing the top surface of the model of the closed line according to the planar polygon drawing algorithm; Draw the model side of the closed line according to the first coordinate data linked list and the second coordinate data linked list; Corresponding UV and Unity3D materials are assigned to the bottom surface, top surface and side surface of the model.

4. A method for drawing a three-dimensional model in Unity3D based on map data as claimed in claim 3, characterized in that: The model side of the closed line is drawn according to the first coordinate data linked list and the second coordinate data linked list, specifically: Draw triangles in the order of [P1(0), P2(0), P1(1)], [P1(0), P2(1), P1(1)], [P1(1), P2(1), P1(2)], [P1(1), P2(2), P1(2)]…[P1(i), P2(i), P1(i+1)], [P1(i), P2(i+1), P1(i+1)]…[P1(n), P2(n), P1(0)], [P1(n), P2(0), P1(0)] to obtain the model side of the closed line; Wherein, P1 represents the first coordinate data linked list, P2 represents the second coordinate data linked list, n represents the total number of coordinates in the first coordinate data linked list and the second coordinate data linked list, and the total number of coordinates in the first coordinate data linked list is the same as the total number of coordinates in the second coordinate data linked list; Wherein, P1(i) represents the i-th coordinate in the first coordinate data linked list, P2(i) represents the i-th coordinate in the second coordinate data linked list, P1(n) represents the n-th coordinate in the first coordinate data linked list, and P2(n) represents the n-th coordinate in the second coordinate data linked list; Among them, [P1(i), P2(i), P1(i+1)] represents the triangle formed by the three coordinates P1(i), P2(i) and P1(i+1); [P1(i), P2(i+1), P1(i+1)] represents the triangle formed by the three coordinates P1(i), P2(i+1) and P1(i+1); [P1(n), P2(n), P1(0)] represents the triangle formed by the three coordinates P1(n), P2(n) and P1(0); [P1(n), P2(0), P1(0)] represents the triangle formed by the three coordinates P1(n), P2(0) and P1(0).

5. The method for drawing a three-dimensional model in Unity3D based on map data as claimed in claim 3, characterized in that: The specific steps of drawing polygons by the planar polygon drawing algorithm are as follows: S201: Acquire the coordinates of the polygon to be drawn and construct a coordinate data linked list, and number the coordinates in the coordinate data linked list, and go to S202; S202: Determine whether the number of coordinates in the coordinate data linked list is greater than 3, if so, go to S203, if not, go to S209; S203: based on the numbering sequence of the coordinates in the coordinate data linked list, obtain a coordinate as the current coordinate, and go to S204; S204: Obtain the previous coordinate and the next coordinate adjacent to the current coordinate, and determine whether the three coordinate points are on the same straight line. If so, go to S206; if not, go to S207; S206: Delete the current coordinate from the coordinate data linked list, and then go to S202; S207: Based on the vector normal algorithm, determine whether the three coordinates are all convex points of the polygon to be drawn, and whether the three coordinates do not contain other coordinates in the coordinate data linked list; if yes, go to S208; otherwise, go to S209; S208: Draw a triangle based on the three coordinates, then delete the three coordinates from the coordinate data linked list, and then go to S202; S208: taking the coordinates adjacent to the current coordinates as the current coordinates, and then going to S204; S209: Based on the number of coordinates in the coordinate data linked list, when a triangle can be drawn, a triangle is drawn, and then a polygon is drawn based on all the drawn triangles; when a triangle cannot be drawn, a polygon is drawn based on all the drawn triangles.

6. A method for drawing a three-dimensional model in Unity3D based on map data as claimed in claim 1, characterized in that: The coordinates of the left and right sides of the road surface corresponding to the starting point of the route are calculated based on the first preset algorithm, wherein: The calculation formula for the right coordinate of the starting point of the line corresponding to the road surface is: PR(0)=P(0)+dlrn×up×width*0.5 Where PR(0) represents the right coordinate of the starting point P(0) of the line, up represents the unit vector in the upward direction in Unity3d, dlrn=P(1)-P(0), dlrn represents the direction vector at the starting point of the line, P(1) represents the second point of the line, and width represents the width of the road surface; The calculation formula for the right coordinate of the starting point of the line corresponding to the road surface is: PL(0)=P(0)-dlrn×up×width*0.5 Among them, PL(0) represents the left coordinate of the starting point P(0) of the line.

7. A method for drawing a three-dimensional model in Unity3D based on map data as claimed in claim 1, characterized in that: The calculating based on the second preset algorithm to obtain the left and right coordinates of the middle point of the line corresponding to the road surface specifically includes: The line direction angle is calculated based on the line direction vector. The calculation formula is: dlr1=P(i+1)-P(i) dlr2=P(i)-P(i-1) α=arccos(dlr 1×dlr 2) / (|dlr 1|×|dlr 2|) Wherein, dlr1 and dlr 2 both represent the line direction vector, P(i) represents the i-th midpoint of the line, α represents the line direction angle, and arccos represents the arccosine calculation; Determine the calculated line direction angle: When α<180°, PR(i)=P(i)+Normalize((dlr1-dlr2)×width*0.5 PL(i)=P(i)-Normalize((dlr1-dlr2)×width*0.5 Among them, PR(i) represents the right coordinate of the i-th middle point of the line, PL(i) represents the left coordinate of the i-th middle point of the line, Normalize is the vector normalization calculation method in Unity, and width represents the width of the road surface; When α=180°, PR(i)=P(i)-Normalize(dlr1-dlr2)×width*0.5 PL(i)=P(i)+Normalize(dlr1-dlr2)×width*0.

5.

8. The method for drawing a three-dimensional model in Unity3D based on map data according to claim 1, characterized in that: The coordinates of the left and right sides of the road surface corresponding to the end point of the route are calculated based on the third preset algorithm, wherein: The calculation formula for the right coordinate of the road surface corresponding to the end point of the line is: PR(m)=P(m)+dlrm×up×width*0.5 Wherein, PR(m) represents the right coordinate of the end point P(m) of the line, up represents the unit vector in the upward direction in Unity3d, dlrm=P(m)-P(m-1), dlrm represents the line direction vector, and width represents the width of the road surface; The calculation formula for the right coordinate of the road surface corresponding to the end point of the line is: PL(m)=P(m)-dlrm×up×width*0.5 Wherein, PL(m) represents the left coordinate of the end point P(m) of the line.

9. A device for drawing a three-dimensional model in Unity3D based on map data, characterized in that: include: An extraction module is used to extract the lines and closed lines required for creating a three-dimensional model based on the data source of the map data; A creation module, which is used to create a Unity3D material ball according to the model of the line, and to create a Unity3D material ball according to the model of the closed line; A first assigning module is used to model the closed line based on a preset three-dimensional model drawing algorithm, and assign it to the created Unity3D material ball accordingly; The second assignment module is used to model the line based on the set three-dimensional model drawing algorithm, and assign it to the created Unity3D material ball accordingly; The step of modeling the line based on setting the three-dimensional model drawing algorithm specifically includes: Calculate the left and right coordinates of the starting point of the route corresponding to the road surface based on the first preset algorithm; The coordinates of the left and right sides of the road surface corresponding to the middle point of the line are calculated based on the second preset algorithm; The coordinates of the left and right sides of the road surface corresponding to the end point of the route are calculated based on the third preset algorithm; According to all the left coordinates in the obtained left and right coordinates of the starting point, the middle point and the end point, a left coordinate data linked list is established; According to all the right side coordinates in the obtained left and right side coordinates of the starting point, the middle point and the end point, a right side coordinate data linked list is established; According to the established left coordinate data linked list and right coordinate data linked list, triangles are drawn in the order of [PR(0), PR(1), PL(0)], [PL(0), PR(1), PL(1)], [PR(1), PR(2), PL(1)], [PR(1), PR(2), PL(2)] ... [PR(i), PR(i+1), PL(i)], [PL(i), PR(i+1), PL(i+1)] ... [PR(m-1), PR(m), PL(m-1)], [PR(m-1), PR(m), PL(m)] to obtain a line model; Assign corresponding UV and Unity3D materials to the line model; Wherein, PL(i) represents the i-th coordinate in the left coordinate data linked list PL, PR(i) represents the i-th coordinate in the right coordinate data linked list PR, m represents the total number of coordinates in the left coordinate data linked list and the right coordinate data linked list, and the total number of coordinates in the left coordinate data linked list is the same as the total number of coordinates in the right coordinate data linked list, PL(m) represents the m-th coordinate in the left coordinate data linked list, and PR(m) represents the m-th coordinate in the right coordinate data linked list; Among them, [PR(i), PR(i+1), PL(i)] represents the triangle formed by the three coordinates PR(i), PR(i+1) and PL(i), [PL(i), PR(i+1), PL(i+1)] represents the triangle formed by the three coordinates PL(i), PR(i+1) and PL(i+1), [PR(m-1), PR(m), PL(m-1)] represents the triangle formed by the three coordinates PR(m-1), PR(m) and PL(m-1), and [PR(m-1), PR(m), PL(m)] represents the triangle formed by the three coordinates PR(m-1), PR(m), PL(m).