Example #1
0
		function animateCell(cell, index, cells, resolve) {
			const { x: xP, y: yP } = impactCoordinate;
			const { x, y } = cell.userData;
			const circularDistanceFromImpact = Math.sqrt(Math.pow(xP - x, 2) + Math.pow(yP - y, 2));

			const { x: rotX, z: rotZ } = cell.rotation;
			const props = { posY: 0, rotX, rotZ };

			const tween = new TWEEN.Tween(props)
				.to({
					posY: [
						cell.position.y,
						(10 - circularDistanceFromImpact) * -0.1 * force,
						cell.position.y
					],
					rotX: [rotX, rotX + THREE.Math.degToRad((yP - y) * 2 * force), rotX],
					rotZ: [rotZ, rotZ + THREE.Math.degToRad((xP - x) * 2 * force), rotZ]
				}, 2000 / ANIMATION_SPEED_FACTOR)
				.delay(circularDistanceFromImpact * 20 / ANIMATION_SPEED_FACTOR)
				.easing(TWEEN.Easing.Elastic.Out)
				.onUpdate(() => {
					cell.position.y = props.posY; // eslint-disable-line
					cell.rotation.x = props.rotX; // eslint-disable-line
					cell.rotation.z = props.rotZ; // eslint-disable-line
				})
				.start();

			if (index === cells.length - 1) {
				tween.onComplete(() => resolve());
			}
		}
Example #2
0
        loader.load(url, (model) => {
            let container = new THREE.Object3D();

            container.matrixAutoUpdate = false;

            if (settings) {
                if (settings.scale) {
                    var s = settings.scale;

                    model.scale.set(s, s, s);
                }

                if (settings.rotation) {
                    var r = settings.rotation;

                    model.rotation.set(
                        THREE.Math.degToRad(r.x),
                        THREE.Math.degToRad(r.y),
                        THREE.Math.degToRad(r.z)
                    );
                }
            }

            container.add(model);

            this.model = container;

            this.addModel(this.model);

            this.render();
        });
