From ca3777442c0c16ef4c16a08f01e3eaaf698c1248 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Mon, 11 Dec 2017 16:54:35 -0800 Subject: [PATCH 01/46] Added visualization of the differences between 2 images. --- tools/auto-tester/src/ImageComparer.cpp | 6 +- tools/auto-tester/src/common.h | 5 ++ tools/auto-tester/src/ui/MismatchWindow.cpp | 46 ++++++++++++- tools/auto-tester/src/ui/MismatchWindow.h | 2 + tools/auto-tester/src/ui/MismatchWindow.ui | 73 ++++++++++++--------- 5 files changed, 94 insertions(+), 38 deletions(-) diff --git a/tools/auto-tester/src/ImageComparer.cpp b/tools/auto-tester/src/ImageComparer.cpp index 121c98e16e..a80978e564 100644 --- a/tools/auto-tester/src/ImageComparer.cpp +++ b/tools/auto-tester/src/ImageComparer.cpp @@ -8,6 +8,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "ImageComparer.h" +#include "common.h" #include @@ -26,11 +27,6 @@ double ImageComparer::compareImages(QImage resultImage, QImage expectedImage) co const double c1 = pow((K1 * L), 2); const double c2 = pow((K2 * L), 2); - // Coefficients for luminosity calculation - const double R_Y = 0.212655f; - const double G_Y = 0.715158f; - const double B_Y = 0.072187f; - // First go over all full 8x8 blocks // This is done in 3 loops // 1) Read the pixels into a linear array (an optimization) diff --git a/tools/auto-tester/src/common.h b/tools/auto-tester/src/common.h index 126177358f..0c21d79b33 100644 --- a/tools/auto-tester/src/common.h +++ b/tools/auto-tester/src/common.h @@ -34,4 +34,9 @@ enum UserResponse { USER_RESPONSE_ABORT }; +// Coefficients for luminosity calculation +const double R_Y = 0.212655f; +const double G_Y = 0.715158f; +const double B_Y = 0.072187f; + #endif // hifi_common_h diff --git a/tools/auto-tester/src/ui/MismatchWindow.cpp b/tools/auto-tester/src/ui/MismatchWindow.cpp index 07664a1667..ec6dd9ac82 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.cpp +++ b/tools/auto-tester/src/ui/MismatchWindow.cpp @@ -16,6 +16,37 @@ MismatchWindow::MismatchWindow(QWidget *parent) : QDialog(parent) { expectedImage->setScaledContents(true); resultImage->setScaledContents(true); + diffImage->setScaledContents(true); +} + +QPixmap MismatchWindow::computeDiffPixmap(QImage expectedImage, QImage resultImage) { + // This is an optimization, as QImage.setPixel() is embarrassingly slow + unsigned char* buffer = new unsigned char[expectedImage.height() * expectedImage.width() * 3]; + + // loop over each pixel + for (int y = 0; y < expectedImage.height(); ++y) { + for (int x = 0; x < expectedImage.width(); ++x) { + QRgb pixelP = expectedImage.pixel(QPoint(x, y)); + QRgb pixelQ = resultImage.pixel(QPoint(x, y)); + + // Convert to luminance + double p = R_Y * qRed(pixelP) + G_Y * qGreen(pixelP) + B_Y * qBlue(pixelP); + double q = R_Y * qRed(pixelQ) + G_Y * qGreen(pixelQ) + B_Y * qBlue(pixelQ); + + int absDiff = (int)(fabs(p - q)); + + buffer[3 * (x + y * expectedImage.width()) + 0] = absDiff; + buffer[3 * (x + y * expectedImage.width()) + 1] = absDiff; + buffer[3 * (x + y * expectedImage.width()) + 2] = absDiff; + } + } + + QImage diffImage(buffer, expectedImage.width(), expectedImage.height(), QImage::Format_RGB888); + QPixmap resultPixmap = QPixmap::fromImage(diffImage); + + delete[] buffer; + + return resultPixmap; } void MismatchWindow::setTestFailure(TestFailure testFailure) { @@ -24,10 +55,19 @@ void MismatchWindow::setTestFailure(TestFailure testFailure) { imagePath->setText("Path to test: " + testFailure._pathname); expectedFilename->setText(testFailure._expectedImageFilename); - expectedImage->setPixmap(QPixmap(testFailure._pathname + testFailure._expectedImageFilename)); - resultFilename->setText(testFailure._actualImageFilename); - resultImage->setPixmap(QPixmap(testFailure._pathname + testFailure._actualImageFilename)); + + QPixmap expectedPixmap = QPixmap(testFailure._pathname + testFailure._expectedImageFilename); + QPixmap actualPixmap = QPixmap(testFailure._pathname + testFailure._actualImageFilename); + + QPixmap diffPixmap = computeDiffPixmap( + QImage(testFailure._pathname + testFailure._expectedImageFilename), + QImage(testFailure._pathname + testFailure._actualImageFilename) + ); + + expectedImage->setPixmap(expectedPixmap); + resultImage->setPixmap(actualPixmap); + diffImage->setPixmap(diffPixmap); } void MismatchWindow::on_passTestButton_clicked() { diff --git a/tools/auto-tester/src/ui/MismatchWindow.h b/tools/auto-tester/src/ui/MismatchWindow.h index 7c72b7b0b7..af18832f2a 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.h +++ b/tools/auto-tester/src/ui/MismatchWindow.h @@ -25,6 +25,8 @@ public: UserResponse getUserResponse() { return _userResponse; } + QPixmap computeDiffPixmap(QImage expectedImage, QImage resultImage); + private slots: void on_passTestButton_clicked(); void on_failTestButton_clicked(); diff --git a/tools/auto-tester/src/ui/MismatchWindow.ui b/tools/auto-tester/src/ui/MismatchWindow.ui index cab6c61e1c..090121c277 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.ui +++ b/tools/auto-tester/src/ui/MismatchWindow.ui @@ -6,8 +6,8 @@ 0 0 - 1585 - 694 + 1782 + 942 @@ -16,10 +16,10 @@ - 20 - 170 - 720 - 362 + 10 + 20 + 800 + 450 @@ -29,28 +29,41 @@ - 760 - 170 - 720 - 362 + 900 + 20 + 800 + 450 result image + + + + 540 + 480 + 800 + 450 + + + + diff image + + - 760 - 90 - 800 + 60 + 660 + 480 28 - 16 + 12 @@ -60,15 +73,15 @@ - 40 - 90 - 700 + 60 + 630 + 480 28 - 16 + 12 @@ -78,15 +91,15 @@ - 40 - 30 + 20 + 600 1200 28 - 16 + 12 @@ -97,7 +110,7 @@ 30 - 600 + 790 75 23 @@ -109,8 +122,8 @@ - 330 - 600 + 120 + 790 75 23 @@ -122,8 +135,8 @@ - 630 - 600 + 210 + 790 75 23 @@ -135,15 +148,15 @@ - 810 - 600 - 720 + 30 + 850 + 500 28 - 16 + 12 From 05b42726690a9bd0b91046dee2b79d167881b9ff Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Thu, 14 Dec 2017 11:40:30 -0800 Subject: [PATCH 02/46] WIP - writing test results to disk. --- tools/auto-tester/src/Test.cpp | 33 ++++++++++++++++++++++++++++----- tools/auto-tester/src/Test.h | 6 +++++- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index 8cb36fcfca..d9269e3391 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -21,7 +21,20 @@ Test::Test() { mismatchWindow.setModal(true); } -bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages) { +bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory) { + // Delete any previous test results, if user agrees + QString s = testDirectory + "/" + testResultsFolder; + QFileInfo fileInfo(testDirectory + "/" + testResultsFolder); + while (fileInfo.exists()) { + messageBox.setText("Previous test results have been found"); + messageBox.setInformativeText("Delete " + testResultsFolder + " before continuing"); + messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + int reply = messageBox.exec(); + if (reply == QMessageBox::Cancel) { + return false; + } + } + // Loop over both lists and compare each pair of images // Quit loop if user has aborted due to a failed test. const double THRESHOLD{ 0.999 }; @@ -45,12 +58,14 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage } if (similarityIndex < THRESHOLD) { - mismatchWindow.setTestFailure(TestFailure{ + TestFailure testFailure = TestFailure{ (float)similarityIndex, expectedImages[i].left(expectedImages[i].lastIndexOf("/") + 1), // path to the test (including trailing /) QFileInfo(expectedImages[i].toStdString().c_str()).fileName(), // filename of expected image QFileInfo(resultImages[i].toStdString().c_str()).fileName() // filename of result image - }); + }; + + mismatchWindow.setTestFailure(testFailure); mismatchWindow.exec(); @@ -58,6 +73,7 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage case USER_RESPONSE_PASS: break; case USE_RESPONSE_FAIL: + appendTestResultsToFile(testDirectory, testFailure); success = false; break; case USER_RESPONSE_ABORT: @@ -74,6 +90,13 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage return success; } +void Test::appendTestResultsToFile(QString testDirectory, TestFailure testFailure) { + QFileInfo fileInfo(testResultsFileName); + if (!fileInfo.exists()) { + } + +} + void Test::evaluateTests() { // Get list of JPEG images in folder, sorted by name QString pathToImageDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder containing the test images", ".", QFileDialog::ShowDirsOnly); @@ -107,7 +130,7 @@ void Test::evaluateTests() { exit(-1); } - bool success = compareImageLists(expectedImages, resultImages); + bool success = compareImageLists(expectedImages, resultImages, pathToImageDirectory); if (success) { messageBox.information(0, "Success", "All images are as expected"); @@ -164,7 +187,7 @@ void Test::evaluateTestsRecursively() { } // Set success to false if any test has failed - success &= compareImageLists(expectedImages, resultImages); + success &= compareImageLists(expectedImages, resultImages, directory); } if (success) { diff --git a/tools/auto-tester/src/Test.h b/tools/auto-tester/src/Test.h index 1f7b1e92a7..aa71aa5ba4 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/auto-tester/src/Test.h @@ -35,8 +35,12 @@ public: void importTest(QTextStream& textStream, const QString& testPathname, int testNumber); + void appendTestResultsToFile(QString testDirectory, TestFailure testFailure); + private: const QString testFilename{ "test.js" }; + const QString testResultsFolder{ "TestResults" }; + const QString testResultsFileName{ "TestResults.txt" }; QMessageBox messageBox; @@ -49,7 +53,7 @@ private: ImageComparer imageComparer; - bool compareImageLists(QStringList expectedImages, QStringList resultImages); + bool compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory); }; #endif // hifi_test_h From 418d741b39b6a61ca9a7cfb6fde73c38ab53ada4 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 15 Dec 2017 11:55:46 -0800 Subject: [PATCH 03/46] Auto-tester now saves results in a folder hierarchy. --- tools/auto-tester/src/Test.cpp | 65 ++++++++++++++++++--- tools/auto-tester/src/Test.h | 2 +- tools/auto-tester/src/ui/MismatchWindow.cpp | 20 +++++-- tools/auto-tester/src/ui/MismatchWindow.h | 3 + tools/auto-tester/src/ui/MismatchWindow.ui | 30 +++++++++- 5 files changed, 102 insertions(+), 18 deletions(-) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index d9269e3391..25477b3b91 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -22,10 +22,10 @@ Test::Test() { } bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory) { - // Delete any previous test results, if user agrees - QString s = testDirectory + "/" + testResultsFolder; - QFileInfo fileInfo(testDirectory + "/" + testResultsFolder); - while (fileInfo.exists()) { + // If a previous test results folder is found then wait for the user to delete it, or cancel + // (e.g. the user may want to move the folder elsewhere) + QString testResultsFolderPath { testDirectory + "/" + testResultsFolder }; + while (QDir().exists(testResultsFolderPath)) { messageBox.setText("Previous test results have been found"); messageBox.setInformativeText("Delete " + testResultsFolder + " before continuing"); messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); @@ -35,9 +35,12 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage } } + // Create a new test results folder + QDir().mkdir(testResultsFolderPath); + // Loop over both lists and compare each pair of images // Quit loop if user has aborted due to a failed test. - const double THRESHOLD{ 0.999 }; + const double THRESHOLD { 0.999 }; bool success{ true }; bool keepOn{ true }; for (int i = 0; keepOn && i < expectedImages.length(); ++i) { @@ -73,7 +76,7 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage case USER_RESPONSE_PASS: break; case USE_RESPONSE_FAIL: - appendTestResultsToFile(testDirectory, testFailure); + appendTestResultsToFile(testResultsFolderPath, testFailure, mismatchWindow.getComparisonImage()); success = false; break; case USER_RESPONSE_ABORT: @@ -90,11 +93,55 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage return success; } -void Test::appendTestResultsToFile(QString testDirectory, TestFailure testFailure) { - QFileInfo fileInfo(testResultsFileName); - if (!fileInfo.exists()) { +void Test::appendTestResultsToFile(QString testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage) { + if (!QDir().exists(testResultsFolderPath)) { + messageBox.critical(0, "Internal error", "Folder " + testResultsFolderPath + " not found"); + exit(-1); } + static int index = 1; + QString failureFolderPath { testResultsFolderPath + "/" + "Failure_" + QString::number(index) }; + if (!QDir().mkdir(failureFolderPath)) { + messageBox.critical(0, "Internal error", "Failed to create folder " + failureFolderPath); + exit(-1); + } + ++index; + + QString descriptionFileName { "ReadMe.txt" }; + QFile descriptionFile(failureFolderPath + "/" +descriptionFileName); + if (!descriptionFile.open(QIODevice::ReadWrite)) { + messageBox.critical(0, "Internal error", "Failed to create file " + descriptionFileName); + exit(-1); + } + + // Create text file describing the failure + QTextStream stream(&descriptionFile); + stream << "Test failed in folder " << testFailure._pathname.left(testFailure._pathname.length() - 1) << endl; // remove trailing '/' + stream << "Expected image was " << testFailure._expectedImageFilename << endl; + stream << "Actual image was " << testFailure._actualImageFilename << endl; + stream << "Similarity index was " << testFailure._error << endl; + + descriptionFile.close(); + + // Copy expected and actual images, and save the difference image + QString sourceFile; + QString destinationFile; + + sourceFile = testFailure._pathname + testFailure._expectedImageFilename; + destinationFile = failureFolderPath + "/" + "Expected Image.jpg"; + if (!QFile::copy(sourceFile, destinationFile)) { + messageBox.critical(0, "Internal error", "Failed to copy " + sourceFile + " to " + destinationFile); + exit(-1); + } + + sourceFile = testFailure._pathname + testFailure._actualImageFilename; + destinationFile = failureFolderPath + "/" + "Actual Image.jpg"; + if (!QFile::copy(sourceFile, destinationFile)) { + messageBox.critical(0, "Internal error", "Failed to copy " + sourceFile + " to " + destinationFile); + exit(-1); + } + + comparisonImage.save(failureFolderPath + "/" + "Difference Image.jpg"); } void Test::evaluateTests() { diff --git a/tools/auto-tester/src/Test.h b/tools/auto-tester/src/Test.h index aa71aa5ba4..73814c2311 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/auto-tester/src/Test.h @@ -35,7 +35,7 @@ public: void importTest(QTextStream& textStream, const QString& testPathname, int testNumber); - void appendTestResultsToFile(QString testDirectory, TestFailure testFailure); + void appendTestResultsToFile(QString testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage); private: const QString testFilename{ "test.js" }; diff --git a/tools/auto-tester/src/ui/MismatchWindow.cpp b/tools/auto-tester/src/ui/MismatchWindow.cpp index ec6dd9ac82..711ead4fbe 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.cpp +++ b/tools/auto-tester/src/ui/MismatchWindow.cpp @@ -33,11 +33,15 @@ QPixmap MismatchWindow::computeDiffPixmap(QImage expectedImage, QImage resultIma double p = R_Y * qRed(pixelP) + G_Y * qGreen(pixelP) + B_Y * qBlue(pixelP); double q = R_Y * qRed(pixelQ) + G_Y * qGreen(pixelQ) + B_Y * qBlue(pixelQ); - int absDiff = (int)(fabs(p - q)); - - buffer[3 * (x + y * expectedImage.width()) + 0] = absDiff; - buffer[3 * (x + y * expectedImage.width()) + 1] = absDiff; - buffer[3 * (x + y * expectedImage.width()) + 2] = absDiff; + // The intensity value is modified to increase the brightness of the displayed image + double absoluteDifference = fabs(p - q) / 255.0; + double modifiedDifference = pow(absoluteDifference, 0.5); + + int difference = (int)(modifiedDifference * 255.0); + + buffer[3 * (x + y * expectedImage.width()) + 0] = difference; + buffer[3 * (x + y * expectedImage.width()) + 1] = difference; + buffer[3 * (x + y * expectedImage.width()) + 2] = difference; } } @@ -60,7 +64,7 @@ void MismatchWindow::setTestFailure(TestFailure testFailure) { QPixmap expectedPixmap = QPixmap(testFailure._pathname + testFailure._expectedImageFilename); QPixmap actualPixmap = QPixmap(testFailure._pathname + testFailure._actualImageFilename); - QPixmap diffPixmap = computeDiffPixmap( + diffPixmap = computeDiffPixmap( QImage(testFailure._pathname + testFailure._expectedImageFilename), QImage(testFailure._pathname + testFailure._actualImageFilename) ); @@ -84,3 +88,7 @@ void MismatchWindow::on_abortTestsButton_clicked() { _userResponse = USER_RESPONSE_ABORT; close(); } + +QPixmap MismatchWindow::getComparisonImage() { + return diffPixmap; +} \ No newline at end of file diff --git a/tools/auto-tester/src/ui/MismatchWindow.h b/tools/auto-tester/src/ui/MismatchWindow.h index af18832f2a..ad8be16580 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.h +++ b/tools/auto-tester/src/ui/MismatchWindow.h @@ -26,6 +26,7 @@ public: UserResponse getUserResponse() { return _userResponse; } QPixmap computeDiffPixmap(QImage expectedImage, QImage resultImage); + QPixmap getComparisonImage(); private slots: void on_passTestButton_clicked(); @@ -34,6 +35,8 @@ private slots: private: UserResponse _userResponse{ USER_RESPONSE_INVALID }; + + QPixmap diffPixmap; }; diff --git a/tools/auto-tester/src/ui/MismatchWindow.ui b/tools/auto-tester/src/ui/MismatchWindow.ui index 090121c277..392bc1774b 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.ui +++ b/tools/auto-tester/src/ui/MismatchWindow.ui @@ -17,7 +17,7 @@ 10 - 20 + 25 800 450 @@ -30,7 +30,7 @@ 900 - 20 + 25 800 450 @@ -163,6 +163,32 @@ similarity + + + + 30 + 5 + 151 + 16 + + + + Expected Image + + + + + + 930 + 5 + 151 + 16 + + + + Actual Image + + From c7a45ec988fc361006db002444a5c94f96e1ddbc Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 15 Dec 2017 12:52:13 -0800 Subject: [PATCH 04/46] Completed storing test results. --- libraries/gl/src/gl/GLShaders.cpp | 29 +++++++------- tools/auto-tester/src/Test.cpp | 19 +++++---- tools/auto-tester/src/Test.h | 6 +-- tools/auto-tester/src/ui/AutoTester.cpp | 6 ++- tools/auto-tester/src/ui/AutoTester.h | 6 +-- tools/auto-tester/src/ui/AutoTester.ui | 52 ++++++++++++++++--------- 6 files changed, 72 insertions(+), 46 deletions(-) diff --git a/libraries/gl/src/gl/GLShaders.cpp b/libraries/gl/src/gl/GLShaders.cpp index 8ef0198676..daa829f5a8 100644 --- a/libraries/gl/src/gl/GLShaders.cpp +++ b/libraries/gl/src/gl/GLShaders.cpp @@ -2,9 +2,12 @@ #include "GLLogging.h" +#include +#include + namespace gl { - +#pragma optimize("", off) #ifdef SEPARATE_PROGRAM bool compileShader(GLenum shaderDomain, const std::string& shaderSource, const std::string& defines, GLuint &shaderObject, GLuint &programObject, std::string& error) { #else @@ -38,15 +41,15 @@ namespace gl { if (!compiled) { // save the source code to a temp file so we can debug easily - /* + std::ofstream filestream; - filestream.open("debugshader.glsl"); + filestream.open("D:\\debugshader.glsl"); if (filestream.is_open()) { - filestream << srcstr[0]; - filestream << srcstr[1]; - filestream.close(); + filestream << srcstr[0]; + filestream << srcstr[1]; + filestream.close(); } - */ + GLint infoLength = 0; glGetShaderiv(glshader, GL_INFO_LOG_LENGTH, &infoLength); @@ -55,13 +58,13 @@ namespace gl { glGetShaderInfoLog(glshader, infoLength, NULL, temp); - /* - filestream.open("debugshader.glsl.info.txt"); + + filestream.open("D:\\debugshader.glsl.info.txt"); if (filestream.is_open()) { - filestream << std::string(temp); - filestream.close(); + filestream << std::string(temp); + filestream.close(); } - */ + qCWarning(glLogging) << "GLShader::compileShader - failed to compile the gl shader object:"; for (auto s : srcstr) { @@ -74,7 +77,7 @@ namespace gl { delete[] temp; glDeleteShader(glshader); - return false; + exit(-1);// return false; } #ifdef SEPARATE_PROGRAM diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index 25477b3b91..e2669ef4f6 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -21,7 +21,7 @@ Test::Test() { mismatchWindow.setModal(true); } -bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory) { +bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode) { // If a previous test results folder is found then wait for the user to delete it, or cancel // (e.g. the user may want to move the folder elsewhere) QString testResultsFolderPath { testDirectory + "/" + testResultsFolder }; @@ -70,9 +70,13 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage mismatchWindow.setTestFailure(testFailure); - mismatchWindow.exec(); + if (!interactiveMode) { + appendTestResultsToFile(testResultsFolderPath, testFailure, mismatchWindow.getComparisonImage()); + success = false; + } else { + mismatchWindow.exec(); - switch (mismatchWindow.getUserResponse()) { + switch (mismatchWindow.getUserResponse()) { case USER_RESPONSE_PASS: break; case USE_RESPONSE_FAIL: @@ -86,6 +90,7 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage default: assert(false); break; + } } } } @@ -144,7 +149,7 @@ void Test::appendTestResultsToFile(QString testResultsFolderPath, TestFailure te comparisonImage.save(failureFolderPath + "/" + "Difference Image.jpg"); } -void Test::evaluateTests() { +void Test::evaluateTests(bool interactiveMode) { // Get list of JPEG images in folder, sorted by name QString pathToImageDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder containing the test images", ".", QFileDialog::ShowDirsOnly); if (pathToImageDirectory == "") { @@ -177,7 +182,7 @@ void Test::evaluateTests() { exit(-1); } - bool success = compareImageLists(expectedImages, resultImages, pathToImageDirectory); + bool success = compareImageLists(expectedImages, resultImages, pathToImageDirectory, interactiveMode); if (success) { messageBox.information(0, "Success", "All images are as expected"); @@ -189,7 +194,7 @@ void Test::evaluateTests() { // Two criteria are used to decide if a folder contains valid test results. // 1) a 'test'js' file exists in the folder // 2) the folder has the same number of actual and expected images -void Test::evaluateTestsRecursively() { +void Test::evaluateTestsRecursively(bool interactiveMode) { // Select folder to start recursing from QString topLevelDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder that will contain the top level test script", ".", QFileDialog::ShowDirsOnly); if (topLevelDirectory == "") { @@ -234,7 +239,7 @@ void Test::evaluateTestsRecursively() { } // Set success to false if any test has failed - success &= compareImageLists(expectedImages, resultImages, directory); + success &= compareImageLists(expectedImages, resultImages, directory, interactiveMode); } if (success) { diff --git a/tools/auto-tester/src/Test.h b/tools/auto-tester/src/Test.h index 73814c2311..422ac3a9c0 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/auto-tester/src/Test.h @@ -23,8 +23,8 @@ class Test { public: Test(); - void evaluateTests(); - void evaluateTestsRecursively(); + void evaluateTests(bool interactiveMode); + void evaluateTestsRecursively(bool interactiveMode); void createRecursiveScript(); void createTest(); @@ -53,7 +53,7 @@ private: ImageComparer imageComparer; - bool compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory); + bool compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode); }; #endif // hifi_test_h diff --git a/tools/auto-tester/src/ui/AutoTester.cpp b/tools/auto-tester/src/ui/AutoTester.cpp index 105baddb92..efc2490828 100644 --- a/tools/auto-tester/src/ui/AutoTester.cpp +++ b/tools/auto-tester/src/ui/AutoTester.cpp @@ -12,14 +12,16 @@ AutoTester::AutoTester(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); + + ui.checkBoxInteractiveMode->setChecked(true); } void AutoTester::on_evaluateTestsButton_clicked() { - test.evaluateTests(); + test.evaluateTests(ui.checkBoxInteractiveMode->isChecked()); } void AutoTester::on_evaluateTestsRecursivelyButton_clicked() { - test.evaluateTestsRecursively(); + test.evaluateTestsRecursively(ui.checkBoxInteractiveMode->isChecked()); } void AutoTester::on_createRecursiveScriptButton_clicked() { diff --git a/tools/auto-tester/src/ui/AutoTester.h b/tools/auto-tester/src/ui/AutoTester.h index acfea32ba1..99af639582 100644 --- a/tools/auto-tester/src/ui/AutoTester.h +++ b/tools/auto-tester/src/ui/AutoTester.h @@ -22,9 +22,9 @@ public: AutoTester(QWidget *parent = Q_NULLPTR); private slots: -void on_evaluateTestsButton_clicked(); -void on_evaluateTestsRecursivelyButton_clicked(); -void on_createRecursiveScriptButton_clicked(); + void on_evaluateTestsButton_clicked(); + void on_evaluateTestsRecursivelyButton_clicked(); + void on_createRecursiveScriptButton_clicked(); void on_createTestButton_clicked(); void on_closeButton_clicked(); diff --git a/tools/auto-tester/src/ui/AutoTester.ui b/tools/auto-tester/src/ui/AutoTester.ui index 7032ef9710..ceb8eaffeb 100644 --- a/tools/auto-tester/src/ui/AutoTester.ui +++ b/tools/auto-tester/src/ui/AutoTester.ui @@ -6,8 +6,8 @@ 0 0 - 286 - 470 + 607 + 333 @@ -17,9 +17,9 @@ - 60 - 360 - 160 + 190 + 210 + 220 40 @@ -30,9 +30,9 @@ - 60 - 270 - 160 + 360 + 130 + 220 40 @@ -43,9 +43,9 @@ - 60 - 20 - 160 + 20 + 75 + 220 40 @@ -56,9 +56,9 @@ - 60 - 210 - 160 + 360 + 75 + 220 40 @@ -69,9 +69,9 @@ - 60 - 75 - 160 + 20 + 130 + 220 40 @@ -79,13 +79,29 @@ Evaluate Tests Recursively + + + + 23 + 40 + 131 + 20 + + + + <html><head/><body><p>If unchecked, will not show results during evaluation</p></body></html> + + + Interactive Mode + + 0 0 - 286 + 607 21 From 320045cfbdb479d75b5253095e032f28eb650ad4 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 15 Dec 2017 12:53:27 -0800 Subject: [PATCH 05/46] Modified by mistake. --- libraries/gl/src/gl/GLShaders.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/libraries/gl/src/gl/GLShaders.cpp b/libraries/gl/src/gl/GLShaders.cpp index daa829f5a8..8ef0198676 100644 --- a/libraries/gl/src/gl/GLShaders.cpp +++ b/libraries/gl/src/gl/GLShaders.cpp @@ -2,12 +2,9 @@ #include "GLLogging.h" -#include -#include - namespace gl { -#pragma optimize("", off) + #ifdef SEPARATE_PROGRAM bool compileShader(GLenum shaderDomain, const std::string& shaderSource, const std::string& defines, GLuint &shaderObject, GLuint &programObject, std::string& error) { #else @@ -41,15 +38,15 @@ namespace gl { if (!compiled) { // save the source code to a temp file so we can debug easily - + /* std::ofstream filestream; - filestream.open("D:\\debugshader.glsl"); + filestream.open("debugshader.glsl"); if (filestream.is_open()) { - filestream << srcstr[0]; - filestream << srcstr[1]; - filestream.close(); + filestream << srcstr[0]; + filestream << srcstr[1]; + filestream.close(); } - + */ GLint infoLength = 0; glGetShaderiv(glshader, GL_INFO_LOG_LENGTH, &infoLength); @@ -58,13 +55,13 @@ namespace gl { glGetShaderInfoLog(glshader, infoLength, NULL, temp); - - filestream.open("D:\\debugshader.glsl.info.txt"); + /* + filestream.open("debugshader.glsl.info.txt"); if (filestream.is_open()) { - filestream << std::string(temp); - filestream.close(); + filestream << std::string(temp); + filestream.close(); } - + */ qCWarning(glLogging) << "GLShader::compileShader - failed to compile the gl shader object:"; for (auto s : srcstr) { @@ -77,7 +74,7 @@ namespace gl { delete[] temp; glDeleteShader(glshader); - exit(-1);// return false; + return false; } #ifdef SEPARATE_PROGRAM From bd5e2c9ab6cd30419d53076b9fddc3fdc303483e Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 15 Dec 2017 13:14:27 -0800 Subject: [PATCH 06/46] Cleanup per coding standard. --- tools/auto-tester/src/Test.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index e2669ef4f6..7e7baac6e8 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -77,19 +77,19 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage mismatchWindow.exec(); switch (mismatchWindow.getUserResponse()) { - case USER_RESPONSE_PASS: - break; - case USE_RESPONSE_FAIL: - appendTestResultsToFile(testResultsFolderPath, testFailure, mismatchWindow.getComparisonImage()); - success = false; - break; - case USER_RESPONSE_ABORT: - keepOn = false; - success = false; - break; - default: - assert(false); - break; + case USER_RESPONSE_PASS: + break; + case USE_RESPONSE_FAIL: + appendTestResultsToFile(testResultsFolderPath, testFailure, mismatchWindow.getComparisonImage()); + success = false; + break; + case USER_RESPONSE_ABORT: + keepOn = false; + success = false; + break; + default: + assert(false); + break; } } } From 0e7bc29649cc023e860f6d940a02276d2b3e11c0 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 15 Dec 2017 14:10:58 -0800 Subject: [PATCH 07/46] Added include for MacOS --- tools/auto-tester/src/ui/MismatchWindow.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/auto-tester/src/ui/MismatchWindow.cpp b/tools/auto-tester/src/ui/MismatchWindow.cpp index 711ead4fbe..fe22412522 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.cpp +++ b/tools/auto-tester/src/ui/MismatchWindow.cpp @@ -11,6 +11,8 @@ #include +#include + MismatchWindow::MismatchWindow(QWidget *parent) : QDialog(parent) { setupUi(this); @@ -35,7 +37,7 @@ QPixmap MismatchWindow::computeDiffPixmap(QImage expectedImage, QImage resultIma // The intensity value is modified to increase the brightness of the displayed image double absoluteDifference = fabs(p - q) / 255.0; - double modifiedDifference = pow(absoluteDifference, 0.5); + double modifiedDifference = sqrt(absoluteDifference); int difference = (int)(modifiedDifference * 255.0); From 8038f2bd9f60603c60f51b1db9c683e612a4bbef Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 15 Dec 2017 16:14:01 -0800 Subject: [PATCH 08/46] Added required parameter to test call. --- tools/auto-tester/src/Test.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index 7e7baac6e8..2e938c7bc4 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -266,7 +266,8 @@ void Test::createRecursiveScript() { if (!allTestsFilename.open(QIODevice::WriteOnly | QIODevice::Text)) { messageBox.critical(0, "Internal Error", - "Failed to create \"allTests.js\" in directory \"" + topLevelDirectory + "\""); + "Failed to create \"allTests.js\" in directory \"" + topLevelDirectory + "\"" + ); exit(-1); } @@ -339,7 +340,7 @@ void Test::createRecursiveScript() { // The script produced will look as follows: // if (test1HasNotStarted) { // test1HasNotStarted = false; - // test1.test(); + // test1.test("auto"); // print("******started test 1******"); // } // | @@ -362,7 +363,7 @@ void Test::createRecursiveScript() { textStream << tab << tab << "if (test" << i - 1 << ".complete && test" << i << "HasNotStarted) {" << endl; } textStream << tab << tab << tab << "test" << i << "HasNotStarted = false;" << endl; - textStream << tab << tab << tab << "test" << i << "." << testFunction << "();" << endl; + textStream << tab << tab << tab << "test" << i << "." << testFunction << "(\"auto\");" << endl; textStream << tab << tab << tab << "print(\"******started test " << i << "******\");" << endl; textStream << tab << tab << "}" << endl << endl; From 074784d4b852315bfee09cb42efa14df7c4350f2 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Tue, 19 Dec 2017 14:14:53 -0800 Subject: [PATCH 09/46] Completed zipping of results. --- tools/auto-tester/CMakeLists.txt | 43 +++++++------ tools/auto-tester/src/Test.cpp | 75 ++++++++++++++++------ tools/auto-tester/src/Test.h | 12 +++- tools/auto-tester/src/ui/MismatchWindow.ui | 4 +- 4 files changed, 89 insertions(+), 45 deletions(-) diff --git a/tools/auto-tester/CMakeLists.txt b/tools/auto-tester/CMakeLists.txt index e5f2c1fb97..fe91c89352 100644 --- a/tools/auto-tester/CMakeLists.txt +++ b/tools/auto-tester/CMakeLists.txt @@ -1,24 +1,24 @@ -set(TARGET_NAME auto-tester) +set (TARGET_NAME auto-tester) project(${TARGET_NAME}) # Automatically run UIC and MOC. This replaces the older WRAP macros -SET(CMAKE_AUTOUIC ON) -SET(CMAKE_AUTOMOC ON) +SET (CMAKE_AUTOUIC ON) +SET (CMAKE_AUTOMOC ON) -setup_hifi_project(Core Widgets) -link_hifi_libraries() +setup_hifi_project (Core Widgets) +link_hifi_libraries () # FIX: Qt was built with -reduce-relocations if (Qt5_POSITION_INDEPENDENT_CODE) - SET(CMAKE_POSITION_INDEPENDENT_CODE ON) + SET (CMAKE_POSITION_INDEPENDENT_CODE ON) endif() # Qt includes -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${Qt5Core_INCLUDE_DIRS}) -include_directories(${Qt5Widgets_INCLUDE_DIRS}) +include_directories (${CMAKE_CURRENT_SOURCE_DIR}) +include_directories (${Qt5Core_INCLUDE_DIRS}) +include_directories (${Qt5Widgets_INCLUDE_DIRS}) -set(QT_LIBRARIES Qt5::Core Qt5::Widgets) +set (QT_LIBRARIES Qt5::Core Qt5::Widgets) # Find all sources files file (GLOB_RECURSE SOURCES src/*.cpp) @@ -27,21 +27,24 @@ file (GLOB_RECURSE UIS src/ui/*.ui) if (WIN32) # Do not show Console - set_property(TARGET auto-tester PROPERTY WIN32_EXECUTABLE true) + set_property (TARGET auto-tester PROPERTY WIN32_EXECUTABLE true) endif() -add_executable(PROJECT_NAME ${SOURCES} ${HEADERS} ${UIS}) - -target_link_libraries(PROJECT_NAME ${QT_LIBRARIES}) +add_executable (PROJECT_NAME ${SOURCES} ${HEADERS} ${UIS}) -# Copy required dll's. -add_custom_command(TARGET auto-tester POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ -) +target_zlib() +add_dependency_external_projects (quazip) +find_package (QuaZip REQUIRED) +target_include_directories( ${TARGET_NAME} SYSTEM PUBLIC ${QUAZIP_INCLUDE_DIRS}) +target_link_libraries(${TARGET_NAME} ${QUAZIP_LIBRARIES}) + +target_link_libraries (PROJECT_NAME ${QT_LIBRARIES}) + +package_libraries_for_deployment() if (WIN32) + add_paths_to_fixup_libs (${QUAZIP_DLL_PATH}) + find_program(WINDEPLOYQT_COMMAND windeployqt PATHS ${QT_DIR}/bin NO_DEFAULT_PATH) if (NOT WINDEPLOYQT_COMMAND) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index 2e938c7bc4..fdce9b45fc 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -13,6 +13,9 @@ #include #include +#include +#include + Test::Test() { snapshotFilenameFormat = QRegularExpression("hifi-snap-by-.+-on-\\d\\d\\d\\d-\\d\\d-\\d\\d_\\d\\d-\\d\\d-\\d\\d.jpg"); @@ -21,23 +24,43 @@ Test::Test() { mismatchWindow.setModal(true); } -bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode) { - // If a previous test results folder is found then wait for the user to delete it, or cancel - // (e.g. the user may want to move the folder elsewhere) - QString testResultsFolderPath { testDirectory + "/" + testResultsFolder }; - while (QDir().exists(testResultsFolderPath)) { - messageBox.setText("Previous test results have been found"); - messageBox.setInformativeText("Delete " + testResultsFolder + " before continuing"); - messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - int reply = messageBox.exec(); - if (reply == QMessageBox::Cancel) { - return false; +bool Test::createTestResultsFolderPathIfNeeded(QString directory) { + // The test results folder is located in the root of the tests (i.e. for recursive test evaluation) + if (testResultsFolderPath == "") { + testResultsFolderPath = directory + "/" + TEST_RESULTS_FOLDER; + QDir testResultsFolder(testResultsFolderPath); + + if (testResultsFolder.exists()) { + testResultsFolder.removeRecursively(); } + + // Create a new test results folder + return QDir().mkdir(testResultsFolderPath); + } else { + return true; + } +} + +void Test::zipAndDeleteTestResultsFolder() { + QString zippedResultsFileName { testResultsFolderPath + ".zip" }; + QFileInfo fileInfo(zippedResultsFileName); + if (!fileInfo.exists()) { + QFile::remove(zippedResultsFileName); } - // Create a new test results folder - QDir().mkdir(testResultsFolderPath); + QDir testResultsFolder(testResultsFolderPath); + if (!testResultsFolder.isEmpty()) { + JlCompress::compressDir(testResultsFolderPath + ".zip", testResultsFolderPath); + } + testResultsFolder.removeRecursively(); + + //In all cases, for the next evaluation + testResultsFolderPath = ""; + index = 1; +} + +bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode) { // Loop over both lists and compare each pair of images // Quit loop if user has aborted due to a failed test. const double THRESHOLD { 0.999 }; @@ -104,7 +127,6 @@ void Test::appendTestResultsToFile(QString testResultsFolderPath, TestFailure te exit(-1); } - static int index = 1; QString failureFolderPath { testResultsFolderPath + "/" + "Failure_" + QString::number(index) }; if (!QDir().mkdir(failureFolderPath)) { messageBox.critical(0, "Internal error", "Failed to create folder " + failureFolderPath); @@ -112,10 +134,9 @@ void Test::appendTestResultsToFile(QString testResultsFolderPath, TestFailure te } ++index; - QString descriptionFileName { "ReadMe.txt" }; - QFile descriptionFile(failureFolderPath + "/" +descriptionFileName); + QFile descriptionFile(failureFolderPath + "/" + TEST_RESULTS_FILENAME); if (!descriptionFile.open(QIODevice::ReadWrite)) { - messageBox.critical(0, "Internal error", "Failed to create file " + descriptionFileName); + messageBox.critical(0, "Internal error", "Failed to create file " + TEST_RESULTS_FILENAME); exit(-1); } @@ -156,6 +177,11 @@ void Test::evaluateTests(bool interactiveMode) { return; } + // Leave if test results folder could not be created + if (!createTestResultsFolderPathIfNeeded(pathToImageDirectory)) { + return; + } + QStringList sortedImageFilenames = createListOfAllJPEGimagesInDirectory(pathToImageDirectory); // Separate images into two lists. The first is the expected images, the second is the test results @@ -189,6 +215,8 @@ void Test::evaluateTests(bool interactiveMode) { } else { messageBox.information(0, "Failure", "One or more images are not as expected"); } + + zipAndDeleteTestResultsFolder(); } // Two criteria are used to decide if a folder contains valid test results. @@ -201,6 +229,11 @@ void Test::evaluateTestsRecursively(bool interactiveMode) { return; } + // Leave if test results folder could not be created + if (!createTestResultsFolderPathIfNeeded(topLevelDirectory)) { + return; + } + bool success{ true }; QDirIterator it(topLevelDirectory.toStdString().c_str(), QDirIterator::Subdirectories); while (it.hasNext()) { @@ -211,7 +244,7 @@ void Test::evaluateTestsRecursively(bool interactiveMode) { } // - const QString testPathname{ directory + "/" + testFilename }; + const QString testPathname{ directory + "/" + TEST_FILENAME }; QFileInfo fileInfo(testPathname); if (!fileInfo.exists()) { // Folder does not contain 'test.js' @@ -247,6 +280,8 @@ void Test::evaluateTestsRecursively(bool interactiveMode) { } else { messageBox.information(0, "Failure", "One or more images are not as expected"); } + + zipAndDeleteTestResultsFolder(); } void Test::importTest(QTextStream& textStream, const QString& testPathname, int testNumber) { @@ -282,7 +317,7 @@ void Test::createRecursiveScript() { QVector testPathnames; // First test if top-level folder has a test.js file - const QString testPathname{ topLevelDirectory + "/" + testFilename }; + const QString testPathname{ topLevelDirectory + "/" + TEST_FILENAME }; QFileInfo fileInfo(testPathname); if (fileInfo.exists()) { // Current folder contains a test @@ -300,7 +335,7 @@ void Test::createRecursiveScript() { continue; } - const QString testPathname{ directory + "/" + testFilename }; + const QString testPathname{ directory + "/" + TEST_FILENAME }; QFileInfo fileInfo(testPathname); if (fileInfo.exists()) { // Current folder contains a test diff --git a/tools/auto-tester/src/Test.h b/tools/auto-tester/src/Test.h index 422ac3a9c0..dc65e3f665 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/auto-tester/src/Test.h @@ -37,10 +37,13 @@ public: void appendTestResultsToFile(QString testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage); + bool createTestResultsFolderPathIfNeeded(QString directory); + void zipAndDeleteTestResultsFolder(); + private: - const QString testFilename{ "test.js" }; - const QString testResultsFolder{ "TestResults" }; - const QString testResultsFileName{ "TestResults.txt" }; + const QString TEST_FILENAME { "test.js" }; + const QString TEST_RESULTS_FOLDER { "TestResults" }; + const QString TEST_RESULTS_FILENAME { "TestResults.txt" }; QMessageBox messageBox; @@ -54,6 +57,9 @@ private: ImageComparer imageComparer; bool compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode); + + QString testResultsFolderPath { "" }; + int index { 1 }; }; #endif // hifi_test_h diff --git a/tools/auto-tester/src/ui/MismatchWindow.ui b/tools/auto-tester/src/ui/MismatchWindow.ui index 392bc1774b..5ecf966df5 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.ui +++ b/tools/auto-tester/src/ui/MismatchWindow.ui @@ -137,12 +137,12 @@ 210 790 - 75 + 121 23 - Abort Tests + Abort current test From 9835b0638ba29f2dcd32dd855f7722143be7046e Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Tue, 19 Dec 2017 14:40:23 -0800 Subject: [PATCH 10/46] Added progress bar. --- tools/auto-tester/src/Test.cpp | 19 +++++++++++++------ tools/auto-tester/src/Test.h | 8 +++++--- tools/auto-tester/src/ui/AutoTester.cpp | 6 ++++-- tools/auto-tester/src/ui/AutoTester.ui | 17 +++++++++++++++-- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index fdce9b45fc..8bad468afa 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -60,7 +60,12 @@ void Test::zipAndDeleteTestResultsFolder() { index = 1; } -bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode) { +bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode, QProgressBar* progressBar) { + progressBar->setMinimum(0); + progressBar->setMaximum(expectedImages.length() - 1); + progressBar->setValue(0); + progressBar->setVisible(true); + // Loop over both lists and compare each pair of images // Quit loop if user has aborted due to a failed test. const double THRESHOLD { 0.999 }; @@ -116,8 +121,11 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage } } } + + progressBar->setValue(i); } + progressBar->setVisible(false); return success; } @@ -170,7 +178,7 @@ void Test::appendTestResultsToFile(QString testResultsFolderPath, TestFailure te comparisonImage.save(failureFolderPath + "/" + "Difference Image.jpg"); } -void Test::evaluateTests(bool interactiveMode) { +void Test::evaluateTests(bool interactiveMode, QProgressBar* progressBar) { // Get list of JPEG images in folder, sorted by name QString pathToImageDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder containing the test images", ".", QFileDialog::ShowDirsOnly); if (pathToImageDirectory == "") { @@ -208,7 +216,7 @@ void Test::evaluateTests(bool interactiveMode) { exit(-1); } - bool success = compareImageLists(expectedImages, resultImages, pathToImageDirectory, interactiveMode); + bool success = compareImageLists(expectedImages, resultImages, pathToImageDirectory, interactiveMode, progressBar); if (success) { messageBox.information(0, "Success", "All images are as expected"); @@ -222,7 +230,7 @@ void Test::evaluateTests(bool interactiveMode) { // Two criteria are used to decide if a folder contains valid test results. // 1) a 'test'js' file exists in the folder // 2) the folder has the same number of actual and expected images -void Test::evaluateTestsRecursively(bool interactiveMode) { +void Test::evaluateTestsRecursively(bool interactiveMode, QProgressBar* progressBar) { // Select folder to start recursing from QString topLevelDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder that will contain the top level test script", ".", QFileDialog::ShowDirsOnly); if (topLevelDirectory == "") { @@ -243,7 +251,6 @@ void Test::evaluateTestsRecursively(bool interactiveMode) { continue; } - // const QString testPathname{ directory + "/" + TEST_FILENAME }; QFileInfo fileInfo(testPathname); if (!fileInfo.exists()) { @@ -272,7 +279,7 @@ void Test::evaluateTestsRecursively(bool interactiveMode) { } // Set success to false if any test has failed - success &= compareImageLists(expectedImages, resultImages, directory, interactiveMode); + success &= compareImageLists(expectedImages, resultImages, directory, interactiveMode, progressBar); } if (success) { diff --git a/tools/auto-tester/src/Test.h b/tools/auto-tester/src/Test.h index dc65e3f665..37827e9e0b 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/auto-tester/src/Test.h @@ -15,6 +15,7 @@ #include #include #include +#include #include "ImageComparer.h" #include "ui/MismatchWindow.h" @@ -23,11 +24,13 @@ class Test { public: Test(); - void evaluateTests(bool interactiveMode); - void evaluateTestsRecursively(bool interactiveMode); + void evaluateTests(bool interactiveMode, QProgressBar* progressBar); + void evaluateTestsRecursively(bool interactiveMode, QProgressBar* progressBar); void createRecursiveScript(); void createTest(); + bool compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode, QProgressBar* progressBar); + QStringList createListOfAllJPEGimagesInDirectory(QString pathToImageDirectory); bool isInSnapshotFilenameFormat(QString filename); @@ -56,7 +59,6 @@ private: ImageComparer imageComparer; - bool compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode); QString testResultsFolderPath { "" }; int index { 1 }; diff --git a/tools/auto-tester/src/ui/AutoTester.cpp b/tools/auto-tester/src/ui/AutoTester.cpp index efc2490828..1f1283b98b 100644 --- a/tools/auto-tester/src/ui/AutoTester.cpp +++ b/tools/auto-tester/src/ui/AutoTester.cpp @@ -14,14 +14,16 @@ AutoTester::AutoTester(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); ui.checkBoxInteractiveMode->setChecked(true); + + ui.progressBar->setVisible(false); } void AutoTester::on_evaluateTestsButton_clicked() { - test.evaluateTests(ui.checkBoxInteractiveMode->isChecked()); + test.evaluateTests(ui.checkBoxInteractiveMode->isChecked(), ui.progressBar); } void AutoTester::on_evaluateTestsRecursivelyButton_clicked() { - test.evaluateTestsRecursively(ui.checkBoxInteractiveMode->isChecked()); + test.evaluateTestsRecursively(ui.checkBoxInteractiveMode->isChecked(), ui.progressBar); } void AutoTester::on_createRecursiveScriptButton_clicked() { diff --git a/tools/auto-tester/src/ui/AutoTester.ui b/tools/auto-tester/src/ui/AutoTester.ui index ceb8eaffeb..544141975f 100644 --- a/tools/auto-tester/src/ui/AutoTester.ui +++ b/tools/auto-tester/src/ui/AutoTester.ui @@ -7,7 +7,7 @@ 0 0 607 - 333 + 395 @@ -18,7 +18,7 @@ 190 - 210 + 300 220 40 @@ -95,6 +95,19 @@ Interactive Mode + + + + 20 + 190 + 255 + 23 + + + + 24 + + From 4e59fecae2b7345851deff66bd744865c29f1022 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Wed, 20 Dec 2017 10:24:51 -0800 Subject: [PATCH 11/46] Added keylight and ambient light mode radio-buttons to the html (the UI). --- scripts/system/html/entityProperties.html | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index 2ccad2c169..d3a0666b01 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -511,6 +511,11 @@
+
+ Inherit + Off + On +
@@ -531,11 +536,19 @@
-
+
+ +
+
+ Inherit + Off + On +
+
-
+
From d4b34b71adc26a5cf806b0e7c2281f7edbf349ff Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Wed, 20 Dec 2017 13:12:07 -0800 Subject: [PATCH 12/46] First version with packet update. --- .../entities/src/EntityItemProperties.cpp | 58 +++++++++++++++++++ libraries/entities/src/EntityItemProperties.h | 7 ++- libraries/entities/src/EntityPropertyFlags.h | 3 + libraries/entities/src/ZoneEntityItem.cpp | 38 +++++++++++- libraries/entities/src/ZoneEntityItem.h | 12 +++- .../networking/src/udt/PacketHeaders.cpp | 2 +- libraries/networking/src/udt/PacketHeaders.h | 3 +- 7 files changed, 118 insertions(+), 5 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 678ddfcea5..9ef0efca6a 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -242,6 +242,64 @@ void EntityItemProperties::setHazeModeFromString(const QString& hazeMode) { } } +QString EntityItemProperties::getKeyLightModeAsString() const { + // return "enabled" if _keyLightMode is not valid + if (_keyLightMode < COMPONENT_MODE_ITEM_COUNT) { + return COMPONENT_MODES[_keyLightMode].second; + } else { + return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; + } +} + +QString EntityItemProperties::getKeyLightModeString(uint32_t mode) { + // return "enabled" if mode is not valid + if (mode < COMPONENT_MODE_ITEM_COUNT) { + return COMPONENT_MODES[mode].second; + } else { + return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; + } +} + +void EntityItemProperties::setKeyLightModeFromString(const QString& keyLightMode) { + auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { + return (pair.second == keyLightMode); + }); + + if (result != COMPONENT_MODES.end()) { + _keyLightMode = result->first; + _keyLightModeChanged = true; + } +} + +QString EntityItemProperties::getAmbientLightModeAsString() const { + // return "enabled" if _ambientLightMode is not valid + if (_ambientLightMode < COMPONENT_MODE_ITEM_COUNT) { + return COMPONENT_MODES[_ambientLightMode].second; + } else { + return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; + } +} + +QString EntityItemProperties::getAmbientLightModeString(uint32_t mode) { + // return "enabled" if mode is not valid + if (mode < COMPONENT_MODE_ITEM_COUNT) { + return COMPONENT_MODES[mode].second; + } else { + return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; + } +} + +void EntityItemProperties::setAmbientLightModeFromString(const QString& ambientLightMode) { + auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { + return (pair.second == ambientLightMode); + }); + + if (result != COMPONENT_MODES.end()) { + _ambientLightMode = result->first; + _ambientLightModeChanged = true; + } +} + EntityPropertyFlags EntityItemProperties::getChangedProperties() const { EntityPropertyFlags changedProperties; diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 4f7ba1317b..e924ab3f94 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -180,6 +180,8 @@ public: DEFINE_PROPERTY_GROUP(Stage, stage, StagePropertyGroup); DEFINE_PROPERTY_REF_ENUM(PROP_HAZE_MODE, HazeMode, hazeMode, uint32_t, (uint32_t)COMPONENT_MODE_INHERIT); + DEFINE_PROPERTY_REF_ENUM(PROP_KEY_LIGHT_MODE, KeyLightMode, keyLightMode, uint32_t, (uint32_t)COMPONENT_MODE_ENABLED); + DEFINE_PROPERTY_REF_ENUM(PROP_AMBIENT_LIGHT_MODE, AmbientLightMode, ambientLightMode, uint32_t, (uint32_t)COMPONENT_MODE_ENABLED); DEFINE_PROPERTY_GROUP(Skybox, skybox, SkyboxPropertyGroup); DEFINE_PROPERTY_GROUP(Haze, haze, HazePropertyGroup); @@ -248,7 +250,8 @@ public: static QString getBackgroundModeString(BackgroundMode mode); static QString getHazeModeString(uint32_t mode); - + static QString getKeyLightModeString(uint32_t mode); + static QString getAmbientLightModeString(uint32_t mode); public: float getMaxDimension() const { return glm::compMax(_dimensions); } @@ -478,6 +481,8 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { DEBUG_PROPERTY_IF_CHANGED(debug, properties, BackgroundMode, backgroundMode, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, HazeMode, hazeMode, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, KeyLightMode, keyLightMode, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, AmbientLightMode, ambientLightMode, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelVolumeSize, voxelVolumeSize, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelData, voxelData, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelSurfaceStyle, voxelSurfaceStyle, ""); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 41c1e77bb8..73f6ec55c5 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -220,6 +220,9 @@ enum EntityPropertyList { PROP_HAZE_KEYLIGHT_RANGE, PROP_HAZE_KEYLIGHT_ALTITUDE, + PROP_KEY_LIGHT_MODE, + PROP_AMBIENT_LIGHT_MODE, + //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties to end of list just ABOVE this line PROP_AFTER_LAST_ITEM, diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp index 0ed523202b..0701591eca 100644 --- a/libraries/entities/src/ZoneEntityItem.cpp +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -72,6 +72,9 @@ EntityItemProperties ZoneEntityItem::getProperties(EntityPropertyFlags desiredPr COPY_ENTITY_PROPERTY_TO_PROPERTIES(hazeMode, getHazeMode); _hazeProperties.getProperties(properties); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(keyLightMode, getKeyLightMode); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(ambientLightMode, getAmbientLightMode); + return properties; } @@ -115,10 +118,13 @@ bool ZoneEntityItem::setSubClassProperties(const EntityItemProperties& propertie SET_ENTITY_PROPERTY_FROM_PROPERTIES(flyingAllowed, setFlyingAllowed); SET_ENTITY_PROPERTY_FROM_PROPERTIES(ghostingAllowed, setGhostingAllowed); SET_ENTITY_PROPERTY_FROM_PROPERTIES(filterURL, setFilterURL); - + SET_ENTITY_PROPERTY_FROM_PROPERTIES(hazeMode, setHazeMode); _hazePropertiesChanged = _hazeProperties.setProperties(properties); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(keyLightMode, setKeyLightMode); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(ambientLightMode, setAmbientLightMode); + somethingChanged = somethingChanged || _keyLightPropertiesChanged || _stagePropertiesChanged || _skyboxPropertiesChanged || _hazePropertiesChanged; return somethingChanged; @@ -173,6 +179,9 @@ int ZoneEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, bytesRead += bytesFromHaze; dataAt += bytesFromHaze; + READ_ENTITY_PROPERTY(PROP_KEY_LIGHT_MODE, uint32_t, setKeyLightMode); + READ_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_MODE, uint32_t, setAmbientLightMode); + return bytesRead; } @@ -236,6 +245,9 @@ void ZoneEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits APPEND_ENTITY_PROPERTY(PROP_HAZE_MODE, (uint32_t)getHazeMode()); _hazeProperties.appendSubclassData(packetData, params, modelTreeElementExtraEncodeData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState); + + APPEND_ENTITY_PROPERTY(PROP_KEY_LIGHT_MODE, (uint32_t)getKeyLightMode()); + APPEND_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_MODE, (uint32_t)getAmbientLightMode()); } void ZoneEntityItem::debugDump() const { @@ -246,6 +258,8 @@ void ZoneEntityItem::debugDump() const { qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); qCDebug(entities) << " _backgroundMode:" << EntityItemProperties::getBackgroundModeString(_backgroundMode); qCDebug(entities) << " _hazeMode:" << EntityItemProperties::getHazeModeString(_hazeMode); + qCDebug(entities) << " _keyLightMode:" << EntityItemProperties::getKeyLightModeString(_keyLightMode); + qCDebug(entities) << " _ambientLightMode:" << EntityItemProperties::getAmbientLightModeString(_ambientLightMode); _keyLightProperties.debugDump(); _skyboxProperties.debugDump(); @@ -330,3 +344,25 @@ void ZoneEntityItem::setHazeMode(const uint32_t value) { uint32_t ZoneEntityItem::getHazeMode() const { return _hazeMode; } + +void ZoneEntityItem::setKeyLightMode(const uint32_t value) { + if (value < COMPONENT_MODE_ITEM_COUNT) { + _keyLightMode = value; + _keyLightPropertiesChanged = true; + } +} + +uint32_t ZoneEntityItem::getKeyLightMode() const { + return _keyLightMode; +} + +void ZoneEntityItem::setAmbientLightMode(const uint32_t value) { + if (value < COMPONENT_MODE_ITEM_COUNT) { + _ambientLightMode = value; + _ambientLightPropertiesChanged = true; + } +} + +uint32_t ZoneEntityItem::getAmbientLightMode() const { + return _ambientLightMode; +} diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index 46e8a00c24..6a94d5c63b 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -73,6 +73,12 @@ public: void setHazeMode(const uint32_t value); uint32_t getHazeMode() const; + void setKeyLightMode(uint32_t value); + uint32_t getKeyLightMode() const; + + void setAmbientLightMode(uint32_t value); + uint32_t getAmbientLightMode() const; + SkyboxPropertyGroup getSkyboxProperties() const { return resultWithReadLock([&] { return _skyboxProperties; }); } const HazePropertyGroup& getHazeProperties() const { return _hazeProperties; } @@ -113,6 +119,8 @@ public: static const QString DEFAULT_FILTER_URL; static const uint32_t DEFAULT_HAZE_MODE{ (uint32_t)COMPONENT_MODE_INHERIT }; + static const uint32_t DEFAULT_KEY_LIGHT_MODE{ (uint32_t)COMPONENT_MODE_ENABLED }; // so as not to change previous behaviour + static const uint32_t DEFAULT_AMBIENT_LIGHT_MODE{ (uint32_t)COMPONENT_MODE_ENABLED }; protected: KeyLightPropertyGroup _keyLightProperties; @@ -121,8 +129,9 @@ protected: QString _compoundShapeURL; BackgroundMode _backgroundMode = BACKGROUND_MODE_INHERIT; - uint32_t _hazeMode{ DEFAULT_HAZE_MODE }; + uint32_t _keyLightMode{ DEFAULT_KEY_LIGHT_MODE }; + uint32_t _ambientLightMode{ DEFAULT_AMBIENT_LIGHT_MODE }; SkyboxPropertyGroup _skyboxProperties; HazePropertyGroup _hazeProperties; @@ -138,6 +147,7 @@ protected: bool _skyboxPropertiesChanged { false }; bool _hazePropertiesChanged{ false }; bool _stagePropertiesChanged { false }; + bool _ambientLightPropertiesChanged { false }; static bool _drawZoneBoundaries; static bool _zonesArePickable; diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index 62354da11a..3aec01792e 100644 --- a/libraries/networking/src/udt/PacketHeaders.cpp +++ b/libraries/networking/src/udt/PacketHeaders.cpp @@ -30,7 +30,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketType::EntityEdit: case PacketType::EntityData: case PacketType::EntityPhysics: - return static_cast(EntityVersion::StaticCertJsonVersionOne); + return static_cast(EntityVersion::ZoneLightInheritModes); case PacketType::EntityQuery: return static_cast(EntityQueryPacketVersion::ConnectionIdentifier); diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index 618ac2de0c..7af59284e3 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -200,7 +200,8 @@ enum class EntityVersion : PacketVersion { StrokeColorProperty = 77, HasDynamicOwnershipTests, HazeEffect, - StaticCertJsonVersionOne + StaticCertJsonVersionOne, + ZoneLightInheritModes }; enum class EntityScriptCallMethodVersion : PacketVersion { From 58c6f8e9c477dbad312230923acf77da7626c084 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Wed, 20 Dec 2017 19:17:18 -0800 Subject: [PATCH 13/46] Radio buttons now work correctly. --- .../src/RenderableZoneEntityItem.cpp | 23 ++++++++-- .../src/RenderableZoneEntityItem.h | 6 ++- .../entities/src/EntityItemProperties.cpp | 29 ++++++++++++- libraries/entities/src/ZoneEntityItem.cpp | 3 ++ scripts/system/html/entityProperties.html | 12 +++--- scripts/system/html/js/entityProperties.js | 42 +++++++++++++++++-- 6 files changed, 98 insertions(+), 17 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 04da70d733..900b0d7392 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -164,13 +164,20 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { } if (_visible) { - // FInally, push the light visible in the frame - // THe directional key light for sure - _stage->_currentFrame.pushSunLight(_sunIndex); + // Finally, push the light visible in the frame + if (_keyLightMode == COMPONENT_MODE_ENABLED) { + _stage->_currentFrame.pushSunLight(_sunIndex); + } else if (_keyLightMode == COMPONENT_MODE_DISABLED) { + // DEAL WITH OFF LIGHT + } // The ambient light only if it has a valid texture to render with if (_validAmbientTexture || _validSkyboxTexture) { - _stage->_currentFrame.pushAmbientLight(_ambientIndex); + if (_ambientLightMode == COMPONENT_MODE_ENABLED) { + _stage->_currentFrame.pushAmbientLight(_ambientIndex); + } else if (_ambientLightMode == COMPONENT_MODE_DISABLED) { + // DEAL WITH OFF LIGHT + } } // The background only if the mode is not inherit @@ -483,6 +490,14 @@ void ZoneEntityRenderer::setHazeMode(ComponentMode mode) { _hazeMode = mode; } +void ZoneEntityRenderer::setKeyLightMode(ComponentMode mode) { + _keyLightMode = mode; +} + +void ZoneEntityRenderer::setAmbientLightMode(ComponentMode mode) { + _ambientLightMode = mode; +} + void ZoneEntityRenderer::setSkyboxColor(const glm::vec3& color) { editSkybox()->setColor(color); } diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index 050a8a4386..f7f8ecb6ee 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -56,6 +56,8 @@ private: void setSkyboxURL(const QString& skyboxUrl); void setBackgroundMode(BackgroundMode mode); void setHazeMode(ComponentMode mode); + void setKeyLightMode(ComponentMode mode); + void setAmbientLightMode(ComponentMode mode); void setSkyboxColor(const glm::vec3& color); void setProceduralUserData(const QString& userData); @@ -85,7 +87,9 @@ private: const model::HazePointer _haze{ std::make_shared() }; BackgroundMode _backgroundMode{ BACKGROUND_MODE_INHERIT }; - ComponentMode _hazeMode{ COMPONENT_MODE_INHERIT }; + ComponentMode _hazeMode { COMPONENT_MODE_INHERIT }; + ComponentMode _keyLightMode { COMPONENT_MODE_ENABLED }; + ComponentMode _ambientLightMode { COMPONENT_MODE_ENABLED }; indexed_container::Index _sunIndex{ LightStage::INVALID_INDEX }; indexed_container::Index _shadowIndex{ LightStage::INVALID_INDEX }; diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 9ef0efca6a..3984627499 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -388,6 +388,8 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_BACKGROUND_MODE, backgroundMode); CHECK_PROPERTY_CHANGE(PROP_HAZE_MODE, hazeMode); + CHECK_PROPERTY_CHANGE(PROP_KEY_LIGHT_MODE, keyLightMode); + CHECK_PROPERTY_CHANGE(PROP_AMBIENT_LIGHT_MODE, ambientLightMode); CHECK_PROPERTY_CHANGE(PROP_SOURCE_URL, sourceUrl); CHECK_PROPERTY_CHANGE(PROP_VOXEL_VOLUME_SIZE, voxelVolumeSize); @@ -622,6 +624,9 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_HAZE_MODE, hazeMode, getHazeModeAsString()); _haze.copyToScriptValue(_desiredProperties, properties, engine, skipDefaults, defaultEntityProperties); + + COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_KEY_LIGHT_MODE, keyLightMode, getKeyLightModeAsString()); + COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_AMBIENT_LIGHT_MODE, ambientLightMode, getAmbientLightModeAsString()); } // Web only @@ -808,8 +813,9 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(collisionSoundURL, QString, setCollisionSoundURL); COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(backgroundMode, BackgroundMode); - COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(hazeMode, HazeMode); + COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(keyLightMode, KeyLightMode); + COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(ambientLightMode, AmbientLightMode); COPY_PROPERTY_FROM_QSCRIPTVALUE(sourceUrl, QString, setSourceUrl); COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelVolumeSize, glmVec3, setVoxelVolumeSize); @@ -966,8 +972,9 @@ void EntityItemProperties::merge(const EntityItemProperties& other) { COPY_PROPERTY_IF_CHANGED(collisionSoundURL); COPY_PROPERTY_IF_CHANGED(backgroundMode); - COPY_PROPERTY_IF_CHANGED(hazeMode); + COPY_PROPERTY_IF_CHANGED(keyLightMode); + COPY_PROPERTY_IF_CHANGED(ambientLightMode); COPY_PROPERTY_IF_CHANGED(sourceUrl); COPY_PROPERTY_IF_CHANGED(voxelVolumeSize); @@ -1241,6 +1248,9 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_GROUP_PROPERTY_TO_MAP(PROP_HAZE_KEYLIGHT_RANGE, Haze, haze, HazeKeyLightRange, hazeKeyLightRange); ADD_GROUP_PROPERTY_TO_MAP(PROP_HAZE_KEYLIGHT_ALTITUDE, Haze, haze, HazeKeyLightAltitude, hazeKeyLightAltitude); + ADD_PROPERTY_TO_MAP(PROP_KEY_LIGHT_MODE, KeyLightMode, keyLightMode, uint32_t); + ADD_PROPERTY_TO_MAP(PROP_AMBIENT_LIGHT_MODE, AmbientLightMode, ambientLightMode, uint32_t); + ADD_PROPERTY_TO_MAP(PROP_DPI, DPI, dpi, uint16_t); // FIXME - these are not yet handled @@ -1485,6 +1495,10 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy APPEND_ENTITY_PROPERTY(PROP_HAZE_MODE, (uint32_t)properties.getHazeMode()); _staticHaze.setProperties(properties); _staticHaze.appendToEditPacket(packetData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState); + + + APPEND_ENTITY_PROPERTY(PROP_KEY_LIGHT_MODE, (uint32_t)properties.getKeyLightMode()); + APPEND_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_MODE, (uint32_t)properties.getAmbientLightMode()); } if (properties.getType() == EntityTypes::PolyVox) { @@ -1835,6 +1849,9 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_HAZE_MODE, uint32_t, setHazeMode); properties.getHaze().decodeFromEditPacket(propertyFlags, dataAt, processedBytes); + + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_KEY_LIGHT_MODE, uint32_t, setKeyLightMode); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_AMBIENT_LIGHT_MODE, uint32_t, setAmbientLightMode); } if (properties.getType() == EntityTypes::PolyVox) { @@ -2415,6 +2432,14 @@ QList EntityItemProperties::listChangedProperties() { out += "hazeMode"; } + if (keyLightModeChanged()) { + out += "keyLightMode"; + } + + if (ambientLightModeChanged()) { + out += "ambientLightMode"; + } + if (voxelVolumeSizeChanged()) { out += "voxelVolumeSize"; } diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp index 0701591eca..3b30774656 100644 --- a/libraries/entities/src/ZoneEntityItem.cpp +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -211,6 +211,9 @@ EntityPropertyFlags ZoneEntityItem::getEntityProperties(EncodeBitstreamParams& p requestedProperties += PROP_HAZE_MODE; requestedProperties += _hazeProperties.getEntityProperties(params); + requestedProperties += PROP_KEY_LIGHT_MODE; + requestedProperties += PROP_AMBIENT_LIGHT_MODE; + return requestedProperties; } diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index d3a0666b01..bc98dcc25f 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -512,9 +512,9 @@
- Inherit - Off - On + Inherit + Off + On
@@ -540,9 +540,9 @@
- Inherit - Off - On + Inherit + Off + On
diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index 0ab9f7a9cb..0fd88d9f19 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -627,7 +627,6 @@ function loaded() { var elHyperlinkHref = document.getElementById("property-hyperlink-href"); - var elTextText = document.getElementById("property-text-text"); var elTextLineHeight = document.getElementById("property-text-line-height"); var elTextTextColor = document.getElementById("property-text-text-color"); @@ -641,6 +640,10 @@ function loaded() { var elZoneStageSunModelEnabled = document.getElementById("property-zone-stage-sun-model-enabled"); + var elZoneKeyLightModeInherit = document.getElementById("property-zone-key-light-mode-inherit"); + var elZoneKeyLightModeDisabled = document.getElementById("property-zone-key-light-mode-disabled"); + var elZoneKeyLightModeEnabled = document.getElementById("property-zone-key-light-mode-enabled"); + var elZoneKeyLightColor = document.getElementById("property-zone-key-light-color"); var elZoneKeyLightColorRed = document.getElementById("property-zone-key-light-color-red"); var elZoneKeyLightColorGreen = document.getElementById("property-zone-key-light-color-green"); @@ -649,6 +652,11 @@ function loaded() { var elZoneKeyLightAmbientIntensity = document.getElementById("property-zone-key-ambient-intensity"); var elZoneKeyLightDirectionX = document.getElementById("property-zone-key-light-direction-x"); var elZoneKeyLightDirectionY = document.getElementById("property-zone-key-light-direction-y"); + + var elZoneAmbientLightModeInherit = document.getElementById("property-zone-ambient-light-mode-inherit"); + var elZoneAmbientLightModeDisabled = document.getElementById("property-zone-ambient-light-mode-disabled"); + var elZoneAmbientLightModeEnabled = document.getElementById("property-zone-ambient-light-mode-enabled"); + var elZoneKeyLightAmbientURL = document.getElementById("property-zone-key-ambient-url"); var elZoneHazeModeInherit = document.getElementById("property-zone-haze-mode-inherit"); @@ -1002,7 +1010,13 @@ function loaded() { elLightFalloffRadius.value = properties.falloffRadius.toFixed(1); elLightExponent.value = properties.exponent.toFixed(2); elLightCutoff.value = properties.cutoff.toFixed(2); + } else if (properties.type === "Zone") { + + elZoneKeyLightModeInherit.checked = (properties.keyLightMode === 'inherit'); + elZoneKeyLightModeDisabled.checked = (properties.keyLightMode === 'disabled'); + elZoneKeyLightModeEnabled.checked = (properties.keyLightMode === 'enabled'); + elZoneStageSunModelEnabled.checked = properties.stage.sunModelEnabled; elZoneKeyLightColor.style.backgroundColor = "rgb(" + properties.keyLight.color.red + "," + properties.keyLight.color.green + "," + properties.keyLight.color.blue + ")"; @@ -1013,6 +1027,11 @@ function loaded() { elZoneKeyLightAmbientIntensity.value = properties.keyLight.ambientIntensity.toFixed(2); elZoneKeyLightDirectionX.value = properties.keyLight.direction.x.toFixed(2); elZoneKeyLightDirectionY.value = properties.keyLight.direction.y.toFixed(2); + + elZoneAmbientLightModeInherit.checked = (properties.ambientLightMode === 'inherit'); + elZoneAmbientLightModeDisabled.checked = (properties.ambientLightMode === 'disabled'); + elZoneAmbientLightModeEnabled.checked = (properties.ambientLightMode === 'enabled'); + elZoneKeyLightAmbientURL.value = properties.keyLight.ambientURL; elZoneHazeModeInherit.checked = (properties.hazeMode === 'inherit'); @@ -1400,6 +1419,13 @@ function loaded() { } })); + var keyLightModeChanged = createZoneComponentModeChangedFunction('keyLightMode', + elZoneKeyLightModeInherit, elZoneKeyLightModeDisabled, elZoneKeyLightModeEnabled); + + elZoneKeyLightModeInherit.addEventListener('change', keyLightModeChanged); + elZoneKeyLightModeDisabled.addEventListener('change', keyLightModeChanged); + elZoneKeyLightModeEnabled.addEventListener('change', keyLightModeChanged); + elZoneStageSunModelEnabled.addEventListener('change', createEmitGroupCheckedPropertyUpdateFunction('stage', 'sunModelEnabled')); colorPickers.push($('#property-zone-key-light-color').colpick({ @@ -1425,6 +1451,14 @@ function loaded() { elZoneKeyLightColorBlue.addEventListener('change', zoneKeyLightColorChangeFunction); elZoneKeyLightIntensity.addEventListener('change', createEmitGroupNumberPropertyUpdateFunction('keyLight', 'intensity')); + + var ambientLightModeChanged = createZoneComponentModeChangedFunction('ambientLightMode', + elZoneAmbientLightModeInherit, elZoneAmbientLightModeDisabled, elZoneAmbientLightModeEnabled); + + elZoneAmbientLightModeInherit.addEventListener('change', ambientLightModeChanged); + elZoneAmbientLightModeDisabled.addEventListener('change', ambientLightModeChanged); + elZoneAmbientLightModeEnabled.addEventListener('change', ambientLightModeChanged); + elZoneKeyLightAmbientIntensity.addEventListener('change', createEmitGroupNumberPropertyUpdateFunction('keyLight', 'ambientIntensity')); elZoneKeyLightAmbientURL.addEventListener('change', @@ -1435,9 +1469,9 @@ function loaded() { elZoneKeyLightDirectionX.addEventListener('change', zoneKeyLightDirectionChangeFunction); elZoneKeyLightDirectionY.addEventListener('change', zoneKeyLightDirectionChangeFunction); - var hazeModeChanged = - createZoneComponentModeChangedFunction('hazeMode', elZoneHazeModeInherit, - elZoneHazeModeDisabled, elZoneHazeModeEnabled); + var hazeModeChanged = createZoneComponentModeChangedFunction('hazeMode', + elZoneHazeModeInherit, elZoneHazeModeDisabled, elZoneHazeModeEnabled); + elZoneHazeModeInherit.addEventListener('change', hazeModeChanged); elZoneHazeModeDisabled.addEventListener('change', hazeModeChanged); elZoneHazeModeEnabled.addEventListener('change', hazeModeChanged); From e974cac177abf69ce2bdaa4da148e5722452c455 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Thu, 21 Dec 2017 19:19:55 -0800 Subject: [PATCH 14/46] Keylight inheritance mode works. --- .../src/RenderableZoneEntityItem.cpp | 21 +++++++------- .../src/RenderableZoneEntityItem.h | 4 +-- libraries/render-utils/src/LightStage.cpp | 28 +++++++++++++++++++ libraries/render-utils/src/LightStage.h | 17 +++++++++++ 4 files changed, 57 insertions(+), 13 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 900b0d7392..97d403e4d3 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -165,18 +165,14 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { if (_visible) { // Finally, push the light visible in the frame - if (_keyLightMode == COMPONENT_MODE_ENABLED) { + if (_keyLightMode != BACKGROUND_MODE_INHERIT) { _stage->_currentFrame.pushSunLight(_sunIndex); - } else if (_keyLightMode == COMPONENT_MODE_DISABLED) { - // DEAL WITH OFF LIGHT } // The ambient light only if it has a valid texture to render with if (_validAmbientTexture || _validSkyboxTexture) { - if (_ambientLightMode == COMPONENT_MODE_ENABLED) { + if (_ambientLightMode != BACKGROUND_MODE_INHERIT) { _stage->_currentFrame.pushAmbientLight(_ambientIndex); - } else if (_ambientLightMode == COMPONENT_MODE_DISABLED) { - // DEAL WITH OFF LIGHT } } @@ -201,7 +197,6 @@ void ZoneEntityRenderer::removeFromScene(const ScenePointer& scene, Transaction& Parent::removeFromScene(scene, transaction); } - void ZoneEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) { DependencyManager::get()->updateZone(entity->getID()); @@ -244,11 +239,11 @@ void ZoneEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scen updateKeyZoneItemFromEntity(); if (sunChanged) { - updateKeySunFromEntity(); + updateKeySunFromEntity(entity); } if (sunChanged || skyboxChanged) { - updateKeyAmbientFromEntity(); + updateKeyAmbientFromEntity(entity); } if (backgroundChanged || skyboxChanged) { @@ -317,7 +312,9 @@ bool ZoneEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPoint return false; } -void ZoneEntityRenderer::updateKeySunFromEntity() { +void ZoneEntityRenderer::updateKeySunFromEntity(const TypedEntityPointer& entity) { + setKeyLightMode((ComponentMode)entity->getKeyLightMode()); + const auto& sunLight = editSunLight(); sunLight->setType(model::Light::SUN); sunLight->setPosition(_lastPosition); @@ -329,7 +326,9 @@ void ZoneEntityRenderer::updateKeySunFromEntity() { sunLight->setDirection(_keyLightProperties.getDirection()); } -void ZoneEntityRenderer::updateKeyAmbientFromEntity() { +void ZoneEntityRenderer::updateKeyAmbientFromEntity(const TypedEntityPointer& entity) { + setAmbientLightMode((ComponentMode)entity->getAmbientLightMode()); + const auto& ambientLight = editAmbientLight(); ambientLight->setType(model::Light::AMBIENT); ambientLight->setPosition(_lastPosition); diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index f7f8ecb6ee..bf6bda2af8 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -46,8 +46,8 @@ protected: private: void updateKeyZoneItemFromEntity(); - void updateKeySunFromEntity(); - void updateKeyAmbientFromEntity(); + void updateKeySunFromEntity(const TypedEntityPointer& entity); + void updateKeyAmbientFromEntity(const TypedEntityPointer& entity); void updateHazeFromEntity(const TypedEntityPointer& entity); void updateKeyBackgroundFromEntity(const TypedEntityPointer& entity); void updateAmbientMap(); diff --git a/libraries/render-utils/src/LightStage.cpp b/libraries/render-utils/src/LightStage.cpp index e568554452..0cc30495b8 100644 --- a/libraries/render-utils/src/LightStage.cpp +++ b/libraries/render-utils/src/LightStage.cpp @@ -28,6 +28,34 @@ static const auto MAX_BIAS = 0.006f; const LightStage::Index LightStage::INVALID_INDEX { render::indexed_container::INVALID_INDEX }; LightStage::LightStage() { + // Add off lights + const LightPointer ambientOffLight { std::make_shared() }; + ambientOffLight->setAmbientIntensity(0.0f); + ambientOffLight->setColor(model::Vec3(0.0)); + ambientOffLight->setIntensity(0.0f); + ambientOffLight->setType(model::Light::Type::AMBIENT); + _ambientOffLight = addLight(ambientOffLight); + + const LightPointer pointOffLight { std::make_shared() }; + pointOffLight->setAmbientIntensity(0.0f); + pointOffLight->setColor(model::Vec3(0.0)); + pointOffLight->setIntensity(0.0f); + pointOffLight->setType(model::Light::Type::POINT); + _pointOffLight = addLight(pointOffLight); + + const LightPointer spotOffLight { std::make_shared() }; + spotOffLight->setAmbientIntensity(0.0f); + spotOffLight->setColor(model::Vec3(0.0)); + spotOffLight->setIntensity(0.0f); + spotOffLight->setType(model::Light::Type::SPOT); + _spotOffLight = addLight(spotOffLight); + + const LightPointer sunOffLight { std::make_shared() }; + sunOffLight->setAmbientIntensity(0.0f); + sunOffLight->setColor(model::Vec3(0.0)); + sunOffLight->setIntensity(0.0f); + sunOffLight->setType(model::Light::Type::SUN); + _sunOffLight = addLight(sunOffLight); } LightStage::Shadow::Schema::Schema() { diff --git a/libraries/render-utils/src/LightStage.h b/libraries/render-utils/src/LightStage.h index 508e67ec17..5ba0b02131 100644 --- a/libraries/render-utils/src/LightStage.h +++ b/libraries/render-utils/src/LightStage.h @@ -185,6 +185,11 @@ public: Frame _currentFrame; + Index getAmbientOffLight() { return _ambientOffLight; } + Index getPointOffLight() { return _pointOffLight; } + Index getSpotOffLight() { return _spotOffLight; } + Index getSunOffLight() { return _sunOffLight; } + protected: struct Desc { @@ -199,6 +204,18 @@ protected: Descs _descs; LightMap _lightMap; + // define off lights + + const LightPointer ambientOffLight { std::make_shared() }; + const LightPointer pointOffLight { std::make_shared() }; + const LightPointer spotOffLight { std::make_shared() }; + const LightPointer sunOffLight { std::make_shared() }; + + Index _ambientOffLight; + Index _pointOffLight; + Index _spotOffLight; + Index _sunOffLight; + }; using LightStagePointer = std::shared_ptr; From 502cac2ac71a9569aae3f6fdedb5b2ed96359908 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 22 Dec 2017 08:05:12 -0800 Subject: [PATCH 15/46] Keylight inherit/off/on working --- .../src/RenderableZoneEntityItem.cpp | 12 +++++++++++- .../entities-renderer/src/RenderableZoneEntityItem.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 97d403e4d3..41edb5b020 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -165,7 +165,17 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { if (_visible) { // Finally, push the light visible in the frame - if (_keyLightMode != BACKGROUND_MODE_INHERIT) { + if (_keyLightMode == COMPONENT_MODE_DISABLED && sunOnIndex == NO_STORED_VALUE) { + // Just turned off, store previous value before changing + sunOnIndex = _sunIndex; + _sunIndex = _stage->getSunOffLight(); + } else if (_keyLightMode == COMPONENT_MODE_ENABLED && sunOnIndex != NO_STORED_VALUE) { + // Just turned on, restore previous value before clearing stored value + _sunIndex = sunOnIndex; + sunOnIndex = NO_STORED_VALUE; + } + + if (_keyLightMode != COMPONENT_MODE_INHERIT) { _stage->_currentFrame.pushSunLight(_sunIndex); } diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index bf6bda2af8..fe3f1a2a14 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -95,6 +95,9 @@ private: indexed_container::Index _shadowIndex{ LightStage::INVALID_INDEX }; indexed_container::Index _ambientIndex{ LightStage::INVALID_INDEX }; + const int NO_STORED_VALUE { -1 }; + indexed_container::Index sunOnIndex { NO_STORED_VALUE }; + BackgroundStagePointer _backgroundStage; BackgroundStage::Index _backgroundIndex{ BackgroundStage::INVALID_INDEX }; From e102b8c08767b4f717d51d2eb62616bfd1250d27 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 22 Dec 2017 08:35:09 -0800 Subject: [PATCH 16/46] Fixed Ubuntu warning. --- libraries/entities-renderer/src/RenderableZoneEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 41edb5b020..80f9836c1c 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -181,7 +181,7 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { // The ambient light only if it has a valid texture to render with if (_validAmbientTexture || _validSkyboxTexture) { - if (_ambientLightMode != BACKGROUND_MODE_INHERIT) { + if (_ambientLightMode != COMPONENT_MODE_INHERIT) { _stage->_currentFrame.pushAmbientLight(_ambientIndex); } } From 3f82e9147b5ea2a6e7ea3d9519e27821a2fed6d0 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 22 Dec 2017 16:30:19 -0800 Subject: [PATCH 17/46] Change keylight/ambient mode default from "enabled" to "inherit" --- .../entities-renderer/src/RenderableZoneEntityItem.h | 4 ++-- libraries/entities/src/EntityItemProperties.h | 4 ++-- libraries/entities/src/ZoneEntityItem.h | 12 ++++-------- scripts/system/html/entityProperties.html | 8 ++++---- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index fe3f1a2a14..437aea8d0f 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -88,8 +88,8 @@ private: BackgroundMode _backgroundMode{ BACKGROUND_MODE_INHERIT }; ComponentMode _hazeMode { COMPONENT_MODE_INHERIT }; - ComponentMode _keyLightMode { COMPONENT_MODE_ENABLED }; - ComponentMode _ambientLightMode { COMPONENT_MODE_ENABLED }; + ComponentMode _keyLightMode { COMPONENT_MODE_INHERIT }; + ComponentMode _ambientLightMode { COMPONENT_MODE_INHERIT }; indexed_container::Index _sunIndex{ LightStage::INVALID_INDEX }; indexed_container::Index _shadowIndex{ LightStage::INVALID_INDEX }; diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index e924ab3f94..c5dbb99d69 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -180,8 +180,8 @@ public: DEFINE_PROPERTY_GROUP(Stage, stage, StagePropertyGroup); DEFINE_PROPERTY_REF_ENUM(PROP_HAZE_MODE, HazeMode, hazeMode, uint32_t, (uint32_t)COMPONENT_MODE_INHERIT); - DEFINE_PROPERTY_REF_ENUM(PROP_KEY_LIGHT_MODE, KeyLightMode, keyLightMode, uint32_t, (uint32_t)COMPONENT_MODE_ENABLED); - DEFINE_PROPERTY_REF_ENUM(PROP_AMBIENT_LIGHT_MODE, AmbientLightMode, ambientLightMode, uint32_t, (uint32_t)COMPONENT_MODE_ENABLED); + DEFINE_PROPERTY_REF_ENUM(PROP_KEY_LIGHT_MODE, KeyLightMode, keyLightMode, uint32_t, (uint32_t)COMPONENT_MODE_INHERIT); + DEFINE_PROPERTY_REF_ENUM(PROP_AMBIENT_LIGHT_MODE, AmbientLightMode, ambientLightMode, uint32_t, (uint32_t)COMPONENT_MODE_INHERIT); DEFINE_PROPERTY_GROUP(Skybox, skybox, SkyboxPropertyGroup); DEFINE_PROPERTY_GROUP(Haze, haze, HazePropertyGroup); diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index 6a94d5c63b..a020fa90ba 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -118,20 +118,16 @@ public: static const bool DEFAULT_GHOSTING_ALLOWED; static const QString DEFAULT_FILTER_URL; - static const uint32_t DEFAULT_HAZE_MODE{ (uint32_t)COMPONENT_MODE_INHERIT }; - static const uint32_t DEFAULT_KEY_LIGHT_MODE{ (uint32_t)COMPONENT_MODE_ENABLED }; // so as not to change previous behaviour - static const uint32_t DEFAULT_AMBIENT_LIGHT_MODE{ (uint32_t)COMPONENT_MODE_ENABLED }; - protected: KeyLightPropertyGroup _keyLightProperties; ShapeType _shapeType = DEFAULT_SHAPE_TYPE; QString _compoundShapeURL; - BackgroundMode _backgroundMode = BACKGROUND_MODE_INHERIT; - uint32_t _hazeMode{ DEFAULT_HAZE_MODE }; - uint32_t _keyLightMode{ DEFAULT_KEY_LIGHT_MODE }; - uint32_t _ambientLightMode{ DEFAULT_AMBIENT_LIGHT_MODE }; + BackgroundMode _backgroundMode { BACKGROUND_MODE_INHERIT }; + uint32_t _hazeMode { COMPONENT_MODE_INHERIT }; + uint32_t _keyLightMode { COMPONENT_MODE_INHERIT }; + uint32_t _ambientLightMode { COMPONENT_MODE_INHERIT }; SkyboxPropertyGroup _skyboxProperties; HazePropertyGroup _hazeProperties; diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index bc98dcc25f..c914ec34d4 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -512,9 +512,9 @@
- Inherit + Inherit Off - On + On
@@ -540,9 +540,9 @@
- Inherit + Inherit Off - On + On
From 0b73e7db3f663942455807c6502d0bec385102e9 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Tue, 26 Dec 2017 09:15:13 -0800 Subject: [PATCH 18/46] WIP - adding AmbientLightPropertyGroup --- .../src/RenderableZoneEntityItem.cpp | 6 +- .../src/RenderableZoneEntityItem.h | 1 + .../src/AmbientLightPropertyGroup.cpp | 155 ++++++++++++++++++ .../entities/src/AmbientLightPropertyGroup.h | 83 ++++++++++ .../entities/src/EntityItemProperties.cpp | 1 - libraries/entities/src/EntityItemProperties.h | 1 + libraries/entities/src/EntityPropertyFlags.h | 7 +- .../entities/src/KeyLightPropertyGroup.cpp | 65 ++------ .../entities/src/KeyLightPropertyGroup.h | 2 - libraries/entities/src/ZoneEntityItem.h | 1 + 10 files changed, 260 insertions(+), 62 deletions(-) create mode 100644 libraries/entities/src/AmbientLightPropertyGroup.cpp create mode 100644 libraries/entities/src/AmbientLightPropertyGroup.h diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 80f9836c1c..85c5baff97 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -346,12 +346,12 @@ void ZoneEntityRenderer::updateKeyAmbientFromEntity(const TypedEntityPointer& en // Set the keylight - ambientLight->setAmbientIntensity(_keyLightProperties.getAmbientIntensity()); + ambientLight->setAmbientIntensity(_ambientLightProperties.getAmbientIntensity()); - if (_keyLightProperties.getAmbientURL().isEmpty()) { + if (_ambientLightProperties.getAmbientURL().isEmpty()) { setAmbientURL(_skyboxProperties.getURL()); } else { - setAmbientURL(_keyLightProperties.getAmbientURL()); + setAmbientURL(_ambientLightProperties.getAmbientURL()); } } diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index 437aea8d0f..0e3bed941f 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -111,6 +111,7 @@ private: bool _needHazeUpdate{ true }; KeyLightPropertyGroup _keyLightProperties; + AmbientLightPropertyGroup _ambientLightProperties; HazePropertyGroup _hazeProperties; StagePropertyGroup _stageProperties; SkyboxPropertyGroup _skyboxProperties; diff --git a/libraries/entities/src/AmbientLightPropertyGroup.cpp b/libraries/entities/src/AmbientLightPropertyGroup.cpp new file mode 100644 index 0000000000..dbcb0eef75 --- /dev/null +++ b/libraries/entities/src/AmbientLightPropertyGroup.cpp @@ -0,0 +1,155 @@ +// +// AmbientLightPropertyGroup.cpp +// libraries/entities/src +// +// Created by Nissim Hadar on 2017/12/24. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "AmbientLightPropertyGroup.h" + +#include +#include + +#include "EntityItemProperties.h" +#include "EntityItemPropertiesMacros.h" + +const float AmbientLightPropertyGroup::DEFAULT_AMBIENT_LIGHT_INTENSITY = 0.5f; + +void AmbientLightPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, QScriptValue& properties, + QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const { + + COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_AMBIENT_LIGHT_INTENSITY, AmbientLight, ambientLight, AmbientIntensity, ambientIntensity); + COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_AMBIENT_LIGHT_URL, AmbientLight, ambientLight, AmbientURL, ambientURL); +} + +void AmbientLightPropertyGroup::copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings) { + COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(ambientLight, ambientIntensity, float, setAmbientIntensity); + COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(ambientLight, ambientURL, QString, setAmbientURL); + + // legacy property support + COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(ambientLightAmbientIntensity, float, setAmbientIntensity, getAmbientIntensity); +} + +void AmbientLightPropertyGroup::merge(const AmbientLightPropertyGroup& other) { + COPY_PROPERTY_IF_CHANGED(ambientIntensity); + COPY_PROPERTY_IF_CHANGED(ambientURL); +} + +void AmbientLightPropertyGroup::debugDump() const { + qCDebug(entities) << " AmbientLightPropertyGroup: ---------------------------------------------"; + qCDebug(entities) << " ambientIntensity:" << getAmbientIntensity(); + qCDebug(entities) << " ambientURL:" << getAmbientURL(); +} + +void AmbientLightPropertyGroup::listChangedProperties(QList& out) { + if (ambientIntensityChanged()) { + out << "ambientLight-ambientIntensity"; + } + if (ambientURLChanged()) { + out << "ambientLight-ambientURL"; + } +} + +bool AmbientLightPropertyGroup::appendToEditPacket(OctreePacketData* packetData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const { + + bool successPropertyFits = true; + + APPEND_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_INTENSITY, getAmbientIntensity()); + APPEND_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_URL, getAmbientURL()); + + return true; +} + +bool AmbientLightPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt, + int& processedBytes) { + + int bytesRead = 0; + bool overwriteLocalData = true; + bool somethingChanged = false; + + READ_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_INTENSITY, float, setAmbientIntensity); + READ_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_URL, QString, setAmbientURL); + + DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_AMBIENT_LIGHT_INTENSITY, AmbientIntensity); + DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_AMBIENT_LIGHT_URL, AmbientURL); + + processedBytes += bytesRead; + + Q_UNUSED(somethingChanged); + + return true; +} + +void AmbientLightPropertyGroup::markAllChanged() { + _ambientIntensityChanged = true; + _ambientURLChanged = true; +} + +EntityPropertyFlags AmbientLightPropertyGroup::getChangedProperties() const { + EntityPropertyFlags changedProperties; + + CHECK_PROPERTY_CHANGE(PROP_AMBIENT_LIGHT_INTENSITY, ambientIntensity); + CHECK_PROPERTY_CHANGE(PROP_AMBIENT_LIGHT_URL, ambientURL); + + return changedProperties; +} + +void AmbientLightPropertyGroup::getProperties(EntityItemProperties& properties) const { + COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(AmbientLight, AmbientIntensity, getAmbientIntensity); + COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(AmbientLight, AmbientURL, getAmbientURL); +} + +bool AmbientLightPropertyGroup::setProperties(const EntityItemProperties& properties) { + bool somethingChanged = false; + + SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(AmbientLight, AmbientIntensity, ambientIntensity, setAmbientIntensity); + SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(AmbientLight, AmbientURL, ambientURL, setAmbientURL); + + return somethingChanged; +} + +EntityPropertyFlags AmbientLightPropertyGroup::getEntityProperties(EncodeBitstreamParams& params) const { + EntityPropertyFlags requestedProperties; + + requestedProperties += PROP_AMBIENT_LIGHT_INTENSITY; + requestedProperties += PROP_AMBIENT_LIGHT_URL; + + return requestedProperties; +} + +void AmbientLightPropertyGroup::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, + EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const { + + bool successPropertyFits = true; + + APPEND_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_INTENSITY, getAmbientIntensity()); + APPEND_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_URL, getAmbientURL()); +} + +int AmbientLightPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData, + bool& somethingChanged) { + + int bytesRead = 0; + const unsigned char* dataAt = data; + + READ_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_INTENSITY, float, setAmbientIntensity); + READ_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_URL, QString, setAmbientURL); + + return bytesRead; +} diff --git a/libraries/entities/src/AmbientLightPropertyGroup.h b/libraries/entities/src/AmbientLightPropertyGroup.h new file mode 100644 index 0000000000..fbbc7c9900 --- /dev/null +++ b/libraries/entities/src/AmbientLightPropertyGroup.h @@ -0,0 +1,83 @@ +// +// AmbientLightPropertyGroup.h +// libraries/entities/src +// +// Created by Nissim Hadar on 2017/12/24. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#ifndef hifi_AmbientLightPropertyGroup_h +#define hifi_AmbientLightPropertyGroup_h + +#include + +#include + +#include +#include "EntityItemPropertiesMacros.h" +#include "PropertyGroup.h" + +class EntityItemProperties; +class EncodeBitstreamParams; +class OctreePacketData; +class EntityTreeElementExtraEncodeData; +class ReadBitstreamToTreeParams; + +class AmbientLightPropertyGroup : public PropertyGroup { +public: + // EntityItemProperty related helpers + virtual void copyToScriptValue(const EntityPropertyFlags& desiredProperties, QScriptValue& properties, + QScriptEngine* engine, bool skipDefaults, + EntityItemProperties& defaultEntityProperties) const override; + virtual void copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings) override; + + void merge(const AmbientLightPropertyGroup& other); + + virtual void debugDump() const override; + virtual void listChangedProperties(QList& out) override; + + virtual bool appendToEditPacket(OctreePacketData* packetData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const override; + + virtual bool decodeFromEditPacket(EntityPropertyFlags& propertyFlags, + const unsigned char*& dataAt, int& processedBytes) override; + virtual void markAllChanged() override; + virtual EntityPropertyFlags getChangedProperties() const override; + + // EntityItem related helpers + // methods for getting/setting all properties of an entity + virtual void getProperties(EntityItemProperties& propertiesOut) const override; + + /// returns true if something changed + virtual bool setProperties(const EntityItemProperties& properties) override; + + virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const override; + + virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, + EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const override; + + virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData, + bool& somethingChanged) override; + + static const float DEFAULT_AMBIENT_LIGHT_INTENSITY; + + DEFINE_PROPERTY(PROP_AMBIENT_LIGHT_INTENSITY, AmbientIntensity, ambientIntensity, float, DEFAULT_AMBIENT_LIGHT_INTENSITY); + DEFINE_PROPERTY_REF(PROP_AMBIENT_LIGHT_URL, AmbientURL, ambientURL, QString, ""); +}; + +#endif // hifi_AmbientLightPropertyGroup_h diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 570f12fc9b..01ae7d36f9 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -1162,7 +1162,6 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_PROPERTY_TO_MAP(PROP_KEYLIGHT_COLOR, KeyLightColor, keyLightColor, xColor); ADD_PROPERTY_TO_MAP(PROP_KEYLIGHT_INTENSITY, KeyLightIntensity, keyLightIntensity, float); - ADD_PROPERTY_TO_MAP(PROP_KEYLIGHT_AMBIENT_INTENSITY, KeyLightAmbientIntensity, keyLightAmbientIntensity, float); ADD_PROPERTY_TO_MAP(PROP_KEYLIGHT_DIRECTION, KeyLightDirection, keyLightDirection, glm::vec3); ADD_PROPERTY_TO_MAP(PROP_VOXEL_VOLUME_SIZE, VoxelVolumeSize, voxelVolumeSize, glm::vec3); ADD_PROPERTY_TO_MAP(PROP_VOXEL_DATA, VoxelData, voxelData, QByteArray); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index c5dbb99d69..3de76e3777 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -172,6 +172,7 @@ public: DEFINE_PROPERTY(PROP_RADIUS_FINISH, RadiusFinish, radiusFinish, float, particle::DEFAULT_RADIUS_FINISH); DEFINE_PROPERTY(PROP_EMITTER_SHOULD_TRAIL, EmitterShouldTrail, emitterShouldTrail, bool, particle::DEFAULT_EMITTER_SHOULD_TRAIL); DEFINE_PROPERTY_GROUP(KeyLight, keyLight, KeyLightPropertyGroup); + DEFINE_PROPERTY_GROUP(AmbientLight, ambientLight, AmbientLightPropertyGroup); DEFINE_PROPERTY_REF(PROP_VOXEL_VOLUME_SIZE, VoxelVolumeSize, voxelVolumeSize, glm::vec3, PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE); DEFINE_PROPERTY_REF(PROP_VOXEL_DATA, VoxelData, voxelData, QByteArray, PolyVoxEntityItem::DEFAULT_VOXEL_DATA); DEFINE_PROPERTY_REF(PROP_VOXEL_SURFACE_STYLE, VoxelSurfaceStyle, voxelSurfaceStyle, uint16_t, PolyVoxEntityItem::DEFAULT_VOXEL_SURFACE_STYLE); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 73f6ec55c5..8317bad05f 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -244,7 +244,6 @@ enum EntityPropertyList { // the size of the properties bitflags mask PROP_KEYLIGHT_COLOR = PROP_COLOR, PROP_KEYLIGHT_INTENSITY = PROP_INTENSITY, - PROP_KEYLIGHT_AMBIENT_INTENSITY = PROP_CUTOFF, PROP_KEYLIGHT_DIRECTION = PROP_EXPONENT, PROP_STAGE_SUN_MODEL_ENABLED = PROP_IS_SPOTLIGHT, PROP_STAGE_LATITUDE = PROP_DIFFUSE_COLOR, @@ -257,8 +256,10 @@ enum EntityPropertyList { PROP_SKYBOX_COLOR = PROP_ANIMATION_URL, PROP_SKYBOX_URL = PROP_ANIMATION_FPS, - PROP_KEYLIGHT_AMBIENT_URL = PROP_ANIMATION_PLAYING, - + + PROP_AMBIENT_LIGHT_INTENSITY = PROP_CUTOFF, + PROP_AMBIENT_LIGHT_URL = PROP_ANIMATION_PLAYING, + // Aliases/Piggyback properties for Web. These properties intentionally reuse the enum values for // other properties which will never overlap with each other. PROP_SOURCE_URL = PROP_MODEL_URL, diff --git a/libraries/entities/src/KeyLightPropertyGroup.cpp b/libraries/entities/src/KeyLightPropertyGroup.cpp index 4246da309b..4bf8818c99 100644 --- a/libraries/entities/src/KeyLightPropertyGroup.cpp +++ b/libraries/entities/src/KeyLightPropertyGroup.cpp @@ -17,54 +17,41 @@ #include "EntityItemProperties.h" #include "EntityItemPropertiesMacros.h" - const xColor KeyLightPropertyGroup::DEFAULT_KEYLIGHT_COLOR = { 255, 255, 255 }; const float KeyLightPropertyGroup::DEFAULT_KEYLIGHT_INTENSITY = 1.0f; const float KeyLightPropertyGroup::DEFAULT_KEYLIGHT_AMBIENT_INTENSITY = 0.5f; const glm::vec3 KeyLightPropertyGroup::DEFAULT_KEYLIGHT_DIRECTION = { 0.0f, -1.0f, 0.0f }; -void KeyLightPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, QScriptValue& properties, QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const { - +void KeyLightPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desiredProperties, QScriptValue& properties, + QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const { + COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_COLOR, KeyLight, keyLight, Color, color); COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_INTENSITY, KeyLight, keyLight, Intensity, intensity); - COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_AMBIENT_INTENSITY, KeyLight, keyLight, AmbientIntensity, ambientIntensity); COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_DIRECTION, KeyLight, keyLight, Direction, direction); - COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_AMBIENT_URL, KeyLight, keyLight, AmbientURL, ambientURL); - } void KeyLightPropertyGroup::copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings) { - COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, color, xColor, setColor); COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, intensity, float, setIntensity); - COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, ambientIntensity, float, setAmbientIntensity); COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, direction, glmVec3, setDirection); - COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE(keyLight, ambientURL, QString, setAmbientURL); // legacy property support COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightColor, xColor, setColor, getColor); COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightIntensity, float, setIntensity, getIntensity); - COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightAmbientIntensity, float, setAmbientIntensity, getAmbientIntensity); COPY_PROPERTY_FROM_QSCRIPTVALUE_GETTER(keyLightDirection, glmVec3, setDirection, getDirection); } void KeyLightPropertyGroup::merge(const KeyLightPropertyGroup& other) { COPY_PROPERTY_IF_CHANGED(color); COPY_PROPERTY_IF_CHANGED(intensity); - COPY_PROPERTY_IF_CHANGED(ambientIntensity); COPY_PROPERTY_IF_CHANGED(direction); - COPY_PROPERTY_IF_CHANGED(ambientURL); } - - void KeyLightPropertyGroup::debugDump() const { qCDebug(entities) << " KeyLightPropertyGroup: ---------------------------------------------"; qCDebug(entities) << " color:" << getColor(); // << "," << getColor()[1] << "," << getColor()[2]; qCDebug(entities) << " intensity:" << getIntensity(); qCDebug(entities) << " direction:" << getDirection(); - qCDebug(entities) << " ambientIntensity:" << getAmbientIntensity(); - qCDebug(entities) << " ambientURL:" << getAmbientURL(); } void KeyLightPropertyGroup::listChangedProperties(QList& out) { @@ -77,52 +64,39 @@ void KeyLightPropertyGroup::listChangedProperties(QList& out) { if (directionChanged()) { out << "keyLight-direction"; } - if (ambientIntensityChanged()) { - out << "keyLight-ambientIntensity"; - } - if (ambientURLChanged()) { - out << "keyLight-ambientURL"; - } } - bool KeyLightPropertyGroup::appendToEditPacket(OctreePacketData* packetData, - EntityPropertyFlags& requestedProperties, - EntityPropertyFlags& propertyFlags, - EntityPropertyFlags& propertiesDidntFit, - int& propertyCount, - OctreeElement::AppendState& appendState) const { + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const { bool successPropertyFits = true; APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, getIntensity()); - APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_INTENSITY, getAmbientIntensity()); APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, getDirection()); - APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_URL, getAmbientURL()); return true; } - -bool KeyLightPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt , int& processedBytes) { - +bool KeyLightPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt, + int& processedBytes) { + int bytesRead = 0; bool overwriteLocalData = true; bool somethingChanged = false; READ_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, xColor, setColor); READ_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, float, setIntensity); - READ_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_INTENSITY, float, setAmbientIntensity); READ_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, glm::vec3, setDirection); - READ_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_URL, QString, setAmbientURL); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_COLOR, Color); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_INTENSITY, Intensity); - DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_AMBIENT_INTENSITY, AmbientIntensity); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_DIRECTION, Direction); - DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_AMBIENT_URL, AmbientURL); processedBytes += bytesRead; @@ -134,9 +108,7 @@ bool KeyLightPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFl void KeyLightPropertyGroup::markAllChanged() { _colorChanged = true; _intensityChanged = true; - _ambientIntensityChanged = true; _directionChanged = true; - _ambientURLChanged = true; } EntityPropertyFlags KeyLightPropertyGroup::getChangedProperties() const { @@ -144,20 +116,15 @@ EntityPropertyFlags KeyLightPropertyGroup::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_COLOR, color); CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_INTENSITY, intensity); - CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_AMBIENT_INTENSITY, ambientIntensity); CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_DIRECTION, direction); - CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_AMBIENT_URL, ambientURL); return changedProperties; } -void KeyLightPropertyGroup::getProperties(EntityItemProperties& properties) const { - +void KeyLightPropertyGroup::getProperties(EntityItemProperties& properties) const { COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(KeyLight, Color, getColor); COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(KeyLight, Intensity, getIntensity); - COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(KeyLight, AmbientIntensity, getAmbientIntensity); COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(KeyLight, Direction, getDirection); - COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(KeyLight, AmbientURL, getAmbientURL); } bool KeyLightPropertyGroup::setProperties(const EntityItemProperties& properties) { @@ -165,9 +132,7 @@ bool KeyLightPropertyGroup::setProperties(const EntityItemProperties& properties SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(KeyLight, Color, color, setColor); SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(KeyLight, Intensity, intensity, setIntensity); - SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(KeyLight, AmbientIntensity, ambientIntensity, setAmbientIntensity); SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(KeyLight, Direction, direction, setDirection); - SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(KeyLight, AmbientURL, ambientURL, setAmbientURL); return somethingChanged; } @@ -177,9 +142,7 @@ EntityPropertyFlags KeyLightPropertyGroup::getEntityProperties(EncodeBitstreamPa requestedProperties += PROP_KEYLIGHT_COLOR; requestedProperties += PROP_KEYLIGHT_INTENSITY; - requestedProperties += PROP_KEYLIGHT_AMBIENT_INTENSITY; requestedProperties += PROP_KEYLIGHT_DIRECTION; - requestedProperties += PROP_KEYLIGHT_AMBIENT_URL; return requestedProperties; } @@ -196,9 +159,7 @@ void KeyLightPropertyGroup::appendSubclassData(OctreePacketData* packetData, Enc APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, getIntensity()); - APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_INTENSITY, getAmbientIntensity()); APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, getDirection()); - APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_URL, getAmbientURL()); } int KeyLightPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, @@ -211,9 +172,7 @@ int KeyLightPropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char* READ_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, xColor, setColor); READ_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, float, setIntensity); - READ_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_INTENSITY, float, setAmbientIntensity); READ_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, glm::vec3, setDirection); - READ_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_URL, QString, setAmbientURL); return bytesRead; } diff --git a/libraries/entities/src/KeyLightPropertyGroup.h b/libraries/entities/src/KeyLightPropertyGroup.h index 210d410bd9..f33ebb282d 100644 --- a/libraries/entities/src/KeyLightPropertyGroup.h +++ b/libraries/entities/src/KeyLightPropertyGroup.h @@ -81,9 +81,7 @@ public: DEFINE_PROPERTY_REF(PROP_KEYLIGHT_COLOR, Color, color, xColor, DEFAULT_KEYLIGHT_COLOR); DEFINE_PROPERTY(PROP_KEYLIGHT_INTENSITY, Intensity, intensity, float, DEFAULT_KEYLIGHT_INTENSITY); - DEFINE_PROPERTY(PROP_KEYLIGHT_AMBIENT_INTENSITY, AmbientIntensity, ambientIntensity, float, DEFAULT_KEYLIGHT_AMBIENT_INTENSITY); DEFINE_PROPERTY_REF(PROP_KEYLIGHT_DIRECTION, Direction, direction, glm::vec3, DEFAULT_KEYLIGHT_DIRECTION); - DEFINE_PROPERTY_REF(PROP_KEYLIGHT_AMBIENT_URL, AmbientURL, ambientURL, QString, ""); }; #endif // hifi_KeyLightPropertyGroup_h diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index a020fa90ba..6f60ffaca9 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -13,6 +13,7 @@ #define hifi_ZoneEntityItem_h #include "KeyLightPropertyGroup.h" +#include "AmbientLightPropertyGroup.h" #include "EntityItem.h" #include "EntityTree.h" #include "SkyboxPropertyGroup.h" From 1fa8f7c55bd19b383aa9ba16214bbb31be4f6e8f Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Tue, 26 Dec 2017 09:15:45 -0800 Subject: [PATCH 19/46] WIP - adding AmbientLightPropertyGroup --- libraries/entities/src/KeyLightPropertyGroup.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/src/KeyLightPropertyGroup.cpp b/libraries/entities/src/KeyLightPropertyGroup.cpp index 4bf8818c99..61d48f7cb1 100644 --- a/libraries/entities/src/KeyLightPropertyGroup.cpp +++ b/libraries/entities/src/KeyLightPropertyGroup.cpp @@ -93,7 +93,7 @@ bool KeyLightPropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFl READ_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, float, setIntensity); READ_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, glm::vec3, setDirection); - + DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_COLOR, Color); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_INTENSITY, Intensity); DECODE_GROUP_PROPERTY_HAS_CHANGED(PROP_KEYLIGHT_DIRECTION, Direction); From 4ffd896cedbe7d611d83d26201cc57e00b6b7175 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Tue, 26 Dec 2017 11:15:33 -0800 Subject: [PATCH 20/46] WIP - adding AmbientLightPropertyGroup --- .../src/RenderableZoneEntityItem.cpp | 16 +++++--- .../src/RenderableZoneEntityItem.h | 2 +- .../entities/src/EntityItemProperties.cpp | 15 ++++++- libraries/entities/src/ZoneEntityItem.cpp | 35 ++++++++++++++-- libraries/entities/src/ZoneEntityItem.h | 5 ++- scripts/system/html/js/entityProperties.js | 40 ++++++++++++------- 6 files changed, 85 insertions(+), 28 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 85c5baff97..e6af7bcdd0 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -212,7 +212,8 @@ void ZoneEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scen // FIXME one of the bools here could become true between being fetched and being reset, // resulting in a lost update - bool sunChanged = entity->keyLightPropertiesChanged(); + bool keyLightChanged = entity->keyLightPropertiesChanged(); + bool ambientLightChanged = entity->ambientLightPropertiesChanged(); bool backgroundChanged = entity->backgroundPropertiesChanged(); bool skyboxChanged = entity->skyboxPropertiesChanged(); bool hazeChanged = entity->hazePropertiesChanged(); @@ -223,6 +224,7 @@ void ZoneEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scen _lastDimensions = entity->getDimensions(); _keyLightProperties = entity->getKeyLightProperties(); + _ambientLightProperties = entity->getAmbientLightProperties(); _skyboxProperties = entity->getSkyboxProperties(); _hazeProperties = entity->getHazeProperties(); _stageProperties = entity->getStageProperties(); @@ -248,12 +250,12 @@ void ZoneEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scen updateKeyZoneItemFromEntity(); - if (sunChanged) { + if (keyLightChanged) { updateKeySunFromEntity(entity); } - if (sunChanged || skyboxChanged) { - updateKeyAmbientFromEntity(entity); + if (ambientLightChanged || skyboxChanged) { + updateAmbientLightFromEntity(entity); } if (backgroundChanged || skyboxChanged) { @@ -279,9 +281,11 @@ ItemKey ZoneEntityRenderer::getKey() { bool ZoneEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { if (entity->keyLightPropertiesChanged() || + entity->ambientLightPropertiesChanged() || entity->backgroundPropertiesChanged() || entity->hazePropertiesChanged() || entity->skyboxPropertiesChanged()) { + return true; } @@ -336,7 +340,7 @@ void ZoneEntityRenderer::updateKeySunFromEntity(const TypedEntityPointer& entity sunLight->setDirection(_keyLightProperties.getDirection()); } -void ZoneEntityRenderer::updateKeyAmbientFromEntity(const TypedEntityPointer& entity) { +void ZoneEntityRenderer::updateAmbientLightFromEntity(const TypedEntityPointer& entity) { setAmbientLightMode((ComponentMode)entity->getAmbientLightMode()); const auto& ambientLight = editAmbientLight(); @@ -345,7 +349,7 @@ void ZoneEntityRenderer::updateKeyAmbientFromEntity(const TypedEntityPointer& en ambientLight->setOrientation(_lastRotation); - // Set the keylight + // Set the ambient light ambientLight->setAmbientIntensity(_ambientLightProperties.getAmbientIntensity()); if (_ambientLightProperties.getAmbientURL().isEmpty()) { diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index 0e3bed941f..f7473f1898 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -47,7 +47,7 @@ protected: private: void updateKeyZoneItemFromEntity(); void updateKeySunFromEntity(const TypedEntityPointer& entity); - void updateKeyAmbientFromEntity(const TypedEntityPointer& entity); + void updateAmbientLightFromEntity(const TypedEntityPointer& entity); void updateHazeFromEntity(const TypedEntityPointer& entity); void updateKeyBackgroundFromEntity(const TypedEntityPointer& entity); void updateAmbientMap(); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 01ae7d36f9..d13569e260 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -35,6 +35,7 @@ SkyboxPropertyGroup EntityItemProperties::_staticSkybox; HazePropertyGroup EntityItemProperties::_staticHaze; StagePropertyGroup EntityItemProperties::_staticStage; KeyLightPropertyGroup EntityItemProperties::_staticKeyLight; +AmbientLightPropertyGroup EntityItemProperties::_staticAmbientLight; EntityPropertyList PROP_LAST_ITEM = (EntityPropertyList)(PROP_AFTER_LAST_ITEM - 1); @@ -79,6 +80,7 @@ void EntityItemProperties::debugDump() const { getSkybox().debugDump(); getHaze().debugDump(); getKeyLight().debugDump(); + getAmbientLight().debugDump(); qCDebug(entities) << " changed properties..."; EntityPropertyFlags props = getChangedProperties(); @@ -438,6 +440,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { changedProperties += _animation.getChangedProperties(); changedProperties += _keyLight.getChangedProperties(); + changedProperties += _ambientLight.getChangedProperties(); changedProperties += _skybox.getChangedProperties(); changedProperties += _stage.getChangedProperties(); changedProperties += _haze.getChangedProperties(); @@ -612,6 +615,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool // Zones only if (_type == EntityTypes::Zone) { _keyLight.copyToScriptValue(_desiredProperties, properties, engine, skipDefaults, defaultEntityProperties); + _ambientLight.copyToScriptValue(_desiredProperties, properties, engine, skipDefaults, defaultEntityProperties); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_BACKGROUND_MODE, backgroundMode, getBackgroundModeAsString()); @@ -845,6 +849,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool _animation.copyFromScriptValue(object, _defaultSettings); _keyLight.copyFromScriptValue(object, _defaultSettings); + _ambientLight.copyFromScriptValue(object, _defaultSettings); _skybox.copyFromScriptValue(object, _defaultSettings); _stage.copyFromScriptValue(object, _defaultSettings); _haze.copyFromScriptValue(object, _defaultSettings); @@ -994,6 +999,7 @@ void EntityItemProperties::merge(const EntityItemProperties& other) { _animation.merge(other._animation); _keyLight.merge(other._keyLight); + _ambientLight.merge(other._ambientLight); _skybox.merge(other._skybox); _stage.merge(other._stage); _haze.merge(other._haze); @@ -1476,6 +1482,9 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy _staticKeyLight.setProperties(properties); _staticKeyLight.appendToEditPacket(packetData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState); + _staticAmbientLight.setProperties(properties); + _staticAmbientLight.appendToEditPacket(packetData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState); + _staticStage.setProperties(properties); _staticStage.appendToEditPacket(packetData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState); @@ -1495,7 +1504,6 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy _staticHaze.setProperties(properties); _staticHaze.appendToEditPacket(packetData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState); - APPEND_ENTITY_PROPERTY(PROP_KEY_LIGHT_MODE, (uint32_t)properties.getKeyLightMode()); APPEND_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_MODE, (uint32_t)properties.getAmbientLightMode()); } @@ -1834,7 +1842,8 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int } if (properties.getType() == EntityTypes::Zone) { - properties.getKeyLight().decodeFromEditPacket(propertyFlags, dataAt , processedBytes); + properties.getKeyLight().decodeFromEditPacket(propertyFlags, dataAt, processedBytes); + properties.getAmbientLight().decodeFromEditPacket(propertyFlags, dataAt, processedBytes); properties.getStage().decodeFromEditPacket(propertyFlags, dataAt , processedBytes); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SHAPE_TYPE, ShapeType, setShapeType); @@ -2079,6 +2088,7 @@ void EntityItemProperties::markAllChanged() { _staticCertificateVersionChanged = true; _keyLight.markAllChanged(); + _ambientLight.markAllChanged(); _backgroundModeChanged = true; _hazeModeChanged = true; @@ -2540,6 +2550,7 @@ QList EntityItemProperties::listChangedProperties() { getAnimation().listChangedProperties(out); getKeyLight().listChangedProperties(out); + getAmbientLight().listChangedProperties(out); getSkybox().listChangedProperties(out); getStage().listChangedProperties(out); getHaze().listChangedProperties(out); diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp index 3b30774656..bab7d8c7b7 100644 --- a/libraries/entities/src/ZoneEntityItem.cpp +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -53,7 +53,11 @@ EntityItemProperties ZoneEntityItem::getProperties(EntityPropertyFlags desiredPr withReadLock([&] { _keyLightProperties.getProperties(properties); }); - + + withReadLock([&] { + _ambientLightProperties.getProperties(properties); + }); + _stageProperties.getProperties(properties); COPY_ENTITY_PROPERTY_TO_PROPERTIES(shapeType, getShapeType); @@ -103,6 +107,9 @@ bool ZoneEntityItem::setSubClassProperties(const EntityItemProperties& propertie withWriteLock([&] { _keyLightPropertiesChanged = _keyLightProperties.setProperties(properties); }); + withWriteLock([&] { + _ambientLightPropertiesChanged = _ambientLightProperties.setProperties(properties); + }); _stagePropertiesChanged = _stageProperties.setProperties(properties); @@ -125,7 +132,8 @@ bool ZoneEntityItem::setSubClassProperties(const EntityItemProperties& propertie SET_ENTITY_PROPERTY_FROM_PROPERTIES(keyLightMode, setKeyLightMode); SET_ENTITY_PROPERTY_FROM_PROPERTIES(ambientLightMode, setAmbientLightMode); - somethingChanged = somethingChanged || _keyLightPropertiesChanged || _stagePropertiesChanged || _skyboxPropertiesChanged || _hazePropertiesChanged; + somethingChanged = somethingChanged || _keyLightPropertiesChanged || _ambientLightPropertiesChanged || + _stagePropertiesChanged || _skyboxPropertiesChanged || _hazePropertiesChanged; return somethingChanged; } @@ -147,6 +155,16 @@ int ZoneEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, bytesRead += bytesFromKeylight; dataAt += bytesFromKeylight; + int bytesFromAmbientlight; + withWriteLock([&] { + bytesFromAmbientlight = _ambientLightProperties.readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args, + propertyFlags, overwriteLocalData, _ambientLightPropertiesChanged); + }); + + somethingChanged = somethingChanged || _ambientLightPropertiesChanged; + bytesRead += bytesFromAmbientlight; + dataAt += bytesFromAmbientlight; + int bytesFromStage = _stageProperties.readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args, propertyFlags, overwriteLocalData, _stagePropertiesChanged); somethingChanged = somethingChanged || _stagePropertiesChanged; @@ -194,6 +212,10 @@ EntityPropertyFlags ZoneEntityItem::getEntityProperties(EncodeBitstreamParams& p requestedProperties += _keyLightProperties.getEntityProperties(params); }); + withReadLock([&] { + requestedProperties += _ambientLightProperties.getEntityProperties(params); + }); + requestedProperties += _stageProperties.getEntityProperties(params); requestedProperties += PROP_SHAPE_TYPE; @@ -228,10 +250,13 @@ void ZoneEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits bool successPropertyFits = true; _keyLightProperties.appendSubclassData(packetData, params, modelTreeElementExtraEncodeData, requestedProperties, - propertyFlags, propertiesDidntFit, propertyCount, appendState); + propertyFlags, propertiesDidntFit, propertyCount, appendState); + + _ambientLightProperties.appendSubclassData(packetData, params, modelTreeElementExtraEncodeData, requestedProperties, + propertyFlags, propertiesDidntFit, propertyCount, appendState); _stageProperties.appendSubclassData(packetData, params, modelTreeElementExtraEncodeData, requestedProperties, - propertyFlags, propertiesDidntFit, propertyCount, appendState); + propertyFlags, propertiesDidntFit, propertyCount, appendState); APPEND_ENTITY_PROPERTY(PROP_SHAPE_TYPE, (uint32_t)getShapeType()); @@ -265,6 +290,7 @@ void ZoneEntityItem::debugDump() const { qCDebug(entities) << " _ambientLightMode:" << EntityItemProperties::getAmbientLightModeString(_ambientLightMode); _keyLightProperties.debugDump(); + _ambientLightProperties.debugDump(); _skyboxProperties.debugDump(); _hazeProperties.debugDump(); _stageProperties.debugDump(); @@ -330,6 +356,7 @@ QString ZoneEntityItem::getCompoundShapeURL() const { void ZoneEntityItem::resetRenderingPropertiesChanged() { withWriteLock([&] { _keyLightPropertiesChanged = false; + _ambientLightPropertiesChanged = false; _backgroundPropertiesChanged = false; _skyboxPropertiesChanged = false; _hazePropertiesChanged = false; diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index 6f60ffaca9..53c011b5ad 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -67,6 +67,7 @@ public: virtual void setCompoundShapeURL(const QString& url); KeyLightPropertyGroup getKeyLightProperties() const { return resultWithReadLock([&] { return _keyLightProperties; }); } + AmbientLightPropertyGroup getAmbientLightProperties() const { return resultWithReadLock([&] { return _ambientLightProperties; }); } void setBackgroundMode(BackgroundMode value) { _backgroundMode = value; _backgroundPropertiesChanged = true; } BackgroundMode getBackgroundMode() const { return _backgroundMode; } @@ -94,6 +95,7 @@ public: void setFilterURL(const QString url); bool keyLightPropertiesChanged() const { return _keyLightPropertiesChanged; } + bool ambientLightPropertiesChanged() const { return _ambientLightPropertiesChanged; } bool backgroundPropertiesChanged() const { return _backgroundPropertiesChanged; } bool skyboxPropertiesChanged() const { return _skyboxPropertiesChanged; } @@ -121,6 +123,7 @@ public: protected: KeyLightPropertyGroup _keyLightProperties; + AmbientLightPropertyGroup _ambientLightProperties; ShapeType _shapeType = DEFAULT_SHAPE_TYPE; QString _compoundShapeURL; @@ -140,11 +143,11 @@ protected: // Dirty flags turn true when either keylight properties is changing values. bool _keyLightPropertiesChanged { false }; + bool _ambientLightPropertiesChanged { false }; bool _backgroundPropertiesChanged{ false }; bool _skyboxPropertiesChanged { false }; bool _hazePropertiesChanged{ false }; bool _stagePropertiesChanged { false }; - bool _ambientLightPropertiesChanged { false }; static bool _drawZoneBoundaries; static bool _zonesArePickable; diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index 0fd88d9f19..5d788726f6 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -640,6 +640,7 @@ function loaded() { var elZoneStageSunModelEnabled = document.getElementById("property-zone-stage-sun-model-enabled"); + // Key light var elZoneKeyLightModeInherit = document.getElementById("property-zone-key-light-mode-inherit"); var elZoneKeyLightModeDisabled = document.getElementById("property-zone-key-light-mode-disabled"); var elZoneKeyLightModeEnabled = document.getElementById("property-zone-key-light-mode-enabled"); @@ -649,16 +650,18 @@ function loaded() { var elZoneKeyLightColorGreen = document.getElementById("property-zone-key-light-color-green"); var elZoneKeyLightColorBlue = document.getElementById("property-zone-key-light-color-blue"); var elZoneKeyLightIntensity = document.getElementById("property-zone-key-intensity"); - var elZoneKeyLightAmbientIntensity = document.getElementById("property-zone-key-ambient-intensity"); var elZoneKeyLightDirectionX = document.getElementById("property-zone-key-light-direction-x"); var elZoneKeyLightDirectionY = document.getElementById("property-zone-key-light-direction-y"); + // Ambient light var elZoneAmbientLightModeInherit = document.getElementById("property-zone-ambient-light-mode-inherit"); var elZoneAmbientLightModeDisabled = document.getElementById("property-zone-ambient-light-mode-disabled"); var elZoneAmbientLightModeEnabled = document.getElementById("property-zone-ambient-light-mode-enabled"); - var elZoneKeyLightAmbientURL = document.getElementById("property-zone-key-ambient-url"); + var elZoneAmbientLightIntensity = document.getElementById("property-zone-key-ambient-intensity"); + var elZoneAmbientLightURL = document.getElementById("property-zone-key-ambient-url"); + // Haze var elZoneHazeModeInherit = document.getElementById("property-zone-haze-mode-inherit"); var elZoneHazeModeDisabled = document.getElementById("property-zone-haze-mode-disabled"); var elZoneHazeModeEnabled = document.getElementById("property-zone-haze-mode-enabled"); @@ -1012,7 +1015,7 @@ function loaded() { elLightCutoff.value = properties.cutoff.toFixed(2); } else if (properties.type === "Zone") { - + // Key light elZoneKeyLightModeInherit.checked = (properties.keyLightMode === 'inherit'); elZoneKeyLightModeDisabled.checked = (properties.keyLightMode === 'disabled'); elZoneKeyLightModeEnabled.checked = (properties.keyLightMode === 'enabled'); @@ -1024,16 +1027,18 @@ function loaded() { elZoneKeyLightColorGreen.value = properties.keyLight.color.green; elZoneKeyLightColorBlue.value = properties.keyLight.color.blue; elZoneKeyLightIntensity.value = properties.keyLight.intensity.toFixed(2); - elZoneKeyLightAmbientIntensity.value = properties.keyLight.ambientIntensity.toFixed(2); elZoneKeyLightDirectionX.value = properties.keyLight.direction.x.toFixed(2); elZoneKeyLightDirectionY.value = properties.keyLight.direction.y.toFixed(2); + // Ambient light elZoneAmbientLightModeInherit.checked = (properties.ambientLightMode === 'inherit'); elZoneAmbientLightModeDisabled.checked = (properties.ambientLightMode === 'disabled'); elZoneAmbientLightModeEnabled.checked = (properties.ambientLightMode === 'enabled'); - elZoneKeyLightAmbientURL.value = properties.keyLight.ambientURL; + elZoneAmbientLightIntensity.value = properties.ambientLight.ambientIntensity.toFixed(2); + elZoneAmbientLightURL.value = properties.ambientLight.ambientURL; + // Haze elZoneHazeModeInherit.checked = (properties.hazeMode === 'inherit'); elZoneHazeModeDisabled.checked = (properties.hazeMode === 'disabled'); elZoneHazeModeEnabled.checked = (properties.hazeMode === 'enabled'); @@ -1399,6 +1404,7 @@ function loaded() { var textBackgroundColorChangeFunction = createEmitColorPropertyUpdateFunction( 'backgroundColor', elTextBackgroundColorRed, elTextBackgroundColorGreen, elTextBackgroundColorBlue); + elTextBackgroundColorRed.addEventListener('change', textBackgroundColorChangeFunction); elTextBackgroundColorGreen.addEventListener('change', textBackgroundColorChangeFunction); elTextBackgroundColorBlue.addEventListener('change', textBackgroundColorChangeFunction); @@ -1419,6 +1425,7 @@ function loaded() { } })); + // Key light var keyLightModeChanged = createZoneComponentModeChangedFunction('keyLightMode', elZoneKeyLightModeInherit, elZoneKeyLightModeDisabled, elZoneKeyLightModeEnabled); @@ -1446,12 +1453,20 @@ function loaded() { })); var zoneKeyLightColorChangeFunction = createEmitGroupColorPropertyUpdateFunction('keyLight', 'color', elZoneKeyLightColorRed, elZoneKeyLightColorGreen, elZoneKeyLightColorBlue); + elZoneKeyLightColorRed.addEventListener('change', zoneKeyLightColorChangeFunction); elZoneKeyLightColorGreen.addEventListener('change', zoneKeyLightColorChangeFunction); elZoneKeyLightColorBlue.addEventListener('change', zoneKeyLightColorChangeFunction); elZoneKeyLightIntensity.addEventListener('change', createEmitGroupNumberPropertyUpdateFunction('keyLight', 'intensity')); + var zoneKeyLightDirectionChangeFunction = createEmitGroupVec3PropertyUpdateFunction('keyLight', 'direction', + elZoneKeyLightDirectionX, elZoneKeyLightDirectionY); + + elZoneKeyLightDirectionX.addEventListener('change', zoneKeyLightDirectionChangeFunction); + elZoneKeyLightDirectionY.addEventListener('change', zoneKeyLightDirectionChangeFunction); + + // Ambient light var ambientLightModeChanged = createZoneComponentModeChangedFunction('ambientLightMode', elZoneAmbientLightModeInherit, elZoneAmbientLightModeDisabled, elZoneAmbientLightModeEnabled); @@ -1459,16 +1474,13 @@ function loaded() { elZoneAmbientLightModeDisabled.addEventListener('change', ambientLightModeChanged); elZoneAmbientLightModeEnabled.addEventListener('change', ambientLightModeChanged); - elZoneKeyLightAmbientIntensity.addEventListener('change', - createEmitGroupNumberPropertyUpdateFunction('keyLight', 'ambientIntensity')); - elZoneKeyLightAmbientURL.addEventListener('change', - createEmitGroupTextPropertyUpdateFunction('keyLight', 'ambientURL')); - var zoneKeyLightDirectionChangeFunction = - createEmitGroupVec3PropertyUpdateFunction('keyLight', 'direction', - elZoneKeyLightDirectionX, elZoneKeyLightDirectionY); - elZoneKeyLightDirectionX.addEventListener('change', zoneKeyLightDirectionChangeFunction); - elZoneKeyLightDirectionY.addEventListener('change', zoneKeyLightDirectionChangeFunction); + elZoneAmbientLightIntensity.addEventListener('change', + createEmitGroupNumberPropertyUpdateFunction('ambientLight', 'ambientIntensity')); + elZoneAmbientLightURL.addEventListener('change', + createEmitGroupTextPropertyUpdateFunction('ambientLight', 'ambientURL')); + + // Haze var hazeModeChanged = createZoneComponentModeChangedFunction('hazeMode', elZoneHazeModeInherit, elZoneHazeModeDisabled, elZoneHazeModeEnabled); From 9b9295aaecdd4d1352463429d521ecc4dd641568 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Wed, 27 Dec 2017 14:17:05 -0800 Subject: [PATCH 21/46] Script that uses date, time and coordinates to compute sun position - this is then used to position the keylight. --- scripts/developer/sunModel.js | 277 ++++++++++++++++++++++++++++++++++ 1 file changed, 277 insertions(+) create mode 100644 scripts/developer/sunModel.js diff --git a/scripts/developer/sunModel.js b/scripts/developer/sunModel.js new file mode 100644 index 0000000000..dc0753cd73 --- /dev/null +++ b/scripts/developer/sunModel.js @@ -0,0 +1,277 @@ +// +// sunModel.js +// scripts/developer +// +// Created by Nissim Hadar on 2017/12/27. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +// Code is based on the NOAA model - see https://www.esrl.noaa.gov/gmd/grad/solcalc/ +// +(function() { + // Utility functions for trig. calculations + function toRadians(angle_degs) { + return angle_degs * (Math.PI / 180); + } + function toDegrees(angle_rads) { + return angle_rads * (180.0 / Math.PI); + } + + // Parameters + var latitude_degs = 47.751033; + var longitude_degs = -122.228176; + + // These are used a lot + var latitude = toRadians(latitude_degs); + var longitude = toRadians(longitude_degs); + + // Code to check if Daylight Savings is active + Date.prototype.stdTimezoneOffset = function() { + var fy = this.getFullYear(); + if (!Date.prototype.stdTimezoneOffset.cache.hasOwnProperty(fy)) { + var maxOffset = new Date(fy, 0, 1).getTimezoneOffset(); + var monthsTestOrder = [6, 7, 5, 8, 4, 9, 3, 10, 2, 11, 1]; + + for(var mi = 0;mi < 12; ++mi) { + var offset = new Date(fy, monthsTestOrder[mi], 1).getTimezoneOffset(); + if (offset != maxOffset) { + maxOffset = Math.max(maxOffset, offset); + break; + } + } + Date.prototype.stdTimezoneOffset.cache[fy] = maxOffset; + } + return Date.prototype.stdTimezoneOffset.cache[fy]; + }; + + // Cache the result for per year stdTimezoneOffset so that you don't need to recalculate it when testing multiple dates in + // the same year. + Date.prototype.stdTimezoneOffset.cache = {}; + + Date.prototype.isDST = function() { + return this.getTimezoneOffset() < this.stdTimezoneOffset(); + }; + + // The Julian Date is the number of days (fractional) that have elapsed since Jan 1st, 4713 BC + function getJulianDate(dateTime) { + var month = dateTime.getMonth() + 1; + var day = dateTime.getDate() + 1; + var year = dateTime.getFullYear(); + + if (month <= 2) { + year -= 1; + month += 12; + } + + var A = Math.floor(year / 100); + var B = 2 - A + Math.floor(A / 4); + return Math.floor(365.25 * (year + 4716)) + Math.floor(30.6001 * (month + 1)) + day + B - 1524.5; + } + + function getMinutes(dateTime) { + var hours = dateTime.getHours(); + var minutes = dateTime.getMinutes(); + var seconds = dateTime.getSeconds(); + + if (Date.prototype.isDST()) { + hour -= 1; + } + + return hours * 60 + minutes + seconds / 60.0; + } + + function calcGeomMeanAnomalySun(t) { + var M = 357.52911 + t * (35999.05029 - 0.0001537 * t); + return M; // in degrees + } + + function calcSunEqOfCenter(t) { + var m = calcGeomMeanAnomalySun(t); + var mrad = toRadians(m); + var sinm = Math.sin(mrad); + var sin2m = Math.sin(mrad + mrad); + var sin3m = Math.sin(mrad + mrad + mrad); + var C = sinm * (1.914602 - t * (0.004817 + 0.000014 * t)) + sin2m * (0.019993 - 0.000101 * t) + sin3m * 0.000289; + return C; // in degrees + } + + function calcGeomMeanLongSun(t) { + var L0 = 280.46646 + t * (36000.76983 + t*(0.0003032)) + while(L0 > 360.0) { + L0 -= 360.0 + } + while(L0 < 0.0) { + L0 += 360.0 + } + return L0 // in degrees + } + + function calcSunTrueLong(t) { + var l0 = calcGeomMeanLongSun(t); + var c = calcSunEqOfCenter(t); + var O = l0 + c; + return O; // in degrees + } + + function calcSunApparentLong(t) { + var o = calcSunTrueLong(t); + var omega = 125.04 - 1934.136 * t; + var lambda = o - 0.00569 - 0.00478 * Math.sin(toRadians(omega)); + return lambda; // in degrees + } + + function calcMeanObliquityOfEcliptic(t) { + var seconds = 21.448 - t * (46.8150 + t * (0.00059 - t * (0.001813))); + var e0 = 23.0 + (26.0 + (seconds / 60.0)) / 60.0; + return e0; // in degrees + } + + function calcObliquityCorrection(t) { + var e0 = calcMeanObliquityOfEcliptic(t); + var omega = 125.04 - 1934.136 * t; + var e = e0 + 0.00256 * Math.cos(toRadians(omega)); + return e; // in degrees + } + + function calcSunDeclination(t) { + var e = calcObliquityCorrection(t); + var lambda = calcSunApparentLong(t); + + var sint = Math.sin(toRadians(e)) * Math.sin(toRadians(lambda)); + var theta = toDegrees(Math.asin(sint)); + return theta; // in degrees + } + + function calcEccentricityEarthOrbit(t) { + var e = 0.016708634 - t * (0.000042037 + 0.0000001267 * t); + return e; // unitless + } + + function calcEquationOfTime(t) { + var epsilon = calcObliquityCorrection(t); + var l0 = calcGeomMeanLongSun(t); + var e = calcEccentricityEarthOrbit(t); + var m = calcGeomMeanAnomalySun(t); + + var y = Math.tan(toRadians(epsilon) / 2.0); + y *= y; + + var sin2l0 = Math.sin(2.0 * toRadians(l0)); + var sinm = Math.sin(toRadians(m)); + var cos2l0 = Math.cos(2.0 * toRadians(l0)); + var sin4l0 = Math.sin(4.0 * toRadians(l0)); + var sin2m = Math.sin(2.0 * toRadians(m)); + + var Etime = y * sin2l0 - 2.0 * e * sinm + 4.0 * e * y * sinm * cos2l0 - 0.5 * y * y * sin4l0 - 1.25 * e * e * sin2m; + return toDegrees(Etime) * 4.0; // in minutes of time + } + + function calcSunTrueAnomaly(t) { + var m = calcGeomMeanAnomalySun(t); + var c = calcSunEqOfCenter(t); + var v = m + c; + return v; // in degrees + } + + function calcSunRadVector(t) { + var v = calcSunTrueAnomaly(t); + var e = calcEccentricityEarthOrbit(t); + var R = (1.000001018 * (1 - e * e)) / (1 + e * Math.cos(toRadians(v))); + return R; // in AUs + } + + var COMPUTATION_CYCLE = 5000; // Run every 5 seconds + this.preload = function(entityID) { // You don't have the entityID before the preload + Script.setInterval( + function() { + var dateTime = new Date(); + + var julianDay = getJulianDate(dateTime); + var localTimeMinutes = getMinutes(dateTime); + var timeZone = -dateTime.getTimezoneOffset() / 60; + var totalTime = julianDay + localTimeMinutes/1440.0 - timeZone / 24.0; + var julianCentralTime = (julianDay - 2451545.0)/36525.0; + var eqTime = calcEquationOfTime(julianCentralTime) + var theta_rads = toRadians(calcSunDeclination(julianCentralTime)); + var solarTimeFix = eqTime + 4.0 * longitude_degs - 60.0 * timeZone; + var earthRadVec = calcSunRadVector(julianCentralTime); + + var trueSolarTime = localTimeMinutes + solarTimeFix; + while (trueSolarTime > 1440) { + trueSolarTime -= 1440; + } + + var hourAngle = trueSolarTime / 4.0 - 180.0; + if (hourAngle < -180.0) { + hourAngle += 360.0; + } + var hourAngleRadians = toRadians(hourAngle); + + var csz = Math.sin(latitude) * Math.sin(theta_rads) + + Math.cos(latitude) * Math.cos(theta_rads) * Math.cos(hourAngleRadians); + csz = Math.min(1.0, Math.max(-1.0, csz)); + + var zenith = toDegrees(Math.acos(csz)); + var azDenom = ( Math.cos(latitude) * Math.sin(toRadians(zenith))); + if (Math.abs(azDenom) > 0.001) { + azRad = (( Math.sin(latitude) * Math.cos(toRadians(zenith)) ) - Math.sin(theta_rads)) / azDenom; + if (Math.abs(azRad) > 1.0) { + if (azRad < 0.0) { + azRad = -1.0; + } else { + azRad = 1.0; + } + } + var solarAzimuth_degs = 180.0 - toDegrees(Math.acos(azRad)) + if (hourAngle > 0.0) { + solarAzimuth_degs = -solarAzimuth_degs; + } + } else { + if (latitude_degs > 0.0) { + solarAzimuth_degs = 180.0; + } else { + solarAzimuth_degs = 0.0; + } + } + if (solarAzimuth_degs < 0.0) { + solarAzimuth_degs += 360.0; + } + + // Atmospheric Refraction correction + var exoatmElevation = 90.0 - zenith; + if (exoatmElevation > 85.0) { + var refractionCorrection = 0.0; + } else { + var te = Math.tan(toRadians(exoatmElevation)); + if (exoatmElevation > 5.0) { + var refractionCorrection = 58.1 / te - 0.07 / (te * te * te) + 0.000086 / (te * te * te * te * te); + } else if (exoatmElevation > -0.575) { + var refractionCorrection = + 1735.0 + exoatmElevation * + (-518.2 + exoatmElevation * (103.4 + exoatmElevation * (-12.79 + exoatmElevation * 0.711))); + } else { + var refractionCorrection = -20.774 / te; + } + refractionCorrection = refractionCorrection / 3600.0; + } + + var solarZenith = zenith - refractionCorrection; + var solarAltitude_degs = 90.0 - solarZenith; // aka solar elevation + + // Convert to XYZ + var solarAltitude = toRadians(solarAltitude_degs); + var solarAzimuth = toRadians(solarAzimuth_degs); + + var xPos = Math.cos(solarAltitude) * Math.sin(solarAzimuth); + var zPos = Math.cos(solarAltitude) * Math.cos(solarAzimuth); + var yPos = -Math.sin(solarAltitude); + + Entities.editEntity(entityID, { keyLight : {direction: { x: xPos, y: yPos, z: zPos }}}); + }, + + COMPUTATION_CYCLE + ); + }; +}); \ No newline at end of file From 03cf7710d0fbf011dba7cefbd0ee1e98a0deb3d2 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Thu, 28 Dec 2017 09:34:55 -0800 Subject: [PATCH 22/46] Ambient light inheritance --- .../src/RenderableZoneEntityItem.cpp | 27 ++++++++++++------- .../src/RenderableZoneEntityItem.h | 3 ++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index e6af7bcdd0..6e6b87a6e5 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -165,14 +165,14 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { if (_visible) { // Finally, push the light visible in the frame - if (_keyLightMode == COMPONENT_MODE_DISABLED && sunOnIndex == NO_STORED_VALUE) { + if (_keyLightMode == COMPONENT_MODE_DISABLED && _sunOnIndex == NO_STORED_VALUE) { // Just turned off, store previous value before changing - sunOnIndex = _sunIndex; + _sunOnIndex = _sunIndex; _sunIndex = _stage->getSunOffLight(); - } else if (_keyLightMode == COMPONENT_MODE_ENABLED && sunOnIndex != NO_STORED_VALUE) { + } else if (_keyLightMode == COMPONENT_MODE_ENABLED && _sunOnIndex != NO_STORED_VALUE) { // Just turned on, restore previous value before clearing stored value - _sunIndex = sunOnIndex; - sunOnIndex = NO_STORED_VALUE; + _sunIndex = _sunOnIndex; + _sunOnIndex = NO_STORED_VALUE; } if (_keyLightMode != COMPONENT_MODE_INHERIT) { @@ -180,10 +180,19 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { } // The ambient light only if it has a valid texture to render with - if (_validAmbientTexture || _validSkyboxTexture) { - if (_ambientLightMode != COMPONENT_MODE_INHERIT) { - _stage->_currentFrame.pushAmbientLight(_ambientIndex); - } + if (_ambientLightMode == COMPONENT_MODE_DISABLED && _ambientOnIndex == NO_STORED_VALUE) { + // Just turned off, store previous value before changing + _ambientOnIndex = _ambientIndex; + _ambientIndex = _stage->getAmbientOffLight(); + } + else if (_ambientLightMode == COMPONENT_MODE_ENABLED && _ambientOnIndex != NO_STORED_VALUE) { + // Just turned on, restore previous value before clearing stored value + _ambientIndex = _ambientOnIndex; + _ambientOnIndex = NO_STORED_VALUE; + } + + if (_ambientLightMode != COMPONENT_MODE_INHERIT && (_validAmbientTexture || _validSkyboxTexture)) { + _stage->_currentFrame.pushAmbientLight(_ambientIndex); } // The background only if the mode is not inherit diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index f7473f1898..f753d39b97 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -96,7 +96,8 @@ private: indexed_container::Index _ambientIndex{ LightStage::INVALID_INDEX }; const int NO_STORED_VALUE { -1 }; - indexed_container::Index sunOnIndex { NO_STORED_VALUE }; + indexed_container::Index _sunOnIndex { NO_STORED_VALUE }; + indexed_container::Index _ambientOnIndex { NO_STORED_VALUE }; BackgroundStagePointer _backgroundStage; BackgroundStage::Index _backgroundIndex{ BackgroundStage::INVALID_INDEX }; From 8bb4d1431cd8d32cd7604fd8e07228b62b8f6360 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Thu, 28 Dec 2017 09:35:40 -0800 Subject: [PATCH 23/46] WIP - copy skylight URL to ambient URL. --- scripts/system/edit.js | 6 +- scripts/system/html/entityProperties.html | 72 ++++++++++++---------- scripts/system/html/js/entityProperties.js | 9 +++ 3 files changed, 53 insertions(+), 34 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index e28f877d85..ae3f88bd4e 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -2044,9 +2044,9 @@ var PropertiesTool = function (opts) { // If any of the natural dimensions are not 0, resize if (properties.type === "Model" && naturalDimensions.x === 0 && naturalDimensions.y === 0 && - naturalDimensions.z === 0) { + naturalDimensions.z === 0) { Window.notifyEditError("Cannot reset entity to its natural dimensions: Model URL" + - " is invalid or the model has not yet been loaded."); + " is invalid or the model has not yet been loaded."); } else { Entities.editEntity(selectionManager.selections[i], { dimensions: properties.naturalDimensions @@ -2089,6 +2089,8 @@ var PropertiesTool = function (opts) { Entities.reloadServerScripts(selectionManager.selections[i]); } } + } else if (data.action === "copySkyboxURLToAmbientURL") { + Window.notifyEditError("I DON'T KNOW HOW :("); } } else if (data.type === "propertiesPageReady") { updateSelections(true); diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index c914ec34d4..40ed8fe18f 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -536,6 +536,46 @@
+
+ + Background + + +
+
+ + Skybox + +
+
+ Skybox color +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + + +
+
@@ -668,39 +708,7 @@ -
- - Background - - -
-
- - Skybox - -
-
- Skybox color -
-
-
-
-
-
-
- - -
-
- -
TextM diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index 5d788726f6..390aeae96d 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -654,6 +654,8 @@ function loaded() { var elZoneKeyLightDirectionY = document.getElementById("property-zone-key-light-direction-y"); // Ambient light + var elCopySkyboxURLToAmbientURL = document.getElementById("copy-skybox-url-to-ambient-url"); + var elZoneAmbientLightModeInherit = document.getElementById("property-zone-ambient-light-mode-inherit"); var elZoneAmbientLightModeDisabled = document.getElementById("property-zone-ambient-light-mode-disabled"); var elZoneAmbientLightModeEnabled = document.getElementById("property-zone-ambient-light-mode-enabled"); @@ -1467,6 +1469,13 @@ function loaded() { elZoneKeyLightDirectionY.addEventListener('change', zoneKeyLightDirectionChangeFunction); // Ambient light + elCopySkyboxURLToAmbientURL.addEventListener("click", function () { + EventBridge.emitWebEvent(JSON.stringify({ + type: "action", + action: "copySkyboxURLToAmbientURL" + })); + }); + var ambientLightModeChanged = createZoneComponentModeChangedFunction('ambientLightMode', elZoneAmbientLightModeInherit, elZoneAmbientLightModeDisabled, elZoneAmbientLightModeEnabled); From 9636a0b4500b732bb67eb1ff16cc214c60d3e8d8 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Thu, 28 Dec 2017 09:35:58 -0800 Subject: [PATCH 24/46] No idea... --- interface/resources/qml/js/Utils.jsc | Bin 6596 -> 6516 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/interface/resources/qml/js/Utils.jsc b/interface/resources/qml/js/Utils.jsc index ab20e996b9469915ac6a89901da175143e6b5024..dec1adb6f865f057bee2a149c2f75b38999f104d 100644 GIT binary patch delta 571 zcmX?N{KZJ8u*@VmC9xz?n1O+TiIbI~=hd;21V#o19aaVgHoo}aeohVMaEtRteXlX} zPSnv5oWKA9OJMZGRBf>h3=9k$j0_AQjXM|_7&w?fvKyC4F*0pon|z4Tjp>2#W-cZp zCRHm228J|-OokkWR0b;seK2$Zv)man8A=#D7)lwECdaY_Z{EVPlbO+Aa~{WiMn;3p zeq1)pX&Rp0Odj1137(xUDl>e$#eBPiph6iSp$RBL1t6gg6rl=`Py@11LjwZ?gJ)-p zO2z;G|Dh6-Kk!QUK+J6b`4%Ldfsh8fpVC&A*2iV;C72bXXY}mb_f{tI)LMb*EnX9J{G= zWhd%r2u=a1V_;xd0i!3TYBMn~Oze}}xIuuCiJN`$Ax1YQ1Ch;KOh!zK77PpwX$+YR zISi=`Rt)-J=nQ5#GvqU*Fr-dSWC>+b{ttoq>=ByP;tQR3ZUgVgXbl0wUpf+{t2c2;V_YW>%0zE-Eu7@8|bm+Qc$> zpP=$&9Ra?{EBJ*O|4!b+@6DtD6XfCh#4m8mV+SNeKiE%J5D=>uc>IY!?xDwySu;W4 zqkWnOf8L2Se!YkMZQ2YB3^3Ib9KaHv_~UNEgg!vje&Ua~_;Tt0|NqlG`0H-?7`^~G zXTc|afln{_kqls902%PXw;SwsDUeL_8--ny%Q>VsPY@_zWVD#fD3mA;4F`}LLFRzM z9^}`}l|l)OlOG5-Ggq4 From 64644fc980e57a11aabaadfacde89e3dbeb4ebc2 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Thu, 28 Dec 2017 14:31:59 -0800 Subject: [PATCH 25/46] WIP - skybox inheritance --- .../src/RenderableZoneEntityItem.cpp | 4 ++ .../src/RenderableZoneEntityItem.h | 5 +++ .../entities/src/EntityItemProperties.cpp | 42 ++++++++++++++++++- libraries/entities/src/EntityItemProperties.h | 5 +++ libraries/entities/src/EntityPropertyFlags.h | 1 + libraries/entities/src/ZoneEntityItem.cpp | 17 ++++++++ libraries/entities/src/ZoneEntityItem.h | 4 ++ scripts/system/html/entityProperties.html | 11 +++-- scripts/system/html/js/entityProperties.js | 35 ++++++++++++---- 9 files changed, 112 insertions(+), 12 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 6e6b87a6e5..c883bd631c 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -520,6 +520,10 @@ void ZoneEntityRenderer::setAmbientLightMode(ComponentMode mode) { _ambientLightMode = mode; } +void ZoneEntityRenderer::setSkyboxMode(ComponentMode mode) { + _skyboxMode = mode; +} + void ZoneEntityRenderer::setSkyboxColor(const glm::vec3& color) { editSkybox()->setColor(color); } diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index f753d39b97..f72aadf7b9 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -55,9 +55,12 @@ private: void setAmbientURL(const QString& ambientUrl); void setSkyboxURL(const QString& skyboxUrl); void setBackgroundMode(BackgroundMode mode); + void setHazeMode(ComponentMode mode); void setKeyLightMode(ComponentMode mode); void setAmbientLightMode(ComponentMode mode); + void setSkyboxMode(ComponentMode mode); + void setSkyboxColor(const glm::vec3& color); void setProceduralUserData(const QString& userData); @@ -87,9 +90,11 @@ private: const model::HazePointer _haze{ std::make_shared() }; BackgroundMode _backgroundMode{ BACKGROUND_MODE_INHERIT }; + ComponentMode _hazeMode { COMPONENT_MODE_INHERIT }; ComponentMode _keyLightMode { COMPONENT_MODE_INHERIT }; ComponentMode _ambientLightMode { COMPONENT_MODE_INHERIT }; + ComponentMode _skyboxMode { COMPONENT_MODE_INHERIT }; indexed_container::Index _sunIndex{ LightStage::INVALID_INDEX }; indexed_container::Index _shadowIndex{ LightStage::INVALID_INDEX }; diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index d13569e260..f5fce2929b 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -302,6 +302,35 @@ void EntityItemProperties::setAmbientLightModeFromString(const QString& ambientL } } +QString EntityItemProperties::getSkyboxModeAsString() const { + // return "enabled" if _skyboxMode is not valid + if (_skyboxMode < COMPONENT_MODE_ITEM_COUNT) { + return COMPONENT_MODES[_skyboxMode].second; + } else { + return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; + } +} + +QString EntityItemProperties::getSkyboxModeString(uint32_t mode) { + // return "enabled" if mode is not valid + if (mode < COMPONENT_MODE_ITEM_COUNT) { + return COMPONENT_MODES[mode].second; + } else { + return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; + } +} + +void EntityItemProperties::setSkyboxModeFromString(const QString& skyboxMode) { + auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { + return (pair.second == skyboxMode); + }); + + if (result != COMPONENT_MODES.end()) { + _skyboxMode = result->first; + _skyboxModeChanged = true; + } +} + EntityPropertyFlags EntityItemProperties::getChangedProperties() const { EntityPropertyFlags changedProperties; @@ -392,6 +421,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_HAZE_MODE, hazeMode); CHECK_PROPERTY_CHANGE(PROP_KEY_LIGHT_MODE, keyLightMode); CHECK_PROPERTY_CHANGE(PROP_AMBIENT_LIGHT_MODE, ambientLightMode); + CHECK_PROPERTY_CHANGE(PROP_SKYBOX_MODE, skyboxMode); CHECK_PROPERTY_CHANGE(PROP_SOURCE_URL, sourceUrl); CHECK_PROPERTY_CHANGE(PROP_VOXEL_VOLUME_SIZE, voxelVolumeSize); @@ -631,6 +661,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_KEY_LIGHT_MODE, keyLightMode, getKeyLightModeAsString()); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_AMBIENT_LIGHT_MODE, ambientLightMode, getAmbientLightModeAsString()); + COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_SKYBOX_MODE, skyboxMode, getSkyboxModeAsString()); } // Web only @@ -820,6 +851,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(hazeMode, HazeMode); COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(keyLightMode, KeyLightMode); COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(ambientLightMode, AmbientLightMode); + COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(skyboxMode, SkyboxMode); COPY_PROPERTY_FROM_QSCRIPTVALUE(sourceUrl, QString, setSourceUrl); COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelVolumeSize, glmVec3, setVoxelVolumeSize); @@ -980,6 +1012,7 @@ void EntityItemProperties::merge(const EntityItemProperties& other) { COPY_PROPERTY_IF_CHANGED(hazeMode); COPY_PROPERTY_IF_CHANGED(keyLightMode); COPY_PROPERTY_IF_CHANGED(ambientLightMode); + COPY_PROPERTY_IF_CHANGED(skyboxMode); COPY_PROPERTY_IF_CHANGED(sourceUrl); COPY_PROPERTY_IF_CHANGED(voxelVolumeSize); @@ -1255,6 +1288,7 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_PROPERTY_TO_MAP(PROP_KEY_LIGHT_MODE, KeyLightMode, keyLightMode, uint32_t); ADD_PROPERTY_TO_MAP(PROP_AMBIENT_LIGHT_MODE, AmbientLightMode, ambientLightMode, uint32_t); + ADD_PROPERTY_TO_MAP(PROP_SKYBOX_MODE, SkyboxMode, skyboxMode, uint32_t); ADD_PROPERTY_TO_MAP(PROP_DPI, DPI, dpi, uint16_t); @@ -1506,6 +1540,7 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy APPEND_ENTITY_PROPERTY(PROP_KEY_LIGHT_MODE, (uint32_t)properties.getKeyLightMode()); APPEND_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_MODE, (uint32_t)properties.getAmbientLightMode()); + APPEND_ENTITY_PROPERTY(PROP_SKYBOX_MODE, (uint32_t)properties.getSkyboxMode()); } if (properties.getType() == EntityTypes::PolyVox) { @@ -1860,7 +1895,8 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_KEY_LIGHT_MODE, uint32_t, setKeyLightMode); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_AMBIENT_LIGHT_MODE, uint32_t, setAmbientLightMode); - } + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SKYBOX_MODE, uint32_t, setSkyboxMode); + } if (properties.getType() == EntityTypes::PolyVox) { READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize); @@ -2449,6 +2485,10 @@ QList EntityItemProperties::listChangedProperties() { out += "ambientLightMode"; } + if (skyboxModeChanged()) { + out += "skyboxMode"; + } + if (voxelVolumeSizeChanged()) { out += "voxelVolumeSize"; } diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 3de76e3777..336731c1d4 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -183,6 +183,7 @@ public: DEFINE_PROPERTY_REF_ENUM(PROP_HAZE_MODE, HazeMode, hazeMode, uint32_t, (uint32_t)COMPONENT_MODE_INHERIT); DEFINE_PROPERTY_REF_ENUM(PROP_KEY_LIGHT_MODE, KeyLightMode, keyLightMode, uint32_t, (uint32_t)COMPONENT_MODE_INHERIT); DEFINE_PROPERTY_REF_ENUM(PROP_AMBIENT_LIGHT_MODE, AmbientLightMode, ambientLightMode, uint32_t, (uint32_t)COMPONENT_MODE_INHERIT); + DEFINE_PROPERTY_REF_ENUM(PROP_SKYBOX_MODE, SkyboxMode, skyboxMode, uint32_t, (uint32_t)COMPONENT_MODE_INHERIT); DEFINE_PROPERTY_GROUP(Skybox, skybox, SkyboxPropertyGroup); DEFINE_PROPERTY_GROUP(Haze, haze, HazePropertyGroup); @@ -253,6 +254,7 @@ public: static QString getHazeModeString(uint32_t mode); static QString getKeyLightModeString(uint32_t mode); static QString getAmbientLightModeString(uint32_t mode); + static QString getSkyboxModeString(uint32_t mode); public: float getMaxDimension() const { return glm::compMax(_dimensions); } @@ -481,9 +483,12 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { DEBUG_PROPERTY_IF_CHANGED(debug, properties, StaticCertificateVersion, staticCertificateVersion, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, BackgroundMode, backgroundMode, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, HazeMode, hazeMode, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, KeyLightMode, keyLightMode, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, AmbientLightMode, ambientLightMode, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, SkyboxMode, skyboxMode, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelVolumeSize, voxelVolumeSize, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelData, voxelData, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelSurfaceStyle, voxelSurfaceStyle, ""); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 8317bad05f..d0cdf2d97c 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -222,6 +222,7 @@ enum EntityPropertyList { PROP_KEY_LIGHT_MODE, PROP_AMBIENT_LIGHT_MODE, + PROP_SKYBOX_MODE, //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties to end of list just ABOVE this line diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp index bab7d8c7b7..96dcc1bc32 100644 --- a/libraries/entities/src/ZoneEntityItem.cpp +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -78,6 +78,7 @@ EntityItemProperties ZoneEntityItem::getProperties(EntityPropertyFlags desiredPr COPY_ENTITY_PROPERTY_TO_PROPERTIES(keyLightMode, getKeyLightMode); COPY_ENTITY_PROPERTY_TO_PROPERTIES(ambientLightMode, getAmbientLightMode); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(skyboxMode, getSkyboxMode); return properties; } @@ -131,6 +132,7 @@ bool ZoneEntityItem::setSubClassProperties(const EntityItemProperties& propertie SET_ENTITY_PROPERTY_FROM_PROPERTIES(keyLightMode, setKeyLightMode); SET_ENTITY_PROPERTY_FROM_PROPERTIES(ambientLightMode, setAmbientLightMode); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(skyboxMode, setSkyboxMode); somethingChanged = somethingChanged || _keyLightPropertiesChanged || _ambientLightPropertiesChanged || _stagePropertiesChanged || _skyboxPropertiesChanged || _hazePropertiesChanged; @@ -199,6 +201,7 @@ int ZoneEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_KEY_LIGHT_MODE, uint32_t, setKeyLightMode); READ_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_MODE, uint32_t, setAmbientLightMode); + READ_ENTITY_PROPERTY(PROP_SKYBOX_MODE, uint32_t, setSkyboxMode); return bytesRead; } @@ -235,6 +238,7 @@ EntityPropertyFlags ZoneEntityItem::getEntityProperties(EncodeBitstreamParams& p requestedProperties += PROP_KEY_LIGHT_MODE; requestedProperties += PROP_AMBIENT_LIGHT_MODE; + requestedProperties += PROP_SKYBOX_MODE; return requestedProperties; } @@ -276,6 +280,7 @@ void ZoneEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits APPEND_ENTITY_PROPERTY(PROP_KEY_LIGHT_MODE, (uint32_t)getKeyLightMode()); APPEND_ENTITY_PROPERTY(PROP_AMBIENT_LIGHT_MODE, (uint32_t)getAmbientLightMode()); + APPEND_ENTITY_PROPERTY(PROP_SKYBOX_MODE, (uint32_t)getSkyboxMode()); } void ZoneEntityItem::debugDump() const { @@ -288,6 +293,7 @@ void ZoneEntityItem::debugDump() const { qCDebug(entities) << " _hazeMode:" << EntityItemProperties::getHazeModeString(_hazeMode); qCDebug(entities) << " _keyLightMode:" << EntityItemProperties::getKeyLightModeString(_keyLightMode); qCDebug(entities) << " _ambientLightMode:" << EntityItemProperties::getAmbientLightModeString(_ambientLightMode); + qCDebug(entities) << " _skyboxMode:" << EntityItemProperties::getSkyboxModeString(_skyboxMode); _keyLightProperties.debugDump(); _ambientLightProperties.debugDump(); @@ -396,3 +402,14 @@ void ZoneEntityItem::setAmbientLightMode(const uint32_t value) { uint32_t ZoneEntityItem::getAmbientLightMode() const { return _ambientLightMode; } + +void ZoneEntityItem::setSkyboxMode(const uint32_t value) { + if (value < COMPONENT_MODE_ITEM_COUNT) { + _skyboxMode = value; + _skyboxPropertiesChanged = true; + } +} + +uint32_t ZoneEntityItem::getSkyboxMode() const { + return _skyboxMode; +} diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index 53c011b5ad..bdc5821da6 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -81,6 +81,9 @@ public: void setAmbientLightMode(uint32_t value); uint32_t getAmbientLightMode() const; + void setSkyboxMode(uint32_t value); + uint32_t getSkyboxMode() const; + SkyboxPropertyGroup getSkyboxProperties() const { return resultWithReadLock([&] { return _skyboxProperties; }); } const HazePropertyGroup& getHazeProperties() const { return _hazeProperties; } @@ -132,6 +135,7 @@ protected: uint32_t _hazeMode { COMPONENT_MODE_INHERIT }; uint32_t _keyLightMode { COMPONENT_MODE_INHERIT }; uint32_t _ambientLightMode { COMPONENT_MODE_INHERIT }; + uint32_t _skyboxMode { COMPONENT_MODE_INHERIT }; SkyboxPropertyGroup _skyboxProperties; HazePropertyGroup _hazeProperties; diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index 40ed8fe18f..85beab4098 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -540,6 +540,11 @@ Background +
+ Inherit + Off + On +
-
+
@@ -569,7 +569,7 @@
-
+
@@ -587,7 +587,7 @@
- + Haze diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index da9be64ef0..98e67cde05 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -1104,8 +1104,15 @@ function loaded() { elZoneFilterURL.value = properties.filterURL; // Show/hide sections as required - showElements(document.getElementsByClassName('skybox-section'), + showElements(document.getElementsByClassName('skybox-section'), elZoneSkyboxModeEnabled.checked); + showElements(document.getElementsByClassName('keylight-section'), + elZoneKeyLightModeEnabled.checked); + showElements(document.getElementsByClassName('ambient-section'), + elZoneAmbientLightModeEnabled.checked); + showElements(document.getElementsByClassName('haze-section'), + elZoneHazeModeEnabled.checked); + } else if (properties.type === "PolyVox") { elVoxelVolumeSizeX.value = properties.voxelVolumeSize.x.toFixed(2); elVoxelVolumeSizeY.value = properties.voxelVolumeSize.y.toFixed(2); From 87e896ab20a90a1d10c81ced65527364628ca5fe Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 29 Dec 2017 15:13:46 -0800 Subject: [PATCH 29/46] Zone inheritance ready for testing. --- .../entities-renderer/src/RenderableZoneEntityItem.cpp | 8 +++----- scripts/system/edit.js | 2 -- scripts/system/html/entityProperties.html | 3 +++ scripts/system/html/js/entityProperties.js | 7 +++---- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 8bf64db9b1..12e6d921b7 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -184,8 +184,7 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { // Just turned off, store previous value before changing _skyboxOnIndex = _backgroundIndex; _backgroundIndex = _stage->getSunOffLight(); - } - else if (_skyboxMode == COMPONENT_MODE_ENABLED && _skyboxOnIndex != NO_STORED_VALUE) { + } else if (_skyboxMode == COMPONENT_MODE_ENABLED && _skyboxOnIndex != NO_STORED_VALUE) { // Just turned on, restore previous value before clearing stored value _backgroundIndex = _skyboxOnIndex; _skyboxOnIndex = NO_STORED_VALUE; @@ -200,14 +199,13 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { // Just turned off, store previous value before changing _ambientOnIndex = _ambientIndex; _ambientIndex = _stage->getAmbientOffLight(); - } - else if (_ambientLightMode == COMPONENT_MODE_ENABLED && _ambientOnIndex != NO_STORED_VALUE) { + } else if (_ambientLightMode == COMPONENT_MODE_ENABLED && _ambientOnIndex != NO_STORED_VALUE) { // Just turned on, restore previous value before clearing stored value _ambientIndex = _ambientOnIndex; _ambientOnIndex = NO_STORED_VALUE; } - if (_ambientLightMode != COMPONENT_MODE_INHERIT && (_validAmbientTexture || _validSkyboxTexture)) { + if (_ambientLightMode != COMPONENT_MODE_INHERIT && (_validAmbientTexture)) { _stage->_currentFrame.pushAmbientLight(_ambientIndex); } diff --git a/scripts/system/edit.js b/scripts/system/edit.js index ae3f88bd4e..44366aa61c 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -2089,8 +2089,6 @@ var PropertiesTool = function (opts) { Entities.reloadServerScripts(selectionManager.selections[i]); } } - } else if (data.action === "copySkyboxURLToAmbientURL") { - Window.notifyEditError("I DON'T KNOW HOW :("); } } else if (data.type === "propertiesPageReady") { updateSelections(true); diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index ee2301b219..38d6a99f0c 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -564,8 +564,11 @@
+
+
+
diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index 98e67cde05..2e0af2d23d 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -1492,10 +1492,9 @@ function loaded() { // Ambient light elCopySkyboxURLToAmbientURL.addEventListener("click", function () { - EventBridge.emitWebEvent(JSON.stringify({ - type: "action", - action: "copySkyboxURLToAmbientURL" - })); + document.getElementById("property-zone-key-ambient-url").value = properties.skybox.url; + properties.ambientLight.ambientURL = properties.skybox.url; + updateProperties(properties); }); var ambientLightModeChanged = createZoneComponentModeChangedFunction('ambientLightMode', From b6bbf1abe118ef61eb7c31e5ffd17320d0b33244 Mon Sep 17 00:00:00 2001 From: "nissim.hadar" Date: Fri, 29 Dec 2017 23:47:42 -0800 Subject: [PATCH 30/46] Added sun intensity modulation as a function of altitude. --- scripts/developer/sunModel.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/scripts/developer/sunModel.js b/scripts/developer/sunModel.js index dc0753cd73..2343e3da7f 100644 --- a/scripts/developer/sunModel.js +++ b/scripts/developer/sunModel.js @@ -8,7 +8,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// Code is based on the NOAA model - see https://www.esrl.noaa.gov/gmd/grad/solcalc/ +// Sun angle is based on the NOAA model - see https://www.esrl.noaa.gov/gmd/grad/solcalc/ // (function() { // Utility functions for trig. calculations @@ -213,10 +213,10 @@ Math.cos(latitude) * Math.cos(theta_rads) * Math.cos(hourAngleRadians); csz = Math.min(1.0, Math.max(-1.0, csz)); - var zenith = toDegrees(Math.acos(csz)); - var azDenom = ( Math.cos(latitude) * Math.sin(toRadians(zenith))); + var zenith_degs = toDegrees(Math.acos(csz)); + var azDenom = ( Math.cos(latitude) * Math.sin(toRadians(zenith_degs))); if (Math.abs(azDenom) > 0.001) { - azRad = (( Math.sin(latitude) * Math.cos(toRadians(zenith)) ) - Math.sin(theta_rads)) / azDenom; + azRad = (( Math.sin(latitude) * Math.cos(toRadians(zenith_degs)) ) - Math.sin(theta_rads)) / azDenom; if (Math.abs(azRad) > 1.0) { if (azRad < 0.0) { azRad = -1.0; @@ -240,7 +240,7 @@ } // Atmospheric Refraction correction - var exoatmElevation = 90.0 - zenith; + var exoatmElevation = 90.0 - zenith_degs; if (exoatmElevation > 85.0) { var refractionCorrection = 0.0; } else { @@ -257,7 +257,7 @@ refractionCorrection = refractionCorrection / 3600.0; } - var solarZenith = zenith - refractionCorrection; + var solarZenith = zenith_degs - refractionCorrection; var solarAltitude_degs = 90.0 - solarZenith; // aka solar elevation // Convert to XYZ @@ -268,7 +268,24 @@ var zPos = Math.cos(solarAltitude) * Math.cos(solarAzimuth); var yPos = -Math.sin(solarAltitude); - Entities.editEntity(entityID, { keyLight : {direction: { x: xPos, y: yPos, z: zPos }}}); + // Compute intensity, modelling the atmosphere as a spherical shell + // The optical air mass ratio at zenith is 1.0, and around 38.0 at the horizon + // The ratio is limited between 1 and 38 + var EARTH_RADIUS_KM = 6371.0; + var ATMOSPHERE_THICKNESS_KM = 9.0; + var r = EARTH_RADIUS_KM / ATMOSPHERE_THICKNESS_KM; + + var opticalAirMassRatio = Math.sqrt(r * r * csz * csz + 2 * r + 1) - r * csz; + opticalAirMassRatio = Math.min(38.0, Math.max(1.0, opticalAirMassRatio)); + + Entities.editEntity( + entityID, { + keyLight : { + direction: { x: xPos, y: yPos, z: zPos }, + intensity: 1.0 / opticalAirMassRatio + } + } + ); }, COMPUTATION_CYCLE From b56c7535d22a62db5e79fc76921591968fb3cb11 Mon Sep 17 00:00:00 2001 From: "nissim.hadar" Date: Sat, 30 Dec 2017 12:25:58 -0800 Subject: [PATCH 31/46] Added legacy functionality (for zones that used Background "skybox") --- libraries/entities-renderer/src/RenderableZoneEntityItem.cpp | 5 +++-- libraries/entities/src/EntityItemProperties.cpp | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 672ad1ceec..a6c0b374fa 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -190,7 +190,8 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { _skyboxOnIndex = NO_STORED_VALUE; } - if (_skyboxMode != COMPONENT_MODE_INHERIT) { + // _backgroundMode is kept for legacy purposes + if (_skyboxMode != COMPONENT_MODE_INHERIT || _backgroundMode != BACKGROUND_MODE_INHERIT) { _backgroundStage->_currentFrame.pushBackground(_backgroundIndex); } @@ -205,7 +206,7 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { _ambientOnIndex = NO_STORED_VALUE; } - if (_ambientLightMode != COMPONENT_MODE_INHERIT && (_validAmbientTexture)) { + if (_ambientLightMode != COMPONENT_MODE_INHERIT && _validAmbientTexture) { _stage->_currentFrame.pushAmbientLight(_ambientIndex); } diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 3a38e4acd7..d5a58c9580 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -2130,6 +2130,7 @@ void EntityItemProperties::markAllChanged() { _keyLight.markAllChanged(); _ambientLight.markAllChanged(); + _skybox.markAllChanged(); _backgroundModeChanged = true; _hazeModeChanged = true; From fb59da5fb34842e933dfd1d2d903c6a484031cf5 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Sat, 30 Dec 2017 18:19:00 -0800 Subject: [PATCH 32/46] Reverted to old version of auto-tester. --- tools/auto-tester/CMakeLists.txt | 41 +++-- tools/auto-tester/src/ImageComparer.cpp | 6 +- tools/auto-tester/src/Test.cpp | 176 ++++---------------- tools/auto-tester/src/Test.h | 20 +-- tools/auto-tester/src/common.h | 5 - tools/auto-tester/src/ui/AutoTester.cpp | 8 +- tools/auto-tester/src/ui/AutoTester.h | 6 +- tools/auto-tester/src/ui/AutoTester.ui | 65 ++------ tools/auto-tester/src/ui/MismatchWindow.cpp | 56 +------ tools/auto-tester/src/ui/MismatchWindow.h | 5 - tools/auto-tester/src/ui/MismatchWindow.ui | 103 ++++-------- 11 files changed, 115 insertions(+), 376 deletions(-) diff --git a/tools/auto-tester/CMakeLists.txt b/tools/auto-tester/CMakeLists.txt index fe91c89352..e5f2c1fb97 100644 --- a/tools/auto-tester/CMakeLists.txt +++ b/tools/auto-tester/CMakeLists.txt @@ -1,24 +1,24 @@ -set (TARGET_NAME auto-tester) +set(TARGET_NAME auto-tester) project(${TARGET_NAME}) # Automatically run UIC and MOC. This replaces the older WRAP macros -SET (CMAKE_AUTOUIC ON) -SET (CMAKE_AUTOMOC ON) +SET(CMAKE_AUTOUIC ON) +SET(CMAKE_AUTOMOC ON) -setup_hifi_project (Core Widgets) -link_hifi_libraries () +setup_hifi_project(Core Widgets) +link_hifi_libraries() # FIX: Qt was built with -reduce-relocations if (Qt5_POSITION_INDEPENDENT_CODE) - SET (CMAKE_POSITION_INDEPENDENT_CODE ON) + SET(CMAKE_POSITION_INDEPENDENT_CODE ON) endif() # Qt includes -include_directories (${CMAKE_CURRENT_SOURCE_DIR}) -include_directories (${Qt5Core_INCLUDE_DIRS}) -include_directories (${Qt5Widgets_INCLUDE_DIRS}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${Qt5Core_INCLUDE_DIRS}) +include_directories(${Qt5Widgets_INCLUDE_DIRS}) -set (QT_LIBRARIES Qt5::Core Qt5::Widgets) +set(QT_LIBRARIES Qt5::Core Qt5::Widgets) # Find all sources files file (GLOB_RECURSE SOURCES src/*.cpp) @@ -27,24 +27,21 @@ file (GLOB_RECURSE UIS src/ui/*.ui) if (WIN32) # Do not show Console - set_property (TARGET auto-tester PROPERTY WIN32_EXECUTABLE true) + set_property(TARGET auto-tester PROPERTY WIN32_EXECUTABLE true) endif() -add_executable (PROJECT_NAME ${SOURCES} ${HEADERS} ${UIS}) - -target_zlib() -add_dependency_external_projects (quazip) -find_package (QuaZip REQUIRED) -target_include_directories( ${TARGET_NAME} SYSTEM PUBLIC ${QUAZIP_INCLUDE_DIRS}) -target_link_libraries(${TARGET_NAME} ${QUAZIP_LIBRARIES}) +add_executable(PROJECT_NAME ${SOURCES} ${HEADERS} ${UIS}) -target_link_libraries (PROJECT_NAME ${QT_LIBRARIES}) +target_link_libraries(PROJECT_NAME ${QT_LIBRARIES}) -package_libraries_for_deployment() +# Copy required dll's. +add_custom_command(TARGET auto-tester POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ +) if (WIN32) - add_paths_to_fixup_libs (${QUAZIP_DLL_PATH}) - find_program(WINDEPLOYQT_COMMAND windeployqt PATHS ${QT_DIR}/bin NO_DEFAULT_PATH) if (NOT WINDEPLOYQT_COMMAND) diff --git a/tools/auto-tester/src/ImageComparer.cpp b/tools/auto-tester/src/ImageComparer.cpp index a80978e564..121c98e16e 100644 --- a/tools/auto-tester/src/ImageComparer.cpp +++ b/tools/auto-tester/src/ImageComparer.cpp @@ -8,7 +8,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "ImageComparer.h" -#include "common.h" #include @@ -27,6 +26,11 @@ double ImageComparer::compareImages(QImage resultImage, QImage expectedImage) co const double c1 = pow((K1 * L), 2); const double c2 = pow((K2 * L), 2); + // Coefficients for luminosity calculation + const double R_Y = 0.212655f; + const double G_Y = 0.715158f; + const double B_Y = 0.072187f; + // First go over all full 8x8 blocks // This is done in 3 loops // 1) Read the pixels into a linear array (an optimization) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index 8bad468afa..8cb36fcfca 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -13,9 +13,6 @@ #include #include -#include -#include - Test::Test() { snapshotFilenameFormat = QRegularExpression("hifi-snap-by-.+-on-\\d\\d\\d\\d-\\d\\d-\\d\\d_\\d\\d-\\d\\d-\\d\\d.jpg"); @@ -24,51 +21,10 @@ Test::Test() { mismatchWindow.setModal(true); } -bool Test::createTestResultsFolderPathIfNeeded(QString directory) { - // The test results folder is located in the root of the tests (i.e. for recursive test evaluation) - if (testResultsFolderPath == "") { - testResultsFolderPath = directory + "/" + TEST_RESULTS_FOLDER; - QDir testResultsFolder(testResultsFolderPath); - - if (testResultsFolder.exists()) { - testResultsFolder.removeRecursively(); - } - - // Create a new test results folder - return QDir().mkdir(testResultsFolderPath); - } else { - return true; - } -} - -void Test::zipAndDeleteTestResultsFolder() { - QString zippedResultsFileName { testResultsFolderPath + ".zip" }; - QFileInfo fileInfo(zippedResultsFileName); - if (!fileInfo.exists()) { - QFile::remove(zippedResultsFileName); - } - - QDir testResultsFolder(testResultsFolderPath); - if (!testResultsFolder.isEmpty()) { - JlCompress::compressDir(testResultsFolderPath + ".zip", testResultsFolderPath); - } - - testResultsFolder.removeRecursively(); - - //In all cases, for the next evaluation - testResultsFolderPath = ""; - index = 1; -} - -bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode, QProgressBar* progressBar) { - progressBar->setMinimum(0); - progressBar->setMaximum(expectedImages.length() - 1); - progressBar->setValue(0); - progressBar->setVisible(true); - +bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages) { // Loop over both lists and compare each pair of images // Quit loop if user has aborted due to a failed test. - const double THRESHOLD { 0.999 }; + const double THRESHOLD{ 0.999 }; bool success{ true }; bool keepOn{ true }; for (int i = 0; keepOn && i < expectedImages.length(); ++i) { @@ -89,107 +45,42 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage } if (similarityIndex < THRESHOLD) { - TestFailure testFailure = TestFailure{ + mismatchWindow.setTestFailure(TestFailure{ (float)similarityIndex, expectedImages[i].left(expectedImages[i].lastIndexOf("/") + 1), // path to the test (including trailing /) QFileInfo(expectedImages[i].toStdString().c_str()).fileName(), // filename of expected image QFileInfo(resultImages[i].toStdString().c_str()).fileName() // filename of result image - }; + }); - mismatchWindow.setTestFailure(testFailure); + mismatchWindow.exec(); - if (!interactiveMode) { - appendTestResultsToFile(testResultsFolderPath, testFailure, mismatchWindow.getComparisonImage()); - success = false; - } else { - mismatchWindow.exec(); - - switch (mismatchWindow.getUserResponse()) { - case USER_RESPONSE_PASS: - break; - case USE_RESPONSE_FAIL: - appendTestResultsToFile(testResultsFolderPath, testFailure, mismatchWindow.getComparisonImage()); - success = false; - break; - case USER_RESPONSE_ABORT: - keepOn = false; - success = false; - break; - default: - assert(false); - break; - } + switch (mismatchWindow.getUserResponse()) { + case USER_RESPONSE_PASS: + break; + case USE_RESPONSE_FAIL: + success = false; + break; + case USER_RESPONSE_ABORT: + keepOn = false; + success = false; + break; + default: + assert(false); + break; } } - - progressBar->setValue(i); } - progressBar->setVisible(false); return success; } -void Test::appendTestResultsToFile(QString testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage) { - if (!QDir().exists(testResultsFolderPath)) { - messageBox.critical(0, "Internal error", "Folder " + testResultsFolderPath + " not found"); - exit(-1); - } - - QString failureFolderPath { testResultsFolderPath + "/" + "Failure_" + QString::number(index) }; - if (!QDir().mkdir(failureFolderPath)) { - messageBox.critical(0, "Internal error", "Failed to create folder " + failureFolderPath); - exit(-1); - } - ++index; - - QFile descriptionFile(failureFolderPath + "/" + TEST_RESULTS_FILENAME); - if (!descriptionFile.open(QIODevice::ReadWrite)) { - messageBox.critical(0, "Internal error", "Failed to create file " + TEST_RESULTS_FILENAME); - exit(-1); - } - - // Create text file describing the failure - QTextStream stream(&descriptionFile); - stream << "Test failed in folder " << testFailure._pathname.left(testFailure._pathname.length() - 1) << endl; // remove trailing '/' - stream << "Expected image was " << testFailure._expectedImageFilename << endl; - stream << "Actual image was " << testFailure._actualImageFilename << endl; - stream << "Similarity index was " << testFailure._error << endl; - - descriptionFile.close(); - - // Copy expected and actual images, and save the difference image - QString sourceFile; - QString destinationFile; - - sourceFile = testFailure._pathname + testFailure._expectedImageFilename; - destinationFile = failureFolderPath + "/" + "Expected Image.jpg"; - if (!QFile::copy(sourceFile, destinationFile)) { - messageBox.critical(0, "Internal error", "Failed to copy " + sourceFile + " to " + destinationFile); - exit(-1); - } - - sourceFile = testFailure._pathname + testFailure._actualImageFilename; - destinationFile = failureFolderPath + "/" + "Actual Image.jpg"; - if (!QFile::copy(sourceFile, destinationFile)) { - messageBox.critical(0, "Internal error", "Failed to copy " + sourceFile + " to " + destinationFile); - exit(-1); - } - - comparisonImage.save(failureFolderPath + "/" + "Difference Image.jpg"); -} - -void Test::evaluateTests(bool interactiveMode, QProgressBar* progressBar) { +void Test::evaluateTests() { // Get list of JPEG images in folder, sorted by name QString pathToImageDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder containing the test images", ".", QFileDialog::ShowDirsOnly); if (pathToImageDirectory == "") { return; } - // Leave if test results folder could not be created - if (!createTestResultsFolderPathIfNeeded(pathToImageDirectory)) { - return; - } - QStringList sortedImageFilenames = createListOfAllJPEGimagesInDirectory(pathToImageDirectory); // Separate images into two lists. The first is the expected images, the second is the test results @@ -216,32 +107,25 @@ void Test::evaluateTests(bool interactiveMode, QProgressBar* progressBar) { exit(-1); } - bool success = compareImageLists(expectedImages, resultImages, pathToImageDirectory, interactiveMode, progressBar); + bool success = compareImageLists(expectedImages, resultImages); if (success) { messageBox.information(0, "Success", "All images are as expected"); } else { messageBox.information(0, "Failure", "One or more images are not as expected"); } - - zipAndDeleteTestResultsFolder(); } // Two criteria are used to decide if a folder contains valid test results. // 1) a 'test'js' file exists in the folder // 2) the folder has the same number of actual and expected images -void Test::evaluateTestsRecursively(bool interactiveMode, QProgressBar* progressBar) { +void Test::evaluateTestsRecursively() { // Select folder to start recursing from QString topLevelDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder that will contain the top level test script", ".", QFileDialog::ShowDirsOnly); if (topLevelDirectory == "") { return; } - // Leave if test results folder could not be created - if (!createTestResultsFolderPathIfNeeded(topLevelDirectory)) { - return; - } - bool success{ true }; QDirIterator it(topLevelDirectory.toStdString().c_str(), QDirIterator::Subdirectories); while (it.hasNext()) { @@ -251,7 +135,8 @@ void Test::evaluateTestsRecursively(bool interactiveMode, QProgressBar* progress continue; } - const QString testPathname{ directory + "/" + TEST_FILENAME }; + // + const QString testPathname{ directory + "/" + testFilename }; QFileInfo fileInfo(testPathname); if (!fileInfo.exists()) { // Folder does not contain 'test.js' @@ -279,7 +164,7 @@ void Test::evaluateTestsRecursively(bool interactiveMode, QProgressBar* progress } // Set success to false if any test has failed - success &= compareImageLists(expectedImages, resultImages, directory, interactiveMode, progressBar); + success &= compareImageLists(expectedImages, resultImages); } if (success) { @@ -287,8 +172,6 @@ void Test::evaluateTestsRecursively(bool interactiveMode, QProgressBar* progress } else { messageBox.information(0, "Failure", "One or more images are not as expected"); } - - zipAndDeleteTestResultsFolder(); } void Test::importTest(QTextStream& textStream, const QString& testPathname, int testNumber) { @@ -308,8 +191,7 @@ void Test::createRecursiveScript() { if (!allTestsFilename.open(QIODevice::WriteOnly | QIODevice::Text)) { messageBox.critical(0, "Internal Error", - "Failed to create \"allTests.js\" in directory \"" + topLevelDirectory + "\"" - ); + "Failed to create \"allTests.js\" in directory \"" + topLevelDirectory + "\""); exit(-1); } @@ -324,7 +206,7 @@ void Test::createRecursiveScript() { QVector testPathnames; // First test if top-level folder has a test.js file - const QString testPathname{ topLevelDirectory + "/" + TEST_FILENAME }; + const QString testPathname{ topLevelDirectory + "/" + testFilename }; QFileInfo fileInfo(testPathname); if (fileInfo.exists()) { // Current folder contains a test @@ -342,7 +224,7 @@ void Test::createRecursiveScript() { continue; } - const QString testPathname{ directory + "/" + TEST_FILENAME }; + const QString testPathname{ directory + "/" + testFilename }; QFileInfo fileInfo(testPathname); if (fileInfo.exists()) { // Current folder contains a test @@ -382,7 +264,7 @@ void Test::createRecursiveScript() { // The script produced will look as follows: // if (test1HasNotStarted) { // test1HasNotStarted = false; - // test1.test("auto"); + // test1.test(); // print("******started test 1******"); // } // | @@ -405,7 +287,7 @@ void Test::createRecursiveScript() { textStream << tab << tab << "if (test" << i - 1 << ".complete && test" << i << "HasNotStarted) {" << endl; } textStream << tab << tab << tab << "test" << i << "HasNotStarted = false;" << endl; - textStream << tab << tab << tab << "test" << i << "." << testFunction << "(\"auto\");" << endl; + textStream << tab << tab << tab << "test" << i << "." << testFunction << "();" << endl; textStream << tab << tab << tab << "print(\"******started test " << i << "******\");" << endl; textStream << tab << tab << "}" << endl << endl; diff --git a/tools/auto-tester/src/Test.h b/tools/auto-tester/src/Test.h index 37827e9e0b..1f7b1e92a7 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/auto-tester/src/Test.h @@ -15,7 +15,6 @@ #include #include #include -#include #include "ImageComparer.h" #include "ui/MismatchWindow.h" @@ -24,13 +23,11 @@ class Test { public: Test(); - void evaluateTests(bool interactiveMode, QProgressBar* progressBar); - void evaluateTestsRecursively(bool interactiveMode, QProgressBar* progressBar); + void evaluateTests(); + void evaluateTestsRecursively(); void createRecursiveScript(); void createTest(); - bool compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode, QProgressBar* progressBar); - QStringList createListOfAllJPEGimagesInDirectory(QString pathToImageDirectory); bool isInSnapshotFilenameFormat(QString filename); @@ -38,15 +35,8 @@ public: void importTest(QTextStream& textStream, const QString& testPathname, int testNumber); - void appendTestResultsToFile(QString testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage); - - bool createTestResultsFolderPathIfNeeded(QString directory); - void zipAndDeleteTestResultsFolder(); - private: - const QString TEST_FILENAME { "test.js" }; - const QString TEST_RESULTS_FOLDER { "TestResults" }; - const QString TEST_RESULTS_FILENAME { "TestResults.txt" }; + const QString testFilename{ "test.js" }; QMessageBox messageBox; @@ -59,9 +49,7 @@ private: ImageComparer imageComparer; - - QString testResultsFolderPath { "" }; - int index { 1 }; + bool compareImageLists(QStringList expectedImages, QStringList resultImages); }; #endif // hifi_test_h diff --git a/tools/auto-tester/src/common.h b/tools/auto-tester/src/common.h index 0c21d79b33..126177358f 100644 --- a/tools/auto-tester/src/common.h +++ b/tools/auto-tester/src/common.h @@ -34,9 +34,4 @@ enum UserResponse { USER_RESPONSE_ABORT }; -// Coefficients for luminosity calculation -const double R_Y = 0.212655f; -const double G_Y = 0.715158f; -const double B_Y = 0.072187f; - #endif // hifi_common_h diff --git a/tools/auto-tester/src/ui/AutoTester.cpp b/tools/auto-tester/src/ui/AutoTester.cpp index 1f1283b98b..105baddb92 100644 --- a/tools/auto-tester/src/ui/AutoTester.cpp +++ b/tools/auto-tester/src/ui/AutoTester.cpp @@ -12,18 +12,14 @@ AutoTester::AutoTester(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); - - ui.checkBoxInteractiveMode->setChecked(true); - - ui.progressBar->setVisible(false); } void AutoTester::on_evaluateTestsButton_clicked() { - test.evaluateTests(ui.checkBoxInteractiveMode->isChecked(), ui.progressBar); + test.evaluateTests(); } void AutoTester::on_evaluateTestsRecursivelyButton_clicked() { - test.evaluateTestsRecursively(ui.checkBoxInteractiveMode->isChecked(), ui.progressBar); + test.evaluateTestsRecursively(); } void AutoTester::on_createRecursiveScriptButton_clicked() { diff --git a/tools/auto-tester/src/ui/AutoTester.h b/tools/auto-tester/src/ui/AutoTester.h index 99af639582..acfea32ba1 100644 --- a/tools/auto-tester/src/ui/AutoTester.h +++ b/tools/auto-tester/src/ui/AutoTester.h @@ -22,9 +22,9 @@ public: AutoTester(QWidget *parent = Q_NULLPTR); private slots: - void on_evaluateTestsButton_clicked(); - void on_evaluateTestsRecursivelyButton_clicked(); - void on_createRecursiveScriptButton_clicked(); +void on_evaluateTestsButton_clicked(); +void on_evaluateTestsRecursivelyButton_clicked(); +void on_createRecursiveScriptButton_clicked(); void on_createTestButton_clicked(); void on_closeButton_clicked(); diff --git a/tools/auto-tester/src/ui/AutoTester.ui b/tools/auto-tester/src/ui/AutoTester.ui index 544141975f..7032ef9710 100644 --- a/tools/auto-tester/src/ui/AutoTester.ui +++ b/tools/auto-tester/src/ui/AutoTester.ui @@ -6,8 +6,8 @@ 0 0 - 607 - 395 + 286 + 470
@@ -17,9 +17,9 @@ - 190 - 300 - 220 + 60 + 360 + 160 40 @@ -30,9 +30,9 @@ - 360 - 130 - 220 + 60 + 270 + 160 40 @@ -43,9 +43,9 @@ - 20 - 75 - 220 + 60 + 20 + 160 40 @@ -56,9 +56,9 @@ - 360 - 75 - 220 + 60 + 210 + 160 40 @@ -69,9 +69,9 @@ - 20 - 130 - 220 + 60 + 75 + 160 40 @@ -79,42 +79,13 @@ Evaluate Tests Recursively
- - - - 23 - 40 - 131 - 20 - - - - <html><head/><body><p>If unchecked, will not show results during evaluation</p></body></html> - - - Interactive Mode - - - - - - 20 - 190 - 255 - 23 - - - - 24 - - 0 0 - 607 + 286 21 diff --git a/tools/auto-tester/src/ui/MismatchWindow.cpp b/tools/auto-tester/src/ui/MismatchWindow.cpp index fe22412522..07664a1667 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.cpp +++ b/tools/auto-tester/src/ui/MismatchWindow.cpp @@ -11,48 +11,11 @@ #include -#include - MismatchWindow::MismatchWindow(QWidget *parent) : QDialog(parent) { setupUi(this); expectedImage->setScaledContents(true); resultImage->setScaledContents(true); - diffImage->setScaledContents(true); -} - -QPixmap MismatchWindow::computeDiffPixmap(QImage expectedImage, QImage resultImage) { - // This is an optimization, as QImage.setPixel() is embarrassingly slow - unsigned char* buffer = new unsigned char[expectedImage.height() * expectedImage.width() * 3]; - - // loop over each pixel - for (int y = 0; y < expectedImage.height(); ++y) { - for (int x = 0; x < expectedImage.width(); ++x) { - QRgb pixelP = expectedImage.pixel(QPoint(x, y)); - QRgb pixelQ = resultImage.pixel(QPoint(x, y)); - - // Convert to luminance - double p = R_Y * qRed(pixelP) + G_Y * qGreen(pixelP) + B_Y * qBlue(pixelP); - double q = R_Y * qRed(pixelQ) + G_Y * qGreen(pixelQ) + B_Y * qBlue(pixelQ); - - // The intensity value is modified to increase the brightness of the displayed image - double absoluteDifference = fabs(p - q) / 255.0; - double modifiedDifference = sqrt(absoluteDifference); - - int difference = (int)(modifiedDifference * 255.0); - - buffer[3 * (x + y * expectedImage.width()) + 0] = difference; - buffer[3 * (x + y * expectedImage.width()) + 1] = difference; - buffer[3 * (x + y * expectedImage.width()) + 2] = difference; - } - } - - QImage diffImage(buffer, expectedImage.width(), expectedImage.height(), QImage::Format_RGB888); - QPixmap resultPixmap = QPixmap::fromImage(diffImage); - - delete[] buffer; - - return resultPixmap; } void MismatchWindow::setTestFailure(TestFailure testFailure) { @@ -61,19 +24,10 @@ void MismatchWindow::setTestFailure(TestFailure testFailure) { imagePath->setText("Path to test: " + testFailure._pathname); expectedFilename->setText(testFailure._expectedImageFilename); + expectedImage->setPixmap(QPixmap(testFailure._pathname + testFailure._expectedImageFilename)); + resultFilename->setText(testFailure._actualImageFilename); - - QPixmap expectedPixmap = QPixmap(testFailure._pathname + testFailure._expectedImageFilename); - QPixmap actualPixmap = QPixmap(testFailure._pathname + testFailure._actualImageFilename); - - diffPixmap = computeDiffPixmap( - QImage(testFailure._pathname + testFailure._expectedImageFilename), - QImage(testFailure._pathname + testFailure._actualImageFilename) - ); - - expectedImage->setPixmap(expectedPixmap); - resultImage->setPixmap(actualPixmap); - diffImage->setPixmap(diffPixmap); + resultImage->setPixmap(QPixmap(testFailure._pathname + testFailure._actualImageFilename)); } void MismatchWindow::on_passTestButton_clicked() { @@ -90,7 +44,3 @@ void MismatchWindow::on_abortTestsButton_clicked() { _userResponse = USER_RESPONSE_ABORT; close(); } - -QPixmap MismatchWindow::getComparisonImage() { - return diffPixmap; -} \ No newline at end of file diff --git a/tools/auto-tester/src/ui/MismatchWindow.h b/tools/auto-tester/src/ui/MismatchWindow.h index ad8be16580..7c72b7b0b7 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.h +++ b/tools/auto-tester/src/ui/MismatchWindow.h @@ -25,9 +25,6 @@ public: UserResponse getUserResponse() { return _userResponse; } - QPixmap computeDiffPixmap(QImage expectedImage, QImage resultImage); - QPixmap getComparisonImage(); - private slots: void on_passTestButton_clicked(); void on_failTestButton_clicked(); @@ -35,8 +32,6 @@ private slots: private: UserResponse _userResponse{ USER_RESPONSE_INVALID }; - - QPixmap diffPixmap; }; diff --git a/tools/auto-tester/src/ui/MismatchWindow.ui b/tools/auto-tester/src/ui/MismatchWindow.ui index 5ecf966df5..cab6c61e1c 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.ui +++ b/tools/auto-tester/src/ui/MismatchWindow.ui @@ -6,8 +6,8 @@ 0 0 - 1782 - 942 + 1585 + 694
@@ -16,10 +16,10 @@ - 10 - 25 - 800 - 450 + 20 + 170 + 720 + 362 @@ -29,41 +29,28 @@ - 900 - 25 - 800 - 450 + 760 + 170 + 720 + 362 result image - - - - 540 - 480 - 800 - 450 - - - - diff image - - - 60 - 660 - 480 + 760 + 90 + 800 28 - 12 + 16 @@ -73,15 +60,15 @@ - 60 - 630 - 480 + 40 + 90 + 700 28 - 12 + 16 @@ -91,15 +78,15 @@ - 20 - 600 + 40 + 30 1200 28 - 12 + 16 @@ -110,7 +97,7 @@ 30 - 790 + 600 75 23 @@ -122,8 +109,8 @@ - 120 - 790 + 330 + 600 75 23 @@ -135,60 +122,34 @@ - 210 - 790 - 121 + 630 + 600 + 75 23 - Abort current test + Abort Tests - 30 - 850 - 500 + 810 + 600 + 720 28 - 12 + 16 similarity - - - - 30 - 5 - 151 - 16 - - - - Expected Image - - - - - - 930 - 5 - 151 - 16 - - - - Actual Image - - From 0764e80996c7bf30f3ba08527890fcd9bbd3263d Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Sat, 30 Dec 2017 18:19:42 -0800 Subject: [PATCH 33/46] Corrected behaviour of skybox modes. --- libraries/entities-renderer/src/RenderableZoneEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index a6c0b374fa..999bcf45bd 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -183,7 +183,7 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { if (_skyboxMode == COMPONENT_MODE_DISABLED && _skyboxOnIndex == NO_STORED_VALUE) { // Just turned off, store previous value before changing _skyboxOnIndex = _backgroundIndex; - _backgroundIndex = _stage->getSunOffLight(); + _backgroundIndex = INVALID_INDEX; } else if (_skyboxMode == COMPONENT_MODE_ENABLED && _skyboxOnIndex != NO_STORED_VALUE) { // Just turned on, restore previous value before clearing stored value _backgroundIndex = _skyboxOnIndex; From dad3a0d3408320d2a7525a3cde92546e8a0f5a2d Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Tue, 2 Jan 2018 09:08:05 -0800 Subject: [PATCH 34/46] Fixed skybox inheritance. --- libraries/entities-renderer/src/RenderableZoneEntityItem.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 999bcf45bd..0d975759b4 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -145,10 +145,8 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { updateSkyboxMap(); if (_needBackgroundUpdate) { - if (BackgroundStage::isIndexInvalid(_backgroundIndex)) { + if (_skyboxMode == COMPONENT_MODE_ENABLED && BackgroundStage::isIndexInvalid(_backgroundIndex)) { _backgroundIndex = _backgroundStage->addBackground(_background); - } else { - } _needBackgroundUpdate = false; } From 22c5890812f926618e644aed0e3306ed32dc2570 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Tue, 2 Jan 2018 09:23:38 -0800 Subject: [PATCH 35/46] Rebased. --- tools/auto-tester/CMakeLists.txt | 44 ++-- tools/auto-tester/src/ImageComparer.cpp | 6 +- tools/auto-tester/src/Test.cpp | 210 +++++++++++++++++--- tools/auto-tester/src/Test.h | 21 +- tools/auto-tester/src/common.h | 5 + tools/auto-tester/src/ui/AutoTester.cpp | 12 +- tools/auto-tester/src/ui/AutoTester.h | 7 +- tools/auto-tester/src/ui/AutoTester.ui | 78 ++++++-- tools/auto-tester/src/ui/MismatchWindow.cpp | 56 +++++- tools/auto-tester/src/ui/MismatchWindow.h | 5 + tools/auto-tester/src/ui/MismatchWindow.ui | 103 +++++++--- 11 files changed, 426 insertions(+), 121 deletions(-) diff --git a/tools/auto-tester/CMakeLists.txt b/tools/auto-tester/CMakeLists.txt index e5f2c1fb97..a875f5676a 100644 --- a/tools/auto-tester/CMakeLists.txt +++ b/tools/auto-tester/CMakeLists.txt @@ -1,47 +1,41 @@ -set(TARGET_NAME auto-tester) +set (TARGET_NAME auto-tester) project(${TARGET_NAME}) # Automatically run UIC and MOC. This replaces the older WRAP macros -SET(CMAKE_AUTOUIC ON) -SET(CMAKE_AUTOMOC ON) +SET (CMAKE_AUTOUIC ON) +SET (CMAKE_AUTOMOC ON) -setup_hifi_project(Core Widgets) -link_hifi_libraries() +setup_hifi_project (Core Widgets) +link_hifi_libraries () # FIX: Qt was built with -reduce-relocations if (Qt5_POSITION_INDEPENDENT_CODE) - SET(CMAKE_POSITION_INDEPENDENT_CODE ON) + SET (CMAKE_POSITION_INDEPENDENT_CODE ON) endif() # Qt includes -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${Qt5Core_INCLUDE_DIRS}) -include_directories(${Qt5Widgets_INCLUDE_DIRS}) +include_directories (${CMAKE_CURRENT_SOURCE_DIR}) +include_directories (${Qt5Core_INCLUDE_DIRS}) +include_directories (${Qt5Widgets_INCLUDE_DIRS}) -set(QT_LIBRARIES Qt5::Core Qt5::Widgets) - -# Find all sources files -file (GLOB_RECURSE SOURCES src/*.cpp) -file (GLOB_RECURSE HEADERS src/*.h) -file (GLOB_RECURSE UIS src/ui/*.ui) +set (QT_LIBRARIES Qt5::Core Qt5::Widgets) if (WIN32) # Do not show Console - set_property(TARGET auto-tester PROPERTY WIN32_EXECUTABLE true) + set_property (TARGET auto-tester PROPERTY WIN32_EXECUTABLE true) endif() -add_executable(PROJECT_NAME ${SOURCES} ${HEADERS} ${UIS}) +target_zlib() +add_dependency_external_projects (quazip) +find_package (QuaZip REQUIRED) +target_include_directories( ${TARGET_NAME} SYSTEM PUBLIC ${QUAZIP_INCLUDE_DIRS}) +target_link_libraries(${TARGET_NAME} ${QUAZIP_LIBRARIES}) -target_link_libraries(PROJECT_NAME ${QT_LIBRARIES}) - -# Copy required dll's. -add_custom_command(TARGET auto-tester POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ -) +package_libraries_for_deployment() if (WIN32) + add_paths_to_fixup_libs (${QUAZIP_DLL_PATH}) + find_program(WINDEPLOYQT_COMMAND windeployqt PATHS ${QT_DIR}/bin NO_DEFAULT_PATH) if (NOT WINDEPLOYQT_COMMAND) diff --git a/tools/auto-tester/src/ImageComparer.cpp b/tools/auto-tester/src/ImageComparer.cpp index 121c98e16e..a80978e564 100644 --- a/tools/auto-tester/src/ImageComparer.cpp +++ b/tools/auto-tester/src/ImageComparer.cpp @@ -8,6 +8,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "ImageComparer.h" +#include "common.h" #include @@ -26,11 +27,6 @@ double ImageComparer::compareImages(QImage resultImage, QImage expectedImage) co const double c1 = pow((K1 * L), 2); const double c2 = pow((K2 * L), 2); - // Coefficients for luminosity calculation - const double R_Y = 0.212655f; - const double G_Y = 0.715158f; - const double B_Y = 0.072187f; - // First go over all full 8x8 blocks // This is done in 3 loops // 1) Read the pixels into a linear array (an optimization) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index 8cb36fcfca..6294829655 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -13,6 +13,9 @@ #include #include +#include +#include + Test::Test() { snapshotFilenameFormat = QRegularExpression("hifi-snap-by-.+-on-\\d\\d\\d\\d-\\d\\d-\\d\\d_\\d\\d-\\d\\d-\\d\\d.jpg"); @@ -21,10 +24,51 @@ Test::Test() { mismatchWindow.setModal(true); } -bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages) { +bool Test::createTestResultsFolderPathIfNeeded(QString directory) { + // The test results folder is located in the root of the tests (i.e. for recursive test evaluation) + if (testResultsFolderPath == "") { + testResultsFolderPath = directory + "/" + TEST_RESULTS_FOLDER; + QDir testResultsFolder(testResultsFolderPath); + + if (testResultsFolder.exists()) { + testResultsFolder.removeRecursively(); + } + + // Create a new test results folder + return QDir().mkdir(testResultsFolderPath); + } else { + return true; + } +} + +void Test::zipAndDeleteTestResultsFolder() { + QString zippedResultsFileName { testResultsFolderPath + ".zip" }; + QFileInfo fileInfo(zippedResultsFileName); + if (!fileInfo.exists()) { + QFile::remove(zippedResultsFileName); + } + + QDir testResultsFolder(testResultsFolderPath); + if (!testResultsFolder.isEmpty()) { + JlCompress::compressDir(testResultsFolderPath + ".zip", testResultsFolderPath); + } + + testResultsFolder.removeRecursively(); + + //In all cases, for the next evaluation + testResultsFolderPath = ""; + index = 1; +} + +bool Test::compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode, QProgressBar* progressBar) { + progressBar->setMinimum(0); + progressBar->setMaximum(expectedImages.length() - 1); + progressBar->setValue(0); + progressBar->setVisible(true); + // Loop over both lists and compare each pair of images // Quit loop if user has aborted due to a failed test. - const double THRESHOLD{ 0.999 }; + const double THRESHOLD { 0.999 }; bool success{ true }; bool keepOn{ true }; for (int i = 0; keepOn && i < expectedImages.length(); ++i) { @@ -45,42 +89,107 @@ bool Test::compareImageLists(QStringList expectedImages, QStringList resultImage } if (similarityIndex < THRESHOLD) { - mismatchWindow.setTestFailure(TestFailure{ + TestFailure testFailure = TestFailure{ (float)similarityIndex, expectedImages[i].left(expectedImages[i].lastIndexOf("/") + 1), // path to the test (including trailing /) QFileInfo(expectedImages[i].toStdString().c_str()).fileName(), // filename of expected image QFileInfo(resultImages[i].toStdString().c_str()).fileName() // filename of result image - }); + }; - mismatchWindow.exec(); + mismatchWindow.setTestFailure(testFailure); - switch (mismatchWindow.getUserResponse()) { - case USER_RESPONSE_PASS: - break; - case USE_RESPONSE_FAIL: - success = false; - break; - case USER_RESPONSE_ABORT: - keepOn = false; - success = false; - break; - default: - assert(false); - break; + if (!interactiveMode) { + appendTestResultsToFile(testResultsFolderPath, testFailure, mismatchWindow.getComparisonImage()); + success = false; + } else { + mismatchWindow.exec(); + + switch (mismatchWindow.getUserResponse()) { + case USER_RESPONSE_PASS: + break; + case USE_RESPONSE_FAIL: + appendTestResultsToFile(testResultsFolderPath, testFailure, mismatchWindow.getComparisonImage()); + success = false; + break; + case USER_RESPONSE_ABORT: + keepOn = false; + success = false; + break; + default: + assert(false); + break; + } } } + + progressBar->setValue(i); } + progressBar->setVisible(false); return success; } -void Test::evaluateTests() { +void Test::appendTestResultsToFile(QString testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage) { + if (!QDir().exists(testResultsFolderPath)) { + messageBox.critical(0, "Internal error", "Folder " + testResultsFolderPath + " not found"); + exit(-1); + } + + QString failureFolderPath { testResultsFolderPath + "/" + "Failure_" + QString::number(index) }; + if (!QDir().mkdir(failureFolderPath)) { + messageBox.critical(0, "Internal error", "Failed to create folder " + failureFolderPath); + exit(-1); + } + ++index; + + QFile descriptionFile(failureFolderPath + "/" + TEST_RESULTS_FILENAME); + if (!descriptionFile.open(QIODevice::ReadWrite)) { + messageBox.critical(0, "Internal error", "Failed to create file " + TEST_RESULTS_FILENAME); + exit(-1); + } + + // Create text file describing the failure + QTextStream stream(&descriptionFile); + stream << "Test failed in folder " << testFailure._pathname.left(testFailure._pathname.length() - 1) << endl; // remove trailing '/' + stream << "Expected image was " << testFailure._expectedImageFilename << endl; + stream << "Actual image was " << testFailure._actualImageFilename << endl; + stream << "Similarity index was " << testFailure._error << endl; + + descriptionFile.close(); + + // Copy expected and actual images, and save the difference image + QString sourceFile; + QString destinationFile; + + sourceFile = testFailure._pathname + testFailure._expectedImageFilename; + destinationFile = failureFolderPath + "/" + "Expected Image.jpg"; + if (!QFile::copy(sourceFile, destinationFile)) { + messageBox.critical(0, "Internal error", "Failed to copy " + sourceFile + " to " + destinationFile); + exit(-1); + } + + sourceFile = testFailure._pathname + testFailure._actualImageFilename; + destinationFile = failureFolderPath + "/" + "Actual Image.jpg"; + if (!QFile::copy(sourceFile, destinationFile)) { + messageBox.critical(0, "Internal error", "Failed to copy " + sourceFile + " to " + destinationFile); + exit(-1); + } + + comparisonImage.save(failureFolderPath + "/" + "Difference Image.jpg"); +} + +void Test::evaluateTests(bool interactiveMode, QProgressBar* progressBar) { // Get list of JPEG images in folder, sorted by name QString pathToImageDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder containing the test images", ".", QFileDialog::ShowDirsOnly); if (pathToImageDirectory == "") { return; } + // Leave if test results folder could not be created + if (!createTestResultsFolderPathIfNeeded(pathToImageDirectory)) { + return; + } + QStringList sortedImageFilenames = createListOfAllJPEGimagesInDirectory(pathToImageDirectory); // Separate images into two lists. The first is the expected images, the second is the test results @@ -107,25 +216,32 @@ void Test::evaluateTests() { exit(-1); } - bool success = compareImageLists(expectedImages, resultImages); + bool success = compareImageLists(expectedImages, resultImages, pathToImageDirectory, interactiveMode, progressBar); if (success) { messageBox.information(0, "Success", "All images are as expected"); } else { messageBox.information(0, "Failure", "One or more images are not as expected"); } + + zipAndDeleteTestResultsFolder(); } // Two criteria are used to decide if a folder contains valid test results. // 1) a 'test'js' file exists in the folder // 2) the folder has the same number of actual and expected images -void Test::evaluateTestsRecursively() { +void Test::evaluateTestsRecursively(bool interactiveMode, QProgressBar* progressBar) { // Select folder to start recursing from QString topLevelDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select folder that will contain the top level test script", ".", QFileDialog::ShowDirsOnly); if (topLevelDirectory == "") { return; } + // Leave if test results folder could not be created + if (!createTestResultsFolderPathIfNeeded(topLevelDirectory)) { + return; + } + bool success{ true }; QDirIterator it(topLevelDirectory.toStdString().c_str(), QDirIterator::Subdirectories); while (it.hasNext()) { @@ -135,8 +251,7 @@ void Test::evaluateTestsRecursively() { continue; } - // - const QString testPathname{ directory + "/" + testFilename }; + const QString testPathname{ directory + "/" + TEST_FILENAME }; QFileInfo fileInfo(testPathname); if (!fileInfo.exists()) { // Folder does not contain 'test.js' @@ -164,7 +279,7 @@ void Test::evaluateTestsRecursively() { } // Set success to false if any test has failed - success &= compareImageLists(expectedImages, resultImages); + success &= compareImageLists(expectedImages, resultImages, directory, interactiveMode, progressBar); } if (success) { @@ -172,6 +287,8 @@ void Test::evaluateTestsRecursively() { } else { messageBox.information(0, "Failure", "One or more images are not as expected"); } + + zipAndDeleteTestResultsFolder(); } void Test::importTest(QTextStream& textStream, const QString& testPathname, int testNumber) { @@ -191,7 +308,8 @@ void Test::createRecursiveScript() { if (!allTestsFilename.open(QIODevice::WriteOnly | QIODevice::Text)) { messageBox.critical(0, "Internal Error", - "Failed to create \"allTests.js\" in directory \"" + topLevelDirectory + "\""); + "Failed to create \"allTests.js\" in directory \"" + topLevelDirectory + "\"" + ); exit(-1); } @@ -206,7 +324,7 @@ void Test::createRecursiveScript() { QVector testPathnames; // First test if top-level folder has a test.js file - const QString testPathname{ topLevelDirectory + "/" + testFilename }; + const QString testPathname{ topLevelDirectory + "/" + TEST_FILENAME }; QFileInfo fileInfo(testPathname); if (fileInfo.exists()) { // Current folder contains a test @@ -224,7 +342,7 @@ void Test::createRecursiveScript() { continue; } - const QString testPathname{ directory + "/" + testFilename }; + const QString testPathname{ directory + "/" + TEST_FILENAME }; QFileInfo fileInfo(testPathname); if (fileInfo.exists()) { // Current folder contains a test @@ -264,7 +382,7 @@ void Test::createRecursiveScript() { // The script produced will look as follows: // if (test1HasNotStarted) { // test1HasNotStarted = false; - // test1.test(); + // test1.test("auto"); // print("******started test 1******"); // } // | @@ -287,7 +405,7 @@ void Test::createRecursiveScript() { textStream << tab << tab << "if (test" << i - 1 << ".complete && test" << i << "HasNotStarted) {" << endl; } textStream << tab << tab << tab << "test" << i << "HasNotStarted = false;" << endl; - textStream << tab << tab << tab << "test" << i << "." << testFunction << "();" << endl; + textStream << tab << tab << tab << "test" << i << "." << testFunction << "(\"auto\");" << endl; textStream << tab << tab << tab << "print(\"******started test " << i << "******\");" << endl; textStream << tab << tab << "}" << endl << endl; @@ -366,6 +484,39 @@ void Test::createTest() { messageBox.information(0, "Success", "Test images have been created"); } +void Test::deleteOldSnapshots() { + // Select folder to start recursing from + QString topLevelDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select root folder for snapshot deletion", ".", QFileDialog::ShowDirsOnly); + if (topLevelDirectory == "") { + return; + } + + // Recurse over folders + QDirIterator it(topLevelDirectory.toStdString().c_str(), QDirIterator::Subdirectories); + while (it.hasNext()) { + QString directory = it.next(); + if (directory[directory.length() - 1] == '.') { + // ignore '.', '..' directories + continue; + } + + QStringList sortedImageFilenames = createListOfAllJPEGimagesInDirectory(directory); + + // Delete any file that is a snapshot (NOT the Expected Images) + QStringList expectedImages; + QStringList resultImages; + foreach(QString currentFilename, sortedImageFilenames) { + QString fullCurrentFilename = directory + "/" + currentFilename; + if (isInSnapshotFilenameFormat(currentFilename)) { + if (!QFile::remove(fullCurrentFilename)) { + messageBox.critical(0, "Error", "Could not delete existing file: " + currentFilename + "\nSnapshot deletion aborted"); + exit(-1); + } + } + } + } +} + QStringList Test::createListOfAllJPEGimagesInDirectory(QString pathToImageDirectory) { imageDirectory = QDir(pathToImageDirectory); QStringList nameFilters; @@ -374,6 +525,7 @@ QStringList Test::createListOfAllJPEGimagesInDirectory(QString pathToImageDirect return imageDirectory.entryList(nameFilters, QDir::Files, QDir::Name); } +// Use regular expressions to check if files are in specific format bool Test::isInSnapshotFilenameFormat(QString filename) { return (snapshotFilenameFormat.match(filename).hasMatch()); } diff --git a/tools/auto-tester/src/Test.h b/tools/auto-tester/src/Test.h index 1f7b1e92a7..f3625b1fa3 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/auto-tester/src/Test.h @@ -15,6 +15,7 @@ #include #include #include +#include #include "ImageComparer.h" #include "ui/MismatchWindow.h" @@ -23,10 +24,13 @@ class Test { public: Test(); - void evaluateTests(); - void evaluateTestsRecursively(); + void evaluateTests(bool interactiveMode, QProgressBar* progressBar); + void evaluateTestsRecursively(bool interactiveMode, QProgressBar* progressBar); void createRecursiveScript(); void createTest(); + void deleteOldSnapshots(); + + bool compareImageLists(QStringList expectedImages, QStringList resultImages, QString testDirectory, bool interactiveMode, QProgressBar* progressBar); QStringList createListOfAllJPEGimagesInDirectory(QString pathToImageDirectory); @@ -35,8 +39,15 @@ public: void importTest(QTextStream& textStream, const QString& testPathname, int testNumber); + void appendTestResultsToFile(QString testResultsFolderPath, TestFailure testFailure, QPixmap comparisonImage); + + bool createTestResultsFolderPathIfNeeded(QString directory); + void zipAndDeleteTestResultsFolder(); + private: - const QString testFilename{ "test.js" }; + const QString TEST_FILENAME { "test.js" }; + const QString TEST_RESULTS_FOLDER { "TestResults" }; + const QString TEST_RESULTS_FILENAME { "TestResults.txt" }; QMessageBox messageBox; @@ -49,7 +60,9 @@ private: ImageComparer imageComparer; - bool compareImageLists(QStringList expectedImages, QStringList resultImages); + + QString testResultsFolderPath { "" }; + int index { 1 }; }; #endif // hifi_test_h diff --git a/tools/auto-tester/src/common.h b/tools/auto-tester/src/common.h index 126177358f..0c21d79b33 100644 --- a/tools/auto-tester/src/common.h +++ b/tools/auto-tester/src/common.h @@ -34,4 +34,9 @@ enum UserResponse { USER_RESPONSE_ABORT }; +// Coefficients for luminosity calculation +const double R_Y = 0.212655f; +const double G_Y = 0.715158f; +const double B_Y = 0.072187f; + #endif // hifi_common_h diff --git a/tools/auto-tester/src/ui/AutoTester.cpp b/tools/auto-tester/src/ui/AutoTester.cpp index 105baddb92..2834ff81e0 100644 --- a/tools/auto-tester/src/ui/AutoTester.cpp +++ b/tools/auto-tester/src/ui/AutoTester.cpp @@ -12,14 +12,18 @@ AutoTester::AutoTester(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); + + ui.checkBoxInteractiveMode->setChecked(true); + + ui.progressBar->setVisible(false); } void AutoTester::on_evaluateTestsButton_clicked() { - test.evaluateTests(); + test.evaluateTests(ui.checkBoxInteractiveMode->isChecked(), ui.progressBar); } void AutoTester::on_evaluateTestsRecursivelyButton_clicked() { - test.evaluateTestsRecursively(); + test.evaluateTestsRecursively(ui.checkBoxInteractiveMode->isChecked(), ui.progressBar); } void AutoTester::on_createRecursiveScriptButton_clicked() { @@ -30,6 +34,10 @@ void AutoTester::on_createTestButton_clicked() { test.createTest(); } +void AutoTester::on_deleteOldSnapshotsButton_clicked() { + test.deleteOldSnapshots(); +} + void AutoTester::on_closeButton_clicked() { exit(0); } \ No newline at end of file diff --git a/tools/auto-tester/src/ui/AutoTester.h b/tools/auto-tester/src/ui/AutoTester.h index acfea32ba1..110b26a7ba 100644 --- a/tools/auto-tester/src/ui/AutoTester.h +++ b/tools/auto-tester/src/ui/AutoTester.h @@ -22,10 +22,11 @@ public: AutoTester(QWidget *parent = Q_NULLPTR); private slots: -void on_evaluateTestsButton_clicked(); -void on_evaluateTestsRecursivelyButton_clicked(); -void on_createRecursiveScriptButton_clicked(); + void on_evaluateTestsButton_clicked(); + void on_evaluateTestsRecursivelyButton_clicked(); + void on_createRecursiveScriptButton_clicked(); void on_createTestButton_clicked(); + void on_deleteOldSnapshotsButton_clicked(); void on_closeButton_clicked(); private: diff --git a/tools/auto-tester/src/ui/AutoTester.ui b/tools/auto-tester/src/ui/AutoTester.ui index 7032ef9710..4b2f9520a9 100644 --- a/tools/auto-tester/src/ui/AutoTester.ui +++ b/tools/auto-tester/src/ui/AutoTester.ui @@ -6,8 +6,8 @@ 0 0 - 286 - 470 + 607 + 395 @@ -17,9 +17,9 @@ - 60 - 360 - 160 + 190 + 300 + 220 40 @@ -30,9 +30,9 @@ - 60 - 270 - 160 + 360 + 130 + 220 40 @@ -43,9 +43,9 @@ - 60 - 20 - 160 + 20 + 75 + 220 40 @@ -56,9 +56,9 @@ - 60 - 210 - 160 + 360 + 75 + 220 40 @@ -69,9 +69,9 @@ - 60 - 75 - 160 + 20 + 130 + 220 40 @@ -79,13 +79,55 @@ Evaluate Tests Recursively + + + + 23 + 40 + 131 + 20 + + + + <html><head/><body><p>If unchecked, will not show results during evaluation</p></body></html> + + + Interactive Mode + + + + + + 20 + 190 + 255 + 23 + + + + 24 + + + + + + 360 + 240 + 220 + 40 + + + + Delete Old Snapshots + + 0 0 - 286 + 607 21 diff --git a/tools/auto-tester/src/ui/MismatchWindow.cpp b/tools/auto-tester/src/ui/MismatchWindow.cpp index 07664a1667..fe22412522 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.cpp +++ b/tools/auto-tester/src/ui/MismatchWindow.cpp @@ -11,11 +11,48 @@ #include +#include + MismatchWindow::MismatchWindow(QWidget *parent) : QDialog(parent) { setupUi(this); expectedImage->setScaledContents(true); resultImage->setScaledContents(true); + diffImage->setScaledContents(true); +} + +QPixmap MismatchWindow::computeDiffPixmap(QImage expectedImage, QImage resultImage) { + // This is an optimization, as QImage.setPixel() is embarrassingly slow + unsigned char* buffer = new unsigned char[expectedImage.height() * expectedImage.width() * 3]; + + // loop over each pixel + for (int y = 0; y < expectedImage.height(); ++y) { + for (int x = 0; x < expectedImage.width(); ++x) { + QRgb pixelP = expectedImage.pixel(QPoint(x, y)); + QRgb pixelQ = resultImage.pixel(QPoint(x, y)); + + // Convert to luminance + double p = R_Y * qRed(pixelP) + G_Y * qGreen(pixelP) + B_Y * qBlue(pixelP); + double q = R_Y * qRed(pixelQ) + G_Y * qGreen(pixelQ) + B_Y * qBlue(pixelQ); + + // The intensity value is modified to increase the brightness of the displayed image + double absoluteDifference = fabs(p - q) / 255.0; + double modifiedDifference = sqrt(absoluteDifference); + + int difference = (int)(modifiedDifference * 255.0); + + buffer[3 * (x + y * expectedImage.width()) + 0] = difference; + buffer[3 * (x + y * expectedImage.width()) + 1] = difference; + buffer[3 * (x + y * expectedImage.width()) + 2] = difference; + } + } + + QImage diffImage(buffer, expectedImage.width(), expectedImage.height(), QImage::Format_RGB888); + QPixmap resultPixmap = QPixmap::fromImage(diffImage); + + delete[] buffer; + + return resultPixmap; } void MismatchWindow::setTestFailure(TestFailure testFailure) { @@ -24,10 +61,19 @@ void MismatchWindow::setTestFailure(TestFailure testFailure) { imagePath->setText("Path to test: " + testFailure._pathname); expectedFilename->setText(testFailure._expectedImageFilename); - expectedImage->setPixmap(QPixmap(testFailure._pathname + testFailure._expectedImageFilename)); - resultFilename->setText(testFailure._actualImageFilename); - resultImage->setPixmap(QPixmap(testFailure._pathname + testFailure._actualImageFilename)); + + QPixmap expectedPixmap = QPixmap(testFailure._pathname + testFailure._expectedImageFilename); + QPixmap actualPixmap = QPixmap(testFailure._pathname + testFailure._actualImageFilename); + + diffPixmap = computeDiffPixmap( + QImage(testFailure._pathname + testFailure._expectedImageFilename), + QImage(testFailure._pathname + testFailure._actualImageFilename) + ); + + expectedImage->setPixmap(expectedPixmap); + resultImage->setPixmap(actualPixmap); + diffImage->setPixmap(diffPixmap); } void MismatchWindow::on_passTestButton_clicked() { @@ -44,3 +90,7 @@ void MismatchWindow::on_abortTestsButton_clicked() { _userResponse = USER_RESPONSE_ABORT; close(); } + +QPixmap MismatchWindow::getComparisonImage() { + return diffPixmap; +} \ No newline at end of file diff --git a/tools/auto-tester/src/ui/MismatchWindow.h b/tools/auto-tester/src/ui/MismatchWindow.h index 7c72b7b0b7..ad8be16580 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.h +++ b/tools/auto-tester/src/ui/MismatchWindow.h @@ -25,6 +25,9 @@ public: UserResponse getUserResponse() { return _userResponse; } + QPixmap computeDiffPixmap(QImage expectedImage, QImage resultImage); + QPixmap getComparisonImage(); + private slots: void on_passTestButton_clicked(); void on_failTestButton_clicked(); @@ -32,6 +35,8 @@ private slots: private: UserResponse _userResponse{ USER_RESPONSE_INVALID }; + + QPixmap diffPixmap; }; diff --git a/tools/auto-tester/src/ui/MismatchWindow.ui b/tools/auto-tester/src/ui/MismatchWindow.ui index cab6c61e1c..5ecf966df5 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.ui +++ b/tools/auto-tester/src/ui/MismatchWindow.ui @@ -6,8 +6,8 @@ 0 0 - 1585 - 694 + 1782 + 942 @@ -16,10 +16,10 @@ - 20 - 170 - 720 - 362 + 10 + 25 + 800 + 450 @@ -29,28 +29,41 @@ - 760 - 170 - 720 - 362 + 900 + 25 + 800 + 450 result image + + + + 540 + 480 + 800 + 450 + + + + diff image + + - 760 - 90 - 800 + 60 + 660 + 480 28 - 16 + 12 @@ -60,15 +73,15 @@ - 40 - 90 - 700 + 60 + 630 + 480 28 - 16 + 12 @@ -78,15 +91,15 @@ - 40 - 30 + 20 + 600 1200 28 - 16 + 12 @@ -97,7 +110,7 @@ 30 - 600 + 790 75 23 @@ -109,8 +122,8 @@ - 330 - 600 + 120 + 790 75 23 @@ -122,34 +135,60 @@ - 630 - 600 - 75 + 210 + 790 + 121 23 - Abort Tests + Abort current test - 810 - 600 - 720 + 30 + 850 + 500 28 - 16 + 12 similarity + + + + 30 + 5 + 151 + 16 + + + + Expected Image + + + + + + 930 + 5 + 151 + 16 + + + + Actual Image + + From 5b7ef9a3d366e269548e6f0aa75559ffe79b26b3 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Thu, 4 Jan 2018 09:13:58 -0800 Subject: [PATCH 36/46] Minor cleanup. --- .../entities-renderer/src/RenderableZoneEntityItem.h | 2 +- libraries/entities/src/EntityItemProperties.h | 8 +++++--- libraries/entities/src/ZoneEntityItem.h | 7 +++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index 2664180433..150b06d912 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -91,10 +91,10 @@ private: BackgroundMode _backgroundMode{ BACKGROUND_MODE_INHERIT }; - ComponentMode _hazeMode { COMPONENT_MODE_INHERIT }; ComponentMode _keyLightMode { COMPONENT_MODE_INHERIT }; ComponentMode _ambientLightMode { COMPONENT_MODE_INHERIT }; ComponentMode _skyboxMode { COMPONENT_MODE_INHERIT }; + ComponentMode _hazeMode { COMPONENT_MODE_INHERIT }; indexed_container::Index _sunIndex{ LightStage::INVALID_INDEX }; indexed_container::Index _shadowIndex{ LightStage::INVALID_INDEX }; diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index e7c4c3909b..6ad89275c4 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -181,10 +181,12 @@ public: DEFINE_PROPERTY_REF_ENUM(PROP_BACKGROUND_MODE, BackgroundMode, backgroundMode, BackgroundMode, BACKGROUND_MODE_INHERIT); DEFINE_PROPERTY_GROUP(Stage, stage, StagePropertyGroup); + DEFINE_PROPERTY_REF_ENUM(PROP_KEY_LIGHT_MODE, KeyLightMode, keyLightMode, uint32_t, (uint32_t)COMPONENT_MODE_ENABLED); + DEFINE_PROPERTY_REF_ENUM(PROP_SKYBOX_MODE, SkyboxMode, skyboxMode, uint32_t, (uint32_t)COMPONENT_MODE_ENABLED); + DEFINE_PROPERTY_REF_ENUM(PROP_AMBIENT_LIGHT_MODE, AmbientLightMode, ambientLightMode, uint32_t, (uint32_t)COMPONENT_MODE_ENABLED); + + // This is the default mode for zone creation DEFINE_PROPERTY_REF_ENUM(PROP_HAZE_MODE, HazeMode, hazeMode, uint32_t, (uint32_t)COMPONENT_MODE_INHERIT); - DEFINE_PROPERTY_REF_ENUM(PROP_KEY_LIGHT_MODE, KeyLightMode, keyLightMode, uint32_t, (uint32_t)COMPONENT_MODE_INHERIT); - DEFINE_PROPERTY_REF_ENUM(PROP_AMBIENT_LIGHT_MODE, AmbientLightMode, ambientLightMode, uint32_t, (uint32_t)COMPONENT_MODE_INHERIT); - DEFINE_PROPERTY_REF_ENUM(PROP_SKYBOX_MODE, SkyboxMode, skyboxMode, uint32_t, (uint32_t)COMPONENT_MODE_INHERIT); DEFINE_PROPERTY_GROUP(Skybox, skybox, SkyboxPropertyGroup); DEFINE_PROPERTY_GROUP(Haze, haze, HazePropertyGroup); diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index bdc5821da6..08bb93c573 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -132,10 +132,13 @@ protected: QString _compoundShapeURL; BackgroundMode _backgroundMode { BACKGROUND_MODE_INHERIT }; - uint32_t _hazeMode { COMPONENT_MODE_INHERIT }; + + // The following 3 values are the defaults for zone creation uint32_t _keyLightMode { COMPONENT_MODE_INHERIT }; - uint32_t _ambientLightMode { COMPONENT_MODE_INHERIT }; uint32_t _skyboxMode { COMPONENT_MODE_INHERIT }; + uint32_t _ambientLightMode { COMPONENT_MODE_INHERIT }; + + uint32_t _hazeMode { COMPONENT_MODE_INHERIT }; SkyboxPropertyGroup _skyboxProperties; HazePropertyGroup _hazeProperties; From e8770ec204231ff3393ecc2cfb9dda448d7046cf Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Thu, 4 Jan 2018 11:30:02 -0800 Subject: [PATCH 37/46] TEMPORARY fix for older content not containing these fields (keylight, skybox, ambient light). --- libraries/entities/src/EntityTree.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 8f780355db..580c4b4482 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -2281,6 +2281,17 @@ bool EntityTree::readFromMap(QVariantMap& map) { properties.setOwningAvatarID(myNodeID); } + // TEMPORARY fix for older content not containing these fields + if (!entityMap.contains("keyLightMode")) { + properties.setKeyLightMode(COMPONENT_MODE_ENABLED); + } + if (!entityMap.contains("skyboxMode")) { + properties.setSkyboxMode(COMPONENT_MODE_ENABLED); + } + if (!entityMap.contains("ambientLightMode")) { + properties.setAmbientLightMode(COMPONENT_MODE_ENABLED); + } + EntityItemPointer entity = addEntity(entityItemID, properties); if (!entity) { qCDebug(entities) << "adding Entity failed:" << entityItemID << properties.getType(); From 8bd2985f1f97f3231e842775efbc05fff5a1811a Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Thu, 4 Jan 2018 13:06:28 -0800 Subject: [PATCH 38/46] Simplified code. --- .../src/RenderableZoneEntityItem.cpp | 50 ++++--------------- .../src/RenderableZoneEntityItem.h | 5 -- .../entities/src/EntityItemProperties.cpp | 29 +---------- libraries/entities/src/EntityItemProperties.h | 5 +- libraries/entities/src/ZoneEntityItem.cpp | 8 +-- 5 files changed, 16 insertions(+), 81 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 0d975759b4..138ecb9f38 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -163,48 +163,23 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { if (_visible) { // Finally, push the light visible in the frame - if (_keyLightMode == COMPONENT_MODE_DISABLED && _sunOnIndex == NO_STORED_VALUE) { - // Just turned off, store previous value before changing - _sunOnIndex = _sunIndex; - _sunIndex = _stage->getSunOffLight(); - } else if (_keyLightMode == COMPONENT_MODE_ENABLED && _sunOnIndex != NO_STORED_VALUE) { - // Just turned on, restore previous value before clearing stored value - _sunIndex = _sunOnIndex; - _sunOnIndex = NO_STORED_VALUE; - } - - if (_keyLightMode != COMPONENT_MODE_INHERIT) { + if (_keyLightMode == COMPONENT_MODE_DISABLED) { + _stage->_currentFrame.pushSunLight(_stage->getSunOffLight()); + } else if (_keyLightMode == COMPONENT_MODE_ENABLED) { _stage->_currentFrame.pushSunLight(_sunIndex); } // The background only if the mode is not inherit - if (_skyboxMode == COMPONENT_MODE_DISABLED && _skyboxOnIndex == NO_STORED_VALUE) { - // Just turned off, store previous value before changing - _skyboxOnIndex = _backgroundIndex; - _backgroundIndex = INVALID_INDEX; - } else if (_skyboxMode == COMPONENT_MODE_ENABLED && _skyboxOnIndex != NO_STORED_VALUE) { - // Just turned on, restore previous value before clearing stored value - _backgroundIndex = _skyboxOnIndex; - _skyboxOnIndex = NO_STORED_VALUE; - } - - // _backgroundMode is kept for legacy purposes - if (_skyboxMode != COMPONENT_MODE_INHERIT || _backgroundMode != BACKGROUND_MODE_INHERIT) { + if (_skyboxMode == COMPONENT_MODE_DISABLED) { + _backgroundStage->_currentFrame.pushBackground(INVALID_INDEX); + } else if (_skyboxMode == COMPONENT_MODE_ENABLED) { _backgroundStage->_currentFrame.pushBackground(_backgroundIndex); } // The ambient light only if it has a valid texture to render with - if (_ambientLightMode == COMPONENT_MODE_DISABLED && _ambientOnIndex == NO_STORED_VALUE) { - // Just turned off, store previous value before changing - _ambientOnIndex = _ambientIndex; - _ambientIndex = _stage->getAmbientOffLight(); - } else if (_ambientLightMode == COMPONENT_MODE_ENABLED && _ambientOnIndex != NO_STORED_VALUE) { - // Just turned on, restore previous value before clearing stored value - _ambientIndex = _ambientOnIndex; - _ambientOnIndex = NO_STORED_VALUE; - } - - if (_ambientLightMode != COMPONENT_MODE_INHERIT && _validAmbientTexture) { + if (_ambientLightMode == COMPONENT_MODE_DISABLED) { + _stage->_currentFrame.pushAmbientLight(_stage->getAmbientOffLight()); + } else if (_ambientLightMode == COMPONENT_MODE_ENABLED) { _stage->_currentFrame.pushAmbientLight(_ambientIndex); } @@ -222,11 +197,6 @@ void ZoneEntityRenderer::removeFromScene(const ScenePointer& scene, Transaction& } #endif Parent::removeFromScene(scene, transaction); - - // clear flags - _sunOnIndex = NO_STORED_VALUE; - _ambientOnIndex = NO_STORED_VALUE; - _skyboxOnIndex = NO_STORED_VALUE; } void ZoneEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) { @@ -276,7 +246,7 @@ void ZoneEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scen updateKeySunFromEntity(entity); } - if (ambientLightChanged || skyboxChanged) { + if (ambientLightChanged) { updateAmbientLightFromEntity(entity); } diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index 150b06d912..37b40e01b6 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -100,11 +100,6 @@ private: indexed_container::Index _shadowIndex{ LightStage::INVALID_INDEX }; indexed_container::Index _ambientIndex{ LightStage::INVALID_INDEX }; - const int NO_STORED_VALUE { -1 }; - indexed_container::Index _sunOnIndex { NO_STORED_VALUE }; - indexed_container::Index _ambientOnIndex { NO_STORED_VALUE }; - indexed_container::Index _skyboxOnIndex { NO_STORED_VALUE }; - BackgroundStagePointer _backgroundStage; BackgroundStage::Index _backgroundIndex{ BackgroundStage::INVALID_INDEX }; diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index d5a58c9580..0a53f96a59 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -224,7 +224,7 @@ QString EntityItemProperties::getHazeModeAsString() const { } } -QString EntityItemProperties::getHazeModeString(uint32_t mode) { +QString EntityItemProperties::getComponentModeString(uint32_t mode) { // return "inherit" if mode is not valid if (mode < COMPONENT_MODE_ITEM_COUNT) { return COMPONENT_MODES[mode].second; @@ -253,15 +253,6 @@ QString EntityItemProperties::getKeyLightModeAsString() const { } } -QString EntityItemProperties::getKeyLightModeString(uint32_t mode) { - // return "enabled" if mode is not valid - if (mode < COMPONENT_MODE_ITEM_COUNT) { - return COMPONENT_MODES[mode].second; - } else { - return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; - } -} - void EntityItemProperties::setKeyLightModeFromString(const QString& keyLightMode) { auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { return (pair.second == keyLightMode); @@ -282,15 +273,6 @@ QString EntityItemProperties::getAmbientLightModeAsString() const { } } -QString EntityItemProperties::getAmbientLightModeString(uint32_t mode) { - // return "enabled" if mode is not valid - if (mode < COMPONENT_MODE_ITEM_COUNT) { - return COMPONENT_MODES[mode].second; - } else { - return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; - } -} - void EntityItemProperties::setAmbientLightModeFromString(const QString& ambientLightMode) { auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { return (pair.second == ambientLightMode); @@ -311,15 +293,6 @@ QString EntityItemProperties::getSkyboxModeAsString() const { } } -QString EntityItemProperties::getSkyboxModeString(uint32_t mode) { - // return "enabled" if mode is not valid - if (mode < COMPONENT_MODE_ITEM_COUNT) { - return COMPONENT_MODES[mode].second; - } else { - return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; - } -} - void EntityItemProperties::setSkyboxModeFromString(const QString& skyboxMode) { auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { return (pair.second == skyboxMode); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 6ad89275c4..587b9189a1 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -255,10 +255,7 @@ public: DEFINE_PROPERTY_REF(PROP_SERVER_SCRIPTS, ServerScripts, serverScripts, QString, ENTITY_ITEM_DEFAULT_SERVER_SCRIPTS); static QString getBackgroundModeString(BackgroundMode mode); - static QString getHazeModeString(uint32_t mode); - static QString getKeyLightModeString(uint32_t mode); - static QString getAmbientLightModeString(uint32_t mode); - static QString getSkyboxModeString(uint32_t mode); + static QString getComponentModeString(uint32_t mode); public: float getMaxDimension() const { return glm::compMax(_dimensions); } diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp index 32db157b5e..87b417588d 100644 --- a/libraries/entities/src/ZoneEntityItem.cpp +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -290,10 +290,10 @@ void ZoneEntityItem::debugDump() const { qCDebug(entities) << " dimensions:" << debugTreeVector(getScaledDimensions()); qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); qCDebug(entities) << " _backgroundMode:" << EntityItemProperties::getBackgroundModeString(_backgroundMode); - qCDebug(entities) << " _hazeMode:" << EntityItemProperties::getHazeModeString(_hazeMode); - qCDebug(entities) << " _keyLightMode:" << EntityItemProperties::getKeyLightModeString(_keyLightMode); - qCDebug(entities) << " _ambientLightMode:" << EntityItemProperties::getAmbientLightModeString(_ambientLightMode); - qCDebug(entities) << " _skyboxMode:" << EntityItemProperties::getSkyboxModeString(_skyboxMode); + qCDebug(entities) << " _hazeMode:" << EntityItemProperties::getComponentModeString(_hazeMode); + qCDebug(entities) << " _keyLightMode:" << EntityItemProperties::getComponentModeString(_keyLightMode); + qCDebug(entities) << " _ambientLightMode:" << EntityItemProperties::getComponentModeString(_ambientLightMode); + qCDebug(entities) << " _skyboxMode:" << EntityItemProperties::getComponentModeString(_skyboxMode); _keyLightProperties.debugDump(); _ambientLightProperties.debugDump(); From 1e2413bade0550036ab51a5d24c74e93c824df7e Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Thu, 4 Jan 2018 16:01:22 -0800 Subject: [PATCH 39/46] Removed unneeded file. --- interface/resources/qml/js/Utils.jsc | Bin 6516 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 interface/resources/qml/js/Utils.jsc diff --git a/interface/resources/qml/js/Utils.jsc b/interface/resources/qml/js/Utils.jsc deleted file mode 100644 index dec1adb6f865f057bee2a149c2f75b38999f104d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6516 zcmcIoUu;`v75^pIE$JA$?grI>!GgGms+6Xks;Qcgh$~04#kCaHG_+`>$r6WVijypL zsuXP~Ra&U=q8U_82JzsB3R!3ZKlH&0L-Mr1`T(q*BGyS2MAJY{6(P^?5LFXKzweLl zy|%BDXywbp%{|}w&fniT=evI4{L#^|k>toD06O>V!pnF6m>li^4(@P%GC1u72ktf z$kV>Bb^>=gfsZN*FfhNA zIIsBS`vj)cJLCFoBt?wL!&qM+?g5;4X?p@=;so_QhYLs|j&mw6-@5zOH^^x!NeFpdfI2zm5k7ULMfDB|eBtniA~%nHgm^xy>~Fo_;KFWydy zj7{Pk4hae&{}seBC2YJP{5db|oxa*zNE1HjF2>j z34s*uO=3pyF>lWcPG_Brr2Y|E+~~Jc@l89GsMx8wa`g9d|D#$o^_N(Byem@F2SUpP zSu_=}qKhkCp~br$=H-9YYPDEuyeqP}(H&xsLu6U=+o=yjwO5aI0FlL&?!NS3uy`V-a-GvR+09{mcmwX znOY?G73y<4Dm~wD%cjRZvL9%cO^1DC-x10@vK{UwyMH6{=CRwcq{;4uX4#IHO|qY9 zmhD8aNw!7VbwouMH~NVlJ3Uvn(}{|mj&DX5SNgyAro*%TZmm|6klHa`*)&_@HJ08N zOFz?94Vl5?!D`6d8@7sW+M|+IaMQXaEgwto3%zyxuz=&@M)xvXnoLu^5dx2>q~^9_ zysM&^4ZRh%R?uyL|CE@eXgX|ViMkuKHf$B888_uyLB8GAh%7C$qX=^bdp&Ucu})NL z6**rO`6d+{jIC5KyP`g5b1}NOF|&j0V(0ngwdntrUpgt$#!=>z-%O`;SmZZUdqIXkOZN)_$2$R--)0C}*OCl@ zg8eo^@DmMtuU1{W?#lAUT&Z^zFRyDNy$!|7&k|Q>#b8P-9M}5-nmUX z6|dN-MA=Twt+gHc`-JLNL*LyTRTIrg+Wu&|Gm`EdrpZ|k=`2YZ4{3&^D<0B3Negb$ z0v(Q~E?M)uaft3Ml`L?^aAT%%gP(5PINP|9RU5;N8!T9!I3+jO<@qTg@t{)2oCU+W zTuPpDQ5|~0RanwsS8Yi{ReABWG*A-Cl0d^Gp&|)1ND?+#2+{fkb()CkIsJ`yme&IG zDQsn(kvbkRrz(Bv0qa`m;yun9^YVkz%>x5gZk?Y=p*QY5EN*LuR2Pgc*;X!8d$k~L zZ?5Z{9RTbjWy-v{&JQ{E{+y<0rI}tb+^CvEw<5(~{G98o@)@ut!|*9?n#>oBl@(8T!oq z@@%bh8=m#PqGNsfmd6Elr`Pn=BF{@2Q*6x!N4Drbj&iG zemOa!OO3_&xE4olno_Zklq0FWlD*Vd;=!yu$X|{;Q}&-qW7ZpQQKxR zrJ)AbZ}R9b>lLq$vaKC>-+T1S>S$J#(OT6!wd%pry6y`MU)JR^zX3g#A5@m-L>i(O zH|U$1Tx)hZQMS|ZO4SU`HQ)T-_Kq(-zlO#9s+xOWs@SP`*-jb}jb@IBRX^MbL>=RrX+YW(th#e0XSW*DdQ~3| z9(KR`D}Nmlxc5Ry509jk^&cMDR>R}BPOGleTeU`=7*SX2fYn+Ctc<^wOe-x>M~gEM zGI~T*&1b9Ls&X{#bQu1m-C)M3;H9Y51OR-GY+KOQ=IwM3b2eVg_}$6m$W zaQXH_$NQ?e6&cOzO?i9KD){HE&?;{~?Wm8t%{n>?DsP+A@_Lh&0jub*rPxZ#*BmVl zI*KlI+`C`sc!NdjdsV8Mr{8t=SpFWNJB~N)`okhGnt~o9d{I9NZ2!B0ZJY<|U+nX$ cHQ%<=i8VVNFIUarOZEOd?D=Kp&$U|ZfBbNDS^xk5 From adbc4d0c395bdb13cb7efa0794e164803355a039 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Thu, 4 Jan 2018 18:23:25 -0800 Subject: [PATCH 40/46] Removed background mode from code (still in the protocol). --- .../src/RenderableZoneEntityItem.cpp | 1 - libraries/entities/src/ZoneEntityItem.cpp | 4 - libraries/entities/src/ZoneEntityItem.h | 3 - .../src/SceneScriptingInterface.cpp | 153 ++++++++++++++++ .../src/SceneScriptingInterface.h | 166 ++++++++++++++++++ 5 files changed, 319 insertions(+), 8 deletions(-) create mode 100644 libraries/script-engine/src/SceneScriptingInterface.cpp create mode 100644 libraries/script-engine/src/SceneScriptingInterface.h diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 138ecb9f38..8cc4a0194f 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -385,7 +385,6 @@ void ZoneEntityRenderer::updateKeyBackgroundFromEntity(const TypedEntityPointer& setSkyboxMode((ComponentMode)entity->getSkyboxMode()); editBackground(); - setBackgroundMode(entity->getBackgroundMode()); setSkyboxColor(_skyboxProperties.getColorVec3()); setProceduralUserData(entity->getUserData()); setSkyboxURL(_skyboxProperties.getURL()); diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp index 87b417588d..f2fb480353 100644 --- a/libraries/entities/src/ZoneEntityItem.cpp +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -62,7 +62,6 @@ EntityItemProperties ZoneEntityItem::getProperties(EntityPropertyFlags desiredPr COPY_ENTITY_PROPERTY_TO_PROPERTIES(shapeType, getShapeType); COPY_ENTITY_PROPERTY_TO_PROPERTIES(compoundShapeURL, getCompoundShapeURL); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(backgroundMode, getBackgroundMode); // Contains a QString property, must be synchronized withReadLock([&] { @@ -116,7 +115,6 @@ bool ZoneEntityItem::setSubClassProperties(const EntityItemProperties& propertie SET_ENTITY_PROPERTY_FROM_PROPERTIES(shapeType, setShapeType); SET_ENTITY_PROPERTY_FROM_PROPERTIES(compoundShapeURL, setCompoundShapeURL); - SET_ENTITY_PROPERTY_FROM_PROPERTIES(backgroundMode, setBackgroundMode); // Contains a QString property, must be synchronized withWriteLock([&] { @@ -175,7 +173,6 @@ int ZoneEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, READ_ENTITY_PROPERTY(PROP_SHAPE_TYPE, ShapeType, setShapeType); READ_ENTITY_PROPERTY(PROP_COMPOUND_SHAPE_URL, QString, setCompoundShapeURL); - READ_ENTITY_PROPERTY(PROP_BACKGROUND_MODE, BackgroundMode, setBackgroundMode); int bytesFromSkybox; withWriteLock([&] { @@ -265,7 +262,6 @@ void ZoneEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits APPEND_ENTITY_PROPERTY(PROP_SHAPE_TYPE, (uint32_t)getShapeType()); APPEND_ENTITY_PROPERTY(PROP_COMPOUND_SHAPE_URL, getCompoundShapeURL()); - APPEND_ENTITY_PROPERTY(PROP_BACKGROUND_MODE, (uint32_t)getBackgroundMode()); // could this be a uint16?? _skyboxProperties.appendSubclassData(packetData, params, modelTreeElementExtraEncodeData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState); diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index 08bb93c573..aca7a0fd1b 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -69,9 +69,6 @@ public: KeyLightPropertyGroup getKeyLightProperties() const { return resultWithReadLock([&] { return _keyLightProperties; }); } AmbientLightPropertyGroup getAmbientLightProperties() const { return resultWithReadLock([&] { return _ambientLightProperties; }); } - void setBackgroundMode(BackgroundMode value) { _backgroundMode = value; _backgroundPropertiesChanged = true; } - BackgroundMode getBackgroundMode() const { return _backgroundMode; } - void setHazeMode(const uint32_t value); uint32_t getHazeMode() const; diff --git a/libraries/script-engine/src/SceneScriptingInterface.cpp b/libraries/script-engine/src/SceneScriptingInterface.cpp new file mode 100644 index 0000000000..3883b948df --- /dev/null +++ b/libraries/script-engine/src/SceneScriptingInterface.cpp @@ -0,0 +1,153 @@ +// +// SceneScriptingInterface.cpp +// libraries/script-engine +// +// Created by Sam Gateau on 2/24/15. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "SceneScriptingInterface.h" + +#include + +float SceneScripting::Location::getLongitude() const { + return _skyStage->getOriginLongitude(); +} + +float SceneScripting::Location::getLatitude() const { + return _skyStage->getOriginLatitude(); +} + +float SceneScripting::Location::getAltitude() const { + return _skyStage->getOriginSurfaceAltitude(); +} + +void SceneScripting::Location::setLongitude(float longitude) { + _skyStage->setOriginLongitude(longitude); +} + +void SceneScripting::Location::setLatitude(float latitude) { + _skyStage->setOriginLatitude(latitude); +} + +void SceneScripting::Location::setAltitude(float altitude) { + _skyStage->setOriginSurfaceAltitude(altitude); +} + +void SceneScripting::Time::setHour(float hour) { + _skyStage->setDayTime(hour); +} + +float SceneScripting::Time::getHour() const { + return _skyStage->getDayTime(); +} + +void SceneScripting::Time::setDay(int day) { + _skyStage->setYearTime(day); +} + +int SceneScripting::Time::getDay() const { + return _skyStage->getYearTime(); +} + +glm::vec3 SceneScripting::KeyLight::getColor() const { + return _skyStage->getSunColor(); +} + +void SceneScripting::KeyLight::setColor(const glm::vec3& color) { + _skyStage->setSunColor(color); +} + +float SceneScripting::KeyLight::getIntensity() const { + return _skyStage->getSunIntensity(); +} + +void SceneScripting::KeyLight::setIntensity(float intensity) { + _skyStage->setSunIntensity(intensity); +} + +float SceneScripting::KeyLight::getAmbientIntensity() const { + return _skyStage->getSunAmbientIntensity(); +} + +void SceneScripting::KeyLight::setAmbientIntensity(float intensity) { + _skyStage->setSunAmbientIntensity(intensity); +} + +void SceneScripting::KeyLight::setAmbientSphere(const gpu::SHPointer& sphere) { + _skyStage->setSunAmbientSphere(sphere); +} + +void SceneScripting::KeyLight::setAmbientMap(const gpu::TexturePointer& map) { + _skyStage->setSunAmbientMap(map); +} + + +glm::vec3 SceneScripting::KeyLight::getDirection() const { + return _skyStage->getSunDirection(); +} + +void SceneScripting::KeyLight::setDirection(const glm::vec3& direction) { + _skyStage->setSunDirection(direction); +} + +void SceneScripting::Stage::setOrientation(const glm::quat& orientation) const { + _skyStage->setOriginOrientation(orientation); +} + +void SceneScripting::Stage::setLocation(float longitude, float latitude, float altitude) { + _skyStage->setOriginLocation(longitude, latitude, altitude); +} + +void SceneScripting::Stage::setSunModelEnable(bool isEnabled) { + _skyStage->setSunModelEnable(isEnabled); +} + +bool SceneScripting::Stage::isSunModelEnabled() const { + return _skyStage->isSunModelEnabled(); +} + +void SceneScripting::Stage::setBackgroundMode(const QString& mode) { + if (mode == QString("inherit")) { + _skyStage->setBackgroundMode(model::SunSkyStage::NO_BACKGROUND); + } else if (mode == QString("skybox")) { + _skyStage->setBackgroundMode(model::SunSkyStage::SKY_BOX); + } +} + +QString SceneScripting::Stage::getBackgroundMode() const { + switch (_skyStage->getBackgroundMode()) { + case model::SunSkyStage::NO_BACKGROUND: + return QString("inherit"); + case model::SunSkyStage::SKY_BOX: + return QString("skybox"); + default: + return QString("inherit"); + }; +} + +SceneScriptingInterface::SceneScriptingInterface() : _stage{ new SceneScripting::Stage{ _skyStage } } { + // Let's make sure the sunSkyStage is using a proceduralSkybox + _skyStage->setSkybox(model::SkyboxPointer(new ProceduralSkybox())); +} + +void SceneScriptingInterface::setShouldRenderAvatars(bool shouldRenderAvatars) { + if (shouldRenderAvatars != _shouldRenderAvatars) { + _shouldRenderAvatars = shouldRenderAvatars; + emit shouldRenderAvatarsChanged(_shouldRenderAvatars); + } +} + +void SceneScriptingInterface::setShouldRenderEntities(bool shouldRenderEntities) { + if (shouldRenderEntities != _shouldRenderEntities) { + _shouldRenderEntities = shouldRenderEntities; + emit shouldRenderEntitiesChanged(_shouldRenderEntities); + } +} + +model::SunSkyStagePointer SceneScriptingInterface::getSkyStage() const { + return _skyStage; +} diff --git a/libraries/script-engine/src/SceneScriptingInterface.h b/libraries/script-engine/src/SceneScriptingInterface.h new file mode 100644 index 0000000000..7bc22eb3e6 --- /dev/null +++ b/libraries/script-engine/src/SceneScriptingInterface.h @@ -0,0 +1,166 @@ +// +// SceneScriptingInterface.h +// libraries/script-engine +// +// Created by Sam Gateau on 2/24/15. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_SceneScriptingInterface_h +#define hifi_SceneScriptingInterface_h + +#include // QObject +#include // Dependency + +#include "model/Stage.h" + +// TODO: if QT moc ever supports nested classes, subclass these to the interface instead of namespacing +namespace SceneScripting { + class Location : public QObject { + Q_OBJECT + + public: + Location(model::SunSkyStagePointer skyStage) : _skyStage{ skyStage } {} + + Q_PROPERTY(float longitude READ getLongitude WRITE setLongitude) + Q_PROPERTY(float latitude READ getLatitude WRITE setLatitude) + Q_PROPERTY(float altitude READ getAltitude WRITE setAltitude) + + float getLongitude() const; + float getLatitude() const; + float getAltitude() const; + void setLongitude(float longitude); + void setLatitude(float latitude); + void setAltitude(float altitude); + + protected: + model::SunSkyStagePointer _skyStage; + }; + using LocationPointer = std::unique_ptr; + + class Time : public QObject { + Q_OBJECT + + public: + Time(model::SunSkyStagePointer skyStage) : _skyStage{ skyStage } {} + + Q_PROPERTY(float hour READ getHour WRITE setHour) + Q_PROPERTY(int day READ getDay WRITE setDay) + + float getHour() const; + void setHour(float hour); + int getDay() const; + void setDay(int day); + + protected: + model::SunSkyStagePointer _skyStage; + }; + using TimePointer = std::unique_ptr @@ -17,9 +17,9 @@ - 190 - 300 - 220 + 60 + 360 + 160 40 @@ -30,9 +30,9 @@ - 360 - 130 - 220 + 60 + 270 + 160 40 @@ -43,9 +43,9 @@ - 20 - 75 - 220 + 60 + 20 + 160 40 @@ -56,9 +56,9 @@ - 360 - 75 - 220 + 60 + 210 + 160 40 @@ -69,9 +69,9 @@ - 20 - 130 - 220 + 60 + 75 + 160 40 @@ -79,55 +79,13 @@ Evaluate Tests Recursively - - - - 23 - 40 - 131 - 20 - - - - <html><head/><body><p>If unchecked, will not show results during evaluation</p></body></html> - - - Interactive Mode - - - - - - 20 - 190 - 255 - 23 - - - - 24 - - - - - - 360 - 240 - 220 - 40 - - - - Delete Old Snapshots - - 0 0 - 607 + 286 21 diff --git a/tools/auto-tester/src/ui/MismatchWindow.cpp b/tools/auto-tester/src/ui/MismatchWindow.cpp index fe22412522..07664a1667 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.cpp +++ b/tools/auto-tester/src/ui/MismatchWindow.cpp @@ -11,48 +11,11 @@ #include -#include - MismatchWindow::MismatchWindow(QWidget *parent) : QDialog(parent) { setupUi(this); expectedImage->setScaledContents(true); resultImage->setScaledContents(true); - diffImage->setScaledContents(true); -} - -QPixmap MismatchWindow::computeDiffPixmap(QImage expectedImage, QImage resultImage) { - // This is an optimization, as QImage.setPixel() is embarrassingly slow - unsigned char* buffer = new unsigned char[expectedImage.height() * expectedImage.width() * 3]; - - // loop over each pixel - for (int y = 0; y < expectedImage.height(); ++y) { - for (int x = 0; x < expectedImage.width(); ++x) { - QRgb pixelP = expectedImage.pixel(QPoint(x, y)); - QRgb pixelQ = resultImage.pixel(QPoint(x, y)); - - // Convert to luminance - double p = R_Y * qRed(pixelP) + G_Y * qGreen(pixelP) + B_Y * qBlue(pixelP); - double q = R_Y * qRed(pixelQ) + G_Y * qGreen(pixelQ) + B_Y * qBlue(pixelQ); - - // The intensity value is modified to increase the brightness of the displayed image - double absoluteDifference = fabs(p - q) / 255.0; - double modifiedDifference = sqrt(absoluteDifference); - - int difference = (int)(modifiedDifference * 255.0); - - buffer[3 * (x + y * expectedImage.width()) + 0] = difference; - buffer[3 * (x + y * expectedImage.width()) + 1] = difference; - buffer[3 * (x + y * expectedImage.width()) + 2] = difference; - } - } - - QImage diffImage(buffer, expectedImage.width(), expectedImage.height(), QImage::Format_RGB888); - QPixmap resultPixmap = QPixmap::fromImage(diffImage); - - delete[] buffer; - - return resultPixmap; } void MismatchWindow::setTestFailure(TestFailure testFailure) { @@ -61,19 +24,10 @@ void MismatchWindow::setTestFailure(TestFailure testFailure) { imagePath->setText("Path to test: " + testFailure._pathname); expectedFilename->setText(testFailure._expectedImageFilename); + expectedImage->setPixmap(QPixmap(testFailure._pathname + testFailure._expectedImageFilename)); + resultFilename->setText(testFailure._actualImageFilename); - - QPixmap expectedPixmap = QPixmap(testFailure._pathname + testFailure._expectedImageFilename); - QPixmap actualPixmap = QPixmap(testFailure._pathname + testFailure._actualImageFilename); - - diffPixmap = computeDiffPixmap( - QImage(testFailure._pathname + testFailure._expectedImageFilename), - QImage(testFailure._pathname + testFailure._actualImageFilename) - ); - - expectedImage->setPixmap(expectedPixmap); - resultImage->setPixmap(actualPixmap); - diffImage->setPixmap(diffPixmap); + resultImage->setPixmap(QPixmap(testFailure._pathname + testFailure._actualImageFilename)); } void MismatchWindow::on_passTestButton_clicked() { @@ -90,7 +44,3 @@ void MismatchWindow::on_abortTestsButton_clicked() { _userResponse = USER_RESPONSE_ABORT; close(); } - -QPixmap MismatchWindow::getComparisonImage() { - return diffPixmap; -} \ No newline at end of file diff --git a/tools/auto-tester/src/ui/MismatchWindow.h b/tools/auto-tester/src/ui/MismatchWindow.h index ad8be16580..7c72b7b0b7 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.h +++ b/tools/auto-tester/src/ui/MismatchWindow.h @@ -25,9 +25,6 @@ public: UserResponse getUserResponse() { return _userResponse; } - QPixmap computeDiffPixmap(QImage expectedImage, QImage resultImage); - QPixmap getComparisonImage(); - private slots: void on_passTestButton_clicked(); void on_failTestButton_clicked(); @@ -35,8 +32,6 @@ private slots: private: UserResponse _userResponse{ USER_RESPONSE_INVALID }; - - QPixmap diffPixmap; }; diff --git a/tools/auto-tester/src/ui/MismatchWindow.ui b/tools/auto-tester/src/ui/MismatchWindow.ui index 5ecf966df5..cab6c61e1c 100644 --- a/tools/auto-tester/src/ui/MismatchWindow.ui +++ b/tools/auto-tester/src/ui/MismatchWindow.ui @@ -6,8 +6,8 @@ 0 0 - 1782 - 942 + 1585 + 694 @@ -16,10 +16,10 @@ - 10 - 25 - 800 - 450 + 20 + 170 + 720 + 362 @@ -29,41 +29,28 @@ - 900 - 25 - 800 - 450 + 760 + 170 + 720 + 362 result image - - - - 540 - 480 - 800 - 450 - - - - diff image - - - 60 - 660 - 480 + 760 + 90 + 800 28 - 12 + 16 @@ -73,15 +60,15 @@ - 60 - 630 - 480 + 40 + 90 + 700 28 - 12 + 16 @@ -91,15 +78,15 @@ - 20 - 600 + 40 + 30 1200 28 - 12 + 16 @@ -110,7 +97,7 @@ 30 - 790 + 600 75 23 @@ -122,8 +109,8 @@ - 120 - 790 + 330 + 600 75 23 @@ -135,60 +122,34 @@ - 210 - 790 - 121 + 630 + 600 + 75 23 - Abort current test + Abort Tests - 30 - 850 - 500 + 810 + 600 + 720 28 - 12 + 16 similarity - - - - 30 - 5 - 151 - 16 - - - - Expected Image - - - - - - 930 - 5 - 151 - 16 - - - - Actual Image - - From 3963c0a5a183d8cb0e1f8e4880b60c2b19dd749a Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 5 Jan 2018 12:22:20 -0800 Subject: [PATCH 44/46] Code review improvements. --- .../entities/src/EntityItemProperties.cpp | 63 +++++++------------ libraries/entities/src/EntityItemProperties.h | 11 ++++ libraries/entities/src/EntityTree.cpp | 30 ++++----- 3 files changed, 49 insertions(+), 55 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 0a53f96a59..76a591f20a 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -208,20 +208,18 @@ void EntityItemProperties::setBackgroundModeFromString(const QString& background } } -using ComponentPair = std::pair; -const std::array COMPONENT_MODES = { { - ComponentPair{ COMPONENT_MODE_INHERIT,{ "inherit" } }, - ComponentPair{ COMPONENT_MODE_DISABLED,{ "disabled" } }, - ComponentPair{ COMPONENT_MODE_ENABLED,{ "enabled" } } -} }; - -QString EntityItemProperties::getHazeModeAsString() const { - // return "inherit" if _hazeMode is not valid - if (_hazeMode < COMPONENT_MODE_ITEM_COUNT) { - return COMPONENT_MODES[_hazeMode].second; +QString EntityItemProperties::getComponentModeAsString(uint32_t mode) { + // return "inherit" if mode is not valid + if (mode < COMPONENT_MODE_ITEM_COUNT) { + return COMPONENT_MODES[mode].second; } else { return COMPONENT_MODES[COMPONENT_MODE_INHERIT].second; } + +} + +QString EntityItemProperties::getHazeModeAsString() const { + return getComponentModeAsString(_hazeMode); } QString EntityItemProperties::getComponentModeString(uint32_t mode) { @@ -233,10 +231,14 @@ QString EntityItemProperties::getComponentModeString(uint32_t mode) { } } -void EntityItemProperties::setHazeModeFromString(const QString& hazeMode) { - auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { - return (pair.second == hazeMode); +const auto EntityItemProperties::findComponent(const QString& mode) { + return std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { + return (pair.second == mode); }); +} + +void EntityItemProperties::setHazeModeFromString(const QString& hazeMode) { + auto result = findComponent(hazeMode); if (result != COMPONENT_MODES.end()) { _hazeMode = result->first; @@ -245,18 +247,11 @@ void EntityItemProperties::setHazeModeFromString(const QString& hazeMode) { } QString EntityItemProperties::getKeyLightModeAsString() const { - // return "enabled" if _keyLightMode is not valid - if (_keyLightMode < COMPONENT_MODE_ITEM_COUNT) { - return COMPONENT_MODES[_keyLightMode].second; - } else { - return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; - } + return getComponentModeAsString(_keyLightMode); } void EntityItemProperties::setKeyLightModeFromString(const QString& keyLightMode) { - auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { - return (pair.second == keyLightMode); - }); + auto result = findComponent(keyLightMode); if (result != COMPONENT_MODES.end()) { _keyLightMode = result->first; @@ -265,18 +260,11 @@ void EntityItemProperties::setKeyLightModeFromString(const QString& keyLightMode } QString EntityItemProperties::getAmbientLightModeAsString() const { - // return "enabled" if _ambientLightMode is not valid - if (_ambientLightMode < COMPONENT_MODE_ITEM_COUNT) { - return COMPONENT_MODES[_ambientLightMode].second; - } else { - return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; - } + return getComponentModeAsString(_ambientLightMode); } void EntityItemProperties::setAmbientLightModeFromString(const QString& ambientLightMode) { - auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { - return (pair.second == ambientLightMode); - }); + auto result = findComponent(ambientLightMode); if (result != COMPONENT_MODES.end()) { _ambientLightMode = result->first; @@ -285,18 +273,11 @@ void EntityItemProperties::setAmbientLightModeFromString(const QString& ambientL } QString EntityItemProperties::getSkyboxModeAsString() const { - // return "enabled" if _skyboxMode is not valid - if (_skyboxMode < COMPONENT_MODE_ITEM_COUNT) { - return COMPONENT_MODES[_skyboxMode].second; - } else { - return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; - } + return getComponentModeAsString(_skyboxMode); } void EntityItemProperties::setSkyboxModeFromString(const QString& skyboxMode) { - auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { - return (pair.second == skyboxMode); - }); + auto result = findComponent(skyboxMode); if (result != COMPONENT_MODES.end()) { _skyboxMode = result->first; diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 587b9189a1..467a89166c 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -47,6 +47,13 @@ const quint64 UNKNOWN_CREATED_TIME = 0; +using ComponentPair = std::pair; +const std::array COMPONENT_MODES = { { + ComponentPair { COMPONENT_MODE_INHERIT, { "inherit" } }, + ComponentPair { COMPONENT_MODE_DISABLED, { "disabled" } }, + ComponentPair { COMPONENT_MODE_ENABLED, { "enabled" } } +} }; + /// A collection of properties of an entity item used in the scripting API. Translates between the actual properties of an /// entity and a JavaScript style hash/QScriptValue storing a set of properties. Used in scripting to set/get the complete /// set of entity item properties via JavaScript hashes/QScriptValues @@ -255,7 +262,11 @@ public: DEFINE_PROPERTY_REF(PROP_SERVER_SCRIPTS, ServerScripts, serverScripts, QString, ENTITY_ITEM_DEFAULT_SERVER_SCRIPTS); static QString getBackgroundModeString(BackgroundMode mode); + static QString getComponentModeString(uint32_t mode); + static QString getComponentModeAsString(uint32_t mode); + + const auto findComponent(const QString& mode); public: float getMaxDimension() const { return glm::compMax(_dimensions); } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index ff1b65db15..a0eaefd43e 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -2281,22 +2281,24 @@ bool EntityTree::readFromMap(QVariantMap& map) { properties.setOwningAvatarID(myNodeID); } - // TEMPORARY fix for older content not containing these fields - if (!entityMap.contains("keyLightMode")) { - properties.setKeyLightMode(COMPONENT_MODE_ENABLED); - } - - if (!entityMap.contains("skyboxMode")) { - if (entityMap.contains("backgroundMode") && properties.getBackgroundModeAsString() == "inherit") { - // The content creator has set the combo to NOTHING - this is actually inherit - properties.setSkyboxMode(COMPONENT_MODE_INHERIT); - } else { - properties.setSkyboxMode(COMPONENT_MODE_ENABLED); + // TEMPORARY fix for older content not containing these fields in the zones + if (properties.getType() == EntityTypes::EntityType::Zone) { + if (!entityMap.contains("keyLightMode")) { + properties.setKeyLightMode(COMPONENT_MODE_ENABLED); } - } - if (!entityMap.contains("ambientLightMode")) { - properties.setAmbientLightMode(COMPONENT_MODE_ENABLED); + if (!entityMap.contains("skyboxMode")) { + if (entityMap.contains("backgroundMode") && properties.getBackgroundModeAsString() == "inherit") { + // The content creator has set the combo to NOTHING - this is actually inherit + properties.setSkyboxMode(COMPONENT_MODE_INHERIT); + } else { + properties.setSkyboxMode(COMPONENT_MODE_ENABLED); + } + } + + if (!entityMap.contains("ambientLightMode")) { + properties.setAmbientLightMode(COMPONENT_MODE_ENABLED); + } } EntityItemPointer entity = addEntity(entityItemID, properties); From 635fd2d0cf84687248ddf58f50c0fe6622274d7b Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 5 Jan 2018 12:48:21 -0800 Subject: [PATCH 45/46] Use older C++ version for Ubuntu --- libraries/entities/src/EntityItemProperties.cpp | 2 +- libraries/entities/src/EntityItemProperties.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 76a591f20a..90470adcf0 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -231,7 +231,7 @@ QString EntityItemProperties::getComponentModeString(uint32_t mode) { } } -const auto EntityItemProperties::findComponent(const QString& mode) { +const std::array::const_iterator EntityItemProperties::findComponent(const QString& mode) { return std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { return (pair.second == mode); }); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 467a89166c..5a210e54ce 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -266,7 +266,7 @@ public: static QString getComponentModeString(uint32_t mode); static QString getComponentModeAsString(uint32_t mode); - const auto findComponent(const QString& mode); + const std::array::const_iterator findComponent(const QString& mode); public: float getMaxDimension() const { return glm::compMax(_dimensions); } From d6451632949858defb4a1b8dd492e2ecbfce07b0 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Fri, 5 Jan 2018 13:16:02 -0800 Subject: [PATCH 46/46] Fixed gcc warning. --- libraries/entities/src/EntityItemProperties.cpp | 2 +- libraries/entities/src/EntityItemProperties.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 90470adcf0..cfbfdd0274 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -231,7 +231,7 @@ QString EntityItemProperties::getComponentModeString(uint32_t mode) { } } -const std::array::const_iterator EntityItemProperties::findComponent(const QString& mode) { +std::array::const_iterator EntityItemProperties::findComponent(const QString& mode) { return std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { return (pair.second == mode); }); diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 5a210e54ce..0240cee44a 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -266,7 +266,7 @@ public: static QString getComponentModeString(uint32_t mode); static QString getComponentModeAsString(uint32_t mode); - const std::array::const_iterator findComponent(const QString& mode); + std::array::const_iterator findComponent(const QString& mode); public: float getMaxDimension() const { return glm::compMax(_dimensions); }