Model normal processing method, device, storage medium and electronic device
By calculating and managing the normals of vertices in the model and judging whether to calculate the average normal based on the included angle threshold, the problem that the existing technology cannot achieve the model smoothness and edge-angle effects at the same time is solved, ensuring the lighting effect of the model.
Patent Information
- Application Number
- CN202011305688.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-20
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2040-11-20
AI Technical Summary
The existing model normal processing method cannot meet the parts that need to show smooth and angular effects on the model surface, and will also cause the lighting effect of the model to be distorted.
By determining at least two normals corresponding to the same vertex in the model, the angle between each two normals is calculated. When the angle is less than the set threshold, the average normal is calculated and used as the normal of the vertex to achieve a smooth effect; when the angle is greater than the threshold, multiple normals are maintained to present an edge-angle effect.
It realizes that the model surface can not only show a smooth effect, but also an edge-angle effect, thus keeping the model's lighting effect undistorted.
Smart Images

Figure CN114519762B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a model normal processing method, device, storage medium and electronic device. Background Art
[0002] When reading the model based on the operating system, since the model surface is composed of multiple planes, each vertex of each plane corresponds to a normal. When multiple planes share a vertex, the vertex corresponds to multiple normals. The average normal corresponding to the multiple normals is calculated, and the average normal is used as the normal of the vertex, so that the model surface presents a smooth effect, but it cannot meet the needs of the parts of the model that need to present an angular effect, and the lighting effect of the model will also be distorted. When the multiple normals of the vertex are maintained, the model will present an angular effect, but it cannot meet the needs of the parts of the model that need a smooth effect. Therefore, the above model normal processing method cannot simultaneously meet the needs of the parts of the model that need to present a smooth effect and the parts that need to present an angular effect, and will also distort the lighting effect of the model. Summary of the invention
[0003] The embodiments of the present application provide a model normal processing method, device, storage medium and electronic device, which can make the model surface present both a smooth effect and an angular effect, thereby making the lighting effect of the model undistorted. The technical solution is as follows:
[0004] In a first aspect, an embodiment of the present application provides a model normal processing method, the method comprising:
[0005] Determine at least two normals corresponding to the same vertex in the model;
[0006] Calculating the angle between each two normal lines of the at least two normal lines;
[0007] When there is a target angle among the angles that is smaller than the angle threshold, an average normal is calculated based on the normal corresponding to the target angle, and the average normal is used as the normal of the vertex.
[0008] In a second aspect, an embodiment of the present application provides a model normal processing device, the device comprising:
[0009] A normal determination module, used to determine at least two normals corresponding to the same vertex in the model;
[0010] An angle calculation module, used to calculate the angle between each two normal lines of the at least two normal lines;
[0011] The average normal module is used to calculate the average normal based on the normal corresponding to the target angle when there is a target angle less than the angle threshold among the angles, and use the average normal as the normal of the vertex.
[0012] In a third aspect, an embodiment of the present application provides a computer storage medium, wherein the computer storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the above-mentioned method steps.
[0013] In a fourth aspect, an embodiment of the present application provides an electronic device, which may include: a processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the above-mentioned method steps.
[0014] The beneficial effects brought about by the technical solutions provided by some embodiments of the present application include at least:
[0015] In one or more embodiments of the present application, at least two normals corresponding to the same vertex in the model are first determined, and then the angle between each two normals of the at least two normals is calculated. When there is a target angle less than an angle threshold among the angles, an average normal is calculated based on the normals corresponding to the target angle, and the average normal is used as the normal of the vertex. The angle threshold can be set to determine whether to use the average normal as the normal of the vertex, so that the model surface can present both a smooth effect and an angular effect, thereby preventing the lighting effect of the model from being distorted. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present application 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 application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 It is a flow chart of a model normal processing method provided in an embodiment of the present application;
[0018] Figure 2a is an example schematic diagram of a model surface provided in an embodiment of the present application;
[0019] Figure 2b is an example schematic diagram of angle calculation provided in an embodiment of the present application;
[0020] Figure 2c is another example schematic diagram of angle calculation provided in an embodiment of the present application;
[0021] Figure 3 It is a flowchart of another model normal processing method provided in an embodiment of the present application;
[0022] Figure 4is a structural schematic diagram of a model normal processing device provided in an embodiment of the present application;
[0023] Figure 5 is a structural schematic diagram of another model normal processing device provided in an embodiment of the present application;
[0024] Figure 6 It is a structural diagram of an index value generation module provided in an embodiment of the present application;
[0025] Figure 7 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0027] In the description of the present application, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In the description of the present application, it should be noted that, unless otherwise clearly specified and limited, "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood in specific circumstances. In addition, in the description of the present application, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B, which can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects before and after are an "or" relationship.
[0028] There are multiple planes on the model surface that share a vertex, so one vertex corresponds to multiple normals. By judging the planes that share the vertex in turn, when the plane that shares the vertex needs to present a smooth effect, the average normal between the multiple normals corresponding to the shared vertex is calculated, and the average normal is used as the normal of the shared vertex. When the plane that shares the vertex needs to present an angular effect, while making the lighting effect of the model not distorted, the multiple normals of the shared vertex are maintained. This process requires the model reader to judge every two connected faces. When the number of planes is large, the workload is very large. Therefore, according to some embodiments, an angle threshold is set to judge whether the connected planes in the model need a smooth effect or an angular effect, thereby judging whether to use the average normal as the normal of the vertex.
[0029] The present application is described in detail below with reference to specific embodiments.
[0030] In one embodiment, Figure 1 As shown, a model normal processing method is proposed, which can be implemented by a computer program and can be run on a model normal processing device based on the von Neumann system. The computer program can be integrated into an application or run as an independent tool application.
[0031] Specifically, the model normal processing method includes:
[0032] S101: Determine at least two normal lines corresponding to the same vertex in the model.
[0033] The model refers to a model with three-dimensional data constructed by three-dimensional production software through virtual three-dimensional space, which can be read by an operating system (OS). Among them, the operating system refers to a computer program that manages computer hardware and software resources, including but not limited to the following systems: Android system (Android system), Microsoft Windows operating system (Windows system), Apple computer operating system (mac system), Linux system and Apple mobile device operating system (iPhone Operating System, iOS), etc.
[0034] The surface of the model is composed of multiple planes, one plane includes at least three vertices, and one vertex on a plane corresponds to one normal. When multiple planes share a vertex, the vertex corresponds to at least two normals. When reading the model, the normal corresponding to the vertex is determined by reading the normal vector corresponding to the vertex. Among them, the normal vector refers to a quantity including the size and direction of the normal, which can be represented in the form of vn (a, b, c). It should be noted that the plane can be the smallest unit of the model surface, including but not limited to triangular faces and quadrilateral faces. When the plane is a triangular face, each plane includes three vertices; when the plane is a quadrilateral, each plane includes four vertices. Figure 2a As shown, a schematic diagram of an example of a model surface is shown, taking a spherical model as an example, wherein the model surface is composed of minimum unit triangular faces.
[0035] Specifically, the method for determining at least two normals corresponding to the same vertex in the model includes but is not limited to the following methods: sequentially read the normal vector of each vertex in each plane in the model, and when the vertices have the same vertex coordinates but different normal vectors, extract the different normal vectors in the vertex, thereby determining at least two normals corresponding to the same vertex in the model. The vertex coordinates refer to the coordinates of the vertex in the model in three-dimensional space, which can be expressed in the form of v (x, y, z), and each vertex has a unique vertex coordinate corresponding to it.
[0036] S102: Calculate the angle between every two normal lines of the at least two normal lines.
[0037] Specifically, based on the normal vector, the angle between two normals is calculated. While determining at least two normals corresponding to the same vertex, the normal vector corresponding to each normal is determined, wherein the process of calculating the angle between each two normals is as follows: first, the inner product of the normal vectors corresponding to the two normals is calculated, and then the value obtained by the inner product calculation is divided by the modulus of the two normal vectors, and finally the cosine value of the angle is obtained. The angle can be obtained by the cosine value of the angle. For example, taking the normal vector vn1 (a1, b1, c1) of the first normal and the normal vector vn2 (a2, b2, c2) of the second normal as examples, the formula for calculating the cosine value of the angle is as follows:
[0038]
[0039] Thus we can get:
[0040]
[0041] Wherein, θ is the angle between the two normal lines, and the angle θ can be calculated accordingly.
[0042] It should be noted that each two normal lines may be selected from the at least two normal lines according to a preset rule, so as to calculate the angle between each two normal lines selected.
[0043] The default rule is to select in the order in which the normals are read, such as Figure 2b As shown, an example schematic diagram of angle calculation is taken as an example, the normals corresponding to the same vertex include normal 1, normal 2, normal 3 and normal 4. In the second step of reading, it is read that normal 2 and normal 1 are the same vertex, then the angle between normal 1 and normal 2 is calculated to obtain angle 12. In the third step of reading, it is read that normal 3 is the same vertex as normal 2 and normal 1, then the angle between normal 1 and normal 3 is calculated to obtain angle 13; the angle between normal 2 and normal 3 is calculated to obtain angle 23.
[0044] Optionally, the default rule is to select every two normals after determining all normals of the same vertex. Figure 2b As shown, an example schematic diagram of angle calculation is taken as an example that the normals corresponding to the same vertex include normal 1, normal 2, normal 3 and normal 4. After determining all normals corresponding to the same vertex, that is, normal 1, normal 2, normal 3 and normal 4, the angle 12 between normal 1 and normal 2, the angle 13 between normal 1 and normal 3, and the angle 23 between normal 2 and normal 3 are calculated at the same time.
[0045] S103: When there is a target angle among the angles that is smaller than the angle threshold, an average normal is calculated based on normals corresponding to the target angle, and the average normal is used as the normal of the vertex.
[0046] The angle threshold is a criterion for determining whether to use the average normal as the vertex. When the angle is less than the angle threshold, the average normal is used as the normal of the vertex, so that the vertex presents a smooth effect on the model surface. When the angle is greater than the angle threshold, the at least two normals corresponding to the vertex are maintained, so that the vertex presents an angular effect on the model surface. Among them, the target angle is the angle less than the angle threshold among the angles.
[0047] Optionally, the angle threshold may be set by the model reader or by the operating system according to model display requirements. Different angle thresholds may be set to make the model present different effects.
[0048] The average normal is calculated based on the normal corresponding to the target angle. Specifically, the calculation process of the average normal may be:
[0049] The normal vectors corresponding to the target normal are added to obtain an added vector, and the added vector is normalized to obtain an average normal.
[0050] Taking the normal vector vn1 (a1, b1, c1) of the first normal and the normal vector vn2 (a2, b2, c2) of the second normal as an example, the average normal vn 12 (a 12 , b 12 , c 12 ) is calculated as:
[0051]
[0052]
[0053]
[0054] Specifically, when the target angle includes one, the average normal of the two normals corresponding to the target angle is calculated, and the average normal is used as the normal of the vertex. For example, when the two normals corresponding to the target angle are vn1 (a1, b1, c1) and vn2 (a2, b2, c2), the average normal vn 12 (a 12 , b 12 , c 12 ) as the normal of the vertex.
[0055] When the target angles include at least two, the first average normals of the two normals corresponding to each target angle are calculated respectively, the average normal of each of the first average normals is calculated, and the average normal is used as the normal of the vertex.
[0056] For example, taking two target angles as an example, the two normals corresponding to one target angle are vn1 (a1, b1, c1) and vn2 (a2, b2, c2). According to the average normal calculation formula, the first average normal is vn 12 (a 12 , b 12 , c 12 ); The two normals corresponding to the other target angle are vn3 (a3, b3, c3) and vn4 (a4, b4, c4). According to the average normal calculation formula, the first average normal is vn 34 (a 34 , b 34 , c 34 ). Then calculate the first average normal vn 12 and the first mean normal vn 34 The average normal of is obtained as vn, and vn is used as the normal of the vertex, where the calculation formula of vn (a, b, c) is as follows:
[0057]
[0058]
[0059]
[0060] It should be noted that in the lighting effect of the model, the direction of the normal vector is used as the orientation of the model surface to the space, that is, the direction of the model surface relative to the light source. When the average normal is used as the normal of the vertex, the direction of the model surface relative to the light source becomes the direction of the average normal, rather than the multiple directions corresponding to the multiple normals, which will cause the model's lighting effect to be distorted. When the angle is greater than the angle threshold, the at least two normals corresponding to the vertex are maintained, and the direction of the model surface relative to the light source is also maintained as the direction of the at least two normals, so that the model's lighting effect is not distorted.
[0061] In the embodiment of the present application, at least two normals corresponding to the same vertex in the model are first determined, and then the angle between each two normals of the at least two normals is calculated. When there is a target angle less than the angle threshold among the angles, an average normal is calculated based on the normals corresponding to the target angle, and the average normal is used as the normal of the vertex. The angle threshold can be set to determine whether to use the average normal as the normal of the vertex, so that the model surface can present both a smooth effect and an angular effect, thereby making the lighting effect of the model undistorted.
[0062] See also Figure 3 , Figure 3 This is a flow chart of another embodiment of a model normal processing method proposed in this application. Specifically:
[0063] S201: Read a model file corresponding to the model, and obtain vertex data in the model file, where the vertex data at least includes vertex coordinates of each vertex and a normal vector of each vertex.
[0064] The model file refers to a file containing vertex data in the model, and the model can be read by reading the model file. The model file includes but is not limited to the following: obj file, 3ds file and max file.
[0065] The vertex data refers to the relevant data set for the vertices in the model, which is used to present the model and the model effect, including vertex coordinates and normal vectors.
[0066] Optionally, the vertex data further includes texture coordinates of each vertex, wherein texture coordinates refer to a two-dimensional array that maps texture pixels to vertex coordinates, wherein each texture pixel has a unique corresponding address in the texture, which can be expressed as vt(u, v).
[0067] Specifically, the vertex data in the model file may be read by byte, by character, by line, or randomly.
[0068] S202: Save the vertex coordinates of each vertex into a first set, and save the normal vector of each vertex into a second set.
[0069] Specifically, the vertex data (vertex coordinates and normal vectors) in the model can be freely combined to obtain the vertex coordinates and normal vectors corresponding to each vertex. Before the vertex coordinates and normal vectors are freely combined, the vertex coordinates of each vertex are saved in a first set, and the normal vectors of each vertex are saved in a second set.
[0070] Optionally, when the vertex data includes texture coordinates, the texture coordinates of each vertex are saved in a third set, so that the vertex coordinates, normal vector and texture coordinates can be freely combined to obtain the vertex coordinates, normal vector and texture coordinates corresponding to each vertex.
[0071] S203: Acquire a set of plane data of the model, each of the plane data comprising a vertex index on the plane, a texture index of the vertex index on the plane, and a normal index corresponding to the vertex index on the plane.
[0072] The plane data set refers to the set of each plane data in the model, including all plane data in the model. The plane data refers to the vertex index of the vertex coordinates of each vertex in the plane, the texture index of the texture coordinates and the normal index of the normal vector.
[0073] Specifically, the process of obtaining the plane data set of the model is: obtaining vertex coordinates in a first set, normal vectors in a second set, and texture coordinates in a third set.
[0074] For example, the vertex indices corresponding to the first set and vertex coordinates are [1(x1, y1, z1), 2(x2, y2, z2), 3(x3, y3, z3)], where "1" is the index of the vertex coordinate (x1, y1, z1), "2" is the index of the vertex coordinate (x2, y2, z2), and "3" is the index of the vertex coordinate (x3, y3, z3). The normal indices corresponding to the second set and normal vectors are [1(a1, b1, c1), 2(a2, b2, c2), 3(a3, b3, c3)], where "1" is the index of the normal vector (a1, b1, c1), "2" is the index of the normal vector (a2, b2, c2), and "3" is the index of the normal vector (a3, b3, c3). The texture index corresponding to the third set and texture coordinates is [1 (u1, v1), 2 (u2, v2), 3 (u3, v3)], where "1" is the index of texture coordinate (u1, v1), "2" is the index of texture coordinate (u2, v2), and "3" is the index of texture coordinate (u3, v3). When a plane includes three vertices, and the vertex coordinates of the first vertex are (x1, y1, z1), texture coordinates (u1, v1), and normal vector (a2, b2, c2), the vertex coordinates of the second vertex are (x3, y3, z3), texture coordinates (u1, v1), and normal vector (a2, b2, c2), and the vertex coordinates of the second vertex are (x2, y2, z2), texture coordinates (u2, v2), and normal vector (a1, b1, c1), the plane data is (1 / 1 / 2, 3 / 1 / 2, 2 / 2 / 1).
[0075] S204: Generate an index value corresponding to the plane data based on the first set, the second set, and the third set.
[0076] Specifically, the vertex coordinates corresponding to the vertex index are searched in the first set, the texture coordinates corresponding to the texture index are searched in the second set, and the normal vector corresponding to the normal index is searched in the third set, and an index value including the vertex coordinates, the texture coordinates and the normal vector is generated.
[0077] For example, if the plane data is (1 / 1 / 2, 3 / 1 / 2, 2 / 2 / 1), the index value f1 corresponding to the plane data is [(x1, y1, z1, u1, v1, u2, v2), (x3, y3, z3, u1, v1, u2, v2), (x2, y1, z2, u2, v2, u1, v1)]
[0078] Optionally, identical plane data in the plane data set is deleted.
[0079] In order to avoid data duplication, when vertex data with the same vertex coordinates, texture coordinates and normal vectors are obtained, the vertex data is deleted and only one of the same vertex data is retained, thereby avoiding repeated calculation of the normal vector.
[0080] S205: Determine at least two index values with the same vertex coordinates, and determine a normal vector in the at least two index values.
[0081] When the vertex coordinates in the index values are the same but the normal vectors are different, please refer to S101 for details, which will not be described again here.
[0082] Optionally, when the vertex data includes texture coordinates, the vertex coordinates in the index value are the same, but the texture coordinates or normal vectors are different, and the different normal vectors are determined based on the texture coordinates and the normal vectors. The index values corresponding to the plane data with different normal vectors are finally determined based on the index values.
[0083] S206: Calculate the angle between every two normal lines of the at least two normal lines.
[0084] For details, please refer to S102, which will not be repeated here.
[0085] S207: When there is a target angle among the angles that is smaller than the angle threshold, an average normal is calculated based on normals corresponding to the target angle, and the average normal is used as the normal of the vertex.
[0086] For details, please refer to S103, which will not be repeated here.
[0087] Optionally, when the target angles include at least two, determine the normal corresponding to each target angle, and calculate the average normal corresponding to at least three of the normals. For example, taking the existence of two target angles as an example, the two normals corresponding to one target angle are vn1 (a1, b1, c1) and vn2 (a2, b2, c2), and the two normals corresponding to the other target angle are vn3 (a3, b3, c3) and vn4 (a4, b4, c4). Then, the average normal corresponding to vn1, vn2, vn3 and vn4 is calculated as vn, and vn is used as the normal of the vertex, wherein the calculation formula of vn (a, b, c) is as follows:
[0088]
[0089]
[0090]
[0091] Optionally, after taking the average normal as the normal of the vertex, the index value of the normal vector is determined in the second set based on the normal vector of the average normal, and the index value of the normal vector in the plane data of the plane where the vertex is located is updated to the index value of the normal vector of the average normal, and the updated plane data is saved in the plane data set.
[0092] In the embodiment of the present application, the angle threshold can be set to determine whether to use the average normal as the normal of the vertex, so that the model surface can present both a smooth effect and an angular effect, thereby making the lighting effect of the model undistorted. In addition, the read vertex coordinates are saved to the first set, and the normal vector is saved to the second set. At least two normals corresponding to the same vertex are determined by reading the plane data index value in the plane data set, so that the determination process is organized and no data is missed. Furthermore, the same plane data is deleted to avoid invalid repeated calculation of the angle.
[0093] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0094] See also Figure 4 , which shows a schematic diagram of the structure of a model normal processing device provided by an exemplary embodiment of the present application. The model normal processing device can be implemented as all or part of the device through software, hardware or a combination of both. The device 1 includes a normal determination module 11, an angle calculation module 12 and an average normal module 13.
[0095] A normal determination module 11, used to determine at least two normals corresponding to the same vertex in the model;
[0096] An angle calculation module 12, used to calculate the angle between each two normal lines of the at least two normal lines;
[0097] The average normal module 13 is used to calculate the average normal based on the normal corresponding to the target angle when there is a target angle less than the angle threshold among the angles, and use the average normal as the normal of the vertex.
[0098] Optional, such as Figure 5 As shown, the device 1 further includes:
[0099] A data reading module 14 is used to read a model file corresponding to the model and obtain vertex data in the model file, wherein the vertex data at least includes vertex coordinates of each vertex and a normal vector of each vertex;
[0100] The data storage module 15 is used to store the vertex coordinates of each vertex in the first set, and store the normal vector of each vertex in the second set.
[0101] Optionally, the vertex data also includes texture coordinates of each vertex, and the data storage module 15 is further used for:
[0102] The texture coordinates of each of the vertices are saved in a third set.
[0103] Optionally, the device 1 further includes:
[0104] A set acquisition module 16 is used to acquire a set of plane data of the model, each of which includes a vertex index on the plane, a texture index of the vertex index on the plane, and a normal index corresponding to the vertex index on the plane;
[0105] The index value generating module 17 is used to generate an index value corresponding to the plane data based on the first set, the second set and the third set.
[0106] Optionally, the device 1 further includes:
[0107] A data deletion module 18, used for deleting the same plane data in the plane data set;
[0108] Optional, such as Figure 6 As shown, the index value generating module 17 further includes:
[0109] A vertex coordinate search unit 171, configured to search the first set for the vertex coordinate corresponding to the vertex index;
[0110] A texture coordinate search unit 172, configured to search the second set for the texture coordinate corresponding to the texture index;
[0111] A normal vector search unit 173, configured to search the third set for a normal vector corresponding to the normal index;
[0112] The index value generating unit 174 is used to generate an index value including the vertex coordinates, the texture coordinates and the normal vector.
[0113] Optionally, the normal determination module 11 is further used for:
[0114] At least two index values having the same vertex coordinates are determined, and a normal vector in the at least two index values is determined.
[0115] Optionally, the average normal module 13 is further used for:
[0116] When the target angle includes one, calculating the average normal of two normals corresponding to the target angle;
[0117] When the target angles include at least two, the first average normals of the two normals corresponding to each target angle are calculated respectively, and the average normal of the first average normals is calculated.
[0118] It should be noted that the model normal processing device provided in the above embodiment only uses the division of the above functional modules as an example when executing the model normal processing method. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the model normal processing device provided in the above embodiment and the model normal processing method embodiment belong to the same concept, and the implementation process thereof is detailed in the method embodiment, which will not be repeated here.
[0119] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0120] In this embodiment, at least two normals corresponding to the same vertex in the model are first determined, and then the angle between each two normals of the at least two normals is calculated. When there is a target angle less than the angle threshold among the angles, an average normal is calculated based on the normals corresponding to the target angle, and the average normal is used as the normal of the vertex. The angle threshold can be set to determine whether to use the average normal as the normal of the vertex, so that the model surface can present both a smooth effect and an angular effect, thereby preventing the lighting effect of the model from being distorted.
[0121] The present application also provides a computer storage medium, which can store multiple instructions, and the instructions are suitable for being loaded and executed by a processor as described above. Figure 1-Figure 3 The model normal processing method of the embodiment shown in the figure can be specifically implemented by referring to Figure 1-Figure 3 The specific description of the illustrated embodiment will not be repeated here.
[0122] The present application also provides a computer program product, which stores at least one instruction, and the at least one instruction is loaded and executed by the processor as described above. Figure 1-Figure 3 The model normal processing method of the embodiment shown in the figure can be specifically implemented by referring to Figure 1-Figure 3 The specific description of the illustrated embodiment will not be repeated here.
[0123] See also Figure 7 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 7As shown, the electronic device 1000 may include: at least one processor 1001 , at least one network interface 1004 , a user interface 1003 , a memory 1005 , and at least one communication bus 1002 .
[0124] The communication bus 1002 is used to realize the connection and communication between these components.
[0125] The user interface 1003 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 1003 may also include a standard wired interface and a wireless interface.
[0126] The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0127] Among them, the processor 1001 may include one or more processing cores. The processor 1001 uses various interfaces and lines to connect various parts of the entire server 1000, and executes various functions and processes data of the server 1000 by running or executing instructions, programs, code sets or instruction sets stored in the memory 1005, and calling data stored in the memory 1005. Optionally, the processor 1001 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 1001 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communication. It can be understood that the above-mentioned modem may not be integrated into the processor 1001, and it can be implemented separately through a chip.
[0128] Among them, the memory 1005 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory). Optionally, the memory 1005 includes a non-transitory computer-readable storage medium. The memory 1005 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 1005 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 1005 may also be optionally at least one storage device located away from the aforementioned processor 1001. As Figure 7 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a model normal processing application.
[0129] exist Figure 7 In the electronic device 1000 shown, the user interface 1003 is mainly used to provide an input interface for the user and obtain the data input by the user; and the processor 1001 can be used to call the model normal processing application stored in the memory 1005, and specifically perform the following operations:
[0130] Determine at least two normals corresponding to the same vertex in the model;
[0131] Calculating the angle between each two normal lines of the at least two normal lines;
[0132] When there is a target angle among the angles that is smaller than the angle threshold, an average normal is calculated based on the normal corresponding to the target angle, and the average normal is used as the normal of the vertex.
[0133] In one embodiment, before executing the step of determining at least two normals corresponding to the same vertex in the model, the processor 1001 further performs the following operations:
[0134] Reading a model file corresponding to the model, and obtaining vertex data in the model file, wherein the vertex data at least includes vertex coordinates of each vertex and a normal vector of each vertex;
[0135] The vertex coordinates of each vertex are saved in a first set, and the normal vectors of each vertex are saved in a second set.
[0136] In one embodiment, when the processor 1001 executes the steps of saving the vertex coordinates of each vertex into the first set and saving the normal vector of each vertex into the second set, the vertex data also includes the texture coordinates of each vertex, and further performs the following operations:
[0137] The texture coordinates of each of the vertices are saved in a third set.
[0138] In one embodiment, the processor 1001 further performs the following operations:
[0139] Acquire a set of plane data of the model, each of the plane data comprising a vertex index on the plane, a texture index of the vertex index on the plane, and a normal index corresponding to the vertex index on the plane;
[0140] Based on the first set, the second set, and the third set, an index value corresponding to the plane data is generated.
[0141] In one embodiment, the processor 1001 further performs the following operations:
[0142] Delete the same plane data in the plane data set.
[0143] In an embodiment, when the processor 1001 generates the index value corresponding to the plane data based on the first set, the second set, and the third set, the processor 1001 specifically performs the following operations:
[0144] Searching the first set for vertex coordinates corresponding to the vertex index;
[0145] Searching for the texture coordinates corresponding to the texture index in the second set;
[0146] Searching the third set for a normal vector corresponding to the normal index;
[0147] An index value including the vertex coordinates, the texture coordinates, and the normal vector is generated.
[0148] In one embodiment, the processor 1001 performs the following operations when determining at least two normals corresponding to the same vertex in the model:
[0149] At least two index values having the same vertex coordinates are determined, and a normal vector in the at least two index values is determined.
[0150] In one embodiment, the processor 1001 performs the following operations when determining at least two normals corresponding to the same vertex in the model:
[0151] When the target angle includes one, calculating the average normal of two normals corresponding to the target angle;
[0152] When the target angles include at least two, the first average normals of the two normals corresponding to each target angle are calculated respectively, and the average normal of the first average normals is calculated.
[0153] In one embodiment, the processor 1001 performs the following operations when calculating the average normal between every two target normals:
[0154] Add the normal vectors corresponding to the target normal to obtain the average normal
[0155] In this embodiment, at least two normals corresponding to the same vertex in the model are first determined, and then the angle between each two normals of the at least two normals is calculated. When there is a target angle less than the angle threshold among the angles, an average normal is calculated based on the normals corresponding to the target angle, and the average normal is used as the normal of the vertex. The angle threshold can be set to determine whether to use the average normal as the normal of the vertex, so that the model surface can present both a smooth effect and an angular effect, thereby preventing the lighting effect of the model from being distorted.
[0156] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0157] The above disclosure is only the preferred embodiment of the present application, which certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A model normal processing method, characterized in that: The method comprises: Determine at least two normals corresponding to the same vertex in the model; Calculating the angle between each two normal lines of the at least two normal lines; When there is a target angle among the angles that is less than the angle threshold, an average normal is calculated based on the normal corresponding to the target angle, and the average normal is used as the normal of the vertex; The calculating the average normal based on the normal corresponding to the target angle includes: When the target angles include at least two, first average normals of two normals corresponding to each target angle are calculated respectively, and an average normal of each of the first average normals is calculated; When the target angle includes one, the average normal of the two normals corresponding to the target angle is calculated.
2. The method according to claim 1, characterized in that Before determining at least two normal lines corresponding to the same vertex in the model, the method further includes: Reading a model file corresponding to the model, and obtaining vertex data in the model file, wherein the vertex data at least includes vertex coordinates of each vertex and a normal vector of each vertex; The vertex coordinates of each vertex are saved in a first set, and the normal vectors of each vertex are saved in a second set.
3. The method according to claim 2, characterized in that The vertex data also includes texture coordinates of each vertex, and the method further includes: The texture coordinates of each of the vertices are saved in a third set.
4. The method according to claim 3, characterized in that The method further comprises: Acquire a set of plane data of the model, each of the plane data comprising a vertex index on the plane, a texture index of the vertex index on the plane, and a normal index corresponding to the vertex index on the plane; Based on the first set, the second set, and the third set, an index value corresponding to the plane data is generated.
5. The method according to claim 4, characterized in that The method further comprises: Delete the same plane data in the plane data set.
6. The method according to claim 4, characterized in that The generating, based on the first set, the second set, and the third set, an index value corresponding to the plane data includes: Searching the first set for vertex coordinates corresponding to the vertex index; Searching for the texture coordinates corresponding to the texture index in the second set; Searching the third set for a normal vector corresponding to the normal index; An index value including the vertex coordinates, the texture coordinates, and the normal vector is generated.
7. The method according to claim 6, characterized in that The determining of at least two normal lines corresponding to the same vertex in the model includes: At least two index values having the same vertex coordinates are determined, and a normal vector in the at least two index values is determined.
8. The method according to claim 1, characterized in that The calculating the average normal between every two target normals comprises: The normal vectors corresponding to the target normal are added to obtain an average normal.
9. A model normal processing device, characterized in that: The device comprises: A normal determination module, used to determine at least two normals corresponding to the same vertex in the model; An angle calculation module, used to calculate the angle between each two normal lines of the at least two normal lines; An average normal module is used to calculate an average normal based on the normal corresponding to the target angle when there is a target angle less than an angle threshold among the angles, and use the average normal as the normal of the vertex; the calculation of the average normal based on the normal corresponding to the target angle includes: when the target angles include at least two, respectively calculate the first average normal of the two normals corresponding to each target angle, and calculate the average normal of each of the first average normals; when the target angle includes one, calculate the average normal of the two normals corresponding to the target angle.
10. A computer storage medium, characterized in that: The computer storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the method steps as claimed in any one of claims 1 to 8.
11. An electronic device, characterized in that: include: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the method steps as claimed in any one of claims 1 to 8.
Citation Information
Patent Citations
Three-dimensional font rendering method, medium, equipment and device
CN110660121A