Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2011-02-21 21:18:37 +0300
committerLukas Toenne <lukas.toenne@googlemail.com>2011-02-21 21:18:37 +0300
commit4fb730d6d0f20db2d35b36237d5778a40bdec076 (patch)
treea6c92e6f77f19b7cd78e26d40028e80b3672ee3d /source/blender/blenloader
parent33887fa41dcc010a8543e8bc78d1b2de23fcd099 (diff)
Fixed do_versions for node groups which contain nodes that have changed sockets. do_versions is running before the lib_verify_nodetree function updates socket lists of nodes. This means that when adding unlinked sockets in do_versions to restore older node groups, the new sockets are not taken into account. To fix this a temporary node tree flag has been introduced, which delays actual group socket do_version until the group tree internal nodes have been updated. After that the unlinked group sockets are exposed (like old node groups did), then the external sockets look up the new index, so that external links to group instances are preserved.
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r--source/blender/blenloader/intern/readfile.c86
1 files changed, 85 insertions, 1 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 3f722cc8cf3..8e9273fafc5 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2028,6 +2028,55 @@ static void lib_link_nodetree(FileData *fd, Main *main)
}
}
+/* updates group node socket own_index so that
+ * external links to/from the group node are preserved.
+ */
+static void lib_node_do_versions_group(bNode *gnode)
+{
+ bNodeTree *ngroup= (bNodeTree*)gnode->id;
+ bNode *intnode;
+ bNodeSocket *sock, *gsock, *intsock;
+ int found;
+
+ for (sock=gnode->outputs.first; sock; sock=sock->next) {
+ int old_index = sock->to_index;
+ for (gsock=ngroup->outputs.first; gsock; gsock=gsock->next) {
+ if (gsock->link && gsock->link->fromsock->own_index == old_index) {
+ sock->own_index = gsock->own_index;
+ break;
+ }
+ }
+ }
+ for (sock=gnode->inputs.first; sock; sock=sock->next) {
+ int old_index = sock->to_index;
+ /* can't use break in double loop */
+ found = 0;
+ for (intnode=ngroup->nodes.first; intnode && !found; intnode=intnode->next) {
+ for (intsock=intnode->inputs.first; intsock; intsock=intsock->next) {
+ if (intsock->own_index == old_index && intsock->link) {
+ sock->own_index = intsock->link->fromsock->own_index;
+ found = 1;
+ break;
+ }
+ }
+ }
+ }
+}
+
+/* updates external links for all group nodes in a tree */
+static void lib_nodetree_do_versions_group(bNodeTree *ntree)
+{
+ bNode *node;
+
+ for (node=ntree->nodes.first; node; node=node->next) {
+ if (node->type==NODE_GROUP) {
+ bNodeTree *ngroup= (bNodeTree*)node->id;
+ if (ngroup->flag & NTREE_DO_VERSIONS)
+ lib_node_do_versions_group(node);
+ }
+ }
+}
+
/* verify types for nodes and groups, all data has to be read */
/* open = 0: appending/linking, open = 1: open new file (need to clean out dynamic
* typedefs*/
@@ -2049,6 +2098,37 @@ static void lib_verify_nodetree(Main *main, int UNUSED(open))
ntreeVerifyTypes(ntree); /* internal nodes, no groups! */
}
+ {
+ int has_old_groups=0;
+ /* XXX this should actually be part of do_versions, but since we need
+ * finished library linking, it is not possible there. Instead in do_versions
+ * we have set the NTREE_DO_VERSIONS flag, so at this point we can do the
+ * actual group node updates.
+ */
+ for(ntree= main->nodetree.first; ntree; ntree= ntree->id.next) {
+ if (ntree->flag & NTREE_DO_VERSIONS) {
+ /* this adds copies and links from all unlinked internal sockets to group inputs/outputs. */
+ nodeAddAllGroupSockets(ntree);
+ has_old_groups = 1;
+ }
+ }
+ /* now verify all types in material trees, groups are set OK now */
+ for(ma= main->mat.first; ma; ma= ma->id.next) {
+ if(ma->nodetree)
+ lib_nodetree_do_versions_group(ma->nodetree);
+ }
+ /* and scene trees */
+ for(sce= main->scene.first; sce; sce= sce->id.next) {
+ if(sce->nodetree)
+ lib_nodetree_do_versions_group(ma->nodetree);
+ }
+ /* and texture trees */
+ for(tx= main->tex.first; tx; tx= tx->id.next) {
+ if(tx->nodetree)
+ lib_nodetree_do_versions_group(ma->nodetree);
+ }
+ }
+
/* now verify all types in material trees, groups are set OK now */
for(ma= main->mat.first; ma; ma= ma->id.next) {
if(ma->nodetree)
@@ -11375,7 +11455,11 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
* this mimics the old behaviour by adding all unlinked sockets to groups.
*/
for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) {
- nodeAddAllGroupSockets(ntree);
+ /* XXX Only setting a flag here. Actual adding of group sockets
+ * is done in lib_verify_nodetree, because at this point the internal
+ * nodes may not be up-to-date! (missing lib-link)
+ */
+ ntree->flag |= NTREE_DO_VERSIONS;
}
}