armory/blender/arm/logicnode/value_vector_from_transform.py
niacdoial 17daabeb29 Improved quaternion and angle handling in logic nodes (+2bugfixes)
- Made so all nodes outputting a quaternion object also output it as a XYZ (vector) + W (float) combination
- Modernized the interface of the "Action/Rotate Object" node, to align on the newer "Action/Set Rotation" node interface  ("Action/Rotate Object Along Axis" is now depreciated, but still usable)
- Fixed a blender-side-only bug with the "Logic/Switch" node (...which technically could have lead to a compile-time problem if exploited the right way)
- Fixed a bug on the "Action/Set Rotation" node: now, quaternion input is automatically normalized in order to avoid accidental scaling
- Added a "Value/Separate Quaternion" node
- Made so the names of some sockets change in the "Set Rotation" and "Rotate Object" nodes, so they adapt to those nodes' input types.
  (Same thing with "Value/Vector From Transform"'s output type)
2020-08-30 15:50:06 +02:00

44 lines
1.7 KiB
Python

import bpy
from bpy.props import *
from bpy.types import Node, NodeSocket
from arm.logicnode.arm_nodes import *
class VectorFromTransformNode(Node, ArmLogicTreeNode):
'''Vector from transform node'''
bl_idname = 'LNVectorFromTransformNode'
bl_label = 'Vector From Transform'
bl_icon = 'NONE'
def init(self, context):
self.inputs.new('NodeSocketShader', 'Transform')
self.outputs.new('NodeSocketVector', 'Vector')
self.outputs.new('NodeSocketVector', 'Quaternion XYZ')
self.outputs.new('NodeSocketFloat', 'Quaternion W')
def on_property_update(self, context):
"""called by the EnumProperty, used to update the node socket labels"""
# note: the conditions on len(self.outputs) are take in account "old version" (pre-2020.9) nodes, which only have one output
if self.property0 == "Quaternion":
self.outputs[0].name = "Quaternion"
if len(self.outputs) > 1:
self.outputs[1].name = "Quaternion XYZ"
self.outputs[2].name = "Quaternion W"
else:
self.outputs[0].name = "Vector"
if len(self.outputs) > 1:
self.outputs[1].name = "[quaternion only]"
self.outputs[2].name = "[quaternion only]"
def draw_buttons(self, context, layout):
layout.prop(self, 'property0')
property0: EnumProperty(
items = [('Up', 'Up', 'Up'),
('Right', 'Right', 'Right'),
('Look', 'Look', 'Look'),
('Quaternion', 'Quaternion', 'Quaternion')],
name='', default='Look',
update=on_property_update)
add_node(VectorFromTransformNode, category='Value')