Example #1
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();
        });
function createCSS3DObject(data) {
    const get = (key1, key2, fallback=0) => data.get(key1, EMPTY_MAP).get(key2) || fallback;
    const position = (key2) => get('position', key2);
    const display = (key2) => get('display', key2);
    const degToRadians = (deg) => (deg / 360) * 2 * Math.PI;
    const rotation = (key2) => degToRadians(get('rotation', key2));

    const div = document.createElement('div');
    div.style = display('style') || '';
    div.style.width = `${display('width')}px`;
    div.style.height = `${display('height')}px`;
    const CSS3DObject = new THREE.CSS3DObject(div);

    let Object3D = CSS3DObject;
    if (display('pivot') == 'top') {
        CSS3DObject.position.y = -display('height')/2;
        Object3D = new THREE.Object3D();
        Object3D.add(CSS3DObject);
        Object3D.element = div;
    }

    Object3D.position.set(position('x'), position('y'), position('z'));
    Object3D.rotation.set(rotation('x'), rotation('y'), rotation('z'));
    return Object3D;
}
/**
 * Background floating particles/strips
 *
 * @class BackgroundParticles
 * @constructor
 * @param {Object} [options]
 * @param {Object} [strips=true] Strips?
 * @param {Number} [options.count=1000] Number of particles
 * @param {Number} [options.particleSize=0.5] Size of a particle
 * @param {Array} [options.rangeY=[-100, 100]] Y range for positions
 * @requires jQuery, THREE, random
 */
function BackgroundParticles (options) {
  var parameters = jQuery.extend({
    count: 1000,
    particleSize: 0.5,
    rangeY: [-100, 100],
    strips: true,
    stripsCount: 20
  }, options);

  var material = new THREE.PointCloudMaterial({
    size: parameters.particleSize
  });

  var geometry = new THREE.Geometry();

  for (var i = 0; i < parameters.count; i++) {
    var particle = new THREE.Vector3(
      random(-50, 50),
      random(parameters.rangeY[0], parameters.rangeY[1]),
      random(-50, 100)
    );

    geometry.vertices.push(particle);
  }

  var group = new THREE.Object3D();

  group.add(new THREE.PointCloud(geometry, material));
  
  if (parameters.strips) {
    var stripsGeometry = new THREE.Geometry();

    var stripGeometry = new THREE.PlaneGeometry(5, 2);
    var stripMaterial = new THREE.MeshLambertMaterial({ color: '#666666' });

    for (var i = 0; i < parameters.stripsCount; i++) {
      var stripMesh = new THREE.Mesh(stripGeometry, stripMaterial);
      stripMesh.position.set(
        random(-50, 50),
        random(parameters.rangeY[0], parameters.rangeY[1]),
        random(-50, 0)
      );

      stripMesh.scale.set(
        random(0.5, 1),
        random(0.1, 1),
        1
      );

      stripMesh.updateMatrix();
      stripsGeometry.merge(stripMesh.geometry, stripMesh.matrix);
    } 

    var totalMesh = new THREE.Mesh(stripsGeometry, stripMaterial);

    group.add(totalMesh);
  }

  this.el = group;
}
Example #4
0
    type_more(portion, cursor_visible) {
        // Add one more letter
        if (portion > this.text.length) {
            portion = this.text.length;

            // Notify that the animation has ended
            if (_.isFunction(this.after)) {
                this.after();
                delete this.after;
            }
        }

        // Cleanup old mesh
        this.mesh.remove(this.text_mesh);
        this.text_mesh.geometry.dispose();

        // Create new mesh
        let current_text = this.text.substr(0, portion);
        if (cursor_visible) {
            current_text += this.cursor.text;
        }
        this.geometry = this.make_text(current_text);
        this.text_mesh = new THREE.Mesh(this.geometry, this.material);

        // Add it back to the group
        this.mesh.add(this.text_mesh);
    }
 composeText(text) {
     if (!fontsLoaded) {
         return null;
     }
     // 32 is the ASCII code for white space.
     const charIndices = _.map(text, l => l.charCodeAt(0) - 32);
     const letterOffset = 0.4;
     const textMesh = new THREE.Object3D();
     for (let j = 0; j < charIndices.length; j++) {
         const idx = charIndices[j];
         let pIdx = this.charPointers[idx];
         if (pIdx === undefined) {
             pIdx = 0;
             this.charPointers[idx] = pIdx;
         }
         if (this.charMeshes[idx] === undefined) {
             this.charMeshes[idx] = [];
         }
         let mesh = this.charMeshes[idx][pIdx];
         if (mesh === undefined) {
             if (this.charMeshes[idx].length > 0) {
                 mesh = this.charMeshes[idx][0].clone();
             } else {
                 mesh = this.drawChar3D(text[j]);
             }
             this.charMeshes[idx].push(mesh);
         }
         mesh.position.set((j - charIndices.length / 2) * letterOffset, 0, 0);
         this.charPointers[idx]++;
         textMesh.add(mesh);
     }
     return textMesh;
 }
