From 70823f5486a471f29468bebf440d3345f159148a Mon Sep 17 00:00:00 2001 From: Ed Preston Date: Thu, 9 Feb 2023 02:09:59 +1100 Subject: [PATCH 1/4] Separate Out eslintConfig move eslintConfig to its own file to keep package.json clean modifications and commits not bound to or carry the risk of dependency changes. This commit is the equivalent configuration as the starting point. --- .eslintrc.json | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 52 ---------------------------------------------- 2 files changed, 56 insertions(+), 52 deletions(-) create mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000000000..9f9a60fd8ec040 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,56 @@ +{ + "root": true, + "parserOptions": { + "ecmaVersion": 2020, // parse at 2020 using rules to enforce 2018 + "sourceType": "module" + }, + "extends": [ + "mdcs", + "plugin:compat/recommended" + ], + "plugins": [ + "html", + "import" + ], + "settings": { + "polyfills": [ + "WebGL2RenderingContext" + ] + }, + "globals": { + "__THREE_DEVTOOLS__": "readonly", + "potpack": "readonly", + "fflate": "readonly", + "OIMO": "readonly", + "Stats": "readonly", + "XRWebGLBinding": "readonly", + "XRWebGLLayer": "readonly", + "GPUShaderStage": "readonly", + "GPUBufferUsage": "readonly", + "GPUTextureUsage": "readonly", + "GPUMapMode": "readonly", + "QUnit": "readonly", + "Ammo": "readonly", + "XRRigidTransform": "readonly", + "XRMediaBinding": "readonly", + "CodeMirror": "readonly", + "esprima": "readonly", + "jsonlint": "readonly" + }, + "rules": { + "no-throw-literal": [ + "error" + ], + "quotes": [ + "error", + "single" + ], + "prefer-const": [ + "error", + { + "destructuring": "any", + "ignoreReadBeforeAssign": false + } + ] + } +} diff --git a/package.json b/package.json index 461e3480cf1b85..2b3980c0cd03e0 100644 --- a/package.json +++ b/package.json @@ -38,58 +38,6 @@ "example": "examples", "test": "test" }, - "eslintConfig": { - "root": true, - "extends": [ - "mdcs", - "plugin:compat/recommended" - ], - "plugins": [ - "html", - "import" - ], - "settings": { - "polyfills": [ - "WebGL2RenderingContext" - ] - }, - "globals": { - "__THREE_DEVTOOLS__": "readonly", - "potpack": "readonly", - "fflate": "readonly", - "OIMO": "readonly", - "Stats": "readonly", - "XRWebGLBinding": "readonly", - "XRWebGLLayer": "readonly", - "GPUShaderStage": "readonly", - "GPUBufferUsage": "readonly", - "GPUTextureUsage": "readonly", - "GPUMapMode": "readonly", - "QUnit": "readonly", - "Ammo": "readonly", - "XRRigidTransform": "readonly", - "XRMediaBinding": "readonly", - "CodeMirror": "readonly", - "esprima": "readonly", - "jsonlint": "readonly" - }, - "rules": { - "no-throw-literal": [ - "error" - ], - "quotes": [ - "error", - "single" - ], - "prefer-const": [ - "error", - { - "destructuring": "any", - "ignoreReadBeforeAssign": false - } - ] - } - }, "browserslist": [ "> 1%, not dead, not ie 11, not op_mini all" ], From cdecf121c216a1cf7ae79c5c2d375a7ef9012722 Mon Sep 17 00:00:00 2001 From: Ed Preston Date: Thu, 9 Feb 2023 13:32:10 +1100 Subject: [PATCH 2/4] Update Three.js Convert ES 2020 imports into 2018. --- src/Three.js | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/Three.js b/src/Three.js index 8254f9a36f7038..a18aeb3d1caf68 100644 --- a/src/Three.js +++ b/src/Three.js @@ -86,7 +86,14 @@ export { BooleanKeyframeTrack } from './animation/tracks/BooleanKeyframeTrack.js export { PropertyMixer } from './animation/PropertyMixer.js'; export { PropertyBinding } from './animation/PropertyBinding.js'; export { KeyframeTrack } from './animation/KeyframeTrack.js'; -export * as AnimationUtils from './animation/AnimationUtils.js'; +export { arraySlice } from './animation/AnimationUtils.js'; +export { convertArray } from './animation/AnimationUtils.js'; +export { isTypedArray } from './animation/AnimationUtils.js'; +export { getKeyframeOrder } from './animation/AnimationUtils.js'; +export { sortedArray } from './animation/AnimationUtils.js'; +export { flattenJSON } from './animation/AnimationUtils.js'; +export { subclip } from './animation/AnimationUtils.js'; +export { makeClipAdditive } from './animation/AnimationUtils.js'; export { AnimationObjectGroup } from './animation/AnimationObjectGroup.js'; export { AnimationMixer } from './animation/AnimationMixer.js'; export { AnimationClip } from './animation/AnimationClip.js'; @@ -111,7 +118,30 @@ export { DiscreteInterpolant } from './math/interpolants/DiscreteInterpolant.js' export { CubicInterpolant } from './math/interpolants/CubicInterpolant.js'; export { Interpolant } from './math/Interpolant.js'; export { Triangle } from './math/Triangle.js'; -export * as MathUtils from './math/MathUtils.js'; +export { DEG2RAD } from './math/MathUtils.js'; +export { RAD2DEG } from './math/MathUtils.js'; +export { generateUUID } from './math/MathUtils.js'; +export { clamp } from './math/MathUtils.js'; +export { euclideanModulo } from './math/MathUtils.js'; +export { mapLinear } from './math/MathUtils.js'; +export { inverseLerp } from './math/MathUtils.js'; +export { lerp } from './math/MathUtils.js'; +export { damp } from './math/MathUtils.js'; +export { pingpong } from './math/MathUtils.js'; +export { smoothstep } from './math/MathUtils.js'; +export { smootherstep } from './math/MathUtils.js'; +export { randInt } from './math/MathUtils.js'; +export { randFloat } from './math/MathUtils.js'; +export { randFloatSpread } from './math/MathUtils.js'; +export { seededRandom } from './math/MathUtils.js'; +export { degToRad } from './math/MathUtils.js'; +export { radToDeg } from './math/MathUtils.js'; +export { isPowerOfTwo } from './math/MathUtils.js'; +export { ceilPowerOfTwo } from './math/MathUtils.js'; +export { floorPowerOfTwo } from './math/MathUtils.js'; +export { setQuaternionFromProperEuler } from './math/MathUtils.js'; +export { normalize } from './math/MathUtils.js'; +export { denormalize } from './math/MathUtils.js'; export { Spherical } from './math/Spherical.js'; export { Cylindrical } from './math/Cylindrical.js'; export { Plane } from './math/Plane.js'; @@ -150,7 +180,8 @@ export { Path } from './extras/core/Path.js'; export { ShapePath } from './extras/core/ShapePath.js'; export { CurvePath } from './extras/core/CurvePath.js'; export { Curve } from './extras/core/Curve.js'; -export * as DataUtils from './extras/DataUtils.js'; +export { toHalfFloat } from './extras/DataUtils.js'; +export { fromHalfFloat } from './extras/DataUtils.js'; export { ImageUtils } from './extras/ImageUtils.js'; export { ShapeUtils } from './extras/ShapeUtils.js'; export { PMREMGenerator } from './extras/PMREMGenerator.js'; From 899b16929e452f167a4cae5a0cedac5075324b0a Mon Sep 17 00:00:00 2001 From: Ed Preston Date: Thu, 9 Feb 2023 13:32:38 +1100 Subject: [PATCH 3/4] Update .eslintrc.json Set project to ES 2018 --- .eslintrc.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9f9a60fd8ec040..e9a40f2d87acf6 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,12 @@ { "root": true, + "env": { + "browser": true, + "node": true, + "es2018": true + }, "parserOptions": { - "ecmaVersion": 2020, // parse at 2020 using rules to enforce 2018 + "ecmaVersion": 2018, "sourceType": "module" }, "extends": [ From 1c93446592bbc7e50b661a40a5d19685994bccbf Mon Sep 17 00:00:00 2001 From: Ed Preston Date: Thu, 9 Feb 2023 14:28:31 +1100 Subject: [PATCH 4/4] Add Public Interface Export Objects MathUtils, AnimationUtils, and DataUtils need to be updated to export their namespaces. Privately, individual functions are exported to support the other parts of the library, publicly they are namespaced with an object wrapper. --- src/Three.js | 37 +++------------------------------ src/animation/AnimationUtils.js | 14 ++++++++++++- src/extras/DataUtils.js | 8 ++++++- src/math/MathUtils.js | 28 ++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 37 deletions(-) diff --git a/src/Three.js b/src/Three.js index a18aeb3d1caf68..929845050689b7 100644 --- a/src/Three.js +++ b/src/Three.js @@ -86,14 +86,7 @@ export { BooleanKeyframeTrack } from './animation/tracks/BooleanKeyframeTrack.js export { PropertyMixer } from './animation/PropertyMixer.js'; export { PropertyBinding } from './animation/PropertyBinding.js'; export { KeyframeTrack } from './animation/KeyframeTrack.js'; -export { arraySlice } from './animation/AnimationUtils.js'; -export { convertArray } from './animation/AnimationUtils.js'; -export { isTypedArray } from './animation/AnimationUtils.js'; -export { getKeyframeOrder } from './animation/AnimationUtils.js'; -export { sortedArray } from './animation/AnimationUtils.js'; -export { flattenJSON } from './animation/AnimationUtils.js'; -export { subclip } from './animation/AnimationUtils.js'; -export { makeClipAdditive } from './animation/AnimationUtils.js'; +export { AnimationUtils } from './animation/AnimationUtils.js'; export { AnimationObjectGroup } from './animation/AnimationObjectGroup.js'; export { AnimationMixer } from './animation/AnimationMixer.js'; export { AnimationClip } from './animation/AnimationClip.js'; @@ -118,30 +111,7 @@ export { DiscreteInterpolant } from './math/interpolants/DiscreteInterpolant.js' export { CubicInterpolant } from './math/interpolants/CubicInterpolant.js'; export { Interpolant } from './math/Interpolant.js'; export { Triangle } from './math/Triangle.js'; -export { DEG2RAD } from './math/MathUtils.js'; -export { RAD2DEG } from './math/MathUtils.js'; -export { generateUUID } from './math/MathUtils.js'; -export { clamp } from './math/MathUtils.js'; -export { euclideanModulo } from './math/MathUtils.js'; -export { mapLinear } from './math/MathUtils.js'; -export { inverseLerp } from './math/MathUtils.js'; -export { lerp } from './math/MathUtils.js'; -export { damp } from './math/MathUtils.js'; -export { pingpong } from './math/MathUtils.js'; -export { smoothstep } from './math/MathUtils.js'; -export { smootherstep } from './math/MathUtils.js'; -export { randInt } from './math/MathUtils.js'; -export { randFloat } from './math/MathUtils.js'; -export { randFloatSpread } from './math/MathUtils.js'; -export { seededRandom } from './math/MathUtils.js'; -export { degToRad } from './math/MathUtils.js'; -export { radToDeg } from './math/MathUtils.js'; -export { isPowerOfTwo } from './math/MathUtils.js'; -export { ceilPowerOfTwo } from './math/MathUtils.js'; -export { floorPowerOfTwo } from './math/MathUtils.js'; -export { setQuaternionFromProperEuler } from './math/MathUtils.js'; -export { normalize } from './math/MathUtils.js'; -export { denormalize } from './math/MathUtils.js'; +export { MathUtils } from './math/MathUtils.js'; export { Spherical } from './math/Spherical.js'; export { Cylindrical } from './math/Cylindrical.js'; export { Plane } from './math/Plane.js'; @@ -180,8 +150,7 @@ export { Path } from './extras/core/Path.js'; export { ShapePath } from './extras/core/ShapePath.js'; export { CurvePath } from './extras/core/CurvePath.js'; export { Curve } from './extras/core/Curve.js'; -export { toHalfFloat } from './extras/DataUtils.js'; -export { fromHalfFloat } from './extras/DataUtils.js'; +export { DataUtils } from './extras/DataUtils.js'; export { ImageUtils } from './extras/ImageUtils.js'; export { ShapeUtils } from './extras/ShapeUtils.js'; export { PMREMGenerator } from './extras/PMREMGenerator.js'; diff --git a/src/animation/AnimationUtils.js b/src/animation/AnimationUtils.js index 0ac0626810d4ea..6cd6f5ba1ccb64 100644 --- a/src/animation/AnimationUtils.js +++ b/src/animation/AnimationUtils.js @@ -349,6 +349,17 @@ function makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targe } +const AnimationUtils = { + arraySlice: arraySlice, + convertArray: convertArray, + isTypedArray: isTypedArray, + getKeyframeOrder: getKeyframeOrder, + sortedArray: sortedArray, + flattenJSON: flattenJSON, + subclip: subclip, + makeClipAdditive: makeClipAdditive +}; + export { arraySlice, convertArray, @@ -357,5 +368,6 @@ export { sortedArray, flattenJSON, subclip, - makeClipAdditive + makeClipAdditive, + AnimationUtils }; diff --git a/src/extras/DataUtils.js b/src/extras/DataUtils.js index ec3910b5231a1b..3234f34c0106a6 100644 --- a/src/extras/DataUtils.js +++ b/src/extras/DataUtils.js @@ -164,7 +164,13 @@ function fromHalfFloat( val ) { } +const DataUtils = { + toHalfFloat: toHalfFloat, + fromHalfFloat: fromHalfFloat, +}; + export { toHalfFloat, - fromHalfFloat + fromHalfFloat, + DataUtils }; diff --git a/src/math/MathUtils.js b/src/math/MathUtils.js index f64985edf8d892..8b1d6ae3046677 100644 --- a/src/math/MathUtils.js +++ b/src/math/MathUtils.js @@ -291,7 +291,32 @@ function normalize( value, array ) { } - +const MathUtils = { + DEG2RAD: DEG2RAD, + RAD2DEG: RAD2DEG, + generateUUID: generateUUID, + clamp: clamp, + euclideanModulo: euclideanModulo, + mapLinear: mapLinear, + inverseLerp: inverseLerp, + lerp: lerp, + damp: damp, + pingpong: pingpong, + smoothstep: smoothstep, + smootherstep: smootherstep, + randInt: randInt, + randFloat: randFloat, + randFloatSpread: randFloatSpread, + seededRandom: seededRandom, + degToRad: degToRad, + radToDeg: radToDeg, + isPowerOfTwo: isPowerOfTwo, + ceilPowerOfTwo: ceilPowerOfTwo, + floorPowerOfTwo: floorPowerOfTwo, + setQuaternionFromProperEuler: setQuaternionFromProperEuler, + normalize: normalize, + denormalize: denormalize +}; export { DEG2RAD, @@ -318,4 +343,5 @@ export { setQuaternionFromProperEuler, normalize, denormalize, + MathUtils };