Browse Source

Merge remote branch 'alteredq/skinning' into skinning

Mr.doob 14 years ago
parent
commit
5b8f3700ad
3 changed files with 28 additions and 87 deletions
  1. 1 3
      build/ThreeExtras.js
  2. 15 12
      examples/ribbons_gl.html
  3. 12 72
      src/extras/MiscUtils.js

+ 1 - 3
build/ThreeExtras.js

@@ -280,9 +280,7 @@ THREE.Detector={canvas:!!document.createElement("canvas").getContext,webgl:windo
 c;c=d.style;c.fontFamily="monospace";c.fontSize="13px";c.textAlign="center";c.background="#eee";c.color="#000";c.padding="1em";c.width="475px";c.margin="5em auto 0";a.appendChild(d);b.appendChild(a);return d}};
 var GeometryUtils={merge:function(a,b){var c=b instanceof THREE.Mesh,d=a.vertices.length,f=c?b.geometry:b,g=a.vertices,h=f.vertices,k=a.faces,j=f.faces,m=a.uvs;f=f.uvs;c&&b.autoUpdateMatrix&&b.updateMatrix();for(var o=0,w=h.length;o<w;o++){var u=new THREE.Vertex(h[o].position.clone());c&&b.localMatrix.multiplyVector3(u.position);g.push(u)}o=0;for(w=j.length;o<w;o++){h=j[o];var t,x=h.vertexNormals;if(h instanceof THREE.Face3)t=new THREE.Face3(h.a+d,h.b+d,h.c+d);else h instanceof THREE.Face4&&(t=new THREE.Face4(h.a+
 d,h.b+d,h.c+d,h.d+d));t.centroid.copy(h.centroid);t.normal.copy(h.normal);c=0;for(g=x.length;c<g;c++){u=x[c];t.vertexNormals.push(u.clone())}t.materials=h.materials.slice();k.push(t)}o=0;for(w=f.length;o<w;o++){d=f[o];k=[];c=0;for(g=d.length;c<g;c++)k.push(new THREE.UV(d[c].u,d[c].v));m.push(k)}}},ImageUtils={loadTexture:function(a,b,c){var d=new Image;d.onload=function(){this.loaded=!0;c&&c(this)};d.src=a;return new THREE.Texture(d,b)},loadArray:function(a,b){var c,d,f=[];c=f.loadCount=0;for(d=a.length;c<
-d;++c){f[c]=new Image;f[c].loaded=0;f[c].onload=function(){f.loadCount+=1;this.loaded=!0;b&&b(this)};f[c].src=a[c]}return f}};
-THREE.requestAnimationFrame=function(a,b){if(!THREE.requestAnimationFrameImpl_)THREE.requestAnimationFrameImpl_=function(){for(var c=[a,window],d=["requestAnimationFrame","webkitRequestAnimationFrame","mozRequestAnimationFrame","operaRequestAnimationFrame","requestAnimationFrame"],f=[function(m){return function(o,w){o[m].call(o,w)}},function(m){return function(o,w){window[m].call(window,w)}}],g=0;g<c.length;++g)for(var h=c[g],k=0;k<d.length;++k){var j=d[k];if(h[j]){console.log("using ",j);return f[g](j)}}console.log("using window.setTimeout");
-return function(m,o){window.setTimeout(o,1E3/70)}}();THREE.requestAnimationFrameImpl_(a,b)};
+d;++c){f[c]=new Image;f[c].loaded=0;f[c].onload=function(){f.loadCount+=1;this.loaded=!0;b&&b(this)};f[c].src=a[c]}return f}};if(!window.requestAnimationFrame)window.requestAnimationFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)}}();
 var SceneUtils={loadScene:function(a,b,c,d){a=new Worker(a);a.postMessage(0);a.onmessage=function(f){function g(){for(o in L.objects)if(!G.objects[o]){A=L.objects[o];if(q=G.geometries[A.geometry]){ba=[];for(i=0;i<A.materials.length;i++)ba[i]=G.materials[A.materials[i]];F=A.position;r=A.rotation;s=A.scale;object=new THREE.Mesh(q,ba);object.position.set(F[0],F[1],F[2]);object.rotation.set(r[0],r[1],r[2]);object.scale.set(s[0],s[1],s[2]);object.visible=A.visible;G.scene.addObject(object);G.objects[o]=
 object}}}function h(U){return function(na){G.geometries[U]=na;g();V-=1;k()}}function k(){d({total_models:Y,total_textures:Z,loaded_models:Y-V,loaded_textures:Z-S},G);V==0&&S==0&&c(G)}var j,m,o,w,u,t,x,A,F,v,I,q,J,e,ba,L,M,V,S,Y,Z,G;L=f.data;M=new THREE.Loader;S=V=0;G={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{}};f=function(){S-=1;k()};for(u in L.cameras){v=L.cameras[u];if(v.type=="perspective")J=new THREE.Camera(v.fov,v.aspect,v.near,v.far);
 else if(v.type=="ortho"){J=new THREE.Camera;J.projectionMatrix=THREE.Matrix4.makeOrtho(v.left,v.right,v.top,v.bottom,v.near,v.far)}F=v.position;v=v.target;J.position.set(F[0],F[1],F[2]);J.target.position.set(v[0],v[1],v[2]);G.cameras[u]=J}for(w in L.lights){u=L.lights[w];if(u.type=="directional"){F=u.direction;light=new THREE.DirectionalLight;light.position.set(F[0],F[1],F[2]);light.position.normalize()}else if(u.type=="point"){F=u.position;light=new THREE.PointLight;light.position.set(F[0],F[1],

+ 15 - 12
examples/ribbons_gl.html

@@ -27,22 +27,24 @@
 				z-index:100;
 				
             }			
-			
-			
-		</style>
+		</style>		
 	</head>
-	<body>
 	
+	<body>
+		
+		<script type="text/javascript" src="../build/ThreeExtras.js"></script>
+		<script type="text/javascript" src="js/Stats.js"></script>
+
         <div id="info">
 			<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl ribbons example
 		</div>
 		
-		<script type="text/javascript" src="../build/ThreeExtras.js"></script>
-		<script type="text/javascript" src="js/Stats.js"></script>
 
 		<script type="text/javascript">
 
 			if ( ! THREE.Detector.webgl ) THREE.Detector.addGetWebGLMessage();
+			
+			window.onload = init;
 
 			var container, stats;
 			var camera, scene, renderer, ribbon, geometry, geometry2, materials = [], ribbons = [],
@@ -58,9 +60,6 @@
 				enabled  : true
 				
 			};
-
-			init();
-			loop();
 			
 			function init() {
 
@@ -168,6 +167,8 @@
 				document.addEventListener( 'touchstart', onDocumentTouchStart, false );
 				document.addEventListener( 'touchmove', onDocumentTouchMove, false );
 				
+				loop();
+				
 			}
 
 			function onDocumentMouseMove( event ) {
@@ -257,9 +258,9 @@
 			}			
 
 			function loop() {
-				
-				THREE.requestAnimationFrame( renderer.domElement, loop );
-				
+
+				requestAnimationFrame( loop, renderer.domElement );
+
 				var time = new Date().getTime() * 0.00005;
 				
 				camera.position.x += ( mouseX - camera.position.x ) * 0.036;
@@ -335,6 +336,8 @@
 
 				stats.update();
 				
+				
+
 			}
 
 

+ 12 - 72
src/extras/MiscUtils.js

@@ -2,75 +2,15 @@
  * @author greggman / http://greggman.com/
  */
  
-THREE.requestAnimationFrame = function( element, callback ) {
-
-	if ( ! THREE.requestAnimationFrameImpl_ ) {
-	
-		THREE.requestAnimationFrameImpl_ = function() {
-	  
-			var objects = [ element, window ];
-			
-			var functionNames = [
-				"requestAnimationFrame",
-				"webkitRequestAnimationFrame",
-				"mozRequestAnimationFrame",
-				"operaRequestAnimationFrame",
-				"requestAnimationFrame"
-			];
-	  
-			var functions = [
-			
-				function ( name ) {
-				
-					return function( element, callback ) {
-						
-								element[ name ].call( element, callback );
-						
-							};
-
-				},
-				
-			
-				function ( name ) {
-			  
-					return function( element, callback ) {
-						
-						window[ name ].call( window, callback );
-
-					};
-
-				}
-
-			];
-		  
-			for ( var ii = 0; ii < objects.length; ++ii ) {
-			
-				var obj = objects[ ii ];
-				for ( var jj = 0; jj < functionNames.length; ++jj ) {
-				
-					var functionName = functionNames[ jj ];
-					if ( obj[ functionName ] ) {
-				
-						console.log( "using ", functionName );
-						return functions[ ii ]( functionName );
-
-					}
-					
-				}
-
-			}
-			
-			console.log( "using window.setTimeout" );
-			
-			return function( element, callback ) {
-			
-			   window.setTimeout(callback, 1000 / 70);
-			   
-			};
-		
-		}();
-	}
-
-	THREE.requestAnimationFrameImpl_( element, callback );
-
-};
+if (!window.requestAnimationFrame) {
+  window.requestAnimationFrame = (function() {
+    return window.requestAnimationFrame ||
+           window.webkitRequestAnimationFrame ||
+           window.mozRequestAnimationFrame ||
+           window.oRequestAnimationFrame ||
+           window.msRequestAnimationFrame ||
+           function(/* function FrameRequestCallback */ callback, /* DOMElement Element */ element) {
+             window.setTimeout(callback, 1000/60);
+           };
+  })();
+};