diff options
author | Sergey Sharybin <sergey@blender.org> | 2022-08-03 11:54:11 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2022-08-04 17:02:44 +0300 |
commit | 665d3db3a40c1e1ec3c5c5371b29bddcf07a6f92 (patch) | |
tree | daf07202118e1f8df71bbef69f27b7d3bb5913e4 /source/blender/makesrna/intern/rna_ID.c | |
parent | 39a68b27b90e4dc85e9eb69364bb81fad8e36337 (diff) |
Fix T99460: Allow creation new datablocks from evaluated
This changes makes it possible to copy evaluated result and put it
to the original bmain.
Prior to this change from the API point of view there was false
perception that it is possible, while in practice it was very fragile:
it only worked if the ID did not reference any evaluated IDs.
This change makes it so `id.copy()` Python API call will make it so
the copied ID only references original data-blocks. This sounds a bit
implicit, so here is motivational aspect why it is considered better
approach to all other:
- There needs to be a way to support the described scenario, in the
lest fragile way. Requiring to always use an explicit function call
or an argument is too verbose and is easy to be missed.
- The `id.copy()` is already doing implicit thing: it always adds the
result to the bmain. So it might as well ensure the copied result
does not reference evaluated data-blocks.
- Added clarity in the documentation should address possible confusion.
The limitation of this change is that the copy() of evaluated geometry
will clear its reference to the shape key. This is because the key is
only referenced for validness of RNA paths for drivers and the key
itself might not match topology of evaluated geometry due to modifiers.
Differential Revision: https://developer.blender.org/D15611
Diffstat (limited to 'source/blender/makesrna/intern/rna_ID.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_ID.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index b4fa7088d38..4b8f8ca7b4b 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -650,7 +650,7 @@ static ID *rna_ID_evaluated_get(ID *id, struct Depsgraph *depsgraph) static ID *rna_ID_copy(ID *id, Main *bmain) { - ID *newid = BKE_id_copy(bmain, id); + ID *newid = BKE_id_copy_for_use_in_bmain(bmain, id); if (newid != NULL) { id_us_min(newid); @@ -2045,7 +2045,10 @@ static void rna_def_ID(BlenderRNA *brna) func = RNA_def_function(srna, "copy", "rna_ID_copy"); RNA_def_function_ui_description( - func, "Create a copy of this data-block (not supported for all data-blocks)"); + func, + "Create a copy of this data-block (not supported for all data-blocks). " + "The result is added to the Blend-File Data (Main database), with all references to other " + "data-blocks ensured to be from within the same Blend-File Data"); RNA_def_function_flag(func, FUNC_USE_MAIN); parm = RNA_def_pointer(func, "id", "ID", "", "New copy of the ID"); RNA_def_function_return(func, parm); |