-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new operator about convert curve to mesh with group infos.
- add a new operator which can converte selected object to mesh, and if object is curve and has bevel object, it will copy the virtools group info of bevel object at the same time. - add a hint in virtools group panel to tell user that the virtools group of non-mesh object will not be saved.
- Loading branch information
Showing
3 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import bpy | ||
import typing | ||
from . import PROP_virtools_group | ||
|
||
class BBP_OT_snoop_group_then_to_mesh(bpy.types.Operator): | ||
"""Convert selected objects into mesh objects and try to copy the Virtools Group infos of their associated curve bevel object if they have. """ | ||
bl_idname = "bbp.snoop_group_then_to_mesh" | ||
bl_label = "Snoop Group then to Mesh" | ||
bl_options = {'UNDO'} | ||
|
||
@classmethod | ||
def poll(cls, context): | ||
return len(context.selected_objects) != 0 | ||
|
||
def execute(self, context): | ||
for obj in context.selected_objects: | ||
# skip all non-curve object | ||
if obj.type != 'CURVE': continue | ||
|
||
# fetch curve data block | ||
curve: bpy.types.Curve = typing.cast(bpy.types.Curve, obj.data) | ||
|
||
# if bevel mode is not object, skip | ||
if curve.bevel_mode != 'OBJECT': continue | ||
# if bevel object is None, skip | ||
bevel_obj: bpy.types.Object | None = curve.bevel_object | ||
if bevel_obj is None: continue | ||
|
||
# copy bevel object group info into current object | ||
# MARK: VirtoolsGroupsHelper is self-mutex. | ||
# we only can operate one VirtoolsGroupsHelper at the same time. | ||
# so we extract bevel object group infos then apply to target later. | ||
group_infos: tuple[str, ...] | ||
with PROP_virtools_group.VirtoolsGroupsHelper(bevel_obj) as bevel_gp: | ||
group_infos = tuple(bevel_gp.iterate_groups()) | ||
with PROP_virtools_group.VirtoolsGroupsHelper(obj) as this_gp: | ||
this_gp.clear_groups() | ||
this_gp.add_groups(group_infos) | ||
|
||
# convert all selected object to mesh | ||
# no matter the success of copying virtools group infos and whether selected object is curve | ||
bpy.ops.object.convert(target = 'MESH') | ||
|
||
return {'FINISHED'} | ||
|
||
def register() -> None: | ||
bpy.utils.register_class(BBP_OT_snoop_group_then_to_mesh) | ||
|
||
def unregister() -> None: | ||
bpy.utils.unregister_class(BBP_OT_snoop_group_then_to_mesh) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters