Hey folks.
Just a short post saying that I’ve finished version 1 and could do with feedback.
Here are some screenshots:
You can mess with it here: plasmation.jamesheazlewood.com/scenes/editor/1
Here’s a video showing how to use the interface:
The exporter
While I’m here, I should get into how I managed to get the exporter working.
My first atttempt was to change the renderer so it would render to a bunch of textures stored in an array. This worked well and it allowed me to use a JQuery slider to scrub through the exported frames. However, because all these images were stored in web.gl buffers, it was hard to get the data from them. Another issue was that it was using an enormous amount of GPU memory as the webGL contect would crash multiple times when exporting more than 100 or so images (I guess storing over 100 512×512 textures is a bad idea…)
My next attempt was to simply use the canvas to render. The way I did this was just render the animation to the canvas the way way I had been before, except implement things like frame skips and allow the user to control whether it has opacity or not.
This was fairly easy, apart from mutliple bugs with Jquery (I ended up just using the context straight from javascript).
The frame constructor worked by rendering a frame to the main canvas, and then using a different 2D canvas, draw this frame on top of what was already on this new 2D canvas ad a proper location. This was easy as I could choose the scaling of the image as well (although it kind of sucks, but I want to wait and see how it looks once I add the lens blur effect to prevent that noisy velocity thing).
Below is the code for creating the sprite-sheet client-side:
plas.Reset(); plas.RefreshShaders(); plas.options.viewMode = 1; plas.Render(); plas.ticks = 0; var image; var canvas = document.getElementById('image_compile'); var context = canvas.getContext('2d'); var scale = plas.options.scale; var size = (512 * scale); var frameCount = plas.options.frames; var h = Math.round(frameCount / plas.options.horFrames); canvas.width = size * plas.options.horFrames; canvas.height = size * h; context.globalAlpha = 1.0; var rFrame = 0; var x, y; while(rFrame < frameCount) { if(plas.Render()) { x = rFrame % plas.options.horFrames; y = Math.floor((rFrame - x) / plas.options.horFrames); image = new Image(); image.src = plas.BufferData(); context.drawImage(image, x * size, y * size, size, size); rFrame ++; } } $("#image_output").attr("src", canvas.toDataURL("image/png"));
Once the frames are rendered to the new canvas, it gets all the data from this canvas and converts it to a data url (base64 encoded thing, the same as I already had) and puts that in an image ready for exporting. The user can then just save the image to their hard drive.
I noticed that the you can save a canvas as an image in Firefox and Chrome, which meant I didn’t even need to create an image from the canvas data, however, although Internet Explorer 11 ran the simulation really well, it couldn’t save canvas data as an image. This meant that I had to convert it to an image.
The next step was then going through all the set-able options in the scene and giving them controls. I used a slider because I find it requires less clicks and typing to just move a slider back and forth. I added titles to these sliders and then got it to also draw their values underneath.
Done.