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