I am trying to create a simple library of procedural materials for myself.
As per my logic what I need to do is :
- Create a node tree in Python
- 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
- 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
- I know that I can use
- It updates in at least 5 seconds.
- 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) :
All I need to know is :
- How to detect the change in the material and to redraw the preview
- How to link the temporary material to the
- Pls help me
! I know that my 'Class' naming is wrong, it was just a test attempt so I didn't pay much attention