Example #3
0
export default function pluginResize(context, config) {
	config = config || {};
	if (config.fov !== false) {
		config.fov = true;
	}

	window.addEventListener('resize', resize.bind(context, config), false);
	setTimeout(resize.bind(context, config), 0);

	if (config.fov) {
		if (!config.ratio) {
			config.ratio = 16 / 9;
		}

		config.y = 2 * ThreeMath.radToDeg(Math.atan(1 / config.ratio));
		config.height = 2 * Math.tan(ThreeMath.degToRad(config.y / 2));

		config.x = 2 * ThreeMath.radToDeg(Math.atan(config.height / 2 * config.ratio));
		config.width = 2 * Math.tan(ThreeMath.degToRad(config.x / 2));

		if (config.helper) {
			const geometry = new BoxGeometry(config.width / config.height, 1, 1);
			const material = new MeshBasicMaterial({ wireframe: true });

			context.fov_helper = new Mesh(geometry, material);
			context.fov_helper.position.set(0, 0, -1 / config.height - 0.5);
			context.camera.add(context.fov_helper);
		}
	}
}
Example #4
0
Ellipsoid.prototype.cartesianToCartographic = function cartesianToCartographic(position, target = new Coordinates('EPSG:4326', 0, 0, 0)) {
    // for details, see for example http://www.linz.govt.nz/data/geodetic-system/coordinate-conversion/geodetic-datum-conversions/equations-used-datum
    // TODO the following is only valable for oblate ellipsoid of revolution. do we want to support triaxial ellipsoid?
    const R = Math.sqrt(position.x * position.x + position.y * position.y + position.z * position.z);
    const a = this.rayon_1; // x
    const b = this.rayon_3; // z
    const e = Math.abs((a * a - b * b) / (a * a));
    const f = 1 - Math.sqrt(1 - e);
    const rsqXY = Math.sqrt(position.x * position.x + position.y * position.y);

    const theta = Math.atan2(position.y, position.x);
    const nu = Math.atan(position.z / rsqXY * ((1 - f) + e * a / R));

    const sinu = Math.sin(nu);
    const cosu = Math.cos(nu);

    const phi = Math.atan((position.z * (1 - f) + e * a * sinu * sinu * sinu) / ((1 - f) * (rsqXY - e * a * cosu * cosu * cosu)));

    const h = (rsqXY * Math.cos(phi)) + position.z * Math.sin(phi) - a * Math.sqrt(1 - e * Math.sin(phi) * Math.sin(phi));

    return target.set('EPSG:4326',
        THREE.Math.radToDeg(theta),
        THREE.Math.radToDeg(phi),
        h);
};
Example #5
0
PanoramaTileBuilder.prototype.uProjecte = function uProjecte(u, params) {
    // both (theta, phi) and (y, z) are swapped in setFromSpherical
    params.projected.theta = THREE.Math.degToRad(90 - THREE.Math.lerp(
        params.extent.east(),
        params.extent.west(),
        1 - u));
};
Example #6
0
File: lines.js Project: hahla/hahla
    function render() {
        theta += 0.1;
        camera.position.x = radius * Math.sin( THREE.Math.degToRad( theta ) );
        camera.position.y = radius * Math.sin( THREE.Math.degToRad( theta ) );
        camera.position.z = radius * Math.cos( THREE.Math.degToRad( theta ) );
        camera.lookAt( scene.position );

        // find intersections
        var vector = new THREE.Vector3( mouse.x, mouse.y, 1 ).unproject( camera );
        raycaster.set( camera.position, vector.sub( camera.position ).normalize() );
        var intersects = raycaster.intersectObjects( parentTransform.children, true);
        if ( intersects.length > 0 ) {
            if ( currentIntersected !== undefined ) {
                currentIntersected.material.linewidth = 1;
            }
            currentIntersected = intersects[ 0 ].object;
            currentIntersected.material.linewidth = 5;
            sphereInter.visible = true;
            sphereInter.position.copy( intersects[ 0 ].point );
        } else {
            if ( currentIntersected !== undefined ) {
                currentIntersected.material.linewidth = 1;
            }
            currentIntersected = undefined;
            sphereInter.visible = false;
        }
        renderer.render( scene, camera );
    }
Example #7
0
    (function update() {

      window.requestAnimationFrame(update.bind(this));

      if (this.freeze) return;

      // should not need this
      var orientation = getOrientation();
      if (orientation !== this.screenOrientation) {
        this.screenOrientation = orientation;
        this.autoAlign = true;
      }

      this.alpha = this.deviceOrientation.gamma ?
        THREE.Math.degToRad(this.deviceOrientation.alpha) : 0; // Z
      this.beta = this.deviceOrientation.beta ?
        THREE.Math.degToRad(this.deviceOrientation.beta) : 0; // X'
      this.gamma = this.deviceOrientation.gamma ?
        THREE.Math.degToRad(this.deviceOrientation.gamma) : 0; // Y''
      this.orient = this.screenOrientation ?
        THREE.Math.degToRad(this.screenOrientation) : 0; // O

      // The angles alpha, beta and gamma
      // form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''

      // 'ZXY' for the device, but 'YXZ' for us
      euler.set(this.beta, this.alpha, - this.gamma, 'YXZ');

      quaternion.setFromEuler(euler);
      quaternionLerp.slerp(quaternion, 0.5); // interpolate

      // orient the device
      if (this.autoAlign) this.orientationQuaternion.copy(quaternion); // interpolation breaks the auto alignment
      else this.orientationQuaternion.copy(quaternionLerp);

      // camera looks out the back of the device, not the top
      this.orientationQuaternion.multiply(q1);

      // adjust for screen orientation
      this.orientationQuaternion.multiply(q0.setFromAxisAngle(zee, - this.orient));

      finalQuaternion.copy(this.alignQuaternion);
      finalQuaternion.multiply(this.orientationQuaternion);

      finalEuler.setFromQuaternion(finalQuaternion, 'YXZ');

      if (this.autoAlign && this.alpha !== 0) {

        this.autoAlign = false;

        this.align();

      }

      this.setState({ euler: finalEuler });

    }).call(this);
