protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var result = Result.Failure;
            var view   = doc.Views.ActiveView;

            if (view == null)
            {
                return(result);
            }

            System.Drawing.Point windows_drawing_point;
            if (!GetCursorPos(out windows_drawing_point) || !ScreenToClient(view.Handle, ref windows_drawing_point))
            {
                return(result);
            }

            var xform = view.ActiveViewport.GetTransform(CoordinateSystem.Screen, CoordinateSystem.World);
            var point = new Rhino.Geometry.Point3d(windows_drawing_point.X, windows_drawing_point.Y, 0.0);

            RhinoApp.WriteLine("screen point: ({0})", point);
            point.Transform(xform);
            RhinoApp.WriteLine("world point: ({0})", point);
            result = Result.Success;
            return(result);
        }
Beispiel #2
0
        private void GetLights()
        {
            LightTable        allLights = doc.Lights;
            List <UnifyLight> lightList = new List <UnifyLight>();

            foreach (LightObject light in allLights)
            {
                UnifyLight unifyObj = new UnifyLight();

                unifyObj.ObjType    = "LightObject";
                unifyObj.LightType  = light.LightGeometry.LightStyle.ToString();
                unifyObj.Guid       = light.Id;
                unifyObj.Diffuse    = Utility.ColorToString(light.LightGeometry.Diffuse);
                unifyObj.UniqueName = light.LightGeometry.LightStyle.ToString() + "-" + light.Id.ToString();
                unifyObj.Intensity  = light.LightGeometry.Intensity;

                if (light.LightGeometry.LightStyle == Rhino.Geometry.LightStyle.WorldRectangular)
                {
                    // adjust location, rhino reports location at lower left corner
                    // unity reports location at center of the area/rectangle
                    Rhino.Geometry.Point3d loc = new Rhino.Geometry.Point3d(
                        light.LightGeometry.Location.X + (light.LightGeometry.Length.Length * 0.5),
                        light.LightGeometry.Location.Y + (light.LightGeometry.Width.Length * 0.5),
                        light.LightGeometry.Location.Z);
                    unifyObj.Location = loc.ToString();

                    // create target from location + direction
                    Rhino.Geometry.Transform xf     = Rhino.Geometry.Transform.Translation(light.LightGeometry.Direction);
                    Rhino.Geometry.Point3d   target = loc;
                    loc.Transform(xf);
                    unifyObj.Target = target.ToString();
                }
                else
                {
                    // create target from location + direction
                    Rhino.Geometry.Transform xf     = Rhino.Geometry.Transform.Translation(light.LightGeometry.Direction);
                    Rhino.Geometry.Point3d   target = light.LightGeometry.Location;
                    target.Transform(xf);
                    unifyObj.Target = target.ToString();

                    unifyObj.Location = light.LightGeometry.Location.ToString();
                }

                unifyObj.Range           = light.LightGeometry.Direction.Length;
                unifyObj.SpotAngle       = light.LightGeometry.SpotAngleRadians;
                unifyObj.ShadowIntensity = light.LightGeometry.SpotLightShadowIntensity;
                unifyObj.Width           = light.LightGeometry.Width.Length;
                unifyObj.Length          = light.LightGeometry.Length.Length;

                if (light.IsDeleted)
                {
                    unifyObj.Deleted = true;
                }

                lightList.Add(unifyObj);
            }

            this.Lights = lightList;
        }
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var result = Result.Failure;
      var view = doc.Views.ActiveView;
      if (view == null) return result;

      System.Drawing.Point windows_drawing_point;
      if (!GetCursorPos(out windows_drawing_point) || !ScreenToClient(view.Handle, ref windows_drawing_point))
        return result;

      var xform = view.ActiveViewport.GetTransform(CoordinateSystem.Screen, CoordinateSystem.World);
      var point = new Rhino.Geometry.Point3d(windows_drawing_point.X, windows_drawing_point.Y, 0.0);
      RhinoApp.WriteLine("screen point: ({0})", point);
      point.Transform(xform);
      RhinoApp.WriteLine("world point: ({0})", point);
      result = Result.Success;
      return result;
    }