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
tempelate_ID_preview
but :
- 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) :
https://www.youtube.com/watch?v=8mSSCQ7LGVo
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
template_preview
- Pls help me
! I know that my 'Class' naming is wrong, it was just a test attempt so I didn't pay much attention