Skip to content

Commit

Permalink
blender: Update background shader in interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
vkoskiv committed Jul 1, 2024
1 parent 2f2aae4 commit fec8c25
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bindings/blender_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ def partial_update(self, depsgraph):
# Kind of annoying that seemingly every update has 'type', except if it's an
# update in the Scene datablock. I'm sure there is a good reason for this though.
if not hasattr(update.id, 'type'):
if update.id.id_type == 'MATERIAL':
update_matname = update.id.name
if update.id.id_type == 'WORLD':
self.cr_scene.set_background(convert_background(update.id.node_tree))
else:
match update.id.type:
case 'MESH':
Expand Down
30 changes: 30 additions & 0 deletions bindings/blender_ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import bpy
from bpy.types import Panel
from bpy_extras.node_utils import find_node_input

# Most of this is just a carbon-copy of the Cycles UI boilerplate

Expand Down Expand Up @@ -198,6 +199,34 @@ def draw(self, context):
sub.active = dof.focus_object is None
sub.prop(dof, "focus_distance", text="Distance")

def panel_node_draw(layout, id_data, output_type, input_name):
ntree = id_data.node_tree
node = ntree.get_output_node('CYCLES')
if node:
input = find_node_input(node, input_name)
if input:
layout.template_node_view(ntree, node, input)
else:
layout.label(text="Incompatible output node")
else:
layout.label(text="No output node")
return True

class C_RAY_WORLD_PT_surface(CrayButtonsPanel, Panel):
bl_label = "Surface"
bl_context = "world"

@classmethod
def poll(cls, context):
return context.world and CrayButtonsPanel.poll(context)

def draw(self, context):
layout = self.layout
layout.use_property_split = True
world = context.world
if not panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Surface'):
layout.prop(world, "color")

class C_RAY_CAMERA_PT_dof_aperture(CrayButtonsPanel, Panel):
bl_label = "Aperture"
bl_parent_id = "C_RAY_CAMERA_PT_dof"
Expand Down Expand Up @@ -245,6 +274,7 @@ def get_panels():
C_RAY_MATERIAL_PT_preview,
C_RAY_CAMERA_PT_dof,
C_RAY_CAMERA_PT_dof_aperture,
C_RAY_WORLD_PT_surface,
)

def register():
Expand Down

0 comments on commit fec8c25

Please sign in to comment.