Example #6
0
File: player.js Project: calrk/LD32
	attackAnim () {
		if(this.isVR){
			return;
		}
		this.model.getObjectByName('weapon').rotation.x = this.interpolator([0, 0.33, 0.66, 1], [0, 0.35, -0.75, 0], this.interpPercent);
		this.model.getObjectByName('weapon').rotation.z = this.interpolator([0, 0.33, 0.66, 1], [0, -0.1, 0.25, 0], this.interpPercent);
	}
Example #7
0
function init() {

    camera = new THREE.PerspectiveCamera(55, window.innerWidth / window.innerHeight, 20, 3000);
    camera.position.z = 1000;

    scene = new THREE.Scene();

    //init object to hold cubes and rotate
    cubeHolder = new THREE.Object3D();
    scene.add(cubeHolder);

    //add light
    var light = new THREE.PointLight(0xFFFFFF, 1);
    light.position.set(1000, 1000, 1000);
    scene.add(light);

    //use lambert material to get greyscale shadows
    var material = new THREE.MeshLambertMaterial();

    //create cubes
    var geometry = new THREE.BoxGeometry(100, 100, 100);
    var spread = 2000;
    for(var j = 0; j < 100; j++) {
        var cube = new THREE.Mesh(geometry, material);
        //randomize size, posn + rotation
        cube.scale.x = cube.scale.y = cube.scale.z = Math.random() * 3 + .05;
        cubeHolder.add(cube);
        cube.position.x = Math.random() * spread - spread / 2;
        cube.position.y = Math.random() * spread - spread / 2;
        cube.position.z = Math.random() * spread - spread / 2;
        cube.rotation.x = Math.random() * 2 * Math.PI - Math.PI;
        cube.rotation.y = Math.random() * 2 * Math.PI - Math.PI;
        cube.rotation.z = Math.random() * 2 * Math.PI - Math.PI;
    }

    //init renderer
    renderer = new THREE.WebGLRenderer();
    renderer.setSize( window.innerWidth, window.innerHeight );

    document.body.appendChild( renderer.domElement );

    //POST PROCESSING
    //Create Shader Passes
    //render pass renders scene into effects composer
    var renderPass = new THREE.RenderPass( scene, camera );
    kaleidoPass = new THREE.ShaderPass( THREE.KaleidoShader );

    //Add Shader Passes to Composer
    //order is important
    composer = new THREE.EffectComposer( renderer );
    composer.addPass( renderPass );
    composer.addPass( kaleidoPass );

    //set last pass in composer chain to renderToScreen
    kaleidoParams = {
        sides: 12,
        angle: 0.0
    };
}
Example #8
0
/**
 * Animated water ripple
 *
 * @class Drop
 * @constructor
 * @param {Object} [options]
 * @param {Number} [options.count=6] Rings number
 * @param {String} [options.color='#ffffff'] Rings color
 * @param {Number} [options.amplitude=2] Rings max expanded amplitude 
 * @requires jQuery, THREE, TweenLite, loop
 */
