3 ms·
I know what you mean! Unity3D has no way to simply draw a circle or pie chart into a texture. It would be great to be able to use the canvas api (and any JavaS
by DonHopkins 8y ago
I know what you mean! Unity3D has no way to simply draw a circle or pie chart into a texture.
It would be great to be able to use the canvas api (and any JavaScript library like d3 that uses canvas) to dynamically draw Unity3D textures.
To address that problem (and others), I'm been developing a Unity3D extension called UnityJS, which integrates a web browser and JavaScript with Unity3D, so you can use the canvas api to draw images for use as 2D user interface overlays and 3D mesh textures in Unity. And of course the other (main) point of UnityJS is to use JavaScript for scripting and debugging Unity apps, and integrate Unity apps with off-the-shelf JavaScript web libraries (d3, socket.io, whatever).
https://github.com/SimHacker/UnityJS/blob/master/doc/Anatomy.txt https://github.com/SimHacker/UnityJS/blob/master/doc/Anatomy...
Drawing on canvases actually works pretty well in the WebGL build, because the JavaScript runs in the same browser tab and address space that's running the Unity app, so you can efficiently blit the canvas's pixels right into Unity's texture memory.
(Although I don't believe there's a way to share the canvas texture directly through GPU memory, or even directly share Unity's ArrayBuffer memory, but it's fast enough for interactive user interface stuff, and millions of times better than the "portable" technique of writing out a data uri with a base 64 encoded compressed png file, which is the "standard" way of getting pixels out of the web browser! Web tech sure sucks!)
https://github.com/SimHacker/UnityJS/blob/master/Libraries/UnityJS/StreamingAssets/UnityJS/bridge.jss#L640 https://github.com/SimHacker/UnityJS/blob/master/Libraries/U...
- bufferoverflow 8y agoActually a circle is very easy to draw using a shader: (4th answer down) https://stackoverflow.com/questions/13708395/how-can-i-draw-a-circle-in-unity3d https://stackoverflow.com/questions/13708395/how-can-i-draw-... A pie chart would be harder.
- DonHopkins 8y agoBut drawing that circle (or a pie chart) into a texture (so you don't have to draw each triangle every frame) is a whole can of worms. It might be fine in some cases on a big honking workstation, but reducing the number of draws and triangles becomes quite important when you're doing mobile user interfaces or VR. Also, it would take a hell of a lot of programming to duplicate the canvas api with LineRenderer and dynamic meshes. And then you've rolled yourself a custom C# drawing API, so there aren't any full featured well supported off-the-shelf libraries like d3 or chartjs to drive it. One of the nice things about the way UnityJS integrates JavaScript with a standard web browser in Unity apps is that you can use any of the enormous ecosystem of existing off-the-shelf JavaScript libraries without modification (both visual canvas drawing, and JSON based data wrangling libraries and APIs for services). It's all about leveraging existing JavaScript libraries and web technologies, instead of reinventing half-assed Unity C# versions. Given any JSON based web service or SDK you might want to talk to (google sheets or slack for example), the chances of finding a working well supported JavaScript library that talks to it are a lot higher than finding an equivalent C# library that runs in Unity. (Socket.io is a good example: there exist some for Unity, but they all have problems and limitations, and none of them compare in quality and support to the standard JavaScript socket.io library.)
- pcwalton 8y agoYou've described exactly why I want to integrate Pathfinder into Unity [1]. :) Pathfinder offers a subset of HTML canvas that I would like to expand over the next few weeks and months into the full API. (Ideally it will actually be the HTML canvas implementation for Firefox someday.) There's also the benefit that Pathfinder can transform the canvas in 3D while keeping the content in vector form (i.e. no quality loss), which is important for VR. [1]: https://github.com/pcwalton/pathfinder/issues/147 https://github.com/pcwalton/pathfinder/issues/147
- maeln 8y agoIt's even more simple using a SDF, and making it a pie-chart is almost trivial: https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm https://iquilezles.org/www/articles/distfunctions2d/distfunc...
- Crinus 8y ago> integrates a web browser and JavaScript with Unity3D, so you can use the canvas api to draw images for use as 2D user interface overlays and 3D mesh textures in Unity. Great use of resources, you could also use ogv.js for animated particle textures :-P
- DonHopkins 8y agoI'm hoping to find an excuse to integrate an Apple ][ emulator into a Unity3D app! https://www.scullinsteel.com/apple2/#appleinvaders https://www.scullinsteel.com/apple2/#appleinvaders