Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Style Improvements #4806

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cameras/Camera.js
Expand Up @@ -31,7 +31,7 @@ THREE.Camera.prototype.lookAt = function () {

}();

THREE.Camera.prototype.clone = function (camera) {
THREE.Camera.prototype.clone = function ( camera ) {

if ( camera === undefined ) camera = new THREE.Camera();

Expand Down
16 changes: 8 additions & 8 deletions src/cameras/CubeCamera.js
Expand Up @@ -12,13 +12,13 @@ THREE.CubeCamera = function ( near, far, cubeResolution ) {
var fov = 90, aspect = 1;

var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
cameraPX.up.set( 0, -1, 0 );
cameraPX.up.set( 0, - 1, 0 );
cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
this.add( cameraPX );

var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
cameraNX.up.set( 0, -1, 0 );
cameraNX.lookAt( new THREE.Vector3( -1, 0, 0 ) );
cameraNX.up.set( 0, - 1, 0 );
cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
this.add( cameraNX );

var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
Expand All @@ -27,18 +27,18 @@ THREE.CubeCamera = function ( near, far, cubeResolution ) {
this.add( cameraPY );

var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
cameraNY.up.set( 0, 0, -1 );
cameraNY.lookAt( new THREE.Vector3( 0, -1, 0 ) );
cameraNY.up.set( 0, 0, - 1 );
cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
this.add( cameraNY );

var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
cameraPZ.up.set( 0, -1, 0 );
cameraPZ.up.set( 0, - 1, 0 );
cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
this.add( cameraPZ );

var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
cameraNZ.up.set( 0, -1, 0 );
cameraNZ.lookAt( new THREE.Vector3( 0, 0, -1 ) );
cameraNZ.up.set( 0, - 1, 0 );
cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
this.add( cameraNZ );

this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
Expand Down
2 changes: 1 addition & 1 deletion src/cameras/OrthographicCamera.js
Expand Up @@ -36,7 +36,7 @@ THREE.OrthographicCamera.prototype.clone = function () {
camera.right = this.right;
camera.top = this.top;
camera.bottom = this.bottom;

camera.near = this.near;
camera.far = this.far;

Expand Down
2 changes: 1 addition & 1 deletion src/cameras/PerspectiveCamera.js
Expand Up @@ -92,7 +92,7 @@ THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {

var aspect = this.fullWidth / this.fullHeight;
var top = Math.tan( THREE.Math.degToRad( this.fov * 0.5 ) ) * this.near;
var bottom = -top;
var bottom = - top;
var left = aspect * bottom;
var right = aspect * top;
var width = Math.abs( right - left );
Expand Down
120 changes: 60 additions & 60 deletions src/core/BufferGeometry.js
Expand Up @@ -88,13 +88,13 @@ THREE.BufferGeometry.prototype = {

}

var positions = this.attributes[ "position" ].array;
var positions = this.attributes[ 'position' ].array;

if ( positions ) {

var bb = this.boundingBox;

if( positions.length >= 3 ) {
if ( positions.length >= 3 ) {
bb.min.x = bb.max.x = positions[ 0 ];
bb.min.y = bb.max.y = positions[ 1 ];
bb.min.z = bb.max.z = positions[ 2 ];
Expand Down Expand Up @@ -533,7 +533,7 @@ THREE.BufferGeometry.prototype = {

tmp2.crossVectors( n2, t );
test = tmp2.dot( tan2[ v ] );
w = ( test < 0.0 ) ? -1.0 : 1.0;
w = ( test < 0.0 ) ? - 1.0 : 1.0;

tangents[ v * 4 ] = tmp.x;
tangents[ v * 4 + 1 ] = tmp.y;
Expand Down Expand Up @@ -571,19 +571,19 @@ THREE.BufferGeometry.prototype = {
WARNING: This method will also expand the vertex count to prevent sprawled triangles across draw offsets.
indexBufferSize - Defaults to 65535, but allows for larger or smaller chunks.
*/
computeOffsets: function(indexBufferSize) {
computeOffsets: function ( indexBufferSize ) {

var size = indexBufferSize;
if(indexBufferSize === undefined)
if ( indexBufferSize === undefined )
size = 65535; //WebGL limits type of index buffer values to 16-bit.

var s = Date.now();

var indices = this.attributes['index'].array;
var vertices = this.attributes['position'].array;
var indices = this.attributes[ 'index' ].array;
var vertices = this.attributes[ 'position' ].array;

var verticesCount = (vertices.length/3);
var facesCount = (indices.length/3);
var verticesCount = ( vertices.length / 3 );
var facesCount = ( indices.length / 3 );

/*
console.log("Computing buffers in offsets of "+size+" -> indices:"+indices.length+" vertices:"+vertices.length);
Expand All @@ -596,72 +596,72 @@ THREE.BufferGeometry.prototype = {
var vertexPtr = 0;

var offsets = [ { start:0, count:0, index:0 } ];
var offset = offsets[0];
var offset = offsets[ 0 ];

var duplicatedVertices = 0;
var newVerticeMaps = 0;
var faceVertices = new Int32Array(6);
var faceVertices = new Int32Array( 6 );
var vertexMap = new Int32Array( vertices.length );
var revVertexMap = new Int32Array( vertices.length );
for(var j = 0; j < vertices.length; j++) { vertexMap[j] = -1; revVertexMap[j] = -1; }
for ( var j = 0; j < vertices.length; j ++ ) { vertexMap[ j ] = - 1; revVertexMap[ j ] = - 1; }

/*
Traverse every face and reorder vertices in the proper offsets of 65k.
We can have more than 65k entries in the index buffer per offset, but only reference 65k values.
*/
for(var findex = 0; findex < facesCount; findex++) {
for ( var findex = 0; findex < facesCount; findex ++ ) {
newVerticeMaps = 0;

for(var vo = 0; vo < 3; vo++) {
var vid = indices[ findex*3 + vo ];
if(vertexMap[vid] == -1) {
for ( var vo = 0; vo < 3; vo ++ ) {
var vid = indices[ findex * 3 + vo ];
if ( vertexMap[ vid ] == - 1 ) {
//Unmapped vertice
faceVertices[vo*2] = vid;
faceVertices[vo*2+1] = -1;
newVerticeMaps++;
} else if(vertexMap[vid] < offset.index) {
faceVertices[ vo * 2 ] = vid;
faceVertices[ vo * 2 + 1 ] = - 1;
newVerticeMaps ++;
} else if ( vertexMap[ vid ] < offset.index ) {
//Reused vertices from previous block (duplicate)
faceVertices[vo*2] = vid;
faceVertices[vo*2+1] = -1;
duplicatedVertices++;
faceVertices[ vo * 2 ] = vid;
faceVertices[ vo * 2 + 1 ] = - 1;
duplicatedVertices ++;
} else {
//Reused vertice in the current block
faceVertices[vo*2] = vid;
faceVertices[vo*2+1] = vertexMap[vid];
faceVertices[ vo * 2 ] = vid;
faceVertices[ vo * 2 + 1 ] = vertexMap[ vid ];
}
}

var faceMax = vertexPtr + newVerticeMaps;
if(faceMax > (offset.index + size)) {
if ( faceMax > ( offset.index + size ) ) {
var new_offset = { start:indexPtr, count:0, index:vertexPtr };
offsets.push(new_offset);
offsets.push( new_offset );
offset = new_offset;

//Re-evaluate reused vertices in light of new offset.
for(var v = 0; v < 6; v+=2) {
var new_vid = faceVertices[v+1];
if(new_vid > -1 && new_vid < offset.index)
faceVertices[v+1] = -1;
for ( var v = 0; v < 6; v += 2 ) {
var new_vid = faceVertices[ v + 1 ];
if ( new_vid > - 1 && new_vid < offset.index )
faceVertices[ v + 1 ] = - 1;
}
}

//Reindex the face.
for(var v = 0; v < 6; v+=2) {
var vid = faceVertices[v];
var new_vid = faceVertices[v+1];
for ( var v = 0; v < 6; v += 2 ) {
var vid = faceVertices[ v ];
var new_vid = faceVertices[ v + 1 ];

if(new_vid === -1)
new_vid = vertexPtr++;
if ( new_vid === - 1 )
new_vid = vertexPtr ++;

vertexMap[vid] = new_vid;
revVertexMap[new_vid] = vid;
sortedIndices[indexPtr++] = new_vid - offset.index; //XXX overflows at 16bit
offset.count++;
vertexMap[ vid ] = new_vid;
revVertexMap[ new_vid ] = vid;
sortedIndices[ indexPtr ++ ] = new_vid - offset.index; //XXX overflows at 16bit
offset.count ++;
}
}

/* Move all attribute values to map to the new computed indices , also expand the vertice stack to match our new vertexPtr. */
this.reorderBuffers(sortedIndices, revVertexMap, vertexPtr);
this.reorderBuffers( sortedIndices, revVertexMap, vertexPtr );
this.offsets = offsets;

/*
Expand Down Expand Up @@ -710,45 +710,45 @@ THREE.BufferGeometry.prototype = {
indexMap - Int32Array where the position is the new vertex ID and the value the old vertex ID for each vertex.
vertexCount - Amount of total vertices considered in this reordering (in case you want to grow the vertice stack).
*/
reorderBuffers: function(indexBuffer, indexMap, vertexCount) {
reorderBuffers: function ( indexBuffer, indexMap, vertexCount ) {

/* Create a copy of all attributes for reordering. */
var sortedAttributes = {};
var types = [ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array ];
for( var attr in this.attributes ) {
if(attr == 'index')
for ( var attr in this.attributes ) {
if ( attr == 'index' )
continue;
var sourceArray = this.attributes[attr].array;
for ( var i = 0, il = types.length; i < il; i++ ) {
var type = types[i];
if (sourceArray instanceof type) {
sortedAttributes[attr] = new type( this.attributes[attr].itemSize * vertexCount );
var sourceArray = this.attributes[ attr ].array;
for ( var i = 0, il = types.length; i < il; i ++ ) {
var type = types[ i ];
if ( sourceArray instanceof type ) {
sortedAttributes[ attr ] = new type( this.attributes[ attr ].itemSize * vertexCount );
break;
}
}
}

/* Move attribute positions based on the new index map */
for(var new_vid = 0; new_vid < vertexCount; new_vid++) {
var vid = indexMap[new_vid];
for ( var new_vid = 0; new_vid < vertexCount; new_vid ++ ) {
var vid = indexMap[ new_vid ];
for ( var attr in this.attributes ) {
if(attr == 'index')
if ( attr == 'index' )
continue;
var attrArray = this.attributes[attr].array;
var attrSize = this.attributes[attr].itemSize;
var sortedAttr = sortedAttributes[attr];
for(var k = 0; k < attrSize; k++)
var attrArray = this.attributes[ attr ].array;
var attrSize = this.attributes[ attr ].itemSize;
var sortedAttr = sortedAttributes[ attr ];
for ( var k = 0; k < attrSize; k ++ )
sortedAttr[ new_vid * attrSize + k ] = attrArray[ vid * attrSize + k ];
}
}

/* Carry the new sorted buffers locally */
this.attributes['index'].array = indexBuffer;
this.attributes[ 'index' ].array = indexBuffer;
for ( var attr in this.attributes ) {
if(attr == 'index')
if ( attr == 'index' )
continue;
this.attributes[attr].array = sortedAttributes[attr];
this.attributes[attr].numItems = this.attributes[attr].itemSize * vertexCount;
this.attributes[ attr ].array = sortedAttributes[ attr ];
this.attributes[ attr ].numItems = this.attributes[ attr ].itemSize * vertexCount;
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/core/EventDispatcher.js
Expand Up @@ -75,7 +75,7 @@ THREE.EventDispatcher.prototype = {
},

dispatchEvent: function ( event ) {

if ( this._listeners === undefined ) return;

var listeners = this._listeners;
Expand Down
12 changes: 6 additions & 6 deletions src/core/Face3.js
Expand Up @@ -35,21 +35,21 @@ THREE.Face3.prototype = {
face.materialIndex = this.materialIndex;

for ( var i = 0, il = this.vertexNormals.length; i < il; i ++ ) {

face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();

}

for ( var i = 0, il = this.vertexColors.length; i < il; i ++ ) {

face.vertexColors[ i ] = this.vertexColors[ i ].clone();

}

for ( var i = 0, il = this.vertexTangents.length; i < il; i ++ ) {

face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();

}

return face;
Expand Down
2 changes: 1 addition & 1 deletion src/core/Face4.js
Expand Up @@ -4,7 +4,7 @@

THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {

console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.')
console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' )
return new THREE.Face3( a, b, c, normal, color, materialIndex );

};
10 changes: 5 additions & 5 deletions src/core/Geometry.js
Expand Up @@ -19,7 +19,7 @@ THREE.Geometry = function () {

this.faces = [];

this.faceVertexUvs = [[]];
this.faceVertexUvs = [ [] ];

this.morphTargets = [];
this.morphColors = [];
Expand Down Expand Up @@ -381,7 +381,7 @@ THREE.Geometry.prototype = {

face = this.faces[ f ];

for ( i = 0; i < Math.min( face.vertexNormals.length, 3 ); i++ ) {
for ( i = 0; i < Math.min( face.vertexNormals.length, 3 ); i ++ ) {

n.copy( face.vertexNormals[ i ] );

Expand All @@ -398,7 +398,7 @@ THREE.Geometry.prototype = {

tmp2.crossVectors( face.vertexNormals[ i ], t );
test = tmp2.dot( tan2[ vertexIndex ] );
w = (test < 0.0) ? -1.0 : 1.0;
w = ( test < 0.0 ) ? - 1.0 : 1.0;

face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );

Expand Down Expand Up @@ -606,7 +606,7 @@ THREE.Geometry.prototype = {
// have to remove them from the geometry.
var faceIndicesToRemove = [];

for( i = 0, il = this.faces.length; i < il; i ++ ) {
for ( i = 0, il = this.faces.length; i < il; i ++ ) {

face = this.faces[ i ];

Expand All @@ -616,7 +616,7 @@ THREE.Geometry.prototype = {

indices = [ face.a, face.b, face.c ];

var dupIndex = -1;
var dupIndex = - 1;

// if any duplicate vertices are found in a Face3
// we have to remove the face as nothing can be saved
Expand Down
4 changes: 2 additions & 2 deletions src/core/Object3D.js
Expand Up @@ -168,7 +168,7 @@ THREE.Object3D.prototype = {

},

rotateOnAxis: function() {
rotateOnAxis: function () {

// rotate object on axis in object space
// axis is assumed to be normalized
Expand Down Expand Up @@ -325,7 +325,7 @@ THREE.Object3D.prototype = {

if ( object === this ) {

console.warn( 'THREE.Object3D.add: An object can\'t be added as a child of itself.' );
console.warn( "THREE.Object3D.add: An object can't be added as a child of itself." );
return;

}
Expand Down