-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add a way to load SVG files from buffer at an adjustable scale #3422
Comments
The SVG module is currently only compiled in editor builds. For this to work in exported projects, the SVG module needs to be compiled in export templates as well, which will increase its binary size. This is not a problem in 4.0 as we'll need run-time SVG loading for godotengine/godot#51159, but this is something to keep in mind for
This approach generally works well as long as you enable mipmaps on the texture in the Import dock. This will use more memory, but it makes run-time scaling easier and faster. |
Good to know about I'm using emojis (3k+) and importing each one of them on a larger scale, this is increasing the size of the EDIT: I updated the proposal with information about the large amount of SVG files and |
Remember that Godot supports colored DynamicFonts, so you can load an |
Unfortunately, this isn't an option for me, the support for colored fonts from the emoji library I'm using (OpenMoji) is low (only Firefox / Edge / Adobe CC supports it), I've tried it on Godot and it doesn't work so I opted for the SVG approach. 😭 One option would be to make Godot support it, but probably the runtime SVG approach is much simpler. |
I am interested in the proposal and I'm working on the thorvg svg upgrade. godotengine/godot#49645 Not sure if the core team will approve of doing the svg import at runtime, but still am interested. |
I'm in for improvements to SVG, being able to decide the import size of a SVG depending on the window size or even on a graphics setting would be great, on the other hand that would need the region rect coordinates to be specified as UVs or to be multiplied by the chosen size, the mulltiplication is easy to implement though so it's not a problem, but only if the sprite don't change rect in the middle of an animation. |
Goost has a way to rasterize SVGs as an But as suggested here, a better SVG importer would need to be integrated. As far as I know, current SVG loader is mostly useful for rendering simple geometry such as editor icons. |
You can use LunaSVG for importing SVG files. It's fast, easy to use, regularly maintained, free from crash and supports a wide range of svg features. |
@sammycage Current plan is to use ThorVG (godotengine/godot#49645). Luna has been tried, but seems to be less maintained, among other things (godotengine/godot#49601). |
@pycbouh This is a misleading statement. |
I understand that it's your project and you are defensive of it, but that's what the maintainer responsible for changes decided after testing it thoroughly. I didn't intend to hurt your feelings, just wanted to point out that we did try it and it didn't work out practically. |
@pycbouh I understand. This is just a suggestion 😊😊😊. |
Not to hurt the feelings of fire who tried to integrate both libs, but I wish him to be more descriptive for the work that is done in general (there's barely anything at #2912, what are other pro's and con's?). 😛 While ThorVG may be better maintained (backed by Samsung), it does not necessarily mean that the quality and feature set is the same. And it's unlikely that such a lib will require major maintenance effort anyways. |
Evaluation notes on Samsung ThorVG vs LunaVG:As requested I have typed some notes. ThorVGhttps://github.com/Samsung/thorvg
LunaSVGhttps://github.com/sammycage/lunasvg
|
Although
It would also be worth investigating how to use CSS to control the coloring of the SVG files as well, rather than having the coloring hard-coded, but that may take a little more work. Example static const std::string KDarkThemeCSS = ".pane { fill:darkgreen;} ...";
static const std::string KLightThemeCSS = ".pane { fill:#80c080;} ...";
lunasvg::Environment::loadGlobalStyleSheet(KDarkThemeCSS); // The theme's properties are applied to every single file that is loaded after this function call. |
This could tie in nicely to #6495, and probably others too, like #2924. Implementing a brand new SVG texture type would really improve Godot's SVG experience and make it much more powerful on that front. |
I think it should be a dedicated SVGTexture with a Even with godotengine/godot#78248, I think SVGTexture is still relevant as a helper for procedural texture generation without relying on a Viewport. |
I've tested an implementation like that here. It works, but the usability is poor, the ".svg" must exist as a file/resource, not as a property of |
I think it could have good usability if you added a way to change the texture's import mode to a SVGTexture, so that it imports a SVGTexture instead of an ImageTexture. You'd need to find a way to restrict this import mode to |
I thought about this possibility, what made me disregard it for now was the current "import workflow", where This is fine in the case of .svg content, but an issue in the case of It's possible to write a custom workflow for |
Describe the project you are working on
2D topdown game.
Describe the problem or limitation you are having in your project
Some elements need to be scaled correctly, the strategy of scaling the SVG up on import and shrinking when drawing has its limitations.
I'm importing a lot of SVG files at a larger scale (and shrinking later), this is increasing the size of the
pck
a lot, being able to load them at runtime would allow me to have a much smallerpck
.Describe the feature / enhancement and how it helps to overcome the problem or limitation
The
Image
contains methods to load different formats from a buffer: bmp, jpg, png, tga, webp.But there are no methods to load buffer containing SVG data.
Implementing this method makes it possible to start working on a solution to update the texture when the desired size changes.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
The addition of this method
Image::load_svg_from_buffer(buffer: PoolByteArray, scale: float = 1.0)
to theImage
.This method should be available in the editor and in exported projects.
If this enhancement will not be used often, can it be worked around with a few lines of script?
No, we can load SVGs from file at runtime with Image::load, but there is no option to load it at different scales, the scale 1.0 is implicit and cannot be modified.
Edit: According to #3422 (comment), SVG is only available in editor builds, so even the Image::load won't work for exported projects.
Is there a reason why this should be core and not an add-on in the asset library?
This method provides functionality to create amazing add-ons, but its implementation depends on things only available in the core, like access to the SVG parser and rasterizer library (nanosvg).
The text was updated successfully, but these errors were encountered: