Voxel model compression method, decompression method, device, system and medium
By compressing the vertex data of the voxel model in units of rectangular surfaces, recording the normal index information and two-dimensional coordinate extreme values, the problem of large storage space of the voxel model is solved, and saving storage resources and improving loading speed are achieved.
Patent Information
- Application Number
- CN202110790392.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-13
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2041-07-13
AI Technical Summary
In the prior art, the storage space of the voxel model occupies a large amount, resulting in wasted storage resources.
By compressing the vertex data of the voxel model in units of rectangular surfaces, recording the normal index information and two-dimensional coordinate extreme values of each rectangular surface, the compression of the vertex data is achieved.
This greatly saves the storage space of the voxel model, improves the online loading speed and network transmission efficiency of the model.
Smart Images

Figure CN113779023B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for compressing a voxel model, a decompression method, a system, and a medium. Background Art
[0002] Currently, common 3D model formats include the OBJ and STL formats. Almost all 3D modeling software supports exporting these two formats. The 3D model files in these two formats directly store the vertex data of the model, the vertex information corresponding to each triangular face, and the normal vectors of the fragments in the file in ASCII code. These two encodings are simple and general and are therefore widely used. However, the method of recording using ASCII code actually increases a lot of unnecessary storage space, resulting in a large storage space occupied by the voxel model and wasting storage resources. Summary of the Invention
[0003] In view of the above deficiencies of the prior art, the purpose of the present invention is to provide a method and device for compressing a voxel model, a decompression method, a system, and a medium, aiming to solve the problem that the voxel model data in the prior art occupies too much storage space and wastes storage resources.
[0004] The technical solution of the present invention is as follows:
[0005] A method for compressing a voxel model includes:
[0006] Obtaining vertex data of a voxel model to be compressed;
[0007] Obtaining normal index information corresponding to multiple rectangular faces in the voxel model to be compressed according to the vertex data;
[0008] Traversing the rectangular faces according to the normal index information, and determining the two-dimensional coordinate extrema of the traversed rectangular faces according to the vertex data;
[0009] Storing the two-dimensional coordinate extrema and normal index information of the rectangular faces in a preset order to compress the vertex data, and obtaining compressed voxel model data.
[0010] In one embodiment, obtaining normal index information corresponding to multiple rectangular faces in the voxel model to be compressed according to the vertex data includes:
[0011] Creating a normal slice table with a preset structure;
[0012] Calculating the directions of the normal vectors of all rectangular faces in the voxel model to be compressed according to the vertex data, and the normal coordinates of each rectangular face;
[0013] Counting the number of rectangular faces corresponding to each normal coordinate along the directions of the respective normal vectors and recording them in the normal slice table to obtain normal index information.
[0014] In one embodiment, the rectangular surfaces are traversed according to the normal features in the normal index information, and the two-dimensional coordinate extrema of the traversed rectangular surfaces are determined based on the vertex data, including:
[0015] Traverse the rectangular surfaces in sequence according to the normal index information, and when each traversal result is obtained, determine the minimum coordinate pair and the maximum coordinate pair of the currently traversed rectangular surface in the two-dimensional plane based on the vertex data, so as to obtain the corresponding two-dimensional coordinate extrema.
[0016] In one embodiment, the two-dimensional coordinate extrema of the rectangular surfaces and the normal index information are stored in a preset order to compress the vertex data, so as to obtain the compressed voxel model data, including:
[0017] Write the two-dimensional coordinate extrema of each rectangular surface into a preset data array in the data storage order of the normal index information to compress the vertex data;
[0018] Output the written preset data array and the normal index information as the compressed voxel model data.
[0019] A compression device for a voxel model, including:
[0020] A vertex acquisition module, configured to acquire the vertex data of the voxel model to be compressed;
[0021] A normal slicing module, configured to acquire the normal index information corresponding to multiple rectangular surfaces in the voxel model to be compressed according to the vertex data;
[0022] A traversal module, configured to traverse the rectangular surfaces according to the normal index information, and determine the two-dimensional coordinate extrema of the traversed rectangular surfaces based on the vertex data;
[0023] A compression storage module, configured to store the two-dimensional coordinate extrema of the rectangular surfaces and the normal index information in a preset order to compress the vertex data, so as to obtain the compressed voxel model data.
[0024] A decompression method for a voxel model, including:
[0025] Acquire the compressed voxel model data;
[0026] Read the normal index information and the two-dimensional coordinate extrema of the rectangular surfaces in the compressed voxel model data in a preset order;
[0027] Decompress and calculate the corresponding vertex data according to the normal index information and the two-dimensional coordinate extrema of the rectangular surfaces;
[0028] Construct the corresponding voxel model according to the decompressed vertex data.
[0029] In one embodiment, reading the normal index information and two-dimensional coordinate extreme values of the rectangular faces in the compressed voxel model data in a preset order includes:
[0030] After parsing the compressed voxel model data, obtaining a preset data array and the normal index information of the rectangular faces, where the preset data array is used to store the two-dimensional coordinate extreme values of the rectangular faces;
[0031] According to the data storage order of the normal index information, sequentially reading the two-dimensional coordinate extreme values of each rectangular face in the preset data array to obtain the two-dimensional coordinate extreme values of all rectangular faces.
[0032] A decompression device for a voxel model, comprising:
[0033] A compressed data acquisition module for acquiring the compressed voxel model data;
[0034] A reading module for reading the normal index information and two-dimensional coordinate extreme values of the rectangular faces in the compressed voxel model data in a preset order;
[0035] A decompression calculation module for decompressing and calculating corresponding vertex data according to the normal index information and two-dimensional coordinate extreme values of the rectangular faces;
[0036] A construction module for constructing a corresponding voxel model according to the decompressed vertex data.
[0037] A compression and decompression system for a voxel model, the system includes at least one processor; and,
[0038] A memory communicatively connected to at least one processor; wherein,
[0039] The memory stores instructions executable by at least one processor, and the instructions are executed by at least one processor so that at least one processor can execute the above-mentioned compression method or decompression method of the voxel model.
[0040] A non-volatile computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by one or more processors, one or more processors can execute the above-mentioned compression method or decompression method of the voxel model.
[0041] Advantageous effects: The present invention discloses a compression method, decompression method, device, system and medium for a voxel model. Compared with the prior art, by compressing the vertex data of the voxel model in units of rectangular faces, recording the normal index information and two-dimensional coordinate extreme values of each rectangular face to achieve the compression of the vertex data, thereby obtaining the compressed voxel model data, which greatly saves the storage space of the voxel model. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The present invention will be further described below in conjunction with the accompanying drawings and embodiments. In the drawings:
[0043] Figure 1 is a flowchart of a method for compressing a voxel model provided by an embodiment of the present invention;
[0044] Figure 2 is a schematic diagram of a voxel model provided by an embodiment of the method for compressing a voxel model of the present invention;
[0045] Figure 3 is a schematic diagram of different rectangular faces of a voxel model provided by an embodiment of the method for compressing a voxel model of the present invention;
[0046] Figure 4 is a flowchart of a method for decompressing a voxel model provided by an embodiment of the present invention;
[0047] Figure 5 is a schematic diagram of functional modules of a device for compressing a voxel model provided by an embodiment of the present invention;
[0048] Figure 6 is a schematic diagram of functional modules of a device for decompressing a voxel model provided by an embodiment of the present invention;
[0049] Figure 7 is a schematic diagram of the hardware structure of a system for compressing and decompressing a voxel model provided by an embodiment of the present invention. Detailed Embodiments
[0050] To make the objectives, technical solutions and effects of the present invention clearer and more definite, the present invention will be further described in detail below. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. The embodiments of the present invention will be described below in conjunction with the accompanying drawings.
[0051] Please refer to Figure 1 , the method for compressing a voxel model provided by the present invention includes the following steps:
[0052] S102. Obtain the vertex data of the voxel model to be compressed.
[0053] In this embodiment, the voxel model to be compressed is a voxel model generated by existing pixel modeling tools such as MagicaVoxel (voxel editor), ao-mesher (voxel open source library), etc. A voxel model is a model that represents a three-dimensional object by an ordered combination of a large number of regular voxels, that is, a voxel model composed of a set of multiple volume pixels (the smallest unit in the three-dimensional segmentation of digital data). The voxel model data is recorded in binary data, and the storage space is greatly reduced compared with ASCII code, making it have the advantages of easy editing, easy creation, and small occupied space. For exampleFigure 2 As shown, it is a schematic diagram of a simple voxel model. The present invention further compresses the voxel model to save the occupied space of the model to the greatest extent, thereby improving the online loading speed of the voxel model. Before compression, the vertex data of the voxel model to be compressed is first obtained. The vertex data at least includes vertex coordinates and vertex normal vectors. Of course, according to the modeling requirements, it can further include, for example, texture information, ambient occlusion information, material information, etc. to improve the visual effect of model construction. This embodiment makes a limitation in this regard.
[0054] S104. Obtain the normal index information corresponding to each of the multiple rectangular faces in the voxel model to be compressed according to the vertex data.
[0055] In this embodiment, as Figure 2 shown, based on the cubic structure of volume pixels, the faces of the voxel model have inherent rules. Specifically, there are only six directions for the faces of the triangular fragments of the model. A certain face is only one of these six. If the direction of the normal vector is used to represent the orientation of the face, it can be expressed as: +X, -X, +Y, -Y, +Z, -Z. For a face of a triangular fragment with an orientation of +X or -X, the vertices on the face will have equal x coordinates; for a face of a triangular fragment with an orientation of +Y or -Y, the vertices on the face will have equal y coordinates; similarly, for a face of a triangular fragment with an orientation of +Z or -Z, the vertices on the face will have equal z coordinates.
[0056] Based on the above rules of normal coordinates, each face is given corresponding normal features. When saving the data of the voxel model, the vertex data can be compressed by taking the face as the unit and using the normal features as the index to save storage space, that is, obtain the normal index information of each rectangular face in the voxel model to be compressed. The normal index information stores the normal features of each rectangular face. The specific normal features at least include the direction of the normal vector, the normal coordinates, and the number of faces corresponding to each normal coordinate. Each rectangular face can be accurately located through the normal index information. Preferably, as Figure 3 shown, different from the traditional method of using triangular faces as the smallest unit for constructing a polygon mesh model, in this embodiment, when performing data compression, rectangular faces can be used as the basic unit of the voxel model, so that the six vertices required for the two triangular faces forming the rectangular face can be further reduced to the four vertices required for the rectangular face. The normal features of all rectangular faces are obtained through the vertex data of the model to form normal index information convenient for finding each rectangular face, so as to perform accurate and efficient compression processing subsequently.
[0057] Specifically, step S104 in the compression method of the voxel model provided by the present invention includes:
[0058] Create a normal slice table with a preset structure;
[0059] Calculate the direction of the normal vector of all rectangular faces in the voxel model to be compressed according to the vertex data, and the normal coordinates of each rectangular face;
[0060] Count the number of rectangular faces corresponding to each normal coordinate along the direction of each normal vector and record it in the normal slice table to obtain the normal index information.
[0061] In this embodiment, the normal index information is in the form of a table. By creating a normal slice table with a preset structure to store the normal features of all rectangular faces, the normal index information is formed. Among them, the normal features include the direction of the normal vector, the normal coordinates, and the number of rectangular faces corresponding to each normal coordinate. Specifically, the direction of the normal vector includes the six orientations of +X, -X, +Y, -Y, +Z, -Z as described above. The vector represented by the line perpendicular to the rectangular face is the normal vector of the rectangular face. In the voxel model, there are countless normal vectors for a rectangular face, and the directions of these countless normal vectors are the same; the normal coordinates are the coordinate values of the rectangular face in its normal direction, that is, the vertical axis coordinate values of the vertices on the rectangular face. The normal direction is the normal direction of the rectangular face. It can be understood that in this embodiment, the normal direction of the rectangular face is the direction of the normal vector of the rectangular face. Therefore, the normal slice table is specifically used to record the number of rectangular faces corresponding to different normal coordinates in each normal direction, so as to classify and summarize each rectangular face that makes up the voxel model according to its normal direction and the coordinate values in the normal direction, and obtain the normal index information for subsequent rectangular face search.
[0062] During specific calculation, calculate the direction of the normal vector of all rectangular faces in the voxel model to be compressed according to the vertex coordinates and vertex normal vectors of the voxel model to be compressed, and the normal coordinates of each rectangular face.
[0063] In this embodiment, according to the vertex coordinates and vertex normal vectors in the vertex data, the normal vectors of all rectangular faces can be calculated, and then the direction of the normal vector of the rectangular face can be obtained. And according to the law of the normal coordinates of the above voxel model, the vertices on each rectangular face have equal coordinate values along the normal direction. Take this coordinate value as the normal coordinate of each rectangular face, count the normal coordinates in the direction of each normal vector and the number of rectangular faces corresponding to each normal coordinate, and store them in the normal slice table one by one in a preset order, so as to realize accurate and detailed classification and statistics of rectangular faces to form normal index information, providing a solid index data foundation for subsequent compression of the model data saved by vertices into model data saved by rectangular faces.
[0064] Specifically, the normal slice table can adopt a matrix format, such as a cross - table, for classification and summarization. For example, the first row represents the directions of each normal vector, the first column represents the normal coordinates, and each cross - cell represents the number of rectangular faces with the direction of the normal vector corresponding to the current column and the normal coordinates corresponding to the current row. Conversely, the first row can also be set as the normal coordinates and the first column as the directions of each normal vector. This embodiment does not limit this. Preferably, since there are only six directions for the normal vectors of all rectangular faces, namely +X, -X, +Y, -Y, +Z, -Z, a normal code in digital form, such as 0, 1, 2, 3, 4, 5, can be used to represent these six situations, further simplifying the constituent data of the voxel model. Of course, in other embodiments, other numbers can also be used for differentiation, and this embodiment does not limit this. In an application embodiment, the content of the normal slice table is as follows: when the normal code is 0, there are 23 rectangular faces with an x - coordinate of 0; when the normal code is 0, there are 12 rectangular faces with an x - coordinate of 1; and so on, recording the number of rectangular faces when the x - coordinate reaches the maximum value when the normal code is 0. For example, when the normal code is 0, there are 20 rectangular faces with an x - coordinate of 15. Similarly, according to the above - mentioned recording and storage rules, record the number of rectangular faces corresponding to different normal coordinates when the normal code is from 1 to 5 in the normal slice table in turn, so as to obtain a normal slice table in pure digital form as normal index information, further simplifying the stored data, saving storage space, effectively improving the network transmission speed and online loading speed of the voxel model, and realizing a more efficient process for the transmission and loading of the voxel model.
[0065] S106. Traverse the rectangular faces according to the normal index information, and determine the two - dimensional coordinate extrema of the traversed rectangular faces according to the vertex data.
[0066] In this embodiment, after obtaining the normal index information of all rectangular faces, since each vertex of each rectangular face has the same coordinate value in its normal direction, when compressing, it is not necessary to completely save the coordinate values of the third dimension of each vertex, that is, the vertical axis coordinate value, but only need to pay attention to the coordinate information of each rectangular face in its two - dimensional plane. Further, based on the characteristic that all four interior angles of a rectangular face are right angles, only the two - dimensional coordinate extrema of each rectangular face are needed to determine the positions of its four vertices in the two - dimensional plane, where the two - dimensional coordinate extrema include the two - dimensional coordinate maximum value and the two - dimensional coordinate minimum value. Therefore, in this embodiment, after traversing all rectangular faces in a preset order according to the normal characteristics in the normal index information, the two - dimensional coordinate extrema of each rectangular face in the two - dimensional plane are obtained through the six vertex data of the rectangular face (two triangular fragments form a rectangular face), compressing the three - dimensional vertex data into two - dimensional coordinate extremum data in units of rectangular faces, greatly saving the data volume and storage space required to save a rectangular face.
[0067] Specifically, step S106 in the voxel model compression method provided by the present invention includes:
[0068] Traverse the rectangular faces in sequence according to the normal index information. When each traversal result is obtained, determine the minimum coordinate pair and the maximum coordinate pair of the currently traversed rectangular face on the two-dimensional plane according to the vertex data, so as to obtain the corresponding two-dimensional coordinate extreme values.
[0069] In this embodiment, since all rectangular faces have been refined and classified according to the normal characteristics of each rectangular face through the normal index information, the rectangular faces can be traversed in sequence according to the normal characteristics. For example, they can be traversed in sequence according to the storage order of the normal characteristics of each rectangular face in the normal index information. Each traversal can obtain a rectangular face. When each traversal result is obtained, the minimum coordinate pair and the maximum coordinate pair of the currently traversed rectangular face on the two-dimensional plane are determined according to the vertex data, so as to obtain the corresponding two-dimensional coordinate extreme values. That is to say, in this embodiment, the traversal action and the determination action of the two-dimensional coordinate extreme values are alternated. After each rectangular face is traversed, the two-dimensional coordinate extreme values of the rectangular face on the two-dimensional plane are obtained, ensuring the accuracy when compressing data in units of rectangular faces.
[0070] The specific normal index information is obtained by refining and classifying all rectangular faces through a normal slice table, and obtaining the number of rectangular faces corresponding to different coordinate values under each normal. At this time, each rectangular face is traversed along different normal vector directions and different normal coordinates. In particular, it can be traversed in a corresponding order. For example, the traversal order is the same as the storage order of the normal slice table, preferably in accordance with the preset normal order and the rule that the coordinate values increase from small to large. The preset normal order can be set in advance. For example, when the normal codes of 0, 1, 2, 3, 4, and 5 respectively represent the six normals of +X, -X, +Y, -Y, +Z, and -Z, the preset normal order can adopt the order of increasing numbers. Of course, in other embodiments, other orders can also be adopted, as long as the traversal order is the same as the storage order. This embodiment does not limit this.
[0071] In an optional embodiment, taking the above-mentioned preset normal order as an example, first traverse the rectangular surface with a normal code of 0 and an x coordinate of 0, and then traverse the rectangular surface with a normal code of 0 and an x coordinate of 1, until all the rectangular surfaces with a normal code of 0 are traversed, and then start traversing the rectangular surface with a normal code of 1 and an x coordinate of 0, and so on, traversing all the rectangular surfaces in order. Moreover, when storing data for each traversed rectangular surface, the three-dimensional coordinates of the six vertices of the rectangular surface are no longer required, that is, the complete x, y, and z coordinates, but only the minimum coordinate pair and the maximum coordinate pair of the current rectangular surface on its two-dimensional plane need to be recorded. The minimum coordinate pair is the minimum horizontal axis coordinate value lo_x and the minimum vertical axis coordinate value lo_y of the current rectangular surface on its two-dimensional plane, and the maximum coordinate pair is the maximum horizontal axis coordinate value hi_x and the maximum vertical axis coordinate value hi_y of the current rectangular surface on its two-dimensional plane. That is, the minimum coordinate pair and the maximum coordinate pair represent the positions of the two diagonal vertices on one diagonal of the current rectangular surface on the two-dimensional plane. Through these two diagonal vertices, the positions of the two diagonal vertices on the other diagonal of the current rectangular surface on the two-dimensional plane can be deduced. And the coordinate of the third dimension of the current rectangular surface, that is, the vertical axis coordinate value, is the index information used during traversal, that is, the normal of the current rectangular surface and the coordinate value on the normal. Therefore, the data required to save each rectangular surface is compressed from the three-dimensional coordinates of six vertices and their normal vectors to the two-dimensional coordinates of two diagonal vertices, which greatly reduces the space occupied by the compressed data compared with the uncompressed data. For applications such as online web 3D games, etc., it greatly reduces the loading time of model data and improves the data transmission and loading efficiency of the voxel model.
[0072] S108. Store the two-dimensional coordinate extreme values and normal index information of the rectangular surfaces in a preset order to compress the vertex data, and obtain the compressed voxel model data.
[0073] In this embodiment, during compression output, the two-dimensional coordinate extreme values of each rectangular surface are stored in a preset order to compress the vertex data in units of surfaces. The stored two-dimensional coordinate extreme values and normal index information are output to obtain the voxel model data with greatly reduced storage space after compression. Specifically, the preset order for storage is the same as the traversal order of the rectangular surfaces when obtaining the two-dimensional coordinate extreme values, ensuring the accuracy of data compression and avoiding data chaos that may cause the inability to restore the correct voxel model during subsequent decompression.
[0074] Specifically, step S108 in the voxel model compression method provided by the present invention includes:
[0075] Write the two-dimensional coordinate extreme values of each rectangular surface into a preset data array in the data storage order of the normal index information to compress the vertex data;
[0076] Output the preset data array and the normal index information after writing as compressed voxel model data.
[0077] In this embodiment, a preset data array is created to store the compressed data. Similar to the traversal order of the rectangular faces, when writing data into the preset data array, it is also written according to the data storage order of the normal index information, that is, according to the storage order of the normal features. Preferably, it is written in the preset normal order and in the rule of increasing coordinate values in sequence. The written data specifically includes the minimum coordinate pair and the maximum coordinate of each rectangular face. Since the writing order is the same as the storage order of the normal features, the normal features of each rectangular face can be determined one by one. Then, the completed preset data array and the normal index information are output as compressed voxel model data, which can greatly reduce the occupied space while ensuring the accurate storage of the model information, thereby enabling faster network transmission and being beneficial to improving the online loading speed of the voxel model and realizing a more efficient, fast and smooth voxel model loading process.
[0078] As can be seen from the above method embodiments, the compression method of the voxel model provided by the present invention compresses the vertex data of the voxel model in units of rectangular faces, records the normal index information and two-dimensional coordinate extrema of each rectangular face to achieve the compression of the vertex data, thereby obtaining the compressed voxel model data, which greatly saves the storage space of the voxel model.
[0079] It should be noted that there is not necessarily a certain order among the above steps. Those of ordinary skill in the art can understand according to the description of the embodiments of the present invention that in different embodiments, the above steps can have different execution orders, that is, they can be executed in parallel or exchanged, etc.
[0080] Corresponding to the above compression method of the voxel model, the present invention also provides a decompression method of the voxel model for decompressing the above compressed voxel model data. As Figure 4 shown, the decompression method of the voxel model includes the following steps:
[0081] S402. Obtain the compressed voxel model data;
[0082] S404. Read the normal index information and two-dimensional coordinate extrema of the rectangular faces in the compressed voxel model data in a preset order;
[0083] S406. Decompress and calculate the corresponding vertex data according to the normal index information and two-dimensional coordinate extrema of the rectangular faces;
[0084] S408. Construct the corresponding voxel model according to the decompressed vertex data.
[0085] Specifically, step S404 in the method for decompressing the voxel model provided by the present invention includes:
[0086] After parsing the compressed voxel model data, obtain a preset data array and the normal index information of the rectangular faces. The preset data array is used to store the two-dimensional coordinate extrema of the rectangular faces.
[0087] Read the two-dimensional coordinate extrema of each rectangular face in the preset data array in sequence according to the data storage order of the normal index information to obtain the two-dimensional coordinate extrema of all rectangular faces.
[0088] It is easy to understand that the decompression process is the reverse process of the compression process. During decompression, first obtain the compressed voxel model data. After parsing the compressed voxel model data, a preset data array and the normal index information of the rectangular faces can be obtained. Then, traverse the preset data array in the preset order according to the normal index information, and sequentially obtain the two-dimensional coordinate extrema and normal features of each rectangular face. The normal features include the normal direction of the normal vector of the rectangular face and the normal coordinates. Specifically, read according to the data storage order of the normal index information, that is, the reading order is the same as the storage order during compression, and read in the preset normal order and the order of increasing coordinate values. Then, according to the data of each rectangular face, including its two-dimensional coordinate extrema, the normal direction of the normal vector, and the corresponding normal coordinates, calculate and decompress to obtain the six vertex data of the rectangular face. According to the six vertex data of each decompressed rectangular face, form a triangle patch face by taking three as a group, and then the corresponding voxel model can be obtained.
[0089] To better understand the implementation process of the compression method and decompression method of the voxel model provided by the present invention, the following specific application examples are given to illustrate the compression process and decompression process of the voxel model:
[0090] In this embodiment, the vertex data of each face constituting the voxel model to be compressed includes the following 8 data segments:
[0091] x: The x coordinate of the vertex, data type Uint8;
[0092] y: The y coordinate of the vertex, data type Uint8;
[0093] z: The z coordinate of the vertex, data type Uint8;
[0094] ao: The ambient occlusion information of the vertex, data type Uint8;
[0095] UV: The texture information of the vertex, that is, the UV coordinates. Through binary shift and or operations, write the two-dimensional data into a data segment, data type Uint8;
[0096] normalCode: Normal vector information of the vertex. Since there are only 6 directions for the normal vector, namely -X, +X, -Y, +Y, -Z, +Z, the six cases can be represented by the numbers 0, 1, 2, 3, 4, 5. The data type is Uint8;
[0097] packedAo: Ao information on the rectangular face where the vertex is located, including the ao information of the four vertices of the rectangle. Similarly, through binary shift and or operations, the four data are written into a data segment. The data type is Uint8;
[0098] material_id: Material id of the vertex. The data type is Uint8.
[0099] Each of the above data segments is of Uint8 type. One Uint8 occupies one Byte. Therefore, one vertex occupies 8 Bytes. Since the voxel model generated in this embodiment still uses the method of representing a rectangular face with two triangles, a rectangular face will be composed of six vertices, that is, it will occupy 48 Bytes. And through the compression in this embodiment, the number of bytes occupied by each rectangular face will be greatly reduced.
[0100] Specifically, the implementation process of data compression is as follows:
[0101] Step 1: Input the vertex data of the unprocessed voxel model and the material table;
[0102] Step 2: Calculate the number of vertices and the number of triangular faces;
[0103] Step 3: Create a normal_slice_table (normal slice table), a material_table (material table), and a data array for storing the compressed data;
[0104] Step 4: Execute loop step a. Loop step a is specifically to set a variable k and make k traverse the 6 values of the normal vector, that is, [0, 1, 2, 3, 4, 5];
[0105] Step 5: Execute loop step b. Loop step b is specifically to traverse all rectangular faces. If the value of the normal vector of the face is equal to k, then execute step 6;
[0106] Step 6: If the value of the normal of the face is equal to k, traverse the face with the coordinate value z = 0 on the normal, continuously traverse 6 vertices, record the minimum horizontal axis coordinate value lo_x, the minimum vertical axis coordinate value lo_y, the maximum horizontal axis coordinate value hi_x, the maximum vertical axis coordinate value hi_y, the normal coordinate z, packedAO into data, record the material id used by this face into material_table, and continue traversing after incrementing normal_slice_table[k][z] by 1;
[0107] Step 7: End of loop in step b;
[0108] Step 8: End of loop in step a;
[0109] Step 9: Record the key-value pairs of normal_slice_table into an array one by one, denoted as slice_info (slice information);
[0110] Step 10: Output slice_info, material_table, and data as the final compressed data.
[0111] Reduce the data required to store a rectangular face to lo_x, lo_y, hi_x, hi_y, material_id, packedAo. The data type is Uint8, each occupying one byte. Compared with originally requiring 48 bytes to record a rectangular face, only 6 bytes are needed at this time, greatly reducing the required storage space.
[0112] Correspondingly, the implementation process of data decompression is as follows:
[0113] Step 1: Input slice_info, material_table, and data;
[0114] Step 2: Create mesh_buffer (mesh buffer) to store the decompressed data;
[0115] Step 3: Execute loop step a. Loop step a is specifically to traverse the array slice_info;
[0116] Step 4: Read the value of the normal (normal_code) and the coordinate value on the normal (normal_code_count) from slice_info;
[0117] Step 5: Execute loop step b. Loop step b is specifically to set a variable j and make j traverse from 0 to normal_code_count;
[0118] Step 6: Execute loop step c. Specifically, set a variable k and let k iterate from 0 to z_count, where z_count is the number of rectangular faces with the current z value (the coordinate value in the normal direction).
[0119] Step 7: Read lo_x, lo_y, hi_x, hi_y, z, and packedAO from data in sequence.
[0120] Step 8: Calculate the ao values of the four vertices of the rectangular face through normal_code and packedAO.
[0121] Step 9: Calculate the 3D coordinates of the four vertices through normal_code, lo_x, lo_y, hi_x, hi_y, and z.
[0122] Step 10: Continuously write the data of 6 vertices into mesh_buffer, with every three vertices forming a triangular face.
[0123] Step 11: End loop step c.
[0124] Step 12: End loop step b.
[0125] Step 13: End loop step a.
[0126] Step 14: The obtained mesh_buffer is the decompressed data.
[0127] Using the above decompression method, the compressed data reduces the space occupancy by approximately 7 / 8 compared to the uncompressed data. For the original 1mb data, it now only requires about 128kb. And when compared with OBJ and STL files using ASCII code, it only needs a few tenths of the storage space of the latter, greatly reducing the storage space occupied by the model data, enabling faster network transmission and decompression and loading. For applications such as online web 3D games, it greatly reduces the loading time of the model data and improves the data transmission and loading efficiency of the voxel model.
[0128] Corresponding to the above compression method of the voxel model, another embodiment of the present invention provides a voxel model compression device, as Figure 5 shown. The device 500 includes:
[0129] A vertex acquisition module 502, configured to acquire vertex data of the voxel model to be compressed;
[0130] A normal slicing module 504, configured to obtain the normal index information corresponding to multiple rectangular faces in the voxel model to be compressed according to the vertex data;
[0131] A traversal module 506, configured to traverse rectangular faces according to normal index information and determine the two-dimensional coordinate extreme values of the traversed rectangular faces based on vertex data;
[0132] A compression storage module 508, configured to store the two-dimensional coordinate extreme values and normal index information of rectangular faces in a preset order to compress vertex data, thereby obtaining compressed voxel model data.
[0133] The vertex acquisition module 502, the normal slicing module 504, the traversal module 506, and the compression storage module 508 are connected in sequence. The modules in the present invention refer to a series of computer program instruction segments capable of completing specific functions, and are more suitable for describing the execution process of a voxel model compression device than programs. For the specific implementation manners of each module, please refer to the corresponding method embodiments above, which will not be elaborated herein.
[0134] In one embodiment, the normal slicing module 504 includes:
[0135] A creation unit, configured to create a normal slicing table with a preset structure;
[0136] A calculation unit, configured to calculate the directions of the normal vectors of all rectangular faces in the voxel model to be compressed and the normal coordinates of each rectangular face based on vertex data;
[0137] A statistics storage unit, configured to count the number of rectangular faces corresponding to each normal coordinate along the directions of respective normal vectors and record the count in the normal slicing table to obtain normal index information.
[0138] In one embodiment, the traversal module 506 is configured to:
[0139] Traverse rectangular faces in sequence according to normal index information, and when obtaining each traversal result, determine the minimum coordinate pair and the maximum coordinate pair of the currently traversed rectangular face in a two-dimensional plane based on vertex data, thereby obtaining corresponding two-dimensional coordinate extreme values.
[0140] In one embodiment, the compression storage module 508 includes:
[0141] A writing unit, configured to sequentially write the two-dimensional coordinate extreme values of each rectangular face into a preset data array in the data storage order of normal index information to compress vertex data;
[0142] A compression output unit, configured to output the written preset data array and normal index information as compressed voxel model data.
[0143] Corresponding to the above-described voxel model decompression method, another embodiment of the present invention provides a voxel model decompression device, as Figure 6 shown. The device 600 includes:
[0144] The compressed data acquisition module 602 is configured to acquire the compressed voxel model data;
[0145] The reading module 604 is configured to read the normal index information and two-dimensional coordinate extreme values of the rectangular faces in the compressed voxel model data in a preset order;
[0146] The decompression calculation module 606 is configured to perform decompression calculation according to the normal index information and two-dimensional coordinate extreme values of the rectangular faces to obtain the corresponding vertex data;
[0147] The construction module 608 is configured to construct the corresponding voxel model according to the decompressed vertex data.
[0148] The compressed data acquisition module 602, the reading module 604, the decompression calculation module 606 and the construction module 608 are connected in sequence. The modules referred to in the present invention refer to a series of computer program instruction segments that can complete specific functions, and are more suitable for describing the execution process of the voxel model decompression device than programs. For the specific implementation manners of each module, please refer to the corresponding method embodiments above, which will not be elaborated here.
[0149] In one embodiment, the reading module 604 includes:
[0150] The parsing unit is configured to parse the compressed voxel model data to obtain a preset data array and the normal index information of the rectangular faces, and the preset data array is used to store the two-dimensional coordinate extreme values of the rectangular faces;
[0151] The reading unit is configured to sequentially read the two-dimensional coordinate extreme values of each rectangular face in the preset data array according to the data storage order of the normal index information to obtain the two-dimensional coordinate extreme values of all rectangular faces.
[0152] Another embodiment of the present invention provides a voxel model compression and decompression system. The voxel model compression and decompression system can be a computing device such as a mobile terminal, a desktop computer, a notebook, a palm computer, and a server. As Figure 7 shown, the system 700 includes:
[0153] One or more processors 702 and a memory 704. Figure 7 Taking one processor 702 as an example for introduction, the processor 702 and the memory 704 can be connected through a bus or other means. Figure 7 Taking the connection through the bus as an example.
[0154] The processor 702 is used to complete various control logics of the system 700. It can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISC Machine), or other programmable logic devices, discrete gate or transistor logic, discrete hardware components, or any combination of these components. Moreover, the processor 702 can also be any conventional processor, microprocessor, or state machine. The processor 702 can also be implemented as a combination of computing devices. For example, a combination of a DSP and a microprocessor, multiple microprocessors, one or more microprocessors combined with a DSP and / or any other such configuration.
[0155] The memory 704, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as program instructions corresponding to the voxel model compression method in the embodiments of the present invention. The processor 702 executes various functional applications and data processing of the system 700 by running the non-volatile software programs, instructions, and units stored in the memory 704, that is, implements the voxel model compression method in the above method embodiments, or implements the voxel model decompression method in the above method embodiments.
[0156] The memory 704 can include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store data created according to the use of the system 700, etc. In addition, the memory 704 can include high-speed random access memory, and can also include non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some embodiments, the memory 704 can optionally include memories remotely set relative to the processor 702, and these remote memories can be connected to the system 700 through a network. Examples of the above networks include, but are not limited to, the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.
[0157] One or more units are stored in the memory 704 and, when executed by one or more processors 702, execute the voxel model compression method in any of the above method embodiments. For example, execute the method steps S102 to S108 described above Figure 1 or execute the method steps S402 to S408 described above Figure 4 in.
[0158] The embodiments of the present invention provide a non-volatile computer-readable storage medium. The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are executed by one or more processors. For example, execute the above-described Figure 1The method steps S102 to S108 in, or execute the above-described Figure 4 method steps S402 to S408 in.
[0159] By way of example, the non-volatile storage medium can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable ROM (EEPROM), or flash memory. The volatile memory can include random access memory (RAM) as an external cache memory. By way of illustration and not limitation, RAM can be obtained in many forms such as synchronous RAM (SRAM), dynamic RAM, (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), SyncLink DRAM (SLDRAM), and direct Rambus (Rambus) RAM (DRRAM). The disclosed memory components or memories of the operating environment described herein are intended to include one or more of these and / or any other suitable types of memories.
[0160] In summary, in the voxel model compression method, decompression method, device, system, and medium disclosed in the present invention, the method obtains vertex data of a voxel model to be compressed; obtains normal index information corresponding to multiple rectangular faces in the voxel model to be compressed according to the vertex data; traverses the rectangular faces according to the normal index information, and determines two-dimensional coordinate extreme values of the traversed rectangular faces according to the vertex data; stores the two-dimensional coordinate extreme values and normal index information of the rectangular faces in a preset order to compress the vertex data, and obtains compressed voxel model data. By the embodiments of the present invention, the vertex data of the voxel model is compressed in units of rectangular faces, and the normal index information and two-dimensional coordinate extreme values of each rectangular face are recorded to compress the vertex data, so as to obtain compressed voxel model data, greatly saving the storage space of the voxel model.
[0161] The embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0162] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solution, in essence, or the part that contributes to the related technology can be embodied in the form of a software product. This computer software product can exist in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer electronic device (which can be a personal computer, a server, or a network electronic device, etc.) to execute the methods of each embodiment or some parts of the embodiments.
[0163] Among other things, conditional language such as "can", "able to", "may", or "could", unless specifically stated otherwise or otherwise understood within the context in which it is used, generally is intended to convey that a particular embodiment can include (while other embodiments do not include) a particular feature, element, and / or operation. Thus, such conditional language generally is also intended to imply that the feature, element, and / or operation is in some way required for one or more embodiments or that one or more embodiments must include logic for determining whether the feature, element, and / or operation is included or will be performed in any particular embodiment, with or without input or prompting.
[0164] What has been described herein in the specification and the drawings includes examples of a compression method, a decompression method, an apparatus, a system, and a medium that can provide a voxel model. Of course, it is not possible to describe every conceivable combination of elements and / or methods for the purpose of describing the various features of the present disclosure, but it can be recognized that many additional combinations and permutations of the disclosed features are possible. Therefore, it is apparent that various modifications can be made to the present disclosure without departing from the scope or spirit thereof. Additionally, or in the alternative, other embodiments of the present disclosure may be apparent from consideration of the specification and the drawings and practice of the present disclosure as presented herein. The intention is that the examples presented in the specification and the drawings are considered illustrative in all respects and not restrictive. Although specific terms are employed herein, they are used in a general and descriptive sense and not for purposes of limitation.
Claims
1. A compression method for a voxel model, characterized in that, Comprising: Obtaining vertex data of a voxel model to be compressed; Obtaining normal index information corresponding to each of a plurality of rectangular faces in the voxel model to be compressed according to the vertex data; Traversing the rectangular faces according to the normal index information, and determining two-dimensional coordinate extrema of the traversed rectangular faces according to the vertex data; Storing the two-dimensional coordinate extrema and the normal index information of the rectangular faces in a preset order to compress the vertex data, obtaining compressed voxel model data; The obtaining the normal index information corresponding to each of a plurality of rectangular faces in the voxel model to be compressed according to the vertex data includes: Creating a normal slice table with a preset structure; Calculating the directions of the normal vectors of all the rectangular faces in the voxel model to be compressed according to the vertex data, and the normal coordinates of each rectangular face; Counting the number of rectangular faces corresponding to each normal coordinate along the directions of the respective normal vectors and recording same in the normal slice table to obtain the normal index information; Calculating the normal vector of a rectangular face according to the vertex coordinates and vertex normal vectors in the vertex data; Obtaining the coordinate values of each rectangular face along the directions of the respective normal vectors, and using the coordinate values as the normal coordinates of each rectangular face; Storing the normal coordinates in the direction of each normal vector, and the number of rectangular faces corresponding to each normal coordinate in a preset order in the normal slice table.
2. The compression method of the voxel model according to claim 1, wherein The traversing the rectangular faces according to the normal index information, and determining two-dimensional coordinate extrema of the traversed rectangular faces according to the vertex data includes: Traversing the rectangular faces in sequence according to the normal index information, and determining the minimum coordinate pair and the maximum coordinate pair of the currently traversed rectangular face in the two-dimensional plane according to the vertex data when each traversal result is obtained, to obtain corresponding two-dimensional coordinate extrema.
3. The compression method of the voxel model according to claim 1, characterized in that, The storing the two-dimensional coordinate extrema and the normal index information of the rectangular faces in a preset order to compress the vertex data, obtaining compressed voxel model data includes: Sequentially writing the two-dimensional coordinate extrema of each rectangular face into a preset data array according to the data storage order of the normal index information to compress the vertex data; Outputting the written preset data array and the normal index information as compressed voxel model data.
4. A compression device for a voxel model, characterized in that, Comprising: A vertex obtaining module, configured to obtain vertex data of a voxel model to be compressed; A normal slice module, configured to obtain normal index information corresponding to each of a plurality of rectangular faces in the voxel model to be compressed according to the vertex data; A traversing module, configured to traverse the rectangular faces according to the normal index information, and determine two-dimensional coordinate extrema of the traversed rectangular faces according to the vertex data; A compression storage module, configured to store the two-dimensional coordinate extrema and the normal index information of the rectangular faces in a preset order to compress the vertex data, obtaining compressed voxel model data; The obtaining the normal index information corresponding to each of a plurality of rectangular faces in the voxel model to be compressed according to the vertex data includes: Creating a normal slice table with a preset structure; Calculate the directions of the normal vectors of all rectangular faces in the voxel model to be compressed and the normal coordinates of each rectangular face according to the vertex data; Count the number of rectangular faces corresponding to each normal coordinate along the directions of the respective normal vectors and record them in the normal slice table to obtain the normal index information; Calculate the normal vectors of the rectangular faces based on the vertex coordinates and vertex normal vectors in the vertex data; Obtain the coordinate values of each rectangular face along the directions of the respective normal vectors and use the coordinate values as the normal coordinates of each rectangular face; Store the normal coordinates in the directions of each normal vector and the number of rectangular faces corresponding to each normal coordinate in the normal slice table in a preset order.
5. A decompression method for the voxel model according to claim 1, characterized in that Include: Obtain the compressed voxel model data; Read the normal index information and two-dimensional coordinate extrema of the rectangular faces in the compressed voxel model data in a preset order; Decompress and calculate the corresponding vertex data based on the normal index information and the two-dimensional coordinate extrema of the rectangular faces; Construct the corresponding voxel model based on the decompressed vertex data.
6. The decompression method of the voxel model according to claim 5, wherein The step of reading the normal index information and two-dimensional coordinate extrema of the rectangular faces in the compressed voxel model data in a preset order includes: After parsing the compressed voxel model data, obtain a preset data array and the normal index information of the rectangular faces, where the preset data array is used to store the two-dimensional coordinate extrema of the rectangular faces; Read the two-dimensional coordinate extrema of each rectangular face in the preset data array in the data storage order of the normal index information to obtain the two-dimensional coordinate extrema of all rectangular faces.
7. A decompression device for the voxel model according to claim 1, characterized in that, Include: A compressed data acquisition module for obtaining the compressed voxel model data; A reading module for reading the normal index information and two-dimensional coordinate extrema of the rectangular faces in the compressed voxel model data in a preset order; A decompression calculation module for decompressing and calculating the corresponding vertex data based on the normal index information and the two-dimensional coordinate extrema of the rectangular faces; A construction module for constructing the corresponding voxel model based on the decompressed vertex data.
8. A compression and decompression system for a voxel model, characterized in that, The system includes at least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor is enabled to execute the compression method of the voxel model according to any one of claims 1-3, or execute the decompression method of the voxel model according to claims 5-6.
9. A non-volatile computer-readable storage medium, characterized in that, The non-volatile computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by one or more processors, the one or more processors can be enabled to execute the compression method of the voxel model according to any one of claims 1-3, or execute the decompression method of the voxel model according to claims 5-6.
Citation Information
Patent Citations
Three-dimensional model coding method and device and terminal
CN112802134A