Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added cross-browser requestAnimFrame to c3dapi.js, modified scene.js …

…to make use of it.
  • Loading branch information...
commit 1731147af5625e23a0f487acb375099ba5dc8c1a 1 parent 7c6a4f9
@Callaghan Callaghan authored
Showing with 55 additions and 37 deletions.
  1. +14 −1 c3dl/c3dapi.js
  2. +41 −36 c3dl/scene.js
View
15 c3dl/c3dapi.js
@@ -159,4 +159,17 @@ c3dl_require('init.js');
//interaction
c3dl_require('interaction/picking.js');
-c3dl_require('interaction/pickingresult.js');
+c3dl_require('interaction/pickingresult.js');
+
+//Function to call the various versions of requestAnimationFrame
+//To be updated when this is properly standardized.
+window.requestAnimFrame = (function(callback){
+ return window.requestAnimationFrame ||
+ window.webkitRequestAnimationFrame ||
+ window.mozRequestAnimationFrame ||
+ window.oRequestAnimationFrame ||
+ window.msRequestAnimationFrame ||
+ function(/* function */ callback, /* DOMElement */ element){
+ window.setTimeout(callback, 1000 / 60);
+ };
+ })();
View
77 c3dl/scene.js
@@ -941,41 +941,8 @@ c3dl.Scene = function ()
return isFound;
}
-
- /**
- Start scene sets a default ambient light to white with full
- intensity. If this ambient lighting is not desired, call
- setAmbientLight(..) after this method, which will undo the
- default ambient light values.
- */
- this.startScene = function ()
- {
- if (c3dl.debug.SHARK === true)
- {
- connectShark();
- startShark();
- }
- numFramesSinceSceneStart = 0;
- frameCounter = 0;
-
- // Safety Checks
- if (glCanvas3D == null) return false;
- if (renderer == null) return false;
- if (camera == null) return false;
-
- // Start the timer
- lastTimeTaken = Date.now();
-
- // Benchmark hook:
- if (typeof(benchmarkSetupDone) == "function") benchmarkSetupDone();
-
- // Create a timer for this object
- timerID = setInterval(this.render, 5);
-
- this.setAmbientLight([ambientLight[0], ambientLight[1], ambientLight[2]]);
- }
-
- /**
+
+/**
@private
Render Loop
*/
@@ -994,7 +961,7 @@ c3dl.Scene = function ()
// If a user wants to stop rendering, this is where it happens
if (exitFlag)
{
- timerID = clearInterval(timerID);
+ //timerID = clearInterval(timerID);
if (c3dl.debug.SHARK === true)
{
stopShark();
@@ -1050,6 +1017,44 @@ c3dl.Scene = function ()
FPS_Counter++;
}
+ this.refresh = function() {
+ thisScn.render();
+ requestAnimFrame(thisScn.refresh);
+ }
+
+ /**
+ Start scene sets a default ambient light to white with full
+ intensity. If this ambient lighting is not desired, call
+ setAmbientLight(..) after this method, which will undo the
+ default ambient light values.
+ */
+ this.startScene = function ()
+ {
+ if (c3dl.debug.SHARK === true)
+ {
+ connectShark();
+ startShark();
+ }
+ numFramesSinceSceneStart = 0;
+ frameCounter = 0;
+
+ // Safety Checks
+ if (glCanvas3D == null) return false;
+ if (renderer == null) return false;
+ if (camera == null) return false;
+
+ // Start the timer
+ lastTimeTaken = Date.now();
+
+ // Benchmark hook:
+ if (typeof(benchmarkSetupDone) == "function") benchmarkSetupDone();
+
+ // Create a timer for this object
+ this.refresh();
+
+ this.setAmbientLight([ambientLight[0], ambientLight[1], ambientLight[2]]);
+ }
+
/**
@private
Updates all objects based on time.
Please sign in to comment.
Something went wrong with that request. Please try again.