Blender  V3.3
rna_world.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <float.h>
8 #include <stdlib.h>
9 
10 #include "RNA_define.h"
11 
12 #include "rna_internal.h"
13 
14 #include "DNA_material_types.h"
15 #include "DNA_texture_types.h"
16 #include "DNA_world_types.h"
17 
18 #include "WM_types.h"
19 
20 #ifdef RNA_RUNTIME
21 
22 # include "MEM_guardedalloc.h"
23 
24 # include "BKE_context.h"
25 # include "BKE_layer.h"
26 # include "BKE_main.h"
27 # include "BKE_texture.h"
28 
29 # include "DEG_depsgraph.h"
30 # include "DEG_depsgraph_build.h"
31 
32 # include "ED_node.h"
33 
34 # include "WM_api.h"
35 
36 static PointerRNA rna_World_lighting_get(PointerRNA *ptr)
37 {
38  return rna_pointer_inherit_refine(ptr, &RNA_WorldLighting, ptr->owner_id);
39 }
40 
41 static PointerRNA rna_World_mist_get(PointerRNA *ptr)
42 {
43  return rna_pointer_inherit_refine(ptr, &RNA_WorldMistSettings, ptr->owner_id);
44 }
45 
46 static void rna_World_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
47 {
48  World *wo = (World *)ptr->owner_id;
49 
50  DEG_id_tag_update(&wo->id, 0);
52 }
53 
54 # if 0
55 static void rna_World_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
56 {
57  World *wo = (World *)ptr->owner_id;
58 
59  DEG_id_tag_update(&wo->id, 0);
61 }
62 # endif
63 
64 static void rna_World_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
65 {
66  World *wo = (World *)ptr->owner_id;
67 
68  DEG_id_tag_update(&wo->id, 0);
71 }
72 
73 static void rna_World_use_nodes_update(bContext *C, PointerRNA *ptr)
74 {
75  World *wrld = (World *)ptr->data;
76  Main *bmain = CTX_data_main(C);
78 
79  if (wrld->use_nodes && wrld->nodetree == NULL) {
80  ED_node_shader_default(C, &wrld->id);
81  }
82 
84  rna_World_update(bmain, scene, ptr);
85  rna_World_draw_update(bmain, scene, ptr);
86 }
87 
88 void rna_World_lightgroup_get(PointerRNA *ptr, char *value)
89 {
90  BKE_lightgroup_membership_get(((World *)ptr->owner_id)->lightgroup, value);
91 }
92 
93 int rna_World_lightgroup_length(PointerRNA *ptr)
94 {
95  return BKE_lightgroup_membership_length(((World *)ptr->owner_id)->lightgroup);
96 }
97 
98 void rna_World_lightgroup_set(PointerRNA *ptr, const char *value)
99 {
100  BKE_lightgroup_membership_set(&((World *)ptr->owner_id)->lightgroup, value);
101 }
102 
103 #else
104 
105 static void rna_def_lighting(BlenderRNA *brna)
106 {
107  StructRNA *srna;
108  PropertyRNA *prop;
109 
110  srna = RNA_def_struct(brna, "WorldLighting", NULL);
111  RNA_def_struct_sdna(srna, "World");
112  RNA_def_struct_nested(brna, srna, "World");
113  RNA_def_struct_ui_text(srna, "Lighting", "Lighting for a World data-block");
114 
115  /* ambient occlusion */
116  prop = RNA_def_property(srna, "use_ambient_occlusion", PROP_BOOLEAN, PROP_NONE);
119  prop,
120  "Use Ambient Occlusion",
121  "Use Ambient Occlusion to add shadowing based on distance between objects");
122  RNA_def_property_update(prop, 0, "rna_World_update");
123 
124  prop = RNA_def_property(srna, "ao_factor", PROP_FLOAT, PROP_FACTOR);
125  RNA_def_property_float_sdna(prop, NULL, "aoenergy");
126  RNA_def_property_range(prop, 0, INT_MAX);
127  RNA_def_property_ui_range(prop, 0, 1, 0.1, 2);
128  RNA_def_property_ui_text(prop, "Factor", "Factor for ambient occlusion blending");
129  RNA_def_property_update(prop, 0, "rna_World_update");
130 
131  prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_DISTANCE);
132  RNA_def_property_float_sdna(prop, NULL, "aodist");
133  RNA_def_property_range(prop, 0, FLT_MAX);
135  prop, "Distance", "Length of rays, defines how far away other faces give occlusion effect");
136  RNA_def_property_update(prop, 0, "rna_World_update");
137 }
138 
139 static void rna_def_world_mist(BlenderRNA *brna)
140 {
141  StructRNA *srna;
142  PropertyRNA *prop;
143 
144  static const EnumPropertyItem falloff_items[] = {
145  {WO_MIST_QUADRATIC, "QUADRATIC", 0, "Quadratic", "Use quadratic progression"},
146  {WO_MIST_LINEAR, "LINEAR", 0, "Linear", "Use linear progression"},
148  "INVERSE_QUADRATIC",
149  0,
150  "Inverse Quadratic",
151  "Use inverse quadratic progression"},
152  {0, NULL, 0, NULL, NULL},
153  };
154 
155  srna = RNA_def_struct(brna, "WorldMistSettings", NULL);
156  RNA_def_struct_sdna(srna, "World");
157  RNA_def_struct_nested(brna, srna, "World");
158  RNA_def_struct_ui_text(srna, "World Mist", "Mist settings for a World data-block");
159 
160  prop = RNA_def_property(srna, "use_mist", PROP_BOOLEAN, PROP_NONE);
163  prop, "Use Mist", "Occlude objects with the environment color as they are further away");
164  RNA_def_property_update(prop, 0, "rna_World_draw_update");
165 
166  prop = RNA_def_property(srna, "intensity", PROP_FLOAT, PROP_NONE);
167  RNA_def_property_float_sdna(prop, NULL, "misi");
168  RNA_def_property_range(prop, 0, 1);
169  RNA_def_property_ui_text(prop, "Minimum", "Overall minimum intensity of the mist effect");
170  RNA_def_property_update(prop, 0, "rna_World_draw_update");
171 
172  prop = RNA_def_property(srna, "start", PROP_FLOAT, PROP_DISTANCE);
173  RNA_def_property_float_sdna(prop, NULL, "miststa");
174  RNA_def_property_range(prop, 0, FLT_MAX);
175  RNA_def_property_ui_range(prop, 0, 10000, 10, 2);
177  prop, "Start", "Starting distance of the mist, measured from the camera");
178  RNA_def_property_update(prop, 0, "rna_World_draw_update");
179 
180  prop = RNA_def_property(srna, "depth", PROP_FLOAT, PROP_DISTANCE);
181  RNA_def_property_float_sdna(prop, NULL, "mistdist");
182  RNA_def_property_range(prop, 0, FLT_MAX);
183  RNA_def_property_ui_range(prop, 0, 10000, 10, 2);
184  RNA_def_property_ui_text(prop, "Depth", "Distance over which the mist effect fades in");
185  RNA_def_property_update(prop, 0, "rna_World_draw_update");
186 
187  prop = RNA_def_property(srna, "height", PROP_FLOAT, PROP_DISTANCE);
188  RNA_def_property_float_sdna(prop, NULL, "misthi");
189  RNA_def_property_range(prop, 0, 100);
190  RNA_def_property_ui_text(prop, "Height", "Control how much mist density decreases with height");
191  RNA_def_property_update(prop, 0, "rna_World_update");
192 
193  prop = RNA_def_property(srna, "falloff", PROP_ENUM, PROP_NONE);
194  RNA_def_property_enum_sdna(prop, NULL, "mistype");
195  RNA_def_property_enum_items(prop, falloff_items);
196  RNA_def_property_ui_text(prop, "Falloff", "Type of transition used to fade mist");
197  RNA_def_property_update(prop, 0, "rna_World_draw_update");
198 }
199 
201 {
202  StructRNA *srna;
203  PropertyRNA *prop;
204 
205  static float default_world_color[] = {0.05f, 0.05f, 0.05f};
206 
207  srna = RNA_def_struct(brna, "World", "ID");
209  srna,
210  "World",
211  "World data-block describing the environment and ambient lighting of a scene");
212  RNA_def_struct_ui_icon(srna, ICON_WORLD_DATA);
213 
215 
216  /* colors */
217  prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
218  RNA_def_property_float_sdna(prop, NULL, "horr");
219  RNA_def_property_array(prop, 3);
220  RNA_def_property_float_array_default(prop, default_world_color);
221  RNA_def_property_ui_text(prop, "Color", "Color of the background");
222  // RNA_def_property_update(prop, 0, "rna_World_update");
223  /* render-only uses this */
224  RNA_def_property_update(prop, 0, "rna_World_draw_update");
225 
226  /* nested structs */
227  prop = RNA_def_property(srna, "light_settings", PROP_POINTER, PROP_NONE);
229  RNA_def_property_struct_type(prop, "WorldLighting");
230  RNA_def_property_pointer_funcs(prop, "rna_World_lighting_get", NULL, NULL, NULL);
231  RNA_def_property_ui_text(prop, "Lighting", "World lighting settings");
232 
233  prop = RNA_def_property(srna, "mist_settings", PROP_POINTER, PROP_NONE);
235  RNA_def_property_struct_type(prop, "WorldMistSettings");
236  RNA_def_property_pointer_funcs(prop, "rna_World_mist_get", NULL, NULL, NULL);
237  RNA_def_property_ui_text(prop, "Mist", "World mist settings");
238 
239  /* nodes */
240  prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
241  RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
244  RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node based worlds");
245 
246  prop = RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
247  RNA_def_property_boolean_sdna(prop, NULL, "use_nodes", 1);
250  RNA_def_property_ui_text(prop, "Use Nodes", "Use shader nodes to render the world");
251  RNA_def_property_update(prop, 0, "rna_World_use_nodes_update");
252 
253  /* Lightgroup Membership */
254  prop = RNA_def_property(srna, "lightgroup", PROP_STRING, PROP_NONE);
256  prop, "rna_World_lightgroup_get", "rna_World_lightgroup_length", "rna_World_lightgroup_set");
258  RNA_def_property_ui_text(prop, "Lightgroup", "Lightgroup that the world belongs to");
259 
260  rna_def_lighting(brna);
261  rna_def_world_mist(brna);
262 }
263 
264 #endif
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
void BKE_lightgroup_membership_set(struct LightgroupMembership **lgm, const char *name)
Definition: layer.c:2642
void BKE_lightgroup_membership_get(struct LightgroupMembership *lgm, char *name)
Definition: layer.c:2624
int BKE_lightgroup_membership_length(struct LightgroupMembership *lgm)
Definition: layer.c:2634
#define UNUSED(x)
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
#define WO_AMB_OCC
#define WO_MIST
@ WO_MIST_QUADRATIC
@ WO_MIST_INVERSE_QUADRATIC
@ WO_MIST_LINEAR
void ED_node_shader_default(const struct bContext *C, struct ID *id)
Read Guarded memory(de)allocation.
@ PROP_FLOAT
Definition: RNA_types.h:61
@ PROP_BOOLEAN
Definition: RNA_types.h:59
@ PROP_ENUM
Definition: RNA_types.h:63
@ PROP_STRING
Definition: RNA_types.h:62
@ PROP_POINTER
Definition: RNA_types.h:64
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition: RNA_types.h:312
@ PROP_CONTEXT_UPDATE
Definition: RNA_types.h:269
@ PROP_ANIMATABLE
Definition: RNA_types.h:202
@ PROP_EDITABLE
Definition: RNA_types.h:189
@ PROP_NEVER_NULL
Definition: RNA_types.h:239
@ PROP_PTR_NO_OWNERSHIP
Definition: RNA_types.h:257
@ PROP_DISTANCE
Definition: RNA_types.h:149
@ PROP_COLOR
Definition: RNA_types.h:153
@ PROP_NONE
Definition: RNA_types.h:126
@ PROP_FACTOR
Definition: RNA_types.h:144
#define C
Definition: RandGen.cpp:25
#define NC_WORLD
Definition: WM_types.h:337
#define ND_WORLD
Definition: WM_types.h:401
#define ND_DRAW
Definition: WM_types.h:410
#define ND_WORLD_DRAW
Definition: WM_types.h:435
#define NC_OBJECT
Definition: WM_types.h:329
Scene scene
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:186
void rna_def_animdata_common(StructRNA *srna)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2740
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
Definition: rna_define.c:2236
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
Definition: rna_define.c:3285
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1645
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1237
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1872
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1048
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1539
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
Definition: rna_define.c:1737
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1772
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2900
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1257
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1495
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
Definition: rna_define.c:3385
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1028
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2601
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
Definition: rna_define.c:1245
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1490
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2493
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
Definition: rna_define.c:1664
void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
Definition: rna_define.c:2043
void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname)
Definition: rna_define.c:1119
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
Definition: rna_define.c:1503
void RNA_def_world(BlenderRNA *brna)
Definition: rna_world.c:200
static void rna_def_world_mist(BlenderRNA *brna)
Definition: rna_world.c:139
static void rna_def_lighting(BlenderRNA *brna)
Definition: rna_world.c:105
Definition: BKE_main.h:121
void * data
Definition: RNA_types.h:38
struct ID * owner_id
Definition: RNA_types.h:36
struct bNodeTree * nodetree
short use_nodes
void WM_main_add_notifier(unsigned int type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3480