[Bf-blender-cvs] [2e98524b58a] master: Add support for area lights to the Apply Transform operator

Lukas Stockner noreply at git.blender.org
Mon Apr 30 22:13:37 CEST 2018


Commit: 2e98524b58a53f0d546e5f1e7d549d2f45815055
Author: Lukas Stockner
Date:   Mon Apr 30 22:05:03 2018 +0200
Branches: master
https://developer.blender.org/rB2e98524b58a53f0d546e5f1e7d549d2f45815055

Add support for area lights to the Apply Transform operator

Since area lights are affected by scaling them, it only makes sense to support applying the scale to the lamp size.
Of course, applying location or rotation does not work.

If a scaling that changes the aspect ratio is applied to a square lamp, the mode is automatically changed to Rectangle.

===================================================================

M	source/blender/editors/object/object_transform.c

===================================================================

diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c
index 05f98026e18..e29d49d00cb 100644
--- a/source/blender/editors/object/object_transform.c
+++ b/source/blender/editors/object/object_transform.c
@@ -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"
@@ -472,6 +473,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;
 	
@@ -601,6 +614,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;
 		}



More information about the Bf-blender-cvs mailing list