Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Ebb <matt@mke3.net>2009-11-28 07:04:01 +0300
committerMatt Ebb <matt@mke3.net>2009-11-28 07:04:01 +0300
commitaa3ed478483e02101d7ee04d9118f5ecca066a8e (patch)
treed989b5c35b16c535b49f046a381595a2159f121b /source/blender/editors/object/object_modifier.c
parent54c5859578362976cc54b4e04f0a513117b4698e (diff)
* New tool - Join as Shapes
Available in object mode (Object -> Join as Shapes), only works for meshes at the present. Will merge all selected objects as shape keys on the active object, if the vertex count is the same. This does not keep references to the external objects like in some applications, rather it's a quick way to update the shapes on the active object (perhaps after importing new versions from external applications).
Diffstat (limited to 'source/blender/editors/object/object_modifier.c')
-rw-r--r--source/blender/editors/object/object_modifier.c166
1 files changed, 87 insertions, 79 deletions
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 58f2ed443ca..7bb5eb6f63b 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -331,119 +331,127 @@ int ED_object_modifier_convert(ReportList *reports, Scene *scene, Object *ob, Mo
return 1;
}
-int ED_object_modifier_apply(ReportList *reports, Scene *scene, Object *ob, ModifierData *md, int mode)
+static int modifier_apply_shape(ReportList *reports, Scene *scene, Object *ob, ModifierData *md)
{
- DerivedMesh *dm;
- Mesh *me = ob->data;
- int converted = 0;
+ if (ob->type==OB_MESH) {
+ DerivedMesh *dm;
+ Mesh *me= ob->data;
+ Key *key=me->key;
+ KeyBlock *kb;
+
+ if(!modifier_sameTopology(md)) {
+ BKE_report(reports, RPT_ERROR, "Only deforming modifiers can be applied to Shapes");
+ return 0;
+ }
+ mesh_pmv_off(ob, me);
+
+ dm = mesh_create_derived_for_modifier(scene, ob, md);
+ if (!dm) {
+ BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply");
+ return 0;
+ }
+
+ if(key == NULL) {
+ key= me->key= add_key((ID *)me);
+ key->type= KEY_RELATIVE;
+ /* if that was the first key block added, then it was the basis.
+ * Initialise it with the mesh, and add another for the modifier */
+ kb= add_keyblock(scene, key);
+ mesh_to_key(me, kb);
+ }
- if (scene->obedit) {
- BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied in editmode");
- return 0;
- } else if (((ID*) ob->data)->us>1) {
- BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied to multi-user data");
+ kb= add_keyblock(scene, key);
+ DM_to_meshkey(dm, me, kb);
+
+ dm->release(dm);
+ }
+ else {
+ BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type");
return 0;
}
+ return 1;
+}
- if (md!=ob->modifiers.first)
- BKE_report(reports, RPT_INFO, "Applied modifier was not first, result may not be as expected.");
-
+static int modifier_apply_obdata(ReportList *reports, Scene *scene, Object *ob, ModifierData *md)
+{
if (ob->type==OB_MESH) {
- if (mode == MODIFIER_APPLY_SHAPE) {
- Key *key=me->key;
- KeyBlock *kb;
- int newkey=0;
-
- if(!modifier_sameTopology(md)) {
- BKE_report(reports, RPT_ERROR, "Only deforming modifiers can be applied to Shapes");
- return 0;
- }
- mesh_pmv_off(ob, me);
-
- dm = mesh_create_derived_for_modifier(scene, ob, md);
- if (!dm) {
- BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply");
- return 0;
- }
-
- if(key == NULL) {
- key= me->key= add_key((ID *)me);
- key->type= KEY_RELATIVE;
- newkey= 1;
- }
- kb= add_keyblock(scene, key);
-
- if (newkey) {
- /* if that was the first key block added, then it was the basis.
- * Initialise it with the mesh, and add another for the modifier */
- mesh_to_key(me, kb);
- kb= add_keyblock(scene, key);
- }
- DM_to_meshkey(dm, me, kb);
- converted = 1;
-
- dm->release(dm);
+ DerivedMesh *dm;
+ Mesh *me = ob->data;
+ if( me->key) {
+ BKE_report(reports, RPT_ERROR, "Modifier cannot be applied to Mesh with Shape Keys");
+ return 0;
}
- else { /* MODIFIER_APPLY_DATA */
- if( me->key) {
- BKE_report(reports, RPT_ERROR, "Modifier cannot be applied to Mesh with Shape Keys");
- return 0;
- }
-
- mesh_pmv_off(ob, me);
-
- /* Multires: ensure that recent sculpting is applied */
- if(md->type == eModifierType_Multires)
- multires_force_update(ob);
-
- dm = mesh_create_derived_for_modifier(scene, ob, md);
- if (!dm) {
- BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply");
- return 0;
- }
-
- DM_to_mesh(dm, me);
- converted = 1;
-
- dm->release(dm);
+
+ mesh_pmv_off(ob, me);
+
+ /* Multires: ensure that recent sculpting is applied */
+ if(md->type == eModifierType_Multires)
+ multires_force_update(ob);
+
+ dm = mesh_create_derived_for_modifier(scene, ob, md);
+ if (!dm) {
+ BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply");
+ return 0;
}
+
+ DM_to_mesh(dm, me);
+
+ dm->release(dm);
}
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
Curve *cu = ob->data;
int numVerts;
float (*vertexCos)[3];
-
+
+
BKE_report(reports, RPT_INFO, "Applied modifier only changed CV points, not tesselated/bevel vertices");
-
+
if (!(md->mode&eModifierMode_Realtime) || (mti->isDisabled && mti->isDisabled(md))) {
BKE_report(reports, RPT_ERROR, "Modifier is disabled, skipping apply");
return 0;
}
-
+
vertexCos = curve_getVertexCos(cu, &cu->nurb, &numVerts);
mti->deformVerts(md, ob, NULL, vertexCos, numVerts, 0, 0);
curve_applyVertexCos(cu, &cu->nurb, vertexCos);
- converted = 1;
-
MEM_freeN(vertexCos);
-
+
DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
}
else {
BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type");
return 0;
}
+ return 1;
+}
- if (converted) {
- BLI_remlink(&ob->modifiers, md);
- modifier_free(md);
+int ED_object_modifier_apply(ReportList *reports, Scene *scene, Object *ob, ModifierData *md, int mode)
+{
+ if (scene->obedit) {
+ BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied in editmode");
+ return 0;
+ } else if (((ID*) ob->data)->us>1) {
+ BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied to multi-user data");
+ return 0;
+ }
+
+ if (md!=ob->modifiers.first)
+ BKE_report(reports, RPT_INFO, "Applied modifier was not first, result may not be as expected.");
- return 1;
+ if (mode == MODIFIER_APPLY_SHAPE) {
+ if (!modifier_apply_shape(reports, scene, ob, md))
+ return 0;
+ } else {
+ if (!modifier_apply_obdata(reports, scene, ob, md))
+ return 0;
}
- return 0;
+ BLI_remlink(&ob->modifiers, md);
+ modifier_free(md);
+
+ return 1;
}
int ED_object_modifier_copy(ReportList *reports, Object *ob, ModifierData *md)