1
1

Compare commits

...

5 Commits

9 changed files with 276 additions and 0 deletions

View File

@@ -699,6 +699,44 @@ class NODE_PT_annotation(AnnotationDataPanel, Panel):
snode = context.space_data
return snode is not None and snode.node_tree is not None
class NODE_PT_asset_tools(Panel):
bl_label = "Asset Tools"
bl_space_type = 'NODE_EDITOR'
bl_region_type = 'UI'
bl_category = "Node"
@classmethod
def poll(cls, context):
snode = context.space_data
return snode.tree_type == 'GeometryNodeTree'
def draw(self, context):
layout = self.layout
snode = context.space_data
ntree = snode.node_tree
layout.operator("node.asset_tool_add", text="Add Asset Tool")
for asset_tool in ntree.asset_tools:
col = layout.column(align=True)
col.prop(asset_tool, "weight_group_name", text="")
col.prop(asset_tool, "default_weight", text="")
class NODE_OT_asset_tool_add(bpy.types.Operator):
bl_idname = "node.asset_tool_add"
bl_label = "Add Asset Tool"
bl_description = "Add asset tool"
@classmethod
def poll(cls, context):
snode = context.space_data
return snode.node_tree is not None
def execute(self, context):
ntree = context.space_data.node_tree
ntree.asset_tools.new()
return {'FINISHED'}
def node_draw_tree_view(_layout, _context):
pass
@@ -743,6 +781,8 @@ classes = (
NODE_PT_quality,
NODE_PT_annotation,
NODE_UL_interface_sockets,
NODE_PT_asset_tools,
NODE_OT_asset_tool_add,
node_panel(EEVEE_MATERIAL_PT_settings),
node_panel(MATERIAL_PT_viewport),

View File

@@ -7500,6 +7500,63 @@ class TOPBAR_PT_gpencil_vertexcolor(GreasePencilVertexcolorPanel, Panel):
return ob and ob.type == 'GPENCIL'
class VIEW3D_PT_asset_tools(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Assets"
bl_label = "Asset Tools"
def draw(self, context):
layout = self.layout
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
props.default_weight = asset_tool.default_weight
for socket in node_group.inputs[1:]:
layout.prop(modifier, f'["{socket.identifier}"]', text=socket.name)
class ASSET_OT_setup_weight_paint_tool(bpy.types.Operator):
bl_idname = "asset.setup_weight_paint_tool"
bl_label = "Setup weight paint tool"
bl_description = "Setup weight paint tool"
vertex_group_name: bpy.props.StringProperty()
default_weight: bpy.props.FloatProperty(default=1.0)
@classmethod
def poll(cls, context):
return context.active_object and context.active_object.type == 'MESH'
def execute(self, context):
ob = context.active_object
if ob.mode != 'WEIGHT_PAINT':
bpy.ops.object.mode_set(mode='WEIGHT_PAINT')
name = self.vertex_group_name
if not name in ob.vertex_groups:
group = ob.vertex_groups.new(name=name)
group.add(list(range(len(ob.data.vertices))), self.default_weight, 'REPLACE')
ob.vertex_groups.active = ob.vertex_groups[name]
return {'FINISHED'}
classes = (
VIEW3D_HT_header,
VIEW3D_HT_tool_header,
@@ -7730,6 +7787,8 @@ classes = (
TOPBAR_PT_gpencil_materials,
TOPBAR_PT_gpencil_vertexcolor,
TOPBAR_PT_annotation_layers,
VIEW3D_PT_asset_tools,
ASSET_OT_setup_weight_paint_tool,
)

View File

@@ -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

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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,15 @@ 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];
float default_weight;
char _pad[4];
} AssetTool;
/* socket value structs for input buttons
* DEPRECATED now using ID properties
*/

View File

@@ -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;

View File

@@ -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,45 @@ 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");
prop = RNA_def_property(srna, "default_weight", PROP_FLOAT, PROP_NONE);
RNA_def_property_ui_text(prop, "Default Weight", "");
RNA_def_property_ui_range(prop, 0.0, 1.0f, 0.1, 4);
}
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 asset tool");
parm = RNA_def_pointer(func, "asset_tool", "AssetTool", "", "New asset tool");
RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
RNA_def_function_return(func, parm);
func = RNA_def_function(srna, "remove", "rna_AssetToolGroup_remove");
RNA_def_function_ui_description(func, "Remove an asset tool");
parm = RNA_def_pointer(func, "asset_tool", "AssetTool", "", "Asset tool to remove");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
}
static void rna_def_nodetree(BlenderRNA *brna)
{
StructRNA *srna;
@@ -10988,6 +11047,12 @@ static void rna_def_nodetree(BlenderRNA *brna)
RNA_def_struct_refine_func(srna, "rna_NodeTree_refine");
RNA_def_struct_register_funcs(srna, "rna_NodeTree_register", "rna_NodeTree_unregister", NULL);
prop = RNA_def_property(srna, "asset_tools", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "asset_tools", NULL);
RNA_def_property_struct_type(prop, "AssetTool");
RNA_def_property_ui_text(prop, "Asset Tools", "Tools for this asset");
RNA_def_property_srna(prop, "AssetToolGroup");
prop = RNA_def_property(srna, "view_center", PROP_FLOAT, PROP_XYZ);
RNA_def_property_array(prop, 2);
RNA_def_property_float_sdna(prop, NULL, "view_center");
@@ -11300,6 +11365,9 @@ void RNA_def_nodetree(BlenderRNA *brna)
rna_def_nodetree(brna);
rna_def_asset_tool(brna);
rna_def_asset_tool_group(brna);
rna_def_node_socket_standard_types(brna);
rna_def_composite_nodetree(brna);