
PyNodes opens up the node system in Blender to scripters and adds a number of UI-level improvements. === Dynamic node type registration === Node types can now be added at runtime, using the RNA registration mechanism from python. This enables addons such as render engines to create a complete user interface with nodes. Examples of how such nodes can be defined can be found in my personal wiki docs atm [1] and as a script template in release/scripts/templates_py/custom_nodes.py [2]. === Node group improvements === Each node editor now has a tree history of edited node groups, which allows opening and editing nested node groups. The node editor also supports pinning now, so that different spaces can be used to edit different node groups simultaneously. For more ramblings and rationale see (really old) blog post on code.blender.org [3]. The interface of node groups has been overhauled. Sockets of a node group are no longer displayed in columns on either side, but instead special input/output nodes are used to mirror group sockets inside a node tree. This solves the problem of long node lines in groups and allows more adaptable node layout. Internal sockets can be exposed from a group by either connecting to the extension sockets in input/output nodes (shown as empty circle) or by adding sockets from the node property bar in the "Interface" panel. Further details such as the socket name can also be changed there. [1] http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes [2] http://projects.blender.org/scm/viewvc.php/trunk/blender/release/scripts/templates_py/custom_nodes.py?view=markup&root=bf-blender [3] http://code.blender.org/index.php/2012/01/improving-node-group-interface-editing/
160 lines
4.4 KiB
C++
160 lines
4.4 KiB
C++
/*
|
|
* Copyright 2011, Blender Foundation.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
* Contributor:
|
|
* Jeroen Bakker
|
|
* Monique Dewanchand
|
|
*/
|
|
|
|
#include "COM_Socket.h"
|
|
#include "COM_Node.h"
|
|
#include "COM_SocketConnection.h"
|
|
#include "COM_ExecutionSystem.h"
|
|
|
|
InputSocket::InputSocket(DataType datatype) : Socket(datatype)
|
|
{
|
|
this->m_connection = NULL;
|
|
this->m_resizeMode = COM_SC_CENTER;
|
|
}
|
|
InputSocket::InputSocket(DataType datatype, InputSocketResizeMode resizeMode) : Socket(datatype)
|
|
{
|
|
this->m_connection = NULL;
|
|
this->m_resizeMode = resizeMode;
|
|
}
|
|
|
|
InputSocket::InputSocket(InputSocket *from) : Socket(from->getDataType())
|
|
{
|
|
this->m_connection = NULL;
|
|
this->m_resizeMode = from->getResizeMode();
|
|
}
|
|
|
|
int InputSocket::isInputSocket() const { return true; }
|
|
const int InputSocket::isConnected() const { return this->m_connection != NULL; }
|
|
|
|
void InputSocket::setConnection(SocketConnection *connection)
|
|
{
|
|
this->m_connection = connection;
|
|
}
|
|
SocketConnection *InputSocket::getConnection()
|
|
{
|
|
return this->m_connection;
|
|
}
|
|
|
|
void InputSocket::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
|
|
{
|
|
if (this->isConnected()) {
|
|
this->m_connection->getFromSocket()->determineResolution(resolution, preferredResolution);
|
|
}
|
|
else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
void InputSocket::relinkConnections(InputSocket *relinkToSocket)
|
|
{
|
|
if (!isConnected()) {
|
|
return;
|
|
}
|
|
SocketConnection *connection = this->getConnection();
|
|
connection->setToSocket(relinkToSocket);
|
|
relinkToSocket->setConnection(connection);
|
|
this->setConnection(NULL);
|
|
}
|
|
|
|
void InputSocket::relinkConnectionsDuplicate(InputSocket *relinkToSocket, int editorNodeInputSocketIndex, ExecutionSystem *graph)
|
|
{
|
|
if (!this->isConnected()) {
|
|
Node *node = (Node *)this->getNode();
|
|
switch (this->getDataType()) {
|
|
case COM_DT_COLOR:
|
|
node->addSetColorOperation(graph, relinkToSocket, editorNodeInputSocketIndex);
|
|
break;
|
|
case COM_DT_VECTOR:
|
|
node->addSetVectorOperation(graph, relinkToSocket, editorNodeInputSocketIndex);
|
|
break;
|
|
case COM_DT_VALUE:
|
|
node->addSetValueOperation(graph, relinkToSocket, editorNodeInputSocketIndex);
|
|
break;
|
|
}
|
|
return;
|
|
}
|
|
SocketConnection *newConnection = new SocketConnection();
|
|
OutputSocket *fromSocket = this->getConnection()->getFromSocket();
|
|
newConnection->setToSocket(relinkToSocket);
|
|
newConnection->setFromSocket(fromSocket);
|
|
relinkToSocket->setConnection(newConnection);
|
|
fromSocket->addConnection(newConnection);
|
|
graph->addSocketConnection(newConnection);
|
|
}
|
|
|
|
void InputSocket::relinkConnections(InputSocket *relinkToSocket, int editorNodeInputSocketIndex, ExecutionSystem *graph)
|
|
{
|
|
if (isConnected()) {
|
|
relinkConnections(relinkToSocket);
|
|
}
|
|
else {
|
|
Node *node = (Node *)this->getNode();
|
|
switch (this->getDataType()) {
|
|
case COM_DT_COLOR:
|
|
node->addSetColorOperation(graph, relinkToSocket, editorNodeInputSocketIndex);
|
|
break;
|
|
case COM_DT_VECTOR:
|
|
node->addSetVectorOperation(graph, relinkToSocket, editorNodeInputSocketIndex);
|
|
break;
|
|
case COM_DT_VALUE:
|
|
node->addSetValueOperation(graph, relinkToSocket, editorNodeInputSocketIndex);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void InputSocket::unlinkConnections(ExecutionSystem *system)
|
|
{
|
|
SocketConnection *connection = getConnection();
|
|
if (connection) {
|
|
system->removeSocketConnection(connection);
|
|
connection->getFromSocket()->removeConnection(connection);
|
|
setConnection(NULL);
|
|
delete connection;
|
|
}
|
|
}
|
|
|
|
bool InputSocket::isStatic()
|
|
{
|
|
if (isConnected()) {
|
|
NodeBase *node = this->getConnection()->getFromNode();
|
|
if (node) {
|
|
return node->isStatic();
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
SocketReader *InputSocket::getReader()
|
|
{
|
|
return this->getOperation();
|
|
}
|
|
|
|
NodeOperation *InputSocket::getOperation() const
|
|
{
|
|
if (isConnected()) {
|
|
return (NodeOperation *)this->m_connection->getFromSocket()->getNode();
|
|
}
|
|
else {
|
|
return NULL;
|
|
}
|
|
}
|