function Drop (options) {
  this.parameters = jQuery.extend({
    count: 6,
    color: '#ffffff',
    amplitude: 2
  }, options);

  var group = new THREE.Object3D();

  var plane = this.getPlane();

  var caches = [];
  var idleTweens = [];

  for (var i = 0; i < this.parameters.count; i++) {
    var planeCopy = plane.clone();
    planeCopy.material = planeCopy.material.clone();

    var tween = this.getTween(planeCopy, i);
    var cache = { duration: (10 + i) / 10, z: (this.parameters.count - i) * 5 };

    group.add(planeCopy);
    caches.push(cache);
    idleTweens.push(tween);
  }

  this.el = group;

  this.in = function () {
    for (var i = 0, j = group.children.length; i < j; i++) {
      var el = group.children[i];
      var cache = caches[i];
      TweenLite.to(el.position, cache.duration, { z: 0 });
    }
  };

  this.out = function (way) {
    var factor = way === 'up' ? 1 : -1;

    for (var i = 0, j = group.children.length; i < j; i++) {
      var el = group.children[i];
      var cache = caches[i];
      TweenLite.to(el.position, cache.duration, { z: factor * cache.z });
    }
  };

  this.start = function () {
    for (var i = 0, j = idleTweens.length; i < j; i++) {
      idleTweens[i].resume();
    }
  };

  this.stop = function () {
    for (var i = 0, j = idleTweens.length; i < j; i++) {
      idleTweens[i].pause();
    }
  };
}
  exports.build = function(humanNotation, rotation) {
    rotation = typeof rotation !== 'undefined' ? rotation : "[0,0,0]";

    var rotationArray = JSON.parse(rotation);

    scene = new THREE.Scene();
    figure = new THREE.Object3D();
    figure.useQuaternion = true;
    figure.quaternion = new THREE.Quaternion();
    figure.quaternion.setFromEuler(new THREE.Vector3(rotationArray[0] * Math.PI / 180, rotationArray[1] * Math.PI / 180, rotationArray[2] * Math.PI / 180));
    scene.add(figure);
    prisms = [];
    var computerNotation = parseNotation(humanNotation);

    // after adding a new prism its exit direction
    // is cumulated in this quaternion to be used to
    // orient the next prism
    var Q = new THREE.Quaternion();
    var previous = null;

    for (var i = 0; i < computerNotation.length; i++) {
      var mesh;
      if (i % 2) {
        mesh = THREE.SceneUtils.createMultiMaterialObject(geometryOdd, materialOdd);
      } else {
        if (useFirstColor === true && i === 0) {
          mesh = THREE.SceneUtils.createMultiMaterialObject(geometryEven, materialFirst);
        } else {
          mesh = THREE.SceneUtils.createMultiMaterialObject(geometryEven, materialEven);
        }
      }
      mesh.useQuaternion = true;
      figure.add(mesh);
      prisms.push(mesh);

      mesh.quaternion.copy(Q);
      mesh.updateMatrix();

      Q.multiplyQuaternions(advanceQuaternion(mesh, computerNotation[i]), Q);

      if (previous !== null) {
        connectPrisms(previous, mesh);
      }
      previous = mesh;
    }

    // center each figure around 0,0,0
    var positions = prisms.map(function(prism) {
      return prism.position;
    });
    var center = computeCenter(positions);
    prisms.forEach(function(prism) {
      prism.position.sub(center);
    });

    setupCamera();
  };
Example #10
0
 function magicRedraw(){
   root.remove(curves);
   root.remove(movingGuys);
   curves = new THREE.Object3D();
   movingGuys = new THREE.Object3D();
   drawData(window.params.country, window.params.format, window.params.sitc_id, countryArr, curves, movingGuys);      
   root.add(curves);
   root.add(movingGuys);
 }
