Skip to content

Commit

Permalink
add device orientation template three.js
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-armour committed Sep 24, 2015
1 parent 8a8a3ec commit 6042dc3
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cookbook-threejs/templates/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

[Jaanga]( http://jaanga.github.io// ) » [Cookbook]( http://jaanga.github.io/cookbook-threejs/ ) »
Templates
Three.js Templates Read Me
===
<span style=display:none; >[View as web page]( http://jaanga.github.io/libs "View file as a web page." ) </span>
<input type=button value='View file as source code on GitHub' onclick=window.location.href='https://github.com/jaanga/libs/tree/gh-pages'; />


[template-threejs-device-orientation-r1.html]( template-threejs-device-orientation-r1.html )

119 changes: 119 additions & 0 deletions cookbook-threejs/templates/template-threejs-device-orientation-r1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<!doctype html>
<html lang=en >
<head>
<title>template-threejs-device-orientation-r1</title>
<meta charset=utf-8 />
<meta name=viewport content='width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0' />
</head>
<body>
<script src=http://mrdoob.github.io/three.js/build/three.min.js ></script>
<script src=http://mrdoob.github.io/three.js/examples/js/controls/OrbitControls.js ></script>
<script src=http://mrdoob.github.io/three.js/examples/js/libs/stats.min.js ></script>
<script>


var css, menu, stats, renderer, scene, camera, controls;
var geometry, material, mesh;

init();
animate();

function init() {

css = document.head.appendChild( document.createElement( 'style' ) );
css.innerHTML ='body { font: 600 12pt monospace; margin: 0; overflow: hidden; }' +
'#i {text-decoration: none; }' +
'';

menu = document.body.appendChild( document.createElement( 'div' ) );
menu.style.cssText = 'margin: 0 20px; position: absolute; ';
menu.innerHTML = '<h2 style=margin:0; ><a href="" >' + document.title + '</a> ' +
'<a id=i href=http://jaanga.github.io/ >&#x24D8;</a></h2>' +
'<div id=info ></div>' +
'';

stats = new Stats();
stats.domElement.style.cssText = 'position: absolute; right: 0; top: 0; z-index: 100; ';
document.body.appendChild( stats.domElement );

renderer = new THREE.WebGLRenderer( { alpha: 1, antialias: true, clearColor: 0xffffff } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 100, 100, 100 );

controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.maxDistance = 800;

scene = new THREE.Scene();

window.addEventListener( 'resize', onWindowResize, false );

// assets

var geometry = new THREE.SphereGeometry( 150, 16, 16);
var material = new THREE.MeshBasicMaterial({ map: THREE.ImageUtils.loadTexture( '../../textures/skydome.jpg' ) });
var skysphere = new THREE.Mesh( geometry, material );
skysphere.scale.x = -1;
scene.add( skysphere );

geometry = new THREE.BoxGeometry( 100, 2, 100 );
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh( geometry, material );
mesh.position.set( 0, -10, 0 );
scene.add( mesh );

mesh = new THREE.GridHelper( 50, 10 );
mesh.position.set( 0, -9, 0 );
scene.add( mesh );

var axisHelper = new THREE.AxisHelper( 50 );
scene.add( axisHelper );


addBoxesNoLights();

}

function addBoxesNoLights() {

geometry = new THREE.BoxGeometry( 10, 10, 10 );
material = new THREE.MeshNormalMaterial( { opacity: 0.7, side: THREE.DoubleSide, transparent: true });
for (var i = 0; i < 50; i++) {

mesh = new THREE.Mesh( geometry, material );
mesh.position.set( 100 * Math.random() - 50, 100 * Math.random(), 100 * Math.random() - 50 );
mesh.rotation.set( 6.3 * Math.random(), 1.57 * Math.random(), 3.14 * Math.random() );

scene.add( mesh );

helper = new THREE.EdgesHelper( mesh );
helper.material.color.setRGB( 1, 0, 0 );
scene.add( helper );

}

}

function onWindowResize() {

camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();

renderer.setSize( window.innerWidth, window.innerHeight );

}

function animate() {

requestAnimationFrame( animate );
controls.update();
stats.update();
renderer.render( scene, camera );

}

</script>
</body>
</html>
Binary file added textures/skydome.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6042dc3

Please sign in to comment.