SELF DIRECTED RESEARCH2

From XPUB & Lens-Based wiki
Revision as of 20:06, 13 January 2014 by Δεριζαματζορπρομπλεμιναυστραλια (talk | contribs) (Created page with "⌨ 3D BROWSER✌ Threejs Webgl experiments 2 http://dgagegaegaegaeeagg.tumblr.com/ <br> File:Χωρ2ίς τίτλο.png <br> Code example <br> <source lang="javascr...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

⌨ 3D BROWSER✌ Threejs Webgl experiments 2


http://dgagegaegaegaeeagg.tumblr.com/
Χωρ2ίς τίτλο.png

Code example

 
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <style>
            body { 
                background-color: #ffffff;
                margin: 0;
                overflow: hidden;
            }
        </style>
    </head>
    <body>
        
        <script src="http://brangerbriz.net/labs/threejs_playGnd/js/three.min.js"></script>
        <script src="http://brangerbriz.net/labs/threejs_playGnd/js/Detector.js"></script>
        <script>

            if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
            
            var camera, scene1, scene2, scene3, scene4, renderer;
            var geometry, material, cube, cylinder, icosahedron;

            function setup() {

                var W = window.innerWidth/2, H = window.innerHeight;
                renderer1 = new THREE.WebGLRenderer( { preserveDrawingBuffer: true } );
				renderer1.autoClearColor = false;
                renderer1.setSize( W, H );
                document.body.appendChild( renderer1.domElement );

                renderer2 = new THREE.WebGLRenderer( { preserveDrawingBuffer: true } );
				renderer2.autoClearColor = false;
                renderer2.setSize( W, H );
                document.body.appendChild( renderer2.domElement );

                
                renderer3= new THREE.WebGLRenderer( { preserveDrawingBuffer: true } );
				renderer3.autoClearColor = false;
                renderer3.setSize( W, H );
                document.body.appendChild( renderer3.domElement );
                
                renderer4= new THREE.WebGLRenderer( { preserveDrawingBuffer: true } );
				renderer4.autoClearColor = false;
                renderer4.setSize( W, H );
                document.body.appendChild( renderer4.domElement );
                
                camera = new THREE.PerspectiveCamera( 510, W/H, 1, 10000 );
                camera.position.z = 300;

                scene1 = new THREE.Scene();
                scene2 = new THREE.Scene();
                scene3 = new THREE.Scene();
                scene4 = new THREE.Scene();

                                 bg = document.body.style;
bg.background = '#000000';

               geometry = new THREE.CubeGeometry( 95, 95, 55 );
for ( var i = 0; i < 100; i ++ ) {
    material = new THREE.MeshNormalMaterial( { color: Math.random()*0xffffff } );
    cube = new THREE.Mesh( geometry, material);
    cube.position.x = Math.random() * 1000 - 500;
    cube.position.y = Math.random() * 1000 - 500;
    cube.position.z = Math.random() * 1000 - 500;
    cube.rotation.x = Math.random() * 2 * Math.PI;
    cube.rotation.y = Math.random() * 2 * Math.PI;
    cube.rotation.z = Math.random() * 2 * Math.PI;
    scene1.add(cube);
    }

                           geometry = new THREE.CubeGeometry(100, 100, 200);
for ( var i = 5; i < 200; i ++ ) {
    material = new THREE.MeshNormalMaterial( { color: Math.random()*0xffffff } );
    cube = new THREE.Mesh( geometry, material);
    cube.position.x = Math.random() * 1000 - 1500;
    cube.position.y = Math.random() * 1000 - 1500;
    cube.position.z = Math.random() * 1000 - 1500;
    cube.rotation.x = Math.random() * 2 * Math.PI;
    cube.rotation.y = Math.random() * 2 * Math.PI;
    cube.rotation.z = Math.random() * 2 * Math.PI;
    scene2.add(cube);
    }
                
            geometry = new THREE.CylinderGeometry(100, 100, 200, 50, 50, false );
for ( var i = 0; i < 300; i ++ ) {
    material = new THREE.MeshNormalMaterial( { color: Math.random()*0xffffff } );
    cylinder = new THREE.Mesh( geometry, material);
    cylinder.position.x = Math.random() * 1000 - 500;
    cylinder.position.y = Math.random() * 1000 - 500;
    cylinder.position.z = Math.random() * 1000 - 500;
    cylinder.rotation.x = Math.random() * 2 * Math.PI;
    cylinder.rotation.y = Math.random() * 2 * Math.PI;
    cylinder.rotation.z = Math.random() * 2 * Math.PI;
    scene3.add(cylinder);
    }
                
                                          geometry = new THREE.IcosahedronGeometry( 110, 0 );
for ( var i = 0; i < 1300; i ++ ) {
    material = new THREE.MeshNormalMaterial( { color: Math.random()*0xffffff } );
    icosahedron = new THREE.Mesh( geometry, material);
    icosahedron .position.x = Math.random() * 1000 - 500;
    icosahedron .position.y = Math.random() * 1000 - 500;
    icosahedron .position.z = Math.random() * 1000 - 500;
    icosahedron .rotation.x = Math.random() * 2 * Math.PI;
    icosahedron .rotation.y = Math.random() * 2 * Math.PI;
    icosahedron .rotation.z = Math.random() * 2 * Math.PI;
    scene4.add(icosahedron );
    }

     }
           

            function draw() {

                requestAnimationFrame( draw );
                
                cube.rotation.x = Date.now() * 0.0005;    
                cube.rotation.y = Date.now() * 0.0002;    
                cube.rotation.z = Date.now() * 0.001;
                cube.position.y = Math.sin( Date.now() * 0.002 ) * 3300;

               
                
                camera.position.z = Math.sin( Date.now() * 0.00112 ) * 5600;
				camera.position.y = Math.sin( Date.now() * 0.00012 ) * 5600;
				camera.lookAt(cube.position);
 
                cylinder.rotation.x = Date.now() * 0.0005;  
                cylinder.rotation.y = Date.now() * 0.0002;  
                cylinder.rotation.z = Date.now() * 0.001;
                
                
                icosahedron.rotation.x = Date.now() * 0.00205;  
                icosahedron.rotation.y = Date.now() * 0.01002;  
                icosahedron.rotation.z = Date.now() * 0.001;

                renderer1.render( scene1, camera );
                renderer2.render( scene2, camera );
                renderer3.render( scene3, camera );
                renderer4.render( scene4, camera );
            }

            setup();
            draw();

        </script>
        
    </body>
</html>