Orientation for 3D cursor
[blender.git] / source / blender / editors / object / object_transform.c
index bb23f871a256d9ccd5a9818e22084ca666d32504..0db880a22c6ca084a3bc8ba431e53cd746a1e756 100644 (file)
@@ -35,6 +35,7 @@
 #include "DNA_armature_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meta_types.h"
+#include "DNA_lamp_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_group_types.h"
@@ -408,15 +409,13 @@ static void ignore_parent_tx(const bContext *C, Main *bmain, Scene *scene, Objec
 {
        Object workob;
        Object *ob_child;
-       EvaluationContext eval_ctx;
-
-       CTX_data_eval_ctx(C, &eval_ctx);
+       Depsgraph *depsgraph = CTX_data_depsgraph(C);
        
        /* a change was made, adjust the children to compensate */
        for (ob_child = bmain->object.first; ob_child; ob_child = ob_child->id.next) {
                if (ob_child->parent == ob) {
                        BKE_object_apply_mat4(ob_child, ob_child->obmat, true, false);
-                       BKE_object_workob_calc_parent(&eval_ctx, scene, ob_child, &workob);
+                       BKE_object_workob_calc_parent(depsgraph, scene, ob_child, &workob);
                        invert_m4_m4(ob_child->parentinv, workob.obmat);
                }
        }
@@ -429,12 +428,10 @@ static int apply_objects_internal(
 {
        Main *bmain = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
-       EvaluationContext eval_ctx;
+       Depsgraph *depsgraph = CTX_data_depsgraph(C);
        float rsmat[3][3], obmat[3][3], iobmat[3][3], mat[4][4], scale;
        bool changed = true;
 
-       CTX_data_eval_ctx(C, &eval_ctx);
-       
        /* first check if we can execute */
        CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
        {
@@ -483,6 +480,18 @@ static int apply_objects_internal(
                                changed = false;
                        }
                }
+
+               if (ob->type == OB_LAMP) {
+                       Lamp *la = ob->data;
+                       if (la->type == LA_AREA) {
+                               if (apply_rot || apply_loc) {
+                                       BKE_reportf(reports, RPT_ERROR,
+                                                   "Area Lamps can only have scale applied: \"%s\"",
+                                                   ob->id.name + 2);
+                                       changed = false;
+                               }
+                       }
+               }
        }
        CTX_DATA_END;
        
@@ -536,7 +545,7 @@ static int apply_objects_internal(
                        Mesh *me = ob->data;
 
                        if (apply_scale)
-                               multiresModifier_scale_disp(&eval_ctx, scene, ob);
+                               multiresModifier_scale_disp(depsgraph, scene, ob);
                        
                        /* adjust data */
                        BKE_mesh_transform(me, mat, true);
@@ -545,7 +554,7 @@ static int apply_objects_internal(
                        BKE_mesh_calc_normals(me);
                }
                else if (ob->type == OB_ARMATURE) {
-                       ED_armature_apply_transform(ob, mat, do_props);
+                       ED_armature_transform_apply(ob, mat, do_props);
                }
                else if (ob->type == OB_LATTICE) {
                        Lattice *lt = ob->data;
@@ -612,6 +621,22 @@ static int apply_objects_internal(
                                ob->empty_drawsize *= max_scale;
                        }
                }
+               else if (ob->type == OB_LAMP) {
+                       Lamp *la = ob->data;
+                       if (la->type != LA_AREA) {
+                               continue;
+                       }
+
+                       bool keeps_aspect_ratio = compare_ff_relative(rsmat[0][0], rsmat[1][1], FLT_EPSILON, 64);
+                       if ((la->area_shape == LA_AREA_SQUARE) && !keeps_aspect_ratio) {
+                               la->area_shape = LA_AREA_RECT;
+                               la->area_sizey = la->area_size;
+                       }
+
+                       la->area_size *= rsmat[0][0];
+                       la->area_sizey *= rsmat[1][1];
+                       la->area_sizez *= rsmat[2][2];
+               }
                else {
                        continue;
                }
@@ -626,9 +651,9 @@ static int apply_objects_internal(
                        unit_axis_angle(ob->rotAxis, &ob->rotAngle);
                }
 
-               BKE_object_where_is_calc(&eval_ctx, scene, ob);
+               BKE_object_where_is_calc(depsgraph, scene, ob);
                if (ob->type == OB_ARMATURE) {
-                       BKE_pose_where_is(&eval_ctx, scene, ob); /* needed for bone parents */
+                       BKE_pose_where_is(depsgraph, scene, ob); /* needed for bone parents */
                }
 
                ignore_parent_tx(C, bmain, scene, ob);
@@ -651,16 +676,14 @@ static int apply_objects_internal(
 static int visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op))
 {
        Scene *scene = CTX_data_scene(C);
-       EvaluationContext eval_ctx;
+       Depsgraph *depsgraph = CTX_data_depsgraph(C);
        bool changed = false;
-       
-       CTX_data_eval_ctx(C, &eval_ctx);
 
        CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
        {
-               BKE_object_where_is_calc(&eval_ctx, scene, ob);
+               BKE_object_where_is_calc(depsgraph, scene, ob);
                BKE_object_apply_mat4(ob, ob->obmat, true, true);
-               BKE_object_where_is_calc(&eval_ctx, scene, ob);
+               BKE_object_where_is_calc(depsgraph, scene, ob);
 
                /* update for any children that may get moved */
                DEG_id_tag_update(&ob->id, OB_RECALC_OB);
@@ -744,7 +767,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
        Scene *scene = CTX_data_scene(C);
        Object *obact = CTX_data_active_object(C);
        Object *obedit = CTX_data_edit_object(C);
-       EvaluationContext eval_ctx;
+       Depsgraph *depsgraph = CTX_data_depsgraph(C);
        Object *tob;
        float cursor[3], cent[3], cent_neg[3], centn[3];
        int centermode = RNA_enum_get(op->ptr, "type");
@@ -754,8 +777,6 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
        CollectionPointerLink *ctx_ob;
        CollectionPointerLink *ctx_ob_act = NULL;
 
-       CTX_data_eval_ctx(C, &eval_ctx);
-
        /* keep track of what is changed */
        int tot_change = 0, tot_lib_error = 0, tot_multiuser_arm_error = 0;
 
@@ -766,7 +787,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
        else {
                /* get the view settings if 'around' isn't set and the view is available */
                View3D *v3d = CTX_wm_view3d(C);
-               copy_v3_v3(cursor, ED_view3d_cursor3d_get(scene, v3d));
+               copy_v3_v3(cursor, ED_view3d_cursor3d_get(scene, v3d)->location);
                if (v3d && !RNA_struct_property_is_set(op->ptr, "center"))
                        around = v3d->around;
        }
@@ -871,7 +892,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
                                                        float min[3], max[3];
                                                        /* only bounds support */
                                                        INIT_MINMAX(min, max);
-                                                       BKE_object_minmax_dupli(scene, ob, min, max, true);
+                                                       BKE_object_minmax_dupli(depsgraph, scene, ob, min, max, true);
                                                        mid_v3_v3v3(cent, min, max);
                                                        invert_m4_m4(ob->imat, ob->obmat);
                                                        mul_m4_v3(ob->imat, cent);
@@ -988,8 +1009,8 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
                                        arm->id.tag |= LIB_TAG_DOIT;
                                        /* do_inverse_offset = true; */ /* docenter_armature() handles this */
 
-                                       BKE_object_where_is_calc(&eval_ctx, scene, ob);
-                                       BKE_pose_where_is(&eval_ctx, scene, ob); /* needed for bone parents */
+                                       BKE_object_where_is_calc(depsgraph, scene, ob);
+                                       BKE_pose_where_is(depsgraph, scene, ob); /* needed for bone parents */
 
                                        ignore_parent_tx(C, bmain, scene, ob);
 
@@ -1047,9 +1068,9 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
 
                                add_v3_v3(ob->loc, centn);
 
-                               BKE_object_where_is_calc(&eval_ctx, scene, ob);
+                               BKE_object_where_is_calc(depsgraph, scene, ob);
                                if (ob->type == OB_ARMATURE) {
-                                       BKE_pose_where_is(&eval_ctx, scene, ob); /* needed for bone parents */
+                                       BKE_pose_where_is(depsgraph, scene, ob); /* needed for bone parents */
                                }
 
                                ignore_parent_tx(C, bmain, scene, ob);
@@ -1076,9 +1097,9 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
                                                mul_v3_mat3_m4v3(centn, ob_other->obmat, cent); /* omit translation part */
                                                add_v3_v3(ob_other->loc, centn);
 
-                                               BKE_object_where_is_calc(&eval_ctx, scene, ob_other);
+                                               BKE_object_where_is_calc(depsgraph, scene, ob_other);
                                                if (ob_other->type == OB_ARMATURE) {
-                                                       BKE_pose_where_is(&eval_ctx, scene, ob_other); /* needed for bone parents */
+                                                       BKE_pose_where_is(depsgraph, scene, ob_other); /* needed for bone parents */
                                                }
                                                ignore_parent_tx(C, bmain, scene, ob_other);
                                        }
@@ -1292,11 +1313,7 @@ static int object_transform_axis_target_invoke(bContext *C, wmOperator *op, cons
                return OPERATOR_PASS_THROUGH;
        }
 
-       EvaluationContext eval_ctx;
-
-       CTX_data_eval_ctx(C, &eval_ctx);
-
-       ED_view3d_autodist_init(&eval_ctx, vc.depsgraph, vc.ar, vc.v3d, 0);
+       ED_view3d_autodist_init(vc.depsgraph, vc.ar, vc.v3d, 0);
 
        if (vc.rv3d->depths != NULL) {
                vc.rv3d->depths->damaged = true;