three.js 源碼注釋(八十二)extras/geometries/RingGeometry.js,three.jsgeometries

來源:互聯網
上載者:User

three.js 源碼注釋(八十二)extras/geometries/RingGeometry.js,three.jsgeometries

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

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

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


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

以下代碼是THREE.JS 源碼檔案中extras/geometries/RingGeometry.js檔案的注釋.

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


/** * @author Kaleb Murphy *//*///RingGeometry用來在三維空間內建立一個二維圓環面對象.//////用法: var geometry = new THREE.RingGeometry(1,5,32);///   var material = new THREE.MeshBasicMaterial({color: 0x00ff00});///   var Ring = new THREE.Mesh(geometry,material);///   scene.add(Ring);*////<summary>TorusGeometry</summary>///<param name ="innerRadius" type="float">圓環面內圓半徑,預設初始化為0</param>///<param name ="outerRadius" type="float">圓環面外圓半徑,預設初始化為50</param>///<param name ="thetaSegments" type="int">圓環面圓周上的細分線段數,代表了圓環的圓度,最低的是3。預設值是8</param>///<param name ="phiSegments" type="int">圓環面內圓到外圓方向上的細分線段數,最低的是1。預設值是8</param>///<param name ="thetaStart" type="float">圓環面的起始角度,預設初始化為0</param>///<param name ="thetaLength" type="float">圓環面圓周弧長,預設初始化為Math.PI * 2</param>THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {THREE.Geometry.call( this );//調用Geometry對象的call方法,將原本屬於Geometry的方法交給當前對象RingGeometry來使用.innerRadius = innerRadius || 0;//圓環面內圓半徑,預設初始化為0outerRadius = outerRadius || 50;//圓環面外圓半徑,預設初始化為50thetaStart = thetaStart !== undefined ? thetaStart : 0;//圓環面的起始角度,預設初始化為0thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;//圓環面圓周弧長,預設初始化為Math.PI * 2thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;//圓環面圓周上的細分線段數,代表了圓環的圓度,最低的是3。預設值是8phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;//圓環面內圓到外圓方向上的細分線段數,最低的是1。預設值是8var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );//計算頂點資料,壓入vertices數組.for ( i = 0; i < phiSegments + 1; i ++ ) { // concentric circles inside ringfor ( o = 0; o < thetaSegments + 1; o ++ ) { // number of segments per circle 圓周上的分段數var vertex = new THREE.Vector3();var segment = thetaStart + o / thetaSegments * thetaLength;vertex.x = radius * Math.cos( segment );vertex.y = radius * Math.sin( segment );this.vertices.push( vertex );uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );}radius += radiusStep;}var n = new THREE.Vector3( 0, 0, 1 );//計算三角面,以及貼圖uv.for ( i = 0; i < phiSegments; i ++ ) { // concentric circles inside ringvar thetaSegment = i * (thetaSegments + 1);for ( o = 0; o < thetaSegments ; o ++ ) { // number of segments per circle 圓周上的分段數var segment = o + thetaSegment;var v1 = segment;var v2 = segment + thetaSegments + 1;var v3 = segment + thetaSegments + 2;this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ]);v1 = segment;v2 = segment + thetaSegments + 2;v3 = segment + 1;this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ]);}}this.computeFaceNormals();//計算面的法線this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );//計算球體邊界};/*****************************************************下面是RingGeometry對象的方法屬性定義,繼承自Geometry對象.**************************************************/THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );


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

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

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


以下代碼是THREE.JS 源碼檔案中extras/geometries/RingGeometry.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.