mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-09 13:06:01 +10:00
Changed addChild()s to add()s in ColladaLoader.
Cleaned up some more examples.
This commit is contained in:
+7
-7
@@ -69,7 +69,7 @@ THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(b,c,e,f){t
|
||||
this.x=b.x*f;this.y=b.y*f;this.z=b.z*f;this.w=Math.cos(e);return this},setFromRotationMatrix:function(b){var c=Math.pow(b.determinant(),1/3);this.w=Math.sqrt(Math.max(0,c+b.n11+b.n22+b.n33))/2;this.x=Math.sqrt(Math.max(0,c+b.n11-b.n22-b.n33))/2;this.y=Math.sqrt(Math.max(0,c-b.n11+b.n22-b.n33))/2;this.z=Math.sqrt(Math.max(0,c-b.n11-b.n22+b.n33))/2;this.x=b.n32-b.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=b.n13-b.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=b.n21-b.n12<0?-Math.abs(this.z):Math.abs(this.z);
|
||||
this.normalize();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 b=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);b==0?this.w=this.z=this.y=this.x=0:(b=1/b,this.x*=b,this.y*=b,this.z*=b,this.w*=b);return this},multiplySelf:function(b){var c=
|
||||
this.x,e=this.y,f=this.z,h=this.w,m=b.x,k=b.y,n=b.z,b=b.w;this.x=c*b+h*m+e*n-f*k;this.y=e*b+h*k+f*m-c*n;this.z=f*b+h*n+c*k-e*m;this.w=h*b-c*m-e*k-f*n;return this},multiply:function(b,c){this.x=b.x*c.w+b.y*c.z-b.z*c.y+b.w*c.x;this.y=-b.x*c.z+b.y*c.w+b.z*c.x+b.w*c.y;this.z=b.x*c.y-b.y*c.x+b.z*c.w+b.w*c.z;this.w=-b.x*c.x-b.y*c.y-b.z*c.z+b.w*c.w;return this},multiplyVector3:function(b,c){c||(c=b);var e=b.x,f=b.y,h=b.z,m=this.x,k=this.y,n=this.z,u=this.w,p=u*e+k*h-n*f,v=u*f+n*e-m*h,t=u*h+m*f-k*e,e=-m*
|
||||
e-k*f-n*h;c.x=p*u+e*-m+v*-n-t*-k;c.y=v*u+e*-k+t*-m-p*-n;c.z=t*u+e*-n+p*-k-v*-m;return c}};THREE.Quaternion.slerp=function(b,c,e,f){var h=b.w*c.w+b.x*c.x+b.y*c.y+b.z*c.z;if(Math.abs(h)>=1)return e.w=b.w,e.x=b.x,e.y=b.y,e.z=b.z,e;var m=Math.acos(h),k=Math.sqrt(1-h*h);if(Math.abs(k)<0.0010)return e.w=0.5*(b.w+c.w),e.x=0.5*(b.x+c.x),e.y=0.5*(b.y+c.y),e.z=0.5*(b.z+c.z),e;h=Math.sin((1-f)*m)/k;f=Math.sin(f*m)/k;e.w=b.w*h+c.w*f;e.x=b.x*h+c.x*f;e.y=b.y*h+c.y*f;e.z=b.z*h+c.z*f;return e};
|
||||
e-k*f-n*h;c.x=p*u+e*-m+v*-n-t*-k;c.y=v*u+e*-k+t*-m-p*-n;c.z=t*u+e*-n+p*-k-v*-m;return c}};THREE.Quaternion.slerp=function(b,c,e,f){var h=b.w*c.w+b.x*c.x+b.y*c.y+b.z*c.z;if(Math.abs(h)>=1)return e.w=b.w,e.x=b.x,e.y=b.y,e.z=b.z,e;var m=Math.acos(h),k=Math.sqrt(1-h*h);if(Math.abs(k)<0.001)return e.w=0.5*(b.w+c.w),e.x=0.5*(b.x+c.x),e.y=0.5*(b.y+c.y),e.z=0.5*(b.z+c.z),e;h=Math.sin((1-f)*m)/k;f=Math.sin(f*m)/k;e.w=b.w*h+c.w*f;e.x=b.x*h+c.x*f;e.y=b.y*h+c.y*f;e.z=b.z*h+c.z*f;return e};
|
||||
THREE.Vertex=function(b){this.position=b||new THREE.Vector3};THREE.Face3=function(b,c,e,f,h,m){this.a=b;this.b=c;this.c=e;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.color=h instanceof THREE.Color?h:new THREE.Color;this.vertexColors=h instanceof Array?h:[];this.vertexTangents=[];this.materials=m instanceof Array?m:[m];this.centroid=new THREE.Vector3};
|
||||
THREE.Face4=function(b,c,e,f,h,m,k){this.a=b;this.b=c;this.c=e;this.d=f;this.normal=h instanceof THREE.Vector3?h:new THREE.Vector3;this.vertexNormals=h instanceof Array?h:[];this.color=m instanceof THREE.Color?m:new THREE.Color;this.vertexColors=m instanceof Array?m:[];this.vertexTangents=[];this.materials=k instanceof Array?k:[k];this.centroid=new THREE.Vector3};THREE.UV=function(b,c){this.u=b||0;this.v=c||0};
|
||||
THREE.UV.prototype={constructor:THREE.UV,set:function(b,c){this.u=b;this.v=c;return this},copy:function(b){this.u=b.u;this.v=b.v;return this},clone:function(){return new THREE.UV(this.u,this.v)}};
|
||||
@@ -428,7 +428,7 @@ this.getPrevKeyWith("pos",w,k.index-1).pos,this.points[1]=h,this.points[2]=m,thi
|
||||
THREE.Animation.prototype.interpolateCatmullRom=function(b,c){var e=[],f=[],h,m,k,n,u,p;h=(b.length-1)*c;m=Math.floor(h);h-=m;e[0]=m==0?m:m-1;e[1]=m;e[2]=m>b.length-2?m:m+1;e[3]=m>b.length-3?m:m+2;m=b[e[0]];n=b[e[1]];u=b[e[2]];p=b[e[3]];e=h*h;k=h*e;f[0]=this.interpolate(m[0],n[0],u[0],p[0],h,e,k);f[1]=this.interpolate(m[1],n[1],u[1],p[1],h,e,k);f[2]=this.interpolate(m[2],n[2],u[2],p[2],h,e,k);return f};
|
||||
THREE.Animation.prototype.interpolate=function(b,c,e,f,h,m,k){b=(e-b)*0.5;f=(f-c)*0.5;return(2*(c-e)+b+f)*k+(-3*(c-e)-2*b-f)*m+b*h+c};THREE.Animation.prototype.getNextKeyWith=function(b,c,e){var f=this.data.hierarchy[c].keys;for(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?e=e<f.length-1?e:f.length-1:e%=f.length;e<f.length;e++)if(f[e][b]!==void 0)return f[e];return this.data.hierarchy[c].keys[0]};
|
||||
THREE.Animation.prototype.getPrevKeyWith=function(b,c,e){for(var f=this.data.hierarchy[c].keys,e=this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?e>0?e:0:e>=0?e:e+f.length;e>=0;e--)if(f[e][b]!==void 0)return f[e];return this.data.hierarchy[c].keys[f.length-1]};
|
||||
THREE.FirstPersonCamera=function(b){function c(b,c){return function(){c.apply(b,arguments)}}THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.movementSpeed=1;this.lookSpeed=0.0050;this.noFly=!1;this.lookVertical=!0;this.autoForward=!1;this.activeLook=!0;this.heightSpeed=!1;this.heightCoef=1;this.heightMin=0;this.constrainVertical=!1;this.verticalMin=0;this.verticalMax=3.14;this.domElement=document;this.lastUpdate=(new Date).getTime();this.tdiff=0;if(b){if(b.movementSpeed!==void 0)this.movementSpeed=
|
||||
THREE.FirstPersonCamera=function(b){function c(b,c){return function(){c.apply(b,arguments)}}THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.movementSpeed=1;this.lookSpeed=0.005;this.noFly=!1;this.lookVertical=!0;this.autoForward=!1;this.activeLook=!0;this.heightSpeed=!1;this.heightCoef=1;this.heightMin=0;this.constrainVertical=!1;this.verticalMin=0;this.verticalMax=3.14;this.domElement=document;this.lastUpdate=(new Date).getTime();this.tdiff=0;if(b){if(b.movementSpeed!==void 0)this.movementSpeed=
|
||||
b.movementSpeed;if(b.lookSpeed!==void 0)this.lookSpeed=b.lookSpeed;if(b.noFly!==void 0)this.noFly=b.noFly;if(b.lookVertical!==void 0)this.lookVertical=b.lookVertical;if(b.autoForward!==void 0)this.autoForward=b.autoForward;if(b.activeLook!==void 0)this.activeLook=b.activeLook;if(b.heightSpeed!==void 0)this.heightSpeed=b.heightSpeed;if(b.heightCoef!==void 0)this.heightCoef=b.heightCoef;if(b.heightMin!==void 0)this.heightMin=b.heightMin;if(b.heightMax!==void 0)this.heightMax=b.heightMax;if(b.constrainVertical!==
|
||||
void 0)this.constrainVertical=b.constrainVertical;if(b.verticalMin!==void 0)this.verticalMin=b.verticalMin;if(b.verticalMax!==void 0)this.verticalMax=b.verticalMax;if(b.domElement!==void 0)this.domElement=b.domElement}this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=this.autoSpeedFactor=0;this.mouseDragOn=this.freeze=this.moveRight=this.moveLeft=this.moveBackward=this.moveForward=!1;this.domElement===document?(this.viewHalfX=window.innerWidth/2,this.viewHalfY=window.innerHeight/2):(this.viewHalfX=
|
||||
this.domElement.offsetWidth/2,this.viewHalfY=this.domElement.offsetHeight/2,this.domElement.setAttribute("tabindex",-1));this.onMouseDown=function(b){this.domElement!==document&&this.domElement.focus();b.preventDefault();b.stopPropagation();if(this.activeLook)switch(b.button){case 0:this.moveForward=!0;break;case 2:this.moveBackward=!0}this.mouseDragOn=!0};this.onMouseUp=function(b){b.preventDefault();b.stopPropagation();if(this.activeLook)switch(b.button){case 0:this.moveForward=!1;break;case 2:this.moveBackward=
|
||||
@@ -441,7 +441,7 @@ c*b);this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*Math.PI
|
||||
THREE.FirstPersonCamera.prototype.supr=THREE.Camera.prototype;THREE.FirstPersonCamera.prototype.translate=function(b,c){this.matrix.rotateAxis(c);if(this.noFly)c.y=0;this.position.addSelf(c.multiplyScalar(b));this.target.position.addSelf(c.multiplyScalar(b))};
|
||||
THREE.PathCamera=function(b){function c(b,e,c,f){var h={name:c,fps:0.6,length:f,hierarchy:[]},k,m=e.getControlPointsArray(),n=e.getLength(),u=m.length,D=0;k=u-1;e={parent:-1,keys:[]};e.keys[0]={time:0,pos:m[0],rot:[0,0,0,1],scl:[1,1,1]};e.keys[k]={time:f,pos:m[k],rot:[0,0,0,1],scl:[1,1,1]};for(k=1;k<u-1;k++)D=f*n.chunks[k]/n.total,e.keys[k]={time:D,pos:m[k]};h.hierarchy[0]=e;THREE.AnimationHandler.add(h);return new THREE.Animation(b,c,THREE.AnimationHandler.CATMULLROM_FORWARD,!1)}function e(b,e){var c,
|
||||
f,h=new THREE.Geometry;for(c=0;c<b.points.length*e;c++)f=c/(b.points.length*e),f=b.getPoint(f),h.vertices[c]=new THREE.Vertex(new THREE.Vector3(f.x,f.y,f.z));return h}function f(b,c){var f=e(c,10),h=e(c,10),k=new THREE.LineBasicMaterial({color:16711680,linewidth:3});lineObj=new THREE.Line(f,k);particleObj=new THREE.ParticleSystem(h,new THREE.ParticleBasicMaterial({color:16755200,size:3}));lineObj.scale.set(1,1,1);b.addChild(lineObj);particleObj.scale.set(1,1,1);b.addChild(particleObj);h=new THREE.SphereGeometry(1,
|
||||
16,8);k=new THREE.MeshBasicMaterial({color:65280});for(i=0;i<c.points.length;i++)f=new THREE.Mesh(h,k),f.position.copy(c.points[i]),f.updateMatrix(),b.addChild(f)}THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.id="PathCamera"+THREE.PathCameraIdCounter++;this.duration=1E4;this.waypoints=[];this.useConstantSpeed=!0;this.resamplingCoef=50;this.debugPath=new THREE.Object3D;this.debugDummy=new THREE.Object3D;this.animationParent=new THREE.Object3D;this.lookSpeed=0.0050;this.lookHorizontal=
|
||||
16,8);k=new THREE.MeshBasicMaterial({color:65280});for(i=0;i<c.points.length;i++)f=new THREE.Mesh(h,k),f.position.copy(c.points[i]),f.updateMatrix(),b.addChild(f)}THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.id="PathCamera"+THREE.PathCameraIdCounter++;this.duration=1E4;this.waypoints=[];this.useConstantSpeed=!0;this.resamplingCoef=50;this.debugPath=new THREE.Object3D;this.debugDummy=new THREE.Object3D;this.animationParent=new THREE.Object3D;this.lookSpeed=0.005;this.lookHorizontal=
|
||||
this.lookVertical=!0;this.verticalAngleMap={srcRange:[0,6.28],dstRange:[0,6.28]};this.horizontalAngleMap={srcRange:[0,6.28],dstRange:[0,6.28]};this.domElement=document;if(b){if(b.duration!==void 0)this.duration=b.duration*1E3;if(b.waypoints!==void 0)this.waypoints=b.waypoints;if(b.useConstantSpeed!==void 0)this.useConstantSpeed=b.useConstantSpeed;if(b.resamplingCoef!==void 0)this.resamplingCoef=b.resamplingCoef;if(b.createDebugPath!==void 0)this.createDebugPath=b.createDebugPath;if(b.createDebugDummy!==
|
||||
void 0)this.createDebugDummy=b.createDebugDummy;if(b.lookSpeed!==void 0)this.lookSpeed=b.lookSpeed;if(b.lookVertical!==void 0)this.lookVertical=b.lookVertical;if(b.lookHorizontal!==void 0)this.lookHorizontal=b.lookHorizontal;if(b.verticalAngleMap!==void 0)this.verticalAngleMap=b.verticalAngleMap;if(b.horizontalAngleMap!==void 0)this.horizontalAngleMap=b.horizontalAngleMap;if(b.domElement!==void 0)this.domElement=b.domElement}this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=0;this.domElement===
|
||||
document?(this.viewHalfX=window.innerWidth/2,this.viewHalfY=window.innerHeight/2):(this.viewHalfX=this.domElement.offsetWidth/2,this.viewHalfY=this.domElement.offsetHeight/2,this.domElement.setAttribute("tabindex",-1));var h=Math.PI*2,m=Math.PI/180;this.update=function(b,e,c){var f,k;this.lookHorizontal&&(this.lon+=this.mouseX*this.lookSpeed);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));this.phi=
|
||||
@@ -449,7 +449,7 @@ document?(this.viewHalfX=window.innerWidth/2,this.viewHalfY=window.innerHeight/2
|
||||
f.y=100*Math.cos(this.phi);f.z=100*Math.sin(this.phi)*Math.sin(this.theta);this.supr.update.call(this,b,e,c)};this.onMouseMove=function(b){this.domElement===document?(this.mouseX=b.pageX-this.viewHalfX,this.mouseY=b.pageY-this.viewHalfY):(this.mouseX=b.pageX-this.domElement.offsetLeft-this.viewHalfX,this.mouseY=b.pageY-this.domElement.offsetTop-this.viewHalfY)};this.spline=new THREE.Spline;this.spline.initFromArray(this.waypoints);this.useConstantSpeed&&this.spline.reparametrizeByArcLength(this.resamplingCoef);
|
||||
if(this.createDebugDummy){var b=new THREE.MeshLambertMaterial({color:30719}),k=new THREE.MeshLambertMaterial({color:65280}),n=new THREE.CubeGeometry(10,10,20),u=new THREE.CubeGeometry(2,2,10);this.animationParent=new THREE.Mesh(n,b);b=new THREE.Mesh(u,k);b.position.set(0,10,0);this.animation=c(this.animationParent,this.spline,this.id,this.duration);this.animationParent.addChild(this);this.animationParent.addChild(this.target);this.animationParent.addChild(b)}else this.animation=c(this.animationParent,
|
||||
this.spline,this.id,this.duration),this.animationParent.addChild(this.target),this.animationParent.addChild(this);this.createDebugPath&&f(this.debugPath,this.spline);this.domElement.addEventListener("mousemove",function(b,e){return function(){e.apply(b,arguments)}}(this,this.onMouseMove),!1)};THREE.PathCamera.prototype=new THREE.Camera;THREE.PathCamera.prototype.constructor=THREE.PathCamera;THREE.PathCamera.prototype.supr=THREE.Camera.prototype;THREE.PathCameraIdCounter=0;
|
||||
THREE.FlyCamera=function(b){function c(b,c){return function(){c.apply(b,arguments)}}THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.tmpQuaternion=new THREE.Quaternion;this.movementSpeed=1;this.rollSpeed=0.0050;this.autoForward=this.dragToLook=!1;this.domElement=document;if(b){if(b.movementSpeed!==void 0)this.movementSpeed=b.movementSpeed;if(b.rollSpeed!==void 0)this.rollSpeed=b.rollSpeed;if(b.dragToLook!==void 0)this.dragToLook=b.dragToLook;if(b.autoForward!==void 0)this.autoForward=
|
||||
THREE.FlyCamera=function(b){function c(b,c){return function(){c.apply(b,arguments)}}THREE.Camera.call(this,b.fov,b.aspect,b.near,b.far,b.target);this.tmpQuaternion=new THREE.Quaternion;this.movementSpeed=1;this.rollSpeed=0.005;this.autoForward=this.dragToLook=!1;this.domElement=document;if(b){if(b.movementSpeed!==void 0)this.movementSpeed=b.movementSpeed;if(b.rollSpeed!==void 0)this.rollSpeed=b.rollSpeed;if(b.dragToLook!==void 0)this.dragToLook=b.dragToLook;if(b.autoForward!==void 0)this.autoForward=
|
||||
b.autoForward;if(b.domElement!==void 0)this.domElement=b.domElement}this.useTarget=!1;this.useQuaternion=!0;this.mouseStatus=0;this.moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0};this.moveVector=new THREE.Vector3(0,0,0);this.rotationVector=new THREE.Vector3(0,0,0);this.lastUpdate=-1;this.tdiff=0;this.domElement!==document&&this.domElement.setAttribute("tabindex",-1);this.handleEvent=function(b){if(typeof this[b.type]=="function")this[b.type](b)};
|
||||
this.keydown=function(b){if(!b.altKey){switch(b.keyCode){case 16:this.movementSpeedMultiplier=0.1;break;case 87:this.moveState.forward=1;break;case 83:this.moveState.back=1;break;case 65:this.moveState.left=1;break;case 68:this.moveState.right=1;break;case 82:this.moveState.up=1;break;case 70:this.moveState.down=1;break;case 38:this.moveState.pitchUp=1;break;case 40:this.moveState.pitchDown=1;break;case 37:this.moveState.yawLeft=1;break;case 39:this.moveState.yawRight=1;break;case 81:this.moveState.rollLeft=
|
||||
1;break;case 69:this.moveState.rollRight=1}this.updateMovementVector();this.updateRotationVector()}};this.keyup=function(b){switch(b.keyCode){case 16:this.movementSpeedMultiplier=1;break;case 87:this.moveState.forward=0;break;case 83:this.moveState.back=0;break;case 65:this.moveState.left=0;break;case 68:this.moveState.right=0;break;case 82:this.moveState.up=0;break;case 70:this.moveState.down=0;break;case 38:this.moveState.pitchUp=0;break;case 40:this.moveState.pitchDown=0;break;case 37:this.moveState.yawLeft=
|
||||
@@ -498,7 +498,7 @@ THREE.ExtrudeGeometry.__v2=new THREE.Vector2;THREE.ExtrudeGeometry.__v3=new THRE
|
||||
THREE.IcosahedronGeometry=function(b){function c(b,c,e){var f=Math.sqrt(b*b+c*c+e*e);return h.vertices.push(new THREE.Vertex(new THREE.Vector3(b/f,c/f,e/f)))-1}function e(b,c,e,f){f.faces.push(new THREE.Face3(b,c,e))}function f(b,e){var f=h.vertices[b].position,k=h.vertices[e].position;return c((f.x+k.x)/2,(f.y+k.y)/2,(f.z+k.z)/2)}var h=this,m=new THREE.Geometry;this.subdivisions=b||0;THREE.Geometry.call(this);b=(1+Math.sqrt(5))/2;c(-1,b,0);c(1,b,0);c(-1,-b,0);c(1,-b,0);c(0,-1,b);c(0,1,b);c(0,-1,
|
||||
-b);c(0,1,-b);c(b,0,-1);c(b,0,1);c(-b,0,-1);c(-b,0,1);e(0,11,5,m);e(0,5,1,m);e(0,1,7,m);e(0,7,10,m);e(0,10,11,m);e(1,5,9,m);e(5,11,4,m);e(11,10,2,m);e(10,7,6,m);e(7,1,8,m);e(3,9,4,m);e(3,4,2,m);e(3,2,6,m);e(3,6,8,m);e(3,8,9,m);e(4,9,5,m);e(2,4,11,m);e(6,2,10,m);e(8,6,7,m);e(9,8,1,m);for(var k=0;k<this.subdivisions;k++){var b=new THREE.Geometry,n;for(n in m.faces){var u=f(m.faces[n].a,m.faces[n].b),p=f(m.faces[n].b,m.faces[n].c),v=f(m.faces[n].c,m.faces[n].a);e(m.faces[n].a,u,v,b);e(m.faces[n].b,p,
|
||||
u,b);e(m.faces[n].c,v,p,b);e(u,p,v,b)}m.faces=b.faces}h.faces=m.faces;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.IcosahedronGeometry.prototype=new THREE.Geometry;THREE.IcosahedronGeometry.prototype.constructor=THREE.IcosahedronGeometry;
|
||||
THREE.LatheGeometry=function(b,c,e){THREE.Geometry.call(this);this.steps=c||12;this.angle=e||2*Math.PI;for(var c=this.angle/this.steps,e=[],f=[],h=[],m=[],k=(new THREE.Matrix4).setRotationZ(c),n=0;n<b.length;n++)this.vertices.push(new THREE.Vertex(b[n])),e[n]=b[n].clone(),f[n]=this.vertices.length-1;for(var u=0;u<=this.angle+0.0010;u+=c){for(n=0;n<e.length;n++)u<this.angle?(e[n]=k.multiplyVector3(e[n].clone()),this.vertices.push(new THREE.Vertex(e[n])),h[n]=this.vertices.length-1):h=m;u==0&&(m=f);
|
||||
THREE.LatheGeometry=function(b,c,e){THREE.Geometry.call(this);this.steps=c||12;this.angle=e||2*Math.PI;for(var c=this.angle/this.steps,e=[],f=[],h=[],m=[],k=(new THREE.Matrix4).setRotationZ(c),n=0;n<b.length;n++)this.vertices.push(new THREE.Vertex(b[n])),e[n]=b[n].clone(),f[n]=this.vertices.length-1;for(var u=0;u<=this.angle+0.001;u+=c){for(n=0;n<e.length;n++)u<this.angle?(e[n]=k.multiplyVector3(e[n].clone()),this.vertices.push(new THREE.Vertex(e[n])),h[n]=this.vertices.length-1):h=m;u==0&&(m=f);
|
||||
for(n=0;n<f.length-1;n++)this.faces.push(new THREE.Face4(h[n],h[n+1],f[n+1],f[n])),this.faceVertexUvs[0].push([new THREE.UV(1-u/this.angle,n/b.length),new THREE.UV(1-u/this.angle,(n+1)/b.length),new THREE.UV(1-(u-c)/this.angle,(n+1)/b.length),new THREE.UV(1-(u-c)/this.angle,n/b.length)]);f=h;h=[]}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.LatheGeometry.prototype=new THREE.Geometry;THREE.LatheGeometry.prototype.constructor=THREE.LatheGeometry;
|
||||
THREE.PlaneGeometry=function(b,c,e,f){THREE.Geometry.call(this);var h,m=b/2,k=c/2,e=e||1,f=f||1,n=e+1,u=f+1;b/=e;var p=c/f;for(h=0;h<u;h++)for(c=0;c<n;c++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(c*b-m,-(h*p-k),0)));for(h=0;h<f;h++)for(c=0;c<e;c++)this.faces.push(new THREE.Face4(c+n*h,c+n*(h+1),c+1+n*(h+1),c+1+n*h)),this.faceVertexUvs[0].push([new THREE.UV(c/e,h/f),new THREE.UV(c/e,(h+1)/f),new THREE.UV((c+1)/e,(h+1)/f),new THREE.UV((c+1)/e,h/f)]);this.computeCentroids();this.computeFaceNormals()};
|
||||
THREE.PlaneGeometry.prototype=new THREE.Geometry;THREE.PlaneGeometry.prototype.constructor=THREE.PlaneGeometry;
|
||||
@@ -554,7 +554,7 @@ for(y=0;y<o.weights.length;y++)for(var z=0;z<o.weights[y].length;z++){var A=o.we
|
||||
e,k,m;c.name=b.id||"";c.matrixAutoUpdate=!1;c.matrix=b.matrix;for(m=0;m<b.controllers.length;m++){var n=da[b.controllers[m].url];switch(n.type){case "skin":if(qa[n.skin.source]){var o=new z;o.url=n.skin.source;o.instance_material=b.controllers[m].instance_material;b.geometries.push(o);e=b.controllers[m]}else if(da[n.skin.source]&&(k=n=da[n.skin.source],n.morph&&qa[n.morph.source]))o=new z,o.url=n.morph.source,o.instance_material=b.controllers[m].instance_material,b.geometries.push(o);break;case "morph":if(qa[n.morph.source])o=
|
||||
new z,o.url=n.morph.source,o.instance_material=b.controllers[m].instance_material,b.geometries.push(o),k=b.controllers[m];console.log("DAE: morph-controller partially supported.")}}for(m=0;m<b.geometries.length;m++){var n=b.geometries[m],o=n.instance_material,n=qa[n.url],p={},t=0,u;if(n&&n.mesh&&n.mesh.primitives){if(c.name.length==0)c.name=n.id;if(o)for(j=0;j<o.length;j++){u=o[j];var v=sa[ua[u.target].instance_effect.url].shader;v.material.opacity=!v.material.opacity?1:v.material.opacity;u=p[u.symbol]=
|
||||
v.material;t++}o=u||new THREE.MeshLambertMaterial({color:14540253,shading:THREE.FlatShading});n=n.mesh.geometry3js;if(t>1){o=new THREE.MeshFaceMaterial;for(j=0;j<n.faces.length;j++)t=n.faces[j],t.materials=[p[t.daeMaterial]]}if(e!==void 0)f(n,e),o.morphTargets=!0,o=new THREE.SkinnedMesh(n,o),o.skeleton=e.skeleton,o.skinController=da[e.url],o.skinInstanceController=e,o.name="skin_"+pa.length,pa.push(o);else if(k!==void 0){p=n;t=k instanceof x?da[k.url]:k;if(!t||!t.morph)console.log("could not find morph controller!");
|
||||
else{t=t.morph;for(v=0;v<t.targets.length;v++){var w=qa[t.targets[v]];if(w.mesh&&w.mesh.primitives&&w.mesh.primitives.length)w=w.mesh.primitives[0].geometry,w.vertices.length===p.vertices.length&&p.morphTargets.push({name:"target_1",vertices:w.vertices})}p.morphTargets.push({name:"target_Z",vertices:p.vertices})}o.morphTargets=!0;o=new THREE.Mesh(n,o);o.name="morph_"+Da.length;Da.push(o)}else o=new THREE.Mesh(n,o);c.addChild(o)}}for(m=0;m<b.nodes.length;m++)c.addChild(h(b.nodes[m],b));return c}function m(){this.init_from=
|
||||
else{t=t.morph;for(v=0;v<t.targets.length;v++){var w=qa[t.targets[v]];if(w.mesh&&w.mesh.primitives&&w.mesh.primitives.length)w=w.mesh.primitives[0].geometry,w.vertices.length===p.vertices.length&&p.morphTargets.push({name:"target_1",vertices:w.vertices})}p.morphTargets.push({name:"target_Z",vertices:p.vertices})}o.morphTargets=!0;o=new THREE.Mesh(n,o);o.name="morph_"+Da.length;Da.push(o)}else o=new THREE.Mesh(n,o);c.add(o)}}for(m=0;m<b.nodes.length;m++)c.add(h(b.nodes[m],b));return c}function m(){this.init_from=
|
||||
this.id=""}function k(){this.type=this.name=this.id="";this.morph=this.skin=null}function n(){this.weights=this.targets=this.source=this.method=null}function u(){this.source="";this.bindShapeMatrix=null;this.invBindMatrices=[];this.joints=[];this.weights=[]}function p(){this.name=this.id="";this.nodes=[];this.scene=new THREE.Object3D}function v(){this.sid=this.name=this.id="";this.nodes=[];this.controllers=[];this.transforms=[];this.geometries=[];this.channels=[];this.matrix=new THREE.Matrix4}function t(){this.type=
|
||||
this.sid="";this.data=[];this.matrix=new THREE.Matrix4}function x(){this.url="";this.skeleton=[];this.instance_material=[]}function w(){this.target=this.symbol=""}function z(){this.url="";this.instance_material=[]}function y(){this.id="";this.mesh=null}function A(b){this.geometry=b.id;this.primitives=[];this.geometry3js=this.vertices=null}function E(){}function D(){this.material="";this.count=0;this.inputs=[];this.vcount=null;this.p=[];this.geometry=new THREE.Geometry}function F(){this.source="";
|
||||
this.stride=this.count=0;this.params=[]}function G(){this.input={}}function N(){this.semantic="";this.offset=0;this.source="";this.set=0}function Q(b){this.id=b;this.type=null}function K(){this.name=this.id="";this.instance_effect=null}function H(){this.color=new THREE.Color(0);this.color.setRGB(Math.random(),Math.random(),Math.random());this.color.a=1;this.texcoord=this.texture=null}function M(b,c){this.type=b;this.effect=c;this.material=null}function X(b){this.effect=b;this.format=this.init_from=
|
||||
@@ -599,7 +599,7 @@ V.prototype.parse=function(b){this.source=b.getAttribute("source").replace(/^#/,
|
||||
this.inputs=[];for(var c=0;c<b.childNodes.length;c++){var e=b.childNodes[c];if(e.nodeType==1)switch(e.nodeName){case "input":this.inputs.push((new N).parse(e))}}return this};o.prototype.create=function(){for(var b=0;b<this.inputs.length;b++){var c=this.inputs[b],e=this.animation.source[c.source];switch(c.semantic){case "INPUT":this.input=e.read();break;case "OUTPUT":this.output=e.read();break;case "INTERPOLATION":this.interpolation=e.read();break;case "IN_TANGENT":break;case "OUT_TANGENT":break;default:console.log(c.semantic)}}this.duration=
|
||||
this.endTime=this.startTime=0;if(this.input.length){this.startTime=1E8;this.endTime=-1E8;for(b=0;b<this.input.length;b++)this.startTime=Math.min(this.startTime,this.input[b]),this.endTime=Math.max(this.endTime,this.input[b]);this.duration=this.endTime-this.startTime}};return{load:function(e,f){if(document.implementation&&document.implementation.createDocument){document.implementation.createDocument("http://www.collada.org/2005/11/COLLADASchema","COLLADA",null);e+="?rnd="+Math.random();var n=new XMLHttpRequest;
|
||||
n.overrideMimeType&&n.overrideMimeType("text/xml");n.onreadystatechange=function(){if(n.readyState==4&&(n.status==0||n.status==200)){ga=f;var o,t=e;Y=n.responseXML;o=ga;t!==void 0&&(t=t.split("/"),t.pop(),Ea=t.join("/")+"/");va=b("//dae:library_images/dae:image",m,"image");ua=b("//dae:library_materials/dae:material",K,"material");sa=b("//dae:library_effects/dae:effect",O,"effect");qa=b("//dae:library_geometries/dae:geometry",y,"geometry");da=b("//dae:library_controllers/dae:controller",k,"controller");
|
||||
J=b("//dae:library_animations/dae:animation",U,"animation");xa=b(".//dae:library_visual_scenes/dae:visual_scene",p,"visual_scene");Da=[];pa=[];(t=Y.evaluate(".//dae:scene/dae:instance_visual_scene",Y,S,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null).iterateNext())?(t=t.getAttribute("url").replace(/^#/,""),Z=xa[t]):Z=null;T=new THREE.Object3D;for(t=0;t<Z.nodes.length;t++)T.addChild(h(Z.nodes[t]));c();for(var u in J);u={scene:T,morphs:Da,skins:pa,dae:{images:va,materials:ua,effects:sa,geometries:qa,controllers:da,
|
||||
J=b("//dae:library_animations/dae:animation",U,"animation");xa=b(".//dae:library_visual_scenes/dae:visual_scene",p,"visual_scene");Da=[];pa=[];(t=Y.evaluate(".//dae:scene/dae:instance_visual_scene",Y,S,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null).iterateNext())?(t=t.getAttribute("url").replace(/^#/,""),Z=xa[t]):Z=null;T=new THREE.Object3D;for(t=0;t<Z.nodes.length;t++)T.add(h(Z.nodes[t]));c();for(var u in J);u={scene:T,morphs:Da,skins:pa,dae:{images:va,materials:ua,effects:sa,geometries:qa,controllers:da,
|
||||
animations:J,visualScenes:xa,scene:Z}};o&&o(u)}};n.open("GET",e,!0);n.send(null)}else alert("Don't know how to parse XML!")},setPreferredShading:function(b){Ga=b},applySkin:f,geometries:qa}};THREE.JSONLoader=function(b){THREE.Loader.call(this,b)};THREE.JSONLoader.prototype=new THREE.Loader;THREE.JSONLoader.prototype.constructor=THREE.JSONLoader;THREE.JSONLoader.prototype.supr=THREE.Loader.prototype;
|
||||
THREE.JSONLoader.prototype.load=function(b){var c=this,e=b.model,f=b.callback,h=b.texture_path?b.texture_path:this.extractUrlbase(e),b=new Worker(e);b.onmessage=function(b){c.createModel(b.data,f,h);c.onLoadComplete()};this.onLoadStart();b.postMessage((new Date).getTime())};
|
||||
THREE.JSONLoader.prototype.createModel=function(b,c,e){var f=new THREE.Geometry,h=b.scale!==void 0?1/b.scale:1;this.init_materials(f,b.materials,e);(function(c){if(b.version===void 0||b.version!=2)console.error("Deprecated file format.");else{var e,h,u,p,v,t,x,w,z,y,A,E,D,F,G=b.faces;t=b.vertices;var N=b.normals,Q=b.colors,K=0;for(e=0;e<b.uvs.length;e++)b.uvs[e].length&&K++;for(e=0;e<K;e++)f.faceUvs[e]=[],f.faceVertexUvs[e]=[];p=0;for(v=t.length;p<v;)x=new THREE.Vertex,x.position.x=t[p++]*c,x.position.y=
|
||||
|
||||
@@ -69,7 +69,7 @@ THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){t
|
||||
this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.n11+a.n22+a.n33))/2;this.x=Math.sqrt(Math.max(0,b+a.n11-a.n22-a.n33))/2;this.y=Math.sqrt(Math.max(0,b-a.n11+a.n22-a.n33))/2;this.z=Math.sqrt(Math.max(0,b-a.n11-a.n22+a.n33))/2;this.x=a.n32-a.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=a.n13-a.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.n21-a.n12<0?-Math.abs(this.z):Math.abs(this.z);
|
||||
this.normalize();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);a==0?this.w=this.z=this.y=this.x=0:(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,g=a.x,f=a.y,h=a.z,a=a.w;this.x=b*a+e*g+c*h-d*f;this.y=c*a+e*f+d*g-b*h;this.z=d*a+e*h+b*f-c*g;this.w=e*a-b*g-c*f-d*h;return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,g=this.x,f=this.y,h=this.z,l=this.w,j=l*c+f*e-h*d,n=l*d+h*c-g*e,i=l*e+g*d-f*c,c=-g*
|
||||
c-f*d-h*e;b.x=j*l+c*-g+n*-h-i*-f;b.y=n*l+c*-f+i*-g-j*-h;b.z=i*l+c*-h+j*-f-n*-g;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)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var g=Math.acos(e),f=Math.sqrt(1-e*e);if(Math.abs(f)<0.0010)return 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),c;e=Math.sin((1-d)*g)/f;d=Math.sin(d*g)/f;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};
|
||||
c-f*d-h*e;b.x=j*l+c*-g+n*-h-i*-f;b.y=n*l+c*-f+i*-g-j*-h;b.z=i*l+c*-h+j*-f-n*-g;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)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var g=Math.acos(e),f=Math.sqrt(1-e*e);if(Math.abs(f)<0.001)return 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),c;e=Math.sin((1-d)*g)/f;d=Math.sin(d*g)/f;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){this.position=a||new THREE.Vector3};THREE.Face3=function(a,b,c,d,e,g){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materials=g instanceof Array?g:[g];this.centroid=new THREE.Vector3};
|
||||
THREE.Face4=function(a,b,c,d,e,g,f){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=g instanceof THREE.Color?g:new THREE.Color;this.vertexColors=g instanceof Array?g:[];this.vertexTangents=[];this.materials=f instanceof Array?f:[f];this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
|
||||
THREE.UV.prototype={constructor:THREE.UV,set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.u=a.u;this.v=a.v;return this},clone:function(){return new THREE.UV(this.u,this.v)}};
|
||||
|
||||
@@ -69,7 +69,7 @@ THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){t
|
||||
this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.n11+a.n22+a.n33))/2;this.x=Math.sqrt(Math.max(0,b+a.n11-a.n22-a.n33))/2;this.y=Math.sqrt(Math.max(0,b-a.n11+a.n22-a.n33))/2;this.z=Math.sqrt(Math.max(0,b-a.n11-a.n22+a.n33))/2;this.x=a.n32-a.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=a.n13-a.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.n21-a.n12<0?-Math.abs(this.z):Math.abs(this.z);
|
||||
this.normalize();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);a==0?this.w=this.z=this.y=this.x=0:(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,g=a.x,f=a.y,h=a.z,a=a.w;this.x=b*a+e*g+c*h-d*f;this.y=c*a+e*f+d*g-b*h;this.z=d*a+e*h+b*f-c*g;this.w=e*a-b*g-c*f-d*h;return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,g=this.x,f=this.y,h=this.z,j=this.w,i=j*c+f*e-h*d,k=j*d+h*c-g*e,l=j*e+g*d-f*c,c=-g*
|
||||
c-f*d-h*e;b.x=i*j+c*-g+k*-h-l*-f;b.y=k*j+c*-f+l*-g-i*-h;b.z=l*j+c*-h+i*-f-k*-g;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)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var g=Math.acos(e),f=Math.sqrt(1-e*e);if(Math.abs(f)<0.0010)return 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),c;e=Math.sin((1-d)*g)/f;d=Math.sin(d*g)/f;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};
|
||||
c-f*d-h*e;b.x=i*j+c*-g+k*-h-l*-f;b.y=k*j+c*-f+l*-g-i*-h;b.z=l*j+c*-h+i*-f-k*-g;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)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var g=Math.acos(e),f=Math.sqrt(1-e*e);if(Math.abs(f)<0.001)return 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),c;e=Math.sin((1-d)*g)/f;d=Math.sin(d*g)/f;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){this.position=a||new THREE.Vector3};THREE.Face3=function(a,b,c,d,e,g){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materials=g instanceof Array?g:[g];this.centroid=new THREE.Vector3};
|
||||
THREE.Face4=function(a,b,c,d,e,g,f){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=g instanceof THREE.Color?g:new THREE.Color;this.vertexColors=g instanceof Array?g:[];this.vertexTangents=[];this.materials=f instanceof Array?f:[f];this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
|
||||
THREE.UV.prototype={constructor:THREE.UV,set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.u=a.u;this.v=a.v;return this},clone:function(){return new THREE.UV(this.u,this.v)}};THREE.Camera=function(a,b,c,d,e){THREE.Object3D.call(this);this.fov=a||50;this.aspect=b||1;this.near=c!==void 0?c:0.1;this.far=d!==void 0?d:2E3;this.target=e||new THREE.Object3D;this.useTarget=!0;this.matrixWorldInverse=new THREE.Matrix4;this.projectionMatrix=null;this.updateProjectionMatrix()};
|
||||
|
||||
@@ -81,7 +81,7 @@ this.getPrevKeyWith("pos",p,f.index-1).pos,this.points[1]=g,this.points[2]=h,thi
|
||||
THREE.Animation.prototype.interpolateCatmullRom=function(a,b){var c=[],e=[],g,h,f,k,l,m;g=(a.length-1)*b;h=Math.floor(g);g-=h;c[0]=h==0?h:h-1;c[1]=h;c[2]=h>a.length-2?h:h+1;c[3]=h>a.length-3?h:h+2;h=a[c[0]];k=a[c[1]];l=a[c[2]];m=a[c[3]];c=g*g;f=g*c;e[0]=this.interpolate(h[0],k[0],l[0],m[0],g,c,f);e[1]=this.interpolate(h[1],k[1],l[1],m[1],g,c,f);e[2]=this.interpolate(h[2],k[2],l[2],m[2],g,c,f);return e};
|
||||
THREE.Animation.prototype.interpolate=function(a,b,c,e,g,h,f){a=(c-a)*0.5;e=(e-b)*0.5;return(2*(b-c)+a+e)*f+(-3*(b-c)-2*a-e)*h+a*g+b};THREE.Animation.prototype.getNextKeyWith=function(a,b,c){var e=this.data.hierarchy[b].keys;for(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?c=c<e.length-1?c:e.length-1:c%=e.length;c<e.length;c++)if(e[c][a]!==void 0)return e[c];return this.data.hierarchy[b].keys[0]};
|
||||
THREE.Animation.prototype.getPrevKeyWith=function(a,b,c){for(var e=this.data.hierarchy[b].keys,c=this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?c>0?c:0:c>=0?c:c+e.length;c>=0;c--)if(e[c][a]!==void 0)return e[c];return this.data.hierarchy[b].keys[e.length-1]};
|
||||
THREE.FirstPersonCamera=function(a){function b(a,b){return function(){b.apply(a,arguments)}}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.movementSpeed=1;this.lookSpeed=0.0050;this.noFly=!1;this.lookVertical=!0;this.autoForward=!1;this.activeLook=!0;this.heightSpeed=!1;this.heightCoef=1;this.heightMin=0;this.constrainVertical=!1;this.verticalMin=0;this.verticalMax=3.14;this.domElement=document;this.lastUpdate=(new Date).getTime();this.tdiff=0;if(a){if(a.movementSpeed!==void 0)this.movementSpeed=
|
||||
THREE.FirstPersonCamera=function(a){function b(a,b){return function(){b.apply(a,arguments)}}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.movementSpeed=1;this.lookSpeed=0.005;this.noFly=!1;this.lookVertical=!0;this.autoForward=!1;this.activeLook=!0;this.heightSpeed=!1;this.heightCoef=1;this.heightMin=0;this.constrainVertical=!1;this.verticalMin=0;this.verticalMax=3.14;this.domElement=document;this.lastUpdate=(new Date).getTime();this.tdiff=0;if(a){if(a.movementSpeed!==void 0)this.movementSpeed=
|
||||
a.movementSpeed;if(a.lookSpeed!==void 0)this.lookSpeed=a.lookSpeed;if(a.noFly!==void 0)this.noFly=a.noFly;if(a.lookVertical!==void 0)this.lookVertical=a.lookVertical;if(a.autoForward!==void 0)this.autoForward=a.autoForward;if(a.activeLook!==void 0)this.activeLook=a.activeLook;if(a.heightSpeed!==void 0)this.heightSpeed=a.heightSpeed;if(a.heightCoef!==void 0)this.heightCoef=a.heightCoef;if(a.heightMin!==void 0)this.heightMin=a.heightMin;if(a.heightMax!==void 0)this.heightMax=a.heightMax;if(a.constrainVertical!==
|
||||
void 0)this.constrainVertical=a.constrainVertical;if(a.verticalMin!==void 0)this.verticalMin=a.verticalMin;if(a.verticalMax!==void 0)this.verticalMax=a.verticalMax;if(a.domElement!==void 0)this.domElement=a.domElement}this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=this.autoSpeedFactor=0;this.mouseDragOn=this.freeze=this.moveRight=this.moveLeft=this.moveBackward=this.moveForward=!1;this.domElement===document?(this.viewHalfX=window.innerWidth/2,this.viewHalfY=window.innerHeight/2):(this.viewHalfX=
|
||||
this.domElement.offsetWidth/2,this.viewHalfY=this.domElement.offsetHeight/2,this.domElement.setAttribute("tabindex",-1));this.onMouseDown=function(a){this.domElement!==document&&this.domElement.focus();a.preventDefault();a.stopPropagation();if(this.activeLook)switch(a.button){case 0:this.moveForward=!0;break;case 2:this.moveBackward=!0}this.mouseDragOn=!0};this.onMouseUp=function(a){a.preventDefault();a.stopPropagation();if(this.activeLook)switch(a.button){case 0:this.moveForward=!1;break;case 2:this.moveBackward=
|
||||
@@ -94,7 +94,7 @@ b*a);this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*Math.PI
|
||||
THREE.FirstPersonCamera.prototype.supr=THREE.Camera.prototype;THREE.FirstPersonCamera.prototype.translate=function(a,b){this.matrix.rotateAxis(b);if(this.noFly)b.y=0;this.position.addSelf(b.multiplyScalar(a));this.target.position.addSelf(b.multiplyScalar(a))};
|
||||
THREE.PathCamera=function(a){function b(a,c,b,e){var f={name:b,fps:0.6,length:e,hierarchy:[]},h,g=c.getControlPointsArray(),k=c.getLength(),l=g.length,y=0;h=l-1;c={parent:-1,keys:[]};c.keys[0]={time:0,pos:g[0],rot:[0,0,0,1],scl:[1,1,1]};c.keys[h]={time:e,pos:g[h],rot:[0,0,0,1],scl:[1,1,1]};for(h=1;h<l-1;h++)y=e*k.chunks[h]/k.total,c.keys[h]={time:y,pos:g[h]};f.hierarchy[0]=c;THREE.AnimationHandler.add(f);return new THREE.Animation(a,b,THREE.AnimationHandler.CATMULLROM_FORWARD,!1)}function c(a,c){var b,
|
||||
e,f=new THREE.Geometry;for(b=0;b<a.points.length*c;b++)e=b/(a.points.length*c),e=a.getPoint(e),f.vertices[b]=new THREE.Vertex(new THREE.Vector3(e.x,e.y,e.z));return f}function e(a,b){var e=c(b,10),f=c(b,10),h=new THREE.LineBasicMaterial({color:16711680,linewidth:3});lineObj=new THREE.Line(e,h);particleObj=new THREE.ParticleSystem(f,new THREE.ParticleBasicMaterial({color:16755200,size:3}));lineObj.scale.set(1,1,1);a.addChild(lineObj);particleObj.scale.set(1,1,1);a.addChild(particleObj);f=new THREE.SphereGeometry(1,
|
||||
16,8);h=new THREE.MeshBasicMaterial({color:65280});for(i=0;i<b.points.length;i++)e=new THREE.Mesh(f,h),e.position.copy(b.points[i]),e.updateMatrix(),a.addChild(e)}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.id="PathCamera"+THREE.PathCameraIdCounter++;this.duration=1E4;this.waypoints=[];this.useConstantSpeed=!0;this.resamplingCoef=50;this.debugPath=new THREE.Object3D;this.debugDummy=new THREE.Object3D;this.animationParent=new THREE.Object3D;this.lookSpeed=0.0050;this.lookHorizontal=
|
||||
16,8);h=new THREE.MeshBasicMaterial({color:65280});for(i=0;i<b.points.length;i++)e=new THREE.Mesh(f,h),e.position.copy(b.points[i]),e.updateMatrix(),a.addChild(e)}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.id="PathCamera"+THREE.PathCameraIdCounter++;this.duration=1E4;this.waypoints=[];this.useConstantSpeed=!0;this.resamplingCoef=50;this.debugPath=new THREE.Object3D;this.debugDummy=new THREE.Object3D;this.animationParent=new THREE.Object3D;this.lookSpeed=0.005;this.lookHorizontal=
|
||||
this.lookVertical=!0;this.verticalAngleMap={srcRange:[0,6.28],dstRange:[0,6.28]};this.horizontalAngleMap={srcRange:[0,6.28],dstRange:[0,6.28]};this.domElement=document;if(a){if(a.duration!==void 0)this.duration=a.duration*1E3;if(a.waypoints!==void 0)this.waypoints=a.waypoints;if(a.useConstantSpeed!==void 0)this.useConstantSpeed=a.useConstantSpeed;if(a.resamplingCoef!==void 0)this.resamplingCoef=a.resamplingCoef;if(a.createDebugPath!==void 0)this.createDebugPath=a.createDebugPath;if(a.createDebugDummy!==
|
||||
void 0)this.createDebugDummy=a.createDebugDummy;if(a.lookSpeed!==void 0)this.lookSpeed=a.lookSpeed;if(a.lookVertical!==void 0)this.lookVertical=a.lookVertical;if(a.lookHorizontal!==void 0)this.lookHorizontal=a.lookHorizontal;if(a.verticalAngleMap!==void 0)this.verticalAngleMap=a.verticalAngleMap;if(a.horizontalAngleMap!==void 0)this.horizontalAngleMap=a.horizontalAngleMap;if(a.domElement!==void 0)this.domElement=a.domElement}this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=0;this.domElement===
|
||||
document?(this.viewHalfX=window.innerWidth/2,this.viewHalfY=window.innerHeight/2):(this.viewHalfX=this.domElement.offsetWidth/2,this.viewHalfY=this.domElement.offsetHeight/2,this.domElement.setAttribute("tabindex",-1));var g=Math.PI*2,h=Math.PI/180;this.update=function(a,c,b){var e,f;this.lookHorizontal&&(this.lon+=this.mouseX*this.lookSpeed);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));this.phi=
|
||||
@@ -102,7 +102,7 @@ document?(this.viewHalfX=window.innerWidth/2,this.viewHalfY=window.innerHeight/2
|
||||
e.y=100*Math.cos(this.phi);e.z=100*Math.sin(this.phi)*Math.sin(this.theta);this.supr.update.call(this,a,c,b)};this.onMouseMove=function(a){this.domElement===document?(this.mouseX=a.pageX-this.viewHalfX,this.mouseY=a.pageY-this.viewHalfY):(this.mouseX=a.pageX-this.domElement.offsetLeft-this.viewHalfX,this.mouseY=a.pageY-this.domElement.offsetTop-this.viewHalfY)};this.spline=new THREE.Spline;this.spline.initFromArray(this.waypoints);this.useConstantSpeed&&this.spline.reparametrizeByArcLength(this.resamplingCoef);
|
||||
if(this.createDebugDummy){var a=new THREE.MeshLambertMaterial({color:30719}),f=new THREE.MeshLambertMaterial({color:65280}),k=new THREE.CubeGeometry(10,10,20),l=new THREE.CubeGeometry(2,2,10);this.animationParent=new THREE.Mesh(k,a);a=new THREE.Mesh(l,f);a.position.set(0,10,0);this.animation=b(this.animationParent,this.spline,this.id,this.duration);this.animationParent.addChild(this);this.animationParent.addChild(this.target);this.animationParent.addChild(a)}else this.animation=b(this.animationParent,
|
||||
this.spline,this.id,this.duration),this.animationParent.addChild(this.target),this.animationParent.addChild(this);this.createDebugPath&&e(this.debugPath,this.spline);this.domElement.addEventListener("mousemove",function(a,c){return function(){c.apply(a,arguments)}}(this,this.onMouseMove),!1)};THREE.PathCamera.prototype=new THREE.Camera;THREE.PathCamera.prototype.constructor=THREE.PathCamera;THREE.PathCamera.prototype.supr=THREE.Camera.prototype;THREE.PathCameraIdCounter=0;
|
||||
THREE.FlyCamera=function(a){function b(a,b){return function(){b.apply(a,arguments)}}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.tmpQuaternion=new THREE.Quaternion;this.movementSpeed=1;this.rollSpeed=0.0050;this.autoForward=this.dragToLook=!1;this.domElement=document;if(a){if(a.movementSpeed!==void 0)this.movementSpeed=a.movementSpeed;if(a.rollSpeed!==void 0)this.rollSpeed=a.rollSpeed;if(a.dragToLook!==void 0)this.dragToLook=a.dragToLook;if(a.autoForward!==void 0)this.autoForward=
|
||||
THREE.FlyCamera=function(a){function b(a,b){return function(){b.apply(a,arguments)}}THREE.Camera.call(this,a.fov,a.aspect,a.near,a.far,a.target);this.tmpQuaternion=new THREE.Quaternion;this.movementSpeed=1;this.rollSpeed=0.005;this.autoForward=this.dragToLook=!1;this.domElement=document;if(a){if(a.movementSpeed!==void 0)this.movementSpeed=a.movementSpeed;if(a.rollSpeed!==void 0)this.rollSpeed=a.rollSpeed;if(a.dragToLook!==void 0)this.dragToLook=a.dragToLook;if(a.autoForward!==void 0)this.autoForward=
|
||||
a.autoForward;if(a.domElement!==void 0)this.domElement=a.domElement}this.useTarget=!1;this.useQuaternion=!0;this.mouseStatus=0;this.moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0};this.moveVector=new THREE.Vector3(0,0,0);this.rotationVector=new THREE.Vector3(0,0,0);this.lastUpdate=-1;this.tdiff=0;this.domElement!==document&&this.domElement.setAttribute("tabindex",-1);this.handleEvent=function(a){if(typeof this[a.type]=="function")this[a.type](a)};
|
||||
this.keydown=function(a){if(!a.altKey){switch(a.keyCode){case 16:this.movementSpeedMultiplier=0.1;break;case 87:this.moveState.forward=1;break;case 83:this.moveState.back=1;break;case 65:this.moveState.left=1;break;case 68:this.moveState.right=1;break;case 82:this.moveState.up=1;break;case 70:this.moveState.down=1;break;case 38:this.moveState.pitchUp=1;break;case 40:this.moveState.pitchDown=1;break;case 37:this.moveState.yawLeft=1;break;case 39:this.moveState.yawRight=1;break;case 81:this.moveState.rollLeft=
|
||||
1;break;case 69:this.moveState.rollRight=1}this.updateMovementVector();this.updateRotationVector()}};this.keyup=function(a){switch(a.keyCode){case 16:this.movementSpeedMultiplier=1;break;case 87:this.moveState.forward=0;break;case 83:this.moveState.back=0;break;case 65:this.moveState.left=0;break;case 68:this.moveState.right=0;break;case 82:this.moveState.up=0;break;case 70:this.moveState.down=0;break;case 38:this.moveState.pitchUp=0;break;case 40:this.moveState.pitchDown=0;break;case 37:this.moveState.yawLeft=
|
||||
@@ -151,7 +151,7 @@ THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THRE
|
||||
THREE.IcosahedronGeometry=function(a){function b(a,c,b){var e=Math.sqrt(a*a+c*c+b*b);return g.vertices.push(new THREE.Vertex(new THREE.Vector3(a/e,c/e,b/e)))-1}function c(a,c,b,e){e.faces.push(new THREE.Face3(a,c,b))}function e(a,c){var e=g.vertices[a].position,f=g.vertices[c].position;return b((e.x+f.x)/2,(e.y+f.y)/2,(e.z+f.z)/2)}var g=this,h=new THREE.Geometry;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;b(-1,a,0);b(1,a,0);b(-1,-a,0);b(1,-a,0);b(0,-1,a);b(0,1,a);b(0,-1,
|
||||
-a);b(0,1,-a);b(a,0,-1);b(a,0,1);b(-a,0,-1);b(-a,0,1);c(0,11,5,h);c(0,5,1,h);c(0,1,7,h);c(0,7,10,h);c(0,10,11,h);c(1,5,9,h);c(5,11,4,h);c(11,10,2,h);c(10,7,6,h);c(7,1,8,h);c(3,9,4,h);c(3,4,2,h);c(3,2,6,h);c(3,6,8,h);c(3,8,9,h);c(4,9,5,h);c(2,4,11,h);c(6,2,10,h);c(8,6,7,h);c(9,8,1,h);for(var f=0;f<this.subdivisions;f++){var a=new THREE.Geometry,k;for(k in h.faces){var l=e(h.faces[k].a,h.faces[k].b),m=e(h.faces[k].b,h.faces[k].c),n=e(h.faces[k].c,h.faces[k].a);c(h.faces[k].a,l,n,a);c(h.faces[k].b,m,
|
||||
l,a);c(h.faces[k].c,n,m,a);c(l,m,n,a)}h.faces=a.faces}g.faces=h.faces;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.IcosahedronGeometry.prototype=new THREE.Geometry;THREE.IcosahedronGeometry.prototype.constructor=THREE.IcosahedronGeometry;
|
||||
THREE.LatheGeometry=function(a,b,c){THREE.Geometry.call(this);this.steps=b||12;this.angle=c||2*Math.PI;for(var b=this.angle/this.steps,c=[],e=[],g=[],h=[],f=(new THREE.Matrix4).setRotationZ(b),k=0;k<a.length;k++)this.vertices.push(new THREE.Vertex(a[k])),c[k]=a[k].clone(),e[k]=this.vertices.length-1;for(var l=0;l<=this.angle+0.0010;l+=b){for(k=0;k<c.length;k++)l<this.angle?(c[k]=f.multiplyVector3(c[k].clone()),this.vertices.push(new THREE.Vertex(c[k])),g[k]=this.vertices.length-1):g=h;l==0&&(h=e);
|
||||
THREE.LatheGeometry=function(a,b,c){THREE.Geometry.call(this);this.steps=b||12;this.angle=c||2*Math.PI;for(var b=this.angle/this.steps,c=[],e=[],g=[],h=[],f=(new THREE.Matrix4).setRotationZ(b),k=0;k<a.length;k++)this.vertices.push(new THREE.Vertex(a[k])),c[k]=a[k].clone(),e[k]=this.vertices.length-1;for(var l=0;l<=this.angle+0.001;l+=b){for(k=0;k<c.length;k++)l<this.angle?(c[k]=f.multiplyVector3(c[k].clone()),this.vertices.push(new THREE.Vertex(c[k])),g[k]=this.vertices.length-1):g=h;l==0&&(h=e);
|
||||
for(k=0;k<e.length-1;k++)this.faces.push(new THREE.Face4(g[k],g[k+1],e[k+1],e[k])),this.faceVertexUvs[0].push([new THREE.UV(1-l/this.angle,k/a.length),new THREE.UV(1-l/this.angle,(k+1)/a.length),new THREE.UV(1-(l-b)/this.angle,(k+1)/a.length),new THREE.UV(1-(l-b)/this.angle,k/a.length)]);e=g;g=[]}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.LatheGeometry.prototype=new THREE.Geometry;THREE.LatheGeometry.prototype.constructor=THREE.LatheGeometry;
|
||||
THREE.PlaneGeometry=function(a,b,c,e){THREE.Geometry.call(this);var g,h=a/2,f=b/2,c=c||1,e=e||1,k=c+1,l=e+1;a/=c;var m=b/e;for(g=0;g<l;g++)for(b=0;b<k;b++)this.vertices.push(new THREE.Vertex(new THREE.Vector3(b*a-h,-(g*m-f),0)));for(g=0;g<e;g++)for(b=0;b<c;b++)this.faces.push(new THREE.Face4(b+k*g,b+k*(g+1),b+1+k*(g+1),b+1+k*g)),this.faceVertexUvs[0].push([new THREE.UV(b/c,g/e),new THREE.UV(b/c,(g+1)/e),new THREE.UV((b+1)/c,(g+1)/e),new THREE.UV((b+1)/c,g/e)]);this.computeCentroids();this.computeFaceNormals()};
|
||||
THREE.PlaneGeometry.prototype=new THREE.Geometry;THREE.PlaneGeometry.prototype.constructor=THREE.PlaneGeometry;
|
||||
@@ -207,7 +207,7 @@ for(u=0;u<l.weights.length;u++)for(var x=0;x<l.weights[u].length;x++){var w=l.we
|
||||
b,f,h;c.name=a.id||"";c.matrixAutoUpdate=!1;c.matrix=a.matrix;for(h=0;h<a.controllers.length;h++){var k=aa[a.controllers[h].url];switch(k.type){case "skin":if(ba[k.skin.source]){var l=new x;l.url=k.skin.source;l.instance_material=a.controllers[h].instance_material;a.geometries.push(l);b=a.controllers[h]}else if(aa[k.skin.source]&&(f=k=aa[k.skin.source],k.morph&&ba[k.morph.source]))l=new x,l.url=k.morph.source,l.instance_material=a.controllers[h].instance_material,a.geometries.push(l);break;case "morph":if(ba[k.morph.source])l=
|
||||
new x,l.url=k.morph.source,l.instance_material=a.controllers[h].instance_material,a.geometries.push(l),f=a.controllers[h];console.log("DAE: morph-controller partially supported.")}}for(h=0;h<a.geometries.length;h++){var k=a.geometries[h],l=k.instance_material,k=ba[k.url],m={},n=0,o;if(k&&k.mesh&&k.mesh.primitives){if(c.name.length==0)c.name=k.id;if(l)for(j=0;j<l.length;j++){o=l[j];var p=ga[fa[o.target].instance_effect.url].shader;p.material.opacity=!p.material.opacity?1:p.material.opacity;o=m[o.symbol]=
|
||||
p.material;n++}l=o||new THREE.MeshLambertMaterial({color:14540253,shading:THREE.FlatShading});k=k.mesh.geometry3js;if(n>1){l=new THREE.MeshFaceMaterial;for(j=0;j<k.faces.length;j++)n=k.faces[j],n.materials=[m[n.daeMaterial]]}if(b!==void 0)e(k,b),l.morphTargets=!0,l=new THREE.SkinnedMesh(k,l),l.skeleton=b.skeleton,l.skinController=aa[b.url],l.skinInstanceController=b,l.name="skin_"+ea.length,ea.push(l);else if(f!==void 0){m=k;n=f instanceof t?aa[f.url]:f;if(!n||!n.morph)console.log("could not find morph controller!");
|
||||
else{n=n.morph;for(p=0;p<n.targets.length;p++){var u=ba[n.targets[p]];if(u.mesh&&u.mesh.primitives&&u.mesh.primitives.length)u=u.mesh.primitives[0].geometry,u.vertices.length===m.vertices.length&&m.morphTargets.push({name:"target_1",vertices:u.vertices})}m.morphTargets.push({name:"target_Z",vertices:m.vertices})}l.morphTargets=!0;l=new THREE.Mesh(k,l);l.name="morph_"+da.length;da.push(l)}else l=new THREE.Mesh(k,l);c.addChild(l)}}for(h=0;h<a.nodes.length;h++)c.addChild(g(a.nodes[h],a));return c}function h(){this.init_from=
|
||||
else{n=n.morph;for(p=0;p<n.targets.length;p++){var u=ba[n.targets[p]];if(u.mesh&&u.mesh.primitives&&u.mesh.primitives.length)u=u.mesh.primitives[0].geometry,u.vertices.length===m.vertices.length&&m.morphTargets.push({name:"target_1",vertices:u.vertices})}m.morphTargets.push({name:"target_Z",vertices:m.vertices})}l.morphTargets=!0;l=new THREE.Mesh(k,l);l.name="morph_"+da.length;da.push(l)}else l=new THREE.Mesh(k,l);c.add(l)}}for(h=0;h<a.nodes.length;h++)c.add(g(a.nodes[h],a));return c}function h(){this.init_from=
|
||||
this.id=""}function f(){this.type=this.name=this.id="";this.morph=this.skin=null}function k(){this.weights=this.targets=this.source=this.method=null}function l(){this.source="";this.bindShapeMatrix=null;this.invBindMatrices=[];this.joints=[];this.weights=[]}function m(){this.name=this.id="";this.nodes=[];this.scene=new THREE.Object3D}function n(){this.sid=this.name=this.id="";this.nodes=[];this.controllers=[];this.transforms=[];this.geometries=[];this.channels=[];this.matrix=new THREE.Matrix4}function o(){this.type=
|
||||
this.sid="";this.data=[];this.matrix=new THREE.Matrix4}function t(){this.url="";this.skeleton=[];this.instance_material=[]}function p(){this.target=this.symbol=""}function x(){this.url="";this.instance_material=[]}function v(){this.id="";this.mesh=null}function u(a){this.geometry=a.id;this.primitives=[];this.geometry3js=this.vertices=null}function z(){}function y(){this.material="";this.count=0;this.inputs=[];this.vcount=null;this.p=[];this.geometry=new THREE.Geometry}function w(){this.source="";
|
||||
this.stride=this.count=0;this.params=[]}function A(){this.input={}}function C(){this.semantic="";this.offset=0;this.source="";this.set=0}function F(a){this.id=a;this.type=null}function G(){this.name=this.id="";this.instance_effect=null}function I(){this.color=new THREE.Color(0);this.color.setRGB(Math.random(),Math.random(),Math.random());this.color.a=1;this.texcoord=this.texture=null}function H(a,c){this.type=a;this.effect=c;this.material=null}function M(a){this.effect=a;this.format=this.init_from=
|
||||
@@ -252,7 +252,7 @@ N.prototype.parse=function(a){this.source=a.getAttribute("source").replace(/^#/,
|
||||
this.inputs=[];for(var c=0;c<a.childNodes.length;c++){var b=a.childNodes[c];if(b.nodeType==1)switch(b.nodeName){case "input":this.inputs.push((new C).parse(b))}}return this};K.prototype.create=function(){for(var a=0;a<this.inputs.length;a++){var c=this.inputs[a],b=this.animation.source[c.source];switch(c.semantic){case "INPUT":this.input=b.read();break;case "OUTPUT":this.output=b.read();break;case "INTERPOLATION":this.interpolation=b.read();break;case "IN_TANGENT":break;case "OUT_TANGENT":break;default:console.log(c.semantic)}}this.duration=
|
||||
this.endTime=this.startTime=0;if(this.input.length){this.startTime=1E8;this.endTime=-1E8;for(a=0;a<this.input.length;a++)this.startTime=Math.min(this.startTime,this.input[a]),this.endTime=Math.max(this.endTime,this.input[a]);this.duration=this.endTime-this.startTime}};return{load:function(c,e){if(document.implementation&&document.implementation.createDocument){document.implementation.createDocument("http://www.collada.org/2005/11/COLLADASchema","COLLADA",null);c+="?rnd="+Math.random();var k=new XMLHttpRequest;
|
||||
k.overrideMimeType&&k.overrideMimeType("text/xml");k.onreadystatechange=function(){if(k.readyState==4&&(k.status==0||k.status==200)){$=e;var l,n=c;Q=k.responseXML;l=$;n!==void 0&&(n=n.split("/"),n.pop(),ja=n.join("/")+"/");Y=a("//dae:library_images/dae:image",h,"image");fa=a("//dae:library_materials/dae:material",G,"material");ga=a("//dae:library_effects/dae:effect",D,"effect");ba=a("//dae:library_geometries/dae:geometry",v,"geometry");aa=a("//dae:library_controllers/dae:controller",f,"controller");
|
||||
ca=a("//dae:library_animations/dae:animation",L,"animation");ha=a(".//dae:library_visual_scenes/dae:visual_scene",m,"visual_scene");da=[];ea=[];(n=Q.evaluate(".//dae:scene/dae:instance_visual_scene",Q,E,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null).iterateNext())?(n=n.getAttribute("url").replace(/^#/,""),W=ha[n]):W=null;Z=new THREE.Object3D;for(n=0;n<W.nodes.length;n++)Z.addChild(g(W.nodes[n]));b();for(var o in ca);o={scene:Z,morphs:da,skins:ea,dae:{images:Y,materials:fa,effects:ga,geometries:ba,controllers:aa,
|
||||
ca=a("//dae:library_animations/dae:animation",L,"animation");ha=a(".//dae:library_visual_scenes/dae:visual_scene",m,"visual_scene");da=[];ea=[];(n=Q.evaluate(".//dae:scene/dae:instance_visual_scene",Q,E,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null).iterateNext())?(n=n.getAttribute("url").replace(/^#/,""),W=ha[n]):W=null;Z=new THREE.Object3D;for(n=0;n<W.nodes.length;n++)Z.add(g(W.nodes[n]));b();for(var o in ca);o={scene:Z,morphs:da,skins:ea,dae:{images:Y,materials:fa,effects:ga,geometries:ba,controllers:aa,
|
||||
animations:ca,visualScenes:ha,scene:W}};l&&l(o)}};k.open("GET",c,!0);k.send(null)}else alert("Don't know how to parse XML!")},setPreferredShading:function(a){ka=a},applySkin:e,geometries:ba}};THREE.JSONLoader=function(a){THREE.Loader.call(this,a)};THREE.JSONLoader.prototype=new THREE.Loader;THREE.JSONLoader.prototype.constructor=THREE.JSONLoader;THREE.JSONLoader.prototype.supr=THREE.Loader.prototype;
|
||||
THREE.JSONLoader.prototype.load=function(a){var b=this,c=a.model,e=a.callback,g=a.texture_path?a.texture_path:this.extractUrlbase(c),a=new Worker(c);a.onmessage=function(a){b.createModel(a.data,e,g);b.onLoadComplete()};this.onLoadStart();a.postMessage((new Date).getTime())};
|
||||
THREE.JSONLoader.prototype.createModel=function(a,b,c){var e=new THREE.Geometry,g=a.scale!==void 0?1/a.scale:1;this.init_materials(e,a.materials,c);(function(c){if(a.version===void 0||a.version!=2)console.error("Deprecated file format.");else{var b,g,l,m,n,o,t,p,x,v,u,z,y,w,A=a.faces;o=a.vertices;var C=a.normals,F=a.colors,G=0;for(b=0;b<a.uvs.length;b++)a.uvs[b].length&&G++;for(b=0;b<G;b++)e.faceUvs[b]=[],e.faceVertexUvs[b]=[];m=0;for(n=o.length;m<n;)t=new THREE.Vertex,t.position.x=o[m++]*c,t.position.y=
|
||||
|
||||
@@ -69,7 +69,7 @@ THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){t
|
||||
this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.n11+a.n22+a.n33))/2;this.x=Math.sqrt(Math.max(0,b+a.n11-a.n22-a.n33))/2;this.y=Math.sqrt(Math.max(0,b-a.n11+a.n22-a.n33))/2;this.z=Math.sqrt(Math.max(0,b-a.n11-a.n22+a.n33))/2;this.x=a.n32-a.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=a.n13-a.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.n21-a.n12<0?-Math.abs(this.z):Math.abs(this.z);
|
||||
this.normalize();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);a==0?this.w=this.z=this.y=this.x=0:(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,g=a.x,f=a.y,h=a.z,a=a.w;this.x=b*a+e*g+c*h-d*f;this.y=c*a+e*f+d*g-b*h;this.z=d*a+e*h+b*f-c*g;this.w=e*a-b*g-c*f-d*h;return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,g=this.x,f=this.y,h=this.z,k=this.w,i=k*c+f*e-h*d,l=k*d+h*c-g*e,j=k*e+g*d-f*c,c=-g*
|
||||
c-f*d-h*e;b.x=i*k+c*-g+l*-h-j*-f;b.y=l*k+c*-f+j*-g-i*-h;b.z=j*k+c*-h+i*-f-l*-g;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)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var g=Math.acos(e),f=Math.sqrt(1-e*e);if(Math.abs(f)<0.0010)return 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),c;e=Math.sin((1-d)*g)/f;d=Math.sin(d*g)/f;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};
|
||||
c-f*d-h*e;b.x=i*k+c*-g+l*-h-j*-f;b.y=l*k+c*-f+j*-g-i*-h;b.z=j*k+c*-h+i*-f-l*-g;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)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var g=Math.acos(e),f=Math.sqrt(1-e*e);if(Math.abs(f)<0.001)return 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),c;e=Math.sin((1-d)*g)/f;d=Math.sin(d*g)/f;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){this.position=a||new THREE.Vector3};THREE.Face3=function(a,b,c,d,e,g){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materials=g instanceof Array?g:[g];this.centroid=new THREE.Vector3};
|
||||
THREE.Face4=function(a,b,c,d,e,g,f){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=g instanceof THREE.Color?g:new THREE.Color;this.vertexColors=g instanceof Array?g:[];this.vertexTangents=[];this.materials=f instanceof Array?f:[f];this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.u=a||0;this.v=b||0};
|
||||
THREE.UV.prototype={constructor:THREE.UV,set:function(a,b){this.u=a;this.v=b;return this},copy:function(a){this.u=a.u;this.v=a.v;return this},clone:function(){return new THREE.UV(this.u,this.v)}};
|
||||
|
||||
@@ -69,7 +69,7 @@ THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(b,c,d,f){t
|
||||
this.x=b.x*f;this.y=b.y*f;this.z=b.z*f;this.w=Math.cos(d);return this},setFromRotationMatrix:function(b){var c=Math.pow(b.determinant(),1/3);this.w=Math.sqrt(Math.max(0,c+b.n11+b.n22+b.n33))/2;this.x=Math.sqrt(Math.max(0,c+b.n11-b.n22-b.n33))/2;this.y=Math.sqrt(Math.max(0,c-b.n11+b.n22-b.n33))/2;this.z=Math.sqrt(Math.max(0,c-b.n11-b.n22+b.n33))/2;this.x=b.n32-b.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=b.n13-b.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=b.n21-b.n12<0?-Math.abs(this.z):Math.abs(this.z);
|
||||
this.normalize();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 b=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);b==0?this.w=this.z=this.y=this.x=0:(b=1/b,this.x*=b,this.y*=b,this.z*=b,this.w*=b);return this},multiplySelf:function(b){var c=
|
||||
this.x,d=this.y,f=this.z,i=this.w,h=b.x,j=b.y,k=b.z,b=b.w;this.x=c*b+i*h+d*k-f*j;this.y=d*b+i*j+f*h-c*k;this.z=f*b+i*k+c*j-d*h;this.w=i*b-c*h-d*j-f*k;return this},multiply:function(b,c){this.x=b.x*c.w+b.y*c.z-b.z*c.y+b.w*c.x;this.y=-b.x*c.z+b.y*c.w+b.z*c.x+b.w*c.y;this.z=b.x*c.y-b.y*c.x+b.z*c.w+b.w*c.z;this.w=-b.x*c.x-b.y*c.y-b.z*c.z+b.w*c.w;return this},multiplyVector3:function(b,c){c||(c=b);var d=b.x,f=b.y,i=b.z,h=this.x,j=this.y,k=this.z,p=this.w,n=p*d+j*i-k*f,t=p*f+k*d-h*i,q=p*i+h*f-j*d,d=-h*
|
||||
d-j*f-k*i;c.x=n*p+d*-h+t*-k-q*-j;c.y=t*p+d*-j+q*-h-n*-k;c.z=q*p+d*-k+n*-j-t*-h;return c}};THREE.Quaternion.slerp=function(b,c,d,f){var i=b.w*c.w+b.x*c.x+b.y*c.y+b.z*c.z;if(Math.abs(i)>=1)return d.w=b.w,d.x=b.x,d.y=b.y,d.z=b.z,d;var h=Math.acos(i),j=Math.sqrt(1-i*i);if(Math.abs(j)<0.0010)return d.w=0.5*(b.w+c.w),d.x=0.5*(b.x+c.x),d.y=0.5*(b.y+c.y),d.z=0.5*(b.z+c.z),d;i=Math.sin((1-f)*h)/j;f=Math.sin(f*h)/j;d.w=b.w*i+c.w*f;d.x=b.x*i+c.x*f;d.y=b.y*i+c.y*f;d.z=b.z*i+c.z*f;return d};
|
||||
d-j*f-k*i;c.x=n*p+d*-h+t*-k-q*-j;c.y=t*p+d*-j+q*-h-n*-k;c.z=q*p+d*-k+n*-j-t*-h;return c}};THREE.Quaternion.slerp=function(b,c,d,f){var i=b.w*c.w+b.x*c.x+b.y*c.y+b.z*c.z;if(Math.abs(i)>=1)return d.w=b.w,d.x=b.x,d.y=b.y,d.z=b.z,d;var h=Math.acos(i),j=Math.sqrt(1-i*i);if(Math.abs(j)<0.001)return d.w=0.5*(b.w+c.w),d.x=0.5*(b.x+c.x),d.y=0.5*(b.y+c.y),d.z=0.5*(b.z+c.z),d;i=Math.sin((1-f)*h)/j;f=Math.sin(f*h)/j;d.w=b.w*i+c.w*f;d.x=b.x*i+c.x*f;d.y=b.y*i+c.y*f;d.z=b.z*i+c.z*f;return d};
|
||||
THREE.Vertex=function(b){this.position=b||new THREE.Vector3};THREE.Face3=function(b,c,d,f,i,h){this.a=b;this.b=c;this.c=d;this.normal=f instanceof THREE.Vector3?f:new THREE.Vector3;this.vertexNormals=f instanceof Array?f:[];this.color=i instanceof THREE.Color?i:new THREE.Color;this.vertexColors=i instanceof Array?i:[];this.vertexTangents=[];this.materials=h instanceof Array?h:[h];this.centroid=new THREE.Vector3};
|
||||
THREE.Face4=function(b,c,d,f,i,h,j){this.a=b;this.b=c;this.c=d;this.d=f;this.normal=i instanceof THREE.Vector3?i:new THREE.Vector3;this.vertexNormals=i instanceof Array?i:[];this.color=h instanceof THREE.Color?h:new THREE.Color;this.vertexColors=h instanceof Array?h:[];this.vertexTangents=[];this.materials=j instanceof Array?j:[j];this.centroid=new THREE.Vector3};THREE.UV=function(b,c){this.u=b||0;this.v=c||0};
|
||||
THREE.UV.prototype={constructor:THREE.UV,set:function(b,c){this.u=b;this.v=c;return this},copy:function(b){this.u=b.u;this.v=b.v;return this},clone:function(){return new THREE.UV(this.u,this.v)}};
|
||||
|
||||
+174
-176
@@ -1,256 +1,254 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>three.js webgl - intersection: ray with mesh (through box)</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: Monospace;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#oldie { background-color: #ddd !important }
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>three.js webgl - intersection: ray with mesh (through box)</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<style type="text/css">
|
||||
#info {
|
||||
position: absolute;
|
||||
top: 30px; left: 10px; width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index:100;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Monospace;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#oldie { background-color: #ddd !important }
|
||||
#options {
|
||||
position: absolute;
|
||||
top: 10px; left: 10px; width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index:100;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
#info {
|
||||
position: absolute;
|
||||
top: 30px; left: 10px; width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index:100;
|
||||
}
|
||||
<script type="text/javascript">
|
||||
|
||||
#options {
|
||||
position: absolute;
|
||||
top: 10px; left: 10px; width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index:100;
|
||||
}
|
||||
var camera, scene, projector, renderer,
|
||||
info, mouse = { x: 0, y: 0 }, sun, loader, stats;
|
||||
|
||||
</style>
|
||||
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
var meshes = [];
|
||||
|
||||
<script type="text/javascript">
|
||||
var theta = 0;
|
||||
var camdist = 1500;
|
||||
|
||||
var camera, scene, projector, renderer,
|
||||
info, mouse = { x: 0, y: 0 }, sun, loader, stats;
|
||||
var totalFaces = 0, totalColliders = 0;
|
||||
|
||||
var meshes = [];
|
||||
function init() {
|
||||
|
||||
var theta = 0;
|
||||
var camdist = 1500;
|
||||
|
||||
var totalFaces = 0, totalColliders = 0;
|
||||
|
||||
function init() {
|
||||
|
||||
container = document.createElement( 'div' );
|
||||
document.body.appendChild( container );
|
||||
container = document.createElement( 'div' );
|
||||
document.body.appendChild( container );
|
||||
|
||||
info = document.getElementById("info");
|
||||
info = document.getElementById("info");
|
||||
|
||||
camera = new THREE.Camera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
|
||||
camera.position.z = camdist;
|
||||
camera = new THREE.Camera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
|
||||
camera.position.z = camdist;
|
||||
|
||||
loader = new THREE.JSONLoader( );
|
||||
loader = new THREE.JSONLoader( );
|
||||
|
||||
scene = new THREE.Scene();
|
||||
scene = new THREE.Scene();
|
||||
|
||||
projector = new THREE.Projector();
|
||||
projector = new THREE.Projector();
|
||||
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize( window.innerWidth, window.innerHeight );
|
||||
container.appendChild( renderer.domElement );
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize( window.innerWidth, window.innerHeight );
|
||||
container.appendChild( renderer.domElement );
|
||||
|
||||
var ambientLight = new THREE.AmbientLight( 0x606060 );
|
||||
scene.add( ambientLight );
|
||||
var ambientLight = new THREE.AmbientLight( 0x606060 );
|
||||
scene.add( ambientLight );
|
||||
|
||||
sun = new THREE.DirectionalLight( 0xffffff );
|
||||
sun.position = camera.position.clone();
|
||||
scene.add( sun );
|
||||
sun = new THREE.DirectionalLight( 0xffffff );
|
||||
sun.position = camera.position.clone();
|
||||
scene.add( sun );
|
||||
|
||||
loadCube();
|
||||
loadCube();
|
||||
|
||||
stats = new Stats();
|
||||
stats.domElement.style.position = 'absolute';
|
||||
stats.domElement.style.top = '0px';
|
||||
container.appendChild( stats.domElement );
|
||||
stats = new Stats();
|
||||
stats.domElement.style.position = 'absolute';
|
||||
stats.domElement.style.top = '0px';
|
||||
container.appendChild( stats.domElement );
|
||||
|
||||
container.onmousemove = onDocumentMouseMove;
|
||||
animate();
|
||||
container.onmousemove = onDocumentMouseMove;
|
||||
animate();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function loadCube(p) {
|
||||
function loadCube(p) {
|
||||
|
||||
var onGeometry = function( geometry ) {
|
||||
var onGeometry = function( geometry ) {
|
||||
|
||||
var sx = 300;
|
||||
var sy = 240;
|
||||
var sz = 300;
|
||||
var sx = 300;
|
||||
var sy = 240;
|
||||
var sz = 300;
|
||||
|
||||
addCube( new THREE.Vector3(-sx, 0, 0), geometry );
|
||||
addCube( new THREE.Vector3( 0, 0, 0), geometry );
|
||||
addCube( new THREE.Vector3( sx, 0, 0), geometry );
|
||||
addCube( new THREE.Vector3(-sx, 0, 0), geometry );
|
||||
addCube( new THREE.Vector3( 0, 0, 0), geometry );
|
||||
addCube( new THREE.Vector3( sx, 0, 0), geometry );
|
||||
|
||||
addCube( new THREE.Vector3(-sx, sy, 0), geometry );
|
||||
addCube( new THREE.Vector3( 0, sy, 0), geometry );
|
||||
addCube( new THREE.Vector3( sx, sy, 0), geometry );
|
||||
addCube( new THREE.Vector3(-sx, sy, 0), geometry );
|
||||
addCube( new THREE.Vector3( 0, sy, 0), geometry );
|
||||
addCube( new THREE.Vector3( sx, sy, 0), geometry );
|
||||
|
||||
addCube( new THREE.Vector3(-sx,-sy, 0), geometry );
|
||||
addCube( new THREE.Vector3( 0, -sy, 0), geometry );
|
||||
addCube( new THREE.Vector3( sx,-sy, 0), geometry );
|
||||
addCube( new THREE.Vector3(-sx,-sy, 0), geometry );
|
||||
addCube( new THREE.Vector3( 0, -sy, 0), geometry );
|
||||
addCube( new THREE.Vector3( sx,-sy, 0), geometry );
|
||||
|
||||
addCube( new THREE.Vector3(-sx, 0, sz), geometry );
|
||||
addCube( new THREE.Vector3( 0, 0, sz), geometry );
|
||||
addCube( new THREE.Vector3( sx, 0, sz), geometry );
|
||||
addCube( new THREE.Vector3(-sx, 0, sz), geometry );
|
||||
addCube( new THREE.Vector3( 0, 0, sz), geometry );
|
||||
addCube( new THREE.Vector3( sx, 0, sz), geometry );
|
||||
|
||||
addCube( new THREE.Vector3(-sx, sy, sz), geometry );
|
||||
addCube( new THREE.Vector3( 0, sy, sz), geometry );
|
||||
addCube( new THREE.Vector3( sx, sy, sz), geometry );
|
||||
addCube( new THREE.Vector3(-sx, sy, sz), geometry );
|
||||
addCube( new THREE.Vector3( 0, sy, sz), geometry );
|
||||
addCube( new THREE.Vector3( sx, sy, sz), geometry );
|
||||
|
||||
addCube( new THREE.Vector3(-sx,-sy, sz), geometry );
|
||||
addCube( new THREE.Vector3( 0, -sy, sz), geometry );
|
||||
addCube( new THREE.Vector3( sx,-sy, sz), geometry );
|
||||
addCube( new THREE.Vector3(-sx,-sy, sz), geometry );
|
||||
addCube( new THREE.Vector3( 0, -sy, sz), geometry );
|
||||
addCube( new THREE.Vector3( sx,-sy, sz), geometry );
|
||||
|
||||
addCube( new THREE.Vector3(-sx, 0, -sz), geometry );
|
||||
addCube( new THREE.Vector3( 0, 0, -sz), geometry );
|
||||
addCube( new THREE.Vector3( sx, 0, -sz), geometry );
|
||||
addCube( new THREE.Vector3(-sx, 0, -sz), geometry );
|
||||
addCube( new THREE.Vector3( 0, 0, -sz), geometry );
|
||||
addCube( new THREE.Vector3( sx, 0, -sz), geometry );
|
||||
|
||||
addCube( new THREE.Vector3(-sx, sy, -sz), geometry );
|
||||
addCube( new THREE.Vector3( 0, sy, -sz), geometry );
|
||||
addCube( new THREE.Vector3( sx, sy, -sz), geometry );
|
||||
addCube( new THREE.Vector3(-sx, sy, -sz), geometry );
|
||||
addCube( new THREE.Vector3( 0, sy, -sz), geometry );
|
||||
addCube( new THREE.Vector3( sx, sy, -sz), geometry );
|
||||
|
||||
addCube( new THREE.Vector3(-sx,-sy, -sz), geometry );
|
||||
addCube( new THREE.Vector3( 0, -sy, -sz), geometry );
|
||||
addCube( new THREE.Vector3( sx,-sy, -sz), geometry );
|
||||
addCube( new THREE.Vector3(-sx,-sy, -sz), geometry );
|
||||
addCube( new THREE.Vector3( 0, -sy, -sz), geometry );
|
||||
addCube( new THREE.Vector3( sx,-sy, -sz), geometry );
|
||||
|
||||
addCube( new THREE.Vector3(-sx, 0, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3( 0, 0, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3( sx, 0, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3(-sx, 0, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3( 0, 0, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3( sx, 0, -sz*2), geometry );
|
||||
|
||||
addCube( new THREE.Vector3(-sx, sy, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3( 0, sy, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3( sx, sy, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3(-sx, sy, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3( 0, sy, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3( sx, sy, -sz*2), geometry );
|
||||
|
||||
addCube( new THREE.Vector3(-sx,-sy, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3( 0, -sy, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3( sx,-sy, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3(-sx,-sy, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3( 0, -sy, -sz*2), geometry );
|
||||
addCube( new THREE.Vector3( sx,-sy, -sz*2), geometry );
|
||||
|
||||
// info.innerHTML = "Total colliders: " + totalColliders + " (Faces: " + totalFaces + ")<br>";
|
||||
// info.innerHTML = "Total colliders: " + totalColliders + " (Faces: " + totalFaces + ")<br>";
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
loader.load( { model: "obj/suzanne/suzanneHi.js", callback: onGeometry } );
|
||||
}
|
||||
loader.load( { model: "obj/suzanne/suzanneHi.js", callback: onGeometry } );
|
||||
}
|
||||
|
||||
function addCube( p, g) {
|
||||
function addCube( p, g) {
|
||||
|
||||
totalFaces += g.faces.length;
|
||||
totalColliders++;
|
||||
totalFaces += g.faces.length;
|
||||
totalColliders++;
|
||||
|
||||
var mesh = new THREE.Mesh( g, new THREE.MeshLambertMaterial( { color: 0x003300 } ) );
|
||||
mesh.position = p;
|
||||
var mesh = new THREE.Mesh( g, new THREE.MeshLambertMaterial( { color: 0x003300 } ) );
|
||||
mesh.position = p;
|
||||
|
||||
//mesh.rotation.x = Math.random() * Math.PI;
|
||||
//mesh.rotation.y = Math.random() * Math.PI;
|
||||
//mesh.rotation.z = Math.random() * Math.PI;
|
||||
//mesh.rotation.x = Math.random() * Math.PI;
|
||||
//mesh.rotation.y = Math.random() * Math.PI;
|
||||
//mesh.rotation.z = Math.random() * Math.PI;
|
||||
|
||||
//mesh.scale.x = Math.random() + 0.5;
|
||||
//mesh.scale.y = Math.random() + 0.5;
|
||||
//mesh.scale.z = Math.random() + 0.5;
|
||||
//mesh.scale.x = Math.random() + 0.5;
|
||||
//mesh.scale.y = Math.random() + 0.5;
|
||||
//mesh.scale.z = Math.random() + 0.5;
|
||||
|
||||
scene.add( mesh );
|
||||
var mc = THREE.CollisionUtils.MeshColliderWBox(mesh);
|
||||
THREE.Collisions.colliders.push( mc );
|
||||
meshes.push( mesh );
|
||||
scene.add( mesh );
|
||||
var mc = THREE.CollisionUtils.MeshColliderWBox(mesh);
|
||||
THREE.Collisions.colliders.push( mc );
|
||||
meshes.push( mesh );
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
function onDocumentMouseMove( event ) {
|
||||
function onDocumentMouseMove( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
|
||||
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
|
||||
event.preventDefault();
|
||||
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
|
||||
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
function animate() {
|
||||
function animate() {
|
||||
|
||||
requestAnimationFrame( animate );
|
||||
requestAnimationFrame( animate );
|
||||
|
||||
if( meshes.length == 0 ) return;
|
||||
if( meshes.length == 0 ) return;
|
||||
|
||||
var i, l = meshes.length;
|
||||
var i, l = meshes.length;
|
||||
|
||||
for ( i = 0; i < l; i++ ) {
|
||||
for ( i = 0; i < l; i++ ) {
|
||||
|
||||
meshes[ i ].materials[ 0 ].color.setHex( 0x003300 );
|
||||
meshes[ i ].materials[ 0 ].color.setHex( 0x003300 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
|
||||
var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
|
||||
var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
|
||||
|
||||
var c = THREE.Collisions.rayCastNearest( ray );
|
||||
var c = THREE.Collisions.rayCastNearest( ray );
|
||||
|
||||
if( c ) {
|
||||
if( c ) {
|
||||
|
||||
//info.innerHTML += "Found @ distance " + c.distance;
|
||||
c.mesh.materials[ 0 ].color.setHex( 0xbb0000 );
|
||||
//info.innerHTML += "Found @ distance " + c.distance;
|
||||
c.mesh.materials[ 0 ].color.setHex( 0xbb0000 );
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
//info.innerHTML += "No intersection";
|
||||
//info.innerHTML += "No intersection";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
camera.position.x = camdist * Math.cos( theta );
|
||||
camera.position.z = camdist * Math.sin( theta );
|
||||
camera.position.y = camdist/2 * Math.sin( theta * 2) ;
|
||||
camera.position.x = camdist * Math.cos( theta );
|
||||
camera.position.z = camdist * Math.sin( theta );
|
||||
camera.position.y = camdist/2 * Math.sin( theta * 2) ;
|
||||
|
||||
sun.position.copy( camera.position );
|
||||
sun.position.normalize();
|
||||
sun.position.copy( camera.position );
|
||||
sun.position.normalize();
|
||||
|
||||
theta += 0.005;
|
||||
theta += 0.005;
|
||||
|
||||
renderer.render( scene, camera );
|
||||
renderer.render( scene, camera );
|
||||
|
||||
stats.update();
|
||||
stats.update();
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
function vts(v) {
|
||||
function vts(v) {
|
||||
|
||||
if(!v) return "undefined<br>";
|
||||
else return v.x + " , " + v.y + " , " + v.z + "<br>";
|
||||
if(!v) return "undefined<br>";
|
||||
else return v.x + " , " + v.y + " , " + v.z + "<br>";
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
</script>
|
||||
</script>
|
||||
|
||||
</head>
|
||||
</head>
|
||||
|
||||
<body onload="init();">
|
||||
<div id="info"></div>
|
||||
<div id="options"></div>
|
||||
</body>
|
||||
<body onload="init();">
|
||||
<div id="info"></div>
|
||||
<div id="options"></div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -1,217 +1,215 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>three.js webgl - intersection: ray/mesh readinf normal</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: Monospace;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#oldie { background-color: #ddd !important }
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>three.js webgl - intersection: ray/mesh readinf normal</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<style type="text/css">
|
||||
#info {
|
||||
position: absolute;
|
||||
top: 30px; left: 10px; width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index:100;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Monospace;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#oldie { background-color: #ddd !important }
|
||||
#options {
|
||||
position: absolute;
|
||||
top: 10px; left: 10px; width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index:100;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
#info {
|
||||
position: absolute;
|
||||
top: 30px; left: 10px; width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index:100;
|
||||
}
|
||||
<script type="text/javascript">
|
||||
|
||||
#options {
|
||||
position: absolute;
|
||||
top: 10px; left: 10px; width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index:100;
|
||||
}
|
||||
var camera, scene, projector, renderer,
|
||||
info, mouse = { x: 0, y: 0 }, sun, loader, stats, line;
|
||||
|
||||
</style>
|
||||
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
var meshes = [];
|
||||
|
||||
<script type="text/javascript">
|
||||
var theta = 0;
|
||||
var camdist = 500;
|
||||
|
||||
var camera, scene, projector, renderer,
|
||||
info, mouse = { x: 0, y: 0 }, sun, loader, stats, line;
|
||||
var totalFaces = 0, totalColliders = 0;
|
||||
|
||||
var meshes = [];
|
||||
function init() {
|
||||
|
||||
var theta = 0;
|
||||
var camdist = 500;
|
||||
|
||||
var totalFaces = 0, totalColliders = 0;
|
||||
|
||||
function init() {
|
||||
|
||||
container = document.createElement( 'div' );
|
||||
document.body.appendChild( container );
|
||||
container = document.createElement( 'div' );
|
||||
document.body.appendChild( container );
|
||||
|
||||
info = document.getElementById("info");
|
||||
info = document.getElementById("info");
|
||||
|
||||
camera = new THREE.Camera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
|
||||
camera.position.z = camdist;
|
||||
camera = new THREE.Camera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
|
||||
camera.position.z = camdist;
|
||||
|
||||
loader = new THREE.JSONLoader( );
|
||||
loader = new THREE.JSONLoader( );
|
||||
|
||||
scene = new THREE.Scene();
|
||||
scene = new THREE.Scene();
|
||||
|
||||
projector = new THREE.Projector();
|
||||
projector = new THREE.Projector();
|
||||
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize( window.innerWidth, window.innerHeight );
|
||||
container.appendChild( renderer.domElement );
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize( window.innerWidth, window.innerHeight );
|
||||
container.appendChild( renderer.domElement );
|
||||
|
||||
var ambientLight = new THREE.AmbientLight( 0x606060 );
|
||||
scene.add( ambientLight );
|
||||
var ambientLight = new THREE.AmbientLight( 0x606060 );
|
||||
scene.add( ambientLight );
|
||||
|
||||
sun = new THREE.DirectionalLight( 0xffffff );
|
||||
sun.position = camera.position.clone();
|
||||
scene.add( sun );
|
||||
sun = new THREE.DirectionalLight( 0xffffff );
|
||||
sun.position = camera.position.clone();
|
||||
scene.add( sun );
|
||||
|
||||
loadCube();
|
||||
loadCube();
|
||||
|
||||
var lineMat = new THREE.LineBasicMaterial( { color: 0xff0000, opacity: 1, linewidth: 3 } );
|
||||
var lineMat = new THREE.LineBasicMaterial( { color: 0xff0000, opacity: 1, linewidth: 3 } );
|
||||
|
||||
var geom = new THREE.Geometry();
|
||||
geom.vertices.push( new THREE.Vertex( new THREE.Vector3(-100, 0, 0) ) );
|
||||
geom.vertices.push( new THREE.Vertex( new THREE.Vector3( 100, 0, 0) ) );
|
||||
var geom = new THREE.Geometry();
|
||||
geom.vertices.push( new THREE.Vertex( new THREE.Vector3(-100, 0, 0) ) );
|
||||
geom.vertices.push( new THREE.Vertex( new THREE.Vector3( 100, 0, 0) ) );
|
||||
|
||||
line = new THREE.Line(geom, lineMat);
|
||||
scene.add( line );
|
||||
line = new THREE.Line(geom, lineMat);
|
||||
scene.add( line );
|
||||
|
||||
stats = new Stats();
|
||||
stats.domElement.style.position = 'absolute';
|
||||
stats.domElement.style.top = '0px';
|
||||
container.appendChild( stats.domElement );
|
||||
stats = new Stats();
|
||||
stats.domElement.style.position = 'absolute';
|
||||
stats.domElement.style.top = '0px';
|
||||
container.appendChild( stats.domElement );
|
||||
|
||||
container.onmousemove = onDocumentMouseMove;
|
||||
animate();
|
||||
container.onmousemove = onDocumentMouseMove;
|
||||
animate();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function loadCube(p) {
|
||||
function loadCube(p) {
|
||||
|
||||
var onGeometry = function( geometry ) {
|
||||
var onGeometry = function( geometry ) {
|
||||
|
||||
var sx = 300;
|
||||
var sy = 240;
|
||||
var sz = 300;
|
||||
var sx = 300;
|
||||
var sy = 240;
|
||||
var sz = 300;
|
||||
|
||||
addCube( new THREE.Vector3( 0, 0, 0), geometry );
|
||||
addCube( new THREE.Vector3( 0, 0, 0), geometry );
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
loader.load( { model: "obj/suzanne/suzanneHi.js", callback: onGeometry } );
|
||||
}
|
||||
loader.load( { model: "obj/suzanne/suzanneHi.js", callback: onGeometry } );
|
||||
}
|
||||
|
||||
function addCube( p, g) {
|
||||
function addCube( p, g) {
|
||||
|
||||
totalFaces += g.faces.length;
|
||||
totalColliders++;
|
||||
totalFaces += g.faces.length;
|
||||
totalColliders++;
|
||||
|
||||
var mesh = new THREE.Mesh( g, new THREE.MeshLambertMaterial( { color: 0x003300 } ) );
|
||||
mesh.position = p;
|
||||
var mesh = new THREE.Mesh( g, new THREE.MeshLambertMaterial( { color: 0x003300 } ) );
|
||||
mesh.position = p;
|
||||
|
||||
scene.add( mesh );
|
||||
var mc = THREE.CollisionUtils.MeshColliderWBox(mesh);
|
||||
THREE.Collisions.colliders.push( mc );
|
||||
meshes.push( mesh );
|
||||
scene.add( mesh );
|
||||
var mc = THREE.CollisionUtils.MeshColliderWBox(mesh);
|
||||
THREE.Collisions.colliders.push( mc );
|
||||
meshes.push( mesh );
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
function onDocumentMouseMove( event ) {
|
||||
function onDocumentMouseMove( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
|
||||
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
|
||||
event.preventDefault();
|
||||
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
|
||||
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
function animate() {
|
||||
function animate() {
|
||||
|
||||
requestAnimationFrame( animate );
|
||||
requestAnimationFrame( animate );
|
||||
|
||||
var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
|
||||
var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
|
||||
var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
|
||||
|
||||
if ( meshes.length == 0 ) return;
|
||||
if ( meshes.length == 0 ) return;
|
||||
|
||||
var i, l = meshes.length;
|
||||
var i, l = meshes.length;
|
||||
|
||||
for ( i = 0; i < l; i++ ) {
|
||||
meshes[ i ].materials[ 0 ].color.setHex( 0x003300 );
|
||||
}
|
||||
for ( i = 0; i < l; i++ ) {
|
||||
meshes[ i ].materials[ 0 ].color.setHex( 0x003300 );
|
||||
}
|
||||
|
||||
info.innerHTML = "";
|
||||
info.innerHTML = "";
|
||||
|
||||
|
||||
var c = THREE.Collisions.rayCastNearest( ray );
|
||||
var c = THREE.Collisions.rayCastNearest( ray );
|
||||
|
||||
if( c ) {
|
||||
if( c ) {
|
||||
|
||||
info.innerHTML += "Found @ normal " + vts(c.normal);
|
||||
info.innerHTML += "Found @ normal " + vts(c.normal);
|
||||
|
||||
var poi = ray.origin.clone().addSelf( ray.direction.clone().multiplyScalar(c.distance) );
|
||||
line.geometry.vertices[0].position = poi;
|
||||
line.geometry.vertices[1].position = poi.clone().addSelf(c.normal.multiplyScalar(100));
|
||||
line.geometry.__dirtyVertices = true;
|
||||
line.geometry.__dirtyElements = true;
|
||||
var poi = ray.origin.clone().addSelf( ray.direction.clone().multiplyScalar(c.distance) );
|
||||
line.geometry.vertices[0].position = poi;
|
||||
line.geometry.vertices[1].position = poi.clone().addSelf(c.normal.multiplyScalar(100));
|
||||
line.geometry.__dirtyVertices = true;
|
||||
line.geometry.__dirtyElements = true;
|
||||
|
||||
c.mesh.materials[ 0 ].color.setHex( 0xbb0000 );
|
||||
c.mesh.materials[ 0 ].color.setHex( 0xbb0000 );
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
info.innerHTML += "No intersection";
|
||||
info.innerHTML += "No intersection";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
camera.position.x = camdist * Math.cos( theta );
|
||||
camera.position.z = camdist * Math.sin( theta );
|
||||
camera.position.y = camdist/2 * Math.sin( theta * 2) ;
|
||||
camera.position.x = camdist * Math.cos( theta );
|
||||
camera.position.z = camdist * Math.sin( theta );
|
||||
camera.position.y = camdist/2 * Math.sin( theta * 2) ;
|
||||
|
||||
sun.position.copy( camera.position );
|
||||
sun.position.normalize();
|
||||
sun.position.copy( camera.position );
|
||||
sun.position.normalize();
|
||||
|
||||
theta += 0.005;
|
||||
theta += 0.005;
|
||||
|
||||
renderer.render( scene, camera );
|
||||
renderer.render( scene, camera );
|
||||
|
||||
stats.update();
|
||||
stats.update();
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
function vts(v) {
|
||||
function vts(v) {
|
||||
|
||||
if(!v) return "undefined<br>";
|
||||
else return v.x.toFixed(2) + " , " + v.y.toFixed(2) + " , " + v.z.toFixed(2) + "<br>";
|
||||
if(!v) return "undefined<br>";
|
||||
else return v.x.toFixed(2) + " , " + v.y.toFixed(2) + " , " + v.z.toFixed(2) + "<br>";
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
</script>
|
||||
</script>
|
||||
|
||||
</head>
|
||||
</head>
|
||||
|
||||
<body onload="init();">
|
||||
<div id="info"></div>
|
||||
<div id="options"></div>
|
||||
</body>
|
||||
<body onload="init();">
|
||||
<div id="info"></div>
|
||||
<div id="options"></div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -1,238 +1,236 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>three.js webgl - intersection: ray with sphere/AABB/plane</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<style type="text/css">
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>three.js webgl - intersection: ray with sphere/AABB/plane</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: Monospace;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Monospace;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
#oldie {
|
||||
background-color: #ddd !important
|
||||
}
|
||||
|
||||
#oldie {
|
||||
background-color: #ddd !important
|
||||
}
|
||||
#info {
|
||||
position: absolute;
|
||||
top: 30px;
|
||||
left: 150px;
|
||||
width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#info {
|
||||
position: absolute;
|
||||
top: 30px;
|
||||
left: 150px;
|
||||
width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#options {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 150px;
|
||||
width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
</style>
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
|
||||
#options {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 150px;
|
||||
width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index: 100;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
|
||||
<script type="text/javascript" src="js/Stats.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
<script type="text/javascript">
|
||||
|
||||
var camera, scene, projector, renderer,
|
||||
info, mouse = { x: 0, y: 0 }, sun;
|
||||
var camera, scene, projector, renderer,
|
||||
info, mouse = { x: 0, y: 0 }, sun;
|
||||
|
||||
var theta = 0;
|
||||
var camdist = 1500;
|
||||
var geoms = [];
|
||||
var theta = 0;
|
||||
var camdist = 1500;
|
||||
var geoms = [];
|
||||
|
||||
function init () {
|
||||
function init () {
|
||||
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
|
||||
info = document.getElementById("info");
|
||||
info = document.getElementById("info");
|
||||
|
||||
camera = new THREE.Camera(40, window.innerWidth / window.innerHeight, 1, 10000);
|
||||
camera = new THREE.Camera(40, window.innerWidth / window.innerHeight, 1, 10000);
|
||||
|
||||
scene = new THREE.Scene();
|
||||
scene = new THREE.Scene();
|
||||
|
||||
projector = new THREE.Projector();
|
||||
projector = new THREE.Projector();
|
||||
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
container.appendChild(renderer.domElement);
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
container.appendChild(renderer.domElement);
|
||||
|
||||
var ambientLight = new THREE.AmbientLight(0x606060);
|
||||
scene.add(ambientLight);
|
||||
var ambientLight = new THREE.AmbientLight(0x606060);
|
||||
scene.add(ambientLight);
|
||||
|
||||
sun = new THREE.DirectionalLight(0xffffff);
|
||||
scene.add(sun);
|
||||
sun = new THREE.DirectionalLight(0xffffff);
|
||||
scene.add(sun);
|
||||
|
||||
//makeWall(480);
|
||||
//makeWall(360);
|
||||
makeWall(240);
|
||||
makeWall(120);
|
||||
makeWall(0);
|
||||
makeWall(-120);
|
||||
makeWall(-240);
|
||||
//makeWall(-360);
|
||||
//makeWall(-480);
|
||||
//makeWall(480);
|
||||
//makeWall(360);
|
||||
makeWall(240);
|
||||
makeWall(120);
|
||||
makeWall(0);
|
||||
makeWall(-120);
|
||||
makeWall(-240);
|
||||
//makeWall(-360);
|
||||
//makeWall(-480);
|
||||
|
||||
plane = new THREE.Mesh( new THREE.PlaneGeometry( 30000, 30000, 10, 10 ), new THREE.MeshLambertMaterial( { color: 0x003300 } ) );
|
||||
plane.position.y = - 480;
|
||||
plane.rotation.x = Math.PI / - 2;
|
||||
scene.add( plane );
|
||||
geoms.push( plane );
|
||||
plane = new THREE.Mesh( new THREE.PlaneGeometry( 30000, 30000, 10, 10 ), new THREE.MeshLambertMaterial( { color: 0x003300 } ) );
|
||||
plane.position.y = - 480;
|
||||
plane.rotation.x = Math.PI / - 2;
|
||||
scene.add( plane );
|
||||
geoms.push( plane );
|
||||
|
||||
var cplane = new THREE.PlaneCollider( plane.position, new THREE.Vector3( 0, 1, 0 ) );
|
||||
cplane.mesh = plane;
|
||||
THREE.Collisions.colliders.push( cplane );
|
||||
var cplane = new THREE.PlaneCollider( plane.position, new THREE.Vector3( 0, 1, 0 ) );
|
||||
cplane.mesh = plane;
|
||||
THREE.Collisions.colliders.push( cplane );
|
||||
|
||||
stats = new Stats();
|
||||
stats.domElement.style.position = 'absolute';
|
||||
stats.domElement.style.top = '0px';
|
||||
container.appendChild( stats.domElement );
|
||||
stats = new Stats();
|
||||
stats.domElement.style.position = 'absolute';
|
||||
stats.domElement.style.top = '0px';
|
||||
container.appendChild( stats.domElement );
|
||||
|
||||
container.onmousemove = onDocumentMouseMove;
|
||||
animate();
|
||||
container.onmousemove = onDocumentMouseMove;
|
||||
animate();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function makeWall(z){
|
||||
var mx = 120 * 2;
|
||||
for (var i = -mx; i <= mx; i += 120) {
|
||||
for (var j = -mx; j <= mx; j += 120) {
|
||||
if (Math.random() > 0.5)
|
||||
createCube(100, new THREE.Vector3(j, i, z));
|
||||
else
|
||||
createSphere(50, new THREE.Vector3(j, i, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
function makeWall(z){
|
||||
var mx = 120 * 2;
|
||||
for (var i = -mx; i <= mx; i += 120) {
|
||||
for (var j = -mx; j <= mx; j += 120) {
|
||||
if (Math.random() > 0.5)
|
||||
createCube(100, new THREE.Vector3(j, i, z));
|
||||
else
|
||||
createSphere(50, new THREE.Vector3(j, i, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createCube(s, p){
|
||||
var cube = new THREE.Mesh(new THREE.CubeGeometry( s, s, s ), new THREE.MeshLambertMaterial( { color: 0x003300 } ) );
|
||||
cube.position = p;
|
||||
scene.add(cube);
|
||||
geoms.push(cube);
|
||||
THREE.Collisions.colliders.push(THREE.CollisionUtils.MeshAABB(cube, p));
|
||||
}
|
||||
function createCube(s, p){
|
||||
var cube = new THREE.Mesh(new THREE.CubeGeometry( s, s, s ), new THREE.MeshLambertMaterial( { color: 0x003300 } ) );
|
||||
cube.position = p;
|
||||
scene.add(cube);
|
||||
geoms.push(cube);
|
||||
THREE.Collisions.colliders.push(THREE.CollisionUtils.MeshAABB(cube, p));
|
||||
}
|
||||
|
||||
function createSphere(rad, p){
|
||||
var sphere = new THREE.Mesh( new THREE.SphereGeometry( rad, 10, 10 ), new THREE.MeshLambertMaterial( { color: 0x003300 } ) );
|
||||
sphere.position = p;
|
||||
scene.add(sphere);
|
||||
geoms.push(sphere);
|
||||
function createSphere(rad, p){
|
||||
var sphere = new THREE.Mesh( new THREE.SphereGeometry( rad, 10, 10 ), new THREE.MeshLambertMaterial( { color: 0x003300 } ) );
|
||||
sphere.position = p;
|
||||
scene.add(sphere);
|
||||
geoms.push(sphere);
|
||||
|
||||
var sc = new THREE.SphereCollider(p, rad);
|
||||
sc.mesh = sphere;
|
||||
THREE.Collisions.colliders.push(sc);
|
||||
}
|
||||
var sc = new THREE.SphereCollider(p, rad);
|
||||
sc.mesh = sphere;
|
||||
THREE.Collisions.colliders.push(sc);
|
||||
}
|
||||
|
||||
function onDocumentMouseMove(event){
|
||||
function onDocumentMouseMove(event){
|
||||
event.preventDefault();
|
||||
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|
||||
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|
||||
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||
function animate(){
|
||||
|
||||
}
|
||||
requestAnimationFrame( animate );
|
||||
|
||||
function animate(){
|
||||
var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
|
||||
requestAnimationFrame( animate );
|
||||
var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
|
||||
|
||||
var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
projector.unprojectVector( vector, camera );
|
||||
for ( var i = 0; i < geoms.length; i++) {
|
||||
geoms[i].materials[0].color = new THREE.Color(0x007700);
|
||||
}
|
||||
|
||||
var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );
|
||||
if ( !document.getElementById( "nearest" ).checked ) {
|
||||
|
||||
for ( var i = 0; i < geoms.length; i++) {
|
||||
geoms[i].materials[0].color = new THREE.Color(0x007700);
|
||||
}
|
||||
// Raycast all
|
||||
|
||||
if ( !document.getElementById( "nearest" ).checked ) {
|
||||
ts = new Date().getTime();
|
||||
var cs = THREE.Collisions.rayCastAll( ray );
|
||||
tt = new Date().getTime() - ts;
|
||||
|
||||
// Raycast all
|
||||
if ( cs.length > 0 ) {
|
||||
|
||||
ts = new Date().getTime();
|
||||
var cs = THREE.Collisions.rayCastAll( ray );
|
||||
tt = new Date().getTime() - ts;
|
||||
info.innerHTML = cs.length + " colliders found in " + tt;
|
||||
|
||||
if ( cs.length > 0 ) {
|
||||
for ( var i = 0; i < cs.length; i ++ ) {
|
||||
|
||||
info.innerHTML = cs.length + " colliders found in " + tt;
|
||||
cs[ i ].mesh.materials[ 0 ].color.setHex( 0xaa0000 );
|
||||
|
||||
for ( var i = 0; i < cs.length; i ++ ) {
|
||||
}
|
||||
|
||||
cs[ i ].mesh.materials[ 0 ].color.setHex( 0xaa0000 );
|
||||
} else {
|
||||
|
||||
}
|
||||
info.innerHTML = "No intersection";
|
||||
|
||||
} else {
|
||||
}
|
||||
|
||||
info.innerHTML = "No intersection";
|
||||
} else {
|
||||
|
||||
}
|
||||
// Raycast nearest
|
||||
|
||||
} else {
|
||||
ts = new Date().getTime();
|
||||
var c = THREE.Collisions.rayCastNearest( ray );
|
||||
tt = new Date().getTime() - ts;
|
||||
|
||||
// Raycast nearest
|
||||
if ( c ) {
|
||||
|
||||
ts = new Date().getTime();
|
||||
var c = THREE.Collisions.rayCastNearest( ray );
|
||||
tt = new Date().getTime() - ts;
|
||||
info.innerHTML = "Found in " + tt + " @ distance " + c.distance;
|
||||
c.mesh.materials[ 0 ].color.setHex( 0xaa0000 );
|
||||
|
||||
if ( c ) {
|
||||
} else {
|
||||
|
||||
info.innerHTML = "Found in " + tt + " @ distance " + c.distance;
|
||||
c.mesh.materials[ 0 ].color.setHex( 0xaa0000 );
|
||||
info.innerHTML = "No intersection";
|
||||
|
||||
} else {
|
||||
}
|
||||
|
||||
info.innerHTML = "No intersection";
|
||||
}
|
||||
|
||||
}
|
||||
camera.position.x = camdist * Math.cos(theta);
|
||||
camera.position.z = camdist * Math.sin(theta);
|
||||
camera.position.y = camdist / 2 * Math.sin(theta * 2);
|
||||
sun.position = camera.position.clone();
|
||||
sun.position.normalize();
|
||||
theta += 0.005;
|
||||
|
||||
}
|
||||
renderer.render( scene, camera );
|
||||
|
||||
camera.position.x = camdist * Math.cos(theta);
|
||||
camera.position.z = camdist * Math.sin(theta);
|
||||
camera.position.y = camdist / 2 * Math.sin(theta * 2);
|
||||
sun.position = camera.position.clone();
|
||||
sun.position.normalize();
|
||||
theta += 0.005;
|
||||
stats.update();
|
||||
|
||||
renderer.render( scene, camera );
|
||||
}
|
||||
|
||||
stats.update();
|
||||
function vts(v){
|
||||
if (!v)
|
||||
return "undefined<br>";
|
||||
else
|
||||
return v.x + " , " + v.y + " , " + v.z + "<br>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function vts(v){
|
||||
if (!v)
|
||||
return "undefined<br>";
|
||||
else
|
||||
return v.x + " , " + v.y + " , " + v.z + "<br>";
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init();">
|
||||
<div id="info">
|
||||
</div>
|
||||
<div id="options">
|
||||
<input type="checkbox" id="nearest" checked/> Nearest collider only
|
||||
<br/>
|
||||
</div>
|
||||
</body>
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init();">
|
||||
<div id="info">
|
||||
</div>
|
||||
<div id="options">
|
||||
<input type="checkbox" id="nearest" checked/> Nearest collider only
|
||||
<br/>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,93 +1,91 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>three.js webgl - collision reaction</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||
<style type="text/css">
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>three.js webgl - collision reaction</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: Monospace;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Monospace;
|
||||
background-color: #f0f0f0;
|
||||
margin: 0px;
|
||||
overflow: hidden;
|
||||
}
|
||||
#oldie {
|
||||
background-color: #ddd !important
|
||||
}
|
||||
|
||||
#oldie {
|
||||
background-color: #ddd !important
|
||||
}
|
||||
#info {
|
||||
position: absolute;
|
||||
top: 30px;
|
||||
left: 10px;
|
||||
width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#info {
|
||||
position: absolute;
|
||||
top: 30px;
|
||||
left: 10px;
|
||||
width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index: 100;
|
||||
}
|
||||
#options {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 10px;
|
||||
width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index: 100;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript" src="../build/Three.js"></script>
|
||||
<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
#options {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 10px;
|
||||
width: 800px;
|
||||
color: #000000;
|
||||
padding: 5px;
|
||||
font-family: Monospace;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
z-index: 100;
|
||||
}
|
||||
var camera, scene, renderer, info, mouse2d, sun, loader, sphere, debugNormal;
|
||||
|
||||
</style>
|
||||
<script type="text/javascript" src="../build/Three.js">
|
||||
</script>
|
||||
<script type="text/javascript" src="js/RequestAnimationFrame.js">
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var camera, scene, renderer, info, mouse2d, sun, loader, sphere, debugNormal;
|
||||
|
||||
var range = 400;
|
||||
var speed = 1;
|
||||
var sphereSize = 4;
|
||||
var range = 400;
|
||||
var speed = 1;
|
||||
var sphereSize = 4;
|
||||
|
||||
var cubes = [];
|
||||
|
||||
function init(){
|
||||
|
||||
function init(){
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
|
||||
info = document.getElementById("info");
|
||||
info = document.getElementById("info");
|
||||
|
||||
camera = new THREE.Camera(40, window.innerWidth / window.innerHeight, 1, 10000);
|
||||
camera.position.y = 120;
|
||||
camera = new THREE.Camera(40, window.innerWidth / window.innerHeight, 1, 10000);
|
||||
camera.position.y = 120;
|
||||
camera.position.x = 300;
|
||||
camera.position.z = 0;
|
||||
mouse2d = new THREE.Vector3(0, 0, 1);
|
||||
mouse2d = new THREE.Vector3(0, 0, 1);
|
||||
|
||||
loader = new THREE.Loader(true);
|
||||
loader = new THREE.Loader(true);
|
||||
|
||||
scene = new THREE.Scene();
|
||||
scene = new THREE.Scene();
|
||||
|
||||
sphere = new THREE.Mesh( new THREE.SphereGeometry( sphereSize, 10, 10 ), new THREE.MeshLambertMaterial( { color: 0xff0000 } ) );
|
||||
scene.add( sphere );
|
||||
sphere = new THREE.Mesh( new THREE.SphereGeometry( sphereSize, 10, 10 ), new THREE.MeshLambertMaterial( { color: 0xff0000 } ) );
|
||||
scene.add( sphere );
|
||||
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
container.appendChild(renderer.domElement);
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
container.appendChild(renderer.domElement);
|
||||
|
||||
var ambientLight = new THREE.AmbientLight(0xdddddd);
|
||||
scene.add(ambientLight);
|
||||
var ambientLight = new THREE.AmbientLight(0xdddddd);
|
||||
scene.add(ambientLight);
|
||||
|
||||
sun = new THREE.DirectionalLight(0xffffff);
|
||||
sun.position = new THREE.Vector3(1, -1, 1).normalize();
|
||||
scene.add(sun);
|
||||
sun = new THREE.DirectionalLight(0xffffff);
|
||||
sun.position = new THREE.Vector3(1, -1, 1).normalize();
|
||||
scene.add(sun);
|
||||
|
||||
createObstacles();
|
||||
createObstacles();
|
||||
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.vertices.push( new THREE.Vertex( new THREE.Vector3(0, 0, 0) ) );
|
||||
@@ -95,36 +93,43 @@
|
||||
debugNormal = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: 0xff0000 } ) );
|
||||
scene.add( debugNormal );
|
||||
|
||||
container.onmousemove = onDocumentMouseMove;
|
||||
animate();
|
||||
}
|
||||
container.onmousemove = onDocumentMouseMove;
|
||||
animate();
|
||||
|
||||
function createObstacles(){
|
||||
createCube(100, 50, 10, new THREE.Vector3( 20, 0, 100), Math.PI / 4);
|
||||
}
|
||||
|
||||
function createObstacles(){
|
||||
|
||||
createCube(100, 50, 10, new THREE.Vector3( 20, 0, 100), Math.PI / 4);
|
||||
camera.target = createCube(100, 50, 10, new THREE.Vector3(-20, 0, 200), -Math.PI / 4);
|
||||
createCube(100, 50, 10, new THREE.Vector3( 20, 0, 300), Math.PI / 4);
|
||||
}
|
||||
createCube(100, 50, 10, new THREE.Vector3( 20, 0, 300), Math.PI / 4);
|
||||
|
||||
function createCube(sx, sy, sz, p, ry){
|
||||
|
||||
var cube = new THREE.Mesh( new THREE.CubeGeometry( sx, sy, sz ), new THREE.MeshLambertMaterial( { color: 0x003300 } ) );
|
||||
cube.position = p;
|
||||
cube.rotation.y = ry;
|
||||
scene.add(cube);
|
||||
THREE.Collisions.colliders.push( THREE.CollisionUtils.MeshOBB(cube) );
|
||||
}
|
||||
|
||||
function createCube(sx, sy, sz, p, ry){
|
||||
|
||||
var cube = new THREE.Mesh( new THREE.CubeGeometry( sx, sy, sz ), new THREE.MeshLambertMaterial( { color: 0x003300 } ) );
|
||||
cube.position = p;
|
||||
cube.rotation.y = ry;
|
||||
scene.add(cube);
|
||||
THREE.Collisions.colliders.push( THREE.CollisionUtils.MeshOBB(cube) );
|
||||
cubes.push(cube);
|
||||
return cube;
|
||||
}
|
||||
|
||||
function onDocumentMouseMove(event){
|
||||
event.preventDefault();
|
||||
mouse2d.x = (event.clientX / window.innerWidth) * 2 - 1;
|
||||
mouse2d.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||
mouse2d.z = 1;
|
||||
}
|
||||
}
|
||||
|
||||
function animate(){
|
||||
requestAnimationFrame(animate);
|
||||
function onDocumentMouseMove(event){
|
||||
|
||||
event.preventDefault();
|
||||
mouse2d.x = (event.clientX / window.innerWidth) * 2 - 1;
|
||||
mouse2d.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||
mouse2d.z = 1;
|
||||
|
||||
}
|
||||
|
||||
function animate(){
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
|
||||
for (var i = 0; i < cubes.length; i++) {
|
||||
cubes[i].materials[0].color = new THREE.Color(0x003300);
|
||||
@@ -149,31 +154,31 @@
|
||||
debugNormal.geometry.vertices[1].position = poi.clone().addSelf( c.normal.clone() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(sphere.position.z > range) sphere.position = new THREE.Vector3(0,0,0);
|
||||
if (sphere.position.z > range) sphere.position = new THREE.Vector3(0,0,0);
|
||||
|
||||
camera.position.x = Math.cos(mouse2d.x * Math.PI) * 300;
|
||||
camera.position.y = Math.cos(mouse2d.y * Math.PI) * 300;
|
||||
camera.position.z = 200 + Math.sin(mouse2d.x * Math.PI) * 300 + Math.sin(mouse2d.y * Math.PI) * 300;
|
||||
|
||||
renderer.render(scene, camera);
|
||||
}
|
||||
renderer.render(scene, camera);
|
||||
|
||||
function vts(v){
|
||||
if (!v)
|
||||
return "undefined<br>";
|
||||
else
|
||||
return v.x + " , " + v.y + " , " + v.z + "<br>";
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init();">
|
||||
<div id="info">
|
||||
</div>
|
||||
<div id="options">
|
||||
</div>
|
||||
</body>
|
||||
function vts(v) {
|
||||
|
||||
if (!v)
|
||||
return "undefined<br>";
|
||||
else
|
||||
return v.x + " , " + v.y + " , " + v.z + "<br>";
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init();">
|
||||
<div id="info">
|
||||
</div>
|
||||
<div id="options">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -106,7 +106,7 @@ THREE.ColladaLoader = function () {
|
||||
|
||||
for ( var i = 0; i < daeScene.nodes.length; i ++ ) {
|
||||
|
||||
scene.addChild( createSceneGraph( daeScene.nodes[ i ] ) );
|
||||
scene.add( createSceneGraph( daeScene.nodes[ i ] ) );
|
||||
|
||||
}
|
||||
|
||||
@@ -675,7 +675,7 @@ THREE.ColladaLoader = function () {
|
||||
|
||||
}
|
||||
|
||||
obj.addChild( mesh );
|
||||
obj.add( mesh );
|
||||
|
||||
}
|
||||
|
||||
@@ -683,7 +683,7 @@ THREE.ColladaLoader = function () {
|
||||
|
||||
for ( i = 0; i < node.nodes.length; i ++ ) {
|
||||
|
||||
obj.addChild(createSceneGraph(node.nodes[i], node));
|
||||
obj.add( createSceneGraph( node.nodes[i], node ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user