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) 2016 Blender Foundation.
17 * All rights reserved.
18 */
19
20 /** \file
21 * \ingroup RNA
22 */
23
24 #include "DNA_cachefile_types.h"
25 #include "DNA_scene_types.h"
26
27 #include "RNA_access.h"
28 #include "RNA_define.h"
29 #include "RNA_enum_types.h"
30
31 #include "rna_internal.h"
32
33 #ifdef RNA_RUNTIME
34
35 # include "BLI_string.h"
36
37 # include "BKE_cachefile.h"
38
39 # include "DEG_depsgraph.h"
40
41 # include "WM_api.h"
42 # include "WM_types.h"
43
44 # ifdef WITH_ALEMBIC
45 # include "ABC_alembic.h"
46 # endif
47
rna_CacheFile_update(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)48 static void rna_CacheFile_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
49 {
50 CacheFile *cache_file = (CacheFile *)ptr->data;
51
52 DEG_id_tag_update(&cache_file->id, ID_RECALC_COPY_ON_WRITE);
53 WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
54 }
55
rna_CacheFile_object_paths_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)56 static void rna_CacheFile_object_paths_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
57 {
58 CacheFile *cache_file = (CacheFile *)ptr->data;
59 rna_iterator_listbase_begin(iter, &cache_file->object_paths, NULL);
60 }
61
62 #else
63
64 /* cachefile.object_paths */
rna_def_alembic_object_path(BlenderRNA * brna)65 static void rna_def_alembic_object_path(BlenderRNA *brna)
66 {
67 StructRNA *srna = RNA_def_struct(brna, "AlembicObjectPath", NULL);
68 RNA_def_struct_sdna(srna, "AlembicObjectPath");
69 RNA_def_struct_ui_text(srna, "Object Path", "Path of an object inside of an Alembic archive");
70 RNA_def_struct_ui_icon(srna, ICON_NONE);
71
72 RNA_define_lib_overridable(true);
73
74 PropertyRNA *prop = RNA_def_property(srna, "path", PROP_STRING, PROP_NONE);
75 RNA_def_property_ui_text(prop, "Path", "Object path");
76 RNA_def_struct_name_property(srna, prop);
77
78 RNA_define_lib_overridable(false);
79 }
80
81 /* cachefile.object_paths */
rna_def_cachefile_object_paths(BlenderRNA * brna,PropertyRNA * cprop)82 static void rna_def_cachefile_object_paths(BlenderRNA *brna, PropertyRNA *cprop)
83 {
84 RNA_def_property_srna(cprop, "AlembicObjectPaths");
85 StructRNA *srna = RNA_def_struct(brna, "AlembicObjectPaths", NULL);
86 RNA_def_struct_sdna(srna, "CacheFile");
87 RNA_def_struct_ui_text(srna, "Object Paths", "Collection of object paths");
88 }
89
rna_def_cachefile(BlenderRNA * brna)90 static void rna_def_cachefile(BlenderRNA *brna)
91 {
92 StructRNA *srna = RNA_def_struct(brna, "CacheFile", "ID");
93 RNA_def_struct_sdna(srna, "CacheFile");
94 RNA_def_struct_ui_text(srna, "CacheFile", "");
95 RNA_def_struct_ui_icon(srna, ICON_FILE);
96
97 RNA_define_lib_overridable(true);
98
99 PropertyRNA *prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
100 RNA_def_property_ui_text(prop, "File Path", "Path to external displacements file");
101 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
102
103 prop = RNA_def_property(srna, "is_sequence", PROP_BOOLEAN, PROP_NONE);
104 RNA_def_property_ui_text(
105 prop, "Sequence", "Whether the cache is separated in a series of files");
106 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
107
108 /* ----------------- For Scene time ------------------- */
109
110 prop = RNA_def_property(srna, "override_frame", PROP_BOOLEAN, PROP_NONE);
111 RNA_def_property_ui_text(prop,
112 "Override Frame",
113 "Whether to use a custom frame for looking up data in the cache file,"
114 " instead of using the current scene frame");
115 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
116
117 prop = RNA_def_property(srna, "frame", PROP_FLOAT, PROP_NONE);
118 RNA_def_property_float_sdna(prop, NULL, "frame");
119 RNA_def_property_range(prop, -MAXFRAME, MAXFRAME);
120 RNA_def_property_ui_text(prop,
121 "Frame",
122 "The time to use for looking up the data in the cache file,"
123 " or to determine which file to use in a file sequence");
124 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
125
126 prop = RNA_def_property(srna, "frame_offset", PROP_FLOAT, PROP_NONE);
127 RNA_def_property_float_sdna(prop, NULL, "frame_offset");
128 RNA_def_property_range(prop, -MAXFRAME, MAXFRAME);
129 RNA_def_property_ui_text(prop,
130 "Frame Offset",
131 "Subtracted from the current frame to use for "
132 "looking up the data in the cache file, or to "
133 "determine which file to use in a file sequence");
134 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
135
136 /* ----------------- Axis Conversion ----------------- */
137
138 prop = RNA_def_property(srna, "forward_axis", PROP_ENUM, PROP_NONE);
139 RNA_def_property_enum_sdna(prop, NULL, "forward_axis");
140 RNA_def_property_enum_items(prop, rna_enum_object_axis_items);
141 RNA_def_property_ui_text(prop, "Forward", "");
142 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
143
144 prop = RNA_def_property(srna, "up_axis", PROP_ENUM, PROP_NONE);
145 RNA_def_property_enum_sdna(prop, NULL, "up_axis");
146 RNA_def_property_enum_items(prop, rna_enum_object_axis_items);
147 RNA_def_property_ui_text(prop, "Up", "");
148 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
149
150 prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
151 RNA_def_property_float_sdna(prop, NULL, "scale");
152 RNA_def_property_range(prop, 0.0001f, 1000.0f);
153 RNA_def_property_ui_text(
154 prop,
155 "Scale",
156 "Value by which to enlarge or shrink the object with respect to the world's origin"
157 " (only applicable through a Transform Cache constraint)");
158 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
159
160 /* object paths */
161 prop = RNA_def_property(srna, "object_paths", PROP_COLLECTION, PROP_NONE);
162 RNA_def_property_collection_sdna(prop, NULL, "object_paths", NULL);
163 RNA_def_property_collection_funcs(prop,
164 "rna_CacheFile_object_paths_begin",
165 "rna_iterator_listbase_next",
166 "rna_iterator_listbase_end",
167 "rna_iterator_listbase_get",
168 NULL,
169 NULL,
170 NULL,
171 NULL);
172 RNA_def_property_struct_type(prop, "AlembicObjectPath");
173 RNA_def_property_srna(prop, "AlembicObjectPaths");
174 RNA_def_property_ui_text(
175 prop, "Object Paths", "Paths of the objects inside the Alembic archive");
176
177 /* ----------------- Alembic Velocity Attribute ----------------- */
178
179 prop = RNA_def_property(srna, "velocity_name", PROP_STRING, PROP_NONE);
180 RNA_def_property_ui_text(prop,
181 "Velocity Attribute",
182 "Name of the Alembic attribute used for generating motion blur data");
183 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
184 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
185
186 static const EnumPropertyItem velocity_unit_items[] = {
187 {CACHEFILE_VELOCITY_UNIT_SECOND, "SECOND", 0, "Second", ""},
188 {CACHEFILE_VELOCITY_UNIT_FRAME, "FRAME", 0, "Frame", ""},
189 {0, NULL, 0, NULL, NULL},
190 };
191
192 prop = RNA_def_property(srna, "velocity_unit", PROP_ENUM, PROP_NONE);
193 RNA_def_property_enum_sdna(prop, NULL, "velocity_unit");
194 RNA_def_property_enum_items(prop, velocity_unit_items);
195 RNA_def_property_ui_text(
196 prop,
197 "Velocity Unit",
198 "Define how the velocity vectors are interpreted with regard to time, 'frame' means "
199 "the delta time is 1 frame, 'second' means the delta time is 1 / FPS");
200 RNA_def_property_update(prop, 0, "rna_CacheFile_update");
201 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
202
203 RNA_define_lib_overridable(false);
204
205 rna_def_cachefile_object_paths(brna, prop);
206
207 rna_def_animdata_common(srna);
208 }
209
RNA_def_cachefile(BlenderRNA * brna)210 void RNA_def_cachefile(BlenderRNA *brna)
211 {
212 rna_def_cachefile(brna);
213 rna_def_alembic_object_path(brna);
214 }
215
216 #endif
217