diff --git a/nodes.py b/nodes.py index 9fb4f1e..1bc75ae 100644 --- a/nodes.py +++ b/nodes.py @@ -634,6 +634,34 @@ class SetControlNode(AbstractRigNodesNode): control_obj.scale = control_scale +class RemapPositionNode(AbstractRigNodesEventNode): + """Relative remapping of a location""" + + bl_idname = "RemapPositionNode" + bl_label = "Remap Position" + bl_icon = "EMPTY_ARROWS" + + def init(self, context): + self.inputs.new("NodeSocketVector", "From Origin") + self.inputs.new("NodeSocketVector", "From Destination") + self.inputs.new("NodeSocketVector", "To Origin") + self.inputs.new("NodeSocketVector", "To Destination") + self.outputs.new("NodeSocketVector", "Result") + + def execute(self, depsgraph: bpy.types.Depsgraph) -> None: + from_origin = self._get_input_value("From Origin", Vector) + from_dest = self._get_input_value("From Destination", Vector) + to_origin = self._get_input_value("To Origin", Vector) + to_dest = self._get_input_value("To Destination", Vector) + + from_dist = (from_dest - from_origin).length + to_dist = (to_dest - to_origin).length + + fact = to_dist / from_dist if to_dist != 0 else 0 + res = (from_dest - from_origin) * fact + to_origin + self.outputs["Result"].default_value = res + + class ToVector(AbstractRigNodesNode): bl_idname = "ToVector" bl_label = "To Vector" @@ -1343,6 +1371,7 @@ node_categories = [ nodeitems_utils.NodeItem("ClampNode"), nodeitems_utils.NodeItem("ToEulerNode"), nodeitems_utils.NodeItem("FromEulerNode"), + nodeitems_utils.NodeItem("RemapPositionNode"), ], ), RigNodesNodeCategory( @@ -1371,6 +1400,7 @@ classes = ( TwoBoneIKNode, SetCursorNode, SequenceNode, + RemapPositionNode, # Math Nodes RotateTowards, AngleFromVectors, diff --git a/rignodes-remap_location.blend b/rignodes-remap_location.blend new file mode 100644 index 0000000..d519d4f Binary files /dev/null and b/rignodes-remap_location.blend differ