Example #11
0
  build () {
    this.traces = this.soup.traces
    if (this.selectedTraces.length > 0) {
      let newTraces = []
      for (let [i, trace] of this.traces.entries()) {
        if (_.includes(this.selectedTraces, i)) {
          newTraces.push(trace)
        }
      }
      this.traces = newTraces
    }

    glgeom.clearObject3D(this.displayObj)
    glgeom.clearObject3D(this.pickingObj)

    let nCopy = 0
    for (let trace of this.traces) {
      nCopy += trace.points.length
    }

    let unitGeom = new glgeom.BlockArrowGeometry()
    let unitBufferGeom = new THREE.BufferGeometry().fromGeometry(unitGeom)

    this.displayGeom = new glgeom.CopyBufferGeometry(unitBufferGeom, nCopy)
    this.pickingGeom = new glgeom.CopyBufferGeometry(unitBufferGeom, nCopy)

    let obj = new THREE.Object3D()

    let iCopy = 0
    for (let trace of this.traces) {
      let n = trace.points.length
      for (let i of _.range(n)) {
        let point = trace.points[i]
        let tangent = trace.tangents[i]
        let normal = trace.binormals[i]
        let target = point.clone().add(tangent)

        obj.matrix.identity()
        obj.position.copy(point)
        obj.up.copy(normal)
        obj.lookAt(target)
        obj.updateMatrix()

        this.displayGeom.applyMatrixToCopy(obj.matrix, iCopy)
        this.pickingGeom.applyMatrixToCopy(obj.matrix, iCopy)
        this.pickingGeom.applyColorToCopy(trace.indexColors[i], iCopy)

        iCopy += 1
      }
    }

    this.recolor()

    this.displayObj.add(new THREE.Mesh(this.displayGeom, this.displayMaterial))
    this.pickingObj.add(new THREE.Mesh(this.pickingGeom, this.pickingMaterial))
  }
Example #12
0
        onRender3D={() => {
            const base = new THREE.Object3D();
            
            const draft = new Draft();
            draft.drawPoints(GenPoints.createFromIcosahedronGeometry({ radius: props.radius - 8, detail: 2 }));
            const mantle = draft.build(Projection.plane(1));

            base.add(mantle);
            base.userData.mantle = mantle;
            return base;
        }}
Example #13
0
/**
 * 3D Flow field
 * Fake flocking
 *
 * @param {Array} [points] MainCurve's points
 * @param {Object} [options]
 * @param {Object} [options.subsNumber=3] SubCurves number
 * @param {Number} [options.subsAmplitude=30] SubCurves amplitude
 * @param {Number} [options.subsPrecision=10] SubCurves precision (=subdivisions)
 * @param {Number} [options.noiseXincrement=0.1] SubCurves x noise
 * @param {Number} [options.moiseYincrement=0.1] SubCurves y noise
 * @param {Number} [options.noiseZincrement=0.1] SubCurves z noise
 * @param {Number} [options.renderResolution=100] SubCurves render precision (=subdivisions)
 * @param {String} [options.mainColor='#ffffff'] MainCurve's color
 * @param {String} [options.subsColor='#4c4c4c'] SubCurves color
 * @requires jQuery, THREE, TweenLite, random, noise, map
 */
function FlowField (points, options) {
  this.parameters = jQuery.extend(FlowField.defaultOptions, options);

  var group = new THREE.Object3D();

  var curves = this.getCurves(points);
  var main = curves.main;
  var subs = curves.subs;
  var lines = this.getLines(main, subs);
  var inTweens = [];

  for (var i = 0, j = lines.length; i < j; i++) {
    group.add(lines[i]);
    inTweens.push(this.getInTween(lines[i]));
  }

  var triangleGeometry = new THREE.TetrahedronGeometry(3);
  var triangleMaterial = new THREE.MeshLambertMaterial({ shading: THREE.FlatShading });
  var triangleMesh = new THREE.Mesh(triangleGeometry, triangleMaterial);

  var follow = this.getFollow(triangleMesh, subs);

  for (var k = 0, l = follow.meshes.length; k < l; k++) {
    group.add(follow.meshes[k]);
  }

  this.el = group;

  this.in = function () {
    for (var i = 0, j = inTweens.length; i < j; i++) {
      inTweens[i].restart();
    }
  };

  this.out = function () {
    for (var i = 0, j = inTweens.length; i < j; i++) {
      inTweens[i].reverse();
    }
  };

  this.start = function () {
    for (var i = 0, j = follow.tweens.length; i < j; i++) {
      follow.tweens[i].resume();
    }
  };

  this.stop = function () {
    for (var i = 0, j = follow.tweens.length; i < j; i++) {
      follow.tweens[i].pause();
    }
  };
}
Example #14
0
/**
 * Cloud of meshes looking at the same coordinates
 *
 * @class LookAtField
 * @constructor
 * @param {Object} [options]
 * @param {Number} [options.count=100] Meshes number
 * @requires jQuery, THREE, TweenLite, random
 */