Example #8
0
	this.update = function () {

		var alpha = scope.deviceOrientation.alpha ? THREE.Math.degToRad(scope.deviceOrientation.alpha) : 0; // Z
		var beta = scope.deviceOrientation.beta ? THREE.Math.degToRad(scope.deviceOrientation.beta) : 0; // X'
		var gamma = scope.deviceOrientation.gamma ? THREE.Math.degToRad(scope.deviceOrientation.gamma) : 0; // Y''
		var orient = scope.screenOrientation ? THREE.Math.degToRad(scope.screenOrientation) : 0; // O
		//scope.object.quaternion
		deviceQuat = createQuaternion(alpha, beta, gamma, orient);

	};
export default (tiltAngle, panAngle, rollAngle, color) => {
  headMaterial.color = new THREE.Color(color)

  group.rotation.x = THREE.Math.degToRad(-tiltAngle)
  group.rotation.y = THREE.Math.degToRad(panAngle)
  group.rotation.z = THREE.Math.degToRad(-rollAngle)

  renderer.render(scene, camera)

  return renderer.domElement.toDataURL()
}
    return function(delta) {
      if (this.freeze) {
        return;
      }

      this.alpha = deviceOrientation.gamma ?
        THREE.Math.degToRad(deviceOrientation.alpha) : 0; // Z
      this.beta = deviceOrientation.beta ?
        THREE.Math.degToRad(deviceOrientation.beta) : 0; // X'
      this.gamma = deviceOrientation.gamma ?
        THREE.Math.degToRad(deviceOrientation.gamma) : 0; // Y''
      this.orient = screenOrientation ?
        THREE.Math.degToRad(screenOrientation) : 0; // O

      // The angles alpha, beta and gamma
      // form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''

      // 'ZXY' for the device, but 'YXZ' for us
      euler.set(this.beta, this.alpha, - this.gamma, 'YXZ');

      quaternion.setFromEuler(euler);
      quaternionLerp.slerp(quaternion, 0.5); // interpolate

      // orient the device
      if (this.autoAlign) {
        this.orientationQuaternion.copy(quaternion); // interpolation breaks the auto alignment
      } else {
        this.orientationQuaternion.copy(quaternionLerp);
      }

      // camera looks out the back of the device, not the top
      this.orientationQuaternion.multiply(q1);

      // adjust for screen orientation
      this.orientationQuaternion.multiply(q0.setFromAxisAngle(zee, - this.orient));

      this.object.quaternion.copy(this.alignQuaternion);
      this.object.quaternion.multiply(this.orientationQuaternion);

      if (this.autoForward) {

        tempVector3
          .set(0, 0, -1)
          .applyQuaternion(this.object.quaternion, 'ZXY')
          .setLength(this.movementSpeed / 50); // TODO: why 50 :S

        this.object.position.add(tempVector3);
      }

      if (this.autoAlign && this.alpha !== 0) {
        this.autoAlign = false;
        this.align();
      }
    };
Example #11
0
Ellipsoid.prototype.geodeticSurfaceNormalCartographic = function geodeticSurfaceNormalCartographic(coordCarto, target = new THREE.Vector3()) {
    var longitude = THREE.Math.degToRad(coordCarto.longitude());
    var latitude = THREE.Math.degToRad(coordCarto.latitude());
    var cosLatitude = Math.cos(latitude);

    var x = cosLatitude * Math.cos(longitude);
    var y = cosLatitude * Math.sin(longitude);
    var z = Math.sin(latitude);

    return target.set(x, y, z);
};
Example #12
0
 function render() {
   theta += 0.1;
   camera.position.x = radius * Math.sin( THREE.Math.degToRad( theta ) );
   camera.position.z = radius * Math.cos( THREE.Math.degToRad( theta ) );
   camera.lookAt( camera.target );
   if ( mixer ) {
     var time = Date.now();
     mixer.update( ( time - prevTime ) * 0.001 );
     prevTime = time;
   }
   renderer.render( scene, camera );
 }
