public static Rhino.Commands.Result AddBackgroundBitmap(Rhino.RhinoDoc doc)
    {
        Rhino.RhinoApp.WriteLine ("hey");
        // Allow the user to select a bitmap file
        Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog();
        fd.Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg";
        if (!fd.ShowDialog())
          return Rhino.Commands.Result.Cancel;

        // Verify the file that was selected
        System.Drawing.Image image;
        try
        {
          image = System.Drawing.Image.FromFile(fd.FileName);
        }
        catch (Exception)
        {
          return Rhino.Commands.Result.Failure;
        }

        // Allow the user to pick the bitmap origin
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Bitmap Origin");
        gp.ConstrainToConstructionPlane(true);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
          return gp.CommandResult();

        // Get the view that the point was picked in.
        // This will be the view that the bitmap appears in.
        Rhino.Display.RhinoView view = gp.View();
        if (view == null)
        {
          view = doc.Views.ActiveView;
          if (view == null)
        return Rhino.Commands.Result.Failure;
        }

        // Allow the user to specify the bitmap with in model units
        Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber();
        gn.SetCommandPrompt("Bitmap width");
        gn.SetLowerLimit(1.0, false);
        gn.Get();
        if (gn.CommandResult() != Rhino.Commands.Result.Success)
          return gn.CommandResult();

        // Cook up some scale factors
        double w = gn.Number();
        double image_width = image.Width;
        double image_height = image.Height;
        double h = w * (image_height / image_width);

        Rhino.Geometry.Plane plane = view.ActiveViewport.ConstructionPlane();
        plane.Origin = gp.Point();
        view.ActiveViewport.SetTraceImage(fd.FileName, plane, w, h, false, false);
        view.Redraw();
        return Rhino.Commands.Result.Success;
    }
Example #2
0
  public static Rhino.Commands.Result AddTexture(Rhino.RhinoDoc doc)
  {
    // Select object to add texture
    Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Surface |
      Rhino.DocObjects.ObjectType.PolysrfFilter |
      Rhino.DocObjects.ObjectType.Mesh;
    Rhino.DocObjects.ObjRef objref;
    Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to add texture", false, filter, out objref);
    if( rc!= Rhino.Commands.Result.Success )
      return rc;

    Rhino.DocObjects.RhinoObject rhino_object = objref.Object();
    if (rhino_object == null)
      return Rhino.Commands.Result.Failure;

    // Select texture
    Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog();
    fd.Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg";
    if (fd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
      return Rhino.Commands.Result.Cancel;

    // Verify texture
    string bitmap_filename = fd.FileName;
    if( string.IsNullOrEmpty(bitmap_filename) || !System.IO.File.Exists(bitmap_filename) )
      return Rhino.Commands.Result.Nothing;

    // Make sure the object has it's material source set to "material_from_object"
    if( rhino_object.Attributes.MaterialSource != Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject )
    {
      rhino_object.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject;
    }

    // Make sure the object has a material assigned
    int material_index = rhino_object.Attributes.MaterialIndex;
    if (material_index < 0)
    {
      // Create a new material based on Rhino's default material
      material_index = doc.Materials.Add();
      // Assign the new material (index) to the object.
      rhino_object.Attributes.MaterialIndex = material_index;
    }
 
    if (material_index >= 0)
    {
      Rhino.DocObjects.Material mat = doc.Materials[material_index];
      mat.SetBumpTexture(bitmap_filename);
      mat.CommitChanges();

      //Don't forget to update the object, if necessary
      rhino_object.CommitChanges();

      doc.Views.Redraw();
      return Rhino.Commands.Result.Success;
    }
 
    return Rhino.Commands.Result.Failure;
  }
Example #3
0
        private void On_CellClick(object sender, GridCellMouseEventArgs e)
        {
            // test if color
            if (e.GridColumn is null)
            {
                return;
            }
            if (e.GridColumn.HeaderText == "Color")
            {
                var model = e.Item as ParticleConduitModel;

                // Native
                var color = model.Color;
                Dialogs.ShowColorDialog(ref color);
                model.Color = color;

                // Eto
                // TODO: implement
            }

            // test if image
            if (e.GridColumn.HeaderText == "Image")
            {
                var model = e.Item as ParticleConduitModel;
                // Allow the user to select a bitmap file
                var fd = new Rhino.UI.OpenFileDialog {
                    Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg"
                };
                if (!fd.ShowOpenDialog())
                {
                    return;
                }

                // Verify the file that was selected
                System.Drawing.Image image;
                try
                {
                    image = System.Drawing.Image.FromFile(fd.FileName);
                }
                catch (Exception)
                {
                    return;
                }

                model.Bitmap = new System.Drawing.Bitmap(image);
            }
        }
    public static Rhino.Commands.Result AddBackgroundBitmap(Rhino.RhinoDoc doc)
    {
        // Allow the user to select a bitmap file
        var fd = new Rhino.UI.OpenFileDialog {
            Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg"
        };

        if (!fd.ShowOpenDialog())
        {
            return(Rhino.Commands.Result.Cancel);
        }

        // Verify the file that was selected
        System.Drawing.Image image;
        try
        {
            image = System.Drawing.Image.FromFile(fd.FileName);
        }
        catch (Exception)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Allow the user to pick the bitmap origin
        var gp = new Rhino.Input.Custom.GetPoint();

        gp.SetCommandPrompt("Bitmap Origin");
        gp.ConstrainToConstructionPlane(true);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Get the view that the point was picked in.
        // This will be the view that the bitmap appears in.
        var view = gp.View();

        if (view == null)
        {
            view = doc.Views.ActiveView;
            if (view == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
        }

        // Allow the user to specify the bitmap width in model units
        var gn = new Rhino.Input.Custom.GetNumber();

        gn.SetCommandPrompt("Bitmap width");
        gn.SetLowerLimit(1.0, false);
        gn.Get();
        if (gn.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gn.CommandResult());
        }

        // Cook up some scale factors
        var w            = gn.Number();
        var image_width  = image.Width;
        var image_height = image.Height;
        var h            = w * (image_height / image_width);

        var plane = view.ActiveViewport.ConstructionPlane();

        plane.Origin = gp.Point();
        view.ActiveViewport.SetTraceImage(fd.FileName, plane, w, h, false, false);
        view.Redraw();
        return(Rhino.Commands.Result.Success);
    }
    public static Rhino.Commands.Result AddTexture(Rhino.RhinoDoc doc)
    {
        // Select object to add texture
        const ObjectType filter = Rhino.DocObjects.ObjectType.Surface |
                                  Rhino.DocObjects.ObjectType.PolysrfFilter |
                                  Rhino.DocObjects.ObjectType.Mesh;

        Rhino.DocObjects.ObjRef objref;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select object to add texture", false, filter, out objref);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.DocObjects.RhinoObject rhino_object = objref.Object();
        if (rhino_object == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Select texture
        Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog();
        fd.Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg";
        if (fd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
        {
            return(Rhino.Commands.Result.Cancel);
        }

        // Verify texture
        string bitmap_filename = fd.FileName;

        if (string.IsNullOrEmpty(bitmap_filename) || !System.IO.File.Exists(bitmap_filename))
        {
            return(Rhino.Commands.Result.Nothing);
        }

        // Make sure the object has it's material source set to "material_from_object"
        rhino_object.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject;

        // Make sure the object has a material assigned
        int material_index = rhino_object.Attributes.MaterialIndex;

        if (material_index < 0)
        {
            // Create a new material based on Rhino's default material
            material_index = doc.Materials.Add();
            // Assign the new material (index) to the object.
            rhino_object.Attributes.MaterialIndex = material_index;
        }

        if (material_index >= 0)
        {
            Rhino.DocObjects.Material mat = doc.Materials[material_index];
            mat.SetBumpTexture(bitmap_filename);
            mat.CommitChanges();

            //Don't forget to update the object, if necessary
            rhino_object.CommitChanges();

            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }

        return(Rhino.Commands.Result.Failure);
    }