function LookAtField (options) {
  var parameters = jQuery.extend({
    count: 100
  }, options);

  var center = new THREE.Vector3(0, 50, 0);

  var triangleGeometry = new THREE.TetrahedronGeometry(3);

  var triangleMaterial = new THREE.MeshLambertMaterial({ shading: THREE.FlatShading });
  var triangleMesh = new THREE.Mesh(triangleGeometry, triangleMaterial);

  var group = new THREE.Object3D();

  for (var i = 0; i < parameters.count; i++) {
    var triangleCopy = triangleMesh.clone();
    triangleCopy.position.x = random(-50, 50);
    triangleCopy.position.y = random(-50, 50);
    triangleCopy.position.z = random(-50, 30);

    triangleCopy.rotation.x = random(0, 2 * Math.PI);
    triangleCopy.rotation.y = random(0, 2 * Math.PI);
    triangleCopy.rotation.z = random(0, 2 * Math.PI);

    triangleCopy.scale.x = triangleCopy.scale.y = triangleCopy.scale.z = random(0.6, 1);

    triangleCopy.lookAt(center);

    group.add(triangleCopy);
  }

  group.position.y = -50;

  function update () {
    for (var i = 0; i < parameters.count; i++) {
      group.children[i].lookAt(center);
    }
  }

  this.el = group;

  this.in = function () {
    group.visible = true;
    TweenLite.to(center, 2, { y: 0, onUpdate: update });
    TweenLite.to(group.position, 1, { y: 0 });
  };

  this.out = function () {
    TweenLite.to(center, 1, { y: 50, onUpdate: update, onComplete: function () { group.visible = false; } });
    TweenLite.to(group.position, 1, { y: -50 });
  };
}
Example #15
0
module.exports = function (opts) {
    // Materials
    var wallMat = new THREE.MeshPhongMaterial({map: textures[opts.texture].wall});
    var topMat = new THREE.MeshPhongMaterial({map: textures[opts.texture].top});
    var wallMesh = new THREE.Mesh(mergeGeometry, wallMat);
    var topMesh = new THREE.Mesh(wallPieceTop, topMat);
    var group = new THREE.Object3D();
    group.add(wallMesh);
    group.add(topMesh);
    group.position.set(opts.x, opts.y, opts.z);
    group.rotation.y = opts.rotation;
    return group;
};
Example #16
0
function init() {

    scene = new THREE.Scene();
    //scene.fog = new THREE.Fog(0x93d7e6, 800, 1200);

    camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
    camera.position.z = 1000;

    geometry = new THREE.DodecahedronGeometry(100);
    material = new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe: true, wireframeLinewidth: 1 } );

    group = new THREE.Object3D();

    mesh = new THREE.Mesh( geometry, material );
    group.add( mesh );

    geometryFilled = new THREE.DodecahedronGeometry(80);
    materialFilled = new THREE.MeshLambertMaterial({
        color: 0xf6fcfd,
        emissive: 0xa5c8d0,
        side: THREE.FrontSide,
        shading: THREE.FlatShading
    });

    meshFilled = new THREE.Mesh( geometryFilled, materialFilled );
    group.add( meshFilled );

    geometry.vertices.forEach((v, i) => animateVertice([v, geometryFilled.vertices[i]]));

    var lights = [];
    lights[ 0 ] = new THREE.PointLight( 0xf6fcfd, 0.2, 0 );
    lights[ 1 ] = new THREE.PointLight( 0xf6fcfd, 1, 0 );
    lights[ 2 ] = new THREE.PointLight( 0xf6fcfd, 1, 0 );

    lights[ 0 ].position.set( 800, 0, 800 );
    lights[ 1 ].position.set( 100, 200, 100 );
    lights[ 2 ].position.set( - 100, - 200, - 100 );

    scene.add( lights[ 0 ] );
    /*scene.add( lights[ 1 ] );
    scene.add( lights[ 2 ] );*/
    scene.add(group);

    renderer = new THREE.WebGLRenderer({antialias: true});
    renderer.setSize( window.innerWidth, window.innerHeight );
    renderer.setClearColor( 0x93D7E6, 1);

    document.body.appendChild( renderer.domElement );

}
Example #17
0
Player.create = function (connetor, el) {
  var bodyMaterial = new THREE.MeshPhongMaterial({
    color: '#999999'
  });

  var faceTexture = THREE.ImageUtils.loadTexture(environment.getBaseUrl() + '/images/face.png');
  var headMaterial = new THREE.MeshLambertMaterial({
    color: '#ffffaa',
    map: faceTexture
  });

  var geometry1 = new THREE.CylinderGeometry(0.02, 0.5, 1.3, 10);
  var body = new THREE.Mesh(geometry1, bodyMaterial);
  body.castShadow = true;
  body.recieveShadow = true;

  var geometry2 = new THREE.SphereGeometry(0.3, 10, 10);
  var head = new THREE.Mesh(geometry2, headMaterial);
  head.position.y = 0.6;
  head.rotation.y = Math.PI / 2;
  head.castShadow = true;
  head.recieveShadow = true;

  var obj = new THREE.Object3D();
  obj.add(head);
  obj.add(body);

  if (el.attr('name')) {
    obj.add(Player.createLabel(el));
  }

  // loader = new THREE.OBJLoader(this.manager);
  // loader.load("//" + this.getAssetHost() + "/models/hardhat.obj", (function(self) {
  //   return function(object) {
  //     object.traverse(function(child) {
  //       material = new THREE.MeshPhongMaterial({
  //         color: '#FFCC00'
  //       });
  //       if (child instanceof THREE.Mesh) {
  //         return child.material = material;
  //       }
  //     });
  //     object.scale.set(0.3, 0.3, 0.3);
  //     object.position.y += 0.7;
  //     return obj.add(object);
  //   };
  // })(this));

  return obj;
};
 /**
  * rotates the erich according to axis and angle
  * @param {string} axis - 'x', 'y' or 'z'
  * @param {number} angle - in radians
  */
 rotate(axis, angle) {
     switch (axis) {
         case 'x':
             this.object3D.rotateX(angle);
             break;
         case 'y':
             this.object3D.rotateY(angle);
             break;
         case 'z':
             this.object3D.rotateZ(angle);
             break;
         default:
             throw new Error('angle not possible');
     }
 }
