RhinoCommon - Texture Mapping

Are there some examples on how to apply, modify or delete texture mapping on one or many objects?
Thanks

Have you seen this http://wiki.mcneel.com/developer/rhinocommonsamples/addtexture

This example shows how to add a texture to a material map (bump). My request concerns texture mapping like “Planar”, “Spherical” which set the position and wrapping type for textures over an objet.
Thanks,

Hi,

I’ve found this example within the old Rhino.NET SDK which show the properties “m_rendering_attributes” in the attributes of the objects. However, I can’t find the equivalent within RhinoCommon :

http://wiki.mcneel.com/developer/sdksamples/mappingref

Also, always in the old Rhino.NET SDK, a texture mapping table exist in the ActiveDoc object which allow to modify or add new texture mapping.

> RhUtil.RhinoApp.ActiveDoc.m_texture_mapping_table

For both, does someone knows the equivalent in RhinoCommon?
Thanks

Here’s how I’ve applied a planar mapping if it helps (l_mesh is a mesh object):

BoundingBox bb = l_mesh.GetBoundingBox(turtle.Plane);

Interval ix = new Interval(bb.Min.X, bb.Max.X);
Interval iy = new Interval(bb.Min.Y, bb.Max.Y);
Interval iz = new Interval(bb.Min.Z, bb.Max.Z);

//create texture mapping
Rhino.Render.TextureMapping tm = Rhino.Render.TextureMapping.CreatePlaneMapping(turtle.Plane, ix, iy, iz);

l_mesh.TextureCoordinates.SetTextureCoordinates(tm);

//add the leaf to the document
document.Objects.AddMesh(l_mesh, turtle.Attributes);
1 Like

Hi Tom,

Thanks for your reply. Your example helps me to understand a bit more on the subject… any idea on how to apply mapping on a specific channel?

Also, in the doc I only found the TextureCoordinates properties in association with Mesh Object… again any idea on how to apply mapping on a brep object, surface, etc.?

Thanks

Also,unfortunatly “TextureCoordinates.SetTextureCoordinates™;” doesn’t add texture mapping information in the “Properties > Texture Mapping” Panel when I select the object after setting the texture coordinates by script. So this is probably not the way to keep testing…

Thanks

Found this example but still no clue on how to convert it to RhinoCommon…

Thanks again

There is my actual try to apply a planar texture map (size of 1,1,1) on a picked brep surface. Result the variable “done” give “true”, but no change is visible… and also as said in a previous post, no texture mapping object is added to the scene or accessible through the object properties…

I’m beginning to think that there is no way to do what I’m looking using RhinoCommon, which is really disappointed is this is true…

Thanks again,

// Selection des objects
 Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
 go.SetCommandPrompt("Select object(s)");
 go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep;
 go.EnablePreSelect(true, true);
 go.GetMultiple(0, 0);
 if (go.CommandResult() != Result.Success) { return go.CommandResult(); }

 int obj_count = go.ObjectCount;
 if (obj_count == 0) { return Result.Failure; }

Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
 for (int i = 0; i < obj_count; i++)
 {
      // Creation du map
      Rhino.Geometry.BoundingBox obj_bb = go.Object(i).Geometry().GetBoundingBox(false);
      Interval ix = new Interval(0, 1);
      Interval iy = new Interval(0, 1);
      Interval iz = new Interval(0, 1);
      Rhino.Render.TextureMapping plane_mapping = Rhino.Render.TextureMapping.CreatePlaneMapping(plane, ix, iy, iz);
      Rhino.Geometry.Mesh[] meshes = go.Object(i).Object().GetMeshes(MeshType.Render);
      for (int j = 0; j < meshes.Length; j++)
      {
          bool done = meshes[j].TextureCoordinates.SetTextureCoordinates(plane_mapping);
           RhinoApp.WriteLine("Set Texture Coordinates : " + done.ToString());
      }
}
doc.Views.Redraw();

No one has an idea?

This may not be in RhinoCommon yet. I need to check.

@andy, can you help me figure out what functionality I need to have exposed in RhinoCommon in order to help @sideprojek with his problem?

This is the C++ version.

https://github.com/mcneel/Rhino5Samples_CPP/tree/master/SampleTextureMapping

Perfect! Thanks Andy. @sideprojek not all of this functionality is currently available in RhinoCommon.

@JohnM, since you’re working in this area right now for exposing more rendering SDK features in RhinoCommon, could you look at the C++ sample Andy posted and make sure this can be done with RhinoCommon in SR7?

Thanks, Steve

I will take a look at it and make sure it is supported in SR7.

Happy to read that this goes foward! When the SR7 release is Schedule?

The next Rhino 5.0 SR7 release candidate should include RhinoDoc.Objects.ModifyTextureMapping, DocObjects.RhinoObject.GetTextureMapping and DocObjects.RhinoObject.GetTextureChannels methods which will give you the ability to query and assign texture mapping to objects. If you use channel 1 you will see the mappings in the object properties texture mapping page

2 Likes

Very Good !!
I need this for a customer.

Hi, could someone confirm me that it’s not possible to assign texture coordinates by face using RhinoCommon’s mesh class? In other words, to be able to have multiple texture coordinates per vertex (one for each of the faces it belongs to).

The best solution I could come up is to unweld the mesh keeping the original normals. Hopefully there is a better way.

That’s the only way.

Andy

Any plans to make the texture unwarpping available in RhinoCommon?