A model parsing method and related apparatus adapted to OpenGL ES
By optimizing the parsing and reorganization of 3D model data, a vertex model that meets the rendering method of glDrawElements is generated, which solves the memory and performance problems caused by redundant vertex data and achieves more efficient image rendering.
Patent Information
- Application Number
- CN202310092582.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-10
- Publication Date
- 2026-07-03
- Estimated Expiration
- 2043-02-10
AI Technical Summary
Existing technologies contain redundant vertex data during 3D model parsing, leading to increased memory requirements and performance issues, and failing to meet the requirements of efficient rendering methods.
By defining multiple containers and index arrays, the model data parsing and reorganization are optimized, redundant vertex data is filtered out, and a vertex model that meets the rendering method of glDrawElements is generated.
The model data size was reduced, memory requirements were lowered, rendering performance and bus bandwidth utilization were improved, resulting in more efficient image rendering.
Smart Images

Figure CN116563436B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to 3D image rendering technology, and more particularly to a model parsing method and related apparatus adapted to OpenGL ES. Background Technology
[0002] 3ds Max is a common 3D modeling tool. The models it exports include files in formats such as .obj and .mtl. The .obj file contains complete vertex coordinates, texture coordinates, normal coordinates, and face composition information of the model, while the .mtl file contains texture map paths, texture materials, and other attribute information.
[0003] OpenGL ES is a lightweight, cross-platform graphics rendering API derived from the OpenGL graphics set for mobile devices, enabling the rendering of rich and colorful 3D scenes on mobile devices.
[0004] During the model loading stage of 3D graphics rendering, the obj data exported from 3ds Max needs to be parsed, reorganized, and sorted to obtain model data that can be directly adapted to the indexed rendering method in OpenGL ES.
[0005] Before importing a 3ds Max model into OpenGLES for rendering, the .obj and .mtl files need to be parsed and converted to obtain model data that conforms to OpenGLES rendering rules. The current common parsing and conversion method is to parse and convert the .obj file based on the rendering rules of the glDrawArrays interface. Specifically, the process can be summarized as follows: based on the index value of the 'f' attribute data in the .obj file, the data of the 'v', 'vt', and 'vn' attributes are filtered and sorted to obtain a new model dataset (mainly containing three reorganized arrays, corresponding to 'v', 'vt', and 'vn' respectively).
[0006] This approach has two drawbacks:
[0007] 1) The 'f' data in the .obj file contains a large number of duplicate index values. This means that the final vertex array contains a lot of redundant and duplicate vertex / texture / normal coordinate data, resulting in a model data size that is several times larger than the original .obj file. As the model becomes more complex, the memory requirements increase, necessitating the use of larger storage devices (DDR or flash), thus increasing costs.
[0008] 2) The model generated by this approach is only applicable to the conventional rendering method in OpenGL ES: glDrawArrays. It does not meet the vertex data order requirements of the more efficient rendering method glDrawElements. As the complexity of the constructed model increases and the number of vertices rises sharply, continuing to use the traditional glDrawArrays rendering method will result in performance problems such as decreased frame rate, insufficient bus bandwidth, and soaring GPU load. Summary of the Invention
[0009] The purpose of this invention is to provide a model parsing method and related apparatus adapted to OpenGL ES, so as to obtain a vertex model that meets the vertex data requirements of the glDrawElements rendering method, while filtering out a large amount of repetitive and redundant vertex data.
[0010] The following provides a brief overview of one or more aspects to offer a basic understanding of them. This overview is not an exhaustive summary of all conceived aspects, nor is it intended to identify key or decisive elements of all aspects, nor to define the scope of any or all aspects. Its sole purpose is to present some concepts of one or more aspects in a simplified form to prepare for the more detailed descriptions that follow.
[0011] According to a first aspect of the present invention, a model parsing method adapted to OpenGL ES is provided, comprising:
[0012] Step 1: Define containers ver_array, ori_tex_array, ori_nor_array, tex_array, nor_array, idx_array, and idx_record_array, where idx_record_array contains three elements: idx_ver, idx_tex, and idx_final.
[0013] Step 2: Read all vertex coordinates 'v' from obj into ver_array; read all texture coordinates 'vt' from obj into ori_tex_array; read all normal coordinates 'vn' from obj into ori_nor_array;
[0014] Step 3: Read the index number data corresponding to one vertex of triangle 'f' in obj, and record them as idx_ver / idx_tex / idx_nor respectively;
[0015] Step 4: Traverse idx_record_array and check whether the correspondence between idx_ver and idx_ver & idx_tex recorded in Step 3 has been recorded:
[0016] Step 41: If idx_ver is not recorded, then use this idx_ver as idx_final, add the value of idx_final to the end of idx_array, and then proceed to step 5;
[0017] Step 42: If idx_ver already exists, but the correspondence between idx_ver and idx_tex does not exist, then increment the capacity of ver_array by 1, take the value of ver_array[idx_ver] and add it to the end of ver_array, and record idx_final as the index value of the end of ver_array, add the value of idx_final to the end of idx_array, and then proceed to step 5;
[0018] Step 43: If the correspondence between idx_ver and idx_tex has been recorded, take the idx_final value of the matching element in idx_record_array and add it to the end of idx_array, then proceed to step 6;
[0019] Step 5: Update idx_record_array, tex_array, and nor_array. Record the set idx_ver&idx_tex&idx_final in idx_record_array, take the value of ori_tex_array[idx_tex] and put it in the position of tex_array[idx_final], and take the value of ori_nor_array[idx_nor] and put it in the position of nor_array[idx_final].
[0020] Step 6: Determine if all 'f' data in obj has been read. If not, return to step 3 to read the next vertex. If yes, end the process.
[0021] In one embodiment, the container ver_array defined in step 1 is used to store the original and newly added vertex coordinates, ori_tex_array is used to store the texture coordinates in the original order, ori_nor_array is used to store the normal coordinates in the original order, tex_array is used to store the texture coordinates after the order is adjusted, and nor_array is used to store the normal coordinates after the order is adjusted.
[0022] In one embodiment, the idx_record_array defined in step 1 is a structure array used to record the processed index data. idx_ver and idx_tex are the initial idx values of vertex coordinates and texture coordinates in their respective containers, and idx_final is the index value of vertex / texture / normal coordinates in the final array after filtering and reorganization.
[0023] In one embodiment, steps S41, S42, and S43 decrement the actual stored idx_final value by 1.
[0024] According to a second aspect of the present invention, a 3D image rendering apparatus is provided, comprising a memory and a processor; the memory is used to store a computer program; the processor is used to implement, when executing the computer program, the model parsing method adapted to OpenGL ES as described in the first aspect.
[0025] According to a third aspect of the present invention, a readable storage medium is provided, wherein a program is stored on the storage medium, and when the program is executed by a processor, implements the model parsing method adapted to OpenGL ES as described in the first aspect.
[0026] The beneficial effects of this invention are: by optimizing the sorting method of data parsing and reorganization during Obj model conversion, a vertex model that meets the requirements of glDrawElements for vertex data can be obtained. In this process, redundant and repeated vertex data in the model data can be filtered out, reducing the size of the model data generated after parsing, saving flash space, and also improving performance and reducing the load on bus bandwidth. Attached Figure Description
[0027] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0028] The above-described features and advantages of the present invention will be better understood after reading the following detailed description of embodiments of the present disclosure in conjunction with the accompanying drawings. In the drawings, components are not necessarily drawn to scale, and components having similar related properties or features may have the same or similar reference numerals.
[0029] Figure 1 This is a flowchart of an embodiment of the method of this application. Detailed Implementation
[0030] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments. It should be noted that the aspects described below with reference to the accompanying drawings and specific embodiments are merely exemplary and should not be construed as limiting the scope of protection of the present invention in any way.
[0031] like Figure 1 As shown, this application embodiment provides a model parsing method adapted to OpenGL ES, including:
[0032] Step 1: Define containers ver_array, ori_tex_array, ori_nor_array, tex_array, nor_array, idx_array, and idx_record_array.
[0033] Among them, the container ver_array is used to store the original and newly added vertex coordinates, ori_tex_array is used to store the texture coordinates in the original order, ori_nor_array is used to store the normal coordinates in the original order, idx_array is used to store the index numbers after reordering, tex_array is used to store the texture coordinates after adjusting the order, and nor_array is used to store the normal coordinates after adjusting the order.
[0034] idx_record_array is a structure array used to record processed index data. It contains three elements: idx_ver, idx_tex, and idx_ver_final. idx_ver and idx_tex are the initial idx values of vertex coordinates and texture coordinates in their respective containers, while idx_final is the index value of the vertex / texture / normal coordinates in the final array after filtering and reorganization.
[0035] Step 2: Read all vertex coordinates 'v' from obj into ver_array; read all texture coordinates 'vt' from obj into ori_tex_array; read all normal coordinates 'vn' from obj into ori_nor_array; thereafter, the data in ori_tex_array and ori_nor_array will remain unchanged, and new vertex coordinates will be appended to the end of ver_array during the subsequent sorting process.
[0036] Step 3: Read the index number data corresponding to one vertex of triangle 'f' in obj, and record them as idx_ver / idx_tex / idx_nor respectively;
[0037] Step 4: Traverse the idx_record_array array and check whether the correspondence between idx_ver and idx_ver & idx_tex recorded in Step 3 has been recorded. Since there is a one-to-one correspondence between idx_nor and idx_ver, it is only necessary to filter the correspondence between idx_ver & idx_tex.
[0038] There are three possibilities:
[0039] Step 41: If idx_ver is not recorded, then use this idx_ver as idx_final, and append the value of idx_final to the end of idx_array. That is, let...
[0040] idx_final = idx_ver;
[0041] idx_array[next]=idx_final;
[0042] After this step is completed, proceed to step 5;
[0043] Step 42: If idx_ver already exists, but the correspondence between idx_ver and idx_tex does not exist, then increment the capacity of ver_array by 1, and append the value of ver_array[idx_ver] to the end of ver_array. Also, set idx_final as the index of the end of ver_array and append the value of idx_final to the end of idx_array. That is, let...
[0044] ver_array[max+1]=ver_array[idx_ver];
[0045] idx_final = max + 1;
[0046] idx_array[next]=idx_final;
[0047] After this step is completed, proceed to step 5;
[0048] Step 43: If the correspondence between idx_ver and idx_tex has been recorded, then take the idx_final value of the matching element in idx_record_array and add it to the end of idx_array.
[0049] That is, let
[0050] idx_final=idx_record_array[find].idx_final;
[0051] idx_array[next]=idx_final;
[0052] After this step is completed, proceed to step 6;
[0053] Step 5: Update idx_record_array, tex_array, and nor_array. Record the set idx_ver&idx_tex&idx_final in idx_record_array, take the value of ori_tex_array[idx_tex] and put it in the position of tex_array[idx_final], and take the value of ori_nor_array[idx_nor] and put it in the position of nor_array[idx_final].
[0054] That is, let
[0055] idx_record_array[next]={idx_ver,idx_tex,idx_final};
[0056] tex_array[idx_final]=ori_tex_array[idx_tex];
[0057] nor_array[idx_final]=ori_nor_array[idx_nor];
[0058] Step 6: Determine if all 'f' data in obj has been read. If not, return to step 3 to read the next vertex. If yes, end the process.
[0059] It should be noted that since glDrawElements defines the index starting from '0', while the index in obj starts from '1', the idx_final value actually stored in steps S41, S42, and S43 should be processed as '-1'.
[0060] By employing the above method, the data sorting during Obj model conversion can be optimized to adapt to the drawing requirements of glDrawElements. This results in three identically sorted coordinate arrays (ver_array, tex_array, nor_array) and an index array (idx_array). Furthermore, the ver / tex / nor coordinates obtained from each index value in the index array correspond to the same vertex. Therefore, during model rendering, glDrawElements can be used instead of glDrawArrays for more efficient image rendering. In addition, this method filters out a large amount of duplicate and redundant vertex data during parsing, significantly reducing the size of the final model file.
[0061] It is readily understood that this application embodiment also provides a 3D image rendering apparatus, including a memory and a processor. The memory can be used to store instructions, programs, code, code sets, or instruction sets. The memory 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, and instructions for implementing the aforementioned model parsing method adapted to OpenGL ES; the data storage area may store data involved in the aforementioned method.
[0062] Accordingly, embodiments of the present invention also provide a computer storage medium storing computer-executable instructions, which, when executed by a processor, implement the aforementioned OpenGL ES-adapted model parsing method of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, external hard drive, read-only memory (ROM), magnetic disk, or optical disk. Thus, embodiments of the present invention are not limited to any specific hardware and software combination.
[0063] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0064] The prior description of this disclosure is provided to enable any person skilled in the art to make or use this disclosure. Various modifications to this disclosure will be apparent to those skilled in the art, and the general principles defined herein may be applied to other variations without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not intended to be limited to the examples and designs described herein, but should be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0065] The above description is merely a preferred example of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application shall be included within the scope of protection of this application.
Claims
1. A model parsing method adapted to OpenGL ES, characterized in that, Applications include 3D image rendering, including: Step 1: Define containers ver_array, ori_tex_array, ori_nor_array, tex_array, nor_array, idx_array, and idx_record_array, where idx_record_array contains three elements: idx_ver, idx_tex, and idx_final. Step 2: Read all vertex coordinates 'v' from obj into ver_array; read all texture coordinates 'vt' from obj into ori_tex_array; read all normal coordinates 'vn' from obj into ori_nor_array; Step 3: Read the index number data corresponding to one vertex of triangle 'f' in obj, and record them as idx_ver / idx_tex / idx_nor respectively; Step 4: Iterate through idx_record_array and check whether the correspondence between idx_ver and idx_ver & idx_tex recorded in Step 3 has been recorded: Step 41: If idx_ver is not recorded, then use this idx_ver as idx_final, add the value of idx_final to the end of idx_array, and then proceed to step 5; Step 42: If idx_ver already exists, but the correspondence between idx_ver and idx_tex does not exist, then increment the capacity of ver_array by 1, take the value of ver_array[idx_ver] and add it to the end of ver_array, and record idx_final as the index value of the end of ver_array, add the value of idx_final to the end of idx_array, and then proceed to step 5; Step 43: If the correspondence between idx_ver and idx_tex has been recorded, take the idx_final value of the matching element in idx_record_array and add it to the end of idx_array, then proceed to step 6; Step 5: Update idx_record_array, tex_array, and nor_array. Record the set idx_ver&idx_tex&idx_final into idx_record_array. Take the value of ori_tex_array[idx_tex] and put it into the position of tex_array[idx_final]. Take the value of ori_nor_array[idx_nor] and put it into the position of nor_array[idx_final]. Step 6: Determine if all 'f' data in obj has been read. If not, return to step 3 to read the next vertex. If yes, end the process.
2. The model parsing method adapted to OpenGL ES according to claim 1, characterized in that: The container ver_array defined in step 1 is used to store the original and newly added vertex coordinates, ori_tex_array is used to store the texture coordinates in the original order, ori_nor_array is used to store the normal coordinates in the original order, tex_array is used to store the texture coordinates after the order is adjusted, and nor_array is used to store the normal coordinates after the order is adjusted.
3. The model parsing method adapted to OpenGL ES according to claim 2, characterized in that: The idx_record_array defined in step 1 is a structure array used to record the processed index data. idx_ver and idx_tex are the initial idx values of vertex coordinates and texture coordinates in their respective containers, and idx_final is the index value of vertex / texture / normal coordinates in the final array after filtering and reorganization.
4. The model parsing method adapted to OpenGL ES according to claim 1, characterized in that: In steps S41, S42, and S43, the actual stored idx_final value is decremented by 1.
5. A 3D image rendering device, characterized in that: Including memory and processor; The memory is used to store computer programs; The processor is configured to implement, when executing the computer program, the model parsing method adapted to OpenGL ES as described in any one of claims 1 to 4.
6. A readable storage medium, characterized in that, The storage medium stores a program that, when executed by a processor, implements the OpenGL ES-compatible model parsing method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
OpenGL (Open Graphics Library)-based transparent / translucent display processing device and method
CN102509335A
Method and device for implementing mobile terminal 3D (three dimensional) model
CN103617220A