/* * Copyright 2010, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * @fileoverview Base for all o3d classes implemented in javscript. * Include just this file in a script tag and it will include all other * source files needed by o3d. * For more information about o3d see * http://code.google.com/p/o3d. */ /** * A namespace for all the o3d classes. * @namespace */ var o3d = o3d || {}; /** * Define this because the Google internal JSCompiler needs goog.typedef below. */ var goog = goog || {}; /** * A macro for defining composite types. * * By assigning goog.typedef to a name, this tells Google internal JSCompiler * that this is not the name of a class, but rather it's the name of a composite * type. * * For example, * /** @type {Array|NodeList} / goog.ArrayLike = goog.typedef; * will tell JSCompiler to replace all appearances of goog.ArrayLike in type * definitions with the union of Array and NodeList. * * Does nothing in uncompiled code. */ goog.typedef = true; /** * Reference to the global context. In most cases this will be 'window'. */ o3d.global = this; /** * Path for included scripts. * @type {string} */ o3d.basePath = ''; /** * Some javascripts don't support __defineGetter__ or __defineSetter__ * so we define some here so at least we don't get compile errors. * We expect the initialzation code will check and complain. This stubs * are just here to make sure we can actually get to the initialization code. */ if (!Object.prototype.__defineSetter__) { Object.prototype.__defineSetter__ = function() {} Object.prototype.__defineGetter__ = function() {} } /** * Tries to detect the base path of the base.js script that * bootstraps the o3d libraries. * @private */ o3d.findBasePath_ = function() { var doc = o3d.global.document; if (typeof doc == 'undefined') { return; } if (o3d.global.BASE_PATH) { o3d.basePath = o3d.global.BASE_PATH; return; } else { // HACK to hide compiler warnings :( o3d.global.BASE_PATH = null; } var scripts = doc.getElementsByTagName('script'); for (var script, i = 0; script = scripts[i]; i++) { var src = script.src; var l = src.length; var s = 'o3d-webgl/base.js'; var sl = s.length; if (src.substr(l - sl) == s) { o3d.basePath = src.substr(0, l - sl) + 'o3d-webgl/'; return; } } }; /** * Writes a script tag for the given o3d source file name * to the document. (Must be called at execution time.) * @param {string} src The full path to the source file. * @private */ o3d.writeScriptTag_ = function(src) { var doc = o3d.global.document; if (typeof doc != 'undefined') { doc.write('