three.js 源碼注釋(六十六)objects/Sprite.js,three.jssprite.js

來源:互聯網
上載者:User

three.js 源碼注釋(六十六)objects/Sprite.js,three.jssprite.js

商域無疆 (http://blog.csdn.net/omni360/)

本文遵循“署名-非商業用途-保持一致”創作公用協議

轉載請保留此句:商域無疆 -  本部落格專註於 敏捷開發及移動和物聯裝置研究:資料視覺效果、GOLANG、Html5、WEBGL、THREE.JS,否則,出自本部落格的文章拒絕轉載或再轉載,謝謝合作。


俺也是剛開始學,好多地兒肯定不對還請見諒.

以下代碼是THREE.JS 源碼檔案中objects/Sprite.js檔案的注釋.

更多更新在 : https://github.com/omni360/three.js.sourcecode

/** * @author mikael emtinger / http://gomo.se/ * @author alteredq / http://alteredqualia.com/ *//*///Sprite對象,點精靈對象,對應粒子物件,具體的實現是通過BufferGeometry建立一個總是面對相機的平面./// 用法:var map = THREE.ImageUtils.loadTexture("sprite.png");//載入image對象/// var material = new THREE.SpriteMaterial({map:map,color: 0xffffff,fog: true});//建立材質對象,這裡有專門適用於Sprite對象的材質對象SpriteMaterial./// var sprite = new THREE.Sprite( material);//建立精靈對象./// scene.add(line); //將精靈添加到情境中.*////<summary>Sprite</summary>///<param name ="material" type="THREE.SpriteMaterial">選擇性參數,SpriteMaterial對象(點精靈對象專用的材質對象)</param>///<returns type="Sprite">返回Sprite對象</returns>THREE.Sprite = ( function () {var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0 ] );var geometry = new THREE.BufferGeometry();//使用buffergeometry對象geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );//為geometry對象添加position屬性.這裡可以看考BufferGeometry對象的源碼注釋.return function ( material ) {THREE.Object3D.call( this );//調用Object3D對象的call方法,將原本屬於Object3D的方法交給當前對象Sprite來使用.this.geometry = geometry;this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();};} )();/*****************************************************下面是Sprite對象的方法屬性定義,繼承自Object3D**************************************************/THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );/*///raycast方法用來獲得當前對象與射線(參數raycaster)的交點.raycaster.intersectObject會調用這個方法。主要是用來進行碰撞檢測,/// 在選擇情境中的對象時經常會用到,判斷當前滑鼠是否與對象重合用來選擇對象./// NOTE:raycast方法中參數intersects參數用來儲存交點的集合,格式如下///intersects.push( {//////distance: distance,///point: this.position,///face: null,///object: this//////} );///*////<summary>raycast</summary>///<param name ="raycaster" type="THREE.Raycaster">射線對象</param>///<param name ="intersects" type="ObjectArray">交點的屬性集合</param>///<returns type="ObjectArray">交點的屬性集合</returns>THREE.Sprite.prototype.raycast = ( function () {var matrixPosition = new THREE.Vector3();return function ( raycaster, intersects ) {matrixPosition.setFromMatrixPosition( this.matrixWorld );var distance = raycaster.ray.distanceToPoint( matrixPosition );if ( distance > this.scale.x ) {return;}intersects.push( {distance: distance,point: this.position,face: null,object: this} );};}() );/*updateMatrix方法///updateMatrix方法更新情境中當前精靈的平移、旋轉和縮放屬性.*////<summary>updateMatrix</summary>///<returns type="Skeleton">返回新的Sprite精靈對象.</returns>THREE.Sprite.prototype.updateMatrix = function () {this.matrix.compose( this.position, this.quaternion, this.scale );//compose方法應用變換矩陣的平移、旋轉和縮放設定this.matrixWorldNeedsUpdate = true;//Sprite對象matrixWorldNeedsUpdate屬性,設定為true.};/*clone方法///clone方法複製一個Sprite精靈對象.*////<summary>clone</summary>///<param name ="object" type="Sprite">接收複製的Sprite對象</param>///<returns type="Sprite">返回複製的Sprite精靈對象.</returns>THREE.Sprite.prototype.clone = function ( object ) {if ( object === undefined ) object = new THREE.Sprite( this.material );THREE.Object3D.prototype.clone.call( this, object );return object;//返回複製的Sprite精靈對象};// Backwards compatibility 向後相容,粒子被更名為精靈.THREE.Particle = THREE.Sprite;



商域無疆 (http://blog.csdn.net/omni360/)

本文遵循“署名-非商業用途-保持一致”創作公用協議

轉載請保留此句:商域無疆 -  本部落格專註於 敏捷開發及移動和物聯裝置研究:資料視覺效果、GOLANG、Html5、WEBGL、THREE.JS,否則,出自本部落格的文章拒絕轉載或再轉載,謝謝合作。


以下代碼是THREE.JS 源碼檔案中objects/Sprite.js檔案的注釋.

更多更新在 : https://github.com/omni360/three.js.sourcecode

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.