Hi! As a learning experience I’m trying to add 3D cursor rotation control to the N-panel. As it is, the cursor’s rotation is cool, and it will be useful, but it’s frustrating because the user doesn’t have exact control over its rotation. An easy solution is just to add the rotation control below the position The only possible downside is it takes a small amount of space, but I think it’s worth it.
So, I added the property below the location, but it displays as a quaternion, which makes it frustrating to adjust with the sliders.
I am looking for the N-panel C code for an example of the euler display of a quaternion, but I haven’t found it yet. It’s not clear what the N-panel is called in the code, or even if a solution I found would apply. I’m also not able to find the source for layout.column().prop(...)
Is there a method to display a quaternion as a euler rotation built into prop(…)? Or any tips on where to look where this is already done?
Thanks for taking a look at such a basic question. I’m looking forward to becoming more proficient in the Blender codebase.
There is no automatic method to display a quaternion value as an Euler.
I think the simplest way to solve this is to change the cursor rotation to be stored internally as an Euler value. Converting to and from quaternion is not ideal as this does not always exactly preserve the Euler values as the user specified.
Hello! I’m still working storing the cursor’s rotation as a Euler rotation internally, but it’s proving to be a bit more difficult than I thought. I am basing my changes to the cursor rotation property off of this image:
In the DNA_view3d_types.h file I have made the necessary change:
I’ve also change the cursor rotation initialization in the scene.c and versioning_280.c from unit-qt(…):
/*unit_qt(sce->cursor.rotation); HANSTODO: Change to Euler */
zero_v3(sce->cursor.rotation);
The only code I haven’t changed to euler is in ED_view3d_cursor3d_position_rotation(…), which will take a bit more work to move to Euler operations. I haven’t started to modify it because I can’t find where it is used, Qt-Creator can only find one usage of the function, which is in the same file.
Where my understanding breaks down is here: The cursor is still interpreted as a quaternion:
What you can do is rename it from rotation[3] to rotation_euler[3]. Then you will get a bunch of compile errors and you can go over each to ensure it is not being interpreted as a quaternion.
There’s a bunch of places where you’ll have to use eul_to_mat3() or eul_to_quat().