mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-03 17:30:04 -05:00
Merge branch 'master' into feature/launcherconfigs
This commit is contained in:
Binary file not shown.
@@ -4,7 +4,7 @@ return {
|
||||
Parent = "SolarSystem",
|
||||
Renderable = {
|
||||
Type = "RenderableSphere",
|
||||
Size = { 10, 20 },
|
||||
Size = 10E20,
|
||||
Segments = 40,
|
||||
Texture = "textures/eso0932a_blend.png",
|
||||
Orientation = "Inside/Outside"
|
||||
|
||||
@@ -4,7 +4,7 @@ return {
|
||||
Parent = "SolarSystem",
|
||||
Renderable = {
|
||||
Type = "RenderableSphere",
|
||||
Size = { 10, 22 },
|
||||
Size = 10E22,
|
||||
Segments = 40,
|
||||
Texture = "textures/DarkUniverse_mellinger_8k.jpg",
|
||||
Orientation = "Inside/Outside"
|
||||
|
||||
@@ -28,12 +28,19 @@
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/vector/vec4property.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/util/keys.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
} // namespace opengl
|
||||
} // namespace ghoul
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class LuaConsole : public properties::PropertyOwner {
|
||||
@@ -46,7 +53,9 @@ public:
|
||||
bool keyboardCallback(Key key, KeyModifier modifier, KeyAction action);
|
||||
void charCallback(unsigned int codepoint, KeyModifier modifier);
|
||||
|
||||
void update();
|
||||
void render();
|
||||
float currentHeight() const;
|
||||
|
||||
private:
|
||||
void parallelConnectionChanged(const ParallelConnection::Status& status);
|
||||
@@ -55,6 +64,14 @@ private:
|
||||
properties::BoolProperty _isVisible;
|
||||
properties::BoolProperty _remoteScripting;
|
||||
|
||||
properties::Vec4Property _backgroundColor;
|
||||
properties::Vec4Property _highlightColor;
|
||||
properties::Vec4Property _separatorColor;
|
||||
properties::Vec4Property _entryTextColor;
|
||||
properties::Vec4Property _historyTextColor;
|
||||
properties::IntProperty _historyLength;
|
||||
|
||||
|
||||
size_t _inputPosition;
|
||||
std::vector<std::string> _commandsHistory;
|
||||
size_t _activeCommand;
|
||||
@@ -65,6 +82,17 @@ private:
|
||||
bool hasInitialValue;
|
||||
std::string initialValue;
|
||||
} _autoCompleteInfo;
|
||||
|
||||
float _currentHeight;
|
||||
float _targetHeight;
|
||||
float _fullHeight;
|
||||
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _font;
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _historyFont;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _program;
|
||||
GLuint _vao;
|
||||
GLuint _vbo;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/numericalproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
//glm includes
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
@@ -292,6 +292,18 @@ public:
|
||||
*/
|
||||
void setReadOnly(bool state);
|
||||
|
||||
/**
|
||||
* Default view options that can be used in the Property::setViewOption method. The
|
||||
* values are: Property::ViewOptions::Color = <code>color</code>,
|
||||
* Property::ViewOptions::LightPosition = <code>lightPosition</code>,
|
||||
* Property::ViewOptions::PowerScaledScalar = <code>powerScaledScalar</code>, and
|
||||
* Property::ViewOptions::PowerScaledCoordinate = <code>powerScaledCoordinate</code>.
|
||||
*/
|
||||
struct ViewOptions {
|
||||
static const char* Color;
|
||||
static const char* LightPosition;
|
||||
};
|
||||
|
||||
/**
|
||||
* This method allows the developer to give hints to the GUI about different
|
||||
* representations for the GUI. The same Property (for example Vec4Property) can be
|
||||
@@ -307,18 +319,14 @@ public:
|
||||
void setViewOption(std::string option, bool value = true);
|
||||
|
||||
/**
|
||||
* Default view options that can be used in the Property::setViewOption method. The
|
||||
* values are: Property::ViewOptions::Color = <code>color</code>,
|
||||
* Property::ViewOptions::LightPosition = <code>lightPosition</code>,
|
||||
* Property::ViewOptions::PowerScaledScalar = <code>powerScaledScalar</code>, and
|
||||
* Property::ViewOptions::PowerScaledCoordinate = <code>powerScaledCoordinate</code>.
|
||||
* This method returns the state of a \p option hint. See Property::ViewOptions for a
|
||||
* default list of possible options. As these are only hints, the GUI is free to
|
||||
* ignore any suggestion by the developer.
|
||||
* \param option The view option that should be retrieved
|
||||
* \param defaultValue The value that is returned if the \p option was not set
|
||||
* \return The view option's value
|
||||
*/
|
||||
struct ViewOptions {
|
||||
static const char* Color;
|
||||
static const char* LightPosition;
|
||||
static const char* PowerScaledScalar;
|
||||
static const char* PowerScaledCoordinate;
|
||||
};
|
||||
bool viewOption(const std::string& option, bool defaultValue = false) const;
|
||||
|
||||
/**
|
||||
* Returns the metaData that contains all information for external applications to
|
||||
|
||||
@@ -28,20 +28,21 @@
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
// Forward declare to minimize dependencies
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
class Texture;
|
||||
}
|
||||
class Dictionary;
|
||||
}
|
||||
} // namespace ghoul
|
||||
|
||||
namespace openspace {
|
||||
|
||||
struct RenderData;
|
||||
struct UpdateData;
|
||||
struct RendererTasks;
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
// Forward declare to minimize dependencies
|
||||
|
||||
@@ -25,20 +25,13 @@
|
||||
#ifndef __OPENSPACE_CORE___RENDERENGINE___H__
|
||||
#define __OPENSPACE_CORE___RENDERENGINE___H__
|
||||
|
||||
#include <openspace/performance/performancemanager.h>
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/intproperty.h>
|
||||
#include <openspace/properties/triggerproperty.h>
|
||||
|
||||
#include <openspace/rendering/raycastermanager.h>
|
||||
#include <openspace/rendering/renderer.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
|
||||
#include <openspace/util/syncdata.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace fontrendering {
|
||||
@@ -49,17 +42,21 @@ namespace opengl {
|
||||
}
|
||||
class Dictionary;
|
||||
class SharedMemory;
|
||||
}
|
||||
} // namespace ghoul
|
||||
|
||||
namespace openspace {
|
||||
|
||||
// Forward declare to minimize dependencies
|
||||
namespace performance { class PerformanceManager; }
|
||||
namespace scripting { struct LuaLibrary; }
|
||||
class Camera;
|
||||
class SyncBuffer;
|
||||
class RaycasterManager;
|
||||
class Renderer;
|
||||
class Scene;
|
||||
class SceneManager;
|
||||
class ScreenLog;
|
||||
class ScreenSpaceRenderable;
|
||||
class Syncable;
|
||||
class SyncBuffer;
|
||||
|
||||
class RenderEngine : public properties::PropertyOwner {
|
||||
public:
|
||||
@@ -76,7 +73,7 @@ public:
|
||||
};
|
||||
|
||||
RenderEngine();
|
||||
~RenderEngine() = default;
|
||||
~RenderEngine();
|
||||
|
||||
void initialize();
|
||||
void initializeGL();
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
|
||||
// constructors & destructor
|
||||
Scene();
|
||||
~Scene();
|
||||
|
||||
/**
|
||||
* Initalizes the SceneGraph
|
||||
|
||||
@@ -25,16 +25,12 @@
|
||||
#ifndef __OPENSPACE_CORE___SCENEGRAPHNODE___H__
|
||||
#define __OPENSPACE_CORE___SCENEGRAPHNODE___H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/scene/translation.h>
|
||||
#include <openspace/scene/rotation.h>
|
||||
#include <openspace/scene/scale.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/boolean.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -43,6 +39,16 @@ namespace ghoul { class Dictionary; }
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Camera;
|
||||
struct RenderData;
|
||||
class Renderable;
|
||||
struct RendererTasks;
|
||||
class Rotation;
|
||||
class Translation;
|
||||
class Scale;
|
||||
class Scene;
|
||||
struct UpdateData;
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
class SceneGraphNode : public properties::PropertyOwner {
|
||||
|
||||
@@ -75,7 +75,12 @@ public:
|
||||
* have in order to be stored in the ScreenLog
|
||||
*/
|
||||
ScreenLog(std::chrono::seconds timeToLive, LogLevel logLevel = LogLevel::Info);
|
||||
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~ScreenLog();
|
||||
|
||||
/**
|
||||
* Overwritten ghoul::loggling::Log method that is called whenever a new log message
|
||||
* shall be stored.
|
||||
|
||||
@@ -28,7 +28,6 @@ set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/modelgeometry.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/multimodelgeometry.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablemodel.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablepath.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplane.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesphere.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesphericalgrid.h
|
||||
@@ -47,7 +46,6 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/modelgeometry.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/multimodelgeometry.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablemodel.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablepath.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplane.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesphere.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesphericalgrid.cpp
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <modules/base/rendering/renderablemodel.h>
|
||||
#include <modules/base/rendering/renderablepath.h>
|
||||
#include <modules/base/rendering/renderablesphere.h>
|
||||
#include <modules/base/rendering/renderablesphericalgrid.h>
|
||||
#include <modules/base/rendering/renderabletrailorbit.h>
|
||||
@@ -77,7 +76,6 @@ void BaseModule::internalInitialize() {
|
||||
ghoul_assert(fRenderable, "Renderable factory was not created");
|
||||
|
||||
fRenderable->registerClass<RenderableModel>("RenderableModel");
|
||||
fRenderable->registerClass<RenderablePath>("RenderablePath");
|
||||
fRenderable->registerClass<RenderablePlane>("RenderablePlane");
|
||||
fRenderable->registerClass<RenderableSphere>("RenderableSphere");
|
||||
fRenderable->registerClass<RenderableSphericalGrid>("RenderableSphericalGrid");
|
||||
@@ -107,13 +105,15 @@ void BaseModule::internalInitialize() {
|
||||
std::vector<documentation::Documentation> BaseModule::documentations() const {
|
||||
return {
|
||||
RenderableModel::Documentation(),
|
||||
RenderablePlane::Documentation(),
|
||||
RenderableSphere::Documentation(),
|
||||
RenderableTrailOrbit::Documentation(),
|
||||
RenderableTrailTrajectory::Documentation(),
|
||||
ScreenSpaceFramebuffer::Documentation(),
|
||||
ScreenSpaceImage::Documentation(),
|
||||
StaticRotation::Documentation(),
|
||||
StaticScale::Documentation(),
|
||||
StaticTranslation::Documentation(),
|
||||
RenderableTrailOrbit::Documentation(),
|
||||
RenderableTrailTrajectory::Documentation(),
|
||||
modelgeometry::ModelGeometry::Documentation(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -25,20 +25,24 @@
|
||||
#include <modules/base/rendering/modelgeometry.h>
|
||||
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
#include <ghoul/filesystem/cachemanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <ghoul/misc/invariants.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace {
|
||||
const char* _loggerCat = "ModelGeometry";
|
||||
const char* keyGeomModelFile = "GeometryFile";
|
||||
|
||||
const char* KeyName = "Name";
|
||||
const char* KeyType = "Type";
|
||||
const char* KeyGeomModelFile = "GeometryFile";
|
||||
const int8_t CurrentCacheVersion = 3;
|
||||
const char* keyType = "Type";
|
||||
const char* keyName = "Name";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
namespace modelgeometry {
|
||||
@@ -50,13 +54,13 @@ documentation:: Documentation ModelGeometry::Documentation() {
|
||||
"base_geometry_model",
|
||||
{
|
||||
{
|
||||
keyType,
|
||||
KeyType,
|
||||
new StringVerifier,
|
||||
"The type of the Model Geometry that should be generated",
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
keyGeomModelFile,
|
||||
KeyGeomModelFile,
|
||||
new StringVerifier,
|
||||
"The file that should be loaded in this ModelGeometry. The file can "
|
||||
"contain filesystem tokens or can be specified relatively to the "
|
||||
@@ -71,25 +75,18 @@ documentation:: Documentation ModelGeometry::Documentation() {
|
||||
std::unique_ptr<ModelGeometry> ModelGeometry::createFromDictionary(
|
||||
const ghoul::Dictionary& dictionary)
|
||||
{
|
||||
if (!dictionary.hasKeyAndValue<std::string>(keyType)) {
|
||||
if (!dictionary.hasKeyAndValue<std::string>(KeyType)) {
|
||||
throw ghoul::RuntimeError("Dictionary did not contain a key 'Type'");
|
||||
}
|
||||
|
||||
std::string geometryType = dictionary.value<std::string>(keyType);
|
||||
const std::string geometryType = dictionary.value<std::string>(KeyType);
|
||||
|
||||
auto factory = FactoryManager::ref().factory<ModelGeometry>();
|
||||
|
||||
std::unique_ptr<ModelGeometry> result = factory->create(geometryType, dictionary);
|
||||
if (result == nullptr) {
|
||||
throw ghoul::RuntimeError(
|
||||
"Failed to create a ModelGeometry object of type '" + geometryType + "'"
|
||||
);
|
||||
}
|
||||
return result;
|
||||
return factory->create(geometryType, dictionary);;
|
||||
}
|
||||
|
||||
ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary)
|
||||
: properties::PropertyOwner("ModelGeometry")
|
||||
, _parent(nullptr)
|
||||
, _mode(GL_TRIANGLES)
|
||||
{
|
||||
documentation::testSpecificationAndThrow(
|
||||
@@ -98,11 +95,7 @@ ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary)
|
||||
"ModelGeometry"
|
||||
);
|
||||
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(keyName, name);
|
||||
ghoul_assert(success, "Name tag was not present");
|
||||
|
||||
_file = absPath(dictionary.value<std::string>(keyGeomModelFile));
|
||||
_file = absPath(dictionary.value<std::string>(KeyGeomModelFile));
|
||||
}
|
||||
|
||||
double ModelGeometry::boundingRadius() const {
|
||||
@@ -119,10 +112,6 @@ double ModelGeometry::boundingRadius() const {
|
||||
return maxDist;
|
||||
}
|
||||
|
||||
|
||||
ModelGeometry::~ModelGeometry() {
|
||||
}
|
||||
|
||||
void ModelGeometry::render() {
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
|
||||
@@ -135,39 +124,67 @@ void ModelGeometry::changeRenderMode(const GLenum mode) {
|
||||
}
|
||||
|
||||
bool ModelGeometry::initialize(Renderable* parent) {
|
||||
_parent = parent;
|
||||
float maximumDistanceSquared = 0;
|
||||
for (auto v: _vertices)
|
||||
{
|
||||
for (const Vertex& v : _vertices) {
|
||||
maximumDistanceSquared = glm::max(
|
||||
glm::pow(v.location[0], 2.f) +
|
||||
glm::pow(v.location[1], 2.f) +
|
||||
glm::pow(v.location[2], 2.f), maximumDistanceSquared);
|
||||
}
|
||||
_parent->setBoundingSphere(glm::sqrt(maximumDistanceSquared));
|
||||
parent->setBoundingSphere(glm::sqrt(maximumDistanceSquared));
|
||||
|
||||
if (_vertices.empty())
|
||||
if (_vertices.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glGenVertexArrays(1, &_vaoID);
|
||||
glGenBuffers(1, &_vbo);
|
||||
glGenBuffers(1, &_ibo);
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, _vertices.size() * sizeof(Vertex), _vertices.data(), GL_STATIC_DRAW);
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
_vertices.size() * sizeof(Vertex),
|
||||
_vertices.data(),
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex),
|
||||
reinterpret_cast<const GLvoid*>(offsetof(Vertex, location)));
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex),
|
||||
reinterpret_cast<const GLvoid*>(offsetof(Vertex, tex)));
|
||||
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
|
||||
reinterpret_cast<const GLvoid*>(offsetof(Vertex, normal)));
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
4,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(Vertex),
|
||||
reinterpret_cast<const GLvoid*>(offsetof(Vertex, location))
|
||||
);
|
||||
glVertexAttribPointer(
|
||||
1,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(Vertex),
|
||||
reinterpret_cast<const GLvoid*>(offsetof(Vertex, tex))
|
||||
);
|
||||
glVertexAttribPointer(
|
||||
2,
|
||||
3,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(Vertex),
|
||||
reinterpret_cast<const GLvoid*>(offsetof(Vertex, normal))
|
||||
);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _indices.size() * sizeof(int), _indices.data(), GL_STATIC_DRAW);
|
||||
glBufferData(
|
||||
GL_ELEMENT_ARRAY_BUFFER,
|
||||
_indices.size() * sizeof(int),
|
||||
_indices.data(),
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
@@ -181,37 +198,42 @@ void ModelGeometry::deinitialize() {
|
||||
}
|
||||
|
||||
bool ModelGeometry::loadObj(const std::string& filename) {
|
||||
std::string cachedFile = FileSys.cacheManager()->cachedFilename(
|
||||
const std::string cachedFile = FileSys.cacheManager()->cachedFilename(
|
||||
filename,
|
||||
ghoul::filesystem::CacheManager::Persistent::Yes
|
||||
);
|
||||
);
|
||||
|
||||
bool hasCachedFile = FileSys.fileExists(cachedFile);
|
||||
const bool hasCachedFile = FileSys.fileExists(cachedFile);
|
||||
if (hasCachedFile) {
|
||||
LINFO("Cached file '" << cachedFile << "' used for Model file '" << filename << "'");
|
||||
LINFO("Cached file '" << cachedFile << "' used for file '" << filename << "'");
|
||||
|
||||
bool success = loadCachedFile(cachedFile);
|
||||
if (success)
|
||||
const bool success = loadCachedFile(cachedFile);
|
||||
if (success) {
|
||||
return true;
|
||||
else
|
||||
}
|
||||
else {
|
||||
FileSys.cacheManager()->removeCacheFile(filename);
|
||||
}
|
||||
// Intentional fall-through to the 'else' computation to generate the cache
|
||||
// file for the next run
|
||||
}
|
||||
else {
|
||||
LINFO("Cached file '" << cachedFile << "' used for Model file '" << filename << "' not found");
|
||||
LINFO(
|
||||
"Cached file '" << cachedFile << "' for file '" << filename << "' not found"
|
||||
);
|
||||
}
|
||||
|
||||
LINFO("Loading Model file '" << filename << "'");
|
||||
bool success = loadModel(filename);
|
||||
const bool modelSuccess = loadModel(filename);
|
||||
|
||||
if (!success)
|
||||
if (!modelSuccess) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LINFO("Saving cache");
|
||||
success = saveCachedFile(cachedFile);
|
||||
const bool cacheSuccess = saveCachedFile(cachedFile);
|
||||
|
||||
return success;
|
||||
return cacheSuccess;
|
||||
}
|
||||
|
||||
bool ModelGeometry::saveCachedFile(const std::string& filename) {
|
||||
@@ -271,22 +293,6 @@ bool ModelGeometry::loadCachedFile(const std::string& filename) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ModelGeometry::getVertices(std::vector<Vertex>* vertexList) {
|
||||
vertexList->clear();
|
||||
for (auto v : _vertices)
|
||||
vertexList->push_back(v);
|
||||
|
||||
return !(vertexList->empty());
|
||||
}
|
||||
|
||||
bool ModelGeometry::getIndices(std::vector<int>* indexList) {
|
||||
indexList->clear();
|
||||
for (auto i : _indices)
|
||||
indexList->push_back(i);
|
||||
|
||||
return !(indexList->empty());
|
||||
}
|
||||
|
||||
void ModelGeometry::setUniforms(ghoul::opengl::ProgramObject&) {}
|
||||
|
||||
} // namespace modelgeometry
|
||||
|
||||
@@ -27,36 +27,46 @@
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <modules/base/rendering/renderablemodel.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
namespace ghoul { class Dictionary; }
|
||||
#include <memory>
|
||||
|
||||
namespace ghoul {
|
||||
class Dictionary;
|
||||
|
||||
namespace opengl { class ProgramObject; }
|
||||
} // namespace ghoul
|
||||
|
||||
namespace openspace {
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
class Renderable;
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
namespace modelgeometry {
|
||||
|
||||
class ModelGeometry : public properties::PropertyOwner {
|
||||
public:
|
||||
static std::unique_ptr<ModelGeometry> createFromDictionary(
|
||||
const ghoul::Dictionary& dictionary
|
||||
);
|
||||
|
||||
struct Vertex {
|
||||
GLfloat location[4];
|
||||
GLfloat tex[2];
|
||||
GLfloat normal[3];
|
||||
};
|
||||
|
||||
static std::unique_ptr<ModelGeometry> createFromDictionary(
|
||||
const ghoul::Dictionary& dictionary
|
||||
);
|
||||
|
||||
ModelGeometry(const ghoul::Dictionary& dictionary);
|
||||
virtual ~ModelGeometry();
|
||||
virtual ~ModelGeometry() = default;
|
||||
|
||||
virtual bool initialize(Renderable* parent);
|
||||
virtual void deinitialize();
|
||||
void render();
|
||||
|
||||
virtual bool loadModel(const std::string& filename) = 0;
|
||||
void changeRenderMode(const GLenum mode);
|
||||
bool getVertices(std::vector<Vertex>* vertexList);
|
||||
bool getIndices(std::vector<int>* indexList);
|
||||
//bool getVertices(std::vector<Vertex>* vertexList);
|
||||
//bool getIndices(std::vector<int>* indexList);
|
||||
|
||||
double boundingRadius() const;
|
||||
|
||||
@@ -65,8 +75,6 @@ public:
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
protected:
|
||||
Renderable* _parent;
|
||||
|
||||
bool loadObj(const std::string& filename);
|
||||
bool loadCachedFile(const std::string& filename);
|
||||
bool saveCachedFile(const std::string& filename);
|
||||
|
||||
@@ -24,15 +24,9 @@
|
||||
|
||||
#include <modules/base/rendering/multimodelgeometry.h>
|
||||
|
||||
#include "ghoul/logging/logmanager.h"
|
||||
#include "ghoul/io/model/modelreadermultiformat.h"
|
||||
#include "ghoul/opengl/vertexbufferobject.h"
|
||||
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "MultiModelGeometry";
|
||||
}
|
||||
#include <cstring>
|
||||
|
||||
namespace openspace {
|
||||
namespace modelgeometry {
|
||||
@@ -43,25 +37,13 @@ MultiModelGeometry::MultiModelGeometry(const ghoul::Dictionary& dictionary)
|
||||
loadObj(_file);
|
||||
}
|
||||
|
||||
bool MultiModelGeometry::initialize(Renderable* parent) {
|
||||
bool success = ModelGeometry::initialize(parent);
|
||||
return success;
|
||||
}
|
||||
|
||||
void MultiModelGeometry::deinitialize() {
|
||||
ModelGeometry::deinitialize();
|
||||
}
|
||||
|
||||
bool MultiModelGeometry::loadModel(const std::string& filename) {
|
||||
ghoul::io::ModelReaderMultiFormat modelReader;
|
||||
|
||||
std::vector<ghoul::io::ModelReaderBase::Vertex> vertices;
|
||||
std::vector<int> indices;
|
||||
|
||||
modelReader.loadModel(filename, vertices, indices);
|
||||
ghoul::io::ModelReaderMultiFormat().loadModel(filename, vertices, indices);
|
||||
|
||||
_vertices.reserve(vertices.size());
|
||||
for (const auto & v : vertices) {
|
||||
for (const ghoul::io::ModelReaderBase::Vertex& v : vertices) {
|
||||
Vertex vv;
|
||||
memcpy(vv.location, v.location, sizeof(GLfloat) * 3);
|
||||
vv.location[3] = 1.0;
|
||||
|
||||
@@ -38,9 +38,6 @@ class MultiModelGeometry : public ModelGeometry {
|
||||
public:
|
||||
MultiModelGeometry(const ghoul::Dictionary& dictionary);
|
||||
|
||||
bool initialize(Renderable* parent) override;
|
||||
void deinitialize() override;
|
||||
|
||||
private:
|
||||
bool loadModel(const std::string& filename);
|
||||
};
|
||||
|
||||
@@ -24,38 +24,34 @@
|
||||
|
||||
#include <modules/base/rendering/renderablemodel.h>
|
||||
|
||||
#include <modules/base/rendering/modelgeometry.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <modules/base/rendering/modelgeometry.h>
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
#include <openspace/util/time.h>
|
||||
#include <ghoul/misc/invariants.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/misc/invariants.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderableModel";
|
||||
|
||||
const char* KeyGeometry = "Geometry";
|
||||
const char* KeyTexture = "Textures.Color";
|
||||
|
||||
const char* KeyModelTransform = "Rotation.ModelTransform";
|
||||
const char* KeyFading = "Shading.Fadeable";
|
||||
|
||||
const char* keyBody = "Body";
|
||||
const char* keyStart = "StartTime";
|
||||
const char* keyEnd = "EndTime";
|
||||
const char* keyFading = "Shading.Fadeable";
|
||||
|
||||
const char* keyModelTransform = "Rotation.ModelTransform";
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -75,9 +71,23 @@ documentation::Documentation RenderableModel::Documentation() {
|
||||
{
|
||||
KeyTexture,
|
||||
new StringVerifier,
|
||||
"A color texture that can be applied to the model specified bny the "
|
||||
"A color texture that can be applied to the model specified by the "
|
||||
"Geometry.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
KeyModelTransform,
|
||||
new DoubleMatrix3Verifier,
|
||||
"Specifies a distinct transformation matrix that is applied to the "
|
||||
"model. If it is not specified, it is equal to the Identity matrix.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
KeyFading,
|
||||
new BoolVerifier,
|
||||
"Specifies whether the model should be periodically fading in and out. "
|
||||
"If this value is not specified, it will not fade.",
|
||||
Optional::Yes
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -85,16 +95,14 @@ documentation::Documentation RenderableModel::Documentation() {
|
||||
|
||||
RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _geometry(nullptr)
|
||||
, _colorTexturePath("colorTexture", "Color Texture")
|
||||
, _performFade("performFading", "Perform Fading", false)
|
||||
, _performShading("performShading", "Perform Shading", true)
|
||||
, _fading("fading", "Fade", 0)
|
||||
, _debugModelRotation("modelrotation", "Model Rotation", glm::vec3(0.f), glm::vec3(0.f), glm::vec3(360.f))
|
||||
, _programObject(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _geometry(nullptr)
|
||||
, _alpha(1.f)
|
||||
, _performShading("performShading", "Perform Shading", true)
|
||||
, _frameCount(0)
|
||||
, _modelTransform(1.0)
|
||||
{
|
||||
ghoul_precondition(
|
||||
dictionary.hasKeyAndValue<std::string>(SceneGraphNode::KeyName),
|
||||
@@ -107,7 +115,6 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
|
||||
"RenderableModel"
|
||||
);
|
||||
|
||||
|
||||
if (dictionary.hasKey(KeyGeometry)) {
|
||||
std::string name = dictionary.value<std::string>(SceneGraphNode::KeyName);
|
||||
ghoul::Dictionary dict = dictionary.value<ghoul::Dictionary>(KeyGeometry);
|
||||
@@ -119,57 +126,39 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
|
||||
_colorTexturePath = absPath(dictionary.value<std::string>(KeyTexture));
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(KeyModelTransform)) {
|
||||
_modelTransform = dictionary.value<glm::dmat3>(KeyModelTransform);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(KeyFading)) {
|
||||
_performFade = dictionary.value<bool>(KeyFading);
|
||||
}
|
||||
|
||||
addPropertySubOwner(_geometry.get());
|
||||
|
||||
addProperty(_colorTexturePath);
|
||||
_colorTexturePath.onChange(std::bind(&RenderableModel::loadTexture, this));
|
||||
|
||||
addProperty(_debugModelRotation);
|
||||
|
||||
if (dictionary.hasKeyAndValue<glm::dmat3>(keyModelTransform)) {
|
||||
dictionary.getValue(keyModelTransform, _modelTransform);
|
||||
}
|
||||
else {
|
||||
_modelTransform = glm::dmat3(1.f);
|
||||
}
|
||||
addProperty(_performShading);
|
||||
|
||||
if (dictionary.hasKeyAndValue<bool>(keyFading)) {
|
||||
bool fading;
|
||||
dictionary.getValue(keyFading, fading);
|
||||
_performFade = fading;
|
||||
}
|
||||
addProperty(_performFade);
|
||||
}
|
||||
|
||||
bool RenderableModel::isReady() const {
|
||||
bool ready = true;
|
||||
ready &= (_programObject != nullptr);
|
||||
ready &= (_texture != nullptr);
|
||||
return ready;
|
||||
return _programObject && _texture;
|
||||
}
|
||||
|
||||
bool RenderableModel::initialize() {
|
||||
bool completeSuccess = true;
|
||||
if (_programObject == nullptr) {
|
||||
// NH shader
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_programObject = renderEngine.buildRenderProgram("ModelProgram",
|
||||
"${MODULE_BASE}/shaders/model_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/model_fs.glsl");
|
||||
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
_programObject = OsEng.renderEngine().buildRenderProgram(
|
||||
"ModelProgram",
|
||||
"${MODULE_BASE}/shaders/model_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/model_fs.glsl"
|
||||
);
|
||||
|
||||
loadTexture();
|
||||
|
||||
bool completeSuccess = true;
|
||||
completeSuccess &= (_texture != nullptr);
|
||||
completeSuccess &= _geometry->initialize(this);
|
||||
//completeSuccess &= !_source.empty();
|
||||
//completeSuccess &= !_destination.empty();
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
@@ -180,10 +169,8 @@ bool RenderableModel::deinitialize() {
|
||||
}
|
||||
_texture = nullptr;
|
||||
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject) {
|
||||
renderEngine.removeRenderProgram(_programObject);
|
||||
OsEng.renderEngine().removeRenderProgram(_programObject);
|
||||
_programObject = nullptr;
|
||||
}
|
||||
|
||||
@@ -199,30 +186,18 @@ void RenderableModel::render(const RenderData& data) {
|
||||
}
|
||||
else if (!_performFade && _fading < 1.f) {
|
||||
_fading = _fading + 0.01f;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// debug rotation controlled from GUI
|
||||
glm::mat4 unitMat4(1);
|
||||
glm::vec3 debugEulerRot = glm::radians(_debugModelRotation.value());
|
||||
glm::mat4 rotX = glm::rotate(unitMat4, debugEulerRot.x, glm::vec3(1, 0, 0));
|
||||
glm::mat4 rotY = glm::rotate(unitMat4, debugEulerRot.y, glm::vec3(0, 1, 0));
|
||||
glm::mat4 rotZ = glm::rotate(unitMat4, debugEulerRot.z, glm::vec3(0, 0, 1));
|
||||
glm::dmat4 debugModelRotation = rotX * rotY * rotZ;
|
||||
|
||||
// Model transform and view transform needs to be in double precision
|
||||
glm::dmat4 modelTransform =
|
||||
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
|
||||
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
|
||||
glm::dmat4(glm::scale(glm::dmat4(_modelTransform), glm::dvec3(data.modelTransform.scale)));
|
||||
debugModelRotation; // debug model rotation controlled from GUI
|
||||
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
|
||||
|
||||
glm::vec3 directionToSun = glm::normalize(_sunPos - data.modelTransform.translation);
|
||||
glm::vec3 directionToSunViewSpace = glm::mat3(data.camera.combinedViewMatrix()) * directionToSun;
|
||||
|
||||
_programObject->setUniform("transparency", _alpha);
|
||||
_programObject->setUniform("directionToSunViewSpace", directionToSunViewSpace);
|
||||
_programObject->setUniform("modelViewTransform", glm::mat4(modelViewTransform));
|
||||
_programObject->setUniform("projectionTransform", data.camera.projectionMatrix());
|
||||
@@ -239,7 +214,6 @@ void RenderableModel::render(const RenderData& data) {
|
||||
|
||||
_geometry->render();
|
||||
|
||||
// disable shader
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
@@ -247,23 +221,6 @@ void RenderableModel::update(const UpdateData& data) {
|
||||
if (_programObject->isDirty()) {
|
||||
_programObject->rebuildFromFile();
|
||||
}
|
||||
// double _time = data.time;
|
||||
|
||||
//if (_isGhost){
|
||||
// futureTime = openspace::ImageSequencer::ref().getNextCaptureTime();
|
||||
// double remaining = openspace::ImageSequencer::ref().getNextCaptureTime() - data.time;
|
||||
// double interval = openspace::ImageSequencer::ref().getIntervalLength();
|
||||
// double t = 1.f - remaining / openspace::ImageSequencer::ref().getIntervalLength();
|
||||
// if (interval > 60) {
|
||||
// if (t < 0.8)
|
||||
// _fading = static_cast<float>(t);
|
||||
// else if (t >= 0.95)
|
||||
// _fading = _fading - 0.5f;
|
||||
// }
|
||||
// else
|
||||
// _fading = 0.f;
|
||||
// _time = futureTime;
|
||||
//}
|
||||
|
||||
_sunPos = OsEng.renderEngine().scene()->sceneGraphNode("Sun")->worldPosition();
|
||||
}
|
||||
@@ -273,7 +230,10 @@ void RenderableModel::loadTexture() {
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
|
||||
if (_texture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
|
||||
LDEBUGC(
|
||||
"RenderableModel",
|
||||
"Loaded texture from '" << absPath(_colorTexturePath) << "'"
|
||||
);
|
||||
_texture->uploadTexture();
|
||||
_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
}
|
||||
|
||||
@@ -31,15 +31,21 @@
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <openspace/properties/vector/vec3property.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
class Texture;
|
||||
} // namespace opengl
|
||||
} // namespace ghoul
|
||||
|
||||
namespace openspace {
|
||||
|
||||
struct RenderData;
|
||||
struct UpdateData;
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
namespace modelgeometry {
|
||||
@@ -64,24 +70,18 @@ protected:
|
||||
void loadTexture();
|
||||
|
||||
private:
|
||||
std::unique_ptr<modelgeometry::ModelGeometry> _geometry;
|
||||
|
||||
properties::StringProperty _colorTexturePath;
|
||||
properties::BoolProperty _performFade;
|
||||
properties::BoolProperty _performShading;
|
||||
properties::FloatProperty _fading;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
|
||||
std::unique_ptr<modelgeometry::ModelGeometry> _geometry;
|
||||
|
||||
glm::dmat3 _modelTransform;
|
||||
|
||||
float _alpha;
|
||||
|
||||
int _frameCount;
|
||||
|
||||
glm::dvec3 _sunPos;
|
||||
|
||||
properties::BoolProperty _performShading;
|
||||
properties::Vec3Property _debugModelRotation;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -1,269 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/base/rendering/renderablepath.h>
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <fstream>
|
||||
|
||||
/* TODO for this class:
|
||||
* In order to add geometry shader (for pretty-draw),
|
||||
* need to pack each consecutive point pair into a vec2
|
||||
* in order to draw quad between them.
|
||||
*/
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderableTrail";
|
||||
//constants
|
||||
const char* keyName = "Name";
|
||||
const char* keyBody = "Body";
|
||||
const char* keyObserver = "Observer";
|
||||
const char* keyFrame = "Frame";
|
||||
const char* keyPathModule = "ModulePath";
|
||||
const char* keyColor = "RGB";
|
||||
const char* keyTimeSteps = "TimeSteps";
|
||||
const char* keyPointSteps = "PointSteps";
|
||||
const char* keyDrawLine = "DrawLine";
|
||||
const char* keRenderDistanceInterval = "RenderDistanceInterval";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
RenderablePath::RenderablePath(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _lineWidth("lineWidth", "Line Width", 2.f, 1.f, 20.f)
|
||||
, _drawLine("drawline", "Draw Line", false)
|
||||
, _programObject(nullptr)
|
||||
, _successfullDictionaryFetch(true)
|
||||
, _vaoID(0)
|
||||
, _vBufferID(0)
|
||||
, _needsSweep(true)
|
||||
, _start(0.0)
|
||||
, _stop(0.0)
|
||||
{
|
||||
_successfullDictionaryFetch &= dictionary.getValue(keyBody, _target);
|
||||
_successfullDictionaryFetch &= dictionary.getValue(keyObserver, _observer);
|
||||
_successfullDictionaryFetch &= dictionary.getValue(keyFrame, _frame);
|
||||
_successfullDictionaryFetch &= dictionary.getValue(keyTimeSteps, _increment);
|
||||
|
||||
float fPointSteps; // Dictionary can not pick out ints...
|
||||
if (!dictionary.getValue(keyPointSteps, fPointSteps))
|
||||
fPointSteps = 4;
|
||||
_pointSteps = static_cast<int>(fPointSteps);
|
||||
|
||||
glm::vec3 color(0.f);
|
||||
if (dictionary.hasKeyAndValue<glm::vec3>(keyColor))
|
||||
dictionary.getValue(keyColor, color);
|
||||
_lineColor = color;
|
||||
|
||||
bool drawLine = false;
|
||||
if (dictionary.hasKeyAndValue<bool>(keyDrawLine))
|
||||
dictionary.getValue(keyDrawLine, drawLine);
|
||||
_drawLine = drawLine;
|
||||
addProperty(_drawLine);
|
||||
addProperty(_lineWidth);
|
||||
_distanceFade = 1.0;
|
||||
}
|
||||
|
||||
bool RenderablePath::initialize() {
|
||||
if (!_successfullDictionaryFetch) {
|
||||
LERROR("The following keys need to be set in the Dictionary. Cannot initialize!");
|
||||
LERROR(keyBody << ": " << _target);
|
||||
LERROR(keyObserver << ": " << _observer);
|
||||
LERROR(keyFrame << ": " << _frame);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool completeSuccess = true;
|
||||
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_programObject = renderEngine.buildRenderProgram("PathProgram",
|
||||
"${MODULE_BASE}/shaders/path_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/path_fs.glsl");
|
||||
if (!_programObject)
|
||||
return false;
|
||||
|
||||
bool intervalSet = hasTimeInterval();
|
||||
if (intervalSet) {
|
||||
completeSuccess &= getInterval(_start, _stop);
|
||||
}
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
bool RenderablePath::deinitialize() {
|
||||
glDeleteVertexArrays(1, &_vaoID);
|
||||
_vaoID = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vBufferID);
|
||||
_vBufferID = 0;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject) {
|
||||
renderEngine.removeRenderProgram(_programObject);
|
||||
_programObject = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderablePath::isReady() const {
|
||||
return (_programObject != nullptr) && _successfullDictionaryFetch;
|
||||
}
|
||||
|
||||
void RenderablePath::render(const RenderData& data) {
|
||||
double time = openspace::Time::ref().j2000Seconds();
|
||||
if (_start > time || _stop < time)
|
||||
return;
|
||||
|
||||
|
||||
size_t nPointsToDraw = _vertexArray.size();// (time - _start) / (_stop - _start) * (_vertexArray.size()) + 1 + 0.5;
|
||||
|
||||
_programObject->activate();
|
||||
|
||||
// Calculate variables to be used as uniform variables in shader
|
||||
glm::dvec3 bodyPosition = data.modelTransform.translation;
|
||||
|
||||
// Model transform and view transform needs to be in double precision
|
||||
glm::dmat4 modelTransform =
|
||||
glm::translate(glm::dmat4(1.0), bodyPosition); // Translation
|
||||
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
|
||||
|
||||
_programObject->setUniform("modelViewTransform", glm::mat4(modelViewTransform));
|
||||
_programObject->setUniform("projectionTransform", data.camera.projectionMatrix());
|
||||
_programObject->setUniform("pointSteps", _pointSteps);
|
||||
_programObject->setUniform("color", _lineColor);
|
||||
|
||||
if (_drawLine) {
|
||||
glLineWidth(_lineWidth);
|
||||
glBindVertexArray(_vaoID);
|
||||
glDrawArrays(GL_LINE_STRIP, 0, static_cast<GLsizei>(nPointsToDraw));
|
||||
glBindVertexArray(0);
|
||||
glLineWidth(1.f);
|
||||
}
|
||||
|
||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(nPointsToDraw));
|
||||
glBindVertexArray(0);
|
||||
|
||||
glDisable(GL_PROGRAM_POINT_SIZE);
|
||||
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
void RenderablePath::update(const UpdateData& data) {
|
||||
if (data.isTimeJump)
|
||||
_needsSweep = true;
|
||||
|
||||
if (_needsSweep) {
|
||||
calculatePath(_observer);
|
||||
sendToGPU();
|
||||
_needsSweep = false;
|
||||
}
|
||||
|
||||
if (_programObject->isDirty())
|
||||
_programObject->rebuildFromFile();
|
||||
}
|
||||
|
||||
void RenderablePath::calculatePath(std::string observer) {
|
||||
double interval = (_stop - _start);
|
||||
int segments = static_cast<int>(interval /_increment);
|
||||
|
||||
if (segments == 0)
|
||||
return;
|
||||
|
||||
double lightTime;
|
||||
// bool correctPosition = true;
|
||||
|
||||
double currentTime = _start;
|
||||
_vertexArray.resize(segments);
|
||||
|
||||
//psc pscPos;
|
||||
//float r, g, b;
|
||||
//float g = _lineColor[1];
|
||||
//float b = _lineColor[2];
|
||||
glm::vec3 position;
|
||||
for (int i = 0; i < segments; i++) {
|
||||
position =
|
||||
glm::vec3(SpiceManager::ref().targetPosition(_target, observer, _frame, {}, currentTime, lightTime));
|
||||
|
||||
// Convert from 100 m to m
|
||||
position *= 10e2;
|
||||
|
||||
//pscPos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
|
||||
//pscPos[3] += 3;
|
||||
|
||||
//if (!correctPosition) {
|
||||
// r = 1.f;
|
||||
// g = b = 0.5f;
|
||||
//}
|
||||
//else if ((i % 8) == 0) {
|
||||
// r = _lineColor[0];
|
||||
// g = _lineColor[1];
|
||||
// b = _lineColor[2];
|
||||
//}
|
||||
//else {
|
||||
// r = g = b = 0.6f;
|
||||
//}
|
||||
//add position
|
||||
_vertexArray[i] = { position[0], position[1], position[2], 1.0f };
|
||||
//add color for position
|
||||
//_vertexArray[i + 1] = { r, g, b, a };
|
||||
currentTime += _increment;
|
||||
}
|
||||
_lastPosition = glm::vec4(position, 1.0f);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, _vertexArray.size() * sizeof(VertexInfo), &_vertexArray[0]);
|
||||
}
|
||||
|
||||
void RenderablePath::sendToGPU() {
|
||||
glGenVertexArrays(1, &_vaoID);
|
||||
glGenBuffers(1, &_vBufferID);
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
|
||||
glBufferData(GL_ARRAY_BUFFER, _vertexArray.size() * sizeof(VertexInfo), NULL, GL_STREAM_DRAW); // orphaning the buffer, sending NULL data.
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, _vertexArray.size() * sizeof(VertexInfo), &_vertexArray[0]);
|
||||
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
//glEnableVertexAttribArray(1);
|
||||
//glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(VertexInfo) * 2, (void*)(sizeof(VertexInfo)));
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -1,94 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2017 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_MODULE_BASE___RENDERABLEPATH___H__
|
||||
#define __OPENSPACE_MODULE_BASE___RENDERABLEPATH___H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
class Texture;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderablePath : public Renderable {
|
||||
public:
|
||||
RenderablePath(const ghoul::Dictionary& dictionary);
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
|
||||
bool isReady() const override;
|
||||
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
void calculatePath(std::string observer);
|
||||
private:
|
||||
struct VertexInfo {
|
||||
float x, y, z, e;
|
||||
//float r, g, b, a;
|
||||
};
|
||||
void sendToGPU();
|
||||
void addPosition(glm::vec3 pos);
|
||||
void addColor(glm::vec4 col);
|
||||
|
||||
glm::vec3 _lineColor;
|
||||
glm::vec4 _lastPosition;
|
||||
properties::FloatProperty _lineWidth;
|
||||
properties::BoolProperty _drawLine;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
|
||||
bool _successfullDictionaryFetch;
|
||||
|
||||
std::string _target;
|
||||
std::string _observer;
|
||||
std::string _frame;
|
||||
|
||||
GLuint _vaoID;
|
||||
GLuint _vBufferID;
|
||||
|
||||
bool _needsSweep;
|
||||
|
||||
std::vector<VertexInfo> _vertexArray;
|
||||
|
||||
float _increment;
|
||||
double _start;
|
||||
double _stop;
|
||||
float _distanceFade;
|
||||
int _pointSteps;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_BASE___RENDERABLEPATH___H__
|
||||
@@ -22,14 +22,14 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <modules/base/rendering/renderableplane.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <modules/newhorizons/rendering/renderableplanetprojection.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
@@ -38,108 +38,106 @@
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
namespace {
|
||||
static const std::string _loggerCat = "RenderablePlane";
|
||||
|
||||
const char* keyFieldlines = "Fieldlines";
|
||||
const char* keyFilename = "File";
|
||||
const char* keyHints = "Hints";
|
||||
const char* keyShaders = "Shaders";
|
||||
const char* keyVertexShader = "VertexShader";
|
||||
const char* keyFragmentShader = "FragmentShader";
|
||||
}
|
||||
const char* KeySize = "Size";
|
||||
const char* KeyBillboard = "Billboard";
|
||||
const char* KeyBlendMode = "BlendMode";
|
||||
const char* KeyTexture = "Texture";
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation RenderablePlane::Documentation() {
|
||||
using namespace documentation;
|
||||
return {
|
||||
"Renderable Plane",
|
||||
"base_renderable_plane",
|
||||
{
|
||||
{
|
||||
KeySize,
|
||||
new DoubleVerifier,
|
||||
"Specifies the size of the square plane in meters.",
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
KeyBillboard,
|
||||
new BoolVerifier,
|
||||
"Specifies whether the plane is a billboard, which means that it is "
|
||||
"always facing the camera. If this is false, it can be oriented using "
|
||||
"other transformations. The default is 'false'.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
KeyBlendMode,
|
||||
new StringInListVerifier({ "Normal", "Additive" }),
|
||||
"Specifies the blend mode that is applied to this plane. The default "
|
||||
"value is 'Normal'.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
KeyTexture,
|
||||
new StringVerifier,
|
||||
"Specifies the texture that is applied to this plane. This image has to "
|
||||
"be a square image.",
|
||||
Optional::No
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _texturePath("texture", "Texture")
|
||||
, _billboard("billboard", "Billboard", false)
|
||||
, _projectionListener("projectionListener", "DisplayProjections", false)
|
||||
, _size("size", "Size", 10, 0, std::pow(10, 25))
|
||||
, _origin(Origin::Center)
|
||||
, _shader(nullptr)
|
||||
, _textureIsDirty(false)
|
||||
, _texture(nullptr)
|
||||
, _blendMode(BlendMode::Normal)
|
||||
, _quad(0)
|
||||
, _vertexPositionBuffer(0)
|
||||
, _planeIsDirty(false)
|
||||
, _textureIsDirty(false)
|
||||
{
|
||||
dictionary.getValue("Size", _size);
|
||||
documentation::testSpecificationAndThrow(
|
||||
Documentation(),
|
||||
dictionary,
|
||||
"RenderablePlane"
|
||||
);
|
||||
|
||||
if (dictionary.hasKey("Name")) {
|
||||
dictionary.getValue("Name", _nodeName);
|
||||
_size = dictionary.value<double>(KeySize);
|
||||
|
||||
if (dictionary.hasKey(KeyBillboard)) {
|
||||
_billboard = dictionary.value<bool>(KeyBillboard);
|
||||
}
|
||||
|
||||
std::string origin;
|
||||
if (dictionary.getValue("Origin", origin)) {
|
||||
if (origin == "LowerLeft") {
|
||||
_origin = Origin::LowerLeft;
|
||||
if (dictionary.hasKey(KeyBlendMode)) {
|
||||
const std::string v = dictionary.value<std::string>(KeyBlendMode);
|
||||
if (v == "Normal") {
|
||||
_blendMode = BlendMode::Normal;
|
||||
}
|
||||
else if (origin == "LowerRight") {
|
||||
_origin = Origin::LowerRight;
|
||||
}
|
||||
else if (origin == "UpperLeft") {
|
||||
_origin = Origin::UpperLeft;
|
||||
}
|
||||
else if (origin == "UpperRight") {
|
||||
_origin = Origin::UpperRight;
|
||||
}
|
||||
else if (origin == "Center") {
|
||||
_origin = Origin::Center;
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to get the billboard value
|
||||
bool billboard = false;
|
||||
if (dictionary.getValue("Billboard", billboard)) {
|
||||
_billboard = billboard;
|
||||
}
|
||||
if (dictionary.hasKey("ProjectionListener")){
|
||||
bool projectionListener = false;
|
||||
if (dictionary.getValue("ProjectionListener", projectionListener)) {
|
||||
_projectionListener = projectionListener;
|
||||
}
|
||||
}
|
||||
|
||||
std::string blendMode;
|
||||
if (dictionary.getValue("BlendMode", blendMode)) {
|
||||
if (blendMode == "Additive") {
|
||||
else if (v == "Additive") {
|
||||
_blendMode = BlendMode::Additive;
|
||||
setRenderBin(Renderable::RenderBin::Transparent);
|
||||
}
|
||||
}
|
||||
|
||||
std::string texturePath = "";
|
||||
bool success = dictionary.getValue("Texture", texturePath);
|
||||
if (success) {
|
||||
_texturePath = absPath(texturePath);
|
||||
_textureFile = new ghoul::filesystem::File(_texturePath);
|
||||
}
|
||||
_texturePath = absPath(dictionary.value<std::string>(KeyTexture));
|
||||
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
|
||||
|
||||
addProperty(_billboard);
|
||||
addProperty(_texturePath);
|
||||
_texturePath.onChange(std::bind(&RenderablePlane::loadTexture, this));
|
||||
_textureFile->setCallback([&](const ghoul::filesystem::File&) { _textureIsDirty = true; });
|
||||
_texturePath.onChange([this]() {loadTexture(); });
|
||||
_textureFile->setCallback(
|
||||
[this](const ghoul::filesystem::File&) { _textureIsDirty = true; }
|
||||
);
|
||||
|
||||
addProperty(_size);
|
||||
//_size.onChange(std::bind(&RenderablePlane::createPlane, this));
|
||||
_size.onChange([this](){ _planeIsDirty = true; });
|
||||
|
||||
setBoundingSphere(_size);
|
||||
}
|
||||
|
||||
RenderablePlane::~RenderablePlane() {
|
||||
delete _textureFile;
|
||||
_textureFile = nullptr;
|
||||
}
|
||||
|
||||
bool RenderablePlane::isReady() const {
|
||||
bool ready = true;
|
||||
if (!_shader)
|
||||
ready &= false;
|
||||
if(!_texture)
|
||||
ready &= false;
|
||||
return ready;
|
||||
return _shader && _texture;
|
||||
}
|
||||
|
||||
bool RenderablePlane::initialize() {
|
||||
@@ -147,17 +145,10 @@ bool RenderablePlane::initialize() {
|
||||
glGenBuffers(1, &_vertexPositionBuffer); // generate buffer
|
||||
createPlane();
|
||||
|
||||
if (_shader == nullptr) {
|
||||
// Plane Program
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_shader = renderEngine.buildRenderProgram("PlaneProgram",
|
||||
"${MODULE_BASE}/shaders/plane_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/plane_fs.glsl"
|
||||
);
|
||||
if (!_shader)
|
||||
return false;
|
||||
}
|
||||
_shader = OsEng.renderEngine().buildRenderProgram("PlaneProgram",
|
||||
"${MODULE_BASE}/shaders/plane_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/plane_fs.glsl"
|
||||
);
|
||||
|
||||
loadTexture();
|
||||
|
||||
@@ -171,16 +162,8 @@ bool RenderablePlane::deinitialize() {
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
_vertexPositionBuffer = 0;
|
||||
|
||||
if (!_projectionListener){
|
||||
// its parents job to kill texture
|
||||
// iff projectionlistener
|
||||
_texture = nullptr;
|
||||
}
|
||||
|
||||
delete _textureFile;
|
||||
_textureFile = nullptr;
|
||||
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
@@ -191,44 +174,35 @@ bool RenderablePlane::deinitialize() {
|
||||
}
|
||||
|
||||
void RenderablePlane::render(const RenderData& data) {
|
||||
glm::mat4 scaleTransform = glm::mat4(1.0);
|
||||
|
||||
// Activate shader
|
||||
_shader->activate();
|
||||
if (_projectionListener){
|
||||
//get parent node-texture and set with correct dimensions
|
||||
SceneGraphNode* textureNode = OsEng.renderEngine().scene()->sceneGraphNode(_nodeName)->parent();
|
||||
if (textureNode != nullptr){
|
||||
RenderablePlanetProjection* t = static_cast<RenderablePlanetProjection*>(textureNode->renderable());
|
||||
_texture = std::unique_ptr<ghoul::opengl::Texture>(&(t->baseTexture()));
|
||||
unsigned int h = _texture->height();
|
||||
unsigned int w = _texture->width();
|
||||
float scale = static_cast<float>(h) / static_cast<float>(w);
|
||||
scaleTransform = glm::scale(glm::mat4(1.0), glm::vec3(1.f, scale, 1.f));
|
||||
}
|
||||
}
|
||||
//if (_projectionListener){
|
||||
// //get parent node-texture and set with correct dimensions
|
||||
// SceneGraphNode* textureNode = OsEng.renderEngine().scene()->sceneGraphNode(_nodeName)->parent();
|
||||
// if (textureNode != nullptr){
|
||||
// RenderablePlanetProjection* t = static_cast<RenderablePlanetProjection*>(textureNode->renderable());
|
||||
// _texture = std::unique_ptr<ghoul::opengl::Texture>(&(t->baseTexture()));
|
||||
// unsigned int h = _texture->height();
|
||||
// unsigned int w = _texture->width();
|
||||
// float scale = static_cast<float>(h) / static_cast<float>(w);
|
||||
// scaleTransform = glm::scale(glm::mat4(1.0), glm::vec3(1.f, scale, 1.f));
|
||||
// }
|
||||
//}
|
||||
|
||||
// Model transform and view transform needs to be in double precision
|
||||
glm::dmat4 rotationTransform;
|
||||
if (_billboard)
|
||||
rotationTransform = glm::inverse(glm::dmat4(data.camera.viewRotationMatrix()));
|
||||
else
|
||||
rotationTransform = glm::dmat4(data.modelTransform.rotation);
|
||||
const glm::dmat4 rotationTransform = _billboard ?
|
||||
glm::inverse(glm::dmat4(data.camera.viewRotationMatrix())) :
|
||||
glm::dmat4(data.modelTransform.rotation);
|
||||
|
||||
glm::dmat4 modelTransform =
|
||||
const glm::dmat4 modelTransform =
|
||||
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
|
||||
rotationTransform *
|
||||
glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale))) *
|
||||
glm::dmat4(scaleTransform);
|
||||
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
|
||||
glm::dmat4(1.0);
|
||||
const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
|
||||
|
||||
_shader->setUniform("modelViewProjectionTransform",
|
||||
data.camera.projectionMatrix() * glm::mat4(modelViewTransform));
|
||||
|
||||
//_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
//_shader->setUniform("ModelTransform", transform);
|
||||
//setPscUniforms(*_shader.get(), data.camera, data.position);
|
||||
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
unit.activate();
|
||||
_texture->bind();
|
||||
@@ -276,9 +250,14 @@ void RenderablePlane::update(const UpdateData&) {
|
||||
|
||||
void RenderablePlane::loadTexture() {
|
||||
if (_texturePath.value() != "") {
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture =
|
||||
ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath));
|
||||
|
||||
if (texture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'");
|
||||
LDEBUGC(
|
||||
"RenderablePlane",
|
||||
"Loaded texture from '" << absPath(_texturePath) << "'"
|
||||
);
|
||||
texture->uploadTexture();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
@@ -286,19 +265,15 @@ void RenderablePlane::loadTexture() {
|
||||
|
||||
_texture = std::move(texture);
|
||||
|
||||
delete _textureFile;
|
||||
_textureFile = new ghoul::filesystem::File(_texturePath);
|
||||
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
|
||||
_textureFile->setCallback([&](const ghoul::filesystem::File&) { _textureIsDirty = true; });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderablePlane::createPlane() {
|
||||
// ============================
|
||||
// GEOMETRY (quad)
|
||||
// ============================
|
||||
const GLfloat size = _size;
|
||||
const GLfloat vertex_data[] = {
|
||||
const GLfloat vertexData[] = {
|
||||
// x y z w s t
|
||||
-size, -size, 0.f, 0.f, 0.f, 0.f,
|
||||
size, size, 0.f, 0.f, 1.f, 1.f,
|
||||
@@ -308,13 +283,28 @@ void RenderablePlane::createPlane() {
|
||||
size, size, 0.f, 0.f, 1.f, 1.f,
|
||||
};
|
||||
|
||||
glBindVertexArray(_quad); // bind array
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
|
||||
glBindVertexArray(_quad);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(0));
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
4,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(GLfloat) * 6,
|
||||
reinterpret_cast<void*>(0)
|
||||
);
|
||||
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
|
||||
glVertexAttribPointer(
|
||||
1,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(GLfloat) * 6,
|
||||
reinterpret_cast<void*>(sizeof(GLfloat) * 4)
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -29,35 +29,31 @@
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace filesystem {
|
||||
class File;
|
||||
}
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
class Texture;
|
||||
}
|
||||
namespace filesystem { class File; }
|
||||
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
class Texture;
|
||||
}
|
||||
} // namespace ghoul
|
||||
|
||||
namespace openspace {
|
||||
struct LinePoint;
|
||||
|
||||
struct RenderData;
|
||||
struct UpdateData;
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
struct LinePoint;
|
||||
|
||||
class RenderablePlane : public Renderable {
|
||||
|
||||
enum class Origin {
|
||||
LowerLeft, LowerRight, UpperLeft, UpperRight, Center
|
||||
};
|
||||
|
||||
public:
|
||||
enum class BlendMode : int {
|
||||
Normal = 0,
|
||||
Additive
|
||||
};
|
||||
|
||||
RenderablePlane(const ghoul::Dictionary& dictionary);
|
||||
~RenderablePlane();
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
@@ -67,27 +63,32 @@ public:
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
private:
|
||||
enum class BlendMode : int {
|
||||
Normal = 0,
|
||||
Additive
|
||||
};
|
||||
|
||||
void loadTexture();
|
||||
void createPlane();
|
||||
|
||||
properties::StringProperty _texturePath;
|
||||
properties::BoolProperty _billboard;
|
||||
properties::BoolProperty _projectionListener;
|
||||
properties::FloatProperty _size;
|
||||
|
||||
Origin _origin;
|
||||
std::string _nodeName;
|
||||
|
||||
bool _planeIsDirty;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
bool _textureIsDirty;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
std::unique_ptr<ghoul::filesystem::File> _textureFile;
|
||||
|
||||
BlendMode _blendMode;
|
||||
ghoul::filesystem::File* _textureFile;
|
||||
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
|
||||
bool _planeIsDirty;
|
||||
bool _textureIsDirty;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -24,38 +24,77 @@
|
||||
|
||||
#include <modules/base/rendering/renderablesphere.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
#include <openspace/util/powerscaledsphere.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
namespace {
|
||||
static const std::string _loggerCat = "RenderableSphere";
|
||||
|
||||
const char* keySize = "Size";
|
||||
const char* keySegments = "Segments";
|
||||
const char* keyTexture = "Texture";
|
||||
const char* keyOrientation = "Orientation";
|
||||
const char* KeySize = "Size";
|
||||
const char* KeySegments = "Segments";
|
||||
const char* KeyTexture = "Texture";
|
||||
const char* KeyOrientation = "Orientation";
|
||||
|
||||
enum Orientation {
|
||||
Outside = 1,
|
||||
Inside = 2
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation RenderableSphere::Documentation() {
|
||||
using namespace documentation;
|
||||
return {
|
||||
"RenderableSphere",
|
||||
"base_renderable_sphere",
|
||||
{
|
||||
{
|
||||
KeySize,
|
||||
new DoubleVerifier,
|
||||
"Specifies the radius of the sphere in meters.",
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
KeySegments,
|
||||
new IntVerifier,
|
||||
"Specifies the number of segments the sphere is separated in.",
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
KeyTexture,
|
||||
new StringVerifier,
|
||||
"Specifies the texture that is applied to the sphere.",
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
KeyOrientation,
|
||||
new StringInListVerifier({ "Inside", "Outside", "Inside/Outside" }),
|
||||
"Specifies whether the texture is applied to the inside of the sphere, "
|
||||
"the outside of the sphere, or both. The default value is 'Outside'.",
|
||||
Optional::Yes
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _texturePath("texture", "Texture")
|
||||
, _orientation("orientation", "Orientation")
|
||||
, _size("size", "Size", glm::vec2(1.f, 1.f), glm::vec2(0.f), glm::vec2(100.f))
|
||||
, _size("size", "Size", 1.f, 0.f, std::pow(10.f, 45))
|
||||
, _segments("segments", "Segments", 8, 4, 100)
|
||||
, _transparency("transparency", "Transparency", 1.f, 0.f, 1.f)
|
||||
, _shader(nullptr)
|
||||
@@ -63,67 +102,68 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
|
||||
, _sphere(nullptr)
|
||||
, _sphereIsDirty(false)
|
||||
{
|
||||
if (dictionary.hasKeyAndValue<glm::vec2>(keySize)) {
|
||||
glm::vec2 size;
|
||||
dictionary.getValue(keySize, size);
|
||||
_size = size;
|
||||
}
|
||||
documentation::testSpecificationAndThrow(
|
||||
Documentation(),
|
||||
dictionary,
|
||||
"RenderableSphere"
|
||||
);
|
||||
|
||||
if (dictionary.hasKeyAndValue<glm::vec2>(keySegments)) {
|
||||
int segments;
|
||||
dictionary.getValue(keySegments, segments);
|
||||
_segments = segments;
|
||||
}
|
||||
|
||||
if (dictionary.hasKeyAndValue<std::string>(keyTexture)) {
|
||||
std::string texture;
|
||||
dictionary.getValue(keyTexture, texture);
|
||||
_texturePath = absPath(texture);
|
||||
}
|
||||
_size = dictionary.value<double>(KeySize);
|
||||
_segments = static_cast<int>(dictionary.value<double>(KeySegments));
|
||||
_texturePath = absPath(dictionary.value<std::string>(KeyTexture));
|
||||
|
||||
_orientation.addOption(Outside, "Outside");
|
||||
_orientation.addOption(Inside, "Inside");
|
||||
_orientation.addOption(Outside | Inside, "Outside + Inside");
|
||||
_orientation.addOption(Outside | Inside, "Inside/Outside");
|
||||
|
||||
if (dictionary.hasKeyAndValue<std::string>(keyOrientation)) {
|
||||
std::string orientation;
|
||||
dictionary.getValue(keyOrientation, orientation);
|
||||
if (orientation == "Outside")
|
||||
_orientation = Outside;
|
||||
else if (orientation == "Inside")
|
||||
if (dictionary.hasKey(KeyOrientation)) {
|
||||
const std::string v = dictionary.value<std::string>(KeyOrientation);
|
||||
if (v == "Inside") {
|
||||
_orientation = Inside;
|
||||
else
|
||||
}
|
||||
else if (v == "Outside") {
|
||||
_orientation = Outside;
|
||||
}
|
||||
else if (v == "Inside/Outside") {
|
||||
_orientation = Outside | Inside;
|
||||
}
|
||||
else {
|
||||
ghoul_assert(false, "Missing 'case' label");
|
||||
}
|
||||
}
|
||||
else {
|
||||
_orientation = Outside;
|
||||
}
|
||||
|
||||
addProperty(_orientation);
|
||||
|
||||
addProperty(_size);
|
||||
_size.onChange([this](){ _sphereIsDirty = true; });
|
||||
|
||||
addProperty(_segments);
|
||||
_segments.onChange([this](){ _sphereIsDirty = true; });
|
||||
|
||||
addProperty(_transparency);
|
||||
|
||||
addProperty(_texturePath);
|
||||
_texturePath.onChange(std::bind(&RenderableSphere::loadTexture, this));
|
||||
_texturePath.onChange([this]() {loadTexture(); });
|
||||
|
||||
|
||||
setRenderBin(Renderable::RenderBin::Transparent);
|
||||
}
|
||||
|
||||
bool RenderableSphere::isReady() const {
|
||||
return (_sphere != nullptr) && (_shader != nullptr) && (_texture != nullptr);
|
||||
return _shader && _texture;
|
||||
}
|
||||
|
||||
bool RenderableSphere::initialize() {
|
||||
delete _sphere;
|
||||
_sphere = new PowerScaledSphere(_size.value(), _segments);
|
||||
_sphere = std::make_unique<PowerScaledSphere>(
|
||||
PowerScaledScalar::CreatePSS(_size), _segments
|
||||
);
|
||||
_sphere->initialize();
|
||||
|
||||
// pscstandard
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_shader = renderEngine.buildRenderProgram("Sphere",
|
||||
_shader = OsEng.renderEngine().buildRenderProgram("Sphere",
|
||||
"${MODULE_BASE}/shaders/sphere_vs.glsl",
|
||||
"${MODULE_BASE}/shaders/sphere_fs.glsl");
|
||||
if (!_shader)
|
||||
return false;
|
||||
|
||||
loadTexture();
|
||||
|
||||
@@ -131,28 +171,21 @@ bool RenderableSphere::initialize() {
|
||||
}
|
||||
|
||||
bool RenderableSphere::deinitialize() {
|
||||
delete _sphere;
|
||||
_sphere = nullptr;
|
||||
|
||||
_texture = nullptr;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_shader) {
|
||||
renderEngine.removeRenderProgram(_shader);
|
||||
OsEng.renderEngine().removeRenderProgram(_shader);
|
||||
_shader = nullptr;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderableSphere::render(const RenderData& data) {
|
||||
|
||||
glm::mat4 transform = glm::mat4(1.0);
|
||||
|
||||
transform = glm::rotate(transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
|
||||
|
||||
// Activate shader
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
_shader->activate();
|
||||
@@ -171,20 +204,40 @@ void RenderableSphere::render(const RenderData& data) {
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
bool usingFramebufferRenderer =
|
||||
OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::Framebuffer;
|
||||
|
||||
bool usingABufferRenderer =
|
||||
OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::ABuffer;
|
||||
|
||||
if (usingABufferRenderer) {
|
||||
_shader->setUniform("additiveBlending", true);
|
||||
}
|
||||
|
||||
if (usingFramebufferRenderer) {
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
}
|
||||
|
||||
_sphere->render();
|
||||
|
||||
if (usingFramebufferRenderer) {
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
_shader->setIgnoreUniformLocationError(IgnoreError::No);
|
||||
_shader->deactivate();
|
||||
}
|
||||
|
||||
void RenderableSphere::update(const UpdateData&) {
|
||||
if (_shader->isDirty())
|
||||
if (_shader->isDirty()) {
|
||||
_shader->rebuildFromFile();
|
||||
}
|
||||
|
||||
if (_sphereIsDirty) {
|
||||
delete _sphere;
|
||||
_sphere = new PowerScaledSphere(_size.value(), _segments);
|
||||
_sphere = std::make_unique<PowerScaledSphere>(
|
||||
PowerScaledScalar::CreatePSS(_size), _segments
|
||||
);
|
||||
_sphere->initialize();
|
||||
_sphereIsDirty = false;
|
||||
}
|
||||
@@ -194,7 +247,10 @@ void RenderableSphere::loadTexture() {
|
||||
if (_texturePath.value() != "") {
|
||||
std::unique_ptr<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(_texturePath);
|
||||
if (texture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'");
|
||||
LDEBUGC(
|
||||
"RenderableSphere",
|
||||
"Loaded texture from '" << absPath(_texturePath) << "'"
|
||||
);
|
||||
texture->uploadTexture();
|
||||
|
||||
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
|
||||
|
||||
@@ -26,19 +26,26 @@
|
||||
#define __OPENSPACE_MODULE_BASE___RENDERABLESPHERE___H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/scalar/intproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <openspace/properties/vector/vec2property.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
class Texture;
|
||||
}
|
||||
} // namespace ghoul
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class PowerScaledSphere;
|
||||
struct RenderData;
|
||||
struct UpdateData;
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
class RenderableSphere : public Renderable {
|
||||
public:
|
||||
@@ -52,13 +59,15 @@ public:
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
private:
|
||||
void loadTexture();
|
||||
|
||||
properties::StringProperty _texturePath;
|
||||
properties::OptionProperty _orientation;
|
||||
|
||||
properties::Vec2Property _size;
|
||||
properties::FloatProperty _size;
|
||||
properties::IntProperty _segments;
|
||||
|
||||
properties::FloatProperty _transparency;
|
||||
@@ -66,7 +75,7 @@ private:
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
|
||||
PowerScaledSphere* _sphere;
|
||||
std::unique_ptr<PowerScaledSphere> _sphere;
|
||||
|
||||
bool _sphereIsDirty;
|
||||
};
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
@@ -61,7 +62,8 @@ RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictio
|
||||
staticGrid = dictionary.getValue(KeyGridParentsRotation, _parentsRotation);
|
||||
}
|
||||
|
||||
dictionary.getValue(KeyGridSegments, _segments);
|
||||
_segments = static_cast<int>(dictionary.value<double>(KeyGridSegments));
|
||||
//dictionary.getValue(KeyGridSegments, _segments);
|
||||
|
||||
|
||||
/*glm::vec2 radius;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderableSphericalGrid : public Renderable{
|
||||
public:
|
||||
RenderableSphericalGrid(const ghoul::Dictionary& dictionary);
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/translation.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace {
|
||||
const char* KeyTranslation = "Translation";
|
||||
|
||||
@@ -73,6 +73,8 @@ class Translation;
|
||||
*/
|
||||
class RenderableTrail : public Renderable {
|
||||
public:
|
||||
~RenderableTrail() = default;
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/scene/translation.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
#include <numeric>
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/scene/translation.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
// This class creates the entire trajectory at once and keeps it in memory the entire
|
||||
// time. This means that there is no need for updating the trail at runtime, but also that
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include <openspace/properties/scalar/intproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
namespace ghoul {
|
||||
|
||||
@@ -28,10 +28,12 @@
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
#include <modules/kameleon/include/kameleonwrapper.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/filesystem/file.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <modules/globebrowsing/tile/tileselector.h>
|
||||
#include <modules/globebrowsing/tile/tilemetadata.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layergroup.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
||||
#include <modules/globebrowsing/tile/tileprovider/tileprovider.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunk.h>
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <modules/globebrowsing/chunk/chunk.h>
|
||||
#include <modules/globebrowsing/globes/renderableglobe.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
namespace ghoul { namespace opengl {
|
||||
class ProgramObject;
|
||||
} }
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <modules/globebrowsing/other/distanceswitch.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <modules/globebrowsing/rendering/gpu/gpulayermanager.h>
|
||||
#include <modules/globebrowsing/rendering/layer/layergroup.h>
|
||||
#include <modules/globebrowsing/tile/rawtiledatareader/rawtiledatareader.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
namespace {
|
||||
const char* keyFrame = "Frame";
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <modules/iswa/util/dataprocessortext.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "DataCygnet";
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include <modules/iswa/rendering/dataplane.h>
|
||||
#include <modules/iswa/util/dataprocessortext.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "DataPlane";
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include <openspace/util/powerscaledsphere.h>
|
||||
#include <modules/iswa/util/dataprocessorjson.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
@@ -28,6 +28,10 @@
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/transformationmanager.h>
|
||||
#include <modules/iswa/rendering/iswabasegroup.h>
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "IswaCygnet";
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "TexturePlane";
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace ghoul {
|
||||
namespace openspace {
|
||||
|
||||
struct RenderData;
|
||||
class RaycastData;
|
||||
struct RaycastData;
|
||||
|
||||
class KameleonVolumeRaycaster : public VolumeRaycaster {
|
||||
public:
|
||||
|
||||
@@ -24,12 +24,17 @@
|
||||
|
||||
#include <modules/newhorizons/rendering/renderablecrawlingline.h>
|
||||
|
||||
#include <modules/newhorizons/util/imagesequencer.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <modules/newhorizons/util/imagesequencer.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
namespace {
|
||||
const char* KeySource = "Source";
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <openspace/util/spicemanager.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/vector/vec3property.h>
|
||||
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace ghoul {
|
||||
|
||||
@@ -33,10 +33,10 @@
|
||||
|
||||
#include <openspace/util/spicemanager.h>
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class ProgramObject;
|
||||
}
|
||||
namespace opengl { class ProgramObject; }
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/framebufferobject.h>
|
||||
#include <ghoul/opengl/textureconversion.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <openspace/engine/virtualpropertymanager.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/interaction/luaconsole.h>
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
@@ -61,7 +62,8 @@ OnScreenGUIModule::OnScreenGUIModule()
|
||||
&(OsEng.settingsEngine()),
|
||||
&(OsEng.interactionHandler()),
|
||||
&(OsEng.renderEngine()),
|
||||
&(OsEng.parallelConnection())
|
||||
&(OsEng.parallelConnection()),
|
||||
&(OsEng.console())
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
|
||||
@@ -407,13 +407,22 @@ void renderVec3Property(Property* prop, const std::string& ownerName,
|
||||
float max = std::max(std::max(p->maxValue().x, p->maxValue().y), p->maxValue().z);
|
||||
|
||||
|
||||
ImGui::SliderFloat3(
|
||||
name.c_str(),
|
||||
glm::value_ptr(value),
|
||||
min,
|
||||
max,
|
||||
"%.5f"
|
||||
);
|
||||
|
||||
if (prop->viewOption(Property::ViewOptions::Color)) {
|
||||
ImGui::ColorEdit3(
|
||||
name.c_str(),
|
||||
glm::value_ptr(value)
|
||||
);
|
||||
}
|
||||
else {
|
||||
ImGui::SliderFloat3(
|
||||
name.c_str(),
|
||||
glm::value_ptr(value),
|
||||
min,
|
||||
max,
|
||||
"%.5f"
|
||||
);
|
||||
}
|
||||
renderTooltip(prop);
|
||||
|
||||
if (value != p->value()) {
|
||||
@@ -443,13 +452,22 @@ void renderVec4Property(Property* prop, const std::string& ownerName,
|
||||
float max = std::max(std::max(std::max(
|
||||
p->maxValue().x, p->maxValue().y), p->maxValue().z), p->maxValue().w);
|
||||
|
||||
ImGui::SliderFloat4(
|
||||
name.c_str(),
|
||||
&value.x,
|
||||
min,
|
||||
max,
|
||||
"%.5f"
|
||||
);
|
||||
if (prop->viewOption(Property::ViewOptions::Color)) {
|
||||
ImGui::ColorEdit4(
|
||||
name.c_str(),
|
||||
glm::value_ptr(value)
|
||||
);
|
||||
}
|
||||
else {
|
||||
ImGui::SliderFloat4(
|
||||
name.c_str(),
|
||||
glm::value_ptr(value),
|
||||
min,
|
||||
max,
|
||||
"%.5f"
|
||||
);
|
||||
}
|
||||
|
||||
renderTooltip(prop);
|
||||
|
||||
if (value != p->value()) {
|
||||
|
||||
@@ -22,17 +22,17 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
// openspace
|
||||
#include <modules/space/rendering/renderableconstellationbounds.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <modules/space/rendering/renderableconstellationbounds.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
// ghoul
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
// std
|
||||
#include <fstream>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
@@ -41,13 +41,12 @@
|
||||
#include "SpiceZpr.h"
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderableConstellationBounds";
|
||||
const char* KeyVertexFile = "File";
|
||||
const char* KeyConstellationFile = "ConstellationFile";
|
||||
const char* KeyReferenceFrame = "ReferenceFrame";
|
||||
|
||||
const char* keyVertexFile = "File";
|
||||
const char* keyConstellationFile = "ConstellationFile";
|
||||
const char* keyReferenceFrame = "ReferenceFrame";
|
||||
|
||||
const char* defaultReferenceFrame = "J2000";
|
||||
const char* DefaultReferenceFrame = "J2000";
|
||||
|
||||
float deg2rad(float deg) {
|
||||
return static_cast<float>((deg / 360.f) * 2.f * M_PI);
|
||||
@@ -56,12 +55,45 @@ namespace {
|
||||
// 360 degrees / 24h = 15 degrees/h
|
||||
return deg2rad(rightAscension * 15);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation RenderableConstellationBounds::Documentation() {
|
||||
using namespace documentation;
|
||||
return {
|
||||
"RenderableConstellationBounds",
|
||||
"space_renderable_constellationbounds",
|
||||
{
|
||||
{
|
||||
KeyVertexFile,
|
||||
new StringVerifier,
|
||||
"Specifies the file containing the bounds information about the "
|
||||
"constellation locations.",
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
KeyConstellationFile,
|
||||
new StringVerifier,
|
||||
"Specifies the file that contains the mapping between constellation "
|
||||
"abbreviations and full name of the constellation. If the file is "
|
||||
"omitted, the abbreviations are used as the full names.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
KeyReferenceFrame,
|
||||
new StringVerifier,
|
||||
"The reference frame in which the constellation points are stored in. "
|
||||
"Defaults to <code>J2000< / code>",
|
||||
Optional::Yes
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
RenderableConstellationBounds::RenderableConstellationBounds(
|
||||
const ghoul::Dictionary& dictionary)
|
||||
const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _vertexFilename("")
|
||||
, _constellationFilename("")
|
||||
@@ -71,66 +103,64 @@ RenderableConstellationBounds::RenderableConstellationBounds(
|
||||
, _vao(0)
|
||||
, _vbo(0)
|
||||
{
|
||||
bool success = dictionary.getValue(keyVertexFile, _vertexFilename);
|
||||
if (!success) {
|
||||
LERROR("RenderableConstellationBounds did not contain a key '" <<
|
||||
keyVertexFile << "'");
|
||||
documentation::testSpecificationAndThrow(
|
||||
Documentation(),
|
||||
dictionary,
|
||||
"RenderableConstellationBounds"
|
||||
);
|
||||
|
||||
_vertexFilename = dictionary.value<std::string>(KeyVertexFile);
|
||||
|
||||
if (dictionary.hasKey(KeyConstellationFile)) {
|
||||
_constellationFilename = dictionary.value<std::string>(KeyConstellationFile);
|
||||
}
|
||||
|
||||
dictionary.getValue(keyConstellationFile, _constellationFilename);
|
||||
|
||||
success = dictionary.getValue(keyReferenceFrame, _originReferenceFrame);
|
||||
if (!success) {
|
||||
_originReferenceFrame = defaultReferenceFrame;
|
||||
if (dictionary.hasKey(KeyReferenceFrame)) {
|
||||
_originReferenceFrame = dictionary.value<std::string>(KeyReferenceFrame);
|
||||
}
|
||||
else {
|
||||
_originReferenceFrame = DefaultReferenceFrame;
|
||||
}
|
||||
|
||||
addProperty(_distance);
|
||||
addProperty(_constellationSelection);
|
||||
_constellationSelection.onChange(
|
||||
std::bind(&RenderableConstellationBounds::selectionPropertyHasChanged, this)
|
||||
[this]() { selectionPropertyHasChanged(); }
|
||||
);
|
||||
}
|
||||
|
||||
bool RenderableConstellationBounds::initialize() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_program = renderEngine.buildRenderProgram("ConstellationBounds",
|
||||
_program = OsEng.renderEngine().buildRenderProgram("ConstellationBounds",
|
||||
"${MODULE_SPACE}/shaders/constellationbounds_vs.glsl",
|
||||
"${MODULE_SPACE}/shaders/constellationbounds_fs.glsl");
|
||||
|
||||
if (!_program)
|
||||
return false;
|
||||
|
||||
bool loadSuccess = loadVertexFile();
|
||||
if (!loadSuccess)
|
||||
if (!loadSuccess) {
|
||||
return false;
|
||||
}
|
||||
loadSuccess = loadConstellationFile();
|
||||
if (!loadSuccess)
|
||||
if (!loadSuccess) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fillSelectionProperty();
|
||||
|
||||
if (_vao == 0) {
|
||||
glGenVertexArrays(1, &_vao);
|
||||
LDEBUG("Generating Vertex Array id '" << _vao << "'");
|
||||
}
|
||||
if (_vbo == 0) {
|
||||
glGenBuffers(1, &_vbo);
|
||||
LDEBUG("Generating Vertex Buffer Object id '" << _vbo << "'");
|
||||
}
|
||||
|
||||
glGenVertexArrays(1, &_vao);
|
||||
glBindVertexArray(_vao);
|
||||
|
||||
glGenBuffers(1, &_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
_vertexValues.size() * 3 * sizeof(float),
|
||||
&_vertexValues[0],
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
_vertexValues.size() * 3 * sizeof(float),
|
||||
&_vertexValues[0],
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
|
||||
GLint positionAttrib = _program->attributeLocation("in_position");
|
||||
glEnableVertexAttribArray(positionAttrib);
|
||||
glVertexAttribPointer(positionAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
return true;
|
||||
@@ -142,9 +172,8 @@ bool RenderableConstellationBounds::deinitialize() {
|
||||
glDeleteVertexArrays(1, &_vao);
|
||||
_vao = 0;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_program) {
|
||||
renderEngine.removeRenderProgram(_program);
|
||||
OsEng.renderEngine().removeRenderProgram(_program);
|
||||
_program = nullptr;
|
||||
}
|
||||
|
||||
@@ -152,7 +181,7 @@ bool RenderableConstellationBounds::deinitialize() {
|
||||
}
|
||||
|
||||
bool RenderableConstellationBounds::isReady() const {
|
||||
return (_vao != 0) && (_vbo != 0) && (_program != nullptr);
|
||||
return (_vao != 0) && (_vbo != 0) && _program;
|
||||
}
|
||||
|
||||
void RenderableConstellationBounds::render(const RenderData& data) {
|
||||
@@ -168,7 +197,6 @@ void RenderableConstellationBounds::render(const RenderData& data) {
|
||||
for (const ConstellationBound& bound : _constellationBounds) {
|
||||
if (bound.isEnabled) {
|
||||
glDrawArrays(
|
||||
//GL_LINE_STRIP,
|
||||
GL_LINE_LOOP,
|
||||
static_cast<GLsizei>(bound.startIndex),
|
||||
static_cast<GLsizei>(bound.nVertices)
|
||||
@@ -188,46 +216,49 @@ void RenderableConstellationBounds::update(const UpdateData& data) {
|
||||
}
|
||||
|
||||
bool RenderableConstellationBounds::loadVertexFile() {
|
||||
if (_vertexFilename.empty())
|
||||
return false;
|
||||
|
||||
std::string fileName = absPath(_vertexFilename);
|
||||
std::ifstream file(fileName);
|
||||
if (!file.good()) {
|
||||
LERROR("Could not open file '" << fileName << "' for reading");
|
||||
if (_vertexFilename.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string fileName = absPath(_vertexFilename);
|
||||
std::ifstream file;
|
||||
file.exceptions(std::ifstream::goodbit);
|
||||
file.open(fileName);
|
||||
|
||||
ConstellationBound currentBound;
|
||||
currentBound.constellationAbbreviation = "";
|
||||
|
||||
std::string currentLine;
|
||||
int currentLineNumber = 1;
|
||||
|
||||
float ra;
|
||||
float dec;
|
||||
std::string constellationName;
|
||||
double rectangularValues[3];
|
||||
|
||||
// Overview of the reading algorithm:
|
||||
// We keep an active ConstellationBound (currentBound) and update it until we read
|
||||
// a new constellation name, at which point the currentBound is stored away, a new,
|
||||
// empty ConstellationBound is created and set at the currentBound
|
||||
while (file.good()) {
|
||||
std::getline(file, currentLine);
|
||||
if (currentLine.empty())
|
||||
if (currentLine.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// @CHECK: Is this the best way of doing this? ---abock
|
||||
std::stringstream s(currentLine);
|
||||
float ra;
|
||||
s >> ra;
|
||||
|
||||
float dec;
|
||||
s >> dec;
|
||||
|
||||
std::string constellationName;
|
||||
s >> constellationName;
|
||||
|
||||
if (!s.good()) {
|
||||
// If this evaluates to true, the stream was not completely filled, which
|
||||
// means that the line was incomplete, so there was an error
|
||||
LERROR("Error reading file '" << fileName << "' at line #" << currentLineNumber);
|
||||
LERRORC(
|
||||
"RenderableConstellationBounds",
|
||||
"Error reading file '" << fileName << "' at line #" << currentLineNumber
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -254,6 +285,7 @@ bool RenderableConstellationBounds::loadVertexFile() {
|
||||
// Convert the (right ascension, declination) to rectangular coordinates)
|
||||
// The 1.0 is the distance of the celestial sphere, we will scale that in the
|
||||
// render function
|
||||
double rectangularValues[3];
|
||||
radrec_c(1.0, ra, dec, rectangularValues);
|
||||
|
||||
// Add the new vertex to our list of vertices
|
||||
@@ -277,39 +309,43 @@ bool RenderableConstellationBounds::loadVertexFile() {
|
||||
}
|
||||
|
||||
bool RenderableConstellationBounds::loadConstellationFile() {
|
||||
if (_constellationFilename.empty())
|
||||
if (_constellationFilename.empty()) {
|
||||
return true;
|
||||
|
||||
std::string fileName = absPath(_constellationFilename);
|
||||
std::ifstream file(fileName);
|
||||
if (!file.good()) {
|
||||
LERROR("Could not open file '" << fileName << "' for reading");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ifstream file;
|
||||
file.exceptions(std::ifstream::goodbit);
|
||||
file.open(absPath(_constellationFilename));
|
||||
|
||||
std::string line;
|
||||
int index = 0;
|
||||
while (file.good()) {
|
||||
std::getline(file, line);
|
||||
if (line.empty())
|
||||
std::getline(file, line);
|
||||
if (line.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string abbreviation;
|
||||
std::stringstream s(line);
|
||||
s >> abbreviation;
|
||||
|
||||
auto it = std::find_if(_constellationBounds.begin(), _constellationBounds.end(),
|
||||
auto it = std::find_if(
|
||||
_constellationBounds.begin(),
|
||||
_constellationBounds.end(),
|
||||
[abbreviation](const ConstellationBound& bound) {
|
||||
return bound.constellationAbbreviation == abbreviation;
|
||||
});
|
||||
}
|
||||
);
|
||||
if (it == _constellationBounds.end()) {
|
||||
LERROR("Could not find constellation '" << abbreviation << "' in list");
|
||||
LERRORC(
|
||||
"RenderableConstellationBounds",
|
||||
"Could not find constellation '" << abbreviation << "' in list"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update the constellations full name
|
||||
s >> it->constellationFullName;
|
||||
|
||||
++index;
|
||||
}
|
||||
|
||||
@@ -329,18 +365,21 @@ void RenderableConstellationBounds::selectionPropertyHasChanged() {
|
||||
const std::vector<int>& values = _constellationSelection;
|
||||
// If no values are selected (the default), we want to show all constellations
|
||||
if (values.size() == 0) {
|
||||
for (ConstellationBound& b : _constellationBounds)
|
||||
for (ConstellationBound& b : _constellationBounds) {
|
||||
b.isEnabled = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// In the worst case, this algorithm runs with 2 * nConstellations, which is
|
||||
// acceptable as the number of constellations is < 100
|
||||
// First disable all constellations
|
||||
for (ConstellationBound& b : _constellationBounds)
|
||||
for (ConstellationBound& b : _constellationBounds) {
|
||||
b.isEnabled = false;
|
||||
}
|
||||
// then re-enable the ones for which we have indices
|
||||
for (int value : values)
|
||||
for (int value : values) {
|
||||
_constellationBounds[value].isEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
/**
|
||||
* This class renders the constellation bounds as defined in
|
||||
* http://cdsarc.u-strasbg.fr/viz-bin/Cat?cat=VI%2F49. It contains the bounds on the
|
||||
@@ -42,14 +44,6 @@ namespace openspace {
|
||||
* The bounds are drawn as lines on a sphere with variable radius, set by the
|
||||
* <code>_distance</code> property. Currently, all constellation bounds are lines, which
|
||||
* leads to artifacts if the radius is very small.
|
||||
* Renderable configuration attributes:
|
||||
* <code>File</code> [string] (required): The file that contains the bounds and the
|
||||
* abbreviations for the different constellations
|
||||
* <code>ConstellationFile</code> [string]: The file that contains the mapping between
|
||||
* abbreviations and full names. If the file is omitted, the abbreviations are used as the
|
||||
* full names.
|
||||
* <code>ReferenceFrame</code> [string]: The reference frame in which the points contained
|
||||
* in the <code>File</code> are stored in. Defaults to <code>J2000</code>
|
||||
*/
|
||||
class RenderableConstellationBounds : public Renderable {
|
||||
public:
|
||||
@@ -63,6 +57,8 @@ public:
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
private:
|
||||
/// Stores the constellation bounds
|
||||
struct ConstellationBound {
|
||||
@@ -106,7 +102,7 @@ private:
|
||||
/// The list of all loaded constellation bounds
|
||||
std::vector<ConstellationBound> _constellationBounds;
|
||||
|
||||
typedef std::array<float, 3> Vertex;
|
||||
using Vertex = std::array<float, 3>;
|
||||
std::vector<Vertex> _vertexValues; ///< A list of all vertices of all bounds
|
||||
|
||||
/// The radius of the celestial sphere onto which the bounds are drawn
|
||||
|
||||
@@ -22,9 +22,11 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
// open space includes
|
||||
#include <modules/space/rendering/renderableplanet.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
@@ -39,6 +41,7 @@
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/misc/invariants.h>
|
||||
|
||||
#include <memory>
|
||||
#include <fstream>
|
||||
@@ -48,21 +51,76 @@
|
||||
|
||||
|
||||
namespace {
|
||||
const char* KeyGeometry = "Geometry";
|
||||
const char* KeyRadius = "Radius";
|
||||
const char* KeyColorTexture = "Textures.Color";
|
||||
const char* KeyNightTexture = "Textures.Night";
|
||||
const char* KeyHeightTexture = "Textures.Height";
|
||||
const char* KeyShading = "PerformShading";
|
||||
|
||||
|
||||
|
||||
static const std::string _loggerCat = "RenderablePlanet";
|
||||
|
||||
const char* keyFrame = "Frame";
|
||||
const char* keyGeometry = "Geometry";
|
||||
const char* keyRadius = "Radius";
|
||||
const char* keyShading = "PerformShading";
|
||||
const char* keyShadowGroup = "Shadow_Group";
|
||||
const char* keyShadowSource = "Source";
|
||||
const char* keyShadowCaster = "Caster";
|
||||
// const char* keyPlanetRadius = "PlanetRadius";
|
||||
const char* keyBody = "Body";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation RenderablePlanet::Documentation() {
|
||||
using namespace documentation;
|
||||
return {
|
||||
"RenderablePlanet",
|
||||
"space_renderable_planet",
|
||||
{
|
||||
{
|
||||
KeyGeometry,
|
||||
new ReferencingVerifier("space_geometry_planet"),
|
||||
"Specifies the planet geometry that is used for this RenderablePlanet.",
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
KeyRadius,
|
||||
new DoubleVerifier,
|
||||
"Specifies the radius of the planet. If this value is not specified, it "
|
||||
"will try to query the SPICE library for radius values.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
KeyColorTexture,
|
||||
new StringVerifier,
|
||||
"Specifies the color texture that is used for this RenderablePlanet.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
KeyHeightTexture,
|
||||
new StringVerifier,
|
||||
"Specifies the height texture that is used for this RenderablePlanet.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
KeyNightTexture,
|
||||
new StringVerifier,
|
||||
"Specifies the texture that is used for the night side of this "
|
||||
"RenderablePlanet.",
|
||||
Optional::Yes
|
||||
},
|
||||
{
|
||||
KeyShading,
|
||||
new BoolVerifier,
|
||||
"Specifies whether the planet should be rendered shaded by the Sun. If "
|
||||
"this value is 'false', any existing night texture will not be used. "
|
||||
"This value defaults to 'true'.",
|
||||
Optional::Yes
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _colorTexturePath("colorTexture", "Color Texture")
|
||||
@@ -74,106 +132,83 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
, _heightExaggeration("heightExaggeration", "Height Exaggeration", 1.f, 0.f, 10.f)
|
||||
, _geometry(nullptr)
|
||||
, _performShading("performShading", "Perform Shading", true)
|
||||
, _rotation("rotation", "Rotation", 0, 0, 360)
|
||||
, _alpha(1.f)
|
||||
, _planetRadius(0.f)
|
||||
, _hasNightTexture(false)
|
||||
, _hasHeightTexture(false)
|
||||
, _shadowEnabled(false)
|
||||
{
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
|
||||
ghoul_assert(
|
||||
success,
|
||||
std::string("RenderablePlanet need the '") + SceneGraphNode::KeyName +
|
||||
"' be specified"
|
||||
ghoul_precondition(
|
||||
dictionary.hasKeyAndValue<std::string>(SceneGraphNode::KeyName),
|
||||
"RenderablePlanet needs the name to be specified"
|
||||
);
|
||||
|
||||
ghoul::Dictionary geometryDictionary;
|
||||
success = dictionary.getValue(keyGeometry, geometryDictionary);
|
||||
documentation::testSpecificationAndThrow(
|
||||
Documentation(),
|
||||
dictionary,
|
||||
"RenderablePlanet"
|
||||
);
|
||||
|
||||
const std::string name = dictionary.value<std::string>(SceneGraphNode::KeyName);
|
||||
|
||||
glm::dvec3 radius;
|
||||
bool accutareRadius = false;
|
||||
try {
|
||||
SpiceManager::ref().getValue(name, "RADII", radius);
|
||||
accutareRadius = true;
|
||||
} catch (const SpiceManager::SpiceException& e) {
|
||||
accutareRadius = false;
|
||||
ghoul::Dictionary geomDict = dictionary.value<ghoul::Dictionary>(KeyGeometry);
|
||||
|
||||
if (dictionary.hasKey(KeyRadius)) {
|
||||
// If the user specified a radius, we want to use this
|
||||
_planetRadius = dictionary.value<double>(KeyRadius);
|
||||
}
|
||||
|
||||
if (accutareRadius) {
|
||||
else if (SpiceManager::ref().hasValue(name, "RADII") ) {
|
||||
// If the user didn't specfify a radius, but Spice has a radius, we can use this
|
||||
glm::dvec3 radius;
|
||||
SpiceManager::ref().getValue(name, "RADII", radius);
|
||||
radius *= 1000.0; // Spice gives radii in KM.
|
||||
std::swap(radius[1], radius[2]); // z is equivalent to y in our coordinate system
|
||||
geometryDictionary.setValue(keyRadius, radius);
|
||||
geomDict.setValue(KeyRadius, radius);
|
||||
|
||||
_planetRadius = (radius.x + radius.y + radius.z) / 3.0;
|
||||
}
|
||||
else {
|
||||
LERRORC("RenderablePlanet", "Missing radius specification");
|
||||
}
|
||||
|
||||
if (success) {
|
||||
//geometryDictionary.setValue(SceneGraphNode::KeyName, name);
|
||||
_geometry = planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary);
|
||||
|
||||
float planetRadius;
|
||||
if (accutareRadius) {
|
||||
_planetRadius = (radius[0] + radius[1] + radius[2]) / 3.0;
|
||||
} else if (geometryDictionary.getValue(keyRadius, planetRadius)) {
|
||||
_planetRadius = planetRadius;
|
||||
}
|
||||
else {
|
||||
LWARNING("No Radius value specified for " << name << " planet.");
|
||||
}
|
||||
_geometry = planetgeometry::PlanetGeometry::createFromDictionary(geomDict);
|
||||
|
||||
if (dictionary.hasKey(KeyColorTexture)) {
|
||||
_colorTexturePath = absPath(dictionary.value<std::string>(KeyColorTexture));
|
||||
}
|
||||
|
||||
dictionary.getValue(keyFrame, _frame);
|
||||
dictionary.getValue(keyBody, _target);
|
||||
|
||||
|
||||
// TODO: textures need to be replaced by a good system similar to the geometry as soon
|
||||
// as the requirements are fixed (ab)
|
||||
std::string texturePath = "";
|
||||
success = dictionary.getValue("Textures.Color", texturePath);
|
||||
if (success)
|
||||
_colorTexturePath = absPath(texturePath);
|
||||
|
||||
std::string nightTexturePath = "";
|
||||
dictionary.getValue("Textures.Night", nightTexturePath);
|
||||
if (nightTexturePath != ""){
|
||||
if (dictionary.hasKey(KeyNightTexture)) {
|
||||
_hasNightTexture = true;
|
||||
_nightTexturePath = absPath(nightTexturePath);
|
||||
_nightTexturePath = absPath(dictionary.value<std::string>(KeyNightTexture));
|
||||
}
|
||||
|
||||
std::string heightMapTexturePath = "";
|
||||
dictionary.getValue("Textures.Height", heightMapTexturePath);
|
||||
if (heightMapTexturePath != "") {
|
||||
|
||||
if (dictionary.hasKey(KeyHeightTexture)) {
|
||||
_hasHeightTexture = true;
|
||||
_heightMapTexturePath = absPath(heightMapTexturePath);
|
||||
_heightMapTexturePath = absPath(dictionary.value<std::string>(KeyHeightTexture));
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(KeyShading)) {
|
||||
_performShading = dictionary.value<bool>(KeyShading);
|
||||
}
|
||||
|
||||
addPropertySubOwner(_geometry.get());
|
||||
|
||||
auto loadTextureCallback = [this]() {loadTexture(); };
|
||||
addProperty(_colorTexturePath);
|
||||
_colorTexturePath.onChange(std::bind(&RenderablePlanet::loadTexture, this));
|
||||
_colorTexturePath.onChange(loadTextureCallback);
|
||||
|
||||
addProperty(_nightTexturePath);
|
||||
_nightTexturePath.onChange(std::bind(&RenderablePlanet::loadTexture, this));
|
||||
_nightTexturePath.onChange(loadTextureCallback);
|
||||
|
||||
addProperty(_heightMapTexturePath);
|
||||
_heightMapTexturePath.onChange(std::bind(&RenderablePlanet::loadTexture, this));
|
||||
_heightMapTexturePath.onChange(loadTextureCallback);
|
||||
|
||||
addProperty(_heightExaggeration);
|
||||
|
||||
if (dictionary.hasKeyAndValue<bool>(keyShading)) {
|
||||
bool shading;
|
||||
dictionary.getValue(keyShading, shading);
|
||||
_performShading = shading;
|
||||
}
|
||||
|
||||
addProperty(_performShading);
|
||||
// Mainly for debugging purposes @AA
|
||||
addProperty(_rotation);
|
||||
|
||||
// Shadow data:
|
||||
ghoul::Dictionary shadowDictionary;
|
||||
success = dictionary.getValue(keyShadowGroup, shadowDictionary);
|
||||
bool success = dictionary.getValue(keyShadowGroup, shadowDictionary);
|
||||
bool disableShadows = false;
|
||||
if (success) {
|
||||
std::vector< std::pair<std::string, float > > sourceArray;
|
||||
@@ -247,9 +282,6 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
}
|
||||
|
||||
RenderablePlanet::~RenderablePlanet() {
|
||||
}
|
||||
|
||||
bool RenderablePlanet::initialize() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
|
||||
@@ -267,8 +299,6 @@ bool RenderablePlanet::initialize() {
|
||||
"shadowNightProgram",
|
||||
"${MODULE_SPACE}/shaders/shadow_nighttexture_vs.glsl",
|
||||
"${MODULE_SPACE}/shaders/shadow_nighttexture_fs.glsl");
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
else if (_programObject == nullptr && _shadowEnabled) {
|
||||
// shadow program
|
||||
@@ -276,8 +306,6 @@ bool RenderablePlanet::initialize() {
|
||||
"shadowProgram",
|
||||
"${MODULE_SPACE}/shaders/shadow_vs.glsl",
|
||||
"${MODULE_SPACE}/shaders/shadow_fs.glsl");
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
else if (_programObject == nullptr && _hasNightTexture) {
|
||||
// Night texture program
|
||||
@@ -285,8 +313,6 @@ bool RenderablePlanet::initialize() {
|
||||
"nightTextureProgram",
|
||||
"${MODULE_SPACE}/shaders/nighttexture_vs.glsl",
|
||||
"${MODULE_SPACE}/shaders/nighttexture_fs.glsl");
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
else if (_programObject == nullptr) {
|
||||
// pscstandard
|
||||
@@ -294,8 +320,6 @@ bool RenderablePlanet::initialize() {
|
||||
"pscstandard",
|
||||
"${MODULE_SPACE}/shaders/renderableplanet_vs.glsl",
|
||||
"${MODULE_SPACE}/shaders/renderableplanet_fs.glsl");
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
_programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
@@ -323,7 +347,7 @@ bool RenderablePlanet::initialize() {
|
||||
}
|
||||
|
||||
bool RenderablePlanet::deinitialize() {
|
||||
if(_geometry) {
|
||||
if (_geometry) {
|
||||
_geometry->deinitialize();
|
||||
_geometry = nullptr;
|
||||
}
|
||||
@@ -334,9 +358,9 @@ bool RenderablePlanet::deinitialize() {
|
||||
_programObject = nullptr;
|
||||
}
|
||||
|
||||
_geometry = nullptr;
|
||||
_texture = nullptr;
|
||||
_nightTexture = nullptr;
|
||||
_geometry = nullptr;
|
||||
_texture = nullptr;
|
||||
_nightTexture = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ namespace planetgeometry {
|
||||
class PlanetGeometry;
|
||||
}
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
class RenderablePlanet : public Renderable {
|
||||
public:
|
||||
// Shadow structure
|
||||
@@ -69,8 +71,7 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
explicit RenderablePlanet(const ghoul::Dictionary& dictionary);
|
||||
~RenderablePlanet();
|
||||
RenderablePlanet(const ghoul::Dictionary& dictionary);
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
@@ -79,6 +80,8 @@ public:
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
protected:
|
||||
void loadTexture();
|
||||
private:
|
||||
@@ -96,14 +99,11 @@ private:
|
||||
|
||||
std::unique_ptr<planetgeometry::PlanetGeometry> _geometry;
|
||||
properties::BoolProperty _performShading;
|
||||
properties::IntProperty _rotation;
|
||||
float _alpha;
|
||||
std::vector< ShadowConf > _shadowConfArray;
|
||||
float _planetRadius;
|
||||
|
||||
glm::dmat3 _stateMatrix;
|
||||
std::string _frame;
|
||||
std::string _target;
|
||||
bool _hasNightTexture;
|
||||
bool _hasHeightTexture;
|
||||
bool _shadowEnabled;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace filesystem { class File; }
|
||||
namespace opengl {
|
||||
@@ -40,7 +42,8 @@ namespace opengl {
|
||||
} // namespace ghoul
|
||||
|
||||
namespace openspace {
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
namespace documentation { struct Documentation; }
|
||||
|
||||
class RenderableStars : public Renderable {
|
||||
public:
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <modules/space/rendering/simplespheregeometry.h>
|
||||
#include <openspace/util/powerscaledsphere.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "SimpleSphereGeometry";
|
||||
|
||||
@@ -82,9 +82,12 @@ void SpaceModule::internalInitialize() {
|
||||
|
||||
std::vector<documentation::Documentation> SpaceModule::documentations() const {
|
||||
return {
|
||||
RenderableConstellationBounds::Documentation(),
|
||||
RenderablePlanet::Documentation(),
|
||||
RenderableRings::Documentation(),
|
||||
RenderableStars::Documentation(),
|
||||
SpiceRotation::Documentation(),
|
||||
SpiceTranslation::Documentation(),
|
||||
RenderableRings::Documentation(),
|
||||
planetgeometry::PlanetGeometry::Documentation()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace ghoul {
|
||||
namespace openspace {
|
||||
|
||||
struct RenderData;
|
||||
class RaycastData;
|
||||
struct RaycastData;
|
||||
|
||||
class ToyVolumeRaycaster : public VolumeRaycaster {
|
||||
public:
|
||||
|
||||
+2
-1
@@ -51,7 +51,8 @@ return {
|
||||
},
|
||||
Fonts = {
|
||||
Mono = "${FONTS}/Droid_Sans_Mono/DroidSansMono.ttf",
|
||||
Light = "${FONTS}/Roboto/Roboto-Regular.ttf"
|
||||
Light = "${FONTS}/Roboto/Roboto-Regular.ttf",
|
||||
Console = "${FONTS}/Inconsolata/Inconsolata-Regular.ttf"
|
||||
},
|
||||
Logging = {
|
||||
-- LogLevel = "Trace",
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#version __CONTEXT__
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec4 color;
|
||||
|
||||
void main() {
|
||||
FragColor = color;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#version __CONTEXT__
|
||||
|
||||
in vec2 in_position;
|
||||
|
||||
uniform float height;
|
||||
uniform ivec2 res;
|
||||
|
||||
uniform mat4 ortho;
|
||||
|
||||
void main() {
|
||||
float y = float(res.y) - in_position.y * height * res.y;
|
||||
|
||||
gl_Position = ortho * vec4(in_position.x * res.x, y, 0.0, 1.0);
|
||||
}
|
||||
@@ -152,6 +152,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName,
|
||||
_globalPropertyNamespace->addPropertySubOwner(_renderEngine.get());
|
||||
_globalPropertyNamespace->addPropertySubOwner(_windowWrapper.get());
|
||||
_globalPropertyNamespace->addPropertySubOwner(_parallelConnection.get());
|
||||
_globalPropertyNamespace->addPropertySubOwner(_console.get());
|
||||
|
||||
FactoryManager::initialize();
|
||||
FactoryManager::ref().addFactory(
|
||||
@@ -346,7 +347,6 @@ void OpenSpaceEngine::create(int argc, char** argv,
|
||||
FileSys.createCacheManager(
|
||||
absPath("${" + ConfigurationManager::KeyCache + "}"), CacheVersion
|
||||
);
|
||||
_engine->_console->initialize();
|
||||
|
||||
// Register the provided shader directories
|
||||
ghoul::opengl::ShaderPreprocessor::addIncludePath(absPath("${SHADERS}"));
|
||||
@@ -843,6 +843,8 @@ void OpenSpaceEngine::configureLogging() {
|
||||
void OpenSpaceEngine::initializeGL() {
|
||||
LTRACE("OpenSpaceEngine::initializeGL(begin)");
|
||||
|
||||
_engine->_console->initialize();
|
||||
|
||||
const std::string key = ConfigurationManager::KeyOpenGLDebugContext;
|
||||
if (_configurationManager->hasKey(key)) {
|
||||
ghoul::Dictionary dict = _configurationManager->value<ghoul::Dictionary>(key);
|
||||
@@ -1073,17 +1075,24 @@ void OpenSpaceEngine::render(const glm::mat4& sceneMatrix,
|
||||
const glm::mat4& viewMatrix,
|
||||
const glm::mat4& projectionMatrix)
|
||||
{
|
||||
|
||||
bool isGuiWindow = _windowWrapper->hasGuiWindow() ? _windowWrapper->isGuiWindow() : true;
|
||||
bool showOverlay = isGuiWindow && _windowWrapper->isMaster() && _windowWrapper->isRegularRendering();
|
||||
// @CLEANUP: Replace the two windows by a single call to whether a gui should be
|
||||
// rendered ---abock
|
||||
|
||||
if (showOverlay) {
|
||||
_console->update();
|
||||
}
|
||||
|
||||
LTRACE("OpenSpaceEngine::render(begin)");
|
||||
_renderEngine->render(sceneMatrix, viewMatrix, projectionMatrix);
|
||||
|
||||
for (const auto& func : _moduleCallbacks.render) {
|
||||
func();
|
||||
}
|
||||
|
||||
// @CLEANUP: Replace the two windows by a single call to whether a gui should be
|
||||
// rendered ---abock
|
||||
bool showGui = _windowWrapper->hasGuiWindow() ? _windowWrapper->isGuiWindow() : true;
|
||||
if (showGui && _windowWrapper->isMaster() && _windowWrapper->isRegularRendering()) {
|
||||
|
||||
if (showOverlay) {
|
||||
_renderEngine->renderScreenLog();
|
||||
_console->render();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <openspace/query/query.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/keys.h>
|
||||
|
||||
|
||||
+377
-154
@@ -25,6 +25,7 @@
|
||||
#include <openspace/interaction/luaconsole.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
|
||||
#include <ghoul/filesystem/cachemanager.h>
|
||||
@@ -34,6 +35,9 @@
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/misc/clipboard.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@@ -43,6 +47,8 @@ namespace {
|
||||
|
||||
const int NoAutoComplete = -1;
|
||||
|
||||
const int MaximumHistoryLength = 1000;
|
||||
|
||||
// A high number is chosen since we didn't have a version number before
|
||||
// any small number might also be equal to the console history length
|
||||
|
||||
@@ -51,6 +57,17 @@ namespace {
|
||||
const uint64_t CurrentVersion = 0xFEEEFEEE00000001;
|
||||
|
||||
const openspace::Key CommandInputButton = openspace::Key::GraveAccent;
|
||||
|
||||
const char* FontName = "Console";
|
||||
const float EntryFontSize = 14.0f;
|
||||
const float HistoryFontSize = 11.0f;
|
||||
|
||||
// Additional space between the entry text and the history (in pixels)
|
||||
const float SeparatorSpace = 30.f;
|
||||
|
||||
// Determines at which speed the console opens.
|
||||
const float ConsoleOpenSpeed = 2.5;
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -59,27 +76,77 @@ LuaConsole::LuaConsole()
|
||||
: properties::PropertyOwner("LuaConsole")
|
||||
, _isVisible("isVisible", "Is Visible", false)
|
||||
, _remoteScripting("remoteScripting", "Remote scripting", false)
|
||||
, _backgroundColor(
|
||||
"backgroundColor",
|
||||
"Background Color",
|
||||
glm::vec4(21.f / 255.f, 23.f / 255.f, 28.f / 255.f, 0.8f),
|
||||
glm::vec4(0.f),
|
||||
glm::vec4(1.f)
|
||||
)
|
||||
, _highlightColor(
|
||||
"highlightColor",
|
||||
"Highlight Color",
|
||||
glm::vec4(1.f, 1.f, 1.f, 0.f),
|
||||
glm::vec4(0.f),
|
||||
glm::vec4(1.f)
|
||||
)
|
||||
, _separatorColor(
|
||||
"separatorColor",
|
||||
"Separator Color",
|
||||
glm::vec4(0.4f, 0.4f, 0.4f, 0.f),
|
||||
glm::vec4(0.f),
|
||||
glm::vec4(1.f)
|
||||
)
|
||||
, _entryTextColor(
|
||||
"entryTextColor",
|
||||
"Entry Text Color",
|
||||
glm::vec4(1.f, 1.f, 1.f, 1.f),
|
||||
glm::vec4(0.f),
|
||||
glm::vec4(1.f)
|
||||
)
|
||||
, _historyTextColor(
|
||||
"historyTextColor",
|
||||
"History Text Color",
|
||||
glm::vec4(1.0f, 1.0f, 1.0f, 0.65f),
|
||||
glm::vec4(0.f),
|
||||
glm::vec4(1.f)
|
||||
)
|
||||
, _historyLength("historyLength", "History Length", 13, 0, 100)
|
||||
, _inputPosition(0)
|
||||
, _activeCommand(0)
|
||||
, _autoCompleteInfo({NoAutoComplete, false, ""})
|
||||
, _currentHeight(0.f)
|
||||
, _targetHeight(0.f)
|
||||
, _fullHeight(0.f)
|
||||
{
|
||||
addProperty(_isVisible);
|
||||
addProperty(_remoteScripting);
|
||||
|
||||
addProperty(_historyLength);
|
||||
|
||||
_backgroundColor.setViewOption(properties::Property::ViewOptions::Color);
|
||||
addProperty(_backgroundColor);
|
||||
_highlightColor.setViewOption(properties::Property::ViewOptions::Color);
|
||||
addProperty(_highlightColor);
|
||||
_separatorColor.setViewOption(properties::Property::ViewOptions::Color);
|
||||
addProperty(_separatorColor);
|
||||
_entryTextColor.setViewOption(properties::Property::ViewOptions::Color);
|
||||
addProperty(_entryTextColor);
|
||||
_historyTextColor.setViewOption(properties::Property::ViewOptions::Color);
|
||||
addProperty(_historyTextColor);
|
||||
}
|
||||
|
||||
void LuaConsole::initialize() {
|
||||
std::string filename = FileSys.cacheManager()->cachedFilename(
|
||||
const std::string filename = FileSys.cacheManager()->cachedFilename(
|
||||
HistoryFile,
|
||||
"",
|
||||
ghoul::filesystem::CacheManager::Persistent::Yes
|
||||
);
|
||||
|
||||
try {
|
||||
if (FileSys.fileExists(filename)) {
|
||||
std::ifstream file;
|
||||
file.exceptions(std::ofstream::badbit);
|
||||
file.open(filename, std::ios::binary | std::ios::in);
|
||||
|
||||
if (FileSys.fileExists(filename)) {
|
||||
std::ifstream file(filename, std::ios::binary | std::ios::in);
|
||||
|
||||
if (file.good()) {
|
||||
// Read the number of commands from the history
|
||||
uint64_t version;
|
||||
file.read(reinterpret_cast<char*>(&version), sizeof(uint64_t));
|
||||
@@ -94,8 +161,6 @@ void LuaConsole::initialize() {
|
||||
int64_t nCommands;
|
||||
file.read(reinterpret_cast<char*>(&nCommands), sizeof(int64_t));
|
||||
|
||||
// @TODO: Add an upper limit on the number of commands so that the history
|
||||
// can't grow without bounds
|
||||
for (int64_t i = 0; i < nCommands; ++i) {
|
||||
int64_t length;
|
||||
file.read(reinterpret_cast<char*>(&length), sizeof(int64_t));
|
||||
@@ -105,17 +170,52 @@ void LuaConsole::initialize() {
|
||||
_commandsHistory.emplace_back(std::string(tmp.begin(), tmp.end()));
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
LERRORC("LuaConsole", e.what());
|
||||
}
|
||||
|
||||
_commands = _commandsHistory;
|
||||
_commands.push_back("");
|
||||
_activeCommand = _commands.size() - 1;
|
||||
|
||||
_program = ghoul::opengl::ProgramObject::Build(
|
||||
"Console",
|
||||
"${SHADERS}/luaconsole.vert",
|
||||
"${SHADERS}/luaconsole.frag"
|
||||
);
|
||||
|
||||
GLfloat data[] = {
|
||||
0.f, 0.f,
|
||||
1.f, 1.f,
|
||||
0.f, 1.f,
|
||||
|
||||
0.f, 0.f,
|
||||
1.f, 0.f,
|
||||
1.f, 1.f
|
||||
};
|
||||
|
||||
glGenVertexArrays(1, &_vao);
|
||||
glBindVertexArray(_vao);
|
||||
glGenBuffers(1, &_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
2,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
2 * sizeof(GLfloat),
|
||||
reinterpret_cast<void*>(0)
|
||||
);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
_font = OsEng.fontManager().font(FontName, EntryFontSize);
|
||||
|
||||
_historyFont = OsEng.fontManager().font(FontName, HistoryFontSize);
|
||||
|
||||
|
||||
OsEng.parallelConnection().connectionEvent()->subscribe(
|
||||
"luaConsole",
|
||||
"statusChanged",
|
||||
@@ -127,27 +227,39 @@ void LuaConsole::initialize() {
|
||||
}
|
||||
|
||||
void LuaConsole::deinitialize() {
|
||||
std::string filename = FileSys.cacheManager()->cachedFilename(
|
||||
const std::string filename = FileSys.cacheManager()->cachedFilename(
|
||||
HistoryFile,
|
||||
"",
|
||||
ghoul::filesystem::CacheManager::Persistent::Yes
|
||||
);
|
||||
|
||||
std::ofstream file(filename);
|
||||
|
||||
uint64_t version = CurrentVersion;
|
||||
file.write(reinterpret_cast<const char*>(&version), sizeof(uint64_t));
|
||||
|
||||
int64_t nCommands = _commandsHistory.size();
|
||||
file.write(reinterpret_cast<const char*>(&nCommands), sizeof(int64_t));
|
||||
|
||||
for (const std::string& s : _commandsHistory) {
|
||||
int64_t length = s.length();
|
||||
file.write(reinterpret_cast<const char*>(&length), sizeof(int64_t));
|
||||
// We don't write the \0 at the end on purpose
|
||||
file.write(s.c_str(), length);
|
||||
// We want to limit the command history to a realistic value, so that it doesn't
|
||||
// grow without bounds
|
||||
if (_commandsHistory.size() > MaximumHistoryLength) {
|
||||
_commandsHistory = std::vector<std::string>(
|
||||
_commandsHistory.end() - MaximumHistoryLength,
|
||||
_commandsHistory.end()
|
||||
);
|
||||
}
|
||||
|
||||
std::ofstream file(filename, std::ios::binary);
|
||||
if (file.good()) {
|
||||
uint64_t version = CurrentVersion;
|
||||
file.write(reinterpret_cast<const char*>(&version), sizeof(uint64_t));
|
||||
|
||||
int64_t nCommands = _commandsHistory.size();
|
||||
file.write(reinterpret_cast<const char*>(&nCommands), sizeof(int64_t));
|
||||
|
||||
for (const std::string& s : _commandsHistory) {
|
||||
int64_t length = s.length();
|
||||
file.write(reinterpret_cast<const char*>(&length), sizeof(int64_t));
|
||||
// We don't write the \0 at the end on purpose
|
||||
file.write(s.c_str(), length);
|
||||
}
|
||||
}
|
||||
|
||||
_program = nullptr;
|
||||
|
||||
OsEng.parallelConnection().connectionEvent()->unsubscribe("luaConsole");
|
||||
}
|
||||
|
||||
@@ -162,16 +274,20 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio
|
||||
if (_isVisible) {
|
||||
if (_remoteScripting) {
|
||||
_remoteScripting = false;
|
||||
} else {
|
||||
_isVisible = false;
|
||||
}
|
||||
} else {
|
||||
else {
|
||||
_isVisible = false;
|
||||
_commands.back() = "";
|
||||
_inputPosition = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
_isVisible = true;
|
||||
if (OsEng.parallelConnection().status() == ParallelConnection::Status::Host) {
|
||||
_remoteScripting = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -179,31 +295,52 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio
|
||||
return false;
|
||||
}
|
||||
|
||||
if (key == Key::Escape) {
|
||||
_isVisible = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
const bool modifierControl = (modifier == KeyModifier::Control);
|
||||
const bool modifierShift = (modifier == KeyModifier::Shift);
|
||||
|
||||
// Paste from clipboard
|
||||
if (modifierControl && (key == Key::V)) {
|
||||
if (modifierControl && (key == Key::V || key == Key::Y)) {
|
||||
addToCommand(ghoul::clipboardText());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Copy to clipboard
|
||||
if (modifierControl && (key == Key::C)) {
|
||||
if (modifierControl && key == Key::C) {
|
||||
ghoul::setClipboardText(_commands.at(_activeCommand));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Cut to clipboard
|
||||
if (modifierControl && key == Key::X) {
|
||||
ghoul::setClipboardText(_commands.at(_activeCommand));
|
||||
_commands.at(_activeCommand).clear();
|
||||
_inputPosition = 0;
|
||||
}
|
||||
|
||||
// Cut part after cursor to clipboard ("Kill")
|
||||
if (modifierControl && key == Key::K) {
|
||||
auto here = _commands.at(_activeCommand).begin() + _inputPosition;
|
||||
auto end = _commands.at(_activeCommand).end();
|
||||
ghoul::setClipboardText(std::string(here, end));
|
||||
_commands.at(_activeCommand).erase(here, end);
|
||||
}
|
||||
|
||||
// Go to the previous character
|
||||
if ((key == Key::Left) && (_inputPosition > 0)) {
|
||||
--_inputPosition;
|
||||
if (key == Key::Left || (modifierControl && key == Key::B)) {
|
||||
if (_inputPosition > 0) {
|
||||
--_inputPosition;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Go to the next character
|
||||
if (key == Key::Right) {
|
||||
//&& _inputPosition < _commands.at(_activeCommand).length())
|
||||
//++_inputPosition;
|
||||
if (key == Key::Right || (modifierControl && key == Key::F)) {
|
||||
_inputPosition = std::min(
|
||||
_inputPosition + 1,
|
||||
_commands.at(_activeCommand).length()
|
||||
@@ -245,48 +382,40 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Go to the beginning of command string
|
||||
if (key == Key::Home) {
|
||||
if (key == Key::Home || (modifierControl && key == Key::A)) {
|
||||
_inputPosition = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Go to the end of command string
|
||||
if (key == Key::End) {
|
||||
if (key == Key::End || (modifierControl && key == Key::E)) {
|
||||
_inputPosition = _commands.at(_activeCommand).size();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key == Key::Enter) {
|
||||
// SHIFT+ENTER == new line
|
||||
if (modifierShift) {
|
||||
addToCommand("\n");
|
||||
}
|
||||
// ENTER == run lua script
|
||||
else {
|
||||
std::string cmd = _commands.at(_activeCommand);
|
||||
if (cmd != "") {
|
||||
using RemoteScripting = scripting::ScriptEngine::RemoteScripting;
|
||||
OsEng.scriptEngine().queueScript(
|
||||
cmd,
|
||||
_remoteScripting ? RemoteScripting::Yes : RemoteScripting::No
|
||||
);
|
||||
|
||||
// Only add the current command to the history if it hasn't been
|
||||
// executed before. We don't want two of the same commands in a row
|
||||
if (_commandsHistory.empty() || (cmd != _commandsHistory.back())) {
|
||||
_commandsHistory.push_back(_commands.at(_activeCommand));
|
||||
}
|
||||
if (key == Key::Enter || key == Key::KeypadEnter) {
|
||||
std::string cmd = _commands.at(_activeCommand);
|
||||
if (cmd != "") {
|
||||
using RemoteScripting = scripting::ScriptEngine::RemoteScripting;
|
||||
OsEng.scriptEngine().queueScript(
|
||||
cmd,
|
||||
_remoteScripting ? RemoteScripting::Yes : RemoteScripting::No
|
||||
);
|
||||
|
||||
// Only add the current command to the history if it hasn't been
|
||||
// executed before. We don't want two of the same commands in a row
|
||||
if (_commandsHistory.empty() || (cmd != _commandsHistory.back())) {
|
||||
_commandsHistory.push_back(_commands.at(_activeCommand));
|
||||
}
|
||||
|
||||
// Some clean up after the execution of the command
|
||||
_commands = _commandsHistory;
|
||||
_commands.push_back("");
|
||||
_activeCommand = _commands.size() - 1;
|
||||
_inputPosition = 0;
|
||||
_isVisible = false;
|
||||
}
|
||||
|
||||
// Some clean up after the execution of the command
|
||||
_commands = _commandsHistory;
|
||||
_commands.push_back("");
|
||||
_activeCommand = _commands.size() - 1;
|
||||
_inputPosition = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -306,7 +435,7 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio
|
||||
std::sort(allCommands.begin(), allCommands.end());
|
||||
|
||||
std::string currentCommand = _commands.at(_activeCommand);
|
||||
|
||||
|
||||
// Check if it is the first time the tab has been pressed. If so, we need to
|
||||
// store the already entered command so that we can later start the search
|
||||
// from there. We will overwrite the 'currentCommand' thus making the storage
|
||||
@@ -332,7 +461,7 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio
|
||||
std::back_inserter(commandLowerCase),
|
||||
[](char v) { return static_cast<char>(tolower(v)); }
|
||||
);
|
||||
|
||||
|
||||
std::string initialValueLowerCase;
|
||||
std::transform(
|
||||
_autoCompleteInfo.initialValue.begin(),
|
||||
@@ -340,11 +469,11 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio
|
||||
std::back_inserter(initialValueLowerCase),
|
||||
[](char v) { return static_cast<char>(tolower(v)); }
|
||||
);
|
||||
|
||||
|
||||
bool correctCommand =
|
||||
commandLowerCase.substr(0, fullLength) == initialValueLowerCase;
|
||||
|
||||
if (correctLength && correctCommand && (i > _autoCompleteInfo.lastIndex)){
|
||||
|
||||
if (correctLength && correctCommand && (i > _autoCompleteInfo.lastIndex)) {
|
||||
// We found our index, so store it
|
||||
_autoCompleteInfo.lastIndex = i;
|
||||
|
||||
@@ -390,6 +519,11 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio
|
||||
}
|
||||
}
|
||||
|
||||
// We want to ignore the function keys as they don't translate to text anyway
|
||||
if (key >= Key::F1 && key <= Key::F25) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -420,98 +554,187 @@ void LuaConsole::charCallback(unsigned int codepoint, KeyModifier modifier) {
|
||||
addToCommand(std::string(1, static_cast<const char>(codepoint)));
|
||||
}
|
||||
|
||||
void LuaConsole::render() {
|
||||
const float FontSize = 10.0f;
|
||||
|
||||
if (!_isVisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int ySize = OsEng.renderEngine().fontResolution().y;
|
||||
|
||||
const float startY =
|
||||
static_cast<float>(ySize) - 2.0f * FontSize - FontSize * 15.0f * 2.0f;;
|
||||
|
||||
const glm::vec4 red(1, 0, 0, 1);
|
||||
const glm::vec4 lightBlue(0.4, 0.4, 1, 1);
|
||||
const glm::vec4 green(0, 1, 0, 1);
|
||||
const glm::vec4 white(1, 1, 1, 1);
|
||||
std::shared_ptr<ghoul::fontrendering::Font> font = OsEng.fontManager().font(
|
||||
"Mono", FontSize
|
||||
void LuaConsole::update() {
|
||||
// Compute the height by simulating _historyFont number of lines and checking
|
||||
// what the bounding box for that text would be.
|
||||
using namespace ghoul::fontrendering;
|
||||
size_t nLines = std::min(static_cast<size_t>(_historyLength), _commandsHistory.size());
|
||||
const auto bbox = FontRenderer::defaultRenderer().boundingBox(
|
||||
*_historyFont,
|
||||
std::string(nLines, '\n').c_str()
|
||||
);
|
||||
|
||||
using ghoul::fontrendering::RenderFont;
|
||||
// Update the full height and the target height.
|
||||
// Add the height of the entry line and space for a separator.
|
||||
_fullHeight = (bbox.boundingBox.y + EntryFontSize + SeparatorSpace);
|
||||
_targetHeight = _isVisible ? _fullHeight : 0;
|
||||
|
||||
if (_remoteScripting) {
|
||||
int nClients = OsEng.parallelConnection().nConnections() - 1;
|
||||
if (nClients == 1) {
|
||||
RenderFont(
|
||||
*font,
|
||||
glm::vec2(15.f, startY + 20.0f),
|
||||
red,
|
||||
"Broadcasting script to 1 client"
|
||||
);
|
||||
} else {
|
||||
RenderFont(
|
||||
*font,
|
||||
glm::vec2(15.f, startY + 20.0f),
|
||||
red,
|
||||
("Broadcasting script to " + std::to_string(nClients) + " clients").c_str()
|
||||
);
|
||||
}
|
||||
RenderFont(*font, glm::vec2(15.f, startY), red, "$");
|
||||
const float frametime = static_cast<float>(OsEng.windowWrapper().deltaTime());
|
||||
|
||||
// Update the current height.
|
||||
// The current height is the offset that is used to slide
|
||||
// the console in from the top.
|
||||
const glm::ivec2 res = OsEng.windowWrapper().currentWindowResolution();
|
||||
const glm::vec2 dpiScaling = OsEng.windowWrapper().dpiScaling();
|
||||
_currentHeight += (_targetHeight - _currentHeight) *
|
||||
std::pow(0.98, 1.0 / (ConsoleOpenSpeed / dpiScaling.y * frametime));
|
||||
|
||||
_currentHeight = std::max(0.0f, _currentHeight);
|
||||
_currentHeight = std::min(static_cast<float>(res.y), _currentHeight);
|
||||
}
|
||||
|
||||
|
||||
void LuaConsole::render() {
|
||||
using namespace ghoul::fontrendering;
|
||||
|
||||
// Don't render the console if it's collapsed.
|
||||
if (_currentHeight < 1.0f) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (OsEng.parallelConnection().isHost()) {
|
||||
RenderFont(
|
||||
*font,
|
||||
glm::vec2(15.f, startY + 20.0f),
|
||||
lightBlue,
|
||||
"Local script execution"
|
||||
);
|
||||
}
|
||||
RenderFont(*font, glm::vec2(15.f, startY), lightBlue, "$");
|
||||
|
||||
if (_program->isDirty()) {
|
||||
_program->rebuildFromFile();
|
||||
}
|
||||
RenderFont(
|
||||
*font,
|
||||
glm::vec2(15.f + FontSize, startY),
|
||||
white,
|
||||
"%s",
|
||||
|
||||
const glm::vec2 dpiScaling = OsEng.windowWrapper().dpiScaling();
|
||||
const glm::ivec2 res =
|
||||
glm::vec2(OsEng.windowWrapper().currentWindowResolution()) / dpiScaling;
|
||||
|
||||
|
||||
// Render background
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
_program->activate();
|
||||
|
||||
_program->setUniform("res", res);
|
||||
_program->setUniform("color", _backgroundColor);
|
||||
_program->setUniform("height", _currentHeight / res.y);
|
||||
_program->setUniform(
|
||||
"ortho",
|
||||
glm::ortho(
|
||||
0.f, static_cast<float>(res.x), 0.f, static_cast<float>(res.y)
|
||||
)
|
||||
);
|
||||
|
||||
// Draw the background color
|
||||
glBindVertexArray(_vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
// Draw the highlight lines above and below the background
|
||||
_program->setUniform("color", _highlightColor);
|
||||
glDrawArrays(GL_LINES, 1, 4);
|
||||
|
||||
// Draw the separator between the current entry box and the history
|
||||
_program->setUniform("color", _separatorColor);
|
||||
_program->setUniform("height", _currentHeight / res.y - 2.5f * EntryFontSize / res.y);
|
||||
glDrawArrays(GL_LINES, 1, 2);
|
||||
|
||||
_program->deactivate();
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Render text on top of the background
|
||||
glm::vec2 inputLocation = glm::vec2(
|
||||
EntryFontSize / 2.f,
|
||||
res.y - _currentHeight + EntryFontSize
|
||||
);
|
||||
|
||||
// Render the current command
|
||||
RenderFontCr(
|
||||
*_font,
|
||||
inputLocation,
|
||||
_entryTextColor,
|
||||
"> %s",
|
||||
_commands.at(_activeCommand).c_str()
|
||||
);
|
||||
|
||||
const size_t n = std::count(
|
||||
_commands.at(_activeCommand).begin(),
|
||||
_commands.at(_activeCommand).begin() + _inputPosition,
|
||||
'\n'
|
||||
);
|
||||
size_t p = _commands.at(_activeCommand).find_last_of('\n', _inputPosition);
|
||||
size_t linepos = _inputPosition;
|
||||
// Just offset the ^ marker slightly for a nicer look
|
||||
inputLocation.y += 3 * dpiScaling.y;
|
||||
|
||||
if (n > 0) {
|
||||
if (p == _inputPosition) {
|
||||
p = _commands.at(_activeCommand).find_last_of('\n', _inputPosition - 1);
|
||||
if (p != std::string::npos) {
|
||||
linepos -= p + 1;
|
||||
}
|
||||
else {
|
||||
linepos = _inputPosition - 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
linepos -= p + 1;
|
||||
}
|
||||
// Render the ^ marker below the text to show where the current entry point is
|
||||
RenderFont(
|
||||
*_font,
|
||||
inputLocation,
|
||||
_entryTextColor,
|
||||
(std::string(_inputPosition + 2, ' ') + "^").c_str()
|
||||
);
|
||||
|
||||
glm::vec2 historyInputLocation = glm::vec2(
|
||||
HistoryFontSize / 2.f,
|
||||
res.y - HistoryFontSize * 1.5f + _fullHeight - _currentHeight
|
||||
);
|
||||
|
||||
// @CPP17: Replace with array_view
|
||||
std::vector<std::string> commandSubset;
|
||||
if (_commandsHistory.size() < static_cast<size_t>(_historyLength)) {
|
||||
commandSubset = _commandsHistory;
|
||||
}
|
||||
else {
|
||||
commandSubset = std::vector<std::string>(
|
||||
_commandsHistory.end() - _historyLength,
|
||||
_commandsHistory.end()
|
||||
);
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "%" << linepos + 1 << "s";
|
||||
RenderFont(
|
||||
*font,
|
||||
glm::vec2(15.f + FontSize * 0.5f, startY - (FontSize) * (n + 1) * 3.0f / 2.0f),
|
||||
green,
|
||||
ss.str().c_str(),
|
||||
"^"
|
||||
);
|
||||
for (const std::string& cmd : commandSubset) {
|
||||
RenderFontCr(
|
||||
*_historyFont,
|
||||
historyInputLocation,
|
||||
_historyTextColor,
|
||||
"%s",
|
||||
cmd.c_str()
|
||||
);
|
||||
}
|
||||
|
||||
// Computes the location for right justified text on the same y height as the entry
|
||||
auto locationForRightJustifiedText = [&](const std::string& text) {
|
||||
using namespace ghoul::fontrendering;
|
||||
|
||||
const glm::vec2 loc = glm::vec2(
|
||||
EntryFontSize / 2.f,
|
||||
res.y - _currentHeight + EntryFontSize
|
||||
);
|
||||
|
||||
const auto bbox = FontRenderer::defaultRenderer().boundingBox(
|
||||
*_font, text.c_str()
|
||||
);
|
||||
return glm::vec2(
|
||||
loc.x + res.x - bbox.boundingBox.x - 10.f,
|
||||
loc.y
|
||||
);
|
||||
};
|
||||
|
||||
if (_remoteScripting) {
|
||||
const glm::vec4 red(1, 0, 0, 1);
|
||||
|
||||
ParallelConnection::Status status = OsEng.parallelConnection().status();
|
||||
const int nClients =
|
||||
status != ParallelConnection::Status::Disconnected ?
|
||||
OsEng.parallelConnection().nConnections() - 1 :
|
||||
0;
|
||||
|
||||
const std::string nClientsText =
|
||||
nClients == 1 ?
|
||||
"Broadcasting script to 1 client" :
|
||||
"Broadcasting script to " + std::to_string(nClients) + " clients";
|
||||
|
||||
const glm::vec2 loc = locationForRightJustifiedText(nClientsText);
|
||||
RenderFont(*_font, loc, red, nClientsText.c_str());
|
||||
} else if (OsEng.parallelConnection().isHost()) {
|
||||
const glm::vec4 lightBlue(0.4, 0.4, 1, 1);
|
||||
|
||||
const std::string localExecutionText = "Local script execution";
|
||||
const glm::vec2 loc = locationForRightJustifiedText(localExecutionText);
|
||||
RenderFont(*_font, loc, lightBlue, localExecutionText.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
float LuaConsole::currentHeight() const {
|
||||
return _currentHeight;
|
||||
}
|
||||
|
||||
void LuaConsole::addToCommand(std::string c) {
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
#include <ghoul/misc/sharedmemory.h>
|
||||
#include <ghoul/misc/onscopeexit.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "PerformanceManager";
|
||||
|
||||
|
||||
@@ -42,8 +42,6 @@ namespace {
|
||||
|
||||
const char* Property::ViewOptions::Color = "color";
|
||||
const char* Property::ViewOptions::LightPosition = "lightPosition";
|
||||
const char* Property::ViewOptions::PowerScaledCoordinate = "powerScaledCoordinate";
|
||||
const char* Property::ViewOptions::PowerScaledScalar = "powerScaledScalar";
|
||||
|
||||
const char* Property::IdentifierKey = "Identifier";
|
||||
const char* Property::NameKey = "Name";
|
||||
@@ -156,6 +154,12 @@ void Property::setViewOption(std::string option, bool value) {
|
||||
);
|
||||
}
|
||||
|
||||
bool Property::viewOption(const std::string& option, bool defaultValue) const {
|
||||
bool v = defaultValue;
|
||||
_metaData.getValue(_metaDataKeyViewPrefix + option, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
const ghoul::Dictionary& Property::metaData() const {
|
||||
return _metaData;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#ifdef OPENSPACE_MODULE_NEWHORIZONS_ENABLED
|
||||
#include <modules/newhorizons/util/imagesequencer.h>
|
||||
#endif
|
||||
#include <openspace/util/syncdata.h>
|
||||
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
@@ -38,11 +39,17 @@
|
||||
#include <openspace/rendering/framebufferrenderer.h>
|
||||
#include <openspace/rendering/raycastermanager.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/performance/performancemanager.h>
|
||||
#include <openspace/rendering/renderer.h>
|
||||
|
||||
#include <openspace/interaction/luaconsole.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/screenlog.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/rendering/raycastermanager.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/font/font.h>
|
||||
@@ -175,6 +182,11 @@ RenderEngine::RenderEngine()
|
||||
addProperty(_disableMasterRendering);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
RenderEngine::~RenderEngine() {}
|
||||
|
||||
void RenderEngine::setRendererFromString(const std::string& renderingMethod) {
|
||||
_rendererImplementation = rendererFromString(renderingMethod);
|
||||
|
||||
@@ -820,6 +832,8 @@ void RenderEngine::renderInformation() {
|
||||
//OsEng.windowWrapper().viewportPixelCoordinates().w
|
||||
);
|
||||
|
||||
penPosition.y -= OsEng.console().currentHeight();
|
||||
|
||||
if (_showDate && _fontDate) {
|
||||
penPosition.y -= _fontDate->height();
|
||||
RenderFontCr(
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/camera.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
@@ -92,6 +92,9 @@ Scene::Scene()
|
||||
)
|
||||
{}
|
||||
|
||||
Scene::~Scene(){
|
||||
}
|
||||
|
||||
void Scene::setRoot(std::unique_ptr<SceneGraphNode> root) {
|
||||
if (_root) {
|
||||
removeNode(_root.get());
|
||||
|
||||
@@ -24,9 +24,21 @@
|
||||
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
#include <modules/base/translation/statictranslation.h>
|
||||
#include <modules/base/rotation/staticrotation.h>
|
||||
#include <modules/base/scale/staticscale.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/query/query.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/scene/rotation.h>
|
||||
#include <openspace/scene/scale.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/scene/translation.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/logging/consolelog.h>
|
||||
@@ -36,13 +48,6 @@
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/shaderobject.h>
|
||||
|
||||
#include <modules/base/translation/statictranslation.h>
|
||||
#include <modules/base/rotation/staticrotation.h>
|
||||
#include <modules/base/scale/staticscale.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
#include <cctype>
|
||||
#include <chrono>
|
||||
|
||||
|
||||
@@ -547,23 +547,17 @@ std::string ScriptEngine::generateJson() const {
|
||||
}
|
||||
|
||||
bool ScriptEngine::writeLog(const std::string& script) {
|
||||
const std::string KeyScriptLogType =
|
||||
ConfigurationManager::KeyScriptLog + '.' + ConfigurationManager::PartType;
|
||||
const std::string KeyScriptLogFile =
|
||||
ConfigurationManager::KeyScriptLog + '.' + ConfigurationManager::PartFile;
|
||||
|
||||
// Check that logging is enabled and initialize if necessary
|
||||
if (!_logFileExists) {
|
||||
// If a ScriptLogFile was specified, generate it now
|
||||
const bool hasType = OsEng.configurationManager()
|
||||
.hasKey(KeyScriptLogType);
|
||||
const bool hasFile = OsEng.configurationManager()
|
||||
.hasKey(KeyScriptLogFile);
|
||||
if (hasType && hasFile) {
|
||||
OsEng.configurationManager()
|
||||
.getValue(KeyScriptLogType, _logType);
|
||||
OsEng.configurationManager()
|
||||
.getValue(KeyScriptLogFile, _logFilename);
|
||||
const bool hasFile = OsEng.configurationManager().hasKey(
|
||||
ConfigurationManager::KeyScriptLog
|
||||
);
|
||||
if (hasFile) {
|
||||
OsEng.configurationManager().getValue(
|
||||
ConfigurationManager::KeyScriptLog,
|
||||
_logFilename
|
||||
);
|
||||
|
||||
_logFilename = absPath(_logFilename);
|
||||
_logFileExists = true;
|
||||
@@ -581,32 +575,21 @@ bool ScriptEngine::writeLog(const std::string& script) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
LDEBUG("No script log specified in 'openspace.cfg.' To log, set '"
|
||||
<< KeyScriptLogType << " and "
|
||||
<< KeyScriptLogFile
|
||||
<< " in configuration table.");
|
||||
_logScripts = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (_logType == "text") {
|
||||
// Simple text output to logfile
|
||||
std::ofstream file(_logFilename, std::ofstream::app);
|
||||
if (!file.good()) {
|
||||
LERROR("Could not open file '" << _logFilename << "' for logging scripts");
|
||||
return false;
|
||||
}
|
||||
|
||||
file << script << std::endl;
|
||||
file.close();
|
||||
}
|
||||
else {
|
||||
LERROR("Undefined type '" << _logType << "' for script documentation");
|
||||
_logScripts = false;
|
||||
// Simple text output to logfile
|
||||
std::ofstream file(_logFilename, std::ofstream::app);
|
||||
if (!file.good()) {
|
||||
LERROR("Could not open file '" << _logFilename << "' for logging scripts");
|
||||
return false;
|
||||
}
|
||||
|
||||
file << script << std::endl;
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,9 @@ ScreenLog::ScreenLog(std::chrono::seconds timeToLive, LogLevel logLevel)
|
||||
: _timeToLive(std::move(timeToLive))
|
||||
, _logLevel(logLevel)
|
||||
{}
|
||||
|
||||
|
||||
ScreenLog::~ScreenLog() {}
|
||||
|
||||
void ScreenLog::removeExpiredEntries() {
|
||||
auto t = std::chrono::steady_clock::now();
|
||||
auto ttl = _timeToLive;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <ghoul/misc/dictionaryluaformatter.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
#include <fstream>
|
||||
|
||||
Reference in New Issue
Block a user