Example #13
0
PanoramaTileBuilder.prototype.vProjecte = function vProjecte(v, params) {
    if (this.projectionType === ProjectionType.SPHERICAL) {
        params.projected.phi = THREE.Math.degToRad(90 -
            THREE.Math.lerp(
                params.extent.north(),
                params.extent.south(),
                1 - v));
    } else {
        params.projected.y =
            this.height *
            THREE.Math.lerp(params.extent.south(), params.extent.north(), v) / 180;
    }
};
Example #14
0
  updateOrientationScene(orientation, motion) {
    const radOrientation = THREE.Math.degToRad(orientation);
    const radAlpha = THREE.Math.degToRad(motion.alpha);
    const radBeta = THREE.Math.degToRad(motion.beta);
    const radGamma = THREE.Math.degToRad(motion.gamma);

    if (this.camera) {
      this.updateCameraQuaternion(radAlpha, radBeta, radGamma, radOrientation);
      // Render manually if the render loop is stopped
      if (!this.requestId) {
        this.renderer.render(this.scene, this.camera);
      }
    }
  }
Example #15
0
 render: function() {
   return div(
     {
       className: 'viewport',
       style: {
         perspective: '600px',
         position: 'absolute',
         overflow: 'hidden',
         top: '0',
         bottom: '0',
         left: this.props.eye === 'left' ? '0' : '50%',
         right: this.props.eye === 'right' ? '0' : '50%'
       }
     },
     div({
       className: 'head',
       style: {
         transformStyle: 'preserve-3d',
         transformOrigin: '0 0 500px',
         perspective: '600px',
         position: 'absolute',
         top: '0',
         left: '0',
         right: '0',
         bottom: '0',
         transform:
           'rotateY(' + (-THREE.Math.radToDeg(this.state.euler.y)) + 'deg) ' +
           'rotateX(' + (THREE.Math.radToDeg(this.state.euler.x)) + 'deg) ' +
           'rotateZ(' + (THREE.Math.radToDeg(this.state.euler.z)) + 'deg)'
       }
     },
       div({
           className: 'eye',
           style: {
             transformStyle: 'preserve-3d',
             perspective: '600px',
             transform: 'translateX(' + (this.props.eye === 'right' ? '-' : '') + '25px)',
             position: 'absolute',
             top: '0',
             bottom: '0',
             left: '0',
             right: '0'
           }
         },
         this.props.component()
       )
     )
   );
 }
