diff --git a/src/extras/controls/MouseControls.js b/src/extras/controls/MouseControls.js index 669f3d4..ca692ef 100755 --- a/src/extras/controls/MouseControls.js +++ b/src/extras/controls/MouseControls.js @@ -7,7 +7,7 @@ import THREE from 'three'; * This controls allow to change the orientation of the camera using the mouse */ -THREE.MouseControls = function ( object ) { +const MouseControls = function ( object ) { var scope = this; var PI_2 = Math.PI / 2; @@ -62,3 +62,5 @@ THREE.MouseControls = function ( object ) { document.addEventListener( 'mousemove', onMouseMove, false ); }; + +export default MouseControls; diff --git a/src/extras/controls/OrbitControls.js b/src/extras/controls/OrbitControls.js index 2bc3d63..afc08b9 100755 --- a/src/extras/controls/OrbitControls.js +++ b/src/extras/controls/OrbitControls.js @@ -1,4 +1,3 @@ -// Added in order to make it work with a modular approach import THREE from 'three'; /** @@ -16,7 +15,7 @@ import THREE from 'three'; // Zoom - middle mouse, or mousewheel / touch: two finger spread or squish // Pan - right mouse, or arrow keys / touch: three finter swipe -THREE.OrbitControls = function ( object, domElement ) { +const OrbitControls = function ( object, domElement ) { this.object = object; @@ -911,10 +910,10 @@ THREE.OrbitControls = function ( object, domElement ) { }; -THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype ); -THREE.OrbitControls.prototype.constructor = THREE.OrbitControls; +OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype ); +OrbitControls.prototype.constructor = OrbitControls; -Object.defineProperties( THREE.OrbitControls.prototype, { +Object.defineProperties( OrbitControls.prototype, { center: { @@ -1038,3 +1037,5 @@ Object.defineProperties( THREE.OrbitControls.prototype, { } } ); + +export default OrbitControls; diff --git a/src/extras/controls/TrackballControls.js b/src/extras/controls/TrackballControls.js index f7e2bc4..254671a 100755 --- a/src/extras/controls/TrackballControls.js +++ b/src/extras/controls/TrackballControls.js @@ -8,7 +8,7 @@ import THREE from 'three'; * @author Luca Antiga / http://lantiga.github.io */ -THREE.TrackballControls = function ( object, domElement ) { +const TrackballControls = function ( object, domElement ) { var _this = this; var STATE = { NONE: - 1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 }; @@ -622,5 +622,7 @@ THREE.TrackballControls = function ( object, domElement ) { }; -THREE.TrackballControls.prototype = Object.create( THREE.EventDispatcher.prototype ); -THREE.TrackballControls.prototype.constructor = THREE.TrackballControls; +TrackballControls.prototype = Object.create( THREE.EventDispatcher.prototype ); +TrackballControls.prototype.constructor = TrackballControls; + +export default TrackballControls; diff --git a/src/extras/exporters/OBJExporter.js b/src/extras/exporters/OBJExporter.js index 07b2dc2..c8b6b9a 100755 --- a/src/extras/exporters/OBJExporter.js +++ b/src/extras/exporters/OBJExporter.js @@ -1,10 +1,12 @@ +import THREE from 'three'; + /** * @author mrdoob / http://mrdoob.com/ */ -THREE.OBJExporter = function () {}; +const OBJExporter = function () {}; -THREE.OBJExporter.prototype = { +OBJExporter.prototype = { constructor: THREE.OBJExporter, @@ -254,3 +256,5 @@ THREE.OBJExporter.prototype = { } }; + +export default OBJExporter; diff --git a/src/extras/exporters/STLBinaryExporter.js b/src/extras/exporters/STLBinaryExporter.js index f92f67c..8ec6557 100755 --- a/src/extras/exporters/STLBinaryExporter.js +++ b/src/extras/exporters/STLBinaryExporter.js @@ -1,12 +1,14 @@ +import THREE from 'three'; + /** * @author kovacsv / http://kovacsv.hu/ * @author mrdoob / http://mrdoob.com/ * @author mudcube / http://mudcu.be/ */ -THREE.STLBinaryExporter = function () {}; +const STLBinaryExporter = function () {}; -THREE.STLBinaryExporter.prototype = { +STLBinaryExporter.prototype = { constructor: THREE.STLBinaryExporter, @@ -92,3 +94,5 @@ THREE.STLBinaryExporter.prototype = { }() ) }; + +export default STLBinaryExporter; diff --git a/src/extras/exporters/STLExporter.js b/src/extras/exporters/STLExporter.js index d69ce83..bf2d217 100755 --- a/src/extras/exporters/STLExporter.js +++ b/src/extras/exporters/STLExporter.js @@ -1,11 +1,13 @@ +import THREE from 'three'; + /** * @author kovacsv / http://kovacsv.hu/ * @author mrdoob / http://mrdoob.com/ */ -THREE.STLExporter = function () {}; +const STLExporter = function () {}; -THREE.STLExporter.prototype = { +STLExporter.prototype = { constructor: THREE.STLExporter, @@ -73,3 +75,5 @@ THREE.STLExporter.prototype = { }() ) }; + +export default STLExporter; diff --git a/src/extras/geometry/curves/NURBSCurve.js b/src/extras/geometry/curves/NURBSCurve.js index ca3d869..750bb1d 100755 --- a/src/extras/geometry/curves/NURBSCurve.js +++ b/src/extras/geometry/curves/NURBSCurve.js @@ -1,3 +1,5 @@ +import THREE from 'three'; + /** * @author renej * NURBS curve object @@ -13,7 +15,7 @@ * NURBS curve **************************************************************/ -THREE.NURBSCurve = function ( degree, knots /* array of reals */, controlPoints /* array of Vector(2|3|4) */ ) { +const NURBSCurve = function ( degree, knots /* array of reals */, controlPoints /* array of Vector(2|3|4) */ ) { this.degree = degree; this.knots = knots; @@ -29,11 +31,11 @@ THREE.NURBSCurve = function ( degree, knots /* array of reals */, controlPoints }; -THREE.NURBSCurve.prototype = Object.create( THREE.Curve.prototype ); -THREE.NURBSCurve.prototype.constructor = THREE.NURBSCurve; +NURBSCurve.prototype = Object.create( THREE.Curve.prototype ); +NURBSCurve.prototype.constructor = NURBSCurve; -THREE.NURBSCurve.prototype.getPoint = function ( t ) { +NURBSCurve.prototype.getPoint = function ( t ) { var u = this.knots[ 0 ] + t * ( this.knots[ this.knots.length - 1 ] - this.knots[ 0 ] ); // linear mapping t->u @@ -52,7 +54,7 @@ THREE.NURBSCurve.prototype.getPoint = function ( t ) { }; -THREE.NURBSCurve.prototype.getTangent = function ( t ) { +NURBSCurve.prototype.getTangent = function ( t ) { var u = this.knots[ 0 ] + t * ( this.knots[ this.knots.length - 1 ] - this.knots[ 0 ] ); var ders = THREE.NURBSUtils.calcNURBSDerivatives( this.degree, this.knots, this.controlPoints, u, 1 ); @@ -63,3 +65,4 @@ THREE.NURBSCurve.prototype.getTangent = function ( t ) { }; +export default NURBSCurve; diff --git a/src/extras/geometry/curves/NURBSSurface.js b/src/extras/geometry/curves/NURBSSurface.js index 5eecd61..386dc37 100755 --- a/src/extras/geometry/curves/NURBSSurface.js +++ b/src/extras/geometry/curves/NURBSSurface.js @@ -1,3 +1,5 @@ +import THREE from 'three'; + /** * @author renej * NURBS surface object @@ -11,7 +13,7 @@ * NURBS surface **************************************************************/ -THREE.NURBSSurface = function ( degree1, degree2, knots1, knots2 /* arrays of reals */, controlPoints /* array^2 of Vector(2|3|4) */ ) { +const NURBSSurface = function ( degree1, degree2, knots1, knots2 /* arrays of reals */, controlPoints /* array^2 of Vector(2|3|4) */ ) { this.degree1 = degree1; this.degree2 = degree2; @@ -38,9 +40,9 @@ THREE.NURBSSurface = function ( degree1, degree2, knots1, knots2 /* arrays of re }; -THREE.NURBSSurface.prototype = { +NURBSSurface.prototype = { - constructor: THREE.NURBSSurface, + constructor: NURBSSurface, getPoint: function ( t1, t2 ) { @@ -53,3 +55,4 @@ THREE.NURBSSurface.prototype = { }; +export default NURBSSurface; diff --git a/src/extras/geometry/curves/NURBSUtils.js b/src/extras/geometry/curves/NURBSUtils.js index 07128d6..f1763b7 100755 --- a/src/extras/geometry/curves/NURBSUtils.js +++ b/src/extras/geometry/curves/NURBSUtils.js @@ -1,3 +1,5 @@ +import THREE from 'three'; + /** * @author renej * NURBS utils @@ -11,7 +13,7 @@ * NURBS Utils **************************************************************/ -THREE.NURBSUtils = { +const NURBSUtils = { /* Finds knot vector span. @@ -19,7 +21,7 @@ THREE.NURBSUtils = { p : degree u : parametric value U : knot vector - + returns the span */ findSpan: function( p, u, U ) { @@ -43,7 +45,7 @@ THREE.NURBSUtils = { var mid = Math.floor( ( low + high ) / 2 ); while ( u < U[ mid ] || u >= U[ mid + 1 ] ) { - + if ( u < U[ mid ] ) { high = mid; @@ -61,16 +63,16 @@ THREE.NURBSUtils = { return mid; }, - - + + /* Calculate basis functions. See The NURBS Book, page 70, algorithm A2.2 - + span : span in which u lies u : parametric point p : degree U : knot vector - + returns array[p+1] with basis functions values. */ calcBasisFunctions: function( span, u, p, U ) { @@ -81,7 +83,7 @@ THREE.NURBSUtils = { N[ 0 ] = 1.0; for ( var j = 1; j <= p; ++ j ) { - + left[ j ] = u - U[ span + 1 - j ]; right[ j ] = U[ span + j ] - u; @@ -108,7 +110,7 @@ THREE.NURBSUtils = { /* Calculate B-Spline curve points. See The NURBS Book, page 82, algorithm A3.1. - + p : degree of B-Spline U : knot vector P : control points (x, y, z, w) @@ -422,7 +424,7 @@ THREE.NURBSUtils = { /* Calculate rational B-Spline surface point. See The NURBS Book, page 134, algorithm A4.3. - + p1, p2 : degrees of B-Spline surface U1, U2 : knot vectors P : control points (x, y, z, w) @@ -468,5 +470,4 @@ THREE.NURBSUtils = { }; - - +export default NURBSUtils; diff --git a/src/extras/loaders/3MFLoader.js b/src/extras/loaders/3MFLoader.js index 0fbb270..d61a871 100755 --- a/src/extras/loaders/3MFLoader.js +++ b/src/extras/loaders/3MFLoader.js @@ -1,11 +1,13 @@ -THREE.ThreeMFLoader = function ( manager ) { +import THREE from 'three'; + +const ThreeMFLoader = function ( manager ) { this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; this.availableExtensions = []; }; -THREE.ThreeMFLoader.prototype = { +ThreeMFLoader.prototype = { constructor: THREE.ThreeMFLoader, @@ -267,7 +269,7 @@ THREE.ThreeMFLoader.prototype = { } if ( pid ) { - + triangleProperty[ 'pid' ] = pid; } @@ -540,7 +542,7 @@ THREE.ThreeMFLoader.prototype = { var modelsKeys = Object.keys( modelsData ); for ( var i = 0; i < modelsKeys.length; i++ ) { - + var modelsKey = modelsKeys[ i ]; var modelData = modelsData[ modelsKey ]; var modelXml = modelData[ 'xml' ]; @@ -602,3 +604,5 @@ THREE.ThreeMFLoader.prototype = { } }; + +export default ThreeMFLoader; diff --git a/src/extras/loaders/BinaryLoader.js b/src/extras/loaders/BinaryLoader.js index 0441b3c..ac5b198 100755 --- a/src/extras/loaders/BinaryLoader.js +++ b/src/extras/loaders/BinaryLoader.js @@ -1,8 +1,10 @@ +import THREE from 'Three'; + /** * @author alteredq / http://alteredqualia.com/ */ -THREE.BinaryLoader = function ( manager ) { +const BinaryLoader = function ( manager ) { if ( typeof manager === 'boolean' ) { @@ -15,7 +17,7 @@ THREE.BinaryLoader = function ( manager ) { }; -THREE.BinaryLoader.prototype = { +BinaryLoader.prototype = { constructor: THREE.BinaryLoader, @@ -696,3 +698,5 @@ THREE.BinaryLoader.prototype = { } }; + +export default BinaryLoader; diff --git a/src/extras/loaders/OBJLoader.js b/src/extras/loaders/OBJLoader.js index 0bb1b19..fb3b4fe 100755 --- a/src/extras/loaders/OBJLoader.js +++ b/src/extras/loaders/OBJLoader.js @@ -1,8 +1,10 @@ +import THREE from 'Three'; + /** * @author mrdoob / http://mrdoob.com/ */ -THREE.OBJLoader = function ( manager ) { +const OBJLoader = function ( manager ) { this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; @@ -35,7 +37,7 @@ THREE.OBJLoader = function ( manager ) { }; -THREE.OBJLoader.prototype = { +OBJLoader.prototype = { constructor: THREE.OBJLoader, @@ -716,3 +718,5 @@ THREE.OBJLoader.prototype = { } }; + +export default OBJLoader; diff --git a/src/extras/loaders/STLLoader.js b/src/extras/loaders/STLLoader.js index 1040a25..305257f 100755 --- a/src/extras/loaders/STLLoader.js +++ b/src/extras/loaders/STLLoader.js @@ -1,3 +1,5 @@ +import THREE from 'Three'; + /** * @author aleeper / http://adamleeper.com/ * @author mrdoob / http://mrdoob.com/ @@ -27,13 +29,13 @@ */ -THREE.STLLoader = function ( manager ) { +const STLLoader = function ( manager ) { this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; }; -THREE.STLLoader.prototype = { +STLLoader.prototype = { constructor: THREE.STLLoader, @@ -489,3 +491,5 @@ if ( typeof DataView === 'undefined' ) { }; } + + export default STLLoader; diff --git a/src/extras/loaders/SVGLoader.js b/src/extras/loaders/SVGLoader.js index fbcd92c..395140e 100755 --- a/src/extras/loaders/SVGLoader.js +++ b/src/extras/loaders/SVGLoader.js @@ -1,17 +1,19 @@ +import THREE from 'Three'; + /** * @author mrdoob / http://mrdoob.com/ * @author zz85 / http://joshuakoo.com/ */ -THREE.SVGLoader = function ( manager ) { +const SVGLoader = function ( manager ) { this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; }; -THREE.SVGLoader.prototype = { +SVGLoader.prototype = { - constructor: THREE.SVGLoader, + constructor: SVGLoader, load: function ( url, onLoad, onProgress, onError ) { @@ -31,3 +33,5 @@ THREE.SVGLoader.prototype = { } }; + +export default SVGLoader; diff --git a/src/zetoff-three.js b/src/zetoff-three.js index f6f7cb2..7dabf4d 100644 --- a/src/zetoff-three.js +++ b/src/zetoff-three.js @@ -1,29 +1,28 @@ -//Make THREE a global variable -import './three-global'; +import THREE from 'three'; //Loader Libraries -import './extras/loaders/STLLoader'; -import './extras/loaders/OBJLoader'; -import './extras/loaders/BinaryLoader'; -import './extras/loaders/SVGLoader'; -import './extras/loaders/3MFLoader'; +import STLLoader from './extras/loaders/STLLoader'; +import OBJLoader from './extras/loaders/OBJLoader'; +import BinaryLoader from './extras/loaders/BinaryLoader'; +import SVGLoader from './extras/loaders/SVGLoader'; +import ThreeMFLoader from './extras/loaders/3MFLoader'; //Export Libraries //TODO: test these Libraries -import './extras/exporters/STLBinaryExporter'; -import './extras/exporters/STLExporter'; -import './extras/exporters/OBJExporter'; +import STLBinaryExporter from './extras/exporters/STLBinaryExporter'; +import STLExporter from './extras/exporters/STLExporter'; +import OBJExporter from './extras/exporters/OBJExporter'; //Control Libraries -import './extras/controls/OrbitControls'; -import './extras/controls/MouseControls'; -import './extras/controls/TrackballControls'; +import OrbitControls from './extras/controls/OrbitControls'; +import MouseControls from './extras/controls/MouseControls'; +import TrackballControls from './extras/controls/TrackballControls'; //Geometry -import './extras/geometry/curves/NURBSCurve'; -import './extras/geometry/curves/NURBSSurface'; -import './extras/geometry/curves/NURBSUtils'; +import NURBSCurve from './extras/geometry/curves/NURBSCurve'; +import NURBSSurface from './extras/geometry/curves/NURBSSurface'; +import NURBSUtils from './extras/geometry/curves/NURBSUtils'; import ThreeBSP from './extras/geometry/modifiers/ThreeCSG'; //math @@ -33,13 +32,27 @@ import './math'; //TODO: Add Shaders -//Assign the global THREE to the local THREE -const THREE = global.THREE; -//Delete global THREE -delete global.THREE; +THREE.STLLoader = STLLoader; +THREE.OBJLoader = OBJLoader; +THREE.BinaryLoader = BinaryLoader; +THREE.SVGLoader = SVGLoader; +THREE.ThreeMFLoader = ThreeMFLoader; + +THREE.STLBinaryExporter = STLBinaryExporter; +THREE.STLExporter = STLExporter; +THREE.OBJExporter = OBJExporter; + +THREE.OrbitControls = OrbitControls; +THREE.MouseControls = MouseControls; +THREE.TrackballControls = TrackballControls; + +THREE.NURBSCurve = NURBSCurve; +THREE.NURBSSurface = NURBSSurface; +THREE.NURBSUtils = NURBSUtils; +// FIXME ThreeBSP should be exported as THREE.BSP? //Export local THREE export default THREE; //Export others -export {ThreeBSP}; +export { ThreeBSP };