code
stringlengths 10
343k
| docstring
stringlengths 36
21.9k
| func_name
stringlengths 1
3.35k
| language
stringclasses 1
value | repo
stringlengths 7
58
| path
stringlengths 4
131
| url
stringlengths 44
195
| license
stringclasses 5
values |
---|---|---|---|---|---|---|---|
function Tetrahedron(options) {
var textureCoords = [];
var normals = [];
var detail;
var i;
var t = Math.sqrt(3);
var vertices = [
// Back
1, -1, -1 / t,
-1, -1, -1 / t,
0, 1, 0,
// Right
0, 1, 0,
0, -1, t - 1 / t,
1, -1, -1 / t,
// Left
0, 1, 0,
-1, -1, -1 / t,
0, -1, t - 1 / t,
// Bottom
0, -1, t - 1 / t,
-1, -1, -1 / t,
1, -1, -1 / t
];
var indices = [
0, 1, 2,
3, 4, 5,
6, 7, 8,
9, 10, 11
];
for (i = 0; i < 4; i++) {
textureCoords.push(
0.0, 0.0,
0.5, 1.0,
1.0, 0.0
);
}
options = options || {};
while(--detail) GeometryHelper.subdivide(indices, vertices, textureCoords);
normals = GeometryHelper.computeNormals(vertices, indices);
options.buffers = [
{ name: 'a_pos', data: vertices },
{ name: 'a_texCoord', data: textureCoords, size: 2 },
{ name: 'a_normals', data: normals },
{ name: 'indices', data: indices, size: 1 }
];
return new Geometry(options);
} | This function generates custom buffers and passes them to
a new static geometry, which is returned to the user.
@class Tetrahedron
@constructor
@param {Object} options Parameters that alter the
vertex buffers of the generated geometry.
@return {Object} constructed geometry | Tetrahedron ( options ) | javascript | Famous/engine | webgl-geometries/primitives/Tetrahedron.js | https://github.com/Famous/engine/blob/master/webgl-geometries/primitives/Tetrahedron.js | MIT |
Cylinder.generator = function generator(r, u, v, pos) {
pos[1] = r * Math.sin(v);
pos[0] = r * Math.cos(v);
pos[2] = r * (-1 + u / Math.PI * 2);
}; | Function used in iterative construction of parametric primitive.
@static
@method
@param {Number} r Cylinder radius.
@param {Number} u Longitudal progress from 0 to PI.
@param {Number} v Latitudal progress from 0 to PI.
@param {Array} pos X, Y, Z position of vertex at given slice and stack.
@return {undefined} undefined | generator ( r , u , v , pos ) | javascript | Famous/engine | webgl-geometries/primitives/Cylinder.js | https://github.com/Famous/engine/blob/master/webgl-geometries/primitives/Cylinder.js | MIT |
function Triangle (options) {
options = options || {};
var detail = options.detail || 1;
var normals = [];
var textureCoords = [
0.0, 0.0,
0.5, 1.0,
1.0, 0.0
];
var indices = [
0, 1, 2
];
var vertices = [
-1, -1, 0,
0, 1, 0,
1, -1, 0
];
while(--detail) GeometryHelper.subdivide(indices, vertices, textureCoords);
if (options.backface !== false) {
GeometryHelper.addBackfaceTriangles(vertices, indices);
}
normals = GeometryHelper.computeNormals(vertices, indices);
options.buffers = [
{ name: 'a_pos', data: vertices },
{ name: 'a_texCoord', data: textureCoords, size: 2 },
{ name: 'a_normals', data: normals },
{ name: 'indices', data: indices, size: 1 }
];
return new Geometry(options);
} | This function returns a new static geometry, which is passed
custom buffer data.
@class Triangle
@constructor
@param {Object} options Parameters that alter the
vertex buffers of the generated geometry.
@return {Object} constructed geometry | Triangle ( options ) | javascript | Famous/engine | webgl-geometries/primitives/Triangle.js | https://github.com/Famous/engine/blob/master/webgl-geometries/primitives/Triangle.js | MIT |
function Circle (options) {
options = options || {};
var detail = options.detail || 30;
var buffers = getCircleBuffers(detail, true);
if (options.backface !== false) {
GeometryHelper.addBackfaceTriangles(buffers.vertices, buffers.indices);
}
var textureCoords = getCircleTexCoords(buffers.vertices);
var normals = GeometryHelper.computeNormals(buffers.vertices, buffers.indices);
options.buffers = [
{ name: 'a_pos', data: buffers.vertices },
{ name: 'a_texCoord', data: textureCoords, size: 2 },
{ name: 'a_normals', data: normals },
{ name: 'indices', data: buffers.indices, size: 1 }
];
return new Geometry(options);
} | This function returns a new static geometry, which is passed
custom buffer data.
@class Circle
@constructor
@param {Object} options Parameters that alter the
vertex buffers of the generated geometry.
@return {Object} constructed geometry | Circle ( options ) | javascript | Famous/engine | webgl-geometries/primitives/Circle.js | https://github.com/Famous/engine/blob/master/webgl-geometries/primitives/Circle.js | MIT |
function getCircleBuffers(detail) {
var vertices = [0, 0, 0];
var indices = [];
var counter = 1;
var theta;
var x;
var y;
for (var i = 0; i < detail + 1; i++) {
theta = i / detail * Math.PI * 2;
x = Math.cos(theta);
y = Math.sin(theta);
vertices.push(x, y, 0);
if (i > 0) indices.push(0, counter, ++counter);
}
return {
vertices: vertices,
indices: indices
};
} | Calculates and returns all vertex positions, texture
coordinates and normals of the circle primitive.
@method
@param {Number} detail Amount of detail that determines how many
vertices are created and where they are placed
@return {Object} constructed geometry | getCircleBuffers ( detail ) | javascript | Famous/engine | webgl-geometries/primitives/Circle.js | https://github.com/Famous/engine/blob/master/webgl-geometries/primitives/Circle.js | MIT |
function Icosahedron( options )
{
options = options || {};
var t = ( 1 + Math.sqrt( 5 ) ) / 2;
var vertices = [
- 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
0, - 1, -t, 0, 1, -t, 0, - 1, t, 0, 1, t,
t, 0, 1, t, 0, -1, - t, 0, 1, - t, 0, -1
];
var indices = [
0, 5, 11, 0, 1, 5, 0, 7, 1, 0, 10, 7, 0, 11, 10,
1, 9, 5, 5, 4, 11, 11, 2, 10, 10, 6, 7, 7, 8, 1,
3, 4, 9, 3, 2, 4, 3, 6, 2, 3, 8, 6, 3, 9, 8,
4, 5, 9, 2, 11, 4, 6, 10, 2, 8, 7, 6, 9, 1, 8
];
GeometryHelper.getUniqueFaces(vertices, indices);
var normals = GeometryHelper.computeNormals(vertices, indices);
var textureCoords = GeometryHelper.getSpheroidUV(vertices);
vertices = GeometryHelper.normalizeAll(vertices);
options.buffers = [
{ name: 'a_pos', data: vertices },
{ name: 'a_texCoord', data: textureCoords, size: 2 },
{ name: 'a_normals', data: normals },
{ name: 'indices', data: indices, size: 1 }
];
return new Geometry(options);
} | This function returns a new static geometry, which is passed
custom buffer data.
@class Icosahedron
@constructor
@param {Object} options Parameters that alter the
vertex buffers of the generated geometry.
@return {Object} constructed geometry | Icosahedron ( options ) | javascript | Famous/engine | webgl-geometries/primitives/Icosahedron.js | https://github.com/Famous/engine/blob/master/webgl-geometries/primitives/Icosahedron.js | MIT |
function BoxGeometry(options) {
options = options || {};
var vertices = [];
var textureCoords = [];
var normals = [];
var indices = [];
var data;
var d;
var v;
var i;
var j;
for (i = 0; i < boxData.length; i++) {
data = boxData[i];
v = i * 4;
for (j = 0; j < 4; j++) {
d = data[j];
var octant = pickOctant(d);
vertices.push(octant[0], octant[1], octant[2]);
textureCoords.push(j & 1, (j & 2) / 2);
normals.push(data[4], data[5], data[6]);
}
indices.push(v, v + 1, v + 2);
indices.push(v + 2, v + 1, v + 3);
}
options.buffers = [
{ name: 'a_pos', data: vertices },
{ name: 'a_texCoord', data: textureCoords, size: 2 },
{ name: 'a_normals', data: normals },
{ name: 'indices', data: indices, size: 1 }
];
return new Geometry(options);
} | This function returns a new static geometry, which is passed
custom buffer data.
@class BoxGeometry
@constructor
@param {Object} options Parameters that alter the
vertex buffers of the generated geometry.
@return {Object} constructed geometry | BoxGeometry ( options ) | javascript | Famous/engine | webgl-geometries/primitives/Box.js | https://github.com/Famous/engine/blob/master/webgl-geometries/primitives/Box.js | MIT |
function PathStore () {
this.items = [];
this.paths = [];
this.memo = {};
} | A class that can be used to associate any item with a path.
Items and paths are kept in flat arrays for easy iteration
and a memo is used to provide constant time lookup.
@class | PathStore ( ) | javascript | Famous/engine | core/PathStore.js | https://github.com/Famous/engine/blob/master/core/PathStore.js | MIT |
PathStore.prototype.insert = function insert (path, item) {
var paths = this.paths;
var index = paths.indexOf(path);
if (index !== -1)
throw new Error('item already exists at path: ' + path);
var i = 0;
var targetDepth = PathUtils.depth(path);
var targetIndex = PathUtils.index(path);
// The item will be inserted at a point in the array
// such that it is within its own breadth in the tree
// that the paths represent
while (
paths[i] &&
targetDepth >= PathUtils.depth(paths[i])
) i++;
// The item will be sorted within its breadth by index
// in regard to its siblings.
while (
paths[i] &&
targetDepth === PathUtils.depth(paths[i]) &&
targetIndex < PathUtils.index(paths[i])
) i++;
// insert the items in the path
paths.splice(i, 0, path);
this.items.splice(i, 0, item);
// store the relationship between path and index in the memo
this.memo[path] = i;
// all items behind the inserted item are now no longer
// accurately stored in the memo. Thus the memo must be cleared for
// these items.
for (var len = this.paths.length ; i < len ; i++)
this.memo[this.paths[i]] = null;
}; | Associates an item with the given path. Errors if an item
already exists at the given path.
@method
@param {String} path The path at which to insert the item
@param {Any} item The item to associate with the given path.
@return {undefined} undefined | insert ( path , item ) | javascript | Famous/engine | core/PathStore.js | https://github.com/Famous/engine/blob/master/core/PathStore.js | MIT |
PathStore.prototype.remove = function remove (path) {
var paths = this.paths;
var index = this.memo[path] ? this.memo[path] : paths.indexOf(path);
if (index === -1)
throw new Error('Cannot remove. No item exists at path: ' + path);
paths.splice(index, 1);
this.items.splice(index, 1);
this.memo[path] = null;
for (var len = this.paths.length ; index < len ; index++)
this.memo[this.paths[index]] = null;
}; | Removes the the item from the store at the given path.
Errors if no item exists at the given path.
@method
@param {String} path The path at which to remove the item.
@return {undefined} undefined | remove ( path ) | javascript | Famous/engine | core/PathStore.js | https://github.com/Famous/engine/blob/master/core/PathStore.js | MIT |
PathStore.prototype.get = function get (path) {
if (this.memo[path]) return this.items[this.memo[path]];
var index = this.paths.indexOf(path);
if (index === -1) return void 0;
this.memo[path] = index;
return this.items[index];
}; | Returns the item stored at the current path. Returns undefined
if no item is stored at that path.
@method
@param {String} path The path to lookup the item for
@return {Any | undefined} the item stored or undefined | get ( path ) | javascript | Famous/engine | core/PathStore.js | https://github.com/Famous/engine/blob/master/core/PathStore.js | MIT |
PathStore.prototype.getItems = function getItems () {
return this.items;
}; | Returns an array of the items currently stored in this
PathStore.
@method
@return {Array} items currently stored | getItems ( ) | javascript | Famous/engine | core/PathStore.js | https://github.com/Famous/engine/blob/master/core/PathStore.js | MIT |
PathStore.prototype.getPaths = function getPaths () {
return this.paths;
}; | Returns an array of the paths currently stored in this
PathStore.
@method
@return {Array} paths currently stored | getPaths ( ) | javascript | Famous/engine | core/PathStore.js | https://github.com/Famous/engine/blob/master/core/PathStore.js | MIT |
function Event () {
this.propagationStopped = false;
this.stopPropagation = stopPropagation;
} | The Event class adds the stopPropagation functionality
to the UIEvents within the scene graph.
@constructor Event | Event ( ) | javascript | Famous/engine | core/Event.js | https://github.com/Famous/engine/blob/master/core/Event.js | MIT |
function stopPropagation () {
this.propagationStopped = true;
} | stopPropagation ends the bubbling of the event in the
scene graph.
@method stopPropagation
@return {undefined} undefined | stopPropagation ( ) | javascript | Famous/engine | core/Event.js | https://github.com/Famous/engine/blob/master/core/Event.js | MIT |
function Channel() {
if (typeof self !== 'undefined' && self.window !== self) {
this._enterWorkerMode();
}
} | Channels are being used for interacting with the UI Thread when running in
a Web Worker or with the UIManager/ Compositor when running in single
threaded mode (no Web Worker).
@class Channel
@constructor | Channel ( ) | javascript | Famous/engine | core/Channel.js | https://github.com/Famous/engine/blob/master/core/Channel.js | MIT |
Channel.prototype._enterWorkerMode = function _enterWorkerMode() {
this._workerMode = true;
var _this = this;
self.addEventListener('message', function onmessage(ev) {
_this.onMessage(ev.data);
});
}; | Called during construction. Subscribes for `message` event and routes all
future `sendMessage` messages to the Main Thread ("UI Thread").
Primarily used for testing.
@method
@return {undefined} undefined | _enterWorkerMode ( ) | javascript | Famous/engine | core/Channel.js | https://github.com/Famous/engine/blob/master/core/Channel.js | MIT |
Channel.prototype.sendMessage = function sendMessage (message) {
if (this._workerMode) {
self.postMessage(message);
}
else {
this.onmessage(message);
}
}; | Sends a message to the UIManager.
@param {Any} message Arbitrary message object.
@return {undefined} undefined | sendMessage ( message ) | javascript | Famous/engine | core/Channel.js | https://github.com/Famous/engine/blob/master/core/Channel.js | MIT |
Channel.prototype.postMessage = function postMessage(message) {
return this.onMessage(message);
}; | Sends a message to the manager of this channel (the `Famous` singleton) by
invoking `onMessage`.
Used for preserving API compatibility with Web Workers.
@private
@alias onMessage
@param {Any} message a message to send over the channel
@return {undefined} undefined | postMessage ( message ) | javascript | Famous/engine | core/Channel.js | https://github.com/Famous/engine/blob/master/core/Channel.js | MIT |
function Scene (selector, updater) {
if (!selector) throw new Error('Scene needs to be created with a DOM selector');
if (!updater) throw new Error('Scene needs to be created with a class like Famous');
Node.call(this); // Scene inherits from node
this._globalUpdater = updater; // The updater that will both
// send messages to the renderers
// and update dirty nodes
this._selector = selector; // reference to the DOM selector
// that represents the element
// in the dom that this context
// inhabits
this.mount(selector); // Mount the context to itself
// (it is its own parent)
this._globalUpdater // message a request for the dom
.message(Commands.NEED_SIZE_FOR) // size of the context so that
.message(selector); // the scene graph has a total size
this.show(); // the context begins shown (it's already present in the dom)
} | Scene is the bottom of the scene graph. It is its own
parent and provides the global updater to the scene graph.
@class Scene
@constructor
@extends Node
@param {String} selector a string which is a dom selector
signifying which dom element the context
should be set upon
@param {Famous} updater a class which conforms to Famous' interface
it needs to be able to send methods to
the renderers and update nodes in the scene graph | Scene ( selector , updater ) | javascript | Famous/engine | core/Scene.js | https://github.com/Famous/engine/blob/master/core/Scene.js | MIT |
Scene.prototype.getUpdater = function getUpdater () {
return this._updater;
}; | Scene getUpdater function returns the passed in updater
@return {Famous} the updater for this Scene | getUpdater ( ) | javascript | Famous/engine | core/Scene.js | https://github.com/Famous/engine/blob/master/core/Scene.js | MIT |
Scene.prototype.getSelector = function getSelector () {
return this._selector;
}; | Returns the selector that the context was instantiated with
@return {String} dom selector | getSelector ( ) | javascript | Famous/engine | core/Scene.js | https://github.com/Famous/engine/blob/master/core/Scene.js | MIT |
Scene.prototype.getDispatch = function getDispatch () {
console.warn('Scene#getDispatch is deprecated, require the dispatch directly');
return Dispatch;
}; | Returns the dispatcher of the context. Used to send events
to the nodes in the scene graph.
@return {Dispatch} the Scene's Dispatch
@deprecated | getDispatch ( ) | javascript | Famous/engine | core/Scene.js | https://github.com/Famous/engine/blob/master/core/Scene.js | MIT |
Scene.prototype.onReceive = function onReceive (event, payload) {
// TODO: In the future the dom element that the context is attached to
// should have a representation as a component. It would be render sized
// and the context would receive its size the same way that any render size
// component receives its size.
if (event === 'CONTEXT_RESIZE') {
if (payload.length < 2)
throw new Error(
'CONTEXT_RESIZE\'s payload needs to be at least a pair' +
' of pixel sizes'
);
this.setSizeMode('absolute', 'absolute', 'absolute');
this.setAbsoluteSize(payload[0],
payload[1],
payload[2] ? payload[2] : 0);
this._updater.message(Commands.WITH).message(this._selector).message(Commands.READY);
}
};
Scene.prototype.mount = function mount (path) {
if (this.isMounted())
throw new Error('Scene is already mounted at: ' + this.getLocation());
Dispatch.mount(path, this);
this._id = path;
this._mounted = true;
this._parent = this;
TransformSystem.registerTransformAtPath(path);
SizeSystem.registerSizeAtPath(path);
};
module.exports = Scene; | Receives an event. If the event is 'CONTEXT_RESIZE' it sets the size of the scene
graph to the payload, which must be an array of numbers of at least
length three representing the pixel size in 3 dimensions.
@param {String} event the name of the event being received
@param {*} payload the object being sent
@return {undefined} undefined | onReceive ( event , payload ) | javascript | Famous/engine | core/Scene.js | https://github.com/Famous/engine/blob/master/core/Scene.js | MIT |
Transform.prototype.reset = function reset () {
this.parent = null;
this.breakPoint = false;
this.calculatingWorldMatrix = false;
}; | resets the transform state such that it no longer has a parent
and is not a breakpoint.
@method
@return {undefined} undefined | reset ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.setParent = function setParent (parent) {
this.parent = parent;
}; | sets the parent of this transform.
@method
@param {Transform} parent The transform class that parents this class
@return {undefined} undefined | setParent ( parent ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.getParent = function getParent () {
return this.parent;
}; | returns the parent of this transform
@method
@return {Transform | null} the parent of this transform if one exists | getParent ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.setBreakPoint = function setBreakPoint () {
this.breakPoint = true;
this.calculatingWorldMatrix = true;
}; | Makes this transform a breakpoint. This will cause it to calculate
both a local (relative to the nearest ancestor breakpoint) and a world
matrix (relative to the scene).
@method
@return {undefined} undefined | setBreakPoint ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.setCalculateWorldMatrix = function setCalculateWorldMatrix () {
this.calculatingWorldMatrix = true;
}; | Set this node to calculate the world matrix.
@method
@return {undefined} undefined | setCalculateWorldMatrix ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.isBreakPoint = function isBreakPoint () {
return this.breakPoint;
}; | returns whether or not this transform is a breakpoint.
@method
@return {Boolean} true if this transform is a breakpoint | isBreakPoint ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.getLocalTransform = function getLocalTransform () {
return this.local;
}; | returns the local transform
@method
@return {Float32Array} local transform | getLocalTransform ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.getWorldTransform = function getWorldTransform () {
if (!this.isBreakPoint() && !this.calculatingWorldMatrix)
throw new Error('This transform is not calculating world transforms');
return this.global;
}; | returns the world transform. Requires that this transform is a breakpoint.
@method
@return {Float32Array} world transform. | getWorldTransform ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.calculate = function calculate (node) {
if (!this.parent || this.parent.isBreakPoint())
return fromNode(node, this);
else return fromNodeWithParent(node, this);
}; | Takes a node and calculates the proper transform from it.
@method
@param {Node} node the node to calculate the transform from
@return {undefined} undefined | calculate ( node ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
function _vecOptionalSet (vec, index, val) {
if (val != null && vec[index] !== val) {
vec[index] = val;
return true;
} else return false;
} | A private method to potentially set a value within an
array. Will set the value if a value was given
for the third argument and if that value is different
than the value that is currently in the array at the given index.
Returns true if a value was set and false if not.
@method
@param {Array} vec The array to set the value within
@param {Number} index The index at which to set the value
@param {Any} val The value to potentially set in the array
@return {Boolean} whether or not a value was set | _vecOptionalSet ( vec , index , val ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
function setVec (vec, x, y, z, w) {
var propagate = false;
propagate = _vecOptionalSet(vec, 0, x) || propagate;
propagate = _vecOptionalSet(vec, 1, y) || propagate;
propagate = _vecOptionalSet(vec, 2, z) || propagate;
if (w != null)
propagate = _vecOptionalSet(vec, 3, w) || propagate;
return propagate;
} | private method to set values within an array.
Returns whether or not the array has been changed.
@method
@param {Array} vec The vector to be operated upon
@param {Number | null | undefined} x The x value of the vector
@param {Number | null | undefined} y The y value of the vector
@param {Number | null | undefined} z The z value of the vector
@param {Number | null | undefined} w the w value of the vector
@return {Boolean} whether or not the array was changed | setVec ( vec , x , y , z , w ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.getPosition = function getPosition () {
return this.vectors.position;
}; | Gets the position component of the transform
@method
@return {Float32Array} the position component of the transform | getPosition ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.setPosition = function setPosition (x, y, z) {
this.vectors.positionChanged = setVec(this.vectors.position, x, y, z);
}; | Sets the position component of the transform.
@method
@param {Number} x The x dimension of the position
@param {Number} y The y dimension of the position
@param {Number} z The z dimension of the position
@return {undefined} undefined | setPosition ( x , y , z ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.getRotation = function getRotation () {
return this.vectors.rotation;
}; | Gets the rotation component of the transform. Will return a quaternion.
@method
@return {Float32Array} the quaternion representation of the transform's rotation | getRotation ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.setRotation = function setRotation (x, y, z, w) {
var quat = this.vectors.rotation;
var qx, qy, qz, qw;
if (w != null) {
qx = x;
qy = y;
qz = z;
qw = w;
this._lastEulerVals[0] = null;
this._lastEulerVals[1] = null;
this._lastEulerVals[2] = null;
this._lastEuler = false;
}
else {
if (x == null || y == null || z == null) {
if (this._lastEuler) {
x = x == null ? this._lastEulerVals[0] : x;
y = y == null ? this._lastEulerVals[1] : y;
z = z == null ? this._lastEulerVals[2] : z;
}
else {
var sp = -2 * (quat[1] * quat[2] - quat[3] * quat[0]);
if (Math.abs(sp) > 0.99999) {
y = y == null ? Math.PI * 0.5 * sp : y;
x = x == null ? Math.atan2(-quat[0] * quat[2] + quat[3] * quat[1], 0.5 - quat[1] * quat[1] - quat[2] * quat[2]) : x;
z = z == null ? 0 : z;
}
else {
y = y == null ? Math.asin(sp) : y;
x = x == null ? Math.atan2(quat[0] * quat[2] + quat[3] * quat[1], 0.5 - quat[0] * quat[0] - quat[1] * quat[1]) : x;
z = z == null ? Math.atan2(quat[0] * quat[1] + quat[3] * quat[2], 0.5 - quat[0] * quat[0] - quat[2] * quat[2]) : z;
}
}
}
var hx = x * 0.5;
var hy = y * 0.5;
var hz = z * 0.5;
var sx = Math.sin(hx);
var sy = Math.sin(hy);
var sz = Math.sin(hz);
var cx = Math.cos(hx);
var cy = Math.cos(hy);
var cz = Math.cos(hz);
var sysz = sy * sz;
var cysz = cy * sz;
var sycz = sy * cz;
var cycz = cy * cz;
qx = sx * cycz + cx * sysz;
qy = cx * sycz - sx * cysz;
qz = cx * cysz + sx * sycz;
qw = cx * cycz - sx * sysz;
this._lastEuler = true;
this._lastEulerVals[0] = x;
this._lastEulerVals[1] = y;
this._lastEulerVals[2] = z;
}
this.vectors.rotationChanged = setVec(quat, qx, qy, qz, qw);
}; | Sets the rotation component of the transform. Can take either Euler
angles or a quaternion.
@method
@param {Number} x The rotation about the x axis or the extent in the x dimension
@param {Number} y The rotation about the y axis or the extent in the y dimension
@param {Number} z The rotation about the z axis or the extent in the z dimension
@param {Number} w The rotation about the proceeding vector
@return {undefined} undefined | setRotation ( x , y , z , w ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.getScale = function getScale () {
return this.vectors.scale;
}; | Gets the scale component of the transform
@method
@return {Float32Array} the scale component of the transform | getScale ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.setScale = function setScale (x, y, z) {
this.vectors.scaleChanged = setVec(this.vectors.scale, x, y, z);
}; | Sets the scale component of the transform.
@method
@param {Number | null | undefined} x The x dimension of the scale
@param {Number | null | undefined} y The y dimension of the scale
@param {Number | null | undefined} z The z dimension of the scale
@return {undefined} undefined | setScale ( x , y , z ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.getAlign = function getAlign () {
return this.offsets.align;
}; | Gets the align value of the transform
@method
@return {Float32Array} the align value of the transform | getAlign ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.getMountPoint = function getMountPoint () {
return this.offsets.mountPoint;
}; | Gets the mount point value of the transform.
@method
@return {Float32Array} the mount point of the transform | getMountPoint ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.getOrigin = function getOrigin () {
return this.offsets.origin;
}; | Gets the origin of the transform.
@method
@return {Float32Array} the origin | getOrigin ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.calculateWorldMatrix = function calculateWorldMatrix () {
var nearestBreakPoint = this.parent;
while (nearestBreakPoint && !nearestBreakPoint.isBreakPoint())
nearestBreakPoint = nearestBreakPoint.parent;
if (nearestBreakPoint) return multiply(this.global, nearestBreakPoint.getWorldTransform(), this.local);
else {
for (var i = 0; i < 16 ; i++) this.global[i] = this.local[i];
return false;
}
}; | Calculates the world for this particular transform.
@method
@return {undefined} undefined | calculateWorldMatrix ( ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
function fromNode (node, transform) {
var target = transform.getLocalTransform();
var mySize = node.getSize();
var vectors = transform.vectors;
var offsets = transform.offsets;
var parentSize = node.getParent().getSize();
var changed = 0;
var t00 = target[0];
var t01 = target[1];
var t02 = target[2];
var t10 = target[4];
var t11 = target[5];
var t12 = target[6];
var t20 = target[8];
var t21 = target[9];
var t22 = target[10];
var t30 = target[12];
var t31 = target[13];
var t32 = target[14];
var posX = vectors.position[0];
var posY = vectors.position[1];
var posZ = vectors.position[2];
var rotX = vectors.rotation[0];
var rotY = vectors.rotation[1];
var rotZ = vectors.rotation[2];
var rotW = vectors.rotation[3];
var scaleX = vectors.scale[0];
var scaleY = vectors.scale[1];
var scaleZ = vectors.scale[2];
var alignX = offsets.align[0] * parentSize[0];
var alignY = offsets.align[1] * parentSize[1];
var alignZ = offsets.align[2] * parentSize[2];
var mountPointX = offsets.mountPoint[0] * mySize[0];
var mountPointY = offsets.mountPoint[1] * mySize[1];
var mountPointZ = offsets.mountPoint[2] * mySize[2];
var originX = offsets.origin[0] * mySize[0];
var originY = offsets.origin[1] * mySize[1];
var originZ = offsets.origin[2] * mySize[2];
var wx = rotW * rotX;
var wy = rotW * rotY;
var wz = rotW * rotZ;
var xx = rotX * rotX;
var yy = rotY * rotY;
var zz = rotZ * rotZ;
var xy = rotX * rotY;
var xz = rotX * rotZ;
var yz = rotY * rotZ;
target[0] = (1 - 2 * (yy + zz)) * scaleX;
target[1] = (2 * (xy + wz)) * scaleX;
target[2] = (2 * (xz - wy)) * scaleX;
target[3] = 0;
target[4] = (2 * (xy - wz)) * scaleY;
target[5] = (1 - 2 * (xx + zz)) * scaleY;
target[6] = (2 * (yz + wx)) * scaleY;
target[7] = 0;
target[8] = (2 * (xz + wy)) * scaleZ;
target[9] = (2 * (yz - wx)) * scaleZ;
target[10] = (1 - 2 * (xx + yy)) * scaleZ;
target[11] = 0;
target[12] = alignX + posX - mountPointX + originX -
(target[0] * originX + target[4] * originY + target[8] * originZ);
target[13] = alignY + posY - mountPointY + originY -
(target[1] * originX + target[5] * originY + target[9] * originZ);
target[14] = alignZ + posZ - mountPointZ + originZ -
(target[2] * originX + target[6] * originY + target[10] * originZ);
target[15] = 1;
if (transform.calculatingWorldMatrix && transform.calculateWorldMatrix())
changed |= Transform.WORLD_CHANGED;
if (t00 !== target[0] ||
t01 !== target[1] ||
t02 !== target[2] ||
t10 !== target[4] ||
t11 !== target[5] ||
t12 !== target[6] ||
t20 !== target[8] ||
t21 !== target[9] ||
t22 !== target[10] ||
t30 !== target[12] ||
t31 !== target[13] ||
t32 !== target[14]) changed |= Transform.LOCAL_CHANGED;
return changed;
} | Private function. Creates a transformation matrix from a Node's spec.
@param {Node} node the node to create a transform for
@param {Transform} transform transform to apply
@return {Boolean} whether or not the target array was changed | fromNode ( node , transform ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
function fromNodeWithParent (node, transform) {
var target = transform.getLocalTransform();
var parentMatrix = transform.parent.getLocalTransform();
var mySize = node.getSize();
var vectors = transform.vectors;
var offsets = transform.offsets;
var parentSize = node.getParent().getSize();
var changed = false;
// local cache of everything
var t00 = target[0];
var t01 = target[1];
var t02 = target[2];
var t10 = target[4];
var t11 = target[5];
var t12 = target[6];
var t20 = target[8];
var t21 = target[9];
var t22 = target[10];
var t30 = target[12];
var t31 = target[13];
var t32 = target[14];
var p00 = parentMatrix[0];
var p01 = parentMatrix[1];
var p02 = parentMatrix[2];
var p10 = parentMatrix[4];
var p11 = parentMatrix[5];
var p12 = parentMatrix[6];
var p20 = parentMatrix[8];
var p21 = parentMatrix[9];
var p22 = parentMatrix[10];
var p30 = parentMatrix[12];
var p31 = parentMatrix[13];
var p32 = parentMatrix[14];
var posX = vectors.position[0];
var posY = vectors.position[1];
var posZ = vectors.position[2];
var rotX = vectors.rotation[0];
var rotY = vectors.rotation[1];
var rotZ = vectors.rotation[2];
var rotW = vectors.rotation[3];
var scaleX = vectors.scale[0];
var scaleY = vectors.scale[1];
var scaleZ = vectors.scale[2];
var alignX = offsets.align[0] * parentSize[0];
var alignY = offsets.align[1] * parentSize[1];
var alignZ = offsets.align[2] * parentSize[2];
var mountPointX = offsets.mountPoint[0] * mySize[0];
var mountPointY = offsets.mountPoint[1] * mySize[1];
var mountPointZ = offsets.mountPoint[2] * mySize[2];
var originX = offsets.origin[0] * mySize[0];
var originY = offsets.origin[1] * mySize[1];
var originZ = offsets.origin[2] * mySize[2];
var wx = rotW * rotX;
var wy = rotW * rotY;
var wz = rotW * rotZ;
var xx = rotX * rotX;
var yy = rotY * rotY;
var zz = rotZ * rotZ;
var xy = rotX * rotY;
var xz = rotX * rotZ;
var yz = rotY * rotZ;
var rs0 = (1 - 2 * (yy + zz)) * scaleX;
var rs1 = (2 * (xy + wz)) * scaleX;
var rs2 = (2 * (xz - wy)) * scaleX;
var rs3 = (2 * (xy - wz)) * scaleY;
var rs4 = (1 - 2 * (xx + zz)) * scaleY;
var rs5 = (2 * (yz + wx)) * scaleY;
var rs6 = (2 * (xz + wy)) * scaleZ;
var rs7 = (2 * (yz - wx)) * scaleZ;
var rs8 = (1 - 2 * (xx + yy)) * scaleZ;
var tx = alignX + posX - mountPointX + originX - (rs0 * originX + rs3 * originY + rs6 * originZ);
var ty = alignY + posY - mountPointY + originY - (rs1 * originX + rs4 * originY + rs7 * originZ);
var tz = alignZ + posZ - mountPointZ + originZ - (rs2 * originX + rs5 * originY + rs8 * originZ);
target[0] = p00 * rs0 + p10 * rs1 + p20 * rs2;
target[1] = p01 * rs0 + p11 * rs1 + p21 * rs2;
target[2] = p02 * rs0 + p12 * rs1 + p22 * rs2;
target[3] = 0;
target[4] = p00 * rs3 + p10 * rs4 + p20 * rs5;
target[5] = p01 * rs3 + p11 * rs4 + p21 * rs5;
target[6] = p02 * rs3 + p12 * rs4 + p22 * rs5;
target[7] = 0;
target[8] = p00 * rs6 + p10 * rs7 + p20 * rs8;
target[9] = p01 * rs6 + p11 * rs7 + p21 * rs8;
target[10] = p02 * rs6 + p12 * rs7 + p22 * rs8;
target[11] = 0;
target[12] = p00 * tx + p10 * ty + p20 * tz + p30;
target[13] = p01 * tx + p11 * ty + p21 * tz + p31;
target[14] = p02 * tx + p12 * ty + p22 * tz + p32;
target[15] = 1;
if (transform.calculatingWorldMatrix && transform.calculateWorldMatrix())
changed |= Transform.WORLD_CHANGED;
if (t00 !== target[0] ||
t01 !== target[1] ||
t02 !== target[2] ||
t10 !== target[4] ||
t11 !== target[5] ||
t12 !== target[6] ||
t20 !== target[8] ||
t21 !== target[9] ||
t22 !== target[10] ||
t30 !== target[12] ||
t31 !== target[13] ||
t32 !== target[14]) changed |= Transform.LOCAL_CHANGED;
return changed;
} | Private function. Uses the parent transform, the node's spec, the node's size, and the parent's size
to calculate a final transform for the node. Returns true if the transform has changed.
@private
@param {Node} node the node to create a transform for
@param {Transform} transform transform to apply
@return {Boolean} whether or not the transform changed | fromNodeWithParent ( node , transform ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
function multiply (out, a, b) {
var a00 = a[0], a01 = a[1], a02 = a[2],
a10 = a[4], a11 = a[5], a12 = a[6],
a20 = a[8], a21 = a[9], a22 = a[10],
a30 = a[12], a31 = a[13], a32 = a[14];
var changed = false;
var res;
// Cache only the current line of the second matrix
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
res = b0*a00 + b1*a10 + b2*a20 + b3*a30;
changed = changed ? changed : out[0] === res;
out[0] = res;
res = b0*a01 + b1*a11 + b2*a21 + b3*a31;
changed = changed ? changed : out[1] === res;
out[1] = res;
res = b0*a02 + b1*a12 + b2*a22 + b3*a32;
changed = changed ? changed : out[2] === res;
out[2] = res;
out[3] = 0;
b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];
res = b0*a00 + b1*a10 + b2*a20 + b3*a30;
changed = changed ? changed : out[4] === res;
out[4] = res;
res = b0*a01 + b1*a11 + b2*a21 + b3*a31;
changed = changed ? changed : out[5] === res;
out[5] = res;
res = b0*a02 + b1*a12 + b2*a22 + b3*a32;
changed = changed ? changed : out[6] === res;
out[6] = res;
out[7] = 0;
b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];
res = b0*a00 + b1*a10 + b2*a20 + b3*a30;
changed = changed ? changed : out[8] === res;
out[8] = res;
res = b0*a01 + b1*a11 + b2*a21 + b3*a31;
changed = changed ? changed : out[9] === res;
out[9] = res;
res = b0*a02 + b1*a12 + b2*a22 + b3*a32;
changed = changed ? changed : out[10] === res;
out[10] = res;
out[11] = 0;
b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];
res = b0*a00 + b1*a10 + b2*a20 + b3*a30;
changed = changed ? changed : out[12] === res;
out[12] = res;
res = b0*a01 + b1*a11 + b2*a21 + b3*a31;
changed = changed ? changed : out[13] === res;
out[13] = res;
res = b0*a02 + b1*a12 + b2*a22 + b3*a32;
changed = changed ? changed : out[14] === res;
out[14] = res;
out[15] = 1;
return changed;
} | private method to multiply two transforms.
@method
@param {Array} out The array to write the result to
@param {Array} a the left hand transform
@param {Array} b the right hand transform
@return {undefined} undefined | multiply ( out , a , b ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
Transform.prototype.setOrigin = function setOrigin (x, y, z) {
this.offsets.originChanged = setVec(this.offsets.origin, x, y, z != null ? z - 0.5 : z);
};
/**
* Calculates the world for this particular transform.
*
* @method
*
* @return {undefined} undefined
*/
Transform.prototype.calculateWorldMatrix = function calculateWorldMatrix () {
var nearestBreakPoint = this.parent;
while (nearestBreakPoint && !nearestBreakPoint.isBreakPoint())
nearestBreakPoint = nearestBreakPoint.parent;
if (nearestBreakPoint) return multiply(this.global, nearestBreakPoint.getWorldTransform(), this.local);
else {
for (var i = 0; i < 16 ; i++) this.global[i] = this.local[i];
return false;
}
};
/**
* Private function. Creates a transformation matrix from a Node's spec.
*
* @param {Node} node the node to create a transform for
* @param {Transform} transform transform to apply
*
* @return {Boolean} whether or not the target array was changed
*/
function fromNode (node, transform) {
var target = transform.getLocalTransform();
var mySize = node.getSize();
var vectors = transform.vectors;
var offsets = transform.offsets;
var parentSize = node.getParent().getSize();
var changed = 0;
var t00 = target[0];
var t01 = target[1];
var t02 = target[2];
var t10 = target[4];
var t11 = target[5];
var t12 = target[6];
var t20 = target[8];
var t21 = target[9];
var t22 = target[10];
var t30 = target[12];
var t31 = target[13];
var t32 = target[14];
var posX = vectors.position[0];
var posY = vectors.position[1];
var posZ = vectors.position[2];
var rotX = vectors.rotation[0];
var rotY = vectors.rotation[1];
var rotZ = vectors.rotation[2];
var rotW = vectors.rotation[3];
var scaleX = vectors.scale[0];
var scaleY = vectors.scale[1];
var scaleZ = vectors.scale[2];
var alignX = offsets.align[0] * parentSize[0];
var alignY = offsets.align[1] * parentSize[1];
var alignZ = offsets.align[2] * parentSize[2];
var mountPointX = offsets.mountPoint[0] * mySize[0];
var mountPointY = offsets.mountPoint[1] * mySize[1];
var mountPointZ = offsets.mountPoint[2] * mySize[2];
var originX = offsets.origin[0] * mySize[0];
var originY = offsets.origin[1] * mySize[1];
var originZ = offsets.origin[2] * mySize[2];
var wx = rotW * rotX;
var wy = rotW * rotY;
var wz = rotW * rotZ;
var xx = rotX * rotX;
var yy = rotY * rotY;
var zz = rotZ * rotZ;
var xy = rotX * rotY;
var xz = rotX * rotZ;
var yz = rotY * rotZ;
target[0] = (1 - 2 * (yy + zz)) * scaleX;
target[1] = (2 * (xy + wz)) * scaleX;
target[2] = (2 * (xz - wy)) * scaleX;
target[3] = 0;
target[4] = (2 * (xy - wz)) * scaleY;
target[5] = (1 - 2 * (xx + zz)) * scaleY;
target[6] = (2 * (yz + wx)) * scaleY;
target[7] = 0;
target[8] = (2 * (xz + wy)) * scaleZ;
target[9] = (2 * (yz - wx)) * scaleZ;
target[10] = (1 - 2 * (xx + yy)) * scaleZ;
target[11] = 0;
target[12] = alignX + posX - mountPointX + originX -
(target[0] * originX + target[4] * originY + target[8] * originZ);
target[13] = alignY + posY - mountPointY + originY -
(target[1] * originX + target[5] * originY + target[9] * originZ);
target[14] = alignZ + posZ - mountPointZ + originZ -
(target[2] * originX + target[6] * originY + target[10] * originZ);
target[15] = 1;
if (transform.calculatingWorldMatrix && transform.calculateWorldMatrix())
changed |= Transform.WORLD_CHANGED;
if (t00 !== target[0] ||
t01 !== target[1] ||
t02 !== target[2] ||
t10 !== target[4] ||
t11 !== target[5] ||
t12 !== target[6] ||
t20 !== target[8] ||
t21 !== target[9] ||
t22 !== target[10] ||
t30 !== target[12] ||
t31 !== target[13] ||
t32 !== target[14]) changed |= Transform.LOCAL_CHANGED;
return changed;
}
/**
* Private function. Uses the parent transform, the node's spec, the node's size, and the parent's size
* to calculate a final transform for the node. Returns true if the transform has changed.
*
* @private
*
* @param {Node} node the node to create a transform for
* @param {Transform} transform transform to apply
*
* @return {Boolean} whether or not the transform changed
*/
function fromNodeWithParent (node, transform) {
var target = transform.getLocalTransform();
var parentMatrix = transform.parent.getLocalTransform();
var mySize = node.getSize();
var vectors = transform.vectors;
var offsets = transform.offsets;
var parentSize = node.getParent().getSize();
var changed = false;
// local cache of everything
var t00 = target[0];
var t01 = target[1];
var t02 = target[2];
var t10 = target[4];
var t11 = target[5];
var t12 = target[6];
var t20 = target[8];
var t21 = target[9];
var t22 = target[10];
var t30 = target[12];
var t31 = target[13];
var t32 = target[14];
var p00 = parentMatrix[0];
var p01 = parentMatrix[1];
var p02 = parentMatrix[2];
var p10 = parentMatrix[4];
var p11 = parentMatrix[5];
var p12 = parentMatrix[6];
var p20 = parentMatrix[8];
var p21 = parentMatrix[9];
var p22 = parentMatrix[10];
var p30 = parentMatrix[12];
var p31 = parentMatrix[13];
var p32 = parentMatrix[14];
var posX = vectors.position[0];
var posY = vectors.position[1];
var posZ = vectors.position[2];
var rotX = vectors.rotation[0];
var rotY = vectors.rotation[1];
var rotZ = vectors.rotation[2];
var rotW = vectors.rotation[3];
var scaleX = vectors.scale[0];
var scaleY = vectors.scale[1];
var scaleZ = vectors.scale[2];
var alignX = offsets.align[0] * parentSize[0];
var alignY = offsets.align[1] * parentSize[1];
var alignZ = offsets.align[2] * parentSize[2];
var mountPointX = offsets.mountPoint[0] * mySize[0];
var mountPointY = offsets.mountPoint[1] * mySize[1];
var mountPointZ = offsets.mountPoint[2] * mySize[2];
var originX = offsets.origin[0] * mySize[0];
var originY = offsets.origin[1] * mySize[1];
var originZ = offsets.origin[2] * mySize[2];
var wx = rotW * rotX;
var wy = rotW * rotY;
var wz = rotW * rotZ;
var xx = rotX * rotX;
var yy = rotY * rotY;
var zz = rotZ * rotZ;
var xy = rotX * rotY;
var xz = rotX * rotZ;
var yz = rotY * rotZ;
var rs0 = (1 - 2 * (yy + zz)) * scaleX;
var rs1 = (2 * (xy + wz)) * scaleX;
var rs2 = (2 * (xz - wy)) * scaleX;
var rs3 = (2 * (xy - wz)) * scaleY;
var rs4 = (1 - 2 * (xx + zz)) * scaleY;
var rs5 = (2 * (yz + wx)) * scaleY;
var rs6 = (2 * (xz + wy)) * scaleZ;
var rs7 = (2 * (yz - wx)) * scaleZ;
var rs8 = (1 - 2 * (xx + yy)) * scaleZ;
var tx = alignX + posX - mountPointX + originX - (rs0 * originX + rs3 * originY + rs6 * originZ);
var ty = alignY + posY - mountPointY + originY - (rs1 * originX + rs4 * originY + rs7 * originZ);
var tz = alignZ + posZ - mountPointZ + originZ - (rs2 * originX + rs5 * originY + rs8 * originZ);
target[0] = p00 * rs0 + p10 * rs1 + p20 * rs2;
target[1] = p01 * rs0 + p11 * rs1 + p21 * rs2;
target[2] = p02 * rs0 + p12 * rs1 + p22 * rs2;
target[3] = 0;
target[4] = p00 * rs3 + p10 * rs4 + p20 * rs5;
target[5] = p01 * rs3 + p11 * rs4 + p21 * rs5;
target[6] = p02 * rs3 + p12 * rs4 + p22 * rs5;
target[7] = 0;
target[8] = p00 * rs6 + p10 * rs7 + p20 * rs8;
target[9] = p01 * rs6 + p11 * rs7 + p21 * rs8;
target[10] = p02 * rs6 + p12 * rs7 + p22 * rs8;
target[11] = 0;
target[12] = p00 * tx + p10 * ty + p20 * tz + p30;
target[13] = p01 * tx + p11 * ty + p21 * tz + p31;
target[14] = p02 * tx + p12 * ty + p22 * tz + p32;
target[15] = 1;
if (transform.calculatingWorldMatrix && transform.calculateWorldMatrix())
changed |= Transform.WORLD_CHANGED;
if (t00 !== target[0] ||
t01 !== target[1] ||
t02 !== target[2] ||
t10 !== target[4] ||
t11 !== target[5] ||
t12 !== target[6] ||
t20 !== target[8] ||
t21 !== target[9] ||
t22 !== target[10] ||
t30 !== target[12] ||
t31 !== target[13] ||
t32 !== target[14]) changed |= Transform.LOCAL_CHANGED;
return changed;
}
/**
* private method to multiply two transforms.
*
* @method
*
* @param {Array} out The array to write the result to
* @param {Array} a the left hand transform
* @param {Array} b the right hand transform
*
* @return {undefined} undefined
*/
function multiply (out, a, b) {
var a00 = a[0], a01 = a[1], a02 = a[2],
a10 = a[4], a11 = a[5], a12 = a[6],
a20 = a[8], a21 = a[9], a22 = a[10],
a30 = a[12], a31 = a[13], a32 = a[14];
var changed = false;
var res;
// Cache only the current line of the second matrix
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
res = b0*a00 + b1*a10 + b2*a20 + b3*a30;
changed = changed ? changed : out[0] === res;
out[0] = res;
res = b0*a01 + b1*a11 + b2*a21 + b3*a31;
changed = changed ? changed : out[1] === res;
out[1] = res;
res = b0*a02 + b1*a12 + b2*a22 + b3*a32;
changed = changed ? changed : out[2] === res;
out[2] = res;
out[3] = 0;
b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];
res = b0*a00 + b1*a10 + b2*a20 + b3*a30;
changed = changed ? changed : out[4] === res;
out[4] = res;
res = b0*a01 + b1*a11 + b2*a21 + b3*a31;
changed = changed ? changed : out[5] === res;
out[5] = res;
res = b0*a02 + b1*a12 + b2*a22 + b3*a32;
changed = changed ? changed : out[6] === res;
out[6] = res;
out[7] = 0;
b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];
res = b0*a00 + b1*a10 + b2*a20 + b3*a30;
changed = changed ? changed : out[8] === res;
out[8] = res;
res = b0*a01 + b1*a11 + b2*a21 + b3*a31;
changed = changed ? changed : out[9] === res;
out[9] = res;
res = b0*a02 + b1*a12 + b2*a22 + b3*a32;
changed = changed ? changed : out[10] === res;
out[10] = res;
out[11] = 0;
b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];
res = b0*a00 + b1*a10 + b2*a20 + b3*a30;
changed = changed ? changed : out[12] === res;
out[12] = res;
res = b0*a01 + b1*a11 + b2*a21 + b3*a31;
changed = changed ? changed : out[13] === res;
out[13] = res;
res = b0*a02 + b1*a12 + b2*a22 + b3*a32;
changed = changed ? changed : out[14] === res;
out[14] = res;
out[15] = 1;
return changed;
}
module.exports = Transform; | Sets the origin of the transform.
@method
@param {Number | null | undefined} x the x dimension of the origin
@param {Number | null | undefined} y the y dimension of the origin
@param {Number | null | undefined} z the z dimension of the origin
@return {undefined} undefined | setOrigin ( x , y , z ) | javascript | Famous/engine | core/Transform.js | https://github.com/Famous/engine/blob/master/core/Transform.js | MIT |
function Size (parent) {
this.finalSize = new Float32Array(3);
this.sizeChanged = false;
this.sizeMode = new Uint8Array(3);
this.sizeModeChanged = false;
this.absoluteSize = new Float32Array(3);
this.absoluteSizeChanged = false;
this.proportionalSize = new Float32Array(ONES);
this.proportionalSizeChanged = false;
this.differentialSize = new Float32Array(3);
this.differentialSizeChanged = false;
this.renderSize = new Float32Array(3);
this.renderSizeChanged = false;
this.parent = parent != null ? parent : null;
} | The Size class is responsible for processing Size from a node
@constructor Size
@param {Size} parent the parent size | Size ( parent ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
function setVec (vec, x, y, z) {
var propagate = false;
propagate = _vecOptionalSet(vec, 0, x) || propagate;
propagate = _vecOptionalSet(vec, 1, y) || propagate;
propagate = _vecOptionalSet(vec, 2, z) || propagate;
return propagate;
} | Private method which sets three values within an array of three
using _vecOptionalSet. Returns whether anything has changed.
@method
@param {Array} vec The array to set the values of
@param {Any} x The first value to set within the array
@param {Any} y The second value to set within the array
@param {Any} z The third value to set within the array
@return {Boolean} whether anything has changed | setVec ( vec , x , y , z ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
function resolveSizeMode (val) {
if (val.constructor === String) {
switch (val.toLowerCase()) {
case 'relative':
case 'default': return Size.RELATIVE;
case 'absolute': return Size.ABSOLUTE;
case 'render': return Size.RENDER;
default: throw new Error('unknown size mode: ' + val);
}
}
else if (val < 0 || val > Size.RENDER) throw new Error('unknown size mode: ' + val);
return val;
} | Private method to allow for polymorphism in the size mode such that strings
or the numbers from the enumeration can be used.
@method
@param {String|Number} val The Size mode to resolve.
@return {Number} the resolved size mode from the enumeration. | resolveSizeMode ( val ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
Size.prototype.setParent = function setParent (parent) {
this.parent = parent;
return this;
}; | Sets the parent of this size.
@method
@param {Size} parent The parent size component
@return {Size} this | setParent ( parent ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
Size.prototype.getParent = function getParent () {
return this.parent;
}; | Gets the parent of this size.
@method
@returns {Size|undefined} the parent if one exists | getParent ( ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
Size.prototype.setSizeMode = function setSizeMode (x, y, z) {
if (x != null) x = resolveSizeMode(x);
if (y != null) y = resolveSizeMode(y);
if (z != null) z = resolveSizeMode(z);
this.sizeModeChanged = setVec(this.sizeMode, x, y, z);
return this;
}; | Gets the size mode of this size representation
@method
@param {Number} x the size mode to use for the width
@param {Number} y the size mode to use for the height
@param {Number} z the size mode to use for the depth
@return {array} array of size modes | setSizeMode ( x , y , z ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
Size.prototype.getSizeMode = function getSizeMode () {
return this.sizeMode;
}; | Returns the size mode of this component.
@method
@return {Array} the current size mode of the this. | getSizeMode ( ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
Size.prototype.setAbsolute = function setAbsolute (x, y, z) {
this.absoluteSizeChanged = setVec(this.absoluteSize, x, y, z);
return this;
}; | Sets the absolute size of this size representation.
@method
@param {Number} x The x dimension of the absolute size
@param {Number} y The y dimension of the absolute size
@param {Number} z The z dimension of the absolute size
@return {Size} this | setAbsolute ( x , y , z ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
Size.prototype.getAbsolute = function getAbsolute () {
return this.absoluteSize;
}; | Gets the absolute size of this size representation
@method
@return {array} array of absolute size | getAbsolute ( ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
Size.prototype.setProportional = function setProportional (x, y, z) {
this.proportionalSizeChanged = setVec(this.proportionalSize, x, y, z);
return this;
}; | Sets the proportional size of this size representation.
@method
@param {Number} x The x dimension of the proportional size
@param {Number} y The y dimension of the proportional size
@param {Number} z The z dimension of the proportional size
@return {Size} this | setProportional ( x , y , z ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
Size.prototype.getProportional = function getProportional () {
return this.proportionalSize;
}; | Gets the propotional size of this size representation
@method
@return {array} array of proportional size | getProportional ( ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
Size.prototype.setDifferential = function setDifferential (x, y, z) {
this.differentialSizeChanged = setVec(this.differentialSize, x, y, z);
return this;
}; | Sets the differential size of this size representation.
@method
@param {Number} x The x dimension of the differential size
@param {Number} y The y dimension of the differential size
@param {Number} z The z dimension of the differential size
@return {Size} this | setDifferential ( x , y , z ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
Size.prototype.getDifferential = function getDifferential () {
return this.differentialSize;
}; | Gets the differential size of this size representation
@method
@return {array} array of differential size | getDifferential ( ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
Size.prototype.get = function get () {
return this.finalSize;
}; | Sets the size of this size representation.
@method
@param {Number} x The x dimension of the size
@param {Number} y The y dimension of the size
@param {Number} z The z dimension of the size
@return {Size} this | get ( ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
Size.prototype.fromComponents = function fromComponents (components) {
var mode = this.sizeMode;
var target = this.finalSize;
var parentSize = this.parent ? this.parent.get() : ZEROS;
var prev;
var changed = false;
var len = components.length;
var j;
for (var i = 0 ; i < 3 ; i++) {
prev = target[i];
switch (mode[i]) {
case Size.RELATIVE:
target[i] = parentSize[i] * this.proportionalSize[i] + this.differentialSize[i];
break;
case Size.ABSOLUTE:
target[i] = this.absoluteSize[i];
break;
case Size.RENDER:
var candidate;
var component;
for (j = 0; j < len ; j++) {
component = components[j];
if (component && component.getRenderSize) {
candidate = component.getRenderSize()[i];
target[i] = target[i] < candidate || target[i] === 0 ? candidate : target[i];
}
}
break;
}
changed = changed || prev !== target[i];
}
this.sizeChanged = changed;
return changed;
}; | fromSpecWithParent takes the parent node's size, the target node's spec,
and a target array to write to. Using the node's size mode it calculates
a final size for the node from the node's spec. Returns whether or not
the final size has changed from its last value.
@method
@param {Array} components the node's components
@return {Boolean} true if the size of the node has changed. | fromComponents ( components ) | javascript | Famous/engine | core/Size.js | https://github.com/Famous/engine/blob/master/core/Size.js | MIT |
function SizeSystem () {
this.pathStore = new PathStore();
} | The size system is used to calculate size throughout the scene graph.
It holds size components and operates upon them.
@constructor | SizeSystem ( ) | javascript | Famous/engine | core/SizeSystem.js | https://github.com/Famous/engine/blob/master/core/SizeSystem.js | MIT |
SizeSystem.prototype.registerSizeAtPath = function registerSizeAtPath (path, size) {
if (!PathUtils.depth(path)) return this.pathStore.insert(path, size ? size : new Size());
var parent = this.pathStore.get(PathUtils.parent(path));
if (!parent) throw new Error(
'No parent size registered at expected path: ' + PathUtils.parent(path)
);
if (size) size.setParent(parent);
this.pathStore.insert(path, size ? size : new Size(parent));
}; | Registers a size component to a give path. A size component can be passed as the second argument
or a default one will be created. Throws if no size component has been added at the parent path.
@method
@param {String} path The path at which to register the size component
@param {Size | undefined} size The size component to be registered or undefined.
@return {undefined} undefined | registerSizeAtPath ( path , size ) | javascript | Famous/engine | core/SizeSystem.js | https://github.com/Famous/engine/blob/master/core/SizeSystem.js | MIT |
SizeSystem.prototype.deregisterSizeAtPath = function deregisterSizeAtPath(path) {
this.pathStore.remove(path);
}; | Removes the size component from the given path. Will throw if no component is at that
path
@method
@param {String} path The path at which to remove the size.
@return {undefined} undefined | deregisterSizeAtPath ( path ) | javascript | Famous/engine | core/SizeSystem.js | https://github.com/Famous/engine/blob/master/core/SizeSystem.js | MIT |
SizeSystem.prototype.get = function get (path) {
return this.pathStore.get(path);
}; | Returns the size component stored at a given path. Returns undefined if no
size component is registered to that path.
@method
@param {String} path The path at which to get the size component.
@return {undefined} undefined | get ( path ) | javascript | Famous/engine | core/SizeSystem.js | https://github.com/Famous/engine/blob/master/core/SizeSystem.js | MIT |
SizeSystem.prototype.update = function update () {
var sizes = this.pathStore.getItems();
var paths = this.pathStore.getPaths();
var node;
var size;
var i;
var len;
var components;
for (i = 0, len = sizes.length ; i < len ; i++) {
node = Dispatch.getNode(paths[i]);
components = node.getComponents();
if (!node) continue;
size = sizes[i];
if (size.sizeModeChanged) sizeModeChanged(node, components, size);
if (size.absoluteSizeChanged) absoluteSizeChanged(node, components, size);
if (size.proportionalSizeChanged) proportionalSizeChanged(node, components, size);
if (size.differentialSizeChanged) differentialSizeChanged(node, components, size);
if (size.renderSizeChanged) renderSizeChanged(node, components, size);
if (size.fromComponents(components)) sizeChanged(node, components, size);
}
}; | Updates the sizes in the scene graph. Called internally by the famous engine.
@method
@return {undefined} undefined | update ( ) | javascript | Famous/engine | core/SizeSystem.js | https://github.com/Famous/engine/blob/master/core/SizeSystem.js | MIT |
function sizeModeChanged (node, components, size) {
var sizeMode = size.getSizeMode();
var x = sizeMode[0];
var y = sizeMode[1];
var z = sizeMode[2];
if (node.onSizeModeChange) node.onSizeModeChange(x, y, z);
for (var i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onSizeModeChange)
components[i].onSizeModeChange(x, y, z);
size.sizeModeChanged = false;
} | Private method to alert the node and components that size mode changed.
@method
@private
@param {Node} node Node to potentially call sizeModeChanged on
@param {Array} components a list of the nodes' components
@param {Size} size the size class for the Node
@return {undefined} undefined | sizeModeChanged ( node , components , size ) | javascript | Famous/engine | core/SizeSystem.js | https://github.com/Famous/engine/blob/master/core/SizeSystem.js | MIT |
function absoluteSizeChanged (node, components, size) {
var absoluteSize = size.getAbsolute();
var x = absoluteSize[0];
var y = absoluteSize[1];
var z = absoluteSize[2];
if (node.onAbsoluteSizeChange) node.onAbsoluteSizeChange(x, y, z);
for (var i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onAbsoluteSizeChange)
components[i].onAbsoluteSizeChange(x, y, z);
size.absoluteSizeChanged = false;
} | Private method to alert the node and components that absoluteSize changed.
@method
@private
@param {Node} node Node to potentially call onAbsoluteSizeChange on
@param {Array} components a list of the nodes' components
@param {Size} size the size class for the Node
@return {undefined} undefined | absoluteSizeChanged ( node , components , size ) | javascript | Famous/engine | core/SizeSystem.js | https://github.com/Famous/engine/blob/master/core/SizeSystem.js | MIT |
function proportionalSizeChanged (node, components, size) {
var proportionalSize = size.getProportional();
var x = proportionalSize[0];
var y = proportionalSize[1];
var z = proportionalSize[2];
if (node.onProportionalSizeChange) node.onProportionalSizeChange(x, y, z);
for (var i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onProportionalSizeChange)
components[i].onProportionalSizeChange(x, y, z);
size.proportionalSizeChanged = false;
} | Private method to alert the node and components that the proportional size changed.
@method
@private
@param {Node} node Node to potentially call onProportionalSizeChange on
@param {Array} components a list of the nodes' components
@param {Size} size the size class for the Node
@return {undefined} undefined | proportionalSizeChanged ( node , components , size ) | javascript | Famous/engine | core/SizeSystem.js | https://github.com/Famous/engine/blob/master/core/SizeSystem.js | MIT |
function differentialSizeChanged (node, components, size) {
var differentialSize = size.getDifferential();
var x = differentialSize[0];
var y = differentialSize[1];
var z = differentialSize[2];
if (node.onDifferentialSizeChange) node.onDifferentialSizeChange(x, y, z);
for (var i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onDifferentialSizeChange)
components[i].onDifferentialSizeChange(x, y, z);
size.differentialSizeChanged = false;
} | Private method to alert the node and components that differential size changed.
@method
@private
@param {Node} node Node to potentially call onDifferentialSize on
@param {Array} components a list of the nodes' components
@param {Size} size the size class for the Node
@return {undefined} undefined | differentialSizeChanged ( node , components , size ) | javascript | Famous/engine | core/SizeSystem.js | https://github.com/Famous/engine/blob/master/core/SizeSystem.js | MIT |
function renderSizeChanged (node, components, size) {
var renderSize = size.getRenderSize();
var x = renderSize[0];
var y = renderSize[1];
var z = renderSize[2];
if (node.onRenderSizeChange) node.onRenderSizeChange(x, y, z);
for (var i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onRenderSizeChange)
components[i].onRenderSizeChange(x, y, z);
size.renderSizeChanged = false;
} | Private method to alert the node and components that render size changed.
@method
@private
@param {Node} node Node to potentially call onRenderSizeChange on
@param {Array} components a list of the nodes' components
@param {Size} size the size class for the Node
@return {undefined} undefined | renderSizeChanged ( node , components , size ) | javascript | Famous/engine | core/SizeSystem.js | https://github.com/Famous/engine/blob/master/core/SizeSystem.js | MIT |
function sizeChanged (node, components, size) {
var finalSize = size.get();
var x = finalSize[0];
var y = finalSize[1];
var z = finalSize[2];
if (node.onSizeChange) node.onSizeChange(x, y, z);
for (var i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onSizeChange)
components[i].onSizeChange(x, y, z);
size.sizeChanged = false;
} | Private method to alert the node and components that the size changed.
@method
@private
@param {Node} node Node to potentially call onSizeChange on
@param {Array} components a list of the nodes' components
@param {Size} size the size class for the Node
@return {undefined} undefined | sizeChanged ( node , components , size ) | javascript | Famous/engine | core/SizeSystem.js | https://github.com/Famous/engine/blob/master/core/SizeSystem.js | MIT |
function Dispatch () {
this._nodes = {}; // a container for constant time lookup of nodes
this._queue = []; // The queue is used for two purposes
// 1. It is used to list indicies in the
// Nodes path which are then used to lookup
// a node in the scene graph.
// 2. It is used to assist dispatching
// such that it is possible to do a breadth first
// traversal of the scene graph.
} | The Dispatch class is used to propogate events down the
scene graph.
@class Dispatch
@param {Scene} context The context on which it operates
@constructor | Dispatch ( ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
Dispatch.prototype._setUpdater = function _setUpdater (updater) {
this._updater = updater;
for (var key in this._nodes) this._nodes[key]._setUpdater(updater);
}; | Protected method that sets the updater for the dispatch. The updater will
almost certainly be the FamousEngine class.
@method
@protected
@param {FamousEngine} updater The updater which will be passed through the scene graph
@return {undefined} undefined | _setUpdater ( updater ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
Dispatch.prototype.addChildrenToQueue = function addChildrenToQueue (node) {
var children = node.getChildren();
var child;
for (var i = 0, len = children.length ; i < len ; i++) {
child = children[i];
if (child) this._queue.push(child);
}
}; | Enque the children of a node within the dispatcher. Does not clear
the dispatchers queue first.
@method addChildrenToQueue
@return {void}
@param {Node} node from which to add children to the queue | addChildrenToQueue ( node ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
Dispatch.prototype.next = function next () {
return this._queue.shift();
}; | Returns the next item in the Dispatch's queue.
@method next
@return {Node} next node in the queue | next ( ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
Dispatch.prototype.breadthFirstNext = function breadthFirstNext () {
var child = this._queue.shift();
if (!child) return void 0;
this.addChildrenToQueue(child);
return child;
}; | Returns the next node in the queue, but also adds its children to
the end of the queue. Continually calling this method will result
in a breadth first traversal of the render tree.
@method breadthFirstNext
@return {Node | undefined} the next node in the traversal if one exists | breadthFirstNext ( ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
Dispatch.prototype.mount = function mount (path, node) {
if (!node) throw new Error('Dispatch: no node passed to mount at: ' + path);
if (this._nodes[path])
throw new Error('Dispatch: there is a node already registered at: ' + path);
node._setUpdater(this._updater);
this._nodes[path] = node;
var parentPath = PathUtils.parent(path);
// scenes are their own parents
var parent = !parentPath ? node : this._nodes[parentPath];
if (!parent)
throw new Error(
'Parent to path: ' + path +
' doesn\'t exist at expected path: ' + parentPath
);
var children = node.getChildren();
var components = node.getComponents();
var i;
var len;
if (parent.isMounted()) node._setMounted(true, path);
if (parent.isShown()) node._setShown(true);
if (parent.isMounted()) {
node._setParent(parent);
if (node.onMount) node.onMount(path);
for (i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onMount)
components[i].onMount(node, i);
for (i = 0, len = children.length ; i < len ; i++)
if (children[i] && children[i].mount) children[i].mount(path + '/' + i);
else if (children[i]) this.mount(path + '/' + i, children[i]);
}
if (parent.isShown()) {
if (node.onShow) node.onShow();
for (i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onShow)
components[i].onShow();
}
}; | Calls the onMount method for the node at a given path and
properly registers all of that nodes children to their proper
paths. Throws if that path doesn't have a node registered as
a parent or if there is no node registered at that path.
@method mount
@param {String} path at which to begin mounting
@param {Node} node the node that was mounted
@return {void} | mount ( path , node ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
Dispatch.prototype.dismount = function dismount (path) {
var node = this._nodes[path];
if (!node)
throw new Error(
'No node registered to path: ' + path
);
var children = node.getChildren();
var components = node.getComponents();
var i;
var len;
if (node.isShown()) {
node._setShown(false);
if (node.onHide) node.onHide();
for (i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onHide)
components[i].onHide();
}
if (node.isMounted()) {
if (node.onDismount) node.onDismount(path);
for (i = 0, len = children.length ; i < len ; i++)
if (children[i] && children[i].dismount) children[i].dismount();
else if (children[i]) this.dismount(path + '/' + i);
for (i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onDismount)
components[i].onDismount();
node._setMounted(false);
node._setParent(null);
}
this._nodes[path] = null;
}; | Calls the onDismount method for the node at a given path
and deregisters all of that nodes children. Throws if there
is no node registered at that path.
@method dismount
@return {void}
@param {String} path at which to begin dismounting | dismount ( path ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
Dispatch.prototype.getNode = function getNode (path) {
return this._nodes[path];
}; | Returns a the node registered to the given path, or none
if no node exists at that path.
@method getNode
@return {Node | void} node at the given path
@param {String} path at which to look up the node | getNode ( path ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
Dispatch.prototype.show = function show (path) {
var node = this._nodes[path];
if (!node)
throw new Error(
'No node registered to path: ' + path
);
if (node.onShow) node.onShow();
var components = node.getComponents();
for (var i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onShow)
components[i].onShow();
this.addChildrenToQueue(node);
var child;
while ((child = this.breadthFirstNext()))
this.show(child.getLocation());
}; | Issues the onShow method to the node registered at the given path,
and shows the entire subtree below that node. Throws if no node
is registered to this path.
@method show
@return {void}
@param {String} path the path of the node to show | show ( path ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
Dispatch.prototype.hide = function hide (path) {
var node = this._nodes[path];
if (!node)
throw new Error(
'No node registered to path: ' + path
);
if (node.onHide) node.onHide();
var components = node.getComponents();
for (var i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onHide)
components[i].onHide();
this.addChildrenToQueue(node);
var child;
while ((child = this.breadthFirstNext()))
this.hide(child.getLocation());
}; | Issues the onHide method to the node registered at the given path,
and hides the entire subtree below that node. Throws if no node
is registered to this path.
@method hide
@return {void}
@param {String} path the path of the node to hide | hide ( path ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
Dispatch.prototype.lookupNode = function lookupNode (location) {
if (!location) throw new Error('lookupNode must be called with a path');
this._queue.length = 0;
var path = this._queue;
_splitTo(location, path);
for (var i = 0, len = path.length ; i < len ; i++)
path[i] = this._nodes[path[i]];
return path[path.length - 1];
}; | lookupNode takes a path and returns the node at the location specified
by the path, if one exists. If not, it returns undefined.
@param {String} location The location of the node specified by its path
@return {Node | undefined} The node at the requested path | lookupNode ( location ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
Dispatch.prototype.dispatch = function dispatch (path, event, payload) {
if (!path) throw new Error('dispatch requires a path as it\'s first argument');
if (!event) throw new Error('dispatch requires an event name as it\'s second argument');
var node = this._nodes[path];
if (!node) return;
this.addChildrenToQueue(node);
var child;
while ((child = this.breadthFirstNext()))
if (child && child.onReceive)
child.onReceive(event, payload);
}; | dispatch takes an event name and a payload and dispatches it to the
entire scene graph below the node that the dispatcher is on. The nodes
receive the events in a breadth first traversal, meaning that parents
have the opportunity to react to the event before children.
@param {String} path path of the node to send the event to
@param {String} event name of the event
@param {Any} payload data associated with the event
@return {undefined} undefined | dispatch ( path , event , payload ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
Dispatch.prototype.dispatchUIEvent = function dispatchUIEvent (path, event, payload) {
if (!path) throw new Error('dispatchUIEvent needs a valid path to dispatch to');
if (!event) throw new Error('dispatchUIEvent needs an event name as its second argument');
var node;
Event.call(payload);
node = this.getNode(path);
if (node) {
var parent;
var components;
var i;
var len;
payload.node = node;
while (node) {
if (node.onReceive) node.onReceive(event, payload);
components = node.getComponents();
for (i = 0, len = components.length ; i < len ; i++)
if (components[i] && components[i].onReceive)
components[i].onReceive(event, payload);
if (payload.propagationStopped) break;
parent = node.getParent();
if (parent === node) return;
node = parent;
}
}
}; | dispatchUIevent takes a path, an event name, and a payload and dispatches them in
a manner anologous to DOM bubbling. It first traverses down to the node specified at
the path. That node receives the event first, and then every ancestor receives the event
until the context.
@param {String} path the path of the node
@param {String} event the event name
@param {Any} payload the payload
@return {undefined} undefined | dispatchUIEvent ( path , event , payload ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
function _splitTo (string, target) {
target.length = 0; // clears the array first.
var last = 0;
var i;
var len = string.length;
for (i = 0 ; i < len ; i++) {
if (string[i] === '/') {
target.push(string.substring(last, i));
last = i + 1;
}
}
if (i - last > 0) target.push(string.substring(last, i));
return target;
} | _splitTo is a private method which takes a path and splits it at every '/'
pushing the result into the supplied array. This is a destructive change.
@private
@param {String} string the specified path
@param {Array} target the array to which the result should be written
@return {Array} the target after having been written to | _splitTo ( string , target ) | javascript | Famous/engine | core/Dispatch.js | https://github.com/Famous/engine/blob/master/core/Dispatch.js | MIT |
function FamousEngine() {
var _this = this;
Dispatch._setUpdater(this);
this._updateQueue = []; // The updateQueue is a place where nodes
// can place themselves in order to be
// updated on the frame.
this._nextUpdateQueue = []; // the nextUpdateQueue is used to queue
// updates for the next tick.
// this prevents infinite loops where during
// an update a node continuously puts itself
// back in the update queue.
this._scenes = {}; // a hash of all of the scenes's that the FamousEngine
// is responsible for.
this._messages = TIME_UPDATE; // a queue of all of the draw commands to
// send to the the renderers this frame.
this._inUpdate = false; // when the famous is updating this is true.
// all requests for updates will get put in the
// nextUpdateQueue
this._clock = new Clock(); // a clock to keep track of time for the scene
// graph.
this._channel = new Channel();
this._channel.onMessage = function (message) {
_this.handleMessage(message);
};
} | Famous has two responsibilities, one to act as the highest level
updater and another to send messages over to the renderers. It is
a singleton.
@class FamousEngine
@constructor | FamousEngine ( ) | javascript | Famous/engine | core/FamousEngine.js | https://github.com/Famous/engine/blob/master/core/FamousEngine.js | MIT |
FamousEngine.prototype.init = function init(options) {
if (typeof window === 'undefined') {
throw new Error(
'FamousEngine#init needs to have access to the global window object. ' +
'Instantiate Compositor and UIManager manually in the UI thread.'
);
}
this.compositor = options && options.compositor || new Compositor();
this.renderLoop = options && options.renderLoop || new RequestAnimationFrameLoop();
this.uiManager = new UIManager(this.getChannel(), this.compositor, this.renderLoop);
return this;
}; | An init script that initializes the FamousEngine with options
or default parameters.
@method
@param {Object} options a set of options containing a compositor and a render loop
@return {FamousEngine} this | init ( options ) | javascript | Famous/engine | core/FamousEngine.js | https://github.com/Famous/engine/blob/master/core/FamousEngine.js | MIT |
FamousEngine.prototype.setChannel = function setChannel(channel) {
this._channel = channel;
return this;
}; | Sets the channel that the engine will use to communicate to
the renderers.
@method
@param {Channel} channel The channel to be used for communicating with
the `UIManager`/ `Compositor`.
@return {FamousEngine} this | setChannel ( channel ) | javascript | Famous/engine | core/FamousEngine.js | https://github.com/Famous/engine/blob/master/core/FamousEngine.js | MIT |
FamousEngine.prototype.getChannel = function getChannel () {
return this._channel;
}; | Returns the channel that the engine is currently using
to communicate with the renderers.
@method
@return {Channel} channel The channel to be used for communicating with
the `UIManager`/ `Compositor`. | getChannel ( ) | javascript | Famous/engine | core/FamousEngine.js | https://github.com/Famous/engine/blob/master/core/FamousEngine.js | MIT |
FamousEngine.prototype._update = function _update () {
this._inUpdate = true;
var time = this._clock.now();
var nextQueue = this._nextUpdateQueue;
var queue = this._updateQueue;
var item;
this._messages[1] = time;
SizeSystem.update();
TransformSystem.update();
while (nextQueue.length) queue.unshift(nextQueue.pop());
while (queue.length) {
item = queue.shift();
if (item && item.update) item.update(time);
if (item && item.onUpdate) item.onUpdate(time);
}
this._inUpdate = false;
}; | _update is the body of the update loop. The frame consists of
pulling in appending the nextUpdateQueue to the currentUpdate queue
then moving through the updateQueue and calling onUpdate with the current
time on all nodes. While _update is called _inUpdate is set to true and
all requests to be placed in the update queue will be forwarded to the
nextUpdateQueue.
@method
@return {undefined} undefined | _update ( ) | javascript | Famous/engine | core/FamousEngine.js | https://github.com/Famous/engine/blob/master/core/FamousEngine.js | MIT |
FamousEngine.prototype.requestUpdate = function requestUpdate (requester) {
if (!requester)
throw new Error(
'requestUpdate must be called with a class to be updated'
);
if (this._inUpdate) this.requestUpdateOnNextTick(requester);
else this._updateQueue.push(requester);
}; | requestUpdates takes a class that has an onUpdate method and puts it
into the updateQueue to be updated at the next frame.
If FamousEngine is currently in an update, requestUpdate
passes its argument to requestUpdateOnNextTick.
@method
@param {Object} requester an object with an onUpdate method
@return {undefined} undefined | requestUpdate ( requester ) | javascript | Famous/engine | core/FamousEngine.js | https://github.com/Famous/engine/blob/master/core/FamousEngine.js | MIT |
FamousEngine.prototype.requestUpdateOnNextTick = function requestUpdateOnNextTick (requester) {
this._nextUpdateQueue.push(requester);
}; | requestUpdateOnNextTick is requests an update on the next frame.
If FamousEngine is not currently in an update than it is functionally equivalent
to requestUpdate. This method should be used to prevent infinite loops where
a class is updated on the frame but needs to be updated again next frame.
@method
@param {Object} requester an object with an onUpdate method
@return {undefined} undefined | requestUpdateOnNextTick ( requester ) | javascript | Famous/engine | core/FamousEngine.js | https://github.com/Famous/engine/blob/master/core/FamousEngine.js | MIT |
FamousEngine.prototype.handleMessage = function handleMessage (messages) {
if (!messages)
throw new Error(
'onMessage must be called with an array of messages'
);
var command;
while (messages.length > 0) {
command = messages.shift();
switch (command) {
case Commands.WITH:
this.handleWith(messages);
break;
case Commands.FRAME:
this.handleFrame(messages);
break;
default:
throw new Error('received unknown command: ' + command);
}
}
return this;
}; | postMessage sends a message queue into FamousEngine to be processed.
These messages will be interpreted and sent into the scene graph
as events if necessary.
@method
@param {Array} messages an array of commands.
@return {FamousEngine} this | handleMessage ( messages ) | javascript | Famous/engine | core/FamousEngine.js | https://github.com/Famous/engine/blob/master/core/FamousEngine.js | MIT |
FamousEngine.prototype.handleWith = function handleWith (messages) {
var path = messages.shift();
var command = messages.shift();
switch (command) {
case Commands.TRIGGER: // the TRIGGER command sends a UIEvent to the specified path
var type = messages.shift();
var ev = messages.shift();
Dispatch.dispatchUIEvent(path, type, ev);
break;
default:
throw new Error('received unknown command: ' + command);
}
return this;
}; | handleWith is a method that takes an array of messages following the
WITH command. It'll then issue the next commands to the path specified
by the WITH command.
@method
@param {Array} messages array of messages.
@return {FamousEngine} this | handleWith ( messages ) | javascript | Famous/engine | core/FamousEngine.js | https://github.com/Famous/engine/blob/master/core/FamousEngine.js | MIT |
FamousEngine.prototype.handleFrame = function handleFrame (messages) {
if (!messages) throw new Error('handleFrame must be called with an array of messages');
if (!messages.length) throw new Error('FRAME must be sent with a time');
this.step(messages.shift());
return this;
}; | handleFrame is called when the renderers issue a FRAME command to
FamousEngine. FamousEngine will then step updating the scene graph to the current time.
@method
@param {Array} messages array of messages.
@return {FamousEngine} this | handleFrame ( messages ) | javascript | Famous/engine | core/FamousEngine.js | https://github.com/Famous/engine/blob/master/core/FamousEngine.js | MIT |
FamousEngine.prototype.step = function step (time) {
if (time == null) throw new Error('step must be called with a time');
this._clock.step(time);
this._update();
if (this._messages.length) {
this._channel.sendMessage(this._messages);
while (this._messages.length > 2) this._messages.pop();
}
return this;
}; | step updates the clock and the scene graph and then sends the draw commands
that accumulated in the update to the renderers.
@method
@param {Number} time current engine time
@return {FamousEngine} this | step ( time ) | javascript | Famous/engine | core/FamousEngine.js | https://github.com/Famous/engine/blob/master/core/FamousEngine.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.