mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-27 11:10:15 +02:00
Read raw data of different model file types
This commit is contained in:
parent
3f24f61180
commit
ab0ec9f474
1 changed files with 116 additions and 20 deletions
|
@ -58,28 +58,115 @@ var jointList = MyAvatar.getJointNames();
|
||||||
var mode = 0;
|
var mode = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof String.prototype.fileName !== 'function') {
|
||||||
|
String.prototype.fileName = function (str) {
|
||||||
|
return this.replace(/^(.*[\/\\])*/, "");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof String.prototype.path !== 'function') {
|
||||||
|
String.prototype.path = function (str) {
|
||||||
|
return this.replace(/[\\\/][^\\\/]*$/, "");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var modelUploader = (function () {
|
var modelUploader = (function () {
|
||||||
var that = {},
|
var that = {},
|
||||||
urlBase = "http://public.highfidelity.io/meshes/",
|
urlBase = "http://public.highfidelity.io/meshes/",
|
||||||
model;
|
fstBuffer,
|
||||||
|
fbxBuffer,
|
||||||
|
svoBuffer,
|
||||||
|
mapping = {},
|
||||||
|
NAME_FIELD = "name",
|
||||||
|
SCALE_FIELD = "scale",
|
||||||
|
FILENAME_FIELD = "filename",
|
||||||
|
TEXDIR_FIELD = "texdir",
|
||||||
|
fbxDataView;
|
||||||
|
|
||||||
function readModel(file) {
|
function error(message) {
|
||||||
var url,
|
Window.alert(message);
|
||||||
req;
|
print(message);
|
||||||
|
}
|
||||||
|
|
||||||
print("Reading model from " + file);
|
function readFile(filename, buffer, length) {
|
||||||
|
var url = "file:///" + filename,
|
||||||
|
req = new XMLHttpRequest();
|
||||||
|
|
||||||
url = "file:///" + file;
|
|
||||||
req = new XMLHttpRequest();
|
|
||||||
req.open("GET", url, false);
|
req.open("GET", url, false);
|
||||||
req.responseType = "arraybuffer";
|
req.responseType = "arraybuffer";
|
||||||
req.send();
|
req.send();
|
||||||
if (req.status !== 200) {
|
if (req.status !== 200) {
|
||||||
print("Error reading file: " + req.status + " " + req.statusText);
|
error("Could not read file: " + filename + " : " + req.status + " " + req.statusText);
|
||||||
Window.alert("Could not read file " + req.status + " " + req.statusText);
|
return null;
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
buffer: req.response,
|
||||||
|
length: parseInt(req.getResponseHeader("Content-Length"), 10)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function readMapping(buffer) {
|
||||||
|
return {}; // DJRTODO
|
||||||
|
}
|
||||||
|
|
||||||
|
function readGeometry(buffer) {
|
||||||
|
return {}; // DJRTODO
|
||||||
|
}
|
||||||
|
|
||||||
|
function readModel(filename) {
|
||||||
|
var url,
|
||||||
|
req,
|
||||||
|
fbxFilename,
|
||||||
|
geometry;
|
||||||
|
|
||||||
|
if (filename.toLowerCase().slice(-4) === ".svo") {
|
||||||
|
svoBuffer = readFile(filename);
|
||||||
|
if (svoBuffer === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (filename.toLowerCase().slice(-4) === ".fst") {
|
||||||
|
fstBuffer = readFile(filename);
|
||||||
|
if (fstBuffer === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mapping = readMapping(fstBuffer);
|
||||||
|
fbxFilename = filename.path() + "\\" + mapping[FILENAME_FIELD];
|
||||||
|
|
||||||
|
} else if (filename.toLowerCase().slice(-4) === ".fbx") {
|
||||||
|
fbxFilename = filename;
|
||||||
|
mapping[FILENAME_FIELD] = filename.fileName();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
error("Unrecognized file type: " + filename);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fbxBuffer = readFile(fbxFilename);
|
||||||
|
if (fbxBuffer === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
geometry = readGeometry(fbxBuffer);
|
||||||
|
if (!mapping.hasOwnProperty(SCALE_FIELD)) {
|
||||||
|
mapping[SCALE_FIELD] = (geometry.author === "www.makehuman.org" ? 150.0 : 15.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add any missing basic mappings
|
||||||
|
if (!mapping.hasOwnProperty(NAME_FIELD)) {
|
||||||
|
mapping[NAME_FIELD] = filename.fileName().slice(0, -4);
|
||||||
|
}
|
||||||
|
if (!mapping.hasOwnProperty(TEXDIR_FIELD)) {
|
||||||
|
mapping[TEXDIR_FIELD] = ".";
|
||||||
|
}
|
||||||
|
if (!mapping.hasOwnProperty(SCALE_FIELD)) {
|
||||||
|
mapping[SCALE_FIELD] = 0.2; // For SVO models.
|
||||||
}
|
}
|
||||||
model = req.response;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -99,6 +186,8 @@ var modelUploader = (function () {
|
||||||
|
|
||||||
print("Sending model to High Fidelity");
|
print("Sending model to High Fidelity");
|
||||||
|
|
||||||
|
// DJRTODO
|
||||||
|
|
||||||
req = new XMLHttpRequest();
|
req = new XMLHttpRequest();
|
||||||
req.open("PUT", url, true);
|
req.open("PUT", url, true);
|
||||||
req.responseType = "arraybuffer";
|
req.responseType = "arraybuffer";
|
||||||
|
@ -113,24 +202,31 @@ var modelUploader = (function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
req.send(model);
|
|
||||||
|
if (fbxBuffer !== null) {
|
||||||
|
req.send(fbxBuffer.buffer);
|
||||||
|
} else {
|
||||||
|
req.send(svoBuffer.buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
that.upload = function (file, callback) {
|
that.upload = function (file, callback) {
|
||||||
var url = urlBase + file.replace(/^(.*[\/\\])*/, ""),
|
var url = urlBase + file.fileName();
|
||||||
ok;
|
|
||||||
|
|
||||||
// Read model content ...
|
// Read model content ...
|
||||||
ok = readModel(file);
|
if (!readModel(file)) {
|
||||||
if (!ok) { return; }
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set model properties ...
|
// Set model properties ...
|
||||||
ok = setProperties();
|
if (!setProperties()) {
|
||||||
if (!ok) { return; }
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Put model in HTTP message ...
|
// Put model in HTTP message ...
|
||||||
ok = createHttpMessage();
|
if (!createHttpMessage()) {
|
||||||
if (!ok) { return; }
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Send model to High Fidelity ...
|
// Send model to High Fidelity ...
|
||||||
sendToHighFidelity(url, callback);
|
sendToHighFidelity(url, callback);
|
||||||
|
|
Loading…
Reference in a new issue