From 29b65f5345128ee035599aa7233315a74fe6afe6 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Fri, 2 Jul 2021 12:04:07 +0200 Subject: GPencil: New modifier to generate weights dynamically his new modifier allows to generate weights base on: * Angle of the stroke relative to object or world orientation. For example, if the value is 90, the maximum weights will be for vertical lines and minimum for horizontal lines. * Distance to Target object. The distance calculated is normalized to get valid weights between 0 and 1.0. The weights are created in an existing vertex group and the data can be replaced or mixed with the existing value to combine different weight effects. The minimum parameter, allows to define the minimum weight generated. This is useful to avoid very low weights. The generated weights can be used in any modifier. For example, the angle weight value can be used to mimic FreeStyle Caligraphy modifier using the weight with the thickness modifier. Also some modifier has been changed to inlude a new option to use the weights as factor of the effect. As result of this change, the fading option has been removed from Thickness and Opacity modifiers because this can be done using the new modifier, it's not logic to repeat the same. Reviewed By: mendio, filedescriptor Differential Revision: https://developer.blender.org/D11604 --- source/blender/makesdna/intern/dna_defaults.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/blender/makesdna/intern') diff --git a/source/blender/makesdna/intern/dna_defaults.c b/source/blender/makesdna/intern/dna_defaults.c index 2d55ea05867..03f7dbf6489 100644 --- a/source/blender/makesdna/intern/dna_defaults.c +++ b/source/blender/makesdna/intern/dna_defaults.c @@ -315,6 +315,7 @@ SDNA_DEFAULT_DECL_STRUCT(TextureGpencilModifierData); SDNA_DEFAULT_DECL_STRUCT(ThickGpencilModifierData); SDNA_DEFAULT_DECL_STRUCT(TimeGpencilModifierData); SDNA_DEFAULT_DECL_STRUCT(TintGpencilModifierData); +SDNA_DEFAULT_DECL_STRUCT(WeightGpencilModifierData); SDNA_DEFAULT_DECL_STRUCT(LineartGpencilModifierData); SDNA_DEFAULT_DECL_STRUCT(LengthGpencilModifierData); @@ -541,6 +542,7 @@ const void *DNA_default_table[SDNA_TYPE_MAX] = { SDNA_DEFAULT_DECL(ThickGpencilModifierData), SDNA_DEFAULT_DECL(TimeGpencilModifierData), SDNA_DEFAULT_DECL(TintGpencilModifierData), + SDNA_DEFAULT_DECL(WeightGpencilModifierData), SDNA_DEFAULT_DECL(LineartGpencilModifierData), SDNA_DEFAULT_DECL(LengthGpencilModifierData), }; -- cgit v1.2.3 From 9b89de2571b0c3fa2276b5c2ae589e0ec831d1f5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 3 Jul 2021 23:08:40 +1000 Subject: Cleanup: consistent use of tags: NOTE/TODO/FIXME/XXX Also use doxy style function reference `#` prefix chars when referencing identifiers. --- source/blender/makesdna/intern/dna_genfile.c | 4 ++-- source/blender/makesdna/intern/makesdna.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/makesdna/intern') diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index 2a4bf53702f..84a77e9553e 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -47,7 +47,7 @@ /** * \section dna_genfile Overview * - * - please note: no builtin security to detect input of double structs + * - please NOTE: no builtin security to detect input of double structs * - if you want a struct not to be in DNA file: add two hash marks above it `(##)`. * * Structure DNA data is added to each blender file and to each executable, this to detect @@ -1060,7 +1060,7 @@ void DNA_struct_switch_endian(const SDNA *sdna, int struct_nr, char *data) } case SDNA_TYPE_INT: case SDNA_TYPE_FLOAT: { - /* Note, intentionally ignore long/ulong, because these could be 4 or 8 bytes. + /* NOTE: intentionally ignore long/ulong, because these could be 4 or 8 bytes. * Fortunately, we only use these types for runtime variables and only once for a * struct type that is no longer used. */ BLI_endian_switch_int32_array((int32_t *)member_data, member_array_length); diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index 24cfc1d84f6..5b08f2bf100 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -360,7 +360,7 @@ static int add_type(const char *str, int size) return -1; } if (strchr(str, '*')) { - /* note: this is valid C syntax but we can't parse, complain! + /* NOTE: this is valid C syntax but we can't parse, complain! * `struct SomeStruct* some_var;` <-- correct but we can't handle right now. */ return -1; } @@ -567,7 +567,7 @@ static short *add_struct(int namecode) static int preprocess_include(char *maindata, const int maindata_len) { - /* note: len + 1, last character is a dummy to prevent + /* NOTE: len + 1, last character is a dummy to prevent * comparisons using uninitialized memory */ char *temp = MEM_mallocN(maindata_len + 1, "preprocess_include"); temp[maindata_len] = ' '; -- cgit v1.2.3 From f0f7282d9d9bb5deb6216ac95e280b24f89eb239 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 5 Jul 2021 12:47:46 +1000 Subject: Cleanup: spelling in comments --- source/blender/makesdna/intern/makesdna.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/makesdna/intern') diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index 5b08f2bf100..fb1cf9b591d 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -422,7 +422,7 @@ static int add_name(const char *str) int isfuncptr = (strchr(str + 1, '(')) != NULL; DEBUG_PRINTF(3, "\t\t\t\t*** Function pointer or multidim array pointer found\n"); - /* functionpointer: transform the type (sometimes) */ + /* function-pointer: transform the type (sometimes). */ int i = 0; while (str[i] != ')') { -- cgit v1.2.3 From 31e6f0dc7af6ff1be19da93021b7095fe68da833 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 7 Jul 2021 12:35:03 +1000 Subject: makesdna: fix parsing 'const', 'struct', 'unsigned' as a prefix DNA parsing assumed any identifier which starts with (`struct`, `unsigned`, `const`) was that identifier. So a struct called `constTest foo;` would be parsed as `est foo;`. Add utility function to check identifiers are not part of a larger identifier. This also supports skipping these identifiers in any order. Reviewed By: LazyDodo Ref D11837 --- source/blender/makesdna/intern/makesdna.c | 60 +++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 10 deletions(-) (limited to 'source/blender/makesdna/intern') diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index fb1cf9b591d..f2a75a60a44 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -43,6 +43,7 @@ #define DNA_DEPRECATED_ALLOW +#include #include #include #include @@ -272,6 +273,37 @@ void print_struct_sizes(void); * Make DNA string (write to file). * \{ */ +static bool match_identifier_with_len(const char *str, + const char *identifier, + const size_t identifier_len) +{ + if (strncmp(str, identifier, identifier_len) == 0) { + /* Check `str` isn't a prefix to a longer identifier. */ + if (isdigit(str[identifier_len]) || isalpha(str[identifier_len]) || + (str[identifier_len] == '_')) { + return false; + } + return true; + } + return false; +} + +static bool match_identifier(const char *str, const char *identifier) +{ + const size_t identifier_len = strlen(identifier); + return match_identifier_with_len(str, identifier, identifier_len); +} + +static bool match_identifier_and_advance(char **str_ptr, const char *identifier) +{ + const size_t identifier_len = strlen(identifier); + if (match_identifier_with_len(*str_ptr, identifier, identifier_len)) { + (*str_ptr) += identifier_len; + return true; + } + return false; +} + static const char *version_struct_static_from_alias(const char *str) { const char *str_test = BLI_ghash_lookup(g_version_data.struct_map_static_from_alias, str); @@ -619,7 +651,7 @@ static int preprocess_include(char *maindata, const int maindata_len) else if (cp[-1] == '*' && cp[0] == ' ') { /* pointers with a space */ } /* skip special keywords */ - else if (strncmp("DNA_DEPRECATED", cp, 14) == 0) { + else if (match_identifier(cp, "DNA_DEPRECATED")) { /* single values are skipped already, so decrement 1 less */ a -= 13; cp += 13; @@ -721,7 +753,7 @@ static int convert_include(const char *filename) md1++; /* we've got a struct name when... */ - if (strncmp(md1 - 7, "struct", 6) == 0) { + if (match_identifier(md1 - 7, "struct")) { const int strct = add_type(md1, 0); if (strct == -1) { @@ -756,14 +788,22 @@ static int convert_include(const char *filename) /* skip when it says 'struct' or 'unsigned' or 'const' */ if (*md1) { - if (strncmp(md1, "struct", 6) == 0) { - md1 += 7; - } - if (strncmp(md1, "unsigned", 8) == 0) { - md1 += 9; - } - if (strncmp(md1, "const", 5) == 0) { - md1 += 6; + const char *md1_prev = md1; + while (match_identifier_and_advance(&md1, "struct") || + match_identifier_and_advance(&md1, "unsigned") || + match_identifier_and_advance(&md1, "const")) { + if (UNLIKELY(!ELEM(*md1, '\0', ' '))) { + /* This will happen with: `unsigned(*value)[3]` which isn't supported. */ + fprintf(stderr, + "File '%s' contains non white space character " + "\"%c\" after identifier \"%s\"\n", + filename, + *md1, + md1_prev); + return 1; + } + /* Skip ' ' or '\0'. */ + md1++; } /* we've got a type! */ -- cgit v1.2.3 From 8e8a6b80cf2749d176d14eaa3bbfd0eccc9ec75e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 15 Jul 2021 18:23:28 +1000 Subject: Cleanup: replace BLI_assert(!"text") with BLI_assert_msg(0, "text") This shows the text as part of the assertion message. --- source/blender/makesdna/intern/dna_genfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/makesdna/intern') diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index 84a77e9553e..d23b9441822 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -1398,7 +1398,7 @@ static void init_reconstruct_step_for_member(const SDNA *oldsdna, r_step->data.cast_pointer.array_len = shared_array_length; } else { - BLI_assert(!"invalid pointer size"); + BLI_assert_msg(0, "invalid pointer size"); r_step->type = RECONSTRUCT_STEP_INIT_ZERO; } break; -- cgit v1.2.3 From 7898089de3f20b08a08516bd2fd2be7dd1c565fe Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 8 Jul 2021 22:16:50 +0200 Subject: Assets: Add an active asset library per workspace, for the UI to use This per-workspace active asset library will be used by the asset views later. Note that Asset Browsers have their own active asset library, overriding the one from the workspace. As part of this the `FileSelectAssetLibraryUID` type gets replaced by `AssetLibraryReference` which is on the asset level now, not the File/Asset Browser level. But some more work is needed to complete that, which is better done in a separate commit. This also moves the asset library from/to enum-value logic from RNA to the editor asset level, which will later be used by the asset view. --- source/blender/makesdna/intern/dna_defaults.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/blender/makesdna/intern') diff --git a/source/blender/makesdna/intern/dna_defaults.c b/source/blender/makesdna/intern/dna_defaults.c index 03f7dbf6489..a573e2f9e8c 100644 --- a/source/blender/makesdna/intern/dna_defaults.c +++ b/source/blender/makesdna/intern/dna_defaults.c @@ -152,6 +152,7 @@ /* DNA_asset_defaults.h */ SDNA_DEFAULT_DECL_STRUCT(AssetMetaData); +SDNA_DEFAULT_DECL_STRUCT(AssetLibraryReference); /* DNA_armature_defaults.h */ SDNA_DEFAULT_DECL_STRUCT(bArmature); @@ -348,6 +349,7 @@ const void *DNA_default_table[SDNA_TYPE_MAX] = { /* DNA_asset_defaults.h */ SDNA_DEFAULT_DECL(AssetMetaData), + SDNA_DEFAULT_DECL(AssetLibraryReference), /* DNA_armature_defaults.h */ SDNA_DEFAULT_DECL(bArmature), -- cgit v1.2.3 From 1ab6d5c1dcbeebc0794999d358d483f0b6cac67f Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Wed, 14 Jul 2021 22:51:59 +0300 Subject: Surface Deform: support sparse binding mode for improving performance. When a vertex group is used to limit the influence of the modifier to a subset of vertices, binding data for vertices with zero weight is not needed. This wastes memory, disk space and CPU cycles. If the vertex group contents is known to be final and constant, it is reasonable to optimize by only storing data group vertices. This has to be an option in case the group can change. Supporting this requires adding a vertex index field and spliting the vertex count into mesh and bind variants, but both happen to fit in available padding. The old numverts field is renamed to the new bound vertex count field to maintain the array length invariant. Versioning is used to initialize the other new fields. If a file with sparse binding is opened in an old blender version, it is corrupted into a non-sparse bind with vertex count mismatch, preventing the modifier from working until rebind. Differential Revision: https://developer.blender.org/D11924 --- source/blender/makesdna/intern/dna_rename_defs.h | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/makesdna/intern') diff --git a/source/blender/makesdna/intern/dna_rename_defs.h b/source/blender/makesdna/intern/dna_rename_defs.h index 735be0c10bf..d363e40e4f0 100644 --- a/source/blender/makesdna/intern/dna_rename_defs.h +++ b/source/blender/makesdna/intern/dna_rename_defs.h @@ -136,4 +136,5 @@ DNA_STRUCT_RENAME_ELEM(wmWindow, global_area_map, global_areas) DNA_STRUCT_RENAME_ELEM(LineartGpencilModifierData, line_types, edge_types) DNA_STRUCT_RENAME_ELEM(LineartGpencilModifierData, transparency_flags, mask_switches) DNA_STRUCT_RENAME_ELEM(LineartGpencilModifierData, transparency_mask, material_mask_bits) +DNA_STRUCT_RENAME_ELEM(SurfaceDeformModifierData, numverts, num_bind_verts) DNA_STRUCT_RENAME_ELEM(MaterialLineArt, transparency_mask, material_mask_bits) -- cgit v1.2.3