Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
!/plugins/csl-tools
!/plugins/csl-node-editor
!/plugins/csp-anchor-labels
!/plugins/csp-animated-giant-planets
!/plugins/csp-atmospheres
!/plugins/csp-custom-web-ui
!/plugins/csp-demo-node-editor
Expand Down
12 changes: 9 additions & 3 deletions config/base/scene/simple_desktop.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,15 @@
}
},
"csp-measurement-tools": {},
"csp-animated-giant-planets": {
"bodies": {
"Jupiter": {
"texture": "../share/resources/textures/jupiter.jpg",
"animation": "../share/resources/textures/jupiter-animated/",
"timePerFrame": 210419
}
}
},
"csp-simple-bodies": {
"bodies": {
"Sun": {
Expand Down Expand Up @@ -830,9 +839,6 @@
"Vesta": {
"texture": "../share/resources/textures/vesta.jpg"
},
"Jupiter": {
"texture": "../share/resources/textures/jupiter.jpg"
},
"Io": {
"texture": "../share/resources/textures/io.jpg"
},
Expand Down
47 changes: 47 additions & 0 deletions plugins/csp-animated-giant-planets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ------------------------------------------------------------------------------------------------ #
# This file is part of CosmoScout VR #
# ------------------------------------------------------------------------------------------------ #

# SPDX-FileCopyrightText: German Aerospace Center (DLR) <cosmoscout@dlr.de>
# SPDX-License-Identifier: MIT

option(CSP_ANIMATED_GIANT_PLANETS "Enable compilation of this plugin" ON)

if (NOT CSP_ANIMATED_GIANT_PLANETS)
return()
endif()

# build plugin -------------------------------------------------------------------------------------

file(GLOB SOURCE_FILES src/*.cpp)

# Resoucre files and header files are only added in order to make them available in your IDE.
file(GLOB HEADER_FILES src/*.hpp)
file(GLOB_RECURSE RESOUCRE_FILES textures/*)

add_library(csp-animated-giant-planets SHARED
${SOURCE_FILES}
${HEADER_FILES}
${RESOUCRE_FILES}
)

target_link_libraries(csp-animated-giant-planets
PUBLIC
cs-core
)

# Add this Plugin to a "plugins" folder in your IDE.
set_property(TARGET csp-animated-giant-planets PROPERTY FOLDER "plugins")

# We mark all resource files as "header" in order to make sure that no one tries to compile them.
set_source_files_properties(${RESOUCRE_FILES} PROPERTIES HEADER_FILE_ONLY TRUE)

# Make directory structure available in your IDE.
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES
${SOURCE_FILES} ${HEADER_FILES} ${RESOUCRE_FILES}
)

# install plugin -----------------------------------------------------------------------------------

install(TARGETS csp-animated-giant-planets DESTINATION "share/plugins")
install(DIRECTORY "textures" DESTINATION "share/resources")
32 changes: 32 additions & 0 deletions plugins/csp-animated-giant-planets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
SPDX-FileCopyrightText: German Aerospace Center (DLR) <cosmoscout@dlr.de>
SPDX-License-Identifier: CC-BY-4.0
-->

# Simple bodies for CosmoScout VR

A CosmoSout VR plugin which renders simple spherical celestial bodies. The bodies are drawn as an ellipsoid with an equirectangular texture.

## Configuration

This plugin can be enabled with the following configuration in your `settings.json`:

```javascript
{
...
"plugins": {
...
"csp-simple-bodies": {
"bodies": {
<anchor name>: {
"texture": <path to surface texture>,
"primeMeridianInCenter": true // optional
},
... <more bodies> ...
}
}
}
}
```

**More in-depth information and some tutorials will be provided soon.**
175 changes: 175 additions & 0 deletions plugins/csp-animated-giant-planets/src/Plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// This file is part of CosmoScout VR //
////////////////////////////////////////////////////////////////////////////////////////////////////

// SPDX-FileCopyrightText: German Aerospace Center (DLR) <cosmoscout@dlr.de>
// SPDX-License-Identifier: MIT

#include "Plugin.hpp"

#include "../../../src/cs-core/InputManager.hpp"
#include "../../../src/cs-core/Settings.hpp"
#include "../../../src/cs-core/SolarSystem.hpp"
#include "../../../src/cs-utils/logger.hpp"
#include "../../../src/cs-utils/utils.hpp"
#include "SimpleBody.hpp"
#include "logger.hpp"

////////////////////////////////////////////////////////////////////////////////////////////////////

EXPORT_FN cs::core::PluginBase* create() {
return new csp::animatedgiantplanets::Plugin;
}

////////////////////////////////////////////////////////////////////////////////////////////////////

EXPORT_FN void destroy(cs::core::PluginBase* pluginBase) {
delete pluginBase; // NOLINT(cppcoreguidelines-owning-memory)
}

////////////////////////////////////////////////////////////////////////////////////////////////////

namespace csp::animatedgiantplanets {

////////////////////////////////////////////////////////////////////////////////////////////////////

void from_json(nlohmann::json const& j, Plugin::Settings::SimpleBody::Ring& o) {
cs::core::Settings::deserialize(j, "texture", o.mTexture);
cs::core::Settings::deserialize(j, "innerRadius", o.mInnerRadius);
cs::core::Settings::deserialize(j, "outerRadius", o.mOuterRadius);
}

void to_json(nlohmann::json& j, Plugin::Settings::SimpleBody::Ring const& o) {
cs::core::Settings::serialize(j, "texture", o.mTexture);
cs::core::Settings::serialize(j, "innerRadius", o.mInnerRadius);
cs::core::Settings::serialize(j, "outerRadius", o.mOuterRadius);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void from_json(nlohmann::json const& j, Plugin::Settings::SimpleBody& o) {
cs::core::Settings::deserialize(j, "texture", o.mTexture);
cs::core::Settings::deserialize(j, "primeMeridianInCenter", o.mPrimeMeridianInCenter);
cs::core::Settings::deserialize(j, "ring", o.mRing);
cs::core::Settings::deserialize(j, "animation", o.mAnimation);
cs::core::Settings::deserialize(j, "timePerFrame", o.mTimePerFrame);
}

void to_json(nlohmann::json& j, Plugin::Settings::SimpleBody const& o) {
cs::core::Settings::serialize(j, "texture", o.mTexture);
cs::core::Settings::serialize(j, "primeMeridianInCenter", o.mPrimeMeridianInCenter);
cs::core::Settings::serialize(j, "ring", o.mRing);
cs::core::Settings::serialize(j, "animation", o.mAnimation);
cs::core::Settings::serialize(j, "timePerFrame", o.mTimePerFrame);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void from_json(nlohmann::json const& j, Plugin::Settings& o) {
cs::core::Settings::deserialize(j, "bodies", o.mSimpleBodies);
}

void to_json(nlohmann::json& j, Plugin::Settings const& o) {
cs::core::Settings::serialize(j, "bodies", o.mSimpleBodies);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin::init() {

logger().info("Loading plugin...");

mOnLoadConnection = mAllSettings->onLoad().connect([this]() { onLoad(); });
mOnSaveConnection = mAllSettings->onSave().connect([this]() { onSave(); });

// Load settings.
onLoad();

logger().info("Loading done.");
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin::deInit() {
logger().info("Unloading plugin...");

// Save settings as this plugin may get reloaded.
onSave();

for (auto const& [name, body] : mSimpleBodies) {
unregisterBody(name);
}

mAllSettings->onLoad().disconnect(mOnLoadConnection);
mAllSettings->onSave().disconnect(mOnSaveConnection);

logger().info("Unloading done.");
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin::update() {
for (auto const& body : mSimpleBodies) {
body.second->update();
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin::onLoad() {
// Read settings from JSON.
from_json(mAllSettings->mPlugins.at("csp-animated-giant-planets"), mPluginSettings);

// First try to re-configure existing simpleBodies. We assume that they are similar if they have
// the same name in the settings (which means they are attached to an anchor with the same name).
auto simpleBody = mSimpleBodies.begin();
while (simpleBody != mSimpleBodies.end()) {
auto settings = mPluginSettings.mSimpleBodies.find(simpleBody->first);
// If there are settings for this simpleBody, reconfigure it.
if (settings != mPluginSettings.mSimpleBodies.end()) {
simpleBody->second->setObjectName(settings->first);
simpleBody->second->configure(settings->second);

++simpleBody;
} else {
// Else delete it.
unregisterBody(simpleBody->first);
simpleBody = mSimpleBodies.erase(simpleBody);
}
}

// Then add new simpleBodies.
for (auto const& settings : mPluginSettings.mSimpleBodies) {
if (mSimpleBodies.find(settings.first) != mSimpleBodies.end()) {
continue;
}

auto simpleBody = std::make_shared<SimpleBody>(mAllSettings, mSolarSystem, mTimeControl);
simpleBody->setObjectName(settings.first);
simpleBody->configure(settings.second);

auto object = mSolarSystem->getObject(settings.first);
object->setSurface(simpleBody);
object->setIntersectableObject(simpleBody);

mSimpleBodies.emplace(settings.first, simpleBody);
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin::onSave() {
mAllSettings->mPlugins["csp-animated-giant-planets"] = mPluginSettings;
}

////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin::unregisterBody(std::string const& name) {
auto object = mSolarSystem->getObject(name);
object->setSurface(nullptr);
object->setIntersectableObject(nullptr);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

} // namespace csp::animatedgiantplanets
72 changes: 72 additions & 0 deletions plugins/csp-animated-giant-planets/src/Plugin.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// This file is part of CosmoScout VR //
////////////////////////////////////////////////////////////////////////////////////////////////////

// SPDX-FileCopyrightText: German Aerospace Center (DLR) <cosmoscout@dlr.de>
// SPDX-License-Identifier: MIT

#ifndef CSP_ANIMATED_GIANT_PLANETS_PLUGIN_HPP
#define CSP_ANIMATED_GIANT_PLANETS_PLUGIN_HPP

#include "../../../src/cs-core/PluginBase.hpp"
#include "../../../src/cs-utils/DefaultProperty.hpp"

#include <map>
#include <optional>
#include <string>

namespace csp::animatedgiantplanets {

class SimpleBody;

/// This plugin provides the rendering of planets as spheres with a texture. Despite its name it
/// can also render moons :P. It can be configured via the applications config file. See README.md
/// for details.
class Plugin : public cs::core::PluginBase {
public:
struct Settings {
struct SimpleBody {
std::string mTexture;
cs::utils::DefaultProperty<bool> mPrimeMeridianInCenter{true};

struct Ring {
/// The path to the texture. The texture should represent a cross section of the ring.
std::string mTexture;

/// The distance from the planet's center to where the ring starts in meters.
double mInnerRadius;

/// The distance from the planet's center to where the ring ends in meters.
double mOuterRadius;
};
std::optional<Ring> mRing;

/// The path to the animation textures. the textures should be named 'frame-0.jpg', 'frame-1.jpg', ...
std::optional<std::string> mAnimation;

/// The real time in seconds between two frames of the animation.
std::optional<float> mTimePerFrame;
};

std::map<std::string, SimpleBody> mSimpleBodies;
};

void init() override;
void deInit() override;
void update() override;

private:
void onLoad();
void onSave();
void unregisterBody(std::string const& name);

Settings mPluginSettings;
std::map<std::string, std::shared_ptr<SimpleBody>> mSimpleBodies;

int mOnLoadConnection = -1;
int mOnSaveConnection = -1;
};

} // namespace csp::animatedgiantplanets

#endif // CSP_ANIMATED_GIANT_PLANETS_PLUGIN_HPP
Loading
Loading