1 | /**
|
---|
2 | * @author hughes
|
---|
3 | */
|
---|
4 |
|
---|
5 | THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
|
---|
6 |
|
---|
7 | THREE.Geometry.call( this );
|
---|
8 |
|
---|
9 | this.radius = radius = radius || 50;
|
---|
10 | this.segments = segments = segments !== undefined ? Math.max( 3, segments ) : 8;
|
---|
11 |
|
---|
12 | this.thetaStart = thetaStart = thetaStart !== undefined ? thetaStart : 0;
|
---|
13 | this.thetaLength = thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
|
---|
14 |
|
---|
15 | var i, uvs = [],
|
---|
16 | center = new THREE.Vector3(), centerUV = new THREE.Vector2( 0.5, 0.5 );
|
---|
17 |
|
---|
18 | this.vertices.push(center);
|
---|
19 | uvs.push( centerUV );
|
---|
20 |
|
---|
21 | for ( i = 0; i <= segments; i ++ ) {
|
---|
22 |
|
---|
23 | var vertex = new THREE.Vector3();
|
---|
24 | var segment = thetaStart + i / segments * thetaLength;
|
---|
25 |
|
---|
26 | vertex.x = radius * Math.cos( segment );
|
---|
27 | vertex.y = radius * Math.sin( segment );
|
---|
28 |
|
---|
29 | this.vertices.push( vertex );
|
---|
30 | uvs.push( new THREE.Vector2( ( vertex.x / radius + 1 ) / 2, ( vertex.y / radius + 1 ) / 2 ) );
|
---|
31 |
|
---|
32 | }
|
---|
33 |
|
---|
34 | var n = new THREE.Vector3( 0, 0, 1 );
|
---|
35 |
|
---|
36 | for ( i = 1; i <= segments; i ++ ) {
|
---|
37 |
|
---|
38 | var v1 = i;
|
---|
39 | var v2 = i + 1 ;
|
---|
40 | var v3 = 0;
|
---|
41 |
|
---|
42 | this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
|
---|
43 | this.faceVertexUvs[ 0 ].push( [ uvs[ i ].clone(), uvs[ i + 1 ].clone(), centerUV.clone() ] );
|
---|
44 |
|
---|
45 | }
|
---|
46 |
|
---|
47 | this.computeCentroids();
|
---|
48 | this.computeFaceNormals();
|
---|
49 |
|
---|
50 | this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
|
---|
51 |
|
---|
52 | };
|
---|
53 |
|
---|
54 | THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
|
---|