HTML5 Canvas Library

ready Library Method

Short Description: Return (download) Status

Signature: x.ready ()
Class: taccglOBJFile Class

ready returns "ready" if and when the associated OBJ file has been downloaded, parsed, and is ready for use. It returns "loading" while the file is being downloaded, "error" if there was an error downloading, or "ddmode" if the file is not downloaded because 3D canvas is not available. Using ready or alternatively taccglOBJFile.onload is required if asynchroneously downloading the OBJ file (using async=true) using OBJFile.

There is the general problem that OBJ files are downloaded separately from the internet page and so may not yet be available when an animation is started. Also downloading may take a while, especially in case of big 3D models.

The first thing that needs to be decided is when to start downloading the OBJ files. You can do so immediately after the page has been loaded (e.g. in a script at the end of the page or in the pages onload event handler) or you can start the download only after the user clicked on a button (e.g. to start the animation). The first option might download OBJ files that later on are not needed and the second option requires the user to wait longer.

The second problem one needs to deal with occurs when an animation should be played but the required OBJ file is not yet downloaded. The easiest solution is to use async=false) in OBJFile. Second solution is to show an alternative simpler animation as replacement. This is what ready is very useful for as shown in the example below. Third solution is to wait until the file has been downloaded and is explained in taccglOBJFile.onload.

If the OBJFile refers to an MTL file, then ready becomes true if and when the mtl file has been downloaded and parsed as well, or when it has been determined that the MTL file is not present.

You can use other methods like taccglOBJFile.scene or taccglOBJFile.objs only if an when ready became "ready".

The following example shows a simple replacement animation if and as long ready() does not return "ready". This normally means that upon your first try, the download is started and the replacement animation shown. Upon the second click usually the download is finished and the real animation is shown. However, if there was an error downloading or in ddmode always the replacement animation is shown.


      if (!window.taccgldocfile) taccgldocfile=taccgl.objFile().read('/objtest/taccgldoc.obj',true);
      if (taccgldocfile.ready()=="ready")   {
         var a=taccgl.a("Layout",taccgldocfile.objs("Torus")).modFit(). rotateMiddle(0.7,0.7,0).dur(3).start();
      } else {  // show replacement animation
         var"Layout"). rotateMiddle(0.7,0.7,0).dur(3).start();

WebGL™ is a trademark of the Khronos Group Inc.

Next Page:taccglOBJFile.error - Return error message
Previous Page: UV Map Creation
Please Add a Comment or Question, click here!