diff options
Diffstat (limited to 'source/blender')
398 files changed, 10255 insertions, 7003 deletions
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index c5c2bc3f3ba..547112ecf66 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -92,9 +92,7 @@ static FontBLF *blf_get(int fontid) int BLF_init(void) { - int i; - - for (i = 0; i < BLF_MAX_FONT; i++) { + for (int i = 0; i < BLF_MAX_FONT; i++) { global_font[i] = NULL; } @@ -111,11 +109,8 @@ void BLF_default_dpi(int dpi) void BLF_exit(void) { - FontBLF *font; - int i; - - for (i = 0; i < BLF_MAX_FONT; i++) { - font = global_font[i]; + for (int i = 0; i < BLF_MAX_FONT; i++) { + FontBLF *font = global_font[i]; if (font) { blf_font_free(font); global_font[i] = NULL; @@ -127,11 +122,8 @@ void BLF_exit(void) void BLF_cache_clear(void) { - FontBLF *font; - int i; - - for (i = 0; i < BLF_MAX_FONT; i++) { - font = global_font[i]; + for (int i = 0; i < BLF_MAX_FONT; i++) { + FontBLF *font = global_font[i]; if (font) { blf_glyph_cache_clear(font); blf_kerning_cache_clear(font); @@ -141,11 +133,8 @@ void BLF_cache_clear(void) static int blf_search(const char *name) { - FontBLF *font; - int i; - - for (i = 0; i < BLF_MAX_FONT; i++) { - font = global_font[i]; + for (int i = 0; i < BLF_MAX_FONT; i++) { + FontBLF *font = global_font[i]; if (font && (STREQ(font->name, name))) { return i; } @@ -156,9 +145,7 @@ static int blf_search(const char *name) static int blf_search_available(void) { - int i; - - for (i = 0; i < BLF_MAX_FONT; i++) { + for (int i = 0; i < BLF_MAX_FONT; i++) { if (!global_font[i]) { return i; } @@ -192,13 +179,10 @@ bool BLF_has_glyph(int fontid, unsigned int unicode) int BLF_load(const char *name) { - FontBLF *font; - int i; - /* check if we already load this font. */ - i = blf_search(name); + int i = blf_search(name); if (i >= 0) { - font = global_font[i]; + FontBLF *font = global_font[i]; font->reference_count++; return i; } @@ -208,26 +192,22 @@ int BLF_load(const char *name) int BLF_load_unique(const char *name) { - FontBLF *font; - char *filename; - int i; - /* Don't search in the cache!! make a new * object font, this is for keep fonts threads safe. */ - i = blf_search_available(); + int i = blf_search_available(); if (i == -1) { printf("Too many fonts!!!\n"); return -1; } - filename = blf_dir_search(name); + char *filename = blf_dir_search(name); if (!filename) { printf("Can't find font: %s\n", name); return -1; } - font = blf_font_new(name, filename); + FontBLF *font = blf_font_new(name, filename); MEM_freeN(filename); if (!font) { @@ -251,9 +231,7 @@ void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size) int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) { - int i; - - i = blf_search(name); + int i = blf_search(name); if (i >= 0) { /*font = global_font[i];*/ /*UNUSED*/ return i; @@ -263,14 +241,11 @@ int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size) int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size) { - FontBLF *font; - int i; - /* * Don't search in the cache, make a new object font! * this is to keep the font thread safe. */ - i = blf_search_available(); + int i = blf_search_available(); if (i == -1) { printf("Too many fonts!!!\n"); return -1; @@ -281,7 +256,7 @@ int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size return -1; } - font = blf_font_new_from_mem(name, mem, mem_size); + FontBLF *font = blf_font_new_from_mem(name, mem, mem_size); if (!font) { printf("Can't load font: %s from memory!!\n", name); return -1; @@ -294,11 +269,8 @@ int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size void BLF_unload(const char *name) { - FontBLF *font; - int i; - - for (i = 0; i < BLF_MAX_FONT; i++) { - font = global_font[i]; + for (int i = 0; i < BLF_MAX_FONT; i++) { + FontBLF *font = global_font[i]; if (font && (STREQ(font->name, name))) { BLI_assert(font->reference_count > 0); diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c index 9603470615d..51d3849aa48 100644 --- a/source/blender/blenfont/intern/blf_dir.c +++ b/source/blender/blenfont/intern/blf_dir.c @@ -115,11 +115,8 @@ char **BLF_dir_get(int *ndir) void BLF_dir_free(char **dirs, int count) { - char *path; - int i; - - for (i = 0; i < count; i++) { - path = dirs[i]; + for (int i = 0; i < count; i++) { + char *path = dirs[i]; MEM_freeN(path); } MEM_freeN(dirs); diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 1b27b6dd4c1..1501ee07b66 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -316,8 +316,7 @@ static GlyphBLF **blf_font_ensure_ascii_table(FontBLF *font, GlyphCacheBLF *gc) /* build ascii on demand */ if (glyph_ascii_table['0'] == NULL) { GlyphBLF *g; - unsigned int i; - for (i = 0; i < 256; i++) { + for (uint i = 0; i < 256; i++) { g = blf_glyph_search(gc, i); if (!g) { FT_UInt glyph_index = FT_Get_Char_Index(font->face, i); diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 8e74d5bba7c..f3c5c057dec 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -205,9 +205,7 @@ void blf_glyph_cache_clear(FontBLF *font) void blf_glyph_cache_free(GlyphCacheBLF *gc) { GlyphBLF *g; - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(gc->bucket); i++) { + for (uint i = 0; i < ARRAY_SIZE(gc->bucket); i++) { while ((g = BLI_pophead(&gc->bucket[i]))) { blf_glyph_free(g); } diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c index 6aa39e3aa71..3153a55b697 100644 --- a/source/blender/blenfont/intern/blf_thumbs.c +++ b/source/blender/blenfont/intern/blf_thumbs.c @@ -67,7 +67,6 @@ void BLF_thumb_preview(const char *filename, FontBLF *font; GlyphCacheBLF *gc; - int i; /* Create a new blender font obj and fill it with default values */ font = blf_font_new("thumb_font", filename); @@ -91,7 +90,7 @@ void BLF_thumb_preview(const char *filename, blf_draw_buffer__start(font); - for (i = 0; i < draw_str_lines; i++) { + for (int i = 0; i < draw_str_lines; i++) { const char *draw_str_i18n = i18n_draw_str[i] != NULL ? i18n_draw_str[i] : draw_str[i]; const size_t draw_str_i18n_len = strlen(draw_str_i18n); int draw_str_i18n_nbr = 0; diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h index ef74bb61a7e..fa3c59c781d 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -46,6 +46,10 @@ struct Scene; struct bAction; struct bActionGroup; struct bContext; +struct BlendWriter; +struct BlendDataReader; +struct BlendLibReader; +struct BlendExpander; /* Container for data required to do FCurve and Driver evaluation. */ typedef struct AnimationEvalContext { @@ -101,6 +105,13 @@ void BKE_keyingset_free(struct KeyingSet *ks); /* Free all the KeyingSets in the given list */ void BKE_keyingsets_free(struct ListBase *list); +void BKE_keyingsets_blend_write(struct BlendWriter *writer, struct ListBase *list); +void BKE_keyingsets_blend_read_data(struct BlendDataReader *reader, struct ListBase *list); +void BKE_keyingsets_blend_read_lib(struct BlendLibReader *reader, + struct ID *id, + struct ListBase *list); +void BKE_keyingsets_blend_read_expand(struct BlendExpander *expander, struct ListBase *list); + /* ************************************* */ /* Path Fixing API */ diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h new file mode 100644 index 00000000000..aab962d42a6 --- /dev/null +++ b/source/blender/blenkernel/BKE_attribute.h @@ -0,0 +1,85 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2006 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup bke + * \brief Generic geometry attributes built on CustomData. + */ + +#pragma once + +#include "BLI_sys_types.h" + +#include "BKE_customdata.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct CustomData; +struct CustomDataLayer; +struct ID; +struct PointerRNA; +struct ReportList; + +/* Attribute.domain */ +typedef enum AttributeDomain { + ATTR_DOMAIN_VERTEX = 0, /* Mesh Vertex */ + ATTR_DOMAIN_EDGE = 1, /* Mesh Edge */ + ATTR_DOMAIN_CORNER = 2, /* Mesh Corner */ + ATTR_DOMAIN_POLYGON = 3, /* Mesh Polygon */ + + ATTR_DOMAIN_POINT = 4, /* Hair or PointCloud Point */ + ATTR_DOMAIN_CURVE = 5, /* Hair Curve */ + + ATTR_DOMAIN_NUM +} AttributeDomain; + +/* Attributes */ + +bool BKE_id_attributes_supported(struct ID *id); + +struct CustomDataLayer *BKE_id_attribute_new(struct ID *id, + const char *name, + const int type, + const AttributeDomain domain, + struct ReportList *reports); +bool BKE_id_attribute_remove(struct ID *id, + struct CustomDataLayer *layer, + struct ReportList *reports); + +AttributeDomain BKE_id_attribute_domain(struct ID *id, struct CustomDataLayer *layer); +int BKE_id_attribute_data_length(struct ID *id, struct CustomDataLayer *layer); +bool BKE_id_attribute_required(struct ID *id, struct CustomDataLayer *layer); +bool BKE_id_attribute_rename(struct ID *id, + struct CustomDataLayer *layer, + const char *new_name, + struct ReportList *reports); + +int BKE_id_attributes_length(struct ID *id, const CustomDataMask mask); + +struct CustomDataLayer *BKE_id_attributes_active_get(struct ID *id); +void BKE_id_attributes_active_set(struct ID *id, struct CustomDataLayer *layer); +int *BKE_id_attributes_active_index_p(struct ID *id); + +CustomData *BKE_id_attributes_iterator_next_domain(struct ID *id, struct CustomDataLayer *layers); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index d21fe5afa7e..fea9bbe9bb5 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -570,9 +570,9 @@ void CustomData_data_transfer(const struct MeshPairRemap *me_remap, /* .blend file I/O */ void CustomData_blend_write_prepare(struct CustomData *data, - struct CustomDataLayer **r_write_layers, - struct CustomDataLayer *write_layers_buff, - size_t write_layers_size); + struct CustomDataLayer **r_write_layers, + struct CustomDataLayer *write_layers_buff, + size_t write_layers_size); void CustomData_blend_write(struct BlendWriter *writer, struct CustomData *data, diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h index 4ec8609831b..518bd2a949f 100644 --- a/source/blender/blenkernel/BKE_gpencil.h +++ b/source/blender/blenkernel/BKE_gpencil.h @@ -49,6 +49,7 @@ struct bGPDspoint; struct bGPDstroke; struct bGPDcurve; struct bGPdata; +struct BlendDataReader; #define GPENCIL_SIMPLIFY(scene) ((scene->r.simplify_gpencil & SIMPLIFY_GPENCIL_ENABLE)) #define GPENCIL_SIMPLIFY_ONPLAY(playing) \ @@ -290,6 +291,8 @@ void BKE_gpencil_parent_matrix_get(const struct Depsgraph *depsgraph, void BKE_gpencil_update_layer_parent(const struct Depsgraph *depsgraph, struct Object *ob); +void BKE_gpencil_blend_read_data(struct BlendDataReader *reader, struct bGPdata *gpd); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_gpencil_geom.h b/source/blender/blenkernel/BKE_gpencil_geom.h index 70e12eee6dc..6917a62053c 100644 --- a/source/blender/blenkernel/BKE_gpencil_geom.h +++ b/source/blender/blenkernel/BKE_gpencil_geom.h @@ -126,7 +126,7 @@ float BKE_gpencil_stroke_length(const struct bGPDstroke *gps, bool use_3d); void BKE_gpencil_stroke_set_random_color(struct bGPDstroke *gps); -void BKE_gpencil_convert_mesh(struct Main *bmain, +bool BKE_gpencil_convert_mesh(struct Main *bmain, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob_gp, @@ -137,8 +137,7 @@ void BKE_gpencil_convert_mesh(struct Main *bmain, const float matrix[4][4], const int frame_offset, const bool use_seams, - const bool use_faces, - const bool simple_material); + const bool use_faces); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h index bf386e099e0..0af0a1cc90c 100644 --- a/source/blender/blenkernel/BKE_hair.h +++ b/source/blender/blenkernel/BKE_hair.h @@ -25,6 +25,7 @@ extern "C" { #endif struct BoundBox; +struct CustomDataLayer; struct Depsgraph; struct Hair; struct Main; @@ -37,6 +38,7 @@ struct Hair *BKE_hair_copy(struct Main *bmain, const struct Hair *hair); struct BoundBox *BKE_hair_boundbox_get(struct Object *ob); void BKE_hair_update_customdata_pointers(struct Hair *hair); +bool BKE_hair_customdata_required(struct Hair *hair, struct CustomDataLayer *layer); /* Depsgraph */ diff --git a/source/blender/blenkernel/BKE_icons.h b/source/blender/blenkernel/BKE_icons.h index 8a4fc78eb97..e40489a80da 100644 --- a/source/blender/blenkernel/BKE_icons.h +++ b/source/blender/blenkernel/BKE_icons.h @@ -78,6 +78,8 @@ struct ImBuf; struct PreviewImage; struct StudioLight; struct bGPDlayer; +struct BlendWriter; +struct BlendDataReader; enum eIconSizes; @@ -156,6 +158,9 @@ struct PreviewImage *BKE_previewimg_cached_thumbnail_read(const char *name, void BKE_previewimg_cached_release(const char *name); void BKE_previewimg_cached_release_pointer(struct PreviewImage *prv); +void BKE_previewimg_blend_write(struct BlendWriter *writer, const struct PreviewImage *prv); +void BKE_previewimg_blend_read(struct BlendDataReader *reader, struct PreviewImage *prv); + int BKE_icon_geom_ensure(struct Icon_Geom *geom); struct Icon_Geom *BKE_icon_geom_from_memory(const uchar *data, size_t data_len); struct Icon_Geom *BKE_icon_geom_from_file(const char *filename); diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h index 52503f08153..024d58174e8 100644 --- a/source/blender/blenkernel/BKE_layer.h +++ b/source/blender/blenkernel/BKE_layer.h @@ -99,6 +99,7 @@ void BKE_main_collection_sync(const struct Main *bmain); void BKE_scene_collection_sync(const struct Scene *scene); void BKE_layer_collection_sync(const struct Scene *scene, struct ViewLayer *view_layer); void BKE_layer_collection_local_sync(struct ViewLayer *view_layer, const struct View3D *v3d); +void BKE_layer_collection_local_sync_all(const struct Main *bmain); void BKE_main_collection_sync_remap(const struct Main *bmain); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 3829000a045..3421aa9e900 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -72,6 +72,10 @@ struct bNodeTree; struct bNodeTreeExec; struct bNodeTreeType; struct uiLayout; +struct BlendWriter; +struct BlendDataReader; +struct BlendLibReader; +struct BlendExpander; /* -------------------------------------------------------------------- */ /** \name Node Type Definitions @@ -250,23 +254,23 @@ typedef struct bNodeType { * \note Used as a fallback when #bNode.label isn't set. */ void (*labelfunc)(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen); - /// Optional custom resize handle polling. + /** Optional custom resize handle polling. */ int (*resize_area_func)(struct bNode *node, int x, int y); - /// Optional selection area polling. + /** Optional selection area polling. */ int (*select_area_func)(struct bNode *node, int x, int y); - /// Optional tweak area polling (for grabbing). + /** Optional tweak area polling (for grabbing). */ int (*tweak_area_func)(struct bNode *node, int x, int y); - /// Called when the node is updated in the editor. + /** Called when the node is updated in the editor. */ void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node); - /// Check and update if internal ID data has changed. + /** Check and update if internal ID data has changed. */ void (*group_update_func)(struct bNodeTree *ntree, struct bNode *node); - /// Initialize a new node instance of this type after creation. + /** Initialize a new node instance of this type after creation. */ void (*initfunc)(struct bNodeTree *ntree, struct bNode *node); - /// Free the node instance. + /** Free the node instance. */ void (*freefunc)(struct bNode *node); - /// Make a copy of the node instance. + /** Make a copy of the node instance. */ void (*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node); @@ -453,6 +457,11 @@ struct bNodeTree *ntreeLocalize(struct bNodeTree *ntree); void ntreeLocalSync(struct bNodeTree *localtree, struct bNodeTree *ntree); void ntreeLocalMerge(struct Main *bmain, struct bNodeTree *localtree, struct bNodeTree *ntree); +void ntreeBlendWrite(struct BlendWriter *writer, struct bNodeTree *ntree); +void ntreeBlendReadData(struct BlendDataReader *reader, struct bNodeTree *ntree); +void ntreeBlendReadLib(struct BlendLibReader *reader, struct bNodeTree *ntree); +void ntreeBlendReadExpand(struct BlendExpander *expander, struct bNodeTree *ntree); + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/blenkernel/BKE_packedFile.h b/source/blender/blenkernel/BKE_packedFile.h index 9890399f8a2..f818f5f25fd 100644 --- a/source/blender/blenkernel/BKE_packedFile.h +++ b/source/blender/blenkernel/BKE_packedFile.h @@ -37,6 +37,8 @@ struct ReportList; struct VFont; struct Volume; struct bSound; +struct BlendWriter; +struct BlendDataReader; enum ePF_FileCompare { PF_CMP_EQUAL = 0, @@ -121,6 +123,9 @@ void BKE_packedfile_id_unpack(struct Main *bmain, struct ReportList *reports, enum ePF_FileStatus how); +void BKE_packedfile_blend_write(struct BlendWriter *writer, struct PackedFile *pf); +void BKE_packedfile_blend_read(struct BlendDataReader *reader, struct PackedFile **pf_p); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_pointcloud.h b/source/blender/blenkernel/BKE_pointcloud.h index b2e7e1d23ee..295744af5b4 100644 --- a/source/blender/blenkernel/BKE_pointcloud.h +++ b/source/blender/blenkernel/BKE_pointcloud.h @@ -25,6 +25,7 @@ extern "C" { #endif struct BoundBox; +struct CustomDataLayer; struct Depsgraph; struct Main; struct Object; @@ -37,6 +38,8 @@ struct PointCloud *BKE_pointcloud_copy(struct Main *bmain, const struct PointClo struct BoundBox *BKE_pointcloud_boundbox_get(struct Object *ob); void BKE_pointcloud_update_customdata_pointers(struct PointCloud *pointcloud); +bool BKE_pointcloud_customdata_required(struct PointCloud *pointcloud, + struct CustomDataLayer *layer); /* Dependency Graph */ diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index bf3077b7743..cf43d0fe845 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -77,6 +77,7 @@ set(SRC intern/armature.c intern/armature_deform.c intern/armature_update.c + intern/attribute.c intern/autoexec.c intern/blender.c intern/blender_copybuffer.c @@ -267,6 +268,7 @@ set(SRC BKE_animsys.h BKE_appdir.h BKE_armature.h + BKE_attribute.h BKE_autoexec.h BKE_blender.h BKE_blender_copybuffer.h diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c index e3543290b65..ec2fb5f5bdb 100644 --- a/source/blender/blenkernel/intern/CCGSubSurf.c +++ b/source/blender/blenkernel/intern/CCGSubSurf.c @@ -72,8 +72,7 @@ static CCGVert *_vert_new(CCGVertHDL vHDL, CCGSubSurf *ss) } static void _vert_remEdge(CCGVert *v, CCGEdge *e) { - int i; - for (i = 0; i < v->numEdges; i++) { + for (int i = 0; i < v->numEdges; i++) { if (v->edges[i] == e) { v->edges[i] = v->edges[--v->numEdges]; break; @@ -82,8 +81,7 @@ static void _vert_remEdge(CCGVert *v, CCGEdge *e) } static void _vert_remFace(CCGVert *v, CCGFace *f) { - int i; - for (i = 0; i < v->numFaces; i++) { + for (int i = 0; i < v->numFaces; i++) { if (v->faces[i] == f) { v->faces[i] = v->faces[--v->numFaces]; break; @@ -104,8 +102,7 @@ static void _vert_addFace(CCGVert *v, CCGFace *f, CCGSubSurf *ss) } static CCGEdge *_vert_findEdgeTo(const CCGVert *v, const CCGVert *vQ) { - int i; - for (i = 0; i < v->numEdges; i++) { + for (int i = 0; i < v->numEdges; i++) { CCGEdge *e = v->edges[v->numEdges - 1 - i]; // XXX, note reverse if ((e->v0 == v && e->v1 == vQ) || (e->v1 == v && e->v0 == vQ)) { return e; @@ -155,8 +152,7 @@ static CCGEdge *_edge_new(CCGEdgeHDL eHDL, CCGVert *v0, CCGVert *v1, float creas } static void _edge_remFace(CCGEdge *e, CCGFace *f) { - int i; - for (i = 0; i < e->numFaces; i++) { + for (int i = 0; i < e->numFaces; i++) { if (e->faces[i] == f) { e->faces[i] = e->faces[--e->numFaces]; break; @@ -205,13 +201,12 @@ static CCGFace *_face_new( sizeof(CCGFace) + sizeof(CCGVert *) * numVerts + sizeof(CCGEdge *) * numVerts + ss->meshIFC.vertDataSize * num_face_data + ss->meshIFC.faceUserSize); byte *userData; - int i; f->numVerts = numVerts; f->fHDL = fHDL; f->flags = 0; - for (i = 0; i < numVerts; i++) { + for (int i = 0; i < numVerts; i++) { FACE_getVerts(f)[i] = verts[i]; FACE_getEdges(f)[i] = edges[i]; _vert_addFace(verts[i], f, ss); @@ -1418,9 +1413,7 @@ CCGEdge *ccgSubSurf_getFaceEdge(CCGFace *f, int index) } int ccgSubSurf_getFaceEdgeIndex(CCGFace *f, CCGEdge *e) { - int i; - - for (i = 0; i < f->numVerts; i++) { + for (int i = 0; i < f->numVerts; i++) { if (FACE_getEdges(f)[i] == e) { return i; } diff --git a/source/blender/blenkernel/intern/CCGSubSurf_inline.h b/source/blender/blenkernel/intern/CCGSubSurf_inline.h index 91a7129b433..4681602c071 100644 --- a/source/blender/blenkernel/intern/CCGSubSurf_inline.h +++ b/source/blender/blenkernel/intern/CCGSubSurf_inline.h @@ -142,8 +142,7 @@ BLI_INLINE float *ccg_face_getIFNo( BLI_INLINE int ccg_face_getVertIndex(CCGFace *f, CCGVert *v) { - int i; - for (i = 0; i < f->numVerts; i++) { + for (int i = 0; i < f->numVerts; i++) { if (FACE_getVerts(f)[i] == v) { return i; } @@ -153,8 +152,7 @@ BLI_INLINE int ccg_face_getVertIndex(CCGFace *f, CCGVert *v) BLI_INLINE int ccg_face_getEdgeIndex(CCGFace *f, CCGEdge *e) { - int i; - for (i = 0; i < f->numVerts; i++) { + for (int i = 0; i < f->numVerts; i++) { if (FACE_getEdges(f)[i] == e) { return i; } @@ -215,8 +213,7 @@ BLI_INLINE void Normalize(float no[3]) BLI_INLINE bool VertDataEqual(const float a[], const float b[], const CCGSubSurf *ss) { - int i; - for (i = 0; i < ss->meshIFC.numLayers; i++) { + for (int i = 0; i < ss->meshIFC.numLayers; i++) { if (a[i] != b[i]) { return false; } @@ -231,32 +228,28 @@ BLI_INLINE void VertDataZero(float v[], const CCGSubSurf *ss) BLI_INLINE void VertDataCopy(float dst[], const float src[], const CCGSubSurf *ss) { - int i; - for (i = 0; i < ss->meshIFC.numLayers; i++) { + for (int i = 0; i < ss->meshIFC.numLayers; i++) { dst[i] = src[i]; } } BLI_INLINE void VertDataAdd(float a[], const float b[], const CCGSubSurf *ss) { - int i; - for (i = 0; i < ss->meshIFC.numLayers; i++) { + for (int i = 0; i < ss->meshIFC.numLayers; i++) { a[i] += b[i]; } } BLI_INLINE void VertDataSub(float a[], const float b[], const CCGSubSurf *ss) { - int i; - for (i = 0; i < ss->meshIFC.numLayers; i++) { + for (int i = 0; i < ss->meshIFC.numLayers; i++) { a[i] -= b[i]; } } BLI_INLINE void VertDataMulN(float v[], float f, const CCGSubSurf *ss) { - int i; - for (i = 0; i < ss->meshIFC.numLayers; i++) { + for (int i = 0; i < ss->meshIFC.numLayers; i++) { v[i] *= f; } } @@ -268,8 +261,7 @@ BLI_INLINE void VertDataAvg4(float v[], const float d[], const CCGSubSurf *ss) { - int i; - for (i = 0; i < ss->meshIFC.numLayers; i++) { + for (int i = 0; i < ss->meshIFC.numLayers; i++) { v[i] = (a[i] + b[i] + c[i] + d[i]) * 0.25f; } } diff --git a/source/blender/blenkernel/intern/CCGSubSurf_legacy.c b/source/blender/blenkernel/intern/CCGSubSurf_legacy.c index b723d39ca08..22a4bf18f7f 100644 --- a/source/blender/blenkernel/intern/CCGSubSurf_legacy.c +++ b/source/blender/blenkernel/intern/CCGSubSurf_legacy.c @@ -49,8 +49,7 @@ static int _edge_isBoundary(const CCGEdge *e) static bool _vert_isBoundary(const CCGVert *v) { - int i; - for (i = 0; i < v->numEdges; i++) { + for (int i = 0; i < v->numEdges; i++) { if (_edge_isBoundary(v->edges[i])) { return true; } diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 089d8bef09e..64a8ae15fd3 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -28,6 +28,9 @@ #include "MEM_guardedalloc.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_anim_types.h" #include "DNA_armature_types.h" #include "DNA_constraint_types.h" @@ -63,6 +66,8 @@ #include "RNA_access.h" +#include "BLO_read_write.h" + #include "CLG_log.h" static CLG_LogRef LOG = {"bke.action"}; @@ -169,6 +174,105 @@ static void action_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void action_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + bAction *act = (bAction *)id; + if (act->id.us > 0 || BLO_write_is_undo(writer)) { + BLO_write_id_struct(writer, bAction, id_address, &act->id); + BKE_id_blend_write(writer, &act->id); + + BKE_fcurve_blend_write(writer, &act->curves); + + LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) { + BLO_write_struct(writer, bActionGroup, grp); + } + + LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { + BLO_write_struct(writer, TimeMarker, marker); + } + } +} + +static void action_blend_read_data(BlendDataReader *reader, ID *id) +{ + bAction *act = (bAction *)id; + + BLO_read_list(reader, &act->curves); + BLO_read_list(reader, &act->chanbase); // XXX deprecated - old animation system + BLO_read_list(reader, &act->groups); + BLO_read_list(reader, &act->markers); + + // XXX deprecated - old animation system <<< + LISTBASE_FOREACH (bActionChannel *, achan, &act->chanbase) { + BLO_read_data_address(reader, &achan->grp); + + BLO_read_list(reader, &achan->constraintChannels); + } + // >>> XXX deprecated - old animation system + + BKE_fcurve_blend_read_data(reader, &act->curves); + + LISTBASE_FOREACH (bActionGroup *, agrp, &act->groups) { + BLO_read_data_address(reader, &agrp->channels.first); + BLO_read_data_address(reader, &agrp->channels.last); + } +} + +static void blend_read_lib_constraint_channels(BlendLibReader *reader, ID *id, ListBase *chanbase) +{ + LISTBASE_FOREACH (bConstraintChannel *, chan, chanbase) { + BLO_read_id_address(reader, id->lib, &chan->ipo); + } +} + +static void action_blend_read_lib(BlendLibReader *reader, ID *id) +{ + bAction *act = (bAction *)id; + + // XXX deprecated - old animation system <<< + LISTBASE_FOREACH (bActionChannel *, chan, &act->chanbase) { + BLO_read_id_address(reader, act->id.lib, &chan->ipo); + blend_read_lib_constraint_channels(reader, &act->id, &chan->constraintChannels); + } + // >>> XXX deprecated - old animation system + + BKE_fcurve_blend_read_lib(reader, &act->id, &act->curves); + + LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { + if (marker->camera) { + BLO_read_id_address(reader, act->id.lib, &marker->camera); + } + } +} + +static void blend_read_expand_constraint_channels(BlendExpander *expander, ListBase *chanbase) +{ + LISTBASE_FOREACH (bConstraintChannel *, chan, chanbase) { + BLO_expand(expander, chan->ipo); + } +} + +static void action_blend_read_expand(BlendExpander *expander, ID *id) +{ + bAction *act = (bAction *)id; + + // XXX deprecated - old animation system -------------- + LISTBASE_FOREACH (bActionChannel *, chan, &act->chanbase) { + BLO_expand(expander, chan->ipo); + blend_read_expand_constraint_channels(expander, &chan->constraintChannels); + } + // --------------------------------------------------- + + /* F-Curves in Action */ + BKE_fcurve_blend_read_expand(expander, &act->curves); + + LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { + if (marker->camera) { + BLO_expand(expander, marker->camera); + } + } +} + IDTypeInfo IDType_ID_AC = { .id_code = ID_AC, .id_filter = FILTER_ID_AC, @@ -186,10 +290,10 @@ IDTypeInfo IDType_ID_AC = { .foreach_id = action_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = action_blend_write, + .blend_read_data = action_blend_read_data, + .blend_read_lib = action_blend_read_lib, + .blend_read_expand = action_blend_read_expand, }; /* ***************** Library data level operations on action ************** */ diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 69e70cffdb2..98c01351f32 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -69,6 +69,8 @@ #include "RNA_access.h" +#include "BLO_read_write.h" + #include "nla_private.h" #include "atomic_ops.h" @@ -308,6 +310,55 @@ void BKE_keyingsets_free(ListBase *list) } } +void BKE_keyingsets_blend_write(BlendWriter *writer, ListBase *list) +{ + LISTBASE_FOREACH (KeyingSet *, ks, list) { + /* KeyingSet */ + BLO_write_struct(writer, KeyingSet, ks); + + /* Paths */ + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { + /* Path */ + BLO_write_struct(writer, KS_Path, ksp); + + if (ksp->rna_path) { + BLO_write_string(writer, ksp->rna_path); + } + } + } +} + +void BKE_keyingsets_blend_read_data(BlendDataReader *reader, ListBase *list) +{ + LISTBASE_FOREACH (KeyingSet *, ks, list) { + /* paths */ + BLO_read_list(reader, &ks->paths); + + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { + /* rna path */ + BLO_read_data_address(reader, &ksp->rna_path); + } + } +} + +void BKE_keyingsets_blend_read_lib(BlendLibReader *reader, ID *id, ListBase *list) +{ + LISTBASE_FOREACH (KeyingSet *, ks, list) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { + BLO_read_id_address(reader, id->lib, &ksp->id); + } + } +} + +void BKE_keyingsets_blend_read_expand(BlendExpander *expander, ListBase *list) +{ + LISTBASE_FOREACH (KeyingSet *, ks, list) { + LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { + BLO_expand(expander, ksp->id); + } + } +} + /* ***************************************** */ /* Evaluation Data-Setting Backend */ diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c index 2cc715464ad..236f1391443 100644 --- a/source/blender/blenkernel/intern/appdir.c +++ b/source/blender/blenkernel/intern/appdir.c @@ -746,8 +746,6 @@ bool BKE_appdir_program_python_search(char *fullpath, python_ver, basename, }; - int i; - bool is_found = false; BLI_snprintf(python_ver, sizeof(python_ver), "%s%d.%d", basename, version_major, version_minor); @@ -756,7 +754,7 @@ bool BKE_appdir_program_python_search(char *fullpath, const char *python_bin_dir = BKE_appdir_folder_id(BLENDER_SYSTEM_PYTHON, "bin"); if (python_bin_dir) { - for (i = 0; i < ARRAY_SIZE(python_names); i++) { + for (int i = 0; i < ARRAY_SIZE(python_names); i++) { BLI_join_dirfile(fullpath, fullpath_len, python_bin_dir, python_names[i]); if ( @@ -774,7 +772,7 @@ bool BKE_appdir_program_python_search(char *fullpath, } if (is_found == false) { - for (i = 0; i < ARRAY_SIZE(python_names); i++) { + for (int i = 0; i < ARRAY_SIZE(python_names); i++) { if (BLI_path_program_search(fullpath, fullpath_len, python_names[i])) { is_found = true; break; diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index a653087f961..49ca25aca29 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -45,6 +45,7 @@ #include "DNA_scene_types.h" #include "BKE_action.h" +#include "BKE_anim_data.h" #include "BKE_anim_visualization.h" #include "BKE_armature.h" #include "BKE_constraint.h" @@ -62,6 +63,8 @@ #include "BIK_api.h" +#include "BLO_read_write.h" + #include "CLG_log.h" static CLG_LogRef LOG = {"bke.armature"}; @@ -165,6 +168,125 @@ static void armature_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void write_bone(BlendWriter *writer, Bone *bone) +{ + /* PATCH for upward compatibility after 2.37+ armature recode */ + bone->size[0] = bone->size[1] = bone->size[2] = 1.0f; + + /* Write this bone */ + BLO_write_struct(writer, Bone, bone); + + /* Write ID Properties -- and copy this comment EXACTLY for easy finding + * of library blocks that implement this.*/ + if (bone->prop) { + IDP_BlendWrite(writer, bone->prop); + } + + /* Write Children */ + LISTBASE_FOREACH (Bone *, cbone, &bone->childbase) { + write_bone(writer, cbone); + } +} + +static void armature_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + bArmature *arm = (bArmature *)id; + if (arm->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + arm->bonehash = NULL; + arm->edbo = NULL; + /* Must always be cleared (armatures don't have their own edit-data). */ + arm->needs_flush_to_id = 0; + arm->act_edbone = NULL; + + BLO_write_id_struct(writer, bArmature, id_address, &arm->id); + BKE_id_blend_write(writer, &arm->id); + + if (arm->adt) { + BKE_animdata_blend_write(writer, arm->adt); + } + + /* Direct data */ + LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { + write_bone(writer, bone); + } + } +} + +static void direct_link_bones(BlendDataReader *reader, Bone *bone) +{ + BLO_read_data_address(reader, &bone->parent); + BLO_read_data_address(reader, &bone->prop); + IDP_BlendDataRead(reader, &bone->prop); + + BLO_read_data_address(reader, &bone->bbone_next); + BLO_read_data_address(reader, &bone->bbone_prev); + + bone->flag &= ~(BONE_DRAW_ACTIVE | BONE_DRAW_LOCKED_WEIGHT); + + BLO_read_list(reader, &bone->childbase); + + LISTBASE_FOREACH (Bone *, child, &bone->childbase) { + direct_link_bones(reader, child); + } +} + +static void armature_blend_read_data(BlendDataReader *reader, ID *id) +{ + bArmature *arm = (bArmature *)id; + BLO_read_list(reader, &arm->bonebase); + arm->bonehash = NULL; + arm->edbo = NULL; + /* Must always be cleared (armatures don't have their own edit-data). */ + arm->needs_flush_to_id = 0; + + BLO_read_data_address(reader, &arm->adt); + BKE_animdata_blend_read_data(reader, arm->adt); + + LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { + direct_link_bones(reader, bone); + } + + BLO_read_data_address(reader, &arm->act_bone); + arm->act_edbone = NULL; + + BKE_armature_bone_hash_make(arm); +} + +static void lib_link_bones(BlendLibReader *reader, Bone *bone) +{ + IDP_BlendReadLib(reader, bone->prop); + + LISTBASE_FOREACH (Bone *, curbone, &bone->childbase) { + lib_link_bones(reader, curbone); + } +} + +static void armature_blend_read_lib(BlendLibReader *reader, ID *id) +{ + bArmature *arm = (bArmature *)id; + LISTBASE_FOREACH (Bone *, curbone, &arm->bonebase) { + lib_link_bones(reader, curbone); + } +} + +static void expand_bones(BlendExpander *expander, Bone *bone) +{ + IDP_BlendReadExpand(expander, bone->prop); + + LISTBASE_FOREACH (Bone *, curBone, &bone->childbase) { + expand_bones(expander, curBone); + } +} + +static void armature_blend_read_expand(BlendExpander *expander, ID *id) +{ + bArmature *arm = (bArmature *)id; + LISTBASE_FOREACH (Bone *, curBone, &arm->bonebase) { + expand_bones(expander, curBone); + } +} + IDTypeInfo IDType_ID_AR = { .id_code = ID_AR, .id_filter = FILTER_ID_AR, @@ -182,10 +304,10 @@ IDTypeInfo IDType_ID_AR = { .foreach_id = armature_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = armature_blend_write, + .blend_read_data = armature_blend_read_data, + .blend_read_lib = armature_blend_read_lib, + .blend_read_expand = armature_blend_read_expand, }; /** \} */ diff --git a/source/blender/blenkernel/intern/armature_update.c b/source/blender/blenkernel/intern/armature_update.c index 97c717572bc..de00372c3ec 100644 --- a/source/blender/blenkernel/intern/armature_update.c +++ b/source/blender/blenkernel/intern/armature_update.c @@ -125,7 +125,6 @@ static void splineik_init_tree_from_pchan(Scene *UNUSED(scene), /* perform binding step if required */ if ((ikData->flag & CONSTRAINT_SPLINEIK_BOUND) == 0) { float segmentLen = (1.0f / (float)segcount); - int i; /* setup new empty array for the points list */ if (ikData->points) { @@ -140,7 +139,7 @@ static void splineik_init_tree_from_pchan(Scene *UNUSED(scene), /* perform binding of the joints to parametric positions along the curve based * proportion of the total length that each bone occupies */ - for (i = 0; i < segcount; i++) { + for (int i = 0; i < segcount; i++) { /* 'head' joints, traveling towards the root of the chain * - 2 methods; the one chosen depends on whether we've got usable lengths */ @@ -549,11 +548,9 @@ static void splineik_execute_tree( /* for each pose-tree, execute it if it is spline, otherwise just free it */ while ((tree = pchan_root->siktree.first) != NULL) { - int i; - /* Firstly, calculate the bone matrix the standard way, * since this is needed for roll control. */ - for (i = tree->chainlen - 1; i >= 0; i--) { + for (int i = tree->chainlen - 1; i >= 0; i--) { BKE_pose_where_is_bone(depsgraph, scene, ob, tree->chain[i], ctime, 1); } @@ -565,7 +562,7 @@ static void splineik_execute_tree( * - the chain is traversed in the opposite order to storage order (i.e. parent to children) * so that dependencies are correct */ - for (i = tree->chainlen - 1; i >= 0; i--) { + for (int i = tree->chainlen - 1; i >= 0; i--) { bPoseChannel *pchan = tree->chain[i]; splineik_evaluate_bone(tree, ob, pchan, i, &state); } diff --git a/source/blender/blenkernel/intern/attribute.c b/source/blender/blenkernel/intern/attribute.c new file mode 100644 index 00000000000..9ad73133f9e --- /dev/null +++ b/source/blender/blenkernel/intern/attribute.c @@ -0,0 +1,330 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2006 Blender Foundation. + * All rights reserved. + * + * Implementation of generic geometry attributes management. This is built + * on top of CustomData, which manages individual domains. + */ + +/** \file + * \ingroup bke + */ + +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "DNA_ID.h" +#include "DNA_customdata_types.h" +#include "DNA_hair_types.h" +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_pointcloud_types.h" + +#include "BLI_string_utf8.h" + +#include "BKE_attribute.h" +#include "BKE_customdata.h" +#include "BKE_hair.h" +#include "BKE_pointcloud.h" +#include "BKE_report.h" + +#include "RNA_access.h" + +typedef struct DomainInfo { + CustomData *customdata; + int length; +} DomainInfo; + +static void get_domains(ID *id, DomainInfo info[ATTR_DOMAIN_NUM]) +{ + memset(info, 0, sizeof(DomainInfo) * ATTR_DOMAIN_NUM); + + switch (GS(id->name)) { + case ID_PT: { + PointCloud *pointcloud = (PointCloud *)id; + info[ATTR_DOMAIN_POINT].customdata = &pointcloud->pdata; + info[ATTR_DOMAIN_POINT].length = pointcloud->totpoint; + break; + } + case ID_ME: { + Mesh *mesh = (Mesh *)id; + info[ATTR_DOMAIN_VERTEX].customdata = &mesh->vdata; + info[ATTR_DOMAIN_VERTEX].length = mesh->totvert; + info[ATTR_DOMAIN_EDGE].customdata = &mesh->edata; + info[ATTR_DOMAIN_EDGE].length = mesh->totedge; + info[ATTR_DOMAIN_CORNER].customdata = &mesh->ldata; + info[ATTR_DOMAIN_CORNER].length = mesh->totloop; + info[ATTR_DOMAIN_POLYGON].customdata = &mesh->pdata; + info[ATTR_DOMAIN_POLYGON].length = mesh->totpoly; + break; + } + case ID_HA: { + Hair *hair = (Hair *)id; + info[ATTR_DOMAIN_POINT].customdata = &hair->pdata; + info[ATTR_DOMAIN_POINT].length = hair->totpoint; + info[ATTR_DOMAIN_CURVE].customdata = &hair->cdata; + info[ATTR_DOMAIN_CURVE].length = hair->totcurve; + break; + } + default: + break; + } +} + +static CustomData *attribute_customdata_find(ID *id, CustomDataLayer *layer) +{ + DomainInfo info[ATTR_DOMAIN_NUM]; + get_domains(id, info); + + for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) { + CustomData *customdata = info[domain].customdata; + if (customdata && ARRAY_HAS_ITEM(layer, customdata->layers, customdata->totlayer)) { + return customdata; + } + } + + return NULL; +} + +bool BKE_id_attributes_supported(struct ID *id) +{ + DomainInfo info[ATTR_DOMAIN_NUM]; + get_domains(id, info); + for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) { + if (info[domain].customdata) { + return true; + } + } + return false; +} + +bool BKE_id_attribute_rename(ID *id, + CustomDataLayer *layer, + const char *new_name, + ReportList *reports) +{ + if (BKE_id_attribute_required(id, layer)) { + BLI_assert(!"Required attribute name is not editable"); + return false; + } + + CustomData *customdata = attribute_customdata_find(id, layer); + if (customdata == NULL) { + BKE_report(reports, RPT_ERROR, "Attribute is not part of this geometry"); + return false; + } + + BLI_strncpy_utf8(layer->name, new_name, sizeof(layer->name)); + CustomData_set_layer_unique_name(customdata, layer - customdata->layers); + return true; +} + +CustomDataLayer *BKE_id_attribute_new( + ID *id, const char *name, const int type, const AttributeDomain domain, ReportList *reports) +{ + DomainInfo info[ATTR_DOMAIN_NUM]; + get_domains(id, info); + + CustomData *customdata = info[domain].customdata; + if (customdata == NULL) { + BKE_report(reports, RPT_ERROR, "Attribute domain not supported by this geometry type"); + return NULL; + } + + CustomData_add_layer_named(customdata, type, CD_DEFAULT, NULL, info[domain].length, name); + const int index = CustomData_get_named_layer_index(customdata, type, name); + return (index == -1) ? NULL : &(customdata->layers[index]); +} + +bool BKE_id_attribute_remove(ID *id, CustomDataLayer *layer, ReportList *reports) +{ + CustomData *customdata = attribute_customdata_find(id, layer); + const int index = (customdata) ? + CustomData_get_named_layer_index(customdata, layer->type, layer->name) : + -1; + + if (index == -1) { + BKE_report(reports, RPT_ERROR, "Attribute is not part of this geometry"); + return false; + } + + if (BKE_id_attribute_required(id, layer)) { + BKE_report(reports, RPT_ERROR, "Attribute is required and can't be removed"); + return false; + } + + const int length = BKE_id_attribute_data_length(id, layer); + CustomData_free_layer(customdata, layer->type, length, index); + return true; +} + +int BKE_id_attributes_length(ID *id, const CustomDataMask mask) +{ + DomainInfo info[ATTR_DOMAIN_NUM]; + get_domains(id, info); + + int length = 0; + + for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) { + CustomData *customdata = info[domain].customdata; + if (customdata) { + length += CustomData_number_of_layers_typemask(customdata, mask); + } + } + + return length; +} + +AttributeDomain BKE_id_attribute_domain(ID *id, CustomDataLayer *layer) +{ + DomainInfo info[ATTR_DOMAIN_NUM]; + get_domains(id, info); + + for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) { + CustomData *customdata = info[domain].customdata; + if (customdata && ARRAY_HAS_ITEM(layer, customdata->layers, customdata->totlayer)) { + return domain; + } + } + + BLI_assert(!"Custom data layer not found in geometry"); + return ATTR_DOMAIN_NUM; +} + +int BKE_id_attribute_data_length(ID *id, CustomDataLayer *layer) +{ + DomainInfo info[ATTR_DOMAIN_NUM]; + get_domains(id, info); + + for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) { + CustomData *customdata = info[domain].customdata; + if (customdata && ARRAY_HAS_ITEM(layer, customdata->layers, customdata->totlayer)) { + return info[domain].length; + } + } + + BLI_assert(!"Custom data layer not found in geometry"); + return 0; +} + +bool BKE_id_attribute_required(ID *id, CustomDataLayer *layer) +{ + switch (GS(id->name)) { + case ID_PT: { + return BKE_pointcloud_customdata_required((PointCloud *)id, layer); + } + case ID_HA: { + return BKE_hair_customdata_required((Hair *)id, layer); + } + default: + return false; + } +} + +CustomDataLayer *BKE_id_attributes_active_get(ID *id) +{ + int active_index = *BKE_id_attributes_active_index_p(id); + if (active_index > BKE_id_attributes_length(id, CD_MASK_PROP_ALL)) { + active_index = 0; + } + + DomainInfo info[ATTR_DOMAIN_NUM]; + get_domains(id, info); + + int index = 0; + + for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) { + CustomData *customdata = info[domain].customdata; + if (customdata) { + for (int i = 0; i < customdata->totlayer; i++) { + CustomDataLayer *layer = &customdata->layers[i]; + if (CD_MASK_PROP_ALL & CD_TYPE_AS_MASK(layer->type)) { + if (index == active_index) { + return layer; + } + index++; + } + } + } + } + + return NULL; +} + +void BKE_id_attributes_active_set(ID *id, CustomDataLayer *active_layer) +{ + DomainInfo info[ATTR_DOMAIN_NUM]; + get_domains(id, info); + + int index = 0; + + for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) { + CustomData *customdata = info[domain].customdata; + if (customdata) { + for (int i = 0; i < customdata->totlayer; i++) { + CustomDataLayer *layer = &customdata->layers[i]; + if (layer == active_layer) { + *BKE_id_attributes_active_index_p(id) = index; + return; + } + if (CD_MASK_PROP_ALL & CD_TYPE_AS_MASK(layer->type)) { + index++; + } + } + } + } +} + +int *BKE_id_attributes_active_index_p(ID *id) +{ + switch (GS(id->name)) { + case ID_PT: { + return &((PointCloud *)id)->attributes_active_index; + } + case ID_ME: { + return &((Mesh *)id)->attributes_active_index; + } + case ID_HA: { + return &((Hair *)id)->attributes_active_index; + } + default: + return NULL; + } +} + +CustomData *BKE_id_attributes_iterator_next_domain(ID *id, CustomDataLayer *layers) +{ + DomainInfo info[ATTR_DOMAIN_NUM]; + get_domains(id, info); + + bool use_next = (layers == NULL); + + for (AttributeDomain domain = 0; domain < ATTR_DOMAIN_NUM; domain++) { + CustomData *customdata = info[domain].customdata; + if (customdata && customdata->layers) { + if (customdata->layers == layers) { + use_next = true; + } + else if (use_next) { + return customdata; + } + } + } + + return NULL; +} diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index b35d2b199aa..a816e4354b8 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -52,6 +52,8 @@ #include "RE_render_ext.h" /* RE_texture_evaluate */ +#include "BLO_read_write.h" + static void brush_init_data(ID *id) { Brush *brush = (Brush *)id; @@ -196,6 +198,163 @@ static void brush_foreach_id(ID *id, LibraryForeachIDData *data) BKE_texture_mtex_foreach_id(data, &brush->mask_mtex); } +static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Brush *brush = (Brush *)id; + if (brush->id.us > 0 || BLO_write_is_undo(writer)) { + BLO_write_id_struct(writer, Brush, id_address, &brush->id); + BKE_id_blend_write(writer, &brush->id); + + if (brush->curve) { + BKE_curvemapping_blend_write(writer, brush->curve); + } + + if (brush->gpencil_settings) { + BLO_write_struct(writer, BrushGpencilSettings, brush->gpencil_settings); + + if (brush->gpencil_settings->curve_sensitivity) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_sensitivity); + } + if (brush->gpencil_settings->curve_strength) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_strength); + } + if (brush->gpencil_settings->curve_jitter) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_jitter); + } + if (brush->gpencil_settings->curve_rand_pressure) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_pressure); + } + if (brush->gpencil_settings->curve_rand_strength) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_strength); + } + if (brush->gpencil_settings->curve_rand_uv) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_uv); + } + if (brush->gpencil_settings->curve_rand_hue) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_hue); + } + if (brush->gpencil_settings->curve_rand_saturation) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_saturation); + } + if (brush->gpencil_settings->curve_rand_value) { + BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_value); + } + } + if (brush->gradient) { + BLO_write_struct(writer, ColorBand, brush->gradient); + } + } +} + +static void brush_blend_read_data(BlendDataReader *reader, ID *id) +{ + Brush *brush = (Brush *)id; + + /* fallof curve */ + BLO_read_data_address(reader, &brush->curve); + + BLO_read_data_address(reader, &brush->gradient); + + if (brush->curve) { + BKE_curvemapping_blend_read(reader, brush->curve); + } + else { + BKE_brush_curve_preset(brush, CURVE_PRESET_SHARP); + } + + /* grease pencil */ + BLO_read_data_address(reader, &brush->gpencil_settings); + if (brush->gpencil_settings != NULL) { + BLO_read_data_address(reader, &brush->gpencil_settings->curve_sensitivity); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_strength); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_jitter); + + BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_pressure); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_strength); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_uv); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_hue); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_saturation); + BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_value); + + if (brush->gpencil_settings->curve_sensitivity) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_sensitivity); + } + + if (brush->gpencil_settings->curve_strength) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_strength); + } + + if (brush->gpencil_settings->curve_jitter) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_jitter); + } + + if (brush->gpencil_settings->curve_rand_pressure) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_pressure); + } + + if (brush->gpencil_settings->curve_rand_strength) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_strength); + } + + if (brush->gpencil_settings->curve_rand_uv) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_uv); + } + + if (brush->gpencil_settings->curve_rand_hue) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_hue); + } + + if (brush->gpencil_settings->curve_rand_saturation) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_saturation); + } + + if (brush->gpencil_settings->curve_rand_value) { + BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_value); + } + } + + brush->preview = NULL; + brush->icon_imbuf = NULL; +} + +static void brush_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Brush *brush = (Brush *)id; + + /* brush->(mask_)mtex.obj is ignored on purpose? */ + BLO_read_id_address(reader, brush->id.lib, &brush->mtex.tex); + BLO_read_id_address(reader, brush->id.lib, &brush->mask_mtex.tex); + BLO_read_id_address(reader, brush->id.lib, &brush->clone.image); + BLO_read_id_address(reader, brush->id.lib, &brush->toggle_brush); + BLO_read_id_address(reader, brush->id.lib, &brush->paint_curve); + + /* link default grease pencil palette */ + if (brush->gpencil_settings != NULL) { + if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) { + BLO_read_id_address(reader, brush->id.lib, &brush->gpencil_settings->material); + + if (!brush->gpencil_settings->material) { + brush->gpencil_settings->flag &= ~GP_BRUSH_MATERIAL_PINNED; + } + } + else { + brush->gpencil_settings->material = NULL; + } + } +} + +static void brush_blend_read_expand(BlendExpander *expander, ID *id) +{ + Brush *brush = (Brush *)id; + BLO_expand(expander, brush->mtex.tex); + BLO_expand(expander, brush->mask_mtex.tex); + BLO_expand(expander, brush->clone.image); + BLO_expand(expander, brush->paint_curve); + if (brush->gpencil_settings != NULL) { + BLO_expand(expander, brush->gpencil_settings->material); + } +} + IDTypeInfo IDType_ID_BR = { .id_code = ID_BR, .id_filter = FILTER_ID_BR, @@ -213,10 +372,10 @@ IDTypeInfo IDType_ID_BR = { .foreach_id = brush_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = brush_blend_write, + .blend_read_data = brush_blend_read_data, + .blend_read_lib = brush_blend_read_lib, + .blend_read_expand = brush_blend_read_expand, }; static RNG *brush_rng; @@ -1548,10 +1707,12 @@ void BKE_brush_sculpt_reset(Brush *br) break; case SCULPT_TOOL_SCRAPE: case SCULPT_TOOL_FILL: - br->alpha = 1.0f; + br->alpha = 0.7f; + br->area_radius_factor = 1.0f; br->spacing = 7; br->flag |= BRUSH_ACCUMULATE; br->flag |= BRUSH_INVERT_TO_SCRAPE_FILL; + br->flag2 |= BRUSH_AREA_RADIUS_PRESSURE; break; case SCULPT_TOOL_ROTATE: br->alpha = 1.0; diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index bea8fdd5719..7440cc1f735 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -963,7 +963,6 @@ static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon, int faces_num_active) { BVHTree *tree = NULL; - int i; if (faces_num) { if (faces_mask) { @@ -978,7 +977,7 @@ static BVHTree *bvhtree_from_mesh_faces_create_tree(float epsilon, tree = BLI_bvhtree_new(faces_num_active, epsilon, tree_type, axis); if (tree) { if (vert && face) { - for (i = 0; i < faces_num; i++) { + for (int i = 0; i < faces_num; i++) { float co[4][3]; if (faces_mask && !BLI_BITMAP_TEST_BOOL(faces_mask, i)) { continue; diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index f3386df03c8..9475ba7efcf 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -39,6 +39,7 @@ #include "BLT_translation.h" +#include "BKE_anim_data.h" #include "BKE_cachefile.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" @@ -48,6 +49,8 @@ #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + #ifdef WITH_ALEMBIC # include "ABC_alembic.h" #endif @@ -85,6 +88,37 @@ static void cache_file_free_data(ID *id) BLI_freelistN(&cache_file->object_paths); } +static void cache_file_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + CacheFile *cache_file = (CacheFile *)id; + if (cache_file->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + BLI_listbase_clear(&cache_file->object_paths); + cache_file->handle = NULL; + memset(cache_file->handle_filepath, 0, sizeof(cache_file->handle_filepath)); + cache_file->handle_readers = NULL; + + BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id); + + if (cache_file->adt) { + BKE_animdata_blend_write(writer, cache_file->adt); + } + } +} + +static void cache_file_blend_read_data(BlendDataReader *reader, ID *id) +{ + CacheFile *cache_file = (CacheFile *)id; + BLI_listbase_clear(&cache_file->object_paths); + cache_file->handle = NULL; + cache_file->handle_filepath[0] = '\0'; + cache_file->handle_readers = NULL; + + /* relink animdata */ + BLO_read_data_address(reader, &cache_file->adt); + BKE_animdata_blend_read_data(reader, cache_file->adt); +} + IDTypeInfo IDType_ID_CF = { .id_code = ID_CF, .id_filter = FILTER_ID_CF, @@ -102,8 +136,8 @@ IDTypeInfo IDType_ID_CF = { .foreach_id = NULL, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, + .blend_write = cache_file_blend_write, + .blend_read_data = cache_file_blend_read_data, .blend_read_lib = NULL, .blend_read_expand = NULL, }; diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 45d44a6829e..4fe3ddc81a1 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -24,6 +24,9 @@ #include <stddef.h> #include <stdlib.h> +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_ID.h" #include "DNA_camera_types.h" #include "DNA_defaults.h" @@ -38,6 +41,7 @@ #include "BLI_string.h" #include "BLI_utildefines.h" +#include "BKE_anim_data.h" #include "BKE_camera.h" #include "BKE_idtype.h" #include "BKE_layer.h" @@ -54,6 +58,8 @@ #include "MEM_guardedalloc.h" +#include "BLO_read_write.h" + /* -------------------------------------------------------------------- */ /** \name Camera Data-Block * \{ */ @@ -113,6 +119,67 @@ static void camera_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void camera_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Camera *cam = (Camera *)id; + if (cam->id.us > 0 || BLO_write_is_undo(writer)) { + /* write LibData */ + BLO_write_id_struct(writer, Camera, id_address, &cam->id); + BKE_id_blend_write(writer, &cam->id); + + if (cam->adt) { + BKE_animdata_blend_write(writer, cam->adt); + } + + LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) { + BLO_write_struct(writer, CameraBGImage, bgpic); + } + } +} + +static void camera_blend_read_data(BlendDataReader *reader, ID *id) +{ + Camera *ca = (Camera *)id; + BLO_read_data_address(reader, &ca->adt); + BKE_animdata_blend_read_data(reader, ca->adt); + + BLO_read_list(reader, &ca->bg_images); + + LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) { + bgpic->iuser.ok = 1; + bgpic->iuser.scene = NULL; + } +} + +static void camera_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Camera *ca = (Camera *)id; + BLO_read_id_address(reader, ca->id.lib, &ca->ipo); /* deprecated, for versioning */ + + BLO_read_id_address(reader, ca->id.lib, &ca->dof_ob); /* deprecated, for versioning */ + BLO_read_id_address(reader, ca->id.lib, &ca->dof.focus_object); + + LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) { + BLO_read_id_address(reader, ca->id.lib, &bgpic->ima); + BLO_read_id_address(reader, ca->id.lib, &bgpic->clip); + } +} + +static void camera_blend_read_expand(BlendExpander *expander, ID *id) +{ + Camera *ca = (Camera *)id; + BLO_expand(expander, ca->ipo); // XXX deprecated - old animation system + + LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) { + if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) { + BLO_expand(expander, bgpic->ima); + } + else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) { + BLO_expand(expander, bgpic->ima); + } + } +} + IDTypeInfo IDType_ID_CA = { .id_code = ID_CA, .id_filter = FILTER_ID_CA, @@ -130,10 +197,10 @@ IDTypeInfo IDType_ID_CA = { .foreach_id = camera_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = camera_blend_write, + .blend_read_data = camera_blend_read_data, + .blend_read_lib = camera_blend_read_lib, + .blend_read_expand = camera_blend_read_expand, }; /** \} */ @@ -527,9 +594,8 @@ typedef struct CameraViewFrameData { static void camera_to_frame_view_cb(const float co[3], void *user_data) { CameraViewFrameData *data = (CameraViewFrameData *)user_data; - unsigned int i; - for (i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) { + for (uint i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) { const float nd = dist_signed_squared_to_plane_v3(co, data->plane_tx[i]); CLAMP_MAX(data->dist_vals_sq[i], nd); } @@ -548,7 +614,6 @@ static void camera_frame_fit_data_init(const Scene *scene, CameraViewFrameData *data) { float camera_rotmat_transposed_inversed[4][4]; - unsigned int i; /* setup parameters */ BKE_camera_params_init(params); @@ -585,7 +650,7 @@ static void camera_frame_fit_data_init(const Scene *scene, NULL); /* Rotate planes and get normals from them */ - for (i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) { + for (uint i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) { mul_m4_v4(camera_rotmat_transposed_inversed, data->plane_tx[i]); normalize_v3_v3(data->normal_tx[i], data->plane_tx[i]); } @@ -606,7 +671,6 @@ static bool camera_frame_fit_calc_from_data(CameraParams *params, float *r_scale) { float plane_tx[CAMERA_VIEWFRAME_NUM_PLANES][4]; - unsigned int i; if (data->tot <= 1) { return false; @@ -620,7 +684,7 @@ static bool camera_frame_fit_calc_from_data(CameraParams *params, float scale_diff; /* apply the dist-from-plane's to the transformed plane points */ - for (i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) { + for (int i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) { dists[i] = sqrtf_signed(data->dist_vals_sq[i]); } @@ -648,7 +712,7 @@ static bool camera_frame_fit_calc_from_data(CameraParams *params, float plane_isect_pt_1[3], plane_isect_pt_2[3]; /* apply the dist-from-plane's to the transformed plane points */ - for (i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) { + for (int i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) { float co[3]; mul_v3_v3fl(co, data->normal_tx[i], sqrtf_signed(data->dist_vals_sq[i])); plane_from_point_normal_v3(plane_tx[i], co, data->normal_tx[i]); diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 62e2294345d..770a9379e2d 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -172,24 +172,18 @@ void cloth_init(ClothModifierData *clmd) static BVHTree *bvhtree_build_from_cloth(ClothModifierData *clmd, float epsilon) { - unsigned int i; - BVHTree *bvhtree; - Cloth *cloth; - ClothVertex *verts; - const MVertTri *vt; - if (!clmd) { return NULL; } - cloth = clmd->clothObject; + Cloth *cloth = clmd->clothObject; if (!cloth) { return NULL; } - verts = cloth->verts; - vt = cloth->tri; + ClothVertex *verts = cloth->verts; + const MVertTri *vt = cloth->tri; /* in the moment, return zero if no faces there */ if (!cloth->primitive_num) { @@ -197,11 +191,11 @@ static BVHTree *bvhtree_build_from_cloth(ClothModifierData *clmd, float epsilon) } /* create quadtree with k=26 */ - bvhtree = BLI_bvhtree_new(cloth->primitive_num, epsilon, 4, 26); + BVHTree *bvhtree = BLI_bvhtree_new(cloth->primitive_num, epsilon, 4, 26); /* fill tree */ if (clmd->hairdata == NULL) { - for (i = 0; i < cloth->primitive_num; i++, vt++) { + for (int i = 0; i < cloth->primitive_num; i++, vt++) { float co[3][3]; copy_v3_v3(co[0], verts[vt->tri[0]].xold); @@ -214,7 +208,7 @@ static BVHTree *bvhtree_build_from_cloth(ClothModifierData *clmd, float epsilon) else { MEdge *edges = cloth->edges; - for (i = 0; i < cloth->primitive_num; i++) { + for (int i = 0; i < cloth->primitive_num; i++) { float co[2][3]; copy_v3_v3(co[0], verts[edges[i].v1].xold); @@ -997,8 +991,7 @@ BLI_INLINE void spring_verts_ordered_set(ClothSpring *spring, int v0, int v1) static void cloth_free_edgelist(LinkNodePair *edgelist, unsigned int mvert_num) { if (edgelist) { - unsigned int i; - for (i = 0; i < mvert_num; i++) { + for (uint i = 0; i < mvert_num; i++) { BLI_linklist_free(edgelist[i].list, NULL); } diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 115980d577e..72525272254 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -114,13 +114,11 @@ BVHTree *bvhtree_build_from_mvert(const MVert *mvert, int tri_num, float epsilon) { - BVHTree *tree; - const MVertTri *vt; - int i; - - tree = BLI_bvhtree_new(tri_num, epsilon, 4, 26); + BVHTree *tree = BLI_bvhtree_new(tri_num, epsilon, 4, 26); /* fill tree */ + int i; + const MVertTri *vt; for (i = 0, vt = tri; i < tri_num; i++, vt++) { float co[3][3]; @@ -144,8 +142,6 @@ void bvhtree_update_from_mvert(BVHTree *bvhtree, int tri_num, bool moving) { - const MVertTri *vt; - int i; if ((bvhtree == NULL) || (mvert == NULL)) { return; @@ -155,6 +151,8 @@ void bvhtree_update_from_mvert(BVHTree *bvhtree, moving = false; } + const MVertTri *vt; + int i; for (i = 0, vt = tri; i < tri_num; i++, vt++) { float co[3][3]; bool ret; diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 09731c15c0a..77a29bf41b8 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -347,8 +347,7 @@ void BKE_curvemap_reset(CurveMap *cuma, const rctf *clipr, int preset, int slope cuma->curve[1].y = 1; break; case CURVE_PRESET_MID9: { - int i; - for (i = 0; i < cuma->totpoint; i++) { + for (int i = 0; i < cuma->totpoint; i++) { cuma->curve[i].x = i / ((float)cuma->totpoint - 1); cuma->curve[i].y = 0.5; } @@ -421,8 +420,7 @@ void BKE_curvemap_reset(CurveMap *cuma, const rctf *clipr, int preset, int slope const int num_points = cuma->totpoint * 2 - 1; CurveMapPoint *new_points = MEM_mallocN(num_points * sizeof(CurveMapPoint), "curve symmetric points"); - int i; - for (i = 0; i < cuma->totpoint; i++) { + for (int i = 0; i < cuma->totpoint; i++) { const int src_last_point = cuma->totpoint - i - 1; const int dst_last_point = num_points - i - 1; new_points[i] = cuma->curve[src_last_point]; @@ -969,12 +967,9 @@ void BKE_curvemapping_changed_all(CurveMapping *cumap) /* table should be verified */ float BKE_curvemap_evaluateF(const CurveMapping *cumap, const CurveMap *cuma, float value) { - float fi; - int i; - /* index in table */ - fi = (value - cuma->mintable) * cuma->range; - i = (int)fi; + float fi = (value - cuma->mintable) * cuma->range; + int i = (int)fi; /* fi is table float index and should check against table range i.e. [0.0 CM_TABLE] */ if (fi < 0.0f || fi > CM_TABLE) { diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index ee386b3403b..fc1b4d82c20 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -845,7 +845,8 @@ static void childof_new_data(void *cdata) bChildOfConstraint *data = (bChildOfConstraint *)cdata; data->flag = (CHILDOF_LOCX | CHILDOF_LOCY | CHILDOF_LOCZ | CHILDOF_ROTX | CHILDOF_ROTY | - CHILDOF_ROTZ | CHILDOF_SIZEX | CHILDOF_SIZEY | CHILDOF_SIZEZ); + CHILDOF_ROTZ | CHILDOF_SIZEX | CHILDOF_SIZEY | CHILDOF_SIZEZ | + CHILDOF_SET_INVERSE); unit_m4(data->invmat); } @@ -3811,7 +3812,6 @@ static void transform_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t float newloc[3], newrot[3][3], neweul[3], newsize[3]; float dbuf[4], sval[3]; float *const dvec = dbuf + 1; - int i; /* obtain target effect */ switch (data->from) { @@ -3854,7 +3854,7 @@ static void transform_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t /* determine where in range current transforms lie */ if (data->expo) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { if (from_max[i] - from_min[i]) { sval[i] = (dvec[i] - from_min[i]) / (from_max[i] - from_min[i]); } @@ -3865,7 +3865,7 @@ static void transform_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t } else { /* clamp transforms out of range */ - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { CLAMP(dvec[i], from_min[i], from_max[i]); if (from_max[i] - from_min[i]) { sval[i] = (dvec[i] - from_min[i]) / (from_max[i] - from_min[i]); @@ -3881,7 +3881,7 @@ static void transform_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t case TRANS_SCALE: to_min = data->to_min_scale; to_max = data->to_max_scale; - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { newsize[i] = to_min[i] + (sval[(int)data->map[i]] * (to_max[i] - to_min[i])); } switch (data->mix_mode_scale) { @@ -3897,7 +3897,7 @@ static void transform_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t case TRANS_ROTATION: to_min = data->to_min_rot; to_max = data->to_max_rot; - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { neweul[i] = to_min[i] + (sval[(int)data->map[i]] * (to_max[i] - to_min[i])); } switch (data->mix_mode_rot) { @@ -3924,7 +3924,7 @@ static void transform_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t default: to_min = data->to_min; to_max = data->to_max; - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { newloc[i] = (to_min[i] + (sval[(int)data->map[i]] * (to_max[i] - to_min[i]))); } switch (data->mix_mode_loc) { diff --git a/source/blender/blenkernel/intern/crazyspace.c b/source/blender/blenkernel/intern/crazyspace.c index e4f851819a8..01c05c62b70 100644 --- a/source/blender/blenkernel/intern/crazyspace.c +++ b/source/blender/blenkernel/intern/crazyspace.c @@ -194,30 +194,22 @@ void BKE_crazyspace_set_quats_mesh(Mesh *me, float (*mappedcos)[3], float (*quats)[4]) { - int i; - MVert *mvert; - MLoop *mloop; - MPoly *mp; - - mvert = me->mvert; - for (i = 0; i < me->totvert; i++, mvert++) { + MVert *mvert = me->mvert; + for (int i = 0; i < me->totvert; i++, mvert++) { mvert->flag &= ~ME_VERT_TMP_TAG; } /* first store two sets of tangent vectors in vertices, we derive it just from the face-edges */ mvert = me->mvert; - mp = me->mpoly; - mloop = me->mloop; - - for (i = 0; i < me->totpoly; i++, mp++) { - MLoop *ml_prev, *ml_curr, *ml_next; - int j; + MPoly *mp = me->mpoly; + MLoop *mloop = me->mloop; - ml_next = &mloop[mp->loopstart]; - ml_curr = &ml_next[mp->totloop - 1]; - ml_prev = &ml_next[mp->totloop - 2]; + for (int i = 0; i < me->totpoly; i++, mp++) { + MLoop *ml_next = &mloop[mp->loopstart]; + MLoop *ml_curr = &ml_next[mp->totloop - 1]; + MLoop *ml_prev = &ml_next[mp->totloop - 2]; - for (j = 0; j < mp->totloop; j++) { + for (int j = 0; j < mp->totloop; j++) { if ((mvert[ml_curr->v].flag & ME_VERT_TMP_TAG) == 0) { const float *co_prev, *co_curr, *co_next; /* orig */ const float *vd_prev, *vd_curr, *vd_next; /* deform */ diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 7fe8834c2ec..dfa8d65d117 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -28,12 +28,16 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" +#include "BLI_endian_switch.h" #include "BLI_ghash.h" #include "BLI_math.h" #include "BLI_utildefines.h" #include "BLT_translation.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_anim_types.h" #include "DNA_curve_types.h" #include "DNA_defaults.h" @@ -44,6 +48,7 @@ #include "DNA_object_types.h" #include "DNA_vfont_types.h" +#include "BKE_anim_data.h" #include "BKE_curve.h" #include "BKE_displist.h" #include "BKE_font.h" @@ -59,6 +64,8 @@ #include "CLG_log.h" +#include "BLO_read_write.h" + /* globals */ /* local */ @@ -131,6 +138,158 @@ static void curve_foreach_id(ID *id, LibraryForeachIDData *data) BKE_LIB_FOREACHID_PROCESS(data, curve->vfontbi, IDWALK_CB_USER); } +static void curve_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Curve *cu = (Curve *)id; + if (cu->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + cu->editnurb = NULL; + cu->editfont = NULL; + cu->batch_cache = NULL; + + /* write LibData */ + BLO_write_id_struct(writer, Curve, id_address, &cu->id); + BKE_id_blend_write(writer, &cu->id); + + /* direct data */ + BLO_write_pointer_array(writer, cu->totcol, cu->mat); + if (cu->adt) { + BKE_animdata_blend_write(writer, cu->adt); + } + + if (cu->vfont) { + BLO_write_raw(writer, cu->len + 1, cu->str); + BLO_write_struct_array(writer, CharInfo, cu->len_char32 + 1, cu->strinfo); + BLO_write_struct_array(writer, TextBox, cu->totbox, cu->tb); + } + else { + /* is also the order of reading */ + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { + BLO_write_struct(writer, Nurb, nu); + } + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { + if (nu->type == CU_BEZIER) { + BLO_write_struct_array(writer, BezTriple, nu->pntsu, nu->bezt); + } + else { + BLO_write_struct_array(writer, BPoint, nu->pntsu * nu->pntsv, nu->bp); + if (nu->knotsu) { + BLO_write_float_array(writer, KNOTSU(nu), nu->knotsu); + } + if (nu->knotsv) { + BLO_write_float_array(writer, KNOTSV(nu), nu->knotsv); + } + } + } + } + } +} + +static void switch_endian_knots(Nurb *nu) +{ + if (nu->knotsu) { + BLI_endian_switch_float_array(nu->knotsu, KNOTSU(nu)); + } + if (nu->knotsv) { + BLI_endian_switch_float_array(nu->knotsv, KNOTSV(nu)); + } +} + +static void curve_blend_read_data(BlendDataReader *reader, ID *id) +{ + Curve *cu = (Curve *)id; + BLO_read_data_address(reader, &cu->adt); + BKE_animdata_blend_read_data(reader, cu->adt); + + /* Protect against integer overflow vulnerability. */ + CLAMP(cu->len_char32, 0, INT_MAX - 4); + + BLO_read_pointer_array(reader, (void **)&cu->mat); + + BLO_read_data_address(reader, &cu->str); + BLO_read_data_address(reader, &cu->strinfo); + BLO_read_data_address(reader, &cu->tb); + + if (cu->vfont == NULL) { + BLO_read_list(reader, &(cu->nurb)); + } + else { + cu->nurb.first = cu->nurb.last = NULL; + + TextBox *tb = MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "TextBoxread"); + if (cu->tb) { + memcpy(tb, cu->tb, cu->totbox * sizeof(TextBox)); + MEM_freeN(cu->tb); + cu->tb = tb; + } + else { + cu->totbox = 1; + cu->actbox = 1; + cu->tb = tb; + cu->tb[0].w = cu->linewidth; + } + if (cu->wordspace == 0.0f) { + cu->wordspace = 1.0f; + } + } + + cu->editnurb = NULL; + cu->editfont = NULL; + cu->batch_cache = NULL; + + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { + BLO_read_data_address(reader, &nu->bezt); + BLO_read_data_address(reader, &nu->bp); + BLO_read_data_address(reader, &nu->knotsu); + BLO_read_data_address(reader, &nu->knotsv); + if (cu->vfont == NULL) { + nu->charidx = 0; + } + + if (BLO_read_requires_endian_switch(reader)) { + switch_endian_knots(nu); + } + } + cu->texflag &= ~CU_AUTOSPACE_EVALUATED; +} + +static void curve_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Curve *cu = (Curve *)id; + for (int a = 0; a < cu->totcol; a++) { + BLO_read_id_address(reader, cu->id.lib, &cu->mat[a]); + } + + BLO_read_id_address(reader, cu->id.lib, &cu->bevobj); + BLO_read_id_address(reader, cu->id.lib, &cu->taperobj); + BLO_read_id_address(reader, cu->id.lib, &cu->textoncurve); + BLO_read_id_address(reader, cu->id.lib, &cu->vfont); + BLO_read_id_address(reader, cu->id.lib, &cu->vfontb); + BLO_read_id_address(reader, cu->id.lib, &cu->vfonti); + BLO_read_id_address(reader, cu->id.lib, &cu->vfontbi); + + BLO_read_id_address(reader, cu->id.lib, &cu->ipo); // XXX deprecated - old animation system + BLO_read_id_address(reader, cu->id.lib, &cu->key); +} + +static void curve_blend_read_expand(BlendExpander *expander, ID *id) +{ + Curve *cu = (Curve *)id; + for (int a = 0; a < cu->totcol; a++) { + BLO_expand(expander, cu->mat[a]); + } + + BLO_expand(expander, cu->vfont); + BLO_expand(expander, cu->vfontb); + BLO_expand(expander, cu->vfonti); + BLO_expand(expander, cu->vfontbi); + BLO_expand(expander, cu->key); + BLO_expand(expander, cu->ipo); // XXX deprecated - old animation system + BLO_expand(expander, cu->bevobj); + BLO_expand(expander, cu->taperobj); + BLO_expand(expander, cu->textoncurve); +} + IDTypeInfo IDType_ID_CU = { .id_code = ID_CU, .id_filter = FILTER_ID_CU, @@ -148,10 +307,10 @@ IDTypeInfo IDType_ID_CU = { .foreach_id = curve_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = curve_blend_write, + .blend_read_data = curve_blend_read_data, + .blend_read_lib = curve_blend_read_lib, + .blend_read_expand = curve_blend_read_expand, }; static int cu_isectLL(const float v1[3], @@ -782,11 +941,10 @@ float BKE_nurb_calc_length(const Nurb *nu, int resolution) /* be sure to call makeknots after this */ void BKE_nurb_points_add(Nurb *nu, int number) { - BPoint *bp; - int i; - nu->bp = MEM_recallocN(nu->bp, (nu->pntsu + number) * sizeof(BPoint)); + BPoint *bp; + int i; for (i = 0, bp = &nu->bp[nu->pntsu]; i < number; i++, bp++) { bp->radius = 1.0f; } @@ -1718,12 +1876,10 @@ static void forward_diff_bezier_cotangent(const float p0[3], * they need to be rotated for this, * * This could also be optimized like BKE_curve_forward_diff_bezier */ - int a; - for (a = 0; a <= it; a++) { + for (int a = 0; a <= it; a++) { float t = (float)a / (float)it; - int i; - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { p[i] = (-6.0f * t + 6.0f) * p0[i] + (18.0f * t - 12.0f) * p1[i] + (-18.0f * t + 6.0f) * p2[i] + (6.0f * t) * p3[i]; } @@ -4074,17 +4230,14 @@ void BKE_nurb_handles_autocalc(Nurb *nu, int flag) const float eps = 0.0001f; const float eps_sq = eps * eps; - BezTriple *bezt2, *bezt1, *bezt0; - int i; - if (nu == NULL || nu->bezt == NULL) { return; } - bezt2 = nu->bezt; - bezt1 = bezt2 + (nu->pntsu - 1); - bezt0 = bezt1 - 1; - i = nu->pntsu; + BezTriple *bezt2 = nu->bezt; + BezTriple *bezt1 = bezt2 + (nu->pntsu - 1); + BezTriple *bezt0 = bezt1 - 1; + int i = nu->pntsu; while (i--) { bool align = false, leftsmall = false, rightsmall = false; @@ -4546,14 +4699,12 @@ void BKE_curve_nurbs_vert_coords_apply_with_mat4(ListBase *lb, const bool constrain_2d) { const float *co = vert_coords[0]; - Nurb *nu; - int i; - for (nu = lb->first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, lb) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; - for (i = 0; i < nu->pntsu; i++, bezt++) { + for (int i = 0; i < nu->pntsu; i++, bezt++) { mul_v3_m4v3(bezt->vec[0], mat, co); co += 3; mul_v3_m4v3(bezt->vec[1], mat, co); @@ -4565,7 +4716,7 @@ void BKE_curve_nurbs_vert_coords_apply_with_mat4(ListBase *lb, else { BPoint *bp = nu->bp; - for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { + for (int i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { mul_v3_m4v3(bp->vec, mat, co); co += 3; } @@ -4655,14 +4806,11 @@ float (*BKE_curve_nurbs_key_vert_coords_alloc(ListBase *lb, float *key, int *r_v void BKE_curve_nurbs_key_vert_tilts_apply(ListBase *lb, const float *key) { - Nurb *nu; - int i; - - for (nu = lb->first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, lb) { if (nu->type == CU_BEZIER) { BezTriple *bezt = nu->bezt; - for (i = 0; i < nu->pntsu; i++, bezt++) { + for (int i = 0; i < nu->pntsu; i++, bezt++) { bezt->tilt = key[9]; bezt->radius = key[10]; key += KEYELEM_FLOAT_LEN_BEZTRIPLE; @@ -4671,7 +4819,7 @@ void BKE_curve_nurbs_key_vert_tilts_apply(ListBase *lb, const float *key) else { BPoint *bp = nu->bp; - for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { + for (int i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) { bp->tilt = key[3]; bp->radius = key[4]; key += KEYELEM_FLOAT_LEN_BPOINT; @@ -5196,38 +5344,32 @@ void BKE_curve_transform(Curve *cu, const float mat[4][4], const bool do_keys, c void BKE_curve_translate(Curve *cu, const float offset[3], const bool do_keys) { ListBase *nurb_lb = BKE_curve_nurbs_get(cu); - Nurb *nu; - int i; - - for (nu = nurb_lb->first; nu; nu = nu->next) { - BezTriple *bezt; - BPoint *bp; + LISTBASE_FOREACH (Nurb *, nu, nurb_lb) { if (nu->type == CU_BEZIER) { - i = nu->pntsu; - for (bezt = nu->bezt; i--; bezt++) { + int i = nu->pntsu; + for (BezTriple *bezt = nu->bezt; i--; bezt++) { add_v3_v3(bezt->vec[0], offset); add_v3_v3(bezt->vec[1], offset); add_v3_v3(bezt->vec[2], offset); } } else { - i = nu->pntsu * nu->pntsv; - for (bp = nu->bp; i--; bp++) { + int i = nu->pntsu * nu->pntsv; + for (BPoint *bp = nu->bp; i--; bp++) { add_v3_v3(bp->vec, offset); } } } if (do_keys && cu->key) { - KeyBlock *kb; - for (kb = cu->key->block.first; kb; kb = kb->next) { + LISTBASE_FOREACH (KeyBlock *, kb, &cu->key->block) { float *fp = kb->data; int n = kb->totelem; - for (nu = cu->nurb.first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { if (nu->type == CU_BEZIER) { - for (i = nu->pntsu; i && (n -= KEYELEM_ELEM_LEN_BEZTRIPLE) >= 0; i--) { + for (int i = nu->pntsu; i && (n -= KEYELEM_ELEM_LEN_BEZTRIPLE) >= 0; i--) { add_v3_v3(&fp[0], offset); add_v3_v3(&fp[3], offset); add_v3_v3(&fp[6], offset); @@ -5235,7 +5377,7 @@ void BKE_curve_translate(Curve *cu, const float offset[3], const bool do_keys) } } else { - for (i = nu->pntsu * nu->pntsv; i && (n -= KEYELEM_ELEM_LEN_BPOINT) >= 0; i--) { + for (int i = nu->pntsu * nu->pntsv; i && (n -= KEYELEM_ELEM_LEN_BPOINT) >= 0; i--) { add_v3_v3(fp, offset); fp += KEYELEM_FLOAT_LEN_BPOINT; } @@ -5251,17 +5393,14 @@ void BKE_curve_material_index_remove(Curve *cu, int index) if (curvetype == OB_FONT) { struct CharInfo *info = cu->strinfo; - int i; - for (i = cu->len_char32 - 1; i >= 0; i--, info++) { + for (int i = cu->len_char32 - 1; i >= 0; i--, info++) { if (info->mat_nr && info->mat_nr >= index) { info->mat_nr--; } } } else { - Nurb *nu; - - for (nu = cu->nurb.first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { if (nu->mat_nr && nu->mat_nr >= index) { nu->mat_nr--; } @@ -5275,17 +5414,14 @@ bool BKE_curve_material_index_used(Curve *cu, int index) if (curvetype == OB_FONT) { struct CharInfo *info = cu->strinfo; - int i; - for (i = cu->len_char32 - 1; i >= 0; i--, info++) { + for (int i = cu->len_char32 - 1; i >= 0; i--, info++) { if (info->mat_nr == index) { return true; } } } else { - Nurb *nu; - - for (nu = cu->nurb.first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { if (nu->mat_nr == index) { return true; } @@ -5301,15 +5437,12 @@ void BKE_curve_material_index_clear(Curve *cu) if (curvetype == OB_FONT) { struct CharInfo *info = cu->strinfo; - int i; - for (i = cu->len_char32 - 1; i >= 0; i--, info++) { + for (int i = cu->len_char32 - 1; i >= 0; i--, info++) { info->mat_nr = 0; } } else { - Nurb *nu; - - for (nu = cu->nurb.first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { nu->mat_nr = 0; } } diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index e2adaabca33..7c244ed8f58 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -33,7 +33,6 @@ #include "DNA_customdata_types.h" #include "DNA_hair_types.h" #include "DNA_meshdata_types.h" -#include "DNA_pointcloud_types.h" #include "BLI_bitmap.h" #include "BLI_endian_switch.h" @@ -199,9 +198,7 @@ static void layerCopy_mdeformvert(const void *source, void *dest, int count) static void layerFree_mdeformvert(void *data, int count, int size) { - int i; - - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { MDeformVert *dvert = POINTER_OFFSET(data, i * size); if (dvert->dw) { @@ -232,9 +229,7 @@ void bpy_bm_generic_invalidate(struct BPy_BMGeneric *UNUSED(self)) static void layerFree_bmesh_elem_py_ptr(void *data, int count, int size) { - int i; - - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { void **ptr = POINTER_OFFSET(data, i * size); if (*ptr) { bpy_bm_generic_invalidate(*ptr); @@ -416,9 +411,7 @@ static void layerCopy_tface(const void *source, void *dest, int count) { const MTFace *source_tf = (const MTFace *)source; MTFace *dest_tf = (MTFace *)dest; - int i; - - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { dest_tf[i] = source_tf[i]; } } @@ -475,9 +468,8 @@ static void layerDefault_tface(void *data, int count) { static MTFace default_tf = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}}}; MTFace *tf = (MTFace *)data; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { tf[i] = default_tf; } } @@ -523,9 +515,8 @@ static void layerCopy_origspace_face(const void *source, void *dest, int count) { const OrigSpaceFace *source_tf = (const OrigSpaceFace *)source; OrigSpaceFace *dest_tf = (OrigSpaceFace *)dest; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { dest_tf[i] = source_tf[i]; } } @@ -579,9 +570,8 @@ static void layerDefault_origspace_face(void *data, int count) { static OrigSpaceFace default_osf = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}}}; OrigSpaceFace *osf = (OrigSpaceFace *)data; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { osf[i] = default_osf; } } @@ -620,11 +610,10 @@ static void layerSwap_mdisps(void *data, const int *ci) static void layerCopy_mdisps(const void *source, void *dest, int count) { - int i; const MDisps *s = source; MDisps *d = dest; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (s[i].disps) { d[i].disps = MEM_dupallocN(s[i].disps); d[i].hidden = MEM_dupallocN(s[i].hidden); @@ -642,10 +631,9 @@ static void layerCopy_mdisps(const void *source, void *dest, int count) static void layerFree_mdisps(void *data, int count, int UNUSED(size)) { - int i; MDisps *d = data; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (d[i].disps) { MEM_freeN(d[i].disps); } @@ -695,9 +683,8 @@ static size_t layerFilesize_mdisps(CDataFile *UNUSED(cdf), const void *data, int { const MDisps *d = data; size_t size = 0; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { size += sizeof(float[3]) * d[i].totdisp; } @@ -724,11 +711,10 @@ static void layerInterp_paint_mask( static void layerCopy_grid_paint_mask(const void *source, void *dest, int count) { - int i; const GridPaintMask *s = source; GridPaintMask *d = dest; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (s[i].data) { d[i].data = MEM_dupallocN(s[i].data); d[i].level = s[i].level; @@ -742,10 +728,9 @@ static void layerCopy_grid_paint_mask(const void *source, void *dest, int count) static void layerFree_grid_paint_mask(void *data, int count, int UNUSED(size)) { - int i; GridPaintMask *gpm = data; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (gpm[i].data) { MEM_freeN(gpm[i].data); } @@ -895,8 +880,7 @@ static void layerDefault_mloopcol(void *data, int count) { MLoopCol default_mloopcol = {255, 255, 255, 255}; MLoopCol *mlcol = (MLoopCol *)data; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { mlcol[i] = default_mloopcol; } } @@ -1007,13 +991,12 @@ static void layerInterp_mloopuv( { float uv[2]; int flag = 0; - int i; zero_v2(uv); if (sub_weights) { const float *sub_weight = sub_weights; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { float weight = (weights ? weights[i] : 1.0f) * (*sub_weight); const MLoopUV *src = sources[i]; madd_v2_v2fl(uv, src->uv, weight); @@ -1024,7 +1007,7 @@ static void layerInterp_mloopuv( } } else { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { float weight = weights ? weights[i] : 1; const MLoopUV *src = sources[i]; madd_v2_v2fl(uv, src->uv, weight); @@ -1109,13 +1092,11 @@ static void layerInterp_mloop_origspace( const void **sources, const float *weights, const float *sub_weights, int count, void *dest) { float uv[2]; - int i; - zero_v2(uv); if (sub_weights) { const float *sub_weight = sub_weights; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { float weight = weights ? weights[i] : 1.0f; const OrigSpaceLoop *src = sources[i]; madd_v2_v2fl(uv, src->uv, (*sub_weight) * weight); @@ -1123,7 +1104,7 @@ static void layerInterp_mloop_origspace( } } else { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { float weight = weights ? weights[i] : 1.0f; const OrigSpaceLoop *src = sources[i]; madd_v2_v2fl(uv, src->uv, weight); @@ -1139,7 +1120,6 @@ static void layerInterp_mcol( const void **sources, const float *weights, const float *sub_weights, int count, void *dest) { MCol *mc = dest; - int i, j, k; struct { float a; float r; @@ -1147,20 +1127,18 @@ static void layerInterp_mcol( float b; } col[4] = {{0.0f}}; - const float *sub_weight; - if (count <= 0) { return; } - sub_weight = sub_weights; - for (i = 0; i < count; i++) { + const float *sub_weight = sub_weights; + for (int i = 0; i < count; i++) { float weight = weights ? weights[i] : 1; - for (j = 0; j < 4; j++) { + for (int j = 0; j < 4; j++) { if (sub_weights) { const MCol *src = sources[i]; - for (k = 0; k < 4; k++, sub_weight++, src++) { + for (int k = 0; k < 4; k++, sub_weight++, src++) { const float w = (*sub_weight) * weight; col[j].a += src->a * w; col[j].r += src->r * w; @@ -1179,7 +1157,7 @@ static void layerInterp_mcol( } /* Delay writing to the destination in case dest is in sources. */ - for (j = 0; j < 4; j++) { + for (int j = 0; j < 4; j++) { /* Subdivide smooth or fractal can cause problems without clamping * although weights should also not cause this situation */ @@ -1207,9 +1185,8 @@ static void layerDefault_mcol(void *data, int count) { static MCol default_mcol = {255, 255, 255, 255}; MCol *mcol = (MCol *)data; - int i; - for (i = 0; i < 4 * count; i++) { + for (int i = 0; i < 4 * count; i++) { mcol[i] = default_mcol; } } @@ -1225,23 +1202,21 @@ static void layerInterp_bweight(const void **sources, int count, void *dest) { - float f; float **in = (float **)sources; - int i; if (count <= 0) { return; } - f = 0.0f; + float f = 0.0f; if (weights) { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { f += *in[i] * weights[i]; } } else { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { f += *in[i]; } } @@ -1256,23 +1231,22 @@ static void layerInterp_shapekey(const void **sources, int count, void *dest) { - float co[3]; float **in = (float **)sources; - int i; if (count <= 0) { return; } + float co[3]; zero_v3(co); if (weights) { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { madd_v3_v3fl(co, in[i], weights[i]); } } else { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { add_v3_v3(co, in[i]); } } @@ -1284,9 +1258,8 @@ static void layerInterp_shapekey(const void **sources, static void layerDefault_mvert_skin(void *data, int count) { MVertSkin *vs = data; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { copy_v3_fl(vs[i].radius, 0.25f); vs[i].flag = 0; } @@ -1304,13 +1277,13 @@ static void layerInterp_mvert_skin(const void **sources, void *dest) { MVertSkin *vs_dst = dest; - float radius[3], w; - int i; + float radius[3]; zero_v3(radius); - for (i = 0; i < count; i++) { + + for (int i = 0; i < count; i++) { const MVertSkin *vs_src = sources[i]; - w = weights ? weights[i] : 1.0f; + float w = weights ? weights[i] : 1.0f; madd_v3_v3fl(radius, vs_src->radius, w); } @@ -1437,8 +1410,7 @@ static void layerDefault_propcol(void *data, int count) /* Default to white, full alpha. */ MPropCol default_propcol = {{1.0f, 1.0f, 1.0f, 1.0f}}; MPropCol *pcol = (MPropCol *)data; - int i; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { copy_v4_v4(pcol[i].color, default_propcol.color); } } @@ -2003,43 +1975,42 @@ const CustomData_MeshMasks CD_MASK_BAREMESH_ORIGINDEX = { }; const CustomData_MeshMasks CD_MASK_MESH = { .vmask = (CD_MASK_MVERT | CD_MASK_MDEFORMVERT | CD_MASK_MVERT_SKIN | CD_MASK_PAINT_MASK | - CD_MASK_GENERIC_DATA | CD_MASK_PROP_COLOR), - .emask = (CD_MASK_MEDGE | CD_MASK_FREESTYLE_EDGE | CD_MASK_GENERIC_DATA), + CD_MASK_PROP_ALL | CD_MASK_PROP_COLOR), + .emask = (CD_MASK_MEDGE | CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL), .fmask = 0, .lmask = (CD_MASK_MLOOP | CD_MASK_MDISPS | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | - CD_MASK_CUSTOMLOOPNORMAL | CD_MASK_GRID_PAINT_MASK | CD_MASK_GENERIC_DATA), + CD_MASK_CUSTOMLOOPNORMAL | CD_MASK_GRID_PAINT_MASK | CD_MASK_PROP_ALL), .pmask = (CD_MASK_MPOLY | CD_MASK_RECAST | CD_MASK_FACEMAP | CD_MASK_FREESTYLE_FACE | - CD_MASK_GENERIC_DATA | CD_MASK_SCULPT_FACE_SETS), + CD_MASK_PROP_ALL | CD_MASK_SCULPT_FACE_SETS), }; const CustomData_MeshMasks CD_MASK_EDITMESH = { .vmask = (CD_MASK_MDEFORMVERT | CD_MASK_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_SHAPEKEY | - CD_MASK_SHAPE_KEYINDEX | CD_MASK_GENERIC_DATA | CD_MASK_PROP_COLOR), - .emask = (CD_MASK_GENERIC_DATA), + CD_MASK_SHAPE_KEYINDEX | CD_MASK_PROP_ALL | CD_MASK_PROP_COLOR), + .emask = (CD_MASK_PROP_ALL), .fmask = 0, .lmask = (CD_MASK_MDISPS | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_CUSTOMLOOPNORMAL | - CD_MASK_GRID_PAINT_MASK | CD_MASK_GENERIC_DATA), - .pmask = (CD_MASK_RECAST | CD_MASK_FACEMAP | CD_MASK_GENERIC_DATA | CD_MASK_SCULPT_FACE_SETS), + CD_MASK_GRID_PAINT_MASK | CD_MASK_PROP_ALL), + .pmask = (CD_MASK_RECAST | CD_MASK_FACEMAP | CD_MASK_PROP_ALL | CD_MASK_SCULPT_FACE_SETS), }; const CustomData_MeshMasks CD_MASK_DERIVEDMESH = { .vmask = (CD_MASK_ORIGINDEX | CD_MASK_MDEFORMVERT | CD_MASK_SHAPEKEY | CD_MASK_MVERT_SKIN | - CD_MASK_ORCO | CD_MASK_CLOTH_ORCO | CD_MASK_GENERIC_DATA | CD_MASK_PROP_COLOR), - .emask = (CD_MASK_ORIGINDEX | CD_MASK_FREESTYLE_EDGE | CD_MASK_GENERIC_DATA), + CD_MASK_ORCO | CD_MASK_CLOTH_ORCO | CD_MASK_PROP_ALL | CD_MASK_PROP_COLOR), + .emask = (CD_MASK_ORIGINDEX | CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL), .fmask = (CD_MASK_ORIGINDEX | CD_MASK_ORIGSPACE | CD_MASK_PREVIEW_MCOL | CD_MASK_TANGENT), .lmask = (CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_CUSTOMLOOPNORMAL | CD_MASK_PREVIEW_MLOOPCOL | CD_MASK_ORIGSPACE_MLOOP | - CD_MASK_GENERIC_DATA), /* XXX MISSING CD_MASK_MLOOPTANGENT ? */ + CD_MASK_PROP_ALL), /* XXX MISSING CD_MASK_MLOOPTANGENT ? */ .pmask = (CD_MASK_ORIGINDEX | CD_MASK_RECAST | CD_MASK_FREESTYLE_FACE | CD_MASK_FACEMAP | - CD_MASK_GENERIC_DATA | CD_MASK_SCULPT_FACE_SETS), + CD_MASK_PROP_ALL | CD_MASK_SCULPT_FACE_SETS), }; const CustomData_MeshMasks CD_MASK_BMESH = { .vmask = (CD_MASK_MDEFORMVERT | CD_MASK_BWEIGHT | CD_MASK_MVERT_SKIN | CD_MASK_SHAPEKEY | - CD_MASK_SHAPE_KEYINDEX | CD_MASK_PAINT_MASK | CD_MASK_GENERIC_DATA | - CD_MASK_PROP_COLOR), - .emask = (CD_MASK_BWEIGHT | CD_MASK_CREASE | CD_MASK_FREESTYLE_EDGE | CD_MASK_GENERIC_DATA), + CD_MASK_SHAPE_KEYINDEX | CD_MASK_PAINT_MASK | CD_MASK_PROP_ALL | CD_MASK_PROP_COLOR), + .emask = (CD_MASK_BWEIGHT | CD_MASK_CREASE | CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL), .fmask = 0, .lmask = (CD_MASK_MDISPS | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_CUSTOMLOOPNORMAL | - CD_MASK_GRID_PAINT_MASK | CD_MASK_GENERIC_DATA), - .pmask = (CD_MASK_RECAST | CD_MASK_FREESTYLE_FACE | CD_MASK_FACEMAP | CD_MASK_GENERIC_DATA | + CD_MASK_GRID_PAINT_MASK | CD_MASK_PROP_ALL), + .pmask = (CD_MASK_RECAST | CD_MASK_FREESTYLE_FACE | CD_MASK_FACEMAP | CD_MASK_PROP_ALL | CD_MASK_SCULPT_FACE_SETS), }; /** @@ -2058,18 +2029,18 @@ const CustomData_MeshMasks CD_MASK_EVERYTHING = { .vmask = (CD_MASK_MVERT | CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_NORMAL | CD_MASK_MDEFORMVERT | CD_MASK_BWEIGHT | CD_MASK_MVERT_SKIN | CD_MASK_ORCO | CD_MASK_CLOTH_ORCO | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_PAINT_MASK | - CD_MASK_GENERIC_DATA | CD_MASK_PROP_COLOR), + CD_MASK_PROP_ALL | CD_MASK_PROP_COLOR), .emask = (CD_MASK_MEDGE | CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_BWEIGHT | - CD_MASK_CREASE | CD_MASK_FREESTYLE_EDGE | CD_MASK_GENERIC_DATA), + CD_MASK_CREASE | CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL), .fmask = (CD_MASK_MFACE | CD_MASK_ORIGINDEX | CD_MASK_NORMAL | CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_ORIGSPACE | CD_MASK_TANGENT | CD_MASK_TESSLOOPNORMAL | CD_MASK_PREVIEW_MCOL | - CD_MASK_GENERIC_DATA), + CD_MASK_PROP_ALL), .lmask = (CD_MASK_MLOOP | CD_MASK_BM_ELEM_PYPTR | CD_MASK_MDISPS | CD_MASK_NORMAL | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_CUSTOMLOOPNORMAL | CD_MASK_MLOOPTANGENT | CD_MASK_PREVIEW_MLOOPCOL | CD_MASK_ORIGSPACE_MLOOP | - CD_MASK_GRID_PAINT_MASK | CD_MASK_GENERIC_DATA), + CD_MASK_GRID_PAINT_MASK | CD_MASK_PROP_ALL), .pmask = (CD_MASK_MPOLY | CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_NORMAL | - CD_MASK_RECAST | CD_MASK_FACEMAP | CD_MASK_FREESTYLE_FACE | CD_MASK_GENERIC_DATA | + CD_MASK_RECAST | CD_MASK_FACEMAP | CD_MASK_FREESTYLE_FACE | CD_MASK_PROP_ALL | CD_MASK_SCULPT_FACE_SETS), }; @@ -2093,38 +2064,36 @@ static const char *layerType_getName(int type) void customData_mask_layers__print(const CustomData_MeshMasks *mask) { - int i; - printf("verts mask=0x%lx:\n", (long unsigned int)mask->vmask); - for (i = 0; i < CD_NUMTYPES; i++) { + for (int i = 0; i < CD_NUMTYPES; i++) { if (mask->vmask & CD_TYPE_AS_MASK(i)) { printf(" %s\n", layerType_getName(i)); } } printf("edges mask=0x%lx:\n", (long unsigned int)mask->emask); - for (i = 0; i < CD_NUMTYPES; i++) { + for (int i = 0; i < CD_NUMTYPES; i++) { if (mask->emask & CD_TYPE_AS_MASK(i)) { printf(" %s\n", layerType_getName(i)); } } printf("faces mask=0x%lx:\n", (long unsigned int)mask->fmask); - for (i = 0; i < CD_NUMTYPES; i++) { + for (int i = 0; i < CD_NUMTYPES; i++) { if (mask->fmask & CD_TYPE_AS_MASK(i)) { printf(" %s\n", layerType_getName(i)); } } printf("loops mask=0x%lx:\n", (long unsigned int)mask->lmask); - for (i = 0; i < CD_NUMTYPES; i++) { + for (int i = 0; i < CD_NUMTYPES; i++) { if (mask->lmask & CD_TYPE_AS_MASK(i)) { printf(" %s\n", layerType_getName(i)); } } printf("polys mask=0x%lx:\n", (long unsigned int)mask->pmask); - for (i = 0; i < CD_NUMTYPES; i++) { + for (int i = 0; i < CD_NUMTYPES; i++) { if (mask->pmask & CD_TYPE_AS_MASK(i)) { printf(" %s\n", layerType_getName(i)); } @@ -2253,8 +2222,7 @@ bool CustomData_merge(const struct CustomData *source, /* NOTE: Take care of referenced layers by yourself! */ void CustomData_realloc(CustomData *data, int totelem) { - int i; - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { CustomDataLayer *layer = &data->layers[i]; const LayerTypeInfo *typeInfo; if (layer->flag & CD_FLAG_NOFREE) { @@ -2313,9 +2281,7 @@ void CustomData_reset(CustomData *data) void CustomData_free(CustomData *data, int totelem) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { customData_free_layer__internal(&data->layers[i], totelem); } @@ -2329,9 +2295,7 @@ void CustomData_free(CustomData *data, int totelem) void CustomData_free_typemask(struct CustomData *data, int totelem, CustomDataMask mask) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { CustomDataLayer *layer = &data->layers[i]; if (!(mask & CD_TYPE_AS_MASK(layer->type))) { continue; @@ -2350,9 +2314,9 @@ void CustomData_free_typemask(struct CustomData *data, int totelem, CustomDataMa static void customData_update_offsets(CustomData *data) { const LayerTypeInfo *typeInfo; - int i, offset = 0; + int offset = 0; - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { typeInfo = layerType_getInfo(data->layers[i].type); data->layers[i].offset = offset; @@ -2366,9 +2330,7 @@ static void customData_update_offsets(CustomData *data) /* to use when we're in the middle of modifying layers */ static int CustomData_get_layer_index__notypemap(const CustomData *data, int type) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { return i; } @@ -2400,9 +2362,7 @@ int CustomData_get_layer_index_n(const struct CustomData *data, int type, int n) int CustomData_get_named_layer_index(const CustomData *data, int type, const char *name) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { if (STREQ(data->layers[i].name, name)) { return i; @@ -2482,9 +2442,7 @@ int CustomData_get_stencil_layer(const CustomData *data, int type) void CustomData_set_layer_active(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active = n; } @@ -2493,9 +2451,7 @@ void CustomData_set_layer_active(CustomData *data, int type, int n) void CustomData_set_layer_render(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active_rnd = n; } @@ -2504,9 +2460,7 @@ void CustomData_set_layer_render(CustomData *data, int type, int n) void CustomData_set_layer_clone(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active_clone = n; } @@ -2515,9 +2469,7 @@ void CustomData_set_layer_clone(CustomData *data, int type, int n) void CustomData_set_layer_stencil(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active_mask = n; } @@ -2528,9 +2480,7 @@ void CustomData_set_layer_stencil(CustomData *data, int type, int n) * CustomData_get_render_layer_index. */ void CustomData_set_layer_active_index(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active = n - i; } @@ -2539,9 +2489,7 @@ void CustomData_set_layer_active_index(CustomData *data, int type, int n) void CustomData_set_layer_render_index(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active_rnd = n - i; } @@ -2550,9 +2498,7 @@ void CustomData_set_layer_render_index(CustomData *data, int type, int n) void CustomData_set_layer_clone_index(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active_clone = n - i; } @@ -2561,9 +2507,7 @@ void CustomData_set_layer_clone_index(CustomData *data, int type, int n) void CustomData_set_layer_stencil_index(CustomData *data, int type, int n) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].active_mask = n - i; } @@ -2572,9 +2516,7 @@ void CustomData_set_layer_stencil_index(CustomData *data, int type, int n) void CustomData_set_layer_flag(struct CustomData *data, int type, int flag) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { data->layers[i].flag |= flag; } @@ -2759,7 +2701,6 @@ bool CustomData_free_layer(CustomData *data, int type, int totelem, int index) { const int index_first = CustomData_get_layer_index(data, type); const int n = index - index_first; - int i; BLI_assert(index >= index_first); if ((index_first == -1) || (n < 0)) { @@ -2769,14 +2710,14 @@ bool CustomData_free_layer(CustomData *data, int type, int totelem, int index) customData_free_layer__internal(&data->layers[index], totelem); - for (i = index + 1; i < data->totlayer; i++) { + for (int i = index + 1; i < data->totlayer; i++) { data->layers[i - 1] = data->layers[i]; } data->totlayer--; /* if layer was last of type in array, set new active layer */ - i = CustomData_get_layer_index__notypemap(data, type); + int i = CustomData_get_layer_index__notypemap(data, type); if (i != -1) { /* don't decrement zero index */ @@ -2810,8 +2751,7 @@ bool CustomData_free_layer(CustomData *data, int type, int totelem, int index) bool CustomData_free_layer_active(CustomData *data, int type, int totelem) { - int index = 0; - index = CustomData_get_active_layer_index(data, type); + const int index = CustomData_get_active_layer_index(data, type); if (index == -1) { return false; } @@ -2833,9 +2773,9 @@ bool CustomData_has_layer(const CustomData *data, int type) int CustomData_number_of_layers(const CustomData *data, int type) { - int i, number = 0; + int number = 0; - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].type == type) { number++; } @@ -2846,9 +2786,9 @@ int CustomData_number_of_layers(const CustomData *data, int type) int CustomData_number_of_layers_typemask(const CustomData *data, CustomDataMask mask) { - int i, number = 0; + int number = 0; - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (mask & CD_TYPE_AS_MASK(data->layers[i].type)) { number++; } @@ -2861,13 +2801,11 @@ static void *customData_duplicate_referenced_layer_index(CustomData *data, const int layer_index, const int totelem) { - CustomDataLayer *layer; - if (layer_index == -1) { return NULL; } - layer = &data->layers[layer_index]; + CustomDataLayer *layer = &data->layers[layer_index]; if (layer->flag & CD_FLAG_NOFREE) { /* MEM_dupallocN won't work in case of complex layers, like e.g. @@ -2894,10 +2832,8 @@ static void *customData_duplicate_referenced_layer_index(CustomData *data, void *CustomData_duplicate_referenced_layer(CustomData *data, const int type, const int totelem) { - int layer_index; - /* get the layer index of the first layer of type */ - layer_index = CustomData_get_active_layer_index(data, type); + int layer_index = CustomData_get_active_layer_index(data, type); return customData_duplicate_referenced_layer_index(data, layer_index, totelem); } @@ -2907,10 +2843,8 @@ void *CustomData_duplicate_referenced_layer_n(CustomData *data, const int n, const int totelem) { - int layer_index; - /* get the layer index of the desired layer */ - layer_index = CustomData_get_layer_index_n(data, type, n); + int layer_index = CustomData_get_layer_index_n(data, type, n); return customData_duplicate_referenced_layer_index(data, layer_index, totelem); } @@ -2920,26 +2854,21 @@ void *CustomData_duplicate_referenced_layer_named(CustomData *data, const char *name, const int totelem) { - int layer_index; - /* get the layer index of the desired layer */ - layer_index = CustomData_get_named_layer_index(data, type, name); + int layer_index = CustomData_get_named_layer_index(data, type, name); return customData_duplicate_referenced_layer_index(data, layer_index, totelem); } bool CustomData_is_referenced_layer(struct CustomData *data, int type) { - CustomDataLayer *layer; - int layer_index; - /* get the layer index of the first layer of type */ - layer_index = CustomData_get_active_layer_index(data, type); + int layer_index = CustomData_get_active_layer_index(data, type); if (layer_index == -1) { return false; } - layer = &data->layers[layer_index]; + CustomDataLayer *layer = &data->layers[layer_index]; return (layer->flag & CD_FLAG_NOFREE) != 0; } @@ -2980,9 +2909,7 @@ void CustomData_free_temporary(CustomData *data, int totelem) void CustomData_set_only_copy(const struct CustomData *data, CustomDataMask mask) { - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (!(mask & CD_TYPE_AS_MASK(data->layers[i].type))) { data->layers[i].flag |= CD_FLAG_NOCOPY; } @@ -3044,12 +2971,10 @@ static void CustomData_copy_data_layer(const CustomData *source, void CustomData_copy_data_named( const CustomData *source, CustomData *dest, int source_index, int dest_index, int count) { - int src_i, dest_i; - /* copies a layer at a time */ - for (src_i = 0; src_i < source->totlayer; src_i++) { + for (int src_i = 0; src_i < source->totlayer; src_i++) { - dest_i = CustomData_get_named_layer_index( + int dest_i = CustomData_get_named_layer_index( dest, source->layers[src_i].type, source->layers[src_i].name); /* if we found a matching layer, copy the data */ @@ -3062,11 +2987,9 @@ void CustomData_copy_data_named( void CustomData_copy_data( const CustomData *source, CustomData *dest, int source_index, int dest_index, int count) { - int src_i, dest_i; - /* copies a layer at a time */ - dest_i = 0; - for (src_i = 0; src_i < source->totlayer; src_i++) { + int dest_i = 0; + for (int src_i = 0; src_i < source->totlayer; src_i++) { /* find the first dest layer with type >= the source type * (this should work because layers are ordered by type) @@ -3119,12 +3042,9 @@ void CustomData_copy_layer_type_data(const CustomData *source, void CustomData_free_elem(CustomData *data, int index, int count) { - int i; - const LayerTypeInfo *typeInfo; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (!(data->layers[i].flag & CD_FLAG_NOFREE)) { - typeInfo = layerType_getInfo(data->layers[i].type); + const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type); if (typeInfo->free) { size_t offset = (size_t)index * typeInfo->size; @@ -3145,8 +3065,6 @@ void CustomData_interp(const CustomData *source, int count, int dest_index) { - int src_i, dest_i; - int j; const void *source_buf[SOURCE_BUF_SIZE]; const void **sources = source_buf; @@ -3156,8 +3074,8 @@ void CustomData_interp(const CustomData *source, } /* interpolates a layer at a time */ - dest_i = 0; - for (src_i = 0; src_i < source->totlayer; src_i++) { + int dest_i = 0; + for (int src_i = 0; src_i < source->totlayer; src_i++) { const LayerTypeInfo *typeInfo = layerType_getInfo(source->layers[src_i].type); if (!typeInfo->interp) { continue; @@ -3179,7 +3097,7 @@ void CustomData_interp(const CustomData *source, if (dest->layers[dest_i].type == source->layers[src_i].type) { void *src_data = source->layers[src_i].data; - for (j = 0; j < count; j++) { + for (int j = 0; j < count; j++) { sources[j] = POINTER_OFFSET(src_data, (size_t)src_indices[j] * typeInfo->size); } @@ -3212,11 +3130,8 @@ void CustomData_interp(const CustomData *source, */ void CustomData_swap_corners(struct CustomData *data, int index, const int *corner_indices) { - const LayerTypeInfo *typeInfo; - int i; - - for (i = 0; i < data->totlayer; i++) { - typeInfo = layerType_getInfo(data->layers[i].type); + for (int i = 0; i < data->totlayer; i++) { + const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type); if (typeInfo->swap) { const size_t offset = (size_t)index * typeInfo->size; @@ -3231,14 +3146,13 @@ void CustomData_swap_corners(struct CustomData *data, int index, const int *corn */ void CustomData_swap(struct CustomData *data, const int index_a, const int index_b) { - int i; char buff_static[256]; if (index_a == index_b) { return; } - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type); const size_t size = typeInfo->size; const size_t offset_a = size * index_a; @@ -3259,12 +3173,10 @@ void CustomData_swap(struct CustomData *data, const int index_a, const int index void *CustomData_get(const CustomData *data, int index, int type) { - int layer_index; - BLI_assert(index >= 0); /* get the layer index of the active layer of type */ - layer_index = CustomData_get_active_layer_index(data, type); + int layer_index = CustomData_get_active_layer_index(data, type); if (layer_index == -1) { return NULL; } @@ -3277,12 +3189,10 @@ void *CustomData_get(const CustomData *data, int index, int type) void *CustomData_get_n(const CustomData *data, int type, int index, int n) { - int layer_index; - BLI_assert(index >= 0 && n >= 0); /* get the layer index of the first layer of type */ - layer_index = data->typemap[type]; + int layer_index = data->typemap[type]; if (layer_index == -1) { return NULL; } @@ -3436,12 +3346,10 @@ void CustomData_to_bmeshpoly(CustomData *fdata, CustomData *ldata, int totloop) void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *ldata, int total) { - int i; - /* avoid accumulating extra layers */ BLI_assert(!CustomData_from_bmeshpoly_test(fdata, ldata, false)); - for (i = 0; i < ldata->totlayer; i++) { + for (int i = 0; i < ldata->totlayer; i++) { if (ldata->layers[i].type == CD_MLOOPUV) { CustomData_add_layer_named(fdata, CD_MTFACE, CD_CALLOC, NULL, total, ldata->layers[i].name); } @@ -3619,12 +3527,6 @@ bool CustomData_bmesh_merge(const CustomData *source, BMesh *bm, const char htype) { - BMHeader *h; - BMIter iter; - CustomData destold; - void *tmp; - int iter_type; - int totelem; if (CustomData_number_of_layers_typemask(source, mask) == 0) { return false; @@ -3632,7 +3534,7 @@ bool CustomData_bmesh_merge(const CustomData *source, /* copy old layer description so that old data can be copied into * the new allocation */ - destold = *dest; + CustomData destold = *dest; if (destold.layers) { destold.layers = MEM_dupallocN(destold.layers); } @@ -3644,6 +3546,8 @@ bool CustomData_bmesh_merge(const CustomData *source, return false; } + int iter_type; + int totelem; switch (htype) { case BM_VERT: iter_type = BM_VERTS_OF_MESH; @@ -3672,9 +3576,11 @@ bool CustomData_bmesh_merge(const CustomData *source, CustomData_bmesh_init_pool(dest, totelem, htype); if (iter_type != BM_LOOPS_OF_FACE) { + BMHeader *h; + BMIter iter; /*ensure all current elements follow new customdata layout*/ BM_ITER_MESH (h, &iter, bm, iter_type) { - tmp = NULL; + void *tmp = NULL; CustomData_bmesh_copy_data(&destold, dest, h->data, &tmp); CustomData_bmesh_free_block(&destold, &h->data); h->data = tmp; @@ -3683,12 +3589,13 @@ bool CustomData_bmesh_merge(const CustomData *source, else { BMFace *f; BMLoop *l; + BMIter iter; BMIter liter; /*ensure all current elements follow new customdata layout*/ BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - tmp = NULL; + void *tmp = NULL; CustomData_bmesh_copy_data(&destold, dest, l->head.data, &tmp); CustomData_bmesh_free_block(&destold, &l->head.data); l->head.data = tmp; @@ -3707,16 +3614,13 @@ bool CustomData_bmesh_merge(const CustomData *source, void CustomData_bmesh_free_block(CustomData *data, void **block) { - const LayerTypeInfo *typeInfo; - int i; - if (*block == NULL) { return; } - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (!(data->layers[i].flag & CD_FLAG_NOFREE)) { - typeInfo = layerType_getInfo(data->layers[i].type); + const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type); if (typeInfo->free) { int offset = data->layers[i].offset; @@ -3756,7 +3660,6 @@ void CustomData_bmesh_free_block_data(CustomData *data, void *block) static void CustomData_bmesh_alloc_block(CustomData *data, void **block) { - if (*block) { CustomData_bmesh_free_block(data, block); } @@ -3810,13 +3713,11 @@ static void CustomData_bmesh_set_default_n(CustomData *data, void **block, int n void CustomData_bmesh_set_default(CustomData *data, void **block) { - int i; - if (*block == NULL) { CustomData_bmesh_alloc_block(data, block); } - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { CustomData_bmesh_set_default_n(data, block, i); } } @@ -3830,7 +3731,6 @@ void CustomData_bmesh_copy_data_exclude_by_type(const CustomData *source, /* Note that having a version of this function without a 'mask_exclude' * would cause too much duplicate code, so add a check instead. */ const bool no_mask = (mask_exclude == 0); - int dest_i, src_i; if (*dest_block == NULL) { CustomData_bmesh_alloc_block(dest, dest_block); @@ -3840,8 +3740,8 @@ void CustomData_bmesh_copy_data_exclude_by_type(const CustomData *source, } /* copies a layer at a time */ - dest_i = 0; - for (src_i = 0; src_i < source->totlayer; src_i++) { + int dest_i = 0; + for (int src_i = 0; src_i < source->totlayer; src_i++) { /* find the first dest layer with type >= the source type * (this should work because layers are ordered by type) @@ -3898,10 +3798,8 @@ void CustomData_bmesh_copy_data(const CustomData *source, */ void *CustomData_bmesh_get(const CustomData *data, void *block, int type) { - int layer_index; - /* get the layer index of the first layer of type */ - layer_index = CustomData_get_active_layer_index(data, type); + int layer_index = CustomData_get_active_layer_index(data, type); if (layer_index == -1) { return NULL; } @@ -3911,10 +3809,8 @@ void *CustomData_bmesh_get(const CustomData *data, void *block, int type) void *CustomData_bmesh_get_n(const CustomData *data, void *block, int type, int n) { - int layer_index; - /* get the layer index of the first layer of type */ - layer_index = CustomData_get_layer_index(data, type); + int layer_index = CustomData_get_layer_index(data, type); if (layer_index == -1) { return NULL; } @@ -3957,10 +3853,8 @@ bool CustomData_layer_has_interp(const struct CustomData *data, int layer_n) bool CustomData_has_math(const struct CustomData *data) { - int i; - /* interpolates a layer at a time */ - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (CustomData_layer_has_math(data, i)) { return true; } @@ -3972,12 +3866,9 @@ bool CustomData_has_math(const struct CustomData *data) /* a non bmesh version would have to check layer->data */ bool CustomData_bmesh_has_free(const struct CustomData *data) { - const LayerTypeInfo *typeInfo; - int i; - - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (!(data->layers[i].flag & CD_FLAG_NOFREE)) { - typeInfo = layerType_getInfo(data->layers[i].type); + const LayerTypeInfo *typeInfo = layerType_getInfo(data->layers[i].type); if (typeInfo->free) { return true; } @@ -3988,10 +3879,8 @@ bool CustomData_bmesh_has_free(const struct CustomData *data) bool CustomData_has_interp(const struct CustomData *data) { - int i; - /* interpolates a layer at a time */ - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (CustomData_layer_has_interp(data, i)) { return true; } @@ -4002,8 +3891,7 @@ bool CustomData_has_interp(const struct CustomData *data) bool CustomData_has_referenced(const struct CustomData *data) { - int i; - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (data->layers[i].flag & CD_FLAG_NOFREE) { return true; } @@ -4210,16 +4098,13 @@ void CustomData_to_bmesh_block(const CustomData *source, void **dest_block, bool use_default_init) { - const LayerTypeInfo *typeInfo; - int dest_i, src_i; - if (*dest_block == NULL) { CustomData_bmesh_alloc_block(dest, dest_block); } /* copies a layer at a time */ - dest_i = 0; - for (src_i = 0; src_i < source->totlayer; src_i++) { + int dest_i = 0; + for (int src_i = 0; src_i < source->totlayer; src_i++) { /* find the first dest layer with type >= the source type * (this should work because layers are ordered by type) @@ -4242,7 +4127,7 @@ void CustomData_to_bmesh_block(const CustomData *source, const void *src_data = source->layers[src_i].data; void *dest_data = POINTER_OFFSET(*dest_block, offset); - typeInfo = layerType_getInfo(dest->layers[dest_i].type); + const LayerTypeInfo *typeInfo = layerType_getInfo(dest->layers[dest_i].type); const size_t src_offset = (size_t)src_index * typeInfo->size; if (typeInfo->copy) { @@ -4273,11 +4158,9 @@ void CustomData_from_bmesh_block(const CustomData *source, void *src_block, int dest_index) { - int dest_i, src_i; - /* copies a layer at a time */ - dest_i = 0; - for (src_i = 0; src_i < source->totlayer; src_i++) { + int dest_i = 0; + for (int src_i = 0; src_i < source->totlayer; src_i++) { /* find the first dest layer with type >= the source type * (this should work because layers are ordered by type) @@ -4421,24 +4304,15 @@ int CustomData_layertype_layers_max(const int type) return typeInfo->layers_max(); } -static bool CustomData_is_property_layer(int type) -{ - if ((type == CD_PROP_FLOAT) || (type == CD_PROP_INT32) || (type == CD_PROP_STRING)) { - return true; - } - return false; -} - static bool cd_layer_find_dupe(CustomData *data, const char *name, int type, int index) { - int i; /* see if there is a duplicate */ - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { if (i != index) { CustomDataLayer *layer = &data->layers[i]; - if (CustomData_is_property_layer(type)) { - if (CustomData_is_property_layer(layer->type) && STREQ(layer->name, name)) { + if (CD_TYPE_AS_MASK(type) & CD_MASK_PROP_ALL) { + if ((CD_TYPE_AS_MASK(layer->type) & CD_MASK_PROP_ALL) && STREQ(layer->name, name)) { return true; } } @@ -4520,7 +4394,6 @@ bool CustomData_verify_versions(struct CustomData *data, int index) const LayerTypeInfo *typeInfo; CustomDataLayer *layer = &data->layers[index]; bool keeplayer = true; - int i; if (layer->type >= CD_NUMTYPES) { keeplayer = false; /* unknown layer type from future version */ @@ -4548,7 +4421,7 @@ bool CustomData_verify_versions(struct CustomData *data, int index) } if (!keeplayer) { - for (i = index + 1; i < data->totlayer; i++) { + for (int i = index + 1; i < data->totlayer; i++) { data->layers[i - 1] = data->layers[i]; } data->totlayer--; @@ -4576,13 +4449,12 @@ bool CustomData_layer_validate(CustomDataLayer *layer, const uint totitems, cons void CustomData_layers__print(CustomData *data) { - int i; - const CustomDataLayer *layer; printf("{\n"); + int i; + const CustomDataLayer *layer; for (i = 0, layer = data->layers; i < data->totlayer; i++, layer++) { - const char *name = CustomData_layertype_name(layer->type); const int size = CustomData_sizeof(layer->type); const char *structname; @@ -4612,13 +4484,9 @@ static void customdata_external_filename(char filename[FILE_MAX], void CustomData_external_reload(CustomData *data, ID *UNUSED(id), CustomDataMask mask, int totelem) { - CustomDataLayer *layer; - const LayerTypeInfo *typeInfo; - int i; - - for (i = 0; i < data->totlayer; i++) { - layer = &data->layers[i]; - typeInfo = layerType_getInfo(layer->type); + for (int i = 0; i < data->totlayer; i++) { + CustomDataLayer *layer = &data->layers[i]; + const LayerTypeInfo *typeInfo = layerType_getInfo(layer->type); if (!(mask & CD_TYPE_AS_MASK(layer->type))) { /* pass */ @@ -4640,13 +4508,13 @@ void CustomData_external_read(CustomData *data, ID *id, CustomDataMask mask, int CDataFileLayer *blay; char filename[FILE_MAX]; const LayerTypeInfo *typeInfo; - int i, update = 0; + int update = 0; if (!external) { return; } - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); @@ -4674,7 +4542,7 @@ void CustomData_external_read(CustomData *data, ID *id, CustomDataMask mask, int return; } - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); @@ -4716,7 +4584,7 @@ void CustomData_external_write( CDataFile *cdf; CDataFileLayer *blay; const LayerTypeInfo *typeInfo; - int i, update = 0; + int update = 0; char filename[FILE_MAX]; if (!external) { @@ -4724,7 +4592,7 @@ void CustomData_external_write( } /* test if there is anything to write */ - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); @@ -4746,7 +4614,7 @@ void CustomData_external_write( cdf = cdf_create(CDF_TYPE_MESH); - for (i = 0; i < data->totlayer; i++) { + for (int i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); @@ -4768,6 +4636,7 @@ void CustomData_external_write( return; } + int i; for (i = 0; i < data->totlayer; i++) { layer = &data->layers[i]; typeInfo = layerType_getInfo(layer->type); @@ -4844,16 +4713,13 @@ void CustomData_external_add( void CustomData_external_remove(CustomData *data, ID *id, int type, int totelem) { CustomDataExternal *external = data->external; - CustomDataLayer *layer; - // char filename[FILE_MAX]; - int layer_index; // i, remove_file; - layer_index = CustomData_get_active_layer_index(data, type); + int layer_index = CustomData_get_active_layer_index(data, type); if (layer_index == -1) { return; } - layer = &data->layers[layer_index]; + CustomDataLayer *layer = &data->layers[layer_index]; if (!external) { return; @@ -4870,15 +4736,12 @@ void CustomData_external_remove(CustomData *data, ID *id, int type, int totelem) bool CustomData_external_test(CustomData *data, int type) { - CustomDataLayer *layer; - int layer_index; - - layer_index = CustomData_get_active_layer_index(data, type); + int layer_index = CustomData_get_active_layer_index(data, type); if (layer_index == -1) { return false; } - layer = &data->layers[layer_index]; + CustomDataLayer *layer = &data->layers[layer_index]; return (layer->flag & CD_FLAG_EXTERNAL) != 0; } @@ -4974,15 +4837,13 @@ static void customdata_data_transfer_interp_generic(const CustomDataTransferLaye tmp_dst = MEM_mallocN(data_size, __func__); if (count > 1 && !interp_cd) { - int i; - if (data_flag) { /* Boolean case, we can 'interpolate' in two groups, * and choose value from highest weighted group. */ float tot_weight_true = 0.0f; int item_true_idx = -1, item_false_idx = -1; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (check_bit_flag(sources[i], data_size, data_flag)) { tot_weight_true += weights[i]; item_true_idx = i; @@ -4997,7 +4858,7 @@ static void customdata_data_transfer_interp_generic(const CustomDataTransferLaye /* We just choose highest weighted source. */ float max_weight = 0.0f; - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if (weights[i] > max_weight) { max_weight = weights[i]; best_src_idx = i; @@ -5086,7 +4947,6 @@ void CustomData_data_transfer(const MeshPairRemap *me_remap, { MeshPairRemapItem *mapit = me_remap->items; const int totelem = me_remap->items_num; - int i; const int data_type = laymap->data_type; const void *data_src = laymap->data_src; @@ -5126,11 +4986,10 @@ void CustomData_data_transfer(const MeshPairRemap *me_remap, interp = laymap->interp ? laymap->interp : customdata_data_transfer_interp_generic; - for (i = 0; i < totelem; i++, data_dst = POINTER_OFFSET(data_dst, data_step), mapit++) { + for (int i = 0; i < totelem; i++, data_dst = POINTER_OFFSET(data_dst, data_step), mapit++) { const int sources_num = mapit->sources_num; const float mix_factor = laymap->mix_factor * (laymap->mix_weights ? laymap->mix_weights[i] : 1.0f); - int j; if (!sources_num) { /* No sources for this element, skip it. */ @@ -5143,7 +5002,7 @@ void CustomData_data_transfer(const MeshPairRemap *me_remap, tmp_data_src = MEM_reallocN((void *)tmp_data_src, sizeof(*tmp_data_src) * tmp_buff_size); } - for (j = 0; j < sources_num; j++) { + for (int j = 0; j < sources_num; j++) { const size_t src_idx = (size_t)mapit->indices_src[j]; tmp_data_src[j] = POINTER_OFFSET(data_src, (data_step * src_idx) + data_offset); } diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c index 1b35fdd1706..7a3a6ea44a9 100644 --- a/source/blender/blenkernel/intern/data_transfer.c +++ b/source/blender/blenkernel/intern/data_transfer.c @@ -101,13 +101,12 @@ bool BKE_object_data_transfer_get_dttypes_capacity(const int dtdata_types, bool *r_advanced_mixing, bool *r_threshold) { - int i; bool ret = false; *r_advanced_mixing = false; *r_threshold = false; - for (i = 0; (i < DT_TYPE_MAX) && !(ret && *r_advanced_mixing && *r_threshold); i++) { + for (int i = 0; (i < DT_TYPE_MAX) && !(ret && *r_advanced_mixing && *r_threshold); i++) { const int dtdata_type = 1 << i; if (!(dtdata_types & dtdata_type)) { @@ -451,9 +450,7 @@ static void data_transfer_interp_char(const CustomDataTransferLayerMap *laymap, float val_src = 0.0f; const float val_dst = (float)(*data_dst) / 255.0f; - int i; - - for (i = count; i--;) { + for (int i = count; i--;) { val_src += ((float)(*data_src[i]) / 255.0f) * weights[i]; } @@ -1254,7 +1251,6 @@ void BKE_object_data_transfer_layout(struct Depsgraph *depsgraph, { Mesh *me_src; Mesh *me_dst; - int i; const bool use_create = true; /* We always create needed layers here. */ @@ -1272,7 +1268,7 @@ void BKE_object_data_transfer_layout(struct Depsgraph *depsgraph, } /* Check all possible data types. */ - for (i = 0; i < DT_TYPE_MAX; i++) { + for (int i = 0; i < DT_TYPE_MAX; i++) { const int dtdata_type = 1 << i; int cddata_type; int fromlayers, tolayers, fromto_idx; @@ -1410,7 +1406,6 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, Mesh *me_src; /* Assumed always true if not using an evaluated mesh as destination. */ bool dirty_nors_dst = true; - int i; MDeformVert *mdef = NULL; int vg_idx = -1; @@ -1478,7 +1473,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, /* Check all possible data types. * Note item mappings and dest mix weights are cached. */ - for (i = 0; i < DT_TYPE_MAX; i++) { + for (int i = 0; i < DT_TYPE_MAX; i++) { const int dtdata_type = 1 << i; int cddata_type; int fromlayers, tolayers, fromto_idx; @@ -1850,7 +1845,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, data_transfer_dtdata_type_postprocess(ob_src, ob_dst, me_src, me_dst, dtdata_type, changed); } - for (i = 0; i < DATAMAX; i++) { + for (int i = 0; i < DATAMAX; i++) { BKE_mesh_remap_free(&geom_map[i]); MEM_SAFE_FREE(weights[i]); } diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 74a8a4268fc..f7cf4faf7cb 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -200,9 +200,8 @@ void BKE_defvert_copy_index(MDeformVert *dvert_dst, void BKE_defvert_sync(MDeformVert *dvert_dst, const MDeformVert *dvert_src, const bool use_ensure) { if (dvert_src->totweight && dvert_dst->totweight) { - int i; - MDeformWeight *dw_src; - for (i = 0, dw_src = dvert_src->dw; i < dvert_src->totweight; i++, dw_src++) { + MDeformWeight *dw_src = dvert_src->dw; + for (int i = 0; i < dvert_src->totweight; i++, dw_src++) { MDeformWeight *dw_dst; if (use_ensure) { dw_dst = BKE_defvert_ensure_index(dvert_dst, dw_src->def_nr); @@ -228,9 +227,8 @@ void BKE_defvert_sync_mapped(MDeformVert *dvert_dst, const bool use_ensure) { if (dvert_src->totweight && dvert_dst->totweight) { - int i; - MDeformWeight *dw_src; - for (i = 0, dw_src = dvert_src->dw; i < dvert_src->totweight; i++, dw_src++) { + MDeformWeight *dw_src = dvert_src->dw; + for (int i = 0; i < dvert_src->totweight; i++, dw_src++) { if (dw_src->def_nr < flip_map_len) { MDeformWeight *dw_dst; if (use_ensure) { @@ -254,8 +252,7 @@ void BKE_defvert_sync_mapped(MDeformVert *dvert_dst, void BKE_defvert_remap(MDeformVert *dvert, const int *map, const int map_len) { MDeformWeight *dw = dvert->dw; - unsigned int i; - for (i = dvert->totweight; i != 0; i--, dw++) { + for (int i = dvert->totweight; i != 0; i--, dw++) { if (dw->def_nr < map_len) { BLI_assert(map[dw->def_nr] >= 0); @@ -281,11 +278,9 @@ void BKE_defvert_normalize_subset(MDeformVert *dvert, } } else { - MDeformWeight *dw; - unsigned int i; + MDeformWeight *dw = dvert->dw; float tot_weight = 0.0f; - - for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) { + for (int i = dvert->totweight; i != 0; i--, dw++) { if ((dw->def_nr < vgroup_tot) && vgroup_subset[dw->def_nr]) { tot_weight += dw->weight; } @@ -293,7 +288,8 @@ void BKE_defvert_normalize_subset(MDeformVert *dvert, if (tot_weight > 0.0f) { float scalar = 1.0f / tot_weight; - for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) { + dw = dvert->dw; + for (int i = dvert->totweight; i != 0; i--, dw++) { if ((dw->def_nr < vgroup_tot) && vgroup_subset[dw->def_nr]) { dw->weight *= scalar; @@ -822,8 +818,7 @@ int BKE_defvert_find_shared(const MDeformVert *dvert_a, const MDeformVert *dvert bool BKE_defvert_is_weight_zero(const struct MDeformVert *dvert, const int defgroup_tot) { MDeformWeight *dw = dvert->dw; - unsigned int i; - for (i = dvert->totweight; i != 0; i--, dw++) { + for (int i = dvert->totweight; i != 0; i--, dw++) { if (dw->weight != 0.0f) { /* check the group is in-range, happens on rare situations */ if (LIKELY(dw->def_nr < defgroup_tot)) { @@ -841,7 +836,6 @@ float BKE_defvert_total_selected_weight(const struct MDeformVert *dv, int defbase_tot, const bool *defbase_sel) { - int i; float total = 0.0f; const MDeformWeight *dw = dv->dw; @@ -849,7 +843,7 @@ float BKE_defvert_total_selected_weight(const struct MDeformVert *dv, return total; } - for (i = dv->totweight; i != 0; i--, dw++) { + for (int i = dv->totweight; i != 0; i--, dw++) { if (dw->def_nr < defbase_tot) { if (defbase_sel[dw->def_nr]) { total += dw->weight; @@ -947,7 +941,6 @@ float BKE_defvert_lock_relative_weight(float weight, void BKE_defvert_array_copy(MDeformVert *dst, const MDeformVert *src, int totvert) { /* Assumes dst is already set up */ - int i; if (!src || !dst) { return; @@ -955,7 +948,7 @@ void BKE_defvert_array_copy(MDeformVert *dst, const MDeformVert *src, int totver memcpy(dst, src, totvert * sizeof(MDeformVert)); - for (i = 0; i < totvert; i++) { + for (int i = 0; i < totvert; i++) { if (src[i].dw) { dst[i].dw = MEM_mallocN(sizeof(MDeformWeight) * src[i].totweight, "copy_deformWeight"); memcpy(dst[i].dw, src[i].dw, sizeof(MDeformWeight) * src[i].totweight); @@ -968,14 +961,13 @@ void BKE_defvert_array_free_elems(MDeformVert *dvert, int totvert) /* Instead of freeing the verts directly, * call this function to delete any special * vert data */ - int i; if (!dvert) { return; } /* Free any special data from the verts */ - for (i = 0; i < totvert; i++) { + for (int i = 0; i < totvert; i++) { if (dvert[i].dw) { MEM_freeN(dvert[i].dw); } diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 50c9ce4fb75..b7309743af1 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -475,13 +475,12 @@ static void blendColors(const float t_color[3], float result[4]) { /* Same thing as BLI's blend_color_mix_float(), but for non-premultiplied alpha. */ - int i; float i_alpha = 1.0f - s_alpha; float f_alpha = t_alpha * i_alpha + s_alpha; /* blend colors */ if (f_alpha) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { result[i] = (t_color[i] * t_alpha * i_alpha + s_color[i] * s_alpha) / f_alpha; } } @@ -1429,9 +1428,6 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b } if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { - int i; - int n_pos; - /* For vertex format, count every vertex that is connected by an edge */ int numOfEdges = mesh->totedge; int numOfPolys = mesh->totpoly; @@ -1440,7 +1436,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b struct MLoop *mloop = mesh->mloop; /* count number of edges per vertex */ - for (i = 0; i < numOfEdges; i++) { + for (int i = 0; i < numOfEdges; i++) { ad->n_num[edge[i].v1]++; ad->n_num[edge[i].v2]++; @@ -1450,7 +1446,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b /* also add number of vertices to temp_data * to locate points on "mesh edge" */ - for (i = 0; i < numOfPolys; i++) { + for (int i = 0; i < numOfPolys; i++) { for (int j = 0; j < mpoly[i].totloop; j++) { temp_data[mloop[mpoly[i].loopstart + j].v]++; } @@ -1458,7 +1454,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b /* now check if total number of edges+faces for * each vertex is even, if not -> vertex is on mesh edge */ - for (i = 0; i < sData->total_points; i++) { + for (int i = 0; i < sData->total_points; i++) { if ((temp_data[i] % 2) || (temp_data[i] < 4)) { ad->flags[i] |= ADJ_ON_MESH_EDGE; } @@ -1468,14 +1464,14 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b } /* order n_index array */ - n_pos = 0; - for (i = 0; i < sData->total_points; i++) { + int n_pos = 0; + for (int i = 0; i < sData->total_points; i++) { ad->n_index[i] = n_pos; n_pos += ad->n_num[i]; } /* and now add neighbor data using that info */ - for (i = 0; i < numOfEdges; i++) { + for (int i = 0; i < numOfEdges; i++) { /* first vertex */ int index = edge[i].v1; n_pos = ad->n_index[index] + temp_data[index]; @@ -1616,7 +1612,6 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface PaintSurfaceData *sData = surface->data; PaintPoint *pPoint = (PaintPoint *)sData->type_data; Mesh *mesh = dynamicPaint_canvas_mesh_get(surface->canvas); - int i; const bool scene_color_manage = BKE_scene_check_color_management_enabled(scene); if (surface->type != MOD_DPAINT_SURFACE_T_PAINT) { @@ -1630,7 +1625,7 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface /* Single color */ if (surface->init_color_type == MOD_DPAINT_INITIAL_COLOR) { /* apply color to every surface point */ - for (i = 0; i < sData->total_points; i++) { + for (int i = 0; i < sData->total_points; i++) { copy_v4_v4(pPoint[i].color, surface->init_color); } } @@ -1703,7 +1698,7 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface return; } - for (i = 0; i < totloop; i++) { + for (int i = 0; i < totloop; i++) { rgba_uchar_to_float(pPoint[mloop[i].v].color, (const unsigned char *)&col[mloop[i].v].r); } } @@ -2029,8 +2024,7 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object * result->dvert = dvert; } if (defgrp_index != -1 && dvert) { - int i; - for (i = 0; i < sData->total_points; i++) { + for (int i = 0; i < sData->total_points; i++) { MDeformVert *dv = &dvert[i]; MDeformWeight *def_weight = BKE_defvert_find_index(dv, defgrp_index); @@ -4908,13 +4902,12 @@ static void surface_determineForceTargetPoints(const PaintSurfaceData *sData, { BakeAdjPoint *bNeighs = sData->bData->bNeighs; const int numOfNeighs = sData->adj_data->n_num[index]; - int i; closest_id[0] = closest_id[1] = -1; closest_d[0] = closest_d[1] = -1.0f; /* find closest neigh */ - for (i = 0; i < numOfNeighs; i++) { + for (int i = 0; i < numOfNeighs; i++) { const int n_index = sData->adj_data->n_index[index] + i; const float dir_dot = dot_v3v3(bNeighs[n_index].dir, force); @@ -4929,7 +4922,7 @@ static void surface_determineForceTargetPoints(const PaintSurfaceData *sData, } /* find second closest neigh */ - for (i = 0; i < numOfNeighs; i++) { + for (int i = 0; i < numOfNeighs; i++) { const int n_index = sData->adj_data->n_index[index] + i; if (n_index == closest_id[0]) { @@ -4989,26 +4982,24 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, PaintSurfaceData *sData = surface->data; PaintBakeData *bData = sData->bData; BakeAdjPoint *bNeighs = sData->bData->bNeighs; - int index, steps, step; - float eff_scale, max_velocity = 0.0f; + float max_velocity = 0.0f; if (!sData->adj_data) { return; } /* find max velocity */ - for (index = 0; index < sData->total_points; index++) { + for (int index = 0; index < sData->total_points; index++) { float vel = bData->brush_velocity[index * 4 + 3]; CLAMP_MIN(max_velocity, vel); } - steps = (int)ceil((double)max_velocity / bData->average_dist * (double)timescale); + int steps = (int)ceil((double)max_velocity / bData->average_dist * (double)timescale); CLAMP(steps, 0, 12); - eff_scale = brush->smudge_strength / (float)steps * timescale; + float eff_scale = brush->smudge_strength / (float)steps * timescale; - for (step = 0; step < steps; step++) { - for (index = 0; index < sData->total_points; index++) { - int i; + for (int step = 0; step < steps; step++) { + for (int index = 0; index < sData->total_points; index++) { if (sData->adj_data->flags[index] & ADJ_BORDER_PIXEL) { continue; @@ -5030,7 +5021,7 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface, sData, index, &bData->brush_velocity[index * 4], closest_d, closest_id); /* Apply movement towards those two points */ - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { int n_index = closest_id[i]; if (n_index != -1 && closest_d[i] > 0.0f) { float dir_dot = closest_d[i], dir_factor; @@ -5753,10 +5744,9 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal /* calculate average neigh distance (single thread) */ for (index = 0; index < sData->total_points; index++) { - int i; int numOfNeighs = sData->adj_data->n_num[index]; - for (i = 0; i < numOfNeighs; i++) { + for (int i = 0; i < numOfNeighs; i++) { average_dist += (double)bNeighs[sData->adj_data->n_index[index] + i].dist; } } @@ -5827,8 +5817,7 @@ static void dynamic_paint_surface_pre_step_cb(void *__restrict userdata, /* drying */ if (surface->flags & MOD_DPAINT_USE_DRYING) { if (pPoint->wetness >= MIN_WETNESS) { - int i; - float dry_ratio, f_color[4]; + float f_color[4]; float p_wetness = pPoint->wetness; value_dissolve(&pPoint->wetness, @@ -5838,7 +5827,7 @@ static void dynamic_paint_surface_pre_step_cb(void *__restrict userdata, CLAMP_MIN(pPoint->wetness, 0.0f); if (pPoint->wetness < surface->color_dry_threshold) { - dry_ratio = pPoint->wetness / p_wetness; + float dry_ratio = pPoint->wetness / p_wetness; /* * Slowly "shift" paint from wet layer to dry layer as it drys: @@ -5858,7 +5847,7 @@ static void dynamic_paint_surface_pre_step_cb(void *__restrict userdata, /* For each rgb component, calculate a new dry layer color that keeps the final blend * color with these new alpha values. (wet layer color doesn't change). */ if (pPoint->color[3]) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { pPoint->color[i] = (f_color[i] * f_color[3] - pPoint->e_color[i] * pPoint->e_color[3]) / (pPoint->color[3] * (1.0f - pPoint->e_color[3])); @@ -5914,7 +5903,6 @@ static bool dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *o MVert *mvert = mesh->mvert; int numOfVerts = mesh->totvert; - int i; if (!bData->prev_verts) { return true; @@ -5926,7 +5914,7 @@ static bool dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *o } /* vertices */ - for (i = 0; i < numOfVerts; i++) { + for (int i = 0; i < numOfVerts; i++) { if (!equals_v3v3(bData->prev_verts[i].co, mvert[i].co)) { return true; } diff --git a/source/blender/blenkernel/intern/editmesh_bvh.c b/source/blender/blenkernel/intern/editmesh_bvh.c index dc194f0077c..a1e53a1f848 100644 --- a/source/blender/blenkernel/intern/editmesh_bvh.c +++ b/source/blender/blenkernel/intern/editmesh_bvh.c @@ -66,7 +66,6 @@ BMBVHTree *BKE_bmbvh_new_ex(BMesh *bm, BMBVHTree *bmtree = MEM_callocN(sizeof(*bmtree), "BMBVHTree"); float cos[3][3]; - int i; int tottri; /* avoid testing every tri */ @@ -95,7 +94,7 @@ BMBVHTree *BKE_bmbvh_new_ex(BMesh *bm, test_fn_ret = false; tottri = 0; - for (i = 0; i < looptris_tot; i++) { + for (int i = 0; i < looptris_tot; i++) { f_test = looptris[i][0]->f; if (f_test != f_test_prev) { test_fn_ret = test_fn(f_test, user_data); @@ -116,7 +115,7 @@ BMBVHTree *BKE_bmbvh_new_ex(BMesh *bm, f_test_prev = NULL; test_fn_ret = false; - for (i = 0; i < looptris_tot; i++) { + for (int i = 0; i < looptris_tot; i++) { if (test_fn) { /* note, the arrays wont align now! take care */ f_test = looptris[i][0]->f; @@ -422,13 +421,11 @@ static void bmbvh_find_vert_closest_cb(void *userdata, struct VertSearchUserData *bmcb_data = userdata; const BMLoop **ltri = bmcb_data->looptris[index]; const float dist_max_sq = bmcb_data->dist_max_sq; - int i; const float *tri_cos[3]; - bmbvh_tri_from_face(tri_cos, ltri, bmcb_data->cos_cage); - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { const float dist_sq = len_squared_v3v3(co, tri_cos[i]); if (dist_sq < hit->dist_sq && dist_sq < dist_max_sq) { copy_v3_v3(hit->co, tri_cos[i]); diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 1c5c74379f8..40548189583 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -74,9 +74,7 @@ EffectorWeights *BKE_effector_add_weights(Collection *collection) { EffectorWeights *weights = MEM_callocN(sizeof(EffectorWeights), "EffectorWeights"); - int i; - - for (i = 0; i < NUM_PFIELD_TYPES; i++) { + for (int i = 0; i < NUM_PFIELD_TYPES; i++) { weights->weight[i] = 1.0f; } diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 5d227ec2f9b..d5b54eb1cd1 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -617,11 +617,10 @@ static short get_fcurve_end_keyframes(FCurve *fcu, /* only include selected items? */ if (do_sel_only) { BezTriple *bezt; - unsigned int i; /* find first selected */ bezt = fcu->bezt; - for (i = 0; i < fcu->totvert; bezt++, i++) { + for (int i = 0; i < fcu->totvert; bezt++, i++) { if (BEZT_ISSEL_ANY(bezt)) { *first = bezt; found = true; @@ -631,7 +630,7 @@ static short get_fcurve_end_keyframes(FCurve *fcu, /* find last selected */ bezt = ARRAY_LAST_ITEM(fcu->bezt, BezTriple, fcu->totvert); - for (i = 0; i < fcu->totvert; bezt--, i++) { + for (int i = 0; i < fcu->totvert; bezt--, i++) { if (BEZT_ISSEL_ANY(bezt)) { *last = bezt; found = true; @@ -661,7 +660,6 @@ bool BKE_fcurve_calc_bounds(FCurve *fcu, float xminv = 999999999.0f, xmaxv = -999999999.0f; float yminv = 999999999.0f, ymaxv = -999999999.0f; bool foundvert = false; - unsigned int i; if (fcu->totvert) { if (fcu->bezt) { @@ -689,6 +687,7 @@ bool BKE_fcurve_calc_bounds(FCurve *fcu, if (ymin || ymax) { BezTriple *bezt, *prevbezt = NULL; + int i; for (bezt = fcu->bezt, i = 0; i < fcu->totvert; prevbezt = bezt, bezt++, i++) { if ((do_sel_only == false) || BEZT_ISSEL_ANY(bezt)) { /* keyframe itself */ @@ -726,6 +725,7 @@ bool BKE_fcurve_calc_bounds(FCurve *fcu, /* only loop over keyframes to find extents for values if needed */ if (ymin || ymax) { FPoint *fpt; + int i; for (fpt = fcu->fpt, i = 0; i < fcu->totvert; fpt++, i++) { if (fpt->vec[1] < yminv) { diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c index 04f3b4f64d6..df7d308a87c 100644 --- a/source/blender/blenkernel/intern/fluid.c +++ b/source/blender/blenkernel/intern/fluid.c @@ -181,7 +181,6 @@ void BKE_fluid_reallocate_copy_fluid(FluidDomainSettings *fds, float *n_b = manta_smoke_get_color_b(fds->fluid); /* Noise smoke fields. */ - int wt_res_old[3]; float *o_wt_dens = manta_noise_get_density(fluid_old); float *o_wt_react = manta_noise_get_react(fluid_old); float *o_wt_flame = manta_noise_get_flame(fluid_old); @@ -210,6 +209,7 @@ void BKE_fluid_reallocate_copy_fluid(FluidDomainSettings *fds, float *n_wt_tcv2 = manta_noise_get_texture_v2(fds->fluid); float *n_wt_tcw2 = manta_noise_get_texture_w2(fds->fluid); + int wt_res_old[3]; manta_noise_get_res(fluid_old, wt_res_old); for (int z = o_min[2]; z < o_max[2]; z++) { @@ -593,8 +593,7 @@ static void clamp_bounds_in_domain(FluidDomainSettings *fds, int margin, float dt) { - int i; - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { int adapt = (fds->flags & FLUID_DOMAIN_USE_ADAPTIVE_DOMAIN) ? fds->adapt_res : 0; /* Add some margin. */ min[i] -= margin; @@ -3431,7 +3430,6 @@ static Mesh *create_smoke_geometry(FluidDomainSettings *fds, Mesh *orgmesh, Obje int num_verts = 8; int num_faces = 6; - int i; float ob_loc[3] = {0}; float ob_cache_loc[3] = {0}; @@ -3551,7 +3549,7 @@ static Mesh *create_smoke_geometry(FluidDomainSettings *fds, Mesh *orgmesh, Obje /* Convert shift to local space and apply to vertices. */ mul_mat3_m4_v3(ob->imat, fds->obj_shift_f); /* Apply shift to vertices. */ - for (i = 0; i < num_verts; i++) { + for (int i = 0; i < num_verts; i++) { add_v3_v3(mverts[i].co, fds->obj_shift_f); } } @@ -3817,6 +3815,13 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd, } } + /* Adaptive domain needs to know about current state, so save it here. */ + int o_res[3], o_min[3], o_max[3], o_shift[3]; + copy_v3_v3_int(o_res, fds->res); + copy_v3_v3_int(o_min, fds->res_min); + copy_v3_v3_int(o_max, fds->res_max); + copy_v3_v3_int(o_shift, fds->shift); + /* Ensure that time parameters are initialized correctly before every step. */ float fps = scene->r.frs_sec / scene->r.frs_sec_base; fds->frame_length = DT_DEFAULT * (25.0f / fps) * fds->time_scale; @@ -3905,8 +3910,6 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd, bool with_gdomain; with_gdomain = (fds->guide_source == FLUID_DOMAIN_GUIDE_SRC_DOMAIN); - int o_res[3], o_min[3], o_max[3], o_shift[3]; - /* Cache mode specific settings. */ switch (mode) { case FLUID_DOMAIN_CACHE_ALL: @@ -3970,13 +3973,9 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd, break; } - /* Adaptive domain needs to know about current state, so save it here. */ - copy_v3_v3_int(o_res, fds->res); - copy_v3_v3_int(o_min, fds->res_min); - copy_v3_v3_int(o_max, fds->res_max); - copy_v3_v3_int(o_shift, fds->shift); - bool read_partial = false, read_all = false; + bool grid_display = fds->use_coba; + /* Try to read from cache and keep track of read success. */ if (read_cache) { @@ -4040,7 +4039,8 @@ static void BKE_fluid_modifier_processDomain(FluidModifierData *fmd, } } - read_partial = !baking_data && !baking_particles && !baking_mesh && next_data; + read_partial = !baking_data && !baking_particles && !baking_mesh && next_data && + !grid_display; read_all = !read_partial && with_resumable_cache; has_data = manta_read_data(fds->fluid, fmd, data_frame, read_all); } diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index c973b681fe7..56cd58b0493 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -178,12 +178,11 @@ static void fcm_generator_evaluate( /* we overwrite cvalue with the sum of the polynomial */ float *powers = MEM_callocN(sizeof(float) * data->arraysize, "Poly Powers"); float value = 0.0f; - unsigned int i; /* for each x^n, precalculate value based on previous one first... this should be * faster that calling pow() for each entry */ - for (i = 0; i < data->arraysize; i++) { + for (uint i = 0; i < data->arraysize; i++) { /* first entry is x^0 = 1, otherwise, calculate based on previous */ if (i) { powers[i] = powers[i - 1] * evaltime; @@ -194,7 +193,7 @@ static void fcm_generator_evaluate( } /* for each coefficient, add to value, which we'll write to *cvalue in one go */ - for (i = 0; i < data->arraysize; i++) { + for (uint i = 0; i < data->arraysize; i++) { value += data->coefficients[i] * powers[i]; } diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 890cfd91710..88d91cf5640 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -57,6 +57,8 @@ #include "BKE_main.h" #include "BKE_packedFile.h" +#include "BLO_read_write.h" + static CLG_LogRef LOG = {"bke.data_transfer"}; static ThreadRWMutex vfont_rwlock = BLI_RWLOCK_INITIALIZER; @@ -120,6 +122,31 @@ static void vfont_free_data(ID *id) } } +static void vfont_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + VFont *vf = (VFont *)id; + if (vf->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + vf->data = NULL; + vf->temp_pf = NULL; + + /* write LibData */ + BLO_write_id_struct(writer, VFont, id_address, &vf->id); + BKE_id_blend_write(writer, &vf->id); + + /* direct data */ + BKE_packedfile_blend_write(writer, vf->packedfile); + } +} + +static void vfont_blend_read_data(BlendDataReader *reader, ID *id) +{ + VFont *vf = (VFont *)id; + vf->data = NULL; + vf->temp_pf = NULL; + BKE_packedfile_blend_read(reader, &vf->packedfile); +} + IDTypeInfo IDType_ID_VF = { .id_code = ID_VF, .id_filter = FILTER_ID_VF, @@ -137,8 +164,8 @@ IDTypeInfo IDType_ID_VF = { .foreach_id = NULL, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, + .blend_write = vfont_blend_write, + .blend_read_data = vfont_blend_read_data, .blend_read_lib = NULL, .blend_read_expand = NULL, }; @@ -434,20 +461,14 @@ static void build_underline(Curve *cu, BLI_addtail(nubase, nu2); if (rot != 0.0f) { - float si, co; - int i; - - si = sinf(rot); - co = cosf(rot); + float si = sinf(rot); + float co = cosf(rot); - for (i = nu2->pntsu; i > 0; i--) { - float *fp; - float x, y; + for (int i = nu2->pntsu; i > 0; i--) { + float *fp = bp->vec; - fp = bp->vec; - - x = fp[0] - rect->xmin; - y = fp[1] - rect->ymin; + float x = fp[0] - rect->xmin; + float y = fp[1] - rect->ymin; fp[0] = (+co * x + si * y) + rect->xmin; fp[1] = (-si * x + co * y) + rect->ymin; @@ -474,35 +495,29 @@ static void buildchar(Curve *cu, int charidx, const float fsize) { - BezTriple *bezt1, *bezt2; - Nurb *nu1 = NULL, *nu2 = NULL; - float *fp, shear, x, si, co; - VFontData *vfd = NULL; - VChar *che = NULL; - int i; - - vfd = vfont_get_data(which_vfont(cu, info)); + VFontData *vfd = vfont_get_data(which_vfont(cu, info)); if (!vfd) { return; } /* make a copy at distance ofsx, ofsy with shear */ - shear = cu->shear; - si = sinf(rot); - co = cosf(rot); + float shear = cu->shear; + float si = sinf(rot); + float co = cosf(rot); - che = find_vfont_char(vfd, character); + VChar *che = find_vfont_char(vfd, character); /* Select the glyph data */ + Nurb *nu1 = NULL; if (che) { nu1 = che->nurbsbase.first; } /* Create the character */ while (nu1) { - bezt1 = nu1->bezt; + BezTriple *bezt1 = nu1->bezt; if (bezt1) { - nu2 = (Nurb *)MEM_mallocN(sizeof(Nurb), "duplichar_nurb"); + Nurb *nu2 = (Nurb *)MEM_mallocN(sizeof(Nurb), "duplichar_nurb"); if (nu2 == NULL) { break; } @@ -520,20 +535,20 @@ static void buildchar(Curve *cu, } /* nu2->trim.first = 0; */ /* nu2->trim.last = 0; */ - i = nu2->pntsu; + int u = nu2->pntsu; - bezt2 = (BezTriple *)MEM_malloc_arrayN(i, sizeof(BezTriple), "duplichar_bezt2"); + BezTriple *bezt2 = (BezTriple *)MEM_malloc_arrayN(u, sizeof(BezTriple), "duplichar_bezt2"); if (bezt2 == NULL) { MEM_freeN(nu2); break; } - memcpy(bezt2, bezt1, i * sizeof(struct BezTriple)); + memcpy(bezt2, bezt1, u * sizeof(struct BezTriple)); nu2->bezt = bezt2; if (shear != 0.0f) { bezt2 = nu2->bezt; - for (i = nu2->pntsu; i > 0; i--) { + for (int i = nu2->pntsu; i > 0; i--) { bezt2->vec[0][0] += shear * bezt2->vec[0][1]; bezt2->vec[1][0] += shear * bezt2->vec[1][1]; bezt2->vec[2][0] += shear * bezt2->vec[2][1]; @@ -542,10 +557,10 @@ static void buildchar(Curve *cu, } if (rot != 0.0f) { bezt2 = nu2->bezt; - for (i = nu2->pntsu; i > 0; i--) { - fp = bezt2->vec[0]; + for (int i = nu2->pntsu; i > 0; i--) { + float *fp = bezt2->vec[0]; - x = fp[0]; + float x = fp[0]; fp[0] = co * x + si * fp[1]; fp[1] = -si * x + co * fp[1]; x = fp[3]; @@ -562,8 +577,8 @@ static void buildchar(Curve *cu, if (info->flag & CU_CHINFO_SMALLCAPS_CHECK) { const float sca = cu->smallcaps_scale; - for (i = nu2->pntsu; i > 0; i--) { - fp = bezt2->vec[0]; + for (int i = nu2->pntsu; i > 0; i--) { + float *fp = bezt2->vec[0]; fp[0] *= sca; fp[1] *= sca; fp[3] *= sca; @@ -575,8 +590,8 @@ static void buildchar(Curve *cu, } bezt2 = nu2->bezt; - for (i = nu2->pntsu; i > 0; i--) { - fp = bezt2->vec[0]; + for (int i = nu2->pntsu; i > 0; i--) { + float *fp = bezt2->vec[0]; fp[0] = (fp[0] + ofsx) * fsize; fp[1] = (fp[1] + ofsy) * fsize; fp[3] = (fp[3] + ofsx) * fsize; diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index c384088f139..560069b1650 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -40,12 +40,16 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_gpencil_types.h" #include "DNA_material_types.h" #include "DNA_meshdata_types.h" #include "DNA_space_types.h" #include "BKE_action.h" +#include "BKE_anim_data.h" #include "BKE_collection.h" #include "BKE_colortools.h" #include "BKE_deform.h" @@ -64,6 +68,10 @@ #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + +#include "BKE_gpencil.h" + static CLG_LogRef LOG = {"bke.gpencil"}; static void greasepencil_copy_data(Main *UNUSED(bmain), @@ -111,6 +119,161 @@ static void greasepencil_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void greasepencil_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + bGPdata *gpd = (bGPdata *)id; + if (gpd->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed data-blocks. */ + /* XXX not sure why the whole run-time data is not cleared in reading code, + * for now mimicking it here. */ + gpd->runtime.sbuffer = NULL; + gpd->runtime.sbuffer_used = 0; + gpd->runtime.sbuffer_size = 0; + gpd->runtime.tot_cp_points = 0; + + /* write gpd data block to file */ + BLO_write_id_struct(writer, bGPdata, id_address, &gpd->id); + BKE_id_blend_write(writer, &gpd->id); + + if (gpd->adt) { + BKE_animdata_blend_write(writer, gpd->adt); + } + + BLO_write_pointer_array(writer, gpd->totcol, gpd->mat); + + /* write grease-pencil layers to file */ + BLO_write_struct_list(writer, bGPDlayer, &gpd->layers); + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + /* Write mask list. */ + BLO_write_struct_list(writer, bGPDlayer_Mask, &gpl->mask_layers); + /* write this layer's frames to file */ + BLO_write_struct_list(writer, bGPDframe, &gpl->frames); + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + /* write strokes */ + BLO_write_struct_list(writer, bGPDstroke, &gpf->strokes); + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { + BLO_write_struct_array(writer, bGPDspoint, gps->totpoints, gps->points); + BLO_write_struct_array(writer, bGPDtriangle, gps->tot_triangles, gps->triangles); + BKE_defvert_blend_write(writer, gps->totpoints, gps->dvert); + } + } + } + } +} + +void BKE_gpencil_blend_read_data(BlendDataReader *reader, bGPdata *gpd) +{ + /* we must firstly have some grease-pencil data to link! */ + if (gpd == NULL) { + return; + } + + /* relink animdata */ + BLO_read_data_address(reader, &gpd->adt); + BKE_animdata_blend_read_data(reader, gpd->adt); + + /* Ensure full objectmode for linked grease pencil. */ + if (gpd->id.lib != NULL) { + gpd->flag &= ~GP_DATA_STROKE_PAINTMODE; + gpd->flag &= ~GP_DATA_STROKE_EDITMODE; + gpd->flag &= ~GP_DATA_STROKE_SCULPTMODE; + gpd->flag &= ~GP_DATA_STROKE_WEIGHTMODE; + gpd->flag &= ~GP_DATA_STROKE_VERTEXMODE; + } + + /* init stroke buffer */ + gpd->runtime.sbuffer = NULL; + gpd->runtime.sbuffer_used = 0; + gpd->runtime.sbuffer_size = 0; + gpd->runtime.tot_cp_points = 0; + + /* relink palettes (old palettes deprecated, only to convert old files) */ + BLO_read_list(reader, &gpd->palettes); + if (gpd->palettes.first != NULL) { + LISTBASE_FOREACH (Palette *, palette, &gpd->palettes) { + BLO_read_list(reader, &palette->colors); + } + } + + /* materials */ + BLO_read_pointer_array(reader, (void **)&gpd->mat); + + /* relink layers */ + BLO_read_list(reader, &gpd->layers); + + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + /* relink frames */ + BLO_read_list(reader, &gpl->frames); + + BLO_read_data_address(reader, &gpl->actframe); + + gpl->runtime.icon_id = 0; + + /* Relink masks. */ + BLO_read_list(reader, &gpl->mask_layers); + + LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { + /* relink strokes (and their points) */ + BLO_read_list(reader, &gpf->strokes); + + LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { + /* relink stroke points array */ + BLO_read_data_address(reader, &gps->points); + /* Relink geometry*/ + BLO_read_data_address(reader, &gps->triangles); + + /* relink stroke edit curve. */ + BLO_read_data_address(reader, &gps->editcurve); + if (gps->editcurve != NULL) { + /* relink curve point array */ + BLO_read_data_address(reader, &gps->editcurve->curve_points); + } + + /* relink weight data */ + if (gps->dvert) { + BLO_read_data_address(reader, &gps->dvert); + BKE_defvert_blend_read(reader, gps->totpoints, gps->dvert); + } + } + } + } +} + +static void greasepencil_blend_read_data(BlendDataReader *reader, ID *id) +{ + bGPdata *gpd = (bGPdata *)id; + BKE_gpencil_blend_read_data(reader, gpd); +} + +static void greasepencil_blend_read_lib(BlendLibReader *reader, ID *id) +{ + bGPdata *gpd = (bGPdata *)id; + + /* Relink all data-lock linked by GP data-lock */ + /* Layers */ + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + /* Layer -> Parent References */ + BLO_read_id_address(reader, gpd->id.lib, &gpl->parent); + } + + /* materials */ + for (int a = 0; a < gpd->totcol; a++) { + BLO_read_id_address(reader, gpd->id.lib, &gpd->mat[a]); + } +} + +static void greasepencil_blend_read_expand(BlendExpander *expander, ID *id) +{ + bGPdata *gpd = (bGPdata *)id; + LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { + BLO_expand(expander, gpl->parent); + } + + for (int a = 0; a < gpd->totcol; a++) { + BLO_expand(expander, gpd->mat[a]); + } +} + IDTypeInfo IDType_ID_GD = { .id_code = ID_GD, .id_filter = FILTER_ID_GD, @@ -128,10 +291,10 @@ IDTypeInfo IDType_ID_GD = { .foreach_id = greasepencil_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = greasepencil_blend_write, + .blend_read_data = greasepencil_blend_read_data, + .blend_read_lib = greasepencil_blend_read_lib, + .blend_read_expand = greasepencil_blend_read_expand, }; /* ************************************************** */ diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c index 20b9380cfbb..2e81c5c0747 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.c +++ b/source/blender/blenkernel/intern/gpencil_geom.c @@ -395,9 +395,8 @@ static void stroke_interpolate_deform_weights( { const MDeformVert *vl = &gps->dvert[index_from]; const MDeformVert *vr = &gps->dvert[index_to]; - int i; - for (i = 0; i < vert->totweight; i++) { + for (int i = 0; i < vert->totweight; i++) { float wl = BKE_defvert_find_weight(vl, vert->dw[i].def_nr); float wr = BKE_defvert_find_weight(vr, vert->dw[i].def_nr); vert->dw[i].weight = interpf(wr, wl, ratio); @@ -415,7 +414,6 @@ bool BKE_gpencil_stroke_sample(bGPdata *gpd, bGPDstroke *gps, const float dist, bGPDspoint *pt = gps->points; bGPDspoint *pt1 = NULL; bGPDspoint *pt2 = NULL; - int i; LinkData *ld; ListBase def_nr_list = {0}; @@ -436,7 +434,7 @@ bool BKE_gpencil_stroke_sample(bGPdata *gpd, bGPDstroke *gps, const float dist, } int next_point_index = 1; - i = 0; + int i = 0; float pressure, strength, ratio_result; float vert_color[4]; int index_from, index_to; @@ -522,7 +520,6 @@ bool BKE_gpencil_stroke_sample(bGPdata *gpd, bGPDstroke *gps, const float dist, bool BKE_gpencil_stroke_stretch(bGPDstroke *gps, const float dist, const float tip_length) { bGPDspoint *pt = gps->points, *last_pt, *second_last, *next_pt; - int i; float threshold = (tip_length == 0 ? 0.001f : tip_length); if (gps->totpoints < 2 || dist < FLT_EPSILON) { @@ -536,7 +533,7 @@ bool BKE_gpencil_stroke_stretch(bGPDstroke *gps, const float dist, const float t float len1 = 0.0f; float len2 = 0.0f; - i = 1; + int i = 1; while (len1 < threshold && gps->totpoints > i) { next_pt = &pt[i]; len1 = len_v3v3(&next_pt->x, &pt->x); @@ -1321,11 +1318,9 @@ float BKE_gpencil_stroke_length(const bGPDstroke *gps, bool use_3d) return 0.0f; } float *last_pt = &gps->points[0].x; - int i; - bGPDspoint *pt; float total_length = 0.0f; - for (i = 1; i < gps->totpoints; i++) { - pt = &gps->points[i]; + for (int i = 1; i < gps->totpoints; i++) { + bGPDspoint *pt = &gps->points[i]; if (use_3d) { total_length += len_v3v3(&pt->x, last_pt); } @@ -2287,13 +2282,11 @@ static Material *gpencil_add_material(Main *bmain, return mat_gp; } -static int gpencil_material_find_index_by_name_prefix(Object *ob, const char *name_prefix) +static int gpencil_material_find_index_by_name(Object *ob, const char *name) { - const int name_prefix_len = strlen(name_prefix); for (int i = 0; i < ob->totcol; i++) { Material *ma = BKE_object_material_get(ob, i + 1); - if ((ma != NULL) && (ma->gp_style != NULL) && - (STREQLEN(ma->id.name + 2, name_prefix, name_prefix_len))) { + if ((ma != NULL) && (ma->gp_style != NULL) && (STREQ(ma->id.name + 2, name))) { return i; } } @@ -2302,6 +2295,20 @@ static int gpencil_material_find_index_by_name_prefix(Object *ob, const char *na } /** + * Create the name with the object name and a suffix. + */ +static void make_element_name(const char *obname, const char *name, const int maxlen, char *r_name) +{ + char str[256]; + SNPRINTF(str, "%s_%s", obname, name); + + /* Replace any point by underscore. */ + BLI_str_replace_char(str, '.', '_'); + + BLI_strncpy_utf8(r_name, str, maxlen); +} + +/** * Convert a mesh object to grease pencil stroke. * * \param bmain: Main thread pointer. @@ -2316,9 +2323,8 @@ static int gpencil_material_find_index_by_name_prefix(Object *ob, const char *na * \param frame_offset: Destination frame number offset. * \param use_seams: Only export seam edges. * \param use_faces: Export faces as filled strokes. - * \simple_material: Create only 2 materials (stroke and fill) */ -void BKE_gpencil_convert_mesh(Main *bmain, +bool BKE_gpencil_convert_mesh(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob_gp, @@ -2329,11 +2335,10 @@ void BKE_gpencil_convert_mesh(Main *bmain, const float matrix[4][4], const int frame_offset, const bool use_seams, - const bool use_faces, - const bool simple_material) + const bool use_faces) { if (ELEM(NULL, ob_gp, ob_mesh) || (ob_gp->type != OB_GPENCIL) || (ob_gp->data == NULL)) { - return; + return false; } bGPdata *gpd = (bGPdata *)ob_gp->data; @@ -2344,92 +2349,73 @@ void BKE_gpencil_convert_mesh(Main *bmain, MPoly *mp, *mpoly = me_eval->mpoly; MLoop *mloop = me_eval->mloop; int mpoly_len = me_eval->totpoly; - int i; - int stroke_mat_index = gpencil_material_find_index_by_name_prefix(ob_gp, "Stroke"); - int fill_mat_index = gpencil_material_find_index_by_name_prefix(ob_gp, "Fill"); - - /* If the object has enough materials means it was created in a previous step. */ - const bool create_mat = ((ob_gp->totcol > 0) && (ob_gp->totcol >= ob_mesh->totcol)) ? false : - true; + char element_name[200]; /* Need at least an edge. */ if (me_eval->totvert < 2) { - return; + return false; } - int r_idx; const float default_colors[2][4] = {{0.0f, 0.0f, 0.0f, 1.0f}, {0.7f, 0.7f, 0.7f, 1.0f}}; /* Create stroke material. */ - if (create_mat) { - if (stroke_mat_index == -1) { - gpencil_add_material(bmain, ob_gp, "Stroke", default_colors[0], true, false, &r_idx); - stroke_mat_index = ob_gp->totcol - 1; - } + make_element_name(ob_mesh->id.name + 2, "Stroke", 64, element_name); + int stroke_mat_index = gpencil_material_find_index_by_name(ob_gp, element_name); + + if (stroke_mat_index == -1) { + gpencil_add_material( + bmain, ob_gp, element_name, default_colors[0], true, false, &stroke_mat_index); } + /* Export faces as filled strokes. */ if (use_faces) { - if (create_mat) { - /* Find a material slot with material assigned. */ - bool material_found = false; - for (i = 0; i < ob_mesh->totcol; i++) { - Material *ma = BKE_object_material_get(ob_mesh, i + 1); - if (ma != NULL) { - material_found = true; - break; - } - } - - /* If no materials or use simple materials, create a simple fill. */ - if ((!material_found) || (simple_material)) { - if (fill_mat_index == -1) { - gpencil_add_material(bmain, ob_gp, "Fill", default_colors[1], false, true, &r_idx); - fill_mat_index = ob_gp->totcol - 1; - } - } - else { - /* Create all materials for fill. */ - for (i = 0; i < ob_mesh->totcol; i++) { - Material *ma = BKE_object_material_get(ob_mesh, i + 1); - if (ma == NULL) { - continue; - } - float color[4]; - copy_v3_v3(color, &ma->r); - color[3] = 1.0f; - gpencil_add_material(bmain, ob_gp, ma->id.name + 2, color, false, true, &r_idx); - } - } - } /* Read all polygons and create fill for each. */ if (mpoly_len > 0) { - bGPDlayer *gpl_fill = BKE_gpencil_layer_named_get(gpd, DATA_("Fills")); + make_element_name(ob_mesh->id.name + 2, "Fills", 128, element_name); + /* Create Layer and Frame. */ + bGPDlayer *gpl_fill = BKE_gpencil_layer_named_get(gpd, element_name); if (gpl_fill == NULL) { - gpl_fill = BKE_gpencil_layer_addnew(gpd, DATA_("Fills"), true); + gpl_fill = BKE_gpencil_layer_addnew(gpd, element_name, true); } bGPDframe *gpf_fill = BKE_gpencil_layer_frame_get( gpl_fill, CFRA + frame_offset, GP_GETFRAME_ADD_NEW); + int i; for (i = 0, mp = mpoly; i < mpoly_len; i++, mp++) { MLoop *ml = &mloop[mp->loopstart]; - /* Create fill stroke. */ - int mat_idx = (simple_material) || (mp->mat_nr + 1 > ob_gp->totcol - 1) ? - MAX2(fill_mat_index, 0) : - mp->mat_nr + 1; + /* Find material. */ + int mat_idx = 0; + Material *ma = BKE_object_material_get(ob_mesh, mp->mat_nr + 1); + make_element_name( + ob_mesh->id.name + 2, (ma != NULL) ? ma->id.name + 2 : "Fill", 64, element_name); + mat_idx = gpencil_material_find_index_by_name(ob_gp, element_name); + if (mat_idx == -1) { + float color[4]; + if (ma != NULL) { + copy_v3_v3(color, &ma->r); + color[3] = 1.0f; + } + else { + copy_v4_v4(color, default_colors[1]); + } + gpencil_add_material(bmain, ob_gp, element_name, color, false, true, &mat_idx); + } bGPDstroke *gps_fill = BKE_gpencil_stroke_add(gpf_fill, mat_idx, mp->totloop, 10, false); gps_fill->flag |= GP_STROKE_CYCLIC; /* Add points to strokes. */ - int j; - for (j = 0; j < mp->totloop; j++, ml++) { + for (int j = 0; j < mp->totloop; j++, ml++) { MVert *mv = &me_eval->mvert[ml->v]; - bGPDspoint *pt = &gps_fill->points[j]; copy_v3_v3(&pt->x, mv->co); mul_m4_v3(matrix, &pt->x); pt->pressure = 1.0f; pt->strength = 1.0f; } + /* If has only 3 points subdivide. */ + if (mp->totloop == 3) { + BKE_gpencil_stroke_subdivide(gpd, gps_fill, 1, GP_SUBDIV_SIMPLE); + } BKE_gpencil_stroke_geometry_update(gpd, gps_fill); } @@ -2437,17 +2423,23 @@ void BKE_gpencil_convert_mesh(Main *bmain, } /* Create stroke from edges. */ - bGPDlayer *gpl_stroke = BKE_gpencil_layer_named_get(gpd, DATA_("Lines")); + make_element_name(ob_mesh->id.name + 2, "Lines", 128, element_name); + + /* Create Layer and Frame. */ + bGPDlayer *gpl_stroke = BKE_gpencil_layer_named_get(gpd, element_name); if (gpl_stroke == NULL) { - gpl_stroke = BKE_gpencil_layer_addnew(gpd, DATA_("Lines"), true); + gpl_stroke = BKE_gpencil_layer_addnew(gpd, element_name, true); } bGPDframe *gpf_stroke = BKE_gpencil_layer_frame_get( gpl_stroke, CFRA + frame_offset, GP_GETFRAME_ADD_NEW); + gpencil_generate_edgeloops( ob_eval, gpd, gpf_stroke, stroke_mat_index, angle, thickness, offset, matrix, use_seams); /* Tag for recalculation */ DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE); + + return true; } /** diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c index 8831d09698b..57997eaf3a1 100644 --- a/source/blender/blenkernel/intern/hair.c +++ b/source/blender/blenkernel/intern/hair.c @@ -47,6 +47,11 @@ #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + +static const char *HAIR_ATTR_POSITION = "Position"; +static const char *HAIR_ATTR_RADIUS = "Radius"; + /* Hair datablock */ static void hair_random(Hair *hair); @@ -61,8 +66,10 @@ static void hair_init_data(ID *id) CustomData_reset(&hair->pdata); CustomData_reset(&hair->cdata); - CustomData_add_layer(&hair->pdata, CD_LOCATION, CD_CALLOC, NULL, hair->totpoint); - CustomData_add_layer(&hair->pdata, CD_RADIUS, CD_CALLOC, NULL, hair->totpoint); + CustomData_add_layer_named( + &hair->pdata, CD_PROP_FLOAT3, CD_CALLOC, NULL, hair->totpoint, HAIR_ATTR_POSITION); + CustomData_add_layer_named( + &hair->pdata, CD_PROP_FLOAT, CD_CALLOC, NULL, hair->totpoint, HAIR_ATTR_RADIUS); CustomData_add_layer(&hair->cdata, CD_HAIRCURVE, CD_CALLOC, NULL, hair->totcurve); BKE_hair_update_customdata_pointers(hair); @@ -104,6 +111,69 @@ static void hair_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void hair_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Hair *hair = (Hair *)id; + if (hair->id.us > 0 || BLO_write_is_undo(writer)) { + CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; + CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE]; + CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); + CustomData_blend_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff)); + + /* Write LibData */ + BLO_write_id_struct(writer, Hair, id_address, &hair->id); + BKE_id_blend_write(writer, &hair->id); + + /* Direct data */ + CustomData_blend_write(writer, &hair->pdata, players, hair->totpoint, CD_MASK_ALL, &hair->id); + CustomData_blend_write(writer, &hair->cdata, clayers, hair->totcurve, CD_MASK_ALL, &hair->id); + + BLO_write_pointer_array(writer, hair->totcol, hair->mat); + if (hair->adt) { + BKE_animdata_blend_write(writer, hair->adt); + } + + /* Remove temporary data. */ + if (players && players != players_buff) { + MEM_freeN(players); + } + if (clayers && clayers != clayers_buff) { + MEM_freeN(clayers); + } + } +} + +static void hair_blend_read_data(BlendDataReader *reader, ID *id) +{ + Hair *hair = (Hair *)id; + BLO_read_data_address(reader, &hair->adt); + BKE_animdata_blend_read_data(reader, hair->adt); + + /* Geometry */ + CustomData_blend_read(reader, &hair->pdata, hair->totpoint); + CustomData_blend_read(reader, &hair->cdata, hair->totcurve); + BKE_hair_update_customdata_pointers(hair); + + /* Materials */ + BLO_read_pointer_array(reader, (void **)&hair->mat); +} + +static void hair_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Hair *hair = (Hair *)id; + for (int a = 0; a < hair->totcol; a++) { + BLO_read_id_address(reader, hair->id.lib, &hair->mat[a]); + } +} + +static void hair_blend_read_expand(BlendExpander *expander, ID *id) +{ + Hair *hair = (Hair *)id; + for (int a = 0; a < hair->totcol; a++) { + BLO_expand(expander, hair->mat[a]); + } +} + IDTypeInfo IDType_ID_HA = { .id_code = ID_HA, .id_filter = FILTER_ID_HA, @@ -121,10 +191,10 @@ IDTypeInfo IDType_ID_HA = { .foreach_id = hair_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = hair_blend_write, + .blend_read_data = hair_blend_read_data, + .blend_read_lib = hair_blend_read_lib, + .blend_read_expand = hair_blend_read_expand, }; static void hair_random(Hair *hair) @@ -222,12 +292,17 @@ BoundBox *BKE_hair_boundbox_get(Object *ob) void BKE_hair_update_customdata_pointers(Hair *hair) { - hair->co = CustomData_get_layer(&hair->pdata, CD_LOCATION); - hair->radius = CustomData_get_layer(&hair->pdata, CD_RADIUS); + hair->co = CustomData_get_layer_named(&hair->pdata, CD_PROP_FLOAT3, HAIR_ATTR_POSITION); + hair->radius = CustomData_get_layer_named(&hair->pdata, CD_PROP_FLOAT, HAIR_ATTR_RADIUS); hair->curves = CustomData_get_layer(&hair->cdata, CD_HAIRCURVE); hair->mapping = CustomData_get_layer(&hair->cdata, CD_HAIRMAPPING); } +bool BKE_hair_customdata_required(Hair *UNUSED(hair), CustomDataLayer *layer) +{ + return layer->type == CD_PROP_FLOAT3 && STREQ(layer->name, HAIR_ATTR_POSITION); +} + /* Dependency Graph */ Hair *BKE_hair_new_for_eval(const Hair *hair_src, int totpoint, int totcurve) @@ -294,7 +369,8 @@ static Hair *hair_evaluate_modifiers(struct Depsgraph *depsgraph, } /* Ensure we are not overwriting referenced data. */ - CustomData_duplicate_referenced_layer(&hair->pdata, CD_LOCATION, hair->totpoint); + CustomData_duplicate_referenced_layer_named( + &hair->pdata, CD_PROP_FLOAT3, HAIR_ATTR_POSITION, hair->totpoint); BKE_hair_update_customdata_pointers(hair); /* Created deformed coordinates array on demand. */ diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c index bec0da750e1..01e3eef4e19 100644 --- a/source/blender/blenkernel/intern/icons.c +++ b/source/blender/blenkernel/intern/icons.c @@ -59,6 +59,8 @@ #include "IMB_imbuf_types.h" #include "IMB_thumbs.h" +#include "BLO_read_write.h" + /** * Only allow non-managed icons to be removed (by Python for eg). * Previews & ID's have their own functions to remove icons. @@ -214,17 +216,14 @@ void BKE_icons_deferred_free(void) static PreviewImage *previewimg_create_ex(size_t deferred_data_size) { - PreviewImage *prv_img = NULL; - int i; - - prv_img = MEM_mallocN(sizeof(PreviewImage) + deferred_data_size, "img_prv"); + PreviewImage *prv_img = MEM_mallocN(sizeof(PreviewImage) + deferred_data_size, "img_prv"); memset(prv_img, 0, sizeof(*prv_img)); /* leave deferred data dirty */ if (deferred_data_size) { prv_img->tag |= PRV_TAG_DEFFERED; } - for (i = 0; i < NUM_ICON_SIZES; i++) { + for (int i = 0; i < NUM_ICON_SIZES; i++) { prv_img->flag[i] |= PRV_CHANGED; prv_img->changed_timestamp[i] = 0; } @@ -240,9 +239,7 @@ void BKE_previewimg_freefunc(void *link) { PreviewImage *prv = (PreviewImage *)link; if (prv) { - int i; - - for (i = 0; i < NUM_ICON_SIZES; i++) { + for (int i = 0; i < NUM_ICON_SIZES; i++) { if (prv->rect[i]) { MEM_freeN(prv->rect[i]); } @@ -277,8 +274,7 @@ void BKE_previewimg_clear_single(struct PreviewImage *prv, enum eIconSizes size) void BKE_previewimg_clear(struct PreviewImage *prv) { - int i; - for (i = 0; i < NUM_ICON_SIZES; i++) { + for (int i = 0; i < NUM_ICON_SIZES; i++) { BKE_previewimg_clear_single(prv, i); } } @@ -286,11 +282,10 @@ void BKE_previewimg_clear(struct PreviewImage *prv) PreviewImage *BKE_previewimg_copy(const PreviewImage *prv) { PreviewImage *prv_img = NULL; - int i; if (prv) { prv_img = MEM_dupallocN(prv); - for (i = 0; i < NUM_ICON_SIZES; i++) { + for (int i = 0; i < NUM_ICON_SIZES; i++) { if (prv->rect[i]) { prv_img->rect[i] = MEM_dupallocN(prv->rect[i]); } @@ -522,6 +517,48 @@ void BKE_previewimg_ensure(PreviewImage *prv, const int size) } } +void BKE_previewimg_blend_write(BlendWriter *writer, const PreviewImage *prv) +{ + /* Note we write previews also for undo steps. It takes up some memory, + * but not doing so would causes all previews to be re-rendered after + * undo which is too expensive. */ + + if (prv == NULL) { + return; + } + + PreviewImage prv_copy = *prv; + /* don't write out large previews if not requested */ + if (!(U.flag & USER_SAVE_PREVIEWS)) { + prv_copy.w[1] = 0; + prv_copy.h[1] = 0; + prv_copy.rect[1] = NULL; + } + BLO_write_struct_at_address(writer, PreviewImage, prv, &prv_copy); + if (prv_copy.rect[0]) { + BLO_write_uint32_array(writer, prv_copy.w[0] * prv_copy.h[0], prv_copy.rect[0]); + } + if (prv_copy.rect[1]) { + BLO_write_uint32_array(writer, prv_copy.w[1] * prv_copy.h[1], prv_copy.rect[1]); + } +} + +void BKE_previewimg_blend_read(BlendDataReader *reader, PreviewImage *prv) +{ + if (prv == NULL) { + return; + } + + for (int i = 0; i < NUM_ICON_SIZES; i++) { + if (prv->rect[i]) { + BLO_read_data_address(reader, &prv->rect[i]); + } + prv->gputexture[i] = NULL; + } + prv->icon_id = 0; + prv->tag = 0; +} + void BKE_icon_changed(const int icon_id) { BLI_assert(BLI_thread_is_main()); @@ -546,8 +583,7 @@ void BKE_icon_changed(const int icon_id) /* If we have previews, they all are now invalid changed. */ if (p_prv && *p_prv) { - int i; - for (i = 0; i < NUM_ICON_SIZES; i++) { + for (int i = 0; i < NUM_ICON_SIZES; i++) { (*p_prv)->flag[i] |= PRV_CHANGED; (*p_prv)->changed_timestamp[i]++; } diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 7195ebda5ff..189eef5e175 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -95,7 +95,6 @@ IDProperty *IDP_CopyIDPArray(const IDProperty *array, const int flag) { /* don't use MEM_dupallocN because this may be part of an array */ IDProperty *narray, *tmp; - int i; BLI_assert(array->type == IDP_IDPARRAY); @@ -103,7 +102,7 @@ IDProperty *IDP_CopyIDPArray(const IDProperty *array, const int flag) *narray = *array; narray->data.pointer = MEM_dupallocN(array->data.pointer); - for (i = 0; i < narray->len; i++) { + for (int i = 0; i < narray->len; i++) { /* ok, the copy functions always allocate a new structure, * which doesn't work here. instead, simply copy the * contents of the new structure into the array cell, @@ -120,11 +119,9 @@ IDProperty *IDP_CopyIDPArray(const IDProperty *array, const int flag) static void IDP_FreeIDPArray(IDProperty *prop, const bool do_id_user) { - int i; - BLI_assert(prop->type == IDP_IDPARRAY); - for (i = 0; i < prop->len; i++) { + for (int i = 0; i < prop->len; i++) { IDP_FreePropertyContent_ex(GETPROP(prop, i), do_id_user); } @@ -176,9 +173,7 @@ void IDP_ResizeIDPArray(IDProperty *prop, int newlen) /* first check if the array buffer size has room */ if (newlen <= prop->totallen) { if (newlen < prop->len && prop->totallen - newlen < IDP_ARRAY_REALLOC_LIMIT) { - int i; - - for (i = newlen; i < prop->len; i++) { + for (int i = newlen; i < prop->len; i++) { IDP_FreePropertyContent(GETPROP(prop, i)); } @@ -194,8 +189,7 @@ void IDP_ResizeIDPArray(IDProperty *prop, int newlen) /* free trailing items */ if (newlen < prop->len) { /* newlen is smaller */ - int i; - for (i = newlen; i < prop->len; i++) { + for (int i = newlen; i < prop->len; i++) { IDP_FreePropertyContent(GETPROP(prop, i)); } } @@ -921,13 +915,12 @@ bool IDP_EqualsProperties_ex(IDProperty *prop1, IDProperty *prop2, const bool is case IDP_IDPARRAY: { IDProperty *array1 = IDP_IDPArray(prop1); IDProperty *array2 = IDP_IDPArray(prop2); - int i; if (prop1->len != prop2->len) { return false; } - for (i = 0; i < prop1->len; i++) { + for (int i = 0; i < prop1->len; i++) { if (!IDP_EqualsProperties_ex(&array1[i], &array2[i], is_strict)) { return false; } @@ -1253,7 +1246,6 @@ static void IDP_DirectLinkProperty(IDProperty *prop, BlendDataReader *reader); static void IDP_DirectLinkIDPArray(IDProperty *prop, BlendDataReader *reader) { IDProperty *array; - int i; /* since we didn't save the extra buffer, set totallen to len */ prop->totallen = prop->len; @@ -1268,7 +1260,7 @@ static void IDP_DirectLinkIDPArray(IDProperty *prop, BlendDataReader *reader) prop->totallen = 0; } - for (i = 0; i < prop->len; i++) { + for (int i = 0; i < prop->len; i++) { IDP_DirectLinkProperty(&array[i], reader); } } @@ -1276,7 +1268,6 @@ static void IDP_DirectLinkIDPArray(IDProperty *prop, BlendDataReader *reader) static void IDP_DirectLinkArray(IDProperty *prop, BlendDataReader *reader) { IDProperty **array; - int i; /* since we didn't save the extra buffer, set totallen to len */ prop->totallen = prop->len; @@ -1285,7 +1276,7 @@ static void IDP_DirectLinkArray(IDProperty *prop, BlendDataReader *reader) BLO_read_pointer_array(reader, &prop->data.pointer); array = prop->data.pointer; - for (i = 0; i < prop->len; i++) { + for (int i = 0; i < prop->len; i++) { IDP_DirectLinkProperty(array[i], reader); } } diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index be3795a02b1..0ddac216931 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -47,6 +47,9 @@ # include "intern/openexr/openexr_multi.h" #endif +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_brush_types.h" #include "DNA_camera_types.h" #include "DNA_defaults.h" @@ -97,6 +100,8 @@ #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + /* for image user iteration */ #include "DNA_node_types.h" #include "DNA_screen_types.h" @@ -216,6 +221,88 @@ static void image_foreach_cache(ID *id, } } +static void image_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Image *ima = (Image *)id; + if (ima->id.us > 0 || BLO_write_is_undo(writer)) { + ImagePackedFile *imapf; + + /* Some trickery to keep forward compatibility of packed images. */ + BLI_assert(ima->packedfile == NULL); + if (ima->packedfiles.first != NULL) { + imapf = ima->packedfiles.first; + ima->packedfile = imapf->packedfile; + } + + /* write LibData */ + BLO_write_id_struct(writer, Image, id_address, &ima->id); + BKE_id_blend_write(writer, &ima->id); + + for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { + BLO_write_struct(writer, ImagePackedFile, imapf); + BKE_packedfile_blend_write(writer, imapf->packedfile); + } + + BKE_previewimg_blend_write(writer, ima->preview); + + LISTBASE_FOREACH (ImageView *, iv, &ima->views) { + BLO_write_struct(writer, ImageView, iv); + } + BLO_write_struct(writer, Stereo3dFormat, ima->stereo3d_format); + + BLO_write_struct_list(writer, ImageTile, &ima->tiles); + + ima->packedfile = NULL; + + BLO_write_struct_list(writer, RenderSlot, &ima->renderslots); + } +} + +static void image_blend_read_data(BlendDataReader *reader, ID *id) +{ + Image *ima = (Image *)id; + BLO_read_list(reader, &ima->tiles); + + BLO_read_list(reader, &(ima->renderslots)); + if (!BLO_read_data_is_undo(reader)) { + /* We reset this last render slot index only when actually reading a file, not for undo. */ + ima->last_render_slot = ima->render_slot; + } + + BLO_read_list(reader, &(ima->views)); + BLO_read_list(reader, &(ima->packedfiles)); + + if (ima->packedfiles.first) { + LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) { + BKE_packedfile_blend_read(reader, &imapf->packedfile); + } + ima->packedfile = NULL; + } + else { + BKE_packedfile_blend_read(reader, &ima->packedfile); + } + + BLI_listbase_clear(&ima->anims); + BLO_read_data_address(reader, &ima->preview); + BKE_previewimg_blend_read(reader, ima->preview); + BLO_read_data_address(reader, &ima->stereo3d_format); + LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { + tile->ok = IMA_OK; + } +} + +static void image_blend_read_lib(BlendLibReader *UNUSED(reader), ID *id) +{ + Image *ima = (Image *)id; + /* Images have some kind of 'main' cache, when NULL we should also clear all others. */ + /* Needs to be done *after* cache pointers are restored (call to + * `foreach_cache`/`blo_cache_storage_entry_restore_in_new`), easier for now to do it in + * lib_link... */ + if (ima->cache == NULL) { + BKE_image_free_buffers(ima); + } +} + IDTypeInfo IDType_ID_IM = { .id_code = ID_IM, .id_filter = FILTER_ID_IM, @@ -233,9 +320,9 @@ IDTypeInfo IDType_ID_IM = { .foreach_id = NULL, .foreach_cache = image_foreach_cache, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, + .blend_write = image_blend_write, + .blend_read_data = image_blend_read_data, + .blend_read_lib = image_blend_read_lib, .blend_read_expand = NULL, }; @@ -4073,12 +4160,11 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, } else { const int totviews = BLI_listbase_count(&ima->views); - int i; struct ImBuf **ibuf_arr; ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); - for (i = 0; i < totfiles; i++) { + for (int i = 0; i < totfiles; i++) { ibuf_arr[i] = load_sequence_single(ima, iuser, frame, i, &assign); } @@ -4090,13 +4176,13 @@ static ImBuf *image_load_sequence_file(Image *ima, ImageUser *iuser, int entry, ibuf = ibuf_arr[(iuser ? iuser->multi_index : 0)]; if (assign) { - for (i = 0; i < totviews; i++) { + for (int i = 0; i < totviews; i++) { image_assign_ibuf(ima, ibuf_arr[i], i, entry); } } /* "remove" the others (decrease their refcount) */ - for (i = 0; i < totviews; i++) { + for (int i = 0; i < totviews; i++) { if (ibuf_arr[i] != ibuf) { IMB_freeImBuf(ibuf_arr[i]); } @@ -4232,12 +4318,11 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) const bool is_multiview = BKE_image_is_multiview(ima); const int totfiles = image_num_files(ima); ImageTile *tile = BKE_image_get_tile(ima, 0); - int i; if (totfiles != BLI_listbase_count_at_most(&ima->anims, totfiles + 1)) { image_free_anims(ima); - for (i = 0; i < totfiles; i++) { + for (int i = 0; i < totfiles; i++) { /* allocate the ImageAnim */ ImageAnim *ia = MEM_callocN(sizeof(ImageAnim), "Image Anim"); BLI_addtail(&ima->anims, ia); @@ -4254,7 +4339,7 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * totviews, "Image Views (movie) Imbufs"); - for (i = 0; i < totfiles; i++) { + for (int i = 0; i < totfiles; i++) { ibuf_arr[i] = load_movie_single(ima, iuser, frame, i); } @@ -4262,7 +4347,7 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) IMB_ImBufFromStereo3d(ima->stereo3d_format, ibuf_arr[0], &ibuf_arr[0], &ibuf_arr[1]); } - for (i = 0; i < totviews; i++) { + for (int i = 0; i < totviews; i++) { if (ibuf_arr[i]) { image_assign_ibuf(ima, ibuf_arr[i], i, frame); } @@ -4275,7 +4360,7 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame) ibuf = ibuf_arr[(iuser ? iuser->multi_index : 0)]; /* "remove" the others (decrease their refcount) */ - for (i = 0; i < totviews; i++) { + for (int i = 0; i < totviews; i++) { if (ibuf_arr[i] != ibuf) { IMB_freeImBuf(ibuf_arr[i]); } @@ -4411,12 +4496,11 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) else { struct ImBuf **ibuf_arr; const int totviews = BLI_listbase_count(&ima->views); - int i; BLI_assert(totviews > 0); ibuf_arr = MEM_callocN(sizeof(ImBuf *) * totviews, "Image Views Imbufs"); - for (i = 0; i < totfiles; i++) { + for (int i = 0; i < totfiles; i++) { ibuf_arr[i] = load_image_single(ima, iuser, cfra, i, has_packed, &assign); } @@ -4427,7 +4511,7 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra) } /* return the original requested ImBuf */ - i = (iuser && iuser->multi_index < totviews) ? iuser->multi_index : 0; + int i = (iuser && iuser->multi_index < totviews) ? iuser->multi_index : 0; ibuf = ibuf_arr[i]; if (assign) { @@ -5681,10 +5765,9 @@ static void image_update_views_format(Image *ima, ImageUser *iuser) /* nothing to do */ } else if (ima->views_format == R_IMF_VIEWS_STEREO_3D) { - int i; const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME}; - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { image_add_view(ima, names[i], ima->filepath); } return; diff --git a/source/blender/blenkernel/intern/image_gpu.c b/source/blender/blenkernel/intern/image_gpu.c index d4a1c1e2c46..f37e038e69e 100644 --- a/source/blender/blenkernel/intern/image_gpu.c +++ b/source/blender/blenkernel/intern/image_gpu.c @@ -272,6 +272,13 @@ static GPUTexture *image_get_gpu_texture(Image *ima, * context and might as well ensure we have as much space free as possible. */ gpu_free_unused_buffers(); + /* Free GPU textures when requesting a different render pass/layer. */ + if (ima->gpu_pass != iuser->pass || ima->gpu_layer != iuser->layer) { + ima->gpu_pass = iuser->pass; + ima->gpu_layer = iuser->layer; + ima->gpuflag |= IMA_GPU_REFRESH; + } + /* currently, gpu refresh tagging is used by ima sequences */ if (ima->gpuflag & IMA_GPU_REFRESH) { image_free_gpu(ima, true); @@ -282,7 +289,10 @@ static GPUTexture *image_get_gpu_texture(Image *ima, BKE_image_tag_time(ima); /* Test if we already have a texture. */ - GPUTexture **tex = get_image_gpu_texture_ptr(ima, textarget, iuser ? iuser->multiview_eye : 0); + const int current_view = iuser ? ((iuser->flag & IMA_SHOW_STEREO) != 0 ? iuser->multiview_eye : + iuser->view) : + 0; + GPUTexture **tex = get_image_gpu_texture_ptr(ima, textarget, current_view); if (*tex) { return *tex; } diff --git a/source/blender/blenkernel/intern/image_save.c b/source/blender/blenkernel/intern/image_save.c index 19eb3380b8e..e571499ba8e 100644 --- a/source/blender/blenkernel/intern/image_save.c +++ b/source/blender/blenkernel/intern/image_save.c @@ -252,7 +252,6 @@ static bool image_save_single(ReportList *reports, } /* individual multiview images */ else if (imf->views_format == R_IMF_VIEWS_INDIVIDUAL) { - int i; unsigned char planes = ibuf->planes; const int totviews = (rr ? BLI_listbase_count(&rr->views) : BLI_listbase_count(&ima->views)); @@ -260,7 +259,7 @@ static bool image_save_single(ReportList *reports, BKE_image_release_ibuf(ima, ibuf, lock); } - for (i = 0; i < totviews; i++) { + for (int i = 0; i < totviews; i++) { char filepath[FILE_MAX]; bool ok_view = false; const char *view = rr ? ((RenderView *)BLI_findlink(&rr->views, i))->name : @@ -324,12 +323,11 @@ static bool image_save_single(ReportList *reports, unsigned char planes = ibuf->planes; const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME}; - int i; /* we need to get the specific per-view buffers */ BKE_image_release_ibuf(ima, ibuf, lock); - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { ImageUser view_iuser; if (iuser) { @@ -382,7 +380,7 @@ static bool image_save_single(ReportList *reports, IMB_freeImBuf(ibuf); - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { IMB_freeImBuf(ibuf_stereo[i]); } } diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 456325851a6..1b63aa1a8af 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -28,12 +28,16 @@ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" +#include "BLI_endian_switch.h" #include "BLI_math_vector.h" #include "BLI_string_utils.h" #include "BLI_utildefines.h" #include "BLT_translation.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_ID.h" #include "DNA_anim_types.h" #include "DNA_key_types.h" @@ -43,6 +47,7 @@ #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "BKE_anim_data.h" #include "BKE_curve.h" #include "BKE_customdata.h" #include "BKE_deform.h" @@ -58,6 +63,8 @@ #include "RNA_access.h" +#include "BLO_read_write.h" + static void shapekey_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, @@ -98,6 +105,94 @@ static void shapekey_foreach_id(ID *id, LibraryForeachIDData *data) BKE_LIB_FOREACHID_PROCESS_ID(data, key->from, IDWALK_CB_LOOPBACK); } +static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Key *key = (Key *)id; + if (key->id.us > 0 || BLO_write_is_undo(writer)) { + /* write LibData */ + BLO_write_id_struct(writer, Key, id_address, &key->id); + BKE_id_blend_write(writer, &key->id); + + if (key->adt) { + BKE_animdata_blend_write(writer, key->adt); + } + + /* direct data */ + LISTBASE_FOREACH (KeyBlock *, kb, &key->block) { + BLO_write_struct(writer, KeyBlock, kb); + if (kb->data) { + BLO_write_raw(writer, kb->totelem * key->elemsize, kb->data); + } + } + } +} + +/* old defines from DNA_ipo_types.h for data-type, stored in DNA - don't modify! */ +#define IPO_FLOAT 4 +#define IPO_BEZTRIPLE 100 +#define IPO_BPOINT 101 + +static void switch_endian_keyblock(Key *key, KeyBlock *kb) +{ + int elemsize = key->elemsize; + char *data = kb->data; + + for (int a = 0; a < kb->totelem; a++) { + const char *cp = key->elemstr; + char *poin = data; + + while (cp[0]) { /* cp[0] == amount */ + switch (cp[1]) { /* cp[1] = type */ + case IPO_FLOAT: + case IPO_BPOINT: + case IPO_BEZTRIPLE: { + int b = cp[0]; + BLI_endian_switch_float_array((float *)poin, b); + poin += sizeof(float) * b; + break; + } + } + + cp += 2; + } + data += elemsize; + } +} + +static void shapekey_blend_read_data(BlendDataReader *reader, ID *id) +{ + Key *key = (Key *)id; + BLO_read_list(reader, &(key->block)); + + BLO_read_data_address(reader, &key->adt); + BKE_animdata_blend_read_data(reader, key->adt); + + BLO_read_data_address(reader, &key->refkey); + + LISTBASE_FOREACH (KeyBlock *, kb, &key->block) { + BLO_read_data_address(reader, &kb->data); + + if (BLO_read_requires_endian_switch(reader)) { + switch_endian_keyblock(key, kb); + } + } +} + +static void shapekey_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Key *key = (Key *)id; + BLI_assert((key->id.tag & LIB_TAG_EXTERN) == 0); + + BLO_read_id_address(reader, key->id.lib, &key->ipo); // XXX deprecated - old animation system + BLO_read_id_address(reader, key->id.lib, &key->from); +} + +static void shapekey_blend_read_expand(BlendExpander *expander, ID *id) +{ + Key *key = (Key *)id; + BLO_expand(expander, key->ipo); // XXX deprecated - old animation system +} + IDTypeInfo IDType_ID_KE = { .id_code = ID_KE, .id_filter = 0, @@ -115,21 +210,16 @@ IDTypeInfo IDType_ID_KE = { .foreach_id = shapekey_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = shapekey_blend_write, + .blend_read_data = shapekey_blend_read_data, + .blend_read_lib = shapekey_blend_read_lib, + .blend_read_expand = shapekey_blend_read_expand, }; #define KEY_MODE_DUMMY 0 /* use where mode isn't checked for */ #define KEY_MODE_BPOINT 1 #define KEY_MODE_BEZTRIPLE 2 -/* old defines from DNA_ipo_types.h for data-type, stored in DNA - don't modify! */ -#define IPO_FLOAT 4 -#define IPO_BEZTRIPLE 100 -#define IPO_BPOINT 101 - /* Internal use only. */ typedef struct WeightsArrayCache { int num_defgroup_weights; @@ -1242,7 +1332,6 @@ static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cac defgrp_index = BKE_object_defgroup_name_index(ob, vgroup); if (defgrp_index != -1) { float *weights; - int i; if (cache) { if (cache->defgroup_weights == NULL) { @@ -1260,6 +1349,7 @@ static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cac weights = MEM_mallocN(totvert * sizeof(float), "weights"); if (em) { + int i; const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) { dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); @@ -1267,7 +1357,7 @@ static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cac } } else { - for (i = 0; i < totvert; i++, dvert++) { + for (int i = 0; i < totvert; i++, dvert++) { weights[i] = BKE_defvert_find_weight(dvert, defgrp_index); } } @@ -1860,13 +1950,10 @@ KeyBlock *BKE_keyblock_from_object_reference(Object *ob) /* get the appropriate KeyBlock given an index */ KeyBlock *BKE_keyblock_from_key(Key *key, int index) { - KeyBlock *kb; - int i; - if (key) { - kb = key->block.first; + KeyBlock *kb = key->block.first; - for (i = 1; i < key->totkey; i++) { + for (int i = 1; i < key->totkey; i++) { kb = kb->next; if (index == i) { diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 5201faef9cd..a3267c0762e 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -249,11 +249,10 @@ void BKE_lattice_bitmap_from_flag( Lattice *lt, BLI_bitmap *bitmap, const short flag, const bool clear, const bool respecthide) { const unsigned int tot = lt->pntsu * lt->pntsv * lt->pntsw; - unsigned int i; BPoint *bp; bp = lt->def; - for (i = 0; i < tot; i++, bp++) { + for (int i = 0; i < tot; i++, bp++) { if ((bp->f1 & flag) && (!respecthide || !bp->hide)) { BLI_BITMAP_ENABLE(bitmap, i); } diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index 4da59ff302d..1ad34fde0fa 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -931,6 +931,8 @@ void BKE_main_collection_sync(const Main *bmain) for (const Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { BKE_scene_collection_sync(scene); } + + BKE_layer_collection_local_sync_all(bmain); } void BKE_main_collection_sync_remap(const Main *bmain) @@ -1246,6 +1248,28 @@ void BKE_layer_collection_local_sync(ViewLayer *view_layer, const View3D *v3d) } /** + * Sync the local collection for all the view-ports. + */ +void BKE_layer_collection_local_sync_all(const Main *bmain) +{ + LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + if (area->spacetype != SPACE_VIEW3D) { + continue; + } + View3D *v3d = area->spacedata.first; + if (v3d->flag & V3D_LOCAL_COLLECTIONS) { + BKE_layer_collection_local_sync(view_layer, v3d); + } + } + } + } + } +} + +/** * Isolate the collection locally * * Same as BKE_layer_collection_isolate_local but for a viewport diff --git a/source/blender/blenkernel/intern/light.c b/source/blender/blenkernel/intern/light.c index 976fa010057..1ce079b006e 100644 --- a/source/blender/blenkernel/intern/light.c +++ b/source/blender/blenkernel/intern/light.c @@ -25,6 +25,9 @@ #include "MEM_guardedalloc.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_anim_types.h" #include "DNA_defaults.h" #include "DNA_light_types.h" @@ -37,6 +40,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BKE_anim_data.h" #include "BKE_colortools.h" #include "BKE_icons.h" #include "BKE_idtype.h" @@ -50,6 +54,8 @@ #include "DEG_depsgraph.h" +#include "BLO_read_write.h" + static void light_init_data(ID *id) { Light *la = (Light *)id; @@ -119,6 +125,59 @@ static void light_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void light_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Light *la = (Light *)id; + if (la->id.us > 0 || BLO_write_is_undo(writer)) { + /* write LibData */ + BLO_write_id_struct(writer, Light, id_address, &la->id); + BKE_id_blend_write(writer, &la->id); + + if (la->adt) { + BKE_animdata_blend_write(writer, la->adt); + } + + if (la->curfalloff) { + BKE_curvemapping_blend_write(writer, la->curfalloff); + } + + /* Node-tree is integral part of lights, no libdata. */ + if (la->nodetree) { + BLO_write_struct(writer, bNodeTree, la->nodetree); + ntreeBlendWrite(writer, la->nodetree); + } + + BKE_previewimg_blend_write(writer, la->preview); + } +} + +static void light_blend_read_data(BlendDataReader *reader, ID *id) +{ + Light *la = (Light *)id; + BLO_read_data_address(reader, &la->adt); + BKE_animdata_blend_read_data(reader, la->adt); + + BLO_read_data_address(reader, &la->curfalloff); + if (la->curfalloff) { + BKE_curvemapping_blend_read(reader, la->curfalloff); + } + + BLO_read_data_address(reader, &la->preview); + BKE_previewimg_blend_read(reader, la->preview); +} + +static void light_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Light *la = (Light *)id; + BLO_read_id_address(reader, la->id.lib, &la->ipo); // XXX deprecated - old animation system +} + +static void light_blend_read_expand(BlendExpander *expander, ID *id) +{ + Light *la = (Light *)id; + BLO_expand(expander, la->ipo); // XXX deprecated - old animation system +} + IDTypeInfo IDType_ID_LA = { .id_code = ID_LA, .id_filter = FILTER_ID_LA, @@ -136,10 +195,10 @@ IDTypeInfo IDType_ID_LA = { .foreach_id = light_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = light_blend_write, + .blend_read_data = light_blend_read_data, + .blend_read_lib = light_blend_read_lib, + .blend_read_expand = light_blend_read_expand, }; Light *BKE_light_add(Main *bmain, const char *name) diff --git a/source/blender/blenkernel/intern/lightprobe.c b/source/blender/blenkernel/intern/lightprobe.c index b4b13306112..cf680641a7b 100644 --- a/source/blender/blenkernel/intern/lightprobe.c +++ b/source/blender/blenkernel/intern/lightprobe.c @@ -30,6 +30,7 @@ #include "BLI_utildefines.h" +#include "BKE_anim_data.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" @@ -38,6 +39,8 @@ #include "BLT_translation.h" +#include "BLO_read_write.h" + static void lightprobe_init_data(ID *id) { LightProbe *probe = (LightProbe *)id; @@ -54,6 +57,33 @@ static void lightprobe_foreach_id(ID *id, LibraryForeachIDData *data) BKE_LIB_FOREACHID_PROCESS(data, probe->visibility_grp, IDWALK_CB_NOP); } +static void lightprobe_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + LightProbe *prb = (LightProbe *)id; + if (prb->id.us > 0 || BLO_write_is_undo(writer)) { + /* write LibData */ + BLO_write_id_struct(writer, LightProbe, id_address, &prb->id); + BKE_id_blend_write(writer, &prb->id); + + if (prb->adt) { + BKE_animdata_blend_write(writer, prb->adt); + } + } +} + +static void lightprobe_blend_read_data(BlendDataReader *reader, ID *id) +{ + LightProbe *prb = (LightProbe *)id; + BLO_read_data_address(reader, &prb->adt); + BKE_animdata_blend_read_data(reader, prb->adt); +} + +static void lightprobe_blend_read_lib(BlendLibReader *reader, ID *id) +{ + LightProbe *prb = (LightProbe *)id; + BLO_read_id_address(reader, prb->id.lib, &prb->visibility_grp); +} + IDTypeInfo IDType_ID_LP = { .id_code = ID_LP, .id_filter = FILTER_ID_LP, @@ -71,9 +101,9 @@ IDTypeInfo IDType_ID_LP = { .foreach_id = lightprobe_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, + .blend_write = lightprobe_blend_write, + .blend_read_data = lightprobe_blend_read_data, + .blend_read_lib = lightprobe_blend_read_lib, .blend_read_expand = NULL, }; diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index 8dc44a32eaa..f0f06b6402a 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -39,6 +39,7 @@ #include "BLT_translation.h" +#include "BKE_anim_data.h" #include "BKE_colorband.h" #include "BKE_colortools.h" #include "BKE_context.h" @@ -51,6 +52,8 @@ #include "BKE_node.h" #include "BKE_texture.h" +#include "BLO_read_write.h" + static void linestyle_init_data(ID *id) { FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; @@ -189,6 +192,558 @@ static void linestyle_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modifiers) +{ + LineStyleModifier *m; + + for (m = modifiers->first; m; m = m->next) { + int struct_nr; + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_AlongStroke); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromCamera); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromObject); + break; + case LS_MODIFIER_MATERIAL: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Material); + break; + case LS_MODIFIER_TANGENT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Tangent); + break; + case LS_MODIFIER_NOISE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Noise); + break; + case LS_MODIFIER_CREASE_ANGLE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_CreaseAngle); + break; + case LS_MODIFIER_CURVATURE_3D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Curvature_3D); + break; + default: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ + } + BLO_write_struct_by_id(writer, struct_nr, m); + } + for (m = modifiers->first; m; m = m->next) { + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + BLO_write_struct( + writer, ColorBand, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + BLO_write_struct( + writer, ColorBand, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); + break; + case LS_MODIFIER_MATERIAL: + BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Material *)m)->color_ramp); + break; + case LS_MODIFIER_TANGENT: + BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Tangent *)m)->color_ramp); + break; + case LS_MODIFIER_NOISE: + BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Noise *)m)->color_ramp); + break; + case LS_MODIFIER_CREASE_ANGLE: + BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp); + break; + case LS_MODIFIER_CURVATURE_3D: + BLO_write_struct( + writer, ColorBand, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp); + break; + } + } +} + +static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modifiers) +{ + LineStyleModifier *m; + + for (m = modifiers->first; m; m = m->next) { + int struct_nr; + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_AlongStroke); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromCamera); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromObject); + break; + case LS_MODIFIER_MATERIAL: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Material); + break; + case LS_MODIFIER_TANGENT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Tangent); + break; + case LS_MODIFIER_NOISE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Noise); + break; + case LS_MODIFIER_CREASE_ANGLE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_CreaseAngle); + break; + case LS_MODIFIER_CURVATURE_3D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Curvature_3D); + break; + default: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ + } + BLO_write_struct_by_id(writer, struct_nr, m); + } + for (m = modifiers->first; m; m = m->next) { + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_AlongStroke *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + BKE_curvemapping_blend_write(writer, + ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + BKE_curvemapping_blend_write(writer, + ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve); + break; + case LS_MODIFIER_MATERIAL: + BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Material *)m)->curve); + break; + case LS_MODIFIER_TANGENT: + BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Tangent *)m)->curve); + break; + case LS_MODIFIER_NOISE: + BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Noise *)m)->curve); + break; + case LS_MODIFIER_CREASE_ANGLE: + BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_CreaseAngle *)m)->curve); + break; + case LS_MODIFIER_CURVATURE_3D: + BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Curvature_3D *)m)->curve); + break; + } + } +} + +static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *modifiers) +{ + LineStyleModifier *m; + + for (m = modifiers->first; m; m = m->next) { + int struct_nr; + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_AlongStroke); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromCamera); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromObject); + break; + case LS_MODIFIER_MATERIAL: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Material); + break; + case LS_MODIFIER_CALLIGRAPHY: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Calligraphy); + break; + case LS_MODIFIER_TANGENT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Tangent); + break; + case LS_MODIFIER_NOISE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Noise); + break; + case LS_MODIFIER_CREASE_ANGLE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_CreaseAngle); + break; + case LS_MODIFIER_CURVATURE_3D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Curvature_3D); + break; + default: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ + } + BLO_write_struct_by_id(writer, struct_nr, m); + } + for (m = modifiers->first; m; m = m->next) { + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_AlongStroke *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + BKE_curvemapping_blend_write(writer, + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + BKE_curvemapping_blend_write(writer, + ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve); + break; + case LS_MODIFIER_MATERIAL: + BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_Material *)m)->curve); + break; + case LS_MODIFIER_TANGENT: + BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_Tangent *)m)->curve); + break; + case LS_MODIFIER_CREASE_ANGLE: + BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_CreaseAngle *)m)->curve); + break; + case LS_MODIFIER_CURVATURE_3D: + BKE_curvemapping_blend_write(writer, + ((LineStyleThicknessModifier_Curvature_3D *)m)->curve); + break; + } + } +} + +static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *modifiers) +{ + LineStyleModifier *m; + + for (m = modifiers->first; m; m = m->next) { + int struct_nr; + switch (m->type) { + case LS_MODIFIER_SAMPLING: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Sampling); + break; + case LS_MODIFIER_BEZIER_CURVE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BezierCurve); + break; + case LS_MODIFIER_SINUS_DISPLACEMENT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SinusDisplacement); + break; + case LS_MODIFIER_SPATIAL_NOISE: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SpatialNoise); + break; + case LS_MODIFIER_PERLIN_NOISE_1D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise1D); + break; + case LS_MODIFIER_PERLIN_NOISE_2D: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise2D); + break; + case LS_MODIFIER_BACKBONE_STRETCHER: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BackboneStretcher); + break; + case LS_MODIFIER_TIP_REMOVER: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_TipRemover); + break; + case LS_MODIFIER_POLYGONIZATION: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Polygonalization); + break; + case LS_MODIFIER_GUIDING_LINES: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_GuidingLines); + break; + case LS_MODIFIER_BLUEPRINT: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Blueprint); + break; + case LS_MODIFIER_2D_OFFSET: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DOffset); + break; + case LS_MODIFIER_2D_TRANSFORM: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DTransform); + break; + case LS_MODIFIER_SIMPLIFICATION: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Simplification); + break; + default: + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ + } + BLO_write_struct_by_id(writer, struct_nr, m); + } +} + +static void linestyle_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; + if (linestyle->id.us > 0 || BLO_write_is_undo(writer)) { + BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id); + BKE_id_blend_write(writer, &linestyle->id); + + if (linestyle->adt) { + BKE_animdata_blend_write(writer, linestyle->adt); + } + + write_linestyle_color_modifiers(writer, &linestyle->color_modifiers); + write_linestyle_alpha_modifiers(writer, &linestyle->alpha_modifiers); + write_linestyle_thickness_modifiers(writer, &linestyle->thickness_modifiers); + write_linestyle_geometry_modifiers(writer, &linestyle->geometry_modifiers); + for (int a = 0; a < MAX_MTEX; a++) { + if (linestyle->mtex[a]) { + BLO_write_struct(writer, MTex, linestyle->mtex[a]); + } + } + if (linestyle->nodetree) { + BLO_write_struct(writer, bNodeTree, linestyle->nodetree); + ntreeBlendWrite(writer, linestyle->nodetree); + } + } +} + +static void direct_link_linestyle_color_modifier(BlendDataReader *reader, + LineStyleModifier *modifier) +{ + switch (modifier->type) { + case LS_MODIFIER_ALONG_STROKE: { + LineStyleColorModifier_AlongStroke *m = (LineStyleColorModifier_AlongStroke *)modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_DISTANCE_FROM_CAMERA: { + LineStyleColorModifier_DistanceFromCamera *m = (LineStyleColorModifier_DistanceFromCamera *) + modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_DISTANCE_FROM_OBJECT: { + LineStyleColorModifier_DistanceFromObject *m = (LineStyleColorModifier_DistanceFromObject *) + modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_MATERIAL: { + LineStyleColorModifier_Material *m = (LineStyleColorModifier_Material *)modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_TANGENT: { + LineStyleColorModifier_Tangent *m = (LineStyleColorModifier_Tangent *)modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_NOISE: { + LineStyleColorModifier_Noise *m = (LineStyleColorModifier_Noise *)modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_CREASE_ANGLE: { + LineStyleColorModifier_CreaseAngle *m = (LineStyleColorModifier_CreaseAngle *)modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + case LS_MODIFIER_CURVATURE_3D: { + LineStyleColorModifier_Curvature_3D *m = (LineStyleColorModifier_Curvature_3D *)modifier; + BLO_read_data_address(reader, &m->color_ramp); + break; + } + } +} + +static void direct_link_linestyle_alpha_modifier(BlendDataReader *reader, + LineStyleModifier *modifier) +{ + switch (modifier->type) { + case LS_MODIFIER_ALONG_STROKE: { + LineStyleAlphaModifier_AlongStroke *m = (LineStyleAlphaModifier_AlongStroke *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_DISTANCE_FROM_CAMERA: { + LineStyleAlphaModifier_DistanceFromCamera *m = (LineStyleAlphaModifier_DistanceFromCamera *) + modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_DISTANCE_FROM_OBJECT: { + LineStyleAlphaModifier_DistanceFromObject *m = (LineStyleAlphaModifier_DistanceFromObject *) + modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_MATERIAL: { + LineStyleAlphaModifier_Material *m = (LineStyleAlphaModifier_Material *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_TANGENT: { + LineStyleAlphaModifier_Tangent *m = (LineStyleAlphaModifier_Tangent *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_NOISE: { + LineStyleAlphaModifier_Noise *m = (LineStyleAlphaModifier_Noise *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_CREASE_ANGLE: { + LineStyleAlphaModifier_CreaseAngle *m = (LineStyleAlphaModifier_CreaseAngle *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_CURVATURE_3D: { + LineStyleAlphaModifier_Curvature_3D *m = (LineStyleAlphaModifier_Curvature_3D *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + } +} + +static void direct_link_linestyle_thickness_modifier(BlendDataReader *reader, + LineStyleModifier *modifier) +{ + switch (modifier->type) { + case LS_MODIFIER_ALONG_STROKE: { + LineStyleThicknessModifier_AlongStroke *m = (LineStyleThicknessModifier_AlongStroke *) + modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_DISTANCE_FROM_CAMERA: { + LineStyleThicknessModifier_DistanceFromCamera *m = + (LineStyleThicknessModifier_DistanceFromCamera *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_DISTANCE_FROM_OBJECT: { + LineStyleThicknessModifier_DistanceFromObject *m = + (LineStyleThicknessModifier_DistanceFromObject *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_MATERIAL: { + LineStyleThicknessModifier_Material *m = (LineStyleThicknessModifier_Material *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_TANGENT: { + LineStyleThicknessModifier_Tangent *m = (LineStyleThicknessModifier_Tangent *)modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_CREASE_ANGLE: { + LineStyleThicknessModifier_CreaseAngle *m = (LineStyleThicknessModifier_CreaseAngle *) + modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + case LS_MODIFIER_CURVATURE_3D: { + LineStyleThicknessModifier_Curvature_3D *m = (LineStyleThicknessModifier_Curvature_3D *) + modifier; + BLO_read_data_address(reader, &m->curve); + BKE_curvemapping_blend_read(reader, m->curve); + break; + } + } +} + +static void direct_link_linestyle_geometry_modifier(BlendDataReader *UNUSED(reader), + LineStyleModifier *UNUSED(modifier)) +{ +} + +static void linestyle_blend_read_data(BlendDataReader *reader, ID *id) +{ + FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; + + BLO_read_data_address(reader, &linestyle->adt); + BKE_animdata_blend_read_data(reader, linestyle->adt); + BLO_read_list(reader, &linestyle->color_modifiers); + LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->color_modifiers) { + direct_link_linestyle_color_modifier(reader, modifier); + } + BLO_read_list(reader, &linestyle->alpha_modifiers); + LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->alpha_modifiers) { + direct_link_linestyle_alpha_modifier(reader, modifier); + } + BLO_read_list(reader, &linestyle->thickness_modifiers); + LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->thickness_modifiers) { + direct_link_linestyle_thickness_modifier(reader, modifier); + } + BLO_read_list(reader, &linestyle->geometry_modifiers); + LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->geometry_modifiers) { + direct_link_linestyle_geometry_modifier(reader, modifier); + } + for (int a = 0; a < MAX_MTEX; a++) { + BLO_read_data_address(reader, &linestyle->mtex[a]); + } +} + +static void linestyle_blend_read_lib(BlendLibReader *reader, ID *id) +{ + FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; + + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) { + switch (m->type) { + case LS_MODIFIER_DISTANCE_FROM_OBJECT: { + LineStyleColorModifier_DistanceFromObject *cm = + (LineStyleColorModifier_DistanceFromObject *)m; + BLO_read_id_address(reader, linestyle->id.lib, &cm->target); + break; + } + } + } + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->alpha_modifiers) { + switch (m->type) { + case LS_MODIFIER_DISTANCE_FROM_OBJECT: { + LineStyleAlphaModifier_DistanceFromObject *am = + (LineStyleAlphaModifier_DistanceFromObject *)m; + BLO_read_id_address(reader, linestyle->id.lib, &am->target); + break; + } + } + } + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->thickness_modifiers) { + switch (m->type) { + case LS_MODIFIER_DISTANCE_FROM_OBJECT: { + LineStyleThicknessModifier_DistanceFromObject *tm = + (LineStyleThicknessModifier_DistanceFromObject *)m; + BLO_read_id_address(reader, linestyle->id.lib, &tm->target); + break; + } + } + } + for (int a = 0; a < MAX_MTEX; a++) { + MTex *mtex = linestyle->mtex[a]; + if (mtex) { + BLO_read_id_address(reader, linestyle->id.lib, &mtex->tex); + BLO_read_id_address(reader, linestyle->id.lib, &mtex->object); + } + } +} + +static void linestyle_blend_read_expand(BlendExpander *expander, ID *id) +{ + FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; + + for (int a = 0; a < MAX_MTEX; a++) { + if (linestyle->mtex[a]) { + BLO_expand(expander, linestyle->mtex[a]->tex); + BLO_expand(expander, linestyle->mtex[a]->object); + } + } + + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) { + if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { + BLO_expand(expander, ((LineStyleColorModifier_DistanceFromObject *)m)->target); + } + } + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->alpha_modifiers) { + if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { + BLO_expand(expander, ((LineStyleAlphaModifier_DistanceFromObject *)m)->target); + } + } + LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->thickness_modifiers) { + if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { + BLO_expand(expander, ((LineStyleThicknessModifier_DistanceFromObject *)m)->target); + } + } +} + IDTypeInfo IDType_ID_LS = { .id_code = ID_LS, .id_filter = FILTER_ID_LS, @@ -206,10 +761,10 @@ IDTypeInfo IDType_ID_LS = { .foreach_id = linestyle_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = linestyle_blend_write, + .blend_read_data = linestyle_blend_read_data, + .blend_read_lib = linestyle_blend_read_lib, + .blend_read_expand = linestyle_blend_read_expand, }; static const char *modifier_name[LS_MODIFIER_NUM] = { diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index 79b8a30242e..c8c4fea7ab1 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -28,6 +28,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_endian_switch.h" #include "BLI_ghash.h" #include "BLI_listbase.h" #include "BLI_math.h" @@ -43,6 +44,7 @@ #include "BKE_curve.h" #include "BKE_idtype.h" +#include "BKE_anim_data.h" #include "BKE_image.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" @@ -53,6 +55,8 @@ #include "DEG_depsgraph_build.h" +#include "BLO_read_write.h" + static CLG_LogRef LOG = {"bke.mask"}; static void mask_copy_data(Main *UNUSED(bmain), @@ -94,6 +98,155 @@ static void mask_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void mask_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Mask *mask = (Mask *)id; + if (mask->id.us > 0 || BLO_write_is_undo(writer)) { + MaskLayer *masklay; + + BLO_write_id_struct(writer, Mask, id_address, &mask->id); + BKE_id_blend_write(writer, &mask->id); + + if (mask->adt) { + BKE_animdata_blend_write(writer, mask->adt); + } + + for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { + MaskSpline *spline; + MaskLayerShape *masklay_shape; + + BLO_write_struct(writer, MaskLayer, masklay); + + for (spline = masklay->splines.first; spline; spline = spline->next) { + int i; + + void *points_deform = spline->points_deform; + spline->points_deform = NULL; + + BLO_write_struct(writer, MaskSpline, spline); + BLO_write_struct_array(writer, MaskSplinePoint, spline->tot_point, spline->points); + + spline->points_deform = points_deform; + + for (i = 0; i < spline->tot_point; i++) { + MaskSplinePoint *point = &spline->points[i]; + + if (point->tot_uw) { + BLO_write_struct_array(writer, MaskSplinePointUW, point->tot_uw, point->uw); + } + } + } + + for (masklay_shape = masklay->splines_shapes.first; masklay_shape; + masklay_shape = masklay_shape->next) { + BLO_write_struct(writer, MaskLayerShape, masklay_shape); + BLO_write_float_array( + writer, masklay_shape->tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE, masklay_shape->data); + } + } + } +} + +static void mask_blend_read_data(BlendDataReader *reader, ID *id) +{ + Mask *mask = (Mask *)id; + BLO_read_data_address(reader, &mask->adt); + + BLO_read_list(reader, &mask->masklayers); + + LISTBASE_FOREACH (MaskLayer *, masklay, &mask->masklayers) { + /* can't use newdataadr since it's a pointer within an array */ + MaskSplinePoint *act_point_search = NULL; + + BLO_read_list(reader, &masklay->splines); + + LISTBASE_FOREACH (MaskSpline *, spline, &masklay->splines) { + MaskSplinePoint *points_old = spline->points; + + BLO_read_data_address(reader, &spline->points); + + for (int i = 0; i < spline->tot_point; i++) { + MaskSplinePoint *point = &spline->points[i]; + + if (point->tot_uw) { + BLO_read_data_address(reader, &point->uw); + } + } + + /* detect active point */ + if ((act_point_search == NULL) && (masklay->act_point >= points_old) && + (masklay->act_point < points_old + spline->tot_point)) { + act_point_search = &spline->points[masklay->act_point - points_old]; + } + } + + BLO_read_list(reader, &masklay->splines_shapes); + + LISTBASE_FOREACH (MaskLayerShape *, masklay_shape, &masklay->splines_shapes) { + BLO_read_data_address(reader, &masklay_shape->data); + + if (masklay_shape->tot_vert) { + if (BLO_read_requires_endian_switch(reader)) { + BLI_endian_switch_float_array(masklay_shape->data, + masklay_shape->tot_vert * sizeof(float) * + MASK_OBJECT_SHAPE_ELEM_SIZE); + } + } + } + + BLO_read_data_address(reader, &masklay->act_spline); + masklay->act_point = act_point_search; + } +} + +static void lib_link_mask_parent(BlendLibReader *reader, Mask *mask, MaskParent *parent) +{ + BLO_read_id_address(reader, mask->id.lib, &parent->id); +} + +static void mask_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Mask *mask = (Mask *)id; + LISTBASE_FOREACH (MaskLayer *, masklay, &mask->masklayers) { + MaskSpline *spline; + + spline = masklay->splines.first; + while (spline) { + for (int i = 0; i < spline->tot_point; i++) { + MaskSplinePoint *point = &spline->points[i]; + + lib_link_mask_parent(reader, mask, &point->parent); + } + + lib_link_mask_parent(reader, mask, &spline->parent); + + spline = spline->next; + } + } +} + +static void expand_mask_parent(BlendExpander *expander, MaskParent *parent) +{ + if (parent->id) { + BLO_expand(expander, parent->id); + } +} + +static void mask_blend_read_expand(BlendExpander *expander, ID *id) +{ + Mask *mask = (Mask *)id; + LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) { + LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { + for (int i = 0; i < spline->tot_point; i++) { + MaskSplinePoint *point = &spline->points[i]; + expand_mask_parent(expander, &point->parent); + } + + expand_mask_parent(expander, &spline->parent); + } + } +} + IDTypeInfo IDType_ID_MSK = { .id_code = ID_MSK, .id_filter = FILTER_ID_MSK, @@ -111,10 +264,10 @@ IDTypeInfo IDType_ID_MSK = { .foreach_id = mask_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = mask_blend_write, + .blend_read_data = mask_blend_read_data, + .blend_read_lib = mask_blend_read_lib, + .blend_read_expand = mask_blend_read_expand, }; static struct { @@ -362,7 +515,6 @@ void BKE_mask_point_direction_switch(MaskSplinePoint *point) { const int tot_uw = point->tot_uw; const int tot_uw_half = tot_uw / 2; - int i; float co_tmp[2]; @@ -377,14 +529,14 @@ void BKE_mask_point_direction_switch(MaskSplinePoint *point) /* swap UW's */ if (tot_uw > 1) { /* count */ - for (i = 0; i < tot_uw_half; i++) { + for (int i = 0; i < tot_uw_half; i++) { MaskSplinePointUW *uw_a = &point->uw[i]; MaskSplinePointUW *uw_b = &point->uw[tot_uw - (i + 1)]; SWAP(MaskSplinePointUW, *uw_a, *uw_b); } } - for (i = 0; i < tot_uw; i++) { + for (int i = 0; i < tot_uw; i++) { MaskSplinePointUW *uw = &point->uw[i]; uw->u = 1.0f - uw->u; } @@ -731,10 +883,8 @@ float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, const fl } float cur_u = 0.0f, cur_w = 0.0f, next_u = 0.0f, next_w = 0.0f, fac; /* Quite warnings */ - int i; - - for (i = 0; i <= point->tot_uw; i++) { + for (int i = 0; i <= point->tot_uw; i++) { if (i == 0) { cur_u = 0.0f; cur_w = 1.0f; /* mask_point_interp_weight will scale it */ @@ -815,8 +965,6 @@ void BKE_mask_point_add_uw(MaskSplinePoint *point, float u, float w) void BKE_mask_point_select_set(MaskSplinePoint *point, const bool do_select) { - int i; - if (do_select) { MASKPOINT_SEL_ALL(point); } @@ -824,7 +972,7 @@ void BKE_mask_point_select_set(MaskSplinePoint *point, const bool do_select) MASKPOINT_DESEL_ALL(point); } - for (i = 0; i < point->tot_uw; i++) { + for (int i = 0; i < point->tot_uw; i++) { if (do_select) { point->uw[i].flag |= SELECT; } @@ -979,12 +1127,9 @@ void BKE_mask_spline_free_list(ListBase *splines) static MaskSplinePoint *mask_spline_points_copy(const MaskSplinePoint *points, int tot_point) { - MaskSplinePoint *npoints; - int i; - - npoints = MEM_dupallocN(points); + MaskSplinePoint *npoints = MEM_dupallocN(points); - for (i = 0; i < tot_point; i++) { + for (int i = 0; i < tot_point; i++) { MaskSplinePoint *point = &npoints[i]; if (point->uw) { @@ -1435,8 +1580,7 @@ void BKE_mask_layer_calc_handles(MaskLayer *masklay) { MaskSpline *spline; for (spline = masklay->splines.first; spline; spline = spline->next) { - int i; - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { BKE_mask_calc_handle_point(spline, &spline->points[i]); } } @@ -1451,9 +1595,7 @@ void BKE_mask_spline_ensure_deform(MaskSpline *spline) // printf("alloc new deform spline\n"); if (spline->points_deform) { - int i; - - for (i = 0; i < allocated_points; i++) { + for (int i = 0; i < allocated_points; i++) { MaskSplinePoint *point = &spline->points_deform[i]; BKE_mask_point_free(point); } @@ -1538,8 +1680,7 @@ void BKE_mask_layer_shape_from_mask(MaskLayer *masklay, MaskLayerShape *masklay_ MaskSpline *spline; for (spline = masklay->splines.first; spline; spline = spline->next) { - int i; - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { mask_layer_shape_from_mask_point(&spline->points[i].bezt, fp); fp += MASK_OBJECT_SHAPE_ELEM_SIZE; } @@ -1563,8 +1704,7 @@ void BKE_mask_layer_shape_to_mask(MaskLayer *masklay, MaskLayerShape *masklay_sh MaskSpline *spline; for (spline = masklay->splines.first; spline; spline = spline->next) { - int i; - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { mask_layer_shape_to_mask_point(&spline->points[i].bezt, fp); fp += MASK_OBJECT_SHAPE_ELEM_SIZE; } @@ -1600,8 +1740,7 @@ void BKE_mask_layer_shape_to_mask_interp(MaskLayer *masklay, MaskSpline *spline; for (spline = masklay->splines.first; spline; spline = spline->next) { - int i; - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { BezTriple *bezt = &spline->points[i].bezt; /* *** BKE_mask_layer_shape_from_mask - swapped *** */ interp_v2_v2v2_flfl(bezt->vec[0], fp_a, fp_b, fac, ifac); @@ -1836,9 +1975,8 @@ void BKE_mask_layer_shape_changed_add(MaskLayer *masklay, const int pi_prev_abs = pi_prev + index_offset; const int pi_next_abs = pi_next + index_offset; - int i; if (do_init_interpolate) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { interp_weights_uv_v2_calc(uv[i], spline->points[pi_curr].bezt.vec[i], spline->points[pi_prev].bezt.vec[i], @@ -1873,7 +2011,7 @@ void BKE_mask_layer_shape_changed_add(MaskLayer *masklay, mask_layer_shape_from_mask_point(&spline->points[spline_point_index].bezt, fp); if (do_init_interpolate && spline->tot_point > 2) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { interp_weights_uv_v2_apply( uv[i], &fp[i * 2], @@ -1988,8 +2126,7 @@ void BKE_mask_clipboard_copy_from_layer(MaskLayer *mask_layer) for (spline = mask_layer->splines.first; spline; spline = spline->next) { if (spline->flag & SELECT) { MaskSpline *spline_new = BKE_mask_spline_copy(spline); - int i; - for (i = 0; i < spline_new->tot_point; i++) { + for (int i = 0; i < spline_new->tot_point; i++) { MaskSplinePoint *point = &spline_new->points[i]; if (point->parent.id) { if (!BLI_ghash_lookup(mask_clipboard.id_hash, point->parent.id)) { @@ -2019,9 +2156,8 @@ void BKE_mask_clipboard_paste_to_layer(Main *bmain, MaskLayer *mask_layer) for (spline = mask_clipboard.splines.first; spline; spline = spline->next) { MaskSpline *spline_new = BKE_mask_spline_copy(spline); - int i; - for (i = 0; i < spline_new->tot_point; i++) { + for (int i = 0; i < spline_new->tot_point; i++) { MaskSplinePoint *point = &spline_new->points[i]; if (point->parent.id) { const char *id_name = BLI_ghash_lookup(mask_clipboard.id_hash, point->parent.id); diff --git a/source/blender/blenkernel/intern/mask_evaluate.c b/source/blender/blenkernel/intern/mask_evaluate.c index 2fbf5f8648d..595fd0c9550 100644 --- a/source/blender/blenkernel/intern/mask_evaluate.c +++ b/source/blender/blenkernel/intern/mask_evaluate.c @@ -84,22 +84,19 @@ unsigned int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, i const float max_segment = 0.005; unsigned int resol = BKE_mask_spline_resolution(spline, width, height); float max_jump = 0.0f; - int i; /* avoid checking the featrher if we already hit the maximum value */ if (resol >= MASK_RESOL_MAX) { return MASK_RESOL_MAX; } - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; - float prev_u, prev_w; - int j; - prev_u = 0.0f; - prev_w = point->bezt.weight; + float prev_u = 0.0f; + float prev_w = point->bezt.weight; - for (j = 0; j < point->tot_uw; j++) { + for (int j = 0; j < point->tot_uw; j++) { const float w_diff = (point->uw[j].w - prev_w); const float u_diff = (point->uw[j].u - prev_u); @@ -239,12 +236,10 @@ static void feather_bucket_check_intersect(float (*feather_points)[2], int cur_a, int cur_b) { - int i; - const float *v1 = (float *)feather_points[cur_a]; const float *v2 = (float *)feather_points[cur_b]; - for (i = 0; i < bucket->tot_segment; i++) { + for (int i = 0; i < bucket->tot_segment; i++) { int check_a = bucket->segments[i][0]; int check_b = bucket->segments[i][1]; @@ -346,7 +341,6 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, FeatherEdgesBucket *buckets; - unsigned int i; float min[2], max[2]; float max_delta_x = -1.0f, max_delta_y = -1.0f, max_delta; @@ -361,7 +355,7 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, /* find min/max corners of mask to build buckets in that space */ INIT_MINMAX2(min, max); - for (i = 0; i < tot_feather_point; i++) { + for (uint i = 0; i < tot_feather_point; i++) { unsigned int next = i + 1; float delta; @@ -426,7 +420,7 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, /* fill in buckets' edges */ buckets = MEM_callocN(sizeof(FeatherEdgesBucket) * tot_bucket, "feather buckets"); - for (i = 0; i < tot_feather_point; i++) { + for (int i = 0; i < tot_feather_point; i++) { int start = i, end = i + 1; int start_bucket_index, end_bucket_index; @@ -462,7 +456,7 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, } /* check all edges for intersection with edges from their buckets */ - for (i = 0; i < tot_feather_point; i++) { + for (int i = 0; i < tot_feather_point; i++) { int cur_a = i, cur_b = i + 1; int start_bucket_index, end_bucket_index; @@ -499,7 +493,7 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline, } /* free buckets */ - for (i = 0; i < tot_bucket; i++) { + for (int i = 0; i < tot_bucket; i++) { if (buckets[i].segments) { MEM_freeN(buckets[i].segments); } @@ -803,11 +797,10 @@ float *BKE_mask_point_segment_feather_diff(MaskSpline *spline, { float *feather, *fp; unsigned int resol = BKE_mask_spline_feather_resolution(spline, width, height); - unsigned int i; feather = fp = MEM_callocN(2 * resol * sizeof(float), "mask point spline feather diff points"); - for (i = 0; i < resol; i++, fp += 2) { + for (uint i = 0; i < resol; i++, fp += 2) { float u = (float)(i % resol) / resol, weight; float co[2], n[2]; diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c index 92885535f57..583ee8f2857 100644 --- a/source/blender/blenkernel/intern/mask_rasterize.c +++ b/source/blender/blenkernel/intern/mask_rasterize.c @@ -226,10 +226,9 @@ MaskRasterHandle *BKE_maskrasterize_handle_new(void) void BKE_maskrasterize_handle_free(MaskRasterHandle *mr_handle) { const unsigned int layers_tot = mr_handle->layers_tot; - unsigned int i; MaskRasterLayer *layer = mr_handle->layers; - for (i = 0; i < layers_tot; i++, layer++) { + for (uint i = 0; i < layers_tot; i++, layer++) { if (layer->face_array) { MEM_freeN(layer->face_array); @@ -672,7 +671,6 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, if (width != height) { float *fp; float *ffp; - unsigned int i; float asp; if (width < height) { @@ -686,12 +684,12 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, asp = (float)height / (float)width; } - for (i = 0; i < tot_diff_point; i++, fp += 2) { + for (uint i = 0; i < tot_diff_point; i++, fp += 2) { (*fp) = (((*fp) - 0.5f) / asp) + 0.5f; } if (tot_diff_feather_points) { - for (i = 0; i < tot_diff_feather_points; i++, ffp += 2) { + for (uint i = 0; i < tot_diff_feather_points; i++, ffp += 2) { (*ffp) = (((*ffp) - 0.5f) / asp) + 0.5f; } } @@ -1353,13 +1351,12 @@ float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float x /* if (BLI_rctf_isect_pt_v(&mr_handle->bounds, xy)) */ const unsigned int layers_tot = mr_handle->layers_tot; - unsigned int i; MaskRasterLayer *layer = mr_handle->layers; /* return value */ float value = 0.0f; - for (i = 0; i < layers_tot; i++, layer++) { + for (uint i = 0; i < layers_tot; i++, layer++) { float value_layer; /* also used as signal for unused layer (when render is disabled) */ diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index d521d6c8a99..885cc1baefc 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -29,6 +29,9 @@ #include "MEM_guardedalloc.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_ID.h" #include "DNA_anim_types.h" #include "DNA_collection_types.h" @@ -54,6 +57,7 @@ #include "BLT_translation.h" +#include "BKE_anim_data.h" #include "BKE_brush.h" #include "BKE_curve.h" #include "BKE_displist.h" @@ -78,6 +82,8 @@ #include "NOD_shader.h" +#include "BLO_read_write.h" + static CLG_LogRef LOG = {"bke.material"}; static void material_init_data(ID *id) @@ -160,6 +166,82 @@ static void material_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void material_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Material *ma = (Material *)id; + if (ma->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + ma->texpaintslot = NULL; + BLI_listbase_clear(&ma->gpumaterial); + + /* write LibData */ + BLO_write_id_struct(writer, Material, id_address, &ma->id); + BKE_id_blend_write(writer, &ma->id); + + if (ma->adt) { + BKE_animdata_blend_write(writer, ma->adt); + } + + /* nodetree is integral part of material, no libdata */ + if (ma->nodetree) { + BLO_write_struct(writer, bNodeTree, ma->nodetree); + ntreeBlendWrite(writer, ma->nodetree); + } + + BKE_previewimg_blend_write(writer, ma->preview); + + /* grease pencil settings */ + if (ma->gp_style) { + BLO_write_struct(writer, MaterialGPencilStyle, ma->gp_style); + } + } +} + +static void material_blend_read_data(BlendDataReader *reader, ID *id) +{ + Material *ma = (Material *)id; + BLO_read_data_address(reader, &ma->adt); + BKE_animdata_blend_read_data(reader, ma->adt); + + ma->texpaintslot = NULL; + + BLO_read_data_address(reader, &ma->preview); + BKE_previewimg_blend_read(reader, ma->preview); + + BLI_listbase_clear(&ma->gpumaterial); + + BLO_read_data_address(reader, &ma->gp_style); +} + +static void material_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Material *ma = (Material *)id; + BLO_read_id_address(reader, ma->id.lib, &ma->ipo); // XXX deprecated - old animation system + + /* relink grease pencil settings */ + if (ma->gp_style != NULL) { + MaterialGPencilStyle *gp_style = ma->gp_style; + if (gp_style->sima != NULL) { + BLO_read_id_address(reader, ma->id.lib, &gp_style->sima); + } + if (gp_style->ima != NULL) { + BLO_read_id_address(reader, ma->id.lib, &gp_style->ima); + } + } +} + +static void material_blend_read_expand(BlendExpander *expander, ID *id) +{ + Material *ma = (Material *)id; + BLO_expand(expander, ma->ipo); // XXX deprecated - old animation system + + if (ma->gp_style) { + MaterialGPencilStyle *gp_style = ma->gp_style; + BLO_expand(expander, gp_style->sima); + BLO_expand(expander, gp_style->ima); + } +} + IDTypeInfo IDType_ID_MA = { .id_code = ID_MA, .id_filter = FILTER_ID_MA, @@ -177,10 +259,10 @@ IDTypeInfo IDType_ID_MA = { .foreach_id = material_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = material_blend_write, + .blend_read_data = material_blend_read_data, + .blend_read_lib = material_blend_read_lib, + .blend_read_expand = material_blend_read_expand, }; void BKE_gpencil_material_attr_init(Material *ma) @@ -1287,9 +1369,7 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma) void BKE_texpaint_slots_refresh_object(Scene *scene, struct Object *ob) { - int i; - - for (i = 1; i < ob->totcol + 1; i++) { + for (int i = 1; i < ob->totcol + 1; i++) { Material *ma = BKE_object_material_get(ob, i); BKE_texpaint_slot_refresh_cache(scene, ma); } diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index fe6f1bd4a97..d71c100ed87 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -35,6 +35,9 @@ #include "MEM_guardedalloc.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_defaults.h" #include "DNA_material_types.h" #include "DNA_meta_types.h" @@ -50,6 +53,7 @@ #include "BKE_main.h" +#include "BKE_anim_data.h" #include "BKE_curve.h" #include "BKE_displist.h" #include "BKE_idtype.h" @@ -62,6 +66,8 @@ #include "DEG_depsgraph.h" +#include "BLO_read_write.h" + static void metaball_init_data(ID *id) { MetaBall *metaball = (MetaBall *)id; @@ -110,6 +116,71 @@ static void metaball_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + MetaBall *mb = (MetaBall *)id; + if (mb->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + BLI_listbase_clear(&mb->disp); + mb->editelems = NULL; + /* Must always be cleared (meta's don't have their own edit-data). */ + mb->needs_flush_to_id = 0; + mb->lastelem = NULL; + mb->batch_cache = NULL; + + /* write LibData */ + BLO_write_id_struct(writer, MetaBall, id_address, &mb->id); + BKE_id_blend_write(writer, &mb->id); + + /* direct data */ + BLO_write_pointer_array(writer, mb->totcol, mb->mat); + if (mb->adt) { + BKE_animdata_blend_write(writer, mb->adt); + } + + LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) { + BLO_write_struct(writer, MetaElem, ml); + } + } +} + +static void metaball_blend_read_data(BlendDataReader *reader, ID *id) +{ + MetaBall *mb = (MetaBall *)id; + BLO_read_data_address(reader, &mb->adt); + BKE_animdata_blend_read_data(reader, mb->adt); + + BLO_read_pointer_array(reader, (void **)&mb->mat); + + BLO_read_list(reader, &(mb->elems)); + + BLI_listbase_clear(&mb->disp); + mb->editelems = NULL; + /* Must always be cleared (meta's don't have their own edit-data). */ + mb->needs_flush_to_id = 0; + /* mb->edit_elems.first= mb->edit_elems.last= NULL;*/ + mb->lastelem = NULL; + mb->batch_cache = NULL; +} + +static void metaball_blend_read_lib(BlendLibReader *reader, ID *id) +{ + MetaBall *mb = (MetaBall *)id; + for (int a = 0; a < mb->totcol; a++) { + BLO_read_id_address(reader, mb->id.lib, &mb->mat[a]); + } + + BLO_read_id_address(reader, mb->id.lib, &mb->ipo); // XXX deprecated - old animation system +} + +static void metaball_blend_read_expand(BlendExpander *expander, ID *id) +{ + MetaBall *mb = (MetaBall *)id; + for (int a = 0; a < mb->totcol; a++) { + BLO_expand(expander, mb->mat[a]); + } +} + IDTypeInfo IDType_ID_MB = { .id_code = ID_MB, .id_filter = FILTER_ID_MB, @@ -127,10 +198,10 @@ IDTypeInfo IDType_ID_MB = { .foreach_id = metaball_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = metaball_blend_write, + .blend_read_data = metaball_blend_read_data, + .blend_read_lib = metaball_blend_read_lib, + .blend_read_expand = metaball_blend_read_expand, }; /* Functions */ @@ -484,7 +555,6 @@ bool BKE_mball_minmax_ex( LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) { if ((ml->flag & flag) == flag) { const float scale_mb = (ml->rad * 0.5f) * scale; - int i; if (obmat) { mul_v3_m4v3(centroid, obmat, &ml->x); @@ -494,7 +564,7 @@ bool BKE_mball_minmax_ex( } /* TODO, non circle shapes cubes etc, probably nobody notices - campbell */ - for (i = -1; i != 3; i += 2) { + for (int i = -1; i != 3; i += 2) { copy_v3_v3(vec, centroid); add_v3_fl(vec, scale_mb * i); minmax_v3v3_v3(min, max, vec); diff --git a/source/blender/blenkernel/intern/mball_tessellate.c b/source/blender/blenkernel/intern/mball_tessellate.c index 2a7d3f1797d..7273d2a920d 100644 --- a/source/blender/blenkernel/intern/mball_tessellate.c +++ b/source/blender/blenkernel/intern/mball_tessellate.c @@ -410,7 +410,6 @@ static float densfunc(const MetaElem *ball, float x, float y, float z) */ static float metaball(PROCESS *process, float x, float y, float z) { - int i; float dens = 0.0f; unsigned int front = 0, back = 0; MetaballBVHNode *node; @@ -420,7 +419,7 @@ static float metaball(PROCESS *process, float x, float y, float z) while (front != back) { node = process->bvh_queue[back++]; - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { if ((node->bb[i].min[0] <= x) && (node->bb[i].max[0] >= x) && (node->bb[i].min[1] <= y) && (node->bb[i].max[1] >= y) && (node->bb[i].min[2] <= z) && (node->bb[i].max[2] >= z)) { if (node->child[i]) { @@ -833,18 +832,14 @@ static void makecubetable(void) void BKE_mball_cubeTable_free(void) { - int i; - INTLISTS *lists, *nlists; - INTLIST *ints, *nints; - - for (i = 0; i < 256; i++) { - lists = cubetable[i]; + for (int i = 0; i < 256; i++) { + INTLISTS *lists = cubetable[i]; while (lists) { - nlists = lists->next; + INTLISTS *nlists = lists->next; - ints = lists->list; + INTLIST *ints = lists->list; while (ints) { - nints = ints->next; + INTLIST *nints = ints->next; MEM_freeN(ints); ints = nints; } @@ -1014,8 +1009,6 @@ static int vertid(PROCESS *process, const CORNER *c1, const CORNER *c2) */ static void converge(PROCESS *process, const CORNER *c1, const CORNER *c2, float r_p[3]) { - float tmp, dens; - unsigned int i; float c1_value, c1_co[3]; float c2_value, c2_co[3]; @@ -1032,9 +1025,9 @@ static void converge(PROCESS *process, const CORNER *c1, const CORNER *c2, float copy_v3_v3(c2_co, c2->co); } - for (i = 0; i < process->converge_res; i++) { + for (uint i = 0; i < process->converge_res; i++) { interp_v3_v3v3(r_p, c1_co, c2_co, 0.5f); - dens = metaball(process, r_p[0], r_p[1], r_p[2]); + float dens = metaball(process, r_p[0], r_p[1], r_p[2]); if (dens > 0.0f) { c1_value = dens; @@ -1046,7 +1039,7 @@ static void converge(PROCESS *process, const CORNER *c1, const CORNER *c2, float } } - tmp = -c1_value / (c2_value - c1_value); + float tmp = -c1_value / (c2_value - c1_value); interp_v3_v3v3(r_p, c1_co, c2_co, tmp); } @@ -1154,7 +1147,6 @@ static void find_first_points(PROCESS *process, const unsigned int em) static void polygonize(PROCESS *process) { CUBE c; - unsigned int i; process->centers = MEM_callocN(HASHSIZE * sizeof(CENTERLIST *), "mbproc->centers"); process->corners = MEM_callocN(HASHSIZE * sizeof(CORNER *), "mbproc->corners"); @@ -1164,7 +1156,7 @@ static void polygonize(PROCESS *process) makecubetable(); - for (i = 0; i < process->totelem; i++) { + for (uint i = 0; i < process->totelem; i++) { find_first_points(process, i); } diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c index 9426d09885e..60a9ef2df55 100644 --- a/source/blender/blenkernel/intern/mesh_convert.c +++ b/source/blender/blenkernel/intern/mesh_convert.c @@ -400,9 +400,7 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, mpoly->mat_nr = dl->col; if (mloopuv) { - int i; - - for (i = 0; i < 3; i++, mloopuv++) { + for (int i = 0; i < 3; i++, mloopuv++) { mloopuv->uv[0] = (mloop[i].v - startvert) / (float)(dl->nr - 1); mloopuv->uv[1] = 0.0f; } @@ -464,7 +462,6 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, if (mloopuv) { int orco_sizeu = dl->nr - 1; int orco_sizev = dl->parts - 1; - int i; /* exception as handled in convertblender.c too */ if (dl->flag & DL_CYCL_U) { @@ -477,7 +474,7 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, orco_sizev++; } - for (i = 0; i < 4; i++, mloopuv++) { + for (int i = 0; i < 4; i++, mloopuv++) { /* find uv based on vertex index into grid array */ int v = mloop[i].v - startvert; diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c index fe4b8a60796..0c83820bce9 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.c +++ b/source/blender/blenkernel/intern/mesh_evaluate.c @@ -75,8 +75,7 @@ static CLG_LogRef LOG = {"bke.mesh_evaluate"}; */ static void mesh_calc_normals_vert_fallback(MVert *mverts, int numVerts) { - int i; - for (i = 0; i < numVerts; i++) { + for (int i = 0; i < numVerts; i++) { MVert *mv = &mverts[i]; float no[3]; @@ -149,9 +148,6 @@ void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, const bool only_face_normals) { float(*pnors)[3] = r_polyNors, (*fnors)[3] = r_faceNors; - int i; - const MFace *mf; - const MPoly *mp; if (numPolys == 0) { if (only_face_normals == false) { @@ -180,8 +176,8 @@ void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, } else { /* only calc poly normals */ - mp = mpolys; - for (i = 0; i < numPolys; i++, mp++) { + const MPoly *mp = mpolys; + for (int i = 0; i < numPolys; i++, mp++) { BKE_mesh_calc_poly_normal(mp, mloop + mp->loopstart, mverts, pnors[i]); } } @@ -190,8 +186,8 @@ void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, /* fnors == r_faceNors */ /* NO NEED TO ALLOC YET */ fnors != NULL && numFaces) { - mf = mfaces; - for (i = 0; i < numFaces; i++, mf++, origIndexFace++) { + const MFace *mf = mfaces; + for (int i = 0; i < numFaces; i++, mf++, origIndexFace++) { if (*origIndexFace < numPolys) { copy_v3_v3(fnors[i], pnors[*origIndexFace]); } @@ -244,7 +240,6 @@ static void mesh_calc_normals_poly_prepare_cb(void *__restrict userdata, const int nverts = mp->totloop; float(*edgevecbuf)[3] = BLI_array_alloca(edgevecbuf, (size_t)nverts); - int i; /* Polygon Normal and edge-vector */ /* inline version of #BKE_mesh_calc_poly_normal, also does edge-vectors */ @@ -255,7 +250,7 @@ static void mesh_calc_normals_poly_prepare_cb(void *__restrict userdata, zero_v3(pnor); /* Newell's Method */ - for (i = 0; i < nverts; i++) { + for (int i = 0; i < nverts; i++) { v_curr = mverts[ml[i].v].co; add_newell_cross_v3_v3v3(pnor, v_prev, v_curr); @@ -277,7 +272,7 @@ static void mesh_calc_normals_poly_prepare_cb(void *__restrict userdata, { const float *prev_edge = edgevecbuf[nverts - 1]; - for (i = 0; i < nverts; i++) { + for (int i = 0; i < nverts; i++) { const int lidx = mp->loopstart + i; const float *cur_edge = edgevecbuf[i]; @@ -475,13 +470,12 @@ void BKE_mesh_calc_normals_looptri(MVert *mverts, float(*fnors)[3] = (r_tri_nors) ? r_tri_nors : MEM_calloc_arrayN((size_t)looptri_num, sizeof(*fnors), "meshnormals"); - int i; if (!tnorms || !fnors) { goto cleanup; } - for (i = 0; i < looptri_num; i++) { + for (int i = 0; i < looptri_num; i++) { const MLoopTri *lt = &looptri[i]; float *f_no = fnors[i]; const unsigned int vtri[3] = { @@ -502,7 +496,7 @@ void BKE_mesh_calc_normals_looptri(MVert *mverts, } /* following Mesh convention; we use vertex coordinate itself for normal in this case */ - for (i = 0; i < numVerts; i++) { + for (int i = 0; i < numVerts; i++) { MVert *mv = &mverts[i]; float *no = tnorms[i]; @@ -1785,7 +1779,6 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, * and do not want to use angle to define smooth fans! */ const bool use_split_normals = true; const float split_angle = (float)M_PI; - int i; BLI_SMALLSTACK_DECLARE(clnors_data, short *); @@ -1808,14 +1801,14 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, /* Set all given zero vectors to their default value. */ if (use_vertices) { - for (i = 0; i < numVerts; i++) { + for (int i = 0; i < numVerts; i++) { if (is_zero_v3(r_custom_loopnors[i])) { normal_short_to_float_v3(r_custom_loopnors[i], mverts[i].no); } } } else { - for (i = 0; i < numLoops; i++) { + for (int i = 0; i < numLoops; i++) { if (is_zero_v3(r_custom_loopnors[i])) { copy_v3_v3(r_custom_loopnors[i], lnors[i]); } @@ -1832,7 +1825,7 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, * when we set custom normals per vertices, running this is absolutely useless. */ if (!use_vertices) { - for (i = 0; i < numLoops; i++) { + for (int i = 0; i < numLoops; i++) { if (!lnors_spacearr.lspacearr[i]) { /* This should not happen in theory, but in some rare case (probably ugly geometry) * we can get some NULL loopspacearr at this point. :/ @@ -1937,7 +1930,7 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, /* And we just have to convert plain object-space custom normals to our * lnor space-encoded ones. */ - for (i = 0; i < numLoops; i++) { + for (int i = 0; i < numLoops; i++) { if (!lnors_spacearr.lspacearr[i]) { BLI_BITMAP_DISABLE(done_loops, i); if (G.debug & G_DEBUG) { @@ -2131,13 +2124,12 @@ void BKE_mesh_normals_loop_to_vertex(const int numVerts, const float (*clnors)[3], float (*r_vert_clnors)[3]) { - const MLoop *ml; - int i; - int *vert_loops_nbr = MEM_calloc_arrayN((size_t)numVerts, sizeof(*vert_loops_nbr), __func__); copy_vn_fl((float *)r_vert_clnors, 3 * numVerts, 0.0f); + int i; + const MLoop *ml; for (i = 0, ml = mloops; i < numLoops; i++, ml++) { const unsigned int v = ml->v; @@ -2175,12 +2167,11 @@ static void mesh_calc_ngon_normal(const MPoly *mpoly, const int nverts = mpoly->totloop; const float *v_prev = mvert[loopstart[nverts - 1].v].co; const float *v_curr; - int i; zero_v3(normal); /* Newell's Method */ - for (i = 0; i < nverts; i++) { + for (int i = 0; i < nverts; i++) { v_curr = mvert[loopstart[i].v].co; add_newell_cross_v3_v3v3(normal, v_prev, v_curr); v_prev = v_curr; @@ -2225,12 +2216,11 @@ static void mesh_calc_ngon_normal_coords(const MPoly *mpoly, const int nverts = mpoly->totloop; const float *v_prev = vertex_coords[loopstart[nverts - 1].v]; const float *v_curr; - int i; zero_v3(r_normal); /* Newell's Method */ - for (i = 0; i < nverts; i++) { + for (int i = 0; i < nverts; i++) { v_curr = vertex_coords[loopstart[i].v]; add_newell_cross_v3_v3v3(r_normal, v_prev, v_curr); v_prev = v_curr; @@ -2275,11 +2265,10 @@ static void mesh_calc_ngon_center(const MPoly *mpoly, float cent[3]) { const float w = 1.0f / (float)mpoly->totloop; - int i; zero_v3(cent); - for (i = 0; i < mpoly->totloop; i++) { + for (int i = 0; i < mpoly->totloop; i++) { madd_v3_v3fl(cent, mvert[(loopstart++)->v].co, w); } } @@ -2315,18 +2304,16 @@ float BKE_mesh_calc_poly_area(const MPoly *mpoly, const MLoop *loopstart, const mvarray[loopstart[0].v].co, mvarray[loopstart[1].v].co, mvarray[loopstart[2].v].co); } - int i; const MLoop *l_iter = loopstart; - float area; float(*vertexcos)[3] = BLI_array_alloca(vertexcos, (size_t)mpoly->totloop); /* pack vertex cos into an array for area_poly_v3 */ - for (i = 0; i < mpoly->totloop; i++, l_iter++) { + for (int i = 0; i < mpoly->totloop; i++, l_iter++) { copy_v3_v3(vertexcos[i], mvarray[l_iter->v].co); } /* finally calculate the area */ - area = area_poly_v3((const float(*)[3])vertexcos, (unsigned int)mpoly->totloop); + float area = area_poly_v3((const float(*)[3])vertexcos, (unsigned int)mpoly->totloop); return area; } @@ -2462,8 +2449,6 @@ static float mesh_calc_poly_area_centroid(const MPoly *mpoly, const MVert *mvarray, float r_cent[3]) { - int i; - float tri_area; float total_area = 0.0f; float v1[3], v2[3], v3[3], normal[3], tri_cent[3]; @@ -2472,10 +2457,10 @@ static float mesh_calc_poly_area_centroid(const MPoly *mpoly, copy_v3_v3(v2, mvarray[loopstart[1].v].co); zero_v3(r_cent); - for (i = 2; i < mpoly->totloop; i++) { + for (int i = 2; i < mpoly->totloop; i++) { copy_v3_v3(v3, mvarray[loopstart[i].v].co); - tri_area = area_tri_signed_v3(v1, v2, v3, normal); + float tri_area = area_tri_signed_v3(v1, v2, v3, normal); total_area += tri_area; mid_v3_v3v3v3(tri_cent, v1, v2, v3); @@ -2693,9 +2678,6 @@ static bool mesh_calc_center_centroid_ex(const MVert *mverts, const MLoop *mloop, float r_center[3]) { - const MLoopTri *lt; - float totweight; - int i; zero_v3(r_center); @@ -2703,7 +2685,9 @@ static bool mesh_calc_center_centroid_ex(const MVert *mverts, return false; } - totweight = 0.0f; + float totweight = 0.0f; + const MLoopTri *lt; + int i; for (i = 0, lt = looptri; i < looptri_num; i++, lt++) { const MVert *v1 = &mverts[mloop[lt->tri[0]].v]; const MVert *v2 = &mverts[mloop[lt->tri[1]].v]; @@ -3444,19 +3428,12 @@ static void bm_corners_to_loops_ex(ID *id, int numTex, int numCol) { - MTFace *texface; - MCol *mcol; - MLoopCol *mloopcol; - MLoopUV *mloopuv; - MFace *mf; - int i; - - mf = mface + findex; + MFace *mf = mface + findex; - for (i = 0; i < numTex; i++) { - texface = CustomData_get_n(fdata, CD_MTFACE, findex, i); + for (int i = 0; i < numTex; i++) { + MTFace *texface = CustomData_get_n(fdata, CD_MTFACE, findex, i); - mloopuv = CustomData_get_n(ldata, CD_MLOOPUV, loopstart, i); + MLoopUV *mloopuv = CustomData_get_n(ldata, CD_MLOOPUV, loopstart, i); copy_v2_v2(mloopuv->uv, texface->uv[0]); mloopuv++; copy_v2_v2(mloopuv->uv, texface->uv[1]); @@ -3470,9 +3447,9 @@ static void bm_corners_to_loops_ex(ID *id, } } - for (i = 0; i < numCol; i++) { - mloopcol = CustomData_get_n(ldata, CD_MLOOPCOL, loopstart, i); - mcol = CustomData_get_n(fdata, CD_MCOL, findex, i); + for (int i = 0; i < numCol; i++) { + MLoopCol *mloopcol = CustomData_get_n(ldata, CD_MLOOPCOL, loopstart, i); + MCol *mcol = CustomData_get_n(fdata, CD_MCOL, findex, i); MESH_MLOOPCOL_FROM_MCOL(mloopcol, &mcol[0]); mloopcol++; @@ -3491,7 +3468,7 @@ static void bm_corners_to_loops_ex(ID *id, short(*tlnors)[3] = CustomData_get(fdata, findex, CD_TESSLOOPNORMAL); const int max = mf->v4 ? 4 : 3; - for (i = 0; i < max; i++, lnors++, tlnors++) { + for (int i = 0; i < max; i++, lnors++, tlnors++) { normal_short_to_float_v3(*lnors, *tlnors); } } @@ -3521,7 +3498,7 @@ static void bm_corners_to_loops_ex(ID *id, const int side = (int)sqrtf((float)(fd->totdisp / corners)); const int side_sq = side * side; - for (i = 0; i < tot; i++, disps += side_sq, ld++) { + for (int i = 0; i < tot; i++, disps += side_sq, ld++) { ld->totdisp = side_sq; ld->level = (int)(logf((float)side - 1.0f) / (float)M_LN2) + 1; @@ -3879,15 +3856,11 @@ void BKE_mesh_flush_hidden_from_polys_ex(MVert *mvert, const MPoly *mpoly, const int totpoly) { - const MPoly *mp; - int i; - - i = totpoly; - for (mp = mpoly; i--; mp++) { + int i = totpoly; + for (const MPoly *mp = mpoly; i--; mp++) { if (mp->flag & ME_HIDE) { const MLoop *ml; - int j; - j = mp->totloop; + int j = mp->totloop; for (ml = &mloop[mp->loopstart]; j--; ml++) { mvert[ml->v].flag |= ME_HIDE; medge[ml->e].flag |= ME_HIDE; @@ -3896,11 +3869,10 @@ void BKE_mesh_flush_hidden_from_polys_ex(MVert *mvert, } i = totpoly; - for (mp = mpoly; i--; mp++) { + for (const MPoly *mp = mpoly; i--; mp++) { if ((mp->flag & ME_HIDE) == 0) { const MLoop *ml; - int j; - j = mp->totloop; + int j = mp->totloop; for (ml = &mloop[mp->loopstart]; j--; ml++) { mvert[ml->v].flag &= (char)~ME_HIDE; medge[ml->e].flag &= (short)~ME_HIDE; @@ -3928,9 +3900,8 @@ void BKE_mesh_flush_select_from_polys_ex(MVert *mvert, MVert *mv; MEdge *med; const MPoly *mp; - int i; - i = totvert; + int i = totvert; for (mv = mvert; i--; mv++) { mv->flag &= (char)~SELECT; } @@ -3971,10 +3942,9 @@ void BKE_mesh_flush_select_from_verts_ex(const MVert *mvert, { MEdge *med; MPoly *mp; - int i; /* edges */ - i = totedge; + int i = totedge; for (med = medge; i--; med++) { if ((med->flag & ME_HIDE) == 0) { if ((mvert[med->v1].flag & SELECT) && (mvert[med->v2].flag & SELECT)) { @@ -4052,9 +4022,8 @@ void BKE_mesh_calc_relative_deform(const MPoly *mpoly, for (i = 0, mp = mpoly; i < totpoly; i++, mp++) { const MLoop *loopstart = mloop + mp->loopstart; - int j; - for (j = 0; j < mp->totloop; j++) { + for (int j = 0; j < mp->totloop; j++) { unsigned int v_prev = loopstart[(mp->totloop + (j - 1)) % mp->totloop].v; unsigned int v_curr = loopstart[j].v; unsigned int v_next = loopstart[(j + 1) % mp->totloop].v; diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index b70b1ff036b..3ea0f800178 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -35,6 +35,9 @@ #include "MEM_guardedalloc.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_constraint_types.h" #include "DNA_gpencil_types.h" #include "DNA_movieclip_types.h" @@ -54,6 +57,7 @@ #include "BLT_translation.h" +#include "BKE_anim_data.h" #include "BKE_colortools.h" #include "BKE_global.h" #include "BKE_idtype.h" @@ -74,6 +78,8 @@ #include "GPU_texture.h" +#include "BLO_read_write.h" + #ifdef WITH_OPENEXR # include "intern/openexr/openexr_multi.h" #endif @@ -146,6 +152,179 @@ static void movie_clip_foreach_cache(ID *id, function_callback(id, &key, (void **)&movie_clip->tracking.camera.intrinsics, 0, user_data); } +static void write_movieTracks(BlendWriter *writer, ListBase *tracks) +{ + MovieTrackingTrack *track; + + track = tracks->first; + while (track) { + BLO_write_struct(writer, MovieTrackingTrack, track); + + if (track->markers) { + BLO_write_struct_array(writer, MovieTrackingMarker, track->markersnr, track->markers); + } + + track = track->next; + } +} + +static void write_moviePlaneTracks(BlendWriter *writer, ListBase *plane_tracks_base) +{ + MovieTrackingPlaneTrack *plane_track; + + for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { + BLO_write_struct(writer, MovieTrackingPlaneTrack, plane_track); + + BLO_write_pointer_array(writer, plane_track->point_tracksnr, plane_track->point_tracks); + BLO_write_struct_array( + writer, MovieTrackingPlaneMarker, plane_track->markersnr, plane_track->markers); + } +} + +static void write_movieReconstruction(BlendWriter *writer, + MovieTrackingReconstruction *reconstruction) +{ + if (reconstruction->camnr) { + BLO_write_struct_array( + writer, MovieReconstructedCamera, reconstruction->camnr, reconstruction->cameras); + } +} + +static void movieclip_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + MovieClip *clip = (MovieClip *)id; + if (clip->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + clip->anim = NULL; + clip->tracking_context = NULL; + clip->tracking.stats = NULL; + + MovieTracking *tracking = &clip->tracking; + MovieTrackingObject *object; + + BLO_write_id_struct(writer, MovieClip, id_address, &clip->id); + BKE_id_blend_write(writer, &clip->id); + + if (clip->adt) { + BKE_animdata_blend_write(writer, clip->adt); + } + + write_movieTracks(writer, &tracking->tracks); + write_moviePlaneTracks(writer, &tracking->plane_tracks); + write_movieReconstruction(writer, &tracking->reconstruction); + + object = tracking->objects.first; + while (object) { + BLO_write_struct(writer, MovieTrackingObject, object); + + write_movieTracks(writer, &object->tracks); + write_moviePlaneTracks(writer, &object->plane_tracks); + write_movieReconstruction(writer, &object->reconstruction); + + object = object->next; + } + } +} + +static void direct_link_movieReconstruction(BlendDataReader *reader, + MovieTrackingReconstruction *reconstruction) +{ + BLO_read_data_address(reader, &reconstruction->cameras); +} + +static void direct_link_movieTracks(BlendDataReader *reader, ListBase *tracksbase) +{ + BLO_read_list(reader, tracksbase); + + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { + BLO_read_data_address(reader, &track->markers); + } +} + +static void direct_link_moviePlaneTracks(BlendDataReader *reader, ListBase *plane_tracks_base) +{ + BLO_read_list(reader, plane_tracks_base); + + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { + BLO_read_pointer_array(reader, (void **)&plane_track->point_tracks); + for (int i = 0; i < plane_track->point_tracksnr; i++) { + BLO_read_data_address(reader, &plane_track->point_tracks[i]); + } + + BLO_read_data_address(reader, &plane_track->markers); + } +} + +static void movieclip_blend_read_data(BlendDataReader *reader, ID *id) +{ + MovieClip *clip = (MovieClip *)id; + MovieTracking *tracking = &clip->tracking; + + BLO_read_data_address(reader, &clip->adt); + + direct_link_movieTracks(reader, &tracking->tracks); + direct_link_moviePlaneTracks(reader, &tracking->plane_tracks); + direct_link_movieReconstruction(reader, &tracking->reconstruction); + + BLO_read_data_address(reader, &clip->tracking.act_track); + BLO_read_data_address(reader, &clip->tracking.act_plane_track); + + clip->anim = NULL; + clip->tracking_context = NULL; + clip->tracking.stats = NULL; + + /* TODO we could store those in undo cache storage as well, and preserve them instead of + * re-creating them... */ + BLI_listbase_clear(&clip->runtime.gputextures); + + /* Needed for proper versioning, will be NULL for all newer files anyway. */ + BLO_read_data_address(reader, &clip->tracking.stabilization.rot_track); + + clip->tracking.dopesheet.ok = 0; + BLI_listbase_clear(&clip->tracking.dopesheet.channels); + BLI_listbase_clear(&clip->tracking.dopesheet.coverage_segments); + + BLO_read_list(reader, &tracking->objects); + + LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { + direct_link_movieTracks(reader, &object->tracks); + direct_link_moviePlaneTracks(reader, &object->plane_tracks); + direct_link_movieReconstruction(reader, &object->reconstruction); + } +} + +static void lib_link_movieTracks(BlendLibReader *reader, MovieClip *clip, ListBase *tracksbase) +{ + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { + BLO_read_id_address(reader, clip->id.lib, &track->gpd); + } +} + +static void lib_link_moviePlaneTracks(BlendLibReader *reader, + MovieClip *clip, + ListBase *tracksbase) +{ + LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, tracksbase) { + BLO_read_id_address(reader, clip->id.lib, &plane_track->image); + } +} + +static void movieclip_blend_read_lib(BlendLibReader *reader, ID *id) +{ + MovieClip *clip = (MovieClip *)id; + MovieTracking *tracking = &clip->tracking; + + BLO_read_id_address(reader, clip->id.lib, &clip->gpd); + + lib_link_movieTracks(reader, clip, &tracking->tracks); + lib_link_moviePlaneTracks(reader, clip, &tracking->plane_tracks); + + LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { + lib_link_movieTracks(reader, clip, &object->tracks); + lib_link_moviePlaneTracks(reader, clip, &object->plane_tracks); + } +} + IDTypeInfo IDType_ID_MC = { .id_code = ID_MC, .id_filter = FILTER_ID_MC, @@ -163,9 +342,9 @@ IDTypeInfo IDType_ID_MC = { .foreach_id = movie_clip_foreach_id, .foreach_cache = movie_clip_foreach_cache, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, + .blend_write = movieclip_blend_write, + .blend_read_data = movieclip_blend_read_data, + .blend_read_lib = movieclip_blend_read_lib, .blend_read_expand = NULL, }; diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 0c3abc70a43..b7d6c7a5a28 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -1284,12 +1284,11 @@ static void nlastrip_fix_resize_overlaps(NlaStrip *strip) nls->start = strip->end; } else { - /* shrink transition down to 1 frame long (so that it can still be found), - * then offset everything else by the remaining defict to give the strip room - */ + /* Shrink transition down to 1 frame long (so that it can still be found), + * then offset everything else by the remaining deficit to give the strip room. */ nls->start = nls->end - 1.0f; - /* XXX: review whether preventing fractionals is good here... */ + /* XXX: review whether preventing fractional values is good here... */ offset = ceilf(strip->end - nls->start); /* apply necessary offset to ensure that the strip has enough space */ @@ -1333,12 +1332,11 @@ static void nlastrip_fix_resize_overlaps(NlaStrip *strip) nls->end = strip->start; } else { - /* shrink transition down to 1 frame long (so that it can still be found), - * then offset everything else by the remaining defict to give the strip room - */ + /* Shrink transition down to 1 frame long (so that it can still be found), + * then offset everything else by the remaining deficit to give the strip room. */ nls->end = nls->start + 1.0f; - /* XXX: review whether preventing fractionals is good here... */ + /* XXX: review whether preventing fractional values is good here... */ offset = ceilf(nls->end - strip->start); /* apply necessary offset to ensure that the strip has enough space */ diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 900817a0513..1c7060541db 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -30,6 +30,9 @@ #include <stdlib.h> #include <string.h> +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_action_types.h" #include "DNA_anim_types.h" #include "DNA_gpencil_types.h" @@ -54,6 +57,7 @@ #include "BKE_anim_data.h" #include "BKE_animsys.h" +#include "BKE_colortools.h" #include "BKE_global.h" #include "BKE_idprop.h" #include "BKE_idtype.h" @@ -79,6 +83,8 @@ #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" +#include "BLO_read_write.h" + #define NODE_DEFAULT_MAX_WIDTH 700 /* Fallback types for undefined tree, nodes, sockets */ @@ -337,6 +343,511 @@ static void node_foreach_cache(ID *id, } } +static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *sock) +{ + if (sock->default_value == NULL) { + return; + } + + switch ((eNodeSocketDatatype)sock->type) { + case SOCK_FLOAT: + BLO_write_struct(writer, bNodeSocketValueFloat, sock->default_value); + break; + case SOCK_VECTOR: + BLO_write_struct(writer, bNodeSocketValueVector, sock->default_value); + break; + case SOCK_RGBA: + BLO_write_struct(writer, bNodeSocketValueRGBA, sock->default_value); + break; + case SOCK_BOOLEAN: + BLO_write_struct(writer, bNodeSocketValueBoolean, sock->default_value); + break; + case SOCK_INT: + BLO_write_struct(writer, bNodeSocketValueInt, sock->default_value); + break; + case SOCK_STRING: + BLO_write_struct(writer, bNodeSocketValueString, sock->default_value); + break; + case SOCK_OBJECT: + BLO_write_struct(writer, bNodeSocketValueObject, sock->default_value); + break; + case SOCK_IMAGE: + BLO_write_struct(writer, bNodeSocketValueImage, sock->default_value); + break; + case __SOCK_MESH: + case SOCK_CUSTOM: + case SOCK_SHADER: + case SOCK_EMITTERS: + case SOCK_EVENTS: + case SOCK_FORCES: + case SOCK_CONTROL_FLOW: + BLI_assert(false); + break; + } +} + +static void write_node_socket(BlendWriter *writer, bNodeSocket *sock) +{ + /* actual socket writing */ + BLO_write_struct(writer, bNodeSocket, sock); + + if (sock->prop) { + IDP_BlendWrite(writer, sock->prop); + } + + write_node_socket_default_value(writer, sock); +} +static void write_node_socket_interface(BlendWriter *writer, bNodeSocket *sock) +{ + /* actual socket writing */ + BLO_write_struct(writer, bNodeSocket, sock); + + if (sock->prop) { + IDP_BlendWrite(writer, sock->prop); + } + + write_node_socket_default_value(writer, sock); +} + +/* this is only direct data, tree itself should have been written */ +void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) +{ + /* for link_list() speed, we write per list */ + + if (ntree->adt) { + BKE_animdata_blend_write(writer, ntree->adt); + } + + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + BLO_write_struct(writer, bNode, node); + + if (node->prop) { + IDP_BlendWrite(writer, node->prop); + } + + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { + write_node_socket(writer, sock); + } + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { + write_node_socket(writer, sock); + } + + LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) { + BLO_write_struct(writer, bNodeLink, link); + } + + if (node->storage) { + /* could be handlerized at some point, now only 1 exception still */ + if ((ntree->type == NTREE_SHADER) && + ELEM(node->type, SH_NODE_CURVE_VEC, SH_NODE_CURVE_RGB)) { + BKE_curvemapping_blend_write(writer, node->storage); + } + else if (ntree->type == NTREE_SHADER && (node->type == SH_NODE_SCRIPT)) { + NodeShaderScript *nss = (NodeShaderScript *)node->storage; + if (nss->bytecode) { + BLO_write_string(writer, nss->bytecode); + } + BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); + } + else if ((ntree->type == NTREE_COMPOSIT) && ELEM(node->type, + CMP_NODE_TIME, + CMP_NODE_CURVE_VEC, + CMP_NODE_CURVE_RGB, + CMP_NODE_HUECORRECT)) { + BKE_curvemapping_blend_write(writer, node->storage); + } + else if ((ntree->type == NTREE_TEXTURE) && + (node->type == TEX_NODE_CURVE_RGB || node->type == TEX_NODE_CURVE_TIME)) { + BKE_curvemapping_blend_write(writer, node->storage); + } + else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_MOVIEDISTORTION)) { + /* pass */ + } + else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_GLARE)) { + /* Simple forward compatibility for fix for T50736. + * Not ideal (there is no ideal solution here), but should do for now. */ + NodeGlare *ndg = node->storage; + /* Not in undo case. */ + if (!BLO_write_is_undo(writer)) { + switch (ndg->type) { + case 2: /* Grrrr! magic numbers :( */ + ndg->angle = ndg->streaks; + break; + case 0: + ndg->angle = ndg->star_45; + break; + default: + break; + } + } + BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); + } + else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_CRYPTOMATTE)) { + NodeCryptomatte *nc = (NodeCryptomatte *)node->storage; + if (nc->matte_id) { + BLO_write_string(writer, nc->matte_id); + } + BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); + } + else if (node->typeinfo != &NodeTypeUndefined) { + BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); + } + } + + if (node->type == CMP_NODE_OUTPUT_FILE) { + /* inputs have own storage data */ + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { + BLO_write_struct(writer, NodeImageMultiFileSocket, sock->storage); + } + } + if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS)) { + /* write extra socket info */ + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { + BLO_write_struct(writer, NodeImageLayer, sock->storage); + } + } + } + + LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { + BLO_write_struct(writer, bNodeLink, link); + } + + LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) { + write_node_socket_interface(writer, sock); + } + LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) { + write_node_socket_interface(writer, sock); + } +} + +static void ntree_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + bNodeTree *ntree = (bNodeTree *)id; + if (ntree->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + ntree->init = 0; /* to set callbacks and force setting types */ + ntree->is_updating = false; + ntree->typeinfo = NULL; + ntree->interface_type = NULL; + ntree->progress = NULL; + ntree->execdata = NULL; + + BLO_write_id_struct(writer, bNodeTree, id_address, &ntree->id); + /* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot + * be linked, etc., so we write actual id data here only, for 'real' ID trees. */ + BKE_id_blend_write(writer, &ntree->id); + + ntreeBlendWrite(writer, ntree); + } +} + +static void direct_link_node_socket(BlendDataReader *reader, bNodeSocket *sock) +{ + BLO_read_data_address(reader, &sock->prop); + IDP_BlendDataRead(reader, &sock->prop); + + BLO_read_data_address(reader, &sock->link); + sock->typeinfo = NULL; + BLO_read_data_address(reader, &sock->storage); + BLO_read_data_address(reader, &sock->default_value); + sock->cache = NULL; +} + +/* ntree itself has been read! */ +void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree) +{ + /* note: writing and reading goes in sync, for speed */ + ntree->init = 0; /* to set callbacks and force setting types */ + ntree->is_updating = false; + ntree->typeinfo = NULL; + ntree->interface_type = NULL; + + ntree->progress = NULL; + ntree->execdata = NULL; + + BLO_read_data_address(reader, &ntree->adt); + BKE_animdata_blend_read_data(reader, ntree->adt); + + BLO_read_list(reader, &ntree->nodes); + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + node->typeinfo = NULL; + + BLO_read_list(reader, &node->inputs); + BLO_read_list(reader, &node->outputs); + + BLO_read_data_address(reader, &node->prop); + IDP_BlendDataRead(reader, &node->prop); + + BLO_read_list(reader, &node->internal_links); + LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) { + BLO_read_data_address(reader, &link->fromnode); + BLO_read_data_address(reader, &link->fromsock); + BLO_read_data_address(reader, &link->tonode); + BLO_read_data_address(reader, &link->tosock); + } + + if (node->type == CMP_NODE_MOVIEDISTORTION) { + /* Do nothing, this is runtime cache and hence handled by generic code using + * `IDTypeInfo.foreach_cache` callback. */ + } + else { + BLO_read_data_address(reader, &node->storage); + } + + if (node->storage) { + /* could be handlerized at some point */ + switch (node->type) { + case SH_NODE_CURVE_VEC: + case SH_NODE_CURVE_RGB: + case CMP_NODE_TIME: + case CMP_NODE_CURVE_VEC: + case CMP_NODE_CURVE_RGB: + case CMP_NODE_HUECORRECT: + case TEX_NODE_CURVE_RGB: + case TEX_NODE_CURVE_TIME: { + BKE_curvemapping_blend_read(reader, node->storage); + break; + } + case SH_NODE_SCRIPT: { + NodeShaderScript *nss = (NodeShaderScript *)node->storage; + BLO_read_data_address(reader, &nss->bytecode); + break; + } + case SH_NODE_TEX_POINTDENSITY: { + NodeShaderTexPointDensity *npd = (NodeShaderTexPointDensity *)node->storage; + memset(&npd->pd, 0, sizeof(npd->pd)); + break; + } + case SH_NODE_TEX_IMAGE: { + NodeTexImage *tex = (NodeTexImage *)node->storage; + tex->iuser.ok = 1; + tex->iuser.scene = NULL; + break; + } + case SH_NODE_TEX_ENVIRONMENT: { + NodeTexEnvironment *tex = (NodeTexEnvironment *)node->storage; + tex->iuser.ok = 1; + tex->iuser.scene = NULL; + break; + } + case CMP_NODE_IMAGE: + case CMP_NODE_R_LAYERS: + case CMP_NODE_VIEWER: + case CMP_NODE_SPLITVIEWER: { + ImageUser *iuser = node->storage; + iuser->ok = 1; + iuser->scene = NULL; + break; + } + case CMP_NODE_CRYPTOMATTE: { + NodeCryptomatte *nc = (NodeCryptomatte *)node->storage; + BLO_read_data_address(reader, &nc->matte_id); + break; + } + case TEX_NODE_IMAGE: { + ImageUser *iuser = node->storage; + iuser->ok = 1; + iuser->scene = NULL; + break; + } + default: + break; + } + } + } + BLO_read_list(reader, &ntree->links); + + /* and we connect the rest */ + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + BLO_read_data_address(reader, &node->parent); + node->lasty = 0; + + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { + direct_link_node_socket(reader, sock); + } + LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { + direct_link_node_socket(reader, sock); + } + } + + /* interface socket lists */ + BLO_read_list(reader, &ntree->inputs); + BLO_read_list(reader, &ntree->outputs); + LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) { + direct_link_node_socket(reader, sock); + } + LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) { + direct_link_node_socket(reader, sock); + } + + LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { + BLO_read_data_address(reader, &link->fromnode); + BLO_read_data_address(reader, &link->tonode); + BLO_read_data_address(reader, &link->fromsock); + BLO_read_data_address(reader, &link->tosock); + } + + /* TODO, should be dealt by new generic cache handling of IDs... */ + ntree->previews = NULL; + + /* type verification is in lib-link */ +} + +static void ntree_blend_read_data(BlendDataReader *reader, ID *id) +{ + bNodeTree *ntree = (bNodeTree *)id; + ntreeBlendReadData(reader, ntree); +} + +static void lib_link_node_socket(BlendLibReader *reader, Library *lib, bNodeSocket *sock) +{ + IDP_BlendReadLib(reader, sock->prop); + + switch ((eNodeSocketDatatype)sock->type) { + case SOCK_OBJECT: { + bNodeSocketValueObject *default_value = sock->default_value; + BLO_read_id_address(reader, lib, &default_value->value); + break; + } + case SOCK_IMAGE: { + bNodeSocketValueImage *default_value = sock->default_value; + BLO_read_id_address(reader, lib, &default_value->value); + break; + } + case SOCK_FLOAT: + case SOCK_VECTOR: + case SOCK_RGBA: + case SOCK_BOOLEAN: + case SOCK_INT: + case SOCK_STRING: + case __SOCK_MESH: + case SOCK_CUSTOM: + case SOCK_SHADER: + case SOCK_EMITTERS: + case SOCK_EVENTS: + case SOCK_FORCES: + case SOCK_CONTROL_FLOW: + break; + } +} + +static void lib_link_node_sockets(BlendLibReader *reader, Library *lib, ListBase *sockets) +{ + LISTBASE_FOREACH (bNodeSocket *, sock, sockets) { + lib_link_node_socket(reader, lib, sock); + } +} + +void ntreeBlendReadLib(struct BlendLibReader *reader, struct bNodeTree *ntree) +{ + Library *lib = ntree->id.lib; + + BLO_read_id_address(reader, lib, &ntree->gpd); + + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + /* Link ID Properties -- and copy this comment EXACTLY for easy finding + * of library blocks that implement this.*/ + IDP_BlendReadLib(reader, node->prop); + + BLO_read_id_address(reader, lib, &node->id); + + lib_link_node_sockets(reader, lib, &node->inputs); + lib_link_node_sockets(reader, lib, &node->outputs); + } + + lib_link_node_sockets(reader, lib, &ntree->inputs); + lib_link_node_sockets(reader, lib, &ntree->outputs); + + /* Set node->typeinfo pointers. This is done in lib linking, after the + * first versioning that can change types still without functions that + * update the typeinfo pointers. Versioning after lib linking needs + * these top be valid. */ + ntreeSetTypes(NULL, ntree); + + /* For nodes with static socket layout, add/remove sockets as needed + * to match the static layout. */ + if (!BLO_read_lib_is_undo(reader)) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + node_verify_socket_templates(ntree, node); + } + } +} + +static void ntree_blend_read_lib(BlendLibReader *reader, ID *id) +{ + bNodeTree *ntree = (bNodeTree *)id; + ntreeBlendReadLib(reader, ntree); +} + +static void expand_node_socket(BlendExpander *expander, bNodeSocket *sock) +{ + IDP_BlendReadExpand(expander, sock->prop); + + if (sock->default_value != NULL) { + + switch ((eNodeSocketDatatype)sock->type) { + case SOCK_OBJECT: { + bNodeSocketValueObject *default_value = sock->default_value; + BLO_expand(expander, default_value->value); + break; + } + case SOCK_IMAGE: { + bNodeSocketValueImage *default_value = sock->default_value; + BLO_expand(expander, default_value->value); + break; + } + case SOCK_FLOAT: + case SOCK_VECTOR: + case SOCK_RGBA: + case SOCK_BOOLEAN: + case SOCK_INT: + case SOCK_STRING: + case __SOCK_MESH: + case SOCK_CUSTOM: + case SOCK_SHADER: + case SOCK_EMITTERS: + case SOCK_EVENTS: + case SOCK_FORCES: + case SOCK_CONTROL_FLOW: + break; + } + } +} + +static void expand_node_sockets(BlendExpander *expander, ListBase *sockets) +{ + LISTBASE_FOREACH (bNodeSocket *, sock, sockets) { + expand_node_socket(expander, sock); + } +} + +void ntreeBlendReadExpand(BlendExpander *expander, bNodeTree *ntree) +{ + if (ntree->gpd) { + BLO_expand(expander, ntree->gpd); + } + + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + if (node->id && node->type != CMP_NODE_R_LAYERS) { + BLO_expand(expander, node->id); + } + + IDP_BlendReadExpand(expander, node->prop); + + expand_node_sockets(expander, &node->inputs); + expand_node_sockets(expander, &node->outputs); + } + + expand_node_sockets(expander, &ntree->inputs); + expand_node_sockets(expander, &ntree->outputs); +} + +static void ntree_blend_read_expand(BlendExpander *expander, ID *id) +{ + bNodeTree *ntree = (bNodeTree *)id; + ntreeBlendReadExpand(expander, ntree); +} + IDTypeInfo IDType_ID_NT = { .id_code = ID_NT, .id_filter = FILTER_ID_NT, @@ -354,10 +865,10 @@ IDTypeInfo IDType_ID_NT = { .foreach_id = node_foreach_id, .foreach_cache = node_foreach_cache, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = ntree_blend_write, + .blend_read_data = ntree_blend_read_data, + .blend_read_lib = ntree_blend_read_lib, + .blend_read_expand = ntree_blend_read_expand, }; static void node_add_sockets_from_type(bNodeTree *ntree, bNode *node, bNodeType *ntype) diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index 6793f5e1169..ac3686a021b 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -51,6 +51,8 @@ #include "BKE_sound.h" #include "BKE_volume.h" +#include "BLO_read_write.h" + int BKE_packedfile_seek(PackedFile *pf, int offset, int whence) { int oldseek = -1, seek = 0; @@ -852,3 +854,29 @@ void BKE_packedfile_id_unpack(Main *bmain, ID *id, ReportList *reports, enum ePF break; } } + +void BKE_packedfile_blend_write(BlendWriter *writer, PackedFile *pf) +{ + if (pf == NULL) { + return; + } + BLO_write_struct(writer, PackedFile, pf); + BLO_write_raw(writer, pf->size, pf->data); +} + +void BKE_packedfile_blend_read(BlendDataReader *reader, PackedFile **pf_p) +{ + BLO_read_packed_address(reader, pf_p); + PackedFile *pf = *pf_p; + if (pf == NULL) { + return; + } + + BLO_read_packed_address(reader, &pf->data); + if (pf->data == NULL) { + /* We cannot allow a PackedFile with a NULL data field, + * the whole code assumes this is not possible. See T70315. */ + printf("%s: NULL packedfile data, cleaning up...\n", __func__); + MEM_SAFE_FREE(pf); + } +} diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index bc089d7bd80..545d1bdee13 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -72,6 +72,8 @@ #include "RNA_enum_types.h" +#include "BLO_read_write.h" + #include "bmesh.h" static void palette_init_data(ID *id) @@ -102,6 +104,26 @@ static void palette_free_data(ID *id) BLI_freelistN(&palette->colors); } +static void palette_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Palette *palette = (Palette *)id; + if (palette->id.us > 0 || BLO_write_is_undo(writer)) { + PaletteColor *color; + BLO_write_id_struct(writer, Palette, id_address, &palette->id); + BKE_id_blend_write(writer, &palette->id); + + for (color = palette->colors.first; color; color = color->next) { + BLO_write_struct(writer, PaletteColor, color); + } + } +} + +static void palette_blend_read_data(BlendDataReader *reader, ID *id) +{ + Palette *palette = (Palette *)id; + BLO_read_list(reader, &palette->colors); +} + IDTypeInfo IDType_ID_PAL = { .id_code = ID_PAL, .id_filter = FILTER_ID_PAL, @@ -119,8 +141,8 @@ IDTypeInfo IDType_ID_PAL = { .foreach_id = NULL, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, + .blend_write = palette_blend_write, + .blend_read_data = palette_blend_read_data, .blend_read_lib = NULL, .blend_read_expand = NULL, }; @@ -146,6 +168,23 @@ static void paint_curve_free_data(ID *id) paint_curve->tot_points = 0; } +static void paint_curve_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + PaintCurve *pc = (PaintCurve *)id; + if (pc->id.us > 0 || BLO_write_is_undo(writer)) { + BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id); + BKE_id_blend_write(writer, &pc->id); + + BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points); + } +} + +static void paint_curve_blend_read_data(BlendDataReader *reader, ID *id) +{ + PaintCurve *pc = (PaintCurve *)id; + BLO_read_data_address(reader, &pc->points); +} + IDTypeInfo IDType_ID_PC = { .id_code = ID_PC, .id_filter = FILTER_ID_PC, @@ -163,8 +202,8 @@ IDTypeInfo IDType_ID_PC = { .foreach_id = NULL, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, + .blend_write = paint_curve_blend_write, + .blend_read_data = paint_curve_blend_read_data, .blend_read_lib = NULL, .blend_read_expand = NULL, }; @@ -406,7 +445,7 @@ Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer) case OB_MODE_WEIGHT_GPENCIL: return &ts->gp_weightpaint->paint; case OB_MODE_EDIT: - return &ts->uvsculpt->paint; + return ts->uvsculpt ? &ts->uvsculpt->paint : NULL; default: break; } diff --git a/source/blender/blenkernel/intern/pointcloud.c b/source/blender/blenkernel/intern/pointcloud.c index fb10c9f03e3..6ec305a971c 100644 --- a/source/blender/blenkernel/intern/pointcloud.c +++ b/source/blender/blenkernel/intern/pointcloud.c @@ -47,10 +47,15 @@ #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + /* PointCloud datablock */ static void pointcloud_random(PointCloud *pointcloud); +static const char *POINTCLOUD_ATTR_POSITION = "Position"; +static const char *POINTCLOUD_ATTR_RADIUS = "Radius"; + static void pointcloud_init_data(ID *id) { PointCloud *pointcloud = (PointCloud *)id; @@ -59,8 +64,18 @@ static void pointcloud_init_data(ID *id) MEMCPY_STRUCT_AFTER(pointcloud, DNA_struct_default_get(PointCloud), id); CustomData_reset(&pointcloud->pdata); - CustomData_add_layer(&pointcloud->pdata, CD_LOCATION, CD_CALLOC, NULL, pointcloud->totpoint); - CustomData_add_layer(&pointcloud->pdata, CD_RADIUS, CD_CALLOC, NULL, pointcloud->totpoint); + CustomData_add_layer_named(&pointcloud->pdata, + CD_PROP_FLOAT3, + CD_CALLOC, + NULL, + pointcloud->totpoint, + POINTCLOUD_ATTR_POSITION); + CustomData_add_layer_named(&pointcloud->pdata, + CD_PROP_FLOAT, + CD_CALLOC, + NULL, + pointcloud->totpoint, + POINTCLOUD_ATTR_RADIUS); BKE_pointcloud_update_customdata_pointers(pointcloud); pointcloud_random(pointcloud); @@ -98,6 +113,64 @@ static void pointcloud_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void pointcloud_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + PointCloud *pointcloud = (PointCloud *)id; + if (pointcloud->id.us > 0 || BLO_write_is_undo(writer)) { + CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; + CustomData_blend_write_prepare( + &pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); + + /* Write LibData */ + BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id); + BKE_id_blend_write(writer, &pointcloud->id); + + /* Direct data */ + CustomData_blend_write( + writer, &pointcloud->pdata, players, pointcloud->totpoint, CD_MASK_ALL, &pointcloud->id); + + BLO_write_pointer_array(writer, pointcloud->totcol, pointcloud->mat); + if (pointcloud->adt) { + BKE_animdata_blend_write(writer, pointcloud->adt); + } + + /* Remove temporary data. */ + if (players && players != players_buff) { + MEM_freeN(players); + } + } +} + +static void pointcloud_blend_read_data(BlendDataReader *reader, ID *id) +{ + PointCloud *pointcloud = (PointCloud *)id; + BLO_read_data_address(reader, &pointcloud->adt); + BKE_animdata_blend_read_data(reader, pointcloud->adt); + + /* Geometry */ + CustomData_blend_read(reader, &pointcloud->pdata, pointcloud->totpoint); + BKE_pointcloud_update_customdata_pointers(pointcloud); + + /* Materials */ + BLO_read_pointer_array(reader, (void **)&pointcloud->mat); +} + +static void pointcloud_blend_read_lib(BlendLibReader *reader, ID *id) +{ + PointCloud *pointcloud = (PointCloud *)id; + for (int a = 0; a < pointcloud->totcol; a++) { + BLO_read_id_address(reader, pointcloud->id.lib, &pointcloud->mat[a]); + } +} + +static void pointcloud_blend_read_expand(BlendExpander *expander, ID *id) +{ + PointCloud *pointcloud = (PointCloud *)id; + for (int a = 0; a < pointcloud->totcol; a++) { + BLO_expand(expander, pointcloud->mat[a]); + } +} + IDTypeInfo IDType_ID_PT = { .id_code = ID_PT, .id_filter = FILTER_ID_PT, @@ -115,10 +188,10 @@ IDTypeInfo IDType_ID_PT = { .foreach_id = pointcloud_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = pointcloud_blend_write, + .blend_read_data = pointcloud_blend_read_data, + .blend_read_lib = pointcloud_blend_read_lib, + .blend_read_expand = pointcloud_blend_read_expand, }; static void pointcloud_random(PointCloud *pointcloud) @@ -189,8 +262,15 @@ BoundBox *BKE_pointcloud_boundbox_get(Object *ob) void BKE_pointcloud_update_customdata_pointers(PointCloud *pointcloud) { - pointcloud->co = CustomData_get_layer(&pointcloud->pdata, CD_LOCATION); - pointcloud->radius = CustomData_get_layer(&pointcloud->pdata, CD_RADIUS); + pointcloud->co = CustomData_get_layer_named( + &pointcloud->pdata, CD_PROP_FLOAT3, POINTCLOUD_ATTR_POSITION); + pointcloud->radius = CustomData_get_layer_named( + &pointcloud->pdata, CD_PROP_FLOAT, POINTCLOUD_ATTR_RADIUS); +} + +bool BKE_pointcloud_customdata_required(PointCloud *UNUSED(pointcloud), CustomDataLayer *layer) +{ + return layer->type == CD_PROP_FLOAT3 && STREQ(layer->name, POINTCLOUD_ATTR_POSITION); } /* Dependency Graph */ @@ -259,7 +339,8 @@ static PointCloud *pointcloud_evaluate_modifiers(struct Depsgraph *depsgraph, } /* Ensure we are not overwriting referenced data. */ - CustomData_duplicate_referenced_layer(&pointcloud->pdata, CD_LOCATION, pointcloud->totpoint); + CustomData_duplicate_referenced_layer_named( + &pointcloud->pdata, CD_PROP_FLOAT3, POINTCLOUD_ATTR_POSITION, pointcloud->totpoint); BKE_pointcloud_update_customdata_pointers(pointcloud); /* Created deformed coordinates array on demand. */ diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 92c5af127fc..6c950c4b33f 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -1529,20 +1529,17 @@ static int evaluate_seq_frame_gen(Sequence **seq_arr, ListBase *seqbase, int cfr /* Drop strips which are used for effect inputs, we don't want * them to blend into render stack in any other way than effect - * string rendering. - */ + * string rendering. */ for (LinkNode *seq_item = effect_inputs.list; seq_item; seq_item = seq_item->next) { Sequence *seq = seq_item->link; - /* It's possible that effetc strip would be placed to the same + /* It's possible that effect strip would be placed to the same * 'machine' as it's inputs. We don't want to clear such strips - * from the stack. - */ + * from the stack. */ if (seq_arr[seq->machine] && seq_arr[seq->machine]->type & SEQ_TYPE_EFFECT) { continue; } - /* If we're shown a specified channel, then we want to see the stirps - * which belongs to this machine. - */ + /* If we're shown a specified channel, then we want to see the strips + * which belongs to this machine. */ if (chanshown != 0 && chanshown <= seq->machine) { continue; } @@ -1776,7 +1773,7 @@ static void seq_open_anim_file(Scene *scene, Sequence *seq, bool openfile) seq->strip->colorspace_settings.name); } - /* no individual view files - monoscopic, stereo 3d or exr multiview */ + /* No individual view files - monoscopic, stereo 3d or EXR multi-view. */ totfiles = 1; } @@ -1829,7 +1826,7 @@ static bool seq_proxy_get_custom_file_fname(Sequence *seq, char *name, const int if (view_id > 0) { BLI_snprintf(suffix, sizeof(suffix), "_%d", view_id); /* TODO(sergey): This will actually append suffix after extension - * which is weird but how was originally coded in multiview branch. + * which is weird but how was originally coded in multi-view branch. */ BLI_snprintf(name, PROXY_MAXFILE, "%s_%s", fname, suffix); } @@ -1855,7 +1852,7 @@ static bool seq_proxy_get_fname(Editing *ed, return false; } - /* Multiview suffix. */ + /* Multi-view suffix. */ if (view_id > 0) { BLI_snprintf(suffix, sizeof(suffix), "_%d", view_id); } @@ -2566,7 +2563,9 @@ static void *color_balance_do_thread(void *thread_data_v) return NULL; } -/* cfra is offset by fra_offset only in case we are using a real mask. */ +/** + * \a cfra is offset by \a fra_offset only in case we are using a real mask. + */ ImBuf *BKE_sequencer_render_mask_input(const SeqRenderData *context, int mask_input_type, Sequence *mask_sequence, @@ -2968,7 +2967,7 @@ static ImBuf *seq_render_effect_strip_impl(const SeqRenderData *context, break; case EARLY_DO_EFFECT: for (i = 0; i < 3; i++) { - /* Speed effect requires time remapping of cfra for input(s). */ + /* Speed effect requires time remapping of `cfra` for input(s). */ if (input[0] && seq->type == SEQ_TYPE_SPEED) { float target_frame = BKE_sequencer_speed_effect_target_frame_get(context, seq, cfra, i); ibuf[i] = seq_render_strip(context, state, input[0], target_frame); @@ -3013,7 +3012,9 @@ static ImBuf *seq_render_effect_strip_impl(const SeqRenderData *context, return out; } -/* Render individual view for multiview or single (default view) for monoview. */ +/** + * Render individual view for multi-view or single (default view) for mono-view. + */ static ImBuf *seq_render_image_strip_view(const SeqRenderData *context, Sequence *seq, char *name, @@ -3048,7 +3049,7 @@ static ImBuf *seq_render_image_strip_view(const SeqRenderData *context, imb_freerectImBuf(ibuf); } - /* All sequencer color is done in SRGB space, linear gives odd crossfades. */ + /* All sequencer color is done in SRGB space, linear gives odd cross-fades. */ BKE_sequencer_imbuf_to_sequencer_space(context->scene, ibuf, false); return ibuf; diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc index 9dc1f073e2a..f08051510db 100644 --- a/source/blender/blenkernel/intern/simulation.cc +++ b/source/blender/blenkernel/intern/simulation.cc @@ -63,6 +63,8 @@ #include "SIM_simulation_update.hh" +#include "BLO_read_write.h" + using StateInitFunction = void (*)(SimulationState *state); using StateResetFunction = void (*)(SimulationState *state); using StateRemoveFunction = void (*)(SimulationState *state); @@ -145,6 +147,94 @@ static void simulation_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void simulation_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Simulation *simulation = (Simulation *)id; + if (simulation->id.us > 0 || BLO_write_is_undo(writer)) { + BLO_write_id_struct(writer, Simulation, id_address, &simulation->id); + BKE_id_blend_write(writer, &simulation->id); + + if (simulation->adt) { + BKE_animdata_blend_write(writer, simulation->adt); + } + + /* nodetree is integral part of simulation, no libdata */ + if (simulation->nodetree) { + BLO_write_struct(writer, bNodeTree, simulation->nodetree); + ntreeBlendWrite(writer, simulation->nodetree); + } + + LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { + BLO_write_string(writer, state->name); + BLO_write_string(writer, state->type); + /* TODO: Decentralize this part. */ + if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_SIMULATION)) { + ParticleSimulationState *particle_state = (ParticleSimulationState *)state; + + CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; + CustomData_blend_write_prepare( + &particle_state->attributes, &players, players_buff, ARRAY_SIZE(players_buff)); + + BLO_write_struct(writer, ParticleSimulationState, particle_state); + + CustomData_blend_write(writer, + &particle_state->attributes, + players, + particle_state->tot_particles, + CD_MASK_ALL, + &simulation->id); + + /* Remove temporary data. */ + if (players && players != players_buff) { + MEM_freeN(players); + } + } + else if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_MESH_EMITTER)) { + ParticleMeshEmitterSimulationState *emitter_state = (ParticleMeshEmitterSimulationState *) + state; + BLO_write_struct(writer, ParticleMeshEmitterSimulationState, emitter_state); + } + } + + BLO_write_struct_list(writer, SimulationDependency, &simulation->dependencies); + } +} + +static void simulation_blend_read_data(BlendDataReader *reader, ID *id) +{ + Simulation *simulation = (Simulation *)id; + BLO_read_data_address(reader, &simulation->adt); + BKE_animdata_blend_read_data(reader, simulation->adt); + + BLO_read_list(reader, &simulation->states); + LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { + BLO_read_data_address(reader, &state->name); + BLO_read_data_address(reader, &state->type); + if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_SIMULATION)) { + ParticleSimulationState *particle_state = (ParticleSimulationState *)state; + CustomData_blend_read(reader, &particle_state->attributes, particle_state->tot_particles); + } + } + + BLO_read_list(reader, &simulation->dependencies); +} + +static void simulation_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Simulation *simulation = (Simulation *)id; + LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) { + BLO_read_id_address(reader, simulation->id.lib, &dependency->id); + } +} + +static void simulation_blend_read_expand(BlendExpander *expander, ID *id) +{ + Simulation *simulation = (Simulation *)id; + LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) { + BLO_expand(expander, dependency->id); + } +} + IDTypeInfo IDType_ID_SIM = { /* id_code */ ID_SIM, /* id_filter */ FILTER_ID_SIM, @@ -162,10 +252,10 @@ IDTypeInfo IDType_ID_SIM = { /* foreach_id */ simulation_foreach_id, /* foreach_cache */ NULL, - /* blend_write */ NULL, - /* blend_read_data */ NULL, - /* blend_read_lib */ NULL, - /* blend_read_expand */ NULL, + /* blend_write */ simulation_blend_write, + /* blend_read_data */ simulation_blend_read_data, + /* blend_read_lib */ simulation_blend_read_lib, + /* blend_read_expand */ simulation_blend_read_expand, }; void *BKE_simulation_add(Main *bmain, const char *name) diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 1ebbc1e2d77..9cf5ef85850 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -211,7 +211,7 @@ static float sb_time_scale(Object *ob) * will cause unwanted responses of the softbody system (which does inter frame calculations ) * so first 'cure' would be: interpolate linear in time .. * Q: why do i write this? - * A: because it happened once, that some eger coder 'streamlined' code to fail. + * A: because it happened once, that some eager coder 'streamlined' code to fail. * We DO linear interpolation for goals .. and i think we should do on animated properties as well */ @@ -3014,7 +3014,7 @@ static void curve_surf_to_softbody(Scene *scene, Object *ob) * * a: never ever make tangent handles (sub) and or (ob)ject to collision. * b: rather calculate them using some C2 - * (C2= continuous in second derivate -> no jump in bending ) condition. + * (C2= continuous in second derivative -> no jump in bending ) condition. * * Not too hard to do, but needs some more code to care for; * some one may want look at it (JOW 2010/06/12). */ diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 8ee6a3627dc..c8a31b51500 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -33,6 +33,9 @@ #include "BLT_translation.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_anim_types.h" #include "DNA_object_types.h" #include "DNA_packedFile_types.h" @@ -63,6 +66,8 @@ #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + static void sound_free_audio(bSound *sound); static void sound_copy_data(Main *UNUSED(bmain), @@ -126,6 +131,64 @@ static void sound_foreach_cache(ID *id, function_callback(id, &key, &sound->waveform, 0, user_data); } +static void sound_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + bSound *sound = (bSound *)id; + if (sound->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + sound->tags = 0; + sound->handle = NULL; + sound->playback_handle = NULL; + sound->spinlock = NULL; + + /* write LibData */ + BLO_write_id_struct(writer, bSound, id_address, &sound->id); + BKE_id_blend_write(writer, &sound->id); + + BKE_packedfile_blend_write(writer, sound->packedfile); + } +} + +static void sound_blend_read_data(BlendDataReader *reader, ID *id) +{ + bSound *sound = (bSound *)id; + sound->tags = 0; + sound->handle = NULL; + sound->playback_handle = NULL; + + /* versioning stuff, if there was a cache, then we enable caching: */ + if (sound->cache) { + sound->flags |= SOUND_FLAGS_CACHING; + sound->cache = NULL; + } + + if (BLO_read_data_is_undo(reader)) { + sound->tags |= SOUND_TAGS_WAVEFORM_NO_RELOAD; + } + + sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock"); + BLI_spin_init(sound->spinlock); + + /* clear waveform loading flag */ + sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING; + + BKE_packedfile_blend_read(reader, &sound->packedfile); + BKE_packedfile_blend_read(reader, &sound->newpackedfile); +} + +static void sound_blend_read_lib(BlendLibReader *reader, ID *id) +{ + bSound *sound = (bSound *)id; + BLO_read_id_address( + reader, sound->id.lib, &sound->ipo); // XXX deprecated - old animation system +} + +static void sound_blend_read_expand(BlendExpander *expander, ID *id) +{ + bSound *snd = (bSound *)id; + BLO_expand(expander, snd->ipo); // XXX deprecated - old animation system +} + IDTypeInfo IDType_ID_SO = { .id_code = ID_SO, .id_filter = FILTER_ID_SO, @@ -144,10 +207,10 @@ IDTypeInfo IDType_ID_SO = { .foreach_id = NULL, .foreach_cache = sound_foreach_cache, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = sound_blend_write, + .blend_read_data = sound_blend_read_data, + .blend_read_lib = sound_blend_read_lib, + .blend_read_expand = sound_blend_read_expand, }; #ifdef WITH_AUDASPACE diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c index 8f403792c46..0a8b4baf826 100644 --- a/source/blender/blenkernel/intern/speaker.c +++ b/source/blender/blenkernel/intern/speaker.c @@ -28,12 +28,15 @@ #include "BLT_translation.h" +#include "BKE_anim_data.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" #include "BKE_main.h" #include "BKE_speaker.h" +#include "BLO_read_write.h" + static void speaker_init_data(ID *id) { Speaker *speaker = (Speaker *)id; @@ -50,6 +53,44 @@ static void speaker_foreach_id(ID *id, LibraryForeachIDData *data) BKE_LIB_FOREACHID_PROCESS(data, speaker->sound, IDWALK_CB_USER); } +static void speaker_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Speaker *spk = (Speaker *)id; + if (spk->id.us > 0 || BLO_write_is_undo(writer)) { + /* write LibData */ + BLO_write_id_struct(writer, Speaker, id_address, &spk->id); + BKE_id_blend_write(writer, &spk->id); + + if (spk->adt) { + BKE_animdata_blend_write(writer, spk->adt); + } + } +} + +static void speaker_blend_read_data(BlendDataReader *reader, ID *id) +{ + Speaker *spk = (Speaker *)id; + BLO_read_data_address(reader, &spk->adt); + BKE_animdata_blend_read_data(reader, spk->adt); + +#if 0 + spk->sound = newdataadr(fd, spk->sound); + direct_link_sound(fd, spk->sound); +#endif +} + +static void speaker_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Speaker *spk = (Speaker *)id; + BLO_read_id_address(reader, spk->id.lib, &spk->sound); +} + +static void speaker_blend_read_expand(BlendExpander *expander, ID *id) +{ + Speaker *spk = (Speaker *)id; + BLO_expand(expander, spk->sound); +} + IDTypeInfo IDType_ID_SPK = { .id_code = ID_SPK, .id_filter = FILTER_ID_SPK, @@ -67,10 +108,10 @@ IDTypeInfo IDType_ID_SPK = { .foreach_id = speaker_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = speaker_blend_write, + .blend_read_data = speaker_blend_read_data, + .blend_read_lib = speaker_blend_read_lib, + .blend_read_expand = speaker_blend_read_expand, }; void *BKE_speaker_add(Main *bmain, const char *name) diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index bde9b9ab9b8..c1f2c66badb 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -55,6 +55,8 @@ #include "BKE_node.h" #include "BKE_text.h" +#include "BLO_read_write.h" + #ifdef WITH_PYTHON # include "BPY_extern.h" #endif @@ -167,6 +169,72 @@ static void text_free_data(ID *id) #endif } +static void text_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Text *text = (Text *)id; + + /* Note: we are clearing local temp data here, *not* the flag in the actual 'real' ID. */ + if ((text->flags & TXT_ISMEM) && (text->flags & TXT_ISEXT)) { + text->flags &= ~TXT_ISEXT; + } + + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + text->compiled = NULL; + + /* write LibData */ + BLO_write_id_struct(writer, Text, id_address, &text->id); + BKE_id_blend_write(writer, &text->id); + + if (text->filepath) { + BLO_write_string(writer, text->filepath); + } + + if (!(text->flags & TXT_ISEXT)) { + /* now write the text data, in two steps for optimization in the readfunction */ + LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { + BLO_write_struct(writer, TextLine, tmp); + } + + LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { + BLO_write_raw(writer, tmp->len + 1, tmp->line); + } + } +} + +static void text_blend_read_data(BlendDataReader *reader, ID *id) +{ + Text *text = (Text *)id; + BLO_read_data_address(reader, &text->filepath); + + text->compiled = NULL; + +#if 0 + if (text->flags & TXT_ISEXT) { + BKE_text_reload(text); + } + /* else { */ +#endif + + BLO_read_list(reader, &text->lines); + + BLO_read_data_address(reader, &text->curl); + BLO_read_data_address(reader, &text->sell); + + LISTBASE_FOREACH (TextLine *, ln, &text->lines) { + BLO_read_data_address(reader, &ln->line); + ln->format = NULL; + + if (ln->len != (int)strlen(ln->line)) { + printf("Error loading text, line lengths differ\n"); + ln->len = strlen(ln->line); + } + } + + text->flags = (text->flags) & ~TXT_ISEXT; + + id_us_ensure_real(&text->id); +} + IDTypeInfo IDType_ID_TXT = { .id_code = ID_TXT, .id_filter = FILTER_ID_TXT, @@ -184,8 +252,8 @@ IDTypeInfo IDType_ID_TXT = { .foreach_id = NULL, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, + .blend_write = text_blend_write, + .blend_read_data = text_blend_read_data, .blend_read_lib = NULL, .blend_read_expand = NULL, }; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 9e176f355d3..698f6b8cffd 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -36,6 +36,9 @@ #include "BLT_translation.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_brush_types.h" #include "DNA_color_types.h" #include "DNA_defaults.h" @@ -50,6 +53,7 @@ #include "BKE_main.h" +#include "BKE_anim_data.h" #include "BKE_colorband.h" #include "BKE_colortools.h" #include "BKE_icons.h" @@ -65,6 +69,8 @@ #include "RE_shader_ext.h" +#include "BLO_read_write.h" + static void texture_init_data(ID *id) { Tex *texture = (Tex *)id; @@ -134,6 +140,62 @@ static void texture_foreach_id(ID *id, LibraryForeachIDData *data) BKE_LIB_FOREACHID_PROCESS(data, texture->ima, IDWALK_CB_USER); } +static void texture_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Tex *tex = (Tex *)id; + if (tex->id.us > 0 || BLO_write_is_undo(writer)) { + /* write LibData */ + BLO_write_id_struct(writer, Tex, id_address, &tex->id); + BKE_id_blend_write(writer, &tex->id); + + if (tex->adt) { + BKE_animdata_blend_write(writer, tex->adt); + } + + /* direct data */ + if (tex->coba) { + BLO_write_struct(writer, ColorBand, tex->coba); + } + + /* nodetree is integral part of texture, no libdata */ + if (tex->nodetree) { + BLO_write_struct(writer, bNodeTree, tex->nodetree); + ntreeBlendWrite(writer, tex->nodetree); + } + + BKE_previewimg_blend_write(writer, tex->preview); + } +} + +static void texture_blend_read_data(BlendDataReader *reader, ID *id) +{ + Tex *tex = (Tex *)id; + BLO_read_data_address(reader, &tex->adt); + BKE_animdata_blend_read_data(reader, tex->adt); + + BLO_read_data_address(reader, &tex->coba); + + BLO_read_data_address(reader, &tex->preview); + BKE_previewimg_blend_read(reader, tex->preview); + + tex->iuser.ok = 1; + tex->iuser.scene = NULL; +} + +static void texture_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Tex *tex = (Tex *)id; + BLO_read_id_address(reader, tex->id.lib, &tex->ima); + BLO_read_id_address(reader, tex->id.lib, &tex->ipo); // XXX deprecated - old animation system +} + +static void texture_blend_read_expand(BlendExpander *expander, ID *id) +{ + Tex *tex = (Tex *)id; + BLO_expand(expander, tex->ima); + BLO_expand(expander, tex->ipo); // XXX deprecated - old animation system +} + IDTypeInfo IDType_ID_TE = { .id_code = ID_TE, .id_filter = FILTER_ID_TE, @@ -151,10 +213,10 @@ IDTypeInfo IDType_ID_TE = { .foreach_id = texture_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = texture_blend_write, + .blend_read_data = texture_blend_read_data, + .blend_read_lib = texture_blend_read_lib, + .blend_read_expand = texture_blend_read_expand, }; /* Utils for all IDs using those texture slots. */ diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc index f99be2f6aee..eb871e41f8e 100644 --- a/source/blender/blenkernel/intern/volume.cc +++ b/source/blender/blenkernel/intern/volume.cc @@ -51,6 +51,8 @@ #include "DEG_depsgraph_query.h" +#include "BLO_read_write.h" + #include "CLG_log.h" #ifdef WITH_OPENVDB @@ -509,6 +511,61 @@ static void volume_foreach_cache(ID *id, function_callback(id, &key, (void **)&volume->runtime.grids, 0, user_data); } +static void volume_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + Volume *volume = (Volume *)id; + if (volume->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + volume->runtime.grids = 0; + + /* write LibData */ + BLO_write_id_struct(writer, Volume, id_address, &volume->id); + BKE_id_blend_write(writer, &volume->id); + + /* direct data */ + BLO_write_pointer_array(writer, volume->totcol, volume->mat); + if (volume->adt) { + BKE_animdata_blend_write(writer, volume->adt); + } + + BKE_packedfile_blend_write(writer, volume->packedfile); + } +} + +static void volume_blend_read_data(BlendDataReader *reader, ID *id) +{ + Volume *volume = (Volume *)id; + BLO_read_data_address(reader, &volume->adt); + BKE_animdata_blend_read_data(reader, volume->adt); + + BKE_packedfile_blend_read(reader, &volume->packedfile); + volume->runtime.frame = 0; + + /* materials */ + BLO_read_pointer_array(reader, (void **)&volume->mat); +} + +static void volume_blend_read_lib(BlendLibReader *reader, ID *id) +{ + Volume *volume = (Volume *)id; + /* Needs to be done *after* cache pointers are restored (call to + * `foreach_cache`/`blo_cache_storage_entry_restore_in_new`), easier for now to do it in + * lib_link... */ + BKE_volume_init_grids(volume); + + for (int a = 0; a < volume->totcol; a++) { + BLO_read_id_address(reader, volume->id.lib, &volume->mat[a]); + } +} + +static void volume_blend_read_expand(BlendExpander *expander, ID *id) +{ + Volume *volume = (Volume *)id; + for (int a = 0; a < volume->totcol; a++) { + BLO_expand(expander, volume->mat[a]); + } +} + IDTypeInfo IDType_ID_VO = { /* id_code */ ID_VO, /* id_filter */ FILTER_ID_VO, @@ -526,10 +583,10 @@ IDTypeInfo IDType_ID_VO = { /* foreach_id */ volume_foreach_id, /* foreach_cache */ volume_foreach_cache, - /* blend_write */ NULL, - /* blend_read_data */ NULL, - /* blend_read_lib */ NULL, - /* blend_read_expand */ NULL, + /* blend_write */ volume_blend_write, + /* blend_read_data */ volume_blend_read_data, + /* blend_read_lib */ volume_blend_read_lib, + /* blend_read_expand */ volume_blend_read_expand, }; void BKE_volume_init_grids(Volume *volume) diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index 25c62f139ed..99f35d06c1d 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -27,6 +27,9 @@ #include "MEM_guardedalloc.h" +/* Allow using deprecated functionality for .blend file I/O. */ +#define DNA_DEPRECATED_ALLOW + #include "DNA_defaults.h" #include "DNA_scene_types.h" #include "DNA_texture_types.h" @@ -35,6 +38,7 @@ #include "BLI_listbase.h" #include "BLI_utildefines.h" +#include "BKE_anim_data.h" #include "BKE_icons.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" @@ -51,6 +55,8 @@ #include "GPU_material.h" +#include "BLO_read_write.h" + /** Free (or release) any data used by this world (does not free the world itself). */ static void world_free_data(ID *id) { @@ -122,6 +128,54 @@ static void world_foreach_id(ID *id, LibraryForeachIDData *data) } } +static void world_blend_write(BlendWriter *writer, ID *id, const void *id_address) +{ + World *wrld = (World *)id; + if (wrld->id.us > 0 || BLO_write_is_undo(writer)) { + /* Clean up, important in undo case to reduce false detection of changed datablocks. */ + BLI_listbase_clear(&wrld->gpumaterial); + + /* write LibData */ + BLO_write_id_struct(writer, World, id_address, &wrld->id); + BKE_id_blend_write(writer, &wrld->id); + + if (wrld->adt) { + BKE_animdata_blend_write(writer, wrld->adt); + } + + /* nodetree is integral part of world, no libdata */ + if (wrld->nodetree) { + BLO_write_struct(writer, bNodeTree, wrld->nodetree); + ntreeBlendWrite(writer, wrld->nodetree); + } + + BKE_previewimg_blend_write(writer, wrld->preview); + } +} + +static void world_blend_read_data(BlendDataReader *reader, ID *id) +{ + World *wrld = (World *)id; + BLO_read_data_address(reader, &wrld->adt); + BKE_animdata_blend_read_data(reader, wrld->adt); + + BLO_read_data_address(reader, &wrld->preview); + BKE_previewimg_blend_read(reader, wrld->preview); + BLI_listbase_clear(&wrld->gpumaterial); +} + +static void world_blend_read_lib(BlendLibReader *reader, ID *id) +{ + World *wrld = (World *)id; + BLO_read_id_address(reader, wrld->id.lib, &wrld->ipo); // XXX deprecated - old animation system +} + +static void world_blend_read_expand(BlendExpander *expander, ID *id) +{ + World *wrld = (World *)id; + BLO_expand(expander, wrld->ipo); // XXX deprecated - old animation system +} + IDTypeInfo IDType_ID_WO = { .id_code = ID_WO, .id_filter = FILTER_ID_WO, @@ -139,10 +193,10 @@ IDTypeInfo IDType_ID_WO = { .foreach_id = world_foreach_id, .foreach_cache = NULL, - .blend_write = NULL, - .blend_read_data = NULL, - .blend_read_lib = NULL, - .blend_read_expand = NULL, + .blend_write = world_blend_write, + .blend_read_data = world_blend_read_data, + .blend_read_lib = world_blend_read_lib, + .blend_read_expand = world_blend_read_expand, }; World *BKE_world_add(Main *bmain, const char *name) diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index f030a733752..73f8c2717b0 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -202,7 +202,7 @@ const float bvhtree_kdop_axes[13][3] = { }; /* Used to correct the epsilon and thus match the overlap distance. */ -const float bvhtree_kdop_axes_length[13] = { +static const float bvhtree_kdop_axes_length[13] = { 1.0f, 1.0f, 1.0f, diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 08c7d3b1e91..6727e6a337d 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -2616,9 +2616,9 @@ void print_m4(const char *str, const float m[4][4]) * * Compute the Single Value Decomposition of an arbitrary matrix A * That is compute the 3 matrices U,W,V with U column orthogonal (m,n) - * ,W a diagonal matrix and V an orthogonal square matrix s.t. - * A = U.W.Vt. From this decomposition it is trivial to compute the - * (pseudo-inverse) of A as Ainv = V.Winv.tranpose(U). + * ,W a diagonal matrix and V an orthogonal square matrix `s.t.A = U.W.Vt`. + * From this decomposition it is trivial to compute the (pseudo-inverse) + * of `A` as `Ainv = V.Winv.transpose(U)`. */ void svd_m4(float U[4][4], float s[4], float V[4][4], float A_[4][4]) diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index cde4394a8c3..6328c887063 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1299,6 +1299,11 @@ void BLI_setenv_if_new(const char *env, const char *val) /** * Get an env var, result has to be used immediately. + * + * On windows getenv gets its variables from a static copy of the environment variables taken at + * process start-up, causing it to not pick up on environment variables created during runtime. + * This function uses an alternative method to get environment variables that does pick up on + * runtime environment variables. */ const char *BLI_getenv(const char *env) { diff --git a/source/blender/blenlib/intern/string_search.cc b/source/blender/blenlib/intern/string_search.cc index 17da3b9f493..d64587b85b4 100644 --- a/source/blender/blenlib/intern/string_search.cc +++ b/source/blender/blenlib/intern/string_search.cc @@ -108,7 +108,7 @@ int damerau_levenshtein_distance(StringRef a, StringRef b) */ int get_fuzzy_match_errors(StringRef query, StringRef full) { - /* If it is a perfect partial match, return immediatly. */ + /* If it is a perfect partial match, return immediately. */ if (full.find(query) != StringRef::not_found) { return 0; } @@ -180,8 +180,8 @@ int get_fuzzy_match_errors(StringRef query, StringRef full) * So "bose" does not match "select boundary". However, individual words can be skipped. For * example, "rocc" matches "rotate edge ccw". * - * Returns true when the match was successfull. If it was successfull, the used words are tagged in - * r_word_is_matched. + * \return true when the match was successful. + * If it was successful, the used words are tagged in \a r_word_is_matched. */ static bool match_word_initials(StringRef query, Span<StringRef> words, @@ -384,7 +384,7 @@ void extract_normalized_words(StringRef str, } offset += size; } - /* If the last word is not followed by a separator, it has to be handld separately. */ + /* If the last word is not followed by a separator, it has to be handled separately. */ if (is_in_word) { r_words.append(str_copy.drop_prefix(static_cast<int>(word_start))); } diff --git a/source/blender/blenloader/BLO_read_write.h b/source/blender/blenloader/BLO_read_write.h index e05c1046b95..8a6811444af 100644 --- a/source/blender/blenloader/BLO_read_write.h +++ b/source/blender/blenloader/BLO_read_write.h @@ -210,7 +210,7 @@ bool BLO_read_data_is_undo(BlendDataReader *reader); ID *BLO_read_get_new_id_address(BlendLibReader *reader, struct Library *lib, struct ID *id); #define BLO_read_id_address(reader, lib, id_ptr_p) \ - *(id_ptr_p) = (void *)BLO_read_get_new_id_address((reader), (lib), (ID *)*(id_ptr_p)) + *((void **)id_ptr_p) = (void *)BLO_read_get_new_id_address((reader), (lib), (ID *)*(id_ptr_p)) /* Misc. */ bool BLO_read_lib_is_undo(BlendLibReader *reader); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 0d77965306f..b0f0a08651c 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -113,6 +113,7 @@ #include "BKE_action.h" #include "BKE_anim_data.h" +#include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_brush.h" #include "BKE_collection.h" @@ -126,8 +127,10 @@ #include "BKE_fcurve_driver.h" #include "BKE_fluid.h" #include "BKE_global.h" // for G +#include "BKE_gpencil.h" #include "BKE_gpencil_modifier.h" #include "BKE_hair.h" +#include "BKE_icons.h" #include "BKE_idprop.h" #include "BKE_idtype.h" #include "BKE_image.h" @@ -145,6 +148,7 @@ #include "BKE_nla.h" #include "BKE_node.h" // for tree type defines #include "BKE_object.h" +#include "BKE_packedFile.h" #include "BKE_paint.h" #include "BKE_particle.h" #include "BKE_pointcache.h" @@ -2246,35 +2250,10 @@ static void link_glob_list(FileData *fd, ListBase *lb) /* for glob data */ /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read Image Preview - * \{ */ - -static PreviewImage *direct_link_preview_image(BlendDataReader *reader, PreviewImage *old_prv) -{ - PreviewImage *prv = BLO_read_get_new_data_address(reader, old_prv); - - if (prv) { - for (int i = 0; i < NUM_ICON_SIZES; i++) { - if (prv->rect[i]) { - BLO_read_data_address(reader, &prv->rect[i]); - } - prv->gputexture[i] = NULL; - } - prv->icon_id = 0; - prv->tag = 0; - } - - return prv; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read ID * \{ */ static void lib_link_id(BlendLibReader *reader, ID *id); -static void lib_link_nodetree(BlendLibReader *reader, bNodeTree *ntree); static void lib_link_collection(BlendLibReader *reader, Collection *collection); static void lib_link_id_embedded_id(BlendLibReader *reader, ID *id) @@ -2284,7 +2263,7 @@ static void lib_link_id_embedded_id(BlendLibReader *reader, ID *id) bNodeTree *nodetree = ntreeFromID(id); if (nodetree != NULL) { lib_link_id(reader, &nodetree->id); - lib_link_nodetree(reader, nodetree); + ntreeBlendReadLib(reader, nodetree); } if (GS(id->name) == ID_SCE) { @@ -2338,7 +2317,6 @@ static void direct_link_id_override_property_cb(BlendDataReader *reader, void *d static void direct_link_id_common( BlendDataReader *reader, Library *current_library, ID *id, ID *id_old, const int tag); -static void direct_link_nodetree(BlendDataReader *reader, bNodeTree *ntree); static void direct_link_collection(BlendDataReader *reader, Collection *collection); static void direct_link_id_embedded_id(BlendDataReader *reader, @@ -2355,7 +2333,7 @@ static void direct_link_id_embedded_id(BlendDataReader *reader, (ID *)*nodetree, id_old != NULL ? (ID *)ntreeFromID(id_old) : NULL, 0); - direct_link_nodetree(reader, *nodetree); + ntreeBlendReadData(reader, *nodetree); } if (GS(id->name) == ID_SCE) { @@ -2501,157 +2479,6 @@ static void direct_link_id_common( /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: Brush - * \{ */ - -/* library brush linking after fileread */ -static void lib_link_brush(BlendLibReader *reader, Brush *brush) -{ - /* brush->(mask_)mtex.obj is ignored on purpose? */ - BLO_read_id_address(reader, brush->id.lib, &brush->mtex.tex); - BLO_read_id_address(reader, brush->id.lib, &brush->mask_mtex.tex); - BLO_read_id_address(reader, brush->id.lib, &brush->clone.image); - BLO_read_id_address(reader, brush->id.lib, &brush->toggle_brush); - BLO_read_id_address(reader, brush->id.lib, &brush->paint_curve); - - /* link default grease pencil palette */ - if (brush->gpencil_settings != NULL) { - if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) { - BLO_read_id_address(reader, brush->id.lib, &brush->gpencil_settings->material); - - if (!brush->gpencil_settings->material) { - brush->gpencil_settings->flag &= ~GP_BRUSH_MATERIAL_PINNED; - } - } - else { - brush->gpencil_settings->material = NULL; - } - } -} - -static void direct_link_brush(BlendDataReader *reader, Brush *brush) -{ - /* brush itself has been read */ - - /* fallof curve */ - BLO_read_data_address(reader, &brush->curve); - - BLO_read_data_address(reader, &brush->gradient); - - if (brush->curve) { - BKE_curvemapping_blend_read(reader, brush->curve); - } - else { - BKE_brush_curve_preset(brush, CURVE_PRESET_SHARP); - } - - /* grease pencil */ - BLO_read_data_address(reader, &brush->gpencil_settings); - if (brush->gpencil_settings != NULL) { - BLO_read_data_address(reader, &brush->gpencil_settings->curve_sensitivity); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_strength); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_jitter); - - BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_pressure); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_strength); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_uv); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_hue); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_saturation); - BLO_read_data_address(reader, &brush->gpencil_settings->curve_rand_value); - - if (brush->gpencil_settings->curve_sensitivity) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_sensitivity); - } - - if (brush->gpencil_settings->curve_strength) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_strength); - } - - if (brush->gpencil_settings->curve_jitter) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_jitter); - } - - if (brush->gpencil_settings->curve_rand_pressure) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_pressure); - } - - if (brush->gpencil_settings->curve_rand_strength) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_strength); - } - - if (brush->gpencil_settings->curve_rand_uv) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_uv); - } - - if (brush->gpencil_settings->curve_rand_hue) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_hue); - } - - if (brush->gpencil_settings->curve_rand_saturation) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_saturation); - } - - if (brush->gpencil_settings->curve_rand_value) { - BKE_curvemapping_blend_read(reader, brush->gpencil_settings->curve_rand_value); - } - } - - brush->preview = NULL; - brush->icon_imbuf = NULL; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Palette - * \{ */ - -static void lib_link_palette(BlendLibReader *UNUSED(reader), Palette *UNUSED(palette)) -{ -} - -static void direct_link_palette(BlendDataReader *reader, Palette *palette) -{ - - /* palette itself has been read */ - BLO_read_list(reader, &palette->colors); -} - -static void lib_link_paint_curve(BlendLibReader *UNUSED(reader), PaintCurve *UNUSED(pc)) -{ -} - -static void direct_link_paint_curve(BlendDataReader *reader, PaintCurve *pc) -{ - BLO_read_data_address(reader, &pc->points); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read PackedFile - * \{ */ - -static PackedFile *direct_link_packedfile(BlendDataReader *reader, PackedFile *pf) -{ - BLO_read_packed_address(reader, &pf); - - if (pf) { - BLO_read_packed_address(reader, &pf->data); - if (pf->data == NULL) { - /* We cannot allow a PackedFile with a NULL data field, - * the whole code assumes this is not possible. See T70315. */ - printf("%s: NULL packedfile data, cleaning up...\n", __func__); - MEM_SAFE_FREE(pf); - } - } - - return pf; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read Animation (legacy for version patching) * \{ */ @@ -2711,102 +2538,6 @@ static void lib_link_constraint_channels(BlendLibReader *reader, ID *id, ListBas /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: Action - * \{ */ - -static void lib_link_action(BlendLibReader *reader, bAction *act) -{ - // XXX deprecated - old animation system <<< - LISTBASE_FOREACH (bActionChannel *, chan, &act->chanbase) { - BLO_read_id_address(reader, act->id.lib, &chan->ipo); - lib_link_constraint_channels(reader, &act->id, &chan->constraintChannels); - } - // >>> XXX deprecated - old animation system - - BKE_fcurve_blend_read_lib(reader, &act->id, &act->curves); - - LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { - if (marker->camera) { - BLO_read_id_address(reader, act->id.lib, &marker->camera); - } - } -} - -static void direct_link_action(BlendDataReader *reader, bAction *act) -{ - BLO_read_list(reader, &act->curves); - BLO_read_list(reader, &act->chanbase); // XXX deprecated - old animation system - BLO_read_list(reader, &act->groups); - BLO_read_list(reader, &act->markers); - - // XXX deprecated - old animation system <<< - LISTBASE_FOREACH (bActionChannel *, achan, &act->chanbase) { - BLO_read_data_address(reader, &achan->grp); - - BLO_read_list(reader, &achan->constraintChannels); - } - // >>> XXX deprecated - old animation system - - BKE_fcurve_blend_read_data(reader, &act->curves); - - LISTBASE_FOREACH (bActionGroup *, agrp, &act->groups) { - BLO_read_data_address(reader, &agrp->channels.first); - BLO_read_data_address(reader, &agrp->channels.last); - } -} - -/* ------- */ - -static void lib_link_keyingsets(BlendLibReader *reader, ID *id, ListBase *list) -{ - /* here, we're only interested in the ID pointer stored in some of the paths */ - LISTBASE_FOREACH (KeyingSet *, ks, list) { - LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { - BLO_read_id_address(reader, id->lib, &ksp->id); - } - } -} - -/* NOTE: this assumes that BLO_read_list has already been called on the list */ -static void direct_link_keyingsets(BlendDataReader *reader, ListBase *list) -{ - /* link KeyingSet data to KeyingSet again (non ID-libs) */ - LISTBASE_FOREACH (KeyingSet *, ks, list) { - /* paths */ - BLO_read_list(reader, &ks->paths); - - LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { - /* rna path */ - BLO_read_data_address(reader, &ksp->rna_path); - } - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: CacheFiles - * \{ */ - -static void lib_link_cachefiles(BlendLibReader *UNUSED(reader), CacheFile *UNUSED(cache_file)) -{ -} - -static void direct_link_cachefile(BlendDataReader *reader, CacheFile *cache_file) -{ - BLI_listbase_clear(&cache_file->object_paths); - cache_file->handle = NULL; - cache_file->handle_filepath[0] = '\0'; - cache_file->handle_readers = NULL; - - /* relink animdata */ - BLO_read_data_address(reader, &cache_file->adt); - BKE_animdata_blend_read_data(reader, cache_file->adt); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read ID: WorkSpace * \{ */ @@ -2878,246 +2609,6 @@ static void lib_link_workspace_instance_hook(BlendLibReader *reader, /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: Node Tree - * \{ */ - -static void lib_link_node_socket(BlendLibReader *reader, Library *lib, bNodeSocket *sock) -{ - IDP_BlendReadLib(reader, sock->prop); - - switch ((eNodeSocketDatatype)sock->type) { - case SOCK_OBJECT: { - bNodeSocketValueObject *default_value = sock->default_value; - BLO_read_id_address(reader, lib, &default_value->value); - break; - } - case SOCK_IMAGE: { - bNodeSocketValueImage *default_value = sock->default_value; - BLO_read_id_address(reader, lib, &default_value->value); - break; - } - case SOCK_FLOAT: - case SOCK_VECTOR: - case SOCK_RGBA: - case SOCK_BOOLEAN: - case SOCK_INT: - case SOCK_STRING: - case __SOCK_MESH: - case SOCK_CUSTOM: - case SOCK_SHADER: - case SOCK_EMITTERS: - case SOCK_EVENTS: - case SOCK_FORCES: - case SOCK_CONTROL_FLOW: - break; - } -} - -static void lib_link_node_sockets(BlendLibReader *reader, Library *lib, ListBase *sockets) -{ - LISTBASE_FOREACH (bNodeSocket *, sock, sockets) { - lib_link_node_socket(reader, lib, sock); - } -} - -/* Single node tree (also used for material/scene trees), ntree is not NULL */ -static void lib_link_ntree(BlendLibReader *reader, Library *lib, bNodeTree *ntree) -{ - ntree->id.lib = lib; - - BLO_read_id_address(reader, lib, &ntree->gpd); - - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - /* Link ID Properties -- and copy this comment EXACTLY for easy finding - * of library blocks that implement this.*/ - IDP_BlendReadLib(reader, node->prop); - - BLO_read_id_address(reader, lib, &node->id); - - lib_link_node_sockets(reader, lib, &node->inputs); - lib_link_node_sockets(reader, lib, &node->outputs); - } - - lib_link_node_sockets(reader, lib, &ntree->inputs); - lib_link_node_sockets(reader, lib, &ntree->outputs); - - /* Set node->typeinfo pointers. This is done in lib linking, after the - * first versioning that can change types still without functions that - * update the typeinfo pointers. Versioning after lib linking needs - * these top be valid. */ - ntreeSetTypes(NULL, ntree); - - /* For nodes with static socket layout, add/remove sockets as needed - * to match the static layout. */ - if (!BLO_read_lib_is_undo(reader)) { - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - node_verify_socket_templates(ntree, node); - } - } -} - -/* library ntree linking after fileread */ -static void lib_link_nodetree(BlendLibReader *reader, bNodeTree *ntree) -{ - lib_link_ntree(reader, ntree->id.lib, ntree); -} - -static void direct_link_node_socket(BlendDataReader *reader, bNodeSocket *sock) -{ - BLO_read_data_address(reader, &sock->prop); - IDP_BlendDataRead(reader, &sock->prop); - - BLO_read_data_address(reader, &sock->link); - sock->typeinfo = NULL; - BLO_read_data_address(reader, &sock->storage); - BLO_read_data_address(reader, &sock->default_value); - sock->cache = NULL; -} - -/* ntree itself has been read! */ -static void direct_link_nodetree(BlendDataReader *reader, bNodeTree *ntree) -{ - /* note: writing and reading goes in sync, for speed */ - - ntree->init = 0; /* to set callbacks and force setting types */ - ntree->is_updating = false; - ntree->typeinfo = NULL; - ntree->interface_type = NULL; - - ntree->progress = NULL; - ntree->execdata = NULL; - - BLO_read_data_address(reader, &ntree->adt); - BKE_animdata_blend_read_data(reader, ntree->adt); - - BLO_read_list(reader, &ntree->nodes); - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - node->typeinfo = NULL; - - BLO_read_list(reader, &node->inputs); - BLO_read_list(reader, &node->outputs); - - BLO_read_data_address(reader, &node->prop); - IDP_BlendDataRead(reader, &node->prop); - - BLO_read_list(reader, &node->internal_links); - LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) { - BLO_read_data_address(reader, &link->fromnode); - BLO_read_data_address(reader, &link->fromsock); - BLO_read_data_address(reader, &link->tonode); - BLO_read_data_address(reader, &link->tosock); - } - - if (node->type == CMP_NODE_MOVIEDISTORTION) { - /* Do nothing, this is runtime cache and hence handled by generic code using - * `IDTypeInfo.foreach_cache` callback. */ - } - else { - BLO_read_data_address(reader, &node->storage); - } - - if (node->storage) { - /* could be handlerized at some point */ - switch (node->type) { - case SH_NODE_CURVE_VEC: - case SH_NODE_CURVE_RGB: - case CMP_NODE_TIME: - case CMP_NODE_CURVE_VEC: - case CMP_NODE_CURVE_RGB: - case CMP_NODE_HUECORRECT: - case TEX_NODE_CURVE_RGB: - case TEX_NODE_CURVE_TIME: { - BKE_curvemapping_blend_read(reader, node->storage); - break; - } - case SH_NODE_SCRIPT: { - NodeShaderScript *nss = (NodeShaderScript *)node->storage; - BLO_read_data_address(reader, &nss->bytecode); - break; - } - case SH_NODE_TEX_POINTDENSITY: { - NodeShaderTexPointDensity *npd = (NodeShaderTexPointDensity *)node->storage; - memset(&npd->pd, 0, sizeof(npd->pd)); - break; - } - case SH_NODE_TEX_IMAGE: { - NodeTexImage *tex = (NodeTexImage *)node->storage; - tex->iuser.ok = 1; - tex->iuser.scene = NULL; - break; - } - case SH_NODE_TEX_ENVIRONMENT: { - NodeTexEnvironment *tex = (NodeTexEnvironment *)node->storage; - tex->iuser.ok = 1; - tex->iuser.scene = NULL; - break; - } - case CMP_NODE_IMAGE: - case CMP_NODE_R_LAYERS: - case CMP_NODE_VIEWER: - case CMP_NODE_SPLITVIEWER: { - ImageUser *iuser = node->storage; - iuser->ok = 1; - iuser->scene = NULL; - break; - } - case CMP_NODE_CRYPTOMATTE: { - NodeCryptomatte *nc = (NodeCryptomatte *)node->storage; - BLO_read_data_address(reader, &nc->matte_id); - break; - } - case TEX_NODE_IMAGE: { - ImageUser *iuser = node->storage; - iuser->ok = 1; - iuser->scene = NULL; - break; - } - default: - break; - } - } - } - BLO_read_list(reader, &ntree->links); - - /* and we connect the rest */ - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - BLO_read_data_address(reader, &node->parent); - node->lasty = 0; - - LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { - direct_link_node_socket(reader, sock); - } - LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { - direct_link_node_socket(reader, sock); - } - } - - /* interface socket lists */ - BLO_read_list(reader, &ntree->inputs); - BLO_read_list(reader, &ntree->outputs); - LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) { - direct_link_node_socket(reader, sock); - } - LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) { - direct_link_node_socket(reader, sock); - } - - LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { - BLO_read_data_address(reader, &link->fromnode); - BLO_read_data_address(reader, &link->tonode); - BLO_read_data_address(reader, &link->fromsock); - BLO_read_data_address(reader, &link->tosock); - } - - /* TODO, should be dealt by new generic cache handling of IDs... */ - ntree->previews = NULL; - - /* type verification is in lib-link */ -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read ID: Armature * \{ */ @@ -3275,117 +2766,6 @@ static void lib_link_pose(BlendLibReader *reader, Object *ob, bPose *pose) } } -static void lib_link_bones(BlendLibReader *reader, Bone *bone) -{ - IDP_BlendReadLib(reader, bone->prop); - - LISTBASE_FOREACH (Bone *, curbone, &bone->childbase) { - lib_link_bones(reader, curbone); - } -} - -static void lib_link_armature(BlendLibReader *reader, bArmature *arm) -{ - LISTBASE_FOREACH (Bone *, curbone, &arm->bonebase) { - lib_link_bones(reader, curbone); - } -} - -static void direct_link_bones(BlendDataReader *reader, Bone *bone) -{ - BLO_read_data_address(reader, &bone->parent); - BLO_read_data_address(reader, &bone->prop); - IDP_BlendDataRead(reader, &bone->prop); - - BLO_read_data_address(reader, &bone->bbone_next); - BLO_read_data_address(reader, &bone->bbone_prev); - - bone->flag &= ~(BONE_DRAW_ACTIVE | BONE_DRAW_LOCKED_WEIGHT); - - BLO_read_list(reader, &bone->childbase); - - LISTBASE_FOREACH (Bone *, child, &bone->childbase) { - direct_link_bones(reader, child); - } -} - -static void direct_link_armature(BlendDataReader *reader, bArmature *arm) -{ - BLO_read_list(reader, &arm->bonebase); - arm->bonehash = NULL; - arm->edbo = NULL; - /* Must always be cleared (armatures don't have their own edit-data). */ - arm->needs_flush_to_id = 0; - - BLO_read_data_address(reader, &arm->adt); - BKE_animdata_blend_read_data(reader, arm->adt); - - LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { - direct_link_bones(reader, bone); - } - - BLO_read_data_address(reader, &arm->act_bone); - arm->act_edbone = NULL; - - BKE_armature_bone_hash_make(arm); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Camera - * \{ */ - -static void lib_link_camera(BlendLibReader *reader, Camera *ca) -{ - BLO_read_id_address(reader, ca->id.lib, &ca->ipo); /* deprecated, for versioning */ - - BLO_read_id_address(reader, ca->id.lib, &ca->dof_ob); /* deprecated, for versioning */ - BLO_read_id_address(reader, ca->id.lib, &ca->dof.focus_object); - - LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) { - BLO_read_id_address(reader, ca->id.lib, &bgpic->ima); - BLO_read_id_address(reader, ca->id.lib, &bgpic->clip); - } -} - -static void direct_link_camera(BlendDataReader *reader, Camera *ca) -{ - BLO_read_data_address(reader, &ca->adt); - BKE_animdata_blend_read_data(reader, ca->adt); - - BLO_read_list(reader, &ca->bg_images); - - LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) { - bgpic->iuser.ok = 1; - bgpic->iuser.scene = NULL; - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Light - * \{ */ - -static void lib_link_light(BlendLibReader *reader, Light *la) -{ - BLO_read_id_address(reader, la->id.lib, &la->ipo); // XXX deprecated - old animation system -} - -static void direct_link_light(BlendDataReader *reader, Light *la) -{ - BLO_read_data_address(reader, &la->adt); - BKE_animdata_blend_read_data(reader, la->adt); - - BLO_read_data_address(reader, &la->curfalloff); - if (la->curfalloff) { - BKE_curvemapping_blend_read(reader, la->curfalloff); - } - - la->preview = direct_link_preview_image(reader, la->preview); -} - /** \} */ /* -------------------------------------------------------------------- */ @@ -3400,371 +2780,6 @@ void blo_do_versions_key_uidgen(Key *key) } } -static void lib_link_key(BlendLibReader *reader, Key *key) -{ - BLI_assert((key->id.tag & LIB_TAG_EXTERN) == 0); - - BLO_read_id_address(reader, key->id.lib, &key->ipo); // XXX deprecated - old animation system - BLO_read_id_address(reader, key->id.lib, &key->from); -} - -static void switch_endian_keyblock(Key *key, KeyBlock *kb) -{ - int elemsize = key->elemsize; - char *data = kb->data; - - for (int a = 0; a < kb->totelem; a++) { - const char *cp = key->elemstr; - char *poin = data; - - while (cp[0]) { /* cp[0] == amount */ - switch (cp[1]) { /* cp[1] = type */ - case IPO_FLOAT: - case IPO_BPOINT: - case IPO_BEZTRIPLE: { - int b = cp[0]; - BLI_endian_switch_float_array((float *)poin, b); - poin += sizeof(float) * b; - break; - } - } - - cp += 2; - } - data += elemsize; - } -} - -static void direct_link_key(BlendDataReader *reader, Key *key) -{ - BLO_read_list(reader, &(key->block)); - - BLO_read_data_address(reader, &key->adt); - BKE_animdata_blend_read_data(reader, key->adt); - - BLO_read_data_address(reader, &key->refkey); - - LISTBASE_FOREACH (KeyBlock *, kb, &key->block) { - BLO_read_data_address(reader, &kb->data); - - if (BLO_read_requires_endian_switch(reader)) { - switch_endian_keyblock(key, kb); - } - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Meta Ball - * \{ */ - -static void lib_link_mball(BlendLibReader *reader, MetaBall *mb) -{ - for (int a = 0; a < mb->totcol; a++) { - BLO_read_id_address(reader, mb->id.lib, &mb->mat[a]); - } - - BLO_read_id_address(reader, mb->id.lib, &mb->ipo); // XXX deprecated - old animation system -} - -static void direct_link_mball(BlendDataReader *reader, MetaBall *mb) -{ - BLO_read_data_address(reader, &mb->adt); - BKE_animdata_blend_read_data(reader, mb->adt); - - BLO_read_pointer_array(reader, (void **)&mb->mat); - - BLO_read_list(reader, &(mb->elems)); - - BLI_listbase_clear(&mb->disp); - mb->editelems = NULL; - /* Must always be cleared (meta's don't have their own edit-data). */ - mb->needs_flush_to_id = 0; - /* mb->edit_elems.first= mb->edit_elems.last= NULL;*/ - mb->lastelem = NULL; - mb->batch_cache = NULL; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: World - * \{ */ - -static void lib_link_world(BlendLibReader *reader, World *wrld) -{ - BLO_read_id_address(reader, wrld->id.lib, &wrld->ipo); // XXX deprecated - old animation system -} - -static void direct_link_world(BlendDataReader *reader, World *wrld) -{ - BLO_read_data_address(reader, &wrld->adt); - BKE_animdata_blend_read_data(reader, wrld->adt); - - wrld->preview = direct_link_preview_image(reader, wrld->preview); - BLI_listbase_clear(&wrld->gpumaterial); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: VFont - * \{ */ - -static void lib_link_vfont(BlendLibReader *UNUSED(reader), VFont *UNUSED(vf)) -{ -} - -static void direct_link_vfont(BlendDataReader *reader, VFont *vf) -{ - vf->data = NULL; - vf->temp_pf = NULL; - vf->packedfile = direct_link_packedfile(reader, vf->packedfile); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Text - * \{ */ - -static void lib_link_text(BlendLibReader *UNUSED(reader), Text *UNUSED(text)) -{ -} - -static void direct_link_text(BlendDataReader *reader, Text *text) -{ - BLO_read_data_address(reader, &text->filepath); - - text->compiled = NULL; - -#if 0 - if (text->flags & TXT_ISEXT) { - BKE_text_reload(text); - } - /* else { */ -#endif - - BLO_read_list(reader, &text->lines); - - BLO_read_data_address(reader, &text->curl); - BLO_read_data_address(reader, &text->sell); - - LISTBASE_FOREACH (TextLine *, ln, &text->lines) { - BLO_read_data_address(reader, &ln->line); - ln->format = NULL; - - if (ln->len != (int)strlen(ln->line)) { - printf("Error loading text, line lengths differ\n"); - ln->len = strlen(ln->line); - } - } - - text->flags = (text->flags) & ~TXT_ISEXT; - - id_us_ensure_real(&text->id); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Image - * \{ */ - -static void lib_link_image(BlendLibReader *UNUSED(reader), Image *ima) -{ - /* Images have some kind of 'main' cache, when NULL we should also clear all others. */ - /* Needs to be done *after* cache pointers are restored (call to - * `foreach_cache`/`blo_cache_storage_entry_restore_in_new`), easier for now to do it in - * lib_link... */ - if (ima->cache == NULL) { - BKE_image_free_buffers(ima); - } -} - -static void direct_link_image(BlendDataReader *reader, Image *ima) -{ - BLO_read_list(reader, &ima->tiles); - - BLO_read_list(reader, &(ima->renderslots)); - if (!BLO_read_data_is_undo(reader)) { - /* We reset this last render slot index only when actually reading a file, not for undo. */ - ima->last_render_slot = ima->render_slot; - } - - BLO_read_list(reader, &(ima->views)); - BLO_read_list(reader, &(ima->packedfiles)); - - if (ima->packedfiles.first) { - LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) { - imapf->packedfile = direct_link_packedfile(reader, imapf->packedfile); - } - ima->packedfile = NULL; - } - else { - ima->packedfile = direct_link_packedfile(reader, ima->packedfile); - } - - BLI_listbase_clear(&ima->anims); - ima->preview = direct_link_preview_image(reader, ima->preview); - BLO_read_data_address(reader, &ima->stereo3d_format); - LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { - tile->ok = IMA_OK; - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Curve - * \{ */ - -static void lib_link_curve(BlendLibReader *reader, Curve *cu) -{ - for (int a = 0; a < cu->totcol; a++) { - BLO_read_id_address(reader, cu->id.lib, &cu->mat[a]); - } - - BLO_read_id_address(reader, cu->id.lib, &cu->bevobj); - BLO_read_id_address(reader, cu->id.lib, &cu->taperobj); - BLO_read_id_address(reader, cu->id.lib, &cu->textoncurve); - BLO_read_id_address(reader, cu->id.lib, &cu->vfont); - BLO_read_id_address(reader, cu->id.lib, &cu->vfontb); - BLO_read_id_address(reader, cu->id.lib, &cu->vfonti); - BLO_read_id_address(reader, cu->id.lib, &cu->vfontbi); - - BLO_read_id_address(reader, cu->id.lib, &cu->ipo); // XXX deprecated - old animation system - BLO_read_id_address(reader, cu->id.lib, &cu->key); -} - -static void switch_endian_knots(Nurb *nu) -{ - if (nu->knotsu) { - BLI_endian_switch_float_array(nu->knotsu, KNOTSU(nu)); - } - if (nu->knotsv) { - BLI_endian_switch_float_array(nu->knotsv, KNOTSV(nu)); - } -} - -static void direct_link_curve(BlendDataReader *reader, Curve *cu) -{ - BLO_read_data_address(reader, &cu->adt); - BKE_animdata_blend_read_data(reader, cu->adt); - - /* Protect against integer overflow vulnerability. */ - CLAMP(cu->len_char32, 0, INT_MAX - 4); - - BLO_read_pointer_array(reader, (void **)&cu->mat); - - BLO_read_data_address(reader, &cu->str); - BLO_read_data_address(reader, &cu->strinfo); - BLO_read_data_address(reader, &cu->tb); - - if (cu->vfont == NULL) { - BLO_read_list(reader, &(cu->nurb)); - } - else { - cu->nurb.first = cu->nurb.last = NULL; - - TextBox *tb = MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "TextBoxread"); - if (cu->tb) { - memcpy(tb, cu->tb, cu->totbox * sizeof(TextBox)); - MEM_freeN(cu->tb); - cu->tb = tb; - } - else { - cu->totbox = 1; - cu->actbox = 1; - cu->tb = tb; - cu->tb[0].w = cu->linewidth; - } - if (cu->wordspace == 0.0f) { - cu->wordspace = 1.0f; - } - } - - cu->editnurb = NULL; - cu->editfont = NULL; - cu->batch_cache = NULL; - - LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { - BLO_read_data_address(reader, &nu->bezt); - BLO_read_data_address(reader, &nu->bp); - BLO_read_data_address(reader, &nu->knotsu); - BLO_read_data_address(reader, &nu->knotsv); - if (cu->vfont == NULL) { - nu->charidx = 0; - } - - if (BLO_read_requires_endian_switch(reader)) { - switch_endian_knots(nu); - } - } - cu->texflag &= ~CU_AUTOSPACE_EVALUATED; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Texture - * \{ */ - -static void lib_link_texture(BlendLibReader *reader, Tex *tex) -{ - BLO_read_id_address(reader, tex->id.lib, &tex->ima); - BLO_read_id_address(reader, tex->id.lib, &tex->ipo); // XXX deprecated - old animation system -} - -static void direct_link_texture(BlendDataReader *reader, Tex *tex) -{ - BLO_read_data_address(reader, &tex->adt); - BKE_animdata_blend_read_data(reader, tex->adt); - - BLO_read_data_address(reader, &tex->coba); - - tex->preview = direct_link_preview_image(reader, tex->preview); - - tex->iuser.ok = 1; - tex->iuser.scene = NULL; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Material - * \{ */ - -static void lib_link_material(BlendLibReader *reader, Material *ma) -{ - BLO_read_id_address(reader, ma->id.lib, &ma->ipo); // XXX deprecated - old animation system - - /* relink grease pencil settings */ - if (ma->gp_style != NULL) { - MaterialGPencilStyle *gp_style = ma->gp_style; - if (gp_style->sima != NULL) { - BLO_read_id_address(reader, ma->id.lib, &gp_style->sima); - } - if (gp_style->ima != NULL) { - BLO_read_id_address(reader, ma->id.lib, &gp_style->ima); - } - } -} - -static void direct_link_material(BlendDataReader *reader, Material *ma) -{ - BLO_read_data_address(reader, &ma->adt); - BKE_animdata_blend_read_data(reader, ma->adt); - - ma->texpaintslot = NULL; - - ma->preview = direct_link_preview_image(reader, ma->preview); - BLI_listbase_clear(&ma->gpumaterial); - - BLO_read_data_address(reader, &ma->gp_style); -} - /** \} */ /* -------------------------------------------------------------------- */ @@ -4989,7 +4004,8 @@ static void direct_link_object(BlendDataReader *reader, Object *ob) } } - ob->preview = direct_link_preview_image(reader, ob->preview); + BLO_read_data_address(reader, &ob->preview); + BKE_previewimg_blend_read(reader, ob->preview); } static void direct_link_view_settings(BlendDataReader *reader, @@ -5131,7 +4147,8 @@ static void direct_link_collection(BlendDataReader *reader, Collection *collecti BLO_read_list(reader, &collection->gobject); BLO_read_list(reader, &collection->children); - collection->preview = direct_link_preview_image(reader, collection->preview); + BLO_read_data_address(reader, &collection->preview); + BKE_previewimg_blend_read(reader, collection->preview); collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE; collection->tag = 0; @@ -5315,7 +4332,7 @@ static bool scene_validate_setscene__liblink(Scene *sce, const int totscene) static void lib_link_scene(BlendLibReader *reader, Scene *sce) { - lib_link_keyingsets(reader, &sce->id, &sce->keyingsets); + BKE_keyingsets_blend_read_lib(reader, &sce->id, &sce->keyingsets); BLO_read_id_address(reader, sce->id.lib, &sce->camera); BLO_read_id_address(reader, sce->id.lib, &sce->world); @@ -5594,7 +4611,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) BKE_animdata_blend_read_data(reader, sce->adt); BLO_read_list(reader, &sce->keyingsets); - direct_link_keyingsets(reader, &sce->keyingsets); + BKE_keyingsets_blend_read_data(reader, &sce->keyingsets); BLO_read_data_address(reader, &sce->basact); @@ -5843,7 +4860,8 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) } } - sce->preview = direct_link_preview_image(reader, sce->preview); + BLO_read_data_address(reader, &sce->preview); + BKE_previewimg_blend_read(reader, sce->preview); BKE_curvemapping_blend_read(reader, &sce->r.mblur_shutter_curve); @@ -5882,107 +4900,6 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: Grease Pencil - * \{ */ - -/* relink's grease pencil data's refs */ -static void lib_link_gpencil(BlendLibReader *reader, bGPdata *gpd) -{ - /* Relink all data-lock linked by GP data-lock */ - /* Layers */ - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - /* Layer -> Parent References */ - BLO_read_id_address(reader, gpd->id.lib, &gpl->parent); - } - - /* materials */ - for (int a = 0; a < gpd->totcol; a++) { - BLO_read_id_address(reader, gpd->id.lib, &gpd->mat[a]); - } -} - -/* relinks grease-pencil data - used for direct_link and old file linkage */ -static void direct_link_gpencil(BlendDataReader *reader, bGPdata *gpd) -{ - /* we must firstly have some grease-pencil data to link! */ - if (gpd == NULL) { - return; - } - - /* relink animdata */ - BLO_read_data_address(reader, &gpd->adt); - BKE_animdata_blend_read_data(reader, gpd->adt); - - /* Ensure full objectmode for linked grease pencil. */ - if (gpd->id.lib != NULL) { - gpd->flag &= ~GP_DATA_STROKE_PAINTMODE; - gpd->flag &= ~GP_DATA_STROKE_EDITMODE; - gpd->flag &= ~GP_DATA_STROKE_SCULPTMODE; - gpd->flag &= ~GP_DATA_STROKE_WEIGHTMODE; - gpd->flag &= ~GP_DATA_STROKE_VERTEXMODE; - } - - /* init stroke buffer */ - gpd->runtime.sbuffer = NULL; - gpd->runtime.sbuffer_used = 0; - gpd->runtime.sbuffer_size = 0; - gpd->runtime.tot_cp_points = 0; - - /* relink palettes (old palettes deprecated, only to convert old files) */ - BLO_read_list(reader, &gpd->palettes); - if (gpd->palettes.first != NULL) { - LISTBASE_FOREACH (Palette *, palette, &gpd->palettes) { - BLO_read_list(reader, &palette->colors); - } - } - - /* materials */ - BLO_read_pointer_array(reader, (void **)&gpd->mat); - - /* relink layers */ - BLO_read_list(reader, &gpd->layers); - - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - /* relink frames */ - BLO_read_list(reader, &gpl->frames); - - BLO_read_data_address(reader, &gpl->actframe); - - gpl->runtime.icon_id = 0; - - /* Relink masks. */ - BLO_read_list(reader, &gpl->mask_layers); - - LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - /* relink strokes (and their points) */ - BLO_read_list(reader, &gpf->strokes); - - LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { - /* relink stroke points array */ - BLO_read_data_address(reader, &gps->points); - /* Relink geometry*/ - BLO_read_data_address(reader, &gps->triangles); - - /* relink stroke edit curve. */ - BLO_read_data_address(reader, &gps->editcurve); - if (gps->editcurve != NULL) { - /* relink curve point array */ - BLO_read_data_address(reader, &gps->editcurve->curve_points); - } - - /* relink weight data */ - if (gps->dvert) { - BLO_read_data_address(reader, &gps->dvert); - BKE_defvert_blend_read(reader, gps->totpoints, gps->dvert); - } - } - } - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read Screen Area/Region (Screen Data) * \{ */ @@ -6124,7 +5041,7 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area) if (v3d->gpd) { BLO_read_data_address(reader, &v3d->gpd); - direct_link_gpencil(reader, v3d->gpd); + BKE_gpencil_blend_read_data(reader, v3d->gpd); } BLO_read_data_address(reader, &v3d->localvd); @@ -6196,7 +5113,7 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area) #if 0 sima->gpd = newdataadr(fd, sima->gpd); if (sima->gpd) { - direct_link_gpencil(fd, sima->gpd); + BKE_gpencil_blend_read_data(fd, sima->gpd); } #endif } @@ -6205,7 +5122,7 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area) if (snode->gpd) { BLO_read_data_address(reader, &snode->gpd); - direct_link_gpencil(reader, snode->gpd); + BKE_gpencil_blend_read_data(reader, snode->gpd); } BLO_read_list(reader, &snode->treepath); @@ -6230,7 +5147,7 @@ static void direct_link_area(BlendDataReader *reader, ScrArea *area) #if 0 if (sseq->gpd) { sseq->gpd = newdataadr(fd, sseq->gpd); - direct_link_gpencil(fd, sseq->gpd); + BKE_gpencil_blend_read_data(fd, sseq->gpd); } #endif sseq->scopes.reference_ibuf = NULL; @@ -7154,7 +6071,8 @@ static bool direct_link_screen(BlendDataReader *reader, bScreen *screen) screen->context = NULL; screen->active_region = NULL; - screen->preview = direct_link_preview_image(reader, screen->preview); + BLO_read_data_address(reader, &screen->preview); + BKE_previewimg_blend_read(reader, screen->preview); if (!direct_link_area_map(reader, AREAMAP_FROM_SCREEN(screen))) { printf("Error reading Screen %s... removing it.\n", screen->id.name + 2); @@ -7212,7 +6130,7 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main) // printf("direct_link_library: filepath_abs %s\n", lib->filepath_abs); BlendDataReader reader = {fd}; - lib->packedfile = direct_link_packedfile(&reader, lib->packedfile); + BKE_packedfile_blend_read(&reader, &lib->packedfile); /* new main */ newmain = BKE_main_new(); @@ -7261,619 +6179,6 @@ static void fix_relpaths_library(const char *basepath, Main *main) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Read ID: Light Probe - * \{ */ - -static void lib_link_lightprobe(BlendLibReader *reader, LightProbe *prb) -{ - BLO_read_id_address(reader, prb->id.lib, &prb->visibility_grp); -} - -static void direct_link_lightprobe(BlendDataReader *reader, LightProbe *prb) -{ - BLO_read_data_address(reader, &prb->adt); - BKE_animdata_blend_read_data(reader, prb->adt); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Speaker - * \{ */ - -static void lib_link_speaker(BlendLibReader *reader, Speaker *spk) -{ - BLO_read_id_address(reader, spk->id.lib, &spk->sound); -} - -static void direct_link_speaker(BlendDataReader *reader, Speaker *spk) -{ - BLO_read_data_address(reader, &spk->adt); - BKE_animdata_blend_read_data(reader, spk->adt); - -#if 0 - spk->sound = newdataadr(fd, spk->sound); - direct_link_sound(fd, spk->sound); -#endif -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Sound - * \{ */ - -static void direct_link_sound(BlendDataReader *reader, bSound *sound) -{ - sound->tags = 0; - sound->handle = NULL; - sound->playback_handle = NULL; - - /* versioning stuff, if there was a cache, then we enable caching: */ - if (sound->cache) { - sound->flags |= SOUND_FLAGS_CACHING; - sound->cache = NULL; - } - - if (BLO_read_data_is_undo(reader)) { - sound->tags |= SOUND_TAGS_WAVEFORM_NO_RELOAD; - } - - sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock"); - BLI_spin_init(sound->spinlock); - - /* clear waveform loading flag */ - sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING; - - sound->packedfile = direct_link_packedfile(reader, sound->packedfile); - sound->newpackedfile = direct_link_packedfile(reader, sound->newpackedfile); -} - -static void lib_link_sound(BlendLibReader *reader, bSound *sound) -{ - BLO_read_id_address( - reader, sound->id.lib, &sound->ipo); // XXX deprecated - old animation system -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Movie Clip - * \{ */ - -static void direct_link_movieReconstruction(BlendDataReader *reader, - MovieTrackingReconstruction *reconstruction) -{ - BLO_read_data_address(reader, &reconstruction->cameras); -} - -static void direct_link_movieTracks(BlendDataReader *reader, ListBase *tracksbase) -{ - BLO_read_list(reader, tracksbase); - - LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { - BLO_read_data_address(reader, &track->markers); - } -} - -static void direct_link_moviePlaneTracks(BlendDataReader *reader, ListBase *plane_tracks_base) -{ - BLO_read_list(reader, plane_tracks_base); - - LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) { - BLO_read_pointer_array(reader, (void **)&plane_track->point_tracks); - for (int i = 0; i < plane_track->point_tracksnr; i++) { - BLO_read_data_address(reader, &plane_track->point_tracks[i]); - } - - BLO_read_data_address(reader, &plane_track->markers); - } -} - -static void direct_link_movieclip(BlendDataReader *reader, MovieClip *clip) -{ - MovieTracking *tracking = &clip->tracking; - - BLO_read_data_address(reader, &clip->adt); - - direct_link_movieTracks(reader, &tracking->tracks); - direct_link_moviePlaneTracks(reader, &tracking->plane_tracks); - direct_link_movieReconstruction(reader, &tracking->reconstruction); - - BLO_read_data_address(reader, &clip->tracking.act_track); - BLO_read_data_address(reader, &clip->tracking.act_plane_track); - - clip->anim = NULL; - clip->tracking_context = NULL; - clip->tracking.stats = NULL; - - /* TODO we could store those in undo cache storage as well, and preserve them instead of - * re-creating them... */ - BLI_listbase_clear(&clip->runtime.gputextures); - - /* Needed for proper versioning, will be NULL for all newer files anyway. */ - BLO_read_data_address(reader, &clip->tracking.stabilization.rot_track); - - clip->tracking.dopesheet.ok = 0; - BLI_listbase_clear(&clip->tracking.dopesheet.channels); - BLI_listbase_clear(&clip->tracking.dopesheet.coverage_segments); - - BLO_read_list(reader, &tracking->objects); - - LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { - direct_link_movieTracks(reader, &object->tracks); - direct_link_moviePlaneTracks(reader, &object->plane_tracks); - direct_link_movieReconstruction(reader, &object->reconstruction); - } -} - -static void lib_link_movieTracks(BlendLibReader *reader, MovieClip *clip, ListBase *tracksbase) -{ - LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { - BLO_read_id_address(reader, clip->id.lib, &track->gpd); - } -} - -static void lib_link_moviePlaneTracks(BlendLibReader *reader, - MovieClip *clip, - ListBase *tracksbase) -{ - LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, tracksbase) { - BLO_read_id_address(reader, clip->id.lib, &plane_track->image); - } -} - -static void lib_link_movieclip(BlendLibReader *reader, MovieClip *clip) -{ - MovieTracking *tracking = &clip->tracking; - - BLO_read_id_address(reader, clip->id.lib, &clip->gpd); - - lib_link_movieTracks(reader, clip, &tracking->tracks); - lib_link_moviePlaneTracks(reader, clip, &tracking->plane_tracks); - - LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) { - lib_link_movieTracks(reader, clip, &object->tracks); - lib_link_moviePlaneTracks(reader, clip, &object->plane_tracks); - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Masks - * \{ */ - -static void direct_link_mask(BlendDataReader *reader, Mask *mask) -{ - BLO_read_data_address(reader, &mask->adt); - - BLO_read_list(reader, &mask->masklayers); - - LISTBASE_FOREACH (MaskLayer *, masklay, &mask->masklayers) { - /* can't use newdataadr since it's a pointer within an array */ - MaskSplinePoint *act_point_search = NULL; - - BLO_read_list(reader, &masklay->splines); - - LISTBASE_FOREACH (MaskSpline *, spline, &masklay->splines) { - MaskSplinePoint *points_old = spline->points; - - BLO_read_data_address(reader, &spline->points); - - for (int i = 0; i < spline->tot_point; i++) { - MaskSplinePoint *point = &spline->points[i]; - - if (point->tot_uw) { - BLO_read_data_address(reader, &point->uw); - } - } - - /* detect active point */ - if ((act_point_search == NULL) && (masklay->act_point >= points_old) && - (masklay->act_point < points_old + spline->tot_point)) { - act_point_search = &spline->points[masklay->act_point - points_old]; - } - } - - BLO_read_list(reader, &masklay->splines_shapes); - - LISTBASE_FOREACH (MaskLayerShape *, masklay_shape, &masklay->splines_shapes) { - BLO_read_data_address(reader, &masklay_shape->data); - - if (masklay_shape->tot_vert) { - if (BLO_read_requires_endian_switch(reader)) { - BLI_endian_switch_float_array(masklay_shape->data, - masklay_shape->tot_vert * sizeof(float) * - MASK_OBJECT_SHAPE_ELEM_SIZE); - } - } - } - - BLO_read_data_address(reader, &masklay->act_spline); - masklay->act_point = act_point_search; - } -} - -static void lib_link_mask_parent(BlendLibReader *reader, Mask *mask, MaskParent *parent) -{ - BLO_read_id_address(reader, mask->id.lib, &parent->id); -} - -static void lib_link_mask(BlendLibReader *reader, Mask *mask) -{ - LISTBASE_FOREACH (MaskLayer *, masklay, &mask->masklayers) { - MaskSpline *spline; - - spline = masklay->splines.first; - while (spline) { - for (int i = 0; i < spline->tot_point; i++) { - MaskSplinePoint *point = &spline->points[i]; - - lib_link_mask_parent(reader, mask, &point->parent); - } - - lib_link_mask_parent(reader, mask, &spline->parent); - - spline = spline->next; - } - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Line Style - * \{ */ - -static void lib_link_linestyle(BlendLibReader *reader, FreestyleLineStyle *linestyle) -{ - LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) { - switch (m->type) { - case LS_MODIFIER_DISTANCE_FROM_OBJECT: { - LineStyleColorModifier_DistanceFromObject *cm = - (LineStyleColorModifier_DistanceFromObject *)m; - BLO_read_id_address(reader, linestyle->id.lib, &cm->target); - break; - } - } - } - LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->alpha_modifiers) { - switch (m->type) { - case LS_MODIFIER_DISTANCE_FROM_OBJECT: { - LineStyleAlphaModifier_DistanceFromObject *am = - (LineStyleAlphaModifier_DistanceFromObject *)m; - BLO_read_id_address(reader, linestyle->id.lib, &am->target); - break; - } - } - } - LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->thickness_modifiers) { - switch (m->type) { - case LS_MODIFIER_DISTANCE_FROM_OBJECT: { - LineStyleThicknessModifier_DistanceFromObject *tm = - (LineStyleThicknessModifier_DistanceFromObject *)m; - BLO_read_id_address(reader, linestyle->id.lib, &tm->target); - break; - } - } - } - for (int a = 0; a < MAX_MTEX; a++) { - MTex *mtex = linestyle->mtex[a]; - if (mtex) { - BLO_read_id_address(reader, linestyle->id.lib, &mtex->tex); - BLO_read_id_address(reader, linestyle->id.lib, &mtex->object); - } - } -} - -static void direct_link_linestyle_color_modifier(BlendDataReader *reader, - LineStyleModifier *modifier) -{ - switch (modifier->type) { - case LS_MODIFIER_ALONG_STROKE: { - LineStyleColorModifier_AlongStroke *m = (LineStyleColorModifier_AlongStroke *)modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_DISTANCE_FROM_CAMERA: { - LineStyleColorModifier_DistanceFromCamera *m = (LineStyleColorModifier_DistanceFromCamera *) - modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_DISTANCE_FROM_OBJECT: { - LineStyleColorModifier_DistanceFromObject *m = (LineStyleColorModifier_DistanceFromObject *) - modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_MATERIAL: { - LineStyleColorModifier_Material *m = (LineStyleColorModifier_Material *)modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_TANGENT: { - LineStyleColorModifier_Tangent *m = (LineStyleColorModifier_Tangent *)modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_NOISE: { - LineStyleColorModifier_Noise *m = (LineStyleColorModifier_Noise *)modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_CREASE_ANGLE: { - LineStyleColorModifier_CreaseAngle *m = (LineStyleColorModifier_CreaseAngle *)modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - case LS_MODIFIER_CURVATURE_3D: { - LineStyleColorModifier_Curvature_3D *m = (LineStyleColorModifier_Curvature_3D *)modifier; - BLO_read_data_address(reader, &m->color_ramp); - break; - } - } -} - -static void direct_link_linestyle_alpha_modifier(BlendDataReader *reader, - LineStyleModifier *modifier) -{ - switch (modifier->type) { - case LS_MODIFIER_ALONG_STROKE: { - LineStyleAlphaModifier_AlongStroke *m = (LineStyleAlphaModifier_AlongStroke *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_DISTANCE_FROM_CAMERA: { - LineStyleAlphaModifier_DistanceFromCamera *m = (LineStyleAlphaModifier_DistanceFromCamera *) - modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_DISTANCE_FROM_OBJECT: { - LineStyleAlphaModifier_DistanceFromObject *m = (LineStyleAlphaModifier_DistanceFromObject *) - modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_MATERIAL: { - LineStyleAlphaModifier_Material *m = (LineStyleAlphaModifier_Material *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_TANGENT: { - LineStyleAlphaModifier_Tangent *m = (LineStyleAlphaModifier_Tangent *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_NOISE: { - LineStyleAlphaModifier_Noise *m = (LineStyleAlphaModifier_Noise *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_CREASE_ANGLE: { - LineStyleAlphaModifier_CreaseAngle *m = (LineStyleAlphaModifier_CreaseAngle *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_CURVATURE_3D: { - LineStyleAlphaModifier_Curvature_3D *m = (LineStyleAlphaModifier_Curvature_3D *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - } -} - -static void direct_link_linestyle_thickness_modifier(BlendDataReader *reader, - LineStyleModifier *modifier) -{ - switch (modifier->type) { - case LS_MODIFIER_ALONG_STROKE: { - LineStyleThicknessModifier_AlongStroke *m = (LineStyleThicknessModifier_AlongStroke *) - modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_DISTANCE_FROM_CAMERA: { - LineStyleThicknessModifier_DistanceFromCamera *m = - (LineStyleThicknessModifier_DistanceFromCamera *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_DISTANCE_FROM_OBJECT: { - LineStyleThicknessModifier_DistanceFromObject *m = - (LineStyleThicknessModifier_DistanceFromObject *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_MATERIAL: { - LineStyleThicknessModifier_Material *m = (LineStyleThicknessModifier_Material *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_TANGENT: { - LineStyleThicknessModifier_Tangent *m = (LineStyleThicknessModifier_Tangent *)modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_CREASE_ANGLE: { - LineStyleThicknessModifier_CreaseAngle *m = (LineStyleThicknessModifier_CreaseAngle *) - modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - case LS_MODIFIER_CURVATURE_3D: { - LineStyleThicknessModifier_Curvature_3D *m = (LineStyleThicknessModifier_Curvature_3D *) - modifier; - BLO_read_data_address(reader, &m->curve); - BKE_curvemapping_blend_read(reader, m->curve); - break; - } - } -} - -static void direct_link_linestyle_geometry_modifier(BlendDataReader *UNUSED(reader), - LineStyleModifier *UNUSED(modifier)) -{ -} - -static void direct_link_linestyle(BlendDataReader *reader, FreestyleLineStyle *linestyle) -{ - BLO_read_data_address(reader, &linestyle->adt); - BKE_animdata_blend_read_data(reader, linestyle->adt); - BLO_read_list(reader, &linestyle->color_modifiers); - LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->color_modifiers) { - direct_link_linestyle_color_modifier(reader, modifier); - } - BLO_read_list(reader, &linestyle->alpha_modifiers); - LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->alpha_modifiers) { - direct_link_linestyle_alpha_modifier(reader, modifier); - } - BLO_read_list(reader, &linestyle->thickness_modifiers); - LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->thickness_modifiers) { - direct_link_linestyle_thickness_modifier(reader, modifier); - } - BLO_read_list(reader, &linestyle->geometry_modifiers); - LISTBASE_FOREACH (LineStyleModifier *, modifier, &linestyle->geometry_modifiers) { - direct_link_linestyle_geometry_modifier(reader, modifier); - } - for (int a = 0; a < MAX_MTEX; a++) { - BLO_read_data_address(reader, &linestyle->mtex[a]); - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Hair - * \{ */ - -static void lib_link_hair(BlendLibReader *reader, Hair *hair) -{ - for (int a = 0; a < hair->totcol; a++) { - BLO_read_id_address(reader, hair->id.lib, &hair->mat[a]); - } -} - -static void direct_link_hair(BlendDataReader *reader, Hair *hair) -{ - BLO_read_data_address(reader, &hair->adt); - BKE_animdata_blend_read_data(reader, hair->adt); - - /* Geometry */ - CustomData_blend_read(reader, &hair->pdata, hair->totpoint); - CustomData_blend_read(reader, &hair->cdata, hair->totcurve); - BKE_hair_update_customdata_pointers(hair); - - /* Materials */ - BLO_read_pointer_array(reader, (void **)&hair->mat); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Point Cloud - * \{ */ - -static void lib_link_pointcloud(BlendLibReader *reader, PointCloud *pointcloud) -{ - for (int a = 0; a < pointcloud->totcol; a++) { - BLO_read_id_address(reader, pointcloud->id.lib, &pointcloud->mat[a]); - } -} - -static void direct_link_pointcloud(BlendDataReader *reader, PointCloud *pointcloud) -{ - BLO_read_data_address(reader, &pointcloud->adt); - BKE_animdata_blend_read_data(reader, pointcloud->adt); - - /* Geometry */ - CustomData_blend_read(reader, &pointcloud->pdata, pointcloud->totpoint); - BKE_pointcloud_update_customdata_pointers(pointcloud); - - /* Materials */ - BLO_read_pointer_array(reader, (void **)&pointcloud->mat); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Volume - * \{ */ - -static void lib_link_volume(BlendLibReader *reader, Volume *volume) -{ - /* Needs to be done *after* cache pointers are restored (call to - * `foreach_cache`/`blo_cache_storage_entry_restore_in_new`), easier for now to do it in - * lib_link... */ - BKE_volume_init_grids(volume); - - for (int a = 0; a < volume->totcol; a++) { - BLO_read_id_address(reader, volume->id.lib, &volume->mat[a]); - } -} - -static void direct_link_volume(BlendDataReader *reader, Volume *volume) -{ - BLO_read_data_address(reader, &volume->adt); - BKE_animdata_blend_read_data(reader, volume->adt); - - volume->packedfile = direct_link_packedfile(reader, volume->packedfile); - volume->runtime.frame = 0; - - /* materials */ - BLO_read_pointer_array(reader, (void **)&volume->mat); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Read ID: Simulation - * \{ */ - -static void lib_link_simulation(BlendLibReader *reader, Simulation *simulation) -{ - LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) { - BLO_read_id_address(reader, simulation->id.lib, &dependency->id); - } -} - -static void direct_link_simulation(BlendDataReader *reader, Simulation *simulation) -{ - BLO_read_data_address(reader, &simulation->adt); - BKE_animdata_blend_read_data(reader, simulation->adt); - - BLO_read_list(reader, &simulation->states); - LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { - BLO_read_data_address(reader, &state->name); - BLO_read_data_address(reader, &state->type); - if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_SIMULATION)) { - ParticleSimulationState *particle_state = (ParticleSimulationState *)state; - CustomData_blend_read(reader, &particle_state->attributes, particle_state->tot_particles); - } - } - - BLO_read_list(reader, &simulation->dependencies); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Read Library Data Block * \{ */ @@ -8032,110 +6337,52 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID * case ID_OB: direct_link_object(&reader, (Object *)id); break; - case ID_CU: - direct_link_curve(&reader, (Curve *)id); - break; - case ID_MB: - direct_link_mball(&reader, (MetaBall *)id); - break; - case ID_MA: - direct_link_material(&reader, (Material *)id); - break; - case ID_TE: - direct_link_texture(&reader, (Tex *)id); - break; - case ID_IM: - direct_link_image(&reader, (Image *)id); - break; - case ID_LA: - direct_link_light(&reader, (Light *)id); - break; - case ID_VF: - direct_link_vfont(&reader, (VFont *)id); - break; - case ID_TXT: - direct_link_text(&reader, (Text *)id); - break; case ID_IP: direct_link_ipo(&reader, (Ipo *)id); break; - case ID_KE: - direct_link_key(&reader, (Key *)id); - break; - case ID_WO: - direct_link_world(&reader, (World *)id); - break; case ID_LI: direct_link_library(fd, (Library *)id, main); break; - case ID_CA: - direct_link_camera(&reader, (Camera *)id); - break; - case ID_SPK: - direct_link_speaker(&reader, (Speaker *)id); - break; - case ID_SO: - direct_link_sound(&reader, (bSound *)id); - break; - case ID_LP: - direct_link_lightprobe(&reader, (LightProbe *)id); - break; case ID_GR: direct_link_collection(&reader, (Collection *)id); break; - case ID_AR: - direct_link_armature(&reader, (bArmature *)id); - break; - case ID_AC: - direct_link_action(&reader, (bAction *)id); - break; - case ID_NT: - direct_link_nodetree(&reader, (bNodeTree *)id); - break; - case ID_BR: - direct_link_brush(&reader, (Brush *)id); - break; case ID_PA: direct_link_particlesettings(&reader, (ParticleSettings *)id); break; - case ID_GD: - direct_link_gpencil(&reader, (bGPdata *)id); - break; - case ID_MC: - direct_link_movieclip(&reader, (MovieClip *)id); - break; - case ID_MSK: - direct_link_mask(&reader, (Mask *)id); + case ID_WS: + direct_link_workspace(&reader, (WorkSpace *)id, main); break; + case ID_ME: + case ID_LT: + case ID_AC: + case ID_NT: case ID_LS: - direct_link_linestyle(&reader, (FreestyleLineStyle *)id); - break; + case ID_TXT: + case ID_VF: + case ID_MC: case ID_PAL: - direct_link_palette(&reader, (Palette *)id); - break; case ID_PC: - direct_link_paint_curve(&reader, (PaintCurve *)id); - break; - case ID_CF: - direct_link_cachefile(&reader, (CacheFile *)id); - break; - case ID_WS: - direct_link_workspace(&reader, (WorkSpace *)id, main); - break; + case ID_BR: + case ID_IM: + case ID_LA: + case ID_MA: + case ID_MB: + case ID_CU: + case ID_CA: + case ID_WO: + case ID_MSK: + case ID_SPK: + case ID_AR: + case ID_LP: + case ID_KE: + case ID_TE: + case ID_GD: case ID_HA: - direct_link_hair(&reader, (Hair *)id); - break; case ID_PT: - direct_link_pointcloud(&reader, (PointCloud *)id); - break; case ID_VO: - direct_link_volume(&reader, (Volume *)id); - break; case ID_SIM: - direct_link_simulation(&reader, (Simulation *)id); - break; - case ID_ME: - case ID_LT: + case ID_SO: + case ID_CF: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -8741,9 +6988,6 @@ static void lib_link_all(FileData *fd, Main *bmain) * Please keep order of entries in that switch matching that order, it's easier to quickly see * whether something is wrong then. */ switch (GS(id->name)) { - case ID_MSK: - lib_link_mask(&reader, (Mask *)id); - break; case ID_WM: lib_link_windowmanager(&reader, (wmWindowManager *)id); break; @@ -8754,114 +6998,58 @@ static void lib_link_all(FileData *fd, Main *bmain) case ID_SCE: lib_link_scene(&reader, (Scene *)id); break; - case ID_LS: - lib_link_linestyle(&reader, (FreestyleLineStyle *)id); - break; case ID_OB: lib_link_object(&reader, (Object *)id); break; case ID_SCR: - /* DO NOT skip screens here, - * 3D viewport may contains pointers to other ID data (like bgpic)! See T41411. */ + /* DO NOT skip screens here, 3D viewport may contains pointers + * to other ID data (like #View3D.ob_center)! See T41411. */ lib_link_screen(&reader, (bScreen *)id); break; - case ID_MC: - lib_link_movieclip(&reader, (MovieClip *)id); - break; - case ID_WO: - lib_link_world(&reader, (World *)id); - break; - case ID_LP: - lib_link_lightprobe(&reader, (LightProbe *)id); - break; - case ID_SPK: - lib_link_speaker(&reader, (Speaker *)id); - break; case ID_PA: lib_link_particlesettings(&reader, (ParticleSettings *)id); break; - case ID_PC: - lib_link_paint_curve(&reader, (PaintCurve *)id); - break; - case ID_BR: - lib_link_brush(&reader, (Brush *)id); - break; case ID_GR: lib_link_collection(&reader, (Collection *)id); break; - case ID_SO: - lib_link_sound(&reader, (bSound *)id); - break; - case ID_TXT: - lib_link_text(&reader, (Text *)id); + case ID_IP: + /* XXX deprecated... still needs to be maintained for version patches still. */ + lib_link_ipo(&reader, (Ipo *)id); break; - case ID_CA: - lib_link_camera(&reader, (Camera *)id); + case ID_LI: + lib_link_library(&reader, (Library *)id); /* Only init users. */ break; + case ID_ME: + case ID_LT: + case ID_AC: + case ID_NT: + case ID_LS: + case ID_TXT: + case ID_VF: + case ID_MC: + case ID_PAL: + case ID_PC: + case ID_BR: + case ID_IM: case ID_LA: - lib_link_light(&reader, (Light *)id); - break; + case ID_MA: case ID_MB: - lib_link_mball(&reader, (MetaBall *)id); - break; case ID_CU: - lib_link_curve(&reader, (Curve *)id); - break; - case ID_CF: - lib_link_cachefiles(&reader, (CacheFile *)id); - break; + case ID_CA: + case ID_WO: + case ID_MSK: + case ID_SPK: case ID_AR: - lib_link_armature(&reader, (bArmature *)id); - break; - case ID_VF: - lib_link_vfont(&reader, (VFont *)id); - break; + case ID_LP: + case ID_KE: + case ID_TE: + case ID_GD: case ID_HA: - lib_link_hair(&reader, (Hair *)id); - break; case ID_PT: - lib_link_pointcloud(&reader, (PointCloud *)id); - break; case ID_VO: - lib_link_volume(&reader, (Volume *)id); - break; - case ID_MA: - lib_link_material(&reader, (Material *)id); - break; - case ID_TE: - lib_link_texture(&reader, (Tex *)id); - break; - case ID_IM: - lib_link_image(&reader, (Image *)id); - break; - case ID_NT: - /* Has to be done after node users (scene/materials/...), this will verify group nodes. */ - lib_link_nodetree(&reader, (bNodeTree *)id); - break; - case ID_GD: - lib_link_gpencil(&reader, (bGPdata *)id); - break; - case ID_PAL: - lib_link_palette(&reader, (Palette *)id); - break; - case ID_KE: - lib_link_key(&reader, (Key *)id); - break; - case ID_AC: - lib_link_action(&reader, (bAction *)id); - break; case ID_SIM: - lib_link_simulation(&reader, (Simulation *)id); - break; - case ID_IP: - /* XXX deprecated... still needs to be maintained for version patches still. */ - lib_link_ipo(&reader, (Ipo *)id); - break; - case ID_LI: - lib_link_library(&reader, (Library *)id); /* Only init users. */ - break; - case ID_ME: - case ID_LT: + case ID_SO: + case ID_CF: /* Do nothing. Handled by IDTypeInfo callback. */ break; } @@ -9445,7 +7633,6 @@ static void expand_constraint_channels(BlendExpander *expander, ListBase *chanba } static void expand_id(BlendExpander *expander, ID *id); -static void expand_nodetree(BlendExpander *expander, bNodeTree *ntree); static void expand_collection(BlendExpander *expander, Collection *collection); static void expand_id_embedded_id(BlendExpander *expander, ID *id) @@ -9454,7 +7641,7 @@ static void expand_id_embedded_id(BlendExpander *expander, ID *id) bNodeTree *nodetree = ntreeFromID(id); if (nodetree != NULL) { expand_id(expander, &nodetree->id); - expand_nodetree(expander, nodetree); + ntreeBlendReadExpand(expander, nodetree); } if (GS(id->name) == ID_SCE) { @@ -9483,35 +7670,6 @@ static void expand_id(BlendExpander *expander, ID *id) expand_id_embedded_id(expander, id); } -static void expand_action(BlendExpander *expander, bAction *act) -{ - // XXX deprecated - old animation system -------------- - LISTBASE_FOREACH (bActionChannel *, chan, &act->chanbase) { - BLO_expand(expander, chan->ipo); - expand_constraint_channels(expander, &chan->constraintChannels); - } - // --------------------------------------------------- - - /* F-Curves in Action */ - BKE_fcurve_blend_read_expand(expander, &act->curves); - - LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { - if (marker->camera) { - BLO_expand(expander, marker->camera); - } - } -} - -static void expand_keyingsets(BlendExpander *expander, ListBase *list) -{ - /* expand the ID-pointers in KeyingSets's paths */ - LISTBASE_FOREACH (KeyingSet *, ks, list) { - LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { - BLO_expand(expander, ksp->id); - } - } -} - static void expand_particlesettings(BlendExpander *expander, ParticleSettings *part) { BLO_expand(expander, part->instance_object); @@ -9577,136 +7735,6 @@ static void expand_collection(BlendExpander *expander, Collection *collection) #endif } -static void expand_key(BlendExpander *expander, Key *key) -{ - BLO_expand(expander, key->ipo); // XXX deprecated - old animation system -} - -static void expand_node_socket(BlendExpander *expander, bNodeSocket *sock) -{ - IDP_BlendReadExpand(expander, sock->prop); - - if (sock->default_value != NULL) { - - switch ((eNodeSocketDatatype)sock->type) { - case SOCK_OBJECT: { - bNodeSocketValueObject *default_value = sock->default_value; - BLO_expand(expander, default_value->value); - break; - } - case SOCK_IMAGE: { - bNodeSocketValueImage *default_value = sock->default_value; - BLO_expand(expander, default_value->value); - break; - } - case SOCK_FLOAT: - case SOCK_VECTOR: - case SOCK_RGBA: - case SOCK_BOOLEAN: - case SOCK_INT: - case SOCK_STRING: - case __SOCK_MESH: - case SOCK_CUSTOM: - case SOCK_SHADER: - case SOCK_EMITTERS: - case SOCK_EVENTS: - case SOCK_FORCES: - case SOCK_CONTROL_FLOW: - break; - } - } -} - -static void expand_node_sockets(BlendExpander *expander, ListBase *sockets) -{ - LISTBASE_FOREACH (bNodeSocket *, sock, sockets) { - expand_node_socket(expander, sock); - } -} - -static void expand_nodetree(BlendExpander *expander, bNodeTree *ntree) -{ - if (ntree->gpd) { - BLO_expand(expander, ntree->gpd); - } - - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - if (node->id && node->type != CMP_NODE_R_LAYERS) { - BLO_expand(expander, node->id); - } - - IDP_BlendReadExpand(expander, node->prop); - - expand_node_sockets(expander, &node->inputs); - expand_node_sockets(expander, &node->outputs); - } - - expand_node_sockets(expander, &ntree->inputs); - expand_node_sockets(expander, &ntree->outputs); -} - -static void expand_texture(BlendExpander *expander, Tex *tex) -{ - BLO_expand(expander, tex->ima); - BLO_expand(expander, tex->ipo); // XXX deprecated - old animation system -} - -static void expand_brush(BlendExpander *expander, Brush *brush) -{ - BLO_expand(expander, brush->mtex.tex); - BLO_expand(expander, brush->mask_mtex.tex); - BLO_expand(expander, brush->clone.image); - BLO_expand(expander, brush->paint_curve); - if (brush->gpencil_settings != NULL) { - BLO_expand(expander, brush->gpencil_settings->material); - } -} - -static void expand_material(BlendExpander *expander, Material *ma) -{ - BLO_expand(expander, ma->ipo); // XXX deprecated - old animation system - - if (ma->gp_style) { - MaterialGPencilStyle *gp_style = ma->gp_style; - BLO_expand(expander, gp_style->sima); - BLO_expand(expander, gp_style->ima); - } -} - -static void expand_light(BlendExpander *expander, Light *la) -{ - BLO_expand(expander, la->ipo); // XXX deprecated - old animation system -} - -static void expand_world(BlendExpander *expander, World *wrld) -{ - BLO_expand(expander, wrld->ipo); // XXX deprecated - old animation system -} - -static void expand_mball(BlendExpander *expander, MetaBall *mb) -{ - for (int a = 0; a < mb->totcol; a++) { - BLO_expand(expander, mb->mat[a]); - } -} - -static void expand_curve(BlendExpander *expander, Curve *cu) -{ - for (int a = 0; a < cu->totcol; a++) { - BLO_expand(expander, cu->mat[a]); - } - - BLO_expand(expander, cu->vfont); - BLO_expand(expander, cu->vfontb); - BLO_expand(expander, cu->vfonti); - BLO_expand(expander, cu->vfontbi); - BLO_expand(expander, cu->key); - BLO_expand(expander, cu->ipo); // XXX deprecated - old animation system - BLO_expand(expander, cu->bevobj); - BLO_expand(expander, cu->taperobj); - BLO_expand(expander, cu->textoncurve); -} - /* callback function used to expand constraint ID-links */ static void expand_constraint_cb(bConstraint *UNUSED(con), ID **idpoin, @@ -9742,22 +7770,6 @@ static void expand_pose(BlendExpander *expander, bPose *pose) } } -static void expand_bones(BlendExpander *expander, Bone *bone) -{ - IDP_BlendReadExpand(expander, bone->prop); - - LISTBASE_FOREACH (Bone *, curBone, &bone->childbase) { - expand_bones(expander, curBone); - } -} - -static void expand_armature(BlendExpander *expander, bArmature *arm) -{ - LISTBASE_FOREACH (Bone *, curBone, &arm->bonebase) { - expand_bones(expander, curBone); - } -} - static void expand_object_expandModifiers(void *userData, Object *UNUSED(ob), ID **idpoin, @@ -9869,7 +7881,7 @@ static void expand_scene(BlendExpander *expander, Scene *sce) BLO_expand(expander, sce->camera); BLO_expand(expander, sce->world); - expand_keyingsets(expander, &sce->keyingsets); + BKE_keyingsets_blend_read_expand(expander, &sce->keyingsets); if (sce->set) { BLO_expand(expander, sce->set); @@ -9965,100 +7977,6 @@ static void expand_scene(BlendExpander *expander, Scene *sce) } } -static void expand_camera(BlendExpander *expander, Camera *ca) -{ - BLO_expand(expander, ca->ipo); // XXX deprecated - old animation system - - LISTBASE_FOREACH (CameraBGImage *, bgpic, &ca->bg_images) { - if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) { - BLO_expand(expander, bgpic->ima); - } - else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) { - BLO_expand(expander, bgpic->ima); - } - } -} - -static void expand_cachefile(BlendExpander *UNUSED(expander), CacheFile *UNUSED(cache_file)) -{ -} - -static void expand_speaker(BlendExpander *expander, Speaker *spk) -{ - BLO_expand(expander, spk->sound); -} - -static void expand_sound(BlendExpander *expander, bSound *snd) -{ - BLO_expand(expander, snd->ipo); // XXX deprecated - old animation system -} - -static void expand_lightprobe(BlendExpander *UNUSED(expander), LightProbe *UNUSED(prb)) -{ -} - -static void expand_movieclip(BlendExpander *UNUSED(expander), MovieClip *UNUSED(clip)) -{ -} - -static void expand_mask_parent(BlendExpander *expander, MaskParent *parent) -{ - if (parent->id) { - BLO_expand(expander, parent->id); - } -} - -static void expand_mask(BlendExpander *expander, Mask *mask) -{ - LISTBASE_FOREACH (MaskLayer *, mask_layer, &mask->masklayers) { - LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { - for (int i = 0; i < spline->tot_point; i++) { - MaskSplinePoint *point = &spline->points[i]; - expand_mask_parent(expander, &point->parent); - } - - expand_mask_parent(expander, &spline->parent); - } - } -} - -static void expand_linestyle(BlendExpander *expander, FreestyleLineStyle *linestyle) -{ - for (int a = 0; a < MAX_MTEX; a++) { - if (linestyle->mtex[a]) { - BLO_expand(expander, linestyle->mtex[a]->tex); - BLO_expand(expander, linestyle->mtex[a]->object); - } - } - - LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->color_modifiers) { - if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { - BLO_expand(expander, ((LineStyleColorModifier_DistanceFromObject *)m)->target); - } - } - LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->alpha_modifiers) { - if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { - BLO_expand(expander, ((LineStyleAlphaModifier_DistanceFromObject *)m)->target); - } - } - LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->thickness_modifiers) { - if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { - BLO_expand(expander, ((LineStyleThicknessModifier_DistanceFromObject *)m)->target); - } - } -} - -static void expand_gpencil(BlendExpander *expander, bGPdata *gpd) -{ - LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { - BLO_expand(expander, gpl->parent); - } - - for (int a = 0; a < gpd->totcol; a++) { - BLO_expand(expander, gpd->mat[a]); - } -} - static void expand_workspace(BlendExpander *expander, WorkSpace *workspace) { LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) { @@ -10066,34 +7984,6 @@ static void expand_workspace(BlendExpander *expander, WorkSpace *workspace) } } -static void expand_hair(BlendExpander *expander, Hair *hair) -{ - for (int a = 0; a < hair->totcol; a++) { - BLO_expand(expander, hair->mat[a]); - } -} - -static void expand_pointcloud(BlendExpander *expander, PointCloud *pointcloud) -{ - for (int a = 0; a < pointcloud->totcol; a++) { - BLO_expand(expander, pointcloud->mat[a]); - } -} - -static void expand_volume(BlendExpander *expander, Volume *volume) -{ - for (int a = 0; a < volume->totcol; a++) { - BLO_expand(expander, volume->mat[a]); - } -} - -static void expand_simulation(BlendExpander *expander, Simulation *simulation) -{ - LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) { - BLO_expand(expander, dependency->id); - } -} - /** * Set the callback func used over all ID data found by \a BLO_expand_main func. * @@ -10140,93 +8030,21 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) case ID_OB: expand_object(&expander, (Object *)id); break; - case ID_CU: - expand_curve(&expander, (Curve *)id); - break; - case ID_MB: - expand_mball(&expander, (MetaBall *)id); - break; case ID_SCE: expand_scene(&expander, (Scene *)id); break; - case ID_MA: - expand_material(&expander, (Material *)id); - break; - case ID_TE: - expand_texture(&expander, (Tex *)id); - break; - case ID_WO: - expand_world(&expander, (World *)id); - break; - case ID_LA: - expand_light(&expander, (Light *)id); - break; - case ID_KE: - expand_key(&expander, (Key *)id); - break; - case ID_CA: - expand_camera(&expander, (Camera *)id); - break; - case ID_SPK: - expand_speaker(&expander, (Speaker *)id); - break; - case ID_SO: - expand_sound(&expander, (bSound *)id); - break; - case ID_LP: - expand_lightprobe(&expander, (LightProbe *)id); - break; - case ID_AR: - expand_armature(&expander, (bArmature *)id); - break; - case ID_AC: - expand_action(&expander, (bAction *)id); // XXX deprecated - old animation system - break; case ID_GR: expand_collection(&expander, (Collection *)id); break; - case ID_NT: - expand_nodetree(&expander, (bNodeTree *)id); - break; - case ID_BR: - expand_brush(&expander, (Brush *)id); - break; case ID_IP: expand_ipo(&expander, (Ipo *)id); // XXX deprecated - old animation system break; case ID_PA: expand_particlesettings(&expander, (ParticleSettings *)id); break; - case ID_MC: - expand_movieclip(&expander, (MovieClip *)id); - break; - case ID_MSK: - expand_mask(&expander, (Mask *)id); - break; - case ID_LS: - expand_linestyle(&expander, (FreestyleLineStyle *)id); - break; - case ID_GD: - expand_gpencil(&expander, (bGPdata *)id); - break; - case ID_CF: - expand_cachefile(&expander, (CacheFile *)id); - break; case ID_WS: expand_workspace(&expander, (WorkSpace *)id); break; - case ID_HA: - expand_hair(&expander, (Hair *)id); - break; - case ID_PT: - expand_pointcloud(&expander, (PointCloud *)id); - break; - case ID_VO: - expand_volume(&expander, (Volume *)id); - break; - case ID_SIM: - expand_simulation(&expander, (Simulation *)id); - break; default: break; } diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c index 6aa7de06277..3be814a67c1 100644 --- a/source/blender/blenloader/intern/versioning_290.c +++ b/source/blender/blenloader/intern/versioning_290.c @@ -31,8 +31,10 @@ #include "DNA_genfile.h" #include "DNA_gpencil_modifier_types.h" #include "DNA_gpencil_types.h" +#include "DNA_hair_types.h" #include "DNA_modifier_types.h" #include "DNA_object_types.h" +#include "DNA_pointcloud_types.h" #include "DNA_rigidbody_types.h" #include "DNA_screen_types.h" #include "DNA_shader_fx_types.h" @@ -251,6 +253,25 @@ static void panels_remove_x_closed_flag_recursive(Panel *panel) } } +static void do_versions_point_attributes(CustomData *pdata) +{ + /* Change to generic named float/float3 attributes. */ + const int CD_LOCATION = 43; + const int CD_RADIUS = 44; + + for (int i = 0; i < pdata->totlayer; i++) { + CustomDataLayer *layer = &pdata->layers[i]; + if (layer->type == CD_LOCATION) { + STRNCPY(layer->name, "Position"); + layer->type = CD_PROP_FLOAT3; + } + else if (layer->type == CD_RADIUS) { + STRNCPY(layer->name, "Radius"); + layer->type = CD_PROP_FLOAT; + } + } +} + void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain) { UNUSED_VARS(fd); @@ -555,6 +576,27 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain) } } + /* Hair and PointCloud attributes. */ + for (Hair *hair = bmain->hairs.first; hair != NULL; hair = hair->id.next) { + do_versions_point_attributes(&hair->pdata); + } + for (PointCloud *pointcloud = bmain->pointclouds.first; pointcloud != NULL; + pointcloud = pointcloud->id.next) { + do_versions_point_attributes(&pointcloud->pdata); + } + + /* Show outliner mode column by default. */ + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, space, &area->spacedata) { + if (space->spacetype == SPACE_OUTLINER) { + SpaceOutliner *space_outliner = (SpaceOutliner *)space; + + space_outliner->flag |= SO_MODE_COLUMN; + } + } + } + } /* Keep this block, even when empty. */ /* Init grease pencil default curve resolution. */ diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c index d04907872b7..de4cff0101d 100644 --- a/source/blender/blenloader/intern/versioning_userdef.c +++ b/source/blender/blenloader/intern/versioning_userdef.c @@ -233,6 +233,8 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme) * the outliner's, and it's less disruptive to just copy them. */ copy_v4_v4_uchar(btheme->space_file.back, btheme->space_outliner.back); copy_v4_v4_uchar(btheme->space_file.row_alternate, btheme->space_outliner.row_alternate); + + FROM_DEFAULT_V4_UCHAR(space_image.grid); } #undef FROM_DEFAULT_V4_UCHAR diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index a0245346771..44a875cac4e 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -95,9 +95,7 @@ #include "DNA_anim_types.h" #include "DNA_armature_types.h" -#include "DNA_brush_types.h" #include "DNA_cachefile_types.h" -#include "DNA_camera_types.h" #include "DNA_cloth_types.h" #include "DNA_collection_types.h" #include "DNA_constraint_types.h" @@ -106,45 +104,24 @@ #include "DNA_fileglobal_types.h" #include "DNA_fluid_types.h" #include "DNA_genfile.h" -#include "DNA_gpencil_modifier_types.h" #include "DNA_gpencil_types.h" -#include "DNA_hair_types.h" -#include "DNA_key_types.h" -#include "DNA_lattice_types.h" -#include "DNA_layer_types.h" -#include "DNA_light_types.h" #include "DNA_lightprobe_types.h" -#include "DNA_linestyle_types.h" -#include "DNA_mask_types.h" -#include "DNA_material_types.h" -#include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "DNA_meta_types.h" #include "DNA_movieclip_types.h" -#include "DNA_node_types.h" #include "DNA_object_force_types.h" #include "DNA_object_types.h" -#include "DNA_packedFile_types.h" #include "DNA_particle_types.h" #include "DNA_pointcache_types.h" -#include "DNA_pointcloud_types.h" #include "DNA_rigidbody_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_sdna_types.h" #include "DNA_sequence_types.h" #include "DNA_shader_fx_types.h" -#include "DNA_simulation_types.h" -#include "DNA_sound_types.h" #include "DNA_space_types.h" -#include "DNA_speaker_types.h" -#include "DNA_text_types.h" -#include "DNA_vfont_types.h" #include "DNA_view3d_types.h" -#include "DNA_volume_types.h" #include "DNA_windowmanager_types.h" #include "DNA_workspace_types.h" -#include "DNA_world_types.h" #include "BLI_bitmap.h" #include "BLI_blenlib.h" @@ -153,19 +130,20 @@ #include "BKE_action.h" #include "BKE_anim_data.h" +#include "BKE_animsys.h" #include "BKE_armature.h" #include "BKE_blender_version.h" #include "BKE_bpath.h" #include "BKE_collection.h" #include "BKE_colortools.h" #include "BKE_constraint.h" -#include "BKE_curve.h" #include "BKE_curveprofile.h" #include "BKE_deform.h" #include "BKE_fcurve.h" #include "BKE_fcurve_driver.h" #include "BKE_global.h" // for G #include "BKE_gpencil_modifier.h" +#include "BKE_icons.h" #include "BKE_idprop.h" #include "BKE_idtype.h" #include "BKE_layer.h" @@ -175,6 +153,7 @@ #include "BKE_modifier.h" #include "BKE_node.h" #include "BKE_object.h" +#include "BKE_packedFile.h" #include "BKE_pointcache.h" #include "BKE_report.h" #include "BKE_sequencer.h" @@ -659,242 +638,6 @@ static void writelist_id(WriteData *wd, int filecode, const char *structname, co * These functions are used by blender's .blend system for file saving/loading. * \{ */ -static void write_previews(BlendWriter *writer, const PreviewImage *prv_orig) -{ - /* Note we write previews also for undo steps. It takes up some memory, - * but not doing so would causes all previews to be re-rendered after - * undo which is too expensive. */ - if (prv_orig) { - PreviewImage prv = *prv_orig; - - /* don't write out large previews if not requested */ - if (!(U.flag & USER_SAVE_PREVIEWS)) { - prv.w[1] = 0; - prv.h[1] = 0; - prv.rect[1] = NULL; - } - BLO_write_struct_at_address(writer, PreviewImage, prv_orig, &prv); - if (prv.rect[0]) { - BLO_write_uint32_array(writer, prv.w[0] * prv.h[0], prv.rect[0]); - } - if (prv.rect[1]) { - BLO_write_uint32_array(writer, prv.w[1] * prv.h[1], prv.rect[1]); - } - } -} - -static void write_action(BlendWriter *writer, bAction *act, const void *id_address) -{ - if (act->id.us > 0 || BLO_write_is_undo(writer)) { - BLO_write_id_struct(writer, bAction, id_address, &act->id); - BKE_id_blend_write(writer, &act->id); - - BKE_fcurve_blend_write(writer, &act->curves); - - LISTBASE_FOREACH (bActionGroup *, grp, &act->groups) { - BLO_write_struct(writer, bActionGroup, grp); - } - - LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { - BLO_write_struct(writer, TimeMarker, marker); - } - } -} - -static void write_keyingsets(BlendWriter *writer, ListBase *list) -{ - LISTBASE_FOREACH (KeyingSet *, ks, list) { - /* KeyingSet */ - BLO_write_struct(writer, KeyingSet, ks); - - /* Paths */ - LISTBASE_FOREACH (KS_Path *, ksp, &ks->paths) { - /* Path */ - BLO_write_struct(writer, KS_Path, ksp); - - if (ksp->rna_path) { - BLO_write_string(writer, ksp->rna_path); - } - } - } -} - -static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *sock) -{ - if (sock->default_value == NULL) { - return; - } - - switch ((eNodeSocketDatatype)sock->type) { - case SOCK_FLOAT: - BLO_write_struct(writer, bNodeSocketValueFloat, sock->default_value); - break; - case SOCK_VECTOR: - BLO_write_struct(writer, bNodeSocketValueVector, sock->default_value); - break; - case SOCK_RGBA: - BLO_write_struct(writer, bNodeSocketValueRGBA, sock->default_value); - break; - case SOCK_BOOLEAN: - BLO_write_struct(writer, bNodeSocketValueBoolean, sock->default_value); - break; - case SOCK_INT: - BLO_write_struct(writer, bNodeSocketValueInt, sock->default_value); - break; - case SOCK_STRING: - BLO_write_struct(writer, bNodeSocketValueString, sock->default_value); - break; - case SOCK_OBJECT: - BLO_write_struct(writer, bNodeSocketValueObject, sock->default_value); - break; - case SOCK_IMAGE: - BLO_write_struct(writer, bNodeSocketValueImage, sock->default_value); - break; - case __SOCK_MESH: - case SOCK_CUSTOM: - case SOCK_SHADER: - case SOCK_EMITTERS: - case SOCK_EVENTS: - case SOCK_FORCES: - case SOCK_CONTROL_FLOW: - BLI_assert(false); - break; - } -} - -static void write_node_socket(BlendWriter *writer, bNodeSocket *sock) -{ - /* actual socket writing */ - BLO_write_struct(writer, bNodeSocket, sock); - - if (sock->prop) { - IDP_BlendWrite(writer, sock->prop); - } - - write_node_socket_default_value(writer, sock); -} -static void write_node_socket_interface(BlendWriter *writer, bNodeSocket *sock) -{ - /* actual socket writing */ - BLO_write_struct(writer, bNodeSocket, sock); - - if (sock->prop) { - IDP_BlendWrite(writer, sock->prop); - } - - write_node_socket_default_value(writer, sock); -} -/* this is only direct data, tree itself should have been written */ -static void write_nodetree_nolib(BlendWriter *writer, bNodeTree *ntree) -{ - /* for link_list() speed, we write per list */ - - if (ntree->adt) { - BKE_animdata_blend_write(writer, ntree->adt); - } - - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - BLO_write_struct(writer, bNode, node); - - if (node->prop) { - IDP_BlendWrite(writer, node->prop); - } - - LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { - write_node_socket(writer, sock); - } - LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { - write_node_socket(writer, sock); - } - - LISTBASE_FOREACH (bNodeLink *, link, &node->internal_links) { - BLO_write_struct(writer, bNodeLink, link); - } - - if (node->storage) { - /* could be handlerized at some point, now only 1 exception still */ - if ((ntree->type == NTREE_SHADER) && - ELEM(node->type, SH_NODE_CURVE_VEC, SH_NODE_CURVE_RGB)) { - BKE_curvemapping_blend_write(writer, node->storage); - } - else if (ntree->type == NTREE_SHADER && (node->type == SH_NODE_SCRIPT)) { - NodeShaderScript *nss = (NodeShaderScript *)node->storage; - if (nss->bytecode) { - BLO_write_string(writer, nss->bytecode); - } - BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); - } - else if ((ntree->type == NTREE_COMPOSIT) && ELEM(node->type, - CMP_NODE_TIME, - CMP_NODE_CURVE_VEC, - CMP_NODE_CURVE_RGB, - CMP_NODE_HUECORRECT)) { - BKE_curvemapping_blend_write(writer, node->storage); - } - else if ((ntree->type == NTREE_TEXTURE) && - (node->type == TEX_NODE_CURVE_RGB || node->type == TEX_NODE_CURVE_TIME)) { - BKE_curvemapping_blend_write(writer, node->storage); - } - else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_MOVIEDISTORTION)) { - /* pass */ - } - else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_GLARE)) { - /* Simple forward compatibility for fix for T50736. - * Not ideal (there is no ideal solution here), but should do for now. */ - NodeGlare *ndg = node->storage; - /* Not in undo case. */ - if (!BLO_write_is_undo(writer)) { - switch (ndg->type) { - case 2: /* Grrrr! magic numbers :( */ - ndg->angle = ndg->streaks; - break; - case 0: - ndg->angle = ndg->star_45; - break; - default: - break; - } - } - BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); - } - else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_CRYPTOMATTE)) { - NodeCryptomatte *nc = (NodeCryptomatte *)node->storage; - if (nc->matte_id) { - BLO_write_string(writer, nc->matte_id); - } - BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); - } - else if (node->typeinfo != &NodeTypeUndefined) { - BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage); - } - } - - if (node->type == CMP_NODE_OUTPUT_FILE) { - /* inputs have own storage data */ - LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { - BLO_write_struct(writer, NodeImageMultiFileSocket, sock->storage); - } - } - if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS)) { - /* write extra socket info */ - LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { - BLO_write_struct(writer, NodeImageLayer, sock->storage); - } - } - } - - LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { - BLO_write_struct(writer, bNodeLink, link); - } - - LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) { - write_node_socket_interface(writer, sock); - } - LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) { - write_node_socket_interface(writer, sock); - } -} - /** * Take care using 'use_active_win', since we wont want the currently active window * to change which scene renders (currently only used for undo). @@ -1622,291 +1365,14 @@ static void write_object(BlendWriter *writer, Object *ob, const void *id_address BLO_write_struct_list(writer, LinkData, &ob->pc_ids); - write_previews(writer, ob->preview); - } -} - -static void write_vfont(BlendWriter *writer, VFont *vf, const void *id_address) -{ - if (vf->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - vf->data = NULL; - vf->temp_pf = NULL; - - /* write LibData */ - BLO_write_id_struct(writer, VFont, id_address, &vf->id); - BKE_id_blend_write(writer, &vf->id); - - /* direct data */ - if (vf->packedfile) { - PackedFile *pf = vf->packedfile; - BLO_write_struct(writer, PackedFile, pf); - BLO_write_raw(writer, pf->size, pf->data); - } - } -} - -static void write_key(BlendWriter *writer, Key *key, const void *id_address) -{ - if (key->id.us > 0 || BLO_write_is_undo(writer)) { - /* write LibData */ - BLO_write_id_struct(writer, Key, id_address, &key->id); - BKE_id_blend_write(writer, &key->id); - - if (key->adt) { - BKE_animdata_blend_write(writer, key->adt); - } - - /* direct data */ - LISTBASE_FOREACH (KeyBlock *, kb, &key->block) { - BLO_write_struct(writer, KeyBlock, kb); - if (kb->data) { - BLO_write_raw(writer, kb->totelem * key->elemsize, kb->data); - } - } - } -} - -static void write_camera(BlendWriter *writer, Camera *cam, const void *id_address) -{ - if (cam->id.us > 0 || BLO_write_is_undo(writer)) { - /* write LibData */ - BLO_write_id_struct(writer, Camera, id_address, &cam->id); - BKE_id_blend_write(writer, &cam->id); - - if (cam->adt) { - BKE_animdata_blend_write(writer, cam->adt); - } - - LISTBASE_FOREACH (CameraBGImage *, bgpic, &cam->bg_images) { - BLO_write_struct(writer, CameraBGImage, bgpic); - } - } -} - -static void write_mball(BlendWriter *writer, MetaBall *mb, const void *id_address) -{ - if (mb->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - BLI_listbase_clear(&mb->disp); - mb->editelems = NULL; - /* Must always be cleared (meta's don't have their own edit-data). */ - mb->needs_flush_to_id = 0; - mb->lastelem = NULL; - mb->batch_cache = NULL; - - /* write LibData */ - BLO_write_id_struct(writer, MetaBall, id_address, &mb->id); - BKE_id_blend_write(writer, &mb->id); - - /* direct data */ - BLO_write_pointer_array(writer, mb->totcol, mb->mat); - if (mb->adt) { - BKE_animdata_blend_write(writer, mb->adt); - } - - LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) { - BLO_write_struct(writer, MetaElem, ml); - } - } -} - -static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address) -{ - if (cu->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - cu->editnurb = NULL; - cu->editfont = NULL; - cu->batch_cache = NULL; - - /* write LibData */ - BLO_write_id_struct(writer, Curve, id_address, &cu->id); - BKE_id_blend_write(writer, &cu->id); - - /* direct data */ - BLO_write_pointer_array(writer, cu->totcol, cu->mat); - if (cu->adt) { - BKE_animdata_blend_write(writer, cu->adt); - } - - if (cu->vfont) { - BLO_write_raw(writer, cu->len + 1, cu->str); - BLO_write_struct_array(writer, CharInfo, cu->len_char32 + 1, cu->strinfo); - BLO_write_struct_array(writer, TextBox, cu->totbox, cu->tb); - } - else { - /* is also the order of reading */ - LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { - BLO_write_struct(writer, Nurb, nu); - } - LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { - if (nu->type == CU_BEZIER) { - BLO_write_struct_array(writer, BezTriple, nu->pntsu, nu->bezt); - } - else { - - BLO_write_struct_array(writer, BPoint, nu->pntsu * nu->pntsv, nu->bp); - if (nu->knotsu) { - BLO_write_float_array(writer, KNOTSU(nu), nu->knotsu); - } - if (nu->knotsv) { - BLO_write_float_array(writer, KNOTSV(nu), nu->knotsv); - } - } - } - } - } -} - -static void write_image(BlendWriter *writer, Image *ima, const void *id_address) -{ - if (ima->id.us > 0 || BLO_write_is_undo(writer)) { - ImagePackedFile *imapf; - - /* Some trickery to keep forward compatibility of packed images. */ - BLI_assert(ima->packedfile == NULL); - if (ima->packedfiles.first != NULL) { - imapf = ima->packedfiles.first; - ima->packedfile = imapf->packedfile; - } - - /* write LibData */ - BLO_write_id_struct(writer, Image, id_address, &ima->id); - BKE_id_blend_write(writer, &ima->id); - - for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { - BLO_write_struct(writer, ImagePackedFile, imapf); - if (imapf->packedfile) { - PackedFile *pf = imapf->packedfile; - BLO_write_struct(writer, PackedFile, pf); - BLO_write_raw(writer, pf->size, pf->data); - } - } - - write_previews(writer, ima->preview); - - LISTBASE_FOREACH (ImageView *, iv, &ima->views) { - BLO_write_struct(writer, ImageView, iv); - } - BLO_write_struct(writer, Stereo3dFormat, ima->stereo3d_format); - - BLO_write_struct_list(writer, ImageTile, &ima->tiles); - - ima->packedfile = NULL; - - BLO_write_struct_list(writer, RenderSlot, &ima->renderslots); - } -} - -static void write_texture(BlendWriter *writer, Tex *tex, const void *id_address) -{ - if (tex->id.us > 0 || BLO_write_is_undo(writer)) { - /* write LibData */ - BLO_write_id_struct(writer, Tex, id_address, &tex->id); - BKE_id_blend_write(writer, &tex->id); - - if (tex->adt) { - BKE_animdata_blend_write(writer, tex->adt); - } - - /* direct data */ - if (tex->coba) { - BLO_write_struct(writer, ColorBand, tex->coba); - } - - /* nodetree is integral part of texture, no libdata */ - if (tex->nodetree) { - BLO_write_struct(writer, bNodeTree, tex->nodetree); - write_nodetree_nolib(writer, tex->nodetree); - } - - write_previews(writer, tex->preview); - } -} - -static void write_material(BlendWriter *writer, Material *ma, const void *id_address) -{ - if (ma->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - ma->texpaintslot = NULL; - BLI_listbase_clear(&ma->gpumaterial); - - /* write LibData */ - BLO_write_id_struct(writer, Material, id_address, &ma->id); - BKE_id_blend_write(writer, &ma->id); - - if (ma->adt) { - BKE_animdata_blend_write(writer, ma->adt); - } - - /* nodetree is integral part of material, no libdata */ - if (ma->nodetree) { - BLO_write_struct(writer, bNodeTree, ma->nodetree); - write_nodetree_nolib(writer, ma->nodetree); - } - - write_previews(writer, ma->preview); - - /* grease pencil settings */ - if (ma->gp_style) { - BLO_write_struct(writer, MaterialGPencilStyle, ma->gp_style); - } - } -} - -static void write_world(BlendWriter *writer, World *wrld, const void *id_address) -{ - if (wrld->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - BLI_listbase_clear(&wrld->gpumaterial); - - /* write LibData */ - BLO_write_id_struct(writer, World, id_address, &wrld->id); - BKE_id_blend_write(writer, &wrld->id); - - if (wrld->adt) { - BKE_animdata_blend_write(writer, wrld->adt); - } - - /* nodetree is integral part of world, no libdata */ - if (wrld->nodetree) { - BLO_write_struct(writer, bNodeTree, wrld->nodetree); - write_nodetree_nolib(writer, wrld->nodetree); - } - - write_previews(writer, wrld->preview); - } -} - -static void write_light(BlendWriter *writer, Light *la, const void *id_address) -{ - if (la->id.us > 0 || BLO_write_is_undo(writer)) { - /* write LibData */ - BLO_write_id_struct(writer, Light, id_address, &la->id); - BKE_id_blend_write(writer, &la->id); - - if (la->adt) { - BKE_animdata_blend_write(writer, la->adt); - } - - if (la->curfalloff) { - BKE_curvemapping_blend_write(writer, la->curfalloff); - } - - /* Node-tree is integral part of lights, no libdata. */ - if (la->nodetree) { - BLO_write_struct(writer, bNodeTree, la->nodetree); - write_nodetree_nolib(writer, la->nodetree); - } - - write_previews(writer, la->preview); + BKE_previewimg_blend_write(writer, ob->preview); } } static void write_collection_nolib(BlendWriter *writer, Collection *collection) { /* Shared function for collection data-blocks and scene master collection. */ - write_previews(writer, collection->preview); + BKE_previewimg_blend_write(writer, collection->preview); LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { BLO_write_struct(writer, CollectionObject, cob); @@ -2059,7 +1525,7 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address) if (sce->adt) { BKE_animdata_blend_write(writer, sce->adt); } - write_keyingsets(writer, &sce->keyingsets); + BKE_keyingsets_blend_write(writer, &sce->keyingsets); /* direct data */ ToolSettings *tos = sce->toolsettings; @@ -2234,7 +1700,7 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address) if (sce->nodetree) { BLO_write_struct(writer, bNodeTree, sce->nodetree); - write_nodetree_nolib(writer, sce->nodetree); + ntreeBlendWrite(writer, sce->nodetree); } write_view_settings(writer, &sce->view_settings); @@ -2251,7 +1717,7 @@ static void write_scene(BlendWriter *writer, Scene *sce, const void *id_address) write_pointcaches(writer, &(sce->rigidbody_world->shared->ptcaches)); } - write_previews(writer, sce->preview); + BKE_previewimg_blend_write(writer, sce->preview); BKE_curvemapping_curves_blend_write(writer, &sce->r.mblur_shutter_curve); LISTBASE_FOREACH (ViewLayer *, view_layer, &sce->view_layers) { @@ -2606,652 +2072,13 @@ static void write_screen(BlendWriter *writer, bScreen *screen, const void *id_ad writestruct_at_address(writer->wd, ID_SCRN, bScreen, 1, id_address, screen); BKE_id_blend_write(writer, &screen->id); - write_previews(writer, screen->preview); + BKE_previewimg_blend_write(writer, screen->preview); /* direct data */ write_area_map(writer, AREAMAP_FROM_SCREEN(screen)); } } -static void write_bone(BlendWriter *writer, Bone *bone) -{ - /* PATCH for upward compatibility after 2.37+ armature recode */ - bone->size[0] = bone->size[1] = bone->size[2] = 1.0f; - - /* Write this bone */ - BLO_write_struct(writer, Bone, bone); - - /* Write ID Properties -- and copy this comment EXACTLY for easy finding - * of library blocks that implement this.*/ - if (bone->prop) { - IDP_BlendWrite(writer, bone->prop); - } - - /* Write Children */ - LISTBASE_FOREACH (Bone *, cbone, &bone->childbase) { - write_bone(writer, cbone); - } -} - -static void write_armature(BlendWriter *writer, bArmature *arm, const void *id_address) -{ - if (arm->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - arm->bonehash = NULL; - arm->edbo = NULL; - /* Must always be cleared (armatures don't have their own edit-data). */ - arm->needs_flush_to_id = 0; - arm->act_edbone = NULL; - - BLO_write_id_struct(writer, bArmature, id_address, &arm->id); - BKE_id_blend_write(writer, &arm->id); - - if (arm->adt) { - BKE_animdata_blend_write(writer, arm->adt); - } - - /* Direct data */ - LISTBASE_FOREACH (Bone *, bone, &arm->bonebase) { - write_bone(writer, bone); - } - } -} - -static void write_text(BlendWriter *writer, Text *text, const void *id_address) -{ - /* Note: we are clearing local temp data here, *not* the flag in the actual 'real' ID. */ - if ((text->flags & TXT_ISMEM) && (text->flags & TXT_ISEXT)) { - text->flags &= ~TXT_ISEXT; - } - - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - text->compiled = NULL; - - /* write LibData */ - BLO_write_id_struct(writer, Text, id_address, &text->id); - BKE_id_blend_write(writer, &text->id); - - if (text->filepath) { - BLO_write_string(writer, text->filepath); - } - - if (!(text->flags & TXT_ISEXT)) { - /* now write the text data, in two steps for optimization in the readfunction */ - LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { - BLO_write_struct(writer, TextLine, tmp); - } - - LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { - BLO_write_raw(writer, tmp->len + 1, tmp->line); - } - } -} - -static void write_speaker(BlendWriter *writer, Speaker *spk, const void *id_address) -{ - if (spk->id.us > 0 || BLO_write_is_undo(writer)) { - /* write LibData */ - BLO_write_id_struct(writer, Speaker, id_address, &spk->id); - BKE_id_blend_write(writer, &spk->id); - - if (spk->adt) { - BKE_animdata_blend_write(writer, spk->adt); - } - } -} - -static void write_sound(BlendWriter *writer, bSound *sound, const void *id_address) -{ - if (sound->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - sound->tags = 0; - sound->handle = NULL; - sound->playback_handle = NULL; - sound->spinlock = NULL; - - /* write LibData */ - BLO_write_id_struct(writer, bSound, id_address, &sound->id); - BKE_id_blend_write(writer, &sound->id); - - if (sound->packedfile) { - PackedFile *pf = sound->packedfile; - BLO_write_struct(writer, PackedFile, pf); - BLO_write_raw(writer, pf->size, pf->data); - } - } -} - -static void write_probe(BlendWriter *writer, LightProbe *prb, const void *id_address) -{ - if (prb->id.us > 0 || BLO_write_is_undo(writer)) { - /* write LibData */ - BLO_write_id_struct(writer, LightProbe, id_address, &prb->id); - BKE_id_blend_write(writer, &prb->id); - - if (prb->adt) { - BKE_animdata_blend_write(writer, prb->adt); - } - } -} - -static void write_nodetree(BlendWriter *writer, bNodeTree *ntree, const void *id_address) -{ - if (ntree->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - ntree->init = 0; /* to set callbacks and force setting types */ - ntree->is_updating = false; - ntree->typeinfo = NULL; - ntree->interface_type = NULL; - ntree->progress = NULL; - ntree->execdata = NULL; - - BLO_write_id_struct(writer, bNodeTree, id_address, &ntree->id); - /* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot - * be linked, etc., so we write actual id data here only, for 'real' ID trees. */ - BKE_id_blend_write(writer, &ntree->id); - - write_nodetree_nolib(writer, ntree); - } -} - -static void write_brush(BlendWriter *writer, Brush *brush, const void *id_address) -{ - if (brush->id.us > 0 || BLO_write_is_undo(writer)) { - BLO_write_id_struct(writer, Brush, id_address, &brush->id); - BKE_id_blend_write(writer, &brush->id); - - if (brush->curve) { - BKE_curvemapping_blend_write(writer, brush->curve); - } - - if (brush->gpencil_settings) { - BLO_write_struct(writer, BrushGpencilSettings, brush->gpencil_settings); - - if (brush->gpencil_settings->curve_sensitivity) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_sensitivity); - } - if (brush->gpencil_settings->curve_strength) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_strength); - } - if (brush->gpencil_settings->curve_jitter) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_jitter); - } - if (brush->gpencil_settings->curve_rand_pressure) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_pressure); - } - if (brush->gpencil_settings->curve_rand_strength) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_strength); - } - if (brush->gpencil_settings->curve_rand_uv) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_uv); - } - if (brush->gpencil_settings->curve_rand_hue) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_hue); - } - if (brush->gpencil_settings->curve_rand_saturation) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_saturation); - } - if (brush->gpencil_settings->curve_rand_value) { - BKE_curvemapping_blend_write(writer, brush->gpencil_settings->curve_rand_value); - } - } - if (brush->gradient) { - BLO_write_struct(writer, ColorBand, brush->gradient); - } - } -} - -static void write_palette(BlendWriter *writer, Palette *palette, const void *id_address) -{ - if (palette->id.us > 0 || BLO_write_is_undo(writer)) { - PaletteColor *color; - BLO_write_id_struct(writer, Palette, id_address, &palette->id); - BKE_id_blend_write(writer, &palette->id); - - for (color = palette->colors.first; color; color = color->next) { - BLO_write_struct(writer, PaletteColor, color); - } - } -} - -static void write_paintcurve(BlendWriter *writer, PaintCurve *pc, const void *id_address) -{ - if (pc->id.us > 0 || BLO_write_is_undo(writer)) { - BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id); - BKE_id_blend_write(writer, &pc->id); - - BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points); - } -} - -static void write_movieTracks(BlendWriter *writer, ListBase *tracks) -{ - MovieTrackingTrack *track; - - track = tracks->first; - while (track) { - BLO_write_struct(writer, MovieTrackingTrack, track); - - if (track->markers) { - BLO_write_struct_array(writer, MovieTrackingMarker, track->markersnr, track->markers); - } - - track = track->next; - } -} - -static void write_moviePlaneTracks(BlendWriter *writer, ListBase *plane_tracks_base) -{ - MovieTrackingPlaneTrack *plane_track; - - for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { - BLO_write_struct(writer, MovieTrackingPlaneTrack, plane_track); - - BLO_write_pointer_array(writer, plane_track->point_tracksnr, plane_track->point_tracks); - BLO_write_struct_array( - writer, MovieTrackingPlaneMarker, plane_track->markersnr, plane_track->markers); - } -} - -static void write_movieReconstruction(BlendWriter *writer, - MovieTrackingReconstruction *reconstruction) -{ - if (reconstruction->camnr) { - BLO_write_struct_array( - writer, MovieReconstructedCamera, reconstruction->camnr, reconstruction->cameras); - } -} - -static void write_movieclip(BlendWriter *writer, MovieClip *clip, const void *id_address) -{ - if (clip->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - clip->anim = NULL; - clip->tracking_context = NULL; - clip->tracking.stats = NULL; - - MovieTracking *tracking = &clip->tracking; - MovieTrackingObject *object; - - BLO_write_id_struct(writer, MovieClip, id_address, &clip->id); - BKE_id_blend_write(writer, &clip->id); - - if (clip->adt) { - BKE_animdata_blend_write(writer, clip->adt); - } - - write_movieTracks(writer, &tracking->tracks); - write_moviePlaneTracks(writer, &tracking->plane_tracks); - write_movieReconstruction(writer, &tracking->reconstruction); - - object = tracking->objects.first; - while (object) { - BLO_write_struct(writer, MovieTrackingObject, object); - - write_movieTracks(writer, &object->tracks); - write_moviePlaneTracks(writer, &object->plane_tracks); - write_movieReconstruction(writer, &object->reconstruction); - - object = object->next; - } - } -} - -static void write_mask(BlendWriter *writer, Mask *mask, const void *id_address) -{ - if (mask->id.us > 0 || BLO_write_is_undo(writer)) { - MaskLayer *masklay; - - BLO_write_id_struct(writer, Mask, id_address, &mask->id); - BKE_id_blend_write(writer, &mask->id); - - if (mask->adt) { - BKE_animdata_blend_write(writer, mask->adt); - } - - for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { - MaskSpline *spline; - MaskLayerShape *masklay_shape; - - BLO_write_struct(writer, MaskLayer, masklay); - - for (spline = masklay->splines.first; spline; spline = spline->next) { - int i; - - void *points_deform = spline->points_deform; - spline->points_deform = NULL; - - BLO_write_struct(writer, MaskSpline, spline); - BLO_write_struct_array(writer, MaskSplinePoint, spline->tot_point, spline->points); - - spline->points_deform = points_deform; - - for (i = 0; i < spline->tot_point; i++) { - MaskSplinePoint *point = &spline->points[i]; - - if (point->tot_uw) { - BLO_write_struct_array(writer, MaskSplinePointUW, point->tot_uw, point->uw); - } - } - } - - for (masklay_shape = masklay->splines_shapes.first; masklay_shape; - masklay_shape = masklay_shape->next) { - BLO_write_struct(writer, MaskLayerShape, masklay_shape); - BLO_write_float_array( - writer, masklay_shape->tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE, masklay_shape->data); - } - } - } -} - -static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modifiers) -{ - LineStyleModifier *m; - - for (m = modifiers->first; m; m = m->next) { - int struct_nr; - switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_AlongStroke); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromCamera); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromObject); - break; - case LS_MODIFIER_MATERIAL: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Material); - break; - case LS_MODIFIER_TANGENT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Tangent); - break; - case LS_MODIFIER_NOISE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Noise); - break; - case LS_MODIFIER_CREASE_ANGLE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_CreaseAngle); - break; - case LS_MODIFIER_CURVATURE_3D: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Curvature_3D); - break; - default: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ - } - BLO_write_struct_by_id(writer, struct_nr, m); - } - for (m = modifiers->first; m; m = m->next) { - switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - BLO_write_struct( - writer, ColorBand, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - BLO_write_struct( - writer, ColorBand, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); - break; - case LS_MODIFIER_MATERIAL: - BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Material *)m)->color_ramp); - break; - case LS_MODIFIER_TANGENT: - BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Tangent *)m)->color_ramp); - break; - case LS_MODIFIER_NOISE: - BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_Noise *)m)->color_ramp); - break; - case LS_MODIFIER_CREASE_ANGLE: - BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp); - break; - case LS_MODIFIER_CURVATURE_3D: - BLO_write_struct( - writer, ColorBand, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp); - break; - } - } -} - -static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modifiers) -{ - LineStyleModifier *m; - - for (m = modifiers->first; m; m = m->next) { - int struct_nr; - switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_AlongStroke); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromCamera); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromObject); - break; - case LS_MODIFIER_MATERIAL: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Material); - break; - case LS_MODIFIER_TANGENT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Tangent); - break; - case LS_MODIFIER_NOISE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Noise); - break; - case LS_MODIFIER_CREASE_ANGLE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_CreaseAngle); - break; - case LS_MODIFIER_CURVATURE_3D: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Curvature_3D); - break; - default: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ - } - BLO_write_struct_by_id(writer, struct_nr, m); - } - for (m = modifiers->first; m; m = m->next) { - switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_AlongStroke *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - BKE_curvemapping_blend_write(writer, - ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - BKE_curvemapping_blend_write(writer, - ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve); - break; - case LS_MODIFIER_MATERIAL: - BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Material *)m)->curve); - break; - case LS_MODIFIER_TANGENT: - BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Tangent *)m)->curve); - break; - case LS_MODIFIER_NOISE: - BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Noise *)m)->curve); - break; - case LS_MODIFIER_CREASE_ANGLE: - BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_CreaseAngle *)m)->curve); - break; - case LS_MODIFIER_CURVATURE_3D: - BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_Curvature_3D *)m)->curve); - break; - } - } -} - -static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *modifiers) -{ - LineStyleModifier *m; - - for (m = modifiers->first; m; m = m->next) { - int struct_nr; - switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_AlongStroke); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromCamera); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromObject); - break; - case LS_MODIFIER_MATERIAL: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Material); - break; - case LS_MODIFIER_CALLIGRAPHY: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Calligraphy); - break; - case LS_MODIFIER_TANGENT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Tangent); - break; - case LS_MODIFIER_NOISE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Noise); - break; - case LS_MODIFIER_CREASE_ANGLE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_CreaseAngle); - break; - case LS_MODIFIER_CURVATURE_3D: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Curvature_3D); - break; - default: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ - } - BLO_write_struct_by_id(writer, struct_nr, m); - } - for (m = modifiers->first; m; m = m->next) { - switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_AlongStroke *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - BKE_curvemapping_blend_write(writer, - ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - BKE_curvemapping_blend_write(writer, - ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve); - break; - case LS_MODIFIER_MATERIAL: - BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_Material *)m)->curve); - break; - case LS_MODIFIER_TANGENT: - BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_Tangent *)m)->curve); - break; - case LS_MODIFIER_CREASE_ANGLE: - BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_CreaseAngle *)m)->curve); - break; - case LS_MODIFIER_CURVATURE_3D: - BKE_curvemapping_blend_write(writer, - ((LineStyleThicknessModifier_Curvature_3D *)m)->curve); - break; - } - } -} - -static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *modifiers) -{ - LineStyleModifier *m; - - for (m = modifiers->first; m; m = m->next) { - int struct_nr; - switch (m->type) { - case LS_MODIFIER_SAMPLING: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Sampling); - break; - case LS_MODIFIER_BEZIER_CURVE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BezierCurve); - break; - case LS_MODIFIER_SINUS_DISPLACEMENT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SinusDisplacement); - break; - case LS_MODIFIER_SPATIAL_NOISE: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SpatialNoise); - break; - case LS_MODIFIER_PERLIN_NOISE_1D: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise1D); - break; - case LS_MODIFIER_PERLIN_NOISE_2D: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise2D); - break; - case LS_MODIFIER_BACKBONE_STRETCHER: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BackboneStretcher); - break; - case LS_MODIFIER_TIP_REMOVER: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_TipRemover); - break; - case LS_MODIFIER_POLYGONIZATION: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Polygonalization); - break; - case LS_MODIFIER_GUIDING_LINES: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_GuidingLines); - break; - case LS_MODIFIER_BLUEPRINT: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Blueprint); - break; - case LS_MODIFIER_2D_OFFSET: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DOffset); - break; - case LS_MODIFIER_2D_TRANSFORM: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DTransform); - break; - case LS_MODIFIER_SIMPLIFICATION: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Simplification); - break; - default: - struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ - } - BLO_write_struct_by_id(writer, struct_nr, m); - } -} - -static void write_linestyle(BlendWriter *writer, - FreestyleLineStyle *linestyle, - const void *id_address) -{ - if (linestyle->id.us > 0 || BLO_write_is_undo(writer)) { - BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id); - BKE_id_blend_write(writer, &linestyle->id); - - if (linestyle->adt) { - BKE_animdata_blend_write(writer, linestyle->adt); - } - - write_linestyle_color_modifiers(writer, &linestyle->color_modifiers); - write_linestyle_alpha_modifiers(writer, &linestyle->alpha_modifiers); - write_linestyle_thickness_modifiers(writer, &linestyle->thickness_modifiers); - write_linestyle_geometry_modifiers(writer, &linestyle->geometry_modifiers); - for (int a = 0; a < MAX_MTEX; a++) { - if (linestyle->mtex[a]) { - BLO_write_struct(writer, MTex, linestyle->mtex[a]); - } - } - if (linestyle->nodetree) { - BLO_write_struct(writer, bNodeTree, linestyle->nodetree); - write_nodetree_nolib(writer, linestyle->nodetree); - } - } -} - -static void write_cachefile(BlendWriter *writer, CacheFile *cache_file, const void *id_address) -{ - if (cache_file->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - BLI_listbase_clear(&cache_file->object_paths); - cache_file->handle = NULL; - memset(cache_file->handle_filepath, 0, sizeof(cache_file->handle_filepath)); - cache_file->handle_readers = NULL; - - BLO_write_id_struct(writer, CacheFile, id_address, &cache_file->id); - - if (cache_file->adt) { - BKE_animdata_blend_write(writer, cache_file->adt); - } - } -} - static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const void *id_address) { BLO_write_id_struct(writer, WorkSpace, id_address, &workspace->id); @@ -3267,140 +2094,6 @@ static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const voi } } -static void write_hair(BlendWriter *writer, Hair *hair, const void *id_address) -{ - if (hair->id.us > 0 || BLO_write_is_undo(writer)) { - CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; - CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE]; - CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); - CustomData_blend_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff)); - - /* Write LibData */ - BLO_write_id_struct(writer, Hair, id_address, &hair->id); - BKE_id_blend_write(writer, &hair->id); - - /* Direct data */ - CustomData_blend_write(writer, &hair->pdata, players, hair->totpoint, CD_MASK_ALL, &hair->id); - CustomData_blend_write(writer, &hair->cdata, clayers, hair->totcurve, CD_MASK_ALL, &hair->id); - - BLO_write_pointer_array(writer, hair->totcol, hair->mat); - if (hair->adt) { - BKE_animdata_blend_write(writer, hair->adt); - } - - /* Remove temporary data. */ - if (players && players != players_buff) { - MEM_freeN(players); - } - if (clayers && clayers != clayers_buff) { - MEM_freeN(clayers); - } - } -} - -static void write_pointcloud(BlendWriter *writer, PointCloud *pointcloud, const void *id_address) -{ - if (pointcloud->id.us > 0 || BLO_write_is_undo(writer)) { - CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; - CustomData_blend_write_prepare( - &pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); - - /* Write LibData */ - BLO_write_id_struct(writer, PointCloud, id_address, &pointcloud->id); - BKE_id_blend_write(writer, &pointcloud->id); - - /* Direct data */ - CustomData_blend_write( - writer, &pointcloud->pdata, players, pointcloud->totpoint, CD_MASK_ALL, &pointcloud->id); - - BLO_write_pointer_array(writer, pointcloud->totcol, pointcloud->mat); - if (pointcloud->adt) { - BKE_animdata_blend_write(writer, pointcloud->adt); - } - - /* Remove temporary data. */ - if (players && players != players_buff) { - MEM_freeN(players); - } - } -} - -static void write_volume(BlendWriter *writer, Volume *volume, const void *id_address) -{ - if (volume->id.us > 0 || BLO_write_is_undo(writer)) { - /* Clean up, important in undo case to reduce false detection of changed datablocks. */ - volume->runtime.grids = 0; - - /* write LibData */ - BLO_write_id_struct(writer, Volume, id_address, &volume->id); - BKE_id_blend_write(writer, &volume->id); - - /* direct data */ - BLO_write_pointer_array(writer, volume->totcol, volume->mat); - if (volume->adt) { - BKE_animdata_blend_write(writer, volume->adt); - } - - if (volume->packedfile) { - PackedFile *pf = volume->packedfile; - BLO_write_struct(writer, PackedFile, pf); - BLO_write_raw(writer, pf->size, pf->data); - } - } -} - -static void write_simulation(BlendWriter *writer, Simulation *simulation, const void *id_address) -{ - if (simulation->id.us > 0 || BLO_write_is_undo(writer)) { - BLO_write_id_struct(writer, Simulation, id_address, &simulation->id); - BKE_id_blend_write(writer, &simulation->id); - - if (simulation->adt) { - BKE_animdata_blend_write(writer, simulation->adt); - } - - /* nodetree is integral part of simulation, no libdata */ - if (simulation->nodetree) { - BLO_write_struct(writer, bNodeTree, simulation->nodetree); - write_nodetree_nolib(writer, simulation->nodetree); - } - - LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { - BLO_write_string(writer, state->name); - BLO_write_string(writer, state->type); - /* TODO: Decentralize this part. */ - if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_SIMULATION)) { - ParticleSimulationState *particle_state = (ParticleSimulationState *)state; - - CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; - CustomData_blend_write_prepare( - &particle_state->attributes, &players, players_buff, ARRAY_SIZE(players_buff)); - - BLO_write_struct(writer, ParticleSimulationState, particle_state); - - CustomData_blend_write(writer, - &particle_state->attributes, - players, - particle_state->tot_particles, - CD_MASK_ALL, - &simulation->id); - - /* Remove temporary data. */ - if (players && players != players_buff) { - MEM_freeN(players); - } - } - else if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_MESH_EMITTER)) { - ParticleMeshEmitterSimulationState *emitter_state = (ParticleMeshEmitterSimulationState *) - state; - BLO_write_struct(writer, ParticleMeshEmitterSimulationState, emitter_state); - } - } - - BLO_write_struct_list(writer, SimulationDependency, &simulation->dependencies); - } -} - /* Keep it last of write_foodata functions. */ static void write_libraries(WriteData *wd, Main *main) { @@ -3447,9 +2140,7 @@ static void write_libraries(WriteData *wd, Main *main) BKE_id_blend_write(&writer, &main->curlib->id); if (main->curlib->packedfile) { - PackedFile *pf = main->curlib->packedfile; - writestruct(wd, DATA, PackedFile, 1, pf); - writedata(wd, DATA, pf->size, pf->data); + BKE_packedfile_blend_write(&writer, main->curlib->packedfile); if (wd->use_memfile == false) { printf("write packed .blend: %s\n", main->curlib->filepath); } @@ -3670,107 +2361,49 @@ static bool write_file_handle(Main *mainvar, case ID_SCR: write_screen(&writer, (bScreen *)id_buffer, id); break; - case ID_MC: - write_movieclip(&writer, (MovieClip *)id_buffer, id); - break; - case ID_MSK: - write_mask(&writer, (Mask *)id_buffer, id); - break; case ID_SCE: write_scene(&writer, (Scene *)id_buffer, id); break; - case ID_CU: - write_curve(&writer, (Curve *)id_buffer, id); - break; - case ID_MB: - write_mball(&writer, (MetaBall *)id_buffer, id); - break; - case ID_IM: - write_image(&writer, (Image *)id_buffer, id); - break; - case ID_CA: - write_camera(&writer, (Camera *)id_buffer, id); - break; - case ID_LA: - write_light(&writer, (Light *)id_buffer, id); - break; - case ID_VF: - write_vfont(&writer, (VFont *)id_buffer, id); - break; - case ID_KE: - write_key(&writer, (Key *)id_buffer, id); - break; - case ID_WO: - write_world(&writer, (World *)id_buffer, id); - break; - case ID_TXT: - write_text(&writer, (Text *)id_buffer, id); - break; - case ID_SPK: - write_speaker(&writer, (Speaker *)id_buffer, id); - break; - case ID_LP: - write_probe(&writer, (LightProbe *)id_buffer, id); - break; - case ID_SO: - write_sound(&writer, (bSound *)id_buffer, id); - break; case ID_GR: write_collection(&writer, (Collection *)id_buffer, id); break; - case ID_AR: - write_armature(&writer, (bArmature *)id_buffer, id); - break; - case ID_AC: - write_action(&writer, (bAction *)id_buffer, id); - break; case ID_OB: write_object(&writer, (Object *)id_buffer, id); break; - case ID_MA: - write_material(&writer, (Material *)id_buffer, id); - break; - case ID_TE: - write_texture(&writer, (Tex *)id_buffer, id); - break; case ID_PA: write_particlesettings(&writer, (ParticleSettings *)id_buffer, id); break; + case ID_ME: + case ID_LT: + case ID_AC: case ID_NT: - write_nodetree(&writer, (bNodeTree *)id_buffer, id); - break; - case ID_BR: - write_brush(&writer, (Brush *)id_buffer, id); - break; - case ID_PAL: - write_palette(&writer, (Palette *)id_buffer, id); - break; + case ID_LS: + case ID_TXT: + case ID_VF: + case ID_MC: case ID_PC: - write_paintcurve(&writer, (PaintCurve *)id_buffer, id); - break; + case ID_PAL: + case ID_BR: + case ID_IM: + case ID_LA: + case ID_MA: + case ID_MB: + case ID_CU: + case ID_CA: + case ID_WO: + case ID_MSK: + case ID_SPK: + case ID_AR: + case ID_LP: + case ID_KE: + case ID_TE: case ID_GD: - write_gpencil(&writer, (bGPdata *)id_buffer, id); - break; - case ID_LS: - write_linestyle(&writer, (FreestyleLineStyle *)id_buffer, id); - break; - case ID_CF: - write_cachefile(&writer, (CacheFile *)id_buffer, id); - break; case ID_HA: - write_hair(&writer, (Hair *)id_buffer, id); - break; case ID_PT: - write_pointcloud(&writer, (PointCloud *)id_buffer, id); - break; case ID_VO: - write_volume(&writer, (Volume *)id_buffer, id); - break; case ID_SIM: - write_simulation(&writer, (Simulation *)id_buffer, id); - break; - case ID_ME: - case ID_LT: + case ID_SO: + case ID_CF: /* Do nothing, handled in IDTypeInfo callback. */ break; case ID_LI: diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h index 5f5d6baaba2..9199801d1a1 100644 --- a/source/blender/bmesh/bmesh.h +++ b/source/blender/bmesh/bmesh.h @@ -41,7 +41,7 @@ * \subsection bm_faces Faces * * Faces in BMesh are stored as a circular linked list of loops. Loops store per-face-vertex data - * (amongst other things outlined later in this document), and define the face boundary. + * (among other things outlined later in this document), and define the face boundary. * \subsection bm_loop The Loop * * Loops can be thought of as a *face-corner*, since faces don't reference verts or edges directly. diff --git a/source/blender/bmesh/operators/bmo_bisect_plane.c b/source/blender/bmesh/operators/bmo_bisect_plane.c index ef59ebf1f2f..337437fb607 100644 --- a/source/blender/bmesh/operators/bmo_bisect_plane.c +++ b/source/blender/bmesh/operators/bmo_bisect_plane.c @@ -65,9 +65,9 @@ void bmo_bisect_plane_exec(BMesh *bm, BMOperator *op) BM_mesh_bisect_plane(bm, plane, use_snap_center, true, ELE_CUT, ELE_NEW, dist); if (clear_outer || clear_inner) { - /* Use an array of vertices because 'geom' contains both vers and edges that may use them. - * Removing a vert may remove and edge which is later checked by BMO_ITER. - * over-alloc the total possible vert count */ + /* Use an array of vertices because 'geom' contains both verts and edges that may use them. + * Removing a vert may remove and edge which is later checked by #BMO_ITER. + * over-allocate the total possible vert count. */ const int vert_arr_max = min_ii(bm->totvert, BMO_slot_buffer_count(op->slots_in, "geom")); BMVert **vert_arr = MEM_mallocN(sizeof(*vert_arr) * (size_t)vert_arr_max, __func__); BMOIter siter; diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.cpp b/source/blender/compositor/intern/COM_ExecutionGroup.cpp index e5dfee7d0cd..08f794d7eba 100644 --- a/source/blender/compositor/intern/COM_ExecutionGroup.cpp +++ b/source/blender/compositor/intern/COM_ExecutionGroup.cpp @@ -198,13 +198,13 @@ void ExecutionGroup::execute(ExecutionSystem *graph) const bNodeTree *bTree = context.getbNodeTree(); if (this->m_width == 0 || this->m_height == 0) { return; - } /// \note Break out... no pixels to calculate. + } /** \note Break out... no pixels to calculate. */ if (bTree->test_break && bTree->test_break(bTree->tbh)) { return; - } /// \note Early break out for blur and preview nodes. + } /** \note Early break out for blur and preview nodes. */ if (this->m_numberOfChunks == 0) { return; - } /// \note Early break out. + } /** \note Early break out. */ unsigned int chunkNumber; this->m_executionStartTime = PIL_check_seconds_timer(); diff --git a/source/blender/compositor/intern/COM_NodeGraph.cpp b/source/blender/compositor/intern/COM_NodeGraph.cpp index 01dd662ad11..fe680f61a90 100644 --- a/source/blender/compositor/intern/COM_NodeGraph.cpp +++ b/source/blender/compositor/intern/COM_NodeGraph.cpp @@ -184,7 +184,7 @@ NodeOutput *NodeGraph::find_output(const NodeRange &node_range, bNodeSocket *b_s void NodeGraph::add_bNodeLink(const NodeRange &node_range, bNodeLink *b_nodelink) { - /// \note Ignore invalid links. + /** \note Ignore invalid links. */ if (!(b_nodelink->flag & NODE_LINK_VALID)) { return; } diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cpp b/source/blender/compositor/intern/COM_WorkScheduler.cpp index 06929f0037e..570e1eeba20 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.cpp +++ b/source/blender/compositor/intern/COM_WorkScheduler.cpp @@ -44,26 +44,26 @@ # error COM_CURRENT_THREADING_MODEL No threading model selected #endif -/// \brief list of all CPUDevices. for every hardware thread an instance of CPUDevice is created +/** \brief list of all CPUDevices. for every hardware thread an instance of CPUDevice is created */ static vector<CPUDevice *> g_cpudevices; static ThreadLocal(CPUDevice *) g_thread_device; #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE -/// \brief list of all thread for every CPUDevice in cpudevices a thread exists +/** \brief list of all thread for every CPUDevice in cpudevices a thread exists. */ static ListBase g_cputhreads; static bool g_cpuInitialized = false; -/// \brief all scheduled work for the cpu +/** \brief all scheduled work for the cpu */ static ThreadQueue *g_cpuqueue; static ThreadQueue *g_gpuqueue; # ifdef COM_OPENCL_ENABLED static cl_context g_context; static cl_program g_program; -/// \brief list of all OpenCLDevices. for every OpenCL GPU device an instance of OpenCLDevice is -/// created +/** \brief list of all OpenCLDevices. for every OpenCL GPU device an instance of OpenCLDevice is + * created. */ static vector<OpenCLDevice *> g_gpudevices; -/// \brief list of all thread for every GPUDevice in cpudevices a thread exists +/** \brief list of all thread for every GPUDevice in cpudevices a thread exists. */ static ListBase g_gputhreads; -/// \brief all scheduled work for the gpu +/** \brief all scheduled work for the GPU. */ static bool g_openclActive = false; static bool g_openclInitialized = false; # endif diff --git a/source/blender/compositor/nodes/COM_ImageNode.cpp b/source/blender/compositor/nodes/COM_ImageNode.cpp index 3dbd3773247..c178722a23f 100644 --- a/source/blender/compositor/nodes/COM_ImageNode.cpp +++ b/source/blender/compositor/nodes/COM_ImageNode.cpp @@ -72,7 +72,7 @@ NodeOperation *ImageNode::doMultilayerCheck(NodeConverter &converter, void ImageNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { - /// Image output + /** Image output */ NodeOutput *outputImage = this->getOutputSocket(0); bNode *editorNode = this->getbNode(); Image *image = (Image *)editorNode->id; diff --git a/source/blender/compositor/operations/COM_BokehImageOperation.h b/source/blender/compositor/operations/COM_BokehImageOperation.h index db1d3976d44..7e3c026ace8 100644 --- a/source/blender/compositor/operations/COM_BokehImageOperation.h +++ b/source/blender/compositor/operations/COM_BokehImageOperation.h @@ -29,7 +29,7 @@ * - angle offset of the flaps * - rounding of the flaps (also used to make a circular lens) * - simulate catadioptric - * - simulate lensshift + * - simulate lens-shift * * Per pixel the algorithm determines the edge of the bokeh on the same line as the center of the *image and the pixel is evaluating. diff --git a/source/blender/compositor/operations/COM_ReadBufferOperation.cpp b/source/blender/compositor/operations/COM_ReadBufferOperation.cpp index 70aaab560cd..99cc9f5dd01 100644 --- a/source/blender/compositor/operations/COM_ReadBufferOperation.cpp +++ b/source/blender/compositor/operations/COM_ReadBufferOperation.cpp @@ -41,7 +41,7 @@ void ReadBufferOperation::determineResolution(unsigned int resolution[2], operation->determineResolution(resolution, preferredResolution); operation->setResolution(resolution); - /// \todo: may not occur!, but does with blur node + /** \todo: may not occur!, but does with blur node */ if (this->m_memoryProxy->getExecutor()) { this->m_memoryProxy->getExecutor()->setResolution(resolution); } diff --git a/source/blender/compositor/operations/COM_ViewerOperation.cpp b/source/blender/compositor/operations/COM_ViewerOperation.cpp index 3d5d50e1c7f..e1d891559a7 100644 --- a/source/blender/compositor/operations/COM_ViewerOperation.cpp +++ b/source/blender/compositor/operations/COM_ViewerOperation.cpp @@ -190,7 +190,7 @@ void ViewerOperation::updateImage(rcti *rect) rect->ymin, rect->xmax, rect->ymax); - + this->m_image->gpuflag |= IMA_GPU_REFRESH; this->updateDraw(); } diff --git a/source/blender/depsgraph/intern/depsgraph_physics.cc b/source/blender/depsgraph/intern/depsgraph_physics.cc index 76f3a2e8ff4..0b8203ab05f 100644 --- a/source/blender/depsgraph/intern/depsgraph_physics.cc +++ b/source/blender/depsgraph/intern/depsgraph_physics.cc @@ -62,17 +62,28 @@ static ePhysicsRelationType modifier_to_relation_type(unsigned int modifier_type BLI_assert(!"Unknown collision modifier type"); return DEG_PHYSICS_RELATIONS_NUM; } +/* Get ID from an ID type object, in a safe manner. This means that object can be nullptr, + * in which case the function returns nullptr. + */ +template<class T> static ID *object_id_safe(T *object) +{ + if (object == nullptr) { + return nullptr; + } + return &object->id; +} ListBase *DEG_get_effector_relations(const Depsgraph *graph, Collection *collection) { const deg::Depsgraph *deg_graph = reinterpret_cast<const deg::Depsgraph *>(graph); - if (deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR] == nullptr) { + blender::Map<const ID *, ListBase *> *hash = deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR]; + if (hash == nullptr) { return nullptr; } - - ID *collection_orig = DEG_get_original_id(&collection->id); - return deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR]->lookup_default(collection_orig, - nullptr); + /* Note: nullptr is a valid lookup key here as it means that the relation is not bound to a + * specific collection. */ + ID *collection_orig = DEG_get_original_id(object_id_safe(collection)); + return hash->lookup_default(collection_orig, nullptr); } ListBase *DEG_get_collision_relations(const Depsgraph *graph, @@ -81,11 +92,14 @@ ListBase *DEG_get_collision_relations(const Depsgraph *graph, { const deg::Depsgraph *deg_graph = reinterpret_cast<const deg::Depsgraph *>(graph); const ePhysicsRelationType type = modifier_to_relation_type(modifier_type); - if (deg_graph->physics_relations[type] == nullptr) { + blender::Map<const ID *, ListBase *> *hash = deg_graph->physics_relations[type]; + if (hash == nullptr) { return nullptr; } - ID *collection_orig = DEG_get_original_id(&collection->id); - return deg_graph->physics_relations[type]->lookup_default(collection_orig, nullptr); + /* Note: nullptr is a valid lookup key here as it means that the relation is not bound to a + * specific collection. */ + ID *collection_orig = DEG_get_original_id(object_id_safe(collection)); + return hash->lookup_default(collection_orig, nullptr); } /********************** Depsgraph Building API ************************/ @@ -170,7 +184,12 @@ ListBase *build_effector_relations(Depsgraph *graph, Collection *collection) graph->physics_relations[DEG_PHYSICS_EFFECTOR] = new Map<const ID *, ListBase *>(); hash = graph->physics_relations[DEG_PHYSICS_EFFECTOR]; } - return hash->lookup_or_add_cb(&collection->id, [&]() { + /* If collection is nullptr still use it as a key. + * In this case the BKE_effector_relations_create() will create relates for all bases in the + * view layer. + */ + ID *collection_id = object_id_safe(collection); + return hash->lookup_or_add_cb(collection_id, [&]() { ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph *>(graph); return BKE_effector_relations_create(depsgraph, graph->view_layer, collection); }); @@ -186,7 +205,12 @@ ListBase *build_collision_relations(Depsgraph *graph, graph->physics_relations[type] = new Map<const ID *, ListBase *>(); hash = graph->physics_relations[type]; } - return hash->lookup_or_add_cb(&collection->id, [&]() { + /* If collection is nullptr still use it as a key. + * In this case the BKE_collision_relations_create() will create relates for all bases in the + * view layer. + */ + ID *collection_id = object_id_safe(collection); + return hash->lookup_or_add_cb(collection_id, [&]() { ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph *>(graph); return BKE_collision_relations_create(depsgraph, collection, modifier_type); }); diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 8aea2f8e969..8fbf30507a5 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -77,6 +77,8 @@ set(SRC intern/draw_select_buffer.c intern/draw_view.c engines/basic/basic_engine.c + engines/image/image_engine.c + engines/image/image_shader.c engines/eevee/eevee_bloom.c engines/eevee/eevee_data.c engines/eevee/eevee_depth_of_field.c @@ -132,6 +134,7 @@ set(SRC engines/overlay/overlay_edit_curve.c engines/overlay/overlay_edit_mesh.c engines/overlay/overlay_edit_text.c + engines/overlay/overlay_edit_uv.c engines/overlay/overlay_engine.c engines/overlay/overlay_extra.c engines/overlay/overlay_facing.c @@ -319,6 +322,7 @@ data_to_c_simple(engines/basic/shaders/conservative_depth_geom.glsl SRC) data_to_c_simple(engines/basic/shaders/depth_vert.glsl SRC) data_to_c_simple(engines/basic/shaders/depth_frag.glsl SRC) +data_to_c_simple(engines/overlay/shaders/common_overlay_lib.glsl SRC) data_to_c_simple(engines/overlay/shaders/antialiasing_frag.glsl SRC) data_to_c_simple(engines/overlay/shaders/antialiasing_vert.glsl SRC) data_to_c_simple(engines/overlay/shaders/armature_dof_vert.glsl SRC) @@ -362,6 +366,15 @@ data_to_c_simple(engines/overlay/shaders/edit_mesh_skin_root_vert.glsl SRC) data_to_c_simple(engines/overlay/shaders/edit_mesh_vert.glsl SRC) data_to_c_simple(engines/overlay/shaders/edit_particle_strand_vert.glsl SRC) data_to_c_simple(engines/overlay/shaders/edit_particle_point_vert.glsl SRC) +data_to_c_simple(engines/overlay/shaders/edit_uv_edges_vert.glsl SRC) +data_to_c_simple(engines/overlay/shaders/edit_uv_edges_geom.glsl SRC) +data_to_c_simple(engines/overlay/shaders/edit_uv_edges_frag.glsl SRC) +data_to_c_simple(engines/overlay/shaders/edit_uv_verts_vert.glsl SRC) +data_to_c_simple(engines/overlay/shaders/edit_uv_verts_frag.glsl SRC) +data_to_c_simple(engines/overlay/shaders/edit_uv_faces_vert.glsl SRC) +data_to_c_simple(engines/overlay/shaders/edit_uv_face_dots_vert.glsl SRC) +data_to_c_simple(engines/overlay/shaders/edit_uv_stretching_vert.glsl SRC) +data_to_c_simple(engines/overlay/shaders/edit_uv_tiled_image_borders_vert.glsl SRC) data_to_c_simple(engines/overlay/shaders/extra_frag.glsl SRC) data_to_c_simple(engines/overlay/shaders/extra_vert.glsl SRC) data_to_c_simple(engines/overlay/shaders/extra_groundline_vert.glsl SRC) @@ -402,6 +415,9 @@ data_to_c_simple(engines/overlay/shaders/wireframe_vert.glsl SRC) data_to_c_simple(engines/overlay/shaders/wireframe_frag.glsl SRC) data_to_c_simple(engines/overlay/shaders/xray_fade_frag.glsl SRC) +data_to_c_simple(engines/image/shaders/engine_image_frag.glsl SRC) +data_to_c_simple(engines/image/shaders/engine_image_vert.glsl SRC) + list(APPEND INC ) diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h index 6db3bb39643..ca5c2c94b40 100644 --- a/source/blender/draw/DRW_engine.h +++ b/source/blender/draw/DRW_engine.h @@ -99,6 +99,10 @@ void DRW_draw_render_loop_offscreen(struct Depsgraph *depsgraph, const bool do_color_management, struct GPUOffScreen *ofs, struct GPUViewport *viewport); +void DRW_draw_render_loop_2d_ex(struct Depsgraph *depsgraph, + struct ARegion *region, + struct GPUViewport *viewport, + const struct bContext *evil_C); void DRW_draw_select_loop(struct Depsgraph *depsgraph, struct ARegion *region, struct View3D *v3d, diff --git a/source/blender/draw/engines/basic/basic_engine.c b/source/blender/draw/engines/basic/basic_engine.c index 94c380b3b50..89b659cfa8a 100644 --- a/source/blender/draw/engines/basic/basic_engine.c +++ b/source/blender/draw/engines/basic/basic_engine.c @@ -46,7 +46,7 @@ extern char datatoc_common_view_lib_glsl[]; /* *********** LISTS *********** */ /* GPUViewport.storage - * Is freed everytime the viewport engine changes */ + * Is freed every time the viewport engine changes. */ typedef struct BASIC_StorageList { struct BASIC_PrivateData *g_data; } BASIC_StorageList; diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.c b/source/blender/draw/engines/eevee/eevee_lightcache.c index f23cca41215..4904f34a00b 100644 --- a/source/blender/draw/engines/eevee/eevee_lightcache.c +++ b/source/blender/draw/engines/eevee/eevee_lightcache.c @@ -388,8 +388,8 @@ LightCache *EEVEE_lightcache_create(const int grid_len, static bool eevee_lightcache_static_load(LightCache *lcache) { /* We use fallback if a texture is not setup and there is no data to restore it. */ - if ((!lcache->grid_tx.tex && !lcache->grid_tx.data) || - (!lcache->cube_tx.tex && !lcache->cube_tx.data)) { + if ((!lcache->grid_tx.tex && !lcache->grid_tx.data) || !lcache->grid_data || + (!lcache->cube_tx.tex && !lcache->cube_tx.data) || !lcache->cube_data) { return false; } /* If cache is too big for this GPU. */ diff --git a/source/blender/draw/engines/eevee/shaders/closure_lib.glsl b/source/blender/draw/engines/eevee/shaders/closure_lib.glsl index e572245ace9..b56a186ab3f 100644 --- a/source/blender/draw/engines/eevee/shaders/closure_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/closure_lib.glsl @@ -36,7 +36,7 @@ struct Closure { Closure nodetree_exec(void); /* clang-format off */ -/* Avoid multiline defines. */ +/* Avoid multi-line defines. */ #ifdef VOLUMETRICS # define CLOSURE_DEFAULT Closure(vec3(0), vec3(0), vec3(0), 0.0) #elif !defined(USE_SSS) diff --git a/source/blender/draw/engines/external/external_engine.c b/source/blender/draw/engines/external/external_engine.c index 36d295d1dde..f7303f8cc6f 100644 --- a/source/blender/draw/engines/external/external_engine.c +++ b/source/blender/draw/engines/external/external_engine.c @@ -52,7 +52,7 @@ extern char datatoc_common_view_lib_glsl[]; /* *********** LISTS *********** */ /* GPUViewport.storage - * Is freed everytime the viewport engine changes */ + * Is freed every time the viewport engine changes. */ typedef struct EXTERNAL_Storage { int dummy; } EXTERNAL_Storage; diff --git a/source/blender/draw/engines/image/image_engine.c b/source/blender/draw/engines/image/image_engine.c new file mode 100644 index 00000000000..9f1278b473b --- /dev/null +++ b/source/blender/draw/engines/image/image_engine.c @@ -0,0 +1,304 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2020, Blender Foundation. + */ + +/** \file + * \ingroup draw_editors + * + * Draw engine to draw the Image/UV editor + */ + +#include "DRW_render.h" + +#include "BKE_image.h" +#include "BKE_object.h" + +#include "DNA_camera_types.h" + +#include "IMB_imbuf_types.h" + +#include "ED_image.h" + +#include "GPU_batch.h" + +#include "image_engine.h" +#include "image_private.h" + +#define SIMA_DRAW_FLAG_SHOW_ALPHA (1 << 0) +#define SIMA_DRAW_FLAG_APPLY_ALPHA (1 << 1) +#define SIMA_DRAW_FLAG_SHUFFLING (1 << 2) +#define SIMA_DRAW_FLAG_DEPTH (1 << 3) +#define SIMA_DRAW_FLAG_TILED (1 << 4) +#define SIMA_DRAW_FLAG_DO_REPEAT (1 << 5) + +static void image_cache_image_add(DRWShadingGroup *grp, Image *image) +{ + const bool is_tiled_texture = image && image->source == IMA_SRC_TILED; + float obmat[4][4]; + unit_m4(obmat); + + GPUBatch *geom = DRW_cache_quad_get(); + + if (is_tiled_texture) { + LISTBASE_FOREACH (ImageTile *, tile, &image->tiles) { + const int tile_x = ((tile->tile_number - 1001) % 10); + const int tile_y = ((tile->tile_number - 1001) / 10); + obmat[3][1] = (float)tile_y; + obmat[3][0] = (float)tile_x; + DRW_shgroup_call_obmat(grp, geom, obmat); + } + } + else { + DRW_shgroup_call_obmat(grp, geom, obmat); + } +} + +static void image_gpu_texture_get(Image *image, + ImageUser *iuser, + ImBuf *ibuf, + GPUTexture **r_gpu_texture, + bool *r_owns_texture, + GPUTexture **r_tex_tile_data) +{ + + const DRWContextState *draw_ctx = DRW_context_state_get(); + SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + + if (image) { + if (BKE_image_is_multilayer(image)) { + /* update multiindex and pass for the current eye */ + BKE_image_multilayer_index(image->rr, &sima->iuser); + } + else { + BKE_image_multiview_index(image, &sima->iuser); + } + + if (ibuf) { + if (sima->flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) { + if (ibuf->zbuf) { + BLI_assert(!"Integer based depth buffers not supported"); + } + else if (ibuf->zbuf_float) { + *r_gpu_texture = GPU_texture_create_2d( + __func__, ibuf->x, ibuf->y, 0, GPU_R16F, ibuf->zbuf_float); + *r_owns_texture = true; + } + else if (ibuf->rect_float && ibuf->channels == 1) { + *r_gpu_texture = GPU_texture_create_2d( + __func__, ibuf->x, ibuf->y, 0, GPU_R16F, ibuf->rect_float); + *r_owns_texture = true; + } + } + else if (image->source == IMA_SRC_TILED) { + *r_gpu_texture = BKE_image_get_gpu_tiles(image, iuser, ibuf); + *r_tex_tile_data = BKE_image_get_gpu_tilemap(image, iuser, NULL); + *r_owns_texture = false; + } + else { + *r_gpu_texture = BKE_image_get_gpu_texture(image, iuser, ibuf); + *r_owns_texture = false; + } + } + } +} + +static void image_cache_image(IMAGE_Data *vedata, Image *image, ImageUser *iuser, ImBuf *ibuf) +{ + IMAGE_PassList *psl = vedata->psl; + IMAGE_StorageList *stl = vedata->stl; + IMAGE_PrivateData *pd = stl->pd; + + const DRWContextState *draw_ctx = DRW_context_state_get(); + const Scene *scene = draw_ctx->scene; + SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + + GPUTexture *tex_tile_data = NULL; + image_gpu_texture_get(image, iuser, ibuf, &pd->texture, &pd->owns_texture, &tex_tile_data); + + if (pd->texture) { + static float color[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + static float shuffle[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + static float far_near[2] = {100.0f, 0.0f}; + + if (scene->camera && scene->camera->type == OB_CAMERA) { + far_near[1] = ((Camera *)scene->camera->data)->clip_start; + far_near[0] = ((Camera *)scene->camera->data)->clip_end; + } + + const bool use_premul_alpha = image->alpha_mode == IMA_ALPHA_PREMUL; + const bool is_tiled_texture = tex_tile_data != NULL; + const bool do_repeat = (!is_tiled_texture) && ((sima->flag & SI_DRAW_TILE) != 0); + const bool is_zoom_out = sima->zoom < 1.0f; + + /* use interpolation filtering when zooming out */ + eGPUSamplerState state = 0; + SET_FLAG_FROM_TEST(state, is_zoom_out, GPU_SAMPLER_FILTER); + + int draw_flags = 0; + SET_FLAG_FROM_TEST(draw_flags, do_repeat, SIMA_DRAW_FLAG_DO_REPEAT); + + if ((sima->flag & SI_USE_ALPHA) != 0) { + /* Show RGBA */ + draw_flags |= SIMA_DRAW_FLAG_SHOW_ALPHA | SIMA_DRAW_FLAG_APPLY_ALPHA; + } + else if ((sima->flag & SI_SHOW_ALPHA) != 0) { + draw_flags |= SIMA_DRAW_FLAG_SHUFFLING; + copy_v4_fl4(shuffle, 0.0f, 0.0f, 0.0f, 1.0f); + } + else if ((sima->flag & SI_SHOW_ZBUF) != 0) { + draw_flags |= SIMA_DRAW_FLAG_DEPTH | SIMA_DRAW_FLAG_SHUFFLING; + copy_v4_fl4(shuffle, 1.0f, 0.0f, 0.0f, 0.0f); + } + else if ((sima->flag & SI_SHOW_R) != 0) { + draw_flags |= SIMA_DRAW_FLAG_APPLY_ALPHA | SIMA_DRAW_FLAG_SHUFFLING; + copy_v4_fl4(shuffle, 1.0f, 0.0f, 0.0f, 0.0f); + } + else if ((sima->flag & SI_SHOW_G) != 0) { + draw_flags |= SIMA_DRAW_FLAG_APPLY_ALPHA | SIMA_DRAW_FLAG_SHUFFLING; + copy_v4_fl4(shuffle, 0.0f, 1.0f, 0.0f, 0.0f); + } + else if ((sima->flag & SI_SHOW_B) != 0) { + draw_flags |= SIMA_DRAW_FLAG_APPLY_ALPHA | SIMA_DRAW_FLAG_SHUFFLING; + copy_v4_fl4(shuffle, 0.0f, 0.0f, 1.0f, 0.0f); + } + else /* RGB */ { + draw_flags |= SIMA_DRAW_FLAG_APPLY_ALPHA; + } + + GPUShader *shader = IMAGE_shader_image_get(); + DRWShadingGroup *shgrp = DRW_shgroup_create(shader, psl->image_pass); + if (tex_tile_data != NULL) { + draw_flags |= SIMA_DRAW_FLAG_TILED; + DRW_shgroup_uniform_texture_ex(shgrp, "imageTileArray", pd->texture, state); + DRW_shgroup_uniform_texture(shgrp, "imageTileData", tex_tile_data); + } + else { + DRW_shgroup_uniform_texture_ex(shgrp, "imageTexture", pd->texture, state); + } + DRW_shgroup_uniform_vec2_copy(shgrp, "farNearDistances", far_near); + DRW_shgroup_uniform_vec4_copy(shgrp, "color", color); + DRW_shgroup_uniform_vec4_copy(shgrp, "shuffle", shuffle); + DRW_shgroup_uniform_int_copy(shgrp, "drawFlags", draw_flags); + DRW_shgroup_uniform_bool_copy(shgrp, "imgPremultiplied", use_premul_alpha); + image_cache_image_add(shgrp, image); + } +} + +/* -------------------------------------------------------------------- */ +/** \name Engine Callbacks + * \{ */ +static void IMAGE_engine_init(void *ved) +{ + IMAGE_shader_library_ensure(); + IMAGE_Data *vedata = (IMAGE_Data *)ved; + IMAGE_StorageList *stl = vedata->stl; + if (!stl->pd) { + stl->pd = MEM_callocN(sizeof(IMAGE_PrivateData), __func__); + } + IMAGE_PrivateData *pd = stl->pd; + + pd->ibuf = NULL; + pd->lock = NULL; + pd->texture = NULL; +} + +static void IMAGE_cache_init(void *ved) +{ + IMAGE_Data *vedata = (IMAGE_Data *)ved; + IMAGE_StorageList *stl = vedata->stl; + IMAGE_PrivateData *pd = stl->pd; + IMAGE_PassList *psl = vedata->psl; + + const DRWContextState *draw_ctx = DRW_context_state_get(); + SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + + { + /* Write depth is needed for background overlay rendering. Near depth is used for + * transparency checker and Far depth is used for indicating the image size. */ + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS | + DRW_STATE_BLEND_ALPHA_PREMUL; + psl->image_pass = DRW_pass_create("Image", state); + } + + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + GPU_framebuffer_bind(dfbl->default_fb); + static float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + GPU_framebuffer_clear_color_depth(dfbl->default_fb, clear_col, 1.0); + + { + Image *image = ED_space_image(sima); + ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &pd->lock, 0); + image_cache_image(vedata, image, &sima->iuser, ibuf); + pd->ibuf = ibuf; + } +} + +static void IMAGE_cache_populate(void *UNUSED(vedata), Object *UNUSED(ob)) +{ + /* Function intentional left empty. `cache_populate` is required to be implemented. */ +} + +static void image_draw_finish(IMAGE_Data *ved) +{ + IMAGE_Data *vedata = (IMAGE_Data *)ved; + IMAGE_StorageList *stl = vedata->stl; + IMAGE_PrivateData *pd = stl->pd; + const DRWContextState *draw_ctx = DRW_context_state_get(); + SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + + ED_space_image_release_buffer(sima, pd->ibuf, pd->lock); + + if (pd->texture && pd->owns_texture) { + GPU_texture_free(pd->texture); + pd->owns_texture = false; + } + pd->texture = NULL; +} + +static void IMAGE_draw_scene(void *ved) +{ + IMAGE_Data *vedata = (IMAGE_Data *)ved; + IMAGE_PassList *psl = vedata->psl; + + DRW_draw_pass(psl->image_pass); + + image_draw_finish(vedata); +} + +static void IMAGE_engine_free(void) +{ + IMAGE_shader_free(); +} + +/* \} */ +static const DrawEngineDataSize IMAGE_data_size = DRW_VIEWPORT_DATA_SIZE(IMAGE_Data); + +DrawEngineType draw_engine_image_type = { + NULL, /* next */ + NULL, /* prev */ + N_("UV/Image"), /* idname */ + &IMAGE_data_size, /* vedata_size */ + &IMAGE_engine_init, /* engine_init */ + &IMAGE_engine_free, /* engine_free */ + &IMAGE_cache_init, /* cache_init */ + &IMAGE_cache_populate, /* cache_populate */ + NULL, /* cache_finish */ + &IMAGE_draw_scene, /* draw_scene */ + NULL, /* view_update */ + NULL, /* id_update */ + NULL, /* render_to_image */ +}; diff --git a/source/blender/draw/engines/image/image_engine.h b/source/blender/draw/engines/image/image_engine.h new file mode 100644 index 00000000000..0098d863ef9 --- /dev/null +++ b/source/blender/draw/engines/image/image_engine.h @@ -0,0 +1,25 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2020, Blender Foundation. + */ + +/** \file + * \ingroup draw_editors + */ + +#pragma once + +extern DrawEngineType draw_engine_image_type; diff --git a/source/blender/draw/engines/image/image_private.h b/source/blender/draw/engines/image/image_private.h new file mode 100644 index 00000000000..d11d868d4d2 --- /dev/null +++ b/source/blender/draw/engines/image/image_private.h @@ -0,0 +1,69 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2020, Blender Foundation. + */ + +/** \file + * \ingroup draw_engine + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Forward declarations */ +struct rcti; +struct GPUBatch; +struct Image; +struct ImBuf; +struct GPUTexture; + +/* *********** LISTS *********** */ + +/* GPUViewport.storage + * Is freed everytime the viewport engine changes */ +typedef struct IMAGE_PassList { + DRWPass *image_pass; +} IMAGE_PassList; + +typedef struct IMAGE_PrivateData { + void *lock; + struct ImBuf *ibuf; + + struct GPUTexture *texture; + bool owns_texture; +} IMAGE_PrivateData; + +typedef struct IMAGE_StorageList { + IMAGE_PrivateData *pd; +} IMAGE_StorageList; + +typedef struct IMAGE_Data { + void *engine_type; + DRWViewportEmptyList *fbl; + DRWViewportEmptyList *txl; + IMAGE_PassList *psl; + IMAGE_StorageList *stl; +} IMAGE_Data; + +/* image_shader.c */ +GPUShader *IMAGE_shader_image_get(void); +void IMAGE_shader_library_ensure(void); +void IMAGE_shader_free(void); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/draw/engines/image/image_shader.c b/source/blender/draw/engines/image/image_shader.c new file mode 100644 index 00000000000..433c79e20cf --- /dev/null +++ b/source/blender/draw/engines/image/image_shader.c @@ -0,0 +1,77 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2020, Blender Foundation. + */ + +/** \file + * \ingroup draw_engine + */ + +#include "DRW_render.h" + +#include "BLI_dynstr.h" + +#include "GPU_batch.h" + +#include "image_engine.h" +#include "image_private.h" + +extern char datatoc_common_colormanagement_lib_glsl[]; +extern char datatoc_common_globals_lib_glsl[]; +extern char datatoc_common_view_lib_glsl[]; + +extern char datatoc_engine_image_frag_glsl[]; +extern char datatoc_engine_image_vert_glsl[]; + +typedef struct IMAGE_Shaders { + GPUShader *image_sh; +} IMAGE_Shaders; + +static struct { + IMAGE_Shaders shaders; + DRWShaderLibrary *lib; +} e_data = {0}; /* Engine data */ + +void IMAGE_shader_library_ensure(void) +{ + if (e_data.lib == NULL) { + e_data.lib = DRW_shader_library_create(); + /* NOTE: Theses needs to be ordered by dependencies. */ + DRW_SHADER_LIB_ADD(e_data.lib, common_colormanagement_lib); + DRW_SHADER_LIB_ADD(e_data.lib, common_globals_lib); + DRW_SHADER_LIB_ADD(e_data.lib, common_view_lib); + } +} + +GPUShader *IMAGE_shader_image_get(void) +{ + IMAGE_Shaders *sh_data = &e_data.shaders; + if (!sh_data->image_sh) { + sh_data->image_sh = DRW_shader_create_with_shaderlib( + datatoc_engine_image_vert_glsl, NULL, datatoc_engine_image_frag_glsl, e_data.lib, NULL); + } + return sh_data->image_sh; +} + +void IMAGE_shader_free(void) +{ + GPUShader **sh_data_as_array = (GPUShader **)&e_data.shaders; + for (int i = 0; i < (sizeof(IMAGE_Shaders) / sizeof(GPUShader *)); i++) { + DRW_SHADER_FREE_SAFE(sh_data_as_array[i]); + } + + DRW_SHADER_LIB_FREE_SAFE(e_data.lib); +}
\ No newline at end of file diff --git a/source/blender/draw/engines/image/shaders/engine_image_frag.glsl b/source/blender/draw/engines/image/shaders/engine_image_frag.glsl new file mode 100644 index 00000000000..5c5d9362dfc --- /dev/null +++ b/source/blender/draw/engines/image/shaders/engine_image_frag.glsl @@ -0,0 +1,91 @@ +#pragma BLENDER_REQUIRE(common_colormanagement_lib.glsl) + +/* Keep in sync with image_engine.c */ +#define SIMA_DRAW_FLAG_SHOW_ALPHA (1 << 0) +#define SIMA_DRAW_FLAG_APPLY_ALPHA (1 << 1) +#define SIMA_DRAW_FLAG_SHUFFLING (1 << 2) +#define SIMA_DRAW_FLAG_DEPTH (1 << 3) +#define SIMA_DRAW_FLAG_TILED (1 << 4) +#define SIMA_DRAW_FLAG_DO_REPEAT (1 << 5) + +uniform sampler2DArray imageTileArray; +uniform sampler1DArray imageTileData; +uniform sampler2D imageTexture; + +uniform bool imgPremultiplied; +uniform int drawFlags; +uniform vec2 farNearDistances; +uniform vec4 color; +uniform vec4 shuffle; + +#define FAR_DISTANCE farNearDistances.x +#define NEAR_DISTANCE farNearDistances.y + +in vec2 uvs; + +out vec4 fragColor; + +/* TODO(fclem) deduplicate code. */ +bool node_tex_tile_lookup(inout vec3 co, sampler2DArray ima, sampler1DArray map) +{ + vec2 tile_pos = floor(co.xy); + + if (tile_pos.x < 0 || tile_pos.y < 0 || tile_pos.x >= 10) { + return false; + } + + float tile = 10.0 * tile_pos.y + tile_pos.x; + if (tile >= textureSize(map, 0).x) { + return false; + } + + /* Fetch tile information. */ + float tile_layer = texelFetch(map, ivec2(tile, 0), 0).x; + if (tile_layer < 0.0) { + return false; + } + + vec4 tile_info = texelFetch(map, ivec2(tile, 1), 0); + + co = vec3(((co.xy - tile_pos) * tile_info.zw) + tile_info.xy, tile_layer); + return true; +} + +void main() +{ + vec4 tex_color; + /* Read texture */ + if ((drawFlags & SIMA_DRAW_FLAG_TILED) != 0) { + vec3 co = vec3(uvs, 0.0); + if (node_tex_tile_lookup(co, imageTileArray, imageTileData)) { + tex_color = texture(imageTileArray, co); + } + else { + tex_color = vec4(1.0, 0.0, 1.0, 1.0); + } + } + else { + vec2 uvs_clamped = ((drawFlags & SIMA_DRAW_FLAG_DO_REPEAT) != 0) ? + fract(uvs) : + clamp(uvs, vec2(0.0), vec2(1.0)); + tex_color = texture(imageTexture, uvs_clamped); + } + + if ((drawFlags & SIMA_DRAW_FLAG_APPLY_ALPHA) != 0) { + if (!imgPremultiplied && tex_color.a != 0.0 && tex_color.a != 1.0) { + tex_color.rgb *= tex_color.a; + } + } + if ((drawFlags & SIMA_DRAW_FLAG_DEPTH) != 0) { + tex_color = smoothstep(FAR_DISTANCE, NEAR_DISTANCE, tex_color); + } + + if ((drawFlags & SIMA_DRAW_FLAG_SHUFFLING) != 0) { + tex_color = color * dot(tex_color, shuffle); + } + if ((drawFlags & SIMA_DRAW_FLAG_SHOW_ALPHA) == 0) { + tex_color.a = 1.0; + } + + fragColor = tex_color; +} diff --git a/source/blender/draw/engines/image/shaders/engine_image_vert.glsl b/source/blender/draw/engines/image/shaders/engine_image_vert.glsl new file mode 100644 index 00000000000..3f1fb154d44 --- /dev/null +++ b/source/blender/draw/engines/image/shaders/engine_image_vert.glsl @@ -0,0 +1,31 @@ +#pragma BLENDER_REQUIRE(common_view_lib.glsl) + +#define SIMA_DRAW_FLAG_DO_REPEAT (1 << 5) + +uniform int drawFlags; + +in vec3 pos; +out vec2 uvs; + +void main() +{ + /* `pos` contains the coordinates of a quad (-1..1). but we need the coordinates of an image + * plane (0..1) */ + vec3 image_pos = pos * 0.5 + 0.5; + + if ((drawFlags & SIMA_DRAW_FLAG_DO_REPEAT) != 0) { + gl_Position = vec4(pos.xy, 0.0, 1.0); + uvs = point_view_to_object(image_pos).xy; + } + else { + vec3 world_pos = point_object_to_world(image_pos); + vec4 position = point_world_to_ndc(world_pos); + /* Move drawn pixels to the front. In the overlay engine the depth is used + * to detect if a transparency texture or the background color should be drawn. + * Vertices are between 0.0 and 0.2, Edges between 0.2 and 0.4 + * actual pixels are at 0.75, 1.0 is used for the background. */ + position.z = 0.75; + gl_Position = position; + uvs = world_pos.xy; + } +} diff --git a/source/blender/draw/engines/overlay/overlay_background.c b/source/blender/draw/engines/overlay/overlay_background.c index f52ae691a35..cb09d916a0f 100644 --- a/source/blender/draw/engines/overlay/overlay_background.c +++ b/source/blender/draw/engines/overlay/overlay_background.c @@ -31,6 +31,7 @@ #define BG_GRADIENT 1 #define BG_CHECKER 2 #define BG_RADIAL 3 +#define BG_SOLID_CHECKER 4 void OVERLAY_background_cache_init(OVERLAY_Data *vedata) { @@ -40,7 +41,7 @@ void OVERLAY_background_cache_init(OVERLAY_Data *vedata) const DRWContextState *draw_ctx = DRW_context_state_get(); const Scene *scene = draw_ctx->scene; const RegionView3D *rv3d = draw_ctx->rv3d; - const BoundBox *bb = rv3d->clipbb; + const BoundBox *bb = rv3d ? rv3d->clipbb : NULL; const View3D *v3d = draw_ctx->v3d; bool draw_clipping_bounds = (pd->clipping_state != 0); @@ -50,9 +51,11 @@ void OVERLAY_background_cache_init(OVERLAY_Data *vedata) if (DRW_state_is_opengl_render() && !DRW_state_draw_background()) { background_type = BG_SOLID; - zero_v3(color_override); color_override[3] = 1.0f; } + else if (pd->is_image_editor) { + background_type = BG_SOLID_CHECKER; + } else if (!DRW_state_draw_background()) { background_type = BG_CHECKER; } diff --git a/source/blender/draw/engines/overlay/overlay_edit_uv.c b/source/blender/draw/engines/overlay/overlay_edit_uv.c new file mode 100644 index 00000000000..109db6433e0 --- /dev/null +++ b/source/blender/draw/engines/overlay/overlay_edit_uv.c @@ -0,0 +1,394 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2019, Blender Foundation. + */ + +/** \file + * \ingroup draw_engine + */ +#include "DRW_render.h" + +#include "draw_cache_impl.h" +#include "draw_manager_text.h" + +#include "BKE_image.h" + +#include "DNA_mesh_types.h" + +#include "ED_image.h" + +#include "GPU_batch.h" + +#include "UI_interface.h" +#include "UI_resources.h" + +#include "overlay_private.h" + +typedef struct OVERLAY_StretchingAreaTotals { + void *next, *prev; + float *total_area; + float *total_area_uv; +} OVERLAY_StretchingAreaTotals; + +static OVERLAY_UVLineStyle edit_uv_line_style_from_space_image(const SpaceImage *sima) +{ + const bool is_uv_editor = sima->mode == SI_MODE_UV; + if (is_uv_editor) { + switch (sima->dt_uv) { + case SI_UVDT_OUTLINE: + return OVERLAY_UV_LINE_STYLE_OUTLINE; + case SI_UVDT_BLACK: + return OVERLAY_UV_LINE_STYLE_BLACK; + case SI_UVDT_WHITE: + return OVERLAY_UV_LINE_STYLE_WHITE; + case SI_UVDT_DASH: + return OVERLAY_UV_LINE_STYLE_DASH; + default: + return OVERLAY_UV_LINE_STYLE_BLACK; + } + } + else { + return OVERLAY_UV_LINE_STYLE_SHADOW; + } +} + +/* -------------------------------------------------------------------- */ +/** \name Internal API + * \{ */ + +void OVERLAY_edit_uv_init(OVERLAY_Data *vedata) +{ + OVERLAY_StorageList *stl = vedata->stl; + OVERLAY_PrivateData *pd = stl->pd; + const DRWContextState *draw_ctx = DRW_context_state_get(); + SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + const Scene *scene = draw_ctx->scene; + const ToolSettings *ts = scene->toolsettings; + + Image *image = sima->image; + /* By design no image is an image type. This so editor shows UV's by default. */ + const bool is_image_type = + (image == NULL) || ELEM(image->type, IMA_TYPE_IMAGE, IMA_TYPE_MULTILAYER, IMA_TYPE_UV_TEST); + const bool is_uv_editor = sima->mode == SI_MODE_UV; + const bool has_edit_object = (draw_ctx->object_edit) != NULL; + const bool is_paint_mode = sima->mode == SI_MODE_PAINT; + const bool is_view_mode = sima->mode == SI_MODE_VIEW; + const bool is_edit_mode = draw_ctx->object_mode == OB_MODE_EDIT; + const bool do_uv_overlay = is_image_type && is_uv_editor && has_edit_object; + const bool show_modified_uvs = sima->flag & SI_DRAWSHADOW; + const bool is_tiled_image = image && (image->source == IMA_SRC_TILED); + const bool do_faces = ((sima->flag & SI_NO_DRAWFACES) == 0); + const bool do_face_dots = (ts->uv_flag & UV_SYNC_SELECTION) ? + (ts->selectmode & SCE_SELECT_FACE) != 0 : + (ts->uv_selectmode == UV_SELECT_FACE); + const bool do_uvstretching_overlay = is_image_type && is_uv_editor && is_edit_mode && + ((sima->flag & SI_DRAW_STRETCH) != 0); + pd->edit_uv.do_faces = do_faces && !do_uvstretching_overlay; + pd->edit_uv.do_face_dots = do_faces && do_face_dots; + + pd->edit_uv.do_uv_overlay = do_uv_overlay; + pd->edit_uv.do_uv_shadow_overlay = + is_image_type && + ((is_paint_mode && + ((draw_ctx->object_mode & (OB_MODE_TEXTURE_PAINT | OB_MODE_EDIT)) != 0)) || + (is_view_mode && ((draw_ctx->object_mode & (OB_MODE_TEXTURE_PAINT)) != 0)) || + (do_uv_overlay && (show_modified_uvs))); + pd->edit_uv.do_uv_stretching_overlay = do_uvstretching_overlay; + pd->edit_uv.uv_opacity = sima->uv_opacity; + pd->edit_uv.do_tiled_image_overlay = is_image_type && is_tiled_image; + + pd->edit_uv.dash_length = 4.0f * UI_DPI_FAC; + pd->edit_uv.line_style = edit_uv_line_style_from_space_image(sima); + pd->edit_uv.do_smooth_wire = ((U.gpu_flag & USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE) > 0); + + pd->edit_uv.draw_type = sima->dt_uvstretch; + BLI_listbase_clear(&pd->edit_uv.totals); + pd->edit_uv.total_area_ratio = 0.0f; + pd->edit_uv.total_area_ratio_inv = 0.0f; + + ED_space_image_get_uv_aspect(sima, &pd->edit_uv.aspect[0], &pd->edit_uv.aspect[1]); +} + +void OVERLAY_edit_uv_cache_init(OVERLAY_Data *vedata) +{ + OVERLAY_StorageList *stl = vedata->stl; + OVERLAY_PassList *psl = vedata->psl; + OVERLAY_PrivateData *pd = stl->pd; + + if (pd->edit_uv.do_uv_overlay || pd->edit_uv.do_uv_shadow_overlay) { + /* uv edges */ + { + DRW_PASS_CREATE(psl->edit_uv_edges_ps, + DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | + DRW_STATE_BLEND_ALPHA); + GPUShader *sh = OVERLAY_shader_edit_uv_edges_get(); + if (pd->edit_uv.do_uv_shadow_overlay) { + pd->edit_uv_shadow_edges_grp = DRW_shgroup_create(sh, psl->edit_uv_edges_ps); + DRW_shgroup_uniform_block(pd->edit_uv_shadow_edges_grp, "globalsBlock", G_draw.block_ubo); + DRW_shgroup_uniform_int_copy( + pd->edit_uv_shadow_edges_grp, "lineStyle", OVERLAY_UV_LINE_STYLE_SHADOW); + DRW_shgroup_uniform_float_copy( + pd->edit_uv_shadow_edges_grp, "alpha", pd->edit_uv.uv_opacity); + DRW_shgroup_uniform_float( + pd->edit_uv_shadow_edges_grp, "dashLength", &pd->edit_uv.dash_length, 1); + DRW_shgroup_uniform_bool( + pd->edit_uv_shadow_edges_grp, "doSmoothWire", &pd->edit_uv.do_smooth_wire, 1); + } + + if (pd->edit_uv.do_uv_overlay) { + pd->edit_uv_edges_grp = DRW_shgroup_create(sh, psl->edit_uv_edges_ps); + DRW_shgroup_uniform_block(pd->edit_uv_edges_grp, "globalsBlock", G_draw.block_ubo); + DRW_shgroup_uniform_int_copy(pd->edit_uv_edges_grp, "lineStyle", pd->edit_uv.line_style); + DRW_shgroup_uniform_float_copy(pd->edit_uv_edges_grp, "alpha", pd->edit_uv.uv_opacity); + DRW_shgroup_uniform_float( + pd->edit_uv_edges_grp, "dashLength", &pd->edit_uv.dash_length, 1); + DRW_shgroup_uniform_bool( + pd->edit_uv_edges_grp, "doSmoothWire", &pd->edit_uv.do_smooth_wire, 1); + } + } + } + + if (pd->edit_uv.do_uv_overlay) { + /* uv verts */ + { + DRW_PASS_CREATE(psl->edit_uv_verts_ps, + DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | + DRW_STATE_BLEND_ALPHA); + GPUShader *sh = OVERLAY_shader_edit_uv_verts_get(); + pd->edit_uv_verts_grp = DRW_shgroup_create(sh, psl->edit_uv_verts_ps); + + const float point_size = UI_GetThemeValuef(TH_FACEDOT_SIZE); + + DRW_shgroup_uniform_block(pd->edit_uv_verts_grp, "globalsBlock", G_draw.block_ubo); + DRW_shgroup_uniform_float_copy( + pd->edit_uv_verts_grp, "pointSize", (point_size + 1.5f) * M_SQRT2); + DRW_shgroup_uniform_float_copy(pd->edit_uv_verts_grp, "outlineWidth", 0.75f); + } + + /* uv faces */ + if (pd->edit_uv.do_faces) { + DRW_PASS_CREATE(psl->edit_uv_faces_ps, + DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_ALWAYS | DRW_STATE_BLEND_ALPHA); + GPUShader *sh = OVERLAY_shader_edit_uv_face_get(); + pd->edit_uv_faces_grp = DRW_shgroup_create(sh, psl->edit_uv_faces_ps); + DRW_shgroup_uniform_block(pd->edit_uv_faces_grp, "globalsBlock", G_draw.block_ubo); + DRW_shgroup_uniform_float(pd->edit_uv_faces_grp, "uvOpacity", &pd->edit_uv.uv_opacity, 1); + } + + /* uv face dots */ + if (pd->edit_uv.do_face_dots) { + const float point_size = UI_GetThemeValuef(TH_FACEDOT_SIZE); + GPUShader *sh = OVERLAY_shader_edit_uv_face_dots_get(); + pd->edit_uv_face_dots_grp = DRW_shgroup_create(sh, psl->edit_uv_verts_ps); + DRW_shgroup_uniform_block(pd->edit_uv_face_dots_grp, "globalsBlock", G_draw.block_ubo); + DRW_shgroup_uniform_float_copy(pd->edit_uv_face_dots_grp, "pointSize", point_size); + } + } + + /* uv stretching */ + if (pd->edit_uv.do_uv_stretching_overlay) { + DRW_PASS_CREATE(psl->edit_uv_stretching_ps, + DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_ALWAYS | DRW_STATE_BLEND_ALPHA); + if (pd->edit_uv.draw_type == SI_UVDT_STRETCH_ANGLE) { + GPUShader *sh = OVERLAY_shader_edit_uv_stretching_angle_get(); + pd->edit_uv_stretching_grp = DRW_shgroup_create(sh, psl->edit_uv_stretching_ps); + DRW_shgroup_uniform_block(pd->edit_uv_stretching_grp, "globalsBlock", G_draw.block_ubo); + DRW_shgroup_uniform_vec2_copy(pd->edit_uv_stretching_grp, "aspect", pd->edit_uv.aspect); + } + else /* SI_UVDT_STRETCH_AREA */ { + GPUShader *sh = OVERLAY_shader_edit_uv_stretching_area_get(); + pd->edit_uv_stretching_grp = DRW_shgroup_create(sh, psl->edit_uv_stretching_ps); + DRW_shgroup_uniform_block(pd->edit_uv_stretching_grp, "globalsBlock", G_draw.block_ubo); + DRW_shgroup_uniform_float( + pd->edit_uv_stretching_grp, "totalAreaRatio", &pd->edit_uv.total_area_ratio, 1); + DRW_shgroup_uniform_float( + pd->edit_uv_stretching_grp, "totalAreaRatioInv", &pd->edit_uv.total_area_ratio_inv, 1); + } + } + + if (pd->edit_uv.do_tiled_image_overlay) { + const DRWContextState *draw_ctx = DRW_context_state_get(); + SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + Image *image = sima->image; + GPUBatch *geom = DRW_cache_quad_wires_get(); + float obmat[4][4]; + unit_m4(obmat); + + DRW_PASS_CREATE(psl->edit_uv_tiled_image_borders_ps, + DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_ALWAYS); + GPUShader *sh = OVERLAY_shader_edit_uv_tiled_image_borders_get(); + + float theme_color[4], selected_color[4]; + UI_GetThemeColorShade4fv(TH_BACK, 60, theme_color); + UI_GetThemeColor4fv(TH_FACE_SELECT, selected_color); + srgb_to_linearrgb_v4(theme_color, theme_color); + srgb_to_linearrgb_v4(selected_color, selected_color); + + DRWShadingGroup *grp = DRW_shgroup_create(sh, psl->edit_uv_tiled_image_borders_ps); + DRW_shgroup_uniform_vec4_copy(grp, "color", theme_color); + DRW_shgroup_uniform_vec3_copy(grp, "offset", (float[3]){0.0f, 0.0f, 0.0f}); + + LISTBASE_FOREACH (ImageTile *, tile, &image->tiles) { + const int tile_x = ((tile->tile_number - 1001) % 10); + const int tile_y = ((tile->tile_number - 1001) / 10); + obmat[3][1] = (float)tile_y; + obmat[3][0] = (float)tile_x; + DRW_shgroup_call_obmat(grp, geom, obmat); + } + + /* Active tile border */ + ImageTile *active_tile = BLI_findlink(&image->tiles, image->active_tile_index); + obmat[3][0] = (float)((active_tile->tile_number - 1001) % 10); + obmat[3][1] = (float)((active_tile->tile_number - 1001) / 10); + grp = DRW_shgroup_create(sh, psl->edit_uv_tiled_image_borders_ps); + DRW_shgroup_uniform_vec4_copy(grp, "color", selected_color); + DRW_shgroup_call_obmat(grp, geom, obmat); + + struct DRWTextStore *dt = DRW_text_cache_ensure(); + uchar color[4]; + /* Color Management: Exception here as texts are drawn in sRGB space directly. */ + UI_GetThemeColorShade4ubv(TH_BACK, 60, color); + char text[16]; + LISTBASE_FOREACH (ImageTile *, tile, &image->tiles) { + BLI_snprintf(text, 5, "%d", tile->tile_number); + float tile_location[3] = { + ((tile->tile_number - 1001) % 10), ((tile->tile_number - 1001) / 10), 0.0f}; + DRW_text_cache_add(dt, + tile_location, + text, + strlen(text), + 10, + 10, + DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_ASCII, + color); + } + } +} + +void OVERLAY_edit_uv_cache_populate(OVERLAY_Data *vedata, Object *ob) +{ + OVERLAY_StorageList *stl = vedata->stl; + OVERLAY_PrivateData *pd = stl->pd; + GPUBatch *geom; + const bool is_edit_object = DRW_object_is_in_edit_mode(ob); + + const DRWContextState *draw_ctx = DRW_context_state_get(); + const bool draw_shadows = (draw_ctx->object_mode != OB_MODE_OBJECT) && + (ob->mode == draw_ctx->object_mode); + if (is_edit_object) { + if (pd->edit_uv.do_uv_overlay) { + geom = DRW_mesh_batch_cache_get_edituv_edges(ob->data); + if (geom) { + DRW_shgroup_call_obmat(pd->edit_uv_edges_grp, geom, NULL); + } + geom = DRW_mesh_batch_cache_get_edituv_verts(ob->data); + if (geom) { + DRW_shgroup_call_obmat(pd->edit_uv_verts_grp, geom, NULL); + } + if (pd->edit_uv.do_faces) { + geom = DRW_mesh_batch_cache_get_edituv_faces(ob->data); + if (geom) { + DRW_shgroup_call_obmat(pd->edit_uv_faces_grp, geom, NULL); + } + } + if (pd->edit_uv.do_face_dots) { + geom = DRW_mesh_batch_cache_get_edituv_facedots(ob->data); + if (geom) { + DRW_shgroup_call_obmat(pd->edit_uv_face_dots_grp, geom, NULL); + } + } + } + + if (pd->edit_uv.do_uv_stretching_overlay) { + Mesh *me = ob->data; + + if (pd->edit_uv.draw_type == SI_UVDT_STRETCH_ANGLE) { + geom = DRW_mesh_batch_cache_get_edituv_faces_stretch_angle(me); + } + else /* SI_UVDT_STRETCH_AREA */ { + OVERLAY_StretchingAreaTotals *totals = MEM_mallocN(sizeof(OVERLAY_StretchingAreaTotals), + __func__); + BLI_addtail(&pd->edit_uv.totals, totals); + geom = DRW_mesh_batch_cache_get_edituv_faces_stretch_area( + me, &totals->total_area, &totals->total_area_uv); + } + + if (geom) { + DRW_shgroup_call_obmat(pd->edit_uv_stretching_grp, geom, NULL); + } + } + } + + if (draw_shadows) { + if (pd->edit_uv.do_uv_shadow_overlay) { + geom = DRW_mesh_batch_cache_get_uv_edges(ob->data); + if (geom) { + DRW_shgroup_call_obmat(pd->edit_uv_shadow_edges_grp, geom, NULL); + } + } + } +} + +static void edit_uv_stretching_update_ratios(OVERLAY_Data *vedata) +{ + OVERLAY_StorageList *stl = vedata->stl; + OVERLAY_PrivateData *pd = stl->pd; + + if (pd->edit_uv.draw_type == SI_UVDT_STRETCH_AREA) { + float total_area = 0.0f; + float total_area_uv = 0.0f; + + LISTBASE_FOREACH (OVERLAY_StretchingAreaTotals *, totals, &pd->edit_uv.totals) { + total_area += *totals->total_area; + total_area_uv += *totals->total_area_uv; + } + + if (total_area > FLT_EPSILON && total_area_uv > FLT_EPSILON) { + pd->edit_uv.total_area_ratio = total_area / total_area_uv; + pd->edit_uv.total_area_ratio_inv = total_area_uv / total_area; + } + } + BLI_freelistN(&pd->edit_uv.totals); +} + +void OVERLAY_edit_uv_draw(OVERLAY_Data *vedata) +{ + OVERLAY_PassList *psl = vedata->psl; + OVERLAY_StorageList *stl = vedata->stl; + OVERLAY_PrivateData *pd = stl->pd; + + if (pd->edit_uv.do_tiled_image_overlay) { + DRW_draw_pass(psl->edit_uv_tiled_image_borders_ps); + } + + if (pd->edit_uv.do_uv_stretching_overlay) { + edit_uv_stretching_update_ratios(vedata); + DRW_draw_pass(psl->edit_uv_stretching_ps); + } + if (pd->edit_uv.do_uv_overlay) { + if (pd->edit_uv.do_faces) { + DRW_draw_pass(psl->edit_uv_faces_ps); + } + DRW_draw_pass(psl->edit_uv_edges_ps); + + DRW_draw_pass(psl->edit_uv_verts_ps); + } + else if (pd->edit_uv.do_uv_shadow_overlay) { + DRW_draw_pass(psl->edit_uv_edges_ps); + } +} + +/* \{ */ diff --git a/source/blender/draw/engines/overlay/overlay_engine.c b/source/blender/draw/engines/overlay/overlay_engine.c index 1312408498a..9cdd371ec4e 100644 --- a/source/blender/draw/engines/overlay/overlay_engine.c +++ b/source/blender/draw/engines/overlay/overlay_engine.c @@ -29,9 +29,13 @@ #include "ED_view3d.h" +#include "UI_interface.h" + #include "BKE_object.h" #include "BKE_paint.h" +#include "DNA_space_types.h" + #include "overlay_engine.h" #include "overlay_private.h" @@ -48,6 +52,10 @@ static void OVERLAY_engine_init(void *vedata) const View3D *v3d = draw_ctx->v3d; const Scene *scene = draw_ctx->scene; const ToolSettings *ts = scene->toolsettings; + const SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + BLI_assert(v3d || sima); + + OVERLAY_shader_library_ensure(); if (!stl->pd) { /* Alloc transient pointers */ @@ -55,6 +63,14 @@ static void OVERLAY_engine_init(void *vedata) } OVERLAY_PrivateData *pd = stl->pd; + pd->is_image_editor = sima != NULL; + + if (pd->is_image_editor) { + pd->clipping_state = 0; + OVERLAY_grid_init(data); + OVERLAY_edit_uv_init(data); + return; + } pd->hide_overlays = (v3d->flag2 & V3D_HIDE_OVERLAYS) != 0; pd->ctx_mode = CTX_data_mode_enum_ex( @@ -122,6 +138,13 @@ static void OVERLAY_cache_init(void *vedata) OVERLAY_StorageList *stl = data->stl; OVERLAY_PrivateData *pd = stl->pd; + if (pd->is_image_editor) { + OVERLAY_background_cache_init(vedata); + OVERLAY_grid_cache_init(vedata); + OVERLAY_edit_uv_cache_init(vedata); + return; + } + switch (pd->ctx_mode) { case CTX_MODE_EDIT_MESH: OVERLAY_edit_mesh_cache_init(vedata); @@ -240,6 +263,14 @@ static void OVERLAY_cache_populate(void *vedata, Object *ob) { OVERLAY_Data *data = vedata; OVERLAY_PrivateData *pd = data->stl->pd; + + if (pd->is_image_editor) { + if (ob->type == OB_MESH) { + OVERLAY_edit_uv_cache_populate(vedata, ob); + } + return; + } + const DRWContextState *draw_ctx = DRW_context_state_get(); const bool is_select = DRW_state_is_select(); const bool renderable = DRW_object_is_renderable(ob); @@ -414,6 +445,12 @@ static void OVERLAY_cache_populate(void *vedata, Object *ob) static void OVERLAY_cache_finish(void *vedata) { + OVERLAY_Data *data = vedata; + OVERLAY_PrivateData *pd = data->stl->pd; + if (pd->is_image_editor) { + return; + } + /* TODO(fclem) Only do this when really needed. */ { /* HACK we allocate the in front depth here to avoid the overhead when if is not needed. */ @@ -445,6 +482,16 @@ static void OVERLAY_draw_scene(void *vedata) GPU_framebuffer_clear_color(dfbl->overlay_only_fb, clear_col); } + if (pd->is_image_editor) { + OVERLAY_background_draw(data); + OVERLAY_grid_draw(data); + if (DRW_state_is_fbo()) { + GPU_framebuffer_bind(dfbl->overlay_fb); + } + OVERLAY_edit_uv_draw(data); + return; + } + OVERLAY_image_background_draw(vedata); OVERLAY_background_draw(vedata); diff --git a/source/blender/draw/engines/overlay/overlay_grid.c b/source/blender/draw/engines/overlay/overlay_grid.c index e3079870d8f..7445dfc2e3d 100644 --- a/source/blender/draw/engines/overlay/overlay_grid.c +++ b/source/blender/draw/engines/overlay/overlay_grid.c @@ -26,6 +26,7 @@ #include "DEG_depsgraph_query.h" +#include "ED_image.h" #include "ED_view3d.h" #include "overlay_private.h" @@ -42,14 +43,31 @@ enum { CLIP_ZNEG = (1 << 8), GRID_BACK = (1 << 9), GRID_CAMERA = (1 << 10), + PLANE_IMAGE = (1 << 11), }; void OVERLAY_grid_init(OVERLAY_Data *vedata) { OVERLAY_PrivateData *pd = vedata->stl->pd; OVERLAY_ShadingData *shd = &pd->shdata; - const DRWContextState *draw_ctx = DRW_context_state_get(); + + shd->grid_flag = 0; + shd->zneg_flag = 0; + shd->zpos_flag = 0; + shd->grid_line_size = max_ff(0.0f, U.pixelsize - 1.0f) * 0.5f; + + if (pd->is_image_editor) { + SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + shd->grid_flag = ED_space_image_has_buffer(sima) ? 0 : PLANE_IMAGE | SHOW_GRID; + shd->grid_distance = 1.0f; + shd->grid_mesh_size = 1.0f; + for (int step = 0; step < 8; step++) { + shd->grid_steps[step] = powf(4, step) * (1.0f / 16.0f); + } + return; + } + View3D *v3d = draw_ctx->v3d; Scene *scene = draw_ctx->scene; RegionView3D *rv3d = draw_ctx->rv3d; @@ -60,10 +78,6 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata) const bool show_floor = (pd->v3d_gridflag & V3D_SHOW_FLOOR) != 0; const bool show_ortho_grid = (pd->v3d_gridflag & V3D_SHOW_ORTHO_GRID) != 0; - shd->grid_flag = 0; - shd->zneg_flag = 0; - shd->zpos_flag = 0; - if (pd->hide_overlays || !(pd->v3d_gridflag & (V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z | V3D_SHOW_FLOOR | V3D_SHOW_ORTHO_GRID))) { return; @@ -163,14 +177,16 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata) } shd->grid_distance = dist / 2.0f; - shd->grid_line_size = max_ff(0.0f, U.pixelsize - 1.0f) * 0.5f; ED_view3d_grid_steps(scene, v3d, rv3d, shd->grid_steps); } void OVERLAY_grid_cache_init(OVERLAY_Data *vedata) { - OVERLAY_ShadingData *shd = &vedata->stl->pd->shdata; + OVERLAY_StorageList *stl = vedata->stl; + OVERLAY_PrivateData *pd = stl->pd; + OVERLAY_ShadingData *shd = &pd->shdata; + OVERLAY_PassList *psl = vedata->psl; DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); @@ -182,12 +198,29 @@ void OVERLAY_grid_cache_init(OVERLAY_Data *vedata) DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA; DRW_PASS_CREATE(psl->grid_ps, state); - - GPUShader *sh = OVERLAY_shader_grid(); + DRWShadingGroup *grp; + GPUShader *sh; struct GPUBatch *geom = DRW_cache_grid_get(); + if (pd->is_image_editor) { + /* add quad background */ + sh = OVERLAY_shader_grid_image(); + grp = DRW_shgroup_create(sh, psl->grid_ps); + DRW_shgroup_call(grp, DRW_cache_quad_get(), NULL); + float color_back[4]; + interp_v4_v4v4(color_back, G_draw.block.colorBackground, G_draw.block.colorGrid, 0.5); + DRW_shgroup_uniform_vec4_copy(grp, "color", color_back); + + /* add wire border */ + grp = DRW_shgroup_create(sh, psl->grid_ps); + DRW_shgroup_call(grp, DRW_cache_quad_wires_get(), NULL); + DRW_shgroup_uniform_vec4_copy(grp, "color", G_draw.block.colorGrid); + } + + sh = OVERLAY_shader_grid(); + /* Create 3 quads to render ordered transparency Z axis */ - DRWShadingGroup *grp = DRW_shgroup_create(sh, psl->grid_ps); + grp = DRW_shgroup_create(sh, psl->grid_ps); DRW_shgroup_uniform_int(grp, "gridFlag", &shd->zneg_flag, 1); DRW_shgroup_uniform_vec3(grp, "planeAxes", shd->zplane_axes, 1); DRW_shgroup_uniform_float(grp, "gridDistance", &shd->grid_distance, 1); diff --git a/source/blender/draw/engines/overlay/overlay_private.h b/source/blender/draw/engines/overlay/overlay_private.h index 86c1f077571..c1d29cf7450 100644 --- a/source/blender/draw/engines/overlay/overlay_private.h +++ b/source/blender/draw/engines/overlay/overlay_private.h @@ -34,6 +34,9 @@ extern "C" { # define USE_GEOM_SHADER_WORKAROUND 0 #endif +/* Needed for eSpaceImage_UVDT_Stretch */ +#include "DNA_space_types.h" + typedef struct OVERLAY_FramebufferList { struct GPUFrameBuffer *overlay_default_fb; struct GPUFrameBuffer *overlay_line_fb; @@ -55,6 +58,14 @@ typedef struct OVERLAY_TextureList { #define NOT_IN_FRONT 0 #define IN_FRONT 1 +typedef enum OVERLAY_UVLineStyle { + OVERLAY_UV_LINE_STYLE_OUTLINE = 0, + OVERLAY_UV_LINE_STYLE_DASH = 1, + OVERLAY_UV_LINE_STYLE_BLACK = 2, + OVERLAY_UV_LINE_STYLE_WHITE = 3, + OVERLAY_UV_LINE_STYLE_SHADOW = 4, +} OVERLAY_UVLineStyle; + typedef struct OVERLAY_PassList { DRWPass *antialiasing_ps; DRWPass *armature_ps[2]; @@ -79,6 +90,11 @@ typedef struct OVERLAY_PassList { DRWPass *edit_text_overlay_ps; DRWPass *edit_text_darken_ps; DRWPass *edit_text_wire_ps[2]; + DRWPass *edit_uv_edges_ps; + DRWPass *edit_uv_verts_ps; + DRWPass *edit_uv_faces_ps; + DRWPass *edit_uv_stretching_ps; + DRWPass *edit_uv_tiled_image_borders_ps; DRWPass *extra_ps[2]; DRWPass *extra_blend_ps; DRWPass *extra_centers_ps; @@ -247,6 +263,12 @@ typedef struct OVERLAY_PrivateData { DRWShadingGroup *edit_particle_point_grp; DRWShadingGroup *edit_text_overlay_grp; DRWShadingGroup *edit_text_wire_grp[2]; + DRWShadingGroup *edit_uv_verts_grp; + DRWShadingGroup *edit_uv_edges_grp; + DRWShadingGroup *edit_uv_shadow_edges_grp; + DRWShadingGroup *edit_uv_faces_grp; + DRWShadingGroup *edit_uv_face_dots_grp; + DRWShadingGroup *edit_uv_stretching_grp; DRWShadingGroup *extra_grid_grp; DRWShadingGroup *facing_grp[2]; DRWShadingGroup *motion_path_lines_grp; @@ -289,6 +311,7 @@ typedef struct OVERLAY_PrivateData { View3DOverlay overlay; enum eContextObjectMode ctx_mode; + bool is_image_editor; bool clear_in_front; bool use_in_front; bool wireframe_mode; @@ -328,6 +351,29 @@ typedef struct OVERLAY_PrivateData { int select_mode; } edit_particle; struct { + bool do_uv_overlay; + bool do_uv_shadow_overlay; + bool do_uv_stretching_overlay; + bool do_tiled_image_overlay; + + bool do_faces; + bool do_face_dots; + + float uv_opacity; + /* edge drawing */ + OVERLAY_UVLineStyle line_style; + float dash_length; + int do_smooth_wire; + + /* stretching overlay */ + float aspect[2]; + eSpaceImage_UVDT_Stretch draw_type; + ListBase totals; + float total_area_ratio; + float total_area_ratio_inv; + + } edit_uv; + struct { bool transparent; bool show_relations; bool do_pose_xray; @@ -475,6 +521,11 @@ void OVERLAY_edit_particle_cache_init(OVERLAY_Data *vedata); void OVERLAY_edit_particle_cache_populate(OVERLAY_Data *vedata, Object *ob); void OVERLAY_edit_particle_draw(OVERLAY_Data *vedata); +void OVERLAY_edit_uv_init(OVERLAY_Data *vedata); +void OVERLAY_edit_uv_cache_init(OVERLAY_Data *vedata); +void OVERLAY_edit_uv_cache_populate(OVERLAY_Data *vedata, Object *ob); +void OVERLAY_edit_uv_draw(OVERLAY_Data *vedata); + void OVERLAY_extra_cache_init(OVERLAY_Data *vedata); void OVERLAY_extra_cache_populate(OVERLAY_Data *vedata, Object *ob); void OVERLAY_extra_blend_draw(OVERLAY_Data *vedata); @@ -573,6 +624,7 @@ void OVERLAY_wireframe_cache_populate(OVERLAY_Data *vedata, void OVERLAY_wireframe_draw(OVERLAY_Data *vedata); void OVERLAY_wireframe_in_front_draw(OVERLAY_Data *vedata); +void OVERLAY_shader_library_ensure(void); GPUShader *OVERLAY_shader_antialiasing(void); GPUShader *OVERLAY_shader_armature_degrees_of_freedom_wire(void); GPUShader *OVERLAY_shader_armature_degrees_of_freedom_solid(void); @@ -602,6 +654,13 @@ GPUShader *OVERLAY_shader_edit_mesh_skin_root(void); GPUShader *OVERLAY_shader_edit_mesh_vert(void); GPUShader *OVERLAY_shader_edit_particle_strand(void); GPUShader *OVERLAY_shader_edit_particle_point(void); +GPUShader *OVERLAY_shader_edit_uv_edges_get(void); +GPUShader *OVERLAY_shader_edit_uv_face_get(void); +GPUShader *OVERLAY_shader_edit_uv_face_dots_get(void); +GPUShader *OVERLAY_shader_edit_uv_verts_get(void); +GPUShader *OVERLAY_shader_edit_uv_stretching_area_get(void); +GPUShader *OVERLAY_shader_edit_uv_stretching_angle_get(void); +GPUShader *OVERLAY_shader_edit_uv_tiled_image_borders_get(void); GPUShader *OVERLAY_shader_extra(bool is_select); GPUShader *OVERLAY_shader_extra_groundline(void); GPUShader *OVERLAY_shader_extra_wire(bool use_object, bool is_select); @@ -610,6 +669,7 @@ GPUShader *OVERLAY_shader_extra_point(void); GPUShader *OVERLAY_shader_facing(void); GPUShader *OVERLAY_shader_gpencil_canvas(void); GPUShader *OVERLAY_shader_grid(void); +GPUShader *OVERLAY_shader_grid_image(void); GPUShader *OVERLAY_shader_image(void); GPUShader *OVERLAY_shader_motion_path_line(void); GPUShader *OVERLAY_shader_motion_path_vert(void); diff --git a/source/blender/draw/engines/overlay/overlay_shader.c b/source/blender/draw/engines/overlay/overlay_shader.c index e3cb052890b..4530d6e8adf 100644 --- a/source/blender/draw/engines/overlay/overlay_shader.c +++ b/source/blender/draw/engines/overlay/overlay_shader.c @@ -70,6 +70,15 @@ extern char datatoc_edit_mesh_analysis_vert_glsl[]; extern char datatoc_edit_mesh_analysis_frag_glsl[]; extern char datatoc_edit_particle_strand_vert_glsl[]; extern char datatoc_edit_particle_point_vert_glsl[]; +extern char datatoc_edit_uv_verts_vert_glsl[]; +extern char datatoc_edit_uv_verts_frag_glsl[]; +extern char datatoc_edit_uv_edges_vert_glsl[]; +extern char datatoc_edit_uv_edges_geom_glsl[]; +extern char datatoc_edit_uv_edges_frag_glsl[]; +extern char datatoc_edit_uv_faces_vert_glsl[]; +extern char datatoc_edit_uv_face_dots_vert_glsl[]; +extern char datatoc_edit_uv_stretching_vert_glsl[]; +extern char datatoc_edit_uv_tiled_image_borders_vert_glsl[]; extern char datatoc_extra_frag_glsl[]; extern char datatoc_extra_vert_glsl[]; extern char datatoc_extra_groundline_vert_glsl[]; @@ -113,6 +122,7 @@ extern char datatoc_xray_fade_frag_glsl[]; extern char datatoc_gpu_shader_depth_only_frag_glsl[]; extern char datatoc_gpu_shader_point_varying_color_frag_glsl[]; extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[]; +extern char datatoc_gpu_shader_2D_smooth_color_frag_glsl[]; extern char datatoc_gpu_shader_uniform_color_frag_glsl[]; extern char datatoc_gpu_shader_flat_color_frag_glsl[]; extern char datatoc_gpu_shader_point_varying_color_varying_outline_aa_frag_glsl[]; @@ -120,6 +130,7 @@ extern char datatoc_gpu_shader_common_obinfos_lib_glsl[]; extern char datatoc_gpencil_common_lib_glsl[]; +extern char datatoc_common_overlay_lib_glsl[]; extern char datatoc_common_colormanagement_lib_glsl[]; extern char datatoc_common_fullscreen_vert_glsl[]; extern char datatoc_common_fxaa_lib_glsl[]; @@ -164,6 +175,13 @@ typedef struct OVERLAY_Shaders { GPUShader *edit_mesh_analysis; GPUShader *edit_particle_strand; GPUShader *edit_particle_point; + GPUShader *edit_uv_verts; + GPUShader *edit_uv_faces; + GPUShader *edit_uv_edges; + GPUShader *edit_uv_face_dots; + GPUShader *edit_uv_stretching_angle; + GPUShader *edit_uv_stretching_area; + GPUShader *edit_uv_tiled_image_borders; GPUShader *extra; GPUShader *extra_select; GPUShader *extra_groundline; @@ -175,6 +193,7 @@ typedef struct OVERLAY_Shaders { GPUShader *facing; GPUShader *gpencil_canvas; GPUShader *grid; + GPUShader *grid_image; GPUShader *image; GPUShader *motion_path_line; GPUShader *motion_path_vert; @@ -203,8 +222,20 @@ typedef struct OVERLAY_Shaders { static struct { OVERLAY_Shaders sh_data[GPU_SHADER_CFG_LEN]; + DRWShaderLibrary *lib; } e_data = {{{NULL}}}; +void OVERLAY_shader_library_ensure(void) +{ + if (e_data.lib == NULL) { + e_data.lib = DRW_shader_library_create(); + /* NOTE: Theses needs to be ordered by dependencies. */ + DRW_SHADER_LIB_ADD(e_data.lib, common_globals_lib); + DRW_SHADER_LIB_ADD(e_data.lib, common_overlay_lib); + DRW_SHADER_LIB_ADD(e_data.lib, common_view_lib); + } +} + GPUShader *OVERLAY_shader_antialiasing(void) { OVERLAY_Shaders *sh_data = &e_data.sh_data[0]; @@ -1012,6 +1043,20 @@ GPUShader *OVERLAY_shader_grid(void) return sh_data->grid; } +GPUShader *OVERLAY_shader_grid_image(void) +{ + OVERLAY_Shaders *sh_data = &e_data.sh_data[0]; + if (!sh_data->grid_image) { + sh_data->grid_image = DRW_shader_create_with_shaderlib( + datatoc_edit_uv_tiled_image_borders_vert_glsl, + NULL, + datatoc_gpu_shader_uniform_color_frag_glsl, + e_data.lib, + "#define blender_srgb_to_framebuffer_space(a) a\n"); + } + return sh_data->grid_image; +} + GPUShader *OVERLAY_shader_image(void) { const DRWContextState *draw_ctx = DRW_context_state_get(); @@ -1449,6 +1494,108 @@ GPUShader *OVERLAY_shader_xray_fade(void) return sh_data->xray_fade; } +/* -------------------------------------------------------------------- */ +/** \name Edit UV shaders + * \{ */ + +GPUShader *OVERLAY_shader_edit_uv_edges_get(void) +{ + OVERLAY_Shaders *sh_data = &e_data.sh_data[0]; + if (!sh_data->edit_uv_edges) { + sh_data->edit_uv_edges = DRW_shader_create_with_shaderlib(datatoc_edit_uv_edges_vert_glsl, + datatoc_edit_uv_edges_geom_glsl, + datatoc_edit_uv_edges_frag_glsl, + e_data.lib, + NULL); + } + return sh_data->edit_uv_edges; +} + +GPUShader *OVERLAY_shader_edit_uv_face_get(void) +{ + OVERLAY_Shaders *sh_data = &e_data.sh_data[0]; + if (!sh_data->edit_uv_faces) { + sh_data->edit_uv_faces = DRW_shader_create_with_shaderlib( + datatoc_edit_uv_faces_vert_glsl, + NULL, + datatoc_gpu_shader_flat_color_frag_glsl, + e_data.lib, + "#define blender_srgb_to_framebuffer_space(a) a\n"); + } + return sh_data->edit_uv_faces; +} + +GPUShader *OVERLAY_shader_edit_uv_face_dots_get(void) +{ + OVERLAY_Shaders *sh_data = &e_data.sh_data[0]; + if (!sh_data->edit_uv_face_dots) { + sh_data->edit_uv_face_dots = DRW_shader_create_with_shaderlib( + datatoc_edit_uv_face_dots_vert_glsl, + NULL, + datatoc_gpu_shader_flat_color_frag_glsl, + e_data.lib, + "#define blender_srgb_to_framebuffer_space(a) a\n"); + } + return sh_data->edit_uv_face_dots; +} + +GPUShader *OVERLAY_shader_edit_uv_verts_get(void) +{ + OVERLAY_Shaders *sh_data = &e_data.sh_data[0]; + if (!sh_data->edit_uv_verts) { + sh_data->edit_uv_verts = DRW_shader_create_with_shaderlib( + datatoc_edit_uv_verts_vert_glsl, NULL, datatoc_edit_uv_verts_frag_glsl, e_data.lib, NULL); + } + + return sh_data->edit_uv_verts; +} + +GPUShader *OVERLAY_shader_edit_uv_stretching_area_get(void) +{ + OVERLAY_Shaders *sh_data = &e_data.sh_data[0]; + if (!sh_data->edit_uv_stretching_area) { + sh_data->edit_uv_stretching_area = DRW_shader_create_with_shaderlib( + datatoc_edit_uv_stretching_vert_glsl, + NULL, + datatoc_gpu_shader_2D_smooth_color_frag_glsl, + e_data.lib, + "#define blender_srgb_to_framebuffer_space(a) a\n"); + } + + return sh_data->edit_uv_stretching_area; +} + +GPUShader *OVERLAY_shader_edit_uv_stretching_angle_get(void) +{ + OVERLAY_Shaders *sh_data = &e_data.sh_data[0]; + if (!sh_data->edit_uv_stretching_angle) { + sh_data->edit_uv_stretching_angle = DRW_shader_create_with_shaderlib( + datatoc_edit_uv_stretching_vert_glsl, + NULL, + datatoc_gpu_shader_2D_smooth_color_frag_glsl, + e_data.lib, + "#define blender_srgb_to_framebuffer_space(a) a\n#define STRETCH_ANGLE\n"); + } + + return sh_data->edit_uv_stretching_angle; +} + +GPUShader *OVERLAY_shader_edit_uv_tiled_image_borders_get(void) +{ + OVERLAY_Shaders *sh_data = &e_data.sh_data[0]; + if (!sh_data->edit_uv_tiled_image_borders) { + sh_data->edit_uv_tiled_image_borders = DRW_shader_create_with_shaderlib( + datatoc_edit_uv_tiled_image_borders_vert_glsl, + NULL, + datatoc_gpu_shader_uniform_color_frag_glsl, + e_data.lib, + "#define blender_srgb_to_framebuffer_space(a) a\n"); + } + return sh_data->edit_uv_tiled_image_borders; +} + +/* \} */ + static OVERLAY_InstanceFormats g_formats = {NULL}; OVERLAY_InstanceFormats *OVERLAY_shader_instance_formats_get(void) @@ -1521,6 +1668,8 @@ OVERLAY_InstanceFormats *OVERLAY_shader_instance_formats_get(void) void OVERLAY_shader_free(void) { + DRW_SHADER_LIB_FREE_SAFE(e_data.lib); + for (int sh_data_index = 0; sh_data_index < ARRAY_SIZE(e_data.sh_data); sh_data_index++) { OVERLAY_Shaders *sh_data = &e_data.sh_data[sh_data_index]; GPUShader **sh_data_as_array = (GPUShader **)sh_data; diff --git a/source/blender/draw/engines/overlay/shaders/background_frag.glsl b/source/blender/draw/engines/overlay/shaders/background_frag.glsl index d5aaaf75b79..71bfd2f8e73 100644 --- a/source/blender/draw/engines/overlay/shaders/background_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/background_frag.glsl @@ -13,6 +13,7 @@ out vec4 fragColor; #define BG_GRADIENT 1 #define BG_CHECKER 2 #define BG_RADIAL 3 +#define BG_SOLID_CHECKER 4 #define SQRT2 1.4142135623730950488 /* 4x4 bayer matrix prepared for 8bit UNORM precision error. */ @@ -43,7 +44,11 @@ void main() vec3 col_high; vec3 col_low; - switch (bgType) { + /* BG_SOLID_CHECKER selects BG_SOLID when no pixel has been drawn otherwise use the BG_CHERKER. + */ + int bg_type = bgType == BG_SOLID_CHECKER ? (depth == 1.0 ? BG_SOLID : BG_CHECKER) : bgType; + + switch (bg_type) { case BG_SOLID: bg_col = colorBackground.rgb; break; diff --git a/source/blender/draw/engines/overlay/shaders/common_overlay_lib.glsl b/source/blender/draw/engines/overlay/shaders/common_overlay_lib.glsl new file mode 100644 index 00000000000..65aeb81a4ef --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/common_overlay_lib.glsl @@ -0,0 +1,5 @@ +#define OVERLAY_UV_LINE_STYLE_OUTLINE 0 +#define OVERLAY_UV_LINE_STYLE_DASH 1 +#define OVERLAY_UV_LINE_STYLE_BLACK 2 +#define OVERLAY_UV_LINE_STYLE_WHITE 3 +#define OVERLAY_UV_LINE_STYLE_SHADOW 4 diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_edges_frag.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_frag.glsl new file mode 100644 index 00000000000..b81fdd2c712 --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_frag.glsl @@ -0,0 +1,77 @@ +#pragma BLENDER_REQUIRE(common_globals_lib.glsl) +#pragma BLENDER_REQUIRE(common_overlay_lib.glsl) + +uniform int lineStyle; +uniform bool doSmoothWire; +uniform float alpha; +uniform float dashLength; + +in float selectionFac_f; +noperspective in float edgeCoord_f; +noperspective in vec2 stipplePos_f; +flat in vec2 stippleStart_f; + +layout(location = 0) out vec4 fragColor; + +#define M_1_SQRTPI 0.5641895835477563 /* 1/sqrt(pi) */ + +/** + * We want to know how much a pixel is covered by a line. + * We replace the square pixel with acircle of the same area and try to find the intersection area. + * The area we search is the circular segment. https://en.wikipedia.org/wiki/Circular_segment + * The formula for the area uses inverse trig function and is quite complexe. Instead, + * we approximate it by using the smoothstep function and a 1.05 factor to the disc radius. + */ +#define DISC_RADIUS (M_1_SQRTPI * 1.05) +#define GRID_LINE_SMOOTH_START (0.5 - DISC_RADIUS) +#define GRID_LINE_SMOOTH_END (0.5 + DISC_RADIUS) + +void main() +{ + vec4 inner_color = vec4(vec3(0.0), 1.0); + vec4 outer_color = vec4(0.0); + + vec2 dd = fwidth(stipplePos_f); + float line_distance = distance(stipplePos_f, stippleStart_f) / max(dd.x, dd.y); + + if (lineStyle == OVERLAY_UV_LINE_STYLE_OUTLINE) { + inner_color = mix(colorWireEdit, colorEdgeSelect, selectionFac_f); + outer_color = vec4(vec3(0.0), 1.0); + } + else if (lineStyle == OVERLAY_UV_LINE_STYLE_DASH) { + if (fract(line_distance / dashLength) < 0.5) { + inner_color = mix(vec4(1.0), colorEdgeSelect, selectionFac_f); + } + } + else if (lineStyle == OVERLAY_UV_LINE_STYLE_BLACK) { + vec4 base_color = vec4(vec3(0.0), 1.0); + inner_color = mix(base_color, colorEdgeSelect, selectionFac_f); + } + else if (lineStyle == OVERLAY_UV_LINE_STYLE_WHITE) { + vec4 base_color = vec4(1.0); + inner_color = mix(base_color, colorEdgeSelect, selectionFac_f); + } + else if (lineStyle == OVERLAY_UV_LINE_STYLE_SHADOW) { + inner_color = colorUVShadow; + } + + float dist = abs(edgeCoord_f) - max(sizeEdge - 0.5, 0.0); + float dist_outer = dist - max(sizeEdge, 1.0); + float mix_w; + float mix_w_outer; + + if (doSmoothWire) { + mix_w = smoothstep(GRID_LINE_SMOOTH_START, GRID_LINE_SMOOTH_END, dist); + mix_w_outer = smoothstep(GRID_LINE_SMOOTH_START, GRID_LINE_SMOOTH_END, dist_outer); + } + else { + mix_w = step(0.5, dist); + mix_w_outer = step(0.5, dist_outer); + } + + vec4 final_color = mix(outer_color, inner_color, 1.0 - mix_w * outer_color.a); + final_color.a *= 1.0 - (outer_color.a > 0.0 ? mix_w_outer : mix_w); + final_color.a *= alpha; + + fragColor = final_color; +}
\ No newline at end of file diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl new file mode 100644 index 00000000000..4f8d553a220 --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_geom.glsl @@ -0,0 +1,63 @@ +#pragma BLENDER_REQUIRE(common_globals_lib.glsl) +#pragma BLENDER_REQUIRE(common_overlay_lib.glsl) + +layout(lines) in; +layout(triangle_strip, max_vertices = 4) out; + +in float selectionFac[2]; +flat in vec2 stippleStart[2]; +noperspective in vec2 stipplePos[2]; + +uniform int lineStyle; +uniform bool doSmoothWire; + +out float selectionFac_f; +noperspective out float edgeCoord_f; +noperspective out vec2 stipplePos_f; +flat out vec2 stippleStart_f; + +void do_vertex( + vec4 pos, float selection_fac, vec2 stipple_start, vec2 stipple_pos, float coord, vec2 offset) +{ + selectionFac_f = selection_fac; + edgeCoord_f = coord; + stippleStart_f = stipple_start; + stipplePos_f = stipple_pos; + + gl_Position = pos; + /* Multiply offset by 2 because gl_Position range is [-1..1]. */ + gl_Position.xy += offset * 2.0; + EmitVertex(); +} + +void main() +{ + vec2 ss_pos[2]; + vec4 pos0 = gl_in[0].gl_Position; + vec4 pos1 = gl_in[1].gl_Position; + ss_pos[0] = pos0.xy / pos0.w; + ss_pos[1] = pos1.xy / pos1.w; + + float half_size = sizeEdge; + /* Enlarge edge for outline drawing. */ + /* Factor of 3.0 out of nowhere! Seems to fix issues with float imprecision. */ + half_size += (lineStyle == OVERLAY_UV_LINE_STYLE_OUTLINE) ? + max(sizeEdge * (doSmoothWire ? 1.0 : 3.0), 1.0) : + 0.0; + /* Add 1 px for AA */ + if (doSmoothWire) { + half_size += 0.5; + } + + vec2 line = ss_pos[0] - ss_pos[1]; + vec2 line_dir = normalize(line); + vec2 line_perp = vec2(-line_dir.y, line_dir.x); + vec2 edge_ofs = line_perp * sizeViewportInv * ceil(half_size); + + do_vertex(pos0, selectionFac[0], stippleStart[0], stipplePos[0], half_size, edge_ofs.xy); + do_vertex(pos0, selectionFac[0], stippleStart[0], stipplePos[0], -half_size, -edge_ofs.xy); + do_vertex(pos1, selectionFac[1], stippleStart[1], stipplePos[1], half_size, edge_ofs.xy); + do_vertex(pos1, selectionFac[1], stippleStart[1], stipplePos[1], -half_size, -edge_ofs.xy); + + EndPrimitive(); +} diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl new file mode 100644 index 00000000000..4661cf248e6 --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/edit_uv_edges_vert.glsl @@ -0,0 +1,32 @@ +#pragma BLENDER_REQUIRE(common_globals_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) + +in vec3 pos; +in vec2 u; +in int flag; + +out float selectionFac; +noperspective out vec2 stipplePos; +flat out vec2 stippleStart; + +void main() +{ + vec3 world_pos = point_object_to_world(vec3(u, 0.0)); + gl_Position = point_world_to_ndc(world_pos); + /* Snap vertices to the pixel grid to reduce artifacts. */ + vec2 half_viewport_res = sizeViewport.xy * 0.5; + vec2 half_pixel_offset = sizeViewportInv * 0.5; + gl_Position.xy = floor(gl_Position.xy * half_viewport_res) / half_viewport_res + + half_pixel_offset; + + bool is_select = (flag & VERT_UV_SELECT) != 0; + selectionFac = is_select ? 1.0 : 0.0; + /* Move selected edges to the top + * Vertices are between 0.0 and 0.2, Edges between 0.2 and 0.4 + * actual pixels are at 0.75, 1.0 is used for the background. */ + float depth = is_select ? 0.25 : 0.35; + gl_Position.z = depth; + + /* Avoid precision loss. */ + stippleStart = stipplePos = 500.0 + 500.0 * (gl_Position.xy / gl_Position.w); +} diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_face_dots_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_face_dots_vert.glsl new file mode 100644 index 00000000000..61152c83a29 --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/edit_uv_face_dots_vert.glsl @@ -0,0 +1,18 @@ +#pragma BLENDER_REQUIRE(common_globals_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) + +uniform float pointSize; + +in vec2 u; +in int flag; + +flat out vec4 finalColor; + +void main() +{ + vec3 world_pos = point_object_to_world(vec3(u, 0.0)); + gl_Position = point_world_to_ndc(world_pos); + + finalColor = ((flag & FACE_UV_SELECT) != 0) ? colorVertexSelect : vec4(colorWire.rgb, 1.0); + gl_PointSize = pointSize; +} diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_faces_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_faces_vert.glsl new file mode 100644 index 00000000000..cf1018ae5f9 --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/edit_uv_faces_vert.glsl @@ -0,0 +1,22 @@ +#pragma BLENDER_REQUIRE(common_globals_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) + +uniform float uvOpacity; + +in vec2 u; +in int flag; + +flat out vec4 finalColor; + +void main() +{ + vec3 world_pos = point_object_to_world(vec3(u, 0.0)); + gl_Position = point_world_to_ndc(world_pos); + + bool is_selected = (flag & FACE_UV_SELECT) != 0; + bool is_active = (flag & FACE_UV_ACTIVE) != 0; + + finalColor = (is_selected) ? colorFaceSelect : colorFace; + finalColor = (is_active) ? colorEditMeshActive : finalColor; + finalColor.a *= uvOpacity; +} diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_stretching_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_stretching_vert.glsl new file mode 100644 index 00000000000..ce97f1e27ac --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/edit_uv_stretching_vert.glsl @@ -0,0 +1,98 @@ +#pragma BLENDER_REQUIRE(common_view_lib.glsl) + +uniform vec2 aspect; +in vec2 pos; + +#ifdef STRETCH_ANGLE +in vec2 uv_angles; +in float angle; + +#else +in float ratio; +uniform float totalAreaRatio; +uniform float totalAreaRatioInv; + +#endif + +noperspective out vec4 finalColor; + +vec3 weight_to_rgb(float weight) +{ + vec3 r_rgb; + float blend = ((weight / 2.0) + 0.5); + + if (weight <= 0.25) { /* blue->cyan */ + r_rgb[0] = 0.0; + r_rgb[1] = blend * weight * 4.0; + r_rgb[2] = blend; + } + else if (weight <= 0.50) { /* cyan->green */ + r_rgb[0] = 0.0; + r_rgb[1] = blend; + r_rgb[2] = blend * (1.0 - ((weight - 0.25) * 4.0)); + } + else if (weight <= 0.75) { /* green->yellow */ + r_rgb[0] = blend * ((weight - 0.50) * 4.0); + r_rgb[1] = blend; + r_rgb[2] = 0.0; + } + else if (weight <= 1.0) { /* yellow->red */ + r_rgb[0] = blend; + r_rgb[1] = blend * (1.0 - ((weight - 0.75) * 4.0)); + r_rgb[2] = 0.0; + } + else { + /* exceptional value, unclamped or nan, + * avoid uninitialized memory use */ + r_rgb[0] = 1.0; + r_rgb[1] = 0.0; + r_rgb[2] = 1.0; + } + + return r_rgb; +} + +#define M_PI 3.1415926535897932 + +vec2 angle_to_v2(float angle) +{ + return vec2(cos(angle), sin(angle)); +} + +/* Adapted from BLI_math_vector.h */ +float angle_normalized_v2v2(vec2 v1, vec2 v2) +{ + v1 = normalize(v1 * aspect); + v2 = normalize(v2 * aspect); + /* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */ + bool q = (dot(v1, v2) >= 0.0); + vec2 v = (q) ? (v1 - v2) : (v1 + v2); + float a = 2.0 * asin(length(v) / 2.0); + return (q) ? a : M_PI - a; +} + +float area_ratio_to_stretch(float ratio, float tot_ratio, float inv_tot_ratio) +{ + ratio *= (ratio > 0.0f) ? tot_ratio : -inv_tot_ratio; + return (ratio > 1.0f) ? (1.0f / ratio) : ratio; +} + +void main() +{ + vec3 world_pos = point_object_to_world(vec3(pos, 0.0)); + gl_Position = point_world_to_ndc(world_pos); + +#ifdef STRETCH_ANGLE + vec2 v1 = angle_to_v2(uv_angles.x * M_PI); + vec2 v2 = angle_to_v2(uv_angles.y * M_PI); + float uv_angle = angle_normalized_v2v2(v1, v2) / M_PI; + float stretch = 1.0 - abs(uv_angle - angle); + stretch = stretch; + stretch = 1.0 - stretch * stretch; +#else + float stretch = 1.0 - area_ratio_to_stretch(ratio, totalAreaRatio, totalAreaRatioInv); + +#endif + + finalColor = vec4(weight_to_rgb(stretch), 1.0); +} diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_tiled_image_borders_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_tiled_image_borders_vert.glsl new file mode 100644 index 00000000000..c762858a910 --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/edit_uv_tiled_image_borders_vert.glsl @@ -0,0 +1,12 @@ +#pragma BLENDER_REQUIRE(common_view_lib.glsl) + +in vec3 pos; + +void main() +{ + /* `pos` contains the coordinates of a quad (-1..1). but we need the coordinates of an image + * plane (0..1) */ + vec3 image_pos = pos * 0.5 + 0.5; + vec4 position = point_object_to_ndc(image_pos); + gl_Position = position; +} diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_verts_frag.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_verts_frag.glsl new file mode 100644 index 00000000000..11694de38ca --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/edit_uv_verts_frag.glsl @@ -0,0 +1,33 @@ + +uniform vec4 outlineColor; + +in vec4 radii; +in vec4 fillColor; +out vec4 fragColor; + +void main() +{ + float dist = length(gl_PointCoord - vec2(0.5)); + + // transparent outside of point + // --- 0 --- + // smooth transition + // --- 1 --- + // pure outline color + // --- 2 --- + // smooth transition + // --- 3 --- + // pure fill color + // ... + // dist = 0 at center of point + + float midStroke = 0.5 * (radii[1] + radii[2]); + + if (dist > midStroke) { + fragColor.rgb = outlineColor.rgb; + fragColor.a = mix(outlineColor.a, 0.0, smoothstep(radii[1], radii[0], dist)); + } + else { + fragColor = mix(fillColor, outlineColor, smoothstep(radii[3], radii[2], dist)); + } +} diff --git a/source/blender/draw/engines/overlay/shaders/edit_uv_verts_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_uv_verts_vert.glsl new file mode 100644 index 00000000000..327a35ce6b2 --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/edit_uv_verts_vert.glsl @@ -0,0 +1,44 @@ +#pragma BLENDER_REQUIRE(common_globals_lib.glsl) +#pragma BLENDER_REQUIRE(common_view_lib.glsl) + +uniform float pointSize; +uniform float outlineWidth; + +in vec2 u; +in int flag; + +out vec4 fillColor; +out vec4 outlineColor; +out vec4 radii; + +/* TODO Theme? */ +const vec4 pinned_col = vec4(1.0, 0.0, 0.0, 1.0); + +void main() +{ + bool is_selected = (flag & (VERT_UV_SELECT | FACE_UV_SELECT)) != 0; + bool is_pinned = (flag & VERT_UV_PINNED) != 0; + vec4 deselect_col = (is_pinned) ? pinned_col : vec4(colorWire.rgb, 1.0); + fillColor = (is_selected) ? colorVertexSelect : deselect_col; + outlineColor = (is_pinned) ? pinned_col : vec4(fillColor.rgb, 0.0); + + vec3 world_pos = point_object_to_world(vec3(u, 0.0)); + /* Move selected vertices to the top + * Vertices are between 0.0 and 0.2, Edges between 0.2 and 0.4 + * actual pixels are at 0.75, 1.0 is used for the background. */ + float depth = is_selected ? 0.05 : 0.15; + gl_Position = vec4(point_world_to_ndc(world_pos).xy, depth, 1.0); + gl_PointSize = pointSize; + + // calculate concentric radii in pixels + float radius = 0.5 * pointSize; + + // start at the outside and progress toward the center + radii[0] = radius; + radii[1] = radius - 1.0; + radii[2] = radius - outlineWidth; + radii[3] = radius - outlineWidth - 1.0; + + // convert to PointCoord units + radii /= pointSize; +} diff --git a/source/blender/draw/engines/overlay/shaders/grid_vert.glsl b/source/blender/draw/engines/overlay/shaders/grid_vert.glsl index dd0e771ad93..6df4ead9f2a 100644 --- a/source/blender/draw/engines/overlay/shaders/grid_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/grid_vert.glsl @@ -12,7 +12,7 @@ uniform int gridFlag; #define PLANE_YZ (1 << 6) #define CLIP_Z_POS (1 << 7) #define CLIP_Z_NEG (1 << 8) - +#define PLANE_IMAGE (1 << 11) in vec3 pos; out vec3 local_pos; @@ -28,9 +28,12 @@ void main() else if ((gridFlag & PLANE_XZ) != 0) { vert_pos = vec3(pos.x, 0.0, pos.y); } - else { + else if ((gridFlag & PLANE_YZ) != 0) { vert_pos = vec3(0.0, pos.x, pos.y); } + else /* PLANE_IMAGE */ { + vert_pos = vec3(pos.xy * 0.5 + 0.5, 0.0); + } local_pos = vert_pos; diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index e154a52b32f..8e3562216e9 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -736,9 +736,11 @@ bool DRW_state_draw_background(void); /* Avoid too many lookups while drawing */ typedef struct DRWContextState { - struct ARegion *region; /* 'CTX_wm_region(C)' */ - struct RegionView3D *rv3d; /* 'CTX_wm_region_view3d(C)' */ - struct View3D *v3d; /* 'CTX_wm_view3d(C)' */ + + struct ARegion *region; /* 'CTX_wm_region(C)' */ + struct RegionView3D *rv3d; /* 'CTX_wm_region_view3d(C)' */ + struct View3D *v3d; /* 'CTX_wm_view3d(C)' */ + struct SpaceLink *space_data; /* 'CTX_wm_space_data(C)' */ struct Scene *scene; /* 'CTX_data_scene(C)' */ struct ViewLayer *view_layer; /* 'CTX_data_view_layer(C)' */ diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index c7ba707d403..d090832dc4b 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -1559,8 +1559,14 @@ void DRW_mesh_batch_cache_create_requested(struct TaskGraph *task_graph, scene, ts, use_hide); - /* TODO(jbakker): Work-around for threading issues in 2.90. See T79533, T79038. Needs to be - * solved or made permanent in 2.91. Underlying issue still needs to be researched. */ + + /* Ensure that all requested batches have finished. + * Ideally we want to remove this sync, but there are cases where this doesn't work. + * See T79038 for example. + * + * An idea to improve this is to separate the Object mode from the edit mode draw caches. And + * based on the mode the correct one will be updated. Other option is to look into using + * drw_batch_cache_generate_requested_delayed. */ BLI_task_graph_work_and_wait(task_graph); #ifdef DEBUG drw_mesh_batch_cache_check_available(task_graph, me); diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index ea5421f3965..56f31a69396 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -178,6 +178,9 @@ void DRW_globals_update(void) UI_GetThemeColorShadeAlpha4fv(TH_WIRE, 0, -30, gb->colorOutline); UI_GetThemeColorShadeAlpha4fv(TH_LIGHT, 0, 255, gb->colorLightNoAlpha); + /* UV colors */ + UI_GetThemeColor4fv(TH_UV_SHADOW, gb->colorUVShadow); + gb->sizePixel = U.pixelsize; gb->sizeObjectCenter = (UI_GetThemeValuef(TH_OBCENTER_DIA) + 1.0f) * U.pixelsize; gb->sizeLightCenter = (UI_GetThemeValuef(TH_OBCENTER_DIA) + 1.5f) * U.pixelsize; @@ -210,7 +213,7 @@ void DRW_globals_update(void) /* TODO more accurate transform. */ srgb_to_linearrgb_v4(color, color); color += 4; - } while (color != gb->UBO_LAST_COLOR); + } while (color <= gb->UBO_LAST_COLOR); } if (G_draw.block_ubo == NULL) { diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h index 645848e7fe0..e3967678319 100644 --- a/source/blender/draw/intern/draw_common.h +++ b/source/blender/draw/intern/draw_common.h @@ -33,7 +33,7 @@ struct RegionView3D; struct ViewLayer; #define UBO_FIRST_COLOR colorWire -#define UBO_LAST_COLOR colorFaceFront +#define UBO_LAST_COLOR colorUVShadow /* Used as ubo but colors can be directly referenced as well */ /* Keep in sync with: common_globals_lib.glsl (globalsBlock) */ @@ -141,6 +141,8 @@ typedef struct GlobalsUboStorage { float colorFaceBack[4]; float colorFaceFront[4]; + float colorUVShadow[4]; + /* NOTE! Put all color before UBO_LAST_COLOR */ float screenVecs[2][4]; /* padded as vec4 */ float sizeViewport[2], sizeViewportInv[2]; /* packed as vec4 in glsl */ diff --git a/source/blender/draw/intern/draw_fluid.c b/source/blender/draw/intern/draw_fluid.c index af14f11e6e9..809512bd7dd 100644 --- a/source/blender/draw/intern/draw_fluid.c +++ b/source/blender/draw/intern/draw_fluid.c @@ -183,6 +183,10 @@ static GPUTexture *create_volume_texture(const int dim[3], GPUTexture *tex = NULL; int final_dim[3] = {UNPACK3(dim)}; + if (data == NULL) { + return NULL; + } + while (1) { tex = GPU_texture_create_3d("volume", UNPACK3(final_dim), 1, format, NULL); @@ -292,6 +296,10 @@ static GPUTexture *create_density_texture(FluidDomainSettings *fds, int highres) data = manta_smoke_get_density(fds->fluid); } + if (data == NULL) { + return NULL; + } + GPUTexture *tex = create_volume_texture(dim, GPU_R8, data); swizzle_texture_channel_single(tex); return tex; diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index e6d51bce54e..203f8af130d 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -78,6 +78,7 @@ #include "RE_pipeline.h" #include "UI_resources.h" +#include "UI_view2d.h" #include "WM_api.h" #include "wm_window.h" @@ -94,6 +95,7 @@ #include "engines/eevee/eevee_engine.h" #include "engines/external/external_engine.h" #include "engines/gpencil/gpencil_engine.h" +#include "engines/image/image_engine.h" #include "engines/overlay/overlay_engine.h" #include "engines/select/select_engine.h" #include "engines/workbench/workbench_engine.h" @@ -126,6 +128,25 @@ static void drw_state_ensure_not_reused(DRWManager *dst) } #endif +static bool drw_draw_show_annotation(void) +{ + if (DST.draw_ctx.space_data == NULL) { + View3D *v3d = DST.draw_ctx.v3d; + return (v3d && ((v3d->flag2 & V3D_SHOW_ANNOTATION) != 0) && + ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0)); + } + + switch (DST.draw_ctx.space_data->spacetype) { + case SPACE_IMAGE: { + SpaceImage *sima = (SpaceImage *)DST.draw_ctx.space_data; + return (sima->flag & SI_SHOW_GPENCIL) != 0; + } + default: + BLI_assert(""); + return false; + } +} + /* -------------------------------------------------------------------- */ /** \name Threading * \{ */ @@ -287,6 +308,7 @@ struct DupliObject *DRW_object_get_dupli(const Object *UNUSED(ob)) /** \name Color Management * \{ */ +/* TODO(fclem) This should be a render engine callback to determine if we need CM or not. */ static void drw_viewport_colormanagement_set(void) { Scene *scene = DST.draw_ctx.scene; @@ -296,21 +318,43 @@ static void drw_viewport_colormanagement_set(void) ColorManagedViewSettings view_settings; float dither = 0.0f; - /* TODO(fclem) This should be a render engine callback to determine if we need CM or not. */ - bool use_workbench = BKE_scene_uses_blender_workbench(scene); - - bool use_scene_lights = (!v3d || - ((v3d->shading.type == OB_MATERIAL) && - (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS)) || - ((v3d->shading.type == OB_RENDER) && - (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS_RENDER))); - bool use_scene_world = - (!v3d || - ((v3d->shading.type == OB_MATERIAL) && (v3d->shading.flag & V3D_SHADING_SCENE_WORLD)) || - ((v3d->shading.type == OB_RENDER) && (v3d->shading.flag & V3D_SHADING_SCENE_WORLD_RENDER))); - bool use_view_transform = v3d && (v3d->shading.type >= OB_MATERIAL); - bool use_render_settings = v3d && ((use_workbench && use_view_transform) || use_scene_lights || - use_scene_world); + bool use_render_settings = false; + bool use_view_transform = false; + + if (v3d) { + bool use_workbench = BKE_scene_uses_blender_workbench(scene); + + bool use_scene_lights = (!v3d || + ((v3d->shading.type == OB_MATERIAL) && + (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS)) || + ((v3d->shading.type == OB_RENDER) && + (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS_RENDER))); + bool use_scene_world = (!v3d || + ((v3d->shading.type == OB_MATERIAL) && + (v3d->shading.flag & V3D_SHADING_SCENE_WORLD)) || + ((v3d->shading.type == OB_RENDER) && + (v3d->shading.flag & V3D_SHADING_SCENE_WORLD_RENDER))); + use_view_transform = v3d && (v3d->shading.type >= OB_MATERIAL); + use_render_settings = v3d && ((use_workbench && use_view_transform) || use_scene_lights || + use_scene_world); + } + else if (DST.draw_ctx.space_data && DST.draw_ctx.space_data->spacetype == SPACE_IMAGE) { + SpaceImage *sima = (SpaceImage *)DST.draw_ctx.space_data; + Image *image = sima->image; + + /* Use inverse logic as there isn't a setting for `Color And Alpha`. */ + const eSpaceImage_Flag display_channels_mode = sima->flag; + const bool display_color_channel = (display_channels_mode & (SI_SHOW_ALPHA | SI_SHOW_ZBUF)) == + 0; + if (display_color_channel && image && (image->source != IMA_SRC_GENERATED) && + ((image->flag & IMA_VIEW_AS_RENDER) != 0)) { + use_render_settings = true; + } + } + else { + use_render_settings = true; + use_view_transform = false; + } if (use_render_settings) { /* Use full render settings, for renders with scene lighting. */ @@ -495,6 +539,8 @@ static void draw_unit_state_create(void) static void drw_viewport_var_init(void) { RegionView3D *rv3d = DST.draw_ctx.rv3d; + ARegion *region = DST.draw_ctx.region; + /* Refresh DST.size */ if (DST.viewport) { int size[2]; @@ -585,6 +631,24 @@ static void drw_viewport_var_init(void) DST.view_active = DST.view_default; DST.view_previous = NULL; } + else if (region) { + View2D *v2d = ®ion->v2d; + float viewmat[4][4]; + float winmat[4][4]; + + rctf region_space = {0.0f, 1.0f, 0.0f, 1.0f}; + BLI_rctf_transform_calc_m4_pivot_min(&v2d->cur, ®ion_space, viewmat); + + unit_m4(winmat); + winmat[0][0] = 2.0f; + winmat[1][1] = 2.0f; + winmat[3][0] = -1.0f; + winmat[3][1] = -1.0f; + + DST.view_default = DRW_view_create(viewmat, winmat, NULL, NULL, NULL); + DST.view_active = DST.view_default; + DST.view_previous = NULL; + } else { zero_v3(DST.screenvecs[0]); zero_v3(DST.screenvecs[1]); @@ -596,7 +660,7 @@ static void drw_viewport_var_init(void) } /* fclem: Is this still needed ? */ - if (DST.draw_ctx.object_edit) { + if (DST.draw_ctx.object_edit && rv3d) { ED_view3d_init_mats_rv3d(DST.draw_ctx.object_edit, rv3d); } @@ -1163,6 +1227,19 @@ static void drw_engines_enable_basic(void) use_drw_engine(&draw_engine_basic_type); } +static void drw_engines_enable_editors(void) +{ + SpaceLink *space_data = DST.draw_ctx.space_data; + if (!space_data) { + return; + } + + if (space_data->spacetype == SPACE_IMAGE) { + use_drw_engine(&draw_engine_image_type); + use_drw_engine(&draw_engine_overlay_type); + } +} + static void drw_engines_enable(ViewLayer *UNUSED(view_layer), RenderEngineType *engine_type, bool gpencil_engine_needed) @@ -1299,8 +1376,7 @@ void DRW_draw_callbacks_post_scene(void) View3D *v3d = DST.draw_ctx.v3d; Depsgraph *depsgraph = DST.draw_ctx.depsgraph; - const bool do_annotations = (v3d && ((v3d->flag2 & V3D_SHOW_ANNOTATION) != 0) && - ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0)); + const bool do_annotations = drw_draw_show_annotation(); if (DST.draw_ctx.evil_C) { DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); @@ -1387,21 +1463,30 @@ struct DRWTextStore *DRW_text_cache_ensure(void) * for each relevant engine / mode engine. */ void DRW_draw_view(const bContext *C) { - Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); - ARegion *region = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); - Scene *scene = DEG_get_evaluated_scene(depsgraph); - RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->shading.type); - GPUViewport *viewport = WM_draw_region_get_bound_viewport(region); + if (v3d) { + Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); + ARegion *region = CTX_wm_region(C); + Scene *scene = DEG_get_evaluated_scene(depsgraph); + RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->shading.type); + GPUViewport *viewport = WM_draw_region_get_bound_viewport(region); - /* Reset before using it. */ - drw_state_prepare_clean_for_draw(&DST); - DST.options.draw_text = ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0 && - (v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) != 0); - DST.options.draw_background = (scene->r.alphamode == R_ADDSKY) || - (v3d->shading.type != OB_RENDER); - DST.options.do_color_management = true; - DRW_draw_render_loop_ex(depsgraph, engine_type, region, v3d, viewport, C); + /* Reset before using it. */ + drw_state_prepare_clean_for_draw(&DST); + DST.options.draw_text = ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0 && + (v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) != 0); + DST.options.draw_background = (scene->r.alphamode == R_ADDSKY) || + (v3d->shading.type != OB_RENDER); + DST.options.do_color_management = true; + DRW_draw_render_loop_ex(depsgraph, engine_type, region, v3d, viewport, C); + } + else { + Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); + ARegion *ar = CTX_wm_region(C); + GPUViewport *viewport = WM_draw_region_get_bound_viewport(ar); + drw_state_prepare_clean_for_draw(&DST); + DRW_draw_render_loop_2d_ex(depsgraph, ar, viewport, C); + } } /** @@ -1909,6 +1994,171 @@ void DRW_cache_restart(void) copy_v2_v2(DST.inv_size, inv_size); } +void DRW_draw_render_loop_2d_ex(struct Depsgraph *depsgraph, + ARegion *region, + GPUViewport *viewport, + const bContext *evil_C) +{ + Scene *scene = DEG_get_evaluated_scene(depsgraph); + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); + + DST.draw_ctx.evil_C = evil_C; + DST.viewport = viewport; + + /* Setup viewport */ + DST.draw_ctx = (DRWContextState){ + .region = region, + .scene = scene, + .view_layer = view_layer, + .obact = OBACT(view_layer), + .depsgraph = depsgraph, + .space_data = CTX_wm_space_data(evil_C), + + /* reuse if caller sets */ + .evil_C = DST.draw_ctx.evil_C, + }; + + drw_context_state_init(); + drw_viewport_var_init(); + drw_viewport_colormanagement_set(); + + /* TODO(jbakker): Only populate when editor needs to draw object. + * for the image editor this is when showing UV's.*/ + const bool do_populate_loop = true; + const bool do_annotations = drw_draw_show_annotation(); + + /* Get list of enabled engines */ + drw_engines_enable_editors(); + drw_engines_data_validate(); + + /* Update ubos */ + DRW_globals_update(); + + drw_debug_init(); + + /* No framebuffer allowed before drawing. */ + BLI_assert(GPU_framebuffer_active_get() == GPU_framebuffer_back_get()); + GPU_framebuffer_bind(DST.default_framebuffer); + GPU_framebuffer_clear_depth_stencil(DST.default_framebuffer, 1.0f, 0xFF); + + /* Init engines */ + drw_engines_init(); + drw_task_graph_init(); + + /* Cache filling */ + { + PROFILE_START(stime); + drw_engines_cache_init(); + + /* Only iterate over objects when overlay uses object data. */ + if (do_populate_loop) { + DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN (depsgraph, ob) { + drw_engines_cache_populate(ob); + } + DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END; + } + + drw_engines_cache_finish(); + + DRW_render_instance_buffer_finish(); + +#ifdef USE_PROFILE + double *cache_time = GPU_viewport_cache_time_get(DST.viewport); + PROFILE_END_UPDATE(*cache_time, stime); +#endif + } + drw_task_graph_deinit(); + + DRW_stats_begin(); + + GPU_framebuffer_bind(DST.default_framebuffer); + + /* Start Drawing */ + DRW_state_reset(); + + if (DST.draw_ctx.evil_C) { + ED_region_draw_cb_draw(DST.draw_ctx.evil_C, DST.draw_ctx.region, REGION_DRAW_PRE_VIEW); + } + + drw_engines_draw_scene(); + + /* Fix 3D view being "laggy" on macos and win+nvidia. (See T56996, T61474) */ + GPU_flush(); + + if (DST.draw_ctx.evil_C) { + DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DRW_state_reset(); + + GPU_framebuffer_bind(dfbl->overlay_fb); + + if (do_annotations) { + GPU_depth_test(false); + GPU_matrix_push_projection(); + wmOrtho2( + region->v2d.cur.xmin, region->v2d.cur.xmax, region->v2d.cur.ymin, region->v2d.cur.ymax); + ED_annotation_draw_view2d(DST.draw_ctx.evil_C, true); + GPU_matrix_pop_projection(); + + GPU_depth_test(true); + } + + GPU_depth_test(false); + ED_region_draw_cb_draw(DST.draw_ctx.evil_C, DST.draw_ctx.region, REGION_DRAW_POST_VIEW); + GPU_depth_test(true); + /* Callback can be nasty and do whatever they want with the state. + * Don't trust them! */ + DRW_state_reset(); + + GPU_depth_test(false); + drw_engines_draw_text(); + GPU_depth_test(true); + + if (do_annotations) { + GPU_depth_test(false); + ED_annotation_draw_view2d(DST.draw_ctx.evil_C, false); + GPU_depth_test(true); + } + } + + DRW_draw_cursor_2d(); + ED_region_pixelspace(DST.draw_ctx.region); + + { + GPU_depth_test(false); + DRW_draw_gizmo_2d(); + GPU_depth_test(true); + } + + DRW_stats_reset(); + + if (G.debug_value > 20 && G.debug_value < 30) { + GPU_depth_test(false); + /* local coordinate visible rect inside region, to accommodate overlapping ui */ + const rcti *rect = ED_region_visible_rect(DST.draw_ctx.region); + DRW_stats_draw(rect); + GPU_depth_test(true); + } + + if (WM_draw_region_get_bound_viewport(region)) { + /* Don't unbind the framebuffer yet in this case and let + * GPU_viewport_unbind do it, so that we can still do further + * drawing of action zones on top. */ + } + else { + GPU_framebuffer_restore(); + } + + DRW_state_reset(); + drw_engines_disable(); + + drw_viewport_cache_resize(); + +#ifdef DEBUG + /* Avoid accidental reuse. */ + drw_state_ensure_not_reused(&DST); +#endif +} + static struct DRWSelectBuffer { struct GPUFrameBuffer *framebuffer_depth_only; struct GPUTexture *texture_depth; @@ -2637,6 +2887,8 @@ void DRW_engines_register(void) DRW_engine_register(&draw_engine_select_type); DRW_engine_register(&draw_engine_basic_type); + DRW_engine_register(&draw_engine_image_type); + /* setup callbacks */ { BKE_mball_batch_cache_dirty_tag_cb = DRW_mball_batch_cache_dirty_tag; diff --git a/source/blender/draw/intern/draw_manager_text.c b/source/blender/draw/intern/draw_manager_text.c index adcac15ab85..e3d0dab6767 100644 --- a/source/blender/draw/intern/draw_manager_text.c +++ b/source/blender/draw/intern/draw_manager_text.c @@ -24,6 +24,7 @@ #include "BLI_math.h" #include "BLI_memiter.h" +#include "BLI_rect.h" #include "BLI_string.h" #include "BKE_editmesh.h" @@ -122,76 +123,105 @@ void DRW_text_cache_add(DRWTextStore *dt, } } -void DRW_text_cache_draw(DRWTextStore *dt, ARegion *region, struct View3D *v3d) +static void drw_text_cache_draw_ex(DRWTextStore *dt, ARegion *region) { - RegionView3D *rv3d = region->regiondata; ViewCachedString *vos; - int tot = 0; - - /* project first and test */ BLI_memiter_handle it; - BLI_memiter_iter_init(dt->cache_strings, &it); - while ((vos = BLI_memiter_iter_step(&it))) { - if (ED_view3d_project_short_ex( - region, - (vos->flag & DRW_TEXT_CACHE_GLOBALSPACE) ? rv3d->persmat : rv3d->persmatob, - (vos->flag & DRW_TEXT_CACHE_LOCALCLIP) != 0, - vos->vec, - vos->sco, - V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == - V3D_PROJ_RET_OK) { - tot++; - } - else { - vos->sco[0] = IS_CLIPPED; - } - } + int col_pack_prev = 0; - if (tot) { - int col_pack_prev = 0; + float original_proj[4][4]; + GPU_matrix_projection_get(original_proj); + wmOrtho2_region_pixelspace(region); - /* Disable clipping for text */ - if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) { - GPU_clip_distances(0); - } + GPU_matrix_push(); + GPU_matrix_identity_set(); - float original_proj[4][4]; - GPU_matrix_projection_get(original_proj); - wmOrtho2_region_pixelspace(region); + const int font_id = BLF_default(); - GPU_matrix_push(); - GPU_matrix_identity_set(); + const uiStyle *style = UI_style_get(); - const int font_id = BLF_default(); + BLF_size(font_id, style->widget.points * U.pixelsize, U.dpi); - const uiStyle *style = UI_style_get(); + BLI_memiter_iter_init(dt->cache_strings, &it); + while ((vos = BLI_memiter_iter_step(&it))) { + if (vos->sco[0] != IS_CLIPPED) { + if (col_pack_prev != vos->col.pack) { + BLF_color4ubv(font_id, vos->col.ub); + col_pack_prev = vos->col.pack; + } + + BLF_position( + font_id, (float)(vos->sco[0] + vos->xoffs), (float)(vos->sco[1] + vos->yoffs), 2.0f); + + ((vos->flag & DRW_TEXT_CACHE_ASCII) ? BLF_draw_ascii : BLF_draw)( + font_id, + (vos->flag & DRW_TEXT_CACHE_STRING_PTR) ? *((const char **)vos->str) : vos->str, + vos->str_len); + } + } - BLF_size(font_id, style->widget.points * U.pixelsize, U.dpi); + GPU_matrix_pop(); + GPU_matrix_projection_set(original_proj); +} +void DRW_text_cache_draw(DRWTextStore *dt, ARegion *region, struct View3D *v3d) +{ + ViewCachedString *vos; + if (v3d) { + RegionView3D *rv3d = region->regiondata; + int tot = 0; + /* project first and test */ + BLI_memiter_handle it; BLI_memiter_iter_init(dt->cache_strings, &it); while ((vos = BLI_memiter_iter_step(&it))) { - if (vos->sco[0] != IS_CLIPPED) { - if (col_pack_prev != vos->col.pack) { - BLF_color4ubv(font_id, vos->col.ub); - col_pack_prev = vos->col.pack; - } + if (ED_view3d_project_short_ex( + region, + (vos->flag & DRW_TEXT_CACHE_GLOBALSPACE) ? rv3d->persmat : rv3d->persmatob, + (vos->flag & DRW_TEXT_CACHE_LOCALCLIP) != 0, + vos->vec, + vos->sco, + V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == + V3D_PROJ_RET_OK) { + tot++; + } + else { + vos->sco[0] = IS_CLIPPED; + } + } - BLF_position( - font_id, (float)(vos->sco[0] + vos->xoffs), (float)(vos->sco[1] + vos->yoffs), 2.0f); + if (tot) { + /* Disable clipping for text */ + const bool rv3d_clipping_enabled = RV3D_CLIPPING_ENABLED(v3d, rv3d); + if (rv3d_clipping_enabled) { + GPU_clip_distances(0); + } + + drw_text_cache_draw_ex(dt, region); - ((vos->flag & DRW_TEXT_CACHE_ASCII) ? BLF_draw_ascii : BLF_draw)( - font_id, - (vos->flag & DRW_TEXT_CACHE_STRING_PTR) ? *((const char **)vos->str) : vos->str, - vos->str_len); + if (rv3d_clipping_enabled) { + GPU_clip_distances(6); } } + } + else { + /* project first */ + BLI_memiter_handle it; + BLI_memiter_iter_init(dt->cache_strings, &it); + View2D *v2d = ®ion->v2d; + float viewmat[4][4]; + rctf region_space = {0.0f, region->winx, 0.0f, region->winy}; + BLI_rctf_transform_calc_m4_pivot_min(&v2d->cur, ®ion_space, viewmat); - GPU_matrix_pop(); - GPU_matrix_projection_set(original_proj); + while ((vos = BLI_memiter_iter_step(&it))) { + float p[3]; + copy_v3_v3(p, vos->vec); + mul_m4_v3(viewmat, p); - if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) { - GPU_clip_distances(6); + vos->sco[0] = p[0]; + vos->sco[1] = p[1]; } + + drw_text_cache_draw_ex(dt, region); } } diff --git a/source/blender/draw/intern/draw_view.c b/source/blender/draw/intern/draw_view.c index d01e1a51080..3033cf70b29 100644 --- a/source/blender/draw/intern/draw_view.c +++ b/source/blender/draw/intern/draw_view.c @@ -35,6 +35,7 @@ #include "GPU_shader.h" #include "UI_resources.h" +#include "UI_view2d.h" #include "WM_types.h" @@ -196,6 +197,65 @@ void DRW_draw_cursor(void) } } +/* -------------------------------------------------------------------- */ + +/** \name 2D Cursor + * \{ */ + +static bool is_cursor_visible_2d(const DRWContextState *draw_ctx) +{ + SpaceInfo *space_data = (SpaceInfo *)draw_ctx->space_data; + if (space_data == NULL) { + return false; + } + if (space_data->spacetype == SPACE_IMAGE) { + SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + return sima->mode == SI_MODE_UV; + } + return false; +} + +void DRW_draw_cursor_2d(void) +{ + const DRWContextState *draw_ctx = DRW_context_state_get(); + ARegion *region = draw_ctx->region; + + GPU_color_mask(true, true, true, true); + GPU_depth_mask(false); + GPU_depth_test(GPU_DEPTH_NONE); + + if (is_cursor_visible_2d(draw_ctx)) { + SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + int co[2]; + UI_view2d_view_to_region(®ion->v2d, sima->cursor[0], sima->cursor[1], &co[0], &co[1]); + + /* Draw nice Anti Aliased cursor. */ + GPU_line_width(1.0f); + GPU_blend(true); + GPU_line_smooth(true); + + /* Draw lines */ + float original_proj[4][4]; + GPU_matrix_projection_get(original_proj); + GPU_matrix_push(); + ED_region_pixelspace(region); + GPU_matrix_translate_2f(co[0] + 0.5f, co[1] + 0.5f); + GPU_matrix_scale_2f(U.widget_unit, U.widget_unit); + + GPUBatch *cursor_batch = DRW_cache_cursor_get(true); + GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_FLAT_COLOR); + GPU_batch_set_shader(cursor_batch, shader); + + GPU_batch_draw(cursor_batch); + + GPU_blend(false); + GPU_line_smooth(false); + GPU_matrix_pop(); + GPU_matrix_projection_set(original_proj); + } +} +/* \} */ + /* **************************** 3D Gizmo ******************************** */ void DRW_draw_gizmo_3d(void) diff --git a/source/blender/draw/intern/draw_view.h b/source/blender/draw/intern/draw_view.h index a01a2d0dcce..24fabaae05e 100644 --- a/source/blender/draw/intern/draw_view.h +++ b/source/blender/draw/intern/draw_view.h @@ -25,5 +25,6 @@ void DRW_draw_region_info(void); void DRW_clear_background(void); void DRW_draw_cursor(void); +void DRW_draw_cursor_2d(void); void DRW_draw_gizmo_3d(void); void DRW_draw_gizmo_2d(void); diff --git a/source/blender/draw/intern/shaders/common_globals_lib.glsl b/source/blender/draw/intern/shaders/common_globals_lib.glsl index bd1b1fb6f3a..691f1d5e519 100644 --- a/source/blender/draw/intern/shaders/common_globals_lib.glsl +++ b/source/blender/draw/intern/shaders/common_globals_lib.glsl @@ -103,6 +103,8 @@ layout(std140) uniform globalsBlock vec4 colorFaceBack; vec4 colorFaceFront; + vec4 colorUVShadow; + vec4 screenVecs[2]; vec4 sizeViewport; /* Inverted size in zw. */ diff --git a/source/blender/draw/tests/shaders_test.cc b/source/blender/draw/tests/shaders_test.cc index b73c94208b5..8feccc9588e 100644 --- a/source/blender/draw/tests/shaders_test.cc +++ b/source/blender/draw/tests/shaders_test.cc @@ -11,6 +11,7 @@ #include "engines/eevee/eevee_private.h" #include "engines/gpencil/gpencil_engine.h" +#include "engines/image/image_private.h" #include "engines/overlay/overlay_private.h" #include "engines/workbench/workbench_private.h" @@ -151,8 +152,19 @@ TEST_F(DrawTest, gpencil_glsl_shaders) GPENCIL_shader_free(); } +TEST_F(DrawTest, image_glsl_shaders) +{ + IMAGE_shader_library_ensure(); + + EXPECT_NE(IMAGE_shader_image_get(), nullptr); + + IMAGE_shader_free(); +} + TEST_F(DrawTest, overlay_glsl_shaders) { + OVERLAY_shader_library_ensure(); + for (int i = 0; i < 2; i++) { eGPUShaderConfig sh_cfg = i == 0 ? GPU_SHADER_CFG_DEFAULT : GPU_SHADER_CFG_CLIPPED; DRW_draw_state_init_gtests(sh_cfg); @@ -189,6 +201,13 @@ TEST_F(DrawTest, overlay_glsl_shaders) EXPECT_NE(OVERLAY_shader_edit_mesh_vert(), nullptr); EXPECT_NE(OVERLAY_shader_edit_particle_strand(), nullptr); EXPECT_NE(OVERLAY_shader_edit_particle_point(), nullptr); + EXPECT_NE(OVERLAY_shader_edit_uv_edges_get(), nullptr); + EXPECT_NE(OVERLAY_shader_edit_uv_face_get(), nullptr); + EXPECT_NE(OVERLAY_shader_edit_uv_face_dots_get(), nullptr); + EXPECT_NE(OVERLAY_shader_edit_uv_verts_get(), nullptr); + EXPECT_NE(OVERLAY_shader_edit_uv_stretching_area_get(), nullptr); + EXPECT_NE(OVERLAY_shader_edit_uv_stretching_angle_get(), nullptr); + EXPECT_NE(OVERLAY_shader_edit_uv_tiled_image_borders_get(), nullptr); EXPECT_NE(OVERLAY_shader_extra(false), nullptr); EXPECT_NE(OVERLAY_shader_extra(true), nullptr); EXPECT_NE(OVERLAY_shader_extra_groundline(), nullptr); @@ -201,6 +220,7 @@ TEST_F(DrawTest, overlay_glsl_shaders) EXPECT_NE(OVERLAY_shader_facing(), nullptr); EXPECT_NE(OVERLAY_shader_gpencil_canvas(), nullptr); EXPECT_NE(OVERLAY_shader_grid(), nullptr); + EXPECT_NE(OVERLAY_shader_grid_image(), nullptr); EXPECT_NE(OVERLAY_shader_image(), nullptr); EXPECT_NE(OVERLAY_shader_motion_path_line(), nullptr); EXPECT_NE(OVERLAY_shader_motion_path_vert(), nullptr); diff --git a/source/blender/editors/CMakeLists.txt b/source/blender/editors/CMakeLists.txt index 7910cf47a33..1f5dc73f732 100644 --- a/source/blender/editors/CMakeLists.txt +++ b/source/blender/editors/CMakeLists.txt @@ -23,11 +23,12 @@ if(WITH_BLENDER) add_subdirectory(animation) add_subdirectory(armature) add_subdirectory(curve) + add_subdirectory(geometry) + add_subdirectory(gizmo_library) add_subdirectory(gpencil) add_subdirectory(interface) add_subdirectory(io) add_subdirectory(lattice) - add_subdirectory(gizmo_library) add_subdirectory(mask) add_subdirectory(mesh) add_subdirectory(metaball) diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c index 3b15cd794d8..4d5ff33d5cf 100644 --- a/source/blender/editors/animation/drivers.c +++ b/source/blender/editors/animation/drivers.c @@ -355,9 +355,8 @@ int ANIM_add_driver_with_target(ReportList *reports, int src_len = (RNA_property_array_check(prop)) ? RNA_property_array_length(&ptr2, prop2) : 1; int len = MIN2(dst_len, src_len); - int i; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { done_tot += add_driver_with_target(reports, dst_id, dst_path, @@ -378,9 +377,8 @@ int ANIM_add_driver_with_target(ReportList *reports, case CREATEDRIVER_MAPPING_1_N: /* 1-N - Specified target index for all */ default: { int len = (RNA_property_array_check(prop)) ? RNA_property_array_length(&ptr, prop) : 1; - int i; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { done_tot += add_driver_with_target(reports, dst_id, dst_path, diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 9d54be61171..a8fb0be4fbf 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -177,7 +177,6 @@ static void draw_modifier__generator(uiLayout *layout, const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; float *cp = NULL; char xval[32]; - uint i; int maxXWidth; /* draw polynomial order selector */ @@ -221,7 +220,7 @@ static void draw_modifier__generator(uiLayout *layout, UI_block_func_set(block, deg_update, fcurve_owner_id, NULL); cp = data->coefficients; - for (i = 0; (i < data->arraysize) && (cp); i++, cp++) { + for (uint i = 0; (i < data->arraysize) && (cp); i++, cp++) { /* To align with first line... */ if (i) { uiDefBut(block, @@ -319,7 +318,6 @@ static void draw_modifier__generator(uiLayout *layout, case FCM_GENERATOR_POLYNOMIAL_FACTORISED: /* Factorized polynomial expression */ { float *cp = NULL; - uint i; /* draw polynomial order selector */ row = uiLayoutRow(layout, false); @@ -351,7 +349,7 @@ static void draw_modifier__generator(uiLayout *layout, UI_block_func_set(block, deg_update, fcurve_owner_id, NULL); cp = data->coefficients; - for (i = 0; (i < data->poly_order) && (cp); i++, cp += 2) { + for (uint i = 0; (i < data->poly_order) && (cp); i++, cp += 2) { /* To align with first line */ if (i) { uiDefBut(block, diff --git a/source/blender/editors/animation/keyframes_edit.c b/source/blender/editors/animation/keyframes_edit.c index ef86b132a60..de2525ee150 100644 --- a/source/blender/editors/animation/keyframes_edit.c +++ b/source/blender/editors/animation/keyframes_edit.c @@ -943,11 +943,8 @@ KeyframeEditFunc ANIM_editkeyframes_snap(short mode) static void mirror_bezier_xaxis_ex(BezTriple *bezt, const float center) { - float diff; - int i; - - for (i = 0; i < 3; i++) { - diff = (center - bezt->vec[i][0]); + for (int i = 0; i < 3; i++) { + float diff = (center - bezt->vec[i][0]); bezt->vec[i][0] = (center + diff); } swap_v3_v3(bezt->vec[0], bezt->vec[2]); @@ -958,11 +955,8 @@ static void mirror_bezier_xaxis_ex(BezTriple *bezt, const float center) static void mirror_bezier_yaxis_ex(BezTriple *bezt, const float center) { - float diff; - int i; - - for (i = 0; i < 3; i++) { - diff = (center - bezt->vec[i][1]); + for (int i = 0; i < 3; i++) { + float diff = (center - bezt->vec[i][1]); bezt->vec[i][1] = (center + diff); } } diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 64065d6d633..ea032446fc6 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -108,7 +108,6 @@ void delete_fcurve_key(FCurve *fcu, int index, bool do_recalc) /* Delete selected keyframes in given F-Curve */ bool delete_fcurve_keys(FCurve *fcu) { - int i; bool changed = false; if (fcu->bezt == NULL) { /* ignore baked curves */ @@ -116,7 +115,7 @@ bool delete_fcurve_keys(FCurve *fcu) } /* Delete selected BezTriples */ - for (i = 0; i < fcu->totvert; i++) { + for (int i = 0; i < fcu->totvert; i++) { if (fcu->bezt[i].f2 & SELECT) { memmove(&fcu->bezt[i], &fcu->bezt[i + 1], sizeof(BezTriple) * (fcu->totvert - i - 1)); fcu->totvert--; @@ -148,19 +147,16 @@ void clear_fcurve_keys(FCurve *fcu) /* duplicate selected keyframes for the given F-Curve */ void duplicate_fcurve_keys(FCurve *fcu) { - BezTriple *newbezt; - int i; - /* this can only work when there is an F-Curve, and also when there are some BezTriples */ if (ELEM(NULL, fcu, fcu->bezt)) { return; } - for (i = 0; i < fcu->totvert; i++) { + for (int i = 0; i < fcu->totvert; i++) { /* If a key is selected */ if (fcu->bezt[i].f2 & SELECT) { /* Expand the list */ - newbezt = MEM_callocN(sizeof(BezTriple) * (fcu->totvert + 1), "beztriple"); + BezTriple *newbezt = MEM_callocN(sizeof(BezTriple) * (fcu->totvert + 1), "beztriple"); memcpy(newbezt, fcu->bezt, sizeof(BezTriple) * (i + 1)); memcpy(newbezt + i + 1, fcu->bezt + i, sizeof(BezTriple)); @@ -489,16 +485,15 @@ typedef struct tSmooth_Bezt { // TODO: introduce scaling factor for weighting falloff void smooth_fcurve(FCurve *fcu) { - BezTriple *bezt; - int i, x, totSel = 0; + int totSel = 0; if (fcu->bezt == NULL) { return; } /* first loop through - count how many verts are selected */ - bezt = fcu->bezt; - for (i = 0; i < fcu->totvert; i++, bezt++) { + BezTriple *bezt = fcu->bezt; + for (int i = 0; i < fcu->totvert; i++, bezt++) { if (BEZT_ISSEL_ANY(bezt)) { totSel++; } @@ -513,7 +508,7 @@ void smooth_fcurve(FCurve *fcu) /* populate tarray with data of selected points */ bezt = fcu->bezt; - for (i = 0, x = 0; (i < fcu->totvert) && (x < totSel); i++, bezt++) { + for (int i = 0, x = 0; (i < fcu->totvert) && (x < totSel); i++, bezt++) { if (BEZT_ISSEL_ANY(bezt)) { /* tsb simply needs pointer to vec, and index */ tsb->h1 = &bezt->vec[0][1]; @@ -539,7 +534,7 @@ void smooth_fcurve(FCurve *fcu) /* round 1: calculate smoothing deltas and new values */ tsb = tarray; - for (i = 0; i < totSel; i++, tsb++) { + for (int i = 0; i < totSel; i++, tsb++) { /* Don't touch end points (otherwise, curves slowly explode, * as we don't have enough data there). */ if (ELEM(i, 0, (totSel - 1)) == 0) { @@ -564,7 +559,7 @@ void smooth_fcurve(FCurve *fcu) /* round 2: apply new values */ tsb = tarray; - for (i = 0; i < totSel; i++, tsb++) { + for (int i = 0; i < totSel; i++, tsb++) { /* don't touch end points, as their values weren't touched above */ if (ELEM(i, 0, (totSel - 1)) == 0) { /* y2 takes the average of the 2 points */ diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 66d4882cf9d..fb4c0ae0758 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -618,22 +618,19 @@ enum { */ static short new_key_needed(FCurve *fcu, float cFrame, float nValue) { - BezTriple *bezt = NULL, *prev = NULL; - int totCount, i; - float valA = 0.0f, valB = 0.0f; - /* safety checking */ if (fcu == NULL) { return KEYNEEDED_JUSTADD; } - totCount = fcu->totvert; + int totCount = fcu->totvert; if (totCount == 0) { return KEYNEEDED_JUSTADD; } /* loop through checking if any are the same */ - bezt = fcu->bezt; - for (i = 0; i < totCount; i++) { + BezTriple *bezt = fcu->bezt; + BezTriple *prev = NULL; + for (int i = 0; i < totCount; i++) { float prevPosi = 0.0f, prevVal = 0.0f; float beztPosi = 0.0f, beztVal = 0.0f; @@ -712,8 +709,8 @@ static short new_key_needed(FCurve *fcu, float cFrame, float nValue) * keyframe is not equal to last keyframe. */ bezt = (fcu->bezt + (fcu->totvert - 1)); - valA = bezt->vec[1][1]; - + float valA = bezt->vec[1][1]; + float valB; if (prev) { valB = prev->vec[1][1]; } diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c index 7fba855ffdb..4c5efb304c9 100644 --- a/source/blender/editors/armature/armature_select.c +++ b/source/blender/editors/armature/armature_select.c @@ -177,11 +177,10 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode void *firstunSel = NULL, *firstSel = NULL, *data; Base *firstunSel_base = NULL, *firstSel_base = NULL; uint hitresult; - short i; bool takeNext = false; int minsel = 0xffffffff, minunsel = 0xffffffff; - for (i = 0; i < hits; i++) { + for (short i = 0; i < hits; i++) { hitresult = buffer[3 + (i * 4)]; if (hitresult & BONESEL_ANY) { /* to avoid including objects in selection */ diff --git a/source/blender/editors/armature/armature_skinning.c b/source/blender/editors/armature/armature_skinning.c index ea9b0eb92b9..aa742d4b7ba 100644 --- a/source/blender/editors/armature/armature_skinning.c +++ b/source/blender/editors/armature/armature_skinning.c @@ -212,10 +212,6 @@ static void envelope_bone_weighting(Object *ob, { /* Create vertex group weights from envelopes */ - Bone *bone; - bDeformGroup *dgroup; - float distance; - int i, iflip, j; bool use_topology = (mesh->editflag & ME_EDIT_MIRROR_TOPO) != 0; bool use_mask = false; @@ -225,30 +221,30 @@ static void envelope_bone_weighting(Object *ob, } /* for each vertex in the mesh */ - for (i = 0; i < mesh->totvert; i++) { + for (int i = 0; i < mesh->totvert; i++) { if (use_mask && !(mesh->mvert[i].flag & SELECT)) { continue; } - iflip = (dgroupflip) ? mesh_get_x_mirror_vert(ob, NULL, i, use_topology) : -1; + int iflip = (dgroupflip) ? mesh_get_x_mirror_vert(ob, NULL, i, use_topology) : -1; /* for each skinnable bone */ - for (j = 0; j < numbones; j++) { + for (int j = 0; j < numbones; j++) { if (!selected[j]) { continue; } - bone = bonelist[j]; - dgroup = dgrouplist[j]; + Bone *bone = bonelist[j]; + bDeformGroup *dgroup = dgrouplist[j]; /* store the distance-factor from the vertex to the bone */ - distance = distfactor_to_bone(verts[i], - root[j], - tip[j], - bone->rad_head * scale, - bone->rad_tail * scale, - bone->dist * scale); + float distance = distfactor_to_bone(verts[i], + root[j], + tip[j], + bone->rad_head * scale, + bone->rad_tail * scale, + bone->dist * scale); /* add the vert to the deform group if (weight != 0.0) */ if (distance != 0.0f) { @@ -300,7 +296,7 @@ static void add_verts_to_dgroups(ReportList *reports, Mat4 bbone_array[MAX_BBONE_SUBDIV], *bbone = NULL; float(*root)[3], (*tip)[3], (*verts)[3]; int *selected; - int numbones, vertsfilled = 0, i, j, segments = 0; + int numbones, vertsfilled = 0, segments = 0; const bool wpmode = (ob->mode & OB_MODE_WEIGHT_PAINT); struct { Object *armob; @@ -346,7 +342,7 @@ static void add_verts_to_dgroups(ReportList *reports, tip = MEM_callocN(sizeof(float[3]) * numbones, "tip"); selected = MEM_callocN(sizeof(int) * numbones, "selected"); - for (j = 0; j < numbones; j++) { + for (int j = 0; j < numbones; j++) { bone = bonelist[j]; dgroup = dgrouplist[j]; @@ -427,7 +423,7 @@ static void add_verts_to_dgroups(ReportList *reports, } /* transform verts to global space */ - for (i = 0; i < mesh->totvert; i++) { + for (int i = 0; i < mesh->totvert; i++) { if (!vertsfilled) { copy_v3_v3(verts[i], mesh->mvert[i].co); } diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c index 04c1ec97841..1c8c5ba9d94 100644 --- a/source/blender/editors/armature/armature_utils.c +++ b/source/blender/editors/armature/armature_utils.c @@ -198,27 +198,26 @@ bool ED_armature_ebone_is_child_recursive(EditBone *ebone_parent, EditBone *ebon */ EditBone *ED_armature_ebone_find_shared_parent(EditBone *ebone_child[], const uint ebone_child_tot) { - uint i; - EditBone *ebone_iter; - #define EBONE_TEMP_UINT(ebone) (*((uint *)(&((ebone)->temp)))) /* clear all */ - for (i = 0; i < ebone_child_tot; i++) { - for (ebone_iter = ebone_child[i]; ebone_iter; ebone_iter = ebone_iter->parent) { + for (uint i = 0; i < ebone_child_tot; i++) { + for (EditBone *ebone_iter = ebone_child[i]; ebone_iter; ebone_iter = ebone_iter->parent) { EBONE_TEMP_UINT(ebone_iter) = 0; } } /* accumulate */ - for (i = 0; i < ebone_child_tot; i++) { - for (ebone_iter = ebone_child[i]->parent; ebone_iter; ebone_iter = ebone_iter->parent) { + for (uint i = 0; i < ebone_child_tot; i++) { + for (EditBone *ebone_iter = ebone_child[i]->parent; ebone_iter; + ebone_iter = ebone_iter->parent) { EBONE_TEMP_UINT(ebone_iter) += 1; } } /* only need search the first chain */ - for (ebone_iter = ebone_child[0]->parent; ebone_iter; ebone_iter = ebone_iter->parent) { + for (EditBone *ebone_iter = ebone_child[0]->parent; ebone_iter; + ebone_iter = ebone_iter->parent) { if (EBONE_TEMP_UINT(ebone_iter) == ebone_child_tot) { return ebone_iter; } diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index 1534ea3287f..cf64cfc849d 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -1041,7 +1041,6 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb, MDefBoundIsect *isect; float(*mp_cagecos)[3] = BLI_array_alloca(mp_cagecos, mp->totloop); - int i; /* create MDefBoundIsect, and extra for 'poly_weights[]' */ isect = BLI_memarena_alloc(mdb->memarena, sizeof(*isect) + (sizeof(float) * mp->totloop)); @@ -1056,7 +1055,7 @@ static MDefBoundIsect *meshdeform_ray_tree_intersect(MeshDeformBind *mdb, isect->len = max_ff(len_v3v3(co1, isect->co), MESHDEFORM_LEN_THRESHOLD); /* compute mean value coordinates for interpolation */ - for (i = 0; i < mp->totloop; i++) { + for (int i = 0; i < mp->totloop; i++) { copy_v3_v3(mp_cagecos[i], cagecos[mloop[mp->loopstart + i].v]); } @@ -1225,9 +1224,8 @@ static float meshdeform_boundary_phi(const MeshDeformBind *mdb, { const MLoop *mloop = mdb->cagemesh_cache.mloop; const MPoly *mp = &mdb->cagemesh_cache.mpoly[isect->poly_index]; - int i; - for (i = 0; i < mp->totloop; i++) { + for (int i = 0; i < mp->totloop; i++) { if (mloop[mp->loopstart + i].v == cagevert) { return isect->poly_weights[i]; } @@ -1241,16 +1239,18 @@ static float meshdeform_interp_w(MeshDeformBind *mdb, float *UNUSED(vec), int UNUSED(cagevert)) { - float dvec[3], ivec[3], wx, wy, wz, result = 0.0f; - float weight, totweight = 0.0f; - int i, a, x, y, z; + float dvec[3], ivec[3], result = 0.0f; + float totweight = 0.0f; - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { ivec[i] = (int)gridvec[i]; dvec[i] = gridvec[i] - ivec[i]; } - for (i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) { + int x, y, z; + float wx, wy, wz; + if (i & 1) { x = ivec[0] + 1; wx = dvec[0]; @@ -1282,8 +1282,8 @@ static float meshdeform_interp_w(MeshDeformBind *mdb, CLAMP(y, 0, mdb->size - 1); CLAMP(z, 0, mdb->size - 1); - a = meshdeform_index(mdb, x, y, z, 0); - weight = wx * wy * wz; + int a = meshdeform_index(mdb, x, y, z, 0); + float weight = wx * wy * wz; result += weight * mdb->phi[a]; totweight += weight; } diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c index 0cd3afc9cf9..85948f3abc3 100644 --- a/source/blender/editors/armature/pose_edit.c +++ b/source/blender/editors/armature/pose_edit.c @@ -742,7 +742,6 @@ static int pose_armature_layers_showall_exec(bContext *C, wmOperator *op) int maxLayers = (RNA_boolean_get(op->ptr, "all")) ? 32 : 16; /* hardcoded for now - we can only have 32 armature layers, so this should be fine... */ bool layers[32] = {false}; - int i; /* sanity checking */ if (arm == NULL) { @@ -755,7 +754,7 @@ static int pose_armature_layers_showall_exec(bContext *C, wmOperator *op) */ RNA_id_pointer_create(&arm->id, &ptr); - for (i = 0; i < maxLayers; i++) { + for (int i = 0; i < maxLayers; i++) { layers[i] = 1; } diff --git a/source/blender/editors/armature/pose_group.c b/source/blender/editors/armature/pose_group.c index cb7c68178d9..ffa28bf9e36 100644 --- a/source/blender/editors/armature/pose_group.c +++ b/source/blender/editors/armature/pose_group.c @@ -381,8 +381,6 @@ static int group_sort_exec(bContext *C, wmOperator *UNUSED(op)) bPoseChannel *pchan; tSortActionGroup *agrp_array; bActionGroup *agrp; - int agrp_count; - int i; if (ELEM(NULL, ob, pose)) { return OPERATOR_CANCELLED; @@ -392,8 +390,9 @@ static int group_sort_exec(bContext *C, wmOperator *UNUSED(op)) } /* create temporary array with bone groups and indices */ - agrp_count = BLI_listbase_count(&pose->agroups); + int agrp_count = BLI_listbase_count(&pose->agroups); agrp_array = MEM_mallocN(sizeof(tSortActionGroup) * agrp_count, "sort bone groups"); + int i; for (agrp = pose->agroups.first, i = 0; agrp; agrp = agrp->next, i++) { BLI_assert(i < agrp_count); agrp_array[i].agrp = agrp; diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index fb102574a85..e6815582a04 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -1144,7 +1144,7 @@ static int *init_index_map(Object *obedit, int *r_old_totvert) Nurb *nu; CVKeyIndex *keyIndex; int *old_to_new_map; - int old_totvert, i; + int old_totvert; int vertex_index; for (nu = curve->nurb.first, old_totvert = 0; nu != NULL; nu = nu->next) { @@ -1157,7 +1157,7 @@ static int *init_index_map(Object *obedit, int *r_old_totvert) } old_to_new_map = MEM_mallocN(old_totvert * sizeof(int), "curve old to new index map"); - for (i = 0; i < old_totvert; i++) { + for (int i = 0; i < old_totvert; i++) { old_to_new_map[i] = -1; } @@ -2804,19 +2804,15 @@ static void smooth_single_bezt(BezTriple *bezt, const BezTriple *bezt_orig_next, float factor) { - int i; - BLI_assert(IN_RANGE_INCL(factor, 0.0f, 1.0f)); - for (i = 0; i < 3; i++) { - float val_old, val_new, offset; - + for (int i = 0; i < 3; i++) { /* get single dimension pos of the mid handle */ - val_old = bezt->vec[1][i]; + float val_old = bezt->vec[1][i]; /* get the weights of the previous/next mid handles and calc offset */ - val_new = (bezt_orig_prev->vec[1][i] * 0.5f) + (bezt_orig_next->vec[1][i] * 0.5f); - offset = (val_old * (1.0f - factor)) + (val_new * factor) - val_old; + float val_new = (bezt_orig_prev->vec[1][i] * 0.5f) + (bezt_orig_next->vec[1][i] * 0.5f); + float offset = (val_old * (1.0f - factor)) + (val_new * factor) - val_old; /* offset midpoint and 2 handles */ bezt->vec[1][i] += offset; @@ -2833,11 +2829,9 @@ static void smooth_single_bp(BPoint *bp, const BPoint *bp_orig_next, float factor) { - int i; - BLI_assert(IN_RANGE_INCL(factor, 0.0f, 1.0f)); - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { float val_old, val_new, offset; val_old = bp->vec[i]; @@ -3472,7 +3466,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) BezTriple *bezt, *beztnew, *beztn; BPoint *bp, *prevbp, *bpnew, *bpn; float vec[15]; - int a, b, sel, amount, *usel, *vsel, i; + int a, b, sel, amount, *usel, *vsel; float factor; // printf("*** subdivideNurb: entering subdivide\n"); @@ -3525,7 +3519,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) memcpy(prevvec, bezt->vec, sizeof(float[9])); - for (i = 0; i < number_cuts; i++) { + for (int i = 0; i < number_cuts; i++) { factor = 1.0f / (number_cuts + 1 - i); memcpy(beztn, nextbezt, sizeof(BezTriple)); @@ -3615,7 +3609,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) if ((bp->f1 & SELECT) && (nextbp->f1 & SELECT)) { // printf("*** subdivideNurb: insert 'linear' point\n"); - for (i = 0; i < number_cuts; i++) { + for (int i = 0; i < number_cuts; i++) { factor = (float)(i + 1) / (number_cuts + 1); memcpy(bpn, nextbp, sizeof(BPoint)); @@ -3646,9 +3640,8 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) * degree of the functions used to build the NURB. The * expression * - * degree = #knots - #controlpoints + 1 (J Walter piece) - * degree = #knots - #controlpoints (Blender - * implementation) + * `degree = knots - controlpoints + 1` (J Walter piece) + * `degree = knots - controlpoints` (Blender implementation) * ( this is confusing.... what is true? Another concern * is that the JW piece allows the curve to become * explicitly 1st order derivative discontinuous, while @@ -3657,12 +3650,12 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) * is an invariant for a single NURB curve. Raising the degree * of the NURB is done elsewhere; the degree is assumed * constant during this operation. Degree is a property shared - * by all controlpoints in a curve (even though it is stored + * by all control-points in a curve (even though it is stored * per control point - this can be misleading). * Adding a knot is done by searching for the place in the * knot vector where a certain knot value must be inserted, or * by picking an appropriate knot value between two existing - * ones. The number of controlpoints that is influenced by the + * ones. The number of control-points that is influenced by the * insertion depends on the order of the curve. A certain * minimum number of knots is needed to form high-order * curves, as can be seen from the equation above. In Blender, @@ -3718,7 +3711,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) bp++; if (b < nu->pntsu - 1) { prevbp = bp - 1; - for (i = 0; i < number_cuts; i++) { + for (int i = 0; i < number_cuts; i++) { factor = (float)(i + 1) / (number_cuts + 1); *bpn = *bp; interp_v4_v4v4(bpn->vec, prevbp->vec, bp->vec, factor); @@ -3736,7 +3729,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) for (b = 0; b < (number_cuts + 1) * nu->pntsu - number_cuts; b++) { BPoint *tmp = bpn; - for (i = 0; i < number_cuts; i++) { + for (int i = 0; i < number_cuts; i++) { factor = (float)(i + 1) / (number_cuts + 1); *tmp = *bp; interp_v4_v4v4(tmp->vec, prevbp->vec, bp->vec, factor); @@ -3778,7 +3771,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) bp++; } if ((a < nu->pntsv - 1) && vsel[a] == nu->pntsu && vsel[a + 1] == nu->pntsu) { - for (i = 0; i < number_cuts; i++) { + for (int i = 0; i < number_cuts; i++) { factor = (float)(i + 1) / (number_cuts + 1); prevbp = bp - nu->pntsu; for (b = 0; b < nu->pntsu; b++) { @@ -3834,7 +3827,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) * handle at most 3rd order curves? I miss * some symmetry here... */ - for (i = 0; i < number_cuts; i++) { + for (int i = 0; i < number_cuts; i++) { factor = (float)(i + 1) / (number_cuts + 1); prevbp = bp - 1; *bpn = *prevbp; diff --git a/source/blender/editors/curve/editcurve_add.c b/source/blender/editors/curve/editcurve_add.c index 19b05f0af0c..4d72e90b89b 100644 --- a/source/blender/editors/curve/editcurve_add.c +++ b/source/blender/editors/curve/editcurve_add.c @@ -508,7 +508,10 @@ Nurb *ED_curve_add_nurbs_primitive( static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf) { - Object *obedit = CTX_data_edit_object(C); + struct Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); ListBase *editnurb; Nurb *nu; bool newob = false; @@ -565,7 +568,7 @@ static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf) /* userdef */ if (newob && !enter_editmode) { - ED_object_editmode_exit(C, EM_FREEDATA); + ED_object_editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA); } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); diff --git a/source/blender/editors/curve/editcurve_select.c b/source/blender/editors/curve/editcurve_select.c index b60eb258916..4b502e9e336 100644 --- a/source/blender/editors/curve/editcurve_select.c +++ b/source/blender/editors/curve/editcurve_select.c @@ -1874,10 +1874,6 @@ static void curve_select_shortest_path_curve(Nurb *nu, int vert_src, int vert_ds static void curve_select_shortest_path_surf(Nurb *nu, int vert_src, int vert_dst) { - HeapSimple *heap; - - int i, vert_curr; - int totu = nu->pntsu; int totv = nu->pntsv; int vert_num = totu * totv; @@ -1890,34 +1886,32 @@ static void curve_select_shortest_path_surf(Nurb *nu, int vert_src, int vert_dst /* init connectivity data */ data = MEM_mallocN(sizeof(*data) * vert_num, __func__); - for (i = 0; i < vert_num; i++) { + for (int i = 0; i < vert_num; i++) { data[i].vert = i; data[i].vert_prev = -1; data[i].cost = FLT_MAX; } /* init heap */ - heap = BLI_heapsimple_new(); + HeapSimple *heap = BLI_heapsimple_new(); - vert_curr = data[vert_src].vert; + int vert_curr = data[vert_src].vert; BLI_heapsimple_insert(heap, 0.0f, &data[vert_src].vert); data[vert_src].cost = 0.0f; data[vert_src].vert_prev = vert_src; /* nop */ while (!BLI_heapsimple_is_empty(heap)) { - int axis, sign; - int u, v; - vert_curr = *((int *)BLI_heapsimple_pop_min(heap)); if (vert_curr == vert_dst) { break; } + int u, v; BKE_nurb_index_to_uv(nu, vert_curr, &u, &v); /* loop over 4 adjacent verts */ - for (sign = -1; sign != 3; sign += 2) { - for (axis = 0; axis != 2; axis += 1) { + for (int sign = -1; sign != 3; sign += 2) { + for (int axis = 0; axis != 2; axis += 1) { int uv_other[2] = {u, v}; int vert_other; @@ -1943,7 +1937,7 @@ static void curve_select_shortest_path_surf(Nurb *nu, int vert_src, int vert_dst BLI_heapsimple_free(heap, NULL); if (vert_curr == vert_dst) { - i = 0; + int i = 0; while (vert_curr != vert_src && i++ < vert_num) { if (nu->type == CU_BEZIER) { select_beztriple(&nu->bezt[vert_curr], SELECT, SELECT, HIDDEN); diff --git a/source/blender/editors/geometry/CMakeLists.txt b/source/blender/editors/geometry/CMakeLists.txt new file mode 100644 index 00000000000..75b334b9ec6 --- /dev/null +++ b/source/blender/editors/geometry/CMakeLists.txt @@ -0,0 +1,45 @@ +# ***** BEGIN GPL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# ***** END GPL LICENSE BLOCK ***** + +set(INC + ../include + ../../blenkernel + ../../blenlib + ../../depsgraph + ../../makesdna + ../../makesrna + ../../windowmanager +) + +set(INC_SYS +) + +set(SRC + geometry_attributes.c + geometry_ops.c + + geometry_intern.h +) + +set(LIB + bf_blenkernel + bf_depsgraph + bf_editor_object + bf_windowmanager +) + +blender_add_lib(bf_editor_geometry "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/geometry/geometry_attributes.c b/source/blender/editors/geometry/geometry_attributes.c new file mode 100644 index 00000000000..4106c03f17d --- /dev/null +++ b/source/blender/editors/geometry/geometry_attributes.c @@ -0,0 +1,156 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup edgeometry + */ + +#include "BKE_attribute.h" +#include "BKE_context.h" +#include "BKE_report.h" + +#include "RNA_access.h" +#include "RNA_define.h" +#include "RNA_enum_types.h" + +#include "DEG_depsgraph.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_geometry.h" +#include "ED_object.h" + +#include "geometry_intern.h" + +/*********************** Attribute Operators ************************/ + +static bool geometry_attributes_poll(bContext *C) +{ + Object *ob = ED_object_context(C); + ID *data = (ob) ? ob->data : NULL; + return (ob && !ID_IS_LINKED(ob) && data && !ID_IS_LINKED(data)) && + BKE_id_attributes_supported(data); +} + +static const EnumPropertyItem *geometry_attribute_domain_itemf(bContext *C, + PointerRNA *UNUSED(ptr), + PropertyRNA *UNUSED(prop), + bool *r_free) +{ + Object *ob = ED_object_context(C); + return rna_enum_attribute_domain_itemf(ob->data, r_free); +} + +static int geometry_attribute_add_exec(bContext *C, wmOperator *op) +{ + Object *ob = ED_object_context(C); + ID *id = ob->data; + + char name[MAX_NAME]; + RNA_string_get(op->ptr, "name", name); + CustomDataType type = (CustomDataType)RNA_enum_get(op->ptr, "data_type"); + AttributeDomain domain = (AttributeDomain)RNA_enum_get(op->ptr, "domain"); + CustomDataLayer *layer = BKE_id_attribute_new(id, name, type, domain, op->reports); + + if (layer == NULL) { + return OPERATOR_CANCELLED; + } + + BKE_id_attributes_active_set(id, layer); + + DEG_id_tag_update(id, ID_RECALC_GEOMETRY); + WM_main_add_notifier(NC_GEOM | ND_DATA, id); + + return OPERATOR_FINISHED; +} + +void GEOMETRY_OT_attribute_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Add Geometry Attribute"; + ot->description = "Add attribute to geometry"; + ot->idname = "GEOMETRY_OT_attribute_add"; + + /* api callbacks */ + ot->poll = geometry_attributes_poll; + ot->exec = geometry_attribute_add_exec; + ot->invoke = WM_operator_props_popup_confirm; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + PropertyRNA *prop; + + prop = RNA_def_string(ot->srna, "name", "Attribute", MAX_NAME, "Name", "Name of new attribute"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_enum(ot->srna, + "data_type", + rna_enum_attribute_type_items, + CD_PROP_FLOAT, + "Data Type", + "Type of data stored in attribute"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_enum(ot->srna, + "domain", + rna_enum_attribute_domain_items, + ATTR_DOMAIN_POINT, + "Domain", + "Type of element that attribute is stored on"); + RNA_def_enum_funcs(prop, geometry_attribute_domain_itemf); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); +} + +static int geometry_attribute_remove_exec(bContext *C, wmOperator *op) +{ + Object *ob = ED_object_context(C); + ID *id = ob->data; + CustomDataLayer *layer = BKE_id_attributes_active_get(id); + + if (layer == NULL) { + return OPERATOR_CANCELLED; + } + + if (!BKE_id_attribute_remove(id, layer, op->reports)) { + return OPERATOR_CANCELLED; + } + + DEG_id_tag_update(id, ID_RECALC_GEOMETRY); + WM_main_add_notifier(NC_GEOM | ND_DATA, id); + + return OPERATOR_FINISHED; +} + +void GEOMETRY_OT_attribute_remove(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Remove Geometry Attribute"; + ot->description = "Remove attribute from geometry"; + ot->idname = "GEOMETRY_OT_attribute_remove"; + + /* api callbacks */ + ot->exec = geometry_attribute_remove_exec; + ot->poll = geometry_attributes_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} diff --git a/source/blender/editors/geometry/geometry_intern.h b/source/blender/editors/geometry/geometry_intern.h new file mode 100644 index 00000000000..7c037fea18a --- /dev/null +++ b/source/blender/editors/geometry/geometry_intern.h @@ -0,0 +1,33 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup edgeometry + */ + +#ifndef __GEOMETRY_INTERN_H__ +#define __GEOMETRY_INTERN_H__ + +struct wmOperatorType; + +/* *** geometry_attributes.c *** */ +void GEOMETRY_OT_attribute_add(struct wmOperatorType *ot); +void GEOMETRY_OT_attribute_remove(struct wmOperatorType *ot); + +#endif /* __GEOMETRY_INTERN_H__ */ diff --git a/source/blender/editors/geometry/geometry_ops.c b/source/blender/editors/geometry/geometry_ops.c new file mode 100644 index 00000000000..ed0aeda731b --- /dev/null +++ b/source/blender/editors/geometry/geometry_ops.c @@ -0,0 +1,36 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup edgeometry + */ + +#include "WM_api.h" + +#include "ED_geometry.h" + +#include "geometry_intern.h" + +/**************************** registration **********************************/ + +void ED_operatortypes_geometry(void) +{ + WM_operatortype_append(GEOMETRY_OT_attribute_add); + WM_operatortype_append(GEOMETRY_OT_attribute_remove); +} diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c index c29244c37f7..481a038fde1 100644 --- a/source/blender/editors/gpencil/annotate_paint.c +++ b/source/blender/editors/gpencil/annotate_paint.c @@ -1119,7 +1119,6 @@ static void annotation_stroke_eraser_dostroke(tGPsdata *p, bGPDspoint *pt1, *pt2; int pc1[2] = {0}; int pc2[2] = {0}; - int i; int mval_i[2]; round_v2i_v2fl(mval_i, mval); @@ -1152,7 +1151,7 @@ static void annotation_stroke_eraser_dostroke(tGPsdata *p, * we don't miss anything, though things will be * slightly slower as a result */ - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { bGPDspoint *pt = &gps->points[i]; pt->flag &= ~GP_SPOINT_TAG; } @@ -1161,7 +1160,7 @@ static void annotation_stroke_eraser_dostroke(tGPsdata *p, * 1) Thin out parts of the stroke under the brush * 2) Tag "too thin" parts for removal (in second pass) */ - for (i = 0; (i + 1) < gps->totpoints; i++) { + for (int i = 0; (i + 1) < gps->totpoints; i++) { /* get points to work with */ pt1 = gps->points + i; pt2 = gps->points + i + 1; diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c index 05c37567c55..b9234ac3ae7 100644 --- a/source/blender/editors/gpencil/gpencil_convert.c +++ b/source/blender/editors/gpencil/gpencil_convert.c @@ -371,10 +371,9 @@ static void gpencil_stroke_path_animation_preprocess_gaps(tGpTimingData *gtd, int *nbr_gaps, float *tot_gaps_time) { - int i; float delta_time = 0.0f; - for (i = 0; i < gtd->num_points; i++) { + for (int i = 0; i < gtd->num_points; i++) { if (gtd->times[i] < 0 && i) { (*nbr_gaps)++; gtd->times[i] = -gtd->times[i] - delta_time; @@ -420,14 +419,11 @@ static void gpencil_stroke_path_animation_add_keyframes(ReportList *reports, float delta_time = 0.0f, next_delta_time = 0.0f; int nbr_done_gaps = 0; - int i; - float cfra; - /* This is a bit tricky, as: * - We can't add arbitrarily close points on FCurve (in time). * - We *must* have all "caps" points of all strokes in FCurve, as much as possible! */ - for (i = 0; i < gtd->num_points; i++) { + for (int i = 0; i < gtd->num_points; i++) { /* If new stroke... */ if (i > end_stroke_idx) { start_stroke_idx = i; @@ -442,7 +438,7 @@ static void gpencil_stroke_path_animation_add_keyframes(ReportList *reports, /* Simple proportional stuff... */ cu->ctime = gtd->dists[i] / gtd->tot_dist * cu->pathlen; - cfra = time_start + ((gtd->times[i] + delta_time) / gtd->tot_time * time_range); + float cfra = time_start + ((gtd->times[i] + delta_time) / gtd->tot_time * time_range); /* And now, the checks about timing... */ if (i == start_stroke_idx) { @@ -527,7 +523,7 @@ static void gpencil_stroke_path_animation(bContext *C, FCurve *fcu; PointerRNA ptr; PropertyRNA *prop = NULL; - int nbr_gaps = 0, i; + int nbr_gaps = 0; if (gtd->mode == GP_STROKECONVERT_TIMING_NONE) { return; @@ -551,7 +547,7 @@ static void gpencil_stroke_path_animation(bContext *C, if (G.debug & G_DEBUG) { printf("%s: tot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time); - for (i = 0; i < gtd->num_points; i++) { + for (int i = 0; i < gtd->num_points; i++) { printf("\tpoint %d:\t\tlen: %f\t\ttime: %f\n", i, gtd->dists[i], gtd->times[i]); } } @@ -628,7 +624,7 @@ static void gpencil_stroke_path_animation(bContext *C, if (G.debug & G_DEBUG) { printf("%s: \ntot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time); - for (i = 0; i < gtd->num_points; i++) { + for (int i = 0; i < gtd->num_points; i++) { printf("\tpoint %d:\t\tlen: %f\t\ttime: %f\n", i, gtd->dists[i], gtd->times[i]); } printf("\n\n"); @@ -1251,12 +1247,10 @@ static void gpencil_stroke_finalize_curve_endpoints(Curve *cu) static void gpencil_stroke_norm_curve_weights(Curve *cu, const float minmax_weights[2]) { - Nurb *nu; const float delta = minmax_weights[0]; - float fac; - int i; /* when delta == minmax_weights[0] == minmax_weights[1], we get div by zero [#35686] */ + float fac; if (IS_EQF(delta, minmax_weights[1])) { fac = 1.0f; } @@ -1264,16 +1258,16 @@ static void gpencil_stroke_norm_curve_weights(Curve *cu, const float minmax_weig fac = 1.0f / (minmax_weights[1] - delta); } - for (nu = cu->nurb.first; nu; nu = nu->next) { + LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { if (nu->bezt) { BezTriple *bezt = nu->bezt; - for (i = 0; i < nu->pntsu; i++, bezt++) { + for (int i = 0; i < nu->pntsu; i++, bezt++) { bezt->weight = (bezt->weight - delta) * fac; } } else if (nu->bp) { BPoint *bp = nu->bp; - for (i = 0; i < nu->pntsu; i++, bp++) { + for (int i = 0; i < nu->pntsu; i++, bp++) { bp->weight = (bp->weight - delta) * fac; } } diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 1994792e61a..9f0271c2aa4 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -5510,7 +5510,6 @@ static int gpencil_cutter_lasso_select(bContext *C, const float scale = ts->gp_sculpt.isect_threshold; bGPDspoint *pt; - int i; GP_SpaceConversion gsc = {NULL}; bool changed = false; @@ -5526,6 +5525,7 @@ static int gpencil_cutter_lasso_select(bContext *C, /* deselect all strokes first */ CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { + int i; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { pt->flag &= ~GP_SPOINT_SELECT; } @@ -5538,7 +5538,7 @@ static int gpencil_cutter_lasso_select(bContext *C, GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) { int tot_inside = 0; const int oldtot = gps->totpoints; - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { pt = &gps->points[i]; if ((pt->flag & GP_SPOINT_SELECT) || (pt->flag & GP_SPOINT_TAG)) { continue; @@ -5562,7 +5562,7 @@ static int gpencil_cutter_lasso_select(bContext *C, } /* if mark all points inside lasso set to remove all stroke */ if ((tot_inside == oldtot) || ((tot_inside == 1) && (oldtot == 2))) { - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { pt = &gps->points[i]; pt->flag |= GP_SPOINT_SELECT; } diff --git a/source/blender/editors/gpencil/gpencil_merge.c b/source/blender/editors/gpencil/gpencil_merge.c index 2713e6b0f54..70478d9b7d0 100644 --- a/source/blender/editors/gpencil/gpencil_merge.c +++ b/source/blender/editors/gpencil/gpencil_merge.c @@ -203,7 +203,6 @@ static void gpencil_calc_points_factor(bContext *C, tGPencilPointCache *src_array) { bGPDspoint *pt; - int i; int idx = 0; /* create selected point array an fill it */ @@ -217,6 +216,7 @@ static void gpencil_calc_points_factor(bContext *C, } LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { if (gps->flag & GP_STROKE_SELECT) { + int i; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { if (clear_stroke) { pt->flag |= GP_SPOINT_TAG; @@ -255,7 +255,7 @@ static void gpencil_calc_points_factor(bContext *C, /* calc center */ float center[2] = {0.0f, 0.0f}; - for (i = 0; i < totpoints; i++) { + for (int i = 0; i < totpoints; i++) { center[0] += points2d[i][0]; center[1] += points2d[i][1]; } @@ -264,7 +264,7 @@ static void gpencil_calc_points_factor(bContext *C, /* calc angle and distance to center for each point */ const float axis[2] = {1.0f, 0.0f}; float v1[3]; - for (i = 0; i < totpoints; i++) { + for (int i = 0; i < totpoints; i++) { float ln = len_v2v2(center, points2d[i]); sub_v2_v2v2(v1, points2d[i], center); float angle = angle_signed_v2v2(axis, v1); @@ -340,10 +340,9 @@ static void gpencil_get_extremes( tGPencilPointCache *src_array, int totpoints, bGPDstroke *gps_filter, float *start, float *end) { tGPencilPointCache *array_pt = NULL; - int i; /* find first point */ - for (i = 0; i < totpoints; i++) { + for (int i = 0; i < totpoints; i++) { array_pt = &src_array[i]; if (gps_filter == array_pt->gps) { copy_v3_v3(start, &array_pt->x); @@ -351,7 +350,7 @@ static void gpencil_get_extremes( } } /* find last point */ - for (i = totpoints - 1; i >= 0; i--) { + for (int i = totpoints - 1; i >= 0; i--) { array_pt = &src_array[i]; if (gps_filter == array_pt->gps) { copy_v3_v3(end, &array_pt->x); diff --git a/source/blender/editors/gpencil/gpencil_mesh.c b/source/blender/editors/gpencil/gpencil_mesh.c index f4e40c2670f..e4862617d12 100644 --- a/source/blender/editors/gpencil/gpencil_mesh.c +++ b/source/blender/editors/gpencil/gpencil_mesh.c @@ -162,7 +162,7 @@ static int gpencil_bake_mesh_animation_exec(bContext *C, wmOperator *op) Object *ob_gpencil = NULL; ListBase list = {NULL, NULL}; - const bool simple_material = gpencil_bake_ob_list(C, depsgraph, scene, &list); + gpencil_bake_ob_list(C, depsgraph, scene, &list); /* Cannot check this in poll because the active object changes. */ if (list.first == NULL) { @@ -264,8 +264,7 @@ static int gpencil_bake_mesh_animation_exec(bContext *C, wmOperator *op) ob_eval->obmat, frame_offset, use_seams, - use_faces, - simple_material); + use_faces); /* Reproject all untaged created strokes. */ if (project_type != GP_REPROJECT_KEEP) { diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 1036f86fa2b..3cdb7682af2 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -941,7 +941,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) const bool is_depth = (bool)(*align_flag & (GP_PROJECT_DEPTH_VIEW | GP_PROJECT_DEPTH_STROKE)); const bool is_camera = (bool)(ts->gp_sculpt.lock_axis == 0) && (rv3d->persp == RV3D_CAMOB) && (!is_depth); - int i, totelem; + int totelem; /* For very low pressure at the end, truncate stroke. */ if (p->paintmode == GP_PAINTMODE_DRAW) { @@ -1079,7 +1079,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* reproject to plane (only in 3d space) */ gpencil_reproject_toplane(p, gps); pt = gps->points; - for (i = 0; i < gps->totpoints; i++, pt++) { + for (int i = 0; i < gps->totpoints; i++, pt++) { /* if parented change position relative to parent object */ gpencil_apply_parent_point(depsgraph, obact, gpl, pt); } @@ -1099,7 +1099,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) int found_depth = 0; depth_arr = MEM_mallocN(sizeof(float) * gpd->runtime.sbuffer_used, "depth_points"); - + int i; for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used; i++, ptc++, pt++) { round_v2i_v2fl(mval_i, &ptc->x); @@ -1169,6 +1169,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) dvert = gps->dvert; /* convert all points (normal behavior) */ + int i; for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used && ptc; i++, ptc++, pt++) { /* convert screen-coordinates to appropriate coordinates (and store them) */ @@ -1266,7 +1267,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p) /* add weights */ if ((ts->gpencil_flags & GP_TOOL_FLAG_CREATE_WEIGHTS) && (have_weight)) { BKE_gpencil_dvert_ensure(gps); - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { MDeformVert *ve = &gps->dvert[i]; MDeformWeight *dw = BKE_defvert_ensure_index(ve, def_nr); if (dw) { @@ -1524,6 +1525,9 @@ static void gpencil_stroke_eraser_dostroke(tGPsdata *p, pt1 = gps->points + i; pt2 = gps->points + i + 1; + float inf1 = 0.0f; + float inf2 = 0.0f; + /* only process if it hasn't been masked out... */ if ((p->flags & GP_PAINTFLAG_SELECTMASK) && !(gps->points->flag & GP_SPOINT_SELECT)) { continue; @@ -1602,22 +1606,36 @@ static void gpencil_stroke_eraser_dostroke(tGPsdata *p, pt2->flag |= GP_SPOINT_TAG; do_cull = true; } + + inf1 = 1.0f; + inf2 = 1.0f; } else { - pt1->pressure -= gpencil_stroke_eraser_calc_influence(p, mval, radius, pc1) * - strength; - pt2->pressure -= gpencil_stroke_eraser_calc_influence(p, mval, radius, pc2) * - strength * 0.5f; + /* Erase point. Only erase if the eraser is on top of the point. */ + inf1 = gpencil_stroke_eraser_calc_influence(p, mval, radius, pc1); + if (inf1 > 0.0f) { + pt1->pressure = 0.0f; + pt1->flag |= GP_SPOINT_TAG; + do_cull = true; + } + inf2 = gpencil_stroke_eraser_calc_influence(p, mval, radius, pc2); + if (inf2 > 0.0f) { + pt2->pressure = 0.0f; + pt2->flag |= GP_SPOINT_TAG; + do_cull = true; + } } /* 2) Tag any point with overly low influence for removal in the next pass */ - if ((pt1->pressure < cull_thresh) || (p->flags & GP_PAINTFLAG_HARD_ERASER) || - (eraser->gpencil_settings->eraser_mode == GP_BRUSH_ERASER_HARD)) { + if ((inf1 > 0.0f) && + (((pt1->pressure < cull_thresh) || (p->flags & GP_PAINTFLAG_HARD_ERASER) || + (eraser->gpencil_settings->eraser_mode == GP_BRUSH_ERASER_HARD)))) { pt1->flag |= GP_SPOINT_TAG; do_cull = true; } - if ((pt2->pressure < cull_thresh) || (p->flags & GP_PAINTFLAG_HARD_ERASER) || - (eraser->gpencil_settings->eraser_mode == GP_BRUSH_ERASER_HARD)) { + if ((inf1 > 2.0f) && + (((pt2->pressure < cull_thresh) || (p->flags & GP_PAINTFLAG_HARD_ERASER) || + (eraser->gpencil_settings->eraser_mode == GP_BRUSH_ERASER_HARD)))) { pt2->flag |= GP_SPOINT_TAG; do_cull = true; } diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index 5084f5090a1..b48fc1cb975 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -773,7 +773,6 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) /* get an array of depths, far depths are blended */ float *depth_arr = NULL; if (is_depth) { - int i; int mval_i[2], mval_prev[2] = {0}; bool interp_depth = false; bool found_depth = false; @@ -787,7 +786,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) depth_arr = MEM_mallocN(sizeof(float) * gps->totpoints, "depth_points"); tGPspoint *ptc = &points2D[0]; - for (i = 0; i < gps->totpoints; i++, ptc++) { + for (int i = 0; i < gps->totpoints; i++, ptc++) { round_v2i_v2fl(mval_i, &ptc->x); if ((ED_view3d_autodist_depth(tgpi->region, mval_i, depth_margin, depth_arr + i) == 0) && (i && (ED_view3d_autodist_depth_seg( @@ -801,14 +800,14 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) } if (!found_depth) { - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { depth_arr[i] = 0.9999f; } } else { /* if all depth are too high disable */ bool valid_depth = false; - for (i = 0; i < gps->totpoints; i++) { + for (int i = 0; i < gps->totpoints; i++) { if (depth_arr[i] < 0.9999f) { valid_depth = true; break; @@ -826,6 +825,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) int last_valid = 0; /* find first valid contact point */ + int i; for (i = 0; i < gps->totpoints; i++) { if (depth_arr[i] != FLT_MAX) { break; diff --git a/source/blender/editors/gpencil/gpencil_sculpt_paint.c b/source/blender/editors/gpencil/gpencil_sculpt_paint.c index 6e16aee2573..fd150f1e20f 100644 --- a/source/blender/editors/gpencil/gpencil_sculpt_paint.c +++ b/source/blender/editors/gpencil/gpencil_sculpt_paint.c @@ -546,12 +546,11 @@ static void gpencil_brush_grab_apply_cached(tGP_BrushEditData *gso, return; } - int i; float inverse_diff_mat[4][4]; invert_m4_m4(inverse_diff_mat, diff_mat); /* Apply dvec to all of the stored points */ - for (i = 0; i < data->size; i++) { + for (int i = 0; i < data->size; i++) { bGPDspoint *pt = &gps->points[data->points[i]]; float delta[3] = {0.0f}; @@ -1106,7 +1105,7 @@ static bool gpencil_sculpt_brush_apply_clone(bContext *C, tGP_BrushEditData *gso gpencil_brush_clone_adjust(gso); } else { - /* Continuous - Just keep pasting everytime we move */ + /* Continuous - Just keep pasting every time we move. */ /* TODO: The spacing of repeat should be controlled using a * "stepsize" or similar property? */ gpencil_brush_clone_add(C, gso); diff --git a/source/blender/editors/gpencil/gpencil_vertex_ops.c b/source/blender/editors/gpencil/gpencil_vertex_ops.c index 36ce7d3dc47..69e50beb66e 100644 --- a/source/blender/editors/gpencil/gpencil_vertex_ops.c +++ b/source/blender/editors/gpencil/gpencil_vertex_ops.c @@ -682,7 +682,6 @@ static int gpencil_material_to_vertex_exec(bContext *C, wmOperator *op) char name[32] = ""; Material *ma = NULL; GPMatArray *mat_elm = NULL; - int i; bool changed = false; @@ -744,6 +743,7 @@ static int gpencil_material_to_vertex_exec(bContext *C, wmOperator *op) /* Check if material exist. */ bool found = false; + int i; for (i = 0; i < totmat; i++) { mat_elm = &mat_table[i]; if (mat_elm->ma == NULL) { @@ -796,6 +796,7 @@ static int gpencil_material_to_vertex_exec(bContext *C, wmOperator *op) /* Update all points. */ bGPDspoint *pt; + int i; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { copy_v3_v3(pt->vert_color, gp_style->stroke_rgba); pt->vert_color[3] = 1.0f; diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h index 47b8eb543f4..341f97943a5 100644 --- a/source/blender/editors/include/ED_fileselect.h +++ b/source/blender/editors/include/ED_fileselect.h @@ -150,6 +150,7 @@ int ED_file_extension_icon(const char *path); void ED_file_read_bookmarks(void); +void ED_file_change_dir_ex(struct bContext *C, struct bScreen *screen, struct ScrArea *area); void ED_file_change_dir(struct bContext *C); void ED_file_path_button(struct bScreen *screen, diff --git a/source/blender/editors/include/ED_geometry.h b/source/blender/editors/include/ED_geometry.h new file mode 100644 index 00000000000..53eeba39088 --- /dev/null +++ b/source/blender/editors/include/ED_geometry.h @@ -0,0 +1,37 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup editors + */ + +#ifndef __ED_GEOMETRY_H__ +#define __ED_GEOMETRY_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void ED_operatortypes_geometry(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __ED_GEOMETRY_H__ */ diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h index 7b59d45b203..bbe66f7fd73 100644 --- a/source/blender/editors/include/UI_interface_icons.h +++ b/source/blender/editors/include/UI_interface_icons.h @@ -106,6 +106,7 @@ struct PreviewImage *UI_icon_to_preview(int icon_id); int UI_rnaptr_icon_get(struct bContext *C, struct PointerRNA *ptr, int rnaicon, const bool big); int UI_idcode_icon_get(const int idcode); int UI_library_icon_get(const struct ID *id); +int UI_mode_icon_get(const int mode); #ifdef __cplusplus } diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 0bd4934dd0f..10650da4b0e 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -6676,7 +6676,7 @@ static void operator_enum_search_update_fn(const struct bContext *C, } } - MEM_freeN(filtered_items); + MEM_freeN((void *)filtered_items); BLI_string_search_free(search); if (do_free) { diff --git a/source/blender/editors/interface/interface_align.c b/source/blender/editors/interface/interface_align.c index e92adc8a2ec..d626c57b121 100644 --- a/source/blender/editors/interface/interface_align.c +++ b/source/blender/editors/interface/interface_align.c @@ -393,7 +393,6 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region) ButAlign *butal_array; ButAlign *butal, *butal_other; int side; - int i, j; /* First loop: we count number of buttons belonging to an align group, * and clear their align flag. @@ -452,9 +451,11 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region) /* Third loop: for each pair of buttons in the same align group, * we compute their potential proximity. Note that each pair is checked only once, and that we * break early in case we know all remaining pairs will always be too far away. */ + int i; for (i = 0, butal = butal_array; i < num_buttons; i++, butal++) { const short alignnr = butal->but->alignnr; + int j; for (j = i + 1, butal_other = &butal_array[i + 1]; j < num_buttons; j++, butal_other++) { const float max_delta = MAX_DELTA; diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 4d53018cd32..bcb8a10be02 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -2162,7 +2162,6 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, const uiWidgetColors *wcol, const rcti *rect) { - uint i; float fx, fy; uiButCurveProfile *but_profile = (uiButCurveProfile *)but; @@ -2241,7 +2240,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, /* Create array of the positions of the table's points. */ float(*table_coords)[2] = MEM_mallocN(sizeof(*table_coords) * tot_points, "table x coords"); - for (i = 0; i < (uint)PROF_TABLE_LEN(profile->path_len); + for (uint i = 0; i < (uint)PROF_TABLE_LEN(profile->path_len); i++) { /* Only add the points from the table here. */ table_coords[i][0] = pts[i].x; table_coords[i][1] = pts[i].y; @@ -2284,7 +2283,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, GPU_blend(GPU_BLEND_ALPHA); GPU_polygon_smooth(false); immBegin(GPU_PRIM_TRIS, 3 * tot_triangles); - for (i = 0; i < tot_triangles; i++) { + for (uint i = 0; i < tot_triangles; i++) { for (uint j = 0; j < 3; j++) { uint *tri = tri_indices[i]; fx = rect->xmin + zoomx * (table_coords[tri[j]][0] - offsx); @@ -2301,7 +2300,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, immUniformColor3ubvAlpha((const uchar *)wcol->item, 255); GPU_line_smooth(true); immBegin(GPU_PRIM_LINE_STRIP, tot_points - 1); - for (i = 0; i < tot_points - 1; i++) { + for (uint i = 0; i < tot_points - 1; i++) { fx = rect->xmin + zoomx * (table_coords[i][0] - offsx); fy = rect->ymin + zoomy * (table_coords[i][1] - offsy); immVertex2f(pos, fx, fy); @@ -2313,7 +2312,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, pts = profile->path; tot_points = (uint)profile->path_len; int selected_free_points = 0; - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { if (point_draw_handles(&pts[i])) { selected_free_points++; } @@ -2325,7 +2324,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, GPU_line_smooth(true); immBegin(GPU_PRIM_LINES, selected_free_points * 4); float ptx, pty; - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { if (point_draw_handles(&pts[i])) { ptx = rect->xmin + zoomx * (pts[i].x - offsx); pty = rect->ymin + zoomy * (pts[i].y - offsy); @@ -2372,7 +2371,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, GPU_blend(GPU_BLEND_NONE); GPU_point_size(max_ff(3.0f, min_ff(UI_DPI_FAC / but->block->aspect * 5.0f, 5.0f))); immBegin(GPU_PRIM_POINTS, tot_points); - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { fx = rect->xmin + zoomx * (pts[i].x - offsx); fy = rect->ymin + zoomy * (pts[i].y - offsy); immAttr4fv(col, (pts[i].flag & PROF_SELECT) ? color_vert_select : color_vert); @@ -2386,7 +2385,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, GPU_blend(GPU_BLEND_NONE); GPU_point_size(max_ff(2.0f, min_ff(UI_DPI_FAC / but->block->aspect * 4.0f, 4.0f))); immBegin(GPU_PRIM_POINTS, selected_free_points * 2); - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { if (point_draw_handles(&pts[i])) { fx = rect->xmin + zoomx * (pts[i].h1_loc[0] - offsx); fy = rect->ymin + zoomy * (pts[i].h1_loc[1] - offsy); @@ -2408,7 +2407,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, if (tot_points > 0 && pts) { GPU_point_size(max_ff(2.0f, min_ff(UI_DPI_FAC / but->block->aspect * 3.0f, 3.0f))); immBegin(GPU_PRIM_POINTS, tot_points); - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { fx = rect->xmin + zoomx * (pts[i].x - offsx); fy = rect->ymin + zoomy * (pts[i].y - offsy); immAttr4fv(col, color_sample); diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index cadc2264bf4..c91b4d826a7 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -975,7 +975,7 @@ static void init_iconfile_list(struct ListBase *list) { IconFile *ifile; struct direntry *dir; - int totfile, i, index = 1; + int index = 1; const char *icondir; BLI_listbase_clear(list); @@ -985,9 +985,9 @@ static void init_iconfile_list(struct ListBase *list) return; } - totfile = BLI_filelist_dir_contents(icondir, &dir); + int totfile = BLI_filelist_dir_contents(icondir, &dir); - for (i = 0; i < totfile; i++) { + for (int i = 0; i < totfile; i++) { if ((dir[i].type & S_IFREG)) { const char *filename = dir[i].relname; @@ -2294,6 +2294,36 @@ int UI_idcode_icon_get(const int idcode) } } +int UI_mode_icon_get(const int mode) +{ + switch (mode) { + case OB_MODE_OBJECT: + return ICON_OBJECT_DATAMODE; + case OB_MODE_EDIT: + case OB_MODE_EDIT_GPENCIL: + return ICON_EDITMODE_HLT; + case OB_MODE_SCULPT: + case OB_MODE_SCULPT_GPENCIL: + return ICON_SCULPTMODE_HLT; + case OB_MODE_VERTEX_PAINT: + case OB_MODE_VERTEX_GPENCIL: + return ICON_VPAINT_HLT; + case OB_MODE_WEIGHT_PAINT: + case OB_MODE_WEIGHT_GPENCIL: + return ICON_WPAINT_HLT; + case OB_MODE_TEXTURE_PAINT: + return ICON_TPAINT_HLT; + case OB_MODE_PARTICLE_EDIT: + return ICON_PARTICLEMODE; + case OB_MODE_POSE: + return ICON_POSE_HLT; + case OB_MODE_PAINT_GPENCIL: + return ICON_GREASEPENCIL; + default: + return ICON_NONE; + } +} + /* draws icon with dpi scale factor */ void UI_icon_draw(float x, float y, int icon_id) { diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index da3ab7556ed..a37f87e593b 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -457,14 +457,14 @@ static void ui_layer_but_cb(bContext *C, void *arg_but, void *arg_index) uiBut *but = arg_but; PointerRNA *ptr = &but->rnapoin; PropertyRNA *prop = but->rnaprop; - int i, index = POINTER_AS_INT(arg_index); + int index = POINTER_AS_INT(arg_index); const int shift = win->eventstate->shift; const int len = RNA_property_array_length(ptr, prop); if (!shift) { RNA_property_boolean_set_index(ptr, prop, index, true); - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { if (i != index) { RNA_property_boolean_set_index(ptr, prop, i, 0); } @@ -632,7 +632,7 @@ static void ui_item_array(uiLayout *layout, uiButNumber *number_but = (uiButNumber *)but; but->a1 = number_but->step_size; - ui_but_change_type(but, UI_BTYPE_NUM_SLIDER); + but = ui_but_change_type(but, UI_BTYPE_NUM_SLIDER); } } } @@ -703,7 +703,7 @@ static void ui_item_array(uiLayout *layout, uiButNumber *number_but = (uiButNumber *)but; but->a1 = number_but->step_size; - ui_but_change_type(but, UI_BTYPE_NUM_SLIDER); + but = ui_but_change_type(but, UI_BTYPE_NUM_SLIDER); } if ((toggle == 1) && but->type == UI_BTYPE_CHECKBOX) { but->type = UI_BTYPE_TOGGLE; @@ -2299,7 +2299,7 @@ void uiItemFullR(uiLayout *layout, uiButNumber *num_but = (uiButNumber *)but; but->a1 = num_but->step_size; - ui_but_change_type(but, UI_BTYPE_NUM_SLIDER); + but = ui_but_change_type(but, UI_BTYPE_NUM_SLIDER); } if (flag & UI_ITEM_R_CHECKBOX_INVERT) { @@ -2584,14 +2584,14 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname } const EnumPropertyItem *item; - int totitem, i; + int totitem; bool free; uiLayout *split = uiLayoutSplit(layout, 0.0f, false); uiLayout *column = uiLayoutColumn(split, false); RNA_property_enum_items_gettexted(block->evil_C, ptr, prop, &item, &totitem, &free); - for (i = 0; i < totitem; i++) { + for (int i = 0; i < totitem; i++) { if (item[i].identifier[0]) { uiItemEnumR_prop(column, item[i].name, item[i].icon, ptr, prop, item[i].value); ui_but_tip_from_enum_item(block->buttons.last, &item[i]); diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 5c4877534f6..6e2229ce3e3 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -1636,8 +1636,6 @@ static void align_sub_panels(Panel *panel) /* returns 1 when it did something */ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) { - int i; - /* count active, not tabbed panels */ int tot = 0; LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { @@ -1666,6 +1664,7 @@ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) /* While we are dragging, we sort on location and update #Panel.sortorder. */ qsort(panelsort, tot, sizeof(PanelSort), find_highest_panel); + int i; for (ps = panelsort, i = 0; i < tot; i++, ps++) { ps->orig->sortorder = i; } @@ -1682,7 +1681,7 @@ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) ps->panel->ofsy = -get_panel_size_y(ps->panel); ps->panel->ofsx += ps->panel->runtime.region_ofsx; - for (i = 0; i < tot - 1; i++, ps++) { + for (int i = 0; i < tot - 1; i++, ps++) { PanelSort *psnext = ps + 1; const bool use_box = ps->panel->type && ps->panel->type->flag & PNL_DRAW_BOX; @@ -1704,7 +1703,7 @@ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) /* we interpolate */ bool changed = false; ps = panelsort; - for (i = 0; i < tot; i++, ps++) { + for (int i = 0; i < tot; i++, ps++) { if ((ps->panel->flag & PNL_SELECT) == 0) { if ((ps->orig->ofsx != ps->panel->ofsx) || (ps->orig->ofsy != ps->panel->ofsy)) { ps->orig->ofsx = round_fl_to_int(fac * (float)ps->panel->ofsx + @@ -1726,6 +1725,7 @@ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) } /* Free `panelsort` array. */ + int i; for (ps = panelsort, i = 0; i < tot; i++, ps++) { MEM_freeN(ps->panel); } diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index f472c56e280..0edc755902a 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -167,7 +167,6 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region float background_color[3]; float tone_bg; - int i; wmOrtho2_region_pixelspace(region); @@ -204,7 +203,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region bbox.xmin += 0.5f * pad_px; /* add padding to the text */ bbox.ymax -= 0.25f * pad_px; - for (i = 0; i < data->fields_len; i++) { + for (int i = 0; i < data->fields_len; i++) { const uiTooltipField *field = &data->fields[i]; const uiTooltipField *field_next = (i + 1) != data->fields_len ? &data->fields[i + 1] : NULL; diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 08d3ad0f23c..77a9d9f549a 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -4255,7 +4255,7 @@ static void curvemap_buttons_layout(uiLayout *layout, uiBut *bt; const float dx = UI_UNIT_X; int icon, size; - int bg = -1, i; + int bg = -1; block = uiLayoutGetBlock(layout); @@ -4464,7 +4464,7 @@ static void curvemap_buttons_layout(uiLayout *layout, curve_but->gradient_type = bg; /* sliders for selected point */ - for (i = 0; i < cm->totpoint; i++) { + for (int i = 0; i < cm->totpoint; i++) { if (cm->curve[i].flag & CUMA_SELECT) { cmp = &cm->curve[i]; break; diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ab0f6d90caa..0cbb8f268a2 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -5002,12 +5002,7 @@ static void draw_disk_shaded(float start, bool shaded) { const float radius_ext_scale = (0.5f / radius_ext); /* 1 / (2 * radius_ext) */ - int i; - float s, c; - float y1, y2; - float fac; - uchar r_col[4]; uint pos, col; GPUVertFormat *format = immVertexFormat(); @@ -5022,24 +5017,24 @@ static void draw_disk_shaded(float start, } immBegin(GPU_PRIM_TRI_STRIP, subd * 2); - for (i = 0; i < subd; i++) { - float a; - - a = start + ((i) / (float)(subd - 1)) * angle; - s = sinf(a); - c = cosf(a); - y1 = s * radius_int; - y2 = s * radius_ext; + for (int i = 0; i < subd; i++) { + float a = start + ((i) / (float)(subd - 1)) * angle; + float s = sinf(a); + float c = cosf(a); + float y1 = s * radius_int; + float y2 = s * radius_ext; if (shaded) { - fac = (y1 + radius_ext) * radius_ext_scale; + uchar r_col[4]; + float fac = (y1 + radius_ext) * radius_ext_scale; color_blend_v4_v4v4(r_col, col1, col2, fac); immAttr4ubv(col, r_col); } immVertex2f(pos, c * radius_int, s * radius_int); if (shaded) { - fac = (y2 + radius_ext) * radius_ext_scale; + uchar r_col[4]; + float fac = (y2 + radius_ext) * radius_ext_scale; color_blend_v4_v4v4(r_col, col1, col2, fac); immAttr4ubv(col, r_col); } diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index c6b29f79137..32caf043119 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -1723,13 +1723,10 @@ static float smooth_view_rect_to_fac(const rctf *rect_a, const rctf *rect_b) const float cent_b[2] = {BLI_rctf_cent_x(rect_b), BLI_rctf_cent_y(rect_b)}; float fac_max = 0.0f; - float tfac; - int i; - - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { /* axis translation normalized to scale */ - tfac = fabsf(cent_a[i] - cent_b[i]) / min_ff(size_a[i], size_b[i]); + float tfac = fabsf(cent_a[i] - cent_b[i]) / min_ff(size_a[i], size_b[i]); fac_max = max_ff(fac_max, tfac); if (fac_max >= 1.0f) { break; diff --git a/source/blender/editors/lattice/editlattice_select.c b/source/blender/editors/lattice/editlattice_select.c index 49cf4779496..4497ca1a379 100644 --- a/source/blender/editors/lattice/editlattice_select.c +++ b/source/blender/editors/lattice/editlattice_select.c @@ -177,9 +177,6 @@ void LATTICE_OT_select_random(wmOperatorType *ot) static void ed_lattice_select_mirrored(Lattice *lt, const int axis, const bool extend) { const int tot = lt->pntsu * lt->pntsv * lt->pntsw; - int i; - BPoint *bp; - BLI_bitmap *selpoints; bool flip_uvw[3] = {false}; flip_uvw[axis] = true; @@ -190,13 +187,13 @@ static void ed_lattice_select_mirrored(Lattice *lt, const int axis, const bool e } /* store "original" selection */ - selpoints = BLI_BITMAP_NEW(tot, __func__); + BLI_bitmap *selpoints = BLI_BITMAP_NEW(tot, __func__); BKE_lattice_bitmap_from_flag(lt, selpoints, SELECT, false, false); /* actual (de)selection */ - for (i = 0; i < tot; i++) { + for (int i = 0; i < tot; i++) { const int i_flip = BKE_lattice_index_flip(lt, i, flip_uvw[0], flip_uvw[1], flip_uvw[2]); - bp = <->def[i]; + BPoint *bp = <->def[i]; if (!bp->hide) { if (BLI_BITMAP_TEST(selpoints, i_flip)) { bp->f1 |= SELECT; diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c index e43eea35a91..770a53d8691 100644 --- a/source/blender/editors/mask/mask_add.c +++ b/source/blender/editors/mask/mask_add.c @@ -76,8 +76,7 @@ static void setup_vertex_point(Mask *mask, */ int point_index = reference_point - spline->points; int delta = new_point == spline->points ? 1 : -1; - int i = 0; - for (i = 0; i < spline->tot_point - 1; i++) { + for (int i = 0; i < spline->tot_point - 1; i++) { MaskSplinePoint *current_point; point_index += delta; @@ -199,9 +198,7 @@ static void finSelectedSplinePoint(MaskLayer *mask_layer, } while (cur_spline) { - int i; - - for (i = 0; i < cur_spline->tot_point; i++) { + for (int i = 0; i < cur_spline->tot_point; i++) { MaskSplinePoint *cur_point = &cur_spline->points[i]; if (MASKPOINT_ISSEL_ANY(cur_point)) { @@ -694,19 +691,17 @@ static int create_primitive_from_points( bContext *C, wmOperator *op, const float (*points)[2], int num_points, char handle_type) { ScrArea *area = CTX_wm_area(C); - Mask *mask; - MaskLayer *mask_layer; - MaskSpline *new_spline; - float scale, location[2], frame_size[2]; - int i, width, height; int size = RNA_float_get(op->ptr, "size"); + int width, height; ED_mask_get_size(area, &width, &height); - scale = (float)size / max_ii(width, height); + float scale = (float)size / max_ii(width, height); /* Get location in mask space. */ + float frame_size[2]; frame_size[0] = width; frame_size[1] = height; + float location[2]; RNA_float_get_array(op->ptr, "location", location); location[0] /= width; location[1] /= height; @@ -717,12 +712,12 @@ static int create_primitive_from_points( location[1] -= 0.5f * scale; bool added_mask = false; - mask_layer = ED_mask_layer_ensure(C, &added_mask); - mask = CTX_data_edit_mask(C); + MaskLayer *mask_layer = ED_mask_layer_ensure(C, &added_mask); + Mask *mask = CTX_data_edit_mask(C); ED_mask_select_toggle_all(mask, SEL_DESELECT); - new_spline = BKE_mask_spline_add(mask_layer); + MaskSpline *new_spline = BKE_mask_spline_add(mask_layer); new_spline->flag = MASK_SPLINE_CYCLIC | SELECT; new_spline->points = MEM_recallocN(new_spline->points, sizeof(MaskSplinePoint) * num_points); @@ -731,7 +726,7 @@ static int create_primitive_from_points( const int spline_index = BKE_mask_layer_shape_spline_to_index(mask_layer, new_spline); - for (i = 0; i < num_points; i++) { + for (int i = 0; i < num_points; i++) { new_spline->tot_point = i + 1; MaskSplinePoint *new_point = &new_spline->points[i]; diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index 51f3a94efde..c9fe03dc599 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -262,15 +262,16 @@ static bool spline_under_mouse_get(const bContext *C, const float threshold = 19.0f; ScrArea *area = CTX_wm_area(C); SpaceClip *sc = CTX_wm_space_clip(C); - int width, height; - float pixel_co[2]; float closest_dist_squared = 0.0f; MaskLayer *closest_layer = NULL; MaskSpline *closest_spline = NULL; bool undistort = false; *r_mask_layer = NULL; *r_mask_spline = NULL; + + int width, height; ED_mask_get_size(area, &width, &height); + float pixel_co[2]; pixel_co[0] = co[0] * width; pixel_co[1] = co[1] * height; if (sc != NULL) { @@ -285,16 +286,13 @@ static bool spline_under_mouse_get(const bContext *C, for (MaskSpline *spline = mask_layer->splines.first; spline != NULL; spline = spline->next) { MaskSplinePoint *points_array; float min[2], max[2], center[2]; - float dist_squared; - int i; - float max_bb_side; if ((spline->flag & SELECT) == 0) { continue; } points_array = BKE_mask_spline_point_array(spline); INIT_MINMAX2(min, max); - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point_deform = &points_array[i]; BezTriple *bezt = &point_deform->bezt; @@ -311,8 +309,8 @@ static bool spline_under_mouse_get(const bContext *C, center[0] = (min[0] + max[0]) / 2.0f * width; center[1] = (min[1] + max[1]) / 2.0f * height; - dist_squared = len_squared_v2v2(pixel_co, center); - max_bb_side = min_ff((max[0] - min[0]) * width, (max[1] - min[1]) * height); + float dist_squared = len_squared_v2v2(pixel_co, center); + float max_bb_side = min_ff((max[0] - min[0]) * width, (max[1] - min[1]) * height); if (dist_squared <= max_bb_side * max_bb_side * 0.5f && (closest_spline == NULL || dist_squared < closest_dist_squared)) { closest_layer = mask_layer; @@ -350,9 +348,7 @@ static bool spline_under_mouse_get(const bContext *C, static bool slide_point_check_initial_feather(MaskSpline *spline) { - int i; - - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; if (point->bezt.weight != 0.0f) { @@ -569,9 +565,7 @@ static int slide_point_invoke(bContext *C, wmOperator *op, const wmEvent *event) static void slide_point_delta_all_feather(SlidePointData *data, float delta) { - int i; - - for (i = 0; i < data->spline->tot_point; i++) { + for (int i = 0; i < data->spline->tot_point; i++) { MaskSplinePoint *point = &data->spline->points[i]; MaskSplinePoint *orig_point = &data->orig_spline->points[i]; @@ -584,16 +578,13 @@ static void slide_point_delta_all_feather(SlidePointData *data, float delta) static void slide_point_restore_spline(SlidePointData *data) { - int i; - - for (i = 0; i < data->spline->tot_point; i++) { + for (int i = 0; i < data->spline->tot_point; i++) { MaskSplinePoint *point = &data->spline->points[i]; MaskSplinePoint *orig_point = &data->orig_spline->points[i]; - int j; point->bezt = orig_point->bezt; - for (j = 0; j < point->tot_uw; j++) { + for (int j = 0; j < point->tot_uw; j++) { point->uw[j] = orig_point->uw[j]; } } @@ -818,13 +809,11 @@ static int slide_point_modal(bContext *C, wmOperator *op, const wmEvent *event) } } else if (data->action == SLIDE_ACTION_SPLINE) { - int i; - if (data->orig_spline == NULL) { data->orig_spline = BKE_mask_spline_copy(data->spline); } - for (i = 0; i < data->spline->tot_point; i++) { + for (int i = 0; i < data->spline->tot_point; i++) { MaskSplinePoint *point = &data->spline->points[i]; add_v2_v2(point->bezt.vec[0], delta); add_v2_v2(point->bezt.vec[1], delta); @@ -1330,13 +1319,13 @@ void MASK_OT_cyclic_toggle(wmOperatorType *ot) static void delete_feather_points(MaskSplinePoint *point) { - int i, count = 0; + int count = 0; if (!point->tot_uw) { return; } - for (i = 0; i < point->tot_uw; i++) { + for (int i = 0; i < point->tot_uw; i++) { if ((point->uw[i].flag & SELECT) == 0) { count++; } @@ -1353,7 +1342,7 @@ static void delete_feather_points(MaskSplinePoint *point) new_uw = MEM_callocN(count * sizeof(MaskSplinePointUW), "new mask uw points"); - for (i = 0; i < point->tot_uw; i++) { + for (int i = 0; i < point->tot_uw; i++) { if ((point->uw[i].flag & SELECT) == 0) { new_uw[j++] = point->uw[i]; } @@ -1383,11 +1372,11 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) while (spline) { const int tot_point_orig = spline->tot_point; - int i, count = 0; + int count = 0; MaskSpline *next_spline = spline->next; /* count unselected points */ - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; if (!MASKPOINT_ISSEL_ANY(point)) { @@ -1409,11 +1398,10 @@ static int delete_exec(bContext *C, wmOperator *UNUSED(op)) } else { MaskSplinePoint *new_points; - int j; new_points = MEM_callocN(count * sizeof(MaskSplinePoint), "deleteMaskPoints"); - for (i = 0, j = 0; i < tot_point_orig; i++) { + for (int i = 0, j = 0; i < tot_point_orig; i++) { MaskSplinePoint *point = &spline->points[i]; if (!MASKPOINT_ISSEL_ANY(point)) { diff --git a/source/blender/editors/mask/mask_select.c b/source/blender/editors/mask/mask_select.c index 82d8a1dc85f..cdc6ece1e84 100644 --- a/source/blender/editors/mask/mask_select.c +++ b/source/blender/editors/mask/mask_select.c @@ -55,9 +55,7 @@ /* 'check' select */ bool ED_mask_spline_select_check(const MaskSpline *spline) { - int i; - - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; if (MASKPOINT_ISSEL_ANY(point)) { @@ -97,8 +95,6 @@ bool ED_mask_select_check(const Mask *mask) /* 'sel' select */ void ED_mask_spline_select_set(MaskSpline *spline, const bool do_select) { - int i; - if (do_select) { spline->flag |= SELECT; } @@ -106,7 +102,7 @@ void ED_mask_spline_select_set(MaskSpline *spline, const bool do_select) spline->flag &= ~SELECT; } - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; BKE_mask_point_select_set(point, do_select); @@ -151,8 +147,7 @@ void ED_mask_select_toggle_all(Mask *mask, int action) continue; } LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { - int i; - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; BKE_mask_point_select_set(point, !MASKPOINT_ISSEL_ANY(point)); } @@ -654,7 +649,6 @@ static int circle_select_exec(bContext *C, wmOperator *op) ARegion *region = CTX_wm_region(C); Mask *mask = CTX_data_edit_mask(C); - int i; float zoomx, zoomy, offset[2], ellipse[2]; int width, height; @@ -692,7 +686,7 @@ static int circle_select_exec(bContext *C, wmOperator *op) LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; MaskSplinePoint *point_deform = &points_array[i]; @@ -871,10 +865,9 @@ static int mask_select_more_less(bContext *C, bool more) LISTBASE_FOREACH (MaskSpline *, spline, &mask_layer->splines) { const bool cyclic = (spline->flag & MASK_SPLINE_CYCLIC) != 0; bool start_sel, end_sel, prev_sel, cur_sel; - int i; /* reselect point if any handle is selected to make the result more predictable */ - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { BKE_mask_point_select_set(spline->points + i, MASKPOINT_ISSEL_ANY(spline->points + i)); } @@ -892,7 +885,7 @@ static int mask_select_more_less(bContext *C, bool more) end_sel = false; } - for (i = 0; i < spline->tot_point; i++) { + for (int i = 0; i < spline->tot_point; i++) { if (i == 0 && !cyclic) { continue; } @@ -908,7 +901,7 @@ static int mask_select_more_less(bContext *C, bool more) } } - for (i = spline->tot_point - 1; i >= 0; i--) { + for (int i = spline->tot_point - 1; i >= 0; i--) { if (i == spline->tot_point - 1 && !cyclic) { continue; } diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index b303c4c7e4e..b349def4637 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -58,7 +58,6 @@ void paintface_flush_flags(struct bContext *C, Object *ob, short flag) MPoly *polys, *mp_orig; const int *index_array = NULL; int totpoly; - int i; BLI_assert((flag & ~(SELECT | ME_HIDE)) == 0); @@ -87,7 +86,7 @@ void paintface_flush_flags(struct bContext *C, Object *ob, short flag) if (me_orig != NULL && me_eval != NULL && me_orig->totpoly == me->totpoly) { /* Update the COW copy of the mesh. */ - for (i = 0; i < me->totpoly; i++) { + for (int i = 0; i < me->totpoly; i++) { me_orig->mpoly[i].flag = me->mpoly[i].flag; } @@ -101,7 +100,7 @@ void paintface_flush_flags(struct bContext *C, Object *ob, short flag) totpoly = me_eval->totpoly; /* loop over final derived polys */ - for (i = 0; i < totpoly; i++) { + for (int i = 0; i < totpoly; i++) { if (index_array[i] != ORIGINDEX_NONE) { /* Copy flags onto the final derived poly from the original mesh poly */ mp_orig = me->mpoly + index_array[i]; diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index 3c426e5d2b1..b7bf6230f22 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -104,7 +104,7 @@ static void make_prim_finish(bContext *C, /* userdef */ if (exit_editmode) { - ED_object_editmode_exit(C, EM_FREEDATA); + ED_object_editmode_exit_ex(CTX_data_main(C), CTX_data_scene(C), obedit, EM_FREEDATA); } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); } diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 515fbab86bc..90ef42c6f48 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -672,12 +672,10 @@ static int linehit_compare(const void *vlh1, const void *vlh2) */ static void prepare_linehits_for_cut(KnifeTool_OpData *kcd) { - KnifeLineHit *linehits, *lhi, *lhj; - int i, j, n; bool is_double = false; - n = kcd->totlinehit; - linehits = kcd->linehits; + int n = kcd->totlinehit; + KnifeLineHit *linehits = kcd->linehits; if (n == 0) { return; } @@ -688,11 +686,11 @@ static void prepare_linehits_for_cut(KnifeTool_OpData *kcd) * by a vertex hit that is very near. Mark such edge hits using * l == -1 and then do another pass to actually remove. * Also remove all but one of a series of vertex hits for the same vertex. */ - for (i = 0; i < n; i++) { - lhi = &linehits[i]; + for (int i = 0; i < n; i++) { + KnifeLineHit *lhi = &linehits[i]; if (lhi->v) { - for (j = i - 1; j >= 0; j--) { - lhj = &linehits[j]; + for (int j = i - 1; j >= 0; j--) { + KnifeLineHit *lhj = &linehits[j]; if (!lhj->kfe || fabsf(lhi->l - lhj->l) > KNIFE_FLT_EPSBIG || fabsf(lhi->m - lhj->m) > KNIFE_FLT_EPSBIG) { break; @@ -703,8 +701,8 @@ static void prepare_linehits_for_cut(KnifeTool_OpData *kcd) is_double = true; } } - for (j = i + 1; j < n; j++) { - lhj = &linehits[j]; + for (int j = i + 1; j < n; j++) { + KnifeLineHit *lhj = &linehits[j]; if (fabsf(lhi->l - lhj->l) > KNIFE_FLT_EPSBIG || fabsf(lhi->m - lhj->m) > KNIFE_FLT_EPSBIG) { break; @@ -719,11 +717,11 @@ static void prepare_linehits_for_cut(KnifeTool_OpData *kcd) if (is_double) { /* delete-in-place loop: copying from pos j to pos i+1 */ - i = 0; - j = 1; + int i = 0; + int j = 1; while (j < n) { - lhi = &linehits[i]; - lhj = &linehits[j]; + KnifeLineHit *lhi = &linehits[i]; + KnifeLineHit *lhj = &linehits[j]; if (lhj->l == -1.0f) { j++; /* skip copying this one */ } diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 22ea222cf01..1537be0aef6 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -171,11 +171,10 @@ static void mesh_uv_reset_array(float **fuv, const int len) } else if (len > 2) { float fac = 0.0f, dfac = 1.0f / (float)len; - int i; dfac *= (float)M_PI * 2.0f; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { fuv[i][0] = 0.5f * sinf(fac) + 0.5f; fuv[i][1] = 0.5f * cosf(fac) + 0.5f; @@ -201,9 +200,8 @@ static void mesh_uv_reset_bmface(BMFace *f, const int cd_loop_uv_offset) static void mesh_uv_reset_mface(MPoly *mp, MLoopUV *mloopuv) { float **fuv = BLI_array_alloca(fuv, mp->totloop); - int i; - for (i = 0; i < mp->totloop; i++) { + for (int i = 0; i < mp->totloop; i++) { fuv[i] = mloopuv[mp->loopstart + i].uv; } @@ -234,13 +232,10 @@ void ED_mesh_uv_loop_reset_ex(struct Mesh *me, const int layernum) } else { /* Collect Mesh UVs */ - MLoopUV *mloopuv; - int i; - BLI_assert(CustomData_has_layer(&me->ldata, CD_MLOOPUV)); - mloopuv = CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, layernum); + MLoopUV *mloopuv = CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, layernum); - for (i = 0; i < me->totpoly; i++) { + for (int i = 0; i < me->totpoly; i++) { mesh_uv_reset_mface(&me->mpoly[i], mloopuv); } } @@ -1061,15 +1056,12 @@ void ED_mesh_update(Mesh *mesh, bContext *C, bool calc_edges, bool calc_edges_lo static void mesh_add_verts(Mesh *mesh, int len) { - CustomData vdata; - MVert *mvert; - int i, totvert; - if (len == 0) { return; } - totvert = mesh->totvert + len; + int totvert = mesh->totvert + len; + CustomData vdata; CustomData_copy(&mesh->vdata, &vdata, CD_MASK_MESH.vmask, CD_DEFAULT, totvert); CustomData_copy_data(&mesh->vdata, &vdata, 0, 0, mesh->totvert); @@ -1084,8 +1076,8 @@ static void mesh_add_verts(Mesh *mesh, int len) /* scan the input list and insert the new vertices */ /* set default flags */ - mvert = &mesh->mvert[mesh->totvert]; - for (i = 0; i < len; i++, mvert++) { + MVert *mvert = &mesh->mvert[mesh->totvert]; + for (int i = 0; i < len; i++, mvert++) { mvert->flag |= SELECT; } diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 482ae4019c3..fa1d147dc5e 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -529,9 +529,12 @@ Object *ED_object_add_type_with_obdata(bContext *C, ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob; - /* for as long scene has editmode... */ - if (CTX_data_edit_object(C)) { - ED_object_editmode_exit(C, EM_FREEDATA); + /* For as long scene has editmode... */ + { + Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + if (obedit != NULL) { + ED_object_editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA); + } } /* deselects all, sets active object */ @@ -778,18 +781,20 @@ static int effector_add_exec(bContext *C, wmOperator *op) dia = RNA_float_get(op->ptr, "radius"); if (type == PFIELD_GUIDE) { + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); Curve *cu; ob = ED_object_add_type( C, OB_CURVE, get_effector_defname(type), loc, rot, false, local_view_bits); cu = ob->data; cu->flag |= CU_PATH | CU_3D; - ED_object_editmode_enter(C, 0); + ED_object_editmode_enter_ex(bmain, scene, ob, 0); ED_object_new_primitive_matrix(C, ob, loc, rot, mat); BLI_addtail(&cu->editnurb->nurbs, ED_curve_add_nurbs_primitive(C, ob, mat, CU_NURBS | CU_PRIM_PATH, dia)); if (!enter_editmode) { - ED_object_editmode_exit(C, EM_FREEDATA); + ED_object_editmode_exit_ex(bmain, scene, ob, EM_FREEDATA); } } else { @@ -900,7 +905,10 @@ void OBJECT_OT_camera_add(wmOperatorType *ot) static int object_metaball_add_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); bool newob = false; bool enter_editmode; ushort local_view_bits; @@ -931,7 +939,7 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op) /* userdef */ if (newob && !enter_editmode) { - ED_object_editmode_exit(C, EM_FREEDATA); + ED_object_editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA); } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); @@ -1017,7 +1025,11 @@ void OBJECT_OT_text_add(wmOperatorType *ot) static int object_armature_add_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + RegionView3D *rv3d = CTX_wm_region_view3d(C); bool newob = false; bool enter_editmode; @@ -1032,7 +1044,7 @@ static int object_armature_add_exec(bContext *C, wmOperator *op) } if ((obedit == NULL) || (obedit->type != OB_ARMATURE)) { obedit = ED_object_add_type(C, OB_ARMATURE, NULL, loc, rot, true, local_view_bits); - ED_object_editmode_enter(C, 0); + ED_object_editmode_enter_ex(bmain, scene, obedit, 0); newob = true; } else { @@ -1049,7 +1061,7 @@ static int object_armature_add_exec(bContext *C, wmOperator *op) /* userdef */ if (newob && !enter_editmode) { - ED_object_editmode_exit(C, EM_FREEDATA); + ED_object_editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA); } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); @@ -2596,20 +2608,18 @@ static int object_convert_exec(bContext *C, wmOperator *op) bGPdata *gpd = (bGPdata *)ob_gpencil->data; gpd->draw_mode = GP_DRAWMODE_3D; - BKE_gpencil_convert_mesh(bmain, - depsgraph, - scene, - ob_gpencil, - ob, - angle, - thickness, - offset, - matrix, - 0, - use_seams, - use_faces, - false); - gpencilConverted = true; + gpencilConverted |= BKE_gpencil_convert_mesh(bmain, + depsgraph, + scene, + ob_gpencil, + ob, + angle, + thickness, + offset, + matrix, + 0, + use_seams, + use_faces); /* Remove unused materials. */ int actcol = ob_gpencil->actcol; diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index 4d55aff1d1f..19097d95743 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -301,8 +301,7 @@ static bool write_internal_bake_pixels(Image *image, /* force OpenGL reload */ static void refresh_images(BakeImages *bake_images) { - int i; - for (i = 0; i < bake_images->size; i++) { + for (int i = 0; i < bake_images->size; i++) { Image *ima = bake_images->data[i].image; LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { if (tile->ok == IMA_OK_LOADED) { @@ -413,10 +412,7 @@ static bool is_noncolor_pass(eScenePassType pass_type) /* if all is good tag image and return true */ static bool bake_object_check(ViewLayer *view_layer, Object *ob, ReportList *reports) { - Image *image; Base *base = BKE_view_layer_base_find(view_layer, ob); - void *lock; - int i; if (base == NULL) { BKE_reportf(reports, RPT_ERROR, "Object \"%s\" is not in view layer", ob->id.name + 2); @@ -440,10 +436,11 @@ static bool bake_object_check(ViewLayer *view_layer, Object *ob, ReportList *rep return false; } - for (i = 0; i < ob->totcol; i++) { + for (int i = 0; i < ob->totcol; i++) { bNodeTree *ntree = NULL; bNode *node = NULL; const int mat_nr = i + 1; + Image *image; ED_object_get_active_image(ob, mat_nr, &image, NULL, &node, &ntree); if (image) { @@ -462,6 +459,7 @@ static bool bake_object_check(ViewLayer *view_layer, Object *ob, ReportList *rep } } + void *lock; ibuf = BKE_image_acquire_ibuf(image, NULL, &lock); if (ibuf) { @@ -637,13 +635,12 @@ static void bake_images_clear(Main *bmain, const bool is_tangent) static void build_image_lookup(Main *bmain, Object *ob, BakeImages *bake_images) { const int tot_mat = ob->totcol; - int i, j; int tot_images = 0; /* error handling and tag (in case multiple materials share the same image) */ BKE_main_id_tag_idcode(bmain, ID_IM, LIB_TAG_DOIT, false); - for (i = 0; i < tot_mat; i++) { + for (int i = 0; i < tot_mat; i++) { Image *image; ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL); @@ -652,7 +649,7 @@ static void build_image_lookup(Main *bmain, Object *ob, BakeImages *bake_images) bake_images->lookup[i] = -1; } else if (image->id.tag & LIB_TAG_DOIT) { - for (j = 0; j < i; j++) { + for (int j = 0; j < i; j++) { if (bake_images->data[j].image == image) { bake_images->lookup[i] = j; break; @@ -675,15 +672,12 @@ static void build_image_lookup(Main *bmain, Object *ob, BakeImages *bake_images) */ static size_t init_internal_images(BakeImages *bake_images, ReportList *reports) { - int i; size_t tot_size = 0; - for (i = 0; i < bake_images->size; i++) { - ImBuf *ibuf; - void *lock; - + for (int i = 0; i < bake_images->size; i++) { BakeImage *bk_image = &bake_images->data[i]; - ibuf = BKE_image_acquire_ibuf(bk_image->image, NULL, &lock); + void *lock; + ImBuf *ibuf = BKE_image_acquire_ibuf(bk_image->image, NULL, &lock); if (ibuf) { bk_image->width = ibuf->x; @@ -1228,8 +1222,7 @@ static int bake(Render *re, cleanup: if (highpoly) { - int i; - for (i = 0; i < tot_highpoly; i++) { + for (int i = 0; i < tot_highpoly; i++) { if (highpoly[i].me != NULL) { BKE_id_free(NULL, &highpoly[i].me->id); } diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index 2f9917a2674..85522209e29 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -80,8 +80,10 @@ /** \name Constraint Data Accessors * \{ */ -/* If object is in posemode, return active bone constraints, else object constraints. No - * constraints are returned for a bone on an inactive bonelayer. */ +/** + * If object is in pose-mode, return active bone constraints, else object constraints. + * No constraints are returned for a bone on an inactive bone-layer. + */ ListBase *ED_object_constraint_active_list(Object *ob) { if (ob == NULL) { @@ -103,13 +105,18 @@ ListBase *ED_object_constraint_active_list(Object *ob) return NULL; } -/* Get the constraints for the active pose bone. Bone may be on an inactive bonelayer (unlike - * ED_object_constraint_active_list, such constraints are not excluded here). */ +/** + * Get the constraints for the active pose bone. Bone may be on an inactive bone-layer + * (unlike #ED_object_constraint_active_list, such constraints are not excluded here). + */ ListBase *ED_object_pose_constraint_list(const bContext *C) { - bPoseChannel *pose_bone = CTX_data_pointer_get(C, "pose_bone").data; + bPoseChannel *pose_bone = CTX_data_pointer_get(C, "active_pose_bone").data; if (pose_bone == NULL) { - return NULL; + pose_bone = CTX_data_pointer_get(C, "pose_bone").data; + if (pose_bone == NULL) { + return NULL; + } } return &pose_bone->constraints; diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c index da00a88ab65..4884df1edb6 100644 --- a/source/blender/editors/object/object_data_transfer.c +++ b/source/blender/editors/object/object_data_transfer.c @@ -153,21 +153,18 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C, Object *ob_src = CTX_data_active_object(C); if (ob_src) { - Mesh *me_eval; - int num_data, i; - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; cddata_masks.lmask |= CD_MASK_MLOOPUV; - me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); - num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPUV); + Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); + int num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPUV); RNA_enum_item_add_separator(&item, &totitem); - for (i = 0; i < num_data; i++) { + for (int i = 0; i < num_data; i++) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = CustomData_get_layer_name( &me_eval->ldata, CD_MLOOPUV, i); @@ -179,21 +176,18 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C, Object *ob_src = CTX_data_active_object(C); if (ob_src) { - Mesh *me_eval; - int num_data, i; - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; cddata_masks.lmask |= CD_MASK_MLOOPCOL; - me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); - num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPCOL); + Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); + int num_data = CustomData_number_of_layers(&me_eval->ldata, CD_MLOOPCOL); RNA_enum_item_add_separator(&item, &totitem); - for (i = 0; i < num_data; i++) { + for (int i = 0; i < num_data; i++) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = CustomData_get_layer_name( &me_eval->ldata, CD_MLOOPCOL, i); diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 966aeed75ab..7e0df736228 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -769,14 +769,14 @@ bool ED_object_editmode_enter(bContext *C, int flag) static int editmode_toggle_exec(bContext *C, wmOperator *op) { - struct wmMsgBus *mbus = CTX_wm_message_bus(C); - const int mode_flag = OB_MODE_EDIT; - const bool is_mode_set = (CTX_data_edit_object(C) != NULL); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = CTX_wm_view3d(C); + ViewLayer *view_layer = CTX_data_view_layer(C); Object *obact = OBACT(view_layer); + const int mode_flag = OB_MODE_EDIT; + const bool is_mode_set = (obact->mode & mode_flag) != 0; + struct wmMsgBus *mbus = CTX_wm_message_bus(C); if (!is_mode_set) { if (!ED_object_mode_compat_set(C, obact, mode_flag, op->reports)) { @@ -785,7 +785,7 @@ static int editmode_toggle_exec(bContext *C, wmOperator *op) } if (!is_mode_set) { - ED_object_editmode_enter(C, 0); + ED_object_editmode_enter_ex(bmain, scene, obact, 0); if (obact->mode & mode_flag) { FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob) { if ((ob != obact) && (ob->type == obact->type)) { @@ -796,7 +796,8 @@ static int editmode_toggle_exec(bContext *C, wmOperator *op) } } else { - ED_object_editmode_exit(C, EM_FREEDATA); + ED_object_editmode_exit_ex(bmain, scene, obact, EM_FREEDATA); + if ((obact->mode & mode_flag) == 0) { FOREACH_OBJECT_BEGIN (view_layer, ob) { if ((ob != obact) && (ob->type == obact->type)) { @@ -859,6 +860,9 @@ void OBJECT_OT_editmode_toggle(wmOperatorType *ot) static int posemode_exec(bContext *C, wmOperator *op) { struct wmMsgBus *mbus = CTX_wm_message_bus(C); + struct Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); Base *base = CTX_data_active_base(C); /* If the base is NULL it means we have an active object, but the object itself is hidden. */ @@ -880,16 +884,17 @@ static int posemode_exec(bContext *C, wmOperator *op) return OPERATOR_PASS_THROUGH; } - if (obact == CTX_data_edit_object(C)) { - ED_object_editmode_exit(C, EM_FREEDATA); - is_mode_set = false; + { + Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + if (obact == obedit) { + ED_object_editmode_exit_ex(bmain, scene, obedit, EM_FREEDATA); + is_mode_set = false; + } } if (is_mode_set) { bool ok = ED_object_posemode_exit(C, obact); if (ok) { - struct Main *bmain = CTX_data_main(C); - ViewLayer *view_layer = CTX_data_view_layer(C); FOREACH_OBJECT_BEGIN (view_layer, ob) { if ((ob != obact) && (ob->type == OB_ARMATURE) && (ob->mode & mode_flag)) { ED_object_posemode_exit_ex(bmain, ob); @@ -901,9 +906,7 @@ static int posemode_exec(bContext *C, wmOperator *op) else { bool ok = ED_object_posemode_enter(C, obact); if (ok) { - struct Main *bmain = CTX_data_main(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - View3D *v3d = CTX_wm_view3d(C); + const View3D *v3d = CTX_wm_view3d(C); FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob) { if ((ob != obact) && (ob->type == OB_ARMATURE) && (ob->mode == OB_MODE_OBJECT) && (!ID_IS_LINKED(ob))) { diff --git a/source/blender/editors/object/object_facemap_ops.c b/source/blender/editors/object/object_facemap_ops.c index 32668598df1..4e2b1eb21b6 100644 --- a/source/blender/editors/object/object_facemap_ops.c +++ b/source/blender/editors/object/object_facemap_ops.c @@ -136,10 +136,8 @@ static void object_fmap_remap_object_mode(Object *ob, const int *remap) Mesh *me = ob->data; if (CustomData_has_layer(&me->pdata, CD_FACEMAP)) { int *map = CustomData_get_layer(&me->pdata, CD_FACEMAP); - int i; - if (map) { - for (i = 0; i < me->totpoly; i++) { + for (int i = 0; i < me->totpoly; i++) { if (map[i] != -1) { map[i] = remap[map[i]]; } diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 52b572fb0dd..e2d043c3206 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -834,11 +834,10 @@ static int apply_objects_internal(bContext *C, } else if (ob->type == OB_FONT) { Curve *cu = ob->data; - int i; scale = mat3_to_scale(rsmat); - for (i = 0; i < cu->totbox; i++) { + for (int i = 0; i < cu->totbox; i++) { TextBox *tb = &cu->tb[i]; tb->x *= scale; tb->y *= scale; diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index de9cca38a6e..b8811408339 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -148,11 +148,9 @@ void ED_vgroup_data_clamp_range(ID *id, const int total) int dvert_tot; if (ED_vgroup_parray_alloc(id, &dvert_arr, &dvert_tot, false)) { - int i; - for (i = 0; i < dvert_tot; i++) { + for (int i = 0; i < dvert_tot; i++) { MDeformVert *dv = dvert_arr[i]; - int j; - for (j = 0; j < dv->totweight; j++) { + for (int j = 0; j < dv->totweight; j++) { if (dv->dw[j].def_nr >= total) { BKE_defvert_remove_group(dv, &dv->dw[j]); j--; @@ -213,18 +211,17 @@ bool ED_vgroup_parray_alloc(ID *id, if (me->dvert) { MVert *mvert = me->mvert; MDeformVert *dvert = me->dvert; - int i; *dvert_tot = me->totvert; *dvert_arr = MEM_mallocN(sizeof(void *) * me->totvert, "vgroup parray from me"); if (use_vert_sel) { - for (i = 0; i < me->totvert; i++) { + for (int i = 0; i < me->totvert; i++) { (*dvert_arr)[i] = (mvert[i].flag & SELECT) ? &dvert[i] : NULL; } } else { - for (i = 0; i < me->totvert; i++) { + for (int i = 0; i < me->totvert; i++) { (*dvert_arr)[i] = me->dvert + i; } } @@ -234,8 +231,6 @@ bool ED_vgroup_parray_alloc(ID *id, return false; } case ID_LT: { - int i = 0; - Lattice *lt = (Lattice *)id; lt = (lt->editlatt) ? lt->editlatt->latt : lt; @@ -245,12 +240,12 @@ bool ED_vgroup_parray_alloc(ID *id, *dvert_arr = MEM_mallocN(sizeof(void *) * (*dvert_tot), "vgroup parray from me"); if (use_vert_sel) { - for (i = 0; i < *dvert_tot; i++) { + for (int i = 0; i < *dvert_tot; i++) { (*dvert_arr)[i] = (def->f1 & SELECT) ? <->dvert[i] : NULL; } } else { - for (i = 0; i < *dvert_tot; i++) { + for (int i = 0; i < *dvert_tot; i++) { (*dvert_arr)[i] = lt->dvert + i; } } @@ -328,7 +323,6 @@ void ED_vgroup_parray_mirror_assign(Object *ob, MDeformVert **dvert_array, const BMEditMesh *em = BKE_editmesh_from_object(ob); MDeformVert **dvert_array_all = NULL; int dvert_tot_all; - int i; /* get an array of all verts, not only selected */ if (ED_vgroup_parray_alloc(ob->data, &dvert_array_all, &dvert_tot_all, false) == false) { @@ -340,7 +334,7 @@ void ED_vgroup_parray_mirror_assign(Object *ob, MDeformVert **dvert_array, const BM_mesh_elem_table_ensure(em->bm, BM_VERT); } - for (i = 0; i < dvert_tot; i++) { + for (int i = 0; i < dvert_tot; i++) { if (dvert_array[i] == NULL) { /* its unselected, check if its mirror is */ int i_sel = ED_mesh_mirror_get_vert(ob, i); @@ -362,17 +356,14 @@ void ED_vgroup_parray_remove_zero(MDeformVert **dvert_array, const bool keep_single) { MDeformVert *dv; - int i; - - for (i = 0; i < dvert_tot; i++) { - int j; + for (int i = 0; i < dvert_tot; i++) { /* in case its not selected */ if (!(dv = dvert_array[i])) { continue; } - j = dv->totweight; + int j = dv->totweight; while (j--) { MDeformWeight *dw; @@ -482,9 +473,7 @@ void ED_vgroup_parray_to_weight_array(const MDeformVert **dvert_array, float *dvert_weights, const int def_nr) { - int i; - - for (i = 0; i < dvert_tot; i++) { + for (int i = 0; i < dvert_tot; i++) { const MDeformVert *dv = dvert_array[i]; dvert_weights[i] = dv ? BKE_defvert_find_weight(dv, def_nr) : 0.0f; } @@ -1163,7 +1152,7 @@ static bool vgroup_normalize(Object *ob) { MDeformWeight *dw; MDeformVert *dv, **dvert_array = NULL; - int i, dvert_tot = 0; + int dvert_tot = 0; const int def_nr = ob->actdef - 1; const bool use_vert_sel = vertex_group_use_vert_sel(ob); @@ -1177,7 +1166,7 @@ static bool vgroup_normalize(Object *ob) if (dvert_array) { float weight_max = 0.0f; - for (i = 0; i < dvert_tot; i++) { + for (int i = 0; i < dvert_tot; i++) { /* in case its not selected */ if (!(dv = dvert_array[i])) { @@ -1191,7 +1180,7 @@ static bool vgroup_normalize(Object *ob) } if (weight_max > 0.0f) { - for (i = 0; i < dvert_tot; i++) { + for (int i = 0; i < dvert_tot; i++) { /* in case its not selected */ if (!(dv = dvert_array[i])) { @@ -1599,7 +1588,7 @@ static void vgroup_levels_subset(Object *ob, { MDeformWeight *dw; MDeformVert *dv, **dvert_array = NULL; - int i, dvert_tot = 0; + int dvert_tot = 0; const bool use_vert_sel = vertex_group_use_vert_sel(ob); const bool use_mirror = (ob->type == OB_MESH) ? @@ -1610,15 +1599,13 @@ static void vgroup_levels_subset(Object *ob, if (dvert_array) { - for (i = 0; i < dvert_tot; i++) { - int j; - + for (int i = 0; i < dvert_tot; i++) { /* in case its not selected */ if (!(dv = dvert_array[i])) { continue; } - j = vgroup_tot; + int j = vgroup_tot; while (j--) { if (vgroup_validmap[j]) { dw = BKE_defvert_find_index(dv, j); @@ -1857,7 +1844,7 @@ static void vgroup_invert_subset(Object *ob, { MDeformWeight *dw; MDeformVert *dv, **dvert_array = NULL; - int i, dvert_tot = 0; + int dvert_tot = 0; const bool use_vert_sel = vertex_group_use_vert_sel(ob); const bool use_mirror = (ob->type == OB_MESH) ? (((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_X) != 0 : @@ -1866,15 +1853,13 @@ static void vgroup_invert_subset(Object *ob, ED_vgroup_parray_alloc(ob->data, &dvert_array, &dvert_tot, use_vert_sel); if (dvert_array) { - for (i = 0; i < dvert_tot; i++) { - int j; - + for (int i = 0; i < dvert_tot; i++) { /* in case its not selected */ if (!(dv = dvert_array[i])) { continue; } - j = vgroup_tot; + int j = vgroup_tot; while (j--) { if (vgroup_validmap[j]) { @@ -2271,21 +2256,20 @@ static void vgroup_quantize_subset(Object *ob, if (dvert_array) { const float steps_fl = steps; MDeformVert *dv; - int i; if (use_mirror && use_vert_sel) { ED_vgroup_parray_mirror_assign(ob, dvert_array, dvert_tot); } - for (i = 0; i < dvert_tot; i++) { + for (int i = 0; i < dvert_tot; i++) { MDeformWeight *dw; - int j; /* in case its not selected */ if (!(dv = dvert_array[i])) { continue; } + int j; for (j = 0, dw = dv->dw; j < dv->totweight; j++, dw++) { if ((dw->def_nr < vgroup_tot) && vgroup_validmap[dw->def_nr]) { dw->weight = floorf((dw->weight * steps_fl) + 0.5f) / steps_fl; @@ -2628,18 +2612,14 @@ static void vgroup_assign_verts(Object *ob, const float weight) } } else { - MVert *mv; - MDeformVert *dv; - int i; - if (!me->dvert) { BKE_object_defgroup_data_create(&me->id); } - mv = me->mvert; - dv = me->dvert; + MVert *mv = me->mvert; + MDeformVert *dv = me->dvert; - for (i = 0; i < me->totvert; i++, mv++, dv++) { + for (int i = 0; i < me->totvert; i++, mv++, dv++) { if (mv->flag & SELECT) { MDeformWeight *dw; dw = BKE_defvert_ensure_index(dv, def_nr); diff --git a/source/blender/editors/object/object_warp.c b/source/blender/editors/object/object_warp.c index 00f9330c8a7..b36a8543d67 100644 --- a/source/blender/editors/object/object_warp.c +++ b/source/blender/editors/object/object_warp.c @@ -71,11 +71,8 @@ static void object_warp_transverts_minmax_x(TransVertStore *tvs, const float x_ofs = (mat_view[3][0] - center_view[0]); float min = FLT_MAX, max = -FLT_MAX; - TransVert *tv; - int i; - - tv = tvs->transverts; - for (i = 0; i < tvs->transverts_tot; i++, tv++) { + TransVert *tv = tvs->transverts; + for (int i = 0; i < tvs->transverts_tot; i++, tv++) { float val; /* convert objectspace->viewspace */ @@ -97,7 +94,6 @@ static void object_warp_transverts(TransVertStore *tvs, const float max) { TransVert *tv; - int i; const float angle = -angle_; /* cache vars for tiny speedup */ #if 1 @@ -123,7 +119,7 @@ static void object_warp_transverts(TransVertStore *tvs, } tv = tvs->transverts; - for (i = 0; i < tvs->transverts_tot; i++, tv++) { + for (int i = 0; i < tvs->transverts_tot; i++, tv++) { float co[3], co_add[2]; float val, phi; diff --git a/source/blender/editors/physics/particle_edit_undo.c b/source/blender/editors/physics/particle_edit_undo.c index 205c04f54a9..8db6c4c853e 100644 --- a/source/blender/editors/physics/particle_edit_undo.c +++ b/source/blender/editors/physics/particle_edit_undo.c @@ -57,7 +57,6 @@ static void undoptcache_from_editcache(PTCacheUndo *undo, PTCacheEdit *edit) { PTCacheEditPoint *point; - int i; size_t mem_used_prev = MEM_get_memory_in_use(); @@ -68,7 +67,7 @@ static void undoptcache_from_editcache(PTCacheUndo *undo, PTCacheEdit *edit) pa = undo->particles = MEM_dupallocN(edit->psys->particles); - for (i = 0; i < edit->totpoint; i++, pa++) { + for (int i = 0; i < edit->totpoint; i++, pa++) { pa->hair = MEM_dupallocN(pa->hair); } @@ -81,7 +80,7 @@ static void undoptcache_from_editcache(PTCacheUndo *undo, PTCacheEdit *edit) pm = undo->mem_cache.first; for (; pm; pm = pm->next) { - for (i = 0; i < BPHYS_TOT_DATA; i++) { + for (int i = 0; i < BPHYS_TOT_DATA; i++) { pm->data[i] = MEM_dupallocN(pm->data[i]); } } @@ -90,7 +89,7 @@ static void undoptcache_from_editcache(PTCacheUndo *undo, PTCacheEdit *edit) point = undo->points = MEM_dupallocN(edit->points); undo->totpoint = edit->totpoint; - for (i = 0; i < edit->totpoint; i++, point++) { + for (int i = 0; i < edit->totpoint; i++, point++) { point->keys = MEM_dupallocN(point->keys); /* no need to update edit key->co & key->time pointers here */ } diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index 41e30adf724..0eda5877bb4 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -721,7 +721,7 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, MVert *mvert; Mesh *mesh, *target_mesh; int numverts; - int i, k; + int k; float from_ob_imat[4][4], to_ob_imat[4][4]; float from_imat[4][4], to_imat[4][4]; @@ -763,7 +763,7 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, mvert = mesh->mvert; /* convert to global coordinates */ - for (i = 0; i < numverts; i++) { + for (int i = 0; i < numverts; i++) { mul_m4_v3(to_mat, mvert[i].co); } @@ -780,6 +780,7 @@ static bool remap_hair_emitter(Depsgraph *depsgraph, return false; } + int i; for (i = 0, tpa = target_psys->particles, pa = psys->particles; i < target_psys->totpart; i++, tpa++, pa++) { float from_co[3]; diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 25b4ddc15fd..509097c7a70 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -604,6 +604,7 @@ static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrec ED_draw_imbuf_method(ibuf) != IMAGE_DRAW_METHOD_GLSL) { image_buffer_rect_update(rj, rr, ibuf, &rj->iuser, renrect, viewname); } + ima->gpuflag |= IMA_GPU_REFRESH; /* make jobs timer to send notifier */ *(rj->do_update) = true; diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 956eaa81198..a6262ead920 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -3307,7 +3307,6 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const char temp_str[MAX_METADATA_STR]; int line_width; int ofs_y = 0; - short i; int len; const float height = BLF_height_max(fontid); const float margin = height / 8; @@ -3321,7 +3320,7 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const const float ymax = (rect->ymax - margin) - descender; if (is_top) { - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { /* first line */ if (i == 0) { bool do_newline = false; @@ -3386,7 +3385,7 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const IMB_metadata_foreach(ibuf, metadata_custom_draw_fields, &ctx); int ofs_x = 0; ofs_y = ctx.current_y; - for (i = 5; i < 10; i++) { + for (int i = 5; i < 10; i++) { len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i]); if (metadata_is_valid(ibuf, temp_str, i, len)) { BLF_position(fontid, xmin + ofs_x, ymin + ofs_y, 0.0f); diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index f4d7869e40a..3d8c718c8a9 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -911,7 +911,6 @@ static void paint_draw_curve_cursor(Brush *brush, ViewContext *vc) GPU_matrix_translate_2f(vc->region->winrct.xmin, vc->region->winrct.ymin); if (brush->paint_curve && brush->paint_curve->points) { - int i; PaintCurve *pc = brush->paint_curve; PaintCurvePoint *cp = pc->points; @@ -928,7 +927,7 @@ static void paint_draw_curve_cursor(Brush *brush, ViewContext *vc) UI_GetThemeColorType4fv(TH_PAINT_CURVE_HANDLE, SPACE_VIEW3D, handle_col); UI_GetThemeColorType4fv(TH_PAINT_CURVE_PIVOT, SPACE_VIEW3D, pivot_col); - for (i = 0; i < pc->tot_points - 1; i++, cp++) { + for (int i = 0; i < pc->tot_points - 1; i++, cp++) { int j; PaintCurvePoint *cp_next = cp + 1; float data[(PAINT_CURVE_NUM_SEGMENTS + 1) * 2]; diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c index 458f021ddb4..c63af64a87a 100644 --- a/source/blender/editors/sculpt_paint/paint_curve.c +++ b/source/blender/editors/sculpt_paint/paint_curve.c @@ -189,23 +189,20 @@ static void paintcurve_point_add(bContext *C, wmOperator *op, const int loc[2]) Paint *p = BKE_paint_get_active_from_context(C); Brush *br = p->brush; Main *bmain = CTX_data_main(C); - PaintCurve *pc; - PaintCurvePoint *pcp; wmWindow *window = CTX_wm_window(C); ARegion *region = CTX_wm_region(C); const float vec[3] = {loc[0], loc[1], 0.0}; - int add_index; - int i; - pc = br->paint_curve; + PaintCurve *pc = br->paint_curve; if (!pc) { br->paint_curve = pc = BKE_paint_curve_add(bmain, "PaintCurve"); } ED_paintcurve_undo_push_begin(op->type->name); - pcp = MEM_mallocN((pc->tot_points + 1) * sizeof(PaintCurvePoint), "PaintCurvePoint"); - add_index = pc->add_index; + PaintCurvePoint *pcp = MEM_mallocN((pc->tot_points + 1) * sizeof(PaintCurvePoint), + "PaintCurvePoint"); + int add_index = pc->add_index; if (pc->points) { if (add_index > 0) { @@ -229,7 +226,7 @@ static void paintcurve_point_add(bContext *C, wmOperator *op, const int loc[2]) copy_v3_v3(pcp[add_index].bez.vec[2], vec); /* last step, clear selection from all bezier handles expect the next */ - for (i = 0; i < pc->tot_points; i++) { + for (int i = 0; i < pc->tot_points; i++) { pcp[i].bez.f1 = pcp[i].bez.f2 = pcp[i].bez.f3 = 0; } diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 3886b78286b..d44654f4fd5 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -2676,7 +2676,6 @@ static void project_bucket_clip_face(const bool is_ortho, /* calc center */ float cent[2] = {0.0f, 0.0f}; /*float up[2] = {0.0f, 1.0f};*/ - int i; bool doubles; (*tot) = 0; @@ -2757,7 +2756,7 @@ static void project_bucket_clip_face(const bool is_ortho, /* now we have all points we need, collect their angles and sort them clockwise */ - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { cent[0] += isectVCosSS[i][0]; cent[1] += isectVCosSS[i][1]; } @@ -2767,7 +2766,7 @@ static void project_bucket_clip_face(const bool is_ortho, /* Collect angles for every point around the center point */ #if 0 /* uses a few more cycles then the above loop */ - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { isectVCosSS[i][2] = angle_2d_clockwise(up, cent, isectVCosSS[i]); } #endif @@ -2776,7 +2775,7 @@ static void project_bucket_clip_face(const bool is_ortho, v1_clipSS[0] = cent[0]; v1_clipSS[1] = cent[1] + 1.0f; - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { v2_clipSS[0] = isectVCosSS[i][0] - cent[0]; v2_clipSS[1] = isectVCosSS[i][1] - cent[1]; isectVCosSS[i][2] = atan2f(v1_clipSS[0] * v2_clipSS[1] - v1_clipSS[1] * v2_clipSS[0], @@ -2794,11 +2793,10 @@ static void project_bucket_clip_face(const bool is_ortho, while (doubles == true) { doubles = false; - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { if (fabsf(isectVCosSS[(i + 1) % *tot][0] - isectVCosSS[i][0]) < PROJ_PIXEL_TOLERANCE && fabsf(isectVCosSS[(i + 1) % *tot][1] - isectVCosSS[i][1]) < PROJ_PIXEL_TOLERANCE) { - int j; - for (j = i; j < (*tot) - 1; j++) { + for (int j = i; j < (*tot) - 1; j++) { isectVCosSS[j][0] = isectVCosSS[j + 1][0]; isectVCosSS[j][1] = isectVCosSS[j + 1][1]; } @@ -2817,13 +2815,13 @@ static void project_bucket_clip_face(const bool is_ortho, } if (is_ortho) { - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { barycentric_weights_v2(v1coSS, v2coSS, v3coSS, isectVCosSS[i], w); interp_v2_v2v2v2(bucket_bounds_uv[i], uv1co, uv2co, uv3co, w); } } else { - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { barycentric_weights_v2_persp(v1coSS, v2coSS, v3coSS, isectVCosSS[i], w); interp_v2_v2v2v2(bucket_bounds_uv[i], uv1co, uv2co, uv3co, w); } @@ -2864,7 +2862,7 @@ static void project_bucket_clip_face(const bool is_ortho, uv3co[1]); printf("["); - for (i = 0; i < (*tot); i++) { + for (int i = 0; i < (*tot); i++) { printf("(%f, %f),", bucket_bounds_uv[i][0], bucket_bounds_uv[i][1]); } printf("]),\\\n"); @@ -5874,8 +5872,6 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m ProjStrokeHandle *ps_handle; Scene *scene = CTX_data_scene(C); ToolSettings *settings = scene->toolsettings; - int i; - bool is_multi_view; char symmetry_flag_views[ARRAY_SIZE(ps_handle->ps_views)] = {0}; ps_handle = MEM_callocN(sizeof(ProjStrokeHandle), "ProjStrokeHandle"); @@ -5893,9 +5889,9 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m ps_handle->symmetry_flags = settings->imapaint.paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; ps_handle->ps_views_tot = 1 + (pow_i(2, count_bits_i(ps_handle->symmetry_flags)) - 1); - is_multi_view = (ps_handle->ps_views_tot != 1); + bool is_multi_view = (ps_handle->ps_views_tot != 1); - for (i = 0; i < ps_handle->ps_views_tot; i++) { + for (int i = 0; i < ps_handle->ps_views_tot; i++) { ProjPaintState *ps = MEM_callocN(sizeof(ProjPaintState), "ProjectionPaintState"); ps_handle->ps_views[i] = ps; } @@ -5918,7 +5914,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m BLI_assert(index == ps_handle->ps_views_tot); } - for (i = 0; i < ps_handle->ps_views_tot; i++) { + for (int i = 0; i < ps_handle->ps_views_tot; i++) { ProjPaintState *ps = ps_handle->ps_views[i]; project_state_init(C, ob, ps, mode); @@ -5936,7 +5932,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m /* allocate and initialize spatial data structures */ - for (i = 0; i < ps_handle->ps_views_tot; i++) { + for (int i = 0; i < ps_handle->ps_views_tot; i++) { ProjPaintState *ps = ps_handle->ps_views[i]; ps->source = (ps->tool == PAINT_TOOL_FILL) ? PROJ_SRC_VIEW_FILL : PROJ_SRC_VIEW; @@ -5961,7 +5957,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m return ps_handle; fail: - for (i = 0; i < ps_handle->ps_views_tot; i++) { + for (int i = 0; i < ps_handle->ps_views_tot; i++) { ProjPaintState *ps = ps_handle->ps_views[i]; MEM_freeN(ps); } diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index e709224f370..db7120ed301 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -711,15 +711,12 @@ static float paint_space_stroke_spacing(bContext *C, static float paint_stroke_overlapped_curve(Brush *br, float x, float spacing) { - int i; const int n = 100 / spacing; const float h = spacing / 50.0f; const float x0 = x - 1; - float sum; - - sum = 0; - for (i = 0; i < n; i++) { + float sum = 0; + for (int i = 0; i < n; i++) { float xx; xx = fabsf(x0 + i * h); @@ -734,21 +731,16 @@ static float paint_stroke_overlapped_curve(Brush *br, float x, float spacing) static float paint_stroke_integrate_overlap(Brush *br, float factor) { - int i; - int m; - float g; - float max; - float spacing = br->spacing * factor; if (!(br->flag & BRUSH_SPACE_ATTEN && (br->spacing < 100))) { return 1.0; } - m = 10; - g = 1.0f / m; - max = 0; - for (i = 0; i < m; i++) { + int m = 10; + float g = 1.0f / m; + float max = 0; + for (int i = 0; i < m; i++) { float overlap = fabs(paint_stroke_overlapped_curve(br, i * g, spacing)); if (overlap > max) { @@ -1151,13 +1143,11 @@ static void paint_stroke_add_sample( static void paint_stroke_sample_average(const PaintStroke *stroke, PaintSample *average) { - int i; - memset(average, 0, sizeof(*average)); BLI_assert(stroke->num_samples > 0); - for (i = 0; i < stroke->num_samples; i++) { + for (int i = 0; i < stroke->num_samples; i++) { add_v2_v2(average->mouse, stroke->samples[i].mouse); average->pressure += stroke->samples[i].pressure; } diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c index d05b1673c9a..b831687ca67 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c @@ -68,9 +68,6 @@ static void tag_object_after_update(Object *object) static bool vertex_color_set(Object *ob, uint paintcol) { Mesh *me; - const MPoly *mp; - int i, j; - if (((me = BKE_mesh_from_object(ob)) == NULL) || (ED_mesh_color_ensure(me, NULL) == false)) { return false; } @@ -78,15 +75,15 @@ static bool vertex_color_set(Object *ob, uint paintcol) const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; const bool use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; - mp = me->mpoly; - for (i = 0; i < me->totpoly; i++, mp++) { + const MPoly *mp = me->mpoly; + for (int i = 0; i < me->totpoly; i++, mp++) { MLoopCol *lcol = me->mloopcol + mp->loopstart; if (use_face_sel && !(mp->flag & ME_FACE_SEL)) { continue; } - j = 0; + int j = 0; do { uint vidx = me->mloop[mp->loopstart + j].v; if (!(use_vert_sel && !(me->mvert[vidx].flag & SELECT))) { @@ -211,7 +208,6 @@ static void vertex_color_smooth_looptag(Mesh *me, const bool *mlooptag) const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; const MPoly *mp; int(*scol)[4]; - int i, j; bool has_shared = false; /* if no mloopcol: do not do */ @@ -223,11 +219,12 @@ static void vertex_color_smooth_looptag(Mesh *me, const bool *mlooptag) scol = MEM_callocN(sizeof(int) * me->totvert * 5, "scol"); + int i; for (i = 0, mp = me->mpoly; i < me->totpoly; i++, mp++) { if ((use_face_sel == false) || (mp->flag & ME_FACE_SEL)) { const MLoop *ml = me->mloop + mp->loopstart; MLoopCol *lcol = me->mloopcol + mp->loopstart; - for (j = 0; j < mp->totloop; j++, ml++, lcol++) { + for (int j = 0; j < mp->totloop; j++, ml++, lcol++) { scol[ml->v][0] += lcol->r; scol[ml->v][1] += lcol->g; scol[ml->v][2] += lcol->b; @@ -250,7 +247,7 @@ static void vertex_color_smooth_looptag(Mesh *me, const bool *mlooptag) if ((use_face_sel == false) || (mp->flag & ME_FACE_SEL)) { const MLoop *ml = me->mloop + mp->loopstart; MLoopCol *lcol = me->mloopcol + mp->loopstart; - for (j = 0; j < mp->totloop; j++, ml++, lcol++) { + for (int j = 0; j < mp->totloop; j++, ml++, lcol++) { if (mlooptag[mp->loopstart + j]) { lcol->r = scol[ml->v][0]; lcol->g = scol[ml->v][1]; diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c b/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c index 637ce8193c1..7120f6a8748 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c @@ -435,9 +435,7 @@ BLI_INLINE uint mcol_softlight(uint col_src, uint col_dst, int fac) cp_dst = (uchar *)&col_dst; cp_mix = (uchar *)&col_mix; - int i = 0; - - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { if (cp_src[i] < 127) { temp = ((2 * ((cp_dst[i] / 2) + 64)) * cp_src[i]) / 255; } diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 5070709cb6d..e6ea79a771a 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -1920,6 +1920,9 @@ static void calc_area_normal_and_center_task_cb(void *__restrict userdata, if (ELEM(data->brush->sculpt_tool, SCULPT_TOOL_SCRAPE, SCULPT_TOOL_FILL) && data->brush->area_radius_factor > 0.0f) { test_radius *= data->brush->area_radius_factor; + if (ss->cache && data->brush->flag2 & BRUSH_AREA_RADIUS_PRESSURE) { + test_radius *= ss->cache->pressure; + } } else { test_radius *= data->brush->normal_radius_factor; diff --git a/source/blender/editors/sculpt_paint/sculpt_boundary.c b/source/blender/editors/sculpt_paint/sculpt_boundary.c index 3051413a405..b07dd18b6fc 100644 --- a/source/blender/editors/sculpt_paint/sculpt_boundary.c +++ b/source/blender/editors/sculpt_paint/sculpt_boundary.c @@ -501,6 +501,10 @@ SculptBoundary *SCULPT_boundary_data_init(Object *object, { SculptSession *ss = object->sculpt; + if (initial_vertex == BOUNDARY_VERTEX_NONE) { + return NULL; + } + SCULPT_vertex_random_access_ensure(ss); SCULPT_boundary_info_ensure(object); diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c index f07d22ed639..9b4b5b8d1e2 100644 --- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c +++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c @@ -36,6 +36,7 @@ #include "BKE_brush.h" #include "BKE_context.h" +#include "BKE_global.h" #include "BKE_main.h" #include "BKE_mesh.h" #include "BKE_mesh_mapping.h" @@ -58,6 +59,7 @@ #include "ED_object.h" #include "ED_screen.h" #include "ED_sculpt.h" +#include "ED_undo.h" #include "ED_view3d.h" #include "paint_intern.h" #include "sculpt_intern.h" @@ -285,11 +287,17 @@ void sculpt_dynamic_topology_disable_with_undo(Main *bmain, Object *ob) { SculptSession *ss = ob->sculpt; - if (ss->bm) { - SCULPT_undo_push_begin("Dynamic topology disable"); - SCULPT_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_END); + if (ss->bm != NULL) { + /* May be false in background mode. */ + const bool use_undo = G.background ? (ED_undo_stack_get() != NULL) : true; + if (use_undo) { + SCULPT_undo_push_begin("Dynamic topology disable"); + SCULPT_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_END); + } SCULPT_dynamic_topology_disable_ex(bmain, depsgraph, scene, ob, NULL); - SCULPT_undo_push_end(); + if (use_undo) { + SCULPT_undo_push_end(); + } } } @@ -300,10 +308,16 @@ static void sculpt_dynamic_topology_enable_with_undo(Main *bmain, { SculptSession *ss = ob->sculpt; if (ss->bm == NULL) { - SCULPT_undo_push_begin("Dynamic topology enable"); + /* May be false in background mode. */ + const bool use_undo = G.background ? (ED_undo_stack_get() != NULL) : true; + if (use_undo) { + SCULPT_undo_push_begin("Dynamic topology enable"); + } SCULPT_dynamic_topology_enable_ex(bmain, depsgraph, scene, ob); - SCULPT_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN); - SCULPT_undo_push_end(); + if (use_undo) { + SCULPT_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN); + SCULPT_undo_push_end(); + } } } diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index fd800ca2c18..287e1eb03d1 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -327,17 +327,14 @@ static bool sculpt_undo_restore_color(bContext *C, SculptUndoNode *unode) ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = OBACT(view_layer); SculptSession *ss = ob->sculpt; - MVert *mvert; - MPropCol *vcol; - int *index, i; if (unode->maxvert) { /* regular mesh restore */ - index = unode->index; - mvert = ss->mvert; - vcol = ss->vcol; + int *index = unode->index; + MVert *mvert = ss->mvert; + MPropCol *vcol = ss->vcol; - for (i = 0; i < unode->totvert; i++) { + for (int i = 0; i < unode->totvert; i++) { copy_v4_v4(vcol[index[i]].color, unode->col[i]); mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE; } @@ -927,16 +924,14 @@ SculptUndoNode *SCULPT_undo_get_first_node() static void sculpt_undo_alloc_and_store_hidden(PBVH *pbvh, SculptUndoNode *unode) { PBVHNode *node = unode->node; - BLI_bitmap **grid_hidden; - int i, *grid_indices, totgrid; - - grid_hidden = BKE_pbvh_grid_hidden(pbvh); + BLI_bitmap **grid_hidden = BKE_pbvh_grid_hidden(pbvh); + int *grid_indices, totgrid; BKE_pbvh_node_get_grids(pbvh, node, &grid_indices, &totgrid, NULL, NULL, NULL); unode->grid_hidden = MEM_callocN(sizeof(*unode->grid_hidden) * totgrid, "unode->grid_hidden"); - for (i = 0; i < totgrid; i++) { + for (int i = 0; i < totgrid; i++) { if (grid_hidden[grid_indices[i]]) { unode->grid_hidden[i] = MEM_dupallocN(grid_hidden[grid_indices[i]]); } @@ -1087,11 +1082,10 @@ static void sculpt_undo_store_hidden(Object *ob, SculptUndoNode *unode) MVert *mvert; const int *vert_indices; int allvert; - int i; BKE_pbvh_node_num_verts(pbvh, node, NULL, &allvert); BKE_pbvh_node_get_verts(pbvh, node, &vert_indices, &mvert); - for (i = 0; i < allvert; i++) { + for (int i = 0; i < allvert; i++) { BLI_BITMAP_SET(unode->vert_hidden, i, mvert[vert_indices[i]].flag & ME_HIDE); } } diff --git a/source/blender/editors/space_api/CMakeLists.txt b/source/blender/editors/space_api/CMakeLists.txt index de1c905b08b..d948d84f1c3 100644 --- a/source/blender/editors/space_api/CMakeLists.txt +++ b/source/blender/editors/space_api/CMakeLists.txt @@ -35,6 +35,7 @@ set(SRC ) set(LIB + bf_editor_geometry bf_editor_space_action bf_editor_space_buttons bf_editor_space_clip diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c index 1656a76e2d4..29ad314cd65 100644 --- a/source/blender/editors/space_api/spacetypes.c +++ b/source/blender/editors/space_api/spacetypes.c @@ -41,6 +41,7 @@ #include "ED_clip.h" #include "ED_curve.h" #include "ED_fileselect.h" +#include "ED_geometry.h" #include "ED_gizmo_library.h" #include "ED_gpencil.h" #include "ED_lattice.h" @@ -106,6 +107,7 @@ void ED_spacetypes_init(void) ED_operatortypes_object(); ED_operatortypes_lattice(); ED_operatortypes_mesh(); + ED_operatortypes_geometry(); ED_operatortypes_sculpt(); ED_operatortypes_uvedit(); ED_operatortypes_paint(); diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index e567b3ca54c..84a020a9ed7 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -333,8 +333,10 @@ static bool buttons_context_path_material(ButsContextPath *path) if (ob && OB_TYPE_SUPPORT_MATERIAL(ob->type)) { ma = BKE_object_material_get(ob, ob->actcol); - RNA_id_pointer_create(&ma->id, &path->ptr[path->len]); - path->len++; + if (ma != NULL) { + RNA_id_pointer_create(&ma->id, &path->ptr[path->len]); + path->len++; + } return true; } } @@ -1113,27 +1115,11 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r /************************* Drawing the Path ************************/ -static void pin_cb(bContext *C, void *UNUSED(arg1), void *UNUSED(arg2)) -{ - SpaceProperties *sbuts = CTX_wm_space_properties(C); - - if (sbuts->flag & SB_PIN_CONTEXT) { - sbuts->pinid = buttons_context_id_path(C); - } - else { - sbuts->pinid = NULL; - } - - ED_area_tag_redraw(CTX_wm_area(C)); -} - void buttons_context_draw(const bContext *C, uiLayout *layout) { SpaceProperties *sbuts = CTX_wm_space_properties(C); ButsContextPath *path = sbuts->path; - uiLayout *row; - uiBlock *block; - uiBut *but; + uiLayout *row, *sub; PointerRNA *ptr; char namebuf[128], *name; int a, icon; @@ -1197,25 +1183,12 @@ void buttons_context_draw(const bContext *C, uiLayout *layout) uiItemSpacer(row); - block = uiLayoutGetBlock(row); - UI_block_emboss_set(block, UI_EMBOSS_NONE); - but = uiDefIconButBitC(block, - UI_BTYPE_ICON_TOGGLE, - SB_PIN_CONTEXT, - 0, - ICON_UNPINNED, - 0, - 0, - UI_UNIT_X, - UI_UNIT_Y, - &sbuts->flag, - 0, - 0, - 0, - 0, - TIP_("Follow context or keep fixed data-block displayed")); - UI_but_flag_disable(but, UI_BUT_UNDO); /* skip undo on screen buttons */ - UI_but_func_set(but, pin_cb, NULL, NULL); + sub = uiLayoutRow(row, false); + uiLayoutSetEmboss(sub, UI_EMBOSS_NONE); + uiItemO(sub, + "", + (sbuts->flag & SB_PIN_CONTEXT) ? ICON_PINNED : ICON_UNPINNED, + "BUTTONS_OT_toggle_pin"); } #ifdef USE_HEADER_CONTEXT_PATH diff --git a/source/blender/editors/space_buttons/buttons_intern.h b/source/blender/editors/space_buttons/buttons_intern.h index 911cf4526bb..a1e2b9e9aaf 100644 --- a/source/blender/editors/space_buttons/buttons_intern.h +++ b/source/blender/editors/space_buttons/buttons_intern.h @@ -93,6 +93,7 @@ extern const char *buttons_context_dir[]; /* doc access */ void buttons_texture_context_compute(const struct bContext *C, struct SpaceProperties *sbuts); /* buttons_ops.c */ +void BUTTONS_OT_toggle_pin(struct wmOperatorType *ot); void BUTTONS_OT_file_browse(struct wmOperatorType *ot); void BUTTONS_OT_directory_browse(struct wmOperatorType *ot); void BUTTONS_OT_context_menu(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index a062b178fc8..2e6ad82ef08 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -53,6 +53,47 @@ #include "buttons_intern.h" /* own include */ /* -------------------------------------------------------------------- */ +/** \name Pin ID Operator + * \{ */ + +static int toggle_pin_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceProperties *sbuts = CTX_wm_space_properties(C); + + sbuts->flag ^= SB_PIN_CONTEXT; + + /* Create the properties space pointer. */ + PointerRNA sbuts_ptr; + bScreen *screen = CTX_wm_screen(C); + RNA_pointer_create(&screen->id, &RNA_SpaceProperties, sbuts, &sbuts_ptr); + + /* Create the new ID pointer and set the the pin ID with RNA + * so we can use the property's RNA update functionality. */ + ID *new_id = (sbuts->flag & SB_PIN_CONTEXT) ? buttons_context_id_path(C) : NULL; + PointerRNA new_id_ptr; + RNA_id_pointer_create(new_id, &new_id_ptr); + RNA_pointer_set(&sbuts_ptr, "pin_id", new_id_ptr); + + ED_area_tag_redraw(CTX_wm_area(C)); + + return OPERATOR_FINISHED; +} + +void BUTTONS_OT_toggle_pin(wmOperatorType *ot) +{ + /* Identifiers. */ + ot->name = "Toggle Pin ID"; + ot->description = "Keep the current data-block displayed"; + ot->idname = "BUTTONS_OT_toggle_pin"; + + /* Callbacks. */ + ot->exec = toggle_pin_exec; + ot->poll = ED_operator_buttons_active; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ /** \name Context Menu Operator * \{ */ diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index d7cf2e4d544..3b7fe45f9c8 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -328,6 +328,7 @@ static void buttons_main_region_listener(wmWindow *UNUSED(win), static void buttons_operatortypes(void) { + WM_operatortype_append(BUTTONS_OT_toggle_pin); WM_operatortype_append(BUTTONS_OT_context_menu); WM_operatortype_append(BUTTONS_OT_file_browse); WM_operatortype_append(BUTTONS_OT_directory_browse); @@ -658,8 +659,8 @@ static void buttons_id_remap(ScrArea *UNUSED(area), SpaceLink *slink, ID *old_id if (sbuts->path) { ButsContextPath *path = sbuts->path; - int i; + int i; for (i = 0; i < path->len; i++) { if (path->ptr[i].owner_id == old_id) { break; diff --git a/source/blender/editors/space_clip/clip_buttons.c b/source/blender/editors/space_clip/clip_buttons.c index 2e7ee3498b5..f3bac697044 100644 --- a/source/blender/editors/space_clip/clip_buttons.c +++ b/source/blender/editors/space_clip/clip_buttons.c @@ -384,7 +384,6 @@ static void marker_block_handler(bContext *C, void *arg_cb, int event) } else if (event == B_MARKER_OFFSET) { float offset[2], delta[2]; - int i; offset[0] = cb->track_offset[0] / width; offset[1] = cb->track_offset[1] / height; @@ -392,7 +391,7 @@ static void marker_block_handler(bContext *C, void *arg_cb, int event) sub_v2_v2v2(delta, offset, cb->track->offset); copy_v2_v2(cb->track->offset, offset); - for (i = 0; i < cb->track->markersnr; i++) { + for (int i = 0; i < cb->track->markersnr; i++) { sub_v2_v2(cb->track->markers[i].pos, delta); } diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index e12e4eb2231..4759075555b 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -871,16 +871,11 @@ static void draw_marker_areas(SpaceClip *sc, static float get_shortest_pattern_side(MovieTrackingMarker *marker) { - int i, next; float len_sq = FLT_MAX; - for (i = 0; i < 4; i++) { - float cur_len; - - next = (i + 1) % 4; - - cur_len = len_squared_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]); - + for (int i = 0; i < 4; i++) { + int next = (i + 1) % 4; + float cur_len = len_squared_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]); len_sq = min_ff(cur_len, len_sq); } @@ -983,7 +978,6 @@ static void draw_marker_slide_zones(SpaceClip *sc, } if ((sc->flag & SC_SHOW_MARKER_PATTERN) && ((track->pat_flag & SELECT) == sel || outline)) { - int i; float pat_min[2], pat_max[2]; /* float dx = 12.0f / width, dy = 12.0f / height;*/ /* XXX UNUSED */ float tilt_ctrl[2]; @@ -993,7 +987,7 @@ static void draw_marker_slide_zones(SpaceClip *sc, } /* pattern's corners sliding squares */ - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { draw_marker_slide_square(marker->pattern_corners[i][0], marker->pattern_corners[i][1], patdx / 1.5f, @@ -1381,8 +1375,7 @@ static void draw_plane_marker_ex(SpaceClip *sc, immUniformColor3fv(selected_color); } - int i; - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { draw_marker_slide_square(plane_marker->corners[i][0], plane_marker->corners[i][1], 3.0f * px[0], diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index 83096b4eded..b2c80faec0b 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -940,11 +940,10 @@ static void start_prefetch_threads(MovieClip *clip, short *do_update, float *progress) { - PrefetchQueue queue; - TaskPool *task_pool; - int i, tot_thread = BLI_task_scheduler_num_threads(); + int tot_thread = BLI_task_scheduler_num_threads(); /* initialize queue */ + PrefetchQueue queue; BLI_spin_init(&queue.spin); queue.current_frame = current_frame; @@ -959,8 +958,8 @@ static void start_prefetch_threads(MovieClip *clip, queue.do_update = do_update; queue.progress = progress; - task_pool = BLI_task_pool_create(&queue, TASK_PRIORITY_LOW); - for (i = 0; i < tot_thread; i++) { + TaskPool *task_pool = BLI_task_pool_create(&queue, TASK_PRIORITY_LOW); + for (int i = 0; i < tot_thread; i++) { BLI_task_pool_push(task_pool, prefetch_task_func, clip, false, NULL); } BLI_task_pool_work_and_wait(task_pool); diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index 8532d8420f9..013731a50d6 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -1412,17 +1412,16 @@ static void do_sequence_proxy(void *pjv, ProxyJob *pj = pjv; MovieClip *clip = pj->clip; Scene *scene = pj->scene; - TaskPool *task_pool; int sfra = SFRA, efra = EFRA; ProxyThread *handles; - int i, tot_thread = BLI_task_scheduler_num_threads(); + int tot_thread = BLI_task_scheduler_num_threads(); int width, height; - ProxyQueue queue; if (build_undistort_count) { BKE_movieclip_get_size(clip, NULL, &width, &height); } + ProxyQueue queue; BLI_spin_init(&queue.spin); queue.cfra = sfra; @@ -1432,9 +1431,9 @@ static void do_sequence_proxy(void *pjv, queue.do_update = do_update; queue.progress = progress; - task_pool = BLI_task_pool_create(&queue, TASK_PRIORITY_LOW); + TaskPool *task_pool = BLI_task_pool_create(&queue, TASK_PRIORITY_LOW); handles = MEM_callocN(sizeof(ProxyThread) * tot_thread, "proxy threaded handles"); - for (i = 0; i < tot_thread; i++) { + for (int i = 0; i < tot_thread; i++) { ProxyThread *handle = &handles[i]; handle->clip = clip; @@ -1456,7 +1455,7 @@ static void do_sequence_proxy(void *pjv, BLI_task_pool_free(task_pool); if (build_undistort_count) { - for (i = 0; i < tot_thread; i++) { + for (int i = 0; i < tot_thread; i++) { ProxyThread *handle = &handles[i]; BKE_tracking_distortion_free(handle->distortion); } diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c index bcbf843f51c..cbf43bb7ff0 100644 --- a/source/blender/editors/space_clip/clip_utils.c +++ b/source/blender/editors/space_clip/clip_utils.c @@ -297,11 +297,8 @@ void clip_graph_tracking_iterate(SpaceClip *sc, MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking); - MovieTrackingTrack *track; - - for (track = tracksbase->first; track; track = track->next) { - int i; + LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) { if (!include_hidden && (track->flag & TRACK_HIDDEN) != 0) { continue; } @@ -310,7 +307,7 @@ void clip_graph_tracking_iterate(SpaceClip *sc, continue; } - for (i = 0; i < track->markersnr; i++) { + for (int i = 0; i < track->markersnr; i++) { MovieTrackingMarker *marker = &track->markers[i]; if (marker->flag & MARKER_DISABLED) { diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index 177a0bc2bcf..05fa7a6b587 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -511,7 +511,6 @@ static int mouse_to_tilt_distance_squared(const MovieTrackingMarker *marker, static bool slide_check_corners(float (*corners)[2]) { - int i, next, prev; float cross = 0.0f; const float p[2] = {0.0f, 0.0f}; @@ -519,16 +518,16 @@ static bool slide_check_corners(float (*corners)[2]) return false; } - for (i = 0; i < 4; i++) { - float v1[2], v2[2], cur_cross; + for (int i = 0; i < 4; i++) { + float v1[2], v2[2]; - next = (i + 1) % 4; - prev = (4 + i - 1) % 4; + int next = (i + 1) % 4; + int prev = (4 + i - 1) % 4; sub_v2_v2v2(v1, corners[i], corners[prev]); sub_v2_v2v2(v2, corners[next], corners[i]); - cur_cross = cross_v2v2(v1, v2); + float cur_cross = cross_v2v2(v1, v2); if (fabsf(cur_cross) > FLT_EPSILON) { if (cross == 0.0f) { diff --git a/source/blender/editors/space_clip/tracking_select.c b/source/blender/editors/space_clip/tracking_select.c index 80d0dd773b2..08b95bd46c5 100644 --- a/source/blender/editors/space_clip/tracking_select.c +++ b/source/blender/editors/space_clip/tracking_select.c @@ -546,9 +546,8 @@ static int box_select_exec(bContext *C, wmOperator *op) for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) { MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr); - int i; - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { if (BLI_rctf_isect_pt_v(&rectf, plane_marker->corners[i])) { if (select) { plane_track->flag |= SELECT; @@ -651,9 +650,8 @@ static int do_lasso_select_marker(bContext *C, for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) { MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr); - int i; - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { float screen_co[2]; /* marker in screen coords */ @@ -812,9 +810,8 @@ static int circle_select_exec(bContext *C, wmOperator *op) for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) { if ((plane_track->flag & PLANE_TRACK_HIDDEN) == 0) { MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_get(plane_track, framenr); - int i; - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { if (point_inside_ellipse(plane_marker->corners[i], offset, ellipse)) { if (select) { plane_track->flag |= SELECT; diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 44131693628..b459c02d9e5 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -39,6 +39,7 @@ struct View2D; void file_calc_previews(const bContext *C, ARegion *region); void file_draw_list(const bContext *C, ARegion *region); +void file_draw_check_ex(bContext *C, struct ScrArea *area); void file_draw_check(bContext *C); void file_draw_check_cb(bContext *C, void *arg1, void *arg2); bool file_draw_check_exists(SpaceFile *sfile); @@ -80,13 +81,13 @@ void file_filename_enter_handle(bContext *C, void *arg_unused, void *arg_but); int file_highlight_set(struct SpaceFile *sfile, struct ARegion *region, int mx, int my); void file_sfile_filepath_set(struct SpaceFile *sfile, const char *filepath); -void file_sfile_to_operator_ex(bContext *C, +void file_sfile_to_operator_ex(struct Main *bmain, struct wmOperator *op, struct SpaceFile *sfile, char *filepath); -void file_sfile_to_operator(bContext *C, struct wmOperator *op, struct SpaceFile *sfile); +void file_sfile_to_operator(struct Main *bmain, struct wmOperator *op, struct SpaceFile *sfile); -void file_operator_to_sfile(bContext *C, struct SpaceFile *sfile, struct wmOperator *op); +void file_operator_to_sfile(struct Main *bmain, struct SpaceFile *sfile, struct wmOperator *op); /* filesel.c */ void fileselect_file_set(SpaceFile *sfile, const int index); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 8c4b2a1b8a6..b3587fc7f97 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1432,9 +1432,8 @@ void FILE_OT_cancel(struct wmOperatorType *ot) /** \name Operator Utilities * \{ */ -void file_sfile_to_operator_ex(bContext *C, wmOperator *op, SpaceFile *sfile, char *filepath) +void file_sfile_to_operator_ex(Main *bmain, wmOperator *op, SpaceFile *sfile, char *filepath) { - Main *bmain = CTX_data_main(C); PropertyRNA *prop; /* XXX, not real length */ @@ -1507,16 +1506,15 @@ void file_sfile_to_operator_ex(bContext *C, wmOperator *op, SpaceFile *sfile, ch } } } -void file_sfile_to_operator(bContext *C, wmOperator *op, SpaceFile *sfile) +void file_sfile_to_operator(Main *bmain, wmOperator *op, SpaceFile *sfile) { - char filepath[FILE_MAX]; + char filepath_dummy[FILE_MAX]; - file_sfile_to_operator_ex(C, op, sfile, filepath); + file_sfile_to_operator_ex(bmain, op, sfile, filepath_dummy); } -void file_operator_to_sfile(bContext *C, SpaceFile *sfile, wmOperator *op) +void file_operator_to_sfile(Main *bmain, SpaceFile *sfile, wmOperator *op) { - Main *bmain = CTX_data_main(C); PropertyRNA *prop; /* If neither of the above are set, split the filepath back */ @@ -1569,25 +1567,37 @@ void file_sfile_filepath_set(SpaceFile *sfile, const char *filepath) } } -void file_draw_check(bContext *C) +void file_draw_check_ex(bContext *C, ScrArea *area) { - SpaceFile *sfile = CTX_wm_space_file(C); + /* May happen when manipulating non-active spaces. */ + if (UNLIKELY(area->spacetype != SPACE_FILE)) { + return; + } + SpaceFile *sfile = area->spacedata.first; wmOperator *op = sfile->op; if (op) { /* fail on reload */ if (op->type->check) { - file_sfile_to_operator(C, op, sfile); + Main *bmain = CTX_data_main(C); + file_sfile_to_operator(bmain, op, sfile); /* redraw */ if (op->type->check(C, op)) { - file_operator_to_sfile(C, sfile, op); + file_operator_to_sfile(bmain, sfile, op); /* redraw, else the changed settings wont get updated */ - ED_area_tag_redraw(CTX_wm_area(C)); + ED_area_tag_redraw(area); } } } } +void file_draw_check(bContext *C) +{ + SpaceFile *sfile = CTX_wm_space_file(C); + ScrArea *area = CTX_wm_area(C); + file_draw_check_ex(C, area); +} + /* for use with; UI_block_func_set */ void file_draw_check_cb(bContext *C, void *UNUSED(arg1), void *UNUSED(arg2)) { @@ -1675,7 +1685,7 @@ static int file_exec(bContext *C, wmOperator *exec_op) sfile->op = NULL; - file_sfile_to_operator_ex(C, op, sfile, filepath); + file_sfile_to_operator_ex(bmain, op, sfile, filepath); if (BLI_exists(sfile->params->dir)) { fsmenu_insert_entry(ED_fsmenu_get(), @@ -2091,6 +2101,7 @@ void FILE_OT_smoothscroll(wmOperatorType *ot) static int filepath_drop_exec(bContext *C, wmOperator *op) { + Main *bmain = CTX_data_main(C); SpaceFile *sfile = CTX_wm_space_file(C); if (sfile) { @@ -2105,7 +2116,7 @@ static int filepath_drop_exec(bContext *C, wmOperator *op) file_sfile_filepath_set(sfile, filepath); if (sfile->op) { - file_sfile_to_operator(C, sfile->op, sfile); + file_sfile_to_operator(bmain, sfile->op, sfile); file_draw_check(C); } diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 0ade50814e0..5f0e6c8361e 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -943,11 +943,9 @@ void filelist_init_icons(void) void filelist_free_icons(void) { - int i; - BLI_assert(G.background == false); - for (i = 0; i < SPECIAL_IMG_MAX; i++) { + for (int i = 0; i < SPECIAL_IMG_MAX; i++) { IMB_freeImBuf(gSpecialFileImages[i]); gSpecialFileImages[i] = NULL; } diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 88c8c6b2939..9fc4e8936f4 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -828,13 +828,23 @@ FileLayout *ED_fileselect_get_layout(struct SpaceFile *sfile, ARegion *region) return sfile->layout; } -void ED_file_change_dir(bContext *C) +/** + * Support updating the directory even when this isn't the active space + * needed so RNA properties update function isn't context sensitive, see T70255. + */ +void ED_file_change_dir_ex(bContext *C, bScreen *screen, ScrArea *area) { - wmWindowManager *wm = CTX_wm_manager(C); - SpaceFile *sfile = CTX_wm_space_file(C); - + /* May happen when manipulating non-active spaces. */ + if (UNLIKELY(area->spacetype != SPACE_FILE)) { + return; + } + SpaceFile *sfile = area->spacedata.first; if (sfile->params) { - ED_fileselect_clear(wm, CTX_data_scene(C), sfile); + wmWindowManager *wm = CTX_wm_manager(C); + Scene *scene = WM_windows_scene_get_from_screen(wm, screen); + if (LIKELY(scene != NULL)) { + ED_fileselect_clear(wm, scene, sfile); + } /* Clear search string, it is very rare to want to keep that filter while changing dir, * and usually very annoying to keep it actually! */ @@ -853,23 +863,28 @@ void ED_file_change_dir(bContext *C) folderlist_pushdir(sfile->folders_prev, sfile->params->dir); - file_draw_check(C); + file_draw_check_ex(C, area); } } +void ED_file_change_dir(bContext *C) +{ + bScreen *screen = CTX_wm_screen(C); + ScrArea *area = CTX_wm_area(C); + ED_file_change_dir_ex(C, screen, area); +} + int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matched_file) { int match = 0; - int i; - FileDirEntry *file; int n = filelist_files_ensure(sfile->files); /* select any file that matches the pattern, this includes exact match * if the user selects a single file by entering the filename */ - for (i = 0; i < n; i++) { - file = filelist_file(sfile->files, i); + for (int i = 0; i < n; i++) { + FileDirEntry *file = filelist_file(sfile->files, i); /* Do not check whether file is a file or dir here! Causes T44243 * (we do accept dirs at this stage). */ if (fnmatch(pattern, file->relpath, 0) == 0) { @@ -941,9 +956,8 @@ int autocomplete_file(struct bContext *C, char *str, void *UNUSED(arg_v)) if (str[0] && sfile->files) { AutoComplete *autocpl = UI_autocomplete_begin(str, FILE_MAX); int nentries = filelist_files_ensure(sfile->files); - int i; - for (i = 0; i < nentries; i++) { + for (int i = 0; i < nentries; i++) { FileDirEntry *file = filelist_file(sfile->files, i); UI_autocomplete_update_name(autocpl, file->relpath); } diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index 0b3c98a392e..329b5fe67fd 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -645,11 +645,10 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) wchar_t wline[FILE_MAXDIR]; __int64 tmp; char tmps[4], *name; - int i; tmp = GetLogicalDrives(); - for (i = 0; i < 26; i++) { + for (int i = 0; i < 26; i++) { if ((tmp >> i) & 1) { tmps[0] = 'A' + i; tmps[1] = ':'; diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index 70d29b52630..a99fcf60b23 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -500,11 +500,7 @@ static void draw_fcurve_samples(SpaceGraph *sipo, ARegion *region, FCurve *fcu) static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2d, uint pos) { SpaceGraph *sipo = (SpaceGraph *)ac->sl; - float samplefreq; - float stime, etime; - float unitFac, offset; short mapping_flag = ANIM_get_normalization_flags(ac); - int i, n; /* when opening a blend file on a different sized screen or while dragging the toolbar this can * happen best just bail out in this case. */ @@ -517,7 +513,9 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2 fcurve_for_draw.driver = NULL; /* compute unit correction factor */ - unitFac = ANIM_unit_mapping_get_factor(ac->scene, id, &fcurve_for_draw, mapping_flag, &offset); + float offset; + float unitFac = ANIM_unit_mapping_get_factor( + ac->scene, id, &fcurve_for_draw, mapping_flag, &offset); /* Note about sampling frequency: * Ideally, this is chosen such that we have 1-2 pixels = 1 segment @@ -535,7 +533,7 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2 /* TODO: perhaps we should have 1.0 frames * as upper limit so that curves don't get too distorted? */ float pixels_per_sample = 1.5f; - samplefreq = pixels_per_sample / UI_view2d_scale_get_x(v2d); + float samplefreq = pixels_per_sample / UI_view2d_scale_get_x(v2d); if (sipo->flag & SIPO_BEAUTYDRAW_OFF) { /* Low Precision = coarse lower-bound clamping @@ -559,20 +557,21 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2 } /* the start/end times are simply the horizontal extents of the 'cur' rect */ - stime = v2d->cur.xmin; - etime = v2d->cur.xmax + samplefreq; /* + samplefreq here so that last item gets included... */ + float stime = v2d->cur.xmin; + float etime = v2d->cur.xmax + + samplefreq; /* + samplefreq here so that last item gets included... */ /* at each sampling interval, add a new vertex * - apply the unit correction factor to the calculated values so that * the displayed values appear correctly in the viewport */ - n = roundf((etime - stime) / samplefreq); + int n = roundf((etime - stime) / samplefreq); if (n > 0) { immBegin(GPU_PRIM_LINE_STRIP, (n + 1)); - for (i = 0; i <= n; i++) { + for (int i = 0; i <= n; i++) { float ctime = stime + i * samplefreq; immVertex2f(pos, ctime, (evaluate_fcurve(&fcurve_for_draw, ctime) + offset) * unitFac); } diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index 058436a46bf..85d153feb4c 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -865,7 +865,7 @@ void draw_image_main(const bContext *C, ARegion *region) Image *ima; ImBuf *ibuf; float zoomx, zoomy; - bool show_viewer, show_render, show_paint, show_stereo3d, show_multilayer; + bool show_viewer, show_stereo3d, show_multilayer; void *lock; /* XXX can we do this in refresh? */ @@ -898,9 +898,6 @@ void draw_image_main(const bContext *C, ARegion *region) } show_viewer = (ima && ima->source == IMA_SRC_VIEWER) != 0; - show_render = (show_viewer && ima->type == IMA_TYPE_R_RESULT) != 0; - show_paint = (ima && (sima->mode == SI_MODE_PAINT) && (show_viewer == false) && - (show_render == false)); show_stereo3d = (ima && BKE_image_is_stereo(ima) && (sima->iuser.flag & IMA_SHOW_STEREO)); show_multilayer = ima && BKE_image_is_multilayer(ima); @@ -998,16 +995,32 @@ void draw_image_main(const bContext *C, ARegion *region) } draw_udim_tile_grids(region, sima, ima); - - /* paint helpers */ - if (show_paint) { - draw_image_paint_helpers(C, region, scene, zoomx, zoomy); - } + draw_image_main_helpers(C, region); if (show_viewer) { BLI_thread_unlock(LOCK_DRAW_IMAGE); } +} + +void draw_image_main_helpers(const bContext *C, ARegion *region) +{ + SpaceImage *sima = CTX_wm_space_image(C); + Scene *scene = CTX_data_scene(C); + Image *ima; + float zoomx, zoomy; + bool show_viewer, show_render, show_paint; + ima = ED_space_image(sima); + ED_space_image_get_zoom(sima, region, &zoomx, &zoomy); + + show_viewer = (ima && ima->source == IMA_SRC_VIEWER) != 0; + show_render = (show_viewer && ima->type == IMA_TYPE_R_RESULT) != 0; + show_paint = (ima && (sima->mode == SI_MODE_PAINT) && (show_viewer == false) && + (show_render == false)); + /* paint helpers */ + if (show_paint) { + draw_image_paint_helpers(C, region, scene, zoomx, zoomy); + } /* render info */ if (ima && show_render) { draw_render_info(C, sima->iuser.scene, ima, region, zoomx, zoomy); diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h index e6f5988aed8..100556ad29a 100644 --- a/source/blender/editors/space_image/image_intern.h +++ b/source/blender/editors/space_image/image_intern.h @@ -37,6 +37,7 @@ extern const char *image_context_dir[]; /* doc access */ /* image_draw.c */ void draw_image_main(const struct bContext *C, struct ARegion *region); +void draw_image_main_helpers(const struct bContext *C, struct ARegion *region); void draw_image_cache(const struct bContext *C, struct ARegion *region); void draw_image_grease_pencil(struct bContext *C, bool onlyv2d); void draw_image_sample_line(struct SpaceImage *sima); diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index aa3f6446d51..f1becd5f027 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -76,6 +76,7 @@ #include "GPU_framebuffer.h" #include "GPU_viewport.h" +#include "DRW_engine.h" #include "DRW_engine_types.h" #include "image_intern.h" @@ -638,8 +639,6 @@ static void image_main_region_draw(const bContext *C, ARegion *region) Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); View2D *v2d = ®ion->v2d; - // View2DScrollers *scrollers; - float col[3]; GPUViewport *viewport = WM_draw_region_get_viewport(region); GPUFrameBuffer *framebuffer_default, *framebuffer_overlay; @@ -647,35 +646,14 @@ static void image_main_region_draw(const bContext *C, ARegion *region) framebuffer_default = GPU_viewport_framebuffer_default_get(viewport); framebuffer_overlay = GPU_viewport_framebuffer_overlay_get(viewport); - GPU_framebuffer_bind(framebuffer_default); - GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f); - - GPU_framebuffer_bind(framebuffer_overlay); - /* XXX not supported yet, disabling for now */ scene->r.scemode &= ~R_COMP_CROP; - /* clear and setup matrix */ - UI_GetThemeColor3fv(TH_BACK, col); - srgb_to_linearrgb_v3_v3(col, col); - GPU_clear_color(col[0], col[1], col[2], 1.0f); - GPU_depth_test(GPU_DEPTH_NONE); - image_user_refresh_scene(C, sima); /* we set view2d from own zoom and offset each time */ image_main_region_set_view2d(sima, region); - /* we draw image in pixelspace */ - draw_image_main(C, region); - - /* and uvs in 0.0-1.0 space */ - UI_view2d_view_ortho(v2d); - - ED_region_draw_cb_draw(C, region, REGION_DRAW_PRE_VIEW); - - ED_uvedit_draw_main(sima, scene, view_layer, obedit, obact, depsgraph); - /* check for mask (delay draw) */ if (ED_space_image_show_uvedit(sima, obedit)) { show_uvedit = true; @@ -687,21 +665,52 @@ static void image_main_region_draw(const bContext *C, ARegion *region) show_curve = true; } - ED_region_draw_cb_draw(C, region, REGION_DRAW_POST_VIEW); + /* we draw image in pixelspace */ + if (!U.experimental.use_image_editor_legacy_drawing) { + DRW_draw_view(C); + draw_image_main_helpers(C, region); - if (sima->flag & SI_SHOW_GPENCIL) { - /* Grease Pencil too (in addition to UV's) */ - draw_image_grease_pencil((bContext *)C, true); + /* sample line */ + UI_view2d_view_ortho(v2d); + draw_image_sample_line(sima); + UI_view2d_view_restore(C); } + else { + GPU_framebuffer_bind(framebuffer_default); + GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f); + + GPU_framebuffer_bind(framebuffer_overlay); + + float col[3]; + /* clear and setup matrix */ + UI_GetThemeColor3fv(TH_BACK, col); + srgb_to_linearrgb_v3_v3(col, col); + GPU_clear_color(col[0], col[1], col[2], 1.0f); + GPU_depth_test(GPU_DEPTH_NONE); + draw_image_main(C, region); + + /* and uvs in 0.0-1.0 space */ + UI_view2d_view_ortho(v2d); + + ED_region_draw_cb_draw(C, region, REGION_DRAW_PRE_VIEW); - /* sample line */ - draw_image_sample_line(sima); + ED_uvedit_draw_main(sima, scene, view_layer, obedit, obact, depsgraph); - UI_view2d_view_restore(C); + ED_region_draw_cb_draw(C, region, REGION_DRAW_POST_VIEW); - if (sima->flag & SI_SHOW_GPENCIL) { - /* draw Grease Pencil - screen space only */ - draw_image_grease_pencil((bContext *)C, false); + if (sima->flag & SI_SHOW_GPENCIL) { + /* Grease Pencil too (in addition to UV's) */ + draw_image_grease_pencil((bContext *)C, true); + } + /* sample line */ + draw_image_sample_line(sima); + + UI_view2d_view_restore(C); + + if (sima->flag & SI_SHOW_GPENCIL) { + /* draw Grease Pencil - screen space only */ + draw_image_grease_pencil((bContext *)C, false); + } } if (mask) { @@ -741,7 +750,7 @@ static void image_main_region_draw(const bContext *C, ARegion *region) C); } - if (show_uvedit || mask || show_curve) { + if ((show_uvedit || mask || show_curve) && U.experimental.use_image_editor_legacy_drawing) { UI_view2d_view_ortho(v2d); ED_image_draw_cursor(region, sima->cursor); UI_view2d_view_restore(C); diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c index 68f4bd0ff38..f8382a17c59 100644 --- a/source/blender/editors/space_node/node_add.c +++ b/source/blender/editors/space_node/node_add.c @@ -100,12 +100,10 @@ static bool add_reroute_intersect_check(bNodeLink *link, float result[2]) { float coord_array[NODE_LINK_RESOL + 1][2]; - int i, b; if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { - - for (i = 0; i < tot - 1; i++) { - for (b = 0; b < NODE_LINK_RESOL; b++) { + for (int i = 0; i < tot - 1; i++) { + for (int b = 0; b < NODE_LINK_RESOL; b++) { if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) { result[0] = (mcoords[i][0] + mcoords[i + 1][0]) / 2.0f; result[1] = (mcoords[i][1] + mcoords[i + 1][1]) / 2.0f; diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c index a09c70b794a..57fd84a4521 100644 --- a/source/blender/editors/space_node/node_relationships.c +++ b/source/blender/editors/space_node/node_relationships.c @@ -322,7 +322,7 @@ static void snode_autoconnect(Main *bmain, ListBase *nodelist = MEM_callocN(sizeof(ListBase), "items_list"); bNodeListItem *nli; bNode *node; - int i, numlinks = 0; + int numlinks = 0; for (node = ntree->nodes.first; node; node = node->next) { if (node->flag & NODE_SELECT) { @@ -376,7 +376,7 @@ static void snode_autoconnect(Main *bmain, /* no selected inputs, connect by finding suitable match */ int num_inputs = BLI_listbase_count(&node_to->inputs); - for (i = 0; i < num_inputs; i++) { + for (int i = 0; i < num_inputs; i++) { /* find the best guess input socket */ sock_to = best_socket_input(ntree, node_to, i, replace); @@ -1007,12 +1007,10 @@ void NODE_OT_link_make(wmOperatorType *ot) static bool cut_links_intersect(bNodeLink *link, const float mcoords[][2], int tot) { float coord_array[NODE_LINK_RESOL + 1][2]; - int i, b; if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { - - for (i = 0; i < tot - 1; i++) { - for (b = 0; b < NODE_LINK_RESOL; b++) { + for (int i = 0; i < tot - 1; i++) { + for (int b = 0; b < NODE_LINK_RESOL; b++) { if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) { return 1; } @@ -1536,11 +1534,10 @@ void ED_node_link_intersect_test(ScrArea *area, int test) if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { float dist = FLT_MAX; - int i; /* loop over link coords to find shortest dist to * upper left node edge of a intersected line segment */ - for (i = 0; i < NODE_LINK_RESOL; i++) { + for (int i = 0; i < NODE_LINK_RESOL; i++) { /* check if the node rect intersetcts the line from this point to next one */ if (BLI_rctf_isect_segment(&select->totr, coord_array[i], coord_array[i + 1])) { /* store the shortest distance to the upper left edge diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c index c5be96470ec..a7e2ad8fc1c 100644 --- a/source/blender/editors/space_node/node_templates.c +++ b/source/blender/editors/space_node/node_templates.c @@ -500,20 +500,20 @@ static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname) int totitems; char name[UI_MAX_NAME_STR]; const char *cur_node_name = NULL; - int i, num = 0; + int num = 0; int icon = ICON_NONE; arg->node_type = ntype; ui_node_link_items(arg, SOCK_OUT, &items, &totitems); - for (i = 0; i < totitems; i++) { + for (int i = 0; i < totitems; i++) { if (ui_compatible_sockets(items[i].socket_type, sock->type)) { num++; } } - for (i = 0; i < totitems; i++) { + for (int i = 0; i < totitems; i++) { if (!ui_compatible_sockets(items[i].socket_type, sock->type)) { continue; } diff --git a/source/blender/editors/space_outliner/outliner_dragdrop.c b/source/blender/editors/space_outliner/outliner_dragdrop.c index 94052223e39..46a5f90f6c2 100644 --- a/source/blender/editors/space_outliner/outliner_dragdrop.c +++ b/source/blender/editors/space_outliner/outliner_dragdrop.c @@ -893,6 +893,9 @@ static int outliner_item_drag_drop_invoke(bContext *C, if (outliner_item_is_co_within_close_toggle(te, view_mval[0])) { return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); } + if (outliner_is_co_within_mode_column(space_outliner, view_mval)) { + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; + } /* Scroll the view when dragging near edges, but not * when the drag goes too far outside the region. */ diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index fbef3aa07d7..3de786ddd4d 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -53,6 +53,7 @@ #include "BKE_main.h" #include "BKE_modifier.h" #include "BKE_object.h" +#include "BKE_particle.h" #include "BKE_report.h" #include "BKE_scene.h" @@ -1884,6 +1885,109 @@ static void outliner_buttons(const bContext *C, } } +static void outliner_mode_toggle_fn(bContext *C, void *tselem_poin, void *UNUSED(arg2)) +{ + SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); + TreeStoreElem *tselem = (TreeStoreElem *)tselem_poin; + TreeViewContext tvc; + outliner_viewcontext_init(C, &tvc); + + TreeElement *te = outliner_find_tree_element(&space_outliner->tree, tselem); + if (!te) { + return; + } + + wmWindow *win = CTX_wm_window(C); + const bool do_extend = win->eventstate->ctrl != 0; + outliner_item_mode_toggle(C, &tvc, te, do_extend); +} + +/* Draw icons for adding and removing objects from the current interation mode. */ +static void outliner_draw_mode_column_toggle(uiBlock *block, + TreeViewContext *tvc, + TreeElement *te, + TreeStoreElem *tselem, + const bool lock_object_modes) +{ + const int active_mode = tvc->obact->mode; + bool draw_active_icon = true; + + if (tselem->type == 0 && te->idcode == ID_OB) { + Object *ob = (Object *)tselem->id; + + /* When not locking object modes, objects can remain in non-object modes. For modes that do not + * allow multi-object editing, these other objects should still show be viewed as not in the + * mode. Otherwise multiple objects show the same mode icon in the outliner even though only + * one object is actually editable in the mode. */ + if (!lock_object_modes && ob != tvc->obact && !(tvc->ob_edit || tvc->ob_pose)) { + draw_active_icon = false; + } + + if (ob->type == tvc->obact->type) { + int icon; + const char *tip; + + if (draw_active_icon && ob->mode == tvc->obact->mode) { + icon = UI_mode_icon_get(active_mode); + tip = TIP_("Remove from the current mode"); + } + else { + /* Not all objects support particle systems */ + if (active_mode == OB_MODE_PARTICLE_EDIT && !psys_get_current(ob)) { + return; + } + icon = ICON_DOT; + tip = TIP_( + "Change the object in the current mode\n" + "* Ctrl to add to the current mode"); + } + + uiBut *but = uiDefIconBut(block, + UI_BTYPE_ICON_TOGGLE, + 0, + icon, + 0, + te->ys, + UI_UNIT_X, + UI_UNIT_Y, + NULL, + 0.0, + 0.0, + 0.0, + 0.0, + tip); + UI_but_func_set(but, outliner_mode_toggle_fn, tselem, NULL); + UI_but_flag_enable(but, UI_BUT_DRAG_LOCK); + + if (ID_IS_LINKED(&ob->id)) { + UI_but_disable(but, TIP_("Can't edit external library data")); + } + } + } +} + +static void outliner_draw_mode_column(const bContext *C, + uiBlock *block, + TreeViewContext *tvc, + SpaceOutliner *space_outliner, + ListBase *tree) +{ + TreeStoreElem *tselem; + const bool lock_object_modes = tvc->scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK; + + LISTBASE_FOREACH (TreeElement *, te, tree) { + tselem = TREESTORE(te); + + if (tvc->obact && tvc->obact->mode != OB_MODE_OBJECT) { + outliner_draw_mode_column_toggle(block, tvc, te, tselem, lock_object_modes); + } + + if (TSELEM_OPEN(tselem, space_outliner)) { + outliner_draw_mode_column(C, block, tvc, space_outliner, &te->subtree); + } + } +} + /* ****************************************************** */ /* Normal Drawing... */ @@ -3500,11 +3604,20 @@ static void outliner_draw_tree(bContext *C, ARegion *region, SpaceOutliner *space_outliner, const float restrict_column_width, + const bool use_mode_column, TreeElement **te_edit) { const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; int starty, startx; + /* Move the tree a unit left in view layer mode */ + short mode_column_offset = (use_mode_column && (space_outliner->outlinevis == SO_SCENES)) ? + UI_UNIT_X : + 0; + if (!use_mode_column && (space_outliner->outlinevis == SO_VIEW_LAYER)) { + mode_column_offset -= UI_UNIT_X; + } + GPU_blend(GPU_BLEND_ALPHA); /* Only once. */ if (space_outliner->outlinevis == SO_DATA_API) { @@ -3530,12 +3643,12 @@ static void outliner_draw_tree(bContext *C, /* Gray hierarchy lines. */ starty = (int)region->v2d.tot.ymax - UI_UNIT_Y / 2 - OL_Y_OFFSET; - startx = UI_UNIT_X / 2 - (U.pixelsize + 1) / 2; + startx = mode_column_offset + UI_UNIT_X / 2 - (U.pixelsize + 1) / 2; outliner_draw_hierarchy_lines(space_outliner, &space_outliner->tree, startx, &starty); /* Items themselves. */ starty = (int)region->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET; - startx = 0; + startx = mode_column_offset; LISTBASE_FOREACH (TreeElement *, te, &space_outliner->tree) { outliner_draw_tree_element(C, block, @@ -3658,12 +3771,22 @@ void draw_outliner(const bContext *C) /* set matrix for 2d-view controls */ UI_view2d_view_ortho(v2d); + /* Only show mode column in View Layers and Scenes view */ + const bool use_mode_column = (space_outliner->flag & SO_MODE_COLUMN) && + (ELEM(space_outliner->outlinevis, SO_VIEW_LAYER, SO_SCENES)); + /* draw outliner stuff (background, hierarchy lines and names) */ const float restrict_column_width = outliner_restrict_columns_width(space_outliner); outliner_back(region); block = UI_block_begin(C, region, __func__, UI_EMBOSS); - outliner_draw_tree( - (bContext *)C, block, &tvc, region, space_outliner, restrict_column_width, &te_edit); + outliner_draw_tree((bContext *)C, + block, + &tvc, + region, + space_outliner, + restrict_column_width, + use_mode_column, + &te_edit); /* Compute outliner dimensions after it has been drawn. */ int tree_width, tree_height; @@ -3698,6 +3821,11 @@ void draw_outliner(const bContext *C) props_active); } + /* Draw mode icons */ + if (use_mode_column) { + outliner_draw_mode_column(C, block, &tvc, space_outliner, &space_outliner->tree); + } + UI_block_emboss_set(block, UI_EMBOSS); /* Draw edit buttons if necessary. */ diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index ad7346a5651..dea67a8678d 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -286,61 +286,6 @@ void OUTLINER_OT_item_openclose(wmOperatorType *ot) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Object Mode Enter/Exit Utilities - * \{ */ - -static void item_object_mode_enter_exit(bContext *C, ReportList *reports, Object *ob, bool enter) -{ - ViewLayer *view_layer = CTX_data_view_layer(C); - Object *obact = OBACT(view_layer); - - if ((ob->type != obact->type) || ID_IS_LINKED(ob->data)) { - return; - } - if (((ob->mode & obact->mode) != 0) == enter) { - return; - } - - if (ob == obact) { - BKE_report(reports, RPT_WARNING, "Active object mode not changed"); - return; - } - - Base *base = BKE_view_layer_base_find(view_layer, ob); - if (base == NULL) { - return; - } - Scene *scene = CTX_data_scene(C); - outliner_object_mode_toggle(C, scene, view_layer, base); -} - -void item_object_mode_enter_fn(bContext *C, - ReportList *reports, - Scene *UNUSED(scene), - TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), - TreeStoreElem *tselem, - void *UNUSED(user_data)) -{ - Object *ob = (Object *)tselem->id; - item_object_mode_enter_exit(C, reports, ob, true); -} - -void item_object_mode_exit_fn(bContext *C, - ReportList *reports, - Scene *UNUSED(scene), - TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), - TreeStoreElem *tselem, - void *UNUSED(user_data)) -{ - Object *ob = (Object *)tselem->id; - item_object_mode_enter_exit(C, reports, ob, false); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Rename Operator * \{ */ @@ -492,7 +437,8 @@ static void id_delete(bContext *C, ReportList *reports, TreeElement *te, TreeSto Main *bmain = CTX_data_main(C); ID *id = tselem->id; - BLI_assert(te->idcode != 0 && id != NULL); + BLI_assert(id != NULL); + BLI_assert((tselem->type == 0 && te->idcode != 0) || tselem->type == TSE_LAYER_COLLECTION); UNUSED_VARS_NDEBUG(te); if (te->idcode == ID_LI && ((Library *)id)->parent != NULL) { diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h index 7e7fdf4bab2..88080218e7f 100644 --- a/source/blender/editors/space_outliner/outliner_intern.h +++ b/source/blender/editors/space_outliner/outliner_intern.h @@ -222,7 +222,6 @@ typedef enum TreeItemSelectAction { OL_ITEM_ACTIVATE = (1 << 2), /* Activate the item */ OL_ITEM_EXTEND = (1 << 3), /* Extend the current selection */ OL_ITEM_RECURSIVE = (1 << 4), /* Select recursively */ - OL_ITEM_TOGGLE_MODE = (1 << 5) /* Temporary */ } TreeItemSelectAction; /* outliner_tree.c ----------------------------------------------- */ @@ -282,13 +281,14 @@ void outliner_item_select(struct bContext *C, struct TreeElement *te, const short select_flag); -void outliner_object_mode_toggle(struct bContext *C, - Scene *scene, - ViewLayer *view_layer, - Base *base); - bool outliner_item_is_co_over_name_icons(const TreeElement *te, float view_co_x); bool outliner_item_is_co_within_close_toggle(const TreeElement *te, float view_co_x); +bool outliner_is_co_within_mode_column(SpaceOutliner *space_outliner, const float view_mval[2]); + +void outliner_item_mode_toggle(struct bContext *C, + TreeViewContext *tvc, + TreeElement *te, + const bool do_extend); /* outliner_edit.c ---------------------------------------------- */ typedef void (*outliner_operation_fn)(struct bContext *C, diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c index 266ea293d43..61228e24ed9 100644 --- a/source/blender/editors/space_outliner/outliner_select.c +++ b/source/blender/editors/space_outliner/outliner_select.c @@ -64,6 +64,7 @@ #include "ED_undo.h" #include "WM_api.h" +#include "WM_toolsystem.h" #include "WM_types.h" #include "UI_interface.h" @@ -74,187 +75,91 @@ #include "outliner_intern.h" -static bool do_outliner_activate_common(bContext *C, - Main *bmain, - Depsgraph *depsgraph, - Scene *scene, - ViewLayer *view_layer, - Base *base, - const bool extend, - const bool do_exit) +static void do_outliner_item_editmode_toggle(bContext *C, Scene *scene, Base *base) { - bool use_all = false; - - if (do_exit) { - FOREACH_OBJECT_BEGIN (view_layer, ob_iter) { - ED_object_mode_generic_exit(bmain, depsgraph, scene, ob_iter); - } - FOREACH_OBJECT_END; - } - - /* Just like clicking in the object changes the active object, - * clicking on the object data should change it as well. */ - ED_object_base_activate(C, base); + Main *bmain = CTX_data_main(C); + Object *ob = base->object; - if (extend) { - use_all = true; + if (BKE_object_is_in_editmode(ob)) { + ED_object_editmode_exit_ex(bmain, scene, ob, EM_FREEDATA); + WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL); } else { - ED_object_base_deselect_all(view_layer, NULL, SEL_DESELECT); + ED_object_editmode_enter_ex(CTX_data_main(C), scene, ob, EM_NO_CONTEXT); + WM_event_add_notifier(C, NC_SCENE | ND_MODE, NULL); } - - return use_all; } -/** - * Bring the newly selected object into edit mode. - * - * If extend is used, we try to have the other compatible selected objects in the new mode as well. - * Otherwise only the new object will be active, selected and in the edit mode. - */ -static void do_outliner_item_editmode_toggle( - bContext *C, Scene *scene, ViewLayer *view_layer, Base *base, const bool extend) +static void do_outliner_item_posemode_toggle(bContext *C, Base *base) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - Object *obact = OBACT(view_layer); Object *ob = base->object; - bool use_all = false; - if (obact == NULL) { - ED_object_base_activate(C, base); - DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); - WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); - obact = ob; - use_all = true; - } - else if (obact->data == ob->data) { - use_all = true; + if (ID_IS_LINKED(ob)) { + BKE_report(CTX_wm_reports(C), RPT_WARNING, "Cannot pose libdata"); } - else if (obact->mode == OB_MODE_OBJECT) { - use_all = do_outliner_activate_common( - C, bmain, depsgraph, scene, view_layer, base, extend, false); - } - else if ((ob->type != obact->type) || ((obact->mode & OB_MODE_EDIT) == 0) || - ((obact->mode & OB_MODE_POSE) && ELEM(OB_ARMATURE, ob->type, obact->type)) || !extend) { - use_all = do_outliner_activate_common( - C, bmain, depsgraph, scene, view_layer, base, extend, true); - } - - if (use_all) { - WM_operator_name_call(C, "OBJECT_OT_editmode_toggle", WM_OP_INVOKE_REGION_WIN, NULL); + else if (ob->mode & OB_MODE_POSE) { + ED_object_posemode_exit_ex(bmain, ob); + WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL); } else { - bool ok; - if (BKE_object_is_in_editmode(ob)) { - ok = ED_object_editmode_exit_ex(bmain, scene, ob, EM_FREEDATA); - } - else { - ok = ED_object_editmode_enter_ex(CTX_data_main(C), scene, ob, EM_NO_CONTEXT); - } - if (ok) { - ED_object_base_select(base, (ob->mode & OB_MODE_EDIT) ? BA_SELECT : BA_DESELECT); - DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); - WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); - } + ED_object_posemode_enter_ex(bmain, ob); + WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_POSE, NULL); } } -static void do_outliner_item_posemode_toggle( - bContext *C, Scene *scene, ViewLayer *view_layer, Base *base, const bool extend) +/* Swap the current active object from the interaction mode with the given base. */ +static void do_outliner_item_mode_toggle_generic(bContext *C, TreeViewContext *tvc, Base *base) { Main *bmain = CTX_data_main(C); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - Object *obact = OBACT(view_layer); - Object *ob = base->object; - bool use_all = false; - - if (obact == NULL) { - ED_object_base_activate(C, base); - DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); - WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); - obact = ob; - use_all = true; - } - else if (obact->data == ob->data) { - use_all = true; - } - else if (obact->mode == OB_MODE_OBJECT) { - use_all = do_outliner_activate_common( - C, bmain, depsgraph, scene, view_layer, base, extend, false); - } - else if ((!ELEM(ob->type, obact->type)) || - ((obact->mode & OB_MODE_EDIT) && ELEM(OB_ARMATURE, ob->type, obact->type))) { - use_all = do_outliner_activate_common( - C, bmain, depsgraph, scene, view_layer, base, extend, true); - } + const int active_mode = tvc->obact->mode; - if (use_all) { - WM_operator_name_call(C, "OBJECT_OT_posemode_toggle", WM_OP_INVOKE_REGION_WIN, NULL); + /* Return all objects to object mode. */ + FOREACH_OBJECT_BEGIN (tvc->view_layer, ob_iter) { + ED_object_mode_generic_exit(bmain, depsgraph, tvc->scene, ob_iter); } - else { - bool ok = false; - - if (ID_IS_LINKED(ob)) { - BKE_report(CTX_wm_reports(C), RPT_WARNING, "Cannot pose libdata"); - } - else if (ob->mode & OB_MODE_POSE) { - ok = ED_object_posemode_exit_ex(bmain, ob); - } - else { - ok = ED_object_posemode_enter_ex(bmain, ob); - } + FOREACH_OBJECT_END; + WM_toolsystem_update_from_context_view3d(C); - if (ok) { - ED_object_base_select(base, (ob->mode & OB_MODE_POSE) ? BA_SELECT : BA_DESELECT); - - DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); - WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL); - WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); - } - } -} + Base *base_active = BKE_view_layer_base_find(tvc->view_layer, tvc->obact); + if (base_active != base) { + ED_object_base_select(base_active, BA_DESELECT); + ED_object_base_activate(C, base); + ED_object_base_select(base, BA_SELECT); -/* For draw callback to run mode switching */ -void outliner_object_mode_toggle(bContext *C, Scene *scene, ViewLayer *view_layer, Base *base) -{ - Object *obact = OBACT(view_layer); - if (obact->mode & OB_MODE_EDIT) { - do_outliner_item_editmode_toggle(C, scene, view_layer, base, true); - } - else if (obact->mode & OB_MODE_POSE) { - do_outliner_item_posemode_toggle(C, scene, view_layer, base, true); + /* XXX: Must add undo step between activation and setting mode to prevent an assert. */ + ED_undo_push(C, "outliner mode toggle"); + ED_object_mode_set(C, active_mode); + ED_outliner_select_sync_from_object_tag(C); } } /* Toggle the item's interaction mode if supported */ -static void outliner_item_mode_toggle(bContext *C, - TreeViewContext *tvc, - TreeElement *te, - const bool extend) +void outliner_item_mode_toggle(bContext *C, + TreeViewContext *tvc, + TreeElement *te, + const bool do_extend) { TreeStoreElem *tselem = TREESTORE(te); - if (tselem->type == 0) { - if (OB_DATA_SUPPORT_EDITMODE(te->idcode)) { - Object *ob = (Object *)outliner_search_back(te, ID_OB); - if ((ob != NULL) && (ob->data == tselem->id)) { - Base *base = BKE_view_layer_base_find(tvc->view_layer, ob); - if ((base != NULL) && (base->flag & BASE_VISIBLE_DEPSGRAPH)) { - do_outliner_item_editmode_toggle(C, tvc->scene, tvc->view_layer, base, extend); - } - } - } - else if (ELEM(te->idcode, ID_GD)) { - /* set grease pencil to object mode */ - WM_operator_name_call(C, "GPENCIL_OT_editmode_toggle", WM_OP_INVOKE_REGION_WIN, NULL); - } - } - else if (tselem->type == TSE_POSE_BASE) { + if (tselem->type == 0 && te->idcode == ID_OB) { Object *ob = (Object *)tselem->id; Base *base = BKE_view_layer_base_find(tvc->view_layer, ob); - if (base != NULL) { - do_outliner_item_posemode_toggle(C, tvc->scene, tvc->view_layer, base, extend); + + /* Hidden objects can be removed from the mode. */ + if (!base || (!(base->flag & BASE_VISIBLE_DEPSGRAPH) && (ob->mode != tvc->obact->mode))) { + return; + } + + if (!do_extend) { + do_outliner_item_mode_toggle_generic(C, tvc, base); + } + else if (tvc->ob_edit && OB_TYPE_SUPPORT_EDITMODE(ob->type)) { + do_outliner_item_editmode_toggle(C, tvc->scene, base); + } + else if (tvc->ob_pose && ob->type == OB_ARMATURE) { + do_outliner_item_posemode_toggle(C, base); } } } @@ -1272,11 +1177,6 @@ void outliner_item_select(bContext *C, extend, select_flag & OL_ITEM_RECURSIVE, activate_data || space_outliner->flag & SO_SYNC_SELECT); - - /* Mode toggle on data activate for now, but move later */ - if (select_flag & OL_ITEM_TOGGLE_MODE) { - outliner_item_mode_toggle(C, &tvc, te, extend); - } } } @@ -1353,6 +1253,16 @@ static bool outliner_is_co_within_restrict_columns(const SpaceOutliner *space_ou return (view_co_x > region->v2d.cur.xmax - outliner_restrict_columns_width(space_outliner)); } +bool outliner_is_co_within_mode_column(SpaceOutliner *space_outliner, const float view_mval[2]) +{ + /* Mode toggles only show in View Layer and Scenes modes. */ + if (!ELEM(space_outliner->outlinevis, SO_VIEW_LAYER, SO_SCENES)) { + return false; + } + + return space_outliner->flag & SO_MODE_COLUMN && view_mval[0] < UI_UNIT_X; +} + /** * Action to run when clicking in the outliner, * @@ -1375,6 +1285,9 @@ static int outliner_item_do_activate_from_cursor(bContext *C, if (outliner_is_co_within_restrict_columns(space_outliner, region, view_mval[0])) { return OPERATOR_CANCELLED; } + if (outliner_is_co_within_mode_column(space_outliner, view_mval)) { + return OPERATOR_CANCELLED; + } if (!(te = outliner_find_item_at_y(space_outliner, &space_outliner->tree, view_mval[1]))) { if (deselect_all) { @@ -1413,7 +1326,7 @@ static int outliner_item_do_activate_from_cursor(bContext *C, const short select_flag = OL_ITEM_ACTIVATE | (select ? OL_ITEM_SELECT : OL_ITEM_DESELECT) | (is_over_name_icons ? OL_ITEM_SELECT_DATA : 0) | - (extend ? OL_ITEM_EXTEND : 0) | OL_ITEM_TOGGLE_MODE; + (extend ? OL_ITEM_EXTEND : 0); outliner_item_select(C, space_outliner, activate_te, select_flag); } @@ -1542,6 +1455,10 @@ static int outliner_box_select_invoke(bContext *C, wmOperator *op, const wmEvent return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; } + if (outliner_is_co_within_mode_column(space_outliner, view_mval)) { + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; + } + return WM_gesture_box_invoke(C, op, event); } diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index 01b6e636ded..0743e841794 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -95,110 +95,105 @@ /** \name ID/Library/Data Set/Un-link Utilities * \{ */ -static void set_operation_types(SpaceOutliner *space_outliner, - ListBase *lb, - int *scenelevel, - int *objectlevel, - int *idlevel, - int *datalevel) +static void get_element_operation_type( + TreeElement *te, int *scenelevel, int *objectlevel, int *idlevel, int *datalevel) { - TreeElement *te; - TreeStoreElem *tselem; + TreeStoreElem *tselem = TREESTORE(te); + if (tselem->flag & TSE_SELECTED) { + /* Layer collection points to collection ID. */ + if (!ELEM(tselem->type, 0, TSE_LAYER_COLLECTION)) { + if (*datalevel == 0) { + *datalevel = tselem->type; + } + else if (*datalevel != tselem->type) { + *datalevel = -1; + } + } + else { + const int idcode = (int)GS(tselem->id->name); + bool is_standard_id = false; + switch ((ID_Type)idcode) { + case ID_SCE: + *scenelevel = 1; + break; + case ID_OB: + *objectlevel = 1; + break; - for (te = lb->first; te; te = te->next) { - tselem = TREESTORE(te); - if (tselem->flag & TSE_SELECTED) { - /* Layer collection points to collection ID. */ - if (!ELEM(tselem->type, 0, TSE_LAYER_COLLECTION)) { - if (*datalevel == 0) { - *datalevel = tselem->type; - } - else if (*datalevel != tselem->type) { - *datalevel = -1; - } + case ID_ME: + case ID_CU: + case ID_MB: + case ID_LT: + case ID_LA: + case ID_AR: + case ID_CA: + case ID_SPK: + case ID_MA: + case ID_TE: + case ID_IP: + case ID_IM: + case ID_SO: + case ID_KE: + case ID_WO: + case ID_AC: + case ID_TXT: + case ID_GR: + case ID_LS: + case ID_LI: + case ID_VF: + case ID_NT: + case ID_BR: + case ID_PA: + case ID_GD: + case ID_MC: + case ID_MSK: + case ID_PAL: + case ID_PC: + case ID_CF: + case ID_WS: + case ID_LP: + case ID_HA: + case ID_PT: + case ID_VO: + case ID_SIM: + is_standard_id = true; + break; + case ID_WM: + case ID_SCR: + /* Those are ignored here. */ + /* Note: while Screens should be manageable here, deleting a screen used by a workspace + * will cause crashes when trying to use that workspace, so for now let's play minimal, + * safe change. */ + break; + } + if (idcode == ID_NLA) { + /* Fake one, not an actual ID type... */ + is_standard_id = true; } - else { - const int idcode = (int)GS(tselem->id->name); - bool is_standard_id = false; - switch ((ID_Type)idcode) { - case ID_SCE: - *scenelevel = 1; - break; - case ID_OB: - *objectlevel = 1; - break; - case ID_ME: - case ID_CU: - case ID_MB: - case ID_LT: - case ID_LA: - case ID_AR: - case ID_CA: - case ID_SPK: - case ID_MA: - case ID_TE: - case ID_IP: - case ID_IM: - case ID_SO: - case ID_KE: - case ID_WO: - case ID_AC: - case ID_TXT: - case ID_GR: - case ID_LS: - case ID_LI: - case ID_VF: - case ID_NT: - case ID_BR: - case ID_PA: - case ID_GD: - case ID_MC: - case ID_MSK: - case ID_PAL: - case ID_PC: - case ID_CF: - case ID_WS: - case ID_LP: - case ID_HA: - case ID_PT: - case ID_VO: - case ID_SIM: - is_standard_id = true; - break; - case ID_WM: - case ID_SCR: - /* Those are ignored here. */ - /* Note: while Screens should be manageable here, deleting a screen used by a workspace - * will cause crashes when trying to use that workspace, so for now let's play minimal, - * safe change. */ - break; + if (is_standard_id) { + if (*idlevel == 0) { + *idlevel = idcode; } - if (idcode == ID_NLA) { - /* Fake one, not an actual ID type... */ - is_standard_id = true; + else if (*idlevel != idcode) { + *idlevel = -1; } - - if (is_standard_id) { - if (*idlevel == 0) { - *idlevel = idcode; - } - else if (*idlevel != idcode) { - *idlevel = -1; - } - if (ELEM(*datalevel, TSE_VIEW_COLLECTION_BASE, TSE_SCENE_COLLECTION_BASE)) { - *datalevel = 0; - } + if (ELEM(*datalevel, TSE_VIEW_COLLECTION_BASE, TSE_SCENE_COLLECTION_BASE)) { + *datalevel = 0; } } } - if (TSELEM_OPEN(tselem, space_outliner)) { - set_operation_types( - space_outliner, &te->subtree, scenelevel, objectlevel, idlevel, datalevel); - } } } +static TreeElement *get_target_element(SpaceOutliner *space_outliner) +{ + TreeElement *te = outliner_find_element_with_flag(&space_outliner->tree, TSE_ACTIVE); + BLI_assert(te); + + return te; +} + static void unlink_action_fn(bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), @@ -405,7 +400,7 @@ static void outliner_do_libdata_operation(bContext *C, for (te = lb->first; te; te = te->next) { tselem = TREESTORE(te); if (tselem->flag & TSE_SELECTED) { - if (ELEM(tselem->type, 0, TSE_LAYER_COLLECTION)) { + if ((tselem->type == 0 && te->idcode != 0) || tselem->type == TSE_LAYER_COLLECTION) { TreeStoreElem *tsep = te->parent ? TREESTORE(te->parent) : NULL; operation_fn(C, reports, scene, te, tsep, tselem, user_data); } @@ -1492,16 +1487,6 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op) C, op->reports, scene, space_outliner, &space_outliner->tree, item_rename_fn); str = "Rename Object"; } - else if (event == OL_OP_OBJECT_MODE_ENTER) { - outliner_do_object_operation( - C, op->reports, scene, space_outliner, &space_outliner->tree, item_object_mode_enter_fn); - str = "Enter Current Mode"; - } - else if (event == OL_OP_OBJECT_MODE_EXIT) { - outliner_do_object_operation( - C, op->reports, scene, space_outliner, &space_outliner->tree, item_object_mode_exit_fn); - str = "Exit Current Mode"; - } else { BLI_assert(0); return OPERATOR_CANCELLED; @@ -1806,18 +1791,16 @@ static int outliner_id_operation_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; - eOutlinerIdOpTypes event; /* check for invalid states */ if (space_outliner == NULL) { return OPERATOR_CANCELLED; } - set_operation_types( - space_outliner, &space_outliner->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); - - event = RNA_enum_get(op->ptr, "type"); + TreeElement *te = get_target_element(space_outliner); + get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel); + eOutlinerIdOpTypes event = RNA_enum_get(op->ptr, "type"); switch (event) { case OUTLINER_IDOP_UNLINK: { /* unlink datablock from its parent */ @@ -2138,18 +2121,16 @@ static int outliner_lib_operation_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; - eOutlinerLibOpTypes event; /* check for invalid states */ if (space_outliner == NULL) { return OPERATOR_CANCELLED; } - set_operation_types( - space_outliner, &space_outliner->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); - - event = RNA_enum_get(op->ptr, "type"); + TreeElement *te = get_target_element(space_outliner); + get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel); + eOutlinerLibOpTypes event = RNA_enum_get(op->ptr, "type"); switch (event) { case OL_LIB_RENAME: { outliner_do_libdata_operation( @@ -2271,8 +2252,9 @@ static int outliner_action_set_exec(bContext *C, wmOperator *op) if (space_outliner == NULL) { return OPERATOR_CANCELLED; } - set_operation_types( - space_outliner, &space_outliner->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); + + TreeElement *te = get_target_element(space_outliner); + get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel); /* get action to use */ act = BLI_findlink(&bmain->actions, RNA_enum_get(op->ptr, "action")); @@ -2379,22 +2361,21 @@ static int outliner_animdata_operation_exec(bContext *C, wmOperator *op) wmWindowManager *wm = CTX_wm_manager(C); SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; - eOutliner_AnimDataOps event; /* check for invalid states */ if (space_outliner == NULL) { return OPERATOR_CANCELLED; } - event = RNA_enum_get(op->ptr, "type"); - set_operation_types( - space_outliner, &space_outliner->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); + TreeElement *te = get_target_element(space_outliner); + get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel); if (datalevel != TSE_ANIM_DATA) { return OPERATOR_CANCELLED; } /* perform the core operation */ + eOutliner_AnimDataOps event = RNA_enum_get(op->ptr, "type"); switch (event) { case OUTLINER_ANIMOP_CLEAR_ADT: /* Remove Animation Data - this may remove the active action, in some cases... */ @@ -2484,15 +2465,10 @@ static const EnumPropertyItem prop_constraint_op_types[] = { static int outliner_constraint_operation_exec(bContext *C, wmOperator *op) { SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); - int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; - eOutliner_PropConstraintOps event; - - event = RNA_enum_get(op->ptr, "type"); - set_operation_types( - space_outliner, &space_outliner->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); + eOutliner_PropConstraintOps event = RNA_enum_get(op->ptr, "type"); outliner_do_data_operation( - space_outliner, datalevel, event, &space_outliner->tree, constraint_fn, C); + space_outliner, TSE_CONSTRAINT, event, &space_outliner->tree, constraint_fn, C); if (event == OL_CONSTRAINTOP_DELETE) { outliner_cleanup_tree(space_outliner); @@ -2536,15 +2512,10 @@ static const EnumPropertyItem prop_modifier_op_types[] = { static int outliner_modifier_operation_exec(bContext *C, wmOperator *op) { SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); - int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; - eOutliner_PropModifierOps event; - - event = RNA_enum_get(op->ptr, "type"); - set_operation_types( - space_outliner, &space_outliner->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); + eOutliner_PropModifierOps event = RNA_enum_get(op->ptr, "type"); outliner_do_data_operation( - space_outliner, datalevel, event, &space_outliner->tree, modifier_fn, C); + space_outliner, TSE_MODIFIER, event, &space_outliner->tree, modifier_fn, C); if (event == OL_MODIFIER_OP_DELETE) { outliner_cleanup_tree(space_outliner); @@ -2591,17 +2562,16 @@ static int outliner_data_operation_exec(bContext *C, wmOperator *op) { SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; - eOutliner_PropDataOps event; /* check for invalid states */ if (space_outliner == NULL) { return OPERATOR_CANCELLED; } - event = RNA_enum_get(op->ptr, "type"); - set_operation_types( - space_outliner, &space_outliner->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); + TreeElement *te = get_target_element(space_outliner); + get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel); + eOutliner_PropDataOps event = RNA_enum_get(op->ptr, "type"); switch (datalevel) { case TSE_POSE_CHANNEL: { outliner_do_data_operation( @@ -2700,134 +2670,116 @@ static int outliner_operator_menu(bContext *C, const char *opname) } static int do_outliner_operation_event(bContext *C, + ReportList *reports, ARegion *region, SpaceOutliner *space_outliner, - TreeElement *te, - const float mval[2]) + TreeElement *te) { - ReportList *reports = CTX_wm_reports(C); /* XXX... */ + int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; + TreeStoreElem *tselem = TREESTORE(te); - if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) { - int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; - TreeStoreElem *tselem = TREESTORE(te); + int select_flag = OL_ITEM_ACTIVATE | OL_ITEM_SELECT; + if (tselem->flag & TSE_SELECTED) { + select_flag |= OL_ITEM_EXTEND; + } - /* select object that's clicked on and popup context menu */ - if (!(tselem->flag & TSE_SELECTED)) { + outliner_item_select(C, space_outliner, te, select_flag); - if (outliner_flag_is_any_test(&space_outliner->tree, TSE_SELECTED, 1)) { - outliner_flag_set(&space_outliner->tree, TSE_SELECTED, 0); - } + /* Only redraw, don't rebuild here because TreeElement pointers will + * become invalid and operations will crash. */ + ED_region_tag_redraw_no_rebuild(region); + ED_outliner_select_sync_from_outliner(C, space_outliner); - tselem->flag |= TSE_SELECTED; + get_element_operation_type(te, &scenelevel, &objectlevel, &idlevel, &datalevel); - /* Only redraw, don't rebuild here because TreeElement pointers will - * become invalid and operations will crash. */ - ED_region_tag_redraw_no_rebuild(region); - ED_outliner_select_sync_from_outliner(C, space_outliner); + if (scenelevel) { + if (objectlevel || datalevel || idlevel) { + BKE_report(reports, RPT_WARNING, "Mixed selection"); + return OPERATOR_CANCELLED; } - - set_operation_types( - space_outliner, &space_outliner->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); - - if (scenelevel) { - if (objectlevel || datalevel || idlevel) { - BKE_report(reports, RPT_WARNING, "Mixed selection"); - return OPERATOR_CANCELLED; - } - return outliner_operator_menu(C, "OUTLINER_OT_scene_operation"); - } - if (objectlevel) { - WM_menu_name_call(C, "OUTLINER_MT_object", WM_OP_INVOKE_REGION_WIN); - return OPERATOR_FINISHED; + return outliner_operator_menu(C, "OUTLINER_OT_scene_operation"); + } + if (objectlevel) { + WM_menu_name_call(C, "OUTLINER_MT_object", WM_OP_INVOKE_REGION_WIN); + return OPERATOR_FINISHED; + } + if (idlevel) { + if (idlevel == -1 || datalevel) { + BKE_report(reports, RPT_WARNING, "Mixed selection"); + return OPERATOR_CANCELLED; } - if (idlevel) { - if (idlevel == -1 || datalevel) { - BKE_report(reports, RPT_WARNING, "Mixed selection"); - return OPERATOR_CANCELLED; - } - switch (idlevel) { - case ID_GR: - WM_menu_name_call(C, "OUTLINER_MT_collection", WM_OP_INVOKE_REGION_WIN); - return OPERATOR_FINISHED; - break; - case ID_LI: - return outliner_operator_menu(C, "OUTLINER_OT_lib_operation"); - break; - default: - return outliner_operator_menu(C, "OUTLINER_OT_id_operation"); - break; - } - } - else if (datalevel) { - if (datalevel == -1) { - BKE_report(reports, RPT_WARNING, "Mixed selection"); - return OPERATOR_CANCELLED; - } - if (datalevel == TSE_ANIM_DATA) { - return outliner_operator_menu(C, "OUTLINER_OT_animdata_operation"); - } - if (datalevel == TSE_DRIVER_BASE) { - /* do nothing... no special ops needed yet */ - return OPERATOR_CANCELLED; - } - if (datalevel == TSE_LAYER_COLLECTION) { + switch (idlevel) { + case ID_GR: WM_menu_name_call(C, "OUTLINER_MT_collection", WM_OP_INVOKE_REGION_WIN); return OPERATOR_FINISHED; - } - if (ELEM(datalevel, TSE_SCENE_COLLECTION_BASE, TSE_VIEW_COLLECTION_BASE)) { - WM_menu_name_call(C, "OUTLINER_MT_collection_new", WM_OP_INVOKE_REGION_WIN); - return OPERATOR_FINISHED; - } - if (datalevel == TSE_ID_BASE) { - /* do nothing... there are no ops needed here yet */ - return 0; - } - if (datalevel == TSE_CONSTRAINT) { - return outliner_operator_menu(C, "OUTLINER_OT_constraint_operation"); - } - if (datalevel == TSE_MODIFIER) { - return outliner_operator_menu(C, "OUTLINER_OT_modifier_operation"); - } - return outliner_operator_menu(C, "OUTLINER_OT_data_operation"); + break; + case ID_LI: + return outliner_operator_menu(C, "OUTLINER_OT_lib_operation"); + break; + default: + return outliner_operator_menu(C, "OUTLINER_OT_id_operation"); + break; } - - return 0; } - - for (te = te->subtree.first; te; te = te->next) { - int retval = do_outliner_operation_event(C, region, space_outliner, te, mval); - if (retval) { - return retval; + else if (datalevel) { + if (datalevel == -1) { + BKE_report(reports, RPT_WARNING, "Mixed selection"); + return OPERATOR_CANCELLED; + } + if (datalevel == TSE_ANIM_DATA) { + return outliner_operator_menu(C, "OUTLINER_OT_animdata_operation"); + } + if (datalevel == TSE_DRIVER_BASE) { + /* do nothing... no special ops needed yet */ + return OPERATOR_CANCELLED; } + if (datalevel == TSE_LAYER_COLLECTION) { + WM_menu_name_call(C, "OUTLINER_MT_collection", WM_OP_INVOKE_REGION_WIN); + return OPERATOR_FINISHED; + } + if (ELEM(datalevel, TSE_SCENE_COLLECTION_BASE, TSE_VIEW_COLLECTION_BASE)) { + WM_menu_name_call(C, "OUTLINER_MT_collection_new", WM_OP_INVOKE_REGION_WIN); + return OPERATOR_FINISHED; + } + if (datalevel == TSE_ID_BASE) { + /* do nothing... there are no ops needed here yet */ + return 0; + } + if (datalevel == TSE_CONSTRAINT) { + return outliner_operator_menu(C, "OUTLINER_OT_constraint_operation"); + } + if (datalevel == TSE_MODIFIER) { + return outliner_operator_menu(C, "OUTLINER_OT_modifier_operation"); + } + return outliner_operator_menu(C, "OUTLINER_OT_data_operation"); } return 0; } -static int outliner_operation(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) +static int outliner_operation(bContext *C, wmOperator *op, const wmEvent *event) { ARegion *region = CTX_wm_region(C); SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); uiBut *but = UI_context_active_but_get(C); - TreeElement *te; - float fmval[2]; + float view_mval[2]; if (but) { UI_but_tooltip_timer_remove(C, but); } - UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]); + UI_view2d_region_to_view( + ®ion->v2d, event->mval[0], event->mval[1], &view_mval[0], &view_mval[1]); - for (te = space_outliner->tree.first; te; te = te->next) { - int retval = do_outliner_operation_event(C, region, space_outliner, te, fmval); - if (retval) { - return retval; - } + TreeElement *hovered_te = outliner_find_item_at_y( + space_outliner, &space_outliner->tree, view_mval[1]); + if (!hovered_te) { + /* Let this fall through to 'OUTLINER_MT_context_menu'. */ + return OPERATOR_PASS_THROUGH; } - /* Let this fall through to 'OUTLINER_MT_context_menu'. */ - return OPERATOR_PASS_THROUGH; + return do_outliner_operation_event(C, op->reports, region, space_outliner, hovered_te); } /* Menu only! Calls other operators */ diff --git a/source/blender/editors/space_outliner/space_outliner.c b/source/blender/editors/space_outliner/space_outliner.c index 6a63c3c65c3..2ed834a15dd 100644 --- a/source/blender/editors/space_outliner/space_outliner.c +++ b/source/blender/editors/space_outliner/space_outliner.c @@ -314,7 +314,7 @@ static SpaceLink *outliner_create(const ScrArea *UNUSED(area), const Scene *UNUS space_outliner->show_restrict_flags = SO_RESTRICT_ENABLE | SO_RESTRICT_HIDE; space_outliner->outlinevis = SO_VIEW_LAYER; space_outliner->sync_select_dirty |= WM_OUTLINER_SYNC_SELECT_FROM_ALL; - space_outliner->flag |= SO_SYNC_SELECT; + space_outliner->flag = SO_SYNC_SELECT | SO_MODE_COLUMN; /* header */ region = MEM_callocN(sizeof(ARegion), "header for outliner"); diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index a35feb62c9d..962c4e4c59d 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -823,7 +823,6 @@ int sequencer_image_seq_get_minmax_frame(wmOperator *op, void sequencer_image_seq_reserve_frames( wmOperator *op, StripElem *se, int len, int minframe, int numdigits) { - int i; char *filename = NULL; RNA_BEGIN (op->ptr, itemptr, "files") { filename = RNA_string_get_alloc(&itemptr, "name", NULL, 0); @@ -837,7 +836,7 @@ void sequencer_image_seq_reserve_frames( /* Strip the frame from filename and substitute with `#`. */ BLI_path_frame_strip(filename, ext); - for (i = 0; i < len; i++, se++) { + for (int i = 0; i < len; i++, se++) { BLI_strncpy(filename_stripped, filename, sizeof(filename_stripped)); BLI_path_frame(filename_stripped, minframe + i, numdigits); BLI_snprintf(se->name, sizeof(se->name), "%s%s", filename_stripped, ext); diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 70735a8ec82..662be2491a0 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -242,7 +242,6 @@ static void draw_seq_waveform(View2D *v2d, int x2_offset = min_ff(v2d->cur.xmax + 1.0f, x2); if (seq->sound && ((sseq->flag & SEQ_ALL_WAVEFORMS) || (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM))) { - int i, j, p; int length = floor((x2_offset - x1_offset) / stepsize) + 1; float ymid = (y1 + y2) / 2.0f; float yscale = (y2 - y1) / 2.0f; @@ -303,15 +302,15 @@ static void draw_seq_waveform(View2D *v2d, immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); immBegin(GPU_PRIM_TRI_STRIP, length * 2); - for (i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { float sampleoffset = startsample + ((x1_offset - x1) / stepsize + i) * samplestep; - p = sampleoffset; + int p = sampleoffset; value1 = waveform->data[p * 3]; value2 = waveform->data[p * 3 + 1]; if (samplestep > 1.0f) { - for (j = p + 1; (j < waveform->length) && (j < p + samplestep); j++) { + for (int j = p + 1; (j < waveform->length) && (j < p + samplestep); j++) { if (value1 > waveform->data[j * 3]) { value1 = waveform->data[j * 3]; } diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index f175c2a7419..e446a1a5ed7 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -1482,7 +1482,7 @@ static int sequencer_slip_invoke(bContext *C, wmOperator *op, const wmEvent *eve Scene *scene = CTX_data_scene(C); Editing *ed = BKE_sequencer_editing_get(scene, false); float mouseloc[2]; - int num_seq, i; + int num_seq; View2D *v2d = UI_view2d_fromcontext(C); /* Recursively count the trimmed elements. */ @@ -1506,7 +1506,7 @@ static int sequencer_slip_invoke(bContext *C, wmOperator *op, const wmEvent *eve slip_add_sequences_recursive(ed->seqbasep, data->seq_array, data->trim, 0, true); - for (i = 0; i < num_seq; i++) { + for (int i = 0; i < num_seq; i++) { transseq_backup(data->ts + i, data->seq_array[i]); } @@ -1611,21 +1611,19 @@ static void sequencer_slip_apply_limits(SlipData *data, int *offset) static int sequencer_slip_exec(bContext *C, wmOperator *op) { - SlipData *data; Scene *scene = CTX_data_scene(C); Editing *ed = BKE_sequencer_editing_get(scene, false); - int num_seq, i; int offset = RNA_int_get(op->ptr, "offset"); bool success = false; /* Recursively count the trimmed elements. */ - num_seq = slip_count_sequences_recursive(ed->seqbasep, true); + int num_seq = slip_count_sequences_recursive(ed->seqbasep, true); if (num_seq == 0) { return OPERATOR_CANCELLED; } - data = op->customdata = MEM_mallocN(sizeof(SlipData), "trimdata"); + SlipData *data = op->customdata = MEM_mallocN(sizeof(SlipData), "trimdata"); data->ts = MEM_mallocN(num_seq * sizeof(TransSeq), "trimdata_transform"); data->seq_array = MEM_mallocN(num_seq * sizeof(Sequence *), "trimdata_sequences"); data->trim = MEM_mallocN(num_seq * sizeof(bool), "trimdata_trim"); @@ -1633,7 +1631,7 @@ static int sequencer_slip_exec(bContext *C, wmOperator *op) slip_add_sequences_recursive(ed->seqbasep, data->seq_array, data->trim, 0, true); - for (i = 0; i < num_seq; i++) { + for (int i = 0; i < num_seq; i++) { transseq_backup(data->ts + i, data->seq_array[i]); } @@ -1749,14 +1747,13 @@ static int sequencer_slip_modal(bContext *C, wmOperator *op, const wmEvent *even case EVT_ESCKEY: case RIGHTMOUSE: { - int i; Editing *ed = BKE_sequencer_editing_get(scene, false); - for (i = 0; i < data->num_seq; i++) { + for (int i = 0; i < data->num_seq; i++) { transseq_restore(data->ts + i, data->seq_array[i]); } - for (i = 0; i < data->num_seq; i++) { + for (int i = 0; i < data->num_seq; i++) { Sequence *seq = data->seq_array[i]; BKE_sequence_reload_new_file(bmain, scene, seq, false); BKE_sequence_calc(scene, seq); diff --git a/source/blender/editors/space_sequencer/sequencer_scopes.c b/source/blender/editors/space_sequencer/sequencer_scopes.c index 58a6f274310..1639870fee2 100644 --- a/source/blender/editors/space_sequencer/sequencer_scopes.c +++ b/source/blender/editors/space_sequencer/sequencer_scopes.c @@ -123,11 +123,9 @@ static void wform_put_border(uchar *tgt, int w, int h) static void wform_put_gridrow(uchar *tgt, float perc, int w, int h) { - int i; - tgt += (int)(perc / 100.0f * h) * w * 4; - for (i = 0; i < w * 2; i++) { + for (int i = 0; i < w * 2; i++) { tgt[0] = 255; tgt += 4; @@ -415,11 +413,10 @@ static void draw_histogram_marker(ImBuf *ibuf, int x) { uchar *p = (uchar *)ibuf->rect; int barh = ibuf->y * 0.1; - int i; p += 4 * (x + ibuf->x * (ibuf->y - barh + 1)); - for (i = 0; i < barh - 1; i++) { + for (int i = 0; i < barh - 1; i++) { p[0] = p[1] = p[2] = 255; p += ibuf->x * 4; } @@ -429,11 +426,10 @@ static void draw_histogram_bar(ImBuf *ibuf, int x, float val, int col) { uchar *p = (uchar *)ibuf->rect; int barh = ibuf->y * val * 0.9f; - int i; p += 4 * (x + ibuf->x); - for (i = 0; i < barh; i++) { + for (int i = 0; i < barh; i++) { p[col] = 255; p += ibuf->x * 4; } diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c index 955b4dba5e8..96a1776d763 100644 --- a/source/blender/editors/space_sequencer/sequencer_select.c +++ b/source/blender/editors/space_sequencer/sequencer_select.c @@ -1388,9 +1388,8 @@ static bool select_grouped_effect(Editing *ed, Sequence *actseq, const int chann Sequence *seq; bool changed = false; bool effects[SEQ_TYPE_MAX + 1]; - int i; - for (i = 0; i <= SEQ_TYPE_MAX; i++) { + for (int i = 0; i <= SEQ_TYPE_MAX; i++) { effects[i] = false; } diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 688dce3c54e..2ae8d4cde7a 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -2914,9 +2914,9 @@ typedef struct SetSelection { static int flatten_width(SpaceText *st, const char *str) { - int i, total = 0; + int total = 0; - for (i = 0; str[i]; i += BLI_str_utf8_size_safe(str + i)) { + for (int i = 0; str[i]; i += BLI_str_utf8_size_safe(str + i)) { if (str[i] == '\t') { total += st->tabnumber - total % st->tabnumber; } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index da44815b31a..f3300f21628 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -905,7 +905,7 @@ void ED_view3d_grid_steps(const Scene *scene, float r_grid_steps[STEPS_LEN]) { const void *usys; - int i, len; + int len; BKE_unit_system_get(scene->unit.system, B_UNIT_LENGTH, &usys, &len); float grid_scale = v3d->grid; BLI_assert(STEPS_LEN >= len); @@ -918,6 +918,7 @@ void ED_view3d_grid_steps(const Scene *scene, grid_scale /= scene->unit.scale_length; + int i; for (i = 0; i < len; i++) { r_grid_steps[i] = (float)BKE_unit_scalar_get(usys, len - 1 - i) * grid_scale; } @@ -932,7 +933,7 @@ void ED_view3d_grid_steps(const Scene *scene, grid_scale /= powf(v3d->gridsubdiv, 3); } int subdiv = 1; - for (i = 0;; i++) { + for (int i = 0;; i++) { r_grid_steps[i] = grid_scale * subdiv; if (i == STEPS_LEN - 1) { diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 63bcdb9c1ff..032e3fea458 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -334,10 +334,9 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3]) else if (ob_act && (ob_act->mode & OB_MODE_EDIT) && (ob_act->type == OB_FONT)) { Curve *cu = ob_act_eval->data; EditFont *ef = cu->editfont; - int i; zero_v3(lastofs); - for (i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) { add_v2_v2(lastofs, ef->textcurs[i]); } mul_v2_fl(lastofs, 1.0f / 4.0f); @@ -4883,11 +4882,10 @@ static void calc_local_clipping(float clip_local[6][4], { BoundBox clipbb_local; float imat[4][4]; - int i; invert_m4_m4(imat, mat); - for (i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) { mul_v3_m4v3(clipbb_local.vec[i], imat, clipbb->vec[i]); } diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 7562bf6f75c..4bc64a337f5 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -1658,8 +1658,7 @@ static Base *object_mouse_select_menu(bContext *C, static bool selectbuffer_has_bones(const uint *buffer, const uint hits) { - uint i; - for (i = 0; i < hits; i++) { + for (uint i = 0; i < hits; i++) { if (buffer[(4 * i) + 3] & 0xFFFF0000) { return true; } @@ -2127,11 +2126,10 @@ static bool ed_object_select_pick(bContext *C, if (basact->object->type == OB_CAMERA) { MovieClip *clip = BKE_object_movieclip_get(scene, basact->object, false); if (clip != NULL && oldbasact == basact) { - int i, hitresult; bool changed = false; - for (i = 0; i < hits; i++) { - hitresult = buffer[3 + (i * 4)]; + for (int i = 0; i < hits; i++) { + int hitresult = buffer[3 + (i * 4)]; /* if there's bundles in buffer select bundles first, * so non-camera elements should be ignored in buffer */ diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 54a3ebb8c0c..0eaae7f17cd 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -163,41 +163,6 @@ void constraintNumInput(TransInfo *t, float vec[3]) } } -static void postConstraintChecks(TransInfo *t, float vec[3]) -{ - mul_m3_v3(t->spacemtx_inv, vec); - - transform_snap_increment(t, vec); - - if (t->flag & T_NULL_ONE) { - if (!(t->con.mode & CON_AXIS0)) { - vec[0] = 1.0f; - } - - if (!(t->con.mode & CON_AXIS1)) { - vec[1] = 1.0f; - } - - if (!(t->con.mode & CON_AXIS2)) { - vec[2] = 1.0f; - } - } - - if (applyNumInput(&t->num, vec)) { - constraintNumInput(t, vec); - removeAspectRatio(t, vec); - } - - /* If `t->values` is operator param, use that directly but not if snapping is forced */ - if (t->flag & T_INPUT_IS_VALUES_FINAL && (t->tsnap.status & SNAP_FORCED) == 0) { - copy_v3_v3(vec, t->values); - constraintValuesFinal(t, vec); - /* inverse transformation at the end */ - } - - mul_m3_v3(t->spacemtx, vec); -} - static void viewAxisCorrectCenter(const TransInfo *t, float t_con_center[3]) { if (t->spacetype == SPACE_VIEW3D) { @@ -432,15 +397,22 @@ static void applyAxisConstraintVec( { copy_v3_v3(out, in); if (!td && t->con.mode & CON_APPLY) { + bool is_snap_to_point = false, is_snap_to_edge = false, is_snap_to_face = false; mul_m3_v3(t->con.pmtx, out); - bool is_snap_to_edge = false, is_snap_to_face = false; + if (activeSnap(t)) { - is_snap_to_edge = (t->tsnap.snapElem & SCE_SNAP_MODE_EDGE) != 0; - is_snap_to_face = (t->tsnap.snapElem & SCE_SNAP_MODE_FACE) != 0; + if (validSnap(t)) { + is_snap_to_point = (t->tsnap.snapElem & SCE_SNAP_MODE_VERTEX) != 0; + is_snap_to_edge = (t->tsnap.snapElem & SCE_SNAP_MODE_EDGE) != 0; + is_snap_to_face = (t->tsnap.snapElem & SCE_SNAP_MODE_FACE) != 0; + } + else if (t->tsnap.snapElem & SCE_SNAP_MODE_GRID) { + is_snap_to_point = true; + } } /* With snap points, a projection is alright, no adjustments needed. */ - if (!validSnap(t) || is_snap_to_edge || is_snap_to_face) { + if (!is_snap_to_point || is_snap_to_edge || is_snap_to_face) { const int dims = getConstraintSpaceDimension(t); if (dims == 2) { if (!is_zero_v3(out)) { @@ -486,7 +458,6 @@ static void applyAxisConstraintVec( } } } - postConstraintChecks(t, out); } } @@ -913,12 +884,11 @@ static void drawObjectConstraint(TransInfo *t) * Without drawing the first light, users have little clue what they are doing. */ short options = DRAWLIGHT; - int i; float tmp_axismtx[3][3]; FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; - for (i = 0; i < tc->data_len; i++, td++) { + for (int i = 0; i < tc->data_len; i++, td++) { float co[3]; float(*axismtx)[3]; diff --git a/source/blender/editors/transform/transform_convert_mask.c b/source/blender/editors/transform/transform_convert_mask.c index 6f34c49bdac..340f14c6800 100644 --- a/source/blender/editors/transform/transform_convert_mask.c +++ b/source/blender/editors/transform/transform_convert_mask.c @@ -138,12 +138,11 @@ static void MaskPointToTransData(Scene *scene, invert_m3_m3(parent_inverse_matrix, parent_matrix); if (is_prop_edit || is_sel_point) { - int i; tdm->point = point; copy_m3_m3(tdm->vec, bezt->vec); - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { copy_m3_m3(tdm->parent_matrix, parent_matrix); copy_m3_m3(tdm->parent_inverse_matrix, parent_inverse_matrix); diff --git a/source/blender/editors/transform/transform_convert_mesh.c b/source/blender/editors/transform/transform_convert_mesh.c index 7ad54a56545..06ab60d992c 100644 --- a/source/blender/editors/transform/transform_convert_mesh.c +++ b/source/blender/editors/transform/transform_convert_mesh.c @@ -1296,6 +1296,9 @@ void mesh_customdatacorrect_init(TransInfo *t) use_merge_group = (t->settings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT_KEEP_CONNECTED) != 0; } } + else { + return; + } FOREACH_TRANS_DATA_CONTAINER (t, tc) { mesh_customdatacorrect_init_container(tc, use_merge_group); diff --git a/source/blender/editors/transform/transform_mode_edge_seq_slide.c b/source/blender/editors/transform/transform_mode_edge_seq_slide.c index 141f9acdeb4..d2474d78387 100644 --- a/source/blender/editors/transform/transform_mode_edge_seq_slide.c +++ b/source/blender/editors/transform/transform_mode_edge_seq_slide.c @@ -93,22 +93,29 @@ static void applySeqSlideValue(TransInfo *t, const float val[2]) static void applySeqSlide(TransInfo *t, const int mval[2]) { char str[UI_MAX_DRAW_STR]; + float values_final[3]; snapSequenceBounds(t, mval); - - if (t->con.mode & CON_APPLY) { - float tvec[3]; - t->con.applyVec(t, NULL, NULL, t->values, tvec); - copy_v3_v3(t->values_final, tvec); + if (applyNumInput(&t->num, values_final)) { + if (t->con.mode & CON_APPLY) { + if (t->con.mode & CON_AXIS0) { + /* Do nothing. */ + } + else { + mul_v2_v2fl(values_final, t->spacemtx[1], values_final[0]); + } + } + } + else if (t->con.mode & CON_APPLY) { + t->con.applyVec(t, NULL, NULL, t->values, values_final); } else { - // transform_snap_increment(t, t->values); - applyNumInput(&t->num, t->values); - copy_v3_v3(t->values_final, t->values); + copy_v2_v2(values_final, t->values); } - t->values_final[0] = floorf(t->values_final[0] + 0.5f); - t->values_final[1] = floorf(t->values_final[1] + 0.5f); + values_final[0] = floorf(values_final[0] + 0.5f); + values_final[1] = floorf(values_final[1] + 0.5f); + copy_v2_v2(t->values_final, values_final); headerSeqSlide(t, t->values_final, str); applySeqSlideValue(t, t->values_final); diff --git a/source/blender/editors/transform/transform_mode_translate.c b/source/blender/editors/transform/transform_mode_translate.c index 866b9d921c8..758a6d04f11 100644 --- a/source/blender/editors/transform/transform_mode_translate.c +++ b/source/blender/editors/transform/transform_mode_translate.c @@ -360,42 +360,49 @@ static void applyTranslation(TransInfo *t, const int UNUSED(mval[2])) if (t->flag & T_INPUT_IS_VALUES_FINAL) { mul_v3_m3v3(global_dir, t->spacemtx, t->values); } + else if (applyNumInput(&t->num, global_dir)) { + if (t->con.mode & CON_APPLY) { + if (t->con.mode & CON_AXIS0) { + /* Do nothing. */ + } + else if (t->con.mode & CON_AXIS1) { + mul_v3_v3fl(global_dir, t->spacemtx[1], global_dir[0]); + } + else if (t->con.mode & CON_AXIS2) { + mul_v3_v3fl(global_dir, t->spacemtx[2], global_dir[0]); + } + } + } else { copy_v3_v3(global_dir, t->values); - if (applyNumInput(&t->num, global_dir)) { - removeAspectRatio(t, global_dir); + + t->tsnap.snapElem = 0; + applySnapping(t, global_dir); + transform_snap_grid(t, global_dir); + + if (t->con.mode & CON_APPLY) { + float in[3]; + copy_v3_v3(in, global_dir); + t->con.applyVec(t, NULL, NULL, in, global_dir); } - else { - applySnapping(t, global_dir); - if (!validSnap(t) && !(t->con.mode & CON_APPLY)) { - float dist_sq = FLT_MAX; - if (transform_snap_grid(t, global_dir)) { - dist_sq = len_squared_v3v3(t->values, global_dir); - } + float incr_dir[3]; + mul_v3_m3v3(incr_dir, t->spacemtx_inv, global_dir); + if (transform_snap_increment(t, incr_dir)) { + mul_v3_m3v3(incr_dir, t->spacemtx, incr_dir); - /* Check the snap distance to the initial value to work with mixed snap. */ - float increment_loc[3]; - copy_v3_v3(increment_loc, t->values); - if (transform_snap_increment(t, increment_loc)) { - if ((dist_sq == FLT_MAX) || (len_squared_v3v3(t->values, increment_loc) < dist_sq)) { - copy_v3_v3(global_dir, increment_loc); - } - } + /* Test for mixed snap with grid. */ + float snap_dist_sq = FLT_MAX; + if (t->tsnap.snapElem != 0) { + snap_dist_sq = len_squared_v3v3(t->values, global_dir); + } + if ((snap_dist_sq == FLT_MAX) || (len_squared_v3v3(global_dir, incr_dir) < snap_dist_sq)) { + copy_v3_v3(global_dir, incr_dir); } } } - if (t->con.mode & CON_APPLY) { - float in[3]; - copy_v3_v3(in, global_dir); - t->con.applyVec(t, NULL, NULL, in, global_dir); - headerTranslation(t, global_dir, str); - } - else { - headerTranslation(t, global_dir, str); - } - + headerTranslation(t, global_dir, str); applyTranslationValue(t, global_dir); /* evil hack - redo translation if clipping needed */ diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 1813acadb9e..a546aabd095 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -464,6 +464,7 @@ void applySnapping(TransInfo *t, float *vec) void resetSnapping(TransInfo *t) { t->tsnap.status = 0; + t->tsnap.snapElem = 0; t->tsnap.align = false; t->tsnap.project = 0; t->tsnap.mode = 0; @@ -1412,12 +1413,12 @@ void snapSequenceBounds(TransInfo *t, const int mval[2]) t->values[0] = frame_near - frame_snap; } -static void snap_grid_apply_ex( +static void snap_grid_apply( TransInfo *t, const int max_index, const float grid_dist, const float loc[3], float r_out[3]) { + BLI_assert(max_index <= 2); const float *center_global = t->center_global; const float *asp = t->aspect; - bool use_local_axis = false; /* use a fallback for cursor selection, * this isn't useful as a global center for absolute grid snapping @@ -1427,74 +1428,27 @@ static void snap_grid_apply_ex( center_global = cd->global; } - if (t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2)) { - use_local_axis = true; + float in[3]; + if (t->con.mode & CON_APPLY) { + BLI_assert(t->tsnap.snapElem == 0); + t->con.applyVec(t, NULL, NULL, loc, in); + } + else { + copy_v3_v3(in, loc); } for (int i = 0; i <= max_index; i++) { - /* do not let unconstrained axis jump to absolute grid increments */ - if (!(t->con.mode & CON_APPLY) || t->con.mode & (CON_AXIS0 << i)) { - const float iter_fac = grid_dist * asp[i]; - - if (use_local_axis) { - float local_axis[3]; - float pos_on_axis[3]; - - copy_v3_v3(local_axis, t->spacemtx[i]); - copy_v3_v3(pos_on_axis, t->spacemtx[i]); - - /* amount of movement on axis from initial pos */ - mul_v3_fl(pos_on_axis, loc[i]); - - /* actual global position on axis */ - add_v3_v3(pos_on_axis, center_global); - - float min_dist = INFINITY; - for (int j = 0; j < 3; j++) { - if (fabs(local_axis[j]) < 0.01f) { - /* Ignore very small (normalized) axis changes */ - continue; - } - - /* closest point on grid */ - float grid_p = iter_fac * roundf(pos_on_axis[j] / iter_fac); - float dist_p = fabs((grid_p - pos_on_axis[j]) / local_axis[j]); - - /* The amount of distance needed to travel along the - * local axis to snap to the closest grid point */ - /* in the global j axis direction */ - float move_dist = (grid_p - center_global[j]) / local_axis[j]; - - if (dist_p < min_dist) { - min_dist = dist_p; - r_out[i] = move_dist; - } - } - } - else { - r_out[i] = iter_fac * roundf((loc[i] + center_global[i]) / iter_fac) - center_global[i]; - } - } + const float iter_fac = grid_dist * asp[i]; + r_out[i] = iter_fac * roundf((in[i] + center_global[i]) / iter_fac) - center_global[i]; } } -static void snap_grid_apply(TransInfo *t, int max_index, const float grid_dist, float *r_val) +bool transform_snap_grid(TransInfo *t, float *val) { - BLI_assert(t->tsnap.mode & SCE_SNAP_MODE_GRID); - BLI_assert(max_index <= 2); - - /* Early bailing out if no need to snap */ - if (grid_dist == 0.0f) { - return; + if (!activeSnap(t)) { + return false; } - /* absolute snapping on grid based on global center. - * for now only 3d view (others can be added if we want) */ - snap_grid_apply_ex(t, max_index, grid_dist, r_val, r_val); -} - -bool transform_snap_grid(TransInfo *t, float *val) -{ if ((!(t->tsnap.mode & SCE_SNAP_MODE_GRID)) || validSnap(t)) { /* Don't do grid snapping if there is a valid snap point. */ return false; @@ -1508,10 +1462,15 @@ bool transform_snap_grid(TransInfo *t, float *val) return false; } - float grid_dist = activeSnap(t) ? (t->modifiers & MOD_PRECISION) ? t->snap[2] : t->snap[1] : - t->snap[0]; + float grid_dist = (t->modifiers & MOD_PRECISION) ? t->snap[2] : t->snap[1]; + + /* Early bailing out if no need to snap */ + if (grid_dist == 0.0f) { + return false; + } - snap_grid_apply(t, t->idx_max, grid_dist, val); + snap_grid_apply(t, t->idx_max, grid_dist, val, val); + t->tsnap.snapElem = SCE_SNAP_MODE_GRID; return true; } diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index 8d30dc19732..0ae167c117e 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -1231,17 +1231,16 @@ static PFace *p_face_add_fill(PChart *chart, PVert *v1, PVert *v2, PVert *v3) static PBool p_quad_split_direction(PHandle *handle, float **co, PHashKey *vkeys) { - /* slight bias to prefer one edge over the other in case they are equal, so + /* Slight bias to prefer one edge over the other in case they are equal, so * that in symmetric models we choose the same split direction instead of - * depending on floating point errors to decide */ + * depending on floating point errors to decide. */ float bias = 1.0f + 1e-6f; float fac = len_v3v3(co[0], co[2]) * bias - len_v3v3(co[1], co[3]); PBool dir = (fac <= 0.0f); - /* the face exists check is there because of a special case: when - * two quads share three vertices, they can each be split into two - * triangles, resulting in two identical triangles. for example in - * suzanne's nose. */ + /* The face exists check is there because of a special case: + * when two quads share three vertices, they can each be split into two triangles, + * resulting in two identical triangles. For example in Suzanne's nose. */ if (dir) { if (p_face_exists(handle, vkeys, 0, 1, 2) || p_face_exists(handle, vkeys, 0, 2, 3)) { return !dir; diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index bb50cd3744f..72dc610f3c8 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -93,6 +93,7 @@ set(SRC opengl/gl_context.cc opengl/gl_drawlist.cc opengl/gl_debug.cc + opengl/gl_debug_layer.cc opengl/gl_framebuffer.cc opengl/gl_immediate.cc opengl/gl_index_buffer.cc diff --git a/source/blender/gpu/intern/gpu_batch.cc b/source/blender/gpu/intern/gpu_batch.cc index de079a89de7..1f873570f4a 100644 --- a/source/blender/gpu/intern/gpu_batch.cc +++ b/source/blender/gpu/intern/gpu_batch.cc @@ -235,14 +235,12 @@ void GPU_batch_draw(GPUBatch *batch) { GPU_shader_bind(batch->shader); GPU_batch_draw_advanced(batch, 0, 0, 0, 0); - GPU_shader_unbind(); } void GPU_batch_draw_range(GPUBatch *batch, int v_first, int v_count) { GPU_shader_bind(batch->shader); GPU_batch_draw_advanced(batch, v_first, v_count, 0, 0); - GPU_shader_unbind(); } /* Draw multiple instance of a batch without having any instance attributes. */ @@ -252,7 +250,6 @@ void GPU_batch_draw_instanced(GPUBatch *batch, int i_count) GPU_shader_bind(batch->shader); GPU_batch_draw_advanced(batch, 0, 0, 0, i_count); - GPU_shader_unbind(); } void GPU_batch_draw_advanced( diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc index 0a488c0dfc0..9c3a88e30f0 100644 --- a/source/blender/gpu/intern/gpu_immediate.cc +++ b/source/blender/gpu/intern/gpu_immediate.cc @@ -186,7 +186,7 @@ void immEnd(void) if (imm->batch) { if (imm->vertex_idx < imm->vertex_len) { - GPU_vertbuf_data_resize(imm->batch->verts[0], imm->vertex_len); + GPU_vertbuf_data_resize(imm->batch->verts[0], imm->vertex_idx); /* TODO: resize only if vertex count is much smaller */ } GPU_batch_set_shader(imm->batch, imm->shader); diff --git a/source/blender/gpu/intern/gpu_state.cc b/source/blender/gpu/intern/gpu_state.cc index 529c8795327..be523020e8a 100644 --- a/source/blender/gpu/intern/gpu_state.cc +++ b/source/blender/gpu/intern/gpu_state.cc @@ -173,12 +173,15 @@ void GPU_line_width(float width) void GPU_point_size(float size) { - SET_MUTABLE_STATE(point_size, size * PIXELSIZE); + GPUStateManager *stack = Context::get()->state_manager; + auto &state = stack->mutable_state; + /* Keep the sign of point_size since it represents the enable state. */ + state.point_size = size * ((state.point_size > 0.0) ? 1.0f : -1.0f); } /* Programmable point size * - shaders set their own point size when enabled - * - use glPointSize when disabled */ + * - use GPU_point_size when disabled */ /* TODO remove and use program point size everywhere */ void GPU_program_point_size(bool enable) { diff --git a/source/blender/gpu/intern/gpu_vertex_format.cc b/source/blender/gpu/intern/gpu_vertex_format.cc index 220c48457bc..ac8439167e3 100644 --- a/source/blender/gpu/intern/gpu_vertex_format.cc +++ b/source/blender/gpu/intern/gpu_vertex_format.cc @@ -51,6 +51,7 @@ void GPU_vertformat_clear(GPUVertFormat *format) format->packed = false; format->name_offset = 0; format->name_len = 0; + format->deinterleaved = false; for (uint i = 0; i < GPU_VERT_ATTR_MAX_LEN; i++) { format->attrs[i].name_len = 0; diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc index c8d57a20a38..edaa84cdcf8 100644 --- a/source/blender/gpu/opengl/gl_backend.cc +++ b/source/blender/gpu/opengl/gl_backend.cc @@ -178,7 +178,7 @@ static bool detect_mip_render_workaround(void) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClear(GL_COLOR_BUFFER_BIT); glBindFramebuffer(GL_FRAMEBUFFER, 0); - glDrawBuffer(GL_BACK); + /* Read mip 1. If color is not the same as the clear_color, the rendering failed. */ glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 1, GL_RGBA, GL_FLOAT, source_pix); bool enable_workaround = !equals_v4v4(clear_color, source_pix); @@ -207,11 +207,22 @@ static void detect_workarounds(void) printf(" version: %s\n\n", version); GCaps.depth_blitting_workaround = true; GCaps.mip_render_workaround = true; + GLContext::debug_layer_workaround = true; GLContext::unused_fb_slot_workaround = true; - GLContext::texture_copy_workaround = true; /* Turn off extensions. */ GLContext::base_instance_support = false; + GLContext::clear_texture_support = false; + GLContext::copy_image_support = false; + GLContext::debug_layer_support = false; + GLContext::direct_state_access_support = false; + GLContext::fixed_restart_index_support = false; + GLContext::multi_bind_support = false; + GLContext::multi_draw_indirect_support = false; + GLContext::shader_draw_parameters_support = false; GLContext::texture_cube_map_array_support = false; + GLContext::texture_filter_anisotropic_support = false; + GLContext::texture_gather_support = false; + GLContext::vertex_attrib_binding_support = false; return; } @@ -266,7 +277,7 @@ static void detect_workarounds(void) * covered since they only support GL 4.4 on windows. * This fixes some issues with workbench anti-aliasing on Win + Intel GPU. (see T76273) */ if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_WIN, GPU_DRIVER_OFFICIAL) && !GLEW_VERSION_4_5) { - GLContext::texture_copy_workaround = true; + GLContext::copy_image_support = false; } /* Special fix for theses specific GPUs. * Without this workaround, blender crashes on startup. (see T72098) */ @@ -303,6 +314,11 @@ static void detect_workarounds(void) strstr(version, "Mesa 19.1") || strstr(version, "Mesa 19.2"))) { GLContext::unused_fb_slot_workaround = true; } + /* There is a bug on older Nvidia GPU where GL_ARB_texture_gather + * is reported to be supported but yield a compile error (see T55802). */ + if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY) && !GLEW_VERSION_4_0) { + GLContext::texture_gather_support = false; + } /* dFdx/dFdy calculation factors, those are dependent on driver. */ if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY) && @@ -321,6 +337,15 @@ static void detect_workarounds(void) GLContext::derivative_signs[1] = 1.0; } } + + /* Disable multidraw if the base instance cannot be read. */ + if (GLContext::shader_draw_parameters_support == false) { + GLContext::multi_draw_indirect_support = false; + } + /* Enable our own incomplete debug layer if no other is available. */ + if (GLContext::debug_layer_support == false) { + GLContext::debug_layer_workaround = true; + } } /** Internal capabilities. */ @@ -330,10 +355,20 @@ GLint GLContext::max_ubo_size; GLint GLContext::max_ubo_binds; /** Extensions. */ bool GLContext::base_instance_support = false; +bool GLContext::clear_texture_support = false; +bool GLContext::copy_image_support = false; bool GLContext::debug_layer_support = false; +bool GLContext::direct_state_access_support = false; +bool GLContext::fixed_restart_index_support = false; +bool GLContext::multi_bind_support = false; +bool GLContext::multi_draw_indirect_support = false; +bool GLContext::shader_draw_parameters_support = false; bool GLContext::texture_cube_map_array_support = false; +bool GLContext::texture_filter_anisotropic_support = false; +bool GLContext::texture_gather_support = false; +bool GLContext::vertex_attrib_binding_support = false; /** Workarounds. */ -bool GLContext::texture_copy_workaround = false; +bool GLContext::debug_layer_workaround = false; bool GLContext::unused_fb_slot_workaround = false; float GLContext::derivative_signs[2] = {1.0f, 1.0f}; @@ -354,15 +389,26 @@ void GLBackend::capabilities_init(void) glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &GLContext::max_ubo_binds); glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &GLContext::max_ubo_size); GLContext::base_instance_support = GLEW_ARB_base_instance; + GLContext::clear_texture_support = GLEW_ARB_clear_texture; + GLContext::copy_image_support = GLEW_ARB_copy_image; + GLContext::debug_layer_support = GLEW_VERSION_4_3 || GLEW_KHR_debug || GLEW_ARB_debug_output; + GLContext::direct_state_access_support = GLEW_ARB_direct_state_access; + GLContext::fixed_restart_index_support = GLEW_ARB_ES3_compatibility; + GLContext::multi_bind_support = GLEW_ARB_multi_bind; + GLContext::multi_draw_indirect_support = GLEW_ARB_multi_draw_indirect; + GLContext::shader_draw_parameters_support = GLEW_ARB_shader_draw_parameters; GLContext::texture_cube_map_array_support = GLEW_ARB_texture_cube_map_array; - GLContext::debug_layer_support = (GLEW_VERSION_4_3 || GLEW_KHR_debug); + GLContext::texture_filter_anisotropic_support = GLEW_EXT_texture_filter_anisotropic; + GLContext::texture_gather_support = GLEW_ARB_texture_gather; + GLContext::vertex_attrib_binding_support = GLEW_ARB_vertex_attrib_binding; + + detect_workarounds(); + /* Disable this feature entirely when not debugging. */ if ((G.debug & G_DEBUG_GPU) == 0) { - /* Disable this feature entierly when not debugging. */ GLContext::debug_layer_support = false; + GLContext::debug_layer_workaround = false; } - - detect_workarounds(); } /** \} */ diff --git a/source/blender/gpu/opengl/gl_batch.cc b/source/blender/gpu/opengl/gl_batch.cc index b25bafad6a3..ca627775e1f 100644 --- a/source/blender/gpu/opengl/gl_batch.cc +++ b/source/blender/gpu/opengl/gl_batch.cc @@ -307,7 +307,7 @@ void GLBatch::bind(int i_first) #if GPU_TRACK_INDEX_RANGE /* Can be removed if GL 4.3 is required. */ - if (!GLEW_ARB_ES3_compatibility && (elem != NULL)) { + if (!GLContext::fixed_restart_index_support && (elem != NULL)) { glPrimitiveRestartIndex(this->elem_()->restart_index()); } #endif @@ -324,7 +324,6 @@ void GLBatch::bind(int i_first) void GLBatch::draw(int v_first, int v_count, int i_first, int i_count) { GL_CHECK_RESOURCES("Batch"); - GL_CHECK_ERROR("Batch Pre drawing"); this->bind(i_first); @@ -346,7 +345,6 @@ void GLBatch::draw(int v_first, int v_count, int i_first, int i_count) glDrawElementsInstancedBaseVertex( gl_type, v_count, index_type, v_first_ofs, i_count, base_index); } - GL_CHECK_ERROR("Batch Post-drawing Indexed"); } else { #ifdef __APPLE__ @@ -361,7 +359,6 @@ void GLBatch::draw(int v_first, int v_count, int i_first, int i_count) #ifdef __APPLE__ glEnable(GL_PRIMITIVE_RESTART); #endif - GL_CHECK_ERROR("Batch Post-drawing Non-indexed"); } } diff --git a/source/blender/gpu/opengl/gl_context.cc b/source/blender/gpu/opengl/gl_context.cc index 6b3b06ef12b..9c98953f469 100644 --- a/source/blender/gpu/opengl/gl_context.cc +++ b/source/blender/gpu/opengl/gl_context.cc @@ -74,6 +74,9 @@ GLContext::GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list GHOST_DisposeRectangle(bounds); if (default_fbo != 0) { + /* Bind default framebuffer, otherwise state might be undefined because of + * detect_mip_render_workaround(). */ + glBindFramebuffer(GL_FRAMEBUFFER, default_fbo); front_left = new GLFrameBuffer("front_left", this, GL_COLOR_ATTACHMENT0, default_fbo, w, h); back_left = new GLFrameBuffer("back_left", this, GL_COLOR_ATTACHMENT0, default_fbo, w, h); } @@ -81,6 +84,7 @@ GLContext::GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list front_left = new GLFrameBuffer("front_left", this, GL_FRONT_LEFT, 0, w, h); back_left = new GLFrameBuffer("back_left", this, GL_BACK_LEFT, 0, w, h); } + GLboolean supports_stereo_quad_buffer = GL_FALSE; glGetBooleanv(GL_STEREO, &supports_stereo_quad_buffer); if (supports_stereo_quad_buffer) { @@ -95,7 +99,7 @@ GLContext::GLContext(void *ghost_window, GLSharedOrphanLists &shared_orphan_list active_fb = back_left; static_cast<GLStateManager *>(state_manager)->active_fb = static_cast<GLFrameBuffer *>( - back_left); + active_fb); } GLContext::~GLContext() diff --git a/source/blender/gpu/opengl/gl_context.hh b/source/blender/gpu/opengl/gl_context.hh index 10ae396d138..9822c842ce7 100644 --- a/source/blender/gpu/opengl/gl_context.hh +++ b/source/blender/gpu/opengl/gl_context.hh @@ -62,10 +62,20 @@ class GLContext : public Context { static GLint max_ubo_binds; /** Extensions. */ static bool base_instance_support; + static bool clear_texture_support; + static bool copy_image_support; static bool debug_layer_support; + static bool direct_state_access_support; + static bool fixed_restart_index_support; + static bool multi_bind_support; + static bool multi_draw_indirect_support; + static bool shader_draw_parameters_support; static bool texture_cube_map_array_support; + static bool texture_filter_anisotropic_support; + static bool texture_gather_support; + static bool vertex_attrib_binding_support; /** Workarounds. */ - static bool texture_copy_workaround; + static bool debug_layer_workaround; static bool unused_fb_slot_workaround; static float derivative_signs[2]; diff --git a/source/blender/gpu/opengl/gl_debug.cc b/source/blender/gpu/opengl/gl_debug.cc index 468d1514d60..db99e90d0ec 100644 --- a/source/blender/gpu/opengl/gl_debug.cc +++ b/source/blender/gpu/opengl/gl_debug.cc @@ -112,17 +112,13 @@ static void APIENTRY debug_callback(GLenum UNUSED(source), #undef APIENTRY +/* This function needs to be called once per context. */ void init_gl_callbacks(void) { -#ifdef __APPLE__ - fprintf(stderr, "GPUDebug: OpenGL debug callback is not available on Apple\n"); - return; -#endif /* not Apple */ - char msg[256] = ""; const char format[] = "Successfully hooked OpenGL debug callback using %s"; - if (GLContext::debug_layer_support) { + if (GLEW_VERSION_4_3 || GLEW_KHR_debug) { SNPRINTF(msg, format, GLEW_VERSION_4_3 ? "OpenGL 4.3" : "KHR_debug extension"); glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); @@ -148,7 +144,8 @@ void init_gl_callbacks(void) msg); } else { - fprintf(stderr, "GPUDebug: Failed to hook OpenGL debug callback\n"); + fprintf(stderr, "GPUDebug: Failed to hook OpenGL debug callback. Use fallback debug layer.\n"); + init_debug_layer(); } } @@ -243,4 +240,68 @@ void raise_gl_error(const char *info) /** \} */ +/* -------------------------------------------------------------------- */ +/** \name Object Label + * + * Useful for debugging through render-doc. Only defined if using `--debug-gpu`. + * Make sure to bind the object first so that it gets defined by the GL implementation. + * \{ */ + +static const char *to_str_prefix(GLenum type) +{ + switch (type) { + case GL_FRAGMENT_SHADER: + case GL_GEOMETRY_SHADER: + case GL_VERTEX_SHADER: + case GL_SHADER: + case GL_PROGRAM: + return "SHD-"; + case GL_SAMPLER: + return "SAM-"; + case GL_TEXTURE: + return "TEX-"; + case GL_FRAMEBUFFER: + return "FBO-"; + case GL_VERTEX_ARRAY: + return "VAO-"; + case GL_UNIFORM_BUFFER: + return "UBO-"; + case GL_BUFFER: + return "BUF-"; + default: + return ""; + } +} +static const char *to_str_suffix(GLenum type) +{ + switch (type) { + case GL_FRAGMENT_SHADER: + return "-Frag"; + case GL_GEOMETRY_SHADER: + return "-Geom"; + case GL_VERTEX_SHADER: + return "-Vert"; + default: + return ""; + } +} + +void object_label(GLenum type, GLuint object, const char *name) +{ + if ((G.debug & G_DEBUG_GPU) && (GLEW_VERSION_4_3 || GLEW_KHR_debug)) { + char label[64]; + SNPRINTF(label, "%s%s%s", to_str_prefix(type), name, to_str_suffix(type)); + /* Small convenience for caller. */ + if (ELEM(type, GL_FRAGMENT_SHADER, GL_GEOMETRY_SHADER, GL_VERTEX_SHADER)) { + type = GL_SHADER; + } + if (ELEM(type, GL_UNIFORM_BUFFER)) { + type = GL_BUFFER; + } + glObjectLabel(type, object, -1, label); + } +} + +/** \} */ + } // namespace blender::gpu::debug diff --git a/source/blender/gpu/opengl/gl_debug.hh b/source/blender/gpu/opengl/gl_debug.hh index 5537147d0fe..892fb1d2ddb 100644 --- a/source/blender/gpu/opengl/gl_debug.hh +++ b/source/blender/gpu/opengl/gl_debug.hh @@ -20,16 +20,60 @@ #pragma once -namespace blender { -namespace gpu { -namespace debug { +#include "gl_context.hh" -/* Enabled on MacOS by default since there is no support for debug callbacks. */ -#if defined(DEBUG) && defined(__APPLE__) -# define GL_CHECK_ERROR(info) debug::check_gl_error(info) -#else -# define GL_CHECK_ERROR(info) -#endif +#include "glew-mx.h" + +/* Manual line breaks for readability. */ +/* clang-format off */ +#define _VA_ARG_LIST1(t) t +#define _VA_ARG_LIST2(t, a) t a +#define _VA_ARG_LIST4(t, a, b, c) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST2(b, c) +#define _VA_ARG_LIST6(t, a, b, c, d, e) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST4(b, c, d, e) +#define _VA_ARG_LIST8(t, a, b, c, d, e, f, g) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST6(b, c, d, e, f, g) +#define _VA_ARG_LIST10(t, a, b, c, d, e, f, g, h, i) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST8(b, c, d, e, f, g, h, i) +#define _VA_ARG_LIST12(t, a, b, c, d, e, f, g, h, i, j, k) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST10(b, c, d, e, f, g, h, i, j, k) +#define _VA_ARG_LIST14(t, a, b, c, d, e, f, g, h, i, j, k, l, m) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST12(b, c, d, e, f, g, h, i, j, k, l, m) +#define _VA_ARG_LIST16(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST14(b, c, d, e, f, g, h, i, j, k, l, m, o, p) +#define _VA_ARG_LIST18(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST16(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r) +#define _VA_ARG_LIST20(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST18(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u) +#define _VA_ARG_LIST22(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u, v, w) \ + _VA_ARG_LIST2(t, a), _VA_ARG_LIST20(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u, v, w) +#define ARG_LIST(...) VA_NARGS_CALL_OVERLOAD(_VA_ARG_LIST, __VA_ARGS__) + +#define _VA_ARG_LIST_CALL1(t) +#define _VA_ARG_LIST_CALL2(t, a) a +#define _VA_ARG_LIST_CALL4(t, a, b, c) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL2(b, c) +#define _VA_ARG_LIST_CALL6(t, a, b, c, d, e) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL4(b, c, d, e) +#define _VA_ARG_LIST_CALL8(t, a, b, c, d, e, f, g) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL6(b, c, d, e, f, g) +#define _VA_ARG_LIST_CALL10(t, a, b, c, d, e, f, g, h, i) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL8(b, c, d, e, f, g, h, i) +#define _VA_ARG_LIST_CALL12(t, a, b, c, d, e, f, g, h, i, j, k) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL10(b, c, d, e, f, g, h, i, j, k) +#define _VA_ARG_LIST_CALL14(t, a, b, c, d, e, f, g, h, i, j, k, l, m) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL12(b, c, d, e, f, g, h, i, j, k, l, m) +#define _VA_ARG_LIST_CALL16(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL14(b, c, d, e, f, g, h, i, j, k, l, m, o, p) +#define _VA_ARG_LIST_CALL18(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL16(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r) +#define _VA_ARG_LIST_CALL20(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL18(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u) +#define _VA_ARG_LIST_CALL22(t, a, b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u, v, w) \ + _VA_ARG_LIST_CALL2(t, a), _VA_ARG_LIST_CALL20(b, c, d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, u, v, w) +#define ARG_LIST_CALL(...) VA_NARGS_CALL_OVERLOAD(_VA_ARG_LIST_CALL, __VA_ARGS__) +/* clang-format on */ #ifdef DEBUG # define GL_CHECK_RESOURCES(info) debug::check_gl_resources(info) @@ -37,11 +81,52 @@ namespace debug { # define GL_CHECK_RESOURCES(info) #endif +namespace blender { +namespace gpu { +namespace debug { + void raise_gl_error(const char *info); void check_gl_error(const char *info); void check_gl_resources(const char *info); void init_gl_callbacks(void); +void init_debug_layer(void); + +void object_label(GLenum type, GLuint object, const char *name); + } // namespace debug + +#define DEBUG_FUNC_OVERRIDE(func, ...) \ + inline void func(ARG_LIST(__VA_ARGS__)) \ + { \ + if (GLContext::debug_layer_workaround) { \ + debug::check_gl_error("generated before " #func); \ + ::func(ARG_LIST_CALL(__VA_ARGS__)); \ + debug::check_gl_error("" #func); \ + } \ + else { \ + ::func(ARG_LIST_CALL(__VA_ARGS__)); \ + } \ + } + +/* Avoid very long declarations. */ +/* clang-format off */ +DEBUG_FUNC_OVERRIDE(glClear, GLbitfield, mask); +DEBUG_FUNC_OVERRIDE(glDeleteTextures, GLsizei, n, const GLuint *, textures); +DEBUG_FUNC_OVERRIDE(glDrawArrays, GLenum, mode, GLint, first, GLsizei, count); +DEBUG_FUNC_OVERRIDE(glFinish, void); +DEBUG_FUNC_OVERRIDE(glFlush, void); +DEBUG_FUNC_OVERRIDE(glGenTextures, GLsizei, n, GLuint *, textures); +DEBUG_FUNC_OVERRIDE(glGetTexImage, GLenum, target, GLint, level, GLenum, format, GLenum, type, void *, pixels); +DEBUG_FUNC_OVERRIDE(glReadBuffer, GLenum, mode); +DEBUG_FUNC_OVERRIDE(glReadPixels, GLint, x, GLint, y, GLsizei, width, GLsizei, height, GLenum, format, GLenum, type, void *, pixels); +DEBUG_FUNC_OVERRIDE(glTexImage1D, GLenum, target, GLint, level, GLint, internalformat, GLsizei, width, GLint, border, GLenum, format, GLenum, type, const void *, pixels); +DEBUG_FUNC_OVERRIDE(glTexImage2D, GLenum, target, GLint, level, GLint, internalformat, GLsizei, width, GLsizei, height, GLint, border, GLenum, format, GLenum, type, const void *, pixels); +DEBUG_FUNC_OVERRIDE(glTexParameteri, GLenum, target, GLenum, pname, GLint, param); +DEBUG_FUNC_OVERRIDE(glTexParameteriv, GLenum, target, GLenum, pname, const GLint *, params); +DEBUG_FUNC_OVERRIDE(glTexSubImage1D, GLenum, target, GLint, level, GLint, xoffset, GLsizei, width, GLenum, format, GLenum, type, const void *, pixels); +DEBUG_FUNC_OVERRIDE(glTexSubImage2D, GLenum, target, GLint, level, GLint, xoffset, GLint, yoffset, GLsizei, width, GLsizei, height, GLenum, format, GLenum, type, const void *, pixels); +/* clang-format on */ + } // namespace gpu } // namespace blender diff --git a/source/blender/gpu/opengl/gl_debug_layer.cc b/source/blender/gpu/opengl/gl_debug_layer.cc new file mode 100644 index 00000000000..801cb9dbfbd --- /dev/null +++ b/source/blender/gpu/opengl/gl_debug_layer.cc @@ -0,0 +1,165 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + * + * Implement our own subset of KHR_debug extension. + * We override the functions pointers by our own implementation that just checks glGetError. + */ + +#include "BLI_utildefines.h" + +#include "glew-mx.h" + +#include "gl_debug.hh" + +typedef void *GPUvoidptr; + +#define GPUvoidptr_set void *ret = +#define GPUvoidptr_ret return ret + +#define GLboolean_set GLboolean ret = +#define GLboolean_ret return ret + +#define void_set +#define void_ret + +#define DEBUG_FUNC_DECLARE(pfn, rtn_type, fn, ...) \ + pfn real_##fn; \ + static rtn_type GLAPIENTRY debug_##fn(ARG_LIST(__VA_ARGS__)) \ + { \ + debug::check_gl_error("generated before " #fn); \ + rtn_type##_set real_##fn(ARG_LIST_CALL(__VA_ARGS__)); \ + debug::check_gl_error("" #fn); \ + rtn_type##_ret; \ + } + +namespace blender::gpu::debug { + +/* List of wrapped functions. We dont have to support all of them. + * Some functions might be declared as extern in GLEW. We cannot override them in this case. + * Keep the list in alphabetical order. */ + +/* Avoid very long declarations. */ +/* clang-format off */ +DEBUG_FUNC_DECLARE(PFNGLBEGINQUERYPROC, void, glBeginQuery, GLenum, target, GLuint, id); +DEBUG_FUNC_DECLARE(PFNGLBEGINTRANSFORMFEEDBACKPROC, void, glBeginTransformFeedback, GLenum, primitiveMode); +DEBUG_FUNC_DECLARE(PFNGLBINDBUFFERBASEPROC, void, glBindBufferBase, GLenum, target, GLuint, index, GLuint, buffer); +DEBUG_FUNC_DECLARE(PFNGLBINDBUFFERPROC, void, glBindBuffer, GLenum, target, GLuint, buffer); +DEBUG_FUNC_DECLARE(PFNGLBINDFRAMEBUFFERPROC, void, glBindFramebuffer, GLenum, target, GLuint, framebuffer); +DEBUG_FUNC_DECLARE(PFNGLBINDSAMPLERPROC, void, glBindSampler, GLuint, unit, GLuint, sampler); +DEBUG_FUNC_DECLARE(PFNGLBINDVERTEXARRAYPROC, void, glBindVertexArray, GLuint, array); +DEBUG_FUNC_DECLARE(PFNGLBLITFRAMEBUFFERPROC, void, glBlitFramebuffer, GLint, srcX0, GLint, srcY0, GLint, srcX1, GLint, srcY1, GLint, dstX0, GLint, dstY0, GLint, dstX1, GLint, dstY1, GLbitfield, mask, GLenum, filter); +DEBUG_FUNC_DECLARE(PFNGLBUFFERDATAPROC, void, glBufferData, GLenum, target, GLsizeiptr, size, const void *, data, GLenum, usage); +DEBUG_FUNC_DECLARE(PFNGLBUFFERSUBDATAPROC, void, glBufferSubData, GLenum, target, GLintptr, offset, GLsizeiptr, size, const void *, data); +DEBUG_FUNC_DECLARE(PFNGLDELETEBUFFERSPROC, void, glDeleteBuffers, GLsizei, n, const GLuint *, buffers); +DEBUG_FUNC_DECLARE(PFNGLDELETEFRAMEBUFFERSPROC, void, glDeleteFramebuffers, GLsizei, n, const GLuint*, framebuffers); +DEBUG_FUNC_DECLARE(PFNGLDELETEPROGRAMPROC, void, glDeleteProgram, GLuint, program); +DEBUG_FUNC_DECLARE(PFNGLDELETEQUERIESPROC, void, glDeleteQueries, GLsizei, n, const GLuint *, ids); +DEBUG_FUNC_DECLARE(PFNGLDELETESAMPLERSPROC, void, glDeleteSamplers, GLsizei, count, const GLuint *, samplers); +DEBUG_FUNC_DECLARE(PFNGLDELETESHADERPROC, void, glDeleteShader, GLuint, shader); +DEBUG_FUNC_DECLARE(PFNGLDELETEVERTEXARRAYSPROC, void, glDeleteVertexArrays, GLsizei, n, const GLuint *, arrays); +DEBUG_FUNC_DECLARE(PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC, void, glDrawArraysInstancedBaseInstance, GLenum, mode, GLint, first, GLsizei, count, GLsizei, primcount, GLuint, baseinstance); +DEBUG_FUNC_DECLARE(PFNGLDRAWARRAYSINSTANCEDPROC, void, glDrawArraysInstanced, GLenum, mode, GLint, first, GLsizei, count, GLsizei, primcount); +DEBUG_FUNC_DECLARE(PFNGLDRAWBUFFERSPROC, void, glDrawBuffers, GLsizei, n, const GLenum*, bufs); +DEBUG_FUNC_DECLARE(PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC, void, glDrawElementsInstancedBaseVertexBaseInstance, GLenum, mode, GLsizei, count, GLenum, type, const void *, indices, GLsizei, primcount, GLint, basevertex, GLuint, baseinstance); +DEBUG_FUNC_DECLARE(PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC, void, glDrawElementsInstancedBaseVertex, GLenum, mode, GLsizei, count, GLenum, type, const void *, indices, GLsizei, instancecount, GLint, basevertex); +DEBUG_FUNC_DECLARE(PFNGLENDQUERYPROC, void, glEndQuery, GLenum, target); +DEBUG_FUNC_DECLARE(PFNGLENDTRANSFORMFEEDBACKPROC, void, glEndTransformFeedback, void); +DEBUG_FUNC_DECLARE(PFNGLFRAMEBUFFERTEXTURE2DPROC, void, glFramebufferTexture2D, GLenum, target, GLenum, attachment, GLenum, textarget, GLuint, texture, GLint, level); +DEBUG_FUNC_DECLARE(PFNGLFRAMEBUFFERTEXTURELAYERPROC, void, glFramebufferTextureLayer, GLenum, target, GLenum, attachment, GLuint, texture, GLint, level, GLint, layer); +DEBUG_FUNC_DECLARE(PFNGLFRAMEBUFFERTEXTUREPROC, void, glFramebufferTexture, GLenum, target, GLenum, attachment, GLuint, texture, GLint, level); +DEBUG_FUNC_DECLARE(PFNGLGENBUFFERSPROC, void, glGenBuffers, GLsizei, n, GLuint *, buffers); +DEBUG_FUNC_DECLARE(PFNGLGENERATEMIPMAPPROC, void, glGenerateMipmap, GLenum, target); +DEBUG_FUNC_DECLARE(PFNGLGENERATETEXTUREMIPMAPPROC, void, glGenerateTextureMipmap, GLuint, texture); +DEBUG_FUNC_DECLARE(PFNGLGENFRAMEBUFFERSPROC, void, glGenFramebuffers, GLsizei, n, GLuint *, framebuffers); +DEBUG_FUNC_DECLARE(PFNGLGENQUERIESPROC, void, glGenQueries, GLsizei, n, GLuint *, ids); +DEBUG_FUNC_DECLARE(PFNGLGENSAMPLERSPROC, void, glGenSamplers, GLsizei, n, GLuint *, samplers); +DEBUG_FUNC_DECLARE(PFNGLGENVERTEXARRAYSPROC, void, glGenVertexArrays, GLsizei, n, GLuint *, arrays); +DEBUG_FUNC_DECLARE(PFNGLLINKPROGRAMPROC, void, glLinkProgram, GLuint, program); +DEBUG_FUNC_DECLARE(PFNGLMAPBUFFERRANGEPROC, GPUvoidptr, glMapBufferRange, GLenum, target, GLintptr, offset, GLsizeiptr, length, GLbitfield, access); +DEBUG_FUNC_DECLARE(PFNGLTEXBUFFERPROC, void, glTexBuffer, GLenum, target, GLenum, internalFormat, GLuint, buffer); +DEBUG_FUNC_DECLARE(PFNGLTEXIMAGE3DPROC, void, glTexImage3D, GLenum, target, GLint, level, GLint, internalFormat, GLsizei, width, GLsizei, height, GLsizei, depth, GLint, border, GLenum, format, GLenum, type, const GLvoid *,pixels); +DEBUG_FUNC_DECLARE(PFNGLTEXSUBIMAGE3DPROC, void, glTexSubImage3D, GLenum, target, GLint, level, GLint, xoffset, GLint, yoffset, GLint, zoffset, GLsizei, width, GLsizei, height, GLsizei, depth, GLenum, format, GLenum, type, const GLvoid *, pixels); +DEBUG_FUNC_DECLARE(PFNGLTEXTUREBUFFERPROC, void, glTextureBuffer, GLuint, texture, GLenum, internalformat, GLuint, buffer); +DEBUG_FUNC_DECLARE(PFNGLUNMAPBUFFERPROC, GLboolean, glUnmapBuffer, GLenum, target); +DEBUG_FUNC_DECLARE(PFNGLUSEPROGRAMPROC, void, glUseProgram, GLuint, program); +/* clang-format on */ + +#undef DEBUG_FUNC_DECLARE + +/* Init a fallback layer (to KHR_debug) that covers only some functions. + * We override the functions pointers by our own implementation that just checks glGetError. + * Some additional functions (not overridable) are covered inside the header using wrappers. */ +void init_debug_layer(void) +{ +#define DEBUG_WRAP(function) \ + do { \ + real_##function = ::function; \ + ::function = &debug_##function; \ + } while (0) + + DEBUG_WRAP(glBeginQuery); + DEBUG_WRAP(glBeginTransformFeedback); + DEBUG_WRAP(glBindBuffer); + DEBUG_WRAP(glBindBufferBase); + DEBUG_WRAP(glBindFramebuffer); + DEBUG_WRAP(glBindSampler); + DEBUG_WRAP(glBindVertexArray); + DEBUG_WRAP(glBlitFramebuffer); + DEBUG_WRAP(glBufferData); + DEBUG_WRAP(glBufferSubData); + DEBUG_WRAP(glDeleteBuffers); + DEBUG_WRAP(glDeleteFramebuffers); + DEBUG_WRAP(glDeleteProgram); + DEBUG_WRAP(glDeleteQueries); + DEBUG_WRAP(glDeleteSamplers); + DEBUG_WRAP(glDeleteShader); + DEBUG_WRAP(glDeleteVertexArrays); + DEBUG_WRAP(glDrawArraysInstanced); + DEBUG_WRAP(glDrawArraysInstancedBaseInstance); + DEBUG_WRAP(glDrawBuffers); + DEBUG_WRAP(glDrawElementsInstancedBaseVertex); + DEBUG_WRAP(glDrawElementsInstancedBaseVertexBaseInstance); + DEBUG_WRAP(glEndQuery); + DEBUG_WRAP(glEndTransformFeedback); + DEBUG_WRAP(glFramebufferTexture); + DEBUG_WRAP(glFramebufferTexture2D); + DEBUG_WRAP(glFramebufferTextureLayer); + DEBUG_WRAP(glGenBuffers); + DEBUG_WRAP(glGenerateMipmap); + DEBUG_WRAP(glGenerateTextureMipmap); + DEBUG_WRAP(glGenFramebuffers); + DEBUG_WRAP(glGenQueries); + DEBUG_WRAP(glGenSamplers); + DEBUG_WRAP(glGenVertexArrays); + DEBUG_WRAP(glLinkProgram); + DEBUG_WRAP(glMapBufferRange); + DEBUG_WRAP(glTexBuffer); + DEBUG_WRAP(glTexImage3D); + DEBUG_WRAP(glTexSubImage3D); + DEBUG_WRAP(glTextureBuffer); + DEBUG_WRAP(glUnmapBuffer); + DEBUG_WRAP(glUseProgram); + +#undef DEBUG_WRAP +} + +} // namespace blender::gpu::debug
\ No newline at end of file diff --git a/source/blender/gpu/opengl/gl_drawlist.cc b/source/blender/gpu/opengl/gl_drawlist.cc index 6e3b1107b9c..990e1a8014b 100644 --- a/source/blender/gpu/opengl/gl_drawlist.cc +++ b/source/blender/gpu/opengl/gl_drawlist.cc @@ -41,8 +41,6 @@ #include <limits.h> -#define USE_MULTI_DRAW_INDIRECT 1 - using namespace blender::gpu; typedef struct GLDrawCommand { @@ -75,8 +73,7 @@ GLDrawList::GLDrawList(int length) data_size_ = 0; data_ = NULL; - if (USE_MULTI_DRAW_INDIRECT && GLEW_ARB_multi_draw_indirect && - GLContext::base_instance_support) { + if (GLContext::multi_draw_indirect_support) { /* Alloc the biggest possible command list, which is indexed. */ buffer_size_ = sizeof(GLDrawCommandIndexed) * length; } diff --git a/source/blender/gpu/opengl/gl_framebuffer.cc b/source/blender/gpu/opengl/gl_framebuffer.cc index bfc8a2f74eb..1578c5fa619 100644 --- a/source/blender/gpu/opengl/gl_framebuffer.cc +++ b/source/blender/gpu/opengl/gl_framebuffer.cc @@ -26,10 +26,12 @@ #include "GPU_capabilities.h" #include "gl_backend.hh" -#include "gl_framebuffer.hh" +#include "gl_debug.hh" #include "gl_state.hh" #include "gl_texture.hh" +#include "gl_framebuffer.hh" + namespace blender::gpu { /* -------------------------------------------------------------------- */ @@ -63,10 +65,8 @@ GLFrameBuffer::GLFrameBuffer( viewport_[2] = scissor_[2] = w; viewport_[3] = scissor_[3] = h; - if (fbo_id_ && GLContext::debug_layer_support) { - char sh_name[32]; - SNPRINTF(sh_name, "FrameBuffer-%s", name); - glObjectLabel(GL_FRAMEBUFFER, fbo_id_, -1, sh_name); + if (fbo_id_) { + debug::object_label(GL_FRAMEBUFFER, fbo_id_, name_); } } @@ -97,14 +97,11 @@ void GLFrameBuffer::init(void) context_ = GLContext::get(); state_manager_ = static_cast<GLStateManager *>(context_->state_manager); glGenFramebuffers(1, &fbo_id_); + /* Binding before setting the label is needed on some drivers. + * This is not an issue since we call this function only before binding. */ + glBindFramebuffer(GL_FRAMEBUFFER, fbo_id_); - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "FrameBuffer-%s", name_); - /* Binding before setting the label is needed on some drivers. */ - glBindFramebuffer(GL_FRAMEBUFFER, fbo_id_); - glObjectLabel(GL_FRAMEBUFFER, fbo_id_, -1, sh_name); - } + debug::object_label(GL_FRAMEBUFFER, fbo_id_, name_); } /** \} */ diff --git a/source/blender/gpu/opengl/gl_immediate.cc b/source/blender/gpu/opengl/gl_immediate.cc index 7afbbf9965c..fd31d77cc80 100644 --- a/source/blender/gpu/opengl/gl_immediate.cc +++ b/source/blender/gpu/opengl/gl_immediate.cc @@ -60,11 +60,9 @@ GLImmediate::GLImmediate() glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); - if (GLContext::debug_layer_support) { - glObjectLabel(GL_VERTEX_ARRAY, vao_id_, -1, "VAO-Immediate"); - glObjectLabel(GL_BUFFER, buffer.vbo_id, -1, "VBO-ImmediateBuffer"); - glObjectLabel(GL_BUFFER, buffer_strict.vbo_id, -1, "VBO-ImmediateBufferStrict"); - } + debug::object_label(GL_VERTEX_ARRAY, vao_id_, "Immediate"); + debug::object_label(GL_BUFFER, buffer.vbo_id, "ImmediateVbo"); + debug::object_label(GL_BUFFER, buffer_strict.vbo_id, "ImmediateVboStrict"); } GLImmediate::~GLImmediate() @@ -89,7 +87,6 @@ uchar *GLImmediate::begin() const size_t available_bytes = buffer_size() - buffer_offset(); GL_CHECK_RESOURCES("Immediate"); - GL_CHECK_ERROR("Immediate Pre-Begin"); glBindBuffer(GL_ARRAY_BUFFER, vbo_id()); @@ -133,7 +130,6 @@ uchar *GLImmediate::begin() } void *data = glMapBufferRange(GL_ARRAY_BUFFER, buffer_offset(), bytes_needed, access); BLI_assert(data != NULL); - GL_CHECK_ERROR("Immediate Post-Begin"); bytes_mapped_ = bytes_needed; return (uchar *)data; @@ -155,8 +151,6 @@ void GLImmediate::end(void) } glUnmapBuffer(GL_ARRAY_BUFFER); - GL_CHECK_ERROR("Immediate Post-Unmap"); - if (vertex_len > 0) { GLContext::get()->state_manager->apply_state(); @@ -180,8 +174,6 @@ void GLImmediate::end(void) * They are not required so just comment them. (T55722) */ // glBindBuffer(GL_ARRAY_BUFFER, 0); // glBindVertexArray(0); - - GL_CHECK_ERROR("Immediate Post-drawing"); } buffer_offset() += buffer_bytes_used; diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index 4314ecfa6be..c400f218f5a 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -28,6 +28,7 @@ #include "GPU_platform.h" #include "gl_backend.hh" +#include "gl_debug.hh" #include "gl_vertex_buffer.hh" #include "gl_shader.hh" @@ -48,11 +49,7 @@ GLShader::GLShader(const char *name) : Shader(name) #endif shader_program_ = glCreateProgram(); - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "ShaderProgram-%s", name); - glObjectLabel(GL_PROGRAM, shader_program_, -1, sh_name); - } + debug::object_label(GL_PROGRAM, shader_program_, name); } GLShader::~GLShader(void) @@ -88,25 +85,15 @@ char *GLShader::glsl_patch_get(void) /* Enable extensions for features that are not part of our base GLSL version * don't use an extension for something already available! */ - if (GLEW_ARB_texture_gather) { - /* There is a bug on older Nvidia GPU where GL_ARB_texture_gather - * is reported to be supported but yield a compile error (see T55802). */ - if (!GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY) || GLEW_VERSION_4_0) { - STR_CONCAT(patch, slen, "#extension GL_ARB_texture_gather: enable\n"); - - /* Some drivers don't agree on GLEW_ARB_texture_gather and the actual support in the - * shader so double check the preprocessor define (see T56544). */ - if (!GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY) && !GLEW_VERSION_4_0) { - STR_CONCAT(patch, slen, "#ifdef GL_ARB_texture_gather\n"); - STR_CONCAT(patch, slen, "# define GPU_ARB_texture_gather\n"); - STR_CONCAT(patch, slen, "#endif\n"); - } - else { - STR_CONCAT(patch, slen, "#define GPU_ARB_texture_gather\n"); - } - } + if (GLContext::texture_gather_support) { + STR_CONCAT(patch, slen, "#extension GL_ARB_texture_gather: enable\n"); + /* Some drivers don't agree on GLEW_ARB_texture_gather and the actual support in the + * shader so double check the preprocessor define (see T56544). */ + STR_CONCAT(patch, slen, "#ifdef GL_ARB_texture_gather\n"); + STR_CONCAT(patch, slen, "# define GPU_ARB_texture_gather\n"); + STR_CONCAT(patch, slen, "#endif\n"); } - if (GLEW_ARB_shader_draw_parameters) { + if (GLContext::shader_draw_parameters_support) { STR_CONCAT(patch, slen, "#extension GL_ARB_shader_draw_parameters : enable\n"); STR_CONCAT(patch, slen, "#define GPU_ARB_shader_draw_parameters\n"); } @@ -163,21 +150,7 @@ GLuint GLShader::create_shader_stage(GLenum gl_stage, MutableSpan<const char *> return 0; } - if (GLContext::debug_layer_support) { - char sh_name[64]; - switch (gl_stage) { - case GL_VERTEX_SHADER: - BLI_snprintf(sh_name, sizeof(sh_name), "VertShader-%s", name); - break; - case GL_GEOMETRY_SHADER: - BLI_snprintf(sh_name, sizeof(sh_name), "GeomShader-%s", name); - break; - case GL_FRAGMENT_SHADER: - BLI_snprintf(sh_name, sizeof(sh_name), "FragShader-%s", name); - break; - } - glObjectLabel(GL_SHADER, shader, -1, sh_name); - } + debug::object_label(gl_stage, shader, name); glAttachShader(shader_program_, shader); return shader; diff --git a/source/blender/gpu/opengl/gl_state.cc b/source/blender/gpu/opengl/gl_state.cc index 6dcb56288e8..1678760e9cd 100644 --- a/source/blender/gpu/opengl/gl_state.cc +++ b/source/blender/gpu/opengl/gl_state.cc @@ -30,6 +30,7 @@ #include "glew-mx.h" #include "gl_context.hh" +#include "gl_debug.hh" #include "gl_framebuffer.hh" #include "gl_texture.hh" @@ -55,7 +56,7 @@ GLStateManager::GLStateManager(void) : GPUStateManager() glPrimitiveRestartIndex((GLuint)0xFFFFFFFF); /* TODO: Should become default. But needs at least GL 4.3 */ - if (GLEW_ARB_ES3_compatibility) { + if (GLContext::fixed_restart_index_support) { /* Takes precedence over #GL_PRIMITIVE_RESTART. */ glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); } @@ -140,13 +141,13 @@ void GLStateManager::set_mutable_state(const GPUStateMutable &state) GPUStateMutable changed = state ^ current_mutable_; /* TODO remove, should be uniform. */ - if (changed.point_size != 0) { + if (float_as_uint(changed.point_size) != 0) { if (state.point_size > 0.0f) { glEnable(GL_PROGRAM_POINT_SIZE); - glPointSize(state.point_size); } else { glDisable(GL_PROGRAM_POINT_SIZE); + glPointSize(fabsf(state.point_size)); } } @@ -453,7 +454,6 @@ void GLStateManager::texture_bind(Texture *tex_, eGPUSamplerState sampler_type, /* Bind the texture to slot 0 for editing purpose. Used by legacy pipeline. */ void GLStateManager::texture_bind_temp(GLTexture *tex) { - // BLI_assert(!GLEW_ARB_direct_state_access); glActiveTexture(GL_TEXTURE0); glBindTexture(tex->target_, tex->tex_id_); /* Will reset the first texture that was originally bound to slot 0 back before drawing. */ @@ -505,7 +505,7 @@ void GLStateManager::texture_bind_apply(void) int last = 64 - bitscan_reverse_uint64(dirty_bind); int count = last - first; - if (GLEW_ARB_multi_bind) { + if (GLContext::multi_bind_support) { glBindTextures(first, count, textures_ + first); glBindSamplers(first, count, samplers_ + first); } diff --git a/source/blender/gpu/opengl/gl_state.hh b/source/blender/gpu/opengl/gl_state.hh index db9b9721ad5..fb2ed3403f7 100644 --- a/source/blender/gpu/opengl/gl_state.hh +++ b/source/blender/gpu/opengl/gl_state.hh @@ -42,8 +42,8 @@ class GLTexture; **/ class GLStateManager : public GPUStateManager { public: - /** Anothter reference to tje active framebuffer. */ - GLFrameBuffer *active_fb; + /** Anothter reference to the active framebuffer. */ + GLFrameBuffer *active_fb = nullptr; private: /** Current state of the GL implementation. Avoids resetting the whole state for every change. */ diff --git a/source/blender/gpu/opengl/gl_texture.cc b/source/blender/gpu/opengl/gl_texture.cc index ec08b736af2..ef4b2d1d4d3 100644 --- a/source/blender/gpu/opengl/gl_texture.cc +++ b/source/blender/gpu/opengl/gl_texture.cc @@ -89,21 +89,14 @@ bool GLTexture::init_internal(void) this->ensure_mipmaps(0); /* Avoid issue with incomplete textures. */ - if (GLEW_ARB_direct_state_access) { + if (GLContext::direct_state_access_support) { glTextureParameteri(tex_id_, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } else { glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "Texture-%s", name_); - /* Binding before setting the label is needed on some drivers. */ - glObjectLabel(GL_TEXTURE, tex_id_, -1, sh_name); - } - - GL_CHECK_ERROR("Post-texture creation"); + debug::object_label(GL_TEXTURE, tex_id_, name_); return true; } @@ -118,21 +111,15 @@ bool GLTexture::init_internal(GPUVertBuf *vbo) GLenum internal_format = to_gl_internal_format(format_); - if (GLEW_ARB_direct_state_access) { + if (GLContext::direct_state_access_support) { glTextureBuffer(tex_id_, internal_format, gl_vbo->vbo_id_); } else { glTexBuffer(target_, internal_format, gl_vbo->vbo_id_); } - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "Texture-%s", name_); - /* Binding before setting the label is needed on some drivers. */ - glObjectLabel(GL_TEXTURE, tex_id_, -1, sh_name); - } + debug::object_label(GL_TEXTURE, tex_id_, name_); - GL_CHECK_ERROR("Post-texture buffer creation"); return true; } @@ -193,8 +180,6 @@ void GLTexture::ensure_mipmaps(int miplvl) break; } } - - GL_CHECK_ERROR("Post-mipmap creation"); } this->mip_range_set(0, mipmaps_); @@ -240,7 +225,6 @@ void GLTexture::update_sub_direct_state_access( break; } } - GL_CHECK_ERROR("Post-update_sub_direct_state_access"); } void GLTexture::update_sub( @@ -260,8 +244,8 @@ void GLTexture::update_sub( GLenum gl_format = to_gl_data_format(format_); GLenum gl_type = to_gl(type); - /* Some drivers have issues with cubemap & glTextureSubImage3D even if it correct. */ - if (GLEW_ARB_direct_state_access && (type_ != GPU_TEXTURE_CUBE)) { + /* Some drivers have issues with cubemap & glTextureSubImage3D even if it is correct. */ + if (GLContext::direct_state_access_support && (type_ != GPU_TEXTURE_CUBE)) { this->update_sub_direct_state_access(mip, offset, extent, gl_format, gl_type, data); return; } @@ -304,8 +288,6 @@ void GLTexture::update_sub( break; } } - - GL_CHECK_ERROR("Post-update_sub"); } /** This will create the mipmap images and populate them with filtered data from base level. @@ -324,7 +306,7 @@ void GLTexture::generate_mipmap(void) } /* Downsample from mip 0 using implementation. */ - if (GLEW_ARB_direct_state_access) { + if (GLContext::direct_state_access_support) { glGenerateTextureMipmap(tex_id_); } else { @@ -337,7 +319,7 @@ void GLTexture::clear(eGPUDataFormat data_format, const void *data) { BLI_assert(validate_data_format(format_, data_format)); - if (GLEW_ARB_clear_texture && !(G.debug & G_DEBUG_GPU_FORCE_WORKAROUNDS)) { + if (GLContext::clear_texture_support) { int mip = 0; GLenum gl_format = to_gl_data_format(format_); GLenum gl_type = to_gl(data_format); @@ -366,8 +348,7 @@ void GLTexture::copy_to(Texture *dst_) /* TODO support array / 3D textures. */ BLI_assert(dst->d_ == 0); - if (GLEW_ARB_copy_image && !GLContext::texture_copy_workaround) { - /* Opengl 4.3 */ + if (GLContext::copy_image_support) { int mip = 0; /* NOTE: mip_size_get() won't override any dimension that is equal to 0. */ int extent[3] = {1, 1, 1}; @@ -403,7 +384,7 @@ void *GLTexture::read(int mip, eGPUDataFormat type) GLenum gl_format = to_gl_data_format(format_); GLenum gl_type = to_gl(type); - if (GLEW_ARB_direct_state_access) { + if (GLContext::direct_state_access_support) { glGetTextureImage(tex_id_, mip, gl_format, gl_type, texture_size, data); } else { @@ -434,7 +415,7 @@ void GLTexture::swizzle_set(const char swizzle[4]) (GLint)swizzle_to_gl(swizzle[1]), (GLint)swizzle_to_gl(swizzle[2]), (GLint)swizzle_to_gl(swizzle[3])}; - if (GLEW_ARB_direct_state_access) { + if (GLContext::direct_state_access_support) { glTextureParameteriv(tex_id_, GL_TEXTURE_SWIZZLE_RGBA, gl_swizzle); } else { @@ -448,7 +429,7 @@ void GLTexture::mip_range_set(int min, int max) BLI_assert(min <= max && min >= 0 && max <= mipmaps_); mip_min_ = min; mip_max_ = max; - if (GLEW_ARB_direct_state_access) { + if (GLContext::direct_state_access_support) { glTextureParameteri(tex_id_, GL_TEXTURE_BASE_LEVEL, min); glTextureParameteri(tex_id_, GL_TEXTURE_MAX_LEVEL, max); } @@ -510,22 +491,20 @@ void GLTexture::samplers_init(void) * - GL_TEXTURE_LOD_BIAS is 0.0f. **/ - if (GLContext::debug_layer_support) { - char sampler_name[128]; - SNPRINTF(sampler_name, - "Sampler%s%s%s%s%s%s%s%s%s%s", - (state == GPU_SAMPLER_DEFAULT) ? "_default" : "", - (state & GPU_SAMPLER_FILTER) ? "_filter" : "", - (state & GPU_SAMPLER_MIPMAP) ? "_mipmap" : "", - (state & GPU_SAMPLER_REPEAT) ? "_repeat-" : "", - (state & GPU_SAMPLER_REPEAT_S) ? "S" : "", - (state & GPU_SAMPLER_REPEAT_T) ? "T" : "", - (state & GPU_SAMPLER_REPEAT_R) ? "R" : "", - (state & GPU_SAMPLER_CLAMP_BORDER) ? "_clamp_border" : "", - (state & GPU_SAMPLER_COMPARE) ? "_compare" : "", - (state & GPU_SAMPLER_ANISO) ? "_aniso" : ""); - glObjectLabel(GL_SAMPLER, samplers_[i], -1, sampler_name); - } + char sampler_name[128] = "\0\0"; + SNPRINTF(sampler_name, + "%s%s%s%s%s%s%s%s%s%s", + (state == GPU_SAMPLER_DEFAULT) ? "_default" : "", + (state & GPU_SAMPLER_FILTER) ? "_filter" : "", + (state & GPU_SAMPLER_MIPMAP) ? "_mipmap" : "", + (state & GPU_SAMPLER_REPEAT) ? "_repeat-" : "", + (state & GPU_SAMPLER_REPEAT_S) ? "S" : "", + (state & GPU_SAMPLER_REPEAT_T) ? "T" : "", + (state & GPU_SAMPLER_REPEAT_R) ? "R" : "", + (state & GPU_SAMPLER_CLAMP_BORDER) ? "_clamp_border" : "", + (state & GPU_SAMPLER_COMPARE) ? "_compare" : "", + (state & GPU_SAMPLER_ANISO) ? "_aniso" : ""); + debug::object_label(GL_SAMPLER, samplers_[i], &sampler_name[1]); } samplers_update(); @@ -535,14 +514,12 @@ void GLTexture::samplers_init(void) glSamplerParameteri(icon_sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glSamplerParameterf(icon_sampler, GL_TEXTURE_LOD_BIAS, -0.5f); - if (GLContext::debug_layer_support) { - glObjectLabel(GL_SAMPLER, icon_sampler, -1, "Sampler-icons"); - } + debug::object_label(GL_SAMPLER, icon_sampler, "icons"); } void GLTexture::samplers_update(void) { - if (!GLEW_EXT_texture_filter_anisotropic) { + if (!GLContext::texture_filter_anisotropic_support) { return; } diff --git a/source/blender/gpu/opengl/gl_uniform_buffer.cc b/source/blender/gpu/opengl/gl_uniform_buffer.cc index 74453a08bfe..dd305fca555 100644 --- a/source/blender/gpu/opengl/gl_uniform_buffer.cc +++ b/source/blender/gpu/opengl/gl_uniform_buffer.cc @@ -29,6 +29,7 @@ #include "gpu_context_private.hh" #include "gl_backend.hh" +#include "gl_debug.hh" #include "gl_uniform_buffer.hh" namespace blender::gpu { @@ -62,11 +63,7 @@ void GLUniformBuf::init(void) glBindBuffer(GL_UNIFORM_BUFFER, ubo_id_); glBufferData(GL_UNIFORM_BUFFER, size_in_bytes_, NULL, GL_DYNAMIC_DRAW); - if (GLContext::debug_layer_support) { - char sh_name[64]; - SNPRINTF(sh_name, "UBO-%s", name_); - glObjectLabel(GL_BUFFER, ubo_id_, -1, sh_name); - } + debug::object_label(GL_UNIFORM_BUFFER, ubo_id_, name_); } void GLUniformBuf::update(const void *data) diff --git a/source/blender/gpu/opengl/gl_vertex_array.cc b/source/blender/gpu/opengl/gl_vertex_array.cc index 732221cfab3..14a7b4deb7d 100644 --- a/source/blender/gpu/opengl/gl_vertex_array.cc +++ b/source/blender/gpu/opengl/gl_vertex_array.cc @@ -135,7 +135,7 @@ void GLVertArray::update_bindings(const GLuint vao, } } - if (attr_mask != 0 && GLEW_ARB_vertex_attrib_binding) { + if (attr_mask != 0 && GLContext::vertex_attrib_binding_support) { for (uint16_t mask = 1, a = 0; a < 16; a++, mask <<= 1) { if (attr_mask & mask) { GLContext *ctx = GLContext::get(); diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl index 640ceb97e5b..bdc0d37a7ae 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl @@ -11,29 +11,33 @@ uniform vec4 calls_data[MAX_CALLS * 3]; out vec2 texCoord_interp; flat out vec4 finalColor; +in vec2 pos; + void main() { - vec4 pos = calls_data[gl_InstanceID * 3]; + vec4 rect = calls_data[gl_InstanceID * 3]; vec4 tex = calls_data[gl_InstanceID * 3 + 1]; finalColor = calls_data[gl_InstanceID * 3 + 2]; - if (gl_VertexID == 0) { - pos.xy = pos.xz; + /* Use pos to select the right swizzle (instead of gl_VertexID) + * in order to workaround an OSX driver bug. */ + if (pos == vec2(0.0, 0.0)) { + rect.xy = rect.xz; tex.xy = tex.xz; } - else if (gl_VertexID == 1) { - pos.xy = pos.xw; + else if (pos == vec2(0.0, 1.0)) { + rect.xy = rect.xw; tex.xy = tex.xw; } - else if (gl_VertexID == 2) { - pos.xy = pos.yw; + else if (pos == vec2(1.0, 1.0)) { + rect.xy = rect.yw; tex.xy = tex.yw; } else { - pos.xy = pos.yz; + rect.xy = rect.yz; tex.xy = tex.yz; } - gl_Position = vec4(pos.xy, 0.0f, 1.0f); + gl_Position = vec4(rect.xy, 0.0f, 1.0f); texCoord_interp = tex.xy; } diff --git a/source/blender/ikplugin/intern/iksolver_plugin.c b/source/blender/ikplugin/intern/iksolver_plugin.c index ba096653e0f..c7d8a8b3723 100644 --- a/source/blender/ikplugin/intern/iksolver_plugin.c +++ b/source/blender/ikplugin/intern/iksolver_plugin.c @@ -583,8 +583,8 @@ static void free_posetree(PoseTree *tree) MEM_freeN(tree); } -///---------------------------------------- -/// Plugin API for legacy iksolver +/* ------------------------------ + * Plugin API for legacy iksolver */ void iksolver_initialize_tree(struct Depsgraph *UNUSED(depsgraph), struct Scene *UNUSED(scene), diff --git a/source/blender/imbuf/intern/dds/BlockDXT.cpp b/source/blender/imbuf/intern/dds/BlockDXT.cpp index 1fbe7b46963..8978b823e2a 100644 --- a/source/blender/imbuf/intern/dds/BlockDXT.cpp +++ b/source/blender/imbuf/intern/dds/BlockDXT.cpp @@ -247,14 +247,14 @@ void BlockDXT1::setIndices(const int *idx) } } -/// Flip DXT1 block vertically. +/** Flip DXT1 block vertically. */ inline void BlockDXT1::flip4() { swap(row[0], row[3]); swap(row[1], row[2]); } -/// Flip half DXT1 block vertically. +/** Flip half DXT1 block vertically. */ inline void BlockDXT1::flip2() { swap(row[0], row[1]); @@ -299,27 +299,27 @@ void AlphaBlockDXT3::decodeBlock(ColorBlock *block) const block->color(0xF).a = (alphaF << 4) | alphaF; } -/// Flip DXT3 alpha block vertically. +/** Flip DXT3 alpha block vertically. */ void AlphaBlockDXT3::flip4() { swap(row[0], row[3]); swap(row[1], row[2]); } -/// Flip half DXT3 alpha block vertically. +/** Flip half DXT3 alpha block vertically. */ void AlphaBlockDXT3::flip2() { swap(row[0], row[1]); } -/// Flip DXT3 block vertically. +/** Flip DXT3 block vertically. */ void BlockDXT3::flip4() { alpha.flip4(); color.flip4(); } -/// Flip half DXT3 block vertically. +/** Flip half DXT3 block vertically. */ void BlockDXT3::flip2() { alpha.flip2(); @@ -458,21 +458,21 @@ void BlockDXT5::decodeBlockNV5x(ColorBlock *block) const alpha.decodeBlock(block); } -/// Flip DXT5 block vertically. +/** Flip DXT5 block vertically. */ void BlockDXT5::flip4() { alpha.flip4(); color.flip4(); } -/// Flip half DXT5 block vertically. +/** Flip half DXT5 block vertically. */ void BlockDXT5::flip2() { alpha.flip2(); color.flip2(); } -/// Decode ATI1 block. +/** Decode ATI1 block. */ void BlockATI1::decodeBlock(ColorBlock *block) const { uint8 alpha_array[8]; @@ -488,19 +488,19 @@ void BlockATI1::decodeBlock(ColorBlock *block) const } } -/// Flip ATI1 block vertically. +/** Flip ATI1 block vertically. */ void BlockATI1::flip4() { alpha.flip4(); } -/// Flip half ATI1 block vertically. +/** Flip half ATI1 block vertically. */ void BlockATI1::flip2() { alpha.flip2(); } -/// Decode ATI2 block. +/** Decode ATI2 block. */ void BlockATI2::decodeBlock(ColorBlock *block) const { uint8 alpha_array[8]; @@ -525,14 +525,14 @@ void BlockATI2::decodeBlock(ColorBlock *block) const } } -/// Flip ATI2 block vertically. +/** Flip ATI2 block vertically. */ void BlockATI2::flip4() { x.flip4(); y.flip4(); } -/// Flip half ATI2 block vertically. +/** Flip half ATI2 block vertically. */ void BlockATI2::flip2() { x.flip2(); @@ -586,14 +586,14 @@ void BlockCTX1::setIndices(const int *idx) } } -/// Flip CTX1 block vertically. +/** Flip CTX1 block vertically. */ inline void BlockCTX1::flip4() { swap(row[0], row[3]); swap(row[1], row[2]); } -/// Flip half CTX1 block vertically. +/** Flip half CTX1 block vertically. */ inline void BlockCTX1::flip2() { swap(row[0], row[1]); diff --git a/source/blender/imbuf/intern/dds/BlockDXT.h b/source/blender/imbuf/intern/dds/BlockDXT.h index 70ec8808c61..83cc147c76c 100644 --- a/source/blender/imbuf/intern/dds/BlockDXT.h +++ b/source/blender/imbuf/intern/dds/BlockDXT.h @@ -55,7 +55,7 @@ #include <Common.h> #include <Stream.h> -/// DXT1 block. +/** DXT1 block. */ struct BlockDXT1 { Color16 col0; Color16 col1; @@ -81,13 +81,13 @@ struct BlockDXT1 { void flip2(); }; -/// Return true if the block uses four color mode, false otherwise. +/** Return true if the block uses four color mode, false otherwise. */ inline bool BlockDXT1::isFourColorMode() const { return col0.u > col1.u; } -/// DXT3 alpha block with explicit alpha. +/** DXT3 alpha block with explicit alpha. */ struct AlphaBlockDXT3 { union { struct { @@ -117,7 +117,7 @@ struct AlphaBlockDXT3 { void flip2(); }; -/// DXT3 block. +/** DXT3 block. */ struct BlockDXT3 { AlphaBlockDXT3 alpha; BlockDXT1 color; @@ -129,7 +129,7 @@ struct BlockDXT3 { void flip2(); }; -/// DXT5 alpha block. +/** DXT5 alpha block. */ struct AlphaBlockDXT5 { // uint64 unions do not compile on all platforms #if 0 @@ -245,7 +245,7 @@ struct AlphaBlockDXT5 { void flip2(); }; -/// DXT5 block. +/** DXT5 block. */ struct BlockDXT5 { AlphaBlockDXT5 alpha; BlockDXT1 color; @@ -257,7 +257,7 @@ struct BlockDXT5 { void flip2(); }; -/// ATI1 block. +/** ATI1 block. */ struct BlockATI1 { AlphaBlockDXT5 alpha; @@ -267,7 +267,7 @@ struct BlockATI1 { void flip2(); }; -/// ATI2 block. +/** ATI2 block. */ struct BlockATI2 { AlphaBlockDXT5 x; AlphaBlockDXT5 y; @@ -278,7 +278,7 @@ struct BlockATI2 { void flip2(); }; -/// CTX1 block. +/** CTX1 block. */ struct BlockCTX1 { uint8 col0[2]; uint8 col1[2]; diff --git a/source/blender/imbuf/intern/dds/Color.h b/source/blender/imbuf/intern/dds/Color.h index d0b67d4638c..4a9202617f5 100644 --- a/source/blender/imbuf/intern/dds/Color.h +++ b/source/blender/imbuf/intern/dds/Color.h @@ -29,7 +29,7 @@ #pragma once -/// 32 bit color stored as BGRA. +/** 32 bit color stored as BGRA. */ class Color32 { public: Color32() @@ -93,7 +93,7 @@ class Color32 { }; }; -/// 16 bit 565 BGR color. +/** 16 bit 565 BGR color. */ class Color16 { public: Color16() diff --git a/source/blender/imbuf/intern/dds/ColorBlock.cpp b/source/blender/imbuf/intern/dds/ColorBlock.cpp index 69757d797b5..f2e8e0b0313 100644 --- a/source/blender/imbuf/intern/dds/ColorBlock.cpp +++ b/source/blender/imbuf/intern/dds/ColorBlock.cpp @@ -46,12 +46,12 @@ inline static uint colorDistance(Color32 c0, Color32 c1) } #endif -/// Default constructor. +/** Default constructor. */ ColorBlock::ColorBlock() { } -/// Init the color block from an array of colors. +/** Init the color block from an array of colors. */ ColorBlock::ColorBlock(const uint *linearImage) { for (uint i = 0; i < 16; i++) { @@ -59,7 +59,7 @@ ColorBlock::ColorBlock(const uint *linearImage) } } -/// Init the color block with the contents of the given block. +/** Init the color block with the contents of the given block. */ ColorBlock::ColorBlock(const ColorBlock &block) { for (uint i = 0; i < 16; i++) { @@ -67,7 +67,7 @@ ColorBlock::ColorBlock(const ColorBlock &block) } } -/// Initialize this color block. +/** Initialize this color block. */ ColorBlock::ColorBlock(const Image *img, uint x, uint y) { init(img, x, y); @@ -159,7 +159,7 @@ void ColorBlock::swizzle(uint x, uint y, uint z, uint w) } } -/// Returns true if the block has a single color. +/** Returns true if the block has a single color. */ bool ColorBlock::isSingleColor(Color32 mask /*= Color32(0xFF, 0xFF, 0xFF, 0x00)*/) const { uint u = m_color[0].u & mask.u; @@ -174,7 +174,7 @@ bool ColorBlock::isSingleColor(Color32 mask /*= Color32(0xFF, 0xFF, 0xFF, 0x00)* } #if 0 -/// Returns true if the block has a single color, ignoring transparent pixels. +/** Returns true if the block has a single color, ignoring transparent pixels. */ bool ColorBlock::isSingleColorNoAlpha() const { Color32 c; @@ -199,7 +199,7 @@ bool ColorBlock::isSingleColorNoAlpha() const #endif #if 0 -/// Count number of unique colors in this color block. +/** Count number of unique colors in this color block. */ uint ColorBlock::countUniqueColors() const { uint count = 0; @@ -223,7 +223,7 @@ uint ColorBlock::countUniqueColors() const #endif #if 0 -/// Get average color of the block. +/** Get average color of the block. */ Color32 ColorBlock::averageColor() const { uint r, g, b, a; @@ -240,7 +240,7 @@ Color32 ColorBlock::averageColor() const } #endif -/// Return true if the block is not fully opaque. +/** Return true if the block is not fully opaque. */ bool ColorBlock::hasAlpha() const { for (uint i = 0; i < 16; i++) { @@ -253,7 +253,7 @@ bool ColorBlock::hasAlpha() const #if 0 -/// Get diameter color range. +/** Get diameter color range. */ void ColorBlock::diameterRange(Color32 *start, Color32 *end) const { Color32 c0, c1; @@ -274,7 +274,7 @@ void ColorBlock::diameterRange(Color32 *start, Color32 *end) const *end = c1; } -/// Get luminance color range. +/** Get luminance color range. */ void ColorBlock::luminanceRange(Color32 *start, Color32 *end) const { Color32 minColor, maxColor; @@ -299,7 +299,7 @@ void ColorBlock::luminanceRange(Color32 *start, Color32 *end) const *end = maxColor; } -/// Get color range based on the bounding box. +/** Get color range based on the bounding box. */ void ColorBlock::boundsRange(Color32 *start, Color32 *end) const { Color32 minColor(255, 255, 255); @@ -344,7 +344,7 @@ void ColorBlock::boundsRange(Color32 *start, Color32 *end) const *end = maxColor; } -/// Get color range based on the bounding box. +/** Get color range based on the bounding box. */ void ColorBlock::boundsRangeAlpha(Color32 *start, Color32 *end) const { Color32 minColor(255, 255, 255, 255); @@ -400,7 +400,7 @@ void ColorBlock::boundsRangeAlpha(Color32 *start, Color32 *end) const #endif #if 0 -/// Sort colors by abosolute value in their 16 bit representation. +/** Sort colors by abosolute value in their 16 bit representation. */ void ColorBlock::sortColorsByAbsoluteValue() { // Dummy selection sort. @@ -422,7 +422,7 @@ void ColorBlock::sortColorsByAbsoluteValue() #endif #if 0 -/// Find extreme colors in the given axis. +/** Find extreme colors in the given axis. */ void ColorBlock::computeRange(Vector3::Arg axis, Color32 *start, Color32 *end) const { @@ -452,7 +452,7 @@ void ColorBlock::computeRange(Vector3::Arg axis, Color32 *start, Color32 *end) c #endif #if 0 -/// Sort colors in the given axis. +/** Sort colors in the given axis. */ void ColorBlock::sortColors(const Vector3 &axis) { float luma_array[16]; @@ -477,7 +477,7 @@ void ColorBlock::sortColors(const Vector3 &axis) #endif #if 0 -/// Get the volume of the color block. +/** Get the volume of the color block. */ float ColorBlock::volume() const { Box bounds; diff --git a/source/blender/imbuf/intern/dds/ColorBlock.h b/source/blender/imbuf/intern/dds/ColorBlock.h index dd63286e230..98b4c9cb40a 100644 --- a/source/blender/imbuf/intern/dds/ColorBlock.h +++ b/source/blender/imbuf/intern/dds/ColorBlock.h @@ -32,7 +32,7 @@ #include <Color.h> #include <Image.h> -/// Uncompressed 4x4 color block. +/** Uncompressed 4x4 color block. */ struct ColorBlock { ColorBlock(); ColorBlock(const uint *linearImage); @@ -61,31 +61,31 @@ struct ColorBlock { Color32 m_color[4 * 4]; }; -/// Get pointer to block colors. +/** Get pointer to block colors. */ inline const Color32 *ColorBlock::colors() const { return m_color; } -/// Get block color. +/** Get block color. */ inline Color32 ColorBlock::color(uint i) const { return m_color[i]; } -/// Get block color. +/** Get block color. */ inline Color32 &ColorBlock::color(uint i) { return m_color[i]; } -/// Get block color. +/** Get block color. */ inline Color32 ColorBlock::color(uint x, uint y) const { return m_color[y * 4 + x]; } -/// Get block color. +/** Get block color. */ inline Color32 &ColorBlock::color(uint x, uint y) { return m_color[y * 4 + x]; diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.h b/source/blender/imbuf/intern/dds/DirectDrawSurface.h index ac7f893fddd..373d5974a5e 100644 --- a/source/blender/imbuf/intern/dds/DirectDrawSurface.h +++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.h @@ -73,7 +73,7 @@ struct DDSCaps { uint caps4; }; -/// DDS file header for DX10. +/** DDS file header for DX10. */ struct DDSHeader10 { uint dxgiFormat; uint resourceDimension; @@ -82,7 +82,7 @@ struct DDSHeader10 { uint reserved; }; -/// DDS file header. +/** DDS file header. */ struct DDSHeader { uint fourcc; uint size; @@ -132,7 +132,7 @@ struct DDSHeader { uint d3d9Format() const; }; -/// DirectDraw Surface. (DDS) +/** DirectDraw Surface. (DDS) */ class DirectDrawSurface { public: DirectDrawSurface(unsigned char *mem, uint size); diff --git a/source/blender/imbuf/intern/dds/Image.h b/source/blender/imbuf/intern/dds/Image.h index 4ccfec99445..0f977641d89 100644 --- a/source/blender/imbuf/intern/dds/Image.h +++ b/source/blender/imbuf/intern/dds/Image.h @@ -32,7 +32,7 @@ #include "Color.h" #include "Common.h" -/// 32 bit RGBA image. +/** 32 bit RGBA image. */ class Image { public: enum Format { diff --git a/source/blender/io/alembic/exporter/abc_archive.cc b/source/blender/io/alembic/exporter/abc_archive.cc index 5fbf74f0705..a181a721de9 100644 --- a/source/blender/io/alembic/exporter/abc_archive.cc +++ b/source/blender/io/alembic/exporter/abc_archive.cc @@ -37,9 +37,7 @@ # include "utfconv.h" #endif -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::Abc::ErrorHandler; using Alembic::Abc::kWrapExisting; @@ -260,6 +258,4 @@ void ABCArchive::update_bounding_box(const Imath::Box3d &bounds) abc_archive_bbox_.set(bounds); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_archive.h b/source/blender/io/alembic/exporter/abc_archive.h index 43d0acf2520..8e6e5e40663 100644 --- a/source/blender/io/alembic/exporter/abc_archive.h +++ b/source/blender/io/alembic/exporter/abc_archive.h @@ -36,9 +36,7 @@ struct Main; struct Scene; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* Container for an Alembic archive and time sampling info. * @@ -82,6 +80,4 @@ class ABCArchive { Alembic::Abc::OBox3dProperty abc_archive_bbox_; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_export_capi.cc b/source/blender/io/alembic/exporter/abc_export_capi.cc index 6412379c126..c22864a5433 100644 --- a/source/blender/io/alembic/exporter/abc_export_capi.cc +++ b/source/blender/io/alembic/exporter/abc_export_capi.cc @@ -62,9 +62,7 @@ struct ExportJobData { bool export_ok; }; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { // Construct the depsgraph for exporting. static void build_depsgraph(Depsgraph *depsgraph, const bool visible_objects_only) @@ -197,9 +195,7 @@ static void export_endjob(void *customdata) WM_set_locked_interface(data->wm, false); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic bool ABC_export(Scene *scene, bContext *C, diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc index 4cb6ca0c601..e2be241c144 100644 --- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc +++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc @@ -40,9 +40,7 @@ #include "DNA_layer_types.h" #include "DNA_object_types.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { ABCHierarchyIterator::ABCHierarchyIterator(Depsgraph *depsgraph, ABCArchive *abc_archive, @@ -275,6 +273,4 @@ AbstractHierarchyWriter *ABCHierarchyIterator::create_particle_writer( return particle_writer.release(); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h index 5bc82564cdb..a0d9257b822 100644 --- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h +++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h @@ -32,9 +32,7 @@ struct Depsgraph; struct ID; struct Object; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCAbstractWriter; class ABCHierarchyIterator; @@ -93,6 +91,4 @@ class ABCHierarchyIterator : public AbstractHierarchyIterator { const HierarchyContext *context, const ABCWriterConstructorArgs &writer_args); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_subdiv_disabler.cc b/source/blender/io/alembic/exporter/abc_subdiv_disabler.cc index 7c147076975..255803a6bfb 100644 --- a/source/blender/io/alembic/exporter/abc_subdiv_disabler.cc +++ b/source/blender/io/alembic/exporter/abc_subdiv_disabler.cc @@ -32,9 +32,7 @@ #include "BKE_modifier.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { SubdivModifierDisabler::SubdivModifierDisabler(Depsgraph *depsgraph) : depsgraph_(depsgraph) { @@ -102,6 +100,4 @@ ModifierData *SubdivModifierDisabler::get_subdiv_modifier(Scene *scene, Object * return nullptr; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_subdiv_disabler.h b/source/blender/io/alembic/exporter/abc_subdiv_disabler.h index 677847f3f63..3556df7ff31 100644 --- a/source/blender/io/alembic/exporter/abc_subdiv_disabler.h +++ b/source/blender/io/alembic/exporter/abc_subdiv_disabler.h @@ -25,9 +25,7 @@ struct ModifierData; struct Object; struct Scene; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /** * Temporarily all subdivision modifiers on mesh objects. @@ -50,6 +48,4 @@ class SubdivModifierDisabler final { static ModifierData *get_subdiv_modifier(Scene *scene, Object *ob); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_abstract.cc b/source/blender/io/alembic/exporter/abc_writer_abstract.cc index 84527a12e85..0b08d8c4e58 100644 --- a/source/blender/io/alembic/exporter/abc_writer_abstract.cc +++ b/source/blender/io/alembic/exporter/abc_writer_abstract.cc @@ -32,9 +32,7 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.alembic"}; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::Abc::OObject; using Alembic::Abc::TimeSamplingPtr; @@ -112,6 +110,4 @@ void ABCAbstractWriter::write_visibility(const HierarchyContext &context) Alembic::AbcGeom::kVisibilityHidden); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_abstract.h b/source/blender/io/alembic/exporter/abc_writer_abstract.h index fefa9c356f2..59c55330443 100644 --- a/source/blender/io/alembic/exporter/abc_writer_abstract.h +++ b/source/blender/io/alembic/exporter/abc_writer_abstract.h @@ -30,9 +30,7 @@ struct Material; struct Object; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCAbstractWriter : public AbstractHierarchyWriter { protected: @@ -77,6 +75,4 @@ class ABCAbstractWriter : public AbstractHierarchyWriter { void write_visibility(const HierarchyContext &context); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_camera.cc b/source/blender/io/alembic/exporter/abc_writer_camera.cc index 6f13f791c4e..0ce6c3dc07f 100644 --- a/source/blender/io/alembic/exporter/abc_writer_camera.cc +++ b/source/blender/io/alembic/exporter/abc_writer_camera.cc @@ -31,9 +31,7 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.alembic"}; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::AbcGeom::CameraSample; using Alembic::AbcGeom::OCamera; @@ -105,6 +103,4 @@ void ABCCameraWriter::do_write(HierarchyContext &context) abc_camera_schema_.set(camera_sample); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_camera.h b/source/blender/io/alembic/exporter/abc_writer_camera.h index ceaa352d162..1b3e5898517 100644 --- a/source/blender/io/alembic/exporter/abc_writer_camera.h +++ b/source/blender/io/alembic/exporter/abc_writer_camera.h @@ -23,9 +23,7 @@ #include <Alembic/AbcGeom/OCamera.h> -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCCameraWriter : public ABCAbstractWriter { private: @@ -47,6 +45,4 @@ class ABCCameraWriter : public ABCAbstractWriter { virtual void do_write(HierarchyContext &context) override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_curves.cc b/source/blender/io/alembic/exporter/abc_writer_curves.cc index 9d65830c699..6a12e4c59f3 100644 --- a/source/blender/io/alembic/exporter/abc_writer_curves.cc +++ b/source/blender/io/alembic/exporter/abc_writer_curves.cc @@ -41,9 +41,7 @@ using Alembic::AbcGeom::OInt16Property; using Alembic::AbcGeom::ON3fGeomParam; using Alembic::AbcGeom::OV2fGeomParam; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { const std::string ABC_CURVE_RESOLUTION_U_PROPNAME("blender:resolution"); @@ -196,6 +194,4 @@ Mesh *ABCCurveMeshWriter::get_export_mesh(Object *object_eval, bool &r_needsfree return BKE_mesh_new_nomain_from_curve(object_eval); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_curves.h b/source/blender/io/alembic/exporter/abc_writer_curves.h index cd6621c398d..d15f008f947 100644 --- a/source/blender/io/alembic/exporter/abc_writer_curves.h +++ b/source/blender/io/alembic/exporter/abc_writer_curves.h @@ -27,9 +27,7 @@ #include <Alembic/AbcGeom/OCurves.h> -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { extern const std::string ABC_CURVE_RESOLUTION_U_PROPNAME; @@ -56,6 +54,4 @@ class ABCCurveMeshWriter : public ABCGenericMeshWriter { virtual Mesh *get_export_mesh(Object *object_eval, bool &r_needsfree) override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_hair.cc b/source/blender/io/alembic/exporter/abc_writer_hair.cc index 1e1d2cf32ca..80034245b84 100644 --- a/source/blender/io/alembic/exporter/abc_writer_hair.cc +++ b/source/blender/io/alembic/exporter/abc_writer_hair.cc @@ -43,9 +43,7 @@ using Alembic::AbcGeom::OCurvesSchema; using Alembic::AbcGeom::ON3fGeomParam; using Alembic::AbcGeom::OV2fGeomParam; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { ABCHairWriter::ABCHairWriter(const ABCWriterConstructorArgs &args) : ABCAbstractWriter(args), uv_warning_shown_(false) @@ -306,6 +304,4 @@ void ABCHairWriter::write_hair_child_sample(const HierarchyContext &context, } } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_hair.h b/source/blender/io/alembic/exporter/abc_writer_hair.h index 0e149b0d045..f7d988ecbc4 100644 --- a/source/blender/io/alembic/exporter/abc_writer_hair.h +++ b/source/blender/io/alembic/exporter/abc_writer_hair.h @@ -26,9 +26,7 @@ struct ParticleSettings; struct ParticleSystem; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCHairWriter : public ABCAbstractWriter { private: @@ -63,6 +61,4 @@ class ABCHairWriter : public ABCAbstractWriter { std::vector<int32_t> &hvertices); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_instance.cc b/source/blender/io/alembic/exporter/abc_writer_instance.cc index 581d94ee961..14c65e2a2e2 100644 --- a/source/blender/io/alembic/exporter/abc_writer_instance.cc +++ b/source/blender/io/alembic/exporter/abc_writer_instance.cc @@ -26,9 +26,7 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.alembic"}; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::Abc::OObject; @@ -69,6 +67,4 @@ void ABCInstanceWriter::do_write(HierarchyContext & /*context*/) /* Instances don't have data to be written. Just creating them is enough. */ } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_instance.h b/source/blender/io/alembic/exporter/abc_writer_instance.h index 74379b9d6bd..067c4af7aed 100644 --- a/source/blender/io/alembic/exporter/abc_writer_instance.h +++ b/source/blender/io/alembic/exporter/abc_writer_instance.h @@ -21,9 +21,7 @@ #include "abc_writer_abstract.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* Writer for Alembic instances, i.e. data that references another Alembic object. * @@ -43,6 +41,4 @@ class ABCInstanceWriter : public ABCAbstractWriter { virtual void do_write(HierarchyContext &context) override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_mball.cc b/source/blender/io/alembic/exporter/abc_writer_mball.cc index 167e392eb96..a797310f864 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mball.cc +++ b/source/blender/io/alembic/exporter/abc_writer_mball.cc @@ -32,9 +32,7 @@ #include "DNA_mesh_types.h" #include "DNA_meta_types.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { ABCMetaballWriter::ABCMetaballWriter(const ABCWriterConstructorArgs &args) : ABCGenericMeshWriter(args) @@ -85,6 +83,4 @@ bool ABCMetaballWriter::is_basis_ball(Scene *scene, Object *ob) const return ob == basis_ob; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_mball.h b/source/blender/io/alembic/exporter/abc_writer_mball.h index 90d8c4d4b15..f96daa6d84b 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mball.h +++ b/source/blender/io/alembic/exporter/abc_writer_mball.h @@ -21,9 +21,7 @@ #include "abc_writer_mesh.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCMetaballWriter : public ABCGenericMeshWriter { public: @@ -40,6 +38,4 @@ class ABCMetaballWriter : public ABCGenericMeshWriter { bool is_basis_ball(Scene *scene, Object *ob) const; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.cc b/source/blender/io/alembic/exporter/abc_writer_mesh.cc index a9c722cae91..b762ad47932 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mesh.cc +++ b/source/blender/io/alembic/exporter/abc_writer_mesh.cc @@ -66,9 +66,7 @@ using Alembic::AbcGeom::OSubDSchema; using Alembic::AbcGeom::OV2fGeomParam; using Alembic::AbcGeom::UInt32ArraySample; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* NOTE: Alembic's polygon winding order is clockwise, to match with Renderman. */ @@ -551,6 +549,4 @@ Mesh *ABCMeshWriter::get_export_mesh(Object *object_eval, bool & /*r_needsfree*/ return BKE_object_get_evaluated_mesh(object_eval); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.h b/source/blender/io/alembic/exporter/abc_writer_mesh.h index 2bb5b687c47..956587df7c0 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mesh.h +++ b/source/blender/io/alembic/exporter/abc_writer_mesh.h @@ -27,9 +27,7 @@ struct ModifierData; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* Writer for Alembic geometry. Does not assume the object is a mesh object. */ class ABCGenericMeshWriter : public ABCAbstractWriter { @@ -90,6 +88,4 @@ class ABCMeshWriter : public ABCGenericMeshWriter { virtual Mesh *get_export_mesh(Object *object_eval, bool &r_needsfree) override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_nurbs.cc b/source/blender/io/alembic/exporter/abc_writer_nurbs.cc index a2dc4441b75..de1870fefd9 100644 --- a/source/blender/io/alembic/exporter/abc_writer_nurbs.cc +++ b/source/blender/io/alembic/exporter/abc_writer_nurbs.cc @@ -31,9 +31,7 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.alembic"}; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::Abc::OObject; using Alembic::AbcGeom::FloatArraySample; @@ -181,6 +179,4 @@ void ABCNurbsWriter::do_write(HierarchyContext &context) } } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_nurbs.h b/source/blender/io/alembic/exporter/abc_writer_nurbs.h index f7fd8ffe91a..691390ffc9f 100644 --- a/source/blender/io/alembic/exporter/abc_writer_nurbs.h +++ b/source/blender/io/alembic/exporter/abc_writer_nurbs.h @@ -23,9 +23,7 @@ #include "abc_writer_mesh.h" #include <vector> -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCNurbsWriter : public ABCAbstractWriter { private: @@ -52,6 +50,4 @@ class ABCNurbsMeshWriter : public ABCGenericMeshWriter { virtual Mesh *get_export_mesh(Object *object_eval, bool &r_needsfree) override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_points.cc b/source/blender/io/alembic/exporter/abc_writer_points.cc index 350b70b9552..83d33577b3b 100644 --- a/source/blender/io/alembic/exporter/abc_writer_points.cc +++ b/source/blender/io/alembic/exporter/abc_writer_points.cc @@ -36,9 +36,7 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.alembic"}; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::AbcGeom::kVertexScope; using Alembic::AbcGeom::OPoints; @@ -143,6 +141,4 @@ void ABCPointsWriter::do_write(HierarchyContext &context) abc_points_schema_.set(sample); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_points.h b/source/blender/io/alembic/exporter/abc_writer_points.h index 88dd424ca2a..fec5e84f3f2 100644 --- a/source/blender/io/alembic/exporter/abc_writer_points.h +++ b/source/blender/io/alembic/exporter/abc_writer_points.h @@ -26,9 +26,7 @@ #include <Alembic/AbcGeom/OPoints.h> -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCPointsWriter : public ABCAbstractWriter { Alembic::AbcGeom::OPoints abc_points_; @@ -47,6 +45,4 @@ class ABCPointsWriter : public ABCAbstractWriter { virtual void do_write(HierarchyContext &context) override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_transform.cc b/source/blender/io/alembic/exporter/abc_writer_transform.cc index 93ffd847bf2..a72a6b47aa9 100644 --- a/source/blender/io/alembic/exporter/abc_writer_transform.cc +++ b/source/blender/io/alembic/exporter/abc_writer_transform.cc @@ -33,9 +33,7 @@ #include "CLG_log.h" static CLG_LogRef LOG = {"io.alembic"}; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { using Alembic::Abc::OObject; using Alembic::AbcGeom::OXform; @@ -115,6 +113,4 @@ bool ABCTransformWriter::check_is_animated(const HierarchyContext &context) cons return BKE_object_moves_in_time(context.object, context.animation_check_include_parent); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/exporter/abc_writer_transform.h b/source/blender/io/alembic/exporter/abc_writer_transform.h index 9d172531d1f..a334fe610ee 100644 --- a/source/blender/io/alembic/exporter/abc_writer_transform.h +++ b/source/blender/io/alembic/exporter/abc_writer_transform.h @@ -23,9 +23,7 @@ #include <Alembic/AbcGeom/OXform.h> -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class ABCTransformWriter : public ABCAbstractWriter { private: @@ -42,6 +40,4 @@ class ABCTransformWriter : public ABCAbstractWriter { virtual Alembic::Abc::OObject get_alembic_object() const override; }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_axis_conversion.cc b/source/blender/io/alembic/intern/abc_axis_conversion.cc index 396c8fdb28b..23b24d2fd9a 100644 --- a/source/blender/io/alembic/intern/abc_axis_conversion.cc +++ b/source/blender/io/alembic/intern/abc_axis_conversion.cc @@ -25,9 +25,7 @@ #include "DNA_object_types.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { void create_swapped_rotation_matrix(float rot_x_mat[3][3], float rot_y_mat[3][3], @@ -168,6 +166,4 @@ void create_transform_matrix(Object *obj, copy_m44_axis_swap(r_yup_mat, zup_mat, ABC_YUP_FROM_ZUP); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_axis_conversion.h b/source/blender/io/alembic/intern/abc_axis_conversion.h index 797592d9eee..30988222fb7 100644 --- a/source/blender/io/alembic/intern/abc_axis_conversion.h +++ b/source/blender/io/alembic/intern/abc_axis_conversion.h @@ -26,9 +26,7 @@ struct Object; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* TODO(kevin): for now keeping these transformations hardcoded to make sure * everything works properly, and also because Alembic is almost exclusively @@ -98,6 +96,4 @@ void create_transform_matrix(Object *obj, AbcMatrixMode mode, Object *proxy_from); -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_customdata.cc b/source/blender/io/alembic/intern/abc_customdata.cc index 408894a8de2..66e05504303 100644 --- a/source/blender/io/alembic/intern/abc_customdata.cc +++ b/source/blender/io/alembic/intern/abc_customdata.cc @@ -50,9 +50,7 @@ using Alembic::Abc::V2fArraySample; using Alembic::AbcGeom::OC4fGeomParam; using Alembic::AbcGeom::OV2fGeomParam; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { static void get_uvs(const CDStreamConfig &config, std::vector<Imath::V2f> &uvs, @@ -489,6 +487,4 @@ void read_custom_data(const std::string &iobject_full_name, } } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_customdata.h b/source/blender/io/alembic/intern/abc_customdata.h index 8f4accb70dc..e98ec271b9f 100644 --- a/source/blender/io/alembic/intern/abc_customdata.h +++ b/source/blender/io/alembic/intern/abc_customdata.h @@ -36,9 +36,7 @@ struct Mesh; using Alembic::Abc::ICompoundProperty; using Alembic::Abc::OCompoundProperty; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { struct UVSample { std::vector<Imath::V2f> uvs; @@ -113,6 +111,4 @@ void read_custom_data(const std::string &iobject_full_name, const CDStreamConfig &config, const Alembic::Abc::ISampleSelector &iss); -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_archive.cc b/source/blender/io/alembic/intern/abc_reader_archive.cc index 776b8955d47..4951dc0e035 100644 --- a/source/blender/io/alembic/intern/abc_reader_archive.cc +++ b/source/blender/io/alembic/intern/abc_reader_archive.cc @@ -39,9 +39,7 @@ using Alembic::Abc::Exception; using Alembic::Abc::IArchive; using Alembic::Abc::kWrapExisting; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { static IArchive open_archive(const std::string &filename, const std::vector<std::istream *> &input_streams) @@ -108,6 +106,4 @@ Alembic::Abc::IObject ArchiveReader::getTop() return m_archive.getTop(); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_archive.h b/source/blender/io/alembic/intern/abc_reader_archive.h index aea62b46cce..2a4fd6bd8fb 100644 --- a/source/blender/io/alembic/intern/abc_reader_archive.h +++ b/source/blender/io/alembic/intern/abc_reader_archive.h @@ -30,9 +30,7 @@ struct Main; struct Scene; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* Wrappers around input and output archives. The goal is to be able to use * streams so that unicode paths work on Windows (T49112), and to make sure that @@ -52,6 +50,4 @@ class ArchiveReader { Alembic::Abc::IObject getTop(); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_camera.cc b/source/blender/io/alembic/intern/abc_reader_camera.cc index 3affb35908d..d7a096a4ed8 100644 --- a/source/blender/io/alembic/intern/abc_reader_camera.cc +++ b/source/blender/io/alembic/intern/abc_reader_camera.cc @@ -37,9 +37,7 @@ using Alembic::AbcGeom::IFloatProperty; using Alembic::AbcGeom::ISampleSelector; using Alembic::AbcGeom::kWrapExisting; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { AbcCameraReader::AbcCameraReader(const Alembic::Abc::IObject &object, ImportSettings &settings) : AbcObjectReader(object, settings) @@ -114,6 +112,4 @@ void AbcCameraReader::readObjectData(Main *bmain, const ISampleSelector &sample_ m_object->data = bcam; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_camera.h b/source/blender/io/alembic/intern/abc_reader_camera.h index b733269407b..408e9623970 100644 --- a/source/blender/io/alembic/intern/abc_reader_camera.h +++ b/source/blender/io/alembic/intern/abc_reader_camera.h @@ -21,9 +21,7 @@ #include "abc_reader_object.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcCameraReader : public AbcObjectReader { Alembic::AbcGeom::ICameraSchema m_schema; @@ -39,6 +37,4 @@ class AbcCameraReader : public AbcObjectReader { void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_curves.cc b/source/blender/io/alembic/intern/abc_reader_curves.cc index a505dfd654b..e29b6eda6fc 100644 --- a/source/blender/io/alembic/intern/abc_reader_curves.cc +++ b/source/blender/io/alembic/intern/abc_reader_curves.cc @@ -54,9 +54,7 @@ using Alembic::AbcGeom::IInt16Property; using Alembic::AbcGeom::ISampleSelector; using Alembic::AbcGeom::kWrapExisting; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { AbcCurveReader::AbcCurveReader(const Alembic::Abc::IObject &object, ImportSettings &settings) : AbcObjectReader(object, settings) @@ -356,6 +354,4 @@ Mesh *AbcCurveReader::read_mesh(Mesh *existing_mesh, return BKE_mesh_new_nomain_from_curve(m_object); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_curves.h b/source/blender/io/alembic/intern/abc_reader_curves.h index 7488adb9b24..075ed5ca6a1 100644 --- a/source/blender/io/alembic/intern/abc_reader_curves.h +++ b/source/blender/io/alembic/intern/abc_reader_curves.h @@ -29,9 +29,7 @@ struct Curve; #define ABC_CURVE_RESOLUTION_U_PROPNAME "blender:resolution" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcCurveReader : public AbcObjectReader { Alembic::AbcGeom::ICurvesSchema m_curves_schema; @@ -55,6 +53,4 @@ class AbcCurveReader : public AbcObjectReader { const Alembic::Abc::ISampleSelector &sample_selector); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index 98130eb28cd..5a42be2bb02 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -60,9 +60,7 @@ using Alembic::AbcGeom::N3fArraySamplePtr; using Alembic::AbcGeom::UInt32ArraySamplePtr; using Alembic::AbcGeom::V2fArraySamplePtr; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { /* NOTE: Alembic's polygon winding order is clockwise, to match with Renderman. */ @@ -936,6 +934,4 @@ Mesh *AbcSubDReader::read_mesh(Mesh *existing_mesh, return config.mesh; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.h b/source/blender/io/alembic/intern/abc_reader_mesh.h index 363a74b8b5f..a29eeb71dff 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.h +++ b/source/blender/io/alembic/intern/abc_reader_mesh.h @@ -24,9 +24,7 @@ struct Mesh; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcMeshReader : public AbcObjectReader { Alembic::AbcGeom::IPolyMeshSchema m_schema; @@ -85,6 +83,4 @@ void read_mverts(MVert *mverts, CDStreamConfig get_config(struct Mesh *mesh); -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_nurbs.cc b/source/blender/io/alembic/intern/abc_reader_nurbs.cc index 3ca3f6229ab..27d4ec44a27 100644 --- a/source/blender/io/alembic/intern/abc_reader_nurbs.cc +++ b/source/blender/io/alembic/intern/abc_reader_nurbs.cc @@ -44,9 +44,7 @@ using Alembic::AbcGeom::INuPatch; using Alembic::AbcGeom::INuPatchSchema; using Alembic::AbcGeom::IObject; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { AbcNurbsReader::AbcNurbsReader(const IObject &object, ImportSettings &settings) : AbcObjectReader(object, settings) @@ -227,6 +225,4 @@ void AbcNurbsReader::getNurbsPatches(const IObject &obj) } } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_nurbs.h b/source/blender/io/alembic/intern/abc_reader_nurbs.h index 738da82885d..e8be2efba9f 100644 --- a/source/blender/io/alembic/intern/abc_reader_nurbs.h +++ b/source/blender/io/alembic/intern/abc_reader_nurbs.h @@ -21,9 +21,7 @@ #include "abc_reader_object.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcNurbsReader : public AbcObjectReader { std::vector<std::pair<Alembic::AbcGeom::INuPatchSchema, Alembic::Abc::IObject>> m_schemas; @@ -39,6 +37,4 @@ class AbcNurbsReader : public AbcObjectReader { void getNurbsPatches(const Alembic::Abc::IObject &obj); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_object.cc b/source/blender/io/alembic/intern/abc_reader_object.cc index 06b0c07f4c5..1e832de1f47 100644 --- a/source/blender/io/alembic/intern/abc_reader_object.cc +++ b/source/blender/io/alembic/intern/abc_reader_object.cc @@ -41,9 +41,7 @@ using Alembic::AbcGeom::IObject; using Alembic::AbcGeom::IXform; using Alembic::AbcGeom::IXformSchema; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { AbcObjectReader::AbcObjectReader(const IObject &object, ImportSettings &settings) : m_name(""), @@ -335,6 +333,4 @@ void AbcObjectReader::decref() BLI_assert(m_refcount >= 0); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_object.h b/source/blender/io/alembic/intern/abc_reader_object.h index 0bde60b06b5..8e00ed42777 100644 --- a/source/blender/io/alembic/intern/abc_reader_object.h +++ b/source/blender/io/alembic/intern/abc_reader_object.h @@ -31,9 +31,7 @@ struct Object; using Alembic::AbcCoreAbstract::chrono_t; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { struct ImportSettings { bool do_convert_mat; @@ -168,6 +166,4 @@ class AbcObjectReader { Imath::M44d get_matrix(const Alembic::AbcGeom::IXformSchema &schema, const float time); -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_points.cc b/source/blender/io/alembic/intern/abc_reader_points.cc index b805da4daa3..f8cc6b0314a 100644 --- a/source/blender/io/alembic/intern/abc_reader_points.cc +++ b/source/blender/io/alembic/intern/abc_reader_points.cc @@ -43,9 +43,7 @@ using Alembic::AbcGeom::IPoints; using Alembic::AbcGeom::IPointsSchema; using Alembic::AbcGeom::ISampleSelector; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { AbcPointsReader::AbcPointsReader(const Alembic::Abc::IObject &object, ImportSettings &settings) : AbcObjectReader(object, settings) @@ -158,6 +156,4 @@ struct Mesh *AbcPointsReader::read_mesh(struct Mesh *existing_mesh, return new_mesh ? new_mesh : existing_mesh; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_points.h b/source/blender/io/alembic/intern/abc_reader_points.h index 8a970ac35b3..aed66699c75 100644 --- a/source/blender/io/alembic/intern/abc_reader_points.h +++ b/source/blender/io/alembic/intern/abc_reader_points.h @@ -25,9 +25,7 @@ #include "abc_customdata.h" #include "abc_reader_object.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcPointsReader : public AbcObjectReader { Alembic::AbcGeom::IPointsSchema m_schema; @@ -53,6 +51,4 @@ void read_points_sample(const Alembic::AbcGeom::IPointsSchema &schema, const Alembic::AbcGeom::ISampleSelector &selector, CDStreamConfig &config); -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_transform.cc b/source/blender/io/alembic/intern/abc_reader_transform.cc index 456d1da2c68..3aab2f2d339 100644 --- a/source/blender/io/alembic/intern/abc_reader_transform.cc +++ b/source/blender/io/alembic/intern/abc_reader_transform.cc @@ -29,9 +29,7 @@ using Alembic::Abc::ISampleSelector; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { AbcEmptyReader::AbcEmptyReader(const Alembic::Abc::IObject &object, ImportSettings &settings) : AbcObjectReader(object, settings) @@ -77,6 +75,4 @@ void AbcEmptyReader::readObjectData(Main *bmain, const ISampleSelector &UNUSED(s m_object->data = NULL; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_reader_transform.h b/source/blender/io/alembic/intern/abc_reader_transform.h index 812d3bdfc92..e515560912f 100644 --- a/source/blender/io/alembic/intern/abc_reader_transform.h +++ b/source/blender/io/alembic/intern/abc_reader_transform.h @@ -23,9 +23,7 @@ #include <Alembic/AbcGeom/All.h> -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcEmptyReader : public AbcObjectReader { Alembic::AbcGeom::IXformSchema m_schema; @@ -41,6 +39,4 @@ class AbcEmptyReader : public AbcObjectReader { void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel); }; -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_util.cc b/source/blender/io/alembic/intern/abc_util.cc index 04febd7bfcb..edb20da89a5 100644 --- a/source/blender/io/alembic/intern/abc_util.cc +++ b/source/blender/io/alembic/intern/abc_util.cc @@ -38,9 +38,7 @@ #include "PIL_time.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { std::string get_id_name(const Object *const ob) { @@ -261,6 +259,4 @@ std::ostream &operator<<(std::ostream &os, const SimpleLogger &logger) return os; } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/intern/abc_util.h b/source/blender/io/alembic/intern/abc_util.h index 4689173ab5f..98f4b0376a7 100644 --- a/source/blender/io/alembic/intern/abc_util.h +++ b/source/blender/io/alembic/intern/abc_util.h @@ -36,9 +36,7 @@ using Alembic::Abc::chrono_t; struct ID; struct Object; -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AbcObjectReader; struct ImportSettings; @@ -161,6 +159,4 @@ class SimpleLogger { */ std::ostream &operator<<(std::ostream &os, const SimpleLogger &logger); -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/tests/abc_export_test.cc b/source/blender/io/alembic/tests/abc_export_test.cc index c602868b07e..625dbfd176f 100644 --- a/source/blender/io/alembic/tests/abc_export_test.cc +++ b/source/blender/io/alembic/tests/abc_export_test.cc @@ -12,9 +12,7 @@ #include "DEG_depsgraph.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { class AlembicExportTest : public testing::Test { protected: @@ -159,6 +157,4 @@ TEST_F(AlembicExportTest, TimeSamples180degShutter) EXPECT_NEAR(32 + 0.15, frames[9], 1e-5); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/alembic/tests/abc_matrix_test.cc b/source/blender/io/alembic/tests/abc_matrix_test.cc index b58e989b1a1..02ef1a99348 100644 --- a/source/blender/io/alembic/tests/abc_matrix_test.cc +++ b/source/blender/io/alembic/tests/abc_matrix_test.cc @@ -6,9 +6,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" -namespace blender { -namespace io { -namespace alembic { +namespace blender::io::alembic { TEST(abc_matrix, CreateRotationMatrixY_YfromZ) { @@ -287,6 +285,4 @@ TEST(abc_matrix, CopyM44AxisSwapWithScale_gimbal_ZfromY) EXPECT_M4_NEAR(expect, result, 1e-5f); } -} // namespace alembic -} // namespace io -} // namespace blender +} // namespace blender::io::alembic diff --git a/source/blender/io/common/IO_abstract_hierarchy_iterator.h b/source/blender/io/common/IO_abstract_hierarchy_iterator.h index 1d78cc38746..e3ed3dd70a2 100644 --- a/source/blender/io/common/IO_abstract_hierarchy_iterator.h +++ b/source/blender/io/common/IO_abstract_hierarchy_iterator.h @@ -51,8 +51,7 @@ struct Object; struct ParticleSystem; struct ViewLayer; -namespace blender { -namespace io { +namespace blender::io { class AbstractHierarchyWriter; class DupliParentFinder; @@ -356,5 +355,4 @@ class AbstractHierarchyIterator { ExportChildren &graph_children(const HierarchyContext *parent_context); }; -} // namespace io -} // namespace blender +} // namespace blender::io diff --git a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc index d825625cafc..6e763c29631 100644 --- a/source/blender/io/common/intern/abstract_hierarchy_iterator.cc +++ b/source/blender/io/common/intern/abstract_hierarchy_iterator.cc @@ -44,8 +44,7 @@ #include "DEG_depsgraph_query.h" -namespace blender { -namespace io { +namespace blender::io { const HierarchyContext *HierarchyContext::root() { @@ -755,5 +754,4 @@ bool AbstractHierarchyIterator::should_visit_dupli_object(const DupliObject *dup return !dupli_object->no_draw; } -} // namespace io -} // namespace blender +} // namespace blender::io diff --git a/source/blender/io/common/intern/object_identifier.cc b/source/blender/io/common/intern/object_identifier.cc index 696bc5d2c34..a2d2d998bec 100644 --- a/source/blender/io/common/intern/object_identifier.cc +++ b/source/blender/io/common/intern/object_identifier.cc @@ -26,8 +26,7 @@ extern "C" { #include <cstring> #include <sstream> -namespace blender { -namespace io { +namespace blender::io { ObjectIdentifier::ObjectIdentifier(Object *object, Object *duplicated_by, @@ -112,5 +111,4 @@ bool operator==(const ObjectIdentifier &obj_ident_a, const ObjectIdentifier &obj return obj_ident_a.persistent_id == obj_ident_b.persistent_id; } -} // namespace io -} // namespace blender +} // namespace blender::io diff --git a/source/blender/io/usd/intern/usd_capi.cc b/source/blender/io/usd/intern/usd_capi.cc index 52075728e3e..4717f27dbd9 100644 --- a/source/blender/io/usd/intern/usd_capi.cc +++ b/source/blender/io/usd/intern/usd_capi.cc @@ -46,9 +46,7 @@ #include "WM_api.h" #include "WM_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { struct ExportJobData { Main *bmain; @@ -185,9 +183,7 @@ static void export_endjob(void *customdata) WM_set_locked_interface(data->wm, false); } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd bool USD_export(bContext *C, const char *filepath, diff --git a/source/blender/io/usd/intern/usd_exporter_context.h b/source/blender/io/usd/intern/usd_exporter_context.h index 5513768b527..41ff34b327e 100644 --- a/source/blender/io/usd/intern/usd_exporter_context.h +++ b/source/blender/io/usd/intern/usd_exporter_context.h @@ -26,9 +26,7 @@ struct Depsgraph; struct Object; -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { class USDHierarchyIterator; @@ -40,6 +38,4 @@ struct USDExporterContext { const USDExportParams &export_params; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc index 39fbef70e81..66dfc21441e 100644 --- a/source/blender/io/usd/intern/usd_hierarchy_iterator.cc +++ b/source/blender/io/usd/intern/usd_hierarchy_iterator.cc @@ -42,9 +42,7 @@ #include "DNA_layer_types.h" #include "DNA_object_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDHierarchyIterator::USDHierarchyIterator(Depsgraph *depsgraph, pxr::UsdStageRefPtr stage, @@ -149,6 +147,4 @@ AbstractHierarchyWriter *USDHierarchyIterator::create_particle_writer( return nullptr; } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_hierarchy_iterator.h b/source/blender/io/usd/intern/usd_hierarchy_iterator.h index 03e80ce735a..922ab761bd9 100644 --- a/source/blender/io/usd/intern/usd_hierarchy_iterator.h +++ b/source/blender/io/usd/intern/usd_hierarchy_iterator.h @@ -31,9 +31,7 @@ struct Depsgraph; struct ID; struct Object; -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { using blender::io::AbstractHierarchyIterator; using blender::io::AbstractHierarchyWriter; @@ -71,6 +69,4 @@ class USDHierarchyIterator : public AbstractHierarchyIterator { USDExporterContext create_usd_export_context(const HierarchyContext *context); }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_abstract.cc b/source/blender/io/usd/intern/usd_writer_abstract.cc index 0edfbc62d6b..3f5babdee56 100644 --- a/source/blender/io/usd/intern/usd_writer_abstract.cc +++ b/source/blender/io/usd/intern/usd_writer_abstract.cc @@ -34,9 +34,7 @@ static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal); static const pxr::TfToken surface("surface", pxr::TfToken::Immortal); } // namespace usdtokens -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDAbstractWriter::USDAbstractWriter(const USDExporterContext &usd_export_context) : usd_export_context_(usd_export_context), @@ -155,6 +153,4 @@ bool USDAbstractWriter::mark_as_instance(const HierarchyContext &context, const return true; } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_abstract.h b/source/blender/io/usd/intern/usd_writer_abstract.h index 6cf7c79c5fa..6a3b8d515dc 100644 --- a/source/blender/io/usd/intern/usd_writer_abstract.h +++ b/source/blender/io/usd/intern/usd_writer_abstract.h @@ -35,9 +35,7 @@ struct Material; struct Object; -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { using blender::io::AbstractHierarchyWriter; using blender::io::HierarchyContext; @@ -82,6 +80,4 @@ class USDAbstractWriter : public AbstractHierarchyWriter { virtual bool mark_as_instance(const HierarchyContext &context, const pxr::UsdPrim &prim); }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_camera.cc b/source/blender/io/usd/intern/usd_writer_camera.cc index d51eb32d3fd..f21a0444888 100644 --- a/source/blender/io/usd/intern/usd_writer_camera.cc +++ b/source/blender/io/usd/intern/usd_writer_camera.cc @@ -28,9 +28,7 @@ #include "DNA_camera_types.h" #include "DNA_scene_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDCameraWriter::USDCameraWriter(const USDExporterContext &ctx) : USDAbstractWriter(ctx) { @@ -108,6 +106,4 @@ void USDCameraWriter::do_write(HierarchyContext &context) } } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_camera.h b/source/blender/io/usd/intern/usd_writer_camera.h index 1c613d7879b..f6d7e777f2f 100644 --- a/source/blender/io/usd/intern/usd_writer_camera.h +++ b/source/blender/io/usd/intern/usd_writer_camera.h @@ -20,9 +20,7 @@ #include "usd_writer_abstract.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { /* Writer for writing camera data to UsdGeomCamera. */ class USDCameraWriter : public USDAbstractWriter { @@ -34,6 +32,4 @@ class USDCameraWriter : public USDAbstractWriter { virtual void do_write(HierarchyContext &context) override; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_hair.cc b/source/blender/io/usd/intern/usd_writer_hair.cc index 0fd5c4ce727..df09aa2f187 100644 --- a/source/blender/io/usd/intern/usd_writer_hair.cc +++ b/source/blender/io/usd/intern/usd_writer_hair.cc @@ -26,9 +26,7 @@ #include "DNA_particle_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDHairWriter::USDHairWriter(const USDExporterContext &ctx) : USDAbstractWriter(ctx) { @@ -87,6 +85,4 @@ bool USDHairWriter::check_is_animated(const HierarchyContext &UNUSED(context)) c return true; } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_hair.h b/source/blender/io/usd/intern/usd_writer_hair.h index b9a28013875..8dc256fdb8e 100644 --- a/source/blender/io/usd/intern/usd_writer_hair.h +++ b/source/blender/io/usd/intern/usd_writer_hair.h @@ -20,9 +20,7 @@ #include "usd_writer_abstract.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { /* Writer for writing hair particle data as USD curves. */ class USDHairWriter : public USDAbstractWriter { @@ -34,6 +32,4 @@ class USDHairWriter : public USDAbstractWriter { virtual bool check_is_animated(const HierarchyContext &context) const override; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_light.cc b/source/blender/io/usd/intern/usd_writer_light.cc index 19115dd1a4e..b6a81c973d2 100644 --- a/source/blender/io/usd/intern/usd_writer_light.cc +++ b/source/blender/io/usd/intern/usd_writer_light.cc @@ -30,9 +30,7 @@ #include "DNA_light_types.h" #include "DNA_object_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDLightWriter::USDLightWriter(const USDExporterContext &ctx) : USDAbstractWriter(ctx) { @@ -109,6 +107,4 @@ void USDLightWriter::do_write(HierarchyContext &context) usd_light.CreateSpecularAttr().Set(light->spec_fac, timecode); } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_light.h b/source/blender/io/usd/intern/usd_writer_light.h index 082050ad071..9be82bfe214 100644 --- a/source/blender/io/usd/intern/usd_writer_light.h +++ b/source/blender/io/usd/intern/usd_writer_light.h @@ -20,9 +20,7 @@ #include "usd_writer_abstract.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { class USDLightWriter : public USDAbstractWriter { public: @@ -33,6 +31,4 @@ class USDLightWriter : public USDAbstractWriter { virtual void do_write(HierarchyContext &context) override; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index 2073d4cbe87..3f9cb78ea3b 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -44,9 +44,7 @@ #include <iostream> -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDGenericMeshWriter::USDGenericMeshWriter(const USDExporterContext &ctx) : USDAbstractWriter(ctx) { @@ -462,6 +460,4 @@ Mesh *USDMeshWriter::get_export_mesh(Object *object_eval, bool & /*r_needsfree*/ return BKE_object_get_evaluated_mesh(object_eval); } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_mesh.h b/source/blender/io/usd/intern/usd_writer_mesh.h index 078daa05501..6345f2d4240 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.h +++ b/source/blender/io/usd/intern/usd_writer_mesh.h @@ -22,9 +22,7 @@ #include <pxr/usd/usdGeom/mesh.h> -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { struct USDMeshData; @@ -62,6 +60,4 @@ class USDMeshWriter : public USDGenericMeshWriter { virtual Mesh *get_export_mesh(Object *object_eval, bool &r_needsfree) override; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_metaball.cc b/source/blender/io/usd/intern/usd_writer_metaball.cc index f003fba18a4..8e32bd4705a 100644 --- a/source/blender/io/usd/intern/usd_writer_metaball.cc +++ b/source/blender/io/usd/intern/usd_writer_metaball.cc @@ -34,9 +34,7 @@ #include "DNA_mesh_types.h" #include "DNA_meta_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDMetaballWriter::USDMetaballWriter(const USDExporterContext &ctx) : USDGenericMeshWriter(ctx) { @@ -78,6 +76,4 @@ bool USDMetaballWriter::is_basis_ball(Scene *scene, Object *ob) const return ob == basis_ob; } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_metaball.h b/source/blender/io/usd/intern/usd_writer_metaball.h index 216f5a2638f..f82c001154e 100644 --- a/source/blender/io/usd/intern/usd_writer_metaball.h +++ b/source/blender/io/usd/intern/usd_writer_metaball.h @@ -20,9 +20,7 @@ #include "usd_writer_mesh.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { class USDMetaballWriter : public USDGenericMeshWriter { public: @@ -38,6 +36,4 @@ class USDMetaballWriter : public USDGenericMeshWriter { bool is_basis_ball(Scene *scene, Object *ob) const; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_transform.cc b/source/blender/io/usd/intern/usd_writer_transform.cc index 49983115455..632a6dd0f3f 100644 --- a/source/blender/io/usd/intern/usd_writer_transform.cc +++ b/source/blender/io/usd/intern/usd_writer_transform.cc @@ -28,9 +28,7 @@ #include "DNA_layer_types.h" -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { USDTransformWriter::USDTransformWriter(const USDExporterContext &ctx) : USDAbstractWriter(ctx) { @@ -64,6 +62,4 @@ bool USDTransformWriter::check_is_animated(const HierarchyContext &context) cons return BKE_object_moves_in_time(context.object, context.animation_check_include_parent); } -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_writer_transform.h b/source/blender/io/usd/intern/usd_writer_transform.h index 39a1f20e7e8..eba87b28faa 100644 --- a/source/blender/io/usd/intern/usd_writer_transform.h +++ b/source/blender/io/usd/intern/usd_writer_transform.h @@ -22,9 +22,7 @@ #include <pxr/usd/usdGeom/xform.h> -namespace blender { -namespace io { -namespace usd { +namespace blender::io::usd { class USDTransformWriter : public USDAbstractWriter { private: @@ -38,6 +36,4 @@ class USDTransformWriter : public USDAbstractWriter { bool check_is_animated(const HierarchyContext &context) const override; }; -} // namespace usd -} // namespace io -} // namespace blender +} // namespace blender::io::usd diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h index 033a69d230e..6c3ffc09919 100644 --- a/source/blender/makesdna/DNA_brush_types.h +++ b/source/blender/makesdna/DNA_brush_types.h @@ -774,6 +774,7 @@ typedef enum eBrushFlags2 { BRUSH_CLOTH_PIN_SIMULATION_BOUNDARY = (1 << 4), BRUSH_POSE_USE_LOCK_ROTATION = (1 << 5), BRUSH_CLOTH_USE_COLLISION = (1 << 6), + BRUSH_AREA_RADIUS_PRESSURE = (1 << 7), } eBrushFlags2; typedef enum { diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h index 2990fa85c27..ca4d309e3b1 100644 --- a/source/blender/makesdna/DNA_customdata_types.h +++ b/source/blender/makesdna/DNA_customdata_types.h @@ -147,9 +147,9 @@ typedef enum CustomDataType { CD_CUSTOMLOOPNORMAL = 41, CD_SCULPT_FACE_SETS = 42, - CD_LOCATION = 43, + /* CD_LOCATION = 43, */ /* UNUSED */ + /* CD_RADIUS = 44, */ /* UNUSED */ CD_HAIRCURVE = 45, - CD_RADIUS = 44, CD_HAIRMAPPING = 46, CD_PROP_COLOR = 47, @@ -209,17 +209,17 @@ typedef enum CustomDataType { #define CD_MASK_PROP_FLOAT3 (1ULL << CD_PROP_FLOAT3) #define CD_MASK_PROP_FLOAT2 (1ULL << CD_PROP_FLOAT2) -/** Data types that may be defined for all mesh elements types. */ -#define CD_MASK_GENERIC_DATA \ - (CD_MASK_PROP_FLOAT | CD_MASK_PROP_INT32 | CD_MASK_PROP_STRING | CD_MASK_PROP_FLOAT3 | \ - CD_MASK_PROP_FLOAT2) - /** Multires loop data. */ #define CD_MASK_MULTIRES_GRIDS (CD_MASK_MDISPS | CD_GRID_PAINT_MASK) /* All data layers. */ #define CD_MASK_ALL (~0LL) +/* All generic attributes. */ +#define CD_MASK_PROP_ALL \ + (CD_MASK_PROP_FLOAT | CD_MASK_PROP_FLOAT2 | CD_MASK_PROP_FLOAT3 | CD_MASK_PROP_INT32 | \ + CD_MASK_PROP_COLOR | CD_MASK_PROP_STRING | CD_MASK_MLOOPCOL) + typedef struct CustomData_MeshMasks { uint64_t vmask; uint64_t emask; diff --git a/source/blender/makesdna/DNA_hair_types.h b/source/blender/makesdna/DNA_hair_types.h index d120e61cfef..27799560395 100644 --- a/source/blender/makesdna/DNA_hair_types.h +++ b/source/blender/makesdna/DNA_hair_types.h @@ -56,6 +56,8 @@ typedef struct Hair { /* Custom Data */ struct CustomData pdata; struct CustomData cdata; + int attributes_active_index; + int _pad3; /* Material */ struct Material **mat; diff --git a/source/blender/makesdna/DNA_image_defaults.h b/source/blender/makesdna/DNA_image_defaults.h index ce1296d681f..93ff8792dfa 100644 --- a/source/blender/makesdna/DNA_image_defaults.h +++ b/source/blender/makesdna/DNA_image_defaults.h @@ -36,6 +36,8 @@ .gen_type = IMA_GENTYPE_GRID, \ \ .gpuframenr = INT_MAX, \ + .gpu_pass = SHRT_MAX, \ + .gpu_layer = SHRT_MAX, \ } /** \} */ diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h index 749bc55fcb9..4a05d7ba319 100644 --- a/source/blender/makesdna/DNA_image_types.h +++ b/source/blender/makesdna/DNA_image_types.h @@ -147,9 +147,11 @@ typedef struct Image { int lastframe; /* GPU texture flag. */ - short gpuflag; - char _pad2[2]; int gpuframenr; + short gpuflag; + short gpu_pass; + short gpu_layer; + char _pad2[6]; /** Deprecated. */ struct PackedFile *packedfile DNA_DEPRECATED; diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index a6aef5b08ad..abfa3cc1b2e 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -191,6 +191,9 @@ typedef struct Mesh { int totpoly, totloop; /* END BMESH ONLY */ + int attributes_active_index; + int _pad3; + /* the last selected vertex/edge/face are used for the active face however * this means the active face must always be selected, this is to keep track * of the last selected face and is similar to the old active face flag where diff --git a/source/blender/makesdna/DNA_pointcloud_types.h b/source/blender/makesdna/DNA_pointcloud_types.h index d3b687c2c68..86cff098096 100644 --- a/source/blender/makesdna/DNA_pointcloud_types.h +++ b/source/blender/makesdna/DNA_pointcloud_types.h @@ -38,6 +38,8 @@ typedef struct PointCloud { /* Custom Data */ struct CustomData pdata; + int attributes_active_index; + int _pad4; /* Material */ struct Material **mat; diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index 6fe6a5461e1..06ab01a9730 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -284,6 +284,7 @@ typedef enum eSpaceOutliner_Flag { /* SO_HIDE_KEYINGSETINFO = (1 << 3), */ /* UNUSED */ SO_SKIP_SORT_ALPHA = (1 << 4), SO_SYNC_SELECT = (1 << 5), + SO_MODE_COLUMN = (1 << 6), } eSpaceOutliner_Flag; /* SpaceOutliner.filter */ diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 589077ea67b..b63f4529559 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -620,9 +620,10 @@ typedef struct UserDef_Experimental { char use_new_hair_type; char use_cycles_debug; char use_sculpt_vertex_colors; + char use_image_editor_legacy_drawing; char use_tools_missing_icons; /** `makesdna` does not allow empty structs. */ - char _pad[2]; + char _pad[1]; } UserDef_Experimental; #define USER_EXPERIMENTAL_TEST(userdef, member) \ diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index 8ad0271f355..b9688df8a3e 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -805,83 +805,91 @@ static eSDNA_Type sdna_type_nr(const char *dna_type) static void cast_elem( const char *ctype, const char *otype, int name_array_len, char *curdata, const char *olddata) { - double val = 0.0; - int curlen = 1, oldlen = 1; - eSDNA_Type ctypenr, otypenr; - if ((otypenr = sdna_type_nr(otype)) == -1 || (ctypenr = sdna_type_nr(ctype)) == -1) { return; } /* define lengths */ - oldlen = DNA_elem_type_size(otypenr); - curlen = DNA_elem_type_size(ctypenr); + const int oldlen = DNA_elem_type_size(otypenr); + const int curlen = DNA_elem_type_size(ctypenr); + + double old_value_f = 0.0; + uint64_t old_value_i = 0; while (name_array_len > 0) { switch (otypenr) { case SDNA_TYPE_CHAR: - val = *olddata; + old_value_i = *olddata; + old_value_f = (double)old_value_i; break; case SDNA_TYPE_UCHAR: - val = *((unsigned char *)olddata); + old_value_i = *((unsigned char *)olddata); + old_value_f = (double)old_value_i; break; case SDNA_TYPE_SHORT: - val = *((short *)olddata); + old_value_i = *((short *)olddata); + old_value_f = (double)old_value_i; break; case SDNA_TYPE_USHORT: - val = *((unsigned short *)olddata); + old_value_i = *((unsigned short *)olddata); + old_value_f = (double)old_value_i; break; case SDNA_TYPE_INT: - val = *((int *)olddata); + old_value_i = *((int *)olddata); + old_value_f = (double)old_value_i; break; case SDNA_TYPE_FLOAT: - val = *((float *)olddata); + old_value_f = *((float *)olddata); + old_value_i = (uint64_t)(int64_t)old_value_f; break; case SDNA_TYPE_DOUBLE: - val = *((double *)olddata); + old_value_f = *((double *)olddata); + old_value_i = (uint64_t)(int64_t)old_value_f; break; case SDNA_TYPE_INT64: - val = *((int64_t *)olddata); + old_value_i = (uint64_t) * ((int64_t *)olddata); + old_value_f = (double)old_value_i; break; case SDNA_TYPE_UINT64: - val = *((uint64_t *)olddata); + old_value_i = *((uint64_t *)olddata); + old_value_f = (double)old_value_i; break; } switch (ctypenr) { case SDNA_TYPE_CHAR: - *curdata = val; + *curdata = (char)old_value_i; break; case SDNA_TYPE_UCHAR: - *((unsigned char *)curdata) = val; + *((unsigned char *)curdata) = (unsigned char)old_value_i; break; case SDNA_TYPE_SHORT: - *((short *)curdata) = val; + *((short *)curdata) = (short)old_value_i; break; case SDNA_TYPE_USHORT: - *((unsigned short *)curdata) = val; + *((unsigned short *)curdata) = (unsigned short)old_value_i; break; case SDNA_TYPE_INT: - *((int *)curdata) = val; + *((int *)curdata) = (int)old_value_i; break; case SDNA_TYPE_FLOAT: if (otypenr < 2) { - val /= 255; + old_value_f /= 255.0; } - *((float *)curdata) = val; + *((float *)curdata) = old_value_f; break; case SDNA_TYPE_DOUBLE: if (otypenr < 2) { - val /= 255; + old_value_f /= 255.0; } - *((double *)curdata) = val; + *((double *)curdata) = old_value_f; break; case SDNA_TYPE_INT64: - *((int64_t *)curdata) = val; + *((int64_t *)curdata) = (int64_t)old_value_i; break; case SDNA_TYPE_UINT64: - *((uint64_t *)curdata) = val; + *((uint64_t *)curdata) = old_value_i; break; } diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 6acd9d16f80..8ee10047750 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -67,6 +67,8 @@ extern StructRNA RNA_ArmatureGpencilModifier; extern StructRNA RNA_ArmatureModifier; extern StructRNA RNA_ArrayGpencilModifier; extern StructRNA RNA_ArrayModifier; +extern StructRNA RNA_Attribute; +extern StructRNA RNA_AttributeGroup; extern StructRNA RNA_BackgroundImage; extern StructRNA RNA_BevelModifier; extern StructRNA RNA_BezierSplinePoint; @@ -93,6 +95,8 @@ extern StructRNA RNA_BrushCapabilitiesVertexPaint; extern StructRNA RNA_BrushTextureSlot; extern StructRNA RNA_BuildGpencilModifier; extern StructRNA RNA_BuildModifier; +extern StructRNA RNA_ByteColorAttribute; +extern StructRNA RNA_ByteColorAttributeValue; extern StructRNA RNA_CacheFile; extern StructRNA RNA_Camera; extern StructRNA RNA_CameraDOFSettings; @@ -247,6 +251,10 @@ extern StructRNA RNA_FaceMap; extern StructRNA RNA_FieldSettings; extern StructRNA RNA_FileBrowserFSMenuEntry; extern StructRNA RNA_FileSelectParams; +extern StructRNA RNA_FloatAttribute; +extern StructRNA RNA_FloatAttributeValue; +extern StructRNA RNA_FloatColorAttribute; +extern StructRNA RNA_FloatColorAttributeValue; extern StructRNA RNA_FloatProperty; extern StructRNA RNA_FloorConstraint; extern StructRNA RNA_FluidDomainSettings; @@ -292,6 +300,8 @@ extern StructRNA RNA_ImagePreview; extern StructRNA RNA_ImageSequence; extern StructRNA RNA_ImageTexture; extern StructRNA RNA_ImageUser; +extern StructRNA RNA_IntAttribute; +extern StructRNA RNA_IntAttributeValue; extern StructRNA RNA_IntProperty; extern StructRNA RNA_Itasc; extern StructRNA RNA_Key; @@ -588,6 +598,8 @@ extern StructRNA RNA_SplinePoint; extern StructRNA RNA_SpotLight; extern StructRNA RNA_Stereo3dDisplay; extern StructRNA RNA_StretchToConstraint; +extern StructRNA RNA_StringAttribute; +extern StructRNA RNA_StringAttributeValue; extern StructRNA RNA_StringProperty; extern StructRNA RNA_Struct; extern StructRNA RNA_StucciTexture; diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index 08442a36c87..15b29e45053 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -26,6 +26,7 @@ extern "C" { #endif +struct ID; struct bNodeSocketType; struct bNodeTreeType; struct bNodeType; @@ -231,6 +232,10 @@ extern const EnumPropertyItem rna_enum_context_mode_items[]; extern const EnumPropertyItem rna_enum_curveprofile_preset_items[]; extern const EnumPropertyItem rna_enum_preference_section_items[]; +extern const EnumPropertyItem rna_enum_attribute_type_items[]; +extern const EnumPropertyItem rna_enum_attribute_domain_items[]; +extern const EnumPropertyItem *rna_enum_attribute_domain_itemf(struct ID *id, bool *r_free); + /* API calls */ int rna_node_tree_type_to_enum(struct bNodeTreeType *typeinfo); int rna_node_tree_idname_to_enum(const char *idname); diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index 303005a0f9e..0387f83d695 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -30,6 +30,7 @@ set(DEFSRC rna_animation.c rna_animviz.c rna_armature.c + rna_attribute.c rna_boid.c rna_brush.c rna_cachefile.c diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index a81bd4d0832..f1086ab69bc 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -4276,6 +4276,7 @@ static RNAProcessItem PROCESS_ITEMS[] = { {"rna_animation.c", "rna_animation_api.c", RNA_def_animation}, {"rna_animviz.c", NULL, RNA_def_animviz}, {"rna_armature.c", "rna_armature_api.c", RNA_def_armature}, + {"rna_attribute.c", NULL, RNA_def_attribute}, {"rna_boid.c", NULL, RNA_def_boid}, {"rna_brush.c", NULL, RNA_def_brush}, {"rna_cachefile.c", NULL, RNA_def_cachefile}, diff --git a/source/blender/makesrna/intern/rna_attribute.c b/source/blender/makesrna/intern/rna_attribute.c new file mode 100644 index 00000000000..9e9575344c5 --- /dev/null +++ b/source/blender/makesrna/intern/rna_attribute.c @@ -0,0 +1,680 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup RNA + */ + +#include <stdlib.h> + +#include "RNA_access.h" +#include "RNA_define.h" +#include "RNA_enum_types.h" + +#include "rna_internal.h" + +#include "DNA_customdata_types.h" +#include "DNA_hair_types.h" +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_pointcloud_types.h" + +#include "BKE_attribute.h" +#include "BKE_customdata.h" + +#include "WM_types.h" + +const EnumPropertyItem rna_enum_attribute_type_items[] = { + {CD_PROP_FLOAT, "FLOAT", 0, "Float", "Floating point value"}, + {CD_PROP_INT32, "INT", 0, "Integer", "32 bit integer"}, + {CD_PROP_FLOAT3, "FLOAT_VECTOR", 0, "Vector", "3D vector with floating point values"}, + {CD_PROP_COLOR, "FLOAT_COLOR", 0, "Float Color", "RGBA color with floating point precisions"}, + {CD_MLOOPCOL, "BYTE_COLOR", 0, "Byte Color", "RGBA color with 8-bit precision"}, + {CD_PROP_STRING, "STRING", 0, "String", "Text string"}, + {0, NULL, 0, NULL, NULL}, +}; + +const EnumPropertyItem rna_enum_attribute_domain_items[] = { + /* Not implement yet + {ATTR_DOMAIN_GEOMETRY, "GEOMETRY", 0, "Geometry", "Attribute on (whole) geometry"}, */ + {ATTR_DOMAIN_VERTEX, "VERTEX", 0, "Vertex", "Attribute on mesh vertex"}, + {ATTR_DOMAIN_EDGE, "EDGE", 0, "Edge", "Attribute on mesh edge"}, + {ATTR_DOMAIN_CORNER, "CORNER", 0, "Corner", "Attribute on mesh polygon corner"}, + {ATTR_DOMAIN_POLYGON, "POLYGON", 0, "Polygon", "Attribute on mesh polygons"}, + /* Not implement yet + {ATTR_DOMAIN_GRIDS, "GRIDS", 0, "Grids", "Attribute on mesh multires grids"}, */ + {ATTR_DOMAIN_POINT, "POINT", 0, "Point", "Attribute on point"}, + {ATTR_DOMAIN_CURVE, "CURVE", 0, "Curve", "Attribute on hair curve"}, + {0, NULL, 0, NULL, NULL}, +}; + +#ifdef RNA_RUNTIME + +# include "BLI_math.h" + +# include "DEG_depsgraph.h" + +# include "BLT_translation.h" + +# include "WM_api.h" + +/* Attribute */ + +static char *rna_Attribute_path(PointerRNA *ptr) +{ + CustomDataLayer *layer = ptr->data; + return BLI_sprintfN("attributes['%s']", layer->name); +} + +static void rna_Attribute_name_set(PointerRNA *ptr, const char *value) +{ + BKE_id_attribute_rename(ptr->owner_id, ptr->data, value, NULL); +} + +static int rna_Attribute_name_editable(PointerRNA *ptr, const char **r_info) +{ + CustomDataLayer *layer = ptr->data; + if (BKE_id_attribute_required(ptr->owner_id, layer)) { + *r_info = N_("Can't modify name of required geometry attribute"); + return false; + } + + return true; +} + +static int rna_Attribute_type_get(PointerRNA *ptr) +{ + CustomDataLayer *layer = ptr->data; + return layer->type; +} + +const EnumPropertyItem *rna_enum_attribute_domain_itemf(ID *id, bool *r_free) +{ + EnumPropertyItem *item = NULL; + const EnumPropertyItem *domain_item = NULL; + const ID_Type id_type = GS(id->name); + int totitem = 0, a; + + for (a = 0; rna_enum_attribute_domain_items[a].identifier; a++) { + domain_item = &rna_enum_attribute_domain_items[a]; + + if (id_type == ID_PT && !ELEM(domain_item->value, ATTR_DOMAIN_POINT)) { + continue; + } + if (id_type == ID_HA && !ELEM(domain_item->value, ATTR_DOMAIN_POINT, ATTR_DOMAIN_CURVE)) { + continue; + } + if (id_type == ID_ME && ELEM(domain_item->value, ATTR_DOMAIN_POINT, ATTR_DOMAIN_CURVE)) { + continue; + } + + RNA_enum_item_add(&item, &totitem, domain_item); + } + RNA_enum_item_end(&item, &totitem); + + *r_free = true; + return item; +} + +static const EnumPropertyItem *rna_Attribute_domain_itemf(bContext *UNUSED(C), + PointerRNA *ptr, + PropertyRNA *UNUSED(prop), + bool *r_free) +{ + return rna_enum_attribute_domain_itemf(ptr->owner_id, r_free); +} + +static int rna_Attribute_domain_get(PointerRNA *ptr) +{ + return BKE_id_attribute_domain(ptr->owner_id, ptr->data); +} + +static void rna_Attribute_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + ID *id = ptr->owner_id; + CustomDataLayer *layer = (CustomDataLayer *)ptr->data; + + int length = BKE_id_attribute_data_length(id, layer); + size_t struct_size; + + switch (layer->type) { + case CD_PROP_FLOAT: + struct_size = sizeof(MFloatProperty); + break; + case CD_PROP_INT32: + struct_size = sizeof(MIntProperty); + break; + case CD_PROP_FLOAT3: + struct_size = sizeof(float[3]); + break; + case CD_PROP_COLOR: + struct_size = sizeof(MPropCol); + break; + case CD_MLOOPCOL: + struct_size = sizeof(MLoopCol); + break; + case CD_PROP_STRING: + struct_size = sizeof(MStringProperty); + break; + default: + struct_size = 0; + length = 0; + break; + } + + rna_iterator_array_begin(iter, layer->data, struct_size, length, 0, NULL); +} + +static int rna_Attribute_data_length(PointerRNA *ptr) +{ + ID *id = ptr->owner_id; + CustomDataLayer *layer = (CustomDataLayer *)ptr->data; + return BKE_id_attribute_data_length(id, layer); +} + +static void rna_Attribute_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) +{ + ID *id = ptr->owner_id; + + /* cheating way for importers to avoid slow updates */ + if (id->us > 0) { + DEG_id_tag_update(id, 0); + WM_main_add_notifier(NC_GEOM | ND_DATA, id); + } +} + +/* Color Attribute */ + +static void rna_ByteColorAttributeValue_color_get(PointerRNA *ptr, float *values) +{ + MLoopCol *mlcol = (MLoopCol *)ptr->data; + srgb_to_linearrgb_uchar4(values, &mlcol->r); +} + +static void rna_ByteColorAttributeValue_color_set(PointerRNA *ptr, const float *values) +{ + MLoopCol *mlcol = (MLoopCol *)ptr->data; + linearrgb_to_srgb_uchar4(&mlcol->r, values); +} + +/* Attribute Group */ + +static PointerRNA rna_AttributeGroup_new( + ID *id, ReportList *reports, const char *name, const int type, const int domain) +{ + CustomDataLayer *layer = BKE_id_attribute_new(id, name, type, domain, reports); + DEG_id_tag_update(id, ID_RECALC_GEOMETRY); + WM_main_add_notifier(NC_GEOM | ND_DATA, id); + + PointerRNA ptr; + RNA_pointer_create(id, &RNA_Attribute, layer, &ptr); + return ptr; +} + +static void rna_AttributeGroup_remove(ID *id, ReportList *reports, PointerRNA *attribute_ptr) +{ + CustomDataLayer *layer = (CustomDataLayer *)attribute_ptr->data; + BKE_id_attribute_remove(id, layer, reports); + RNA_POINTER_INVALIDATE(attribute_ptr); + + DEG_id_tag_update(id, ID_RECALC_GEOMETRY); + WM_main_add_notifier(NC_GEOM | ND_DATA, id); +} + +static int rna_Attributes_layer_skip(CollectionPropertyIterator *UNUSED(iter), void *data) +{ + CustomDataLayer *layer = (CustomDataLayer *)data; + return !(CD_TYPE_AS_MASK(layer->type) & CD_MASK_PROP_ALL); +} + +/* Attributes are spread over multiple domains in separate CustomData, we use repeated + * array iterators to loop over all. */ +static void rna_AttributeGroup_next_domain(ID *id, + CollectionPropertyIterator *iter, + int(skip)(CollectionPropertyIterator *iter, void *data)) +{ + do { + CustomDataLayer *prev_layers = (CustomDataLayer *)iter->internal.array.endptr - + iter->internal.array.length; + CustomData *customdata = BKE_id_attributes_iterator_next_domain(id, prev_layers); + if (customdata == NULL) { + return; + } + rna_iterator_array_begin( + iter, customdata->layers, sizeof(CustomDataLayer), customdata->totlayer, false, skip); + } while (!iter->valid); +} + +void rna_AttributeGroup_iterator_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + memset(&iter->internal.array, 0, sizeof(iter->internal.array)); + rna_AttributeGroup_next_domain(ptr->owner_id, iter, rna_Attributes_layer_skip); +} + +void rna_AttributeGroup_iterator_next(CollectionPropertyIterator *iter) +{ + rna_iterator_array_next(iter); + + if (!iter->valid) { + ID *id = iter->parent.owner_id; + rna_AttributeGroup_next_domain(id, iter, rna_Attributes_layer_skip); + } +} + +PointerRNA rna_AttributeGroup_iterator_get(CollectionPropertyIterator *iter) +{ + /* refine to the proper type */ + StructRNA *type; + CustomDataLayer *layer = rna_iterator_array_get(iter); + + switch (layer->type) { + case CD_PROP_FLOAT: + type = &RNA_FloatAttribute; + break; + case CD_PROP_INT32: + type = &RNA_IntAttribute; + break; + case CD_PROP_FLOAT3: + type = &RNA_FloatVectorAttribute; + break; + case CD_PROP_COLOR: + type = &RNA_FloatColorAttribute; + break; + case CD_MLOOPCOL: + type = &RNA_ByteColorAttribute; + break; + case CD_PROP_STRING: + type = &RNA_StringAttribute; + break; + default: + return PointerRNA_NULL; + } + + return rna_pointer_inherit_refine(&iter->parent, type, layer); +} + +int rna_AttributeGroup_length(PointerRNA *ptr) +{ + return BKE_id_attributes_length(ptr->owner_id, CD_MASK_PROP_ALL); +} + +static int rna_AttributeGroup_active_index_get(PointerRNA *ptr) +{ + return *BKE_id_attributes_active_index_p(ptr->owner_id); +} + +static PointerRNA rna_AttributeGroup_active_get(PointerRNA *ptr) +{ + ID *id = ptr->owner_id; + CustomDataLayer *layer = BKE_id_attributes_active_get(id); + + PointerRNA attribute_ptr; + RNA_pointer_create(id, &RNA_Attribute, layer, &attribute_ptr); + return attribute_ptr; +} + +static void rna_AttributeGroup_active_set(PointerRNA *ptr, + PointerRNA attribute_ptr, + ReportList *UNUSED(reports)) +{ + ID *id = ptr->owner_id; + CustomDataLayer *layer = attribute_ptr.data; + BKE_id_attributes_active_set(id, layer); +} + +static void rna_AttributeGroup_active_index_set(PointerRNA *ptr, int value) +{ + *BKE_id_attributes_active_index_p(ptr->owner_id) = value; +} + +static void rna_AttributeGroup_active_index_range( + PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax) +{ + *min = 0; + *max = BKE_id_attributes_length(ptr->owner_id, CD_MASK_PROP_ALL); + + *softmin = *min; + *softmax = *max; +} + +static void rna_AttributeGroup_update_active(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + rna_Attribute_update_data(bmain, scene, ptr); +} + +#else + +static void rna_def_attribute_float(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "FloatAttribute", "Attribute"); + RNA_def_struct_sdna(srna, "CustomDataLayer"); + RNA_def_struct_ui_text(srna, "Float Attribute", "Geometry attribute with floating point values"); + + prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "FloatAttributeValue"); + RNA_def_property_collection_funcs(prop, + "rna_Attribute_data_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_Attribute_data_length", + NULL, + NULL, + NULL); + + srna = RNA_def_struct(brna, "FloatAttributeValue", NULL); + RNA_def_struct_sdna(srna, "MFloatProperty"); + RNA_def_struct_ui_text( + srna, "Float Attribute Value", "Floating point value in geometry attribute"); + prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "f"); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); +} + +static void rna_def_attribute_float_vector(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + /* Float Vector Attribute */ + srna = RNA_def_struct(brna, "FloatVectorAttribute", "Attribute"); + RNA_def_struct_sdna(srna, "CustomDataLayer"); + RNA_def_struct_ui_text( + srna, "Float Vector Attribute", "Vector geometry attribute, with floating point precision"); + + prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "FloatVectorAttributeValue"); + RNA_def_property_collection_funcs(prop, + "rna_Attribute_data_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_Attribute_data_length", + NULL, + NULL, + NULL); + + /* Float Vector Attribute Value */ + srna = RNA_def_struct(brna, "FloatVectorAttributeValue", NULL); + RNA_def_struct_sdna(srna, "vec3f"); + RNA_def_struct_ui_text( + srna, "Float Vector Attribute Value", "Vector value in geometry attribute"); + + prop = RNA_def_property(srna, "vector", PROP_FLOAT, PROP_DIRECTION); + RNA_def_property_ui_text(prop, "Vector", "3D vector"); + RNA_def_property_float_sdna(prop, NULL, "x"); + RNA_def_property_array(prop, 3); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); +} + +static void rna_def_attribute_float_color(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + /* Float Color Attribute */ + srna = RNA_def_struct(brna, "FloatColorAttribute", "Attribute"); + RNA_def_struct_sdna(srna, "CustomDataLayer"); + RNA_def_struct_ui_text( + srna, "Float Color Attribute", "Color geometry attribute, with floating point precision"); + + prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "FloatColorAttributeValue"); + RNA_def_property_collection_funcs(prop, + "rna_Attribute_data_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_Attribute_data_length", + NULL, + NULL, + NULL); + + /* Float Color Attribute Value */ + srna = RNA_def_struct(brna, "FloatColorAttributeValue", NULL); + RNA_def_struct_sdna(srna, "MPropCol"); + RNA_def_struct_ui_text(srna, "Float Color Attribute Value", "Color value in geometry attribute"); + + prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR); + RNA_def_property_ui_text(prop, "Color", "RGBA color in scene linear color space"); + RNA_def_property_float_sdna(prop, NULL, "color"); + RNA_def_property_array(prop, 4); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); +} + +static void rna_def_attribute_byte_color(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + /* Byte Color Attribute */ + srna = RNA_def_struct(brna, "ByteColorAttribute", "Attribute"); + RNA_def_struct_sdna(srna, "CustomDataLayer"); + RNA_def_struct_ui_text( + srna, "Byte Color Attribute", "Color geometry attribute, with 8-bit precision"); + + prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "ByteColorAttributeValue"); + RNA_def_property_collection_funcs(prop, + "rna_Attribute_data_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_Attribute_data_length", + NULL, + NULL, + NULL); + + /* Byte Color Attribute Value */ + srna = RNA_def_struct(brna, "ByteColorAttributeValue", NULL); + RNA_def_struct_sdna(srna, "MLoopCol"); + RNA_def_struct_ui_text(srna, "Byte Color Attribute Value", "Color value in geometry attribute"); + + prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR); + RNA_def_property_array(prop, 4); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_float_funcs(prop, + "rna_ByteColorAttributeValue_color_get", + "rna_ByteColorAttributeValue_color_set", + NULL); + RNA_def_property_ui_text(prop, "Color", "RGBA color in scene linear color space"); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); +} + +static void rna_def_attribute_int(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "IntAttribute", "Attribute"); + RNA_def_struct_sdna(srna, "CustomDataLayer"); + RNA_def_struct_ui_text(srna, "Int Attribute", "Integer geometry attribute"); + + prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "IntAttributeValue"); + RNA_def_property_collection_funcs(prop, + "rna_Attribute_data_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_Attribute_data_length", + NULL, + NULL, + NULL); + + srna = RNA_def_struct(brna, "IntAttributeValue", NULL); + RNA_def_struct_sdna(srna, "MIntProperty"); + RNA_def_struct_ui_text(srna, "Integer Attribute Value", "Integer value in geometry attribute"); + prop = RNA_def_property(srna, "value", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "i"); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); +} + +static void rna_def_attribute_string(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "StringAttribute", "Attribute"); + RNA_def_struct_sdna(srna, "CustomDataLayer"); + RNA_def_struct_ui_text(srna, "String Attribute", "String geometry attribute"); + + prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "StringAttributeValue"); + RNA_def_property_collection_funcs(prop, + "rna_Attribute_data_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_Attribute_data_length", + NULL, + NULL, + NULL); + + srna = RNA_def_struct(brna, "StringAttributeValue", NULL); + RNA_def_struct_sdna(srna, "MStringProperty"); + RNA_def_struct_ui_text(srna, "String Attribute Value", "String value in geometry attribute"); + prop = RNA_def_property(srna, "value", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "s"); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); +} + +static void rna_def_attribute(BlenderRNA *brna) +{ + PropertyRNA *prop; + StructRNA *srna; + + srna = RNA_def_struct(brna, "Attribute", NULL); + RNA_def_struct_sdna(srna, "CustomDataLayer"); + RNA_def_struct_ui_text(srna, "Attribute", "Geometry attribute"); + RNA_def_struct_path_func(srna, "rna_Attribute_path"); + + prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_struct_name_property(srna, prop); + RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Attribute_name_set"); + RNA_def_property_editable_func(prop, "rna_Attribute_name_editable"); + RNA_def_property_ui_text(prop, "Name", "Name of the Attribute"); + RNA_def_struct_name_property(srna, prop); + + prop = RNA_def_property(srna, "data_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "type"); + RNA_def_property_enum_items(prop, rna_enum_attribute_type_items); + RNA_def_property_enum_funcs(prop, "rna_Attribute_type_get", NULL, NULL); + RNA_def_property_ui_text(prop, "Data Type", "Type of data stored in attribute"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + + prop = RNA_def_property(srna, "domain", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, rna_enum_attribute_domain_items); + RNA_def_property_enum_funcs( + prop, "rna_Attribute_domain_get", NULL, "rna_Attribute_domain_itemf"); + RNA_def_property_ui_text(prop, "Domain", "Domain of the Attribute"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + + /* types */ + rna_def_attribute_float(brna); + rna_def_attribute_float_vector(brna); + rna_def_attribute_float_color(brna); + rna_def_attribute_byte_color(brna); + rna_def_attribute_int(brna); + rna_def_attribute_string(brna); +} + +/* Mesh/PointCloud/Hair.attributes */ +static void rna_def_attribute_group(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + FunctionRNA *func; + PropertyRNA *parm; + + srna = RNA_def_struct(brna, "AttributeGroup", NULL); + RNA_def_struct_ui_text(srna, "Attribute Group", "Group of geometry attributes"); + RNA_def_struct_sdna(srna, "ID"); + + /* API */ + func = RNA_def_function(srna, "new", "rna_AttributeGroup_new"); + RNA_def_function_ui_description(func, "Add an attribute"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + parm = RNA_def_string(func, "name", "Attribute", 0, "", "Attribute name"); + RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); + parm = RNA_def_enum( + func, "type", rna_enum_attribute_type_items, CD_PROP_FLOAT, "Type", "Attribute type"); + RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); + parm = RNA_def_enum(func, + "domain", + rna_enum_attribute_domain_items, + ATTR_DOMAIN_VERTEX, + "Domain", + "Type of element that attribute is stored on"); + RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); + parm = RNA_def_pointer(func, "attribute", "Attribute", "", "New geometry attribute"); + RNA_def_parameter_flags(parm, 0, PARM_RNAPTR); + RNA_def_function_return(func, parm); + + func = RNA_def_function(srna, "remove", "rna_AttributeGroup_remove"); + RNA_def_function_ui_description(func, "Remove an attribute"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + parm = RNA_def_pointer(func, "attribute", "Attribute", "", "Geometry Attribute"); + RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR); + RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0); + + /* Active */ + prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "Attribute"); + RNA_def_property_pointer_funcs( + prop, "rna_AttributeGroup_active_get", "rna_AttributeGroup_active_set", NULL, NULL); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK); + RNA_def_property_ui_text(prop, "Active Attribute", "Active attribute"); + RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active"); + + prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_int_funcs(prop, + "rna_AttributeGroup_active_index_get", + "rna_AttributeGroup_active_index_set", + "rna_AttributeGroup_active_index_range"); + RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active"); +} + +void rna_def_attributes_common(StructRNA *srna) +{ + PropertyRNA *prop; + + /* Attributes */ + prop = RNA_def_property(srna, "attributes", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_funcs(prop, + "rna_AttributeGroup_iterator_begin", + "rna_AttributeGroup_iterator_next", + "rna_iterator_array_end", + "rna_AttributeGroup_iterator_get", + "rna_AttributeGroup_length", + NULL, + NULL, + NULL); + RNA_def_property_struct_type(prop, "Attribute"); + RNA_def_property_ui_text(prop, "Attributes", "Geometry attributes"); + RNA_def_property_srna(prop, "AttributeGroup"); +} + +void RNA_def_attribute(BlenderRNA *brna) +{ + rna_def_attribute(brna); + rna_def_attribute_group(brna); +} +#endif diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index 0b923eb5635..3fd32aa6fd7 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -2971,6 +2971,13 @@ static void rna_def_brush(BlenderRNA *brna) prop, "Plane Offset Pressure", "Enable tablet pressure sensitivity for offset"); RNA_def_property_update(prop, 0, "rna_Brush_update"); + prop = RNA_def_property(srna, "use_pressure_area_radius", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag2", BRUSH_AREA_RADIUS_PRESSURE); + RNA_def_property_ui_icon(prop, ICON_STYLUS_PRESSURE, 0); + RNA_def_property_ui_text( + prop, "Area Radius Pressure", "Enable tablet pressure sensitivity for area radius"); + RNA_def_property_update(prop, 0, "rna_Brush_update"); + prop = RNA_def_property(srna, "use_pressure_size", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_SIZE_PRESSURE); RNA_def_property_ui_icon(prop, ICON_STYLUS_PRESSURE, 0); diff --git a/source/blender/makesrna/intern/rna_hair.c b/source/blender/makesrna/intern/rna_hair.c index f6dc93323fe..4ca66c6b583 100644 --- a/source/blender/makesrna/intern/rna_hair.c +++ b/source/blender/makesrna/intern/rna_hair.c @@ -34,6 +34,7 @@ # include "BLI_math_vector.h" +# include "BKE_attribute.h" # include "BKE_hair.h" # include "DEG_depsgraph.h" @@ -224,6 +225,9 @@ static void rna_def_hair(BlenderRNA *brna) RNA_def_property_collection_funcs( prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "rna_IDMaterials_assign_int"); + /* attributes */ + rna_def_attributes_common(srna); + /* common */ rna_def_animdata_common(srna); } diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index ad43202d850..eaf4e8866f9 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -151,6 +151,7 @@ void RNA_def_action(struct BlenderRNA *brna); void RNA_def_animation(struct BlenderRNA *brna); void RNA_def_animviz(struct BlenderRNA *brna); void RNA_def_armature(struct BlenderRNA *brna); +void RNA_def_attribute(struct BlenderRNA *brna); void RNA_def_boid(struct BlenderRNA *brna); void RNA_def_brush(struct BlenderRNA *brna); void RNA_def_cachefile(struct BlenderRNA *brna); @@ -221,6 +222,13 @@ void RNA_def_xr(struct BlenderRNA *brna); /* Common Define functions */ +void rna_def_attributes_common(struct StructRNA *srna); + +void rna_AttributeGroup_iterator_begin(CollectionPropertyIterator *iter, PointerRNA *ptr); +void rna_AttributeGroup_iterator_next(CollectionPropertyIterator *iter); +PointerRNA rna_AttributeGroup_iterator_get(CollectionPropertyIterator *iter); +int rna_AttributeGroup_length(PointerRNA *ptr); + void rna_def_animdata_common(struct StructRNA *srna); bool rna_AnimaData_override_apply(struct Main *bmain, diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index bb5ec0d6835..346946dfb0d 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -3200,6 +3200,9 @@ static void rna_def_mesh(BlenderRNA *brna) rna_def_paint_mask(brna, prop); /* End paint mask */ + /* Attributes */ + rna_def_attributes_common(srna); + /* Remesh */ prop = RNA_def_property(srna, "remesh_voxel_size", PROP_FLOAT, PROP_DISTANCE); RNA_def_property_float_sdna(prop, NULL, "remesh_voxel_size"); diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c index 3067a5a9453..13b068c2be5 100644 --- a/source/blender/makesrna/intern/rna_particle.c +++ b/source/blender/makesrna/intern/rna_particle.c @@ -243,35 +243,87 @@ static void rna_ParticleHairKey_location_object_get(PointerRNA *ptr, float *valu } } +/* Helper function which returns index of the given hair_key in particle which owns it. + * Works with cases when hair_key is coming from the particle which was passed here, and from the + * original particle of the given one. + * + * Such trickery is needed to allow modification of hair keys in the original object using + * evaluated particle and object to access proper hair matrix. */ +static int hair_key_index_get(/*const*/ HairKey *hair_key, + /*const*/ ParticleSystemModifierData *modifier, + /*const*/ ParticleData *particle) +{ + if (ARRAY_HAS_ITEM(hair_key, particle->hair, particle->totkey)) { + return hair_key - particle->hair; + } + + const ParticleSystem *particle_system = modifier->psys; + const int particle_index = particle - particle_system->particles; + + const ParticleSystemModifierData *original_modifier = (ParticleSystemModifierData *) + BKE_modifier_get_original(&modifier->modifier); + const ParticleSystem *original_particle_system = original_modifier->psys; + const ParticleData *original_particle = &original_particle_system->particles[particle_index]; + + if (ARRAY_HAS_ITEM(hair_key, original_particle->hair, original_particle->totkey)) { + return hair_key - original_particle->hair; + } + + return -1; +} + +/* Set hair_key->co to the given coordinate in object space (the given coordinate will be + * converted to the proper space). + * + * The hair_key can be coming from both original and evaluated object. Object, modifier and + * particle are to be from evaluated object, so that all the data needed for hair matrix is + * present. */ +static void hair_key_location_object_set(HairKey *hair_key, + Object *object, + ParticleSystemModifierData *modifier, + ParticleData *particle, + const float src_co[3]) +{ + Mesh *hair_mesh = (modifier->psys->flag & PSYS_HAIR_DYNAMICS) ? modifier->psys->hair_out_mesh : + NULL; + + if (hair_mesh != NULL) { + const int hair_key_index = hair_key_index_get(hair_key, modifier, particle); + if (hair_key_index == -1) { + return; + } + + MVert *mvert = &hair_mesh->mvert[particle->hair_index + (hair_key_index)]; + copy_v3_v3(mvert->co, src_co); + return; + } + + float hairmat[4][4]; + psys_mat_hair_to_object( + object, modifier->mesh_final, modifier->psys->part->from, particle, hairmat); + + float imat[4][4]; + invert_m4_m4(imat, hairmat); + + copy_v3_v3(hair_key->co, src_co); + mul_m4_v3(imat, hair_key->co); +} + static void rna_ParticleHairKey_location_object_set(PointerRNA *ptr, const float *values) { HairKey *hkey = (HairKey *)ptr->data; Object *ob = (Object *)ptr->owner_id; + ParticleSystemModifierData *psmd; ParticleData *pa; - rna_ParticleHairKey_location_object_info(ptr, &psmd, &pa); - if (pa) { - Mesh *hair_mesh = (psmd->psys->flag & PSYS_HAIR_DYNAMICS) ? psmd->psys->hair_out_mesh : NULL; - - if (hair_mesh) { - MVert *mvert = &hair_mesh->mvert[pa->hair_index + (hkey - pa->hair)]; - copy_v3_v3(mvert->co, values); - } - else { - float hairmat[4][4]; - float imat[4][4]; - - psys_mat_hair_to_object(ob, psmd->mesh_final, psmd->psys->part->from, pa, hairmat); - invert_m4_m4(imat, hairmat); - copy_v3_v3(hkey->co, values); - mul_m4_v3(imat, hkey->co); - } - } - else { + if (pa == NULL) { zero_v3(hkey->co); + return; } + + hair_key_location_object_set(hkey, ob, psmd, pa, values); } static void rna_ParticleHairKey_co_object(HairKey *hairkey, @@ -301,6 +353,31 @@ static void rna_ParticleHairKey_co_object(HairKey *hairkey, } } +static void rna_ParticleHairKey_co_object_set(ID *id, + HairKey *hair_key, + Object *object, + ParticleSystemModifierData *modifier, + ParticleData *particle, + float co[3]) +{ + + if (particle == NULL) { + return; + } + + /* Mark particle system as edited, so then particle_system_update() does not reset the hair + * keys from path. This behavior is similar to how particle edit mode sets flags. */ + ParticleSystemModifierData *orig_modifier = (ParticleSystemModifierData *) + modifier->modifier.orig_modifier_data; + orig_modifier->psys->flag |= PSYS_EDITED; + + hair_key_location_object_set(hair_key, object, modifier, particle, co); + + /* Tag similar to brushes in particle edit mode, so the modifier stack is properly evaluated + * with the same particle system recalc flags as during combing. */ + DEG_id_tag_update(id, ID_RECALC_GEOMETRY | ID_RECALC_PSYS_REDO); +} + static void rna_Particle_uv_on_emitter(ParticleData *particle, ReportList *reports, ParticleSystemModifierData *modifier, @@ -1651,6 +1728,19 @@ static void rna_def_particle_hair_key(BlenderRNA *brna) func, "co", 3, NULL, -FLT_MAX, FLT_MAX, "Co", "Exported hairkey location", -1e4, 1e4); RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); RNA_def_function_output(func, parm); + + func = RNA_def_function(srna, "co_object_set", "rna_ParticleHairKey_co_object_set"); + RNA_def_function_flag(func, FUNC_USE_SELF_ID); + RNA_def_function_ui_description(func, "Set hairkey location with particle and modifier data"); + parm = RNA_def_pointer(func, "object", "Object", "", "Object"); + RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); + parm = RNA_def_pointer(func, "modifier", "ParticleSystemModifier", "", "Particle modifier"); + RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); + parm = RNA_def_pointer(func, "particle", "Particle", "", "hair particle"); + RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); + parm = RNA_def_float_vector( + func, "co", 3, NULL, -FLT_MAX, FLT_MAX, "Co", "Specified hairkey location", -1e4, 1e4); + RNA_def_parameter_flags(parm, PROP_THICK_WRAP, PARM_REQUIRED); } static void rna_def_particle_key(BlenderRNA *brna) @@ -3019,7 +3109,7 @@ static void rna_def_particle_settings(BlenderRNA *brna) /* physical properties */ prop = RNA_def_property(srna, "mass", PROP_FLOAT, PROP_UNIT_MASS); RNA_def_property_range(prop, 0.00000001f, 100000.0f); - RNA_def_property_ui_range(prop, 0.01, 100, 1, 3); + RNA_def_property_ui_range(prop, 0.01, 100, 1, 4); RNA_def_property_ui_text(prop, "Mass", "Mass of the particles"); RNA_def_property_update(prop, 0, "rna_Particle_reset"); @@ -3349,7 +3439,7 @@ static void rna_def_particle_settings(BlenderRNA *brna) prop = RNA_def_property(srna, "keyed_loops", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "keyed_loops"); RNA_def_property_range(prop, 1.0f, 10000.0f); - RNA_def_property_ui_range(prop, 1.0f, 100.0f, 0.1, 3); + RNA_def_property_ui_range(prop, 1.0f, 100.0f, 1, 3); RNA_def_property_ui_text(prop, "Loop Count", "Number of times the keys are looped"); RNA_def_property_update(prop, 0, "rna_Particle_redo"); diff --git a/source/blender/makesrna/intern/rna_pointcloud.c b/source/blender/makesrna/intern/rna_pointcloud.c index 4e3243ae80f..90ff69b2a8a 100644 --- a/source/blender/makesrna/intern/rna_pointcloud.c +++ b/source/blender/makesrna/intern/rna_pointcloud.c @@ -156,6 +156,8 @@ static void rna_def_pointcloud(BlenderRNA *brna) RNA_def_property_collection_funcs( prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "rna_IDMaterials_assign_int"); + rna_def_attributes_common(srna); + /* common */ rna_def_animdata_common(srna); } diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index c7076d6c631..7134b085fe7 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -1852,7 +1852,7 @@ int rna_property_override_diff_default(Main *bmain, if (is_first_insert) { /* We need to clean up all possible existing insertion operations, - * otherwise we'd end up with a mess of ops everytime something changes. */ + * otherwise we'd end up with a mess of ops every time something changes. */ for (IDOverrideLibraryPropertyOperation *opop = op->operations.first; opop != NULL;) { IDOverrideLibraryPropertyOperation *opop_next = opop->next; diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 34a84ce9265..317759ce418 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -2606,9 +2606,10 @@ static void rna_FileBrowser_FSMenu_active_range(PointerRNA *UNUSED(ptr), *max = *softmax = ED_fsmenu_get_nentries(fsmenu, category) - 1; } -static void rna_FileBrowser_FSMenu_active_update(struct bContext *C, PointerRNA *UNUSED(ptr)) +static void rna_FileBrowser_FSMenu_active_update(struct bContext *C, PointerRNA *ptr) { - ED_file_change_dir(C); + ScrArea *area = rna_area_from_space(ptr); + ED_file_change_dir_ex(C, (bScreen *)ptr->owner_id, area); } static int rna_FileBrowser_FSMenuSystem_active_get(PointerRNA *ptr) @@ -2970,7 +2971,11 @@ static void rna_def_space_outliner(BlenderRNA *brna) ICON_RENDER_RESULT, "View Layer", "Display collections and objects in the view layer"}, - {SO_SEQUENCE, "SEQUENCE", ICON_SEQUENCE, "Sequence", "Display sequence data-blocks"}, + {SO_SEQUENCE, + "SEQUENCE", + ICON_SEQUENCE, + "Video Sequencer", + "Display data belonging to the Video Sequencer"}, {SO_LIBRARIES, "LIBRARIES", ICON_FILE_BLEND, @@ -3037,6 +3042,12 @@ static void rna_def_space_outliner(BlenderRNA *brna) prop, "Sync Outliner Selection", "Sync outliner selection with other editors"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL); + prop = RNA_def_property(srna, "show_mode_column", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", SO_MODE_COLUMN); + RNA_def_property_ui_text( + prop, "Show Mode Column", "Show the mode column for mode toggle and activation"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL); + /* Granular restriction column option. */ prop = RNA_def_property(srna, "show_restrict_column_enable", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "show_restrict_flags", SO_RESTRICT_ENABLE); diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 10e3f9c86ee..1ecd0a581b6 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -3061,6 +3061,11 @@ static void rna_def_userdef_theme_space_image(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Metadata Text", ""); RNA_def_property_update(prop, 0, "rna_userdef_theme_update"); + prop = RNA_def_property(srna, "grid", PROP_FLOAT, PROP_COLOR_GAMMA); + RNA_def_property_array(prop, 4); + RNA_def_property_ui_text(prop, "Grid", ""); + RNA_def_property_update(prop, 0, "rna_userdef_theme_update"); + rna_def_userdef_theme_spaces_curves(srna, false, false, false, true); rna_def_userdef_theme_spaces_paint_curves(srna); @@ -6118,6 +6123,11 @@ static void rna_def_userdef_experimental(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "use_sculpt_vertex_colors", 1); RNA_def_property_ui_text(prop, "Sculpt Vertex Colors", "Use the new Vertex Painting system"); + prop = RNA_def_property(srna, "use_image_editor_legacy_drawing", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "use_image_editor_legacy_drawing", 1); + RNA_def_property_ui_text( + prop, "Legacy Image Editor Drawing", "Use legacy UV/Image editor drawing"); + prop = RNA_def_property(srna, "use_tools_missing_icons", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "use_tools_missing_icons", 1); RNA_def_property_ui_text(prop, "Tools with Missing Icons", "Show tools with missing icons"); diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c index 98bbb328007..94a9a922ff7 100644 --- a/source/blender/modifiers/intern/MOD_hook.c +++ b/source/blender/modifiers/intern/MOD_hook.c @@ -313,10 +313,19 @@ static void deformVerts_do(HookModifierData *hmd, MOD_get_vgroup(ob, mesh, hmd->name, &dvert, &hd.defgrp_index); int cd_dvert_offset = -1; - if ((em != NULL) && (hd.defgrp_index != -1)) { - cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); - if (cd_dvert_offset == -1) { - hd.defgrp_index = -1; + if (hd.defgrp_index != -1) { + /* Edit-mesh. */ + if (em != NULL) { + cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); + if (cd_dvert_offset == -1) { + hd.defgrp_index = -1; + } + } + else { + /* Regular mesh. */ + if (dvert == NULL) { + hd.defgrp_index = -1; + } } } diff --git a/source/blender/modifiers/intern/MOD_meshcache_mdd.c b/source/blender/modifiers/intern/MOD_meshcache_mdd.c index cb150976ff5..d216c14ab43 100644 --- a/source/blender/modifiers/intern/MOD_meshcache_mdd.c +++ b/source/blender/modifiers/intern/MOD_meshcache_mdd.c @@ -65,13 +65,13 @@ static bool meshcache_read_mdd_head(FILE *fp, *err_str = "Invalid frame total"; return false; } - /* intentionally dont seek back */ + /* Intentionally don't seek back. */ return true; } /** - * Gets the index frange and factor + * Gets the index range and factor. */ static bool meshcache_read_mdd_range(FILE *fp, const int verts_tot, diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c index 179996d5acf..cc844e53603 100644 --- a/source/blender/modifiers/intern/MOD_util.c +++ b/source/blender/modifiers/intern/MOD_util.c @@ -229,7 +229,7 @@ Mesh *MOD_deform_mesh_eval_get(Object *ob, * that's properly generated for curves. */ mesh = BKE_mesh_new_nomain_from_curve(ob); - /* Currently, that may not be the case everytime + /* Currently, that may not be the case every time * (texts e.g. tend to give issues, * also when deforming curve points instead of generated curve geometry... ). */ if (mesh != NULL && mesh->totvert != num_verts) { diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c index a9a9a3ad5d9..a74be2b580e 100644 --- a/source/blender/python/bmesh/bmesh_py_types_customdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c @@ -84,6 +84,15 @@ PyDoc_STRVAR(bpy_bmlayeraccess_collection__float_doc, "Generic float custom-data layer.\n\ntype: :class:`BMLayerCollection`"); PyDoc_STRVAR(bpy_bmlayeraccess_collection__int_doc, "Generic int custom-data layer.\n\ntype: :class:`BMLayerCollection`"); +PyDoc_STRVAR(bpy_bmlayeraccess_collection__float_vector_doc, + "Generic 3D vector with float precision custom-data layer.\n\ntype: " + ":class:`BMLayerCollection`"); +PyDoc_STRVAR(bpy_bmlayeraccess_collection__float_color_doc, + "Generic RGBA color with float precision custom-data layer.\n\ntype: " + ":class:`BMLayerCollection`"); +PyDoc_STRVAR(bpy_bmlayeraccess_collection__color_doc, + "Generic RGBA color with 8-bit precision custom-data layer.\n\ntype: " + ":class:`BMLayerCollection`"); PyDoc_STRVAR(bpy_bmlayeraccess_collection__string_doc, "Generic string custom-data layer (exposed as bytes, 255 max length).\n\ntype: " ":class:`BMLayerCollection`"); @@ -102,8 +111,6 @@ PyDoc_STRVAR(bpy_bmlayeraccess_collection__crease_doc, PyDoc_STRVAR( bpy_bmlayeraccess_collection__uv_doc, "Accessor for :class:`BMLoopUV` UV (as a 2D Vector).\n\ntype: :class:`BMLayerCollection`"); -PyDoc_STRVAR(bpy_bmlayeraccess_collection__color_doc, - "Accessor for vertex color layer.\n\ntype: :class:`BMLayerCollection`"); PyDoc_STRVAR(bpy_bmlayeraccess_collection__skin_doc, "Accessor for skin layer.\n\ntype: :class:`BMLayerCollection`"); PyDoc_STRVAR(bpy_bmlayeraccess_collection__paint_mask_doc, @@ -188,6 +195,21 @@ static PyGetSetDef bpy_bmlayeraccess_vert_getseters[] = { (setter)NULL, bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT32}, + {"float_vector", + (getter)bpy_bmlayeraccess_collection_get, + (setter)NULL, + bpy_bmlayeraccess_collection__float_vector_doc, + (void *)CD_PROP_FLOAT3}, + {"float_color", + (getter)bpy_bmlayeraccess_collection_get, + (setter)NULL, + bpy_bmlayeraccess_collection__float_color_doc, + (void *)CD_PROP_COLOR}, + {"color", + (getter)bpy_bmlayeraccess_collection_get, + (setter)NULL, + bpy_bmlayeraccess_collection__color_doc, + (void *)CD_MLOOPCOL}, {"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, @@ -229,6 +251,21 @@ static PyGetSetDef bpy_bmlayeraccess_edge_getseters[] = { (setter)NULL, bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT32}, + {"float_vector", + (getter)bpy_bmlayeraccess_collection_get, + (setter)NULL, + bpy_bmlayeraccess_collection__float_vector_doc, + (void *)CD_PROP_FLOAT3}, + {"float_color", + (getter)bpy_bmlayeraccess_collection_get, + (setter)NULL, + bpy_bmlayeraccess_collection__float_color_doc, + (void *)CD_PROP_COLOR}, + {"color", + (getter)bpy_bmlayeraccess_collection_get, + (setter)NULL, + bpy_bmlayeraccess_collection__color_doc, + (void *)CD_MLOOPCOL}, {"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, @@ -267,6 +304,21 @@ static PyGetSetDef bpy_bmlayeraccess_face_getseters[] = { (setter)NULL, bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT32}, + {"float_vector", + (getter)bpy_bmlayeraccess_collection_get, + (setter)NULL, + bpy_bmlayeraccess_collection__float_vector_doc, + (void *)CD_PROP_FLOAT3}, + {"float_color", + (getter)bpy_bmlayeraccess_collection_get, + (setter)NULL, + bpy_bmlayeraccess_collection__float_color_doc, + (void *)CD_PROP_COLOR}, + {"color", + (getter)bpy_bmlayeraccess_collection_get, + (setter)NULL, + bpy_bmlayeraccess_collection__color_doc, + (void *)CD_MLOOPCOL}, {"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, @@ -300,12 +352,21 @@ static PyGetSetDef bpy_bmlayeraccess_loop_getseters[] = { (setter)NULL, bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT32}, + {"float_vector", + (getter)bpy_bmlayeraccess_collection_get, + (setter)NULL, + bpy_bmlayeraccess_collection__float_vector_doc, + (void *)CD_PROP_FLOAT3}, + {"float_color", + (getter)bpy_bmlayeraccess_collection_get, + (setter)NULL, + bpy_bmlayeraccess_collection__float_color_doc, + (void *)CD_PROP_COLOR}, {"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STRING}, - {"uv", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, @@ -1072,6 +1133,14 @@ PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer) ret = PyLong_FromLong(*(int *)value); break; } + case CD_PROP_FLOAT3: { + ret = Vector_CreatePyObject_wrap((float *)value, 3, NULL); + break; + } + case CD_PROP_COLOR: { + ret = Vector_CreatePyObject_wrap((float *)value, 4, NULL); + break; + } case CD_PROP_STRING: { MStringProperty *mstring = value; ret = PyBytes_FromStringAndSize(mstring->s, mstring->s_len); @@ -1150,6 +1219,18 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj } break; } + case CD_PROP_FLOAT3: { + if (mathutils_array_parse((float *)value, 3, 3, py_value, "BMElem Float Vector") == -1) { + ret = -1; + } + break; + } + case CD_PROP_COLOR: { + if (mathutils_array_parse((float *)value, 4, 4, py_value, "BMElem Float Color") == -1) { + ret = -1; + } + break; + } case CD_PROP_STRING: { MStringProperty *mstring = value; char *tmp_val; diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index f9ff0558570..55753e91f14 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -607,12 +607,12 @@ PyDoc_STRVAR( " ``GL_ARB_texture_gather``, ``GL_ARB_texture_cube_map_array`` and " "``GL_ARB_shader_draw_parameters``.\n" "\n" - " To debug shaders, use the --debug-gpu-shaders command line option" - " to see full GLSL shader compilation and linking errors.\n" + " To debug shaders, use the ``--debug-gpu-shaders`` command line option " + "to see full GLSL shader compilation and linking errors.\n" "\n" " For drawing user interface elements and gizmos, use " - " ``fragOutput = blender_srgb_to_framebuffer_space(fragOutput)``" - " to transform the output sRGB colors to the framebuffer colorspace." + "``fragOutput = blender_srgb_to_framebuffer_space(fragOutput)`` " + "to transform the output sRGB colors to the frame-buffer color-space." "\n" " :param vertexcode: Vertex shader code.\n" " :type vertexcode: str\n" diff --git a/source/blender/python/intern/bpy_rna_ui.c b/source/blender/python/intern/bpy_rna_ui.c index 9f37b8300db..27e4cb069ce 100644 --- a/source/blender/python/intern/bpy_rna_ui.c +++ b/source/blender/python/intern/bpy_rna_ui.c @@ -29,6 +29,7 @@ #include "UI_interface.h" #include "bpy_rna.h" +#include "bpy_rna_ui.h" PyDoc_STRVAR(bpy_rna_uilayout_introspect_doc, ".. method:: introspect()\n" diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c index 37ed9f89bc7..b1a469d1365 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.c +++ b/source/blender/windowmanager/intern/wm_dragdrop.c @@ -400,7 +400,7 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect) rect->ymin = rect->ymax = cursory; } - /* XXX todo, multiline drag draws... but maybe not, more types mixed wont work well */ + /* Should we support multi-line drag draws? Maybe not, more types mixed wont work well. */ GPU_blend(GPU_BLEND_ALPHA); for (drag = wm->drags.first; drag; drag = drag->next) { const uchar text_col[] = {255, 255, 255, 255}; diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index c0de86a599c..1d3db3e7609 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -795,6 +795,7 @@ static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view) /* After area regions so we can do area 'overlay' drawing. */ ED_screen_draw_edges(win); wm_draw_callbacks(win); + wmWindowViewport(win); /* Blend in floating regions (menus). */ LISTBASE_FOREACH (ARegion *, region, &screen->regionbase) { diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index b85bf8cb323..5a22e990218 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -190,8 +190,6 @@ void WM_init_opengl(void) GPU_pass_cache_init(); - BKE_subdiv_init(); - opengl_is_init = true; } @@ -323,6 +321,8 @@ void WM_init(bContext *C, int argc, const char **argv) UI_init(); } + BKE_subdiv_init(); + ED_spacemacros_init(); /* note: there is a bug where python needs initializing before loading the |