Blender  V2.93
rna_world.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include <float.h>
22 #include <stdlib.h>
23 
24 #include "RNA_define.h"
25 
26 #include "rna_internal.h"
27 
28 #include "DNA_material_types.h"
29 #include "DNA_texture_types.h"
30 #include "DNA_world_types.h"
31 
32 #include "WM_types.h"
33 
34 #ifdef RNA_RUNTIME
35 
36 # include "MEM_guardedalloc.h"
37 
38 # include "BKE_context.h"
39 # include "BKE_main.h"
40 # include "BKE_texture.h"
41 
42 # include "DEG_depsgraph.h"
43 # include "DEG_depsgraph_build.h"
44 
45 # include "ED_node.h"
46 
47 # include "WM_api.h"
48 
49 static PointerRNA rna_World_lighting_get(PointerRNA *ptr)
50 {
52 }
53 
54 static PointerRNA rna_World_mist_get(PointerRNA *ptr)
55 {
57 }
58 
59 static void rna_World_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
60 {
61  World *wo = (World *)ptr->owner_id;
62 
63  DEG_id_tag_update(&wo->id, 0);
65 }
66 
67 # if 0
68 static void rna_World_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
69 {
70  World *wo = (World *)ptr->owner_id;
71 
72  DEG_id_tag_update(&wo->id, 0);
74 }
75 # endif
76 
77 static void rna_World_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
78 {
79  World *wo = (World *)ptr->owner_id;
80 
81  DEG_id_tag_update(&wo->id, 0);
84 }
85 
86 static void rna_World_use_nodes_update(bContext *C, PointerRNA *ptr)
87 {
88  World *wrld = (World *)ptr->data;
89  Main *bmain = CTX_data_main(C);
91 
92  if (wrld->use_nodes && wrld->nodetree == NULL) {
93  ED_node_shader_default(C, &wrld->id);
94  }
95 
97  rna_World_update(bmain, scene, ptr);
98  rna_World_draw_update(bmain, scene, ptr);
99 }
100 
101 #else
102 
103 static void rna_def_lighting(BlenderRNA *brna)
104 {
105  StructRNA *srna;
106  PropertyRNA *prop;
107 
108  srna = RNA_def_struct(brna, "WorldLighting", NULL);
109  RNA_def_struct_sdna(srna, "World");
110  RNA_def_struct_nested(brna, srna, "World");
111  RNA_def_struct_ui_text(srna, "Lighting", "Lighting for a World data-block");
112 
113  /* ambient occlusion */
114  prop = RNA_def_property(srna, "use_ambient_occlusion", PROP_BOOLEAN, PROP_NONE);
117  prop,
118  "Use Ambient Occlusion",
119  "Use Ambient Occlusion to add shadowing based on distance between objects");
120  RNA_def_property_update(prop, 0, "rna_World_update");
121 
122  prop = RNA_def_property(srna, "ao_factor", PROP_FLOAT, PROP_FACTOR);
123  RNA_def_property_float_sdna(prop, NULL, "aoenergy");
124  RNA_def_property_range(prop, 0, INT_MAX);
125  RNA_def_property_ui_range(prop, 0, 1, 0.1, 2);
126  RNA_def_property_ui_text(prop, "Factor", "Factor for ambient occlusion blending");
127  RNA_def_property_update(prop, 0, "rna_World_update");
128 
129  prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_DISTANCE);
130  RNA_def_property_float_sdna(prop, NULL, "aodist");
132  prop, "Distance", "Length of rays, defines how far away other faces give occlusion effect");
133  RNA_def_property_update(prop, 0, "rna_World_update");
134 }
135 
136 static void rna_def_world_mist(BlenderRNA *brna)
137 {
138  StructRNA *srna;
139  PropertyRNA *prop;
140 
141  static const EnumPropertyItem falloff_items[] = {
142  {WO_MIST_QUADRATIC, "QUADRATIC", 0, "Quadratic", "Use quadratic progression"},
143  {WO_MIST_LINEAR, "LINEAR", 0, "Linear", "Use linear progression"},
145  "INVERSE_QUADRATIC",
146  0,
147  "Inverse Quadratic",
148  "Use inverse quadratic progression"},
149  {0, NULL, 0, NULL, NULL},
150  };
151 
152  srna = RNA_def_struct(brna, "WorldMistSettings", NULL);
153  RNA_def_struct_sdna(srna, "World");
154  RNA_def_struct_nested(brna, srna, "World");
155  RNA_def_struct_ui_text(srna, "World Mist", "Mist settings for a World data-block");
156 
157  prop = RNA_def_property(srna, "use_mist", PROP_BOOLEAN, PROP_NONE);
160  prop, "Use Mist", "Occlude objects with the environment color as they are further away");
161  RNA_def_property_update(prop, 0, "rna_World_draw_update");
162 
163  prop = RNA_def_property(srna, "intensity", PROP_FLOAT, PROP_NONE);
164  RNA_def_property_float_sdna(prop, NULL, "misi");
165  RNA_def_property_range(prop, 0, 1);
166  RNA_def_property_ui_text(prop, "Minimum", "Overall minimum intensity of the mist effect");
167  RNA_def_property_update(prop, 0, "rna_World_draw_update");
168 
169  prop = RNA_def_property(srna, "start", PROP_FLOAT, PROP_DISTANCE);
170  RNA_def_property_float_sdna(prop, NULL, "miststa");
171  RNA_def_property_range(prop, 0, FLT_MAX);
172  RNA_def_property_ui_range(prop, 0, 10000, 10, 2);
174  prop, "Start", "Starting distance of the mist, measured from the camera");
175  RNA_def_property_update(prop, 0, "rna_World_draw_update");
176 
177  prop = RNA_def_property(srna, "depth", PROP_FLOAT, PROP_DISTANCE);
178  RNA_def_property_float_sdna(prop, NULL, "mistdist");
179  RNA_def_property_range(prop, 0, FLT_MAX);
180  RNA_def_property_ui_range(prop, 0, 10000, 10, 2);
181  RNA_def_property_ui_text(prop, "Depth", "Distance over which the mist effect fades in");
182  RNA_def_property_update(prop, 0, "rna_World_draw_update");
183 
184  prop = RNA_def_property(srna, "height", PROP_FLOAT, PROP_DISTANCE);
185  RNA_def_property_float_sdna(prop, NULL, "misthi");
186  RNA_def_property_range(prop, 0, 100);
187  RNA_def_property_ui_text(prop, "Height", "Control how much mist density decreases with height");
188  RNA_def_property_update(prop, 0, "rna_World_update");
189 
190  prop = RNA_def_property(srna, "falloff", PROP_ENUM, PROP_NONE);
191  RNA_def_property_enum_sdna(prop, NULL, "mistype");
192  RNA_def_property_enum_items(prop, falloff_items);
193  RNA_def_property_ui_text(prop, "Falloff", "Type of transition used to fade mist");
194  RNA_def_property_update(prop, 0, "rna_World_draw_update");
195 }
196 
198 {
199  StructRNA *srna;
200  PropertyRNA *prop;
201 
202  static float default_world_color[] = {0.05f, 0.05f, 0.05f};
203 
204  srna = RNA_def_struct(brna, "World", "ID");
206  srna,
207  "World",
208  "World data-block describing the environment and ambient lighting of a scene");
209  RNA_def_struct_ui_icon(srna, ICON_WORLD_DATA);
210 
212 
213  /* colors */
214  prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
215  RNA_def_property_float_sdna(prop, NULL, "horr");
216  RNA_def_property_array(prop, 3);
217  RNA_def_property_float_array_default(prop, default_world_color);
218  RNA_def_property_ui_text(prop, "Color", "Color of the background");
219  /* RNA_def_property_update(prop, 0, "rna_World_update"); */
220  /* render-only uses this */
221  RNA_def_property_update(prop, 0, "rna_World_draw_update");
222 
223  /* nested structs */
224  prop = RNA_def_property(srna, "light_settings", PROP_POINTER, PROP_NONE);
226  RNA_def_property_struct_type(prop, "WorldLighting");
227  RNA_def_property_pointer_funcs(prop, "rna_World_lighting_get", NULL, NULL, NULL);
228  RNA_def_property_ui_text(prop, "Lighting", "World lighting settings");
229 
230  prop = RNA_def_property(srna, "mist_settings", PROP_POINTER, PROP_NONE);
232  RNA_def_property_struct_type(prop, "WorldMistSettings");
233  RNA_def_property_pointer_funcs(prop, "rna_World_mist_get", NULL, NULL, NULL);
234  RNA_def_property_ui_text(prop, "Mist", "World mist settings");
235 
236  /* nodes */
237  prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
238  RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
240  RNA_def_property_ui_text(prop, "Node Tree", "Node tree for node based worlds");
241 
242  prop = RNA_def_property(srna, "use_nodes", PROP_BOOLEAN, PROP_NONE);
243  RNA_def_property_boolean_sdna(prop, NULL, "use_nodes", 1);
246  RNA_def_property_ui_text(prop, "Use Nodes", "Use shader nodes to render the world");
247  RNA_def_property_update(prop, 0, "rna_World_use_nodes_update");
248 
249  rna_def_lighting(brna);
250  rna_def_world_mist(brna);
251 }
252 
253 #endif
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
#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
@ WO_MIST_QUADRATIC
@ WO_MIST_INVERSE_QUADRATIC
@ WO_MIST_LINEAR
#define WO_MIST
void ED_node_shader_default(const struct bContext *C, struct ID *id)
Read Guarded memory(de)allocation.
StructRNA RNA_WorldLighting
StructRNA RNA_WorldMistSettings
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_POINTER
Definition: RNA_types.h:78
@ PROP_CONTEXT_UPDATE
Definition: RNA_types.h:254
@ PROP_ANIMATABLE
Definition: RNA_types.h:188
@ PROP_NEVER_NULL
Definition: RNA_types.h:225
@ PROP_PTR_NO_OWNERSHIP
Definition: RNA_types.h:242
@ PROP_DISTANCE
Definition: RNA_types.h:135
@ PROP_COLOR
Definition: RNA_types.h:139
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_FACTOR
Definition: RNA_types.h:131
#define C
Definition: RandGen.cpp:39
#define NC_WORLD
Definition: WM_types.h:288
#define ND_WORLD
Definition: WM_types.h:353
#define ND_DRAW
Definition: WM_types.h:362
#define ND_WORLD_DRAW
Definition: WM_types.h:387
#define NC_OBJECT
Definition: WM_types.h:280
Scene scene
PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *data)
Definition: rna_access.c:196
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:2762
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
Definition: rna_define.c:2257
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
Definition: rna_define.c:1676
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
Definition: rna_define.c:1259
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
Definition: rna_define.c:1892
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
Definition: rna_define.c:1067
void RNA_def_property_array(PropertyRNA *prop, int length)
Definition: rna_define.c:1568
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
Definition: rna_define.c:1757
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
Definition: rna_define.c:1792
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
Definition: rna_define.c:2927
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
Definition: rna_define.c:1279
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1517
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:3373
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
Definition: rna_define.c:1047
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2623
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
Definition: rna_define.c:1267
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
Definition: rna_define.c:2515
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
Definition: rna_define.c:1706
void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
Definition: rna_define.c:2064
void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname)
Definition: rna_define.c:1138
void RNA_def_world(BlenderRNA *brna)
Definition: rna_world.c:197
static void rna_def_world_mist(BlenderRNA *brna)
Definition: rna_world.c:136
static void rna_def_lighting(BlenderRNA *brna)
Definition: rna_world.c:103
Definition: BKE_main.h:116
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
struct bNodeTree * nodetree
short use_nodes
void WM_main_add_notifier(unsigned int type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157