Lines rendered at absurd size with example Immediate-Mode Drawing script

Avatar
  • updated
  • Not a bug

My code currently looks like:

using System.Collections;using System.Collections.Generic;using UnityEngine;using Shapes;
[ExecuteAlways] public class MissileShapes : ImmediateModeShapeDrawer {
public override void DrawShapes( Camera cam ){
using( Draw.Command( cam ) ){
// set up static parameters. these are used for all following Draw.Line calls Draw.LineGeometry = LineGeometry.Volumetric3D; Draw.ThicknessSpace = ThicknessSpace.Pixels; Draw.Thickness = 1; // 4px wide
// set static parameter to draw in the local space of this object Draw.Matrix = transform.localToWorldMatrix;
// draw lines Draw.Line( Vector3.zero, Vector3.right, Color.red ); Draw.Line( Vector3.zero, Vector3.up, Color.green ); Draw.Line( Vector3.zero, Vector3.forward, Color.blue ); }
}
}

and for some reason the lines rendered are strangly large and scale depending on camera distance to the lines.

Youtube video

Project files:

https://storage.buymymojo.net/s/cRsGCnLCbxRfTac

Reporting a bug? please specify Unity version:
2023.1.11f1
Reporting a bug? please specify Shapes version:
4.3.1
Reporting a bug? please specify Render Pipeline:
URP
Avatar
Freya Holmér creator
  • Not a bug

what's the scale of the object?

Draw.Matrix = transform.localToWorldMatrix;

will also include the scale of that object, so if that scale is ~100 then the lines will scale along with it

Avatar
buymymojo

the object just so happen to be exactly scale 100 lol.

What should I do to handle this?

trying

Draw.Matrix = transform.worldToLocalMatrix;

Doesn't render anything

Avatar
Freya Holmér creator
// takes position, rotation and scale into account:
Draw.Matrix = transform.localToWorldMatrix;

// takes only position and rotation into account:
Draw.Position = transform.position;
Draw.Rotation = transform.rotation;
Avatar
buymymojo

Never mind I figured out using

Draw.Matrix = Matrix4x4.TRS( transform.position, transform.rotation, Vector3.one );

works. thanks for the help!

Avatar
Freya Holmér creator

that works too!