Proper custom gizmo scaling

How should you set the gizmo group/gizmo properties so that a custom gizmo is always scaled exactly the same (screen space wise)?

Here’s the issue:
Zoomed In – The spacing between the boxes here is what I’m after:

Zoomed Out – Incorrect; I want to maintain the offset between the boxes:

As you can see, the boxes correctly maintain their size (which is what I want), but they do NOT maintain their effective distance offset from each other (which I can’t figure out how to maintain).

Here’s some pertinent pieces of the code:

GizmoGroup options

class DCONFIG_GGT_symmetry_gizmo(bpy.types.GizmoGroup):
    bl_label = "Symmetry Gizmo Group"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'WINDOW'
    bl_options = {'3D'}

setting various Gizmo options

            mpr.use_draw_scale = True
            mpr.select_bias = 0.02
            mpr.scale_basis = 0.2
            mpr.use_select_background = True
            mpr.use_event_handle_all = False
            mpr.use_grab_cursor = True

Gizmo matrix calculation – draw_offset is a unit vector like (1,0,0) or (0, -1, 0); I’m taking my custom shape cube and shifting it along each of the 6 axis directions:

    def update(self, mat_target):
        mat_t = Matrix.Translation(self.draw_offset * 0.25)
        self.matrix_basis = mat_t @ mat_target

I might be wrong. But isn’t Translation Matricies connected to the position of a object, not it’s scale.

Also I personally would look if I can plug a different projection matrix . Or create a custom view matrix that uses the target of the viewport matrix but does not move(or zoom in-out). And feed that to the gizmo’s view matrix.

Thanks for replying over here. The issue turned out to be a simple setting and a potential bug that i’ll ask about later.

You need to set the use_draw_offset_scale to True on your Gizmo object AND use the matrix_offset field instead of matrix_basis

However, there’s a weird gotcha if you also set use_draw_scale to True. If you set this to True after you’ve already set use_draw_offset_scale things are broken again. I will follow up with some devs later to see if that’s by design or not.

1 Like