Example #19
0
	startGame() {
		console.log("game starting");

		//this.scene.fog = new THREE.Fog(0, 1, 1000);

		// lights
		this.ambientLight = new THREE.AmbientLight( constants.AMBIENT_COLOR.getHex() );
		this.ambientLight.intensity = .75;
		this.scene.add(this.ambientLight);

		this.dirLight1 = new THREE.DirectionalLight( 0xffffbb, .5 );
		this.dirLight1.position.set( 1, 1, 1 );
		this.scene.add( this.dirLight1 );

		//this.dirLight1 = new THREE.DirectionalLight( constants.DIR1_COLOR.getHex(), 0.9 );
		//this.dirLight1.position.set( 1, 1, 1 );
		//this.scene.add( this.dirLight1 );

		this.dirLight2 = new THREE.DirectionalLight( constants.DIR2_COLOR.getHex(), 0.5 );
		this.dirLight2.position.set(1, -1, .8 );
		this.scene.add( this.dirLight2 );

		this.controller = this.controllerMaker(this);
		this.overmap = new overmap.OverMap(this);
		this.viewer = this.viewMaker(this);

		// camera rotation
		this.camera.rotation.set( 0, 0, 0 );

		this.pitch = new THREE.Object3D();
		this.pitch.rotation.x = Math.PI / 4;
		this.pitch.add(this.camera);

		this.roll = new THREE.Object3D();
		this.roll.add(this.pitch);

		// yaw
		this.yaw = new THREE.Object3D();
		this.yaw.add(this.roll);
		this.yaw.rotation.z = Math.PI;
		this.scene.add(this.yaw);

		this.yaw.position.set(0, 0, this.viewer.getCameraZ());

		this.controller.start();

		console.log("started");
	}
