提交 09a10f7b 编写于 作者: A alteredq

Fixed update of PathCamera.

No more need for manual update hack.

Problems with keeping constant speed are still there. Added debug particles sampled along the spline - seems problems come from spline, samples have weird distribution.
上级 1f9d0d57
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -48,7 +48,7 @@ b,c)}}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==undefined
THREE.Quaternion.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},setFromEuler:function(a){var b=0.5*Math.PI/360,c=a.x*b,d=a.y*b,e=a.z*b;a=Math.cos(d);d=Math.sin(d);b=Math.cos(-e);e=Math.sin(-e);var f=Math.cos(c);c=Math.sin(c);var g=a*b,j=d*e;this.w=g*f-j*c;this.x=g*c+j*f;this.y=d*b*f+a*e*c;this.z=a*e*f-d*b*c;return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=
-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(a==0)this.w=this.z=this.y=this.x=0;else{a=1/a;this.x*=a;this.y*=a;this.z*=a;this.w*=a}return this},multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,f=a.x,g=a.y,j=a.z;a=a.w;this.x=b*a+e*f+c*j-d*g;this.y=c*a+e*g+d*f-b*j;this.z=d*a+e*j+b*g-c*f;this.w=e*a-b*f-c*g-d*j;return this},
multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,j=this.z,h=this.w,i=h*c+g*e-j*d,p=h*d+j*c-f*e,n=h*e+f*d-g*c;c=-f*c-g*d-j*e;b.x=i*h+c*-f+p*-j-n*-g;b.y=p*h+c*-g+n*-f-i*-j;b.z=n*h+c*-j+i*-g-p*-f;return b}};
THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(Math.abs(e)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var f=Math.acos(e),g=Math.sqrt(1-e*e);if(Math.abs(g)<0.001){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}e=Math.sin((1-d)*f)/g;d=Math.sin(d*f)/g;c.w=a.w*e+b.w*d;c.x=a.x*e+b.x*d;c.y=a.y*e+b.y*d;c.z=a.z*e+b.z*d;return c};
THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(Math.abs(e)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var f=Math.acos(e),g=Math.sqrt(1-e*e);if(Math.abs(g)<0.0010){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}e=Math.sin((1-d)*f)/g;d=Math.sin(d*f)/g;c.w=a.w*e+b.w*d;c.x=a.x*e+b.x*d;c.y=a.y*e+b.y*d;c.z=a.z*e+b.z*d;return c};
THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=!0};
THREE.Face3=function(a,b,c,d,e){this.a=a;this.b=b;this.c=c;this.centroid=new THREE.Vector3;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.materials=e instanceof Array?e:[e]};THREE.Face4=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.d=d;this.centroid=new THREE.Vector3;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.materials=f instanceof Array?f:[f]};
THREE.UV=function(a,b){this.set(a||0,b||0)};THREE.UV.prototype={set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.set(a.u,a.v);return this}};THREE.Geometry=function(){this.id="Geometry"+THREE.GeometryIdCounter++;this.vertices=[];this.faces=[];this.uvs=[];this.uvs2=[];this.colors=[];this.skinWeights=[];this.skinIndices=[];this.boundingSphere=this.boundingBox=null;this.hasTangents=!1};
......
......@@ -48,7 +48,7 @@ b,c)}}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==undefined
THREE.Quaternion.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},setFromEuler:function(a){var b=0.5*Math.PI/360,c=a.x*b,d=a.y*b,e=a.z*b;a=Math.cos(d);d=Math.sin(d);b=Math.cos(-e);e=Math.sin(-e);var f=Math.cos(c);c=Math.sin(c);var g=a*b,i=d*e;this.w=g*f-i*c;this.x=g*c+i*f;this.y=d*b*f+a*e*c;this.z=a*e*f-d*b*c;return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=
-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(a==0)this.w=this.z=this.y=this.x=0;else{a=1/a;this.x*=a;this.y*=a;this.z*=a;this.w*=a}return this},multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,f=a.x,g=a.y,i=a.z;a=a.w;this.x=b*a+e*f+c*i-d*g;this.y=c*a+e*g+d*f-b*i;this.z=d*a+e*i+b*g-c*f;this.w=e*a-b*f-c*g-d*i;return this},
multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,i=this.z,h=this.w,j=h*c+g*e-i*d,n=h*d+i*c-f*e,m=h*e+f*d-g*c;c=-f*c-g*d-i*e;b.x=j*h+c*-f+n*-i-m*-g;b.y=n*h+c*-g+m*-f-j*-i;b.z=m*h+c*-i+j*-g-n*-f;return b}};
THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(Math.abs(e)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var f=Math.acos(e),g=Math.sqrt(1-e*e);if(Math.abs(g)<0.001){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}e=Math.sin((1-d)*f)/g;d=Math.sin(d*f)/g;c.w=a.w*e+b.w*d;c.x=a.x*e+b.x*d;c.y=a.y*e+b.y*d;c.z=a.z*e+b.z*d;return c};
THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(Math.abs(e)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var f=Math.acos(e),g=Math.sqrt(1-e*e);if(Math.abs(g)<0.0010){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}e=Math.sin((1-d)*f)/g;d=Math.sin(d*f)/g;c.w=a.w*e+b.w*d;c.x=a.x*e+b.x*d;c.y=a.y*e+b.y*d;c.z=a.z*e+b.z*d;return c};
THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=!0};
THREE.Face3=function(a,b,c,d,e){this.a=a;this.b=b;this.c=c;this.centroid=new THREE.Vector3;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.materials=e instanceof Array?e:[e]};THREE.Face4=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.d=d;this.centroid=new THREE.Vector3;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.materials=f instanceof Array?f:[f]};
THREE.UV=function(a,b){this.set(a||0,b||0)};THREE.UV.prototype={set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.set(a.u,a.v);return this}};THREE.Camera=function(a,b,c,d,e){THREE.Object3D.call(this);this.fov=a||50;this.aspect=b||1;this.near=c||0.1;this.far=d||2E3;this.target=e||new THREE.Object3D;this.useTarget=!0;this.matrixWorldInverse=new THREE.Matrix4;this.projectionMatrix=null;this.updateProjectionMatrix()};THREE.Camera.prototype=new THREE.Object3D;
......
......@@ -38,7 +38,7 @@ var Torus=function(a,d,b,f){this.radius=a||100;this.tube=d||40;this.segmentsR=b|
var Icosahedron=function(a){function d(v,q,n){var p=Math.sqrt(v*v+q*q+n*n);return h.vertices.push(new THREE.Vertex(new THREE.Vector3(v/p,q/p,n/p)))-1}function b(v,q,n,p){p.faces.push(new THREE.Face3(v,q,n))}function f(v,q){var n=h.vertices[v].position,p=h.vertices[q].position;return d((n.x+p.x)/2,(n.y+p.y)/2,(n.z+p.z)/2)}var h=this,c=new THREE.Geometry,e;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;d(-1,a,0);d(1,a,0);d(-1,-a,0);d(1,-a,0);d(0,-1,a);d(0,1,a);d(0,-1,-a);d(0,
1,-a);d(a,0,-1);d(a,0,1);d(-a,0,-1);d(-a,0,1);b(0,11,5,c);b(0,5,1,c);b(0,1,7,c);b(0,7,10,c);b(0,10,11,c);b(1,5,9,c);b(5,11,4,c);b(11,10,2,c);b(10,7,6,c);b(7,1,8,c);b(3,9,4,c);b(3,4,2,c);b(3,2,6,c);b(3,6,8,c);b(3,8,9,c);b(4,9,5,c);b(2,4,11,c);b(6,2,10,c);b(8,6,7,c);b(9,8,1,c);for(a=0;a<this.subdivisions;a++){e=new THREE.Geometry;for(var g in c.faces){var j=f(c.faces[g].a,c.faces[g].b),m=f(c.faces[g].b,c.faces[g].c),k=f(c.faces[g].c,c.faces[g].a);b(c.faces[g].a,j,k,e);b(c.faces[g].b,m,j,e);b(c.faces[g].c,
k,m,e);b(j,m,k,e)}c.faces=e.faces}h.faces=c.faces;delete c;delete e;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};Icosahedron.prototype=new THREE.Geometry;Icosahedron.prototype.constructor=Icosahedron;
function LathedObject(a,d,b){THREE.Geometry.call(this);this.nsteps=d||12;this.latheAngle=b||2*Math.PI;d=this.latheAngle/this.nsteps;for(var f=[],h=[],c=[],e=[],g=0;g<a.length;g++){this.vertices.push(new THREE.Vertex(a[g]));h[g]=this.vertices.length-1;f[g]=new THREE.Vector3(a[g].x,a[g].y,a[g].z)}for(var j=THREE.Matrix4.rotationZMatrix(this.stepSize),m=0;m<=this.latheAngle+0.001;m+=this.stepSize){for(g=0;g<f.length;g++)if(m<b){f[g]=j.multiplyVector3(f[g].clone());this.vertices.push(new THREE.Vertex(f[g]));
function LathedObject(a,d,b){THREE.Geometry.call(this);this.nsteps=d||12;this.latheAngle=b||2*Math.PI;d=this.latheAngle/this.nsteps;for(var f=[],h=[],c=[],e=[],g=0;g<a.length;g++){this.vertices.push(new THREE.Vertex(a[g]));h[g]=this.vertices.length-1;f[g]=new THREE.Vector3(a[g].x,a[g].y,a[g].z)}for(var j=THREE.Matrix4.rotationZMatrix(this.stepSize),m=0;m<=this.latheAngle+0.0010;m+=this.stepSize){for(g=0;g<f.length;g++)if(m<b){f[g]=j.multiplyVector3(f[g].clone());this.vertices.push(new THREE.Vertex(f[g]));
c[g]=this.vertices.length-1}else c=e;m==0&&(e=h);for(g=0;g<h.length-1;g++){this.faces.push(new THREE.Face4(c[g],c[g+1],h[g+1],h[g]));this.uvs.push([new THREE.UV(m/b,g/a.length),new THREE.UV(m/b,(g+1)/a.length),new THREE.UV((m-d)/b,(g+1)/a.length),new THREE.UV((m-d)/b,g/a.length)])}h=c;c=[]}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()}LathedObject.prototype=new THREE.Geometry;LathedObject.prototype.constructor=LathedObject;
if(!window.Int32Array){window.Int32Array=Array;window.Float32Array=Array}
THREE.MarchingCubes=function(a,d){THREE.Object3D.call(this);this.materials=d instanceof Array?d:[d];this.init=function(b){this.isolation=80;this.size=b;this.size2=this.size*this.size;this.size3=this.size2*this.size;this.halfsize=this.size/2;this.delta=2/this.size;this.yd=this.size;this.zd=this.size2;this.field=new Float32Array(this.size3);this.normal_cache=new Float32Array(this.size3*3);this.vlist=new Float32Array(36);this.nlist=new Float32Array(36);this.firstDraw=!0;this.maxCount=4096;this.count=
......
......@@ -48,7 +48,7 @@ b,c)}}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==undefined
THREE.Quaternion.prototype={set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},setFromEuler:function(a){var b=0.5*Math.PI/360,c=a.x*b,d=a.y*b,e=a.z*b;a=Math.cos(d);d=Math.sin(d);b=Math.cos(-e);e=Math.sin(-e);var f=Math.cos(c);c=Math.sin(c);var g=a*b,i=d*e;this.w=g*f-i*c;this.x=g*c+i*f;this.y=d*b*f+a*e*c;this.z=a*e*f-d*b*c;return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=
-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);if(a==0)this.w=this.z=this.y=this.x=0;else{a=1/a;this.x*=a;this.y*=a;this.z*=a;this.w*=a}return this},multiplySelf:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,f=a.x,g=a.y,i=a.z;a=a.w;this.x=b*a+e*f+c*i-d*g;this.y=c*a+e*g+d*f-b*i;this.z=d*a+e*i+b*g-c*f;this.w=e*a-b*f-c*g-d*i;return this},
multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,i=this.z,h=this.w,l=h*c+g*e-i*d,n=h*d+i*c-f*e,m=h*e+f*d-g*c;c=-f*c-g*d-i*e;b.x=l*h+c*-f+n*-i-m*-g;b.y=n*h+c*-g+m*-f-l*-i;b.z=m*h+c*-i+l*-g-n*-f;return b}};
THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(Math.abs(e)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var f=Math.acos(e),g=Math.sqrt(1-e*e);if(Math.abs(g)<0.001){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}e=Math.sin((1-d)*f)/g;d=Math.sin(d*f)/g;c.w=a.w*e+b.w*d;c.x=a.x*e+b.x*d;c.y=a.y*e+b.y*d;c.z=a.z*e+b.z*d;return c};
THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;if(Math.abs(e)>=1){c.w=a.w;c.x=a.x;c.y=a.y;c.z=a.z;return c}var f=Math.acos(e),g=Math.sqrt(1-e*e);if(Math.abs(g)<0.0010){c.w=0.5*(a.w+b.w);c.x=0.5*(a.x+b.x);c.y=0.5*(a.y+b.y);c.z=0.5*(a.z+b.z);return c}e=Math.sin((1-d)*f)/g;d=Math.sin(d*f)/g;c.w=a.w*e+b.w*d;c.x=a.x*e+b.x*d;c.y=a.y*e+b.y*d;c.z=a.z*e+b.z*d;return c};
THREE.Vertex=function(a,b){this.position=a||new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.normal=b||new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.normalScreen=new THREE.Vector3;this.tangent=new THREE.Vector4;this.__visible=!0};
THREE.Face3=function(a,b,c,d,e){this.a=a;this.b=b;this.c=c;this.centroid=new THREE.Vector3;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.materials=e instanceof Array?e:[e]};THREE.Face4=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.d=d;this.centroid=new THREE.Vector3;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.materials=f instanceof Array?f:[f]};
THREE.UV=function(a,b){this.set(a||0,b||0)};THREE.UV.prototype={set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.set(a.u,a.v);return this}};THREE.Geometry=function(){this.id="Geometry"+THREE.GeometryIdCounter++;this.vertices=[];this.faces=[];this.uvs=[];this.uvs2=[];this.colors=[];this.skinWeights=[];this.skinIndices=[];this.boundingSphere=this.boundingBox=null;this.hasTangents=!1};
......
此差异已折叠。
......@@ -27,31 +27,31 @@
THREE.PathCamera = function ( parameters ) {
THREE.Camera.call( this, parameters.fov, parameters.aspect, parameters.near, parameters.far, parameters.target );
this.duration = 10 * 1000; // milliseconds
this.waypoints = [];
this.debugPath = new THREE.Object3D();
this.debugDummy = new THREE.Object3D();
this.animationParent = new THREE.Object3D();
this.lookSpeed = 0.005;
this.lookVertical = true;
this.lookHorizontal = true;
this.verticalAngleMap = { srcRange: [ 0, 6.28 ], dstRange: [ 0, 6.28 ] };
this.horizontalAngleMap = { srcRange: [ 0, 6.28 ], dstRange: [ 0, 6.28 ] };
this.domElement = document;
if ( parameters ) {
if ( parameters.duration !== undefined ) this.duration = parameters.duration * 1000;
if ( parameters.waypoints !== undefined ) this.waypoints = parameters.waypoints;
if ( parameters.createDebugPath !== undefined ) this.createDebugPath = parameters.createDebugPath;
if ( parameters.createDebugDummy !== undefined ) this.createDebugDummy = parameters.createDebugDummy;
if ( parameters.lookSpeed !== undefined ) this.lookSpeed = parameters.lookSpeed;
if ( parameters.lookVertical !== undefined ) this.lookVertical = parameters.lookVertical;
if ( parameters.lookHorizontal !== undefined ) this.lookHorizontal = parameters.lookHorizontal;
......@@ -67,24 +67,24 @@ THREE.PathCamera = function ( parameters ) {
this.lat = 0;
this.lon = 0;
this.phi = 0;
this.theta = 0;
this.windowHalfX = window.innerWidth / 2;
this.windowHalfY = window.innerHeight / 2;
var PI2 = Math.PI * 2,
PI180 = Math.PI / 180;
// methods
this.updateManual = function () {
this.update = function ( parentMatrixWorld, forceUpdate, camera ) {
var srcRange, dstRange;
if( this.lookHorizontal ) this.lon += this.mouseX * this.lookSpeed;
if( this.lookVertical ) this.lat -= this.mouseY * this.lookSpeed;
if( this.lookVertical ) this.lat -= this.mouseY * this.lookSpeed;
this.lon = Math.max( 0, Math.min( 360, this.lon ) );
this.lat = Math.max( - 85, Math.min( 85, this.lat ) );
......@@ -117,7 +117,7 @@ THREE.PathCamera = function ( parameters ) {
targetPosition.y = position.y + 100 * Math.cos( this.phi );
targetPosition.z = position.z + 100 * Math.sin( this.phi ) * Math.sin( this.theta );
this.supr.update.call( this );
this.supr.update.call( this, parentMatrixWorld, forceUpdate, camera );
};
......@@ -148,8 +148,8 @@ THREE.PathCamera = function ( parameters ) {
return ( x - sa ) * ( eb - ea ) / ( sb - sa ) + ea;
};
function distance( a, b ) {
var dx = a[ 0 ] - b[ 0 ],
......@@ -157,7 +157,7 @@ THREE.PathCamera = function ( parameters ) {
dz = a[ 2 ] - b[ 2 ];
return Math.sqrt( dx * dx + dy * dy + dz * dz );
};
function bind( scope, fn ) {
......@@ -171,7 +171,7 @@ THREE.PathCamera = function ( parameters ) {
};
function initAnimationPath( parent, path, name, duration ) {
var animationData = {
name: name,
......@@ -179,28 +179,31 @@ THREE.PathCamera = function ( parameters ) {
length: duration,
hierarchy: []
};
var i,
parentAnimation, childAnimation,
pl = path.length,
totalLength = splineLength( path ),
sl = splineLength( path ),
t = 0,
first = 0,
last = pl - 1;
parentAnimation = { parent: -1, keys: [] };
parentAnimation.keys[ first ] = { time: 0, pos: path[ first ], rot: [ 0, 0, 0, 1 ], scl: [ 1, 1, 1 ] };
parentAnimation.keys[ last ] = { time: duration, pos: path[ last ], rot: [ 0, 0, 0, 1 ], scl: [ 1, 1, 1 ] };
console.log( "path totalLength: ", totalLength );
parentAnimation.keys[ last ] = { time: duration, pos: path[ last ], rot: [ 0, 0, 0, 1 ], scl: [ 1, 1, 1 ] };
for ( i = first + 1; i < last; i++ ) {
console.log( "path length total:", sl.total, "chunks:", sl.chunks );
t += duration * distance( path[ i ], path[ i - 1 ] ) / totalLength;
for ( i = 1; i < pl-1; i++ ) {
t = duration * sl.chunks[ i ] / sl.total;
//t += duration * distance( path[ i ], path[ i - 1 ] ) / sl.total;
parentAnimation.keys[ i ] = { time: t, pos: path[ i ] };
console.log( i, t/1000 );
}
......@@ -209,66 +212,84 @@ THREE.PathCamera = function ( parameters ) {
THREE.AnimationHandler.add( animationData );
return new THREE.Animation( parent, name, THREE.AnimationHandler.CATMULLROM_FORWARD, false );
//return new THREE.Animation( parent, name, THREE.AnimationHandler.CATMULLROM, false );
//return new THREE.Animation( parent, name, THREE.AnimationHandler.LINEAR, false );
};
function createSplineGeometryFromPoints( points, n_sub ) {
var i, index, position,
geometry = new THREE.Geometry(),
function splineLength( points ) {
var i, index, p, coords = [],
spline = new THREE.Spline(),
p, coords = [];
n_sub = 100,
c = 0,
point = 0, intPoint = 0, oldIntPoint = 0,
chunkLengths = [ 0 ],
totalLength = 0;
for ( i = 0; i < points.length; i ++ ) {
p = points[ i ];
coords[ i ] = { x: p[ 0 ], y: p[ 1 ], z: p[ 2 ] };
}
for ( i = 0; i < coords.length * n_sub; i ++ ) {
var oldPosition = [ points[ 0 ][ 0 ], points[ 0 ][ 1 ], points[ 0 ][ 2 ] ];
for ( i = 1; i < coords.length * n_sub; i ++ ) {
index = i / ( coords.length * n_sub );
position = spline.getPoint( coords, index );
totalLength += distance( [ position.x, position.y, position.z ], oldPosition );
oldPosition = [ position.x, position.y, position.z ];
point = ( coords.length - 1 ) * index;
intPoint = Math.floor( point );
geometry.vertices[ i ] = new THREE.Vertex( new THREE.Vector3( position.x, position.y, position.z ) );
if ( intPoint != oldIntPoint ) {
chunkLengths[ intPoint ] = totalLength;
oldIntPoint = intPoint;
}
//console.log( intPoint, i, index, totalLength );
}
return geometry;
return { chunks: chunkLengths, total: totalLength };
};
function splineLength( points ) {
var i, index, p, coords = [],
spline = new THREE.Spline(),
n_sub = 100, totalLength = 0;
function createSplineGeometryFromPoints( points, n_sub ) {
var i, index, position,
geometry = new THREE.Geometry(),
spline = new THREE.Spline(),
p, coords = [];
for ( i = 0; i < points.length; i ++ ) {
p = points[ i ];
coords[ i ] = { x: p[ 0 ], y: p[ 1 ], z: p[ 2 ] };
}
var oldPosition = [ points[ 0 ][ 0 ], points[ 0 ][ 1 ], points[ 0 ][ 2 ] ];
for ( i = 1; i < coords.length * n_sub; i ++ ) {
for ( i = 0; i < coords.length * n_sub; i ++ ) {
index = i / ( coords.length * n_sub );
position = spline.getPoint( coords, index );
totalLength += distance( [ position.x, position.y, position.z ], oldPosition );
oldPosition = [ position.x, position.y, position.z ];
geometry.vertices[ i ] = new THREE.Vertex( new THREE.Vector3( position.x, position.y, position.z ) );
}
}
return totalLength;
return geometry;
};
function createWaypointGeometryFromPoints( points ) {
var i, position,
......@@ -288,12 +309,17 @@ THREE.PathCamera = function ( parameters ) {
function createPath( parent, path ) {
var lineGeo = createSplineGeometryFromPoints( path, 10 ),
particleGeo = createSplineGeometryFromPoints( path, 10 ),
lineMat = new THREE.LineBasicMaterial( { color: 0xff0000, linewidth: 3 } );
lineObj = new THREE.Line( lineGeo, lineMat );
particleObj = new THREE.ParticleSystem( particleGeo, new THREE.ParticleBasicMaterial( { color: 0xffaa00, size: 3 } ) );
lineObj.scale.set( 1, 1, 1 );
parent.addChild( lineObj );
particleObj.scale.set( 1, 1, 1 );
parent.addChild( particleObj );
var waypoint,
geo = new Sphere( 1, 16, 8 ),
mat = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册