mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 23:39:26 +02:00
Update model reading in preparation for API upload
This commit is contained in:
parent
70548976db
commit
eaf0b366d0
1 changed files with 62 additions and 34 deletions
|
@ -64,6 +64,13 @@ if (typeof String.prototype.fileName !== "function") {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof String.prototype.fileBase !== "function") {
|
||||||
|
String.prototype.fileBase = function () {
|
||||||
|
var filename = this.fileName();
|
||||||
|
return filename.slice(0, filename.indexOf("."));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof String.prototype.fileType !== "function") {
|
if (typeof String.prototype.fileType !== "function") {
|
||||||
String.prototype.fileType = function () {
|
String.prototype.fileType = function () {
|
||||||
return this.slice(this.lastIndexOf(".") + 1);
|
return this.slice(this.lastIndexOf(".") + 1);
|
||||||
|
@ -272,13 +279,14 @@ var httpMultiPart = (function () {
|
||||||
|
|
||||||
var modelUploader = (function () {
|
var modelUploader = (function () {
|
||||||
var that = {},
|
var that = {},
|
||||||
urlBase = "http://public.highfidelity.io/meshes/",
|
|
||||||
modelFile,
|
modelFile,
|
||||||
fstBuffer,
|
fstBuffer,
|
||||||
fbxBuffer,
|
fbxBuffer,
|
||||||
svoBuffer,
|
svoBuffer,
|
||||||
mapping,
|
mapping,
|
||||||
geometry,
|
geometry,
|
||||||
|
API_URL = "https://data.highfidelity.io/api/v1/models",
|
||||||
|
MODEL_URL = "http://public.highfidelity.io/models/content",
|
||||||
NAME_FIELD = "name",
|
NAME_FIELD = "name",
|
||||||
SCALE_FIELD = "scale",
|
SCALE_FIELD = "scale",
|
||||||
FILENAME_FIELD = "filename",
|
FILENAME_FIELD = "filename",
|
||||||
|
@ -290,8 +298,8 @@ var modelUploader = (function () {
|
||||||
MAX_TEXTURE_SIZE = 1024;
|
MAX_TEXTURE_SIZE = 1024;
|
||||||
|
|
||||||
function error(message) {
|
function error(message) {
|
||||||
Window.alert(message);
|
|
||||||
print(message);
|
print(message);
|
||||||
|
Window.alert(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetDataObjects() {
|
function resetDataObjects() {
|
||||||
|
@ -460,57 +468,71 @@ var modelUploader = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function readModel() {
|
function readModel() {
|
||||||
var fbxFilename;
|
var fbxFilename,
|
||||||
|
svoFilename,
|
||||||
|
fileType;
|
||||||
|
|
||||||
print("Reading model file: " + modelFile);
|
print("Reading model file: " + modelFile);
|
||||||
|
|
||||||
if (modelFile.toLowerCase().slice(-4) === ".svo") {
|
if (modelFile.toLowerCase().slice(-4) === ".fst") {
|
||||||
svoBuffer = readFile(modelFile);
|
fstBuffer = readFile(modelFile);
|
||||||
if (svoBuffer === null) {
|
if (fstBuffer === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
readMapping(fstBuffer);
|
||||||
|
fileType = mapping[FILENAME_FIELD].toLowerCase().fileType();
|
||||||
|
if (mapping.hasOwnProperty(FILENAME_FIELD)) {
|
||||||
|
if (fileType === "fbx") {
|
||||||
|
fbxFilename = modelFile.path() + "\\" + mapping[FILENAME_FIELD];
|
||||||
|
} else if (fileType === "svo") {
|
||||||
|
svoFilename = modelFile.path() + "\\" + mapping[FILENAME_FIELD];
|
||||||
|
} else {
|
||||||
|
error("Unrecognized model type in FST file!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error("Model file name not found in FST file!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (modelFile.toLowerCase().slice(-4) === ".fbx") {
|
||||||
|
fbxFilename = modelFile;
|
||||||
|
mapping[FILENAME_FIELD] = modelFile.fileName();
|
||||||
|
|
||||||
|
} else if (modelFile.toLowerCase().slice(-4) === ".svo") {
|
||||||
|
svoFilename = modelFile;
|
||||||
|
mapping[FILENAME_FIELD] = modelFile.fileName();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
error("Unrecognized file type: " + modelFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (modelFile.toLowerCase().slice(-4) === ".fst") {
|
if (fbxFilename) {
|
||||||
fstBuffer = readFile(modelFile);
|
|
||||||
if (fstBuffer === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
readMapping(fstBuffer);
|
|
||||||
if (mapping.hasOwnProperty(FILENAME_FIELD)) {
|
|
||||||
fbxFilename = modelFile.path() + "\\" + mapping[FILENAME_FIELD];
|
|
||||||
} else {
|
|
||||||
error("FBX file name not found in FST file!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (modelFile.toLowerCase().slice(-4) === ".fbx") {
|
|
||||||
fbxFilename = modelFile;
|
|
||||||
mapping[FILENAME_FIELD] = modelFile.fileName();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
error("Unrecognized file type: " + modelFile);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fbxBuffer = readFile(fbxFilename);
|
fbxBuffer = readFile(fbxFilename);
|
||||||
if (fbxBuffer === null) {
|
if (fbxBuffer === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
readGeometry(fbxBuffer);
|
readGeometry(fbxBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
if (mapping.hasOwnProperty(SCALE_FIELD)) {
|
if (svoFilename) {
|
||||||
mapping[SCALE_FIELD] = parseFloat(mapping[SCALE_FIELD]);
|
svoBuffer = readFile(svoFilename);
|
||||||
} else {
|
if (svoBuffer === null) {
|
||||||
mapping[SCALE_FIELD] = (geometry.author === "www.makehuman.org" ? 150.0 : 15.0);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mapping.hasOwnProperty(SCALE_FIELD)) {
|
||||||
|
mapping[SCALE_FIELD] = parseFloat(mapping[SCALE_FIELD]);
|
||||||
|
} else {
|
||||||
|
mapping[SCALE_FIELD] = (geometry.author === "www.makehuman.org" ? 150.0 : 15.0);
|
||||||
|
}
|
||||||
|
|
||||||
// Add any missing basic mappings
|
// Add any missing basic mappings
|
||||||
if (!mapping.hasOwnProperty(NAME_FIELD)) {
|
if (!mapping.hasOwnProperty(NAME_FIELD)) {
|
||||||
mapping[NAME_FIELD] = modelFile.fileName().slice(0, -4);
|
mapping[NAME_FIELD] = modelFile.fileName().fileBase();
|
||||||
}
|
}
|
||||||
if (!mapping.hasOwnProperty(TEXDIR_FIELD)) {
|
if (!mapping.hasOwnProperty(TEXDIR_FIELD)) {
|
||||||
mapping[TEXDIR_FIELD] = ".";
|
mapping[TEXDIR_FIELD] = ".";
|
||||||
|
@ -626,6 +648,9 @@ var modelUploader = (function () {
|
||||||
for (lodFile in mapping.lod) {
|
for (lodFile in mapping.lod) {
|
||||||
if (mapping.lod.hasOwnProperty(lodFile)) {
|
if (mapping.lod.hasOwnProperty(lodFile)) {
|
||||||
lodBuffer = readFile(modelFile.path() + "\/" + lodFile);
|
lodBuffer = readFile(modelFile.path() + "\/" + lodFile);
|
||||||
|
if (lodBuffer === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
httpMultiPart.add({
|
httpMultiPart.add({
|
||||||
name: "lod" + lodCount,
|
name: "lod" + lodCount,
|
||||||
buffer: lodBuffer
|
buffer: lodBuffer
|
||||||
|
@ -639,6 +664,9 @@ var modelUploader = (function () {
|
||||||
textureBuffer = readFile(modelFile.path() + "\/"
|
textureBuffer = readFile(modelFile.path() + "\/"
|
||||||
+ (mapping[TEXDIR_FIELD] !== "." ? mapping[TEXDIR_FIELD] + "\/" : "")
|
+ (mapping[TEXDIR_FIELD] !== "." ? mapping[TEXDIR_FIELD] + "\/" : "")
|
||||||
+ geometry.textures[i]);
|
+ geometry.textures[i]);
|
||||||
|
if (textureBuffer === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
textureSourceFormat = geometry.textures[i].fileType().toLowerCase();
|
textureSourceFormat = geometry.textures[i].fileType().toLowerCase();
|
||||||
textureTargetFormat = (textureSourceFormat === "jpg" ? "jpg" : "png");
|
textureTargetFormat = (textureSourceFormat === "jpg" ? "jpg" : "png");
|
||||||
|
@ -654,7 +682,7 @@ var modelUploader = (function () {
|
||||||
// Model category
|
// Model category
|
||||||
httpMultiPart.add({
|
httpMultiPart.add({
|
||||||
name : "model_category",
|
name : "model_category",
|
||||||
string : "item" // DJRTODO: What model category to use?
|
string : "content"
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue