[Bf-blender-cvs] [969ad129f7b] temp-asset-tools-prototype: initial asset tools

Jacques Lucke noreply at git.blender.org
Tue Mar 16 12:38:06 CET 2021


Commit: 969ad129f7bae74a65a791f110bcbfdb7eb6cf06
Author: Jacques Lucke
Date:   Tue Mar 16 11:53:45 2021 +0100
Branches: temp-asset-tools-prototype
https://developer.blender.org/rB969ad129f7bae74a65a791f110bcbfdb7eb6cf06

initial asset tools

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

M	release/scripts/startup/bl_ui/space_view3d.py
A	source/blender/blenkernel/BKE_asset_tool.h
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/asset_tool.cc
M	source/blender/blenkernel/intern/node.cc
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_nodetree.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index f6898015339..6c1c25bea6c 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -7508,9 +7508,22 @@ class VIEW3D_PT_asset_tools(Panel):
 
     def draw(self, context):
         layout = self.layout
-        layout.label(text="Hello World")
-        props = layout.operator("asset.setup_weight_paint_tool", text="Create Weights")
-        props.vertex_group_name = "Hello"
+
+        ob = context.active_object
+        if ob is None:
+            return
+
+        for modifier in ob.modifiers:
+            if modifier.type != 'NODES':
+                continue
+            if modifier.node_group is None:
+                continue
+            node_group = modifier.node_group
+            for asset_tool in node_group.asset_tools:
+                group_name = asset_tool.weight_group_name
+                props = layout.operator("asset.setup_weight_paint_tool", text=group_name)
+                props.vertex_group_name = group_name
+
 
 class ASSET_OT_setup_weight_paint_tool(bpy.types.Operator):
     bl_idname = "asset.setup_weight_paint_tool"
diff --git a/source/blender/blenkernel/BKE_asset_tool.h b/source/blender/blenkernel/BKE_asset_tool.h
new file mode 100644
index 00000000000..8967881eae8
--- /dev/null
+++ b/source/blender/blenkernel/BKE_asset_tool.h
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+#pragma once
+
+/** \file
+ * \ingroup bke
+ */
+
+struct AssetTool;
+struct bNodeTree;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct AssetTool *BKE_asset_tool_new(void);
+struct AssetTool *BKE_asset_tool_copy(struct AssetTool *src);
+void BKE_asset_tool_free(struct AssetTool *asset_tool);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 310ac6c4903..e7c67ff5019 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -80,6 +80,7 @@ set(SRC
   intern/armature_pose.cc
   intern/armature_update.c
   intern/asset.cc
+  intern/asset_tool.cc
   intern/attribute.c
   intern/attribute_access.cc
   intern/attribute_math.cc
@@ -284,6 +285,7 @@ set(SRC
   BKE_appdir.h
   BKE_armature.h
   BKE_asset.h
+  BKE_asset_tool.h
   BKE_attribute.h
   BKE_attribute_access.hh
   BKE_attribute_math.hh
diff --git a/source/blender/blenkernel/intern/asset_tool.cc b/source/blender/blenkernel/intern/asset_tool.cc
new file mode 100644
index 00000000000..cc1fb11340a
--- /dev/null
+++ b/source/blender/blenkernel/intern/asset_tool.cc
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+/** \file
+ * \ingroup bke
+ */
+
+#include "BKE_asset_tool.h"
+
+#include "DNA_node_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+
+AssetTool *BKE_asset_tool_new()
+{
+  AssetTool *asset_tool = (AssetTool *)MEM_callocN(sizeof(AssetTool), __func__);
+  return asset_tool;
+}
+
+AssetTool *BKE_asset_tool_copy(AssetTool *src)
+{
+  AssetTool *asset_tool = (AssetTool *)MEM_dupallocN(src);
+  return asset_tool;
+}
+
+void BKE_asset_tool_free(AssetTool *asset_tool)
+{
+  MEM_freeN(asset_tool);
+}
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 66c0e724fdf..4d955aef3fb 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -60,6 +60,7 @@
 
 #include "BKE_anim_data.h"
 #include "BKE_animsys.h"
+#include "BKE_asset_tool.h"
 #include "BKE_colortools.h"
 #include "BKE_cryptomatte.h"
 #include "BKE_global.h"
@@ -221,6 +222,12 @@ static void ntree_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c
   /* Don't copy error messages in the runtime struct.
    * They should be filled during execution anyway. */
   ntree_dst->ui_storage = nullptr;
+
+  BLI_listbase_clear(&ntree_dst->asset_tools);
+  LISTBASE_FOREACH (AssetTool *, asset_tool_src, &ntree_src->asset_tools) {
+    AssetTool *asset_tool_dst = BKE_asset_tool_copy(asset_tool_src);
+    BLI_addtail(&ntree_dst->asset_tools, asset_tool_dst);
+  }
 }
 
 static void ntree_free_data(ID *id)
@@ -276,6 +283,10 @@ static void ntree_free_data(ID *id)
   }
 
   delete ntree->ui_storage;
