Blender V4.3
viewport.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "blender/viewport.h"
6#include "blender/util.h"
7
8#include "scene/pass.h"
9
10#include "util/log.h"
11
13
15 : use_scene_world(true),
16 use_scene_lights(true),
17 studiolight_rotate_z(0.0f),
18 studiolight_intensity(1.0f),
19 studiolight_background_alpha(1.0f),
20 display_pass(PASS_COMBINED),
21 show_active_pixels(false)
22{
23}
24
25BlenderViewportParameters::BlenderViewportParameters(BL::SpaceView3D &b_v3d, bool use_developer_ui)
27{
28 if (!b_v3d) {
29 return;
30 }
31
32 BL::View3DShading shading = b_v3d.shading();
33 PointerRNA cshading = RNA_pointer_get(&shading.ptr, "cycles");
34
35 /* We only copy the shading parameters if we are in look-dev mode.
36 * Otherwise defaults are being used. These defaults mimic normal render settings. */
37 if (shading.type() == BL::View3DShading::type_RENDERED) {
38 use_scene_world = shading.use_scene_world_render();
39 use_scene_lights = shading.use_scene_lights_render();
40
41 if (!use_scene_world) {
42 studiolight_rotate_z = shading.studiolight_rotate_z();
43 studiolight_intensity = shading.studiolight_intensity();
44 studiolight_background_alpha = shading.studiolight_background_alpha();
45 studiolight_path = shading.selected_studio_light().path();
46 }
47 }
48
49 /* Film. */
50
51 /* Lookup display pass based on the enum identifier.
52 * This is because integer values of python enum are not aligned with the passes definition in
53 * the kernel. */
54
56
57 const string display_pass_identifier = get_enum_identifier(cshading, "render_pass");
58 if (!display_pass_identifier.empty()) {
59 const ustring pass_type_identifier(string_to_lower(display_pass_identifier));
60 const NodeEnum *pass_type_enum = Pass::get_type_enum();
61 if (pass_type_enum->exists(pass_type_identifier)) {
62 display_pass = static_cast<PassType>((*pass_type_enum)[pass_type_identifier]);
63 }
64 }
65
66 if (use_developer_ui) {
67 show_active_pixels = get_boolean(cshading, "show_active_pixels");
68 }
69}
70
72{
73 return use_scene_world != other.use_scene_world || use_scene_lights != other.use_scene_lights ||
74 studiolight_rotate_z != other.studiolight_rotate_z ||
75 studiolight_intensity != other.studiolight_intensity ||
76 studiolight_background_alpha != other.studiolight_background_alpha ||
77 studiolight_path != other.studiolight_path;
78}
79
81{
82 return display_pass != other.display_pass || show_active_pixels != other.show_active_pixels;
83}
84
86{
87 return shader_modified(other) || film_modified(other);
88}
89
94
bool shader_modified(const BlenderViewportParameters &other) const
Definition viewport.cpp:71
bool film_modified(const BlenderViewportParameters &other) const
Definition viewport.cpp:80
bool use_custom_shader() const
Definition viewport.cpp:90
bool modified(const BlenderViewportParameters &other) const
Definition viewport.cpp:85
static const NodeEnum * get_type_enum()
Definition pass.cpp:45
static bool get_boolean(PointerRNA &ptr, const char *name)
static string get_enum_identifier(PointerRNA &ptr, const char *name)
#define CCL_NAMESPACE_END
PassType
@ PASS_COMBINED
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
string string_to_lower(const string &s)
Definition string.cpp:190
bool exists(ustring x) const
Definition node_enum.h:29