initial medium support
parent
dd8c361b9e
commit
cd6d3f8a65
|
@ -32,11 +32,11 @@ from ..export import (get_instance_materials,
|
|||
resolution, MtsLaunch, MtsExporter)
|
||||
|
||||
from ..properties import (
|
||||
engine, sampler, integrator, lamp, texture, material
|
||||
engine, sampler, integrator, lamp, texture, material, world
|
||||
);
|
||||
|
||||
from ..ui import (
|
||||
render_panels, lamps, materials
|
||||
render_panels, lamps, materials, world
|
||||
)
|
||||
|
||||
from ..ui.textures import (
|
||||
|
|
|
@ -258,3 +258,56 @@ class MITSUBA_OT_convert_material(bpy.types.Operator):
|
|||
|
||||
material_converter(self.report, context.scene, blender_mat)
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
@MitsubaAddon.addon_register_class
|
||||
class MITSUBA_MT_presets_medium(MITSUBA_MT_base):
|
||||
bl_label = "Mitsuba Medium Presets"
|
||||
preset_subdir = "mitsuba/medium"
|
||||
|
||||
@MitsubaAddon.addon_register_class
|
||||
class MITSUBA_OT_preset_medium_add(bl_operators.presets.AddPresetBase, bpy.types.Operator):
|
||||
'''Save the current settings as a preset'''
|
||||
bl_idname = 'mitsuba.preset_medium_add'
|
||||
bl_label = 'Add Mitsuba Medium settings preset'
|
||||
preset_menu = 'MITSUBA_MT_presets_medium'
|
||||
preset_values = []
|
||||
preset_subdir = 'mitsuba/medium'
|
||||
|
||||
def execute(self, context):
|
||||
ks = 'bpy.context.scene.mitsuba_media.media[bpy.context.scene.mitsuba_media.media_index].%s'
|
||||
pv = [
|
||||
ks%v['attr'] for v in bpy.types.mitsuba_medium_data.get_exportable_properties()
|
||||
]
|
||||
|
||||
self.preset_values = pv
|
||||
return super().execute(context)
|
||||
|
||||
@MitsubaAddon.addon_register_class
|
||||
class MITSUBA_OT_medium_add(bpy.types.Operator):
|
||||
'''Add a new medium definition to the scene'''
|
||||
|
||||
bl_idname = "mitsuba.medium_add"
|
||||
bl_label = "Add Mitsuba Medium"
|
||||
|
||||
new_medium_name = bpy.props.StringProperty(default='New Medium')
|
||||
|
||||
def invoke(self, context, event):
|
||||
v = context.scene.mitsuba_media.media
|
||||
v.add()
|
||||
new_vol = v[len(v)-1]
|
||||
new_vol.name = self.properties.new_medium_name
|
||||
return {'FINISHED'}
|
||||
|
||||
@MitsubaAddon.addon_register_class
|
||||
class MITSUBA_OT_medium_remove(bpy.types.Operator):
|
||||
'''Remove the selected medium definition'''
|
||||
|
||||
bl_idname = "mitsuba.medium_remove"
|
||||
bl_label = "Remove Mitsuba Medium"
|
||||
|
||||
def invoke(self, context, event):
|
||||
w = context.scene.mitsuba_media
|
||||
w.media.remove( w.media_index )
|
||||
w.media_index = len(w.media)-1
|
||||
return {'FINISHED'}
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
# ##### BEGIN GPL LICENSE BLOCK #####
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
from .. import MitsubaAddon
|
||||
|
||||
from extensions_framework import declarative_property_group
|
||||
|
||||
def WorldMediumParameter(attr, name):
|
||||
return [
|
||||
{
|
||||
'attr': '%s_medium' % attr,
|
||||
'type': 'string',
|
||||
'name': '%s_medium' % attr,
|
||||
'description': '%s_medium' % attr,
|
||||
'save_in_preset': True
|
||||
},
|
||||
{
|
||||
'type': 'prop_search',
|
||||
'attr': attr,
|
||||
'src': lambda s,c: s.scene.mitsuba_media,
|
||||
'src_attr': 'media',
|
||||
'trg': lambda s,c: c.mitsuba_world,
|
||||
'trg_attr': '%s_medium' % attr,
|
||||
'name': name
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@MitsubaAddon.addon_register_class
|
||||
class mitsuba_medium_data(declarative_property_group):
|
||||
'''
|
||||
Storage class for Mitsuba medium data. The
|
||||
mitsuba_media object will store 1 or more of
|
||||
these in its CollectionProperty 'media'.
|
||||
'''
|
||||
|
||||
ef_attach_to = [] # not attached
|
||||
|
||||
controls = [
|
||||
'type', 'g'
|
||||
]
|
||||
|
||||
properties = [
|
||||
{
|
||||
'type': 'enum',
|
||||
'attr': 'type',
|
||||
'name': 'Type',
|
||||
'items': [
|
||||
('homogeneous', 'Homogeneous', 'homogeneous'),
|
||||
('heterogeneous', 'Heterogeneous', 'heterogeneous'),
|
||||
],
|
||||
'save_in_preset': True
|
||||
},
|
||||
{
|
||||
'type': 'float',
|
||||
'attr': 'g',
|
||||
'name': 'Asymmetry',
|
||||
'description': 'Scattering asymmetry RGB. -1 means back-scattering, 0 is isotropic, 1 is forwards scattering.',
|
||||
'default': 0.0,
|
||||
'min': -1.0,
|
||||
'soft_min': -1.0,
|
||||
'max': 1.0,
|
||||
'soft_max': 1.0,
|
||||
'precision': 4,
|
||||
'save_in_preset': True
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@MitsubaAddon.addon_register_class
|
||||
class mitsuba_media(declarative_property_group):
|
||||
'''
|
||||
Storage class for Mitsuba Material media.
|
||||
'''
|
||||
|
||||
ef_attach_to = ['Scene']
|
||||
|
||||
controls = [
|
||||
'media_select',
|
||||
['op_vol_add', 'op_vol_rem']
|
||||
]
|
||||
|
||||
visibility = {}
|
||||
|
||||
properties = [
|
||||
{
|
||||
'type': 'collection',
|
||||
'ptype': mitsuba_medium_data,
|
||||
'name': 'media',
|
||||
'attr': 'media',
|
||||
'items': [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
'type': 'int',
|
||||
'name': 'media_index',
|
||||
'attr': 'media_index',
|
||||
},
|
||||
{
|
||||
'type': 'template_list',
|
||||
'name': 'media_select',
|
||||
'attr': 'media_select',
|
||||
'trg': lambda sc,c: c.mitsuba_media,
|
||||
'trg_attr': 'media_index',
|
||||
'src': lambda sc,c: c.mitsuba_media,
|
||||
'src_attr': 'media',
|
||||
},
|
||||
{
|
||||
'type': 'operator',
|
||||
'attr': 'op_vol_add',
|
||||
'operator': 'mitsuba.medium_add',
|
||||
'text': 'Add',
|
||||
'icon': 'ZOOMIN',
|
||||
},
|
||||
{
|
||||
'type': 'operator',
|
||||
'attr': 'op_vol_rem',
|
||||
'operator': 'mitsuba.medium_remove',
|
||||
'text': 'Remove',
|
||||
'icon': 'ZOOMOUT',
|
||||
},
|
||||
]
|
|
@ -0,0 +1,67 @@
|
|||
# ##### BEGIN GPL LICENSE BLOCK #####
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
import bpy, bl_ui
|
||||
|
||||
from .. import MitsubaAddon
|
||||
|
||||
from extensions_framework.ui import property_group_renderer
|
||||
|
||||
class world_panel(bl_ui.properties_world.WorldButtonsPanel, property_group_renderer):
|
||||
COMPAT_ENGINES = { MitsubaAddon.BL_IDNAME }
|
||||
|
||||
@MitsubaAddon.addon_register_class
|
||||
class media(world_panel):
|
||||
'''
|
||||
Participating Media Settings
|
||||
'''
|
||||
|
||||
bl_label = 'Mitsuba Media'
|
||||
|
||||
display_property_groups = [
|
||||
( ('scene',), 'mitsuba_media' )
|
||||
]
|
||||
|
||||
def draw(self, context):
|
||||
super().draw(context)
|
||||
|
||||
if context.world:
|
||||
row = self.layout.row(align=True)
|
||||
row.menu("MITSUBA_MT_presets_medium", text=bpy.types.MITSUBA_MT_presets_medium.bl_label)
|
||||
row.operator("mitsuba.preset_medium_add", text="", icon="ZOOMIN")
|
||||
row.operator("mitsuba.preset_medium_add", text="", icon="ZOOMOUT").remove_active = True
|
||||
|
||||
if len(context.scene.mitsuba_media.media) > 0:
|
||||
current_vol_ind = context.scene.mitsuba_media.media_index
|
||||
current_vol = context.scene.mitsuba_media.media[current_vol_ind]
|
||||
# 'name' is not a member of current_vol.properties,
|
||||
# so we draw it explicitly
|
||||
self.layout.prop(
|
||||
current_vol, 'name'
|
||||
)
|
||||
# Here we draw the currently selected mitsuba_media_data property group
|
||||
for control in current_vol.controls:
|
||||
self.draw_column(
|
||||
control,
|
||||
self.layout,
|
||||
current_vol,
|
||||
context,
|
||||
property_group = current_vol
|
||||
)
|
||||
else:
|
||||
self.layout.label('No active World available!')
|
Loading…
Reference in New Issue