Blender  V2.93
blender_viewport.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "blender_viewport.h"
17 
18 #include "blender_util.h"
19 
21 
22 BlenderViewportParameters::BlenderViewportParameters()
23  : use_scene_world(true),
24  use_scene_lights(true),
25  studiolight_rotate_z(0.0f),
26  studiolight_intensity(1.0f),
27  studiolight_background_alpha(1.0f),
28  studiolight_path(ustring())
29 {
30 }
31 
32 BlenderViewportParameters::BlenderViewportParameters(BL::SpaceView3D &b_v3d)
34 {
35  /* We only copy the parameters if we are in look dev mode. otherwise
36  * defaults are being used. These defaults mimic normal render settings */
37  if (b_v3d && b_v3d.shading().type() == BL::View3DShading::type_RENDERED) {
38  use_scene_world = b_v3d.shading().use_scene_world_render();
39  use_scene_lights = b_v3d.shading().use_scene_lights_render();
40  if (!use_scene_world) {
41  studiolight_rotate_z = b_v3d.shading().studiolight_rotate_z();
42  studiolight_intensity = b_v3d.shading().studiolight_intensity();
43  studiolight_background_alpha = b_v3d.shading().studiolight_background_alpha();
44  studiolight_path = b_v3d.shading().selected_studio_light().path();
45  }
46  }
47 }
48 
49 /* Check if two instances are different. */
50 const bool BlenderViewportParameters::modified(const BlenderViewportParameters &other) const
51 {
52  return use_scene_world != other.use_scene_world || use_scene_lights != other.use_scene_lights ||
53  studiolight_rotate_z != other.studiolight_rotate_z ||
54  studiolight_intensity != other.studiolight_intensity ||
55  studiolight_background_alpha != other.studiolight_background_alpha ||
56  studiolight_path != other.studiolight_path;
57 }
58 
59 const bool BlenderViewportParameters::custom_viewport_parameters() const
60 {
61  return !(use_scene_world && use_scene_lights);
62 }
63 
65 {
66  PassType display_pass = PASS_NONE;
67  if (b_v3d) {
68  BL::View3DShading b_view3dshading = b_v3d.shading();
69  PointerRNA cshading = RNA_pointer_get(&b_view3dshading.ptr, "cycles");
70  display_pass = (PassType)get_enum(cshading, "render_pass", -1, -1);
71  }
72  return display_pass;
73 }
74 
75 PassType update_viewport_display_passes(BL::SpaceView3D &b_v3d, vector<Pass> &passes)
76 {
77  if (b_v3d) {
79 
80  passes.clear();
81  Pass::add(display_pass, passes);
82 
83  return display_pass;
84  }
85  return PASS_NONE;
86 }
87 
struct View3DShading View3DShading
static int get_enum(PointerRNA &ptr, const char *name, int num_values=-1, int default_value=-1)
Definition: blender_util.h:386
PassType update_viewport_display_passes(BL::SpaceView3D &b_v3d, vector< Pass > &passes)
static PassType get_viewport_display_render_pass(BL::SpaceView3D &b_v3d)
static void add(PassType type, vector< Pass > &passes, const char *name=NULL)
Definition: film.cpp:103
#define CCL_NAMESPACE_END
PassType
Definition: kernel_types.h:347
@ PASS_NONE
Definition: kernel_types.h:348
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6562