C# texture on Brep's surface

I want to set two materials on the same BREP, place the texture on the BREP surface, and set up UV coordinates. How should I write the C# code?

@nathanletwory has to correct me if I am wrong, but I don’t think you can apply a per face UV right now in Rhino.

texture_material = new Material{Name = “Tex”+Tex_fileName,DiffuseColor = System.Drawing.Color.White};

texture_material.SetBitmapTexture(texture_FilePath);

texture_material.CommitChanges();

var Render_mat = RenderMaterial.CreateBasicMaterial(texture_material, doc);

doc.RenderMaterials.Add(Render_mat);

Rhino.DocObjects.ObjectAttributes attr = new Rhino.DocObjects.ObjectAttributes();

attr.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject;

attr.RenderMaterial = Render_mat;

Brep Extrusion = Brep.CreateFromOffsetFace(breps[k].Faces[0], Houde, doc.ModelAbsoluteTolerance, false, true);

Extrusion.Standardize();

Guid Extrusion_id = doc.Objects.AddBrep(Extrusion, attr);

Because if the texture is directly applied to the object, it will be like that, so I still don’t know how to set two materials on one object.

@Gijs, UVs you can set up as you like. It is per-face material setting that is the challenge.

Now I am very confused, for me it is the opposite. If I run ApplyPlanarMapping for example, I cannot seem to select a face of a polysurface, while I can assign a different material to a single face.

Sure, but we’re talking about doing that via C# here.

To have different UV mapping on different faces you essentially create as many UV mapping channels as you have need for, then create the UV mapping on the whole geometry.

How to do the assinging of material per face in code using RhinoCommon I don’t know. @Jussi_Aaltonen was working on that, but he’s currently not able to help out here.

I see, interesting. So each have their own flaw then. Does that mean we could apply different UV’s per C# and per face material directly in Rhino to have both?

I don’t follow.

UVs are always ‘mesh-wide’. So you have to have multiple mapping channels if you want to have different faces behave differently. This you can do by C# already (and manually).

It is setting per-face materials I’m not sure about how to do in C#.

Got it, I had a brain fart. The material just needs to address a different channel.
I was actually thinking that it is not possible to make a per face UV (in other words, each face/set of faces having a single independent channel)

Or more precise: the texture in the material.

Right, well, different mapping channels and you get what you need :slight_smile:

mostly, yes, but it means you do need to do quite a bit of book-keeping in your materials to work with that.
What we might need is a multi-material that can be applied to a polysurface, where you can set the channel for each material rather than per texture.

That is what you need to do anyway. You need to specify what UV set (mapping channel) you want to use for a texture.

It does not matter what level it is at, material or texture. Doing a multi-material would just mean you have to do it in a different place. You still have multiple UV sets (mapping channels) to deal with.