Skip to content

Commit 2f14e62

Browse files
authored
Extras: Convert to classes. (#21624)
* Extras: Convert to classes. * Extras: Clean up.
1 parent 92e531c commit 2f14e62

File tree

5 files changed

+65
-64
lines changed

5 files changed

+65
-64
lines changed

src/extras/DataUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const _floatView = new Float32Array( 1 );
22
const _int32View = new Int32Array( _floatView.buffer );
33

4-
const DataUtils = {
4+
class DataUtils {
55

66
// Converts float32 to float16 (stored as uint16 value).
77

8-
toHalfFloat: function ( val ) {
8+
static toHalfFloat( val ) {
99

1010
// Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
1111

@@ -54,6 +54,6 @@ const DataUtils = {
5454

5555
}
5656

57-
};
57+
}
5858

5959
export { DataUtils };

src/extras/ImageUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
let _canvas;
22

3-
const ImageUtils = {
3+
class ImageUtils {
44

5-
getDataURL: function ( image ) {
5+
static getDataURL( image ) {
66

77
if ( /^data:/i.test( image.src ) ) {
88

@@ -59,6 +59,6 @@ const ImageUtils = {
5959

6060
}
6161

62-
};
62+
}
6363

6464
export { ImageUtils };

src/extras/ShapeUtils.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Earcut } from './Earcut.js';
22

3-
const ShapeUtils = {
3+
class ShapeUtils {
44

55
// calculate area of the contour polygon
66

7-
area: function ( contour ) {
7+
static area( contour ) {
88

99
const n = contour.length;
1010
let a = 0.0;
@@ -17,15 +17,15 @@ const ShapeUtils = {
1717

1818
return a * 0.5;
1919

20-
},
20+
}
2121

22-
isClockWise: function ( pts ) {
22+
static isClockWise( pts ) {
2323

2424
return ShapeUtils.area( pts ) < 0;
2525

26-
},
26+
}
2727

28-
triangulateShape: function ( contour, holes ) {
28+
static triangulateShape( contour, holes ) {
2929

3030
const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
3131
const holeIndices = []; // array of hole indices
@@ -64,7 +64,7 @@ const ShapeUtils = {
6464

6565
}
6666

67-
};
67+
}
6868

6969
function removeDupEndPts( points ) {
7070

src/extras/core/Curve.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,39 @@ import { Matrix4 } from '../../math/Matrix4.js';
3333
*
3434
**/
3535

36-
function Curve() {
36+
class Curve {
3737

38-
this.type = 'Curve';
38+
constructor() {
3939

40-
this.arcLengthDivisions = 200;
40+
this.type = 'Curve';
4141

42-
}
42+
this.arcLengthDivisions = 200;
4343

44-
Object.assign( Curve.prototype, {
44+
}
4545

4646
// Virtual base class method to overwrite and implement in subclasses
4747
// - t [0 .. 1]
4848

49-
getPoint: function ( /* t, optionalTarget */ ) {
49+
getPoint( /* t, optionalTarget */ ) {
5050

5151
console.warn( 'THREE.Curve: .getPoint() not implemented.' );
5252
return null;
5353

54-
},
54+
}
5555

5656
// Get point at relative position in curve according to arc length
5757
// - u [0 .. 1]
5858

59-
getPointAt: function ( u, optionalTarget ) {
59+
getPointAt( u, optionalTarget ) {
6060

6161
const t = this.getUtoTmapping( u );
6262
return this.getPoint( t, optionalTarget );
6363

64-
},
64+
}
6565

6666
// Get sequence of points using getPoint( t )
6767

68-
getPoints: function ( divisions = 5 ) {
68+
getPoints( divisions = 5 ) {
6969

7070
const points = [];
7171

@@ -77,11 +77,11 @@ Object.assign( Curve.prototype, {
7777

7878
return points;
7979

80-
},
80+
}
8181

8282
// Get sequence of points using getPointAt( u )
8383

84-
getSpacedPoints: function ( divisions = 5 ) {
84+
getSpacedPoints( divisions = 5 ) {
8585

8686
const points = [];
8787

@@ -93,20 +93,20 @@ Object.assign( Curve.prototype, {
9393

9494
return points;
9595

96-
},
96+
}
9797

9898
// Get total curve arc length
9999

100-
getLength: function () {
100+
getLength() {
101101

102102
const lengths = this.getLengths();
103103
return lengths[ lengths.length - 1 ];
104104

105-
},
105+
}
106106

107107
// Get list of cumulative segment lengths
108108

109-
getLengths: function ( divisions ) {
109+
getLengths( divisions ) {
110110

111111
if ( divisions === undefined ) divisions = this.arcLengthDivisions;
112112

@@ -139,18 +139,18 @@ Object.assign( Curve.prototype, {
139139

140140
return cache; // { sums: cache, sum: sum }; Sum is in the last element.
141141

142-
},
142+
}
143143

144-
updateArcLengths: function () {
144+
updateArcLengths() {
145145

146146
this.needsUpdate = true;
147147
this.getLengths();
148148

149-
},
149+
}
150150

151151
// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
152152

153-
getUtoTmapping: function ( u, distance ) {
153+
getUtoTmapping( u, distance ) {
154154

155155
const arcLengths = this.getLengths();
156156

@@ -223,14 +223,14 @@ Object.assign( Curve.prototype, {
223223

224224
return t;
225225

226-
},
226+
}
227227

228228
// Returns a unit vector tangent at t
229229
// In case any sub curve does not implement its tangent derivation,
230230
// 2 points a small delta apart will be used to find its gradient
231231
// which seems to give a reasonable approximation
232232

233-
getTangent: function ( t, optionalTarget ) {
233+
getTangent( t, optionalTarget ) {
234234

235235
const delta = 0.0001;
236236
let t1 = t - delta;
@@ -250,16 +250,16 @@ Object.assign( Curve.prototype, {
250250

251251
return tangent;
252252

253-
},
253+
}
254254

255-
getTangentAt: function ( u, optionalTarget ) {
255+
getTangentAt( u, optionalTarget ) {
256256

257257
const t = this.getUtoTmapping( u );
258258
return this.getTangent( t, optionalTarget );
259259

260-
},
260+
}
261261

262-
computeFrenetFrames: function ( segments, closed ) {
262+
computeFrenetFrames( segments, closed ) {
263263

264264
// see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
265265

@@ -372,23 +372,23 @@ Object.assign( Curve.prototype, {
372372
binormals: binormals
373373
};
374374

375-
},
375+
}
376376

377-
clone: function () {
377+
clone() {
378378

379379
return new this.constructor().copy( this );
380380

381-
},
381+
}
382382

383-
copy: function ( source ) {
383+
copy( source ) {
384384

385385
this.arcLengthDivisions = source.arcLengthDivisions;
386386

387387
return this;
388388

389-
},
389+
}
390390

391-
toJSON: function () {
391+
toJSON() {
392392

393393
const data = {
394394
metadata: {
@@ -403,17 +403,17 @@ Object.assign( Curve.prototype, {
403403

404404
return data;
405405

406-
},
406+
}
407407

408-
fromJSON: function ( json ) {
408+
fromJSON( json ) {
409409

410410
this.arcLengthDivisions = json.arcLengthDivisions;
411411

412412
return this;
413413

414414
}
415415

416-
} );
416+
}
417417

418418

419419
export { Curve };

src/extras/objects/ImmediateRenderObject.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
import { Object3D } from '../../core/Object3D.js';
22

3-
function ImmediateRenderObject( material ) {
3+
class ImmediateRenderObject extends Object3D {
44

5-
Object3D.call( this );
5+
constructor( material ) {
66

7-
this.material = material;
8-
this.render = function ( /* renderCallback */ ) {};
7+
super();
98

10-
this.hasPositions = false;
11-
this.hasNormals = false;
12-
this.hasColors = false;
13-
this.hasUvs = false;
9+
this.material = material;
10+
this.render = function ( /* renderCallback */ ) {};
1411

15-
this.positionArray = null;
16-
this.normalArray = null;
17-
this.colorArray = null;
18-
this.uvArray = null;
12+
this.hasPositions = false;
13+
this.hasNormals = false;
14+
this.hasColors = false;
15+
this.hasUvs = false;
1916

20-
this.count = 0;
17+
this.positionArray = null;
18+
this.normalArray = null;
19+
this.colorArray = null;
20+
this.uvArray = null;
2121

22-
}
22+
this.count = 0;
23+
24+
}
2325

24-
ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
25-
ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
26+
}
2627

2728
ImmediateRenderObject.prototype.isImmediateRenderObject = true;
2829

0 commit comments

Comments
 (0)