|
Blender
V2.59
|
00001 /* 00002 * $Id: rna_meta.c 36095 2011-04-11 01:18:25Z campbellbarton $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * Contributor(s): Blender Foundation (2008), Juho Vepsalainen, Jiri Hnidek 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00030 #include <stdlib.h> 00031 00032 #include "RNA_define.h" 00033 #include "RNA_enum_types.h" 00034 00035 #include "rna_internal.h" 00036 00037 #include "DNA_mesh_types.h" 00038 #include "DNA_meta_types.h" 00039 00040 #ifdef RNA_RUNTIME 00041 00042 #include "BLI_math.h" 00043 00044 #include "MEM_guardedalloc.h" 00045 00046 #include "DNA_scene_types.h" 00047 #include "DNA_object_types.h" 00048 00049 #include "BKE_mball.h" 00050 #include "BKE_depsgraph.h" 00051 #include "BKE_main.h" 00052 00053 #include "WM_types.h" 00054 #include "WM_api.h" 00055 00056 static int rna_Meta_texspace_editable(PointerRNA *ptr) 00057 { 00058 MetaBall *mb= (MetaBall*)ptr->data; 00059 return (mb->texflag & MB_AUTOSPACE)? 0: PROP_EDITABLE; 00060 } 00061 00062 static void rna_Meta_texspace_loc_get(PointerRNA *ptr, float *values) 00063 { 00064 MetaBall *mb= (MetaBall*)ptr->data; 00065 00066 /* tex_space_mball() needs object.. ugh */ 00067 00068 copy_v3_v3(values, mb->loc); 00069 } 00070 00071 static void rna_Meta_texspace_loc_set(PointerRNA *ptr, const float *values) 00072 { 00073 MetaBall *mb= (MetaBall*)ptr->data; 00074 00075 copy_v3_v3(mb->loc, values); 00076 } 00077 00078 static void rna_Meta_texspace_size_get(PointerRNA *ptr, float *values) 00079 { 00080 MetaBall *mb= (MetaBall*)ptr->data; 00081 00082 /* tex_space_mball() needs object.. ugh */ 00083 00084 copy_v3_v3(values, mb->size); 00085 } 00086 00087 static void rna_Meta_texspace_size_set(PointerRNA *ptr, const float *values) 00088 { 00089 MetaBall *mb= (MetaBall*)ptr->data; 00090 00091 copy_v3_v3(mb->size, values); 00092 } 00093 00094 00095 static void rna_MetaBall_update_data(Main *bmain, Scene *scene, PointerRNA *ptr) 00096 { 00097 MetaBall *mb= ptr->id.data; 00098 Object *ob; 00099 00100 /* cheating way for importers to avoid slow updates */ 00101 if(mb->id.us > 0) { 00102 for(ob=bmain->object.first; ob; ob= ob->id.next) 00103 if(ob->data == mb) 00104 copy_mball_properties(scene, ob); 00105 00106 DAG_id_tag_update(&mb->id, 0); 00107 WM_main_add_notifier(NC_GEOM|ND_DATA, mb); 00108 } 00109 } 00110 00111 static void rna_MetaBall_update_rotation(Main *bmain, Scene *scene, PointerRNA *ptr) 00112 { 00113 MetaElem *ml= ptr->data; 00114 normalize_qt(ml->quat); 00115 rna_MetaBall_update_data(bmain, scene, ptr); 00116 } 00117 00118 static MetaElem *rna_MetaBall_elements_new(MetaBall *mb, int type) 00119 { 00120 MetaElem *ml= add_metaball_element(mb, type); 00121 00122 /* cheating way for importers to avoid slow updates */ 00123 if(mb->id.us > 0) { 00124 DAG_id_tag_update(&mb->id, 0); 00125 WM_main_add_notifier(NC_GEOM|ND_DATA, &mb->id); 00126 } 00127 00128 return ml; 00129 } 00130 00131 static void rna_MetaBall_elements_remove(MetaBall *mb, ReportList *reports, MetaElem *ml) 00132 { 00133 int found= 0; 00134 00135 found= BLI_remlink_safe(&mb->elems, ml); 00136 00137 if(!found) { 00138 BKE_reportf(reports, RPT_ERROR, "MetaBall \"%s\" does not contain spline given", mb->id.name+2); 00139 return; 00140 } 00141 00142 MEM_freeN(ml); 00143 /* invalidate pointer!, no can do */ 00144 00145 /* cheating way for importers to avoid slow updates */ 00146 if(mb->id.us > 0) { 00147 DAG_id_tag_update(&mb->id, 0); 00148 WM_main_add_notifier(NC_GEOM|ND_DATA, &mb->id); 00149 } 00150 } 00151 00152 #else 00153 00154 static void rna_def_metaelement(BlenderRNA *brna) 00155 { 00156 StructRNA *srna; 00157 PropertyRNA *prop; 00158 00159 srna= RNA_def_struct(brna, "MetaElement", NULL); 00160 RNA_def_struct_sdna(srna, "MetaElem"); 00161 RNA_def_struct_ui_text(srna, "Meta Element", "Blobby element in a MetaBall datablock"); 00162 RNA_def_struct_ui_icon(srna, ICON_OUTLINER_DATA_META); 00163 00164 /* enums */ 00165 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); 00166 RNA_def_property_enum_items(prop, metaelem_type_items); 00167 RNA_def_property_ui_text(prop, "Type", "Metaball types"); 00168 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00169 00170 /* number values */ 00171 prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION); 00172 RNA_def_property_float_sdna(prop, NULL, "x"); 00173 RNA_def_property_array(prop, 3); 00174 RNA_def_property_ui_text(prop, "Location", ""); 00175 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00176 00177 prop= RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_QUATERNION); 00178 RNA_def_property_float_sdna(prop, NULL, "quat"); 00179 RNA_def_property_ui_text(prop, "Rotation", "Normalized quaternion rotation"); 00180 RNA_def_property_update(prop, 0, "rna_MetaBall_update_rotation"); 00181 00182 prop= RNA_def_property(srna, "radius", PROP_FLOAT, PROP_UNSIGNED|PROP_UNIT_LENGTH); 00183 RNA_def_property_float_sdna(prop, NULL, "rad"); 00184 RNA_def_property_ui_text(prop, "Radius", ""); 00185 RNA_def_property_range(prop, 0.0f, FLT_MAX); 00186 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00187 00188 prop= RNA_def_property(srna, "size_x", PROP_FLOAT, PROP_DISTANCE); 00189 RNA_def_property_float_sdna(prop, NULL, "expx"); 00190 RNA_def_property_range(prop, 0.0f, 20.0f); 00191 RNA_def_property_ui_text(prop, "Size X", "Size of element, use of components depends on element type"); 00192 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00193 00194 prop= RNA_def_property(srna, "size_y", PROP_FLOAT, PROP_DISTANCE); 00195 RNA_def_property_float_sdna(prop, NULL, "expy"); 00196 RNA_def_property_range(prop, 0.0f, 20.0f); 00197 RNA_def_property_ui_text(prop, "Size Y", "Size of element, use of components depends on element type"); 00198 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00199 00200 prop= RNA_def_property(srna, "size_z", PROP_FLOAT, PROP_DISTANCE); 00201 RNA_def_property_float_sdna(prop, NULL, "expz"); 00202 RNA_def_property_range(prop, 0.0f, 20.0f); 00203 RNA_def_property_ui_text(prop, "Size Z", "Size of element, use of components depends on element type"); 00204 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00205 00206 prop= RNA_def_property(srna, "stiffness", PROP_FLOAT, PROP_NONE); 00207 RNA_def_property_float_sdna(prop, NULL, "s"); 00208 RNA_def_property_range(prop, 0.0f, 10.0f); 00209 RNA_def_property_ui_text(prop, "Stiffness", "Stiffness defines how much of the element to fill"); 00210 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00211 00212 /* flags */ 00213 prop= RNA_def_property(srna, "use_negative", PROP_BOOLEAN, PROP_NONE); 00214 RNA_def_property_boolean_sdna(prop, NULL, "flag", MB_NEGATIVE); 00215 RNA_def_property_ui_text(prop, "Negative", "Set metaball as negative one"); 00216 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00217 00218 prop= RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE); 00219 RNA_def_property_boolean_sdna(prop, NULL, "flag", MB_HIDE); 00220 RNA_def_property_ui_text(prop, "Hide", "Hide element"); 00221 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00222 } 00223 00224 /* mball.elements */ 00225 static void rna_def_metaball_elements(BlenderRNA *brna, PropertyRNA *cprop) 00226 { 00227 StructRNA *srna; 00228 PropertyRNA *prop; 00229 00230 FunctionRNA *func; 00231 PropertyRNA *parm; 00232 00233 RNA_def_property_srna(cprop, "MetaBallElements"); 00234 srna= RNA_def_struct(brna, "MetaBallElements", NULL); 00235 RNA_def_struct_sdna(srna, "MetaBall"); 00236 RNA_def_struct_ui_text(srna, "Meta Elements", "Collection of metaball elements"); 00237 00238 func= RNA_def_function(srna, "new", "rna_MetaBall_elements_new"); 00239 RNA_def_function_ui_description(func, "Add a new spline to the curve."); 00240 RNA_def_enum(func, "type", metaelem_type_items, MB_BALL, "", "type for the new meta-element."); 00241 parm= RNA_def_pointer(func, "element", "MetaElement", "", "The newly created meta-element."); 00242 RNA_def_function_return(func, parm); 00243 00244 func= RNA_def_function(srna, "remove", "rna_MetaBall_elements_remove"); 00245 RNA_def_function_ui_description(func, "Remove a spline from a curve."); 00246 RNA_def_function_flag(func, FUNC_USE_REPORTS); 00247 parm= RNA_def_pointer(func, "element", "MetaElement", "", "The element to remove."); 00248 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); 00249 00250 prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); 00251 RNA_def_property_pointer_sdna(prop, NULL, "lastelem"); 00252 RNA_def_property_ui_text(prop, "Active Element", "Last selected element"); 00253 } 00254 00255 static void rna_def_metaball(BlenderRNA *brna) 00256 { 00257 StructRNA *srna; 00258 PropertyRNA *prop; 00259 static EnumPropertyItem prop_update_items[] = { 00260 {MB_UPDATE_ALWAYS, "UPDATE_ALWAYS", 0, "Always", "While editing, update metaball always"}, 00261 {MB_UPDATE_HALFRES, "HALFRES", 0, "Half", "While editing, update metaball in half resolution"}, 00262 {MB_UPDATE_FAST, "FAST", 0, "Fast", "While editing, update metaball without polygonization"}, 00263 {MB_UPDATE_NEVER, "NEVER", 0, "Never", "While editing, don't update metaball at all"}, 00264 {0, NULL, 0, NULL, NULL}}; 00265 00266 srna= RNA_def_struct(brna, "MetaBall", "ID"); 00267 RNA_def_struct_ui_text(srna, "MetaBall", "Metaball datablock to defined blobby surfaces"); 00268 RNA_def_struct_ui_icon(srna, ICON_META_DATA); 00269 00270 prop= RNA_def_property(srna, "elements", PROP_COLLECTION, PROP_NONE); 00271 RNA_def_property_collection_sdna(prop, NULL, "elems", NULL); 00272 RNA_def_property_struct_type(prop, "MetaElement"); 00273 RNA_def_property_ui_text(prop, "Elements", "Meta elements"); 00274 rna_def_metaball_elements(brna, prop); 00275 00276 /* enums */ 00277 prop= RNA_def_property(srna, "update_method", PROP_ENUM, PROP_NONE); 00278 RNA_def_property_enum_sdna(prop, NULL, "flag"); 00279 RNA_def_property_enum_items(prop, prop_update_items); 00280 RNA_def_property_ui_text(prop, "Update", "Metaball edit update behavior"); 00281 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00282 00283 /* number values */ 00284 prop= RNA_def_property(srna, "resolution", PROP_FLOAT, PROP_DISTANCE); 00285 RNA_def_property_float_sdna(prop, NULL, "wiresize"); 00286 RNA_def_property_range(prop, 0.050f, 1.0f); 00287 RNA_def_property_ui_text(prop, "Wire Size", "Polygonization resolution in the 3D viewport"); 00288 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00289 00290 prop= RNA_def_property(srna, "render_resolution", PROP_FLOAT, PROP_DISTANCE); 00291 RNA_def_property_float_sdna(prop, NULL, "rendersize"); 00292 RNA_def_property_range(prop, 0.050f, 1.0f); 00293 RNA_def_property_ui_text(prop, "Render Size", "Polygonization resolution in rendering"); 00294 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00295 00296 prop= RNA_def_property(srna, "threshold", PROP_FLOAT, PROP_NONE); 00297 RNA_def_property_float_sdna(prop, NULL, "thresh"); 00298 RNA_def_property_range(prop, 0.0f, 5.0f); 00299 RNA_def_property_ui_text(prop, "Threshold", "Influence of meta elements"); 00300 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00301 00302 /* texture space */ 00303 prop= RNA_def_property(srna, "use_auto_texspace", PROP_BOOLEAN, PROP_NONE); 00304 RNA_def_property_boolean_sdna(prop, NULL, "texflag", MB_AUTOSPACE); 00305 RNA_def_property_ui_text(prop, "Auto Texture Space", "Adjusts active object's texture space automatically when transforming object"); 00306 00307 prop= RNA_def_property(srna, "texspace_location", PROP_FLOAT, PROP_TRANSLATION); 00308 RNA_def_property_array(prop, 3); 00309 RNA_def_property_ui_text(prop, "Texture Space Location", "Texture space location"); 00310 RNA_def_property_editable_func(prop, "rna_Meta_texspace_editable"); 00311 RNA_def_property_float_funcs(prop, "rna_Meta_texspace_loc_get", "rna_Meta_texspace_loc_set", NULL); 00312 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00313 00314 prop= RNA_def_property(srna, "texspace_size", PROP_FLOAT, PROP_XYZ); 00315 RNA_def_property_array(prop, 3); 00316 RNA_def_property_ui_text(prop, "Texture Space Size", "Texture space size"); 00317 RNA_def_property_editable_func(prop, "rna_Meta_texspace_editable"); 00318 RNA_def_property_float_funcs(prop, "rna_Meta_texspace_size_get", "rna_Meta_texspace_size_set", NULL); 00319 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data"); 00320 00321 /* not supported yet 00322 prop= RNA_def_property(srna, "texspace_rot", PROP_FLOAT, PROP_EULER); 00323 RNA_def_property_float(prop, NULL, "rot"); 00324 RNA_def_property_ui_text(prop, "Texture Space Rotation", "Texture space rotation"); 00325 RNA_def_property_editable_func(prop, "rna_Meta_texspace_editable"); 00326 RNA_def_property_update(prop, 0, "rna_MetaBall_update_data");*/ 00327 00328 /* materials */ 00329 prop= RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE); 00330 RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol"); 00331 RNA_def_property_struct_type(prop, "Material"); 00332 RNA_def_property_ui_text(prop, "Materials", ""); 00333 RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */ 00334 00335 /* anim */ 00336 rna_def_animdata_common(srna); 00337 } 00338 00339 void RNA_def_meta(BlenderRNA *brna) 00340 { 00341 rna_def_metaelement(brna); 00342 rna_def_metaball(brna); 00343 } 00344 00345 #endif