Example #20
0
  update (delta) {
    this.handleInput()
    this.step(delta)

    // Object isn't actually part of a rendered scene, so we need to call this manually
    this.object.updateMatrixWorld(true)
  }
Example #21
0
  function onGlobeMousemove(event) {
    var map, material;

    // Get pointc, convert to latitude/longitude
    var latlng = getEventCenter.call(this, event);

    // Look for country at that latitude/longitude
    var country = geo.search(latlng[0], latlng[1]);

    if (country !== null && country.code !== currentCountry) {

      // Track the current country displayed
      currentCountry = country.code;

      // Update the html
      d3.select("#msg").html(country.code);

       // Overlay the selected country
      map = textureCache(country.code, '#CDC290');
      material = new THREE.MeshPhongMaterial({map: map, transparent: true});
      if (!overlay) {
        overlay = new THREE.Mesh(new THREE.SphereGeometry(201, 40, 40), material);
        overlay.rotation.y = Math.PI;
        root.add(overlay);
      } else {
        overlay.material = material;
      }
    }
  }
Example #22
0
    function move(opts) {
        if (opts.direction == 'back') {
            temp = CONST.room.width * 0.25;
        }
        if (opts.direction == 'forward') {
            temp = -CONST.room.width * 0.25;
        }
        var worldDirection = group.getWorldDirection();
        var value = _.clone(group.position);

        if (worldDirection.x == 1) {
            value.x = value.x + temp;
        } else if (worldDirection.x == -1) {
            value.x = value.x - temp;
        } else if (worldDirection.z == 1) {
            value.z = value.z + temp;
        } else if (worldDirection.z == -1) {
            value.z = value.z - temp;
        }
        var time = Math.round(Math.abs(temp) /CONST.speed/2 * 1000);
        steps.play();
        new TWEEN.Tween(group.position)
            .to({z: value.z, x: value.x}, time)
            .onComplete(function () {
                steps.stop();
                if(opts.callback){
                    opts.callback();
                }
            })
            .start();
    }
Example #23
0
	self.remove = function (view) {
		var index = pieces.indexOf(view);
		if (index > -1) {
			pieces = pieces.splice(index, 1);
		}
		mesh.remove(view.mesh());
	};
Example #24
0
Entity.init = function(mesh, bbox) {
  Object3D.call(this);
  this.mesh = mesh;
  this.bbox = (bbox === undefined)? mesh : bbox;
  this.add(this.mesh);
  this.add(this.bbox);
};
    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 #26
