From 12827cda7e9cd2df9f728c54a2ed7b5a065f408d Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 31 May 2023 18:42:37 +0300 Subject: [PATCH 1/5] Added preferences.py, DevProperties and STORM_HYDRA_PT_dev panel --- hydra_storm/__init__.py | 4 +++- hydra_storm/preferences.py | 30 ++++++++++++++++++++++++++++++ hydra_storm/properties.py | 19 +++++++++++++++++++ hydra_storm/ui.py | 23 ++++++++++++++++++++++- 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 hydra_storm/preferences.py diff --git a/hydra_storm/__init__.py b/hydra_storm/__init__.py index f75a59b2c..032c585af 100644 --- a/hydra_storm/__init__.py +++ b/hydra_storm/__init__.py @@ -21,16 +21,18 @@ bl_info = { } -from . import engine, properties, ui +from . import engine, properties, ui, preferences def register(): engine.register() properties.register() ui.register() + preferences.register() def unregister(): + preferences.unregister() ui.unregister() properties.unregister() engine.unregister() diff --git a/hydra_storm/preferences.py b/hydra_storm/preferences.py new file mode 100644 index 000000000..42c713073 --- /dev/null +++ b/hydra_storm/preferences.py @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright 2022, AMD + +import bpy + + +class AddonPreferences(bpy.types.AddonPreferences): + bl_idname = 'hydra_storm' + + dev_tools: bpy.props.BoolProperty( + name="Developer Tools", + description="Enable developer tools", + default=False, + ) + + def draw(self, context): + layout = self.layout + layout.prop(self, "dev_tools") + + +def addon_preferences(): + if 'hydra_storm' not in bpy.context.preferences.addons: + return None + + return bpy.context.preferences.addons['hydra_storm'].preferences + + +register, unregister = bpy.utils.register_classes_factory([ + AddonPreferences, +]) diff --git a/hydra_storm/properties.py b/hydra_storm/properties.py index 1200a5ec1..6bb5fb8b7 100644 --- a/hydra_storm/properties.py +++ b/hydra_storm/properties.py @@ -22,6 +22,22 @@ class Properties(bpy.types.PropertyGroup): del cls.bl_type.hydra_storm +class DevProperties(bpy.types.PropertyGroup): + render_data: bpy.props.EnumProperty( + name="Render Data", + description="Select data to render", + items=(('BLENDER', "Blender", "Render Blender scene"), + ('USD', "USD", "Render USD file"), + ('ALL', "All", "Render Blender scene and USD file")), + default='BLENDER', + ) + usd_file: bpy.props.StringProperty( + name="USD File", + description="Select data to render", + subtype='DIR_PATH', + ) + + class SceneProperties(Properties): bl_type = bpy.types.Scene @@ -51,7 +67,10 @@ class SceneProperties(Properties): default=16, min=0, ) + dev: bpy.props.PointerProperty(type=DevProperties) + register, unregister = bpy.utils.register_classes_factory(( + DevProperties, SceneProperties, )) diff --git a/hydra_storm/ui.py b/hydra_storm/ui.py index 7051079d3..6b9f80469 100644 --- a/hydra_storm/ui.py +++ b/hydra_storm/ui.py @@ -6,6 +6,7 @@ import bpy from .engine import StormHydraRenderEngine +from .preferences import addon_preferences class Panel(bpy.types.Panel): @@ -88,10 +89,30 @@ class STORM_HYDRA_LIGHT_PT_light(Panel): main_col.prop(light, 'size') +class STORM_HYDRA_PT_dev(Panel): + """Final render delegate and settings""" + bl_label = "Dev" + + @classmethod + def poll(cls, context): + preferences = addon_preferences() + return preferences.dev_tools if preferences else True + + def draw(self, context): + layout = self.layout + layout.use_property_split = True + layout.use_property_decorate = False + + settings = context.scene.hydra_storm.dev + layout.prop(settings, 'render_data') + if settings.render_data in ('USD', 'ALL'): + layout.prop(settings, 'usd_file') + + register_classes, unregister_classes = bpy.utils.register_classes_factory(( STORM_HYDRA_RENDER_PT_render_settings, - STORM_HYDRA_LIGHT_PT_light, + STORM_HYDRA_PT_dev, )) -- 2.30.2 From 7b0d95a0b6d89441c46407cd5c5fbf16adc5d3dc Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Wed, 31 May 2023 19:33:41 +0300 Subject: [PATCH 2/5] Updated dev settings. Added USD rendering to engine --- hydra_storm/engine.py | 29 ++++++++++++++++++++++++++++- hydra_storm/preferences.py | 3 --- hydra_storm/properties.py | 15 ++++++--------- hydra_storm/ui.py | 10 ++++++---- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/hydra_storm/engine.py b/hydra_storm/engine.py index 222ce87cc..500713bf3 100644 --- a/hydra_storm/engine.py +++ b/hydra_storm/engine.py @@ -7,6 +7,11 @@ from pathlib import Path import bpy import bpy_hydra +import _bpy_hydra + +from pxr import Usd + +from .preferences import addon_preferences class StormHydraRenderEngine(bpy_hydra.HydraRenderEngine): @@ -19,10 +24,22 @@ class StormHydraRenderEngine(bpy_hydra.HydraRenderEngine): delegate_id = 'HdStormRendererPlugin' + def __init__(self): + self._usd_stage = None + + def _sync_usd_stage(self): + preferences = addon_preferences() + dev = bpy.context.scene.hydra_storm.dev + if preferences.dev_tools and dev.render_usd and dev.usd_file: + if not self._usd_stage: + self._usd_stage = Usd.Stage.Open(dev.usd_file) + + if self._usd_stage: + _bpy_hydra.engine_sync_usd(self.engine_ptr, self._usd_stage) + @classmethod def register(cls): super().register() - bpy_hydra.register_plugins([str(Path(__file__).parent / "plugin")]) def get_render_settings(self, engine_type): @@ -35,6 +52,16 @@ class StormHydraRenderEngine(bpy_hydra.HydraRenderEngine): 'maxLights': settings.max_lights, } + def update(self, data, depsgraph): + super().update(data, depsgraph) + self._sync_usd_stage() + + def view_update(self, context, depsgraph): + super().view_update(context, depsgraph) + self._sync_usd_stage() + + + register, unregister = bpy.utils.register_classes_factory(( StormHydraRenderEngine, diff --git a/hydra_storm/preferences.py b/hydra_storm/preferences.py index 42c713073..001072a80 100644 --- a/hydra_storm/preferences.py +++ b/hydra_storm/preferences.py @@ -19,9 +19,6 @@ class AddonPreferences(bpy.types.AddonPreferences): def addon_preferences(): - if 'hydra_storm' not in bpy.context.preferences.addons: - return None - return bpy.context.preferences.addons['hydra_storm'].preferences diff --git a/hydra_storm/properties.py b/hydra_storm/properties.py index 6bb5fb8b7..0b9737a94 100644 --- a/hydra_storm/properties.py +++ b/hydra_storm/properties.py @@ -23,18 +23,15 @@ class Properties(bpy.types.PropertyGroup): class DevProperties(bpy.types.PropertyGroup): - render_data: bpy.props.EnumProperty( - name="Render Data", - description="Select data to render", - items=(('BLENDER', "Blender", "Render Blender scene"), - ('USD', "USD", "Render USD file"), - ('ALL', "All", "Render Blender scene and USD file")), - default='BLENDER', + render_usd: bpy.props.BoolProperty( + name="Render USD", + description="Render USD file with Blender scene", + default=False, ) usd_file: bpy.props.StringProperty( name="USD File", - description="Select data to render", - subtype='DIR_PATH', + description="Select USD file to render", + subtype='FILE_PATH', ) diff --git a/hydra_storm/ui.py b/hydra_storm/ui.py index 6b9f80469..cc39306d9 100644 --- a/hydra_storm/ui.py +++ b/hydra_storm/ui.py @@ -103,10 +103,12 @@ class STORM_HYDRA_PT_dev(Panel): layout.use_property_split = True layout.use_property_decorate = False - settings = context.scene.hydra_storm.dev - layout.prop(settings, 'render_data') - if settings.render_data in ('USD', 'ALL'): - layout.prop(settings, 'usd_file') + dev = context.scene.hydra_storm.dev + col = layout.column() + col.prop(dev, 'render_usd') + row = col.row() + row.enabled = dev.render_usd + row.prop(dev, 'usd_file') register_classes, unregister_classes = bpy.utils.register_classes_factory(( -- 2.30.2 From d6179c7cee865a804bd77910499a635e16f88803 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Thu, 1 Jun 2023 11:33:57 +0300 Subject: [PATCH 3/5] Improvements in render settings --- hydra_storm/ui.py | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/hydra_storm/ui.py b/hydra_storm/ui.py index 84c146778..9c8c3d287 100644 --- a/hydra_storm/ui.py +++ b/hydra_storm/ui.py @@ -26,7 +26,7 @@ class Panel(bpy.types.Panel): class STORM_HYDRA_RENDER_PT_final(Panel): """Final render delegate and settings""" bl_idname = 'STORM_HYDRA_RENDER_PT_final' - bl_label = "Storm Final Settings" + bl_label = "Final Render Settings" def draw(self, context): layout = self.layout @@ -38,25 +38,19 @@ class STORM_HYDRA_RENDER_PT_final(Panel): layout.prop(settings, 'max_lights') -class FinalPanel(bpy.types.Panel): +class STORM_HYDRA_RENDER_PT_volume_final(bpy.types.Panel): bl_parent_id = STORM_HYDRA_RENDER_PT_final.bl_idname + bl_label = "Volume Raymarching" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_options = {'DEFAULT_CLOSED'} - def settings(self, context): - return context.scene.hydra_storm.final - - -class STORM_HYDRA_RENDER_PT_volume_final(FinalPanel): - bl_label = "Volume Raymarching" - def draw(self, context): layout = self.layout layout.use_property_split = True layout.use_property_decorate = False - settings = self.settings(context) + settings = context.scene.hydra_storm.final col = layout.column(align=True) col.prop(settings, "volume_raymarching_step_size", text="Step Size") @@ -70,7 +64,7 @@ class STORM_HYDRA_RENDER_PT_volume_final(FinalPanel): class STORM_HYDRA_RENDER_PT_viewport(Panel): """Viewport render delegate and settings""" bl_idname = 'STORM_HYDRA_RENDER_PT_viewport' - bl_label = "Storm Viewport Settings" + bl_label = "Viewport Render Settings" def draw(self, context): layout = self.layout @@ -82,25 +76,19 @@ class STORM_HYDRA_RENDER_PT_viewport(Panel): layout.prop(settings, 'max_lights') -class ViewportPanel(bpy.types.Panel): +class STORM_HYDRA_RENDER_PT_volume_viewport(bpy.types.Panel): bl_parent_id = STORM_HYDRA_RENDER_PT_viewport.bl_idname + bl_label = "Volume Raymarching" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_options = {'DEFAULT_CLOSED'} - def settings(self, context): - return context.scene.hydra_storm.viewport - - -class STORM_HYDRA_RENDER_PT_volume_viewport(ViewportPanel): - bl_label = "Volume Raymarching" - def draw(self, context): layout = self.layout layout.use_property_split = True layout.use_property_decorate = False - settings = self.settings(context) + settings = context.scene.hydra_storm.viewport col = layout.column(align=True) col.prop(settings, "volume_raymarching_step_size", text="Step Size") @@ -109,9 +97,7 @@ class STORM_HYDRA_RENDER_PT_volume_viewport(ViewportPanel): class STORM_HYDRA_LIGHT_PT_light(Panel): - """ - Physical light sources - """ + """Physical light sources""" bl_label = "Light" bl_context = 'data' @@ -169,8 +155,7 @@ class STORM_HYDRA_RENDER_PT_dev(Panel): @classmethod def poll(cls, context): - preferences = addon_preferences() - return preferences.dev_tools if preferences else True + return addon_preferences().dev_tools def draw(self, context): layout = self.layout -- 2.30.2 From 25a463bb74fbe02d85ff9ed688d8815ad38280c0 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Fri, 2 Jun 2023 11:59:48 +0300 Subject: [PATCH 4/5] Fixed update by making USD file opening and syncing only once --- hydra_storm/engine.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hydra_storm/engine.py b/hydra_storm/engine.py index 038ae59cb..93e463cd3 100644 --- a/hydra_storm/engine.py +++ b/hydra_storm/engine.py @@ -28,10 +28,8 @@ class StormHydraRenderEngine(bpy_hydra.HydraRenderEngine): def _sync_usd_stage(self): preferences = addon_preferences() dev = bpy.context.scene.hydra_storm.dev - if preferences.dev_tools and dev.render_usd and dev.usd_file: - if not self._usd_stage: - self._usd_stage = Usd.Stage.Open(dev.usd_file) - + if preferences.dev_tools and not self._usd_stage and dev.render_usd and dev.usd_file: + self._usd_stage = Usd.Stage.Open(dev.usd_file) if self._usd_stage: _bpy_hydra.engine_sync_usd(self.engine_ptr, self._usd_stage) -- 2.30.2 From 70dc789cf06132fcf10b7d59859046e018be698d Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Fri, 2 Jun 2023 12:49:59 +0300 Subject: [PATCH 5/5] Fixed hiding Dev panel for other render engines --- hydra_storm/ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hydra_storm/ui.py b/hydra_storm/ui.py index 9c8c3d287..fc9e3ecb2 100644 --- a/hydra_storm/ui.py +++ b/hydra_storm/ui.py @@ -155,7 +155,7 @@ class STORM_HYDRA_RENDER_PT_dev(Panel): @classmethod def poll(cls, context): - return addon_preferences().dev_tools + return super().poll(context) and addon_preferences().dev_tools def draw(self, context): layout = self.layout -- 2.30.2