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 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?
@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)