Skip to content

Commit b2da39b

Browse files
authored
Merge pull request #19994 from DefinitelyMaybe/src/geometires--move-to-es6-classes
geometries: move to es6 classes
2 parents a5c63ac + aa324f2 commit b2da39b

21 files changed

+1989
-1969
lines changed

src/geometries/CircleGeometry.js

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,109 +6,110 @@ import { Vector2 } from '../math/Vector2.js';
66

77
// CircleGeometry
88

9-
function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
9+
class CircleGeometry extends Geometry {
1010

11-
Geometry.call( this );
11+
constructor( radius, segments, thetaStart, thetaLength ) {
1212

13-
this.type = 'CircleGeometry';
13+
super();
14+
this.type = 'CircleGeometry';
1415

15-
this.parameters = {
16-
radius: radius,
17-
segments: segments,
18-
thetaStart: thetaStart,
19-
thetaLength: thetaLength
20-
};
16+
this.parameters = {
17+
radius: radius,
18+
segments: segments,
19+
thetaStart: thetaStart,
20+
thetaLength: thetaLength
21+
};
2122

22-
this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
23-
this.mergeVertices();
23+
this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
24+
this.mergeVertices();
2425

25-
}
26+
}
2627

27-
CircleGeometry.prototype = Object.create( Geometry.prototype );
28-
CircleGeometry.prototype.constructor = CircleGeometry;
28+
}
2929

3030
// CircleBufferGeometry
3131

32-
function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
32+
class CircleBufferGeometry extends BufferGeometry {
3333

34-
BufferGeometry.call( this );
34+
constructor( radius, segments, thetaStart, thetaLength ) {
3535

36-
this.type = 'CircleBufferGeometry';
36+
super();
3737

38-
this.parameters = {
39-
radius: radius,
40-
segments: segments,
41-
thetaStart: thetaStart,
42-
thetaLength: thetaLength
43-
};
38+
this.type = 'CircleBufferGeometry';
4439

45-
radius = radius || 1;
46-
segments = segments !== undefined ? Math.max( 3, segments ) : 8;
40+
this.parameters = {
41+
radius: radius,
42+
segments: segments,
43+
thetaStart: thetaStart,
44+
thetaLength: thetaLength
45+
};
4746

48-
thetaStart = thetaStart !== undefined ? thetaStart : 0;
49-
thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
47+
radius = radius || 1;
48+
segments = segments !== undefined ? Math.max( 3, segments ) : 8;
5049

51-
// buffers
50+
thetaStart = thetaStart !== undefined ? thetaStart : 0;
51+
thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
5252

53-
const indices = [];
54-
const vertices = [];
55-
const normals = [];
56-
const uvs = [];
53+
// buffers
5754

58-
// helper variables
55+
const indices = [];
56+
const vertices = [];
57+
const normals = [];
58+
const uvs = [];
5959

60-
const vertex = new Vector3();
61-
const uv = new Vector2();
60+
// helper variables
6261

63-
// center point
62+
const vertex = new Vector3();
63+
const uv = new Vector2();
6464

65-
vertices.push( 0, 0, 0 );
66-
normals.push( 0, 0, 1 );
67-
uvs.push( 0.5, 0.5 );
65+
// center point
6866

69-
for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
67+
vertices.push( 0, 0, 0 );
68+
normals.push( 0, 0, 1 );
69+
uvs.push( 0.5, 0.5 );
7070

71-
const segment = thetaStart + s / segments * thetaLength;
71+
for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
7272

73-
// vertex
73+
const segment = thetaStart + s / segments * thetaLength;
7474

75-
vertex.x = radius * Math.cos( segment );
76-
vertex.y = radius * Math.sin( segment );
75+
// vertex
7776

78-
vertices.push( vertex.x, vertex.y, vertex.z );
77+
vertex.x = radius * Math.cos( segment );
78+
vertex.y = radius * Math.sin( segment );
7979

80-
// normal
80+
vertices.push( vertex.x, vertex.y, vertex.z );
8181

82-
normals.push( 0, 0, 1 );
82+
// normal
8383

84-
// uvs
84+
normals.push( 0, 0, 1 );
8585

86-
uv.x = ( vertices[ i ] / radius + 1 ) / 2;
87-
uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
86+
// uvs
8887

89-
uvs.push( uv.x, uv.y );
88+
uv.x = ( vertices[ i ] / radius + 1 ) / 2;
89+
uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
9090

91-
}
91+
uvs.push( uv.x, uv.y );
9292

93-
// indices
93+
}
9494

95-
for ( let i = 1; i <= segments; i ++ ) {
95+
// indices
9696

97-
indices.push( i, i + 1, 0 );
97+
for ( let i = 1; i <= segments; i ++ ) {
9898

99-
}
99+
indices.push( i, i + 1, 0 );
100100

101-
// build geometry
101+
}
102102

103-
this.setIndex( indices );
104-
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
105-
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
106-
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
103+
// build geometry
107104

108-
}
105+
this.setIndex( indices );
106+
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
107+
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
108+
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
109109

110-
CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
111-
CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
110+
}
111+
112+
}
112113

113114

114115
export { CircleGeometry, CircleBufferGeometry };

src/geometries/ConeGeometry.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,49 @@ import { CylinderBufferGeometry } from './CylinderGeometry.js';
33

44
// ConeGeometry
55

6-
function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
6+
class ConeGeometry extends CylinderGeometry {
77

8-
CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
8+
constructor( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
99

10-
this.type = 'ConeGeometry';
10+
super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
11+
this.type = 'ConeGeometry';
1112

12-
this.parameters = {
13-
radius: radius,
14-
height: height,
15-
radialSegments: radialSegments,
16-
heightSegments: heightSegments,
17-
openEnded: openEnded,
18-
thetaStart: thetaStart,
19-
thetaLength: thetaLength
20-
};
13+
this.parameters = {
14+
radius: radius,
15+
height: height,
16+
radialSegments: radialSegments,
17+
heightSegments: heightSegments,
18+
openEnded: openEnded,
19+
thetaStart: thetaStart,
20+
thetaLength: thetaLength
21+
};
2122

22-
}
23+
}
2324

24-
ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
25-
ConeGeometry.prototype.constructor = ConeGeometry;
25+
}
2626

2727
// ConeBufferGeometry
2828

29-
function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
29+
class ConeBufferGeometry extends CylinderBufferGeometry {
3030

31-
CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
31+
constructor( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
3232

33-
this.type = 'ConeBufferGeometry';
33+
super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
34+
this.type = 'ConeBufferGeometry';
3435

35-
this.parameters = {
36-
radius: radius,
37-
height: height,
38-
radialSegments: radialSegments,
39-
heightSegments: heightSegments,
40-
openEnded: openEnded,
41-
thetaStart: thetaStart,
42-
thetaLength: thetaLength
43-
};
36+
this.parameters = {
37+
radius: radius,
38+
height: height,
39+
radialSegments: radialSegments,
40+
heightSegments: heightSegments,
41+
openEnded: openEnded,
42+
thetaStart: thetaStart,
43+
thetaLength: thetaLength
44+
};
4445

45-
}
46+
}
4647

47-
ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
48-
ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
48+
}
4949

5050

5151
export { ConeGeometry, ConeBufferGeometry };

0 commit comments

Comments
 (0)