This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender. With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser. Therefore, code that is not yet aware of tiles will just access the default tile as usual. The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9. Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator. The following features are supported so far: - Automatic detection and loading of all tiles when opening the first tile (1001) - Saving all tiles - Adding and removing tiles - Filling tiles with generated images - Drawing all tiles in the Image Editor - Viewing a tiled grid even if no image is selected - Rendering tiled images in Eevee - Rendering tiled images in Cycles (in SVM mode) - Automatically skipping loading of unused tiles in Cycles - 2D texture painting (also across tiles) - 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders) - Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID) - Different resolutions between tiles There still are some missing features that will be added later (see T72390): - Workbench engine support - Packing/Unpacking support - Baking support - Cycles OSL support - many other Blender features that rely on images Thanks to Brecht for the review and to all who tested the intermediate versions! Differential Revision: https://developer.blender.org/D3509
The following 4 steps to adding a new image format to blender, its probably easiest to look at the png code for a clean clear example, animation formats are a bit more complicated but very similar: Step 1: create a new file named after the format for example lets say we were creating an openexr read/writer use openexr.c It should contain functions to match the following prototypes: struct ImBuf *imb_loadopenexr(unsigned char *mem,int size,int flags); /* Use one of the following depending on what's easier for your file format */ short imb_saveopenexr(struct ImBuf *ibuf, FILE myfile, int flags); short imb_saveopenexr(struct ImBuf *ibuf, char *myfile, int flags); /* Used to test if its the correct format int IMB_is_openexr(void *buf); Step 2: Add your hooks to read and write the image format these go in writeimage.c and readimage.c just look at how the others are done Step 3: Add in IS_openexr to blender/source/blender/imbuf/IMB_imbuf_types.h Add in R_openexr to source/blender/makesdna/DNA_scene_types.h Step 4: Add your hooks to the gui. source/blender/src/buttons_scene.c source/blender/src/toets.c source/blender/src/writeimage.c Step 5: edit the following files: blender/source/blender/imbuf/intern/util.c blender/source/blender/src/filesel.c blender/source/blender/src/screendump.c and add your extension so that your format gets recognized in the thumbnails. Step 6: Alter the build process: For cmake you need to edit blender/source/blender/imbuf/CMakeLists.txt and add in your additional files to source_files. If you have any external library info you will also need to add that to the various build processes. Step 7: Its also good to add your image format to: makepicstring in blender/source/blender/blenkernel/intern/image.c