Example #16
0
File: euler.js Project: as334/dom
 function parseRadianOrDegrees (x) {
   if (x.match(/(d|deg)$/i)) {
     return THREE.Math.degToRad(parseFloat(x));
   } else {
     return parseFloat(x);
   }
 }
 self.onKeyup = function( event ) {
     switch ( event.keyCode ) {
         case 17: // Ctrl
             self.transformControls.setRotationSnap( THREE.Math.degToRad( 15 ) );
             break;
     }
 };
    constructor (options) {
        options = options || {};

        const w = GraphicsEngine.WindowWidth;
        const h = GraphicsEngine.WindowHeight;

        this.scene = new THREE.Scene();

        this.camera = new THREE.PerspectiveCamera(15, w / h, 0.1, Number.MAX_SAFE_INTEGER);
        this.camera.position.set(10, 15, 100);
        this.scene.add(this.camera);

        this.lookAt = new THREE.Object3D();
        this.scene.add(this.lookAt);
        this.lookAt.add(this.camera);
        this.camera.lookAt(this.lookAt.position);

        if (GraphicsEngine.isWebglAvailable()) {
            this.renderer = new THREE.WebGLRenderer(options);
        } else {
            this.renderer = new THREE.CanvasRenderer(options);
        }
        this.renderer.setSize(w, h);
        this.renderer.shadowMapEnabled = true;

        var geometry = new THREE.PlaneGeometry(1000, 1000, 10, 10);
        var material = new THREE.MeshLambertMaterial({
            color: new THREE.Color(0, 0, 1)
        });
        var ground = new THREE.Mesh(geometry, material);
        ground.rotation.x = THREE.Math.degToRad(-90);
        ground.receiveShadow = true;
        this.scene.add(ground);

        this.controls = new THREE.OrbitControls(this.camera, this.renderer.domElement);
        this.controls.enableDamping = true;
        this.controls.dampingFactor = 0.25;
        this.controls.enableZoom = true;

        geometry = new THREE.BoxGeometry(10, 10, 10);
        var cube = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial({
            color: new THREE.Color(0, 1, 0),
            side: THREE.DoubleSide
        }));
        cube.position.y = 5;
        cube.castShadow = true;
        this.scene.add(cube);
        this.cube = cube;

        var ambientLight = new THREE.AmbientLight('#666');
        this.scene.add(ambientLight);

        var pointLight1 = new THREE.PointLight('#ffffff');
        pointLight1.position.set(10, 20, 30);
        pointLight1.intensity = 0.8;
        pointLight1.castShadow = true;
        this.scene.add(pointLight1);

        this.isAnimating = true;
    }
Example #19
0
    this.initiateSmartZoom = function initiateSmartZoom() {
        // point under mouse cursor
        const pointUnderCursor = new THREE.Vector3();

        // check if there is valid geometry under cursor
        if (typeof this.view.getPickingPositionFromDepth(mousePosition) !== 'undefined') {
            pointUnderCursor.copy(this.view.getPickingPositionFromDepth(mousePosition));
        }
        else {
            return;
        }

        // direction of the movement, projected on xy plane and normalized
        const dir = new THREE.Vector3();
        dir.copy(pointUnderCursor).sub(this.camera.position);
        dir.z = 0;
        dir.normalize();

        const distanceToPoint = this.camera.position.distanceTo(pointUnderCursor);

        // camera height (altitude above ground) at the end of the travel, 5000 is an empirical smoothing distance
        const targetHeight = THREE.Math.lerp(this.smartZoomHeightMin, this.smartZoomHeightMax, Math.min(distanceToPoint / 5000, 1));

        // camera position at the end of the travel
        const moveTarget = new THREE.Vector3();

        moveTarget.copy(pointUnderCursor).add(dir.multiplyScalar(-targetHeight * 2));
        moveTarget.z = pointUnderCursor.z + targetHeight;

        // initiate the travel
        this.initiateTravel(moveTarget, 'auto', pointUnderCursor, true);
    };
  update () {
    if (this.enabled === false || !this.deviceOrientation || this.deviceOrientation.alpha === null) {
      return
    }

    const alpha = this.deviceOrientation.alpha ? MathExtra.degToRad(this.deviceOrientation.alpha) : 0 // Z
    const beta = this.deviceOrientation.beta ? MathExtra.degToRad(this.deviceOrientation.beta) : 0 // X'
    const gamma = this.deviceOrientation.gamma ? MathExtra.degToRad(this.deviceOrientation.gamma) : 0 // Y''
    const orient = this.screenOrientation ? MathExtra.degToRad(this.screenOrientation) : 0 // O

    euler.set(beta, alpha, -gamma, 'YXZ') // 'ZXY' for the device, but 'YXZ' for us

    this.object.quaternion.setFromEuler(euler) // orient the device
    this.object.quaternion.multiply(q1) // camera looks out the back of the device, not the top
    this.object.quaternion.multiply(q0.setFromAxisAngle(zee, -orient)) // adjust for screen orientation
  }
