How PixAnvil Works
"Reset". It loads the code from three tabs:
Variables declared in Setup are automatically
accessible from Loop and UI. There are also an empty storage
objects called sim and store that can be used to
store your data.
The 3D vector class vec3 is key to most
3D work. In PixAnvil, this class is a renamed version of BABYLON.Vector3.
By convention, vectors in PixAnvil are written with capital
letters. Given two vectors A and B:
- var A=new vec3(x,y,z); creates a new
vec3 with the given components.
- A.set(x,y,z); sets the vector's
components to these values. This is sometimes needed when
another object has a reference to the vector, such as an
- var C=A.p(B); adds the two vectors,
returning a new third vector, like + (plus).
- A.pe(B); adds B into A, changing A,
like += (plus-equals).
- var C=A.m(B); subtracts the two
vectors, returning a new third vector, like - (minus).
- A.me(B); adds B into A, changing A,
like -= (minus-equals).
- var C=A.t(2.0); scales the A vector by
the scalar, returning a new third vector, like *
- A.te(2.0); scales the A vector,
changing it, like *= (times-equals).
- A.rand(x,y,z); sets the vector's
components to lie in the range [-x/2,+x/2], [-y/2,+y/2],
- A.randSphere(diameter); makes
a random 3-vector inside a sphere of this diameter (vector
length can be as big as diameter/2)
- var c=length(A); makes the scalar
c the length of the vector A.
- var C=normalize(A); makes C a
unit-length vector pointing the same direction as the vector
A. If the vector A is zero, the normalized version is zero.
- var c=dot(A,B); makes c the scalar
dot product of A and B.
- var C=cross(A,B); makes C the
right-handed cross product of A and B.
Your code in Setup, Loop, and UI is also given access to a
number of variables:
You also now have direct access to the simple
WebGL library Igloo, available as "igloo".
- scene is the main BABYLON.Scene
object, created by PixAnvil every Reset. Most onscreen objects
in Babylon.js take a scene as a constructor parameter.
- camera is the main viewport camera
object, a BABYLON.ArcRotateCamera
object, created by PixAnvil every run. You can change where the
camera is looking toward, by calling camera.setTarget(vec3). You
can change where the camera is looking from, by calling
camera.setPosition(vec3), which gets translated as a
- scene is the main BABYLON.Scene object.
Most objects need a scene as a constructor parameter.
creates a ground plane at the given Z axis height. By default
an object at a height of Z=0.0 and a size of 1024 units is
created. The object is returned, if you'd like to further
adjust the position or orientation.
creates red (X axis), green (Y axis), and blue (Z axis) lines.
Size is the length of the lines. Parent is the object used as
the origin, or world origin if not defined.
creates a line pointing in this direction with this color.
Color is a BABYLON.Color3. Parent is the object used as the
origin, or world origin if not defined. Returns the newly
created line mesh object.
creates a line from start to end with this color. Color is a
BABYLON.Color3. The line vanishes at the next frame unless
- lib.tempBox(lo,hi,color) creates
a 3D box with corners lo and hi, with this color. Color is a
BABYLON.Color3. The box vanishes at the next frame unless
- lib.dt is the time, in seconds,
between animation frames. In UI, this value is the real wall
clock time in seconds. In Loop, this value is scaled by the
simulation time scale factor.
- lib.dt_avg is the average time, in
real wall clock seconds, between animation frames.
- lib.time is the cumulative
simulation time, in seconds. Internally it is updated by
adding up lib.dt values.
are the window coordinates x,y pixel dimensions of the
- lib.mousex,lib.mousey are
the window coordinates x,y pixel location of the mouse cursor
are the change in x,y pixel coordinates since the last frame.
These values are slightly smoothed to produce smooth
animations even with jerky 30Hz mice.
- lib.mouseleft is a boolean
value that is set to true if the left mouse button is down.
- lib.key is an ASCII-indexed array of
boolean values, set to true if that ASCII keyboard key is
currently pressed down. For example, lib.key['k'] is
true if the k key is currently held down.
- lib.key_typed is an
ASCII-indexed array of boolean values, set to true if that key
has just been typed--either a key release, or a key repeat.
The value will be true for exactly one Loop and one UI frame,
then set to false again. /li>
- lib.key_toggle is
ASCII-indexed an array of boolean values, initially false.
Typing the corresponding key will toggle the state of the
boolean from false to true or back again. This is useful for
enabling or disabling simulation features.
- lib.wasd_camera(speed) moves
the camera position using the W, A, S, and D keys, as well as
Q and Z for up and down motion. The camera target is
returns a string of the data contained in the given tabName.
This is useful for loading simulation data, or GLSL shaders.
- 2017-03-02: Fix "Reset" bug by reloading BABYLON on reset.
- 2017-02-26: Igloo directly accessible.
- 2017-02-03: Added geometry recycling, so tempBox and
tempVector are much faster now.
- 2017-01-25: Variables declared in Setup are now accessible
from Loop and UI directly.
- 2017-01-19: PixAnvil coordinate system is now right handed
(for some reason this is not the Babylon default, you need to
set scene.useRightHandedSystem = true).
- 2017-01: PixAnvil now uses Babylon.js instead of THREE.js.
O. Lawlor, firstname.lastname@example.org