Lab 5

Today, we are going to look into rendering libraries such as Velocity.js, pixi.js, and three.js

    Velocity.js

    pixi.js

    three.js

Also, clone this repo: git@github.com:shovon/iat381-lab5.git

Velocity.js

Useful for smoothly animating DOM elements

        $('element').velocity({translateX: 100}, 300, function () {
          // Maybe do some more animation here.
        })
      

pixi.js

A helper library for drawing 2D content on a WebGL context (with an HTML5 canvas fallback, just in case)

        var renderer = new PIXI.WebGLRenderer(800, 600);

        document.body.appendChild(renderer.view);

        var stage = new PIXI.Stage();

        var someTexture = PIXI.Texture.fromImage('image.png');
        var sprite = new PIXI.Sprite(someTexture);

        stage.addChild(sprite);

        requestAnimationFrame(function animate() {
          renderer.render(stage);
          requestAnimationFrame(animate);
        });
      

three.js

A helper library to draw 3D content on a variety of rendering platform on the web (including--or rather especially--WebGL)

        // Will hold our list of abstract 3D objects.
        var scene = new THREE.Scene();

        // An absract helper object to generate the matrix to help position
        // vertices in such a way that we get the illusion of a 3D object given
        // some perspective.
        var camera = new THREE.PerspectiveCamera(
          75, window.innerWidth / window.innerHeight, 0.1, 1000
        );

        // This is where the David Blaine will happen.
        var renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);

        // Represents the vertices that will comprise a cube.
        var geometry = new THREE.BoxGeometry(1, 1, 1);

        // Tells WebGL on how we are going to draw the "fragments" of our cube.
        var material = new THREE.MeshBasicMaterial({color: 0xFFFFFF, wireframe: true});

        // Just an abstract 3D object.
        var cube = new THREE.Mesh(geometry, material);
        scene.add(cube);

        camera.position.z = 5;

        requestAnimationFrame(function animate() {
          cube.rotation.x = Date.now()*0.001;
          cube.rotation.y = Date.now()*0.001;

          renderer.render(scene, camera);
          requestAnimationFrame(animate);
        });
      

Optionally, you may also add this code if you want your canvas to auto-resize: https://gist.github.com/shovon/e1bd889e0c49b916e5ef