Example #21
0
  updateVelocity: function(dt) {
    var velocity, dVelocity,
        data = this.data;
    var keys = this.keys;

    dVelocity = this.getVelocityDelta(dt);
    velocity = this.velocity;
    velocity.copy(this.parent.getAttribute('velocity'));
    velocity.x -= velocity.x * data.movementEasing * dt / 1000;
    velocity.z -= velocity.z * data.movementEasing * dt / 1000;

    if (dVelocity) {
      // Set acceleration
      if (dVelocity.length() > 1) {
        dVelocity.setLength(this.data.movementAcceleration * dt / 1000);
      } else {
        dVelocity.multiplyScalar(this.data.movementAcceleration * dt / 1000);
      }

      // Rotate to heading
      var rotation = this.el.getAttribute('rotation');
      if (rotation) {
        this.heading.set(0, THREE.Math.degToRad(rotation.y), 0);
        dVelocity.applyEuler(this.heading);
      }
      velocity.add(dVelocity);
    }

    this.parent.setAttribute('velocity', velocity);

  },
Example #22
0
 render(){
   return(
     <div>
       <Controls
         headSize={this.state.headSize}
         bodyWidth={this.state.bodyWidth}
         bodyHeight={this.state.bodyHeight}
         bodyDepth={this.state.bodyDepth}
         armLength={this.state.armLength}
         armSize={this.state.armSize}
         legLength={this.state.legLength}
         legSize={this.state.legSize}
       />
       <Scene3D
         sliderBusy={this.state.sliderBusy}
         cameraPosition={this.state.cameraPosition}
         cameraQuaternion={this.state.cameraQuaternion}
       >
         <World
           position={new THREE.Vector3(0, 0, 0)}
           worldRotation={this.state.worldRotation}
         >
           <Minecraft
             key={THREE.Math.generateUUID()}
             position={new THREE.Vector3(0, 0, 0)}
             quaternion={new THREE.Quaternion()}
             scale={new THREE.Vector3(1, 1, 1)}
             config={this.state.config}
           />
         </World>
       </Scene3D>
       <Stats />
     </div>
   );
 }
Example #23
0
	return function( particle ) {

		var vertexIndex;

		if ( position === undefined )
		{
			position = new THREE.Vector3();
		}
		
		// first, call method of base prototype
		Emitter.prototype.emit.call( this, particle );

		// determine randomly a vertex from the geometry
		vertexIndex = THREE.Math.randInt( 0, this.mesh.geometry.vertices.length - 1 );

		// copy the vertex data to the position vector of the particle
		particle.position.copy( this.mesh.geometry.vertices[ vertexIndex ] );

		// finally, we need to apply the world matrix of the mesh to calculate
		// the world position of the particle
		particle.position.applyMatrix4( this.mesh.matrixWorld );
		
		// calculate default movement direction
		if ( this.defaultDirection === true ){
			
			// the vertex normal determines the movement direction of the particle
			particle.direction.copy( this._vertexNormals[ vertexIndex ] );

			// transform the direction/normal to world space
			particle.direction.applyMatrix3( this._normalMatrix ).normalize();
		}
		
	};
Example #24
0
 constructor() {
   this.userData = {};
   this.name = null;
   this.value = null;
   this.type = null;
   this.uuid = THREE.Math.generateUUID();
 }
Example #25
0
 function update() {
   if (isUserInteracting === false) {
     lon += 0.1;
   }
   lat = Math.max(-85, Math.min(85, lat));
   phi = THREE.Math.degToRad(90 - lat);
   theta = THREE.Math.degToRad(lon);
   target.x = 500 * Math.sin(phi) * Math.cos(theta);
   target.y = 500 * Math.cos(phi);
   target.z = 500 * Math.sin(phi) * Math.sin(theta);
   camera.position.copy(target).negate();
   camera.lookAt(target);
   renderer.render(scene, camera);
   gl.flush();
   endFrame(gl);
 }
