Prepare for reading and processing model file content

This commit is contained in:
David Rowe 2014-07-20 15:14:48 -07:00
parent ed1b058cb1
commit 2be03ada9c

View file

@ -60,44 +60,80 @@ var mode = 0;
var modelUploader = (function () { var modelUploader = (function () {
var that = {}, var that = {},
urlBase = "http://public.highfidelity.io/meshes/"; urlBase = "http://public.highfidelity.io/meshes/",
model;
that.upload = function (file, callback) { function readModel(file) {
var url, var url,
reqRead, req;
reqSend;
print("Reading model from " + file);
// Read model content ...
url = "file:///" + file; url = "file:///" + file;
print("Reading model from " + url); req = new XMLHttpRequest();
reqRead = new XMLHttpRequest(); req.open("GET", url, false);
reqRead.open("GET", url, false); req.responseType = "arraybuffer";
reqRead.responseType = "arraybuffer"; req.send();
reqRead.send(); if (req.status !== 200) {
if (reqRead.status !== 200) { print("Error reading file: " + req.status + " " + req.statusText);
print("Error reading file: " + reqRead.status + " " + reqRead.statusText); Window.alert("Could not read file " + req.status + " " + req.statusText);
Window.alert("Could not read file " + reqRead.status + " " + reqRead.statusText); return false;
return;
} }
model = req.response;
// Upload to High Fidelity ... return true;
url = urlBase + file.replace(/^(.*[\/\\])*/, ""); }
print("Uploading model to " + url);
reqSend = new XMLHttpRequest(); function setProperties() {
reqSend.open("PUT", url, true); print("Setting model properties");
reqSend.responseType = "arraybuffer"; return true;
reqSend.onreadystatechange = function () { }
if (reqSend.readyState === reqSend.DONE) {
if (reqSend.status === 200) { function createHttpMessage() {
print("Uploaded model"); print("Putting model into HTTP message");
return true;
}
function sendToHighFidelity(url, callback) {
var req;
print("Sending model to High Fidelity");
req = new XMLHttpRequest();
req.open("PUT", url, true);
req.responseType = "arraybuffer";
req.onreadystatechange = function () {
if (req.readyState === req.DONE) {
if (req.status === 200) {
print("Uploaded model: " + url);
callback(url); callback(url);
} else { } else {
print("Error uploading file: " + reqSend.status + " " + reqSend.statusText); print("Error uploading file: " + req.status + " " + req.statusText);
Window.alert("Could not upload file: " + reqSend.status + " " + reqSend.statusText); Window.alert("Could not upload file: " + req.status + " " + req.statusText);
} }
} }
}; };
reqSend.send(reqRead.response); req.send(model);
}
that.upload = function (file, callback) {
var url = urlBase + file.replace(/^(.*[\/\\])*/, ""),
ok;
// Read model content ...
ok = readModel(file);
if (!ok) { return; }
// Set model properties ...
ok = setProperties();
if (!ok) { return; }
// Put model in HTTP message ...
ok = createHttpMessage();
if (!ok) { return; }
// Send model to High Fidelity ...
sendToHighFidelity(url, callback);
}; };
return that; return that;