Polygons in Immediate Drawing are only 2D

Avatar
  • updated
  • Not a bug

Hey,

I wanted to draw a polygon that is always in front of the camera in the Immediate-Drawing mode. I created a PolygonPath and added my Vector3 points to this list. But after calling the Draw.Polygon(PolygonPath pgp, ...) method in the OnPostRender method the polygon appeared always in the z plane.

In fact, after diving into the source code of Shapes, I found in "PolygonPath.cs" that it has a List<Vector2> and that's probably why it's always at z=0. Would be great if I could also add Vector3 to the PolygonPath!

Thanks in advance for a fix!

Tim

Reporting a bug? please specify Unity version:
2020.1.6f1
Reporting a bug? please specify Shapes version:
2.3.1
Reporting a bug? please specify Render Pipeline:
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Not a bug

Polygons are by design only 2D, because triangulation is ambiguous and undefined unless the vertices lie in a single plane

However! you can still set the position and rotation and all that of the polygon by using the Draw matrix

Draw.Matrix = Matrix4x4.TRS( position, rotation, scale );
Draw.Polygon( path, ... );
Draw.Matrix = Matrix4x4.identity;
Avatar
timbrando

Hi Freya,

thanks for your reply. I will try that out as soon as I can! :)

Tim

Avatar
Freya Holmér creator
  • Answer
  • Not a bug

Polygons are by design only 2D, because triangulation is ambiguous and undefined unless the vertices lie in a single plane

However! you can still set the position and rotation and all that of the polygon by using the Draw matrix

Draw.Matrix = Matrix4x4.TRS( position, rotation, scale );
Draw.Polygon( path, ... );
Draw.Matrix = Matrix4x4.identity;