Image set generation method and device, electronic equipment and storage medium
By obtaining the texture rectangle collection, adjusting the initial texture atlas and obtaining the target texture atlas according to the preset size, the problem of resource waste in the atlas generation is solved, and more efficient atlas space utilization and calculation optimization is achieved.
Patent Information
- Application Number
- CN202510411741.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-07-25
AI Technical Summary
The prior art fails to effectively utilize image resources when generating image albums, resulting in the size of the image album being much larger than the image size, resulting in waste of resources.
By obtaining the texture rectangle collection, adjust the size of the initial texture atlas to accommodate all texture rectangles, and obtain the target texture atlas according to the preset size set, and optimize the use of the atlas space using the fill adjustment algorithm.
Reduces redundant space for texture rectangle filling, improves the utilization rate of atlas space, meets the requirements of the graphics engine, and reduces the amount of calculation.
Smart Images

Figure CN120374766A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer image processing, and more particularly, to a method, apparatus, electronic device, and storage medium for generating an atlas. Background Art
[0002] With the continuous development of software applications, the functions of software applications are also constantly enriched. One problem brought about by the enrichment of software functions is that the data scale of the image resources it contains continues to expand. The prior art usually adopts the method of an atlas to manage the huge image resources in software applications. In the conventional atlas generation technology, a large atlas is directly generated, and then the pictures are stored in the atlas in sequence without specific storage rules, resulting in the size of the atlas being much larger than the size of the pictures, thus causing a waste of size resources. Summary of the Invention
[0003] The present invention aims to overcome at least one defect of the above prior art, and provides a method, apparatus, electronic device, and storage medium for generating an atlas, which is used to effectively reduce the waste of size resources caused when generating an atlas.
[0004] According to a first aspect of the present application, there is provided a method for generating an atlas, the method for generating an atlas comprising:
[0005] Obtain a set of texture maps to be processed; the set of texture maps to be processed includes a number of texture images to be processed;
[0006] According to the set of texture maps to be processed, obtain a set of texture rectangles; the set of texture rectangles includes texture rectangles corresponding to the texture images to be processed in the set of texture maps to be processed;
[0007] Obtain an initial texture atlas according to the set of texture rectangles;
[0008] Use the set of texture rectangles as a set of textures to be filled, use the initial texture atlas as an atlas to be adjusted, and perform filling and adjustment on the atlas to be adjusted according to the set of textures to be filled, to obtain an intermediate texture atlas and a filling position information set; the filling position information set includes the filling position information of each texture rectangle in the atlas to be adjusted;
[0009] Obtain a target texture atlas according to a preset size set and the atlas size of the intermediate texture atlas;
[0010] Fill each texture image to be processed into the target texture atlas according to the filling position information set.
[0011] Optionally, the obtaining the initial texture atlas according to the set of texture rectangles specifically includes:
[0012] Statistically calculate the total area of all the texture rectangles in the texture rectangle set, and obtain the initial size according to the total area;
[0013] Construct the initial texture atlas according to the initial size.
[0014] Optionally, obtaining the target texture atlas according to the preset size set and the atlas size of the intermediate texture atlas specifically includes:
[0015] Obtain the target size closest to the atlas size of the intermediate texture atlas from the preset size set;
[0016] Obtain the target size atlas according to the target size;
[0017] Obtain the ratio of the target size to the atlas size;
[0018] Obtain the target texture atlas according to the ratio.
[0019] Optionally, obtaining the target texture atlas according to the ratio specifically includes:
[0020] If the ratio is greater than or equal to the preset ratio, use the target size atlas as the target texture atlas and maintain the filling position information set;
[0021] If the ratio is less than the preset ratio, reduce each texture rectangle in the texture rectangle set according to the ratio, use the reduced texture rectangle set as the texture set to be filled, use the target size atlas as the atlas to be adjusted, and perform filling adjustment on the atlas to be adjusted according to the texture set to be filled to obtain the target texture atlas and the updated filling position information set.
[0022] Optionally, the atlas generation method further includes adding atlas attribute information to the target texture atlas;
[0023] The atlas attribute information includes the texture format and atlas name of the target texture atlas, and / or the image names of the corresponding texture images to be processed and the corresponding filling position information, and / or the target size, and / or the atlas size, and / or the ratio of the target size to the atlas size.
[0024] Optionally, performing filling adjustment on the atlas to be adjusted according to the texture set to be filled specifically includes:
[0025] Divide the free area in the atlas to be adjusted, and obtain the corresponding free area according to the sizes of the texture rectangles in the texture set to be filled for filling; during the filling process, expand the size of the atlas to be adjusted according to the correspondence between the free area and the texture rectangles.
[0026] Optionally, the step of dividing the free area in the atlas to be adjusted and obtaining the corresponding free area according to the sizes of the texture rectangles in the texture set to be filled for filling specifically includes:
[0027] Match the smallest free area that meets the filling size in the atlas to be adjusted according to the filling sizes of the texture rectangles in the texture set to be filled; for each texture rectangle, during the matching process:
[0028] If the free area cannot be matched, expand the size of the atlas to be adjusted, re-obtain the free area according to the expanded atlas to be adjusted, and re-match the smallest free area that meets the filling size for each texture rectangle in the expanded atlas to be adjusted;
[0029] If the free area is matched, fill the texture rectangle into a preset corner of the matched free area, divide the remaining area after filling the matched free area as the free area, and continue to match the free area with the texture rectangles in the texture set to be filled that have not been matched.
[0030] According to the second aspect of the present application, there is provided an atlas generation device, where the atlas generation device includes:
[0031] A texture map acquisition module, configured to acquire a set of texture maps to be processed; the set of texture maps to be processed includes a number of texture images to be processed;
[0032] A texture rectangle acquisition module, configured to acquire a set of texture rectangles according to the set of texture maps to be processed; the set of texture rectangles includes the texture rectangles corresponding to the texture images to be processed in the set of texture maps to be processed;
[0033] An initial atlas acquisition module, configured to acquire an initial texture atlas according to the set of texture rectangles;
[0034] An intermediate atlas acquisition module, configured to use the set of texture rectangles as the texture set to be filled, use the initial texture atlas as the atlas to be adjusted, fill and adjust the atlas to be adjusted according to the texture set to be filled, and obtain an intermediate texture atlas and a filling position information set; the filling position information set includes the filling position information of each texture rectangle in the atlas to be adjusted;
[0035] A target atlas acquisition module, configured to acquire a target texture atlas according to a preset size set and the atlas size of the intermediate texture atlas;
[0036] An image filling module, configured to fill each of the to-be-processed texture images into the target texture atlas according to a filling position information set.
[0037] According to a third aspect of the present application, there is provided an electronic device, including:
[0038] A memory, configured to store one or more computer programs;
[0039] A processor, when the one or more computer programs are executed by the processor, implementing the atlas generation method described in the first aspect above.
[0040] According to a fourth aspect of the present application, there is provided a computer-readable storage medium, where the computer-readable storage medium stores computer instructions, and the computer instructions are used to implement the atlas generation method described in the first aspect above when executed by a processor.
[0041] Based on any of the above aspects, an atlas generation method, apparatus, electronic device, and computer storage medium provided by the embodiments of the present application obtain the to-be-processed texture map set including the to-be-processed texture images, obtain a texture rectangle set according to the to-be-processed texture map set, and obtain an initial texture atlas according to the texture rectangle set, so that the size of the initial texture atlas can match the sizes of the texture rectangles in the texture rectangle set, thereby being able to reduce the redundant space for texture rectangle filling to a certain extent, and also being able to reduce the computational amount of subsequent adjustment calculations in this embodiment; in addition, through the filling adjustment operation, when each of the texture rectangles in the texture rectangle set is filled, while adjusting the initial texture atlas, the filling positions of the texture rectangles can also be adjusted, thereby being able to make more full use of the atlas space; further, a target texture atlas is obtained according to the preset size set, so that the target texture atlas can better meet the requirements of the graphics engine and make the filling of the texture rectangles more in line with the actual scenario requirements. Description of the Drawings
[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present application, and those of ordinary skill in the art can obtain other drawings without creative efforts based on these drawings.
[0043] Figure 1It is a schematic application scenario diagram of the atlas generation method provided in this embodiment.
[0044] Figure 2 It is a flowchart of the atlas generation method provided in this embodiment.
[0045] Figure 3 It is a schematic diagram of the sub-steps of step S3 provided in this embodiment.
[0046] Figure 4 It is a schematic diagram of the sub-steps of step S5 provided in this embodiment.
[0047] Figure 5 It is a schematic diagram of the sub-steps of step S54 provided in this embodiment.
[0048] Figure 6 It is a schematic diagram of the steps of filling adjustment provided in this embodiment.
[0049] Figure 7 It is a schematic diagram of the functional modules of the atlas generation device provided in this embodiment.
[0050] Figure 8 It is a schematic diagram of the structure of the electronic device provided in this embodiment. Detailed implementation manners
[0051] The accompanying drawings of this application are only for illustrative purposes and should not be construed as a limitation to this application. For better illustration of the following embodiments, some components in the drawings are omitted, enlarged or reduced, and do not represent the dimensions of the actual products; for those skilled in the art, it is understandable that some well-known structures and their descriptions in the drawings may be omitted.
[0052] In order to enable those skilled in the art to better understand the solutions of this application, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of this application.
[0053] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0054] With the continuous development of software applications, the functions of software applications are also constantly enriched. One problem caused by the enrichment of software functions is that the data scale of the image resources it contains is constantly expanding, especially for game software. As the content of game functions is continuously enriched, the texture resources of game software will continue to increase, making the size of game software continue to increase accordingly.
[0055] Existing technologies usually use atlases to manage huge image resources in software applications. In conventional atlas generation technologies, they are mainly generated by built-in game engine or third-party atlas tools. These game engines or third-party atlases will directly generate a large atlas, and then store the pictures in the atlas one by one. Since there are no specific storage rules in the process of storing pictures in the atlas, the size of the atlas will be much larger than the size of the picture, which will cause a waste of size resources.
[0056] This embodiment provides a technical solution that can solve the above-mentioned problem. The specific implementation methods of this application are described in detail below in conjunction with the accompanying drawings.
[0057] For example, a schematic diagram of an application scenario of a method for generating an atlas provided in an embodiment of the present application is provided. Figure 1 As shown, the application scenario includes at least a server 100 and a terminal 200 that can communicate with the server 100, the server 100 has image data receiving, image data processing and atlas generation functions; the terminal 200 has image data receiving, image data processing and atlas generation functions, and also supports receiving image data and atlas data from the server 100.
[0058] It is understandable that the server 100 can be an independent electronic device or a cluster of multiple electronic devices; the terminal 200 can be a smart phone terminal, a personal computer, a tablet computer, a car terminal, etc., but is not limited thereto.
[0059] In an implementable manner, the server 100 and the terminal 200 can respectively execute a method for generating an atlas provided in an embodiment of the present application. Alternatively, optionally, a part of the method for generating an atlas provided in an embodiment of the present application is executed in the server 100, and a part is executed in the terminal 200.
[0060] As Figure 2 shown, an embodiment of the present application provides a method for generating an atlas, which may include the following steps:
[0061] S1: Obtain a set of texture maps to be processed; the set of texture maps to be processed contains several texture images to be processed;
[0062] In this embodiment, a set of texture maps to be processed containing several texture images to be processed can be obtained through an image input interface or a file reading tool. Specifically, the set of texture maps to be processed can be a folder or a file directory storing the texture images to be processed.
[0063] When it is necessary to generate an atlas of a corresponding atlas type, a folder list or a file directory where the image resources are stored can be read through an image input interface or a file reading tool, and all the texture images to be processed in the folder or file directory corresponding to the atlas type are loaded to generate the set of texture maps to be processed.
[0064] In a specific implementation, in order to better implement the standardized management of atlas resources, the texture images to be processed can be pre-stored in one or more corresponding folders according to their respective atlas types, or recorded in one or more corresponding file directories, and the corresponding folders or file directories are named according to the atlas type for convenient invocation as an input source. Exemplarily, all the texture images to be processed of the general resources are saved in a folder, and the folder is named common.
[0065] S2: Obtain a set of texture rectangles according to the set of texture maps to be processed; the set of texture rectangles contains the texture rectangles corresponding to the respective texture images in the set of texture maps to be processed;
[0066] It is understandable that in order to better store each of the to-be-processed texture images, it is necessary to obtain the sizes of each of the to-be-processed texture images. At the same time, in order to standardize the sizes of the to-be-processed texture images, corresponding texture rectangles are generated according to the to-be-processed texture images. The texture rectangle is the smallest rectangle structure that contains the to-be-processed texture image. In this embodiment, the texture rectangle can use a rectangle data structure to record the width, height of the texture rectangle, and the image content of the corresponding to-be-processed texture image. Exemplarily, if the size of Image A is 128×256 pixels, the data structure of the texture rectangle can be set as RectA = {width = 256, height = 512, data = Image A}.
[0067] S3: Obtain an initial texture atlas according to the set of texture rectangles;
[0068] In this embodiment, the initial texture atlas can be set as a square texture atlas;
[0069] It is understandable that the obtained texture atlas needs to be able to accommodate all the texture rectangles in the set of texture rectangles. In the most ideal case, the sizes of all the texture rectangles in the set of texture rectangles are the same, so that each of the texture rectangles can be placed in the obtained texture atlas in sequence. In fact, the sizes of the to-be-processed texture images in the set of to-be-processed texture images may be different, so the sizes of the corresponding texture rectangles are also different, and the texture rectangles cannot be regularly stored in the texture atlas.
[0070] In this embodiment, the size of the texture atlas will be adaptively adjusted during the storage process. Therefore, in order to reduce the computational complexity required for the adjustment in this embodiment, the initial texture atlas is obtained in the above-mentioned most ideal case. Specifically, as Figure 3 shown, the obtaining of the initial texture atlas can include the following steps:
[0071] S31: Statistically calculate the total area of all the texture rectangles in the set of texture rectangles, and obtain an initial size according to the total area;
[0072] Specifically, in this step, calculate the total area of all the texture rectangles in the set of texture rectangles. After calculating the total area of all the texture rectangles, take the integer part of the square root of the total area to obtain the initial size. Exemplarily, if the calculated total area is 3,000,000 pixels, the initial size can be set as 1732×1732.
[0073] In one embodiment, in order to better match the conventional size of the image processing engine, after taking the square root of the sum, the obtained square root is rounded up to the nearest power of 2, and this nearest power of 2 is used as the initial size. Exemplarily, if the calculated total area is 3,000,000, the initial size can be set to 2048×2048.
[0074] S32: Construct the initial texture atlas according to the initial size.
[0075] S4: Use the set of texture rectangles as the set of textures to be filled, and the initial texture atlas as the atlas to be adjusted. Fill and adjust the atlas to be adjusted according to the set of textures to be filled, to obtain an intermediate texture atlas and a set of filling position information; the set of filling position information includes the filling position information of each texture rectangle in the atlas to be adjusted.
[0076] In this embodiment, the intermediate texture atlas corresponds to the initial texture atlas and can be set as a square texture atlas.
[0077] As described above, since each texture rectangle in the set of texture rectangles is not necessarily regular, the initial texture atlas obtained in step S3 may not be able to completely accommodate all the texture rectangles. Therefore, it is necessary to adjust the size of the initial texture atlas. For this purpose, this embodiment designs a filling and adjustment algorithm for adjusting the input image set and atlas. The filling and adjustment algorithm is specifically as follows:
[0078] Divide the idle area in the atlas to be adjusted, and obtain the corresponding idle area according to the size of each texture rectangle in the set of textures to be filled for filling; during the filling process, expand the size of the atlas to be adjusted according to the corresponding situation between the idle area and the texture rectangle.
[0079] Specifically, the filling process can specifically be:
[0080] According to the filling size of each texture rectangle in the set of textures to be filled, match the smallest idle area in the atlas to be adjusted that meets the filling size; among them, for each texture rectangle, during the matching process:
[0081] If the idle area cannot be matched, expand the size of the atlas to be adjusted, and re-obtain the idle area according to the expanded atlas to be adjusted, and re-match the smallest idle area that meets the filling size for each texture rectangle in the expanded atlas to be adjusted.
[0082] If the idle area is matched, fill the texture rectangle to the preset corner of the matched idle area, divide the remaining area after filling the matched idle area as the idle area, and continue to match the texture rectangles in the texture set to be filled with the idle area.
[0083] It can be understood that dividing the idle area in the atlas to be adjusted is a dynamic process. In the initial state, the entire atlas to be adjusted can be used as the idle area, then each texture rectangle is matched with the idle area, and new idle areas are continuously divided according to the matching results, or the atlas to be adjusted is expanded and then the idle area is divided until the optimal division of the idle area that can meet the sizes of each texture rectangle is found.
[0084] In a specific implementation manner, as Figure 6 shown, the above filling and adjustment algorithm may specifically include:
[0085] A1: Create and initialize the available idle area set and the filling position information set;
[0086] The available idle area set is used to manage the idle areas divided according to the atlas to be adjusted; it can be understood that initializing the available idle area set and the filling position information set is to avoid the influence of the idle areas and filling position information recorded in the previous traversal operations, so as to more accurately obtain the filling position information.
[0087] A2: Create an idle area with the same size as the atlas to be adjusted, and add the idle area to the available idle area set;
[0088] A3: Traverse each texture rectangle in the texture set to be filled;
[0089] A4: According to the traversed texture rectangle, determine whether there is an idle area in the available idle area set whose size is greater than or equal to the size of the texture rectangle;
[0090] A5: If there is no such idle area, increase the size of the atlas to be adjusted by a preset standard size value, and execute step A1; if there is such an idle area, obtain the idle area as the target idle area, and execute step A6;
[0091] In this embodiment, the standard size value can be set as a positive integer or a positive decimal. The standard size value can be set according to the sizes of the texture rectangles in the atlas to be adjusted and the texture set to be filled. Specifically, different size ranges can be set, and corresponding standard size values can be set for the corresponding size ranges. During actual use, according to the size range in which the size of the atlas to be adjusted falls, the corresponding standard size value is obtained. It can be understood that the larger the standard size value is set, the lower the calculation amount of the filling adjustment, and the worse the filling effect of the texture rectangle. On the contrary, the smaller the standard size value is set, the better the filling effect of the texture rectangle, and the larger the calculation amount of the filling adjustment. Therefore, it needs to be set according to the sizes of the texture rectangles in the atlas to be adjusted and the texture set to be filled. A6: Remove the target free area from the set of available free areas;
[0092] A7: Place the traversed texture rectangle at a preset corner of the target free area, and obtain the covered area where the texture rectangle is placed in the target free area;
[0093] In a specific implementation manner, the preset corner can be set as any one of the four corners of the rectangle corresponding to the free area, such as the upper left corner of the rectangle corresponding to the free area, and the preset corner remains fixed after being determined; by placing the texture rectangle at the preset corner of the free area, the space of the free area can be better utilized, and thus the division of the free area can be better realized;
[0094] A8: Obtain the filling position information of the covered area relative to the atlas to be adjusted, and add the filling position information to the filling position information set;
[0095] In this embodiment, the filling position information can be the coordinate information of the covered area relative to the atlas to be adjusted. Specifically, a coordinate system can be established with the preset corner of the atlas to be adjusted, and the coordinates of the four corners of the covered area are obtained respectively, and the coordinates of the four corners of the obtained covered area are used as the filling position information of the covered area and added to the filling position information set.
[0096] A9: Divide the covered area from the target free area, and divide the remaining area after division into a rectangular first free area and a second free area;
[0097] Specifically, in this embodiment, after dividing the covered area, the remaining area can exactly be divided into two rectangles. In this embodiment, the left / right rectangular area of the covered area can be divided into the first free area, and the upper / lower rectangular area of the covered area and the first free area can be divided into the second free area. Then, the size of the first free area can be expressed as FiFreeRect = (FreeRect.Width - Rect.Width, Rect.Height), where FiFreeRect is the size of the first free area, FreeRect.Width is the width of the corresponding target free area, Rect.Width is the width of the covered area, and Rect.Height is the height of the covered area. Correspondingly, the size of the second free area can be expressed as ScFreeRect = (FreeRect.Width, FreeRect.Height - Rect.Height).
[0098] After dividing the first free area and the second free area, according to the division situation of the first free area and the second free area, record the filling position information of the first free area and the second free area relative to the atlas to be adjusted. In this embodiment, the filling position information of the first free area and the second free area can be the coordinate information relative to the atlas to be adjusted. Specifically, a coordinate system can be established with the preset corner of the atlas to be adjusted, and the coordinates of the four corners of the first free area and the second free area are obtained respectively. The coordinates of the four corners of the first free area and the second free area obtained are respectively recorded as the filling position information of the first free area and the second free area. By recording the filling position information of each free area, it is convenient to better locate the texture rectangle during the subsequent filling and placement process.
[0099] A10: Add the first free area and the second free area to the available free area set as the free areas respectively;
[0100] A11: Traverse the remaining texture rectangles in the texture set to be filled, and repeat the steps of A4 - A11 until the texture set to be filled is completely traversed, and output the atlas to be adjusted with increased size and the filling position information set.
[0101] It is understandable that the above steps continuously traverse the texture rectangles in the texture set to be filled, query the free areas in the available free area set that can place the texture rectangles. When a free area that can place the texture rectangle is found, the texture rectangle is placed in the free area, and the covered area where the texture rectangle is placed in the free area is obtained, and the covered area is split off from the free area, indicating that the texture rectangle has been placed in the covered area. Then, the remaining area of the free area is split into a first free area and a second free area as new free areas, so that the free areas in the available free area set can be continuously enriched;
[0102] During the splitting process, since the covered area obtained by each split matches the size of the corresponding texture rectangle, and the first free area and the second free area are split off from the covered area as new free areas, therefore, when a free area that can place the texture rectangle is found, it means that there is still space in the atlas to be adjusted to accommodate the texture rectangle. On the contrary, when no free area that can place the texture rectangle is found in the available free area set, it means that the atlas to be adjusted can no longer accommodate the texture rectangle. Therefore, it is necessary to expand the atlas to be adjusted, and then re-traverse the texture set to be filled to re-divide the expanded atlas to be adjusted. In the steps of filling and adjusting, each split is performed according to the size of the corresponding texture rectangle. Therefore, the optimal filling and placement situation of each texture rectangle can be effectively found, the space of the atlas to be adjusted can be greatly utilized, the size of the atlas to be adjusted can be reduced, and size waste can be avoided.
[0103] S5: Obtain a target texture atlas according to a preset size set and the atlas size of the intermediate texture atlas;
[0104] In this embodiment, as Figure 4 shown, the step S5 may specifically include the following steps:
[0105] S51: Obtain a target size closest to the atlas size of the intermediate texture atlas from the preset size set;
[0106] S52: Obtain a target size atlas according to the target size;
[0107] S53: Obtain the ratio of the target size to the atlas size;
[0108] S54: Obtain the target texture atlas according to the ratio.
[0109] In this embodiment, the target size atlas corresponds to the intermediate texture atlas and can be set as a square texture atlas. The preset size set may include side length values that are powers of 2, such as 32, 64, 128, 256, 512, 1024, and 2048. Therefore, step S51 is specifically to select from the size set the side length value that is closest to the width and height in the atlas size to form the target size. It can be understood that setting the side length values in the size set as powers of 2 enables the obtained target size to meet the requirements of POT (Power of Two) texture sizes, thereby being able to be compatible with more engines and enhancing the versatility of the atlas generation method in this embodiment. Moreover, processing atlases with non-POT texture sizes requires additional memory and also reduces the sampling efficiency of the graphics processing unit for the atlas.
[0110] Exemplarily, if the atlas size of the intermediate texture atlas is 396×560, since it does not meet the requirements of POT texture sizes and cannot be compressed into formats such as DX1, DX5, and ASTC on the PC platform, the corresponding closest side length value 512 is obtained from the size set, and the target size is 512×512, making the target size meet the requirements of POT texture sizes.
[0111] As Figure 5 shown, step S54 may specifically include the following steps:
[0112] B1: If the ratio is greater than or equal to the preset ratio, use the target size atlas as the target texture atlas and maintain the filling position information set;
[0113] B2: If the ratio is less than the preset ratio, reduce each texture rectangle in the texture rectangle set according to the ratio, use the reduced texture rectangle set as the texture set to be filled, use the target size atlas as the atlas to be adjusted, and perform filling adjustment on the atlas to be adjusted according to the texture set to be filled to obtain the target texture atlas and the updated filling position information set.
[0114] Specifically, in step B2, use the reduced texture rectangle set as the texture set to be filled, use the target size atlas as the atlas to be adjusted, and call the above filling adjustment algorithm again, that is, steps A1 - A11, to update the filling position information set, which will not be elaborated further here.
[0115] Preferably, in this embodiment, the preset ratio can be set to 1. It can be understood that if the ratio of the target size to the atlas size is greater than or equal to 1, it means that the obtained target size atlas can accommodate the intermediate texture atlas, and thus can be compatible with the current filling position information set; if the ratio of the target size to the atlas size is less than 1, at this time the target size atlas cannot be compatible with the current filling position information set. Therefore, each texture rectangle in the texture rectangle set needs to be correspondingly reduced according to the ratio. At the same time, according to the reduced texture rectangle set and the target size atlas, the filling position information of each texture rectangle in the target size atlas is re-obtained.
[0116] S6: Fill each of the to-be-processed texture images into the target texture atlas according to the filling position information set.
[0117] It can be understood that if the ratio obtained in step S53 is greater than or equal to the preset ratio, the filling position information set obtained in step S4 is maintained in step B1, and then in this step S6, each of the to-be-processed texture images is filled into the target texture atlas by using this filling position information set; on the contrary, if the ratio obtained in step S53 is less than the preset ratio, the filling position information set obtained in step S4 is updated in step B2, and then in this step S6, each of the to-be-processed texture images is filled into the target texture atlas by using the updated filling position information set.
[0118] Optionally, the atlas generation method of this embodiment may further include:
[0119] Adding atlas attribute information to the target texture atlas;
[0120] Specifically, the atlas attribute information may include the texture format and atlas name of the target texture atlas, and / or the image names of the corresponding to-be-processed texture images and the corresponding filling position information, and / or the target size, and / or the atlas size, and / or the ratio of the target size to the atlas size.
[0121] In a specific implementation manner, the data structure of the target texture atlas can be constructed, and the texture format and atlas name of the target texture atlas, the ratio, the target size, the atlas size of the intermediate texture atlas, the image names of the corresponding to-be-processed texture images and the corresponding filling position information, etc. are written into the data structure as required according to the actual situation to realize the recording of the atlas attribute information. At the same time, by recording the atlas attribute information of the target texture atlas, the packaging of the atlas and the management and call of the atlas resources can be better realized.
[0122] Such as Figure 7As shown in the figure, the embodiment of the present application also provides an atlas generation device. Optionally, the atlas generation device may include:
[0123] A texture map acquisition module 11, configured to acquire a set of texture maps to be processed; the set of texture maps to be processed includes several texture images to be processed;
[0124] In this embodiment, the texture map acquisition module 11 can be used to execute Figure 2 The step S1 shown in the figure. For the specific description of the texture map acquisition module 11, reference can be made to the description of the step S1.
[0125] A texture rectangle acquisition module 12, configured to acquire a set of texture rectangles according to the set of texture maps to be processed; the set of texture rectangles includes the texture rectangles corresponding to each of the texture images to be processed in the set of texture maps to be processed;
[0126] In this embodiment, the texture rectangle acquisition module 12 can be used to execute Figure 2 The step S2 shown in the figure. For the specific description of the texture rectangle acquisition module 12, reference can be made to the description of the step S2.
[0127] An initial atlas acquisition module 13, configured to acquire an initial texture atlas according to the set of texture rectangles;
[0128] In this embodiment, the initial atlas acquisition module 13 can be used to execute Figure 2 The step S3 shown in the figure. For the specific description of the initial atlas acquisition module 13, reference can be made to the description of the step S3.
[0129] An intermediate atlas acquisition module 14, configured to use the set of texture rectangles as a set of textures to be filled, use the initial texture atlas as an atlas to be adjusted, and perform filling and adjustment on the atlas to be adjusted according to the set of textures to be filled, to obtain an intermediate texture atlas and a filling position information set; the filling position information set includes the filling position information of each texture rectangle in the atlas to be adjusted;
[0130] In this embodiment, the intermediate atlas acquisition module 14 can be used to execute Figure 2 The step S4 shown in the figure. For the specific description of the intermediate atlas acquisition module 14, reference can be made to the description of the step S4.
[0131] A target atlas acquisition module 15, configured to acquire a target texture atlas according to a preset size set and the atlas size of the intermediate texture atlas;
[0132] In this embodiment, the target atlas acquisition module 15 can be used to execute Figure 2For the specific description of step S5 shown, reference may be made to the description of step S5 regarding the target atlas acquisition module 15.
[0133] An image filling module 16 is configured to fill each of the to-be-processed texture images into the target texture atlas according to the filling position information set.
[0134] In this embodiment, the image filling module 16 can be used to execute Figure 2 step S6 shown. For the specific description of the image filling module 16, reference may be made to the description of step S6.
[0135] Optionally, in this embodiment, the atlas generation device may further include a filling adjustment module 17 for performing filling adjustment;
[0136] In this embodiment, the filling adjustment module 17 can be used to execute Figure 6 steps A1 - A11 shown. For the specific description of the filling adjustment module 17, reference may be made to the description of steps A1 - A11.
[0137] It can be understood that the above device embodiments and the above method embodiments can correspond to each other. Similar descriptions in the device embodiments can refer to the method embodiments. To avoid repetition, details are not elaborated here. An atlas generation device provided in an embodiment of the present application can execute an atlas generation method provided in any embodiment of the present application, and has corresponding functional modules and beneficial effects for executing the method. The functional modules of the atlas generation device can be implemented in hardware form, can be implemented by instructions in software form, or can also be implemented by a combination of hardware and software modules.
[0138] Specifically, each step of the method embodiment of the present application can be completed by the integrated logic circuit in the hardware of the processor and / or instructions in software form. Combining the steps of the atlas generation method in the embodiment of the present application can be directly embodied as being completed by the hardware - encoded processor, or completed by a combination of the hardware and software modules in the encoded processor. Optionally, the software module can be located in a random access memory, read - only memory, programmable read - only memory, flash memory, electrically erasable programmable memory, register, and other storage media are all possible. The storage media is located in the memory, and the processor reads the information in the memory and combines its hardware to complete the steps in the above method embodiments.
[0139] An embodiment of the present application provides an electronic device, whose structure is as Figure 8 shown. The electronic device can be the server 100 or the terminal 200 shown in this embodiment Figure 1 shown.
[0140] As Figure 8As shown, the electronic device includes a memory 21, a processor 22, a communication module 23, an input / output interface 24, etc. Optionally, the memory 21, the processor 22, the communication module 23, and the input / output interface 24 can be connected and communicate through a bus 25.
[0141] The memory 21 is used to store one or more computer programs and transmit the code of the computer programs to the processor 22; when the one or more computer programs are executed by the processor 22, the atlas generation method in the embodiments of the present application is implemented.
[0142] Optionally, the electronic device can be connected to a network through the communication module 23 to communicate with other devices, such as terminals or servers, through the network to achieve data interaction. The electronic device can be various forms of digital computers, for example, a desktop computer, a server, a workbench, a mainframe computer, or other types of computers. The electronic device can also be various forms of mobile terminals, for example, a smart phone, a tablet computer, a wearable device (such as a helmet, glasses, a watch, etc.), and other similar mobile terminals.
[0143] Optionally, the electronic device can be connected to the required input / output devices, such as a keyboard, a display device, etc., through the input / output interface 24. The electronic device itself can have a display device and can also externally connect other display devices through the input / output interface 24. Optionally, a storage device, such as a hard disk, etc., can also be connected through the input / output interface 24 to store the data in the electronic device into the storage device, or read the data in the storage device, and can also store the data in the storage device into the memory 21. It can be understood that the input / output interface 24 can be a wired interface or a wireless interface. According to different actual application scenarios, the devices connected to the input / output interface 24 can be components of the electronic device or external devices connected to the electronic device when needed.
[0144] Optionally, the memory 21 can be a volatile memory and / or a non-volatile memory. The volatile memory can be a random access memory, etc., and the non-volatile memory can be a read-only memory, a programmable read-only memory, an erasable programmable read-only memory, an electrically erasable programmable read-only memory, or a flash memory, etc.
[0145] Optionally, the computer program stored in the processor 22 may be divided into one or more modules, which are stored in the memory 21 and executed by the processor 22 to complete the method provided by the present embodiment itself. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, and the computer program instruction segments are used to describe the execution process of the computer program in the electronic device.
[0146] Optionally, the processor 22 may be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the processor 22 include, but are not limited to, a central processing unit, a graphics processing unit, a digital signal processor, various dedicated artificial intelligence computing chips, various processors running machine learning model algorithms, and may also be any suitable controller, microcontroller, processor, etc. The processor 22 executes each method and process of the present embodiment. Exemplarily, such as a method for generating an atlas in an embodiment of the present application.
[0147] Optionally, the bus 25 may include a path for transmitting information. The bus 25 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. According to different functions, the bus 25 may be divided into an address bus, a data bus, a control bus, etc.
[0148] In an alternative implementation, the embodiment of the present application further provides a computer storage medium, on which a computer program is stored. When the computer program is executed by a computer, the computer is enabled to execute the method of the above method embodiment. Part or all of the computer program may be loaded and / or installed on the memory 21 of the electronic device. When the computer program is executed by the processor 22, one or more steps of a method for generating an atlas in an embodiment of the present application may be executed.
[0149] Optionally, the computer-readable storage medium may be a random access memory, a read-only memory, a programmable read-only memory, an erasable programmable read-only memory, an electrically erasable programmable read-only memory, etc.
[0150] Obviously, the above embodiments of the present application are merely examples for clearly illustrating the technical solutions of the present application, rather than limitations on the specific implementation manners of the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the claims of the present application shall be included within the protection scope of the claims of the present application.
Claims
1. A method for generating an atlas, characterized in that, The atlas generation method includes the following steps: Obtain a set of texture maps to be processed; the set of texture maps to be processed contains several texture images to be processed; According to the set of texture maps to be processed, obtain a set of texture rectangles; the set of texture rectangles contains the texture rectangles corresponding to each of the texture images to be processed in the set of texture maps to be processed; Obtain an initial texture atlas according to the set of texture rectangles; Use the set of texture rectangles as the set of textures to be filled, and use the initial texture atlas as the atlas to be adjusted. Fill and adjust the atlas to be adjusted according to the set of textures to be filled to obtain an intermediate texture atlas and a set of filling position information; the set of filling position information includes the filling position information of each texture rectangle in the atlas to be adjusted; Obtain a target texture atlas according to a preset set of sizes and the atlas size of the intermediate texture atlas; Fill each of the texture images to be processed into the target texture atlas according to the set of filling position information.
2. The method for generating an atlas according to claim 1, characterized in that The step of obtaining the initial texture atlas according to the set of texture rectangles specifically includes: Statistically calculate the total area of all the texture rectangles in the set of texture rectangles, and obtain an initial size according to the total area; Construct the initial texture atlas according to the initial size.
3. A method for generating an atlas according to claim 1, characterized in that, The step of obtaining the target texture atlas according to a preset set of sizes and the atlas size of the intermediate texture atlas specifically includes: From the preset set of sizes, obtain the target size that is closest to the atlas size of the intermediate texture atlas; Obtain a target-size atlas according to the target size; Obtain the ratio of the target size to the atlas size; Obtain the target texture atlas according to the ratio.
4. A method for generating an atlas according to claim 3, characterized in that, The step of obtaining the target texture atlas according to the ratio specifically includes: If the ratio is greater than or equal to a preset ratio, use the target-size atlas as the target texture atlas and maintain the set of filling position information; If the ratio is less than the preset ratio, reduce each of the texture rectangles in the set of texture rectangles according to the ratio, use the reduced set of texture rectangles as the set of textures to be filled, use the target-size atlas as the atlas to be adjusted, and fill and adjust the atlas to be adjusted according to the set of textures to be filled to obtain the target texture atlas and an updated set of filling position information.
5. A method for generating an atlas according to claim 3 or 4, characterized in that The atlas generation method further includes adding atlas attribute information to the target texture atlas; The atlas attribute information includes the texture format and atlas name of the target texture atlas, and / or, the image names of the corresponding texture images to be processed and the corresponding filling position information, and / or the target size, and / or the atlas size, and / or the ratio of the target size to the atlas size.
6. A method for generating an atlas according to any one of claims 1-4, characterized in that The step of filling and adjusting the atlas to be adjusted according to the set of textures to be filled specifically includes: Divide idle areas in the atlas to be adjusted, and fill the corresponding idle areas according to the sizes of the texture rectangles in the set of textures to be filled; during the filling process, expand the size of the atlas to be adjusted according to the correspondence between the idle areas and the texture rectangles.
7. A method for generating an atlas according to claim 6, characterized in that, Dividing an idle area in the to-be-adjusted atlas, and obtaining the corresponding idle area for filling according to the sizes of the texture rectangles in the to-be-filled texture set, specifically including: According to the filling sizes of the texture rectangles in the to-be-filled texture set, matching the smallest idle area in the to-be-adjusted atlas that meets the filling size; wherein, for each texture rectangle, during the matching process: If the idle area cannot be matched, expand the size of the to-be-adjusted atlas, and re-obtain the idle area according to the expanded to-be-adjusted atlas, and re-match the smallest idle area that meets the filling size for each texture rectangle in the expanded to-be-adjusted atlas; If the idle area is matched, fill the texture rectangle into a preset corner of the matched idle area, and divide the remaining area after filling the matched idle area as the idle area, and continue to match the idle area with the texture rectangles in the to-be-filled texture set that have not been matched.
8. An atlas generation device, characterized in that, The atlas generation device includes: A texture map acquisition module, configured to acquire a set of to-be-processed texture maps; the set of to-be-processed texture maps includes a plurality of to-be-processed texture images; A texture rectangle acquisition module, configured to acquire a set of texture rectangles according to the set of to-be-processed texture maps; the set of texture rectangles includes the texture rectangles corresponding to the to-be-processed texture images in the set of to-be-processed texture maps; An initial atlas acquisition module, configured to acquire an initial texture atlas according to the set of texture rectangles; An intermediate atlas acquisition module, configured to use the set of texture rectangles as the to-be-filled texture set, use the initial texture atlas as the to-be-adjusted atlas, perform filling adjustment on the to-be-adjusted atlas according to the to-be-filled texture set, and obtain an intermediate texture atlas and a filling position information set; the filling position information set includes the filling position information of each texture rectangle in the to-be-adjusted atlas; A target atlas acquisition module, configured to acquire a target texture atlas according to a preset size set and the atlas size of the intermediate texture atlas; An image filling module, configured to fill each to-be-processed texture image into the target texture atlas according to the filling position information set.
9. An electronic device, characterized in that, Including: A memory, configured to store one or more computer programs; A processor, when the one or more computer programs are executed by the processor, implement a method for generating an atlas according to any one of claims 1-7.
10. A computer-readable storage medium, the computer-readable storage medium stores computer instructions, and the computer instructions are used to cause a processor to implement a method for generating an atlas according to any one of claims 1-7 when executed.