diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_gpencil.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/gpencil.c | 15 |
2 files changed, 19 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h index a0a3f30d6d8..4b4886e8bf3 100644 --- a/source/blender/blenkernel/BKE_gpencil.h +++ b/source/blender/blenkernel/BKE_gpencil.h @@ -228,6 +228,10 @@ struct Material *BKE_gpencil_object_material_ensure_from_brush(struct Main *bmai int BKE_gpencil_object_material_ensure(struct Main *bmain, struct Object *ob, struct Material *material); +struct Material *BKE_gpencil_object_material_ensure_by_name(struct Main *bmain, + struct Object *ob, + const char *name, + int *r_index); struct Material *BKE_gpencil_object_material_new(struct Main *bmain, struct Object *ob, @@ -235,7 +239,7 @@ struct Material *BKE_gpencil_object_material_new(struct Main *bmain, int *r_index); int BKE_gpencil_object_material_index_get(struct Object *ob, struct Material *ma); -int BKE_gpencil_object_material_get_index_name(struct Object *ob, char *name); +int BKE_gpencil_object_material_index_get_by_name(struct Object *ob, const char *name); struct Material *BKE_gpencil_object_material_from_brush_get(struct Object *ob, struct Brush *brush); diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 3b46672f9cd..f7b895c7ca7 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -2446,7 +2446,7 @@ int BKE_gpencil_object_material_index_get(Object *ob, Material *ma) return -1; } -int BKE_gpencil_object_material_get_index_name(Object *ob, char *name) +int BKE_gpencil_object_material_index_get_by_name(Object *ob, const char *name) { short *totcol = BKE_object_material_len_p(ob); Material *read_ma = NULL; @@ -2461,6 +2461,19 @@ int BKE_gpencil_object_material_get_index_name(Object *ob, char *name) return -1; } +Material *BKE_gpencil_object_material_ensure_by_name(Main *bmain, + Object *ob, + const char *name, + int *r_index) +{ + int index = BKE_gpencil_object_material_index_get_by_name(ob, name); + if (index != -1) { + *r_index = index; + return BKE_object_material_get(ob, index + 1); + } + return BKE_gpencil_object_material_new(bmain, ob, name, r_index); +} + /** * Create a default palette. * \param bmain: Main pointer |