mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-04 02:29:49 -06:00
Introduced fadeIn and fadeOut functionality via scripting.
This commit is contained in:
@@ -90,6 +90,9 @@ public:
|
||||
// This is a temporary method to change the origin of the coordinate system ---abock
|
||||
void changeViewPoint(std::string origin);
|
||||
|
||||
//temporaray fade functionality
|
||||
void startFading(int direction, float fadeDuration);
|
||||
|
||||
private:
|
||||
void storePerformanceMeasurements();
|
||||
|
||||
@@ -108,6 +111,9 @@ private:
|
||||
void generateGlslConfig();
|
||||
|
||||
float _globalOpactity;
|
||||
float _fadeDuration;
|
||||
float _currentFadeTime;
|
||||
int _fadeDirection;
|
||||
|
||||
bool _visualizeABuffer;
|
||||
ABufferVisualizer* _visualizer;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
@@ -240,7 +239,12 @@ void mainLogCallback(const char* msg){
|
||||
|
||||
void postFXPass(){
|
||||
glUniform1i(_postFXTexLoc, 0);
|
||||
glUniform1f(_postFXOpacityLoc, OsEng.ref().renderEngine()->globalOpacity());
|
||||
if (OsEng.isMaster()){
|
||||
glUniform1f(_postFXOpacityLoc, 1.f);
|
||||
}
|
||||
else{
|
||||
glUniform1f(_postFXOpacityLoc, OsEng.ref().renderEngine()->globalOpacity());
|
||||
}
|
||||
}
|
||||
|
||||
void setupPostFX(){
|
||||
|
||||
@@ -160,6 +160,37 @@ namespace openspace {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* fadeIn(float):
|
||||
* start a global fadein over (float) seconds
|
||||
*/
|
||||
int fadeIn(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
|
||||
double t = luaL_checknumber(L, -1);
|
||||
|
||||
OsEng.renderEngine()->startFading(1, t);
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* \ingroup LuaScripts
|
||||
* fadeIn(float):
|
||||
* start a global fadeout over (float) seconds
|
||||
*/
|
||||
int fadeOut(lua_State* L) {
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 1)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
|
||||
double t = luaL_checknumber(L, -1);
|
||||
|
||||
OsEng.renderEngine()->startFading(-1, t);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace luascriptfunctions
|
||||
|
||||
|
||||
@@ -176,6 +207,10 @@ namespace openspace {
|
||||
, _visualizeABuffer(false)
|
||||
, _visualizer(nullptr)
|
||||
, _globalOpactity(1.f)
|
||||
, _fadeDuration(2.f)
|
||||
, _currentFadeTime(0.f)
|
||||
, _fadeDirection(0)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
@@ -328,6 +363,24 @@ namespace openspace {
|
||||
|
||||
void RenderEngine::postSynchronizationPreDraw()
|
||||
{
|
||||
//temporary fade funtionality
|
||||
if (_fadeDirection != 0){
|
||||
if (_currentFadeTime > _fadeDuration){
|
||||
_fadeDirection = 0;
|
||||
_globalOpactity = fminf(1.f, fmaxf(0.f, _globalOpactity));
|
||||
}
|
||||
else{
|
||||
|
||||
if (_fadeDirection < 0){
|
||||
_globalOpactity = glm::smoothstep(1.f, 0.f, _currentFadeTime / _fadeDuration);
|
||||
}
|
||||
else{
|
||||
_globalOpactity = glm::smoothstep(0.f, 1.f, _currentFadeTime / _fadeDuration);
|
||||
}
|
||||
_currentFadeTime += static_cast<float>(sgct::Engine::instance()->getAvgDt());
|
||||
}
|
||||
}
|
||||
|
||||
if (_mainCamera){
|
||||
_mainCamera->postSynchronizationPreDraw();
|
||||
}
|
||||
@@ -616,6 +669,12 @@ namespace openspace {
|
||||
_globalOpactity = opacity;
|
||||
}
|
||||
|
||||
void RenderEngine::startFading(int direction, float fadeDuration){
|
||||
_fadeDirection = direction;
|
||||
_fadeDuration = fadeDuration;
|
||||
_currentFadeTime = 0.f;
|
||||
}
|
||||
|
||||
void RenderEngine::generateGlslConfig() {
|
||||
LDEBUG("Generating GLSLS config, expect shader recompilation");
|
||||
int xSize = sgct::Engine::instance()->getActiveWindowPtr()->getXFramebufferResolution();;
|
||||
@@ -690,7 +749,21 @@ namespace openspace {
|
||||
&luascriptfunctions::changeToSunViewPoint,
|
||||
"",
|
||||
""
|
||||
}
|
||||
},
|
||||
//also temporary @JK
|
||||
{
|
||||
"fadeIn",
|
||||
&luascriptfunctions::fadeIn,
|
||||
"number",
|
||||
""
|
||||
},
|
||||
//also temporary @JK
|
||||
{
|
||||
"fadeOut",
|
||||
&luascriptfunctions::fadeOut,
|
||||
"number",
|
||||
""
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -260,15 +260,19 @@ void ScriptEngine::addLibrary(LuaLibrary library) {
|
||||
}
|
||||
|
||||
bool ScriptEngine::runScript(const std::string& script) {
|
||||
if (script.empty())
|
||||
return false;
|
||||
if (script.empty()){
|
||||
LWARNING("Script was empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
int status = luaL_loadstring(_state, script.c_str());
|
||||
if (status != LUA_OK) {
|
||||
LERROR("Error loading script: '" << lua_tostring(_state, -1) << "'");
|
||||
return false;
|
||||
}
|
||||
|
||||
//LDEBUG("Executing script");
|
||||
LDEBUG("Executing script");
|
||||
LINFO(script);
|
||||
if (lua_pcall(_state, 0, LUA_MULTRET, 0)) {
|
||||
LERROR("Error executing script: " << lua_tostring(_state, -1));
|
||||
return false;
|
||||
@@ -608,6 +612,7 @@ bool ScriptEngine::writeDocumentation(const std::string& filename, const std::st
|
||||
|
||||
void ScriptEngine::serialize(SyncBuffer* syncBuffer){
|
||||
syncBuffer->encode(_currentSyncedScript);
|
||||
_currentSyncedScript.clear();
|
||||
}
|
||||
|
||||
void ScriptEngine::deserialize(SyncBuffer* syncBuffer){
|
||||
|
||||
Reference in New Issue
Block a user