Utils
Note: This documentation is for the old 1.2.0 version of A-Frame. Check out the documentation for the current 1.6.0 version
A-Frame’s utility modules are public through AFRAME.utils
.
AFRAME.utils.coordinates
Module for handling vec3 and vec4 types.
.isCoordinates (value)
Tests whether a string is a vec3 or vec4.
AFRAME.utils.coordinates.isCoordinates('1 2 3') |
.parse (value)
Parses an “x y z” string to an {x, y, z}
vec3 object. Or parses an “x y z w” string to an {x, y, z, w} vec4 object.
AFRAME.utils.coordinates.parse('1 2 -3') |
.stringify (data)
Stringifies an {x, y, z}
vec3 object to an “x y z” string.Or Stringifies an {x, y, z, w}
vec4 object to an “x y z w” string.
AFRAME.utils.coordinates.stringify({x: 1, y: 2, z: -3}) |
AFRAME.utils.entity
.getComponentProperty(entity, componentName, delimiter='.')
Performs like Entity.getAttribute
, but with support for
return an individual property for a multi-property component. componentName
is a string that can either be a component name, or a component name delimited
with a property name.
// <a-entity id="box" geometry="primitive: box"></a-entity> |
This is useful for components that need a way to reference a property of a multi-property component.
.setComponentProperty (entity, componentName, value, delimiter)
Performs like Entity.setAttribute
, but with support for setting an
individual property for a multi-property component. componentName
is a string
that can either be a component name, or a component name delimited with a
property name.
// <a-entity id="box" geometry="primitive: box"></a-entity> |
AFRAME.utils.styleParser
.parse (value)
Parses a CSS style-like string to an object.
AFRAME.utils.styleParser.parse('attribute: color; dur: 5000;') |
.stringify (data)
Stringifies an object to a CSS style-like string.
AFRAME.utils.styleParser.stringify({height: 10, width: 5}) |
Object Utils
AFRAME.utils.deepEqual (a, b)
Checks if two objects have the same attributes and values, including nested objects.
deepEqual({a: 1, b: {c: 3}}, {a: 1, b: {c: 3}}) |
AFRAME.utils.diff (a, b)
Returns difference between two objects. The returned object’s set of keys denote which values were not equal, and the set of values are b
‘s values.
diff({a: 1, b: 2, c: 3}, {b: 2, c: 4}) |
AFRAME.utils.extend(target, source, [source, ...])
AFRAME.utils.extendDeep (target, source, [source, ...])
AFRAME.utils.device
AFRAME.utils.device.checkHeadsetConnected ()
Checks if a VR headset is connected by looking for orientation data. Returns a boolean
.
AFRAME.utils.device.isGearVR ()
Checks if device is Gear VR. Returns a boolean
.
AFRAME.utils.device.isOculusGo ()
Checks if device is Oculus Go. Returns a boolean
.
AFRAME.utils.device.isMobile ()
Checks if device is a smartphone. Returns a boolean
.
Function Utils
AFRAME.utils.throttle (function, minimumInterval [, optionalContext])
Returns a throttled function that is called at most once every
minimumInterval
milliseconds. A context such as this
can be provided to
handle function binding for convenience. The same as lodash’s
throttle
.
AFRAME.registerComponent('foo', { |
AFRAME.utils.throttleTick (function (t, dt) {...}, minimumInterval [, optionalContext])
Returns a throttled function that is called at most once every
minimumInterval
milliseconds. A context such as this
can be provided to
handle function binding for convenience.
This variant of .throttle()
is slightly more performant and tailored for
tick
handlers as it uses the t
and dt
timestamps passed by the global
render loop.
AFRAME.registerComponent('foo', { |
Miscellaneous
AFRAME.utils.getUrlParameter (name)
Returns the value of a URL parameter as a string, otherwise returns an empty string.
AFRAME.utils.getUrlParameter('testing'); |