diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-12-21 18:55:10 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-12-21 18:55:10 +0300 |
commit | 29ea21e6bd6d6813a6b8fd58d7085e9efce9b494 (patch) | |
tree | ef8a9cd7c9ccdf4b6d62fe455ebcd29e61354b76 | |
parent | 4d32e002edf9075c168a61b5ea4657c982ff23e2 (diff) |
Multires: added back Reshape function, to copy vertex locations
from another mesh.
-rw-r--r-- | release/scripts/ui/properties_data_modifier.py | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/multires.c | 75 | ||||
-rw-r--r-- | source/blender/editors/object/object_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/object/object_modifier.c | 45 | ||||
-rw-r--r-- | source/blender/editors/object/object_ops.c | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 2 |
6 files changed, 83 insertions, 42 deletions
diff --git a/release/scripts/ui/properties_data_modifier.py b/release/scripts/ui/properties_data_modifier.py index 97237c26191..0de819b0537 100644 --- a/release/scripts/ui/properties_data_modifier.py +++ b/release/scripts/ui/properties_data_modifier.py @@ -445,6 +445,7 @@ class DATA_PT_modifiers(DataButtonsPanel): col.enabled = ob.mode != 'EDIT' col.operator("object.multires_subdivide", text="Subdivide") col.operator("object.multires_higher_levels_delete", text="Delete Higher") + col.operator("object.multires_reshape", text="Reshape") col.prop(md, "optimal_display") layout.separator() diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 88c6788b723..f5414567da8 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -63,6 +63,7 @@ static const int multires_max_levels = 13; static const int multires_grid_tot[] = {0, 4, 9, 25, 81, 289, 1089, 4225, 16641, 66049, 263169, 1050625, 4198401, 16785409}; static const int multires_side_tot[] = {0, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097}; +static void multires_mvert_to_ss(DerivedMesh *dm, MVert *mvert); static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, int invert, int add, DMGridData **oldGridData, int totlvl); MultiresModifierData *find_multires_modifier(Object *ob) @@ -106,6 +107,27 @@ static void multires_set_tot_level(Object *ob, MultiresModifierData *mmd, int lv CLAMP(mmd->renderlvl, 0, mmd->totlvl); } +static void multires_dm_mark_as_modified(DerivedMesh *dm) +{ + CCGDerivedMesh *ccgdm = (CCGDerivedMesh*)dm; + ccgdm->multires.modified = 1; +} + +void multires_mark_as_modified(Object *ob) +{ + if(ob && ob->derivedFinal) + multires_dm_mark_as_modified(ob->derivedFinal); +} + +void multires_force_update(Object *ob) +{ + if(ob && ob->derivedFinal) { + ob->derivedFinal->needsFree =1; + ob->derivedFinal->release(ob->derivedFinal); + ob->derivedFinal = NULL; + } +} + /* XXX */ #if 0 void multiresModifier_join(Object *ob) @@ -168,30 +190,22 @@ void multiresModifier_join(Object *ob) } #endif -/* Returns 0 on success, 1 if the src's totvert doesn't match */ +/* Returns 1 on success, 0 if the src's totvert doesn't match */ int multiresModifier_reshape(MultiresModifierData *mmd, Object *dst, Object *src) { - /* XXX */ -#if 0 - Mesh *src_me = get_mesh(src); + DerivedMesh *srcdm = src->derivedFinal; DerivedMesh *mrdm = dst->derivedFinal; - if(mrdm && mrdm->getNumVerts(mrdm) == src_me->totvert) { - MVert *mvert = CDDM_get_verts(mrdm); - int i; + if(mrdm && srcdm && mrdm->getNumVerts(mrdm) == srcdm->getNumVerts(srcdm)) { + multires_mvert_to_ss(mrdm, srcdm->getVertArray(srcdm)); - for(i = 0; i < src_me->totvert; ++i) - copy_v3_v3(mvert[i].co, src_me->mvert[i].co); - mrdm->needsFree = 1; - MultiresDM_mark_as_modified(mrdm); - mrdm->release(mrdm); - dst->derivedFinal = NULL; + multires_dm_mark_as_modified(mrdm); + multires_force_update(dst); - return 0; + return 1; } -#endif - return 1; + return 0; } static void column_vectors_to_mat3(float mat[][3], float v1[3], float v2[3], float v3[3]) @@ -242,7 +256,7 @@ static void multires_copy_dm_grid(DMGridData *gridA, DMGridData *gridB, int size } /* direction=1 for delete higher, direction=0 for lower (not implemented yet) */ -void multiresModifier_del_levels(struct MultiresModifierData *mmd, struct Object *ob, int direction) +void multiresModifier_del_levels(MultiresModifierData *mmd, Object *ob, int direction) { Mesh *me = get_mesh(ob); int lvl = multires_get_level(ob, mmd, 0); @@ -621,27 +635,6 @@ static void multiresModifier_update(DerivedMesh *dm) } } -static void multires_dm_mark_as_modified(struct DerivedMesh *dm) -{ - CCGDerivedMesh *ccgdm = (CCGDerivedMesh*)dm; - ccgdm->multires.modified = 1; -} - -void multires_mark_as_modified(struct Object *ob) -{ - if(ob && ob->derivedFinal) - multires_dm_mark_as_modified(ob->derivedFinal); -} - -void multires_force_update(Object *ob) -{ - if(ob && ob->derivedFinal) { - ob->derivedFinal->needsFree =1; - ob->derivedFinal->release(ob->derivedFinal); - ob->derivedFinal = NULL; - } -} - void multires_stitch_grids(Object *ob) { /* utility for smooth brush */ @@ -661,7 +654,7 @@ void multires_stitch_grids(Object *ob) } } -struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, int local_mmd, DerivedMesh *dm, Object *ob, +DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, int local_mmd, DerivedMesh *dm, Object *ob, int useRenderParams, int isFinalCalc) { Mesh *me= ob->data; @@ -973,7 +966,7 @@ static void multires_load_old_faces(ListBase **fmap, ListBase **emap, MultiresLe } } -static void multires_old_mvert_to_ss(DerivedMesh *dm, MVert *mvert) +static void multires_mvert_to_ss(DerivedMesh *dm, MVert *mvert) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm; CCGSubSurf *ss = ccgdm->ss; @@ -1197,7 +1190,7 @@ static void multires_load_old_dm(DerivedMesh *dm, Mesh *me, int totlvl) MEM_freeN(vvmap); - multires_old_mvert_to_ss(dm, vdst); + multires_mvert_to_ss(dm, vdst); } diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 848855da1b0..562216e5890 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -142,6 +142,7 @@ void OBJECT_OT_modifier_apply(struct wmOperatorType *ot); void OBJECT_OT_modifier_convert(struct wmOperatorType *ot); void OBJECT_OT_modifier_copy(struct wmOperatorType *ot); void OBJECT_OT_multires_subdivide(struct wmOperatorType *ot); +void OBJECT_OT_multires_reshape(struct wmOperatorType *ot); void OBJECT_OT_multires_higher_levels_delete(struct wmOperatorType *ot); void OBJECT_OT_multires_save_external(struct wmOperatorType *ot); void OBJECT_OT_multires_pack_external(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 06c31e9f1a9..552de1f8f60 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -814,6 +814,51 @@ void OBJECT_OT_multires_subdivide(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +/****************** multires reshape operator *********************/ + +static int multires_reshape_exec(bContext *C, wmOperator *op) +{ + PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_MultiresModifier); + Object *ob= ptr.id.data, *secondob= NULL; + MultiresModifierData *mmd= ptr.data; + + CTX_DATA_BEGIN(C, Object*, selob, selected_editable_objects) { + if(selob->type == OB_MESH && selob != ob) { + secondob= selob; + break; + } + } + CTX_DATA_END; + + if(!secondob) { + BKE_report(op->reports, RPT_ERROR, "Second selected mesh object require to copy shape from."); + return OPERATOR_CANCELLED; + } + + if(!multiresModifier_reshape(mmd, ob, secondob)) { + BKE_report(op->reports, RPT_ERROR, "Objects do not have the same number of vertices."); + return OPERATOR_CANCELLED; + } + + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_multires_reshape(wmOperatorType *ot) +{ + ot->name= "Multires Reshape"; + ot->description= "Copy vertex coordinates from other object."; + ot->idname= "OBJECT_OT_multires_reshape"; + + ot->poll= multires_poll; + ot->exec= multires_reshape_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + /****************** multires save external operator *********************/ static int multires_save_external_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index dbd03561c20..bd43e9c24c4 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -135,6 +135,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_modifier_convert); WM_operatortype_append(OBJECT_OT_modifier_copy); WM_operatortype_append(OBJECT_OT_multires_subdivide); + WM_operatortype_append(OBJECT_OT_multires_reshape); WM_operatortype_append(OBJECT_OT_multires_higher_levels_delete); WM_operatortype_append(OBJECT_OT_multires_save_external); WM_operatortype_append(OBJECT_OT_multires_pack_external); diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index c6aef8df407..fe8d6d6a367 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -55,9 +55,9 @@ EnumPropertyItem modifier_type_items[] ={ {eModifierType_Mask, "MASK", ICON_MOD_MASK, "Mask", ""}, {eModifierType_Mirror, "MIRROR", ICON_MOD_MIRROR, "Mirror", ""}, {eModifierType_Multires, "MULTIRES", ICON_MOD_MULTIRES, "Multiresolution", ""}, + {eModifierType_Solidify, "SOLIDIFY", ICON_MOD_DISPLACE, "Solidify", ""}, {eModifierType_Subsurf, "SUBSURF", ICON_MOD_SUBSURF, "Subdivision Surface", ""}, {eModifierType_UVProject, "UV_PROJECT", ICON_MOD_UVPROJECT, "UV Project", ""}, - {eModifierType_Solidify, "SOLIDIFY", ICON_MOD_DISPLACE, "Solidify", ""}, {0, "", 0, "Deform", ""}, {eModifierType_Armature, "ARMATURE", ICON_MOD_ARMATURE, "Armature", ""}, {eModifierType_Cast, "CAST", ICON_MOD_CAST, "Cast", ""}, |