diff --git a/examples/jsm/deprecated/Geometry.js b/examples/jsm/deprecated/Geometry.js index 80a09438c2c6a8..c3b8d8eae5129e 100644 --- a/examples/jsm/deprecated/Geometry.js +++ b/examples/jsm/deprecated/Geometry.js @@ -18,48 +18,48 @@ const _m1 = new Matrix4(); const _obj = new Object3D(); const _offset = new Vector3(); -function Geometry() { +class Geometry extends EventDispatcher { - this.uuid = MathUtils.generateUUID(); + constructor() { - this.name = ''; - this.type = 'Geometry'; + super(); - this.vertices = []; - this.colors = []; - this.faces = []; - this.faceVertexUvs = [[]]; + Object.defineProperty( this, 'isGeometry', { value: true } ); - this.morphTargets = []; - this.morphNormals = []; + this.uuid = MathUtils.generateUUID(); - this.skinWeights = []; - this.skinIndices = []; + this.name = ''; + this.type = 'Geometry'; - this.lineDistances = []; + this.vertices = []; + this.colors = []; + this.faces = []; + this.faceVertexUvs = [[]]; - this.boundingBox = null; - this.boundingSphere = null; + this.morphTargets = []; + this.morphNormals = []; - // update flags + this.skinWeights = []; + this.skinIndices = []; - this.elementsNeedUpdate = false; - this.verticesNeedUpdate = false; - this.uvsNeedUpdate = false; - this.normalsNeedUpdate = false; - this.colorsNeedUpdate = false; - this.lineDistancesNeedUpdate = false; - this.groupsNeedUpdate = false; + this.lineDistances = []; -} + this.boundingBox = null; + this.boundingSphere = null; -Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { + // update flags - constructor: Geometry, + this.elementsNeedUpdate = false; + this.verticesNeedUpdate = false; + this.uvsNeedUpdate = false; + this.normalsNeedUpdate = false; + this.colorsNeedUpdate = false; + this.lineDistancesNeedUpdate = false; + this.groupsNeedUpdate = false; - isGeometry: true, + } - applyMatrix4: function ( matrix ) { + applyMatrix4( matrix ) { const normalMatrix = new Matrix3().getNormalMatrix( matrix ); @@ -100,9 +100,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, + } - rotateX: function ( angle ) { + rotateX( angle ) { // rotate geometry around world x-axis @@ -112,9 +112,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, + } - rotateY: function ( angle ) { + rotateY( angle ) { // rotate geometry around world y-axis @@ -124,9 +124,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, + } - rotateZ: function ( angle ) { + rotateZ( angle ) { // rotate geometry around world z-axis @@ -136,9 +136,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, + } - translate: function ( x, y, z ) { + translate( x, y, z ) { // translate geometry @@ -148,9 +148,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, + } - scale: function ( x, y, z ) { + scale( x, y, z ) { // scale geometry @@ -160,9 +160,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, + } - lookAt: function ( vector ) { + lookAt( vector ) { _obj.lookAt( vector ); @@ -172,9 +172,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, + } - fromBufferGeometry: function ( geometry ) { + fromBufferGeometry( geometry ) { const scope = this; @@ -313,9 +313,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, + } - center: function () { + center() { this.computeBoundingBox(); @@ -325,9 +325,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, + } - normalize: function () { + normalize() { this.computeBoundingSphere(); @@ -348,9 +348,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, + } - computeFaceNormals: function () { + computeFaceNormals() { const cb = new Vector3(), ab = new Vector3(); @@ -372,9 +372,11 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), } - }, + } + + computeVertexNormals( areaWeighted = true ) { - computeVertexNormals: function ( areaWeighted = true ) { + if ( areaWeighted === undefined ) areaWeighted = true; const vertices = new Array( this.vertices.length ); @@ -459,9 +461,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), } - }, + } - computeFlatVertexNormals: function () { + computeFlatVertexNormals() { this.computeFaceNormals(); @@ -493,9 +495,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), } - }, + } - computeMorphNormals: function () { + computeMorphNormals() { // save original normals // - create temp variables on first access @@ -604,9 +606,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), } - }, + } - computeBoundingBox: function () { + computeBoundingBox() { if ( this.boundingBox === null ) { @@ -616,9 +618,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), this.boundingBox.setFromPoints( this.vertices ); - }, + } - computeBoundingSphere: function () { + computeBoundingSphere() { if ( this.boundingSphere === null ) { @@ -628,9 +630,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), this.boundingSphere.setFromPoints( this.vertices ); - }, + } - merge: function ( geometry, matrix, materialIndexOffset = 0 ) { + merge( geometry, matrix, materialIndexOffset = 0 ) { if ( ! ( geometry && geometry.isGeometry ) ) { @@ -747,9 +749,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), } - }, + } - mergeMesh: function ( mesh ) { + mergeMesh( mesh ) { if ( ! ( mesh && mesh.isMesh ) ) { @@ -762,7 +764,7 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), this.merge( mesh.geometry, mesh.matrix ); - }, + } /* * Checks for duplicate vertices with hashmap. @@ -770,7 +772,7 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), * and faces' vertices are updated. */ - mergeVertices: function ( precisionPoints = 4 ) { + mergeVertices( precisionPoints = 4 ) { const verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique) const unique = [], changes = []; @@ -847,9 +849,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), this.vertices = unique; return diff; - }, + } - setFromPoints: function ( points ) { + setFromPoints( points ) { this.vertices = []; @@ -862,9 +864,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, + } - sortFacesByMaterialIndex: function () { + sortFacesByMaterialIndex() { const faces = this.faces; const length = faces.length; @@ -909,9 +911,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1; if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2; - }, + } - toJSON: function () { + toJSON() { const data = { metadata: { @@ -1102,9 +1104,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return data; - }, + } - clone: function () { + clone() { /* // Handle primitives @@ -1132,9 +1134,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return new Geometry().copy( this ); - }, + } - copy: function ( source ) { + copy( source ) { // reset @@ -1364,9 +1366,9 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, + } - toBufferGeometry: function () { + toBufferGeometry() { const geometry = new DirectGeometry().fromGeometry( this ); @@ -1461,78 +1463,78 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return buffergeometry; - }, + } - computeTangents: function () { + computeTangents() { console.error( 'THREE.Geometry: .computeTangents() has been removed.' ); - }, + } - computeLineDistances: function () { + computeLineDistances() { console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' ); - }, + } - applyMatrix: function ( matrix ) { + applyMatrix( matrix ) { console.warn( 'THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().' ); return this.applyMatrix4( matrix ); - }, + } - dispose: function () { + dispose() { this.dispatchEvent( { type: 'dispose' } ); } -} ); + createBufferGeometryFromObject( object ) { -Geometry.createBufferGeometryFromObject = function ( object ) { + let buffergeometry = new BufferGeometry(); - let buffergeometry = new BufferGeometry(); + const geometry = object.geometry; - const geometry = object.geometry; + if ( object.isPoints || object.isLine ) { - if ( object.isPoints || object.isLine ) { + const positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 ); + const colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 ); - const positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 ); - const colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 ); + buffergeometry.setAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) ); + buffergeometry.setAttribute( 'color', colors.copyColorsArray( geometry.colors ) ); - buffergeometry.setAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) ); - buffergeometry.setAttribute( 'color', colors.copyColorsArray( geometry.colors ) ); + if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) { - if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) { + const lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 ); - const lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 ); + buffergeometry.setAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) ); - buffergeometry.setAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) ); + } - } + if ( geometry.boundingSphere !== null ) { - if ( geometry.boundingSphere !== null ) { + buffergeometry.boundingSphere = geometry.boundingSphere.clone(); - buffergeometry.boundingSphere = geometry.boundingSphere.clone(); + } - } + if ( geometry.boundingBox !== null ) { - if ( geometry.boundingBox !== null ) { + buffergeometry.boundingBox = geometry.boundingBox.clone(); - buffergeometry.boundingBox = geometry.boundingBox.clone(); + } - } + } else if ( object.isMesh ) { + + buffergeometry = geometry.toBufferGeometry(); - } else if ( object.isMesh ) { + } - buffergeometry = geometry.toBufferGeometry(); + return buffergeometry; } - return buffergeometry; - -}; +} class DirectGeometry { diff --git a/examples/jsm/lines/LineGeometry.js b/examples/jsm/lines/LineGeometry.js index c80f9589e0b3c9..4e88eeda8f409f 100644 --- a/examples/jsm/lines/LineGeometry.js +++ b/examples/jsm/lines/LineGeometry.js @@ -1,20 +1,18 @@ import { LineSegmentsGeometry } from '../lines/LineSegmentsGeometry.js'; -var LineGeometry = function () { +class LineGeometry extends LineSegmentsGeometry { - LineSegmentsGeometry.call( this ); + constructor() { - this.type = 'LineGeometry'; + super(); -}; + Object.defineProperty( this, 'isLineGeometry', { value: true } ); -LineGeometry.prototype = Object.assign( Object.create( LineSegmentsGeometry.prototype ), { + this.type = 'LineGeometry'; - constructor: LineGeometry, - - isLineGeometry: true, + } - setPositions: function ( array ) { + setPositions( array ) { // converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format @@ -37,9 +35,9 @@ LineGeometry.prototype = Object.assign( Object.create( LineSegmentsGeometry.prot return this; - }, + } - setColors: function ( array ) { + setColors( array ) { // converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format @@ -62,9 +60,9 @@ LineGeometry.prototype = Object.assign( Object.create( LineSegmentsGeometry.prot return this; - }, + } - fromLine: function ( line ) { + fromLine( line ) { var geometry = line.geometry; @@ -83,9 +81,9 @@ LineGeometry.prototype = Object.assign( Object.create( LineSegmentsGeometry.prot return this; - }, + } - copy: function ( /* source */ ) { + copy( /* source */ ) { // todo @@ -93,6 +91,6 @@ LineGeometry.prototype = Object.assign( Object.create( LineSegmentsGeometry.prot } -} ); +} export { LineGeometry }; diff --git a/examples/jsm/lines/LineSegmentsGeometry.js b/examples/jsm/lines/LineSegmentsGeometry.js index b30831b658f234..277f23d229377b 100644 --- a/examples/jsm/lines/LineSegmentsGeometry.js +++ b/examples/jsm/lines/LineSegmentsGeometry.js @@ -9,29 +9,30 @@ import { WireframeGeometry } from '../../../build/three.module.js'; -var LineSegmentsGeometry = function () { +const box = new Box3(); +const vector = new Vector3(); - InstancedBufferGeometry.call( this ); +class LineSegmentsGeometry extends InstancedBufferGeometry { - this.type = 'LineSegmentsGeometry'; + constructor() { - var positions = [ - 1, 2, 0, 1, 2, 0, - 1, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 0, - 1, - 1, 0, 1, - 1, 0 ]; - var uvs = [ - 1, 2, 1, 2, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 2, 1, - 2 ]; - var index = [ 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5 ]; + super(); - this.setIndex( index ); - this.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) ); - this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + Object.defineProperty( this, 'isLineSegmentsGeometry', { value: true } ); -}; + this.type = 'LineSegmentsGeometry'; -LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGeometry.prototype ), { + var positions = [ - 1, 2, 0, 1, 2, 0, - 1, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 0, - 1, - 1, 0, 1, - 1, 0 ]; + var uvs = [ - 1, 2, 1, 2, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 2, 1, - 2 ]; + var index = [ 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5 ]; - constructor: LineSegmentsGeometry, + this.setIndex( index ); + this.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); - isLineSegmentsGeometry: true, + } - applyMatrix4: function ( matrix ) { + applyMatrix4( matrix ) { var start = this.attributes.instanceStart; var end = this.attributes.instanceEnd; @@ -60,9 +61,9 @@ LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGe return this; - }, + } - setPositions: function ( array ) { + setPositions( array ) { var lineSegments; @@ -88,9 +89,9 @@ LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGe return this; - }, + } - setColors: function ( array ) { + setColors( array ) { var colors; @@ -111,25 +112,25 @@ LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGe return this; - }, + } - fromWireframeGeometry: function ( geometry ) { + fromWireframeGeometry( geometry ) { this.setPositions( geometry.attributes.position.array ); return this; - }, + } - fromEdgesGeometry: function ( geometry ) { + fromEdgesGeometry( geometry ) { this.setPositions( geometry.attributes.position.array ); return this; - }, + } - fromMesh: function ( mesh ) { + fromMesh( mesh ) { this.fromWireframeGeometry( new WireframeGeometry( mesh.geometry ) ); @@ -137,9 +138,9 @@ LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGe return this; - }, + } - fromLineSegments: function ( lineSegments ) { + fromLineSegments( lineSegments ) { var geometry = lineSegments.geometry; @@ -158,97 +159,85 @@ LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGe return this; - }, - - computeBoundingBox: function () { - - var box = new Box3(); - - return function computeBoundingBox() { - - if ( this.boundingBox === null ) { - - this.boundingBox = new Box3(); - - } + } - var start = this.attributes.instanceStart; - var end = this.attributes.instanceEnd; + computeBoundingBox() { - if ( start !== undefined && end !== undefined ) { + if ( this.boundingBox === null ) { - this.boundingBox.setFromBufferAttribute( start ); + this.boundingBox = new Box3(); - box.setFromBufferAttribute( end ); + } - this.boundingBox.union( box ); + var start = this.attributes.instanceStart; + var end = this.attributes.instanceEnd; - } + if ( start !== undefined && end !== undefined ) { - }; + this.boundingBox.setFromBufferAttribute( start ); - }(), + box.setFromBufferAttribute( end ); - computeBoundingSphere: function () { + this.boundingBox.union( box ); - var vector = new Vector3(); + } - return function computeBoundingSphere() { + } - if ( this.boundingSphere === null ) { + computeBoundingSphere() { - this.boundingSphere = new Sphere(); + if ( this.boundingSphere === null ) { - } + this.boundingSphere = new Sphere(); - if ( this.boundingBox === null ) { + } - this.computeBoundingBox(); + if ( this.boundingBox === null ) { - } + this.computeBoundingBox(); - var start = this.attributes.instanceStart; - var end = this.attributes.instanceEnd; + } - if ( start !== undefined && end !== undefined ) { + var start = this.attributes.instanceStart; + var end = this.attributes.instanceEnd; - var center = this.boundingSphere.center; + if ( start !== undefined && end !== undefined ) { - this.boundingBox.getCenter( center ); + var center = this.boundingSphere.center; - var maxRadiusSq = 0; + this.boundingBox.getCenter( center ); - for ( var i = 0, il = start.count; i < il; i ++ ) { + var maxRadiusSq = 0; - vector.fromBufferAttribute( start, i ); - maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) ); + for ( var i = 0, il = start.count; i < il; i ++ ) { - vector.fromBufferAttribute( end, i ); - maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) ); + vector.fromBufferAttribute( start, i ); + maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) ); - } + vector.fromBufferAttribute( end, i ); + maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) ); - this.boundingSphere.radius = Math.sqrt( maxRadiusSq ); + } - if ( isNaN( this.boundingSphere.radius ) ) { + this.boundingSphere.radius = Math.sqrt( maxRadiusSq ); - console.error( 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.', this ); + if ( isNaN( this.boundingSphere.radius ) ) { - } + console.error( 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.', this ); } - }; + } - }(), + } - toJSON: function () { + toJSON() { // todo - }, + } - applyMatrix: function ( matrix ) { + applyMatrix( matrix ) { console.warn( 'THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4().' ); @@ -256,6 +245,6 @@ LineSegmentsGeometry.prototype = Object.assign( Object.create( InstancedBufferGe } -} ); +} export { LineSegmentsGeometry }; diff --git a/examples/jsm/lines/WireframeGeometry2.js b/examples/jsm/lines/WireframeGeometry2.js index 4b63a4a06a35dd..a7edb44fd080cc 100644 --- a/examples/jsm/lines/WireframeGeometry2.js +++ b/examples/jsm/lines/WireframeGeometry2.js @@ -3,24 +3,22 @@ import { } from '../../../build/three.module.js'; import { LineSegmentsGeometry } from '../lines/LineSegmentsGeometry.js'; -var WireframeGeometry2 = function ( geometry ) { +class WireframeGeometry2 extends LineSegmentsGeometry { - LineSegmentsGeometry.call( this ); + constructor( geometry ) { - this.type = 'WireframeGeometry2'; + super(); - this.fromWireframeGeometry( new WireframeGeometry( geometry ) ); + Object.defineProperty( this, 'isWireframeGeometry2', { value: true } ); - // set colors, maybe + this.type = 'WireframeGeometry2'; -}; + this.fromWireframeGeometry( new WireframeGeometry( geometry ) ); -WireframeGeometry2.prototype = Object.assign( Object.create( LineSegmentsGeometry.prototype ), { + // set colors, maybe - constructor: WireframeGeometry2, + } - isWireframeGeometry2: true - -} ); +} export { WireframeGeometry2 }; diff --git a/src/core/BufferAttribute.js b/src/core/BufferAttribute.js index 3e0b5153fe95e4..9fcdb3d5e56c78 100644 --- a/src/core/BufferAttribute.js +++ b/src/core/BufferAttribute.js @@ -7,53 +7,49 @@ import { StaticDrawUsage } from '../constants.js'; const _vector = new Vector3(); const _vector2 = new Vector2(); -function BufferAttribute( array, itemSize, normalized ) { +class BufferAttribute { - if ( Array.isArray( array ) ) { + constructor( array, itemSize, normalized ) { - throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' ); + if ( Array.isArray( array ) ) { - } - - this.name = ''; + throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' ); - this.array = array; - this.itemSize = itemSize; - this.count = array !== undefined ? array.length / itemSize : 0; - this.normalized = normalized === true; + } - this.usage = StaticDrawUsage; - this.updateRange = { offset: 0, count: - 1 }; + Object.defineProperty( this, 'isBufferAttribute', { value: true } ); - this.version = 0; + this.name = ''; -} + this.array = array; + this.itemSize = itemSize; + this.count = array !== undefined ? array.length / itemSize : 0; + this.normalized = normalized === true; -Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', { + this.usage = StaticDrawUsage; + this.updateRange = { offset: 0, count: - 1 }; - set: function ( value ) { - - if ( value === true ) this.version ++; + this.version = 0; } -} ); + set needsUpdate( value ) { -Object.assign( BufferAttribute.prototype, { + if ( value === true ) this.version ++; - isBufferAttribute: true, + } - onUploadCallback: function () {}, + onUploadCallback() {} - setUsage: function ( value ) { + setUsage( value ) { this.usage = value; return this; - }, + } - copy: function ( source ) { + copy( source ) { this.name = source.name; this.array = new source.array.constructor( source.array ); @@ -65,9 +61,9 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - copyAt: function ( index1, attribute, index2 ) { + copyAt( index1, attribute, index2 ) { index1 *= this.itemSize; index2 *= attribute.itemSize; @@ -80,17 +76,17 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - copyArray: function ( array ) { + copyArray( array ) { this.array.set( array ); return this; - }, + } - copyColorsArray: function ( colors ) { + copyColorsArray( colors ) { const array = this.array; let offset = 0; @@ -114,9 +110,9 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - copyVector2sArray: function ( vectors ) { + copyVector2sArray( vectors ) { const array = this.array; let offset = 0; @@ -139,9 +135,9 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - copyVector3sArray: function ( vectors ) { + copyVector3sArray( vectors ) { const array = this.array; let offset = 0; @@ -165,9 +161,9 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - copyVector4sArray: function ( vectors ) { + copyVector4sArray( vectors ) { const array = this.array; let offset = 0; @@ -192,9 +188,9 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - applyMatrix3: function ( m ) { + applyMatrix3( m ) { if ( this.itemSize === 2 ) { @@ -222,9 +218,9 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - applyMatrix4: function ( m ) { + applyMatrix4( m ) { for ( let i = 0, l = this.count; i < l; i ++ ) { @@ -240,9 +236,9 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - applyNormalMatrix: function ( m ) { + applyNormalMatrix( m ) { for ( let i = 0, l = this.count; i < l; i ++ ) { @@ -258,9 +254,9 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - transformDirection: function ( m ) { + transformDirection( m ) { for ( let i = 0, l = this.count; i < l; i ++ ) { @@ -276,73 +272,75 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - set: function ( value, offset = 0 ) { + set( value, offset = 0 ) { + + if ( offset === undefined ) offset = 0; this.array.set( value, offset ); return this; - }, + } - getX: function ( index ) { + getX( index ) { return this.array[ index * this.itemSize ]; - }, + } - setX: function ( index, x ) { + setX( index, x ) { this.array[ index * this.itemSize ] = x; return this; - }, + } - getY: function ( index ) { + getY( index ) { return this.array[ index * this.itemSize + 1 ]; - }, + } - setY: function ( index, y ) { + setY( index, y ) { this.array[ index * this.itemSize + 1 ] = y; return this; - }, + } - getZ: function ( index ) { + getZ( index ) { return this.array[ index * this.itemSize + 2 ]; - }, + } - setZ: function ( index, z ) { + setZ( index, z ) { this.array[ index * this.itemSize + 2 ] = z; return this; - }, + } - getW: function ( index ) { + getW( index ) { return this.array[ index * this.itemSize + 3 ]; - }, + } - setW: function ( index, w ) { + setW( index, w ) { this.array[ index * this.itemSize + 3 ] = w; return this; - }, + } - setXY: function ( index, x, y ) { + setXY( index, x, y ) { index *= this.itemSize; @@ -351,9 +349,9 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - setXYZ: function ( index, x, y, z ) { + setXYZ( index, x, y, z ) { index *= this.itemSize; @@ -363,9 +361,9 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - setXYZW: function ( index, x, y, z, w ) { + setXYZW( index, x, y, z, w ) { index *= this.itemSize; @@ -376,23 +374,23 @@ Object.assign( BufferAttribute.prototype, { return this; - }, + } - onUpload: function ( callback ) { + onUpload( callback ) { this.onUploadCallback = callback; return this; - }, + } - clone: function () { + clone() { return new this.constructor( this.array, this.itemSize ).copy( this ); - }, + } - toJSON: function () { + toJSON() { return { itemSize: this.itemSize, @@ -403,108 +401,112 @@ Object.assign( BufferAttribute.prototype, { } -} ); +} // -function Int8BufferAttribute( array, itemSize, normalized ) { +class Int8BufferAttribute extends BufferAttribute { - BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized ); + constructor( array, itemSize, normalized ) { + + super( new Int8Array( array ), itemSize, normalized ); + + } } -Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); -Int8BufferAttribute.prototype.constructor = Int8BufferAttribute; +class Uint8BufferAttribute extends BufferAttribute { + constructor( array, itemSize, normalized ) { -function Uint8BufferAttribute( array, itemSize, normalized ) { + super( new Uint8Array( array ), itemSize, normalized ); - BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized ); + } } -Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); -Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute; +class Uint8ClampedBufferAttribute extends BufferAttribute { + constructor( array, itemSize, normalized ) { -function Uint8ClampedBufferAttribute( array, itemSize, normalized ) { + super( new Uint8ClampedArray( array ), itemSize, normalized ); - BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized ); + } } -Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype ); -Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute; +class Int16BufferAttribute extends BufferAttribute { + constructor( array, itemSize, normalized ) { -function Int16BufferAttribute( array, itemSize, normalized ) { + super( new Int16Array( array ), itemSize, normalized ); - BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized ); + } } -Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); -Int16BufferAttribute.prototype.constructor = Int16BufferAttribute; +class Uint16BufferAttribute extends BufferAttribute { + constructor( array, itemSize, normalized ) { -function Uint16BufferAttribute( array, itemSize, normalized ) { + super( new Uint16Array( array ), itemSize, normalized ); - BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized ); + } } -Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); -Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute; +class Int32BufferAttribute extends BufferAttribute { + constructor( array, itemSize, normalized ) { -function Int32BufferAttribute( array, itemSize, normalized ) { + super( new Int32Array( array ), itemSize, normalized ); - BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized ); + } } -Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); -Int32BufferAttribute.prototype.constructor = Int32BufferAttribute; +class Uint32BufferAttribute extends BufferAttribute { + constructor( array, itemSize, normalized ) { -function Uint32BufferAttribute( array, itemSize, normalized ) { + super( new Uint32Array( array ), itemSize, normalized ); - BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized ); + } } -Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); -Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute; +class Float16BufferAttribute extends BufferAttribute { + + constructor( array, itemSize, normalized ) { -function Float16BufferAttribute( array, itemSize, normalized ) { + super( new Uint16Array( array ), itemSize, normalized ); - BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized ); + Object.defineProperty( this, 'isFloat16BufferAttribute', { value: true } ); + + } } -Float16BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); -Float16BufferAttribute.prototype.constructor = Float16BufferAttribute; -Float16BufferAttribute.prototype.isFloat16BufferAttribute = true; +class Float32BufferAttribute extends BufferAttribute { + + constructor( array, itemSize, normalized ) { -function Float32BufferAttribute( array, itemSize, normalized ) { + super( new Float32Array( array ), itemSize, normalized ); - BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized ); + } } -Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); -Float32BufferAttribute.prototype.constructor = Float32BufferAttribute; +class Float64BufferAttribute extends BufferAttribute { + constructor( array, itemSize, normalized ) { -function Float64BufferAttribute( array, itemSize, normalized ) { + super( new Float64Array( array ), itemSize, normalized ); - BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized ); + } } -Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); -Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; - // export { diff --git a/src/core/EventDispatcher.js b/src/core/EventDispatcher.js index 77988ca004e745..91c7907bdf7a31 100644 --- a/src/core/EventDispatcher.js +++ b/src/core/EventDispatcher.js @@ -2,11 +2,9 @@ * https://github.com/mrdoob/eventdispatcher.js/ */ -function EventDispatcher() {} +class EventDispatcher { -Object.assign( EventDispatcher.prototype, { - - addEventListener: function ( type, listener ) { + addEventListener( type, listener ) { if ( this._listeners === undefined ) this._listeners = {}; @@ -24,9 +22,9 @@ Object.assign( EventDispatcher.prototype, { } - }, + } - hasEventListener: function ( type, listener ) { + hasEventListener( type, listener ) { if ( this._listeners === undefined ) return false; @@ -34,9 +32,9 @@ Object.assign( EventDispatcher.prototype, { return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1; - }, + } - removeEventListener: function ( type, listener ) { + removeEventListener( type, listener ) { if ( this._listeners === undefined ) return; @@ -55,9 +53,9 @@ Object.assign( EventDispatcher.prototype, { } - }, + } - dispatchEvent: function ( event ) { + dispatchEvent( event ) { if ( this._listeners === undefined ) return; @@ -81,7 +79,6 @@ Object.assign( EventDispatcher.prototype, { } -} ); - +} export { EventDispatcher }; diff --git a/src/core/InstancedBufferAttribute.js b/src/core/InstancedBufferAttribute.js index d9a56c7eae69c1..0f33f1463d75db 100644 --- a/src/core/InstancedBufferAttribute.js +++ b/src/core/InstancedBufferAttribute.js @@ -1,30 +1,28 @@ import { BufferAttribute } from './BufferAttribute.js'; -function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) { +class InstancedBufferAttribute extends BufferAttribute { - if ( typeof ( normalized ) === 'number' ) { + constructor( array, itemSize, normalized, meshPerAttribute ) { - meshPerAttribute = normalized; + super( array, itemSize, normalized ); - normalized = false; + Object.defineProperty( this, 'isInstancedBufferAttribute', { value: true } ); - console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' ); + if ( typeof ( normalized ) === 'number' ) { - } - - BufferAttribute.call( this, array, itemSize, normalized ); + meshPerAttribute = normalized; - this.meshPerAttribute = meshPerAttribute || 1; + normalized = false; -} + console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' ); -InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), { + } - constructor: InstancedBufferAttribute, + this.meshPerAttribute = meshPerAttribute || 1; - isInstancedBufferAttribute: true, + } - copy: function ( source ) { + copy( source ) { BufferAttribute.prototype.copy.call( this, source ); @@ -32,9 +30,9 @@ InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribu return this; - }, + } - toJSON: function () { + toJSON() { const data = BufferAttribute.prototype.toJSON.call( this ); @@ -46,8 +44,6 @@ InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribu } -} ); - - +} export { InstancedBufferAttribute }; diff --git a/src/core/InstancedBufferGeometry.js b/src/core/InstancedBufferGeometry.js index b762e286df1d2d..9b4e8982a55662 100644 --- a/src/core/InstancedBufferGeometry.js +++ b/src/core/InstancedBufferGeometry.js @@ -1,21 +1,19 @@ import { BufferGeometry } from './BufferGeometry.js'; -function InstancedBufferGeometry() { +class InstancedBufferGeometry extends BufferGeometry { - BufferGeometry.call( this ); + constructor() { - this.type = 'InstancedBufferGeometry'; - this.instanceCount = Infinity; + super(); -} - -InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), { + Object.defineProperty( this, 'isInstancedBufferGeometry', { value: true } ); - constructor: InstancedBufferGeometry, + this.type = 'InstancedBufferGeometry'; + this.instanceCount = Infinity; - isInstancedBufferGeometry: true, + } - copy: function ( source ) { + copy( source ) { BufferGeometry.prototype.copy.call( this, source ); @@ -23,15 +21,15 @@ InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry return this; - }, + } - clone: function () { + clone() { return new this.constructor().copy( this ); - }, + } - toJSON: function () { + toJSON() { const data = BufferGeometry.prototype.toJSON.call( this ); @@ -43,6 +41,6 @@ InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry } -} ); +} export { InstancedBufferGeometry }; diff --git a/src/core/InstancedInterleavedBuffer.js b/src/core/InstancedInterleavedBuffer.js index caae9bd0c0046e..555760e89d2227 100644 --- a/src/core/InstancedInterleavedBuffer.js +++ b/src/core/InstancedInterleavedBuffer.js @@ -1,20 +1,18 @@ import { InterleavedBuffer } from './InterleavedBuffer.js'; -function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) { +class InstancedInterleavedBuffer extends InterleavedBuffer { - InterleavedBuffer.call( this, array, stride ); + constructor( array, stride, meshPerAttribute ) { - this.meshPerAttribute = meshPerAttribute || 1; + super( array, stride ); -} - -InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), { + Object.defineProperty( this, 'isInstancedInterleavedBuffer', { value: true } ); - constructor: InstancedInterleavedBuffer, + this.meshPerAttribute = meshPerAttribute || 1; - isInstancedInterleavedBuffer: true, + } - copy: function ( source ) { + copy( source ) { InterleavedBuffer.prototype.copy.call( this, source ); @@ -22,9 +20,9 @@ InstancedInterleavedBuffer.prototype = Object.assign( Object.create( Interleaved return this; - }, + } - clone: function ( data ) { + clone( data ) { const ib = InterleavedBuffer.prototype.clone.call( this, data ); @@ -32,9 +30,9 @@ InstancedInterleavedBuffer.prototype = Object.assign( Object.create( Interleaved return ib; - }, + } - toJSON: function ( data ) { + toJSON( data ) { const json = InterleavedBuffer.prototype.toJSON.call( this, data ); @@ -45,6 +43,6 @@ InstancedInterleavedBuffer.prototype = Object.assign( Object.create( Interleaved } -} ); +} export { InstancedInterleavedBuffer }; diff --git a/src/core/InterleavedBuffer.js b/src/core/InterleavedBuffer.js index e00fbec34285fe..6a0ec5839f494e 100644 --- a/src/core/InterleavedBuffer.js +++ b/src/core/InterleavedBuffer.js @@ -1,46 +1,42 @@ import { MathUtils } from '../math/MathUtils.js'; import { StaticDrawUsage } from '../constants.js'; -function InterleavedBuffer( array, stride ) { +class InterleavedBuffer { - this.array = array; - this.stride = stride; - this.count = array !== undefined ? array.length / stride : 0; + constructor( array, stride ) { - this.usage = StaticDrawUsage; - this.updateRange = { offset: 0, count: - 1 }; + this.array = array; + this.stride = stride; + this.count = array !== undefined ? array.length / stride : 0; - this.version = 0; + this.isInterleavedBuffer = true; - this.uuid = MathUtils.generateUUID(); + this.usage = StaticDrawUsage; + this.updateRange = { offset: 0, count: - 1 }; -} - -Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', { + this.version = 0; - set: function ( value ) { - - if ( value === true ) this.version ++; + this.uuid = MathUtils.generateUUID(); } -} ); + set needsUpdate( value ) { -Object.assign( InterleavedBuffer.prototype, { + if ( value === true ) this.version ++; - isInterleavedBuffer: true, + } - onUploadCallback: function () {}, + onUploadCallback() {} - setUsage: function ( value ) { + setUsage( value ) { this.usage = value; return this; - }, + } - copy: function ( source ) { + copy( source ) { this.array = new source.array.constructor( source.array ); this.count = source.count; @@ -49,9 +45,9 @@ Object.assign( InterleavedBuffer.prototype, { return this; - }, + } - copyAt: function ( index1, attribute, index2 ) { + copyAt( index1, attribute, index2 ) { index1 *= this.stride; index2 *= attribute.stride; @@ -64,17 +60,19 @@ Object.assign( InterleavedBuffer.prototype, { return this; - }, + } + + set( value, offset = 0 ) { - set: function ( value, offset = 0 ) { + if ( offset === undefined ) offset = 0; this.array.set( value, offset ); return this; - }, + } - clone: function ( data ) { + clone( data ) { if ( data.arrayBuffers === undefined ) { @@ -101,17 +99,17 @@ Object.assign( InterleavedBuffer.prototype, { return ib; - }, + } - onUpload: function ( callback ) { + onUpload( callback ) { this.onUploadCallback = callback; return this; - }, + } - toJSON: function ( data ) { + toJSON( data ) { if ( data.arrayBuffers === undefined ) { @@ -144,6 +142,6 @@ Object.assign( InterleavedBuffer.prototype, { } -} ); +} export { InterleavedBuffer }; diff --git a/src/core/InterleavedBufferAttribute.js b/src/core/InterleavedBufferAttribute.js index e4a956d3355571..c62cbfdaeade9e 100644 --- a/src/core/InterleavedBufferAttribute.js +++ b/src/core/InterleavedBufferAttribute.js @@ -3,57 +3,42 @@ import { BufferAttribute } from './BufferAttribute.js'; const _vector = new Vector3(); -function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) { +class InterleavedBufferAttribute { - this.name = ''; + constructor( interleavedBuffer, itemSize, offset, normalized ) { - this.data = interleavedBuffer; - this.itemSize = itemSize; - this.offset = offset; + Object.defineProperty( this, 'isInterleavedBufferAttribute', { value: true } ); - this.normalized = normalized === true; + this.name = ''; -} - -Object.defineProperties( InterleavedBufferAttribute.prototype, { - - count: { - - get: function () { + this.data = interleavedBuffer; + this.itemSize = itemSize; + this.offset = offset; - return this.data.count; + this.normalized = normalized === true; - } + } - }, + get count() { - array: { + return this.data.count; - get: function () { + } - return this.data.array; + get array() { - } + return this.data.array; - }, - - needsUpdate: { + } - set: function ( value ) { + set needsUpdate( value ) { - this.data.needsUpdate = value; - } + this.data.needsUpdate = value; } -} ); - -Object.assign( InterleavedBufferAttribute.prototype, { - - isInterleavedBufferAttribute: true, - - applyMatrix4: function ( m ) { + applyMatrix4( m ) { for ( let i = 0, l = this.data.count; i < l; i ++ ) { @@ -69,65 +54,65 @@ Object.assign( InterleavedBufferAttribute.prototype, { return this; - }, + } - setX: function ( index, x ) { + setX( index, x ) { this.data.array[ index * this.data.stride + this.offset ] = x; return this; - }, + } - setY: function ( index, y ) { + setY( index, y ) { this.data.array[ index * this.data.stride + this.offset + 1 ] = y; return this; - }, + } - setZ: function ( index, z ) { + setZ( index, z ) { this.data.array[ index * this.data.stride + this.offset + 2 ] = z; return this; - }, + } - setW: function ( index, w ) { + setW( index, w ) { this.data.array[ index * this.data.stride + this.offset + 3 ] = w; return this; - }, + } - getX: function ( index ) { + getX( index ) { return this.data.array[ index * this.data.stride + this.offset ]; - }, + } - getY: function ( index ) { + getY( index ) { return this.data.array[ index * this.data.stride + this.offset + 1 ]; - }, + } - getZ: function ( index ) { + getZ( index ) { return this.data.array[ index * this.data.stride + this.offset + 2 ]; - }, + } - getW: function ( index ) { + getW( index ) { return this.data.array[ index * this.data.stride + this.offset + 3 ]; - }, + } - setXY: function ( index, x, y ) { + setXY( index, x, y ) { index = index * this.data.stride + this.offset; @@ -136,9 +121,9 @@ Object.assign( InterleavedBufferAttribute.prototype, { return this; - }, + } - setXYZ: function ( index, x, y, z ) { + setXYZ( index, x, y, z ) { index = index * this.data.stride + this.offset; @@ -148,9 +133,9 @@ Object.assign( InterleavedBufferAttribute.prototype, { return this; - }, + } - setXYZW: function ( index, x, y, z, w ) { + setXYZW( index, x, y, z, w ) { index = index * this.data.stride + this.offset; @@ -161,9 +146,9 @@ Object.assign( InterleavedBufferAttribute.prototype, { return this; - }, + } - clone: function ( data ) { + clone( data ) { if ( data === undefined ) { @@ -203,9 +188,9 @@ Object.assign( InterleavedBufferAttribute.prototype, { } - }, + } - toJSON: function ( data ) { + toJSON( data ) { if ( data === undefined ) { @@ -262,7 +247,6 @@ Object.assign( InterleavedBufferAttribute.prototype, { } -} ); - +} export { InterleavedBufferAttribute }; diff --git a/src/core/Raycaster.js b/src/core/Raycaster.js index e39e58aa33b976..f64545851fb7d6 100644 --- a/src/core/Raycaster.js +++ b/src/core/Raycaster.js @@ -1,37 +1,6 @@ import { Ray } from '../math/Ray.js'; import { Layers } from './Layers.js'; -function Raycaster( origin, direction, near, far ) { - - this.ray = new Ray( origin, direction ); - // direction is assumed to be normalized (for accurate distance calculations) - - this.near = near || 0; - this.far = far || Infinity; - this.camera = null; - this.layers = new Layers(); - - this.params = { - Mesh: {}, - Line: { threshold: 1 }, - LOD: {}, - Points: { threshold: 1 }, - Sprite: {} - }; - - Object.defineProperties( this.params, { - PointCloud: { - get: function () { - - console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' ); - return this.Points; - - } - } - } ); - -} - function ascSort( a, b ) { return a.distance - b.distance; @@ -60,17 +29,40 @@ function intersectObject( object, raycaster, intersects, recursive ) { } -Object.assign( Raycaster.prototype, { +class Raycaster { - set: function ( origin, direction ) { + constructor( origin, direction, near, far ) { + this.ray = new Ray( origin, direction ); // direction is assumed to be normalized (for accurate distance calculations) - this.ray.set( origin, direction ); + this.near = near || 0; + this.far = far || Infinity; + this.camera = null; + this.layers = new Layers(); - }, + this.params = { + Mesh: {}, + Line: { threshold: 1 }, + LOD: {}, + Points: { threshold: 1 }, + Sprite: {} + }; - setFromCamera: function ( coords, camera ) { + Object.defineProperties( this.params, { + PointCloud: { + get: function () { + + console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' ); + return this.Points; + + } + } + } ); + + } + + setFromCamera( coords, camera ) { if ( camera && camera.isPerspectiveCamera ) { @@ -90,9 +82,9 @@ Object.assign( Raycaster.prototype, { } - }, + } - intersectObject: function ( object, recursive, optionalTarget ) { + intersectObject( object, recursive, optionalTarget ) { const intersects = optionalTarget || []; @@ -102,9 +94,9 @@ Object.assign( Raycaster.prototype, { return intersects; - }, + } - intersectObjects: function ( objects, recursive, optionalTarget ) { + intersectObjects( objects, recursive, optionalTarget ) { const intersects = optionalTarget || []; @@ -127,7 +119,18 @@ Object.assign( Raycaster.prototype, { } -} ); +} + +Object.assign( Raycaster.prototype, { + set: function ( origin, direction ) { + + // direction is assumed to be normalized (for accurate distance calculations) + + this.ray.set( origin, direction ); + + } + +} ); export { Raycaster };