Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_transform.c
| Show All 32 Lines | |||||
| #include "DNA_anim_types.h" | #include "DNA_anim_types.h" | ||||
| #include "DNA_armature_types.h" | #include "DNA_armature_types.h" | ||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meta_types.h" | #include "DNA_meta_types.h" | ||||
| #include "DNA_lamp_types.h" | #include "DNA_lamp_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_gpencil_types.h" | |||||
| #include "DNA_group_types.h" | #include "DNA_group_types.h" | ||||
| #include "DNA_lattice_types.h" | #include "DNA_lattice_types.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_array.h" | #include "BLI_array.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_idcode.h" | #include "BKE_idcode.h" | ||||
| #include "BKE_mball.h" | #include "BKE_mball.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_multires.h" | #include "BKE_multires.h" | ||||
| #include "BKE_armature.h" | #include "BKE_armature.h" | ||||
| #include "BKE_lattice.h" | #include "BKE_lattice.h" | ||||
| #include "BKE_tracking.h" | #include "BKE_tracking.h" | ||||
| #include "BKE_gpencil.h" | |||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "ED_armature.h" | #include "ED_armature.h" | ||||
| #include "ED_keyframing.h" | #include "ED_keyframing.h" | ||||
| #include "ED_mesh.h" | #include "ED_mesh.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_view3d.h" | #include "ED_view3d.h" | ||||
| #include "ED_gpencil.h" | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "object_intern.h" | #include "object_intern.h" | ||||
| /*************************** Clear Transformation ****************************/ | /*************************** Clear Transformation ****************************/ | ||||
| /* clear location of object */ | /* clear location of object */ | ||||
| ▲ Show 20 Lines • Show All 345 Lines • ▼ Show 20 Lines | static int apply_objects_internal( | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_depsgraph(C); | ||||
| float rsmat[3][3], obmat[3][3], iobmat[3][3], mat[4][4], scale; | float rsmat[3][3], obmat[3][3], iobmat[3][3], mat[4][4], scale; | ||||
| bool changed = true; | bool changed = true; | ||||
| /* first check if we can execute */ | /* first check if we can execute */ | ||||
| CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) | CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) | ||||
| { | { | ||||
| if (ELEM(ob->type, OB_MESH, OB_ARMATURE, OB_LATTICE, OB_MBALL, OB_CURVE, OB_SURF, OB_FONT)) { | if (ELEM(ob->type, OB_MESH, OB_ARMATURE, OB_LATTICE, OB_MBALL, OB_CURVE, OB_SURF, OB_FONT, OB_GPENCIL)) { | ||||
| ID *obdata = ob->data; | ID *obdata = ob->data; | ||||
| if (ID_REAL_USERS(obdata) > 1) { | if (ID_REAL_USERS(obdata) > 1) { | ||||
| BKE_reportf(reports, RPT_ERROR, | BKE_reportf(reports, RPT_ERROR, | ||||
| "Cannot apply to a multi user: Object \"%s\", %s \"%s\", aborting", | "Cannot apply to a multi user: Object \"%s\", %s \"%s\", aborting", | ||||
| ob->id.name + 2, BKE_idcode_to_name(GS(obdata->name)), obdata->name + 2); | ob->id.name + 2, BKE_idcode_to_name(GS(obdata->name)), obdata->name + 2); | ||||
| changed = false; | changed = false; | ||||
| } | } | ||||
| Show All 29 Lines | if (ob->type == OB_FONT) { | ||||
| if (apply_rot || apply_loc) { | if (apply_rot || apply_loc) { | ||||
| BKE_reportf(reports, RPT_ERROR, | BKE_reportf(reports, RPT_ERROR, | ||||
| "Font's can only have scale applied: \"%s\"", | "Font's can only have scale applied: \"%s\"", | ||||
| ob->id.name + 2); | ob->id.name + 2); | ||||
| changed = false; | changed = false; | ||||
| } | } | ||||
| } | } | ||||
| if (ob->type == OB_GPENCIL) { | |||||
| bGPdata *gpd = ob->data; | |||||
| if (gpd) { | |||||
| if (gpd->layers.first) { | |||||
| /* Unsupported configuration */ | |||||
| bool has_unparented_layers = false; | |||||
| for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | |||||
| /* Parented layers aren't supported as we can't easily re-evaluate the scene to sample parent movement */ | |||||
| if (gpl->parent == NULL) { | |||||
| has_unparented_layers = true; | |||||
| break; | |||||
| } | |||||
| } | |||||
| if (has_unparented_layers == false) { | |||||
| BKE_reportf(reports, RPT_ERROR, | |||||
| "Can't apply to a GP datablock where all layers are parented: Object \"%s\", %s \"%s\", aborting", | |||||
| ob->id.name + 2, BKE_idcode_to_name(ID_GD), gpd->id.name + 2); | |||||
| changed = false; | |||||
| } | |||||
| } | |||||
| else { | |||||
| /* No layers/data */ | |||||
| BKE_reportf(reports, RPT_ERROR, | |||||
| "Can't apply to GP datablock with no layers: Object \"%s\", %s \"%s\", aborting", | |||||
| ob->id.name + 2, BKE_idcode_to_name(ID_GD), gpd->id.name + 2); | |||||
| } | |||||
| } | |||||
| } | |||||
| if (ob->type == OB_LAMP) { | if (ob->type == OB_LAMP) { | ||||
| Lamp *la = ob->data; | Lamp *la = ob->data; | ||||
| if (la->type == LA_AREA) { | if (la->type == LA_AREA) { | ||||
| if (apply_rot || apply_loc) { | if (apply_rot || apply_loc) { | ||||
| BKE_reportf(reports, RPT_ERROR, | BKE_reportf(reports, RPT_ERROR, | ||||
| "Area Lights can only have scale applied: \"%s\"", | "Area Lights can only have scale applied: \"%s\"", | ||||
| ob->id.name + 2); | ob->id.name + 2); | ||||
| changed = false; | changed = false; | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | else if (ob->type == OB_FONT) { | ||||
| tb->w *= scale; | tb->w *= scale; | ||||
| tb->h *= scale; | tb->h *= scale; | ||||
| } | } | ||||
| if (do_props) { | if (do_props) { | ||||
| cu->fsize *= scale; | cu->fsize *= scale; | ||||
| } | } | ||||
| } | } | ||||
| else if (ob->type == OB_GPENCIL) { | |||||
| bGPdata *gpd = ob->data; | |||||
| BKE_gpencil_transform(gpd, mat); | |||||
| } | |||||
| else if (ob->type == OB_CAMERA) { | else if (ob->type == OB_CAMERA) { | ||||
| MovieClip *clip = BKE_object_movieclip_get(scene, ob, false); | MovieClip *clip = BKE_object_movieclip_get(scene, ob, false); | ||||
| /* applying scale on camera actually scales clip's reconstruction. | /* applying scale on camera actually scales clip's reconstruction. | ||||
| * of there's clip assigned to camera nothing to do actually. | * of there's clip assigned to camera nothing to do actually. | ||||
| */ | */ | ||||
| if (!clip) | if (!clip) | ||||
| continue; | continue; | ||||
| ▲ Show 20 Lines • Show All 453 Lines • ▼ Show 20 Lines | #endif | ||||
| negate_v3_v3(cent_neg, cent); | negate_v3_v3(cent_neg, cent); | ||||
| BKE_lattice_translate(lt, cent_neg, 1); | BKE_lattice_translate(lt, cent_neg, 1); | ||||
| tot_change++; | tot_change++; | ||||
| lt->id.tag |= LIB_TAG_DOIT; | lt->id.tag |= LIB_TAG_DOIT; | ||||
| do_inverse_offset = true; | do_inverse_offset = true; | ||||
| } | } | ||||
| else if (ob->type == OB_GPENCIL) { | |||||
| bGPdata *gpd = ob->data; | |||||
| float gpcenter[3]; | |||||
| if (gpd) { | |||||
| if (centermode == ORIGIN_TO_GEOMETRY) { | |||||
| zero_v3(gpcenter); | |||||
| BKE_gpencil_centroid_3D(gpd, gpcenter); | |||||
| add_v3_v3(gpcenter, ob->obmat[3]); | |||||
| } | |||||
| if (centermode == ORIGIN_TO_CURSOR) { | |||||
| copy_v3_v3(gpcenter, cursor); | |||||
| } | |||||
| if ((centermode == ORIGIN_TO_GEOMETRY) || (centermode == ORIGIN_TO_CURSOR)) { | |||||
| bGPDspoint *pt; | |||||
| float imat[3][3], bmat[3][3]; | |||||
| float offset_global[3]; | |||||
| float offset_local[3]; | |||||
| int i; | |||||
| sub_v3_v3v3(offset_global, gpcenter, ob->obmat[3]); | |||||
| copy_m3_m4(bmat, obact->obmat); | |||||
| invert_m3_m3(imat, bmat); | |||||
| mul_m3_v3(imat, offset_global); | |||||
| mul_v3_m3v3(offset_local, imat, offset_global); | |||||
| float diff_mat[4][4]; | |||||
| float inverse_diff_mat[4][4]; | |||||
| /* recalculate all strokes (all layers are considered without evaluating lock attributtes) */ | |||||
| for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | |||||
| /* calculate difference matrix */ | |||||
| ED_gpencil_parent_location(depsgraph, obact, gpd, gpl, diff_mat); | |||||
| /* undo matrix */ | |||||
| invert_m4_m4(inverse_diff_mat, diff_mat); | |||||
| for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { | |||||
| for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { | |||||
| /* skip strokes that are invalid for current view */ | |||||
| if (ED_gpencil_stroke_can_use(C, gps) == false) | |||||
| continue; | |||||
| for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { | |||||
| float mpt[3]; | |||||
| mul_v3_m4v3(mpt, inverse_diff_mat, &pt->x); | |||||
| sub_v3_v3(mpt, offset_local); | |||||
| mul_v3_m4v3(&pt->x, diff_mat, mpt); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| DEG_id_tag_update(&gpd->id, OB_RECALC_OB | OB_RECALC_DATA); | |||||
| tot_change++; | |||||
| if (centermode == ORIGIN_TO_GEOMETRY) { | |||||
| copy_v3_v3(ob->loc, gpcenter); | |||||
| } | |||||
| ob->id.tag |= LIB_TAG_DOIT; | |||||
| do_inverse_offset = true; | |||||
| } | |||||
| else { | |||||
| BKE_report(op->reports, RPT_WARNING, "Grease Pencil Object does not support this set origin option"); | |||||
| } | |||||
| } | |||||
| } | |||||
| /* offset other selected objects */ | /* offset other selected objects */ | ||||
| if (do_inverse_offset && (centermode != GEOMETRY_TO_ORIGIN)) { | if (do_inverse_offset && (centermode != GEOMETRY_TO_ORIGIN)) { | ||||
| CollectionPointerLink *ctx_link_other; | CollectionPointerLink *ctx_link_other; | ||||
| float obmat[4][4]; | float obmat[4][4]; | ||||
| /* was the object data modified | /* was the object data modified | ||||
| * note: the functions above must set 'cent' */ | * note: the functions above must set 'cent' */ | ||||
| ▲ Show 20 Lines • Show All 493 Lines • Show Last 20 Lines | |||||