Add possibility to render USD file for testing purposes #14

Merged
Bogdan Nagirniak merged 6 commits from BLEN-428 into storm-hydra-addon 2023-06-02 15:55:44 +02:00
4 changed files with 40 additions and 17 deletions
Showing only changes of commit 7b0d95a0b6 - Show all commits

View File

@ -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,

View File

@ -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

View File

@ -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',
)

View File

@ -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((