mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 22:17:03 +02:00
Tidy model data handling
This commit is contained in:
parent
f39aed37b6
commit
0c589b73c4
1 changed files with 20 additions and 18 deletions
|
@ -282,6 +282,7 @@ var modelUploader = (function () {
|
||||||
fbxBuffer,
|
fbxBuffer,
|
||||||
svoBuffer,
|
svoBuffer,
|
||||||
mapping,
|
mapping,
|
||||||
|
geometry,
|
||||||
NAME_FIELD = "name",
|
NAME_FIELD = "name",
|
||||||
SCALE_FIELD = "scale",
|
SCALE_FIELD = "scale",
|
||||||
FILENAME_FIELD = "filename",
|
FILENAME_FIELD = "filename",
|
||||||
|
@ -290,14 +291,22 @@ var modelUploader = (function () {
|
||||||
PITCH_FIELD = "pitch",
|
PITCH_FIELD = "pitch",
|
||||||
YAW_FIELD = "yaw",
|
YAW_FIELD = "yaw",
|
||||||
ROLL_FIELD = "roll",
|
ROLL_FIELD = "roll",
|
||||||
MAX_TEXTURE_SIZE = 1024,
|
MAX_TEXTURE_SIZE = 1024;
|
||||||
geometry;
|
|
||||||
|
|
||||||
function error(message) {
|
function error(message) {
|
||||||
Window.alert(message);
|
Window.alert(message);
|
||||||
print(message);
|
print(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetDataObjects() {
|
||||||
|
fstBuffer = null;
|
||||||
|
fbxBuffer = null;
|
||||||
|
svoBuffer = null;
|
||||||
|
mapping = {};
|
||||||
|
geometry = {};
|
||||||
|
geometry.textures = [];
|
||||||
|
}
|
||||||
|
|
||||||
function readFile(filename) {
|
function readFile(filename) {
|
||||||
var url = "file:///" + filename,
|
var url = "file:///" + filename,
|
||||||
req = new XMLHttpRequest();
|
req = new XMLHttpRequest();
|
||||||
|
@ -318,7 +327,6 @@ var modelUploader = (function () {
|
||||||
|
|
||||||
function readMapping(fstBuffer) {
|
function readMapping(fstBuffer) {
|
||||||
var dv = new DataView(fstBuffer.buffer),
|
var dv = new DataView(fstBuffer.buffer),
|
||||||
mapping = {},
|
|
||||||
lines,
|
lines,
|
||||||
line,
|
line,
|
||||||
values,
|
values,
|
||||||
|
@ -342,13 +350,10 @@ var modelUploader = (function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapping;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function readGeometry(fbxBuffer) {
|
function readGeometry(fbxBuffer) {
|
||||||
var geometry,
|
var textures,
|
||||||
textures,
|
|
||||||
view,
|
view,
|
||||||
index,
|
index,
|
||||||
EOF;
|
EOF;
|
||||||
|
@ -356,8 +361,6 @@ var modelUploader = (function () {
|
||||||
// Reference:
|
// Reference:
|
||||||
// http://code.blender.org/index.php/2013/08/fbx-binary-file-format-specification/
|
// http://code.blender.org/index.php/2013/08/fbx-binary-file-format-specification/
|
||||||
|
|
||||||
geometry = {};
|
|
||||||
geometry.textures = [];
|
|
||||||
textures = {};
|
textures = {};
|
||||||
view = new DataView(fbxBuffer.buffer);
|
view = new DataView(fbxBuffer.buffer);
|
||||||
EOF = false;
|
EOF = false;
|
||||||
|
@ -458,8 +461,6 @@ var modelUploader = (function () {
|
||||||
readTextFBX();
|
readTextFBX();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return geometry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function readModel() {
|
function readModel() {
|
||||||
|
@ -467,11 +468,6 @@ var modelUploader = (function () {
|
||||||
|
|
||||||
print("Reading model file: " + modelFile);
|
print("Reading model file: " + modelFile);
|
||||||
|
|
||||||
fstBuffer = null;
|
|
||||||
fbxBuffer = null;
|
|
||||||
svoBuffer = null;
|
|
||||||
mapping = {};
|
|
||||||
|
|
||||||
if (modelFile.toLowerCase().slice(-4) === ".svo") {
|
if (modelFile.toLowerCase().slice(-4) === ".svo") {
|
||||||
svoBuffer = readFile(modelFile);
|
svoBuffer = readFile(modelFile);
|
||||||
if (svoBuffer === null) {
|
if (svoBuffer === null) {
|
||||||
|
@ -485,7 +481,7 @@ var modelUploader = (function () {
|
||||||
if (fstBuffer === null) {
|
if (fstBuffer === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mapping = readMapping(fstBuffer);
|
readMapping(fstBuffer);
|
||||||
if (mapping.hasOwnProperty(FILENAME_FIELD)) {
|
if (mapping.hasOwnProperty(FILENAME_FIELD)) {
|
||||||
fbxFilename = modelFile.path() + "\\" + mapping[FILENAME_FIELD];
|
fbxFilename = modelFile.path() + "\\" + mapping[FILENAME_FIELD];
|
||||||
} else {
|
} else {
|
||||||
|
@ -507,7 +503,7 @@ var modelUploader = (function () {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
geometry = readGeometry(fbxBuffer);
|
readGeometry(fbxBuffer);
|
||||||
|
|
||||||
if (mapping.hasOwnProperty(SCALE_FIELD)) {
|
if (mapping.hasOwnProperty(SCALE_FIELD)) {
|
||||||
mapping[SCALE_FIELD] = parseFloat(mapping[SCALE_FIELD]);
|
mapping[SCALE_FIELD] = parseFloat(mapping[SCALE_FIELD]);
|
||||||
|
@ -697,23 +693,29 @@ var modelUploader = (function () {
|
||||||
|
|
||||||
modelFile = file;
|
modelFile = file;
|
||||||
|
|
||||||
|
resetDataObjects();
|
||||||
|
|
||||||
// Read model content ...
|
// Read model content ...
|
||||||
if (!readModel()) {
|
if (!readModel()) {
|
||||||
|
resetDataObjects();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set model properties ...
|
// Set model properties ...
|
||||||
if (!setProperties()) {
|
if (!setProperties()) {
|
||||||
|
resetDataObjects();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put model in HTTP message ...
|
// Put model in HTTP message ...
|
||||||
if (!createHttpMessage()) {
|
if (!createHttpMessage()) {
|
||||||
|
resetDataObjects();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send model to High Fidelity ...
|
// Send model to High Fidelity ...
|
||||||
sendToHighFidelity(url, callback);
|
sendToHighFidelity(url, callback);
|
||||||
|
resetDataObjects();
|
||||||
};
|
};
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
|
|
Loading…
Reference in a new issue