Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matrix_out: nesting fix + recursive node #3991

Merged
merged 1 commit into from
Mar 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions nodes/matrix/matrix_out_mk2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
from sverchok.utils.sv_transform_helper import AngleUnits, SvAngleHelper
from sverchok.utils.nodes_mixins.recursive_nodes import SvRecursiveNode
from mathutils import Matrix


Expand All @@ -37,7 +38,7 @@
}


class SvMatrixOutNodeMK2(bpy.types.Node, SverchCustomTreeNode, SvAngleHelper):
class SvMatrixOutNodeMK2(bpy.types.Node, SverchCustomTreeNode, SvAngleHelper, SvRecursiveNode):
"""
Triggers: Matrix, Out
Tooltip: Convert a matrix into its location, scale & rotation components
Expand Down Expand Up @@ -79,7 +80,7 @@ def update_mode(self, context):
items=mode_items, default="AXISANGLE", update=update_mode)

def sv_init(self, context):
self.inputs.new('SvMatrixSocket', "Matrix")
self.inputs.new('SvMatrixSocket', "Matrix").is_mandatory =True
# translation and scale outputs
self.outputs.new('SvVerticesSocket', "Location")
self.outputs.new('SvVerticesSocket', "Scale")
Expand All @@ -104,48 +105,41 @@ def draw_buttons(self, context, layout):
def draw_buttons_ext(self, context, layout):
if self.mode in {"EULER", "AXISANGLE"}:
self.draw_angle_units_buttons(context, layout)

def process(self):

def process_data(self, params):
input_M = params[0]
outputs = self.outputs
if not any(s.is_linked for s in outputs):
return

input_M = self.inputs['Matrix'].sv_get()

# decompose matrices into: Translation, Rotation (quaternion) and Scale
location_list = []
quaternion_list = [] # rotations (as quaternions)
scale_list = []
angles = [[], [], []]
axis_list, angle_list = [], []
for m in input_M:
T, R, S = m.decompose()
location_list.append(list(T))
location_list.append([list(T)])
quaternion_list.append(R)
scale_list.append(list(S))
scale_list.append([list(S)])

outputs["Location"].sv_set(location_list)
outputs["Scale"].sv_set(scale_list)

if self.mode == "QUATERNION":
self.outputs['Quaternion'].sv_set(quaternion_list)

elif self.mode == "EULER":
if self.mode == "EULER":
# conversion factor from radians to the current angle units
au = self.angle_conversion_factor(AngleUnits.RADIANS, self.angle_units)

for i, name in enumerate("XYZ"):
if outputs["Angle " + name].is_linked:
angles = [q.to_euler(self.euler_order)[i] * au for q in quaternion_list]
outputs["Angle " + name].sv_set([angles])

angles[i] = [[q.to_euler(self.euler_order)[i] * au] for q in quaternion_list]
elif self.mode == "AXISANGLE":
if outputs['Axis'].is_linked:
axis_list = [tuple(q.axis) for q in quaternion_list]
outputs['Axis'].sv_set([axis_list])
axis_list = [[tuple(q.axis)] for q in quaternion_list]


if outputs['Angle'].is_linked:
# conversion factor from radians to the current angle units
au = self.angle_conversion_factor(AngleUnits.RADIANS, self.angle_units)
angle_list = [q.angle * au for q in quaternion_list]
outputs['Angle'].sv_set([angle_list])
angle_list = [[q.angle * au] for q in quaternion_list]

return (location_list, scale_list, quaternion_list, *angles, axis_list, angle_list)



def register():
Expand Down