Geometry Nodes: Fix Support for extending nested menus with assets
The builtin asset catalog paths weren't properly updated after more nesting was added to the geometry nodes add menu. This commit resolves that and a few other issues extending menus like nested menus in mesh edit mode. Unfortunately this requires some boilerplate code duplicating the menu structure currently.
This commit is contained in:
@@ -42,7 +42,7 @@ class NODE_MT_geometry_node_GEO_COLOR(Menu):
|
||||
ops.name = "data_type"
|
||||
ops.value = "'RGBA'"
|
||||
node_add_menu.add_node_type(layout, "FunctionNodeSeparateColor")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Utilties/Color")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_CURVE(Menu):
|
||||
@@ -77,7 +77,7 @@ class NODE_MT_geometry_node_GEO_CURVE_READ(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSplineLength")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSplineParameter")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeInputSplineResolution")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Curve/Read")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_CURVE_SAMPLE(Menu):
|
||||
@@ -87,7 +87,7 @@ class NODE_MT_geometry_node_GEO_CURVE_SAMPLE(Menu):
|
||||
def draw(self, _context):
|
||||
layout = self.layout
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSampleCurve")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Curve/Sample")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_CURVE_WRITE(Menu):
|
||||
@@ -104,7 +104,7 @@ class NODE_MT_geometry_node_GEO_CURVE_WRITE(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSetSplineCyclic")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSetSplineResolution")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeCurveSplineType")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Curve/Write")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_CURVE_OPERATIONS(Menu):
|
||||
@@ -123,7 +123,7 @@ class NODE_MT_geometry_node_GEO_CURVE_OPERATIONS(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeReverseCurve")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSubdivideCurve")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeTrimCurve")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Curve/Operations")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_PRIMITIVES_CURVE(Menu):
|
||||
@@ -140,7 +140,7 @@ class NODE_MT_geometry_node_GEO_PRIMITIVES_CURVE(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeCurveQuadraticBezier")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeCurvePrimitiveQuadrilateral")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeCurveStar")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Curve/Primitives")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_curve_topology(Menu):
|
||||
@@ -152,7 +152,7 @@ class NODE_MT_geometry_node_curve_topology(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeCurveOfPoint")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeOffsetPointInCurve")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodePointsOfCurve")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Curve/Topology")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_GEOMETRY(Menu):
|
||||
@@ -186,7 +186,7 @@ class NODE_MT_geometry_node_GEO_GEOMETRY_READ(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeInputRadius")
|
||||
if context.space_data.geometry_nodes_type == 'TOOL':
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeToolSelection")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Geometry/Read")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_GEOMETRY_WRITE(Menu):
|
||||
@@ -199,7 +199,7 @@ class NODE_MT_geometry_node_GEO_GEOMETRY_WRITE(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSetPosition")
|
||||
if context.space_data.geometry_nodes_type == 'TOOL':
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeToolSetSelection")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Geometry/Write")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_GEOMETRY_OPERATIONS(Menu):
|
||||
@@ -217,7 +217,7 @@ class NODE_MT_geometry_node_GEO_GEOMETRY_OPERATIONS(Menu):
|
||||
layout.separator()
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSeparateComponents")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSeparateGeometry")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Geometry/Operations")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_GEOMETRY_SAMPLE(Menu):
|
||||
@@ -231,7 +231,7 @@ class NODE_MT_geometry_node_GEO_GEOMETRY_SAMPLE(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeRaycast")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSampleIndex")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSampleNearest")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Geometry/Sample")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_INPUT(Menu):
|
||||
@@ -261,7 +261,7 @@ class NODE_MT_geometry_node_GEO_INPUT_CONSTANT(Menu):
|
||||
node_add_menu.add_node_type(layout, "FunctionNodeInputString")
|
||||
node_add_menu.add_node_type(layout, "ShaderNodeValue")
|
||||
node_add_menu.add_node_type(layout, "FunctionNodeInputVector")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Input/Constant")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_INPUT_GROUP(Menu):
|
||||
@@ -271,7 +271,7 @@ class NODE_MT_geometry_node_GEO_INPUT_GROUP(Menu):
|
||||
def draw(self, _context):
|
||||
layout = self.layout
|
||||
node_add_menu.add_node_type(layout, "NodeGroupInput")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Input/Group")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_INPUT_SCENE(Menu):
|
||||
@@ -288,7 +288,7 @@ class NODE_MT_geometry_node_GEO_INPUT_SCENE(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeObjectInfo")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeInputSceneTime")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSelfObject")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Input/Scene")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_INSTANCE(Menu):
|
||||
@@ -364,7 +364,7 @@ class NODE_MT_geometry_node_GEO_MESH_READ(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeInputMeshIsland")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeInputShortestEdgePaths")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeInputMeshVertexNeighbors")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Mesh/Read")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_MESH_SAMPLE(Menu):
|
||||
@@ -375,7 +375,7 @@ class NODE_MT_geometry_node_GEO_MESH_SAMPLE(Menu):
|
||||
layout = self.layout
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSampleNearestSurface")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSampleUVSurface")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Mesh/Sample")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_MESH_WRITE(Menu):
|
||||
@@ -387,7 +387,7 @@ class NODE_MT_geometry_node_GEO_MESH_WRITE(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSetShadeSmooth")
|
||||
if context.space_data.geometry_nodes_type == 'TOOL':
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeToolSetFaceSet")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Mesh/Write")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_GEO_MESH_OPERATIONS(Menu):
|
||||
@@ -412,7 +412,7 @@ class NODE_MT_geometry_node_GEO_MESH_OPERATIONS(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSubdivideMesh")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeSubdivisionSurface")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeTriangulate")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Mesh/Operations")
|
||||
|
||||
|
||||
class NODE_MT_category_PRIMITIVES_MESH(Menu):
|
||||
@@ -429,7 +429,7 @@ class NODE_MT_category_PRIMITIVES_MESH(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeMeshCircle")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeMeshLine")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeMeshUVSphere")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Mesh/Primitives")
|
||||
|
||||
|
||||
class NODE_MT_geometry_node_mesh_topology(Menu):
|
||||
@@ -446,7 +446,7 @@ class NODE_MT_geometry_node_mesh_topology(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeFaceOfCorner")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeOffsetCornerInFace")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeVertexOfCorner")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Mesh/Topology")
|
||||
|
||||
|
||||
class NODE_MT_category_GEO_OUTPUT(Menu):
|
||||
@@ -505,7 +505,7 @@ class NODE_MT_category_GEO_TEXT(Menu):
|
||||
node_add_menu.add_node_type(layout, "FunctionNodeValueToString")
|
||||
layout.separator()
|
||||
node_add_menu.add_node_type(layout, "FunctionNodeInputSpecialCharacters")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Utilities/Text")
|
||||
|
||||
|
||||
class NODE_MT_category_GEO_TEXTURE(Menu):
|
||||
@@ -556,7 +556,7 @@ class NODE_MT_category_GEO_UTILITIES_FIELD(Menu):
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeAccumulateField")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeFieldAtIndex")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeFieldOnDomain")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Utilties/Field")
|
||||
|
||||
|
||||
class NODE_MT_category_GEO_UTILITIES_ROTATION(Menu):
|
||||
@@ -575,7 +575,7 @@ class NODE_MT_category_GEO_UTILITIES_ROTATION(Menu):
|
||||
node_add_menu.add_node_type(layout, "FunctionNodeRotationToEuler")
|
||||
node_add_menu.add_node_type(layout, "FunctionNodeRotationToQuaternion")
|
||||
node_add_menu.add_node_type(layout, "FunctionNodeQuaternionToRotation")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Utilities/Rotation")
|
||||
|
||||
|
||||
class NODE_MT_category_GEO_UTILITIES_MATH(Menu):
|
||||
@@ -592,7 +592,7 @@ class NODE_MT_category_GEO_UTILITIES_MATH(Menu):
|
||||
node_add_menu.add_node_type(layout, "ShaderNodeMapRange")
|
||||
node_add_menu.add_node_type(layout, "ShaderNodeMath")
|
||||
node_add_menu.add_node_type(layout, "ShaderNodeMix")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Utilities/Math")
|
||||
|
||||
|
||||
class NODE_MT_category_GEO_UV(Menu):
|
||||
@@ -603,7 +603,7 @@ class NODE_MT_category_GEO_UV(Menu):
|
||||
layout = self.layout
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeUVPackIslands")
|
||||
node_add_menu.add_node_type(layout, "GeometryNodeUVUnwrap")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Mesh/UV")
|
||||
|
||||
|
||||
class NODE_MT_category_GEO_VECTOR(Menu):
|
||||
@@ -622,7 +622,7 @@ class NODE_MT_category_GEO_VECTOR(Menu):
|
||||
ops.name = "data_type"
|
||||
ops.value = "'VECTOR'"
|
||||
node_add_menu.add_node_type(layout, "ShaderNodeSeparateXYZ")
|
||||
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
|
||||
node_add_menu.draw_assets_for_catalog(layout, "Utilities/Vector")
|
||||
|
||||
|
||||
class NODE_MT_category_GEO_VOLUME(Menu):
|
||||
|
||||
@@ -4498,6 +4498,7 @@ class VIEW3D_MT_edit_mesh_extrude(Menu):
|
||||
|
||||
layout.operator("mesh.extrude_repeat")
|
||||
layout.operator("mesh.spin").angle = pi * 2
|
||||
layout.template_node_operator_asset_menu_items(catalog_path="Mesh/Extrude")
|
||||
|
||||
|
||||
class VIEW3D_MT_edit_mesh_vertices(Menu):
|
||||
@@ -4642,6 +4643,7 @@ class VIEW3D_MT_edit_mesh_faces_data(Menu):
|
||||
layout.separator()
|
||||
layout.operator("mesh.mark_freestyle_face").clear = False
|
||||
layout.operator("mesh.mark_freestyle_face", text="Clear Freestyle Face").clear = True
|
||||
layout.template_node_operator_asset_menu_items(catalog_path="Face/Face Data")
|
||||
|
||||
|
||||
class VIEW3D_MT_edit_mesh_faces(Menu):
|
||||
@@ -4787,6 +4789,7 @@ class VIEW3D_MT_edit_mesh_normals(Menu):
|
||||
|
||||
layout.menu("VIEW3D_MT_edit_mesh_normals_select_strength")
|
||||
layout.menu("VIEW3D_MT_edit_mesh_normals_set_strength")
|
||||
layout.template_node_operator_asset_menu_items(catalog_path="Mesh/Normals")
|
||||
|
||||
|
||||
class VIEW3D_MT_edit_mesh_shading(Menu):
|
||||
@@ -4810,13 +4813,16 @@ class VIEW3D_MT_edit_mesh_shading(Menu):
|
||||
props.clear = True
|
||||
|
||||
layout.operator("mesh.mark_sharp", text="Sharp Vertices").use_verts = True
|
||||
layout.template_node_operator_asset_menu_items(catalog_path="Mesh/Shading")
|
||||
|
||||
|
||||
class VIEW3D_MT_edit_mesh_weights(Menu):
|
||||
bl_label = "Weights"
|
||||
|
||||
def draw(self, _context):
|
||||
VIEW3D_MT_paint_weight.draw_generic(self.layout, is_editmode=True)
|
||||
layout = self.layout
|
||||
VIEW3D_MT_paint_weight.draw_generic(layout, is_editmode=True)
|
||||
layout.template_node_operator_asset_menu_items(catalog_path="Mesh/Weights")
|
||||
|
||||
|
||||
class VIEW3D_MT_edit_mesh_clean(Menu):
|
||||
@@ -4841,6 +4847,8 @@ class VIEW3D_MT_edit_mesh_clean(Menu):
|
||||
layout.operator("mesh.remove_doubles")
|
||||
layout.operator("mesh.fill_holes")
|
||||
|
||||
layout.template_node_operator_asset_menu_items(catalog_path="Mesh/Clean Up")
|
||||
|
||||
|
||||
class VIEW3D_MT_edit_mesh_delete(Menu):
|
||||
bl_label = "Delete"
|
||||
@@ -4865,6 +4873,8 @@ class VIEW3D_MT_edit_mesh_delete(Menu):
|
||||
layout.operator("mesh.edge_collapse")
|
||||
layout.operator("mesh.delete_edgeloop", text="Edge Loops")
|
||||
|
||||
layout.template_node_operator_asset_menu_items(catalog_path="Mesh/Delete")
|
||||
|
||||
|
||||
class VIEW3D_MT_edit_mesh_merge(Menu):
|
||||
bl_label = "Merge"
|
||||
@@ -4878,6 +4888,8 @@ class VIEW3D_MT_edit_mesh_merge(Menu):
|
||||
|
||||
layout.operator("mesh.remove_doubles", text="By Distance")
|
||||
|
||||
layout.template_node_operator_asset_menu_items(catalog_path="Mesh/Merge")
|
||||
|
||||
|
||||
class VIEW3D_MT_edit_mesh_split(Menu):
|
||||
bl_label = "Split"
|
||||
@@ -4891,6 +4903,8 @@ class VIEW3D_MT_edit_mesh_split(Menu):
|
||||
|
||||
layout.operator_enum("mesh.edge_split", "type")
|
||||
|
||||
layout.template_node_operator_asset_menu_items(catalog_path="Mesh/Split")
|
||||
|
||||
|
||||
class VIEW3D_MT_edit_mesh_showhide(ShowHideMenu, Menu):
|
||||
_operator_name = "mesh"
|
||||
|
||||
@@ -619,9 +619,18 @@ static Set<std::string> get_builtin_menus(const ObjectType object_type, const eO
|
||||
menus.add_new("Select");
|
||||
menus.add_new("Add");
|
||||
menus.add_new("Mesh");
|
||||
menus.add_new("Mesh/Extrude");
|
||||
menus.add_new("Mesh/Clean Up");
|
||||
menus.add_new("Mesh/Delete");
|
||||
menus.add_new("Mesh/Merge");
|
||||
menus.add_new("Mesh/Normals");
|
||||
menus.add_new("Mesh/Shading");
|
||||
menus.add_new("Mesh/Split");
|
||||
menus.add_new("Mesh/Weights");
|
||||
menus.add_new("Vertex");
|
||||
menus.add_new("Edge");
|
||||
menus.add_new("Face");
|
||||
menus.add_new("Face/Face Data");
|
||||
menus.add_new("UV");
|
||||
break;
|
||||
case OB_MODE_SCULPT:
|
||||
@@ -650,6 +659,10 @@ static Set<std::string> get_builtin_menus(const ObjectType object_type, const eO
|
||||
static void catalog_assets_draw(const bContext *C, Menu *menu)
|
||||
{
|
||||
bScreen &screen = *CTX_wm_screen(C);
|
||||
const Object *active_object = CTX_data_active_object(C);
|
||||
if (!active_object) {
|
||||
return;
|
||||
}
|
||||
asset::AssetItemTree *tree = get_static_item_tree(*C);
|
||||
if (!tree) {
|
||||
return;
|
||||
@@ -663,15 +676,15 @@ static void catalog_assets_draw(const bContext *C, Menu *menu)
|
||||
asset_system::AssetCatalogTreeItem *catalog_item = tree->catalogs.find_item(menu_path);
|
||||
BLI_assert(catalog_item != nullptr);
|
||||
|
||||
if (assets.is_empty() && !catalog_item->has_children()) {
|
||||
return;
|
||||
}
|
||||
|
||||
uiLayout *layout = menu->layout;
|
||||
uiItemS(layout);
|
||||
bool add_separator = true;
|
||||
|
||||
wmOperatorType *ot = WM_operatortype_find("GEOMETRY_OT_execute_node_group", true);
|
||||
for (const asset_system::AssetRepresentation *asset : assets) {
|
||||
if (add_separator) {
|
||||
uiItemS(layout);
|
||||
add_separator = false;
|
||||
}
|
||||
PointerRNA props_ptr;
|
||||
uiItemFullO_ptr(layout,
|
||||
ot,
|
||||
@@ -684,6 +697,9 @@ static void catalog_assets_draw(const bContext *C, Menu *menu)
|
||||
asset::operator_asset_reference_props_set(*asset, props_ptr);
|
||||
}
|
||||
|
||||
const Set<std::string> builtin_menus = get_builtin_menus(ObjectType(active_object->type),
|
||||
eObjectMode(active_object->mode));
|
||||
|
||||
asset_system::AssetLibrary *all_library = ED_assetlist_library_get_once_available(
|
||||
asset_system::all_library_reference());
|
||||
if (!all_library) {
|
||||
@@ -691,8 +707,15 @@ static void catalog_assets_draw(const bContext *C, Menu *menu)
|
||||
}
|
||||
|
||||
catalog_item->foreach_child([&](asset_system::AssetCatalogTreeItem &item) {
|
||||
asset::draw_menu_for_catalog(
|
||||
screen, *all_library, item, "GEO_MT_node_operator_catalog_assets", *layout);
|
||||
if (builtin_menus.contains_as(item.catalog_path().str())) {
|
||||
return;
|
||||
}
|
||||
if (add_separator) {
|
||||
uiItemS(layout);
|
||||
add_separator = false;
|
||||
}
|
||||
asset::draw_menu_for_catalog(
|
||||
screen, *all_library, item, "GEO_MT_node_operator_catalog_assets", *layout);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -805,7 +828,7 @@ void ui_template_node_operator_asset_menu_items(uiLayout &layout,
|
||||
if (!tree) {
|
||||
return;
|
||||
}
|
||||
const asset_system::AssetCatalogTreeItem *item = tree->catalogs.find_root_item(catalog_path);
|
||||
const asset_system::AssetCatalogTreeItem *item = tree->catalogs.find_item(catalog_path);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
@@ -849,7 +872,7 @@ void ui_template_node_operator_asset_root_items(uiLayout &layout, const bContext
|
||||
eObjectMode(active_object->mode));
|
||||
|
||||
tree->catalogs.foreach_root_item([&](asset_system::AssetCatalogTreeItem &item) {
|
||||
if (!builtin_menus.contains(item.get_name())) {
|
||||
if (!builtin_menus.contains_as(item.catalog_path().str())) {
|
||||
asset::draw_menu_for_catalog(
|
||||
screen, *all_library, item, "GEO_MT_node_operator_catalog_assets", layout);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,61 @@ static asset::AssetItemTree build_catalog_tree(const bContext &C, const bNodeTre
|
||||
return asset::build_filtered_all_catalog_tree(library, C, type_filter, meta_data_filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to avoid adding a separate root catalog when the assets have already been added to one of
|
||||
* the builtin menus.
|
||||
* TODO: The need to define the builtin menu labels here is completely non-ideal. We don't have
|
||||
* any UI introspection that can do this though. This can be solved in the near future by
|
||||
* removing the need to define the add menu completely, instead using a per-node-type path which
|
||||
* can be merged with catalog tree.
|
||||
*/
|
||||
static const Set<StringRef> get_builtin_menus()
|
||||
{
|
||||
Set<StringRef> menus;
|
||||
menus.add_multiple_new({"Attribute",
|
||||
"Input",
|
||||
"Input/Constant",
|
||||
"Input/Group",
|
||||
"Input/Scene",
|
||||
"Output",
|
||||
"Geometry",
|
||||
"Geometry/Read",
|
||||
"Geometry/Sample",
|
||||
"Geometry/Write",
|
||||
"Geometry/Operations",
|
||||
"Curve",
|
||||
"Curve/Read",
|
||||
"Curve/Sample",
|
||||
"Curve/Write",
|
||||
"Curve/Operations",
|
||||
"Curve/Primitives",
|
||||
"Curve/Topology",
|
||||
"Mesh",
|
||||
"Mesh/Read",
|
||||
"Mesh/Sample",
|
||||
"Mesh/Write",
|
||||
"Mesh/Operations",
|
||||
"Mesh/Primitives",
|
||||
"Mesh/Topology",
|
||||
"Mesh/UV",
|
||||
"Point",
|
||||
"Volume",
|
||||
"Simulation",
|
||||
"Material",
|
||||
"Texture",
|
||||
"Utilities",
|
||||
"Utilities/Color",
|
||||
"Utilities/Text",
|
||||
"Utilities/Vector",
|
||||
"Utilities/Field",
|
||||
"Utilities/Math",
|
||||
"Utilities/Rotation",
|
||||
"Group",
|
||||
"Layout",
|
||||
"Unassigned"});
|
||||
return menus;
|
||||
}
|
||||
|
||||
static void node_add_catalog_assets_draw(const bContext *C, Menu *menu)
|
||||
{
|
||||
bScreen &screen = *CTX_wm_screen(C);
|
||||
@@ -87,9 +142,13 @@ static void node_add_catalog_assets_draw(const bContext *C, Menu *menu)
|
||||
}
|
||||
|
||||
uiLayout *layout = menu->layout;
|
||||
uiItemS(layout);
|
||||
bool add_separator = true;
|
||||
|
||||
for (const asset_system::AssetRepresentation *asset : assets) {
|
||||
if (add_separator) {
|
||||
uiItemS(layout);
|
||||
add_separator = false;
|
||||
}
|
||||
PointerRNA op_ptr;
|
||||
uiItemFullO(layout,
|
||||
"NODE_OT_add_group_asset",
|
||||
@@ -108,7 +167,16 @@ static void node_add_catalog_assets_draw(const bContext *C, Menu *menu)
|
||||
return;
|
||||
}
|
||||
|
||||
const Set<StringRef> all_builtin_menus = get_builtin_menus();
|
||||
|
||||
catalog_item->foreach_child([&](asset_system::AssetCatalogTreeItem &item) {
|
||||
if (all_builtin_menus.contains_as(item.catalog_path().str())) {
|
||||
return;
|
||||
}
|
||||
if (add_separator) {
|
||||
uiItemS(layout);
|
||||
add_separator = false;
|
||||
}
|
||||
asset::draw_menu_for_catalog(
|
||||
screen, *all_library, item, "NODE_MT_node_add_catalog_assets", *layout);
|
||||
});
|
||||
@@ -167,40 +235,7 @@ static void add_root_catalogs_draw(const bContext *C, Menu *menu)
|
||||
uiItemL(layout, IFACE_("Loading Asset Libraries"), ICON_INFO);
|
||||
}
|
||||
|
||||
/* Avoid adding a separate root catalog when the assets have already been added to one of the
|
||||
* builtin menus.
|
||||
* TODO: The need to define the builtin menu labels here is completely non-ideal. We don't have
|
||||
* any UI introspection that can do this though. This can be solved in the near future by
|
||||
* removing the need to define the add menu completely, instead using a per-node-type path which
|
||||
* can be merged with catalog tree.
|
||||
*/
|
||||
static Set<std::string> all_builtin_menus = []() {
|
||||
Set<std::string> menus;
|
||||
menus.add_new("Attribute");
|
||||
menus.add_new("Color");
|
||||
menus.add_new("Curve");
|
||||
menus.add_new("Curve Primitives");
|
||||
menus.add_new("Curve Topology");
|
||||
menus.add_new("Geometry");
|
||||
menus.add_new("Input");
|
||||
menus.add_new("Instances");
|
||||
menus.add_new("Material");
|
||||
menus.add_new("Mesh");
|
||||
menus.add_new("Mesh Primitives");
|
||||
menus.add_new("Mesh Topology");
|
||||
menus.add_new("Output");
|
||||
menus.add_new("Point");
|
||||
menus.add_new("Text");
|
||||
menus.add_new("Texture");
|
||||
menus.add_new("Tool");
|
||||
menus.add_new("Utilities");
|
||||
menus.add_new("UV");
|
||||
menus.add_new("Vector");
|
||||
menus.add_new("Volume");
|
||||
menus.add_new("Group");
|
||||
menus.add_new("Layout");
|
||||
return menus;
|
||||
}();
|
||||
const Set<StringRef> all_builtin_menus = get_builtin_menus();
|
||||
|
||||
asset_system::AssetLibrary *all_library = ED_assetlist_library_get_once_available(
|
||||
asset_system::all_library_reference());
|
||||
@@ -209,7 +244,7 @@ static void add_root_catalogs_draw(const bContext *C, Menu *menu)
|
||||
}
|
||||
|
||||
tree.catalogs.foreach_root_item([&](asset_system::AssetCatalogTreeItem &item) {
|
||||
if (!all_builtin_menus.contains(item.get_name())) {
|
||||
if (!all_builtin_menus.contains_as(item.catalog_path().str())) {
|
||||
asset::draw_menu_for_catalog(
|
||||
screen, *all_library, item, "NODE_MT_node_add_catalog_assets", *layout);
|
||||
}
|
||||
@@ -266,7 +301,7 @@ void ui_template_node_asset_menu_items(uiLayout &layout,
|
||||
return;
|
||||
}
|
||||
asset::AssetItemTree &tree = *snode.runtime->assets_for_menu;
|
||||
const asset_system::AssetCatalogTreeItem *item = tree.catalogs.find_root_item(catalog_path);
|
||||
const asset_system::AssetCatalogTreeItem *item = tree.catalogs.find_item(catalog_path);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user