- console.error( 'THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
-
- }
-
- }
-
- }
-
-} );
-
-const _start$1 = new Vector3();
-const _end$1 = new Vector3();
-
-function LineSegments( geometry, material ) {
-
- Line.call( this, geometry, material );
-
- this.type = 'LineSegments';
-
-}
-
-LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
-
- constructor: LineSegments,
-
- isLineSegments: true,
-
- computeLineDistances: function () {
-
- const geometry = this.geometry;
-
- if ( geometry.isBufferGeometry ) {
-
- // we assume non-indexed geometry
-
- if ( geometry.index === null ) {
-
- const positionAttribute = geometry.attributes.position;
- const lineDistances = [];
-
- for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
-
- _start$1.fromBufferAttribute( positionAttribute, i );
- _end$1.fromBufferAttribute( positionAttribute, i + 1 );
-
- lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
- lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
-
- }
-
- geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
-
- } else {
-
- console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
-
- }
-
- } else if ( geometry.isGeometry ) {
-
- const vertices = geometry.vertices;
- const lineDistances = geometry.lineDistances;
-
- for ( let i = 0, l = vertices.length; i < l; i += 2 ) {
-
- _start$1.copy( vertices[ i ] );
- _end$1.copy( vertices[ i + 1 ] );
-
- lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
- lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
-
- }
-
- }
-
- return this;
-
- }
-
-} );
-
-function LineLoop( geometry, material ) {
-
- Line.call( this, geometry, material );
-
- this.type = 'LineLoop';
-
-}
-
-LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
-
- constructor: LineLoop,
-
- isLineLoop: true,
-
-} );
-
-/**
- * parameters = {
- * color: <hex>,
- * opacity: <float>,
- * map: new THREE.Texture( <Image> ),
- * alphaMap: new THREE.Texture( <Image> ),
- *
- * size: <float>,
- * sizeAttenuation: <bool>
- *
- * morphTargets: <bool>
- * }
- */
-
-function PointsMaterial( parameters ) {
-
- Material.call( this );
-
- this.type = 'PointsMaterial';
-
- this.color = new Color( 0xffffff );
-
- this.map = null;
-
- this.alphaMap = null;
-
- this.size = 1;
- this.sizeAttenuation = true;
-
- this.morphTargets = false;
-
- this.setValues( parameters );
-
-}
-
-PointsMaterial.prototype = Object.create( Material.prototype );
-PointsMaterial.prototype.constructor = PointsMaterial;
-
-PointsMaterial.prototype.isPointsMaterial = true;
-
-PointsMaterial.prototype.copy = function ( source ) {
-
- Material.prototype.copy.call( this, source );
-
- this.color.copy( source.color );
-
- this.map = source.map;
-
- this.alphaMap = source.alphaMap;
-
- this.size = source.size;
- this.sizeAttenuation = source.sizeAttenuation;
-
- this.morphTargets = source.morphTargets;
-
- return this;
-
-};
-
-const _inverseMatrix$2 = new Matrix4();
-const _ray$2 = new Ray();
-const _sphere$3 = new Sphere();
-const _position$1 = new Vector3();
-
-function Points( geometry, material ) {
-
- Object3D.call( this );
-
- this.type = 'Points';
-
- this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
- this.material = material !== undefined ? material : new PointsMaterial();
-
- this.updateMorphTargets();
-
-}
-
-Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
-
- constructor: Points,
-
- isPoints: true,
-
- copy: function ( source ) {
-
- Object3D.prototype.copy.call( this, source );
-
- this.material = source.material;
- this.geometry = source.geometry;
-
- return this;
-
- },
-
- raycast: function ( raycaster, intersects ) {
-
- const geometry = this.geometry;
- const matrixWorld = this.matrixWorld;
- const threshold = raycaster.params.Points.threshold;
-
- // Checking boundingSphere distance to ray
-
- if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
-
- _sphere$3.copy( geometry.boundingSphere );
- _sphere$3.applyMatrix4( matrixWorld );
- _sphere$3.radius += threshold;
-
- if ( raycaster.ray.intersectsSphere( _sphere$3 ) === false ) return;
-
- //
-
- _inverseMatrix$2.copy( matrixWorld ).invert();
- _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
-
- const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
- const localThresholdSq = localThreshold * localThreshold;
-
- if ( geometry.isBufferGeometry ) {
-
- const index = geometry.index;
- const attributes = geometry.attributes;
- const positionAttribute = attributes.position;
-
- if ( index !== null ) {
-
- const indices = index.array;
-
- for ( let i = 0, il = indices.length; i < il; i ++ ) {
-
- const a = indices[ i ];
-
- _position$1.fromBufferAttribute( positionAttribute, a );
-
- testPoint( _position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
-
- }
-
- } else {
-
- for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {
-
- _position$1.fromBufferAttribute( positionAttribute, i );
-
- testPoint( _position$1, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
-
- }
-
- }
-
- } else {
-
- const vertices = geometry.vertices;
-
- for ( let i = 0, l = vertices.length; i < l; i ++ ) {
-
- testPoint( vertices[ i ], i, localThresholdSq, matrixWorld, raycaster, intersects, this );
-
- }
-
- }
-
- },
-
- updateMorphTargets: function () {
-
- const geometry = this.geometry;
-
- if ( geometry.isBufferGeometry ) {
-
- const morphAttributes = geometry.morphAttributes;
- const keys = Object.keys( morphAttributes );
-
- if ( keys.length > 0 ) {
-
- const morphAttribute = morphAttributes[ keys[ 0 ] ];
-
- if ( morphAttribute !== undefined ) {
-
- this.morphTargetInfluences = [];
- this.morphTargetDictionary = {};
-
- for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
-
- const name = morphAttribute[ m ].name || String( m );
-
- this.morphTargetInfluences.push( 0 );
- this.morphTargetDictionary[ name ] = m;
-
- }
-
- }
-
- }
-
- } else {
-
- const morphTargets = geometry.morphTargets;
-
- if ( morphTargets !== undefined && morphTargets.length > 0 ) {
-
- console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
-
- }
-
- }
-
- }
-
-} );
-
-function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
-
- const rayPointDistanceSq = _ray$2.distanceSqToPoint( point );
-
- if ( rayPointDistanceSq < localThresholdSq ) {
-
- const intersectPoint = new Vector3();
-
- _ray$2.closestPointToPoint( point, intersectPoint );
- intersectPoint.applyMatrix4( matrixWorld );
-
- const distance = raycaster.ray.origin.distanceTo( intersectPoint );
-
- if ( distance < raycaster.near || distance > raycaster.far ) return;
-
- intersects.push( {
-
- distance: distance,
- distanceToRay: Math.sqrt( rayPointDistanceSq ),
- point: intersectPoint,
- index: index,
- face: null,
- object: object
-
- } );
-
- }
-
-}
-
-function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
-
- Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
-
- this.format = format !== undefined ? format : RGBFormat;
-
- this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
- this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
-
- this.generateMipmaps = false;
-
- const scope = this;
-
- function updateVideo() {
-
- scope.needsUpdate = true;
- video.requestVideoFrameCallback( updateVideo );
-
- }
-
- if ( 'requestVideoFrameCallback' in video ) {
-
- video.requestVideoFrameCallback( updateVideo );
-
- }
-
-}
-
-VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
-
- constructor: VideoTexture,
-
- clone: function () {
-
- return new this.constructor( this.image ).copy( this );
-
- },
-
- isVideoTexture: true,
-
- update: function () {
-
- const video = this.image;
- const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
-
- if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
-
- this.needsUpdate = true;
-
- }
-
- }
-
-} );
-
-function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
-
- Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
-
- this.image = { width: width, height: height };
- this.mipmaps = mipmaps;
-
- // no flipping for cube textures
- // (also flipping doesn't work for compressed textures )
-
- this.flipY = false;
-
- // can't generate mipmaps for compressed textures
- // mips must be embedded in DDS files
-
- this.generateMipmaps = false;
-
-}
-
-CompressedTexture.prototype = Object.create( Texture.prototype );
-CompressedTexture.prototype.constructor = CompressedTexture;
-
-CompressedTexture.prototype.isCompressedTexture = true;
-
-function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
-
- Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
-
- this.needsUpdate = true;
-
-}
-
-CanvasTexture.prototype = Object.create( Texture.prototype );
-CanvasTexture.prototype.constructor = CanvasTexture;
-CanvasTexture.prototype.isCanvasTexture = true;
-
-function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
-
- format = format !== undefined ? format : DepthFormat;
-
- if ( format !== DepthFormat && format !== DepthStencilFormat ) {
-
- throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
-
- }
-
- if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
- if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
-
- Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
-
- this.image = { width: width, height: height };
-
- this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
- this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
-
- this.flipY = false;
- this.generateMipmaps = false;
-
-}
-
-DepthTexture.prototype = Object.create( Texture.prototype );
-DepthTexture.prototype.constructor = DepthTexture;
-DepthTexture.prototype.isDepthTexture = true;
-
-let _geometryId = 0; // Geometry uses even numbers as Id
-const _m1$3 = new Matrix4();
-const _obj$1 = new Object3D();
-const _offset$1 = new Vector3();
-
-function Geometry() {
-
- Object.defineProperty( this, 'id', { value: _geometryId += 2 } );
-
- this.uuid = MathUtils.generateUUID();
-
- this.name = '';
- this.type = 'Geometry';
-
- this.vertices = [];
- this.colors = [];
- this.faces = [];
- this.faceVertexUvs = [[]];
-
- this.morphTargets = [];
- this.morphNormals = [];
-
- this.skinWeights = [];
- this.skinIndices = [];
-
- this.lineDistances = [];
-
- this.boundingBox = null;
- this.boundingSphere = null;
-
- // update flags
-
- this.elementsNeedUpdate = false;
- this.verticesNeedUpdate = false;
- this.uvsNeedUpdate = false;
- this.normalsNeedUpdate = false;
- this.colorsNeedUpdate = false;
- this.lineDistancesNeedUpdate = false;
- this.groupsNeedUpdate = false;
-
-}
-
-Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
-
- constructor: Geometry,
-
- isGeometry: true,
-
- applyMatrix4: function ( matrix ) {
-
- const normalMatrix = new Matrix3().getNormalMatrix( matrix );
-
- for ( let i = 0, il = this.vertices.length; i < il; i ++ ) {
-
- const vertex = this.vertices[ i ];
- vertex.applyMatrix4( matrix );
-
- }
-
- for ( let i = 0, il = this.faces.length; i < il; i ++ ) {
-
- const face = this.faces[ i ];
- face.normal.applyMatrix3( normalMatrix ).normalize();
-
- for ( let j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
-
- face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
-
- }
-
- }
-
- if ( this.boundingBox !== null ) {
-
- this.computeBoundingBox();
-
- }
-
- if ( this.boundingSphere !== null ) {
-
- this.computeBoundingSphere();
-
- }
-
- this.verticesNeedUpdate = true;
- this.normalsNeedUpdate = true;
-
- return this;
-
- },
-
- rotateX: function ( angle ) {
-
- // rotate geometry around world x-axis
-
- _m1$3.makeRotationX( angle );
-
- this.applyMatrix4( _m1$3 );
-
- return this;
-
- },
-
- rotateY: function ( angle ) {
-
- // rotate geometry around world y-axis
-
- _m1$3.makeRotationY( angle );
-
- this.applyMatrix4( _m1$3 );
-
- return this;
-
- },
-
- rotateZ: function ( angle ) {
-
- // rotate geometry around world z-axis
-
- _m1$3.makeRotationZ( angle );
-
- this.applyMatrix4( _m1$3 );
-
- return this;
-
- },
-
- translate: function ( x, y, z ) {
-
- // translate geometry
-
- _m1$3.makeTranslation( x, y, z );
-
- this.applyMatrix4( _m1$3 );
-
- return this;
-
- },
-
- scale: function ( x, y, z ) {
-
- // scale geometry
-
- _m1$3.makeScale( x, y, z );
-
- this.applyMatrix4( _m1$3 );
-
- return this;
-
- },
-
- lookAt: function ( vector ) {
-
- _obj$1.lookAt( vector );
-
- _obj$1.updateMatrix();
-
- this.applyMatrix4( _obj$1.matrix );
-
- return this;
-
- },
-
- fromBufferGeometry: function ( geometry ) {
-
- const scope = this;
-
- const index = geometry.index !== null ? geometry.index : undefined;
- const attributes = geometry.attributes;
-
- if ( attributes.position === undefined ) {
-
- console.error( 'THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.' );
- return this;
-
- }
-
- const position = attributes.position;
- const normal = attributes.normal;
- const color = attributes.color;
- const uv = attributes.uv;
- const uv2 = attributes.uv2;
-
- if ( uv2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
-
- for ( let i = 0; i < position.count; i ++ ) {
-
- scope.vertices.push( new Vector3().fromBufferAttribute( position, i ) );
-
- if ( color !== undefined ) {
-
- scope.colors.push( new Color().fromBufferAttribute( color, i ) );
-
- }
-
- }
-
- function addFace( a, b, c, materialIndex ) {
-
- const vertexColors = ( color === undefined ) ? [] : [
- scope.colors[ a ].clone(),
- scope.colors[ b ].clone(),
- scope.colors[ c ].clone()
- ];
-
- const vertexNormals = ( normal === undefined ) ? [] : [
- new Vector3().fromBufferAttribute( normal, a ),
- new Vector3().fromBufferAttribute( normal, b ),
- new Vector3().fromBufferAttribute( normal, c )
- ];
-
- const face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
-
- scope.faces.push( face );
-
- if ( uv !== undefined ) {
-
- scope.faceVertexUvs[ 0 ].push( [
- new Vector2().fromBufferAttribute( uv, a ),
- new Vector2().fromBufferAttribute( uv, b ),
- new Vector2().fromBufferAttribute( uv, c )
- ] );
-
- }
-
- if ( uv2 !== undefined ) {
-
- scope.faceVertexUvs[ 1 ].push( [
- new Vector2().fromBufferAttribute( uv2, a ),
- new Vector2().fromBufferAttribute( uv2, b ),
- new Vector2().fromBufferAttribute( uv2, c )
- ] );
-
- }
-
- }
-
- const groups = geometry.groups;
-
- if ( groups.length > 0 ) {
-
- for ( let i = 0; i < groups.length; i ++ ) {
-
- const group = groups[ i ];
-
- const start = group.start;
- const count = group.count;
-
- for ( let j = start, jl = start + count; j < jl; j += 3 ) {
-
- if ( index !== undefined ) {
-
- addFace( index.getX( j ), index.getX( j + 1 ), index.getX( j + 2 ), group.materialIndex );
-
- } else {
-
- addFace( j, j + 1, j + 2, group.materialIndex );
-
- }
-
- }
-
- }
-
- } else {
-
- if ( index !== undefined ) {
-
- for ( let i = 0; i < index.count; i += 3 ) {
-
- addFace( index.getX( i ), index.getX( i + 1 ), index.getX( i + 2 ) );
-
- }
-
- } else {
-
- for ( let i = 0; i < position.count; i += 3 ) {
-
- addFace( i, i + 1, i + 2 );
-
- }
-
- }
-
- }
-
- this.computeFaceNormals();
-
- if ( geometry.boundingBox !== null ) {
-
- this.boundingBox = geometry.boundingBox.clone();
-
- }
-
- if ( geometry.boundingSphere !== null ) {
-
- this.boundingSphere = geometry.boundingSphere.clone();
-
- }
-
- return this;
-
- },
-
- center: function () {
-
- this.computeBoundingBox();
-
- this.boundingBox.getCenter( _offset$1 ).negate();
-
- this.translate( _offset$1.x, _offset$1.y, _offset$1.z );
-
- return this;
-
- },
-
- normalize: function () {
-
- this.computeBoundingSphere();
-
- const center = this.boundingSphere.center;
- const radius = this.boundingSphere.radius;
-
- const s = radius === 0 ? 1 : 1.0 / radius;
-
- const matrix = new Matrix4();
- matrix.set(
- s, 0, 0, - s * center.x,
- 0, s, 0, - s * center.y,
- 0, 0, s, - s * center.z,
- 0, 0, 0, 1
- );
-
- this.applyMatrix4( matrix );
-
- return this;
-
- },
-
- computeFaceNormals: function () {
-
- const cb = new Vector3(), ab = new Vector3();
-
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
-
- const face = this.faces[ f ];
-
- const vA = this.vertices[ face.a ];
- const vB = this.vertices[ face.b ];
- const vC = this.vertices[ face.c ];
-
- cb.subVectors( vC, vB );
- ab.subVectors( vA, vB );
- cb.cross( ab );
-
- cb.normalize();
-
- face.normal.copy( cb );
-
- }
-
- },
-
- computeVertexNormals: function ( areaWeighted = true ) {
-
- const vertices = new Array( this.vertices.length );
-
- for ( let v = 0, vl = this.vertices.length; v < vl; v ++ ) {
-
- vertices[ v ] = new Vector3();
-
- }
-
- if ( areaWeighted ) {
-
- // vertex normals weighted by triangle areas
- // http://www.iquilezles.org/www/articles/normals/normals.htm
-
- const cb = new Vector3(), ab = new Vector3();
-
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
-
- const face = this.faces[ f ];
-
- const vA = this.vertices[ face.a ];
- const vB = this.vertices[ face.b ];
- const vC = this.vertices[ face.c ];
-
- cb.subVectors( vC, vB );
- ab.subVectors( vA, vB );
- cb.cross( ab );
-
- vertices[ face.a ].add( cb );
- vertices[ face.b ].add( cb );
- vertices[ face.c ].add( cb );
-
- }
-
- } else {
-
- this.computeFaceNormals();
-
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
-
- const face = this.faces[ f ];
-
- vertices[ face.a ].add( face.normal );
- vertices[ face.b ].add( face.normal );
- vertices[ face.c ].add( face.normal );
-
- }
-
- }
-
- for ( let v = 0, vl = this.vertices.length; v < vl; v ++ ) {
-
- vertices[ v ].normalize();
-
- }
-
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
-
- const face = this.faces[ f ];
-
- const vertexNormals = face.vertexNormals;
-
- if ( vertexNormals.length === 3 ) {
-
- vertexNormals[ 0 ].copy( vertices[ face.a ] );
- vertexNormals[ 1 ].copy( vertices[ face.b ] );
- vertexNormals[ 2 ].copy( vertices[ face.c ] );
-
- } else {
-
- vertexNormals[ 0 ] = vertices[ face.a ].clone();
- vertexNormals[ 1 ] = vertices[ face.b ].clone();
- vertexNormals[ 2 ] = vertices[ face.c ].clone();
-
- }
-
- }
-
- if ( this.faces.length > 0 ) {
-
- this.normalsNeedUpdate = true;
-
- }
-
- },
-
- computeFlatVertexNormals: function () {
-
- this.computeFaceNormals();
-
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
-
- const face = this.faces[ f ];
-
- const vertexNormals = face.vertexNormals;
-
- if ( vertexNormals.length === 3 ) {
-
- vertexNormals[ 0 ].copy( face.normal );
- vertexNormals[ 1 ].copy( face.normal );
- vertexNormals[ 2 ].copy( face.normal );
-
- } else {
-
- vertexNormals[ 0 ] = face.normal.clone();
- vertexNormals[ 1 ] = face.normal.clone();
- vertexNormals[ 2 ] = face.normal.clone();
-
- }
-
- }
-
- if ( this.faces.length > 0 ) {
-
- this.normalsNeedUpdate = true;
-
- }
-
- },
-
- computeMorphNormals: function () {
-
- // save original normals
- // - create temp variables on first access
- // otherwise just copy (for faster repeated calls)
-
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
-
- const face = this.faces[ f ];
-
- if ( ! face.__originalFaceNormal ) {
-
- face.__originalFaceNormal = face.normal.clone();
-
- } else {
-
- face.__originalFaceNormal.copy( face.normal );
-
- }
-
- if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
-
- for ( let i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
-
- if ( ! face.__originalVertexNormals[ i ] ) {
-
- face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
-
- } else {
-
- face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
-
- }
-
- }
-
- }
-
- // use temp geometry to compute face and vertex normals for each morph
-
- const tmpGeo = new Geometry();
- tmpGeo.faces = this.faces;
-
- for ( let i = 0, il = this.morphTargets.length; i < il; i ++ ) {
-
- // create on first access
-
- if ( ! this.morphNormals[ i ] ) {
-
- this.morphNormals[ i ] = {};
- this.morphNormals[ i ].faceNormals = [];
- this.morphNormals[ i ].vertexNormals = [];
-
- const dstNormalsFace = this.morphNormals[ i ].faceNormals;
- const dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
-
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
-
- const faceNormal = new Vector3();
- const vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
-
- dstNormalsFace.push( faceNormal );
- dstNormalsVertex.push( vertexNormals );
-
- }
-
- }
-
- const morphNormals = this.morphNormals[ i ];
-
- // set vertices to morph target
-
- tmpGeo.vertices = this.morphTargets[ i ].vertices;
-
- // compute morph normals
-
- tmpGeo.computeFaceNormals();
- tmpGeo.computeVertexNormals();
-
- // store morph normals
-
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
-
- const face = this.faces[ f ];
-
- const faceNormal = morphNormals.faceNormals[ f ];
- const vertexNormals = morphNormals.vertexNormals[ f ];
-
- faceNormal.copy( face.normal );
-
- vertexNormals.a.copy( face.vertexNormals[ 0 ] );
- vertexNormals.b.copy( face.vertexNormals[ 1 ] );
- vertexNormals.c.copy( face.vertexNormals[ 2 ] );
-
- }
-
- }
-
- // restore original normals
-
- for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
-
- const face = this.faces[ f ];
-
- face.normal = face.__originalFaceNormal;
- face.vertexNormals = face.__originalVertexNormals;
-
- }
-
- },
-
- computeBoundingBox: function () {
-
- if ( this.boundingBox === null ) {
-
- this.boundingBox = new Box3();
-
- }
-
- this.boundingBox.setFromPoints( this.vertices );
-
- },
-
- computeBoundingSphere: function () {
-
- if ( this.boundingSphere === null ) {
-
- this.boundingSphere = new Sphere();
-
- }
-
- this.boundingSphere.setFromPoints( this.vertices );
-
- },
-
- merge: function ( geometry, matrix, materialIndexOffset = 0 ) {
-
- if ( ! ( geometry && geometry.isGeometry ) ) {
-
- console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
- return;
-
- }
-
- let normalMatrix;
- const vertexOffset = this.vertices.length,
- vertices1 = this.vertices,
- vertices2 = geometry.vertices,
- faces1 = this.faces,
- faces2 = geometry.faces,
- colors1 = this.colors,
- colors2 = geometry.colors;
-
- if ( matrix !== undefined ) {
-
- normalMatrix = new Matrix3().getNormalMatrix( matrix );
-
- }
-
- // vertices
-
- for ( let i = 0, il = vertices2.length; i < il; i ++ ) {
-
- const vertex = vertices2[ i ];
-
- const vertexCopy = vertex.clone();
-
- if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
-
- vertices1.push( vertexCopy );
-
- }
-
- // colors
-
- for ( let i = 0, il = colors2.length; i < il; i ++ ) {
-
- colors1.push( colors2[ i ].clone() );
-
- }
-
- // faces
-
- for ( let i = 0, il = faces2.length; i < il; i ++ ) {
-
- const face = faces2[ i ];
- let normal, color;
- const faceVertexNormals = face.vertexNormals,
- faceVertexColors = face.vertexColors;
-
- const faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
- faceCopy.normal.copy( face.normal );
-
- if ( normalMatrix !== undefined ) {
-
- faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
-
- }
-
- for ( let j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
-
- normal = faceVertexNormals[ j ].clone();
-
- if ( normalMatrix !== undefined ) {
-
- normal.applyMatrix3( normalMatrix ).normalize();
-
- }
-
- faceCopy.vertexNormals.push( normal );
-
- }
-
- faceCopy.color.copy( face.color );
-
- for ( let j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
-
- color = faceVertexColors[ j ];
- faceCopy.vertexColors.push( color.clone() );
-
- }
-
- faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
-
- faces1.push( faceCopy );
-
- }
-
- // uvs
-
- for ( let i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
-
- const faceVertexUvs2 = geometry.faceVertexUvs[ i ];
-
- if ( this.faceVertexUvs[ i ] === undefined ) this.faceVertexUvs[ i ] = [];
-
- for ( let j = 0, jl = faceVertexUvs2.length; j < jl; j ++ ) {
-
- const uvs2 = faceVertexUvs2[ j ], uvsCopy = [];
-
- for ( let k = 0, kl = uvs2.length; k < kl; k ++ ) {
-
- uvsCopy.push( uvs2[ k ].clone() );
-
- }
-
- this.faceVertexUvs[ i ].push( uvsCopy );
-
- }
-
- }
-
- },
-
- mergeMesh: function ( mesh ) {
-
- if ( ! ( mesh && mesh.isMesh ) ) {
-
- console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
- return;
-
- }
-
- if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
-
- this.merge( mesh.geometry, mesh.matrix );
-
- },
-
- /*
- * Checks for duplicate vertices with hashmap.
- * Duplicated vertices are removed
- * and faces' vertices are updated.
- */
-
- mergeVertices: function ( precisionPoints = 4 ) {
-
- const verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
- const unique = [], changes = [];
-
- const precision = Math.pow( 10, precisionPoints );
-
- for ( let i = 0, il = this.vertices.length; i < il; i ++ ) {
-
- const v = this.vertices[ i ];
- const key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
-
- if ( verticesMap[ key ] === undefined ) {
-
- verticesMap[ key ] = i;
- unique.push( this.vertices[ i ] );
- changes[ i ] = unique.length - 1;
-
- } else {
-
- //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
- changes[ i ] = changes[ verticesMap[ key ] ];
-
- }
-
- }
-
-
- // if faces are completely degenerate after merging vertices, we
- // have to remove them from the geometry.
- const faceIndicesToRemove = [];
-
- for ( let i = 0, il = this.faces.length; i < il; i ++ ) {
-
- const face = this.faces[ i ];
-
- face.a = changes[ face.a ];
- face.b = changes[ face.b ];
- face.c = changes[ face.c ];
-
- const indices = [ face.a, face.b, face.c ];
-
- // if any duplicate vertices are found in a Face3
- // we have to remove the face as nothing can be saved
- for ( let n = 0; n < 3; n ++ ) {
-
- if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
-
- faceIndicesToRemove.push( i );
- break;
-
- }
-
- }
-
- }
-
- for ( let i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
-
- const idx = faceIndicesToRemove[ i ];
-
- this.faces.splice( idx, 1 );
-
- for ( let j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
-
- this.faceVertexUvs[ j ].splice( idx, 1 );
-
- }
-
- }
-
- // Use unique set of vertices
-
- const diff = this.vertices.length - unique.length;
- this.vertices = unique;
- return diff;
-
- },
-
- setFromPoints: function ( points ) {
-
- this.vertices = [];
-
- for ( let i = 0, l = points.length; i < l; i ++ ) {
-
- const point = points[ i ];
- this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
-
- }
-
- return this;
-
- },
-
- sortFacesByMaterialIndex: function () {
-
- const faces = this.faces;
- const length = faces.length;
-
- // tag faces
-
- for ( let i = 0; i < length; i ++ ) {
-
- faces[ i ]._id = i;
-
- }
-
- // sort faces
-
- function materialIndexSort( a, b ) {
-
- return a.materialIndex - b.materialIndex;
-
- }
-
- faces.sort( materialIndexSort );
-
- // sort uvs
-
- const uvs1 = this.faceVertexUvs[ 0 ];
- const uvs2 = this.faceVertexUvs[ 1 ];
-
- let newUvs1, newUvs2;
-
- if ( uvs1 && uvs1.length === length ) newUvs1 = [];
- if ( uvs2 && uvs2.length === length ) newUvs2 = [];
-
- for ( let i = 0; i < length; i ++ ) {
-
- const id = faces[ i ]._id;
-
- if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
- if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
-
- }
-
- if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
- if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
-
- },
-
- toJSON: function () {
-
- const data = {
- metadata: {
- version: 4.5,
- type: 'Geometry',
- generator: 'Geometry.toJSON'
- }
- };
-
- // standard Geometry serialization
-
- data.uuid = this.uuid;
- data.type = this.type;
- if ( this.name !== '' ) data.name = this.name;
-
- if ( this.parameters !== undefined ) {
-
- const parameters = this.parameters;
-
- for ( const key in parameters ) {
-
- if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
-
- }
-
- return data;
-
- }
-
- const vertices = [];
-
- for ( let i = 0; i < this.vertices.length; i ++ ) {
-
- const vertex = this.vertices[ i ];
- vertices.push( vertex.x, vertex.y, vertex.z );
-
- }
-
- const faces = [];
- const normals = [];
- const normalsHash = {};
- const colors = [];
- const colorsHash = {};
- const uvs = [];
- const uvsHash = {};
-
- for ( let i = 0; i < this.faces.length; i ++ ) {
-
- const face = this.faces[ i ];
-
- const hasMaterial = true;
- const hasFaceUv = false; // deprecated
- const hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
- const hasFaceNormal = face.normal.length() > 0;
- const hasFaceVertexNormal = face.vertexNormals.length > 0;
- const hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
- const hasFaceVertexColor = face.vertexColors.length > 0;
-
- let faceType = 0;
-
- faceType = setBit( faceType, 0, 0 ); // isQuad
- faceType = setBit( faceType, 1, hasMaterial );
- faceType = setBit( faceType, 2, hasFaceUv );
- faceType = setBit( faceType, 3, hasFaceVertexUv );
- faceType = setBit( faceType, 4, hasFaceNormal );
- faceType = setBit( faceType, 5, hasFaceVertexNormal );
- faceType = setBit( faceType, 6, hasFaceColor );
- faceType = setBit( faceType, 7, hasFaceVertexColor );
-
- faces.push( faceType );
- faces.push( face.a, face.b, face.c );
- faces.push( face.materialIndex );
-
- if ( hasFaceVertexUv ) {
-
- const faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
-
- faces.push(
- getUvIndex( faceVertexUvs[ 0 ] ),
- getUvIndex( faceVertexUvs[ 1 ] ),
- getUvIndex( faceVertexUvs[ 2 ] )
- );
-
- }
-
- if ( hasFaceNormal ) {
-
- faces.push( getNormalIndex( face.normal ) );
-
- }
-
- if ( hasFaceVertexNormal ) {
-
- const vertexNormals = face.vertexNormals;
-
- faces.push(
- getNormalIndex( vertexNormals[ 0 ] ),
- getNormalIndex( vertexNormals[ 1 ] ),
- getNormalIndex( vertexNormals[ 2 ] )
- );
-
- }
-
- if ( hasFaceColor ) {
-
- faces.push( getColorIndex( face.color ) );
-
- }
-
- if ( hasFaceVertexColor ) {
-
- const vertexColors = face.vertexColors;
-
- faces.push(
- getColorIndex( vertexColors[ 0 ] ),
- getColorIndex( vertexColors[ 1 ] ),
- getColorIndex( vertexColors[ 2 ] )
- );