graphic-o3d-samples-o3djs-io.js / js
@fileoverview This file contains various functions and class for io.
A Module with various io functions and classes. @namespace
Creates a LoadInfo object.
parameter: {!o3d.ArchiveRequest} opt_request The request to watch.
parameter: {boolean} opt_hasStatus true if opt_request is a o3d.ArchiveRequest vs for example an o3d.FileRequest or an XMLHttpRequest.
returns: {!o3djs.io.LoadInfo} The new LoadInfo.
see: o3djs.io.LoadInfo
A class to help with progress reporting for most loading utilities. Example: <pre> var g_loadInfo = null; g_id = window.setInterval(statusUpdate, 500); g_loadInfo = o3djs.scene.loadScene(client, pack, parent, 'http://google.com/somescene.tgz', callback); function callback(pack, parent, exception) { g_loadInfo = null; window.clearInterval(g_id); if (!exception) { // do something with scene just loaded } } function statusUpdate() { if (g_loadInfo) { var progress = g_loadInfo.getKnownProgressInfoSoFar(); document.getElementById('loadstatus').innerHTML = progress.percent; } } </pre> @constructor
parameter: {!o3d.ArchiveRequest} opt_request The request to watch.
parameter: {boolean} opt_hasStatus true if opt_request is a o3d.ArchiveRequest vs for example an o3d.FileRequest or an XMLHttpRequest.
see: o3djs.scene.loadScene
see: o3djs.io.loadArchive
see: o3djs.io.loadTexture
see: o3djs.loader.Loader
Adds another LoadInfo as a child of this LoadInfo so they can be managed as a group.
parameter: {!o3djs.io.LoadInfo} loadInfo The child LoadInfo.
Marks this LoadInfo as finished.
Gets the total bytes that will be streamed known so far. If you are only streaming 1 file then this will be the info for that file but if you have queued up many files using a o3djs.loader.Loader only a couple of files are streamed at a time meaning that the size is not known for files that have yet started to download. If you are downloading many files for your application and you want to provide a progress status you have about 4 options 1) Use LoadInfo.getTotalBytesDownloaded() / LoadInfo.getTotalKnownBytesToStreamSoFar() and just be aware the bar will grown and then shrink as new files start to download and their lengths become known. 2) Use LoadInfo.getTotalRequestsDownloaded() / LoadInfo.getTotalKnownRequestsToStreamSoFar() and be aware the granularity is not all that great since it only reports fully downloaded files. If you are downloading a bunch of small files this might be ok. 3) Put all your files in one archive. Then there will be only one file and method 1 will work well. 4) Figure out the total size in bytes of the files you will download and put that number in your application, then use LoadInfo.getTotalBytesDownloaded() / MY_APPS_TOTAL_BYTES_TO_DOWNLOAD.
returns: {number} The total number of currently known bytes to be streamed.
Gets the total bytes downloaded so far.
returns: {number} The total number of currently known bytes to be streamed.
Gets the total streams that will be download known so far. We can't know all the streams since you could use a o3djs.loader.Loader object, request some streams, then call this function, then request some more. See LoadInfo.getTotalKnownBytesToStreamSoFar for details.
returns: {number} The total number of requests currently known to be streamed.
see: o3djs.io.LoadInfo.getTotalKnownBytesToStreamSoFar
Gets the total requests downloaded so far.
returns: {number} The total requests downloaded so far.
Gets progress info. This is commonly formatted version of the information available from a LoadInfo. See LoadInfo.getTotalKnownBytesToStreamSoFar for details.
returns: {percent: number, downloaded: string, totalBytes: string, base: number, suffix: string} progress info.
see: o3djs.io.LoadInfo.getTotalKnownBytesToStreamSoFar
Loads text from an external file. This function is synchronous.
parameter: {string} url The url of the external file.
returns: {string} the loaded text if the request is synchronous.
Loads text from an external file. This function is asynchronous.
parameter: {string} url The url of the external file.
parameter: {function(string, *): void} callback A callback passed the loaded string and an exception which will be null on success.
returns: {!o3djs.io.LoadInfo} A LoadInfo to track progress.
A ArchiveInfo object loads and manages an archive of files. There are methods for locating a file by uri and for freeing the archive. You can only read archives that have as their first file a file named 'aaaaaaaa.o3d' the contents of the which is 'o3d'. This is to prevent O3D from being used to read arbitrary tar gz files. Example: <pre> var loadInfo = o3djs.io.loadArchive(pack, 'http://google.com/files.tgz', callback); function callback(archiveInfo, exception) { if (!exception) { pack.createTextureFromRawData( archiveInfo.getFileByURI('logo.jpg'), true); pack.createTextureFromRawData( archiveInfo.getFileByURI('wood/oak.png'), true); pack.createTextureFromRawData( archiveInfo.getFileByURI('wood/maple.dds'), true); archiveInfo.destroy(); } else { alert(exception); } } </pre> @constructor
parameter: {!o3d.Pack} pack Pack to create request in.
parameter: {string} url The url of the archive file.
parameter: {!function(!o3djs.io.ArchiveInfo, *): void} onFinished A callback that is called when the archive is finished loading and passed the ArchiveInfo and an exception which is null on success.
The list of files in the archive by uri. @type {!Object}
The pack used to create the archive request. @type {!o3d.Pack}
True if this archive has not be destroyed. @type {boolean}
Records each RawData file as it comes in. @private
parameter: {!o3d.RawData} rawData RawData from archive request.
The LoadInfo to track loading progress. @type {!o3djs.io.LoadInfo}
Releases all the RAW data associated with this archive. It does not release any objects created from that RAW data.
Gets files by regular expression or wildcards from the archive.
parameter: {(string|!RegExp)} uri of file to get. Can have wildcards '*' and '?'.
parameter: {boolean} opt_caseInsensitive Only valid if it's a wildcard string.
returns: {!Array.} An array of the matching RawDatas for the files matching or undefined if it doesn't exist.
Gets a file by URI from the archive.
parameter: {string} uri of file to get.
parameter: {boolean} opt_caseInsensitive True to be case insensitive. Default false.
returns: {(o3d.RawData|undefined)} The RawData for the file or undefined if it doesn't exist.
Loads an archive file. When the entire archive is ready the onFinished callback will be called with an ArchiveInfo for accessing the archive.
parameter: {!o3d.Pack} pack Pack to create request in.
parameter: {string} url The url of the archive file.
parameter: {!function(!o3djs.io.ArchiveInfo, *): void} onFinished A callback that is called when the archive is successfully loaded and an Exception object which is null on success.
returns: {!o3djs.io.LoadInfo} The a LoadInfo for tracking progress.
see: o3djs.io.ArchiveInfo
Loads an archive file. This function is asynchronous. This is a low level version of o3djs.io.loadArchive which can be used for things like progressive loading.
parameter: {!o3d.Pack} pack Pack to create request in.
parameter: {string} url The url of the archive file.
parameter: {!function(RawData): void} onFileAvailable A callback, taking a single argument 'data'. As each file is loaded from the archive, this function is called with the file's data.
parameter: {!function(!o3d.ArchiveRequest, *): void} onFinished A callback that is called when the archive is successfully loaded. It is passed the ArchiveRquest and null on success or a javascript exception on failure.
returns: {!o3djs.io.LoadInfo} A LoadInfo for tracking progress.
Loads a texture. Textures are loaded asynchronously. Example: <pre> var loadInfo = o3djs.io.loadTexture(pack, 'http://google.com/someimage.jpg', callback); function callback(texture, exception) { if (!exception) { g_mySampler.texture = texture; } else { alert(exception); } } </pre>
parameter: {!o3d.Pack} pack Pack to load texture into.
parameter: {string} url URL of texture to load.
parameter: {!function(!o3d.Texture, *): void} callback Callback when texture is loaded. It will be passed the texture and an exception on error or null on success.
returns: {!o3djs.io.LoadInfo} A LoadInfo to track progress.
see: o3djs.io.createLoader
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.