Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
| Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | static void cryptomatte_remove(NodeCryptomatte &n, float encoded_hash) | ||||
| CryptomatteEntry *entry = cryptomatte_find(n, encoded_hash); | CryptomatteEntry *entry = cryptomatte_find(n, encoded_hash); | ||||
| if (!entry) { | if (!entry) { | ||||
| return; | return; | ||||
| } | } | ||||
| BLI_remlink(&n.entries, entry); | BLI_remlink(&n.entries, entry); | ||||
| MEM_freeN(entry); | MEM_freeN(entry); | ||||
| } | } | ||||
| static bNodeSocketTemplate cmp_node_cryptomatte_in[] = { | |||||
| {SOCK_RGBA, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, {-1, ""}}; | |||||
| static bNodeSocketTemplate cmp_node_cryptomatte_out[] = { | |||||
| {SOCK_RGBA, N_("Image")}, | |||||
| {SOCK_FLOAT, N_("Matte")}, | |||||
| {SOCK_RGBA, N_("Pick")}, | |||||
| {-1, ""}, | |||||
| }; | |||||
| void ntreeCompositCryptomatteSyncFromAdd(const Scene *scene, bNode *node) | |||||
| { | |||||
| BLI_assert(ELEM(node->type, CMP_NODE_CRYPTOMATTE, CMP_NODE_CRYPTOMATTE_LEGACY)); | |||||
| NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage); | |||||
| if (n->runtime.add[0] != 0.0f) { | |||||
| cryptomatte_add(*scene, *node, *n, n->runtime.add[0]); | |||||
| zero_v3(n->runtime.add); | |||||
| } | |||||
| } | |||||
| void ntreeCompositCryptomatteSyncFromRemove(bNode *node) | void ntreeCompositCryptomatteSyncFromRemove(bNode *node) | ||||
| { | { | ||||
| BLI_assert(ELEM(node->type, CMP_NODE_CRYPTOMATTE, CMP_NODE_CRYPTOMATTE_LEGACY)); | BLI_assert(ELEM(node->type, CMP_NODE_CRYPTOMATTE, CMP_NODE_CRYPTOMATTE_LEGACY)); | ||||
| NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage); | NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage); | ||||
| if (n->runtime.remove[0] != 0.0f) { | if (n->runtime.remove[0] != 0.0f) { | ||||
| cryptomatte_remove(*n, n->runtime.remove[0]); | cryptomatte_remove(*n, n->runtime.remove[0]); | ||||
| zero_v3(n->runtime.remove); | zero_v3(n->runtime.remove); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | for (blender::StringRef layer_name : | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| const char *cstr = first_layer_name.c_str(); | const char *cstr = first_layer_name.c_str(); | ||||
| BLI_strncpy(r_prefix, cstr, prefix_len); | BLI_strncpy(r_prefix, cstr, prefix_len); | ||||
| } | } | ||||
| void ntreeCompositCryptomatteSyncFromAdd(const Scene *scene, bNode *node) | |||||
| { | |||||
| BLI_assert(ELEM(node->type, CMP_NODE_CRYPTOMATTE, CMP_NODE_CRYPTOMATTE_LEGACY)); | |||||
| NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage); | |||||
| if (n->runtime.add[0] != 0.0f) { | |||||
| cryptomatte_add(*scene, *node, *n, n->runtime.add[0]); | |||||
| zero_v3(n->runtime.add); | |||||
| } | |||||
| } | |||||
| CryptomatteSession *ntreeCompositCryptomatteSession(const Scene *scene, bNode *node) | CryptomatteSession *ntreeCompositCryptomatteSession(const Scene *scene, bNode *node) | ||||
| { | { | ||||
| blender::bke::cryptomatte::CryptomatteSessionPtr session_ptr = cryptomatte_init_from_node( | blender::bke::cryptomatte::CryptomatteSessionPtr session_ptr = cryptomatte_init_from_node( | ||||
| *scene, *node, true); | *scene, *node, true); | ||||
| return session_ptr.release(); | return session_ptr.release(); | ||||
| } | } | ||||
| namespace blender::nodes::node_composite_cryptomatte_cc { | |||||
| static bNodeSocketTemplate cmp_node_cryptomatte_in[] = { | |||||
| {SOCK_RGBA, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f}, {-1, ""}}; | |||||
| static bNodeSocketTemplate cmp_node_cryptomatte_out[] = { | |||||
| {SOCK_RGBA, N_("Image")}, | |||||
| {SOCK_FLOAT, N_("Matte")}, | |||||
| {SOCK_RGBA, N_("Pick")}, | |||||
| {-1, ""}, | |||||
| }; | |||||
| static void node_init_cryptomatte(bNodeTree *UNUSED(ntree), bNode *node) | static void node_init_cryptomatte(bNodeTree *UNUSED(ntree), bNode *node) | ||||
| { | { | ||||
| NodeCryptomatte *user = static_cast<NodeCryptomatte *>( | NodeCryptomatte *user = static_cast<NodeCryptomatte *>( | ||||
| MEM_callocN(sizeof(NodeCryptomatte), __func__)); | MEM_callocN(sizeof(NodeCryptomatte), __func__)); | ||||
| node->storage = user; | node->storage = user; | ||||
| } | } | ||||
| static void node_init_api_cryptomatte(const bContext *C, PointerRNA *ptr) | static void node_init_api_cryptomatte(const bContext *C, PointerRNA *ptr) | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | if (scene == nullptr) { | ||||
| "The node tree must be the compositing node tree of any scene in the file"); | "The node tree must be the compositing node tree of any scene in the file"); | ||||
| } | } | ||||
| return scene != nullptr; | return scene != nullptr; | ||||
| } | } | ||||
| *r_disabled_hint = TIP_("Not a compositor node tree"); | *r_disabled_hint = TIP_("Not a compositor node tree"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| } // namespace blender::nodes::node_composite_cryptomatte_cc | |||||
| void register_node_type_cmp_cryptomatte() | void register_node_type_cmp_cryptomatte() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_composite_cryptomatte_cc; | |||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| cmp_node_type_base(&ntype, CMP_NODE_CRYPTOMATTE, "Cryptomatte", NODE_CLASS_MATTE, 0); | cmp_node_type_base(&ntype, CMP_NODE_CRYPTOMATTE, "Cryptomatte", NODE_CLASS_MATTE, 0); | ||||
| node_type_socket_templates(&ntype, cmp_node_cryptomatte_in, cmp_node_cryptomatte_out); | node_type_socket_templates( | ||||
| &ntype, file_ns::cmp_node_cryptomatte_in, file_ns::cmp_node_cryptomatte_out); | |||||
| node_type_size(&ntype, 240, 100, 700); | node_type_size(&ntype, 240, 100, 700); | ||||
| node_type_init(&ntype, node_init_cryptomatte); | node_type_init(&ntype, file_ns::node_init_cryptomatte); | ||||
| ntype.initfunc_api = node_init_api_cryptomatte; | ntype.initfunc_api = file_ns::node_init_api_cryptomatte; | ||||
| ntype.poll = node_poll_cryptomatte; | ntype.poll = file_ns::node_poll_cryptomatte; | ||||
| node_type_storage(&ntype, "NodeCryptomatte", node_free_cryptomatte, node_copy_cryptomatte); | node_type_storage( | ||||
| &ntype, "NodeCryptomatte", file_ns::node_free_cryptomatte, file_ns::node_copy_cryptomatte); | |||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /** \name Cryptomatte Legacy | /** \name Cryptomatte Legacy | ||||
| * \{ */ | * \{ */ | ||||
| static void node_init_cryptomatte_legacy(bNodeTree *ntree, bNode *node) | |||||
| { | |||||
| node_init_cryptomatte(ntree, node); | |||||
| nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, "image", "Image"); | |||||
| /* Add three inputs by default, as recommended by the Cryptomatte specification. */ | |||||
| ntreeCompositCryptomatteAddSocket(ntree, node); | |||||
| ntreeCompositCryptomatteAddSocket(ntree, node); | |||||
| ntreeCompositCryptomatteAddSocket(ntree, node); | |||||
| } | |||||
| bNodeSocket *ntreeCompositCryptomatteAddSocket(bNodeTree *ntree, bNode *node) | bNodeSocket *ntreeCompositCryptomatteAddSocket(bNodeTree *ntree, bNode *node) | ||||
| { | { | ||||
| BLI_assert(node->type == CMP_NODE_CRYPTOMATTE_LEGACY); | BLI_assert(node->type == CMP_NODE_CRYPTOMATTE_LEGACY); | ||||
| NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage); | NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage); | ||||
| char sockname[32]; | char sockname[32]; | ||||
| n->num_inputs++; | n->num_inputs++; | ||||
| BLI_snprintf(sockname, sizeof(sockname), "Crypto %.2d", n->num_inputs - 1); | BLI_snprintf(sockname, sizeof(sockname), "Crypto %.2d", n->num_inputs - 1); | ||||
| Show All 10 Lines | if (n->num_inputs < 2) { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| bNodeSocket *sock = static_cast<bNodeSocket *>(node->inputs.last); | bNodeSocket *sock = static_cast<bNodeSocket *>(node->inputs.last); | ||||
| nodeRemoveSocket(ntree, node, sock); | nodeRemoveSocket(ntree, node, sock); | ||||
| n->num_inputs--; | n->num_inputs--; | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| namespace blender::nodes::node_composite_cryptomatte_legacy_cc { | |||||
| static void node_init_cryptomatte_legacy(bNodeTree *ntree, bNode *node) | |||||
| { | |||||
| namespace file_ns = blender::nodes::node_composite_cryptomatte_cc; | |||||
| file_ns::node_init_cryptomatte(ntree, node); | |||||
| nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, "image", "Image"); | |||||
| /* Add three inputs by default, as recommended by the Cryptomatte specification. */ | |||||
| ntreeCompositCryptomatteAddSocket(ntree, node); | |||||
| ntreeCompositCryptomatteAddSocket(ntree, node); | |||||
| ntreeCompositCryptomatteAddSocket(ntree, node); | |||||
| } | |||||
| } // namespace blender::nodes::node_composite_cryptomatte_legacy_cc | |||||
| void register_node_type_cmp_cryptomatte_legacy() | void register_node_type_cmp_cryptomatte_legacy() | ||||
| { | { | ||||
| namespace legacy_file_ns = blender::nodes::node_composite_cryptomatte_legacy_cc; | |||||
| namespace file_ns = blender::nodes::node_composite_cryptomatte_cc; | |||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| cmp_node_type_base(&ntype, CMP_NODE_CRYPTOMATTE_LEGACY, "Cryptomatte", NODE_CLASS_MATTE, 0); | cmp_node_type_base(&ntype, CMP_NODE_CRYPTOMATTE_LEGACY, "Cryptomatte", NODE_CLASS_MATTE, 0); | ||||
| node_type_socket_templates(&ntype, nullptr, cmp_node_cryptomatte_out); | node_type_socket_templates(&ntype, nullptr, file_ns::cmp_node_cryptomatte_out); | ||||
| node_type_init(&ntype, node_init_cryptomatte_legacy); | node_type_init(&ntype, legacy_file_ns::node_init_cryptomatte_legacy); | ||||
| node_type_storage(&ntype, "NodeCryptomatte", node_free_cryptomatte, node_copy_cryptomatte); | node_type_storage( | ||||
| &ntype, "NodeCryptomatte", file_ns::node_free_cryptomatte, file_ns::node_copy_cryptomatte); | |||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| } | } | ||||