-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new Copy Modifiers node
- Loading branch information
Showing
6 changed files
with
178 additions
and
1 deletion.
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
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,42 @@ | ||
=================== | ||
Copy Modifiers Node | ||
=================== | ||
|
||
.. figure:: https://user-images.githubusercontent.com/28003269/163018172-7911e4a4-acd3-4cd5-a09f-1b436c9de088.png | ||
:align: right | ||
:figwidth: 200px | ||
|
||
Functionality | ||
------------- | ||
|
||
The node performs similar operation to standard Blender Copy Modifiers operation. | ||
It takes two set of objects and apply modifiers from one set to another. | ||
It is useful for example in case when you want to assign Remesh or Subdivide modifiers | ||
to Sverchok objects. | ||
|
||
.. raw:: html | ||
|
||
<video width="700" controls> | ||
<source src="https://user-images.githubusercontent.com/28003269/163026163-a8762f52-b6f2-4dcd-b95e-760da3af033a.mp4" type="video/mp4"> | ||
Your browser does not support the video tag. | ||
</video> | ||
|
||
Inputs | ||
------ | ||
|
||
**Object To** - Objects to whom to apply modifiers | ||
|
||
**Object From** - Objects from which get modifiers | ||
|
||
Outputs | ||
------- | ||
|
||
**Object** - Objects with assigned modifiers | ||
|
||
Examples | ||
-------- | ||
|
||
Assign Remesh modifier | ||
|
||
.. image:: https://user-images.githubusercontent.com/28003269/163020246-317c00e5-dd15-4caa-8c14-3c98ca633ae5.png | ||
:width: 700 px |
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 |
---|---|---|
|
@@ -19,3 +19,4 @@ Objects | |
set_loop_normals | ||
set_mesh_attribute | ||
set_collection | ||
copy_modifiers |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# This file is part of project Sverchok. It's copyrighted by the contributors | ||
# recorded in the version control history of the file, available from | ||
# its original location https://github.com/nortikin/sverchok/commit/master | ||
# | ||
# SPDX-License-Identifier: GPL3 | ||
# License-Filename: LICENSE | ||
from operator import attrgetter | ||
|
||
import bpy | ||
from sverchok.data_structure import repeat_last | ||
|
||
from sverchok.node_tree import SverchCustomTreeNode | ||
from sverchok.utils.nodes_mixins.sv_animatable_nodes import SvAnimatableNode | ||
from sverchok.utils.handle_blender_data import BlModifier | ||
|
||
|
||
class SvCopyModifiersNode(SvAnimatableNode, SverchCustomTreeNode, bpy.types.Node): | ||
""" | ||
Triggers: modifiers | ||
Tooltip: | ||
""" | ||
bl_idname = 'SvCopyModifiersNode' | ||
bl_label = 'Copy Modifiers' | ||
bl_icon = 'MODIFIER_DATA' | ||
|
||
def sv_init(self, context): | ||
self.inputs.new('SvObjectSocket', 'Object To') | ||
self.inputs.new('SvObjectSocket', 'Object From') | ||
self.outputs.new('SvObjectSocket', 'Object') | ||
|
||
def draw_buttons(self, context, layout): | ||
self.draw_animatable_buttons(layout) | ||
|
||
def process(self): | ||
obj_to = self.inputs['Object To'].sv_get(deepcopy=False, default=[]) | ||
obj_from = self.inputs['Object From'].sv_get(deepcopy=False, default=[]) | ||
|
||
for to, _from in zip(obj_to, repeat_last(obj_from)): | ||
|
||
# test changes, should prevent from useless mesh reevaluations presumably | ||
is_valid = True | ||
for mod_from in _from.modifiers: | ||
if mod_from.name not in to.modifiers: | ||
is_valid = False | ||
break | ||
mod_to = to.modifiers[mod_from.name] | ||
if BlModifier(mod_to) != BlModifier(mod_from): | ||
is_valid = False | ||
break | ||
else: | ||
if len(to.modifiers) != len(_from.modifiers): | ||
is_valid = False | ||
|
||
# reapply modifiers | ||
if not is_valid: | ||
to.modifiers.clear() | ||
for mod_from in _from.modifiers: | ||
mod_to = to.modifiers.new(mod_from.name, mod_from.type) | ||
|
||
# apply modifier properties | ||
for prop in (p for p in mod_from.bl_rna.properties if not p.is_readonly): | ||
setattr(mod_to, prop.identifier, getattr(mod_from, prop.identifier)) | ||
if mod_from.type == 'NODES' and mod_from.node_group: | ||
for tree_inp in mod_from.node_group.inputs[1:]: | ||
prop_name = tree_inp.identifier | ||
mod_to[prop_name] = mod_from[prop_name] | ||
mod_to[f"{prop_name}_use_attribute"] = mod_from[f"{prop_name}_use_attribute"] | ||
mod_to[f"{prop_name}_attribute_name"] = mod_from[f"{prop_name}_attribute_name"] | ||
for tree_out in mod_from.node_group.outputs[1:]: | ||
prop_name = tree_out.identifier | ||
mod_to[f"{prop_name}_attribute_name"] = mod_from[f"{prop_name}_attribute_name"] | ||
|
||
self.outputs['Object'].sv_set(obj_to) | ||
|
||
|
||
register, unregister = bpy.utils.register_classes_factory([SvCopyModifiersNode]) |
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