minetest / minetest

Minetest is an open source voxel game-creation platform with easy modding and game creation
https://www.minetest.net/
Other
10.64k stars 2.01k forks source link

Formspecs: Draw simple shapes (polygons, polylines, circles) #8087

Closed orwell96 closed 5 years ago

orwell96 commented 5 years ago
Issue type

Formspecs currently feature the box[] element to draw a colored rectangle. You can draw horizontal and vertical lines using this, too. However, I would like to draw polylines or other primitive shapes that may be diagonal. This would allow, for example, for creating in-game road/railway mappers.

If a replacement for the formspec language should be implemented, I would be fine with it implemented there.

rubenwardy commented 5 years ago

This could be done with image elements

SmallJoker commented 5 years ago

I think an image drawing library (like cairo) would be better suited for this job.

paramat commented 5 years ago

~Formspec element positioning is so weird and buggy i don't think this would be usable for drawing anything as the elements couldn't be aligned. -1~

raymoo commented 5 years ago

You can't draw arbitrary length diagonal lines with images because you can't rotate them except in multiples of 90 degrees. Stretching an image of a diagonal line will change the line's width. Same with circles, you can't get an arbitrary radius / line width circle without making a new image for every circle, which may not be possible if you are dynamically deciding these parameters.

raymoo commented 5 years ago

Wouldn't #8524 solve your concern about coordinates being weird?

Desour commented 5 years ago

Related: #8549

Couldn't drawing primitives be done with vector graphics? (Related: #2419)

v-rob commented 5 years ago

I think dynamic images (like ^[combine, but actually designed for dynamically created images) would be a better solution to this problem. The main problem with ^[combine is that it fills up the cache on the client after a while, making it non-feasible for something that can change constantly.

Dynamically-created images would be killing two birds with one stone -- both entities and formspecs could have dynamic images. You could also place the image on both an entity and a formspec (think placing the rail map on both the formspec and somewhere in the train entity).

raymoo commented 5 years ago

How do you imagine I would draw a diagonal line of arbitrary length? I think one way it could be solved is with rotation modifiers other than in multiples of 90 degrees, but maybe you have something else in mind.

raymoo commented 5 years ago

@DS-Minetest I think vector graphics would have the same problem with diagonal lines I mentioned in https://github.com/minetest/minetest/issues/8087#issuecomment-455709451

EDIT: Assuming that "using vector graphics" means "using SVG files" like the linked issue is about.

v-rob commented 5 years ago

How do you imagine I would draw a diagonal line of arbitrary length? I think one way it could be solved is with rotation modifiers other than in multiples of 90 degrees, but maybe you have something else in mind.

By dynamic images, I mean images that you actually create. You would draw directly to pixels, and, if an API was created, probably lines, circles, and suchlike. I'm not speaking of modifying/rotating existing images, I mean making new ones entirely with the possibility to combine with existing images. There are a few issues for this.

raymoo commented 5 years ago

Oh, I see. That doesn't sound very efficient if you wanted to draw a very long diagonal line, since you would need to draw and store a texture with size quadratic in the length of the line. With a line primitive the engine could just use two triangles to draw the line and the rasterizer would just need to fill in the pixels along the line instead of a huge square bounding the line.

paramat commented 5 years ago

Deleted my comment as formspec coordinates have been improved. However i still don't like the idea and it is disapproved by 2 other core devs.

raymoo commented 5 years ago

@rubenwardy's disapproval is based on a false premise (that this feature is possible with image elements). For example, it is not possible to draw uniform length diagonal lines with procedural length and width.