0
$\begingroup$

I would like to know to access individual elements of a matrix or matrices from Matrix/Matrix list input in the script node. Then I can perform some operations(experimentation) on those elements and then send them to output as a Matrix/Matrix list. I would like to do similar with Euler angles and Vectors. I am very new to programming and have searched this forum and coudn't find anything to do with this with regards to animation nodes.

$\endgroup$

1 Answer 1

3
$\begingroup$

Here are some examples for creating and decomposing each type:

Vector and Vector list

from mathutils import Vector

# create Vector
x = 1
y = 2
z = 3
new_vector = Vector((x,y,z))

# extract individual elements
x_element = new_vector.x # new_vector[0]
y_element = new_vector.y # new_vector[1]
z_element = new_vector.z # new_vector[2]

# create AN vector list
new_vector_list = Vector3DList()

# append element to vector List
new_vector_list.append(new_vector)
 
# get element from vector List
first_element = new_vector_list[0]

# get first element's x value
first_vector_x = new_vector_list[0].x

Euler and Euler list

from math import radians
from mathutils import Euler

# create Euler
x = radians(30)
y = radians(45)
z = radians(60)
new_euler = Euler((x,y,z)) # Euler((x,y,z),"XYZ")

# extract individual elements
x_element = new_euler.x # new_euler[0]
y_element = new_euler.y # new_euler[1]
z_element = new_euler.z # new_euler[2]

# create AN euler List
new_euler_list = EulerList()

# append element to euler List
new_euler_list.append(new_euler)

# get element from euler List
first_element = new_euler_list[0]

# get first element's x value
first_element_x = new_euler_list[0].x

Matrix and Matrix list

from mathutils import Matrix, Euler, Vector

# create matrix
location = Vector((0,0,0))
rotation = Euler((0,0,0))
scale = Vector((0,0,0))
new_matrix = AN.utils.math.composeMatrix(location, rotation, scale)

# extract location
extracted_loc = new_matrix.to_translation()

# extract rotation
extracted_rot = new_matrix.to_euler()

# extract scale
extracted_scale = new_matrix.to_scale()

# create AN matrix list
new_matrix_list = Matrix4x4List()

# append element to matrix list
new_matrix_list.append(new_matrix)

# get element from matrix list
first_element = new_matrix_list[0]

# get first element's location
first_element_location = new_matrix_list[0].to_translation()

# get first element's x location
first_element_location = new_matrix_list[0].to_translation().x

# get raw matrix element
matrix_first_element = new_matrix_list[0][0]

I suggest you to look at blender api documentation for more information.

$\endgroup$
1
  • $\begingroup$ Thankyou for nice comprehensive answer. I just discovered the mathutils page about an hour and was in process of working it out. What other python functions like append should I look at that will be useful to manipulate, sort or search the lists. $\endgroup$ Jul 31, 2020 at 17:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .