3D word rendering method and system and medium
By obtaining the vertex information in the 2D picture and calculating the normal vector, the problem of lack of normal vector information when rendering 3D words is solved, and more obvious outlines and stronger front and back distinctions are achieved, improving rendering quality.
Patent Information
- Application Number
- CN202510038977.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-10
- Publication Date
- 2025-05-16
AI Technical Summary
The prior art cannot obtain normal vector information when rendering 3D words, resulting in difficulty in lighting calculation and lack of contour distinction between front and back.
By obtaining the vertex information in the 2D picture, calculating the normal vector, and combining the vertex information for 3D word rendering, the rendering effect is optimized to more clearly reflect the 3D word outline and distinguish the front and back sides.
It improves the rendering effect of 3D characters, makes the outline more obvious, and the distinction between front and back sides is stronger, improving the rendering quality.
Smart Images

Figure CN120014131A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of 3D character rendering, and in particular to a 3D character rendering method, system and medium. Background Art
[0002] At present, when rendering 3D characters using Opengles / Direct3D and other rendering libraries, we only know a 2D character image. Under the existing methods, we can only get the character's vertices and texture coordinates, that is, the coordinate information of the 3D character, but we can't get the 3D character's normal vector information. Without the normal vector information, we can't perform all the lighting calculations, and the outline of the rendered 3D characters is not clear, and we can't distinguish the front and side. Summary of the invention
[0003] The main purpose of the present invention is to provide a 3D character rendering method, system and medium, aiming to improve the rendering effect of 3D characters, so as to more clearly reflect the outline of 3D characters and better distinguish the front, back and sides of 3D characters.
[0004] To achieve the above object, the present invention provides a 3D character rendering method, the method comprising the following steps:
[0005] Step S100, obtaining vertex information in a 2D image;
[0006] Step S200, obtaining data information required for calculating a normal vector according to the vertex information;
[0007] Step S300, calculating a normal vector according to the data information required for calculating the normal vector;
[0008] Step S400, rendering 3D characters according to the vertex information and the calculated normal vector;
[0009] Step S500, optimizing the display effect of the rendered 3D characters.
[0010] A further technical solution of the present invention is that step S100 comprises:
[0011] Step S110 , traverse each pixel point of the 2D image according to the pixel width and height of the 2D image, and record the colored pixel points therein as vertex data.
[0012] A further technical solution of the present invention is that step S110 comprises:
[0013] Step S111 , traverse the pixel points on each row along the X direction row by row according to a preset step distance in the Y direction, and record the colored pixel points therein as vertex data.
[0014] A further technical solution of the present invention is that step S111 comprises:
[0015] Step S112, when traversing in the X direction, first start traversing from 0, when a point with color is found, mark this point as the starting point, and then continue traversing; every time it is found that the next pixel point is without color, it is necessary to record the starting point and the position of this point as vertex data; then reset the starting point and end point marks, and then traverse downwards, when a point with color is found again, mark this point as the starting point, and then repeat the above steps until all the pixel data in this row are traversed.
[0016] A further technical solution of the present invention is that step S200 comprises:
[0017] Step S210, calling AddPointToList for the first time to obtain vertex information for drawing and put it into topVec;
[0018] Step S220, call AddPointToList again to obtain vertex information used to calculate the normal vector, and put it into calNorLowerVec;
[0019] Step S230, traverse topVec for the first time, put a vertex into desVec, then increase the Y coordinate of the vertex by a step distance to obtain two vertices of the first rectangle, and then traverse for the second time, and so on to obtain the other two vertices of the first rectangle, and then traverse again until all the vertex information in topVec is traversed;
[0020] Step S240, determining whether the number of elements in topVec and calNorLowerVec is equal, if they are equal, executing step S300;
[0021] If the number of elements in topVec and calNorLowerVec is not equal, the normal vectors of the left and right faces of the 3D font are replaced by (-1.0f, 0.0f, 0.0f) and (1.0f, 0.0f, 0.0f).
[0022] A further technical solution of the present invention is that step S300 includes: obtaining a line connecting two points on the side of the 3D character, and a slope of a line on a 2D plane connected to the line, and calculating a normal vector of the side of the 3D character, and normal vectors of the front and back of the 3D character.
[0023] A further technical solution of the present invention is that step S400 includes: rendering 3D cubes one by one according to the vertex information of all rectangles and the calculated normal vectors to splice into a corresponding 3D model; wherein, a rectangle is formed according to every four vertex information in desVec, and then the thickness of the rectangle is increased, that is, the Z coordinate is increased to form a cube.
[0024] A further technical solution of the present invention is that step S500 comprises:
[0025] The front, back and sides of the 3D characters are rendered differently based on the normal vector information. For the sides of the 3D characters, a color ratio is obtained by adding the absolute value of the Z coordinate of the normal vector to 1.0 and then dividing by 2.0. The calculated color is then multiplied by the color ratio.
[0026] To achieve the above object, the present invention further proposes a 3D word rendering system, which includes a memory, a processor, and a 3D word rendering program stored on the processor, and the 3D word rendering program executes the steps of the above method when executed by the processor.
[0027] To achieve the above object, the present invention further proposes a computer-readable storage medium, characterized in that the computer-readable storage medium stores a 3D word rendering program, and the 3D word rendering program executes the steps of the above method when executed by a processor.
[0028] The beneficial effects of the 3D character rendering method, system and medium of the present invention are:
[0029] The present invention obtains vertex information in a 2D image through the above technical solution; obtains data information required for calculating a normal vector based on the vertex information; calculates a normal vector based on the data information required for calculating the normal vector; renders 3D characters based on the vertex information and the calculated normal vector; and optimizes the display effect of the rendered 3D characters, thereby improving the rendering effect of the 3D characters and more clearly reflecting the contour of the 3D characters. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying creative work.
[0031] Figure 1 It is a schematic diagram of the overall process of the 3D character rendering method of the present invention;
[0032] Figure 2is a detailed flow chart of step S200;
[0033] Figure 3 It is a schematic diagram of a 3D word picture;
[0034] Figure 4 It is a schematic diagram of the four vertex information of a rectangle;
[0035] Figure 5 This is a schematic diagram of normal vector calculation;
[0036] Figure 6 A rectangular diagram is formed based on every 4 data in desVec;
[0037] Figure 7 It is a schematic diagram of a cube;
[0038] Figure 8 It is a rendered 3D word schematic;
[0039] Fig. 9 This is a schematic diagram of the optimized 3D text rendering;
[0040] Fig.10 It is a system architecture diagram of the 3D character rendering system of the present invention.
[0041] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0042] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only 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.
[0043] The present invention proposes a 3D word rendering method, and the background technology for implementing the 3D word rendering method of the present invention is Opengles and C++. It can also be implemented using other rendering APIs and languages, and the technical principles are exactly the same, only the implementation has slight API differences. Using this solution, in addition to the vertex coordinate data, index data and texture coordinate data that can only render 3D word special effects, additional normal vector information can be obtained, and then the front and side are differentiated according to the normal vector information, so that the effect of the 3D word special effects is greatly improved. At the same time, different strategies for obtaining vertices are selected according to the width and height of the original image, and the rendering method is optimized. It is no longer just rendering plane rectangles one by one, but rendering multiple cubes to superimpose into a 3D word, so as to reduce the number of rendered geometric bodies and further improve the performance.
[0044] Please refer to Figure 1 The 3D character rendering method of the present invention comprises the following steps:
[0045] Step S100, obtaining vertex information in a 2D image.
[0046] Wherein, the step S100 specifically includes:
[0047] Step S110 , traverse each pixel point of the 2D image according to the pixel width and height of the 2D image, and record the colored pixel points therein as vertex data.
[0048] The step S110 specifically includes:
[0049] Step S111 , traverse the pixel points on each row along the X direction row by row according to a preset step distance in the Y direction, and record the colored pixel points therein as vertex data.
[0050] The step S111 comprises:
[0051] Step S112, when traversing in the X direction, first start traversing from 0, when a point with color is found, mark this point as the starting point, and then continue traversing; every time it is found that the next pixel point is without color, it is necessary to record the starting point and the position of this point as vertex data; then reset the starting point and end point marks, and then traverse downwards, when a point with color is found again, mark this point as the starting point, and then repeat the above steps until all the pixel data in this row are traversed.
[0052] Step S200, obtaining data information required for calculating normal vectors according to the vertex information.
[0053] Please refer to Figure 2 , the step S200 comprises:
[0054] Step S210, calling AddPointToList for the first time to obtain vertex information for drawing and put it into topVec;
[0055] Step S220, call AddPointToList again to obtain vertex information used to calculate the normal vector, and put it into calNorLowerVec;
[0056] Step S230, traverse topVec for the first time, put a vertex into desVec, then increase the Y coordinate of the vertex by a step distance to obtain two vertices of the first rectangle, and then traverse for the second time, and so on to obtain the other two vertices of the first rectangle, and then traverse again until all the vertex information in topVec is traversed;
[0057] Step S240, determining whether the number of elements in topVec and calNorLowerVec is equal, if they are equal, executing step S300;
[0058] If the number of elements in topVec and calNorLowerVec is not equal, the normal vectors of the left and right faces of the 3D font are replaced by (-1.0f, 0.0f, 0.0f) and (1.0f, 0.0f, 0.0f).
[0059] Step S300, calculating a normal vector according to the data information required for calculating the normal vector.
[0060] The step S300 specifically includes: obtaining a line connecting two points on the side of the 3D character, and a slope of a line on a 2D plane connected to the line, and calculating a normal vector of the side of the 3D character, and normal vectors of the front and back of the 3D character.
[0061] Step S400: Rendering 3D characters according to the vertex information and the calculated normal vectors.
[0062] The step S400 specifically includes: rendering 3D cubes according to the vertex information of all rectangles and the calculated normal vectors to splice into the corresponding 3D model; wherein, a rectangle is formed according to every four vertex information in desVec, and then the thickness of the rectangle is increased, that is, the Z coordinate is increased to form a cube.
[0063] Step S500, optimizing the display effect of the rendered 3D characters.
[0064] The step S500 specifically includes:
[0065] The front, back and sides of the 3D characters are rendered differently based on the normal vector information. For the sides of the 3D characters, a color ratio is obtained by adding the absolute value of the Z coordinate of the normal vector to 1.0 and then dividing by 2.0. The calculated color is then multiplied by the color ratio.
[0066] The following combination Figures 1 to 9 The workflow of 3D character rendering of the present invention is further elaborated in detail.
[0067] 1. From a Figure 3 Get the vertex information and the data needed to calculate the normal vector from the 2D picture shown:
[0068] 1. The present invention first needs to be based on Figure 3The pixel width and height of the 2D image shown in the figure are used to traverse each pixel, starting from the upper left corner: for (int y = 0; y <height;y+=interval)。
[0069] The interval is the distance of each step, and is generally set to 1. However, if the image is very large, if the interval is still equal to 1, the loop will be performed many times. At the same time, the more the number of loops, the more vertex information will be generated. The more vertex information, the greater the cost of rendering a 3D character. Therefore, the present invention needs to think of a method to reduce the generated vertex information as much as possible without reducing the rendering quality, that is, to increase the interval.
[0070] 2. This method is to flexibly determine the size of the interval according to the pixel size of the image. Because when the image is very large, there is no need to traverse pixel by pixel. For example, you only need to get the data of the first and sixth rows to represent all the data of rows 1 to 6. Because the image is very large, the difference between each row is relatively small. But when the image is very small, this cannot be done because the difference between the data of each row is still quite obvious.
[0071] int interval = 1;
[0072] int minSize=std::min(width,height);
[0073] interval=interval+(minSize-256) / 256.
[0074] 3. After the loop in the y direction is entered, the present invention starts to traverse each pixel point in the x direction.
[0075] The specific plan is as follows:
[0076] ① Start from left to right and traverse the pixels one by one. As long as the pixel is found to have color, the position of this point is recorded.
[0077] ② However, the vertex data obtained in this way is very large, and there are as many vertex data as there are pixels. Such a large amount of vertex data puts a great load on the GPU, and there is no need to use so much vertex data. The present invention only needs to obtain a few key vertex data to draw the 3D model.
[0078] ③ As we all know, a 2D figure can be regarded as composed of countless line segments. Then the present invention can remove the x coordinates of the vertex data obtained above that are continuously increased by 1, leaving only the first and last coordinates to connect into line segments. However, it cannot be simply removed directly. Because some pictures do not have only one figure in the horizontal direction. For example, there are four figures on this horizontal line.
[0079] So when traversing in the x direction, first start traversing from x equals 0. When a point with color is found, mark this point as the starting point, and then continue traversing. Whenever the next x is found to be without color, it is necessary to record the starting point and the position of this point as vertex data. Then reset the starting point and end point marks, and continue traversing. When a point with color is found again, mark this point as the starting point, and then repeat the above steps until all the pixel data in this row are traversed.
[0080] It should be noted that sometimes there is only one pixel in a certain place in the image, such as the tip. We need to exclude this point because a line cannot be drawn from one point, at least two points are needed. So it cannot be used as the starting point. So when we mark a starting point and immediately find that there is no data for the next x, we reset the starting point.
[0081] The function implemented in C++ in this invention contains the vertex data obtained from this row of the image in the vector. The relevant calculation method used is as follows:
[0082] void HGeometryMath::AddPointToList(PixType pixType,int y,int width,char*data,std::vector <hpointf>&vector)
[0083] {
[0084] int startX = -1;
[0085] int endX = -1;
[0086] int dataOffset = 0;
[0087] for(int x=0;x <width;x++){
[0088] if (pixType == kRGB) {
[0089] dataOffset = y*width*3+x*3;
[0090] }else{
[0091] dataOffset = y*width*4+x*4;
[0092] }
[0093] char*currentData=data+dataOffset;
[0094] / / Determine whether this pixel is valid
[0095] bool isValid = false;
[0096] switch(pixType){
[0097] case kRGB:
[0098]
[0099]
[0100]
[0101] 4. With the methods provided above, you can get data from the picture. The relevant calculation method used is as follows:
[0102]
[0103] First, we call AddPointToList once to get the vertex information used for actual drawing and put it in topVec, and then call AddPointToList again to get the vertex information used to calculate the normal vector and put it in calNorLowerVec. Then determine whether topVec is empty. If it is not empty, it means there is vertex data in it. It is necessary to traverse topVec. In the first traversal, put a vertex into desVec, and then increase the y coordinate of this vertex by interval and continue to put it into desVec. In this way, we put the vertices of the upper left corner and lower left corner of the first rectangle into desVec, and then. Then perform a second traversal, and you can put the vertices of the upper right corner and lower right corner of the first rectangle into desVec. Then start the third traversal and the fourth traversal to calculate the vertices of the second rectangle, and so on until the traversal is completed. (The reason for storing vertices in this way here is that the vertex data stored in desVec needs to start from the 0th, and every 4 represents the four vertices of a rectangle obtained from the 2D image, which is convenient for the subsequent calculation of the information of the 6 faces of the cube)
[0104] like Figure 4 As shown, for example, the 0th one is the upper left corner, the first one is the lower left corner of the rectangle, the second one is the upper right corner of the rectangle, and the third one is the lower right corner of the rectangle.
[0105] Next, we need to determine whether the number of elements in topVec and calNorLowerVec is equal. Only when they are equal, the data in calNorLowerVec can be used to calculate the normal vector. If they are not equal, it means that the row with interval added below this row does not match the current row. We cannot use this data to calculate the side normal vector. We can only use (-1.0f, 0.0f, 0.0f) and (1.0f, 0.0f, 0.0f) to replace the normal vectors of the left and right sides of the 3D font. If they are the same, they can be used for normal vector calculation, and the calculated normal vector is put into normalVec. Here, an extra normal vector (1.0f, 0.0f, 0.0f) is placed after each loop just as a placeholder, and it will not be used in subsequent calculations. The significance of this is to make the number of elements in normalVec and desVec equal, making it convenient to calculate during subsequent traversal. The relevant calculation methods used are as follows:
[0106]
[0107] 5. Calculate the normal vector
[0108] When calculating the normal vector, such as Figure 5 As shown, since the sides of the 3D characters must be on the same plane, we only need to calculate the slope of the line connecting the two points on the side of the 3D character and the line connected to this line on a 2D plane, and then we can calculate the normal vector of the side of the 3D character. The relevant calculation method used is as follows:
[0109] glm::vec3 HGeometryMath::CalculateNormal(float x1,float y1,float x2,float y2,bool isRight)
[0110] {
[0111] if(x1==x2){
[0112] if(isRight){
[0113] return glm::vec3(1.0f,0.0f,0.0f);
[0114] }else{
[0115] return glm::vec3(-1.0f,0.0f,0.0f);
[0116] }
[0117] }else if(y1==y2){
[0118] / / Data error
[0119] return glm::vec3(0.0f,0.0f,0.0f);
[0120] }
[0121] float slope=(y1-y2) / (x1-x2);
[0122] float normalF=-1.0f / slope;
[0123] glm::vec3 normal(1.0f,1.0f*normalF,0.0f);
[0124] normal=glm::normalize(normal);
[0125] return normal;
[0126] }
[0127] Then calculate the normal vectors of the front and back faces of the 3D image. This is very simple. The normal vector of the front face must be perpendicular to the xy plane, so the normal vector must be (0,0,1). The same is true for the back face, but in the opposite direction, so the normal vector is (0,0,-1).
[0128] 2. Rendering 3D Words
[0129] The existing principle of rendering 3D characters is to render flat rectangles of the size of pixels in the y direction and stack them together to form a 3D model. Now we optimize it. Instead of just rendering flat rectangles, we render 3D cubes to splice into corresponding 3D models, just like building blocks, splicing small cubes into a complex model. This greatly reduces the number of drawings, because the original rectangle can only be 1 pixel high. If you want to stack an object with a height of 1000 pixels, you need 1000 rectangles, but our cube can be greater than 1. For example, if it is 5, then you only need 200 cubes to stack an object with a height of 1000 pixels.
[0130] 1. In the above steps, we have obtained the vertex information and normal vectors, and determined the interval according to the pixel size of the image. Next, we only need to calculate the vertices, texture coordinates and normal vectors required for rendering the six faces of each small square based on this information. Then we can render the small squares one by one, and then superimpose them one by one to form the 3D text model we want.
[0131] 2. First, you need to form a rectangle based on every 4 data in desVec (such as Figure 6 Then by adding thickness, or z-coordinate, to the rectangle, it becomes a cube.
[0132] However, desVec only has vertex position information, not texture coordinates, so we need to calculate the texture coordinates. Since we usually use a picture as the texture of 3D text, the texture coordinates are easy to calculate. We only need to convert the x and y coordinates of the 2D point in the original picture into 0.0 to 1.0, which is the texture coordinate (texture coordinates are all 0.0 to 1.0). At the same time, we need to convert the vertex data in the range of 0 to pixel width and height into data in the range of -1.0 to 1.0, which is convenient for subsequent calculations. The specific calculation method is as follows:
[0133] for(int i=0; i <desVec.size();i=i+4)
[0134] {
[0135] if(i+4>desVec.size()){
[0136] break;
[0137] }
[0138] float x0=desVec.at(i+0).x()*2.0f-(float)width;
[0139] float y0=desVec.at(i+0).y()*2.0f-(float)height;
[0140] float u0=desVec.at(i+0).x() / (float)width;
[0141] float v0=desVec.at(i+0).y() / (float)height;
[0142] float x1=desVec.at(i+1).x()*2.0f-(float)width;
[0143] float y1=desVec.at(i+1).y()*2.0f-(float)height;
[0144] float u1=desVec.at(i+1).x() / (float)width;
[0145]
[0146] Then, according to the set thickness of the 3D font, the texture offset of the four vertices in front and the four vertices in the back of the cube is calculated (such as Figure 7 The greater the thickness, the greater the difference between the front and back, and the greater the difference in texture coordinates.
[0147] float texOffsetZ = (float)thick / (float)width; / / offset texture x in z direction.
[0148] The index information here is because we use the glDrawIndex function of OpenGL to draw the aggregate, so the index information is needed. Looking through the official OpenGL documentation, we can know that when using the triangle list to draw, it takes 6 indexes to draw a face of a cube, that is, a rectangle. Here, how to get the index list from the 4 vertices of the rectangle is not described in detail.
[0149] The following code shows how to use four vertices to generate vertex information in a loop.
[0150] unsigned inti_0 = 0;
[0151] unsigned inti_1 = 1;
[0152] unsigned inti_2 = 2;
[0153] unsigned inti_3 = 3;
[0154] for(int i = 0; i <desVec.size();i=i+4)。
[0155] 1. Find the four vertices in front of the small cube:
[0156]
[0157]
[0158] 2. Find the four vertices behind the small cube:
[0159]
[0160]
[0161]
[0162] 3. Find the four vertex information on the small cube:
[0163]
[0164] 4. Find the following four vertex information of the small cube:
[0165]
[0166]
[0167] 5. Find the four vertices on the right side of the small cube:
[0168]
[0169]
[0170] 6. Find the four vertices on the left side of the small cube:
[0171]
[0172]
[0173] At this point, all the data used to render the 3D text is stored in vertexInfo.indexVec and vertexInfo.posNormalTexVec. Now you only need to call the corresponding drawing API to draw these vertices to draw the 3D text (such as Figure 8 shown).
[0174] 3. Use normal vectors to improve rendering effects:
[0175] Now that we have the normal vector, we can optimize the 3D display effect. Because the z coordinates of the normal vectors on the front and back sides must be 1.0 or -1.0, and the z coordinates of the normal vectors on the side must be 0, we can design an algorithm. We add the absolute value of the z coordinate of the normal vector to 1.0 and divide it by 2.0 to get a color ratio, and then multiply the calculated color by this color ratio. Then the color of the side must be twice as dark as the color of the front and back sides, which further highlights the 3D depth of the 3D text (such as Fig. 9 shown).
[0176] float rate=(abs(NormalCord.z)+1.0) / 2.0;
[0177] resultColor*=rate.
[0178] The beneficial effects of the 3D character rendering method of the present invention are:
[0179] The present invention obtains vertex information in a 2D image through the above technical solution; obtains data information required for calculating a normal vector based on the vertex information; calculates a normal vector based on the data information required for calculating the normal vector; renders 3D characters based on the vertex information and the calculated normal vector; and optimizes the display effect of the rendered 3D characters, thereby improving the rendering effect of the 3D characters and more clearly reflecting the contour of the 3D characters.
[0180] To achieve the above object, the present invention also provides a 3D character rendering system, such as Fig.10 As shown, the system includes a processor 1001, a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002, and a 3D word rendering program stored on the processor, wherein the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001. When the processor 1001 is called, the steps of the 3D word rendering method described in the above embodiment are performed, which will not be repeated here.
[0181] Those skilled in the art will understand that Fig.10 The system structure shown in the figure does not constitute a limitation of the system, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0182] like Fig.10 As shown, the memory 1005 as a computer storage medium may include an operating device, a network communication module, a user interface module and a 3D character rendering program.
[0183] exist Fig.10 In the system shown, the network interface 1004 is mainly used to connect to the network server and communicate data with the network server; the user interface 1003 is mainly used to interact with the user terminal and receive instructions input by the user; and the processor 1001 can be used to call the 3D character rendering program stored in the memory 1005.
[0184] To achieve the above objective, the present invention further proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a 3D word rendering program, and when the 3D word rendering program is executed by a processor, the steps of the method described above are executed, which will not be described in detail here.
[0185] The above description is only a preferred embodiment of the present invention, and does not limit the patent scope of the present invention. All equivalent structural changes made by using the contents of the present invention specification and drawings under the concept of the present invention, or directly / indirectly applied in other related technical fields are included in the patent protection scope of the present invention.< / hpointf>
Claims
1. A 3D character rendering method, characterized in that: The method comprises the following steps: Step S100, obtaining vertex information in a 2D image; Step S200, obtaining data information required for calculating a normal vector according to the vertex information; Step S300, calculating a normal vector according to the data information required for calculating the normal vector; Step S400, rendering 3D characters according to the vertex information and the calculated normal vector; Step S500, optimizing the display effect of the rendered 3D characters.
2. The 3D character rendering method according to claim 1, characterized in that: The step S100 includes: Step S110 , traverse each pixel point of the 2D image according to the pixel width and height of the 2D image, and record the colored pixel points therein as vertex data.
3. The 3D character rendering method according to claim 2, characterized in that: The step S110 includes: Step S111 , traverse the pixel points on each row along the X direction row by row according to a preset step distance in the Y direction, and record the colored pixel points therein as vertex data.
4. The 3D character rendering method according to claim 3, characterized in that: The step S111 comprises: Step S112, when traversing in the X direction, first start traversing from 0, when a point with color is found, mark this point as the starting point, and then continue traversing; every time it is found that the next pixel point is without color, it is necessary to record the starting point and the position of this point as vertex data; then reset the starting point and end point marks, and then traverse downwards, when a point with color is found again, mark this point as the starting point, and then repeat the above steps until all the pixel data in this row are traversed.
5. The 3D character rendering method according to claim 4, characterized in that: The step S200 includes: Step S210, calling AddPointToList for the first time to obtain vertex information for drawing and put it into topVec; Step S220, call AddPointToList again to obtain vertex information used to calculate the normal vector, and put it into calNorLowerVec; Step S230, traverse topVec for the first time, put a vertex into desVec, then increase the Y coordinate of the vertex by a step distance to obtain two vertices of the first rectangle, and then traverse for the second time, and so on to obtain the other two vertices of the first rectangle, and then traverse again until all the vertex information in topVec is traversed; Step S240, determining whether the number of elements in topVec and calNorLowerVec is equal, if they are equal, executing step S300; If the number of elements in topVec and calNorLowerVec is not equal, the normal vectors of the left and right faces of the 3D font are replaced by (-1.0f, 0.0f, 0.0f) and (1.0f, 0.0f, 0.0f).
6. The 3D character rendering method according to claim 5, characterized in that: The step S300 includes: obtaining a line connecting two points on the side of the 3D character, and a slope of a line on a 2D plane connected to the line, and calculating a normal vector of the side of the 3D character, and normal vectors of the front and back of the 3D character.
7. The 3D character rendering method according to claim 6, characterized in that: The step S400 includes: rendering 3D cubes according to the vertex information of all rectangles and the calculated normal vectors to splice into the corresponding 3D model; wherein, a rectangle is formed according to every four vertex information in desVec, and then the thickness of the rectangle is increased, that is, the Z coordinate is increased to form a cube.
8. The 3D character rendering method according to claim 7, characterized in that: The step S500 includes: The front, back and sides of the 3D characters are rendered differently based on the normal vector information. For the sides of the 3D characters, a color ratio is obtained by adding the absolute value of the Z coordinate of the normal vector to 1.0 and then dividing by 2.
0. The calculated color is then multiplied by the color ratio.
9. A 3D character rendering system, characterized in that: The system comprises a memory, a processor and a 3D word rendering program stored on the processor, and the 3D word rendering program executes the steps of the method according to any one of claims 1 to 8 when executed by the processor.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a 3D word rendering program, and when the 3D word rendering program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are performed.