summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
authorpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-17 21:23:53 +0000
committerpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-17 21:23:53 +0000
commite106b901229419b078903bdd7f2bac97f2932bdc (patch)
tree119ccaea0417e96a24c08d9cdcb115bae3a1abbc /o3d
parent4cc9a1751f50ee33ec0ddcd00267ac7edfc270b9 (diff)
downloadchromium_src-e106b901229419b078903bdd7f2bac97f2932bdc.zip
chromium_src-e106b901229419b078903bdd7f2bac97f2932bdc.tar.gz
chromium_src-e106b901229419b078903bdd7f2bac97f2932bdc.tar.bz2
Got the yard and seven_shapes models to convert to pure-json. This would have been trivial, it turns out, except one little bug where if there weren't other files mentioned in the json, it didn't finish loading. Added some comments to smooth things over.
Review URL: http://codereview.chromium.org/2861004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50138 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r--o3d/samples/o3d-webgl/archive_request.js38
-rw-r--r--o3d/samples/samples_gen.py19
2 files changed, 39 insertions, 18 deletions
diff --git a/o3d/samples/o3d-webgl/archive_request.js b/o3d/samples/o3d-webgl/archive_request.js
index e35282a..aa45ec6 100644
--- a/o3d/samples/o3d-webgl/archive_request.js
+++ b/o3d/samples/o3d-webgl/archive_request.js
@@ -144,9 +144,12 @@ o3d.ArchiveRequest.prototype.open =
};
/**
- * Send the request.
- * Unlike XMLHttpRequest the onreadystatechange callback will be called no
- * matter what, with success or failure.
+ * Sends the request. In this implementation, this function sets up a callback
+ * which searches the json it loads for more files to load. It then sends
+ * requests for each of those files. When the last of those files has loaded,
+ * the onreadystatechange callback will get called. Unlike XMLHttpRequest the
+ * onreadystatechange callback will be called no matter what, with success or
+ * failure.
*/
o3d.ArchiveRequest.prototype.send = function() {
var that = this;
@@ -158,12 +161,9 @@ o3d.ArchiveRequest.prototype.send = function() {
// elsewhere to reconstitute it, which is risky.
var filteredJSON = JSON.stringify(JSON.parse(sourceJSON));
- if (that.onfileavailable) {
- var rawData = new o3d.RawData();
- rawData.uri = 'scene.json';
- rawData.stringValue = filteredJSON;
- that.onfileavailable(rawData);
- }
+ var rawData = new o3d.RawData();
+ rawData.uri = 'scene.json';
+ rawData.stringValue = filteredJSON;
// In o3d-webgl, the "archive" is really just the top-level
// scene.json. We run a regexp on it to find URIs for certain
@@ -176,7 +176,8 @@ o3d.ArchiveRequest.prototype.send = function() {
uris.push(matchArray[1]);
}
- that.pendingRequests_ = uris.length;
+ // Plus one for the current request.
+ that.pendingRequests_ = uris.length + 1;
// Issue requests for each of these URIs.
for (var ii = 0; ii < uris.length; ++ii) {
@@ -189,7 +190,7 @@ o3d.ArchiveRequest.prototype.send = function() {
rawData.uri = uri;
rawData.stringValue = value;
}
- that.decrementPendingRequests_(rawData, exc);
+ that.resolvePendingRequest_(rawData, exc);
};
o3djs.io.loadTextFile(that.relativeToAbsoluteURI_(uri),
completion);
@@ -203,16 +204,18 @@ o3d.ArchiveRequest.prototype.send = function() {
var rawData = new o3d.RawData();
rawData.uri = uri;
rawData.image_ = image;
- that.decrementPendingRequests_(rawData, exc);
+ that.resolvePendingRequest_(rawData, exc);
};
image.onerror = function() {
- that.decrementPendingRequests_(null, exc);
+ that.resolvePendingRequest_(null, exc);
}
image.src = that.relativeToAbsoluteURI_(uri);
};
func(uris[ii]);
}
}
+
+ that.resolvePendingRequest_(rawData);
};
o3djs.io.loadTextFile(this.uri, callback);
@@ -247,10 +250,15 @@ o3d.ArchiveRequest.prototype.stringEndsWith_ = function(string, suffix) {
};
/**
- * Decrements the number of pending requests.
+ * Decrements the number of pending requests. Calls onfileavailable callback
+ * if one is provided, calls onreadystatechange if this is the last of the
+ * requests.
+ * @param {o3d.RawData} rawData The current raw data object.
+ * @param {function(!o3d.RawData): void} An optional callback to call passing
+ * the current raw data as an argument.
* @private
*/
-o3d.ArchiveRequest.prototype.decrementPendingRequests_ =
+o3d.ArchiveRequest.prototype.resolvePendingRequest_ =
function(rawData, opt_exc) {
this.success = this.success && rawData && (!opt_exc);
if (opt_exc != null) {
diff --git a/o3d/samples/samples_gen.py b/o3d/samples/samples_gen.py
index 443fd77..7184811 100644
--- a/o3d/samples/samples_gen.py
+++ b/o3d/samples/samples_gen.py
@@ -3,11 +3,17 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# This script generates gyp code to build the contents of the assets directory.
+
import posixpath
import sys
import os.path
output_filename = 'samples_gen.gyp'
+
+# Set to true to make json output more human readable.
+pretty_print = False
+
try:
output_file = open(output_filename, "w+")
except IOError:
@@ -37,10 +43,10 @@ assets = [
{'path': 'convert_assets/part1.zip', 'up': y_up},
{'path': 'convert_assets/part2.zip', 'up': y_up},
{'path': 'convert_assets/part3.zip', 'up': y_up},
- {'path': 'convert_assets/seven_shapes.zip', 'up': y_up},
+ {'path': 'convert_assets/seven_shapes.zip', 'up': y_up, 'webgl': True},
{'path': 'convert_assets/stencil_frame.zip', 'up': y_up},
{'path': 'convert_assets/teapot.zip', 'up': y_up, 'webgl': True},
- {'path': 'convert_assets/yard.zip', 'up': y_up},
+ {'path': 'convert_assets/yard.zip', 'up': y_up, 'webgl': True},
{'path': 'home-configurators/convert_cbassets/Agra_Rug.kmz', 'up': z_up},
{'path': 'home-configurators/convert_cbassets/Asimi_Rug.kmz', 'up': z_up},
{'path': 'home-configurators/convert_cbassets/Camden_Chair.kmz', 'up': z_up},
@@ -65,13 +71,16 @@ assets = [
{'path': 'home-configurators/convert_cbassets/Troy_Twin_Sleeper.kmz', 'up': z_up},
{'path': 'io/convert_levels/all_actors.kmz', 'up': y_up},
{'path': 'io/convert_levels/map1.kmz', 'up': y_up},
- {'path': 'simpleviewer/convert_assets/cube.zip', 'up': y_up, 'webgl': True},
+ {'path': 'simpleviewer/convert_assets/cube.zip', 'up': y_up, 'webgl': True}
]
output_file.write("""# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# THIS FILE IS AUTOMATICALLY GENERATED by the script samples_gen.py Do not
+# edit this file. Instead edit samples_gen.py.
+
{
'variables': {
'chromium_code': 1,
@@ -100,10 +109,12 @@ def write_action(asset, webgl_mode):
output_base = posixpath.splitext(output)[0]
output_tgz = output_base + ".o3dtgz"
output_json = output_base + "/scene.json"
+
output = output_tgz
if webgl_mode:
output = output_json
output_dir = posixpath.dirname(output)
+
output_file.write(" {\n")
output_file.write(" 'action_name': '%s',\n" % name)
output_file.write(" 'inputs': [\n")
@@ -136,6 +147,8 @@ def write_action(asset, webgl_mode):
output_file.write(" '<(PRODUCT_DIR)/o3dConverter',\n")
output_file.write(" '--no-condition',\n")
output_file.write(" '--up-axis=%s',\n" % asset['up'])
+ if pretty_print:
+ output_file.write(" '--pretty-print',\n")
if webgl_mode:
output_file.write(" '--no-binary',\n")
output_file.write(" '--no-archive',\n")