diff options
Diffstat (limited to 'source/blender/makesrna/intern/rna_lattice.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_lattice.c | 137 |
1 files changed, 120 insertions, 17 deletions
diff --git a/source/blender/makesrna/intern/rna_lattice.c b/source/blender/makesrna/intern/rna_lattice.c index 26c4ebb7b23..03a1dc9ec8f 100644 --- a/source/blender/makesrna/intern/rna_lattice.c +++ b/source/blender/makesrna/intern/rna_lattice.c @@ -1,5 +1,5 @@ /** - * $Id: rna_lattice.c 19382 2009-03-23 13:24:48Z blendix $ + * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * @@ -36,6 +36,16 @@ #ifdef RNA_RUNTIME +#include "DNA_object_types.h" +#include "DNA_scene_types.h" + +#include "BKE_depsgraph.h" +#include "BKE_lattice.h" +#include "BKE_main.h" + +#include "WM_api.h" +#include "WM_types.h" + static void rna_LatticePoint_co_get(PointerRNA *ptr, float *values) { Lattice *lt= (Lattice*)ptr->id.data; @@ -58,22 +68,103 @@ static void rna_LatticePoint_groups_begin(CollectionPropertyIterator *iter, Poin BPoint *bp= (BPoint*)ptr->data; MDeformVert *dvert= lt->dvert + (bp-lt->def); - rna_iterator_array_begin(iter, (void*)dvert->dw, sizeof(MDeformWeight), dvert->totweight, NULL); + rna_iterator_array_begin(iter, (void*)dvert->dw, sizeof(MDeformWeight), dvert->totweight, 0, NULL); } else - rna_iterator_array_begin(iter, NULL, 0, 0, NULL); + rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL); } static void rna_Lattice_points_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { Lattice *lt= (Lattice*)ptr->data; + int tot= lt->pntsu*lt->pntsv*lt->pntsw; - if(lt->def) { - int tot= lt->pntsu*lt->pntsv*lt->pntsw; - rna_iterator_array_begin(iter, (void*)lt->def, sizeof(BPoint), tot, NULL); - } + if(lt->editlatt && lt->editlatt->def) + rna_iterator_array_begin(iter, (void*)lt->editlatt->def, sizeof(BPoint), tot, 0, NULL); + else if(lt->def) + rna_iterator_array_begin(iter, (void*)lt->def, sizeof(BPoint), tot, 0, NULL); else - rna_iterator_array_begin(iter, NULL, 0, 0, NULL); + rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL); +} + +static void rna_Lattice_update_data(bContext *C, PointerRNA *ptr) +{ + Main *bmain= CTX_data_main(C); + Scene *scene= CTX_data_scene(C); + Lattice *lt= ptr->id.data; + Object *ob; + + for(ob=bmain->object.first; ob; ob= ob->id.next) { + if(ob->data == lt) { + /* XXX this will loop over all objects again (slow) */ + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob); + } + } +} + +static void rna_Lattice_update_size(bContext *C, PointerRNA *ptr) +{ + Main *bmain= CTX_data_main(C); + Lattice *lt= ptr->id.data; + Object *ob; + int newu, newv, neww; + + /* we don't modify the actual pnts, but go through opnts instead */ + newu= (lt->opntsu > 0)? lt->opntsu: lt->pntsu; + newv= (lt->opntsv > 0)? lt->opntsv: lt->pntsv; + neww= (lt->opntsw > 0)? lt->opntsw: lt->pntsw; + + /* resizelattice needs an object, any object will have the same result */ + for(ob=bmain->object.first; ob; ob= ob->id.next) { + if(ob->data == lt) { + resizelattice(lt, newu, newv, neww, ob); + if(lt->editlatt) + resizelattice(lt->editlatt, newu, newv, neww, ob); + break; + } + } + + /* otherwise without, means old points are not repositioned */ + if(!ob) { + resizelattice(lt, newu, newv, neww, NULL); + if(lt->editlatt) + resizelattice(lt->editlatt, newu, newv, neww, NULL); + } + + rna_Lattice_update_data(C, ptr); +} + +static void rna_Lattice_outside_set(PointerRNA *ptr, int value) +{ + Lattice *lt= ptr->data; + + if(value) lt->flag |= LT_OUTSIDE; + else lt->flag &= ~LT_OUTSIDE; + + outside_lattice(lt); + + if(lt->editlatt) { + if(value) lt->editlatt->flag |= LT_OUTSIDE; + else lt->editlatt->flag &= ~LT_OUTSIDE; + + outside_lattice(lt->editlatt); + } +} + +static void rna_Lattice_points_u_set(PointerRNA *ptr, int value) +{ + ((Lattice*)ptr->data)->opntsu= CLAMPIS(value, 1, 64); +} + +static void rna_Lattice_points_v_set(PointerRNA *ptr, int value) +{ + ((Lattice*)ptr->data)->opntsv= CLAMPIS(value, 1, 64); +} + +static void rna_Lattice_points_w_set(PointerRNA *ptr, int value) +{ + ((Lattice*)ptr->data)->opntsw= CLAMPIS(value, 1, 64); } #else @@ -97,9 +188,10 @@ static void rna_def_latticepoint(BlenderRNA *brna) RNA_def_property_float_sdna(prop, NULL, "vec"); RNA_def_property_array(prop, 3); RNA_def_property_ui_text(prop, "Deformed Location", ""); + RNA_def_property_update(prop, 0, "rna_Lattice_update_data"); prop= RNA_def_property(srna, "groups", PROP_COLLECTION, PROP_NONE); - 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); + 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, 0, 0); RNA_def_property_struct_type(prop, "VertexGroupElement"); RNA_def_property_ui_text(prop, "Groups", "Weights for the vertex groups this point is member of."); } @@ -110,10 +202,10 @@ static void rna_def_lattice(BlenderRNA *brna) PropertyRNA *prop; static EnumPropertyItem prop_keyblock_type_items[] = { - {KEY_LINEAR, "KEY_LINEAR", "Linear", ""}, - {KEY_CARDINAL, "KEY_CARDINAL", "Cardinal", ""}, - {KEY_BSPLINE, "KEY_BSPLINE", "BSpline", ""}, - {0, NULL, NULL, NULL}}; + {KEY_LINEAR, "KEY_LINEAR", 0, "Linear", ""}, + {KEY_CARDINAL, "KEY_CARDINAL", 0, "Cardinal", ""}, + {KEY_BSPLINE, "KEY_BSPLINE", 0, "BSpline", ""}, + {0, NULL, 0, NULL, NULL}}; srna= RNA_def_struct(brna, "Lattice", "ID"); RNA_def_struct_ui_text(srna, "Lattice", "Lattice datablock defining a grid for deforming other objects."); @@ -121,37 +213,48 @@ static void rna_def_lattice(BlenderRNA *brna) prop= RNA_def_property(srna, "points_u", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "pntsu"); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_int_funcs(prop, NULL, "rna_Lattice_points_u_set", NULL); + RNA_def_property_range(prop, 1, 64); RNA_def_property_ui_text(prop, "U", "Points in U direction."); + RNA_def_property_update(prop, 0, "rna_Lattice_update_size"); prop= RNA_def_property(srna, "points_v", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "pntsv"); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_int_funcs(prop, NULL, "rna_Lattice_points_v_set", NULL); + RNA_def_property_range(prop, 1, 64); RNA_def_property_ui_text(prop, "V", "Points in V direction."); + RNA_def_property_update(prop, 0, "rna_Lattice_update_size"); prop= RNA_def_property(srna, "points_w", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "pntsw"); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_int_funcs(prop, NULL, "rna_Lattice_points_w_set", NULL); + RNA_def_property_range(prop, 1, 64); RNA_def_property_ui_text(prop, "W", "Points in W direction."); + RNA_def_property_update(prop, 0, "rna_Lattice_update_size"); prop= RNA_def_property(srna, "interpolation_type_u", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "typeu"); RNA_def_property_enum_items(prop, prop_keyblock_type_items); RNA_def_property_ui_text(prop, "Interpolation Type U", ""); + RNA_def_property_update(prop, 0, "rna_Lattice_update_data"); prop= RNA_def_property(srna, "interpolation_type_v", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "typev"); RNA_def_property_enum_items(prop, prop_keyblock_type_items); RNA_def_property_ui_text(prop, "Interpolation Type V", ""); + RNA_def_property_update(prop, 0, "rna_Lattice_update_data"); prop= RNA_def_property(srna, "interpolation_type_w", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "typew"); RNA_def_property_enum_items(prop, prop_keyblock_type_items); RNA_def_property_ui_text(prop, "Interpolation Type W", ""); + RNA_def_property_update(prop, 0, "rna_Lattice_update_data"); prop= RNA_def_property(srna, "outside", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", LT_OUTSIDE); + RNA_def_property_boolean_funcs(prop, NULL, "rna_Lattice_outside_set"); RNA_def_property_ui_text(prop, "Outside", "Only draw, and take into account, the outer vertices."); + RNA_def_property_update(prop, 0, "rna_Lattice_update_data"); prop= RNA_def_property(srna, "shape_keys", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "key"); @@ -159,7 +262,7 @@ static void rna_def_lattice(BlenderRNA *brna) prop= RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "LatticePoint"); - 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); + 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, 0, 0); RNA_def_property_ui_text(prop, "Points", "Points of the lattice."); } |