_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q21800
train
function (idx, out) { if (idx < this.triangleCount && idx >= 0) { if (!out) { out = []; } var indices = this.indices; out[0] = indices[idx * 3]; out[1] = indices[idx * 3 + 1]; out[2] = indices[idx * 3 + 2]; return out; } }
javascript
{ "resource": "" }
q21801
train
function (idx, arr) { var indices = this.indices; indices[idx * 3] = arr[0]; indices[idx * 3 + 1] = arr[1]; indices[idx * 3 + 2] = arr[2]; }
javascript
{ "resource": "" }
q21802
train
function (array) { var value; var ArrayConstructor = this.vertexCount > 0xffff ? vendor.Uint32Array : vendor.Uint16Array; // Convert 2d array to flat if (array[0] && (array[0].length)) { var n = 0; var size = 3; value = new ArrayConstructor(array.length * size); for (var i = 0; i < array.length; i++) { for (var j = 0; j < size; j++) { value[n++] = array[i][j]; } } } else { value = new ArrayConstructor(array); } this.indices = value; }
javascript
{ "resource": "" }
q21803
train
function () { var enabledAttributes = this._enabledAttributes; var attributeList = this._attributeList; // Cache if (enabledAttributes) { return enabledAttributes; } var result = []; var nVertex = this.vertexCount; for (var i = 0; i < attributeList.length; i++) { var name = attributeList[i]; var attrib = this.attributes[name]; if (attrib.value) { if (attrib.value.length === nVertex * attrib.size) { result.push(name); } } } this._enabledAttributes = result; return result; }
javascript
{ "resource": "" }
q21804
train
function (renderer) { var cache = this._cache; cache.use(renderer.__uid__); var chunks = cache.get('chunks'); if (chunks) { for (var c = 0; c < chunks.length; c++) { var chunk = chunks[c]; for (var k = 0; k < chunk.attributeBuffers.length; k++) { var attribs = chunk.attributeBuffers[k]; renderer.gl.deleteBuffer(attribs.buffer); } if (chunk.indicesBuffer) { renderer.gl.deleteBuffer(chunk.indicesBuffer.buffer); } } } if (this.__vaoCache) { var vaoExt = renderer.getGLExtension('OES_vertex_array_object'); for (var id in this.__vaoCache) { var vao = this.__vaoCache[id].vao; if (vao) { vaoExt.deleteVertexArrayOES(vao); } } } this.__vaoCache = {}; cache.deleteContext(renderer.__uid__); }
javascript
{ "resource": "" }
q21805
train
function (globalEasing) { var self = this; var clipCount = 0; var oneTrackDone = function() { clipCount--; if (clipCount === 0) { self._doneCallback(); } }; var lastClip; for (var propName in this._tracks) { var clip = createTrackClip( this, globalEasing, oneTrackDone, this._tracks[propName], propName, self._interpolater, self._maxTime ); if (clip) { this._clipList.push(clip); clipCount++; // If start after added to animation if (this.animation) { this.animation.addClip(clip); } lastClip = clip; } } // Add during callback on the last clip if (lastClip) { var oldOnFrame = lastClip.onframe; lastClip.onframe = function (target, percent) { oldOnFrame(target, percent); for (var i = 0; i < self._onframeList.length; i++) { self._onframeList[i](target, percent); } }; } if (!clipCount) { this._doneCallback(); } return this; }
javascript
{ "resource": "" }
q21806
train
function () { for (var i = 0; i < this._clipList.length; i++) { var clip = this._clipList[i]; this.animation.removeClip(clip); } this._clipList = []; }
javascript
{ "resource": "" }
q21807
vec3lerp
train
function vec3lerp(out, a, b, t, oa, ob) { var ax = a[oa]; var ay = a[oa + 1]; var az = a[oa + 2]; out[0] = ax + t * (b[ob] - ax); out[1] = ay + t * (b[ob + 1] - ay); out[2] = az + t * (b[ob + 2] - az); return out; }
javascript
{ "resource": "" }
q21808
train
function (opts) { opts = opts || {}; this.name = opts.name || ''; /** * @param {clay.Node} */ this.target = opts.target || null; /** * @type {Array} */ this.position = vec3.create(); /** * Rotation is represented by a quaternion * @type {Array} */ this.rotation = quat.create(); /** * @type {Array} */ this.scale = vec3.fromValues(1, 1, 1); this.channels = { time: null, position: null, rotation: null, scale: null }; this._cacheKey = 0; this._cacheTime = 0; }
javascript
{ "resource": "" }
q21809
derive
train
function derive(makeDefaultOpt, initialize/*optional*/, proto/*optional*/) { if (typeof initialize == 'object') { proto = initialize; initialize = null; } var _super = this; var propList; if (!(makeDefaultOpt instanceof Function)) { // Optimize the property iterate if it have been fixed propList = []; for (var propName in makeDefaultOpt) { if (makeDefaultOpt.hasOwnProperty(propName)) { propList.push(propName); } } } var sub = function(options) { // call super constructor _super.apply(this, arguments); if (makeDefaultOpt instanceof Function) { // Invoke makeDefaultOpt each time if it is a function, So we can make sure each // property in the object will not be shared by mutiple instances extend(this, makeDefaultOpt.call(this, options)); } else { extendWithPropList(this, makeDefaultOpt, propList); } if (this.constructor === sub) { // Initialize function will be called in the order of inherit var initializers = sub.__initializers__; for (var i = 0; i < initializers.length; i++) { initializers[i].apply(this, arguments); } } }; // save super constructor sub.__super__ = _super; // Initialize function will be called after all the super constructor is called if (!_super.__initializers__) { sub.__initializers__ = []; } else { sub.__initializers__ = _super.__initializers__.slice(); } if (initialize) { sub.__initializers__.push(initialize); } var Ctor = function() {}; Ctor.prototype = _super.prototype; sub.prototype = new Ctor(); sub.prototype.constructor = sub; extend(sub.prototype, proto); // extend the derive method as a static method; sub.extend = _super.extend; // DEPCRATED sub.derive = _super.extend; return sub; }
javascript
{ "resource": "" }
q21810
train
function(name, action, context) { if (!name || !action) { return; } var handlers = this.__handlers__ || (this.__handlers__={}); if (!handlers[name]) { handlers[name] = []; } else { if (this.has(name, action)) { return; } } var handler = new Handler(action, context || this); handlers[name].push(handler); return this; }
javascript
{ "resource": "" }
q21811
train
function(name, action, context) { if (!name || !action) { return; } var self = this; function wrapper() { self.off(name, wrapper); action.apply(this, arguments); } return this.on(name, wrapper, context); }
javascript
{ "resource": "" }
q21812
train
function(name, action) { var handlers = this.__handlers__; if (! handlers || ! handlers[name]) { return false; } var hdls = handlers[name]; for (var i = 0; i < hdls.length; i++) { if (hdls[i].action === action) { return true; } } }
javascript
{ "resource": "" }
q21813
train
function (path, basePath) { if (!basePath || path.match(/^\//)) { return path; } var pathParts = path.split('/'); var basePathParts = basePath.split('/'); var item = pathParts[0]; while(item === '.' || item === '..') { if (item === '..') { basePathParts.pop(); } pathParts.shift(); item = pathParts[0]; } return basePathParts.join('/') + '/' + pathParts.join('/'); }
javascript
{ "resource": "" }
q21814
train
function (target, source) { if (source) { for (var propName in source) { if (target[propName] === undefined) { target[propName] = source[propName]; } } } return target; }
javascript
{ "resource": "" }
q21815
train
function () { var self = this; this._running = true; this._time = Date.now(); this._pausedTime = 0; var requestAnimationFrame = vendor.requestAnimationFrame; function step() { if (self._running) { requestAnimationFrame(step); if (!self._paused) { self._update(); } } } requestAnimationFrame(step); }
javascript
{ "resource": "" }
q21816
train
function (target, options) { options = options || {}; var animator = new Animator( target, options.loop, options.getter, options.setter, options.interpolater ); animator.animation = this; return animator; }
javascript
{ "resource": "" }
q21817
train
function (symbol, value) { if (value === undefined) { console.warn('Uniform value "' + symbol + '" is undefined'); } var uniform = this.uniforms[symbol]; if (uniform) { if (typeof value === 'string') { // Try to parse as a color. Invalid color string will return null. value = parseColor$1(value) || value; } uniform.value = value; if (this.autoUpdateTextureStatus && uniform.type === 't') { if (value) { this.enableTexture(symbol); } else { this.disableTexture(symbol); } } } }
javascript
{ "resource": "" }
q21818
train
function (symbol, value) { if (typeof(symbol) === 'object') { for (var key in symbol) { var val = symbol[key]; this.setUniform(key, val); } } else { this.setUniform(symbol, value); } }
javascript
{ "resource": "" }
q21819
train
function(shader, keepStatus) { var originalUniforms = this.uniforms; // Ignore if uniform can use in shader. this.uniforms = shader.createUniforms(); this.shader = shader; var uniforms = this.uniforms; this._enabledUniforms = Object.keys(uniforms); // Make sure uniforms are set in same order to avoid texture slot wrong this._enabledUniforms.sort(); this._textureUniforms = this._enabledUniforms.filter(function (uniformName) { var type = this.uniforms[uniformName].type; return type === 't' || type === 'tv'; }, this); var originalVertexDefines = this.vertexDefines; var originalFragmentDefines = this.fragmentDefines; this.vertexDefines = util$1.clone(shader.vertexDefines); this.fragmentDefines = util$1.clone(shader.fragmentDefines); if (keepStatus) { for (var symbol in originalUniforms) { if (uniforms[symbol]) { uniforms[symbol].value = originalUniforms[symbol].value; } } util$1.defaults(this.vertexDefines, originalVertexDefines); util$1.defaults(this.fragmentDefines, originalFragmentDefines); } var textureStatus = {}; for (var key in shader.textures) { textureStatus[key] = { shaderType: shader.textures[key].shaderType, type: shader.textures[key].type, enabled: (keepStatus && this._textureStatus[key]) ? this._textureStatus[key].enabled : false }; } this._textureStatus = textureStatus; this._programKey = ''; }
javascript
{ "resource": "" }
q21820
train
function () { var material = new this.constructor({ name: this.name, shader: this.shader }); for (var symbol in this.uniforms) { material.uniforms[symbol].value = this.uniforms[symbol].value; } material.depthTest = this.depthTest; material.depthMask = this.depthMask; material.transparent = this.transparent; material.blend = this.blend; material.vertexDefines = util$1.clone(this.vertexDefines); material.fragmentDefines = util$1.clone(this.fragmentDefines); material.enableTexture(this.getEnabledTextures()); material.precision = this.precision; return material; }
javascript
{ "resource": "" }
q21821
train
function () { var enabledTextures = []; var textureStatus = this._textureStatus; for (var symbol in textureStatus) { if (textureStatus[symbol].enabled) { enabledTextures.push(symbol); } } return enabledTextures; }
javascript
{ "resource": "" }
q21822
checkShaderErrorMsg
train
function checkShaderErrorMsg(_gl, shader, shaderString) { if (!_gl.getShaderParameter(shader, _gl.COMPILE_STATUS)) { return [_gl.getShaderInfoLog(shader), addLineNumbers(shaderString)].join('\n'); } }
javascript
{ "resource": "" }
q21823
train
function () { var uniforms = {}; for (var symbol in this.uniformTemplates){ var uniformTpl = this.uniformTemplates[symbol]; uniforms[symbol] = { type: uniformTpl.type, value: uniformTpl.value() }; } return uniforms; }
javascript
{ "resource": "" }
q21824
train
function () { var code = shaderCodeCache[this._shaderID]; var shader = new Shader(code.vertex, code.fragment); return shader; }
javascript
{ "resource": "" }
q21825
train
function () { if (this._clearStack.length > 0) { var opt = this._clearStack.pop(); this.clearColor = opt.clearColor; this.clearBit = opt.clearBit; } }
javascript
{ "resource": "" }
q21826
train
function(root, disposeGeometry, disposeTexture) { // Dettached from parent if (root.getParent()) { root.getParent().remove(root); } var disposedMap = {}; root.traverse(function(node) { var material = node.material; if (node.geometry && disposeGeometry) { node.geometry.dispose(this); } if (disposeTexture && material && !disposedMap[material.__uid__]) { var textureUniforms = material.getTextureUniforms(); for (var u = 0; u < textureUniforms.length; u++) { var uniformName = textureUniforms[u]; var val = material.uniforms[uniformName].value; var uniformType = material.uniforms[uniformName].type; if (!val) { continue; } if (uniformType === 't') { val.dispose && val.dispose(this); } else if (uniformType === 'tv') { for (var k = 0; k < val.length; k++) { if (val[k]) { val[k].dispose && val[k].dispose(this); } } } } disposedMap[material.__uid__] = true; } // Particle system and AmbientCubemap light need to dispose if (node.dispose) { node.dispose(this); } }, this); }
javascript
{ "resource": "" }
q21827
train
function (m) { var v = this.array; m = m.array; // Perspective projection if (m[15] === 0) { var w = -1 / v[2]; v[0] = m[0] * v[0] * w; v[1] = m[5] * v[1] * w; v[2] = (m[10] * v[2] + m[14]) * w; } else { v[0] = m[0] * v[0] + m[12]; v[1] = m[5] * v[1] + m[13]; v[2] = m[10] * v[2] + m[14]; } this._dirty = true; return this; }
javascript
{ "resource": "" }
q21828
train
function (x, y, z, w) { this.array[0] = x; this.array[1] = y; this.array[2] = z; this.array[3] = w; this._dirty = true; return this; }
javascript
{ "resource": "" }
q21829
train
function (arr) { this.array[0] = arr[0]; this.array[1] = arr[1]; this.array[2] = arr[2]; this.array[3] = arr[3]; this._dirty = true; return this; }
javascript
{ "resource": "" }
q21830
train
function (view, right, up) { quat.setAxes(this.array, view.array, right.array, up.array); this._dirty = true; return this; }
javascript
{ "resource": "" }
q21831
train
function (arr) { for (var i = 0; i < this.array.length; i++) { this.array[i] = arr[i]; } this._dirty = true; return this; }
javascript
{ "resource": "" }
q21832
train
function(q, v) { mat4.fromRotationTranslation(this.array, q.array, v.array); this._dirty = true; return this; }
javascript
{ "resource": "" }
q21833
train
function(rad, axis) { mat4.rotate(this.array, this.array, rad, axis.array); this._dirty = true; return this; }
javascript
{ "resource": "" }
q21834
train
function (min, max) { /** * Minimum coords of bounding box * @type {clay.Vector3} */ this.min = min || new Vector3(Infinity, Infinity, Infinity); /** * Maximum coords of bounding box * @type {clay.Vector3} */ this.max = max || new Vector3(-Infinity, -Infinity, -Infinity); this.vertices = null; }
javascript
{ "resource": "" }
q21835
train
function (vertices) { if (vertices.length > 0) { var min = this.min; var max = this.max; var minArr = min.array; var maxArr = max.array; vec3Copy(minArr, vertices[0]); vec3Copy(maxArr, vertices[0]); for (var i = 1; i < vertices.length; i++) { var vertex = vertices[i]; if (vertex[0] < minArr[0]) { minArr[0] = vertex[0]; } if (vertex[1] < minArr[1]) { minArr[1] = vertex[1]; } if (vertex[2] < minArr[2]) { minArr[2] = vertex[2]; } if (vertex[0] > maxArr[0]) { maxArr[0] = vertex[0]; } if (vertex[1] > maxArr[1]) { maxArr[1] = vertex[1]; } if (vertex[2] > maxArr[2]) { maxArr[2] = vertex[2]; } } min._dirty = true; max._dirty = true; } }
javascript
{ "resource": "" }
q21836
train
function (bbox) { var min = this.min; var max = this.max; vec3.min(min.array, min.array, bbox.min.array); vec3.max(max.array, max.array, bbox.max.array); min._dirty = true; max._dirty = true; return this; }
javascript
{ "resource": "" }
q21837
train
function (bbox) { var _min = this.min.array; var _max = this.max.array; var _min2 = bbox.min.array; var _max2 = bbox.max.array; return ! (_min[0] > _max2[0] || _min[1] > _max2[1] || _min[2] > _max2[2] || _max[0] < _min2[0] || _max[1] < _min2[1] || _max[2] < _min2[2]); }
javascript
{ "resource": "" }
q21838
train
function (p) { var _min = this.min.array; var _max = this.max.array; var _p = p.array; return _min[0] <= _p[0] && _min[1] <= _p[1] && _min[2] <= _p[2] && _max[0] >= _p[0] && _max[1] >= _p[1] && _max[2] >= _p[2]; }
javascript
{ "resource": "" }
q21839
train
function () { var _min = this.min.array; var _max = this.max.array; return isFinite(_min[0]) && isFinite(_min[1]) && isFinite(_min[2]) && isFinite(_max[0]) && isFinite(_max[1]) && isFinite(_max[2]); }
javascript
{ "resource": "" }
q21840
train
function (matrix) { var min = this.min.array; var max = this.max.array; var m = matrix.array; // min in min z var v10 = min[0]; var v11 = min[1]; var v12 = min[2]; // max in min z var v20 = max[0]; var v21 = max[1]; var v22 = min[2]; // max in max z var v30 = max[0]; var v31 = max[1]; var v32 = max[2]; if (m[15] === 1) { // Orthographic projection min[0] = m[0] * v10 + m[12]; min[1] = m[5] * v11 + m[13]; max[2] = m[10] * v12 + m[14]; max[0] = m[0] * v30 + m[12]; max[1] = m[5] * v31 + m[13]; min[2] = m[10] * v32 + m[14]; } else { var w = -1 / v12; min[0] = m[0] * v10 * w; min[1] = m[5] * v11 * w; max[2] = (m[10] * v12 + m[14]) * w; w = -1 / v22; max[0] = m[0] * v20 * w; max[1] = m[5] * v21 * w; w = -1 / v32; min[2] = (m[10] * v32 + m[14]) * w; } this.min._dirty = true; this.max._dirty = true; return this; }
javascript
{ "resource": "" }
q21841
train
function (bbox) { var min = this.min; var max = this.max; vec3Copy(min.array, bbox.min.array); vec3Copy(max.array, bbox.max.array); min._dirty = true; max._dirty = true; return this; }
javascript
{ "resource": "" }
q21842
train
function (name) { var scene = this._scene; if (scene) { var nodeRepository = scene._nodeRepository; delete nodeRepository[this.name]; nodeRepository[name] = this; } this.name = name; }
javascript
{ "resource": "" }
q21843
train
function (node) { var originalParent = node._parent; if (originalParent === this) { return; } if (originalParent) { originalParent.remove(node); } node._parent = this; this._children.push(node); var scene = this._scene; if (scene && scene !== node.scene) { node.traverse(this._addSelfToScene, this); } // Mark children needs update transform // In case child are remove and added again after parent moved node._needsUpdateWorldTransform = true; }
javascript
{ "resource": "" }
q21844
train
function (node) { var children = this._children; var idx = children.indexOf(node); if (idx < 0) { return; } children.splice(idx, 1); node._parent = null; if (this._scene) { node.traverse(this._removeSelfFromScene, this); } }
javascript
{ "resource": "" }
q21845
train
function () { var children = this._children; for (var idx = 0; idx < children.length; idx++) { children[idx]._parent = null; if (this._scene) { children[idx].traverse(this._removeSelfFromScene, this); } } this._children = []; }
javascript
{ "resource": "" }
q21846
train
function (node) { var parent = node._parent; while(parent) { if (parent === this) { return true; } parent = parent._parent; } return false; }
javascript
{ "resource": "" }
q21847
train
function (name) { var children = this._children; for (var i = 0; i < children.length; i++) { if (children[i].name === name) { return children[i]; } } }
javascript
{ "resource": "" }
q21848
train
function (name) { var children = this._children; for (var i = 0; i < children.length; i++) { var child = children[i]; if (child.name === name) { return child; } else { var res = child.getDescendantByName(name); if (res) { return res; } } } }
javascript
{ "resource": "" }
q21849
train
function (path) { if (!path) { return; } // TODO Name have slash ? var pathArr = path.split('/'); var current = this; for (var i = 0; i < pathArr.length; i++) { var name = pathArr[i]; // Skip empty if (!name) { continue; } var found = false; var children = current._children; for (var j = 0; j < children.length; j++) { var child = children[j]; if (child.name === name) { current = child; found = true; break; } } // Early return if not found if (!found) { return; } } return current; }
javascript
{ "resource": "" }
q21850
train
function (callback, context) { callback.call(context, this); var _children = this._children; for(var i = 0, len = _children.length; i < len; i++) { _children[i].traverse(callback, context); } }
javascript
{ "resource": "" }
q21851
train
function (callback, context) { var _children = this._children; for(var i = 0, len = _children.length; i < len; i++) { var child = _children[i]; callback.call(context, child, i); } }
javascript
{ "resource": "" }
q21852
train
function (keepScale) { var scale = !keepScale ? this.scale: null; this.localTransform.decomposeMatrix(scale, this.rotation, this.position); }
javascript
{ "resource": "" }
q21853
train
function () { var position = this.position; var rotation = this.rotation; var scale = this.scale; if (this.transformNeedsUpdate()) { var m = this.localTransform.array; // Transform order, scale->rotation->position mat4.fromRotationTranslation(m, rotation.array, position.array); mat4.scale(m, m, scale.array); rotation._dirty = false; scale._dirty = false; position._dirty = false; this._needsUpdateWorldTransform = true; } }
javascript
{ "resource": "" }
q21854
train
function () { var localTransform = this.localTransform.array; var worldTransform = this.worldTransform.array; if (this._parent) { mat4.multiplyAffine( worldTransform, this._parent.worldTransform.array, localTransform ); } else { mat4.copy(worldTransform, localTransform); } }
javascript
{ "resource": "" }
q21855
train
function () { // Find the root node which transform needs update; var rootNodeIsDirty = this; while (rootNodeIsDirty && rootNodeIsDirty.getParent() && rootNodeIsDirty.getParent().transformNeedsUpdate() ) { rootNodeIsDirty = rootNodeIsDirty.getParent(); } rootNodeIsDirty.update(); }
javascript
{ "resource": "" }
q21856
train
function (forceUpdateWorld) { if (this.autoUpdateLocalTransform) { this.updateLocalTransform(); } else { // Transform is manually setted forceUpdateWorld = true; } if (forceUpdateWorld || this._needsUpdateWorldTransform) { this._updateWorldTransformTopDown(); forceUpdateWorld = true; this._needsUpdateWorldTransform = false; } var children = this._children; for(var i = 0, len = children.length; i < len; i++) { children[i].update(forceUpdateWorld); } }
javascript
{ "resource": "" }
q21857
train
function (out) { // PENDING if (this.transformNeedsUpdate()) { this.updateWorldTransform(); } var m = this.worldTransform.array; if (out) { var arr = out.array; arr[0] = m[12]; arr[1] = m[13]; arr[2] = m[14]; return out; } else { return new Vector3(m[12], m[13], m[14]); } }
javascript
{ "resource": "" }
q21858
train
function () { var node = new this.constructor(); var children = this._children; node.setName(this.name); node.position.copy(this.position); node.rotation.copy(this.rotation); node.scale.copy(this.scale); for (var i = 0; i < children.length; i++) { node.add(children[i].clone()); } return node; }
javascript
{ "resource": "" }
q21859
train
function(point, out) { if (!out) { out = new Vector3(); } var d = this.distanceToPoint(point); vec3.scaleAndAdd(out.array, point.array, this.normal.array, -d); out._dirty = true; return out; }
javascript
{ "resource": "" }
q21860
train
function() { var invLen = 1 / vec3.len(this.normal.array); vec3.scale(this.normal.array, invLen); this.distance *= invLen; }
javascript
{ "resource": "" }
q21861
train
function(frustum) { // Check if all coords of frustum is on plane all under plane var coords = frustum.vertices; var normal = this.normal.array; var onPlane = vec3.dot(coords[0].array, normal) > this.distance; for (var i = 1; i < 8; i++) { if ((vec3.dot(coords[i].array, normal) > this.distance) != onPlane) { return true; } } }
javascript
{ "resource": "" }
q21862
train
function(plane) { vec3.copy(this.normal.array, plane.normal.array); this.normal._dirty = true; this.distance = plane.distance; }
javascript
{ "resource": "" }
q21863
train
function (plane) { // Distance to plane var d = vec3.dot(plane.normal.array, this.direction.array); vec3.scaleAndAdd(this.direction.array, this.direction.array, plane.normal.array, -d * 2); this.direction._dirty = true; }
javascript
{ "resource": "" }
q21864
train
function (matrix) { Vector3.add(this.direction, this.direction, this.origin); Vector3.transformMat4(this.origin, this.origin, matrix); Vector3.transformMat4(this.direction, this.direction, matrix); Vector3.sub(this.direction, this.direction, this.origin); Vector3.normalize(this.direction, this.direction); }
javascript
{ "resource": "" }
q21865
train
function (ray) { Vector3.copy(this.origin, ray.origin); Vector3.copy(this.direction, ray.direction); }
javascript
{ "resource": "" }
q21866
train
function (viewMatrix) { Matrix4.copy(this.viewMatrix, viewMatrix); Matrix4.invert(this.worldTransform, viewMatrix); this.decomposeWorldTransform(); }
javascript
{ "resource": "" }
q21867
train
function (projectionMatrix) { Matrix4.copy(this.projectionMatrix, projectionMatrix); Matrix4.invert(this.invProjectionMatrix, projectionMatrix); this.decomposeProjectionMatrix(); }
javascript
{ "resource": "" }
q21868
train
function (node) { if (node instanceof Camera) { if (this._cameraList.length > 0) { console.warn('Found multiple camera in one scene. Use the fist one.'); } this._cameraList.push(node); } else if (node instanceof Light) { this.lights.push(node); } if (node.name) { this._nodeRepository[node.name] = node; } }
javascript
{ "resource": "" }
q21869
train
function (node) { var idx; if (node instanceof Camera) { idx = this._cameraList.indexOf(node); if (idx >= 0) { this._cameraList.splice(idx, 1); } } else if (node instanceof Light) { idx = this.lights.indexOf(node); if (idx >= 0) { this.lights.splice(idx, 1); } } if (node.name) { delete this._nodeRepository[node.name]; } }
javascript
{ "resource": "" }
q21870
train
function (camera) { var idx = this._cameraList.indexOf(camera); if (idx >= 0) { this._cameraList.splice(idx, 1); } this._cameraList.unshift(camera); }
javascript
{ "resource": "" }
q21871
train
function (camera, updateSceneBoundingBox) { var id = camera.__uid__; var renderList = this._renderLists.get(id); if (!renderList) { renderList = new RenderList(); this._renderLists.put(id, renderList); } renderList.startCount(); if (updateSceneBoundingBox) { this.viewBoundingBoxLastFrame.min.set(Infinity, Infinity, Infinity); this.viewBoundingBoxLastFrame.max.set(-Infinity, -Infinity, -Infinity); } var sceneMaterialTransparent = this.material && this.material.transparent || false; this._doUpdateRenderList(this, camera, sceneMaterialTransparent, renderList, updateSceneBoundingBox); renderList.endCount(); return renderList; }
javascript
{ "resource": "" }
q21872
train
function (lightGroup) { var prevLightNumber = this._previousLightNumber; var currentLightNumber = this._lightNumber; // PENDING Performance for (var type in currentLightNumber[lightGroup]) { if (!prevLightNumber[lightGroup]) { return true; } if (currentLightNumber[lightGroup][type] !== prevLightNumber[lightGroup][type]) { return true; } } for (var type in prevLightNumber[lightGroup]) { if (!currentLightNumber[lightGroup]) { return true; } if (currentLightNumber[lightGroup][type] !== prevLightNumber[lightGroup][type]) { return true; } } return false; }
javascript
{ "resource": "" }
q21873
train
function (name, type, size, semantic) { var attrib = new Attribute$1(name, type, size, semantic); if (this.attributes[name]) { this.removeAttribute(name); } this.attributes[name] = attrib; this._attributeList.push(name); return attrib; }
javascript
{ "resource": "" }
q21874
train
function () { var bbox = this.boundingBox; if (!bbox) { bbox = this.boundingBox = new BoundingBox(); } var posArr = this.attributes.position.value; if (posArr && posArr.length) { var min = bbox.min; var max = bbox.max; var minArr = min.array; var maxArr = max.array; vec3.set(minArr, posArr[0], posArr[1], posArr[2]); vec3.set(maxArr, posArr[0], posArr[1], posArr[2]); for (var i = 3; i < posArr.length;) { var x = posArr[i++]; var y = posArr[i++]; var z = posArr[i++]; if (x < minArr[0]) { minArr[0] = x; } if (y < minArr[1]) { minArr[1] = y; } if (z < minArr[2]) { minArr[2] = z; } if (x > maxArr[0]) { maxArr[0] = x; } if (y > maxArr[1]) { maxArr[1] = y; } if (z > maxArr[2]) { maxArr[2] = z; } } min._dirty = true; max._dirty = true; } }
javascript
{ "resource": "" }
q21875
train
function () { if (!this.vertexCount || !this.indices) { return; } if (this.indices.length > 0xffff) { this.indices = new vendor.Uint32Array(this.indices); } var attributes = this.attributes; var indices = this.indices; var attributeNameList = this.getEnabledAttributes(); var oldAttrValues = {}; for (var a = 0; a < attributeNameList.length; a++) { var name = attributeNameList[a]; oldAttrValues[name] = attributes[name].value; attributes[name].init(this.indices.length); } var cursor = 0; for (var i = 0; i < indices.length; i++) { var ii = indices[i]; for (var a = 0; a < attributeNameList.length; a++) { var name = attributeNameList[a]; var array = attributes[name].value; var size = attributes[name].size; for (var k = 0; k < size; k++) { array[cursor * size + k] = oldAttrValues[name][ii * size + k]; } } indices[i] = cursor; cursor++; } this.dirty(); }
javascript
{ "resource": "" }
q21876
train
function () { if (!this.vertexCount) { return; } if (!this.isUniqueVertex()) { this.generateUniqueVertex(); } var attributes = this.attributes; var array = attributes.barycentric.value; var indices = this.indices; // Already existed; if (array && array.length === indices.length * 3) { return; } array = attributes.barycentric.value = new Float32Array(indices.length * 3); for (var i = 0; i < (indices ? indices.length : this.vertexCount / 3);) { for (var j = 0; j < 3; j++) { var ii = indices ? indices[i++] : (i * 3 + j); array[ii * 3 + j] = 1; } } this.dirty(); }
javascript
{ "resource": "" }
q21877
train
function (matrix) { var attributes = this.attributes; var positions = attributes.position.value; var normals = attributes.normal.value; var tangents = attributes.tangent.value; matrix = matrix.array; // Normal Matrix var inverseTransposeMatrix = mat4.create(); mat4.invert(inverseTransposeMatrix, matrix); mat4.transpose(inverseTransposeMatrix, inverseTransposeMatrix); var vec3TransformMat4 = vec3.transformMat4; var vec3ForEach = vec3.forEach; vec3ForEach(positions, 3, 0, null, vec3TransformMat4, matrix); if (normals) { vec3ForEach(normals, 3, 0, null, vec3TransformMat4, inverseTransposeMatrix); } if (tangents) { vec3ForEach(tangents, 4, 0, null, vec3TransformMat4, inverseTransposeMatrix); } if (this.boundingBox) { this.updateBoundingBox(); } }
javascript
{ "resource": "" }
q21878
train
function() { var heightSegments = this.heightSegments; var widthSegments = this.widthSegments; var attributes = this.attributes; var positions = []; var texcoords = []; var normals = []; var faces = []; for (var y = 0; y <= heightSegments; y++) { var t = y / heightSegments; for (var x = 0; x <= widthSegments; x++) { var s = x / widthSegments; positions.push([2 * s - 1, 2 * t - 1, 0]); if (texcoords) { texcoords.push([s, t]); } if (normals) { normals.push([0, 0, 1]); } if (x < widthSegments && y < heightSegments) { var i = x + y * (widthSegments + 1); faces.push([i, i + 1, i + widthSegments + 1]); faces.push([i + widthSegments + 1, i + 1, i + widthSegments + 2]); } } } attributes.position.fromArray(positions); attributes.texcoord0.fromArray(texcoords); attributes.normal.fromArray(normals); this.initIndicesFromArray(faces); this.boundingBox = new BoundingBox(); this.boundingBox.min.set(-1, -1, 0); this.boundingBox.max.set(1, 1, 0); }
javascript
{ "resource": "" }
q21879
train
function() { var planes = { 'px': createPlane('px', this.depthSegments, this.heightSegments), 'nx': createPlane('nx', this.depthSegments, this.heightSegments), 'py': createPlane('py', this.widthSegments, this.depthSegments), 'ny': createPlane('ny', this.widthSegments, this.depthSegments), 'pz': createPlane('pz', this.widthSegments, this.heightSegments), 'nz': createPlane('nz', this.widthSegments, this.heightSegments), }; var attrList = ['position', 'texcoord0', 'normal']; var vertexNumber = 0; var faceNumber = 0; for (var pos in planes) { vertexNumber += planes[pos].vertexCount; faceNumber += planes[pos].indices.length; } for (var k = 0; k < attrList.length; k++) { this.attributes[attrList[k]].init(vertexNumber); } this.indices = new vendor.Uint16Array(faceNumber); var faceOffset = 0; var vertexOffset = 0; for (var pos in planes) { var plane = planes[pos]; for (var k = 0; k < attrList.length; k++) { var attrName = attrList[k]; var attrArray = plane.attributes[attrName].value; var attrSize = plane.attributes[attrName].size; var isNormal = attrName === 'normal'; for (var i = 0; i < attrArray.length; i++) { var value = attrArray[i]; if (this.inside && isNormal) { value = -value; } this.attributes[attrName].value[i + attrSize * vertexOffset] = value; } } var len = plane.indices.length; for (var i = 0; i < plane.indices.length; i++) { this.indices[i + faceOffset] = vertexOffset + plane.indices[this.inside ? (len - i - 1) : i]; } faceOffset += plane.indices.length; vertexOffset += plane.vertexCount; } this.boundingBox = new BoundingBox(); this.boundingBox.max.set(1, 1, 1); this.boundingBox.min.set(-1, -1, -1); }
javascript
{ "resource": "" }
q21880
train
function (renderer) { var _gl = renderer.gl; _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, this.flipY); _gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha); _gl.pixelStorei(_gl.UNPACK_ALIGNMENT, this.unpackAlignment); // Use of none-power of two texture // http://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences if (this.format === glenum.DEPTH_COMPONENT) { this.useMipmap = false; } var sRGBExt = renderer.getGLExtension('EXT_sRGB'); // Fallback if (this.format === Texture.SRGB && !sRGBExt) { this.format = Texture.RGB; } if (this.format === Texture.SRGB_ALPHA && !sRGBExt) { this.format = Texture.RGBA; } this.NPOT = !this.isPowerOfTwo(); }
javascript
{ "resource": "" }
q21881
train
function () { if (this.image.px) { return isPowerOfTwo$1(this.image.px.width) && isPowerOfTwo$1(this.image.px.height); } else { return isPowerOfTwo$1(this.width) && isPowerOfTwo$1(this.height); } }
javascript
{ "resource": "" }
q21882
train
function (clip, mapRule) { // Clip have been exists in for (var i = 0; i < this._clips.length; i++) { if (this._clips[i].clip === clip) { return; } } // Map the joint index in skeleton to joint pose index in clip var maps = []; for (var i = 0; i < this.joints.length; i++) { maps[i] = -1; } // Create avatar for (var i = 0; i < clip.tracks.length; i++) { for (var j = 0; j < this.joints.length; j++) { var joint = this.joints[j]; var track = clip.tracks[i]; var jointName = joint.name; if (mapRule) { jointName = mapRule[jointName]; } if (track.name === jointName) { maps[j] = i; break; } } } this._clips.push({ maps: maps, clip: clip }); return this._clips.length - 1; }
javascript
{ "resource": "" }
q21883
train
function (geometry) { var attributes = geometry.attributes; var positionAttr = attributes.position; var jointAttr = attributes.joint; var weightAttr = attributes.weight; var jointsBoundingBoxes = []; for (var i = 0; i < this.joints.length; i++) { jointsBoundingBoxes[i] = new BoundingBox(); jointsBoundingBoxes[i].__updated = false; } var vtxJoint = []; var vtxPos = []; var vtxWeight = []; var maxJointIdx = 0; for (var i = 0; i < geometry.vertexCount; i++) { jointAttr.get(i, vtxJoint); positionAttr.get(i, vtxPos); weightAttr.get(i, vtxWeight); for (var k = 0; k < 4; k++) { if (vtxWeight[k] > 0.01) { var jointIdx = vtxJoint[k]; maxJointIdx = Math.max(maxJointIdx, jointIdx); var min = jointsBoundingBoxes[jointIdx].min.array; var max = jointsBoundingBoxes[jointIdx].max.array; jointsBoundingBoxes[jointIdx].__updated = true; min = vec3.min(min, min, vtxPos); max = vec3.max(max, max, vtxPos); } } } this._jointsBoundingBoxes = jointsBoundingBoxes; this.boundingBox = new BoundingBox(); if (maxJointIdx < this.joints.length - 1) { console.warn('Geometry joints and skeleton joints don\'t match'); } }
javascript
{ "resource": "" }
q21884
train
function () { this._setPose(); var jointsBoundingBoxes = this._jointsBoundingBoxes; for (var i = 0; i < this.joints.length; i++) { var joint = this.joints[i]; mat4.multiply( this._skinMatricesSubArrays[i], joint.node.worldTransform.array, this._jointMatricesSubArrays[i] ); } if (this.boundingBox) { this.boundingBox.min.set(Infinity, Infinity, Infinity); this.boundingBox.max.set(-Infinity, -Infinity, -Infinity); for (var i = 0; i < this.joints.length; i++) { var joint = this.joints[i]; var bbox = jointsBoundingBoxes[i]; if (bbox.__updated) { tmpBoundingBox.copy(bbox); tmpMat4.array = this._skinMatricesSubArrays[i]; tmpBoundingBox.applyTransform(tmpMat4); this.boundingBox.union(tmpBoundingBox); } } } }
javascript
{ "resource": "" }
q21885
train
function (buffer) { var header = new Uint32Array(buffer, 0, 4); if (header[0] !== 0x46546C67) { this.trigger('error', 'Invalid glTF binary format: Invalid header'); return; } if (header[0] < 2) { this.trigger('error', 'Only glTF2.0 is supported.'); return; } var dataView = new DataView(buffer, 12); var json; var buffers = []; // Read chunks for (var i = 0; i < dataView.byteLength;) { var chunkLength = dataView.getUint32(i, true); i += 4; var chunkType = dataView.getUint32(i, true); i += 4; // json if (chunkType === 0x4E4F534A) { var arr = new Uint8Array(buffer, i + 12, chunkLength); // TODO, for the browser not support TextDecoder. var decoder = new TextDecoder(); var str = decoder.decode(arr); try { json = JSON.parse(str); } catch (e) { this.trigger('error', 'JSON Parse error:' + e.toString()); return; } } else if (chunkType === 0x004E4942) { buffers.push(buffer.slice(i + 12, i + 12 + chunkLength)); } i += chunkLength; } if (!json) { this.trigger('error', 'Invalid glTF binary format: Can\'t find JSON.'); return; } return this.parse(json, buffers); }
javascript
{ "resource": "" }
q21886
train
function (path) { if (path && path.match(/^data:(.*?)base64,/)) { return path; } var rootPath = this.bufferRootPath; if (rootPath == null) { rootPath = this.rootPath; } return util$1.relative2absolute(path, rootPath); }
javascript
{ "resource": "" }
q21887
train
function (path) { if (path && path.match(/^data:(.*?)base64,/)) { return path; } var rootPath = this.textureRootPath; if (rootPath == null) { rootPath = this.rootPath; } return util$1.relative2absolute(path, rootPath); }
javascript
{ "resource": "" }
q21888
train
function (renderer) { if (renderer.__currentFrameBuffer) { // Already bound if (renderer.__currentFrameBuffer === this) { return; } console.warn('Renderer already bound with another framebuffer. Unbind it first'); } renderer.__currentFrameBuffer = this; var _gl = renderer.gl; _gl.bindFramebuffer(GL_FRAMEBUFFER, this._getFrameBufferGL(renderer)); this._boundRenderer = renderer; var cache = this._cache; cache.put('viewport', renderer.viewport); var hasTextureAttached = false; var width; var height; for (var attachment in this._textures) { hasTextureAttached = true; var obj = this._textures[attachment]; if (obj) { // TODO Do width, height checking, make sure size are same width = obj.texture.width; height = obj.texture.height; // Attach textures this._doAttach(renderer, obj.texture, attachment, obj.target); } } this._width = width; this._height = height; if (!hasTextureAttached && this.depthBuffer) { console.error('Must attach texture before bind, or renderbuffer may have incorrect width and height.'); } if (this.viewport) { renderer.setViewport(this.viewport); } else { renderer.setViewport(0, 0, width, height, 1); } var attachedTextures = cache.get('attached_textures'); if (attachedTextures) { for (var attachment in attachedTextures) { if (!this._textures[attachment]) { var target = attachedTextures[attachment]; this._doDetach(_gl, attachment, target); } } } if (!cache.get(KEY_DEPTHTEXTURE_ATTACHED) && this.depthBuffer) { // Create a new render buffer if (cache.miss(KEY_RENDERBUFFER)) { cache.put(KEY_RENDERBUFFER, _gl.createRenderbuffer()); } var renderbuffer = cache.get(KEY_RENDERBUFFER); if (width !== cache.get(KEY_RENDERBUFFER_WIDTH) || height !== cache.get(KEY_RENDERBUFFER_HEIGHT)) { _gl.bindRenderbuffer(GL_RENDERBUFFER, renderbuffer); _gl.renderbufferStorage(GL_RENDERBUFFER, _gl.DEPTH_COMPONENT16, width, height); cache.put(KEY_RENDERBUFFER_WIDTH, width); cache.put(KEY_RENDERBUFFER_HEIGHT, height); _gl.bindRenderbuffer(GL_RENDERBUFFER, null); } if (!cache.get(KEY_RENDERBUFFER_ATTACHED)) { _gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer); cache.put(KEY_RENDERBUFFER_ATTACHED, true); } } }
javascript
{ "resource": "" }
q21889
train
function (renderer) { // Remove status record on renderer renderer.__currentFrameBuffer = null; var _gl = renderer.gl; _gl.bindFramebuffer(GL_FRAMEBUFFER, null); this._boundRenderer = null; this._cache.use(renderer.__uid__); var viewport = this._cache.get('viewport'); // Reset viewport; if (viewport) { renderer.setViewport(viewport); } this.updateMipmap(renderer); }
javascript
{ "resource": "" }
q21890
train
function (renderer) { var _gl = renderer.gl; for (var attachment in this._textures) { var obj = this._textures[attachment]; if (obj) { var texture = obj.texture; // FIXME some texture format can't generate mipmap if (!texture.NPOT && texture.useMipmap && texture.minFilter === Texture.LINEAR_MIPMAP_LINEAR) { var target = texture.textureType === 'textureCube' ? glenum.TEXTURE_CUBE_MAP : glenum.TEXTURE_2D; _gl.bindTexture(target, texture.getWebGLTexture(renderer)); _gl.generateMipmap(target); _gl.bindTexture(target, null); } } } }
javascript
{ "resource": "" }
q21891
train
function (attachment, target) { // TODO depth extension check ? this._textures[attachment] = null; if (this._boundRenderer) { var cache = this._cache; cache.use(this._boundRenderer.__uid__); this._doDetach(this._boundRenderer.gl, attachment, target); } }
javascript
{ "resource": "" }
q21892
train
function (scene) { if (this.scene) { this.detachScene(); } scene.skybox = this; this.scene = scene; scene.on('beforerender', this._beforeRenderScene, this); }
javascript
{ "resource": "" }
q21893
train
function (envMap) { if (envMap.textureType === 'texture2D') { this.material.define('EQUIRECTANGULAR'); // LINEAR filter can remove the artifacts in pole envMap.minFilter = Texture.LINEAR; } else { this.material.undefine('EQUIRECTANGULAR'); } this.material.set('environmentMap', envMap); }
javascript
{ "resource": "" }
q21894
train
function (renderer, path, cubeMap, option, onsuccess, onerror) { var self = this; if (typeof(option) === 'function') { onsuccess = option; onerror = onsuccess; option = {}; } else { option = option || {}; } textureUtil.loadTexture(path, option, function (texture) { // PENDING texture.flipY = option.flipY || false; self.panoramaToCubeMap(renderer, texture, cubeMap, option); texture.dispose(renderer); onsuccess && onsuccess(cubeMap); }, onerror); }
javascript
{ "resource": "" }
q21895
train
function (renderer, panoramaMap, cubeMap, option) { var environmentMapPass = new EnvironmentMapPass(); var skydome = new Skybox$1({ scene: new Scene() }); skydome.setEnvironmentMap(panoramaMap); option = option || {}; if (option.encodeRGBM) { skydome.material.define('fragment', 'RGBM_ENCODE'); } // Share sRGB cubeMap.sRGB = panoramaMap.sRGB; environmentMapPass.texture = cubeMap; environmentMapPass.render(renderer, skydome.scene); environmentMapPass.texture = null; environmentMapPass.dispose(renderer); return cubeMap; }
javascript
{ "resource": "" }
q21896
train
function (size, unitSize, color1, color2) { size = size || 512; unitSize = unitSize || 64; color1 = color1 || 'black'; color2 = color2 || 'white'; var repeat = Math.ceil(size / unitSize); var canvas = document.createElement('canvas'); canvas.width = size; canvas.height = size; var ctx = canvas.getContext('2d'); ctx.fillStyle = color2; ctx.fillRect(0, 0, size, size); ctx.fillStyle = color1; for (var i = 0; i < repeat; i++) { for (var j = 0; j < repeat; j++) { var isFill = j % 2 ? (i % 2) : (i % 2 - 1); if (isFill) { ctx.fillRect(i * unitSize, j * unitSize, unitSize, unitSize); } } } var texture = new Texture2D({ image: canvas, anisotropic: 8 }); return texture; }
javascript
{ "resource": "" }
q21897
train
function (color) { var canvas = document.createElement('canvas'); canvas.width = 1; canvas.height = 1; var ctx = canvas.getContext('2d'); ctx.fillStyle = color; ctx.fillRect(0, 0, 1, 1); var texture = new Texture2D({ image: canvas }); return texture; }
javascript
{ "resource": "" }
q21898
train
function (renderer, size) { if (!renderer.getGLExtension('EXT_shader_texture_lod')) { console.warn('Device not support textureCubeLodEXT'); return; } if (!this._brdfLookup) { this._normalDistribution = cubemapUtil.generateNormalDistribution(); this._brdfLookup = cubemapUtil.integrateBRDF(renderer, this._normalDistribution); } var cubemap = this.cubemap; if (cubemap.__prefiltered) { return; } var result = cubemapUtil.prefilterEnvironmentMap( renderer, cubemap, { encodeRGBM: true, width: size, height: size }, this._normalDistribution, this._brdfLookup ); this.cubemap = result.environmentMap; this.cubemap.__prefiltered = true; cubemap.dispose(renderer); }
javascript
{ "resource": "" }
q21899
train
function (renderer, scene, sceneCamera, notUpdateScene) { if (!sceneCamera) { sceneCamera = scene.getMainCamera(); } this.trigger('beforerender', this, renderer, scene, sceneCamera); this._renderShadowPass(renderer, scene, sceneCamera, notUpdateScene); this.trigger('afterrender', this, renderer, scene, sceneCamera); }
javascript
{ "resource": "" }