@whoisbma I know we said no documentation needed, but I thought I'd leave a few notes and a few references here, just in case.
Notes
This PR refactors the codebase to be a tiny bit more modular. The goal here was basically to split out the the simulation step of the system (now in src/Simulation.js) and the rendering subsystems (now in View2d.js, View3d.js, &c).
The TileProvider class in sim-1.js houses both the simulation and a list of renderers, several of which could be active at once. The basic render loop of the application is: 1) TileProvider calls .simulate() on the simulation. This steps the state forward a single time step. 2) TileProvider calls render() on all of the tiles in the list of renderers. Each of these may or may not draw to the screen. 3) TileProvider increments the global time step by 1, then goes to step 1. A big todo for me is to refactor input handling, which is basically a big block of event listeners right now. I want input to be handled at the beginning of each frame, and I want each renderer to have an opportunity to change its state based on input at the beginning of each frame.
Every renderer is designed to be a subclass of the View class in View.js. This class implements the basic interface for the renderer as well as a default render operation. If you're implementing a renderer, consider subclassing View and overriding the render() method.
.render() gets two parameters: resources, and parameters. resources includes .t, the current time step, .camera, which can construct the ViewProjection matrix for the current 3D view with it's get_matrix() method, and .transform_2d, which is a 3x3 affine transformation matrix used to place quads for the 2D views. parameters contains the current states of the global parameters to the simulation, defined in parameters.js.
Each renderer can reference the simulation through this.parent. That reference will contain pointers to the simulations various state variables stored in textures, like H (the height buffer) or Q (the flux buffer).
Note: preserveDrawingBuffer
I enabled preserveDrawingBuffer: true in regl. You should now be able to get the contents of the current canvas output as a Uint8Array by calling
// essentially a thin wrapper around gl.readPixels()
let pixels = regl.read();
// pixels is now a Uint8Array instance.
at any point. If you're interested in the contents of a particular framebuffer associated with a simulation variable, you can now get at by:
/** Let's say you want to read the DoubleFramebuffer containing
* the height map of the simulation, which (in a rendering class like View2d)
* lives in this.parent.H
**/
this.parent.H.front.use(async () => {
let pixels = await regl.read();
// pixels is now a Float32Array instance
});
@whoisbma I know we said no documentation needed, but I thought I'd leave a few notes and a few references here, just in case.
Notes
src/Simulation.js
) and the rendering subsystems (now inView2d.js
,View3d.js
, &c).TileProvider
class insim-1.js
houses both the simulation and a list of renderers, several of which could be active at once. The basic render loop of the application is: 1)TileProvider
calls.simulate()
on the simulation. This steps the state forward a single time step. 2)TileProvider
callsrender()
on all of the tiles in the list of renderers. Each of these may or may not draw to the screen. 3)TileProvider
increments the global time step by 1, then goes to step 1. A big todo for me is to refactor input handling, which is basically a big block of event listeners right now. I want input to be handled at the beginning of each frame, and I want each renderer to have an opportunity to change its state based on input at the beginning of each frame.View
class inView.js
. This class implements the basic interface for the renderer as well as a default render operation. If you're implementing a renderer, consider subclassingView
and overriding therender()
method..render()
gets two parameters:resources
, andparameters
.resources
includes.t
, the current time step,.camera
, which can construct the ViewProjection matrix for the current 3D view with it'sget_matrix()
method, and.transform_2d
, which is a 3x3 affine transformation matrix used to place quads for the 2D views.parameters
contains the current states of the global parameters to the simulation, defined inparameters.js
.this.parent
. That reference will contain pointers to the simulations various state variables stored in textures, likeH
(the height buffer) orQ
(the flux buffer).Note: preserveDrawingBuffer
I enabled
preserveDrawingBuffer: true
in regl. You should now be able to get the contents of the current canvas output as aUint8Array
by callingat any point. If you're interested in the contents of a particular framebuffer associated with a simulation variable, you can now get at by: