From f0619c0a561e8a5819a1be4a04908d6636281b79 Mon Sep 17 00:00:00 2001 From: Valtteri Koskivuori Date: Wed, 20 Dec 2023 21:08:31 +0200 Subject: [PATCH] blender: Enable material preview in UI It's not fully working yet. It does render the preview, but for some reason, all the preview objects are shown overlapping at once. I haven't found the flag that blender uses to hide the extra meshes yet. --- bindings/blender_init.py | 2 +- bindings/blender_ui.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bindings/blender_init.py b/bindings/blender_init.py index 5dcf464c..f12318b6 100644 --- a/bindings/blender_init.py +++ b/bindings/blender_init.py @@ -147,7 +147,7 @@ def dump(obj): class CrayRender(bpy.types.RenderEngine): bl_idname = "C_RAY" bl_label = "c-ray for Blender" - bl_use_preview = False + bl_use_preview = True bl_use_shading_nodes_custom = False def __init__(self): diff --git a/bindings/blender_ui.py b/bindings/blender_ui.py index 6b2fa379..7f94c98a 100644 --- a/bindings/blender_ui.py +++ b/bindings/blender_ui.py @@ -91,6 +91,19 @@ def draw(self, context): col = layout.column() col.prop(context.scene.c_ray, "bounces", text="Total") +class C_RAY_MATERIAL_PT_preview(CrayButtonsPanel, Panel): + bl_label = "Preview" + bl_context = "material" + bl_options = {'DEFAULT_CLOSED'} + + @classmethod + def poll(cls, context): + mat = context.material + return mat and (not mat.grease_pencil) and CrayButtonsPanel.poll(context) + + def draw(self, context): + self.layout.template_preview(context.material) + class C_RAY_CAMERA_PT_dof(CrayButtonsPanel, Panel): bl_label = "Depth of Field" bl_context = "data" @@ -165,6 +178,7 @@ def get_panels(): C_RAY_RENDER_PT_performance_clustering, C_RAY_RENDER_PT_light_paths, C_RAY_RENDER_PT_light_paths_bounces, + C_RAY_MATERIAL_PT_preview, C_RAY_CAMERA_PT_dof, C_RAY_CAMERA_PT_dof_aperture, )