0
$\begingroup$

I am trying to find a way to add a bool property to Areas that are of type 'VIEW_3D'.

What I am trying to implement is a mechanism where I would have a simple On/Off switch for each visible 3D VIEW so I can show/hide some custom UI in these 3D VIEWS. Basically something like "Show Overlays" switch that exists for every 3d view.

enter image description here

If I try to do something like the code below I get only read-only property that I can't change:

def register():
    bpy.types.Area.show_custom_interface = bpy.props.BoolProperty()

Is there any workaround for this? Perhaps I think about it all wrong. Any suggestions/advice super appreciated!

Thank you so much!

Maciej

--- EDIT ---

To further explain what I am trying to achieve. I just want a custom on/off switch(bool) per 3d view, so based on it's value I can show/hide my custom things (can be anything that is drawn in 3dview) in particular 3d view. Here is an example of code that adds a little mini preview in the corner of the 3dview. It works great but as you can see it puts that preview in all 3d views. How can I alter the code below to control where that mini preview would show up?

enter image description here

import bpy
import gpu
from gpu_extras.presets import draw_texture_2d

WIDTH = 512
HEIGHT = 256

offscreen = gpu.types.GPUOffScreen(WIDTH, HEIGHT)


def draw():
    context = bpy.context
    scene = context.scene

    view_matrix = scene.camera.matrix_world.inverted()

    projection_matrix = scene.camera.calc_matrix_camera(
        context.evaluated_depsgraph_get(), x=WIDTH, y=HEIGHT)

    offscreen.draw_view3d(
        scene,
        context.view_layer,
        context.space_data,
        context.region,
        view_matrix,
        projection_matrix,
        do_color_management=False)

    gpu.state.depth_mask_set(False)
    draw_texture_2d(offscreen.texture_color, (10, 10), WIDTH, HEIGHT)


bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL')
$\endgroup$
1
  • $\begingroup$ After tinkering with it a little bit more the only idea I have at a moment is to basically hijack a property that already exist and use it for my own purposes. So for example since I don't use metaballs I could hijack this property: bpy.types.SpaceView3d.show_object_viewport_meta Now this would work for my purposes, but obviously that would be an absolute HACK that also interrupts the real purpose of that property. I hope that I am missing something trivial and obvious here and there actually is a simple solution to add that custom property to Area or Space types. $\endgroup$ Commented Mar 3 at 18:09

0

You must log in to answer this question.

Browse other questions tagged .