Create Planar (UVW) texture mapping

Hello,

I’m currently using this snippit to get a texture mapping onto a surface:

private TextureMapping GetPlanarMapping(Brep brep)
{
    var bbox = brep.GetBoundingBox(false);
            
    var mapping = TextureMapping.CreatePlaneMapping(
                    Plane.WorldXY, 
                    new Interval(bbox.Min.X, bbox.Max.X),
                    new Interval(bbox.Min.Y, bbox.Max.Y), 
                    new Interval(bbox.Min.Z, bbox.Max.Z));

    return mapping;
}

It creates a Planar (UV) mapping that is mostly correct but slightly offset. If switched (in the UI) to UVW it maps correctly. How can I create this as UVW?

I was just now looking at https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Render_TextureMapping_CreatePlaneMapping.htm

I haven’t created texture mappings programmatically before, but I can’t see anything out of the ordinary. For the given snippet I’d expect UVW mapping, too, asuming the bounding box has actually a thickness/height. Have you ensured the bounding box is valid and the z-values are as expected?

I have. For the test case I’m using, the bounding box is valid and has a diagonal of roughly (125, 175, 2)

Looks like currently there is no way to programmatically create Planar (UVW) mapping. I’ve logged it as https://mcneel.myjetbrains.com/youtrack/issue/RH-46993

@diana_lp, I’ve made some amendments to the texture mapping functions. I think they’ll be available in the next 6.7 release candidate that goes out in the next 24 hrs or so (if everything goes ok).

You should be able to use

private TextureMapping GetPlanarMapping(Brep brep)
{
    var bbox = brep.GetBoundingBox(false);
            
    var mapping = TextureMapping.CreatePlaneMapping(
                    Plane.WorldXY, 
                    new Interval(bbox.Min.X, bbox.Max.X),
                    new Interval(bbox.Min.Y, bbox.Max.Y), 
                    new Interval(bbox.Min.Z, bbox.Max.Z),
                    true); // true for capped planar = Planar UVW

    return mapping;
}

I also adapted the API a bit so that there are TryGetXXMapping that allows you to test if they are capped or not (for planar, box and cylindrical mappings)

1 Like

@nathanletwory, Thank you so much for your help! I will look for this in the next RC.

RH-46993 is fixed in the latest Service Release