webvr js meetup initial commit

This commit is contained in:
Senad Uka
2017-03-11 15:22:17 +01:00
commit 3f640b55db
761 changed files with 264174 additions and 0 deletions

211
node_modules/three/examples/js/exporters/MMDExporter.js generated vendored Normal file
View File

@@ -0,0 +1,211 @@
/**
* @author takahiro / http://github.com/takahirox
*
* Dependencies
* - mmd-parser https://github.com/takahirox/mmd-parser
*/
THREE.MMDExporter = function () {
// Unicode to Shift_JIS table
var u2sTable;
function unicodeToShiftjis( str ) {
if ( u2sTable === undefined ) {
var encoder = new MMDParser.CharsetEncoder();
var table = encoder.s2uTable;
u2sTable = {};
var keys = Object.keys( table );
for ( var i = 0, il = keys.length; i < il; i ++ ) {
var key = keys[ i ];
var value = table[ key ];
key = parseInt( key );
u2sTable[ value ] = key;
}
}
var array = [];
for ( var i = 0, il = str.length; i < il; i ++ ) {
var code = str.charCodeAt( i )
var value = u2sTable[ code ];
if ( value === undefined ) {
throw 'cannot convert charcode 0x' + code.toString( 16 );
} else if ( value > 0xff ) {
array.push( ( value >> 8 ) & 0xff );
array.push( value & 0xff );
} else {
array.push( value & 0xff );
}
}
return new Uint8Array( array );
}
function getBindBones( skin ) {
// any more efficient ways?
var poseSkin = skin.clone();
poseSkin.pose();
return poseSkin.skeleton.bones;
}
/* TODO: implement
// mesh -> pmd
this.parsePmd = function ( object ) {
};
*/
/* TODO: implement
// mesh -> pmx
this.parsePmx = function ( object ) {
};
*/
/*
* skeleton -> vpd
* Returns Shift_JIS encoded Uint8Array. Otherwise return strings.
*/
this.parseVpd = function ( skin, outputShiftJis, useOriginalBones ) {
if ( skin.isSkinnedMesh !== true ) {
console.warn( 'THREE.MMDExporter: parseVpd() requires SkinnedMesh instance.' );
return null;
}
function toStringsFromNumber( num ) {
if ( Math.abs( num ) < 1e-6 ) num = 0;
var a = num.toString();
if ( a.indexOf( '.' ) === -1 ) {
a += '.';
}
a += '000000';
var index = a.indexOf( '.' );
var d = a.slice( 0, index );
var p = a.slice( index + 1, index + 7 );
return d + '.' + p;
}
function toStringsFromArray( array ) {
var a = [];
for ( var i = 0, il = array.length; i < il; i ++ ) {
a.push( toStringsFromNumber( array[ i ] ) );
}
return a.join( ',' );
}
skin.updateMatrixWorld( true );
var bones = skin.skeleton.bones;
var bones2 = getBindBones( skin );
var position = new THREE.Vector3();
var quaternion = new THREE.Quaternion();
var quaternion2 = new THREE.Quaternion();
var matrix = new THREE.Matrix4();
var array = [];
array.push( 'Vocaloid Pose Data file' );
array.push( '' );
array.push( ( skin.name !== '' ? skin.name.replace( /\s/g, '_' ) : 'skin' ) + '.osm;' );
array.push( bones.length + ';' );
array.push( '' );
for ( var i = 0, il = bones.length; i < il; i ++ ) {
var bone = bones[ i ];
var bone2 = bones2[ i ];
/*
* use the bone matrix saved before solving IK.
* see CCDIKSolver for the detail.
*/
if ( useOriginalBones === true &&
bone.userData.ik !== undefined &&
bone.userData.ik.originalMatrix !== undefined ) {
matrix.fromArray( bone.userData.ik.originalMatrix );
} else {
matrix.copy( bone.matrix );
}
position.setFromMatrixPosition( matrix );
quaternion.setFromRotationMatrix( matrix );
var pArray = position.sub( bone2.position ).toArray();
var qArray = quaternion2.copy( bone2.quaternion ).conjugate().multiply( quaternion ).toArray();
// right to left
pArray[ 2 ] = -pArray[ 2 ];
qArray[ 0 ] = -qArray[ 0 ];
qArray[ 1 ] = -qArray[ 1 ];
array.push( 'Bone' + i + '{' + bone.name );
array.push( ' ' + toStringsFromArray( pArray ) + ';' );
array.push( ' ' + toStringsFromArray( qArray ) + ';' );
array.push( '}' );
array.push( '' );
}
array.push( '' );
var lines = array.join( '\n' );
return ( outputShiftJis === true ) ? unicodeToShiftjis( lines ) : lines;
};
/* TODO: implement
// animation + skeleton -> vmd
this.parseVmd = function ( object ) {
};
*/
};

256
node_modules/three/examples/js/exporters/OBJExporter.js generated vendored Normal file
View File

