Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extras: Convert to classes. #21624

Merged
merged 2 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/extras/DataUtils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const _floatView = new Float32Array( 1 );
const _int32View = new Int32Array( _floatView.buffer );

const DataUtils = {
class DataUtils {

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

toHalfFloat: function ( val ) {
static toHalfFloat( val ) {

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

Expand Down Expand Up @@ -54,6 +54,6 @@ const DataUtils = {

}

};
}

export { DataUtils };
6 changes: 3 additions & 3 deletions src/extras/ImageUtils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
let _canvas;

const ImageUtils = {
class ImageUtils {

getDataURL: function ( image ) {
static getDataURL( image ) {

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

Expand Down Expand Up @@ -59,6 +59,6 @@ const ImageUtils = {

}

};
}

export { ImageUtils };
14 changes: 7 additions & 7 deletions src/extras/ShapeUtils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Earcut } from './Earcut.js';

const ShapeUtils = {
class ShapeUtils {

// calculate area of the contour polygon

area: function ( contour ) {
static area( contour ) {

const n = contour.length;
let a = 0.0;
Expand All @@ -17,15 +17,15 @@ const ShapeUtils = {

return a * 0.5;

},
}

isClockWise: function ( pts ) {
static isClockWise( pts ) {

return ShapeUtils.area( pts ) < 0;

},
}

triangulateShape: function ( contour, holes ) {
static triangulateShape( contour, holes ) {

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

}

};
}

function removeDupEndPts( points ) {

Expand Down
70 changes: 35 additions & 35 deletions src/extras/core/Curve.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,39 @@ import { Matrix4 } from '../../math/Matrix4.js';
*
**/

function Curve() {
class Curve {

this.type = 'Curve';
constructor() {

this.arcLengthDivisions = 200;
this.type = 'Curve';

}
this.arcLengthDivisions = 200;

Object.assign( Curve.prototype, {
}

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

getPoint: function ( /* t, optionalTarget */ ) {
getPoint( /* t, optionalTarget */ ) {

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

},
}

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

getPointAt: function ( u, optionalTarget ) {
getPointAt( u, optionalTarget ) {

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

},
}

// Get sequence of points using getPoint( t )

getPoints: function ( divisions = 5 ) {
getPoints( divisions = 5 ) {

const points = [];

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

return points;

},
}

// Get sequence of points using getPointAt( u )

getSpacedPoints: function ( divisions = 5 ) {
getSpacedPoints( divisions = 5 ) {

const points = [];

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

return points;

},
}

// Get total curve arc length

getLength: function () {
getLength() {

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

},
}

// Get list of cumulative segment lengths

getLengths: function ( divisions ) {
getLengths( divisions ) {

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

Expand Down Expand Up @@ -139,18 +139,18 @@ Object.assign( Curve.prototype, {

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

},
}

updateArcLengths: function () {
updateArcLengths() {

this.needsUpdate = true;
this.getLengths();

},
}

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

getUtoTmapping: function ( u, distance ) {
getUtoTmapping( u, distance ) {

const arcLengths = this.getLengths();

Expand Down Expand Up @@ -223,14 +223,14 @@ Object.assign( Curve.prototype, {

return t;

},
}

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

getTangent: function ( t, optionalTarget ) {
getTangent( t, optionalTarget ) {

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

return tangent;

},
}

getTangentAt: function ( u, optionalTarget ) {
getTangentAt( u, optionalTarget ) {

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

},
}

computeFrenetFrames: function ( segments, closed ) {
computeFrenetFrames( segments, closed ) {

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

Expand Down Expand Up @@ -372,23 +372,23 @@ Object.assign( Curve.prototype, {
binormals: binormals
};

},
}

clone: function () {
clone() {

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

},
}

copy: function ( source ) {
copy( source ) {

this.arcLengthDivisions = source.arcLengthDivisions;

return this;

},
}

toJSON: function () {
toJSON() {

const data = {
metadata: {
Expand All @@ -403,17 +403,17 @@ Object.assign( Curve.prototype, {

return data;

},
}

fromJSON: function ( json ) {
fromJSON( json ) {

this.arcLengthDivisions = json.arcLengthDivisions;

return this;

}

} );
}


export { Curve };
33 changes: 17 additions & 16 deletions src/extras/objects/ImmediateRenderObject.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { Object3D } from '../../core/Object3D.js';

function ImmediateRenderObject( material ) {
class ImmediateRenderObject extends Object3D {

Object3D.call( this );
constructor( material ) {

this.material = material;
this.render = function ( /* renderCallback */ ) {};
super();

this.hasPositions = false;
this.hasNormals = false;
this.hasColors = false;
this.hasUvs = false;
this.material = material;
this.render = function ( /* renderCallback */ ) {};

this.positionArray = null;
this.normalArray = null;
this.colorArray = null;
this.uvArray = null;
this.hasPositions = false;
this.hasNormals = false;
this.hasColors = false;
this.hasUvs = false;

this.count = 0;
this.positionArray = null;
this.normalArray = null;
this.colorArray = null;
this.uvArray = null;

}
this.count = 0;

}

ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
}

ImmediateRenderObject.prototype.isImmediateRenderObject = true;

Expand Down