Add a CollectionsSlideNavigator that controls the root collection of this figure.
Get the CollectionsSlideNavigator for the figure (will only return
if the navigator was added with figure.addSlideNavigator).
Add cursor for recording interactive videos. Cursor will be hidden when first added.
cursor element
Get cursor element.
cursor element
Add a figure element to the root collection of the figure.
If adding an array of elements, then the added elements will be returned in an array (even if only one element is added). If not adding an array, then that single element will be returned.
reference name of element
element to add
added element, or array of added elements
// Add name and element
const element = figure.primitives.polygon({ radius: 1 });
figure.add('name', element);
// Element only (name will be autogenerated)
const element = figure.primitives.polygon({ radius: 1 });
figure.add(element);
Get element from an element path with '.' separators.
For instance, if a collection has a child collection 'a', which has a child primitive 'b', then the path would be: 'a.b'.
element at path. If elementPath
is null, then the figure's base collection is returned. If elementPath
is invalid then null is returned.
// Get all the elements from a figure
figure.add(
{
name: 'c',
make: 'collection',
elements: [
{
name: 'tri',
make: 'triangle',
height: 0.4,
width: 0.4,
},
{
name: 'text',
make: 'text',
text: 'triangle',
position: [0, -0.4],
xAlign: 'center',
},
],
},
);
const c = figure.getElement('c');
// Elements within collections can be found with dot notation
const tri = figure.getElement('c.tri');
// Or the collection can be queried directly
const text = c.getElement('text');
Returns an array of result from getElement calls on an array of paths.
Array of getElement results
Returns an array of result from
getElement calls on an
array of paths. Same as getElements but more succinct
Array of getElement results
Recreate all automatically generated atlases.
This would be typically used after loading custom fonts.
Return matrix that can convert between 'pixel', 'figure' and 'gl' spaces.
These matrices would be generally used to transform points between spaces.
transformPoint can be used to do this for individual points, but if
converting many points, then generating the transform matrix once and
applying it to each point can be more efficient.
Depending on the type of figure scene, not all space combinations are possible.
For 2D scenes, all combinations are possible.
For 3D scenes:
transformPoint instead where a
plane can be defined to intersect with.transformPoint for each point to be transformed.Transform a point between 'figure', 'gl' and 'pixel' spaces.
plane is only needed when converting from pixel space (a 2D space) to
'figure' space or 'gl' space (a 3D space). A ray from the pixel is drawn
into the screen and the intersection with the defined plane is returned.
space to convert point from
space to convert point to
figure space intersection plane for 'pixel' to 'figure' conversion (default: xy plane at z = 0)
Get remaining animation durations of running animations
Show specific elements within a figure, while hiding all others
Set scenarios of all elements with scenarioName defined
Stop all animations, movement and pulses in figure.
Debug - 3D Shapes
Show touchable 3D shapes in figure. This will only last for one animation frame, so it will not work if an animation is ongoing.
Note, the shown borders will be for the instant this method is called only. If animation is ongoing, the shown borders will not move with the animation. To update the borders, call this method again.
Debug - 2D Shapes
Show the touchBorders of selected elements in the figure or all elements in the figure.
Note, the shown borders will be for the instant this method is called only. If animation is ongoing, the shown borders will not move with the animation. To update the borders, call this method again.
use null for all
elements, touchable for all touchable elements or define specific
elements to show ('touchable')
array of colors to cycle through for each shape ([blue, cyan, purple, green, red, yellow, black])
Debug - 2D Shapes
Show the borders or touchBorders of selected elements in the figure or all elements in the figure.
('border')
use null for all
elements, touchable for all touchable elements or define specific
elements to show (null)
array of colors to cycle through for each shape ([blue, cyan, purple, green, red, yellow, black])
Force figure to draw on next available animation frame.
Check if any element in the figure is animating.
Sets manual frames.
Normally, when a browser is ready to refresh the screen it will call FigureOne to do a draw. The time between frames is not fixed and depends on a number of factors. This is the most performant way to handle drawing.
However, when debugging it can be useful to manually trigger a draw frame with a defined delta time from the last frame.
This method turns on manual frames. Use frame to trigger a draw.
End manual frames. Reverts drawing to when browser reqeusts it.
Manually trigger a draw frame with a specified time step (in seconds) from
the last draw frame. Can only be used when setManualFrames() has been
called.
in seconds
Add a frame rate annotation to the figure.
Each time the browser requests FigureOne to paint the screen, FigureOne performs two main tasks:
Frame rate is determined by FigureOne's total frame processing time (setupDraw time + draw time), and how frequently a browser requests FigureOne to draw a frame.
The frame rate will not be faster than the browser wants, but it can be slower if the total frame processing time is too long.
The frame rate and time durations are reported as both an average, and
worst case (max). The averaging is done over numFrames number of frames.
The screen output is then:
Where:
Note: FigureOne only requests animation frame notifications from the browser when an element is animating or moving. If everything is still, then the frame rate will be 0.
Primary Figure class.
A figure will attach a WebGL canvas and 2D canvas to the html
divelement with id"figureOneContainer".The figure creates and manages all drawing elements, renders the drawing elements on a browser's animation frames and listens for guestures from the user.
The figure also has a recorder, allowing it to record and playback states, and gestures.
To attach to a different
div, use thehtmlIdproperty in the class constructor.If a figure is paused, then all drawing element animations will also be paused.
Figurehas a number of convenience methods for creating drawing elements and useful transforms for converting between the different spaces (e.g. pixel, GL, figure).Notifications - The notification manager property
notificationswill publish the following events:beforeDraw: published before a frame is drawnafterDraw: published after a frame is drawnresize: published after a resize event, but before frame drawingParam: options
Example
Example