|
| 1 | +extends PanelContainer |
| 2 | + |
| 3 | +@onready var preview3D := owner |
| 4 | + |
| 5 | +@onready var Tonemap := %Tonemap |
| 6 | +@onready var TonemapMode := %TonemapMode |
| 7 | +@onready var TonemapExposure := %TonemapExposure |
| 8 | +@onready var TonemapWhite := %TonemapWhite |
| 9 | + |
| 10 | +@onready var Glow := %Glow |
| 11 | +@onready var GlowBleed := %GlowBleed |
| 12 | +@onready var GlowBloom := %GlowBloom |
| 13 | +@onready var GlowIntensity := %GlowIntensity |
| 14 | +@onready var GlowStrength := %GlowStrength |
| 15 | +@onready var GlowIntensityLabel := %GlowIntensityLabel |
| 16 | +@onready var GlowBlendMode := %GlowBlendMode |
| 17 | +@onready var GlowBlendMix := %GlowBlendMix |
| 18 | +@onready var GlowBlendMixLabel := %GlowBlendMixLabel |
| 19 | +@onready var GlowThreshold := %GlowThreshold |
| 20 | +@onready var GlowClamp := %GlowClamp |
| 21 | + |
| 22 | +@onready var Adjustment := %Adjustment |
| 23 | +@onready var AdjustmentBrightness := %AdjustmentBrightness |
| 24 | +@onready var AdjustmentContrast := %AdjustmentContrast |
| 25 | +@onready var AdjustmentSaturation := %AdjustmentSaturation |
| 26 | + |
| 27 | +const SETTING_PREVIEW_TONEMAP_ENABLED := "ui_3d_preview_tonemap_enabled" |
| 28 | +const SETTING_PREVIEW_TONEMAP := "ui_3d_preview_tonemap" |
| 29 | +const SETTING_PREVIEW_TONEMAP_WHITE := "ui_3d_preview_tonemap_white" |
| 30 | +const SETTING_PREVIEW_TONEMAP_EXPOSURE := "ui_3d_preview_tonemap_exposure" |
| 31 | + |
| 32 | +const SETTING_PREVIEW_GLOW_ENABLED := "ui_3d_preview_glow_enabled" |
| 33 | +const SETTING_PREVIEW_GLOW_SIZE := "ui_3d_preview_glow_size" |
| 34 | +const SETTING_PREVIEW_GLOW_BLOOM := "ui_3d_preview_glow_bloom" |
| 35 | +const SETTING_PREVIEW_GLOW_INTENSITY := "ui_3d_preview_glow_intensity" |
| 36 | +const SETTING_PREVIEW_GLOW_STRENGTH := "ui_3d_preview_glow_strength" |
| 37 | +const SETTING_PREVIEW_GLOW_BLEND_MODE := "ui_3d_preview_glow_blend_mode" |
| 38 | +const SETTING_PREVIEW_GLOW_BLEND_MIX_FAC := "ui_3d_preview_glow_blend_mix_factor" |
| 39 | +const SETTING_PREVIEW_GLOW_LOWER_THRESHOLD := "ui_3d_preview_glow_lower_threshold" |
| 40 | +const SETTING_PREVIEW_GLOW_UPPER_THRESHOLD := "ui_3d_preview_glow_upper_threshold" |
| 41 | + |
| 42 | +const SETTING_PREVIEW_ADJUSTMENT_ENABLED := "ui_3d_preview_adjustment_enabled" |
| 43 | +const SETTING_PREVIEW_ADJUSTMENT_BRIGHTNESS := "ui_3d_preview_adjustment_brightness" |
| 44 | +const SETTING_PREVIEW_ADJUSTMENT_CONTRAST := "ui_3d_preview_adjustment_contrast" |
| 45 | +const SETTING_PREVIEW_ADJUSTMENT_SATURATION := "ui_3d_preview_adjustment_saturation" |
| 46 | + |
| 47 | +var environment : Environment |
| 48 | + |
| 49 | + |
| 50 | +func _open() -> void: |
| 51 | + pass |
| 52 | + |
| 53 | + |
| 54 | +func _ready() -> void: |
| 55 | + await preview3D.ready |
| 56 | + environment = preview3D.environment |
| 57 | + |
| 58 | + if mm_globals.has_config(SETTING_PREVIEW_TONEMAP_ENABLED): |
| 59 | + Tonemap.button_pressed = mm_globals.get_config(SETTING_PREVIEW_TONEMAP_ENABLED) |
| 60 | + restore_tonemap_settings() |
| 61 | + |
| 62 | + if mm_globals.has_config(SETTING_PREVIEW_GLOW_ENABLED): |
| 63 | + Glow.button_pressed = mm_globals.get_config(SETTING_PREVIEW_GLOW_ENABLED) |
| 64 | + environment.glow_enabled = Glow.button_pressed |
| 65 | + $VBoxContainer/GlowSection.visible = Glow.button_pressed |
| 66 | + |
| 67 | + if mm_globals.has_config(SETTING_PREVIEW_GLOW_SIZE): |
| 68 | + GlowBleed.value = mm_globals.get_config(SETTING_PREVIEW_GLOW_SIZE) |
| 69 | + environment.glow_hdr_scale = GlowBleed.value |
| 70 | + |
| 71 | + if mm_globals.has_config(SETTING_PREVIEW_GLOW_BLOOM): |
| 72 | + GlowBloom.value = mm_globals.get_config(SETTING_PREVIEW_GLOW_BLOOM) |
| 73 | + environment.glow_bloom = GlowBloom.value |
| 74 | + |
| 75 | + if mm_globals.has_config(SETTING_PREVIEW_GLOW_INTENSITY): |
| 76 | + GlowIntensity.value = mm_globals.get_config(SETTING_PREVIEW_GLOW_INTENSITY) |
| 77 | + environment.glow_intensity = GlowIntensity.value |
| 78 | + |
| 79 | + if mm_globals.has_config(SETTING_PREVIEW_GLOW_STRENGTH): |
| 80 | + GlowClamp.value = mm_globals.get_config(SETTING_PREVIEW_GLOW_STRENGTH) |
| 81 | + environment.glow_strength = GlowStrength.value |
| 82 | + |
| 83 | + if mm_globals.has_config(SETTING_PREVIEW_GLOW_BLEND_MODE): |
| 84 | + GlowBlendMode.selected = mm_globals.get_config(SETTING_PREVIEW_GLOW_BLEND_MODE) |
| 85 | + environment.glow_blend_mode = GlowBlendMode.selected |
| 86 | + GlowBlendMix.visible = GlowBlendMode.selected == Environment.GLOW_BLEND_MODE_MIX |
| 87 | + GlowBlendMixLabel.visible = GlowBlendMode.selected == Environment.GLOW_BLEND_MODE_MIX |
| 88 | + GlowIntensity.visible = GlowBlendMode.selected != Environment.GLOW_BLEND_MODE_MIX |
| 89 | + GlowIntensityLabel.visible = GlowBlendMode.selected != Environment.GLOW_BLEND_MODE_MIX |
| 90 | + |
| 91 | + if mm_globals.has_config(SETTING_PREVIEW_GLOW_BLEND_MIX_FAC): |
| 92 | + GlowBlendMix.value = mm_globals.get_config(SETTING_PREVIEW_GLOW_BLEND_MIX_FAC) |
| 93 | + environment.glow_mix = GlowBlendMix.value |
| 94 | + |
| 95 | + if mm_globals.has_config(SETTING_PREVIEW_GLOW_LOWER_THRESHOLD): |
| 96 | + GlowThreshold.value = mm_globals.get_config(SETTING_PREVIEW_GLOW_LOWER_THRESHOLD) |
| 97 | + environment.glow_hdr_threshold = GlowThreshold.value |
| 98 | + |
| 99 | + if mm_globals.has_config(SETTING_PREVIEW_GLOW_UPPER_THRESHOLD): |
| 100 | + GlowClamp.value = mm_globals.get_config(SETTING_PREVIEW_GLOW_UPPER_THRESHOLD) |
| 101 | + environment.glow_hdr_luminance_cap = GlowClamp.value |
| 102 | + |
| 103 | + if mm_globals.has_config(SETTING_PREVIEW_ADJUSTMENT_ENABLED): |
| 104 | + Adjustment.button_pressed = mm_globals.get_config(SETTING_PREVIEW_ADJUSTMENT_ENABLED) |
| 105 | + environment.adjustment_enabled = Adjustment.button_pressed |
| 106 | + $VBoxContainer/AdjustmentSection.visible = Adjustment.button_pressed |
| 107 | + |
| 108 | + if mm_globals.has_config(SETTING_PREVIEW_ADJUSTMENT_BRIGHTNESS): |
| 109 | + AdjustmentBrightness.value = mm_globals.get_config(SETTING_PREVIEW_ADJUSTMENT_BRIGHTNESS) |
| 110 | + environment.adjustment_brightness = AdjustmentBrightness.value |
| 111 | + |
| 112 | + if mm_globals.has_config(SETTING_PREVIEW_ADJUSTMENT_CONTRAST): |
| 113 | + AdjustmentContrast.value = mm_globals.get_config(SETTING_PREVIEW_ADJUSTMENT_CONTRAST) |
| 114 | + environment.adjustment_contrast = AdjustmentContrast.value |
| 115 | + |
| 116 | + if mm_globals.has_config(SETTING_PREVIEW_ADJUSTMENT_SATURATION): |
| 117 | + AdjustmentSaturation.value = mm_globals.get_config(SETTING_PREVIEW_ADJUSTMENT_SATURATION) |
| 118 | + environment.adjustment_saturation = AdjustmentSaturation.value |
| 119 | + |
| 120 | + |
| 121 | +func _on_minimum_size_changed() -> void: |
| 122 | + size = get_combined_minimum_size() |
| 123 | + |
| 124 | + |
| 125 | +func _on_glow_blending_item_selected(index: int) -> void: |
| 126 | + environment.glow_blend_mode = index |
| 127 | + mm_globals.set_config(SETTING_PREVIEW_GLOW_BLEND_MODE, index) |
| 128 | + GlowBlendMix.visible = index == Environment.GLOW_BLEND_MODE_MIX |
| 129 | + GlowBlendMixLabel.visible = index == Environment.GLOW_BLEND_MODE_MIX |
| 130 | + GlowIntensity.visible = GlowBlendMode.selected != Environment.GLOW_BLEND_MODE_MIX |
| 131 | + GlowIntensityLabel.visible = GlowBlendMode.selected != Environment.GLOW_BLEND_MODE_MIX |
| 132 | + |
| 133 | + |
| 134 | +func _on_glow_blend_mix_value_changed(value: Variant) -> void: |
| 135 | + environment.glow_mix = value |
| 136 | + mm_globals.set_config(SETTING_PREVIEW_GLOW_BLEND_MIX_FAC, value) |
| 137 | + |
| 138 | + |
| 139 | +func _on_glow_size_value_changed(value: Variant) -> void: |
| 140 | + environment.glow_hdr_scale = value |
| 141 | + mm_globals.set_config(SETTING_PREVIEW_GLOW_SIZE, value) |
| 142 | + |
| 143 | + |
| 144 | +func _on_glow_toggled(toggled_on: bool) -> void: |
| 145 | + environment.glow_enabled = toggled_on |
| 146 | + $VBoxContainer/GlowSection.visible = Glow.button_pressed |
| 147 | + mm_globals.set_config(SETTING_PREVIEW_GLOW_ENABLED, toggled_on) |
| 148 | + |
| 149 | + |
| 150 | +func _on_glow_bloom_value_changed(value: Variant) -> void: |
| 151 | + environment.glow_bloom = value |
| 152 | + mm_globals.set_config(SETTING_PREVIEW_GLOW_BLOOM, value) |
| 153 | + |
| 154 | + |
| 155 | +func _on_glow_intensity_value_changed(value: Variant) -> void: |
| 156 | + environment.glow_intensity = value |
| 157 | + mm_globals.set_config(SETTING_PREVIEW_GLOW_INTENSITY, value) |
| 158 | + |
| 159 | + |
| 160 | +func _on_glow_threshold_value_changed(value: Variant) -> void: |
| 161 | + environment.glow_hdr_threshold = value |
| 162 | + mm_globals.set_config(SETTING_PREVIEW_GLOW_LOWER_THRESHOLD, value) |
| 163 | + |
| 164 | + |
| 165 | +func _on_glow_clamp_value_changed(value: Variant) -> void: |
| 166 | + environment.glow_hdr_luminance_cap = value |
| 167 | + mm_globals.set_config(SETTING_PREVIEW_GLOW_UPPER_THRESHOLD, value) |
| 168 | + |
| 169 | + |
| 170 | +func _on_glow_strength_value_changed(value: Variant) -> void: |
| 171 | + environment.glow_strength = value |
| 172 | + mm_globals.set_config(SETTING_PREVIEW_GLOW_STRENGTH, value) |
| 173 | + |
| 174 | + |
| 175 | +func _on_adjustment_toggled(toggled_on: bool) -> void: |
| 176 | + environment.adjustment_enabled = toggled_on |
| 177 | + $VBoxContainer/AdjustmentSection.visible = toggled_on |
| 178 | + mm_globals.set_config(SETTING_PREVIEW_ADJUSTMENT_ENABLED, toggled_on) |
| 179 | + |
| 180 | + |
| 181 | +func _on_adjustment_brightness_value_changed(value: Variant) -> void: |
| 182 | + environment.adjustment_brightness = value |
| 183 | + mm_globals.set_config(SETTING_PREVIEW_ADJUSTMENT_BRIGHTNESS, value) |
| 184 | + |
| 185 | + |
| 186 | +func _on_adjustment_contrast_value_changed(value: Variant) -> void: |
| 187 | + environment.adjustment_contrast = value |
| 188 | + mm_globals.set_config(SETTING_PREVIEW_ADJUSTMENT_CONTRAST, value) |
| 189 | + |
| 190 | + |
| 191 | +func _on_adjustment_saturation_value_changed(value: Variant) -> void: |
| 192 | + environment.adjustment_saturation = value |
| 193 | + mm_globals.set_config(SETTING_PREVIEW_ADJUSTMENT_SATURATION, value) |
| 194 | + |
| 195 | + |
| 196 | +func restore_tonemap_settings() -> void: |
| 197 | + if Tonemap.button_pressed: |
| 198 | + if mm_globals.has_config(SETTING_PREVIEW_TONEMAP): |
| 199 | + TonemapMode.selected = mm_globals.get_config(SETTING_PREVIEW_TONEMAP) |
| 200 | + environment.tonemap_mode = TonemapMode.selected |
| 201 | + |
| 202 | + if mm_globals.has_config(SETTING_PREVIEW_TONEMAP_EXPOSURE): |
| 203 | + TonemapExposure.value = mm_globals.get_config(SETTING_PREVIEW_TONEMAP_EXPOSURE) |
| 204 | + environment.tonemap_exposure = TonemapExposure.value |
| 205 | + |
| 206 | + if mm_globals.has_config(SETTING_PREVIEW_TONEMAP_WHITE): |
| 207 | + TonemapWhite.value = mm_globals.get_config(SETTING_PREVIEW_TONEMAP_WHITE) |
| 208 | + environment.tonemap_white = TonemapWhite.value |
| 209 | + |
| 210 | +func _on_tonemap_toggled(toggled_on: bool) -> void: |
| 211 | + $VBoxContainer/TonemapSection.visible = toggled_on |
| 212 | + mm_globals.set_config(SETTING_PREVIEW_TONEMAP_ENABLED, toggled_on) |
| 213 | + if not toggled_on: |
| 214 | + environment.tonemap_mode = Environment.TONE_MAPPER_LINEAR |
| 215 | + environment.tonemap_exposure = 1.0 |
| 216 | + environment.tonemap_white = 1.0 |
| 217 | + else: |
| 218 | + restore_tonemap_settings() |
| 219 | + |
| 220 | + |
| 221 | +func _on_tone_map_item_selected(index: int) -> void: |
| 222 | + environment.tonemap_mode = index |
| 223 | + mm_globals.set_config(SETTING_PREVIEW_TONEMAP, index) |
| 224 | + |
| 225 | + |
| 226 | +func _on_tonemap_white_value_changed(value: Variant) -> void: |
| 227 | + environment.tonemap_white = value |
| 228 | + mm_globals.set_config(SETTING_PREVIEW_TONEMAP_WHITE, value) |
| 229 | + |
| 230 | + |
| 231 | +func _on_tonemap_exposure_value_changed(value: Variant) -> void: |
| 232 | + environment.tonemap_exposure = value |
| 233 | + mm_globals.set_config(SETTING_PREVIEW_TONEMAP_EXPOSURE, value) |
0 commit comments