Quarterions Math


  • Move the Quaternion node from Transform to Variable
  • Move the Separate Quaternion node from Transform to Math
  • Add Add, Sub, Slerp functions for quartenions
  • Add Quaternion Math node to Math category (first version):

Waiting for your suggestions.
Tell me how best to name the operation.


This looks a hard work ^^

I just think that we should separate things trough a separate node instead of a checkbox (just to keep all the same and don’t need to create a separator for every node we do). From performance view i can’t say which is better.

This looks good for me :+1:

My only suggestions would be to leave the quaternion variable with a single output (if this becomes a variable) and to rename Get Euler to To Euler

Captura de tela de 2020-11-06 16-20-39

Great work!

1 Like


Separator Out is a switch for displaying the resulting data. It does not carry any mathematical operations, it is just an appeal to the fields of the Vec4 class. In the math node, I think it’s convenient.

I think this makes sense, I’ll leave it as it was.

Not really difficult. =)

  • If it’s about mathematical operations, then they are partially similar to operations with vectors, and many have already been implemented in Kha. If you want to read on quaternions, then I recommend this article.
  • If about the formation of nodes, then I will try to briefly describe, it may be useful. If you’re not interested, skip it.

It should be understood that the list (array) of input and output parameters can be changed at any time. There is only a problem with outputs, which I wrote about here.
For example, to display the list of operations, EnumProperty is used, which has the ability to specify the set, get functions (all Properties have them). Thus, we get control over saving the results of the selection and displaying it, and over the event selected from the list. As a result:

  def get_enum(self):   
    return self['property0'] # get the selected value

  # Value – the order number in the items list
  def set_enum(self, value):
	select_current = self.get_enum_id_value(self, 'property0', value)
    select_prev = self.property0
	# Checking the choice of another operation, in case the same value was chosen, nothing changed	
    if select_prev != select_current:
		# Examples of removing the last item in a list
		# Checking which operation is selected
		if (select_current == 'Lerp') or (select_current == 'Slerp'):
          self.add_input('NodeSocketVector', 'From')
          self.add_input('NodeSocketVector', 'To')
          self.add_input('NodeSocketFloat', 'T')
      if (select_current == 'FromAxisAngle'):
          self.add_input('NodeSocketVector', 'Quaternion')
          self.add_input('NodeSocketVector', 'Axis')
          self.add_input('NodeSocketFloat', 'Angle')
     self['property0'] = value # save select
  property0: EnumProperty(
    items = [('Add', 'Add', 'Add'),
             ('Subtract', 'Subtract', 'Subtract'),
             ('Lerp', 'Lerp', 'Lerp'),
             ('Slerp', 'Slerp', 'Slerp'),
             ('FromAxisAngle', 'From Axis Angle', 'From Axis Angle')],
    name='', default='Add', set=set_enum, get=get_enum)

Function for deriving an identifier from the EnumProperty items:

    def get_enum_id_value(obj, prop_name, value):
        return obj.bl_rna.properties[prop_name].enum_items[value].identifier

If you delete the parameters, then the connections disappear, so you can control this too. For example, if there was an Add operation, but Subtract was selected, and other nodes were connected to the parameters, then it is not necessary to delete inputs.
Blender already renders the display of inputs and outputs.
I hope I explained clearly. :slight_smile: