Revision: 44740
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44740
Author:   lukastoenne
Date:     2012-03-08 12:04:06 +0000 (Thu, 08 Mar 2012)
Log Message:
-----------
Modified behaviour of the link-insertion operator (drag on link, request by 
Sebastian Koenig). This would previously attempt to find a socket with exactly 
matching type to the from/to sockets of the cut link, but this is annoying 
because it often links to the "secondary" sockets, such as Factor input in the 
Mix node. New behaviour is to choose the input/output for reconnection based on 
the "highest" (= most important) socket types (in order color, vector, value), 
like the autoconnect operator (FKEY) also does. It is far from ideal and will 
probably not work in all situations either, but until we have a detailed design 
for "best sockets to auto-link" this will have to do.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_node/node_edit.c

Modified: trunk/blender/source/blender/editors/space_node/node_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_edit.c 2012-03-08 
11:57:51 UTC (rev 44739)
+++ trunk/blender/source/blender/editors/space_node/node_edit.c 2012-03-08 
12:04:06 UTC (rev 44740)
@@ -2698,34 +2698,35 @@
 /* *********************  automatic node insert on dragging 
******************* */
 
 /* assumes sockets in list */
-static bNodeSocket *socket_best_match(ListBase *sockets, int type)
+static bNodeSocket *socket_best_match(ListBase *sockets)
 {
        bNodeSocket *sock;
+       int type, maxtype=0;
        
-       /* first, match type */
-       for(sock= sockets->first; sock; sock= sock->next)
-               if(!nodeSocketIsHidden(sock))
-                       if(type == sock->type)
+       /* find type range */
+       for (sock=sockets->first; sock; sock=sock->next)
+               maxtype = MAX2(sock->type, maxtype);
+       
+       /* try all types, starting from 'highest' (i.e. colors, vectors, 
values) */
+       for (type=maxtype; type >= 0; --type) {
+               for(sock= sockets->first; sock; sock= sock->next) {
+                       if(!nodeSocketIsHidden(sock) && type==sock->type) {
                                return sock;
+                       }
+               }
+       }
        
-       /* then just use first unhidden socket */
-       for(sock= sockets->first; sock; sock= sock->next)
-               if(!nodeSocketIsHidden(sock))
-                       return sock;
-
-       /* OK, let's unhide proper one */
-       for(sock= sockets->first; sock; sock= sock->next) {
-               if(type == sock->type) {
-                       sock->flag &= ~(SOCK_HIDDEN|SOCK_AUTO_HIDDEN);
-                       return sock;
+       /* no visible sockets, unhide first of highest type */
+       for (type=maxtype; type >= 0; --type) {
+               for(sock= sockets->first; sock; sock= sock->next) {
+                       if(type==sock->type) {
+                               sock->flag &= ~(SOCK_HIDDEN|SOCK_AUTO_HIDDEN);
+                               return sock;
+                       }
                }
        }
        
-       /* just the first */
-       sock= sockets->first;
-       sock->flag &= ~(SOCK_HIDDEN|SOCK_AUTO_HIDDEN);
-       
-       return sockets->first;
+       return NULL;
 }
 
 /* prevent duplicate testing code below */
@@ -2783,10 +2784,10 @@
                sockto= link->tosock;
                
                link->tonode= select;
-               link->tosock= socket_best_match(&select->inputs, 
link->fromsock->type);
+               link->tosock= socket_best_match(&select->inputs);
                link->flag &= ~NODE_LINKFLAG_HILITE;
                
-               nodeAddLink(snode->edittree, select, 
socket_best_match(&select->outputs, sockto->type), node, sockto);
+               nodeAddLink(snode->edittree, select, 
socket_best_match(&select->outputs), node, sockto);
                ntreeUpdateTree(snode->edittree);       /* needed for pointers 
*/
                snode_update(snode, select);
                ED_node_changed_update(snode->id, select);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to