Method and device for replacing ground texture in mesh model
By calculating the texture value and data range of the tile block geometry, a new coordinate system is built for texture replacement, which solves the problems of blurred boundaries and inconsistent resolution of texture replacement in the existing technology, and achieves a clear texture edge connection effect.
Patent Information
- Application Number
- CN202410611317.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-16
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2044-05-16
AI Technical Summary
In the prior art, when the texture replacement of mesh model is replaced, the boundary part is prone to blurring, and the resolution after texture replacement is inconsistent with the original texture, making it difficult to maintain a clear edge connection effect.
By calculating the unit pixel texture value and data range of the tile block geometry, a new coordinate system is built, and the target image is matched with the selected image using resampling technology, and the pixel value of the selected image is replaced one by one to achieve texture replacement.
It solves the problem of blurred boundaries after texture replacement, maintains the consistent resolution of the texture, and improves the edge connection effect.
Smart Images

Figure CN118351280B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of real-scene three-dimensional models, and in particular to a method and device for replacing ground texture in a mesh model. Background Art
[0002] Digital images of the ground and the sides of buildings collected by aerial cameras and oblique cameras can be used to generate mesh models using real-life 3D software. Mesh models are real-life 3D models with two main features: (1) the model expresses the spatial structure through a triangulated irregular network (TIN); (2) textures are added to the model to truly reflect natural terrain and objects.
[0003] The structure of the mesh model is in the form of layers and blocks. Layering refers to different resolutions, from top to bottom, from low resolution to high resolution. Blocks are divided according to the geometric position in the x and y directions. When displaying a scene, if you want to see the whole picture, you need to zoom out the scene and schedule a low-resolution mesh model. Similarly, if you want to see a detailed scene, you need to zoom in the scene and dynamically schedule a high-resolution mesh model.
[0004] Due to the modeling software itself or the operator, the mesh model texture may have holes, blur, dislocation, inconsistent uniform color, etc., so it is necessary to replace the local texture. In the existing technology, most of them use mapping, and the replaced texture is often inconsistent with the original texture resolution, and blurring will occur at the boundary. Summary of the invention
[0005] In order to solve the above problems in the prior art, the present invention proposes a method and device for replacing ground texture in a mesh model, which can effectively solve the boundary blur problem after texture replacement.
[0006] In one aspect of the present invention, a method for replacing ground texture in a mesh model is provided, the method comprising:
[0007] Calculate the unit pixel texture value of the tile block in the current LOD level according to the length and width of the tile block geometry texture image;
[0008] Calculate the data range of the selected volume and the data range of each tile block geometry in the current LOD level respectively, and then form a set of tile block geometries whose data ranges intersect with the selected volume;
[0009] Traversing all primitives of tile block geometry in the set, and generating a triangle vertex index array of the primitives of tile block geometry;
[0010] Traversing the triangle vertex index array, calculating the texture value per unit length of the triangle, and then obtaining the maximum texture value per unit length;
[0011] The new coordinate system is constructed by taking the first point on the bottom surface of the selection body as the origin of the new coordinate system, taking the line connecting the first point and the second point on the bottom surface of the selection body as the x-axis, and taking the line on the bottom surface of the selection body, passing through the origin and perpendicular to the x-axis as the y-axis;
[0012] Calculating the number of image rows and columns of the selected object according to the data range of the selected object, the maximum unit length texture value and the unit pixel texture value;
[0013] Using resampling technology, compress or enlarge the target image to the same number of rows and columns as the image of the selected object;
[0014] Calculate the row and column numbers of each pixel point in the selected volume in the new coordinate system;
[0015] According to the row and column numbers in the new coordinate system, the pixel values of the target image are used to replace the pixel values of the selected volume image one by one, so as to complete the texture replacement of the current LOD layer.
[0016] Preferably, the step of “calculating the unit pixel texture value of the tile block in the current LOD level according to the length and width of the tile block geometry texture image” comprises:
[0017] The unit pixel texture value of the tile block in the current LOD level is calculated according to the following formula:
[0018] texperpixel.x = 1.0 / iLength
[0019] texperpixel.y=1.0 / iWidth
[0020] in,
[0021] iLength and iWidth are the length and width of the tile block geometry texture image respectively; texperpixel.x and texperpixel.y are the unit pixel texture values of the tile block.
[0022] Preferably, the data range of a certain tile block geometry is calculated according to the following formula:
[0023] ptmin=MIN(bb1.x,bb1.y,bb1.z:bbn.x,bbn.y,bbn.z)
[0024] ptmax=MAX(bb1.x,bb1.y,bb1.z:bbn.x,bbn.y,bbn.z)
[0025] Among them, ptmin and ptmax are three-dimensional variables, which are used to store the minimum and maximum values of the data range of the tile block geometry respectively; bb1.x, bb1.y, bb1.z are the three-dimensional coordinates of the first vertex point of the triangulated mesh of the tile block geometry; bbn.x, bbn.y, bbn.z are the three-dimensional coordinates of the nth vertex point of the triangulated mesh of the tile block geometry; MIN means to find the minimum values of the x, y and z coordinates of all vertices of the geometry respectively; MAX means to find the maximum values of the x, y and z coordinates of all vertices of the geometry respectively;
[0026] The data range of the selected body is calculated according to the following formula:
[0027] ptmin1=MIN(aa1.x,aa1.y,aa1.z:aan.x,aan.y,aan.z)
[0028] ptmax1=MAX(aa1.x,aa1.y,aa1.z:aan.x,aan.y,aan.z)
[0029] Among them, ptmin1 and ptmax1 are both three-dimensional variables, which are respectively used to store the minimum and maximum values of the selected body data range; aa1.x, aa1.y, aa1.z are the three-dimensional coordinates of the first vertex point of the selected body; aan.x, aan.y, aan.z are the three-dimensional coordinates of the nth vertex point of the selected body; MIN means to find the minimum values of the x, y and z coordinates of all vertices of the selected body respectively; MAX means to find the maximum values of the x, y and z coordinates of all vertices of the selected body respectively.
[0030] Preferably, the step of "traversing the triangle vertex index array, calculating the texture value per unit length of the triangle, and then obtaining the maximum texture value per unit length" includes:
[0031] Traversing the triangle vertex index array, calculating the geometric coordinate difference and texture coordinate difference between all two adjacent vertices;
[0032] If the geometric coordinate difference and the texture coordinate difference between two adjacent vertices are respectively greater than the preset geometric coordinate tolerance and the preset texture coordinate tolerance, the corresponding texture value per unit length is calculated according to the following formula:
[0033] ptscale1.x=fabs(vc1.x / pt1.x)
[0034] ptscale1.y=fabs(vc1.y / pt1.y)
[0035] Wherein, ptscale1.x, ptscale1.y are the texture values of the unit length;
[0036] vc1.x, vc1.y are the texture coordinate differences between two vertices; pt1.x, pt1.y are the geometric coordinate differences between the corresponding two vertices; the fabs function represents taking the absolute value of a number;
[0037] The maximum value of all the calculated texture values per unit length is taken to obtain the maximum texture value per unit length.
[0038] Preferably, the step of "calculating the number of image rows and columns of the selected object according to the data range of the selected object, the maximum texture value per unit length and the texture value per unit pixel" comprises:
[0039] The number of image rows and columns of the selected object is calculated according to the following formula:
[0040] iRowNum=ptwidth1.x*ptscale.x / texperpixel.x+0.5
[0041] iColumnNum=ptwidth1.y*ptscale.y / texperpixel.y+0.5
[0042] ptwidth1=ptmax1-ptmin1
[0043] in,
[0044] iRowNum and iColumnNum are the number of image rows and columns of the selected body respectively; ptwidth1.x, ptwidth1.y are the geometric dimensions of the selected body; ptscale.x, ptscale.y are the maximum unit length texture values; texperpixel.x, texperpixel.y are the texture values of the unit pixel; ptmin1, ptmax1 are the minimum and maximum values of the data range of the selected body.
[0045] Preferably, the step of "calculating the row and column numbers of each pixel point in the selected volume in the new coordinate system" includes:
[0046] Traversing the triangle vertex index array to find the minimum geometric coordinate value of each triangle;
[0047] According to the texture coordinate values of the three vertices of each triangle, calculate the texture coordinate range of the triangle:
[0048] pttexMin=MIN(tta,tta1,tta2)
[0049] pttexMax=MAX(tta,tta1,tta2)
[0050] Among them, pttexMin and pttexMax are the minimum and maximum values of the texture coordinates of the triangle respectively; tta, tta1 and tta2 are the texture coordinate values of the three vertices of the triangle respectively; MIN() and MAX() are functions for finding the minimum and maximum values of the texture coordinates respectively;
[0051] According to the texture coordinate range of each triangle and the unit pixel texture value, the range of the row and column numbers of the triangle pixel value is calculated:
[0052] ioo=pttexMin.y / texperpixel.y
[0053] joo=pttexMin.x / texperpixel.x
[0054] ioo1=pttexMax.y / texperpixel.y
[0055] joo1=pttexMax.x / texperpixel.x
[0056] Among them, pttexMin.x, pttexMin.y, pttexMax.x and pttexMax.y are the texture coordinate ranges of the triangle, ioo and ioo1 are the minimum and maximum row numbers of the triangle pixel values, joo and joo1 are the minimum and maximum column numbers of the triangle pixel values, texperpixel.x and texperpixel.y are the unit pixel texture values;
[0057] The texture coordinate difference of each pixel point in the triangle is calculated based on the minimum row and column sequence number of the triangle pixel value and the unit pixel texture value:
[0058] vc2.x=(col-joo)*texperpixel.x
[0059] vc2.y=(row-ioo)*texperpixel.y
[0060] Among them, row and col are the row and column number variables of the pixel points within the triangle range; ioo and joo are the minimum row number and column number of the triangle pixel value respectively; texperpixel.x, terperpixel.y are the unit pixel texture values; vc2.x, vc2.y are the texture coordinate differences of the pixel points;
[0061] The geometric coordinate value of the pixel is calculated according to the texture coordinate difference of the pixel, the maximum unit length texture value and the minimum geometric coordinate value of the triangle:
[0062] pt1.x = vc2.x / ptscale.x + pt0.x
[0063] pt1.y=vc2.y / ptscale.y+pt0.y
[0064] Among them, pt1.x, pt1.y are the geometric coordinate values of the pixel points; vc2.x, vc2.y are the texture coordinate differences of the triangle pixel points; ptscale.x, ptscale.y are the maximum unit length texture values; pt0.x, pt0.y are the minimum geometric coordinate values of the triangle;
[0065] According to the row and column numbers of each pixel of the triangle, the unit pixel texture value and the maximum unit length texture value, the relative geometric coordinate value of each pixel point contained in each triangle in the new coordinate system is inversely calculated using affine transformation:
[0066] dx2=a1*dx1+b1*dy1
[0067] dy2=-b1*dx1+a1*dy1
[0068] a1=cos(α)
[0069] b1=sin(α)
[0070] Wherein, dx2, dy2 are the relative geometric coordinate values of the pixel point in the new coordinate system; dx1, dy1 are the relative geometric coordinate values of the pixel point in the old coordinate system; α is the counterclockwise rotation angle of the new coordinate system relative to the old coordinate system;
[0071] For each pixel point of each triangle in the selected volume, the row and column numbers of the pixel point in the new coordinate system are calculated according to the relative geometric coordinate value, the maximum unit length texture value and the unit pixel texture value of the pixel point in the new coordinate system:
[0072] jo=dx2*ptscale.x / texperpixel.x+0.5
[0073] io=dy2*ptscale.y / texperpixel.y+0.5
[0074] Among them, io and jo are the row and column numbers of the triangle pixel points in the selected body in the new coordinate system; dx2 and dy2 are the relative geometric coordinate values of the triangle pixel points in the new coordinate system; ptscale.x and ptscale.y are the maximum unit length texture values; texperpixel.x and texperpixel.y are the unit pixel texture values.
[0075] Preferably, the step of "replacing the pixel values of the selected volume image one by one with the pixel values of the target image according to the row and column numbers in the new coordinate system to complete the texture replacement of the current LOD layer" includes:
[0076] According to the row and column numbers of the triangle pixel points in the selected volume in the new coordinate system, the pixel value at the corresponding position in the target image is obtained, and the red, green and blue components of the pixel value are used to replace the red, green and blue components of the corresponding pixel value in the original image of the selected volume respectively:
[0077] img[(row*iLength1+col)*3]=img1[(io*iLength2+jo)*3]
[0078] img[(row*iLength1+col)*3+1]=img1[(io*iLength2+jo)*3+1]
[0079] img[(row*iLength1+col)*3+2]=img1[(io*iLength2+jo)*3+2]
[0080] Among them, img is the memory space for storing the original image of the selection body; img1 is the memory space for storing the target image; row and col are the pixel row and column numbers of the selection body image; io and jo are the row and column numbers of the triangle pixel points in the selection body in the new coordinate system; iLength1 is the pixel record length of the selection body image; iLength2 is the pixel record length of the target image.
[0081] Preferably, the method further comprises:
[0082] For the remaining LOD layers in the mesh model, the selected volume image is replaced by the target image.
[0083] According to a second aspect of the present invention, a processing device is provided, comprising a memory and a processor, wherein the memory stores a computer program that can be loaded by the processor and execute the method described above.
[0084] According to a third aspect of the present invention, a computer-readable storage device is provided, storing a computer program that can be loaded by a processor and execute the method described above.
[0085] The present invention has the following beneficial effects:
[0086] The present invention processes the tile block geometry that has an intersection between the data range and the selected body, constructs a new coordinate system for the selected body image that is consistent with the target image, and then, through a series of calculations, establishes a one-to-one correspondence between the pixel points in the selected body image and the pixel points in the target image, and finally uses the pixel values in the target image to replace the corresponding pixel values in the selected body image one by one, thereby achieving texture replacement. The advantages of the present invention are: using a pixel-level replacement method, compared to the mapping-type replacement method in the prior art, the replaced texture can maintain the same resolution as the original texture, can better handle the edge effect, and solves the blurring phenomenon of the boundary in the mapping method. BRIEF DESCRIPTION OF THE DRAWINGS
[0087] Figure 1 It is a schematic diagram of the main steps of an embodiment of a method for replacing ground texture in a mesh model of the present invention;
[0088] Figure 2 is a partial schematic diagram of the ground texture of the mesh model in an embodiment of the present invention;
[0089] Figure 3 It is a schematic diagram of a new coordinate system constructed in an embodiment of the present invention. DETAILED DESCRIPTION
[0090] The preferred embodiments of the present invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are only used to explain the technical principles of the present invention and are not intended to limit the protection scope of the present invention.
[0091] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0092] It should be noted that, in the description of the present invention, the terms "first" and "second" are only for the convenience of description, and do not indicate or imply the relative importance of the devices, elements or parameters, and therefore cannot be understood as limiting the present invention. In addition, the term "and / or" in the present invention is only a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally indicates that the associated objects before and after are in an "or" relationship.
[0093] Figure 1 FIG. 1 is a schematic diagram of the main steps of an embodiment of a method for replacing ground texture in a mesh model of the present invention. Figure 1 As shown, the replacement method of this embodiment includes steps S10-S90:
[0094] Step S10, calculating the unit pixel texture value of the tile block in the current LOD level according to the length and width of the tile block geometry texture image.
[0095] Specifically, the unit pixel texture value of the tile block in the current LOD level is calculated according to the method shown in the following formulas (1)-(2):
[0096] texperpixel.x = 1.0 / iLength (1)
[0097] texperpixel.y = 1.0 / iWidth (2)
[0098] Among them, iLength and iWidth are the length and width of the tile block geometry texture image respectively; texperpixel.x and texperpixel.y are the unit pixel texture values of the tile block.
[0099] Step S20, respectively calculate the data range of the selected volume and the data range of each tile block geometry in the current LOD level, and then form a set of tile block geometry that have an intersection between the data range and the selected volume. This step may specifically include steps S21-S23:
[0100] Step S21, calculate the data range of a tile block geometry according to the method shown in the following formulas (3)-(4):
[0101] ptmin = MIN(bb1.x, bb1.y, bb1.z:bbn.x,bbn.y,bbn.z) (3)
[0102] ptmax = MAX(bb1.x, bb1.y, bb1.z:bbn.x,bbn.y,bbn.z) (4)
[0103] Among them, ptmin and ptmax are both three-dimensional variables, which are respectively used to store the minimum and maximum values of the data range of the tile block geometry; bb1.x, bb1.y, bb1.z are the three-dimensional coordinates of the first vertex point of the triangulated network of the tile block geometry; bbn.x, bbn.y, bbn.z are the three-dimensional coordinates of the nth vertex point of the triangulated network of the tile block geometry; MIN means to find the minimum values of the x, y and z coordinates of all vertices of the geometry respectively; MAX means to find the maximum values of the x, y and z coordinates of all vertices of the geometry respectively.
[0104] Step S22, calculate the data range of the selected body according to the method shown in the following formulas (5)-(6):
[0105] ptmin1 = MIN(aa1.x, aa1.y, aa1.z:aan.x,aan.y,aan.z) (5)
[0106] ptmax1 = MAX(aa1.x, aa1.y, aa1.z:aan.x,aan.y,aan.z) (6)
[0107] Among them, ptmin1 and ptmax1 are both three-dimensional variables, which are used to store the minimum and maximum values of the selected body data range respectively; aa1.x, aa1.y, aa1.z are the three-dimensional coordinates of the first vertex of the selected body; aan.x, aan.y, aan.z are the three-dimensional coordinates of the nth vertex of the selected body; MIN means to find the minimum values of the x, y and z coordinates of all vertices of the selected body respectively; MAX means to find the maximum values of the x, y and z coordinates of all vertices of the selected body respectively.
[0108] Step S23, grouping the tile block geometric bodies that have an intersection between the data range and the selection body into a set.
[0109] Figure 2 FIG. 1 is a partial schematic diagram of the ground texture of the mesh model in an embodiment of the present invention. Figure 2 As shown in the figure, there are 4 tiles, the intersections between them form a cross, each tile contains several triangles surrounded by thin white lines, and the three-dimensional figure surrounded by thick white lines is the selection body. It can be seen from the figure that the data ranges of these 4 adjacent tiles intersect with the data range of the selection body, so these 4 tile geometry bodies are combined into a set, and the subsequent steps only process the tiles in this set.
[0110] Step S30, traverse all tile block geometry primitives in the set to generate a tile block geometry primitive triangle vertex index array.
[0111] Step S40, traverse the triangle vertex index array, calculate the texture value per unit length of the triangle, and then obtain the maximum texture value per unit length. This step may specifically include steps S41-S43:
[0112] Step S41, traverse the triangle vertex index array, and calculate the geometric coordinate difference and texture coordinate difference between all two adjacent vertices.
[0113] Step S42: If the geometric coordinate difference and the texture coordinate difference between two adjacent vertices are respectively greater than the preset geometric coordinate tolerance and the preset texture coordinate tolerance, the corresponding texture value per unit length can be calculated according to the method shown in the following formulas (7)-(8):
[0114] ptscale1.x = fabs(vc1.x / pt1.x) (7)
[0115] ptscale1.y = fabs(vc1.y / pt1.y) (8)
[0116] Among them, ptscale1.x, ptscale1.y are texture values of unit length; vc1.x, vc1.y are the texture coordinate differences between two vertices; pt1.x, pt1.y are the geometric coordinate differences between the corresponding two vertices; the fabs function means taking the absolute value of a number.
[0117] Step S43, taking the maximum value among all the calculated unit length texture values to obtain the maximum unit length texture value.
[0118] In order to facilitate texture replacement, a coordinate system that is unified with the target image needs to be specially constructed for the selected object, which is referred to as the new coordinate system below, and the coordinate system of the original image is called the old coordinate system. Figure 3 Schematic diagram of a new coordinate system constructed in an embodiment of the present invention. Figure 3 As shown, the coordinate system composed of x, o, and y is the old coordinate system. According to the method of the following step S50, a new coordinate system composed of x', o', and y' is constructed, and α is the counterclockwise rotation angle of the new coordinate system relative to the old coordinate system.
[0119] Step S50, select the first point on the bottom surface of the body as the origin of the new coordinate system (marked as o′ in the figure), select the line connecting the first point and the second point on the bottom surface of the body as the x-axis (marked as x′ in the figure), and select the line on the bottom surface of the body, passing through the origin and perpendicular to the x-axis as the y-axis (marked as y′ in the figure), so as to construct a new coordinate system.
[0120] Step S60, calculating the number of image rows and columns of the selected object according to the data range of the selected object, the maximum unit length texture value and the unit pixel texture value.
[0121] Specifically, the number of image rows and columns of the selected object can be calculated according to the method shown in the following formulas (9)-(11):
[0122] iRowNum = ptwidth1.x*ptscale.x / texperpixel.x+0.5 (9)
[0123] iColumnNum = ptwidth1.y*ptscale.y / texperpixel.y+0.5 (10)
[0124] ptwidth1 = ptmax1-ptmin1 (11)
[0125] Among them, iRowNum and iColumnNum are the number of image rows and columns of the selected body respectively; ptwidth1.x, ptwidth1.y are the geometric dimensions of the selected body; ptscale.x, ptscale.y are the maximum unit length texture values; texperpixel.x, texperpixel.y are the texture values per unit pixel; ptmin1, ptmax1 are the minimum and maximum values of the data range of the selected body; ptmin1.x and ptmax1.x are the minimum and maximum values in the x direction respectively, and ptmin1.y and ptmax1.y are the minimum and maximum values in the y direction respectively.
[0126] Step S70, using resampling technology, compressing or enlarging the target image to the same number of rows and columns as the image of the selected object.
[0127] Step S80, calculating and selecting the row and column numbers of each pixel point in the body in the new coordinate system.
[0128] This step may specifically include steps S81-S87:
[0129] Step S81, traverse the triangle vertex index array to find the minimum geometric coordinate value of each triangle.
[0130] The minimum geometric coordinate value of each triangle includes the minimum geometric coordinate value of the triangle in the x direction and the minimum geometric coordinate value of the triangle in the y direction.
[0131] Step S82, calculate the texture coordinate range of each triangle according to the texture coordinate values of the three vertices of the triangle, as shown in formulas (12)-(13):
[0132] pttexMin = MIN(tta, tta1, tta2) (12)
[0133] pttexMax = MAX(tta, tta1, tta2) (13)
[0134] Among them, pttexMin and pttexMax are the minimum and maximum values of the triangle texture coordinates, that is, the texture coordinate range of the triangle; tta, tta1 and tta2 are the texture coordinate values of the three vertices of the triangle; MIN() and MAX() are functions for finding the minimum and maximum values of the texture coordinates, respectively.
[0135] Step S83, according to the texture coordinate range and unit pixel texture value of each triangle, calculate the range of the row and column numbers of the triangle pixel value, as shown in the following formulas (14)-(17):
[0136] ioo =pttexMin.y / texperpixel.y (14)
[0137] joo =pttexMin.x / texperpixel.x (15)
[0138] ioo1=pttexMax.y / texperpixel.y (16)
[0139] joo1=pttexMax.x / texperpixel.x (17)
[0140] Among them, pttexMin.x, pttexMin.y, pttexMax.x and pttexMax.y are the texture coordinate ranges of the triangle, ioo and ioo1 are the minimum and maximum row numbers of the triangle pixel values respectively, joo and joo1 are the minimum and maximum column numbers of the triangle pixel values respectively, and texperpixel.x and texperpixel.y are unit pixel texture values.
[0141] Step S84, calculate the texture coordinate difference of each pixel point in the triangle according to the minimum row and column sequence number of the triangle pixel value and the unit pixel texture value, as shown in formulas (18)-(19):
[0142] vc2.x = (col-joo)*texperpixel.x (18)
[0143] vc2.y = (row-ioo)*texperpixel.y (19)
[0144] Among them, row and col are the row and column number variables of the pixel points within the triangle range; ioo and joo are the minimum row number and column number of the triangle pixel value respectively; texperpixel.x, terperpixel.y are the unit pixel texture values; vc2.x, vc2.y are the texture coordinate differences of the pixel points;
[0145] Step S85, calculate the geometric coordinate value of the pixel point according to the texture coordinate difference of the pixel point, the maximum unit length texture value and the minimum geometric coordinate value of the triangle, as shown in formulas (20)-(21):
[0146] pt1.x = vc2.x / ptscale.x+pt0.x (20)
[0147] pt1.y = vc2.y / ptscale.y+pt0.y (21)
[0148] Among them, pt1.x, pt1.y are the geometric coordinate values of the pixel points; vc2.x, vc2.y are the texture coordinate differences of the triangle pixel points; ptscale.x, ptscale.y are the maximum unit length texture values; pt0.x, pt0.y are the minimum geometric coordinate values of the triangle;
[0149] Step S86, according to the row and column numbers, unit pixel texture value and maximum unit length texture value of each pixel of each triangle, the relative geometric coordinate value of each pixel point contained in each triangle in the new coordinate system is calculated by using affine transformation, as shown in formulas (22)-(25):
[0150] dx2 = a1*dx1+b1*dy1 (22)
[0151] dy2 = -b1*dx1+a1*dy1 (23)
[0152] a1 = cos(α) (24)
[0153] b1 = sin(α) (25)
[0154] Wherein, dx2, dy2 are the relative geometric coordinate values of the pixel point in the new coordinate system; dx1, dy1 are the relative geometric coordinate values of the pixel point in the old coordinate system; α is the counterclockwise rotation angle of the new coordinate system relative to the old coordinate system;
[0155] Step S87, for each pixel point of each triangle in the selected body, the row and column numbers of the pixel point in the new coordinate system are calculated according to the relative geometric coordinate value, the maximum unit length texture value and the unit pixel texture value of the pixel point in the new coordinate system, as shown in formulas (26)-(27):
[0156] jo = dx2*ptscale.x / texperpixel.x+0.5 (26)
[0157] io = dy2*ptscale.y / texperpixel.y+0.5 (27)
[0158] Among them, io and jo are the row and column numbers of the selected triangle pixel points in the new coordinate system; dx2 and dy2 are the relative geometric coordinate values of the triangle pixel points in the new coordinate system; ptscale.x and ptscale.y are the maximum unit length texture values; texperpixel.x and texperpixel.y are the unit pixel texture values.
[0159] When extracting the image pixel point set contained in each triangle of the tile mesh triangulation network, the drop method can be used.
[0160] Step S90, according to the row and column numbers in the new coordinate system, the pixel values of the target image are used to replace the pixel values of the selected volume image one by one, so as to complete the texture replacement of the current LOD layer.
[0161] Specifically, the pixel value of the corresponding position in the target image is obtained according to the row and column numbers of the triangle pixel points in the selected body in the new coordinate system, and the red, green and blue components of the pixel value are used to replace the red, green and blue components of the corresponding pixel value in the original image of the selected body, as shown in formulas (28)-(30):
[0162] img[(row*iLength1+col)*3] = img1[(io*iLength2+jo)*3] (28)
[0163] img[(row*iLength1+col)*3+1] = img1[(io*iLength2+jo)*3+1] (29)
[0164] img[(row*iLength1+col)*3+2] = img1[(io*iLength2+jo)*3+2] (30)
[0165] Among them, img is the memory space for storing the original image of the selected body; img1 is the memory space for storing the target image; row and col are the pixel row and column numbers of the selected body image; io and jo are the row and column numbers of the triangle pixel points in the selected body in the new coordinate system; iLength1 is the pixel record length of the selected body image; iLength2 is the pixel record length of the target image.
[0166] Although the various steps in the above embodiment are described in the above-mentioned order, those skilled in the art can understand that in order to achieve the effect of this embodiment, different steps do not have to be executed in such an order. They can be executed simultaneously (in parallel) or in a reverse order. These simple changes are within the scope of protection of the present invention.
[0167] In an optional embodiment, it also includes:
[0168] Step S100: For the remaining LOD layers in the mesh model, the selected volume image is replaced with the target image, thereby completing the replacement of the selected volume image in the entire mesh model.
[0169] Furthermore, the present invention also provides an embodiment of a processing device. The processing device of this embodiment includes a memory and a processor. The memory stores a computer program that can be loaded by the processor and execute the method as described above.
[0170] Furthermore, the present invention also provides an embodiment of a computer-readable storage device, in which the storage device of this embodiment stores a computer program that can be loaded by a processor and execute the method described above.
[0171] The computer-readable storage device may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0172] Those skilled in the art should be able to appreciate that the method steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of electronic hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in electronic hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0173] So far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.
Claims
1. A method for replacing ground texture in a mesh model, characterized in that: The method comprises: Calculate the unit pixel texture value of the tile block in the current LOD level according to the length and width of the tile block geometry texture image; Calculate the data range of the selected volume and the data range of each tile block geometry in the current LOD level respectively, and then form a set of tile block geometries whose data ranges intersect with the selected volume; Traversing all primitives of tile block geometry in the set, and generating a triangle vertex index array of the primitives of tile block geometry; Traversing the triangle vertex index array, calculating the texture value per unit length of the triangle, and then obtaining the maximum texture value per unit length; The new coordinate system is constructed by taking the first point on the bottom surface of the selection body as the origin of the new coordinate system, taking the line connecting the first point and the second point on the bottom surface of the selection body as the x-axis, and taking the line on the bottom surface of the selection body, passing through the origin and perpendicular to the x-axis as the y-axis; Calculating the number of image rows and columns of the selected object according to the data range of the selected object, the maximum unit length texture value and the unit pixel texture value; Using resampling technology, compress or enlarge the target image to the same number of rows and columns as the image of the selected object; Calculate the row and column numbers of each pixel point in the selected volume in the new coordinate system; According to the row and column numbers in the new coordinate system, the pixel values of the target image are used to replace the pixel values of the selected volume image one by one, so as to complete the texture replacement of the current LOD layer.
2. The method for replacing ground texture in a mesh model according to claim 1, characterized in that: The steps of "calculating the unit pixel texture value of the tile block in the current LOD level according to the length and width of the tile block geometry texture image" include: The unit pixel texture value of the tile block in the current LOD level is calculated according to the following formula: texperpixel.x = 1.0 / iLength texperpixel.y=1.0 / iWidth in, iLength and iWidth are the length and width of the tile block geometry texture image respectively; texperpixel.x and texperpixel.y are the unit pixel texture values of the tile block.
3. The method for replacing ground texture in a mesh model according to claim 1, characterized in that: The data range of a tile block geometry is calculated according to the following formula: ptmin=MIN(bb1.x,bb1.y,bb1.z:bbn.x,bbn.y,bbn.z) ptmax=MAX(bb1.x,bb1.y,bb1.z:bbn.x,bbn.y,bbn.z) Among them, ptmin and ptmax are three-dimensional variables, which are used to store the minimum and maximum values of the data range of the tile block geometry respectively; bb1.x, bb1.y, bb1.z are the three-dimensional coordinates of the first vertex point of the triangulated mesh of the tile block geometry; bbn.x, bbn.y, bbn.z are the three-dimensional coordinates of the nth vertex point of the triangulated mesh of the tile block geometry; MIN means to find the minimum values of the x, y and z coordinates of all vertices of the geometry respectively; MAX means to find the maximum values of the x, y and z coordinates of all vertices of the geometry respectively; The data range of the selected body is calculated according to the following formula: ptmin1=MIN(aa1.x,aa1.y,aa1.z:aan.x,aan.y,aan.z) ptmax1=MAX(aa1.x,aa1.y,aa1.z:aan.x,aan.y,aan.z) Among them, ptmin1 and ptmax1 are both three-dimensional variables, which are respectively used to store the minimum and maximum values of the selected body data range; aa1.x, aa1.y, aa1.z are the three-dimensional coordinates of the first vertex point of the selected body; aan.x, aan.y, aan.z are the three-dimensional coordinates of the nth vertex point of the selected body; MIN means to find the minimum values of the x, y and z coordinates of all vertices of the selected body respectively; MAX means to find the maximum values of the x, y and z coordinates of all vertices of the selected body respectively.
4. The method for replacing ground texture in a mesh model according to claim 1, characterized in that: The step of "traversing the triangle vertex index array, calculating the texture value per unit length of the triangle, and then obtaining the maximum texture value per unit length" includes: Traversing the triangle vertex index array, calculating the geometric coordinate difference and texture coordinate difference between all two adjacent vertices; If the geometric coordinate difference and the texture coordinate difference between two adjacent vertices are respectively greater than the preset geometric coordinate tolerance and the preset texture coordinate tolerance, the corresponding texture value per unit length is calculated according to the following formula: ptscale1.x=fabs(vc1.x / pt1.x) ptscale1.y=fabs(vc1.y / pt1.y) Wherein, ptscale1.x, ptscale1.y are the texture values of the unit length; vc1.x, vc1.y are the texture coordinate differences between two vertices; pt1.x, pt1.y are the geometric coordinate differences between the corresponding two vertices; the fabs function represents taking the absolute value of a number; The maximum value of all the calculated texture values per unit length is taken to obtain the maximum texture value per unit length.
5. The method for replacing ground texture in a mesh model according to claim 3, characterized in that: The step of "calculating the number of image rows and columns of the selected object according to the data range of the selected object, the maximum unit length texture value and the unit pixel texture value" includes: The number of image rows and columns of the selected object is calculated according to the following formula: iRowNum=ptwidth1.x*ptscale.x / texperpixel.x+0.5 iColumnNum=ptwidth1.y*ptscale.y / texperpixel.y+0.5 ptwidth1=ptmax1-ptmin1 in, iRowNum and iColumnNum are the number of image rows and columns of the selected body respectively; ptwidth1.x, ptwidth1.y are the geometric dimensions of the selected body; ptscale.x, ptscale.y are the maximum unit length texture values; texperpixel.x, texperpixel.y are the texture values of the unit pixel; ptmin1, ptmax1 are the minimum and maximum values of the data range of the selected body.
6. The method for replacing ground texture in a mesh model according to claim 1, characterized in that: The step of "calculating the row and column numbers of each pixel point in the selected volume in the new coordinate system" includes: Traversing the triangle vertex index array to find the minimum geometric coordinate value of each triangle; According to the texture coordinate values of the three vertices of each triangle, calculate the texture coordinate range of the triangle: pttexMin=MIN(tta,tta1,tta2) pttexMax=MAX(tta,tta1,tta2) Among them, pttexMin and pttexMax are the minimum and maximum values of the triangle texture coordinates respectively; tta, tta1 and tta2 are the texture coordinate values of the three vertices of the triangle respectively; MIN() and MAX() are the functions for finding the minimum and maximum values of the texture coordinates respectively; According to the texture coordinate range of each triangle and the unit pixel texture value, the range of the row and column numbers of the triangle pixel value is calculated: ioo=pttexMin.y / texperpixel.y joo=pttexMin.x / texperpixel.x ioo1=pttexMax.y / texperpixel.y joo1=pttexMax.x / texperpixel.x Among them, pttexMin.x, pttexMin.y, pttexMax.x and pttexMax.y are the texture coordinate ranges of the triangle, ioo and ioo1 are the minimum and maximum row numbers of the triangle pixel values, joo and joo1 are the minimum and maximum column numbers of the triangle pixel values, texperpixel.x and texperpixel.y are the unit pixel texture values; The texture coordinate difference of each pixel point in the triangle is calculated based on the minimum row and column sequence number of the triangle pixel value and the unit pixel texture value: vc2.x=(col-joo)*texperpixel.x vc2.y=(row-ioo)*texperpixel.y Among them, row and col are the row and column number variables of the pixel points within the triangle range; ioo and joo are the minimum row number and column number of the triangle pixel value respectively; texperpixel.x, terperpixel.y are the unit pixel texture values; vc2.x, vc2.y are the texture coordinate differences of the pixel points; The geometric coordinate value of the pixel is calculated according to the texture coordinate difference of the pixel, the maximum unit length texture value and the minimum geometric coordinate value of the triangle: pt1.x = vc2.x / ptscale.x + pt0.x pt1.y=vc2.y / ptscale.y+pt0.y Among them, pt1.x, pt1.y are the geometric coordinate values of the pixel points; vc2.x, vc2.y are the texture coordinate differences of the triangle pixel points; ptscale.x, ptscale.y are the maximum unit length texture values; pt0.x, pt0.y are the minimum geometric coordinate values of the triangle; According to the row and column numbers of each pixel of the triangle, the unit pixel texture value and the maximum unit length texture value, the relative geometric coordinate value of each pixel point contained in each triangle in the new coordinate system is inversely calculated using affine transformation: dx2=a1*dx1+b1*dy1 dy2=-b1*dx1+a1*dy1 a1=cos(α) b1=sin(α) Wherein, dx2, dy2 are the relative geometric coordinate values of the pixel point in the new coordinate system; dx1, dy1 are the relative geometric coordinate values of the pixel point in the old coordinate system; α is the counterclockwise rotation angle of the new coordinate system relative to the old coordinate system; For each pixel point of each triangle in the selected volume, the row and column numbers of the pixel point in the new coordinate system are calculated according to the relative geometric coordinate value, the maximum unit length texture value and the unit pixel texture value of the pixel point in the new coordinate system: jo=dx2*ptscale.x / texperpixel.x+0.5 io=dy2*ptscale.y / texperpixel.y+0.5 Among them, io and jo are the row and column numbers of the triangle pixel points in the selected body in the new coordinate system; dx2 and dy2 are the relative geometric coordinate values of the triangle pixel points in the new coordinate system; ptscale.x and ptscale.y are the maximum unit length texture values; texperpixel.x and texperpixel.y are the unit pixel texture values.
7. The method for replacing ground texture in a mesh model according to claim 1, characterized in that: The step of "replacing the pixel values of the selected volume image one by one with the pixel values of the target image according to the row and column numbers in the new coordinate system to complete the texture replacement of the current LOD layer" includes: According to the row and column numbers of the triangle pixel points in the selected volume in the new coordinate system, the pixel value at the corresponding position in the target image is obtained, and the red, green and blue components of the pixel value are used to replace the red, green and blue components of the corresponding pixel value in the original image of the selected volume respectively: img[(row*iLength1+col)*3]=img1[(io*iLength2+jo)*3] img[(row*iLength1+col)*3+1]=img1[(io*iLength2+jo)*3+1] img[(row*iLength1+col)*3+2]=img1[(io*iLength2+jo)*3+2] Among them, img is the memory space for storing the original image of the selection body; img1 is the memory space for storing the target image; row and col are the pixel row and column numbers of the selection body image; io and jo are the row and column numbers of the triangle pixel points in the selection body in the new coordinate system; iLength1 is the pixel record length of the selection body image; iLength2 is the pixel record length of the target image.
8. The method for replacing ground texture in a mesh model according to claim 1, characterized in that: The method further comprises: For the remaining LOD layers in the mesh model, the selected volume image is replaced by the target image.
9. A processing device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program that can be loaded by the processor and execute the method according to any one of claims 1 to 8.
10. A computer-readable storage device, characterized in that: A computer program is stored which can be loaded by a processor and execute the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Three-dimensional image generation method and device, electronic equipment and storage medium
CN113643414A
Tile data compression method, device and equipment
CN117692009A
