godot-extended-libraries / godot-next

Godot Node Extensions - Basic Node Extensions for Godot Engine
MIT License
960 stars 61 forks source link

Node to draw 3D lines and splines #26

Open aaronfranke opened 5 years ago

aaronfranke commented 5 years ago

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:

Zireael07 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

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

willnationsdev commented 4 years ago

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 commented 4 years ago

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

RichardEllicott commented 3 years ago

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 commented 3 years ago

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

Eman2022 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.