Grasshopper material

Hi,

I would like to display object in render view in Rhino 6 through grasshopper with texture-bitmap. (do not care much about mapping for now)
Currently there are options to choose different colors, transparencies but not possible to add simple bitmaps.

Is there any way to display object with bitmap, for me it is fine even if I use material from Rhino Material tabs, but geometry has to come from grasshopper.

Is there any possibilities to apply texture via existing components or special code has to be written?

1 Like

Found it.
Is there any possibility to apply box mapping for gh objects?:slight_smile:

Hello
so you find
SetBitmapTexture for Material
Here the script from David Rutten with Bitmap added

private void RunScript(Color Colour, double Reflection, double Smoothness, string fileName, ref object Mat)
{
Reflection = Math.Min(Math.Max(Reflection, 0), 1);
Smoothness = Math.Min(Math.Max(Smoothness, 0), 1);

Material material = new Material();
material.SetBitmapTexture(fileName);

material.ReflectionColor = Colour;
material.DiffuseColor = Color.White;
material.AmbientColor = Color.Black;
material.EmissionColor = Color.Black;
material.Reflectivity = Reflection;
material.ReflectionGlossiness = Smoothness;

var renderMaterial = Rhino.Render.RenderMaterial.CreateBasicMaterial(material);
Mat = new GH_Material(renderMaterial);

}

And it seems that texture is not mapped correctly. Is there any way to apply mapping to gh objects? I know how to do it with guid and rhino objects but not gh objects.

Human has some texture mapping components that are pretty nice. Maybe this helps?

Hey Petras,
reusing that I did something moving a texture on a sphere.

Not very good programming, but up to you to use it for your need.

//Draw all meshes in this method.
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
Mesh mesh = Mesh.CreateFromBrep(brep);
mesh[0].SetTextureCoordinates(tm, Transform.Identity, true);
args.Display.DrawMeshShaded(mesh[0], new Rhino.Display.DisplayMaterial(material));
}
custom-display-with_texture_movement.gh (10.4 KB)

1 Like

I don’t know if what I did was useful for you, but that was useful for me to make a script that put a gradient on a mesh.
The script needs

The link in Grasshopper

4 Likes

Thank you the texture mapping in previous post was exactly what I needed:)

1 Like

Just went through your latest post for octahedral lattice sphere.
I would like to ask about line meshing. I tried similar technique before, when applying 3D convex hull at each node.

The example below creates convex hull from polygon vertices. But in the next image you see that in some cases polygons may go inside the minimal convex hull shapes. Do you have any suggestion how to avoid this and create convex hull that always takes all polygon points?

1 Like

That would be a Concave Hull. I found quick a code for the 2d version of it. https://github.com/mapbox/concaveman

Hello
For your problem I have no pre existing solution.

Hi,

Do you know if it is possible to create a texture like you did but without the path of bitmap.

The thing is that I creating a bitmap from laptop camera, and would like to apply that bitmap as a texture to an object.

The input I have is System.Drawing.Bitmap, and the texture material requires a path.

Hi Petras, the first answer I have is to copy your image on a new file and put this path ! Not very effective, surely because Material class was not designed to be machine generated.

Is then the only option is to convert every pixel to a point cloud?

I tried this convertion to point cloud and it works, but it is very slow, 300 ms for 640x480 px bitmap.

I am wondering if a simple texture mapping would make it realtime?
As I do not need any geomtry just preview in rhino.

private void RunScript(object x, object y, ref object A)
  {
    System.Drawing.Bitmap b = (System.Drawing.Bitmap) x;

     cloud = new PointCloud();

    for(int i = 0; i < b.Width;i++){// b.Width
      for(int j = 0; j < b.Height;j++){// b.Height
        cloud.Add(new Point3d(i, j, 0), b.GetPixel(i, j));
      }

    }
    box = cloud.GetBoundingBox(false);


  }

  // <Custom additional code> 

  PointCloud cloud;
  BoundingBox box;
  
  
  public override BoundingBox ClippingBox{get{return box;}}


  public override void DrawViewportWires(IGH_PreviewArgs args) {
    args.Display.DrawPointCloud(cloud,1);
  }

  // </Custom additional code> 
}

Hi Laurent,
Do you know of a way to apply a displacement map to a texture applied to a surface within gh as you showed above?

(rhino 6 for mac)

Thanks
Tim

@tim9, no I don’t know how to apply displacement map.
It seems to be accessible via RhinoCommon (V7 ?)

Hi Petras, have you found a solution to this problem ?

I have a similar issue : I generated a System.Drawing.Bitmap which is the preview of an InstanceDefinition, and now I’d like to display it in Human UI, but the only inputs are paths…

If inputs are paths, then I suggest to save File.Save and then load it from path.