From 7a130f3789ad66ea6a3ed381c0a581ac3dab9bf3 Mon Sep 17 00:00:00 2001 From: "petersont@google.com" Date: Fri, 26 Feb 2010 18:17:10 +0000 Subject: First check in of the o3d implimentation in webgl. Classes work well enough to run the hellocube sample. Review URL: http://codereview.chromium.org/561026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40133 0039d316-1c4b-4281-b951-d872f2087c98 --- o3d/samples/o3d-webgl-samples/hellocube.html | 300 ++++++++ o3d/samples/o3d-webgl/base.js | 211 ++++++ o3d/samples/o3d-webgl/bitmap.js | 140 ++++ o3d/samples/o3d-webgl/bounding_box.js | 124 ++++ o3d/samples/o3d-webgl/buffer.js | 280 ++++++++ o3d/samples/o3d-webgl/clear_buffer.js | 125 ++++ o3d/samples/o3d-webgl/client.js | 841 ++++++++++++++++++++++ o3d/samples/o3d-webgl/draw_context.js | 70 ++ o3d/samples/o3d-webgl/draw_element.js | 69 ++ o3d/samples/o3d-webgl/draw_list.js | 106 +++ o3d/samples/o3d-webgl/draw_pass.js | 77 ++ o3d/samples/o3d-webgl/effect.js | 424 +++++++++++ o3d/samples/o3d-webgl/element.js | 214 ++++++ o3d/samples/o3d-webgl/event.js | 260 +++++++ o3d/samples/o3d-webgl/field.js | 134 ++++ o3d/samples/o3d-webgl/file_request.js | 170 +++++ o3d/samples/o3d-webgl/material.js | 77 ++ o3d/samples/o3d-webgl/named_object.js | 72 ++ o3d/samples/o3d-webgl/named_object_base.js | 47 ++ o3d/samples/o3d-webgl/object_base.js | 69 ++ o3d/samples/o3d-webgl/pack.js | 348 +++++++++ o3d/samples/o3d-webgl/param.js | 829 ++++++++++++++++++++++ o3d/samples/o3d-webgl/param_object.js | 169 +++++ o3d/samples/o3d-webgl/primitive.js | 157 +++++ o3d/samples/o3d-webgl/raw_data.js | 94 +++ o3d/samples/o3d-webgl/ray_intersection_info.js | 77 ++ o3d/samples/o3d-webgl/render_node.js | 205 ++++++ o3d/samples/o3d-webgl/render_surface.js | 89 +++ o3d/samples/o3d-webgl/render_surface_set.js | 74 ++ o3d/samples/o3d-webgl/shape.js | 128 ++++ o3d/samples/o3d-webgl/state.js | 567 +++++++++++++++ o3d/samples/o3d-webgl/state_set.js | 62 ++ o3d/samples/o3d-webgl/stream.js | 101 +++ o3d/samples/o3d-webgl/stream_bank.js | 101 +++ o3d/samples/o3d-webgl/texture.js | 463 ++++++++++++ o3d/samples/o3d-webgl/transform.js | 942 +++++++++++++++++++++++++ o3d/samples/o3d-webgl/tree_traversal.js | 111 +++ o3d/samples/o3d-webgl/types.js | 119 ++++ o3d/samples/o3d-webgl/viewport.js | 96 +++ o3d/samples/o3djs/webgl.js | 114 +++ 40 files changed, 8656 insertions(+) create mode 100644 o3d/samples/o3d-webgl-samples/hellocube.html create mode 100644 o3d/samples/o3d-webgl/base.js create mode 100644 o3d/samples/o3d-webgl/bitmap.js create mode 100644 o3d/samples/o3d-webgl/bounding_box.js create mode 100644 o3d/samples/o3d-webgl/buffer.js create mode 100644 o3d/samples/o3d-webgl/clear_buffer.js create mode 100644 o3d/samples/o3d-webgl/client.js create mode 100644 o3d/samples/o3d-webgl/draw_context.js create mode 100644 o3d/samples/o3d-webgl/draw_element.js create mode 100644 o3d/samples/o3d-webgl/draw_list.js create mode 100644 o3d/samples/o3d-webgl/draw_pass.js create mode 100644 o3d/samples/o3d-webgl/effect.js create mode 100644 o3d/samples/o3d-webgl/element.js create mode 100644 o3d/samples/o3d-webgl/event.js create mode 100644 o3d/samples/o3d-webgl/field.js create mode 100644 o3d/samples/o3d-webgl/file_request.js create mode 100644 o3d/samples/o3d-webgl/material.js create mode 100644 o3d/samples/o3d-webgl/named_object.js create mode 100644 o3d/samples/o3d-webgl/named_object_base.js create mode 100644 o3d/samples/o3d-webgl/object_base.js create mode 100644 o3d/samples/o3d-webgl/pack.js create mode 100644 o3d/samples/o3d-webgl/param.js create mode 100644 o3d/samples/o3d-webgl/param_object.js create mode 100644 o3d/samples/o3d-webgl/primitive.js create mode 100644 o3d/samples/o3d-webgl/raw_data.js create mode 100644 o3d/samples/o3d-webgl/ray_intersection_info.js create mode 100644 o3d/samples/o3d-webgl/render_node.js create mode 100644 o3d/samples/o3d-webgl/render_surface.js create mode 100644 o3d/samples/o3d-webgl/render_surface_set.js create mode 100644 o3d/samples/o3d-webgl/shape.js create mode 100644 o3d/samples/o3d-webgl/state.js create mode 100644 o3d/samples/o3d-webgl/state_set.js create mode 100644 o3d/samples/o3d-webgl/stream.js create mode 100644 o3d/samples/o3d-webgl/stream_bank.js create mode 100644 o3d/samples/o3d-webgl/texture.js create mode 100644 o3d/samples/o3d-webgl/transform.js create mode 100644 o3d/samples/o3d-webgl/tree_traversal.js create mode 100644 o3d/samples/o3d-webgl/types.js create mode 100644 o3d/samples/o3d-webgl/viewport.js create mode 100644 o3d/samples/o3djs/webgl.js (limited to 'o3d') diff --git a/o3d/samples/o3d-webgl-samples/hellocube.html b/o3d/samples/o3d-webgl-samples/hellocube.html new file mode 100644 index 0000000..f0db297f --- /dev/null +++ b/o3d/samples/o3d-webgl-samples/hellocube.html @@ -0,0 +1,300 @@ + + + + + + + + +Hello Cube: Getting started with O3D + + + + + + +

Hello Cube

+This example shows how to display a spinning red cube in O3D. +
+ + +
+ + + +
+ + + + +
+ + diff --git a/o3d/samples/o3d-webgl/base.js b/o3d/samples/o3d-webgl/base.js new file mode 100644 index 0000000..9863ee6 --- /dev/null +++ b/o3d/samples/o3d-webgl/base.js @@ -0,0 +1,211 @@ +/* + * 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 = ''; + +/** + * 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('