Polyline linewidth does not stay at 1 pixel when parent object is scaled (with RegularPolygon it does)

Avatar
  • updated

When scaling polylines, the line width does not stay at 1 pixel.
I'm creating a polyline with this kind of code:

Polyline polyline = gameobject.AddComponent(typeof(Polyline)) as Polyline;
(Vector3[] points, Color[] colors) = calc_polyline_data(m_num_points, 0.0f, radius, color);
polyline.SetPoints(points, colors);
polyline.Color = color;
polyline.BlendMode = m_blend_mode;
polyline.ThicknessSpace = ThicknessSpace.Pixels;
polyline.Thickness = m_lineweight;
polyline.ScaleMode = Shapes.ScaleMode.Coordinate

Then scaling this object like this:

Polyline poly = gameobject.GetComponent(typeof(Polyline)) as Polyline;
Vector3 current = poly.transform.localScale;
poly.transform.localScale = new Vector3(scale, scale, 1.0f);

This will result in the line thickness not staying at 1 pixel in screen space, as demonstrated here (the lines become distorted below a certain scale value):


Image 452


Now, as these are for now just regular polygons created with Polylines, I tried to do the same thing with RegularPolygons:

RegularPolygon polyline = poly.AddComponent(typeof(RegularPolygon)) as RegularPolygon;
polyline.Sides = m_num_points;
polyline.Radius = radius;
polyline.Color = color;
polyline.BlendMode = m_blend_mode;
polyline.ThicknessSpace = ThicknessSpace.Pixels;
polyline.Thickness = m_lineweight;
polyline.ScaleMode = Shapes.ScaleMode.Coordinate;
polyline.Border = true;

This results in expected rendering of the lines, with uniform line width with all scaling values:


Image 453


Dunno if this is a bug or expected behaviour, but I would expect and hope the same thing with these settings with ThicknessSpace set to pixels, would result in always 1 pixel linewidths. If there is some workaround for this, or something I am not getting, please let me know :)

Thanks! And thanks for the wonderful library.

Reporting a bug? please specify Unity version:
2020.3.13f1
Reporting a bug? please specify Shapes version:
4.0.2
Reporting a bug? please specify Render Pipeline:
URP
Avatar
Freya Holmér creator
Quote from Mark Simmons

Any updates on this. I'm struggling with this issue also.

currently looking into a major overhaul of polylines, so this will be part of that update!

Avatar
Mark Simmons

Any updates on this. I'm struggling with this issue also.

Avatar
Freya Holmér creator

yep, the polyline shouldn't scale the width here, I'll look into it!