Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/startup/bl_operators/geometry_nodes.py
| Show All 32 Lines | def geometry_node_group_empty_new(context): | ||||
| input_node.location.x = -200 - input_node.width | input_node.location.x = -200 - input_node.width | ||||
| output_node.location.x = 200 | output_node.location.x = 200 | ||||
| group.links.new(output_node.inputs[0], input_node.outputs[0]) | group.links.new(output_node.inputs[0], input_node.outputs[0]) | ||||
| return group | return group | ||||
| def geometry_modifier_poll(context) -> bool: | def geometry_modifier_poll(context, require_modifier=True) -> bool: | ||||
| ob = context.object | ob = context.object | ||||
| # Test object support for geometry node modifier (No volume, curve, or hair object support yet) | # Test object support for geometry node modifier (No volume, curve, or hair object support yet) | ||||
| if not ob or ob.type not in {'MESH', 'POINTCLOUD'}: | if not ob or ob.type not in {'MESH', 'POINTCLOUD'}: | ||||
| return False | return False | ||||
| if require_modifier: | |||||
| modifier = ob.modifiers.active | |||||
| if not modifier or modifier.type != 'NODES': | |||||
| return False | |||||
| return True | return True | ||||
| class NewGeometryNodesModifier(bpy.types.Operator): | class NewGeometryNodesModifier(bpy.types.Operator): | ||||
| """Create a new modifier with a new geometry node group""" | """Create a new modifier with a new geometry node group""" | ||||
| bl_idname = "node.new_geometry_nodes_modifier" | bl_idname = "node.new_geometry_nodes_modifier" | ||||
| bl_label = "New Geometry Node Modifier" | bl_label = "New Geometry Node Modifier" | ||||
| bl_options = {'REGISTER', 'UNDO'} | bl_options = {'REGISTER', 'UNDO'} | ||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| return geometry_modifier_poll(context) | return geometry_modifier_poll(context, require_modifier=False) | ||||
| def execute(self, context): | def execute(self, context): | ||||
| modifier = context.object.modifiers.new("GeometryNodes", "NODES") | modifier = context.object.modifiers.new("GeometryNodes", "NODES") | ||||
| if not modifier: | if not modifier: | ||||
| return {'CANCELLED'} | return {'CANCELLED'} | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class NewGeometryNodeTreeAssign(bpy.types.Operator): | class NewGeometryNodeTreeAssign(bpy.types.Operator): | ||||
| """Create a new geometry node group and assign it to the active modifier""" | """Create a new geometry node group and assign it to the active modifier""" | ||||
| bl_idname = "node.new_geometry_node_group_assign" | bl_idname = "node.new_geometry_node_group_assign" | ||||
| bl_label = "Assign New Geometry Node Group" | bl_label = "Assign New Geometry Node Group" | ||||
| bl_options = {'REGISTER', 'UNDO'} | bl_options = {'REGISTER', 'UNDO'} | ||||
| @classmethod | @classmethod | ||||
| def poll(cls, context): | def poll(cls, context): | ||||
| return geometry_modifier_poll(context) | return geometry_modifier_poll(context) | ||||
| def execute(self, context): | def execute(self, context): | ||||
| modifier = context.object.modifiers.active | modifier = context.object.modifiers.active | ||||
| if not modifier: | |||||
| return {'CANCELLED'} | |||||
| group = geometry_node_group_empty_new(context) | group = geometry_node_group_empty_new(context) | ||||
| modifier.node_group = group | modifier.node_group = group | ||||
| return {'FINISHED'} | return {'FINISHED'} | ||||
| class DuplicateGeometryNodeTreeAssign(bpy.types.Operator): | |||||
| """Duplicate the geometry node group and assign it the the active modifier""" | |||||
| bl_idname = "node.duplicate_geometry_node_group_assign" | |||||
| bl_label = "Assign Duplicate Geometry Node Group" | |||||
| bl_options = {'REGISTER', 'UNDO'} | |||||
| @classmethod | |||||
| def poll(cls, context): | |||||
| return geometry_modifier_poll(context) | |||||
| def execute(self, context): | |||||
| modifier = context.object.modifiers.active | |||||
| group = modifier.node_group.copy() | |||||
| modifier.node_group = group | |||||
| return {'FINISHED'} | |||||
| classes = ( | classes = ( | ||||
| NewGeometryNodesModifier, | NewGeometryNodesModifier, | ||||
| NewGeometryNodeTreeAssign, | NewGeometryNodeTreeAssign, | ||||
| DuplicateGeometryNodeTreeAssign, | |||||
| ) | ) | ||||