Add cubemap output format

This commit is contained in:
Zach Fox 2018-05-03 12:57:00 -07:00
parent 900486ed01
commit c3d3cdca3d
8 changed files with 64 additions and 17 deletions

View file

@ -7350,9 +7350,9 @@ void Application::takeSecondaryCameraSnapshot(const QString& filename) {
});
}
void Application::takeSecondaryCamera360Snapshot(const glm::vec3& cameraPosition, const QString& filename) {
postLambdaEvent([filename, cameraPosition, this] {
Snapshot::save360Snapshot(cameraPosition, filename);
void Application::takeSecondaryCamera360Snapshot(const glm::vec3& cameraPosition, const bool& cubemapOutputFormat, const QString& filename) {
postLambdaEvent([filename, cubemapOutputFormat, cameraPosition, this] {
Snapshot::save360Snapshot(cameraPosition, cubemapOutputFormat, filename);
});
}

View file

@ -273,7 +273,7 @@ public:
void takeSnapshot(bool notify, bool includeAnimated = false, float aspectRatio = 0.0f, const QString& filename = QString());
void takeSecondaryCameraSnapshot(const QString& filename = QString());
void takeSecondaryCamera360Snapshot(const glm::vec3& cameraPosition, const QString& filename = QString());
void takeSecondaryCamera360Snapshot(const glm::vec3& cameraPosition, const bool& cubemapOutputFormat, const QString& filename = QString());
void shareSnapshot(const QString& filename, const QUrl& href = QUrl(""));

View file

@ -431,8 +431,8 @@ void WindowScriptingInterface::takeSecondaryCameraSnapshot(const QString& filena
qApp->takeSecondaryCameraSnapshot(filename);
}
void WindowScriptingInterface::takeSecondaryCamera360Snapshot(const glm::vec3& cameraPosition, const QString& filename) {
qApp->takeSecondaryCamera360Snapshot(cameraPosition, filename);
void WindowScriptingInterface::takeSecondaryCamera360Snapshot(const glm::vec3& cameraPosition, const bool& cubemapOutputFormat, const QString& filename) {
qApp->takeSecondaryCamera360Snapshot(cameraPosition, cubemapOutputFormat, filename);
}
void WindowScriptingInterface::shareSnapshot(const QString& path, const QUrl& href) {

View file

@ -376,7 +376,7 @@ public slots:
*
* var filename = QString();
*/
void takeSecondaryCamera360Snapshot(const glm::vec3& cameraPosition, const QString& filename = QString());
void takeSecondaryCamera360Snapshot(const glm::vec3& cameraPosition, const bool& cubemapOutputFormat = false, const QString& filename = QString());
/**jsdoc
* Emit a {@link Window.connectionAdded|connectionAdded} or a {@link Window.connectionError|connectionError} signal that
@ -588,13 +588,13 @@ signals:
/**jsdoc
* Triggered when a still equirectangular snapshot has been taken by calling {@link Window.takeSecondaryCamera360Snapshot|takeSecondaryCamera360Snapshot}
* @function Window.equirectangularSnapshotTaken
* @function Window.snapshot360Taken
* @param {string} pathStillSnapshot - The path and name of the snapshot image file.
* @param {boolean} notify - The value of the <code>notify</code> parameter that {@link Window.takeSecondaryCamera360Snapshot|takeSecondaryCamera360Snapshot}
* was called with.
* @returns {Signal}
*/
void equirectangularSnapshotTaken(const QString& pathEquirectangularSnapshot, bool notify);
void snapshot360Taken(const QString& path360Snapshot, bool notify);
/**jsdoc
* Triggered when a snapshot submitted via {@link Window.shareSnapshot|shareSnapshot} is ready for sharing. The snapshot

View file

@ -20,6 +20,7 @@
#include <QtCore/QJsonArray>
#include <QtNetwork/QHttpMultiPart>
#include <QtGui/QImage>
#include <QPainter>
#include <QtConcurrent/QtConcurrentRun>
#include <AccountManager.h>
@ -102,6 +103,7 @@ QString Snapshot::saveSnapshot(QImage image, const QString& filename) {
}
QString Snapshot::snapshotFilename;
bool Snapshot::cubemapOutputFormat;
qint16 Snapshot::snapshotIndex = 0;
bool Snapshot::oldEnabled = false;
QVariant Snapshot::oldAttachedEntityId = 0;
@ -110,8 +112,9 @@ QVariant Snapshot::oldvFoV = 0;
QVariant Snapshot::oldNearClipPlaneDistance = 0;
QVariant Snapshot::oldFarClipPlaneDistance = 0;
static const float CUBEMAP_SIDE_PIXEL_DIMENSION = 2048.0f;
void Snapshot::save360Snapshot(const glm::vec3& cameraPosition, const QString& filename) {
void Snapshot::save360Snapshot(const glm::vec3& cameraPosition, const bool& cubemapOutputFormat, const QString& filename) {
Snapshot::snapshotFilename = filename;
Snapshot::cubemapOutputFormat = cubemapOutputFormat;
SecondaryCameraJobConfig* secondaryCameraRenderConfig = static_cast<SecondaryCameraJobConfig*>(qApp->getRenderEngine()->getConfiguration()->getConfig("SecondaryCamera"));
// Save initial values of secondary camera render config
@ -191,12 +194,54 @@ void Snapshot::takeNextSnapshot() {
}
// Process six QImages
QtConcurrent::run(Snapshot::convertToEquirectangular);
if (Snapshot::cubemapOutputFormat) {
QtConcurrent::run(Snapshot::convertToCubemap);
} else {
QtConcurrent::run(Snapshot::convertToEquirectangular);
}
}
Snapshot::snapshotIndex++;
}
void Snapshot::convertToCubemap() {
float outputImageHeight = CUBEMAP_SIDE_PIXEL_DIMENSION * 3.0f;
float outputImageWidth = CUBEMAP_SIDE_PIXEL_DIMENSION * 4.0f;
QImage outputImage(outputImageWidth, outputImageHeight, QImage::Format_RGB32);
QPainter painter(&outputImage);
QPoint destPos;
// Paint DownImage
destPos = QPoint(CUBEMAP_SIDE_PIXEL_DIMENSION, CUBEMAP_SIDE_PIXEL_DIMENSION * 2.0f);
painter.drawImage(destPos, Snapshot::imageArray[0]);
// Paint FrontImage
destPos = QPoint(CUBEMAP_SIDE_PIXEL_DIMENSION, CUBEMAP_SIDE_PIXEL_DIMENSION);
painter.drawImage(destPos, Snapshot::imageArray[1]);
// Paint LeftImage
destPos = QPoint(0, CUBEMAP_SIDE_PIXEL_DIMENSION);
painter.drawImage(destPos, Snapshot::imageArray[2]);
// Paint BackImage
destPos = QPoint(CUBEMAP_SIDE_PIXEL_DIMENSION * 3.0f, CUBEMAP_SIDE_PIXEL_DIMENSION);
painter.drawImage(destPos, Snapshot::imageArray[3]);
// Paint RightImage
destPos = QPoint(CUBEMAP_SIDE_PIXEL_DIMENSION * 2.0f, CUBEMAP_SIDE_PIXEL_DIMENSION);
painter.drawImage(destPos, Snapshot::imageArray[4]);
// Paint UpImage
destPos = QPoint(CUBEMAP_SIDE_PIXEL_DIMENSION, 0);
painter.drawImage(destPos, Snapshot::imageArray[5]);
painter.end();
emit DependencyManager::get<WindowScriptingInterface>()->snapshot360Taken(saveSnapshot(outputImage, Snapshot::snapshotFilename), true);
}
void Snapshot::convertToEquirectangular() {
// I got help from StackOverflow while writing this code:
// https://stackoverflow.com/questions/34250742/converting-a-cubemap-into-equirectangular-panorama
@ -278,7 +323,7 @@ void Snapshot::convertToEquirectangular() {
}
}
emit DependencyManager::get<WindowScriptingInterface>()->equirectangularSnapshotTaken(saveSnapshot(outputImage, Snapshot::snapshotFilename), true);
emit DependencyManager::get<WindowScriptingInterface>()->snapshot360Taken(saveSnapshot(outputImage, Snapshot::snapshotFilename), true);
}
QTemporaryFile* Snapshot::saveTempSnapshot(QImage image) {

View file

@ -40,7 +40,7 @@ public:
Snapshot();
static QString saveSnapshot(QImage image, const QString& filename);
static void save360Snapshot(const glm::vec3& cameraPosition, const QString& filename);
static void save360Snapshot(const glm::vec3& cameraPosition, const bool& cubemapOutputFormat, const QString& filename);
static QTemporaryFile* saveTempSnapshot(QImage image);
static SnapshotMetaData* parseSnapshotData(QString snapshotPath);
@ -61,6 +61,7 @@ private:
static QFile* savedFileForSnapshot(QImage & image, bool isTemporary, const QString& userSelectedFilename = QString());
static QString snapshotFilename;
static bool cubemapOutputFormat;
static QTimer snapshotTimer;
static qint16 snapshotIndex;
static bool oldEnabled;
@ -70,6 +71,7 @@ private:
static QVariant oldNearClipPlaneDistance;
static QVariant oldFarClipPlaneDistance;
static QImage imageArray[6];
static void convertToCubemap();
static void convertToEquirectangular();
};

View file

@ -672,7 +672,7 @@
Menu.menuItemEvent.connect(menuItemEvent);
Window.domainConnectionRefused.connect(onDomainConnectionRefused);
Window.stillSnapshotTaken.connect(onSnapshotTaken);
Window.equirectangularSnapshotTaken.connect(onSnapshotTaken);
Window.snapshot360Taken.connect(onSnapshotTaken);
Window.processingGifStarted.connect(processingGif);
Window.connectionAdded.connect(connectionAdded);
Window.connectionError.connect(connectionError);

View file

@ -194,7 +194,7 @@
Window.domainChanged.connect(onDomainChanged);
Window.geometryChanged.connect(resizeViewFinderOverlay);
Window.stillSnapshotTaken.connect(onStillSnapshotTaken);
Window.equirectangularSnapshotTaken.connect(onEquirectangularSnapshotTaken);
Window.snapshot360Taken.connect(on360SnapshotTaken);
Controller.keyPressEvent.connect(keyPressEvent);
HMD.displayModeChanged.connect(onHMDChanged);
viewFinderOverlay = false;
@ -407,7 +407,7 @@
}, 250);
}
}
function onEquirectangularSnapshotTaken() {
function on360SnapshotTaken() {
if (monitorShowsCameraView) {
setDisplay(true);
}
@ -606,7 +606,7 @@
Window.domainChanged.disconnect(onDomainChanged);
Window.geometryChanged.disconnect(resizeViewFinderOverlay);
Window.stillSnapshotTaken.disconnect(onStillSnapshotTaken);
Window.equirectangularSnapshotTaken.disconnect(onEquirectangularSnapshotTaken);
Window.snapshot360Taken.disconnect(on360SnapshotTaken);
addOrRemoveButton(true);
if (tablet) {
tablet.screenChanged.disconnect(onTabletScreenChanged);