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>2013-03-18 20:34:57 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2013-03-18 20:34:57 +0400
commit4638e5f99a9ba59ad0b8a1fd52b12e876480b9e8 (patch)
tree2444f12b4612440f44cf02835cdf5951b6564e92 /intern/cycles/blender/blender_python.cpp
parent7bfef29f2f2a1b262d28abdc6e30fcd9c1f1caad (diff)
Merge of the PyNodes branch (aka "custom nodes") into trunk.
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/
Diffstat (limited to 'intern/cycles/blender/blender_python.cpp')
-rw-r--r--intern/cycles/blender/blender_python.cpp93
1 files changed, 57 insertions, 36 deletions
diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp
index a10f3b63033..f7a05463f66 100644
--- a/intern/cycles/blender/blender_python.cpp
+++ b/intern/cycles/blender/blender_python.cpp
@@ -207,6 +207,7 @@ static PyObject *available_devices_func(PyObject *self, PyObject *args)
}
#ifdef WITH_OSL
+
static PyObject *osl_update_node_func(PyObject *self, PyObject *args)
{
PyObject *pynodegroup, *pynode;
@@ -248,17 +249,19 @@ static PyObject *osl_update_node_func(PyObject *self, PyObject *args)
continue;
/* determine socket type */
- BL::NodeSocket::type_enum socket_type;
- float default_float4[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+ std::string socket_type;
+ BL::NodeSocket::type_enum data_type = BL::NodeSocket::type_VALUE;
+ float4 default_float4 = make_float4(0.0f, 0.0f, 0.0f, 1.0f);
float default_float = 0.0f;
int default_int = 0;
std::string default_string = "";
if(param->isclosure) {
- socket_type = BL::NodeSocket::type_SHADER;
+ socket_type = "NodeSocketShader";
}
else if(param->type.vecsemantics == TypeDesc::COLOR) {
- socket_type = BL::NodeSocket::type_RGBA;
+ socket_type = "NodeSocketColor";
+ data_type = BL::NodeSocket::type_RGBA;
if(param->validdefault) {
default_float4[0] = param->fdefault[0];
@@ -269,7 +272,8 @@ static PyObject *osl_update_node_func(PyObject *self, PyObject *args)
else if(param->type.vecsemantics == TypeDesc::POINT ||
param->type.vecsemantics == TypeDesc::VECTOR ||
param->type.vecsemantics == TypeDesc::NORMAL) {
- socket_type = BL::NodeSocket::type_VECTOR;
+ socket_type = "NodeSocketVector";
+ data_type = BL::NodeSocket::type_VECTOR;
if(param->validdefault) {
default_float4[0] = param->fdefault[0];
@@ -279,17 +283,20 @@ static PyObject *osl_update_node_func(PyObject *self, PyObject *args)
}
else if(param->type.aggregate == TypeDesc::SCALAR) {
if(param->type.basetype == TypeDesc::INT) {
- socket_type = BL::NodeSocket::type_INT;
+ socket_type = "NodeSocketInt";
+ data_type = BL::NodeSocket::type_INT;
if(param->validdefault)
default_int = param->idefault[0];
}
else if(param->type.basetype == TypeDesc::FLOAT) {
- socket_type = BL::NodeSocket::type_VALUE;
+ socket_type = "NodeSocketFloat";
+ data_type = BL::NodeSocket::type_VALUE;
if(param->validdefault)
default_float = param->fdefault[0];
}
else if(param->type.basetype == TypeDesc::STRING) {
- socket_type = BL::NodeSocket::type_STRING;
+ socket_type = "NodeSocketString";
+ data_type = BL::NodeSocket::type_STRING;
if(param->validdefault)
default_string = param->sdefault[0];
}
@@ -300,38 +307,52 @@ static PyObject *osl_update_node_func(PyObject *self, PyObject *args)
continue;
/* find socket socket */
- BL::NodeSocket b_sock = b_node.find_socket(param->name.c_str(), param->isoutput);
-
- /* remove if type no longer matches */
- if(b_sock && b_sock.type() != socket_type) {
- b_node.remove_socket(b_sock);
- b_sock = BL::NodeSocket(PointerRNA_NULL);
+ BL::NodeSocket b_sock(PointerRNA_NULL);
+ if (param->isoutput) {
+ b_sock = b_node.outputs[param->name];
+
+ /* remove if type no longer matches */
+ if(b_sock && b_sock.bl_idname() != socket_type) {
+ b_node.outputs.remove(b_sock);
+ b_sock = BL::NodeSocket(PointerRNA_NULL);
+ }
+
+ if (!b_sock) {
+ /* create new socket */
+ b_sock = b_node.outputs.create(socket_type.c_str(), param->name.c_str(), param->name.c_str());
+ }
+ }
+ else {
+ b_sock = b_node.inputs[param->name];
+
+ /* remove if type no longer matches */
+ if(b_sock && b_sock.bl_idname() != socket_type) {
+ b_node.inputs.remove(b_sock);
+ b_sock = BL::NodeSocket(PointerRNA_NULL);
+ }
+
+ if (!b_sock) {
+ /* create new socket */
+ b_sock = b_node.inputs.create(socket_type.c_str(), param->name.c_str(), param->name.c_str());
+ }
}
- /* create new socket */
- if(!b_sock) {
- b_sock = b_node.add_socket(param->name.c_str(), socket_type, param->isoutput);
-
- /* set default value */
- if(socket_type == BL::NodeSocket::type_VALUE) {
- BL::NodeSocketFloatNone b_float_sock(b_sock.ptr);
- b_float_sock.default_value(default_float);
+ /* set default value */
+ if(b_sock) {
+ if(data_type == BL::NodeSocket::type_VALUE) {
+ set_float(b_sock.ptr, "default_value", default_float);
}
- else if(socket_type == BL::NodeSocket::type_INT) {
- BL::NodeSocketIntNone b_int_sock(b_sock.ptr);
- b_int_sock.default_value(default_int);
+ else if(data_type == BL::NodeSocket::type_INT) {
+ set_int(b_sock.ptr, "default_value", default_int);
}
- else if(socket_type == BL::NodeSocket::type_RGBA) {
- BL::NodeSocketRGBA b_rgba_sock(b_sock.ptr);
- b_rgba_sock.default_value(default_float4);
+ else if(data_type == BL::NodeSocket::type_RGBA) {
+ set_float4(b_sock.ptr, "default_value", default_float4);
}
- else if(socket_type == BL::NodeSocket::type_VECTOR) {
- BL::NodeSocketVectorNone b_vector_sock(b_sock.ptr);
- b_vector_sock.default_value(default_float4);
+ else if(data_type == BL::NodeSocket::type_VECTOR) {
+ set_float3(b_sock.ptr, "default_value", float4_to_float3(default_float4));
}
- else if(socket_type == BL::NodeSocket::type_STRING) {
- BL::NodeSocketStringNone b_string_sock(b_sock.ptr);
- b_string_sock.default_value(default_string);
+ else if(data_type == BL::NodeSocket::type_STRING) {
+ set_string(b_sock.ptr, "default_value", default_string);
}
}
@@ -349,7 +370,7 @@ static PyObject *osl_update_node_func(PyObject *self, PyObject *args)
for (b_node.inputs.begin(b_input); b_input != b_node.inputs.end(); ++b_input) {
if(used_sockets.find(b_input->ptr.data) == used_sockets.end()) {
- b_node.remove_socket(*b_input);
+ b_node.inputs.remove(*b_input);
removed = true;
break;
}
@@ -357,7 +378,7 @@ static PyObject *osl_update_node_func(PyObject *self, PyObject *args)
for (b_node.outputs.begin(b_output); b_output != b_node.outputs.end(); ++b_output) {
if(used_sockets.find(b_output->ptr.data) == used_sockets.end()) {
- b_node.remove_socket(*b_output);
+ b_node.outputs.remove(*b_output);
removed = true;
break;
}