How to create a material in grasshopper from an image

Hello
you will find some discussions on this forum if you search with “texture” keyword

Here a simple way of doing using some C#, could be Python. I am not sure it is the last Material but it works.
You will find some way of changing texture like here

material.gh (9.8 KB)
You can add easily others texture not just the diffuse but the bump …

private void RunScript(System.Drawing.Color Colour, double Reflection, double Smoothness, string filename, Transform transform, ref object Mat)
  {
    Reflection = Math.Min(Math.Max(Reflection, 0), 1);
    Smoothness = Math.Min(Math.Max(Smoothness, 0), 1);
    Rhino.DocObjects.Material material = new  Rhino.DocObjects.Material();
    //material.SetBitmapTexture(fileName);
    material.ReflectionColor = Colour;
    material.DiffuseColor = Colour;
    material.AmbientColor = System.Drawing.Color.Black;
    material.EmissionColor = System.Drawing.Color.Black;
    material.Reflectivity = Reflection;
    material.ReflectionGlossiness = Smoothness;

    Rhino.DocObjects.Texture text = new Rhino.DocObjects.Texture();
    text.ApplyUvwTransform = true;
    text.UvwTransform = transform;
    text.FileName = filename;
    material.SetTexture(text, Rhino.DocObjects.TextureType.Diffuse);


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