material refresh feature

metadata
Wenzel Jakob 2010-11-17 10:12:23 +01:00
parent ada5d996a3
commit 3085d5ebb7
4 changed files with 61 additions and 7 deletions

View File

@ -20,21 +20,75 @@ import bpy
from properties_material import MaterialButtonsPanel
from extensions_framework.ui import property_group_renderer
from mitsuba.outputs import MtsLog
material_cache = {}
class mitsuba_material_base(MaterialButtonsPanel, property_group_renderer):
COMPAT_ENGINES = {'mitsuba'}
MTS_PROPS = ['type']
def draw(self, context):
mat = context.material.mitsuba_material
if mat.name in material_cache:
mat_cached = material_cache[mat.name]
else:
mat_cached = {}
material_cache[mat.name] = mat_cached
repaint = False
for prop in self.MTS_PROPS:
prop_value = getattr(mat, prop)
prop_cache_value = mat_cached[prop] if prop in mat_cached else None
if prop_cache_value != prop_value:
mat_cached[prop] = prop_value
repaint = True
if repaint:
# Cause a repaint
MtsLog("Forcing a repaint")
context.material.preview_render_type = context.material.preview_render_type
return super().draw(context)
class mitsuba_material_sub(MaterialButtonsPanel, property_group_renderer):
COMPAT_ENGINES = {'mitsuba'}
MTS_COMPAT = set()
MTS_PROPS = []
@classmethod
def poll(cls, context):
'''
Only show Mitsuba panel if mitsuba_material.material in MTS_COMPAT
'''
return super().poll(context) and context.material.mitsuba_material.type in cls.MTS_COMPAT
return super().poll(context) and context and context.material \
and context.material.mitsuba_material \
and context.material.mitsuba_material.type in cls.MTS_COMPAT
def draw(self, context):
mat = context.material.mitsuba_material
sub_type = getattr(bpy.types, 'mitsuba_mat_%s' % mat.type)
mat = getattr(mat, 'mitsuba_mat_%s' % mat.type)
if mat.name in material_cache:
mat_cached = material_cache[mat.name]
else:
mat_cached = {}
material_cache[mat.name] = mat_cached
props = sub_type.get_exportable_properties()
repaint = False
for prop_entry in props:
prop = prop_entry['attr']
prop_value = getattr(mat, prop) if hasattr(mat, prop) else None
prop_cache_value = mat_cached[prop] if prop in mat_cached else None
if prop_cache_value != prop_value:
mat_cached[prop] = prop_value
repaint = True
if repaint:
# Cause a repaint
MtsLog("Forcing a repaint")
context.material.preview_render_type = context.material.preview_render_type
return super().draw(context)
class MATERIAL_PT_context_material_mts(MaterialButtonsPanel, bpy.types.Panel):
bl_label = ""

View File

@ -25,7 +25,7 @@ class ui_material_composite(mitsuba_material_sub, bpy.types.Panel):
bl_label = 'Mitsuba Composite Material'
MTS_COMPAT = {'composite'}
display_property_groups = [
( ('material', 'mitsuba_material'), 'mitsuba_mat_composite' )
]

View File

@ -35,6 +35,6 @@ class emission(mitsuba_material_base, bpy.types.Panel):
def draw_header(self, context):
mat = active_node_mat(context.material)
self.layout.prop(mat.mitsuba_emission, "use_emission", text="")
if context.material:
mat = active_node_mat(context.material)
self.layout.prop(mat.mitsuba_emission, "use_emission", text="")

View File

@ -24,7 +24,7 @@ class ui_material_phong(mitsuba_material_sub, bpy.types.Panel):
bl_label = 'Mitsuba Phong Material'
MTS_COMPAT = {'phong'}
display_property_groups = [
( ('material', 'mitsuba_material'), 'mitsuba_mat_phong' )
]