Simple ThreeJS experiment
This is a simple use of ThreeJS : A basic rotating sphere
by Eve Weinberg
HTML
<script src="https://raw.githubusercontent.com/evejweinberg/webvr-boilerplate/master/LoadJSON/asset_src/model.json"></script>
<script src="http://itp.evejweinberg.com/OBJLoader.js"></script>
<div id="myPlanet"></div>
CSS
body {
background : #000;
padding : 50px;
margin : 0;
}
#myPlanet {
width : 400px;
height: 400px;
margin : auto;
}
JavaScript
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE.OBJLoader = function ( manager ) {
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
this.materials = null;
};
THREE.OBJLoader.prototype = {
constructor: THREE.OBJLoader,
load: function ( url, onLoad, onProgress, onError ) {
var scope = this;
var loader = new THREE.XHRLoader( scope.manager );
loader.setPath( this.path );
loader.load( url, function ( text ) {
onLoad( scope.parse( text ) );
}, onProgress, onError );
},
setPath: function ( value ) {
this.path = value;
},
setMaterials: function ( materials ) {
this.materials = materials;
},
parse: function ( text ) {
console.time( 'OBJLoader' );
var objects = [];
var object;
var foundObjects = false;
var vertices = [];
var normals = [];
var uvs = [];
function addObject( name ) {
var geometry = {
vertices: [],
normals: [],
uvs: []
};
var material = {
name: '',
smooth: true
};
object = {
name: name,
geometry: geometry,
material: material
};
objects.push( object );
}
function parseVertexIndex( value ) {
var index = parseInt( value );
return ( index >= 0 ? index - 1 : index + vertices.length / 3 ) * 3;
}
function parseNormalIndex( value ) {
var index = parseInt( value );
return ( index >= 0 ? index - 1 : index + normals.length / 3 ) * 3;
}
function parseUVIndex( value ) {
var index = parseInt( value );
return ( index >= 0 ? index - 1 : index + uvs.length / 2 ) * 2;
}
function addVertex( a, b, c ) {
object.geometry.vertices.push(
vertices[ a ], vertices[ a + 1 ], vertices[ a + 2 ],
vertices[ b ], vertices[ b + 1 ], vertices[ b + 2 ],
vertices[ c ], vertices[ c + 1 ], vertices[ c + 2 ]
);
}
function addNormal( a, b, c ) {
object.geometry.normals.push(
normals[ a ], normals[ a + 1 ], normals[ a + 2 ],
normals[ b ], normals[ b + 1 ],...