@@ -0,0 +1,256 @@
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE.OBJExporter = function () {};
THREE.OBJExporter.prototype = {
constructor: THREE.OBJExporter,
parse: function ( object ) {
var output = '';
var indexVertex = 0;
var indexVertexUvs = 0;
var indexNormals = 0;
var vertex = new THREE.Vector3();
var normal = new THREE.Vector3();
var uv = new THREE.Vector2();
var i, j, l, m, face = [];
var parseMesh = function ( mesh ) {
var nbVertex = 0;
var nbNormals = 0;
var nbVertexUvs = 0;
var geometry = mesh.geometry;
var normalMatrixWorld = new THREE.Matrix3();
if ( geometry instanceof THREE.Geometry ) {
geometry = new THREE.BufferGeometry().setFromObject( mesh );
}
if ( geometry instanceof THREE.BufferGeometry ) {
// shortcuts
var vertices = geometry.getAttribute( 'position' );
var normals = geometry.getAttribute( 'normal' );
var uvs = geometry.getAttribute( 'uv' );
var indices = geometry.getIndex();
// name of the mesh object
output += 'o ' + mesh.name + '\n';
// vertices
if( vertices !== undefined ) {
for ( i = 0, l = vertices.count; i < l; i ++, nbVertex++ ) {
vertex.x = vertices.getX( i );
vertex.y = vertices.getY( i );
vertex.z = vertices.getZ( i );
// transfrom the vertex to world space
vertex.applyMatrix4( mesh.matrixWorld );
// transform the vertex to export format
output += 'v ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\n';
}
}
// uvs
if( uvs !== undefined ) {
for ( i = 0, l = uvs.count; i < l; i ++, nbVertexUvs++ ) {
uv.x = uvs.getX( i );
uv.y = uvs.getY( i );
// transform the uv to export format
output += 'vt ' + uv.x + ' ' + uv.y + '\n';
}
}
// normals
if( normals !== undefined ) {
normalMatrixWorld.getNormalMatrix( mesh.matrixWorld );
for ( i = 0, l = normals.count; i < l; i ++, nbNormals++ ) {
normal.x = normals.getX( i );
normal.y = normals.getY( i );
normal.z = normals.getZ( i );
// transfrom the normal to world space
normal.applyMatrix3( normalMatrixWorld );
// transform the normal to export format
output += 'vn ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\n';
}
}
// faces
if( indices !== null ) {
for ( i = 0, l = indices.count; i < l; i += 3 ) {
for( m = 0; m < 3; m ++ ){
j = indices.getX( i + m ) + 1;
face[ m ] = ( indexVertex + j ) + '/' + ( uvs ? ( indexVertexUvs + j ) : '' ) + '/' + ( indexNormals + j );
}
// transform the face to export format
output += 'f ' + face.join( ' ' ) + "\n";
}
} else {
for ( i = 0, l = vertices.count; i < l; i += 3 ) {
for( m = 0; m < 3; m ++ ){
j = i + m + 1;
face[ m ] = ( indexVertex + j ) + '/' + ( uvs ? ( indexVertexUvs + j ) : '' ) + '/' + ( indexNormals + j );
}
// transform the face to export format
output += 'f ' + face.join( ' ' ) + "\n";
}
}
} else {
console.warn( 'THREE.OBJExporter.parseMesh(): geometry type unsupported', geometry );
}
// update index
indexVertex += nbVertex;
indexVertexUvs += nbVertexUvs;
indexNormals += nbNormals;
};
var parseLine = function( line ) {
var nbVertex = 0;
var geometry = line.geometry;
var type = line.type;
if ( geometry instanceof THREE.Geometry ) {
geometry = new THREE.BufferGeometry().setFromObject( line );
}
if ( geometry instanceof THREE.BufferGeometry ) {
// shortcuts
var vertices = geometry.getAttribute( 'position' );
var indices = geometry.getIndex();
// name of the line object
output += 'o ' + line.name + '\n';
if( vertices !== undefined ) {
for ( i = 0, l = vertices.count; i < l; i ++, nbVertex++ ) {
vertex.x = vertices.getX( i );
vertex.y = vertices.getY( i );
vertex.z = vertices.getZ( i );
// transfrom the vertex to world space
vertex.applyMatrix4( line.matrixWorld );
// transform the vertex to export format
output += 'v ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\n';
}
}
if ( type === 'Line' ) {
output += 'l ';
for ( j = 1, l = vertices.count; j <= l; j++ ) {
output += ( indexVertex + j ) + ' ';
}
output += '\n';
}
if ( type === 'LineSegments' ) {
for ( j = 1, k = j + 1, l = vertices.count; j < l; j += 2, k = j + 1 ) {
output += 'l ' + ( indexVertex + j ) + ' ' + ( indexVertex + k ) + '\n';
}
}
} else {
console.warn('THREE.OBJExporter.parseLine(): geometry type unsupported', geometry );
}
// update index
indexVertex += nbVertex;
};
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
parseMesh( child );
}
if ( child instanceof THREE.Line ) {
parseLine( child );
}
} );
return output;
}
};

View File

