[Bf-blender-cvs] [1febae0398e] compositor-cryptomatte-workflow: Merge branch 'master' into compositor-cryptomatte-workflow

Jeroen Bakker noreply at git.blender.org
Wed Mar 3 13:37:21 CET 2021


Commit: 1febae0398e73a249739e3cabd970dbbbb4f6ff9
Author: Jeroen Bakker
Date:   Wed Mar 3 12:49:17 2021 +0100
Branches: compositor-cryptomatte-workflow
https://developer.blender.org/rB1febae0398e73a249739e3cabd970dbbbb4f6ff9

Merge branch 'master' into compositor-cryptomatte-workflow

===================================================================



===================================================================

diff --cc source/blender/blenkernel/intern/cryptomatte.cc
index b1f22db6ba2,9d9cace3a35..e375b9b2eb4
--- a/source/blender/blenkernel/intern/cryptomatte.cc
+++ b/source/blender/blenkernel/intern/cryptomatte.cc
@@@ -182,25 -182,11 +182,27 @@@ float BKE_cryptomatte_hash_to_float(uin
    return blender::bke::cryptomatte::CryptomatteHash(cryptomatte_hash).float_encoded();
  }
  
 +/* Find an ID in the given main that matches the given encoded float. */
 +bool BKE_cryptomatte_find_name(const Main *bmain,
 +                               const float encoded_hash,
 +                               char *r_name,
 +                               int name_len)
 +{
 +  CryptomatteSession session(bmain);
 +  std::optional<std::string> name = session[encoded_hash];
 +  if (!name) {
 +    return false;
 +  }
 +
 +  BLI_strncpy(r_name, name->c_str(), name_len);
 +  return true;
 +}
 +
  char *BKE_cryptomatte_entries_to_matte_id(NodeCryptomatte *node_storage)
  {
-   DynStr *matte_id = BLI_dynstr_new();
+   std::stringstream ss;
+   ss.precision(9);
+ 
    bool first = true;
    LISTBASE_FOREACH (CryptomatteEntry *, entry, &node_storage->entries) {
      if (!first) {
diff --cc source/blender/editors/space_node/node_intern.h
index 98949916bb4,4ec8f56480e..6fbedf7f453
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@@ -286,6 -291,15 +291,12 @@@ void NODE_GGT_backdrop_crop(struct wmGi
  void NODE_GGT_backdrop_sun_beams(struct wmGizmoGroupType *gzgt);
  void NODE_GGT_backdrop_corner_pin(struct wmGizmoGroupType *gzgt);
  
 -void NODE_OT_cryptomatte_layer_add(struct wmOperatorType *ot);
 -void NODE_OT_cryptomatte_layer_remove(struct wmOperatorType *ot);
 -
+ /* node_geometry_attribute_search.cc */
+ void node_geometry_add_attribute_search_button(const struct bNodeTree *node_tree,
+                                                const struct bNode *node,
+                                                struct PointerRNA *socket_ptr,
+                                                struct uiLayout *layout);
+ 
  extern const char *node_context_dir[];
  
  /* XXXXXX */
diff --cc source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
index 852ef165195,d25bbb4c240..1a3338b1476
--- a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
@@@ -27,114 -25,104 +27,119 @@@
  #include "BLI_dynstr.h"
  #include "BLI_hash_mm3.h"
  #include "BLI_utildefines.h"
 -#include "node_composite_util.h"
 +
 +#include "BKE_context.h"
 +#include "BKE_cryptomatte.h"
 +#include "BKE_global.h"
 +#include "BKE_lib_id.h"
 +#include "BKE_library.h"
 +#include "BKE_main.h"
  
- static CryptomatteEntry *cryptomatte_find(NodeCryptomatte *n, float encoded_hash)
+ #include <optional>
+ 
+ extern "C" {
+ static std::optional<CryptomatteEntry *> cryptomatte_find(const NodeCryptomatte &n,
+                                                           float encoded_hash)
  {
-   LISTBASE_FOREACH (CryptomatteEntry *, entry, &n->entries) {
+   LISTBASE_FOREACH (CryptomatteEntry *, entry, &n.entries) {
      if (entry->encoded_hash == encoded_hash) {
-       return entry;
+       return std::make_optional(entry);
      }
    }
-   return NULL;
+   return std::nullopt;
  }
  
- static void cryptomatte_add(Main *bmain, NodeCryptomatte *n, float encoded_hash)
 -static void cryptomatte_add(NodeCryptomatte &n, float f)
++static void cryptomatte_add(Main *bmain, NodeCryptomatte &n, float encoded_hash)
  {
    /* Check if entry already exist. */
-   if (cryptomatte_find(n, encoded_hash) != NULL) {
 -  if (cryptomatte_find(n, f)) {
++  if (cryptomatte_find(n, encoded_hash)) {
      return;
    }
 +
-   CryptomatteEntry *entry = MEM_callocN(sizeof(CryptomatteEntry), __func__);
+   CryptomatteEntry *entry = static_cast<CryptomatteEntry *>(
+       MEM_callocN(sizeof(CryptomatteEntry), __func__));
 -  entry->encoded_hash = f;
 +  entry->encoded_hash = encoded_hash;
 +  BKE_cryptomatte_find_name(bmain, encoded_hash, entry->name, sizeof(entry->name));
 +
-   BLI_addtail(&n->entries, entry);
+   BLI_addtail(&n.entries, entry);
  }
  
- static void cryptomatte_remove(NodeCryptomatte *n, float encoded_hash)
 -static void cryptomatte_remove(NodeCryptomatte &n, float f)
++static void cryptomatte_remove(NodeCryptomatte &n, float encoded_hash)
  {
-   CryptomatteEntry *entry = cryptomatte_find(n, encoded_hash);
-   if (entry == NULL) {
 -  std::optional<CryptomatteEntry *> entry = cryptomatte_find(n, f);
++  std::optional<CryptomatteEntry *> entry = cryptomatte_find(n, encoded_hash);
+   if (!entry) {
      return;
    }
- 
-   BLI_remlink(&n->entries, entry);
-   MEM_freeN(entry);
+   BLI_remlink(&n.entries, entry.value());
+   MEM_freeN(entry.value());
  }
  
 -static bNodeSocketTemplate outputs[] = {
 +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(bNodeTree *UNUSED(ntree), bNode *node)
 +void ntreeCompositCryptomatteSyncFromAdd(Main *bmain, bNodeTree *UNUSED(ntree), bNode *node)
  {
-   NodeCryptomatte *n = node->storage;
+   NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage);
    if (n->add[0] != 0.0f) {
-     cryptomatte_add(bmain, n, n->add[0]);
 -    cryptomatte_add(*n, n->add[0]);
++    cryptomatte_add(bmain, *n, n->add[0]);
      zero_v3(n->add);
    }
  }
  
 -void ntreeCompositCryptomatteSyncFromRemove(bNodeTree *UNUSED(ntree), bNode *node)
 +void ntreeCompositCryptomatteSyncFromRemove(Main *UNUSED(bmain),
 +                                            bNodeTree *UNUSED(ntree),
 +                                            bNode *node)
  {
-   NodeCryptomatte *n = node->storage;
+   NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage);
    if (n->remove[0] != 0.0f) {
-     cryptomatte_remove(n, n->remove[0]);
+     cryptomatte_remove(*n, n->remove[0]);
      zero_v3(n->remove);
    }
  }
  
 -bNodeSocket *ntreeCompositCryptomatteAddSocket(bNodeTree *ntree, bNode *node)
 -{
 -  NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage);
 -  char sockname[32];
 -  n->num_inputs++;
 -  BLI_snprintf(sockname, sizeof(sockname), "Crypto %.2d", n->num_inputs - 1);
 -  bNodeSocket *sock = nodeAddStaticSocket(
 -      ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, nullptr, sockname);
 -  return sock;
 -}
 +const char *CRYPTOMATTE_LAYER_PREFIX_OBJECT = "CryptoObject";
 +const char *CRYPTOMATTE_LAYER_PREFIX_MATERIAL = "CryptoMaterial";
 +const char *CRYPTOMATTE_LAYER_PREFIX_ASSET = "CryptoAsset";
 +const char *CRYPTOMATTE_LAYER_PREFIX_UNKNOWN = "";
  
 -int ntreeCompositCryptomatteRemoveSocket(bNodeTree *ntree, bNode *node)
 +const char *ntreeCompositCryptomatteLayerPrefix(const bNode *node)
  {
 -  NodeCryptomatte *n = static_cast<NodeCryptomatte *>(node->storage);
 -  if (n->num_inputs < 2) {
 -    return 0;
 +  NodeCryptomatte *cryptoMatteSettings = (NodeCryptomatte *)node->storage;
 +
 +  switch (cryptoMatteSettings->type) {
 +    case CMP_CRYPTOMATTE_TYPE_OBJECT:
 +      return CRYPTOMATTE_LAYER_PREFIX_OBJECT;
 +
 +    case CMP_CRYPTOMATTE_TYPE_MATERIAL:
 +      return CRYPTOMATTE_LAYER_PREFIX_MATERIAL;
 +
 +    case CMP_CRYPTOMATTE_TYPE_ASSET:
 +      return CRYPTOMATTE_LAYER_PREFIX_ASSET;
    }
 -  bNodeSocket *sock = static_cast<bNodeSocket *>(node->inputs.last);
 -  nodeRemoveSocket(ntree, node, sock);
 -  n->num_inputs--;
 -  return 1;
 +  BLI_assert(false && "Invalid Cryptomatte layer.");
 +  return CRYPTOMATTE_LAYER_PREFIX_UNKNOWN;
  }
  
 -static void init(bNodeTree *ntree, bNode *node)
 +static void node_init_cryptomatte(bNodeTree *UNUSED(ntree), bNode *node)
  {
-   NodeCryptomatte *user = MEM_callocN(sizeof(NodeCryptomatte), "cryptomatte user");
+   NodeCryptomatte *user = static_cast<NodeCryptomatte *>(
+       MEM_callocN(sizeof(NodeCryptomatte), __func__));
    node->storage = user;
 +}
  
 -  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);
 +static void node_init_api_cryptomatte(const bContext *C, PointerRNA *ptr)
 +{
 +  Scene *scene = CTX_data_scene(C);
-   bNode *node = ptr->data;
++  bNode *node = static_cast<bNode *>(ptr->data);
 +  node->id = &scene->id;
 +  id_us_plus(node->id);
  }
  
  static void node_free_cryptomatte(bNode *node)
@@@ -157,21 -146,6 +163,22 @@@ static void node_copy_cryptomatte(bNode
    dest_node->storage = dest_nc;
  }
  
 +static bool node_poll_cryptomatte(bNodeType *UNUSED(ntype), bNodeTree *ntree)
 +{
 +  if (STREQ(ntree->idname, "CompositorNodeTree")) {
 +    Scene *scene;
 +
 +    /* See node_composit_poll_rlayers. */
-     for (scene = G.main->scenes.first; scene; scene = scene->id.next)
++    for (scene = static_cast<Scene *>(G.main->scenes.first); scene;
++         scene = static_cast<Scene *>(scene->id.next))
 +      if (scene->nodetree == ntree)
 +        break;
 +
 +    return (scene != NULL);
 +  }
 +  return false;
 +}
 +
  void register_node_type_cmp_cryptomatte(void)
  {
    static bNodeType ntype;



More information about the Bf-blender-cvs mailing list