2
0

CircleTypedGeometry.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * @author hughes
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. THREE.CircleTypedGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  6. this.parameters = {
  7. radius: radius,
  8. segments: segments,
  9. thetaStart: thetaStart,
  10. thetaLength: thetaLength
  11. };
  12. radius = radius || 50;
  13. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  14. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  15. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  16. //
  17. var elements = segments + 2;
  18. var indices = new Uint16Array( segments * 3 );
  19. var vertices = new Float32Array( elements * 3 );
  20. var normals = new Float32Array( elements * 3 );
  21. var uvs = new Float32Array( elements * 2 );
  22. // center
  23. normals[ 2 ] = 1;
  24. uvs[ 0 ] = 0.5;
  25. uvs[ 1 ] = 0.5;
  26. var offset = 0, offset2 = 2, offset3 = 3;
  27. for ( var i = 0; i <= segments; i ++ ) {
  28. var segment = thetaStart + i / segments * thetaLength;
  29. var x = radius * Math.cos( segment );
  30. var y = radius * Math.sin( segment );
  31. vertices[ offset3 ] = x;
  32. vertices[ offset3 + 1 ] = y;
  33. normals[ offset3 + 2 ] = 1;
  34. uvs[ offset2 ] = ( x / radius + 1 ) / 2;
  35. uvs[ offset2 + 1 ] = ( y / radius + 1 ) / 2;
  36. offset2 += 2;
  37. offset3 += 3;
  38. //
  39. indices[ offset ] = 0;
  40. indices[ offset + 1 ] = i + 1;
  41. indices[ offset + 2 ] = i + 2;
  42. offset += 3;
  43. }
  44. THREE.IndexedTypedGeometry.call( this );
  45. this.setArrays( indices, vertices, normals, uvs );
  46. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  47. };
  48. THREE.CircleTypedGeometry.prototype = Object.create( THREE.IndexedTypedGeometry.prototype );
  49. THREE.CircleTypedGeometry.prototype.constructor = THREE.CircleTypedGeometry;