Example #26
0
Regulator.prototype.isReady = function() {

	// if a regulator is instantiated with a zero frequency then it goes into
	// stealth mode (doesn't regulate)
	if ( this._updatePeriod === 0 )
	{
		return true;
	}

	// if the regulator is instantiated with a negative frequency then it will
	// never allow the code to flow
	if ( this._updatePeriod < 0 )
	{
		return false;
	}

	// retrieve timestamp
	this._currentTime = global.performance.now();

	// if the current timestamp is equal or greater than the "nextUpdateTime"
	// allow the code to flow
	if ( this._currentTime >= this._nextUpdateTime )
	{
		// calculate next update time
		this._nextUpdateTime = this._currentTime + this._updatePeriod + THREE.Math.randFloat( -updatePeriodVariator, updatePeriodVariator );

		return true;
	}

	return false;
};
Example #27
0
	render(renderer, readBuffer, writeBuffer) {

		let uniforms = this.material.uniforms;

		uniforms.tDiffuse.value = readBuffer.texture;
		uniforms.seed.value = Math.random();
		uniforms.active.value = true;

		if(this.counter % this.breakPoint === 0 || this.mode === GlitchPass.Mode.CONSTANT_WILD) {

			uniforms.amount.value = Math.random() / 30.0;
			uniforms.angle.value = THREE.Math.randFloat(-Math.PI, Math.PI);
			uniforms.seedX.value = THREE.Math.randFloat(-1.0, 1.0);
			uniforms.seedY.value = THREE.Math.randFloat(-1.0, 1.0);
			uniforms.distortionX.value = THREE.Math.randFloat(0.0, 1.0);
			uniforms.distortionY.value = THREE.Math.randFloat(0.0, 1.0);
			this.counter = 0;
			this.generateTrigger();

		} else if(this.counter % this.breakPoint < this.breakPoint / 5 || this.mode === GlitchPass.Mode.CONSTANT_MILD) {

			uniforms.amount.value = Math.random() / 90.0;
			uniforms.angle.value = THREE.Math.randFloat(-Math.PI, Math.PI);
			uniforms.distortionX.value = THREE.Math.randFloat(0.0, 1.0);
			uniforms.distortionY.value = THREE.Math.randFloat(0.0, 1.0);
			uniforms.seedX.value = THREE.Math.randFloat(-0.3, 0.3);
			uniforms.seedY.value = THREE.Math.randFloat(-0.3, 0.3);

		} else if(this.mode === GlitchPass.Mode.SPORADIC) {

			uniforms.active.value = false;

		}

		++this.counter;

		if(this.renderToScreen) {

			renderer.render(this.scene, this.camera);

		} else {

			renderer.render(this.scene, this.camera, writeBuffer, false);

		}

	}
