id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
7,800 | clientIO/joint | dist/joint.nowrap.js | function(cells, opt) {
return joint.util.toArray(cells).reduce(function(memo, cell) {
if (cell.isLink()) return memo;
var rect = cell.getBBox(opt);
var angle = cell.angle();
if (angle) rect = rect.bbox(angle);
if (memo) {
return memo.union(rect);
} else {
return rect;
}
}, null);
} | javascript | function(cells, opt) {
return joint.util.toArray(cells).reduce(function(memo, cell) {
if (cell.isLink()) return memo;
var rect = cell.getBBox(opt);
var angle = cell.angle();
if (angle) rect = rect.bbox(angle);
if (memo) {
return memo.union(rect);
} else {
return rect;
}
}, null);
} | [
"function",
"(",
"cells",
",",
"opt",
")",
"{",
"return",
"joint",
".",
"util",
".",
"toArray",
"(",
"cells",
")",
".",
"reduce",
"(",
"function",
"(",
"memo",
",",
"cell",
")",
"{",
"if",
"(",
"cell",
".",
"isLink",
"(",
")",
")",
"return",
"memo",
";",
"var",
"rect",
"=",
"cell",
".",
"getBBox",
"(",
"opt",
")",
";",
"var",
"angle",
"=",
"cell",
".",
"angle",
"(",
")",
";",
"if",
"(",
"angle",
")",
"rect",
"=",
"rect",
".",
"bbox",
"(",
"angle",
")",
";",
"if",
"(",
"memo",
")",
"{",
"return",
"memo",
".",
"union",
"(",
"rect",
")",
";",
"}",
"else",
"{",
"return",
"rect",
";",
"}",
"}",
",",
"null",
")",
";",
"}"
] | Return the bounding box of all cells in array provided. Links are being ignored. | [
"Return",
"the",
"bounding",
"box",
"of",
"all",
"cells",
"in",
"array",
"provided",
".",
"Links",
"are",
"being",
"ignored",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L10847-L10860 |
|
7,801 | clientIO/joint | dist/joint.nowrap.js | dWrapper | function dWrapper(opt) {
function pathConstructor(value) {
return new g.Path(V.normalizePathData(value));
}
var shape = shapeWrapper(pathConstructor, opt);
return function(value, refBBox, node) {
var path = shape(value, refBBox, node);
return {
d: path.serialize()
};
};
} | javascript | function dWrapper(opt) {
function pathConstructor(value) {
return new g.Path(V.normalizePathData(value));
}
var shape = shapeWrapper(pathConstructor, opt);
return function(value, refBBox, node) {
var path = shape(value, refBBox, node);
return {
d: path.serialize()
};
};
} | [
"function",
"dWrapper",
"(",
"opt",
")",
"{",
"function",
"pathConstructor",
"(",
"value",
")",
"{",
"return",
"new",
"g",
".",
"Path",
"(",
"V",
".",
"normalizePathData",
"(",
"value",
")",
")",
";",
"}",
"var",
"shape",
"=",
"shapeWrapper",
"(",
"pathConstructor",
",",
"opt",
")",
";",
"return",
"function",
"(",
"value",
",",
"refBBox",
",",
"node",
")",
"{",
"var",
"path",
"=",
"shape",
"(",
"value",
",",
"refBBox",
",",
"node",
")",
";",
"return",
"{",
"d",
":",
"path",
".",
"serialize",
"(",
")",
"}",
";",
"}",
";",
"}"
] | `d` attribute for SVGPaths | [
"d",
"attribute",
"for",
"SVGPaths"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L11078-L11089 |
7,802 | clientIO/joint | dist/joint.nowrap.js | pointsWrapper | function pointsWrapper(opt) {
var shape = shapeWrapper(g.Polyline, opt);
return function(value, refBBox, node) {
var polyline = shape(value, refBBox, node);
return {
points: polyline.serialize()
};
};
} | javascript | function pointsWrapper(opt) {
var shape = shapeWrapper(g.Polyline, opt);
return function(value, refBBox, node) {
var polyline = shape(value, refBBox, node);
return {
points: polyline.serialize()
};
};
} | [
"function",
"pointsWrapper",
"(",
"opt",
")",
"{",
"var",
"shape",
"=",
"shapeWrapper",
"(",
"g",
".",
"Polyline",
",",
"opt",
")",
";",
"return",
"function",
"(",
"value",
",",
"refBBox",
",",
"node",
")",
"{",
"var",
"polyline",
"=",
"shape",
"(",
"value",
",",
"refBBox",
",",
"node",
")",
";",
"return",
"{",
"points",
":",
"polyline",
".",
"serialize",
"(",
")",
"}",
";",
"}",
";",
"}"
] | `points` attribute for SVGPolylines and SVGPolygons | [
"points",
"attribute",
"for",
"SVGPolylines",
"and",
"SVGPolygons"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L11092-L11100 |
7,803 | clientIO/joint | dist/joint.nowrap.js | function() {
var ancestors = [];
if (!this.graph) {
return ancestors;
}
var parentCell = this.getParentCell();
while (parentCell) {
ancestors.push(parentCell);
parentCell = parentCell.getParentCell();
}
return ancestors;
} | javascript | function() {
var ancestors = [];
if (!this.graph) {
return ancestors;
}
var parentCell = this.getParentCell();
while (parentCell) {
ancestors.push(parentCell);
parentCell = parentCell.getParentCell();
}
return ancestors;
} | [
"function",
"(",
")",
"{",
"var",
"ancestors",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"this",
".",
"graph",
")",
"{",
"return",
"ancestors",
";",
"}",
"var",
"parentCell",
"=",
"this",
".",
"getParentCell",
"(",
")",
";",
"while",
"(",
"parentCell",
")",
"{",
"ancestors",
".",
"push",
"(",
"parentCell",
")",
";",
"parentCell",
"=",
"parentCell",
".",
"getParentCell",
"(",
")",
";",
"}",
"return",
"ancestors",
";",
"}"
] | Return an array of ancestor cells. The array is ordered from the parent of the cell to the most distant ancestor. | [
"Return",
"an",
"array",
"of",
"ancestor",
"cells",
".",
"The",
"array",
"is",
"ordered",
"from",
"the",
"parent",
"of",
"the",
"cell",
"to",
"the",
"most",
"distant",
"ancestor",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L12071-L12086 |
|
7,804 | clientIO/joint | dist/joint.nowrap.js | function(path, opt) {
// Once a property is removed from the `attrs` attribute
// the cellView will recognize a `dirty` flag and rerender itself
// in order to remove the attribute from SVG element.
opt = opt || {};
opt.dirty = true;
var pathArray = Array.isArray(path) ? path : path.split('/');
if (pathArray.length === 1) {
// A top level property
return this.unset(path, opt);
}
// A nested property
var property = pathArray[0];
var nestedPath = pathArray.slice(1);
var propertyValue = joint.util.cloneDeep(this.get(property));
joint.util.unsetByPath(propertyValue, nestedPath, '/');
return this.set(property, propertyValue, opt);
} | javascript | function(path, opt) {
// Once a property is removed from the `attrs` attribute
// the cellView will recognize a `dirty` flag and rerender itself
// in order to remove the attribute from SVG element.
opt = opt || {};
opt.dirty = true;
var pathArray = Array.isArray(path) ? path : path.split('/');
if (pathArray.length === 1) {
// A top level property
return this.unset(path, opt);
}
// A nested property
var property = pathArray[0];
var nestedPath = pathArray.slice(1);
var propertyValue = joint.util.cloneDeep(this.get(property));
joint.util.unsetByPath(propertyValue, nestedPath, '/');
return this.set(property, propertyValue, opt);
} | [
"function",
"(",
"path",
",",
"opt",
")",
"{",
"// Once a property is removed from the `attrs` attribute",
"// the cellView will recognize a `dirty` flag and rerender itself",
"// in order to remove the attribute from SVG element.",
"opt",
"=",
"opt",
"||",
"{",
"}",
";",
"opt",
".",
"dirty",
"=",
"true",
";",
"var",
"pathArray",
"=",
"Array",
".",
"isArray",
"(",
"path",
")",
"?",
"path",
":",
"path",
".",
"split",
"(",
"'/'",
")",
";",
"if",
"(",
"pathArray",
".",
"length",
"===",
"1",
")",
"{",
"// A top level property",
"return",
"this",
".",
"unset",
"(",
"path",
",",
"opt",
")",
";",
"}",
"// A nested property",
"var",
"property",
"=",
"pathArray",
"[",
"0",
"]",
";",
"var",
"nestedPath",
"=",
"pathArray",
".",
"slice",
"(",
"1",
")",
";",
"var",
"propertyValue",
"=",
"joint",
".",
"util",
".",
"cloneDeep",
"(",
"this",
".",
"get",
"(",
"property",
")",
")",
";",
"joint",
".",
"util",
".",
"unsetByPath",
"(",
"propertyValue",
",",
"nestedPath",
",",
"'/'",
")",
";",
"return",
"this",
".",
"set",
"(",
"property",
",",
"propertyValue",
",",
"opt",
")",
";",
"}"
] | A convient way to unset nested properties | [
"A",
"convient",
"way",
"to",
"unset",
"nested",
"properties"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L12280-L12303 |
|
7,805 | clientIO/joint | dist/joint.nowrap.js | function(attrs, value, opt) {
var args = Array.from(arguments);
if (args.length === 0) {
return this.get('attrs');
}
if (Array.isArray(attrs)) {
args[0] = ['attrs'].concat(attrs);
} else if (joint.util.isString(attrs)) {
// Get/set an attribute by a special path syntax that delimits
// nested objects by the colon character.
args[0] = 'attrs/' + attrs;
} else {
args[0] = { 'attrs' : attrs };
}
return this.prop.apply(this, args);
} | javascript | function(attrs, value, opt) {
var args = Array.from(arguments);
if (args.length === 0) {
return this.get('attrs');
}
if (Array.isArray(attrs)) {
args[0] = ['attrs'].concat(attrs);
} else if (joint.util.isString(attrs)) {
// Get/set an attribute by a special path syntax that delimits
// nested objects by the colon character.
args[0] = 'attrs/' + attrs;
} else {
args[0] = { 'attrs' : attrs };
}
return this.prop.apply(this, args);
} | [
"function",
"(",
"attrs",
",",
"value",
",",
"opt",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"from",
"(",
"arguments",
")",
";",
"if",
"(",
"args",
".",
"length",
"===",
"0",
")",
"{",
"return",
"this",
".",
"get",
"(",
"'attrs'",
")",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"attrs",
")",
")",
"{",
"args",
"[",
"0",
"]",
"=",
"[",
"'attrs'",
"]",
".",
"concat",
"(",
"attrs",
")",
";",
"}",
"else",
"if",
"(",
"joint",
".",
"util",
".",
"isString",
"(",
"attrs",
")",
")",
"{",
"// Get/set an attribute by a special path syntax that delimits",
"// nested objects by the colon character.",
"args",
"[",
"0",
"]",
"=",
"'attrs/'",
"+",
"attrs",
";",
"}",
"else",
"{",
"args",
"[",
"0",
"]",
"=",
"{",
"'attrs'",
":",
"attrs",
"}",
";",
"}",
"return",
"this",
".",
"prop",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}"
] | A convenient way to set nested attributes. | [
"A",
"convenient",
"way",
"to",
"set",
"nested",
"attributes",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L12306-L12326 |
|
7,806 | clientIO/joint | dist/joint.nowrap.js | function(path, opt) {
if (Array.isArray(path)) {
return this.removeProp(['attrs'].concat(path));
}
return this.removeProp('attrs/' + path, opt);
} | javascript | function(path, opt) {
if (Array.isArray(path)) {
return this.removeProp(['attrs'].concat(path));
}
return this.removeProp('attrs/' + path, opt);
} | [
"function",
"(",
"path",
",",
"opt",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"path",
")",
")",
"{",
"return",
"this",
".",
"removeProp",
"(",
"[",
"'attrs'",
"]",
".",
"concat",
"(",
"path",
")",
")",
";",
"}",
"return",
"this",
".",
"removeProp",
"(",
"'attrs/'",
"+",
"path",
",",
"opt",
")",
";",
"}"
] | A convenient way to unset nested attributes | [
"A",
"convenient",
"way",
"to",
"unset",
"nested",
"attributes"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L12329-L12337 |
|
7,807 | clientIO/joint | dist/joint.nowrap.js | function(el) {
var $el = this.$(el);
var $rootEl = this.$el;
if ($el.length === 0) {
$el = $rootEl;
}
do {
var magnet = $el.attr('magnet');
if ((magnet || $el.is($rootEl)) && magnet !== 'false') {
return $el[0];
}
$el = $el.parent();
} while ($el.length > 0);
// If the overall cell has set `magnet === false`, then return `undefined` to
// announce there is no magnet found for this cell.
// This is especially useful to set on cells that have 'ports'. In this case,
// only the ports have set `magnet === true` and the overall element has `magnet === false`.
return undefined;
} | javascript | function(el) {
var $el = this.$(el);
var $rootEl = this.$el;
if ($el.length === 0) {
$el = $rootEl;
}
do {
var magnet = $el.attr('magnet');
if ((magnet || $el.is($rootEl)) && magnet !== 'false') {
return $el[0];
}
$el = $el.parent();
} while ($el.length > 0);
// If the overall cell has set `magnet === false`, then return `undefined` to
// announce there is no magnet found for this cell.
// This is especially useful to set on cells that have 'ports'. In this case,
// only the ports have set `magnet === true` and the overall element has `magnet === false`.
return undefined;
} | [
"function",
"(",
"el",
")",
"{",
"var",
"$el",
"=",
"this",
".",
"$",
"(",
"el",
")",
";",
"var",
"$rootEl",
"=",
"this",
".",
"$el",
";",
"if",
"(",
"$el",
".",
"length",
"===",
"0",
")",
"{",
"$el",
"=",
"$rootEl",
";",
"}",
"do",
"{",
"var",
"magnet",
"=",
"$el",
".",
"attr",
"(",
"'magnet'",
")",
";",
"if",
"(",
"(",
"magnet",
"||",
"$el",
".",
"is",
"(",
"$rootEl",
")",
")",
"&&",
"magnet",
"!==",
"'false'",
")",
"{",
"return",
"$el",
"[",
"0",
"]",
";",
"}",
"$el",
"=",
"$el",
".",
"parent",
"(",
")",
";",
"}",
"while",
"(",
"$el",
".",
"length",
">",
"0",
")",
";",
"// If the overall cell has set `magnet === false`, then return `undefined` to",
"// announce there is no magnet found for this cell.",
"// This is especially useful to set on cells that have 'ports'. In this case,",
"// only the ports have set `magnet === true` and the overall element has `magnet === false`.",
"return",
"undefined",
";",
"}"
] | Find the closest element that has the `magnet` attribute set to `true`. If there was not such an element found, return the root element of the cell view. | [
"Find",
"the",
"closest",
"element",
"that",
"has",
"the",
"magnet",
"attribute",
"set",
"to",
"true",
".",
"If",
"there",
"was",
"not",
"such",
"an",
"element",
"found",
"return",
"the",
"root",
"element",
"of",
"the",
"cell",
"view",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L12672-L12697 |
|
7,808 | clientIO/joint | dist/joint.nowrap.js | function(el, prevSelector) {
var selector;
if (el === this.el) {
if (typeof prevSelector === 'string') selector = '> ' + prevSelector;
return selector;
}
if (el) {
var nthChild = V(el).index() + 1;
selector = el.tagName + ':nth-child(' + nthChild + ')';
if (prevSelector) {
selector += ' > ' + prevSelector;
}
selector = this.getSelector(el.parentNode, selector);
}
return selector;
} | javascript | function(el, prevSelector) {
var selector;
if (el === this.el) {
if (typeof prevSelector === 'string') selector = '> ' + prevSelector;
return selector;
}
if (el) {
var nthChild = V(el).index() + 1;
selector = el.tagName + ':nth-child(' + nthChild + ')';
if (prevSelector) {
selector += ' > ' + prevSelector;
}
selector = this.getSelector(el.parentNode, selector);
}
return selector;
} | [
"function",
"(",
"el",
",",
"prevSelector",
")",
"{",
"var",
"selector",
";",
"if",
"(",
"el",
"===",
"this",
".",
"el",
")",
"{",
"if",
"(",
"typeof",
"prevSelector",
"===",
"'string'",
")",
"selector",
"=",
"'> '",
"+",
"prevSelector",
";",
"return",
"selector",
";",
"}",
"if",
"(",
"el",
")",
"{",
"var",
"nthChild",
"=",
"V",
"(",
"el",
")",
".",
"index",
"(",
")",
"+",
"1",
";",
"selector",
"=",
"el",
".",
"tagName",
"+",
"':nth-child('",
"+",
"nthChild",
"+",
"')'",
";",
"if",
"(",
"prevSelector",
")",
"{",
"selector",
"+=",
"' > '",
"+",
"prevSelector",
";",
"}",
"selector",
"=",
"this",
".",
"getSelector",
"(",
"el",
".",
"parentNode",
",",
"selector",
")",
";",
"}",
"return",
"selector",
";",
"}"
] | Construct a unique selector for the `el` element within this view. `prevSelector` is being collected through the recursive call. No value for `prevSelector` is expected when using this method. | [
"Construct",
"a",
"unique",
"selector",
"for",
"the",
"el",
"element",
"within",
"this",
"view",
".",
"prevSelector",
"is",
"being",
"collected",
"through",
"the",
"recursive",
"call",
".",
"No",
"value",
"for",
"prevSelector",
"is",
"expected",
"when",
"using",
"this",
"method",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L12702-L12724 |
|
7,809 | clientIO/joint | dist/joint.nowrap.js | function(angle, absolute, origin, opt) {
if (origin) {
var center = this.getBBox().center();
var size = this.get('size');
var position = this.get('position');
center.rotate(origin, this.get('angle') - angle);
var dx = center.x - size.width / 2 - position.x;
var dy = center.y - size.height / 2 - position.y;
this.startBatch('rotate', { angle: angle, absolute: absolute, origin: origin });
this.position(position.x + dx, position.y + dy, opt);
this.rotate(angle, absolute, null, opt);
this.stopBatch('rotate');
} else {
this.set('angle', absolute ? angle : (this.get('angle') + angle) % 360, opt);
}
return this;
} | javascript | function(angle, absolute, origin, opt) {
if (origin) {
var center = this.getBBox().center();
var size = this.get('size');
var position = this.get('position');
center.rotate(origin, this.get('angle') - angle);
var dx = center.x - size.width / 2 - position.x;
var dy = center.y - size.height / 2 - position.y;
this.startBatch('rotate', { angle: angle, absolute: absolute, origin: origin });
this.position(position.x + dx, position.y + dy, opt);
this.rotate(angle, absolute, null, opt);
this.stopBatch('rotate');
} else {
this.set('angle', absolute ? angle : (this.get('angle') + angle) % 360, opt);
}
return this;
} | [
"function",
"(",
"angle",
",",
"absolute",
",",
"origin",
",",
"opt",
")",
"{",
"if",
"(",
"origin",
")",
"{",
"var",
"center",
"=",
"this",
".",
"getBBox",
"(",
")",
".",
"center",
"(",
")",
";",
"var",
"size",
"=",
"this",
".",
"get",
"(",
"'size'",
")",
";",
"var",
"position",
"=",
"this",
".",
"get",
"(",
"'position'",
")",
";",
"center",
".",
"rotate",
"(",
"origin",
",",
"this",
".",
"get",
"(",
"'angle'",
")",
"-",
"angle",
")",
";",
"var",
"dx",
"=",
"center",
".",
"x",
"-",
"size",
".",
"width",
"/",
"2",
"-",
"position",
".",
"x",
";",
"var",
"dy",
"=",
"center",
".",
"y",
"-",
"size",
".",
"height",
"/",
"2",
"-",
"position",
".",
"y",
";",
"this",
".",
"startBatch",
"(",
"'rotate'",
",",
"{",
"angle",
":",
"angle",
",",
"absolute",
":",
"absolute",
",",
"origin",
":",
"origin",
"}",
")",
";",
"this",
".",
"position",
"(",
"position",
".",
"x",
"+",
"dx",
",",
"position",
".",
"y",
"+",
"dy",
",",
"opt",
")",
";",
"this",
".",
"rotate",
"(",
"angle",
",",
"absolute",
",",
"null",
",",
"opt",
")",
";",
"this",
".",
"stopBatch",
"(",
"'rotate'",
")",
";",
"}",
"else",
"{",
"this",
".",
"set",
"(",
"'angle'",
",",
"absolute",
"?",
"angle",
":",
"(",
"this",
".",
"get",
"(",
"'angle'",
")",
"+",
"angle",
")",
"%",
"360",
",",
"opt",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Rotate element by `angle` degrees, optionally around `origin` point. If `origin` is not provided, it is considered to be the center of the element. If `absolute` is `true`, the `angle` is considered is abslute, i.e. it is not the difference from the previous angle. | [
"Rotate",
"element",
"by",
"angle",
"degrees",
"optionally",
"around",
"origin",
"point",
".",
"If",
"origin",
"is",
"not",
"provided",
"it",
"is",
"considered",
"to",
"be",
"the",
"center",
"of",
"the",
"element",
".",
"If",
"absolute",
"is",
"true",
"the",
"angle",
"is",
"considered",
"is",
"abslute",
"i",
".",
"e",
".",
"it",
"is",
"not",
"the",
"difference",
"from",
"the",
"previous",
"angle",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L13678-L13699 |
|
7,810 | clientIO/joint | dist/joint.nowrap.js | function() {
var element = this.model;
var markup = element.get('markup') || element.markup;
if (!markup) throw new Error('dia.ElementView: markup required');
if (Array.isArray(markup)) return this.renderJSONMarkup(markup);
if (typeof markup === 'string') return this.renderStringMarkup(markup);
throw new Error('dia.ElementView: invalid markup');
} | javascript | function() {
var element = this.model;
var markup = element.get('markup') || element.markup;
if (!markup) throw new Error('dia.ElementView: markup required');
if (Array.isArray(markup)) return this.renderJSONMarkup(markup);
if (typeof markup === 'string') return this.renderStringMarkup(markup);
throw new Error('dia.ElementView: invalid markup');
} | [
"function",
"(",
")",
"{",
"var",
"element",
"=",
"this",
".",
"model",
";",
"var",
"markup",
"=",
"element",
".",
"get",
"(",
"'markup'",
")",
"||",
"element",
".",
"markup",
";",
"if",
"(",
"!",
"markup",
")",
"throw",
"new",
"Error",
"(",
"'dia.ElementView: markup required'",
")",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"markup",
")",
")",
"return",
"this",
".",
"renderJSONMarkup",
"(",
"markup",
")",
";",
"if",
"(",
"typeof",
"markup",
"===",
"'string'",
")",
"return",
"this",
".",
"renderStringMarkup",
"(",
"markup",
")",
";",
"throw",
"new",
"Error",
"(",
"'dia.ElementView: invalid markup'",
")",
";",
"}"
] | `prototype.markup` is rendered by default. Set the `markup` attribute on the model if the default markup is not desirable. | [
"prototype",
".",
"markup",
"is",
"rendered",
"by",
"default",
".",
"Set",
"the",
"markup",
"attribute",
"on",
"the",
"model",
"if",
"the",
"default",
"markup",
"is",
"not",
"desirable",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L13808-L13816 |
|
7,811 | clientIO/joint | dist/joint.nowrap.js | function(evt, x, y) {
var data = this.eventData(evt);
if (data.embedding) this.finalizeEmbedding(data);
} | javascript | function(evt, x, y) {
var data = this.eventData(evt);
if (data.embedding) this.finalizeEmbedding(data);
} | [
"function",
"(",
"evt",
",",
"x",
",",
"y",
")",
"{",
"var",
"data",
"=",
"this",
".",
"eventData",
"(",
"evt",
")",
";",
"if",
"(",
"data",
".",
"embedding",
")",
"this",
".",
"finalizeEmbedding",
"(",
"data",
")",
";",
"}"
] | Drag End Handlers | [
"Drag",
"End",
"Handlers"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L14465-L14469 |
|
7,812 | clientIO/joint | dist/joint.nowrap.js | function(idx, label, opt) {
var labels = this.labels();
idx = (isFinite(idx) && idx !== null) ? (idx | 0) : 0;
if (idx < 0) idx = labels.length + idx;
// getter
if (arguments.length <= 1) return this.prop(['labels', idx]);
// setter
return this.prop(['labels', idx], label, opt);
} | javascript | function(idx, label, opt) {
var labels = this.labels();
idx = (isFinite(idx) && idx !== null) ? (idx | 0) : 0;
if (idx < 0) idx = labels.length + idx;
// getter
if (arguments.length <= 1) return this.prop(['labels', idx]);
// setter
return this.prop(['labels', idx], label, opt);
} | [
"function",
"(",
"idx",
",",
"label",
",",
"opt",
")",
"{",
"var",
"labels",
"=",
"this",
".",
"labels",
"(",
")",
";",
"idx",
"=",
"(",
"isFinite",
"(",
"idx",
")",
"&&",
"idx",
"!==",
"null",
")",
"?",
"(",
"idx",
"|",
"0",
")",
":",
"0",
";",
"if",
"(",
"idx",
"<",
"0",
")",
"idx",
"=",
"labels",
".",
"length",
"+",
"idx",
";",
"// getter",
"if",
"(",
"arguments",
".",
"length",
"<=",
"1",
")",
"return",
"this",
".",
"prop",
"(",
"[",
"'labels'",
",",
"idx",
"]",
")",
";",
"// setter",
"return",
"this",
".",
"prop",
"(",
"[",
"'labels'",
",",
"idx",
"]",
",",
"label",
",",
"opt",
")",
";",
"}"
] | Labels API A convenient way to set labels. Currently set values will be mixined with `value` if used as a setter. | [
"Labels",
"API",
"A",
"convenient",
"way",
"to",
"set",
"labels",
".",
"Currently",
"set",
"values",
"will",
"be",
"mixined",
"with",
"value",
"if",
"used",
"as",
"a",
"setter",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L14738-L14749 |
|
7,813 | clientIO/joint | dist/joint.nowrap.js | function() {
var connectionAncestor;
if (this.graph) {
var cells = [
this,
this.getSourceElement(), // null if source is a point
this.getTargetElement() // null if target is a point
].filter(function(item) {
return !!item;
});
connectionAncestor = this.graph.getCommonAncestor.apply(this.graph, cells);
}
return connectionAncestor || null;
} | javascript | function() {
var connectionAncestor;
if (this.graph) {
var cells = [
this,
this.getSourceElement(), // null if source is a point
this.getTargetElement() // null if target is a point
].filter(function(item) {
return !!item;
});
connectionAncestor = this.graph.getCommonAncestor.apply(this.graph, cells);
}
return connectionAncestor || null;
} | [
"function",
"(",
")",
"{",
"var",
"connectionAncestor",
";",
"if",
"(",
"this",
".",
"graph",
")",
"{",
"var",
"cells",
"=",
"[",
"this",
",",
"this",
".",
"getSourceElement",
"(",
")",
",",
"// null if source is a point",
"this",
".",
"getTargetElement",
"(",
")",
"// null if target is a point",
"]",
".",
"filter",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"!",
"!",
"item",
";",
"}",
")",
";",
"connectionAncestor",
"=",
"this",
".",
"graph",
".",
"getCommonAncestor",
".",
"apply",
"(",
"this",
".",
"graph",
",",
"cells",
")",
";",
"}",
"return",
"connectionAncestor",
"||",
"null",
";",
"}"
] | Returns the common ancestor for the source element, target element and the link itself. | [
"Returns",
"the",
"common",
"ancestor",
"for",
"the",
"source",
"element",
"target",
"element",
"and",
"the",
"link",
"itself",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L14973-L14991 |
|
7,814 | clientIO/joint | dist/joint.nowrap.js | function(cell) {
var cellId = (joint.util.isString(cell) || joint.util.isNumber(cell)) ? cell : cell.id;
var ancestor = this.getRelationshipAncestor();
return !!ancestor && (ancestor.id === cellId || ancestor.isEmbeddedIn(cellId));
} | javascript | function(cell) {
var cellId = (joint.util.isString(cell) || joint.util.isNumber(cell)) ? cell : cell.id;
var ancestor = this.getRelationshipAncestor();
return !!ancestor && (ancestor.id === cellId || ancestor.isEmbeddedIn(cellId));
} | [
"function",
"(",
"cell",
")",
"{",
"var",
"cellId",
"=",
"(",
"joint",
".",
"util",
".",
"isString",
"(",
"cell",
")",
"||",
"joint",
".",
"util",
".",
"isNumber",
"(",
"cell",
")",
")",
"?",
"cell",
":",
"cell",
".",
"id",
";",
"var",
"ancestor",
"=",
"this",
".",
"getRelationshipAncestor",
"(",
")",
";",
"return",
"!",
"!",
"ancestor",
"&&",
"(",
"ancestor",
".",
"id",
"===",
"cellId",
"||",
"ancestor",
".",
"isEmbeddedIn",
"(",
"cellId",
")",
")",
";",
"}"
] | Is source, target and the link itself embedded in a given cell? | [
"Is",
"source",
"target",
"and",
"the",
"link",
"itself",
"embedded",
"in",
"a",
"given",
"cell?"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L14994-L15000 |
|
7,815 | clientIO/joint | dist/joint.nowrap.js | function() {
var defaultLabel = this.get('defaultLabel') || this.defaultLabel || {};
var label = {};
label.markup = defaultLabel.markup || this.get('labelMarkup') || this.labelMarkup;
label.position = defaultLabel.position;
label.attrs = defaultLabel.attrs;
label.size = defaultLabel.size;
return label;
} | javascript | function() {
var defaultLabel = this.get('defaultLabel') || this.defaultLabel || {};
var label = {};
label.markup = defaultLabel.markup || this.get('labelMarkup') || this.labelMarkup;
label.position = defaultLabel.position;
label.attrs = defaultLabel.attrs;
label.size = defaultLabel.size;
return label;
} | [
"function",
"(",
")",
"{",
"var",
"defaultLabel",
"=",
"this",
".",
"get",
"(",
"'defaultLabel'",
")",
"||",
"this",
".",
"defaultLabel",
"||",
"{",
"}",
";",
"var",
"label",
"=",
"{",
"}",
";",
"label",
".",
"markup",
"=",
"defaultLabel",
".",
"markup",
"||",
"this",
".",
"get",
"(",
"'labelMarkup'",
")",
"||",
"this",
".",
"labelMarkup",
";",
"label",
".",
"position",
"=",
"defaultLabel",
".",
"position",
";",
"label",
".",
"attrs",
"=",
"defaultLabel",
".",
"attrs",
";",
"label",
".",
"size",
"=",
"defaultLabel",
".",
"size",
";",
"return",
"label",
";",
"}"
] | Get resolved default label. | [
"Get",
"resolved",
"default",
"label",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L15003-L15014 |
|
7,816 | clientIO/joint | dist/joint.nowrap.js | function(endType) {
// create handler for specific end type (source|target).
var onModelChange = function(endModel, opt) {
this.onEndModelChange(endType, endModel, opt);
};
function watchEndModel(link, end) {
end = end || {};
var endModel = null;
var previousEnd = link.previous(endType) || {};
if (previousEnd.id) {
this.stopListening(this.paper.getModelById(previousEnd.id), 'change', onModelChange);
}
if (end.id) {
// If the observed model changes, it caches a new bbox and do the link update.
endModel = this.paper.getModelById(end.id);
this.listenTo(endModel, 'change', onModelChange);
}
onModelChange.call(this, endModel, { cacheOnly: true });
return this;
}
return watchEndModel;
} | javascript | function(endType) {
// create handler for specific end type (source|target).
var onModelChange = function(endModel, opt) {
this.onEndModelChange(endType, endModel, opt);
};
function watchEndModel(link, end) {
end = end || {};
var endModel = null;
var previousEnd = link.previous(endType) || {};
if (previousEnd.id) {
this.stopListening(this.paper.getModelById(previousEnd.id), 'change', onModelChange);
}
if (end.id) {
// If the observed model changes, it caches a new bbox and do the link update.
endModel = this.paper.getModelById(end.id);
this.listenTo(endModel, 'change', onModelChange);
}
onModelChange.call(this, endModel, { cacheOnly: true });
return this;
}
return watchEndModel;
} | [
"function",
"(",
"endType",
")",
"{",
"// create handler for specific end type (source|target).",
"var",
"onModelChange",
"=",
"function",
"(",
"endModel",
",",
"opt",
")",
"{",
"this",
".",
"onEndModelChange",
"(",
"endType",
",",
"endModel",
",",
"opt",
")",
";",
"}",
";",
"function",
"watchEndModel",
"(",
"link",
",",
"end",
")",
"{",
"end",
"=",
"end",
"||",
"{",
"}",
";",
"var",
"endModel",
"=",
"null",
";",
"var",
"previousEnd",
"=",
"link",
".",
"previous",
"(",
"endType",
")",
"||",
"{",
"}",
";",
"if",
"(",
"previousEnd",
".",
"id",
")",
"{",
"this",
".",
"stopListening",
"(",
"this",
".",
"paper",
".",
"getModelById",
"(",
"previousEnd",
".",
"id",
")",
",",
"'change'",
",",
"onModelChange",
")",
";",
"}",
"if",
"(",
"end",
".",
"id",
")",
"{",
"// If the observed model changes, it caches a new bbox and do the link update.",
"endModel",
"=",
"this",
".",
"paper",
".",
"getModelById",
"(",
"end",
".",
"id",
")",
";",
"this",
".",
"listenTo",
"(",
"endModel",
",",
"'change'",
",",
"onModelChange",
")",
";",
"}",
"onModelChange",
".",
"call",
"(",
"this",
",",
"endModel",
",",
"{",
"cacheOnly",
":",
"true",
"}",
")",
";",
"return",
"this",
";",
"}",
"return",
"watchEndModel",
";",
"}"
] | Returns a function observing changes on an end of the link. If a change happens and new end is a new model, it stops listening on the previous one and starts listening to the new one. | [
"Returns",
"a",
"function",
"observing",
"changes",
"on",
"an",
"end",
"of",
"the",
"link",
".",
"If",
"a",
"change",
"happens",
"and",
"new",
"end",
"is",
"a",
"new",
"model",
"it",
"stops",
"listening",
"on",
"the",
"previous",
"one",
"and",
"starts",
"listening",
"to",
"the",
"new",
"one",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L15981-L16011 |
|
7,817 | clientIO/joint | dist/joint.nowrap.js | function(x, y, opt) {
// accept input in form `{ x, y }, opt` or `x, y, opt`
var isPointProvided = (typeof x !== 'number');
var localX = isPointProvided ? x.x : x;
var localY = isPointProvided ? x.y : y;
var localOpt = isPointProvided ? y : opt;
var vertex = { x: localX, y: localY };
var idx = this.getVertexIndex(localX, localY);
this.model.insertVertex(idx, vertex, localOpt);
return idx;
} | javascript | function(x, y, opt) {
// accept input in form `{ x, y }, opt` or `x, y, opt`
var isPointProvided = (typeof x !== 'number');
var localX = isPointProvided ? x.x : x;
var localY = isPointProvided ? x.y : y;
var localOpt = isPointProvided ? y : opt;
var vertex = { x: localX, y: localY };
var idx = this.getVertexIndex(localX, localY);
this.model.insertVertex(idx, vertex, localOpt);
return idx;
} | [
"function",
"(",
"x",
",",
"y",
",",
"opt",
")",
"{",
"// accept input in form `{ x, y }, opt` or `x, y, opt`",
"var",
"isPointProvided",
"=",
"(",
"typeof",
"x",
"!==",
"'number'",
")",
";",
"var",
"localX",
"=",
"isPointProvided",
"?",
"x",
".",
"x",
":",
"x",
";",
"var",
"localY",
"=",
"isPointProvided",
"?",
"x",
".",
"y",
":",
"y",
";",
"var",
"localOpt",
"=",
"isPointProvided",
"?",
"y",
":",
"opt",
";",
"var",
"vertex",
"=",
"{",
"x",
":",
"localX",
",",
"y",
":",
"localY",
"}",
";",
"var",
"idx",
"=",
"this",
".",
"getVertexIndex",
"(",
"localX",
",",
"localY",
")",
";",
"this",
".",
"model",
".",
"insertVertex",
"(",
"idx",
",",
"vertex",
",",
"localOpt",
")",
";",
"return",
"idx",
";",
"}"
] | Add a new vertex at calculated index to the `vertices` array. | [
"Add",
"a",
"new",
"vertex",
"at",
"calculated",
"index",
"to",
"the",
"vertices",
"array",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L16194-L16206 |
|
7,818 | clientIO/joint | dist/joint.nowrap.js | function(angle, cx, cy) {
// getter
if (angle === undefined) {
return V.matrixToRotate(this.matrix());
}
// setter
// If the origin is not set explicitely, rotate around the center. Note that
// we must use the plain bounding box (`this.el.getBBox()` instead of the one that gives us
// the real bounding box (`bbox()`) including transformations).
if (cx === undefined) {
var bbox = this.viewport.getBBox();
cx = bbox.width / 2;
cy = bbox.height / 2;
}
var ctm = this.matrix().translate(cx,cy).rotate(angle).translate(-cx,-cy);
this.matrix(ctm);
return this;
} | javascript | function(angle, cx, cy) {
// getter
if (angle === undefined) {
return V.matrixToRotate(this.matrix());
}
// setter
// If the origin is not set explicitely, rotate around the center. Note that
// we must use the plain bounding box (`this.el.getBBox()` instead of the one that gives us
// the real bounding box (`bbox()`) including transformations).
if (cx === undefined) {
var bbox = this.viewport.getBBox();
cx = bbox.width / 2;
cy = bbox.height / 2;
}
var ctm = this.matrix().translate(cx,cy).rotate(angle).translate(-cx,-cy);
this.matrix(ctm);
return this;
} | [
"function",
"(",
"angle",
",",
"cx",
",",
"cy",
")",
"{",
"// getter",
"if",
"(",
"angle",
"===",
"undefined",
")",
"{",
"return",
"V",
".",
"matrixToRotate",
"(",
"this",
".",
"matrix",
"(",
")",
")",
";",
"}",
"// setter",
"// If the origin is not set explicitely, rotate around the center. Note that",
"// we must use the plain bounding box (`this.el.getBBox()` instead of the one that gives us",
"// the real bounding box (`bbox()`) including transformations).",
"if",
"(",
"cx",
"===",
"undefined",
")",
"{",
"var",
"bbox",
"=",
"this",
".",
"viewport",
".",
"getBBox",
"(",
")",
";",
"cx",
"=",
"bbox",
".",
"width",
"/",
"2",
";",
"cy",
"=",
"bbox",
".",
"height",
"/",
"2",
";",
"}",
"var",
"ctm",
"=",
"this",
".",
"matrix",
"(",
")",
".",
"translate",
"(",
"cx",
",",
"cy",
")",
".",
"rotate",
"(",
"angle",
")",
".",
"translate",
"(",
"-",
"cx",
",",
"-",
"cy",
")",
";",
"this",
".",
"matrix",
"(",
"ctm",
")",
";",
"return",
"this",
";",
"}"
] | Experimental - do not use in production. | [
"Experimental",
"-",
"do",
"not",
"use",
"in",
"production",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L18161-L18183 |
|
7,819 | clientIO/joint | dist/joint.nowrap.js | function($el) {
var el = joint.util.isString($el)
? this.viewport.querySelector($el)
: $el instanceof $ ? $el[0] : $el;
var id = this.findAttribute('model-id', el);
if (id) return this._views[id];
return undefined;
} | javascript | function($el) {
var el = joint.util.isString($el)
? this.viewport.querySelector($el)
: $el instanceof $ ? $el[0] : $el;
var id = this.findAttribute('model-id', el);
if (id) return this._views[id];
return undefined;
} | [
"function",
"(",
"$el",
")",
"{",
"var",
"el",
"=",
"joint",
".",
"util",
".",
"isString",
"(",
"$el",
")",
"?",
"this",
".",
"viewport",
".",
"querySelector",
"(",
"$el",
")",
":",
"$el",
"instanceof",
"$",
"?",
"$el",
"[",
"0",
"]",
":",
"$el",
";",
"var",
"id",
"=",
"this",
".",
"findAttribute",
"(",
"'model-id'",
",",
"el",
")",
";",
"if",
"(",
"id",
")",
"return",
"this",
".",
"_views",
"[",
"id",
"]",
";",
"return",
"undefined",
";",
"}"
] | Find the first view climbing up the DOM tree starting at element `el`. Note that `el` can also be a selector or a jQuery object. | [
"Find",
"the",
"first",
"view",
"climbing",
"up",
"the",
"DOM",
"tree",
"starting",
"at",
"element",
"el",
".",
"Note",
"that",
"el",
"can",
"also",
"be",
"a",
"selector",
"or",
"a",
"jQuery",
"object",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L18216-L18226 |
|
7,820 | clientIO/joint | dist/joint.nowrap.js | function(cell) {
var id = (joint.util.isString(cell) || joint.util.isNumber(cell)) ? cell : (cell && cell.id);
return this._views[id];
} | javascript | function(cell) {
var id = (joint.util.isString(cell) || joint.util.isNumber(cell)) ? cell : (cell && cell.id);
return this._views[id];
} | [
"function",
"(",
"cell",
")",
"{",
"var",
"id",
"=",
"(",
"joint",
".",
"util",
".",
"isString",
"(",
"cell",
")",
"||",
"joint",
".",
"util",
".",
"isNumber",
"(",
"cell",
")",
")",
"?",
"cell",
":",
"(",
"cell",
"&&",
"cell",
".",
"id",
")",
";",
"return",
"this",
".",
"_views",
"[",
"id",
"]",
";",
"}"
] | Find a view for a model `cell`. `cell` can also be a string or number representing a model `id`. | [
"Find",
"a",
"view",
"for",
"a",
"model",
"cell",
".",
"cell",
"can",
"also",
"be",
"a",
"string",
"or",
"number",
"representing",
"a",
"model",
"id",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L18229-L18234 |
|
7,821 | clientIO/joint | dist/joint.nowrap.js | function(p) {
p = new g.Point(p);
var views = this.model.getElements().map(this.findViewByModel, this);
return views.filter(function(view) {
return view && view.vel.getBBox({ target: this.viewport }).containsPoint(p);
}, this);
} | javascript | function(p) {
p = new g.Point(p);
var views = this.model.getElements().map(this.findViewByModel, this);
return views.filter(function(view) {
return view && view.vel.getBBox({ target: this.viewport }).containsPoint(p);
}, this);
} | [
"function",
"(",
"p",
")",
"{",
"p",
"=",
"new",
"g",
".",
"Point",
"(",
"p",
")",
";",
"var",
"views",
"=",
"this",
".",
"model",
".",
"getElements",
"(",
")",
".",
"map",
"(",
"this",
".",
"findViewByModel",
",",
"this",
")",
";",
"return",
"views",
".",
"filter",
"(",
"function",
"(",
"view",
")",
"{",
"return",
"view",
"&&",
"view",
".",
"vel",
".",
"getBBox",
"(",
"{",
"target",
":",
"this",
".",
"viewport",
"}",
")",
".",
"containsPoint",
"(",
"p",
")",
";",
"}",
",",
"this",
")",
";",
"}"
] | Find all views at given point | [
"Find",
"all",
"views",
"at",
"given",
"point"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L18237-L18246 |
|
7,822 | clientIO/joint | dist/joint.nowrap.js | function(rect, opt) {
opt = joint.util.defaults(opt || {}, { strict: false });
rect = new g.Rect(rect);
var views = this.model.getElements().map(this.findViewByModel, this);
var method = opt.strict ? 'containsRect' : 'intersect';
return views.filter(function(view) {
return view && rect[method](view.vel.getBBox({ target: this.viewport }));
}, this);
} | javascript | function(rect, opt) {
opt = joint.util.defaults(opt || {}, { strict: false });
rect = new g.Rect(rect);
var views = this.model.getElements().map(this.findViewByModel, this);
var method = opt.strict ? 'containsRect' : 'intersect';
return views.filter(function(view) {
return view && rect[method](view.vel.getBBox({ target: this.viewport }));
}, this);
} | [
"function",
"(",
"rect",
",",
"opt",
")",
"{",
"opt",
"=",
"joint",
".",
"util",
".",
"defaults",
"(",
"opt",
"||",
"{",
"}",
",",
"{",
"strict",
":",
"false",
"}",
")",
";",
"rect",
"=",
"new",
"g",
".",
"Rect",
"(",
"rect",
")",
";",
"var",
"views",
"=",
"this",
".",
"model",
".",
"getElements",
"(",
")",
".",
"map",
"(",
"this",
".",
"findViewByModel",
",",
"this",
")",
";",
"var",
"method",
"=",
"opt",
".",
"strict",
"?",
"'containsRect'",
":",
"'intersect'",
";",
"return",
"views",
".",
"filter",
"(",
"function",
"(",
"view",
")",
"{",
"return",
"view",
"&&",
"rect",
"[",
"method",
"]",
"(",
"view",
".",
"vel",
".",
"getBBox",
"(",
"{",
"target",
":",
"this",
".",
"viewport",
"}",
")",
")",
";",
"}",
",",
"this",
")",
";",
"}"
] | Find all views in given area | [
"Find",
"all",
"views",
"in",
"given",
"area"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L18249-L18260 |
|
7,823 | clientIO/joint | dist/joint.nowrap.js | function(evt, view) {
if (evt.type === 'mousedown' && evt.button === 2) {
// handled as `contextmenu` type
return true;
}
if (this.options.guard && this.options.guard(evt, view)) {
return true;
}
if (evt.data && evt.data.guarded !== undefined) {
return evt.data.guarded;
}
if (view && view.model && (view.model instanceof joint.dia.Cell)) {
return false;
}
if (this.svg === evt.target || this.el === evt.target || $.contains(this.svg, evt.target)) {
return false;
}
return true; // Event guarded. Paper should not react on it in any way.
} | javascript | function(evt, view) {
if (evt.type === 'mousedown' && evt.button === 2) {
// handled as `contextmenu` type
return true;
}
if (this.options.guard && this.options.guard(evt, view)) {
return true;
}
if (evt.data && evt.data.guarded !== undefined) {
return evt.data.guarded;
}
if (view && view.model && (view.model instanceof joint.dia.Cell)) {
return false;
}
if (this.svg === evt.target || this.el === evt.target || $.contains(this.svg, evt.target)) {
return false;
}
return true; // Event guarded. Paper should not react on it in any way.
} | [
"function",
"(",
"evt",
",",
"view",
")",
"{",
"if",
"(",
"evt",
".",
"type",
"===",
"'mousedown'",
"&&",
"evt",
".",
"button",
"===",
"2",
")",
"{",
"// handled as `contextmenu` type",
"return",
"true",
";",
"}",
"if",
"(",
"this",
".",
"options",
".",
"guard",
"&&",
"this",
".",
"options",
".",
"guard",
"(",
"evt",
",",
"view",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"evt",
".",
"data",
"&&",
"evt",
".",
"data",
".",
"guarded",
"!==",
"undefined",
")",
"{",
"return",
"evt",
".",
"data",
".",
"guarded",
";",
"}",
"if",
"(",
"view",
"&&",
"view",
".",
"model",
"&&",
"(",
"view",
".",
"model",
"instanceof",
"joint",
".",
"dia",
".",
"Cell",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"this",
".",
"svg",
"===",
"evt",
".",
"target",
"||",
"this",
".",
"el",
"===",
"evt",
".",
"target",
"||",
"$",
".",
"contains",
"(",
"this",
".",
"svg",
",",
"evt",
".",
"target",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"// Event guarded. Paper should not react on it in any way.",
"}"
] | Guard the specified event. If the event is not interesting, guard returns `true`. Otherwise, it returns `false`. | [
"Guard",
"the",
"specified",
"event",
".",
"If",
"the",
"event",
"is",
"not",
"interesting",
"guard",
"returns",
"true",
".",
"Otherwise",
"it",
"returns",
"false",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L18828-L18852 |
|
7,824 | clientIO/joint | dist/joint.nowrap.js | function() {
var current = this.get('ports') || {};
var currentItemsMap = {};
util.toArray(current.items).forEach(function(item) {
currentItemsMap[item.id] = true;
});
var previous = this.previous('ports') || {};
var removed = {};
util.toArray(previous.items).forEach(function(item) {
if (!currentItemsMap[item.id]) {
removed[item.id] = true;
}
});
var graph = this.graph;
if (graph && !util.isEmpty(removed)) {
var inboundLinks = graph.getConnectedLinks(this, { inbound: true });
inboundLinks.forEach(function(link) {
if (removed[link.get('target').port]) link.remove();
});
var outboundLinks = graph.getConnectedLinks(this, { outbound: true });
outboundLinks.forEach(function(link) {
if (removed[link.get('source').port]) link.remove();
});
}
} | javascript | function() {
var current = this.get('ports') || {};
var currentItemsMap = {};
util.toArray(current.items).forEach(function(item) {
currentItemsMap[item.id] = true;
});
var previous = this.previous('ports') || {};
var removed = {};
util.toArray(previous.items).forEach(function(item) {
if (!currentItemsMap[item.id]) {
removed[item.id] = true;
}
});
var graph = this.graph;
if (graph && !util.isEmpty(removed)) {
var inboundLinks = graph.getConnectedLinks(this, { inbound: true });
inboundLinks.forEach(function(link) {
if (removed[link.get('target').port]) link.remove();
});
var outboundLinks = graph.getConnectedLinks(this, { outbound: true });
outboundLinks.forEach(function(link) {
if (removed[link.get('source').port]) link.remove();
});
}
} | [
"function",
"(",
")",
"{",
"var",
"current",
"=",
"this",
".",
"get",
"(",
"'ports'",
")",
"||",
"{",
"}",
";",
"var",
"currentItemsMap",
"=",
"{",
"}",
";",
"util",
".",
"toArray",
"(",
"current",
".",
"items",
")",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"currentItemsMap",
"[",
"item",
".",
"id",
"]",
"=",
"true",
";",
"}",
")",
";",
"var",
"previous",
"=",
"this",
".",
"previous",
"(",
"'ports'",
")",
"||",
"{",
"}",
";",
"var",
"removed",
"=",
"{",
"}",
";",
"util",
".",
"toArray",
"(",
"previous",
".",
"items",
")",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"!",
"currentItemsMap",
"[",
"item",
".",
"id",
"]",
")",
"{",
"removed",
"[",
"item",
".",
"id",
"]",
"=",
"true",
";",
"}",
"}",
")",
";",
"var",
"graph",
"=",
"this",
".",
"graph",
";",
"if",
"(",
"graph",
"&&",
"!",
"util",
".",
"isEmpty",
"(",
"removed",
")",
")",
"{",
"var",
"inboundLinks",
"=",
"graph",
".",
"getConnectedLinks",
"(",
"this",
",",
"{",
"inbound",
":",
"true",
"}",
")",
";",
"inboundLinks",
".",
"forEach",
"(",
"function",
"(",
"link",
")",
"{",
"if",
"(",
"removed",
"[",
"link",
".",
"get",
"(",
"'target'",
")",
".",
"port",
"]",
")",
"link",
".",
"remove",
"(",
")",
";",
"}",
")",
";",
"var",
"outboundLinks",
"=",
"graph",
".",
"getConnectedLinks",
"(",
"this",
",",
"{",
"outbound",
":",
"true",
"}",
")",
";",
"outboundLinks",
".",
"forEach",
"(",
"function",
"(",
"link",
")",
"{",
"if",
"(",
"removed",
"[",
"link",
".",
"get",
"(",
"'source'",
")",
".",
"port",
"]",
")",
"link",
".",
"remove",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
] | remove links tied wiht just removed element
@private | [
"remove",
"links",
"tied",
"wiht",
"just",
"removed",
"element"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L19640-L19673 |
|
7,825 | clientIO/joint | dist/joint.nowrap.js | function(port) {
if (this._portElementsCache[port.id]) {
return this._portElementsCache[port.id].portElement;
}
return this._createPortElement(port);
} | javascript | function(port) {
if (this._portElementsCache[port.id]) {
return this._portElementsCache[port.id].portElement;
}
return this._createPortElement(port);
} | [
"function",
"(",
"port",
")",
"{",
"if",
"(",
"this",
".",
"_portElementsCache",
"[",
"port",
".",
"id",
"]",
")",
"{",
"return",
"this",
".",
"_portElementsCache",
"[",
"port",
".",
"id",
"]",
".",
"portElement",
";",
"}",
"return",
"this",
".",
"_createPortElement",
"(",
"port",
")",
";",
"}"
] | Try to get element from cache,
@param port
@returns {*}
@private | [
"Try",
"to",
"get",
"element",
"from",
"cache"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L20063-L20069 |
|
7,826 | clientIO/joint | dist/joint.nowrap.js | freeJoin | function freeJoin(p1, p2, bbox) {
var p = new g.Point(p1.x, p2.y);
if (bbox.containsPoint(p)) p = new g.Point(p2.x, p1.y);
// kept for reference
// if (bbox.containsPoint(p)) p = null;
return p;
} | javascript | function freeJoin(p1, p2, bbox) {
var p = new g.Point(p1.x, p2.y);
if (bbox.containsPoint(p)) p = new g.Point(p2.x, p1.y);
// kept for reference
// if (bbox.containsPoint(p)) p = null;
return p;
} | [
"function",
"freeJoin",
"(",
"p1",
",",
"p2",
",",
"bbox",
")",
"{",
"var",
"p",
"=",
"new",
"g",
".",
"Point",
"(",
"p1",
".",
"x",
",",
"p2",
".",
"y",
")",
";",
"if",
"(",
"bbox",
".",
"containsPoint",
"(",
"p",
")",
")",
"p",
"=",
"new",
"g",
".",
"Point",
"(",
"p2",
".",
"x",
",",
"p1",
".",
"y",
")",
";",
"// kept for reference",
"// if (bbox.containsPoint(p)) p = null;",
"return",
"p",
";",
"}"
] | returns a point `p` where lines p,p1 and p,p2 are perpendicular and p is not contained in the given box | [
"returns",
"a",
"point",
"p",
"where",
"lines",
"p",
"p1",
"and",
"p",
"p2",
"are",
"perpendicular",
"and",
"p",
"is",
"not",
"contained",
"in",
"the",
"given",
"box"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L22476-L22484 |
7,827 | clientIO/joint | dist/joint.nowrap.js | insideElement | function insideElement(from, to, fromBBox, toBBox, bearing) {
var route = {};
var boundary = fromBBox.union(toBBox).inflate(1);
// start from the point which is closer to the boundary
var reversed = boundary.center().distance(to) > boundary.center().distance(from);
var start = reversed ? to : from;
var end = reversed ? from : to;
var p1, p2, p3;
if (bearing) {
// Points on circle with radius equals 'W + H` are always outside the rectangle
// with width W and height H if the center of that circle is the center of that rectangle.
p1 = g.Point.fromPolar(boundary.width + boundary.height, radians[bearing], start);
p1 = boundary.pointNearestToPoint(p1).move(p1, -1);
} else {
p1 = boundary.pointNearestToPoint(start).move(start, 1);
}
p2 = freeJoin(p1, end, boundary);
if (p1.round().equals(p2.round())) {
p2 = g.Point.fromPolar(boundary.width + boundary.height, g.toRad(p1.theta(start)) + Math.PI / 2, end);
p2 = boundary.pointNearestToPoint(p2).move(end, 1).round();
p3 = freeJoin(p1, p2, boundary);
route.points = reversed ? [p2, p3, p1] : [p1, p3, p2];
} else {
route.points = reversed ? [p2, p1] : [p1, p2];
}
route.direction = reversed ? getBearing(p1, to) : getBearing(p2, to);
return route;
} | javascript | function insideElement(from, to, fromBBox, toBBox, bearing) {
var route = {};
var boundary = fromBBox.union(toBBox).inflate(1);
// start from the point which is closer to the boundary
var reversed = boundary.center().distance(to) > boundary.center().distance(from);
var start = reversed ? to : from;
var end = reversed ? from : to;
var p1, p2, p3;
if (bearing) {
// Points on circle with radius equals 'W + H` are always outside the rectangle
// with width W and height H if the center of that circle is the center of that rectangle.
p1 = g.Point.fromPolar(boundary.width + boundary.height, radians[bearing], start);
p1 = boundary.pointNearestToPoint(p1).move(p1, -1);
} else {
p1 = boundary.pointNearestToPoint(start).move(start, 1);
}
p2 = freeJoin(p1, end, boundary);
if (p1.round().equals(p2.round())) {
p2 = g.Point.fromPolar(boundary.width + boundary.height, g.toRad(p1.theta(start)) + Math.PI / 2, end);
p2 = boundary.pointNearestToPoint(p2).move(end, 1).round();
p3 = freeJoin(p1, p2, boundary);
route.points = reversed ? [p2, p3, p1] : [p1, p3, p2];
} else {
route.points = reversed ? [p2, p1] : [p1, p2];
}
route.direction = reversed ? getBearing(p1, to) : getBearing(p2, to);
return route;
} | [
"function",
"insideElement",
"(",
"from",
",",
"to",
",",
"fromBBox",
",",
"toBBox",
",",
"bearing",
")",
"{",
"var",
"route",
"=",
"{",
"}",
";",
"var",
"boundary",
"=",
"fromBBox",
".",
"union",
"(",
"toBBox",
")",
".",
"inflate",
"(",
"1",
")",
";",
"// start from the point which is closer to the boundary",
"var",
"reversed",
"=",
"boundary",
".",
"center",
"(",
")",
".",
"distance",
"(",
"to",
")",
">",
"boundary",
".",
"center",
"(",
")",
".",
"distance",
"(",
"from",
")",
";",
"var",
"start",
"=",
"reversed",
"?",
"to",
":",
"from",
";",
"var",
"end",
"=",
"reversed",
"?",
"from",
":",
"to",
";",
"var",
"p1",
",",
"p2",
",",
"p3",
";",
"if",
"(",
"bearing",
")",
"{",
"// Points on circle with radius equals 'W + H` are always outside the rectangle",
"// with width W and height H if the center of that circle is the center of that rectangle.",
"p1",
"=",
"g",
".",
"Point",
".",
"fromPolar",
"(",
"boundary",
".",
"width",
"+",
"boundary",
".",
"height",
",",
"radians",
"[",
"bearing",
"]",
",",
"start",
")",
";",
"p1",
"=",
"boundary",
".",
"pointNearestToPoint",
"(",
"p1",
")",
".",
"move",
"(",
"p1",
",",
"-",
"1",
")",
";",
"}",
"else",
"{",
"p1",
"=",
"boundary",
".",
"pointNearestToPoint",
"(",
"start",
")",
".",
"move",
"(",
"start",
",",
"1",
")",
";",
"}",
"p2",
"=",
"freeJoin",
"(",
"p1",
",",
"end",
",",
"boundary",
")",
";",
"if",
"(",
"p1",
".",
"round",
"(",
")",
".",
"equals",
"(",
"p2",
".",
"round",
"(",
")",
")",
")",
"{",
"p2",
"=",
"g",
".",
"Point",
".",
"fromPolar",
"(",
"boundary",
".",
"width",
"+",
"boundary",
".",
"height",
",",
"g",
".",
"toRad",
"(",
"p1",
".",
"theta",
"(",
"start",
")",
")",
"+",
"Math",
".",
"PI",
"/",
"2",
",",
"end",
")",
";",
"p2",
"=",
"boundary",
".",
"pointNearestToPoint",
"(",
"p2",
")",
".",
"move",
"(",
"end",
",",
"1",
")",
".",
"round",
"(",
")",
";",
"p3",
"=",
"freeJoin",
"(",
"p1",
",",
"p2",
",",
"boundary",
")",
";",
"route",
".",
"points",
"=",
"reversed",
"?",
"[",
"p2",
",",
"p3",
",",
"p1",
"]",
":",
"[",
"p1",
",",
"p3",
",",
"p2",
"]",
";",
"}",
"else",
"{",
"route",
".",
"points",
"=",
"reversed",
"?",
"[",
"p2",
",",
"p1",
"]",
":",
"[",
"p1",
",",
"p2",
"]",
";",
"}",
"route",
".",
"direction",
"=",
"reversed",
"?",
"getBearing",
"(",
"p1",
",",
"to",
")",
":",
"getBearing",
"(",
"p2",
",",
"to",
")",
";",
"return",
"route",
";",
"}"
] | Finds route for situations where one element is inside the other. Typically the route is directed outside the outer element first and then back towards the inner element. | [
"Finds",
"route",
"for",
"situations",
"where",
"one",
"element",
"is",
"inside",
"the",
"other",
".",
"Typically",
"the",
"route",
"is",
"directed",
"outside",
"the",
"outer",
"element",
"first",
"and",
"then",
"back",
"towards",
"the",
"inner",
"element",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L22640-L22677 |
7,828 | clientIO/joint | dist/joint.nowrap.js | router | function router(vertices, opt, linkView) {
var sourceBBox = getSourceBBox(linkView, opt);
var targetBBox = getTargetBBox(linkView, opt);
var sourceAnchor = getSourceAnchor(linkView, opt);
var targetAnchor = getTargetAnchor(linkView, opt);
// if anchor lies outside of bbox, the bbox expands to include it
sourceBBox = sourceBBox.union(getPointBox(sourceAnchor));
targetBBox = targetBBox.union(getPointBox(targetAnchor));
vertices = util.toArray(vertices).map(g.Point);
vertices.unshift(sourceAnchor);
vertices.push(targetAnchor);
var bearing; // bearing of previous route segment
var orthogonalVertices = []; // the array of found orthogonal vertices to be returned
for (var i = 0, max = vertices.length - 1; i < max; i++) {
var route = null;
var from = vertices[i];
var to = vertices[i + 1];
var isOrthogonal = !!getBearing(from, to);
if (i === 0) { // source
if (i + 1 === max) { // route source -> target
// Expand one of the elements by 1px to detect situations when the two
// elements are positioned next to each other with no gap in between.
if (sourceBBox.intersect(targetBBox.clone().inflate(1))) {
route = insideElement(from, to, sourceBBox, targetBBox);
} else if (!isOrthogonal) {
route = elementElement(from, to, sourceBBox, targetBBox);
}
} else { // route source -> vertex
if (sourceBBox.containsPoint(to)) {
route = insideElement(from, to, sourceBBox, getPointBox(to).moveAndExpand(getPaddingBox(opt)));
} else if (!isOrthogonal) {
route = elementVertex(from, to, sourceBBox);
}
}
} else if (i + 1 === max) { // route vertex -> target
// prevent overlaps with previous line segment
var isOrthogonalLoop = isOrthogonal && getBearing(to, from) === bearing;
if (targetBBox.containsPoint(from) || isOrthogonalLoop) {
route = insideElement(from, to, getPointBox(from).moveAndExpand(getPaddingBox(opt)), targetBBox, bearing);
} else if (!isOrthogonal) {
route = vertexElement(from, to, targetBBox, bearing);
}
} else if (!isOrthogonal) { // route vertex -> vertex
route = vertexVertex(from, to, bearing);
}
// applicable to all routes:
// set bearing for next iteration
if (route) {
Array.prototype.push.apply(orthogonalVertices, route.points);
bearing = route.direction;
} else {
// orthogonal route and not looped
bearing = getBearing(from, to);
}
// push `to` point to identified orthogonal vertices array
if (i + 1 < max) {
orthogonalVertices.push(to);
}
}
return orthogonalVertices;
} | javascript | function router(vertices, opt, linkView) {
var sourceBBox = getSourceBBox(linkView, opt);
var targetBBox = getTargetBBox(linkView, opt);
var sourceAnchor = getSourceAnchor(linkView, opt);
var targetAnchor = getTargetAnchor(linkView, opt);
// if anchor lies outside of bbox, the bbox expands to include it
sourceBBox = sourceBBox.union(getPointBox(sourceAnchor));
targetBBox = targetBBox.union(getPointBox(targetAnchor));
vertices = util.toArray(vertices).map(g.Point);
vertices.unshift(sourceAnchor);
vertices.push(targetAnchor);
var bearing; // bearing of previous route segment
var orthogonalVertices = []; // the array of found orthogonal vertices to be returned
for (var i = 0, max = vertices.length - 1; i < max; i++) {
var route = null;
var from = vertices[i];
var to = vertices[i + 1];
var isOrthogonal = !!getBearing(from, to);
if (i === 0) { // source
if (i + 1 === max) { // route source -> target
// Expand one of the elements by 1px to detect situations when the two
// elements are positioned next to each other with no gap in between.
if (sourceBBox.intersect(targetBBox.clone().inflate(1))) {
route = insideElement(from, to, sourceBBox, targetBBox);
} else if (!isOrthogonal) {
route = elementElement(from, to, sourceBBox, targetBBox);
}
} else { // route source -> vertex
if (sourceBBox.containsPoint(to)) {
route = insideElement(from, to, sourceBBox, getPointBox(to).moveAndExpand(getPaddingBox(opt)));
} else if (!isOrthogonal) {
route = elementVertex(from, to, sourceBBox);
}
}
} else if (i + 1 === max) { // route vertex -> target
// prevent overlaps with previous line segment
var isOrthogonalLoop = isOrthogonal && getBearing(to, from) === bearing;
if (targetBBox.containsPoint(from) || isOrthogonalLoop) {
route = insideElement(from, to, getPointBox(from).moveAndExpand(getPaddingBox(opt)), targetBBox, bearing);
} else if (!isOrthogonal) {
route = vertexElement(from, to, targetBBox, bearing);
}
} else if (!isOrthogonal) { // route vertex -> vertex
route = vertexVertex(from, to, bearing);
}
// applicable to all routes:
// set bearing for next iteration
if (route) {
Array.prototype.push.apply(orthogonalVertices, route.points);
bearing = route.direction;
} else {
// orthogonal route and not looped
bearing = getBearing(from, to);
}
// push `to` point to identified orthogonal vertices array
if (i + 1 < max) {
orthogonalVertices.push(to);
}
}
return orthogonalVertices;
} | [
"function",
"router",
"(",
"vertices",
",",
"opt",
",",
"linkView",
")",
"{",
"var",
"sourceBBox",
"=",
"getSourceBBox",
"(",
"linkView",
",",
"opt",
")",
";",
"var",
"targetBBox",
"=",
"getTargetBBox",
"(",
"linkView",
",",
"opt",
")",
";",
"var",
"sourceAnchor",
"=",
"getSourceAnchor",
"(",
"linkView",
",",
"opt",
")",
";",
"var",
"targetAnchor",
"=",
"getTargetAnchor",
"(",
"linkView",
",",
"opt",
")",
";",
"// if anchor lies outside of bbox, the bbox expands to include it",
"sourceBBox",
"=",
"sourceBBox",
".",
"union",
"(",
"getPointBox",
"(",
"sourceAnchor",
")",
")",
";",
"targetBBox",
"=",
"targetBBox",
".",
"union",
"(",
"getPointBox",
"(",
"targetAnchor",
")",
")",
";",
"vertices",
"=",
"util",
".",
"toArray",
"(",
"vertices",
")",
".",
"map",
"(",
"g",
".",
"Point",
")",
";",
"vertices",
".",
"unshift",
"(",
"sourceAnchor",
")",
";",
"vertices",
".",
"push",
"(",
"targetAnchor",
")",
";",
"var",
"bearing",
";",
"// bearing of previous route segment",
"var",
"orthogonalVertices",
"=",
"[",
"]",
";",
"// the array of found orthogonal vertices to be returned",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"max",
"=",
"vertices",
".",
"length",
"-",
"1",
";",
"i",
"<",
"max",
";",
"i",
"++",
")",
"{",
"var",
"route",
"=",
"null",
";",
"var",
"from",
"=",
"vertices",
"[",
"i",
"]",
";",
"var",
"to",
"=",
"vertices",
"[",
"i",
"+",
"1",
"]",
";",
"var",
"isOrthogonal",
"=",
"!",
"!",
"getBearing",
"(",
"from",
",",
"to",
")",
";",
"if",
"(",
"i",
"===",
"0",
")",
"{",
"// source",
"if",
"(",
"i",
"+",
"1",
"===",
"max",
")",
"{",
"// route source -> target",
"// Expand one of the elements by 1px to detect situations when the two",
"// elements are positioned next to each other with no gap in between.",
"if",
"(",
"sourceBBox",
".",
"intersect",
"(",
"targetBBox",
".",
"clone",
"(",
")",
".",
"inflate",
"(",
"1",
")",
")",
")",
"{",
"route",
"=",
"insideElement",
"(",
"from",
",",
"to",
",",
"sourceBBox",
",",
"targetBBox",
")",
";",
"}",
"else",
"if",
"(",
"!",
"isOrthogonal",
")",
"{",
"route",
"=",
"elementElement",
"(",
"from",
",",
"to",
",",
"sourceBBox",
",",
"targetBBox",
")",
";",
"}",
"}",
"else",
"{",
"// route source -> vertex",
"if",
"(",
"sourceBBox",
".",
"containsPoint",
"(",
"to",
")",
")",
"{",
"route",
"=",
"insideElement",
"(",
"from",
",",
"to",
",",
"sourceBBox",
",",
"getPointBox",
"(",
"to",
")",
".",
"moveAndExpand",
"(",
"getPaddingBox",
"(",
"opt",
")",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"isOrthogonal",
")",
"{",
"route",
"=",
"elementVertex",
"(",
"from",
",",
"to",
",",
"sourceBBox",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"i",
"+",
"1",
"===",
"max",
")",
"{",
"// route vertex -> target",
"// prevent overlaps with previous line segment",
"var",
"isOrthogonalLoop",
"=",
"isOrthogonal",
"&&",
"getBearing",
"(",
"to",
",",
"from",
")",
"===",
"bearing",
";",
"if",
"(",
"targetBBox",
".",
"containsPoint",
"(",
"from",
")",
"||",
"isOrthogonalLoop",
")",
"{",
"route",
"=",
"insideElement",
"(",
"from",
",",
"to",
",",
"getPointBox",
"(",
"from",
")",
".",
"moveAndExpand",
"(",
"getPaddingBox",
"(",
"opt",
")",
")",
",",
"targetBBox",
",",
"bearing",
")",
";",
"}",
"else",
"if",
"(",
"!",
"isOrthogonal",
")",
"{",
"route",
"=",
"vertexElement",
"(",
"from",
",",
"to",
",",
"targetBBox",
",",
"bearing",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"isOrthogonal",
")",
"{",
"// route vertex -> vertex",
"route",
"=",
"vertexVertex",
"(",
"from",
",",
"to",
",",
"bearing",
")",
";",
"}",
"// applicable to all routes:",
"// set bearing for next iteration",
"if",
"(",
"route",
")",
"{",
"Array",
".",
"prototype",
".",
"push",
".",
"apply",
"(",
"orthogonalVertices",
",",
"route",
".",
"points",
")",
";",
"bearing",
"=",
"route",
".",
"direction",
";",
"}",
"else",
"{",
"// orthogonal route and not looped",
"bearing",
"=",
"getBearing",
"(",
"from",
",",
"to",
")",
";",
"}",
"// push `to` point to identified orthogonal vertices array",
"if",
"(",
"i",
"+",
"1",
"<",
"max",
")",
"{",
"orthogonalVertices",
".",
"push",
"(",
"to",
")",
";",
"}",
"}",
"return",
"orthogonalVertices",
";",
"}"
] | Return points through which a connection needs to be drawn in order to obtain an orthogonal link routing from source to target going through `vertices`. | [
"Return",
"points",
"through",
"which",
"a",
"connection",
"needs",
"to",
"be",
"drawn",
"in",
"order",
"to",
"obtain",
"an",
"orthogonal",
"link",
"routing",
"from",
"source",
"to",
"target",
"going",
"through",
"vertices",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L22683-L22769 |
7,829 | clientIO/joint | dist/joint.nowrap.js | modelCenter | function modelCenter(view, magnet) {
var model = view.model;
var bbox = model.getBBox();
var center = bbox.center();
var angle = model.angle();
var portId = view.findAttribute('port', magnet);
if (portId) {
var portGroup = model.portProp(portId, 'group');
var portsPositions = model.getPortsPositions(portGroup);
var anchor = new g.Point(portsPositions[portId]).offset(bbox.origin());
anchor.rotate(center, -angle);
return anchor;
}
return center;
} | javascript | function modelCenter(view, magnet) {
var model = view.model;
var bbox = model.getBBox();
var center = bbox.center();
var angle = model.angle();
var portId = view.findAttribute('port', magnet);
if (portId) {
var portGroup = model.portProp(portId, 'group');
var portsPositions = model.getPortsPositions(portGroup);
var anchor = new g.Point(portsPositions[portId]).offset(bbox.origin());
anchor.rotate(center, -angle);
return anchor;
}
return center;
} | [
"function",
"modelCenter",
"(",
"view",
",",
"magnet",
")",
"{",
"var",
"model",
"=",
"view",
".",
"model",
";",
"var",
"bbox",
"=",
"model",
".",
"getBBox",
"(",
")",
";",
"var",
"center",
"=",
"bbox",
".",
"center",
"(",
")",
";",
"var",
"angle",
"=",
"model",
".",
"angle",
"(",
")",
";",
"var",
"portId",
"=",
"view",
".",
"findAttribute",
"(",
"'port'",
",",
"magnet",
")",
";",
"if",
"(",
"portId",
")",
"{",
"var",
"portGroup",
"=",
"model",
".",
"portProp",
"(",
"portId",
",",
"'group'",
")",
";",
"var",
"portsPositions",
"=",
"model",
".",
"getPortsPositions",
"(",
"portGroup",
")",
";",
"var",
"anchor",
"=",
"new",
"g",
".",
"Point",
"(",
"portsPositions",
"[",
"portId",
"]",
")",
".",
"offset",
"(",
"bbox",
".",
"origin",
"(",
")",
")",
";",
"anchor",
".",
"rotate",
"(",
"center",
",",
"-",
"angle",
")",
";",
"return",
"anchor",
";",
"}",
"return",
"center",
";",
"}"
] | Can find anchor from model, when there is no selector or the link end is connected to a port | [
"Can",
"find",
"anchor",
"from",
"model",
"when",
"there",
"is",
"no",
"selector",
"or",
"the",
"link",
"end",
"is",
"connected",
"to",
"a",
"port"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/dist/joint.nowrap.js#L23945-L23962 |
7,830 | clientIO/joint | tutorials/js/pipes.js | function(ctx, from, to, width, gradient) {
var innerWidth = width - 4;
var outerWidth = width;
var buttFrom = g.point(from).move(to, -outerWidth / 2);
var buttTo = g.point(to).move(from, -outerWidth / 2);
ctx.beginPath();
ctx.lineWidth = outerWidth;
ctx.strokeStyle = 'rgba(0,0,0,0.6)';
ctx.moveTo(from.x, from.y);
ctx.lineTo(to.x, to.y);
ctx.stroke();
ctx.closePath();
gradient.addColorStop(0.000, 'rgba(86, 170, 255, 1)');
gradient.addColorStop(0.500, 'rgba(255, 255, 255, 1)');
gradient.addColorStop(1.000, 'rgba(86, 170, 255, 1)');
ctx.beginPath();
ctx.lineWidth = innerWidth;
ctx.strokeStyle = gradient;
ctx.moveTo(from.x, from.y);
ctx.lineTo(to.x, to.y);
ctx.stroke();
ctx.closePath();
ctx.lineCap = "square";
ctx.beginPath();
ctx.lineWidth = innerWidth;
ctx.strokeStyle = 'rgba(0,0,0,0.5)';
ctx.moveTo(from.x, from.y);
ctx.lineTo(buttFrom.x, buttFrom.y);
ctx.stroke();
ctx.closePath();
ctx.beginPath();
ctx.lineWidth = innerWidth;
ctx.strokeStyle = 'rgba(0,0,0,0.5)';
ctx.moveTo(to.x, to.y);
ctx.lineTo(buttTo.x, buttTo.y);
ctx.stroke();
ctx.closePath();
} | javascript | function(ctx, from, to, width, gradient) {
var innerWidth = width - 4;
var outerWidth = width;
var buttFrom = g.point(from).move(to, -outerWidth / 2);
var buttTo = g.point(to).move(from, -outerWidth / 2);
ctx.beginPath();
ctx.lineWidth = outerWidth;
ctx.strokeStyle = 'rgba(0,0,0,0.6)';
ctx.moveTo(from.x, from.y);
ctx.lineTo(to.x, to.y);
ctx.stroke();
ctx.closePath();
gradient.addColorStop(0.000, 'rgba(86, 170, 255, 1)');
gradient.addColorStop(0.500, 'rgba(255, 255, 255, 1)');
gradient.addColorStop(1.000, 'rgba(86, 170, 255, 1)');
ctx.beginPath();
ctx.lineWidth = innerWidth;
ctx.strokeStyle = gradient;
ctx.moveTo(from.x, from.y);
ctx.lineTo(to.x, to.y);
ctx.stroke();
ctx.closePath();
ctx.lineCap = "square";
ctx.beginPath();
ctx.lineWidth = innerWidth;
ctx.strokeStyle = 'rgba(0,0,0,0.5)';
ctx.moveTo(from.x, from.y);
ctx.lineTo(buttFrom.x, buttFrom.y);
ctx.stroke();
ctx.closePath();
ctx.beginPath();
ctx.lineWidth = innerWidth;
ctx.strokeStyle = 'rgba(0,0,0,0.5)';
ctx.moveTo(to.x, to.y);
ctx.lineTo(buttTo.x, buttTo.y);
ctx.stroke();
ctx.closePath();
} | [
"function",
"(",
"ctx",
",",
"from",
",",
"to",
",",
"width",
",",
"gradient",
")",
"{",
"var",
"innerWidth",
"=",
"width",
"-",
"4",
";",
"var",
"outerWidth",
"=",
"width",
";",
"var",
"buttFrom",
"=",
"g",
".",
"point",
"(",
"from",
")",
".",
"move",
"(",
"to",
",",
"-",
"outerWidth",
"/",
"2",
")",
";",
"var",
"buttTo",
"=",
"g",
".",
"point",
"(",
"to",
")",
".",
"move",
"(",
"from",
",",
"-",
"outerWidth",
"/",
"2",
")",
";",
"ctx",
".",
"beginPath",
"(",
")",
";",
"ctx",
".",
"lineWidth",
"=",
"outerWidth",
";",
"ctx",
".",
"strokeStyle",
"=",
"'rgba(0,0,0,0.6)'",
";",
"ctx",
".",
"moveTo",
"(",
"from",
".",
"x",
",",
"from",
".",
"y",
")",
";",
"ctx",
".",
"lineTo",
"(",
"to",
".",
"x",
",",
"to",
".",
"y",
")",
";",
"ctx",
".",
"stroke",
"(",
")",
";",
"ctx",
".",
"closePath",
"(",
")",
";",
"gradient",
".",
"addColorStop",
"(",
"0.000",
",",
"'rgba(86, 170, 255, 1)'",
")",
";",
"gradient",
".",
"addColorStop",
"(",
"0.500",
",",
"'rgba(255, 255, 255, 1)'",
")",
";",
"gradient",
".",
"addColorStop",
"(",
"1.000",
",",
"'rgba(86, 170, 255, 1)'",
")",
";",
"ctx",
".",
"beginPath",
"(",
")",
";",
"ctx",
".",
"lineWidth",
"=",
"innerWidth",
";",
"ctx",
".",
"strokeStyle",
"=",
"gradient",
";",
"ctx",
".",
"moveTo",
"(",
"from",
".",
"x",
",",
"from",
".",
"y",
")",
";",
"ctx",
".",
"lineTo",
"(",
"to",
".",
"x",
",",
"to",
".",
"y",
")",
";",
"ctx",
".",
"stroke",
"(",
")",
";",
"ctx",
".",
"closePath",
"(",
")",
";",
"ctx",
".",
"lineCap",
"=",
"\"square\"",
";",
"ctx",
".",
"beginPath",
"(",
")",
";",
"ctx",
".",
"lineWidth",
"=",
"innerWidth",
";",
"ctx",
".",
"strokeStyle",
"=",
"'rgba(0,0,0,0.5)'",
";",
"ctx",
".",
"moveTo",
"(",
"from",
".",
"x",
",",
"from",
".",
"y",
")",
";",
"ctx",
".",
"lineTo",
"(",
"buttFrom",
".",
"x",
",",
"buttFrom",
".",
"y",
")",
";",
"ctx",
".",
"stroke",
"(",
")",
";",
"ctx",
".",
"closePath",
"(",
")",
";",
"ctx",
".",
"beginPath",
"(",
")",
";",
"ctx",
".",
"lineWidth",
"=",
"innerWidth",
";",
"ctx",
".",
"strokeStyle",
"=",
"'rgba(0,0,0,0.5)'",
";",
"ctx",
".",
"moveTo",
"(",
"to",
".",
"x",
",",
"to",
".",
"y",
")",
";",
"ctx",
".",
"lineTo",
"(",
"buttTo",
".",
"x",
",",
"buttTo",
".",
"y",
")",
";",
"ctx",
".",
"stroke",
"(",
")",
";",
"ctx",
".",
"closePath",
"(",
")",
";",
"}"
] | A drawing function executed for all links segments. | [
"A",
"drawing",
"function",
"executed",
"for",
"all",
"links",
"segments",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/tutorials/js/pipes.js#L143-L189 |
|
7,831 | clientIO/joint | demo/chess/src/garbochess.js | SeeAddKnightAttacks | function SeeAddKnightAttacks(target, us, attacks) {
var pieceIdx = (us | pieceKnight) << 4;
var attackerSq = g_pieceList[pieceIdx++];
while (attackerSq != 0) {
if (IsSquareOnPieceLine(target, attackerSq)) {
attacks[attacks.length] = attackerSq;
}
attackerSq = g_pieceList[pieceIdx++];
}
} | javascript | function SeeAddKnightAttacks(target, us, attacks) {
var pieceIdx = (us | pieceKnight) << 4;
var attackerSq = g_pieceList[pieceIdx++];
while (attackerSq != 0) {
if (IsSquareOnPieceLine(target, attackerSq)) {
attacks[attacks.length] = attackerSq;
}
attackerSq = g_pieceList[pieceIdx++];
}
} | [
"function",
"SeeAddKnightAttacks",
"(",
"target",
",",
"us",
",",
"attacks",
")",
"{",
"var",
"pieceIdx",
"=",
"(",
"us",
"|",
"pieceKnight",
")",
"<<",
"4",
";",
"var",
"attackerSq",
"=",
"g_pieceList",
"[",
"pieceIdx",
"++",
"]",
";",
"while",
"(",
"attackerSq",
"!=",
"0",
")",
"{",
"if",
"(",
"IsSquareOnPieceLine",
"(",
"target",
",",
"attackerSq",
")",
")",
"{",
"attacks",
"[",
"attacks",
".",
"length",
"]",
"=",
"attackerSq",
";",
"}",
"attackerSq",
"=",
"g_pieceList",
"[",
"pieceIdx",
"++",
"]",
";",
"}",
"}"
] | target = attacking square, us = color of knights to look for, attacks = array to add squares to | [
"target",
"=",
"attacking",
"square",
"us",
"=",
"color",
"of",
"knights",
"to",
"look",
"for",
"attacks",
"=",
"array",
"to",
"add",
"squares",
"to"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/demo/chess/src/garbochess.js#L2446-L2456 |
7,832 | clientIO/joint | src/geometry.js | function(p, opt) {
opt = opt || {};
var precision = (opt.precision === undefined) ? this.PRECISION : opt.precision;
var subdivisions = (opt.subdivisions === undefined) ? this.getSubdivisions({ precision: precision }) : opt.subdivisions;
// does not use localOpt
// identify the subdivision that contains the point:
var investigatedSubdivision;
var investigatedSubdivisionStartT; // assume that subdivisions are evenly spaced
var investigatedSubdivisionEndT;
var distFromStart; // distance of point from start of baseline
var distFromEnd; // distance of point from end of baseline
var chordLength; // distance between start and end of the subdivision
var minSumDist; // lowest observed sum of the two distances
var n = subdivisions.length;
var subdivisionSize = (n ? (1 / n) : 0);
for (var i = 0; i < n; i++) {
var currentSubdivision = subdivisions[i];
var startDist = currentSubdivision.start.distance(p);
var endDist = currentSubdivision.end.distance(p);
var sumDist = startDist + endDist;
// check that the point is closest to current subdivision and not any other
if (!minSumDist || (sumDist < minSumDist)) {
investigatedSubdivision = currentSubdivision;
investigatedSubdivisionStartT = i * subdivisionSize;
investigatedSubdivisionEndT = (i + 1) * subdivisionSize;
distFromStart = startDist;
distFromEnd = endDist;
chordLength = currentSubdivision.start.distance(currentSubdivision.end);
minSumDist = sumDist;
}
}
var precisionRatio = pow(10, -precision);
// recursively divide investigated subdivision:
// until distance between baselinePoint and closest path endpoint is within 10^(-precision)
// then return the closest endpoint of that final subdivision
while (true) {
// check if we have reached at least one required observed precision
// - calculated as: the difference in distances from point to start and end divided by the distance
// - note that this function is not monotonic = it doesn't converge stably but has "teeth"
// - the function decreases while one of the endpoints is fixed but "jumps" whenever we switch
// - this criterion works well for points lying far away from the curve
var startPrecisionRatio = (distFromStart ? (abs(distFromStart - distFromEnd) / distFromStart) : 0);
var endPrecisionRatio = (distFromEnd ? (abs(distFromStart - distFromEnd) / distFromEnd) : 0);
var hasRequiredPrecision = ((startPrecisionRatio < precisionRatio) || (endPrecisionRatio < precisionRatio));
// check if we have reached at least one required minimal distance
// - calculated as: the subdivision chord length multiplied by precisionRatio
// - calculation is relative so it will work for arbitrarily large/small curves and their subdivisions
// - this is a backup criterion that works well for points lying "almost at" the curve
var hasMinimalStartDistance = (distFromStart ? (distFromStart < (chordLength * precisionRatio)) : true);
var hasMinimalEndDistance = (distFromEnd ? (distFromEnd < (chordLength * precisionRatio)) : true);
var hasMinimalDistance = (hasMinimalStartDistance || hasMinimalEndDistance);
// do we stop now?
if (hasRequiredPrecision || hasMinimalDistance) {
return ((distFromStart <= distFromEnd) ? investigatedSubdivisionStartT : investigatedSubdivisionEndT);
}
// otherwise, set up for next iteration
var divided = investigatedSubdivision.divide(0.5);
subdivisionSize /= 2;
var startDist1 = divided[0].start.distance(p);
var endDist1 = divided[0].end.distance(p);
var sumDist1 = startDist1 + endDist1;
var startDist2 = divided[1].start.distance(p);
var endDist2 = divided[1].end.distance(p);
var sumDist2 = startDist2 + endDist2;
if (sumDist1 <= sumDist2) {
investigatedSubdivision = divided[0];
investigatedSubdivisionEndT -= subdivisionSize; // subdivisionSize was already halved
distFromStart = startDist1;
distFromEnd = endDist1;
} else {
investigatedSubdivision = divided[1];
investigatedSubdivisionStartT += subdivisionSize; // subdivisionSize was already halved
distFromStart = startDist2;
distFromEnd = endDist2;
}
}
} | javascript | function(p, opt) {
opt = opt || {};
var precision = (opt.precision === undefined) ? this.PRECISION : opt.precision;
var subdivisions = (opt.subdivisions === undefined) ? this.getSubdivisions({ precision: precision }) : opt.subdivisions;
// does not use localOpt
// identify the subdivision that contains the point:
var investigatedSubdivision;
var investigatedSubdivisionStartT; // assume that subdivisions are evenly spaced
var investigatedSubdivisionEndT;
var distFromStart; // distance of point from start of baseline
var distFromEnd; // distance of point from end of baseline
var chordLength; // distance between start and end of the subdivision
var minSumDist; // lowest observed sum of the two distances
var n = subdivisions.length;
var subdivisionSize = (n ? (1 / n) : 0);
for (var i = 0; i < n; i++) {
var currentSubdivision = subdivisions[i];
var startDist = currentSubdivision.start.distance(p);
var endDist = currentSubdivision.end.distance(p);
var sumDist = startDist + endDist;
// check that the point is closest to current subdivision and not any other
if (!minSumDist || (sumDist < minSumDist)) {
investigatedSubdivision = currentSubdivision;
investigatedSubdivisionStartT = i * subdivisionSize;
investigatedSubdivisionEndT = (i + 1) * subdivisionSize;
distFromStart = startDist;
distFromEnd = endDist;
chordLength = currentSubdivision.start.distance(currentSubdivision.end);
minSumDist = sumDist;
}
}
var precisionRatio = pow(10, -precision);
// recursively divide investigated subdivision:
// until distance between baselinePoint and closest path endpoint is within 10^(-precision)
// then return the closest endpoint of that final subdivision
while (true) {
// check if we have reached at least one required observed precision
// - calculated as: the difference in distances from point to start and end divided by the distance
// - note that this function is not monotonic = it doesn't converge stably but has "teeth"
// - the function decreases while one of the endpoints is fixed but "jumps" whenever we switch
// - this criterion works well for points lying far away from the curve
var startPrecisionRatio = (distFromStart ? (abs(distFromStart - distFromEnd) / distFromStart) : 0);
var endPrecisionRatio = (distFromEnd ? (abs(distFromStart - distFromEnd) / distFromEnd) : 0);
var hasRequiredPrecision = ((startPrecisionRatio < precisionRatio) || (endPrecisionRatio < precisionRatio));
// check if we have reached at least one required minimal distance
// - calculated as: the subdivision chord length multiplied by precisionRatio
// - calculation is relative so it will work for arbitrarily large/small curves and their subdivisions
// - this is a backup criterion that works well for points lying "almost at" the curve
var hasMinimalStartDistance = (distFromStart ? (distFromStart < (chordLength * precisionRatio)) : true);
var hasMinimalEndDistance = (distFromEnd ? (distFromEnd < (chordLength * precisionRatio)) : true);
var hasMinimalDistance = (hasMinimalStartDistance || hasMinimalEndDistance);
// do we stop now?
if (hasRequiredPrecision || hasMinimalDistance) {
return ((distFromStart <= distFromEnd) ? investigatedSubdivisionStartT : investigatedSubdivisionEndT);
}
// otherwise, set up for next iteration
var divided = investigatedSubdivision.divide(0.5);
subdivisionSize /= 2;
var startDist1 = divided[0].start.distance(p);
var endDist1 = divided[0].end.distance(p);
var sumDist1 = startDist1 + endDist1;
var startDist2 = divided[1].start.distance(p);
var endDist2 = divided[1].end.distance(p);
var sumDist2 = startDist2 + endDist2;
if (sumDist1 <= sumDist2) {
investigatedSubdivision = divided[0];
investigatedSubdivisionEndT -= subdivisionSize; // subdivisionSize was already halved
distFromStart = startDist1;
distFromEnd = endDist1;
} else {
investigatedSubdivision = divided[1];
investigatedSubdivisionStartT += subdivisionSize; // subdivisionSize was already halved
distFromStart = startDist2;
distFromEnd = endDist2;
}
}
} | [
"function",
"(",
"p",
",",
"opt",
")",
"{",
"opt",
"=",
"opt",
"||",
"{",
"}",
";",
"var",
"precision",
"=",
"(",
"opt",
".",
"precision",
"===",
"undefined",
")",
"?",
"this",
".",
"PRECISION",
":",
"opt",
".",
"precision",
";",
"var",
"subdivisions",
"=",
"(",
"opt",
".",
"subdivisions",
"===",
"undefined",
")",
"?",
"this",
".",
"getSubdivisions",
"(",
"{",
"precision",
":",
"precision",
"}",
")",
":",
"opt",
".",
"subdivisions",
";",
"// does not use localOpt",
"// identify the subdivision that contains the point:",
"var",
"investigatedSubdivision",
";",
"var",
"investigatedSubdivisionStartT",
";",
"// assume that subdivisions are evenly spaced",
"var",
"investigatedSubdivisionEndT",
";",
"var",
"distFromStart",
";",
"// distance of point from start of baseline",
"var",
"distFromEnd",
";",
"// distance of point from end of baseline",
"var",
"chordLength",
";",
"// distance between start and end of the subdivision",
"var",
"minSumDist",
";",
"// lowest observed sum of the two distances",
"var",
"n",
"=",
"subdivisions",
".",
"length",
";",
"var",
"subdivisionSize",
"=",
"(",
"n",
"?",
"(",
"1",
"/",
"n",
")",
":",
"0",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"var",
"currentSubdivision",
"=",
"subdivisions",
"[",
"i",
"]",
";",
"var",
"startDist",
"=",
"currentSubdivision",
".",
"start",
".",
"distance",
"(",
"p",
")",
";",
"var",
"endDist",
"=",
"currentSubdivision",
".",
"end",
".",
"distance",
"(",
"p",
")",
";",
"var",
"sumDist",
"=",
"startDist",
"+",
"endDist",
";",
"// check that the point is closest to current subdivision and not any other",
"if",
"(",
"!",
"minSumDist",
"||",
"(",
"sumDist",
"<",
"minSumDist",
")",
")",
"{",
"investigatedSubdivision",
"=",
"currentSubdivision",
";",
"investigatedSubdivisionStartT",
"=",
"i",
"*",
"subdivisionSize",
";",
"investigatedSubdivisionEndT",
"=",
"(",
"i",
"+",
"1",
")",
"*",
"subdivisionSize",
";",
"distFromStart",
"=",
"startDist",
";",
"distFromEnd",
"=",
"endDist",
";",
"chordLength",
"=",
"currentSubdivision",
".",
"start",
".",
"distance",
"(",
"currentSubdivision",
".",
"end",
")",
";",
"minSumDist",
"=",
"sumDist",
";",
"}",
"}",
"var",
"precisionRatio",
"=",
"pow",
"(",
"10",
",",
"-",
"precision",
")",
";",
"// recursively divide investigated subdivision:",
"// until distance between baselinePoint and closest path endpoint is within 10^(-precision)",
"// then return the closest endpoint of that final subdivision",
"while",
"(",
"true",
")",
"{",
"// check if we have reached at least one required observed precision",
"// - calculated as: the difference in distances from point to start and end divided by the distance",
"// - note that this function is not monotonic = it doesn't converge stably but has \"teeth\"",
"// - the function decreases while one of the endpoints is fixed but \"jumps\" whenever we switch",
"// - this criterion works well for points lying far away from the curve",
"var",
"startPrecisionRatio",
"=",
"(",
"distFromStart",
"?",
"(",
"abs",
"(",
"distFromStart",
"-",
"distFromEnd",
")",
"/",
"distFromStart",
")",
":",
"0",
")",
";",
"var",
"endPrecisionRatio",
"=",
"(",
"distFromEnd",
"?",
"(",
"abs",
"(",
"distFromStart",
"-",
"distFromEnd",
")",
"/",
"distFromEnd",
")",
":",
"0",
")",
";",
"var",
"hasRequiredPrecision",
"=",
"(",
"(",
"startPrecisionRatio",
"<",
"precisionRatio",
")",
"||",
"(",
"endPrecisionRatio",
"<",
"precisionRatio",
")",
")",
";",
"// check if we have reached at least one required minimal distance",
"// - calculated as: the subdivision chord length multiplied by precisionRatio",
"// - calculation is relative so it will work for arbitrarily large/small curves and their subdivisions",
"// - this is a backup criterion that works well for points lying \"almost at\" the curve",
"var",
"hasMinimalStartDistance",
"=",
"(",
"distFromStart",
"?",
"(",
"distFromStart",
"<",
"(",
"chordLength",
"*",
"precisionRatio",
")",
")",
":",
"true",
")",
";",
"var",
"hasMinimalEndDistance",
"=",
"(",
"distFromEnd",
"?",
"(",
"distFromEnd",
"<",
"(",
"chordLength",
"*",
"precisionRatio",
")",
")",
":",
"true",
")",
";",
"var",
"hasMinimalDistance",
"=",
"(",
"hasMinimalStartDistance",
"||",
"hasMinimalEndDistance",
")",
";",
"// do we stop now?",
"if",
"(",
"hasRequiredPrecision",
"||",
"hasMinimalDistance",
")",
"{",
"return",
"(",
"(",
"distFromStart",
"<=",
"distFromEnd",
")",
"?",
"investigatedSubdivisionStartT",
":",
"investigatedSubdivisionEndT",
")",
";",
"}",
"// otherwise, set up for next iteration",
"var",
"divided",
"=",
"investigatedSubdivision",
".",
"divide",
"(",
"0.5",
")",
";",
"subdivisionSize",
"/=",
"2",
";",
"var",
"startDist1",
"=",
"divided",
"[",
"0",
"]",
".",
"start",
".",
"distance",
"(",
"p",
")",
";",
"var",
"endDist1",
"=",
"divided",
"[",
"0",
"]",
".",
"end",
".",
"distance",
"(",
"p",
")",
";",
"var",
"sumDist1",
"=",
"startDist1",
"+",
"endDist1",
";",
"var",
"startDist2",
"=",
"divided",
"[",
"1",
"]",
".",
"start",
".",
"distance",
"(",
"p",
")",
";",
"var",
"endDist2",
"=",
"divided",
"[",
"1",
"]",
".",
"end",
".",
"distance",
"(",
"p",
")",
";",
"var",
"sumDist2",
"=",
"startDist2",
"+",
"endDist2",
";",
"if",
"(",
"sumDist1",
"<=",
"sumDist2",
")",
"{",
"investigatedSubdivision",
"=",
"divided",
"[",
"0",
"]",
";",
"investigatedSubdivisionEndT",
"-=",
"subdivisionSize",
";",
"// subdivisionSize was already halved",
"distFromStart",
"=",
"startDist1",
";",
"distFromEnd",
"=",
"endDist1",
";",
"}",
"else",
"{",
"investigatedSubdivision",
"=",
"divided",
"[",
"1",
"]",
";",
"investigatedSubdivisionStartT",
"+=",
"subdivisionSize",
";",
"// subdivisionSize was already halved",
"distFromStart",
"=",
"startDist2",
";",
"distFromEnd",
"=",
"endDist2",
";",
"}",
"}",
"}"
] | Returns `t` of the point on the curve closest to point `p` | [
"Returns",
"t",
"of",
"the",
"point",
"on",
"the",
"curve",
"closest",
"to",
"point",
"p"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/src/geometry.js#L484-L583 |
|
7,833 | clientIO/joint | src/geometry.js | function(p) {
var start = this.start;
var end = this.end;
if (start.cross(p, end) !== 0) return false;
// else: cross product of 0 indicates that this line and the vector to `p` are collinear
var length = this.length();
if ((new g.Line(start, p)).length() > length) return false;
if ((new g.Line(p, end)).length() > length) return false;
// else: `p` lies between start and end of the line
return true;
} | javascript | function(p) {
var start = this.start;
var end = this.end;
if (start.cross(p, end) !== 0) return false;
// else: cross product of 0 indicates that this line and the vector to `p` are collinear
var length = this.length();
if ((new g.Line(start, p)).length() > length) return false;
if ((new g.Line(p, end)).length() > length) return false;
// else: `p` lies between start and end of the line
return true;
} | [
"function",
"(",
"p",
")",
"{",
"var",
"start",
"=",
"this",
".",
"start",
";",
"var",
"end",
"=",
"this",
".",
"end",
";",
"if",
"(",
"start",
".",
"cross",
"(",
"p",
",",
"end",
")",
"!==",
"0",
")",
"return",
"false",
";",
"// else: cross product of 0 indicates that this line and the vector to `p` are collinear",
"var",
"length",
"=",
"this",
".",
"length",
"(",
")",
";",
"if",
"(",
"(",
"new",
"g",
".",
"Line",
"(",
"start",
",",
"p",
")",
")",
".",
"length",
"(",
")",
">",
"length",
")",
"return",
"false",
";",
"if",
"(",
"(",
"new",
"g",
".",
"Line",
"(",
"p",
",",
"end",
")",
")",
".",
"length",
"(",
")",
">",
"length",
")",
"return",
"false",
";",
"// else: `p` lies between start and end of the line",
"return",
"true",
";",
"}"
] | Returns `true` if the point lies on the line. | [
"Returns",
"true",
"if",
"the",
"point",
"lies",
"on",
"the",
"line",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/src/geometry.js#L1402-L1416 |
|
7,834 | clientIO/joint | src/geometry.js | function(ratio) {
var dividerPoint = this.pointAt(ratio);
// return array with two new lines
return [
new Line(this.start, dividerPoint),
new Line(dividerPoint, this.end)
];
} | javascript | function(ratio) {
var dividerPoint = this.pointAt(ratio);
// return array with two new lines
return [
new Line(this.start, dividerPoint),
new Line(dividerPoint, this.end)
];
} | [
"function",
"(",
"ratio",
")",
"{",
"var",
"dividerPoint",
"=",
"this",
".",
"pointAt",
"(",
"ratio",
")",
";",
"// return array with two new lines",
"return",
"[",
"new",
"Line",
"(",
"this",
".",
"start",
",",
"dividerPoint",
")",
",",
"new",
"Line",
"(",
"dividerPoint",
",",
"this",
".",
"end",
")",
"]",
";",
"}"
] | Divides the line into two at requested `ratio` between 0 and 1. | [
"Divides",
"the",
"line",
"into",
"two",
"at",
"requested",
"ratio",
"between",
"0",
"and",
"1",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/src/geometry.js#L1419-L1428 |
|
7,835 | clientIO/joint | src/geometry.js | function(length) {
var dividerPoint = this.pointAtLength(length);
// return array with two new lines
return [
new Line(this.start, dividerPoint),
new Line(dividerPoint, this.end)
];
} | javascript | function(length) {
var dividerPoint = this.pointAtLength(length);
// return array with two new lines
return [
new Line(this.start, dividerPoint),
new Line(dividerPoint, this.end)
];
} | [
"function",
"(",
"length",
")",
"{",
"var",
"dividerPoint",
"=",
"this",
".",
"pointAtLength",
"(",
"length",
")",
";",
"// return array with two new lines",
"return",
"[",
"new",
"Line",
"(",
"this",
".",
"start",
",",
"dividerPoint",
")",
",",
"new",
"Line",
"(",
"dividerPoint",
",",
"this",
".",
"end",
")",
"]",
";",
"}"
] | Divides the line into two at requested `length`. | [
"Divides",
"the",
"line",
"into",
"two",
"at",
"requested",
"length",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/src/geometry.js#L1431-L1440 |
|
7,836 | clientIO/joint | src/geometry.js | function(ratio, opt) {
var segments = this.segments;
var numSegments = segments.length;
if (numSegments === 0) return null; // if segments is an empty array
if (ratio < 0) ratio = 0;
if (ratio > 1) ratio = 1;
opt = opt || {};
var precision = (opt.precision === undefined) ? this.PRECISION : opt.precision;
var segmentSubdivisions = (opt.segmentSubdivisions === undefined) ? this.getSegmentSubdivisions({ precision: precision }) : opt.segmentSubdivisions;
var localOpt = { precision: precision, segmentSubdivisions: segmentSubdivisions };
var pathLength = this.length(localOpt);
var length = pathLength * ratio;
return this.divideAtLength(length, localOpt);
} | javascript | function(ratio, opt) {
var segments = this.segments;
var numSegments = segments.length;
if (numSegments === 0) return null; // if segments is an empty array
if (ratio < 0) ratio = 0;
if (ratio > 1) ratio = 1;
opt = opt || {};
var precision = (opt.precision === undefined) ? this.PRECISION : opt.precision;
var segmentSubdivisions = (opt.segmentSubdivisions === undefined) ? this.getSegmentSubdivisions({ precision: precision }) : opt.segmentSubdivisions;
var localOpt = { precision: precision, segmentSubdivisions: segmentSubdivisions };
var pathLength = this.length(localOpt);
var length = pathLength * ratio;
return this.divideAtLength(length, localOpt);
} | [
"function",
"(",
"ratio",
",",
"opt",
")",
"{",
"var",
"segments",
"=",
"this",
".",
"segments",
";",
"var",
"numSegments",
"=",
"segments",
".",
"length",
";",
"if",
"(",
"numSegments",
"===",
"0",
")",
"return",
"null",
";",
"// if segments is an empty array",
"if",
"(",
"ratio",
"<",
"0",
")",
"ratio",
"=",
"0",
";",
"if",
"(",
"ratio",
">",
"1",
")",
"ratio",
"=",
"1",
";",
"opt",
"=",
"opt",
"||",
"{",
"}",
";",
"var",
"precision",
"=",
"(",
"opt",
".",
"precision",
"===",
"undefined",
")",
"?",
"this",
".",
"PRECISION",
":",
"opt",
".",
"precision",
";",
"var",
"segmentSubdivisions",
"=",
"(",
"opt",
".",
"segmentSubdivisions",
"===",
"undefined",
")",
"?",
"this",
".",
"getSegmentSubdivisions",
"(",
"{",
"precision",
":",
"precision",
"}",
")",
":",
"opt",
".",
"segmentSubdivisions",
";",
"var",
"localOpt",
"=",
"{",
"precision",
":",
"precision",
",",
"segmentSubdivisions",
":",
"segmentSubdivisions",
"}",
";",
"var",
"pathLength",
"=",
"this",
".",
"length",
"(",
"localOpt",
")",
";",
"var",
"length",
"=",
"pathLength",
"*",
"ratio",
";",
"return",
"this",
".",
"divideAtLength",
"(",
"length",
",",
"localOpt",
")",
";",
"}"
] | Divides the path into two at requested `ratio` between 0 and 1 with precision better than `opt.precision`; optionally using `opt.subdivisions` provided. | [
"Divides",
"the",
"path",
"into",
"two",
"at",
"requested",
"ratio",
"between",
"0",
"and",
"1",
"with",
"precision",
"better",
"than",
"opt",
".",
"precision",
";",
"optionally",
"using",
"opt",
".",
"subdivisions",
"provided",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/src/geometry.js#L2027-L2045 |
|
7,837 | clientIO/joint | src/geometry.js | function(index, arg) {
var segments = this.segments;
var numSegments = segments.length;
if (numSegments === 0) throw new Error('Path has no segments.');
if (index < 0) index = numSegments + index; // convert negative indices to positive
if (index >= numSegments || index < 0) throw new Error('Index out of range.');
var currentSegment;
var replacedSegment = segments[index];
var previousSegment = replacedSegment.previousSegment;
var nextSegment = replacedSegment.nextSegment;
var updateSubpathStart = replacedSegment.isSubpathStart; // boolean: is an update of subpath starts necessary?
if (!Array.isArray(arg)) {
if (!arg || !arg.isSegment) throw new Error('Segment required.');
currentSegment = this.prepareSegment(arg, previousSegment, nextSegment);
segments.splice(index, 1, currentSegment); // directly replace
if (updateSubpathStart && currentSegment.isSubpathStart) updateSubpathStart = false; // already updated by `prepareSegment`
} else {
// flatten one level deep
// so we can chain arbitrary Path.createSegment results
arg = arg.reduce(function(acc, val) {
return acc.concat(val);
}, []);
if (!arg[0].isSegment) throw new Error('Segments required.');
segments.splice(index, 1);
var n = arg.length;
for (var i = 0; i < n; i++) {
var currentArg = arg[i];
currentSegment = this.prepareSegment(currentArg, previousSegment, nextSegment);
segments.splice((index + i), 0, currentSegment); // incrementing index to insert subsequent segments after inserted segments
previousSegment = currentSegment;
if (updateSubpathStart && currentSegment.isSubpathStart) updateSubpathStart = false; // already updated by `prepareSegment`
}
}
// if replaced segment used to start a subpath and no new subpath start was added, update all subsequent segments until another subpath start segment is reached
if (updateSubpathStart && nextSegment) this.updateSubpathStartSegment(nextSegment);
} | javascript | function(index, arg) {
var segments = this.segments;
var numSegments = segments.length;
if (numSegments === 0) throw new Error('Path has no segments.');
if (index < 0) index = numSegments + index; // convert negative indices to positive
if (index >= numSegments || index < 0) throw new Error('Index out of range.');
var currentSegment;
var replacedSegment = segments[index];
var previousSegment = replacedSegment.previousSegment;
var nextSegment = replacedSegment.nextSegment;
var updateSubpathStart = replacedSegment.isSubpathStart; // boolean: is an update of subpath starts necessary?
if (!Array.isArray(arg)) {
if (!arg || !arg.isSegment) throw new Error('Segment required.');
currentSegment = this.prepareSegment(arg, previousSegment, nextSegment);
segments.splice(index, 1, currentSegment); // directly replace
if (updateSubpathStart && currentSegment.isSubpathStart) updateSubpathStart = false; // already updated by `prepareSegment`
} else {
// flatten one level deep
// so we can chain arbitrary Path.createSegment results
arg = arg.reduce(function(acc, val) {
return acc.concat(val);
}, []);
if (!arg[0].isSegment) throw new Error('Segments required.');
segments.splice(index, 1);
var n = arg.length;
for (var i = 0; i < n; i++) {
var currentArg = arg[i];
currentSegment = this.prepareSegment(currentArg, previousSegment, nextSegment);
segments.splice((index + i), 0, currentSegment); // incrementing index to insert subsequent segments after inserted segments
previousSegment = currentSegment;
if (updateSubpathStart && currentSegment.isSubpathStart) updateSubpathStart = false; // already updated by `prepareSegment`
}
}
// if replaced segment used to start a subpath and no new subpath start was added, update all subsequent segments until another subpath start segment is reached
if (updateSubpathStart && nextSegment) this.updateSubpathStartSegment(nextSegment);
} | [
"function",
"(",
"index",
",",
"arg",
")",
"{",
"var",
"segments",
"=",
"this",
".",
"segments",
";",
"var",
"numSegments",
"=",
"segments",
".",
"length",
";",
"if",
"(",
"numSegments",
"===",
"0",
")",
"throw",
"new",
"Error",
"(",
"'Path has no segments.'",
")",
";",
"if",
"(",
"index",
"<",
"0",
")",
"index",
"=",
"numSegments",
"+",
"index",
";",
"// convert negative indices to positive",
"if",
"(",
"index",
">=",
"numSegments",
"||",
"index",
"<",
"0",
")",
"throw",
"new",
"Error",
"(",
"'Index out of range.'",
")",
";",
"var",
"currentSegment",
";",
"var",
"replacedSegment",
"=",
"segments",
"[",
"index",
"]",
";",
"var",
"previousSegment",
"=",
"replacedSegment",
".",
"previousSegment",
";",
"var",
"nextSegment",
"=",
"replacedSegment",
".",
"nextSegment",
";",
"var",
"updateSubpathStart",
"=",
"replacedSegment",
".",
"isSubpathStart",
";",
"// boolean: is an update of subpath starts necessary?",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"arg",
")",
")",
"{",
"if",
"(",
"!",
"arg",
"||",
"!",
"arg",
".",
"isSegment",
")",
"throw",
"new",
"Error",
"(",
"'Segment required.'",
")",
";",
"currentSegment",
"=",
"this",
".",
"prepareSegment",
"(",
"arg",
",",
"previousSegment",
",",
"nextSegment",
")",
";",
"segments",
".",
"splice",
"(",
"index",
",",
"1",
",",
"currentSegment",
")",
";",
"// directly replace",
"if",
"(",
"updateSubpathStart",
"&&",
"currentSegment",
".",
"isSubpathStart",
")",
"updateSubpathStart",
"=",
"false",
";",
"// already updated by `prepareSegment`",
"}",
"else",
"{",
"// flatten one level deep",
"// so we can chain arbitrary Path.createSegment results",
"arg",
"=",
"arg",
".",
"reduce",
"(",
"function",
"(",
"acc",
",",
"val",
")",
"{",
"return",
"acc",
".",
"concat",
"(",
"val",
")",
";",
"}",
",",
"[",
"]",
")",
";",
"if",
"(",
"!",
"arg",
"[",
"0",
"]",
".",
"isSegment",
")",
"throw",
"new",
"Error",
"(",
"'Segments required.'",
")",
";",
"segments",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"var",
"n",
"=",
"arg",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"var",
"currentArg",
"=",
"arg",
"[",
"i",
"]",
";",
"currentSegment",
"=",
"this",
".",
"prepareSegment",
"(",
"currentArg",
",",
"previousSegment",
",",
"nextSegment",
")",
";",
"segments",
".",
"splice",
"(",
"(",
"index",
"+",
"i",
")",
",",
"0",
",",
"currentSegment",
")",
";",
"// incrementing index to insert subsequent segments after inserted segments",
"previousSegment",
"=",
"currentSegment",
";",
"if",
"(",
"updateSubpathStart",
"&&",
"currentSegment",
".",
"isSubpathStart",
")",
"updateSubpathStart",
"=",
"false",
";",
"// already updated by `prepareSegment`",
"}",
"}",
"// if replaced segment used to start a subpath and no new subpath start was added, update all subsequent segments until another subpath start segment is reached",
"if",
"(",
"updateSubpathStart",
"&&",
"nextSegment",
")",
"this",
".",
"updateSubpathStartSegment",
"(",
"nextSegment",
")",
";",
"}"
] | Replace the segment at `index` with `arg`. Accepts negative indices, from `-1` to `-segments.length`. Accepts one segment or an array of segments as argument. Throws an error if path has no segments. Throws an error if index is out of range. Throws an error if argument is not a segment or an array of segments. | [
"Replace",
"the",
"segment",
"at",
"index",
"with",
"arg",
".",
"Accepts",
"negative",
"indices",
"from",
"-",
"1",
"to",
"-",
"segments",
".",
"length",
".",
"Accepts",
"one",
"segment",
"or",
"an",
"array",
"of",
"segments",
"as",
"argument",
".",
"Throws",
"an",
"error",
"if",
"path",
"has",
"no",
"segments",
".",
"Throws",
"an",
"error",
"if",
"index",
"is",
"out",
"of",
"range",
".",
"Throws",
"an",
"error",
"if",
"argument",
"is",
"not",
"a",
"segment",
"or",
"an",
"array",
"of",
"segments",
"."
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/src/geometry.js#L2539-L2589 |
|
7,838 | clientIO/joint | demo/expand/index.js | function(cell, portId) {
console.assert(cell.isVisible());
console.assert(!cell.portProp(portId, 'collapsed'), 'port ' + portId + ' on ' + cell.id + ' should be expanded');
} | javascript | function(cell, portId) {
console.assert(cell.isVisible());
console.assert(!cell.portProp(portId, 'collapsed'), 'port ' + portId + ' on ' + cell.id + ' should be expanded');
} | [
"function",
"(",
"cell",
",",
"portId",
")",
"{",
"console",
".",
"assert",
"(",
"cell",
".",
"isVisible",
"(",
")",
")",
";",
"console",
".",
"assert",
"(",
"!",
"cell",
".",
"portProp",
"(",
"portId",
",",
"'collapsed'",
")",
",",
"'port '",
"+",
"portId",
"+",
"' on '",
"+",
"cell",
".",
"id",
"+",
"' should be expanded'",
")",
";",
"}"
] | Simple unit testing | [
"Simple",
"unit",
"testing"
] | 99ba02fe6c64e407bdfff6ba595d2068422c3e76 | https://github.com/clientIO/joint/blob/99ba02fe6c64e407bdfff6ba595d2068422c3e76/demo/expand/index.js#L198-L202 |
|
7,839 | Mikhus/canvas-gauges | lib/RadialGauge.js | displayValue | function displayValue(gauge) {
if (gauge.options.animatedValue) {
return gauge.options.value;
}
return gauge.value;
} | javascript | function displayValue(gauge) {
if (gauge.options.animatedValue) {
return gauge.options.value;
}
return gauge.value;
} | [
"function",
"displayValue",
"(",
"gauge",
")",
"{",
"if",
"(",
"gauge",
".",
"options",
".",
"animatedValue",
")",
"{",
"return",
"gauge",
".",
"options",
".",
"value",
";",
"}",
"return",
"gauge",
".",
"value",
";",
"}"
] | Find and return gauge value to display
@param {RadialGauge} gauge | [
"Find",
"and",
"return",
"gauge",
"value",
"to",
"display"
] | 8f1a0936951be63f612e16443eb7b2235863679e | https://github.com/Mikhus/canvas-gauges/blob/8f1a0936951be63f612e16443eb7b2235863679e/lib/RadialGauge.js#L683-L689 |
7,840 | Mikhus/canvas-gauges | lib/LinearGauge.js | drawLinearBar | function drawLinearBar(context, options, x, y, w, h) {
drawLinearBarShape(context, options, '', x, y, w, h);
} | javascript | function drawLinearBar(context, options, x, y, w, h) {
drawLinearBarShape(context, options, '', x, y, w, h);
} | [
"function",
"drawLinearBar",
"(",
"context",
",",
"options",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
")",
"{",
"drawLinearBarShape",
"(",
"context",
",",
"options",
",",
"''",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
")",
";",
"}"
] | Draws gauge bar
@param {Canvas2DContext} context
@param {LinearGaugeOptions} options
@param {number} x x-coordinate of the top-left corner of the gauge
@param {number} y y-coordinate of the top-left corner of the gauge
@param {number} w width of the gauge
@param {number} h height of the gauge | [
"Draws",
"gauge",
"bar"
] | 8f1a0936951be63f612e16443eb7b2235863679e | https://github.com/Mikhus/canvas-gauges/blob/8f1a0936951be63f612e16443eb7b2235863679e/lib/LinearGauge.js#L467-L469 |
7,841 | Teradata/covalent | scripts/version-placeholders.js | replaceVersionPlaceholders | function replaceVersionPlaceholders(packageDir, projectVersion) {
// Resolve files that contain version placeholders using Grep or Findstr since those are
// extremely fast and also have a very simple usage.
const files = findFilesWithPlaceholders(packageDir);
// Walk through every file that contains version placeholders and replace those with the current
// version of the root package.json file.
files.forEach(filePath => {
const fileContent = readFileSync(filePath, 'utf-8')
.replace(ngVersionPlaceholderRegex, buildConfig.angularVersion)
.replace(materialVersionPlaceholderRegex, buildConfig.materialVersion)
.replace(versionPlaceholderRegex, projectVersion);
writeFileSync(filePath, fileContent);
});
} | javascript | function replaceVersionPlaceholders(packageDir, projectVersion) {
// Resolve files that contain version placeholders using Grep or Findstr since those are
// extremely fast and also have a very simple usage.
const files = findFilesWithPlaceholders(packageDir);
// Walk through every file that contains version placeholders and replace those with the current
// version of the root package.json file.
files.forEach(filePath => {
const fileContent = readFileSync(filePath, 'utf-8')
.replace(ngVersionPlaceholderRegex, buildConfig.angularVersion)
.replace(materialVersionPlaceholderRegex, buildConfig.materialVersion)
.replace(versionPlaceholderRegex, projectVersion);
writeFileSync(filePath, fileContent);
});
} | [
"function",
"replaceVersionPlaceholders",
"(",
"packageDir",
",",
"projectVersion",
")",
"{",
"// Resolve files that contain version placeholders using Grep or Findstr since those are",
"// extremely fast and also have a very simple usage.",
"const",
"files",
"=",
"findFilesWithPlaceholders",
"(",
"packageDir",
")",
";",
"// Walk through every file that contains version placeholders and replace those with the current",
"// version of the root package.json file.",
"files",
".",
"forEach",
"(",
"filePath",
"=>",
"{",
"const",
"fileContent",
"=",
"readFileSync",
"(",
"filePath",
",",
"'utf-8'",
")",
".",
"replace",
"(",
"ngVersionPlaceholderRegex",
",",
"buildConfig",
".",
"angularVersion",
")",
".",
"replace",
"(",
"materialVersionPlaceholderRegex",
",",
"buildConfig",
".",
"materialVersion",
")",
".",
"replace",
"(",
"versionPlaceholderRegex",
",",
"projectVersion",
")",
";",
"writeFileSync",
"(",
"filePath",
",",
"fileContent",
")",
";",
"}",
")",
";",
"}"
] | Walks through every file in a directory and replaces the version placeholders | [
"Walks",
"through",
"every",
"file",
"in",
"a",
"directory",
"and",
"replaces",
"the",
"version",
"placeholders"
] | 75e047408b21b95689b669b8851c41dd3f844204 | https://github.com/Teradata/covalent/blob/75e047408b21b95689b669b8851c41dd3f844204/scripts/version-placeholders.js#L28-L43 |
7,842 | Teradata/covalent | scripts/version-placeholders.js | findFilesWithPlaceholders | function findFilesWithPlaceholders(packageDir) {
const findCommand = buildPlaceholderFindCommand(packageDir);
return spawnSync(findCommand.binary, findCommand.args).stdout
.toString()
.split(/[\n\r]/)
.filter(String);
} | javascript | function findFilesWithPlaceholders(packageDir) {
const findCommand = buildPlaceholderFindCommand(packageDir);
return spawnSync(findCommand.binary, findCommand.args).stdout
.toString()
.split(/[\n\r]/)
.filter(String);
} | [
"function",
"findFilesWithPlaceholders",
"(",
"packageDir",
")",
"{",
"const",
"findCommand",
"=",
"buildPlaceholderFindCommand",
"(",
"packageDir",
")",
";",
"return",
"spawnSync",
"(",
"findCommand",
".",
"binary",
",",
"findCommand",
".",
"args",
")",
".",
"stdout",
".",
"toString",
"(",
")",
".",
"split",
"(",
"/",
"[\\n\\r]",
"/",
")",
".",
"filter",
"(",
"String",
")",
";",
"}"
] | Finds all files in the specified package dir where version placeholders are included. | [
"Finds",
"all",
"files",
"in",
"the",
"specified",
"package",
"dir",
"where",
"version",
"placeholders",
"are",
"included",
"."
] | 75e047408b21b95689b669b8851c41dd3f844204 | https://github.com/Teradata/covalent/blob/75e047408b21b95689b669b8851c41dd3f844204/scripts/version-placeholders.js#L46-L52 |
7,843 | Teradata/covalent | scripts/version-placeholders.js | buildPlaceholderFindCommand | function buildPlaceholderFindCommand(packageDir) {
if (platform() === 'win32') {
return {
binary: 'findstr',
args: ['/msi', `${materialVersionPlaceholderText} ${ngVersionPlaceholderText} ${versionPlaceholderText}`, `${packageDir}\\*`]
};
} else {
return {
binary: 'grep',
args: ['-ril', `${materialVersionPlaceholderText}\\|${ngVersionPlaceholderText}\\|${versionPlaceholderText}`, packageDir]
};
}
} | javascript | function buildPlaceholderFindCommand(packageDir) {
if (platform() === 'win32') {
return {
binary: 'findstr',
args: ['/msi', `${materialVersionPlaceholderText} ${ngVersionPlaceholderText} ${versionPlaceholderText}`, `${packageDir}\\*`]
};
} else {
return {
binary: 'grep',
args: ['-ril', `${materialVersionPlaceholderText}\\|${ngVersionPlaceholderText}\\|${versionPlaceholderText}`, packageDir]
};
}
} | [
"function",
"buildPlaceholderFindCommand",
"(",
"packageDir",
")",
"{",
"if",
"(",
"platform",
"(",
")",
"===",
"'win32'",
")",
"{",
"return",
"{",
"binary",
":",
"'findstr'",
",",
"args",
":",
"[",
"'/msi'",
",",
"`",
"${",
"materialVersionPlaceholderText",
"}",
"${",
"ngVersionPlaceholderText",
"}",
"${",
"versionPlaceholderText",
"}",
"`",
",",
"`",
"${",
"packageDir",
"}",
"\\\\",
"`",
"]",
"}",
";",
"}",
"else",
"{",
"return",
"{",
"binary",
":",
"'grep'",
",",
"args",
":",
"[",
"'-ril'",
",",
"`",
"${",
"materialVersionPlaceholderText",
"}",
"\\\\",
"${",
"ngVersionPlaceholderText",
"}",
"\\\\",
"${",
"versionPlaceholderText",
"}",
"`",
",",
"packageDir",
"]",
"}",
";",
"}",
"}"
] | Builds the command that will be executed to find all files containing version placeholders. | [
"Builds",
"the",
"command",
"that",
"will",
"be",
"executed",
"to",
"find",
"all",
"files",
"containing",
"version",
"placeholders",
"."
] | 75e047408b21b95689b669b8851c41dd3f844204 | https://github.com/Teradata/covalent/blob/75e047408b21b95689b669b8851c41dd3f844204/scripts/version-placeholders.js#L55-L67 |
7,844 | exokitxr/exokit | src/DOM.js | _cloneNode | function _cloneNode(deep, sourceNode, parentNode) {
const clone = new sourceNode.constructor(sourceNode[symbols.windowSymbol]);
clone.attrs = sourceNode.attrs;
clone.tagName = sourceNode.tagName;
clone.value = sourceNode.value;
// Link the parent.
if (parentNode) { clone.parentNode = parentNode; }
// Copy children.
if (deep) {
clone.childNodes = new NodeList(
sourceNode.childNodes.map(childNode =>
_cloneNode(true, childNode, clone)
)
);
}
return clone;
} | javascript | function _cloneNode(deep, sourceNode, parentNode) {
const clone = new sourceNode.constructor(sourceNode[symbols.windowSymbol]);
clone.attrs = sourceNode.attrs;
clone.tagName = sourceNode.tagName;
clone.value = sourceNode.value;
// Link the parent.
if (parentNode) { clone.parentNode = parentNode; }
// Copy children.
if (deep) {
clone.childNodes = new NodeList(
sourceNode.childNodes.map(childNode =>
_cloneNode(true, childNode, clone)
)
);
}
return clone;
} | [
"function",
"_cloneNode",
"(",
"deep",
",",
"sourceNode",
",",
"parentNode",
")",
"{",
"const",
"clone",
"=",
"new",
"sourceNode",
".",
"constructor",
"(",
"sourceNode",
"[",
"symbols",
".",
"windowSymbol",
"]",
")",
";",
"clone",
".",
"attrs",
"=",
"sourceNode",
".",
"attrs",
";",
"clone",
".",
"tagName",
"=",
"sourceNode",
".",
"tagName",
";",
"clone",
".",
"value",
"=",
"sourceNode",
".",
"value",
";",
"// Link the parent.",
"if",
"(",
"parentNode",
")",
"{",
"clone",
".",
"parentNode",
"=",
"parentNode",
";",
"}",
"// Copy children.",
"if",
"(",
"deep",
")",
"{",
"clone",
".",
"childNodes",
"=",
"new",
"NodeList",
"(",
"sourceNode",
".",
"childNodes",
".",
"map",
"(",
"childNode",
"=>",
"_cloneNode",
"(",
"true",
",",
"childNode",
",",
"clone",
")",
")",
")",
";",
"}",
"return",
"clone",
";",
"}"
] | Clone node. Internal function to not expose the `sourceNode` and `parentNode` args
used to facilitate recursive cloning.
@param {boolean} deep - Recursive.
@param {object} sourceNode - Node to clone.
@param {parentNode} parentNode - Used for recursive cloning to attach parent. | [
"Clone",
"node",
".",
"Internal",
"function",
"to",
"not",
"expose",
"the",
"sourceNode",
"and",
"parentNode",
"args",
"used",
"to",
"facilitate",
"recursive",
"cloning",
"."
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/src/DOM.js#L270-L289 |
7,845 | exokitxr/exokit | examples/FBXLoader.js | function () {
var images = {};
var blobs = {};
if ( 'Video' in fbxTree.Objects ) {
var videoNodes = fbxTree.Objects.Video;
for ( var nodeID in videoNodes ) {
var videoNode = videoNodes[ nodeID ];
var id = parseInt( nodeID );
images[ id ] = videoNode.RelativeFilename || videoNode.Filename;
// raw image data is in videoNode.Content
if ( 'Content' in videoNode ) {
var arrayBufferContent = ( videoNode.Content instanceof ArrayBuffer ) && ( videoNode.Content.byteLength > 0 );
var base64Content = ( typeof videoNode.Content === 'string' ) && ( videoNode.Content !== '' );
if ( arrayBufferContent || base64Content ) {
var image = this.parseImage( videoNodes[ nodeID ] );
blobs[ videoNode.RelativeFilename || videoNode.Filename ] = image;
}
}
}
}
for ( var id in images ) {
var filename = images[ id ];
if ( blobs[ filename ] !== undefined ) images[ id ] = blobs[ filename ];
else images[ id ] = images[ id ].split( '\\' ).pop();
}
return images;
} | javascript | function () {
var images = {};
var blobs = {};
if ( 'Video' in fbxTree.Objects ) {
var videoNodes = fbxTree.Objects.Video;
for ( var nodeID in videoNodes ) {
var videoNode = videoNodes[ nodeID ];
var id = parseInt( nodeID );
images[ id ] = videoNode.RelativeFilename || videoNode.Filename;
// raw image data is in videoNode.Content
if ( 'Content' in videoNode ) {
var arrayBufferContent = ( videoNode.Content instanceof ArrayBuffer ) && ( videoNode.Content.byteLength > 0 );
var base64Content = ( typeof videoNode.Content === 'string' ) && ( videoNode.Content !== '' );
if ( arrayBufferContent || base64Content ) {
var image = this.parseImage( videoNodes[ nodeID ] );
blobs[ videoNode.RelativeFilename || videoNode.Filename ] = image;
}
}
}
}
for ( var id in images ) {
var filename = images[ id ];
if ( blobs[ filename ] !== undefined ) images[ id ] = blobs[ filename ];
else images[ id ] = images[ id ].split( '\\' ).pop();
}
return images;
} | [
"function",
"(",
")",
"{",
"var",
"images",
"=",
"{",
"}",
";",
"var",
"blobs",
"=",
"{",
"}",
";",
"if",
"(",
"'Video'",
"in",
"fbxTree",
".",
"Objects",
")",
"{",
"var",
"videoNodes",
"=",
"fbxTree",
".",
"Objects",
".",
"Video",
";",
"for",
"(",
"var",
"nodeID",
"in",
"videoNodes",
")",
"{",
"var",
"videoNode",
"=",
"videoNodes",
"[",
"nodeID",
"]",
";",
"var",
"id",
"=",
"parseInt",
"(",
"nodeID",
")",
";",
"images",
"[",
"id",
"]",
"=",
"videoNode",
".",
"RelativeFilename",
"||",
"videoNode",
".",
"Filename",
";",
"// raw image data is in videoNode.Content",
"if",
"(",
"'Content'",
"in",
"videoNode",
")",
"{",
"var",
"arrayBufferContent",
"=",
"(",
"videoNode",
".",
"Content",
"instanceof",
"ArrayBuffer",
")",
"&&",
"(",
"videoNode",
".",
"Content",
".",
"byteLength",
">",
"0",
")",
";",
"var",
"base64Content",
"=",
"(",
"typeof",
"videoNode",
".",
"Content",
"===",
"'string'",
")",
"&&",
"(",
"videoNode",
".",
"Content",
"!==",
"''",
")",
";",
"if",
"(",
"arrayBufferContent",
"||",
"base64Content",
")",
"{",
"var",
"image",
"=",
"this",
".",
"parseImage",
"(",
"videoNodes",
"[",
"nodeID",
"]",
")",
";",
"blobs",
"[",
"videoNode",
".",
"RelativeFilename",
"||",
"videoNode",
".",
"Filename",
"]",
"=",
"image",
";",
"}",
"}",
"}",
"}",
"for",
"(",
"var",
"id",
"in",
"images",
")",
"{",
"var",
"filename",
"=",
"images",
"[",
"id",
"]",
";",
"if",
"(",
"blobs",
"[",
"filename",
"]",
"!==",
"undefined",
")",
"images",
"[",
"id",
"]",
"=",
"blobs",
"[",
"filename",
"]",
";",
"else",
"images",
"[",
"id",
"]",
"=",
"images",
"[",
"id",
"]",
".",
"split",
"(",
"'\\\\'",
")",
".",
"pop",
"(",
")",
";",
"}",
"return",
"images",
";",
"}"
] | Parse FBXTree.Objects.Video for embedded image data These images are connected to textures in FBXTree.Objects.Textures via FBXTree.Connections. | [
"Parse",
"FBXTree",
".",
"Objects",
".",
"Video",
"for",
"embedded",
"image",
"data",
"These",
"images",
"are",
"connected",
"to",
"textures",
"in",
"FBXTree",
".",
"Objects",
".",
"Textures",
"via",
"FBXTree",
".",
"Connections",
"."
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L190-L238 |
|
7,846 | exokitxr/exokit | examples/FBXLoader.js | function ( videoNode ) {
var content = videoNode.Content;
var fileName = videoNode.RelativeFilename || videoNode.Filename;
var extension = fileName.slice( fileName.lastIndexOf( '.' ) + 1 ).toLowerCase();
var type;
switch ( extension ) {
case 'bmp':
type = 'image/bmp';
break;
case 'jpg':
case 'jpeg':
type = 'image/jpeg';
break;
case 'png':
type = 'image/png';
break;
case 'tif':
type = 'image/tiff';
break;
case 'tga':
if ( typeof THREE.TGALoader !== 'function' ) {
console.warn( 'FBXLoader: THREE.TGALoader is required to load TGA textures' );
return;
} else {
if ( THREE.Loader.Handlers.get( '.tga' ) === null ) {
THREE.Loader.Handlers.add( /\.tga$/i, new THREE.TGALoader() );
}
type = 'image/tga';
break;
}
default:
console.warn( 'FBXLoader: Image type "' + extension + '" is not supported.' );
return;
}
if ( typeof content === 'string' ) { // ASCII format
return 'data:' + type + ';base64,' + content;
} else { // Binary Format
var array = new Uint8Array( content );
return window.URL.createObjectURL( new Blob( [ array ], { type: type } ) );
}
} | javascript | function ( videoNode ) {
var content = videoNode.Content;
var fileName = videoNode.RelativeFilename || videoNode.Filename;
var extension = fileName.slice( fileName.lastIndexOf( '.' ) + 1 ).toLowerCase();
var type;
switch ( extension ) {
case 'bmp':
type = 'image/bmp';
break;
case 'jpg':
case 'jpeg':
type = 'image/jpeg';
break;
case 'png':
type = 'image/png';
break;
case 'tif':
type = 'image/tiff';
break;
case 'tga':
if ( typeof THREE.TGALoader !== 'function' ) {
console.warn( 'FBXLoader: THREE.TGALoader is required to load TGA textures' );
return;
} else {
if ( THREE.Loader.Handlers.get( '.tga' ) === null ) {
THREE.Loader.Handlers.add( /\.tga$/i, new THREE.TGALoader() );
}
type = 'image/tga';
break;
}
default:
console.warn( 'FBXLoader: Image type "' + extension + '" is not supported.' );
return;
}
if ( typeof content === 'string' ) { // ASCII format
return 'data:' + type + ';base64,' + content;
} else { // Binary Format
var array = new Uint8Array( content );
return window.URL.createObjectURL( new Blob( [ array ], { type: type } ) );
}
} | [
"function",
"(",
"videoNode",
")",
"{",
"var",
"content",
"=",
"videoNode",
".",
"Content",
";",
"var",
"fileName",
"=",
"videoNode",
".",
"RelativeFilename",
"||",
"videoNode",
".",
"Filename",
";",
"var",
"extension",
"=",
"fileName",
".",
"slice",
"(",
"fileName",
".",
"lastIndexOf",
"(",
"'.'",
")",
"+",
"1",
")",
".",
"toLowerCase",
"(",
")",
";",
"var",
"type",
";",
"switch",
"(",
"extension",
")",
"{",
"case",
"'bmp'",
":",
"type",
"=",
"'image/bmp'",
";",
"break",
";",
"case",
"'jpg'",
":",
"case",
"'jpeg'",
":",
"type",
"=",
"'image/jpeg'",
";",
"break",
";",
"case",
"'png'",
":",
"type",
"=",
"'image/png'",
";",
"break",
";",
"case",
"'tif'",
":",
"type",
"=",
"'image/tiff'",
";",
"break",
";",
"case",
"'tga'",
":",
"if",
"(",
"typeof",
"THREE",
".",
"TGALoader",
"!==",
"'function'",
")",
"{",
"console",
".",
"warn",
"(",
"'FBXLoader: THREE.TGALoader is required to load TGA textures'",
")",
";",
"return",
";",
"}",
"else",
"{",
"if",
"(",
"THREE",
".",
"Loader",
".",
"Handlers",
".",
"get",
"(",
"'.tga'",
")",
"===",
"null",
")",
"{",
"THREE",
".",
"Loader",
".",
"Handlers",
".",
"add",
"(",
"/",
"\\.tga$",
"/",
"i",
",",
"new",
"THREE",
".",
"TGALoader",
"(",
")",
")",
";",
"}",
"type",
"=",
"'image/tga'",
";",
"break",
";",
"}",
"default",
":",
"console",
".",
"warn",
"(",
"'FBXLoader: Image type \"'",
"+",
"extension",
"+",
"'\" is not supported.'",
")",
";",
"return",
";",
"}",
"if",
"(",
"typeof",
"content",
"===",
"'string'",
")",
"{",
"// ASCII format",
"return",
"'data:'",
"+",
"type",
"+",
"';base64,'",
"+",
"content",
";",
"}",
"else",
"{",
"// Binary Format",
"var",
"array",
"=",
"new",
"Uint8Array",
"(",
"content",
")",
";",
"return",
"window",
".",
"URL",
".",
"createObjectURL",
"(",
"new",
"Blob",
"(",
"[",
"array",
"]",
",",
"{",
"type",
":",
"type",
"}",
")",
")",
";",
"}",
"}"
] | Parse embedded image data in FBXTree.Video.Content | [
"Parse",
"embedded",
"image",
"data",
"in",
"FBXTree",
".",
"Video",
".",
"Content"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L241-L310 |
|
7,847 | exokitxr/exokit | examples/FBXLoader.js | function ( images ) {
var textureMap = new Map();
if ( 'Texture' in fbxTree.Objects ) {
var textureNodes = fbxTree.Objects.Texture;
for ( var nodeID in textureNodes ) {
var texture = this.parseTexture( textureNodes[ nodeID ], images );
textureMap.set( parseInt( nodeID ), texture );
}
}
return textureMap;
} | javascript | function ( images ) {
var textureMap = new Map();
if ( 'Texture' in fbxTree.Objects ) {
var textureNodes = fbxTree.Objects.Texture;
for ( var nodeID in textureNodes ) {
var texture = this.parseTexture( textureNodes[ nodeID ], images );
textureMap.set( parseInt( nodeID ), texture );
}
}
return textureMap;
} | [
"function",
"(",
"images",
")",
"{",
"var",
"textureMap",
"=",
"new",
"Map",
"(",
")",
";",
"if",
"(",
"'Texture'",
"in",
"fbxTree",
".",
"Objects",
")",
"{",
"var",
"textureNodes",
"=",
"fbxTree",
".",
"Objects",
".",
"Texture",
";",
"for",
"(",
"var",
"nodeID",
"in",
"textureNodes",
")",
"{",
"var",
"texture",
"=",
"this",
".",
"parseTexture",
"(",
"textureNodes",
"[",
"nodeID",
"]",
",",
"images",
")",
";",
"textureMap",
".",
"set",
"(",
"parseInt",
"(",
"nodeID",
")",
",",
"texture",
")",
";",
"}",
"}",
"return",
"textureMap",
";",
"}"
] | Parse nodes in FBXTree.Objects.Texture These contain details such as UV scaling, cropping, rotation etc and are connected to images in FBXTree.Objects.Video | [
"Parse",
"nodes",
"in",
"FBXTree",
".",
"Objects",
".",
"Texture",
"These",
"contain",
"details",
"such",
"as",
"UV",
"scaling",
"cropping",
"rotation",
"etc",
"and",
"are",
"connected",
"to",
"images",
"in",
"FBXTree",
".",
"Objects",
".",
"Video"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L315-L333 |
|
7,848 | exokitxr/exokit | examples/FBXLoader.js | function ( textureNode, images ) {
var texture = this.loadTexture( textureNode, images );
texture.ID = textureNode.id;
texture.name = textureNode.attrName;
var wrapModeU = textureNode.WrapModeU;
var wrapModeV = textureNode.WrapModeV;
var valueU = wrapModeU !== undefined ? wrapModeU.value : 0;
var valueV = wrapModeV !== undefined ? wrapModeV.value : 0;
// http://download.autodesk.com/us/fbx/SDKdocs/FBX_SDK_Help/files/fbxsdkref/class_k_fbx_texture.html#889640e63e2e681259ea81061b85143a
// 0: repeat(default), 1: clamp
texture.wrapS = valueU === 0 ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
texture.wrapT = valueV === 0 ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
if ( 'Scaling' in textureNode ) {
var values = textureNode.Scaling.value;
texture.repeat.x = values[ 0 ];
texture.repeat.y = values[ 1 ];
}
return texture;
} | javascript | function ( textureNode, images ) {
var texture = this.loadTexture( textureNode, images );
texture.ID = textureNode.id;
texture.name = textureNode.attrName;
var wrapModeU = textureNode.WrapModeU;
var wrapModeV = textureNode.WrapModeV;
var valueU = wrapModeU !== undefined ? wrapModeU.value : 0;
var valueV = wrapModeV !== undefined ? wrapModeV.value : 0;
// http://download.autodesk.com/us/fbx/SDKdocs/FBX_SDK_Help/files/fbxsdkref/class_k_fbx_texture.html#889640e63e2e681259ea81061b85143a
// 0: repeat(default), 1: clamp
texture.wrapS = valueU === 0 ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
texture.wrapT = valueV === 0 ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
if ( 'Scaling' in textureNode ) {
var values = textureNode.Scaling.value;
texture.repeat.x = values[ 0 ];
texture.repeat.y = values[ 1 ];
}
return texture;
} | [
"function",
"(",
"textureNode",
",",
"images",
")",
"{",
"var",
"texture",
"=",
"this",
".",
"loadTexture",
"(",
"textureNode",
",",
"images",
")",
";",
"texture",
".",
"ID",
"=",
"textureNode",
".",
"id",
";",
"texture",
".",
"name",
"=",
"textureNode",
".",
"attrName",
";",
"var",
"wrapModeU",
"=",
"textureNode",
".",
"WrapModeU",
";",
"var",
"wrapModeV",
"=",
"textureNode",
".",
"WrapModeV",
";",
"var",
"valueU",
"=",
"wrapModeU",
"!==",
"undefined",
"?",
"wrapModeU",
".",
"value",
":",
"0",
";",
"var",
"valueV",
"=",
"wrapModeV",
"!==",
"undefined",
"?",
"wrapModeV",
".",
"value",
":",
"0",
";",
"// http://download.autodesk.com/us/fbx/SDKdocs/FBX_SDK_Help/files/fbxsdkref/class_k_fbx_texture.html#889640e63e2e681259ea81061b85143a",
"// 0: repeat(default), 1: clamp",
"texture",
".",
"wrapS",
"=",
"valueU",
"===",
"0",
"?",
"THREE",
".",
"RepeatWrapping",
":",
"THREE",
".",
"ClampToEdgeWrapping",
";",
"texture",
".",
"wrapT",
"=",
"valueV",
"===",
"0",
"?",
"THREE",
".",
"RepeatWrapping",
":",
"THREE",
".",
"ClampToEdgeWrapping",
";",
"if",
"(",
"'Scaling'",
"in",
"textureNode",
")",
"{",
"var",
"values",
"=",
"textureNode",
".",
"Scaling",
".",
"value",
";",
"texture",
".",
"repeat",
".",
"x",
"=",
"values",
"[",
"0",
"]",
";",
"texture",
".",
"repeat",
".",
"y",
"=",
"values",
"[",
"1",
"]",
";",
"}",
"return",
"texture",
";",
"}"
] | Parse individual node in FBXTree.Objects.Texture | [
"Parse",
"individual",
"node",
"in",
"FBXTree",
".",
"Objects",
".",
"Texture"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L336-L367 |
|
7,849 | exokitxr/exokit | examples/FBXLoader.js | function ( textureNode, images ) {
var fileName;
var currentPath = this.textureLoader.path;
var children = connections.get( textureNode.id ).children;
if ( children !== undefined && children.length > 0 && images[ children[ 0 ].ID ] !== undefined ) {
fileName = images[ children[ 0 ].ID ];
if ( fileName.indexOf( 'blob:' ) === 0 || fileName.indexOf( 'data:' ) === 0 ) {
this.textureLoader.setPath( undefined );
}
}
var texture;
var extension = textureNode.FileName.slice( - 3 ).toLowerCase();
if ( extension === 'tga' ) {
var loader = THREE.Loader.Handlers.get( '.tga' );
if ( loader === null ) {
console.warn( 'FBXLoader: TGALoader not found, creating empty placeholder texture for', fileName );
texture = new THREE.Texture();
} else {
texture = loader.load( fileName );
}
} else if ( extension === 'psd' ) {
console.warn( 'FBXLoader: PSD textures are not supported, creating empty placeholder texture for', fileName );
texture = new THREE.Texture();
} else {
texture = this.textureLoader.load( fileName );
}
this.textureLoader.setPath( currentPath );
return texture;
} | javascript | function ( textureNode, images ) {
var fileName;
var currentPath = this.textureLoader.path;
var children = connections.get( textureNode.id ).children;
if ( children !== undefined && children.length > 0 && images[ children[ 0 ].ID ] !== undefined ) {
fileName = images[ children[ 0 ].ID ];
if ( fileName.indexOf( 'blob:' ) === 0 || fileName.indexOf( 'data:' ) === 0 ) {
this.textureLoader.setPath( undefined );
}
}
var texture;
var extension = textureNode.FileName.slice( - 3 ).toLowerCase();
if ( extension === 'tga' ) {
var loader = THREE.Loader.Handlers.get( '.tga' );
if ( loader === null ) {
console.warn( 'FBXLoader: TGALoader not found, creating empty placeholder texture for', fileName );
texture = new THREE.Texture();
} else {
texture = loader.load( fileName );
}
} else if ( extension === 'psd' ) {
console.warn( 'FBXLoader: PSD textures are not supported, creating empty placeholder texture for', fileName );
texture = new THREE.Texture();
} else {
texture = this.textureLoader.load( fileName );
}
this.textureLoader.setPath( currentPath );
return texture;
} | [
"function",
"(",
"textureNode",
",",
"images",
")",
"{",
"var",
"fileName",
";",
"var",
"currentPath",
"=",
"this",
".",
"textureLoader",
".",
"path",
";",
"var",
"children",
"=",
"connections",
".",
"get",
"(",
"textureNode",
".",
"id",
")",
".",
"children",
";",
"if",
"(",
"children",
"!==",
"undefined",
"&&",
"children",
".",
"length",
">",
"0",
"&&",
"images",
"[",
"children",
"[",
"0",
"]",
".",
"ID",
"]",
"!==",
"undefined",
")",
"{",
"fileName",
"=",
"images",
"[",
"children",
"[",
"0",
"]",
".",
"ID",
"]",
";",
"if",
"(",
"fileName",
".",
"indexOf",
"(",
"'blob:'",
")",
"===",
"0",
"||",
"fileName",
".",
"indexOf",
"(",
"'data:'",
")",
"===",
"0",
")",
"{",
"this",
".",
"textureLoader",
".",
"setPath",
"(",
"undefined",
")",
";",
"}",
"}",
"var",
"texture",
";",
"var",
"extension",
"=",
"textureNode",
".",
"FileName",
".",
"slice",
"(",
"-",
"3",
")",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"extension",
"===",
"'tga'",
")",
"{",
"var",
"loader",
"=",
"THREE",
".",
"Loader",
".",
"Handlers",
".",
"get",
"(",
"'.tga'",
")",
";",
"if",
"(",
"loader",
"===",
"null",
")",
"{",
"console",
".",
"warn",
"(",
"'FBXLoader: TGALoader not found, creating empty placeholder texture for'",
",",
"fileName",
")",
";",
"texture",
"=",
"new",
"THREE",
".",
"Texture",
"(",
")",
";",
"}",
"else",
"{",
"texture",
"=",
"loader",
".",
"load",
"(",
"fileName",
")",
";",
"}",
"}",
"else",
"if",
"(",
"extension",
"===",
"'psd'",
")",
"{",
"console",
".",
"warn",
"(",
"'FBXLoader: PSD textures are not supported, creating empty placeholder texture for'",
",",
"fileName",
")",
";",
"texture",
"=",
"new",
"THREE",
".",
"Texture",
"(",
")",
";",
"}",
"else",
"{",
"texture",
"=",
"this",
".",
"textureLoader",
".",
"load",
"(",
"fileName",
")",
";",
"}",
"this",
".",
"textureLoader",
".",
"setPath",
"(",
"currentPath",
")",
";",
"return",
"texture",
";",
"}"
] | load a texture specified as a blob or data URI, or via an external URL using THREE.TextureLoader | [
"load",
"a",
"texture",
"specified",
"as",
"a",
"blob",
"or",
"data",
"URI",
"or",
"via",
"an",
"external",
"URL",
"using",
"THREE",
".",
"TextureLoader"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L370-L424 |
|
7,850 | exokitxr/exokit | examples/FBXLoader.js | function ( textureMap ) {
var materialMap = new Map();
if ( 'Material' in fbxTree.Objects ) {
var materialNodes = fbxTree.Objects.Material;
for ( var nodeID in materialNodes ) {
var material = this.parseMaterial( materialNodes[ nodeID ], textureMap );
if ( material !== null ) materialMap.set( parseInt( nodeID ), material );
}
}
return materialMap;
} | javascript | function ( textureMap ) {
var materialMap = new Map();
if ( 'Material' in fbxTree.Objects ) {
var materialNodes = fbxTree.Objects.Material;
for ( var nodeID in materialNodes ) {
var material = this.parseMaterial( materialNodes[ nodeID ], textureMap );
if ( material !== null ) materialMap.set( parseInt( nodeID ), material );
}
}
return materialMap;
} | [
"function",
"(",
"textureMap",
")",
"{",
"var",
"materialMap",
"=",
"new",
"Map",
"(",
")",
";",
"if",
"(",
"'Material'",
"in",
"fbxTree",
".",
"Objects",
")",
"{",
"var",
"materialNodes",
"=",
"fbxTree",
".",
"Objects",
".",
"Material",
";",
"for",
"(",
"var",
"nodeID",
"in",
"materialNodes",
")",
"{",
"var",
"material",
"=",
"this",
".",
"parseMaterial",
"(",
"materialNodes",
"[",
"nodeID",
"]",
",",
"textureMap",
")",
";",
"if",
"(",
"material",
"!==",
"null",
")",
"materialMap",
".",
"set",
"(",
"parseInt",
"(",
"nodeID",
")",
",",
"material",
")",
";",
"}",
"}",
"return",
"materialMap",
";",
"}"
] | Parse nodes in FBXTree.Objects.Material | [
"Parse",
"nodes",
"in",
"FBXTree",
".",
"Objects",
".",
"Material"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L427-L447 |
|
7,851 | exokitxr/exokit | examples/FBXLoader.js | function ( materialNode, textureMap ) {
var ID = materialNode.id;
var name = materialNode.attrName;
var type = materialNode.ShadingModel;
// Case where FBX wraps shading model in property object.
if ( typeof type === 'object' ) {
type = type.value;
}
// Ignore unused materials which don't have any connections.
if ( ! connections.has( ID ) ) return null;
var parameters = this.parseParameters( materialNode, textureMap, ID );
var material;
switch ( type.toLowerCase() ) {
case 'phong':
material = new THREE.MeshPhongMaterial();
break;
case 'lambert':
material = new THREE.MeshLambertMaterial();
break;
default:
console.warn( 'THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.', type );
material = new THREE.MeshPhongMaterial( { color: 0x3300ff } );
break;
}
material.setValues( parameters );
material.name = name;
return material;
} | javascript | function ( materialNode, textureMap ) {
var ID = materialNode.id;
var name = materialNode.attrName;
var type = materialNode.ShadingModel;
// Case where FBX wraps shading model in property object.
if ( typeof type === 'object' ) {
type = type.value;
}
// Ignore unused materials which don't have any connections.
if ( ! connections.has( ID ) ) return null;
var parameters = this.parseParameters( materialNode, textureMap, ID );
var material;
switch ( type.toLowerCase() ) {
case 'phong':
material = new THREE.MeshPhongMaterial();
break;
case 'lambert':
material = new THREE.MeshLambertMaterial();
break;
default:
console.warn( 'THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.', type );
material = new THREE.MeshPhongMaterial( { color: 0x3300ff } );
break;
}
material.setValues( parameters );
material.name = name;
return material;
} | [
"function",
"(",
"materialNode",
",",
"textureMap",
")",
"{",
"var",
"ID",
"=",
"materialNode",
".",
"id",
";",
"var",
"name",
"=",
"materialNode",
".",
"attrName",
";",
"var",
"type",
"=",
"materialNode",
".",
"ShadingModel",
";",
"// Case where FBX wraps shading model in property object.",
"if",
"(",
"typeof",
"type",
"===",
"'object'",
")",
"{",
"type",
"=",
"type",
".",
"value",
";",
"}",
"// Ignore unused materials which don't have any connections.",
"if",
"(",
"!",
"connections",
".",
"has",
"(",
"ID",
")",
")",
"return",
"null",
";",
"var",
"parameters",
"=",
"this",
".",
"parseParameters",
"(",
"materialNode",
",",
"textureMap",
",",
"ID",
")",
";",
"var",
"material",
";",
"switch",
"(",
"type",
".",
"toLowerCase",
"(",
")",
")",
"{",
"case",
"'phong'",
":",
"material",
"=",
"new",
"THREE",
".",
"MeshPhongMaterial",
"(",
")",
";",
"break",
";",
"case",
"'lambert'",
":",
"material",
"=",
"new",
"THREE",
".",
"MeshLambertMaterial",
"(",
")",
";",
"break",
";",
"default",
":",
"console",
".",
"warn",
"(",
"'THREE.FBXLoader: unknown material type \"%s\". Defaulting to MeshPhongMaterial.'",
",",
"type",
")",
";",
"material",
"=",
"new",
"THREE",
".",
"MeshPhongMaterial",
"(",
"{",
"color",
":",
"0x3300ff",
"}",
")",
";",
"break",
";",
"}",
"material",
".",
"setValues",
"(",
"parameters",
")",
";",
"material",
".",
"name",
"=",
"name",
";",
"return",
"material",
";",
"}"
] | Parse single node in FBXTree.Objects.Material Materials are connected to texture maps in FBXTree.Objects.Textures FBX format currently only supports Lambert and Phong shading models | [
"Parse",
"single",
"node",
"in",
"FBXTree",
".",
"Objects",
".",
"Material",
"Materials",
"are",
"connected",
"to",
"texture",
"maps",
"in",
"FBXTree",
".",
"Objects",
".",
"Textures",
"FBX",
"format",
"currently",
"only",
"supports",
"Lambert",
"and",
"Phong",
"shading",
"models"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L452-L492 |
|
7,852 | exokitxr/exokit | examples/FBXLoader.js | function ( textureMap, id ) {
// if the texture is a layered texture, just use the first layer and issue a warning
if ( 'LayeredTexture' in fbxTree.Objects && id in fbxTree.Objects.LayeredTexture ) {
console.warn( 'THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer.' );
id = connections.get( id ).children[ 0 ].ID;
}
return textureMap.get( id );
} | javascript | function ( textureMap, id ) {
// if the texture is a layered texture, just use the first layer and issue a warning
if ( 'LayeredTexture' in fbxTree.Objects && id in fbxTree.Objects.LayeredTexture ) {
console.warn( 'THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer.' );
id = connections.get( id ).children[ 0 ].ID;
}
return textureMap.get( id );
} | [
"function",
"(",
"textureMap",
",",
"id",
")",
"{",
"// if the texture is a layered texture, just use the first layer and issue a warning",
"if",
"(",
"'LayeredTexture'",
"in",
"fbxTree",
".",
"Objects",
"&&",
"id",
"in",
"fbxTree",
".",
"Objects",
".",
"LayeredTexture",
")",
"{",
"console",
".",
"warn",
"(",
"'THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer.'",
")",
";",
"id",
"=",
"connections",
".",
"get",
"(",
"id",
")",
".",
"children",
"[",
"0",
"]",
".",
"ID",
";",
"}",
"return",
"textureMap",
".",
"get",
"(",
"id",
")",
";",
"}"
] | get a texture from the textureMap for use by a material. | [
"get",
"a",
"texture",
"from",
"the",
"textureMap",
"for",
"use",
"by",
"a",
"material",
"."
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L625-L637 |
|
7,853 | exokitxr/exokit | examples/FBXLoader.js | function () {
var skeletons = {};
var morphTargets = {};
if ( 'Deformer' in fbxTree.Objects ) {
var DeformerNodes = fbxTree.Objects.Deformer;
for ( var nodeID in DeformerNodes ) {
var deformerNode = DeformerNodes[ nodeID ];
var relationships = connections.get( parseInt( nodeID ) );
if ( deformerNode.attrType === 'Skin' ) {
var skeleton = this.parseSkeleton( relationships, DeformerNodes );
skeleton.ID = nodeID;
if ( relationships.parents.length > 1 ) console.warn( 'THREE.FBXLoader: skeleton attached to more than one geometry is not supported.' );
skeleton.geometryID = relationships.parents[ 0 ].ID;
skeletons[ nodeID ] = skeleton;
} else if ( deformerNode.attrType === 'BlendShape' ) {
var morphTarget = {
id: nodeID,
};
morphTarget.rawTargets = this.parseMorphTargets( relationships, DeformerNodes );
morphTarget.id = nodeID;
if ( relationships.parents.length > 1 ) console.warn( 'THREE.FBXLoader: morph target attached to more than one geometry is not supported.' );
morphTargets[ nodeID ] = morphTarget;
}
}
}
return {
skeletons: skeletons,
morphTargets: morphTargets,
};
} | javascript | function () {
var skeletons = {};
var morphTargets = {};
if ( 'Deformer' in fbxTree.Objects ) {
var DeformerNodes = fbxTree.Objects.Deformer;
for ( var nodeID in DeformerNodes ) {
var deformerNode = DeformerNodes[ nodeID ];
var relationships = connections.get( parseInt( nodeID ) );
if ( deformerNode.attrType === 'Skin' ) {
var skeleton = this.parseSkeleton( relationships, DeformerNodes );
skeleton.ID = nodeID;
if ( relationships.parents.length > 1 ) console.warn( 'THREE.FBXLoader: skeleton attached to more than one geometry is not supported.' );
skeleton.geometryID = relationships.parents[ 0 ].ID;
skeletons[ nodeID ] = skeleton;
} else if ( deformerNode.attrType === 'BlendShape' ) {
var morphTarget = {
id: nodeID,
};
morphTarget.rawTargets = this.parseMorphTargets( relationships, DeformerNodes );
morphTarget.id = nodeID;
if ( relationships.parents.length > 1 ) console.warn( 'THREE.FBXLoader: morph target attached to more than one geometry is not supported.' );
morphTargets[ nodeID ] = morphTarget;
}
}
}
return {
skeletons: skeletons,
morphTargets: morphTargets,
};
} | [
"function",
"(",
")",
"{",
"var",
"skeletons",
"=",
"{",
"}",
";",
"var",
"morphTargets",
"=",
"{",
"}",
";",
"if",
"(",
"'Deformer'",
"in",
"fbxTree",
".",
"Objects",
")",
"{",
"var",
"DeformerNodes",
"=",
"fbxTree",
".",
"Objects",
".",
"Deformer",
";",
"for",
"(",
"var",
"nodeID",
"in",
"DeformerNodes",
")",
"{",
"var",
"deformerNode",
"=",
"DeformerNodes",
"[",
"nodeID",
"]",
";",
"var",
"relationships",
"=",
"connections",
".",
"get",
"(",
"parseInt",
"(",
"nodeID",
")",
")",
";",
"if",
"(",
"deformerNode",
".",
"attrType",
"===",
"'Skin'",
")",
"{",
"var",
"skeleton",
"=",
"this",
".",
"parseSkeleton",
"(",
"relationships",
",",
"DeformerNodes",
")",
";",
"skeleton",
".",
"ID",
"=",
"nodeID",
";",
"if",
"(",
"relationships",
".",
"parents",
".",
"length",
">",
"1",
")",
"console",
".",
"warn",
"(",
"'THREE.FBXLoader: skeleton attached to more than one geometry is not supported.'",
")",
";",
"skeleton",
".",
"geometryID",
"=",
"relationships",
".",
"parents",
"[",
"0",
"]",
".",
"ID",
";",
"skeletons",
"[",
"nodeID",
"]",
"=",
"skeleton",
";",
"}",
"else",
"if",
"(",
"deformerNode",
".",
"attrType",
"===",
"'BlendShape'",
")",
"{",
"var",
"morphTarget",
"=",
"{",
"id",
":",
"nodeID",
",",
"}",
";",
"morphTarget",
".",
"rawTargets",
"=",
"this",
".",
"parseMorphTargets",
"(",
"relationships",
",",
"DeformerNodes",
")",
";",
"morphTarget",
".",
"id",
"=",
"nodeID",
";",
"if",
"(",
"relationships",
".",
"parents",
".",
"length",
">",
"1",
")",
"console",
".",
"warn",
"(",
"'THREE.FBXLoader: morph target attached to more than one geometry is not supported.'",
")",
";",
"morphTargets",
"[",
"nodeID",
"]",
"=",
"morphTarget",
";",
"}",
"}",
"}",
"return",
"{",
"skeletons",
":",
"skeletons",
",",
"morphTargets",
":",
"morphTargets",
",",
"}",
";",
"}"
] | Parse nodes in FBXTree.Objects.Deformer Deformer node can contain skinning or Vertex Cache animation data, however only skinning is supported here Generates map of Skeleton-like objects for use later when generating and binding skeletons. | [
"Parse",
"nodes",
"in",
"FBXTree",
".",
"Objects",
".",
"Deformer",
"Deformer",
"node",
"can",
"contain",
"skinning",
"or",
"Vertex",
"Cache",
"animation",
"data",
"however",
"only",
"skinning",
"is",
"supported",
"here",
"Generates",
"map",
"of",
"Skeleton",
"-",
"like",
"objects",
"for",
"use",
"later",
"when",
"generating",
"and",
"binding",
"skeletons",
"."
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L642-L693 |
|
7,854 | exokitxr/exokit | examples/FBXLoader.js | function ( relationships, deformerNodes ) {
var rawBones = [];
relationships.children.forEach( function ( child ) {
var boneNode = deformerNodes[ child.ID ];
if ( boneNode.attrType !== 'Cluster' ) return;
var rawBone = {
ID: child.ID,
indices: [],
weights: [],
transform: new THREE.Matrix4().fromArray( boneNode.Transform.a ),
transformLink: new THREE.Matrix4().fromArray( boneNode.TransformLink.a ),
linkMode: boneNode.Mode,
};
if ( 'Indexes' in boneNode ) {
rawBone.indices = boneNode.Indexes.a;
rawBone.weights = boneNode.Weights.a;
}
rawBones.push( rawBone );
} );
return {
rawBones: rawBones,
bones: []
};
} | javascript | function ( relationships, deformerNodes ) {
var rawBones = [];
relationships.children.forEach( function ( child ) {
var boneNode = deformerNodes[ child.ID ];
if ( boneNode.attrType !== 'Cluster' ) return;
var rawBone = {
ID: child.ID,
indices: [],
weights: [],
transform: new THREE.Matrix4().fromArray( boneNode.Transform.a ),
transformLink: new THREE.Matrix4().fromArray( boneNode.TransformLink.a ),
linkMode: boneNode.Mode,
};
if ( 'Indexes' in boneNode ) {
rawBone.indices = boneNode.Indexes.a;
rawBone.weights = boneNode.Weights.a;
}
rawBones.push( rawBone );
} );
return {
rawBones: rawBones,
bones: []
};
} | [
"function",
"(",
"relationships",
",",
"deformerNodes",
")",
"{",
"var",
"rawBones",
"=",
"[",
"]",
";",
"relationships",
".",
"children",
".",
"forEach",
"(",
"function",
"(",
"child",
")",
"{",
"var",
"boneNode",
"=",
"deformerNodes",
"[",
"child",
".",
"ID",
"]",
";",
"if",
"(",
"boneNode",
".",
"attrType",
"!==",
"'Cluster'",
")",
"return",
";",
"var",
"rawBone",
"=",
"{",
"ID",
":",
"child",
".",
"ID",
",",
"indices",
":",
"[",
"]",
",",
"weights",
":",
"[",
"]",
",",
"transform",
":",
"new",
"THREE",
".",
"Matrix4",
"(",
")",
".",
"fromArray",
"(",
"boneNode",
".",
"Transform",
".",
"a",
")",
",",
"transformLink",
":",
"new",
"THREE",
".",
"Matrix4",
"(",
")",
".",
"fromArray",
"(",
"boneNode",
".",
"TransformLink",
".",
"a",
")",
",",
"linkMode",
":",
"boneNode",
".",
"Mode",
",",
"}",
";",
"if",
"(",
"'Indexes'",
"in",
"boneNode",
")",
"{",
"rawBone",
".",
"indices",
"=",
"boneNode",
".",
"Indexes",
".",
"a",
";",
"rawBone",
".",
"weights",
"=",
"boneNode",
".",
"Weights",
".",
"a",
";",
"}",
"rawBones",
".",
"push",
"(",
"rawBone",
")",
";",
"}",
")",
";",
"return",
"{",
"rawBones",
":",
"rawBones",
",",
"bones",
":",
"[",
"]",
"}",
";",
"}"
] | Parse single nodes in FBXTree.Objects.Deformer The top level skeleton node has type 'Skin' and sub nodes have type 'Cluster' Each skin node represents a skeleton and each cluster node represents a bone | [
"Parse",
"single",
"nodes",
"in",
"FBXTree",
".",
"Objects",
".",
"Deformer",
"The",
"top",
"level",
"skeleton",
"node",
"has",
"type",
"Skin",
"and",
"sub",
"nodes",
"have",
"type",
"Cluster",
"Each",
"skin",
"node",
"represents",
"a",
"skeleton",
"and",
"each",
"cluster",
"node",
"represents",
"a",
"bone"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L698-L737 |
|
7,855 | exokitxr/exokit | examples/FBXLoader.js | function ( relationships, deformerNodes ) {
var rawMorphTargets = [];
for ( var i = 0; i < relationships.children.length; i ++ ) {
if ( i === 8 ) {
console.warn( 'FBXLoader: maximum of 8 morph targets supported. Ignoring additional targets.' );
break;
}
var child = relationships.children[ i ];
var morphTargetNode = deformerNodes[ child.ID ];
var rawMorphTarget = {
name: morphTargetNode.attrName,
initialWeight: morphTargetNode.DeformPercent,
id: morphTargetNode.id,
fullWeights: morphTargetNode.FullWeights.a
};
if ( morphTargetNode.attrType !== 'BlendShapeChannel' ) return;
var targetRelationships = connections.get( parseInt( child.ID ) );
targetRelationships.children.forEach( function ( child ) {
if ( child.relationship === undefined ) rawMorphTarget.geoID = child.ID;
} );
rawMorphTargets.push( rawMorphTarget );
}
return rawMorphTargets;
} | javascript | function ( relationships, deformerNodes ) {
var rawMorphTargets = [];
for ( var i = 0; i < relationships.children.length; i ++ ) {
if ( i === 8 ) {
console.warn( 'FBXLoader: maximum of 8 morph targets supported. Ignoring additional targets.' );
break;
}
var child = relationships.children[ i ];
var morphTargetNode = deformerNodes[ child.ID ];
var rawMorphTarget = {
name: morphTargetNode.attrName,
initialWeight: morphTargetNode.DeformPercent,
id: morphTargetNode.id,
fullWeights: morphTargetNode.FullWeights.a
};
if ( morphTargetNode.attrType !== 'BlendShapeChannel' ) return;
var targetRelationships = connections.get( parseInt( child.ID ) );
targetRelationships.children.forEach( function ( child ) {
if ( child.relationship === undefined ) rawMorphTarget.geoID = child.ID;
} );
rawMorphTargets.push( rawMorphTarget );
}
return rawMorphTargets;
} | [
"function",
"(",
"relationships",
",",
"deformerNodes",
")",
"{",
"var",
"rawMorphTargets",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"relationships",
".",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"===",
"8",
")",
"{",
"console",
".",
"warn",
"(",
"'FBXLoader: maximum of 8 morph targets supported. Ignoring additional targets.'",
")",
";",
"break",
";",
"}",
"var",
"child",
"=",
"relationships",
".",
"children",
"[",
"i",
"]",
";",
"var",
"morphTargetNode",
"=",
"deformerNodes",
"[",
"child",
".",
"ID",
"]",
";",
"var",
"rawMorphTarget",
"=",
"{",
"name",
":",
"morphTargetNode",
".",
"attrName",
",",
"initialWeight",
":",
"morphTargetNode",
".",
"DeformPercent",
",",
"id",
":",
"morphTargetNode",
".",
"id",
",",
"fullWeights",
":",
"morphTargetNode",
".",
"FullWeights",
".",
"a",
"}",
";",
"if",
"(",
"morphTargetNode",
".",
"attrType",
"!==",
"'BlendShapeChannel'",
")",
"return",
";",
"var",
"targetRelationships",
"=",
"connections",
".",
"get",
"(",
"parseInt",
"(",
"child",
".",
"ID",
")",
")",
";",
"targetRelationships",
".",
"children",
".",
"forEach",
"(",
"function",
"(",
"child",
")",
"{",
"if",
"(",
"child",
".",
"relationship",
"===",
"undefined",
")",
"rawMorphTarget",
".",
"geoID",
"=",
"child",
".",
"ID",
";",
"}",
")",
";",
"rawMorphTargets",
".",
"push",
"(",
"rawMorphTarget",
")",
";",
"}",
"return",
"rawMorphTargets",
";",
"}"
] | The top level morph deformer node has type "BlendShape" and sub nodes have type "BlendShapeChannel" | [
"The",
"top",
"level",
"morph",
"deformer",
"node",
"has",
"type",
"BlendShape",
"and",
"sub",
"nodes",
"have",
"type",
"BlendShapeChannel"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L740-L783 |
|
7,856 | exokitxr/exokit | examples/FBXLoader.js | function ( skeletons, geometryMap, materialMap ) {
var modelMap = new Map();
var modelNodes = fbxTree.Objects.Model;
for ( var nodeID in modelNodes ) {
var id = parseInt( nodeID );
var node = modelNodes[ nodeID ];
var relationships = connections.get( id );
var model = this.buildSkeleton( relationships, skeletons, id, node.attrName );
if ( ! model ) {
switch ( node.attrType ) {
case 'Camera':
model = this.createCamera( relationships );
break;
case 'Light':
model = this.createLight( relationships );
break;
case 'Mesh':
model = this.createMesh( relationships, geometryMap, materialMap );
break;
case 'NurbsCurve':
model = this.createCurve( relationships, geometryMap );
break;
case 'LimbNode': // usually associated with a Bone, however if a Bone was not created we'll make a Group instead
case 'Null':
default:
model = new THREE.Group();
break;
}
model.name = THREE.PropertyBinding.sanitizeNodeName( node.attrName );
model.ID = id;
}
this.setModelTransforms( model, node );
modelMap.set( id, model );
}
return modelMap;
} | javascript | function ( skeletons, geometryMap, materialMap ) {
var modelMap = new Map();
var modelNodes = fbxTree.Objects.Model;
for ( var nodeID in modelNodes ) {
var id = parseInt( nodeID );
var node = modelNodes[ nodeID ];
var relationships = connections.get( id );
var model = this.buildSkeleton( relationships, skeletons, id, node.attrName );
if ( ! model ) {
switch ( node.attrType ) {
case 'Camera':
model = this.createCamera( relationships );
break;
case 'Light':
model = this.createLight( relationships );
break;
case 'Mesh':
model = this.createMesh( relationships, geometryMap, materialMap );
break;
case 'NurbsCurve':
model = this.createCurve( relationships, geometryMap );
break;
case 'LimbNode': // usually associated with a Bone, however if a Bone was not created we'll make a Group instead
case 'Null':
default:
model = new THREE.Group();
break;
}
model.name = THREE.PropertyBinding.sanitizeNodeName( node.attrName );
model.ID = id;
}
this.setModelTransforms( model, node );
modelMap.set( id, model );
}
return modelMap;
} | [
"function",
"(",
"skeletons",
",",
"geometryMap",
",",
"materialMap",
")",
"{",
"var",
"modelMap",
"=",
"new",
"Map",
"(",
")",
";",
"var",
"modelNodes",
"=",
"fbxTree",
".",
"Objects",
".",
"Model",
";",
"for",
"(",
"var",
"nodeID",
"in",
"modelNodes",
")",
"{",
"var",
"id",
"=",
"parseInt",
"(",
"nodeID",
")",
";",
"var",
"node",
"=",
"modelNodes",
"[",
"nodeID",
"]",
";",
"var",
"relationships",
"=",
"connections",
".",
"get",
"(",
"id",
")",
";",
"var",
"model",
"=",
"this",
".",
"buildSkeleton",
"(",
"relationships",
",",
"skeletons",
",",
"id",
",",
"node",
".",
"attrName",
")",
";",
"if",
"(",
"!",
"model",
")",
"{",
"switch",
"(",
"node",
".",
"attrType",
")",
"{",
"case",
"'Camera'",
":",
"model",
"=",
"this",
".",
"createCamera",
"(",
"relationships",
")",
";",
"break",
";",
"case",
"'Light'",
":",
"model",
"=",
"this",
".",
"createLight",
"(",
"relationships",
")",
";",
"break",
";",
"case",
"'Mesh'",
":",
"model",
"=",
"this",
".",
"createMesh",
"(",
"relationships",
",",
"geometryMap",
",",
"materialMap",
")",
";",
"break",
";",
"case",
"'NurbsCurve'",
":",
"model",
"=",
"this",
".",
"createCurve",
"(",
"relationships",
",",
"geometryMap",
")",
";",
"break",
";",
"case",
"'LimbNode'",
":",
"// usually associated with a Bone, however if a Bone was not created we'll make a Group instead",
"case",
"'Null'",
":",
"default",
":",
"model",
"=",
"new",
"THREE",
".",
"Group",
"(",
")",
";",
"break",
";",
"}",
"model",
".",
"name",
"=",
"THREE",
".",
"PropertyBinding",
".",
"sanitizeNodeName",
"(",
"node",
".",
"attrName",
")",
";",
"model",
".",
"ID",
"=",
"id",
";",
"}",
"this",
".",
"setModelTransforms",
"(",
"model",
",",
"node",
")",
";",
"modelMap",
".",
"set",
"(",
"id",
",",
"model",
")",
";",
"}",
"return",
"modelMap",
";",
"}"
] | parse nodes in FBXTree.Objects.Model | [
"parse",
"nodes",
"in",
"FBXTree",
".",
"Objects",
".",
"Model"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L839-L888 |
|
7,857 | exokitxr/exokit | examples/FBXLoader.js | function ( relationships ) {
var model;
var cameraAttribute;
relationships.children.forEach( function ( child ) {
var attr = fbxTree.Objects.NodeAttribute[ child.ID ];
if ( attr !== undefined ) {
cameraAttribute = attr;
}
} );
if ( cameraAttribute === undefined ) {
model = new THREE.Object3D();
} else {
var type = 0;
if ( cameraAttribute.CameraProjectionType !== undefined && cameraAttribute.CameraProjectionType.value === 1 ) {
type = 1;
}
var nearClippingPlane = 1;
if ( cameraAttribute.NearPlane !== undefined ) {
nearClippingPlane = cameraAttribute.NearPlane.value / 1000;
}
var farClippingPlane = 1000;
if ( cameraAttribute.FarPlane !== undefined ) {
farClippingPlane = cameraAttribute.FarPlane.value / 1000;
}
var width = window.innerWidth;
var height = window.innerHeight;
if ( cameraAttribute.AspectWidth !== undefined && cameraAttribute.AspectHeight !== undefined ) {
width = cameraAttribute.AspectWidth.value;
height = cameraAttribute.AspectHeight.value;
}
var aspect = width / height;
var fov = 45;
if ( cameraAttribute.FieldOfView !== undefined ) {
fov = cameraAttribute.FieldOfView.value;
}
var focalLength = cameraAttribute.FocalLength ? cameraAttribute.FocalLength.value : null;
switch ( type ) {
case 0: // Perspective
model = new THREE.PerspectiveCamera( fov, aspect, nearClippingPlane, farClippingPlane );
if ( focalLength !== null ) model.setFocalLength( focalLength );
break;
case 1: // Orthographic
model = new THREE.OrthographicCamera( - width / 2, width / 2, height / 2, - height / 2, nearClippingPlane, farClippingPlane );
break;
default:
console.warn( 'THREE.FBXLoader: Unknown camera type ' + type + '.' );
model = new THREE.Object3D();
break;
}
}
return model;
} | javascript | function ( relationships ) {
var model;
var cameraAttribute;
relationships.children.forEach( function ( child ) {
var attr = fbxTree.Objects.NodeAttribute[ child.ID ];
if ( attr !== undefined ) {
cameraAttribute = attr;
}
} );
if ( cameraAttribute === undefined ) {
model = new THREE.Object3D();
} else {
var type = 0;
if ( cameraAttribute.CameraProjectionType !== undefined && cameraAttribute.CameraProjectionType.value === 1 ) {
type = 1;
}
var nearClippingPlane = 1;
if ( cameraAttribute.NearPlane !== undefined ) {
nearClippingPlane = cameraAttribute.NearPlane.value / 1000;
}
var farClippingPlane = 1000;
if ( cameraAttribute.FarPlane !== undefined ) {
farClippingPlane = cameraAttribute.FarPlane.value / 1000;
}
var width = window.innerWidth;
var height = window.innerHeight;
if ( cameraAttribute.AspectWidth !== undefined && cameraAttribute.AspectHeight !== undefined ) {
width = cameraAttribute.AspectWidth.value;
height = cameraAttribute.AspectHeight.value;
}
var aspect = width / height;
var fov = 45;
if ( cameraAttribute.FieldOfView !== undefined ) {
fov = cameraAttribute.FieldOfView.value;
}
var focalLength = cameraAttribute.FocalLength ? cameraAttribute.FocalLength.value : null;
switch ( type ) {
case 0: // Perspective
model = new THREE.PerspectiveCamera( fov, aspect, nearClippingPlane, farClippingPlane );
if ( focalLength !== null ) model.setFocalLength( focalLength );
break;
case 1: // Orthographic
model = new THREE.OrthographicCamera( - width / 2, width / 2, height / 2, - height / 2, nearClippingPlane, farClippingPlane );
break;
default:
console.warn( 'THREE.FBXLoader: Unknown camera type ' + type + '.' );
model = new THREE.Object3D();
break;
}
}
return model;
} | [
"function",
"(",
"relationships",
")",
"{",
"var",
"model",
";",
"var",
"cameraAttribute",
";",
"relationships",
".",
"children",
".",
"forEach",
"(",
"function",
"(",
"child",
")",
"{",
"var",
"attr",
"=",
"fbxTree",
".",
"Objects",
".",
"NodeAttribute",
"[",
"child",
".",
"ID",
"]",
";",
"if",
"(",
"attr",
"!==",
"undefined",
")",
"{",
"cameraAttribute",
"=",
"attr",
";",
"}",
"}",
")",
";",
"if",
"(",
"cameraAttribute",
"===",
"undefined",
")",
"{",
"model",
"=",
"new",
"THREE",
".",
"Object3D",
"(",
")",
";",
"}",
"else",
"{",
"var",
"type",
"=",
"0",
";",
"if",
"(",
"cameraAttribute",
".",
"CameraProjectionType",
"!==",
"undefined",
"&&",
"cameraAttribute",
".",
"CameraProjectionType",
".",
"value",
"===",
"1",
")",
"{",
"type",
"=",
"1",
";",
"}",
"var",
"nearClippingPlane",
"=",
"1",
";",
"if",
"(",
"cameraAttribute",
".",
"NearPlane",
"!==",
"undefined",
")",
"{",
"nearClippingPlane",
"=",
"cameraAttribute",
".",
"NearPlane",
".",
"value",
"/",
"1000",
";",
"}",
"var",
"farClippingPlane",
"=",
"1000",
";",
"if",
"(",
"cameraAttribute",
".",
"FarPlane",
"!==",
"undefined",
")",
"{",
"farClippingPlane",
"=",
"cameraAttribute",
".",
"FarPlane",
".",
"value",
"/",
"1000",
";",
"}",
"var",
"width",
"=",
"window",
".",
"innerWidth",
";",
"var",
"height",
"=",
"window",
".",
"innerHeight",
";",
"if",
"(",
"cameraAttribute",
".",
"AspectWidth",
"!==",
"undefined",
"&&",
"cameraAttribute",
".",
"AspectHeight",
"!==",
"undefined",
")",
"{",
"width",
"=",
"cameraAttribute",
".",
"AspectWidth",
".",
"value",
";",
"height",
"=",
"cameraAttribute",
".",
"AspectHeight",
".",
"value",
";",
"}",
"var",
"aspect",
"=",
"width",
"/",
"height",
";",
"var",
"fov",
"=",
"45",
";",
"if",
"(",
"cameraAttribute",
".",
"FieldOfView",
"!==",
"undefined",
")",
"{",
"fov",
"=",
"cameraAttribute",
".",
"FieldOfView",
".",
"value",
";",
"}",
"var",
"focalLength",
"=",
"cameraAttribute",
".",
"FocalLength",
"?",
"cameraAttribute",
".",
"FocalLength",
".",
"value",
":",
"null",
";",
"switch",
"(",
"type",
")",
"{",
"case",
"0",
":",
"// Perspective",
"model",
"=",
"new",
"THREE",
".",
"PerspectiveCamera",
"(",
"fov",
",",
"aspect",
",",
"nearClippingPlane",
",",
"farClippingPlane",
")",
";",
"if",
"(",
"focalLength",
"!==",
"null",
")",
"model",
".",
"setFocalLength",
"(",
"focalLength",
")",
";",
"break",
";",
"case",
"1",
":",
"// Orthographic",
"model",
"=",
"new",
"THREE",
".",
"OrthographicCamera",
"(",
"-",
"width",
"/",
"2",
",",
"width",
"/",
"2",
",",
"height",
"/",
"2",
",",
"-",
"height",
"/",
"2",
",",
"nearClippingPlane",
",",
"farClippingPlane",
")",
";",
"break",
";",
"default",
":",
"console",
".",
"warn",
"(",
"'THREE.FBXLoader: Unknown camera type '",
"+",
"type",
"+",
"'.'",
")",
";",
"model",
"=",
"new",
"THREE",
".",
"Object3D",
"(",
")",
";",
"break",
";",
"}",
"}",
"return",
"model",
";",
"}"
] | create a THREE.PerspectiveCamera or THREE.OrthographicCamera | [
"create",
"a",
"THREE",
".",
"PerspectiveCamera",
"or",
"THREE",
".",
"OrthographicCamera"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L935-L1023 |
|
7,858 | exokitxr/exokit | examples/FBXLoader.js | function ( relationships ) {
var model;
var lightAttribute;
relationships.children.forEach( function ( child ) {
var attr = fbxTree.Objects.NodeAttribute[ child.ID ];
if ( attr !== undefined ) {
lightAttribute = attr;
}
} );
if ( lightAttribute === undefined ) {
model = new THREE.Object3D();
} else {
var type;
// LightType can be undefined for Point lights
if ( lightAttribute.LightType === undefined ) {
type = 0;
} else {
type = lightAttribute.LightType.value;
}
var color = 0xffffff;
if ( lightAttribute.Color !== undefined ) {
color = new THREE.Color().fromArray( lightAttribute.Color.value );
}
var intensity = ( lightAttribute.Intensity === undefined ) ? 1 : lightAttribute.Intensity.value / 100;
// light disabled
if ( lightAttribute.CastLightOnObject !== undefined && lightAttribute.CastLightOnObject.value === 0 ) {
intensity = 0;
}
var distance = 0;
if ( lightAttribute.FarAttenuationEnd !== undefined ) {
if ( lightAttribute.EnableFarAttenuation !== undefined && lightAttribute.EnableFarAttenuation.value === 0 ) {
distance = 0;
} else {
distance = lightAttribute.FarAttenuationEnd.value;
}
}
// TODO: could this be calculated linearly from FarAttenuationStart to FarAttenuationEnd?
var decay = 1;
switch ( type ) {
case 0: // Point
model = new THREE.PointLight( color, intensity, distance, decay );
break;
case 1: // Directional
model = new THREE.DirectionalLight( color, intensity );
break;
case 2: // Spot
var angle = Math.PI / 3;
if ( lightAttribute.InnerAngle !== undefined ) {
angle = THREE.Math.degToRad( lightAttribute.InnerAngle.value );
}
var penumbra = 0;
if ( lightAttribute.OuterAngle !== undefined ) {
// TODO: this is not correct - FBX calculates outer and inner angle in degrees
// with OuterAngle > InnerAngle && OuterAngle <= Math.PI
// while three.js uses a penumbra between (0, 1) to attenuate the inner angle
penumbra = THREE.Math.degToRad( lightAttribute.OuterAngle.value );
penumbra = Math.max( penumbra, 1 );
}
model = new THREE.SpotLight( color, intensity, distance, angle, penumbra, decay );
break;
default:
console.warn( 'THREE.FBXLoader: Unknown light type ' + lightAttribute.LightType.value + ', defaulting to a THREE.PointLight.' );
model = new THREE.PointLight( color, intensity );
break;
}
if ( lightAttribute.CastShadows !== undefined && lightAttribute.CastShadows.value === 1 ) {
model.castShadow = true;
}
}
return model;
} | javascript | function ( relationships ) {
var model;
var lightAttribute;
relationships.children.forEach( function ( child ) {
var attr = fbxTree.Objects.NodeAttribute[ child.ID ];
if ( attr !== undefined ) {
lightAttribute = attr;
}
} );
if ( lightAttribute === undefined ) {
model = new THREE.Object3D();
} else {
var type;
// LightType can be undefined for Point lights
if ( lightAttribute.LightType === undefined ) {
type = 0;
} else {
type = lightAttribute.LightType.value;
}
var color = 0xffffff;
if ( lightAttribute.Color !== undefined ) {
color = new THREE.Color().fromArray( lightAttribute.Color.value );
}
var intensity = ( lightAttribute.Intensity === undefined ) ? 1 : lightAttribute.Intensity.value / 100;
// light disabled
if ( lightAttribute.CastLightOnObject !== undefined && lightAttribute.CastLightOnObject.value === 0 ) {
intensity = 0;
}
var distance = 0;
if ( lightAttribute.FarAttenuationEnd !== undefined ) {
if ( lightAttribute.EnableFarAttenuation !== undefined && lightAttribute.EnableFarAttenuation.value === 0 ) {
distance = 0;
} else {
distance = lightAttribute.FarAttenuationEnd.value;
}
}
// TODO: could this be calculated linearly from FarAttenuationStart to FarAttenuationEnd?
var decay = 1;
switch ( type ) {
case 0: // Point
model = new THREE.PointLight( color, intensity, distance, decay );
break;
case 1: // Directional
model = new THREE.DirectionalLight( color, intensity );
break;
case 2: // Spot
var angle = Math.PI / 3;
if ( lightAttribute.InnerAngle !== undefined ) {
angle = THREE.Math.degToRad( lightAttribute.InnerAngle.value );
}
var penumbra = 0;
if ( lightAttribute.OuterAngle !== undefined ) {
// TODO: this is not correct - FBX calculates outer and inner angle in degrees
// with OuterAngle > InnerAngle && OuterAngle <= Math.PI
// while three.js uses a penumbra between (0, 1) to attenuate the inner angle
penumbra = THREE.Math.degToRad( lightAttribute.OuterAngle.value );
penumbra = Math.max( penumbra, 1 );
}
model = new THREE.SpotLight( color, intensity, distance, angle, penumbra, decay );
break;
default:
console.warn( 'THREE.FBXLoader: Unknown light type ' + lightAttribute.LightType.value + ', defaulting to a THREE.PointLight.' );
model = new THREE.PointLight( color, intensity );
break;
}
if ( lightAttribute.CastShadows !== undefined && lightAttribute.CastShadows.value === 1 ) {
model.castShadow = true;
}
}
return model;
} | [
"function",
"(",
"relationships",
")",
"{",
"var",
"model",
";",
"var",
"lightAttribute",
";",
"relationships",
".",
"children",
".",
"forEach",
"(",
"function",
"(",
"child",
")",
"{",
"var",
"attr",
"=",
"fbxTree",
".",
"Objects",
".",
"NodeAttribute",
"[",
"child",
".",
"ID",
"]",
";",
"if",
"(",
"attr",
"!==",
"undefined",
")",
"{",
"lightAttribute",
"=",
"attr",
";",
"}",
"}",
")",
";",
"if",
"(",
"lightAttribute",
"===",
"undefined",
")",
"{",
"model",
"=",
"new",
"THREE",
".",
"Object3D",
"(",
")",
";",
"}",
"else",
"{",
"var",
"type",
";",
"// LightType can be undefined for Point lights",
"if",
"(",
"lightAttribute",
".",
"LightType",
"===",
"undefined",
")",
"{",
"type",
"=",
"0",
";",
"}",
"else",
"{",
"type",
"=",
"lightAttribute",
".",
"LightType",
".",
"value",
";",
"}",
"var",
"color",
"=",
"0xffffff",
";",
"if",
"(",
"lightAttribute",
".",
"Color",
"!==",
"undefined",
")",
"{",
"color",
"=",
"new",
"THREE",
".",
"Color",
"(",
")",
".",
"fromArray",
"(",
"lightAttribute",
".",
"Color",
".",
"value",
")",
";",
"}",
"var",
"intensity",
"=",
"(",
"lightAttribute",
".",
"Intensity",
"===",
"undefined",
")",
"?",
"1",
":",
"lightAttribute",
".",
"Intensity",
".",
"value",
"/",
"100",
";",
"// light disabled",
"if",
"(",
"lightAttribute",
".",
"CastLightOnObject",
"!==",
"undefined",
"&&",
"lightAttribute",
".",
"CastLightOnObject",
".",
"value",
"===",
"0",
")",
"{",
"intensity",
"=",
"0",
";",
"}",
"var",
"distance",
"=",
"0",
";",
"if",
"(",
"lightAttribute",
".",
"FarAttenuationEnd",
"!==",
"undefined",
")",
"{",
"if",
"(",
"lightAttribute",
".",
"EnableFarAttenuation",
"!==",
"undefined",
"&&",
"lightAttribute",
".",
"EnableFarAttenuation",
".",
"value",
"===",
"0",
")",
"{",
"distance",
"=",
"0",
";",
"}",
"else",
"{",
"distance",
"=",
"lightAttribute",
".",
"FarAttenuationEnd",
".",
"value",
";",
"}",
"}",
"// TODO: could this be calculated linearly from FarAttenuationStart to FarAttenuationEnd?",
"var",
"decay",
"=",
"1",
";",
"switch",
"(",
"type",
")",
"{",
"case",
"0",
":",
"// Point",
"model",
"=",
"new",
"THREE",
".",
"PointLight",
"(",
"color",
",",
"intensity",
",",
"distance",
",",
"decay",
")",
";",
"break",
";",
"case",
"1",
":",
"// Directional",
"model",
"=",
"new",
"THREE",
".",
"DirectionalLight",
"(",
"color",
",",
"intensity",
")",
";",
"break",
";",
"case",
"2",
":",
"// Spot",
"var",
"angle",
"=",
"Math",
".",
"PI",
"/",
"3",
";",
"if",
"(",
"lightAttribute",
".",
"InnerAngle",
"!==",
"undefined",
")",
"{",
"angle",
"=",
"THREE",
".",
"Math",
".",
"degToRad",
"(",
"lightAttribute",
".",
"InnerAngle",
".",
"value",
")",
";",
"}",
"var",
"penumbra",
"=",
"0",
";",
"if",
"(",
"lightAttribute",
".",
"OuterAngle",
"!==",
"undefined",
")",
"{",
"// TODO: this is not correct - FBX calculates outer and inner angle in degrees",
"// with OuterAngle > InnerAngle && OuterAngle <= Math.PI",
"// while three.js uses a penumbra between (0, 1) to attenuate the inner angle",
"penumbra",
"=",
"THREE",
".",
"Math",
".",
"degToRad",
"(",
"lightAttribute",
".",
"OuterAngle",
".",
"value",
")",
";",
"penumbra",
"=",
"Math",
".",
"max",
"(",
"penumbra",
",",
"1",
")",
";",
"}",
"model",
"=",
"new",
"THREE",
".",
"SpotLight",
"(",
"color",
",",
"intensity",
",",
"distance",
",",
"angle",
",",
"penumbra",
",",
"decay",
")",
";",
"break",
";",
"default",
":",
"console",
".",
"warn",
"(",
"'THREE.FBXLoader: Unknown light type '",
"+",
"lightAttribute",
".",
"LightType",
".",
"value",
"+",
"', defaulting to a THREE.PointLight.'",
")",
";",
"model",
"=",
"new",
"THREE",
".",
"PointLight",
"(",
"color",
",",
"intensity",
")",
";",
"break",
";",
"}",
"if",
"(",
"lightAttribute",
".",
"CastShadows",
"!==",
"undefined",
"&&",
"lightAttribute",
".",
"CastShadows",
".",
"value",
"===",
"1",
")",
"{",
"model",
".",
"castShadow",
"=",
"true",
";",
"}",
"}",
"return",
"model",
";",
"}"
] | Create a THREE.DirectionalLight, THREE.PointLight or THREE.SpotLight | [
"Create",
"a",
"THREE",
".",
"DirectionalLight",
"THREE",
".",
"PointLight",
"or",
"THREE",
".",
"SpotLight"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L1026-L1147 |
|
7,859 | exokitxr/exokit | examples/FBXLoader.js | function ( deformers ) {
var geometryMap = new Map();
if ( 'Geometry' in fbxTree.Objects ) {
var geoNodes = fbxTree.Objects.Geometry;
for ( var nodeID in geoNodes ) {
var relationships = connections.get( parseInt( nodeID ) );
var geo = this.parseGeometry( relationships, geoNodes[ nodeID ], deformers );
geometryMap.set( parseInt( nodeID ), geo );
}
}
return geometryMap;
} | javascript | function ( deformers ) {
var geometryMap = new Map();
if ( 'Geometry' in fbxTree.Objects ) {
var geoNodes = fbxTree.Objects.Geometry;
for ( var nodeID in geoNodes ) {
var relationships = connections.get( parseInt( nodeID ) );
var geo = this.parseGeometry( relationships, geoNodes[ nodeID ], deformers );
geometryMap.set( parseInt( nodeID ), geo );
}
}
return geometryMap;
} | [
"function",
"(",
"deformers",
")",
"{",
"var",
"geometryMap",
"=",
"new",
"Map",
"(",
")",
";",
"if",
"(",
"'Geometry'",
"in",
"fbxTree",
".",
"Objects",
")",
"{",
"var",
"geoNodes",
"=",
"fbxTree",
".",
"Objects",
".",
"Geometry",
";",
"for",
"(",
"var",
"nodeID",
"in",
"geoNodes",
")",
"{",
"var",
"relationships",
"=",
"connections",
".",
"get",
"(",
"parseInt",
"(",
"nodeID",
")",
")",
";",
"var",
"geo",
"=",
"this",
".",
"parseGeometry",
"(",
"relationships",
",",
"geoNodes",
"[",
"nodeID",
"]",
",",
"deformers",
")",
";",
"geometryMap",
".",
"set",
"(",
"parseInt",
"(",
"nodeID",
")",
",",
"geo",
")",
";",
"}",
"}",
"return",
"geometryMap",
";",
"}"
] | Parse nodes in FBXTree.Objects.Geometry | [
"Parse",
"nodes",
"in",
"FBXTree",
".",
"Objects",
".",
"Geometry"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L1433-L1454 |
|
7,860 | exokitxr/exokit | examples/FBXLoader.js | function ( relationships, geoNode, deformers ) {
switch ( geoNode.attrType ) {
case 'Mesh':
return this.parseMeshGeometry( relationships, geoNode, deformers );
break;
case 'NurbsCurve':
return this.parseNurbsGeometry( geoNode );
break;
}
} | javascript | function ( relationships, geoNode, deformers ) {
switch ( geoNode.attrType ) {
case 'Mesh':
return this.parseMeshGeometry( relationships, geoNode, deformers );
break;
case 'NurbsCurve':
return this.parseNurbsGeometry( geoNode );
break;
}
} | [
"function",
"(",
"relationships",
",",
"geoNode",
",",
"deformers",
")",
"{",
"switch",
"(",
"geoNode",
".",
"attrType",
")",
"{",
"case",
"'Mesh'",
":",
"return",
"this",
".",
"parseMeshGeometry",
"(",
"relationships",
",",
"geoNode",
",",
"deformers",
")",
";",
"break",
";",
"case",
"'NurbsCurve'",
":",
"return",
"this",
".",
"parseNurbsGeometry",
"(",
"geoNode",
")",
";",
"break",
";",
"}",
"}"
] | Parse single node in FBXTree.Objects.Geometry | [
"Parse",
"single",
"node",
"in",
"FBXTree",
".",
"Objects",
".",
"Geometry"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L1457-L1471 |
|
7,861 | exokitxr/exokit | examples/FBXLoader.js | function ( relationships, geoNode, deformers ) {
var skeletons = deformers.skeletons;
var morphTargets = deformers.morphTargets;
var modelNodes = relationships.parents.map( function ( parent ) {
return fbxTree.Objects.Model[ parent.ID ];
} );
// don't create geometry if it is not associated with any models
if ( modelNodes.length === 0 ) return;
var skeleton = relationships.children.reduce( function ( skeleton, child ) {
if ( skeletons[ child.ID ] !== undefined ) skeleton = skeletons[ child.ID ];
return skeleton;
}, null );
var morphTarget = relationships.children.reduce( function ( morphTarget, child ) {
if ( morphTargets[ child.ID ] !== undefined ) morphTarget = morphTargets[ child.ID ];
return morphTarget;
}, null );
// TODO: if there is more than one model associated with the geometry, AND the models have
// different geometric transforms, then this will cause problems
// if ( modelNodes.length > 1 ) { }
// For now just assume one model and get the preRotations from that
var modelNode = modelNodes[ 0 ];
var transformData = {};
if ( 'RotationOrder' in modelNode ) transformData.eulerOrder = modelNode.RotationOrder.value;
if ( 'GeometricTranslation' in modelNode ) transformData.translation = modelNode.GeometricTranslation.value;
if ( 'GeometricRotation' in modelNode ) transformData.rotation = modelNode.GeometricRotation.value;
if ( 'GeometricScaling' in modelNode ) transformData.scale = modelNode.GeometricScaling.value;
var transform = generateTransform( transformData );
return this.genGeometry( geoNode, skeleton, morphTarget, transform );
} | javascript | function ( relationships, geoNode, deformers ) {
var skeletons = deformers.skeletons;
var morphTargets = deformers.morphTargets;
var modelNodes = relationships.parents.map( function ( parent ) {
return fbxTree.Objects.Model[ parent.ID ];
} );
// don't create geometry if it is not associated with any models
if ( modelNodes.length === 0 ) return;
var skeleton = relationships.children.reduce( function ( skeleton, child ) {
if ( skeletons[ child.ID ] !== undefined ) skeleton = skeletons[ child.ID ];
return skeleton;
}, null );
var morphTarget = relationships.children.reduce( function ( morphTarget, child ) {
if ( morphTargets[ child.ID ] !== undefined ) morphTarget = morphTargets[ child.ID ];
return morphTarget;
}, null );
// TODO: if there is more than one model associated with the geometry, AND the models have
// different geometric transforms, then this will cause problems
// if ( modelNodes.length > 1 ) { }
// For now just assume one model and get the preRotations from that
var modelNode = modelNodes[ 0 ];
var transformData = {};
if ( 'RotationOrder' in modelNode ) transformData.eulerOrder = modelNode.RotationOrder.value;
if ( 'GeometricTranslation' in modelNode ) transformData.translation = modelNode.GeometricTranslation.value;
if ( 'GeometricRotation' in modelNode ) transformData.rotation = modelNode.GeometricRotation.value;
if ( 'GeometricScaling' in modelNode ) transformData.scale = modelNode.GeometricScaling.value;
var transform = generateTransform( transformData );
return this.genGeometry( geoNode, skeleton, morphTarget, transform );
} | [
"function",
"(",
"relationships",
",",
"geoNode",
",",
"deformers",
")",
"{",
"var",
"skeletons",
"=",
"deformers",
".",
"skeletons",
";",
"var",
"morphTargets",
"=",
"deformers",
".",
"morphTargets",
";",
"var",
"modelNodes",
"=",
"relationships",
".",
"parents",
".",
"map",
"(",
"function",
"(",
"parent",
")",
"{",
"return",
"fbxTree",
".",
"Objects",
".",
"Model",
"[",
"parent",
".",
"ID",
"]",
";",
"}",
")",
";",
"// don't create geometry if it is not associated with any models",
"if",
"(",
"modelNodes",
".",
"length",
"===",
"0",
")",
"return",
";",
"var",
"skeleton",
"=",
"relationships",
".",
"children",
".",
"reduce",
"(",
"function",
"(",
"skeleton",
",",
"child",
")",
"{",
"if",
"(",
"skeletons",
"[",
"child",
".",
"ID",
"]",
"!==",
"undefined",
")",
"skeleton",
"=",
"skeletons",
"[",
"child",
".",
"ID",
"]",
";",
"return",
"skeleton",
";",
"}",
",",
"null",
")",
";",
"var",
"morphTarget",
"=",
"relationships",
".",
"children",
".",
"reduce",
"(",
"function",
"(",
"morphTarget",
",",
"child",
")",
"{",
"if",
"(",
"morphTargets",
"[",
"child",
".",
"ID",
"]",
"!==",
"undefined",
")",
"morphTarget",
"=",
"morphTargets",
"[",
"child",
".",
"ID",
"]",
";",
"return",
"morphTarget",
";",
"}",
",",
"null",
")",
";",
"// TODO: if there is more than one model associated with the geometry, AND the models have",
"// different geometric transforms, then this will cause problems",
"// if ( modelNodes.length > 1 ) { }",
"// For now just assume one model and get the preRotations from that",
"var",
"modelNode",
"=",
"modelNodes",
"[",
"0",
"]",
";",
"var",
"transformData",
"=",
"{",
"}",
";",
"if",
"(",
"'RotationOrder'",
"in",
"modelNode",
")",
"transformData",
".",
"eulerOrder",
"=",
"modelNode",
".",
"RotationOrder",
".",
"value",
";",
"if",
"(",
"'GeometricTranslation'",
"in",
"modelNode",
")",
"transformData",
".",
"translation",
"=",
"modelNode",
".",
"GeometricTranslation",
".",
"value",
";",
"if",
"(",
"'GeometricRotation'",
"in",
"modelNode",
")",
"transformData",
".",
"rotation",
"=",
"modelNode",
".",
"GeometricRotation",
".",
"value",
";",
"if",
"(",
"'GeometricScaling'",
"in",
"modelNode",
")",
"transformData",
".",
"scale",
"=",
"modelNode",
".",
"GeometricScaling",
".",
"value",
";",
"var",
"transform",
"=",
"generateTransform",
"(",
"transformData",
")",
";",
"return",
"this",
".",
"genGeometry",
"(",
"geoNode",
",",
"skeleton",
",",
"morphTarget",
",",
"transform",
")",
";",
"}"
] | Parse single node mesh geometry in FBXTree.Objects.Geometry | [
"Parse",
"single",
"node",
"mesh",
"geometry",
"in",
"FBXTree",
".",
"Objects",
".",
"Geometry"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L1474-L1522 |
|
7,862 | exokitxr/exokit | examples/FBXLoader.js | function ( geoNode, skeleton, morphTarget, preTransform ) {
var geo = new THREE.BufferGeometry();
if ( geoNode.attrName ) geo.name = geoNode.attrName;
var geoInfo = this.parseGeoNode( geoNode, skeleton );
var buffers = this.genBuffers( geoInfo );
var positionAttribute = new THREE.Float32BufferAttribute( buffers.vertex, 3 );
preTransform.applyToBufferAttribute( positionAttribute );
geo.addAttribute( 'position', positionAttribute );
if ( buffers.colors.length > 0 ) {
geo.addAttribute( 'color', new THREE.Float32BufferAttribute( buffers.colors, 3 ) );
}
if ( skeleton ) {
geo.addAttribute( 'skinIndex', new THREE.Uint16BufferAttribute( buffers.weightsIndices, 4 ) );
geo.addAttribute( 'skinWeight', new THREE.Float32BufferAttribute( buffers.vertexWeights, 4 ) );
// used later to bind the skeleton to the model
geo.FBX_Deformer = skeleton;
}
if ( buffers.normal.length > 0 ) {
var normalAttribute = new THREE.Float32BufferAttribute( buffers.normal, 3 );
var normalMatrix = new THREE.Matrix3().getNormalMatrix( preTransform );
normalMatrix.applyToBufferAttribute( normalAttribute );
geo.addAttribute( 'normal', normalAttribute );
}
buffers.uvs.forEach( function ( uvBuffer, i ) {
// subsequent uv buffers are called 'uv1', 'uv2', ...
var name = 'uv' + ( i + 1 ).toString();
// the first uv buffer is just called 'uv'
if ( i === 0 ) {
name = 'uv';
}
geo.addAttribute( name, new THREE.Float32BufferAttribute( buffers.uvs[ i ], 2 ) );
} );
if ( geoInfo.material && geoInfo.material.mappingType !== 'AllSame' ) {
// Convert the material indices of each vertex into rendering groups on the geometry.
var prevMaterialIndex = buffers.materialIndex[ 0 ];
var startIndex = 0;
buffers.materialIndex.forEach( function ( currentIndex, i ) {
if ( currentIndex !== prevMaterialIndex ) {
geo.addGroup( startIndex, i - startIndex, prevMaterialIndex );
prevMaterialIndex = currentIndex;
startIndex = i;
}
} );
// the loop above doesn't add the last group, do that here.
if ( geo.groups.length > 0 ) {
var lastGroup = geo.groups[ geo.groups.length - 1 ];
var lastIndex = lastGroup.start + lastGroup.count;
if ( lastIndex !== buffers.materialIndex.length ) {
geo.addGroup( lastIndex, buffers.materialIndex.length - lastIndex, prevMaterialIndex );
}
}
// case where there are multiple materials but the whole geometry is only
// using one of them
if ( geo.groups.length === 0 ) {
geo.addGroup( 0, buffers.materialIndex.length, buffers.materialIndex[ 0 ] );
}
}
this.addMorphTargets( geo, geoNode, morphTarget, preTransform );
return geo;
} | javascript | function ( geoNode, skeleton, morphTarget, preTransform ) {
var geo = new THREE.BufferGeometry();
if ( geoNode.attrName ) geo.name = geoNode.attrName;
var geoInfo = this.parseGeoNode( geoNode, skeleton );
var buffers = this.genBuffers( geoInfo );
var positionAttribute = new THREE.Float32BufferAttribute( buffers.vertex, 3 );
preTransform.applyToBufferAttribute( positionAttribute );
geo.addAttribute( 'position', positionAttribute );
if ( buffers.colors.length > 0 ) {
geo.addAttribute( 'color', new THREE.Float32BufferAttribute( buffers.colors, 3 ) );
}
if ( skeleton ) {
geo.addAttribute( 'skinIndex', new THREE.Uint16BufferAttribute( buffers.weightsIndices, 4 ) );
geo.addAttribute( 'skinWeight', new THREE.Float32BufferAttribute( buffers.vertexWeights, 4 ) );
// used later to bind the skeleton to the model
geo.FBX_Deformer = skeleton;
}
if ( buffers.normal.length > 0 ) {
var normalAttribute = new THREE.Float32BufferAttribute( buffers.normal, 3 );
var normalMatrix = new THREE.Matrix3().getNormalMatrix( preTransform );
normalMatrix.applyToBufferAttribute( normalAttribute );
geo.addAttribute( 'normal', normalAttribute );
}
buffers.uvs.forEach( function ( uvBuffer, i ) {
// subsequent uv buffers are called 'uv1', 'uv2', ...
var name = 'uv' + ( i + 1 ).toString();
// the first uv buffer is just called 'uv'
if ( i === 0 ) {
name = 'uv';
}
geo.addAttribute( name, new THREE.Float32BufferAttribute( buffers.uvs[ i ], 2 ) );
} );
if ( geoInfo.material && geoInfo.material.mappingType !== 'AllSame' ) {
// Convert the material indices of each vertex into rendering groups on the geometry.
var prevMaterialIndex = buffers.materialIndex[ 0 ];
var startIndex = 0;
buffers.materialIndex.forEach( function ( currentIndex, i ) {
if ( currentIndex !== prevMaterialIndex ) {
geo.addGroup( startIndex, i - startIndex, prevMaterialIndex );
prevMaterialIndex = currentIndex;
startIndex = i;
}
} );
// the loop above doesn't add the last group, do that here.
if ( geo.groups.length > 0 ) {
var lastGroup = geo.groups[ geo.groups.length - 1 ];
var lastIndex = lastGroup.start + lastGroup.count;
if ( lastIndex !== buffers.materialIndex.length ) {
geo.addGroup( lastIndex, buffers.materialIndex.length - lastIndex, prevMaterialIndex );
}
}
// case where there are multiple materials but the whole geometry is only
// using one of them
if ( geo.groups.length === 0 ) {
geo.addGroup( 0, buffers.materialIndex.length, buffers.materialIndex[ 0 ] );
}
}
this.addMorphTargets( geo, geoNode, morphTarget, preTransform );
return geo;
} | [
"function",
"(",
"geoNode",
",",
"skeleton",
",",
"morphTarget",
",",
"preTransform",
")",
"{",
"var",
"geo",
"=",
"new",
"THREE",
".",
"BufferGeometry",
"(",
")",
";",
"if",
"(",
"geoNode",
".",
"attrName",
")",
"geo",
".",
"name",
"=",
"geoNode",
".",
"attrName",
";",
"var",
"geoInfo",
"=",
"this",
".",
"parseGeoNode",
"(",
"geoNode",
",",
"skeleton",
")",
";",
"var",
"buffers",
"=",
"this",
".",
"genBuffers",
"(",
"geoInfo",
")",
";",
"var",
"positionAttribute",
"=",
"new",
"THREE",
".",
"Float32BufferAttribute",
"(",
"buffers",
".",
"vertex",
",",
"3",
")",
";",
"preTransform",
".",
"applyToBufferAttribute",
"(",
"positionAttribute",
")",
";",
"geo",
".",
"addAttribute",
"(",
"'position'",
",",
"positionAttribute",
")",
";",
"if",
"(",
"buffers",
".",
"colors",
".",
"length",
">",
"0",
")",
"{",
"geo",
".",
"addAttribute",
"(",
"'color'",
",",
"new",
"THREE",
".",
"Float32BufferAttribute",
"(",
"buffers",
".",
"colors",
",",
"3",
")",
")",
";",
"}",
"if",
"(",
"skeleton",
")",
"{",
"geo",
".",
"addAttribute",
"(",
"'skinIndex'",
",",
"new",
"THREE",
".",
"Uint16BufferAttribute",
"(",
"buffers",
".",
"weightsIndices",
",",
"4",
")",
")",
";",
"geo",
".",
"addAttribute",
"(",
"'skinWeight'",
",",
"new",
"THREE",
".",
"Float32BufferAttribute",
"(",
"buffers",
".",
"vertexWeights",
",",
"4",
")",
")",
";",
"// used later to bind the skeleton to the model",
"geo",
".",
"FBX_Deformer",
"=",
"skeleton",
";",
"}",
"if",
"(",
"buffers",
".",
"normal",
".",
"length",
">",
"0",
")",
"{",
"var",
"normalAttribute",
"=",
"new",
"THREE",
".",
"Float32BufferAttribute",
"(",
"buffers",
".",
"normal",
",",
"3",
")",
";",
"var",
"normalMatrix",
"=",
"new",
"THREE",
".",
"Matrix3",
"(",
")",
".",
"getNormalMatrix",
"(",
"preTransform",
")",
";",
"normalMatrix",
".",
"applyToBufferAttribute",
"(",
"normalAttribute",
")",
";",
"geo",
".",
"addAttribute",
"(",
"'normal'",
",",
"normalAttribute",
")",
";",
"}",
"buffers",
".",
"uvs",
".",
"forEach",
"(",
"function",
"(",
"uvBuffer",
",",
"i",
")",
"{",
"// subsequent uv buffers are called 'uv1', 'uv2', ...",
"var",
"name",
"=",
"'uv'",
"+",
"(",
"i",
"+",
"1",
")",
".",
"toString",
"(",
")",
";",
"// the first uv buffer is just called 'uv'",
"if",
"(",
"i",
"===",
"0",
")",
"{",
"name",
"=",
"'uv'",
";",
"}",
"geo",
".",
"addAttribute",
"(",
"name",
",",
"new",
"THREE",
".",
"Float32BufferAttribute",
"(",
"buffers",
".",
"uvs",
"[",
"i",
"]",
",",
"2",
")",
")",
";",
"}",
")",
";",
"if",
"(",
"geoInfo",
".",
"material",
"&&",
"geoInfo",
".",
"material",
".",
"mappingType",
"!==",
"'AllSame'",
")",
"{",
"// Convert the material indices of each vertex into rendering groups on the geometry.",
"var",
"prevMaterialIndex",
"=",
"buffers",
".",
"materialIndex",
"[",
"0",
"]",
";",
"var",
"startIndex",
"=",
"0",
";",
"buffers",
".",
"materialIndex",
".",
"forEach",
"(",
"function",
"(",
"currentIndex",
",",
"i",
")",
"{",
"if",
"(",
"currentIndex",
"!==",
"prevMaterialIndex",
")",
"{",
"geo",
".",
"addGroup",
"(",
"startIndex",
",",
"i",
"-",
"startIndex",
",",
"prevMaterialIndex",
")",
";",
"prevMaterialIndex",
"=",
"currentIndex",
";",
"startIndex",
"=",
"i",
";",
"}",
"}",
")",
";",
"// the loop above doesn't add the last group, do that here.",
"if",
"(",
"geo",
".",
"groups",
".",
"length",
">",
"0",
")",
"{",
"var",
"lastGroup",
"=",
"geo",
".",
"groups",
"[",
"geo",
".",
"groups",
".",
"length",
"-",
"1",
"]",
";",
"var",
"lastIndex",
"=",
"lastGroup",
".",
"start",
"+",
"lastGroup",
".",
"count",
";",
"if",
"(",
"lastIndex",
"!==",
"buffers",
".",
"materialIndex",
".",
"length",
")",
"{",
"geo",
".",
"addGroup",
"(",
"lastIndex",
",",
"buffers",
".",
"materialIndex",
".",
"length",
"-",
"lastIndex",
",",
"prevMaterialIndex",
")",
";",
"}",
"}",
"// case where there are multiple materials but the whole geometry is only",
"// using one of them",
"if",
"(",
"geo",
".",
"groups",
".",
"length",
"===",
"0",
")",
"{",
"geo",
".",
"addGroup",
"(",
"0",
",",
"buffers",
".",
"materialIndex",
".",
"length",
",",
"buffers",
".",
"materialIndex",
"[",
"0",
"]",
")",
";",
"}",
"}",
"this",
".",
"addMorphTargets",
"(",
"geo",
",",
"geoNode",
",",
"morphTarget",
",",
"preTransform",
")",
";",
"return",
"geo",
";",
"}"
] | Generate a THREE.BufferGeometry from a node in FBXTree.Objects.Geometry | [
"Generate",
"a",
"THREE",
".",
"BufferGeometry",
"from",
"a",
"node",
"in",
"FBXTree",
".",
"Objects",
".",
"Geometry"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L1525-L1630 |
|
7,863 | exokitxr/exokit | examples/FBXLoader.js | function ( parentGeo, parentGeoNode, morphGeoNode, preTransform ) {
var morphGeo = new THREE.BufferGeometry();
if ( morphGeoNode.attrName ) morphGeo.name = morphGeoNode.attrName;
var vertexIndices = ( parentGeoNode.PolygonVertexIndex !== undefined ) ? parentGeoNode.PolygonVertexIndex.a : [];
// make a copy of the parent's vertex positions
var vertexPositions = ( parentGeoNode.Vertices !== undefined ) ? parentGeoNode.Vertices.a.slice() : [];
var morphPositions = ( morphGeoNode.Vertices !== undefined ) ? morphGeoNode.Vertices.a : [];
var indices = ( morphGeoNode.Indexes !== undefined ) ? morphGeoNode.Indexes.a : [];
for ( var i = 0; i < indices.length; i ++ ) {
var morphIndex = indices[ i ] * 3;
// FBX format uses blend shapes rather than morph targets. This can be converted
// by additively combining the blend shape positions with the original geometry's positions
vertexPositions[ morphIndex ] += morphPositions[ i * 3 ];
vertexPositions[ morphIndex + 1 ] += morphPositions[ i * 3 + 1 ];
vertexPositions[ morphIndex + 2 ] += morphPositions[ i * 3 + 2 ];
}
// TODO: add morph normal support
var morphGeoInfo = {
vertexIndices: vertexIndices,
vertexPositions: vertexPositions,
};
var morphBuffers = this.genBuffers( morphGeoInfo );
var positionAttribute = new THREE.Float32BufferAttribute( morphBuffers.vertex, 3 );
positionAttribute.name = morphGeoNode.attrName;
preTransform.applyToBufferAttribute( positionAttribute );
parentGeo.morphAttributes.position.push( positionAttribute );
} | javascript | function ( parentGeo, parentGeoNode, morphGeoNode, preTransform ) {
var morphGeo = new THREE.BufferGeometry();
if ( morphGeoNode.attrName ) morphGeo.name = morphGeoNode.attrName;
var vertexIndices = ( parentGeoNode.PolygonVertexIndex !== undefined ) ? parentGeoNode.PolygonVertexIndex.a : [];
// make a copy of the parent's vertex positions
var vertexPositions = ( parentGeoNode.Vertices !== undefined ) ? parentGeoNode.Vertices.a.slice() : [];
var morphPositions = ( morphGeoNode.Vertices !== undefined ) ? morphGeoNode.Vertices.a : [];
var indices = ( morphGeoNode.Indexes !== undefined ) ? morphGeoNode.Indexes.a : [];
for ( var i = 0; i < indices.length; i ++ ) {
var morphIndex = indices[ i ] * 3;
// FBX format uses blend shapes rather than morph targets. This can be converted
// by additively combining the blend shape positions with the original geometry's positions
vertexPositions[ morphIndex ] += morphPositions[ i * 3 ];
vertexPositions[ morphIndex + 1 ] += morphPositions[ i * 3 + 1 ];
vertexPositions[ morphIndex + 2 ] += morphPositions[ i * 3 + 2 ];
}
// TODO: add morph normal support
var morphGeoInfo = {
vertexIndices: vertexIndices,
vertexPositions: vertexPositions,
};
var morphBuffers = this.genBuffers( morphGeoInfo );
var positionAttribute = new THREE.Float32BufferAttribute( morphBuffers.vertex, 3 );
positionAttribute.name = morphGeoNode.attrName;
preTransform.applyToBufferAttribute( positionAttribute );
parentGeo.morphAttributes.position.push( positionAttribute );
} | [
"function",
"(",
"parentGeo",
",",
"parentGeoNode",
",",
"morphGeoNode",
",",
"preTransform",
")",
"{",
"var",
"morphGeo",
"=",
"new",
"THREE",
".",
"BufferGeometry",
"(",
")",
";",
"if",
"(",
"morphGeoNode",
".",
"attrName",
")",
"morphGeo",
".",
"name",
"=",
"morphGeoNode",
".",
"attrName",
";",
"var",
"vertexIndices",
"=",
"(",
"parentGeoNode",
".",
"PolygonVertexIndex",
"!==",
"undefined",
")",
"?",
"parentGeoNode",
".",
"PolygonVertexIndex",
".",
"a",
":",
"[",
"]",
";",
"// make a copy of the parent's vertex positions",
"var",
"vertexPositions",
"=",
"(",
"parentGeoNode",
".",
"Vertices",
"!==",
"undefined",
")",
"?",
"parentGeoNode",
".",
"Vertices",
".",
"a",
".",
"slice",
"(",
")",
":",
"[",
"]",
";",
"var",
"morphPositions",
"=",
"(",
"morphGeoNode",
".",
"Vertices",
"!==",
"undefined",
")",
"?",
"morphGeoNode",
".",
"Vertices",
".",
"a",
":",
"[",
"]",
";",
"var",
"indices",
"=",
"(",
"morphGeoNode",
".",
"Indexes",
"!==",
"undefined",
")",
"?",
"morphGeoNode",
".",
"Indexes",
".",
"a",
":",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"indices",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"morphIndex",
"=",
"indices",
"[",
"i",
"]",
"*",
"3",
";",
"// FBX format uses blend shapes rather than morph targets. This can be converted",
"// by additively combining the blend shape positions with the original geometry's positions",
"vertexPositions",
"[",
"morphIndex",
"]",
"+=",
"morphPositions",
"[",
"i",
"*",
"3",
"]",
";",
"vertexPositions",
"[",
"morphIndex",
"+",
"1",
"]",
"+=",
"morphPositions",
"[",
"i",
"*",
"3",
"+",
"1",
"]",
";",
"vertexPositions",
"[",
"morphIndex",
"+",
"2",
"]",
"+=",
"morphPositions",
"[",
"i",
"*",
"3",
"+",
"2",
"]",
";",
"}",
"// TODO: add morph normal support",
"var",
"morphGeoInfo",
"=",
"{",
"vertexIndices",
":",
"vertexIndices",
",",
"vertexPositions",
":",
"vertexPositions",
",",
"}",
";",
"var",
"morphBuffers",
"=",
"this",
".",
"genBuffers",
"(",
"morphGeoInfo",
")",
";",
"var",
"positionAttribute",
"=",
"new",
"THREE",
".",
"Float32BufferAttribute",
"(",
"morphBuffers",
".",
"vertex",
",",
"3",
")",
";",
"positionAttribute",
".",
"name",
"=",
"morphGeoNode",
".",
"attrName",
";",
"preTransform",
".",
"applyToBufferAttribute",
"(",
"positionAttribute",
")",
";",
"parentGeo",
".",
"morphAttributes",
".",
"position",
".",
"push",
"(",
"positionAttribute",
")",
";",
"}"
] | a morph geometry node is similar to a standard node, and the node is also contained in FBXTree.Objects.Geometry, however it can only have attributes for position, normal and a special attribute Index defining which vertices of the original geometry are affected Normal and position attributes only have data for the vertices that are affected by the morph | [
"a",
"morph",
"geometry",
"node",
"is",
"similar",
"to",
"a",
"standard",
"node",
"and",
"the",
"node",
"is",
"also",
"contained",
"in",
"FBXTree",
".",
"Objects",
".",
"Geometry",
"however",
"it",
"can",
"only",
"have",
"attributes",
"for",
"position",
"normal",
"and",
"a",
"special",
"attribute",
"Index",
"defining",
"which",
"vertices",
"of",
"the",
"original",
"geometry",
"are",
"affected",
"Normal",
"and",
"position",
"attributes",
"only",
"have",
"data",
"for",
"the",
"vertices",
"that",
"are",
"affected",
"by",
"the",
"morph"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L2025-L2065 |
|
7,864 | exokitxr/exokit | examples/FBXLoader.js | function ( NormalNode ) {
var mappingType = NormalNode.MappingInformationType;
var referenceType = NormalNode.ReferenceInformationType;
var buffer = NormalNode.Normals.a;
var indexBuffer = [];
if ( referenceType === 'IndexToDirect' ) {
if ( 'NormalIndex' in NormalNode ) {
indexBuffer = NormalNode.NormalIndex.a;
} else if ( 'NormalsIndex' in NormalNode ) {
indexBuffer = NormalNode.NormalsIndex.a;
}
}
return {
dataSize: 3,
buffer: buffer,
indices: indexBuffer,
mappingType: mappingType,
referenceType: referenceType
};
} | javascript | function ( NormalNode ) {
var mappingType = NormalNode.MappingInformationType;
var referenceType = NormalNode.ReferenceInformationType;
var buffer = NormalNode.Normals.a;
var indexBuffer = [];
if ( referenceType === 'IndexToDirect' ) {
if ( 'NormalIndex' in NormalNode ) {
indexBuffer = NormalNode.NormalIndex.a;
} else if ( 'NormalsIndex' in NormalNode ) {
indexBuffer = NormalNode.NormalsIndex.a;
}
}
return {
dataSize: 3,
buffer: buffer,
indices: indexBuffer,
mappingType: mappingType,
referenceType: referenceType
};
} | [
"function",
"(",
"NormalNode",
")",
"{",
"var",
"mappingType",
"=",
"NormalNode",
".",
"MappingInformationType",
";",
"var",
"referenceType",
"=",
"NormalNode",
".",
"ReferenceInformationType",
";",
"var",
"buffer",
"=",
"NormalNode",
".",
"Normals",
".",
"a",
";",
"var",
"indexBuffer",
"=",
"[",
"]",
";",
"if",
"(",
"referenceType",
"===",
"'IndexToDirect'",
")",
"{",
"if",
"(",
"'NormalIndex'",
"in",
"NormalNode",
")",
"{",
"indexBuffer",
"=",
"NormalNode",
".",
"NormalIndex",
".",
"a",
";",
"}",
"else",
"if",
"(",
"'NormalsIndex'",
"in",
"NormalNode",
")",
"{",
"indexBuffer",
"=",
"NormalNode",
".",
"NormalsIndex",
".",
"a",
";",
"}",
"}",
"return",
"{",
"dataSize",
":",
"3",
",",
"buffer",
":",
"buffer",
",",
"indices",
":",
"indexBuffer",
",",
"mappingType",
":",
"mappingType",
",",
"referenceType",
":",
"referenceType",
"}",
";",
"}"
] | Parse normal from FBXTree.Objects.Geometry.LayerElementNormal if it exists | [
"Parse",
"normal",
"from",
"FBXTree",
".",
"Objects",
".",
"Geometry",
".",
"LayerElementNormal",
"if",
"it",
"exists"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L2068-L2096 |
|
7,865 | exokitxr/exokit | examples/FBXLoader.js | function ( UVNode ) {
var mappingType = UVNode.MappingInformationType;
var referenceType = UVNode.ReferenceInformationType;
var buffer = UVNode.UV.a;
var indexBuffer = [];
if ( referenceType === 'IndexToDirect' ) {
indexBuffer = UVNode.UVIndex.a;
}
return {
dataSize: 2,
buffer: buffer,
indices: indexBuffer,
mappingType: mappingType,
referenceType: referenceType
};
} | javascript | function ( UVNode ) {
var mappingType = UVNode.MappingInformationType;
var referenceType = UVNode.ReferenceInformationType;
var buffer = UVNode.UV.a;
var indexBuffer = [];
if ( referenceType === 'IndexToDirect' ) {
indexBuffer = UVNode.UVIndex.a;
}
return {
dataSize: 2,
buffer: buffer,
indices: indexBuffer,
mappingType: mappingType,
referenceType: referenceType
};
} | [
"function",
"(",
"UVNode",
")",
"{",
"var",
"mappingType",
"=",
"UVNode",
".",
"MappingInformationType",
";",
"var",
"referenceType",
"=",
"UVNode",
".",
"ReferenceInformationType",
";",
"var",
"buffer",
"=",
"UVNode",
".",
"UV",
".",
"a",
";",
"var",
"indexBuffer",
"=",
"[",
"]",
";",
"if",
"(",
"referenceType",
"===",
"'IndexToDirect'",
")",
"{",
"indexBuffer",
"=",
"UVNode",
".",
"UVIndex",
".",
"a",
";",
"}",
"return",
"{",
"dataSize",
":",
"2",
",",
"buffer",
":",
"buffer",
",",
"indices",
":",
"indexBuffer",
",",
"mappingType",
":",
"mappingType",
",",
"referenceType",
":",
"referenceType",
"}",
";",
"}"
] | Parse UVs from FBXTree.Objects.Geometry.LayerElementUV if it exists | [
"Parse",
"UVs",
"from",
"FBXTree",
".",
"Objects",
".",
"Geometry",
".",
"LayerElementUV",
"if",
"it",
"exists"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L2099-L2119 |
|
7,866 | exokitxr/exokit | examples/FBXLoader.js | function ( ColorNode ) {
var mappingType = ColorNode.MappingInformationType;
var referenceType = ColorNode.ReferenceInformationType;
var buffer = ColorNode.Colors.a;
var indexBuffer = [];
if ( referenceType === 'IndexToDirect' ) {
indexBuffer = ColorNode.ColorIndex.a;
}
return {
dataSize: 4,
buffer: buffer,
indices: indexBuffer,
mappingType: mappingType,
referenceType: referenceType
};
} | javascript | function ( ColorNode ) {
var mappingType = ColorNode.MappingInformationType;
var referenceType = ColorNode.ReferenceInformationType;
var buffer = ColorNode.Colors.a;
var indexBuffer = [];
if ( referenceType === 'IndexToDirect' ) {
indexBuffer = ColorNode.ColorIndex.a;
}
return {
dataSize: 4,
buffer: buffer,
indices: indexBuffer,
mappingType: mappingType,
referenceType: referenceType
};
} | [
"function",
"(",
"ColorNode",
")",
"{",
"var",
"mappingType",
"=",
"ColorNode",
".",
"MappingInformationType",
";",
"var",
"referenceType",
"=",
"ColorNode",
".",
"ReferenceInformationType",
";",
"var",
"buffer",
"=",
"ColorNode",
".",
"Colors",
".",
"a",
";",
"var",
"indexBuffer",
"=",
"[",
"]",
";",
"if",
"(",
"referenceType",
"===",
"'IndexToDirect'",
")",
"{",
"indexBuffer",
"=",
"ColorNode",
".",
"ColorIndex",
".",
"a",
";",
"}",
"return",
"{",
"dataSize",
":",
"4",
",",
"buffer",
":",
"buffer",
",",
"indices",
":",
"indexBuffer",
",",
"mappingType",
":",
"mappingType",
",",
"referenceType",
":",
"referenceType",
"}",
";",
"}"
] | Parse Vertex Colors from FBXTree.Objects.Geometry.LayerElementColor if it exists | [
"Parse",
"Vertex",
"Colors",
"from",
"FBXTree",
".",
"Objects",
".",
"Geometry",
".",
"LayerElementColor",
"if",
"it",
"exists"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L2122-L2142 |
|
7,867 | exokitxr/exokit | examples/FBXLoader.js | function ( MaterialNode ) {
var mappingType = MaterialNode.MappingInformationType;
var referenceType = MaterialNode.ReferenceInformationType;
if ( mappingType === 'NoMappingInformation' ) {
return {
dataSize: 1,
buffer: [ 0 ],
indices: [ 0 ],
mappingType: 'AllSame',
referenceType: referenceType
};
}
var materialIndexBuffer = MaterialNode.Materials.a;
// Since materials are stored as indices, there's a bit of a mismatch between FBX and what
// we expect.So we create an intermediate buffer that points to the index in the buffer,
// for conforming with the other functions we've written for other data.
var materialIndices = [];
for ( var i = 0; i < materialIndexBuffer.length; ++ i ) {
materialIndices.push( i );
}
return {
dataSize: 1,
buffer: materialIndexBuffer,
indices: materialIndices,
mappingType: mappingType,
referenceType: referenceType
};
} | javascript | function ( MaterialNode ) {
var mappingType = MaterialNode.MappingInformationType;
var referenceType = MaterialNode.ReferenceInformationType;
if ( mappingType === 'NoMappingInformation' ) {
return {
dataSize: 1,
buffer: [ 0 ],
indices: [ 0 ],
mappingType: 'AllSame',
referenceType: referenceType
};
}
var materialIndexBuffer = MaterialNode.Materials.a;
// Since materials are stored as indices, there's a bit of a mismatch between FBX and what
// we expect.So we create an intermediate buffer that points to the index in the buffer,
// for conforming with the other functions we've written for other data.
var materialIndices = [];
for ( var i = 0; i < materialIndexBuffer.length; ++ i ) {
materialIndices.push( i );
}
return {
dataSize: 1,
buffer: materialIndexBuffer,
indices: materialIndices,
mappingType: mappingType,
referenceType: referenceType
};
} | [
"function",
"(",
"MaterialNode",
")",
"{",
"var",
"mappingType",
"=",
"MaterialNode",
".",
"MappingInformationType",
";",
"var",
"referenceType",
"=",
"MaterialNode",
".",
"ReferenceInformationType",
";",
"if",
"(",
"mappingType",
"===",
"'NoMappingInformation'",
")",
"{",
"return",
"{",
"dataSize",
":",
"1",
",",
"buffer",
":",
"[",
"0",
"]",
",",
"indices",
":",
"[",
"0",
"]",
",",
"mappingType",
":",
"'AllSame'",
",",
"referenceType",
":",
"referenceType",
"}",
";",
"}",
"var",
"materialIndexBuffer",
"=",
"MaterialNode",
".",
"Materials",
".",
"a",
";",
"// Since materials are stored as indices, there's a bit of a mismatch between FBX and what",
"// we expect.So we create an intermediate buffer that points to the index in the buffer,",
"// for conforming with the other functions we've written for other data.",
"var",
"materialIndices",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"materialIndexBuffer",
".",
"length",
";",
"++",
"i",
")",
"{",
"materialIndices",
".",
"push",
"(",
"i",
")",
";",
"}",
"return",
"{",
"dataSize",
":",
"1",
",",
"buffer",
":",
"materialIndexBuffer",
",",
"indices",
":",
"materialIndices",
",",
"mappingType",
":",
"mappingType",
",",
"referenceType",
":",
"referenceType",
"}",
";",
"}"
] | Parse mapping and material data in FBXTree.Objects.Geometry.LayerElementMaterial if it exists | [
"Parse",
"mapping",
"and",
"material",
"data",
"in",
"FBXTree",
".",
"Objects",
".",
"Geometry",
".",
"LayerElementMaterial",
"if",
"it",
"exists"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L2145-L2183 |
|
7,868 | exokitxr/exokit | examples/FBXLoader.js | function ( geoNode ) {
if ( THREE.NURBSCurve === undefined ) {
console.error( 'THREE.FBXLoader: The loader relies on THREE.NURBSCurve for any nurbs present in the model. Nurbs will show up as empty geometry.' );
return new THREE.BufferGeometry();
}
var order = parseInt( geoNode.Order );
if ( isNaN( order ) ) {
console.error( 'THREE.FBXLoader: Invalid Order %s given for geometry ID: %s', geoNode.Order, geoNode.id );
return new THREE.BufferGeometry();
}
var degree = order - 1;
var knots = geoNode.KnotVector.a;
var controlPoints = [];
var pointsValues = geoNode.Points.a;
for ( var i = 0, l = pointsValues.length; i < l; i += 4 ) {
controlPoints.push( new THREE.Vector4().fromArray( pointsValues, i ) );
}
var startKnot, endKnot;
if ( geoNode.Form === 'Closed' ) {
controlPoints.push( controlPoints[ 0 ] );
} else if ( geoNode.Form === 'Periodic' ) {
startKnot = degree;
endKnot = knots.length - 1 - startKnot;
for ( var i = 0; i < degree; ++ i ) {
controlPoints.push( controlPoints[ i ] );
}
}
var curve = new THREE.NURBSCurve( degree, knots, controlPoints, startKnot, endKnot );
var vertices = curve.getPoints( controlPoints.length * 7 );
var positions = new Float32Array( vertices.length * 3 );
vertices.forEach( function ( vertex, i ) {
vertex.toArray( positions, i * 3 );
} );
var geometry = new THREE.BufferGeometry();
geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
return geometry;
} | javascript | function ( geoNode ) {
if ( THREE.NURBSCurve === undefined ) {
console.error( 'THREE.FBXLoader: The loader relies on THREE.NURBSCurve for any nurbs present in the model. Nurbs will show up as empty geometry.' );
return new THREE.BufferGeometry();
}
var order = parseInt( geoNode.Order );
if ( isNaN( order ) ) {
console.error( 'THREE.FBXLoader: Invalid Order %s given for geometry ID: %s', geoNode.Order, geoNode.id );
return new THREE.BufferGeometry();
}
var degree = order - 1;
var knots = geoNode.KnotVector.a;
var controlPoints = [];
var pointsValues = geoNode.Points.a;
for ( var i = 0, l = pointsValues.length; i < l; i += 4 ) {
controlPoints.push( new THREE.Vector4().fromArray( pointsValues, i ) );
}
var startKnot, endKnot;
if ( geoNode.Form === 'Closed' ) {
controlPoints.push( controlPoints[ 0 ] );
} else if ( geoNode.Form === 'Periodic' ) {
startKnot = degree;
endKnot = knots.length - 1 - startKnot;
for ( var i = 0; i < degree; ++ i ) {
controlPoints.push( controlPoints[ i ] );
}
}
var curve = new THREE.NURBSCurve( degree, knots, controlPoints, startKnot, endKnot );
var vertices = curve.getPoints( controlPoints.length * 7 );
var positions = new Float32Array( vertices.length * 3 );
vertices.forEach( function ( vertex, i ) {
vertex.toArray( positions, i * 3 );
} );
var geometry = new THREE.BufferGeometry();
geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
return geometry;
} | [
"function",
"(",
"geoNode",
")",
"{",
"if",
"(",
"THREE",
".",
"NURBSCurve",
"===",
"undefined",
")",
"{",
"console",
".",
"error",
"(",
"'THREE.FBXLoader: The loader relies on THREE.NURBSCurve for any nurbs present in the model. Nurbs will show up as empty geometry.'",
")",
";",
"return",
"new",
"THREE",
".",
"BufferGeometry",
"(",
")",
";",
"}",
"var",
"order",
"=",
"parseInt",
"(",
"geoNode",
".",
"Order",
")",
";",
"if",
"(",
"isNaN",
"(",
"order",
")",
")",
"{",
"console",
".",
"error",
"(",
"'THREE.FBXLoader: Invalid Order %s given for geometry ID: %s'",
",",
"geoNode",
".",
"Order",
",",
"geoNode",
".",
"id",
")",
";",
"return",
"new",
"THREE",
".",
"BufferGeometry",
"(",
")",
";",
"}",
"var",
"degree",
"=",
"order",
"-",
"1",
";",
"var",
"knots",
"=",
"geoNode",
".",
"KnotVector",
".",
"a",
";",
"var",
"controlPoints",
"=",
"[",
"]",
";",
"var",
"pointsValues",
"=",
"geoNode",
".",
"Points",
".",
"a",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"pointsValues",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"+=",
"4",
")",
"{",
"controlPoints",
".",
"push",
"(",
"new",
"THREE",
".",
"Vector4",
"(",
")",
".",
"fromArray",
"(",
"pointsValues",
",",
"i",
")",
")",
";",
"}",
"var",
"startKnot",
",",
"endKnot",
";",
"if",
"(",
"geoNode",
".",
"Form",
"===",
"'Closed'",
")",
"{",
"controlPoints",
".",
"push",
"(",
"controlPoints",
"[",
"0",
"]",
")",
";",
"}",
"else",
"if",
"(",
"geoNode",
".",
"Form",
"===",
"'Periodic'",
")",
"{",
"startKnot",
"=",
"degree",
";",
"endKnot",
"=",
"knots",
".",
"length",
"-",
"1",
"-",
"startKnot",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"degree",
";",
"++",
"i",
")",
"{",
"controlPoints",
".",
"push",
"(",
"controlPoints",
"[",
"i",
"]",
")",
";",
"}",
"}",
"var",
"curve",
"=",
"new",
"THREE",
".",
"NURBSCurve",
"(",
"degree",
",",
"knots",
",",
"controlPoints",
",",
"startKnot",
",",
"endKnot",
")",
";",
"var",
"vertices",
"=",
"curve",
".",
"getPoints",
"(",
"controlPoints",
".",
"length",
"*",
"7",
")",
";",
"var",
"positions",
"=",
"new",
"Float32Array",
"(",
"vertices",
".",
"length",
"*",
"3",
")",
";",
"vertices",
".",
"forEach",
"(",
"function",
"(",
"vertex",
",",
"i",
")",
"{",
"vertex",
".",
"toArray",
"(",
"positions",
",",
"i",
"*",
"3",
")",
";",
"}",
")",
";",
"var",
"geometry",
"=",
"new",
"THREE",
".",
"BufferGeometry",
"(",
")",
";",
"geometry",
".",
"addAttribute",
"(",
"'position'",
",",
"new",
"THREE",
".",
"BufferAttribute",
"(",
"positions",
",",
"3",
")",
")",
";",
"return",
"geometry",
";",
"}"
] | Generate a NurbGeometry from a node in FBXTree.Objects.Geometry | [
"Generate",
"a",
"NurbGeometry",
"from",
"a",
"node",
"in",
"FBXTree",
".",
"Objects",
".",
"Geometry"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L2186-L2251 |
|
7,869 | exokitxr/exokit | examples/FBXLoader.js | function () {
var animationClips = [];
var rawClips = this.parseClips();
if ( rawClips === undefined ) return;
for ( var key in rawClips ) {
var rawClip = rawClips[ key ];
var clip = this.addClip( rawClip );
animationClips.push( clip );
}
return animationClips;
} | javascript | function () {
var animationClips = [];
var rawClips = this.parseClips();
if ( rawClips === undefined ) return;
for ( var key in rawClips ) {
var rawClip = rawClips[ key ];
var clip = this.addClip( rawClip );
animationClips.push( clip );
}
return animationClips;
} | [
"function",
"(",
")",
"{",
"var",
"animationClips",
"=",
"[",
"]",
";",
"var",
"rawClips",
"=",
"this",
".",
"parseClips",
"(",
")",
";",
"if",
"(",
"rawClips",
"===",
"undefined",
")",
"return",
";",
"for",
"(",
"var",
"key",
"in",
"rawClips",
")",
"{",
"var",
"rawClip",
"=",
"rawClips",
"[",
"key",
"]",
";",
"var",
"clip",
"=",
"this",
".",
"addClip",
"(",
"rawClip",
")",
";",
"animationClips",
".",
"push",
"(",
"clip",
")",
";",
"}",
"return",
"animationClips",
";",
"}"
] | take raw animation clips and turn them into three.js animation clips | [
"take",
"raw",
"animation",
"clips",
"and",
"turn",
"them",
"into",
"three",
".",
"js",
"animation",
"clips"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L2263-L2284 |
|
7,870 | exokitxr/exokit | examples/FBXLoader.js | function ( layersMap ) {
var rawStacks = fbxTree.Objects.AnimationStack;
// connect the stacks (clips) up to the layers
var rawClips = {};
for ( var nodeID in rawStacks ) {
var children = connections.get( parseInt( nodeID ) ).children;
if ( children.length > 1 ) {
// it seems like stacks will always be associated with a single layer. But just in case there are files
// where there are multiple layers per stack, we'll display a warning
console.warn( 'THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.' );
}
var layer = layersMap.get( children[ 0 ].ID );
rawClips[ nodeID ] = {
name: rawStacks[ nodeID ].attrName,
layer: layer,
};
}
return rawClips;
} | javascript | function ( layersMap ) {
var rawStacks = fbxTree.Objects.AnimationStack;
// connect the stacks (clips) up to the layers
var rawClips = {};
for ( var nodeID in rawStacks ) {
var children = connections.get( parseInt( nodeID ) ).children;
if ( children.length > 1 ) {
// it seems like stacks will always be associated with a single layer. But just in case there are files
// where there are multiple layers per stack, we'll display a warning
console.warn( 'THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.' );
}
var layer = layersMap.get( children[ 0 ].ID );
rawClips[ nodeID ] = {
name: rawStacks[ nodeID ].attrName,
layer: layer,
};
}
return rawClips;
} | [
"function",
"(",
"layersMap",
")",
"{",
"var",
"rawStacks",
"=",
"fbxTree",
".",
"Objects",
".",
"AnimationStack",
";",
"// connect the stacks (clips) up to the layers",
"var",
"rawClips",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"nodeID",
"in",
"rawStacks",
")",
"{",
"var",
"children",
"=",
"connections",
".",
"get",
"(",
"parseInt",
"(",
"nodeID",
")",
")",
".",
"children",
";",
"if",
"(",
"children",
".",
"length",
">",
"1",
")",
"{",
"// it seems like stacks will always be associated with a single layer. But just in case there are files",
"// where there are multiple layers per stack, we'll display a warning",
"console",
".",
"warn",
"(",
"'THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.'",
")",
";",
"}",
"var",
"layer",
"=",
"layersMap",
".",
"get",
"(",
"children",
"[",
"0",
"]",
".",
"ID",
")",
";",
"rawClips",
"[",
"nodeID",
"]",
"=",
"{",
"name",
":",
"rawStacks",
"[",
"nodeID",
"]",
".",
"attrName",
",",
"layer",
":",
"layer",
",",
"}",
";",
"}",
"return",
"rawClips",
";",
"}"
] | parse nodes in FBXTree.Objects.AnimationStack. These are the top level node in the animation hierarchy. Each Stack node will be used to create a THREE.AnimationClip | [
"parse",
"nodes",
"in",
"FBXTree",
".",
"Objects",
".",
"AnimationStack",
".",
"These",
"are",
"the",
"top",
"level",
"node",
"in",
"the",
"animation",
"hierarchy",
".",
"Each",
"Stack",
"node",
"will",
"be",
"used",
"to",
"create",
"a",
"THREE",
".",
"AnimationClip"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L2525-L2557 |
|
7,871 | exokitxr/exokit | examples/FBXLoader.js | function ( curves ) {
var times = [];
// first join together the times for each axis, if defined
if ( curves.x !== undefined ) times = times.concat( curves.x.times );
if ( curves.y !== undefined ) times = times.concat( curves.y.times );
if ( curves.z !== undefined ) times = times.concat( curves.z.times );
// then sort them and remove duplicates
times = times.sort( function ( a, b ) {
return a - b;
} ).filter( function ( elem, index, array ) {
return array.indexOf( elem ) == index;
} );
return times;
} | javascript | function ( curves ) {
var times = [];
// first join together the times for each axis, if defined
if ( curves.x !== undefined ) times = times.concat( curves.x.times );
if ( curves.y !== undefined ) times = times.concat( curves.y.times );
if ( curves.z !== undefined ) times = times.concat( curves.z.times );
// then sort them and remove duplicates
times = times.sort( function ( a, b ) {
return a - b;
} ).filter( function ( elem, index, array ) {
return array.indexOf( elem ) == index;
} );
return times;
} | [
"function",
"(",
"curves",
")",
"{",
"var",
"times",
"=",
"[",
"]",
";",
"// first join together the times for each axis, if defined",
"if",
"(",
"curves",
".",
"x",
"!==",
"undefined",
")",
"times",
"=",
"times",
".",
"concat",
"(",
"curves",
".",
"x",
".",
"times",
")",
";",
"if",
"(",
"curves",
".",
"y",
"!==",
"undefined",
")",
"times",
"=",
"times",
".",
"concat",
"(",
"curves",
".",
"y",
".",
"times",
")",
";",
"if",
"(",
"curves",
".",
"z",
"!==",
"undefined",
")",
"times",
"=",
"times",
".",
"concat",
"(",
"curves",
".",
"z",
".",
"times",
")",
";",
"// then sort them and remove duplicates",
"times",
"=",
"times",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
"-",
"b",
";",
"}",
")",
".",
"filter",
"(",
"function",
"(",
"elem",
",",
"index",
",",
"array",
")",
"{",
"return",
"array",
".",
"indexOf",
"(",
"elem",
")",
"==",
"index",
";",
"}",
")",
";",
"return",
"times",
";",
"}"
] | For all animated objects, times are defined separately for each axis Here we'll combine the times into one sorted array without duplicates | [
"For",
"all",
"animated",
"objects",
"times",
"are",
"defined",
"separately",
"for",
"each",
"axis",
"Here",
"we",
"ll",
"combine",
"the",
"times",
"into",
"one",
"sorted",
"array",
"without",
"duplicates"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L2712-L2734 |
|
7,872 | exokitxr/exokit | examples/FBXLoader.js | function ( curve ) {
for ( var i = 1; i < curve.values.length; i ++ ) {
var initialValue = curve.values[ i - 1 ];
var valuesSpan = curve.values[ i ] - initialValue;
var absoluteSpan = Math.abs( valuesSpan );
if ( absoluteSpan >= 180 ) {
var numSubIntervals = absoluteSpan / 180;
var step = valuesSpan / numSubIntervals;
var nextValue = initialValue + step;
var initialTime = curve.times[ i - 1 ];
var timeSpan = curve.times[ i ] - initialTime;
var interval = timeSpan / numSubIntervals;
var nextTime = initialTime + interval;
var interpolatedTimes = [];
var interpolatedValues = [];
while ( nextTime < curve.times[ i ] ) {
interpolatedTimes.push( nextTime );
nextTime += interval;
interpolatedValues.push( nextValue );
nextValue += step;
}
curve.times = inject( curve.times, i, interpolatedTimes );
curve.values = inject( curve.values, i, interpolatedValues );
}
}
} | javascript | function ( curve ) {
for ( var i = 1; i < curve.values.length; i ++ ) {
var initialValue = curve.values[ i - 1 ];
var valuesSpan = curve.values[ i ] - initialValue;
var absoluteSpan = Math.abs( valuesSpan );
if ( absoluteSpan >= 180 ) {
var numSubIntervals = absoluteSpan / 180;
var step = valuesSpan / numSubIntervals;
var nextValue = initialValue + step;
var initialTime = curve.times[ i - 1 ];
var timeSpan = curve.times[ i ] - initialTime;
var interval = timeSpan / numSubIntervals;
var nextTime = initialTime + interval;
var interpolatedTimes = [];
var interpolatedValues = [];
while ( nextTime < curve.times[ i ] ) {
interpolatedTimes.push( nextTime );
nextTime += interval;
interpolatedValues.push( nextValue );
nextValue += step;
}
curve.times = inject( curve.times, i, interpolatedTimes );
curve.values = inject( curve.values, i, interpolatedValues );
}
}
} | [
"function",
"(",
"curve",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"curve",
".",
"values",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"initialValue",
"=",
"curve",
".",
"values",
"[",
"i",
"-",
"1",
"]",
";",
"var",
"valuesSpan",
"=",
"curve",
".",
"values",
"[",
"i",
"]",
"-",
"initialValue",
";",
"var",
"absoluteSpan",
"=",
"Math",
".",
"abs",
"(",
"valuesSpan",
")",
";",
"if",
"(",
"absoluteSpan",
">=",
"180",
")",
"{",
"var",
"numSubIntervals",
"=",
"absoluteSpan",
"/",
"180",
";",
"var",
"step",
"=",
"valuesSpan",
"/",
"numSubIntervals",
";",
"var",
"nextValue",
"=",
"initialValue",
"+",
"step",
";",
"var",
"initialTime",
"=",
"curve",
".",
"times",
"[",
"i",
"-",
"1",
"]",
";",
"var",
"timeSpan",
"=",
"curve",
".",
"times",
"[",
"i",
"]",
"-",
"initialTime",
";",
"var",
"interval",
"=",
"timeSpan",
"/",
"numSubIntervals",
";",
"var",
"nextTime",
"=",
"initialTime",
"+",
"interval",
";",
"var",
"interpolatedTimes",
"=",
"[",
"]",
";",
"var",
"interpolatedValues",
"=",
"[",
"]",
";",
"while",
"(",
"nextTime",
"<",
"curve",
".",
"times",
"[",
"i",
"]",
")",
"{",
"interpolatedTimes",
".",
"push",
"(",
"nextTime",
")",
";",
"nextTime",
"+=",
"interval",
";",
"interpolatedValues",
".",
"push",
"(",
"nextValue",
")",
";",
"nextValue",
"+=",
"step",
";",
"}",
"curve",
".",
"times",
"=",
"inject",
"(",
"curve",
".",
"times",
",",
"i",
",",
"interpolatedTimes",
")",
";",
"curve",
".",
"values",
"=",
"inject",
"(",
"curve",
".",
"values",
",",
"i",
",",
"interpolatedValues",
")",
";",
"}",
"}",
"}"
] | Rotations are defined as Euler angles which can have values of any size These will be converted to quaternions which don't support values greater than PI, so we'll interpolate large rotations | [
"Rotations",
"are",
"defined",
"as",
"Euler",
"angles",
"which",
"can",
"have",
"values",
"of",
"any",
"size",
"These",
"will",
"be",
"converted",
"to",
"quaternions",
"which",
"don",
"t",
"support",
"values",
"greater",
"than",
"PI",
"so",
"we",
"ll",
"interpolate",
"large",
"rotations"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L2799-L2840 |
|
7,873 | exokitxr/exokit | examples/FBXLoader.js | function ( reader ) {
// footer size: 160bytes + 16-byte alignment padding
// - 16bytes: magic
// - padding til 16-byte alignment (at least 1byte?)
// (seems like some exporters embed fixed 15 or 16bytes?)
// - 4bytes: magic
// - 4bytes: version
// - 120bytes: zero
// - 16bytes: magic
if ( reader.size() % 16 === 0 ) {
return ( ( reader.getOffset() + 160 + 16 ) & ~ 0xf ) >= reader.size();
} else {
return reader.getOffset() + 160 + 16 >= reader.size();
}
} | javascript | function ( reader ) {
// footer size: 160bytes + 16-byte alignment padding
// - 16bytes: magic
// - padding til 16-byte alignment (at least 1byte?)
// (seems like some exporters embed fixed 15 or 16bytes?)
// - 4bytes: magic
// - 4bytes: version
// - 120bytes: zero
// - 16bytes: magic
if ( reader.size() % 16 === 0 ) {
return ( ( reader.getOffset() + 160 + 16 ) & ~ 0xf ) >= reader.size();
} else {
return reader.getOffset() + 160 + 16 >= reader.size();
}
} | [
"function",
"(",
"reader",
")",
"{",
"// footer size: 160bytes + 16-byte alignment padding",
"// - 16bytes: magic",
"// - padding til 16-byte alignment (at least 1byte?)",
"//\t(seems like some exporters embed fixed 15 or 16bytes?)",
"// - 4bytes: magic",
"// - 4bytes: version",
"// - 120bytes: zero",
"// - 16bytes: magic",
"if",
"(",
"reader",
".",
"size",
"(",
")",
"%",
"16",
"===",
"0",
")",
"{",
"return",
"(",
"(",
"reader",
".",
"getOffset",
"(",
")",
"+",
"160",
"+",
"16",
")",
"&",
"~",
"0xf",
")",
">=",
"reader",
".",
"size",
"(",
")",
";",
"}",
"else",
"{",
"return",
"reader",
".",
"getOffset",
"(",
")",
"+",
"160",
"+",
"16",
">=",
"reader",
".",
"size",
"(",
")",
";",
"}",
"}"
] | Check if reader has reached the end of content. | [
"Check",
"if",
"reader",
"has",
"reached",
"the",
"end",
"of",
"content",
"."
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L3212-L3232 |
|
7,874 | exokitxr/exokit | examples/FBXLoader.js | function ( reader, version ) {
var node = {};
// The first three data sizes depends on version.
var endOffset = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32();
var numProperties = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32();
// note: do not remove this even if you get a linter warning as it moves the buffer forward
var propertyListLen = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32();
var nameLen = reader.getUint8();
var name = reader.getString( nameLen );
// Regards this node as NULL-record if endOffset is zero
if ( endOffset === 0 ) return null;
var propertyList = [];
for ( var i = 0; i < numProperties; i ++ ) {
propertyList.push( this.parseProperty( reader ) );
}
// Regards the first three elements in propertyList as id, attrName, and attrType
var id = propertyList.length > 0 ? propertyList[ 0 ] : '';
var attrName = propertyList.length > 1 ? propertyList[ 1 ] : '';
var attrType = propertyList.length > 2 ? propertyList[ 2 ] : '';
// check if this node represents just a single property
// like (name, 0) set or (name2, [0, 1, 2]) set of {name: 0, name2: [0, 1, 2]}
node.singleProperty = ( numProperties === 1 && reader.getOffset() === endOffset ) ? true : false;
while ( endOffset > reader.getOffset() ) {
var subNode = this.parseNode( reader, version );
if ( subNode !== null ) this.parseSubNode( name, node, subNode );
}
node.propertyList = propertyList; // raw property list used by parent
if ( typeof id === 'number' ) node.id = id;
if ( attrName !== '' ) node.attrName = attrName;
if ( attrType !== '' ) node.attrType = attrType;
if ( name !== '' ) node.name = name;
return node;
} | javascript | function ( reader, version ) {
var node = {};
// The first three data sizes depends on version.
var endOffset = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32();
var numProperties = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32();
// note: do not remove this even if you get a linter warning as it moves the buffer forward
var propertyListLen = ( version >= 7500 ) ? reader.getUint64() : reader.getUint32();
var nameLen = reader.getUint8();
var name = reader.getString( nameLen );
// Regards this node as NULL-record if endOffset is zero
if ( endOffset === 0 ) return null;
var propertyList = [];
for ( var i = 0; i < numProperties; i ++ ) {
propertyList.push( this.parseProperty( reader ) );
}
// Regards the first three elements in propertyList as id, attrName, and attrType
var id = propertyList.length > 0 ? propertyList[ 0 ] : '';
var attrName = propertyList.length > 1 ? propertyList[ 1 ] : '';
var attrType = propertyList.length > 2 ? propertyList[ 2 ] : '';
// check if this node represents just a single property
// like (name, 0) set or (name2, [0, 1, 2]) set of {name: 0, name2: [0, 1, 2]}
node.singleProperty = ( numProperties === 1 && reader.getOffset() === endOffset ) ? true : false;
while ( endOffset > reader.getOffset() ) {
var subNode = this.parseNode( reader, version );
if ( subNode !== null ) this.parseSubNode( name, node, subNode );
}
node.propertyList = propertyList; // raw property list used by parent
if ( typeof id === 'number' ) node.id = id;
if ( attrName !== '' ) node.attrName = attrName;
if ( attrType !== '' ) node.attrType = attrType;
if ( name !== '' ) node.name = name;
return node;
} | [
"function",
"(",
"reader",
",",
"version",
")",
"{",
"var",
"node",
"=",
"{",
"}",
";",
"// The first three data sizes depends on version.",
"var",
"endOffset",
"=",
"(",
"version",
">=",
"7500",
")",
"?",
"reader",
".",
"getUint64",
"(",
")",
":",
"reader",
".",
"getUint32",
"(",
")",
";",
"var",
"numProperties",
"=",
"(",
"version",
">=",
"7500",
")",
"?",
"reader",
".",
"getUint64",
"(",
")",
":",
"reader",
".",
"getUint32",
"(",
")",
";",
"// note: do not remove this even if you get a linter warning as it moves the buffer forward",
"var",
"propertyListLen",
"=",
"(",
"version",
">=",
"7500",
")",
"?",
"reader",
".",
"getUint64",
"(",
")",
":",
"reader",
".",
"getUint32",
"(",
")",
";",
"var",
"nameLen",
"=",
"reader",
".",
"getUint8",
"(",
")",
";",
"var",
"name",
"=",
"reader",
".",
"getString",
"(",
"nameLen",
")",
";",
"// Regards this node as NULL-record if endOffset is zero",
"if",
"(",
"endOffset",
"===",
"0",
")",
"return",
"null",
";",
"var",
"propertyList",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"numProperties",
";",
"i",
"++",
")",
"{",
"propertyList",
".",
"push",
"(",
"this",
".",
"parseProperty",
"(",
"reader",
")",
")",
";",
"}",
"// Regards the first three elements in propertyList as id, attrName, and attrType",
"var",
"id",
"=",
"propertyList",
".",
"length",
">",
"0",
"?",
"propertyList",
"[",
"0",
"]",
":",
"''",
";",
"var",
"attrName",
"=",
"propertyList",
".",
"length",
">",
"1",
"?",
"propertyList",
"[",
"1",
"]",
":",
"''",
";",
"var",
"attrType",
"=",
"propertyList",
".",
"length",
">",
"2",
"?",
"propertyList",
"[",
"2",
"]",
":",
"''",
";",
"// check if this node represents just a single property",
"// like (name, 0) set or (name2, [0, 1, 2]) set of {name: 0, name2: [0, 1, 2]}",
"node",
".",
"singleProperty",
"=",
"(",
"numProperties",
"===",
"1",
"&&",
"reader",
".",
"getOffset",
"(",
")",
"===",
"endOffset",
")",
"?",
"true",
":",
"false",
";",
"while",
"(",
"endOffset",
">",
"reader",
".",
"getOffset",
"(",
")",
")",
"{",
"var",
"subNode",
"=",
"this",
".",
"parseNode",
"(",
"reader",
",",
"version",
")",
";",
"if",
"(",
"subNode",
"!==",
"null",
")",
"this",
".",
"parseSubNode",
"(",
"name",
",",
"node",
",",
"subNode",
")",
";",
"}",
"node",
".",
"propertyList",
"=",
"propertyList",
";",
"// raw property list used by parent",
"if",
"(",
"typeof",
"id",
"===",
"'number'",
")",
"node",
".",
"id",
"=",
"id",
";",
"if",
"(",
"attrName",
"!==",
"''",
")",
"node",
".",
"attrName",
"=",
"attrName",
";",
"if",
"(",
"attrType",
"!==",
"''",
")",
"node",
".",
"attrType",
"=",
"attrType",
";",
"if",
"(",
"name",
"!==",
"''",
")",
"node",
".",
"name",
"=",
"name",
";",
"return",
"node",
";",
"}"
] | recursively parse nodes until the end of the file is reached | [
"recursively",
"parse",
"nodes",
"until",
"the",
"end",
"of",
"the",
"file",
"is",
"reached"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L3235-L3286 |
|
7,875 | exokitxr/exokit | examples/FBXLoader.js | getData | function getData( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {
var index;
switch ( infoObject.mappingType ) {
case 'ByPolygonVertex' :
index = polygonVertexIndex;
break;
case 'ByPolygon' :
index = polygonIndex;
break;
case 'ByVertice' :
index = vertexIndex;
break;
case 'AllSame' :
index = infoObject.indices[ 0 ];
break;
default :
console.warn( 'THREE.FBXLoader: unknown attribute mapping type ' + infoObject.mappingType );
}
if ( infoObject.referenceType === 'IndexToDirect' ) index = infoObject.indices[ index ];
var from = index * infoObject.dataSize;
var to = from + infoObject.dataSize;
return slice( dataArray, infoObject.buffer, from, to );
} | javascript | function getData( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {
var index;
switch ( infoObject.mappingType ) {
case 'ByPolygonVertex' :
index = polygonVertexIndex;
break;
case 'ByPolygon' :
index = polygonIndex;
break;
case 'ByVertice' :
index = vertexIndex;
break;
case 'AllSame' :
index = infoObject.indices[ 0 ];
break;
default :
console.warn( 'THREE.FBXLoader: unknown attribute mapping type ' + infoObject.mappingType );
}
if ( infoObject.referenceType === 'IndexToDirect' ) index = infoObject.indices[ index ];
var from = index * infoObject.dataSize;
var to = from + infoObject.dataSize;
return slice( dataArray, infoObject.buffer, from, to );
} | [
"function",
"getData",
"(",
"polygonVertexIndex",
",",
"polygonIndex",
",",
"vertexIndex",
",",
"infoObject",
")",
"{",
"var",
"index",
";",
"switch",
"(",
"infoObject",
".",
"mappingType",
")",
"{",
"case",
"'ByPolygonVertex'",
":",
"index",
"=",
"polygonVertexIndex",
";",
"break",
";",
"case",
"'ByPolygon'",
":",
"index",
"=",
"polygonIndex",
";",
"break",
";",
"case",
"'ByVertice'",
":",
"index",
"=",
"vertexIndex",
";",
"break",
";",
"case",
"'AllSame'",
":",
"index",
"=",
"infoObject",
".",
"indices",
"[",
"0",
"]",
";",
"break",
";",
"default",
":",
"console",
".",
"warn",
"(",
"'THREE.FBXLoader: unknown attribute mapping type '",
"+",
"infoObject",
".",
"mappingType",
")",
";",
"}",
"if",
"(",
"infoObject",
".",
"referenceType",
"===",
"'IndexToDirect'",
")",
"index",
"=",
"infoObject",
".",
"indices",
"[",
"index",
"]",
";",
"var",
"from",
"=",
"index",
"*",
"infoObject",
".",
"dataSize",
";",
"var",
"to",
"=",
"from",
"+",
"infoObject",
".",
"dataSize",
";",
"return",
"slice",
"(",
"dataArray",
",",
"infoObject",
".",
"buffer",
",",
"from",
",",
"to",
")",
";",
"}"
] | extracts the data from the correct position in the FBX array based on indexing type | [
"extracts",
"the",
"data",
"from",
"the",
"correct",
"position",
"in",
"the",
"FBX",
"array",
"based",
"on",
"indexing",
"type"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L3836-L3866 |
7,876 | exokitxr/exokit | examples/FBXLoader.js | parseNumberArray | function parseNumberArray( value ) {
var array = value.split( ',' ).map( function ( val ) {
return parseFloat( val );
} );
return array;
} | javascript | function parseNumberArray( value ) {
var array = value.split( ',' ).map( function ( val ) {
return parseFloat( val );
} );
return array;
} | [
"function",
"parseNumberArray",
"(",
"value",
")",
"{",
"var",
"array",
"=",
"value",
".",
"split",
"(",
"','",
")",
".",
"map",
"(",
"function",
"(",
"val",
")",
"{",
"return",
"parseFloat",
"(",
"val",
")",
";",
"}",
")",
";",
"return",
"array",
";",
"}"
] | Parses comma separated list of numbers and returns them an array. Used internally by the TextParser | [
"Parses",
"comma",
"separated",
"list",
"of",
"numbers",
"and",
"returns",
"them",
"an",
"array",
".",
"Used",
"internally",
"by",
"the",
"TextParser"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L3963-L3973 |
7,877 | exokitxr/exokit | examples/FBXLoader.js | inject | function inject( a1, index, a2 ) {
return a1.slice( 0, index ).concat( a2 ).concat( a1.slice( index ) );
} | javascript | function inject( a1, index, a2 ) {
return a1.slice( 0, index ).concat( a2 ).concat( a1.slice( index ) );
} | [
"function",
"inject",
"(",
"a1",
",",
"index",
",",
"a2",
")",
"{",
"return",
"a1",
".",
"slice",
"(",
"0",
",",
"index",
")",
".",
"concat",
"(",
"a2",
")",
".",
"concat",
"(",
"a1",
".",
"slice",
"(",
"index",
")",
")",
";",
"}"
] | inject array a2 into array a1 at index | [
"inject",
"array",
"a2",
"into",
"array",
"a1",
"at",
"index"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/FBXLoader.js#L4007-L4011 |
7,878 | exokitxr/exokit | examples/svg-boundings.js | expandXBounds | function expandXBounds(bounds, value) {
if (bounds[MIN_X] > value) bounds[MIN_X] = value;else if (bounds[MAX_X] < value) bounds[MAX_X] = value;
} | javascript | function expandXBounds(bounds, value) {
if (bounds[MIN_X] > value) bounds[MIN_X] = value;else if (bounds[MAX_X] < value) bounds[MAX_X] = value;
} | [
"function",
"expandXBounds",
"(",
"bounds",
",",
"value",
")",
"{",
"if",
"(",
"bounds",
"[",
"MIN_X",
"]",
">",
"value",
")",
"bounds",
"[",
"MIN_X",
"]",
"=",
"value",
";",
"else",
"if",
"(",
"bounds",
"[",
"MAX_X",
"]",
"<",
"value",
")",
"bounds",
"[",
"MAX_X",
"]",
"=",
"value",
";",
"}"
] | expand the x-bounds, if the value lies outside the bounding box | [
"expand",
"the",
"x",
"-",
"bounds",
"if",
"the",
"value",
"lies",
"outside",
"the",
"bounding",
"box"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/svg-boundings.js#L272-L274 |
7,879 | exokitxr/exokit | examples/svg-boundings.js | expandYBounds | function expandYBounds(bounds, value) {
if (bounds[MIN_Y] > value) bounds[MIN_Y] = value;else if (bounds[MAX_Y] < value) bounds[MAX_Y] = value;
} | javascript | function expandYBounds(bounds, value) {
if (bounds[MIN_Y] > value) bounds[MIN_Y] = value;else if (bounds[MAX_Y] < value) bounds[MAX_Y] = value;
} | [
"function",
"expandYBounds",
"(",
"bounds",
",",
"value",
")",
"{",
"if",
"(",
"bounds",
"[",
"MIN_Y",
"]",
">",
"value",
")",
"bounds",
"[",
"MIN_Y",
"]",
"=",
"value",
";",
"else",
"if",
"(",
"bounds",
"[",
"MAX_Y",
"]",
"<",
"value",
")",
"bounds",
"[",
"MAX_Y",
"]",
"=",
"value",
";",
"}"
] | expand the y-bounds, if the value lies outside the bounding box | [
"expand",
"the",
"y",
"-",
"bounds",
"if",
"the",
"value",
"lies",
"outside",
"the",
"bounding",
"box"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/svg-boundings.js#L279-L281 |
7,880 | exokitxr/exokit | examples/svg-boundings.js | calculateBezier | function calculateBezier(t, p0, p1, p2, p3) {
var mt = 1 - t;
return mt * mt * mt * p0 + 3 * mt * mt * t * p1 + 3 * mt * t * t * p2 + t * t * t * p3;
} | javascript | function calculateBezier(t, p0, p1, p2, p3) {
var mt = 1 - t;
return mt * mt * mt * p0 + 3 * mt * mt * t * p1 + 3 * mt * t * t * p2 + t * t * t * p3;
} | [
"function",
"calculateBezier",
"(",
"t",
",",
"p0",
",",
"p1",
",",
"p2",
",",
"p3",
")",
"{",
"var",
"mt",
"=",
"1",
"-",
"t",
";",
"return",
"mt",
"*",
"mt",
"*",
"mt",
"*",
"p0",
"+",
"3",
"*",
"mt",
"*",
"mt",
"*",
"t",
"*",
"p1",
"+",
"3",
"*",
"mt",
"*",
"t",
"*",
"t",
"*",
"p2",
"+",
"t",
"*",
"t",
"*",
"t",
"*",
"p3",
";",
"}"
] | Calculate the bezier value for one dimension at distance 't' | [
"Calculate",
"the",
"bezier",
"value",
"for",
"one",
"dimension",
"at",
"distance",
"t"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/svg-boundings.js#L286-L289 |
7,881 | exokitxr/exokit | examples/svg-boundings.js | function (str) {
var output = [];
var idx = 0;
var c, num;
var nextNumber = function () {
var chars = [];
while (/[^-\d\.]/.test(str.charAt(idx))) {
// skip the non-digit characters
idx++;
}
if ('-' === str.charAt(idx)) {
chars.push('-');
idx++;
}
while ((c = str.charAt(idx)) && /[\d\.Ee]/.test(c)) {
chars.push(c);
idx++;
}
return parseFloat(chars.join(''));
};
while (!isNaN(num = nextNumber())) output.push(num);
return output;
} | javascript | function (str) {
var output = [];
var idx = 0;
var c, num;
var nextNumber = function () {
var chars = [];
while (/[^-\d\.]/.test(str.charAt(idx))) {
// skip the non-digit characters
idx++;
}
if ('-' === str.charAt(idx)) {
chars.push('-');
idx++;
}
while ((c = str.charAt(idx)) && /[\d\.Ee]/.test(c)) {
chars.push(c);
idx++;
}
return parseFloat(chars.join(''));
};
while (!isNaN(num = nextNumber())) output.push(num);
return output;
} | [
"function",
"(",
"str",
")",
"{",
"var",
"output",
"=",
"[",
"]",
";",
"var",
"idx",
"=",
"0",
";",
"var",
"c",
",",
"num",
";",
"var",
"nextNumber",
"=",
"function",
"(",
")",
"{",
"var",
"chars",
"=",
"[",
"]",
";",
"while",
"(",
"/",
"[^-\\d\\.]",
"/",
".",
"test",
"(",
"str",
".",
"charAt",
"(",
"idx",
")",
")",
")",
"{",
"// skip the non-digit characters",
"idx",
"++",
";",
"}",
"if",
"(",
"'-'",
"===",
"str",
".",
"charAt",
"(",
"idx",
")",
")",
"{",
"chars",
".",
"push",
"(",
"'-'",
")",
";",
"idx",
"++",
";",
"}",
"while",
"(",
"(",
"c",
"=",
"str",
".",
"charAt",
"(",
"idx",
")",
")",
"&&",
"/",
"[\\d\\.Ee]",
"/",
".",
"test",
"(",
"c",
")",
")",
"{",
"chars",
".",
"push",
"(",
"c",
")",
";",
"idx",
"++",
";",
"}",
"return",
"parseFloat",
"(",
"chars",
".",
"join",
"(",
"''",
")",
")",
";",
"}",
";",
"while",
"(",
"!",
"isNaN",
"(",
"num",
"=",
"nextNumber",
"(",
")",
")",
")",
"output",
".",
"push",
"(",
"num",
")",
";",
"return",
"output",
";",
"}"
] | Helper - get arguments of a path drawing command | [
"Helper",
"-",
"get",
"arguments",
"of",
"a",
"path",
"drawing",
"command"
] | 989c3068bc82d508fee16f3dea7ee37a73834f74 | https://github.com/exokitxr/exokit/blob/989c3068bc82d508fee16f3dea7ee37a73834f74/examples/svg-boundings.js#L618-L647 |
|
7,882 | fgnass/spin.js | Gruntfile.js | function (res, path) {
let defaultSrc = "default-src 'self';";
let styleSrc = "style-src 'self' fonts.googleapis.com;";
let fontSrc = "font-src 'self' fonts.gstatic.com;";
let imgSrc = "img-src 'self' www.gravatar.com;";
res.setHeader('Content-Security-Policy', `${defaultSrc} ${styleSrc} ${fontSrc} ${imgSrc}`);
} | javascript | function (res, path) {
let defaultSrc = "default-src 'self';";
let styleSrc = "style-src 'self' fonts.googleapis.com;";
let fontSrc = "font-src 'self' fonts.gstatic.com;";
let imgSrc = "img-src 'self' www.gravatar.com;";
res.setHeader('Content-Security-Policy', `${defaultSrc} ${styleSrc} ${fontSrc} ${imgSrc}`);
} | [
"function",
"(",
"res",
",",
"path",
")",
"{",
"let",
"defaultSrc",
"=",
"\"default-src 'self';\"",
";",
"let",
"styleSrc",
"=",
"\"style-src 'self' fonts.googleapis.com;\"",
";",
"let",
"fontSrc",
"=",
"\"font-src 'self' fonts.gstatic.com;\"",
";",
"let",
"imgSrc",
"=",
"\"img-src 'self' www.gravatar.com;\"",
";",
"res",
".",
"setHeader",
"(",
"'Content-Security-Policy'",
",",
"`",
"${",
"defaultSrc",
"}",
"${",
"styleSrc",
"}",
"${",
"fontSrc",
"}",
"${",
"imgSrc",
"}",
"`",
")",
";",
"}"
] | add CSP header to ensure spin.js supports it | [
"add",
"CSP",
"header",
"to",
"ensure",
"spin",
".",
"js",
"supports",
"it"
] | e693e4f933f0a5ade9498ffcbab6c1409be92681 | https://github.com/fgnass/spin.js/blob/e693e4f933f0a5ade9498ffcbab6c1409be92681/Gruntfile.js#L14-L20 |
|
7,883 | terkelg/prompts | lib/index.js | prompt | async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
const answers = {};
const override = prompt._override || {};
questions = [].concat(questions);
let answer, question, quit, name, type;
const getFormattedAnswer = async (question, answer, skipValidation = false) => {
if (!skipValidation && question.validate && question.validate(answer) !== true) {
return;
}
return question.format ? await question.format(answer, answers) : answer
};
for (question of questions) {
({ name, type } = question);
// if property is a function, invoke it unless it's a special function
for (let key in question) {
if (passOn.includes(key)) continue;
let value = question[key];
question[key] = typeof value === 'function' ? await value(answer, { ...answers }, question) : value;
}
if (typeof question.message !== 'string') {
throw new Error('prompt message is required');
}
// update vars in case they changed
({ name, type } = question);
// skip if type is a falsy value
if (!type) continue;
if (prompts[type] === void 0) {
throw new Error(`prompt type (${type}) is not defined`);
}
if (override[question.name] !== undefined) {
answer = await getFormattedAnswer(question, override[question.name]);
if (answer !== undefined) {
answers[name] = answer;
continue;
}
}
try {
// Get the injected answer if there is one or prompt the user
answer = prompt._injected ? getInjectedAnswer(prompt._injected) : await prompts[type](question);
answers[name] = answer = await getFormattedAnswer(question, answer, true);
quit = await onSubmit(question, answer, answers);
} catch (err) {
quit = !(await onCancel(question, answers));
}
if (quit) return answers;
}
return answers;
} | javascript | async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
const answers = {};
const override = prompt._override || {};
questions = [].concat(questions);
let answer, question, quit, name, type;
const getFormattedAnswer = async (question, answer, skipValidation = false) => {
if (!skipValidation && question.validate && question.validate(answer) !== true) {
return;
}
return question.format ? await question.format(answer, answers) : answer
};
for (question of questions) {
({ name, type } = question);
// if property is a function, invoke it unless it's a special function
for (let key in question) {
if (passOn.includes(key)) continue;
let value = question[key];
question[key] = typeof value === 'function' ? await value(answer, { ...answers }, question) : value;
}
if (typeof question.message !== 'string') {
throw new Error('prompt message is required');
}
// update vars in case they changed
({ name, type } = question);
// skip if type is a falsy value
if (!type) continue;
if (prompts[type] === void 0) {
throw new Error(`prompt type (${type}) is not defined`);
}
if (override[question.name] !== undefined) {
answer = await getFormattedAnswer(question, override[question.name]);
if (answer !== undefined) {
answers[name] = answer;
continue;
}
}
try {
// Get the injected answer if there is one or prompt the user
answer = prompt._injected ? getInjectedAnswer(prompt._injected) : await prompts[type](question);
answers[name] = answer = await getFormattedAnswer(question, answer, true);
quit = await onSubmit(question, answer, answers);
} catch (err) {
quit = !(await onCancel(question, answers));
}
if (quit) return answers;
}
return answers;
} | [
"async",
"function",
"prompt",
"(",
"questions",
"=",
"[",
"]",
",",
"{",
"onSubmit",
"=",
"noop",
",",
"onCancel",
"=",
"noop",
"}",
"=",
"{",
"}",
")",
"{",
"const",
"answers",
"=",
"{",
"}",
";",
"const",
"override",
"=",
"prompt",
".",
"_override",
"||",
"{",
"}",
";",
"questions",
"=",
"[",
"]",
".",
"concat",
"(",
"questions",
")",
";",
"let",
"answer",
",",
"question",
",",
"quit",
",",
"name",
",",
"type",
";",
"const",
"getFormattedAnswer",
"=",
"async",
"(",
"question",
",",
"answer",
",",
"skipValidation",
"=",
"false",
")",
"=>",
"{",
"if",
"(",
"!",
"skipValidation",
"&&",
"question",
".",
"validate",
"&&",
"question",
".",
"validate",
"(",
"answer",
")",
"!==",
"true",
")",
"{",
"return",
";",
"}",
"return",
"question",
".",
"format",
"?",
"await",
"question",
".",
"format",
"(",
"answer",
",",
"answers",
")",
":",
"answer",
"}",
";",
"for",
"(",
"question",
"of",
"questions",
")",
"{",
"(",
"{",
"name",
",",
"type",
"}",
"=",
"question",
")",
";",
"// if property is a function, invoke it unless it's a special function",
"for",
"(",
"let",
"key",
"in",
"question",
")",
"{",
"if",
"(",
"passOn",
".",
"includes",
"(",
"key",
")",
")",
"continue",
";",
"let",
"value",
"=",
"question",
"[",
"key",
"]",
";",
"question",
"[",
"key",
"]",
"=",
"typeof",
"value",
"===",
"'function'",
"?",
"await",
"value",
"(",
"answer",
",",
"{",
"...",
"answers",
"}",
",",
"question",
")",
":",
"value",
";",
"}",
"if",
"(",
"typeof",
"question",
".",
"message",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'prompt message is required'",
")",
";",
"}",
"// update vars in case they changed",
"(",
"{",
"name",
",",
"type",
"}",
"=",
"question",
")",
";",
"// skip if type is a falsy value",
"if",
"(",
"!",
"type",
")",
"continue",
";",
"if",
"(",
"prompts",
"[",
"type",
"]",
"===",
"void",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"type",
"}",
"`",
")",
";",
"}",
"if",
"(",
"override",
"[",
"question",
".",
"name",
"]",
"!==",
"undefined",
")",
"{",
"answer",
"=",
"await",
"getFormattedAnswer",
"(",
"question",
",",
"override",
"[",
"question",
".",
"name",
"]",
")",
";",
"if",
"(",
"answer",
"!==",
"undefined",
")",
"{",
"answers",
"[",
"name",
"]",
"=",
"answer",
";",
"continue",
";",
"}",
"}",
"try",
"{",
"// Get the injected answer if there is one or prompt the user",
"answer",
"=",
"prompt",
".",
"_injected",
"?",
"getInjectedAnswer",
"(",
"prompt",
".",
"_injected",
")",
":",
"await",
"prompts",
"[",
"type",
"]",
"(",
"question",
")",
";",
"answers",
"[",
"name",
"]",
"=",
"answer",
"=",
"await",
"getFormattedAnswer",
"(",
"question",
",",
"answer",
",",
"true",
")",
";",
"quit",
"=",
"await",
"onSubmit",
"(",
"question",
",",
"answer",
",",
"answers",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"quit",
"=",
"!",
"(",
"await",
"onCancel",
"(",
"question",
",",
"answers",
")",
")",
";",
"}",
"if",
"(",
"quit",
")",
"return",
"answers",
";",
"}",
"return",
"answers",
";",
"}"
] | Prompt for a series of questions
@param {Array|Object} questions Single question object or Array of question objects
@param {Function} [onSubmit] Callback function called on prompt submit
@param {Function} [onCancel] Callback function called on cancel/abort
@returns {Object} Object with values from user input | [
"Prompt",
"for",
"a",
"series",
"of",
"questions"
] | 496f58d4fecaf67f34685af932980b1907eda642 | https://github.com/terkelg/prompts/blob/496f58d4fecaf67f34685af932980b1907eda642/lib/index.js#L15-L73 |
7,884 | regl-project/regl | lib/texture.js | destroyTextures | function destroyTextures () {
for (var i = 0; i < numTexUnits; ++i) {
gl.activeTexture(GL_TEXTURE0 + i)
gl.bindTexture(GL_TEXTURE_2D, null)
textureUnits[i] = null
}
values(textureSet).forEach(destroy)
stats.cubeCount = 0
stats.textureCount = 0
} | javascript | function destroyTextures () {
for (var i = 0; i < numTexUnits; ++i) {
gl.activeTexture(GL_TEXTURE0 + i)
gl.bindTexture(GL_TEXTURE_2D, null)
textureUnits[i] = null
}
values(textureSet).forEach(destroy)
stats.cubeCount = 0
stats.textureCount = 0
} | [
"function",
"destroyTextures",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"numTexUnits",
";",
"++",
"i",
")",
"{",
"gl",
".",
"activeTexture",
"(",
"GL_TEXTURE0",
"+",
"i",
")",
"gl",
".",
"bindTexture",
"(",
"GL_TEXTURE_2D",
",",
"null",
")",
"textureUnits",
"[",
"i",
"]",
"=",
"null",
"}",
"values",
"(",
"textureSet",
")",
".",
"forEach",
"(",
"destroy",
")",
"stats",
".",
"cubeCount",
"=",
"0",
"stats",
".",
"textureCount",
"=",
"0",
"}"
] | Called when regl is destroyed | [
"Called",
"when",
"regl",
"is",
"destroyed"
] | ca0a862c51622c2829a8b34ec79ed1650255185b | https://github.com/regl-project/regl/blob/ca0a862c51622c2829a8b34ec79ed1650255185b/lib/texture.js#L1592-L1602 |
7,885 | regl-project/regl | example/line-primitives.js | createDrawCall | function createDrawCall (props) {
return regl({
attributes: {
position: props.position
},
uniforms: {
color: props.color,
scale: props.scale,
offset: props.offset,
phase: props.phase,
freq: props.freq
},
lineWidth: lineWidth,
count: props.position.length,
primitive: props.primitive
})
} | javascript | function createDrawCall (props) {
return regl({
attributes: {
position: props.position
},
uniforms: {
color: props.color,
scale: props.scale,
offset: props.offset,
phase: props.phase,
freq: props.freq
},
lineWidth: lineWidth,
count: props.position.length,
primitive: props.primitive
})
} | [
"function",
"createDrawCall",
"(",
"props",
")",
"{",
"return",
"regl",
"(",
"{",
"attributes",
":",
"{",
"position",
":",
"props",
".",
"position",
"}",
",",
"uniforms",
":",
"{",
"color",
":",
"props",
".",
"color",
",",
"scale",
":",
"props",
".",
"scale",
",",
"offset",
":",
"props",
".",
"offset",
",",
"phase",
":",
"props",
".",
"phase",
",",
"freq",
":",
"props",
".",
"freq",
"}",
",",
"lineWidth",
":",
"lineWidth",
",",
"count",
":",
"props",
".",
"position",
".",
"length",
",",
"primitive",
":",
"props",
".",
"primitive",
"}",
")",
"}"
] | this creates a drawCall that allows you to do draw single line primitive. | [
"this",
"creates",
"a",
"drawCall",
"that",
"allows",
"you",
"to",
"do",
"draw",
"single",
"line",
"primitive",
"."
] | ca0a862c51622c2829a8b34ec79ed1650255185b | https://github.com/regl-project/regl/blob/ca0a862c51622c2829a8b34ec79ed1650255185b/example/line-primitives.js#L69-L87 |
7,886 | regl-project/regl | example/stencil-transition.js | centerMesh | function centerMesh (mesh) {
var bb = boundingBox(mesh.positions)
var _translate = [
-0.5 * (bb[0][0] + bb[1][0]),
-0.5 * (bb[0][1] + bb[1][1]),
-0.5 * (bb[0][2] + bb[1][2])
]
var translate = mat4.create()
mat4.translate(translate, translate, _translate)
mesh.positions = tform(mesh.positions, translate)
} | javascript | function centerMesh (mesh) {
var bb = boundingBox(mesh.positions)
var _translate = [
-0.5 * (bb[0][0] + bb[1][0]),
-0.5 * (bb[0][1] + bb[1][1]),
-0.5 * (bb[0][2] + bb[1][2])
]
var translate = mat4.create()
mat4.translate(translate, translate, _translate)
mesh.positions = tform(mesh.positions, translate)
} | [
"function",
"centerMesh",
"(",
"mesh",
")",
"{",
"var",
"bb",
"=",
"boundingBox",
"(",
"mesh",
".",
"positions",
")",
"var",
"_translate",
"=",
"[",
"-",
"0.5",
"*",
"(",
"bb",
"[",
"0",
"]",
"[",
"0",
"]",
"+",
"bb",
"[",
"1",
"]",
"[",
"0",
"]",
")",
",",
"-",
"0.5",
"*",
"(",
"bb",
"[",
"0",
"]",
"[",
"1",
"]",
"+",
"bb",
"[",
"1",
"]",
"[",
"1",
"]",
")",
",",
"-",
"0.5",
"*",
"(",
"bb",
"[",
"0",
"]",
"[",
"2",
"]",
"+",
"bb",
"[",
"1",
"]",
"[",
"2",
"]",
")",
"]",
"var",
"translate",
"=",
"mat4",
".",
"create",
"(",
")",
"mat4",
".",
"translate",
"(",
"translate",
",",
"translate",
",",
"_translate",
")",
"mesh",
".",
"positions",
"=",
"tform",
"(",
"mesh",
".",
"positions",
",",
"translate",
")",
"}"
] | center the rabbit mesh to the origin. | [
"center",
"the",
"rabbit",
"mesh",
"to",
"the",
"origin",
"."
] | ca0a862c51622c2829a8b34ec79ed1650255185b | https://github.com/regl-project/regl/blob/ca0a862c51622c2829a8b34ec79ed1650255185b/example/stencil-transition.js#L27-L38 |
7,887 | regl-project/regl | example/cloth.js | Constraint | function Constraint (i0, i1) {
this.i0 = i0
this.i1 = i1
this.restLength = vec3.distance(position[i0], position[i1])
} | javascript | function Constraint (i0, i1) {
this.i0 = i0
this.i1 = i1
this.restLength = vec3.distance(position[i0], position[i1])
} | [
"function",
"Constraint",
"(",
"i0",
",",
"i1",
")",
"{",
"this",
".",
"i0",
"=",
"i0",
"this",
".",
"i1",
"=",
"i1",
"this",
".",
"restLength",
"=",
"vec3",
".",
"distance",
"(",
"position",
"[",
"i0",
"]",
",",
"position",
"[",
"i1",
"]",
")",
"}"
] | create a constraint between the vertices with the indices i0 and i1. | [
"create",
"a",
"constraint",
"between",
"the",
"vertices",
"with",
"the",
"indices",
"i0",
"and",
"i1",
"."
] | ca0a862c51622c2829a8b34ec79ed1650255185b | https://github.com/regl-project/regl/blob/ca0a862c51622c2829a8b34ec79ed1650255185b/example/cloth.js#L33-L38 |
7,888 | regl-project/regl | example/graph.js | step | function step ({tick}) {
setFBO({ framebuffer: FIELDS[0] }, () => {
regl.clear({ color: [0, 0, 0, 1] })
splatMouse()
splatVerts({
vertexState: VERTEX_STATE[(tick + 1) % 2]
})
})
for (let i = 0; i < 2 * BLUR_PASSES; ++i) {
blurPass({
dest: FIELDS[(i + 1) % 2],
src: FIELDS[i % 2],
axis: (i % 2)
})
}
gradPass({
dest: FIELDS[1],
src: FIELDS[0]
})
applySpringForces({
dest: VERTEX_STATE[(tick + 1) % 2],
src: VERTEX_STATE[tick % 2]
})
integrateVerts({
dest: VERTEX_STATE[tick % 2],
src: VERTEX_STATE[(tick + 1) % 2],
field: FIELDS[1]
})
} | javascript | function step ({tick}) {
setFBO({ framebuffer: FIELDS[0] }, () => {
regl.clear({ color: [0, 0, 0, 1] })
splatMouse()
splatVerts({
vertexState: VERTEX_STATE[(tick + 1) % 2]
})
})
for (let i = 0; i < 2 * BLUR_PASSES; ++i) {
blurPass({
dest: FIELDS[(i + 1) % 2],
src: FIELDS[i % 2],
axis: (i % 2)
})
}
gradPass({
dest: FIELDS[1],
src: FIELDS[0]
})
applySpringForces({
dest: VERTEX_STATE[(tick + 1) % 2],
src: VERTEX_STATE[tick % 2]
})
integrateVerts({
dest: VERTEX_STATE[tick % 2],
src: VERTEX_STATE[(tick + 1) % 2],
field: FIELDS[1]
})
} | [
"function",
"step",
"(",
"{",
"tick",
"}",
")",
"{",
"setFBO",
"(",
"{",
"framebuffer",
":",
"FIELDS",
"[",
"0",
"]",
"}",
",",
"(",
")",
"=>",
"{",
"regl",
".",
"clear",
"(",
"{",
"color",
":",
"[",
"0",
",",
"0",
",",
"0",
",",
"1",
"]",
"}",
")",
"splatMouse",
"(",
")",
"splatVerts",
"(",
"{",
"vertexState",
":",
"VERTEX_STATE",
"[",
"(",
"tick",
"+",
"1",
")",
"%",
"2",
"]",
"}",
")",
"}",
")",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"2",
"*",
"BLUR_PASSES",
";",
"++",
"i",
")",
"{",
"blurPass",
"(",
"{",
"dest",
":",
"FIELDS",
"[",
"(",
"i",
"+",
"1",
")",
"%",
"2",
"]",
",",
"src",
":",
"FIELDS",
"[",
"i",
"%",
"2",
"]",
",",
"axis",
":",
"(",
"i",
"%",
"2",
")",
"}",
")",
"}",
"gradPass",
"(",
"{",
"dest",
":",
"FIELDS",
"[",
"1",
"]",
",",
"src",
":",
"FIELDS",
"[",
"0",
"]",
"}",
")",
"applySpringForces",
"(",
"{",
"dest",
":",
"VERTEX_STATE",
"[",
"(",
"tick",
"+",
"1",
")",
"%",
"2",
"]",
",",
"src",
":",
"VERTEX_STATE",
"[",
"tick",
"%",
"2",
"]",
"}",
")",
"integrateVerts",
"(",
"{",
"dest",
":",
"VERTEX_STATE",
"[",
"tick",
"%",
"2",
"]",
",",
"src",
":",
"VERTEX_STATE",
"[",
"(",
"tick",
"+",
"1",
")",
"%",
"2",
"]",
",",
"field",
":",
"FIELDS",
"[",
"1",
"]",
"}",
")",
"}"
] | Main integration loop | [
"Main",
"integration",
"loop"
] | ca0a862c51622c2829a8b34ec79ed1650255185b | https://github.com/regl-project/regl/blob/ca0a862c51622c2829a8b34ec79ed1650255185b/example/graph.js#L441-L469 |
7,889 | regl-project/regl | example/physics.js | getModelMatrix | function getModelMatrix (rb) {
var ms = rb.getMotionState()
if (ms) {
ms.getWorldTransform(transformTemp)
var p = transformTemp.getOrigin()
var q = transformTemp.getRotation()
return mat4.fromRotationTranslation(
[], [q.x(), q.y(), q.z(), q.w()], [p.x(), p.y(), p.z()])
}
} | javascript | function getModelMatrix (rb) {
var ms = rb.getMotionState()
if (ms) {
ms.getWorldTransform(transformTemp)
var p = transformTemp.getOrigin()
var q = transformTemp.getRotation()
return mat4.fromRotationTranslation(
[], [q.x(), q.y(), q.z(), q.w()], [p.x(), p.y(), p.z()])
}
} | [
"function",
"getModelMatrix",
"(",
"rb",
")",
"{",
"var",
"ms",
"=",
"rb",
".",
"getMotionState",
"(",
")",
"if",
"(",
"ms",
")",
"{",
"ms",
".",
"getWorldTransform",
"(",
"transformTemp",
")",
"var",
"p",
"=",
"transformTemp",
".",
"getOrigin",
"(",
")",
"var",
"q",
"=",
"transformTemp",
".",
"getRotation",
"(",
")",
"return",
"mat4",
".",
"fromRotationTranslation",
"(",
"[",
"]",
",",
"[",
"q",
".",
"x",
"(",
")",
",",
"q",
".",
"y",
"(",
")",
",",
"q",
".",
"z",
"(",
")",
",",
"q",
".",
"w",
"(",
")",
"]",
",",
"[",
"p",
".",
"x",
"(",
")",
",",
"p",
".",
"y",
"(",
")",
",",
"p",
".",
"z",
"(",
")",
"]",
")",
"}",
"}"
] | extracts the model matrix from a rigid body. | [
"extracts",
"the",
"model",
"matrix",
"from",
"a",
"rigid",
"body",
"."
] | ca0a862c51622c2829a8b34ec79ed1650255185b | https://github.com/regl-project/regl/blob/ca0a862c51622c2829a8b34ec79ed1650255185b/example/physics.js#L293-L304 |
7,890 | regl-project/regl | example/pong.js | createAudioBuffer | function createAudioBuffer (length, createAudioDataCallback) {
var channels = 2
var frameCount = context.sampleRate * length
var audioBuffer = context.createBuffer(channels, frameCount, context.sampleRate)
for (var channel = 0; channel < channels; channel++) {
var channelData = audioBuffer.getChannelData(channel)
createAudioDataCallback(channelData, frameCount)
}
return audioBuffer
} | javascript | function createAudioBuffer (length, createAudioDataCallback) {
var channels = 2
var frameCount = context.sampleRate * length
var audioBuffer = context.createBuffer(channels, frameCount, context.sampleRate)
for (var channel = 0; channel < channels; channel++) {
var channelData = audioBuffer.getChannelData(channel)
createAudioDataCallback(channelData, frameCount)
}
return audioBuffer
} | [
"function",
"createAudioBuffer",
"(",
"length",
",",
"createAudioDataCallback",
")",
"{",
"var",
"channels",
"=",
"2",
"var",
"frameCount",
"=",
"context",
".",
"sampleRate",
"*",
"length",
"var",
"audioBuffer",
"=",
"context",
".",
"createBuffer",
"(",
"channels",
",",
"frameCount",
",",
"context",
".",
"sampleRate",
")",
"for",
"(",
"var",
"channel",
"=",
"0",
";",
"channel",
"<",
"channels",
";",
"channel",
"++",
")",
"{",
"var",
"channelData",
"=",
"audioBuffer",
".",
"getChannelData",
"(",
"channel",
")",
"createAudioDataCallback",
"(",
"channelData",
",",
"frameCount",
")",
"}",
"return",
"audioBuffer",
"}"
] | create audio buffer that lasts `length` seconds, and `createAudioDataCallback` will will fill each of the two channels of the buffer with audio data. | [
"create",
"audio",
"buffer",
"that",
"lasts",
"length",
"seconds",
"and",
"createAudioDataCallback",
"will",
"will",
"fill",
"each",
"of",
"the",
"two",
"channels",
"of",
"the",
"buffer",
"with",
"audio",
"data",
"."
] | ca0a862c51622c2829a8b34ec79ed1650255185b | https://github.com/regl-project/regl/blob/ca0a862c51622c2829a8b34ec79ed1650255185b/example/pong.js#L104-L114 |
7,891 | regl-project/regl | lib/util/codegen.js | block | function block () {
var code = []
function push () {
code.push.apply(code, slice(arguments))
}
var vars = []
function def () {
var name = 'v' + (varCounter++)
vars.push(name)
if (arguments.length > 0) {
code.push(name, '=')
code.push.apply(code, slice(arguments))
code.push(';')
}
return name
}
return extend(push, {
def: def,
toString: function () {
return join([
(vars.length > 0 ? 'var ' + vars + ';' : ''),
join(code)
])
}
})
} | javascript | function block () {
var code = []
function push () {
code.push.apply(code, slice(arguments))
}
var vars = []
function def () {
var name = 'v' + (varCounter++)
vars.push(name)
if (arguments.length > 0) {
code.push(name, '=')
code.push.apply(code, slice(arguments))
code.push(';')
}
return name
}
return extend(push, {
def: def,
toString: function () {
return join([
(vars.length > 0 ? 'var ' + vars + ';' : ''),
join(code)
])
}
})
} | [
"function",
"block",
"(",
")",
"{",
"var",
"code",
"=",
"[",
"]",
"function",
"push",
"(",
")",
"{",
"code",
".",
"push",
".",
"apply",
"(",
"code",
",",
"slice",
"(",
"arguments",
")",
")",
"}",
"var",
"vars",
"=",
"[",
"]",
"function",
"def",
"(",
")",
"{",
"var",
"name",
"=",
"'v'",
"+",
"(",
"varCounter",
"++",
")",
"vars",
".",
"push",
"(",
"name",
")",
"if",
"(",
"arguments",
".",
"length",
">",
"0",
")",
"{",
"code",
".",
"push",
"(",
"name",
",",
"'='",
")",
"code",
".",
"push",
".",
"apply",
"(",
"code",
",",
"slice",
"(",
"arguments",
")",
")",
"code",
".",
"push",
"(",
"';'",
")",
"}",
"return",
"name",
"}",
"return",
"extend",
"(",
"push",
",",
"{",
"def",
":",
"def",
",",
"toString",
":",
"function",
"(",
")",
"{",
"return",
"join",
"(",
"[",
"(",
"vars",
".",
"length",
">",
"0",
"?",
"'var '",
"+",
"vars",
"+",
"';'",
":",
"''",
")",
",",
"join",
"(",
"code",
")",
"]",
")",
"}",
"}",
")",
"}"
] | create a code block | [
"create",
"a",
"code",
"block"
] | ca0a862c51622c2829a8b34ec79ed1650255185b | https://github.com/regl-project/regl/blob/ca0a862c51622c2829a8b34ec79ed1650255185b/lib/util/codegen.js#L34-L63 |
7,892 | regl-project/regl | lib/core.js | sortState | function sortState (state) {
return state.sort(function (a, b) {
if (a === S_VIEWPORT) {
return -1
} else if (b === S_VIEWPORT) {
return 1
}
return (a < b) ? -1 : 1
})
} | javascript | function sortState (state) {
return state.sort(function (a, b) {
if (a === S_VIEWPORT) {
return -1
} else if (b === S_VIEWPORT) {
return 1
}
return (a < b) ? -1 : 1
})
} | [
"function",
"sortState",
"(",
"state",
")",
"{",
"return",
"state",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"a",
"===",
"S_VIEWPORT",
")",
"{",
"return",
"-",
"1",
"}",
"else",
"if",
"(",
"b",
"===",
"S_VIEWPORT",
")",
"{",
"return",
"1",
"}",
"return",
"(",
"a",
"<",
"b",
")",
"?",
"-",
"1",
":",
"1",
"}",
")",
"}"
] | Make sure viewport is processed first | [
"Make",
"sure",
"viewport",
"is",
"processed",
"first"
] | ca0a862c51622c2829a8b34ec79ed1650255185b | https://github.com/regl-project/regl/blob/ca0a862c51622c2829a8b34ec79ed1650255185b/lib/core.js#L226-L235 |
7,893 | firebase/angularfire | src/storage/FirebaseStorage.js | _unwrapStorageSnapshot | function _unwrapStorageSnapshot(storageSnapshot) {
return {
bytesTransferred: storageSnapshot.bytesTransferred,
downloadURL: storageSnapshot.downloadURL,
metadata: storageSnapshot.metadata,
ref: storageSnapshot.ref,
state: storageSnapshot.state,
task: storageSnapshot.task,
totalBytes: storageSnapshot.totalBytes
};
} | javascript | function _unwrapStorageSnapshot(storageSnapshot) {
return {
bytesTransferred: storageSnapshot.bytesTransferred,
downloadURL: storageSnapshot.downloadURL,
metadata: storageSnapshot.metadata,
ref: storageSnapshot.ref,
state: storageSnapshot.state,
task: storageSnapshot.task,
totalBytes: storageSnapshot.totalBytes
};
} | [
"function",
"_unwrapStorageSnapshot",
"(",
"storageSnapshot",
")",
"{",
"return",
"{",
"bytesTransferred",
":",
"storageSnapshot",
".",
"bytesTransferred",
",",
"downloadURL",
":",
"storageSnapshot",
".",
"downloadURL",
",",
"metadata",
":",
"storageSnapshot",
".",
"metadata",
",",
"ref",
":",
"storageSnapshot",
".",
"ref",
",",
"state",
":",
"storageSnapshot",
".",
"state",
",",
"task",
":",
"storageSnapshot",
".",
"task",
",",
"totalBytes",
":",
"storageSnapshot",
".",
"totalBytes",
"}",
";",
"}"
] | Take a Storage snapshot and unwrap only the needed properties.
@param snapshot
@returns An object containing the unwrapped values. | [
"Take",
"a",
"Storage",
"snapshot",
"and",
"unwrap",
"only",
"the",
"needed",
"properties",
"."
] | b6dca6ea5a81b3edd44230fb1cb6ca62419f1926 | https://github.com/firebase/angularfire/blob/b6dca6ea5a81b3edd44230fb1cb6ca62419f1926/src/storage/FirebaseStorage.js#L52-L62 |
7,894 | firebase/angularfire | src/database/FirebaseObject.js | FirebaseObject | function FirebaseObject(ref) {
if( !(this instanceof FirebaseObject) ) {
return new FirebaseObject(ref);
}
var self = this;
// These are private config props and functions used internally
// they are collected here to reduce clutter in console.log and forEach
this.$$conf = {
// synchronizes data to Firebase
sync: new ObjectSyncManager(this, ref),
// stores the Firebase ref
ref: ref,
// synchronizes $scope variables with this object
binding: new ThreeWayBinding(this),
// stores observers registered with $watch
listeners: []
};
// this bit of magic makes $$conf non-enumerable and non-configurable
// and non-writable (its properties are still writable but the ref cannot be replaced)
// we redundantly assign it above so the IDE can relax
Object.defineProperty(this, '$$conf', {
value: this.$$conf
});
this.$id = ref.ref.key;
this.$priority = null;
$firebaseUtils.applyDefaults(this, this.$$defaults);
// start synchronizing data with Firebase
this.$$conf.sync.init();
// $resolved provides quick access to the current state of the $loaded() promise.
// This is useful in data-binding when needing to delay the rendering or visibilty
// of the data until is has been loaded from firebase.
this.$resolved = false;
this.$loaded().finally(function() {
self.$resolved = true;
});
} | javascript | function FirebaseObject(ref) {
if( !(this instanceof FirebaseObject) ) {
return new FirebaseObject(ref);
}
var self = this;
// These are private config props and functions used internally
// they are collected here to reduce clutter in console.log and forEach
this.$$conf = {
// synchronizes data to Firebase
sync: new ObjectSyncManager(this, ref),
// stores the Firebase ref
ref: ref,
// synchronizes $scope variables with this object
binding: new ThreeWayBinding(this),
// stores observers registered with $watch
listeners: []
};
// this bit of magic makes $$conf non-enumerable and non-configurable
// and non-writable (its properties are still writable but the ref cannot be replaced)
// we redundantly assign it above so the IDE can relax
Object.defineProperty(this, '$$conf', {
value: this.$$conf
});
this.$id = ref.ref.key;
this.$priority = null;
$firebaseUtils.applyDefaults(this, this.$$defaults);
// start synchronizing data with Firebase
this.$$conf.sync.init();
// $resolved provides quick access to the current state of the $loaded() promise.
// This is useful in data-binding when needing to delay the rendering or visibilty
// of the data until is has been loaded from firebase.
this.$resolved = false;
this.$loaded().finally(function() {
self.$resolved = true;
});
} | [
"function",
"FirebaseObject",
"(",
"ref",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"FirebaseObject",
")",
")",
"{",
"return",
"new",
"FirebaseObject",
"(",
"ref",
")",
";",
"}",
"var",
"self",
"=",
"this",
";",
"// These are private config props and functions used internally",
"// they are collected here to reduce clutter in console.log and forEach",
"this",
".",
"$$conf",
"=",
"{",
"// synchronizes data to Firebase",
"sync",
":",
"new",
"ObjectSyncManager",
"(",
"this",
",",
"ref",
")",
",",
"// stores the Firebase ref",
"ref",
":",
"ref",
",",
"// synchronizes $scope variables with this object",
"binding",
":",
"new",
"ThreeWayBinding",
"(",
"this",
")",
",",
"// stores observers registered with $watch",
"listeners",
":",
"[",
"]",
"}",
";",
"// this bit of magic makes $$conf non-enumerable and non-configurable",
"// and non-writable (its properties are still writable but the ref cannot be replaced)",
"// we redundantly assign it above so the IDE can relax",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"'$$conf'",
",",
"{",
"value",
":",
"this",
".",
"$$conf",
"}",
")",
";",
"this",
".",
"$id",
"=",
"ref",
".",
"ref",
".",
"key",
";",
"this",
".",
"$priority",
"=",
"null",
";",
"$firebaseUtils",
".",
"applyDefaults",
"(",
"this",
",",
"this",
".",
"$$defaults",
")",
";",
"// start synchronizing data with Firebase",
"this",
".",
"$$conf",
".",
"sync",
".",
"init",
"(",
")",
";",
"// $resolved provides quick access to the current state of the $loaded() promise.",
"// This is useful in data-binding when needing to delay the rendering or visibilty",
"// of the data until is has been loaded from firebase.",
"this",
".",
"$resolved",
"=",
"false",
";",
"this",
".",
"$loaded",
"(",
")",
".",
"finally",
"(",
"function",
"(",
")",
"{",
"self",
".",
"$resolved",
"=",
"true",
";",
"}",
")",
";",
"}"
] | Creates a synchronized object with 2-way bindings between Angular and Firebase.
@param {Firebase} ref
@returns {FirebaseObject}
@constructor | [
"Creates",
"a",
"synchronized",
"object",
"with",
"2",
"-",
"way",
"bindings",
"between",
"Angular",
"and",
"Firebase",
"."
] | b6dca6ea5a81b3edd44230fb1cb6ca62419f1926 | https://github.com/firebase/angularfire/blob/b6dca6ea5a81b3edd44230fb1cb6ca62419f1926/src/database/FirebaseObject.js#L35-L75 |
7,895 | firebase/angularfire | src/database/FirebaseObject.js | function () {
var self = this;
var ref = self.$ref();
var def = $q.defer();
var dataJSON;
try {
dataJSON = $firebaseUtils.toJSON(self);
} catch (e) {
def.reject(e);
}
if (typeof dataJSON !== 'undefined') {
$firebaseUtils.doSet(ref, dataJSON).then(function() {
self.$$notify();
def.resolve(self.$ref());
}).catch(def.reject);
}
return def.promise;
} | javascript | function () {
var self = this;
var ref = self.$ref();
var def = $q.defer();
var dataJSON;
try {
dataJSON = $firebaseUtils.toJSON(self);
} catch (e) {
def.reject(e);
}
if (typeof dataJSON !== 'undefined') {
$firebaseUtils.doSet(ref, dataJSON).then(function() {
self.$$notify();
def.resolve(self.$ref());
}).catch(def.reject);
}
return def.promise;
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"ref",
"=",
"self",
".",
"$ref",
"(",
")",
";",
"var",
"def",
"=",
"$q",
".",
"defer",
"(",
")",
";",
"var",
"dataJSON",
";",
"try",
"{",
"dataJSON",
"=",
"$firebaseUtils",
".",
"toJSON",
"(",
"self",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"def",
".",
"reject",
"(",
"e",
")",
";",
"}",
"if",
"(",
"typeof",
"dataJSON",
"!==",
"'undefined'",
")",
"{",
"$firebaseUtils",
".",
"doSet",
"(",
"ref",
",",
"dataJSON",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"self",
".",
"$$notify",
"(",
")",
";",
"def",
".",
"resolve",
"(",
"self",
".",
"$ref",
"(",
")",
")",
";",
"}",
")",
".",
"catch",
"(",
"def",
".",
"reject",
")",
";",
"}",
"return",
"def",
".",
"promise",
";",
"}"
] | Saves all data on the FirebaseObject back to Firebase.
@returns a promise which will resolve after the save is completed. | [
"Saves",
"all",
"data",
"on",
"the",
"FirebaseObject",
"back",
"to",
"Firebase",
"."
] | b6dca6ea5a81b3edd44230fb1cb6ca62419f1926 | https://github.com/firebase/angularfire/blob/b6dca6ea5a81b3edd44230fb1cb6ca62419f1926/src/database/FirebaseObject.js#L82-L102 |
|
7,896 | firebase/angularfire | src/database/FirebaseObject.js | function() {
var self = this;
$firebaseUtils.trimKeys(self, {});
self.$value = null;
return $firebaseUtils.doRemove(self.$ref()).then(function() {
self.$$notify();
return self.$ref();
});
} | javascript | function() {
var self = this;
$firebaseUtils.trimKeys(self, {});
self.$value = null;
return $firebaseUtils.doRemove(self.$ref()).then(function() {
self.$$notify();
return self.$ref();
});
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"$firebaseUtils",
".",
"trimKeys",
"(",
"self",
",",
"{",
"}",
")",
";",
"self",
".",
"$value",
"=",
"null",
";",
"return",
"$firebaseUtils",
".",
"doRemove",
"(",
"self",
".",
"$ref",
"(",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"self",
".",
"$$notify",
"(",
")",
";",
"return",
"self",
".",
"$ref",
"(",
")",
";",
"}",
")",
";",
"}"
] | Removes all keys from the FirebaseObject and also removes
the remote data from the server.
@returns a promise which will resolve after the op completes | [
"Removes",
"all",
"keys",
"from",
"the",
"FirebaseObject",
"and",
"also",
"removes",
"the",
"remote",
"data",
"from",
"the",
"server",
"."
] | b6dca6ea5a81b3edd44230fb1cb6ca62419f1926 | https://github.com/firebase/angularfire/blob/b6dca6ea5a81b3edd44230fb1cb6ca62419f1926/src/database/FirebaseObject.js#L110-L118 |
|
7,897 | firebase/angularfire | src/database/FirebaseObject.js | function (scope, varName) {
var self = this;
return self.$loaded().then(function () {
return self.$$conf.binding.bindTo(scope, varName);
});
} | javascript | function (scope, varName) {
var self = this;
return self.$loaded().then(function () {
return self.$$conf.binding.bindTo(scope, varName);
});
} | [
"function",
"(",
"scope",
",",
"varName",
")",
"{",
"var",
"self",
"=",
"this",
";",
"return",
"self",
".",
"$loaded",
"(",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"self",
".",
"$$conf",
".",
"binding",
".",
"bindTo",
"(",
"scope",
",",
"varName",
")",
";",
"}",
")",
";",
"}"
] | Creates a 3-way data sync between this object, the Firebase server, and a
scope variable. This means that any changes made to the scope variable are
pushed to Firebase, and vice versa.
If scope emits a $destroy event, the binding is automatically severed. Otherwise,
it is possible to unbind the scope variable by using the `unbind` function
passed into the resolve method.
Can only be bound to one scope variable at a time. If a second is attempted,
the promise will be rejected with an error.
@param {object} scope
@param {string} varName
@returns a promise which resolves to an unbind method after data is set in scope | [
"Creates",
"a",
"3",
"-",
"way",
"data",
"sync",
"between",
"this",
"object",
"the",
"Firebase",
"server",
"and",
"a",
"scope",
"variable",
".",
"This",
"means",
"that",
"any",
"changes",
"made",
"to",
"the",
"scope",
"variable",
"are",
"pushed",
"to",
"Firebase",
"and",
"vice",
"versa",
"."
] | b6dca6ea5a81b3edd44230fb1cb6ca62419f1926 | https://github.com/firebase/angularfire/blob/b6dca6ea5a81b3edd44230fb1cb6ca62419f1926/src/database/FirebaseObject.js#L165-L170 |
|
7,898 | firebase/angularfire | src/auth/FirebaseAuth.js | function (stringOrProvider) {
var provider;
if (typeof stringOrProvider == "string") {
var providerID = stringOrProvider.slice(0, 1).toUpperCase() + stringOrProvider.slice(1);
provider = new firebase.auth[providerID+"AuthProvider"]();
} else {
provider = stringOrProvider;
}
return provider;
} | javascript | function (stringOrProvider) {
var provider;
if (typeof stringOrProvider == "string") {
var providerID = stringOrProvider.slice(0, 1).toUpperCase() + stringOrProvider.slice(1);
provider = new firebase.auth[providerID+"AuthProvider"]();
} else {
provider = stringOrProvider;
}
return provider;
} | [
"function",
"(",
"stringOrProvider",
")",
"{",
"var",
"provider",
";",
"if",
"(",
"typeof",
"stringOrProvider",
"==",
"\"string\"",
")",
"{",
"var",
"providerID",
"=",
"stringOrProvider",
".",
"slice",
"(",
"0",
",",
"1",
")",
".",
"toUpperCase",
"(",
")",
"+",
"stringOrProvider",
".",
"slice",
"(",
"1",
")",
";",
"provider",
"=",
"new",
"firebase",
".",
"auth",
"[",
"providerID",
"+",
"\"AuthProvider\"",
"]",
"(",
")",
";",
"}",
"else",
"{",
"provider",
"=",
"stringOrProvider",
";",
"}",
"return",
"provider",
";",
"}"
] | Helper method to turn provider names into AuthProvider instances
@param {object} stringOrProvider Provider ID string to AuthProvider instance
@return {firebdase.auth.AuthProvider} A valid AuthProvider instance | [
"Helper",
"method",
"to",
"turn",
"provider",
"names",
"into",
"AuthProvider",
"instances"
] | b6dca6ea5a81b3edd44230fb1cb6ca62419f1926 | https://github.com/firebase/angularfire/blob/b6dca6ea5a81b3edd44230fb1cb6ca62419f1926/src/auth/FirebaseAuth.js#L221-L230 |
|
7,899 | firebase/angularfire | src/auth/FirebaseAuth.js | function() {
var auth = this._auth;
return this._q(function(resolve) {
var off;
function callback() {
// Turn off this onAuthStateChanged() callback since we just needed to get the authentication data once.
off();
resolve();
}
off = auth.onAuthStateChanged(callback);
});
} | javascript | function() {
var auth = this._auth;
return this._q(function(resolve) {
var off;
function callback() {
// Turn off this onAuthStateChanged() callback since we just needed to get the authentication data once.
off();
resolve();
}
off = auth.onAuthStateChanged(callback);
});
} | [
"function",
"(",
")",
"{",
"var",
"auth",
"=",
"this",
".",
"_auth",
";",
"return",
"this",
".",
"_q",
"(",
"function",
"(",
"resolve",
")",
"{",
"var",
"off",
";",
"function",
"callback",
"(",
")",
"{",
"// Turn off this onAuthStateChanged() callback since we just needed to get the authentication data once.",
"off",
"(",
")",
";",
"resolve",
"(",
")",
";",
"}",
"off",
"=",
"auth",
".",
"onAuthStateChanged",
"(",
"callback",
")",
";",
"}",
")",
";",
"}"
] | Helper that returns a promise which resolves when the initial auth state has been
fetched from the Firebase server. This never rejects and resolves to undefined.
@return {Promise<Object>} A promise fulfilled when the server returns initial auth state. | [
"Helper",
"that",
"returns",
"a",
"promise",
"which",
"resolves",
"when",
"the",
"initial",
"auth",
"state",
"has",
"been",
"fetched",
"from",
"the",
"Firebase",
"server",
".",
"This",
"never",
"rejects",
"and",
"resolves",
"to",
"undefined",
"."
] | b6dca6ea5a81b3edd44230fb1cb6ca62419f1926 | https://github.com/firebase/angularfire/blob/b6dca6ea5a81b3edd44230fb1cb6ca62419f1926/src/auth/FirebaseAuth.js#L238-L250 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.