Blender  V2.93
lightprobe.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  * The Original Code is Copyright (C) Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <string.h>
25 
26 #include "DNA_collection_types.h"
27 #include "DNA_defaults.h"
28 #include "DNA_lightprobe_types.h"
29 #include "DNA_object_types.h"
30 
31 #include "BLI_utildefines.h"
32 
33 #include "BKE_anim_data.h"
34 #include "BKE_idtype.h"
35 #include "BKE_lib_id.h"
36 #include "BKE_lib_query.h"
37 #include "BKE_lightprobe.h"
38 #include "BKE_main.h"
39 
40 #include "BLT_translation.h"
41 
42 #include "BLO_read_write.h"
43 
44 static void lightprobe_init_data(ID *id)
45 {
46  LightProbe *probe = (LightProbe *)id;
48 
50 }
51 
53 {
54  LightProbe *probe = (LightProbe *)id;
55 
58 }
59 
60 static void lightprobe_blend_write(BlendWriter *writer, ID *id, const void *id_address)
61 {
62  LightProbe *prb = (LightProbe *)id;
63  if (prb->id.us > 0 || BLO_write_is_undo(writer)) {
64  /* write LibData */
65  BLO_write_id_struct(writer, LightProbe, id_address, &prb->id);
66  BKE_id_blend_write(writer, &prb->id);
67 
68  if (prb->adt) {
69  BKE_animdata_blend_write(writer, prb->adt);
70  }
71  }
72 }
73 
75 {
76  LightProbe *prb = (LightProbe *)id;
77  BLO_read_data_address(reader, &prb->adt);
78  BKE_animdata_blend_read_data(reader, prb->adt);
79 }
80 
81 static void lightprobe_blend_read_lib(BlendLibReader *reader, ID *id)
82 {
83  LightProbe *prb = (LightProbe *)id;
84  BLO_read_id_address(reader, prb->id.lib, &prb->visibility_grp);
85 }
86 
88  .id_code = ID_LP,
89  .id_filter = FILTER_ID_LP,
90  .main_listbase_index = INDEX_ID_LP,
91  .struct_size = sizeof(LightProbe),
92  .name = "LightProbe",
93  .name_plural = "lightprobes",
94  .translation_context = BLT_I18NCONTEXT_ID_LIGHTPROBE,
95  .flags = 0,
96 
98  .copy_data = NULL,
99  .free_data = NULL,
100  .make_local = NULL,
101  .foreach_id = lightprobe_foreach_id,
102  .foreach_cache = NULL,
103  .owner_get = NULL,
104 
105  .blend_write = lightprobe_blend_write,
106  .blend_read_data = lightprobe_blend_read_data,
107  .blend_read_lib = lightprobe_blend_read_lib,
108  .blend_read_expand = NULL,
109 
110  .blend_read_undo_preserve = NULL,
111 
112  .lib_override_apply_post = NULL,
113 };
114 
115 void BKE_lightprobe_type_set(LightProbe *probe, const short lightprobe_type)
116 {
117  probe->type = lightprobe_type;
118 
119  switch (probe->type) {
121  probe->distinf = 0.3f;
122  probe->falloff = 1.0f;
123  probe->clipsta = 0.01f;
124  break;
126  probe->distinf = 0.1f;
127  probe->falloff = 0.5f;
128  probe->clipsta = 0.001f;
129  break;
132  break;
133  default:
134  BLI_assert(!"LightProbe type not configured.");
135  break;
136  }
137 }
138 
139 void *BKE_lightprobe_add(Main *bmain, const char *name)
140 {
141  LightProbe *probe;
142 
143  probe = BKE_id_new(bmain, ID_LP, name);
144 
145  return probe;
146 }
void BKE_animdata_blend_read_data(struct BlendDataReader *reader, struct AnimData *adt)
Definition: anim_data.c:1574
void BKE_animdata_blend_write(struct BlendWriter *writer, struct AnimData *adt)
Definition: anim_data.c:1552
void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id)
Definition: lib_id.c:2395
void * BKE_id_new(struct Main *bmain, const short type, const char *name)
Definition: lib_id.c:1177
#define BKE_LIB_FOREACHID_PROCESS(_data, _id_super, _cb_flag)
@ IDWALK_CB_USER
Definition: BKE_lib_query.h:87
@ IDWALK_CB_NOP
Definition: BKE_lib_query.h:47
General operations for probes.
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define BLO_read_data_address(reader, ptr_p)
#define BLO_write_id_struct(writer, struct_name, id_address, id)
#define BLO_read_id_address(reader, lib, id_ptr_p)
bool BLO_write_is_undo(BlendWriter *writer)
Definition: writefile.c:1412
#define BLT_I18NCONTEXT_ID_LIGHTPROBE
#define FILTER_ID_LP
Definition: DNA_ID.h:735
@ INDEX_ID_LP
Definition: DNA_ID.h:837
@ ID_LP
Definition: DNA_ID_enums.h:92
Object groups, one object can be in many groups at once.
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:44
@ LIGHTPROBE_SHAPE_ELIPSOID
struct LightProbe LightProbe
@ LIGHTPROBE_TYPE_CUBE
@ LIGHTPROBE_TYPE_PLANAR
@ LIGHTPROBE_TYPE_GRID
Object is a sort of wrapper for general info.
static void init_data(ModifierData *md)
static void lightprobe_blend_read_lib(BlendLibReader *reader, ID *id)
Definition: lightprobe.c:81
static void lightprobe_blend_read_data(BlendDataReader *reader, ID *id)
Definition: lightprobe.c:74
void BKE_lightprobe_type_set(LightProbe *probe, const short lightprobe_type)
Definition: lightprobe.c:115
static void lightprobe_init_data(ID *id)
Definition: lightprobe.c:44
static void lightprobe_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition: lightprobe.c:60
IDTypeInfo IDType_ID_LP
Definition: lightprobe.c:87
void * BKE_lightprobe_add(Main *bmain, const char *name)
Definition: lightprobe.c:139
static void lightprobe_foreach_id(ID *id, LibraryForeachIDData *data)
Definition: lightprobe.c:52
short id_code
Definition: BKE_idtype.h:120
Definition: DNA_ID.h:273
struct Library * lib
Definition: DNA_ID.h:277
int us
Definition: DNA_ID.h:293
struct AnimData * adt
struct Collection * visibility_grp
struct Image * image
Definition: BKE_main.h:116