+
+  LISTBASE_FOREACH_MUTABLE (AssetTool *, asset_tool, &ntree->asset_tools) {
+    BKE_asset_tool_free(asset_tool);
+  }
 }
 
 static void library_foreach_node_socket(LibraryForeachIDData *data, bNodeSocket *sock)
@@ -583,6 +594,8 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree)
   LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) {
     write_node_socket_interface(writer, sock);
   }
+
+  BLO_write_struct_list(writer, AssetTool, &ntree->asset_tools);
 }
 
 static void ntree_blend_write(BlendWriter *writer, ID *id, const void *id_address)
@@ -759,6 +772,8 @@ void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree)
     BLO_read_data_address(reader, &link->tosock);
   }
 
+  BLO_read_list(reader, &ntree->asset_tools);
+
   /* TODO, should be dealt by new generic cache handling of IDs... */
   ntree->previews = nullptr;
 
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 967258f1b81..ef8231c116b 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -473,6 +473,9 @@ typedef struct bNodeTree {
    */
   ListBase inputs, outputs;
 
+  /* List of #AssetTool. */
+  ListBase asset_tools;
+
   /* Node preview hash table
    * Only available in base node trees (e.g. scene->node_tree)
    */
@@ -537,6 +540,13 @@ typedef enum eNodeTreeUpdate {
   NTREE_UPDATE_GROUP = (NTREE_UPDATE_GROUP_IN | NTREE_UPDATE_GROUP_OUT),
 } eNodeTreeUpdate;
 
+typedef struct AssetTool {
+  struct AssetTool *next;
+  struct AssetTool *prev;
+
+  char weight_group_name[64];
+} AssetTool;
+
 /* socket value structs for input buttons
  * DEPRECATED now using ID properties
  */
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index a9125c78229..076cc97dd4d 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -73,6 +73,7 @@ extern StructRNA RNA_Attribute;
 extern StructRNA RNA_AttributeGroup;
 extern StructRNA RNA_AssetMetaData;
 extern StructRNA RNA_AssetTag;
+extern StructRNA RNA_AssetTool;
 extern StructRNA RNA_BackgroundImage;
 extern StructRNA RNA_BevelModifier;
 extern StructRNA RNA_BezierSplinePoint;
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 35c319c2f79..0418cf3e2c3 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "BLI_listbase.h"
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
@@ -37,6 +38,7 @@
 #include "DNA_texture_types.h"
 
 #include "BKE_animsys.h"
+#include "BKE_asset_tool.h"
 #include "BKE_attribute.h"
 #include "BKE_cryptomatte.h"
 #include "BKE_image.h"
@@ -4297,6 +4299,24 @@ static void rna_NodeInputString_string_set(PointerRNA *ptr, const char *value)
     storage->string = NULL;
   }
 }
+
+static PointerRNA rna_AssetToolGroup_new(bNodeTree *ntree)
+{
+  AssetTool *asset_tool = BKE_asset_tool_new();
+  BLI_addtail(&ntree->asset_tools, asset_tool);
+  PointerRNA ptr;
+  RNA_pointer_create(&ntree->id, &RNA_AssetTool, asset_tool, &ptr);
+  return ptr;
+}
+
+static void rna_AssetToolGroup_remove(bNodeTree *ntree, PointerRNA *asset_tool_ptr)
+{
+  AssetTool *asset_tool = (AssetTool *)asset_tool_ptr->data;
+  BLI_remlink(&ntree->asset_tools, asset_tool);
+  BKE_asset_tool_free(asset_tool);
+  RNA_POINTER_INVALIDATE(asset_tool_ptr);
+}
+
 #else
 
 static const EnumPropertyItem prop_image_layer_items[] = {
@@ -10963,6 +10983,41 @@ static void rna_def_node_tree_sockets_api(BlenderRNA *brna, PropertyRNA *cprop,
   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
 }
 
+static void rna_def_asset_tool(BlenderRNA *brna)
+{
+  StructRNA *srna;
+  PropertyRNA *prop;
+
+  srna = RNA_def_struct(brna, "AssetTool", NULL);
+  RNA_def_struct_ui_text(srna, "Asset Tool", "Tool for a specific asset");
+
+  prop = RNA_def_property(srna, "weight_group_name", PROP_STRING, PROP_NONE);
+  RNA_def_property_ui_text(prop, "Weight Group Name", "Name of a vertex group");
+}
+
+static void rna_def_asset_tool_group(BlenderRNA *brna)
+{
+  StructRNA *srna;
+  FunctionRNA *func;
+  PropertyRNA *parm;
+
+  srna = RNA_def_struct(brna, "AssetToolGroup", NULL);
+  RNA_def_struct_ui_text(srna, "Asset Tool Group", "Group of asset tools");
+  RNA_def_struct_sdna(srna, "bNodeTree");
+
+  func = RNA_def_function(srna, "new", "rna_AssetToolGroup_new");
+  RNA_def_function_ui_description(func, "Add an 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list