0
$\begingroup$

I am trying to create a simple library of procedural materials for myself.

As per my logic what I need to do is :

  1. Create a node tree in Python
  2. For preview purposes I think I will add a Data-block/New Material for the material the user has chosen and when the user changes the material just clear the previously generated material
  3. I succeeded in creating a material preview but I have not tried it with a python generated material and the major fallback is that I need to resize the preview window to refresh the preview
  4. I know that I can use tempelate_ID_preview but :
    1. It updates in at least 5 seconds.
    2. It has a bunch of unnecessary 'UI' stuff with it

My Code :

import bpy

class TESTMATPANEL(bpy.types.Panel):
    bl_idname = "panelname"
    bl_label = "Panelname"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "Testing"

    @classmethod
    def poll(cls, context):
        ntree = context.space_data.node_tree
        return ntree is not None and ntree.type=='SHADER'

    def draw(self, context):
        layout = self.layout

        row = layout.row()
        ob = context.active_object
        self.layout.template_preview(ob.active_material, show_buttons= False)

def register():

    bpy.utils.register_class(TESTMATPANEL)

def unregister():

    bpy.utils.unregister_class(TESTMATPANEL)

if __name__ == "__main__":
    register()

My method of creating a procedural Material(Nodes will be different) :

https://www.youtube.com/watch?v=8mSSCQ7LGVo

All I need to know is :

  1. How to detect the change in the material and to redraw the preview
  2. How to link the temporary material to the template_preview
  3. Pls help me

! I know that my 'Class' naming is wrong, it was just a test attempt so I didn't pay much attention

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.