0
export default function(scene) {
  const roomGroup = new THREE.Object3D();

  const wallLeft = new THREE.Mesh(
    new THREE.PlaneGeometry(150, 150),
    new THREE.MeshPhongMaterial({ color: 0xffffff })
  );
  wallLeft.material.side = THREE.DoubleSide;
  wallLeft.rotation.y = Math.PI / 2;
  wallLeft.position.x = -75;
  wallLeft.position.z = 0;
  roomGroup.add(wallLeft);

  const wallRight = wallLeft.clone();
  wallRight.position.x = 75;
  roomGroup.add(wallRight);

  const wallBack = wallLeft.clone();
  wallBack.rotation.y = 0;
  wallBack.position.y = 65;
  wallBack.position.x = 0;
  wallBack.position.z = -75;
  roomGroup.add(wallBack);

  const doorWall = new THREE.Shape();
  doorWall.moveTo(0, 0);
  doorWall.lineTo(65, 0);
  doorWall.lineTo(65, 50);
  doorWall.lineTo(105, 50);
  doorWall.lineTo(105, 0);
  doorWall.lineTo(150, 0);
  doorWall.lineTo(150, 100);
  doorWall.lineTo(0, 100);
  doorWall.lineTo(0, 0);
  const dWall = new THREE.Mesh(
    new THREE.ShapeGeometry(doorWall),
    new THREE.MeshPhongMaterial({ color: 0xffffff })
  );
  dWall.material.side = THREE.DoubleSide;
  dWall.position.set(-75, -10, 75);
  roomGroup.add(dWall);

  const interiorLamp = new THREE.PointLight(0x33ff00, 1, 150);
  interiorLamp.position.set(0, 20, 0);
  roomGroup.add(interiorLamp);

  const exteriorLampLeft = new THREE.PointLight(0x0033ff, 1, 150);
  exteriorLampLeft.position.set(-50, 10, 120);
  roomGroup.add(exteriorLampLeft);

  const exteriorLampRight = exteriorLampLeft.clone();
  exteriorLampRight.position.x = 50;
  roomGroup.add(exteriorLampRight);

  roomGroup.position.set(100, 10, 30);
  scene.add(roomGroup);
}
Example #27
0
  _makeMeshGroup(size, startPosition, unitDirection) {
    const group = new THREE.Object3D();

    let backwards = unitDirection.clone().negate();
    let currentVoxel = Voxel.at(startPosition);

    while (size > 0) {
      this.world.disable(currentVoxel.position, 'snake');
      group.add(this._makeVoxelMesh(currentVoxel.position));
      ([currentVoxel, backwards] = currentVoxel.nextWithDirection(backwards));
      size -= 1;
    }

    this._addEyesTo(group.children[0], unitDirection);

    return group;
  }
Example #28
0
function Planet(name, colour, camera, texture) {
  if (!atmosphereMaterial) {
    atmosphereMaterial = generateAtmosphereMaterial(camera);
  }

  var pivot = new THREE.Object3D(),
      mesh = new THREE.Mesh(geometry, selectMaterial(colour, texture)),
      atmosphereMesh = new THREE.Mesh(atmosphereGeometry, atmosphereMaterial);

  atmosphereMesh.scale.multiplyScalar(1.05);

  pivot.add(mesh);
  pivot.add(atmosphereMesh);

  this.mesh = mesh;
  this.pivot = pivot;
}
Example #29
0
function FeBlockView( feb, options ) {
  THREE.Object3D.call( this );
  options || ( options = {} );

  this.model = feb;
  this.build( options );
  return this;
}
Example #30
0
  constructor(parent, props = {}) {
    super(parent, props);
    console.info("this.props = ", this.props);
    // this.props = props;
    this.grid = [[]];
    this.root = new THREE.Object3D();
    this.root.visible = false;
    this.setTitle(props.title);

    if (this.props.handler) {
      this.keydownHandler = `${this.props.handler}:onkeydown`;
    } else {
      this.keydownHandler = 'onkeydown';
    }

    parent.add(this.root);

    if (this.props.activationKey) {
      events.on('onkeydown', this.downHandler, this);
    }

    events.on(this.keydownHandler, this.downHandler, this);
    // calculate positions
    let {size, position} = Layouts.flex(this.props.window, true);
    position.z = -200;
    //console.info('setting window to: ', position);
    this.window = {
      size: size,
      position: position
    };
    //console.info("sz: ", size, "pos: ", position);
    let menuPlane = new Plane2D({color: [0.5, 0.8, 1], size: size, position: position});
    this.cursor = new Plane2D({
      color: [0.8, 0.98, 1],
      size: {w: 120, h: 120},
      position: {x: this.window.position.x+10, y: this.window.position.y-10, z: -100},
      gridPosition: [0, 0]
    });

    if (props.controls) {
      this.addGroupToGrid(props.controls);
    }

    this.root.add(menuPlane.mesh);
    this.root.add(this.cursor.mesh);
  }