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