[Bf-blender-cvs] [36305cb27ad] temp_cryptomatte: Compositor: Cryptomatte node can now have inputs added and removed as necessary
Stefan Werner
noreply at git.blender.org
Fri Nov 3 21:09:55 CET 2017
Commit: 36305cb27ad3929a33fecf7c162b0fc9ef26d545
Author: Stefan Werner
Date: Tue Apr 18 20:24:33 2017 +0200
Branches: temp_cryptomatte
https://developer.blender.org/rB36305cb27ad3929a33fecf7c162b0fc9ef26d545
Compositor: Cryptomatte node can now have inputs added and removed as necessary
===================================================================
M source/blender/blenkernel/BKE_node.h
M source/blender/compositor/nodes/COM_CryptomatteNode.cpp
M source/blender/compositor/operations/COM_CryptomatteOperation.cpp
M source/blender/compositor/operations/COM_CryptomatteOperation.h
M source/blender/editors/space_node/drawnode.c
M source/blender/editors/space_node/node_edit.c
M source/blender/editors/space_node/node_intern.h
M source/blender/editors/space_node/node_ops.c
M source/blender/makesdna/DNA_node_types.h
M source/blender/nodes/composite/nodes/node_composite_cryptomatte.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 75356cd13e7..e4bd086bdaf 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -993,6 +993,8 @@ void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *ntree, bNode *node);
void ntreeCompositCryptomatteSyncFromAdd(bNodeTree *ntree, bNode *node);
void ntreeCompositCryptomatteSyncFromRemove(bNodeTree *ntree, bNode *node);
+struct bNodeSocket *ntreeCompositCryptomatteAddSocket(struct bNodeTree *ntree, struct bNode *node);
+int ntreeCompositCryptomatteRemoveSocket(struct bNodeTree *ntree, struct bNode *node);
/** \} */
diff --git a/source/blender/compositor/nodes/COM_CryptomatteNode.cpp b/source/blender/compositor/nodes/COM_CryptomatteNode.cpp
index 2b41c60c163..03e403ca29d 100644
--- a/source/blender/compositor/nodes/COM_CryptomatteNode.cpp
+++ b/source/blender/compositor/nodes/COM_CryptomatteNode.cpp
@@ -265,24 +265,24 @@ void CryptomatteNode::convertToOperations(NodeConverter &converter, const Compos
NodeOutput *outputSocketImage = this->getOutputSocket(0);
NodeOutput *outputSocketMatte = this->getOutputSocket(1);
NodeOutput *outputCryptoPick = this->getOutputSocket(2);
-
+
bNode *node = this->getbNode();
- CryptomatteOperation *operation = new CryptomatteOperation();
NodeCryptomatte *cryptoMatteSettings = (NodeCryptomatte *)node->storage;
- if(cryptoMatteSettings) {
+ CryptomatteOperation *operation = new CryptomatteOperation(cryptoMatteSettings->num_inputs);
+ if (cryptoMatteSettings) {
std::string input = cryptoMatteSettings->matte_id;
- if(!input.empty()) {
+ if (!input.empty()) {
// split the string by commas, ignoring white space
std::istringstream ss(input);
- while( ss.good() )
+ while (ss.good())
{
std::string token;
getline(ss, token, ',');
size_t first = token.find_first_not_of(' ');
size_t last = token.find_last_not_of(' ');
- token = token.substr(first, (last-first+1));
+ token = token.substr(first, (last - first + 1));
if (*token.begin() == '<' && *(--token.end()) == '>')
- operation->addObjectIndex(atof(token.substr(1, token.length()-2).c_str()));
+ operation->addObjectIndex(atof(token.substr(1, token.length() - 2).c_str()));
else {
uint32_t hash = 0;
MurmurHash3_x86_32(token.c_str(), token.length(), 0, &hash);
@@ -291,11 +291,12 @@ void CryptomatteNode::convertToOperations(NodeConverter &converter, const Compos
}
}
}
-
+
converter.addOperation(operation);
-
- for(int i = 0; i < 6; i++)
- converter.mapInputSocket(this->getInputSocket(i+1), operation->getInputSocket(i));
+
+ for (int i = 0; i < cryptoMatteSettings->num_inputs; i++) {
+ converter.mapInputSocket(this->getInputSocket(i + 1), operation->getInputSocket(i));
+ }
SeparateChannelOperation *separateOperation = new SeparateChannelOperation;
separateOperation->setChannel(3);
diff --git a/source/blender/compositor/operations/COM_CryptomatteOperation.cpp b/source/blender/compositor/operations/COM_CryptomatteOperation.cpp
index a6521e5bfdb..c27c56fdd0e 100644
--- a/source/blender/compositor/operations/COM_CryptomatteOperation.cpp
+++ b/source/blender/compositor/operations/COM_CryptomatteOperation.cpp
@@ -20,26 +20,28 @@
#include "COM_CryptomatteOperation.h"
-CryptomatteOperation::CryptomatteOperation() : NodeOperation()
+CryptomatteOperation::CryptomatteOperation(size_t num_inputs) : NodeOperation()
{
- for(int i = 0; i < 6; i++) {
- inputs[i] = NULL;
+ for(size_t i = 0; i < num_inputs; i++) {
this->addInputSocket(COM_DT_COLOR);
}
+ inputs.resize(num_inputs);
this->addOutputSocket(COM_DT_COLOR);
this->setComplex(true);
}
void CryptomatteOperation::initExecution()
{
- for(int i = 0; i < 6; i++)
+ for (size_t i = 0; i < inputs.size(); i++) {
inputs[i] = this->getInputSocketReader(i);
+ }
}
void CryptomatteOperation::addObjectIndex(float objectIndex)
{
- if(objectIndex != 0.f)
+ if (objectIndex != 0.f) {
m_objectIndex.push_back(objectIndex);
+ }
}
void CryptomatteOperation::executePixel(float output[4],
@@ -49,7 +51,7 @@ void CryptomatteOperation::executePixel(float output[4],
{
float input[4];
output[0] = output[1] = output[2] = output[3] = 0.0f;
- for(int i = 0; i < 6; i++) {
+ for (size_t i = 0; i < inputs.size(); i++) {
inputs[i]->read(input, x, y, data);
if (i == 0) {
// write the frontmost object as false color for picking
diff --git a/source/blender/compositor/operations/COM_CryptomatteOperation.h b/source/blender/compositor/operations/COM_CryptomatteOperation.h
index 6dc682902bc..65453b30961 100644
--- a/source/blender/compositor/operations/COM_CryptomatteOperation.h
+++ b/source/blender/compositor/operations/COM_CryptomatteOperation.h
@@ -27,9 +27,9 @@ class CryptomatteOperation : public NodeOperation {
private:
std::vector<float> m_objectIndex;
public:
- SocketReader *inputs[6];
+ std::vector<SocketReader *> inputs;
- CryptomatteOperation();
+ CryptomatteOperation(size_t num_inputs = 6);
void initExecution();
void executePixel(float output[4], int x, int y, void *data);
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 4feca3a2088..620ec573d52 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -2504,6 +2504,12 @@ static void node_composit_buts_cryptomatte(uiLayout *layout, bContext *UNUSED(C)
uiItemR(row, ptr, "remove", 0, NULL, ICON_NONE);
}
+static void node_composit_buts_cryptomatte_ex(uiLayout *layout, bContext *UNUSED(C), PointerRNA *UNUSED(ptr))
+{
+ uiItemO(layout, IFACE_("Add Input"), ICON_ZOOMIN, "NODE_OT_cryptomatte_add_socket");
+ uiItemO(layout, IFACE_("Remove Input"), ICON_ZOOMOUT, "NODE_OT_cryptomatte_remove_socket");
+}
+
static void node_composit_buts_brightcontrast(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiItemR(layout, ptr, "use_premultiply", 0, NULL, ICON_NONE);
@@ -2738,6 +2744,7 @@ static void node_composit_set_butfunc(bNodeType *ntype)
break;
case CMP_NODE_CRYPTOMATTE:
ntype->draw_buttons = node_composit_buts_cryptomatte;
+ ntype->draw_buttons_ex = node_composit_buts_cryptomatte_ex;
break;
case CMP_NODE_BRIGHTCONTRAST:
ntype->draw_buttons = node_composit_buts_brightcontrast;
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index 9dc39b1839b..c279ac77a73 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -2602,3 +2602,92 @@ void NODE_OT_clear_viewer_border(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
+
+/* ****************** Cryptomatte Add Socket ******************* */
+
+static int node_cryptomatte_add_socket_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene = CTX_data_scene(C);
+ SpaceNode *snode = CTX_wm_space_node(C);
+ PointerRNA ptr = CTX_data_pointer_get(C, "node");
+ bNodeTree *ntree = NULL;
+ bNode *node = NULL;
+ char file_path[MAX_NAME];
+
+ if (ptr.data) {
+ node = ptr.data;
+ ntree = ptr.id.data;
+ }
+ else if (snode && snode->edittree) {
+ ntree = snode->edittree;
+ node = nodeGetActive(snode->edittree);
+ }
+
+ if (!node || node->type != CMP_NODE_CRYPTOMATTE)
+ return OPERATOR_CANCELLED;
+
+ ntreeCompositCryptomatteAddSocket(ntree, node);
+
+ snode_notify(C, snode);
+
+ return OPERATOR_FINISHED;
+}
+
+void NODE_OT_cryptomatte_add_socket(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Add Cryptomatte Socket";
+ ot->description = "Add a new input to a cryptomatte node";
+ ot->idname = "NODE_OT_cryptomatte_add_socket";
+
+ /* callbacks */
+ ot->exec = node_cryptomatte_add_socket_exec;
+ ot->poll = composite_node_editable;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+/* ****************** Cryptomatte Remove Socket ******************* */
+
+static int node_cryptomatte_remove_socket_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ SpaceNode *snode = CTX_wm_space_node(C);
+ PointerRNA ptr = CTX_data_pointer_get(C, "node");
+ bNodeTree *ntree = NULL;
+ bNode *node = NULL;
+
+ if (ptr.data) {
+ node = ptr.data;
+ ntree = ptr.id.data;
+ }
+ else if (snode && snode->edittree) {
+ ntree = snode->edittree;
+ node = nodeGetActive(snode->edittree);
+ }
+
+ if (!node || node->type != CMP_NODE_CRYPTOMATTE)
+ return OPERATOR_CANCELLED;
+
+ if (!ntreeCompositCryptomatteRemoveSocket(ntree, node))
+ return OPERATOR_CANCELLED;
+
+ snode_notify(C, snode);
+
+ return OPERATOR_FINISHED;
+}
+
+void NODE_OT_cryptomatte_remove_socket(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Remove Cryptomatte Socket";
+ ot->description = "Remove input from a crytpomatte node";
+ ot->idname = "NODE_OT_cryptomatte_remove_socket";
+
+ /* callbacks */
+ ot->exec = node_cryptomatte_remove_socket_exec;
+ ot->poll = composite_node_editable;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index 6b8fa0b88fe..63a27f3026c 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -220,6 +220,9 @@ void NODE_OT_shader_script_update(struct wmOperatorType *ot);
void NODE_OT_viewer_border(struct wmOperatorType *ot);
void NODE_OT_clear_viewer_border(struct wmOperatorType *ot);
+void NODE_OT_cryptomatte_add_socket(struct wmOperatorType *ot);
+void NODE_OT_cryptomatte_remove_socket(struct wmOperatorType *ot);
+
extern const char *node_context_dir[];
// XXXXXX
diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c
index 5118d52efc4..66c56995b37 100644
--- a/source/blender/editors/space_node/node_ops.c
+++ b/source/blender/editors/space_node/node_ops.c
@@ -130,6 +130,9 @@ void node_operatortypes(void)
WM_operatortype_append(NODE_OT_tree_socket_add);
WM_operatortype_append(NODE_OT_tree_socket_remove);
WM_operatortype_append(NODE_OT_tree_socket_move);
+
+ WM_operatortype_append(NODE_OT_cryptomatte_add_socket);
+ WM_operatortype_append(NODE_OT_cryptomatte_remove_socke
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list