Can drag blocks zip folder into hifi and upload the .obj

This commit is contained in:
Elisa Lupin-Jimenez 2017-07-26 15:21:39 -07:00
parent 4570814145
commit ca6a323d54
6 changed files with 96 additions and 38 deletions

View file

@ -230,6 +230,9 @@ static const QString OBJ_EXTENSION = ".obj";
static const QString AVA_JSON_EXTENSION = ".ava.json"; static const QString AVA_JSON_EXTENSION = ".ava.json";
static const QString WEB_VIEW_TAG = "noDownload=true"; static const QString WEB_VIEW_TAG = "noDownload=true";
// temporary zip handling for Emily
static const QString ZIP_EXTENSION = ".zip";
static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f; static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f;
static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS_PER_SECOND; static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS_PER_SECOND;
@ -260,7 +263,10 @@ const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensi
{ AVA_JSON_EXTENSION, &Application::askToWearAvatarAttachmentUrl }, { AVA_JSON_EXTENSION, &Application::askToWearAvatarAttachmentUrl },
{ JSON_EXTENSION, &Application::importJSONFromURL }, { JSON_EXTENSION, &Application::importJSONFromURL },
{ JS_EXTENSION, &Application::askToLoadScript }, { JS_EXTENSION, &Application::askToLoadScript },
{ FST_EXTENSION, &Application::askToSetAvatarUrl } { FST_EXTENSION, &Application::askToSetAvatarUrl },
// temporary zip handling for Emily
{ ZIP_EXTENSION, &Application::importFromZIP }
}; };
class DeadlockWatchdogThread : public QThread { class DeadlockWatchdogThread : public QThread {
@ -2779,6 +2785,15 @@ void Application::onPresent(quint32 frameCount) {
} }
} }
bool Application::importFromZIP(const QString& filePath) {
qDebug() << "A zip file has been dropped in: " << filePath;
QUrl empty = "";
qApp->getFileDownloadInterface()->runUnzip(filePath, empty, false, true);
return true;
}
bool _renderRequested { false };
bool Application::event(QEvent* event) { bool Application::event(QEvent* event) {
if (!Menu::getInstance()) { if (!Menu::getInstance()) {
return false; return false;
@ -6218,7 +6233,7 @@ void Application::addAssetToWorldFromURLRequestFinished() {
if (tempFile.open(QIODevice::WriteOnly)) { if (tempFile.open(QIODevice::WriteOnly)) {
tempFile.write(request->getData()); tempFile.write(request->getData());
addAssetToWorldInfoClear(filename); // Remove message from list; next one added will have a different key. addAssetToWorldInfoClear(filename); // Remove message from list; next one added will have a different key.
qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true); qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true, false);
} else { } else {
QString errorInfo = "Couldn't open temporary file for download"; QString errorInfo = "Couldn't open temporary file for download";
qWarning(interfaceapp) << errorInfo; qWarning(interfaceapp) << errorInfo;

View file

@ -482,6 +482,9 @@ private:
bool importJSONFromURL(const QString& urlString); bool importJSONFromURL(const QString& urlString);
bool importSVOFromURL(const QString& urlString); bool importSVOFromURL(const QString& urlString);
// temporary zip handling for Emily
bool importFromZIP(const QString& filePath);
bool nearbyEntitiesAreReadyForPhysics(); bool nearbyEntitiesAreReadyForPhysics();
int processOctreeStats(ReceivedMessage& message, SharedNodePointer sendingNode); int processOctreeStats(ReceivedMessage& message, SharedNodePointer sendingNode);
void trackIncomingOctreePacket(ReceivedMessage& message, SharedNodePointer sendingNode, bool wasStatsPacket); void trackIncomingOctreePacket(ReceivedMessage& message, SharedNodePointer sendingNode, bool wasStatsPacket);

View file

@ -32,12 +32,19 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent
// nothing for now // nothing for now
} }
void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) { void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool isBlocks) {
qCDebug(scriptengine) << "Url that was downloaded: " + url.toString(); qCDebug(scriptengine) << "Url that was downloaded: " + url.toString();
qCDebug(scriptengine) << "Path where download is saved: " + path; qCDebug(scriptengine) << "Path where download is saved: " + path;
QString fileName = "/" + path.section("/", -1); QString fileName = "/" + path.section("/", -1);
QString tempDir = path; QString tempDir = path;
tempDir.remove(fileName); if (!isBlocks) {
tempDir.remove(fileName);
} else {
QTemporaryDir blocks;
tempDir = blocks.path();
path.remove("file:///");
}
qCDebug(scriptengine) << "Temporary directory at: " + tempDir; qCDebug(scriptengine) << "Temporary directory at: " + tempDir;
if (!isTempDir(tempDir)) { if (!isTempDir(tempDir)) {
qCDebug(scriptengine) << "Temporary directory mismatch; risk of losing files"; qCDebug(scriptengine) << "Temporary directory mismatch; risk of losing files";
@ -45,6 +52,7 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) {
} }
QString file = unzipFile(path, tempDir); QString file = unzipFile(path, tempDir);
qCDebug(scriptengine) << "Unzipped file: " << file;
QString filename = QUrl::fromLocalFile(file).toString(); QString filename = QUrl::fromLocalFile(file).toString();
if (file != "") { if (file != "") {
qCDebug(scriptengine) << "File to upload: " + filename; qCDebug(scriptengine) << "File to upload: " + filename;
@ -54,6 +62,26 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) {
emit unzipResult(path, filename, autoAdd); emit unzipResult(path, filename, autoAdd);
} }
QString FileScriptingInterface::unzipFile(QString path, QString tempDir) {
QDir dir(path);
QString dirName = dir.path();
qCDebug(scriptengine) << "Directory to unzip: " << dirName;
QString target = tempDir + "/model_repo";
QStringList list = JlCompress::extractDir(dirName, target);
qCDebug(scriptengine) << list;
if (!list.isEmpty()) {
return list.front();
}
else {
qCDebug(scriptengine) << "Extraction failed";
return "";
}
}
// fix to check that we are only referring to a temporary directory // fix to check that we are only referring to a temporary directory
bool FileScriptingInterface::isTempDir(QString tempDir) { bool FileScriptingInterface::isTempDir(QString tempDir) {
QString folderName = "/" + tempDir.section("/", -1); QString folderName = "/" + tempDir.section("/", -1);
@ -92,24 +120,6 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) {
request->send(); request->send();
} }
QString FileScriptingInterface::unzipFile(QString path, QString tempDir) {
QDir dir(path);
QString dirName = dir.path();
QString target = tempDir + "/model_repo";
QStringList list = JlCompress::extractDir(dirName, target);
qCDebug(scriptengine) << list;
if (!list.isEmpty()) {
return list.front();
} else {
qCDebug(scriptengine) << "Extraction failed";
return "";
}
}
// this function is not in use // this function is not in use
void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) { void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) {
/*if (!file.isDir()) { /*if (!file.isDir()) {

View file

@ -24,7 +24,7 @@ public:
public slots: public slots:
QString convertUrlToPath(QUrl url); QString convertUrlToPath(QUrl url);
void runUnzip(QString path, QUrl url, bool autoAdd); void runUnzip(QString path, QUrl url, bool autoAdd, bool isBlocks);
QString getTempDir(); QString getTempDir();
signals: signals:

View file

@ -33,8 +33,8 @@
$("head").append( $("head").append(
'<style>' + '<style>' +
'#marketplace-navigation { font-family: Arial, Helvetica, sans-serif; width: 100%; height: 50px; background: #00b4ef; position: fixed; bottom: 0; z-index: 1000; }' + '#marketplace-navigation { font-family: Arial, Helvetica, sans-serif; width: 100%; height: 50px; background: #00b4ef; position: fixed; bottom: 0; z-index: 1000; }' +
'#marketplace-navigation .glyph { margin-left: 20px; margin-right: 3px; font-family: sans-serif; color: #fff; font-size: 24px; line-height: 50px; }' + '#marketplace-navigation .glyph { margin-left: 10px; margin-right: 3px; font-family: sans-serif; color: #fff; font-size: 24px; line-height: 50px; }' +
'#marketplace-navigation .text { color: #fff; font-size: 18px; line-height: 50px; vertical-align: top; position: relative; top: 1px; }' + '#marketplace-navigation .text { color: #fff; font-size: 16px; line-height: 50px; vertical-align: top; position: relative; top: 1px; }' +
'#marketplace-navigation input#back-button { position: absolute; left: 20px; margin-top: 12px; padding-left: 0; padding-right: 5px; }' + '#marketplace-navigation input#back-button { position: absolute; left: 20px; margin-top: 12px; padding-left: 0; padding-right: 5px; }' +
'#marketplace-navigation input#all-markets { position: absolute; right: 20px; margin-top: 12px; padding-left: 15px; padding-right: 15px; }' + '#marketplace-navigation input#all-markets { position: absolute; right: 20px; margin-top: 12px; padding-left: 15px; padding-right: 15px; }' +
'#marketplace-navigation .right { position: absolute; right: 20px; }' + '#marketplace-navigation .right { position: absolute; right: 20px; }' +
@ -79,6 +79,9 @@
letUsKnow.replaceWith(letUsKnow.html()); letUsKnow.replaceWith(letUsKnow.html());
// Add button links. // Add button links.
$('#exploreBlocksMarketplace').on('click', function () {
window.location = "https://vr.google.com/objects";
});
$('#exploreClaraMarketplace').on('click', function () { $('#exploreClaraMarketplace').on('click', function () {
window.location = "https://clara.io/library?gameCheck=true&public=true"; window.location = "https://clara.io/library?gameCheck=true&public=true";
}); });
@ -91,6 +94,16 @@
// Nothing to do. // Nothing to do.
} }
function injectBlocksCode() {
// Make space for marketplaces footer in Blocks pages.
$("head").append(
'<style>' +
'#app { margin-bottom: 135px; }' +
'.footer { bottom: 50px; }' +
'</style>'
);
}
function updateClaraCode() { function updateClaraCode() {
// Have to repeatedly update Clara page because its content can change dynamically without location.href changing. // Have to repeatedly update Clara page because its content can change dynamically without location.href changing.
@ -322,10 +335,12 @@
var DIRECTORY = 0; var DIRECTORY = 0;
var HIFI = 1; var HIFI = 1;
var CLARA = 2; var BLOCKS = 2;
var CLARA = 3;
var pageType = DIRECTORY; var pageType = DIRECTORY;
if (location.href.indexOf("highfidelity.com/") !== -1) { pageType = HIFI; } if (location.href.indexOf("highfidelity.com/") !== -1) { pageType = HIFI; }
if (location.href.indexOf("google.com/") !== -1) { pageType = BLOCKS; }
if (location.href.indexOf("clara.io/") !== -1) { pageType = CLARA; } if (location.href.indexOf("clara.io/") !== -1) { pageType = CLARA; }
injectCommonCode(pageType === DIRECTORY); injectCommonCode(pageType === DIRECTORY);
@ -336,6 +351,9 @@
case HIFI: case HIFI:
injectHiFiCode(); injectHiFiCode();
break; break;
case BLOCKS:
injectBlocksCode();
break;
case CLARA: case CLARA:
injectClaraCode(); injectClaraCode();
break; break;

View file

@ -30,19 +30,31 @@
</div> </div>
<hr class="tile-divider"> <hr class="tile-divider">
</div> </div>
<div class="marketplace-tile"> </div>
<div class="marketplace-tile-first-column"> <div class="marketplace-tile">
<img class="marketplace-tile-image" src="img/clara-tile.png"> <div class="marketplace-tile-first-column">
<img class="marketplace-tile-image" src="img/blocks-tile.png">
</div>
<div class="marketplace-tile-second-column">
<p class="marketplace-tile-description">Blocks, released by Google, allows anyone to create 3D models using just a few simple tools. Browse through other users' creations for low-poly assets to add to your world.</p>
<div class="exploreButton-holder">
<input class="blue exploreButton" type="button" value="Explore" id="exploreBlocksMarketplace" />
</div> </div>
<div class="marketplace-tile-second-column"> <hr class="tile-divider">
<p class="marketplace-tile-description">Clara.io has thousands of models available for importing into High Fidelity. Follow these steps for the best experience:</p> </div>
<ol class="marketplace-clara-steps"> </div>
<li><a id="claraSignUp" href="http://www.clara.io/signup">Create an account here </a>or log in as an existing user.</li> <div class="marketplace-tile">
<li>Choose a model from the list and click &ldquo;Download to High Fidelity&rdquo;.</li> <div class="marketplace-tile-first-column">
</ol> <img class="marketplace-tile-image" src="img/clara-tile.png">
<div class="exploreButton-holder"> </div>
<input class="blue exploreButton" type="button" value="Explore" id="exploreClaraMarketplace" /> <div class="marketplace-tile-second-column">
</div> <p class="marketplace-tile-description">Clara.io has thousands of models available for importing into High Fidelity. Follow these steps for the best experience:</p>
<ol class="marketplace-clara-steps">
<li><a id="claraSignUp" href="http://www.clara.io/signup">Create an account here </a>or log in as an existing user.</li>
<li>Choose a model from the list and click &ldquo;Download to High Fidelity&rdquo;.</li>
</ol>
<div class="exploreButton-holder">
<input class="blue exploreButton" type="button" value="Explore" id="exploreClaraMarketplace" />
</div> </div>
</div> </div>
</div> </div>