提交 aed22aee 编写于 作者: M Mr.doob

Merge pull request #6863 from gero3/MDCSCleanup

 cleanup of files for MrDoob's code style
......@@ -118,7 +118,7 @@ THREE.AudioObject = function ( url, volume, playbackRate, loop ) {
cameraUp.copy( camera.up );
cameraFront.set( 0, 0, -1 );
cameraFront.set( 0, 0, - 1 );
cameraFront.transformDirection( camera.matrixWorld );
this.listener.setPosition( cameraPosition.x, cameraPosition.y, cameraPosition.z );
......@@ -130,7 +130,7 @@ THREE.AudioObject = function ( url, volume, playbackRate, loop ) {
if ( this.directionalSource ) {
soundFront.set( 0, 0, -1 );
soundFront.set( 0, 0, - 1 );
soundFront.transformDirection( this.matrixWorld );
soundUp.copy( this.up );
......
......@@ -62,7 +62,7 @@ THREE.BlendCharacter = function () {
// interpolate the weight for the current time
data.anim.weight = data.startWeight + (data.endWeight - data.startWeight) * data.timeElapsed / data.duration;
data.anim.weight = data.startWeight + ( data.endWeight - data.startWeight ) * data.timeElapsed / data.duration;
}
......@@ -117,7 +117,7 @@ THREE.BlendCharacter = function () {
};
this.play = function(animName, weight) {
this.play = function( animName, weight ) {
this.animations[ animName ].play( 0, weight );
......@@ -172,7 +172,7 @@ THREE.BlendCharacter = function () {
};
this.applyWeight = function(animName, weight) {
this.applyWeight = function( animName, weight ) {
this.animations[ animName ].weight = weight;
......@@ -212,7 +212,9 @@ THREE.BlendCharacter = function () {
for ( a in this.animations ) {
if ( this.animations[ a ].isPlaying ) {
this.animations[ a ].stop(0);
this.animations[ a ].stop( 0 );
}
this.animations[ a ].weight = 0;
......@@ -244,12 +246,14 @@ THREE.BlendCharacter.prototype.getForward = function() {
// pull the character's forward basis vector out of the matrix
forward.set(
-this.matrix.elements[ 8 ],
-this.matrix.elements[ 9 ],
-this.matrix.elements[ 10 ]
- this.matrix.elements[ 8 ],
- this.matrix.elements[ 9 ],
- this.matrix.elements[ 10 ]
);
return forward;
}
};
......@@ -2,7 +2,7 @@
* @author Michael Guerrero / http://realitymeltdown.com
*/
function BlendCharacterGui(animations) {
function BlendCharacterGui( animations ) {
var controls = {
......@@ -22,27 +22,27 @@ function BlendCharacterGui(animations) {
this.showModel = function() {
return controls['Show Model'];
return controls[ 'Show Model' ];
};
this.showSkeleton = function() {
return controls['Show Skeleton'];
return controls[ 'Show Skeleton' ];
};
this.getTimeScale = function() {
return controls['Time Scale'];
return controls[ 'Time Scale' ];
};
this.update = function() {
controls[ 'idle'] = animations[ 'idle' ].weight;
controls[ 'walk'] = animations[ 'walk' ].weight;
controls[ 'run'] = animations[ 'run' ].weight;
controls[ 'idle' ] = animations[ 'idle' ].weight;
controls[ 'walk' ] = animations[ 'walk' ].weight;
controls[ 'run' ] = animations[ 'run' ].weight;
};
......@@ -68,9 +68,9 @@ function BlendCharacterGui(animations) {
playback.add( controls, "walk to run" );
playback.add( controls, "warp walk to run" );
blending.add( controls, "idle", 0, 1, 0.01).listen().onChange( controls.weight );
blending.add( controls, "walk", 0, 1, 0.01).listen().onChange( controls.weight );
blending.add( controls, "run", 0, 1, 0.01).listen().onChange( controls.weight );
blending.add( controls, "idle", 0, 1, 0.01 ).listen().onChange( controls.weight );
blending.add( controls, "walk", 0, 1, 0.01 ).listen().onChange( controls.weight );
blending.add( controls, "run", 0, 1, 0.01 ).listen().onChange( controls.weight );
settings.open();
playback.open();
......@@ -86,18 +86,19 @@ function BlendCharacterGui(animations) {
anims: [ "idle", "walk", "run" ],
weights: [ controls['idle'],
controls['walk'],
controls['run'] ]
weights: [ controls[ 'idle' ],
controls[ 'walk' ],
controls[ 'run' ] ]
}
};
};
controls.start = function() {
var startEvent = new CustomEvent( 'start-animation', getAnimationData() );
window.dispatchEvent(startEvent);
window.dispatchEvent( startEvent );
};
......@@ -117,21 +118,22 @@ function BlendCharacterGui(animations) {
controls.step = function() {
var stepData = { detail: { stepSize: controls['Step Size'] } };
window.dispatchEvent( new CustomEvent('step-animation', stepData ));
var stepData = { detail: { stepSize: controls[ 'Step Size' ] } };
window.dispatchEvent( new CustomEvent( 'step-animation', stepData ) );
};
controls.weight = function() {
// renormalize
var sum = controls['idle'] + controls['walk'] + controls['run'];
controls['idle'] /= sum;
controls['walk'] /= sum;
controls['run'] /= sum;
var sum = controls[ 'idle' ] + controls[ 'walk' ] + controls[ 'run' ];
controls[ 'idle' ] /= sum;
controls[ 'walk' ] /= sum;
controls[ 'run' ] /= sum;
var weightEvent = new CustomEvent( 'weight-animation', getAnimationData() );
window.dispatchEvent(weightEvent);
window.dispatchEvent( weightEvent );
};
controls.crossfade = function( from, to ) {
......@@ -142,6 +144,7 @@ function BlendCharacterGui(animations) {
fadeData.detail.time = controls[ "Crossfade Time" ];
window.dispatchEvent( new CustomEvent( 'crossfade', fadeData ) );
};
controls.warp = function( from, to ) {
......@@ -152,21 +155,22 @@ function BlendCharacterGui(animations) {
warpData.detail.time = controls[ "Crossfade Time" ];
window.dispatchEvent( new CustomEvent( 'warp', warpData ) );
};
controls['idle to walk'] = function() {
controls[ 'idle to walk' ] = function() {
controls.crossfade( 'idle', 'walk' );
};
controls['walk to run'] = function() {
controls[ 'walk to run' ] = function() {
controls.crossfade( 'walk', 'run' );
};
controls['warp walk to run'] = function() {
controls[ 'warp walk to run' ] = function() {
controls.warp( 'walk', 'run' );
......@@ -176,11 +180,12 @@ function BlendCharacterGui(animations) {
var data = {
detail: {
shouldShow: controls['Show Skeleton']
shouldShow: controls[ 'Show Skeleton' ]
}
};
window.dispatchEvent( new CustomEvent( 'toggle-show-skeleton', data ) );
};
......@@ -188,14 +193,15 @@ function BlendCharacterGui(animations) {
var data = {
detail: {
shouldShow: controls['Show Model']
shouldShow: controls[ 'Show Model' ]
}
};
window.dispatchEvent( new CustomEvent( 'toggle-show-model', data ) );
};
init.call(this);
init.call( this );
}
......@@ -27,7 +27,7 @@ THREE.Car = function () {
// car "feel" parameters
this.MAX_SPEED = 2200;
this.MAX_REVERSE_SPEED = -1500;
this.MAX_REVERSE_SPEED = - 1500;
this.MAX_WHEEL_ROTATION = 0.6;
......@@ -107,8 +107,16 @@ THREE.Car = function () {
var loader = new THREE.JSONLoader();
loader.load( bodyURL, function( geometry, materials ) { createBody( geometry, materials ) } );
loader.load( wheelURL, function( geometry, materials ) { createWheels( geometry, materials ) } );
loader.load( bodyURL, function( geometry, materials ) {
createBody( geometry, materials )
} );
loader.load( wheelURL, function( geometry, materials ) {
createWheels( geometry, materials )
} );
};
......@@ -116,8 +124,16 @@ THREE.Car = function () {
var loader = new THREE.BinaryLoader();
loader.load( bodyURL, function( geometry, materials ) { createBody( geometry, materials ) } );
loader.load( wheelURL, function( geometry, materials ) { createWheels( geometry, materials ) } );
loader.load( bodyURL, function( geometry, materials ) {
createBody( geometry, materials )
} );
loader.load( wheelURL, function( geometry, materials ) {
createWheels( geometry, materials )
} );
};
......@@ -128,7 +144,7 @@ THREE.Car = function () {
if ( controls.moveForward ) {
this.speed = THREE.Math.clamp( this.speed + delta * this.FRONT_ACCELERATION, this.MAX_REVERSE_SPEED, this.MAX_SPEED );
this.acceleration = THREE.Math.clamp( this.acceleration + delta, -1, 1 );
this.acceleration = THREE.Math.clamp( this.acceleration + delta, - 1, 1 );
}
......@@ -136,7 +152,7 @@ THREE.Car = function () {
this.speed = THREE.Math.clamp( this.speed - delta * this.BACK_ACCELERATION, this.MAX_REVERSE_SPEED, this.MAX_SPEED );
this.acceleration = THREE.Math.clamp( this.acceleration - delta, -1, 1 );
this.acceleration = THREE.Math.clamp( this.acceleration - delta, - 1, 1 );
}
......@@ -168,7 +184,7 @@ THREE.Car = function () {
var k = exponentialEaseOut( this.speed / this.MAX_REVERSE_SPEED );
this.speed = THREE.Math.clamp( this.speed + k * delta * this.BACK_ACCELERATION, this.MAX_REVERSE_SPEED, 0 );
this.acceleration = THREE.Math.clamp( this.acceleration + k * delta, -1, 0 );
this.acceleration = THREE.Math.clamp( this.acceleration + k * delta, - 1, 0 );
}
......@@ -307,7 +323,7 @@ THREE.Car = function () {
// front right wheel
delta.multiplyVectors( scope.wheelOffset, new THREE.Vector3( -s, s, s ) );
delta.multiplyVectors( scope.wheelOffset, new THREE.Vector3( - s, s, s ) );
scope.frontRightWheelRoot.position.add( delta );
......@@ -321,7 +337,7 @@ THREE.Car = function () {
// back left wheel
delta.multiplyVectors( scope.wheelOffset, new THREE.Vector3( s, s, -s ) );
delta.multiplyVectors( scope.wheelOffset, new THREE.Vector3( s, s, - s ) );
delta.z -= scope.backWheelOffset;
scope.backLeftWheelMesh = new THREE.Mesh( scope.wheelGeometry, wheelFaceMaterial );
......@@ -333,7 +349,7 @@ THREE.Car = function () {
// back right wheel
delta.multiplyVectors( scope.wheelOffset, new THREE.Vector3( -s, s, -s ) );
delta.multiplyVectors( scope.wheelOffset, new THREE.Vector3( - s, s, - s ) );
delta.z -= scope.backWheelOffset;
scope.backRightWheelMesh = new THREE.Mesh( scope.wheelGeometry, wheelFaceMaterial );
......@@ -362,10 +378,30 @@ THREE.Car = function () {
}
function quadraticEaseOut( k ) { return - k * ( k - 2 ); }
function cubicEaseOut( k ) { return -- k * k * k + 1; }
function circularEaseOut( k ) { return Math.sqrt( 1 - -- k * k ); }
function sinusoidalEaseOut( k ) { return Math.sin( k * Math.PI / 2 ); }
function exponentialEaseOut( k ) { return k === 1 ? 1 : - Math.pow( 2, - 10 * k ) + 1; }
function quadraticEaseOut( k ) {
return - k * ( k - 2 );
}
function cubicEaseOut( k ) {
return -- k * k * k + 1;
}
function circularEaseOut( k ) {
return Math.sqrt( 1 - -- k * k );
}
function sinusoidalEaseOut( k ) {
return Math.sin( k * Math.PI / 2 );
}
function exponentialEaseOut( k ) {
return k === 1 ? 1 : - Math.pow( 2, - 10 * k ) + 1;
}
};
......@@ -19,12 +19,12 @@ var restDistance = 25;
var xSegs = 10; //
var ySegs = 10; //
var clothFunction = plane(restDistance * xSegs, restDistance * ySegs);
var clothFunction = plane( restDistance * xSegs, restDistance * ySegs );
var cloth = new Cloth(xSegs, ySegs);
var cloth = new Cloth( xSegs, ySegs );
var GRAVITY = 981 * 1.4; //
var gravity = new THREE.Vector3( 0, -GRAVITY, 0 ).multiplyScalar(MASS);
var gravity = new THREE.Vector3( 0, - GRAVITY, 0 ).multiplyScalar( MASS );
var TIMESTEP = 18 / 1000;
......@@ -35,9 +35,9 @@ var pins = [];
var wind = true;
var windStrength = 2;
var windForce = new THREE.Vector3(0,0,0);
var windForce = new THREE.Vector3( 0, 0, 0 );
var ballPosition = new THREE.Vector3(0, -45, 0);
var ballPosition = new THREE.Vector3( 0, - 45, 0 );
var ballSize = 60; //40
var tmpForce = new THREE.Vector3();
......@@ -45,64 +45,76 @@ var tmpForce = new THREE.Vector3();
var lastTime;
function plane(width, height) {
function plane( width, height ) {
return function(u, v) {
var x = (u - 0.5) * width;
var y = (v + 0.5) * height;
return function( u, v ) {
var x = ( u - 0.5 ) * width;
var y = ( v + 0.5 ) * height;
var z = 0;
return new THREE.Vector3(x, y, z);
return new THREE.Vector3( x, y, z );
};
}
function Particle(x, y, z, mass) {
this.position = clothFunction(x, y); // position
this.previous = clothFunction(x, y); // previous
this.original = clothFunction(x, y);
this.a = new THREE.Vector3(0, 0, 0); // acceleration
function Particle( x, y, z, mass ) {
this.position = clothFunction( x, y ); // position
this.previous = clothFunction( x, y ); // previous
this.original = clothFunction( x, y );
this.a = new THREE.Vector3( 0, 0, 0 ); // acceleration
this.mass = mass;
this.invMass = 1 / mass;
this.tmp = new THREE.Vector3();
this.tmp2 = new THREE.Vector3();
}
// Force -> Acceleration
Particle.prototype.addForce = function(force) {
Particle.prototype.addForce = function( force ) {
this.a.add(
this.tmp2.copy(force).multiplyScalar(this.invMass)
this.tmp2.copy( force ).multiplyScalar( this.invMass )
);
};
// Performs verlet integration
Particle.prototype.integrate = function(timesq) {
var newPos = this.tmp.subVectors(this.position, this.previous);
newPos.multiplyScalar(DRAG).add(this.position);
newPos.add(this.a.multiplyScalar(timesq));
Particle.prototype.integrate = function( timesq ) {
var newPos = this.tmp.subVectors( this.position, this.previous );
newPos.multiplyScalar( DRAG ).add( this.position );
newPos.add( this.a.multiplyScalar( timesq ) );
this.tmp = this.previous;
this.previous = this.position;
this.position = newPos;
this.a.set(0, 0, 0);
this.a.set( 0, 0, 0 );
};
var diff = new THREE.Vector3();
function satisifyConstrains(p1, p2, distance) {
diff.subVectors(p2.position, p1.position);
function satisifyConstrains( p1, p2, distance ) {
diff.subVectors( p2.position, p1.position );
var currentDist = diff.length();
if (currentDist == 0) return; // prevents division by 0
var correction = diff.multiplyScalar(1 - distance / currentDist);
var correctionHalf = correction.multiplyScalar(0.5);
p1.position.add(correctionHalf);
p2.position.sub(correctionHalf);
if ( currentDist == 0 ) return; // prevents division by 0
var correction = diff.multiplyScalar( 1 - distance / currentDist );
var correctionHalf = correction.multiplyScalar( 0.5 );
p1.position.add( correctionHalf );
p2.position.sub( correctionHalf );
}
function Cloth(w, h) {
function Cloth( w, h ) {
w = w || 10;
h = h || 10;
this.w = w;
......@@ -114,49 +126,59 @@ function Cloth(w, h) {
var u, v;
// Create particles
for (v = 0; v <= h; v ++) {
for (u = 0; u <= w; u ++) {
for ( v = 0; v <= h; v ++ ) {
for ( u = 0; u <= w; u ++ ) {
particles.push(
new Particle(u / w, v / h, 0, MASS)
new Particle( u / w, v / h, 0, MASS )
);
}
}
// Structural
for (v = 0; v < h; v ++) {
for (u = 0; u < w; u ++) {
for ( v = 0; v < h; v ++ ) {
for ( u = 0; u < w; u ++ ) {
constrains.push([
particles[index(u, v)],
particles[index(u, v + 1)],
constrains.push( [
particles[ index( u, v ) ],
particles[ index( u, v + 1 ) ],
restDistance
]);
] );
constrains.push([
particles[index(u, v)],
particles[index(u + 1, v)],
constrains.push( [
particles[ index( u, v ) ],
particles[ index( u + 1, v ) ],
restDistance
]);
] );
}
}
for (u = w, v = 0; v < h; v ++) {
constrains.push([
particles[index(u, v)],
particles[index(u, v + 1)],
for ( u = w, v = 0; v < h; v ++ ) {
constrains.push( [
particles[ index( u, v ) ],
particles[ index( u, v + 1 ) ],
restDistance
]);
] );
}
for (v = h, u = 0; u < w; u ++) {
constrains.push([
particles[index(u, v)],
particles[index(u + 1, v)],
for ( v = h, u = 0; u < w; u ++ ) {
constrains.push( [
particles[ index( u, v ) ],
particles[ index( u + 1, v ) ],
restDistance
]);
] );
}
......@@ -189,91 +211,114 @@ function Cloth(w, h) {
this.particles = particles;
this.constrains = constrains;
function index(u, v) {
return u + v * (w + 1);
function index( u, v ) {
return u + v * ( w + 1 );
}
this.index = index;
}
function simulate(time) {
if (!lastTime) {
function simulate( time ) {
if ( ! lastTime ) {
lastTime = time;
return;
}
var i, il, particles, particle, pt, constrains, constrain;
// Aerodynamics forces
if (wind) {
if ( wind ) {
var face, faces = clothGeometry.faces, normal;
particles = cloth.particles;
for (i = 0,il = faces.length; i < il; i ++) {
face = faces[i];
for ( i = 0, il = faces.length; i < il; i ++ ) {
face = faces[ i ];
normal = face.normal;
tmpForce.copy(normal).normalize().multiplyScalar(normal.dot(windForce));
particles[face.a].addForce(tmpForce);
particles[face.b].addForce(tmpForce);
particles[face.c].addForce(tmpForce);
tmpForce.copy( normal ).normalize().multiplyScalar( normal.dot( windForce ) );
particles[ face.a ].addForce( tmpForce );
particles[ face.b ].addForce( tmpForce );
particles[ face.c ].addForce( tmpForce );
}
}
for (particles = cloth.particles, i = 0, il = particles.length
; i < il; i ++) {
particle = particles[i];
particle.addForce(gravity);
for ( particles = cloth.particles, i = 0, il = particles.length
; i < il; i ++ ) {
particle = particles[ i ];
particle.addForce( gravity );
particle.integrate( TIMESTEP_SQ );
particle.integrate(TIMESTEP_SQ);
}
// Start Constrains
constrains = cloth.constrains,
il = constrains.length;
for (i = 0; i < il; i ++) {
constrain = constrains[i];
satisifyConstrains(constrain[0], constrain[1], constrain[2]);
for ( i = 0; i < il; i ++ ) {
constrain = constrains[ i ];
satisifyConstrains( constrain[ 0 ], constrain[ 1 ], constrain[ 2 ] );
}
// Ball Constrains
ballPosition.z = -Math.sin(Date.now() / 600) * 90 ; //+ 40;
ballPosition.x = Math.cos(Date.now() / 400) * 70;
ballPosition.z = - Math.sin( Date.now() / 600 ) * 90 ; //+ 40;
ballPosition.x = Math.cos( Date.now() / 400 ) * 70;
if ( sphere.visible )
for ( particles = cloth.particles, i = 0, il = particles.length
; i < il; i ++ ) {
if (sphere.visible)
for (particles = cloth.particles, i = 0, il = particles.length
; i < il; i ++) {
particle = particles[i];
particle = particles[ i ];
pos = particle.position;
diff.subVectors(pos, ballPosition);
if (diff.length() < ballSize) {
diff.subVectors( pos, ballPosition );
if ( diff.length() < ballSize ) {
// collided
diff.normalize().multiplyScalar(ballSize);
pos.copy(ballPosition).add(diff);
diff.normalize().multiplyScalar( ballSize );
pos.copy( ballPosition ).add( diff );
}
}
// Floor Constains
for (particles = cloth.particles, i = 0, il = particles.length
; i < il; i ++) {
particle = particles[i];
for ( particles = cloth.particles, i = 0, il = particles.length
; i < il; i ++ ) {
particle = particles[ i ];
pos = particle.position;
if (pos.y < -250) {
pos.y = -250;
if ( pos.y < - 250 ) {
pos.y = - 250;
}
}
// Pin Constrains
for (i = 0, il = pins.length; i < il; i ++) {
var xy = pins[i];
var p = particles[xy];
p.position.copy(p.original);
p.previous.copy(p.original);
for ( i = 0, il = pins.length; i < il; i ++ ) {
var xy = pins[ i ];
var p = particles[ xy ];
p.position.copy( p.original );
p.previous.copy( p.original );
}
......
......@@ -17,32 +17,34 @@ THREE.Curves = {};
THREE.Curves.GrannyKnot = THREE.Curve.create( function() {},
function(t) {
function( t ) {
t = 2 * Math.PI * t;
var x = -0.22 * Math.cos(t) - 1.28 * Math.sin(t) - 0.44 * Math.cos(3 * t) - 0.78 * Math.sin(3 * t);
var y = -0.1 * Math.cos(2 * t) - 0.27 * Math.sin(2 * t) + 0.38 * Math.cos(4 * t) + 0.46 * Math.sin(4 * t);
var z = 0.7 * Math.cos(3 * t) - 0.4 * Math.sin(3 * t);
return new THREE.Vector3(x, y, z).multiplyScalar(20);
var x = - 0.22 * Math.cos( t ) - 1.28 * Math.sin( t ) - 0.44 * Math.cos( 3 * t ) - 0.78 * Math.sin( 3 * t );
var y = - 0.1 * Math.cos( 2 * t ) - 0.27 * Math.sin( 2 * t ) + 0.38 * Math.cos( 4 * t ) + 0.46 * Math.sin( 4 * t );
var z = 0.7 * Math.cos( 3 * t ) - 0.4 * Math.sin( 3 * t );
return new THREE.Vector3( x, y, z ).multiplyScalar( 20 );
}
);
THREE.Curves.HeartCurve = THREE.Curve.create(
function(s) {
function( s ) {
this.scale = (s === undefined) ? 5 : s;
this.scale = ( s === undefined ) ? 5 : s;
},
function(t) {
function( t ) {
t *= 2 * Math.PI;
var tx = 16 * Math.pow(Math.sin(t), 3);
var ty = 13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t), tz = 0;
var tx = 16 * Math.pow( Math.sin( t ), 3 );
var ty = 13 * Math.cos( t ) - 5 * Math.cos( 2 * t ) - 2 * Math.cos( 3 * t ) - Math.cos( 4 * t ), tz = 0;
return new THREE.Vector3(tx, ty, tz).multiplyScalar(this.scale);
return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
}
......@@ -53,20 +55,21 @@ function(t) {
// Viviani's Curve
THREE.Curves.VivianiCurve = THREE.Curve.create(
function(radius) {
function( radius ) {
this.radius = radius;
},
function(t) {
function( t ) {
t = t * 4 * Math.PI; // Normalized to 0..1
var a = this.radius / 2;
var tx = a * (1 + Math.cos(t)),
ty = a * Math.sin(t),
tz = 2 * a * Math.sin(t / 2);
var tx = a * ( 1 + Math.cos( t ) ),
ty = a * Math.sin( t ),
tz = 2 * a * Math.sin( t / 2 );
return new THREE.Vector3(tx, ty, tz);
return new THREE.Vector3( tx, ty, tz );
}
......@@ -79,17 +82,17 @@ THREE.Curves.KnotCurve = THREE.Curve.create(
},
function(t) {
function( t ) {
t *= 2 * Math.PI;
var R = 10;
var s = 50;
var tx = s * Math.sin(t),
ty = Math.cos(t) * (R + s * Math.cos(t)),
tz = Math.sin(t) * (R + s * Math.cos(t));
var tx = s * Math.sin( t ),
ty = Math.cos( t ) * ( R + s * Math.cos( t ) ),
tz = Math.sin( t ) * ( R + s * Math.cos( t ) );
return new THREE.Vector3(tx, ty, tz);
return new THREE.Vector3( tx, ty, tz );
}
......@@ -101,16 +104,16 @@ THREE.Curves.HelixCurve = THREE.Curve.create(
},
function(t) {
function( t ) {
var a = 30; // radius
var b = 150; //height
var t2 = 2 * Math.PI * t * b / 30;
var tx = Math.cos(t2) * a,
ty = Math.sin(t2) * a,
var tx = Math.cos( t2 ) * a,
ty = Math.sin( t2 ) * a,
tz = b * t;
return new THREE.Vector3(tx, ty, tz);
return new THREE.Vector3( tx, ty, tz );
}
......@@ -118,20 +121,20 @@ THREE.Curves.HelixCurve = THREE.Curve.create(
THREE.Curves.TrefoilKnot = THREE.Curve.create(
function(s) {
function( s ) {
this.scale = (s === undefined) ? 10 : s;
this.scale = ( s === undefined ) ? 10 : s;
},
function(t) {
function( t ) {
t *= Math.PI * 2;
var tx = (2 + Math.cos(3 * t)) * Math.cos(2 * t),
ty = (2 + Math.cos(3 * t)) * Math.sin(2 * t),
tz = Math.sin(3 * t);
var tx = ( 2 + Math.cos( 3 * t ) ) * Math.cos( 2 * t ),
ty = ( 2 + Math.cos( 3 * t ) ) * Math.sin( 2 * t ),
tz = Math.sin( 3 * t );
return new THREE.Vector3(tx, ty, tz).multiplyScalar(this.scale);
return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
}
......@@ -139,22 +142,22 @@ THREE.Curves.TrefoilKnot = THREE.Curve.create(
THREE.Curves.TorusKnot = THREE.Curve.create(
function(s) {
function( s ) {
this.scale = (s === undefined) ? 10 : s;
this.scale = ( s === undefined ) ? 10 : s;
},
function(t) {
function( t ) {
var p = 3,
q = 4;
t *= Math.PI * 2;
var tx = (2 + Math.cos(q * t)) * Math.cos(p * t),
ty = (2 + Math.cos(q * t)) * Math.sin(p * t),
tz = Math.sin(q * t);
var tx = ( 2 + Math.cos( q * t ) ) * Math.cos( p * t ),
ty = ( 2 + Math.cos( q * t ) ) * Math.sin( p * t ),
tz = Math.sin( q * t );
return new THREE.Vector3(tx, ty, tz).multiplyScalar(this.scale);
return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
}
......@@ -163,22 +166,22 @@ THREE.Curves.TorusKnot = THREE.Curve.create(
THREE.Curves.CinquefoilKnot = THREE.Curve.create(
function(s) {
function( s ) {
this.scale = (s === undefined) ? 10 : s;
this.scale = ( s === undefined ) ? 10 : s;
},
function(t) {
function( t ) {
var p = 2,
q = 5;
t *= Math.PI * 2;
var tx = (2 + Math.cos(q * t)) * Math.cos(p * t),
ty = (2 + Math.cos(q * t)) * Math.sin(p * t),
tz = Math.sin(q * t);
var tx = ( 2 + Math.cos( q * t ) ) * Math.cos( p * t ),
ty = ( 2 + Math.cos( q * t ) ) * Math.sin( p * t ),
tz = Math.sin( q * t );
return new THREE.Vector3(tx, ty, tz).multiplyScalar(this.scale);
return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
}
......@@ -187,20 +190,20 @@ THREE.Curves.CinquefoilKnot = THREE.Curve.create(
THREE.Curves.TrefoilPolynomialKnot = THREE.Curve.create(
function(s) {
function( s ) {
this.scale = (s === undefined) ? 10 : s;
this.scale = ( s === undefined ) ? 10 : s;
},
function(t) {
function( t ) {
t = t * 4 - 2;
var tx = Math.pow(t, 3) - 3 * t,
ty = Math.pow(t, 4) - 4 * t * t,
tz = 1 / 5 * Math.pow(t, 5) - 2 * t;
var tx = Math.pow( t, 3 ) - 3 * t,
ty = Math.pow( t, 4 ) - 4 * t * t,
tz = 1 / 5 * Math.pow( t, 5 ) - 2 * t;
return new THREE.Vector3(tx, ty, tz).multiplyScalar(this.scale);
return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
}
......@@ -212,7 +215,7 @@ THREE.Curves.TrefoilPolynomialKnot = THREE.Curve.create(
// t * r + x;
// };
// }
var scaleTo = function(x, y, t) {
var scaleTo = function( x, y, t ) {
var r = y - x;
return t * r + x;
......@@ -221,20 +224,20 @@ var scaleTo = function(x, y, t) {
THREE.Curves.FigureEightPolynomialKnot = THREE.Curve.create(
function(s) {
function( s ) {
this.scale = (s === undefined) ? 1 : s;
this.scale = ( s === undefined ) ? 1 : s;
},
function(t) {
function( t ) {
t = scaleTo(-4, 4, t);
var tx = 2 / 5 * t * (t * t - 7) * (t * t - 10),
ty = Math.pow(t, 4) - 13 * t * t,
tz = 1 / 10 * t * (t * t - 4) * (t * t - 9) * (t * t - 12);
t = scaleTo( - 4, 4, t );
var tx = 2 / 5 * t * ( t * t - 7 ) * ( t * t - 10 ),
ty = Math.pow( t, 4 ) - 13 * t * t,
tz = 1 / 10 * t * ( t * t - 4 ) * ( t * t - 9 ) * ( t * t - 12 );
return new THREE.Vector3(tx, ty, tz).multiplyScalar(this.scale);
return new THREE.Vector3( tx, ty, tz ).multiplyScalar( this.scale );
}
......@@ -242,21 +245,21 @@ THREE.Curves.FigureEightPolynomialKnot = THREE.Curve.create(
THREE.Curves.DecoratedTorusKnot4a = THREE.Curve.create(
function(s) {
function( s ) {
this.scale = (s === undefined) ? 40 : s;
this.scale = ( s === undefined ) ? 40 : s;
},
function(t) {
function( t ) {
t *= Math.PI * 2;
var
x = Math.cos(2 * t) * (1 + 0.6 * (Math.cos(5 * t) + 0.75 * Math.cos(10 * t))),
y = Math.sin(2 * t) * (1 + 0.6 * (Math.cos(5 * t) + 0.75 * Math.cos(10 * t))),
z = 0.35 * Math.sin(5 * t);
x = Math.cos( 2 * t ) * ( 1 + 0.6 * ( Math.cos( 5 * t ) + 0.75 * Math.cos( 10 * t ) ) ),
y = Math.sin( 2 * t ) * ( 1 + 0.6 * ( Math.cos( 5 * t ) + 0.75 * Math.cos( 10 * t ) ) ),
z = 0.35 * Math.sin( 5 * t );
return new THREE.Vector3(x, y, z).multiplyScalar(this.scale);
return new THREE.Vector3( x, y, z ).multiplyScalar( this.scale );
}
......@@ -265,19 +268,20 @@ THREE.Curves.DecoratedTorusKnot4a = THREE.Curve.create(
THREE.Curves.DecoratedTorusKnot4b = THREE.Curve.create(
function(s) {
function( s ) {
this.scale = (s === undefined) ? 40 : s;
this.scale = ( s === undefined ) ? 40 : s;
},
function(t) {
function( t ) {
var fi = t * Math.PI * 2;
var x = Math.cos(2 * fi) * (1 + 0.45 * Math.cos(3 * fi) + 0.4 * Math.cos(9 * fi)),
y = Math.sin(2 * fi) * (1 + 0.45 * Math.cos(3 * fi) + 0.4 * Math.cos(9 * fi)),
z = 0.2 * Math.sin(9 * fi);
var x = Math.cos( 2 * fi ) * ( 1 + 0.45 * Math.cos( 3 * fi ) + 0.4 * Math.cos( 9 * fi ) ),
y = Math.sin( 2 * fi ) * ( 1 + 0.45 * Math.cos( 3 * fi ) + 0.4 * Math.cos( 9 * fi ) ),
z = 0.2 * Math.sin( 9 * fi );
return new THREE.Vector3(x, y, z).multiplyScalar(this.scale);
return new THREE.Vector3( x, y, z ).multiplyScalar( this.scale );
}
......@@ -286,20 +290,20 @@ THREE.Curves.DecoratedTorusKnot4b = THREE.Curve.create(
THREE.Curves.DecoratedTorusKnot5a = THREE.Curve.create(
function(s) {
function( s ) {
this.scale = (s === undefined) ? 40 : s;
this.scale = ( s === undefined ) ? 40 : s;
},
function(t) {
function( t ) {
var fi = t * Math.PI * 2;
var x = Math.cos(3 * fi) * (1 + 0.3 * Math.cos(5 * fi) + 0.5 * Math.cos(10 * fi)),
y = Math.sin(3 * fi) * (1 + 0.3 * Math.cos(5 * fi) + 0.5 * Math.cos(10 * fi)),
z = 0.2 * Math.sin(20 * fi);
var x = Math.cos( 3 * fi ) * ( 1 + 0.3 * Math.cos( 5 * fi ) + 0.5 * Math.cos( 10 * fi ) ),
y = Math.sin( 3 * fi ) * ( 1 + 0.3 * Math.cos( 5 * fi ) + 0.5 * Math.cos( 10 * fi ) ),
z = 0.2 * Math.sin( 20 * fi );
return new THREE.Vector3(x, y, z).multiplyScalar(this.scale);
return new THREE.Vector3( x, y, z ).multiplyScalar( this.scale );
}
......@@ -307,21 +311,21 @@ THREE.Curves.DecoratedTorusKnot5a = THREE.Curve.create(
THREE.Curves.DecoratedTorusKnot5c = THREE.Curve.create(
function(s) {
function( s ) {
this.scale = (s === undefined) ? 40 : s;
this.scale = ( s === undefined ) ? 40 : s;
},
function(t) {
function( t ) {
var fi = t * Math.PI * 2;
var x = Math.cos(4 * fi) * (1 + 0.5 * (Math.cos(5 * fi) + 0.4 * Math.cos(20 * fi))),
y = Math.sin(4 * fi) * (1 + 0.5 * (Math.cos(5 * fi) + 0.4 * Math.cos(20 * fi))),
z = 0.35 * Math.sin(15 * fi);
var x = Math.cos( 4 * fi ) * ( 1 + 0.5 * ( Math.cos( 5 * fi ) + 0.4 * Math.cos( 20 * fi ) ) ),
y = Math.sin( 4 * fi ) * ( 1 + 0.5 * ( Math.cos( 5 * fi ) + 0.4 * Math.cos( 20 * fi ) ) ),
z = 0.35 * Math.sin( 15 * fi );
return new THREE.Vector3(x, y, z).multiplyScalar(this.scale);
return new THREE.Vector3( x, y, z ).multiplyScalar( this.scale );
}
);
\ No newline at end of file
);
......@@ -6,7 +6,19 @@
var Detector = {
canvas: !! window.CanvasRenderingContext2D,
webgl: ( function () { try { var canvas = document.createElement( 'canvas' ); return !! ( window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ) ); } catch ( e ) { return false; } } )(),
webgl: ( function () {
try {
var canvas = document.createElement( 'canvas' ); return !! ( window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ) );
} catch ( e ) {
return false;
}
} )(),
workers: !! window.Worker,
fileapi: window.File && window.FileReader && window.FileList && window.Blob,
......
......@@ -209,7 +209,7 @@ THREE.MD2Character = function () {
//
var mesh = new THREE.MorphAnimMesh( geometry, materialTexture );
mesh.rotation.y = -Math.PI / 2;
mesh.rotation.y = - Math.PI / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
......
......@@ -16,7 +16,7 @@ THREE.MD2CharacterComplex = function () {
// movement model parameters
this.maxSpeed = 275;
this.maxReverseSpeed = -275;
this.maxReverseSpeed = - 275;
this.frontAcceleration = 600;
this.backAcceleration = 600;
......@@ -261,7 +261,7 @@ THREE.MD2CharacterComplex = function () {
this.setAnimation = function ( animationName ) {
if ( animationName === this.activeAnimation || !animationName ) return;
if ( animationName === this.activeAnimation || ! animationName ) return;
if ( this.meshBody ) {
......@@ -388,7 +388,7 @@ THREE.MD2CharacterComplex = function () {
}
if ( Math.abs( this.speed ) < 0.2 * this.maxSpeed && !( controls.moveLeft || controls.moveRight || controls.moveForward || controls.moveBackward ) ) {
if ( Math.abs( this.speed ) < 0.2 * this.maxSpeed && ! ( controls.moveLeft || controls.moveRight || controls.moveForward || controls.moveBackward ) ) {
if ( this.activeAnimation !== idleAnimation ) {
......@@ -447,7 +447,7 @@ THREE.MD2CharacterComplex = function () {
if ( controls.crouch ) this.maxSpeed = this.crouchSpeed;
else this.maxSpeed = this.walkSpeed;
this.maxReverseSpeed = -this.maxSpeed;
this.maxReverseSpeed = - this.maxSpeed;
if ( controls.moveForward ) this.speed = THREE.Math.clamp( this.speed + delta * this.frontAcceleration, this.maxReverseSpeed, this.maxSpeed );
if ( controls.moveBackward ) this.speed = THREE.Math.clamp( this.speed - delta * this.backAcceleration, this.maxReverseSpeed, this.maxSpeed );
......@@ -532,7 +532,7 @@ THREE.MD2CharacterComplex = function () {
//
var mesh = new THREE.MorphBlendMesh( geometry, materialTexture );
mesh.rotation.y = -Math.PI / 2;
mesh.rotation.y = - Math.PI / 2;
//
......@@ -554,6 +554,10 @@ THREE.MD2CharacterComplex = function () {
}
function exponentialEaseOut( k ) { return k === 1 ? 1 : - Math.pow( 2, - 10 * k ) + 1; }
function exponentialEaseOut( k ) {
return k === 1 ? 1 : - Math.pow( 2, - 10 * k ) + 1;
}
};
此差异已折叠。
......@@ -2,9 +2,9 @@
* @author Slayvin / http://slayvin.net
*/
THREE.ShaderLib['mirror'] = {
THREE.ShaderLib[ 'mirror' ] = {
uniforms: { "mirrorColor": { type: "c", value: new THREE.Color(0x7F7F7F) },
uniforms: { "mirrorColor": { type: "c", value: new THREE.Color( 0x7F7F7F ) },
"mirrorSampler": { type: "t", value: null },
"textureMatrix" : { type: "m4", value: new THREE.Matrix4() }
},
......@@ -25,7 +25,7 @@ THREE.ShaderLib['mirror'] = {
"}"
].join("\n"),
].join( "\n" ),
fragmentShader: [
......@@ -47,7 +47,7 @@ THREE.ShaderLib['mirror'] = {
"}"
].join("\n")
].join( "\n" )
};
......@@ -66,7 +66,7 @@ THREE.Mirror = function ( renderer, camera, options ) {
this.clipBias = options.clipBias !== undefined ? options.clipBias : 0.0;
var mirrorColor = options.color !== undefined ? new THREE.Color(options.color) : new THREE.Color(0x7F7F7F);
var mirrorColor = options.color !== undefined ? new THREE.Color( options.color ) : new THREE.Color( 0x7F7F7F );
this.renderer = renderer;
this.mirrorPlane = new THREE.Plane();
......@@ -74,7 +74,7 @@ THREE.Mirror = function ( renderer, camera, options ) {
this.mirrorWorldPosition = new THREE.Vector3();
this.cameraWorldPosition = new THREE.Vector3();
this.rotationMatrix = new THREE.Matrix4();
this.lookAtPosition = new THREE.Vector3(0, 0, -1);
this.lookAtPosition = new THREE.Vector3( 0, 0, - 1 );
this.clipPlane = new THREE.Vector4();
// For debug only, show the normal and plane of the mirror
......@@ -82,17 +82,17 @@ THREE.Mirror = function ( renderer, camera, options ) {
if ( debugMode ) {
var arrow = new THREE.ArrowHelper(new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, 0 ), 10, 0xffff80 );
var arrow = new THREE.ArrowHelper( new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, 0 ), 10, 0xffff80 );
var planeGeometry = new THREE.Geometry();
planeGeometry.vertices.push( new THREE.Vector3( -10, -10, 0 ) );
planeGeometry.vertices.push( new THREE.Vector3( 10, -10, 0 ) );
planeGeometry.vertices.push( new THREE.Vector3( - 10, - 10, 0 ) );
planeGeometry.vertices.push( new THREE.Vector3( 10, - 10, 0 ) );
planeGeometry.vertices.push( new THREE.Vector3( 10, 10, 0 ) );
planeGeometry.vertices.push( new THREE.Vector3( -10, 10, 0 ) );
planeGeometry.vertices.push( planeGeometry.vertices[0] );
planeGeometry.vertices.push( new THREE.Vector3( - 10, 10, 0 ) );
planeGeometry.vertices.push( planeGeometry.vertices[ 0 ] );
var plane = new THREE.Line( planeGeometry, new THREE.LineBasicMaterial( { color: 0xffff80 } ) );
this.add(arrow);
this.add(plane);
this.add( arrow );
this.add( plane );
}
......@@ -132,7 +132,7 @@ THREE.Mirror = function ( renderer, camera, options ) {
this.material.uniforms.mirrorColor.value = mirrorColor;
this.material.uniforms.textureMatrix.value = this.textureMatrix;
if ( !THREE.Math.isPowerOfTwo(width) || !THREE.Math.isPowerOfTwo( height ) ) {
if ( ! THREE.Math.isPowerOfTwo( width ) || ! THREE.Math.isPowerOfTwo( height ) ) {
this.texture.generateMipmaps = false;
this.tempTexture.generateMipmaps = false;
......@@ -171,6 +171,7 @@ THREE.Mirror.prototype.renderWithMirror = function ( otherMirror ) {
// restore texture matrix of other mirror
otherMirror.updateTextureMatrix();
};
THREE.Mirror.prototype.updateTextureMatrix = function () {
......@@ -192,7 +193,7 @@ THREE.Mirror.prototype.updateTextureMatrix = function () {
this.rotationMatrix.extractRotation( this.camera.matrixWorld );
this.lookAtPosition.set(0, 0, -1);
this.lookAtPosition.set( 0, 0, - 1 );
this.lookAtPosition.applyMatrix4( this.rotationMatrix );
this.lookAtPosition.add( this.cameraWorldPosition );
......@@ -200,7 +201,7 @@ THREE.Mirror.prototype.updateTextureMatrix = function () {
target.reflect( this.normal ).negate();
target.add( this.mirrorWorldPosition );
this.up.set( 0, -1, 0 );
this.up.set( 0, - 1, 0 );
this.up.applyMatrix4( this.rotationMatrix );
this.up.reflect( this.normal ).negate();
......@@ -230,20 +231,20 @@ THREE.Mirror.prototype.updateTextureMatrix = function () {
var q = new THREE.Vector4();
var projectionMatrix = this.mirrorCamera.projectionMatrix;
q.x = ( Math.sign(this.clipPlane.x) + projectionMatrix.elements[8] ) / projectionMatrix.elements[0];
q.y = ( Math.sign(this.clipPlane.y) + projectionMatrix.elements[9] ) / projectionMatrix.elements[5];
q.x = ( Math.sign( this.clipPlane.x ) + projectionMatrix.elements[ 8 ] ) / projectionMatrix.elements[ 0 ];
q.y = ( Math.sign( this.clipPlane.y ) + projectionMatrix.elements[ 9 ] ) / projectionMatrix.elements[ 5 ];
q.z = - 1.0;
q.w = ( 1.0 + projectionMatrix.elements[10] ) / projectionMatrix.elements[14];
q.w = ( 1.0 + projectionMatrix.elements[ 10 ] ) / projectionMatrix.elements[ 14 ];
// Calculate the scaled plane vector
var c = new THREE.Vector4();
c = this.clipPlane.multiplyScalar( 2.0 / this.clipPlane.dot(q) );
c = this.clipPlane.multiplyScalar( 2.0 / this.clipPlane.dot( q ) );
// Replacing the third row of the projection matrix
projectionMatrix.elements[2] = c.x;
projectionMatrix.elements[6] = c.y;
projectionMatrix.elements[10] = c.z + 1.0 - this.clipBias;
projectionMatrix.elements[14] = c.w;
projectionMatrix.elements[ 2 ] = c.x;
projectionMatrix.elements[ 6 ] = c.y;
projectionMatrix.elements[ 10 ] = c.z + 1.0 - this.clipBias;
projectionMatrix.elements[ 14 ] = c.w;
};
......@@ -262,7 +263,7 @@ THREE.Mirror.prototype.render = function () {
}
if ( scene !== undefined && scene instanceof THREE.Scene) {
if ( scene !== undefined && scene instanceof THREE.Scene ) {
// We can't render ourself to ourself
var visible = this.material.visible;
......@@ -291,7 +292,7 @@ THREE.Mirror.prototype.renderTemp = function () {
}
if ( scene !== undefined && scene instanceof THREE.Scene) {
if ( scene !== undefined && scene instanceof THREE.Scene ) {
this.renderer.render( scene, this.mirrorCamera, this.tempTexture, true );
......
此差异已折叠。
......@@ -7,7 +7,9 @@
* based on Dynamic Octree by Piko3D @ http://www.piko3d.com/ and Octree by Marek Pawlowski @ pawlowski.it
*
*/
( function ( THREE ) { "use strict";
( function ( THREE ) {
"use strict";
/*===================================================
......@@ -16,15 +18,21 @@
=====================================================*/
function isNumber ( n ) {
return !isNaN( n ) && isFinite( n );
return ! isNaN( n ) && isFinite( n );
}
function isArray ( target ) {
return Object.prototype.toString.call( target ) === '[object Array]';
}
function toArray ( target ) {
return target ? ( isArray ( target ) !== true ? [ target ] : target ) : [];
}
function indexOfValue( array, value ) {
......@@ -39,7 +47,7 @@
}
return -1;
return - 1;
}
......@@ -55,7 +63,7 @@
}
return -1;
return - 1;
}
......@@ -77,7 +85,7 @@
this.nodeCount = 0;
this.INDEX_INSIDE_CROSS = -1;
this.INDEX_INSIDE_CROSS = - 1;
this.INDEX_OUTSIDE_OFFSET = 2;
this.INDEX_OUTSIDE_POS_X = isNumber( parameters.INDEX_OUTSIDE_POS_X ) ? parameters.INDEX_OUTSIDE_POS_X : 0;
......@@ -89,11 +97,11 @@
this.INDEX_OUTSIDE_MAP = [];
this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_POS_X ] = { index: this.INDEX_OUTSIDE_POS_X, count: 0, x: 1, y: 0, z: 0 };
this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_X ] = { index: this.INDEX_OUTSIDE_NEG_X, count: 0, x: -1, y: 0, z: 0 };
this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_X ] = { index: this.INDEX_OUTSIDE_NEG_X, count: 0, x: - 1, y: 0, z: 0 };
this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_POS_Y ] = { index: this.INDEX_OUTSIDE_POS_Y, count: 0, x: 0, y: 1, z: 0 };
this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_Y ] = { index: this.INDEX_OUTSIDE_NEG_Y, count: 0, x: 0, y: -1, z: 0 };
this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_Y ] = { index: this.INDEX_OUTSIDE_NEG_Y, count: 0, x: 0, y: - 1, z: 0 };
this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_POS_Z ] = { index: this.INDEX_OUTSIDE_POS_Z, count: 0, x: 0, y: 0, z: 1 };
this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_Z ] = { index: this.INDEX_OUTSIDE_NEG_Z, count: 0, x: 0, y: 0, z: -1 };
this.INDEX_OUTSIDE_MAP[ this.INDEX_OUTSIDE_NEG_Z ] = { index: this.INDEX_OUTSIDE_NEG_Z, count: 0, x: 0, y: 0, z: - 1 };
this.FLAG_POS_X = 1 << ( this.INDEX_OUTSIDE_POS_X + 1 );
this.FLAG_NEG_X = 1 << ( this.INDEX_OUTSIDE_NEG_X + 1 );
......@@ -194,13 +202,13 @@
// check uuid to avoid duplicates
if ( !object.uuid ) {
if ( ! object.uuid ) {
object.uuid = THREE.Math.generateUUID();
}
if ( !this.objectsMap[ object.uuid ] ) {
if ( ! this.objectsMap[ object.uuid ] ) {
// store
......@@ -287,7 +295,7 @@
index = indexOfValue( this.objects, object );
if ( index !== -1 ) {
if ( index !== - 1 ) {
this.objects.splice( index, 1 );
......@@ -303,7 +311,7 @@
index = indexOfValue( this.objectsData, objectData );
if ( index !== -1 ) {
if ( index !== - 1 ) {
this.objectsData.splice( index, 1 );
......@@ -319,7 +327,7 @@
index = indexOfPropertyWithValue( this.objectsDeferred, 'object', object );
if ( index !== -1 ) {
if ( index !== - 1 ) {
this.objectsDeferred.splice( index, 1 );
......@@ -378,7 +386,7 @@
// if position has changed since last organization of object in tree
if ( node instanceof THREE.OctreeNode && !objectData.positionLast.equals( objectData.position ) ) {
if ( node instanceof THREE.OctreeNode && ! objectData.positionLast.equals( objectData.position ) ) {
// get octant index of object within current node
......@@ -477,7 +485,7 @@
// ensure radius (i.e. distance of ray) is a number
if ( !( radius > 0 ) ) {
if ( ! ( radius > 0 ) ) {
radius = Number.MAX_VALUE;
......@@ -520,7 +528,7 @@
// if needed, create new result data
if ( resultObjectIndex === -1 ) {
if ( resultObjectIndex === - 1 ) {
resultData = {
object: object,
......@@ -860,7 +868,7 @@
node.indexOctant = indexOctant;
if ( indexOfValue( this.nodesIndices, indexOctant ) === -1 ) {
if ( indexOfValue( this.nodesIndices, indexOctant ) === - 1 ) {
this.nodesIndices.push( indexOctant );
......@@ -908,13 +916,13 @@
indexOctant = this.getOctantIndex( object );
// if object fully contained by an octant, add to subtree
if ( indexOctant > -1 && this.nodesIndices.length > 0 ) {
if ( indexOctant > - 1 && this.nodesIndices.length > 0 ) {
node = this.branch( indexOctant );
node.addObject( object );
} else if ( indexOctant < -1 && this.parent instanceof THREE.OctreeNode ) {
} else if ( indexOctant < - 1 && this.parent instanceof THREE.OctreeNode ) {
// if object lies outside bounds, add to parent node
......@@ -926,7 +934,7 @@
index = indexOfValue( this.objects, object );
if ( index === -1 ) {
if ( index === - 1 ) {
this.objects.push( object );
......@@ -992,7 +1000,7 @@
removeObjectRecursive: function ( object, removeData ) {
var i, l,
index = -1,
index = - 1,
objectData,
node,
objectRemoved;
......@@ -1006,7 +1014,7 @@
index = indexOfValue( this.objects, object );
if ( index !== -1 ) {
if ( index !== - 1 ) {
this.objects.splice( index, 1 );
object.node = undefined;
......@@ -1034,7 +1042,7 @@
objectRemoved = true;
if ( !objectData.faces && !objectData.vertices ) {
if ( ! objectData.faces && ! objectData.vertices ) {
removeData.searchComplete = true;
break;
......@@ -1115,12 +1123,12 @@
indexOctant = this.getOctantIndex( object );
// if lies within octant
if ( indexOctant > -1 ) {
if ( indexOctant > - 1 ) {
objectsSplit.push( object );
objectsSplitOctants.push( indexOctant );
} else if ( indexOctant < -1 ) {
} else if ( indexOctant < - 1 ) {
// lies outside radius
......@@ -1139,7 +1147,7 @@
// if has objects to split
if ( objectsSplit.length > 0) {
if ( objectsSplit.length > 0 ) {
objectsRemaining = objectsRemaining.concat( this.split( objectsSplit, objectsSplitOctants ) );
......@@ -1147,7 +1155,7 @@
// if has objects to expand
if ( objectsExpand.length > 0) {
if ( objectsExpand.length > 0 ) {
objectsRemaining = objectsRemaining.concat( this.expand( objectsExpand, objectsExpandOctants ) );
......@@ -1193,7 +1201,7 @@
// if object contained by octant, branch this tree
if ( indexOctant > -1 ) {
if ( indexOctant > - 1 ) {
node = this.branch( indexOctant );
......@@ -1247,7 +1255,7 @@
radius = ( this.radiusOverlap ) * 0.5;
overlap = radius * this.tree.overlapPct;
radiusOffset = radius - overlap;
offset = this.utilVec31Branch.set( indexOctant & 1 ? radiusOffset : -radiusOffset, indexOctant & 2 ? radiusOffset : -radiusOffset, indexOctant & 4 ? radiusOffset : -radiusOffset );
offset = this.utilVec31Branch.set( indexOctant & 1 ? radiusOffset : - radiusOffset, indexOctant & 2 ? radiusOffset : - radiusOffset, indexOctant & 4 ? radiusOffset : - radiusOffset );
position = new THREE.Vector3().addVectors( this.position, offset );
// node
......@@ -1332,11 +1340,11 @@
// if object outside this, include in calculations
if ( indexOctant < -1 ) {
if ( indexOctant < - 1 ) {
// convert octant index to outside flags
flagsOutside = -indexOctant - this.tree.INDEX_OUTSIDE_OFFSET;
flagsOutside = - indexOctant - this.tree.INDEX_OUTSIDE_OFFSET;
// check against bitwise flags
......@@ -1438,7 +1446,7 @@
// get this octant indices based on octant normal
indexOctant = this.getOctantIndexFromPosition( octantX, octantY, octantZ );
indexOctantInverse = this.getOctantIndexFromPosition( -octantX, -octantY, -octantZ );
indexOctantInverse = this.getOctantIndexFromPosition( - octantX, - octantY, - octantZ );
// properties
......@@ -1453,7 +1461,7 @@
// parent offset is difference between radius + overlap of parent and child
radiusOffset = ( radiusParent + overlapParent ) - ( radius + overlap );
offset.set( indexOctant & 1 ? radiusOffset : -radiusOffset, indexOctant & 2 ? radiusOffset : -radiusOffset, indexOctant & 4 ? radiusOffset : -radiusOffset );
offset.set( indexOctant & 1 ? radiusOffset : - radiusOffset, indexOctant & 2 ? radiusOffset : - radiusOffset, indexOctant & 4 ? radiusOffset : - radiusOffset );
position = new THREE.Vector3().addVectors( this.position, offset );
// parent
......@@ -1735,7 +1743,7 @@
}
objectData.indexOctant = -indexOctant - this.tree.INDEX_OUTSIDE_OFFSET;
objectData.indexOctant = - indexOctant - this.tree.INDEX_OUTSIDE_OFFSET;
return objectData.indexOctant;
......@@ -1743,13 +1751,13 @@
// return octant index from delta xyz
if ( deltaX - radiusObj > -overlap ) {
if ( deltaX - radiusObj > - overlap ) {
// x right
indexOctant = indexOctant | 1;
} else if ( !( deltaX + radiusObj < overlap ) ) {
} else if ( ! ( deltaX + radiusObj < overlap ) ) {
// x left
......@@ -1758,13 +1766,13 @@
}
if ( deltaY - radiusObj > -overlap ) {
if ( deltaY - radiusObj > - overlap ) {
// y right
indexOctant = indexOctant | 2;
} else if ( !( deltaY + radiusObj < overlap ) ) {
} else if ( ! ( deltaY + radiusObj < overlap ) ) {
// y left
......@@ -1774,13 +1782,13 @@
}
if ( deltaZ - radiusObj > -overlap ) {
if ( deltaZ - radiusObj > - overlap ) {
// z right
indexOctant = indexOctant | 4;
} else if ( !( deltaZ + radiusObj < overlap ) ) {
} else if ( ! ( deltaZ + radiusObj < overlap ) ) {
// z left
......@@ -1870,21 +1878,33 @@
pz = position.z;
if ( px < this.left ) {
distance -= Math.pow( px - this.left, 2 );
} else if ( px > this.right ) {
distance -= Math.pow( px - this.right, 2 );
}
if ( py < this.bottom ) {
distance -= Math.pow( py - this.bottom, 2 );
} else if ( py > this.top ) {
distance -= Math.pow( py - this.top, 2 );
}
if ( pz < this.back ) {
distance -= Math.pow( pz - this.back, 2 );
} else if ( pz > this.front ) {
distance -= Math.pow( pz - this.front, 2 );
}
return distance >= 0;
......@@ -1905,20 +1925,23 @@
t4 = ( this.top - origin.y ) * directionPct.y,
t5 = ( this.back - origin.z ) * directionPct.z,
t6 = ( this.front - origin.z ) * directionPct.z,
tmax = Math.min( Math.min( Math.max( t1, t2), Math.max( t3, t4) ), Math.max( t5, t6) ),
tmax = Math.min( Math.min( Math.max( t1, t2 ), Math.max( t3, t4 ) ), Math.max( t5, t6 ) ),
tmin;
// ray would intersect in reverse direction, i.e. this is behind ray
if (tmax < 0)
{
if ( tmax < 0 ) {
return false;
}
tmin = Math.max( Math.max( Math.min( t1, t2), Math.min( t3, t4)), Math.min( t5, t6));
tmin = Math.max( Math.max( Math.min( t1, t2 ), Math.min( t3, t4 ) ), Math.min( t5, t6 ) );
// if tmin > tmax or tmin > ray distance, ray doesn't intersect AABB
if ( tmin > tmax || tmin > distance ) {
return false;
}
return true;
......@@ -1942,7 +1965,7 @@
} else {
depth = !depth || this.depth > depth ? this.depth : depth;
depth = ! depth || this.depth > depth ? this.depth : depth;
}
......@@ -2111,4 +2134,4 @@
};
}( THREE ) );
\ No newline at end of file
}( THREE ) );
......@@ -4,8 +4,20 @@
var PRNG = function () {
this.seed = 1;
this.next = function() { return (this.gen() / 2147483647); };
this.nextRange = function(min, max) { return min + ((max - min) * this.next()) };
this.gen = function() { return this.seed = (this.seed * 16807) % 2147483647; };
this.next = function() {
return ( this.gen() / 2147483647 );
};
this.nextRange = function( min, max ) {
return min + ( ( max - min ) * this.next() )
};
this.gen = function() {
return this.seed = ( this.seed * 16807 ) % 2147483647;
};
};
......@@ -8,37 +8,46 @@
THREE.ParametricGeometries = {
klein: function (v, u) {
klein: function ( v, u ) {
u *= Math.PI;
v *= 2 * Math.PI;
u = u * 2;
var x, y, z;
if (u < Math.PI) {
x = 3 * Math.cos(u) * (1 + Math.sin(u)) + (2 * (1 - Math.cos(u) / 2)) * Math.cos(u) * Math.cos(v);
z = -8 * Math.sin(u) - 2 * (1 - Math.cos(u) / 2) * Math.sin(u) * Math.cos(v);
if ( u < Math.PI ) {
x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( u ) * Math.cos( v );
z = - 8 * Math.sin( u ) - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( u ) * Math.cos( v );
} else {
x = 3 * Math.cos(u) * (1 + Math.sin(u)) + (2 * (1 - Math.cos(u) / 2)) * Math.cos(v + Math.PI);
z = -8 * Math.sin(u);
x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( v + Math.PI );
z = - 8 * Math.sin( u );
}
y = -2 * (1 - Math.cos(u) / 2) * Math.sin(v);
y = - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( v );
return new THREE.Vector3( x, y, z );
return new THREE.Vector3(x, y, z);
},
plane: function (width, height) {
plane: function ( width, height ) {
return function( u, v ) {
return function(u, v) {
var x = u * width;
var y = 0;
var z = v * height;
return new THREE.Vector3(x, y, z);
return new THREE.Vector3( x, y, z );
};
},
mobius: function(u, t) {
mobius: function( u, t ) {
// flat mobius strip
// http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
......@@ -48,14 +57,14 @@ THREE.ParametricGeometries = {
var x, y, z;
var a = 2;
x = Math.cos(v) * (a + u * Math.cos(v / 2));
y = Math.sin(v) * (a + u * Math.cos(v / 2));
z = u * Math.sin(v / 2);
return new THREE.Vector3(x, y, z);
x = Math.cos( v ) * ( a + u * Math.cos( v / 2 ) );
y = Math.sin( v ) * ( a + u * Math.cos( v / 2 ) );
z = u * Math.sin( v / 2 );
return new THREE.Vector3( x, y, z );
},
mobius3d: function(u, t) {
mobius3d: function( u, t ) {
// volumetric mobius strip
u *= Math.PI;
......@@ -65,11 +74,12 @@ THREE.ParametricGeometries = {
var phi = u / 2;
var major = 2.25, a = 0.125, b = 0.65;
var x, y, z;
x = a * Math.cos(t) * Math.cos(phi) - b * Math.sin(t) * Math.sin(phi);
z = a * Math.cos(t) * Math.sin(phi) + b * Math.sin(t) * Math.cos(phi);
y = (major + x) * Math.sin(u);
x = (major + x) * Math.cos(u);
return new THREE.Vector3(x, y, z);
x = a * Math.cos( t ) * Math.cos( phi ) - b * Math.sin( t ) * Math.sin( phi );
z = a * Math.cos( t ) * Math.sin( phi ) + b * Math.sin( t ) * Math.cos( phi );
y = ( major + x ) * Math.sin( u );
x = ( major + x ) * Math.cos( u );
return new THREE.Vector3( x, y, z );
}
};
......@@ -81,14 +91,14 @@ THREE.ParametricGeometries = {
*
*********************************************/
THREE.ParametricGeometries.TubeGeometry = function(path, segments, radius, segmentsRadius, closed, debug) {
THREE.ParametricGeometries.TubeGeometry = function( path, segments, radius, segmentsRadius, closed, debug ) {
this.path = path;
this.segments = segments || 64;
this.radius = radius || 1;
this.segmentsRadius = segmentsRadius || 8;
this.closed = closed || false;
if (debug) this.debug = new THREE.Object3D();
if ( debug ) this.debug = new THREE.Object3D();
var scope = this,
......@@ -102,50 +112,52 @@ THREE.ParametricGeometries.TubeGeometry = function(path, segments, radius, segme
cx, cy, pos, pos2 = new THREE.Vector3(),
i, j, ip, jp, a, b, c, d, uva, uvb, uvc, uvd;
var frames = new THREE.TubeGeometry.FrenetFrames(path, segments, closed),
var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
tangents = frames.tangents,
normals = frames.normals,
binormals = frames.binormals;
// proxy internals
// proxy internals
this.tangents = tangents;
this.normals = normals;
this.binormals = binormals;
var ParametricTube = function(u, v) {
var ParametricTube = function( u, v ) {
v *= 2 * Math.PI;
i = u * (numpoints - 1);
i = Math.floor(i);
i = u * ( numpoints - 1 );
i = Math.floor( i );
pos = path.getPointAt(u);
pos = path.getPointAt( u );
tangent = tangents[i];
normal = normals[i];
binormal = binormals[i];
tangent = tangents[ i ];
normal = normals[ i ];
binormal = binormals[ i ];
if (scope.debug) {
if ( scope.debug ) {
scope.debug.add(new THREE.ArrowHelper(tangent, pos, radius, 0x0000ff));
scope.debug.add(new THREE.ArrowHelper(normal, pos, radius, 0xff0000));
scope.debug.add(new THREE.ArrowHelper(binormal, pos, radius, 0x00ff00));
scope.debug.add( new THREE.ArrowHelper( tangent, pos, radius, 0x0000ff ) );
scope.debug.add( new THREE.ArrowHelper( normal, pos, radius, 0xff0000 ) );
scope.debug.add( new THREE.ArrowHelper( binormal, pos, radius, 0x00ff00 ) );
}
cx = -scope.radius * Math.cos(v); // TODO: Hack: Negating it so it faces outside.
cy = scope.radius * Math.sin(v);
cx = - scope.radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
cy = scope.radius * Math.sin( v );
pos2.copy(pos);
pos2.copy( pos );
pos2.x += cx * normal.x + cy * binormal.x;
pos2.y += cx * normal.y + cy * binormal.y;
pos2.z += cx * normal.z + cy * binormal.z;
return pos2.clone();
};
THREE.ParametricGeometry.call(this, ParametricTube, segments, segmentsRadius);
THREE.ParametricGeometry.call( this, ParametricTube, segments, segmentsRadius );
};
......@@ -176,17 +188,17 @@ THREE.ParametricGeometries.TorusKnotGeometry = function ( radius, tube, segments
function() {
},
function(t) {
function( t ) {
t *= Math.PI * 2;
var r = 0.5;
var tx = (1 + r * Math.cos(q * t)) * Math.cos(p * t),
ty = (1 + r * Math.cos(q * t)) * Math.sin(p * t),
tz = r * Math.sin(q * t);
var tx = ( 1 + r * Math.cos( q * t ) ) * Math.cos( p * t ),
ty = ( 1 + r * Math.cos( q * t ) ) * Math.sin( p * t ),
tz = r * Math.sin( q * t );
return new THREE.Vector3(tx, ty * heightScale, tz).multiplyScalar(radius);
return new THREE.Vector3( tx, ty * heightScale, tz ).multiplyScalar( radius );
}
......@@ -209,21 +221,23 @@ THREE.ParametricGeometries.TorusKnotGeometry.prototype.constructor = THREE.Param
* Parametric Replacement for SphereGeometry
*
*********************************************/
THREE.ParametricGeometries.SphereGeometry = function(size, u, v) {
THREE.ParametricGeometries.SphereGeometry = function( size, u, v ) {
function sphere( u, v ) {
function sphere(u, v) {
u *= Math.PI;
v *= 2 * Math.PI;
var x = size * Math.sin(u) * Math.cos(v);
var y = size * Math.sin(u) * Math.sin(v);
var z = size * Math.cos(u);
var x = size * Math.sin( u ) * Math.cos( v );
var y = size * Math.sin( u ) * Math.sin( v );
var z = size * Math.cos( u );
return new THREE.Vector3( x, y, z );
return new THREE.Vector3(x, y, z);
}
THREE.ParametricGeometry.call(this, sphere, u, v, !true);
THREE.ParametricGeometry.call( this, sphere, u, v, ! true );
};
......@@ -237,18 +251,19 @@ THREE.ParametricGeometries.SphereGeometry.prototype.constructor = THREE.Parametr
*
*********************************************/
THREE.ParametricGeometries.PlaneGeometry = function(width, depth, segmentsWidth, segmentsDepth) {
THREE.ParametricGeometries.PlaneGeometry = function( width, depth, segmentsWidth, segmentsDepth ) {
function plane(u, v) {
function plane( u, v ) {
var x = u * width;
var y = 0;
var z = v * depth;
return new THREE.Vector3(x, y, z);
return new THREE.Vector3( x, y, z );
}
THREE.ParametricGeometry.call(this, plane, segmentsWidth, segmentsDepth);
THREE.ParametricGeometry.call( this, plane, segmentsWidth, segmentsDepth );
};
......
......@@ -23,7 +23,7 @@ THREE.DeferredShaderChunk = {
"}"
].join("\n"),
].join( "\n" ),
computeVertexPositionVS: [
......@@ -41,13 +41,13 @@ THREE.DeferredShaderChunk = {
"vertexPositionVS.xyz /= vertexPositionVS.w;",
"vertexPositionVS.w = 1.0;"
].join("\n"),
].join( "\n" ),
computeNormal: [
"vec3 normal = normalDepth.xyz * 2.0 - 1.0;"
].join("\n"),
].join( "\n" ),
unpackColorMap: [
......@@ -59,7 +59,7 @@ THREE.DeferredShaderChunk = {
"float wrapAround = sign( colorMap.z );",
"float additiveSpecular = sign( colorMap.y );"
].join("\n"),
].join( "\n" ),
computeDiffuse: [
......@@ -85,7 +85,7 @@ THREE.DeferredShaderChunk = {
"}"
].join("\n"),
].join( "\n" ),
computeSpecular: [
......@@ -103,14 +103,14 @@ THREE.DeferredShaderChunk = {
"vec3 schlick = specularColor + vec3( 1.0 - specularColor ) * pow( 1.0 - dot( lightVector, halfVector ), 5.0 );",
"vec3 specular = schlick * max( pow( dotNormalHalf, shininess ), 0.0 ) * diffuse * specularNormalization;"
].join("\n"),
].join( "\n" ),
combine: [
"vec3 light = lightIntensity * lightColor;",
"gl_FragColor = vec4( light * ( albedo * diffuse + specular ), attenuation );"
].join("\n")
].join( "\n" )
};
......@@ -305,7 +305,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n"),
].join( "\n" ),
vertexShader : [
......@@ -346,7 +346,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n")
].join( "\n" )
},
......@@ -391,7 +391,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n"),
].join( "\n" ),
vertexShader : [
......@@ -434,7 +434,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n")
].join( "\n" )
},
......@@ -528,7 +528,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n"),
].join( "\n" ),
vertexShader : [
......@@ -542,7 +542,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n")
].join( "\n" )
},
......@@ -556,7 +556,7 @@ THREE.ShaderDeferred = {
viewWidth: { type: "f", value: 800 },
viewHeight: { type: "f", value: 600 },
lightPositionVS:{ type: "v3", value: new THREE.Vector3( 0, 0, 0 ) },
lightPositionVS: { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) },
lightColor: { type: "c", value: new THREE.Color( 0x000000 ) },
lightIntensity: { type: "f", value: 1.0 },
lightRadius: { type: "f", value: 1.0 }
......@@ -614,7 +614,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n"),
].join( "\n" ),
vertexShader : [
......@@ -627,7 +627,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n")
].join( "\n" )
},
......@@ -641,8 +641,8 @@ THREE.ShaderDeferred = {
viewWidth: { type: "f", value: 800 },
viewHeight: { type: "f", value: 600 },
lightPositionVS :{ type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
lightDirectionVS:{ type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
lightPositionVS : { type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
lightDirectionVS: { type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
lightColor: { type: "c", value: new THREE.Color( 0x000000 ) },
lightIntensity: { type: "f", value: 1.0 },
lightDistance: { type: "f", value: 1.0 },
......@@ -718,7 +718,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n"),
].join( "\n" ),
vertexShader : [
......@@ -730,7 +730,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n")
].join( "\n" )
},
......@@ -788,7 +788,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n"),
].join( "\n" ),
vertexShader : [
......@@ -800,7 +800,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n")
].join( "\n" )
},
......@@ -886,7 +886,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n"),
].join( "\n" ),
vertexShader : [
......@@ -898,7 +898,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n")
].join( "\n" )
},
......@@ -913,7 +913,7 @@ THREE.ShaderDeferred = {
viewHeight: { type: "f", value: 600 },
lightPositionVS: { type: "v3", value: new THREE.Vector3( 0, 1, 0 ) },
lightNormalVS: { type: "v3", value: new THREE.Vector3( 0, -1, 0 ) },
lightNormalVS: { type: "v3", value: new THREE.Vector3( 0, - 1, 0 ) },
lightRightVS: { type: "v3", value: new THREE.Vector3( 1, 0, 0 ) },
lightUpVS: { type: "v3", value: new THREE.Vector3( 1, 0, 0 ) },
......@@ -1041,7 +1041,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n"),
].join( "\n" ),
vertexShader : [
......@@ -1053,7 +1053,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n")
].join( "\n" )
},
......@@ -1087,7 +1087,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n"),
].join( "\n" ),
vertexShader : [
......@@ -1099,7 +1099,7 @@ THREE.ShaderDeferred = {
"}"
].join("\n")
].join( "\n" )
}
......
......@@ -71,7 +71,7 @@ THREE.ShaderGodRays = {
"}"
].join("\n"),
].join( "\n" ),
fragmentShader: [
......@@ -157,7 +157,7 @@ THREE.ShaderGodRays = {
"}"
].join("\n")
].join( "\n" )
},
......@@ -203,7 +203,7 @@ THREE.ShaderGodRays = {
"}"
].join("\n"),
].join( "\n" ),
fragmentShader: [
......@@ -226,7 +226,7 @@ THREE.ShaderGodRays = {
"}"
].join("\n")
].join( "\n" )
},
......@@ -273,7 +273,7 @@ THREE.ShaderGodRays = {
"}"
].join("\n"),
].join( "\n" ),
fragmentShader: [
......@@ -301,7 +301,7 @@ THREE.ShaderGodRays = {
"}"
].join("\n")
].join( "\n" )
}
......
......@@ -30,27 +30,27 @@ THREE.ShaderSkin = {
{
"enableBump" : { type: "i", value: 0 },
"enableSpecular": { type: "i", value: 0 },
"enableBump" : { type: "i", value: 0 },
"enableSpecular": { type: "i", value: 0 },
"tDiffuse" : { type: "t", value: null },
"tBeckmann" : { type: "t", value: null },
"tDiffuse" : { type: "t", value: null },
"tBeckmann" : { type: "t", value: null },
"diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"specular": { type: "c", value: new THREE.Color( 0x111111 ) },
"opacity": { type: "f", value: 1 },
"diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"specular": { type: "c", value: new THREE.Color( 0x111111 ) },
"opacity": { type: "f", value: 1 },
"uRoughness": { type: "f", value: 0.15 },
"uSpecularBrightness": { type: "f", value: 0.75 },
"uRoughness": { type: "f", value: 0.15 },
"uSpecularBrightness": { type: "f", value: 0.75 },
"bumpMap" : { type: "t", value: null },
"bumpScale" : { type: "f", value: 1 },
"bumpMap" : { type: "t", value: null },
"bumpScale" : { type: "f", value: 1 },
"specularMap" : { type: "t", value: null },
"specularMap" : { type: "t", value: null },
"offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
"offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
"uWrapRGB": { type: "v3", value: new THREE.Vector3( 0.75, 0.375, 0.1875 ) }
"uWrapRGB": { type: "v3", value: new THREE.Vector3( 0.75, 0.375, 0.1875 ) }
}
......@@ -279,7 +279,7 @@ THREE.ShaderSkin = {
"}"
].join("\n"),
].join( "\n" ),
vertexShader: [
......@@ -338,26 +338,26 @@ THREE.ShaderSkin = {
{
"passID": { type: "i", value: 0 },
"passID": { type: "i", value: 0 },
"tDiffuse" : { type: "t", value: null },
"tNormal" : { type: "t", value: null },
"tDiffuse" : { type: "t", value: null },
"tNormal" : { type: "t", value: null },
"tBlur1" : { type: "t", value: null },
"tBlur2" : { type: "t", value: null },
"tBlur3" : { type: "t", value: null },
"tBlur4" : { type: "t", value: null },
"tBlur1" : { type: "t", value: null },
"tBlur2" : { type: "t", value: null },
"tBlur3" : { type: "t", value: null },
"tBlur4" : { type: "t", value: null },
"tBeckmann" : { type: "t", value: null },
"tBeckmann" : { type: "t", value: null },
"uNormalScale": { type: "f", value: 1.0 },
"uNormalScale": { type: "f", value: 1.0 },
"diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"specular": { type: "c", value: new THREE.Color( 0x111111 ) },
"opacity": { type: "f", value: 1 },
"diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"specular": { type: "c", value: new THREE.Color( 0x111111 ) },
"opacity": { type: "f", value: 1 },
"uRoughness": { type: "f", value: 0.15 },
"uSpecularBrightness": { type: "f", value: 0.75 }
"uRoughness": { type: "f", value: 0.15 },
"uSpecularBrightness": { type: "f", value: 0.75 }
}
......@@ -570,7 +570,7 @@ THREE.ShaderSkin = {
"}"
].join("\n"),
].join( "\n" ),
vertexShader: [
......@@ -659,7 +659,7 @@ THREE.ShaderSkin = {
"}"
].join("\n"),
].join( "\n" ),
vertexShaderUV: [
......@@ -735,7 +735,7 @@ THREE.ShaderSkin = {
"}"
].join("\n")
].join( "\n" )
},
......@@ -762,7 +762,7 @@ THREE.ShaderSkin = {
"}"
].join("\n"),
].join( "\n" ),
fragmentShader: [
......@@ -794,7 +794,7 @@ THREE.ShaderSkin = {
"}"
].join("\n")
].join( "\n" )
}
......
......@@ -23,32 +23,32 @@ THREE.ShaderTerrain = {
{
"enableDiffuse1" : { type: "i", value: 0 },
"enableDiffuse2" : { type: "i", value: 0 },
"enableSpecular" : { type: "i", value: 0 },
"enableReflection": { type: "i", value: 0 },
"enableDiffuse1" : { type: "i", value: 0 },
"enableDiffuse2" : { type: "i", value: 0 },
"enableSpecular" : { type: "i", value: 0 },
"enableReflection": { type: "i", value: 0 },
"tDiffuse1" : { type: "t", value: null },
"tDiffuse2" : { type: "t", value: null },
"tDetail" : { type: "t", value: null },
"tNormal" : { type: "t", value: null },
"tSpecular" : { type: "t", value: null },
"tDisplacement": { type: "t", value: null },
"tDiffuse1" : { type: "t", value: null },
"tDiffuse2" : { type: "t", value: null },
"tDetail" : { type: "t", value: null },
"tNormal" : { type: "t", value: null },
"tSpecular" : { type: "t", value: null },
"tDisplacement": { type: "t", value: null },
"uNormalScale": { type: "f", value: 1.0 },
"uNormalScale": { type: "f", value: 1.0 },
"uDisplacementBias": { type: "f", value: 0.0 },
"uDisplacementScale": { type: "f", value: 1.0 },
"uDisplacementBias": { type: "f", value: 0.0 },
"uDisplacementScale": { type: "f", value: 1.0 },
"diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"specular": { type: "c", value: new THREE.Color( 0x111111 ) },
"shininess": { type: "f", value: 30 },
"opacity": { type: "f", value: 1 },
"diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"specular": { type: "c", value: new THREE.Color( 0x111111 ) },
"shininess": { type: "f", value: 30 },
"opacity": { type: "f", value: 1 },
"uRepeatBase" : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
"uRepeatOverlay" : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
"uRepeatBase" : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
"uRepeatOverlay" : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
"uOffset" : { type: "v2", value: new THREE.Vector2( 0, 0 ) }
"uOffset" : { type: "v2", value: new THREE.Vector2( 0, 0 ) }
}
......@@ -263,7 +263,7 @@ THREE.ShaderTerrain = {
"}"
].join("\n"),
].join( "\n" ),
vertexShader: [
......@@ -336,7 +336,7 @@ THREE.ShaderTerrain = {
"}"
].join("\n")
].join( "\n" )
}
......
......@@ -12,320 +12,320 @@
THREE.ShaderToon = {
'toon1' : {
'toon1' : {
uniforms: {
uniforms: {
"uDirLightPos": { type: "v3", value: new THREE.Vector3() },
"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"uDirLightPos": { type: "v3", value: new THREE.Vector3() },
"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
"uBaseColor": { type: "c", value: new THREE.Color( 0xffffff ) }
"uBaseColor": { type: "c", value: new THREE.Color( 0xffffff ) }
},
},
vertexShader: [
vertexShader: [
"varying vec3 vNormal;",
"varying vec3 vRefract;",
"varying vec3 vNormal;",
"varying vec3 vRefract;",
"void main() {",
"void main() {",
"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
"vec3 worldNormal = normalize ( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );",
"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
"vec3 worldNormal = normalize ( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );",
"vNormal = normalize( normalMatrix * normal );",
"vNormal = normalize( normalMatrix * normal );",
"vec3 I = worldPosition.xyz - cameraPosition;",
"vRefract = refract( normalize( I ), worldNormal, 1.02 );",
"vec3 I = worldPosition.xyz - cameraPosition;",
"vRefract = refract( normalize( I ), worldNormal, 1.02 );",
"gl_Position = projectionMatrix * mvPosition;",
"gl_Position = projectionMatrix * mvPosition;",
"}"
"}"
].join("\n"),
].join( "\n" ),
fragmentShader: [
fragmentShader: [
"uniform vec3 uBaseColor;",
"uniform vec3 uBaseColor;",
"uniform vec3 uDirLightPos;",
"uniform vec3 uDirLightColor;",
"uniform vec3 uDirLightPos;",
"uniform vec3 uDirLightColor;",
"uniform vec3 uAmbientLightColor;",
"uniform vec3 uAmbientLightColor;",
"varying vec3 vNormal;",
"varying vec3 vNormal;",
"varying vec3 vRefract;",
"varying vec3 vRefract;",
"void main() {",
"void main() {",
"float directionalLightWeighting = max( dot( normalize( vNormal ), uDirLightPos ), 0.0);",
"vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;",
"float directionalLightWeighting = max( dot( normalize( vNormal ), uDirLightPos ), 0.0);",
"vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;",
"float intensity = smoothstep( - 0.5, 1.0, pow( length(lightWeighting), 20.0 ) );",
"intensity += length(lightWeighting) * 0.2;",
"float intensity = smoothstep( - 0.5, 1.0, pow( length(lightWeighting), 20.0 ) );",
"intensity += length(lightWeighting) * 0.2;",
"float cameraWeighting = dot( normalize( vNormal ), vRefract );",
"intensity += pow( 1.0 - length( cameraWeighting ), 6.0 );",
"intensity = intensity * 0.2 + 0.3;",
"float cameraWeighting = dot( normalize( vNormal ), vRefract );",
"intensity += pow( 1.0 - length( cameraWeighting ), 6.0 );",
"intensity = intensity * 0.2 + 0.3;",
"if ( intensity < 0.50 ) {",
"if ( intensity < 0.50 ) {",
"gl_FragColor = vec4( 2.0 * intensity * uBaseColor, 1.0 );",
"gl_FragColor = vec4( 2.0 * intensity * uBaseColor, 1.0 );",
"} else {",
"} else {",
"gl_FragColor = vec4( 1.0 - 2.0 * ( 1.0 - intensity ) * ( 1.0 - uBaseColor ), 1.0 );",
"gl_FragColor = vec4( 1.0 - 2.0 * ( 1.0 - intensity ) * ( 1.0 - uBaseColor ), 1.0 );",
"}",
"}",
"}"
"}"
].join("\n")
].join( "\n" )
},
},
'toon2' : {
'toon2' : {
uniforms: {
uniforms: {
"uDirLightPos": { type: "v3", value: new THREE.Vector3() },
"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"uDirLightPos": { type: "v3", value: new THREE.Vector3() },
"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
"uBaseColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"uLineColor1": { type: "c", value: new THREE.Color( 0x808080 ) },
"uLineColor2": { type: "c", value: new THREE.Color( 0x000000 ) },
"uLineColor3": { type: "c", value: new THREE.Color( 0x000000 ) },
"uLineColor4": { type: "c", value: new THREE.Color( 0x000000 ) }
"uBaseColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"uLineColor1": { type: "c", value: new THREE.Color( 0x808080 ) },
"uLineColor2": { type: "c", value: new THREE.Color( 0x000000 ) },
"uLineColor3": { type: "c", value: new THREE.Color( 0x000000 ) },
"uLineColor4": { type: "c", value: new THREE.Color( 0x000000 ) }
},
},
vertexShader: [
vertexShader: [
"varying vec3 vNormal;",
"varying vec3 vNormal;",
"void main() {",
"void main() {",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"vNormal = normalize( normalMatrix * normal );",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"vNormal = normalize( normalMatrix * normal );",
"}"
"}"
].join("\n"),
].join( "\n" ),
fragmentShader: [
fragmentShader: [
"uniform vec3 uBaseColor;",
"uniform vec3 uLineColor1;",
"uniform vec3 uLineColor2;",
"uniform vec3 uLineColor3;",
"uniform vec3 uLineColor4;",
"uniform vec3 uBaseColor;",
"uniform vec3 uLineColor1;",
"uniform vec3 uLineColor2;",
"uniform vec3 uLineColor3;",
"uniform vec3 uLineColor4;",
"uniform vec3 uDirLightPos;",
"uniform vec3 uDirLightColor;",
"uniform vec3 uDirLightPos;",
"uniform vec3 uDirLightColor;",
"uniform vec3 uAmbientLightColor;",
"uniform vec3 uAmbientLightColor;",
"varying vec3 vNormal;",
"varying vec3 vNormal;",
"void main() {",
"void main() {",
"float camera = max( dot( normalize( vNormal ), vec3( 0.0, 0.0, 1.0 ) ), 0.4);",
"float light = max( dot( normalize( vNormal ), uDirLightPos ), 0.0);",
"float camera = max( dot( normalize( vNormal ), vec3( 0.0, 0.0, 1.0 ) ), 0.4);",
"float light = max( dot( normalize( vNormal ), uDirLightPos ), 0.0);",
"gl_FragColor = vec4( uBaseColor, 1.0 );",
"gl_FragColor = vec4( uBaseColor, 1.0 );",
"if ( length(uAmbientLightColor + uDirLightColor * light) < 1.00 ) {",
"if ( length(uAmbientLightColor + uDirLightColor * light) < 1.00 ) {",
"gl_FragColor *= vec4( uLineColor1, 1.0 );",
"gl_FragColor *= vec4( uLineColor1, 1.0 );",
"}",
"}",
"if ( length(uAmbientLightColor + uDirLightColor * camera) < 0.50 ) {",
"if ( length(uAmbientLightColor + uDirLightColor * camera) < 0.50 ) {",
"gl_FragColor *= vec4( uLineColor2, 1.0 );",
"gl_FragColor *= vec4( uLineColor2, 1.0 );",
"}",
"}",
"}"
"}"
].join( "\n" )
].join("\n")
},
},
'hatching' : {
'hatching' : {
uniforms: {
uniforms: {
"uDirLightPos": { type: "v3", value: new THREE.Vector3() },
"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"uDirLightPos": { type: "v3", value: new THREE.Vector3() },
"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
"uBaseColor": { type: "c", value: new THREE.Color( 0xffffff ) },
"uLineColor1": { type: "c", value: new THREE.Color( 0x000000 ) },
"uLineColor2": { type: "c", value: new THREE.Color( 0x000000 ) },
"uLineColor3": { type: "c", value: new THREE.Color( 0x000000 ) },
"uLineColor4": { type: "c", value: new THREE.Color( 0x000000 ) }
"uBaseColor": { type: "c", value: new THREE.Color( 0xffffff ) },
"uLineColor1": { type: "c", value: new THREE.Color( 0x000000 ) },
"uLineColor2": { type: "c", value: new THREE.Color( 0x000000 ) },
"uLineColor3": { type: "c", value: new THREE.Color( 0x000000 ) },
"uLineColor4": { type: "c", value: new THREE.Color( 0x000000 ) }
},
},
vertexShader: [
vertexShader: [
"varying vec3 vNormal;",
"varying vec3 vNormal;",
"void main() {",
"void main() {",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"vNormal = normalize( normalMatrix * normal );",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"vNormal = normalize( normalMatrix * normal );",
"}"
"}"
].join( "\n" ),
].join("\n"),
fragmentShader: [
fragmentShader: [
"uniform vec3 uBaseColor;",
"uniform vec3 uLineColor1;",
"uniform vec3 uLineColor2;",
"uniform vec3 uLineColor3;",
"uniform vec3 uLineColor4;",
"uniform vec3 uBaseColor;",
"uniform vec3 uLineColor1;",
"uniform vec3 uLineColor2;",
"uniform vec3 uLineColor3;",
"uniform vec3 uLineColor4;",
"uniform vec3 uDirLightPos;",
"uniform vec3 uDirLightColor;",
"uniform vec3 uDirLightPos;",
"uniform vec3 uDirLightColor;",
"uniform vec3 uAmbientLightColor;",
"uniform vec3 uAmbientLightColor;",
"varying vec3 vNormal;",
"varying vec3 vNormal;",
"void main() {",
"void main() {",
"float directionalLightWeighting = max( dot( normalize(vNormal), uDirLightPos ), 0.0);",
"vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;",
"float directionalLightWeighting = max( dot( normalize(vNormal), uDirLightPos ), 0.0);",
"vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;",
"gl_FragColor = vec4( uBaseColor, 1.0 );",
"gl_FragColor = vec4( uBaseColor, 1.0 );",
"if ( length(lightWeighting) < 1.00 ) {",
"if ( length(lightWeighting) < 1.00 ) {",
"if ( mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) {",
"if ( mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) {",
"gl_FragColor = vec4( uLineColor1, 1.0 );",
"gl_FragColor = vec4( uLineColor1, 1.0 );",
"}",
"}",
"}",
"if ( length(lightWeighting) < 0.75 ) {",
"if ( length(lightWeighting) < 0.75 ) {",
"if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) {",
"if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) {",
"gl_FragColor = vec4( uLineColor2, 1.0 );",
"gl_FragColor = vec4( uLineColor2, 1.0 );",
"}",
"}",
"}",
"if ( length(lightWeighting) < 0.50 ) {",
"if ( length(lightWeighting) < 0.50 ) {",
"if (mod(gl_FragCoord.x + gl_FragCoord.y - 5.0, 10.0) == 0.0) {",
"if (mod(gl_FragCoord.x + gl_FragCoord.y - 5.0, 10.0) == 0.0) {",
"gl_FragColor = vec4( uLineColor3, 1.0 );",
"gl_FragColor = vec4( uLineColor3, 1.0 );",
"}",
"}",
"}",
"if ( length(lightWeighting) < 0.3465 ) {",
"if ( length(lightWeighting) < 0.3465 ) {",
"if (mod(gl_FragCoord.x - gl_FragCoord.y - 5.0, 10.0) == 0.0) {",
"if (mod(gl_FragCoord.x - gl_FragCoord.y - 5.0, 10.0) == 0.0) {",
"gl_FragColor = vec4( uLineColor4, 1.0 );",
"gl_FragColor = vec4( uLineColor4, 1.0 );",
"}",
"}",
"}",
"}"
"}"
].join("\n")
].join( "\n" )
},
},
'dotted' : {
'dotted' : {
uniforms: {
uniforms: {
"uDirLightPos": { type: "v3", value: new THREE.Vector3() },
"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"uDirLightPos": { type: "v3", value: new THREE.Vector3() },
"uDirLightColor": { type: "c", value: new THREE.Color( 0xeeeeee ) },
"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
"uAmbientLightColor": { type: "c", value: new THREE.Color( 0x050505 ) },
"uBaseColor": { type: "c", value: new THREE.Color( 0xffffff ) },
"uLineColor1": { type: "c", value: new THREE.Color( 0x000000 ) }
"uBaseColor": { type: "c", value: new THREE.Color( 0xffffff ) },
"uLineColor1": { type: "c", value: new THREE.Color( 0x000000 ) }
},
},
vertexShader: [
vertexShader: [
"varying vec3 vNormal;",
"varying vec3 vNormal;",
"void main() {",
"void main() {",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"vNormal = normalize( normalMatrix * normal );",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"vNormal = normalize( normalMatrix * normal );",
"}"
"}"
].join( "\n" ),
].join("\n"),
fragmentShader: [
fragmentShader: [
"uniform vec3 uBaseColor;",
"uniform vec3 uLineColor1;",
"uniform vec3 uLineColor2;",
"uniform vec3 uLineColor3;",
"uniform vec3 uLineColor4;",
"uniform vec3 uBaseColor;",
"uniform vec3 uLineColor1;",
"uniform vec3 uLineColor2;",
"uniform vec3 uLineColor3;",
"uniform vec3 uLineColor4;",
"uniform vec3 uDirLightPos;",
"uniform vec3 uDirLightColor;",
"uniform vec3 uDirLightPos;",
"uniform vec3 uDirLightColor;",
"uniform vec3 uAmbientLightColor;",
"uniform vec3 uAmbientLightColor;",
"varying vec3 vNormal;",
"varying vec3 vNormal;",
"void main() {",
"void main() {",
"float directionalLightWeighting = max( dot( normalize(vNormal), uDirLightPos ), 0.0);",
"vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;",
"float directionalLightWeighting = max( dot( normalize(vNormal), uDirLightPos ), 0.0);",
"vec3 lightWeighting = uAmbientLightColor + uDirLightColor * directionalLightWeighting;",
"gl_FragColor = vec4( uBaseColor, 1.0 );",
"gl_FragColor = vec4( uBaseColor, 1.0 );",
"if ( length(lightWeighting) < 1.00 ) {",
"if ( length(lightWeighting) < 1.00 ) {",
"if ( ( mod(gl_FragCoord.x, 4.001) + mod(gl_FragCoord.y, 4.0) ) > 6.00 ) {",
"if ( ( mod(gl_FragCoord.x, 4.001) + mod(gl_FragCoord.y, 4.0) ) > 6.00 ) {",
"gl_FragColor = vec4( uLineColor1, 1.0 );",
"gl_FragColor = vec4( uLineColor1, 1.0 );",
"}",
"}",
"}",
"if ( length(lightWeighting) < 0.50 ) {",
"if ( length(lightWeighting) < 0.50 ) {",
"if ( ( mod(gl_FragCoord.x + 2.0, 4.001) + mod(gl_FragCoord.y + 2.0, 4.0) ) > 6.00 ) {",
"if ( ( mod(gl_FragCoord.x + 2.0, 4.001) + mod(gl_FragCoord.y + 2.0, 4.0) ) > 6.00 ) {",
"gl_FragColor = vec4( uLineColor1, 1.0 );",
"gl_FragColor = vec4( uLineColor1, 1.0 );",
"}",
"}",
"}",
"}"
"}"
].join("\n")
].join( "\n" )
}
}
};
......@@ -10,7 +10,7 @@
*
*/
function SimulationRenderer(WIDTH, renderer) {
function SimulationRenderer( WIDTH, renderer ) {
WIDTH = WIDTH || 4;
var camera = new THREE.Camera();
......@@ -19,14 +19,18 @@ function SimulationRenderer(WIDTH, renderer) {
// Init RTT stuff
gl = renderer.getContext();
if ( !gl.getExtension( "OES_texture_float" )) {
if ( ! gl.getExtension( "OES_texture_float" ) ) {
alert( "No OES_texture_float support for float textures!" );
return;
}
if ( gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) == 0) {
if ( gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) == 0 ) {
alert( "No support for vertex shader textures!" );
return;
}
var scene = new THREE.Scene();
......@@ -77,7 +81,7 @@ function SimulationRenderer(WIDTH, renderer) {
predator: { type: "v3", value: new THREE.Vector3() }
},
defines: {
WIDTH: WIDTH.toFixed(2)
WIDTH: WIDTH.toFixed( 2 )
},
vertexShader: document.getElementById( 'vertexShader' ).textContent,
fragmentShader: document.getElementById( 'fragmentShaderVelocity' ).textContent
......@@ -92,6 +96,7 @@ function SimulationRenderer(WIDTH, renderer) {
var rtPosition1, rtPosition2, rtVelocity1, rtVelocity2;
function init() {
var dtPosition = generatePositionTexture();
var dtVelocity = generateVelocityTexture();
......@@ -100,19 +105,21 @@ function SimulationRenderer(WIDTH, renderer) {
rtVelocity1 = getRenderTarget( THREE.RGBFormat );
rtVelocity2 = rtVelocity1.clone();
simulator.renderTexture(dtPosition, rtPosition1);
simulator.renderTexture(rtPosition1, rtPosition2);
simulator.renderTexture( dtPosition, rtPosition1 );
simulator.renderTexture( rtPosition1, rtPosition2 );
simulator.renderTexture(dtVelocity, rtVelocity1);
simulator.renderTexture(rtVelocity1, rtVelocity2);
simulator.renderTexture( dtVelocity, rtVelocity1 );
simulator.renderTexture( rtVelocity1, rtVelocity2 );
simulator.velocityUniforms.testing.value = 10;
}
this.init = init;
function getRenderTarget( type ) {
var renderTarget = new THREE.WebGLRenderTarget(WIDTH, WIDTH, {
var renderTarget = new THREE.WebGLRenderTarget( WIDTH, WIDTH, {
wrapS: THREE.RepeatWrapping,
wrapT: THREE.RepeatWrapping,
minFilter: THREE.NearestFilter,
......@@ -120,20 +127,24 @@ function SimulationRenderer(WIDTH, renderer) {
format: type,
type: THREE.FloatType,
stencilBuffer: false
});
} );
return renderTarget;
}
// Takes a texture, and render out as another texture
this.renderTexture = function ( input, output ) {
mesh.material = passThruShader;
uniforms.texture.value = input;
renderer.render( scene, camera, output );
};
this.renderPosition = function(position, velocity, output, delta) {
this.renderPosition = function( position, velocity, output, delta ) {
mesh.material = positionShader;
positionShader.uniforms.texturePosition.value = position;
positionShader.uniforms.textureVelocity.value = velocity;
......@@ -141,9 +152,11 @@ function SimulationRenderer(WIDTH, renderer) {
positionShader.uniforms.delta.value = delta;
renderer.render( scene, camera, output );
this.currentPosition = output;
};
this.renderVelocity = function(position, velocity, output, delta) {
this.renderVelocity = function( position, velocity, output, delta ) {
mesh.material = velocityShader;
velocityShader.uniforms.texturePosition.value = position;
velocityShader.uniforms.textureVelocity.value = velocity;
......@@ -151,11 +164,12 @@ function SimulationRenderer(WIDTH, renderer) {
velocityShader.uniforms.delta.value = delta;
renderer.render( scene, camera, output );
this.currentVelocity = output;
};
this.simulate = function( delta ) {
if (flipflop) {
if ( flipflop ) {
simulator.renderVelocity( rtPosition1, rtVelocity1, rtVelocity2, delta );
simulator.renderPosition( rtPosition1, rtVelocity2, rtPosition2, delta );
......@@ -167,7 +181,7 @@ function SimulationRenderer(WIDTH, renderer) {
}
flipflop = !flipflop;
flipflop = ! flipflop;
};
......
......@@ -14,15 +14,15 @@
* Three.js integration by zz85 http://twitter.com/blurspline
*/
THREE.ShaderLib['sky'] = {
THREE.ShaderLib[ 'sky' ] = {
uniforms: {
luminance: { type: "f", value:1 },
turbidity: { type: "f", value:2 },
reileigh: { type: "f", value:1 },
mieCoefficient: { type: "f", value:0.005 },
mieDirectionalG: { type: "f", value:0.8 },
luminance: { type: "f", value: 1 },
turbidity: { type: "f", value: 2 },
reileigh: { type: "f", value: 1 },
mieCoefficient: { type: "f", value: 0.005 },
mieDirectionalG: { type: "f", value: 0.8 },
sunPosition: { type: "v3", value: new THREE.Vector3() }
},
......@@ -40,7 +40,7 @@ THREE.ShaderLib['sky'] = {
"}",
].join("\n"),
].join( "\n" ),
fragmentShader: [
......@@ -235,7 +235,7 @@ THREE.ShaderLib['sky'] = {
"gl_FragColor.a = 1.0;",
"}",
].join("\n")
].join( "\n" )
};
......
此差异已折叠。
......@@ -21,7 +21,7 @@ THREE.TypedArrayUtils = {};
THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
var stack = [];
var sp = -1;
var sp = - 1;
var left = 0;
var right = arr.length / eleSize - 1;
var tmp = 0.0, x = 0, y = 0;
......@@ -56,7 +56,7 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
i = j - 1;
while ( i >= left && arr[ i * eleSize + orderElement ] > swap[orderElement ] ) {
while ( i >= left && arr[ i * eleSize + orderElement ] > swap[ orderElement ] ) {
for ( x = 0; x < eleSize; x ++ ) {
......@@ -76,7 +76,7 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
}
if ( sp == -1 ) break;
if ( sp == - 1 ) break;
right = stack[ sp -- ]; //?
left = stack[ sp -- ];
......@@ -215,7 +215,7 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
median = Math.floor( plength / 2 );
node = new self.Node( getPointSet( points, median ), depth, parent, median + pos );
node.left = buildTree( points.subarray( 0, median * eleSize), depth + 1, node, pos );
node.left = buildTree( points.subarray( 0, median * eleSize ), depth + 1, node, pos );
node.right = buildTree( points.subarray( ( median + 1 ) * eleSize, points.length ), depth + 1, node, pos + median + 1 );
return node;
......@@ -224,7 +224,11 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
this.root = buildTree( points, 0, null, 0 );
this.getMaxDepth = function () { return maxDepth; };
this.getMaxDepth = function () {
return maxDepth;
};
this.nearest = function ( point, maxNodes, maxDistance ) {
......@@ -240,15 +244,19 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
bestNodes = new THREE.TypedArrayUtils.Kdtree.BinaryHeap(
function ( e ) { return -e[ 1 ]; }
function ( e ) {
);
return - e[ 1 ];
}
);
function nearestSearch( node ) {
var bestChild,
dimension = node.depth % eleSize,
ownDistance = metric(point, node.obj),
ownDistance = metric( point, node.obj ),
linearDistance = 0,
otherChild,
i,
......@@ -330,7 +338,7 @@ THREE.TypedArrayUtils.quicksortIP = function ( arr, eleSize, orderElement ) {
// if there's still room or the current distance is nearer than the best distance
if ( bestNodes.size() < maxNodes || Math.abs(linearDistance) < bestNodes.peek()[ 1 ] ) {
if ( bestNodes.size() < maxNodes || Math.abs( linearDistance ) < bestNodes.peek()[ 1 ] ) {
if ( bestChild === node.left ) {
......@@ -591,4 +599,4 @@ THREE.TypedArrayUtils.Kdtree.BinaryHeap.prototype = {
}
};
\ No newline at end of file
};
......@@ -38,6 +38,7 @@ THREE.UCSCharacter = function() {
var loader = new THREE.JSONLoader();
console.log( config.baseUrl + config.character );
loader.load( config.baseUrl + config.character, function( geometry ) {
geometry.computeBoundingBox();
geometry.computeVertexNormals();
......@@ -56,28 +57,40 @@ THREE.UCSCharacter = function() {
animation = new THREE.Animation( mesh, geometry.animation );
animation.play();
scope.setSkin(0);
scope.setSkin( 0 );
scope.checkLoadComplete();
} );
};
this.setSkin = function( index ) {
if ( mesh && scope.materials ) {
mesh.material = scope.materials[ index ];
}
};
this.updateMorphs = function( influences ) {
if ( mesh ) {
for ( var i = 0; i < scope.numMorphs; i ++ ) {
mesh.morphTargetInfluences[ i ] = influences[ scope.morphs[ i ] ] / 100;
}
}
};
function loadTextures( baseUrl, textureUrls ) {
var mapping = THREE.UVMapping;
var textures = [];
......@@ -89,9 +102,11 @@ THREE.UCSCharacter = function() {
}
return textures;
}
function createMaterials( skins ) {
var materials = [];
for ( var i = 0; i < skins.length; i ++ ) {
......@@ -107,6 +122,7 @@ THREE.UCSCharacter = function() {
}
return materials;
}
this.checkLoadComplete = function () {
......
......@@ -7,7 +7,7 @@
* @author Jonas Wagner / http://29a.ch/ && http://29a.ch/slides/2012/webglwater/ : Water shader explanations in WebGL
*/
THREE.ShaderLib['water'] = {
THREE.ShaderLib[ 'water' ] = {
uniforms: { "normalSampler": { type: "t", value: null },
"mirrorSampler": { type: "t", value: null },
......@@ -35,7 +35,7 @@ THREE.ShaderLib['water'] = {
' mirrorCoord = textureMatrix * mirrorCoord;',
' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
'}'
].join('\n'),
].join( '\n' ),
fragmentShader: [
'precision highp float;',
......@@ -98,7 +98,7 @@ THREE.ShaderLib['water'] = {
' vec3 albedo = mix( sunColor * diffuseLight * 0.3 + scatter, ( vec3( 0.1 ) + reflectionSample * 0.9 + reflectionSample * specularLight ), reflectance );',
' gl_FragColor = vec4( albedo, alpha );',
'}'
].join('\n')
].join( '\n' )
};
......@@ -108,7 +108,9 @@ THREE.Water = function ( renderer, camera, scene, options ) {
this.name = 'water_' + this.id;
function optionalParameter ( value, defaultValue ) {
return value !== undefined ? value : defaultValue;
}
options = options || {};
......@@ -134,15 +136,16 @@ THREE.Water = function ( renderer, camera, scene, options ) {
this.mirrorWorldPosition = new THREE.Vector3();
this.cameraWorldPosition = new THREE.Vector3();
this.rotationMatrix = new THREE.Matrix4();
this.lookAtPosition = new THREE.Vector3( 0, 0, -1 );
this.lookAtPosition = new THREE.Vector3( 0, 0, - 1 );
this.clipPlane = new THREE.Vector4();
if ( camera instanceof THREE.PerspectiveCamera )
this.camera = camera;
else
{
else {
this.camera = new THREE.PerspectiveCamera();
console.log(this.name + ': camera is not a Perspective Camera!')
console.log( this.name + ': camera is not a Perspective Camera!' )
}
this.textureMatrix = new THREE.Matrix4();
......@@ -174,16 +177,18 @@ THREE.Water = function ( renderer, camera, scene, options ) {
this.material.uniforms.eye.value = this.eye;
if ( !THREE.Math.isPowerOfTwo(width) || !THREE.Math.isPowerOfTwo(height) )
{
if ( ! THREE.Math.isPowerOfTwo( width ) || ! THREE.Math.isPowerOfTwo( height ) ) {
this.texture.generateMipmaps = false;
this.texture.minFilter = THREE.LinearFilter;
this.tempTexture.generateMipmaps = false;
this.tempTexture.minFilter = THREE.LinearFilter;
}
this.updateTextureMatrix();
this.render();
};
THREE.Water.prototype = Object.create( THREE.Mirror.prototype );
......@@ -192,7 +197,11 @@ THREE.Water.prototype.constructor = THREE.Water;
THREE.Water.prototype.updateTextureMatrix = function () {
function sign(x) { return x ? x < 0 ? -1 : 1 : 0; }
function sign( x ) {
return x ? x < 0 ? - 1 : 1 : 0;
}
this.updateMatrixWorld();
this.camera.updateMatrixWorld();
......@@ -211,7 +220,7 @@ THREE.Water.prototype.updateTextureMatrix = function () {
this.rotationMatrix.extractRotation( this.camera.matrixWorld );
this.lookAtPosition.set(0, 0, -1);
this.lookAtPosition.set( 0, 0, - 1 );
this.lookAtPosition.applyMatrix4( this.rotationMatrix );
this.lookAtPosition.add( this.cameraWorldPosition );
......@@ -219,7 +228,7 @@ THREE.Water.prototype.updateTextureMatrix = function () {
target.reflect( this.normal ).negate();
target.add( this.mirrorWorldPosition );
this.up.set(0, -1, 0);
this.up.set( 0, - 1, 0 );
this.up.applyMatrix4( this.rotationMatrix );
this.up.reflect( this.normal ).negate();
......@@ -230,43 +239,44 @@ THREE.Water.prototype.updateTextureMatrix = function () {
this.mirrorCamera.updateProjectionMatrix();
this.mirrorCamera.updateMatrixWorld();
this.mirrorCamera.matrixWorldInverse.getInverse(this.mirrorCamera.matrixWorld);
this.mirrorCamera.matrixWorldInverse.getInverse( this.mirrorCamera.matrixWorld );
// Update the texture matrix
this.textureMatrix.set( 0.5, 0.0, 0.0, 0.5,
0.0, 0.5, 0.0, 0.5,
0.0, 0.0, 0.5, 0.5,
0.0, 0.0, 0.0, 1.0 );
this.textureMatrix.multiply(this.mirrorCamera.projectionMatrix);
this.textureMatrix.multiply(this.mirrorCamera.matrixWorldInverse);
this.textureMatrix.multiply( this.mirrorCamera.projectionMatrix );
this.textureMatrix.multiply( this.mirrorCamera.matrixWorldInverse );
// Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
// Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
this.mirrorPlane.setFromNormalAndCoplanarPoint( this.normal, this.mirrorWorldPosition );
this.mirrorPlane.applyMatrix4(this.mirrorCamera.matrixWorldInverse);
this.mirrorPlane.applyMatrix4( this.mirrorCamera.matrixWorldInverse );
this.clipPlane.set(this.mirrorPlane.normal.x, this.mirrorPlane.normal.y, this.mirrorPlane.normal.z, this.mirrorPlane.constant );
this.clipPlane.set( this.mirrorPlane.normal.x, this.mirrorPlane.normal.y, this.mirrorPlane.normal.z, this.mirrorPlane.constant );
var q = new THREE.Vector4();
var projectionMatrix = this.mirrorCamera.projectionMatrix;
q.x = (sign(this.clipPlane.x) + projectionMatrix.elements[8]) / projectionMatrix.elements[0];
q.y = (sign(this.clipPlane.y) + projectionMatrix.elements[9]) / projectionMatrix.elements[5];
q.z = -1.0;
q.w = (1.0 + projectionMatrix.elements[10]) / projectionMatrix.elements[14];
q.x = ( sign( this.clipPlane.x ) + projectionMatrix.elements[ 8 ] ) / projectionMatrix.elements[ 0 ];
q.y = ( sign( this.clipPlane.y ) + projectionMatrix.elements[ 9 ] ) / projectionMatrix.elements[ 5 ];
q.z = - 1.0;
q.w = ( 1.0 + projectionMatrix.elements[ 10 ] ) / projectionMatrix.elements[ 14 ];
// Calculate the scaled plane vector
var c = new THREE.Vector4();
c = this.clipPlane.multiplyScalar( 2.0 / this.clipPlane.dot(q) );
c = this.clipPlane.multiplyScalar( 2.0 / this.clipPlane.dot( q ) );
// Replacing the third row of the projection matrix
projectionMatrix.elements[2] = c.x;
projectionMatrix.elements[6] = c.y;
projectionMatrix.elements[10] = c.z + 1.0 - this.clipBias;
projectionMatrix.elements[14] = c.w;
projectionMatrix.elements[ 2 ] = c.x;
projectionMatrix.elements[ 6 ] = c.y;
projectionMatrix.elements[ 10 ] = c.z + 1.0 - this.clipBias;
projectionMatrix.elements[ 14 ] = c.w;
var worldCoordinates = new THREE.Vector3();
worldCoordinates.setFromMatrixPosition( this.camera.matrixWorld );
this.eye = worldCoordinates;
this.material.uniforms.eye.value = this.eye;
};
......@@ -15,10 +15,10 @@ THREE.CombinedCamera = function ( width, height, fov, near, far, orthoNear, orth
this.fov = fov;
this.left = -width / 2;
this.left = - width / 2;
this.right = width / 2;
this.top = height / 2;
this.bottom = -height / 2;
this.bottom = - height / 2;
// We could also handle the projectionMatrix internally, but just wanted to test nested camera objects
......@@ -73,10 +73,10 @@ THREE.CombinedCamera.prototype.toOrthographic = function () {
halfHeight /= this.zoom;
halfWidth /= this.zoom;
this.cameraO.left = -halfWidth;
this.cameraO.left = - halfWidth;
this.cameraO.right = halfWidth;
this.cameraO.top = halfHeight;
this.cameraO.bottom = -halfHeight;
this.cameraO.bottom = - halfHeight;
// this.cameraO.left = -farHalfWidth;
// this.cameraO.right = farHalfWidth;
......@@ -103,10 +103,10 @@ THREE.CombinedCamera.prototype.toOrthographic = function () {
THREE.CombinedCamera.prototype.setSize = function( width, height ) {
this.cameraP.aspect = width / height;
this.left = -width / 2;
this.left = - width / 2;
this.right = width / 2;
this.top = height / 2;
this.bottom = -height / 2;
this.bottom = - height / 2;
};
......@@ -158,6 +158,7 @@ THREE.CombinedCamera.prototype.setLens = function ( focalLength, frameHeight ) {
this.setFov( fov );
return fov;
};
......
......@@ -25,7 +25,7 @@ THREE.DragControls = function( _camera, _objects, _domElement ) {
var me = this;
this.on = function( event, handler ) {
if ( !_listeners[ event ] ) _listeners[ event ] = [];
if ( ! _listeners[ event ] ) _listeners[ event ] = [];
_listeners[ event ].push( handler );
return me;
......@@ -35,9 +35,9 @@ THREE.DragControls = function( _camera, _objects, _domElement ) {
this.off = function( event, handler ) {
var l = _listeners[ event ];
if ( !l ) return me;
if ( ! l ) return me;
if ( l.indexOf( handler ) > -1 ) {
if ( l.indexOf( handler ) > - 1 ) {
l.splice( handler, 1 );
......@@ -50,9 +50,9 @@ THREE.DragControls = function( _camera, _objects, _domElement ) {
var notify = function( event, data, member ) {
var l = _listeners[ event ];
if ( !l ) return;
if ( ! l ) return;
if ( !member ) {
if ( ! member ) {
for ( var i = 0; i < l.length; i ++ ) {
......@@ -103,7 +103,7 @@ THREE.DragControls = function( _camera, _objects, _domElement ) {
event.preventDefault();
_mouse.x = ( event.clientX / _domElement.width ) * 2 - 1;
_mouse.y = -( event.clientY / _domElement.height ) * 2 + 1;
_mouse.y = - ( event.clientY / _domElement.height ) * 2 + 1;
_raycaster.setFromCamera( _mouse, _camera );
var ray = _raycaster.ray;
......@@ -118,6 +118,7 @@ THREE.DragControls = function( _camera, _objects, _domElement ) {
var denom = normal.dot( ray.direction );
if ( denom == 0 ) {
// bail
console.log( 'no or infinite solutions' );
return;
......@@ -188,7 +189,7 @@ THREE.DragControls = function( _camera, _objects, _domElement ) {
event.preventDefault();
_mouse.x = ( event.clientX / _domElement.width ) * 2 - 1;
_mouse.y = -( event.clientY / _domElement.height ) * 2 + 1;
_mouse.y = - ( event.clientY / _domElement.height ) * 2 + 1;
_raycaster.setFromCamera( _mouse, _camera );
var intersects = _raycaster.intersectObjects( _objects );
......
......@@ -19,7 +19,7 @@ THREE.EditorControls = function ( object, domElement ) {
var scope = this;
var vector = new THREE.Vector3();
var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2 };
var STATE = { NONE: - 1, ROTATE: 0, ZOOM: 1, PAN: 2 };
var state = STATE.NONE;
var center = this.center;
......@@ -39,7 +39,7 @@ THREE.EditorControls = function ( object, domElement ) {
if ( frame && target.geometry ) {
scale = ( scale.x + scale.y + scale.z ) / 3;
center.add(target.geometry.boundingSphere.center.clone().multiplyScalar( scale ));
center.add( target.geometry.boundingSphere.center.clone().multiplyScalar( scale ) );
var radius = target.geometry.boundingSphere.radius * ( scale );
var pos = object.position.clone().sub( center ).normalize().multiplyScalar( radius * 2 );
object.position.copy( center ).add( pos );
......@@ -185,11 +185,15 @@ THREE.EditorControls = function ( object, domElement ) {
var delta = 0;
if ( event.wheelDelta ) { // WebKit / Opera / Explorer 9
if ( event.wheelDelta ) {
// WebKit / Opera / Explorer 9
delta = - event.wheelDelta;
} else if ( event.detail ) { // Firefox
} else if ( event.detail ) {
// Firefox
delta = event.detail * 10;
......@@ -199,7 +203,11 @@ THREE.EditorControls = function ( object, domElement ) {
}
domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
domElement.addEventListener( 'contextmenu', function ( event ) {
event.preventDefault();
}, false );
domElement.addEventListener( 'mousedown', onMouseDown, false );
domElement.addEventListener( 'mousewheel', onMouseWheel, false );
domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
......@@ -250,7 +258,9 @@ THREE.EditorControls = function ( object, domElement ) {
var closest = touches[ 0 ];
for ( var i in touches ) {
if ( closest.distanceTo(touch) > touches[ i ].distanceTo(touch) ) closest = touches[ i ];
if ( closest.distanceTo( touch ) > touches[ i ].distanceTo( touch ) ) closest = touches[ i ];
}
return closest;
......@@ -275,8 +285,8 @@ THREE.EditorControls = function ( object, domElement ) {
var offset0 = touches[ 0 ].clone().sub( getClosest( touches[ 0 ], prevTouches ) );
var offset1 = touches[ 1 ].clone().sub( getClosest( touches[ 1 ], prevTouches ) );
offset0.x = -offset0.x;
offset1.x = -offset1.x;
offset0.x = - offset0.x;
offset1.x = - offset1.x;
scope.pan( offset0.add( offset1 ).multiplyScalar( 0.5 ) );
......
......@@ -52,7 +52,7 @@ THREE.FirstPersonControls = function ( object, domElement ) {
if ( this.domElement !== document ) {
this.domElement.setAttribute( 'tabindex', -1 );
this.domElement.setAttribute( 'tabindex', - 1 );
}
......@@ -203,7 +203,7 @@ THREE.FirstPersonControls = function ( object, domElement ) {
var actualMoveSpeed = delta * this.movementSpeed;
if ( this.moveForward || ( this.autoForward && !this.moveBackward ) ) this.object.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
if ( this.moveForward || ( this.autoForward && ! this.moveBackward ) ) this.object.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
if ( this.moveBackward ) this.object.translateZ( actualMoveSpeed );
if ( this.moveLeft ) this.object.translateX( - actualMoveSpeed );
......@@ -214,7 +214,7 @@ THREE.FirstPersonControls = function ( object, domElement ) {
var actualLookSpeed = delta * this.lookSpeed;
if ( !this.activeLook ) {
if ( ! this.activeLook ) {
actualLookSpeed = 0;
......@@ -254,7 +254,11 @@ THREE.FirstPersonControls = function ( object, domElement ) {
};
this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
this.domElement.addEventListener( 'contextmenu', function ( event ) {
event.preventDefault();
}, false );
this.domElement.addEventListener( 'mousemove', bind( this, this.onMouseMove ), false );
this.domElement.addEventListener( 'mousedown', bind( this, this.onMouseDown ), false );
......
......@@ -7,7 +7,7 @@ THREE.FlyControls = function ( object, domElement ) {
this.object = object;
this.domElement = ( domElement !== undefined ) ? domElement : document;
if ( domElement ) this.domElement.setAttribute( 'tabindex', -1 );
if ( domElement ) this.domElement.setAttribute( 'tabindex', - 1 );
// API
......@@ -141,7 +141,7 @@ THREE.FlyControls = function ( object, domElement ) {
this.mousemove = function( event ) {
if ( !this.dragToLook || this.mouseStatus > 0 ) {
if ( ! this.dragToLook || this.mouseStatus > 0 ) {
var container = this.getContainerDimensions();
var halfWidth = container.size[ 0 ] / 2;
......@@ -204,11 +204,11 @@ THREE.FlyControls = function ( object, domElement ) {
this.updateMovementVector = function() {
var forward = ( this.moveState.forward || ( this.autoForward && !this.moveState.back ) ) ? 1 : 0;
var forward = ( this.moveState.forward || ( this.autoForward && ! this.moveState.back ) ) ? 1 : 0;
this.moveVector.x = ( -this.moveState.left + this.moveState.right );
this.moveVector.y = ( -this.moveState.down + this.moveState.up );
this.moveVector.z = ( -forward + this.moveState.back );
this.moveVector.x = ( - this.moveState.left + this.moveState.right );
this.moveVector.y = ( - this.moveState.down + this.moveState.up );
this.moveVector.z = ( - forward + this.moveState.back );
//console.log( 'move:', [ this.moveVector.x, this.moveVector.y, this.moveVector.z ] );
......@@ -216,9 +216,9 @@ THREE.FlyControls = function ( object, domElement ) {
this.updateRotationVector = function() {
this.rotationVector.x = ( -this.moveState.pitchDown + this.moveState.pitchUp );
this.rotationVector.y = ( -this.moveState.yawRight + this.moveState.yawLeft );
this.rotationVector.z = ( -this.moveState.rollRight + this.moveState.rollLeft );
this.rotationVector.x = ( - this.moveState.pitchDown + this.moveState.pitchUp );
this.rotationVector.y = ( - this.moveState.yawRight + this.moveState.yawLeft );
this.rotationVector.z = ( - this.moveState.rollRight + this.moveState.rollLeft );
//console.log( 'rotate:', [ this.rotationVector.x, this.rotationVector.y, this.rotationVector.z ] );
......@@ -254,7 +254,11 @@ THREE.FlyControls = function ( object, domElement ) {
}
this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
this.domElement.addEventListener( 'contextmenu', function ( event ) {
event.preventDefault();
}, false );
this.domElement.addEventListener( 'mousemove', bind( this, this.mousemove ), false );
this.domElement.addEventListener( 'mousedown', bind( this, this.mousedown ), false );
......
......@@ -9,9 +9,9 @@ THREE.MouseControls = function ( object ) {
var scope = this;
var PI_2 = Math.PI / 2;
var mouseQuat = {
x: new THREE.Quaternion(),
y: new THREE.Quaternion()
};
x: new THREE.Quaternion(),
y: new THREE.Quaternion()
};
var object = object;
var xVector = new THREE.Vector3( 1, 0, 0 );
var yVector = new THREE.Vector3( 0, 1, 0 );
......@@ -35,9 +35,9 @@ THREE.MouseControls = function ( object ) {
this.enabled = true;
this.orientation = {
x: 0,
y: 0,
};
x: 0,
y: 0,
};
this.update = function() {
......@@ -45,7 +45,7 @@ THREE.MouseControls = function ( object ) {
mouseQuat.x.setFromAxisAngle( xVector, this.orientation.x );
mouseQuat.y.setFromAxisAngle( yVector, this.orientation.y );
object.quaternion.copy(mouseQuat.y).multiply(mouseQuat.x);
object.quaternion.copy( mouseQuat.y ).multiply( mouseQuat.x );
return;
};
......
......@@ -7,7 +7,7 @@
*/
/*global THREE, console */
(function () {
( function () {
function OrbitConstraint ( object ) {
......@@ -260,7 +260,7 @@
if ( zoomChanged ||
lastPosition.distanceToSquared( this.object.position ) > EPS ||
8 * ( 1 - lastQuaternion.dot( this.object.quaternion) ) > EPS ) {
8 * ( 1 - lastQuaternion.dot( this.object.quaternion ) ) > EPS ) {
lastPosition.copy( this.object.position );
lastQuaternion.copy( this.object.quaternion );
......@@ -295,15 +295,15 @@
// API
Object.defineProperty(this, 'constraint', {
Object.defineProperty( this, 'constraint', {
get: function() {
get: function() {
return constraint;
return constraint;
}
}
});
} );
this.getPolarAngle = function () {
......@@ -366,7 +366,7 @@
var dollyEnd = new THREE.Vector2();
var dollyDelta = new THREE.Vector2();
var STATE = { NONE : -1, ROTATE : 0, DOLLY : 1, PAN : 2, TOUCH_ROTATE : 3, TOUCH_DOLLY : 4, TOUCH_PAN : 5 };
var STATE = { NONE : - 1, ROTATE : 0, DOLLY : 1, PAN : 2, TOUCH_ROTATE : 3, TOUCH_DOLLY : 4, TOUCH_PAN : 5 };
var state = STATE.NONE;
......@@ -556,11 +556,15 @@
var delta = 0;
if ( event.wheelDelta !== undefined ) { // WebKit / Opera / Explorer 9
if ( event.wheelDelta !== undefined ) {
// WebKit / Opera / Explorer 9
delta = event.wheelDelta;
} else if ( event.detail !== undefined ) { // Firefox
} else if ( event.detail !== undefined ) {
// Firefox
delta = - event.detail;
......@@ -746,7 +750,11 @@
}
this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
this.domElement.addEventListener( 'contextmenu', function ( event ) {
event.preventDefault();
}, false );
this.domElement.addEventListener( 'mousedown', onMouseDown, false );
this.domElement.addEventListener( 'mousewheel', onMouseWheel, false );
this.domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
......@@ -772,6 +780,7 @@
get: function () {
return this.constraint.object;
}
},
......@@ -921,6 +930,6 @@
}
});
} );
}());
}() );
......@@ -8,7 +8,7 @@
THREE.OrthographicTrackballControls = function ( object, domElement ) {
var _this = this;
var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
var STATE = { NONE: - 1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
this.object = object;
this.domElement = ( domElement !== undefined ) ? domElement : document;
......@@ -186,7 +186,7 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
}() );
this.rotateCamera = (function() {
this.rotateCamera = ( function() {
var axis = new THREE.Vector3(),
quaternion = new THREE.Quaternion();
......@@ -202,7 +202,7 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
angle *= _this.rotateSpeed;
quaternion.setFromAxisAngle( axis, -angle );
quaternion.setFromAxisAngle( axis, - angle );
_eye.applyQuaternion( quaternion );
_this.object.up.applyQuaternion( quaternion );
......@@ -223,9 +223,10 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
_changed = true;
}
}
}());
}() );
this.zoomCamera = function () {
......@@ -264,7 +265,7 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
};
this.panCamera = (function() {
this.panCamera = ( function() {
var mouseChange = new THREE.Vector2(),
objectUp = new THREE.Vector3(),
......@@ -301,21 +302,22 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
_changed = true;
}
}
}());
}() );
this.update = function () {
_eye.subVectors( _this.object.position, _this.target );
if ( !_this.noRotate ) {
if ( ! _this.noRotate ) {
_this.rotateCamera();
}
if ( !_this.noZoom ) {
if ( ! _this.noZoom ) {
_this.zoomCamera();
......@@ -327,7 +329,7 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
}
if ( !_this.noPan ) {
if ( ! _this.noPan ) {
_this.panCamera();
......@@ -385,15 +387,15 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
return;
} else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && !_this.noRotate ) {
} else if ( event.keyCode === _this.keys[ STATE.ROTATE ] && ! _this.noRotate ) {
_state = STATE.ROTATE;
} else if ( event.keyCode === _this.keys[ STATE.ZOOM ] && !_this.noZoom ) {
} else if ( event.keyCode === _this.keys[ STATE.ZOOM ] && ! _this.noZoom ) {
_state = STATE.ZOOM;
} else if ( event.keyCode === _this.keys[ STATE.PAN ] && !_this.noPan ) {
} else if ( event.keyCode === _this.keys[ STATE.PAN ] && ! _this.noPan ) {
_state = STATE.PAN;
......@@ -424,20 +426,20 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
}
if ( _state === STATE.ROTATE && !_this.noRotate ) {
if ( _state === STATE.ROTATE && ! _this.noRotate ) {
_rotateStart.copy( getMouseProjectionOnBall( event.pageX, event.pageY ) );
_rotateEnd.copy( _rotateStart );
} else if ( _state === STATE.ZOOM && !_this.noZoom ) {
} else if ( _state === STATE.ZOOM && ! _this.noZoom ) {
_zoomStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
_zoomEnd.copy(_zoomStart);
_zoomEnd.copy( _zoomStart );
} else if ( _state === STATE.PAN && !_this.noPan ) {
} else if ( _state === STATE.PAN && ! _this.noPan ) {
_panStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
_panEnd.copy(_panStart)
_panEnd.copy( _panStart )
}
......@@ -455,15 +457,15 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
event.preventDefault();
event.stopPropagation();
if ( _state === STATE.ROTATE && !_this.noRotate ) {
if ( _state === STATE.ROTATE && ! _this.noRotate ) {
_rotateEnd.copy( getMouseProjectionOnBall( event.pageX, event.pageY ) );
} else if ( _state === STATE.ZOOM && !_this.noZoom ) {
} else if ( _state === STATE.ZOOM && ! _this.noZoom ) {
_zoomEnd.copy( getMouseOnScreen( event.pageX, event.pageY ) );
} else if ( _state === STATE.PAN && !_this.noPan ) {
} else if ( _state === STATE.PAN && ! _this.noPan ) {
_panEnd.copy( getMouseOnScreen( event.pageX, event.pageY ) );
......@@ -495,11 +497,15 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
var delta = 0;
if ( event.wheelDelta ) { // WebKit / Opera / Explorer 9
if ( event.wheelDelta ) {
// WebKit / Opera / Explorer 9
delta = event.wheelDelta / 40;
} else if ( event.detail ) { // Firefox
} else if ( event.detail ) {
// Firefox
delta = - event.detail / 3;
......@@ -600,7 +606,11 @@ THREE.OrthographicTrackballControls = function ( object, domElement ) {
}
this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
this.domElement.addEventListener( 'contextmenu', function ( event ) {
event.preventDefault();
}, false );
this.domElement.addEventListener( 'mousedown', mousedown, false );
......
......@@ -45,7 +45,7 @@ THREE.PointerLockControls = function ( camera ) {
// assumes the camera itself is not rotated
var direction = new THREE.Vector3( 0, 0, -1 );
var direction = new THREE.Vector3( 0, 0, - 1 );
var rotation = new THREE.Euler( 0, 0, 0, "YXZ" );
return function( v ) {
......
......@@ -15,7 +15,7 @@ THREE.VRControls = function ( object, onError ) {
var oculusDevices = devices.filter( function ( device ) {
return device.deviceName.toLowerCase().indexOf('oculus') !== -1;
return device.deviceName.toLowerCase().indexOf( 'oculus' ) !== - 1;
} );
......@@ -23,7 +23,7 @@ THREE.VRControls = function ( object, onError ) {
return devices.filter( function ( device ) {
return device.deviceName.toLowerCase().indexOf('cardboard') === -1;
return device.deviceName.toLowerCase().indexOf( 'cardboard' ) === - 1;
} );
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -80,11 +80,14 @@ THREE.ConvexGeometry = function( vertices ) {
faces[ f ] = faces[ faces.length - 1 ];
faces.pop();
} else { // not visible
} else {
// not visible
f ++;
}
}
// construct the new faces formed by the edges of the hole and the vertex
......@@ -97,6 +100,7 @@ THREE.ConvexGeometry = function( vertices ) {
] );
}
}
/**
......@@ -208,7 +212,7 @@ THREE.ConvexGeometry = function( vertices ) {
this.faceVertexUvs[ 0 ].push( [
vertexUv( this.vertices[ face.a ] ),
vertexUv( this.vertices[ face.b ] ),
vertexUv( this.vertices[ face.c ])
vertexUv( this.vertices[ face.c ] )
] );
}
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册