Example #28
0
	this.update = function ( delta ) {

		var srcRange, dstRange;

		if( this.lookHorizontal ) this.lon += this.mouseX * this.lookSpeed * delta;
		if( this.lookVertical )   this.lat -= this.mouseY * this.lookSpeed * delta;

		this.lon = Math.max( 0, Math.min( 360, this.lon ) );
		this.lat = Math.max( - 85, Math.min( 85, this.lat ) );

		this.phi = ( 90 - this.lat ) * PI180;
		this.theta = this.lon * PI180;

		this.phi = normalize_angle_rad( this.phi );

		// constrain vertical look angle

		srcRange = this.verticalAngleMap.srcRange;
		dstRange = this.verticalAngleMap.dstRange;

		var tmpPhi = THREE.Math.mapLinear( this.phi, srcRange[ 0 ], srcRange[ 1 ], dstRange[ 0 ], dstRange[ 1 ] );
		var tmpPhiFullRange = dstRange[ 1 ] - dstRange[ 0 ];
		var tmpPhiNormalized = ( tmpPhi - dstRange[ 0 ] ) / tmpPhiFullRange;

		this.phi = QuadraticEaseInOut( tmpPhiNormalized ) * tmpPhiFullRange + dstRange[ 0 ];

		// constrain horizontal look angle

		srcRange = this.horizontalAngleMap.srcRange;
		dstRange = this.horizontalAngleMap.dstRange;

		var tmpTheta = THREE.Math.mapLinear( this.theta, srcRange[ 0 ], srcRange[ 1 ], dstRange[ 0 ], dstRange[ 1 ] );
		var tmpThetaFullRange = dstRange[ 1 ] - dstRange[ 0 ];
		var tmpThetaNormalized = ( tmpTheta - dstRange[ 0 ] ) / tmpThetaFullRange;

		this.theta = QuadraticEaseInOut( tmpThetaNormalized ) * tmpThetaFullRange + dstRange[ 0 ];

		var targetPosition = this.target.position,
			position = this.object.position;

		targetPosition.x = 100 * Math.sin( this.phi ) * Math.cos( this.theta );
		targetPosition.y = 100 * Math.cos( this.phi );
		targetPosition.z = 100 * Math.sin( this.phi ) * Math.sin( this.theta );

		this.object.lookAt( this.target.position );

	};
Example #29
0
	render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {

		this.uniforms[ "tDiffuse" ].value = readBuffer.texture;
		this.uniforms[ 'seed' ].value = Math.random();//default seeding
		this.uniforms[ 'byp' ].value = 0;

		if ( this.curF % this.randX == 0 || this.goWild == true ) {

			this.uniforms[ 'amount' ].value = Math.random() / 30;
			this.uniforms[ 'angle' ].value = THREE.Math.randFloat( - Math.PI, Math.PI );
			this.uniforms[ 'seed_x' ].value = THREE.Math.randFloat( - 1, 1 );
			this.uniforms[ 'seed_y' ].value = THREE.Math.randFloat( - 1, 1 );
			this.uniforms[ 'distortion_x' ].value = THREE.Math.randFloat( 0, 1 );
			this.uniforms[ 'distortion_y' ].value = THREE.Math.randFloat( 0, 1 );
			this.curF = 0;
			this.generateTrigger();

		} else if ( this.curF % this.randX < this.randX / 5 ) {

			this.uniforms[ 'amount' ].value = Math.random() / 90;
			this.uniforms[ 'angle' ].value = THREE.Math.randFloat( - Math.PI, Math.PI );
			this.uniforms[ 'distortion_x' ].value = THREE.Math.randFloat( 0, 1 );
			this.uniforms[ 'distortion_y' ].value = THREE.Math.randFloat( 0, 1 );
			this.uniforms[ 'seed_x' ].value = THREE.Math.randFloat( - 0.3, 0.3 );
			this.uniforms[ 'seed_y' ].value = THREE.Math.randFloat( - 0.3, 0.3 );

		} else if ( this.goWild == false ) {

			this.uniforms[ 'byp' ].value = 1;

		}

		this.curF ++;
		this.quad.material = this.material;

		if ( this.renderToScreen ) {

			renderer.render( this.scene, this.camera );

		} else {

			renderer.render( this.scene, this.camera, writeBuffer, this.clear );

		}

	},
Example #30
0
THREE.MTLLoader.ensurePowerOfTwo_ = function ( image ) {

	if ( ! THREE.Math.isPowerOfTwo( image.width ) || ! THREE.Math.isPowerOfTwo( image.height ) ) {

		var canvas = document.createElement( "canvas" );
		canvas.width = THREE.MTLLoader.nextHighestPowerOfTwo_( image.width );
		canvas.height = THREE.MTLLoader.nextHighestPowerOfTwo_( image.height );

		var ctx = canvas.getContext("2d");
		ctx.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
		return canvas;

	}

	return image;

};