How to create a material in grasshopper from an image

How to create a material in Grasshopper with an image, also I need to adjust mapping scaling, rotation

Using native components, this is not possible yet.

What you can do is create the material in Rhino and the reference it in Grasshopper.

Just write the material name into a text panel and plug it into the Material input of the Custom Preview

1 Like

Thankyou for the reply,

I’m already using that way, but there is a problem that, I had to redo 'the select one material ’ process everytime I update texture mapping. I m not getting a live preview until baked, i specifically need the road texture applied to full stretch along the road following curves of road also. Is there any solution.

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);
  }
2 Likes

Thank you very much @laurent_delrieu for the custom component

1 Like

Hello,

Looks like Rhino.DocObjects.Texture.UvwTransform is not working anymore in Rhino 8 SR3 ? This script was working fine in the latest Rhino 7 but now the scale is not applied anymore and stay at a default value.

Or was there a change in the SDK I did not see?

@dale,@andy could you have a look?

Thanks!