Skip to content

Commit

Permalink
Merge pull request #19994 from DefinitelyMaybe/src/geometires--move-t…
Browse files Browse the repository at this point in the history
…o-es6-classes

geometries: move to es6 classes
mrdoob authored Aug 3, 2020
2 parents a5c63ac + aa324f2 commit b2da39b
Showing 21 changed files with 1,989 additions and 1,969 deletions.
129 changes: 65 additions & 64 deletions src/geometries/CircleGeometry.js
Original file line number Diff line number Diff line change
@@ -6,109 +6,110 @@ import { Vector2 } from '../math/Vector2.js';

// CircleGeometry

function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
class CircleGeometry extends Geometry {

Geometry.call( this );
constructor( radius, segments, thetaStart, thetaLength ) {

this.type = 'CircleGeometry';
super();
this.type = 'CircleGeometry';

this.parameters = {
radius: radius,
segments: segments,
thetaStart: thetaStart,
thetaLength: thetaLength
};
this.parameters = {
radius: radius,
segments: segments,
thetaStart: thetaStart,
thetaLength: thetaLength
};

this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
this.mergeVertices();
this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
this.mergeVertices();

}
}

CircleGeometry.prototype = Object.create( Geometry.prototype );
CircleGeometry.prototype.constructor = CircleGeometry;
}

// CircleBufferGeometry

function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
class CircleBufferGeometry extends BufferGeometry {

BufferGeometry.call( this );
constructor( radius, segments, thetaStart, thetaLength ) {

this.type = 'CircleBufferGeometry';
super();

this.parameters = {
radius: radius,
segments: segments,
thetaStart: thetaStart,
thetaLength: thetaLength
};
this.type = 'CircleBufferGeometry';

radius = radius || 1;
segments = segments !== undefined ? Math.max( 3, segments ) : 8;
this.parameters = {
radius: radius,
segments: segments,
thetaStart: thetaStart,
thetaLength: thetaLength
};

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

// buffers
thetaStart = thetaStart !== undefined ? thetaStart : 0;
thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;

const indices = [];
const vertices = [];
const normals = [];
const uvs = [];
// buffers

// helper variables
const indices = [];
const vertices = [];
const normals = [];
const uvs = [];

const vertex = new Vector3();
const uv = new Vector2();
// helper variables

// center point
const vertex = new Vector3();
const uv = new Vector2();

vertices.push( 0, 0, 0 );
normals.push( 0, 0, 1 );
uvs.push( 0.5, 0.5 );
// center point

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

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

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

vertex.x = radius * Math.cos( segment );
vertex.y = radius * Math.sin( segment );
// vertex

vertices.push( vertex.x, vertex.y, vertex.z );
vertex.x = radius * Math.cos( segment );
vertex.y = radius * Math.sin( segment );

// normal
vertices.push( vertex.x, vertex.y, vertex.z );

normals.push( 0, 0, 1 );
// normal

// uvs
normals.push( 0, 0, 1 );

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

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

}
uvs.push( uv.x, uv.y );

// indices
}

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

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

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

// build geometry
}

this.setIndex( indices );
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
// build geometry

}
this.setIndex( indices );
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );

CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
}

}


export { CircleGeometry, CircleBufferGeometry };
60 changes: 30 additions & 30 deletions src/geometries/ConeGeometry.js
Original file line number Diff line number Diff line change
@@ -3,49 +3,49 @@ import { CylinderBufferGeometry } from './CylinderGeometry.js';

// ConeGeometry

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

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

this.type = 'ConeGeometry';
super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
this.type = 'ConeGeometry';

this.parameters = {
radius: radius,
height: height,
radialSegments: radialSegments,
heightSegments: heightSegments,
openEnded: openEnded,
thetaStart: thetaStart,
thetaLength: thetaLength
};
this.parameters = {
radius: radius,
height: height,
radialSegments: radialSegments,
heightSegments: heightSegments,
openEnded: openEnded,
thetaStart: thetaStart,
thetaLength: thetaLength
};

}
}

ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
ConeGeometry.prototype.constructor = ConeGeometry;
}

// ConeBufferGeometry

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

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

this.type = 'ConeBufferGeometry';
super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
this.type = 'ConeBufferGeometry';

this.parameters = {
radius: radius,
height: height,
radialSegments: radialSegments,
heightSegments: heightSegments,
openEnded: openEnded,
thetaStart: thetaStart,
thetaLength: thetaLength
};
this.parameters = {
radius: radius,
height: height,
radialSegments: radialSegments,
heightSegments: heightSegments,
openEnded: openEnded,
thetaStart: thetaStart,
thetaLength: thetaLength
};

}
}

ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
}


export { ConeGeometry, ConeBufferGeometry };
Loading

0 comments on commit b2da39b

Please sign in to comment.