2018-06-14 15:24:28 +02:00
|
|
|
from arm.logicnode.arm_nodes import *
|
|
|
|
|
2020-09-08 21:16:20 +02:00
|
|
|
class LookAtNode(ArmLogicTreeNode):
|
2021-06-15 23:06:43 +02:00
|
|
|
"""Returns *a* rotation that makes something look away from X,Y or Z, and instead look in the 'from->to' direction"""
|
2018-06-14 15:24:28 +02:00
|
|
|
bl_idname = 'LNLookAtNode'
|
|
|
|
bl_label = 'Look At'
|
2020-10-27 19:44:37 +01:00
|
|
|
arm_section = 'rotation'
|
2021-08-12 20:58:35 +02:00
|
|
|
arm_version = 2
|
2018-06-14 15:24:28 +02:00
|
|
|
|
2021-07-03 19:45:05 +02:00
|
|
|
property0: HaxeEnumProperty(
|
|
|
|
'property0',
|
2019-12-18 14:19:14 +01:00
|
|
|
items = [('X', ' X', 'X'),
|
|
|
|
('-X', '-X', '-X'),
|
|
|
|
('Y', ' Y', 'Y'),
|
|
|
|
('-Y', '-Y', '-Y'),
|
|
|
|
('Z', ' Z', 'Z'),
|
|
|
|
('-Z', '-Z', '-Z')],
|
|
|
|
name='With', default='Z')
|
|
|
|
|
2021-07-20 20:53:22 +02:00
|
|
|
def arm_init(self, context):
|
2021-07-10 21:46:44 +02:00
|
|
|
self.add_input('ArmVectorSocket', 'From Location')
|
|
|
|
self.add_input('ArmVectorSocket', 'To Location')
|
2020-11-17 16:01:15 +01:00
|
|
|
|
2021-08-18 17:04:00 +02:00
|
|
|
self.add_output('ArmRotationSocket', 'Rotation')
|
2018-06-14 15:24:28 +02:00
|
|
|
|
2021-08-18 17:04:00 +02:00
|
|
|
|
2019-12-18 14:19:14 +01:00
|
|
|
def draw_buttons(self, context, layout):
|
|
|
|
layout.prop(self, 'property0')
|
2021-08-12 20:58:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_replacement_node(self, node_tree: bpy.types.NodeTree):
|
|
|
|
if self.arm_version not in (0, 1):
|
|
|
|
raise LookupError()
|
|
|
|
|
|
|
|
|
|
|
|
# transition from version 1 to version 2: make rotations their own sockets
|
|
|
|
# this transition is a mess, I know.
|
|
|
|
newself = self.id_data.nodes.new('LNLookAtNode')
|
|
|
|
converter = self.id_data.nodes.new('LNSeparateRotationNode')
|
|
|
|
self.id_data.links.new(newself.outputs[0], converter.inputs[0])
|
|
|
|
converter.property0 = 'EulerAngles'
|
|
|
|
converter.property1 = 'Rad'
|
|
|
|
converter.property2 = 'XZY'
|
|
|
|
for link in self.outputs[0].links:
|
|
|
|
self.id_data.links.new(converter.outputs[0], link.to_socket)
|
|
|
|
|
|
|
|
return [newself, converter]
|