| |
| |
| |
| |
|
|
| import { Geometry } from '../core/Geometry.js'; |
| import { BufferGeometry } from '../core/BufferGeometry.js'; |
| import { Float32BufferAttribute } from '../core/BufferAttribute.js'; |
| import { Vector2 } from '../math/Vector2.js'; |
| import { Vector3 } from '../math/Vector3.js'; |
|
|
| |
|
|
| function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) { |
|
|
| Geometry.call( this ); |
|
|
| this.type = 'RingGeometry'; |
|
|
| this.parameters = { |
| innerRadius: innerRadius, |
| outerRadius: outerRadius, |
| thetaSegments: thetaSegments, |
| phiSegments: phiSegments, |
| thetaStart: thetaStart, |
| thetaLength: thetaLength |
| }; |
|
|
| this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) ); |
| this.mergeVertices(); |
|
|
| } |
|
|
| RingGeometry.prototype = Object.create( Geometry.prototype ); |
| RingGeometry.prototype.constructor = RingGeometry; |
|
|
| |
|
|
| function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) { |
|
|
| BufferGeometry.call( this ); |
|
|
| this.type = 'RingBufferGeometry'; |
|
|
| this.parameters = { |
| innerRadius: innerRadius, |
| outerRadius: outerRadius, |
| thetaSegments: thetaSegments, |
| phiSegments: phiSegments, |
| thetaStart: thetaStart, |
| thetaLength: thetaLength |
| }; |
|
|
| innerRadius = innerRadius || 0.5; |
| outerRadius = outerRadius || 1; |
|
|
| thetaStart = thetaStart !== undefined ? thetaStart : 0; |
| thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; |
|
|
| thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8; |
| phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1; |
|
|
| |
|
|
| var indices = []; |
| var vertices = []; |
| var normals = []; |
| var uvs = []; |
|
|
| |
|
|
| var segment; |
| var radius = innerRadius; |
| var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments ); |
| var vertex = new Vector3(); |
| var uv = new Vector2(); |
| var j, i; |
|
|
| |
|
|
| for ( j = 0; j <= phiSegments; j ++ ) { |
|
|
| for ( i = 0; i <= thetaSegments; i ++ ) { |
|
|
| |
|
|
| segment = thetaStart + i / thetaSegments * thetaLength; |
|
|
| |
|
|
| vertex.x = radius * Math.cos( segment ); |
| vertex.y = radius * Math.sin( segment ); |
|
|
| vertices.push( vertex.x, vertex.y, vertex.z ); |
|
|
| |
|
|
| normals.push( 0, 0, 1 ); |
|
|
| |
|
|
| uv.x = ( vertex.x / outerRadius + 1 ) / 2; |
| uv.y = ( vertex.y / outerRadius + 1 ) / 2; |
|
|
| uvs.push( uv.x, uv.y ); |
|
|
| } |
|
|
| |
|
|
| radius += radiusStep; |
|
|
| } |
|
|
| |
|
|
| for ( j = 0; j < phiSegments; j ++ ) { |
|
|
| var thetaSegmentLevel = j * ( thetaSegments + 1 ); |
|
|
| for ( i = 0; i < thetaSegments; i ++ ) { |
|
|
| segment = i + thetaSegmentLevel; |
|
|
| var a = segment; |
| var b = segment + thetaSegments + 1; |
| var c = segment + thetaSegments + 2; |
| var d = segment + 1; |
|
|
| |
|
|
| indices.push( a, b, d ); |
| indices.push( b, c, d ); |
|
|
| } |
|
|
| } |
|
|
| |
|
|
| this.setIndex( indices ); |
| this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); |
| this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); |
| this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); |
|
|
| } |
|
|
| RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); |
| RingBufferGeometry.prototype.constructor = RingBufferGeometry; |
|
|
|
|
| export { RingGeometry, RingBufferGeometry }; |
|
|