@@ -0,0 +1,94 @@
/**
* @author kovacsv / http://kovacsv.hu/
* @author mrdoob / http://mrdoob.com/
* @author mudcube / http://mudcu.be/
*/
THREE.STLBinaryExporter = function () {};
THREE.STLBinaryExporter.prototype = {
constructor: THREE.STLBinaryExporter,
parse: ( function () {
var vector = new THREE.Vector3();
var normalMatrixWorld = new THREE.Matrix3();
return function parse( scene ) {
// We collect objects first, as we may need to convert from BufferGeometry to Geometry
var objects = [];
var triangles = 0;
scene.traverse( function ( object ) {
if ( ! ( object instanceof THREE.Mesh ) ) return;
var geometry = object.geometry;
if ( geometry instanceof THREE.BufferGeometry ) {
geometry = new THREE.Geometry().fromBufferGeometry( geometry );
}
if ( ! ( geometry instanceof THREE.Geometry ) ) return;
triangles += geometry.faces.length;
objects.push( {
geometry: geometry,
matrix: object.matrixWorld
} );
} );
var offset = 80; // skip header
var bufferLength = triangles * 2 + triangles * 3 * 4 * 4 + 80 + 4;
var arrayBuffer = new ArrayBuffer( bufferLength );
var output = new DataView( arrayBuffer );
output.setUint32( offset, triangles, true ); offset += 4;
// Traversing our collected objects
objects.forEach( function ( object ) {
var vertices = object.geometry.vertices;
var faces = object.geometry.faces;
normalMatrixWorld.getNormalMatrix( object.matrix );
for ( var i = 0, l = faces.length; i < l; i ++ ) {
var face = faces[ i ];
vector.copy( face.normal ).applyMatrix3( normalMatrixWorld ).normalize();
output.setFloat32( offset, vector.x, true ); offset += 4; // normal
output.setFloat32( offset, vector.y, true ); offset += 4;
output.setFloat32( offset, vector.z, true ); offset += 4;
var indices = [ face.a, face.b, face.c ];
for ( var j = 0; j < 3; j ++ ) {
vector.copy( vertices[ indices[ j ] ] ).applyMatrix4( object.matrix );
output.setFloat32( offset, vector.x, true ); offset += 4; // vertices
output.setFloat32( offset, vector.y, true ); offset += 4;
output.setFloat32( offset, vector.z, true ); offset += 4;
}
output.setUint16( offset, 0, true ); offset += 2; // attribute byte count
}
} );
return output;
};
}() )
};

View File

@@ -0,0 +1,75 @@
/**
* @author kovacsv / http://kovacsv.hu/
* @author mrdoob / http://mrdoob.com/
*/
THREE.STLExporter = function () {};
THREE.STLExporter.prototype = {
constructor: THREE.STLExporter,
parse: ( function () {
var vector = new THREE.Vector3();
var normalMatrixWorld = new THREE.Matrix3();
return function parse( scene ) {
var output = '';
output += 'solid exported\n';
scene.traverse( function ( object ) {
if ( object instanceof THREE.Mesh ) {
var geometry = object.geometry;
var matrixWorld = object.matrixWorld;
if ( geometry instanceof THREE.Geometry ) {
var vertices = geometry.vertices;
var faces = geometry.faces;
normalMatrixWorld.getNormalMatrix( matrixWorld );
for ( var i = 0, l = faces.length; i < l; i ++ ) {
var face = faces[ i ];
vector.copy( face.normal ).applyMatrix3( normalMatrixWorld ).normalize();
output += '\tfacet normal ' + vector.x + ' ' + vector.y + ' ' + vector.z + '\n';
output += '\t\touter loop\n';
var indices = [ face.a, face.b, face.c ];
for ( var j = 0; j < 3; j ++ ) {
vector.copy( vertices[ indices[ j ] ] ).applyMatrix4( matrixWorld );
output += '\t\t\tvertex ' + vector.x + ' ' + vector.y + ' ' + vector.z + '\n';
}
output += '\t\tendloop\n';
output += '\tendfacet\n';
}
}
}
} );
output += 'endsolid exported\n';
return output;
};
}() )
};

View File

@@ -0,0 +1,55 @@
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE.TypedGeometryExporter = function () {};
THREE.TypedGeometryExporter.prototype = {
constructor: THREE.TypedGeometryExporter,
parse: function ( geometry ) {
var output = {
metadata: {
version: 4.0,
type: 'TypedGeometry',
generator: 'TypedGeometryExporter'
}
};
var attributes = [ 'vertices', 'normals', 'uvs' ];
for ( var key in attributes ) {
var attribute = attributes[ key ];
var typedArray = geometry[ attribute ];
var array = [];
for ( var i = 0, l = typedArray.length; i < l; i ++ ) {
array[ i ] = typedArray[ i ];
}
output[ attribute ] = array;
}
var boundingSphere = geometry.boundingSphere;
if ( boundingSphere !== null ) {
output.boundingSphere = {
center: boundingSphere.center.toArray(),
radius: boundingSphere.radius
}
}
return output;
}
};