Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let’s create things in three.js (r63)

yomotsu
December 09, 2013

Let’s create things in three.js (r63)

yomotsu

December 09, 2013
Tweet

More Decks by yomotsu

Other Decks in Programming

Transcript

  1. Hello! I’m Yomotsu just a frontend-engineer at PixelGrid A BIG

    FUN OF Mr.doob and three.js! twitter@yomotsu Tuesday, December 10, 13
  2. var urls = [ 'right.jpg', 'left.jpg', 'top.jpg', 'bottom.jpg', 'front.jpg', 'back.jpg'

    ]; var materials = []; for ( var i = 0; i < 6; i ++ ) { materials.push( new THREE.MeshBasicMaterial({ map: THREE.ImageUtils.loadTexture( urls[ i ] ), side: THREE.BackSide })); } var skyBox = new THREE.Mesh( new THREE.CubeGeometry( 500, 500, 500 ), new THREE.MeshFaceMaterial( materials ) ); scene.add( skyBox ); don’t forget it to show backside! Tuesday, December 10, 13
  3. There are 2 ways to make snowing •as sprites •as

    a particle Tuesday, December 10, 13
  4. Blender allows to export 3D models in JSON for three.js

    ( FYI: it’s needed a plugin ) Tuesday, December 10, 13
  5. var box; var loader = new THREE.JSONLoader(); loader.load( './box.js', function(

    geo, mat ) { box = new THREE.Mesh( geo, new THREE.MeshFaceMaterial( mat ) ); scene.add( box ); } ); Tuesday, December 10, 13
  6. var box, box1, box2; var loader = new THREE.JSONLoader(); loader.load(

    './box.js', function( geo, mat ) { box = new THREE.Mesh( geo, new THREE.MeshFaceMaterial( mat ) ); box1 = box.clone(); box2 = box.clone(); box1.position.set( -3, 0, 0 ); box2.position.set( 3, 0, 0 ); scene.add( box1 ); scene.add( box2 ); } ); Meshes accept `mesh.clone()` to duplicate Tuesday, December 10, 13
  7. var tmpGeometry = new THREE.Geometry(); for ( var i =

    0; i < 5; i ++ ) { ( function () { var treeMeshClone = treeMesh.clone(); treeMeshClone.position.set( i * 10, 0, 0 ); THREE.GeometryUtils.merge( tmpGeometry, treeMeshClone ); } )(); } var forrest = new THREE.Mesh( tmpGeometry, new THREE.MeshFaceMaterial( materials ) ); scene.add( forrest ); Tuesday, December 10, 13
  8. To do so... 1. Clear all transform to be rest

    pose 2. Switch to Object Mode 3. Select the mesh and press CTRL+A and select location. Repeat for rotation and scale 4. Select the armature and do the same Tuesday, December 10, 13
  9. var  santa,  idle; var  clock  =  new  THREE.Clock(); var  loader

     =  new  THREE.JSONLoader(); loader.load(  './santa.js',  function(  geo,  mats  )  {    mats.forEach(  function  (  mat  )  {        mat.skinning  =  true;    }  );    santa  =  new  THREE.SkinnedMesh(        geo,        new  THREE.MeshFaceMaterial(  mats  )    );    THREE.AnimationHandler.add(  santa.geometry.animations[  0  ]  );    idle  =  new  THREE.Animation(        santa,        santa.geometry.animations[  0  ].name,        THREE.AnimationHandler.CATMULLROM    );    scene.add(  santa  );    idle.play(); }  ); Tuesday, December 10, 13
  10.        santa.geometry.animations[  0  ].name,        THREE.AnimationHandler.CATMULLROM

       );    scene.add(  santa  );    idle.play(); }  ); (  function  renderLoop  (){    requestAnimationFrame(  renderLoop  );    var  delta  =  clock.getDelta();    THREE.AnimationHandler.update(  delta  );    renderer.render(  scene,  camera  ); }  )(); Tuesday, December 10, 13
  11. three.js doesn’t have Collision Detections, except Ray. Several physics libs

    are available instead. Physijs, ammo.js, JigLibJS, Cannon.js, Metrix.js and others. Tuesday, December 10, 13