How do I get the rotation (ie. amount of spin around the direction of the light) of a WorldRectangular light please?
I also need the length and width of the light source, but the LightObject.LightGeometry.Length (and Width) is a Vector3d rather than a single float. What do Length and Width actually contain please?
EDIT: What I really need is the transformation matrix of the area light (from a 1m x 1m plane).
They are two sides of the rectangular light from the light location. Since they are vectors you can call use their property
Lengh to get a scalar out of them.
So you have a location (Point3d) and two vectors. You should be able to figure out the transformation matrix from that. For Raytraced I set up the area light like this:
else if (lg.IsSpotLight)
lt = LightType.Spot;
spotangle = lg.SpotAngleRadians * 2;
smooth = 1.0 / Math.Max(lg.HotSpot, 0.001f) - 1.0;
strength = (float)(lg.Intensity * RcCore.It.AllSettings.SpotLightFactor);
else if (lg.IsRectangularLight)
lt = LightType.Area;
strength = (float)(lg.Intensity * RcCore.It.AllSettings.AreaLightFactor);
var width = lg.Width;
var length = lg.Length;
sizeU = (float)width.Length;
sizeV = (float)length.Length;
size = 1.0f;
Fantastic, thanks Nathan.
Can you be more specific in how to do this please?
You can use the location, width and height vectors to construct a plane with the Plane constructor
Plane(Point3d, Vector3d, Vector3d)
Then figure out transform from your 1mx1m plane to it. Maybe something like
Calculate rotation data between two planes could be useful.
Nathan - I have been able to get this working using your suggestion above. It is not a trivial solution, but seems to work.
I would suggest the Rhino Lights have an XForm property added (similar to InstanceObjects) so that the camera transform can be obtained in a consistent fashion with other parts of Rhino.
FYI, there is a PlaneToPlane rotation transform helper:
block instances are the only objects that carry an Xform of their own. There is this old request
https://mcneel.myjetbrains.com/youtrack/issue/RH-20531 for that. I’ll add this thread to the item.
Thanks Nathan. It looks like the rotation transform helper is for rotations only, however a full transformation matrix (scale, rotation, translation) as is supplied with a block instance would be great.
You only need to apply scale separately, rotation and translation are already in the transform matrix you get:
import Rhino.Geometry as RG
xform = RG.Transform.PlaneToPlane(fromPlane, toPlane)
newSubdObj = subdObj
scale = RG.Transform.Scale(RG.Plane.WorldXY, scaleX, scaleY, 1.0)
newSubdObj.Transform(xform * scale)
PlaneToPlane.gh (22.0 KB)
Fantastic, thanks Nathan, I will try this out.