|
Blender
V2.59
|
00001 /* 00002 * $Id: rna_lattice.c 37031 2011-05-31 02:14: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). 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00030 #include <stdlib.h> 00031 00032 #include "RNA_define.h" 00033 00034 #include "rna_internal.h" 00035 00036 #include "DNA_curve_types.h" 00037 #include "DNA_key_types.h" 00038 #include "DNA_lattice_types.h" 00039 #include "DNA_meshdata_types.h" 00040 00041 #ifdef RNA_RUNTIME 00042 00043 #include "DNA_object_types.h" 00044 #include "DNA_scene_types.h" 00045 00046 #include "BKE_depsgraph.h" 00047 #include "BKE_lattice.h" 00048 #include "BKE_main.h" 00049 #include "BKE_deform.h" 00050 00051 #include "WM_api.h" 00052 #include "WM_types.h" 00053 00054 static void rna_LatticePoint_co_get(PointerRNA *ptr, float *values) 00055 { 00056 Lattice *lt= (Lattice*)ptr->id.data; 00057 BPoint *bp= (BPoint*)ptr->data; 00058 int a= bp - lt->def; 00059 int x= a % lt->pntsu; 00060 int y= (a/lt->pntsu) % lt->pntsv; 00061 int z= (a/(lt->pntsu*lt->pntsv)); 00062 00063 values[0]= lt->fu + x*lt->du; 00064 values[1]= lt->fv + y*lt->dv; 00065 values[2]= lt->fw + z*lt->dw; 00066 } 00067 00068 static void rna_LatticePoint_groups_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) 00069 { 00070 Lattice *lt= (Lattice*)ptr->id.data; 00071 00072 if(lt->dvert) { 00073 BPoint *bp= (BPoint*)ptr->data; 00074 MDeformVert *dvert= lt->dvert + (bp-lt->def); 00075 00076 rna_iterator_array_begin(iter, (void*)dvert->dw, sizeof(MDeformWeight), dvert->totweight, 0, NULL); 00077 } 00078 else 00079 rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL); 00080 } 00081 00082 static void rna_Lattice_points_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) 00083 { 00084 Lattice *lt= (Lattice*)ptr->data; 00085 int tot= lt->pntsu*lt->pntsv*lt->pntsw; 00086 00087 if(lt->editlatt && lt->editlatt->latt->def) 00088 rna_iterator_array_begin(iter, (void*)lt->editlatt->latt->def, sizeof(BPoint), tot, 0, NULL); 00089 else if(lt->def) 00090 rna_iterator_array_begin(iter, (void*)lt->def, sizeof(BPoint), tot, 0, NULL); 00091 else 00092 rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL); 00093 } 00094 00095 static void rna_Lattice_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) 00096 { 00097 ID *id= ptr->id.data; 00098 00099 DAG_id_tag_update(id, 0); 00100 WM_main_add_notifier(NC_GEOM|ND_DATA, id); 00101 } 00102 00103 static void rna_Lattice_update_size(Main *bmain, Scene *scene, PointerRNA *ptr) 00104 { 00105 Lattice *lt= ptr->id.data; 00106 Object *ob; 00107 int newu, newv, neww; 00108 00109 /* we don't modify the actual pnts, but go through opnts instead */ 00110 newu= (lt->opntsu > 0)? lt->opntsu: lt->pntsu; 00111 newv= (lt->opntsv > 0)? lt->opntsv: lt->pntsv; 00112 neww= (lt->opntsw > 0)? lt->opntsw: lt->pntsw; 00113 00114 /* resizelattice needs an object, any object will have the same result */ 00115 for(ob=bmain->object.first; ob; ob= ob->id.next) { 00116 if(ob->data == lt) { 00117 resizelattice(lt, newu, newv, neww, ob); 00118 if(lt->editlatt) 00119 resizelattice(lt->editlatt->latt, newu, newv, neww, ob); 00120 break; 00121 } 00122 } 00123 00124 /* otherwise without, means old points are not repositioned */ 00125 if(!ob) { 00126 resizelattice(lt, newu, newv, neww, NULL); 00127 if(lt->editlatt) 00128 resizelattice(lt->editlatt->latt, newu, newv, neww, NULL); 00129 } 00130 00131 rna_Lattice_update_data(bmain, scene, ptr); 00132 } 00133 00134 static void rna_Lattice_use_outside_set(PointerRNA *ptr, int value) 00135 { 00136 Lattice *lt= ptr->data; 00137 00138 if(value) lt->flag |= LT_OUTSIDE; 00139 else lt->flag &= ~LT_OUTSIDE; 00140 00141 outside_lattice(lt); 00142 00143 if(lt->editlatt) { 00144 if(value) lt->editlatt->latt->flag |= LT_OUTSIDE; 00145 else lt->editlatt->latt->flag &= ~LT_OUTSIDE; 00146 00147 outside_lattice(lt->editlatt->latt); 00148 } 00149 } 00150 00151 static int rna_Lattice_size_editable(PointerRNA *ptr) 00152 { 00153 Lattice *lt= (Lattice*)ptr->data; 00154 00155 return lt->key == NULL; 00156 } 00157 00158 static void rna_Lattice_points_u_set(PointerRNA *ptr, int value) 00159 { 00160 Lattice *lt= (Lattice*)ptr->data; 00161 00162 lt->opntsu= CLAMPIS(value, 1, 64); 00163 } 00164 00165 static void rna_Lattice_points_v_set(PointerRNA *ptr, int value) 00166 { 00167 Lattice *lt= (Lattice*)ptr->data; 00168 00169 lt->opntsv= CLAMPIS(value, 1, 64); 00170 } 00171 00172 static void rna_Lattice_points_w_set(PointerRNA *ptr, int value) 00173 { 00174 Lattice *lt= (Lattice*)ptr->data; 00175 00176 lt->opntsw= CLAMPIS(value, 1, 64); 00177 } 00178 00179 static void rna_Lattice_vg_name_set(PointerRNA *ptr, const char *value) 00180 { 00181 Lattice *lt= ptr->data; 00182 strcpy(lt->vgroup, value); 00183 00184 if(lt->editlatt) 00185 strcpy(lt->editlatt->latt->vgroup, value); 00186 } 00187 00188 /* annoying, but is a consequence of RNA structures... */ 00189 static char *rna_LatticePoint_path(PointerRNA *ptr) 00190 { 00191 Lattice *lt= (Lattice*)ptr->id.data; 00192 void *point= ptr->data; 00193 BPoint *points = NULL; 00194 00195 if (lt->editlatt && lt->editlatt->latt->def) 00196 points = lt->editlatt->latt->def; 00197 else 00198 points = lt->def; 00199 00200 if (points && point) { 00201 int tot= lt->pntsu*lt->pntsv*lt->pntsw; 00202 00203 /* only return index if in range */ 00204 if ((point >= (void *)points) && (point < (void *)(points + tot))) { 00205 int pt_index = (int)((BPoint *)point - points); 00206 00207 return BLI_sprintfN("points[%d]", pt_index); 00208 } 00209 } 00210 00211 return BLI_strdup(""); 00212 } 00213 00214 00215 #else 00216 00217 static void rna_def_latticepoint(BlenderRNA *brna) 00218 { 00219 StructRNA *srna; 00220 PropertyRNA *prop; 00221 00222 srna= RNA_def_struct(brna, "LatticePoint", NULL); 00223 RNA_def_struct_sdna(srna, "BPoint"); 00224 RNA_def_struct_ui_text(srna, "LatticePoint", "Point in the lattice grid"); 00225 RNA_def_struct_path_func(srna, "rna_LatticePoint_path"); 00226 00227 prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION); 00228 RNA_def_property_array(prop, 3); 00229 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00230 RNA_def_property_float_funcs(prop, "rna_LatticePoint_co_get", NULL, NULL); 00231 RNA_def_property_ui_text(prop, "Location", ""); 00232 00233 prop= RNA_def_property(srna, "co_deform", PROP_FLOAT, PROP_TRANSLATION); 00234 RNA_def_property_float_sdna(prop, NULL, "vec"); 00235 RNA_def_property_array(prop, 3); 00236 RNA_def_property_ui_text(prop, "Deformed Location", ""); 00237 RNA_def_property_update(prop, 0, "rna_Lattice_update_data"); 00238 00239 prop= RNA_def_property(srna, "groups", PROP_COLLECTION, PROP_NONE); 00240 RNA_def_property_collection_funcs(prop, "rna_LatticePoint_groups_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0); 00241 RNA_def_property_struct_type(prop, "VertexGroupElement"); 00242 RNA_def_property_ui_text(prop, "Groups", "Weights for the vertex groups this point is member of"); 00243 } 00244 00245 static void rna_def_lattice(BlenderRNA *brna) 00246 { 00247 StructRNA *srna; 00248 PropertyRNA *prop; 00249 00250 static EnumPropertyItem prop_keyblock_type_items[] = { 00251 {KEY_LINEAR, "KEY_LINEAR", 0, "Linear", ""}, 00252 {KEY_CARDINAL, "KEY_CARDINAL", 0, "Cardinal", ""}, 00253 {KEY_BSPLINE, "KEY_BSPLINE", 0, "BSpline", ""}, 00254 {0, NULL, 0, NULL, NULL}}; 00255 00256 srna= RNA_def_struct(brna, "Lattice", "ID"); 00257 RNA_def_struct_ui_text(srna, "Lattice", "Lattice datablock defining a grid for deforming other objects"); 00258 RNA_def_struct_ui_icon(srna, ICON_LATTICE_DATA); 00259 00260 prop= RNA_def_property(srna, "points_u", PROP_INT, PROP_NONE); 00261 RNA_def_property_int_sdna(prop, NULL, "pntsu"); 00262 RNA_def_property_int_funcs(prop, NULL, "rna_Lattice_points_u_set", NULL); 00263 RNA_def_property_range(prop, 1, 64); 00264 RNA_def_property_ui_text(prop, "U", "Points in U direction (can't be changed when there are shape keys)"); 00265 RNA_def_property_update(prop, 0, "rna_Lattice_update_size"); 00266 RNA_def_property_editable_func(prop, "rna_Lattice_size_editable"); 00267 00268 prop= RNA_def_property(srna, "points_v", PROP_INT, PROP_NONE); 00269 RNA_def_property_int_sdna(prop, NULL, "pntsv"); 00270 RNA_def_property_int_funcs(prop, NULL, "rna_Lattice_points_v_set", NULL); 00271 RNA_def_property_range(prop, 1, 64); 00272 RNA_def_property_ui_text(prop, "V", "Points in V direction (can't be changed when there are shape keys)"); 00273 RNA_def_property_update(prop, 0, "rna_Lattice_update_size"); 00274 RNA_def_property_editable_func(prop, "rna_Lattice_size_editable"); 00275 00276 prop= RNA_def_property(srna, "points_w", PROP_INT, PROP_NONE); 00277 RNA_def_property_int_sdna(prop, NULL, "pntsw"); 00278 RNA_def_property_int_funcs(prop, NULL, "rna_Lattice_points_w_set", NULL); 00279 RNA_def_property_range(prop, 1, 64); 00280 RNA_def_property_ui_text(prop, "W", "Points in W direction (can't be changed when there are shape keys)"); 00281 RNA_def_property_update(prop, 0, "rna_Lattice_update_size"); 00282 RNA_def_property_editable_func(prop, "rna_Lattice_size_editable"); 00283 00284 prop= RNA_def_property(srna, "interpolation_type_u", PROP_ENUM, PROP_NONE); 00285 RNA_def_property_enum_sdna(prop, NULL, "typeu"); 00286 RNA_def_property_enum_items(prop, prop_keyblock_type_items); 00287 RNA_def_property_ui_text(prop, "Interpolation Type U", ""); 00288 RNA_def_property_update(prop, 0, "rna_Lattice_update_data"); 00289 00290 prop= RNA_def_property(srna, "interpolation_type_v", PROP_ENUM, PROP_NONE); 00291 RNA_def_property_enum_sdna(prop, NULL, "typev"); 00292 RNA_def_property_enum_items(prop, prop_keyblock_type_items); 00293 RNA_def_property_ui_text(prop, "Interpolation Type V", ""); 00294 RNA_def_property_update(prop, 0, "rna_Lattice_update_data"); 00295 00296 prop= RNA_def_property(srna, "interpolation_type_w", PROP_ENUM, PROP_NONE); 00297 RNA_def_property_enum_sdna(prop, NULL, "typew"); 00298 RNA_def_property_enum_items(prop, prop_keyblock_type_items); 00299 RNA_def_property_ui_text(prop, "Interpolation Type W", ""); 00300 RNA_def_property_update(prop, 0, "rna_Lattice_update_data"); 00301 00302 prop= RNA_def_property(srna, "use_outside", PROP_BOOLEAN, PROP_NONE); 00303 RNA_def_property_boolean_sdna(prop, NULL, "flag", LT_OUTSIDE); 00304 RNA_def_property_boolean_funcs(prop, NULL, "rna_Lattice_use_outside_set"); 00305 RNA_def_property_ui_text(prop, "Outside", "Only draw, and take into account, the outer vertices"); 00306 RNA_def_property_update(prop, 0, "rna_Lattice_update_data"); 00307 00308 prop= RNA_def_property(srna, "vertex_group", PROP_STRING, PROP_NONE); 00309 RNA_def_property_string_sdna(prop, NULL, "vgroup"); 00310 RNA_def_property_ui_text(prop, "Vertex Group", "Vertex group to apply the influence of the lattice"); 00311 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Lattice_vg_name_set"); 00312 RNA_def_property_update(prop, 0, "rna_Lattice_update_data"); 00313 00314 prop= RNA_def_property(srna, "shape_keys", PROP_POINTER, PROP_NONE); 00315 RNA_def_property_pointer_sdna(prop, NULL, "key"); 00316 RNA_def_property_ui_text(prop, "Shape Keys", ""); 00317 00318 prop= RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE); 00319 RNA_def_property_struct_type(prop, "LatticePoint"); 00320 RNA_def_property_collection_funcs(prop, "rna_Lattice_points_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0); 00321 RNA_def_property_ui_text(prop, "Points", "Points of the lattice"); 00322 00323 /* pointers */ 00324 rna_def_animdata_common(srna); 00325 } 00326 00327 void RNA_def_lattice(BlenderRNA *brna) 00328 { 00329 rna_def_lattice(brna); 00330 rna_def_latticepoint(brna); 00331 } 00332 00333 #endif 00334