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