Model fusion method and device and electronic equipment
By generating road models in virtual space and automatically fusion of terrain, the problem of low efficiency of road and terrain fusion in the prior art is solved, and efficient model fusion and cost reduction are achieved.
Patent Information
- Application Number
- CN202411471568.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-03-18
AI Technical Summary
When the prior art generates roads in game scenarios, it is difficult to efficiently integrate road models and terrain, resulting in low efficiency and high labor costs.
Generate a road model in the preset virtual space, and automatically fuses the road model and the terrain model based on these parameters by determining the model part of the road model passing through the specified terrain layer and its corresponding terrain fusion parameters.
The integration efficiency of the model is improved, labor costs are reduced, and the automated integration of road models and terrain is achieved.
Smart Images

Figure CN119648929A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of three-dimensional models, and in particular to a model fusion method, device and electronic equipment. Background Art
[0002] When generating roads in a game scene, it is usually necessary to merge the pre-generated road model with the terrain of the game scene. In the related art, it is usually necessary for relevant production personnel to merge the road model with the existing terrain by adjusting it, which is inefficient and has high labor costs. Summary of the invention
[0003] In view of this, the purpose of the present disclosure is to provide a model fusion method, device and electronic equipment to improve the fusion efficiency of the model and reduce labor costs.
[0004] In a first aspect, an embodiment of the present disclosure provides a model fusion method, the method comprising: generating a road model in a preset virtual space; the virtual space includes a terrain model; the terrain model includes a specified terrain layer; determining a model portion of the road model passing through the specified terrain layer, and determining a terrain fusion parameter corresponding to the model portion; based on the terrain fusion parameter, fusing the road model with the terrain model.
[0005] In a second aspect, an embodiment of the present disclosure provides a model fusion device, which includes: a road model generation module, used to generate a road model in a preset virtual space; the virtual space includes a terrain model; the terrain model includes a specified terrain layer; a terrain fusion parameter determination module, used to determine the model part of the road model passing through the specified terrain layer, and determine the terrain fusion parameters corresponding to the model part; a fusion processing module, used to fuse the road model with the terrain model based on the terrain fusion parameters.
[0006] In a third aspect, an embodiment of the present invention provides an electronic device, including a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the above-mentioned model fusion method.
[0007] In a fourth aspect, an embodiment of the present invention provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned model fusion method.
[0008] The embodiments of the present invention bring the following beneficial effects:
[0009] The above-mentioned model fusion method, device and electronic device generate a road model in a preset virtual space; the virtual space includes a terrain model; the terrain model includes a specified terrain layer; the model part of the road model passing through the specified terrain layer is determined, and the terrain fusion parameters corresponding to the model part are determined; based on the terrain fusion parameters, the road model and the terrain model are fused. In this way, when the road model passes through the specified terrain layer, the road model and the terrain are automatically fused based on the terrain fusion parameters, which improves the model fusion efficiency and reduces the labor cost.
[0010] Other features and advantages of the present disclosure will be described in the following description, and partly become apparent from the description, or understood by practicing the present disclosure. The purpose and other advantages of the present disclosure are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0011] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the specific embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the specific embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0013] Figure 1 A flow chart of a model fusion method provided in an embodiment of the present disclosure;
[0014] Figure 2 A schematic diagram of a vertex determined based on a spline curve provided in an embodiment of the present disclosure;
[0015] Figure 3 A schematic diagram of determining a polygon based on vertices provided in an embodiment of the present disclosure;
[0016] Figure 4 A schematic diagram of a road model provided by an embodiment of the present disclosure;
[0017] Figure 5 A schematic diagram of another road model provided in an embodiment of the present disclosure;
[0018] Figure 6 A schematic diagram of a target image provided by an embodiment of the present disclosure;
[0019] Figure 7 A schematic diagram of a terrain with a terrain blueprint provided for an embodiment of the present disclosure;
[0020] Figure 8 A schematic diagram of a fused road model provided in an embodiment of the present disclosure;
[0021] Fig. 9 A schematic diagram of another fused road model provided in an embodiment of the present disclosure;
[0022] Fig.10 A schematic diagram of a road model with guardrails on both sides provided by an embodiment of the present disclosure;
[0023] Fig.11 A schematic diagram of the structure of a model fusion device provided in an embodiment of the present disclosure;
[0024] Fig.12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present disclosure, rather than all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.
[0026] The current road system solutions for large-scale games are mostly generated based on spline meshes. This general solution has two significant disadvantages:
[0027] 1. Unable to interact with terrain, such as automatically flattening the terrain to form a mountain road when passing through terrain defined as a mountain.
[0028] 2 Performance issues caused by large-scale applications: Unreal Engine (UE) native spline mesh generates multiple spline mesh components based on an input spline line. It usually divides the input spline line according to the set accuracy, and then draws multiple spline mesh components based on the divided spline curve. When applied on a large scale, it will cause a sharp increase in draw calls in the scene. The ideal state is to draw a spline line only once.
[0029] In summary, the above methods often generate spline meshes as road models based on splines, which cannot customize textures and cannot interact with terrain. In addition, since each spline generates several spline meshes, performance problems will occur when applied on a large scale.
[0030] Based on this, the embodiments of the present disclosure provide a model fusion method, device and electronic device, which can be applied to virtual scenes that need to introduce road models.
[0031] See also Figure 1 First, a model fusion method provided by an embodiment of the present invention is introduced. The method comprises the following steps:
[0032] Step S102, generating a road model in a preset virtual space; the virtual space includes a terrain model; the terrain model includes a specified terrain layer.
[0033] The road model can be a closed three-dimensional virtual model, with only one face used to represent the road surface, which can be a curved surface, and other faces connected to the road surface can be planes or curved surfaces, which usually change with the change of the road surface to smoothly connect with the road surface, thereby forming a closed road model. The road model can also be a patch model, which directly represents the road with the surface of the patch model without considering the thickness of the road, the terrain it relies on, etc.
[0034] When generating a road model, a curve is usually required to represent the direction of the road. The curve can be regarded as the center line of the road or as an edge line of the road, and there is no restriction here. The road model is usually composed of polygons connected by vertices. Therefore, it is necessary to determine the vertices that make up the road curve based on the curve, and connect these vertices to form polygons to form a road model.
[0035] A road model can be generated at a location in the virtual space that is pre-used to place a road. The virtual space includes a terrain model. The terrain model includes a specified terrain layer. The terrain of the specified terrain layer is usually undulating and has large height changes. Specifically, the terrain layer can represent a mountain, a desert, etc., which is not limited here. The terrain layer can completely cover the surface of the terrain model or partially cover the surface of the terrain model. Since the road model is mainly generated based on curves without considering the terrain of the specified terrain layer, it is difficult for the road model to fit well with the specified terrain layer and requires subsequent fusion processing.
[0036] Step S104, determining the model portion of the road model passing through the specified terrain layer, and determining the terrain fusion parameters corresponding to the model portion.
[0037] The road model needs to fit the terrain model. Each vertex of the road model can be projected onto the road model. If the projected position of some vertices of the road model is on a specified terrain layer, the model part of the road model passing through the specified terrain layer can be determined by these vertices.
[0038] The above terrain fusion parameters can usually be used to indicate the fusion mode of the above determined model part and the specified terrain layer. Specifically, the terrain height of the road model can be used as the fusion mode of the terrain height position of the specified terrain layer, or a target terrain height can be determined based on the terrain height of the road model and the terrain height of the specified terrain layer, and the two can be fused; the above modes can also be mixed as the fusion mode between models. The fusion mode can usually be determined by user input parameters.
[0039] Step S106: Based on the terrain fusion parameters, the road model and the terrain model are fused.
[0040] If the fusion method is based on the terrain height of the road model, if the specified terrain layer is higher than the road model, the higher part needs to be deleted; if the road model is higher than the specified terrain layer, the suspended part between the two needs to be filled. If the terrain height of the specified terrain layer is used as the standard, the terrain height of the vertex of the model part of the road model needs to be set to the terrain height of the corresponding position of the specified terrain layer, and then the two are merged.
[0041] The terrain fusion parameters can also represent the fusion weight of the road model and the fusion weight of the specified terrain layer. Based on the fusion weight, the terrain height of the road model and the terrain height of the specified terrain layer, a target terrain height can be determined, and the terrain height of the model part of the road model and the corresponding part of the specified terrain layer can be calculated.
[0042] The above-mentioned model fusion method generates a road model in a preset virtual space; the virtual space includes a terrain model; the terrain model includes a specified terrain layer; the model portion of the road model passing through the specified terrain layer is determined, and the terrain fusion parameters corresponding to the model portion are determined; based on the terrain fusion parameters, the road model and the terrain model are fused. This method automatically fuses the road model and the terrain based on the terrain fusion parameters when the road model passes through the specified terrain layer, thereby improving the model fusion efficiency and reducing the labor cost.
[0043] The following embodiment provides a specific method for generating a road model in a preset virtual space.
[0044] When generating a road model, you can first obtain preset model parameters. The preset model parameters are used to indicate one or more of the following: the target spline curve, road width, and vertex spacing corresponding to the road model. Among them, the above road width and vertex spacing can be preset or input by the user. The target spline curve usually requires user input. The user can input multiple points on the target spline curve, or input the function expression corresponding to the target spline curve, which is not limited here.
[0045] Then, it is necessary to determine the model structure parameters of the road model corresponding to the target spline curve based on the preset model parameters. The model structure parameters are used to indicate at least one of the following: vertices constituting the road model, polygons constituting the road model. The model structure parameters may include multiple vertex positions, and the connection relationship of the vertices. Furthermore, based on the model structure parameters, the road model corresponding to the target spline curve can be generated in a preset virtual space.
[0046] In practical applications, the preset model parameters may include spline parameters, road width parameters and vertex spacing parameters at the same time. As described above, the spline parameters may be multiple points on the target spline curve, or a function expression corresponding to the target spline curve, etc.; based on the spline parameters, the target spline curve corresponding to the road model may be determined, and then based on the target spline curve, vertex spacing parameters and road width parameters, the position information of multiple vertices constituting the road model may be determined.
[0047] Specifically, it is usually necessary to divide the target spline curve into multiple sub-splines based on the vertex spacing parameter. The vertex spacing parameter usually defines the target length of the sub-spline. It is necessary to divide the target spline curve into multiple sub-splines whose lengths are consistent with the target length. After the target spline curve is divided into sub-splines, the length of the last sub-spline may be less than the target length. The last sub-spline can be merged with the previous sub-spline, or the last sub-spline can be ignored. Alternatively, the target length is fine-tuned. For example, the number of sub-splines is calculated based on the target length and the length of the target spline curve. If the calculated result is not an integer, the calculated result can be rounded up or down. Then the target spline curve is divided into sub-splines whose number matches the rounded result. At this time, the length of each sub-spline is the fine-tuned target length. After the sub-splines are divided, for each sub-spline, it is necessary to determine the position information of the vertices corresponding to the sub-spline based on the endpoint position of the sub-spline and the road width parameter. Further, it is necessary to determine the polygons constituting the road model based on the position information of multiple vertices.
[0048] The above-mentioned multiple sub-splines have a connection sequence, the sub-spline has a first endpoint and a second endpoint, and the second endpoint of the sub-spline coincides with the first endpoint of the sub-spline located after the sub-spline in the connection sequence, that is, two adjacent sub-splines share an endpoint. When determining the position information of the vertex corresponding to each sub-spline, the current sub-spline can be determined from the multiple sub-splines according to the connection sequence. Usually, the sub-spline with a sequence of 1 in the connection sequence can be first determined as the current sub-spline. Then, it is determined whether the current sub-spline is the last sub-spline in the connection sequence. If not, the endpoint position of the first endpoint of the sub-spline and the endpoint direction corresponding to the first endpoint are first determined, and the endpoint direction is usually the tangent direction of the target spline curve at the first endpoint. Then, based on the endpoint position, the endpoint direction and the road width parameter, the position information of the first vertex and the second vertex corresponding to the first endpoint is determined. In specific implementation, the first endpoint of the sub-spline can be directly used as the first vertex, and then a second vertex is determined, or the endpoint is used as the midpoint of the line connecting the first vertex and the second vertex to determine the first vertex and the second vertex.
[0049] Since the current sub-spline is not the last sub-spline, it is necessary to continue to determine the current sub-spline from multiple sub-splines in the connection order, that is, determine the sub-spline after the current sub-spline as the current sub-spline. If the current sub-spline is the last sub-spline, it is necessary to determine the endpoint position of the first endpoint of the sub-spline and the endpoint direction corresponding to the first endpoint, as well as the endpoint position of the second endpoint of the sub-spline and the endpoint direction corresponding to the second endpoint. Then, based on the endpoint position of the first endpoint, the endpoint direction corresponding to the first endpoint and the road width parameter, determine the position information of the third vertex and the fourth vertex corresponding to the first endpoint, and based on the endpoint position of the second endpoint, the endpoint direction corresponding to the second endpoint and the road width parameter, determine the position information of the fifth vertex and the sixth vertex corresponding to the second endpoint. Since there is no sub-spline with the second endpoint of the sub-spline as the first segment point, it is also necessary to generate a corresponding vertex pair based on the second endpoint of the sub-spline.
[0050] In the process of determining the position information of the first vertex and the second vertex corresponding to the first endpoint, it is first necessary to determine the vertical vector corresponding to the first endpoint based on the endpoint direction; the vertical vector is perpendicular to the endpoint direction. In fact, in three-dimensional space, there is a plane perpendicular to the endpoint direction. The direction of the road plane can be pre-set, and then a vector perpendicular to both the endpoint direction and the road plane direction is calculated as the vertical vector. The direction of the road plane can be constant or change according to demand, which is not limited here. Then the position information of the first vertex and the second vertex can be determined based on the endpoint position, the road width parameter and the vertical vector. In specific implementation, the endpoint position can be translated by half of the road width parameter in the opposite direction of the vertical vector, and the position is used as the position of the first vertex. At this time, the distance between the first vertex and the endpoint position is half of the road width parameter, and the direction of the line connecting the first vertex and the endpoint position is the same as the direction of the vertical vector. The endpoint position is translated by half of the road width parameter in the direction of the vertical vector, and the position is used as the position of the second vertex. Then the distance between the second vertex and the endpoint position is half of the road width parameter, and the direction of the line connecting the second vertex and the endpoint position is opposite to the direction of the vertical vector. A vertex pair can be determined based on each first endpoint.
[0051] As described above, the target spline curve is divided into a plurality of sub-splines based on the vertex spacing parameter. Each sub-spline has four vertices determined based on the endpoints of the sub-spline, and each endpoint corresponds to two vertices. The polygons constituting the road model may be quadrilaterals or triangles. When it is a quadrilateral, the four vertices corresponding to each sub-spline may be connected to generate a quadrilateral. When it is a triangle, two triangles may be determined for each sub-spline based on the four vertices of the sub-spline, and for the sake of convenience, these two triangles are referred to as the first triangle and the second triangle. The two first triangles and the second triangle need not have overlapping parts. In a specific implementation, the four vertices may be first connected to form a quadrilateral, and then two non-adjacent vertices may be connected to divide the quadrilateral into two triangles. The specific implementation method may be set according to requirements and is not limited here.
[0052] In practical applications, the preset model parameters may also include texture map parameters. When rendering the road model, the texture map coordinates of each vertex need to be determined. In specific implementation, the sequence number of each sub-spline can be determined according to the connection order. Since the coordinates in the texture map are limited by (0, 0), (0, 1), (1, 0) and (1, 1), the sequence number of the sub-spline with the sequence number 1 in the connection order is usually set to 0, and the sequence numbers of subsequent sub-splines are increased by 1. Then, for each sub-spline, the texture coordinate parameters of the vertices corresponding to the sub-spline are determined based on the sequence number of the sub-spline. Each sub-spline has four vertices, but adjacent sub-splines share two vertices. Similar to the method of determining the vertex, the texture coordinate parameters of the two vertices corresponding to the first endpoint of each sub-spline can be determined first, and then the texture coordinate parameters of the four vertices corresponding to the first endpoint and the second endpoint of the last sub-spline can be determined. For the two vertices corresponding to each first endpoint, the V coordinate of the first vertex can be set to 0, and the U coordinate can be set to be consistent with the serial number of the corresponding sub-spline; the V coordinate of the second vertex can be set to 1, and the U coordinate can be set to be consistent with the serial number of the corresponding sub-spline. The texture coordinate parameters of the first vertex and the second vertex can also be interchangeable, which is not limited here. Further, the road model can be rendered based on the texture coordinate parameters and the texture mapping parameters.
[0053] The following embodiment provides a specific method for determining a model portion of a road model passing through a specified terrain layer and determining a terrain fusion parameter corresponding to the model portion.
[0054] In a specific implementation, multiple positions on the surface of the road model are determined along the spline curve corresponding to the road model; these positions are usually on the spline curve. The determination process can be implemented in a scattered point manner. The range occupied by the specified terrain layer in the virtual space is fixed, and it can be determined whether there is a first position located in the specified terrain layer in the position; if so, the model part of the road model passing through the specified terrain layer can be determined based on the first position. After the first position is determined, points can be further scattered near the first position, and then it can be determined whether the scattered points are in the specified terrain layer, so as to further determine the boundary between the model part of the road model passing through the specified terrain layer and other model parts.
[0055] The above terrain fusion parameters can be represented by a preset grayscale image. The pixel value of a pixel in the grayscale image represents the fusion weight of the road model and\or the specified terrain layer. For example, when the pixel value is 0, the weight of the road model is 1, and the weight of the specified terrain layer is 0; when the pixel value is 255, the weight of the road model is 0, and the weight of the specified terrain layer is 1; when the pixel value is 127, the weight of the road model is 0.5, and the weight of the specified terrain layer is 0.5, and so on. Other values can also be taken, which are not limited here. The terrain fusion parameters corresponding to the model part can be determined based on the positional correspondence between the grayscale image and the model part. The user can randomly set the grayscale image in the model part to form areas corresponding to each grayscale image.
[0056] The following embodiment provides a specific method for fusing a road model with a terrain model based on terrain fusion parameters.
[0057] The above-mentioned road model is usually a patch model, which is composed of multiple vertices connected. In order to better integrate the road model with the terrain model, for each vertex of the model part passing through the specified terrain layer in the road model, the target terrain height can be determined based on the terrain fusion parameter corresponding to the vertex, the terrain height of the vertex, and the terrain height of the target position corresponding to the specified terrain layer and the vertex; then the terrain height of the vertex is updated to the target terrain height, and the road model is updated based on the updated vertex, and the terrain height of the target position corresponding to the specified terrain layer and the vertex is updated to the target terrain height, and the terrain model is updated based on the updated target position.
[0058] As described above, the terrain fusion parameter can be represented by a preset grayscale image; the grayscale image has a corresponding position correspondence with the model part. The pixel value of the pixel in the grayscale image represents the fusion weight of the road model and\or the specified terrain layer. When determining the target terrain height corresponding to the vertex, the corresponding pixel value can be read from the grayscale image based on the correspondence between the grayscale image and the model part, that is, the pixel value corresponding to the vertex is determined; then based on the pixel value, the first fusion weight of the terrain height of the vertex and the second fusion weight of the terrain height of the target position corresponding to the specified terrain layer and the vertex are determined. The sum of the first fusion weight and the second fusion weight is usually 1. Further, the target terrain height can be calculated based on the terrain height of the vertex, the first fusion weight, the terrain height of the target position corresponding to the specified terrain layer and the vertex, and the second fusion weight. Usually, the terrain height of the vertex is multiplied by the first fusion weight, and the terrain height of the target position corresponding to the specified terrain layer and the vertex is multiplied by the second fusion weight, and the two multiplication results are added as the target terrain height.
[0059] After the road model is fused, the edge position of the fused road model can also be determined. The edge position can be obtained by sampling the edge of the road model. Then, it is determined whether the slope of the edge position is greater than a preset slope threshold; if so, a preset protection model is generated at the edge position. The protection model can be a virtual fence, guardrail, etc., which is not set here. When the slope of the edge position is less than or equal to the slope threshold, a tree model, a grass model, etc. can also be generated at the edge position, which is not limited here.
[0060] The present disclosure also provides another model fusion method. Figure 1 This method is implemented based on the method shown in . This method generates only one road mesh for each spline based on the input spline and the procedural mesh of the UE engine, that is, it is drawn once, which alleviates the performance problem when generating a large number of roads on large-scale maps. At the same time, it combines the PCG system of the UE5 engine and the landscape patch native plug-in to realize the interaction between the road system and the terrain.
[0061] The interaction may include: (1) automatically leveling the terrain to form a mountain road when passing through terrain defined as a mountain; (2) scattering trees on both sides of the road; (3) automatically generating wooden boards and fences when the road slope is large. This allows the road system to interact with the scene, greatly improving the efficiency of making large maps and the rationality of the scene. This method is a large-world automated road system solution that uses the UE engine procedural mesh and PCG system.
[0062] This method calculates the vertex information, triangle information, UV information, etc. required to generate the mesh based on the input spline, and then generates a procedural mesh type road patch. In addition, through the PCG system in the UE engine, terrain stamps are scattered to flatten the mountain road when the road passes through the mountain, achieving a reasonable mountain road effect. Trees are scattered on both layers of the road, and fences and wooden boards are scattered when the road slope reaches a threshold.
[0063] The specific algorithm and implementation process will be explained and analyzed step by step below.
[0064] 1. Generate road patches based on procedural mesh:
[0065] First, you need to prepare a spline (equivalent to the above-mentioned "target spline") input. Based on the input spline, calculate the vertex information (equivalent to the above-mentioned "vertex position information"), triangle (equivalent to the above-mentioned "polygon") information, UV information, etc. required to generate the mesh model, and then generate a procedural mesh type road patch. This step is implemented in the Generate Road Proc Mesh function preset in the Unreal Engine. Input is as follows: Figure 1 As shown, it includes: spline (Map Data Spline), road width (equivalent to the above "road width parameter") (RoadWidth), road patch material (Road Material), road patch transparency sorting (Road TranslucentSort Priority), road UV stretching (UV scale), vertex spacing (resampledistance) (equivalent to the above "vertex spacing parameter"). The following is a detailed introduction to the specific implementation of this function:
[0066] (1) Divide the spline into sub-splines according to resampledistance
[0067] Generating a mesh requires a set of vertex position data (vertices), a set of triangle information (triangles) and a set of UV values (UV) (hereinafter referred to as three sets of output arrays). First, for each spline, clear these input containers.
[0068] Then, according to the input spacing of the divided vertices (resampledistance), the spline is divided into N sub-splines, where N is the length of the spline divided by the resampledistance and then rounded to an integer.
[0069] Next, loop through each sub-segment and fill data into the three output arrays.
[0070] (2) For each sub-spline, calculate the vertex position of the mesh to be generated
[0071] The step of calculating the vertex position is implemented in the Create Vertices function preset in the Unreal Engine. The input of this function includes: the current spline (Current Spline), the index of the current sub-spline (Current Index), the index of the last sub-spline on the current spline (Last Pt Index), the road width (Road Width), the container of the vertex position data (vertices) and the spacing of the divided vertices (resampledistance). The following is a detailed description of each step:
[0072] When the current sub-spline is not the last sub-spline, first calculate the coordinates of the sub-spline endpoint through Get location At DistanceAlong Spline (UE built-in function), hereinafter referred to as the sub-spline endpoint (where the input distance is obtained by multiplying the spacing of the divided vertices (resample distance) by the serial number (CurrentIndex) of the current sub-spline) and get the direction of the sub-spline at the endpoint through Get Direction At Distance Along Spline (UE built-in function), hereinafter referred to as the sub-spline direction (where the input distance is obtained by multiplying the spacing of the divided vertices (resampledistance) by the serial number (Current Index) of the current sub-spline). Cross-multiply the sub-spline direction with (0, 0, 1), that is, the vertically upward vector, and then normalize the result to obtain a vector perpendicular to the sub-spline, hereinafter referred to as the vertical vector. Move the sub-spline endpoint along the vertical vector direction by 0.5 times the road width (Road Width) to obtain a vertex position on the road mesh, called pta (equivalent to the position of the above-mentioned "second vertex"), and store the coordinate information of pta in the container of vertex position data (vertices). Then move the sub-spline endpoint along the negative direction of the vertical vector by 0.5 times the road width (Road Width) to obtain another vertex position on the road mesh, called ptb (equivalent to the position of the above-mentioned "first vertex"), and store the coordinate information of ptb in the container of vertex position data (vertices).
[0073] When the current sub-spline is the last sub-spline, first process the second-to-last pair of vertices to be added to the mesh. The same steps as described in the previous paragraph are used to obtain the coordinates of the sub-spline endpoints. The difference is that this time it is necessary to obtain the direction of the previous sub-spline at the endpoint (in order to make the connection between the last two pieces on the mesh more natural). The vertical vector obtained by cross-producting this direction with (0, 1, 0) is called the end vertical vector. Then, the same steps as described in the previous paragraph are used to obtain the coordinate information of pta and ptb and store them in the container of vertex position data (vertices). Then it is necessary to process the last pair of vertices to be added to the mesh. Get Location at Spline Point (UE built-in function) is used to obtain the coordinates of the last endpoint on the spline, hereinafter referred to as the end point (equivalent to the above-mentioned "second endpoint"), and move the end point along the end vertical vector direction by 0.5 times the road width (Road Width) to obtain a vertex position on the road mesh, called pta, such as Figure 2 As shown. The coordinate information of pta is stored in the container of vertex position data (vertices). Similarly, the end point is moved along the negative direction of the end vertical vector by 0.5 times the road width (Road Width) to obtain another vertex position on the road mesh, called ptb, and the coordinate information of ptb is also stored in the container of vertex position data (vertices).
[0074] (3) For each sub-spline, calculate the triangle information of the mesh to be generated, that is, the order of connecting vertices
[0075] The step of calculating triangle information (i.e. the order of connecting vertices) is implemented in the Create Triangles function. The input of this function is the index of the current sub-spline (Current Index) and the container of triangle information data (Triangles). The triangle information is the order of connecting vertices. The order of connecting vertices is calculated as follows.
[0076] A set of 2*2 vertices, the standard connection order is [0, 1, 2, 1, 3, 2]. This basic sequence can be obtained through CreateGrid Mesh Triangles (UE built-in function), such as Fig. 9 When the sequence number of the current sub-spline is n, the connection order of the four vertices generated by the sub-spline is [0+2n, 1+2n, 2+2n, 1+2n, 3+2n, 2+2n], and the calculation diagram is as follows Figure 3 shown.
[0077] (4) For each sub-spline, calculate the UV information of the mesh to be generated, that is, the UV value on each vertex
[0078] The step of calculating UV information (UV value on each vertex) is implemented in the Create UV function. The input of this function includes: the index of the current sub-spline (Current Index) and the container of UV information data (UV). The distribution of UV is as follows Figure 4 As shown in the figure, the U value is 0 on one side of the spline and 1 on the other side. The V information is consistent with the sequence number of the sub-spline to which it belongs.
[0079] (5) For each spline, generate a road mesh based on the data generated by (1)-(4)
[0080] After getting three sets of output arrays, we use one set of vertex position data (vertices), one set of triangle information (triangles), and one set of UV values (UV Scaled) scaled according to the effect requirements as input to generate the road patch mesh. This step is implemented in the Create Proc Mesh function. The input of this function includes: three sets of output arrays, road material and road transparency sorting. The content of this function is introduced in detail below.
[0081] First, create an empty procedural mesh component, and then use Calculate Tangents for Mesh (UE built-in function) to calculate the normal and tangent information of the generated procedural mesh component. These two pieces of information plus the three arrays input are used as input to generate the road mesh through Create Mesh Section (UE built-in function). Then, according to the input road material and road transparency, the procedural mesh component can be set. The generated mesh is as follows Figure 5 As shown, the road effect is as follows Figure 6 shown.
[0082] 2. Change the terrain of the road when passing through mountainous areas
[0083] A mountain road is defined as a road that intersects with the terrain layer that defines the mountain. A mountain road will affect the terrain height (changing the terrain height to a height that is a mixture of the road spline and the original terrain height). The specific implementation steps are:
[0084] (1) Create a PCG Graph in the road blueprint and set the name to PCG_RoadStamp.
[0085] (2) Prepare the terrain stamp blueprint
[0086] The terrain stamp blueprint is a blueprint actor generated based on the landscape patch plug-in in the UE engine, which contains a landscape patch terrain stamp. The length and width, grayscale image, and blending mode with the original terrain can be set on the terrain stamp to change the terrain. The length and width of the terrain stamp are determined by the width of the road, the grayscale image can be replaced according to the effect requirements, and the blending mode is set to Alpha Blend mode, that is, the terrain height is changed to the height of the road spline and the original terrain height. The effect of a single terrain stamp is as follows Figure 7 shown.
[0087] (3) Scattering terrain stamps along roads in PCG Graph
[0088] In PCG_RoadStam, we first scatter points along the road spline, and then determine whether these points are within the range of the mountain (the range of the mountain is determined by the information on the terrain layer). We then scatter terrain stamps on the points within the range of the mountain to change the terrain height. Figure 8 The complete effect is as shown Fig. 9 shown.
[0089] 3. Trees are scattered on both sides of the road
[0090] (1) Create a PCG Graph in the road blueprint
[0091] Similar to the steps in 2-(1), create a PCG Graph named PCG_RoadScatter.
[0092] (2) Scatter trees along roads in the PCG Graph.
[0093] 4. Automatically generate fences and wooden boards when the slope is large
[0094] This function is also generated in PCG_RoadScatter created in step 3. The slope value at each point is calculated through Normal To Density (UE built-in function) (the normal of the calculated point is cross-multiplied with (0, 0, 1), and then the result is arccos).
[0095] 5. The final result is imported into UE, and the scene is displayed as follows Fig.10 shown.
[0096] This method generates only one road mesh for each spline based on the procedural mesh of the UE engine according to the input spline, that is, it is drawn once, which alleviates the performance problem when generating a large number of roads on large-scale maps. At the same time, combined with the PCG system of the UE5 engine and the landscape patch native plug-in, the interaction between the road system and the terrain is realized, including multiple: 1) Automatically flatten the terrain to form a mountain road when passing through terrain defined as a mountain; 2) Scatter trees on both sides of the road; 3) Automatically generate wooden boards and fences when the road slope is large. This method can adapt to various types of terrain, allowing the road system to interact with the scene, has a high reuse potential, and greatly improves the production efficiency of large maps and the rationality of the scene.
[0097] For the above method embodiments, see Fig.11 A model fusion device is shown, the device comprising:
[0098] The road model generation module 1102 is used to generate a road model in a preset virtual space; the virtual space includes a terrain model; the terrain model includes a specified terrain layer;
[0099] A terrain fusion parameter determination module 1104 is used to determine a model portion of the road model passing through a specified terrain layer, and determine a terrain fusion parameter corresponding to the model portion;
[0100] The fusion processing module 1106 is used to fuse the road model with the terrain model based on the terrain fusion parameters.
[0101] The above-mentioned model fusion device generates a road model in a preset virtual space; the virtual space includes a terrain model; the terrain model includes a specified terrain layer; the model portion of the road model passing through the specified terrain layer is determined, and the terrain fusion parameter corresponding to the model portion is determined; based on the terrain fusion parameter, the road model and the terrain model are fused. In this method, when the road model passes through the specified terrain layer, the road model and the terrain are automatically fused based on the terrain fusion parameter, which improves the model fusion efficiency and reduces the labor cost.
[0102] The above-mentioned road model generation module is also used to: obtain preset model parameters; the preset model parameters are used to indicate one or more of the following: the target spline curve, road width, and vertex spacing corresponding to the road model; based on the preset model parameters, determine the model structure parameters of the road model corresponding to the target spline curve; the model structure parameters are used to indicate at least one of the following: vertices constituting the road model, polygons constituting the road model; based on the model structure parameters, generate a road model corresponding to the target spline curve in a preset virtual space.
[0103] The above-mentioned preset model parameters include spline parameters, road width parameters and vertex spacing parameters; the above-mentioned road model generation module is also used to: determine the target spline curve corresponding to the road model based on the spline parameters; determine the position information of multiple vertices constituting the road model based on the target spline curve, vertex spacing parameters and road width parameters; determine the polygons constituting the road model based on the position information of multiple vertices.
[0104] The road model generation module is also used to: divide the target spline curve into multiple sub-splines based on the vertex spacing parameter; for each sub-spline, determine the position information of the vertex corresponding to the sub-spline based on the endpoint position of the sub-spline and the road width parameter.
[0105] The above-mentioned multiple sub-splines have a connection order; the sub-spline has a first endpoint and a second endpoint; the second endpoint of the sub-spline coincides with the first endpoint of the sub-spline located after the sub-spline in the connection order; the above-mentioned road model generation module is also used to: determine the current sub-spline from the multiple sub-splines according to the connection order; determine whether the current sub-spline is the last sub-spline in the connection order; if not, determine the endpoint position of the first endpoint of the sub-spline and the endpoint direction corresponding to the first endpoint; based on the endpoint position, endpoint direction and road width parameter, determine the position information of the first vertex and the second vertex corresponding to the first endpoint; continue to execute the step of determining the current sub-spline from the multiple sub-splines according to the connection order; if yes, determine the endpoint position of the first endpoint of the sub-spline and the endpoint direction corresponding to the first endpoint, as well as the endpoint position of the second endpoint of the sub-spline and the endpoint direction corresponding to the second endpoint; based on the endpoint position of the first endpoint, the endpoint direction corresponding to the first endpoint and the road width parameter, determine the position information of the third vertex and the fourth vertex corresponding to the first endpoint; based on the endpoint position of the second endpoint, the endpoint direction corresponding to the second endpoint and the road width parameter, determine the position information of the fifth vertex and the sixth vertex corresponding to the second endpoint.
[0106] The above-mentioned road model generation module is also used to: determine the vertical vector corresponding to the first endpoint based on the endpoint direction; the vertical vector is perpendicular to the endpoint direction; determine the position information of the first vertex and the second vertex based on the endpoint position, the road width parameter and the vertical vector; the distance between the first vertex and the endpoint position is half of the road width parameter, and the direction of the line connecting the first vertex and the endpoint position is the same as the direction of the vertical vector; the distance between the second vertex and the endpoint position is half of the road width parameter, and the direction of the line connecting the second vertex and the endpoint position is opposite to the direction of the vertical vector.
[0107] The target spline curve is divided into a plurality of sub-splines based on vertex spacing parameters; each sub-spline has four vertices determined based on the endpoints of the sub-spline; the road model generation module is also used to: for each sub-spline, determine a first triangle and a second triangle based on the four vertices of the sub-spline; the first triangle and the second triangle have no overlapping parts.
[0108] The above-mentioned preset model parameters also include texture mapping parameters; the above-mentioned device also includes: a serial number determination module, which is used to determine the serial number of each sub-spline according to the connection order; a texture coordinate parameter determination module, which is used to determine the texture coordinate parameters of the vertices corresponding to the sub-spline for each sub-spline based on the serial number of the sub-spline; and a rendering module, which is used to render the road model based on the texture coordinate parameters and texture mapping parameters.
[0109] The terrain fusion parameter determination module is also used to: determine the positions on the surface of multiple road models along the spline curves corresponding to the road models; determine whether there is a first position located in the specified terrain layer among the positions; if so, determine the model part of the road model passing through the specified terrain layer based on the first position.
[0110] The terrain fusion parameters are represented by a preset grayscale image; the pixel values of the pixels in the grayscale image represent the fusion weights of the road model and / or the specified terrain layer; the terrain fusion parameter determination module is also used to determine the position correspondence between the grayscale image and the model part.
[0111] The above-mentioned road model is a patch model, which is composed of multiple vertices connected; the fusion processing module is also used to: for each vertex of the model part passing through the specified terrain layer in the road model, determine the target terrain height based on the terrain fusion parameter corresponding to the vertex, the terrain height of the vertex and the terrain height of the target position corresponding to the specified terrain layer and the vertex; update the terrain height of the vertex to the target terrain height, and update the road model based on the updated vertex; update the terrain height of the target position corresponding to the specified terrain layer and the vertex to the target terrain height, and update the terrain model based on the updated target position.
[0112] The above-mentioned terrain fusion parameters are represented by a preset grayscale image; the grayscale image and the model part have a corresponding position correspondence; the pixel value of the pixel in the grayscale image represents the fusion weight of the road model and\or the specified terrain layer; the fusion processing module is also used to: determine the pixel value corresponding to the vertex based on the correspondence between the grayscale image and the model part; determine the first fusion weight of the terrain height of the vertex and the second fusion weight of the terrain height of the target position corresponding to the specified terrain layer and the vertex based on the pixel value; calculate the target terrain height based on the terrain height of the vertex, the first fusion weight, the terrain height of the target position corresponding to the specified terrain layer and the vertex, and the second fusion weight.
[0113] The above-mentioned device also includes: an edge position determination module, which is used to determine the edge position of the fused road model; a threshold judgment module, which is used to judge whether the slope of the edge position is greater than a preset slope threshold; and a protection model generation module, which is used to generate a preset protection model at the edge position if so.
[0114] This embodiment further provides an electronic device, including a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the above-mentioned model fusion method, for example:
[0115] A road model is generated in a preset virtual space; the virtual space includes a terrain model; the terrain model includes a specified terrain layer; a model portion of the road model passing through the specified terrain layer is determined, and a terrain fusion parameter corresponding to the model portion is determined; based on the terrain fusion parameter, the road model and the terrain model are fused.
[0116] In the above method, when the road model passes through a specified terrain layer, the road model and the terrain are automatically merged based on the terrain fusion parameters, thereby improving the model fusion efficiency and reducing the labor cost.
[0117] Optionally, the above-mentioned step of generating a road model in a preset virtual space includes: obtaining preset model parameters; the preset model parameters are used to indicate one or more of the following: a target spline curve, a road width, and a vertex spacing corresponding to the road model; based on the preset model parameters, determining the model structure parameters of the road model corresponding to the target spline curve; the model structure parameters are used to indicate at least one of the following: vertices constituting the road model, polygons constituting the road model; based on the model structure parameters, generating a road model corresponding to the target spline curve in the preset virtual space.
[0118] Optionally, the above-mentioned preset model parameters include spline parameters, road width parameters and vertex spacing parameters; the steps of determining the model structure parameters of the road model based on the preset model parameters include: determining the target spline curve corresponding to the road model based on the spline parameters; determining the position information of multiple vertices constituting the road model based on the target spline curve, vertex spacing parameters and road width parameters; determining the polygons constituting the road model based on the position information of multiple vertices.
[0119] Optionally, the above step of determining the position information of multiple vertices constituting the road model based on the target spline curve, vertex spacing parameters and road width parameters includes: dividing the target spline curve into multiple sub-spline lines based on the vertex spacing parameters; for each sub-spline, determining the position information of the vertex corresponding to the sub-spline based on the endpoint position of the sub-spline and the road width parameter.
[0120] Optionally, the above-mentioned multiple sub-splines have a connection order; the sub-spline has a first endpoint and a second endpoint; the second endpoint of the sub-spline coincides with the first endpoint of the sub-spline located after the sub-spline in the connection order; for each sub-spline, based on the endpoint position of the sub-spline and the road width parameter, the step of determining the position information of the vertex corresponding to the sub-spline includes: determining the current sub-spline from the multiple sub-splines according to the connection order; judging whether the current sub-spline is the last sub-spline in the connection order; if not, determining the endpoint position of the first endpoint of the sub-spline and the endpoint direction corresponding to the first endpoint; determining based on the endpoint position, the endpoint direction and the road width parameter The position information of the first vertex and the second vertex corresponding to the first endpoint; continue to execute the step of determining the current sub-spline from multiple sub-splines in the connection order; if yes, determine the endpoint position of the first endpoint of the sub-spline and the endpoint direction corresponding to the first endpoint, as well as the endpoint position of the second endpoint of the sub-spline and the endpoint direction corresponding to the second endpoint; based on the endpoint position of the first endpoint, the endpoint direction corresponding to the first endpoint and the road width parameter, determine the position information of the third vertex and the fourth vertex corresponding to the first endpoint; based on the endpoint position of the second endpoint, the endpoint direction corresponding to the second endpoint and the road width parameter, determine the position information of the fifth vertex and the sixth vertex corresponding to the second endpoint.
[0121] Optionally, the above-mentioned step of determining the position information of the first vertex and the second vertex corresponding to the first endpoint based on the endpoint position, the endpoint direction and the road width parameter includes: determining the vertical vector corresponding to the first endpoint based on the endpoint direction; the vertical vector is perpendicular to the endpoint direction; determining the position information of the first vertex and the second vertex based on the endpoint position, the road width parameter and the vertical vector; the distance between the first vertex and the endpoint position is half the road width parameter, and the direction of the line connecting the first vertex and the endpoint position is the same as the direction of the vertical vector; the distance between the second vertex and the endpoint position is half the road width parameter, and the direction of the line connecting the second vertex and the endpoint position is opposite to the direction of the vertical vector.
[0122] Optionally, the target spline curve is divided into a plurality of sub-splines based on vertex spacing parameters; each sub-spline has four vertices determined based on the endpoints of the sub-spline; based on the position information of the plurality of vertices, the step of determining the polygons constituting the road model comprises: for each sub-spline, determining a first triangle and a second triangle based on the four vertices of the sub-spline; the first triangle and the second triangle have no overlapping parts.
[0123] Optionally, the above step of determining the model portion of the road model passing through the specified terrain layer includes: determining multiple positions on the surface of the road model along the spline curve corresponding to the road model; judging whether there is a first position located in the specified terrain layer among the positions; and if so, determining the model portion of the road model passing through the specified terrain layer based on the first position.
[0124] Optionally, the above-mentioned terrain fusion parameters are represented by a preset grayscale image; the pixel values of the pixels in the grayscale image represent the fusion weights of the road model and / or the specified terrain layer; the step of determining the terrain fusion parameters corresponding to the model part includes: determining the position correspondence between the grayscale image and the model part.
[0125] Optionally, the road model is a patch model, which is composed of multiple vertices connected; the step of fusing the road model with the terrain model based on the terrain fusion parameters includes: for each vertex of the model part passing through the specified terrain layer in the road model, based on the terrain fusion parameters corresponding to the vertex, the terrain height of the vertex and the terrain height of the target position corresponding to the specified terrain layer and the vertex, determining the target terrain height; updating the terrain height of the vertex to the target terrain height, and updating the road model based on the updated vertex; updating the terrain height of the target position corresponding to the specified terrain layer and the vertex to the target terrain height, and updating the terrain model based on the updated target position.
[0126] Optionally, the terrain fusion parameters are represented by a preset grayscale image; the grayscale image has a corresponding position correspondence with the model part; the pixel value of the pixel in the grayscale image represents the fusion weight of the road model and / or the specified terrain layer; based on the terrain fusion parameters corresponding to the vertex, the terrain height of the vertex and the terrain height of the target position corresponding to the specified terrain layer and the vertex, the step of determining the target terrain height corresponding to the vertex includes: determining the pixel value corresponding to the vertex based on the correspondence between the grayscale image and the model part; determining a first fusion weight of the terrain height of the vertex and a second fusion weight of the terrain height of the target position corresponding to the vertex based on the pixel value; calculating the target terrain height based on the terrain height of the vertex, the first fusion weight, the terrain height of the target position corresponding to the specified terrain layer and the vertex, and the second fusion weight.
[0127] Optionally, the above method also includes: determining the edge position of the fused road model; judging whether the slope of the edge position is greater than a preset slope threshold; if so, generating a preset protection model at the edge position.
[0128] See also Fig.12 As shown, the electronic device includes a processor 100 and a memory 101, wherein the memory 101 stores machine executable instructions that can be executed by the processor 100, and the processor 100 executes the machine executable instructions to implement the above-mentioned model fusion method.
[0129] Further, Fig.12 The electronic device shown further includes a bus 102 and a communication interface 103 , and the processor 100 , the communication interface 103 and the memory 101 are connected via the bus 102 .
[0130] The memory 101 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 102 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.12 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0131] The processor 100 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 100. The above processor 100 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 101, and the processor 100 reads the information in the memory 101 and completes the steps of the method of the above embodiment in combination with its hardware.
[0132] This embodiment also provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned model fusion method.
[0133] A model fusion method, device, and electronic device provided in the embodiments of the present disclosure include a computer-readable storage medium storing program code, and the program code includes instructions that can be used to execute the methods described in the previous method embodiments, for example:
[0134] A road model is generated in a preset virtual space; the virtual space includes a terrain model; the terrain model includes a specified terrain layer; a model portion of the road model passing through the specified terrain layer is determined, and a terrain fusion parameter corresponding to the model portion is determined; based on the terrain fusion parameter, the road model and the terrain model are fused.
[0135] In the above method, when the road model passes through a specified terrain layer, the road model and the terrain are automatically merged based on the terrain fusion parameters, thereby improving the model fusion efficiency and reducing the labor cost.
[0136] Optionally, the above-mentioned step of generating a road model in a preset virtual space includes: obtaining preset model parameters; the preset model parameters are used to indicate one or more of the following: a target spline curve, a road width, and a vertex spacing corresponding to the road model; based on the preset model parameters, determining the model structure parameters of the road model corresponding to the target spline curve; the model structure parameters are used to indicate at least one of the following: vertices constituting the road model, polygons constituting the road model; based on the model structure parameters, generating a road model corresponding to the target spline curve in the preset virtual space.
[0137] Optionally, the above-mentioned preset model parameters include spline parameters, road width parameters and vertex spacing parameters; the steps of determining the model structure parameters of the road model based on the preset model parameters include: determining the target spline curve corresponding to the road model based on the spline parameters; determining the position information of multiple vertices constituting the road model based on the target spline curve, vertex spacing parameters and road width parameters; determining the polygons constituting the road model based on the position information of multiple vertices.
[0138] Optionally, the above step of determining the position information of multiple vertices constituting the road model based on the target spline curve, vertex spacing parameters and road width parameters includes: dividing the target spline curve into multiple sub-spline lines based on the vertex spacing parameters; for each sub-spline, determining the position information of the vertex corresponding to the sub-spline based on the endpoint position of the sub-spline and the road width parameter.
[0139] Optionally, the above-mentioned multiple sub-splines have a connection order; the sub-spline has a first endpoint and a second endpoint; the second endpoint of the sub-spline coincides with the first endpoint of the sub-spline located after the sub-spline in the connection order; for each sub-spline, based on the endpoint position of the sub-spline and the road width parameter, the step of determining the position information of the vertex corresponding to the sub-spline includes: determining the current sub-spline from the multiple sub-splines according to the connection order; judging whether the current sub-spline is the last sub-spline in the connection order; if not, determining the endpoint position of the first endpoint of the sub-spline and the endpoint direction corresponding to the first endpoint; determining based on the endpoint position, the endpoint direction and the road width parameter The position information of the first vertex and the second vertex corresponding to the first endpoint; continue to execute the step of determining the current sub-spline from multiple sub-splines in the connection order; if yes, determine the endpoint position of the first endpoint of the sub-spline and the endpoint direction corresponding to the first endpoint, as well as the endpoint position of the second endpoint of the sub-spline and the endpoint direction corresponding to the second endpoint; based on the endpoint position of the first endpoint, the endpoint direction corresponding to the first endpoint and the road width parameter, determine the position information of the third vertex and the fourth vertex corresponding to the first endpoint; based on the endpoint position of the second endpoint, the endpoint direction corresponding to the second endpoint and the road width parameter, determine the position information of the fifth vertex and the sixth vertex corresponding to the second endpoint.
[0140] Optionally, the above-mentioned step of determining the position information of the first vertex and the second vertex corresponding to the first endpoint based on the endpoint position, the endpoint direction and the road width parameter includes: determining the vertical vector corresponding to the first endpoint based on the endpoint direction; the vertical vector is perpendicular to the endpoint direction; determining the position information of the first vertex and the second vertex based on the endpoint position, the road width parameter and the vertical vector; the distance between the first vertex and the endpoint position is half the road width parameter, and the direction of the line connecting the first vertex and the endpoint position is the same as the direction of the vertical vector; the distance between the second vertex and the endpoint position is half the road width parameter, and the direction of the line connecting the second vertex and the endpoint position is opposite to the direction of the vertical vector.
[0141] Optionally, the target spline curve is divided into a plurality of sub-splines based on vertex spacing parameters; each sub-spline has four vertices determined based on the endpoints of the sub-spline; based on the position information of the plurality of vertices, the step of determining the polygons constituting the road model comprises: for each sub-spline, determining a first triangle and a second triangle based on the four vertices of the sub-spline; the first triangle and the second triangle have no overlapping parts.
[0142] Optionally, the above step of determining the model portion of the road model passing through the specified terrain layer includes: determining multiple positions on the surface of the road model along the spline curve corresponding to the road model; judging whether there is a first position located in the specified terrain layer among the positions; and if so, determining the model portion of the road model passing through the specified terrain layer based on the first position.
[0143] Optionally, the above-mentioned terrain fusion parameters are represented by a preset grayscale image; the pixel values of the pixels in the grayscale image represent the fusion weights of the road model and / or the specified terrain layer; the step of determining the terrain fusion parameters corresponding to the model part includes: determining the position correspondence between the grayscale image and the model part.
[0144] Optionally, the road model is a patch model, which is composed of multiple vertices connected; the step of fusing the road model with the terrain model based on the terrain fusion parameters includes: for each vertex of the model part passing through the specified terrain layer in the road model, based on the terrain fusion parameters corresponding to the vertex, the terrain height of the vertex and the terrain height of the target position corresponding to the specified terrain layer and the vertex, determining the target terrain height; updating the terrain height of the vertex to the target terrain height, and updating the road model based on the updated vertex; updating the terrain height of the target position corresponding to the specified terrain layer and the vertex to the target terrain height, and updating the terrain model based on the updated target position.
[0145] Optionally, the terrain fusion parameters are represented by a preset grayscale image; the grayscale image has a corresponding position correspondence with the model part; the pixel value of the pixel in the grayscale image represents the fusion weight of the road model and / or the specified terrain layer; based on the terrain fusion parameters corresponding to the vertex, the terrain height of the vertex and the terrain height of the target position corresponding to the specified terrain layer and the vertex, the step of determining the target terrain height corresponding to the vertex includes: determining the pixel value corresponding to the vertex based on the correspondence between the grayscale image and the model part; determining a first fusion weight of the terrain height of the vertex and a second fusion weight of the terrain height of the target position corresponding to the vertex based on the pixel value; calculating the target terrain height based on the terrain height of the vertex, the first fusion weight, the terrain height of the target position corresponding to the specified terrain layer and the vertex, and the second fusion weight.
[0146] Optionally, the above method also includes: determining the edge position of the fused road model; judging whether the slope of the edge position is greater than a preset slope threshold; if so, generating a preset protection model at the edge position.
[0147] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0148] In addition, in the description of the embodiments of the present disclosure, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For those skilled in the art, the specific meanings of the above terms in the present disclosure can be understood according to specific circumstances.
[0149] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0150] In the description of the present disclosure, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present disclosure and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation of the present disclosure. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0151] Finally, it should be noted that the above embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above embodiments, those skilled in the art should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A model fusion method, characterized in that: The method comprises: Generate a road model in a preset virtual space; the virtual space includes a terrain model; the terrain model includes a specified terrain layer; Determine a model portion of the road model passing through the specified terrain layer, and determine a terrain fusion parameter corresponding to the model portion; The road model is fused with the terrain model based on the terrain fusion parameter.
2. The method according to claim 1, characterized in that The steps of generating a road model in a preset virtual space include: Acquire preset model parameters; the preset model parameters are used to indicate one or more of the following: a target spline curve, a road width, and a vertex spacing corresponding to the road model; Based on the preset model parameters, determining the model structure parameters of the road model; the model structure parameters are used to indicate at least one of the following: vertices constituting the road model, polygons constituting the road model; Based on the model structure parameters, a road model corresponding to the target spline curve is generated in a preset virtual space.
3. The method according to claim 2, characterized in that The preset model parameters include spline parameters, road width parameters and vertex spacing parameters; The step of determining the model structure parameters of the road model based on the preset model parameters includes: Based on the spline parameters, determining a target spline curve corresponding to the road model; Determining position information of a plurality of vertices constituting a road model based on the target spline curve, the vertex spacing parameter and the road width parameter; Based on the position information of the plurality of vertices, polygons constituting the road model are determined.
4. The method according to claim 3, characterized in that The step of determining position information of a plurality of vertices constituting a road model based on the target spline curve, the vertex spacing parameter and the road width parameter comprises: Based on the vertex spacing parameter, dividing the target spline curve into a plurality of sub-splines; For each sub-spline, based on the endpoint position of the sub-spline and the road width parameter, the position information of the vertex corresponding to the sub-spline is determined.
5. The method according to claim 4, characterized in that The plurality of sub-splines have a connection sequence; the sub-spline has a first endpoint and a second endpoint; the second endpoint of the sub-spline coincides with the first endpoint of a sub-spline located after the sub-spline in the connection sequence; For each sub-spline, based on the endpoint position of the sub-spline and the road width parameter, the step of determining the position information of the vertex corresponding to the sub-spline comprises: Determining a current sub-spline from the plurality of sub-splines according to the connection order; Determine whether the current sub-spline is the last sub-spline in the connection sequence; If not, determining the endpoint position of the first endpoint of the sub-spline and the endpoint direction corresponding to the first endpoint; Based on the endpoint position, the endpoint direction and the road width parameter, determine the position information of the first vertex and the second vertex corresponding to the first endpoint; Continue to execute the step of determining a current sub-spline from the plurality of sub-splines according to the connection order; If yes, determine the endpoint position of the first endpoint of the sub-spline and the endpoint direction corresponding to the first endpoint, and the endpoint position of the second endpoint of the sub-spline and the endpoint direction corresponding to the second endpoint; Determine position information of a third vertex and a fourth vertex corresponding to the first endpoint based on the endpoint position of the first endpoint, the endpoint direction corresponding to the first endpoint, and a road width parameter; Based on the endpoint position of the second endpoint, the endpoint direction corresponding to the second endpoint, and a road width parameter, position information of a fifth vertex and a sixth vertex corresponding to the second endpoint is determined.
6. The method according to claim 5, characterized in that The step of determining position information of a first vertex and a second vertex corresponding to the first endpoint based on the endpoint position and the endpoint direction includes: Based on the endpoint direction, determining a vertical vector corresponding to the first endpoint; the vertical vector is perpendicular to the endpoint direction; Based on the endpoint position, the road width parameter and the vertical vector, the position information of the first vertex and the second vertex is determined; the distance between the first vertex and the endpoint position is half of the road width parameter, and the direction of the line connecting the first vertex and the endpoint position is the same as the direction of the vertical vector; the distance between the second vertex and the endpoint position is half of the road width parameter, and the direction of the line connecting the second vertex and the endpoint position is opposite to the direction of the vertical vector.
7. The method according to claim 3, characterized in that The target spline curve is divided into a plurality of sub-splines based on a vertex spacing parameter; each of the sub-splines has four vertices determined based on endpoints of the sub-spline; The step of determining polygons constituting the road model based on the position information of the plurality of vertices comprises: For each of the sub-spline lines, determine a first triangle and a second triangle based on four vertices of the sub-spline line; The first triangle and the second triangle have no overlapping parts.
8. The method according to claim 5, characterized in that The preset model parameters also include texture mapping parameters; The method further comprises: According to the connection sequence, determining the sequence number of each of the sub-splines; For each of the sub-spline lines, based on the sequence number of the sub-spline line, determining the texture coordinate parameters of the vertices corresponding to the sub-spline line; The road model is rendered based on the texture coordinate parameters and the texture mapping parameters.
9. The method according to claim 1, characterized in that: The step of determining the model portion of the road model passing through the specified terrain layer comprises: Determining a plurality of positions on the surface of the road model along a spline curve corresponding to the road model; Determining whether there is a first position located in the specified terrain layer among the positions; If yes, based on the first position, a model portion of the road model passing through the designated terrain layer is determined.
10. The method according to claim 1, characterized in that The terrain fusion parameters are represented by a preset grayscale image; the pixel values of the pixels in the grayscale image represent the fusion weights of the road model and\or the specified terrain layer; The step of determining terrain fusion parameters corresponding to the model part comprises: Determine the position correspondence between the grayscale image and the model part.
11. The method according to claim 1, characterized in that: The road model is a patch model, and the patch model is formed by connecting a plurality of vertices; The step of fusing the road model with the terrain model based on the terrain fusion parameter comprises: For each vertex of the model portion of the road model passing through the designated terrain layer, determine a target terrain height based on a terrain fusion parameter corresponding to the vertex, a terrain height of the vertex, and a terrain height of a target position corresponding to the designated terrain layer and the vertex; updating the terrain height of the vertex to the target terrain height, and updating the road model based on the updated vertex; The terrain height of the target position corresponding to the specified terrain layer and the vertex is updated to the target terrain height, and the terrain model is updated based on the updated target position.
12. The method according to claim 11, characterized in that The terrain fusion parameter is represented by a preset grayscale image; the grayscale image has a corresponding position correspondence with the model part; the pixel value of the pixel in the grayscale image represents the fusion weight of the road model and\or the specified terrain layer; The step of determining the target terrain height corresponding to the vertex based on the terrain fusion parameter corresponding to the vertex, the terrain height of the vertex, and the terrain height of the target position corresponding to the vertex and the designated terrain layer, comprises: Determining a pixel value corresponding to the vertex based on a correspondence between the grayscale image and the model portion; Determine, based on the pixel value, a first fusion weight of the terrain height of the vertex and a second fusion weight of the terrain height of the target position corresponding to the vertex and the designated terrain layer; A target terrain height is calculated based on the terrain height of the vertex, the first fusion weight, the terrain height of the target position corresponding to the designated terrain layer and the vertex, and the second fusion weight.
13. The method according to claim 1, characterized in that The method further comprises: Determine the edge position of the fused road model; Determining whether the slope of the edge position is greater than a preset slope threshold; If so, a preset protection model is generated at the edge position.
14. A model fusion device, characterized in that: The device comprises: A road model generation module, used to generate a road model in a preset virtual space; the virtual space includes a terrain model; the terrain model includes a specified terrain layer; A terrain fusion parameter determination module, used to determine a model portion of the road model passing through the specified terrain layer, and determine a terrain fusion parameter corresponding to the model portion; A fusion processing module is used to fuse the road model with the terrain model based on the terrain fusion parameter.
15. An electronic device, characterized in that: It includes a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the model fusion method described in any one of claims 1-13.
16. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores machine-executable instructions, and when the machine-executable instructions are called and executed by the processor, the machine-executable instructions prompt the processor to implement the model fusion method described in any one of claims 1-13.