Material Preview Control in 3D View

I am looking to display the material preview for cycles, eevee, and grease pencil in the 3D View Editor, but am having trouble when adding the material preview control.

I added the preview to the panel with this:

layout.template_preview(ob.active_material)

But when I change the material index the preview doesn’t update, and when i click the add material slot button Blender crashes.

I would submit this as a bug, but I assume that these controls were only intended to be placed in the properties editor.

I am familiar with Python and the Blender Python API, but haven’t had much success working with Blenders Source?

I thought this might be a good place to start. Can someone point me in the right direction on how I would resolve this issue?

You most likely initialized the gui but it does not call its draw function when it calls it own draw function for the block.

The block is the basic gui element in Blender and in this case works as a floating panel. Or popup as Blender calls them.

I am actually in the same place, wanting to update my custom icon based GUI and looking into draw functions. I would advice to search for the similar code and see exactly how it triggers the draw update.

The preview rendering code is currently tied to the properties editor and hardcoded notifiers, and also assumes there to only exist one preview render in each editor. Search the C code for sbuts->preview to see the relevant code.

I’m not immediately sure what the right solution is.

1 Like