Apply texture mapping for surfaces


#1

Hi,

Is it possible to apply texture mapping to surfaces?

For meshes there is something like this in RhinoCommon:
mesh.TextureCoordinates.SetTextureCoordinates(Mapping);

Is there similar thingy for breps/surfaces?

I tried this

private void RunScript(Guid x, Brep y, Plane p, ref object A)
{
  Rhino.Render.TextureMapping textureMapping = Rhino.Render.TextureMapping.CreatePlaneMapping(p, new Interval(-400, 400), new Interval(-400, 400), new Interval(0, 1));
  Rhino.DocObjects.Tables.ObjectTable.ModifyTextureMapping(x, 1, textureMapping);
}

http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObject
But I get error:
Error (CS0120): An object reference is required for the non-static field, method, or property ‘Rhino.DocObjects.Tables.ObjectTable.ModifyTextureMapping(System.Guid, int, Rhino.Render.TextureMapping)’ (line 74)
What does this error mean?


(Dale Fugier) #2

Hi Tom,

Texture mapping is applied to a surface or polysurface’s render mesh during rendering.

Your code does not work because you are not working with the document’s object table.

I’m thinking something like this might work:

private bool ApplyPlaneMapping(RhinoDoc doc, Guid id, Plane plane)
{
  var mapping = TextureMapping.CreatePlaneMapping(
    plane, 
    new Interval(-400, 400), 
    new Interval(-400, 400), 
    new Interval(0, 1)
    );
  return doc.Objects.ModifyTextureMapping(id, 1, mapping);
}