Adding rotation control to 3D cursor in N-panel -- questions arrise

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.

1 Like

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.

1 Like

Great, thanks so much for your quick reply! I’ll make that change and then figure out how to submit a patch.

I don’t know if you still want an example for the N-panel but here is one by Joshua Leung

81c302bbff48b391b7f62ef7db233e9c7bd2adb2

Just do a search for this SHA in your git log tool

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:

typedef struct View3DCursor {
    float location[3];
    float rotation[3];
    char _pad[8];
} View3DCursor;

In the rna_scene.c file I have also changed the quaternion type to Euler:

prop = RNA_def_property(srna, "cursor_rotation", PROP_FLOAT, PROP_EULER);
RNA_def_property_float_sdna(prop, NULL, "cursor.rotation");              
RNA_def_property_ui_text(prop, "Cursor Rotation", "3D cursor rotation"); 
RNA_def_property_update(prop, NC_WINDOW, NULL);                          

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:

I’ve learned a lot by getting this far, but I’d like to finish. Here’s where I would love some help:

  1. The location of the code that actually draws the 3D cursor.
  2. I believe I am missing something regarding the initialization of the cursor rotation. At startup, the first value of the vector is still 1.0f.
  3. Usage of ED_view3d_cursor3d_position_rotation(…) so I can change those as well.

@ideasman42 Campbell, I am mentioning you because I believe you were behind the 3D cursor rotation feature.

I’d love your input on how to address adding Euler rotation control to the sidepanel (And the 3D cursor placement tool too).

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().

Thanks again Brecht! That worked well. I should have thought of that.

Here’s a patch: https://developer.blender.org/D4400