convert basis to angles for rotation

Godot Version

Godot_v4.3-stable_win64

Question

As you know, in GridMap, the orientation parameter is used for rotation (0-24). To convert angles to basis and then to orientation I use this code:

var angles = Vector3(deg_to_rad(v_x_1), deg_to_rad(v_x_2), deg_to_rad(v_x_3))

var basis = Basis.from_euler(angles)

var arr = [

int(basis.x.x), int(basis.x.y), int(basis.x.z),

int(basis.y.x), int(basis.y.y), int(basis.y.z),

int(basis.z.x), int(basis.z.y), int(basis.z.z)

]

We got a basis. next, we find this basis in the array of all basis associated with the parameter orientation.

var index_orientation = 0

index_orientation = basis_orientations.get(arr,0)

dictionary of basis for all 24 rotation variants:

var basis_orientations = {

[1, 0, 0, 0, 1, 0, 0, 0, 1]: 0,

[0, -1, 0, 1, 0, 0, 0, 0, 1]: 1,

[-1, 0, 0, 0, -1, 0, 0, 0, 1]: 2,

[0, 1, 0, -1, 0, 0, 0, 0, 1]: 3,

[1, 0, 0, 0, 0, -1, 0, 1, 0]: 4,

[0, 0, 1, 1, 0, 0, 0, 1, 0]: 5,

[-1, 0, 0, 0, 0, 1, 0, 1, 0]: 6,

[0, 0, -1, -1, 0, 0, 0, 1, 0]: 7,

[1, 0, 0, 0, -1, 0, 0, 0, -1]: 8,

[0, 1, 0, 1, 0, 0, 0, 0, -1]: 9,

[-1, 0, 0, 0, 1, 0, 0, 0, -1]: 10,

[0, -1, 0, -1, 0, 0, 0, 0, -1]: 11,

[1, 0, 0, 0, 0, 1, 0, -1, 0]: 12,

[0, 0, -1, 1, 0, 0, 0, -1, 0]: 13,

[-1, 0, 0, 0, 0, -1, 0, -1, 0]: 14,

[0, 0, 1, -1, 0, 0, 0, -1, 0]: 15,

[0, 0, 1, 0, 1, 0, -1, 0, 0]: 16,

[0, -1, 0, 0, 0, 1, -1, 0, 0]: 17,

[0, 0, -1, 0, -1, 0, -1, 0, 0]: 18,

[0, 1, 0, 0, 0, -1, -1, 0, 0]: 19,

[0, 0, 1, 0, -1, 0, 1, 0, 0]: 20,

[0, 1, 0, 0, 0, 1, 1, 0, 0]: 21,

[0, 0, -1, 0, 1, 0, 1, 0, 0]: 22,

[0, -1, 0, 0, 0, -1, 1, 0, 0]: 23,

}

But now I need to convert orientation to angles for rotation. I’ve heard of the get_euler() function, but it doesn’t seem to work.

at the moment with the help of this code I got basis:

var basis_array_keys = basis_orientations.keys()

var basis_array = basis_array_keys[orientation_index]

var basis = Basis(

Vector3(basis_array[0], basis_array[1], basis_array[2]),

Vector3(basis_array[3], basis_array[4], basis_array[5]),

Vector3(basis_array[6], basis_array[7], basis_array[8]),
)

But then how to convert the basis to angles?

Why do you need those angles for? Afaik GridMap::set_cell_item() expect the value you can get from the basis by calling GridMap::get_orthogonal_index_from_basis()

thank you, i din’t know about this functions of gridmap: get_orthogonal_index_from_basis and get_basis_with_orthogonal_index. So I can get the basis without using an array.

but now i need get angles for rotation. reverse algorithm. I have an array with cells from gridmap (index,pos,orientation). im need convert orientation to angles.

What do you need angles for? What you’re going to do with them?

im making minecraft-like game. in the previous version used gridmap, but now I’m switching to cloning meshes (blocks) via duplicate() and also use MultiMesh… i want to add support for saves from previous version. but I need angles (not rotation or basis) to set rotation of block (node - mesh)

You can just directly assign the basis.