Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node to draw 3D lines and splines #26

Open
aaronfranke opened this issue Apr 14, 2019 · 15 comments
Open

Node to draw 3D lines and splines #26

aaronfranke opened this issue Apr 14, 2019 · 15 comments

Comments

@aaronfranke
Copy link
Member

In Godot, I sometimes find that I would like the ability to draw lines in 3D. I think that such a thing might be a useful node to have in this node extensions repo.

Possible functionality:

  • Pass two points and have it draw a line between them

  • Pass an origin point and an offset, or a direction+magnitude

  • Pass an array of points and draw lines between all of them (index 0 to 1, then 1 to 2, etc)

  • Ability to set the thickness of the line

  • Ability to set color of the line, perhaps each end having a different color

@Zireael07
Copy link

Dropping this here for interest, alas I don't know how to make custom nodes themselves: https://github.com/Zireael07/FreeRoamRoguelikeRacerPrototype/blob/master/game/scripts/draw_line.gd

@willnationsdev
Copy link
Member

I don't know how to make custom nodes themselves

All you do is add class_name <typename>, e.g. class_name Spline, under the extends statement of the GDScript file. Setting the script_class_name property of a .gdns NativeScript resource also defines a name for that type.

@realkotob
Copy link

I'd like to work on this since I'd like to easily have debugging visualization for stuff in 3D.

I'll likely make a Singleton that can be called to spawn 3D objects, and then a script for each object such as LineGeometry3D, SphereGeometry3D, CurveGeometry3D, etc...

But most importantly, what use cases are we aiming for here? In-editor tooling? Ingame debugging? Do they need to be persistent or clear afterwards, etc...

I know my use case, which is visualization vectors to make physics debugging easier, but I'd like to know what it is we actually we want to support for this class.

@Zireael07
Copy link

Personally, I use the little script I linked for both in-editor tooling and in-game debugging.

@willnationsdev
Copy link
Member

willnationsdev commented Apr 27, 2020

I think the editor/game-time debugging use case is the main one here...but not sure if @aaronfranke has other use cases in mind.

@aaronfranke
Copy link
Member Author

Yes, my use case is debugging, possibly both in-editor and in-game debugging.

@RichardEllicott
Copy link

RichardEllicott commented Oct 30, 2020

is this the same request as a basic LineRenderer like in Unity?

Still i can't make any sort of laser beam or bullet line, this one drives me nuts

@Zireael07
Copy link

@RichardEllicott: Yeah, pretty much Unity's LineRenderer.

@Eman2022
Copy link

Eman2022 commented Apr 5, 2021

Dropping this here for interest, alas I don't know how to make custom nodes themselves: https://github.com/Zireael07/FreeRoamRoguelikeRacerPrototype/blob/master/game/scripts/draw_line.gd

thankyou! this helped me out. How I got it to work:

File Location:
var drawLineFile = load("res://Orometry/draw_line.gd")

I drew lines from mountain peaks to their saddles
for n in range(peaks.size()): # get the points you want in your line var pathVerts = pather.returnObVertPath(peaks[n], peaks[n].saddle) for vert in pathVerts: vert.y += 0.3 # I raised the points up a little to be more visible var pencil = drawLineFile.new() pencil.draw_line_color(pathVerts,10,peaks[n].color) add_child(pencil)

@RichardEllicott
Copy link

Dropping this here for interest, alas I don't know how to make custom nodes themselves: https://github.com/Zireael07/FreeRoamRoguelikeRacerPrototype/blob/master/game/scripts/draw_line.gd

thankyou! this helped me out. How I got it to work:

File Location:
var drawLineFile = load("res://Orometry/draw_line.gd")

I drew lines from mountain peaks to their saddles
for n in range(peaks.size()): # get the points you want in your line var pathVerts = pather.returnObVertPath(peaks[n], peaks[n].saddle) for vert in pathVerts: vert.y += 0.3 # I raised the points up a little to be more visible var pencil = drawLineFile.new() pencil.draw_line_color(pathVerts,10,peaks[n].color) add_child(pencil)

thanks for this snippet... however i tested it and it's way short of Unity's LineRenderer

this code's "line width" does not have any effect, also there is no way of applying a texture to the line

@RichardEllicott
Copy link

RichardEllicott commented Apr 12, 2021

So where can i request a "LineRenderer"? (like Unity)

it takes a laser texure, like this one:
https://i.stack.imgur.com/3YvXH.png

and it sort of "always faces you" like how the billboard sprite does but when you have that special setting...... i have this feeling someone who programmed the billboard sprite, this almost could just be another setting ... like less code required than you think .... i don't personally care if it doesn't have multiple points, i can do that in code, it's the effect of it's look

otherwise you have to crate a weird star shaped mesh to do laser lines, like this:
https://stackoverflow.com/questions/37726819/how-to-do-a-laser-effect-with-hlsl-and-directx-11

i appreciate this is probably complicated for the devs under the hood but would be cool to get some sort of answer if it could be possible

@Zireael07
Copy link

Yes, it's not equivalent to Unity's LineRenderer, but as I most often used Unity's for debugging, it's enough.
Line width not having an effect is IIRC a driver/GLES limitation.

As for texture, I believe it might be possible but you'd need to calculate all the UVs for all the vertices, etc. - IMHO a lot of pain for little gain.

@RichardEllicott
Copy link

RichardEllicott commented Apr 12, 2021

well i don't see how you can texture it as it doesn't have width, so pretty pointless unfortunately

for my purposes i'm using little octagon cylinders atm.... for laser lines..... maybe the problem is more complicated than i give it credit, as the Unity LinerRenderer does render on top of everything (from my memory ~4 years back)

@Eman2022
Copy link

I needed this for testing and it does the trick perfectly. This is great for simple things such as just redrawing the x-z-y axis lines that don't show up when you launch your scene. It also works great for drawing out a path that AStar path tracing has found. I also noticed the width didn't seem to be working but... didn't need it.

@sairam4123
Copy link

sairam4123 commented Aug 24, 2021

I've been working on a DrawingUtils to draw lines and basic 2D shapes. I'll pull request once it's done.
Supports drawing splines, triangles, squares, circles and lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants