該類用來表示空間中的「射線」,主要用來進行碰撞檢測。windows
THREE.Ray = function ( origin, direction ) { this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3(); this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3(); };
Ray類的構造函數頗爲簡單,只有兩個參數origin和direction,顧名思義,也就是端點和方向。數組
Ray類的主要做用是進行碰撞檢測。函數
THREE.Ray.prototype = { constructor: THREE.Ray, set: function ( origin, direction ) {...}, copy: function ( ray ) {...}, at: function( t, optionalTarget ) { var result = optionalTarget || new THREE.Vector3(); return result.copy( this.direction ).multiplyScalar( t ).add( this.origin ); }, recast: function ( t ) { this.origin.copy( this.at( t, THREE.Ray.__v1 ) ); return this; }, closestPointToPoint: function ( point, optionalTarget ) { var result = optionalTarget || new THREE.Vector3(); result.subVectors( point, this.origin ); var directionDistance = result.dot( this.direction ); return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin ); }, distanceToPoint: function ( point ) { var directionDistance = THREE.Ray.__v1.subVectors( point, this.origin ).dot( this.direction ); THREE.Ray.__v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin ); return THREE.Ray.__v1.distanceTo( point ); }, isIntersectionSphere: function( sphere ) { return ( this.distanceToPoint( sphere.center ) <= sphere.radius ); }, isIntersectionPlane: function ( plane ) { // check if the line and plane are non-perpendicular, if they // eventually they will intersect. var denominator = plane.normal.dot( this.direction ); if ( denominator != 0 ) { return true; } // line is coplanar, return origin if( plane.distanceToPoint( this.origin ) == 0 ) { return true; } return false; }, distanceToPlane: function ( plane ) { var denominator = plane.normal.dot( this.direction ); if ( denominator == 0 ) { // line is coplanar, return origin if( plane.distanceToPoint( this.origin ) == 0 ) { return 0; } // Unsure if this is the correct method to handle this case. return undefined; } var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator; return t; }, intersectPlane: function ( plane, optionalTarget ) { var t = this.distanceToPlane( plane ); if( t === undefined ) { return undefined; } return this.at( t, optionalTarget ); }, transform: function ( matrix4 ) {...}, equals: function ( ray ) {...}, clone: function () {...} };
Ray類有這樣一些方法:this
以前咱們分析過Material類和LineBasicMaterial類,如今咱們來看剩下的幾個材質類。MeshBasicMaterial是一種「光照無關」的材質,也就是說,在沒有光照的狀況下,材質依然可以要顯示出來。spa
THREE.MeshBasicMaterial = function ( parameters ) { THREE.Material.call( this ); this.color = new THREE.Color( 0xffffff ); // emissive this.map = null; this.lightMap = null; this.specularMap = null; this.envMap = null; this.combine = THREE.MultiplyOperation; this.reflectivity = 1; this.refractionRatio = 0.98; this.fog = true; this.shading = THREE.SmoothShading; this.wireframe = false; this.wireframeLinewidth = 1; this.wireframeLinecap = 'round'; this.wireframeLinejoin = 'round'; this.vertexColors = THREE.NoColors; this.skinning = false; this.morphTargets = false; this.setValues( parameters ); };
MeshBasicMaterial包括這樣一些屬性:prototype
MeshLambertMaterial是一種朗伯面材質。朗伯面就是各向反射同性面,任何角度的光線照射上去,反射的亮度和反射角度無關。如下摘錄了除掉與MeshBasicMaterial重複的屬性剩下的若干個屬性。code
THREE.MeshLambertMaterial = function ( parameters ) { THREE.Material.call( this ); this.color = new THREE.Color( 0xffffff ); // diffuse this.ambient = new THREE.Color( 0xffffff ); this.emissive = new THREE.Color( 0x000000 ); this.wrapAround = false; this.wrapRGB = new THREE.Vector3( 1, 1, 1 ); this.combine = THREE.MultiplyOperation; this.reflectivity = 1; this.refractionRatio = 0.98; ... this.setValues( parameters ); };
除了MeshBasicMaterial中的color,vertexColors等屬性,MeshLambertMaterial類還具備幾個跟光照相關的屬性:orm
MeshPhongMaterial,旁氏反射面,表示有光澤的物體,在極端狀況下就是鏡面。對象
THREE.MeshPhongMaterial = function ( parameters ) { THREE.Material.call( this ); this.color = new THREE.Color( 0xffffff ); // diffuse this.ambient = new THREE.Color( 0xffffff ); this.emissive = new THREE.Color( 0x000000 ); this.specular = new THREE.Color( 0x111111 ); this.shininess = 30; this.metal = false; this.perPixel = true;
this.bumpMap = null; this.bumpScale = 1; this.normalMap = null; this.normalScale = new THREE.Vector2( 1, 1 ); ...this.setValues( parameters ); };
暫時還沒大弄明白。blog
容許爲某個geometry的每一個面單獨指定材質,一般用於從三維模型中讀取數據,而後構造mesh。
THREE.MeshFaceMaterial = function ( materials ) { this.materials = materials instanceof Array ? materials : []; };
只須要傳入一個數組做爲參數,其materials數組的每個元素都是某種MeshXXXXMaterial,而後再geometry中建立表面時,爲face指定materialIndex便可。