发布于 2017-01-01 09:54:08 | 254 次阅读 | 评论: 0 | 来源: 网友投递
			Three.js JS3D 引擎库
three.js是JavaScript编写的WebGL第 三方库。提供了非常多的3D显示功能。Three.js 是一款运行在浏览器中的 3D 引擎,你可以用它创建各种三维场景,包括了摄影机、光影、材质等各种对象。		
 
THREE.Object3D = function () { 
THREE.Object3DLibrary.push( this ); 
this.id = THREE.Object3DIdCount ++; 
this.name = ''; 
this.properties = {}; 
this.parent = undefined; 
this.children = []; 
this.up = new THREE.Vector3( 0, 1, 0 ); 
this.position = new THREE.Vector3(); 
this.rotation = new THREE.Vector3(); 
this.eulerOrder = THREE.Object3D.defaultEulerOrder; 
this.scale = new THREE.Vector3( 1, 1, 1 ); 
this.renderDepth = null; 
this.rotationAutoUpdate = true; 
this.matrix = new THREE.Matrix4(); 
this.matrixWorld = new THREE.Matrix4(); 
this.matrixRotationWorld = new THREE.Matrix4(); 
this.matrixAutoUpdate = true; 
this.matrixWorldNeedsUpdate = true; 
this.quaternion = new THREE.Quaternion(); 
this.useQuaternion = false; 
this.boundRadius = 0.0; 
this.boundRadiusScale = 1.0; 
this.visible = true; 
this.castShadow = false; 
this.receiveShadow = false; 
this.frustumCulled = true; 
this._vector = new THREE.Vector3(); 
}; 
 
applyMatrix: function ( matrix ) { 
this.matrix.multiply( matrix, this.matrix ); 
this.scale.getScaleFromMatrix( this.matrix ); 
var mat = new THREE.Matrix4().extractRotation( this.matrix ); 
this.rotation.setEulerFromRotationMatrix( mat, this.eulerOrder ); 
this.position.getPositionFromMatrix( this.matrix ); 
}, 
 
translate: function ( distance, axis ) { 
this.matrix.rotateAxis( axis ); 
this.position.addSelf( axis.multiplyScalar( distance ) ); 
}, 
translateX: function ( distance ) { 
this.translate( distance, this._vector.set( 1, 0, 0 ) ); 
}, 
 
traverse: function ( callback ) { 
callback( this ); 
for ( var i = 0, l = this.children.length; i < l; i ++ ) { 
this.children[ i ].traverse( callback ); 
} 
}, 
 
updateMatrix: function () { 
this.matrix.setPosition( this.position ); 
if ( this.useQuaternion === false ) { 
this.matrix.setRotationFromEuler( this.rotation, this.eulerOrder ); 
} else { 
this.matrix.setRotationFromQuaternion( this.quaternion ); 
} 
if ( this.scale.x !== 1 || this.scale.y !== 1 || this.scale.z !== 1 ) { 
this.matrix.scale( this.scale ); 
this.boundRadiusScale = Math.max( this.scale.x, Math.max( this.scale.y, this.scale.z ) ); 
} 
this.matrixWorldNeedsUpdate = true; 
}, 
updateMatrixWorld: function ( force ) { 
if ( this.matrixAutoUpdate === true ) this.updateMatrix(); 
if ( this.matrixWorldNeedsUpdate === true || force === true ) { 
if ( this.parent === undefined ) { 
this.matrixWorld.copy( this.matrix ); 
} else { 
this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix ); 
} 
this.matrixWorldNeedsUpdate = false; 
force = true; 
} 
for ( var i = 0, l = this.children.length; i < l; i ++ ) { 
this.children[ i ].updateMatrixWorld( force ); 
} 
}, 
 
THREE.UV = function ( u, v ) { 
this.u = u || 0; 
this.v = v || 0; 
}; 
 
THREE.Geometry = function () { 
THREE.GeometryLibrary.push( this ); 
this.id = THREE.GeometryIdCount ++; 
this.name = ''; 
this.vertices = []; 
this.colors = []; 
this.normals = []; 
this.faces = []; 
this.faceUvs = [[]]; 
this.faceVertexUvs = [[]]; 
this.morphTargets = []; 
this.morphColors = []; 
this.morphNormals = []; 
this.skinWeights = []; 
this.skinIndices = []; 
this.lineDistances = []; 
this.boundingBox = null; 
this.boundingSphere = null; 
this.hasTangents = false; 
this.dynamic = true; 
this.verticesNeedUpdate = false; 
this.elementsNeedUpdate = false; 
this.uvsNeedUpdate = false; 
this.normalsNeedUpdate = false; 
this.tangentsNeedUpdate = false; 
this.colorsNeedUpdate = false; 
this.lineDistancesNeedUpdate = false; 
this.buffersNeedUpdate = false; 
}; 
 
applyMatrix: function ( matrix ) { 
var normalMatrix = new THREE.Matrix3(); 
normalMatrix.getInverse( matrix ).transpose(); 
for ( var i = 0, il = this.vertices.length; i < il; i ++ ) { 
var vertex = this.vertices[ i ]; 
matrix.multiplyVector3( vertex ); 
} 
for ( var i = 0, il = this.faces.length; i < il; i ++ ) { 
var face = this.faces[ i ]; 
normalMatrix.multiplyVector3( face.normal ).normalize(); 
for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) { 
normalMatrix.multiplyVector3( face.vertexNormals[ j ] ).normalize(); 
} 
matrix.multiplyVector3( face.centroid ); 
} 
}, 
 
THREE.Quaternion = function( x, y, z, w ) { 
this.x = x || 0; 
this.y = y || 0; 
this.z = z || 0; 
this.w = ( w !== undefined ) ? w : 1; 
};