diff --git a/build/three.js b/build/three.js index 8504e73b16e22683abdc62b6afd383bf6e552ca8..b5187cea1bcecec9f1c577018f97cdd9723321c6 100644 --- a/build/three.js +++ b/build/three.js @@ -9675,6 +9675,22 @@ THREE.Geometry.prototype = { }, + center: function () { + + this.computeBoundingBox(); + + var offset = new THREE.Vector3(); + + offset.addVectors( this.boundingBox.min, this.boundingBox.max ); + offset.multiplyScalar( - 0.5 ); + + this.applyMatrix( new THREE.Matrix4().makeTranslation( offset.x, offset.y, offset.z ) ); + this.computeBoundingBox(); + + return offset; + + }, + computeFaceNormals: function () { var cb = new THREE.Vector3(), ab = new THREE.Vector3(); @@ -26683,13 +26699,10 @@ THREE.RenderableLine = function () { /** * @author mrdoob / http://mrdoob.com/ - * @author alteredq / http://alteredqualia.com/ */ THREE.GeometryUtils = { - // Merge two geometries or geometry and geometry from object (using object's transform) - merge: function ( geometry1, geometry2, materialIndexOffset ) { console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' ); @@ -26709,206 +26722,14 @@ THREE.GeometryUtils = { }, - // Get random point in triangle (via barycentric coordinates) - // (uniform distribution) - // http://www.cgafaq.info/wiki/Random_Point_In_Triangle - - randomPointInTriangle: function () { - - var vector = new THREE.Vector3(); - - return function ( vectorA, vectorB, vectorC ) { - - var point = new THREE.Vector3(); - - var a = THREE.Math.random16(); - var b = THREE.Math.random16(); - - if ( ( a + b ) > 1 ) { - - a = 1 - a; - b = 1 - b; - - } - - var c = 1 - a - b; - - point.copy( vectorA ); - point.multiplyScalar( a ); - - vector.copy( vectorB ); - vector.multiplyScalar( b ); - - point.add( vector ); - - vector.copy( vectorC ); - vector.multiplyScalar( c ); - - point.add( vector ); - - return point; - - }; - - }(), - - // Get random point in face (triangle) - // (uniform distribution) - - randomPointInFace: function ( face, geometry, useCachedAreas ) { - - var vA, vB, vC; - - vA = geometry.vertices[ face.a ]; - vB = geometry.vertices[ face.b ]; - vC = geometry.vertices[ face.c ]; - - return THREE.GeometryUtils.randomPointInTriangle( vA, vB, vC ); - - }, - - // Get uniformly distributed random points in mesh - // - create array with cumulative sums of face areas - // - pick random number from 0 to total area - // - find corresponding place in area array by binary search - // - get random point in face - - randomPointsInGeometry: function ( geometry, n ) { - - var face, i, - faces = geometry.faces, - vertices = geometry.vertices, - il = faces.length, - totalArea = 0, - cumulativeAreas = [], - vA, vB, vC, vD; - - // precompute face areas - - for ( i = 0; i < il; i ++ ) { - - face = faces[ i ]; - - vA = vertices[ face.a ]; - vB = vertices[ face.b ]; - vC = vertices[ face.c ]; - - face._area = THREE.GeometryUtils.triangleArea( vA, vB, vC ); - - totalArea += face._area; - - cumulativeAreas[ i ] = totalArea; - - } - - // binary search cumulative areas array - - function binarySearchIndices( value ) { - - function binarySearch( start, end ) { - - // return closest larger index - // if exact number is not found - - if ( end < start ) - return start; - - var mid = start + Math.floor( ( end - start ) / 2 ); - - if ( cumulativeAreas[ mid ] > value ) { - - return binarySearch( start, mid - 1 ); - - } else if ( cumulativeAreas[ mid ] < value ) { - - return binarySearch( mid + 1, end ); - - } else { - - return mid; - - } - - } - - var result = binarySearch( 0, cumulativeAreas.length - 1 ) - return result; - - } - - // pick random face weighted by face area - - var r, index, - result = []; - - var stats = {}; - - for ( i = 0; i < n; i ++ ) { - - r = THREE.Math.random16() * totalArea; - - index = binarySearchIndices( r ); - - result[ i ] = THREE.GeometryUtils.randomPointInFace( faces[ index ], geometry, true ); - - if ( ! stats[ index ] ) { - - stats[ index ] = 1; - - } else { - - stats[ index ] += 1; - - } - - } - - return result; - - }, - - // Get triangle area (half of parallelogram) - // http://mathworld.wolfram.com/TriangleArea.html - - triangleArea: function () { - - var vector1 = new THREE.Vector3(); - var vector2 = new THREE.Vector3(); - - return function ( vectorA, vectorB, vectorC ) { - - vector1.subVectors( vectorB, vectorA ); - vector2.subVectors( vectorC, vectorA ); - vector1.cross( vector2 ); - - return 0.5 * vector1.length(); - - }; - - }(), - - // Center geometry so that 0,0,0 is in center of bounding box - center: function ( geometry ) { - geometry.computeBoundingBox(); - - var bb = geometry.boundingBox; - - var offset = new THREE.Vector3(); - - offset.addVectors( bb.min, bb.max ); - offset.multiplyScalar( -0.5 ); - - geometry.applyMatrix( new THREE.Matrix4().makeTranslation( offset.x, offset.y, offset.z ) ); - geometry.computeBoundingBox(); - - return offset; + console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' ); + return geometry.center(); } }; - /** * @author alteredq / http://alteredqualia.com/ * @author mrdoob / http://mrdoob.com/ @@ -33586,7 +33407,6 @@ THREE.BoxHelper.prototype.update = function ( object ) { var min = geometry.boundingBox.min; var max = geometry.boundingBox.max; - /* 5____4 1/___0/| diff --git a/build/three.min.js b/build/three.min.js index 3c0bc2bc868aecd211ff0dd5e22dcd465b7c9f2c..a214e3b9d67e42e10bc16cd9e47ba53e502cb7fd 100644 --- a/build/three.min.js +++ b/build/three.min.js @@ -196,20 +196,20 @@ f)for(var h=this.attributes[f].array,k=this.attributes[f].itemSize,l=d[f],p=0;p< array:null},d=0,g=b.length;dd?-1:1,e.vertexTangents[c]=new THREE.Vector4(K.x,K.y,K.z,d);this.hasTangents=!0},computeLineDistances:function(){for(var a=0,b=this.vertices,c=0,d=b.length;cd;d++)if(e[d]==e[(d+1)%3]){a.push(f);break}for(f=a.length-1;0<=f;f--)for(e=a[f],this.faces.splice(e,1),c=0,g=this.faceVertexUvs.length;cc&&(h[f].counter+=1,g=h[f].hash+"_"+h[f].counter,g in this.geometryGroups||(this.geometryGroups[g]={faces3:[],materialIndex:f,vertices:0,numMorphTargets:k,numMorphNormals:l})),this.geometryGroups[g].faces3.push(d), -this.geometryGroups[g].vertices+=3;this.geometryGroupsList=[];for(var p in this.geometryGroups)this.geometryGroups[p].id=a++,this.geometryGroupsList.push(this.geometryGroups[p])}}(),clone:function(){for(var a=new THREE.Geometry,b=this.vertices,c=0,d=b.length;cd?-1:1,e.vertexTangents[c]=new THREE.Vector4(K.x,K.y,K.z,d);this.hasTangents=!0},computeLineDistances:function(){for(var a=0,b=this.vertices,c=0,d=b.length;cd;d++)if(e[d]==e[(d+1)%3]){a.push(f);break}for(f=a.length-1;0<=f;f--)for(e=a[f],this.faces.splice(e,1),c=0,g=this.faceVertexUvs.length;cc&&(h[f].counter+=1,g=h[f].hash+"_"+h[f].counter,g in this.geometryGroups||(this.geometryGroups[g]={faces3:[],materialIndex:f,vertices:0,numMorphTargets:k,numMorphNormals:l})),this.geometryGroups[g].faces3.push(d),this.geometryGroups[g].vertices+=3;this.geometryGroupsList=[];for(var p in this.geometryGroups)this.geometryGroups[p].id=a++,this.geometryGroupsList.push(this.geometryGroups[p])}}(),clone:function(){for(var a=new THREE.Geometry,b=this.vertices,c=0,d=b.length;ca?b(c,e-1):l[e]q-1?0:q-1,s=q+1>e-1?e-1:q+1,t=0>p-1?0:p-1,n=p+1>d-1?d-1:p+1,v=[],w=[0,0,h[4*(q*d+p)]/255*b];v.push([-1,0,h[4*(q*d+t)]/255*b]);v.push([-1,-1,h[4*(r*d+t)]/255*b]);v.push([0,-1,h[4*(r*d+p)]/255*b]);v.push([1,-1,h[4*(r*d+n)]/255*b]);v.push([1,0,h[4*(q*d+n)]/255*b]);v.push([1,1,h[4*(s*d+n)]/255*b]);v.push([0,1,h[4*(s*d+p)]/255* b]);v.push([-1,1,h[4*(s*d+t)]/255*b]);r=[];t=v.length;for(s=0;s