提交 13608078 编写于 作者: A alteredq

Moved computeBoundingSphere and computeBoundingBox from CTMLoader into BufferGeometry.

上级 c33d3454
......@@ -495,10 +495,12 @@ THREE.FontUtils.generateShapes=function(a,b){var b=b||{},c=b.curveSegments!==voi
C=void 0,z=void 0,v=void 0,H=void 0,w=m[t[p]].x,s=m[t[p]].y,x=m[t[r]].x,F=m[t[r]].y,C=m[t[n]].x,z=m[t[n]].y;if(1.0E-10>(x-w)*(z-s)-(F-s)*(C-w))m=false;else{for(u=0;u<q;u++)if(!(u==p||u==r||u==n)){var v=m[t[u]].x,H=m[t[u]].y,I=void 0,N=void 0,R=void 0,Y=void 0,B=void 0,G=void 0,Q=void 0,D=void 0,i=void 0,P=void 0,L=void 0,S=void 0,I=R=B=void 0,I=C-x,N=z-F,R=w-C,Y=s-z,B=x-w,G=F-s,Q=v-w,D=H-s,i=v-x,P=H-F,L=v-C,S=H-z,I=I*P-N*i,B=B*D-G*Q,R=R*S-Y*L;if(I>=0&&R>=0&&B>=0){m=false;break a}}m=true}}if(m){f.push([a[g[k]],
a[g[j]],a[g[l]]]);h.push([g[k],g[j],g[l]]);k=j;for(l=j+1;l<e;k++,l++)g[k]=g[l];e--;o=2*e}}return d?h:f};a.Triangulate.area=b;return a})(THREE.FontUtils);self._typeface_js={faces:THREE.FontUtils.faces,loadFace:THREE.FontUtils.loadFace};
THREE.BufferGeometry=function(){this.id=THREE.GeometryCount++;this.vertexColorArray=this.vertexUvArray=this.vertexNormalArray=this.vertexPositionArray=this.vertexIndexArray=this.vertexColorBuffer=this.vertexUvBuffer=this.vertexNormalBuffer=this.vertexPositionBuffer=this.vertexIndexBuffer=null;this.dynamic=false;this.boundingSphere=this.boundingBox=null;this.morphTargets=[]};
THREE.BufferGeometry.prototype={constructor:THREE.BufferGeometry,applyMatrix:function(a){if(this.vertexPositionArray!==void 0){a.multiplyVector3Array(this.vertexPositionArray);this.verticesNeedUpdate=true}if(this.vertexNormalArray!==void 0){var b=new THREE.Matrix4;b.extractRotation(a);b.multiplyVector3Array(this.vertexNormalArray);this.normalsNeedUpdate=true}},computeBoundingBox:function(){},computeBoundingSphere:function(){}};THREE.Curve=function(){};
THREE.Curve.prototype.getPoint=function(){console.log("Warning, getPoint() not implemented!");return null};THREE.Curve.prototype.getPointAt=function(a){return this.getPoint(this.getUtoTmapping(a))};THREE.Curve.prototype.getPoints=function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++)c.push(this.getPoint(b/a));return c};THREE.Curve.prototype.getSpacedPoints=function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++)c.push(this.getPointAt(b/a));return c};
THREE.Curve.prototype.getLength=function(){var a=this.getLengths();return a[a.length-1]};THREE.Curve.prototype.getLengths=function(a){a||(a=this.__arcLengthDivisions?this.__arcLengthDivisions:200);if(this.cacheArcLengths&&this.cacheArcLengths.length==a+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=false;var b=[],c,d=this.getPoint(0),e,f=0;b.push(0);for(e=1;e<=a;e++){c=this.getPoint(e/a);f=f+c.distanceTo(d);b.push(f);d=c}return this.cacheArcLengths=b};
THREE.Curve.prototype.updateArcLengths=function(){this.needsUpdate=true;this.getLengths()};THREE.Curve.prototype.getUtoTmapping=function(a,b){var c=this.getLengths(),d=0,e=c.length,f;f=b?b:a*c[e-1];for(var g=0,h=e-1,k;g<=h;){d=Math.floor(g+(h-g)/2);k=c[d]-f;if(k<0)g=d+1;else if(k>0)h=d-1;else{h=d;break}}d=h;if(c[d]==f)return d/(e-1);g=c[d];return c=(d+(f-g)/(c[d+1]-g))/(e-1)};THREE.Curve.prototype.getNormalVector=function(a){a=this.getTangent(a);return new THREE.Vector2(-a.y,a.x)};
THREE.BufferGeometry.prototype={constructor:THREE.BufferGeometry,applyMatrix:function(a){if(this.vertexPositionArray!==void 0){a.multiplyVector3Array(this.vertexPositionArray);this.verticesNeedUpdate=true}if(this.vertexNormalArray!==void 0){var b=new THREE.Matrix4;b.extractRotation(a);b.multiplyVector3Array(this.vertexNormalArray);this.normalsNeedUpdate=true}},computeBoundingBox:function(){if(!this.boundingBox)this.boundingBox={min:new THREE.Vector3(Infinity,Infinity,Infinity),max:new THREE.Vector3(-Infinity,
-Infinity,-Infinity)};var a=this.vertexPositionArray;if(a)for(var b=this.boundingBox,c,d,e,f=0,g=a.length;f<g;f=f+3){c=a[f];d=a[f+1];e=a[f+2];if(c<b.min.x)b.min.x=c;else if(c>b.max.x)b.max.x=c;if(d<b.min.y)b.min.y=d;else if(d>b.max.y)b.max.y=d;if(e<b.min.z)b.min.z=e;else if(e>b.max.z)b.max.z=e}if(a===void 0||a.length===0){this.boundingBox.min.set(0,0,0);this.boundingBox.max.set(0,0,0)}},computeBoundingSphere:function(){if(!this.boundingSphere)this.boundingSphere={radius:0};var a=this.vertexPositionArray;
if(a){for(var b,c=0,d,e,f=0,g=a.length;f<g;f=f+3){b=a[f];d=a[f+1];e=a[f+2];b=Math.sqrt(b*b+d*d+e*e);b>c&&(c=b)}this.boundingSphere.radius=c}}};THREE.Curve=function(){};THREE.Curve.prototype.getPoint=function(){console.log("Warning, getPoint() not implemented!");return null};THREE.Curve.prototype.getPointAt=function(a){return this.getPoint(this.getUtoTmapping(a))};THREE.Curve.prototype.getPoints=function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++)c.push(this.getPoint(b/a));return c};
THREE.Curve.prototype.getSpacedPoints=function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++)c.push(this.getPointAt(b/a));return c};THREE.Curve.prototype.getLength=function(){var a=this.getLengths();return a[a.length-1]};
THREE.Curve.prototype.getLengths=function(a){a||(a=this.__arcLengthDivisions?this.__arcLengthDivisions:200);if(this.cacheArcLengths&&this.cacheArcLengths.length==a+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=false;var b=[],c,d=this.getPoint(0),e,f=0;b.push(0);for(e=1;e<=a;e++){c=this.getPoint(e/a);f=f+c.distanceTo(d);b.push(f);d=c}return this.cacheArcLengths=b};THREE.Curve.prototype.updateArcLengths=function(){this.needsUpdate=true;this.getLengths()};
THREE.Curve.prototype.getUtoTmapping=function(a,b){var c=this.getLengths(),d=0,e=c.length,f;f=b?b:a*c[e-1];for(var g=0,h=e-1,k;g<=h;){d=Math.floor(g+(h-g)/2);k=c[d]-f;if(k<0)g=d+1;else if(k>0)h=d-1;else{h=d;break}}d=h;if(c[d]==f)return d/(e-1);g=c[d];return c=(d+(f-g)/(c[d+1]-g))/(e-1)};THREE.Curve.prototype.getNormalVector=function(a){a=this.getTangent(a);return new THREE.Vector2(-a.y,a.x)};
THREE.Curve.prototype.getTangent=function(a){var b=a-1.0E-4,a=a+1.0E-4;b<0&&(b=0);a>1&&(a=1);b=this.getPoint(b);return this.getPoint(a).clone().subSelf(b).normalize()};THREE.Curve.prototype.getTangentAt=function(a){return this.getTangent(this.getUtoTmapping(a))};THREE.LineCurve=function(a,b){this.v1=a;this.v2=b};THREE.LineCurve.prototype=Object.create(THREE.Curve.prototype);THREE.LineCurve.prototype.getPoint=function(a){var b=this.v2.clone().subSelf(this.v1);b.multiplyScalar(a).addSelf(this.v1);return b};
THREE.LineCurve.prototype.getPointAt=function(a){return this.getPoint(a)};THREE.LineCurve.prototype.getTangent=function(){return this.v2.clone().subSelf(this.v1).normalize()};THREE.QuadraticBezierCurve=function(a,b,c){this.v0=a;this.v1=b;this.v2=c};THREE.QuadraticBezierCurve.prototype=Object.create(THREE.Curve.prototype);
THREE.QuadraticBezierCurve.prototype.getPoint=function(a){var b;b=THREE.Shape.Utils.b2(a,this.v0.x,this.v1.x,this.v2.x);a=THREE.Shape.Utils.b2(a,this.v0.y,this.v1.y,this.v2.y);return new THREE.Vector2(b,a)};THREE.QuadraticBezierCurve.prototype.getTangent=function(a){var b;b=THREE.Curve.Utils.tangentQuadraticBezier(a,this.v0.x,this.v1.x,this.v2.x);a=THREE.Curve.Utils.tangentQuadraticBezier(a,this.v0.y,this.v1.y,this.v2.y);b=new THREE.Vector2(b,a);b.normalize();return b};
......
......@@ -48,10 +48,12 @@ THREE.FontUtils.generateShapes=function(b,a){var a=a||{},c=a.curveSegments!==voi
A=void 0,w=void 0,u=void 0,C=void 0,v=k[s[m]].x,p=k[s[m]].y,x=k[s[o]].x,z=k[s[o]].y,A=k[s[q]].x,w=k[s[q]].y;if(1.0E-10>(x-v)*(w-p)-(z-p)*(A-v))k=false;else{for(t=0;t<r;t++)if(!(t==m||t==o||t==q)){var u=k[s[t]].x,C=k[s[t]].y,B=void 0,E=void 0,G=void 0,L=void 0,H=void 0,D=void 0,K=void 0,F=void 0,N=void 0,I=void 0,M=void 0,J=void 0,B=G=H=void 0,B=A-x,E=w-z,G=v-A,L=p-w,H=x-v,D=z-p,K=u-v,F=C-p,N=u-x,I=C-z,M=u-A,J=C-w,B=B*I-E*N,H=H*F-D*K,G=G*J-L*M;if(B>=0&&G>=0&&H>=0){k=false;break a}}k=true}}if(k){f.push([b[g[i]],
b[g[j]],b[g[l]]]);h.push([g[i],g[j],g[l]]);i=j;for(l=j+1;l<e;i++,l++)g[i]=g[l];e--;n=2*e}}return d?h:f};b.Triangulate.area=a;return b})(THREE.FontUtils);self._typeface_js={faces:THREE.FontUtils.faces,loadFace:THREE.FontUtils.loadFace};
THREE.BufferGeometry=function(){this.id=THREE.GeometryCount++;this.vertexColorArray=this.vertexUvArray=this.vertexNormalArray=this.vertexPositionArray=this.vertexIndexArray=this.vertexColorBuffer=this.vertexUvBuffer=this.vertexNormalBuffer=this.vertexPositionBuffer=this.vertexIndexBuffer=null;this.dynamic=false;this.boundingSphere=this.boundingBox=null;this.morphTargets=[]};
THREE.BufferGeometry.prototype={constructor:THREE.BufferGeometry,applyMatrix:function(b){if(this.vertexPositionArray!==void 0){b.multiplyVector3Array(this.vertexPositionArray);this.verticesNeedUpdate=true}if(this.vertexNormalArray!==void 0){var a=new THREE.Matrix4;a.extractRotation(b);a.multiplyVector3Array(this.vertexNormalArray);this.normalsNeedUpdate=true}},computeBoundingBox:function(){},computeBoundingSphere:function(){}};THREE.Curve=function(){};
THREE.Curve.prototype.getPoint=function(){console.log("Warning, getPoint() not implemented!");return null};THREE.Curve.prototype.getPointAt=function(b){return this.getPoint(this.getUtoTmapping(b))};THREE.Curve.prototype.getPoints=function(b){b||(b=5);var a,c=[];for(a=0;a<=b;a++)c.push(this.getPoint(a/b));return c};THREE.Curve.prototype.getSpacedPoints=function(b){b||(b=5);var a,c=[];for(a=0;a<=b;a++)c.push(this.getPointAt(a/b));return c};
THREE.Curve.prototype.getLength=function(){var b=this.getLengths();return b[b.length-1]};THREE.Curve.prototype.getLengths=function(b){b||(b=this.__arcLengthDivisions?this.__arcLengthDivisions:200);if(this.cacheArcLengths&&this.cacheArcLengths.length==b+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=false;var a=[],c,d=this.getPoint(0),e,f=0;a.push(0);for(e=1;e<=b;e++){c=this.getPoint(e/b);f=f+c.distanceTo(d);a.push(f);d=c}return this.cacheArcLengths=a};
THREE.Curve.prototype.updateArcLengths=function(){this.needsUpdate=true;this.getLengths()};THREE.Curve.prototype.getUtoTmapping=function(b,a){var c=this.getLengths(),d=0,e=c.length,f;f=a?a:b*c[e-1];for(var g=0,h=e-1,i;g<=h;){d=Math.floor(g+(h-g)/2);i=c[d]-f;if(i<0)g=d+1;else if(i>0)h=d-1;else{h=d;break}}d=h;if(c[d]==f)return d/(e-1);g=c[d];return c=(d+(f-g)/(c[d+1]-g))/(e-1)};THREE.Curve.prototype.getNormalVector=function(b){b=this.getTangent(b);return new THREE.Vector2(-b.y,b.x)};
THREE.BufferGeometry.prototype={constructor:THREE.BufferGeometry,applyMatrix:function(b){if(this.vertexPositionArray!==void 0){b.multiplyVector3Array(this.vertexPositionArray);this.verticesNeedUpdate=true}if(this.vertexNormalArray!==void 0){var a=new THREE.Matrix4;a.extractRotation(b);a.multiplyVector3Array(this.vertexNormalArray);this.normalsNeedUpdate=true}},computeBoundingBox:function(){if(!this.boundingBox)this.boundingBox={min:new THREE.Vector3(Infinity,Infinity,Infinity),max:new THREE.Vector3(-Infinity,
-Infinity,-Infinity)};var b=this.vertexPositionArray;if(b)for(var a=this.boundingBox,c,d,e,f=0,g=b.length;f<g;f=f+3){c=b[f];d=b[f+1];e=b[f+2];if(c<a.min.x)a.min.x=c;else if(c>a.max.x)a.max.x=c;if(d<a.min.y)a.min.y=d;else if(d>a.max.y)a.max.y=d;if(e<a.min.z)a.min.z=e;else if(e>a.max.z)a.max.z=e}if(b===void 0||b.length===0){this.boundingBox.min.set(0,0,0);this.boundingBox.max.set(0,0,0)}},computeBoundingSphere:function(){if(!this.boundingSphere)this.boundingSphere={radius:0};var b=this.vertexPositionArray;
if(b){for(var a,c=0,d,e,f=0,g=b.length;f<g;f=f+3){a=b[f];d=b[f+1];e=b[f+2];a=Math.sqrt(a*a+d*d+e*e);a>c&&(c=a)}this.boundingSphere.radius=c}}};THREE.Curve=function(){};THREE.Curve.prototype.getPoint=function(){console.log("Warning, getPoint() not implemented!");return null};THREE.Curve.prototype.getPointAt=function(b){return this.getPoint(this.getUtoTmapping(b))};THREE.Curve.prototype.getPoints=function(b){b||(b=5);var a,c=[];for(a=0;a<=b;a++)c.push(this.getPoint(a/b));return c};
THREE.Curve.prototype.getSpacedPoints=function(b){b||(b=5);var a,c=[];for(a=0;a<=b;a++)c.push(this.getPointAt(a/b));return c};THREE.Curve.prototype.getLength=function(){var b=this.getLengths();return b[b.length-1]};
THREE.Curve.prototype.getLengths=function(b){b||(b=this.__arcLengthDivisions?this.__arcLengthDivisions:200);if(this.cacheArcLengths&&this.cacheArcLengths.length==b+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=false;var a=[],c,d=this.getPoint(0),e,f=0;a.push(0);for(e=1;e<=b;e++){c=this.getPoint(e/b);f=f+c.distanceTo(d);a.push(f);d=c}return this.cacheArcLengths=a};THREE.Curve.prototype.updateArcLengths=function(){this.needsUpdate=true;this.getLengths()};
THREE.Curve.prototype.getUtoTmapping=function(b,a){var c=this.getLengths(),d=0,e=c.length,f;f=a?a:b*c[e-1];for(var g=0,h=e-1,i;g<=h;){d=Math.floor(g+(h-g)/2);i=c[d]-f;if(i<0)g=d+1;else if(i>0)h=d-1;else{h=d;break}}d=h;if(c[d]==f)return d/(e-1);g=c[d];return c=(d+(f-g)/(c[d+1]-g))/(e-1)};THREE.Curve.prototype.getNormalVector=function(b){b=this.getTangent(b);return new THREE.Vector2(-b.y,b.x)};
THREE.Curve.prototype.getTangent=function(b){var a=b-1.0E-4,b=b+1.0E-4;a<0&&(a=0);b>1&&(b=1);a=this.getPoint(a);return this.getPoint(b).clone().subSelf(a).normalize()};THREE.Curve.prototype.getTangentAt=function(b){return this.getTangent(this.getUtoTmapping(b))};THREE.LineCurve=function(b,a){this.v1=b;this.v2=a};THREE.LineCurve.prototype=Object.create(THREE.Curve.prototype);THREE.LineCurve.prototype.getPoint=function(b){var a=this.v2.clone().subSelf(this.v1);a.multiplyScalar(b).addSelf(this.v1);return a};
THREE.LineCurve.prototype.getPointAt=function(b){return this.getPoint(b)};THREE.LineCurve.prototype.getTangent=function(){return this.v2.clone().subSelf(this.v1).normalize()};THREE.QuadraticBezierCurve=function(b,a,c){this.v0=b;this.v1=a;this.v2=c};THREE.QuadraticBezierCurve.prototype=Object.create(THREE.Curve.prototype);
THREE.QuadraticBezierCurve.prototype.getPoint=function(b){var a;a=THREE.Shape.Utils.b2(b,this.v0.x,this.v1.x,this.v2.x);b=THREE.Shape.Utils.b2(b,this.v0.y,this.v1.y,this.v2.y);return new THREE.Vector2(a,b)};THREE.QuadraticBezierCurve.prototype.getTangent=function(b){var a;a=THREE.Curve.Utils.tangentQuadraticBezier(b,this.v0.x,this.v1.x,this.v2.x);b=THREE.Curve.Utils.tangentQuadraticBezier(b,this.v0.y,this.v1.y,this.v2.y);a=new THREE.Vector2(a,b);a.normalize();return a};
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -518,63 +518,6 @@ THREE.CTMLoader.prototype.createModelBuffers = function ( file, callback ) {
}
// compute bounding sphere and bounding box
// (must do it now as we don't keep typed arrays after setting GL buffers)
scope.boundingBox = { min: new THREE.Vector3( Infinity, Infinity, Infinity ), max: new THREE.Vector3( -Infinity, -Infinity, -Infinity ) };
var vertices = file.body.vertices,
bb = scope.boundingBox,
radius, maxRadius = 0,
x, y, z;
for ( var i = 0, il = vertices.length; i < il; i += 3 ) {
x = vertices[ i ];
y = vertices[ i + 1 ];
z = vertices[ i + 2 ];
// bounding sphere
radius = Math.sqrt( x * x + y * y + z * z );
if ( radius > maxRadius ) maxRadius = radius;
// bounding box
if ( x < bb.min.x ) {
bb.min.x = x;
} else if ( x > bb.max.x ) {
bb.max.x = x;
}
if ( y < bb.min.y ) {
bb.min.y = y;
} else if ( y > bb.max.y ) {
bb.max.y = y;
}
if ( z < bb.min.z ) {
bb.min.z = z;
} else if ( z > bb.max.z ) {
bb.max.z = z;
}
}
scope.boundingSphere = { radius: maxRadius };
// keep references to typed arrays
if ( keepArrays ) {
......
......@@ -60,18 +60,99 @@ THREE.BufferGeometry.prototype = {
},
// for compatibility
computeBoundingBox: function () {
},
if ( ! this.boundingBox ) {
// for compatibility
this.boundingBox = { min: new THREE.Vector3( Infinity, Infinity, Infinity ), max: new THREE.Vector3( -Infinity, -Infinity, -Infinity ) };
}
var vertices = this.vertexPositionArray;
if ( vertices ) {
var bb = this.boundingBox;
var x, y, z;
for ( var i = 0, il = vertices.length; i < il; i += 3 ) {
x = vertices[ i ];
y = vertices[ i + 1 ];
z = vertices[ i + 2 ];
// bounding box
if ( x < bb.min.x ) {
bb.min.x = x;
} else if ( x > bb.max.x ) {
bb.max.x = x;
}
if ( y < bb.min.y ) {
bb.min.y = y;
} else if ( y > bb.max.y ) {
bb.max.y = y;
}
if ( z < bb.min.z ) {
bb.min.z = z;
} else if ( z > bb.max.z ) {
bb.max.z = z;
}
}
}
if ( vertices === undefined || vertices.length === 0 ) {
this.boundingBox.min.set( 0, 0, 0 );
this.boundingBox.max.set( 0, 0, 0 );
}
},
computeBoundingSphere: function () {
}
if ( ! this.boundingSphere ) this.boundingSphere = { radius: 0 };
var vertices = this.vertexPositionArray;
if ( vertices ) {
var radius, maxRadius = 0;
var x, y, z;
for ( var i = 0, il = vertices.length; i < il; i += 3 ) {
x = vertices[ i ];
y = vertices[ i + 1 ];
z = vertices[ i + 2 ];
radius = Math.sqrt( x * x + y * y + z * z );
if ( radius > maxRadius ) maxRadius = radius;
}
this.boundingSphere.radius = maxRadius;
}
}
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册