example-scripts
example-scripts copied to clipboard
Add Textures Example (works with edge version of Openplanet)
This is a draft for 2 reasons:
- It depends on the new textures stuff (which I understand is to be released in v1.24.0)
- I haven't added comments.
There are two todos:
- [ ] documentation for relevant functions (like
nvg::TexturePattern) - [ ] comments / explanation / etc
Similarly as #7, this might be showing a bit too much extra stuff, such as loading an image from HTTP and the animation on NanoVG. It's cool, but maybe a bit too complex.
That said, it might be hard to include a working example script w/o also providing assets to go with it. Maybe this repository should be restructured into multiple modern plugins instead to facilitate it, and also make it more up-to-date with the current API.
image from HTTP
I rejected these alternatives: adding an image file to the repo (this would require introducing a build process or something), hardcoding an image in base64 and decoding it. I guess loading an image with a known location that will always exist could work, but which image?
HTTP seemed a reasonable soln within the constraints of a one-file example script. (I agree that restructuring the repo would be useful, but my goal was to provide a self-contained example about loading a texture, so that wasn't an option for this PR, and wouldn't have made sense to do proactively.)
the animation on NanoVG
When I ran the plugin I couldn't see the texture originally b/c I had the log-window in the way. The animation makes it way more obvious and ensures there's something to tell the user that the texture/plugin isn't frozen or w/e (the UI::Image example can be dragged around so that one is okay already).
Additionally, the animation requires using some other useful things like GetSize(). I think showing more than the minimum is good b/c it helps he user avoid immediately running into problems when they try to go 1 step beyond the minimum.
Yes, I think I'll take some time soon to restructure this repository into modern plugins.
Also, keep in mind that people might not necessarily take the code and run the examples for themselves, but only look at the code, so anything super fancy won't be absolutely required.
I think something like this is a lot easier to understand than 7 lines of confusing math to (essentially) calculate pos:
vec2 pos = vec2(100, 150);
vec2 size = g_textureNvg.GetSize();
nvg::BeginPath();
nvg::Rect(pos, size);
nvg::FillPaint(nvg::TexturePattern(pos, size, 0, g_textureNvg, 1));
nvg::Fill();
By the way, the declaration for TexturePattern is:
Paint TexturePattern(const vec2 &in origin, const vec2 &in size, float angle, nvg::Texture@+ texture, float alpha)
I think something like this is a lot easier to understand than 7 lines of confusing math to (essentially) calculate pos:
Yeah gp. Part of the reason there are so many lines is b/c I thought a 'beating' animation would be cute (originally it was just sinusoidal stretching of size).
By the way, the declaration for TexturePattern is:
Is there a way to access docs for function signatures before openplanet.dev/docs/api is updated? (I searched discord and found some stuff from Greep about it that helped)
I looked in NanoVG docs but the translation to Openplanet API wasn't as clear to me as it is for imgUi (I've used the imgUi docs before to help with some stuff)
There is no way to look at documentation for betas right now unfortunately. Documentation is still something that needs to improve quite a bit on the site, beta documentation being a smaller part of that. Might implement a way to look at that later.