BezierTo breaks when aligned on the YZ plane

Avatar
  • updated
  • Not a bug

BezierTo produces a straight line, rather than the expected curve, when everything is aligned in the YZ plane.

I've attached an example below. The first polyline is the wrong one. The other two -- one with a slight adjustment and one in the XZ plane -- are behaving properly. Any deviation from alignment appears to make it work correctly.

Image 656

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Shapes;

public class ShapeTest : ImmediateModeShapeDrawer
{
    public override void DrawShapes(Camera cam)
    {
        using (Draw.Command(cam))
        {
            Draw.LineGeometry = LineGeometry.Flat2D;
            Draw.ThicknessSpace = ThicknessSpace.Pixels;
            Draw.Thickness = 4;

            using (var p = new PolylinePath()) {
                p.AddPoint(Vector3.zero);
                p.BezierTo(5 * Vector3.up, 5 * Vector3.up + Vector3.forward, Vector3.forward);
                Draw.Polyline(p);
            }
            using (var p = new PolylinePath()) {
                p.AddPoint(Vector3.zero);
                p.BezierTo(5 * Vector3.up, 5 * Vector3.up + Vector3.forward + Vector3.right * 0.001f, Vector3.forward);
                Draw.Polyline(p);
            }
            using (var p = new PolylinePath()) {
                p.AddPoint(Vector3.zero);
                p.BezierTo(5 * Vector3.up, 5 * Vector3.up + Vector3.right, Vector3.right);
                Draw.Polyline(p);
            }
        }
    }
}
Reporting a bug? please specify Unity version:
2021.3.9f1
Reporting a bug? please specify Shapes version:
4.2.1
Reporting a bug? please specify Render Pipeline:
HDRP
Avatar
Freya Holmér creator
  • Not a bug

this is because you've set LineGeometry to Flat2D, which works only on the XY axis. if you want to draw on a different plane, you'll want to rotate the drawing matrix so that the local drawing happens in the XY plane, but it's rendered in your XZ plane.

You can use Draw.Rotate or set Draw.Matrix directly

Avatar
fen

I noticed I was using LineGeometry, not PolylineGeometry! However, it also turns out that PolylineGeometry was set to Billboard, so it's a bit moot. Setting the polyline geometry to Flat2D does make it go haywire as expected.

I used Debug.DrawLine to plot the polyline points that were getting calculated by BezierTo.

Image 657

The debug lines match up with the rendered polylines, so BezierTo is definitely producing a straight line here.

It might be an issue with CalcBezierPointCount. If I make it return a constant, then all three polylines render correctly.

Avatar
Freya Holmér creator

oh yeah I forgot to mention this has now been fixed c: