IDMAnagement: Add owner ID pointer to embedded ones.

Add a dedicated `owner_id` pointer to ID types that can be embedded
(Collections and NodeTrees), and modify slightly come code to make
handling those more safe and consistent.

This implements first part of T69169.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D15838
This commit is contained in:
Bastien Montagne
2022-09-05 15:46:00 +02:00
committed by Bastien Montagne
parent dd19d6456a
commit cd49fee741
20 changed files with 118 additions and 89 deletions

View File

@@ -506,12 +506,12 @@ void ED_node_shader_default(const bContext *C, ID *id)
}
else if (ELEM(GS(id->name), ID_WO, ID_LA)) {
/* Emission */
bNodeTree *ntree = ntreeAddTree(nullptr, "Shader Nodetree", ntreeType_Shader->idname);
bNodeTree *ntree = ntreeAddTreeEmbedded(
nullptr, id, "Shader Nodetree", ntreeType_Shader->idname);
bNode *shader, *output;
if (GS(id->name) == ID_WO) {
World *world = (World *)id;
world->nodetree = ntree;
shader = nodeAddStaticNode(nullptr, ntree, SH_NODE_BACKGROUND);
output = nodeAddStaticNode(nullptr, ntree, SH_NODE_OUTPUT_WORLD);
@@ -525,9 +525,6 @@ void ED_node_shader_default(const bContext *C, ID *id)
copy_v3_v3(((bNodeSocketValueRGBA *)color_sock->default_value)->value, &world->horr);
}
else {
Light *light = (Light *)id;
light->nodetree = ntree;
shader = nodeAddStaticNode(nullptr, ntree, SH_NODE_EMISSION);
output = nodeAddStaticNode(nullptr, ntree, SH_NODE_OUTPUT_LIGHT);
nodeAddLink(ntree,
@@ -560,7 +557,8 @@ void ED_node_composit_default(const bContext *C, Scene *sce)
return;
}
sce->nodetree = ntreeAddTree(nullptr, "Compositing Nodetree", ntreeType_Composite->idname);
sce->nodetree = ntreeAddTreeEmbedded(
nullptr, &sce->id, "Compositing Nodetree", ntreeType_Composite->idname);
sce->nodetree->chunksize = 256;
sce->nodetree->edit_quality = NTREE_QUALITY_HIGH;
@@ -593,7 +591,8 @@ void ED_node_texture_default(const bContext *C, Tex *tex)
return;
}
tex->nodetree = ntreeAddTree(nullptr, "Texture Nodetree", ntreeType_Texture->idname);
tex->nodetree = ntreeAddTreeEmbedded(
nullptr, &tex->id, "Texture Nodetree", ntreeType_Texture->idname);
bNode *out = nodeAddStaticNode(C, tex->nodetree, TEX_NODE_OUTPUT);
out->locx = 300.0f;